linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arend van Spriel <arend.vanspriel@broadcom.com>
To: Hector Martin <marcan@marcan.st>,
	Kalle Valo <kvalo@codeaurora.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, Arend van Spriel <aspriel@gmail.com>,
	Franky Lin <franky.lin@broadcom.com>,
	Hante Meuleman <hante.meuleman@broadcom.com>,
	Chi-hsien Lin <chi-hsien.lin@infineon.com>,
	Wright Feng <wright.feng@infineon.com>,
	Dmitry Osipenko <digetx@gmail.com>
Cc: "Sven Peter" <sven@svenpeter.dev>,
	"Alyssa Rosenzweig" <alyssa@rosenzweig.io>,
	"Mark Kettenis" <kettenis@openbsd.org>,
	"Rafał Miłecki" <zajec5@gmail.com>,
	"Pieter-Paul Giesberts" <pieter-paul.giesberts@broadcom.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"John W. Linville" <linville@tuxdriver.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com,
	SHA-cyfmac-dev-list@infineon.com
Subject: Re: [PATCH v2 04/35] brcmfmac: firmware: Support having multiple alt paths
Date: Thu, 6 Jan 2022 11:43:05 +0100	[thread overview]
Message-ID: <fd95636e-b879-0c82-a7ba-a5c239f4f611@broadcom.com> (raw)
In-Reply-To: <20220104072658.69756-5-marcan@marcan.st>

[-- Attachment #1: Type: text/plain, Size: 6836 bytes --]

On 1/4/2022 8:26 AM, Hector Martin wrote:
> Apple platforms have firmware and config files identified with multiple
> dimensions. We want to be able to find the most specific firmware
> available for any given platform, progressively trying more general
> firmwares.
> 
> First, add support for having multiple alternate firmware paths.

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
> Acked-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Hector Martin <marcan@marcan.st>
> ---
>   .../broadcom/brcm80211/brcmfmac/firmware.c    | 75 ++++++++++++++-----
>   .../broadcom/brcm80211/brcmfmac/firmware.h    |  2 +
>   2 files changed, 59 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> index 0497b721136a..7570dbf22cdd 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
> @@ -427,6 +427,8 @@ void brcmf_fw_nvram_free(void *nvram)
>   struct brcmf_fw {
>   	struct device *dev;
>   	struct brcmf_fw_request *req;
> +	const char *alt_paths[BRCMF_FW_MAX_ALT_PATHS];
> +	int alt_index;
>   	u32 curpos;
>   	void (*done)(struct device *dev, int err, struct brcmf_fw_request *req);
>   };
> @@ -592,14 +594,18 @@ static int brcmf_fw_complete_request(const struct firmware *fw,
>   	return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
>   }
>   
> -static char *brcm_alt_fw_path(const char *path, const char *board_type)
> +static int brcm_alt_fw_paths(const char *path, const char *board_type,
> +			     const char *alt_paths[BRCMF_FW_MAX_ALT_PATHS])
>   {
>   	char alt_path[BRCMF_FW_NAME_LEN];
>   	const char *suffix;
>   
> +	memset(alt_paths, 0, array_size(sizeof(*alt_paths),
> +					BRCMF_FW_MAX_ALT_PATHS));
> +
>   	suffix = strrchr(path, '.');
>   	if (!suffix || suffix == path)
> -		return NULL;
> +		return -EINVAL;
>   
>   	/* strip extension at the end */
>   	strscpy(alt_path, path, BRCMF_FW_NAME_LEN);
> @@ -609,7 +615,18 @@ static char *brcm_alt_fw_path(const char *path, const char *board_type)
>   	strlcat(alt_path, board_type, BRCMF_FW_NAME_LEN);
>   	strlcat(alt_path, suffix, BRCMF_FW_NAME_LEN);
>   
> -	return kstrdup(alt_path, GFP_KERNEL);
> +	alt_paths[0] = kstrdup(alt_path, GFP_KERNEL);
> +
> +	return 0;
> +}
> +
> +static void
> +brcm_free_alt_fw_paths(const char *alt_paths[BRCMF_FW_MAX_ALT_PATHS])
> +{
> +	unsigned int i;
> +
> +	for (i = 0; alt_paths[i]; i++)
> +		kfree(alt_paths[i]);
>   }
>   
>   static int brcmf_fw_request_firmware(const struct firmware **fw,
> @@ -617,19 +634,25 @@ static int brcmf_fw_request_firmware(const struct firmware **fw,
>   {
>   	struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos];
>   	int ret;
> +	unsigned int i;
>   
>   	/* Files can be board-specific, first try a board-specific path */
>   	if (fwctx->req->board_type) {
> -		char *alt_path;
> +		const char *alt_paths[BRCMF_FW_MAX_ALT_PATHS];
>   
> -		alt_path = brcm_alt_fw_path(cur->path, fwctx->req->board_type);
> -		if (!alt_path)
> +		if (brcm_alt_fw_paths(cur->path, fwctx->req->board_type,
> +				      alt_paths) != 0)
>   			goto fallback;
>   
> -		ret = request_firmware(fw, alt_path, fwctx->dev);
> -		kfree(alt_path);
> -		if (ret == 0)
> -			return ret;
> +		for (i = 0; i < BRCMF_FW_MAX_ALT_PATHS && alt_paths[i]; i++) {
> +			ret = firmware_request_nowarn(fw, alt_paths[i],
> +						      fwctx->dev);
> +			if (ret == 0) {
> +				brcm_free_alt_fw_paths(alt_paths);
> +				return ret;
> +			}
> +		}
> +		brcm_free_alt_fw_paths(alt_paths);
>   	}
>   
>   fallback:
> @@ -641,6 +664,8 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
>   	struct brcmf_fw *fwctx = ctx;
>   	int ret;
>   
> +	brcm_free_alt_fw_paths(fwctx->alt_paths);
> +
>   	ret = brcmf_fw_complete_request(fw, fwctx);
>   
>   	while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
> @@ -662,13 +687,27 @@ static void brcmf_fw_request_done_alt_path(const struct firmware *fw, void *ctx)
>   	struct brcmf_fw_item *first = &fwctx->req->items[0];
>   	int ret = 0;
>   
> -	/* Fall back to canonical path if board firmware not found */
> -	if (!fw)
> +	if (fw) {
> +		brcmf_fw_request_done(fw, ctx);
> +		return;
> +	}
> +
> +	fwctx->alt_index++;
> +	if (fwctx->alt_index < BRCMF_FW_MAX_ALT_PATHS &&
> +	    fwctx->alt_paths[fwctx->alt_index]) {
> +		/* Try the next alt firmware */
> +		ret = request_firmware_nowait(THIS_MODULE, true,
> +					      fwctx->alt_paths[fwctx->alt_index],
> +					      fwctx->dev, GFP_KERNEL, fwctx,
> +					      brcmf_fw_request_done_alt_path);
> +	} else {
> +		/* Fall back to canonical path if board firmware not found */
>   		ret = request_firmware_nowait(THIS_MODULE, true, first->path,
>   					      fwctx->dev, GFP_KERNEL, fwctx,
>   					      brcmf_fw_request_done);
> +	}
>   
> -	if (fw || ret < 0)
> +	if (ret < 0)
>   		brcmf_fw_request_done(fw, ctx);
>   }
>   
> @@ -693,7 +732,6 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
>   {
>   	struct brcmf_fw_item *first = &req->items[0];
>   	struct brcmf_fw *fwctx;
> -	char *alt_path;
>   	int ret;
>   
>   	brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
> @@ -712,12 +750,13 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
>   	fwctx->done = fw_cb;
>   
>   	/* First try alternative board-specific path if any */
> -	alt_path = brcm_alt_fw_path(first->path, fwctx->req->board_type);
> -	if (alt_path) {
> -		ret = request_firmware_nowait(THIS_MODULE, true, alt_path,
> +	if (brcm_alt_fw_paths(first->path, req->board_type,
> +			      fwctx->alt_paths) == 0) {
> +		fwctx->alt_index = 0;
> +		ret = request_firmware_nowait(THIS_MODULE, true,
> +					      fwctx->alt_paths[0],
>   					      fwctx->dev, GFP_KERNEL, fwctx,
>   					      brcmf_fw_request_done_alt_path);
> -		kfree(alt_path);
>   	} else {
>   		ret = request_firmware_nowait(THIS_MODULE, true, first->path,
>   					      fwctx->dev, GFP_KERNEL, fwctx,
> diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
> index e290dec9c53d..7f4e6e359c82 100644
> --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
> +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
> @@ -11,6 +11,8 @@
>   
>   #define BRCMF_FW_DEFAULT_PATH		"brcm/"
>   
> +#define BRCMF_FW_MAX_ALT_PATHS	8
> +

Any motivation to have 8 here today? In patch #9 I see a list of 6 paths 
in the commit message so you need 6 and rounded up here to power of 2?

>   /**
>    * struct brcmf_firmware_mapping - Used to map chipid/revmask to firmware
>    *	filename and nvram filename. Each bus type implementation should create

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4219 bytes --]

  parent reply	other threads:[~2022-01-06 10:43 UTC|newest]

Thread overview: 122+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04  7:26 [PATCH v2 00/35] brcmfmac: Support Apple T2 and M1 platforms Hector Martin
2022-01-04  7:26 ` [PATCH v2 01/35] dt-bindings: net: bcm4329-fmac: Add Apple properties & chips Hector Martin
2022-01-11 18:45   ` Rob Herring
2022-01-04  7:26 ` [PATCH v2 02/35] brcmfmac: pcie: Declare missing firmware files in pcie.c Hector Martin
2022-01-06  9:56   ` Arend van Spriel
2022-01-06 11:10     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 03/35] brcmfmac: firmware: Handle per-board clm_blob files Hector Martin
2022-01-06 10:19   ` Arend van Spriel
2022-01-06 10:59     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 04/35] brcmfmac: firmware: Support having multiple alt paths Hector Martin
2022-01-04  8:26   ` Dmitry Osipenko
2022-01-04  8:43     ` Hector Martin
2022-01-04 22:09       ` Dmitry Osipenko
2022-01-05 13:22         ` Hector Martin
2022-01-06 17:40           ` Dmitry Osipenko
2022-01-06 17:58             ` Andy Shevchenko
2022-01-07  3:12               ` Dmitry Osipenko
2022-01-07  9:55                 ` Andy Shevchenko
2022-01-04 22:36       ` Dmitry Osipenko
2022-01-04 22:38   ` Dmitry Osipenko
2022-01-06 10:43   ` Arend van Spriel [this message]
2022-01-06 11:12     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 05/35] brcmfmac: pcie/sdio/usb: Get CLM blob via standard firmware mechanism Hector Martin
2022-01-06 10:48   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 06/35] brcmfmac: firmware: Support passing in multiple board_types Hector Martin
2022-01-04 10:22   ` Arend van Spriel
2022-01-04 10:30     ` Hector Martin
2022-01-04 11:28   ` Andy Shevchenko
2022-01-07  2:50     ` Hector Martin
2022-01-06 12:16   ` Arend van Spriel
2022-01-07  4:02     ` Hector Martin
2022-01-07  6:17       ` Arend Van Spriel
2022-01-07  7:12         ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 07/35] brcmfmac: pcie: Read Apple OTP information Hector Martin
2022-01-04 11:26   ` Andy Shevchenko
2022-01-07  3:53     ` Hector Martin
2022-01-06 12:37   ` Arend van Spriel
2022-01-06 13:08     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 08/35] brcmfmac: of: Fetch Apple properties Hector Martin
2022-01-04 11:17   ` Andy Shevchenko
2022-01-07  3:54     ` Hector Martin
2022-01-08 20:03   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 09/35] brcmfmac: pcie: Perform firmware selection for Apple platforms Hector Martin
2022-01-04 14:24   ` Andy Shevchenko
2022-01-06 13:12     ` Hector Martin
2022-01-08 20:03   ` Arend van Spriel
2022-01-17  6:36     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 10/35] brcmfmac: firmware: Allow platform to override macaddr Hector Martin
2022-01-04 14:23   ` Andy Shevchenko
2022-01-05 13:26     ` Hector Martin
2022-01-06 14:20       ` Andy Shevchenko
2022-01-07  2:39         ` Hector Martin
2022-01-08 20:14   ` Arend van Spriel
2022-01-17  6:38     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 11/35] brcmfmac: msgbuf: Increase RX ring sizes to 1024 Hector Martin
2022-01-10  7:17   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 12/35] brcmfmac: pcie: Fix crashes due to early IRQs Hector Martin
2022-01-04 14:12   ` Andy Shevchenko
2022-01-06 13:10     ` Hector Martin
2022-01-10 13:54       ` Kalle Valo
2022-01-10  7:19   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 13/35] brcmfmac: pcie: Support PCIe core revisions >= 64 Hector Martin
2022-01-10  7:31   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 14/35] brcmfmac: pcie: Add IDs/properties for BCM4378 Hector Martin
2022-01-10  9:10   ` Arend van Spriel
2022-01-10 11:04     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 15/35] ACPI / property: Support strings in Apple _DSM props Hector Martin
2022-01-04  7:26 ` [PATCH v2 16/35] brcmfmac: acpi: Add support for fetching Apple ACPI properties Hector Martin
2022-01-04 10:21   ` Arend van Spriel
2022-01-04 11:00     ` Hector Martin
2022-01-10 14:01       ` Kalle Valo
2022-01-10  9:11   ` Arend van Spriel
2022-01-10 11:07     ` Hector Martin
2022-01-10 11:26       ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 17/35] brcmfmac: pcie: Provide a buffer of random bytes to the device Hector Martin
2022-01-10  9:11   ` Arend van Spriel
2022-01-10 11:09     ` Hector Martin
2022-01-10 11:28       ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 18/35] brcmfmac: pcie: Add IDs/properties for BCM4355 Hector Martin
2022-01-10  9:12   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 19/35] brcmfmac: pcie: Add IDs/properties for BCM4377 Hector Martin
2022-01-10  9:12   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 20/35] brcmfmac: pcie: Perform correct BCM4364 firmware selection Hector Martin
2022-01-10  9:12   ` Arend van Spriel
2022-01-10 11:20     ` Hector Martin
2022-01-10 12:02       ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 21/35] brcmfmac: chip: Only disable D11 cores; handle an arbitrary number Hector Martin
2022-01-19 12:36   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 22/35] brcmfmac: chip: Handle 1024-unit sizes for TCM blocks Hector Martin
2022-01-19 12:36   ` Arend van Spriel
2022-01-20  8:49     ` Arend van Spriel
2022-01-31 16:21     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 23/35] brcmfmac: cfg80211: Add support for scan params v2 Hector Martin
2022-01-04 19:46   ` Arend Van Spriel
2022-01-17  6:57     ` Hector Martin
2022-01-11  8:50   ` Arend van Spriel
2022-01-17  6:58     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 24/35] brcmfmac: feature: Add support for setting feats based on WLC version Hector Martin
2022-01-21  7:35   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 25/35] brcmfmac: cfg80211: Add support for PMKID_V3 operations Hector Martin
2022-01-21  7:35   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 26/35] brcmfmac: cfg80211: Pass the PMK in binary instead of hex Hector Martin
2022-01-21  7:35   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 27/35] brcmfmac: pcie: Add IDs/properties for BCM4387 Hector Martin
2022-01-21  7:35   ` Arend van Spriel
2022-01-31 16:37     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 28/35] brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio Hector Martin
2022-01-04  7:26 ` [PATCH v2 29/35] brcmfmac: pcie: Read the console on init and shutdown Hector Martin
2022-01-04  7:26 ` [PATCH v2 30/35] brcmfmac: pcie: Release firmwares in the brcmf_pcie_setup error path Hector Martin
2022-01-04  7:26 ` [PATCH v2 31/35] brcmfmac: firmware: Allocate space for default boardrev in nvram Hector Martin
2022-01-04  7:26 ` [PATCH v2 32/35] brcmfmac: fwil: Constify iovar name arguments Hector Martin
2022-01-04  7:26 ` [PATCH v2 33/35] brcmfmac: common: Add support for downloading TxCap blobs Hector Martin
2022-01-21  7:36   ` Arend van Spriel
2022-01-31 16:28     ` Hector Martin
2022-01-04  7:26 ` [PATCH v2 34/35] brcmfmac: pcie: Load and provide " Hector Martin
2022-01-21  7:36   ` Arend van Spriel
2022-01-04  7:26 ` [PATCH v2 35/35] brcmfmac: common: Add support for external calibration blobs Hector Martin
2022-01-21  7:35   ` Arend van Spriel
2022-01-04 14:28 ` [PATCH v2 00/35] brcmfmac: Support Apple T2 and M1 platforms Andy Shevchenko
2022-01-10 10:14 ` Kalle Valo
2022-01-10 11:21   ` Hector Martin
2022-01-10 13:46     ` Kalle Valo

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=fd95636e-b879-0c82-a7ba-a5c239f4f611@broadcom.com \
    --to=arend.vanspriel@broadcom.com \
    --cc=SHA-cyfmac-dev-list@infineon.com \
    --cc=alyssa@rosenzweig.io \
    --cc=andy.shevchenko@gmail.com \
    --cc=aspriel@gmail.com \
    --cc=brcm80211-dev-list.pdl@broadcom.com \
    --cc=chi-hsien.lin@infineon.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=digetx@gmail.com \
    --cc=franky.lin@broadcom.com \
    --cc=hante.meuleman@broadcom.com \
    --cc=hdegoede@redhat.com \
    --cc=kettenis@openbsd.org \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=lenb@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    --cc=marcan@marcan.st \
    --cc=netdev@vger.kernel.org \
    --cc=pieter-paul.giesberts@broadcom.com \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=sandals@crustytoothpaste.net \
    --cc=sven@svenpeter.dev \
    --cc=wright.feng@infineon.com \
    --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).