1 From: Hante Meuleman <meuleman@broadcom.com>
2 Date: Fri, 6 Mar 2015 18:40:39 +0100
3 Subject: [PATCH] brcmfmac: Simplify watchdog sleep.
5 The watchdog thread is used to put the SDIO bus to sleep when the
6 system is idling. This patch simplifies the way it is determined
7 when sleep can be entered.
9 Reviewed-by: Arend Van Spriel <arend@broadcom.com>
10 Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
11 Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
12 Reviewed-by: Daniel (Deognyoun) Kim <dekim@broadcom.com>
13 Signed-off-by: Hante Meuleman <meuleman@broadcom.com>
14 Signed-off-by: Arend van Spriel <arend@broadcom.com>
15 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
18 --- a/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
19 +++ b/drivers/net/wireless/brcm80211/brcmfmac/sdio.c
20 @@ -485,10 +485,9 @@ struct brcmf_sdio {
23 uint clkstate; /* State of sd and backplane clock(s) */
24 - bool activity; /* Activity flag for clock down */
25 s32 idletime; /* Control for activity timeout */
26 - s32 idlecount; /* Activity timeout counter */
27 - s32 idleclock; /* How to set bus driver when idle */
28 + s32 idlecount; /* Activity timeout counter */
29 + s32 idleclock; /* How to set bus driver when idle */
30 bool rxflow_mode; /* Rx flow control mode */
31 bool rxflow; /* Is rx flow control on */
32 bool alp_only; /* Don't use HT clock (ALP only) */
33 @@ -511,6 +510,7 @@ struct brcmf_sdio {
34 struct workqueue_struct *brcmf_wq;
35 struct work_struct datawork;
37 + atomic_t dpc_running;
39 bool txoff; /* Transmit flow-controlled */
40 struct brcmf_sdio_count sdcnt;
41 @@ -959,13 +959,8 @@ static int brcmf_sdio_clkctl(struct brcm
42 brcmf_dbg(SDIO, "Enter\n");
44 /* Early exit if we're already there */
45 - if (bus->clkstate == target) {
46 - if (target == CLK_AVAIL) {
47 - brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
48 - bus->activity = true;
50 + if (bus->clkstate == target)
56 @@ -975,7 +970,6 @@ static int brcmf_sdio_clkctl(struct brcm
57 /* Now request HT Avail on the backplane */
58 brcmf_sdio_htclk(bus, true, pendok);
59 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
60 - bus->activity = true;
64 @@ -1024,17 +1018,6 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *
68 - /* Don't sleep if something is pending */
69 - if (atomic_read(&bus->intstatus) ||
70 - atomic_read(&bus->ipend) > 0 ||
71 - bus->ctrl_frame_stat ||
72 - (!atomic_read(&bus->fcstate) &&
73 - brcmu_pktq_mlen(&bus->txq, ~bus->flowcontrol) &&
79 clkcsr = brcmf_sdiod_regrb(bus->sdiodev,
80 SBSDIO_FUNC1_CHIPCLKCSR,
82 @@ -1045,11 +1028,7 @@ brcmf_sdio_bus_sleep(struct brcmf_sdio *
83 SBSDIO_ALP_AVAIL_REQ, &err);
85 err = brcmf_sdio_kso_control(bus, false);
86 - /* disable watchdog */
88 - brcmf_sdio_wd_timer(bus, 0);
91 err = brcmf_sdio_kso_control(bus, true);
94 @@ -3566,7 +3545,7 @@ void brcmf_sdio_isr(struct brcmf_sdio *b
95 queue_work(bus->brcmf_wq, &bus->datawork);
98 -static bool brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
99 +static void brcmf_sdio_bus_watchdog(struct brcmf_sdio *bus)
101 brcmf_dbg(TIMER, "Enter\n");
103 @@ -3627,22 +3606,21 @@ static bool brcmf_sdio_bus_watchdog(stru
106 /* On idle timeout clear activity flag and/or turn off clock */
107 - if ((bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) {
108 - if (++bus->idlecount >= bus->idletime) {
109 + if ((atomic_read(&bus->dpc_tskcnt) == 0) &&
110 + (atomic_read(&bus->dpc_running) == 0) &&
111 + (bus->idletime > 0) && (bus->clkstate == CLK_AVAIL)) {
113 + if (bus->idlecount > bus->idletime) {
114 + brcmf_dbg(SDIO, "idle\n");
115 + sdio_claim_host(bus->sdiodev->func[1]);
116 + brcmf_sdio_wd_timer(bus, 0);
118 - if (bus->activity) {
119 - bus->activity = false;
120 - brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
122 - brcmf_dbg(SDIO, "idle\n");
123 - sdio_claim_host(bus->sdiodev->func[1]);
124 - brcmf_sdio_bus_sleep(bus, true, false);
125 - sdio_release_host(bus->sdiodev->func[1]);
127 + brcmf_sdio_bus_sleep(bus, true, false);
128 + sdio_release_host(bus->sdiodev->func[1]);
131 + bus->idlecount = 0;
134 - return (atomic_read(&bus->ipend) > 0);
137 static void brcmf_sdio_dataworker(struct work_struct *work)
138 @@ -3651,8 +3629,11 @@ static void brcmf_sdio_dataworker(struct
141 while (atomic_read(&bus->dpc_tskcnt)) {
142 + atomic_set(&bus->dpc_running, 1);
143 atomic_set(&bus->dpc_tskcnt, 0);
145 + bus->idlecount = 0;
146 + atomic_set(&bus->dpc_running, 0);
148 if (brcmf_sdiod_freezing(bus->sdiodev)) {
149 brcmf_sdiod_change_state(bus->sdiodev, BRCMF_SDIOD_DOWN);
150 @@ -4154,6 +4135,7 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
152 /* Initialize DPC thread */
153 atomic_set(&bus->dpc_tskcnt, 0);
154 + atomic_set(&bus->dpc_running, 0);
156 /* Assign bus interface call back */
157 bus->sdiodev->bus_if->dev = bus->sdiodev->dev;