Skip to contentSkip to conversation

brcmfmac: provide country found in NVRAM as regulatory hint

RFC PATCH New Rafał Miłecki 1 participant 1 message Jan 6, 2016 Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 brcmfmac: provide country found in NVRAM as regulatory hint

NVRAM may contain info about device country. Example from SR40ac (US):
wl_country_code=US
wl0_country_code=US
wl1_country_code=US
or Netgear R8000 (Canada):
wl0_country_code=CA
wl1_country_code=CA
wl2_country_code=CA

Read it when parsing NVRAM and provide to regulatory.

---
This is HACKy code, do not apply!

Hi, I wanted to post this suggestion for improving brcmfmac. It's bothering OpenWrt users that have to set country manually.

This code is ugly. I think done callback is getting too complex and I don't like the way of referencing wiphy in pcie.c.

But it gives a basic idea and I'd like to see if there will be any comments.

---
 .../broadcom/brcm80211/brcmfmac/cfg80211.h         |  3 ++
 .../broadcom/brcm80211/brcmfmac/firmware.c         | 53 ++++++++++++++--------
 .../broadcom/brcm80211/brcmfmac/firmware.h         |  6 ++-
 .../wireless/broadcom/brcm80211/brcmfmac/pcie.c    | 16 ++++++-
 .../wireless/broadcom/brcm80211/brcmfmac/sdio.c    |  3 +-
 .../net/wireless/broadcom/brcm80211/brcmfmac/usb.c |  3 +-
 6 files changed, 59 insertions(+), 25 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h +3 -0
index c17b6d5..cb96f68 100644
@@ -20,6 +20,9 @@
 /* for brcmu_d11inf */
 #include <brcmu_d11.h>
 
+#include "fwil_types.h"
+#include "p2p.h"
+
 #define WL_NUM_SCAN_MAX			10
 #define WL_TLV_INFO_MAX			1024
 #define WL_BSS_INFO_MAX			2048
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c +34 -19

120 lines not on this page · raw message

drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h +4 -2
index ef06f57..963e929 100644
@@ -76,12 +76,14 @@ int brcmf_fw_get_firmwares_pcie(struct device *dev, u16 flags,
 				const char *code, const char *nvram,
 				void (*fw_cb)(struct device *dev,
 					      const struct firmware *fw,
-					      void *nvram_image, u32 nvram_len),
+					      void *nvram_image, u32 nvram_len,
+					      const char *alpha2),
 				u16 domain_nr, u16 bus_nr);
 int brcmf_fw_get_firmwares(struct device *dev, u16 flags,
 			   const char *code, const char *nvram,
 			   void (*fw_cb)(struct device *dev,
 					 const struct firmware *fw,
-					 void *nvram_image, u32 nvram_len));
+					 void *nvram_image, u32 nvram_len,
+					 const char *alpha2));
 
 #endif /* BRCMFMAC_FIRMWARE_H */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +14 -2
index 3d2d790..1980416 100644
@@ -1682,8 +1682,11 @@ static const struct brcmf_buscore_ops brcmf_pcie_buscore_ops = {
 	.write32 = brcmf_pcie_buscore_write32,
 };
 
+#include "core.h"
+#include "cfg80211.h"
+
 static void brcmf_pcie_setup(struct device *dev, const struct firmware *fw,
-			     void *nvram, u32 nvram_len)
+			     void *nvram, u32 nvram_len, const char *alpha2)
 {
 	struct brcmf_bus *bus = dev_get_drvdata(dev);
 	struct brcmf_pciedev *pcie_bus_dev = bus->bus_priv.pcie;
@@ -1734,8 +1737,17 @@ static void brcmf_pcie_setup(struct device *dev, const struct firmware *fw,
 	init_waitqueue_head(&devinfo->mbdata_resp_wait);
 
 	brcmf_pcie_intr_enable(devinfo);
-	if (brcmf_pcie_attach_bus(bus->dev) == 0)
+	if (brcmf_pcie_attach_bus(bus->dev) == 0) {
+		if (alpha2) {
+			struct brcmf_bus *bus_if = dev_get_drvdata(bus->dev);
+			struct brcmf_pub *drvr = bus_if->drvr;
+			struct brcmf_cfg80211_info *cfg = drvr->config;
+
+			regulatory_hint(cfg->wiphy, alpha2);
+		}
+
 		return;
+	}
 
 	brcmf_pcie_bus_console_read(devinfo);
 
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +2 -1
index ceb2a75..e8552ac 100644
@@ -3928,7 +3928,8 @@ static const struct brcmf_bus_ops brcmf_sdio_bus_ops = {
 
 static void brcmf_sdio_firmware_callback(struct device *dev,
 					 const struct firmware *code,
-					 void *nvram, u32 nvram_len)
+					 void *nvram, u32 nvram_len,
+					 const char *alpha2)
 {
 	struct brcmf_bus *bus_if = dev_get_drvdata(dev);
 	struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c +2 -1
index 66c26a9..78ae9d3 100644
@@ -1159,7 +1159,8 @@ fail:
 
 static void brcmf_usb_probe_phase2(struct device *dev,
 				   const struct firmware *fw,
-				   void *nvram, u32 nvlen)
+				   void *nvram, u32 nvlen,
+				   const char *alpha2)
 {
 	struct brcmf_bus *bus = dev_get_drvdata(dev);
 	struct brcmf_usbdev_info *devinfo;
Signature · 1 line
1.8.4.5