diff options
Diffstat (limited to 'net/mac80211/chan.c')
-rw-r--r-- | net/mac80211/chan.c | 861 |
1 files changed, 716 insertions, 145 deletions
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c index a310e33972de..6d537f03c0ba 100644 --- a/net/mac80211/chan.c +++ b/net/mac80211/chan.c | |||
@@ -63,6 +63,20 @@ static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local) | |||
63 | return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local); | 63 | return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local); |
64 | } | 64 | } |
65 | 65 | ||
66 | static struct ieee80211_chanctx * | ||
67 | ieee80211_vif_get_chanctx(struct ieee80211_sub_if_data *sdata) | ||
68 | { | ||
69 | struct ieee80211_local *local __maybe_unused = sdata->local; | ||
70 | struct ieee80211_chanctx_conf *conf; | ||
71 | |||
72 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | ||
73 | lockdep_is_held(&local->chanctx_mtx)); | ||
74 | if (!conf) | ||
75 | return NULL; | ||
76 | |||
77 | return container_of(conf, struct ieee80211_chanctx, conf); | ||
78 | } | ||
79 | |||
66 | static const struct cfg80211_chan_def * | 80 | static const struct cfg80211_chan_def * |
67 | ieee80211_chanctx_reserved_chandef(struct ieee80211_local *local, | 81 | ieee80211_chanctx_reserved_chandef(struct ieee80211_local *local, |
68 | struct ieee80211_chanctx *ctx, | 82 | struct ieee80211_chanctx *ctx, |
@@ -160,6 +174,9 @@ ieee80211_find_reservation_chanctx(struct ieee80211_local *local, | |||
160 | return NULL; | 174 | return NULL; |
161 | 175 | ||
162 | list_for_each_entry(ctx, &local->chanctx_list, list) { | 176 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
177 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) | ||
178 | continue; | ||
179 | |||
163 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) | 180 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) |
164 | continue; | 181 | continue; |
165 | 182 | ||
@@ -347,6 +364,9 @@ ieee80211_find_chanctx(struct ieee80211_local *local, | |||
347 | list_for_each_entry(ctx, &local->chanctx_list, list) { | 364 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
348 | const struct cfg80211_chan_def *compat; | 365 | const struct cfg80211_chan_def *compat; |
349 | 366 | ||
367 | if (ctx->replace_state != IEEE80211_CHANCTX_REPLACE_NONE) | ||
368 | continue; | ||
369 | |||
350 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) | 370 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) |
351 | continue; | 371 | continue; |
352 | 372 | ||
@@ -622,6 +642,7 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) | |||
622 | struct ieee80211_local *local = sdata->local; | 642 | struct ieee80211_local *local = sdata->local; |
623 | struct ieee80211_chanctx_conf *conf; | 643 | struct ieee80211_chanctx_conf *conf; |
624 | struct ieee80211_chanctx *ctx; | 644 | struct ieee80211_chanctx *ctx; |
645 | bool use_reserved_switch = false; | ||
625 | 646 | ||
626 | lockdep_assert_held(&local->chanctx_mtx); | 647 | lockdep_assert_held(&local->chanctx_mtx); |
627 | 648 | ||
@@ -632,12 +653,23 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) | |||
632 | 653 | ||
633 | ctx = container_of(conf, struct ieee80211_chanctx, conf); | 654 | ctx = container_of(conf, struct ieee80211_chanctx, conf); |
634 | 655 | ||
635 | if (sdata->reserved_chanctx) | 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; | ||
662 | |||
636 | ieee80211_vif_unreserve_chanctx(sdata); | 663 | ieee80211_vif_unreserve_chanctx(sdata); |
664 | } | ||
637 | 665 | ||
638 | ieee80211_assign_vif_chanctx(sdata, NULL); | 666 | ieee80211_assign_vif_chanctx(sdata, NULL); |
639 | if (ieee80211_chanctx_refcount(local, ctx) == 0) | 667 | if (ieee80211_chanctx_refcount(local, ctx) == 0) |
640 | ieee80211_free_chanctx(local, ctx); | 668 | ieee80211_free_chanctx(local, ctx); |
669 | |||
670 | /* Unreserving may ready an in-place reservation. */ | ||
671 | if (use_reserved_switch) | ||
672 | ieee80211_vif_use_reserved_switch(local); | ||
641 | } | 673 | } |
642 | 674 | ||
643 | void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local, | 675 | void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local, |
@@ -787,70 +819,6 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, | |||
787 | return ret; | 819 | return ret; |
788 | } | 820 | } |
789 | 821 | ||
790 | static int __ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata, | ||
791 | struct ieee80211_chanctx *ctx, | ||
792 | u32 *changed) | ||
793 | { | ||
794 | struct ieee80211_local *local = sdata->local; | ||
795 | const struct cfg80211_chan_def *chandef = &sdata->csa_chandef; | ||
796 | u32 chanctx_changed = 0; | ||
797 | |||
798 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, | ||
799 | IEEE80211_CHAN_DISABLED)) | ||
800 | return -EINVAL; | ||
801 | |||
802 | if (ieee80211_chanctx_refcount(local, ctx) != 1) | ||
803 | return -EINVAL; | ||
804 | |||
805 | if (sdata->vif.bss_conf.chandef.width != chandef->width) { | ||
806 | chanctx_changed = IEEE80211_CHANCTX_CHANGE_WIDTH; | ||
807 | *changed |= BSS_CHANGED_BANDWIDTH; | ||
808 | } | ||
809 | |||
810 | sdata->vif.bss_conf.chandef = *chandef; | ||
811 | ctx->conf.def = *chandef; | ||
812 | |||
813 | chanctx_changed |= IEEE80211_CHANCTX_CHANGE_CHANNEL; | ||
814 | drv_change_chanctx(local, ctx, chanctx_changed); | ||
815 | |||
816 | ieee80211_recalc_chanctx_chantype(local, ctx); | ||
817 | ieee80211_recalc_smps_chanctx(local, ctx); | ||
818 | ieee80211_recalc_radar_chanctx(local, ctx); | ||
819 | ieee80211_recalc_chanctx_min_def(local, ctx); | ||
820 | |||
821 | return 0; | ||
822 | } | ||
823 | |||
824 | int ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata, | ||
825 | u32 *changed) | ||
826 | { | ||
827 | struct ieee80211_local *local = sdata->local; | ||
828 | struct ieee80211_chanctx_conf *conf; | ||
829 | struct ieee80211_chanctx *ctx; | ||
830 | int ret; | ||
831 | |||
832 | lockdep_assert_held(&local->mtx); | ||
833 | |||
834 | /* should never be called if not performing a channel switch. */ | ||
835 | if (WARN_ON(!sdata->vif.csa_active)) | ||
836 | return -EINVAL; | ||
837 | |||
838 | mutex_lock(&local->chanctx_mtx); | ||
839 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | ||
840 | lockdep_is_held(&local->chanctx_mtx)); | ||
841 | if (!conf) { | ||
842 | ret = -EINVAL; | ||
843 | goto out; | ||
844 | } | ||
845 | |||
846 | ctx = container_of(conf, struct ieee80211_chanctx, conf); | ||
847 | |||
848 | ret = __ieee80211_vif_change_channel(sdata, ctx, changed); | ||
849 | out: | ||
850 | mutex_unlock(&local->chanctx_mtx); | ||
851 | return ret; | ||
852 | } | ||
853 | |||
854 | static void | 822 | static void |
855 | __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, | 823 | __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, |
856 | bool clear) | 824 | bool clear) |
@@ -905,8 +873,25 @@ int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata) | |||
905 | list_del(&sdata->reserved_chanctx_list); | 873 | list_del(&sdata->reserved_chanctx_list); |
906 | sdata->reserved_chanctx = NULL; | 874 | sdata->reserved_chanctx = NULL; |
907 | 875 | ||
908 | if (ieee80211_chanctx_refcount(sdata->local, ctx) == 0) | 876 | if (ieee80211_chanctx_refcount(sdata->local, ctx) == 0) { |
909 | ieee80211_free_chanctx(sdata->local, ctx); | 877 | if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER) { |
878 | if (WARN_ON(!ctx->replace_ctx)) | ||
879 | return -EINVAL; | ||
880 | |||
881 | WARN_ON(ctx->replace_ctx->replace_state != | ||
882 | IEEE80211_CHANCTX_WILL_BE_REPLACED); | ||
883 | WARN_ON(ctx->replace_ctx->replace_ctx != ctx); | ||
884 | |||
885 | ctx->replace_ctx->replace_ctx = NULL; | ||
886 | ctx->replace_ctx->replace_state = | ||
887 | IEEE80211_CHANCTX_REPLACE_NONE; | ||
888 | |||
889 | list_del_rcu(&ctx->list); | ||
890 | kfree_rcu(ctx, rcu_head); | ||
891 | } else { | ||
892 | ieee80211_free_chanctx(sdata->local, ctx); | ||
893 | } | ||
894 | } | ||
910 | 895 | ||
911 | return 0; | 896 | return 0; |
912 | } | 897 | } |
@@ -917,40 +902,84 @@ int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata, | |||
917 | bool radar_required) | 902 | bool radar_required) |
918 | { | 903 | { |
919 | struct ieee80211_local *local = sdata->local; | 904 | struct ieee80211_local *local = sdata->local; |
920 | struct ieee80211_chanctx_conf *conf; | 905 | struct ieee80211_chanctx *new_ctx, *curr_ctx, *ctx; |
921 | struct ieee80211_chanctx *new_ctx, *curr_ctx; | ||
922 | int ret = 0; | ||
923 | 906 | ||
924 | mutex_lock(&local->chanctx_mtx); | 907 | lockdep_assert_held(&local->chanctx_mtx); |
925 | |||
926 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | ||
927 | lockdep_is_held(&local->chanctx_mtx)); | ||
928 | if (!conf) { | ||
929 | ret = -EINVAL; | ||
930 | goto out; | ||
931 | } | ||
932 | 908 | ||
933 | curr_ctx = container_of(conf, struct ieee80211_chanctx, conf); | 909 | curr_ctx = ieee80211_vif_get_chanctx(sdata); |
910 | if (curr_ctx && local->use_chanctx && !local->ops->switch_vif_chanctx) | ||
911 | return -ENOTSUPP; | ||
934 | 912 | ||
935 | new_ctx = ieee80211_find_reservation_chanctx(local, chandef, mode); | 913 | new_ctx = ieee80211_find_reservation_chanctx(local, chandef, mode); |
936 | if (!new_ctx) { | 914 | if (!new_ctx) { |
937 | if (ieee80211_chanctx_refcount(local, curr_ctx) == 1 && | 915 | if (ieee80211_can_create_new_chanctx(local)) { |
938 | (local->hw.flags & IEEE80211_HW_CHANGE_RUNNING_CHANCTX)) { | ||
939 | /* if we're the only users of the chanctx and | ||
940 | * the driver supports changing a running | ||
941 | * context, reserve our current context | ||
942 | */ | ||
943 | new_ctx = curr_ctx; | ||
944 | } else if (ieee80211_can_create_new_chanctx(local)) { | ||
945 | /* create a new context and reserve it */ | ||
946 | new_ctx = ieee80211_new_chanctx(local, chandef, mode); | 916 | new_ctx = ieee80211_new_chanctx(local, chandef, mode); |
947 | if (IS_ERR(new_ctx)) { | 917 | if (IS_ERR(new_ctx)) |
948 | ret = PTR_ERR(new_ctx); | 918 | return PTR_ERR(new_ctx); |
949 | goto out; | ||
950 | } | ||
951 | } else { | 919 | } else { |
952 | ret = -EBUSY; | 920 | if (!curr_ctx || |
953 | goto out; | 921 | (curr_ctx->replace_state == |
922 | IEEE80211_CHANCTX_WILL_BE_REPLACED) || | ||
923 | !list_empty(&curr_ctx->reserved_vifs)) { | ||
924 | /* | ||
925 | * Another vif already requested this context | ||
926 | * for a reservation. Find another one hoping | ||
927 | * all vifs assigned to it will also switch | ||
928 | * soon enough. | ||
929 | * | ||
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 | ||
934 | * performed. | ||
935 | * | ||
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. | ||
945 | */ | ||
946 | list_for_each_entry(ctx, &local->chanctx_list, | ||
947 | list) { | ||
948 | if (ctx->replace_state != | ||
949 | IEEE80211_CHANCTX_REPLACE_NONE) | ||
950 | continue; | ||
951 | |||
952 | if (!list_empty(&ctx->reserved_vifs)) | ||
953 | continue; | ||
954 | |||
955 | curr_ctx = ctx; | ||
956 | break; | ||
957 | } | ||
958 | } | ||
959 | |||
960 | /* | ||
961 | * If that's true then all available contexts already | ||
962 | * have reservations and cannot be used. | ||
963 | */ | ||
964 | if (!curr_ctx || | ||
965 | (curr_ctx->replace_state == | ||
966 | IEEE80211_CHANCTX_WILL_BE_REPLACED) || | ||
967 | !list_empty(&curr_ctx->reserved_vifs)) | ||
968 | return -EBUSY; | ||
969 | |||
970 | new_ctx = ieee80211_alloc_chanctx(local, chandef, mode); | ||
971 | if (!new_ctx) | ||
972 | return -ENOMEM; | ||
973 | |||
974 | new_ctx->replace_ctx = curr_ctx; | ||
975 | new_ctx->replace_state = | ||
976 | IEEE80211_CHANCTX_REPLACES_OTHER; | ||
977 | |||
978 | curr_ctx->replace_ctx = new_ctx; | ||
979 | curr_ctx->replace_state = | ||
980 | IEEE80211_CHANCTX_WILL_BE_REPLACED; | ||
981 | |||
982 | list_add_rcu(&new_ctx->list, &local->chanctx_list); | ||
954 | } | 983 | } |
955 | } | 984 | } |
956 | 985 | ||
@@ -958,82 +987,601 @@ int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata, | |||
958 | sdata->reserved_chanctx = new_ctx; | 987 | sdata->reserved_chanctx = new_ctx; |
959 | sdata->reserved_chandef = *chandef; | 988 | sdata->reserved_chandef = *chandef; |
960 | sdata->reserved_radar_required = radar_required; | 989 | sdata->reserved_radar_required = radar_required; |
961 | out: | 990 | sdata->reserved_ready = false; |
962 | mutex_unlock(&local->chanctx_mtx); | 991 | |
963 | return ret; | 992 | return 0; |
964 | } | 993 | } |
965 | 994 | ||
966 | int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata, | 995 | static void |
967 | u32 *changed) | 996 | ieee80211_vif_chanctx_reservation_complete(struct ieee80211_sub_if_data *sdata) |
968 | { | 997 | { |
969 | struct ieee80211_local *local = sdata->local; | 998 | switch (sdata->vif.type) { |
970 | struct ieee80211_chanctx *ctx; | 999 | case NL80211_IFTYPE_ADHOC: |
971 | struct ieee80211_chanctx *old_ctx; | 1000 | case NL80211_IFTYPE_AP: |
972 | struct ieee80211_chanctx_conf *conf; | 1001 | case NL80211_IFTYPE_MESH_POINT: |
973 | int ret; | 1002 | ieee80211_queue_work(&sdata->local->hw, |
974 | u32 tmp_changed = *changed; | 1003 | &sdata->csa_finalize_work); |
1004 | break; | ||
1005 | case NL80211_IFTYPE_STATION: | ||
1006 | ieee80211_queue_work(&sdata->local->hw, | ||
1007 | &sdata->u.mgd.chswitch_work); | ||
1008 | break; | ||
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: | ||
1017 | WARN_ON(1); | ||
1018 | break; | ||
1019 | } | ||
1020 | } | ||
975 | 1021 | ||
976 | /* TODO: need to recheck if the chandef is usable etc.? */ | 1022 | static int |
1023 | ieee80211_vif_use_reserved_reassign(struct ieee80211_sub_if_data *sdata) | ||
1024 | { | ||
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; | ||
1029 | u32 changed = 0; | ||
1030 | int err; | ||
977 | 1031 | ||
978 | lockdep_assert_held(&local->mtx); | 1032 | lockdep_assert_held(&local->mtx); |
1033 | lockdep_assert_held(&local->chanctx_mtx); | ||
979 | 1034 | ||
980 | mutex_lock(&local->chanctx_mtx); | 1035 | new_ctx = sdata->reserved_chanctx; |
1036 | old_ctx = ieee80211_vif_get_chanctx(sdata); | ||
981 | 1037 | ||
982 | ctx = sdata->reserved_chanctx; | 1038 | if (WARN_ON(!sdata->reserved_ready)) |
983 | if (WARN_ON(!ctx)) { | 1039 | return -EBUSY; |
984 | ret = -EINVAL; | 1040 | |
985 | goto out; | 1041 | if (WARN_ON(!new_ctx)) |
986 | } | 1042 | return -EINVAL; |
1043 | |||
1044 | if (WARN_ON(!old_ctx)) | ||
1045 | return -EINVAL; | ||
1046 | |||
1047 | if (WARN_ON(new_ctx->replace_state == | ||
1048 | IEEE80211_CHANCTX_REPLACES_OTHER)) | ||
1049 | return -EINVAL; | ||
1050 | |||
1051 | chandef = ieee80211_chanctx_non_reserved_chandef(local, new_ctx, | ||
1052 | &sdata->reserved_chandef); | ||
1053 | if (WARN_ON(!chandef)) | ||
1054 | return -EINVAL; | ||
1055 | |||
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; | ||
1059 | |||
1060 | list_del(&sdata->reserved_chanctx_list); | ||
1061 | sdata->reserved_chanctx = NULL; | ||
1062 | |||
1063 | err = drv_switch_vif_chanctx(local, vif_chsw, 1, | ||
1064 | CHANCTX_SWMODE_REASSIGN_VIF); | ||
1065 | if (err) { | ||
1066 | if (ieee80211_chanctx_refcount(local, new_ctx) == 0) | ||
1067 | ieee80211_free_chanctx(local, new_ctx); | ||
987 | 1068 | ||
988 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | ||
989 | lockdep_is_held(&local->chanctx_mtx)); | ||
990 | if (!conf) { | ||
991 | ret = -EINVAL; | ||
992 | goto out; | 1069 | goto out; |
993 | } | 1070 | } |
994 | 1071 | ||
995 | old_ctx = container_of(conf, struct ieee80211_chanctx, conf); | 1072 | list_move(&sdata->assigned_chanctx_list, &new_ctx->assigned_vifs); |
1073 | rcu_assign_pointer(sdata->vif.chanctx_conf, &new_ctx->conf); | ||
1074 | |||
1075 | if (sdata->vif.type == NL80211_IFTYPE_AP) | ||
1076 | __ieee80211_vif_copy_chanctx_to_vlans(sdata, false); | ||
1077 | |||
1078 | if (ieee80211_chanctx_refcount(local, old_ctx) == 0) | ||
1079 | ieee80211_free_chanctx(local, old_ctx); | ||
996 | 1080 | ||
997 | if (sdata->vif.bss_conf.chandef.width != sdata->reserved_chandef.width) | 1081 | if (sdata->vif.bss_conf.chandef.width != sdata->reserved_chandef.width) |
998 | tmp_changed |= BSS_CHANGED_BANDWIDTH; | 1082 | changed = BSS_CHANGED_BANDWIDTH; |
999 | 1083 | ||
1000 | sdata->vif.bss_conf.chandef = sdata->reserved_chandef; | 1084 | sdata->vif.bss_conf.chandef = sdata->reserved_chandef; |
1001 | 1085 | ||
1002 | /* unref our reservation */ | 1086 | if (changed) |
1003 | sdata->reserved_chanctx = NULL; | 1087 | ieee80211_bss_info_change_notify(sdata, changed); |
1004 | sdata->radar_required = sdata->reserved_radar_required; | 1088 | |
1089 | out: | ||
1090 | ieee80211_vif_chanctx_reservation_complete(sdata); | ||
1091 | return err; | ||
1092 | } | ||
1093 | |||
1094 | static int | ||
1095 | ieee80211_vif_use_reserved_assign(struct ieee80211_sub_if_data *sdata) | ||
1096 | { | ||
1097 | struct ieee80211_local *local = sdata->local; | ||
1098 | struct ieee80211_chanctx *old_ctx, *new_ctx; | ||
1099 | const struct cfg80211_chan_def *chandef; | ||
1100 | int err; | ||
1101 | |||
1102 | old_ctx = ieee80211_vif_get_chanctx(sdata); | ||
1103 | new_ctx = sdata->reserved_chanctx; | ||
1104 | |||
1105 | if (WARN_ON(!sdata->reserved_ready)) | ||
1106 | return -EINVAL; | ||
1107 | |||
1108 | if (WARN_ON(old_ctx)) | ||
1109 | return -EINVAL; | ||
1110 | |||
1111 | if (WARN_ON(!new_ctx)) | ||
1112 | return -EINVAL; | ||
1113 | |||
1114 | if (WARN_ON(new_ctx->replace_state == | ||
1115 | IEEE80211_CHANCTX_REPLACES_OTHER)) | ||
1116 | return -EINVAL; | ||
1117 | |||
1118 | chandef = ieee80211_chanctx_non_reserved_chandef(local, new_ctx, | ||
1119 | &sdata->reserved_chandef); | ||
1120 | if (WARN_ON(!chandef)) | ||
1121 | return -EINVAL; | ||
1122 | |||
1005 | list_del(&sdata->reserved_chanctx_list); | 1123 | list_del(&sdata->reserved_chanctx_list); |
1124 | sdata->reserved_chanctx = NULL; | ||
1006 | 1125 | ||
1007 | if (old_ctx == ctx) { | 1126 | err = ieee80211_assign_vif_chanctx(sdata, new_ctx); |
1008 | /* This is our own context, just change it */ | 1127 | if (err) { |
1009 | ret = __ieee80211_vif_change_channel(sdata, old_ctx, | 1128 | if (ieee80211_chanctx_refcount(local, new_ctx) == 0) |
1010 | &tmp_changed); | 1129 | ieee80211_free_chanctx(local, new_ctx); |
1011 | if (ret) | 1130 | |
1012 | goto out; | 1131 | goto out; |
1013 | } else { | 1132 | } |
1014 | ret = ieee80211_assign_vif_chanctx(sdata, ctx); | 1133 | |
1015 | if (ieee80211_chanctx_refcount(local, old_ctx) == 0) | 1134 | out: |
1016 | ieee80211_free_chanctx(local, old_ctx); | 1135 | ieee80211_vif_chanctx_reservation_complete(sdata); |
1017 | if (ret) { | 1136 | return err; |
1018 | /* if assign fails refcount stays the same */ | 1137 | } |
1019 | if (ieee80211_chanctx_refcount(local, ctx) == 0) | 1138 | |
1020 | ieee80211_free_chanctx(local, ctx); | 1139 | static bool |
1140 | ieee80211_vif_has_in_place_reservation(struct ieee80211_sub_if_data *sdata) | ||
1141 | { | ||
1142 | struct ieee80211_chanctx *old_ctx, *new_ctx; | ||
1143 | |||
1144 | lockdep_assert_held(&sdata->local->chanctx_mtx); | ||
1145 | |||
1146 | new_ctx = sdata->reserved_chanctx; | ||
1147 | old_ctx = ieee80211_vif_get_chanctx(sdata); | ||
1148 | |||
1149 | if (!old_ctx) | ||
1150 | return false; | ||
1151 | |||
1152 | if (WARN_ON(!new_ctx)) | ||
1153 | return false; | ||
1154 | |||
1155 | if (old_ctx->replace_state != IEEE80211_CHANCTX_WILL_BE_REPLACED) | ||
1156 | return false; | ||
1157 | |||
1158 | if (new_ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER) | ||
1159 | return false; | ||
1160 | |||
1161 | return true; | ||
1162 | } | ||
1163 | |||
1164 | static int ieee80211_chsw_switch_hwconf(struct ieee80211_local *local, | ||
1165 | struct ieee80211_chanctx *new_ctx) | ||
1166 | { | ||
1167 | const struct cfg80211_chan_def *chandef; | ||
1168 | |||
1169 | lockdep_assert_held(&local->mtx); | ||
1170 | lockdep_assert_held(&local->chanctx_mtx); | ||
1171 | |||
1172 | chandef = ieee80211_chanctx_reserved_chandef(local, new_ctx, NULL); | ||
1173 | if (WARN_ON(!chandef)) | ||
1174 | return -EINVAL; | ||
1175 | |||
1176 | local->hw.conf.radar_enabled = new_ctx->conf.radar_enabled; | ||
1177 | local->_oper_chandef = *chandef; | ||
1178 | ieee80211_hw_config(local, 0); | ||
1179 | |||
1180 | return 0; | ||
1181 | } | ||
1182 | |||
1183 | static int ieee80211_chsw_switch_vifs(struct ieee80211_local *local, | ||
1184 | int n_vifs) | ||
1185 | { | ||
1186 | struct ieee80211_vif_chanctx_switch *vif_chsw; | ||
1187 | struct ieee80211_sub_if_data *sdata; | ||
1188 | struct ieee80211_chanctx *ctx, *old_ctx; | ||
1189 | int i, err; | ||
1190 | |||
1191 | lockdep_assert_held(&local->mtx); | ||
1192 | lockdep_assert_held(&local->chanctx_mtx); | ||
1193 | |||
1194 | vif_chsw = kzalloc(sizeof(vif_chsw[0]) * n_vifs, GFP_KERNEL); | ||
1195 | if (!vif_chsw) | ||
1196 | return -ENOMEM; | ||
1197 | |||
1198 | i = 0; | ||
1199 | list_for_each_entry(ctx, &local->chanctx_list, list) { | ||
1200 | if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER) | ||
1201 | continue; | ||
1202 | |||
1203 | if (WARN_ON(!ctx->replace_ctx)) { | ||
1204 | err = -EINVAL; | ||
1021 | goto out; | 1205 | goto out; |
1022 | } | 1206 | } |
1023 | 1207 | ||
1024 | if (sdata->vif.type == NL80211_IFTYPE_AP) | 1208 | list_for_each_entry(sdata, &ctx->reserved_vifs, |
1025 | __ieee80211_vif_copy_chanctx_to_vlans(sdata, false); | 1209 | reserved_chanctx_list) { |
1210 | if (!ieee80211_vif_has_in_place_reservation( | ||
1211 | sdata)) | ||
1212 | continue; | ||
1213 | |||
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; | ||
1218 | |||
1219 | i++; | ||
1220 | } | ||
1026 | } | 1221 | } |
1027 | 1222 | ||
1028 | *changed = tmp_changed; | 1223 | err = drv_switch_vif_chanctx(local, vif_chsw, n_vifs, |
1224 | CHANCTX_SWMODE_SWAP_CONTEXTS); | ||
1029 | 1225 | ||
1030 | ieee80211_recalc_chanctx_chantype(local, ctx); | ||
1031 | ieee80211_recalc_smps_chanctx(local, ctx); | ||
1032 | ieee80211_recalc_radar_chanctx(local, ctx); | ||
1033 | ieee80211_recalc_chanctx_min_def(local, ctx); | ||
1034 | out: | 1226 | out: |
1035 | mutex_unlock(&local->chanctx_mtx); | 1227 | kfree(vif_chsw); |
1036 | return ret; | 1228 | return err; |
1229 | } | ||
1230 | |||
1231 | static int ieee80211_chsw_switch_ctxs(struct ieee80211_local *local) | ||
1232 | { | ||
1233 | struct ieee80211_chanctx *ctx; | ||
1234 | int err; | ||
1235 | |||
1236 | lockdep_assert_held(&local->mtx); | ||
1237 | lockdep_assert_held(&local->chanctx_mtx); | ||
1238 | |||
1239 | list_for_each_entry(ctx, &local->chanctx_list, list) { | ||
1240 | if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER) | ||
1241 | continue; | ||
1242 | |||
1243 | if (!list_empty(&ctx->replace_ctx->assigned_vifs)) | ||
1244 | continue; | ||
1245 | |||
1246 | ieee80211_del_chanctx(local, ctx->replace_ctx); | ||
1247 | err = ieee80211_add_chanctx(local, ctx); | ||
1248 | if (err) | ||
1249 | goto err; | ||
1250 | } | ||
1251 | |||
1252 | return 0; | ||
1253 | |||
1254 | err: | ||
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) | ||
1258 | continue; | ||
1259 | |||
1260 | if (!list_empty(&ctx->replace_ctx->assigned_vifs)) | ||
1261 | continue; | ||
1262 | |||
1263 | ieee80211_del_chanctx(local, ctx); | ||
1264 | WARN_ON(ieee80211_add_chanctx(local, ctx->replace_ctx)); | ||
1265 | } | ||
1266 | |||
1267 | return err; | ||
1268 | } | ||
1269 | |||
1270 | int | ||
1271 | ieee80211_vif_use_reserved_switch(struct ieee80211_local *local) | ||
1272 | { | ||
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; | ||
1278 | |||
1279 | lockdep_assert_held(&local->mtx); | ||
1280 | lockdep_assert_held(&local->chanctx_mtx); | ||
1281 | |||
1282 | /* | ||
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 | ||
1286 | * other is ready. | ||
1287 | * | ||
1288 | * For practical reasons and code simplicity just do a single huge | ||
1289 | * switch. | ||
1290 | */ | ||
1291 | |||
1292 | /* | ||
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 | ||
1296 | */ | ||
1297 | |||
1298 | list_for_each_entry(ctx, &local->chanctx_list, list) { | ||
1299 | if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER) | ||
1300 | continue; | ||
1301 | |||
1302 | if (WARN_ON(!ctx->replace_ctx)) { | ||
1303 | err = -EINVAL; | ||
1304 | goto err; | ||
1305 | } | ||
1306 | |||
1307 | if (!local->use_chanctx) | ||
1308 | new_ctx = ctx; | ||
1309 | |||
1310 | n_ctx++; | ||
1311 | |||
1312 | n_assigned = 0; | ||
1313 | n_reserved = 0; | ||
1314 | n_ready = 0; | ||
1315 | |||
1316 | list_for_each_entry(sdata, &ctx->replace_ctx->assigned_vifs, | ||
1317 | assigned_chanctx_list) { | ||
1318 | n_assigned++; | ||
1319 | if (sdata->reserved_chanctx) { | ||
1320 | n_reserved++; | ||
1321 | if (sdata->reserved_ready) | ||
1322 | n_ready++; | ||
1323 | } | ||
1324 | } | ||
1325 | |||
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"); | ||
1330 | err = -EBUSY; | ||
1331 | goto err; | ||
1332 | } | ||
1333 | |||
1334 | return -EAGAIN; | ||
1335 | } | ||
1336 | |||
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) | ||
1342 | return -EAGAIN; | ||
1343 | |||
1344 | old_ctx = ieee80211_vif_get_chanctx(sdata); | ||
1345 | if (old_ctx) { | ||
1346 | if (old_ctx->replace_state == | ||
1347 | IEEE80211_CHANCTX_WILL_BE_REPLACED) | ||
1348 | n_vifs_switch++; | ||
1349 | else | ||
1350 | n_vifs_assign++; | ||
1351 | } else { | ||
1352 | n_vifs_ctxless++; | ||
1353 | } | ||
1354 | |||
1355 | if (sdata->reserved_radar_required) | ||
1356 | ctx->conf.radar_enabled = true; | ||
1357 | } | ||
1358 | } | ||
1359 | |||
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)) { | ||
1366 | err = -EINVAL; | ||
1367 | goto err; | ||
1368 | } | ||
1369 | |||
1370 | /* | ||
1371 | * All necessary vifs are ready. Perform the switch now depending on | ||
1372 | * reservations and driver capabilities. | ||
1373 | */ | ||
1374 | |||
1375 | if (local->use_chanctx) { | ||
1376 | if (n_vifs_switch > 0) { | ||
1377 | err = ieee80211_chsw_switch_vifs(local, n_vifs_switch); | ||
1378 | if (err) | ||
1379 | goto err; | ||
1380 | } | ||
1381 | |||
1382 | if (n_vifs_assign > 0 || n_vifs_ctxless > 0) { | ||
1383 | err = ieee80211_chsw_switch_ctxs(local); | ||
1384 | if (err) | ||
1385 | goto err; | ||
1386 | } | ||
1387 | } else { | ||
1388 | err = ieee80211_chsw_switch_hwconf(local, new_ctx); | ||
1389 | if (err) | ||
1390 | goto err; | ||
1391 | } | ||
1392 | |||
1393 | /* | ||
1394 | * Update all structures, values and pointers to point to new channel | ||
1395 | * context(s). | ||
1396 | */ | ||
1397 | |||
1398 | i = 0; | ||
1399 | list_for_each_entry(ctx, &local->chanctx_list, list) { | ||
1400 | if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER) | ||
1401 | continue; | ||
1402 | |||
1403 | if (WARN_ON(!ctx->replace_ctx)) { | ||
1404 | err = -EINVAL; | ||
1405 | goto err; | ||
1406 | } | ||
1407 | |||
1408 | list_for_each_entry(sdata, &ctx->reserved_vifs, | ||
1409 | reserved_chanctx_list) { | ||
1410 | u32 changed = 0; | ||
1411 | |||
1412 | if (!ieee80211_vif_has_in_place_reservation(sdata)) | ||
1413 | continue; | ||
1414 | |||
1415 | rcu_assign_pointer(sdata->vif.chanctx_conf, &ctx->conf); | ||
1416 | |||
1417 | if (sdata->vif.type == NL80211_IFTYPE_AP) | ||
1418 | __ieee80211_vif_copy_chanctx_to_vlans(sdata, | ||
1419 | false); | ||
1420 | |||
1421 | sdata->radar_required = sdata->reserved_radar_required; | ||
1422 | |||
1423 | if (sdata->vif.bss_conf.chandef.width != | ||
1424 | sdata->reserved_chandef.width) | ||
1425 | changed = BSS_CHANGED_BANDWIDTH; | ||
1426 | |||
1427 | sdata->vif.bss_conf.chandef = sdata->reserved_chandef; | ||
1428 | if (changed) | ||
1429 | ieee80211_bss_info_change_notify(sdata, | ||
1430 | changed); | ||
1431 | |||
1432 | ieee80211_recalc_txpower(sdata); | ||
1433 | } | ||
1434 | |||
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); | ||
1439 | |||
1440 | list_for_each_entry_safe(sdata, sdata_tmp, &ctx->reserved_vifs, | ||
1441 | reserved_chanctx_list) { | ||
1442 | if (ieee80211_vif_get_chanctx(sdata) != ctx) | ||
1443 | continue; | ||
1444 | |||
1445 | list_del(&sdata->reserved_chanctx_list); | ||
1446 | list_move(&sdata->assigned_chanctx_list, | ||
1447 | &new_ctx->assigned_vifs); | ||
1448 | sdata->reserved_chanctx = NULL; | ||
1449 | |||
1450 | ieee80211_vif_chanctx_reservation_complete(sdata); | ||
1451 | } | ||
1452 | |||
1453 | /* | ||
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. | ||
1459 | */ | ||
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( | ||
1463 | sdata))) | ||
1464 | continue; | ||
1465 | |||
1466 | if (WARN_ON(sdata->reserved_chanctx != ctx)) | ||
1467 | continue; | ||
1468 | |||
1469 | if (!sdata->reserved_ready) | ||
1470 | continue; | ||
1471 | |||
1472 | if (ieee80211_vif_get_chanctx(sdata)) | ||
1473 | err = ieee80211_vif_use_reserved_reassign( | ||
1474 | sdata); | ||
1475 | else | ||
1476 | err = ieee80211_vif_use_reserved_assign(sdata); | ||
1477 | |||
1478 | if (err) { | ||
1479 | sdata_info(sdata, | ||
1480 | "failed to finalize (re-)assign reservation (err=%d)\n", | ||
1481 | err); | ||
1482 | ieee80211_vif_unreserve_chanctx(sdata); | ||
1483 | cfg80211_stop_iface(local->hw.wiphy, | ||
1484 | &sdata->wdev, | ||
1485 | GFP_KERNEL); | ||
1486 | } | ||
1487 | } | ||
1488 | } | ||
1489 | |||
1490 | /* | ||
1491 | * Finally free old contexts | ||
1492 | */ | ||
1493 | |||
1494 | list_for_each_entry_safe(ctx, ctx_tmp, &local->chanctx_list, list) { | ||
1495 | if (ctx->replace_state != IEEE80211_CHANCTX_WILL_BE_REPLACED) | ||
1496 | continue; | ||
1497 | |||
1498 | ctx->replace_ctx->replace_ctx = NULL; | ||
1499 | ctx->replace_ctx->replace_state = | ||
1500 | IEEE80211_CHANCTX_REPLACE_NONE; | ||
1501 | |||
1502 | list_del_rcu(&ctx->list); | ||
1503 | kfree_rcu(ctx, rcu_head); | ||
1504 | } | ||
1505 | |||
1506 | return 0; | ||
1507 | |||
1508 | err: | ||
1509 | list_for_each_entry(ctx, &local->chanctx_list, list) { | ||
1510 | if (ctx->replace_state != IEEE80211_CHANCTX_REPLACES_OTHER) | ||
1511 | continue; | ||
1512 | |||
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); | ||
1517 | } | ||
1518 | } | ||
1519 | |||
1520 | return err; | ||
1521 | } | ||
1522 | |||
1523 | int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata) | ||
1524 | { | ||
1525 | struct ieee80211_local *local = sdata->local; | ||
1526 | struct ieee80211_chanctx *new_ctx; | ||
1527 | struct ieee80211_chanctx *old_ctx; | ||
1528 | int err; | ||
1529 | |||
1530 | lockdep_assert_held(&local->mtx); | ||
1531 | lockdep_assert_held(&local->chanctx_mtx); | ||
1532 | |||
1533 | new_ctx = sdata->reserved_chanctx; | ||
1534 | old_ctx = ieee80211_vif_get_chanctx(sdata); | ||
1535 | |||
1536 | if (WARN_ON(!new_ctx)) | ||
1537 | return -EINVAL; | ||
1538 | |||
1539 | if (WARN_ON(new_ctx->replace_state == | ||
1540 | IEEE80211_CHANCTX_WILL_BE_REPLACED)) | ||
1541 | return -EINVAL; | ||
1542 | |||
1543 | if (WARN_ON(sdata->reserved_ready)) | ||
1544 | return -EINVAL; | ||
1545 | |||
1546 | sdata->reserved_ready = true; | ||
1547 | |||
1548 | if (new_ctx->replace_state == IEEE80211_CHANCTX_REPLACE_NONE) { | ||
1549 | if (old_ctx) | ||
1550 | err = ieee80211_vif_use_reserved_reassign(sdata); | ||
1551 | else | ||
1552 | err = ieee80211_vif_use_reserved_assign(sdata); | ||
1553 | |||
1554 | if (err) | ||
1555 | return err; | ||
1556 | } | ||
1557 | |||
1558 | /* | ||
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 | ||
1563 | * | ||
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. | ||
1568 | */ | ||
1569 | if ((old_ctx && | ||
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) | ||
1576 | return err; | ||
1577 | |||
1578 | wiphy_info(local->hw.wiphy, | ||
1579 | "depending in-place reservation failed (err=%d)\n", | ||
1580 | err); | ||
1581 | } | ||
1582 | } | ||
1583 | |||
1584 | return 0; | ||
1037 | } | 1585 | } |
1038 | 1586 | ||
1039 | int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata, | 1587 | int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata, |
@@ -1043,6 +1591,7 @@ int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata, | |||
1043 | struct ieee80211_local *local = sdata->local; | 1591 | struct ieee80211_local *local = sdata->local; |
1044 | struct ieee80211_chanctx_conf *conf; | 1592 | struct ieee80211_chanctx_conf *conf; |
1045 | struct ieee80211_chanctx *ctx; | 1593 | struct ieee80211_chanctx *ctx; |
1594 | const struct cfg80211_chan_def *compat; | ||
1046 | int ret; | 1595 | int ret; |
1047 | 1596 | ||
1048 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, | 1597 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
@@ -1069,11 +1618,33 @@ int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata, | |||
1069 | } | 1618 | } |
1070 | 1619 | ||
1071 | ctx = container_of(conf, struct ieee80211_chanctx, conf); | 1620 | ctx = container_of(conf, struct ieee80211_chanctx, conf); |
1072 | if (!cfg80211_chandef_compatible(&conf->def, chandef)) { | 1621 | |
1622 | compat = cfg80211_chandef_compatible(&conf->def, chandef); | ||
1623 | if (!compat) { | ||
1073 | ret = -EINVAL; | 1624 | ret = -EINVAL; |
1074 | goto out; | 1625 | goto out; |
1075 | } | 1626 | } |
1076 | 1627 | ||
1628 | switch (ctx->replace_state) { | ||
1629 | case IEEE80211_CHANCTX_REPLACE_NONE: | ||
1630 | if (!ieee80211_chanctx_reserved_chandef(local, ctx, compat)) { | ||
1631 | ret = -EBUSY; | ||
1632 | goto out; | ||
1633 | } | ||
1634 | break; | ||
1635 | case IEEE80211_CHANCTX_WILL_BE_REPLACED: | ||
1636 | /* TODO: Perhaps the bandwith change could be treated as a | ||
1637 | * reservation itself? */ | ||
1638 | ret = -EBUSY; | ||
1639 | goto out; | ||
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 | ||
1643 | * anywhere yet */ | ||
1644 | WARN_ON(1); | ||
1645 | break; | ||
1646 | } | ||
1647 | |||
1077 | sdata->vif.bss_conf.chandef = *chandef; | 1648 | sdata->vif.bss_conf.chandef = *chandef; |
1078 | 1649 | ||
1079 | ieee80211_recalc_chanctx_chantype(local, ctx); | 1650 | ieee80211_recalc_chanctx_chantype(local, ctx); |