Skip to content

Commit

Permalink
mac80211: add max channel calculation utility function
Browse files Browse the repository at this point in the history
The utility function has no uses yet. It is aimed
at future chanctx reservation management and
channel switching.

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 65a124d commit 6fa001b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
const struct cfg80211_chan_def *chandef,
enum ieee80211_chanctx_mode chanmode,
u8 radar_detect);
int ieee80211_max_num_channels(struct ieee80211_local *local);

#ifdef CONFIG_MAC80211_NOINLINE
#define debug_noinline noinline
Expand Down
42 changes: 42 additions & 0 deletions net/mac80211/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2873,3 +2873,45 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
num_different_channels,
radar_detect, num);
}

static void
ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c,
void *data)
{
u32 *max_num_different_channels = data;

*max_num_different_channels = max(*max_num_different_channels,
c->num_different_channels);
}

int ieee80211_max_num_channels(struct ieee80211_local *local)
{
struct ieee80211_sub_if_data *sdata;
int num[NUM_NL80211_IFTYPES] = {};
struct ieee80211_chanctx *ctx;
int num_different_channels = 0;
u8 radar_detect = 0;
u32 max_num_different_channels = 1;
int err;

lockdep_assert_held(&local->chanctx_mtx);

list_for_each_entry(ctx, &local->chanctx_list, list) {
num_different_channels++;

if (ctx->conf.radar_enabled)
radar_detect |= BIT(ctx->conf.def.width);
}

list_for_each_entry_rcu(sdata, &local->interfaces, list)
num[sdata->wdev.iftype]++;

err = cfg80211_iter_combinations(local->hw.wiphy,
num_different_channels, radar_detect,
num, ieee80211_iter_max_chans,
&max_num_different_channels);
if (err < 0)
return err;

return max_num_different_channels;
}

0 comments on commit 6fa001b

Please sign in to comment.