summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Robinson <pbrobinson@gmail.com>2018-10-01 09:19:41 +0100
committerPeter Robinson <pbrobinson@gmail.com>2018-10-01 09:19:41 +0100
commit0bae75213b3e6c619c6561e1fc22782cc24aebd8 (patch)
tree92ff3e3ba74033011977acf5192d11792ca8daa6
parent48b07d1ffe67304257b1cb47bdbc28bae22efa03 (diff)
downloadkernel-0bae75213b3e6c619c6561e1fc22782cc24aebd8.tar.gz
kernel-0bae75213b3e6c619c6561e1fc22782cc24aebd8.tar.xz
kernel-0bae75213b3e6c619c6561e1fc22782cc24aebd8.zip
Support loading device specific NVRAM files on brcm WiFi devices
-rw-r--r--0001-brcmfmac-Remove-firmware-loading-code-duplication.patch106
-rw-r--r--0002-brcmfmac-Remove-recursion-from-firmware-load-error-h.patch131
-rw-r--r--0003-brcmfmac-Add-support-for-first-trying-to-get-a-board.patch83
-rw-r--r--0004-brcmfmac-Set-board_type-used-for-nvram-file-selectio.patch87
-rw-r--r--kernel.spec9
5 files changed, 416 insertions, 0 deletions
diff --git a/0001-brcmfmac-Remove-firmware-loading-code-duplication.patch b/0001-brcmfmac-Remove-firmware-loading-code-duplication.patch
new file mode 100644
index 000000000..5145e5534
--- /dev/null
+++ b/0001-brcmfmac-Remove-firmware-loading-code-duplication.patch
@@ -0,0 +1,106 @@
+From 920bc5d0e3a0ffa9142b54c3b6acf253e6e24d64 Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede@redhat.com>
+Date: Thu, 27 Sep 2018 17:44:30 +0200
+Subject: [PATCH 1/5] brcmfmac: Remove firmware-loading code duplication
+
+brcmf_fw_request_next_item and brcmf_fw_request_done both have identical
+code to complete the fw-request depending on the item-type.
+
+This commit adds a new brcmf_fw_complete_request helper removing this code
+duplication.
+
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
+---
+ .../broadcom/brcm80211/brcmfmac/firmware.c | 62 +++++++++----------
+ 1 file changed, 31 insertions(+), 31 deletions(-)
+
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+index 2af2251cd8e9..848c3351d107 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+@@ -587,6 +587,34 @@ static int brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
+ return -ENOENT;
+ }
+
++static int brcmf_fw_complete_request(const struct firmware *fw,
++ struct brcmf_fw *fwctx)
++{
++ struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos];
++ int ret = 0;
++
++ brcmf_dbg(TRACE, "firmware %s %sfound\n", cur->path, fw ? "" : "not ");
++
++ switch (cur->type) {
++ case BRCMF_FW_TYPE_NVRAM:
++ ret = brcmf_fw_request_nvram_done(fw, fwctx);
++ break;
++ case BRCMF_FW_TYPE_BINARY:
++ if (fw)
++ cur->binary = fw;
++ else
++ ret = -ENOENT;
++ break;
++ default:
++ /* something fishy here so bail out early */
++ brcmf_err("unknown fw type: %d\n", cur->type);
++ release_firmware(fw);
++ ret = -EINVAL;
++ }
++
++ return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
++}
++
+ static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
+ {
+ struct brcmf_fw_item *cur;
+@@ -608,15 +636,7 @@ static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
+ if (ret < 0) {
+ brcmf_fw_request_done(NULL, fwctx);
+ } else if (!async && fw) {
+- brcmf_dbg(TRACE, "firmware %s %sfound\n", cur->path,
+- fw ? "" : "not ");
+- if (cur->type == BRCMF_FW_TYPE_BINARY)
+- cur->binary = fw;
+- else if (cur->type == BRCMF_FW_TYPE_NVRAM)
+- brcmf_fw_request_nvram_done(fw, fwctx);
+- else
+- release_firmware(fw);
+-
++ brcmf_fw_complete_request(fw, fwctx);
+ return -EAGAIN;
+ }
+ return 0;
+@@ -630,28 +650,8 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
+
+ cur = &fwctx->req->items[fwctx->curpos];
+
+- brcmf_dbg(TRACE, "enter: firmware %s %sfound\n", cur->path,
+- fw ? "" : "not ");
+-
+- if (!fw)
+- ret = -ENOENT;
+-
+- switch (cur->type) {
+- case BRCMF_FW_TYPE_NVRAM:
+- ret = brcmf_fw_request_nvram_done(fw, fwctx);
+- break;
+- case BRCMF_FW_TYPE_BINARY:
+- cur->binary = fw;
+- break;
+- default:
+- /* something fishy here so bail out early */
+- brcmf_err("unknown fw type: %d\n", cur->type);
+- release_firmware(fw);
+- ret = -EINVAL;
+- goto fail;
+- }
+-
+- if (ret < 0 && !(cur->flags & BRCMF_FW_REQF_OPTIONAL))
++ ret = brcmf_fw_complete_request(fw, fwctx);
++ if (ret < 0)
+ goto fail;
+
+ do {
+--
+2.19.0
+
diff --git a/0002-brcmfmac-Remove-recursion-from-firmware-load-error-h.patch b/0002-brcmfmac-Remove-recursion-from-firmware-load-error-h.patch
new file mode 100644
index 000000000..a0553e6e8
--- /dev/null
+++ b/0002-brcmfmac-Remove-recursion-from-firmware-load-error-h.patch
@@ -0,0 +1,131 @@
+From 7a2f4b4fa44268a570f6fa7782385741134f8da6 Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede@redhat.com>
+Date: Thu, 27 Sep 2018 17:51:36 +0200
+Subject: [PATCH 2/5] brcmfmac: Remove recursion from firmware load error
+ handling
+
+Before this commit brcmf_fw_request_done would call
+brcmf_fw_request_next_item to load the next item, which on an error would
+call brcmf_fw_request_done, which if the error is recoverable (*) will
+then continue calling brcmf_fw_request_next_item for the next item again
+which on an error will call brcmf_fw_request_done again...
+
+This does not blow up because we only have a limited number of items so
+we never recurse too deep. But the recursion is still quite ugly and
+frankly is giving me a headache, so lets fix this.
+
+This commit fixes this by removing brcmf_fw_request_next_item and by
+making brcmf_fw_get_firmwares and brcmf_fw_request_done directly call
+firmware_request_nowait resp. firmware_request themselves.
+
+*) brcmf_fw_request_nvram_done fallback path succeeds or
+ BRCMF_FW_REQF_OPTIONAL is set
+
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
+---
+ .../broadcom/brcm80211/brcmfmac/firmware.c | 65 ++++++-------------
+ 1 file changed, 19 insertions(+), 46 deletions(-)
+
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+index 848c3351d107..13d051cd0fcf 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+@@ -615,33 +615,6 @@ static int brcmf_fw_complete_request(const struct firmware *fw,
+ return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
+ }
+
+-static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
+-{
+- struct brcmf_fw_item *cur;
+- const struct firmware *fw = NULL;
+- int ret;
+-
+- cur = &fwctx->req->items[fwctx->curpos];
+-
+- brcmf_dbg(TRACE, "%srequest for %s\n", async ? "async " : "",
+- cur->path);
+-
+- if (async)
+- ret = request_firmware_nowait(THIS_MODULE, true, cur->path,
+- fwctx->dev, GFP_KERNEL, fwctx,
+- brcmf_fw_request_done);
+- else
+- ret = request_firmware(&fw, cur->path, fwctx->dev);
+-
+- if (ret < 0) {
+- brcmf_fw_request_done(NULL, fwctx);
+- } else if (!async && fw) {
+- brcmf_fw_complete_request(fw, fwctx);
+- return -EAGAIN;
+- }
+- return 0;
+-}
+-
+ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
+ {
+ struct brcmf_fw *fwctx = ctx;
+@@ -651,26 +624,19 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
+ cur = &fwctx->req->items[fwctx->curpos];
+
+ ret = brcmf_fw_complete_request(fw, fwctx);
+- if (ret < 0)
+- goto fail;
+-
+- do {
+- if (++fwctx->curpos == fwctx->req->n_items) {
+- ret = 0;
+- goto done;
+- }
+
+- ret = brcmf_fw_request_next_item(fwctx, false);
+- } while (ret == -EAGAIN);
+-
+- return;
++ while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
++ cur = &fwctx->req->items[fwctx->curpos];
++ request_firmware(&fw, cur->path, fwctx->dev);
++ ret = brcmf_fw_complete_request(fw, ctx);
++ }
+
+-fail:
+- brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
+- dev_name(fwctx->dev), cur->path);
+- brcmf_fw_free_request(fwctx->req);
+- fwctx->req = NULL;
+-done:
++ if (ret) {
++ brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
++ dev_name(fwctx->dev), cur->path);
++ brcmf_fw_free_request(fwctx->req);
++ fwctx->req = NULL;
++ }
+ fwctx->done(fwctx->dev, ret, fwctx->req);
+ kfree(fwctx);
+ }
+@@ -694,7 +660,9 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
+ void (*fw_cb)(struct device *dev, int err,
+ struct brcmf_fw_request *req))
+ {
++ struct brcmf_fw_item *first = &req->items[0];
+ struct brcmf_fw *fwctx;
++ int ret;
+
+ brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
+ if (!fw_cb)
+@@ -711,7 +679,12 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
+ fwctx->req = req;
+ fwctx->done = fw_cb;
+
+- brcmf_fw_request_next_item(fwctx, true);
++ ret = request_firmware_nowait(THIS_MODULE, true, first->path,
++ fwctx->dev, GFP_KERNEL, fwctx,
++ brcmf_fw_request_done);
++ if (ret < 0)
++ brcmf_fw_request_done(NULL, fwctx);
++
+ return 0;
+ }
+
+--
+2.19.0
+
diff --git a/0003-brcmfmac-Add-support-for-first-trying-to-get-a-board.patch b/0003-brcmfmac-Add-support-for-first-trying-to-get-a-board.patch
new file mode 100644
index 000000000..d7a3d1be3
--- /dev/null
+++ b/0003-brcmfmac-Add-support-for-first-trying-to-get-a-board.patch
@@ -0,0 +1,83 @@
+From b2c242bfc79d9a1e6c870595c33707720c7e474c Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede@redhat.com>
+Date: Fri, 28 Sep 2018 00:06:51 +0200
+Subject: [PATCH 3/5] brcmfmac: Add support for first trying to get a board
+ specific nvram file
+
+The nvram files which some brcmfmac chips need are board-specific. To be
+able to distribute these as part of linux-firmware, so that devices with
+such a wifi chip will work OOTB, multiple (one per board) versions must
+co-exist under /lib/firmware.
+
+This commit adds support for callers of the brcmfmac/firmware.c code to
+pass in a board_type parameter through the request structure.
+
+If that parameter is set then the code will first try to load
+chipmodel.board_type.txt before falling back to the old chipmodel.txt name.
+
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
+---
+ .../broadcom/brcm80211/brcmfmac/firmware.c | 27 ++++++++++++++++++-
+ .../broadcom/brcm80211/brcmfmac/firmware.h | 1 +
+ 2 files changed, 27 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+index 13d051cd0fcf..5a7cd5e01b52 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
+@@ -615,6 +615,31 @@ static int brcmf_fw_complete_request(const struct firmware *fw,
+ return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
+ }
+
++static int brcmf_fw_request_firmware(const struct firmware **fw,
++ struct brcmf_fw *fwctx)
++{
++ struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos];
++ int ret;
++
++ /* nvram files are board-specific, first try a board-specific path */
++ if (cur->type == BRCMF_FW_TYPE_NVRAM && fwctx->req->board_type) {
++ char alt_path[BRCMF_FW_NAME_LEN];
++
++ strlcpy(alt_path, cur->path, BRCMF_FW_NAME_LEN);
++ /* strip .txt at the end */
++ alt_path[strlen(alt_path) - 4] = 0;
++ strlcat(alt_path, ".", BRCMF_FW_NAME_LEN);
++ strlcat(alt_path, fwctx->req->board_type, BRCMF_FW_NAME_LEN);
++ strlcat(alt_path, ".txt", BRCMF_FW_NAME_LEN);
++
++ ret = request_firmware(fw, alt_path, fwctx->dev);
++ if (ret == 0)
++ return ret;
++ }
++
++ return request_firmware(fw, cur->path, fwctx->dev);
++}
++
+ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
+ {
+ struct brcmf_fw *fwctx = ctx;
+@@ -627,7 +652,7 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
+
+ while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
+ cur = &fwctx->req->items[fwctx->curpos];
+- request_firmware(&fw, cur->path, fwctx->dev);
++ brcmf_fw_request_firmware(&fw, fwctx);
+ ret = brcmf_fw_complete_request(fw, ctx);
+ }
+
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
+index 2893e56910f0..a0834be8864e 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
+@@ -70,6 +70,7 @@ struct brcmf_fw_request {
+ u16 domain_nr;
+ u16 bus_nr;
+ u32 n_items;
++ const char *board_type;
+ struct brcmf_fw_item items[0];
+ };
+
+--
+2.19.0
+
diff --git a/0004-brcmfmac-Set-board_type-used-for-nvram-file-selectio.patch b/0004-brcmfmac-Set-board_type-used-for-nvram-file-selectio.patch
new file mode 100644
index 000000000..b745abf41
--- /dev/null
+++ b/0004-brcmfmac-Set-board_type-used-for-nvram-file-selectio.patch
@@ -0,0 +1,87 @@
+From 3a96d5ede49bb9259416a5c21b5e1a1ad5cbb2e1 Mon Sep 17 00:00:00 2001
+From: Hans de Goede <hdegoede@redhat.com>
+Date: Fri, 28 Sep 2018 19:23:31 +0200
+Subject: [PATCH 4/5] brcmfmac: Set board_type used for nvram file selection to
+ machine-compatible
+
+For of/devicetree using machines, set the board_type used for nvram file
+selection to the first string listed in the top-level's node compatible
+string, aka the machine-compatible as used by of_machine_is_compatible().
+
+The board_type setting is used to load the board-specific nvram file with
+a board-specific name so that we can ship files for each supported board
+in linux-firmware.
+
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
+---
+ .../net/wireless/broadcom/brcm80211/brcmfmac/common.h | 1 +
+ drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c | 11 ++++++++++-
+ .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 1 +
+ .../net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 1 +
+ 4 files changed, 13 insertions(+), 1 deletion(-)
+
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
+index a34642cb4d2f..e63a273642e9 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
+@@ -59,6 +59,7 @@ struct brcmf_mp_device {
+ bool iapp;
+ bool ignore_probe_fail;
+ struct brcmfmac_pd_cc *country_codes;
++ const char *board_type;
+ union {
+ struct brcmfmac_sdio_pd sdio;
+ } bus;
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+index aee6e5937c41..84e3373289eb 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/of.c
+@@ -27,11 +27,20 @@ void brcmf_of_probe(struct device *dev, enum brcmf_bus_type bus_type,
+ struct brcmf_mp_device *settings)
+ {
+ struct brcmfmac_sdio_pd *sdio = &settings->bus.sdio;
+- struct device_node *np = dev->of_node;
++ struct device_node *root, *np = dev->of_node;
++ struct property *prop;
+ int irq;
+ u32 irqf;
+ u32 val;
+
++ /* Set board-type to the first string of the machine compatible prop */
++ root = of_find_node_by_path("/");
++ if (root) {
++ prop = of_find_property(root, "compatible", NULL);
++ settings->board_type = of_prop_next_string(prop, NULL);
++ of_node_put(root);
++ }
++
+ if (!np || bus_type != BRCMF_BUSTYPE_SDIO ||
+ !of_device_is_compatible(np, "brcm,bcm4329-fmac"))
+ return;
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+index 4fffa6988087..b12f3e0ee69c 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+@@ -1785,6 +1785,7 @@ brcmf_pcie_prepare_fw_request(struct brcmf_pciedev_info *devinfo)
+ fwreq->items[BRCMF_PCIE_FW_CODE].type = BRCMF_FW_TYPE_BINARY;
+ fwreq->items[BRCMF_PCIE_FW_NVRAM].type = BRCMF_FW_TYPE_NVRAM;
+ fwreq->items[BRCMF_PCIE_FW_NVRAM].flags = BRCMF_FW_REQF_OPTIONAL;
++ fwreq->board_type = devinfo->settings->board_type;
+ /* NVRAM reserves PCI domain 0 for Broadcom's SDK faked bus */
+ fwreq->domain_nr = pci_domain_nr(devinfo->pdev->bus) + 1;
+ fwreq->bus_nr = devinfo->pdev->bus->number;
+diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+index a907d7b065fa..3dbbbb117563 100644
+--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+@@ -4177,6 +4177,7 @@ brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus)
+
+ fwreq->items[BRCMF_SDIO_FW_CODE].type = BRCMF_FW_TYPE_BINARY;
+ fwreq->items[BRCMF_SDIO_FW_NVRAM].type = BRCMF_FW_TYPE_NVRAM;
++ fwreq->board_type = bus->sdiodev->settings->board_type;
+
+ return fwreq;
+ }
+--
+2.19.0
+
diff --git a/kernel.spec b/kernel.spec
index b0abe1e03..8528289ae 100644
--- a/kernel.spec
+++ b/kernel.spec
@@ -593,6 +593,12 @@ Patch310: gpio-pxa-handle-corner-case-of-unprobed-device.patch
Patch330: bcm2835-cpufreq-add-CPU-frequency-control-driver.patch
+# Patches enabling device specific brcm firmware nvram
+Patch340: 0001-brcmfmac-Remove-firmware-loading-code-duplication.patch
+Patch341: 0002-brcmfmac-Remove-recursion-from-firmware-load-error-h.patch
+Patch342: 0003-brcmfmac-Add-support-for-first-trying-to-get-a-board.patch
+Patch343: 0004-brcmfmac-Set-board_type-used-for-nvram-file-selectio.patch
+
# Fix for AllWinner A64 Timer Errata, still not final
# https://patchwork.kernel.org/patch/10392891/
Patch350: arm64-arch_timer-Workaround-for-Allwinner-A64-timer-instability.patch
@@ -1877,6 +1883,9 @@ fi
#
#
%changelog
+* Mon Oct 1 2018 Peter Robinson <pbrobinson@fedoraproject.org>
+- Support loading device specific NVRAM files on brcm WiFi devices
+
* Fri Sep 28 2018 Jeremy Cline <jcline@redhat.com> - 4.19.0-0.rc5.git3.1
- Linux v4.19-rc5-159-gad0371482b1e