Commit b441ba8d authored by Hante Meuleman's avatar Hante Meuleman Committed by Kalle Valo

brcmfmac: Simplify watchdog sleep.

The watchdog thread is used to put the SDIO bus to sleep when the
system is idling. This patch simplifies the way it is determined
when sleep can be entered.
Reviewed-by: default avatarArend Van Spriel <arend@broadcom.com>
Reviewed-by: default avatarFranky (Zhenhui) Lin <frankyl@broadcom.com>
Reviewed-by: default avatarPieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: default avatarDaniel (Deognyoun) Kim <dekim@broadcom.com>
Signed-off-by: default avatarHante Meuleman <meuleman@broadcom.com>
Signed-off-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent de6878c8
...@@ -485,10 +485,9 @@ struct brcmf_sdio { ...@@ -485,10 +485,9 @@ struct brcmf_sdio {
#endif /* DEBUG */ #endif /* DEBUG */
uint clkstate; /* State of sd and backplane clock(s) */ uint clkstate; /* State of sd and backplane clock(s) */
bool activity; /* Activity flag for clock down */
s32 idletime; /* Control for activity timeout */ s32 idletime; /* Control for activity timeout */
s32 idlecount; /* Activity timeout counter */ s32 idlecount; /* Activity timeout counter */
s32 idleclock; /* How to set bus driver when idle */ s32 idleclock; /* How to set bus driver when idle */
bool rxflow_mode; /* Rx flow control mode */ bool rxflow_mode; /* Rx flow control mode */
bool rxflow; /* Is rx flow control on */ bool rxflow; /* Is rx flow control on */
bool alp_only; /* Don't use HT clock (ALP only) */ bool alp_only; /* Don't use HT clock (ALP only) */
...@@ -511,6 +510,7 @@ struct brcmf_sdio { ...@@ -511,6 +510,7 @@ struct brcmf_sdio {
struct workqueue_struct *brcmf_wq; struct workqueue_struct *brcmf_wq;
struct work_struct datawork; struct work_struct datawork;
atomic_t dpc_tskcnt; atomic_t dpc_tskcnt;
atomic_t dpc_running;
bool txoff; /* Transmit flow-controlled */ bool txoff; /* Transmit flow-controlled */
struct brcmf_sdio_count sdcnt; struct brcmf_sdio_count sdcnt;
...@@ -959,13 +959,8 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) ...@@ -959,13 +959,8 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
brcmf_dbg(SDIO, "Enter\n"); brcmf_dbg(SDIO, "Enter\n");
/* Early exit if we're already there */ /* Early exit if we're already there */
if (bus->clkstate == target) { if (bus->clkstate == target)
if (target == CLK_AVAIL) {
brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
bus->activity = true;
}
return 0; return 0;
}
switch (target) { switch (target) {
case CLK_AVAIL: case CLK_AVAIL:
...@@ -975,7 +970,6 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok) ...@@ -975,7 +970,6 @@ static int brcmf_sdio_clkctl(struct brcmf_sdio *bus, uint target, bool pendok)
/* Now request HT Avail on the backplane */ /* Now request HT Avail on the backplane */
brcmf_sdio_htclk(bus, true, pendok); brcmf_sdio_htclk(bus, true, pendok);
brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS); brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
bus->activity = true;
break; break;
case CLK_SDONLY: case CLK_SDONLY:
...@@ -1024,17 +1018,6 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) ...@@ -1024,17 +1018,6 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)
/* Going to sleep */ /* Going to sleep */
if (sleep) { if (sleep) {
/* Don't sleep if something is pending */
if (atomic_read(&bus->intstatus) ||
atomic_read(&bus->ipend) > 0 ||
bus->ctrl_frame_stat ||
(!atomic_read(&bus->fcstate) &&
brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) &&
data_ok(bus))) {
err = -EBUSY;
goto done;
}
clkcsr = brcmf_sdiod_regrb(bus->sdiodev, clkcsr = brcmf_sdiod_regrb(bus->sdiodev,
SBSDIO_FUNC1_CHIPCLKCSR, SBSDIO_FUNC1_CHIPCLKCSR,
&err); &err);
...@@ -1045,11 +1028,7 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok) ...@@ -1045,11 +1028,7 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *bus, bool sleep, bool pendok)
SBSDIO_ALP_AVAIL_REQ, &err); SBSDIO_ALP_AVAIL_REQ, &err);
} }
err = brcmf_sdio_kso_control(bus, false); err = brcmf_sdio_kso_control(bus, false);
/* disable watchdog */
if (!err)
brcmf_sdio_wd_timer(bus, 0);
} else { } else {
bus->idlecount = 0;
err = brcmf_sdio_kso_control(bus, true); err = brcmf_sdio_kso_control(bus, true);
} }
if (err) { if (err) {
...@@ -3566,7 +3545,7 @@ void brcmf_sdio_isr(struct brcmf_sdio *bus) ...@@ -3566,7 +3545,7 @@ void brcmf_sdio_isr(struct brcmf_sdio *bus)
queue_work(bus->brcmf_wq, &bus->datawork); queue_work(bus->brcmf_wq, &bus->datawork);
} }
static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
{ {
brcmf_dbg(TIMER, "Enter\n"); brcmf_dbg(TIMER, "Enter\n");
...@@ -3627,22 +3606,21 @@ static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus) ...@@ -3627,22 +3606,21 @@ static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
#endif /* DEBUG */ #endif /* DEBUG */
/* On idle timeout clear activity flag and/or turn off clock */ /* On idle timeout clear activity flag and/or turn off clock */
if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) { if ((atomic_read(&bus->dpc_tskcnt) == 0) &&
if (++bus->idlecount >= bus->idletime) { (atomic_read(&bus->dpc_running) == 0) &&
(bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) {
bus->idlecount++;
if (bus->idlecount > bus->idletime) {
brcmf_dbg(SDIO, "idle\n");
sdio_claim_host(bus->sdiodev->func[1]);
brcmf_sdio_wd_timer(bus, 0);
bus->idlecount = 0; bus->idlecount = 0;
if (bus->activity) { brcmf_sdio_bus_sleep(bus, true, false);
bus->activity = false; sdio_release_host(bus->sdiodev->func[1]);
brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
} else {
brcmf_dbg(SDIO, "idle\n");
sdio_claim_host(bus->sdiodev->func[1]);
brcmf_sdio_bus_sleep(bus, true, false);
sdio_release_host(bus->sdiodev->func[1]);
}
} }
} else {
bus->idlecount = 0;
} }
return (atomic_read(&bus->ipend) > 0);
} }
static void brcmf_sdio_dataworker(struct work_struct *work) static void brcmf_sdio_dataworker(struct work_struct *work)
...@@ -3651,8 +3629,11 @@ static void brcmf_sdio_dataworker(struct work_struct *work) ...@@ -3651,8 +3629,11 @@ static void brcmf_sdio_dataworker(struct work_struct *work)
datawork); datawork);
while (atomic_read(&bus->dpc_tskcnt)) { while (atomic_read(&bus->dpc_tskcnt)) {
atomic_set(&bus->dpc_running, 1);
atomic_set(&bus->dpc_tskcnt, 0); atomic_set(&bus->dpc_tskcnt, 0);
brcmf_sdio_dpc(bus); brcmf_sdio_dpc(bus);
bus->idlecount = 0;
atomic_set(&bus->dpc_running, 0);
} }
if (brcmf_sdiod_freezing(bus->sdiodev)) { if (brcmf_sdiod_freezing(bus->sdiodev)) {
brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN); brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN);
...@@ -4154,6 +4135,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev) ...@@ -4154,6 +4135,7 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
} }
/* Initialize DPC thread */ /* Initialize DPC thread */
atomic_set(&bus->dpc_tskcnt, 0); atomic_set(&bus->dpc_tskcnt, 0);
atomic_set(&bus->dpc_running, 0);
/* Assign bus interface call back */ /* Assign bus interface call back */
bus->sdiodev->bus_if->dev = bus->sdiodev->dev; bus->sdiodev->bus_if->dev = bus->sdiodev->dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment