1 From 716c220b4d990a4fe7800d0685ca69dee99e4e8f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pavel=20L=C3=B6bl?= <pavel@loebl.cz>
3 Date: Fri, 6 May 2022 06:42:46 +0200
4 Subject: [PATCH] brcmfmac: allow setting wlan MAC address using device tree
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This allows firmware to provide MAC address using device tree. Like in
10 case there is no MAC burned in wlan NVRAM.
12 Signed-off-by: Pavel Löbl <pavel@loebl.cz>
13 Signed-off-by: Kalle Valo <kvalo@kernel.org>
14 Link: https://lore.kernel.org/r/20220506044246.67146-1-pavel@loebl.cz
16 .../broadcom/brcm80211/brcmfmac/common.c | 23 ++++++++++++++-----
17 .../broadcom/brcm80211/brcmfmac/common.h | 1 +
18 .../broadcom/brcm80211/brcmfmac/core.c | 4 +++-
19 .../wireless/broadcom/brcm80211/brcmfmac/of.c | 3 +++
20 4 files changed, 24 insertions(+), 7 deletions(-)
22 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
23 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
24 @@ -202,13 +202,24 @@ int brcmf_c_preinit_dcmds(struct brcmf_i
28 - /* retreive mac address */
29 - err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
30 - sizeof(ifp->mac_addr));
32 - bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err);
34 + if (is_valid_ether_addr(ifp->mac_addr)) {
35 + /* set mac address */
36 + err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", ifp->mac_addr,
39 + bphy_err(ifp->drvr, "Setting cur_etheraddr failed, %d\n", err);
43 + /* retrieve mac address */
44 + err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
45 + sizeof(ifp->mac_addr));
47 + bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err);
52 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
53 memcpy(ifp->drvr->wiphy->perm_addr, ifp->drvr->mac, ETH_ALEN);
55 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
56 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
57 @@ -50,6 +50,7 @@ struct brcmf_mp_device {
58 bool ignore_probe_fail;
59 struct brcmfmac_pd_cc *country_codes;
60 const char *board_type;
61 + unsigned char mac[ETH_ALEN];
63 struct brcmfmac_sdio_pd sdio;
65 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
66 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
68 #include <linux/etherdevice.h>
69 #include <linux/module.h>
70 #include <linux/inetdevice.h>
71 +#include <linux/property.h>
72 #include <net/cfg80211.h>
73 #include <net/rtnetlink.h>
74 #include <net/addrconf.h>
75 @@ -1227,7 +1228,8 @@ static int brcmf_bus_started(struct brcm
76 brcmf_dbg(TRACE, "\n");
78 /* add primary networking interface */
79 - ifp = brcmf_add_if(drvr, 0, 0, false, "wlan%d", NULL);
80 + ifp = brcmf_add_if(drvr, 0, 0, false, "wlan%d",
81 + is_valid_ether_addr(drvr->settings->mac) ? drvr->settings->mac : NULL);
85 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
86 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
88 #include <linux/init.h>
90 #include <linux/of_irq.h>
91 +#include <linux/of_net.h>
95 @@ -97,6 +98,8 @@ void brcmf_of_probe(struct device *dev,
97 brcmf_err("failed to get OF country code map (err=%d)\n", err);
99 + of_get_mac_address(np, settings->mac);
101 if (bus_type != BRCMF_BUSTYPE_SDIO)