Skip to content

Commit 15a8f2f

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 a9f3258 commit 15a8f2f

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
@@ -7275,18 +7275,34 @@ static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
72757275
goto fail_pbuf;
72767276
}
72777277

7278+
/* Changing regulatory domain may change power limits upwards.
7279+
* To ensure that we correctly set the new band info, copy the original
7280+
* info first.
7281+
*/
72787282
band = wiphy->bands[NL80211_BAND_2GHZ];
7279-
if (band)
7283+
if (band) {
7284+
memcpy(band->channels, &__wl_2ghz_channels,
7285+
sizeof(__wl_2ghz_channels));
7286+
band->n_channels = ARRAY_SIZE(__wl_2ghz_channels);
72807287
for (i = 0; i < band->n_channels; i++)
72817288
band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7289+
}
72827290
band = wiphy->bands[NL80211_BAND_5GHZ];
7283-
if (band)
7291+
if (band) {
7292+
memcpy(band->channels, &__wl_5ghz_channels,
7293+
sizeof(__wl_5ghz_channels));
7294+
band->n_channels = ARRAY_SIZE(__wl_5ghz_channels);
72847295
for (i = 0; i < band->n_channels; i++)
72857296
band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7297+
}
72867298
band = wiphy->bands[NL80211_BAND_6GHZ];
7287-
if (band)
7299+
if (band) {
7300+
memcpy(band->channels, &__wl_6ghz_channels,
7301+
sizeof(__wl_6ghz_channels));
7302+
band->n_channels = ARRAY_SIZE(__wl_6ghz_channels);
72887303
for (i = 0; i < band->n_channels; i++)
72897304
band->channels[i].flags = IEEE80211_CHAN_DISABLED;
7305+
}
72907306
total = le32_to_cpu(list->count);
72917307
if (total > BRCMF_MAX_CHANSPEC_LIST) {
72927308
bphy_err(drvr, "Invalid count of channel Spec. (%u)\n",
@@ -8746,9 +8762,17 @@ static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
87468762
}
87478763

87488764
err = brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccreq);
8749-
if (err)
8750-
return;
8751-
8765+
if (err) {
8766+
/* Because we ignore the default country code above,
8767+
* we will start out in our custom reg domain, but the chip
8768+
* may already be set to the right country.
8769+
* As such, we force the bands to be re-set the first
8770+
* time we try to set a country for real.
8771+
*/
8772+
if (err != -EAGAIN || !cfg->force_band_setup)
8773+
return;
8774+
}
8775+
cfg->force_band_setup = false;
87528776
err = brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
87538777
if (err) {
87548778
bphy_err(drvr, "Firmware rejected country setting\n");
@@ -8815,6 +8839,7 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
88158839
cfg->pub = drvr;
88168840
init_vif_event(&cfg->vif_event);
88178841
INIT_LIST_HEAD(&cfg->vif_list);
8842+
cfg->force_band_setup = true;
88188843

88198844
vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION);
88208845
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
@@ -350,6 +350,7 @@ struct brcmf_cfg80211_wowl {
350350
* @dongle_up: indicate whether dongle up or not.
351351
* @roam_on: on/off switch for dongle self-roaming.
352352
* @scan_tried: indicates if first scan attempted.
353+
* @force_band_setup: indicates if we should force band setup
353354
* @dcmd_buf: dcmd buffer.
354355
* @extra_buf: mainly to grab assoc information.
355356
* @debugfsdir: debugfs folder for this device.
@@ -380,6 +381,7 @@ struct brcmf_cfg80211_info {
380381
bool pwr_save;
381382
bool dongle_up;
382383
bool scan_tried;
384+
bool force_band_setup;
383385
u8 *dcmd_buf;
384386
u8 *extra_buf;
385387
struct dentry *debugfsdir;

0 commit comments

Comments
 (0)