]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
brcmfmac: firmware: Fix firmware loading
authorLinus Walleij <linus.walleij@linaro.org>
Sun, 8 Aug 2021 18:05:10 +0000 (21:05 +0300)
committerKalle Valo <kvalo@codeaurora.org>
Sat, 21 Aug 2021 15:45:30 +0000 (18:45 +0300)
The patch that would first try the board-specific firmware
had a bug because the fallback would not be called: the
asynchronous interface is used meaning request_firmware_nowait()
returns 0 immediately.

Harden the firmware loading like this:

- If we cannot build an alt_path (like if no board_type is
  specified) just request the first firmware without any
  suffix, like in the past.

- If the lookup of a board specific firmware fails, we get
  a NULL fw in the async callback, so just try again without
  the alt_path from a dedicated brcm_fw_request_done_alt_path
  callback.

- Drop the unnecessary prototype of brcm_fw_request_done.

- Added MODULE_FIRMWARE match for per-board SDIO bins, making
  userspace tools to pull all the relevant firmware files.

Fixes: 5ff013914c62 ("brcmfmac: firmware: Allow per-board firmware binaries")
Cc: Stefan Hansson <newbyte@disroot.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210808180510.8753-1-digetx@gmail.com
drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c

index adfdfc654b1049a0e8a52f8de5613b1ff77c878b..0eb13e5df51775bfa825dfa8d9938dcec3a907a7 100644 (file)
@@ -431,8 +431,6 @@ struct brcmf_fw {
        void (*done)(struct device *dev, int err, struct brcmf_fw_request *req);
 };
 
-static void brcmf_fw_request_done(const struct firmware *fw, void *ctx);
-
 #ifdef CONFIG_EFI
 /* In some cases the EFI-var stored nvram contains "ccode=ALL" or "ccode=XV"
  * to specify "worldwide" compatible settings, but these 2 ccode-s do not work
@@ -658,6 +656,22 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
        kfree(fwctx);
 }
 
+static void brcmf_fw_request_done_alt_path(const struct firmware *fw, void *ctx)
+{
+       struct brcmf_fw *fwctx = 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)
+               ret = request_firmware_nowait(THIS_MODULE, true, first->path,
+                                             fwctx->dev, GFP_KERNEL, fwctx,
+                                             brcmf_fw_request_done);
+
+       if (fw || ret < 0)
+               brcmf_fw_request_done(fw, ctx);
+}
+
 static bool brcmf_fw_request_is_valid(struct brcmf_fw_request *req)
 {
        struct brcmf_fw_item *item;
@@ -702,11 +716,9 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
        if (alt_path) {
                ret = request_firmware_nowait(THIS_MODULE, true, alt_path,
                                              fwctx->dev, GFP_KERNEL, fwctx,
-                                             brcmf_fw_request_done);
+                                             brcmf_fw_request_done_alt_path);
                kfree(alt_path);
-       }
-       /* Else try canonical path */
-       if (ret) {
+       } else {
                ret = request_firmware_nowait(THIS_MODULE, true, first->path,
                                              fwctx->dev, GFP_KERNEL, fwctx,
                                              brcmf_fw_request_done);
index 97ee9e2e2e357f45e43e21bdbaa8c64c6e1e2419..1d1b0b7d8d9b3c5494f9a1d30e2bb0b9e1aa03fc 100644 (file)
@@ -629,6 +629,9 @@ BRCMF_FW_CLM_DEF(43012, "brcmfmac43012-sdio");
 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.txt");
 MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-pcie.*.txt");
 
+/* per-board firmware binaries */
+MODULE_FIRMWARE(BRCMF_FW_DEFAULT_PATH "brcmfmac*-sdio.*.bin");
+
 static const struct brcmf_firmware_mapping brcmf_sdio_fwnames[] = {
        BRCMF_FW_ENTRY(BRCM_CC_43143_CHIP_ID, 0xFFFFFFFF, 43143),
        BRCMF_FW_ENTRY(BRCM_CC_43241_CHIP_ID, 0x0000001F, 43241B0),