mt76: update to the latest version
[oweals/openwrt.git] / package / kernel / mac80211 / patches / 314-v4.16-0001-brcmfmac-Remove-r-w-_sdreg32.patch
1 From 3d110df8f74781354051e4bb1e3e97fa368b2f80 Mon Sep 17 00:00:00 2001
2 From: Ian Molton <ian@mnementh.co.uk>
3 Date: Tue, 19 Dec 2017 13:47:07 +0100
4 Subject: [PATCH] brcmfmac: Remove {r,w}_sdreg32
5
6 Remove yet another IO function from the code and replace with one
7 that already exists.
8
9 Signed-off-by: Ian Molton <ian@mnementh.co.uk>
10 Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
11 [arend: keep address calculation, ie. (base + offset) in one line]
12 Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
13 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
14 ---
15  .../wireless/broadcom/brcm80211/brcmfmac/sdio.c    | 88 +++++++++++-----------
16  1 file changed, 42 insertions(+), 46 deletions(-)
17
18 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
19 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
20 @@ -660,30 +660,6 @@ static bool data_ok(struct brcmf_sdio *b
21                ((u8)(bus->tx_max - bus->tx_seq) & 0x80) == 0;
22  }
23  
24 -/*
25 - * Reads a register in the SDIO hardware block. This block occupies a series of
26 - * adresses on the 32 bit backplane bus.
27 - */
28 -static int r_sdreg32(struct brcmf_sdio *bus, u32 *regvar, u32 offset)
29 -{
30 -       struct brcmf_core *core = bus->sdio_core;
31 -       int ret;
32 -
33 -       *regvar = brcmf_sdiod_readl(bus->sdiodev, core->base + offset, &ret);
34 -
35 -       return ret;
36 -}
37 -
38 -static int w_sdreg32(struct brcmf_sdio *bus, u32 regval, u32 reg_offset)
39 -{
40 -       struct brcmf_core *core = bus->sdio_core;
41 -       int ret;
42 -
43 -       brcmf_sdiod_writel(bus->sdiodev, core->base + reg_offset, regval, &ret);
44 -
45 -       return ret;
46 -}
47 -
48  static int
49  brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
50  {
51 @@ -1078,6 +1054,8 @@ static void brcmf_sdio_get_console_addr(
52  
53  static u32 brcmf_sdio_hostmail(struct brcmf_sdio *bus)
54  {
55 +       struct brcmf_sdio_dev *sdiod = bus->sdiodev;
56 +       struct brcmf_core *core = bus->sdio_core;
57         u32 intstatus = 0;
58         u32 hmb_data;
59         u8 fcbits;
60 @@ -1086,10 +1064,14 @@ static u32 brcmf_sdio_hostmail(struct br
61         brcmf_dbg(SDIO, "Enter\n");
62  
63         /* Read mailbox data and ack that we did so */
64 -       ret = r_sdreg32(bus, &hmb_data, SD_REG(tohostmailboxdata));
65 +       hmb_data = brcmf_sdiod_readl(sdiod,
66 +                                    core->base + SD_REG(tohostmailboxdata),
67 +                                    &ret);
68 +
69 +       if (!ret)
70 +               brcmf_sdiod_writel(sdiod, core->base + SD_REG(tosbmailbox),
71 +                                  SMB_INT_ACK, &ret);
72  
73 -       if (ret == 0)
74 -               w_sdreg32(bus, SMB_INT_ACK, SD_REG(tosbmailbox));
75         bus->sdcnt.f1regdata += 2;
76  
77         /* dongle indicates the firmware has halted/crashed */
78 @@ -1163,6 +1145,8 @@ static u32 brcmf_sdio_hostmail(struct br
79  
80  static void brcmf_sdio_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
81  {
82 +       struct brcmf_sdio_dev *sdiod = bus->sdiodev;
83 +       struct brcmf_core *core = bus->sdio_core;
84         uint retries = 0;
85         u16 lastrbc;
86         u8 hi, lo;
87 @@ -1204,7 +1188,8 @@ static void brcmf_sdio_rxfail(struct brc
88  
89         if (rtx) {
90                 bus->sdcnt.rxrtx++;
91 -               err = w_sdreg32(bus, SMB_NAK, SD_REG(tosbmailbox));
92 +               brcmf_sdiod_writel(sdiod, core->base + SD_REG(tosbmailbox),
93 +                                  SMB_NAK, &err);
94  
95                 bus->sdcnt.f1regdata++;
96                 if (err == 0)
97 @@ -2291,6 +2276,7 @@ static uint brcmf_sdio_sendfromq(struct
98  {
99         struct sk_buff *pkt;
100         struct sk_buff_head pktq;
101 +       u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus);
102         u32 intstatus = 0;
103         int ret = 0, prec_out, i;
104         uint cnt = 0;
105 @@ -2329,7 +2315,8 @@ static uint brcmf_sdio_sendfromq(struct
106                 if (!bus->intr) {
107                         /* Check device status, signal pending interrupt */
108                         sdio_claim_host(bus->sdiodev->func[1]);
109 -                       ret = r_sdreg32(bus, &intstatus, SD_REG(intstatus));
110 +                       intstatus = brcmf_sdiod_readl(bus->sdiodev,
111 +                                                     intstat_addr, &ret);
112                         sdio_release_host(bus->sdiodev->func[1]);
113                         bus->sdcnt.f2txdata++;
114                         if (ret != 0)
115 @@ -2413,12 +2400,13 @@ static int brcmf_sdio_tx_ctrlframe(struc
116  
117  static void brcmf_sdio_bus_stop(struct device *dev)
118  {
119 -       u32 local_hostintmask;
120 -       u8 saveclk;
121 -       int err;
122         struct brcmf_bus *bus_if = dev_get_drvdata(dev);
123         struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
124         struct brcmf_sdio *bus = sdiodev->bus;
125 +       struct brcmf_core *core = bus->sdio_core;
126 +       u32 local_hostintmask;
127 +       u8 saveclk;
128 +       int err;
129  
130         brcmf_dbg(TRACE, "Enter\n");
131  
132 @@ -2435,7 +2423,9 @@ static void brcmf_sdio_bus_stop(struct d
133                 brcmf_sdio_bus_sleep(bus, false, false);
134  
135                 /* Disable and clear interrupts at the chip level also */
136 -               w_sdreg32(bus, 0, SD_REG(hostintmask));
137 +               brcmf_sdiod_writel(sdiodev, core->base + SD_REG(hostintmask),
138 +                                  0, NULL);
139 +
140                 local_hostintmask = bus->hostintmask;
141                 bus->hostintmask = 0;
142  
143 @@ -2454,7 +2444,8 @@ static void brcmf_sdio_bus_stop(struct d
144                 sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
145  
146                 /* Clear any pending interrupts now that F2 is disabled */
147 -               w_sdreg32(bus, local_hostintmask, SD_REG(intstatus));
148 +               brcmf_sdiod_writel(sdiodev, core->base + SD_REG(intstatus),
149 +                                  local_hostintmask, NULL);
150  
151                 sdio_release_host(sdiodev->func[1]);
152         }
153 @@ -2521,7 +2512,9 @@ static int brcmf_sdio_intr_rstatus(struc
154  
155  static void brcmf_sdio_dpc(struct brcmf_sdio *bus)
156  {
157 +       struct brcmf_sdio_dev *sdiod = bus->sdiodev;
158         u32 newstatus = 0;
159 +       u32 intstat_addr = bus->sdio_core->base + SD_REG(intstatus);
160         unsigned long intstatus;
161         uint txlimit = bus->txbound;    /* Tx frames to send before resched */
162         uint framecnt;                  /* Temporary counter of tx/rx frames */
163 @@ -2576,9 +2569,10 @@ static void brcmf_sdio_dpc(struct brcmf_
164          */
165         if (intstatus & I_HMB_FC_CHANGE) {
166                 intstatus &= ~I_HMB_FC_CHANGE;
167 -               err = w_sdreg32(bus, I_HMB_FC_CHANGE, SD_REG(intstatus));
168 +               brcmf_sdiod_writel(sdiod, intstat_addr, I_HMB_FC_CHANGE, &err);
169 +
170 +               newstatus = brcmf_sdiod_readl(sdiod, intstat_addr, &err);
171  
172 -               err = r_sdreg32(bus, &newstatus, SD_REG(intstatus));
173                 bus->sdcnt.f1regdata += 2;
174                 atomic_set(&bus->fcstate,
175                            !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)));
176 @@ -4017,22 +4011,21 @@ static void brcmf_sdio_firmware_callback
177                                          const struct firmware *code,
178                                          void *nvram, u32 nvram_len)
179  {
180 -       struct brcmf_bus *bus_if;
181 -       struct brcmf_sdio_dev *sdiodev;
182 -       struct brcmf_sdio *bus;
183 +       struct brcmf_bus *bus_if = dev_get_drvdata(dev);
184 +       struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
185 +       struct brcmf_sdio *bus = sdiodev->bus;
186 +       struct brcmf_sdio_dev *sdiod = bus->sdiodev;
187 +       struct brcmf_core *core = bus->sdio_core;
188         u8 saveclk;
189  
190         brcmf_dbg(TRACE, "Enter: dev=%s, err=%d\n", dev_name(dev), err);
191 -       bus_if = dev_get_drvdata(dev);
192 -       sdiodev = bus_if->bus_priv.sdio;
193 +
194         if (err)
195                 goto fail;
196  
197         if (!bus_if->drvr)
198                 return;
199  
200 -       bus = sdiodev->bus;
201 -
202         /* try to download image and nvram to the dongle */
203         bus->alp_only = true;
204         err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len);
205 @@ -4063,8 +4056,9 @@ static void brcmf_sdio_firmware_callback
206         }
207  
208         /* Enable function 2 (frame transfers) */
209 -       w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
210 -                 SD_REG(tosbmailboxdata));
211 +       brcmf_sdiod_writel(sdiod, core->base + SD_REG(tosbmailboxdata),
212 +                          SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT, NULL);
213 +
214         err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);
215  
216  
217 @@ -4074,7 +4068,9 @@ static void brcmf_sdio_firmware_callback
218         if (!err) {
219                 /* Set up the interrupt mask and enable interrupts */
220                 bus->hostintmask = HOSTINTMASK;
221 -               w_sdreg32(bus, bus->hostintmask, SD_REG(hostintmask));
222 +               brcmf_sdiod_writel(sdiod, core->base + SD_REG(hostintmask),
223 +                                  bus->hostintmask, NULL);
224 +
225  
226                 brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
227         } else {