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
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
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>
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(-)
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:
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)
35 @@ -301,13 +302,19 @@ static int brcmf_sdiod_buff_read(struct
36 req_sz = pkt->len + 3;
40 - err = sdio_memcpy_fromio(sdiodev->func[fn],
41 - ((u8 *)(pkt->data)), addr, req_sz);
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) {
48 + err = sdio_memcpy_fromio(func, ((u8 *)(pkt->data)), addr,
52 + err = sdio_readsb(func, ((u8 *)(pkt->data)), addr, req_sz);
55 + /* bail out as things are really fishy here */
56 + WARN(1, "invalid sdio function number: %d\n", func->num);
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
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)
74 @@ -325,8 +333,7 @@ static int brcmf_sdiod_buff_write(struct
75 req_sz = pkt->len + 3;
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);
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
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
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.
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)
103 @@ -372,7 +380,7 @@ static int brcmf_sdiod_sglist_rw(struct
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;
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,
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 */
140 + if (func->num == 1)
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);
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;
154 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr, pkt);
155 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr, pkt);
159 @@ -566,13 +574,13 @@ int brcmf_sdiod_recv_chain(struct brcmf_
160 addr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
163 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
164 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
166 else if (!sdiodev->sg_support) {
167 glom_skb = brcmu_pkt_buf_get_skb(totlen);
170 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
171 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[2], addr,
175 @@ -582,8 +590,8 @@ int brcmf_sdiod_recv_chain(struct brcmf_
176 skb_pull(glom_skb, skb->len);
179 - err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, false, addr,
181 + err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], false,
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;
190 - err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);
191 + err = brcmf_sdiod_buff_write(sdiodev, sdiodev->func[2], addr,
194 brcmu_pkt_buf_free_skb(mypkt);
196 @@ -639,14 +648,14 @@ int brcmf_sdiod_send_pkt(struct brcmf_sd
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],
207 - err = brcmf_sdiod_sglist_rw(sdiodev, SDIO_FUNC_2, true, addr,
209 + err = brcmf_sdiod_sglist_rw(sdiodev, sdiodev->func[2], true,
214 @@ -696,10 +705,10 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev
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],
222 - err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_1,
223 + err = brcmf_sdiod_buff_read(sdiodev, sdiodev->func[1],
227 @@ -728,12 +737,12 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev
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)
234 brcmf_dbg(SDIO, "Enter\n");
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);
240 brcmf_dbg(SDIO, "Exit\n");
242 @@ -1105,7 +1114,7 @@ static int brcmf_ops_sdio_suspend(struct
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)
251 @@ -1134,7 +1143,7 @@ static int brcmf_ops_sdio_resume(struct
252 struct sdio_func *func = container_of(dev, struct sdio_func, dev);
254 brcmf_dbg(SDIO, "Enter: F%d\n", func->num);
255 - if (func->num != SDIO_FUNC_2)
256 + if (func->num != 2)
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" : "");
266 - brcmf_sdiod_abort(bus->sdiodev, SDIO_FUNC_2);
267 + brcmf_sdiod_abort(bus->sdiodev, bus->sdiodev->func[2]);
269 brcmf_sdiod_writeb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM,
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++;
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++;
280 @@ -2072,7 +2072,7 @@ static int brcmf_sdio_txpkt_prep_sg(stru
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);
289 @@ -2441,7 +2441,7 @@ static void brcmf_sdio_bus_stop(struct d
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]);
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);
302 - err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);
304 + err = sdio_enable_func(sdiodev->func[2]);
306 brcmf_dbg(INFO, "enable F2: err=%d\n", err);
308 @@ -4082,7 +4081,7 @@ static void brcmf_sdio_firmware_callback
309 brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
311 /* Disable F2 again */
312 - sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
313 + sdio_disable_func(sdiodev->func[2]);
317 @@ -4219,7 +4218,7 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
318 sdio_claim_host(bus->sdiodev->func[1]);
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]);
326 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
327 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
329 #define REG_F0_REG_MASK 0x7FF
330 #define REG_F1_MISC_MASK 0x1FFFF
332 -/* as of sdiod rev 0, supports 3 functions */
333 -#define SBSDIO_NUM_FUNCTION 3
335 /* function 0 vendor specific CCCR registers */
337 #define SDIO_CCCR_BRCM_CARDCAP 0xf0
338 @@ -350,7 +347,8 @@ int brcmf_sdiod_ramrw(struct brcmf_sdio_
339 u8 *data, uint size);
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);
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);