diff options
Diffstat (limited to 'drivers/net/wireless/wl12xx/event.c')
-rw-r--r-- | drivers/net/wireless/wl12xx/event.c | 310 |
1 files changed, 310 insertions, 0 deletions
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/event.c new file mode 100644 index 000000000000..c3c554cd6580 --- /dev/null +++ b/drivers/net/wireless/wl12xx/event.c | |||
@@ -0,0 +1,310 @@ | |||
1 | /* | ||
2 | * This file is part of wl1271 | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Nokia Corporation | ||
5 | * | ||
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | ||
7 | * | ||
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. | ||
11 | * | ||
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. | ||
16 | * | ||
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 | ||
20 | * 02110-1301 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #include "wl12xx.h" | ||
25 | #include "reg.h" | ||
26 | #include "io.h" | ||
27 | #include "event.h" | ||
28 | #include "ps.h" | ||
29 | #include "scan.h" | ||
30 | #include "wl12xx_80211.h" | ||
31 | |||
32 | void wl1271_pspoll_work(struct work_struct *work) | ||
33 | { | ||
34 | struct delayed_work *dwork; | ||
35 | struct wl1271 *wl; | ||
36 | int ret; | ||
37 | |||
38 | dwork = container_of(work, struct delayed_work, work); | ||
39 | wl = container_of(dwork, struct wl1271, pspoll_work); | ||
40 | |||
41 | wl1271_debug(DEBUG_EVENT, "pspoll work"); | ||
42 | |||
43 | mutex_lock(&wl->mutex); | ||
44 | |||
45 | if (unlikely(wl->state == WL1271_STATE_OFF)) | ||
46 | goto out; | ||
47 | |||
48 | if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) | ||
49 | goto out; | ||
50 | |||
51 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | ||
52 | goto out; | ||
53 | |||
54 | /* | ||
55 | * if we end up here, then we were in powersave when the pspoll | ||
56 | * delivery failure occurred, and no-one changed state since, so | ||
57 | * we should go back to powersave. | ||
58 | */ | ||
59 | ret = wl1271_ps_elp_wakeup(wl); | ||
60 | if (ret < 0) | ||
61 | goto out; | ||
62 | |||
63 | wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true); | ||
64 | |||
65 | wl1271_ps_elp_sleep(wl); | ||
66 | out: | ||
67 | mutex_unlock(&wl->mutex); | ||
68 | }; | ||
69 | |||
70 | static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl) | ||
71 | { | ||
72 | int delay = wl->conf.conn.ps_poll_recovery_period; | ||
73 | int ret; | ||
74 | |||
75 | wl->ps_poll_failures++; | ||
76 | if (wl->ps_poll_failures == 1) | ||
77 | wl1271_info("AP with dysfunctional ps-poll, " | ||
78 | "trying to work around it."); | ||
79 | |||
80 | /* force active mode receive data from the AP */ | ||
81 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { | ||
82 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, | ||
83 | wl->basic_rate, true); | ||
84 | if (ret < 0) | ||
85 | return; | ||
86 | set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); | ||
87 | ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, | ||
88 | msecs_to_jiffies(delay)); | ||
89 | } | ||
90 | |||
91 | /* | ||
92 | * If already in active mode, lets we should be getting data from | ||
93 | * the AP right away. If we enter PSM too fast after this, and data | ||
94 | * remains on the AP, we will get another event like this, and we'll | ||
95 | * go into active once more. | ||
96 | */ | ||
97 | } | ||
98 | |||
99 | static int wl1271_event_ps_report(struct wl1271 *wl, | ||
100 | struct event_mailbox *mbox, | ||
101 | bool *beacon_loss) | ||
102 | { | ||
103 | int ret = 0; | ||
104 | u32 total_retries = wl->conf.conn.psm_entry_retries; | ||
105 | |||
106 | wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status); | ||
107 | |||
108 | switch (mbox->ps_status) { | ||
109 | case EVENT_ENTER_POWER_SAVE_FAIL: | ||
110 | wl1271_debug(DEBUG_PSM, "PSM entry failed"); | ||
111 | |||
112 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { | ||
113 | /* remain in active mode */ | ||
114 | wl->psm_entry_retry = 0; | ||
115 | break; | ||
116 | } | ||
117 | |||
118 | if (wl->psm_entry_retry < total_retries) { | ||
119 | wl->psm_entry_retry++; | ||
120 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, | ||
121 | wl->basic_rate, true); | ||
122 | } else { | ||
123 | wl1271_info("No ack to nullfunc from AP."); | ||
124 | wl->psm_entry_retry = 0; | ||
125 | *beacon_loss = true; | ||
126 | } | ||
127 | break; | ||
128 | case EVENT_ENTER_POWER_SAVE_SUCCESS: | ||
129 | wl->psm_entry_retry = 0; | ||
130 | |||
131 | /* enable beacon filtering */ | ||
132 | ret = wl1271_acx_beacon_filter_opt(wl, true); | ||
133 | if (ret < 0) | ||
134 | break; | ||
135 | |||
136 | /* enable beacon early termination */ | ||
137 | ret = wl1271_acx_bet_enable(wl, true); | ||
138 | if (ret < 0) | ||
139 | break; | ||
140 | |||
141 | if (wl->ps_compl) { | ||
142 | complete(wl->ps_compl); | ||
143 | wl->ps_compl = NULL; | ||
144 | } | ||
145 | break; | ||
146 | default: | ||
147 | break; | ||
148 | } | ||
149 | |||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | static void wl1271_event_rssi_trigger(struct wl1271 *wl, | ||
154 | struct event_mailbox *mbox) | ||
155 | { | ||
156 | enum nl80211_cqm_rssi_threshold_event event; | ||
157 | s8 metric = mbox->rssi_snr_trigger_metric[0]; | ||
158 | |||
159 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); | ||
160 | |||
161 | if (metric <= wl->rssi_thold) | ||
162 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; | ||
163 | else | ||
164 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; | ||
165 | |||
166 | if (event != wl->last_rssi_event) | ||
167 | ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); | ||
168 | wl->last_rssi_event = event; | ||
169 | } | ||
170 | |||
171 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) | ||
172 | { | ||
173 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); | ||
174 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); | ||
175 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); | ||
176 | } | ||
177 | |||
178 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) | ||
179 | { | ||
180 | int ret; | ||
181 | u32 vector; | ||
182 | bool beacon_loss = false; | ||
183 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); | ||
184 | |||
185 | wl1271_event_mbox_dump(mbox); | ||
186 | |||
187 | vector = le32_to_cpu(mbox->events_vector); | ||
188 | vector &= ~(le32_to_cpu(mbox->events_mask)); | ||
189 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); | ||
190 | |||
191 | if (vector & SCAN_COMPLETE_EVENT_ID) { | ||
192 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", | ||
193 | mbox->scheduled_scan_status); | ||
194 | |||
195 | wl1271_scan_stm(wl); | ||
196 | } | ||
197 | |||
198 | if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { | ||
199 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT " | ||
200 | "(status 0x%0x)", mbox->scheduled_scan_status); | ||
201 | |||
202 | wl1271_scan_sched_scan_results(wl); | ||
203 | } | ||
204 | |||
205 | if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) { | ||
206 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT " | ||
207 | "(status 0x%0x)", mbox->scheduled_scan_status); | ||
208 | if (wl->sched_scanning) { | ||
209 | wl1271_scan_sched_scan_stop(wl); | ||
210 | ieee80211_sched_scan_stopped(wl->hw); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | /* disable dynamic PS when requested by the firmware */ | ||
215 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID && | ||
216 | wl->bss_type == BSS_TYPE_STA_BSS) { | ||
217 | if (mbox->soft_gemini_sense_info) | ||
218 | ieee80211_disable_dyn_ps(wl->vif); | ||
219 | else | ||
220 | ieee80211_enable_dyn_ps(wl->vif); | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon | ||
225 | * filtering) is enabled. Without PSM, the stack will receive all | ||
226 | * beacons and can detect beacon loss by itself. | ||
227 | * | ||
228 | * As there's possibility that the driver disables PSM before receiving | ||
229 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. | ||
230 | * | ||
231 | */ | ||
232 | if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { | ||
233 | wl1271_info("Beacon loss detected."); | ||
234 | |||
235 | /* indicate to the stack, that beacons have been lost */ | ||
236 | beacon_loss = true; | ||
237 | } | ||
238 | |||
239 | if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { | ||
240 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); | ||
241 | ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); | ||
242 | if (ret < 0) | ||
243 | return ret; | ||
244 | } | ||
245 | |||
246 | if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) | ||
247 | wl1271_event_pspoll_delivery_fail(wl); | ||
248 | |||
249 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { | ||
250 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); | ||
251 | if (wl->vif) | ||
252 | wl1271_event_rssi_trigger(wl, mbox); | ||
253 | } | ||
254 | |||
255 | if ((vector & DUMMY_PACKET_EVENT_ID) && !is_ap) { | ||
256 | wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); | ||
257 | if (wl->vif) | ||
258 | wl1271_tx_dummy_packet(wl); | ||
259 | } | ||
260 | |||
261 | if (wl->vif && beacon_loss) | ||
262 | ieee80211_connection_loss(wl->vif); | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | int wl1271_event_unmask(struct wl1271 *wl) | ||
268 | { | ||
269 | int ret; | ||
270 | |||
271 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); | ||
272 | if (ret < 0) | ||
273 | return ret; | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | void wl1271_event_mbox_config(struct wl1271 *wl) | ||
279 | { | ||
280 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); | ||
281 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); | ||
282 | |||
283 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", | ||
284 | wl->mbox_ptr[0], wl->mbox_ptr[1]); | ||
285 | } | ||
286 | |||
287 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) | ||
288 | { | ||
289 | struct event_mailbox mbox; | ||
290 | int ret; | ||
291 | |||
292 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); | ||
293 | |||
294 | if (mbox_num > 1) | ||
295 | return -EINVAL; | ||
296 | |||
297 | /* first we read the mbox descriptor */ | ||
298 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, | ||
299 | sizeof(struct event_mailbox), false); | ||
300 | |||
301 | /* process the descriptor */ | ||
302 | ret = wl1271_event_process(wl, &mbox); | ||
303 | if (ret < 0) | ||
304 | return ret; | ||
305 | |||
306 | /* then we let the firmware know it can go on...*/ | ||
307 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); | ||
308 | |||
309 | return 0; | ||
310 | } | ||