mac80211: brcm: improve brcmfmac debugging of firmware crashes
[oweals/openwrt.git] / package / kernel / mac80211 / patches / brcm / 865-brcmfmac-get-RAM-info-right-before-downloading-PCIe-.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
2 Subject: [PATCH] brcmfmac: get RAM info right before downloading PCIe firmware
3 MIME-Version: 1.0
4 Content-Type: text/plain; charset=UTF-8
5 Content-Transfer-Encoding: 8bit
6
7 It's important as brcmf_chip_get_raminfo() also makes sure that memory
8 is properly setup. Without it the firmware could report invalid RAM
9 address like 0x04000001.
10
11 During a normal brcmfmac lifetime brcmf_chip_get_raminfo() is called on
12 probe by the brcmf_chip_recognition(). This change allows implementing
13 further improvements like handling errors by resetting a device with
14 the brcmf_pcie_reset_device() and redownloading a firmware afterwards.
15
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 ---
18  drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c | 6 ++++--
19  drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h | 1 +
20  drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 6 ++++++
21  3 files changed, 11 insertions(+), 2 deletions(-)
22
23 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
24 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
25 @@ -696,8 +696,10 @@ static u32 brcmf_chip_tcm_rambase(struct
26         return 0;
27  }
28  
29 -static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
30 +int brcmf_chip_get_raminfo(struct brcmf_chip *pub)
31  {
32 +       struct brcmf_chip_priv *ci = container_of(pub, struct brcmf_chip_priv,
33 +                                                 pub);
34         struct brcmf_core_priv *mem_core;
35         struct brcmf_core *mem;
36  
37 @@ -979,7 +981,7 @@ static int brcmf_chip_recognition(struct
38                 brcmf_chip_set_passive(&ci->pub);
39         }
40  
41 -       return brcmf_chip_get_raminfo(ci);
42 +       return brcmf_chip_get_raminfo(&ci->pub);
43  }
44  
45  static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
46 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
47 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
48 @@ -69,6 +69,7 @@ struct brcmf_buscore_ops {
49         void (*activate)(void *ctx, struct brcmf_chip *chip, u32 rstvec);
50  };
51  
52 +int brcmf_chip_get_raminfo(struct brcmf_chip *pub);
53  struct brcmf_chip *brcmf_chip_attach(void *ctx,
54                                      const struct brcmf_buscore_ops *ops);
55  void brcmf_chip_detach(struct brcmf_chip *chip);
56 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
57 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
58 @@ -1770,6 +1770,12 @@ static void brcmf_pcie_setup(struct devi
59         nvram_len = fwreq->items[BRCMF_PCIE_FW_NVRAM].nv_data.len;
60         kfree(fwreq);
61  
62 +       ret = brcmf_chip_get_raminfo(devinfo->ci);
63 +       if (ret) {
64 +               brcmf_err(bus, "Failed to get RAM info\n");
65 +               goto fail;
66 +       }
67 +
68         /* Some of the firmwares have the size of the memory of the device
69          * defined inside the firmware. This is because part of the memory in
70          * the device is shared and the devision is determined by FW. Parse