312-v4.16-0008-brcmfmac-Cleanup-offsetof.patch 4.9 KB

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