Skip to content

Commit e227300

Browse files
Purushottam Kushwahajmberg-intel
authored andcommitted
cfg80211: pass struct to interface combination check/iter
Move the growing parameter list to a structure for the interface combination check and iteration functions in cfg80211 and mac80211 to make the code easier to understand. Signed-off-by: Purushottam Kushwaha <pkushwah@qti.qualcomm.com> [edit commit message] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 32910bb commit e227300

File tree

4 files changed

+68
-72
lines changed

4 files changed

+68
-72
lines changed

drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,39 +414,41 @@ static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg,
414414
struct brcmf_cfg80211_vif *vif,
415415
enum nl80211_iftype new_type)
416416
{
417-
int iftype_num[NUM_NL80211_IFTYPES];
418417
struct brcmf_cfg80211_vif *pos;
419418
bool check_combos = false;
420419
int ret = 0;
420+
struct iface_combination_params params = {
421+
.num_different_channels = 1,
422+
};
421423

422-
memset(&iftype_num[0], 0, sizeof(iftype_num));
423424
list_for_each_entry(pos, &cfg->vif_list, list)
424425
if (pos == vif) {
425-
iftype_num[new_type]++;
426+
params.iftype_num[new_type]++;
426427
} else {
427428
/* concurrent interfaces so need check combinations */
428429
check_combos = true;
429-
iftype_num[pos->wdev.iftype]++;
430+
params.iftype_num[pos->wdev.iftype]++;
430431
}
431432

432433
if (check_combos)
433-
ret = cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
434+
ret = cfg80211_check_combinations(cfg->wiphy, &params);
434435

435436
return ret;
436437
}
437438

438439
static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg,
439440
enum nl80211_iftype new_type)
440441
{
441-
int iftype_num[NUM_NL80211_IFTYPES];
442442
struct brcmf_cfg80211_vif *pos;
443+
struct iface_combination_params params = {
444+
.num_different_channels = 1,
445+
};
443446

444-
memset(&iftype_num[0], 0, sizeof(iftype_num));
445447
list_for_each_entry(pos, &cfg->vif_list, list)
446-
iftype_num[pos->wdev.iftype]++;
448+
params.iftype_num[pos->wdev.iftype]++;
447449

448-
iftype_num[new_type]++;
449-
return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num);
450+
params.iftype_num[new_type]++;
451+
return cfg80211_check_combinations(cfg->wiphy, &params);
450452
}
451453

452454
static void convert_key_from_CPU(struct brcmf_wsec_key *key,

include/net/cfg80211.h

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,26 @@ struct cfg80211_csa_settings {
771771
u8 count;
772772
};
773773

774+
/**
775+
* struct iface_combination_params - input parameters for interface combinations
776+
*
777+
* Used to pass interface combination parameters
778+
*
779+
* @num_different_channels: the number of different channels we want
780+
* to use for verification
781+
* @radar_detect: a bitmap where each bit corresponds to a channel
782+
* width where radar detection is needed, as in the definition of
783+
* &struct ieee80211_iface_combination.@radar_detect_widths
784+
* @iftype_num: array with the number of interfaces of each interface
785+
* type. The index is the interface type as specified in &enum
786+
* nl80211_iftype.
787+
*/
788+
struct iface_combination_params {
789+
int num_different_channels;
790+
u8 radar_detect;
791+
int iftype_num[NUM_NL80211_IFTYPES];
792+
};
793+
774794
/**
775795
* enum station_parameters_apply_mask - station parameter values to apply
776796
* @STATION_PARAM_APPLY_UAPSD: apply new uAPSD parameters (uapsd_queues, max_sp)
@@ -5575,36 +5595,20 @@ unsigned int ieee80211_get_num_supported_channels(struct wiphy *wiphy);
55755595
* cfg80211_check_combinations - check interface combinations
55765596
*
55775597
* @wiphy: the wiphy
5578-
* @num_different_channels: the number of different channels we want
5579-
* to use for verification
5580-
* @radar_detect: a bitmap where each bit corresponds to a channel
5581-
* width where radar detection is needed, as in the definition of
5582-
* &struct ieee80211_iface_combination.@radar_detect_widths
5583-
* @iftype_num: array with the numbers of interfaces of each interface
5584-
* type. The index is the interface type as specified in &enum
5585-
* nl80211_iftype.
5598+
* @params: the interface combinations parameter
55865599
*
55875600
* This function can be called by the driver to check whether a
55885601
* combination of interfaces and their types are allowed according to
55895602
* the interface combinations.
55905603
*/
55915604
int cfg80211_check_combinations(struct wiphy *wiphy,
5592-
const int num_different_channels,
5593-
const u8 radar_detect,
5594-
const int iftype_num[NUM_NL80211_IFTYPES]);
5605+
struct iface_combination_params *params);
55955606

55965607
/**
55975608
* cfg80211_iter_combinations - iterate over matching combinations
55985609
*
55995610
* @wiphy: the wiphy
5600-
* @num_different_channels: the number of different channels we want
5601-
* to use for verification
5602-
* @radar_detect: a bitmap where each bit corresponds to a channel
5603-
* width where radar detection is needed, as in the definition of
5604-
* &struct ieee80211_iface_combination.@radar_detect_widths
5605-
* @iftype_num: array with the numbers of interfaces of each interface
5606-
* type. The index is the interface type as specified in &enum
5607-
* nl80211_iftype.
5611+
* @params: the interface combinations parameter
56085612
* @iter: function to call for each matching combination
56095613
* @data: pointer to pass to iter function
56105614
*
@@ -5613,9 +5617,7 @@ int cfg80211_check_combinations(struct wiphy *wiphy,
56135617
* purposes.
56145618
*/
56155619
int cfg80211_iter_combinations(struct wiphy *wiphy,
5616-
const int num_different_channels,
5617-
const u8 radar_detect,
5618-
const int iftype_num[NUM_NL80211_IFTYPES],
5620+
struct iface_combination_params *params,
56195621
void (*iter)(const struct ieee80211_iface_combination *c,
56205622
void *data),
56215623
void *data);

net/mac80211/util.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3308,10 +3308,11 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
33083308
struct ieee80211_local *local = sdata->local;
33093309
struct ieee80211_sub_if_data *sdata_iter;
33103310
enum nl80211_iftype iftype = sdata->wdev.iftype;
3311-
int num[NUM_NL80211_IFTYPES];
33123311
struct ieee80211_chanctx *ctx;
3313-
int num_different_channels = 0;
33143312
int total = 1;
3313+
struct iface_combination_params params = {
3314+
.radar_detect = radar_detect,
3315+
};
33153316

33163317
lockdep_assert_held(&local->chanctx_mtx);
33173318

@@ -3322,9 +3323,6 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
33223323
!chandef->chan))
33233324
return -EINVAL;
33243325

3325-
if (chandef)
3326-
num_different_channels = 1;
3327-
33283326
if (WARN_ON(iftype >= NUM_NL80211_IFTYPES))
33293327
return -EINVAL;
33303328

@@ -3335,24 +3333,26 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
33353333
return 0;
33363334
}
33373335

3338-
memset(num, 0, sizeof(num));
3336+
if (chandef)
3337+
params.num_different_channels = 1;
33393338

33403339
if (iftype != NL80211_IFTYPE_UNSPECIFIED)
3341-
num[iftype] = 1;
3340+
params.iftype_num[iftype] = 1;
33423341

33433342
list_for_each_entry(ctx, &local->chanctx_list, list) {
33443343
if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
33453344
continue;
3346-
radar_detect |= ieee80211_chanctx_radar_detect(local, ctx);
3345+
params.radar_detect |=
3346+
ieee80211_chanctx_radar_detect(local, ctx);
33473347
if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) {
3348-
num_different_channels++;
3348+
params.num_different_channels++;
33493349
continue;
33503350
}
33513351
if (chandef && chanmode == IEEE80211_CHANCTX_SHARED &&
33523352
cfg80211_chandef_compatible(chandef,
33533353
&ctx->conf.def))
33543354
continue;
3355-
num_different_channels++;
3355+
params.num_different_channels++;
33563356
}
33573357

33583358
list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) {
@@ -3365,16 +3365,14 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
33653365
local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype))
33663366
continue;
33673367

3368-
num[wdev_iter->iftype]++;
3368+
params.iftype_num[wdev_iter->iftype]++;
33693369
total++;
33703370
}
33713371

3372-
if (total == 1 && !radar_detect)
3372+
if (total == 1 && !params.radar_detect)
33733373
return 0;
33743374

3375-
return cfg80211_check_combinations(local->hw.wiphy,
3376-
num_different_channels,
3377-
radar_detect, num);
3375+
return cfg80211_check_combinations(local->hw.wiphy, &params);
33783376
}
33793377

33803378
static void
@@ -3390,30 +3388,28 @@ ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c,
33903388
int ieee80211_max_num_channels(struct ieee80211_local *local)
33913389
{
33923390
struct ieee80211_sub_if_data *sdata;
3393-
int num[NUM_NL80211_IFTYPES] = {};
33943391
struct ieee80211_chanctx *ctx;
3395-
int num_different_channels = 0;
3396-
u8 radar_detect = 0;
33973392
u32 max_num_different_channels = 1;
33983393
int err;
3394+
struct iface_combination_params params = {0};
33993395

34003396
lockdep_assert_held(&local->chanctx_mtx);
34013397

34023398
list_for_each_entry(ctx, &local->chanctx_list, list) {
34033399
if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
34043400
continue;
34053401

3406-
num_different_channels++;
3402+
params.num_different_channels++;
34073403

3408-
radar_detect |= ieee80211_chanctx_radar_detect(local, ctx);
3404+
params.radar_detect |=
3405+
ieee80211_chanctx_radar_detect(local, ctx);
34093406
}
34103407

34113408
list_for_each_entry_rcu(sdata, &local->interfaces, list)
3412-
num[sdata->wdev.iftype]++;
3409+
params.iftype_num[sdata->wdev.iftype]++;
34133410

3414-
err = cfg80211_iter_combinations(local->hw.wiphy,
3415-
num_different_channels, radar_detect,
3416-
num, ieee80211_iter_max_chans,
3411+
err = cfg80211_iter_combinations(local->hw.wiphy, &params,
3412+
ieee80211_iter_max_chans,
34173413
&max_num_different_channels);
34183414
if (err < 0)
34193415
return err;

net/wireless/util.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,7 @@ int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
15801580
}
15811581

15821582
int cfg80211_iter_combinations(struct wiphy *wiphy,
1583-
const int num_different_channels,
1584-
const u8 radar_detect,
1585-
const int iftype_num[NUM_NL80211_IFTYPES],
1583+
struct iface_combination_params *params,
15861584
void (*iter)(const struct ieee80211_iface_combination *c,
15871585
void *data),
15881586
void *data)
@@ -1593,7 +1591,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
15931591
int num_interfaces = 0;
15941592
u32 used_iftypes = 0;
15951593

1596-
if (radar_detect) {
1594+
if (params->radar_detect) {
15971595
rcu_read_lock();
15981596
regdom = rcu_dereference(cfg80211_regdomain);
15991597
if (regdom)
@@ -1602,8 +1600,8 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
16021600
}
16031601

16041602
for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
1605-
num_interfaces += iftype_num[iftype];
1606-
if (iftype_num[iftype] > 0 &&
1603+
num_interfaces += params->iftype_num[iftype];
1604+
if (params->iftype_num[iftype] > 0 &&
16071605
!(wiphy->software_iftypes & BIT(iftype)))
16081606
used_iftypes |= BIT(iftype);
16091607
}
@@ -1617,7 +1615,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
16171615

16181616
if (num_interfaces > c->max_interfaces)
16191617
continue;
1620-
if (num_different_channels > c->num_different_channels)
1618+
if (params->num_different_channels > c->num_different_channels)
16211619
continue;
16221620

16231621
limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
@@ -1632,16 +1630,17 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
16321630
all_iftypes |= limits[j].types;
16331631
if (!(limits[j].types & BIT(iftype)))
16341632
continue;
1635-
if (limits[j].max < iftype_num[iftype])
1633+
if (limits[j].max < params->iftype_num[iftype])
16361634
goto cont;
1637-
limits[j].max -= iftype_num[iftype];
1635+
limits[j].max -= params->iftype_num[iftype];
16381636
}
16391637
}
16401638

1641-
if (radar_detect != (c->radar_detect_widths & radar_detect))
1639+
if (params->radar_detect !=
1640+
(c->radar_detect_widths & params->radar_detect))
16421641
goto cont;
16431642

1644-
if (radar_detect && c->radar_detect_regions &&
1643+
if (params->radar_detect && c->radar_detect_regions &&
16451644
!(c->radar_detect_regions & BIT(region)))
16461645
goto cont;
16471646

@@ -1675,14 +1674,11 @@ cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c,
16751674
}
16761675

16771676
int cfg80211_check_combinations(struct wiphy *wiphy,
1678-
const int num_different_channels,
1679-
const u8 radar_detect,
1680-
const int iftype_num[NUM_NL80211_IFTYPES])
1677+
struct iface_combination_params *params)
16811678
{
16821679
int err, num = 0;
16831680

1684-
err = cfg80211_iter_combinations(wiphy, num_different_channels,
1685-
radar_detect, iftype_num,
1681+
err = cfg80211_iter_combinations(wiphy, params,
16861682
cfg80211_iter_sum_ifcombs, &num);
16871683
if (err)
16881684
return err;

0 commit comments

Comments
 (0)