2021-04-08 11:31:17

by Shawn Guo

[permalink] [raw]
Subject: [PATCH 0/2] brcmfmac: support parse country code map from DT

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


2021-04-08 11:31:48

by Shawn Guo

[permalink] [raw]
Subject: [PATCH 2/2] brcmfmac: support parse country code map from DT

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 <[email protected]>
---
.../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

2021-04-12 08:23:59

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH 2/2] brcmfmac: support parse country code map from DT

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 <[email protected]>
> ---
> .../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

2021-04-13 09:31:36

by Shawn Guo

[permalink] [raw]
Subject: Re: [PATCH 2/2] brcmfmac: support parse country code map from DT

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 <[email protected]>

Thanks for reviewing, Arend.

> > Signed-off-by: Shawn Guo <[email protected]>
> > ---
> > .../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

2021-04-13 09:32:32

by Shawn Guo

[permalink] [raw]
Subject: Re: [PATCH 2/2] brcmfmac: support parse country code map from DT

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 <[email protected]>
> > ---
> > .../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

2021-04-13 09:34:25

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH 2/2] brcmfmac: support parse country code map from DT



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 <[email protected]>
>
> Thanks for reviewing, Arend.
>
>>> Signed-off-by: Shawn Guo <[email protected]>
>>> ---
>>> .../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