2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 #define WL1271_WAKEUP_TIMEOUT 500
31 void wl1271_elp_work(struct work_struct
*work
)
33 struct delayed_work
*dwork
;
36 dwork
= container_of(work
, struct delayed_work
, work
);
37 wl
= container_of(dwork
, struct wl1271
, elp_work
);
39 wl1271_debug(DEBUG_PSM
, "elp work");
41 mutex_lock(&wl
->mutex
);
43 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
46 if (test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
) ||
47 (!test_bit(WL1271_FLAG_PSM
, &wl
->flags
) &&
48 !test_bit(WL1271_FLAG_IDLE
, &wl
->flags
)))
51 wl1271_debug(DEBUG_PSM
, "chip to elp");
52 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_SLEEP
);
53 set_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
);
56 mutex_unlock(&wl
->mutex
);
59 #define ELP_ENTRY_DELAY 5
61 /* Routines to toggle sleep mode while in ELP */
62 void wl1271_ps_elp_sleep(struct wl1271
*wl
)
64 if (test_bit(WL1271_FLAG_PSM
, &wl
->flags
) ||
65 test_bit(WL1271_FLAG_IDLE
, &wl
->flags
)) {
66 cancel_delayed_work(&wl
->elp_work
);
67 ieee80211_queue_delayed_work(wl
->hw
, &wl
->elp_work
,
68 msecs_to_jiffies(ELP_ENTRY_DELAY
));
72 int wl1271_ps_elp_wakeup(struct wl1271
*wl
, bool chip_awake
)
74 DECLARE_COMPLETION_ONSTACK(compl);
77 u32 start_time
= jiffies
;
80 if (!test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
))
83 wl1271_debug(DEBUG_PSM
, "waking up chip from elp");
86 * The spinlock is required here to synchronize both the work and
87 * the completion variable in one entity.
89 spin_lock_irqsave(&wl
->wl_lock
, flags
);
90 if (work_pending(&wl
->irq_work
) || chip_awake
)
93 wl
->elp_compl
= &compl;
94 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
96 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_WAKE_UP
);
99 ret
= wait_for_completion_timeout(
100 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT
));
102 wl1271_error("ELP wakeup timeout!");
103 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
106 } else if (ret
< 0) {
107 wl1271_error("ELP wakeup completion error.");
112 clear_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
);
114 wl1271_debug(DEBUG_PSM
, "wakeup time: %u ms",
115 jiffies_to_msecs(jiffies
- start_time
));
119 spin_lock_irqsave(&wl
->wl_lock
, flags
);
120 wl
->elp_compl
= NULL
;
121 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
128 int wl1271_ps_set_mode(struct wl1271
*wl
, enum wl1271_cmd_ps_mode mode
,
129 u32 rates
, bool send
)
134 case STATION_POWER_SAVE_MODE
:
135 wl1271_debug(DEBUG_PSM
, "entering psm");
137 ret
= wl1271_acx_wake_up_conditions(wl
);
139 wl1271_error("couldn't set wake up conditions");
143 ret
= wl1271_cmd_ps_mode(wl
, STATION_POWER_SAVE_MODE
);
147 set_bit(WL1271_FLAG_PSM
, &wl
->flags
);
149 case STATION_ACTIVE_MODE
:
151 wl1271_debug(DEBUG_PSM
, "leaving psm");
152 ret
= wl1271_ps_elp_wakeup(wl
, false);
156 /* disable beacon early termination */
157 ret
= wl1271_acx_bet_enable(wl
, false);
161 /* disable beacon filtering */
162 ret
= wl1271_acx_beacon_filter_opt(wl
, false);
166 ret
= wl1271_cmd_ps_mode(wl
, STATION_ACTIVE_MODE
);
170 clear_bit(WL1271_FLAG_PSM
, &wl
->flags
);
177 static void wl1271_ps_filter_frames(struct wl1271
*wl
, u8 hlid
)
181 struct ieee80211_tx_info
*info
;
184 /* filter all frames currently the low level queus for this hlid */
185 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
186 while ((skb
= skb_dequeue(&wl
->links
[hlid
].tx_queue
[i
]))) {
187 info
= IEEE80211_SKB_CB(skb
);
188 info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
189 info
->status
.rates
[0].idx
= -1;
190 ieee80211_tx_status(wl
->hw
, skb
);
195 spin_lock_irqsave(&wl
->wl_lock
, flags
);
196 wl
->tx_queue_count
-= filtered
;
197 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
199 wl1271_handle_tx_low_watermark(wl
);
202 void wl1271_ps_link_start(struct wl1271
*wl
, u8 hlid
, bool clean_queues
)
204 struct ieee80211_sta
*sta
;
206 if (test_bit(hlid
, &wl
->ap_ps_map
))
209 wl1271_debug(DEBUG_PSM
, "start mac80211 PSM on hlid %d blks %d "
210 "clean_queues %d", hlid
, wl
->links
[hlid
].allocated_blks
,
214 sta
= ieee80211_find_sta(wl
->vif
, wl
->links
[hlid
].addr
);
216 wl1271_error("could not find sta %pM for starting ps",
217 wl
->links
[hlid
].addr
);
222 ieee80211_sta_ps_transition_ni(sta
, true);
225 /* do we want to filter all frames from this link's queues? */
227 wl1271_ps_filter_frames(wl
, hlid
);
229 __set_bit(hlid
, &wl
->ap_ps_map
);
232 void wl1271_ps_link_end(struct wl1271
*wl
, u8 hlid
)
234 struct ieee80211_sta
*sta
;
236 if (!test_bit(hlid
, &wl
->ap_ps_map
))
239 wl1271_debug(DEBUG_PSM
, "end mac80211 PSM on hlid %d", hlid
);
241 __clear_bit(hlid
, &wl
->ap_ps_map
);
244 sta
= ieee80211_find_sta(wl
->vif
, wl
->links
[hlid
].addr
);
246 wl1271_error("could not find sta %pM for ending ps",
247 wl
->links
[hlid
].addr
);
251 ieee80211_sta_ps_transition_ni(sta
, false);