Skip to content

Commit

Permalink
mac80211: improve find_chanctx() for reservations
Browse files Browse the repository at this point in the history
This allows new vifs to be assigned to a chanctx
as long as chanctx's reservation chandefs (if any)
and chanctx's current chandef (implied by assigned
vifs at the time, if any) and the new vif chandef
are all compatible.

This implies it is impossible to assign a new vif
to an in-place reservation chanctx.

This gives no advantages for single-channel
hardware. It makes sense for multi-channel
hardware only.

Signed-off-by: Michal Kazior <michal.kazior@tieto.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Michal Kazior authored and Johannes Berg committed Apr 25, 2014
1 parent e3afb92 commit 0288157
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions net/mac80211/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ static bool ieee80211_can_create_new_chanctx(struct ieee80211_local *local)
return ieee80211_num_chanctx(local) < ieee80211_max_num_channels(local);
}

static const struct cfg80211_chan_def *
ieee80211_chanctx_reserved_chandef(struct ieee80211_local *local,
struct ieee80211_chanctx *ctx,
const struct cfg80211_chan_def *compat)
{
struct ieee80211_sub_if_data *sdata;

lockdep_assert_held(&local->chanctx_mtx);

list_for_each_entry(sdata, &ctx->reserved_vifs,
reserved_chanctx_list) {
if (!compat)
compat = &sdata->reserved_chandef;

compat = cfg80211_chandef_compatible(&sdata->reserved_chandef,
compat);
if (!compat)
break;
}

return compat;
}

static enum nl80211_chan_width ieee80211_get_sta_bw(struct ieee80211_sta *sta)
{
switch (sta->bandwidth) {
Expand Down Expand Up @@ -187,27 +210,6 @@ static void ieee80211_change_chanctx(struct ieee80211_local *local,
}
}

static bool ieee80211_chanctx_is_reserved(struct ieee80211_local *local,
struct ieee80211_chanctx *ctx)
{
struct ieee80211_sub_if_data *sdata;
bool ret = false;

lockdep_assert_held(&local->chanctx_mtx);
rcu_read_lock();
list_for_each_entry_rcu(sdata, &local->interfaces, list) {
if (!ieee80211_sdata_running(sdata))
continue;
if (sdata->reserved_chanctx == ctx) {
ret = true;
break;
}
}

rcu_read_unlock();
return ret;
}

static struct ieee80211_chanctx *
ieee80211_find_chanctx(struct ieee80211_local *local,
const struct cfg80211_chan_def *chandef,
Expand All @@ -223,18 +225,18 @@ ieee80211_find_chanctx(struct ieee80211_local *local,
list_for_each_entry(ctx, &local->chanctx_list, list) {
const struct cfg80211_chan_def *compat;

/* We don't support chanctx reservation for multiple
* vifs yet, so don't allow reserved chanctxs to be
* reused.
*/
if ((ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) ||
ieee80211_chanctx_is_reserved(local, ctx))
if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE)
continue;

compat = cfg80211_chandef_compatible(&ctx->conf.def, chandef);
if (!compat)
continue;

compat = ieee80211_chanctx_reserved_chandef(local, ctx,
compat);
if (!compat)
continue;

ieee80211_change_chanctx(local, ctx, compat);

return ctx;
Expand Down

0 comments on commit 0288157

Please sign in to comment.