brcmfmac: sdio: shorten retry loop in brcmf_sdio_kso_control()
authorArend Van Spriel <arend.vanspriel@broadcom.com>
Mon, 5 Sep 2016 10:42:13 +0000 (11:42 +0100)
committerKalle Valo <kvalo@codeaurora.org>
Fri, 9 Sep 2016 09:12:15 +0000 (12:12 +0300)
In brcmf_sdio_kso_control() there is a retry loop as hardware may take
time to settle. However, when the call to brcmf_sdiod_regrb() returns
an error it is due to SDIO access failure and it makes no sense to wait
for hardware to settle. This patch aborts the loop after a number of
subsequent access errors.

Reviewed-by: Hante Meuleman <hante.meuleman@broadcom.com>
Reviewed-by: Pieter-Paul Giesberts <pieter-paul.giesberts@broadcom.com>
Reviewed-by: Franky Lin <franky.lin@broadcom.com>
Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c

index 589a49cd9cd5623434a0d446a2751a6fc152de17..b892dac70f4b02f76e01a7ccb580c6d8aed4bfe4 100644 (file)
@@ -313,6 +313,7 @@ struct rte_console {
 
 #define KSO_WAIT_US 50
 #define MAX_KSO_ATTEMPTS (PMU_MAX_TRANSITION_DLY/KSO_WAIT_US)
+#define BRCMF_SDIO_MAX_ACCESS_ERRORS   5
 
 /*
  * Conversion of 802.1D priority to precedence level
@@ -677,6 +678,7 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
 {
        u8 wr_val = 0, rd_val, cmp_val, bmask;
        int err = 0;
+       int err_cnt = 0;
        int try_cnt = 0;
 
        brcmf_dbg(TRACE, "Enter: on=%d\n", on);
@@ -712,9 +714,14 @@ brcmf_sdio_kso_control(struct brcmf_sdio *bus, bool on)
                 */
                rd_val = brcmf_sdiod_regrb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
                                           &err);
-               if (((rd_val & bmask) == cmp_val) && !err)
+               if (!err) {
+                       if ((rd_val & bmask) == cmp_val)
+                               break;
+                       err_cnt = 0;
+               }
+               /* bail out upon subsequent access errors */
+               if (err && (err_cnt++ > BRCMF_SDIO_MAX_ACCESS_ERRORS))
                        break;
-
                udelay(KSO_WAIT_US);
                brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_SLEEPCSR,
                                  wr_val, &err);