From: Tomasz Maciej Nowak Date: Mon, 20 Jun 2022 12:50:23 +0000 (+0200) Subject: mac80211: brcmfmac: allow setting MAC from NVMEM cells X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=946e42ed89075b6c92749d7f82631331b9109edd;p=openwrt%2Fstaging%2Fynezz.git mac80211: brcmfmac: allow setting MAC from NVMEM cells The MAC can be stored in OTP memory or in flash memory, currently the driver could read it only from OTP. Backport the patch allowing setting the MAC address from flash. Some modules have the OTP programmed but the ODM/OEM decided to overwrite it with value stored in flash. Signed-off-by: Tomasz Maciej Nowak --- diff --git a/package/kernel/mac80211/patches/brcm/001-brcmfmac-allow-setting-wlan-MAC-address-using-device.patch b/package/kernel/mac80211/patches/brcm/001-brcmfmac-allow-setting-wlan-MAC-address-using-device.patch new file mode 100644 index 0000000000..03d9f8ecd8 --- /dev/null +++ b/package/kernel/mac80211/patches/brcm/001-brcmfmac-allow-setting-wlan-MAC-address-using-device.patch @@ -0,0 +1,103 @@ +From 716c220b4d990a4fe7800d0685ca69dee99e4e8f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Pavel=20L=C3=B6bl?= +Date: Fri, 6 May 2022 06:42:46 +0200 +Subject: [PATCH] brcmfmac: allow setting wlan MAC address using device tree +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This allows firmware to provide MAC address using device tree. Like in +case there is no MAC burned in wlan NVRAM. + +Signed-off-by: Pavel Löbl +Signed-off-by: Kalle Valo +Link: https://lore.kernel.org/r/20220506044246.67146-1-pavel@loebl.cz +--- + .../broadcom/brcm80211/brcmfmac/common.c | 23 ++++++++++++++----- + .../broadcom/brcm80211/brcmfmac/common.h | 1 + + .../broadcom/brcm80211/brcmfmac/core.c | 4 +++- + .../wireless/broadcom/brcm80211/brcmfmac/of.c | 3 +++ + 4 files changed, 24 insertions(+), 7 deletions(-) + +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c +@@ -202,13 +202,24 @@ int brcmf_c_preinit_dcmds(struct brcmf_i + char *ptr; + s32 err; + +- /* retreive mac address */ +- err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr, +- sizeof(ifp->mac_addr)); +- if (err < 0) { +- bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err); +- goto done; ++ if (is_valid_ether_addr(ifp->mac_addr)) { ++ /* set mac address */ ++ err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", ifp->mac_addr, ++ ETH_ALEN); ++ if (err < 0) { ++ bphy_err(ifp->drvr, "Setting cur_etheraddr failed, %d\n", err); ++ goto done; ++ } ++ } else { ++ /* retrieve mac address */ ++ err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr, ++ sizeof(ifp->mac_addr)); ++ if (err < 0) { ++ bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err); ++ goto done; ++ } + } ++ + memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac)); + memcpy(ifp->drvr->wiphy->perm_addr, ifp->drvr->mac, ETH_ALEN); + +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h +@@ -50,6 +50,7 @@ struct brcmf_mp_device { + bool ignore_probe_fail; + struct brcmfmac_pd_cc *country_codes; + const char *board_type; ++ unsigned char mac[ETH_ALEN]; + union { + struct brcmfmac_sdio_pd sdio; + } bus; +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -1226,7 +1227,8 @@ static int brcmf_bus_started(struct brcm + brcmf_dbg(TRACE, "\n"); + + /* add primary networking interface */ +- ifp = brcmf_add_if(drvr, 0, 0, false, "wlan%d", NULL); ++ ifp = brcmf_add_if(drvr, 0, 0, false, "wlan%d", ++ is_valid_ether_addr(drvr->settings->mac) ? drvr->settings->mac : NULL); + if (IS_ERR(ifp)) + return PTR_ERR(ifp); + +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +@@ -5,6 +5,7 @@ + #include + #include + #include ++#include + + #include + #include "debug.h" +@@ -97,6 +98,8 @@ void brcmf_of_probe(struct device *dev, + if (err) + brcmf_err("failed to get OF country code map (err=%d)\n", err); + ++ of_get_mac_address(np, settings->mac); ++ + if (bus_type != BRCMF_BUSTYPE_SDIO) + return; + diff --git a/package/kernel/mac80211/patches/brcm/863-brcmfmac-add-in-driver-tables-with-country-codes.patch b/package/kernel/mac80211/patches/brcm/863-brcmfmac-add-in-driver-tables-with-country-codes.patch index 835c870a65..1ddc78f7ca 100644 --- a/package/kernel/mac80211/patches/brcm/863-brcmfmac-add-in-driver-tables-with-country-codes.patch +++ b/package/kernel/mac80211/patches/brcm/863-brcmfmac-add-in-driver-tables-with-country-codes.patch @@ -12,7 +12,7 @@ Signed-off-by: Rafał Miłecki --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c -@@ -58,6 +58,36 @@ static int brcmf_of_get_country_codes(st +@@ -59,6 +59,36 @@ static int brcmf_of_get_country_codes(st return 0; } @@ -49,7 +49,7 @@ Signed-off-by: Rafał Miłecki void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type, struct brcmf_mp_device *settings) { -@@ -90,6 +120,8 @@ void brcmf_of_probe(struct device *dev, +@@ -91,6 +121,8 @@ void brcmf_of_probe(struct device *dev, of_node_put(root); } diff --git a/package/kernel/mac80211/patches/brcm/998-survey.patch b/package/kernel/mac80211/patches/brcm/998-survey.patch index a5efc08015..d194e25177 100644 --- a/package/kernel/mac80211/patches/brcm/998-survey.patch +++ b/package/kernel/mac80211/patches/brcm/998-survey.patch @@ -100,7 +100,7 @@ .add_key = brcmf_cfg80211_add_key, --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c -@@ -1361,6 +1361,8 @@ int brcmf_attach(struct device *dev) +@@ -1363,6 +1363,8 @@ int brcmf_attach(struct device *dev) /* Link to bus module */ drvr->hdrlen = 0; @@ -109,7 +109,7 @@ /* Attach and link in the protocol */ ret = brcmf_proto_attach(drvr); -@@ -1443,6 +1445,12 @@ void brcmf_detach(struct device *dev) +@@ -1445,6 +1447,12 @@ void brcmf_detach(struct device *dev) if (drvr == NULL) return;