]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/net/wireless/wl12xx/event.c
wl12xx: make WL1271_FLAG_CS_PROGRESS flag per-vif
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / wl12xx / event.c
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 ieee80211_vif *vif;
35 struct wl12xx_vif *wlvif;
36 struct delayed_work *dwork;
37 struct wl1271 *wl;
38 int ret;
39
40 dwork = container_of(work, struct delayed_work, work);
41 wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work);
42 vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
43 wl = wlvif->wl;
44
45 wl1271_debug(DEBUG_EVENT, "pspoll work");
46
47 mutex_lock(&wl->mutex);
48
49 if (unlikely(wl->state == WL1271_STATE_OFF))
50 goto out;
51
52 if (!test_and_clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags))
53 goto out;
54
55 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
56 goto out;
57
58 /*
59 * if we end up here, then we were in powersave when the pspoll
60 * delivery failure occurred, and no-one changed state since, so
61 * we should go back to powersave.
62 */
63 ret = wl1271_ps_elp_wakeup(wl);
64 if (ret < 0)
65 goto out;
66
67 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
68 wlvif->basic_rate, true);
69
70 wl1271_ps_elp_sleep(wl);
71 out:
72 mutex_unlock(&wl->mutex);
73 };
74
75 static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl,
76 struct wl12xx_vif *wlvif)
77 {
78 int delay = wl->conf.conn.ps_poll_recovery_period;
79 int ret;
80
81 wlvif->ps_poll_failures++;
82 if (wlvif->ps_poll_failures == 1)
83 wl1271_info("AP with dysfunctional ps-poll, "
84 "trying to work around it.");
85
86 /* force active mode receive data from the AP */
87 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
88 ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
89 wlvif->basic_rate, true);
90 if (ret < 0)
91 return;
92 set_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
93 ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work,
94 msecs_to_jiffies(delay));
95 }
96
97 /*
98 * If already in active mode, lets we should be getting data from
99 * the AP right away. If we enter PSM too fast after this, and data
100 * remains on the AP, we will get another event like this, and we'll
101 * go into active once more.
102 */
103 }
104
105 static int wl1271_event_ps_report(struct wl1271 *wl,
106 struct wl12xx_vif *wlvif,
107 struct event_mailbox *mbox,
108 bool *beacon_loss)
109 {
110 int ret = 0;
111 u32 total_retries = wl->conf.conn.psm_entry_retries;
112
113 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
114
115 switch (mbox->ps_status) {
116 case EVENT_ENTER_POWER_SAVE_FAIL:
117 wl1271_debug(DEBUG_PSM, "PSM entry failed");
118
119 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
120 /* remain in active mode */
121 wlvif->psm_entry_retry = 0;
122 break;
123 }
124
125 if (wlvif->psm_entry_retry < total_retries) {
126 wlvif->psm_entry_retry++;
127 ret = wl1271_ps_set_mode(wl, wlvif,
128 STATION_POWER_SAVE_MODE,
129 wlvif->basic_rate, true);
130 } else {
131 wl1271_info("No ack to nullfunc from AP.");
132 wlvif->psm_entry_retry = 0;
133 *beacon_loss = true;
134 }
135 break;
136 case EVENT_ENTER_POWER_SAVE_SUCCESS:
137 wlvif->psm_entry_retry = 0;
138
139 /* enable beacon filtering */
140 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
141 if (ret < 0)
142 break;
143
144 /*
145 * BET has only a minor effect in 5GHz and masks
146 * channel switch IEs, so we only enable BET on 2.4GHz
147 */
148 if (wl->band == IEEE80211_BAND_2GHZ)
149 /* enable beacon early termination */
150 ret = wl1271_acx_bet_enable(wl, wlvif, true);
151
152 if (wlvif->ps_compl) {
153 complete(wlvif->ps_compl);
154 wlvif->ps_compl = NULL;
155 }
156 break;
157 default:
158 break;
159 }
160
161 return ret;
162 }
163
164 static void wl1271_event_rssi_trigger(struct wl1271 *wl,
165 struct wl12xx_vif *wlvif,
166 struct event_mailbox *mbox)
167 {
168 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
169 enum nl80211_cqm_rssi_threshold_event event;
170 s8 metric = mbox->rssi_snr_trigger_metric[0];
171
172 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
173
174 if (metric <= wlvif->rssi_thold)
175 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
176 else
177 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
178
179 if (event != wlvif->last_rssi_event)
180 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
181 wlvif->last_rssi_event = event;
182 }
183
184 static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
185 {
186 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
187
188 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
189 if (!wlvif->sta.ba_rx_bitmap)
190 return;
191 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
192 vif->bss_conf.bssid);
193 } else {
194 u8 hlid;
195 struct wl1271_link *lnk;
196 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
197 WL12XX_MAX_LINKS) {
198 lnk = &wl->links[hlid];
199 if (!lnk->ba_bitmap)
200 continue;
201
202 ieee80211_stop_rx_ba_session(vif,
203 lnk->ba_bitmap,
204 lnk->addr);
205 }
206 }
207 }
208
209 static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
210 u8 enable)
211 {
212 struct ieee80211_vif *vif;
213 struct wl12xx_vif *wlvif;
214
215 if (enable) {
216 /* disable dynamic PS when requested by the firmware */
217 wl12xx_for_each_wlvif_sta(wl, wlvif) {
218 vif = wl12xx_wlvif_to_vif(wlvif);
219 ieee80211_disable_dyn_ps(vif);
220 }
221 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
222 } else {
223 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
224 wl12xx_for_each_wlvif_sta(wl, wlvif) {
225 vif = wl12xx_wlvif_to_vif(wlvif);
226 ieee80211_enable_dyn_ps(vif);
227 wl1271_recalc_rx_streaming(wl, wlvif);
228 }
229 }
230
231 }
232
233 static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
234 {
235 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
236 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
237 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
238 }
239
240 static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
241 {
242 struct ieee80211_vif *vif;
243 struct wl12xx_vif *wlvif;
244 int ret;
245 u32 vector;
246 bool beacon_loss = false;
247 bool disconnect_sta = false;
248 unsigned long sta_bitmap = 0;
249
250 wl1271_event_mbox_dump(mbox);
251
252 vector = le32_to_cpu(mbox->events_vector);
253 vector &= ~(le32_to_cpu(mbox->events_mask));
254 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
255
256 if (vector & SCAN_COMPLETE_EVENT_ID) {
257 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
258 mbox->scheduled_scan_status);
259
260 wl1271_scan_stm(wl, wl->scan_vif);
261 }
262
263 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
264 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
265 "(status 0x%0x)", mbox->scheduled_scan_status);
266
267 wl1271_scan_sched_scan_results(wl);
268 }
269
270 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
271 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
272 "(status 0x%0x)", mbox->scheduled_scan_status);
273 if (wl->sched_scanning) {
274 wl1271_scan_sched_scan_stop(wl);
275 ieee80211_sched_scan_stopped(wl->hw);
276 }
277 }
278
279 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
280 wl12xx_event_soft_gemini_sense(wl,
281 mbox->soft_gemini_sense_info);
282
283 /*
284 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
285 * filtering) is enabled. Without PSM, the stack will receive all
286 * beacons and can detect beacon loss by itself.
287 *
288 * As there's possibility that the driver disables PSM before receiving
289 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
290 *
291 */
292 if (vector & BSS_LOSE_EVENT_ID) {
293 /* TODO: check for multi-role */
294 wl1271_info("Beacon loss detected.");
295
296 /* indicate to the stack, that beacons have been lost */
297 beacon_loss = true;
298 }
299
300 if (vector & PS_REPORT_EVENT_ID) {
301 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
302 wl12xx_for_each_wlvif_sta(wl, wlvif) {
303 ret = wl1271_event_ps_report(wl, wlvif,
304 mbox, &beacon_loss);
305 if (ret < 0)
306 return ret;
307 }
308 }
309
310 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
311 wl12xx_for_each_wlvif_sta(wl, wlvif) {
312 wl1271_event_pspoll_delivery_fail(wl, wlvif);
313 }
314
315 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
316 /* TODO: check actual multi-role support */
317 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
318 wl12xx_for_each_wlvif_sta(wl, wlvif) {
319 wl1271_event_rssi_trigger(wl, wlvif, mbox);
320 }
321 }
322
323 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
324 u8 role_id = mbox->role_id;
325 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
326 "ba_allowed = 0x%x, role_id=%d",
327 mbox->rx_ba_allowed, role_id);
328
329 wl12xx_for_each_wlvif(wl, wlvif) {
330 if (role_id != 0xff && role_id != wlvif->role_id)
331 continue;
332
333 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
334 if (!wlvif->ba_allowed)
335 wl1271_stop_ba_event(wl, wlvif);
336 }
337 }
338
339 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
340 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
341 "status = 0x%x",
342 mbox->channel_switch_status);
343 /*
344 * That event uses for two cases:
345 * 1) channel switch complete with status=0
346 * 2) channel switch failed status=1
347 */
348
349 /* TODO: configure only the relevant vif */
350 wl12xx_for_each_wlvif_sta(wl, wlvif) {
351 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
352 bool success;
353
354 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
355 &wl->flags))
356 continue;
357
358 success = mbox->channel_switch_status ? false : true;
359 ieee80211_chswitch_done(vif, success);
360 }
361 }
362
363 if ((vector & DUMMY_PACKET_EVENT_ID)) {
364 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
365 wl1271_tx_dummy_packet(wl);
366 }
367
368 /*
369 * "TX retries exceeded" has a different meaning according to mode.
370 * In AP mode the offending station is disconnected.
371 */
372 if (vector & MAX_TX_RETRY_EVENT_ID) {
373 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
374 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
375 disconnect_sta = true;
376 }
377
378 if (vector & INACTIVE_STA_EVENT_ID) {
379 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
380 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
381 disconnect_sta = true;
382 }
383
384 if (disconnect_sta) {
385 u32 num_packets = wl->conf.tx.max_tx_retries;
386 struct ieee80211_sta *sta;
387 const u8 *addr;
388 int h;
389
390 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
391 bool found = false;
392 /* find the ap vif connected to this sta */
393 wl12xx_for_each_wlvif_ap(wl, wlvif) {
394 if (!test_bit(h, wlvif->ap.sta_hlid_map))
395 continue;
396 found = true;
397 break;
398 }
399 if (!found)
400 continue;
401
402 vif = wl12xx_wlvif_to_vif(wlvif);
403 addr = wl->links[h].addr;
404
405 rcu_read_lock();
406 sta = ieee80211_find_sta(vif, addr);
407 if (sta) {
408 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
409 ieee80211_report_low_ack(sta, num_packets);
410 }
411 rcu_read_unlock();
412 }
413 }
414
415 if (beacon_loss)
416 wl12xx_for_each_wlvif_sta(wl, wlvif) {
417 vif = wl12xx_wlvif_to_vif(wlvif);
418 ieee80211_connection_loss(vif);
419 }
420
421 return 0;
422 }
423
424 int wl1271_event_unmask(struct wl1271 *wl)
425 {
426 int ret;
427
428 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
429 if (ret < 0)
430 return ret;
431
432 return 0;
433 }
434
435 void wl1271_event_mbox_config(struct wl1271 *wl)
436 {
437 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
438 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
439
440 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
441 wl->mbox_ptr[0], wl->mbox_ptr[1]);
442 }
443
444 int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
445 {
446 struct event_mailbox mbox;
447 int ret;
448
449 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
450
451 if (mbox_num > 1)
452 return -EINVAL;
453
454 /* first we read the mbox descriptor */
455 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
456 sizeof(struct event_mailbox), false);
457
458 /* process the descriptor */
459 ret = wl1271_event_process(wl, &mbox);
460 if (ret < 0)
461 return ret;
462
463 /* then we let the firmware know it can go on...*/
464 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
465
466 return 0;
467 }