mac80211: backport brcmfmac patchset with driver setting concept
[openwrt.git] / package / kernel / mac80211 / patches / 344-0008-brcmfmac-use-device-memsize-config-from-fw-if-define.patch
1 From: Hante Meuleman <meuleman@broadcom.com>
2 Date: Wed, 17 Feb 2016 11:26:57 +0100
3 Subject: [PATCH] brcmfmac: use device memsize config from fw if defined
4
5 Newer type pcie devices have memory which get shared between fw and
6 hw. The division of this memory is done firmware compile time. As a
7 result the ramsize as used by driver needs to be adjusted for this.
8 This is done by reading the memory size from the firmware.
9
10 Reviewed-by: Arend Van Spriel <arend@broadcom.com>
11 Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
12 Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
13 Signed-off-by: Hante Meuleman <meuleman@broadcom.com>
14 Signed-off-by: Arend van Spriel <arend@broadcom.com>
15 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
16 ---
17
18 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
19 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
20 @@ -207,6 +207,10 @@ static struct brcmf_firmware_mapping brc
21  #define BRCMF_PCIE_CFGREG_REG_BAR3_CONFIG      0x4F4
22  #define BRCMF_PCIE_LINK_STATUS_CTRL_ASPM_ENAB  3
23  
24 +/* Magic number at a magic location to find RAM size */
25 +#define BRCMF_RAMSIZE_MAGIC                    0x534d4152      /* SMAR */
26 +#define BRCMF_RAMSIZE_OFFSET                   0x6c
27 +
28  
29  struct brcmf_pcie_console {
30         u32 base_addr;
31 @@ -1412,6 +1416,28 @@ static const struct brcmf_bus_ops brcmf_
32  };
33  
34  
35 +static void
36 +brcmf_pcie_adjust_ramsize(struct brcmf_pciedev_info *devinfo, u8 *data,
37 +                         u32 data_len)
38 +{
39 +       __le32 *field;
40 +       u32 newsize;
41 +
42 +       if (data_len < BRCMF_RAMSIZE_OFFSET + 8)
43 +               return;
44 +
45 +       field = (__le32 *)&data[BRCMF_RAMSIZE_OFFSET];
46 +       if (le32_to_cpup(field) != BRCMF_RAMSIZE_MAGIC)
47 +               return;
48 +       field++;
49 +       newsize = le32_to_cpup(field);
50 +
51 +       brcmf_dbg(PCIE, "Found ramsize info in FW, adjusting to 0x%x\n",
52 +                 newsize);
53 +       devinfo->ci->ramsize = newsize;
54 +}
55 +
56 +
57  static int
58  brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo,
59                                u32 sharedram_addr)
60 @@ -1694,6 +1720,13 @@ static void brcmf_pcie_setup(struct devi
61  
62         brcmf_pcie_attach(devinfo);
63  
64 +       /* Some of the firmwares have the size of the memory of the device
65 +        * defined inside the firmware. This is because part of the memory in
66 +        * the device is shared and the devision is determined by FW. Parse
67 +        * the firmware and adjust the chip memory size now.
68 +        */
69 +       brcmf_pcie_adjust_ramsize(devinfo, (u8 *)fw->data, fw->size);
70 +
71         ret = brcmf_pcie_download_fw_nvram(devinfo, fw, nvram, nvram_len);
72         if (ret)
73                 goto fail;