1 From ce2e6db554fad444fa0b3904fc3015336e0ef765 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Thu, 11 Oct 2018 11:51:06 +0200
4 Subject: [PATCH] brcmfmac: Add support for getting nvram contents from EFI
7 Various X86 laptops with a SDIO attached brcmfmac wifi chip, store the
8 nvram contents in a special EFI variable. This commit adds support for
9 getting nvram directly from this EFI variable, without the user needing
12 This makes Wifi / Bluetooth work out of the box on these devices instead of
13 requiring manual setup.
15 This has been tested on the following models: Acer Iconia Tab8 w1-810,
16 Acer One 10, Asus T100CHI, Asus T100HA, Asus T100TA, Asus T200TA and a
19 Tested-by: Hans de Goede <hdegoede@redhat.com>
20 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
21 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
23 .../broadcom/brcm80211/brcmfmac/firmware.c | 63 +++++++++++++++++++---
24 1 file changed, 57 insertions(+), 6 deletions(-)
26 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
27 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
29 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 +#include <linux/efi.h>
33 #include <linux/kernel.h>
34 #include <linux/slab.h>
35 #include <linux/device.h>
36 @@ -445,6 +446,51 @@ struct brcmf_fw {
38 static void brcmf_fw_request_done(const struct firmware *fw, void *ctx);
41 +static u8 *brcmf_fw_nvram_from_efi(size_t *data_len_ret)
43 + const u16 name[] = { 'n', 'v', 'r', 'a', 'm', 0 };
44 + struct efivar_entry *nvram_efivar;
45 + unsigned long data_len = 0;
49 + nvram_efivar = kzalloc(sizeof(*nvram_efivar), GFP_KERNEL);
53 + memcpy(&nvram_efivar->var.VariableName, name, sizeof(name));
54 + nvram_efivar->var.VendorGuid = EFI_GUID(0x74b00bd9, 0x805a, 0x4d61,
55 + 0xb5, 0x1f, 0x43, 0x26,
56 + 0x81, 0x23, 0xd1, 0x13);
58 + err = efivar_entry_size(nvram_efivar, &data_len);
62 + data = kmalloc(data_len, GFP_KERNEL);
66 + err = efivar_entry_get(nvram_efivar, NULL, &data_len, data);
70 + brcmf_info("Using nvram EFI variable\n");
72 + kfree(nvram_efivar);
73 + *data_len_ret = data_len;
78 + kfree(nvram_efivar);
82 +static u8 *brcmf_fw_nvram_from_efi(size_t *data_len) { return NULL; }
85 static void brcmf_fw_free_request(struct brcmf_fw_request *req)
87 struct brcmf_fw_item *item;
88 @@ -463,11 +509,12 @@ static int brcmf_fw_request_nvram_done(c
90 struct brcmf_fw *fwctx = ctx;
91 struct brcmf_fw_item *cur;
92 + bool free_bcm47xx_nvram = false;
93 + bool kfree_nvram = false;
100 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(fwctx->dev));
102 @@ -476,12 +523,13 @@ static int brcmf_fw_request_nvram_done(c
103 if (fw && fw->data) {
104 data = (u8 *)fw->data;
108 - data = bcm47xx_nvram_get_contents(&data_len);
109 - if (!data && !(cur->flags & BRCMF_FW_REQF_OPTIONAL))
110 + if ((data = bcm47xx_nvram_get_contents(&data_len)))
111 + free_bcm47xx_nvram = true;
112 + else if ((data = brcmf_fw_nvram_from_efi(&data_len)))
113 + kfree_nvram = true;
114 + else if (!(cur->flags & BRCMF_FW_REQF_OPTIONAL))
120 @@ -489,8 +537,11 @@ static int brcmf_fw_request_nvram_done(c
121 fwctx->req->domain_nr,
125 + if (free_bcm47xx_nvram)
126 bcm47xx_nvram_release_contents(data);
130 release_firmware(fw);
131 if (!nvram && !(cur->flags & BRCMF_FW_REQF_OPTIONAL))