b04e78c70e04865ad6a3db3b58581904a54849b3
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / brcm / 109-v5.4-brcmfmac-get-chip-s-default-RAM-info-during-PCIe-set.patch
1 From 82f93cf46d6007ffa003b2d4a2834563b6b84d21 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Thu, 29 Aug 2019 10:27:01 +0200
4 Subject: [PATCH] brcmfmac: get chip's default RAM info during PCIe setup
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Getting RAM info just once per driver's lifetime (during chip
10 recognition) is not enough as it may get adjusted later (depending on
11 the used firmware). Subsequent inits may load different firmwares so a
12 full RAM recognition is required on every PCIe setup. This is especially
13 important since implementing hardware reset on a firmware crash.
14
15 Moreover calling brcmf_chip_get_raminfo() makes sure that RAM core is
16 up. It's important as having BCMA_CORE_SYS_MEM down on BCM4366 was
17 resulting in firmware failing to initialize and following error:
18 [ 65.657546] brcmfmac 0000:01:00.0: brcmf_pcie_download_fw_nvram: Invalid shared RAM address 0x04000001
19
20 This change makes brcmf_chip_get_raminfo() call during chip recognition
21 redundant for PCIe devices but SDIO and USB still need it and it's a
22 very small overhead anyway.
23
24 Fixes: 4684997d9eea ("brcmfmac: reset PCIe bus on a firmware crash")
25 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
26 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
27 ---
28 drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c | 6 ++++--
29 drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h | 1 +
30 drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 6 ++++++
31 3 files changed, 11 insertions(+), 2 deletions(-)
32
33 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
34 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.c
35 @@ -696,8 +696,10 @@ static u32 brcmf_chip_tcm_rambase(struct
36 return 0;
37 }
38
39 -static int brcmf_chip_get_raminfo(struct brcmf_chip_priv *ci)
40 +int brcmf_chip_get_raminfo(struct brcmf_chip *pub)
41 {
42 + struct brcmf_chip_priv *ci = container_of(pub, struct brcmf_chip_priv,
43 + pub);
44 struct brcmf_core_priv *mem_core;
45 struct brcmf_core *mem;
46
47 @@ -979,7 +981,7 @@ static int brcmf_chip_recognition(struct
48 brcmf_chip_set_passive(&ci->pub);
49 }
50
51 - return brcmf_chip_get_raminfo(ci);
52 + return brcmf_chip_get_raminfo(&ci->pub);
53 }
54
55 static void brcmf_chip_disable_arm(struct brcmf_chip_priv *chip, u16 id)
56 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
57 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/chip.h
58 @@ -69,6 +69,7 @@ struct brcmf_buscore_ops {
59 void (*activate)(void *ctx, struct brcmf_chip *chip, u32 rstvec);
60 };
61
62 +int brcmf_chip_get_raminfo(struct brcmf_chip *pub);
63 struct brcmf_chip *brcmf_chip_attach(void *ctx,
64 const struct brcmf_buscore_ops *ops);
65 void brcmf_chip_detach(struct brcmf_chip *chip);
66 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
67 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
68 @@ -1770,6 +1770,12 @@ static void brcmf_pcie_setup(struct devi
69 nvram_len = fwreq->items[BRCMF_PCIE_FW_NVRAM].nv_data.len;
70 kfree(fwreq);
71
72 + ret = brcmf_chip_get_raminfo(devinfo->ci);
73 + if (ret) {
74 + brcmf_err(bus, "Failed to get RAM info\n");
75 + goto fail;
76 + }
77 +
78 /* Some of the firmwares have the size of the memory of the device
79 * defined inside the firmware. This is because part of the memory in
80 * the device is shared and the devision is determined by FW. Parse