Commit | Line | Data |
---|---|---|
f5fc0f86 LC |
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 | ||
00d20100 SL |
24 | #include "wl12xx.h" |
25 | #include "reg.h" | |
26 | #include "io.h" | |
27 | #include "event.h" | |
28 | #include "ps.h" | |
29 | #include "scan.h" | |
66497dc3 | 30 | #include "wl12xx_80211.h" |
f5fc0f86 | 31 | |
90494a90 JO |
32 | void wl1271_pspoll_work(struct work_struct *work) |
33 | { | |
34 | struct delayed_work *dwork; | |
35 | struct wl1271 *wl; | |
c1b193eb | 36 | int ret; |
90494a90 JO |
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 | ||
8c7f4f31 JO |
45 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
46 | goto out; | |
47 | ||
90494a90 JO |
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 | */ | |
c1b193eb EP |
59 | ret = wl1271_ps_elp_wakeup(wl); |
60 | if (ret < 0) | |
61 | goto out; | |
62 | ||
65cddbf1 | 63 | wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true); |
90494a90 | 64 | |
c1b193eb | 65 | wl1271_ps_elp_sleep(wl); |
90494a90 JO |
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)) { | |
65cddbf1 JO |
82 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, |
83 | wl->basic_rate, true); | |
90494a90 JO |
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 | ||
19ad0715 JO |
99 | static int wl1271_event_ps_report(struct wl1271 *wl, |
100 | struct event_mailbox *mbox, | |
101 | bool *beacon_loss) | |
102 | { | |
103 | int ret = 0; | |
65cddbf1 | 104 | u32 total_retries = wl->conf.conn.psm_entry_retries; |
19ad0715 JO |
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: | |
d8c42c0c JO |
110 | wl1271_debug(DEBUG_PSM, "PSM entry failed"); |
111 | ||
71449f8d | 112 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
d8c42c0c | 113 | /* remain in active mode */ |
461fa136 JO |
114 | wl->psm_entry_retry = 0; |
115 | break; | |
116 | } | |
117 | ||
65cddbf1 | 118 | if (wl->psm_entry_retry < total_retries) { |
19ad0715 | 119 | wl->psm_entry_retry++; |
d8c42c0c | 120 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, |
8eab7b47 | 121 | wl->basic_rate, true); |
19ad0715 | 122 | } else { |
1a186a51 | 123 | wl1271_info("No ack to nullfunc from AP."); |
19ad0715 | 124 | wl->psm_entry_retry = 0; |
d60772f6 | 125 | *beacon_loss = true; |
19ad0715 JO |
126 | } |
127 | break; | |
128 | case EVENT_ENTER_POWER_SAVE_SUCCESS: | |
129 | wl->psm_entry_retry = 0; | |
d8c42c0c JO |
130 | |
131 | /* enable beacon filtering */ | |
132 | ret = wl1271_acx_beacon_filter_opt(wl, true); | |
133 | if (ret < 0) | |
134 | break; | |
135 | ||
0e44eb20 SL |
136 | /* |
137 | * BET has only a minor effect in 5GHz and masks | |
138 | * channel switch IEs, so we only enable BET on 2.4GHz | |
139 | */ | |
140 | if (wl->band == IEEE80211_BAND_2GHZ) | |
141 | /* enable beacon early termination */ | |
142 | ret = wl1271_acx_bet_enable(wl, true); | |
9439064c EP |
143 | |
144 | if (wl->ps_compl) { | |
145 | complete(wl->ps_compl); | |
146 | wl->ps_compl = NULL; | |
147 | } | |
19ad0715 | 148 | break; |
19ad0715 JO |
149 | default: |
150 | break; | |
151 | } | |
152 | ||
153 | return ret; | |
154 | } | |
155 | ||
00236aed JO |
156 | static void wl1271_event_rssi_trigger(struct wl1271 *wl, |
157 | struct event_mailbox *mbox) | |
158 | { | |
159 | enum nl80211_cqm_rssi_threshold_event event; | |
160 | s8 metric = mbox->rssi_snr_trigger_metric[0]; | |
161 | ||
162 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); | |
163 | ||
164 | if (metric <= wl->rssi_thold) | |
165 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; | |
166 | else | |
167 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; | |
168 | ||
169 | if (event != wl->last_rssi_event) | |
170 | ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); | |
171 | wl->last_rssi_event = event; | |
172 | } | |
173 | ||
f4d3b6ab | 174 | static void wl1271_stop_ba_event(struct wl1271 *wl) |
70559a06 | 175 | { |
f4d3b6ab AN |
176 | if (wl->bss_type != BSS_TYPE_AP_BSS) { |
177 | if (!wl->ba_rx_bitmap) | |
178 | return; | |
179 | ieee80211_stop_rx_ba_session(wl->vif, wl->ba_rx_bitmap, | |
180 | wl->bssid); | |
181 | } else { | |
182 | int i; | |
183 | struct wl1271_link *lnk; | |
6b661895 | 184 | for (i = WL1271_AP_STA_HLID_START; i < AP_MAX_LINKS; i++) { |
f4d3b6ab AN |
185 | lnk = &wl->links[i]; |
186 | if (!wl1271_is_active_sta(wl, i) || !lnk->ba_bitmap) | |
187 | continue; | |
188 | ||
189 | ieee80211_stop_rx_ba_session(wl->vif, | |
190 | lnk->ba_bitmap, | |
191 | lnk->addr); | |
192 | } | |
193 | } | |
70559a06 SL |
194 | } |
195 | ||
77ddaa10 EP |
196 | static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl, |
197 | u8 enable) | |
198 | { | |
199 | if (enable) { | |
200 | /* disable dynamic PS when requested by the firmware */ | |
201 | ieee80211_disable_dyn_ps(wl->vif); | |
202 | set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); | |
203 | } else { | |
204 | ieee80211_enable_dyn_ps(wl->vif); | |
205 | clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); | |
206 | wl1271_recalc_rx_streaming(wl); | |
207 | } | |
208 | ||
209 | } | |
210 | ||
f5fc0f86 LC |
211 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) |
212 | { | |
213 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); | |
214 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); | |
215 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); | |
216 | } | |
217 | ||
218 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) | |
219 | { | |
220 | int ret; | |
221 | u32 vector; | |
19ad0715 | 222 | bool beacon_loss = false; |
203c903c | 223 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); |
3618f30f AN |
224 | bool disconnect_sta = false; |
225 | unsigned long sta_bitmap = 0; | |
f5fc0f86 LC |
226 | |
227 | wl1271_event_mbox_dump(mbox); | |
228 | ||
d0f63b20 LC |
229 | vector = le32_to_cpu(mbox->events_vector); |
230 | vector &= ~(le32_to_cpu(mbox->events_mask)); | |
f5fc0f86 LC |
231 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); |
232 | ||
233 | if (vector & SCAN_COMPLETE_EVENT_ID) { | |
34dd2aaa LC |
234 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", |
235 | mbox->scheduled_scan_status); | |
236 | ||
08688d6b | 237 | wl1271_scan_stm(wl); |
f5fc0f86 LC |
238 | } |
239 | ||
6394c01b LC |
240 | if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { |
241 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT " | |
242 | "(status 0x%0x)", mbox->scheduled_scan_status); | |
33c2c06c LC |
243 | |
244 | wl1271_scan_sched_scan_results(wl); | |
6394c01b LC |
245 | } |
246 | ||
247 | if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) { | |
248 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT " | |
249 | "(status 0x%0x)", mbox->scheduled_scan_status); | |
33c2c06c LC |
250 | if (wl->sched_scanning) { |
251 | wl1271_scan_sched_scan_stop(wl); | |
252 | ieee80211_sched_scan_stopped(wl->hw); | |
253 | } | |
6394c01b LC |
254 | } |
255 | ||
8d2ef7bd | 256 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID && |
77ddaa10 EP |
257 | wl->bss_type == BSS_TYPE_STA_BSS) |
258 | wl12xx_event_soft_gemini_sense(wl, | |
259 | mbox->soft_gemini_sense_info); | |
8d2ef7bd | 260 | |
b771eee5 JO |
261 | /* |
262 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon | |
263 | * filtering) is enabled. Without PSM, the stack will receive all | |
264 | * beacons and can detect beacon loss by itself. | |
64e29e44 TP |
265 | * |
266 | * As there's possibility that the driver disables PSM before receiving | |
267 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. | |
268 | * | |
b771eee5 | 269 | */ |
203c903c | 270 | if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { |
1a186a51 | 271 | wl1271_info("Beacon loss detected."); |
f5fc0f86 | 272 | |
b771eee5 | 273 | /* indicate to the stack, that beacons have been lost */ |
19ad0715 JO |
274 | beacon_loss = true; |
275 | } | |
276 | ||
203c903c | 277 | if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { |
19ad0715 JO |
278 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); |
279 | ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); | |
280 | if (ret < 0) | |
281 | return ret; | |
282 | } | |
283 | ||
203c903c | 284 | if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) |
90494a90 JO |
285 | wl1271_event_pspoll_delivery_fail(wl); |
286 | ||
00236aed JO |
287 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { |
288 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); | |
289 | if (wl->vif) | |
290 | wl1271_event_rssi_trigger(wl, mbox); | |
291 | } | |
292 | ||
f4d3b6ab | 293 | if ((vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)) { |
70559a06 | 294 | wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. " |
c690ec81 | 295 | "ba_allowed = 0x%x", mbox->rx_ba_allowed); |
70559a06 | 296 | |
f4d3b6ab AN |
297 | wl->ba_allowed = !!mbox->rx_ba_allowed; |
298 | ||
299 | if (wl->vif && !wl->ba_allowed) | |
300 | wl1271_stop_ba_event(wl); | |
70559a06 SL |
301 | } |
302 | ||
79ebec76 | 303 | if ((vector & DUMMY_PACKET_EVENT_ID)) { |
ae47c45f SL |
304 | wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); |
305 | if (wl->vif) | |
306 | wl1271_tx_dummy_packet(wl); | |
307 | } | |
308 | ||
3618f30f AN |
309 | /* |
310 | * "TX retries exceeded" has a different meaning according to mode. | |
311 | * In AP mode the offending station is disconnected. | |
312 | */ | |
313 | if ((vector & MAX_TX_RETRY_EVENT_ID) && is_ap) { | |
314 | wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID"); | |
315 | sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded); | |
316 | disconnect_sta = true; | |
317 | } | |
318 | ||
319 | if ((vector & INACTIVE_STA_EVENT_ID) && is_ap) { | |
320 | wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID"); | |
321 | sta_bitmap |= le16_to_cpu(mbox->sta_aging_status); | |
322 | disconnect_sta = true; | |
323 | } | |
324 | ||
325 | if (is_ap && disconnect_sta) { | |
326 | u32 num_packets = wl->conf.tx.max_tx_retries; | |
327 | struct ieee80211_sta *sta; | |
328 | const u8 *addr; | |
329 | int h; | |
330 | ||
331 | for (h = find_first_bit(&sta_bitmap, AP_MAX_LINKS); | |
332 | h < AP_MAX_LINKS; | |
333 | h = find_next_bit(&sta_bitmap, AP_MAX_LINKS, h+1)) { | |
334 | if (!wl1271_is_active_sta(wl, h)) | |
335 | continue; | |
336 | ||
337 | addr = wl->links[h].addr; | |
338 | ||
339 | rcu_read_lock(); | |
340 | sta = ieee80211_find_sta(wl->vif, addr); | |
341 | if (sta) { | |
342 | wl1271_debug(DEBUG_EVENT, "remove sta %d", h); | |
343 | ieee80211_report_low_ack(sta, num_packets); | |
344 | } | |
345 | rcu_read_unlock(); | |
346 | } | |
347 | } | |
348 | ||
d60772f6 JO |
349 | if (wl->vif && beacon_loss) |
350 | ieee80211_connection_loss(wl->vif); | |
f5fc0f86 LC |
351 | |
352 | return 0; | |
353 | } | |
354 | ||
355 | int wl1271_event_unmask(struct wl1271 *wl) | |
356 | { | |
357 | int ret; | |
358 | ||
359 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); | |
360 | if (ret < 0) | |
361 | return ret; | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
366 | void wl1271_event_mbox_config(struct wl1271 *wl) | |
367 | { | |
7b048c52 | 368 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
f5fc0f86 LC |
369 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); |
370 | ||
371 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", | |
372 | wl->mbox_ptr[0], wl->mbox_ptr[1]); | |
373 | } | |
374 | ||
13f2dc52 | 375 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) |
f5fc0f86 LC |
376 | { |
377 | struct event_mailbox mbox; | |
378 | int ret; | |
379 | ||
380 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); | |
381 | ||
382 | if (mbox_num > 1) | |
383 | return -EINVAL; | |
384 | ||
385 | /* first we read the mbox descriptor */ | |
7b048c52 TP |
386 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, |
387 | sizeof(struct event_mailbox), false); | |
f5fc0f86 LC |
388 | |
389 | /* process the descriptor */ | |
390 | ret = wl1271_event_process(wl, &mbox); | |
391 | if (ret < 0) | |
392 | return ret; | |
393 | ||
394 | /* then we let the firmware know it can go on...*/ | |
7b048c52 | 395 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); |
f5fc0f86 LC |
396 | |
397 | return 0; | |
398 | } |