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;
141 * BET has only a minor effect in 5GHz and masks
142 * channel switch IEs, so we only enable BET on 2.4GHz
144 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
145 /* enable beacon early termination */
146 ret
= wl1271_acx_bet_enable(wl
, wlvif
, true);
148 if (wlvif
->ps_compl
) {
149 complete(wlvif
->ps_compl
);
150 wlvif
->ps_compl
= NULL
;
160 static void wl1271_event_rssi_trigger(struct wl1271
*wl
,
161 struct wl12xx_vif
*wlvif
,
162 struct event_mailbox
*mbox
)
164 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
165 enum nl80211_cqm_rssi_threshold_event event
;
166 s8 metric
= mbox
->rssi_snr_trigger_metric
[0];
168 wl1271_debug(DEBUG_EVENT
, "RSSI trigger metric: %d", metric
);
170 if (metric
<= wlvif
->rssi_thold
)
171 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
;
173 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
;
175 if (event
!= wlvif
->last_rssi_event
)
176 ieee80211_cqm_rssi_notify(vif
, event
, GFP_KERNEL
);
177 wlvif
->last_rssi_event
= event
;
180 static void wl1271_stop_ba_event(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
182 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
184 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
185 if (!wlvif
->sta
.ba_rx_bitmap
)
187 ieee80211_stop_rx_ba_session(vif
, wlvif
->sta
.ba_rx_bitmap
,
188 vif
->bss_conf
.bssid
);
191 struct wl1271_link
*lnk
;
192 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
,
194 lnk
= &wl
->links
[hlid
];
198 ieee80211_stop_rx_ba_session(vif
,
205 static void wl12xx_event_soft_gemini_sense(struct wl1271
*wl
,
208 struct ieee80211_vif
*vif
;
209 struct wl12xx_vif
*wlvif
;
212 /* disable dynamic PS when requested by the firmware */
213 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
214 vif
= wl12xx_wlvif_to_vif(wlvif
);
215 ieee80211_disable_dyn_ps(vif
);
217 set_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
219 clear_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
220 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
221 vif
= wl12xx_wlvif_to_vif(wlvif
);
222 ieee80211_enable_dyn_ps(vif
);
223 wl1271_recalc_rx_streaming(wl
, wlvif
);
229 static void wl1271_event_mbox_dump(struct event_mailbox
*mbox
)
231 wl1271_debug(DEBUG_EVENT
, "MBOX DUMP:");
232 wl1271_debug(DEBUG_EVENT
, "\tvector: 0x%x", mbox
->events_vector
);
233 wl1271_debug(DEBUG_EVENT
, "\tmask: 0x%x", mbox
->events_mask
);
236 static int wl1271_event_process(struct wl1271
*wl
, struct event_mailbox
*mbox
)
238 struct ieee80211_vif
*vif
;
239 struct wl12xx_vif
*wlvif
;
242 bool beacon_loss
= false;
243 bool disconnect_sta
= false;
244 unsigned long sta_bitmap
= 0;
246 wl1271_event_mbox_dump(mbox
);
248 vector
= le32_to_cpu(mbox
->events_vector
);
249 vector
&= ~(le32_to_cpu(mbox
->events_mask
));
250 wl1271_debug(DEBUG_EVENT
, "vector: 0x%x", vector
);
252 if (vector
& SCAN_COMPLETE_EVENT_ID
) {
253 wl1271_debug(DEBUG_EVENT
, "status: 0x%x",
254 mbox
->scheduled_scan_status
);
256 wl1271_scan_stm(wl
, wl
->scan_vif
);
259 if (vector
& PERIODIC_SCAN_REPORT_EVENT_ID
) {
260 wl1271_debug(DEBUG_EVENT
, "PERIODIC_SCAN_REPORT_EVENT "
261 "(status 0x%0x)", mbox
->scheduled_scan_status
);
263 wl1271_scan_sched_scan_results(wl
);
266 if (vector
& PERIODIC_SCAN_COMPLETE_EVENT_ID
) {
267 wl1271_debug(DEBUG_EVENT
, "PERIODIC_SCAN_COMPLETE_EVENT "
268 "(status 0x%0x)", mbox
->scheduled_scan_status
);
269 if (wl
->sched_scanning
) {
270 ieee80211_sched_scan_stopped(wl
->hw
);
271 wl
->sched_scanning
= false;
275 if (vector
& SOFT_GEMINI_SENSE_EVENT_ID
)
276 wl12xx_event_soft_gemini_sense(wl
,
277 mbox
->soft_gemini_sense_info
);
280 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
281 * filtering) is enabled. Without PSM, the stack will receive all
282 * beacons and can detect beacon loss by itself.
284 * As there's possibility that the driver disables PSM before receiving
285 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
288 if (vector
& BSS_LOSE_EVENT_ID
) {
289 /* TODO: check for multi-role */
290 wl1271_info("Beacon loss detected.");
292 /* indicate to the stack, that beacons have been lost */
296 if (vector
& PS_REPORT_EVENT_ID
) {
297 wl1271_debug(DEBUG_EVENT
, "PS_REPORT_EVENT");
298 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
299 ret
= wl1271_event_ps_report(wl
, wlvif
,
306 if (vector
& PSPOLL_DELIVERY_FAILURE_EVENT_ID
)
307 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
308 wl1271_event_pspoll_delivery_fail(wl
, wlvif
);
311 if (vector
& RSSI_SNR_TRIGGER_0_EVENT_ID
) {
312 /* TODO: check actual multi-role support */
313 wl1271_debug(DEBUG_EVENT
, "RSSI_SNR_TRIGGER_0_EVENT");
314 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
315 wl1271_event_rssi_trigger(wl
, wlvif
, mbox
);
319 if (vector
& BA_SESSION_RX_CONSTRAINT_EVENT_ID
) {
320 u8 role_id
= mbox
->role_id
;
321 wl1271_debug(DEBUG_EVENT
, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
322 "ba_allowed = 0x%x, role_id=%d",
323 mbox
->rx_ba_allowed
, role_id
);
325 wl12xx_for_each_wlvif(wl
, wlvif
) {
326 if (role_id
!= 0xff && role_id
!= wlvif
->role_id
)
329 wlvif
->ba_allowed
= !!mbox
->rx_ba_allowed
;
330 if (!wlvif
->ba_allowed
)
331 wl1271_stop_ba_event(wl
, wlvif
);
335 if (vector
& CHANNEL_SWITCH_COMPLETE_EVENT_ID
) {
336 wl1271_debug(DEBUG_EVENT
, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
338 mbox
->channel_switch_status
);
340 * That event uses for two cases:
341 * 1) channel switch complete with status=0
342 * 2) channel switch failed status=1
345 /* TODO: configure only the relevant vif */
346 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
347 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
350 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
,
354 success
= mbox
->channel_switch_status
? false : true;
355 ieee80211_chswitch_done(vif
, success
);
359 if ((vector
& DUMMY_PACKET_EVENT_ID
)) {
360 wl1271_debug(DEBUG_EVENT
, "DUMMY_PACKET_ID_EVENT_ID");
361 wl1271_tx_dummy_packet(wl
);
365 * "TX retries exceeded" has a different meaning according to mode.
366 * In AP mode the offending station is disconnected.
368 if (vector
& MAX_TX_RETRY_EVENT_ID
) {
369 wl1271_debug(DEBUG_EVENT
, "MAX_TX_RETRY_EVENT_ID");
370 sta_bitmap
|= le16_to_cpu(mbox
->sta_tx_retry_exceeded
);
371 disconnect_sta
= true;
374 if (vector
& INACTIVE_STA_EVENT_ID
) {
375 wl1271_debug(DEBUG_EVENT
, "INACTIVE_STA_EVENT_ID");
376 sta_bitmap
|= le16_to_cpu(mbox
->sta_aging_status
);
377 disconnect_sta
= true;
380 if (disconnect_sta
) {
381 u32 num_packets
= wl
->conf
.tx
.max_tx_retries
;
382 struct ieee80211_sta
*sta
;
386 for_each_set_bit(h
, &sta_bitmap
, WL12XX_MAX_LINKS
) {
388 /* find the ap vif connected to this sta */
389 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
390 if (!test_bit(h
, wlvif
->ap
.sta_hlid_map
))
398 vif
= wl12xx_wlvif_to_vif(wlvif
);
399 addr
= wl
->links
[h
].addr
;
402 sta
= ieee80211_find_sta(vif
, addr
);
404 wl1271_debug(DEBUG_EVENT
, "remove sta %d", h
);
405 ieee80211_report_low_ack(sta
, num_packets
);
412 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
413 vif
= wl12xx_wlvif_to_vif(wlvif
);
414 ieee80211_connection_loss(vif
);
420 int wl1271_event_unmask(struct wl1271
*wl
)
424 ret
= wl1271_acx_event_mbox_mask(wl
, ~(wl
->event_mask
));
431 void wl1271_event_mbox_config(struct wl1271
*wl
)
433 wl
->mbox_ptr
[0] = wl1271_read32(wl
, REG_EVENT_MAILBOX_PTR
);
434 wl
->mbox_ptr
[1] = wl
->mbox_ptr
[0] + sizeof(struct event_mailbox
);
436 wl1271_debug(DEBUG_EVENT
, "MBOX ptrs: 0x%x 0x%x",
437 wl
->mbox_ptr
[0], wl
->mbox_ptr
[1]);
440 int wl1271_event_handle(struct wl1271
*wl
, u8 mbox_num
)
442 struct event_mailbox mbox
;
445 wl1271_debug(DEBUG_EVENT
, "EVENT on mbox %d", mbox_num
);
450 /* first we read the mbox descriptor */
451 wl1271_read(wl
, wl
->mbox_ptr
[mbox_num
], &mbox
,
452 sizeof(struct event_mailbox
), false);
454 /* process the descriptor */
455 ret
= wl1271_event_process(wl
, &mbox
);
459 /* then we let the firmware know it can go on...*/
460 wl1271_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_EVENT_ACK
);