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/mac80211/chan.c | |
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/mac80211/chan.c')
-rw-r--r-- | net/mac80211/chan.c | 147 |
1 files changed, 147 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 | } | ||