From patchwork Mon Jun 20 12:50:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomasz Maciej Nowak X-Patchwork-Id: 1645504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=op9xhPmT; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=terefe.re header.i=@terefe.re header.a=rsa-sha256 header.s=default header.b=wx1Zy+nu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LRVY926rCz9sFx for ; Mon, 20 Jun 2022 23:17:01 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=9G2Ogaz1WUsNdbZz8ZCQh1XzTH4sF2W+3BdAMU+LUd0=; b=op9 xhPmTMTYRBb1GQfB1WW5x7DsvebkSLTr3sKzApzS77t/B+k+XDiJdwGNRDEQOsOZUQJGzbTY+8AOv lOCmfJ66BCgzmnKLddX6s0L1GWO/pgwfkTLnO2RMZu/NBt/C0ArTXXD0fP0x4EYlhm8H778/Vx8Ce gb4pjuaqb/iCRYufpcdpIcTrST1Ef9PYYEKyEI5Eu3ICk2EVZt30kzrwJGE6W+T0hWMZIwD7wnPBC gxHdFaWNrMv+WjdcegobZnjJFsHZt6GARGyMWkp+ZwmQLF5CnYgnJMk4m6NbtePg+Dy4T+unX3hK8 414ajQFfD9/IHTKTavzk+zfPzrWzJkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3HEx-000jid-AI; Mon, 20 Jun 2022 13:14:52 +0000 Received: from mail.terefe.re ([2a04:52c0:101:a4a:0:ffff:5ff:60c8]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o3GrR-000YPa-7Z for openwrt-devel@lists.openwrt.org; Mon, 20 Jun 2022 12:50:35 +0000 Received: from localhost.localdomain (unknown [212.106.161.60]) by mail.terefe.re (Postfix) with ESMTPSA id C7E7E20100; Mon, 20 Jun 2022 14:50:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=terefe.re; s=default; t=1655729431; bh=p/06t8wbCzWXOtZEcNwyvNkGhCfuNto8szQoZ/ooQpM=; h=From:To:Cc:Subject:Date:From; b=wx1Zy+nuPFS+NQsyW+iV/yG9sY5QziVZylXO97++0aZ3fJD7Aa/Fg2OZbyaN6tCj0 HIqBrZqibGjHblTVBz/SE7VGakn70X1zvNbCngGxb7GoE0X5OLjOkobIrdtLQgeORU o0w0zo8FNhUnWBkYFJYxLWIpPubKbpmbgGzeUKCcshxkpeSjR0DUTWNOfIqRYKKlGH YelWJLk6YDwm/cZ6MwARE0aSkidpF4jWJ3FCVTxv05Q0CqyCzAwgZ+X5MsN80bu5gL F7aIHGaIEPzCfxVdb1O2McZCq/BzF9hEz3FN6U0pLL0Lmnjy9MvLTpnm5EE3gCoV5e Tikjkqno5lpcQ== From: Tomasz Maciej Nowak To: openwrt-devel@lists.openwrt.org Cc: Tomasz Maciej Nowak Subject: [PATCH] mac80211: brcmfmac: allow setting MAC from NVMEM cells Date: Mon, 20 Jun 2022 14:50:23 +0200 Message-Id: <20220620125023.3146-1-tmn505@terefe.re> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220620_055033_586843_360FB9D3 X-CRM114-Status: GOOD ( 17.31 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Tomasz Maciej Nowak 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 prog [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Tomasz Maciej Nowak 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 --- ...etting-wlan-MAC-address-using-device.patch | 103 ++++++++++++++++++ ...-in-driver-tables-with-country-codes.patch | 4 +- .../mac80211/patches/brcm/998-survey.patch | 4 +- 3 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 package/kernel/mac80211/patches/brcm/001-brcmfmac-allow-setting-wlan-MAC-address-using-device.patch 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 000000000000..03d9f8ecd8c1 --- /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 835c870a6577..1ddc78f7ca9a 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 a5efc08015fa..d194e25177e0 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;