03d9f8ecd8c1f36e0f7bbdd39b74d82d4ca2f144
[openwrt/staging/rmilecki.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This allows firmware to provide MAC address using device tree. Like in
10 case there is no MAC burned in wlan NVRAM.
11
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
15 ---
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(-)
21
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
25 char *ptr;
26 s32 err;
27
28 - /* retreive mac address */
29 - err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
30 - sizeof(ifp->mac_addr));
31 - if (err < 0) {
32 - bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err);
33 - goto done;
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,
37 + ETH_ALEN);
38 + if (err < 0) {
39 + bphy_err(ifp->drvr, "Setting cur_etheraddr failed, %d\n", err);
40 + goto done;
41 + }
42 + } else {
43 + /* retrieve mac address */
44 + err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
45 + sizeof(ifp->mac_addr));
46 + if (err < 0) {
47 + bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err);
48 + goto done;
49 + }
50 }
51 +
52 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
53 memcpy(ifp->drvr->wiphy->perm_addr, ifp->drvr->mac, ETH_ALEN);
54
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];
62 union {
63 struct brcmfmac_sdio_pd sdio;
64 } bus;
65 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
66 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
67 @@ -7,6 +7,7 @@
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 @@ -1226,7 +1227,8 @@ static int brcmf_bus_started(struct brcm
76 brcmf_dbg(TRACE, "\n");
77
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);
82 if (IS_ERR(ifp))
83 return PTR_ERR(ifp);
84
85 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
86 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
87 @@ -5,6 +5,7 @@
88 #include <linux/init.h>
89 #include <linux/of.h>
90 #include <linux/of_irq.h>
91 +#include <linux/of_net.h>
92
93 #include <defs.h>
94 #include "debug.h"
95 @@ -97,6 +98,8 @@ void brcmf_of_probe(struct device *dev,
96 if (err)
97 brcmf_err("failed to get OF country code map (err=%d)\n", err);
98
99 + of_get_mac_address(np, settings->mac);
100 +
101 if (bus_type != BRCMF_BUSTYPE_SDIO)
102 return;
103