diff options
author | Michal Kazior <michal.kazior@tieto.com> | 2012-06-26 08:37:16 -0400 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2012-10-16 14:22:41 -0400 |
commit | d01a1e658606a0a69100f49c2ef09aacaf74d3e7 (patch) | |
tree | 30de068699ed95997ad44f4d0f703a6deb0ad95b /net | |
parent | ddffeb8c4d0331609ef2581d84de4d763607bd37 (diff) |
mac80211: introduce channel context skeleton code
Channel context are the foundation for multi-channel
operation. They are are immutable and are re-created
(or re-used if other interfaces are bound to a certain
channel and a compatible channel type) on channel
switching.
This is an initial implementation and more features
will come in separate patches.
Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
[some changes including RCU protection]
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/mac80211/chan.c | 147 | ||||
-rw-r--r-- | net/mac80211/ieee80211_i.h | 35 | ||||
-rw-r--r-- | net/mac80211/main.c | 3 |
3 files changed, 185 insertions, 0 deletions
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c index 0bfc914ddd15..4ae94860a161 100644 --- a/net/mac80211/chan.c +++ b/net/mac80211/chan.c | |||
@@ -168,3 +168,150 @@ bool ieee80211_set_channel_type(struct ieee80211_local *local, | |||
168 | return true; | 168 | return true; |
169 | 169 | ||
170 | } | 170 | } |
171 | |||
172 | static struct ieee80211_chanctx * | ||
173 | ieee80211_find_chanctx(struct ieee80211_local *local, | ||
174 | struct ieee80211_channel *channel, | ||
175 | enum nl80211_channel_type channel_type, | ||
176 | enum ieee80211_chanctx_mode mode) | ||
177 | { | ||
178 | struct ieee80211_chanctx *ctx; | ||
179 | |||
180 | lockdep_assert_held(&local->chanctx_mtx); | ||
181 | |||
182 | if (mode == IEEE80211_CHANCTX_EXCLUSIVE) | ||
183 | return NULL; | ||
184 | if (WARN_ON(!channel)) | ||
185 | return NULL; | ||
186 | |||
187 | list_for_each_entry(ctx, &local->chanctx_list, list) { | ||
188 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) | ||
189 | continue; | ||
190 | if (ctx->conf.channel != channel) | ||
191 | continue; | ||
192 | if (ctx->conf.channel_type != channel_type) | ||
193 | continue; | ||
194 | |||
195 | return ctx; | ||
196 | } | ||
197 | |||
198 | return NULL; | ||
199 | } | ||
200 | |||
201 | static struct ieee80211_chanctx * | ||
202 | ieee80211_new_chanctx(struct ieee80211_local *local, | ||
203 | struct ieee80211_channel *channel, | ||
204 | enum nl80211_channel_type channel_type, | ||
205 | enum ieee80211_chanctx_mode mode) | ||
206 | { | ||
207 | struct ieee80211_chanctx *ctx; | ||
208 | |||
209 | lockdep_assert_held(&local->chanctx_mtx); | ||
210 | |||
211 | ctx = kzalloc(sizeof(*ctx) + local->hw.chanctx_data_size, GFP_KERNEL); | ||
212 | if (!ctx) | ||
213 | return ERR_PTR(-ENOMEM); | ||
214 | |||
215 | ctx->conf.channel = channel; | ||
216 | ctx->conf.channel_type = channel_type; | ||
217 | ctx->mode = mode; | ||
218 | |||
219 | list_add(&ctx->list, &local->chanctx_list); | ||
220 | |||
221 | return ctx; | ||
222 | } | ||
223 | |||
224 | static void ieee80211_free_chanctx(struct ieee80211_local *local, | ||
225 | struct ieee80211_chanctx *ctx) | ||
226 | { | ||
227 | lockdep_assert_held(&local->chanctx_mtx); | ||
228 | |||
229 | WARN_ON_ONCE(ctx->refcount != 0); | ||
230 | |||
231 | list_del(&ctx->list); | ||
232 | kfree_rcu(ctx, rcu_head); | ||
233 | } | ||
234 | |||
235 | static int ieee80211_assign_vif_chanctx(struct ieee80211_sub_if_data *sdata, | ||
236 | struct ieee80211_chanctx *ctx) | ||
237 | { | ||
238 | struct ieee80211_local *local __maybe_unused = sdata->local; | ||
239 | |||
240 | lockdep_assert_held(&local->chanctx_mtx); | ||
241 | |||
242 | rcu_assign_pointer(sdata->vif.chanctx_conf, &ctx->conf); | ||
243 | ctx->refcount++; | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | |||
248 | static void ieee80211_unassign_vif_chanctx(struct ieee80211_sub_if_data *sdata, | ||
249 | struct ieee80211_chanctx *ctx) | ||
250 | { | ||
251 | struct ieee80211_local *local __maybe_unused = sdata->local; | ||
252 | |||
253 | lockdep_assert_held(&local->chanctx_mtx); | ||
254 | |||
255 | ctx->refcount--; | ||
256 | rcu_assign_pointer(sdata->vif.chanctx_conf, NULL); | ||
257 | } | ||
258 | |||
259 | static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) | ||
260 | { | ||
261 | struct ieee80211_local *local = sdata->local; | ||
262 | struct ieee80211_chanctx_conf *conf; | ||
263 | struct ieee80211_chanctx *ctx; | ||
264 | |||
265 | lockdep_assert_held(&local->chanctx_mtx); | ||
266 | |||
267 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, | ||
268 | lockdep_is_held(&local->chanctx_mtx)); | ||
269 | if (!conf) | ||
270 | return; | ||
271 | |||
272 | ctx = container_of(conf, struct ieee80211_chanctx, conf); | ||
273 | |||
274 | ieee80211_unassign_vif_chanctx(sdata, ctx); | ||
275 | if (ctx->refcount == 0) | ||
276 | ieee80211_free_chanctx(local, ctx); | ||
277 | } | ||
278 | |||
279 | int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, | ||
280 | struct ieee80211_channel *channel, | ||
281 | enum nl80211_channel_type channel_type, | ||
282 | enum ieee80211_chanctx_mode mode) | ||
283 | { | ||
284 | struct ieee80211_local *local = sdata->local; | ||
285 | struct ieee80211_chanctx *ctx; | ||
286 | int ret; | ||
287 | |||
288 | mutex_lock(&local->chanctx_mtx); | ||
289 | __ieee80211_vif_release_channel(sdata); | ||
290 | |||
291 | ctx = ieee80211_find_chanctx(local, channel, channel_type, mode); | ||
292 | if (!ctx) | ||
293 | ctx = ieee80211_new_chanctx(local, channel, channel_type, mode); | ||
294 | if (IS_ERR(ctx)) { | ||
295 | ret = PTR_ERR(ctx); | ||
296 | goto out; | ||
297 | } | ||
298 | |||
299 | ret = ieee80211_assign_vif_chanctx(sdata, ctx); | ||
300 | if (ret) { | ||
301 | /* if assign fails refcount stays the same */ | ||
302 | if (ctx->refcount == 0) | ||
303 | ieee80211_free_chanctx(local, ctx); | ||
304 | goto out; | ||
305 | } | ||
306 | |||
307 | out: | ||
308 | mutex_unlock(&local->chanctx_mtx); | ||
309 | return ret; | ||
310 | } | ||
311 | |||
312 | void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata) | ||
313 | { | ||
314 | mutex_lock(&sdata->local->chanctx_mtx); | ||
315 | __ieee80211_vif_release_channel(sdata); | ||
316 | mutex_unlock(&sdata->local->chanctx_mtx); | ||
317 | } | ||
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 8c804550465b..9a058e58d53e 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -658,6 +658,30 @@ enum ieee80211_sdata_state_bits { | |||
658 | SDATA_STATE_OFFCHANNEL, | 658 | SDATA_STATE_OFFCHANNEL, |
659 | }; | 659 | }; |
660 | 660 | ||
661 | /** | ||
662 | * enum ieee80211_chanctx_mode - channel context configuration mode | ||
663 | * | ||
664 | * @IEEE80211_CHANCTX_SHARED: channel context may be used by | ||
665 | * multiple interfaces | ||
666 | * @IEEE80211_CHANCTX_EXCLUSIVE: channel context can be used | ||
667 | * only by a single interface. This can be used for example for | ||
668 | * non-fixed channel IBSS. | ||
669 | */ | ||
670 | enum ieee80211_chanctx_mode { | ||
671 | IEEE80211_CHANCTX_SHARED, | ||
672 | IEEE80211_CHANCTX_EXCLUSIVE | ||
673 | }; | ||
674 | |||
675 | struct ieee80211_chanctx { | ||
676 | struct list_head list; | ||
677 | struct rcu_head rcu_head; | ||
678 | |||
679 | enum ieee80211_chanctx_mode mode; | ||
680 | int refcount; | ||
681 | |||
682 | struct ieee80211_chanctx_conf conf; | ||
683 | }; | ||
684 | |||
661 | struct ieee80211_sub_if_data { | 685 | struct ieee80211_sub_if_data { |
662 | struct list_head list; | 686 | struct list_head list; |
663 | 687 | ||
@@ -987,6 +1011,10 @@ struct ieee80211_local { | |||
987 | struct ieee80211_channel *tmp_channel; | 1011 | struct ieee80211_channel *tmp_channel; |
988 | enum nl80211_channel_type tmp_channel_type; | 1012 | enum nl80211_channel_type tmp_channel_type; |
989 | 1013 | ||
1014 | /* channel contexts */ | ||
1015 | struct list_head chanctx_list; | ||
1016 | struct mutex chanctx_mtx; | ||
1017 | |||
990 | /* SNMP counters */ | 1018 | /* SNMP counters */ |
991 | /* dot11CountersTable */ | 1019 | /* dot11CountersTable */ |
992 | u32 dot11TransmittedFragmentCount; | 1020 | u32 dot11TransmittedFragmentCount; |
@@ -1510,6 +1538,13 @@ bool ieee80211_set_channel_type(struct ieee80211_local *local, | |||
1510 | enum nl80211_channel_type | 1538 | enum nl80211_channel_type |
1511 | ieee80211_ht_oper_to_channel_type(struct ieee80211_ht_operation *ht_oper); | 1539 | ieee80211_ht_oper_to_channel_type(struct ieee80211_ht_operation *ht_oper); |
1512 | 1540 | ||
1541 | int __must_check | ||
1542 | ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata, | ||
1543 | struct ieee80211_channel *channel, | ||
1544 | enum nl80211_channel_type channel_type, | ||
1545 | enum ieee80211_chanctx_mode mode); | ||
1546 | void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata); | ||
1547 | |||
1513 | #ifdef CONFIG_MAC80211_NOINLINE | 1548 | #ifdef CONFIG_MAC80211_NOINLINE |
1514 | #define debug_noinline noinline | 1549 | #define debug_noinline noinline |
1515 | #else | 1550 | #else |
diff --git a/net/mac80211/main.c b/net/mac80211/main.c index c80c4490351c..9be3ef1d2e86 100644 --- a/net/mac80211/main.c +++ b/net/mac80211/main.c | |||
@@ -626,6 +626,9 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, | |||
626 | spin_lock_init(&local->filter_lock); | 626 | spin_lock_init(&local->filter_lock); |
627 | spin_lock_init(&local->queue_stop_reason_lock); | 627 | spin_lock_init(&local->queue_stop_reason_lock); |
628 | 628 | ||
629 | INIT_LIST_HEAD(&local->chanctx_list); | ||
630 | mutex_init(&local->chanctx_mtx); | ||
631 | |||
629 | /* | 632 | /* |
630 | * The rx_skb_queue is only accessed from tasklets, | 633 | * The rx_skb_queue is only accessed from tasklets, |
631 | * but other SKB queues are used from within IRQ | 634 | * but other SKB queues are used from within IRQ |