Skip to content

Commit 41d16f7

Browse files
dberlinjannau
authored andcommitted
[brcmfmac] Fix regulatory domain handling to reset bands properly
Currently, we ignore the default country in the reg notifier. We also register a custom regulatory domain, which is set as the default. As a result, the chip is likely to be set to the correct country, but the regulatory domain will not match it. When the regulatory notifier is then called, we see the countries are the same and do not change anything, even though the domain is wrong. This patch forces us to reset the bands on the first country change even if the chip is already set to that country. We also restore the original band info before reconstructing channel info, as the new regdom power limits may be higher than what is currently set. Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
1 parent 72970e7 commit 41d16f7

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7236,18 +7236,34 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
72367236
goto fail_pbuf;
72377237
}
72387238

7239+
/* Changing regulatory domain may change power limits upwards.
7240+
* To ensure that we correctly set the new band info, copy the original
7241+
* info first.
7242+
*/
72397243
band = wiphy->bands[NL80211_BAND_2GHZ];
7240-
if (band)
7244+
if (band) {
7245+
memcpy(band->channels, &__wl_2ghz_channels,
7246+
sizeof(__wl_2ghz_channels));
7247+
band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
72417248
for (i = 0; i < band->n_channels; i++)
72427249
band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7250+
}
72437251
band = wiphy->bands[NL80211_BAND_5GHZ];
7244-
if (band)
7252+
if (band) {
7253+
memcpy(band->channels, &__wl_5ghz_channels,
7254+
sizeof(__wl_5ghz_channels));
7255+
band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
72457256
for (i = 0; i < band->n_channels; i++)
72467257
band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7258+
}
72477259
band = wiphy->bands[NL80211_BAND_6GHZ];
7248-
if (band)
7260+
if (band) {
7261+
memcpy(band->channels, &__wl_6ghz_channels,
7262+
sizeof(__wl_6ghz_channels));
7263+
band->n_channels = ARRAY_SIZE(__wl_6ghz_channels);
72497264
for (i = 0; i < band->n_channels; i++)
72507265
band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7266+
}
72517267
total = le32_to_cpu(list->count);
72527268
if (total > BRCMF_MAX_CHANSPEC_LIST) {
72537269
bphy_err(drvr, "Invalid count of channel Spec. (%u)\n",
@@ -8713,9 +8729,17 @@ static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
87138729
}
87148730

87158731
err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq);
8716-
if (err)
8717-
return;
8718-
8732+
if (err) {
8733+
/* Because we ignore the default country code above,
8734+
* we will start out in our custom reg domain, but the chip
8735+
* may already be set to the right country.
8736+
* As such, we force the bands to be re-set the first
8737+
* time we try to set a country for real.
8738+
*/
8739+
if (err != -EAGAIN || !cfg->force_band_setup)
8740+
return;
8741+
}
8742+
cfg->force_band_setup = false;
87198743
err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
87208744
if (err) {
87218745
bphy_err(drvr, "Firmware rejected country setting\n");
@@ -8782,6 +8806,7 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
87828806
cfg->pub = drvr;
87838807
init_vif_event(&cfg->vif_event);
87848808
INIT_LIST_HEAD(&cfg->vif_list);
8809+
cfg->force_band_setup = true;
87858810

87868811
vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION);
87878812
if (IS_ERR(vif))

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ struct brcmf_cfg80211_wowl {
327327
* @dongle_up: indicate whether dongle up or not.
328328
* @roam_on: on/off switch for dongle self-roaming.
329329
* @scan_tried: indicates if first scan attempted.
330+
* @force_band_setup: indicates if we should force band setup
330331
* @dcmd_buf: dcmd buffer.
331332
* @extra_buf: mainly to grab assoc information.
332333
* @debugfsdir: debugfs folder for this device.
@@ -357,6 +358,7 @@ struct brcmf_cfg80211_info {
357358
bool pwr_save;
358359
bool dongle_up;
359360
bool scan_tried;
361+
bool force_band_setup;
360362
u8 *dcmd_buf;
361363
u8 *extra_buf;
362364
struct dentry *debugfsdir;

0 commit comments

Comments
 (0)