2022-07-11 12:34:13

by Alvin Šipraga

[permalink] [raw]
Subject: [PATCH 0/2] wifi: brcmfmac: add DT property for trivial ccode mapping

From: Alvin Šipraga <[email protected]>

Previous commits introduced a fallback mechanism for translating the
in-kernel ISO3166 country code to the in-firmware country code +
revision pair. The mechanism is dependent on the common chip core ID and
enabled only for a few specific chipsets.

But the in-firmware country code/revision is actually a function of the CLM
blob, not the chip core. Indeed, while it was reported that the fallback
mechanism causes regressions on a board with a chip identified by the
driver as BCM4359, we too have such a board with a BCM4359-identified
chip, and in our case we really do want to use this fallback mechanism.
Put another way, our CLM blob is using ISO3166 country codes, and the
revision is always 0.

Since this is evidently a property of the firmware, it would be nice to
be able to specify this in the device tree, since the driver has no
general mechanism for finding out based on the hardware type alone. This
series adds such a property: brcm,ccode-map-trivial.


Alvin Šipraga (2):
dt-bindings: bcm4329-fmac: add optional brcm,ccode-map-trivial
wifi: brcmfmac: support brcm,ccode-map-trivial DT property

.../bindings/net/wireless/brcm,bcm4329-fmac.yaml | 10 ++++++++++
.../wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 3 +++
.../net/wireless/broadcom/brcm80211/brcmfmac/common.h | 2 ++
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 6 ++++++
4 files changed, 21 insertions(+)

--
2.37.0


2022-07-11 12:34:16

by Alvin Šipraga

[permalink] [raw]
Subject: [PATCH 1/2] dt-bindings: bcm4329-fmac: add optional brcm,ccode-map-trivial

From: Alvin Šipraga <[email protected]>

The bindings already offer a brcm,ccode-map property to describe the
mapping between the kernel's ISO3166 alpha 2 country code string and the
firmware's country code string and revision number. This is a
board-specific property and determined by the CLM blob firmware provided
by the hardware vendor.

However, in some cases the firmware will also use ISO3166 country codes
internally, and the revision will always be zero. This implies a trivial
mapping: cc -> { cc, 0 }.

For such cases, add an optional property brcm,ccode-map-trivial which
obviates the need to describe every trivial country code mapping in the
device tree with the existing brcm,ccode-map property. The new property
is subordinate to the more explicit brcm,ccode-map property.

Signed-off-by: Alvin Šipraga <[email protected]>
---
.../bindings/net/wireless/brcm,bcm4329-fmac.yaml | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml
index c11f23b20c4c..53b4153d9bfc 100644
--- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml
+++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml
@@ -75,6 +75,16 @@ properties:
items:
pattern: '^[A-Z][A-Z]-[A-Z][0-9A-Z]-[0-9]+$'

+ brcm,ccode-map-trivial:
+ description: |
+ Use a trivial mapping of ISO3166 country codes to brcmfmac firmware
+ country code and revision: cc -> { cc, 0 }. In other words, assume that
+ the CLM blob firmware uses ISO3166 country codes as well, and that all
+ revisions are zero. This property is mutually exclusive with
+ brcm,ccode-map. If both properties are specified, then brcm,ccode-map
+ takes precedence.
+ type: boolean
+
required:
- compatible
- reg
--
2.37.0

2022-07-11 12:34:37

by Alvin Šipraga

[permalink] [raw]
Subject: [PATCH 2/2] wifi: brcmfmac: support brcm,ccode-map-trivial DT property

From: Alvin Šipraga <[email protected]>

Commit a21bf90e927f ("brcmfmac: use ISO3166 country code and 0 rev as
fallback on some devices") introduced a fallback mechanism whereby a
trivial mapping from ISO3166 country codes to firmware country code and
revision is used on some devices. This fallback operates on the device
level, so it is enabled only for certain supported chipsets.

In general though, the firmware country codes are determined by the CLM
blob, which is board-specific and may vary despite the underlying
chipset being the same.

The aforementioned commit is actually a refinement of a previous commit
that was reverted in commit 151a7c12c4fc ("Revert "brcmfmac: use ISO3166
country code and 0 rev as fallback"") due to regressions with a BCM4359
device. The refinement restricted the fallback mechanism to specific
chipsets such as the BCM4345.

We use a chipset - CYW88359 - that the driver identifies as a BCM4359
too. But in our case, the CLM blob uses ISO3166 country codes
internally, and all with revision 0. So the trivial mapping is exactly
what is needed in order for the driver to sync the kernel regulatory
domain to the firmware. This is just a matter of how the CLM blob was
prepared by the hardware vendor. The same could hold for other boards
too.

Although the brcm,ccode-map device tree property is useful for cases
where the mapping is more complex, the trivial case invites a much
simpler specification. This patch adds support for parsing the
brcm,ccode-map-trivial device tree property. Subordinate to the more
specific brcm,ccode-map property, this new proprety simply informs the
driver that the fallback method should be used in every case.

In the absence of the new property in the device tree, expect no
functional change.

Signed-off-by: Alvin Šipraga <[email protected]>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 3 +++
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h | 2 ++
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 6 ++++++
3 files changed, 11 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
index 3ae6779fe153..db45da33adfd 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
@@ -7481,6 +7481,9 @@ int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,

static bool brmcf_use_iso3166_ccode_fallback(struct brcmf_pub *drvr)
{
+ if (drvr->settings->trivial_ccode_map)
+ return true;
+
switch (drvr->bus_if->chip) {
case BRCM_CC_4345_CHIP_ID:
case BRCM_CC_43602_CHIP_ID:
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
index 15accc88d5c0..fe717cce5d55 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
@@ -38,6 +38,7 @@ extern struct brcmf_mp_global_t brcmf_mp_global;
* @fcmode: FWS flow control.
* @roamoff: Firmware roaming off?
* @ignore_probe_fail: Ignore probe failure.
+ * @trivial_ccode_map: Assume firmware uses ISO3166 country codes with rev 0
* @country_codes: If available, pointer to struct for translating country codes
* @bus: Bus specific platform data. Only SDIO at the mmoment.
*/
@@ -48,6 +49,7 @@ struct brcmf_mp_device {
bool roamoff;
bool iapp;
bool ignore_probe_fail;
+ bool trivial_ccode_map;
struct brcmfmac_pd_cc *country_codes;
const char *board_type;
unsigned char mac[ETH_ALEN];
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
index 083ac58f466d..1add942462f8 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
@@ -24,6 +24,12 @@ static int brcmf_of_get_country_codes(struct device *dev,

count = of_property_count_strings(np, "brcm,ccode-map");
if (count < 0) {
+ /* If no explicit country code map is specified, check whether
+ * the trivial map should be used.
+ */
+ settings->trivial_ccode_map =
+ of_property_read_bool(np, "brcm,ccode-map-trivial");
+
/* The property is optional, so return success if it doesn't
* exist. Otherwise propagate the error code.
*/
--
2.37.0

2022-07-14 15:25:30

by Ahmad Fatoum

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: bcm4329-fmac: add optional brcm,ccode-map-trivial

On 11.07.22 14:30, Alvin Šipraga wrote:
> From: Alvin Šipraga <[email protected]>
>
> The bindings already offer a brcm,ccode-map property to describe the
> mapping between the kernel's ISO3166 alpha 2 country code string and the
> firmware's country code string and revision number. This is a
> board-specific property and determined by the CLM blob firmware provided
> by the hardware vendor.
>
> However, in some cases the firmware will also use ISO3166 country codes
> internally, and the revision will always be zero. This implies a trivial
> mapping: cc -> { cc, 0 }.
>
> For such cases, add an optional property brcm,ccode-map-trivial which
> obviates the need to describe every trivial country code mapping in the
> device tree with the existing brcm,ccode-map property. The new property
> is subordinate to the more explicit brcm,ccode-map property.
>
> Signed-off-by: Alvin Šipraga <[email protected]>

Reviewed-by: Ahmad Fatoum <[email protected]>

> ---
> .../bindings/net/wireless/brcm,bcm4329-fmac.yaml | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml
> index c11f23b20c4c..53b4153d9bfc 100644
> --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml
> +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml
> @@ -75,6 +75,16 @@ properties:
> items:
> pattern: '^[A-Z][A-Z]-[A-Z][0-9A-Z]-[0-9]+$'
>
> + brcm,ccode-map-trivial:
> + description: |
> + Use a trivial mapping of ISO3166 country codes to brcmfmac firmware
> + country code and revision: cc -> { cc, 0 }. In other words, assume that
> + the CLM blob firmware uses ISO3166 country codes as well, and that all
> + revisions are zero. This property is mutually exclusive with
> + brcm,ccode-map. If both properties are specified, then brcm,ccode-map
> + takes precedence.
> + type: boolean
> +
> required:
> - compatible
> - reg


--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2022-07-14 15:25:37

by Ahmad Fatoum

[permalink] [raw]
Subject: Re: [PATCH 2/2] wifi: brcmfmac: support brcm,ccode-map-trivial DT property

On 11.07.22 14:30, Alvin Šipraga wrote:
> From: Alvin Šipraga <[email protected]>
>
> Commit a21bf90e927f ("brcmfmac: use ISO3166 country code and 0 rev as
> fallback on some devices") introduced a fallback mechanism whereby a
> trivial mapping from ISO3166 country codes to firmware country code and
> revision is used on some devices. This fallback operates on the device
> level, so it is enabled only for certain supported chipsets.
>
> In general though, the firmware country codes are determined by the CLM
> blob, which is board-specific and may vary despite the underlying
> chipset being the same.
>
> The aforementioned commit is actually a refinement of a previous commit
> that was reverted in commit 151a7c12c4fc ("Revert "brcmfmac: use ISO3166
> country code and 0 rev as fallback"") due to regressions with a BCM4359
> device. The refinement restricted the fallback mechanism to specific
> chipsets such as the BCM4345.
>
> We use a chipset - CYW88359 - that the driver identifies as a BCM4359
> too. But in our case, the CLM blob uses ISO3166 country codes
> internally, and all with revision 0. So the trivial mapping is exactly
> what is needed in order for the driver to sync the kernel regulatory
> domain to the firmware. This is just a matter of how the CLM blob was
> prepared by the hardware vendor. The same could hold for other boards
> too.
>
> Although the brcm,ccode-map device tree property is useful for cases
> where the mapping is more complex, the trivial case invites a much
> simpler specification. This patch adds support for parsing the
> brcm,ccode-map-trivial device tree property. Subordinate to the more
> specific brcm,ccode-map property, this new proprety simply informs the
> driver that the fallback method should be used in every case.
>
> In the absence of the new property in the device tree, expect no
> functional change.
>
> Signed-off-by: Alvin Šipraga <[email protected]>

Reviewed-by: Ahmad Fatoum <[email protected]>

> ---
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 3 +++
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h | 2 ++
> drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 6 ++++++
> 3 files changed, 11 insertions(+)
>
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
> index 3ae6779fe153..db45da33adfd 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
> @@ -7481,6 +7481,9 @@ int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
>
> static bool brmcf_use_iso3166_ccode_fallback(struct brcmf_pub *drvr)
> {
> + if (drvr->settings->trivial_ccode_map)
> + return true;
> +
> switch (drvr->bus_if->chip) {
> case BRCM_CC_4345_CHIP_ID:
> case BRCM_CC_43602_CHIP_ID:
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
> index 15accc88d5c0..fe717cce5d55 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
> @@ -38,6 +38,7 @@ extern struct brcmf_mp_global_t brcmf_mp_global;
> * @fcmode: FWS flow control.
> * @roamoff: Firmware roaming off?
> * @ignore_probe_fail: Ignore probe failure.
> + * @trivial_ccode_map: Assume firmware uses ISO3166 country codes with rev 0
> * @country_codes: If available, pointer to struct for translating country codes
> * @bus: Bus specific platform data. Only SDIO at the mmoment.
> */
> @@ -48,6 +49,7 @@ struct brcmf_mp_device {
> bool roamoff;
> bool iapp;
> bool ignore_probe_fail;
> + bool trivial_ccode_map;
> struct brcmfmac_pd_cc *country_codes;
> const char *board_type;
> unsigned char mac[ETH_ALEN];
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> index 083ac58f466d..1add942462f8 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> @@ -24,6 +24,12 @@ static int brcmf_of_get_country_codes(struct device *dev,
>
> count = of_property_count_strings(np, "brcm,ccode-map");
> if (count < 0) {
> + /* If no explicit country code map is specified, check whether
> + * the trivial map should be used.
> + */
> + settings->trivial_ccode_map =
> + of_property_read_bool(np, "brcm,ccode-map-trivial");
> +
> /* The property is optional, so return success if it doesn't
> * exist. Otherwise propagate the error code.
> */


--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

2022-07-18 18:57:51

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: bcm4329-fmac: add optional brcm,ccode-map-trivial

On Mon, 11 Jul 2022 14:30:03 +0200, Alvin Šipraga wrote:
> From: Alvin Šipraga <[email protected]>
>
> The bindings already offer a brcm,ccode-map property to describe the
> mapping between the kernel's ISO3166 alpha 2 country code string and the
> firmware's country code string and revision number. This is a
> board-specific property and determined by the CLM blob firmware provided
> by the hardware vendor.
>
> However, in some cases the firmware will also use ISO3166 country codes
> internally, and the revision will always be zero. This implies a trivial
> mapping: cc -> { cc, 0 }.
>
> For such cases, add an optional property brcm,ccode-map-trivial which
> obviates the need to describe every trivial country code mapping in the
> device tree with the existing brcm,ccode-map property. The new property
> is subordinate to the more explicit brcm,ccode-map property.
>
> Signed-off-by: Alvin Šipraga <[email protected]>
> ---
> .../bindings/net/wireless/brcm,bcm4329-fmac.yaml | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>

Acked-by: Rob Herring <[email protected]>

2022-07-28 10:06:13

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: bcm4329-fmac: add optional brcm,ccode-map-trivial

Alvin Šipraga <[email protected]> wrote:

> From: Alvin Šipraga <[email protected]>
>
> The bindings already offer a brcm,ccode-map property to describe the
> mapping between the kernel's ISO3166 alpha 2 country code string and the
> firmware's country code string and revision number. This is a
> board-specific property and determined by the CLM blob firmware provided
> by the hardware vendor.
>
> However, in some cases the firmware will also use ISO3166 country codes
> internally, and the revision will always be zero. This implies a trivial
> mapping: cc -> { cc, 0 }.
>
> For such cases, add an optional property brcm,ccode-map-trivial which
> obviates the need to describe every trivial country code mapping in the
> device tree with the existing brcm,ccode-map property. The new property
> is subordinate to the more explicit brcm,ccode-map property.
>
> Signed-off-by: Alvin Šipraga <[email protected]>
> Reviewed-by: Ahmad Fatoum <[email protected]>
> Acked-by: Rob Herring <[email protected]>

2 patches applied to wireless-next.git, thanks.

8406993a891f dt-bindings: bcm4329-fmac: add optional brcm,ccode-map-trivial
5c54ab24377b wifi: brcmfmac: support brcm,ccode-map-trivial DT property

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches