^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * mac80211 - channel management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/nl80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <net/cfg80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "ieee80211_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "driver-ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static int ieee80211_chanctx_num_assigned(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int ieee80211_chanctx_num_reserved(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int ieee80211_chanctx_refcount(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return ieee80211_chanctx_num_assigned(local, ctx) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ieee80211_chanctx_num_reserved(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int ieee80211_num_chanctx(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) list_for_each_entry(ctx, &local->chanctx_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct ieee80211_chanctx *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ieee80211_vif_get_chanctx(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct ieee80211_local *local __maybe_unused = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return container_of(conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct cfg80211_chan_def *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ieee80211_chanctx_reserved_chandef(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct ieee80211_chanctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) const struct cfg80211_chan_def *compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) list_for_each_entry(sdata, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) compat = &sdata->reserved_chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) compat = cfg80211_chandef_compatible(&sdata->reserved_chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static const struct cfg80211_chan_def *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ieee80211_chanctx_non_reserved_chandef(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct ieee80211_chanctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) const struct cfg80211_chan_def *compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) list_for_each_entry(sdata, &ctx->assigned_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) assigned_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (sdata->reserved_chanctx != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) compat = &sdata->vif.bss_conf.chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) compat = cfg80211_chandef_compatible(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) &sdata->vif.bss_conf.chandef, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static const struct cfg80211_chan_def *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ieee80211_chanctx_combined_chandef(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct ieee80211_chanctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) const struct cfg80211_chan_def *compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) compat = ieee80211_chanctx_reserved_chandef(local, ctx, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) compat = ieee80211_chanctx_non_reserved_chandef(local, ctx, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ieee80211_chanctx_can_reserve_chandef(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct ieee80211_chanctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) const struct cfg80211_chan_def *def)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (ieee80211_chanctx_combined_chandef(local, ctx, def))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (!list_empty(&ctx->reserved_vifs) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ieee80211_chanctx_reserved_chandef(local, ctx, def))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static struct ieee80211_chanctx *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) ieee80211_find_reservation_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) enum ieee80211_chanctx_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (mode == IEEE80211_CHANCTX_EXCLUSIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!ieee80211_chanctx_can_reserve_chandef(local, ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) chandef))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) enum nl80211_chan_width ieee80211_get_sta_bw(struct ieee80211_sta *sta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) switch (sta->bandwidth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) case IEEE80211_STA_RX_BW_20:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (sta->ht_cap.ht_supported)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return NL80211_CHAN_WIDTH_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) case IEEE80211_STA_RX_BW_40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return NL80211_CHAN_WIDTH_40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) case IEEE80211_STA_RX_BW_80:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return NL80211_CHAN_WIDTH_80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) case IEEE80211_STA_RX_BW_160:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * This applied for both 160 and 80+80. since we use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * the returned value to consider degradation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * ctx->conf.min_def, we have to make sure to take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * the bigger one (NL80211_CHAN_WIDTH_160).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * Otherwise we might try degrading even when not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * needed, as the max required sta_bw returned (80+80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * might be smaller than the configured bw (160).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return NL80211_CHAN_WIDTH_160;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return NL80211_CHAN_WIDTH_20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static enum nl80211_chan_width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ieee80211_get_max_required_bw(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) enum nl80211_chan_width max_bw = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (sdata != sta->sdata &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) !(sta->sdata->bss && sta->sdata->bss == sdata->bss))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) max_bw = max(max_bw, ieee80211_get_sta_bw(&sta->sta));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return max_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static enum nl80211_chan_width
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ieee80211_get_chanctx_max_required_bw(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct ieee80211_chanctx_conf *conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) enum nl80211_chan_width max_bw = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct ieee80211_vif *vif = &sdata->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) switch (vif->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) width = ieee80211_get_max_required_bw(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * The ap's sta->bandwidth is not set yet at this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * point, so take the width from the chandef, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * account also for TDLS peers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) width = max(vif->bss_conf.chandef.width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ieee80211_get_max_required_bw(sdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) width = vif->bss_conf.chandef.width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) case NL80211_IFTYPE_UNSPECIFIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) case NUM_NL80211_IFTYPES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) max_bw = max(max_bw, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) /* use the configured bandwidth in case of monitor interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) sdata = rcu_dereference(local->monitor_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (sdata && rcu_access_pointer(sdata->vif.chanctx_conf) == conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) max_bw = max(max_bw, conf->def.width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return max_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * recalc the min required chan width of the channel context, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * the max of min required widths of all the interfaces bound to this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * channel context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) void ieee80211_recalc_chanctx_min_def(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) enum nl80211_chan_width max_bw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct cfg80211_chan_def min_def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* don't optimize non-20MHz based and radar_enabled confs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (ctx->conf.def.width == NL80211_CHAN_WIDTH_5 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ctx->conf.def.width == NL80211_CHAN_WIDTH_10 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) ctx->conf.def.width == NL80211_CHAN_WIDTH_1 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ctx->conf.def.width == NL80211_CHAN_WIDTH_2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) ctx->conf.def.width == NL80211_CHAN_WIDTH_4 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) ctx->conf.def.width == NL80211_CHAN_WIDTH_8 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ctx->conf.def.width == NL80211_CHAN_WIDTH_16 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) ctx->conf.radar_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) ctx->conf.min_def = ctx->conf.def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) max_bw = ieee80211_get_chanctx_max_required_bw(local, &ctx->conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* downgrade chandef up to max_bw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) min_def = ctx->conf.def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) while (min_def.width > max_bw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ieee80211_chandef_downgrade(&min_def);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (cfg80211_chandef_identical(&ctx->conf.min_def, &min_def))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) ctx->conf.min_def = min_def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (!ctx->driver_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_MIN_WIDTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) static void ieee80211_change_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct ieee80211_chanctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) const struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (cfg80211_chandef_identical(&ctx->conf.def, chandef)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ieee80211_recalc_chanctx_min_def(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) WARN_ON(!cfg80211_chandef_compatible(&ctx->conf.def, chandef));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ctx->conf.def = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_WIDTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ieee80211_recalc_chanctx_min_def(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (!local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) local->_oper_chandef = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ieee80211_hw_config(local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static struct ieee80211_chanctx *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ieee80211_find_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) enum ieee80211_chanctx_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (mode == IEEE80211_CHANCTX_EXCLUSIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) const struct cfg80211_chan_def *compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) compat = cfg80211_chandef_compatible(&ctx->conf.def, chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) compat = ieee80211_chanctx_reserved_chandef(local, ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ieee80211_change_chanctx(local, ctx, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) bool ieee80211_is_radar_required(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (sdata->radar_required) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) ieee80211_chanctx_radar_required(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct ieee80211_chanctx_conf *conf = &ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) bool required = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (!sdata->radar_required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) required = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return required;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static struct ieee80211_chanctx *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) ieee80211_alloc_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) enum ieee80211_chanctx_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) INIT_LIST_HEAD(&ctx->assigned_vifs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) INIT_LIST_HEAD(&ctx->reserved_vifs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) ctx->conf.def = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ctx->conf.rx_chains_static = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ctx->conf.rx_chains_dynamic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) ctx->mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) ctx->conf.radar_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) ieee80211_recalc_chanctx_min_def(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static int ieee80211_add_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) u32 changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (!local->use_chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* turn idle off *before* setting channel -- some drivers need that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) changed = ieee80211_idle_off(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) ieee80211_hw_config(local, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (!local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) local->_oper_chandef = ctx->conf.def;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) err = drv_add_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static struct ieee80211_chanctx *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ieee80211_new_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) enum ieee80211_chanctx_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ctx = ieee80211_alloc_chanctx(local, chandef, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) err = ieee80211_add_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) list_add_rcu(&ctx->list, &local->chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static void ieee80211_del_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (!local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct cfg80211_chan_def *chandef = &local->_oper_chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* S1G doesn't have 20MHz, so get the correct width for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * current channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (chandef->chan->band == NL80211_BAND_S1GHZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) chandef->width =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) ieee80211_s1g_channel_width(chandef->chan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) chandef->center_freq1 = chandef->chan->center_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) chandef->freq1_offset = chandef->chan->freq_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) chandef->center_freq2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* NOTE: Disabling radar is only valid here for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * single channel context. To be sure, check it ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) WARN_ON(local->hw.conf.radar_enabled &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) !list_empty(&local->chanctx_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) local->hw.conf.radar_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) drv_remove_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) ieee80211_recalc_idle(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) static void ieee80211_free_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) WARN_ON_ONCE(ieee80211_chanctx_refcount(local, ctx) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) list_del_rcu(&ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) ieee80211_del_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) kfree_rcu(ctx, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) void ieee80211_recalc_chanctx_chantype(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) struct ieee80211_chanctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct ieee80211_chanctx_conf *conf = &ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) const struct cfg80211_chan_def *compat = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct sta_info *sta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) compat = &sdata->vif.bss_conf.chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) compat = cfg80211_chandef_compatible(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) &sdata->vif.bss_conf.chandef, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (WARN_ON_ONCE(!compat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* TDLS peers can sometimes affect the chandef width */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) list_for_each_entry_rcu(sta, &local->sta_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!sta->uploaded ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) !test_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) !sta->tdls_chandef.chan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) compat = cfg80211_chandef_compatible(&sta->tdls_chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (WARN_ON_ONCE(!compat))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (!compat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ieee80211_change_chanctx(local, ctx, compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct ieee80211_chanctx *chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) bool radar_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* for ieee80211_is_radar_required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) radar_enabled = ieee80211_chanctx_radar_required(local, chanctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (radar_enabled == chanctx->conf.radar_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) chanctx->conf.radar_enabled = radar_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (!local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) local->hw.conf.radar_enabled = chanctx->conf.radar_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RADAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct ieee80211_chanctx *new_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct ieee80211_chanctx *curr_ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_NAN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (conf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) curr_ctx = container_of(conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) drv_unassign_vif_chanctx(local, sdata, curr_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) conf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) list_del(&sdata->assigned_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (new_ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) ret = drv_assign_vif_chanctx(local, sdata, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) conf = &new_ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) list_add(&sdata->assigned_chanctx_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) &new_ctx->assigned_vifs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) rcu_assign_pointer(sdata->vif.chanctx_conf, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) sdata->vif.bss_conf.idle = !conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) if (curr_ctx && ieee80211_chanctx_num_assigned(local, curr_ctx) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) ieee80211_recalc_chanctx_chantype(local, curr_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) ieee80211_recalc_smps_chanctx(local, curr_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) ieee80211_recalc_radar_chanctx(local, curr_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) ieee80211_recalc_chanctx_min_def(local, curr_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) if (new_ctx && ieee80211_chanctx_num_assigned(local, new_ctx) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ieee80211_recalc_txpower(sdata, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ieee80211_recalc_chanctx_min_def(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) sdata->vif.type != NL80211_IFTYPE_MONITOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) ieee80211_bss_info_change_notify(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) BSS_CHANGED_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) ieee80211_check_fast_xmit_iface(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) struct ieee80211_chanctx *chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) u8 rx_chains_static, rx_chains_dynamic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) rx_chains_static = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) rx_chains_dynamic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) u8 needed_static, needed_dynamic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (!ieee80211_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (rcu_access_pointer(sdata->vif.chanctx_conf) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) &chanctx->conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (!sdata->u.mgd.associated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) switch (sdata->smps_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) WARN_ONCE(1, "Invalid SMPS mode %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) sdata->smps_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) case IEEE80211_SMPS_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) needed_static = sdata->needed_rx_chains;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) needed_dynamic = sdata->needed_rx_chains;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) case IEEE80211_SMPS_DYNAMIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) needed_static = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) needed_dynamic = sdata->needed_rx_chains;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) case IEEE80211_SMPS_STATIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) needed_static = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) needed_dynamic = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) rx_chains_static = max(rx_chains_static, needed_static);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) rx_chains_dynamic = max(rx_chains_dynamic, needed_dynamic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* Disable SMPS for the monitor interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) sdata = rcu_dereference(local->monitor_sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (sdata &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) rcu_access_pointer(sdata->vif.chanctx_conf) == &chanctx->conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) rx_chains_dynamic = rx_chains_static = local->rx_chains;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (!local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (rx_chains_static > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) local->smps_mode = IEEE80211_SMPS_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) else if (rx_chains_dynamic > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) local->smps_mode = IEEE80211_SMPS_DYNAMIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) local->smps_mode = IEEE80211_SMPS_STATIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ieee80211_hw_config(local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (rx_chains_static == chanctx->conf.rx_chains_static &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) rx_chains_dynamic == chanctx->conf.rx_chains_dynamic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) chanctx->conf.rx_chains_static = rx_chains_static;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) chanctx->conf.rx_chains_dynamic = rx_chains_dynamic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RX_CHAINS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) bool clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct ieee80211_local *local __maybe_unused = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) struct ieee80211_sub_if_data *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* Check that conf exists, even when clearing this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * must be called with the AP's channel context still there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * as it would otherwise cause VLANs to have an invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * channel context pointer for a while, possibly pointing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * to a channel context that has already been freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) WARN_ON(!conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) conf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) rcu_assign_pointer(vlan->vif.chanctx_conf, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) bool clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) __ieee80211_vif_copy_chanctx_to_vlans(sdata, clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) struct ieee80211_chanctx *ctx = sdata->reserved_chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) lockdep_assert_held(&sdata->local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (WARN_ON(!ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) list_del(&sdata->reserved_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) sdata->reserved_chanctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (ieee80211_chanctx_refcount(sdata->local, ctx) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (WARN_ON(!ctx->replace_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) WARN_ON(ctx->replace_ctx->replace_state !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) IEEE80211_CHANCTX_WILL_BE_REPLACED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) WARN_ON(ctx->replace_ctx->replace_ctx != ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) ctx->replace_ctx->replace_ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) ctx->replace_ctx->replace_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) IEEE80211_CHANCTX_REPLACE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) list_del_rcu(&ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) kfree_rcu(ctx, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) ieee80211_free_chanctx(sdata->local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) enum ieee80211_chanctx_mode mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) bool radar_required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) struct ieee80211_chanctx *new_ctx, *curr_ctx, *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) curr_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (curr_ctx && local->use_chanctx && !local->ops->switch_vif_chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) new_ctx = ieee80211_find_reservation_chanctx(local, chandef, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (!new_ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (ieee80211_can_create_new_chanctx(local)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) new_ctx = ieee80211_new_chanctx(local, chandef, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (IS_ERR(new_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return PTR_ERR(new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (!curr_ctx ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) (curr_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) !list_empty(&curr_ctx->reserved_vifs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * Another vif already requested this context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * for a reservation. Find another one hoping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * all vifs assigned to it will also switch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * soon enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * TODO: This needs a little more work as some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * cases (more than 2 chanctx capable devices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) * may fail which could otherwise succeed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) * provided some channel context juggling was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) * performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) * Consider ctx1..3, vif1..6, each ctx has 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) * vifs. vif1 and vif2 from ctx1 request new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) * different chandefs starting 2 in-place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) * reserations with ctx4 and ctx5 replacing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) * ctx1 and ctx2 respectively. Next vif5 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) * vif6 from ctx3 reserve ctx4. If vif3 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) * vif4 remain on ctx2 as they are then this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * fails unless `replace_ctx` from ctx5 is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * replaced with ctx3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) list_for_each_entry(ctx, &local->chanctx_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (ctx->replace_state !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) IEEE80211_CHANCTX_REPLACE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) if (!list_empty(&ctx->reserved_vifs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) curr_ctx = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) * If that's true then all available contexts already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) * have reservations and cannot be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (!curr_ctx ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) (curr_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) !list_empty(&curr_ctx->reserved_vifs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) new_ctx = ieee80211_alloc_chanctx(local, chandef, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) if (!new_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) new_ctx->replace_ctx = curr_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) new_ctx->replace_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) IEEE80211_CHANCTX_REPLACES_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) curr_ctx->replace_ctx = new_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) curr_ctx->replace_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) IEEE80211_CHANCTX_WILL_BE_REPLACED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) list_add_rcu(&new_ctx->list, &local->chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) list_add(&sdata->reserved_chanctx_list, &new_ctx->reserved_vifs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) sdata->reserved_chanctx = new_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) sdata->reserved_chandef = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) sdata->reserved_radar_required = radar_required;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) sdata->reserved_ready = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) switch (sdata->vif.type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) case NL80211_IFTYPE_ADHOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) case NL80211_IFTYPE_AP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) case NL80211_IFTYPE_MESH_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) case NL80211_IFTYPE_OCB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) ieee80211_queue_work(&sdata->local->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) &sdata->csa_finalize_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) case NL80211_IFTYPE_STATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) ieee80211_queue_work(&sdata->local->hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) &sdata->u.mgd.chswitch_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) case NL80211_IFTYPE_UNSPECIFIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) case NL80211_IFTYPE_AP_VLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) case NL80211_IFTYPE_WDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) case NL80211_IFTYPE_MONITOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) case NL80211_IFTYPE_P2P_CLIENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) case NL80211_IFTYPE_P2P_GO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) case NL80211_IFTYPE_P2P_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) case NL80211_IFTYPE_NAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) case NUM_NL80211_IFTYPES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) ieee80211_vif_update_chandef(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) const struct cfg80211_chan_def *chandef)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) struct ieee80211_sub_if_data *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) sdata->vif.bss_conf.chandef = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) if (sdata->vif.type != NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) vlan->vif.bss_conf.chandef = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct ieee80211_vif_chanctx_switch vif_chsw[1] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) struct ieee80211_chanctx *old_ctx, *new_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) const struct cfg80211_chan_def *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) new_ctx = sdata->reserved_chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) old_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (WARN_ON(!sdata->reserved_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (WARN_ON(!new_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (WARN_ON(!old_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (WARN_ON(new_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) IEEE80211_CHANCTX_REPLACES_OTHER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) chandef = ieee80211_chanctx_non_reserved_chandef(local, new_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) &sdata->reserved_chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (WARN_ON(!chandef))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) ieee80211_change_chanctx(local, new_ctx, chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) vif_chsw[0].vif = &sdata->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) vif_chsw[0].old_ctx = &old_ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) vif_chsw[0].new_ctx = &new_ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) list_del(&sdata->reserved_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) sdata->reserved_chanctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) err = drv_switch_vif_chanctx(local, vif_chsw, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) CHANCTX_SWMODE_REASSIGN_VIF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (ieee80211_chanctx_refcount(local, new_ctx) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) ieee80211_free_chanctx(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) list_move(&sdata->assigned_chanctx_list, &new_ctx->assigned_vifs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) rcu_assign_pointer(sdata->vif.chanctx_conf, &new_ctx->conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (sdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) __ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) ieee80211_check_fast_xmit_iface(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) if (ieee80211_chanctx_refcount(local, old_ctx) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) ieee80211_free_chanctx(local, old_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (sdata->vif.bss_conf.chandef.width != sdata->reserved_chandef.width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) changed = BSS_CHANGED_BANDWIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) ieee80211_vif_update_chandef(sdata, &sdata->reserved_chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) ieee80211_recalc_smps_chanctx(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) ieee80211_recalc_radar_chanctx(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) ieee80211_recalc_chanctx_min_def(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) ieee80211_bss_info_change_notify(sdata, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) ieee80211_vif_chanctx_reservation_complete(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) struct ieee80211_chanctx *old_ctx, *new_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) const struct cfg80211_chan_def *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) old_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) new_ctx = sdata->reserved_chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) if (WARN_ON(!sdata->reserved_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (WARN_ON(old_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (WARN_ON(!new_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) if (WARN_ON(new_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) IEEE80211_CHANCTX_REPLACES_OTHER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) chandef = ieee80211_chanctx_non_reserved_chandef(local, new_ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) &sdata->reserved_chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) if (WARN_ON(!chandef))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) ieee80211_change_chanctx(local, new_ctx, chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) list_del(&sdata->reserved_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) sdata->reserved_chanctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) err = ieee80211_assign_vif_chanctx(sdata, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (ieee80211_chanctx_refcount(local, new_ctx) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) ieee80211_free_chanctx(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) ieee80211_vif_chanctx_reservation_complete(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) struct ieee80211_chanctx *old_ctx, *new_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) lockdep_assert_held(&sdata->local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) new_ctx = sdata->reserved_chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) old_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (!old_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) if (WARN_ON(!new_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (old_ctx->replace_state != IEEE80211_CHANCTX_WILL_BE_REPLACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) if (new_ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) static int ieee80211_chsw_switch_hwconf(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) struct ieee80211_chanctx *new_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) const struct cfg80211_chan_def *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) chandef = ieee80211_chanctx_reserved_chandef(local, new_ctx, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (WARN_ON(!chandef))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) local->hw.conf.radar_enabled = new_ctx->conf.radar_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) local->_oper_chandef = *chandef;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) ieee80211_hw_config(local, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) int n_vifs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) struct ieee80211_vif_chanctx_switch *vif_chsw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) struct ieee80211_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) struct ieee80211_chanctx *ctx, *old_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) vif_chsw = kcalloc(n_vifs, sizeof(vif_chsw[0]), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) if (!vif_chsw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) if (WARN_ON(!ctx->replace_ctx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) list_for_each_entry(sdata, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (!ieee80211_vif_has_in_place_reservation(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) old_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) vif_chsw[i].vif = &sdata->vif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) vif_chsw[i].old_ctx = &old_ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) vif_chsw[i].new_ctx = &ctx->conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) err = drv_switch_vif_chanctx(local, vif_chsw, n_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) CHANCTX_SWMODE_SWAP_CONTEXTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) kfree(vif_chsw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) static int ieee80211_chsw_switch_ctxs(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) if (!list_empty(&ctx->replace_ctx->assigned_vifs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) ieee80211_del_chanctx(local, ctx->replace_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) err = ieee80211_add_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) WARN_ON(ieee80211_add_chanctx(local, ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) list_for_each_entry_continue_reverse(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (!list_empty(&ctx->replace_ctx->assigned_vifs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) ieee80211_del_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) WARN_ON(ieee80211_add_chanctx(local, ctx->replace_ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) static int ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) struct ieee80211_sub_if_data *sdata, *sdata_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) struct ieee80211_chanctx *ctx, *ctx_tmp, *old_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) struct ieee80211_chanctx *new_ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) int err, n_assigned, n_reserved, n_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) int n_ctx = 0, n_vifs_switch = 0, n_vifs_assign = 0, n_vifs_ctxless = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) * If there are 2 independent pairs of channel contexts performing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) * cross-switch of their vifs this code will still wait until both are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) * ready even though it could be possible to switch one before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) * other is ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) * For practical reasons and code simplicity just do a single huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) * switch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) * Verify if the reservation is still feasible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) * - if it's not then disconnect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) * - if it is but not all vifs necessary are ready then defer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (WARN_ON(!ctx->replace_ctx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) if (!local->use_chanctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) new_ctx = ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) n_ctx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) n_assigned = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) n_reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) n_ready = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) list_for_each_entry(sdata, &ctx->replace_ctx->assigned_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) assigned_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) n_assigned++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (sdata->reserved_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) n_reserved++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (sdata->reserved_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) n_ready++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (n_assigned != n_reserved) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (n_ready == n_reserved) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) wiphy_info(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) "channel context reservation cannot be finalized because some interfaces aren't switching\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) ctx->conf.radar_enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) list_for_each_entry(sdata, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) if (ieee80211_vif_has_in_place_reservation(sdata) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) !sdata->reserved_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) old_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) if (old_ctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) if (old_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) IEEE80211_CHANCTX_WILL_BE_REPLACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) n_vifs_switch++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) n_vifs_assign++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) n_vifs_ctxless++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (sdata->reserved_radar_required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) ctx->conf.radar_enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if (WARN_ON(n_ctx == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) WARN_ON(n_vifs_switch == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) n_vifs_assign == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) n_vifs_ctxless == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) WARN_ON(n_ctx > 1 && !local->use_chanctx) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) WARN_ON(!new_ctx && !local->use_chanctx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) * All necessary vifs are ready. Perform the switch now depending on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) * reservations and driver capabilities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) if (local->use_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (n_vifs_switch > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) err = ieee80211_chsw_switch_vifs(local, n_vifs_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (n_vifs_assign > 0 || n_vifs_ctxless > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) err = ieee80211_chsw_switch_ctxs(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) err = ieee80211_chsw_switch_hwconf(local, new_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) * Update all structures, values and pointers to point to new channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) * context(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) if (WARN_ON(!ctx->replace_ctx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) list_for_each_entry(sdata, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) u32 changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (!ieee80211_vif_has_in_place_reservation(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) rcu_assign_pointer(sdata->vif.chanctx_conf, &ctx->conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if (sdata->vif.type == NL80211_IFTYPE_AP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) __ieee80211_vif_copy_chanctx_to_vlans(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) ieee80211_check_fast_xmit_iface(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) sdata->radar_required = sdata->reserved_radar_required;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) if (sdata->vif.bss_conf.chandef.width !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) sdata->reserved_chandef.width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) changed = BSS_CHANGED_BANDWIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) ieee80211_vif_update_chandef(sdata, &sdata->reserved_chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) ieee80211_bss_info_change_notify(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) ieee80211_recalc_txpower(sdata, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) ieee80211_recalc_chanctx_chantype(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) ieee80211_recalc_smps_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) ieee80211_recalc_radar_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) ieee80211_recalc_chanctx_min_def(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) if (ieee80211_vif_get_chanctx(sdata) != ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) list_del(&sdata->reserved_chanctx_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) list_move(&sdata->assigned_chanctx_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) &ctx->assigned_vifs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) sdata->reserved_chanctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) ieee80211_vif_chanctx_reservation_complete(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * This context might have been a dependency for an already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * ready re-assign reservation interface that was deferred. Do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * not propagate error to the caller though. The in-place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * reservation for originally requested interface has already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) * succeeded at this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) if (WARN_ON(ieee80211_vif_has_in_place_reservation(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) sdata)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) if (WARN_ON(sdata->reserved_chanctx != ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (!sdata->reserved_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) if (ieee80211_vif_get_chanctx(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) err = ieee80211_vif_use_reserved_reassign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) err = ieee80211_vif_use_reserved_assign(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) sdata_info(sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) "failed to finalize (re-)assign reservation (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) ieee80211_vif_unreserve_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) cfg80211_stop_iface(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) &sdata->wdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * Finally free old contexts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) list_for_each_entry_safe(ctx, ctx_tmp, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) if (ctx->replace_state != IEEE80211_CHANCTX_WILL_BE_REPLACED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) ctx->replace_ctx->replace_ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) ctx->replace_ctx->replace_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) IEEE80211_CHANCTX_REPLACE_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) list_del_rcu(&ctx->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) kfree_rcu(ctx, rcu_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) list_for_each_entry(ctx, &local->chanctx_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) reserved_chanctx_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) ieee80211_vif_unreserve_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) ieee80211_vif_chanctx_reservation_complete(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) bool use_reserved_switch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) if (!conf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) ctx = container_of(conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (sdata->reserved_chanctx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) if (sdata->reserved_chanctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) IEEE80211_CHANCTX_REPLACES_OTHER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) ieee80211_chanctx_num_reserved(local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) sdata->reserved_chanctx) > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) use_reserved_switch = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) ieee80211_vif_unreserve_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) ieee80211_assign_vif_chanctx(sdata, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) if (ieee80211_chanctx_refcount(local, ctx) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) ieee80211_free_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) sdata->radar_required = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) /* Unreserving may ready an in-place reservation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) if (use_reserved_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) ieee80211_vif_use_reserved_switch(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) enum ieee80211_chanctx_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) u8 radar_detect_width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) ret = cfg80211_chandef_dfs_required(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) sdata->wdev.iftype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) radar_detect_width = BIT(chandef->width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) sdata->radar_required = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) ret = ieee80211_check_combinations(sdata, chandef, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) radar_detect_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) __ieee80211_vif_release_channel(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) ctx = ieee80211_find_chanctx(local, chandef, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) ctx = ieee80211_new_chanctx(local, chandef, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) if (IS_ERR(ctx)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) ret = PTR_ERR(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) ieee80211_vif_update_chandef(sdata, chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) ret = ieee80211_assign_vif_chanctx(sdata, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) /* if assign fails refcount stays the same */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) if (ieee80211_chanctx_refcount(local, ctx) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) ieee80211_free_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) ieee80211_recalc_smps_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) ieee80211_recalc_radar_chanctx(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) sdata->radar_required = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) struct ieee80211_chanctx *new_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) struct ieee80211_chanctx *old_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) lockdep_assert_held(&local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) lockdep_assert_held(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) new_ctx = sdata->reserved_chanctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) old_ctx = ieee80211_vif_get_chanctx(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) if (WARN_ON(!new_ctx))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) if (WARN_ON(new_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) IEEE80211_CHANCTX_WILL_BE_REPLACED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) if (WARN_ON(sdata->reserved_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) sdata->reserved_ready = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if (new_ctx->replace_state == IEEE80211_CHANCTX_REPLACE_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) if (old_ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) err = ieee80211_vif_use_reserved_reassign(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) err = ieee80211_vif_use_reserved_assign(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) * In-place reservation may need to be finalized now either if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) * a) sdata is taking part in the swapping itself and is the last one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) * b) sdata has switched with a re-assign reservation to an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) * context readying in-place switching of old_ctx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) * In case of (b) do not propagate the error up because the requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) * sdata already switched successfully. Just spill an extra warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) * The ieee80211_vif_use_reserved_switch() already stops all necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) * interfaces upon failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) if ((old_ctx &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) old_ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) new_ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) err = ieee80211_vif_use_reserved_switch(local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (err && err != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) if (new_ctx->replace_state ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) IEEE80211_CHANCTX_REPLACES_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) wiphy_info(local->hw.wiphy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) "depending in-place reservation failed (err=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) const struct cfg80211_chan_def *chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) u32 *changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) const struct cfg80211_chan_def *compat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) IEEE80211_CHAN_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) if (cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) if (chandef->width == NL80211_CHAN_WIDTH_20_NOHT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if (!conf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) ctx = container_of(conf, struct ieee80211_chanctx, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) compat = cfg80211_chandef_compatible(&conf->def, chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) if (!compat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) switch (ctx->replace_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) case IEEE80211_CHANCTX_REPLACE_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) if (!ieee80211_chanctx_reserved_chandef(local, ctx, compat)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) case IEEE80211_CHANCTX_WILL_BE_REPLACED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) /* TODO: Perhaps the bandwidth change could be treated as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) * reservation itself? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) case IEEE80211_CHANCTX_REPLACES_OTHER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) /* channel context that is going to replace another channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) * context doesn't really exist and shouldn't be assigned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) * anywhere yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) ieee80211_vif_update_chandef(sdata, chandef);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) ieee80211_recalc_chanctx_chantype(local, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) *changed |= BSS_CHANGED_BANDWIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) lockdep_assert_held(&sdata->local->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) mutex_lock(&sdata->local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) __ieee80211_vif_release_channel(sdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) mutex_unlock(&sdata->local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) struct ieee80211_local *local = sdata->local;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) struct ieee80211_sub_if_data *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) struct ieee80211_chanctx_conf *conf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->bss))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) mutex_lock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) conf = rcu_dereference_protected(ap->vif.chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) lockdep_is_held(&local->chanctx_mtx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) rcu_assign_pointer(sdata->vif.chanctx_conf, conf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) mutex_unlock(&local->chanctx_mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) void ieee80211_iter_chan_contexts_atomic(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) void (*iter)(struct ieee80211_hw *hw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) struct ieee80211_chanctx_conf *chanctx_conf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) void *data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) void *iter_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) struct ieee80211_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) struct ieee80211_chanctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) list_for_each_entry_rcu(ctx, &local->chanctx_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) if (ctx->driver_present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) iter(hw, &ctx->conf, iter_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic);