linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] brcmfmac: support parse country code map from DT
@ 2021-04-08 11:30 Shawn Guo
  2021-04-08 11:30 ` [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map Shawn Guo
  2021-04-08 11:30 ` [PATCH 2/2] brcmfmac: support parse country code map from DT Shawn Guo
  0 siblings, 2 replies; 16+ messages in thread
From: Shawn Guo @ 2021-04-08 11:30 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list,
	Shawn Guo

This is a couple of patches adding optional brcm,ccode-map bindings for
brcmfmac driver to parse country code map from DT.

Shawn Guo (2):
  dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  brcmfmac: support parse country code map from DT

 .../net/wireless/brcm,bcm43xx-fmac.txt        |  7 +++
 .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
 2 files changed, 60 insertions(+)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-08 11:30 [PATCH 0/2] brcmfmac: support parse country code map from DT Shawn Guo
@ 2021-04-08 11:30 ` Shawn Guo
  2021-04-09 18:46   ` Rob Herring
                     ` (2 more replies)
  2021-04-08 11:30 ` [PATCH 2/2] brcmfmac: support parse country code map from DT Shawn Guo
  1 sibling, 3 replies; 16+ messages in thread
From: Shawn Guo @ 2021-04-08 11:30 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list,
	Shawn Guo

Add optional brcm,ccode-map property to support translation from ISO3166
country code to brcmfmac firmware country code and revision.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
index cffb2d6876e3..a65ac4384c04 100644
--- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
+++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
@@ -15,6 +15,12 @@ Optional properties:
 	When not specified the device will use in-band SDIO interrupts.
  - interrupt-names : name of the out-of-band interrupt, which must be set
 	to "host-wake".
+ - brcm,ccode-map : multiple strings for translating ISO3166 country code to
+	brcmfmac firmware country code and revision.  Each string must be in
+	format "AA-BB-num" where:
+	  AA is the ISO3166 country code which must be 2 characters.
+	  BB is the firmware country code which must be 2 characters.
+	  num is the revision number which must fit into signed integer.
 
 Example:
 
@@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
 		interrupt-parent = <&pio>;
 		interrupts = <10 8>; /* PH10 / EINT10 */
 		interrupt-names = "host-wake";
+		brcm,ccode-map = "JP-JP-78", "US-Q2-86";
 	};
 };
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/2] brcmfmac: support parse country code map from DT
  2021-04-08 11:30 [PATCH 0/2] brcmfmac: support parse country code map from DT Shawn Guo
  2021-04-08 11:30 ` [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map Shawn Guo
@ 2021-04-08 11:30 ` Shawn Guo
  2021-04-12  8:09   ` Arend van Spriel
  2021-04-12  8:22   ` Arend van Spriel
  1 sibling, 2 replies; 16+ messages in thread
From: Shawn Guo @ 2021-04-08 11:30 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list,
	Shawn Guo

With any regulatory domain requests coming from either user space or
802.11 IE (Information Element), the country is coded in ISO3166
standard.  It needs to be translated to firmware country code and
revision with the mapping info in settings->country_codes table.
Support populate country_codes table by parsing the mapping from DT.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
index a7554265f95f..ea5c7f434c2c 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
@@ -12,12 +12,61 @@
 #include "common.h"
 #include "of.h"
 
+static int brcmf_of_get_country_codes(struct device *dev,
+				      struct brcmf_mp_device *settings)
+{
+	struct device_node *np = dev->of_node;
+	struct brcmfmac_pd_cc_entry *cce;
+	struct brcmfmac_pd_cc *cc;
+	int count;
+	int i;
+
+	count = of_property_count_strings(np, "brcm,ccode-map");
+	if (count < 0) {
+		/* The property is optional, so return success if it doesn't
+		 * exist. Otherwise propagate the error code.
+		 */
+		return (count == -EINVAL) ? 0 : count;
+	}
+
+	cc = devm_kzalloc(dev, sizeof(*cc) + count * sizeof(*cce), GFP_KERNEL);
+	if (!cc)
+		return -ENOMEM;
+
+	cc->table_size = count;
+
+	for (i = 0; i < count; i++) {
+		const char *map;
+		int ret;
+
+		cce = &cc->table[i];
+
+		if (of_property_read_string_index(np, "brcm,ccode-map",
+						  i, &map))
+			continue;
+
+		/* String format e.g. US-Q2-86 */
+		strncpy(cce->iso3166, map, 2);
+		strncpy(cce->cc, map + 3, 2);
+
+		ret = kstrtos32(map + 6, 10, &cce->rev);
+		if (ret < 0)
+			dev_warn(dev, "failed to read rev of map %s: %d",
+				 cce->iso3166, ret);
+	}
+
+	settings->country_codes = cc;
+
+	return 0;
+}
+
 void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
 		    struct brcmf_mp_device *settings)
 {
 	struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
 	struct device_node *root, *np = dev->of_node;
 	int irq;
+	int ret;
 	u32 irqf;
 	u32 val;
 
@@ -47,6 +96,10 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
 	    !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
 		return;
 
+	ret = brcmf_of_get_country_codes(dev, settings);
+	if (ret)
+		dev_warn(dev, "failed to get OF country code map\n");
+
 	if (of_property_read_u32(np, "brcm,drive-strength", &val) == 0)
 		sdio->drive_strength = val;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-08 11:30 ` [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map Shawn Guo
@ 2021-04-09 18:46   ` Rob Herring
  2021-04-12  1:19     ` Shawn Guo
  2021-04-13 12:43     ` Arend van Spriel
  2021-04-11  7:57   ` Kalle Valo
  2021-04-12  7:48   ` Arend van Spriel
  2 siblings, 2 replies; 16+ messages in thread
From: Rob Herring @ 2021-04-09 18:46 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Kalle Valo, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On Thu, Apr 08, 2021 at 07:30:21PM +0800, Shawn Guo wrote:
> Add optional brcm,ccode-map property to support translation from ISO3166
> country code to brcmfmac firmware country code and revision.
> 
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
>  .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
>  1 file changed, 7 insertions(+)

Can you convert this to schema first.

> 
> diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> index cffb2d6876e3..a65ac4384c04 100644
> --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> @@ -15,6 +15,12 @@ Optional properties:
>  	When not specified the device will use in-band SDIO interrupts.
>   - interrupt-names : name of the out-of-band interrupt, which must be set
>  	to "host-wake".
> + - brcm,ccode-map : multiple strings for translating ISO3166 country code to
> +	brcmfmac firmware country code and revision.  Each string must be in
> +	format "AA-BB-num" where:
> +	  AA is the ISO3166 country code which must be 2 characters.
> +	  BB is the firmware country code which must be 2 characters.
> +	  num is the revision number which must fit into signed integer.

Signed? So "AA-BB--num"?

You should be able to do something like:

items:
  pattern: '^[A-Z][A-Z]-[A-Z][A-Z]-[0-9]+$'

>  
>  Example:
>  
> @@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
>  		interrupt-parent = <&pio>;
>  		interrupts = <10 8>; /* PH10 / EINT10 */
>  		interrupt-names = "host-wake";
> +		brcm,ccode-map = "JP-JP-78", "US-Q2-86";
>  	};
>  };
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-08 11:30 ` [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map Shawn Guo
  2021-04-09 18:46   ` Rob Herring
@ 2021-04-11  7:57   ` Kalle Valo
  2021-04-12  1:25     ` Shawn Guo
  2021-04-12  7:48   ` Arend van Spriel
  2 siblings, 1 reply; 16+ messages in thread
From: Kalle Valo @ 2021-04-11  7:57 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

Shawn Guo <shawn.guo@linaro.org> writes:

> Add optional brcm,ccode-map property to support translation from ISO3166
> country code to brcmfmac firmware country code and revision.
>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
>  .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> index cffb2d6876e3..a65ac4384c04 100644
> --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> @@ -15,6 +15,12 @@ Optional properties:
>  	When not specified the device will use in-band SDIO interrupts.
>   - interrupt-names : name of the out-of-band interrupt, which must be set
>  	to "host-wake".
> + - brcm,ccode-map : multiple strings for translating ISO3166 country code to
> +	brcmfmac firmware country code and revision.  Each string must be in
> +	format "AA-BB-num" where:
> +	  AA is the ISO3166 country code which must be 2 characters.
> +	  BB is the firmware country code which must be 2 characters.
> +	  num is the revision number which must fit into signed integer.
>  
>  Example:
>  
> @@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
>  		interrupt-parent = <&pio>;
>  		interrupts = <10 8>; /* PH10 / EINT10 */
>  		interrupt-names = "host-wake";
> +		brcm,ccode-map = "JP-JP-78", "US-Q2-86";

The commit log does not answer "Why?". Why this needs to be in device
tree and, for example, not hard coded in the driver?

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-09 18:46   ` Rob Herring
@ 2021-04-12  1:19     ` Shawn Guo
  2021-04-13 12:43     ` Arend van Spriel
  1 sibling, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2021-04-12  1:19 UTC (permalink / raw)
  To: Rob Herring
  Cc: Kalle Valo, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On Fri, Apr 09, 2021 at 01:46:06PM -0500, Rob Herring wrote:
> On Thu, Apr 08, 2021 at 07:30:21PM +0800, Shawn Guo wrote:
> > Add optional brcm,ccode-map property to support translation from ISO3166
> > country code to brcmfmac firmware country code and revision.
> > 
> > Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> > ---
> >  .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
> >  1 file changed, 7 insertions(+)
> 
> Can you convert this to schema first.

Yes.  Will do, after driver maintainers agree with the direction.
> 
> > 
> > diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> > index cffb2d6876e3..a65ac4384c04 100644
> > --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> > +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> > @@ -15,6 +15,12 @@ Optional properties:
> >  	When not specified the device will use in-band SDIO interrupts.
> >   - interrupt-names : name of the out-of-band interrupt, which must be set
> >  	to "host-wake".
> > + - brcm,ccode-map : multiple strings for translating ISO3166 country code to
> > +	brcmfmac firmware country code and revision.  Each string must be in
> > +	format "AA-BB-num" where:
> > +	  AA is the ISO3166 country code which must be 2 characters.
> > +	  BB is the firmware country code which must be 2 characters.
> > +	  num is the revision number which must fit into signed integer.
> 
> Signed? So "AA-BB--num"?

Hmm, for some reason, kernel driver uses signed integer to hold the
revision.  It's just a reflecting of that.

> 
> You should be able to do something like:
> 
> items:
>   pattern: '^[A-Z][A-Z]-[A-Z][A-Z]-[0-9]+$'

Ah, yes, that's much better and distinct.  Thanks for the suggestion.

Shawn

> 
> >  
> >  Example:
> >  
> > @@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
> >  		interrupt-parent = <&pio>;
> >  		interrupts = <10 8>; /* PH10 / EINT10 */
> >  		interrupt-names = "host-wake";
> > +		brcm,ccode-map = "JP-JP-78", "US-Q2-86";
> >  	};
> >  };
> > -- 
> > 2.17.1
> > 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-11  7:57   ` Kalle Valo
@ 2021-04-12  1:25     ` Shawn Guo
  2021-04-12 11:54       ` Kalle Valo
  0 siblings, 1 reply; 16+ messages in thread
From: Shawn Guo @ 2021-04-12  1:25 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On Sun, Apr 11, 2021 at 10:57:54AM +0300, Kalle Valo wrote:
> Shawn Guo <shawn.guo@linaro.org> writes:
> 
> > Add optional brcm,ccode-map property to support translation from ISO3166
> > country code to brcmfmac firmware country code and revision.
> >
> > Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> > ---
> >  .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> > index cffb2d6876e3..a65ac4384c04 100644
> > --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> > +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> > @@ -15,6 +15,12 @@ Optional properties:
> >  	When not specified the device will use in-band SDIO interrupts.
> >   - interrupt-names : name of the out-of-band interrupt, which must be set
> >  	to "host-wake".
> > + - brcm,ccode-map : multiple strings for translating ISO3166 country code to
> > +	brcmfmac firmware country code and revision.  Each string must be in
> > +	format "AA-BB-num" where:
> > +	  AA is the ISO3166 country code which must be 2 characters.
> > +	  BB is the firmware country code which must be 2 characters.
> > +	  num is the revision number which must fit into signed integer.
> >  
> >  Example:
> >  
> > @@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
> >  		interrupt-parent = <&pio>;
> >  		interrupts = <10 8>; /* PH10 / EINT10 */
> >  		interrupt-names = "host-wake";
> > +		brcm,ccode-map = "JP-JP-78", "US-Q2-86";
> 
> The commit log does not answer "Why?". Why this needs to be in device
> tree and, for example, not hard coded in the driver?

Thanks for the comment, Kalle.  Actually, this is something I need some
input from driver maintainers.  I can see this country code mapping
table is chipset specific, and can be hard coded in driver per chip id
and revision.  But on the other hand, it makes some sense to have this
table in device tree, as the country code that need to be supported
could be a device specific configuration.

Shawn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-08 11:30 ` [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map Shawn Guo
  2021-04-09 18:46   ` Rob Herring
  2021-04-11  7:57   ` Kalle Valo
@ 2021-04-12  7:48   ` Arend van Spriel
  2 siblings, 0 replies; 16+ messages in thread
From: Arend van Spriel @ 2021-04-12  7:48 UTC (permalink / raw)
  To: Shawn Guo, Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On 08-04-2021 13:30, Shawn Guo wrote:
> Add optional brcm,ccode-map property to support translation from ISO3166
> country code to brcmfmac firmware country code and revision.

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
>   .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
>   1 file changed, 7 insertions(+)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] brcmfmac: support parse country code map from DT
  2021-04-08 11:30 ` [PATCH 2/2] brcmfmac: support parse country code map from DT Shawn Guo
@ 2021-04-12  8:09   ` Arend van Spriel
  2021-04-13  7:45     ` Shawn Guo
  2021-04-12  8:22   ` Arend van Spriel
  1 sibling, 1 reply; 16+ messages in thread
From: Arend van Spriel @ 2021-04-12  8:09 UTC (permalink / raw)
  To: Shawn Guo, Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On 08-04-2021 13:30, Shawn Guo wrote:
> With any regulatory domain requests coming from either user space or
> 802.11 IE (Information Element), the country is coded in ISO3166
> standard.  It needs to be translated to firmware country code and
> revision with the mapping info in settings->country_codes table.
> Support populate country_codes table by parsing the mapping from DT.

comment below, but you may add...

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
>   .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
>   1 file changed, 53 insertions(+)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> index a7554265f95f..ea5c7f434c2c 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c

[...]

> @@ -47,6 +96,10 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
>   	    !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
>   		return;
>   
> +	ret = brcmf_of_get_country_codes(dev, settings);
> +	if (ret)
> +		dev_warn(dev, "failed to get OF country code map\n");

First of all I prefer to use brcmf_err and add ret value to the print 
message " (err=%d)\n". Another thing is that this mapping is not only 
applicable for SDIO devices so you may consider doing this for other bus 
types as well which requires a bit more rework here.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] brcmfmac: support parse country code map from DT
  2021-04-08 11:30 ` [PATCH 2/2] brcmfmac: support parse country code map from DT Shawn Guo
  2021-04-12  8:09   ` Arend van Spriel
@ 2021-04-12  8:22   ` Arend van Spriel
  2021-04-13  7:46     ` Shawn Guo
  1 sibling, 1 reply; 16+ messages in thread
From: Arend van Spriel @ 2021-04-12  8:22 UTC (permalink / raw)
  To: Shawn Guo, Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On 08-04-2021 13:30, Shawn Guo wrote:
> With any regulatory domain requests coming from either user space or
> 802.11 IE (Information Element), the country is coded in ISO3166
> standard.  It needs to be translated to firmware country code and
> revision with the mapping info in settings->country_codes table.
> Support populate country_codes table by parsing the mapping from DT.

one more thing though...

> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> ---
>   .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
>   1 file changed, 53 insertions(+)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> index a7554265f95f..ea5c7f434c2c 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> @@ -12,12 +12,61 @@
>   #include "common.h"
>   #include "of.h"
>   
> +static int brcmf_of_get_country_codes(struct device *dev,
> +				      struct brcmf_mp_device *settings)
> +{

[...]

> +		/* String format e.g. US-Q2-86 */
> +		strncpy(cce->iso3166, map, 2);
> +		strncpy(cce->cc, map + 3, 2);
> +
> +		ret = kstrtos32(map + 6, 10, &cce->rev);
> +		if (ret < 0)
> +			dev_warn(dev, "failed to read rev of map %s: %d",
> +				 cce->iso3166, ret);

Do we need a stronger validation of the string format, eg. use sscanf or 
strstr. Would also be nice to have brcmf_dbg(INFO, ...) here to print 
the entry.

Regards,
Arend

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-12  1:25     ` Shawn Guo
@ 2021-04-12 11:54       ` Kalle Valo
  2021-04-13  7:28         ` Shawn Guo
  0 siblings, 1 reply; 16+ messages in thread
From: Kalle Valo @ 2021-04-12 11:54 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

Shawn Guo <shawn.guo@linaro.org> writes:

> On Sun, Apr 11, 2021 at 10:57:54AM +0300, Kalle Valo wrote:
>> Shawn Guo <shawn.guo@linaro.org> writes:
>> 
>> > Add optional brcm,ccode-map property to support translation from ISO3166
>> > country code to brcmfmac firmware country code and revision.
>> >
>> > Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
>> > ---
>> >  .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
>> >  1 file changed, 7 insertions(+)
>> >
>> > diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
>> > index cffb2d6876e3..a65ac4384c04 100644
>> > --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
>> > +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
>> > @@ -15,6 +15,12 @@ Optional properties:
>> >  	When not specified the device will use in-band SDIO interrupts.
>> >   - interrupt-names : name of the out-of-band interrupt, which must be set
>> >  	to "host-wake".
>> > + - brcm,ccode-map : multiple strings for translating ISO3166 country code to
>> > +	brcmfmac firmware country code and revision.  Each string must be in
>> > +	format "AA-BB-num" where:
>> > +	  AA is the ISO3166 country code which must be 2 characters.
>> > +	  BB is the firmware country code which must be 2 characters.
>> > +	  num is the revision number which must fit into signed integer.
>> >  
>> >  Example:
>> >  
>> > @@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
>> >  		interrupt-parent = <&pio>;
>> >  		interrupts = <10 8>; /* PH10 / EINT10 */
>> >  		interrupt-names = "host-wake";
>> > +		brcm,ccode-map = "JP-JP-78", "US-Q2-86";
>> 
>> The commit log does not answer "Why?". Why this needs to be in device
>> tree and, for example, not hard coded in the driver?
>
> Thanks for the comment, Kalle.  Actually, this is something I need some
> input from driver maintainers.  I can see this country code mapping
> table is chipset specific, and can be hard coded in driver per chip id
> and revision.  But on the other hand, it makes some sense to have this
> table in device tree, as the country code that need to be supported
> could be a device specific configuration.

Could be? Does such a use case exist at the moment or are just guessing
future needs?

From what I have learned so far I think this kind of data should be in
the driver, but of course I might be missing something.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-12 11:54       ` Kalle Valo
@ 2021-04-13  7:28         ` Shawn Guo
  0 siblings, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2021-04-13  7:28 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Rob Herring, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On Mon, Apr 12, 2021 at 02:54:46PM +0300, Kalle Valo wrote:
> Shawn Guo <shawn.guo@linaro.org> writes:
> 
> > On Sun, Apr 11, 2021 at 10:57:54AM +0300, Kalle Valo wrote:
> >> Shawn Guo <shawn.guo@linaro.org> writes:
> >> 
> >> > Add optional brcm,ccode-map property to support translation from ISO3166
> >> > country code to brcmfmac firmware country code and revision.
> >> >
> >> > Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> >> > ---
> >> >  .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
> >> >  1 file changed, 7 insertions(+)
> >> >
> >> > diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> >> > index cffb2d6876e3..a65ac4384c04 100644
> >> > --- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> >> > +++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt
> >> > @@ -15,6 +15,12 @@ Optional properties:
> >> >  	When not specified the device will use in-band SDIO interrupts.
> >> >   - interrupt-names : name of the out-of-band interrupt, which must be set
> >> >  	to "host-wake".
> >> > + - brcm,ccode-map : multiple strings for translating ISO3166 country code to
> >> > +	brcmfmac firmware country code and revision.  Each string must be in
> >> > +	format "AA-BB-num" where:
> >> > +	  AA is the ISO3166 country code which must be 2 characters.
> >> > +	  BB is the firmware country code which must be 2 characters.
> >> > +	  num is the revision number which must fit into signed integer.
> >> >  
> >> >  Example:
> >> >  
> >> > @@ -34,5 +40,6 @@ mmc3: mmc@1c12000 {
> >> >  		interrupt-parent = <&pio>;
> >> >  		interrupts = <10 8>; /* PH10 / EINT10 */
> >> >  		interrupt-names = "host-wake";
> >> > +		brcm,ccode-map = "JP-JP-78", "US-Q2-86";
> >> 
> >> The commit log does not answer "Why?". Why this needs to be in device
> >> tree and, for example, not hard coded in the driver?
> >
> > Thanks for the comment, Kalle.  Actually, this is something I need some
> > input from driver maintainers.  I can see this country code mapping
> > table is chipset specific, and can be hard coded in driver per chip id
> > and revision.  But on the other hand, it makes some sense to have this
> > table in device tree, as the country code that need to be supported
> > could be a device specific configuration.
> 
> Could be? Does such a use case exist at the moment or are just guessing
> future needs?

I hope that the patch [1] from Rafał (copied) is one use case.  And
also, the device I'm working on only needs to support some of the
countries in the mapping table. 

> 
> From what I have learned so far I think this kind of data should be in
> the driver, but of course I might be missing something.

I agree with you that such data are chipset specific and should ideally
be in the driver.  However, the brcmfmac driver implementation has been
taking the mapping table from platform_data [2][3], which is a logical
equivalent of DT data in case of booting with device tree.

Shawn

[1] https://gitlab.dai-labor.de/nadim/powquty-coap/-/blob/563b2bd658822375dcfa8e87707304b94de9901c/kernel/mac80211/patches/863-brcmfmac-add-in-driver-tables-with-country-codes.patch
[2] https://elixir.bootlin.com/linux/v5.12-rc7/source/include/linux/platform_data/brcmfmac.h#L154
[3] https://elixir.bootlin.com/linux/v5.12-rc7/source/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c#L433

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] brcmfmac: support parse country code map from DT
  2021-04-12  8:09   ` Arend van Spriel
@ 2021-04-13  7:45     ` Shawn Guo
  2021-04-13  8:10       ` Arend van Spriel
  0 siblings, 1 reply; 16+ messages in thread
From: Shawn Guo @ 2021-04-13  7:45 UTC (permalink / raw)
  To: Arend van Spriel
  Cc: Kalle Valo, Rob Herring, Rafał Miłecki,
	Arend van Spriel, Franky Lin, Hante Meuleman, Chi-hsien Lin,
	Wright Feng, Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On Mon, Apr 12, 2021 at 10:09:38AM +0200, Arend van Spriel wrote:
> On 08-04-2021 13:30, Shawn Guo wrote:
> > With any regulatory domain requests coming from either user space or
> > 802.11 IE (Information Element), the country is coded in ISO3166
> > standard.  It needs to be translated to firmware country code and
> > revision with the mapping info in settings->country_codes table.
> > Support populate country_codes table by parsing the mapping from DT.
> 
> comment below, but you may add...
> 
> Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>

Thanks for reviewing, Arend.

> > Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> > ---
> >   .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
> >   1 file changed, 53 insertions(+)
> > 
> > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> > index a7554265f95f..ea5c7f434c2c 100644
> > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> 
> [...]
> 
> > @@ -47,6 +96,10 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
> >   	    !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
> >   		return;
> > +	ret = brcmf_of_get_country_codes(dev, settings);
> > +	if (ret)
> > +		dev_warn(dev, "failed to get OF country code map\n");
> 
> First of all I prefer to use brcmf_err and add ret value to the print
> message " (err=%d)\n".

Okay.

> Another thing is that this mapping is not only
> applicable for SDIO devices so you may consider doing this for other bus
> types as well which requires a bit more rework here.

Right. I will take care of it, if we can convince Kalle that having
this data in DT is not such a bad idea.

Shawn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] brcmfmac: support parse country code map from DT
  2021-04-12  8:22   ` Arend van Spriel
@ 2021-04-13  7:46     ` Shawn Guo
  0 siblings, 0 replies; 16+ messages in thread
From: Shawn Guo @ 2021-04-13  7:46 UTC (permalink / raw)
  To: Arend van Spriel
  Cc: Kalle Valo, Rob Herring, Rafał Miłecki,
	Arend van Spriel, Franky Lin, Hante Meuleman, Chi-hsien Lin,
	Wright Feng, Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

On Mon, Apr 12, 2021 at 10:22:47AM +0200, Arend van Spriel wrote:
> On 08-04-2021 13:30, Shawn Guo wrote:
> > With any regulatory domain requests coming from either user space or
> > 802.11 IE (Information Element), the country is coded in ISO3166
> > standard.  It needs to be translated to firmware country code and
> > revision with the mapping info in settings->country_codes table.
> > Support populate country_codes table by parsing the mapping from DT.
> 
> one more thing though...
> 
> > Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
> > ---
> >   .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
> >   1 file changed, 53 insertions(+)
> > 
> > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> > index a7554265f95f..ea5c7f434c2c 100644
> > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
> > @@ -12,12 +12,61 @@
> >   #include "common.h"
> >   #include "of.h"
> > +static int brcmf_of_get_country_codes(struct device *dev,
> > +				      struct brcmf_mp_device *settings)
> > +{
> 
> [...]
> 
> > +		/* String format e.g. US-Q2-86 */
> > +		strncpy(cce->iso3166, map, 2);
> > +		strncpy(cce->cc, map + 3, 2);
> > +
> > +		ret = kstrtos32(map + 6, 10, &cce->rev);
> > +		if (ret < 0)
> > +			dev_warn(dev, "failed to read rev of map %s: %d",
> > +				 cce->iso3166, ret);
> 
> Do we need a stronger validation of the string format, eg. use sscanf or
> strstr. Would also be nice to have brcmf_dbg(INFO, ...) here to print the
> entry.

Sounds good to me for both comments.

Shawn

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/2] brcmfmac: support parse country code map from DT
  2021-04-13  7:45     ` Shawn Guo
@ 2021-04-13  8:10       ` Arend van Spriel
  0 siblings, 0 replies; 16+ messages in thread
From: Arend van Spriel @ 2021-04-13  8:10 UTC (permalink / raw)
  To: Shawn Guo
  Cc: Kalle Valo, Rob Herring, Rafał Miłecki,
	Arend van Spriel, Franky Lin, Hante Meuleman, Chi-hsien Lin,
	Wright Feng, Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list



On 13-04-2021 09:45, Shawn Guo wrote:
> On Mon, Apr 12, 2021 at 10:09:38AM +0200, Arend van Spriel wrote:
>> On 08-04-2021 13:30, Shawn Guo wrote:
>>> With any regulatory domain requests coming from either user space or
>>> 802.11 IE (Information Element), the country is coded in ISO3166
>>> standard.  It needs to be translated to firmware country code and
>>> revision with the mapping info in settings->country_codes table.
>>> Support populate country_codes table by parsing the mapping from DT.
>>
>> comment below, but you may add...
>>
>> Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
> 
> Thanks for reviewing, Arend.
> 
>>> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
>>> ---
>>>    .../wireless/broadcom/brcm80211/brcmfmac/of.c | 53 +++++++++++++++++++
>>>    1 file changed, 53 insertions(+)
>>>
>>> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
>>> index a7554265f95f..ea5c7f434c2c 100644
>>> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
>>> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
>>
>> [...]
>>
>>> @@ -47,6 +96,10 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
>>>    	    !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
>>>    		return;
>>> +	ret = brcmf_of_get_country_codes(dev, settings);
>>> +	if (ret)
>>> +		dev_warn(dev, "failed to get OF country code map\n");
>>
>> First of all I prefer to use brcmf_err and add ret value to the print
>> message " (err=%d)\n".
> 
> Okay.
> 
>> Another thing is that this mapping is not only
>> applicable for SDIO devices so you may consider doing this for other bus
>> types as well which requires a bit more rework here.
> 
> Right. I will take care of it, if we can convince Kalle that having
> this data in DT is not such a bad idea.

Sure. So let me explain a bit how our internal regulatory data is 
organized. The country revision is needed because the rf parameters that 
provide regulatory compliance are tweaked per platform/customer so 
depending on the rf path tight to the chip we need to use a certain 
country revision. As such they could be seen as device specific 
calibration data which is something that is already supported in the 
devicetree bindings.

Regards,
Arend

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map
  2021-04-09 18:46   ` Rob Herring
  2021-04-12  1:19     ` Shawn Guo
@ 2021-04-13 12:43     ` Arend van Spriel
  1 sibling, 0 replies; 16+ messages in thread
From: Arend van Spriel @ 2021-04-13 12:43 UTC (permalink / raw)
  To: Rob Herring, Shawn Guo
  Cc: Kalle Valo, Rafał Miłecki, Arend van Spriel,
	Franky Lin, Hante Meuleman, Chi-hsien Lin, Wright Feng,
	Chung-hsien Hsu, linux-wireless, netdev, devicetree,
	linux-kernel, brcm80211-dev-list.pdl, SHA-cyfmac-dev-list

[-- Attachment #1: Type: text/plain, Size: 1445 bytes --]

On 09-04-2021 20:46, Rob Herring wrote:
> On Thu, Apr 08, 2021 at 07:30:21PM +0800, Shawn Guo wrote:
>> Add optional brcm,ccode-map property to support translation from ISO3166
>> country code to brcmfmac firmware country code and revision.
>>
>> Signed-off-by: Shawn Guo<shawn.guo@linaro.org>
>> ---
>>   .../devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt | 7 +++++++
>>   1 file changed, 7 insertions(+)
> Can you convert this to schema first.
Hi Rob,

You mean to change it to YAML, right? You already applied a patch for 
that a few weeks ago:

https://lore.kernel.org/linux-devicetree/20210324174737.GA3319687@robh.at.kernel.org/

Regards,
Arend

-- 
This electronic communication and the information and any files transmitted 
with it, or attached to it, are confidential and are intended solely for 
the use of the individual or entity to whom it is addressed and may contain 
information that is confidential, legally privileged, protected by privacy 
laws, or otherwise restricted from disclosure to anyone else. If you are 
not the intended recipient or the person responsible for delivering the 
e-mail to the intended recipient, you are hereby notified that any use, 
copying, distributing, dissemination, forwarding, printing, or copying of 
this e-mail is strictly prohibited. If you received this e-mail in error, 
please return the e-mail to the sender, delete it from your computer, and 
destroy any printed copy of it.

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4219 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-04-13 12:44 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 11:30 [PATCH 0/2] brcmfmac: support parse country code map from DT Shawn Guo
2021-04-08 11:30 ` [PATCH 1/2] dt-binding: bcm43xx-fmac: add optional brcm,ccode-map Shawn Guo
2021-04-09 18:46   ` Rob Herring
2021-04-12  1:19     ` Shawn Guo
2021-04-13 12:43     ` Arend van Spriel
2021-04-11  7:57   ` Kalle Valo
2021-04-12  1:25     ` Shawn Guo
2021-04-12 11:54       ` Kalle Valo
2021-04-13  7:28         ` Shawn Guo
2021-04-12  7:48   ` Arend van Spriel
2021-04-08 11:30 ` [PATCH 2/2] brcmfmac: support parse country code map from DT Shawn Guo
2021-04-12  8:09   ` Arend van Spriel
2021-04-13  7:45     ` Shawn Guo
2021-04-13  8:10       ` Arend van Spriel
2021-04-12  8:22   ` Arend van Spriel
2021-04-13  7:46     ` Shawn Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).