Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp284947rda; Sat, 21 Oct 2023 07:41:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEm84TO/SESKbZT1fNBCDr6ND3bZnTkfBi+YYzPAfoxc7oehrl6zrVWpPhLtaFuoHObv0nG X-Received: by 2002:a17:902:f542:b0:1ca:8e43:765a with SMTP id h2-20020a170902f54200b001ca8e43765amr4616484plf.9.1697899303505; Sat, 21 Oct 2023 07:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697899303; cv=none; d=google.com; s=arc-20160816; b=EjOa0cHSIjWpfnYh+XVbtUEK+KVGrCsr2wZ2AD9/+yZDJMlnu8OveJavERTKEnVbDm aSh4R7k0/dxPj64biMHTst9PdgqEhwdF8zjQX9EjYH+PbJMJJp2dSZUkA9DdLX6yFfbG TZR+l6GebsZOGIPbiOCuNgBpi/27s+0pZ6brdex/XX5JW5E8Pvw6OTfZEpbN6Z+nLNvH TrVAvWue6RwY9Vu3FWwEaAP9esqe3Rf/I5kTsb/qTFgTs41JX5E6GnHEFcxfbe9vkOFv uLB+sKs9j5Ge7fKs2b9O3Hhjc5OBnpAybWmvN+6pjqmOwIG9MHCwpOWdZP5IxtCxSm98 yGvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=c4RGN71ke5T4dmY5Ao906sQxzaEaT/R/ELscOoI4tYI=; fh=4mNFSG45Han8obVdpZaezbubo8IaDiwKCCsQixaNGKg=; b=bhII0RfhZ1UcRQidoJ3jeVSF8NmcXaDS+3u2XYXeMehkq/8iQl5KUDPHf7fYGnZ+Vd DBJMUZPdkHCoO+GKlQzeWJNDCMgbFgsO2e+3M76Kji5M2IiJa6/JGzMI9TxKFi8t+9nR D8dS1xHEOcTURlxOzV8F710r6r+DRxCGoIdxvbhktf6k/+HTVI5pICpVN0BSjmQ93rac RjPc9U5IsQVx/zRivGYMbxvUZf70RGQY3lGGtvPhMka+xz0F2Bxv9yuvLsv0nqaXFFd4 TIoXqccxMps8Id9YR+9weTR/cFJ2Q8z35g0MnKanP94SDK49Rz5itUV8kF/v6BDitngl o4Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dberlin.org header.s=google header.b=EdnFsEOQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c17-20020a170903235100b001bb9375b349si641944plh.536.2023.10.21.07.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 07:41:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@dberlin.org header.s=google header.b=EdnFsEOQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id D8DC6805E42C; Sat, 21 Oct 2023 07:41:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbjJUOlC (ORCPT + 99 others); Sat, 21 Oct 2023 10:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231177AbjJUOlA (ORCPT ); Sat, 21 Oct 2023 10:41:00 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AF00D65 for ; Sat, 21 Oct 2023 07:40:54 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-507f1c29f25so140014e87.1 for ; Sat, 21 Oct 2023 07:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dberlin.org; s=google; t=1697899253; x=1698504053; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=c4RGN71ke5T4dmY5Ao906sQxzaEaT/R/ELscOoI4tYI=; b=EdnFsEOQl3gNbC/8mq9MNRTRN0NpZb5IYsyqijXwBTltjr3Ph8mgF+VpuWPNcJY8NJ 0LiekhZvsBiRCB5jj2tD4HrSKHWnkXC+98iuBaq9UjnXjGHSKygAa6eiPLVPXBZmnAOF /0YkTGS1qqSqWlQEHl0f/Kv5VdSwXtTa5pxFHGcGh7JYRujxneWGzQ1W8ZnUJs5UA/GJ M0/tyTybTqTqkKxCxQj4BUCRZb9M294Wu1We6d2ad/yqjU7MPoEbAoDBWZDq7kjRcuLF B8eM5BS9S9vyoNRfR/1trHKqMEfBwP3wdfVIwWM0ZDmVT5uCONHO7mWMfmTGXP7LbzY1 im0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697899253; x=1698504053; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c4RGN71ke5T4dmY5Ao906sQxzaEaT/R/ELscOoI4tYI=; b=VIdUvHbI7KvP5B8hgTx42F36t6Y8fQxGPWDGO9tyN9+obfy/9mgWsgoJT+xfmwtjw+ PV/4Mx8TK5bca9MHgXuYkRevd9o/GNZmfUs6Su4p+GoDtI6Tb16EmzUG1OVwIjyo9N0f IMXrrPZl8iH+XtT5Qk+xCByLJWGm+QbuEeTKS6JaMJqqiLyXC44W9XxQ4r/vGVVtR0Iq ppmbCQqfNhsawSIE911RkxQwPD96U1layMlbxZIuY+Cv2uik8SAUQyv604GfCY8Ffp6C SwGLcEcJhyE/g7zLuCmpQWAhj6FdLI1ai2sJ/4iF8NcCmCGy7BHmsEgm8lMOEWdXvRu9 L8uA== X-Gm-Message-State: AOJu0YyHUop9+QTNQH9GYhA1P89OUxCf/XcZQ0tpD8aHUIlybjX9WuAK ll8Ol5/nf1IL0LyzMm9ftrHlZfY0ZuUvFddhk7jkrw== X-Received: by 2002:ac2:43ab:0:b0:502:fe11:a68f with SMTP id t11-20020ac243ab000000b00502fe11a68fmr3625830lfl.28.1697899252363; Sat, 21 Oct 2023 07:40:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Daniel Berlin Date: Sat, 21 Oct 2023 10:40:41 -0400 Message-ID: Subject: Re: [PATCH 1/1] [brcmfmac] Fix regulatory domain handling to reset bands properly To: Arend van Spriel , Franky Lin , Hante Meuleman Cc: linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sat, 21 Oct 2023 07:41:39 -0700 (PDT) As an aside, the alternative would be to simply not ignore any attempts to set the regulatory domain, regardless of whether it's 00 or the chip is already set to that country. It doesn't happen that often, so it's not clear it's worth avoiding it at a= ll. There are some things i'd have to fix to make it work resiliently well (for example, i know we set the 2g bw cap where we do because it has to be done with the interface down), but i can fix those if needed. On Thu, Oct 19, 2023 at 10:18=E2=80=AFAM Daniel Berlin wrote: > > 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 > --- > .../broadcom/brcm80211/brcmfmac/cfg80211.c | 38 +++++++++++++++---- > .../broadcom/brcm80211/brcmfmac/cfg80211.h | 2 + > 2 files changed, 33 insertions(+), 7 deletions(-) > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c = b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > index 3656790ec4c9..7bc479ccc24b 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > @@ -7199,11 +7199,23 @@ static int brcmf_construct_chaninfo(struct brcmf_= cfg80211_info *cfg, > goto fail_pbuf; > } > > + /* Changing regulatory domain may change channels and limits > + * To ensure that we correctly set the new band info, copy the or= iginal > + * info first. > + */ > band =3D wiphy->bands[NL80211_BAND_2GHZ]; > - if (band) > + if (band) { > + memcpy(band->channels, &__wl_2ghz_channels, > + sizeof(__wl_2ghz_channels)); > + band->n_channels =3D ARRAY_SIZE(__wl_2ghz_channels); > for (i =3D 0; i < band->n_channels; i++) > band->channels[i].flags =3D IEEE80211_CHAN_DISABL= ED; > + } > band =3D wiphy->bands[NL80211_BAND_5GHZ]; > - if (band) > + if (band) { > + memcpy(band->channels, &__wl_5ghz_channels, > + sizeof(__wl_5ghz_channels)); > + band->n_channels =3D ARRAY_SIZE(__wl_5ghz_channels); > for (i =3D 0; i < band->n_channels; i++) > band->channels[i].flags =3D IEEE80211_CHAN_DISABL= ED; > + } > @@ -7210,8 +7222,11 @@ > band =3D wiphy->bands[NL80211_BAND_6GHZ]; > - if (band) > + if (band) { > + memcpy(band->channels, &__wl_6ghz_channels, > + sizeof(__wl_6ghz_channels)); > + band->n_channels =3D ARRAY_SIZE(__wl_6ghz_channels); > for (i =3D 0; i < band->n_channels; i++) > band->channels[i].flags =3D IEEE80211_CHAN_DISABL= ED; > - > + } > total =3D le32_to_cpu(list->count); > if (total > BRCMF_MAX_CHANSPEC_LIST) { > bphy_err(drvr, "Invalid count of channel Spec. (%u)\n", > @@ -8601,9 +8616,17 @@ static void brcmf_cfg80211_reg_notifier(struct wip= hy *wiphy, > } > > err =3D brcmf_translate_country_code(ifp->drvr, req->alpha2, &ccr= eq); > - if (err) > - return; > - > + if (err) { > + /* Because we ignore the default country code above, > + * we will start out in our custom reg domain, but the ch= ip > + * may already be set to the right country. > + * As such, we force the bands to be re-set the first > + * time we try to set a country for real. > + */ > + if (err !=3D -EAGAIN || !cfg->force_band_setup) > + return; > + } > + cfg->force_band_setup =3D false; > err =3D brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(c= creq)); > if (err) { > bphy_err(drvr, "Firmware rejected country setting\n"); > @@ -8670,6 +8693,7 @@ struct brcmf_cfg80211_info *brcmf_cfg80211_attach(s= truct brcmf_pub *drvr, > cfg->pub =3D drvr; > init_vif_event(&cfg->vif_event); > INIT_LIST_HEAD(&cfg->vif_list); > + cfg->force_band_setup =3D true; > > vif =3D brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION); > if (IS_ERR(vif)) > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h = b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h > index 0e1fa3f0dea2..7e60ceeeeb3a 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h > @@ -327,6 +327,7 @@ struct brcmf_cfg80211_wowl { > * @dongle_up: indicate whether dongle up or not. > * @roam_on: on/off switch for dongle self-roaming. > * @scan_tried: indicates if first scan attempted. > + * @force_band_setup: indicates if we should force band setup > * @dcmd_buf: dcmd buffer. > * @extra_buf: mainly to grab assoc information. > * @debugfsdir: debugfs folder for this device. > @@ -357,6 +358,7 @@ struct brcmf_cfg80211_info { > bool pwr_save; > bool dongle_up; > bool scan_tried; > + bool force_band_setup; > u8 *dcmd_buf; > u8 *extra_buf; > struct dentry *debugfsdir; > -- > 2.41.0 >