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
31 #include "wl12xx_80211.h"
33 void wl1271_pspoll_work(struct work_struct *work)
35 struct ieee80211_vif *vif;
36 struct wl12xx_vif *wlvif;
37 struct delayed_work *dwork;
41 dwork = container_of(work, struct delayed_work, work);
42 wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work);
43 vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
46 wl1271_debug(DEBUG_EVENT, "pspoll work");
48 mutex_lock(&wl->mutex);
50 if (unlikely(wl->state == WL1271_STATE_OFF))
53 if (!test_and_clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags))
56 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
60 * if we end up here, then we were in powersave when the pspoll
61 * delivery failure occurred, and no-one changed state since, so
62 * we should go back to powersave.
64 ret = wl1271_ps_elp_wakeup(wl);
68 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
69 wlvif->basic_rate, true);
71 wl1271_ps_elp_sleep(wl);
73 mutex_unlock(&wl->mutex);
76 static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl,
77 struct wl12xx_vif *wlvif)
79 int delay = wl->conf.conn.ps_poll_recovery_period;
82 wlvif->ps_poll_failures++;
83 if (wlvif->ps_poll_failures == 1)
84 wl1271_info("AP with dysfunctional ps-poll, "
85 "trying to work around it.");
87 /* force active mode receive data from the AP */
88 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
89 ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
90 wlvif->basic_rate, true);
93 set_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
94 ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work,
95 msecs_to_jiffies(delay));
99 * If already in active mode, lets we should be getting data from
100 * the AP right away. If we enter PSM too fast after this, and data
101 * remains on the AP, we will get another event like this, and we'll
102 * go into active once more.
106 static int wl1271_event_ps_report(struct wl1271 *wl,
107 struct wl12xx_vif *wlvif,
108 struct event_mailbox *mbox,
112 u32 total_retries = wl->conf.conn.psm_entry_retries;
114 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
116 switch (mbox->ps_status) {
117 case EVENT_ENTER_POWER_SAVE_FAIL:
118 wl1271_debug(DEBUG_PSM, "PSM entry failed");
120 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
121 /* remain in active mode */
122 wlvif->psm_entry_retry = 0;
126 if (wlvif->psm_entry_retry < total_retries) {
127 wlvif->psm_entry_retry++;
128 ret = wl1271_ps_set_mode(wl, wlvif,
129 STATION_POWER_SAVE_MODE,
130 wlvif->basic_rate, true);
132 wl1271_info("No ack to nullfunc from AP.");
133 wlvif->psm_entry_retry = 0;
137 case EVENT_ENTER_POWER_SAVE_SUCCESS:
138 wlvif->psm_entry_retry = 0;
140 /* enable beacon filtering */
141 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
146 * BET has only a minor effect in 5GHz and masks
147 * channel switch IEs, so we only enable BET on 2.4GHz
149 if (wlvif->band == IEEE80211_BAND_2GHZ)
150 /* enable beacon early termination */
151 ret = wl1271_acx_bet_enable(wl, wlvif, true);
153 if (wlvif->ps_compl) {
154 complete(wlvif->ps_compl);
155 wlvif->ps_compl = NULL;
165 static void wl1271_event_rssi_trigger(struct wl1271 *wl,
166 struct wl12xx_vif *wlvif,
167 struct event_mailbox *mbox)
169 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
170 enum nl80211_cqm_rssi_threshold_event event;
171 s8 metric = mbox->rssi_snr_trigger_metric[0];
173 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
175 if (metric <= wlvif->rssi_thold)
176 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
178 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
180 if (event != wlvif->last_rssi_event)
181 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
182 wlvif->last_rssi_event = event;
185 static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
187 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
189 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
190 if (!wlvif->sta.ba_rx_bitmap)
192 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
193 vif->bss_conf.bssid);
196 struct wl1271_link *lnk;
197 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
199 lnk = &wl->links[hlid];
203 ieee80211_stop_rx_ba_session(vif,
210 static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
213 struct ieee80211_vif *vif;
214 struct wl12xx_vif *wlvif;
217 /* disable dynamic PS when requested by the firmware */
218 wl12xx_for_each_wlvif_sta(wl, wlvif) {
219 vif = wl12xx_wlvif_to_vif(wlvif);
220 ieee80211_disable_dyn_ps(vif);
222 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
224 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
225 wl12xx_for_each_wlvif_sta(wl, wlvif) {
226 vif = wl12xx_wlvif_to_vif(wlvif);
227 ieee80211_enable_dyn_ps(vif);
228 wl1271_recalc_rx_streaming(wl, wlvif);
234 static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
236 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
237 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
238 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
241 static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
243 struct ieee80211_vif *vif;
244 struct wl12xx_vif *wlvif;
247 bool beacon_loss = false;
248 bool disconnect_sta = false;
249 unsigned long sta_bitmap = 0;
251 wl1271_event_mbox_dump(mbox);
253 vector = le32_to_cpu(mbox->events_vector);
254 vector &= ~(le32_to_cpu(mbox->events_mask));
255 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
257 if (vector & SCAN_COMPLETE_EVENT_ID) {
258 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
259 mbox->scheduled_scan_status);
261 wl1271_scan_stm(wl, wl->scan_vif);
264 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
265 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
266 "(status 0x%0x)", mbox->scheduled_scan_status);
268 wl1271_scan_sched_scan_results(wl);
271 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
272 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
273 "(status 0x%0x)", mbox->scheduled_scan_status);
274 if (wl->sched_scanning) {
275 wl1271_scan_sched_scan_stop(wl);
276 ieee80211_sched_scan_stopped(wl->hw);
280 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
281 wl12xx_event_soft_gemini_sense(wl,
282 mbox->soft_gemini_sense_info);
285 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
286 * filtering) is enabled. Without PSM, the stack will receive all
287 * beacons and can detect beacon loss by itself.
289 * As there's possibility that the driver disables PSM before receiving
290 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
293 if (vector & BSS_LOSE_EVENT_ID) {
294 /* TODO: check for multi-role */
295 wl1271_info("Beacon loss detected.");
297 /* indicate to the stack, that beacons have been lost */
301 if (vector & PS_REPORT_EVENT_ID) {
302 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
303 wl12xx_for_each_wlvif_sta(wl, wlvif) {
304 ret = wl1271_event_ps_report(wl, wlvif,
311 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
312 wl12xx_for_each_wlvif_sta(wl, wlvif) {
313 wl1271_event_pspoll_delivery_fail(wl, wlvif);
316 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
317 /* TODO: check actual multi-role support */
318 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
319 wl12xx_for_each_wlvif_sta(wl, wlvif) {
320 wl1271_event_rssi_trigger(wl, wlvif, mbox);
324 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
325 u8 role_id = mbox->role_id;
326 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
327 "ba_allowed = 0x%x, role_id=%d",
328 mbox->rx_ba_allowed, role_id);
330 wl12xx_for_each_wlvif(wl, wlvif) {
331 if (role_id != 0xff && role_id != wlvif->role_id)
334 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
335 if (!wlvif->ba_allowed)
336 wl1271_stop_ba_event(wl, wlvif);
340 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
341 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
343 mbox->channel_switch_status);
345 * That event uses for two cases:
346 * 1) channel switch complete with status=0
347 * 2) channel switch failed status=1
350 /* TODO: configure only the relevant vif */
351 wl12xx_for_each_wlvif_sta(wl, wlvif) {
352 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
355 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
359 success = mbox->channel_switch_status ? false : true;
360 ieee80211_chswitch_done(vif, success);
364 if ((vector & DUMMY_PACKET_EVENT_ID)) {
365 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
366 wl1271_tx_dummy_packet(wl);
370 * "TX retries exceeded" has a different meaning according to mode.
371 * In AP mode the offending station is disconnected.
373 if (vector & MAX_TX_RETRY_EVENT_ID) {
374 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
375 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
376 disconnect_sta = true;
379 if (vector & INACTIVE_STA_EVENT_ID) {
380 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
381 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
382 disconnect_sta = true;
385 if (disconnect_sta) {
386 u32 num_packets = wl->conf.tx.max_tx_retries;
387 struct ieee80211_sta *sta;
391 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
393 /* find the ap vif connected to this sta */
394 wl12xx_for_each_wlvif_ap(wl, wlvif) {
395 if (!test_bit(h, wlvif->ap.sta_hlid_map))
403 vif = wl12xx_wlvif_to_vif(wlvif);
404 addr = wl->links[h].addr;
407 sta = ieee80211_find_sta(vif, addr);
409 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
410 ieee80211_report_low_ack(sta, num_packets);
417 wl12xx_for_each_wlvif_sta(wl, wlvif) {
418 vif = wl12xx_wlvif_to_vif(wlvif);
419 ieee80211_connection_loss(vif);
425 int wl1271_event_unmask(struct wl1271 *wl)
429 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
436 void wl1271_event_mbox_config(struct wl1271 *wl)
438 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
439 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
441 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
442 wl->mbox_ptr[0], wl->mbox_ptr[1]);
445 int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
447 struct event_mailbox mbox;
450 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
455 /* first we read the mbox descriptor */
456 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
457 sizeof(struct event_mailbox), false);
459 /* process the descriptor */
460 ret = wl1271_event_process(wl, &mbox);
464 /* then we let the firmware know it can go on...*/
465 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);