4354a7081c1004e9aa90ee1b8f71aae0d4d09826
[openwrt/staging/neocturne.git] /
1 From 00eb62cfc5f806b003fe5d54c8b5fe9a9665482f Mon Sep 17 00:00:00 2001
2 From: Ian Molton <ian@mnementh.co.uk>
3 Date: Tue, 19 Dec 2017 13:47:13 +0100
4 Subject: [PATCH] brcmfmac: Replace function index with function pointer
5
6 In preparation for removing the function array, remove all code that
7 refers to function by index and replace with pointers to the function
8 itself.
9
10 Signed-off-by: Ian Molton <ian@mnementh.co.uk>
11 Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
12 [arend: replace BUG() with WARN() macro]
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 | 85 ++++++++++++----------
17 .../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 15 ++--
18 .../wireless/broadcom/brcm80211/brcmfmac/sdio.h | 6 +-
19 3 files changed, 56 insertions(+), 50 deletions(-)
20
21 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
22 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
23 @@ -291,8 +291,9 @@ out:
24 *ret = retval;
25 }
26
27 -static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev, uint fn,
28 - u32 addr, struct sk_buff *pkt)
29 +static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev,
30 + struct sdio_func *func, u32 addr,
31 + struct sk_buff *pkt)
32 {
33 unsigned int req_sz;
34 int err;
35 @@ -301,13 +302,19 @@ static int brcmf_sdiod_buff_read(struct
36 req_sz = pkt->len + 3;
37 req_sz &= (uint)~3;
38
39 - if (fn == 1)
40 - err = sdio_memcpy_fromio(sdiodev->func[fn],
41 - ((u8 *)(pkt->data)), addr, req_sz);
42 - else
43 - /* function 2 read is FIFO operation */
44 - err = sdio_readsb(sdiodev->func[fn],
45 - ((u8 *)(pkt->data)), addr, req_sz);
46 + switch (func->num) {
47 + case 1:
48 + err = sdio_memcpy_fromio(func, ((u8 *)(pkt->data)), addr,
49 + req_sz);
50 + break;
51 + case 2:
52 + err = sdio_readsb(func, ((u8 *)(pkt->data)), addr, req_sz);
53 + break;
54 + default:
55 + /* bail out as things are really fishy here */
56 + WARN(1, "invalid sdio function number: %d\n", func->num);
57 + err = -ENOMEDIUM;
58 + };
59
60 if (err == -ENOMEDIUM)
61 brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
62 @@ -315,8 +322,9 @@ static int brcmf_sdiod_buff_read(struct
63 return err;
64 }
65
66 -static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
67 - u32 addr, struct sk_buff *pkt)
68 +static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev,
69 + struct sdio_func *func, u32 addr,
70 + struct sk_buff *pkt)
71 {
72 unsigned int req_sz;
73 int err;
74 @@ -325,8 +333,7 @@ static int brcmf_sdiod_buff_write(struct
75 req_sz = pkt->len + 3;
76 req_sz &= (uint)~3;
77
78 - err = sdio_memcpy_toio(sdiodev->func[fn], addr,
79 - ((u8 *)(pkt->data)), req_sz);
80 + err = sdio_memcpy_toio(func, addr, ((u8 *)(pkt->data)), req_sz);
81
82 if (err == -ENOMEDIUM)
83 brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
84 @@ -337,7 +344,7 @@ static int brcmf_sdiod_buff_write(struct
85 /**
86 * brcmf_sdiod_sglist_rw - SDIO interface function for block data access
87 * @sdiodev: brcmfmac sdio device
88 - * @fn: SDIO function number
89 + * @func: SDIO function
90 * @write: direction flag
91 * @addr: dongle memory address as source/destination
92 * @pkt: skb pointer
93 @@ -346,7 +353,8 @@ static int brcmf_sdiod_buff_write(struct
94 * stack for block data access. It assumes that the skb passed down by the
95 * caller has already been padded and aligned.
96 */
97 -static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev, uint fn,
98 +static int brcmf_sdiod_sglist_rw(struct brcmf_sdio_dev *sdiodev,
99 + struct sdio_func *func,
100 bool write, u32 addr,
101 struct sk_buff_head *pktlist)
102 {
103 @@ -372,7 +380,7 @@ static int brcmf_sdiod_sglist_rw(struct
104 req_sz = 0;
105 skb_queue_walk(pktlist, pkt_next)
106 req_sz += pkt_next->len;
107 - req_sz = ALIGN(req_sz, sdiodev->func[fn]->cur_blksize);
108 + req_sz = ALIGN(req_sz, func->cur_blksize);
109 while (req_sz > PAGE_SIZE) {
110 pkt_next = brcmu_pkt_buf_get_skb(PAGE_SIZE);
111 if (pkt_next == NULL) {
112 @@ -391,7 +399,7 @@ static int brcmf_sdiod_sglist_rw(struct
113 target_list = &local_list;
114 }
115
116 - func_blk_sz = sdiodev->func[fn]->cur_blksize;
117 + func_blk_sz = func->cur_blksize;
118 max_req_sz = sdiodev->max_request_size;
119 max_seg_cnt = min_t(unsigned short, sdiodev->max_segment_count,
120 target_list->qlen);
121 @@ -408,10 +416,10 @@ static int brcmf_sdiod_sglist_rw(struct
122 mmc_dat.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
123 mmc_cmd.opcode = SD_IO_RW_EXTENDED;
124 mmc_cmd.arg = write ? 1<<31 : 0; /* write flag */
125 - mmc_cmd.arg |= (fn & 0x7) << 28; /* SDIO func num */
126 - mmc_cmd.arg |= 1<<27; /* block mode */
127 + mmc_cmd.arg |= (func->num & 0x7) << 28; /* SDIO func num */
128 + mmc_cmd.arg |= 1 << 27; /* block mode */
129 /* for function 1 the addr will be incremented */
130 - mmc_cmd.arg |= (fn == 1) ? 1<<26 : 0;
131 + mmc_cmd.arg |= (func->num == 1) ? 1 << 26 : 0;
132 mmc_cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
133 mmc_req.cmd = &mmc_cmd;
134 mmc_req.data = &mmc_dat;
135 @@ -457,11 +465,11 @@ static int brcmf_sdiod_sglist_rw(struct
136 mmc_cmd.arg |= (addr & 0x1FFFF) << 9; /* address */
137 mmc_cmd.arg |= mmc_dat.blocks & 0x1FF; /* block count */
138 /* incrementing addr for function 1 */
139 - if (fn == 1)
140 + if (func->num == 1)
141 addr += req_sz;
142
143 - mmc_set_data_timeout(&mmc_dat, sdiodev->func[fn]->card);
144 - mmc_wait_for_req(sdiodev->func[fn]->card->host, &mmc_req);
145 + mmc_set_data_timeout(&mmc_dat, func->card);
146 + mmc_wait_for_req(func->card->host, &mmc_req);
147
148 ret = mmc_cmd.error ? mmc_cmd.error : mmc_dat.error;
149 if (ret == -ENOMEDIUM) {
150 @@ -541,7 +549,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sd
151 addr &= SBSDIO_SB_OFT_ADDR_MASK;
152 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
153
154 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr, pkt);
155 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr, pkt);
156
157 done:
158 return err;
159 @@ -566,13 +574,13 @@ int brcmf_sdiod_recv_chain(struct brcmf_
160 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
161
162 if (pktq->qlen == 1)
163 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
164 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
165 pktq->next);
166 else if (!sdiodev->sg_support) {
167 glom_skb = brcmu_pkt_buf_get_skb(totlen);
168 if (!glom_skb)
169 return -ENOMEM;
170 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
171 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
172 glom_skb);
173 if (err)
174 goto done;
175 @@ -582,8 +590,8 @@ int brcmf_sdiod_recv_chain(struct brcmf_
176 skb_pull(glom_skb, skb->len);
177 }
178 } else
179 - err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, false, addr,
180 - pktq);
181 + err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], false,
182 + addr, pktq);
183
184 done:
185 brcmu_pkt_buf_free_skb(glom_skb);
186 @@ -614,7 +622,8 @@ int brcmf_sdiod_send_buf(struct brcmf_sd
187 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
188
189 if (!err)
190 - err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);
191 + err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2], addr,
192 + mypkt);
193
194 brcmu_pkt_buf_free_skb(mypkt);
195
196 @@ -639,14 +648,14 @@ int brcmf_sdiod_send_pkt(struct brcmf_sd
197
198 if (pktq->qlen == 1 || !sdiodev->sg_support) {
199 skb_queue_walk(pktq, skb) {
200 - err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2,
201 + err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2],
202 addr, skb);
203 if (err)
204 break;
205 }
206 } else {
207 - err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, true, addr,
208 - pktq);
209 + err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], true,
210 + addr, pktq);
211 }
212
213 return err;
214 @@ -696,10 +705,10 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev
215
216 if (write) {
217 memcpy(pkt->data, data, dsize);
218 - err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_1,
219 + err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[1],
220 sdaddr, pkt);
221 } else {
222 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_1,
223 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[1],
224 sdaddr, pkt);
225 }
226
227 @@ -728,12 +737,12 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev
228 return err;
229 }
230
231 -int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn)
232 +int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func)
233 {
234 brcmf_dbg(SDIO, "Enter\n");
235
236 /* Issue abort cmd52 command through F0 */
237 - brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_ABORT, fn, NULL);
238 + brcmf_sdiod_func0_wb(sdiodev, SDIO_CCCR_ABORT, func->num, NULL);
239
240 brcmf_dbg(SDIO, "Exit\n");
241 return 0;
242 @@ -1105,7 +1114,7 @@ static int brcmf_ops_sdio_suspend(struct
243
244 func = container_of(dev, struct sdio_func, dev);
245 brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
246 - if (func->num != SDIO_FUNC_1)
247 + if (func->num != 1)
248 return 0;
249
250
251 @@ -1134,7 +1143,7 @@ static int brcmf_ops_sdio_resume(struct
252 struct sdio_func *func = container_of(dev, struct sdio_func, dev);
253
254 brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
255 - if (func->num != SDIO_FUNC_2)
256 + if (func->num != 2)
257 return 0;
258
259 brcmf_sdiod_freezer_off(sdiodev);
260 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
261 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
262 @@ -1157,7 +1157,7 @@ static void brcmf_sdio_rxfail(struct brc
263 rtx ? ", send NAK" : "");
264
265 if (abort)
266 - brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2);
267 + brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func[2]);
268
269 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM,
270 &err);
271 @@ -1209,7 +1209,7 @@ static void brcmf_sdio_txfail(struct brc
272 brcmf_err("sdio error, abort command and terminate frame\n");
273 bus->sdcnt.tx_sderrs++;
274
275 - brcmf_sdiod_abort(sdiodev, SDIO_FUNC_2);
276 + brcmf_sdiod_abort(sdiodev, sdiodev->func[2]);
277 brcmf_sdiod_writeb(sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_WF_TERM, NULL);
278 bus->sdcnt.f1regdata++;
279
280 @@ -2072,7 +2072,7 @@ static int brcmf_sdio_txpkt_prep_sg(stru
281 int ntail, ret;
282
283 sdiodev = bus->sdiodev;
284 - blksize = sdiodev->func[SDIO_FUNC_2]->cur_blksize;
285 + blksize = sdiodev->func[2]->cur_blksize;
286 /* sg entry alignment should be a divisor of block size */
287 WARN_ON(blksize % bus->sgentry_align);
288
289 @@ -2441,7 +2441,7 @@ static void brcmf_sdio_bus_stop(struct d
290
291 /* Turn off the bus (F2), free any pending packets */
292 brcmf_dbg(INTR, "disable SDIO interrupts\n");
293 - sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
294 + sdio_disable_func(sdiodev->func[2]);
295
296 /* Clear any pending interrupts now that F2 is disabled */
297 brcmf_sdiod_writel(sdiodev, core->base + SD_REG(intstatus),
298 @@ -4066,8 +4066,7 @@ static void brcmf_sdio_firmware_callback
299 brcmf_sdiod_writel(sdiod, core->base + SD_REG(tosbmailboxdata),
300 SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, NULL);
301
302 - err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);
303 -
304 + err = sdio_enable_func(sdiodev->func[2]);
305
306 brcmf_dbg(INFO, "enable F2: err=%d\n", err);
307
308 @@ -4082,7 +4081,7 @@ static void brcmf_sdio_firmware_callback
309 brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
310 } else {
311 /* Disable F2 again */
312 - sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
313 + sdio_disable_func(sdiodev->func[2]);
314 goto release;
315 }
316
317 @@ -4219,7 +4218,7 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
318 sdio_claim_host(bus->sdiodev->func[1]);
319
320 /* Disable F2 to clear any intermediate frame state on the dongle */
321 - sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]);
322 + sdio_disable_func(bus->sdiodev->func[2]);
323
324 bus->rxflow = false;
325
326 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
327 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
328 @@ -45,9 +45,6 @@
329 #define REG_F0_REG_MASK 0x7FF
330 #define REG_F1_MISC_MASK 0x1FFFF
331
332 -/* as of sdiod rev 0, supports 3 functions */
333 -#define SBSDIO_NUM_FUNCTION 3
334 -
335 /* function 0 vendor specific CCCR registers */
336
337 #define SDIO_CCCR_BRCM_CARDCAP 0xf0
338 @@ -350,7 +347,8 @@ int brcmf_sdiod_ramrw(struct brcmf_sdio_
339 u8 *data, uint size);
340
341 /* Issue an abort to the specified function */
342 -int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, u8 fn);
343 +int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, struct sdio_func *func);
344 +
345 void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev);
346 void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
347 enum brcmf_sdiod_state state);