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 | |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 12 | static int ieee80211_chanctx_num_assigned(struct ieee80211_local *local, |
| 13 | struct ieee80211_chanctx *ctx) |
| 14 | { |
| 15 | struct ieee80211_sub_if_data *sdata; |
| 16 | int num = 0; |
| 17 | |
| 18 | lockdep_assert_held(&local->chanctx_mtx); |
| 19 | |
| 20 | list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list) |
| 21 | num++; |
| 22 | |
| 23 | return num; |
| 24 | } |
| 25 | |
| 26 | static int ieee80211_chanctx_num_reserved(struct ieee80211_local *local, |
| 27 | struct ieee80211_chanctx *ctx) |
| 28 | { |
| 29 | struct ieee80211_sub_if_data *sdata; |
| 30 | int num = 0; |
| 31 | |
| 32 | lockdep_assert_held(&local->chanctx_mtx); |
| 33 | |
| 34 | list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list) |
| 35 | num++; |
| 36 | |
| 37 | return num; |
| 38 | } |
| 39 | |
| 40 | int ieee80211_chanctx_refcount(struct ieee80211_local *local, |
| 41 | struct ieee80211_chanctx *ctx) |
| 42 | { |
| 43 | return ieee80211_chanctx_num_assigned(local, ctx) + |
| 44 | ieee80211_chanctx_num_reserved(local, ctx); |
| 45 | } |
| 46 | |
Michal Kazior | c2b90ad | 2014-04-09 15:29:24 +0200 | [diff] [blame] | 47 | static int ieee80211_num_chanctx(struct ieee80211_local *local) |
| 48 | { |
| 49 | struct ieee80211_chanctx *ctx; |
| 50 | int num = 0; |
| 51 | |
| 52 | lockdep_assert_held(&local->chanctx_mtx); |
| 53 | |
| 54 | list_for_each_entry(ctx, &local->chanctx_list, list) |
| 55 | num++; |
| 56 | |
| 57 | return num; |
| 58 | } |
| 59 | |
| 60 | static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local) |
| 61 | { |
| 62 | lockdep_assert_held(&local->chanctx_mtx); |
| 63 | return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local); |
| 64 | } |
| 65 | |
Michal Kazior | 0288157 | 2014-04-09 15:29:28 +0200 | [diff] [blame] | 66 | static const struct cfg80211_chan_def * |
| 67 | ieee80211_chanctx_reserved_chandef(struct ieee80211_local *local, |
| 68 | struct ieee80211_chanctx *ctx, |
| 69 | const struct cfg80211_chan_def *compat) |
| 70 | { |
| 71 | struct ieee80211_sub_if_data *sdata; |
| 72 | |
| 73 | lockdep_assert_held(&local->chanctx_mtx); |
| 74 | |
| 75 | list_for_each_entry(sdata, &ctx->reserved_vifs, |
| 76 | reserved_chanctx_list) { |
| 77 | if (!compat) |
| 78 | compat = &sdata->reserved_chandef; |
| 79 | |
| 80 | compat = cfg80211_chandef_compatible(&sdata->reserved_chandef, |
| 81 | compat); |
| 82 | if (!compat) |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | return compat; |
| 87 | } |
| 88 | |
Michal Kazior | 13f348a | 2014-04-09 15:29:29 +0200 | [diff] [blame] | 89 | static const struct cfg80211_chan_def * |
| 90 | ieee80211_chanctx_non_reserved_chandef(struct ieee80211_local *local, |
| 91 | struct ieee80211_chanctx *ctx, |
| 92 | const struct cfg80211_chan_def *compat) |
| 93 | { |
| 94 | struct ieee80211_sub_if_data *sdata; |
| 95 | |
| 96 | lockdep_assert_held(&local->chanctx_mtx); |
| 97 | |
| 98 | list_for_each_entry(sdata, &ctx->assigned_vifs, |
| 99 | assigned_chanctx_list) { |
| 100 | if (sdata->reserved_chanctx != NULL) |
| 101 | continue; |
| 102 | |
| 103 | if (!compat) |
| 104 | compat = &sdata->vif.bss_conf.chandef; |
| 105 | |
| 106 | compat = cfg80211_chandef_compatible( |
| 107 | &sdata->vif.bss_conf.chandef, compat); |
| 108 | if (!compat) |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | return compat; |
| 113 | } |
| 114 | |
| 115 | static const struct cfg80211_chan_def * |
| 116 | ieee80211_chanctx_combined_chandef(struct ieee80211_local *local, |
| 117 | struct ieee80211_chanctx *ctx, |
| 118 | const struct cfg80211_chan_def *compat) |
| 119 | { |
| 120 | lockdep_assert_held(&local->chanctx_mtx); |
| 121 | |
| 122 | compat = ieee80211_chanctx_reserved_chandef(local, ctx, compat); |
| 123 | if (!compat) |
| 124 | return NULL; |
| 125 | |
| 126 | compat = ieee80211_chanctx_non_reserved_chandef(local, ctx, compat); |
| 127 | if (!compat) |
| 128 | return NULL; |
| 129 | |
| 130 | return compat; |
| 131 | } |
| 132 | |
| 133 | static bool |
| 134 | ieee80211_chanctx_can_reserve_chandef(struct ieee80211_local *local, |
| 135 | struct ieee80211_chanctx *ctx, |
| 136 | const struct cfg80211_chan_def *def) |
| 137 | { |
| 138 | lockdep_assert_held(&local->chanctx_mtx); |
| 139 | |
| 140 | if (ieee80211_chanctx_combined_chandef(local, ctx, def)) |
| 141 | return true; |
| 142 | |
| 143 | if (!list_empty(&ctx->reserved_vifs) && |
| 144 | ieee80211_chanctx_reserved_chandef(local, ctx, def)) |
| 145 | return true; |
| 146 | |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | static struct ieee80211_chanctx * |
| 151 | ieee80211_find_reservation_chanctx(struct ieee80211_local *local, |
| 152 | const struct cfg80211_chan_def *chandef, |
| 153 | enum ieee80211_chanctx_mode mode) |
| 154 | { |
| 155 | struct ieee80211_chanctx *ctx; |
| 156 | |
| 157 | lockdep_assert_held(&local->chanctx_mtx); |
| 158 | |
| 159 | if (mode == IEEE80211_CHANCTX_EXCLUSIVE) |
| 160 | return NULL; |
| 161 | |
| 162 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
| 163 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) |
| 164 | continue; |
| 165 | |
| 166 | if (!ieee80211_chanctx_can_reserve_chandef(local, ctx, |
| 167 | chandef)) |
| 168 | continue; |
| 169 | |
| 170 | return ctx; |
| 171 | } |
| 172 | |
| 173 | return NULL; |
| 174 | } |
| 175 | |
Eliad Peller | 21f659b | 2013-11-11 20:14:01 +0200 | [diff] [blame] | 176 | static enum nl80211_chan_width ieee80211_get_sta_bw(struct ieee80211_sta *sta) |
| 177 | { |
| 178 | switch (sta->bandwidth) { |
| 179 | case IEEE80211_STA_RX_BW_20: |
| 180 | if (sta->ht_cap.ht_supported) |
| 181 | return NL80211_CHAN_WIDTH_20; |
| 182 | else |
| 183 | return NL80211_CHAN_WIDTH_20_NOHT; |
| 184 | case IEEE80211_STA_RX_BW_40: |
| 185 | return NL80211_CHAN_WIDTH_40; |
| 186 | case IEEE80211_STA_RX_BW_80: |
| 187 | return NL80211_CHAN_WIDTH_80; |
| 188 | case IEEE80211_STA_RX_BW_160: |
| 189 | /* |
| 190 | * This applied for both 160 and 80+80. since we use |
| 191 | * the returned value to consider degradation of |
| 192 | * ctx->conf.min_def, we have to make sure to take |
| 193 | * the bigger one (NL80211_CHAN_WIDTH_160). |
| 194 | * Otherwise we might try degrading even when not |
| 195 | * needed, as the max required sta_bw returned (80+80) |
| 196 | * might be smaller than the configured bw (160). |
| 197 | */ |
| 198 | return NL80211_CHAN_WIDTH_160; |
| 199 | default: |
| 200 | WARN_ON(1); |
| 201 | return NL80211_CHAN_WIDTH_20; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | static enum nl80211_chan_width |
| 206 | ieee80211_get_max_required_bw(struct ieee80211_sub_if_data *sdata) |
| 207 | { |
| 208 | enum nl80211_chan_width max_bw = NL80211_CHAN_WIDTH_20_NOHT; |
| 209 | struct sta_info *sta; |
| 210 | |
| 211 | rcu_read_lock(); |
| 212 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { |
| 213 | if (sdata != sta->sdata && |
| 214 | !(sta->sdata->bss && sta->sdata->bss == sdata->bss)) |
| 215 | continue; |
| 216 | |
| 217 | if (!sta->uploaded) |
| 218 | continue; |
| 219 | |
| 220 | max_bw = max(max_bw, ieee80211_get_sta_bw(&sta->sta)); |
| 221 | } |
| 222 | rcu_read_unlock(); |
| 223 | |
| 224 | return max_bw; |
| 225 | } |
| 226 | |
| 227 | static enum nl80211_chan_width |
| 228 | ieee80211_get_chanctx_max_required_bw(struct ieee80211_local *local, |
| 229 | struct ieee80211_chanctx_conf *conf) |
| 230 | { |
| 231 | struct ieee80211_sub_if_data *sdata; |
| 232 | enum nl80211_chan_width max_bw = NL80211_CHAN_WIDTH_20_NOHT; |
| 233 | |
| 234 | rcu_read_lock(); |
| 235 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 236 | struct ieee80211_vif *vif = &sdata->vif; |
| 237 | enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20_NOHT; |
| 238 | |
| 239 | if (!ieee80211_sdata_running(sdata)) |
| 240 | continue; |
| 241 | |
| 242 | if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf) |
| 243 | continue; |
| 244 | |
| 245 | switch (vif->type) { |
| 246 | case NL80211_IFTYPE_AP: |
| 247 | case NL80211_IFTYPE_AP_VLAN: |
| 248 | width = ieee80211_get_max_required_bw(sdata); |
| 249 | break; |
| 250 | case NL80211_IFTYPE_P2P_DEVICE: |
| 251 | continue; |
| 252 | case NL80211_IFTYPE_STATION: |
| 253 | case NL80211_IFTYPE_ADHOC: |
| 254 | case NL80211_IFTYPE_WDS: |
| 255 | case NL80211_IFTYPE_MESH_POINT: |
| 256 | width = vif->bss_conf.chandef.width; |
| 257 | break; |
| 258 | case NL80211_IFTYPE_UNSPECIFIED: |
| 259 | case NUM_NL80211_IFTYPES: |
| 260 | case NL80211_IFTYPE_MONITOR: |
| 261 | case NL80211_IFTYPE_P2P_CLIENT: |
| 262 | case NL80211_IFTYPE_P2P_GO: |
| 263 | WARN_ON_ONCE(1); |
| 264 | } |
| 265 | max_bw = max(max_bw, width); |
| 266 | } |
Eliad Peller | 1c37a72 | 2014-03-03 13:37:14 +0200 | [diff] [blame] | 267 | |
| 268 | /* use the configured bandwidth in case of monitor interface */ |
| 269 | sdata = rcu_dereference(local->monitor_sdata); |
| 270 | if (sdata && rcu_access_pointer(sdata->vif.chanctx_conf) == conf) |
| 271 | max_bw = max(max_bw, conf->def.width); |
| 272 | |
Eliad Peller | 21f659b | 2013-11-11 20:14:01 +0200 | [diff] [blame] | 273 | rcu_read_unlock(); |
| 274 | |
| 275 | return max_bw; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * recalc the min required chan width of the channel context, which is |
| 280 | * the max of min required widths of all the interfaces bound to this |
| 281 | * channel context. |
| 282 | */ |
| 283 | void ieee80211_recalc_chanctx_min_def(struct ieee80211_local *local, |
| 284 | struct ieee80211_chanctx *ctx) |
| 285 | { |
| 286 | enum nl80211_chan_width max_bw; |
| 287 | struct cfg80211_chan_def min_def; |
| 288 | |
| 289 | lockdep_assert_held(&local->chanctx_mtx); |
| 290 | |
| 291 | /* don't optimize 5MHz, 10MHz, and radar_enabled confs */ |
| 292 | if (ctx->conf.def.width == NL80211_CHAN_WIDTH_5 || |
| 293 | ctx->conf.def.width == NL80211_CHAN_WIDTH_10 || |
| 294 | ctx->conf.radar_enabled) { |
| 295 | ctx->conf.min_def = ctx->conf.def; |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | max_bw = ieee80211_get_chanctx_max_required_bw(local, &ctx->conf); |
| 300 | |
| 301 | /* downgrade chandef up to max_bw */ |
| 302 | min_def = ctx->conf.def; |
| 303 | while (min_def.width > max_bw) |
| 304 | ieee80211_chandef_downgrade(&min_def); |
| 305 | |
| 306 | if (cfg80211_chandef_identical(&ctx->conf.min_def, &min_def)) |
| 307 | return; |
| 308 | |
| 309 | ctx->conf.min_def = min_def; |
| 310 | if (!ctx->driver_present) |
| 311 | return; |
| 312 | |
| 313 | drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_MIN_WIDTH); |
| 314 | } |
| 315 | |
Johannes Berg | 18942d3 | 2013-02-07 21:30:37 +0100 | [diff] [blame] | 316 | static void ieee80211_change_chanctx(struct ieee80211_local *local, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 317 | struct ieee80211_chanctx *ctx, |
| 318 | const struct cfg80211_chan_def *chandef) |
Michal Kazior | 23a85b45 | 2012-06-26 14:37:21 +0200 | [diff] [blame] | 319 | { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 320 | if (cfg80211_chandef_identical(&ctx->conf.def, chandef)) |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 321 | return; |
| 322 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 323 | WARN_ON(!cfg80211_chandef_compatible(&ctx->conf.def, chandef)); |
| 324 | |
| 325 | ctx->conf.def = *chandef; |
| 326 | drv_change_chanctx(local, ctx, IEEE80211_CHANCTX_CHANGE_WIDTH); |
Eliad Peller | 21f659b | 2013-11-11 20:14:01 +0200 | [diff] [blame] | 327 | ieee80211_recalc_chanctx_min_def(local, ctx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 328 | |
| 329 | if (!local->use_chanctx) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 330 | local->_oper_chandef = *chandef; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 331 | ieee80211_hw_config(local, 0); |
| 332 | } |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 333 | } |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 334 | |
| 335 | static struct ieee80211_chanctx * |
| 336 | ieee80211_find_chanctx(struct ieee80211_local *local, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 337 | const struct cfg80211_chan_def *chandef, |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 338 | enum ieee80211_chanctx_mode mode) |
| 339 | { |
| 340 | struct ieee80211_chanctx *ctx; |
| 341 | |
| 342 | lockdep_assert_held(&local->chanctx_mtx); |
| 343 | |
| 344 | if (mode == IEEE80211_CHANCTX_EXCLUSIVE) |
| 345 | return NULL; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 346 | |
| 347 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 348 | const struct cfg80211_chan_def *compat; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 349 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 350 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) |
| 351 | continue; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 352 | |
| 353 | compat = cfg80211_chandef_compatible(&ctx->conf.def, chandef); |
| 354 | if (!compat) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 355 | continue; |
| 356 | |
Michal Kazior | 0288157 | 2014-04-09 15:29:28 +0200 | [diff] [blame] | 357 | compat = ieee80211_chanctx_reserved_chandef(local, ctx, |
| 358 | compat); |
| 359 | if (!compat) |
| 360 | continue; |
| 361 | |
Johannes Berg | 18942d3 | 2013-02-07 21:30:37 +0100 | [diff] [blame] | 362 | ieee80211_change_chanctx(local, ctx, compat); |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 363 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 364 | return ctx; |
| 365 | } |
| 366 | |
| 367 | return NULL; |
| 368 | } |
| 369 | |
Simon Wunderlich | e474685 | 2013-04-08 22:43:16 +0200 | [diff] [blame] | 370 | static bool ieee80211_is_radar_required(struct ieee80211_local *local) |
| 371 | { |
| 372 | struct ieee80211_sub_if_data *sdata; |
| 373 | |
Michal Kazior | cc901de | 2014-01-29 07:56:20 +0100 | [diff] [blame] | 374 | lockdep_assert_held(&local->mtx); |
| 375 | |
Simon Wunderlich | e474685 | 2013-04-08 22:43:16 +0200 | [diff] [blame] | 376 | rcu_read_lock(); |
| 377 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 378 | if (sdata->radar_required) { |
| 379 | rcu_read_unlock(); |
| 380 | return true; |
| 381 | } |
| 382 | } |
| 383 | rcu_read_unlock(); |
| 384 | |
| 385 | return false; |
| 386 | } |
| 387 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 388 | static struct ieee80211_chanctx * |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 389 | ieee80211_alloc_chanctx(struct ieee80211_local *local, |
| 390 | const struct cfg80211_chan_def *chandef, |
| 391 | enum ieee80211_chanctx_mode mode) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 392 | { |
| 393 | struct ieee80211_chanctx *ctx; |
| 394 | |
| 395 | lockdep_assert_held(&local->chanctx_mtx); |
| 396 | |
| 397 | ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL); |
| 398 | if (!ctx) |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 399 | return NULL; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 400 | |
Michal Kazior | 484298a | 2014-04-09 15:29:26 +0200 | [diff] [blame] | 401 | INIT_LIST_HEAD(&ctx->assigned_vifs); |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 402 | INIT_LIST_HEAD(&ctx->reserved_vifs); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 403 | ctx->conf.def = *chandef; |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 404 | ctx->conf.rx_chains_static = 1; |
| 405 | ctx->conf.rx_chains_dynamic = 1; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 406 | ctx->mode = mode; |
Simon Wunderlich | e474685 | 2013-04-08 22:43:16 +0200 | [diff] [blame] | 407 | ctx->conf.radar_enabled = ieee80211_is_radar_required(local); |
Eliad Peller | 21f659b | 2013-11-11 20:14:01 +0200 | [diff] [blame] | 408 | ieee80211_recalc_chanctx_min_def(local, ctx); |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 409 | |
| 410 | return ctx; |
| 411 | } |
| 412 | |
| 413 | static int ieee80211_add_chanctx(struct ieee80211_local *local, |
| 414 | struct ieee80211_chanctx *ctx) |
| 415 | { |
| 416 | u32 changed; |
| 417 | int err; |
| 418 | |
| 419 | lockdep_assert_held(&local->mtx); |
| 420 | lockdep_assert_held(&local->chanctx_mtx); |
| 421 | |
Simon Wunderlich | e474685 | 2013-04-08 22:43:16 +0200 | [diff] [blame] | 422 | if (!local->use_chanctx) |
| 423 | local->hw.conf.radar_enabled = ctx->conf.radar_enabled; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 424 | |
Johannes Berg | 382a103 | 2013-03-22 22:30:09 +0100 | [diff] [blame] | 425 | /* turn idle off *before* setting channel -- some drivers need that */ |
| 426 | changed = ieee80211_idle_off(local); |
| 427 | if (changed) |
| 428 | ieee80211_hw_config(local, changed); |
| 429 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 430 | if (!local->use_chanctx) { |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 431 | local->_oper_chandef = ctx->conf.def; |
Michal Kazior | 9b4816f | 2014-04-04 13:02:43 +0200 | [diff] [blame] | 432 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 433 | } else { |
| 434 | err = drv_add_chanctx(local, ctx); |
| 435 | if (err) { |
Johannes Berg | 382a103 | 2013-03-22 22:30:09 +0100 | [diff] [blame] | 436 | ieee80211_recalc_idle(local); |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 437 | return err; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 438 | } |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 441 | return 0; |
| 442 | } |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 443 | |
Michal Kazior | ed68ebc | 2014-04-09 15:29:30 +0200 | [diff] [blame] | 444 | static struct ieee80211_chanctx * |
| 445 | ieee80211_new_chanctx(struct ieee80211_local *local, |
| 446 | const struct cfg80211_chan_def *chandef, |
| 447 | enum ieee80211_chanctx_mode mode) |
| 448 | { |
| 449 | struct ieee80211_chanctx *ctx; |
| 450 | int err; |
| 451 | |
| 452 | lockdep_assert_held(&local->mtx); |
| 453 | lockdep_assert_held(&local->chanctx_mtx); |
| 454 | |
| 455 | ctx = ieee80211_alloc_chanctx(local, chandef, mode); |
| 456 | if (!ctx) |
| 457 | return ERR_PTR(-ENOMEM); |
| 458 | |
| 459 | err = ieee80211_add_chanctx(local, ctx); |
| 460 | if (err) { |
| 461 | kfree(ctx); |
| 462 | return ERR_PTR(err); |
| 463 | } |
| 464 | |
| 465 | list_add_rcu(&ctx->list, &local->chanctx_list); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 466 | return ctx; |
| 467 | } |
| 468 | |
Michal Kazior | 1f0d54c | 2014-04-09 15:29:31 +0200 | [diff] [blame] | 469 | static void ieee80211_del_chanctx(struct ieee80211_local *local, |
| 470 | struct ieee80211_chanctx *ctx) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 471 | { |
| 472 | lockdep_assert_held(&local->chanctx_mtx); |
| 473 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 474 | if (!local->use_chanctx) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 475 | struct cfg80211_chan_def *chandef = &local->_oper_chandef; |
| 476 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 477 | chandef->center_freq1 = chandef->chan->center_freq; |
| 478 | chandef->center_freq2 = 0; |
Simon Wunderlich | e474685 | 2013-04-08 22:43:16 +0200 | [diff] [blame] | 479 | |
| 480 | /* NOTE: Disabling radar is only valid here for |
| 481 | * single channel context. To be sure, check it ... |
| 482 | */ |
Michal Kazior | 1f0d54c | 2014-04-09 15:29:31 +0200 | [diff] [blame] | 483 | WARN_ON(local->hw.conf.radar_enabled && |
| 484 | !list_empty(&local->chanctx_list)); |
| 485 | |
Simon Wunderlich | e474685 | 2013-04-08 22:43:16 +0200 | [diff] [blame] | 486 | local->hw.conf.radar_enabled = false; |
| 487 | |
Michal Kazior | 9b4816f | 2014-04-04 13:02:43 +0200 | [diff] [blame] | 488 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 489 | } else { |
| 490 | drv_remove_chanctx(local, ctx); |
| 491 | } |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 492 | |
Johannes Berg | fd0f979 | 2013-02-07 00:14:51 +0100 | [diff] [blame] | 493 | ieee80211_recalc_idle(local); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 494 | } |
| 495 | |
Michal Kazior | 1f0d54c | 2014-04-09 15:29:31 +0200 | [diff] [blame] | 496 | static void ieee80211_free_chanctx(struct ieee80211_local *local, |
| 497 | struct ieee80211_chanctx *ctx) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 498 | { |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 499 | lockdep_assert_held(&local->chanctx_mtx); |
| 500 | |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 501 | WARN_ON_ONCE(ieee80211_chanctx_refcount(local, ctx) != 0); |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 502 | |
Michal Kazior | 1f0d54c | 2014-04-09 15:29:31 +0200 | [diff] [blame] | 503 | list_del_rcu(&ctx->list); |
| 504 | ieee80211_del_chanctx(local, ctx); |
| 505 | kfree_rcu(ctx, rcu_head); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 508 | static void ieee80211_recalc_chanctx_chantype(struct ieee80211_local *local, |
| 509 | struct ieee80211_chanctx *ctx) |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 510 | { |
| 511 | struct ieee80211_chanctx_conf *conf = &ctx->conf; |
| 512 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 513 | const struct cfg80211_chan_def *compat = NULL; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 514 | |
| 515 | lockdep_assert_held(&local->chanctx_mtx); |
| 516 | |
| 517 | rcu_read_lock(); |
| 518 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 519 | |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 520 | if (!ieee80211_sdata_running(sdata)) |
| 521 | continue; |
| 522 | if (rcu_access_pointer(sdata->vif.chanctx_conf) != conf) |
| 523 | continue; |
| 524 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 525 | if (!compat) |
| 526 | compat = &sdata->vif.bss_conf.chandef; |
| 527 | |
| 528 | compat = cfg80211_chandef_compatible( |
| 529 | &sdata->vif.bss_conf.chandef, compat); |
| 530 | if (!compat) |
| 531 | break; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 532 | } |
| 533 | rcu_read_unlock(); |
| 534 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 535 | if (WARN_ON_ONCE(!compat)) |
| 536 | return; |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 537 | |
Johannes Berg | 18942d3 | 2013-02-07 21:30:37 +0100 | [diff] [blame] | 538 | ieee80211_change_chanctx(local, ctx, compat); |
Michal Kazior | e89a96f | 2012-06-26 14:37:22 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Johannes Berg | 367bbd1 | 2013-12-18 09:36:09 +0100 | [diff] [blame] | 541 | static void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local, |
| 542 | struct ieee80211_chanctx *chanctx) |
| 543 | { |
| 544 | bool radar_enabled; |
| 545 | |
| 546 | lockdep_assert_held(&local->chanctx_mtx); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 547 | /* for setting local->radar_detect_enabled */ |
| 548 | lockdep_assert_held(&local->mtx); |
Johannes Berg | 367bbd1 | 2013-12-18 09:36:09 +0100 | [diff] [blame] | 549 | |
| 550 | radar_enabled = ieee80211_is_radar_required(local); |
| 551 | |
| 552 | if (radar_enabled == chanctx->conf.radar_enabled) |
| 553 | return; |
| 554 | |
| 555 | chanctx->conf.radar_enabled = radar_enabled; |
| 556 | local->radar_detect_enabled = chanctx->conf.radar_enabled; |
| 557 | |
| 558 | if (!local->use_chanctx) { |
| 559 | local->hw.conf.radar_enabled = chanctx->conf.radar_enabled; |
| 560 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
| 561 | } |
| 562 | |
| 563 | drv_change_chanctx(local, chanctx, IEEE80211_CHANCTX_CHANGE_RADAR); |
| 564 | } |
| 565 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 566 | static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata, |
| 567 | struct ieee80211_chanctx *new_ctx) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 568 | { |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 569 | struct ieee80211_local *local = sdata->local; |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 570 | struct ieee80211_chanctx_conf *conf; |
| 571 | struct ieee80211_chanctx *curr_ctx = NULL; |
| 572 | int ret = 0; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 573 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 574 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 575 | lockdep_is_held(&local->chanctx_mtx)); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 576 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 577 | if (conf) { |
| 578 | curr_ctx = container_of(conf, struct ieee80211_chanctx, conf); |
Michal Kazior | 35f2fce | 2012-06-26 14:37:20 +0200 | [diff] [blame] | 579 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 580 | drv_unassign_vif_chanctx(local, sdata, curr_ctx); |
| 581 | conf = NULL; |
Michal Kazior | 484298a | 2014-04-09 15:29:26 +0200 | [diff] [blame] | 582 | list_del(&sdata->assigned_chanctx_list); |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | if (new_ctx) { |
| 586 | ret = drv_assign_vif_chanctx(local, sdata, new_ctx); |
| 587 | if (ret) |
| 588 | goto out; |
| 589 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 590 | conf = &new_ctx->conf; |
Michal Kazior | 484298a | 2014-04-09 15:29:26 +0200 | [diff] [blame] | 591 | list_add(&sdata->assigned_chanctx_list, |
| 592 | &new_ctx->assigned_vifs); |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | out: |
| 596 | rcu_assign_pointer(sdata->vif.chanctx_conf, conf); |
| 597 | |
| 598 | sdata->vif.bss_conf.idle = !conf; |
| 599 | |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 600 | if (curr_ctx && ieee80211_chanctx_num_assigned(local, curr_ctx) > 0) { |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 601 | ieee80211_recalc_chanctx_chantype(local, curr_ctx); |
| 602 | ieee80211_recalc_smps_chanctx(local, curr_ctx); |
| 603 | ieee80211_recalc_radar_chanctx(local, curr_ctx); |
| 604 | ieee80211_recalc_chanctx_min_def(local, curr_ctx); |
| 605 | } |
| 606 | |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 607 | if (new_ctx && ieee80211_chanctx_num_assigned(local, new_ctx) > 0) { |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 608 | ieee80211_recalc_txpower(sdata); |
| 609 | ieee80211_recalc_chanctx_min_def(local, new_ctx); |
| 610 | } |
Johannes Berg | 5bbe754d | 2013-02-13 13:50:51 +0100 | [diff] [blame] | 611 | |
| 612 | if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE && |
| 613 | sdata->vif.type != NL80211_IFTYPE_MONITOR) |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 614 | ieee80211_bss_info_change_notify(sdata, |
| 615 | BSS_CHANGED_IDLE); |
Johannes Berg | fd0f979 | 2013-02-07 00:14:51 +0100 | [diff] [blame] | 616 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 617 | return ret; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) |
| 621 | { |
| 622 | struct ieee80211_local *local = sdata->local; |
| 623 | struct ieee80211_chanctx_conf *conf; |
| 624 | struct ieee80211_chanctx *ctx; |
| 625 | |
| 626 | lockdep_assert_held(&local->chanctx_mtx); |
| 627 | |
| 628 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 629 | lockdep_is_held(&local->chanctx_mtx)); |
| 630 | if (!conf) |
| 631 | return; |
| 632 | |
| 633 | ctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 634 | |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 635 | if (sdata->reserved_chanctx) |
| 636 | ieee80211_vif_unreserve_chanctx(sdata); |
| 637 | |
Luciano Coelho | 77eeba9 | 2014-03-11 18:24:12 +0200 | [diff] [blame] | 638 | ieee80211_assign_vif_chanctx(sdata, NULL); |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 639 | if (ieee80211_chanctx_refcount(local, ctx) == 0) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 640 | ieee80211_free_chanctx(local, ctx); |
| 641 | } |
| 642 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 643 | void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local, |
| 644 | struct ieee80211_chanctx *chanctx) |
| 645 | { |
| 646 | struct ieee80211_sub_if_data *sdata; |
| 647 | u8 rx_chains_static, rx_chains_dynamic; |
| 648 | |
| 649 | lockdep_assert_held(&local->chanctx_mtx); |
| 650 | |
| 651 | rx_chains_static = 1; |
| 652 | rx_chains_dynamic = 1; |
| 653 | |
| 654 | rcu_read_lock(); |
| 655 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 656 | u8 needed_static, needed_dynamic; |
| 657 | |
| 658 | if (!ieee80211_sdata_running(sdata)) |
| 659 | continue; |
| 660 | |
| 661 | if (rcu_access_pointer(sdata->vif.chanctx_conf) != |
| 662 | &chanctx->conf) |
| 663 | continue; |
| 664 | |
| 665 | switch (sdata->vif.type) { |
| 666 | case NL80211_IFTYPE_P2P_DEVICE: |
| 667 | continue; |
| 668 | case NL80211_IFTYPE_STATION: |
| 669 | if (!sdata->u.mgd.associated) |
| 670 | continue; |
| 671 | break; |
| 672 | case NL80211_IFTYPE_AP_VLAN: |
| 673 | continue; |
| 674 | case NL80211_IFTYPE_AP: |
| 675 | case NL80211_IFTYPE_ADHOC: |
| 676 | case NL80211_IFTYPE_WDS: |
| 677 | case NL80211_IFTYPE_MESH_POINT: |
| 678 | break; |
| 679 | default: |
| 680 | WARN_ON_ONCE(1); |
| 681 | } |
| 682 | |
| 683 | switch (sdata->smps_mode) { |
| 684 | default: |
| 685 | WARN_ONCE(1, "Invalid SMPS mode %d\n", |
| 686 | sdata->smps_mode); |
| 687 | /* fall through */ |
| 688 | case IEEE80211_SMPS_OFF: |
| 689 | needed_static = sdata->needed_rx_chains; |
| 690 | needed_dynamic = sdata->needed_rx_chains; |
| 691 | break; |
| 692 | case IEEE80211_SMPS_DYNAMIC: |
| 693 | needed_static = 1; |
| 694 | needed_dynamic = sdata->needed_rx_chains; |
| 695 | break; |
| 696 | case IEEE80211_SMPS_STATIC: |
| 697 | needed_static = 1; |
| 698 | needed_dynamic = 1; |
| 699 | break; |
| 700 | } |
| 701 | |
| 702 | rx_chains_static = max(rx_chains_static, needed_static); |
| 703 | rx_chains_dynamic = max(rx_chains_dynamic, needed_dynamic); |
| 704 | } |
Ido Yariv | 7b8a9cd | 2014-03-24 09:55:45 +0200 | [diff] [blame] | 705 | |
| 706 | /* Disable SMPS for the monitor interface */ |
| 707 | sdata = rcu_dereference(local->monitor_sdata); |
| 708 | if (sdata && |
| 709 | rcu_access_pointer(sdata->vif.chanctx_conf) == &chanctx->conf) |
| 710 | rx_chains_dynamic = rx_chains_static = local->rx_chains; |
| 711 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 712 | rcu_read_unlock(); |
| 713 | |
| 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; |
| 719 | else |
| 720 | local->smps_mode = IEEE80211_SMPS_STATIC; |
| 721 | ieee80211_hw_config(local, 0); |
| 722 | } |
| 723 | |
| 724 | if (rx_chains_static == chanctx->conf.rx_chains_static && |
| 725 | rx_chains_dynamic == chanctx->conf.rx_chains_dynamic) |
| 726 | return; |
| 727 | |
| 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); |
| 731 | } |
| 732 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 733 | int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 734 | const struct cfg80211_chan_def *chandef, |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 735 | enum ieee80211_chanctx_mode mode) |
| 736 | { |
| 737 | struct ieee80211_local *local = sdata->local; |
| 738 | struct ieee80211_chanctx *ctx; |
Luciano Coelho | 73de86a | 2014-02-13 11:31:59 +0200 | [diff] [blame] | 739 | u8 radar_detect_width = 0; |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 740 | int ret; |
| 741 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 742 | lockdep_assert_held(&local->mtx); |
| 743 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 744 | WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev)); |
| 745 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 746 | mutex_lock(&local->chanctx_mtx); |
Luciano Coelho | 73de86a | 2014-02-13 11:31:59 +0200 | [diff] [blame] | 747 | |
| 748 | ret = cfg80211_chandef_dfs_required(local->hw.wiphy, |
| 749 | chandef, |
| 750 | sdata->wdev.iftype); |
| 751 | if (ret < 0) |
| 752 | goto out; |
| 753 | if (ret > 0) |
| 754 | radar_detect_width = BIT(chandef->width); |
| 755 | |
| 756 | sdata->radar_required = ret; |
| 757 | |
| 758 | ret = ieee80211_check_combinations(sdata, chandef, mode, |
| 759 | radar_detect_width); |
| 760 | if (ret < 0) |
| 761 | goto out; |
| 762 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 763 | __ieee80211_vif_release_channel(sdata); |
| 764 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 765 | ctx = ieee80211_find_chanctx(local, chandef, mode); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 766 | if (!ctx) |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 767 | ctx = ieee80211_new_chanctx(local, chandef, mode); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 768 | if (IS_ERR(ctx)) { |
| 769 | ret = PTR_ERR(ctx); |
| 770 | goto out; |
| 771 | } |
| 772 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 773 | sdata->vif.bss_conf.chandef = *chandef; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 774 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 775 | ret = ieee80211_assign_vif_chanctx(sdata, ctx); |
| 776 | if (ret) { |
| 777 | /* if assign fails refcount stays the same */ |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 778 | if (ieee80211_chanctx_refcount(local, ctx) == 0) |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 779 | ieee80211_free_chanctx(local, ctx); |
| 780 | goto out; |
| 781 | } |
| 782 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 783 | ieee80211_recalc_smps_chanctx(local, ctx); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 784 | ieee80211_recalc_radar_chanctx(local, ctx); |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 785 | out: |
| 786 | mutex_unlock(&local->chanctx_mtx); |
| 787 | return ret; |
| 788 | } |
| 789 | |
Luciano Coelho | 33ffd95 | 2014-01-30 22:08:16 +0200 | [diff] [blame] | 790 | static int __ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata, |
| 791 | struct ieee80211_chanctx *ctx, |
| 792 | u32 *changed) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 793 | { |
| 794 | struct ieee80211_local *local = sdata->local; |
Luciano Coelho | 33787fc | 2013-11-11 20:34:54 +0200 | [diff] [blame] | 795 | const struct cfg80211_chan_def *chandef = &sdata->csa_chandef; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 796 | u32 chanctx_changed = 0; |
| 797 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 798 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
| 799 | IEEE80211_CHAN_DISABLED)) |
| 800 | return -EINVAL; |
| 801 | |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 802 | if (ieee80211_chanctx_refcount(local, ctx) != 1) |
Luciano Coelho | 33ffd95 | 2014-01-30 22:08:16 +0200 | [diff] [blame] | 803 | return -EINVAL; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 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 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 816 | ieee80211_recalc_chanctx_chantype(local, ctx); |
| 817 | ieee80211_recalc_smps_chanctx(local, ctx); |
| 818 | ieee80211_recalc_radar_chanctx(local, ctx); |
Eliad Peller | 21f659b | 2013-11-11 20:14:01 +0200 | [diff] [blame] | 819 | ieee80211_recalc_chanctx_min_def(local, ctx); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 820 | |
Luciano Coelho | 33ffd95 | 2014-01-30 22:08:16 +0200 | [diff] [blame] | 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); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 849 | out: |
| 850 | mutex_unlock(&local->chanctx_mtx); |
| 851 | return ret; |
| 852 | } |
| 853 | |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 854 | static void |
| 855 | __ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, |
| 856 | bool clear) |
| 857 | { |
Johannes Berg | 33926eb | 2014-04-09 21:31:13 +0200 | [diff] [blame] | 858 | struct ieee80211_local *local __maybe_unused = sdata->local; |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 859 | struct ieee80211_sub_if_data *vlan; |
| 860 | struct ieee80211_chanctx_conf *conf; |
| 861 | |
| 862 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP)) |
| 863 | return; |
| 864 | |
| 865 | lockdep_assert_held(&local->mtx); |
| 866 | |
| 867 | /* Check that conf exists, even when clearing this function |
| 868 | * must be called with the AP's channel context still there |
| 869 | * as it would otherwise cause VLANs to have an invalid |
| 870 | * channel context pointer for a while, possibly pointing |
| 871 | * to a channel context that has already been freed. |
| 872 | */ |
| 873 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
Johannes Berg | 33926eb | 2014-04-09 21:31:13 +0200 | [diff] [blame] | 874 | lockdep_is_held(&local->chanctx_mtx)); |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 875 | WARN_ON(!conf); |
| 876 | |
| 877 | if (clear) |
| 878 | conf = NULL; |
| 879 | |
| 880 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 881 | rcu_assign_pointer(vlan->vif.chanctx_conf, conf); |
| 882 | } |
| 883 | |
| 884 | void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata, |
| 885 | bool clear) |
| 886 | { |
| 887 | struct ieee80211_local *local = sdata->local; |
| 888 | |
| 889 | mutex_lock(&local->chanctx_mtx); |
| 890 | |
| 891 | __ieee80211_vif_copy_chanctx_to_vlans(sdata, clear); |
| 892 | |
| 893 | mutex_unlock(&local->chanctx_mtx); |
| 894 | } |
| 895 | |
| 896 | int ieee80211_vif_unreserve_chanctx(struct ieee80211_sub_if_data *sdata) |
| 897 | { |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 898 | struct ieee80211_chanctx *ctx = sdata->reserved_chanctx; |
| 899 | |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 900 | lockdep_assert_held(&sdata->local->chanctx_mtx); |
| 901 | |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 902 | if (WARN_ON(!ctx)) |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 903 | return -EINVAL; |
| 904 | |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 905 | list_del(&sdata->reserved_chanctx_list); |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 906 | sdata->reserved_chanctx = NULL; |
| 907 | |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 908 | if (ieee80211_chanctx_refcount(sdata->local, ctx) == 0) |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 909 | ieee80211_free_chanctx(sdata->local, ctx); |
| 910 | |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | int ieee80211_vif_reserve_chanctx(struct ieee80211_sub_if_data *sdata, |
| 915 | const struct cfg80211_chan_def *chandef, |
Michal Kazior | 0933248 | 2014-04-09 15:29:25 +0200 | [diff] [blame] | 916 | enum ieee80211_chanctx_mode mode, |
| 917 | bool radar_required) |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 918 | { |
| 919 | struct ieee80211_local *local = sdata->local; |
| 920 | struct ieee80211_chanctx_conf *conf; |
| 921 | struct ieee80211_chanctx *new_ctx, *curr_ctx; |
| 922 | int ret = 0; |
| 923 | |
| 924 | mutex_lock(&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 | |
| 933 | curr_ctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 934 | |
Michal Kazior | 13f348a | 2014-04-09 15:29:29 +0200 | [diff] [blame] | 935 | new_ctx = ieee80211_find_reservation_chanctx(local, chandef, mode); |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 936 | if (!new_ctx) { |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 937 | if (ieee80211_chanctx_refcount(local, curr_ctx) == 1 && |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 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; |
Michal Kazior | c2b90ad | 2014-04-09 15:29:24 +0200 | [diff] [blame] | 944 | } else if (ieee80211_can_create_new_chanctx(local)) { |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 945 | /* create a new context and reserve it */ |
| 946 | new_ctx = ieee80211_new_chanctx(local, chandef, mode); |
| 947 | if (IS_ERR(new_ctx)) { |
| 948 | ret = PTR_ERR(new_ctx); |
| 949 | goto out; |
| 950 | } |
Michal Kazior | c2b90ad | 2014-04-09 15:29:24 +0200 | [diff] [blame] | 951 | } else { |
| 952 | ret = -EBUSY; |
| 953 | goto out; |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 957 | list_add(&sdata->reserved_chanctx_list, &new_ctx->reserved_vifs); |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 958 | sdata->reserved_chanctx = new_ctx; |
| 959 | sdata->reserved_chandef = *chandef; |
Michal Kazior | 0933248 | 2014-04-09 15:29:25 +0200 | [diff] [blame] | 960 | sdata->reserved_radar_required = radar_required; |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 961 | out: |
| 962 | mutex_unlock(&local->chanctx_mtx); |
| 963 | return ret; |
| 964 | } |
| 965 | |
| 966 | int ieee80211_vif_use_reserved_context(struct ieee80211_sub_if_data *sdata, |
| 967 | u32 *changed) |
| 968 | { |
| 969 | struct ieee80211_local *local = sdata->local; |
| 970 | struct ieee80211_chanctx *ctx; |
| 971 | struct ieee80211_chanctx *old_ctx; |
| 972 | struct ieee80211_chanctx_conf *conf; |
| 973 | int ret; |
| 974 | u32 tmp_changed = *changed; |
| 975 | |
| 976 | /* TODO: need to recheck if the chandef is usable etc.? */ |
| 977 | |
| 978 | lockdep_assert_held(&local->mtx); |
| 979 | |
| 980 | mutex_lock(&local->chanctx_mtx); |
| 981 | |
| 982 | ctx = sdata->reserved_chanctx; |
| 983 | if (WARN_ON(!ctx)) { |
| 984 | ret = -EINVAL; |
| 985 | goto out; |
| 986 | } |
| 987 | |
| 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; |
| 993 | } |
| 994 | |
| 995 | old_ctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 996 | |
| 997 | if (sdata->vif.bss_conf.chandef.width != sdata->reserved_chandef.width) |
| 998 | tmp_changed |= BSS_CHANGED_BANDWIDTH; |
| 999 | |
| 1000 | sdata->vif.bss_conf.chandef = sdata->reserved_chandef; |
| 1001 | |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 1002 | /* unref our reservation */ |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 1003 | sdata->reserved_chanctx = NULL; |
Michal Kazior | 0933248 | 2014-04-09 15:29:25 +0200 | [diff] [blame] | 1004 | sdata->radar_required = sdata->reserved_radar_required; |
Michal Kazior | e3afb92 | 2014-04-09 15:29:27 +0200 | [diff] [blame] | 1005 | list_del(&sdata->reserved_chanctx_list); |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 1006 | |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 1007 | if (old_ctx == ctx) { |
| 1008 | /* This is our own context, just change it */ |
| 1009 | ret = __ieee80211_vif_change_channel(sdata, old_ctx, |
| 1010 | &tmp_changed); |
| 1011 | if (ret) |
| 1012 | goto out; |
| 1013 | } else { |
| 1014 | ret = ieee80211_assign_vif_chanctx(sdata, ctx); |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 1015 | if (ieee80211_chanctx_refcount(local, old_ctx) == 0) |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 1016 | ieee80211_free_chanctx(local, old_ctx); |
| 1017 | if (ret) { |
| 1018 | /* if assign fails refcount stays the same */ |
Michal Kazior | c0166da | 2014-04-09 15:29:33 +0200 | [diff] [blame] | 1019 | if (ieee80211_chanctx_refcount(local, ctx) == 0) |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 1020 | ieee80211_free_chanctx(local, ctx); |
| 1021 | goto out; |
| 1022 | } |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 1023 | |
Luciano Coelho | 5d52ee8 | 2014-02-27 14:33:47 +0200 | [diff] [blame] | 1024 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 1025 | __ieee80211_vif_copy_chanctx_to_vlans(sdata, false); |
| 1026 | } |
Luciano Coelho | 11335a5 | 2013-10-30 13:09:39 +0200 | [diff] [blame] | 1027 | |
| 1028 | *changed = tmp_changed; |
| 1029 | |
| 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: |
| 1035 | mutex_unlock(&local->chanctx_mtx); |
| 1036 | return ret; |
| 1037 | } |
| 1038 | |
Johannes Berg | 2c9b735 | 2013-02-07 21:37:29 +0100 | [diff] [blame] | 1039 | int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata, |
| 1040 | const struct cfg80211_chan_def *chandef, |
| 1041 | u32 *changed) |
| 1042 | { |
| 1043 | struct ieee80211_local *local = sdata->local; |
| 1044 | struct ieee80211_chanctx_conf *conf; |
| 1045 | struct ieee80211_chanctx *ctx; |
| 1046 | int ret; |
| 1047 | |
| 1048 | if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
| 1049 | IEEE80211_CHAN_DISABLED)) |
| 1050 | return -EINVAL; |
| 1051 | |
| 1052 | mutex_lock(&local->chanctx_mtx); |
| 1053 | if (cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef)) { |
| 1054 | ret = 0; |
| 1055 | goto out; |
| 1056 | } |
| 1057 | |
| 1058 | if (chandef->width == NL80211_CHAN_WIDTH_20_NOHT || |
| 1059 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) { |
| 1060 | ret = -EINVAL; |
| 1061 | goto out; |
| 1062 | } |
| 1063 | |
| 1064 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 1065 | lockdep_is_held(&local->chanctx_mtx)); |
| 1066 | if (!conf) { |
| 1067 | ret = -EINVAL; |
| 1068 | goto out; |
| 1069 | } |
| 1070 | |
| 1071 | ctx = container_of(conf, struct ieee80211_chanctx, conf); |
| 1072 | if (!cfg80211_chandef_compatible(&conf->def, chandef)) { |
| 1073 | ret = -EINVAL; |
| 1074 | goto out; |
| 1075 | } |
| 1076 | |
| 1077 | sdata->vif.bss_conf.chandef = *chandef; |
| 1078 | |
| 1079 | ieee80211_recalc_chanctx_chantype(local, ctx); |
| 1080 | |
| 1081 | *changed |= BSS_CHANGED_BANDWIDTH; |
| 1082 | ret = 0; |
| 1083 | out: |
| 1084 | mutex_unlock(&local->chanctx_mtx); |
| 1085 | return ret; |
| 1086 | } |
| 1087 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 1088 | void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) |
| 1089 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1090 | WARN_ON(sdata->dev && netif_carrier_ok(sdata->dev)); |
| 1091 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1092 | lockdep_assert_held(&sdata->local->mtx); |
| 1093 | |
Michal Kazior | d01a1e6 | 2012-06-26 14:37:16 +0200 | [diff] [blame] | 1094 | mutex_lock(&sdata->local->chanctx_mtx); |
| 1095 | __ieee80211_vif_release_channel(sdata); |
| 1096 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 1097 | } |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 1098 | |
Johannes Berg | 4d76d21 | 2012-12-11 20:38:41 +0100 | [diff] [blame] | 1099 | void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata) |
| 1100 | { |
| 1101 | struct ieee80211_local *local = sdata->local; |
| 1102 | struct ieee80211_sub_if_data *ap; |
| 1103 | struct ieee80211_chanctx_conf *conf; |
| 1104 | |
| 1105 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->bss)) |
| 1106 | return; |
| 1107 | |
| 1108 | ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); |
| 1109 | |
| 1110 | mutex_lock(&local->chanctx_mtx); |
| 1111 | |
| 1112 | conf = rcu_dereference_protected(ap->vif.chanctx_conf, |
| 1113 | lockdep_is_held(&local->chanctx_mtx)); |
| 1114 | rcu_assign_pointer(sdata->vif.chanctx_conf, conf); |
| 1115 | mutex_unlock(&local->chanctx_mtx); |
| 1116 | } |
| 1117 | |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 1118 | void ieee80211_iter_chan_contexts_atomic( |
| 1119 | struct ieee80211_hw *hw, |
| 1120 | void (*iter)(struct ieee80211_hw *hw, |
| 1121 | struct ieee80211_chanctx_conf *chanctx_conf, |
| 1122 | void *data), |
| 1123 | void *iter_data) |
| 1124 | { |
| 1125 | struct ieee80211_local *local = hw_to_local(hw); |
| 1126 | struct ieee80211_chanctx *ctx; |
| 1127 | |
| 1128 | rcu_read_lock(); |
| 1129 | list_for_each_entry_rcu(ctx, &local->chanctx_list, list) |
Johannes Berg | 8a61af6 | 2012-12-13 17:42:30 +0100 | [diff] [blame] | 1130 | if (ctx->driver_present) |
| 1131 | iter(hw, &ctx->conf, iter_data); |
Johannes Berg | 3448c00 | 2012-09-11 17:57:42 +0200 | [diff] [blame] | 1132 | rcu_read_unlock(); |
| 1133 | } |
| 1134 | EXPORT_SYMBOL_GPL(ieee80211_iter_chan_contexts_atomic); |