mac80211: brcmfmac: restructuring sdio access functions - take 2
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 312-v4.16-0001-brcmfmac-Split-brcmf_sdiod_buffrw-function-up.patch
1 From 8f13c87ccc495e30de5f58bbda967f6edd5bec53 Mon Sep 17 00:00:00 2001
2 From: Ian Molton <ian@mnementh.co.uk>
3 Date: Fri, 8 Dec 2017 13:10:26 +0100
4 Subject: [PATCH] brcmfmac: Split brcmf_sdiod_buffrw function up.
5
6 This function needs to be split up into separate read / write variants
7 for clarity.
8
9 Signed-off-by: Ian Molton <ian@mnementh.co.uk>
10 Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
11 Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
12 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
13 ---
14 .../wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 67 +++++++++++++++-------
15 1 file changed, 45 insertions(+), 22 deletions(-)
16
17 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
18 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
19 @@ -414,8 +414,8 @@ void brcmf_sdiod_regwl(struct brcmf_sdio
20 *ret = retval;
21 }
22
23 -static int brcmf_sdiod_buffrw(struct brcmf_sdio_dev *sdiodev, uint fn,
24 - bool write, u32 addr, struct sk_buff *pkt)
25 +static int brcmf_sdiod_buff_read(struct brcmf_sdio_dev *sdiodev, uint fn,
26 + u32 addr, struct sk_buff *pkt)
27 {
28 unsigned int req_sz;
29 int err;
30 @@ -424,18 +424,36 @@ static int brcmf_sdiod_buffrw(struct brc
31 req_sz = pkt->len + 3;
32 req_sz &= (uint)~3;
33
34 - if (write)
35 - err = sdio_memcpy_toio(sdiodev->func[fn], addr,
36 - ((u8 *)(pkt->data)), req_sz);
37 - else if (fn == 1)
38 - err = sdio_memcpy_fromio(sdiodev->func[fn], ((u8 *)(pkt->data)),
39 - addr, req_sz);
40 + if (fn == 1)
41 + err = sdio_memcpy_fromio(sdiodev->func[fn],
42 + ((u8 *)(pkt->data)), addr, req_sz);
43 else
44 /* function 2 read is FIFO operation */
45 - err = sdio_readsb(sdiodev->func[fn], ((u8 *)(pkt->data)), addr,
46 - req_sz);
47 + err = sdio_readsb(sdiodev->func[fn],
48 + ((u8 *)(pkt->data)), addr, req_sz);
49 +
50 + if (err == -ENOMEDIUM)
51 + brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
52 +
53 + return err;
54 +}
55 +
56 +static int brcmf_sdiod_buff_write(struct brcmf_sdio_dev *sdiodev, uint fn,
57 + u32 addr, struct sk_buff *pkt)
58 +{
59 + unsigned int req_sz;
60 + int err;
61 +
62 + /* Single skb use the standard mmc interface */
63 + req_sz = pkt->len + 3;
64 + req_sz &= (uint)~3;
65 +
66 + err = sdio_memcpy_toio(sdiodev->func[fn], addr,
67 + ((u8 *)(pkt->data)), req_sz);
68 +
69 if (err == -ENOMEDIUM)
70 brcmf_sdiod_change_state(sdiodev, BRCMF_SDIOD_NOMEDIUM);
71 +
72 return err;
73 }
74
75 @@ -643,7 +661,7 @@ int brcmf_sdiod_recv_pkt(struct brcmf_sd
76 if (err)
77 goto done;
78
79 - err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr, pkt);
80 + err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr, pkt);
81
82 done:
83 return err;
84 @@ -665,14 +683,14 @@ int brcmf_sdiod_recv_chain(struct brcmf_
85 goto done;
86
87 if (pktq->qlen == 1)
88 - err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr,
89 - pktq->next);
90 + err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
91 + pktq->next);
92 else if (!sdiodev->sg_support) {
93 glom_skb = brcmu_pkt_buf_get_skb(totlen);
94 if (!glom_skb)
95 return -ENOMEM;
96 - err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, false, addr,
97 - glom_skb);
98 + err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_2, addr,
99 + glom_skb);
100 if (err)
101 goto done;
102
103 @@ -707,8 +725,7 @@ int brcmf_sdiod_send_buf(struct brcmf_sd
104 err = brcmf_sdiod_addrprep(sdiodev, &addr);
105
106 if (!err)
107 - err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true, addr,
108 - mypkt);
109 + err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2, addr, mypkt);
110
111 brcmu_pkt_buf_free_skb(mypkt);
112 return err;
113 @@ -730,8 +747,8 @@ int brcmf_sdiod_send_pkt(struct brcmf_sd
114
115 if (pktq->qlen == 1 || !sdiodev->sg_support)
116 skb_queue_walk(pktq, skb) {
117 - err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_2, true,
118 - addr, skb);
119 + err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_2,
120 + addr, skb);
121 if (err)
122 break;
123 }
124 @@ -783,10 +800,16 @@ brcmf_sdiod_ramrw(struct brcmf_sdio_dev
125 sdaddr |= SBSDIO_SB_ACCESS_2_4B_FLAG;
126
127 skb_put(pkt, dsize);
128 - if (write)
129 +
130 + if (write) {
131 memcpy(pkt->data, data, dsize);
132 - err = brcmf_sdiod_buffrw(sdiodev, SDIO_FUNC_1, write, sdaddr,
133 - pkt);
134 + err = brcmf_sdiod_buff_write(sdiodev, SDIO_FUNC_1,
135 + sdaddr, pkt);
136 + } else {
137 + err = brcmf_sdiod_buff_read(sdiodev, SDIO_FUNC_1,
138 + sdaddr, pkt);
139 + }
140 +
141 if (err) {
142 brcmf_err("membytes transfer failed\n");
143 break;