brcmfmac: allow setting wlan MAC address using device tree
authorPavel Löbl <pavel@loebl.cz>
Fri, 6 May 2022 04:42:46 +0000 (06:42 +0200)
committerKalle Valo <kvalo@kernel.org>
Wed, 11 May 2022 05:27:14 +0000 (08:27 +0300)
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 <pavel@loebl.cz>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220506044246.67146-1-pavel@loebl.cz
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c

index e3758bd..fe01da9 100644 (file)
@@ -202,13 +202,24 @@ int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
        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);
 
index 8b5f499..15accc8 100644 (file)
@@ -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;
index 26fab4b..87aef21 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/etherdevice.h>
 #include <linux/module.h>
 #include <linux/inetdevice.h>
+#include <linux/property.h>
 #include <net/cfg80211.h>
 #include <net/rtnetlink.h>
 #include <net/addrconf.h>
@@ -1197,7 +1198,8 @@ static int brcmf_bus_started(struct brcmf_pub *drvr, struct cfg80211_ops *ops)
        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);
 
index 8623bde..083ac58 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/init.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
+#include <linux/of_net.h>
 
 #include <defs.h>
 #include "debug.h"
@@ -99,6 +100,8 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
        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;