2 * mac80211 - channel management
5 #include <linux/nl80211.h>
6 #include <linux/export.h>
7 #include <linux/rtnetlink.h>
8 #include <net/cfg80211.h>
9 #include "ieee80211_i.h"
10 #include "driver-ops.h"
12 static int ieee80211_chanctx_num_assigned(struct ieee80211_local *local,
13 struct ieee80211_chanctx *ctx)
15 struct ieee80211_sub_if_data *sdata;
18 lockdep_assert_held(&local->chanctx_mtx);
20 list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list)
26 static int ieee80211_chanctx_num_reserved(struct ieee80211_local *local,
27 struct ieee80211_chanctx *ctx)
29 struct ieee80211_sub_if_data *sdata;
32 lockdep_assert_held(&local->chanctx_mtx);
34 list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list)
40 int ieee80211_chanctx_refcount(struct ieee80211_local *local,
41 struct ieee80211_chanctx *ctx)
43 return ieee80211_chanctx_num_assigned(local, ctx) +
44 ieee80211_chanctx_num_reserved(local, ctx);
47 static int ieee80211_num_chanctx(struct ieee80211_local *local)
49 struct ieee80211_chanctx *ctx;
52 lockdep_assert_held(&local->chanctx_mtx);
54 list_for_each_entry(ctx, &local->chanctx_list, list)
60 static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local)
62 lockdep_assert_held(&local->chanctx_mtx);
63 return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local);
66 static struct ieee80211_chanctx *
67 ieee80211_vif_get_chanctx(struct ieee80211_sub_if_data *sdata)
69 struct ieee80211_local *local __maybe_unused = sdata->local;
70 struct ieee80211_chanctx_conf *conf;
72 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
73 lockdep_is_held(&local->chanctx_mtx));
77 return container_of(conf, struct ieee80211_chanctx, conf);
80 static const struct cfg80211_chan_def *
81 ieee80211_chanctx_reserved_chandef(struct ieee80211_local *local,
82 struct ieee80211_chanctx *ctx,
83 const struct cfg80211_chan_def *compat)
85 struct ieee80211_sub_if_data *sdata;
87 lockdep_assert_held(&local->chanctx_mtx);
89 list_for_each_entry(sdata, &ctx->reserved_vifs,
90 reserved_chanctx_list) {
92 compat = &sdata->reserved_chandef;
94 compat = cfg80211_chandef_compatible(&sdata->reserved_chandef,
103 static const struct cfg80211_chan_def *
104 ieee80211_chanctx_non_reserved_chandef(struct ieee80211_local *local,
105 struct ieee80211_chanctx *ctx,
106 const struct cfg80211_chan_def *compat)
108 struct ieee80211_sub_if_data *sdata;
110 lockdep_assert_held(&local->chanctx_mtx);
112 list_for_each_entry(sdata, &ctx->assigned_vifs,
113 assigned_chanctx_list) {
114 if (sdata->reserved_chanctx != NULL)
118 compat = &sdata->vif.bss_conf.chandef;
120 compat = cfg80211_chandef_compatible(
121 &sdata->vif.bss_conf.chandef, compat);
129 static const struct cfg80211_chan_def *
130 ieee80211_chanctx_combined_chandef(struct ieee80211_local *local,
131 struct ieee80211_chanctx *ctx,
132 const struct cfg80211_chan_def *compat)
134 lockdep_assert_held(&local->chanctx_mtx);
136 compat = ieee80211_chanctx_reserved_chandef(local, ctx, compat);
140 compat = ieee80211_chanctx_non_reserved_chandef(local, ctx, compat);
148 ieee80211_chanctx_can_reserve_chandef(struct ieee80211_local *local,
149 struct ieee80211_chanctx *ctx,
150 const struct cfg80211_chan_def *def)
152 lockdep_assert_held(&local->chanctx_mtx);
154 if (ieee80211_chanctx_combined_chandef(local, ctx, def))
157 if (!list_empty(&ctx->reserved_vifs) &&
158 ieee80211_chanctx_reserved_chandef(local, ctx, def))
164 static struct ieee80211_chanctx *
165 ieee80211_find_reservation_chanctx(struct ieee80211_local *local,
166 const struct cfg80211_chan_def *chandef,
167 enum ieee80211_chanctx_mode mode)
169 struct ieee80211_chanctx *ctx;
171 lockdep_assert_held(&local->chanctx_mtx);
173 if (mode == IEEE80211_CHANCTX_EXCLUSIVE)
176 list_for_each_entry(ctx, &local->chanctx_list, list) {
177 if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
180 if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE)
183 if (!ieee80211_chanctx_can_reserve_chandef(local, ctx,
193 static enum nl80211_chan_width ieee80211_get_sta_bw(struct ieee80211_sta *sta)
195 switch (sta->bandwidth) {
196 case IEEE80211_STA_RX_BW_20:
197 if (sta->ht_cap.ht_supported)
198 return NL80211_CHAN_WIDTH_20;
200 return NL80211_CHAN_WIDTH_20_NOHT;
201 case IEEE80211_STA_RX_BW_40:
202 return NL80211_CHAN_WIDTH_40;
203 case IEEE80211_STA_RX_BW_80:
204 return NL80211_CHAN_WIDTH_80;
205 case IEEE80211_STA_RX_BW_160:
207 * This applied for both 160 and 80+80. since we use
208 * the returned value to consider degradation of
209 * ctx->conf.min_def, we have to make sure to take
210 * the bigger one (NL80211_CHAN_WIDTH_160).
211 * Otherwise we might try degrading even when not
212 * needed, as the max required sta_bw returned (80+80)
213 * might be smaller than the configured bw (160).
215 return NL80211_CHAN_WIDTH_160;
218 return NL80211_CHAN_WIDTH_20;
222 static enum nl80211_chan_width
223 ieee80211_get_max_required_bw(struct ieee80211_sub_if_data *sdata)
225 enum nl80211_chan_width max_bw = NL80211_CHAN_WIDTH_20_NOHT;
226 struct sta_info *sta;
229 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
230 if (sdata != sta->sdata &&
231 !(sta->sdata->bss && sta->sdata->bss == sdata->bss))
237 max_bw = max(max_bw, ieee80211_get_sta_bw(&sta->sta));
244 static enum nl80211_chan_width
245 ieee80211_get_chanctx_max_required_bw(struct ieee80211_local *local,
246 struct ieee80211_chanctx_conf *conf)
248 struct ieee80211_sub_if_data *sdata;
249 enum nl80211_chan_width max_bw = NL80211_CHAN_WIDTH_20_NOHT;
252 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
253 struct ieee80211_vif *vif = &sdata->vif;
254 enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20_NOHT;
256 if (!ieee80211_sdata_running(sdata))
259 if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf)
263 case NL80211_IFTYPE_AP:
264 case NL80211_IFTYPE_AP_VLAN:
265 width = ieee80211_get_max_required_bw(sdata);
267 case NL80211_IFTYPE_P2P_DEVICE:
269 case NL80211_IFTYPE_STATION:
270 case NL80211_IFTYPE_ADHOC:
271 case NL80211_IFTYPE_WDS:
272 case NL80211_IFTYPE_MESH_POINT:
273 width = vif->bss_conf.chandef.width;
275 case NL80211_IFTYPE_UNSPECIFIED:
276 case NUM_NL80211_IFTYPES:
277 case NL80211_IFTYPE_MONITOR:
278 case NL80211_IFTYPE_P2P_CLIENT:
279 case NL80211_IFTYPE_P2P_GO:
282 max_bw = max(max_bw, width);
285 /* use the configured bandwidth in case of monitor interface */
286 sdata = rcu_dereference(local->monitor_sdata);
287 if (sdata && rcu_access_pointer(sdata->vif.chanctx_conf) == conf)
288 max_bw = max(max_bw, conf->def.width);
296 * recalc the min required chan width of the channel context, which is
297 * the max of min required widths of all the interfaces bound to this
300 void ieee80211_recalc_chanctx_min_def(struct ieee80211_local *local,
301 struct ieee80211_chanctx *ctx)
303 enum nl80211_chan_width max_bw;
304 struct cfg80211_chan_def min_def;
306 lockdep_assert_held(&local->chanctx_mtx);
308 /* don't optimize 5MHz, 10MHz, and radar_enabled confs */
309 if (ctx->conf.def.width == NL80211_CHAN_WIDTH_5 ||
310 ctx->conf.def.width == NL80211_CHAN_WIDTH_10 ||
311 ctx->conf.radar_enabled) {
312 ctx->conf.min_def = ctx->conf.def;
316 max_bw = ieee80211_get_chanctx_max_required_bw(local, &ctx->conf);
318 /* downgrade chandef up to max_bw */
319 min_def = ctx->conf.def;
320 while (min_def.width > max_bw)
321 ieee80211_chandef_downgrade(&min_def);
323 if (cfg80211_chandef_identical(&ctx->conf.min_def, &min_def))
326 ctx->conf.min_def = min_def;
327 if (!ctx->driver_present)
330 drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_MIN_WIDTH);
333 static void ieee80211_change_chanctx(struct ieee80211_local *local,
334 struct ieee80211_chanctx *ctx,
335 const struct cfg80211_chan_def *chandef)
337 if (cfg80211_chandef_identical(&ctx->conf.def, chandef))
340 WARN_ON(!cfg80211_chandef_compatible(&ctx->conf.def, chandef));
342 ctx->conf.def = *chandef;
343 drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_WIDTH);
344 ieee80211_recalc_chanctx_min_def(local, ctx);
346 if (!local->use_chanctx) {
347 local->_oper_chandef = *chandef;
348 ieee80211_hw_config(local, 0);
352 static struct ieee80211_chanctx *
353 ieee80211_find_chanctx(struct ieee80211_local *local,
354 const struct cfg80211_chan_def *chandef,
355 enum ieee80211_chanctx_mode mode)
357 struct ieee80211_chanctx *ctx;
359 lockdep_assert_held(&local->chanctx_mtx);
361 if (mode == IEEE80211_CHANCTX_EXCLUSIVE)
364 list_for_each_entry(ctx, &local->chanctx_list, list) {
365 const struct cfg80211_chan_def *compat;
367 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACE_NONE)
370 if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE)
373 compat = cfg80211_chandef_compatible(&ctx->conf.def, chandef);
377 compat = ieee80211_chanctx_reserved_chandef(local, ctx,
382 ieee80211_change_chanctx(local, ctx, compat);
390 static bool ieee80211_is_radar_required(struct ieee80211_local *local)
392 struct ieee80211_sub_if_data *sdata;
394 lockdep_assert_held(&local->mtx);
397 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
398 if (sdata->radar_required) {
408 static struct ieee80211_chanctx *
409 ieee80211_alloc_chanctx(struct ieee80211_local *local,
410 const struct cfg80211_chan_def *chandef,
411 enum ieee80211_chanctx_mode mode)
413 struct ieee80211_chanctx *ctx;
415 lockdep_assert_held(&local->chanctx_mtx);
417 ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL);
421 INIT_LIST_HEAD(&ctx->assigned_vifs);
422 INIT_LIST_HEAD(&ctx->reserved_vifs);
423 ctx->conf.def = *chandef;
424 ctx->conf.rx_chains_static = 1;
425 ctx->conf.rx_chains_dynamic = 1;
427 ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
428 ieee80211_recalc_chanctx_min_def(local, ctx);
433 static int ieee80211_add_chanctx(struct ieee80211_local *local,
434 struct ieee80211_chanctx *ctx)
439 lockdep_assert_held(&local->mtx);
440 lockdep_assert_held(&local->chanctx_mtx);
442 if (!local->use_chanctx)
443 local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
445 /* turn idle off *before* setting channel -- some drivers need that */
446 changed = ieee80211_idle_off(local);
448 ieee80211_hw_config(local, changed);
450 if (!local->use_chanctx) {
451 local->_oper_chandef = ctx->conf.def;
452 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
454 err = drv_add_chanctx(local, ctx);
456 ieee80211_recalc_idle(local);
464 static struct ieee80211_chanctx *
465 ieee80211_new_chanctx(struct ieee80211_local *local,
466 const struct cfg80211_chan_def *chandef,
467 enum ieee80211_chanctx_mode mode)
469 struct ieee80211_chanctx *ctx;
472 lockdep_assert_held(&local->mtx);
473 lockdep_assert_held(&local->chanctx_mtx);
475 ctx = ieee80211_alloc_chanctx(local, chandef, mode);
477 return ERR_PTR(-ENOMEM);
479 err = ieee80211_add_chanctx(local, ctx);
485 list_add_rcu(&ctx->list, &local->chanctx_list);
489 static void ieee80211_del_chanctx(struct ieee80211_local *local,
490 struct ieee80211_chanctx *ctx)
492 lockdep_assert_held(&local->chanctx_mtx);
494 if (!local->use_chanctx) {
495 struct cfg80211_chan_def *chandef = &local->_oper_chandef;
496 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
497 chandef->center_freq1 = chandef->chan->center_freq;
498 chandef->center_freq2 = 0;
500 /* NOTE: Disabling radar is only valid here for
501 * single channel context. To be sure, check it ...
503 WARN_ON(local->hw.conf.radar_enabled &&
504 !list_empty(&local->chanctx_list));
506 local->hw.conf.radar_enabled = false;
508 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
510 drv_remove_chanctx(local, ctx);
513 ieee80211_recalc_idle(local);
516 static void ieee80211_free_chanctx(struct ieee80211_local *local,
517 struct ieee80211_chanctx *ctx)
519 lockdep_assert_held(&local->chanctx_mtx);
521 WARN_ON_ONCE(ieee80211_chanctx_refcount(local, ctx) != 0);
523 list_del_rcu(&ctx->list);
524 ieee80211_del_chanctx(local, ctx);
525 kfree_rcu(ctx, rcu_head);
528 static void ieee80211_recalc_chanctx_chantype(struct ieee80211_local *local,
529 struct ieee80211_chanctx *ctx)
531 struct ieee80211_chanctx_conf *conf = &ctx->conf;
532 struct ieee80211_sub_if_data *sdata;
533 const struct cfg80211_chan_def *compat = NULL;
535 lockdep_assert_held(&local->chanctx_mtx);
538 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
540 if (!ieee80211_sdata_running(sdata))
542 if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf)
544 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
548 compat = &sdata->vif.bss_conf.chandef;
550 compat = cfg80211_chandef_compatible(
551 &sdata->vif.bss_conf.chandef, compat);
557 if (WARN_ON_ONCE(!compat))
560 ieee80211_change_chanctx(local, ctx, compat);
563 static void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
564 struct ieee80211_chanctx *chanctx)
568 lockdep_assert_held(&local->chanctx_mtx);
569 /* for setting local->radar_detect_enabled */
570 lockdep_assert_held(&local->mtx);
572 radar_enabled = ieee80211_is_radar_required(local);
574 if (radar_enabled == chanctx->conf.radar_enabled)
577 chanctx->conf.radar_enabled = radar_enabled;
578 local->radar_detect_enabled = chanctx->conf.radar_enabled;
580 if (!local->use_chanctx) {
581 local->hw.conf.radar_enabled = chanctx->conf.radar_enabled;
582 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
585 drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RADAR);
588 static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata,
589 struct ieee80211_chanctx *new_ctx)
591 struct ieee80211_local *local = sdata->local;
592 struct ieee80211_chanctx_conf *conf;
593 struct ieee80211_chanctx *curr_ctx = NULL;
596 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
597 lockdep_is_held(&local->chanctx_mtx));
600 curr_ctx = container_of(conf, struct ieee80211_chanctx, conf);
602 drv_unassign_vif_chanctx(local, sdata, curr_ctx);
604 list_del(&sdata->assigned_chanctx_list);
608 ret = drv_assign_vif_chanctx(local, sdata, new_ctx);
612 conf = &new_ctx->conf;
613 list_add(&sdata->assigned_chanctx_list,
614 &new_ctx->assigned_vifs);
618 rcu_assign_pointer(sdata->vif.chanctx_conf, conf);
620 sdata->vif.bss_conf.idle = !conf;
622 if (curr_ctx && ieee80211_chanctx_num_assigned(local, curr_ctx) > 0) {
623 ieee80211_recalc_chanctx_chantype(local, curr_ctx);
624 ieee80211_recalc_smps_chanctx(local, curr_ctx);
625 ieee80211_recalc_radar_chanctx(local, curr_ctx);
626 ieee80211_recalc_chanctx_min_def(local, curr_ctx);
629 if (new_ctx && ieee80211_chanctx_num_assigned(local, new_ctx) > 0) {
630 ieee80211_recalc_txpower(sdata);
631 ieee80211_recalc_chanctx_min_def(local, new_ctx);
634 if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
635 sdata->vif.type != NL80211_IFTYPE_MONITOR)
636 ieee80211_bss_info_change_notify(sdata,
642 static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
644 struct ieee80211_local *local = sdata->local;
645 struct ieee80211_chanctx_conf *conf;
646 struct ieee80211_chanctx *ctx;
647 bool use_reserved_switch = false;
649 lockdep_assert_held(&local->chanctx_mtx);
651 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
652 lockdep_is_held(&local->chanctx_mtx));
656 ctx = container_of(conf, struct ieee80211_chanctx, conf);
658 if (sdata->reserved_chanctx) {
659 if (sdata->reserved_chanctx->replace_state ==
660 IEEE80211_CHANCTX_REPLACES_OTHER &&
661 ieee80211_chanctx_num_reserved(local,
662 sdata->reserved_chanctx) > 1)
663 use_reserved_switch = true;
665 ieee80211_vif_unreserve_chanctx(sdata);
668 ieee80211_assign_vif_chanctx(sdata, NULL);
669 if (ieee80211_chanctx_refcount(local, ctx) == 0)
670 ieee80211_free_chanctx(local, ctx);
672 /* Unreserving may ready an in-place reservation. */
673 if (use_reserved_switch)
674 ieee80211_vif_use_reserved_switch(local);
677 void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
678 struct ieee80211_chanctx *chanctx)
680 struct ieee80211_sub_if_data *sdata;
681 u8 rx_chains_static, rx_chains_dynamic;
683 lockdep_assert_held(&local->chanctx_mtx);
685 rx_chains_static = 1;
686 rx_chains_dynamic = 1;
689 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
690 u8 needed_static, needed_dynamic;
692 if (!ieee80211_sdata_running(sdata))
695 if (rcu_access_pointer(sdata->vif.chanctx_conf) !=
699 switch (sdata->vif.type) {
700 case NL80211_IFTYPE_P2P_DEVICE:
702 case NL80211_IFTYPE_STATION:
703 if (!sdata->u.mgd.associated)
706 case NL80211_IFTYPE_AP_VLAN:
708 case NL80211_IFTYPE_AP:
709 case NL80211_IFTYPE_ADHOC:
710 case NL80211_IFTYPE_WDS:
711 case NL80211_IFTYPE_MESH_POINT:
717 switch (sdata->smps_mode) {
719 WARN_ONCE(1, "Invalid SMPS mode %d\n",
722 case IEEE80211_SMPS_OFF:
723 needed_static = sdata->needed_rx_chains;
724 needed_dynamic = sdata->needed_rx_chains;
726 case IEEE80211_SMPS_DYNAMIC:
728 needed_dynamic = sdata->needed_rx_chains;
730 case IEEE80211_SMPS_STATIC:
736 rx_chains_static = max(rx_chains_static, needed_static);
737 rx_chains_dynamic = max(rx_chains_dynamic, needed_dynamic);
740 /* Disable SMPS for the monitor interface */
741 sdata = rcu_dereference(local->monitor_sdata);
743 rcu_access_pointer(sdata->vif.chanctx_conf) == &chanctx->conf)
744 rx_chains_dynamic = rx_chains_static = local->rx_chains;
748 if (!local->use_chanctx) {
749 if (rx_chains_static > 1)
750 local->smps_mode = IEEE80211_SMPS_OFF;
751 else if (rx_chains_dynamic > 1)
752 local->smps_mode = IEEE80211_SMPS_DYNAMIC;
754 local->smps_mode = IEEE80211_SMPS_STATIC;
755 ieee80211_hw_config(local, 0);
758 if (rx_chains_static == chanctx->conf.rx_chains_static &&
759 rx_chains_dynamic == chanctx->conf.rx_chains_dynamic)
762 chanctx->conf.rx_chains_static = rx_chains_static;
763 chanctx->conf.rx_chains_dynamic = rx_chains_dynamic;
764 drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RX_CHAINS);
767 int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
768 const struct cfg80211_chan_def *chandef,
769 enum ieee80211_chanctx_mode mode)
771 struct ieee80211_local *local = sdata->local;
772 struct ieee80211_chanctx *ctx;
773 u8 radar_detect_width = 0;
776 lockdep_assert_held(&local->mtx);
778 WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
780 mutex_lock(&local->chanctx_mtx);
782 ret = cfg80211_chandef_dfs_required(local->hw.wiphy,
788 radar_detect_width = BIT(chandef->width);
790 sdata->radar_required = ret;
792 ret = ieee80211_check_combinations(sdata, chandef, mode,
797 __ieee80211_vif_release_channel(sdata);
799 ctx = ieee80211_find_chanctx(local, chandef, mode);
801 ctx = ieee80211_new_chanctx(local, chandef, mode);
807 sdata->vif.bss_conf.chandef = *chandef;
809 ret = ieee80211_assign_vif_chanctx(sdata, ctx);
811 /* if assign fails refcount stays the same */
812 if (ieee80211_chanctx_refcount(local, ctx) == 0)
813 ieee80211_free_chanctx(local, ctx);
817 ieee80211_recalc_smps_chanctx(local, ctx);
818 ieee80211_recalc_radar_chanctx(local, ctx);
820 mutex_unlock(&local->chanctx_mtx);
825 __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
828 struct ieee80211_local *local __maybe_unused = sdata->local;
829 struct ieee80211_sub_if_data *vlan;
830 struct ieee80211_chanctx_conf *conf;
832 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP))
835 lockdep_assert_held(&local->mtx);
837 /* Check that conf exists, even when clearing this function
838 * must be called with the AP's channel context still there
839 * as it would otherwise cause VLANs to have an invalid
840 * channel context pointer for a while, possibly pointing
841 * to a channel context that has already been freed.
843 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
844 lockdep_is_held(&local->chanctx_mtx));
850 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
851 rcu_assign_pointer(vlan->vif.chanctx_conf, conf);
854 void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
857 struct ieee80211_local *local = sdata->local;
859 mutex_lock(&local->chanctx_mtx);
861 __ieee80211_vif_copy_chanctx_to_vlans(sdata, clear);
863 mutex_unlock(&local->chanctx_mtx);
866 int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata)
868 struct ieee80211_chanctx *ctx = sdata->reserved_chanctx;
870 lockdep_assert_held(&sdata->local->chanctx_mtx);
875 list_del(&sdata->reserved_chanctx_list);
876 sdata->reserved_chanctx = NULL;
878 if (ieee80211_chanctx_refcount(sdata->local, ctx) == 0) {
879 if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER) {
880 if (WARN_ON(!ctx->replace_ctx))
883 WARN_ON(ctx->replace_ctx->replace_state !=
884 IEEE80211_CHANCTX_WILL_BE_REPLACED);
885 WARN_ON(ctx->replace_ctx->replace_ctx != ctx);
887 ctx->replace_ctx->replace_ctx = NULL;
888 ctx->replace_ctx->replace_state =
889 IEEE80211_CHANCTX_REPLACE_NONE;
891 list_del_rcu(&ctx->list);
892 kfree_rcu(ctx, rcu_head);
894 ieee80211_free_chanctx(sdata->local, ctx);
901 int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata,
902 const struct cfg80211_chan_def *chandef,
903 enum ieee80211_chanctx_mode mode,
906 struct ieee80211_local *local = sdata->local;
907 struct ieee80211_chanctx *new_ctx, *curr_ctx, *ctx;
909 lockdep_assert_held(&local->chanctx_mtx);
911 curr_ctx = ieee80211_vif_get_chanctx(sdata);
912 if (curr_ctx && local->use_chanctx && !local->ops->switch_vif_chanctx)
915 new_ctx = ieee80211_find_reservation_chanctx(local, chandef, mode);
917 if (ieee80211_can_create_new_chanctx(local)) {
918 new_ctx = ieee80211_new_chanctx(local, chandef, mode);
920 return PTR_ERR(new_ctx);
923 (curr_ctx->replace_state ==
924 IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
925 !list_empty(&curr_ctx->reserved_vifs)) {
927 * Another vif already requested this context
928 * for a reservation. Find another one hoping
929 * all vifs assigned to it will also switch
932 * TODO: This needs a little more work as some
933 * cases (more than 2 chanctx capable devices)
934 * may fail which could otherwise succeed
935 * provided some channel context juggling was
938 * Consider ctx1..3, vif1..6, each ctx has 2
939 * vifs. vif1 and vif2 from ctx1 request new
940 * different chandefs starting 2 in-place
941 * reserations with ctx4 and ctx5 replacing
942 * ctx1 and ctx2 respectively. Next vif5 and
943 * vif6 from ctx3 reserve ctx4. If vif3 and
944 * vif4 remain on ctx2 as they are then this
945 * fails unless `replace_ctx` from ctx5 is
946 * replaced with ctx3.
948 list_for_each_entry(ctx, &local->chanctx_list,
950 if (ctx->replace_state !=
951 IEEE80211_CHANCTX_REPLACE_NONE)
954 if (!list_empty(&ctx->reserved_vifs))
963 * If that's true then all available contexts already
964 * have reservations and cannot be used.
967 (curr_ctx->replace_state ==
968 IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
969 !list_empty(&curr_ctx->reserved_vifs))
972 new_ctx = ieee80211_alloc_chanctx(local, chandef, mode);
976 new_ctx->replace_ctx = curr_ctx;
977 new_ctx->replace_state =
978 IEEE80211_CHANCTX_REPLACES_OTHER;
980 curr_ctx->replace_ctx = new_ctx;
981 curr_ctx->replace_state =
982 IEEE80211_CHANCTX_WILL_BE_REPLACED;
984 list_add_rcu(&new_ctx->list, &local->chanctx_list);
988 list_add(&sdata->reserved_chanctx_list, &new_ctx->reserved_vifs);
989 sdata->reserved_chanctx = new_ctx;
990 sdata->reserved_chandef = *chandef;
991 sdata->reserved_radar_required = radar_required;
992 sdata->reserved_ready = false;
998 ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata)
1000 switch (sdata->vif.type) {
1001 case NL80211_IFTYPE_ADHOC:
1002 case NL80211_IFTYPE_AP:
1003 case NL80211_IFTYPE_MESH_POINT:
1004 ieee80211_queue_work(&sdata->local->hw,
1005 &sdata->csa_finalize_work);
1007 case NL80211_IFTYPE_STATION:
1008 ieee80211_queue_work(&sdata->local->hw,
1009 &sdata->u.mgd.chswitch_work);
1011 case NL80211_IFTYPE_UNSPECIFIED:
1012 case NL80211_IFTYPE_AP_VLAN:
1013 case NL80211_IFTYPE_WDS:
1014 case NL80211_IFTYPE_MONITOR:
1015 case NL80211_IFTYPE_P2P_CLIENT:
1016 case NL80211_IFTYPE_P2P_GO:
1017 case NL80211_IFTYPE_P2P_DEVICE:
1018 case NUM_NL80211_IFTYPES:
1025 ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata)
1027 struct ieee80211_local *local = sdata->local;
1028 struct ieee80211_vif_chanctx_switch vif_chsw[1] = {};
1029 struct ieee80211_chanctx *old_ctx, *new_ctx;
1030 const struct cfg80211_chan_def *chandef;
1034 lockdep_assert_held(&local->mtx);
1035 lockdep_assert_held(&local->chanctx_mtx);
1037 new_ctx = sdata->reserved_chanctx;
1038 old_ctx = ieee80211_vif_get_chanctx(sdata);
1040 if (WARN_ON(!sdata->reserved_ready))
1043 if (WARN_ON(!new_ctx))
1046 if (WARN_ON(!old_ctx))
1049 if (WARN_ON(new_ctx->replace_state ==
1050 IEEE80211_CHANCTX_REPLACES_OTHER))
1053 chandef = ieee80211_chanctx_non_reserved_chandef(local, new_ctx,
1054 &sdata->reserved_chandef);
1055 if (WARN_ON(!chandef))
1058 vif_chsw[0].vif = &sdata->vif;
1059 vif_chsw[0].old_ctx = &old_ctx->conf;
1060 vif_chsw[0].new_ctx = &new_ctx->conf;
1062 list_del(&sdata->reserved_chanctx_list);
1063 sdata->reserved_chanctx = NULL;
1065 err = drv_switch_vif_chanctx(local, vif_chsw, 1,
1066 CHANCTX_SWMODE_REASSIGN_VIF);
1068 if (ieee80211_chanctx_refcount(local, new_ctx) == 0)
1069 ieee80211_free_chanctx(local, new_ctx);
1074 list_move(&sdata->assigned_chanctx_list, &new_ctx->assigned_vifs);
1075 rcu_assign_pointer(sdata->vif.chanctx_conf, &new_ctx->conf);
1077 if (sdata->vif.type == NL80211_IFTYPE_AP)
1078 __ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
1080 if (ieee80211_chanctx_refcount(local, old_ctx) == 0)
1081 ieee80211_free_chanctx(local, old_ctx);
1083 if (sdata->vif.bss_conf.chandef.width != sdata->reserved_chandef.width)
1084 changed = BSS_CHANGED_BANDWIDTH;
1086 sdata->vif.bss_conf.chandef = sdata->reserved_chandef;
1089 ieee80211_bss_info_change_notify(sdata, changed);
1092 ieee80211_vif_chanctx_reservation_complete(sdata);
1097 ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data *sdata)
1099 struct ieee80211_local *local = sdata->local;
1100 struct ieee80211_chanctx *old_ctx, *new_ctx;
1101 const struct cfg80211_chan_def *chandef;
1104 old_ctx = ieee80211_vif_get_chanctx(sdata);
1105 new_ctx = sdata->reserved_chanctx;
1107 if (WARN_ON(!sdata->reserved_ready))
1110 if (WARN_ON(old_ctx))
1113 if (WARN_ON(!new_ctx))
1116 if (WARN_ON(new_ctx->replace_state ==
1117 IEEE80211_CHANCTX_REPLACES_OTHER))
1120 chandef = ieee80211_chanctx_non_reserved_chandef(local, new_ctx,
1121 &sdata->reserved_chandef);
1122 if (WARN_ON(!chandef))
1125 list_del(&sdata->reserved_chanctx_list);
1126 sdata->reserved_chanctx = NULL;
1128 err = ieee80211_assign_vif_chanctx(sdata, new_ctx);
1130 if (ieee80211_chanctx_refcount(local, new_ctx) == 0)
1131 ieee80211_free_chanctx(local, new_ctx);
1137 ieee80211_vif_chanctx_reservation_complete(sdata);
1142 ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data *sdata)
1144 struct ieee80211_chanctx *old_ctx, *new_ctx;
1146 lockdep_assert_held(&sdata->local->chanctx_mtx);
1148 new_ctx = sdata->reserved_chanctx;
1149 old_ctx = ieee80211_vif_get_chanctx(sdata);
1154 if (WARN_ON(!new_ctx))
1157 if (old_ctx->replace_state != IEEE80211_CHANCTX_WILL_BE_REPLACED)
1160 if (new_ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1166 static int ieee80211_chsw_switch_hwconf(struct ieee80211_local *local,
1167 struct ieee80211_chanctx *new_ctx)
1169 const struct cfg80211_chan_def *chandef;
1171 lockdep_assert_held(&local->mtx);
1172 lockdep_assert_held(&local->chanctx_mtx);
1174 chandef = ieee80211_chanctx_reserved_chandef(local, new_ctx, NULL);
1175 if (WARN_ON(!chandef))
1178 local->hw.conf.radar_enabled = new_ctx->conf.radar_enabled;
1179 local->_oper_chandef = *chandef;
1180 ieee80211_hw_config(local, 0);
1185 static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local,
1188 struct ieee80211_vif_chanctx_switch *vif_chsw;
1189 struct ieee80211_sub_if_data *sdata;
1190 struct ieee80211_chanctx *ctx, *old_ctx;
1193 lockdep_assert_held(&local->mtx);
1194 lockdep_assert_held(&local->chanctx_mtx);
1196 vif_chsw = kzalloc(sizeof(vif_chsw[0]) * n_vifs, GFP_KERNEL);
1201 list_for_each_entry(ctx, &local->chanctx_list, list) {
1202 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1205 if (WARN_ON(!ctx->replace_ctx)) {
1210 list_for_each_entry(sdata, &ctx->reserved_vifs,
1211 reserved_chanctx_list) {
1212 if (!ieee80211_vif_has_in_place_reservation(
1216 old_ctx = ieee80211_vif_get_chanctx(sdata);
1217 vif_chsw[i].vif = &sdata->vif;
1218 vif_chsw[i].old_ctx = &old_ctx->conf;
1219 vif_chsw[i].new_ctx = &ctx->conf;
1225 err = drv_switch_vif_chanctx(local, vif_chsw, n_vifs,
1226 CHANCTX_SWMODE_SWAP_CONTEXTS);
1233 static int ieee80211_chsw_switch_ctxs(struct ieee80211_local *local)
1235 struct ieee80211_chanctx *ctx;
1238 lockdep_assert_held(&local->mtx);
1239 lockdep_assert_held(&local->chanctx_mtx);
1241 list_for_each_entry(ctx, &local->chanctx_list, list) {
1242 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1245 if (!list_empty(&ctx->replace_ctx->assigned_vifs))
1248 ieee80211_del_chanctx(local, ctx->replace_ctx);
1249 err = ieee80211_add_chanctx(local, ctx);
1257 WARN_ON(ieee80211_add_chanctx(local, ctx));
1258 list_for_each_entry_continue_reverse(ctx, &local->chanctx_list, list) {
1259 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1262 if (!list_empty(&ctx->replace_ctx->assigned_vifs))
1265 ieee80211_del_chanctx(local, ctx);
1266 WARN_ON(ieee80211_add_chanctx(local, ctx->replace_ctx));
1273 ieee80211_vif_use_reserved_switch(struct ieee80211_local *local)
1275 struct ieee80211_sub_if_data *sdata, *sdata_tmp;
1276 struct ieee80211_chanctx *ctx, *ctx_tmp, *old_ctx;
1277 struct ieee80211_chanctx *new_ctx = NULL;
1278 int i, err, n_assigned, n_reserved, n_ready;
1279 int n_ctx = 0, n_vifs_switch = 0, n_vifs_assign = 0, n_vifs_ctxless = 0;
1281 lockdep_assert_held(&local->mtx);
1282 lockdep_assert_held(&local->chanctx_mtx);
1285 * If there are 2 independent pairs of channel contexts performing
1286 * cross-switch of their vifs this code will still wait until both are
1287 * ready even though it could be possible to switch one before the
1290 * For practical reasons and code simplicity just do a single huge
1295 * Verify if the reservation is still feasible.
1296 * - if it's not then disconnect
1297 * - if it is but not all vifs necessary are ready then defer
1300 list_for_each_entry(ctx, &local->chanctx_list, list) {
1301 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1304 if (WARN_ON(!ctx->replace_ctx)) {
1309 if (!local->use_chanctx)
1318 list_for_each_entry(sdata, &ctx->replace_ctx->assigned_vifs,
1319 assigned_chanctx_list) {
1321 if (sdata->reserved_chanctx) {
1323 if (sdata->reserved_ready)
1328 if (n_assigned != n_reserved) {
1329 if (n_ready == n_reserved) {
1330 wiphy_info(local->hw.wiphy,
1331 "channel context reservation cannot be finalized because some interfaces aren't switching\n");
1339 ctx->conf.radar_enabled = false;
1340 list_for_each_entry(sdata, &ctx->reserved_vifs,
1341 reserved_chanctx_list) {
1342 if (ieee80211_vif_has_in_place_reservation(sdata) &&
1343 !sdata->reserved_ready)
1346 old_ctx = ieee80211_vif_get_chanctx(sdata);
1348 if (old_ctx->replace_state ==
1349 IEEE80211_CHANCTX_WILL_BE_REPLACED)
1357 if (sdata->reserved_radar_required)
1358 ctx->conf.radar_enabled = true;
1362 if (WARN_ON(n_ctx == 0) ||
1363 WARN_ON(n_vifs_switch == 0 &&
1364 n_vifs_assign == 0 &&
1365 n_vifs_ctxless == 0) ||
1366 WARN_ON(n_ctx > 1 && !local->use_chanctx) ||
1367 WARN_ON(!new_ctx && !local->use_chanctx)) {
1373 * All necessary vifs are ready. Perform the switch now depending on
1374 * reservations and driver capabilities.
1377 if (local->use_chanctx) {
1378 if (n_vifs_switch > 0) {
1379 err = ieee80211_chsw_switch_vifs(local, n_vifs_switch);
1384 if (n_vifs_assign > 0 || n_vifs_ctxless > 0) {
1385 err = ieee80211_chsw_switch_ctxs(local);
1390 err = ieee80211_chsw_switch_hwconf(local, new_ctx);
1396 * Update all structures, values and pointers to point to new channel
1401 list_for_each_entry(ctx, &local->chanctx_list, list) {
1402 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1405 if (WARN_ON(!ctx->replace_ctx)) {
1410 list_for_each_entry(sdata, &ctx->reserved_vifs,
1411 reserved_chanctx_list) {
1414 if (!ieee80211_vif_has_in_place_reservation(sdata))
1417 rcu_assign_pointer(sdata->vif.chanctx_conf, &ctx->conf);
1419 if (sdata->vif.type == NL80211_IFTYPE_AP)
1420 __ieee80211_vif_copy_chanctx_to_vlans(sdata,
1423 sdata->radar_required = sdata->reserved_radar_required;
1425 if (sdata->vif.bss_conf.chandef.width !=
1426 sdata->reserved_chandef.width)
1427 changed = BSS_CHANGED_BANDWIDTH;
1429 sdata->vif.bss_conf.chandef = sdata->reserved_chandef;
1431 ieee80211_bss_info_change_notify(sdata,
1434 ieee80211_recalc_txpower(sdata);
1437 ieee80211_recalc_chanctx_chantype(local, ctx);
1438 ieee80211_recalc_smps_chanctx(local, ctx);
1439 ieee80211_recalc_radar_chanctx(local, ctx);
1440 ieee80211_recalc_chanctx_min_def(local, ctx);
1442 list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
1443 reserved_chanctx_list) {
1444 if (ieee80211_vif_get_chanctx(sdata) != ctx)
1447 list_del(&sdata->reserved_chanctx_list);
1448 list_move(&sdata->assigned_chanctx_list,
1449 &ctx->assigned_vifs);
1450 sdata->reserved_chanctx = NULL;
1452 ieee80211_vif_chanctx_reservation_complete(sdata);
1456 * This context might have been a dependency for an already
1457 * ready re-assign reservation interface that was deferred. Do
1458 * not propagate error to the caller though. The in-place
1459 * reservation for originally requested interface has already
1460 * succeeded at this point.
1462 list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
1463 reserved_chanctx_list) {
1464 if (WARN_ON(ieee80211_vif_has_in_place_reservation(
1468 if (WARN_ON(sdata->reserved_chanctx != ctx))
1471 if (!sdata->reserved_ready)
1474 if (ieee80211_vif_get_chanctx(sdata))
1475 err = ieee80211_vif_use_reserved_reassign(
1478 err = ieee80211_vif_use_reserved_assign(sdata);
1482 "failed to finalize (re-)assign reservation (err=%d)\n",
1484 ieee80211_vif_unreserve_chanctx(sdata);
1485 cfg80211_stop_iface(local->hw.wiphy,
1493 * Finally free old contexts
1496 list_for_each_entry_safe(ctx, ctx_tmp, &local->chanctx_list, list) {
1497 if (ctx->replace_state != IEEE80211_CHANCTX_WILL_BE_REPLACED)
1500 ctx->replace_ctx->replace_ctx = NULL;
1501 ctx->replace_ctx->replace_state =
1502 IEEE80211_CHANCTX_REPLACE_NONE;
1504 list_del_rcu(&ctx->list);
1505 kfree_rcu(ctx, rcu_head);
1511 list_for_each_entry(ctx, &local->chanctx_list, list) {
1512 if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER)
1515 list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs,
1516 reserved_chanctx_list) {
1517 ieee80211_vif_unreserve_chanctx(sdata);
1518 ieee80211_vif_chanctx_reservation_complete(sdata);
1525 int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata)
1527 struct ieee80211_local *local = sdata->local;
1528 struct ieee80211_chanctx *new_ctx;
1529 struct ieee80211_chanctx *old_ctx;
1532 lockdep_assert_held(&local->mtx);
1533 lockdep_assert_held(&local->chanctx_mtx);
1535 new_ctx = sdata->reserved_chanctx;
1536 old_ctx = ieee80211_vif_get_chanctx(sdata);
1538 if (WARN_ON(!new_ctx))
1541 if (WARN_ON(new_ctx->replace_state ==
1542 IEEE80211_CHANCTX_WILL_BE_REPLACED))
1545 if (WARN_ON(sdata->reserved_ready))
1548 sdata->reserved_ready = true;
1550 if (new_ctx->replace_state == IEEE80211_CHANCTX_REPLACE_NONE) {
1552 err = ieee80211_vif_use_reserved_reassign(sdata);
1554 err = ieee80211_vif_use_reserved_assign(sdata);
1561 * In-place reservation may need to be finalized now either if:
1562 * a) sdata is taking part in the swapping itself and is the last one
1563 * b) sdata has switched with a re-assign reservation to an existing
1564 * context readying in-place switching of old_ctx
1566 * In case of (b) do not propagate the error up because the requested
1567 * sdata already switched successfully. Just spill an extra warning.
1568 * The ieee80211_vif_use_reserved_switch() already stops all necessary
1569 * interfaces upon failure.
1572 old_ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) ||
1573 new_ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER) {
1574 err = ieee80211_vif_use_reserved_switch(local);
1575 if (err && err != -EAGAIN) {
1576 if (new_ctx->replace_state ==
1577 IEEE80211_CHANCTX_REPLACES_OTHER)
1580 wiphy_info(local->hw.wiphy,
1581 "depending in-place reservation failed (err=%d)\n",
1589 int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
1590 const struct cfg80211_chan_def *chandef,
1593 struct ieee80211_local *local = sdata->local;
1594 struct ieee80211_chanctx_conf *conf;
1595 struct ieee80211_chanctx *ctx;
1596 const struct cfg80211_chan_def *compat;
1599 if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
1600 IEEE80211_CHAN_DISABLED))
1603 mutex_lock(&local->chanctx_mtx);
1604 if (cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) {
1609 if (chandef->width == NL80211_CHAN_WIDTH_20_NOHT ||
1610 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) {
1615 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
1616 lockdep_is_held(&local->chanctx_mtx));
1622 ctx = container_of(conf, struct ieee80211_chanctx, conf);
1624 compat = cfg80211_chandef_compatible(&conf->def, chandef);
1630 switch (ctx->replace_state) {
1631 case IEEE80211_CHANCTX_REPLACE_NONE:
1632 if (!ieee80211_chanctx_reserved_chandef(local, ctx, compat)) {
1637 case IEEE80211_CHANCTX_WILL_BE_REPLACED:
1638 /* TODO: Perhaps the bandwith change could be treated as a
1639 * reservation itself? */
1642 case IEEE80211_CHANCTX_REPLACES_OTHER:
1643 /* channel context that is going to replace another channel
1644 * context doesn't really exist and shouldn't be assigned
1650 sdata->vif.bss_conf.chandef = *chandef;
1652 ieee80211_recalc_chanctx_chantype(local, ctx);
1654 *changed |= BSS_CHANGED_BANDWIDTH;
1657 mutex_unlock(&local->chanctx_mtx);
1661 void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
1663 WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev));
1665 lockdep_assert_held(&sdata->local->mtx);
1667 mutex_lock(&sdata->local->chanctx_mtx);
1668 __ieee80211_vif_release_channel(sdata);
1669 mutex_unlock(&sdata->local->chanctx_mtx);
1672 void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata)
1674 struct ieee80211_local *local = sdata->local;
1675 struct ieee80211_sub_if_data *ap;
1676 struct ieee80211_chanctx_conf *conf;
1678 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->bss))
1681 ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap);
1683 mutex_lock(&local->chanctx_mtx);
1685 conf = rcu_dereference_protected(ap->vif.chanctx_conf,
1686 lockdep_is_held(&local->chanctx_mtx));
1687 rcu_assign_pointer(sdata->vif.chanctx_conf, conf);
1688 mutex_unlock(&local->chanctx_mtx);
1691 void ieee80211_iter_chan_contexts_atomic(
1692 struct ieee80211_hw *hw,
1693 void (*iter)(struct ieee80211_hw *hw,
1694 struct ieee80211_chanctx_conf *chanctx_conf,
1698 struct ieee80211_local *local = hw_to_local(hw);
1699 struct ieee80211_chanctx *ctx;
1702 list_for_each_entry_rcu(ctx, &local->chanctx_list, list)
1703 if (ctx->driver_present)
1704 iter(hw, &ctx->conf, iter_data);
1707 EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic);