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.
Unified · Split
| @@ -414,23 +414,24 @@ static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, · 413 unmodified lines | |||
| 414 | struct brcmf_cfg80211_vif *vif, | 414 | struct brcmf_cfg80211_vif *vif, |
| 415 | enum nl80211_iftype new_type) | 415 | enum nl80211_iftype new_type) |
| 416 | { | 416 | { |
| 417 | int iftype_num[NUM_NL80211_IFTYPES]; | ||
| 418 | struct brcmf_cfg80211_vif *pos; | 417 | struct brcmf_cfg80211_vif *pos; |
| 419 | bool check_combos = false; | 418 | bool check_combos = false; |
| 420 | int ret = 0; | 419 | int ret = 0; |
| 420 | struct iface_combination_params params = { | ||
| 421 | .num_different_channels = 1, | ||
| 422 | }; | ||
| 421 | 423 | ||
| 422 | memset(&iftype_num[0], 0, sizeof(iftype_num)); | ||
| 423 | list_for_each_entry(pos, &cfg->vif_list, list) | 424 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 424 | if (pos == vif) { | 425 | if (pos == vif) { |
| 425 | iftype_num[new_type]++; | 426 | params.iftype_num[new_type]++; |
| 426 | } else { | 427 | } else { |
| 427 | /* concurrent interfaces so need check combinations */ | 428 | /* concurrent interfaces so need check combinations */ |
| 428 | check_combos = true; | 429 | check_combos = true; |
| 429 | iftype_num[pos->wdev.iftype]++; | 430 | params.iftype_num[pos->wdev.iftype]++; |
| 430 | } | 431 | } |
| 431 | 432 | ||
| 432 | if (check_combos) | 433 | if (check_combos) |
| 433 | ret = cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); | 434 | ret = cfg80211_check_combinations(cfg->wiphy, ¶ms); |
| 434 | 435 | ||
| 435 | return ret; | 436 | return ret; |
| 436 | } | 437 | } |
| @@ -438,15 +439,16 @@ static int brcmf_vif_change_validate(struct brcmf_cfg80211_info *cfg, · 1 unmodified line | |||
| 438 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, | 439 | static int brcmf_vif_add_validate(struct brcmf_cfg80211_info *cfg, |
| 439 | enum nl80211_iftype new_type) | 440 | enum nl80211_iftype new_type) |
| 440 | { | 441 | { |
| 441 | int iftype_num[NUM_NL80211_IFTYPES]; | ||
| 442 | struct brcmf_cfg80211_vif *pos; | 442 | struct brcmf_cfg80211_vif *pos; |
| 443 | struct iface_combination_params params = { | ||
| 444 | .num_different_channels = 1, | ||
| 445 | }; | ||
| 443 | 446 | ||
| 444 | memset(&iftype_num[0], 0, sizeof(iftype_num)); | ||
| 445 | list_for_each_entry(pos, &cfg->vif_list, list) | 447 | list_for_each_entry(pos, &cfg->vif_list, list) |
| 446 | iftype_num[pos->wdev.iftype]++; | 448 | params.iftype_num[pos->wdev.iftype]++; |
| 447 | 449 | ||
| 448 | iftype_num[new_type]++; | 450 | params.iftype_num[new_type]++; |
| 449 | return cfg80211_check_combinations(cfg->wiphy, 1, 0, iftype_num); | 451 | return cfg80211_check_combinations(cfg->wiphy, ¶ms); |
| 450 | } | 452 | } |
| 451 | 453 | ||
| 452 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, | 454 | static void convert_key_from_CPU(struct brcmf_wsec_key *key, |
| @@ -771,6 +771,26 @@ struct cfg80211_csa_settings { · 770 unmodified lines | |||
| 771 | u8 count; | 771 | u8 count; |
| 772 | }; | 772 | }; |
| 773 | 773 | ||
| 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 | |||
| 774 | /** | 794 | /** |
| 775 | * enum station_parameters_apply_mask - station parameter values to apply | 795 | * enum station_parameters_apply_mask - station parameter values to apply |
| 776 | * @STATION_PARAM_APPLY_UAPSD: apply new uAPSD parameters (uapsd_queues, max_sp) | 796 | * @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); · 4798 unmodified lines | |||
| 5575 | * cfg80211_check_combinations - check interface combinations | 5595 | * cfg80211_check_combinations - check interface combinations |
| 5576 | * | 5596 | * |
| 5577 | * @wiphy: the wiphy | 5597 | * @wiphy: the wiphy |
| 5578 | * @num_different_channels: the number of different channels we want | 5598 | * @params: the interface combinations parameter |
| 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. | ||
| 5586 | * | 5599 | * |
| 5587 | * This function can be called by the driver to check whether a | 5600 | * This function can be called by the driver to check whether a |
| 5588 | * combination of interfaces and their types are allowed according to | 5601 | * combination of interfaces and their types are allowed according to |
| 5589 | * the interface combinations. | 5602 | * the interface combinations. |
| 5590 | */ | 5603 | */ |
| 5591 | int cfg80211_check_combinations(struct wiphy *wiphy, | 5604 | int cfg80211_check_combinations(struct wiphy *wiphy, |
| 5592 | const int num_different_channels, | 5605 | struct iface_combination_params *params); |
| 5593 | const u8 radar_detect, | ||
| 5594 | const int iftype_num[NUM_NL80211_IFTYPES]); | ||
| 5595 | 5606 | ||
| 5596 | /** | 5607 | /** |
| 5597 | * cfg80211_iter_combinations - iterate over matching combinations | 5608 | * cfg80211_iter_combinations - iterate over matching combinations |
| 5598 | * | 5609 | * |
| 5599 | * @wiphy: the wiphy | 5610 | * @wiphy: the wiphy |
| 5600 | * @num_different_channels: the number of different channels we want | 5611 | * @params: the interface combinations parameter |
| 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. | ||
| 5608 | * @iter: function to call for each matching combination | 5612 | * @iter: function to call for each matching combination |
| 5609 | * @data: pointer to pass to iter function | 5613 | * @data: pointer to pass to iter function |
| 5610 | * | 5614 | * |
| @@ -5613,9 +5617,7 @@ int cfg80211_check_combinations(struct wiphy *wiphy, · 2 unmodified lines | |||
| 5613 | * purposes. | 5617 | * purposes. |
| 5614 | */ | 5618 | */ |
| 5615 | int cfg80211_iter_combinations(struct wiphy *wiphy, | 5619 | int cfg80211_iter_combinations(struct wiphy *wiphy, |
| 5616 | const int num_different_channels, | 5620 | struct iface_combination_params *params, |
| 5617 | const u8 radar_detect, | ||
| 5618 | const int iftype_num[NUM_NL80211_IFTYPES], | ||
| 5619 | void (*iter)(const struct ieee80211_iface_combination *c, | 5621 | void (*iter)(const struct ieee80211_iface_combination *c, |
| 5620 | void *data), | 5622 | void *data), |
| 5621 | void *data); | 5623 | void *data); |
| @@ -3308,10 +3308,11 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 3307 unmodified lines | |||
| 3308 | struct ieee80211_local *local = sdata->local; | 3308 | struct ieee80211_local *local = sdata->local; |
| 3309 | struct ieee80211_sub_if_data *sdata_iter; | 3309 | struct ieee80211_sub_if_data *sdata_iter; |
| 3310 | enum nl80211_iftype iftype = sdata->wdev.iftype; | 3310 | enum nl80211_iftype iftype = sdata->wdev.iftype; |
| 3311 | int num[NUM_NL80211_IFTYPES]; | ||
| 3312 | struct ieee80211_chanctx *ctx; | 3311 | struct ieee80211_chanctx *ctx; |
| 3313 | int num_different_channels = 0; | ||
| 3314 | int total = 1; | 3312 | int total = 1; |
| 3313 | struct iface_combination_params params = { | ||
| 3314 | .radar_detect = radar_detect, | ||
| 3315 | }; | ||
| 3315 | 3316 | ||
| 3316 | lockdep_assert_held(&local->chanctx_mtx); | 3317 | lockdep_assert_held(&local->chanctx_mtx); |
| 3317 | 3318 | ||
| @@ -3322,9 +3323,6 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 4 unmodified lines | |||
| 3322 | !chandef->chan)) | 3323 | !chandef->chan)) |
| 3323 | return -EINVAL; | 3324 | return -EINVAL; |
| 3324 | 3325 | ||
| 3325 | if (chandef) | ||
| 3326 | num_different_channels = 1; | ||
| 3327 | |||
| 3328 | if (WARN_ON(iftype >= NUM_NL80211_IFTYPES)) | 3326 | if (WARN_ON(iftype >= NUM_NL80211_IFTYPES)) |
| 3329 | return -EINVAL; | 3327 | return -EINVAL; |
| 3330 | 3328 | ||
| @@ -3335,24 +3333,26 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 4 unmodified lines | |||
| 3335 | return 0; | 3333 | return 0; |
| 3336 | } | 3334 | } |
| 3337 | 3335 | ||
| 3338 | memset(num, 0, sizeof(num)); | 3336 | if (chandef) |
| 3337 | params.num_different_channels = 1; | ||
| 3339 | 3338 | ||
| 3340 | if (iftype != NL80211_IFTYPE_UNSPECIFIED) | 3339 | if (iftype != NL80211_IFTYPE_UNSPECIFIED) |
| 3341 | num[iftype] = 1; | 3340 | params.iftype_num[iftype] = 1; |
| 3342 | 3341 | ||
| 3343 | list_for_each_entry(ctx, &local->chanctx_list, list) { | 3342 | list_for_each_entry(ctx, &local->chanctx_list, list) { |
| 3344 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) | 3343 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) |
| 3345 | continue; | 3344 | continue; |
| 3346 | radar_detect |= ieee80211_chanctx_radar_detect(local, ctx); | 3345 | params.radar_detect |= |
| 3346 | ieee80211_chanctx_radar_detect(local, ctx); | ||
| 3347 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) { | 3347 | if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) { |
| 3348 | num_different_channels++; | 3348 | params.num_different_channels++; |
| 3349 | continue; | 3349 | continue; |
| 3350 | } | 3350 | } |
| 3351 | if (chandef && chanmode == IEEE80211_CHANCTX_SHARED && | 3351 | if (chandef && chanmode == IEEE80211_CHANCTX_SHARED && |
| 3352 | cfg80211_chandef_compatible(chandef, | 3352 | cfg80211_chandef_compatible(chandef, |
| 3353 | &ctx->conf.def)) | 3353 | &ctx->conf.def)) |
| 3354 | continue; | 3354 | continue; |
| 3355 | num_different_channels++; | 3355 | params.num_different_channels++; |
| 3356 | } | 3356 | } |
| 3357 | 3357 | ||
| 3358 | list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) { | 3358 | list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) { |
| @@ -3365,16 +3365,14 @@ int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, · 6 unmodified lines | |||
| 3365 | local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype)) | 3365 | local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype)) |
| 3366 | continue; | 3366 | continue; |
| 3367 | 3367 | ||
| 3368 | num[wdev_iter->iftype]++; | 3368 | params.iftype_num[wdev_iter->iftype]++; |
| 3369 | total++; | 3369 | total++; |
| 3370 | } | 3370 | } |
| 3371 | 3371 | ||
| 3372 | if (total == 1 && !radar_detect) | 3372 | if (total == 1 && !params.radar_detect) |
| 3373 | return 0; | 3373 | return 0; |
| 3374 | 3374 | ||
| 3375 | return cfg80211_check_combinations(local->hw.wiphy, | 3375 | return cfg80211_check_combinations(local->hw.wiphy, ¶ms); |
| 3376 | num_different_channels, | ||
| 3377 | radar_detect, num); | ||
| 3378 | } | 3376 | } |
| 3379 | 3377 | ||
| 3380 | static void | 3378 | static void |
| @@ -3390,12 +3388,10 @@ ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c, · 9 unmodified lines | |||
| 3390 | int ieee80211_max_num_channels(struct ieee80211_local *local) | 3388 | int ieee80211_max_num_channels(struct ieee80211_local *local) |
| 3391 | { | 3389 | { |
| 3392 | struct ieee80211_sub_if_data *sdata; | 3390 | struct ieee80211_sub_if_data *sdata; |
| 3393 | int num[NUM_NL80211_IFTYPES] = {}; | ||
| 3394 | struct ieee80211_chanctx *ctx; | 3391 | struct ieee80211_chanctx *ctx; |
| 3395 | int num_different_channels = 0; | ||
| 3396 | u8 radar_detect = 0; | ||
| 3397 | u32 max_num_different_channels = 1; | 3392 | u32 max_num_different_channels = 1; |
| 3398 | int err; | 3393 | int err; |
| 3394 | struct iface_combination_params params = {0}; | ||
| 3399 | 3395 | ||
| 3400 | lockdep_assert_held(&local->chanctx_mtx); | 3396 | lockdep_assert_held(&local->chanctx_mtx); |
| 3401 | 3397 | ||
| @@ -3403,17 +3399,17 @@ int ieee80211_max_num_channels(struct ieee80211_local *local) · 1 unmodified line | |||
| 3403 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) | 3399 | if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) |
| 3404 | continue; | 3400 | continue; |
| 3405 | 3401 | ||
| 3406 | num_different_channels++; | 3402 | params.num_different_channels++; |
| 3407 | 3403 | ||
| 3408 | radar_detect |= ieee80211_chanctx_radar_detect(local, ctx); | 3404 | params.radar_detect |= |
| 3405 | ieee80211_chanctx_radar_detect(local, ctx); | ||
| 3409 | } | 3406 | } |
| 3410 | 3407 | ||
| 3411 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | 3408 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 3412 | num[sdata->wdev.iftype]++; | 3409 | params.iftype_num[sdata->wdev.iftype]++; |
| 3413 | 3410 | ||
| 3414 | err = cfg80211_iter_combinations(local->hw.wiphy, | 3411 | err = cfg80211_iter_combinations(local->hw.wiphy, ¶ms, |
| 3415 | num_different_channels, radar_detect, | 3412 | ieee80211_iter_max_chans, |
| 3416 | num, ieee80211_iter_max_chans, | ||
| 3417 | &max_num_different_channels); | 3413 | &max_num_different_channels); |
| 3418 | if (err < 0) | 3414 | if (err < 0) |
| 3419 | return err; | 3415 | return err; |
| @@ -1580,9 +1580,7 @@ int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev, · 1579 unmodified lines | |||
| 1580 | } | 1580 | } |
| 1581 | 1581 | ||
| 1582 | int cfg80211_iter_combinations(struct wiphy *wiphy, | 1582 | int cfg80211_iter_combinations(struct wiphy *wiphy, |
| 1583 | const int num_different_channels, | 1583 | struct iface_combination_params *params, |
| 1584 | const u8 radar_detect, | ||
| 1585 | const int iftype_num[NUM_NL80211_IFTYPES], | ||
| 1586 | void (*iter)(const struct ieee80211_iface_combination *c, | 1584 | void (*iter)(const struct ieee80211_iface_combination *c, |
| 1587 | void *data), | 1585 | void *data), |
| 1588 | void *data) | 1586 | void *data) |
| @@ -1593,7 +1591,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 4 unmodified lines | |||
| 1593 | int num_interfaces = 0; | 1591 | int num_interfaces = 0; |
| 1594 | u32 used_iftypes = 0; | 1592 | u32 used_iftypes = 0; |
| 1595 | 1593 | ||
| 1596 | if (radar_detect) { | 1594 | if (params->radar_detect) { |
| 1597 | rcu_read_lock(); | 1595 | rcu_read_lock(); |
| 1598 | regdom = rcu_dereference(cfg80211_regdomain); | 1596 | regdom = rcu_dereference(cfg80211_regdomain); |
| 1599 | if (regdom) | 1597 | if (regdom) |
| @@ -1602,8 +1600,8 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 2 unmodified lines | |||
| 1602 | } | 1600 | } |
| 1603 | 1601 | ||
| 1604 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { | 1602 | for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) { |
| 1605 | num_interfaces += iftype_num[iftype]; | 1603 | num_interfaces += params->iftype_num[iftype]; |
| 1606 | if (iftype_num[iftype] > 0 && | 1604 | if (params->iftype_num[iftype] > 0 && |
| 1607 | !(wiphy->software_iftypes & BIT(iftype))) | 1605 | !(wiphy->software_iftypes & BIT(iftype))) |
| 1608 | used_iftypes |= BIT(iftype); | 1606 | used_iftypes |= BIT(iftype); |
| 1609 | } | 1607 | } |
| @@ -1617,7 +1615,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 7 unmodified lines | |||
| 1617 | 1615 | ||
| 1618 | if (num_interfaces > c->max_interfaces) | 1616 | if (num_interfaces > c->max_interfaces) |
| 1619 | continue; | 1617 | continue; |
| 1620 | if (num_different_channels > c->num_different_channels) | 1618 | if (params->num_different_channels > c->num_different_channels) |
| 1621 | continue; | 1619 | continue; |
| 1622 | 1620 | ||
| 1623 | limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits, | 1621 | limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits, |
| @@ -1632,16 +1630,17 @@ int cfg80211_iter_combinations(struct wiphy *wiphy, · 8 unmodified lines | |||
| 1632 | all_iftypes |= limits[j].types; | 1630 | all_iftypes |= limits[j].types; |
| 1633 | if (!(limits[j].types & BIT(iftype))) | 1631 | if (!(limits[j].types & BIT(iftype))) |
| 1634 | continue; | 1632 | continue; |
| 1635 | if (limits[j].max < iftype_num[iftype]) | 1633 | if (limits[j].max < params->iftype_num[iftype]) |
| 1636 | goto cont; | 1634 | goto cont; |
| 1637 | limits[j].max -= iftype_num[iftype]; | 1635 | limits[j].max -= params->iftype_num[iftype]; |
| 1638 | } | 1636 | } |
| 1639 | } | 1637 | } |
| 1640 | 1638 | ||
| 1641 | if (radar_detect != (c->radar_detect_widths & radar_detect)) | 1639 | if (params->radar_detect != |
| 1640 | (c->radar_detect_widths & params->radar_detect)) | ||
| 1642 | goto cont; | 1641 | goto cont; |
| 1643 | 1642 | ||
| 1644 | if (radar_detect && c->radar_detect_regions && | 1643 | if (params->radar_detect && c->radar_detect_regions && |
| 1645 | !(c->radar_detect_regions & BIT(region))) | 1644 | !(c->radar_detect_regions & BIT(region))) |
| 1646 | goto cont; | 1645 | goto cont; |
| 1647 | 1646 | ||
| @@ -1675,14 +1674,11 @@ cfg80211_iter_sum_ifcombs(const struct ieee80211_iface_combination *c, · 27 unmodified lines | |||
| 1675 | } | 1674 | } |
| 1676 | 1675 | ||
| 1677 | int cfg80211_check_combinations(struct wiphy *wiphy, | 1676 | int cfg80211_check_combinations(struct wiphy *wiphy, |
| 1678 | const int num_different_channels, | 1677 | struct iface_combination_params *params) |
| 1679 | const u8 radar_detect, | ||
| 1680 | const int iftype_num[NUM_NL80211_IFTYPES]) | ||
| 1681 | { | 1678 | { |
| 1682 | int err, num = 0; | 1679 | int err, num = 0; |
| 1683 | 1680 | ||
| 1684 | err = cfg80211_iter_combinations(wiphy, num_different_channels, | 1681 | err = cfg80211_iter_combinations(wiphy, params, |
| 1685 | radar_detect, iftype_num, | ||
| 1686 | cfg80211_iter_sum_ifcombs, &num); | 1682 | cfg80211_iter_sum_ifcombs, &num); |
| 1687 | if (err) | 1683 | if (err) |
| 1688 | return err; | 1684 | return err; |