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
)
546 compat
= &sdata
->vif
.bss_conf
.chandef
;
548 compat
= cfg80211_chandef_compatible(
549 &sdata
->vif
.bss_conf
.chandef
, compat
);
555 if (WARN_ON_ONCE(!compat
))
558 ieee80211_change_chanctx(local
, ctx
, compat
);
561 static void ieee80211_recalc_radar_chanctx(struct ieee80211_local
*local
,
562 struct ieee80211_chanctx
*chanctx
)
566 lockdep_assert_held(&local
->chanctx_mtx
);
567 /* for setting local->radar_detect_enabled */
568 lockdep_assert_held(&local
->mtx
);
570 radar_enabled
= ieee80211_is_radar_required(local
);
572 if (radar_enabled
== chanctx
->conf
.radar_enabled
)
575 chanctx
->conf
.radar_enabled
= radar_enabled
;
576 local
->radar_detect_enabled
= chanctx
->conf
.radar_enabled
;
578 if (!local
->use_chanctx
) {
579 local
->hw
.conf
.radar_enabled
= chanctx
->conf
.radar_enabled
;
580 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
583 drv_change_chanctx(local
, chanctx
, IEEE80211_CHANCTX_CHANGE_RADAR
);
586 static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data
*sdata
,
587 struct ieee80211_chanctx
*new_ctx
)
589 struct ieee80211_local
*local
= sdata
->local
;
590 struct ieee80211_chanctx_conf
*conf
;
591 struct ieee80211_chanctx
*curr_ctx
= NULL
;
594 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
595 lockdep_is_held(&local
->chanctx_mtx
));
598 curr_ctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
600 drv_unassign_vif_chanctx(local
, sdata
, curr_ctx
);
602 list_del(&sdata
->assigned_chanctx_list
);
606 ret
= drv_assign_vif_chanctx(local
, sdata
, new_ctx
);
610 conf
= &new_ctx
->conf
;
611 list_add(&sdata
->assigned_chanctx_list
,
612 &new_ctx
->assigned_vifs
);
616 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, conf
);
618 sdata
->vif
.bss_conf
.idle
= !conf
;
620 if (curr_ctx
&& ieee80211_chanctx_num_assigned(local
, curr_ctx
) > 0) {
621 ieee80211_recalc_chanctx_chantype(local
, curr_ctx
);
622 ieee80211_recalc_smps_chanctx(local
, curr_ctx
);
623 ieee80211_recalc_radar_chanctx(local
, curr_ctx
);
624 ieee80211_recalc_chanctx_min_def(local
, curr_ctx
);
627 if (new_ctx
&& ieee80211_chanctx_num_assigned(local
, new_ctx
) > 0) {
628 ieee80211_recalc_txpower(sdata
);
629 ieee80211_recalc_chanctx_min_def(local
, new_ctx
);
632 if (sdata
->vif
.type
!= NL80211_IFTYPE_P2P_DEVICE
&&
633 sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
)
634 ieee80211_bss_info_change_notify(sdata
,
640 static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data
*sdata
)
642 struct ieee80211_local
*local
= sdata
->local
;
643 struct ieee80211_chanctx_conf
*conf
;
644 struct ieee80211_chanctx
*ctx
;
645 bool use_reserved_switch
= false;
647 lockdep_assert_held(&local
->chanctx_mtx
);
649 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
650 lockdep_is_held(&local
->chanctx_mtx
));
654 ctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
656 if (sdata
->reserved_chanctx
) {
657 if (sdata
->reserved_chanctx
->replace_state
==
658 IEEE80211_CHANCTX_REPLACES_OTHER
&&
659 ieee80211_chanctx_num_reserved(local
,
660 sdata
->reserved_chanctx
) > 1)
661 use_reserved_switch
= true;
663 ieee80211_vif_unreserve_chanctx(sdata
);
666 ieee80211_assign_vif_chanctx(sdata
, NULL
);
667 if (ieee80211_chanctx_refcount(local
, ctx
) == 0)
668 ieee80211_free_chanctx(local
, ctx
);
670 /* Unreserving may ready an in-place reservation. */
671 if (use_reserved_switch
)
672 ieee80211_vif_use_reserved_switch(local
);
675 void ieee80211_recalc_smps_chanctx(struct ieee80211_local
*local
,
676 struct ieee80211_chanctx
*chanctx
)
678 struct ieee80211_sub_if_data
*sdata
;
679 u8 rx_chains_static
, rx_chains_dynamic
;
681 lockdep_assert_held(&local
->chanctx_mtx
);
683 rx_chains_static
= 1;
684 rx_chains_dynamic
= 1;
687 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
688 u8 needed_static
, needed_dynamic
;
690 if (!ieee80211_sdata_running(sdata
))
693 if (rcu_access_pointer(sdata
->vif
.chanctx_conf
) !=
697 switch (sdata
->vif
.type
) {
698 case NL80211_IFTYPE_P2P_DEVICE
:
700 case NL80211_IFTYPE_STATION
:
701 if (!sdata
->u
.mgd
.associated
)
704 case NL80211_IFTYPE_AP_VLAN
:
706 case NL80211_IFTYPE_AP
:
707 case NL80211_IFTYPE_ADHOC
:
708 case NL80211_IFTYPE_WDS
:
709 case NL80211_IFTYPE_MESH_POINT
:
715 switch (sdata
->smps_mode
) {
717 WARN_ONCE(1, "Invalid SMPS mode %d\n",
720 case IEEE80211_SMPS_OFF
:
721 needed_static
= sdata
->needed_rx_chains
;
722 needed_dynamic
= sdata
->needed_rx_chains
;
724 case IEEE80211_SMPS_DYNAMIC
:
726 needed_dynamic
= sdata
->needed_rx_chains
;
728 case IEEE80211_SMPS_STATIC
:
734 rx_chains_static
= max(rx_chains_static
, needed_static
);
735 rx_chains_dynamic
= max(rx_chains_dynamic
, needed_dynamic
);
738 /* Disable SMPS for the monitor interface */
739 sdata
= rcu_dereference(local
->monitor_sdata
);
741 rcu_access_pointer(sdata
->vif
.chanctx_conf
) == &chanctx
->conf
)
742 rx_chains_dynamic
= rx_chains_static
= local
->rx_chains
;
746 if (!local
->use_chanctx
) {
747 if (rx_chains_static
> 1)
748 local
->smps_mode
= IEEE80211_SMPS_OFF
;
749 else if (rx_chains_dynamic
> 1)
750 local
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
752 local
->smps_mode
= IEEE80211_SMPS_STATIC
;
753 ieee80211_hw_config(local
, 0);
756 if (rx_chains_static
== chanctx
->conf
.rx_chains_static
&&
757 rx_chains_dynamic
== chanctx
->conf
.rx_chains_dynamic
)
760 chanctx
->conf
.rx_chains_static
= rx_chains_static
;
761 chanctx
->conf
.rx_chains_dynamic
= rx_chains_dynamic
;
762 drv_change_chanctx(local
, chanctx
, IEEE80211_CHANCTX_CHANGE_RX_CHAINS
);
765 int ieee80211_vif_use_channel(struct ieee80211_sub_if_data
*sdata
,
766 const struct cfg80211_chan_def
*chandef
,
767 enum ieee80211_chanctx_mode mode
)
769 struct ieee80211_local
*local
= sdata
->local
;
770 struct ieee80211_chanctx
*ctx
;
771 u8 radar_detect_width
= 0;
774 lockdep_assert_held(&local
->mtx
);
776 WARN_ON(sdata
->dev
&& netif_carrier_ok(sdata
->dev
));
778 mutex_lock(&local
->chanctx_mtx
);
780 ret
= cfg80211_chandef_dfs_required(local
->hw
.wiphy
,
786 radar_detect_width
= BIT(chandef
->width
);
788 sdata
->radar_required
= ret
;
790 ret
= ieee80211_check_combinations(sdata
, chandef
, mode
,
795 __ieee80211_vif_release_channel(sdata
);
797 ctx
= ieee80211_find_chanctx(local
, chandef
, mode
);
799 ctx
= ieee80211_new_chanctx(local
, chandef
, mode
);
805 sdata
->vif
.bss_conf
.chandef
= *chandef
;
807 ret
= ieee80211_assign_vif_chanctx(sdata
, ctx
);
809 /* if assign fails refcount stays the same */
810 if (ieee80211_chanctx_refcount(local
, ctx
) == 0)
811 ieee80211_free_chanctx(local
, ctx
);
815 ieee80211_recalc_smps_chanctx(local
, ctx
);
816 ieee80211_recalc_radar_chanctx(local
, ctx
);
818 mutex_unlock(&local
->chanctx_mtx
);
823 __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data
*sdata
,
826 struct ieee80211_local
*local __maybe_unused
= sdata
->local
;
827 struct ieee80211_sub_if_data
*vlan
;
828 struct ieee80211_chanctx_conf
*conf
;
830 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_AP
))
833 lockdep_assert_held(&local
->mtx
);
835 /* Check that conf exists, even when clearing this function
836 * must be called with the AP's channel context still there
837 * as it would otherwise cause VLANs to have an invalid
838 * channel context pointer for a while, possibly pointing
839 * to a channel context that has already been freed.
841 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
842 lockdep_is_held(&local
->chanctx_mtx
));
848 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
849 rcu_assign_pointer(vlan
->vif
.chanctx_conf
, conf
);
852 void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data
*sdata
,
855 struct ieee80211_local
*local
= sdata
->local
;
857 mutex_lock(&local
->chanctx_mtx
);
859 __ieee80211_vif_copy_chanctx_to_vlans(sdata
, clear
);
861 mutex_unlock(&local
->chanctx_mtx
);
864 int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data
*sdata
)
866 struct ieee80211_chanctx
*ctx
= sdata
->reserved_chanctx
;
868 lockdep_assert_held(&sdata
->local
->chanctx_mtx
);
873 list_del(&sdata
->reserved_chanctx_list
);
874 sdata
->reserved_chanctx
= NULL
;
876 if (ieee80211_chanctx_refcount(sdata
->local
, ctx
) == 0) {
877 if (ctx
->replace_state
== IEEE80211_CHANCTX_REPLACES_OTHER
) {
878 if (WARN_ON(!ctx
->replace_ctx
))
881 WARN_ON(ctx
->replace_ctx
->replace_state
!=
882 IEEE80211_CHANCTX_WILL_BE_REPLACED
);
883 WARN_ON(ctx
->replace_ctx
->replace_ctx
!= ctx
);
885 ctx
->replace_ctx
->replace_ctx
= NULL
;
886 ctx
->replace_ctx
->replace_state
=
887 IEEE80211_CHANCTX_REPLACE_NONE
;
889 list_del_rcu(&ctx
->list
);
890 kfree_rcu(ctx
, rcu_head
);
892 ieee80211_free_chanctx(sdata
->local
, ctx
);
899 int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data
*sdata
,
900 const struct cfg80211_chan_def
*chandef
,
901 enum ieee80211_chanctx_mode mode
,
904 struct ieee80211_local
*local
= sdata
->local
;
905 struct ieee80211_chanctx
*new_ctx
, *curr_ctx
, *ctx
;
907 lockdep_assert_held(&local
->chanctx_mtx
);
909 curr_ctx
= ieee80211_vif_get_chanctx(sdata
);
910 if (curr_ctx
&& local
->use_chanctx
&& !local
->ops
->switch_vif_chanctx
)
913 new_ctx
= ieee80211_find_reservation_chanctx(local
, chandef
, mode
);
915 if (ieee80211_can_create_new_chanctx(local
)) {
916 new_ctx
= ieee80211_new_chanctx(local
, chandef
, mode
);
918 return PTR_ERR(new_ctx
);
921 (curr_ctx
->replace_state
==
922 IEEE80211_CHANCTX_WILL_BE_REPLACED
) ||
923 !list_empty(&curr_ctx
->reserved_vifs
)) {
925 * Another vif already requested this context
926 * for a reservation. Find another one hoping
927 * all vifs assigned to it will also switch
930 * TODO: This needs a little more work as some
931 * cases (more than 2 chanctx capable devices)
932 * may fail which could otherwise succeed
933 * provided some channel context juggling was
936 * Consider ctx1..3, vif1..6, each ctx has 2
937 * vifs. vif1 and vif2 from ctx1 request new
938 * different chandefs starting 2 in-place
939 * reserations with ctx4 and ctx5 replacing
940 * ctx1 and ctx2 respectively. Next vif5 and
941 * vif6 from ctx3 reserve ctx4. If vif3 and
942 * vif4 remain on ctx2 as they are then this
943 * fails unless `replace_ctx` from ctx5 is
944 * replaced with ctx3.
946 list_for_each_entry(ctx
, &local
->chanctx_list
,
948 if (ctx
->replace_state
!=
949 IEEE80211_CHANCTX_REPLACE_NONE
)
952 if (!list_empty(&ctx
->reserved_vifs
))
961 * If that's true then all available contexts already
962 * have reservations and cannot be used.
965 (curr_ctx
->replace_state
==
966 IEEE80211_CHANCTX_WILL_BE_REPLACED
) ||
967 !list_empty(&curr_ctx
->reserved_vifs
))
970 new_ctx
= ieee80211_alloc_chanctx(local
, chandef
, mode
);
974 new_ctx
->replace_ctx
= curr_ctx
;
975 new_ctx
->replace_state
=
976 IEEE80211_CHANCTX_REPLACES_OTHER
;
978 curr_ctx
->replace_ctx
= new_ctx
;
979 curr_ctx
->replace_state
=
980 IEEE80211_CHANCTX_WILL_BE_REPLACED
;
982 list_add_rcu(&new_ctx
->list
, &local
->chanctx_list
);
986 list_add(&sdata
->reserved_chanctx_list
, &new_ctx
->reserved_vifs
);
987 sdata
->reserved_chanctx
= new_ctx
;
988 sdata
->reserved_chandef
= *chandef
;
989 sdata
->reserved_radar_required
= radar_required
;
990 sdata
->reserved_ready
= false;
996 ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data
*sdata
)
998 switch (sdata
->vif
.type
) {
999 case NL80211_IFTYPE_ADHOC
:
1000 case NL80211_IFTYPE_AP
:
1001 case NL80211_IFTYPE_MESH_POINT
:
1002 ieee80211_queue_work(&sdata
->local
->hw
,
1003 &sdata
->csa_finalize_work
);
1005 case NL80211_IFTYPE_STATION
:
1006 ieee80211_queue_work(&sdata
->local
->hw
,
1007 &sdata
->u
.mgd
.chswitch_work
);
1009 case NL80211_IFTYPE_UNSPECIFIED
:
1010 case NL80211_IFTYPE_AP_VLAN
:
1011 case NL80211_IFTYPE_WDS
:
1012 case NL80211_IFTYPE_MONITOR
:
1013 case NL80211_IFTYPE_P2P_CLIENT
:
1014 case NL80211_IFTYPE_P2P_GO
:
1015 case NL80211_IFTYPE_P2P_DEVICE
:
1016 case NUM_NL80211_IFTYPES
:
1023 ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data
*sdata
)
1025 struct ieee80211_local
*local
= sdata
->local
;
1026 struct ieee80211_vif_chanctx_switch vif_chsw
[1] = {};
1027 struct ieee80211_chanctx
*old_ctx
, *new_ctx
;
1028 const struct cfg80211_chan_def
*chandef
;
1032 lockdep_assert_held(&local
->mtx
);
1033 lockdep_assert_held(&local
->chanctx_mtx
);
1035 new_ctx
= sdata
->reserved_chanctx
;
1036 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1038 if (WARN_ON(!sdata
->reserved_ready
))
1041 if (WARN_ON(!new_ctx
))
1044 if (WARN_ON(!old_ctx
))
1047 if (WARN_ON(new_ctx
->replace_state
==
1048 IEEE80211_CHANCTX_REPLACES_OTHER
))
1051 chandef
= ieee80211_chanctx_non_reserved_chandef(local
, new_ctx
,
1052 &sdata
->reserved_chandef
);
1053 if (WARN_ON(!chandef
))
1056 vif_chsw
[0].vif
= &sdata
->vif
;
1057 vif_chsw
[0].old_ctx
= &old_ctx
->conf
;
1058 vif_chsw
[0].new_ctx
= &new_ctx
->conf
;
1060 list_del(&sdata
->reserved_chanctx_list
);
1061 sdata
->reserved_chanctx
= NULL
;
1063 err
= drv_switch_vif_chanctx(local
, vif_chsw
, 1,
1064 CHANCTX_SWMODE_REASSIGN_VIF
);
1066 if (ieee80211_chanctx_refcount(local
, new_ctx
) == 0)
1067 ieee80211_free_chanctx(local
, new_ctx
);
1072 list_move(&sdata
->assigned_chanctx_list
, &new_ctx
->assigned_vifs
);
1073 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, &new_ctx
->conf
);
1075 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
1076 __ieee80211_vif_copy_chanctx_to_vlans(sdata
, false);
1078 if (ieee80211_chanctx_refcount(local
, old_ctx
) == 0)
1079 ieee80211_free_chanctx(local
, old_ctx
);
1081 if (sdata
->vif
.bss_conf
.chandef
.width
!= sdata
->reserved_chandef
.width
)
1082 changed
= BSS_CHANGED_BANDWIDTH
;
1084 sdata
->vif
.bss_conf
.chandef
= sdata
->reserved_chandef
;
1087 ieee80211_bss_info_change_notify(sdata
, changed
);
1090 ieee80211_vif_chanctx_reservation_complete(sdata
);
1095 ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data
*sdata
)
1097 struct ieee80211_local
*local
= sdata
->local
;
1098 struct ieee80211_chanctx
*old_ctx
, *new_ctx
;
1099 const struct cfg80211_chan_def
*chandef
;
1102 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1103 new_ctx
= sdata
->reserved_chanctx
;
1105 if (WARN_ON(!sdata
->reserved_ready
))
1108 if (WARN_ON(old_ctx
))
1111 if (WARN_ON(!new_ctx
))
1114 if (WARN_ON(new_ctx
->replace_state
==
1115 IEEE80211_CHANCTX_REPLACES_OTHER
))
1118 chandef
= ieee80211_chanctx_non_reserved_chandef(local
, new_ctx
,
1119 &sdata
->reserved_chandef
);
1120 if (WARN_ON(!chandef
))
1123 list_del(&sdata
->reserved_chanctx_list
);
1124 sdata
->reserved_chanctx
= NULL
;
1126 err
= ieee80211_assign_vif_chanctx(sdata
, new_ctx
);
1128 if (ieee80211_chanctx_refcount(local
, new_ctx
) == 0)
1129 ieee80211_free_chanctx(local
, new_ctx
);
1135 ieee80211_vif_chanctx_reservation_complete(sdata
);
1140 ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data
*sdata
)
1142 struct ieee80211_chanctx
*old_ctx
, *new_ctx
;
1144 lockdep_assert_held(&sdata
->local
->chanctx_mtx
);
1146 new_ctx
= sdata
->reserved_chanctx
;
1147 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1152 if (WARN_ON(!new_ctx
))
1155 if (old_ctx
->replace_state
!= IEEE80211_CHANCTX_WILL_BE_REPLACED
)
1158 if (new_ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1164 static int ieee80211_chsw_switch_hwconf(struct ieee80211_local
*local
,
1165 struct ieee80211_chanctx
*new_ctx
)
1167 const struct cfg80211_chan_def
*chandef
;
1169 lockdep_assert_held(&local
->mtx
);
1170 lockdep_assert_held(&local
->chanctx_mtx
);
1172 chandef
= ieee80211_chanctx_reserved_chandef(local
, new_ctx
, NULL
);
1173 if (WARN_ON(!chandef
))
1176 local
->hw
.conf
.radar_enabled
= new_ctx
->conf
.radar_enabled
;
1177 local
->_oper_chandef
= *chandef
;
1178 ieee80211_hw_config(local
, 0);
1183 static int ieee80211_chsw_switch_vifs(struct ieee80211_local
*local
,
1186 struct ieee80211_vif_chanctx_switch
*vif_chsw
;
1187 struct ieee80211_sub_if_data
*sdata
;
1188 struct ieee80211_chanctx
*ctx
, *old_ctx
;
1191 lockdep_assert_held(&local
->mtx
);
1192 lockdep_assert_held(&local
->chanctx_mtx
);
1194 vif_chsw
= kzalloc(sizeof(vif_chsw
[0]) * n_vifs
, GFP_KERNEL
);
1199 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1200 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1203 if (WARN_ON(!ctx
->replace_ctx
)) {
1208 list_for_each_entry(sdata
, &ctx
->reserved_vifs
,
1209 reserved_chanctx_list
) {
1210 if (!ieee80211_vif_has_in_place_reservation(
1214 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1215 vif_chsw
[i
].vif
= &sdata
->vif
;
1216 vif_chsw
[i
].old_ctx
= &old_ctx
->conf
;
1217 vif_chsw
[i
].new_ctx
= &ctx
->conf
;
1223 err
= drv_switch_vif_chanctx(local
, vif_chsw
, n_vifs
,
1224 CHANCTX_SWMODE_SWAP_CONTEXTS
);
1231 static int ieee80211_chsw_switch_ctxs(struct ieee80211_local
*local
)
1233 struct ieee80211_chanctx
*ctx
;
1236 lockdep_assert_held(&local
->mtx
);
1237 lockdep_assert_held(&local
->chanctx_mtx
);
1239 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1240 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1243 if (!list_empty(&ctx
->replace_ctx
->assigned_vifs
))
1246 ieee80211_del_chanctx(local
, ctx
->replace_ctx
);
1247 err
= ieee80211_add_chanctx(local
, ctx
);
1255 WARN_ON(ieee80211_add_chanctx(local
, ctx
));
1256 list_for_each_entry_continue_reverse(ctx
, &local
->chanctx_list
, list
) {
1257 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1260 if (!list_empty(&ctx
->replace_ctx
->assigned_vifs
))
1263 ieee80211_del_chanctx(local
, ctx
);
1264 WARN_ON(ieee80211_add_chanctx(local
, ctx
->replace_ctx
));
1271 ieee80211_vif_use_reserved_switch(struct ieee80211_local
*local
)
1273 struct ieee80211_sub_if_data
*sdata
, *sdata_tmp
;
1274 struct ieee80211_chanctx
*ctx
, *ctx_tmp
, *old_ctx
;
1275 struct ieee80211_chanctx
*new_ctx
= NULL
;
1276 int i
, err
, n_assigned
, n_reserved
, n_ready
;
1277 int n_ctx
= 0, n_vifs_switch
= 0, n_vifs_assign
= 0, n_vifs_ctxless
= 0;
1279 lockdep_assert_held(&local
->mtx
);
1280 lockdep_assert_held(&local
->chanctx_mtx
);
1283 * If there are 2 independent pairs of channel contexts performing
1284 * cross-switch of their vifs this code will still wait until both are
1285 * ready even though it could be possible to switch one before the
1288 * For practical reasons and code simplicity just do a single huge
1293 * Verify if the reservation is still feasible.
1294 * - if it's not then disconnect
1295 * - if it is but not all vifs necessary are ready then defer
1298 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1299 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1302 if (WARN_ON(!ctx
->replace_ctx
)) {
1307 if (!local
->use_chanctx
)
1316 list_for_each_entry(sdata
, &ctx
->replace_ctx
->assigned_vifs
,
1317 assigned_chanctx_list
) {
1319 if (sdata
->reserved_chanctx
) {
1321 if (sdata
->reserved_ready
)
1326 if (n_assigned
!= n_reserved
) {
1327 if (n_ready
== n_reserved
) {
1328 wiphy_info(local
->hw
.wiphy
,
1329 "channel context reservation cannot be finalized because some interfaces aren't switching\n");
1337 ctx
->conf
.radar_enabled
= false;
1338 list_for_each_entry(sdata
, &ctx
->reserved_vifs
,
1339 reserved_chanctx_list
) {
1340 if (ieee80211_vif_has_in_place_reservation(sdata
) &&
1341 !sdata
->reserved_ready
)
1344 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1346 if (old_ctx
->replace_state
==
1347 IEEE80211_CHANCTX_WILL_BE_REPLACED
)
1355 if (sdata
->reserved_radar_required
)
1356 ctx
->conf
.radar_enabled
= true;
1360 if (WARN_ON(n_ctx
== 0) ||
1361 WARN_ON(n_vifs_switch
== 0 &&
1362 n_vifs_assign
== 0 &&
1363 n_vifs_ctxless
== 0) ||
1364 WARN_ON(n_ctx
> 1 && !local
->use_chanctx
) ||
1365 WARN_ON(!new_ctx
&& !local
->use_chanctx
)) {
1371 * All necessary vifs are ready. Perform the switch now depending on
1372 * reservations and driver capabilities.
1375 if (local
->use_chanctx
) {
1376 if (n_vifs_switch
> 0) {
1377 err
= ieee80211_chsw_switch_vifs(local
, n_vifs_switch
);
1382 if (n_vifs_assign
> 0 || n_vifs_ctxless
> 0) {
1383 err
= ieee80211_chsw_switch_ctxs(local
);
1388 err
= ieee80211_chsw_switch_hwconf(local
, new_ctx
);
1394 * Update all structures, values and pointers to point to new channel
1399 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1400 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1403 if (WARN_ON(!ctx
->replace_ctx
)) {
1408 list_for_each_entry(sdata
, &ctx
->reserved_vifs
,
1409 reserved_chanctx_list
) {
1412 if (!ieee80211_vif_has_in_place_reservation(sdata
))
1415 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, &ctx
->conf
);
1417 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
1418 __ieee80211_vif_copy_chanctx_to_vlans(sdata
,
1421 sdata
->radar_required
= sdata
->reserved_radar_required
;
1423 if (sdata
->vif
.bss_conf
.chandef
.width
!=
1424 sdata
->reserved_chandef
.width
)
1425 changed
= BSS_CHANGED_BANDWIDTH
;
1427 sdata
->vif
.bss_conf
.chandef
= sdata
->reserved_chandef
;
1429 ieee80211_bss_info_change_notify(sdata
,
1432 ieee80211_recalc_txpower(sdata
);
1435 ieee80211_recalc_chanctx_chantype(local
, ctx
);
1436 ieee80211_recalc_smps_chanctx(local
, ctx
);
1437 ieee80211_recalc_radar_chanctx(local
, ctx
);
1438 ieee80211_recalc_chanctx_min_def(local
, ctx
);
1440 list_for_each_entry_safe(sdata
, sdata_tmp
, &ctx
->reserved_vifs
,
1441 reserved_chanctx_list
) {
1442 if (ieee80211_vif_get_chanctx(sdata
) != ctx
)
1445 list_del(&sdata
->reserved_chanctx_list
);
1446 list_move(&sdata
->assigned_chanctx_list
,
1447 &new_ctx
->assigned_vifs
);
1448 sdata
->reserved_chanctx
= NULL
;
1450 ieee80211_vif_chanctx_reservation_complete(sdata
);
1454 * This context might have been a dependency for an already
1455 * ready re-assign reservation interface that was deferred. Do
1456 * not propagate error to the caller though. The in-place
1457 * reservation for originally requested interface has already
1458 * succeeded at this point.
1460 list_for_each_entry_safe(sdata
, sdata_tmp
, &ctx
->reserved_vifs
,
1461 reserved_chanctx_list
) {
1462 if (WARN_ON(ieee80211_vif_has_in_place_reservation(
1466 if (WARN_ON(sdata
->reserved_chanctx
!= ctx
))
1469 if (!sdata
->reserved_ready
)
1472 if (ieee80211_vif_get_chanctx(sdata
))
1473 err
= ieee80211_vif_use_reserved_reassign(
1476 err
= ieee80211_vif_use_reserved_assign(sdata
);
1480 "failed to finalize (re-)assign reservation (err=%d)\n",
1482 ieee80211_vif_unreserve_chanctx(sdata
);
1483 cfg80211_stop_iface(local
->hw
.wiphy
,
1491 * Finally free old contexts
1494 list_for_each_entry_safe(ctx
, ctx_tmp
, &local
->chanctx_list
, list
) {
1495 if (ctx
->replace_state
!= IEEE80211_CHANCTX_WILL_BE_REPLACED
)
1498 ctx
->replace_ctx
->replace_ctx
= NULL
;
1499 ctx
->replace_ctx
->replace_state
=
1500 IEEE80211_CHANCTX_REPLACE_NONE
;
1502 list_del_rcu(&ctx
->list
);
1503 kfree_rcu(ctx
, rcu_head
);
1509 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1510 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1513 list_for_each_entry_safe(sdata
, sdata_tmp
, &ctx
->reserved_vifs
,
1514 reserved_chanctx_list
) {
1515 ieee80211_vif_unreserve_chanctx(sdata
);
1516 ieee80211_vif_chanctx_reservation_complete(sdata
);
1523 int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data
*sdata
)
1525 struct ieee80211_local
*local
= sdata
->local
;
1526 struct ieee80211_chanctx
*new_ctx
;
1527 struct ieee80211_chanctx
*old_ctx
;
1530 lockdep_assert_held(&local
->mtx
);
1531 lockdep_assert_held(&local
->chanctx_mtx
);
1533 new_ctx
= sdata
->reserved_chanctx
;
1534 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1536 if (WARN_ON(!new_ctx
))
1539 if (WARN_ON(new_ctx
->replace_state
==
1540 IEEE80211_CHANCTX_WILL_BE_REPLACED
))
1543 if (WARN_ON(sdata
->reserved_ready
))
1546 sdata
->reserved_ready
= true;
1548 if (new_ctx
->replace_state
== IEEE80211_CHANCTX_REPLACE_NONE
) {
1550 err
= ieee80211_vif_use_reserved_reassign(sdata
);
1552 err
= ieee80211_vif_use_reserved_assign(sdata
);
1559 * In-place reservation may need to be finalized now either if:
1560 * a) sdata is taking part in the swapping itself and is the last one
1561 * b) sdata has switched with a re-assign reservation to an existing
1562 * context readying in-place switching of old_ctx
1564 * In case of (b) do not propagate the error up because the requested
1565 * sdata already switched successfully. Just spill an extra warning.
1566 * The ieee80211_vif_use_reserved_switch() already stops all necessary
1567 * interfaces upon failure.
1570 old_ctx
->replace_state
== IEEE80211_CHANCTX_WILL_BE_REPLACED
) ||
1571 new_ctx
->replace_state
== IEEE80211_CHANCTX_REPLACES_OTHER
) {
1572 err
= ieee80211_vif_use_reserved_switch(local
);
1573 if (err
&& err
!= -EAGAIN
) {
1574 if (new_ctx
->replace_state
==
1575 IEEE80211_CHANCTX_REPLACES_OTHER
)
1578 wiphy_info(local
->hw
.wiphy
,
1579 "depending in-place reservation failed (err=%d)\n",
1587 int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data
*sdata
,
1588 const struct cfg80211_chan_def
*chandef
,
1591 struct ieee80211_local
*local
= sdata
->local
;
1592 struct ieee80211_chanctx_conf
*conf
;
1593 struct ieee80211_chanctx
*ctx
;
1594 const struct cfg80211_chan_def
*compat
;
1597 if (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
1598 IEEE80211_CHAN_DISABLED
))
1601 mutex_lock(&local
->chanctx_mtx
);
1602 if (cfg80211_chandef_identical(chandef
, &sdata
->vif
.bss_conf
.chandef
)) {
1607 if (chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
||
1608 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
) {
1613 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1614 lockdep_is_held(&local
->chanctx_mtx
));
1620 ctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1622 compat
= cfg80211_chandef_compatible(&conf
->def
, chandef
);
1628 switch (ctx
->replace_state
) {
1629 case IEEE80211_CHANCTX_REPLACE_NONE
:
1630 if (!ieee80211_chanctx_reserved_chandef(local
, ctx
, compat
)) {
1635 case IEEE80211_CHANCTX_WILL_BE_REPLACED
:
1636 /* TODO: Perhaps the bandwith change could be treated as a
1637 * reservation itself? */
1640 case IEEE80211_CHANCTX_REPLACES_OTHER
:
1641 /* channel context that is going to replace another channel
1642 * context doesn't really exist and shouldn't be assigned
1648 sdata
->vif
.bss_conf
.chandef
= *chandef
;
1650 ieee80211_recalc_chanctx_chantype(local
, ctx
);
1652 *changed
|= BSS_CHANGED_BANDWIDTH
;
1655 mutex_unlock(&local
->chanctx_mtx
);
1659 void ieee80211_vif_release_channel(struct ieee80211_sub_if_data
*sdata
)
1661 WARN_ON(sdata
->dev
&& netif_carrier_ok(sdata
->dev
));
1663 lockdep_assert_held(&sdata
->local
->mtx
);
1665 mutex_lock(&sdata
->local
->chanctx_mtx
);
1666 __ieee80211_vif_release_channel(sdata
);
1667 mutex_unlock(&sdata
->local
->chanctx_mtx
);
1670 void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data
*sdata
)
1672 struct ieee80211_local
*local
= sdata
->local
;
1673 struct ieee80211_sub_if_data
*ap
;
1674 struct ieee80211_chanctx_conf
*conf
;
1676 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
|| !sdata
->bss
))
1679 ap
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
, u
.ap
);
1681 mutex_lock(&local
->chanctx_mtx
);
1683 conf
= rcu_dereference_protected(ap
->vif
.chanctx_conf
,
1684 lockdep_is_held(&local
->chanctx_mtx
));
1685 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, conf
);
1686 mutex_unlock(&local
->chanctx_mtx
);
1689 void ieee80211_iter_chan_contexts_atomic(
1690 struct ieee80211_hw
*hw
,
1691 void (*iter
)(struct ieee80211_hw
*hw
,
1692 struct ieee80211_chanctx_conf
*chanctx_conf
,
1696 struct ieee80211_local
*local
= hw_to_local(hw
);
1697 struct ieee80211_chanctx
*ctx
;
1700 list_for_each_entry_rcu(ctx
, &local
->chanctx_list
, list
)
1701 if (ctx
->driver_present
)
1702 iter(hw
, &ctx
->conf
, iter_data
);
1705 EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic
);