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 case NL80211_IFTYPE_OCB
:
274 width
= vif
->bss_conf
.chandef
.width
;
276 case NL80211_IFTYPE_UNSPECIFIED
:
277 case NUM_NL80211_IFTYPES
:
278 case NL80211_IFTYPE_MONITOR
:
279 case NL80211_IFTYPE_P2P_CLIENT
:
280 case NL80211_IFTYPE_P2P_GO
:
283 max_bw
= max(max_bw
, width
);
286 /* use the configured bandwidth in case of monitor interface */
287 sdata
= rcu_dereference(local
->monitor_sdata
);
288 if (sdata
&& rcu_access_pointer(sdata
->vif
.chanctx_conf
) == conf
)
289 max_bw
= max(max_bw
, conf
->def
.width
);
297 * recalc the min required chan width of the channel context, which is
298 * the max of min required widths of all the interfaces bound to this
301 void ieee80211_recalc_chanctx_min_def(struct ieee80211_local
*local
,
302 struct ieee80211_chanctx
*ctx
)
304 enum nl80211_chan_width max_bw
;
305 struct cfg80211_chan_def min_def
;
307 lockdep_assert_held(&local
->chanctx_mtx
);
309 /* don't optimize 5MHz, 10MHz, and radar_enabled confs */
310 if (ctx
->conf
.def
.width
== NL80211_CHAN_WIDTH_5
||
311 ctx
->conf
.def
.width
== NL80211_CHAN_WIDTH_10
||
312 ctx
->conf
.radar_enabled
) {
313 ctx
->conf
.min_def
= ctx
->conf
.def
;
317 max_bw
= ieee80211_get_chanctx_max_required_bw(local
, &ctx
->conf
);
319 /* downgrade chandef up to max_bw */
320 min_def
= ctx
->conf
.def
;
321 while (min_def
.width
> max_bw
)
322 ieee80211_chandef_downgrade(&min_def
);
324 if (cfg80211_chandef_identical(&ctx
->conf
.min_def
, &min_def
))
327 ctx
->conf
.min_def
= min_def
;
328 if (!ctx
->driver_present
)
331 drv_change_chanctx(local
, ctx
, IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
);
334 static void ieee80211_change_chanctx(struct ieee80211_local
*local
,
335 struct ieee80211_chanctx
*ctx
,
336 const struct cfg80211_chan_def
*chandef
)
338 if (cfg80211_chandef_identical(&ctx
->conf
.def
, chandef
))
341 WARN_ON(!cfg80211_chandef_compatible(&ctx
->conf
.def
, chandef
));
343 ctx
->conf
.def
= *chandef
;
344 drv_change_chanctx(local
, ctx
, IEEE80211_CHANCTX_CHANGE_WIDTH
);
345 ieee80211_recalc_chanctx_min_def(local
, ctx
);
347 if (!local
->use_chanctx
) {
348 local
->_oper_chandef
= *chandef
;
349 ieee80211_hw_config(local
, 0);
353 static struct ieee80211_chanctx
*
354 ieee80211_find_chanctx(struct ieee80211_local
*local
,
355 const struct cfg80211_chan_def
*chandef
,
356 enum ieee80211_chanctx_mode mode
)
358 struct ieee80211_chanctx
*ctx
;
360 lockdep_assert_held(&local
->chanctx_mtx
);
362 if (mode
== IEEE80211_CHANCTX_EXCLUSIVE
)
365 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
366 const struct cfg80211_chan_def
*compat
;
368 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACE_NONE
)
371 if (ctx
->mode
== IEEE80211_CHANCTX_EXCLUSIVE
)
374 compat
= cfg80211_chandef_compatible(&ctx
->conf
.def
, chandef
);
378 compat
= ieee80211_chanctx_reserved_chandef(local
, ctx
,
383 ieee80211_change_chanctx(local
, ctx
, compat
);
391 static bool ieee80211_is_radar_required(struct ieee80211_local
*local
)
393 struct ieee80211_sub_if_data
*sdata
;
395 lockdep_assert_held(&local
->mtx
);
398 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
399 if (sdata
->radar_required
) {
409 static struct ieee80211_chanctx
*
410 ieee80211_alloc_chanctx(struct ieee80211_local
*local
,
411 const struct cfg80211_chan_def
*chandef
,
412 enum ieee80211_chanctx_mode mode
)
414 struct ieee80211_chanctx
*ctx
;
416 lockdep_assert_held(&local
->chanctx_mtx
);
418 ctx
= kzalloc(sizeof(*ctx
) + local
->hw
.chanctx_data_size
, GFP_KERNEL
);
422 INIT_LIST_HEAD(&ctx
->assigned_vifs
);
423 INIT_LIST_HEAD(&ctx
->reserved_vifs
);
424 ctx
->conf
.def
= *chandef
;
425 ctx
->conf
.rx_chains_static
= 1;
426 ctx
->conf
.rx_chains_dynamic
= 1;
428 ctx
->conf
.radar_enabled
= ieee80211_is_radar_required(local
);
429 ieee80211_recalc_chanctx_min_def(local
, ctx
);
434 static int ieee80211_add_chanctx(struct ieee80211_local
*local
,
435 struct ieee80211_chanctx
*ctx
)
440 lockdep_assert_held(&local
->mtx
);
441 lockdep_assert_held(&local
->chanctx_mtx
);
443 if (!local
->use_chanctx
)
444 local
->hw
.conf
.radar_enabled
= ctx
->conf
.radar_enabled
;
446 /* turn idle off *before* setting channel -- some drivers need that */
447 changed
= ieee80211_idle_off(local
);
449 ieee80211_hw_config(local
, changed
);
451 if (!local
->use_chanctx
) {
452 local
->_oper_chandef
= ctx
->conf
.def
;
453 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
455 err
= drv_add_chanctx(local
, ctx
);
457 ieee80211_recalc_idle(local
);
465 static struct ieee80211_chanctx
*
466 ieee80211_new_chanctx(struct ieee80211_local
*local
,
467 const struct cfg80211_chan_def
*chandef
,
468 enum ieee80211_chanctx_mode mode
)
470 struct ieee80211_chanctx
*ctx
;
473 lockdep_assert_held(&local
->mtx
);
474 lockdep_assert_held(&local
->chanctx_mtx
);
476 ctx
= ieee80211_alloc_chanctx(local
, chandef
, mode
);
478 return ERR_PTR(-ENOMEM
);
480 err
= ieee80211_add_chanctx(local
, ctx
);
486 list_add_rcu(&ctx
->list
, &local
->chanctx_list
);
490 static void ieee80211_del_chanctx(struct ieee80211_local
*local
,
491 struct ieee80211_chanctx
*ctx
)
493 lockdep_assert_held(&local
->chanctx_mtx
);
495 if (!local
->use_chanctx
) {
496 struct cfg80211_chan_def
*chandef
= &local
->_oper_chandef
;
497 chandef
->width
= NL80211_CHAN_WIDTH_20_NOHT
;
498 chandef
->center_freq1
= chandef
->chan
->center_freq
;
499 chandef
->center_freq2
= 0;
501 /* NOTE: Disabling radar is only valid here for
502 * single channel context. To be sure, check it ...
504 WARN_ON(local
->hw
.conf
.radar_enabled
&&
505 !list_empty(&local
->chanctx_list
));
507 local
->hw
.conf
.radar_enabled
= false;
509 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
511 drv_remove_chanctx(local
, ctx
);
514 ieee80211_recalc_idle(local
);
517 static void ieee80211_free_chanctx(struct ieee80211_local
*local
,
518 struct ieee80211_chanctx
*ctx
)
520 lockdep_assert_held(&local
->chanctx_mtx
);
522 WARN_ON_ONCE(ieee80211_chanctx_refcount(local
, ctx
) != 0);
524 list_del_rcu(&ctx
->list
);
525 ieee80211_del_chanctx(local
, ctx
);
526 kfree_rcu(ctx
, rcu_head
);
529 static void ieee80211_recalc_chanctx_chantype(struct ieee80211_local
*local
,
530 struct ieee80211_chanctx
*ctx
)
532 struct ieee80211_chanctx_conf
*conf
= &ctx
->conf
;
533 struct ieee80211_sub_if_data
*sdata
;
534 const struct cfg80211_chan_def
*compat
= NULL
;
536 lockdep_assert_held(&local
->chanctx_mtx
);
539 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
541 if (!ieee80211_sdata_running(sdata
))
543 if (rcu_access_pointer(sdata
->vif
.chanctx_conf
) != conf
)
545 if (sdata
->vif
.type
== NL80211_IFTYPE_AP_VLAN
)
549 compat
= &sdata
->vif
.bss_conf
.chandef
;
551 compat
= cfg80211_chandef_compatible(
552 &sdata
->vif
.bss_conf
.chandef
, compat
);
553 if (WARN_ON_ONCE(!compat
))
561 ieee80211_change_chanctx(local
, ctx
, compat
);
564 static void ieee80211_recalc_radar_chanctx(struct ieee80211_local
*local
,
565 struct ieee80211_chanctx
*chanctx
)
569 lockdep_assert_held(&local
->chanctx_mtx
);
570 /* for setting local->radar_detect_enabled */
571 lockdep_assert_held(&local
->mtx
);
573 radar_enabled
= ieee80211_is_radar_required(local
);
575 if (radar_enabled
== chanctx
->conf
.radar_enabled
)
578 chanctx
->conf
.radar_enabled
= radar_enabled
;
579 local
->radar_detect_enabled
= chanctx
->conf
.radar_enabled
;
581 if (!local
->use_chanctx
) {
582 local
->hw
.conf
.radar_enabled
= chanctx
->conf
.radar_enabled
;
583 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_CHANNEL
);
586 drv_change_chanctx(local
, chanctx
, IEEE80211_CHANCTX_CHANGE_RADAR
);
589 static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data
*sdata
,
590 struct ieee80211_chanctx
*new_ctx
)
592 struct ieee80211_local
*local
= sdata
->local
;
593 struct ieee80211_chanctx_conf
*conf
;
594 struct ieee80211_chanctx
*curr_ctx
= NULL
;
597 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
598 lockdep_is_held(&local
->chanctx_mtx
));
601 curr_ctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
603 drv_unassign_vif_chanctx(local
, sdata
, curr_ctx
);
605 list_del(&sdata
->assigned_chanctx_list
);
609 ret
= drv_assign_vif_chanctx(local
, sdata
, new_ctx
);
613 conf
= &new_ctx
->conf
;
614 list_add(&sdata
->assigned_chanctx_list
,
615 &new_ctx
->assigned_vifs
);
619 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, conf
);
621 sdata
->vif
.bss_conf
.idle
= !conf
;
623 if (curr_ctx
&& ieee80211_chanctx_num_assigned(local
, curr_ctx
) > 0) {
624 ieee80211_recalc_chanctx_chantype(local
, curr_ctx
);
625 ieee80211_recalc_smps_chanctx(local
, curr_ctx
);
626 ieee80211_recalc_radar_chanctx(local
, curr_ctx
);
627 ieee80211_recalc_chanctx_min_def(local
, curr_ctx
);
630 if (new_ctx
&& ieee80211_chanctx_num_assigned(local
, new_ctx
) > 0) {
631 ieee80211_recalc_txpower(sdata
);
632 ieee80211_recalc_chanctx_min_def(local
, new_ctx
);
635 if (sdata
->vif
.type
!= NL80211_IFTYPE_P2P_DEVICE
&&
636 sdata
->vif
.type
!= NL80211_IFTYPE_MONITOR
)
637 ieee80211_bss_info_change_notify(sdata
,
643 void ieee80211_recalc_smps_chanctx(struct ieee80211_local
*local
,
644 struct ieee80211_chanctx
*chanctx
)
646 struct ieee80211_sub_if_data
*sdata
;
647 u8 rx_chains_static
, rx_chains_dynamic
;
649 lockdep_assert_held(&local
->chanctx_mtx
);
651 rx_chains_static
= 1;
652 rx_chains_dynamic
= 1;
655 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
) {
656 u8 needed_static
, needed_dynamic
;
658 if (!ieee80211_sdata_running(sdata
))
661 if (rcu_access_pointer(sdata
->vif
.chanctx_conf
) !=
665 switch (sdata
->vif
.type
) {
666 case NL80211_IFTYPE_P2P_DEVICE
:
668 case NL80211_IFTYPE_STATION
:
669 if (!sdata
->u
.mgd
.associated
)
672 case NL80211_IFTYPE_AP_VLAN
:
674 case NL80211_IFTYPE_AP
:
675 case NL80211_IFTYPE_ADHOC
:
676 case NL80211_IFTYPE_WDS
:
677 case NL80211_IFTYPE_MESH_POINT
:
683 switch (sdata
->smps_mode
) {
685 WARN_ONCE(1, "Invalid SMPS mode %d\n",
688 case IEEE80211_SMPS_OFF
:
689 needed_static
= sdata
->needed_rx_chains
;
690 needed_dynamic
= sdata
->needed_rx_chains
;
692 case IEEE80211_SMPS_DYNAMIC
:
694 needed_dynamic
= sdata
->needed_rx_chains
;
696 case IEEE80211_SMPS_STATIC
:
702 rx_chains_static
= max(rx_chains_static
, needed_static
);
703 rx_chains_dynamic
= max(rx_chains_dynamic
, needed_dynamic
);
706 /* Disable SMPS for the monitor interface */
707 sdata
= rcu_dereference(local
->monitor_sdata
);
709 rcu_access_pointer(sdata
->vif
.chanctx_conf
) == &chanctx
->conf
)
710 rx_chains_dynamic
= rx_chains_static
= local
->rx_chains
;
714 if (!local
->use_chanctx
) {
715 if (rx_chains_static
> 1)
716 local
->smps_mode
= IEEE80211_SMPS_OFF
;
717 else if (rx_chains_dynamic
> 1)
718 local
->smps_mode
= IEEE80211_SMPS_DYNAMIC
;
720 local
->smps_mode
= IEEE80211_SMPS_STATIC
;
721 ieee80211_hw_config(local
, 0);
724 if (rx_chains_static
== chanctx
->conf
.rx_chains_static
&&
725 rx_chains_dynamic
== chanctx
->conf
.rx_chains_dynamic
)
728 chanctx
->conf
.rx_chains_static
= rx_chains_static
;
729 chanctx
->conf
.rx_chains_dynamic
= rx_chains_dynamic
;
730 drv_change_chanctx(local
, chanctx
, IEEE80211_CHANCTX_CHANGE_RX_CHAINS
);
734 __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data
*sdata
,
737 struct ieee80211_local
*local __maybe_unused
= sdata
->local
;
738 struct ieee80211_sub_if_data
*vlan
;
739 struct ieee80211_chanctx_conf
*conf
;
741 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_AP
))
744 lockdep_assert_held(&local
->mtx
);
746 /* Check that conf exists, even when clearing this function
747 * must be called with the AP's channel context still there
748 * as it would otherwise cause VLANs to have an invalid
749 * channel context pointer for a while, possibly pointing
750 * to a channel context that has already been freed.
752 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
753 lockdep_is_held(&local
->chanctx_mtx
));
759 list_for_each_entry(vlan
, &sdata
->u
.ap
.vlans
, u
.vlan
.list
)
760 rcu_assign_pointer(vlan
->vif
.chanctx_conf
, conf
);
763 void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data
*sdata
,
766 struct ieee80211_local
*local
= sdata
->local
;
768 mutex_lock(&local
->chanctx_mtx
);
770 __ieee80211_vif_copy_chanctx_to_vlans(sdata
, clear
);
772 mutex_unlock(&local
->chanctx_mtx
);
775 int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data
*sdata
)
777 struct ieee80211_chanctx
*ctx
= sdata
->reserved_chanctx
;
779 lockdep_assert_held(&sdata
->local
->chanctx_mtx
);
784 list_del(&sdata
->reserved_chanctx_list
);
785 sdata
->reserved_chanctx
= NULL
;
787 if (ieee80211_chanctx_refcount(sdata
->local
, ctx
) == 0) {
788 if (ctx
->replace_state
== IEEE80211_CHANCTX_REPLACES_OTHER
) {
789 if (WARN_ON(!ctx
->replace_ctx
))
792 WARN_ON(ctx
->replace_ctx
->replace_state
!=
793 IEEE80211_CHANCTX_WILL_BE_REPLACED
);
794 WARN_ON(ctx
->replace_ctx
->replace_ctx
!= ctx
);
796 ctx
->replace_ctx
->replace_ctx
= NULL
;
797 ctx
->replace_ctx
->replace_state
=
798 IEEE80211_CHANCTX_REPLACE_NONE
;
800 list_del_rcu(&ctx
->list
);
801 kfree_rcu(ctx
, rcu_head
);
803 ieee80211_free_chanctx(sdata
->local
, ctx
);
810 int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data
*sdata
,
811 const struct cfg80211_chan_def
*chandef
,
812 enum ieee80211_chanctx_mode mode
,
815 struct ieee80211_local
*local
= sdata
->local
;
816 struct ieee80211_chanctx
*new_ctx
, *curr_ctx
, *ctx
;
818 lockdep_assert_held(&local
->chanctx_mtx
);
820 curr_ctx
= ieee80211_vif_get_chanctx(sdata
);
821 if (curr_ctx
&& local
->use_chanctx
&& !local
->ops
->switch_vif_chanctx
)
824 new_ctx
= ieee80211_find_reservation_chanctx(local
, chandef
, mode
);
826 if (ieee80211_can_create_new_chanctx(local
)) {
827 new_ctx
= ieee80211_new_chanctx(local
, chandef
, mode
);
829 return PTR_ERR(new_ctx
);
832 (curr_ctx
->replace_state
==
833 IEEE80211_CHANCTX_WILL_BE_REPLACED
) ||
834 !list_empty(&curr_ctx
->reserved_vifs
)) {
836 * Another vif already requested this context
837 * for a reservation. Find another one hoping
838 * all vifs assigned to it will also switch
841 * TODO: This needs a little more work as some
842 * cases (more than 2 chanctx capable devices)
843 * may fail which could otherwise succeed
844 * provided some channel context juggling was
847 * Consider ctx1..3, vif1..6, each ctx has 2
848 * vifs. vif1 and vif2 from ctx1 request new
849 * different chandefs starting 2 in-place
850 * reserations with ctx4 and ctx5 replacing
851 * ctx1 and ctx2 respectively. Next vif5 and
852 * vif6 from ctx3 reserve ctx4. If vif3 and
853 * vif4 remain on ctx2 as they are then this
854 * fails unless `replace_ctx` from ctx5 is
855 * replaced with ctx3.
857 list_for_each_entry(ctx
, &local
->chanctx_list
,
859 if (ctx
->replace_state
!=
860 IEEE80211_CHANCTX_REPLACE_NONE
)
863 if (!list_empty(&ctx
->reserved_vifs
))
872 * If that's true then all available contexts already
873 * have reservations and cannot be used.
876 (curr_ctx
->replace_state
==
877 IEEE80211_CHANCTX_WILL_BE_REPLACED
) ||
878 !list_empty(&curr_ctx
->reserved_vifs
))
881 new_ctx
= ieee80211_alloc_chanctx(local
, chandef
, mode
);
885 new_ctx
->replace_ctx
= curr_ctx
;
886 new_ctx
->replace_state
=
887 IEEE80211_CHANCTX_REPLACES_OTHER
;
889 curr_ctx
->replace_ctx
= new_ctx
;
890 curr_ctx
->replace_state
=
891 IEEE80211_CHANCTX_WILL_BE_REPLACED
;
893 list_add_rcu(&new_ctx
->list
, &local
->chanctx_list
);
897 list_add(&sdata
->reserved_chanctx_list
, &new_ctx
->reserved_vifs
);
898 sdata
->reserved_chanctx
= new_ctx
;
899 sdata
->reserved_chandef
= *chandef
;
900 sdata
->reserved_radar_required
= radar_required
;
901 sdata
->reserved_ready
= false;
907 ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data
*sdata
)
909 switch (sdata
->vif
.type
) {
910 case NL80211_IFTYPE_ADHOC
:
911 case NL80211_IFTYPE_AP
:
912 case NL80211_IFTYPE_MESH_POINT
:
913 case NL80211_IFTYPE_OCB
:
914 ieee80211_queue_work(&sdata
->local
->hw
,
915 &sdata
->csa_finalize_work
);
917 case NL80211_IFTYPE_STATION
:
918 ieee80211_queue_work(&sdata
->local
->hw
,
919 &sdata
->u
.mgd
.chswitch_work
);
921 case NL80211_IFTYPE_UNSPECIFIED
:
922 case NL80211_IFTYPE_AP_VLAN
:
923 case NL80211_IFTYPE_WDS
:
924 case NL80211_IFTYPE_MONITOR
:
925 case NL80211_IFTYPE_P2P_CLIENT
:
926 case NL80211_IFTYPE_P2P_GO
:
927 case NL80211_IFTYPE_P2P_DEVICE
:
928 case NUM_NL80211_IFTYPES
:
935 ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data
*sdata
)
937 struct ieee80211_local
*local
= sdata
->local
;
938 struct ieee80211_vif_chanctx_switch vif_chsw
[1] = {};
939 struct ieee80211_chanctx
*old_ctx
, *new_ctx
;
940 const struct cfg80211_chan_def
*chandef
;
944 lockdep_assert_held(&local
->mtx
);
945 lockdep_assert_held(&local
->chanctx_mtx
);
947 new_ctx
= sdata
->reserved_chanctx
;
948 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
950 if (WARN_ON(!sdata
->reserved_ready
))
953 if (WARN_ON(!new_ctx
))
956 if (WARN_ON(!old_ctx
))
959 if (WARN_ON(new_ctx
->replace_state
==
960 IEEE80211_CHANCTX_REPLACES_OTHER
))
963 chandef
= ieee80211_chanctx_non_reserved_chandef(local
, new_ctx
,
964 &sdata
->reserved_chandef
);
965 if (WARN_ON(!chandef
))
968 vif_chsw
[0].vif
= &sdata
->vif
;
969 vif_chsw
[0].old_ctx
= &old_ctx
->conf
;
970 vif_chsw
[0].new_ctx
= &new_ctx
->conf
;
972 list_del(&sdata
->reserved_chanctx_list
);
973 sdata
->reserved_chanctx
= NULL
;
975 err
= drv_switch_vif_chanctx(local
, vif_chsw
, 1,
976 CHANCTX_SWMODE_REASSIGN_VIF
);
978 if (ieee80211_chanctx_refcount(local
, new_ctx
) == 0)
979 ieee80211_free_chanctx(local
, new_ctx
);
984 list_move(&sdata
->assigned_chanctx_list
, &new_ctx
->assigned_vifs
);
985 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, &new_ctx
->conf
);
987 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
988 __ieee80211_vif_copy_chanctx_to_vlans(sdata
, false);
990 if (ieee80211_chanctx_refcount(local
, old_ctx
) == 0)
991 ieee80211_free_chanctx(local
, old_ctx
);
993 if (sdata
->vif
.bss_conf
.chandef
.width
!= sdata
->reserved_chandef
.width
)
994 changed
= BSS_CHANGED_BANDWIDTH
;
996 sdata
->vif
.bss_conf
.chandef
= sdata
->reserved_chandef
;
999 ieee80211_bss_info_change_notify(sdata
, changed
);
1002 ieee80211_vif_chanctx_reservation_complete(sdata
);
1007 ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data
*sdata
)
1009 struct ieee80211_local
*local
= sdata
->local
;
1010 struct ieee80211_chanctx
*old_ctx
, *new_ctx
;
1011 const struct cfg80211_chan_def
*chandef
;
1014 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1015 new_ctx
= sdata
->reserved_chanctx
;
1017 if (WARN_ON(!sdata
->reserved_ready
))
1020 if (WARN_ON(old_ctx
))
1023 if (WARN_ON(!new_ctx
))
1026 if (WARN_ON(new_ctx
->replace_state
==
1027 IEEE80211_CHANCTX_REPLACES_OTHER
))
1030 chandef
= ieee80211_chanctx_non_reserved_chandef(local
, new_ctx
,
1031 &sdata
->reserved_chandef
);
1032 if (WARN_ON(!chandef
))
1035 list_del(&sdata
->reserved_chanctx_list
);
1036 sdata
->reserved_chanctx
= NULL
;
1038 err
= ieee80211_assign_vif_chanctx(sdata
, new_ctx
);
1040 if (ieee80211_chanctx_refcount(local
, new_ctx
) == 0)
1041 ieee80211_free_chanctx(local
, new_ctx
);
1047 ieee80211_vif_chanctx_reservation_complete(sdata
);
1052 ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data
*sdata
)
1054 struct ieee80211_chanctx
*old_ctx
, *new_ctx
;
1056 lockdep_assert_held(&sdata
->local
->chanctx_mtx
);
1058 new_ctx
= sdata
->reserved_chanctx
;
1059 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1064 if (WARN_ON(!new_ctx
))
1067 if (old_ctx
->replace_state
!= IEEE80211_CHANCTX_WILL_BE_REPLACED
)
1070 if (new_ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1076 static int ieee80211_chsw_switch_hwconf(struct ieee80211_local
*local
,
1077 struct ieee80211_chanctx
*new_ctx
)
1079 const struct cfg80211_chan_def
*chandef
;
1081 lockdep_assert_held(&local
->mtx
);
1082 lockdep_assert_held(&local
->chanctx_mtx
);
1084 chandef
= ieee80211_chanctx_reserved_chandef(local
, new_ctx
, NULL
);
1085 if (WARN_ON(!chandef
))
1088 local
->hw
.conf
.radar_enabled
= new_ctx
->conf
.radar_enabled
;
1089 local
->_oper_chandef
= *chandef
;
1090 ieee80211_hw_config(local
, 0);
1095 static int ieee80211_chsw_switch_vifs(struct ieee80211_local
*local
,
1098 struct ieee80211_vif_chanctx_switch
*vif_chsw
;
1099 struct ieee80211_sub_if_data
*sdata
;
1100 struct ieee80211_chanctx
*ctx
, *old_ctx
;
1103 lockdep_assert_held(&local
->mtx
);
1104 lockdep_assert_held(&local
->chanctx_mtx
);
1106 vif_chsw
= kzalloc(sizeof(vif_chsw
[0]) * n_vifs
, GFP_KERNEL
);
1111 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1112 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1115 if (WARN_ON(!ctx
->replace_ctx
)) {
1120 list_for_each_entry(sdata
, &ctx
->reserved_vifs
,
1121 reserved_chanctx_list
) {
1122 if (!ieee80211_vif_has_in_place_reservation(
1126 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1127 vif_chsw
[i
].vif
= &sdata
->vif
;
1128 vif_chsw
[i
].old_ctx
= &old_ctx
->conf
;
1129 vif_chsw
[i
].new_ctx
= &ctx
->conf
;
1135 err
= drv_switch_vif_chanctx(local
, vif_chsw
, n_vifs
,
1136 CHANCTX_SWMODE_SWAP_CONTEXTS
);
1143 static int ieee80211_chsw_switch_ctxs(struct ieee80211_local
*local
)
1145 struct ieee80211_chanctx
*ctx
;
1148 lockdep_assert_held(&local
->mtx
);
1149 lockdep_assert_held(&local
->chanctx_mtx
);
1151 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1152 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1155 if (!list_empty(&ctx
->replace_ctx
->assigned_vifs
))
1158 ieee80211_del_chanctx(local
, ctx
->replace_ctx
);
1159 err
= ieee80211_add_chanctx(local
, ctx
);
1167 WARN_ON(ieee80211_add_chanctx(local
, ctx
));
1168 list_for_each_entry_continue_reverse(ctx
, &local
->chanctx_list
, list
) {
1169 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1172 if (!list_empty(&ctx
->replace_ctx
->assigned_vifs
))
1175 ieee80211_del_chanctx(local
, ctx
);
1176 WARN_ON(ieee80211_add_chanctx(local
, ctx
->replace_ctx
));
1182 static int ieee80211_vif_use_reserved_switch(struct ieee80211_local
*local
)
1184 struct ieee80211_sub_if_data
*sdata
, *sdata_tmp
;
1185 struct ieee80211_chanctx
*ctx
, *ctx_tmp
, *old_ctx
;
1186 struct ieee80211_chanctx
*new_ctx
= NULL
;
1187 int i
, err
, n_assigned
, n_reserved
, n_ready
;
1188 int n_ctx
= 0, n_vifs_switch
= 0, n_vifs_assign
= 0, n_vifs_ctxless
= 0;
1190 lockdep_assert_held(&local
->mtx
);
1191 lockdep_assert_held(&local
->chanctx_mtx
);
1194 * If there are 2 independent pairs of channel contexts performing
1195 * cross-switch of their vifs this code will still wait until both are
1196 * ready even though it could be possible to switch one before the
1199 * For practical reasons and code simplicity just do a single huge
1204 * Verify if the reservation is still feasible.
1205 * - if it's not then disconnect
1206 * - if it is but not all vifs necessary are ready then defer
1209 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1210 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1213 if (WARN_ON(!ctx
->replace_ctx
)) {
1218 if (!local
->use_chanctx
)
1227 list_for_each_entry(sdata
, &ctx
->replace_ctx
->assigned_vifs
,
1228 assigned_chanctx_list
) {
1230 if (sdata
->reserved_chanctx
) {
1232 if (sdata
->reserved_ready
)
1237 if (n_assigned
!= n_reserved
) {
1238 if (n_ready
== n_reserved
) {
1239 wiphy_info(local
->hw
.wiphy
,
1240 "channel context reservation cannot be finalized because some interfaces aren't switching\n");
1248 ctx
->conf
.radar_enabled
= false;
1249 list_for_each_entry(sdata
, &ctx
->reserved_vifs
,
1250 reserved_chanctx_list
) {
1251 if (ieee80211_vif_has_in_place_reservation(sdata
) &&
1252 !sdata
->reserved_ready
)
1255 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1257 if (old_ctx
->replace_state
==
1258 IEEE80211_CHANCTX_WILL_BE_REPLACED
)
1266 if (sdata
->reserved_radar_required
)
1267 ctx
->conf
.radar_enabled
= true;
1271 if (WARN_ON(n_ctx
== 0) ||
1272 WARN_ON(n_vifs_switch
== 0 &&
1273 n_vifs_assign
== 0 &&
1274 n_vifs_ctxless
== 0) ||
1275 WARN_ON(n_ctx
> 1 && !local
->use_chanctx
) ||
1276 WARN_ON(!new_ctx
&& !local
->use_chanctx
)) {
1282 * All necessary vifs are ready. Perform the switch now depending on
1283 * reservations and driver capabilities.
1286 if (local
->use_chanctx
) {
1287 if (n_vifs_switch
> 0) {
1288 err
= ieee80211_chsw_switch_vifs(local
, n_vifs_switch
);
1293 if (n_vifs_assign
> 0 || n_vifs_ctxless
> 0) {
1294 err
= ieee80211_chsw_switch_ctxs(local
);
1299 err
= ieee80211_chsw_switch_hwconf(local
, new_ctx
);
1305 * Update all structures, values and pointers to point to new channel
1310 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1311 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1314 if (WARN_ON(!ctx
->replace_ctx
)) {
1319 list_for_each_entry(sdata
, &ctx
->reserved_vifs
,
1320 reserved_chanctx_list
) {
1323 if (!ieee80211_vif_has_in_place_reservation(sdata
))
1326 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, &ctx
->conf
);
1328 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
)
1329 __ieee80211_vif_copy_chanctx_to_vlans(sdata
,
1332 sdata
->radar_required
= sdata
->reserved_radar_required
;
1334 if (sdata
->vif
.bss_conf
.chandef
.width
!=
1335 sdata
->reserved_chandef
.width
)
1336 changed
= BSS_CHANGED_BANDWIDTH
;
1338 sdata
->vif
.bss_conf
.chandef
= sdata
->reserved_chandef
;
1340 ieee80211_bss_info_change_notify(sdata
,
1343 ieee80211_recalc_txpower(sdata
);
1346 ieee80211_recalc_chanctx_chantype(local
, ctx
);
1347 ieee80211_recalc_smps_chanctx(local
, ctx
);
1348 ieee80211_recalc_radar_chanctx(local
, ctx
);
1349 ieee80211_recalc_chanctx_min_def(local
, ctx
);
1351 list_for_each_entry_safe(sdata
, sdata_tmp
, &ctx
->reserved_vifs
,
1352 reserved_chanctx_list
) {
1353 if (ieee80211_vif_get_chanctx(sdata
) != ctx
)
1356 list_del(&sdata
->reserved_chanctx_list
);
1357 list_move(&sdata
->assigned_chanctx_list
,
1358 &ctx
->assigned_vifs
);
1359 sdata
->reserved_chanctx
= NULL
;
1361 ieee80211_vif_chanctx_reservation_complete(sdata
);
1365 * This context might have been a dependency for an already
1366 * ready re-assign reservation interface that was deferred. Do
1367 * not propagate error to the caller though. The in-place
1368 * reservation for originally requested interface has already
1369 * succeeded at this point.
1371 list_for_each_entry_safe(sdata
, sdata_tmp
, &ctx
->reserved_vifs
,
1372 reserved_chanctx_list
) {
1373 if (WARN_ON(ieee80211_vif_has_in_place_reservation(
1377 if (WARN_ON(sdata
->reserved_chanctx
!= ctx
))
1380 if (!sdata
->reserved_ready
)
1383 if (ieee80211_vif_get_chanctx(sdata
))
1384 err
= ieee80211_vif_use_reserved_reassign(
1387 err
= ieee80211_vif_use_reserved_assign(sdata
);
1391 "failed to finalize (re-)assign reservation (err=%d)\n",
1393 ieee80211_vif_unreserve_chanctx(sdata
);
1394 cfg80211_stop_iface(local
->hw
.wiphy
,
1402 * Finally free old contexts
1405 list_for_each_entry_safe(ctx
, ctx_tmp
, &local
->chanctx_list
, list
) {
1406 if (ctx
->replace_state
!= IEEE80211_CHANCTX_WILL_BE_REPLACED
)
1409 ctx
->replace_ctx
->replace_ctx
= NULL
;
1410 ctx
->replace_ctx
->replace_state
=
1411 IEEE80211_CHANCTX_REPLACE_NONE
;
1413 list_del_rcu(&ctx
->list
);
1414 kfree_rcu(ctx
, rcu_head
);
1420 list_for_each_entry(ctx
, &local
->chanctx_list
, list
) {
1421 if (ctx
->replace_state
!= IEEE80211_CHANCTX_REPLACES_OTHER
)
1424 list_for_each_entry_safe(sdata
, sdata_tmp
, &ctx
->reserved_vifs
,
1425 reserved_chanctx_list
) {
1426 ieee80211_vif_unreserve_chanctx(sdata
);
1427 ieee80211_vif_chanctx_reservation_complete(sdata
);
1434 static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data
*sdata
)
1436 struct ieee80211_local
*local
= sdata
->local
;
1437 struct ieee80211_chanctx_conf
*conf
;
1438 struct ieee80211_chanctx
*ctx
;
1439 bool use_reserved_switch
= false;
1441 lockdep_assert_held(&local
->chanctx_mtx
);
1443 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1444 lockdep_is_held(&local
->chanctx_mtx
));
1448 ctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1450 if (sdata
->reserved_chanctx
) {
1451 if (sdata
->reserved_chanctx
->replace_state
==
1452 IEEE80211_CHANCTX_REPLACES_OTHER
&&
1453 ieee80211_chanctx_num_reserved(local
,
1454 sdata
->reserved_chanctx
) > 1)
1455 use_reserved_switch
= true;
1457 ieee80211_vif_unreserve_chanctx(sdata
);
1460 ieee80211_assign_vif_chanctx(sdata
, NULL
);
1461 if (ieee80211_chanctx_refcount(local
, ctx
) == 0)
1462 ieee80211_free_chanctx(local
, ctx
);
1464 /* Unreserving may ready an in-place reservation. */
1465 if (use_reserved_switch
)
1466 ieee80211_vif_use_reserved_switch(local
);
1469 int ieee80211_vif_use_channel(struct ieee80211_sub_if_data
*sdata
,
1470 const struct cfg80211_chan_def
*chandef
,
1471 enum ieee80211_chanctx_mode mode
)
1473 struct ieee80211_local
*local
= sdata
->local
;
1474 struct ieee80211_chanctx
*ctx
;
1475 u8 radar_detect_width
= 0;
1478 lockdep_assert_held(&local
->mtx
);
1480 WARN_ON(sdata
->dev
&& netif_carrier_ok(sdata
->dev
));
1482 mutex_lock(&local
->chanctx_mtx
);
1484 ret
= cfg80211_chandef_dfs_required(local
->hw
.wiphy
,
1486 sdata
->wdev
.iftype
);
1490 radar_detect_width
= BIT(chandef
->width
);
1492 sdata
->radar_required
= ret
;
1494 ret
= ieee80211_check_combinations(sdata
, chandef
, mode
,
1495 radar_detect_width
);
1499 __ieee80211_vif_release_channel(sdata
);
1501 ctx
= ieee80211_find_chanctx(local
, chandef
, mode
);
1503 ctx
= ieee80211_new_chanctx(local
, chandef
, mode
);
1509 sdata
->vif
.bss_conf
.chandef
= *chandef
;
1511 ret
= ieee80211_assign_vif_chanctx(sdata
, ctx
);
1513 /* if assign fails refcount stays the same */
1514 if (ieee80211_chanctx_refcount(local
, ctx
) == 0)
1515 ieee80211_free_chanctx(local
, ctx
);
1519 ieee80211_recalc_smps_chanctx(local
, ctx
);
1520 ieee80211_recalc_radar_chanctx(local
, ctx
);
1522 mutex_unlock(&local
->chanctx_mtx
);
1526 int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data
*sdata
)
1528 struct ieee80211_local
*local
= sdata
->local
;
1529 struct ieee80211_chanctx
*new_ctx
;
1530 struct ieee80211_chanctx
*old_ctx
;
1533 lockdep_assert_held(&local
->mtx
);
1534 lockdep_assert_held(&local
->chanctx_mtx
);
1536 new_ctx
= sdata
->reserved_chanctx
;
1537 old_ctx
= ieee80211_vif_get_chanctx(sdata
);
1539 if (WARN_ON(!new_ctx
))
1542 if (WARN_ON(new_ctx
->replace_state
==
1543 IEEE80211_CHANCTX_WILL_BE_REPLACED
))
1546 if (WARN_ON(sdata
->reserved_ready
))
1549 sdata
->reserved_ready
= true;
1551 if (new_ctx
->replace_state
== IEEE80211_CHANCTX_REPLACE_NONE
) {
1553 err
= ieee80211_vif_use_reserved_reassign(sdata
);
1555 err
= ieee80211_vif_use_reserved_assign(sdata
);
1562 * In-place reservation may need to be finalized now either if:
1563 * a) sdata is taking part in the swapping itself and is the last one
1564 * b) sdata has switched with a re-assign reservation to an existing
1565 * context readying in-place switching of old_ctx
1567 * In case of (b) do not propagate the error up because the requested
1568 * sdata already switched successfully. Just spill an extra warning.
1569 * The ieee80211_vif_use_reserved_switch() already stops all necessary
1570 * interfaces upon failure.
1573 old_ctx
->replace_state
== IEEE80211_CHANCTX_WILL_BE_REPLACED
) ||
1574 new_ctx
->replace_state
== IEEE80211_CHANCTX_REPLACES_OTHER
) {
1575 err
= ieee80211_vif_use_reserved_switch(local
);
1576 if (err
&& err
!= -EAGAIN
) {
1577 if (new_ctx
->replace_state
==
1578 IEEE80211_CHANCTX_REPLACES_OTHER
)
1581 wiphy_info(local
->hw
.wiphy
,
1582 "depending in-place reservation failed (err=%d)\n",
1590 int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data
*sdata
,
1591 const struct cfg80211_chan_def
*chandef
,
1594 struct ieee80211_local
*local
= sdata
->local
;
1595 struct ieee80211_chanctx_conf
*conf
;
1596 struct ieee80211_chanctx
*ctx
;
1597 const struct cfg80211_chan_def
*compat
;
1600 if (!cfg80211_chandef_usable(sdata
->local
->hw
.wiphy
, chandef
,
1601 IEEE80211_CHAN_DISABLED
))
1604 mutex_lock(&local
->chanctx_mtx
);
1605 if (cfg80211_chandef_identical(chandef
, &sdata
->vif
.bss_conf
.chandef
)) {
1610 if (chandef
->width
== NL80211_CHAN_WIDTH_20_NOHT
||
1611 sdata
->vif
.bss_conf
.chandef
.width
== NL80211_CHAN_WIDTH_20_NOHT
) {
1616 conf
= rcu_dereference_protected(sdata
->vif
.chanctx_conf
,
1617 lockdep_is_held(&local
->chanctx_mtx
));
1623 ctx
= container_of(conf
, struct ieee80211_chanctx
, conf
);
1625 compat
= cfg80211_chandef_compatible(&conf
->def
, chandef
);
1631 switch (ctx
->replace_state
) {
1632 case IEEE80211_CHANCTX_REPLACE_NONE
:
1633 if (!ieee80211_chanctx_reserved_chandef(local
, ctx
, compat
)) {
1638 case IEEE80211_CHANCTX_WILL_BE_REPLACED
:
1639 /* TODO: Perhaps the bandwidth change could be treated as a
1640 * reservation itself? */
1643 case IEEE80211_CHANCTX_REPLACES_OTHER
:
1644 /* channel context that is going to replace another channel
1645 * context doesn't really exist and shouldn't be assigned
1651 sdata
->vif
.bss_conf
.chandef
= *chandef
;
1653 ieee80211_recalc_chanctx_chantype(local
, ctx
);
1655 *changed
|= BSS_CHANGED_BANDWIDTH
;
1658 mutex_unlock(&local
->chanctx_mtx
);
1662 void ieee80211_vif_release_channel(struct ieee80211_sub_if_data
*sdata
)
1664 WARN_ON(sdata
->dev
&& netif_carrier_ok(sdata
->dev
));
1666 lockdep_assert_held(&sdata
->local
->mtx
);
1668 mutex_lock(&sdata
->local
->chanctx_mtx
);
1669 __ieee80211_vif_release_channel(sdata
);
1670 mutex_unlock(&sdata
->local
->chanctx_mtx
);
1673 void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data
*sdata
)
1675 struct ieee80211_local
*local
= sdata
->local
;
1676 struct ieee80211_sub_if_data
*ap
;
1677 struct ieee80211_chanctx_conf
*conf
;
1679 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_AP_VLAN
|| !sdata
->bss
))
1682 ap
= container_of(sdata
->bss
, struct ieee80211_sub_if_data
, u
.ap
);
1684 mutex_lock(&local
->chanctx_mtx
);
1686 conf
= rcu_dereference_protected(ap
->vif
.chanctx_conf
,
1687 lockdep_is_held(&local
->chanctx_mtx
));
1688 rcu_assign_pointer(sdata
->vif
.chanctx_conf
, conf
);
1689 mutex_unlock(&local
->chanctx_mtx
);
1692 void ieee80211_iter_chan_contexts_atomic(
1693 struct ieee80211_hw
*hw
,
1694 void (*iter
)(struct ieee80211_hw
*hw
,
1695 struct ieee80211_chanctx_conf
*chanctx_conf
,
1699 struct ieee80211_local
*local
= hw_to_local(hw
);
1700 struct ieee80211_chanctx
*ctx
;
1703 list_for_each_entry_rcu(ctx
, &local
->chanctx_list
, list
)
1704 if (ctx
->driver_present
)
1705 iter(hw
, &ctx
->conf
, iter_data
);
1708 EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic
);