Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 - channel management |
| 3 | */ |
| 4 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 5 | #include <linux/nl80211.h> |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 6 | #include <linux/export.h> |
Johannes Berg | 4d76d21 | 2012-12-11 20:38:41 +0100 | [diff] [blame] | 7 | #include <linux/rtnetlink.h> |
Paul Stewart | 3117bbdb | 2012-03-13 07:46:18 -0700 | [diff] [blame] | 8 | #include <net/cfg80211.h> |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9 | #include "ieee80211_i.h" |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 10 | #include "driver-ops.h" |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 11 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 12 | static void ieee80211_change_chandef(struct ieee80211_local *local, |
| 13 | struct ieee80211_chanctx *ctx, |
| 14 | const struct cfg80211_chan_def *chandef) |
Michal Kazior | 23a85b45 | 2012-06-26 14:37:21 +0200 | [diff] [blame] | 15 | { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 16 | if (cfg80211_chandef_identical(&ctx->conf.def, chandef)) |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 17 | return; |
| 18 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 19 | WARN_ON(!cfg80211_chandef_compatible(&ctx->conf.def, chandef)); |
| 20 | |
| 21 | ctx->conf.def = *chandef; |
| 22 | drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_WIDTH); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 23 | |
| 24 | if (!local->use_chanctx) { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 25 | local->_oper_channel_type = cfg80211_get_chandef_type(chandef); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 26 | ieee80211_hw_config(local, 0); |
| 27 | } |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 28 | } |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 29 | |
| 30 | static struct ieee80211_chanctx * |
| 31 | ieee80211_find_chanctx(struct ieee80211_local *local, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 32 | const struct cfg80211_chan_def *chandef, |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 33 | enum ieee80211_chanctx_mode mode) |
| 34 | { |
| 35 | struct ieee80211_chanctx *ctx; |
| 36 | |
| 37 | lockdep_assert_held(&local->chanctx_mtx); |
| 38 | |
| 39 | if (mode == IEEE80211_CHANCTX_EXCLUSIVE) |
| 40 | return NULL; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 41 | |
| 42 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 43 | const struct cfg80211_chan_def *compat; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 44 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 45 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) |
| 46 | continue; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 47 | |
| 48 | compat = cfg80211_chandef_compatible(&ctx->conf.def, chandef); |
| 49 | if (!compat) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 50 | continue; |
| 51 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 52 | ieee80211_change_chandef(local, ctx, compat); |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 53 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 54 | return ctx; |
| 55 | } |
| 56 | |
| 57 | return NULL; |
| 58 | } |
| 59 | |
| 60 | static struct ieee80211_chanctx * |
| 61 | ieee80211_new_chanctx(struct ieee80211_local *local, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 62 | const struct cfg80211_chan_def *chandef, |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 63 | enum ieee80211_chanctx_mode mode) |
| 64 | { |
| 65 | struct ieee80211_chanctx *ctx; |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 66 | int err; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 67 | |
| 68 | lockdep_assert_held(&local->chanctx_mtx); |
| 69 | |
| 70 | ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL); |
| 71 | if (!ctx) |
| 72 | return ERR_PTR(-ENOMEM); |
| 73 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 74 | ctx->conf.def = *chandef; |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 75 | ctx->conf.rx_chains_static = 1; |
| 76 | ctx->conf.rx_chains_dynamic = 1; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 77 | ctx->mode = mode; |
| 78 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 79 | if (!local->use_chanctx) { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 80 | local->_oper_channel_type = |
| 81 | cfg80211_get_chandef_type(chandef); |
| 82 | local->_oper_channel = chandef->chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 83 | ieee80211_hw_config(local, 0); |
| 84 | } else { |
| 85 | err = drv_add_chanctx(local, ctx); |
| 86 | if (err) { |
| 87 | kfree(ctx); |
| 88 | return ERR_PTR(err); |
| 89 | } |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 92 | list_add_rcu(&ctx->list, &local->chanctx_list); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 93 | |
Johannes Berg | fd0f979 | 2013-02-07 00:14:51 +0100 | [diff] [blame] | 94 | mutex_lock(&local->mtx); |
| 95 | ieee80211_recalc_idle(local); |
| 96 | mutex_unlock(&local->mtx); |
| 97 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 98 | return ctx; |
| 99 | } |
| 100 | |
| 101 | static void ieee80211_free_chanctx(struct ieee80211_local *local, |
| 102 | struct ieee80211_chanctx *ctx) |
| 103 | { |
| 104 | lockdep_assert_held(&local->chanctx_mtx); |
| 105 | |
| 106 | WARN_ON_ONCE(ctx->refcount != 0); |
| 107 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 108 | if (!local->use_chanctx) { |
| 109 | local->_oper_channel_type = NL80211_CHAN_NO_HT; |
| 110 | ieee80211_hw_config(local, 0); |
| 111 | } else { |
| 112 | drv_remove_chanctx(local, ctx); |
| 113 | } |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 114 | |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 115 | list_del_rcu(&ctx->list); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 116 | kfree_rcu(ctx, rcu_head); |
Johannes Berg | fd0f979 | 2013-02-07 00:14:51 +0100 | [diff] [blame] | 117 | |
| 118 | mutex_lock(&local->mtx); |
| 119 | ieee80211_recalc_idle(local); |
| 120 | mutex_unlock(&local->mtx); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata, |
| 124 | struct ieee80211_chanctx *ctx) |
| 125 | { |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 126 | struct ieee80211_local *local = sdata->local; |
| 127 | int ret; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 128 | |
| 129 | lockdep_assert_held(&local->chanctx_mtx); |
| 130 | |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 131 | ret = drv_assign_vif_chanctx(local, sdata, ctx); |
| 132 | if (ret) |
| 133 | return ret; |
| 134 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 135 | rcu_assign_pointer(sdata->vif.chanctx_conf, &ctx->conf); |
| 136 | ctx->refcount++; |
| 137 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 138 | ieee80211_recalc_txpower(sdata); |
Johannes Berg | fd0f979 | 2013-02-07 00:14:51 +0100 | [diff] [blame] | 139 | sdata->vif.bss_conf.idle = false; |
| 140 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 141 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 145 | static void ieee80211_recalc_chanctx_chantype(struct ieee80211_local *local, |
| 146 | struct ieee80211_chanctx *ctx) |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 147 | { |
| 148 | struct ieee80211_chanctx_conf *conf = &ctx->conf; |
| 149 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 150 | const struct cfg80211_chan_def *compat = NULL; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 151 | |
| 152 | lockdep_assert_held(&local->chanctx_mtx); |
| 153 | |
| 154 | rcu_read_lock(); |
| 155 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 156 | |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 157 | if (!ieee80211_sdata_running(sdata)) |
| 158 | continue; |
| 159 | if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf) |
| 160 | continue; |
| 161 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 162 | if (!compat) |
| 163 | compat = &sdata->vif.bss_conf.chandef; |
| 164 | |
| 165 | compat = cfg80211_chandef_compatible( |
| 166 | &sdata->vif.bss_conf.chandef, compat); |
| 167 | if (!compat) |
| 168 | break; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 169 | } |
| 170 | rcu_read_unlock(); |
| 171 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 172 | if (WARN_ON_ONCE(!compat)) |
| 173 | return; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 174 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 175 | ieee80211_change_chandef(local, ctx, compat); |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 178 | static void ieee80211_unassign_vif_chanctx(struct ieee80211_sub_if_data *sdata, |
| 179 | struct ieee80211_chanctx *ctx) |
| 180 | { |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 181 | struct ieee80211_local *local = sdata->local; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 182 | |
| 183 | lockdep_assert_held(&local->chanctx_mtx); |
| 184 | |
| 185 | ctx->refcount--; |
| 186 | rcu_assign_pointer(sdata->vif.chanctx_conf, NULL); |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 187 | |
Johannes Berg | fd0f979 | 2013-02-07 00:14:51 +0100 | [diff] [blame] | 188 | sdata->vif.bss_conf.idle = true; |
| 189 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE); |
| 190 | |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 191 | drv_unassign_vif_chanctx(local, sdata, ctx); |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 192 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 193 | if (ctx->refcount > 0) { |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 194 | ieee80211_recalc_chanctx_chantype(sdata->local, ctx); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 195 | ieee80211_recalc_smps_chanctx(local, ctx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame^] | 196 | ieee80211_recalc_radar_chanctx(local, ctx); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 197 | } |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) |
| 201 | { |
| 202 | struct ieee80211_local *local = sdata->local; |
| 203 | struct ieee80211_chanctx_conf *conf; |
| 204 | struct ieee80211_chanctx *ctx; |
| 205 | |
| 206 | lockdep_assert_held(&local->chanctx_mtx); |
| 207 | |
| 208 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 209 | lockdep_is_held(&local->chanctx_mtx)); |
| 210 | if (!conf) |
| 211 | return; |
| 212 | |
| 213 | ctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 214 | |
| 215 | ieee80211_unassign_vif_chanctx(sdata, ctx); |
| 216 | if (ctx->refcount == 0) |
| 217 | ieee80211_free_chanctx(local, ctx); |
| 218 | } |
| 219 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame^] | 220 | void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local, |
| 221 | struct ieee80211_chanctx *chanctx) |
| 222 | { |
| 223 | struct ieee80211_sub_if_data *sdata; |
| 224 | bool radar_enabled = false; |
| 225 | |
| 226 | lockdep_assert_held(&local->chanctx_mtx); |
| 227 | |
| 228 | rcu_read_lock(); |
| 229 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 230 | if (sdata->radar_required) { |
| 231 | radar_enabled = true; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | rcu_read_unlock(); |
| 236 | |
| 237 | if (radar_enabled == chanctx->conf.radar_enabled) |
| 238 | return; |
| 239 | |
| 240 | chanctx->conf.radar_enabled = radar_enabled; |
| 241 | local->radar_detect_enabled = chanctx->conf.radar_enabled; |
| 242 | |
| 243 | if (!local->use_chanctx) { |
| 244 | local->hw.conf.radar_enabled = chanctx->conf.radar_enabled; |
| 245 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
| 246 | } |
| 247 | |
| 248 | drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RADAR); |
| 249 | } |
| 250 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 251 | void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local, |
| 252 | struct ieee80211_chanctx *chanctx) |
| 253 | { |
| 254 | struct ieee80211_sub_if_data *sdata; |
| 255 | u8 rx_chains_static, rx_chains_dynamic; |
| 256 | |
| 257 | lockdep_assert_held(&local->chanctx_mtx); |
| 258 | |
| 259 | rx_chains_static = 1; |
| 260 | rx_chains_dynamic = 1; |
| 261 | |
| 262 | rcu_read_lock(); |
| 263 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 264 | u8 needed_static, needed_dynamic; |
| 265 | |
| 266 | if (!ieee80211_sdata_running(sdata)) |
| 267 | continue; |
| 268 | |
| 269 | if (rcu_access_pointer(sdata->vif.chanctx_conf) != |
| 270 | &chanctx->conf) |
| 271 | continue; |
| 272 | |
| 273 | switch (sdata->vif.type) { |
| 274 | case NL80211_IFTYPE_P2P_DEVICE: |
| 275 | continue; |
| 276 | case NL80211_IFTYPE_STATION: |
| 277 | if (!sdata->u.mgd.associated) |
| 278 | continue; |
| 279 | break; |
| 280 | case NL80211_IFTYPE_AP_VLAN: |
| 281 | continue; |
| 282 | case NL80211_IFTYPE_AP: |
| 283 | case NL80211_IFTYPE_ADHOC: |
| 284 | case NL80211_IFTYPE_WDS: |
| 285 | case NL80211_IFTYPE_MESH_POINT: |
| 286 | break; |
| 287 | default: |
| 288 | WARN_ON_ONCE(1); |
| 289 | } |
| 290 | |
| 291 | switch (sdata->smps_mode) { |
| 292 | default: |
| 293 | WARN_ONCE(1, "Invalid SMPS mode %d\n", |
| 294 | sdata->smps_mode); |
| 295 | /* fall through */ |
| 296 | case IEEE80211_SMPS_OFF: |
| 297 | needed_static = sdata->needed_rx_chains; |
| 298 | needed_dynamic = sdata->needed_rx_chains; |
| 299 | break; |
| 300 | case IEEE80211_SMPS_DYNAMIC: |
| 301 | needed_static = 1; |
| 302 | needed_dynamic = sdata->needed_rx_chains; |
| 303 | break; |
| 304 | case IEEE80211_SMPS_STATIC: |
| 305 | needed_static = 1; |
| 306 | needed_dynamic = 1; |
| 307 | break; |
| 308 | } |
| 309 | |
| 310 | rx_chains_static = max(rx_chains_static, needed_static); |
| 311 | rx_chains_dynamic = max(rx_chains_dynamic, needed_dynamic); |
| 312 | } |
| 313 | rcu_read_unlock(); |
| 314 | |
| 315 | if (!local->use_chanctx) { |
| 316 | if (rx_chains_static > 1) |
| 317 | local->smps_mode = IEEE80211_SMPS_OFF; |
| 318 | else if (rx_chains_dynamic > 1) |
| 319 | local->smps_mode = IEEE80211_SMPS_DYNAMIC; |
| 320 | else |
| 321 | local->smps_mode = IEEE80211_SMPS_STATIC; |
| 322 | ieee80211_hw_config(local, 0); |
| 323 | } |
| 324 | |
| 325 | if (rx_chains_static == chanctx->conf.rx_chains_static && |
| 326 | rx_chains_dynamic == chanctx->conf.rx_chains_dynamic) |
| 327 | return; |
| 328 | |
| 329 | chanctx->conf.rx_chains_static = rx_chains_static; |
| 330 | chanctx->conf.rx_chains_dynamic = rx_chains_dynamic; |
| 331 | drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RX_CHAINS); |
| 332 | } |
| 333 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 334 | int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 335 | const struct cfg80211_chan_def *chandef, |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 336 | enum ieee80211_chanctx_mode mode) |
| 337 | { |
| 338 | struct ieee80211_local *local = sdata->local; |
| 339 | struct ieee80211_chanctx *ctx; |
| 340 | int ret; |
| 341 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 342 | WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev)); |
| 343 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 344 | mutex_lock(&local->chanctx_mtx); |
| 345 | __ieee80211_vif_release_channel(sdata); |
| 346 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 347 | ctx = ieee80211_find_chanctx(local, chandef, mode); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 348 | if (!ctx) |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 349 | ctx = ieee80211_new_chanctx(local, chandef, mode); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 350 | if (IS_ERR(ctx)) { |
| 351 | ret = PTR_ERR(ctx); |
| 352 | goto out; |
| 353 | } |
| 354 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 355 | sdata->vif.bss_conf.chandef = *chandef; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 356 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 357 | ret = ieee80211_assign_vif_chanctx(sdata, ctx); |
| 358 | if (ret) { |
| 359 | /* if assign fails refcount stays the same */ |
| 360 | if (ctx->refcount == 0) |
| 361 | ieee80211_free_chanctx(local, ctx); |
| 362 | goto out; |
| 363 | } |
| 364 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 365 | ieee80211_recalc_smps_chanctx(local, ctx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame^] | 366 | ieee80211_recalc_radar_chanctx(local, ctx); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 367 | out: |
| 368 | mutex_unlock(&local->chanctx_mtx); |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) |
| 373 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 374 | WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev)); |
| 375 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 376 | mutex_lock(&sdata->local->chanctx_mtx); |
| 377 | __ieee80211_vif_release_channel(sdata); |
| 378 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 379 | } |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 380 | |
Johannes Berg | 4d76d21 | 2012-12-11 20:38:41 +0100 | [diff] [blame] | 381 | void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata) |
| 382 | { |
| 383 | struct ieee80211_local *local = sdata->local; |
| 384 | struct ieee80211_sub_if_data *ap; |
| 385 | struct ieee80211_chanctx_conf *conf; |
| 386 | |
| 387 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->bss)) |
| 388 | return; |
| 389 | |
| 390 | ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); |
| 391 | |
| 392 | mutex_lock(&local->chanctx_mtx); |
| 393 | |
| 394 | conf = rcu_dereference_protected(ap->vif.chanctx_conf, |
| 395 | lockdep_is_held(&local->chanctx_mtx)); |
| 396 | rcu_assign_pointer(sdata->vif.chanctx_conf, conf); |
| 397 | mutex_unlock(&local->chanctx_mtx); |
| 398 | } |
| 399 | |
Johannes Berg | 1f4ac5a | 2013-02-08 12:07:44 +0100 | [diff] [blame] | 400 | void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, |
| 401 | bool clear) |
| 402 | { |
| 403 | struct ieee80211_local *local = sdata->local; |
| 404 | struct ieee80211_sub_if_data *vlan; |
| 405 | struct ieee80211_chanctx_conf *conf; |
| 406 | |
| 407 | ASSERT_RTNL(); |
| 408 | |
| 409 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP)) |
| 410 | return; |
| 411 | |
| 412 | mutex_lock(&local->chanctx_mtx); |
| 413 | |
| 414 | /* |
| 415 | * Check that conf exists, even when clearing this function |
| 416 | * must be called with the AP's channel context still there |
| 417 | * as it would otherwise cause VLANs to have an invalid |
| 418 | * channel context pointer for a while, possibly pointing |
| 419 | * to a channel context that has already been freed. |
| 420 | */ |
| 421 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 422 | lockdep_is_held(&local->chanctx_mtx)); |
| 423 | WARN_ON(!conf); |
| 424 | |
| 425 | if (clear) |
| 426 | conf = NULL; |
| 427 | |
| 428 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 429 | rcu_assign_pointer(vlan->vif.chanctx_conf, conf); |
| 430 | |
| 431 | mutex_unlock(&local->chanctx_mtx); |
| 432 | } |
| 433 | |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 434 | void ieee80211_iter_chan_contexts_atomic( |
| 435 | struct ieee80211_hw *hw, |
| 436 | void (*iter)(struct ieee80211_hw *hw, |
| 437 | struct ieee80211_chanctx_conf *chanctx_conf, |
| 438 | void *data), |
| 439 | void *iter_data) |
| 440 | { |
| 441 | struct ieee80211_local *local = hw_to_local(hw); |
| 442 | struct ieee80211_chanctx *ctx; |
| 443 | |
| 444 | rcu_read_lock(); |
| 445 | list_for_each_entry_rcu(ctx, &local->chanctx_list, list) |
Johannes Berg | 8a61af6 | 2012-12-13 17:42:30 +0100 | [diff] [blame] | 446 | if (ctx->driver_present) |
| 447 | iter(hw, &ctx->conf, iter_data); |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 448 | rcu_read_unlock(); |
| 449 | } |
| 450 | EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic); |