mac80211: brcmfmac: restructuring sdio access functions
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 311-v4.16-0003-brcmfmac-Split-brcmf_sdiod_regrw_helper-up.patch
1 From 0fcc9fe0048422d66bb906eaa73cc75e11ff7345 Mon Sep 17 00:00:00 2001
2 From: Ian Molton <ian@mnementh.co.uk>
3 Date: Mon, 13 Nov 2017 21:35:40 +0100
4 Subject: [PATCH] brcmfmac: Split brcmf_sdiod_regrw_helper() up.
5
6 This large function is concealing a LOT of obscure logic about
7 how the hardware functions. Time to split it up.
8
9 This first patch splits the function into two pieces - read and write,
10 doing away with the rw flag in the process.
11
12 Signed-off-by: Ian Molton <ian@mnementh.co.uk>
13 Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
14 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
15 ---
16 .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 94 +++++++++++++++++-----
17 1 file changed, 73 insertions(+), 21 deletions(-)
18
19 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
20 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
21 @@ -302,8 +302,8 @@ static int brcmf_sdiod_request_data(stru
22 return ret;
23 }
24
25 -static int brcmf_sdiod_regrw_helper(struct brcmf_sdio_dev *sdiodev, u32 addr,
26 - u8 regsz, void *data, bool write)
27 +static int brcmf_sdiod_reg_write(struct brcmf_sdio_dev *sdiodev, u32 addr,
28 + u8 regsz, void *data)
29 {
30 u8 func;
31 s32 retry = 0;
32 @@ -324,13 +324,66 @@ static int brcmf_sdiod_regrw_helper(stru
33 func = SDIO_FUNC_1;
34
35 do {
36 - if (!write)
37 - memset(data, 0, regsz);
38 /* for retry wait for 1 ms till bus get settled down */
39 if (retry)
40 usleep_range(1000, 2000);
41 +
42 + ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
43 + data, true);
44 +
45 + } while (ret != 0 && ret != -ENOMEDIUM &&
46 + retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);
47 +
48 + if (ret == -ENOMEDIUM) {
49 + brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
50 + } else if (ret != 0) {
51 + /*
52 + * SleepCSR register access can fail when
53 + * waking up the device so reduce this noise
54 + * in the logs.
55 + */
56 + if (addr != SBSDIO_FUNC1_SLEEPCSR)
57 + brcmf_err("failed to write data F%d@0x%05x, err: %d\n",
58 + func, addr, ret);
59 + else
60 + brcmf_dbg(SDIO, "failed to write data F%d@0x%05x, err: %d\n",
61 + func, addr, ret);
62 + }
63 +
64 + return ret;
65 +}
66 +
67 +static int brcmf_sdiod_reg_read(struct brcmf_sdio_dev *sdiodev, u32 addr,
68 + u8 regsz, void *data)
69 +{
70 + u8 func;
71 + s32 retry = 0;
72 + int ret;
73 +
74 + if (sdiodev->state == BRCMF_SDIOD_NOMEDIUM)
75 + return -ENOMEDIUM;
76 +
77 + /*
78 + * figure out how to read the register based on address range
79 + * 0x00 ~ 0x7FF: function 0 CCCR and FBR
80 + * 0x10000 ~ 0x1FFFF: function 1 miscellaneous registers
81 + * The rest: function 1 silicon backplane core registers
82 + */
83 + if ((addr & ~REG_F0_REG_MASK) == 0)
84 + func = SDIO_FUNC_0;
85 + else
86 + func = SDIO_FUNC_1;
87 +
88 + do {
89 + memset(data, 0, regsz);
90 +
91 + /* for retry wait for 1 ms till bus get settled down */
92 + if (retry)
93 + usleep_range(1000, 2000);
94 +
95 ret = brcmf_sdiod_request_data(sdiodev, func, addr, regsz,
96 - data, write);
97 + data, false);
98 +
99 } while (ret != 0 && ret != -ENOMEDIUM &&
100 retry++ < SDIOH_API_ACCESS_RETRY_LIMIT);
101
102 @@ -343,12 +396,13 @@ static int brcmf_sdiod_regrw_helper(stru
103 * in the logs.
104 */
105 if (addr != SBSDIO_FUNC1_SLEEPCSR)
106 - brcmf_err("failed to %s data F%d@0x%05x, err: %d\n",
107 - write ? "write" : "read", func, addr, ret);
108 + brcmf_err("failed to read data F%d@0x%05x, err: %d\n",
109 + func, addr, ret);
110 else
111 - brcmf_dbg(SDIO, "failed to %s data F%d@0x%05x, err: %d\n",
112 - write ? "write" : "read", func, addr, ret);
113 + brcmf_dbg(SDIO, "failed to read data F%d@0x%05x, err: %d\n",
114 + func, addr, ret);
115 }
116 +
117 return ret;
118 }
119
120 @@ -366,13 +420,11 @@ brcmf_sdiod_set_sbaddr_window(struct brc
121 addr[2] = (address >> 24) & SBSDIO_SBADDRHIGH_MASK;
122
123 for (i = 0; i < 3; i++) {
124 - err = brcmf_sdiod_regrw_helper(sdiodev,
125 - SBSDIO_FUNC1_SBADDRLOW + i,
126 - 1, &addr[i], true);
127 + brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_SBADDRLOW + i, addr[i],
128 + &err);
129 if (err) {
130 brcmf_err("failed at addr: 0x%0x\n",
131 SBSDIO_FUNC1_SBADDRLOW + i);
132 - break;
133 }
134 }
135
136 @@ -407,8 +459,7 @@ u8 brcmf_sdiod_regrb(struct brcmf_sdio_d
137 int retval;
138
139 brcmf_dbg(SDIO, "addr:0x%08x\n", addr);
140 - retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 1, &data,
141 - false);
142 + retval = brcmf_sdiod_reg_read(sdiodev, addr, 1, &data);
143 brcmf_dbg(SDIO, "data:0x%02x\n", data);
144
145 if (ret)
146 @@ -426,8 +477,9 @@ u32 brcmf_sdiod_regrl(struct brcmf_sdio_
147 retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
148 if (retval)
149 goto done;
150 - retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 4, &data,
151 - false);
152 +
153 + retval = brcmf_sdiod_reg_read(sdiodev, addr, 4, &data);
154 +
155 brcmf_dbg(SDIO, "data:0x%08x\n", data);
156
157 done:
158 @@ -443,8 +495,8 @@ void brcmf_sdiod_regwb(struct brcmf_sdio
159 int retval;
160
161 brcmf_dbg(SDIO, "addr:0x%08x, data:0x%02x\n", addr, data);
162 - retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 1, &data,
163 - true);
164 + retval = brcmf_sdiod_reg_write(sdiodev, addr, 1, &data);
165 +
166 if (ret)
167 *ret = retval;
168 }
169 @@ -458,8 +510,8 @@ void brcmf_sdiod_regwl(struct brcmf_sdio
170 retval = brcmf_sdiod_addrprep(sdiodev, 4, &addr);
171 if (retval)
172 goto done;
173 - retval = brcmf_sdiod_regrw_helper(sdiodev, addr, 4, &data,
174 - true);
175 +
176 + retval = brcmf_sdiod_reg_write(sdiodev, addr, 4, &data);
177
178 done:
179 if (ret)