mac80211: brcmfmac: restructuring sdio access functions - take 2
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 312-v4.16-0008-brcmfmac-Cleanup-offsetof.patch
1 From e4c05fc3c0a6c79376f72f17d08014477e962ada Mon Sep 17 00:00:00 2001
2 From: Ian Molton <ian@mnementh.co.uk>
3 Date: Fri, 8 Dec 2017 13:10:33 +0100
4 Subject: [PATCH] brcmfmac: Cleanup offsetof()
5
6 Create a macro to make the code a bit more readable, whilst we're stuck
7 with using struct element offsets as register offsets.
8
9 Signed-off-by: Ian Molton <ian@mnementh.co.uk>
10 Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
11 [arend: rename macro to SD_REG]
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 | 35 +++++++++-------------
16 1 file changed, 14 insertions(+), 21 deletions(-)
17
18 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
19 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
20 @@ -161,6 +161,8 @@ struct rte_console {
21
22 #define CORE_BUS_REG(base, field) \
23 (base + offsetof(struct sdpcmd_regs, field))
24 +#define SD_REG(field) \
25 + (offsetof(struct sdpcmd_regs, field))
26
27 /* SDIO function 1 register CHIPCLKCSR */
28 /* Force ALP request to backplane */
29 @@ -1087,12 +1089,10 @@ static u32 brcmf_sdio_hostmail(struct br
30 brcmf_dbg(SDIO, "Enter\n");
31
32 /* Read mailbox data and ack that we did so */
33 - ret = r_sdreg32(bus, &hmb_data,
34 - offsetof(struct sdpcmd_regs, tohostmailboxdata));
35 + ret = r_sdreg32(bus, &hmb_data, SD_REG(tohostmailboxdata));
36
37 if (ret == 0)
38 - w_sdreg32(bus, SMB_INT_ACK,
39 - offsetof(struct sdpcmd_regs, tosbmailbox));
40 + w_sdreg32(bus, SMB_INT_ACK, SD_REG(tosbmailbox));
41 bus->sdcnt.f1regdata += 2;
42
43 /* dongle indicates the firmware has halted/crashed */
44 @@ -1207,8 +1207,7 @@ static void brcmf_sdio_rxfail(struct brc
45
46 if (rtx) {
47 bus->sdcnt.rxrtx++;
48 - err = w_sdreg32(bus, SMB_NAK,
49 - offsetof(struct sdpcmd_regs, tosbmailbox));
50 + err = w_sdreg32(bus, SMB_NAK, SD_REG(tosbmailbox));
51
52 bus->sdcnt.f1regdata++;
53 if (err == 0)
54 @@ -2333,9 +2332,7 @@ static uint brcmf_sdio_sendfromq(struct
55 if (!bus->intr) {
56 /* Check device status, signal pending interrupt */
57 sdio_claim_host(bus->sdiodev->func[1]);
58 - ret = r_sdreg32(bus, &intstatus,
59 - offsetof(struct sdpcmd_regs,
60 - intstatus));
61 + ret = r_sdreg32(bus, &intstatus, SD_REG(intstatus));
62 sdio_release_host(bus->sdiodev->func[1]);
63 bus->sdcnt.f2txdata++;
64 if (ret != 0)
65 @@ -2441,7 +2438,7 @@ static void brcmf_sdio_bus_stop(struct d
66 brcmf_sdio_bus_sleep(bus, false, false);
67
68 /* Disable and clear interrupts at the chip level also */
69 - w_sdreg32(bus, 0, offsetof(struct sdpcmd_regs, hostintmask));
70 + w_sdreg32(bus, 0, SD_REG(hostintmask));
71 local_hostintmask = bus->hostintmask;
72 bus->hostintmask = 0;
73
74 @@ -2460,8 +2457,7 @@ static void brcmf_sdio_bus_stop(struct d
75 sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
76
77 /* Clear any pending interrupts now that F2 is disabled */
78 - w_sdreg32(bus, local_hostintmask,
79 - offsetof(struct sdpcmd_regs, intstatus));
80 + w_sdreg32(bus, local_hostintmask, SD_REG(intstatus));
81
82 sdio_release_host(sdiodev->func[1]);
83 }
84 @@ -2507,7 +2503,7 @@ static int brcmf_sdio_intr_rstatus(struc
85 int ret;
86
87 buscore = brcmf_chip_get_core(bus->ci, BCMA_CORE_SDIO_DEV);
88 - addr = buscore->base + offsetof(struct sdpcmd_regs, intstatus);
89 + addr = buscore->base + SD_REG(intstatus);
90
91 val = brcmf_sdiod_readl(bus->sdiodev, addr, &ret);
92 bus->sdcnt.f1regdata++;
93 @@ -2584,11 +2580,9 @@ static void brcmf_sdio_dpc(struct brcmf_
94 */
95 if (intstatus & I_HMB_FC_CHANGE) {
96 intstatus &= ~I_HMB_FC_CHANGE;
97 - err = w_sdreg32(bus, I_HMB_FC_CHANGE,
98 - offsetof(struct sdpcmd_regs, intstatus));
99 + err = w_sdreg32(bus, I_HMB_FC_CHANGE, SD_REG(intstatus));
100
101 - err = r_sdreg32(bus, &newstatus,
102 - offsetof(struct sdpcmd_regs, intstatus));
103 + err = r_sdreg32(bus, &newstatus, SD_REG(intstatus));
104 bus->sdcnt.f1regdata += 2;
105 atomic_set(&bus->fcstate,
106 !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)));
107 @@ -3771,7 +3765,7 @@ static void brcmf_sdio_buscore_activate(
108
109 /* clear all interrupts */
110 core = brcmf_chip_get_core(chip, BCMA_CORE_SDIO_DEV);
111 - reg_addr = core->base + offsetof(struct sdpcmd_regs, intstatus);
112 + reg_addr = core->base + SD_REG(intstatus);
113 brcmf_sdiod_writel(sdiodev, reg_addr, 0xFFFFFFFF, NULL);
114
115 if (rstvec)
116 @@ -4067,7 +4061,7 @@ static void brcmf_sdio_firmware_callback
117
118 /* Enable function 2 (frame transfers) */
119 w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
120 - offsetof(struct sdpcmd_regs, tosbmailboxdata));
121 + SD_REG(tosbmailboxdata));
122 err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);
123
124
125 @@ -4077,8 +4071,7 @@ static void brcmf_sdio_firmware_callback
126 if (!err) {
127 /* Set up the interrupt mask and enable interrupts */
128 bus->hostintmask = HOSTINTMASK;
129 - w_sdreg32(bus, bus->hostintmask,
130 - offsetof(struct sdpcmd_regs, hostintmask));
131 + w_sdreg32(bus, bus->hostintmask, SD_REG(hostintmask));
132
133 brcmf_sdiod_writeb(sdiodev, SBSDIO_WATERMARK, 8, &err);
134 } else {