linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Alvin Šipraga" <ALSI@bang-olufsen.dk>
To: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Arend van Spriel <aspriel@gmail.com>,
	Franky Lin <franky.lin@broadcom.com>,
	Hante Meuleman <hante.meuleman@broadcom.com>,
	Alyssa Rosenzweig <alyssa@rosenzweig.io>,
	"asahi@lists.linux.dev" <asahi@lists.linux.dev>,
	"brcm80211-dev-list.pdl@broadcom.com"
	<brcm80211-dev-list.pdl@broadcom.com>,
	"David S. Miller" <davem@davemloft.net>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	Hector Martin <marcan@marcan.st>,
	Jakub Kicinski <kuba@kernel.org>, Kalle Valo <kvalo@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Rafa__ Mi__ecki <zajec5@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	"SHA-cyfmac-dev-list@infineon.com"
	<SHA-cyfmac-dev-list@infineon.com>,
	Sven Peter <sven@svenpeter.dev>
Subject: Re: [PATCH wireless-next v2 08/12] brcmfmac: firmware: Allow platform to override macaddr
Date: Thu, 15 Sep 2022 15:34:40 +0000	[thread overview]
Message-ID: <20220915153438.zt7hs3yuates7na7@bang-olufsen.dk> (raw)
In-Reply-To: <E1oXg7x-0064vN-Cm@rmk-PC.armlinux.org.uk>

On Mon, Sep 12, 2022 at 10:53:17AM +0100, Russell King wrote:
> From: Hector Martin <marcan@marcan.st>
> 
> On Device Tree platforms, it is customary to be able to set the MAC
> address via the Device Tree, as it is often stored in system firmware.
> This is particularly relevant for Apple ARM64 platforms, where this
> information comes from system configuration and passed through by the
> bootloader into the DT.
> 
> Implement support for this by fetching the platform MAC address and
> adding or replacing the macaddr= property in nvram. This becomes the
> dongle's default MAC address.
> 
> On platforms with an SROM MAC address, this overrides it. On platforms
> without one, such as Apple ARM64 devices, this is required for the
> firmware to boot (it will fail if it does not have a valid MAC at all).
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> ---
>  .../broadcom/brcm80211/brcmfmac/firmware.c    | 31 +++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> index 371c086d1f48..c109e20fc5c6 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> @@ -21,6 +21,8 @@
>  #define BRCMF_FW_NVRAM_DEVPATH_LEN		19	/* devpath0=pcie/1/4/ */
>  #define BRCMF_FW_NVRAM_PCIEDEV_LEN		10	/* pcie/1/4/ + \0 */
>  #define BRCMF_FW_DEFAULT_BOARDREV		"boardrev=0xff"
> +#define BRCMF_FW_MACADDR_FMT			"macaddr=%pM"
> +#define BRCMF_FW_MACADDR_LEN			(7 + ETH_ALEN * 3)
>  
>  enum nvram_parser_state {
>  	IDLE,
> @@ -57,6 +59,7 @@ struct nvram_parser {
>  	bool multi_dev_v1;
>  	bool multi_dev_v2;
>  	bool boardrev_found;
> +	bool strip_mac;

  CC [M]  drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.o
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c:63: warning: Function parameter or member 'strip_mac' not described in 'nvram_parser'

Otherwise looks OK and you can add

Reviewed-by: Alvin Šipraga <alsi@bang-olufsen.dk>


>  };
>  
>  /*
> @@ -121,6 +124,10 @@ static enum nvram_parser_state brcmf_nvram_handle_key(struct nvram_parser *nvp)
>  			nvp->multi_dev_v2 = true;
>  		if (strncmp(&nvp->data[nvp->entry], "boardrev", 8) == 0)
>  			nvp->boardrev_found = true;
> +		/* strip macaddr if platform MAC overrides */
> +		if (nvp->strip_mac &&
> +		    strncmp(&nvp->data[nvp->entry], "macaddr", 7) == 0)
> +			st = COMMENT;
>  	} else if (!is_nvram_char(c) || c == ' ') {
>  		brcmf_dbg(INFO, "warning: ln=%d:col=%d: '=' expected, skip invalid key entry\n",
>  			  nvp->line, nvp->column);
> @@ -209,6 +216,7 @@ static int brcmf_init_nvram_parser(struct nvram_parser *nvp,
>  		size = data_len;
>  	/* Add space for properties we may add */
>  	size += strlen(BRCMF_FW_DEFAULT_BOARDREV) + 1;
> +	size += BRCMF_FW_MACADDR_LEN + 1;
>  	/* Alloc for extra 0 byte + roundup by 4 + length field */
>  	size += 1 + 3 + sizeof(u32);
>  	nvp->nvram = kzalloc(size, GFP_KERNEL);
> @@ -368,22 +376,37 @@ static void brcmf_fw_add_defaults(struct nvram_parser *nvp)
>  	nvp->nvram_len++;
>  }
>  
> +static void brcmf_fw_add_macaddr(struct nvram_parser *nvp, u8 *mac)
> +{
> +	int len;
> +
> +	len = scnprintf(&nvp->nvram[nvp->nvram_len], BRCMF_FW_MACADDR_LEN + 1,
> +			BRCMF_FW_MACADDR_FMT, mac);
> +	WARN_ON(len != BRCMF_FW_MACADDR_LEN);
> +	nvp->nvram_len += len + 1;
> +}
> +
>  /* brcmf_nvram_strip :Takes a buffer of "<var>=<value>\n" lines read from a fil
>   * and ending in a NUL. Removes carriage returns, empty lines, comment lines,
>   * and converts newlines to NULs. Shortens buffer as needed and pads with NULs.
>   * End of buffer is completed with token identifying length of buffer.
>   */
>  static void *brcmf_fw_nvram_strip(const u8 *data, size_t data_len,
> -				  u32 *new_length, u16 domain_nr, u16 bus_nr)
> +				  u32 *new_length, u16 domain_nr, u16 bus_nr,
> +				  struct device *dev)
>  {
>  	struct nvram_parser nvp;
>  	u32 pad;
>  	u32 token;
>  	__le32 token_le;
> +	u8 mac[ETH_ALEN];
>  
>  	if (brcmf_init_nvram_parser(&nvp, data, data_len) < 0)
>  		return NULL;
>  
> +	if (eth_platform_get_mac_address(dev, mac) == 0)
> +		nvp.strip_mac = true;
> +
>  	while (nvp.pos < data_len) {
>  		nvp.state = nv_parser_states[nvp.state](&nvp);
>  		if (nvp.state == END)
> @@ -404,6 +427,9 @@ static void *brcmf_fw_nvram_strip(const u8 *data, size_t data_len,
>  
>  	brcmf_fw_add_defaults(&nvp);
>  
> +	if (nvp.strip_mac)
> +		brcmf_fw_add_macaddr(&nvp, mac);
> +
>  	pad = nvp.nvram_len;
>  	*new_length = roundup(nvp.nvram_len + 1, 4);
>  	while (pad != *new_length) {
> @@ -538,7 +564,8 @@ static int brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
>  	if (data)
>  		nvram = brcmf_fw_nvram_strip(data, data_len, &nvram_length,
>  					     fwctx->req->domain_nr,
> -					     fwctx->req->bus_nr);
> +					     fwctx->req->bus_nr,
> +					     fwctx->dev);
>  
>  	if (free_bcm47xx_nvram)
>  		bcm47xx_nvram_release_contents(data);
> -- 
> 2.30.2
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-09-15 15:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12  9:52 [PATCH wireless-next v2 0/12] Add support for bcm4378 on Apple platforms Russell King (Oracle)
2022-09-12  9:52 ` [PATCH wireless-next v2 01/12] dt-bindings: net: bcm4329-fmac: Add Apple properties & chips Russell King
2022-09-12 11:59   ` Alvin Šipraga
2022-09-12 12:04     ` Russell King (Oracle)
2022-09-12 14:01       ` Russell King (Oracle)
2022-09-12 14:13         ` Mark Kettenis
2022-09-12 14:27           ` Alvin Šipraga
2022-09-12 14:29             ` Russell King (Oracle)
2022-09-12  9:52 ` [PATCH wireless-next v2 02/12] brcmfmac: firmware: Handle per-board clm_blob files Russell King
2022-09-15 15:33   ` Alvin Šipraga
2022-09-12  9:52 ` [PATCH wireless-next v2 03/12] brcmfmac: pcie/sdio/usb: Get CLM blob via standard firmware mechanism Russell King
2022-09-15 15:33   ` Alvin Šipraga
2022-09-12  9:52 ` [PATCH wireless-next v2 04/12] brcmfmac: firmware: Support passing in multiple board_types Russell King
2022-09-15 15:34   ` Alvin Šipraga
2022-09-12  9:53 ` [PATCH wireless-next v2 05/12] brcmfmac: pcie: Read Apple OTP information Russell King
2022-09-12  9:53 ` [PATCH wireless-next v2 06/12] brcmfmac: of: Fetch Apple properties Russell King
2022-09-15 15:34   ` Alvin Šipraga
2022-09-12  9:53 ` [PATCH wireless-next v2 07/12] brcmfmac: pcie: Perform firmware selection for Apple platforms Russell King
2022-09-15 15:34   ` Alvin Šipraga
2022-09-12  9:53 ` [PATCH wireless-next v2 08/12] brcmfmac: firmware: Allow platform to override macaddr Russell King
2022-09-15 15:34   ` Alvin Šipraga [this message]
2022-09-12  9:53 ` [PATCH wireless-next v2 09/12] brcmfmac: msgbuf: Increase RX ring sizes to 1024 Russell King
2022-09-15 15:34   ` Alvin Šipraga
2022-09-12  9:53 ` [PATCH wireless-next v2 10/12] brcmfmac: pcie: Support PCIe core revisions >= 64 Russell King
2022-09-12  9:53 ` [PATCH wireless-next v2 11/12] brcmfmac: pcie: Add IDs/properties for BCM4378 Russell King
2022-09-15 15:34   ` Alvin Šipraga
2022-09-15 16:54     ` Russell King (Oracle)
2022-09-15 16:59       ` Alvin Šipraga
2022-09-16  7:31         ` Kalle Valo
2022-09-12  9:53 ` [PATCH wireless-next v2 12/12] arm64: dts: apple: Add WiFi module and antenna properties Russell King
2022-09-13  6:52   ` Kalle Valo
2022-09-13 16:30     ` Hector Martin
2022-09-16  7:28       ` Kalle Valo
2022-09-14 10:31 ` [PATCH wireless-next v2 0/12] Add support for bcm4378 on Apple platforms Arend Van Spriel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220915153438.zt7hs3yuates7na7@bang-olufsen.dk \
    --to=alsi@bang-olufsen.dk \
    --cc=SHA-cyfmac-dev-list@infineon.com \
    --cc=alyssa@rosenzweig.io \
    --cc=asahi@lists.linux.dev \
    --cc=aspriel@gmail.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=franky.lin@broadcom.com \
    --cc=hante.meuleman@broadcom.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=marcan@marcan.st \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh+dt@kernel.org \
    --cc=sven@svenpeter.dev \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).