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
30 #include "wl12xx_80211.h"
32 void wl1271_pspoll_work(struct work_struct
*work
)
34 struct ieee80211_vif
*vif
;
35 struct wl12xx_vif
*wlvif
;
36 struct delayed_work
*dwork
;
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
);
45 wl1271_debug(DEBUG_EVENT
, "pspoll work");
47 mutex_lock(&wl
->mutex
);
49 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
52 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE
, &wl
->flags
))
55 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED
, &wl
->flags
))
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.
63 ret
= wl1271_ps_elp_wakeup(wl
);
67 wl1271_ps_set_mode(wl
, wlvif
, STATION_POWER_SAVE_MODE
,
68 wlvif
->basic_rate
, true);
70 wl1271_ps_elp_sleep(wl
);
72 mutex_unlock(&wl
->mutex
);
75 static void wl1271_event_pspoll_delivery_fail(struct wl1271
*wl
,
76 struct wl12xx_vif
*wlvif
)
78 int delay
= wl
->conf
.conn
.ps_poll_recovery_period
;
81 wl
->ps_poll_failures
++;
82 if (wl
->ps_poll_failures
== 1)
83 wl1271_info("AP with dysfunctional ps-poll, "
84 "trying to work around it.");
86 /* force active mode receive data from the AP */
87 if (test_bit(WL1271_FLAG_PSM
, &wl
->flags
)) {
88 ret
= wl1271_ps_set_mode(wl
, wlvif
, STATION_ACTIVE_MODE
,
89 wlvif
->basic_rate
, true);
92 set_bit(WL1271_FLAG_PSPOLL_FAILURE
, &wl
->flags
);
93 ieee80211_queue_delayed_work(wl
->hw
, &wlvif
->pspoll_work
,
94 msecs_to_jiffies(delay
));
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.
105 static int wl1271_event_ps_report(struct wl1271
*wl
,
106 struct wl12xx_vif
*wlvif
,
107 struct event_mailbox
*mbox
,
111 u32 total_retries
= wl
->conf
.conn
.psm_entry_retries
;
113 wl1271_debug(DEBUG_EVENT
, "ps_status: 0x%x", mbox
->ps_status
);
115 switch (mbox
->ps_status
) {
116 case EVENT_ENTER_POWER_SAVE_FAIL
:
117 wl1271_debug(DEBUG_PSM
, "PSM entry failed");
119 if (!test_bit(WL1271_FLAG_PSM
, &wl
->flags
)) {
120 /* remain in active mode */
121 wl
->psm_entry_retry
= 0;
125 if (wl
->psm_entry_retry
< total_retries
) {
126 wl
->psm_entry_retry
++;
127 ret
= wl1271_ps_set_mode(wl
, wlvif
,
128 STATION_POWER_SAVE_MODE
,
129 wlvif
->basic_rate
, true);
131 wl1271_info("No ack to nullfunc from AP.");
132 wl
->psm_entry_retry
= 0;
136 case EVENT_ENTER_POWER_SAVE_SUCCESS
:
137 wl
->psm_entry_retry
= 0;
139 /* enable beacon filtering */
140 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
145 * BET has only a minor effect in 5GHz and masks
146 * channel switch IEs, so we only enable BET on 2.4GHz
148 if (wl
->band
== IEEE80211_BAND_2GHZ
)
149 /* enable beacon early termination */
150 ret
= wl1271_acx_bet_enable(wl
, wlvif
, true);
153 complete(wl
->ps_compl
);
164 static void wl1271_event_rssi_trigger(struct wl1271
*wl
,
165 struct event_mailbox
*mbox
)
167 enum nl80211_cqm_rssi_threshold_event event
;
168 s8 metric
= mbox
->rssi_snr_trigger_metric
[0];
170 wl1271_debug(DEBUG_EVENT
, "RSSI trigger metric: %d", metric
);
172 if (metric
<= wl
->rssi_thold
)
173 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
;
175 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
;
177 if (event
!= wl
->last_rssi_event
)
178 ieee80211_cqm_rssi_notify(wl
->vif
, event
, GFP_KERNEL
);
179 wl
->last_rssi_event
= event
;
182 static void wl1271_stop_ba_event(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
184 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
185 if (!wl
->ba_rx_bitmap
)
187 ieee80211_stop_rx_ba_session(wl
->vif
, wl
->ba_rx_bitmap
,
188 wl
->vif
->bss_conf
.bssid
);
191 struct wl1271_link
*lnk
;
192 for (i
= WL1271_AP_STA_HLID_START
; i
< AP_MAX_LINKS
; i
++) {
194 if (!wl1271_is_active_sta(wl
, i
) || !lnk
->ba_bitmap
)
197 ieee80211_stop_rx_ba_session(wl
->vif
,
204 static void wl12xx_event_soft_gemini_sense(struct wl1271
*wl
,
208 /* disable dynamic PS when requested by the firmware */
209 ieee80211_disable_dyn_ps(wl
->vif
);
210 set_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
212 ieee80211_enable_dyn_ps(wl
->vif
);
213 clear_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
214 wl1271_recalc_rx_streaming(wl
);
219 static void wl1271_event_mbox_dump(struct event_mailbox
*mbox
)
221 wl1271_debug(DEBUG_EVENT
, "MBOX DUMP:");
222 wl1271_debug(DEBUG_EVENT
, "\tvector: 0x%x", mbox
->events_vector
);
223 wl1271_debug(DEBUG_EVENT
, "\tmask: 0x%x", mbox
->events_mask
);
226 static int wl1271_event_process(struct wl1271
*wl
, struct event_mailbox
*mbox
)
228 struct ieee80211_vif
*vif
= wl
->vif
; /* TODO: get as param */
229 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
232 bool beacon_loss
= false;
233 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
234 bool disconnect_sta
= false;
235 unsigned long sta_bitmap
= 0;
237 wl1271_event_mbox_dump(mbox
);
239 vector
= le32_to_cpu(mbox
->events_vector
);
240 vector
&= ~(le32_to_cpu(mbox
->events_mask
));
241 wl1271_debug(DEBUG_EVENT
, "vector: 0x%x", vector
);
243 if (vector
& SCAN_COMPLETE_EVENT_ID
) {
244 wl1271_debug(DEBUG_EVENT
, "status: 0x%x",
245 mbox
->scheduled_scan_status
);
247 wl1271_scan_stm(wl
, wl
->scan_vif
);
250 if (vector
& PERIODIC_SCAN_REPORT_EVENT_ID
) {
251 wl1271_debug(DEBUG_EVENT
, "PERIODIC_SCAN_REPORT_EVENT "
252 "(status 0x%0x)", mbox
->scheduled_scan_status
);
254 wl1271_scan_sched_scan_results(wl
);
257 if (vector
& PERIODIC_SCAN_COMPLETE_EVENT_ID
) {
258 wl1271_debug(DEBUG_EVENT
, "PERIODIC_SCAN_COMPLETE_EVENT "
259 "(status 0x%0x)", mbox
->scheduled_scan_status
);
260 if (wl
->sched_scanning
) {
261 wl1271_scan_sched_scan_stop(wl
);
262 ieee80211_sched_scan_stopped(wl
->hw
);
266 if (vector
& SOFT_GEMINI_SENSE_EVENT_ID
&&
267 wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
268 wl12xx_event_soft_gemini_sense(wl
,
269 mbox
->soft_gemini_sense_info
);
272 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
273 * filtering) is enabled. Without PSM, the stack will receive all
274 * beacons and can detect beacon loss by itself.
276 * As there's possibility that the driver disables PSM before receiving
277 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
280 if ((vector
& BSS_LOSE_EVENT_ID
) && !is_ap
) {
281 wl1271_info("Beacon loss detected.");
283 /* indicate to the stack, that beacons have been lost */
287 if ((vector
& PS_REPORT_EVENT_ID
) && !is_ap
) {
288 wl1271_debug(DEBUG_EVENT
, "PS_REPORT_EVENT");
289 ret
= wl1271_event_ps_report(wl
, wlvif
, mbox
, &beacon_loss
);
294 if ((vector
& PSPOLL_DELIVERY_FAILURE_EVENT_ID
) && !is_ap
)
295 wl1271_event_pspoll_delivery_fail(wl
, wlvif
);
297 if (vector
& RSSI_SNR_TRIGGER_0_EVENT_ID
) {
298 wl1271_debug(DEBUG_EVENT
, "RSSI_SNR_TRIGGER_0_EVENT");
300 wl1271_event_rssi_trigger(wl
, mbox
);
303 if ((vector
& BA_SESSION_RX_CONSTRAINT_EVENT_ID
)) {
304 wl1271_debug(DEBUG_EVENT
, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
305 "ba_allowed = 0x%x", mbox
->rx_ba_allowed
);
307 wl
->ba_allowed
= !!mbox
->rx_ba_allowed
;
309 if (wl
->vif
&& !wl
->ba_allowed
)
310 wl1271_stop_ba_event(wl
, wlvif
);
313 if ((vector
& CHANNEL_SWITCH_COMPLETE_EVENT_ID
) && !is_ap
) {
314 wl1271_debug(DEBUG_EVENT
, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
316 mbox
->channel_switch_status
);
318 * That event uses for two cases:
319 * 1) channel switch complete with status=0
320 * 2) channel switch failed status=1
322 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS
, &wl
->flags
) &&
324 ieee80211_chswitch_done(wl
->vif
,
325 mbox
->channel_switch_status
? false : true);
328 if ((vector
& DUMMY_PACKET_EVENT_ID
)) {
329 wl1271_debug(DEBUG_EVENT
, "DUMMY_PACKET_ID_EVENT_ID");
331 wl1271_tx_dummy_packet(wl
);
335 * "TX retries exceeded" has a different meaning according to mode.
336 * In AP mode the offending station is disconnected.
338 if ((vector
& MAX_TX_RETRY_EVENT_ID
) && is_ap
) {
339 wl1271_debug(DEBUG_EVENT
, "MAX_TX_RETRY_EVENT_ID");
340 sta_bitmap
|= le16_to_cpu(mbox
->sta_tx_retry_exceeded
);
341 disconnect_sta
= true;
344 if ((vector
& INACTIVE_STA_EVENT_ID
) && is_ap
) {
345 wl1271_debug(DEBUG_EVENT
, "INACTIVE_STA_EVENT_ID");
346 sta_bitmap
|= le16_to_cpu(mbox
->sta_aging_status
);
347 disconnect_sta
= true;
350 if (is_ap
&& disconnect_sta
) {
351 u32 num_packets
= wl
->conf
.tx
.max_tx_retries
;
352 struct ieee80211_sta
*sta
;
356 for (h
= find_first_bit(&sta_bitmap
, AP_MAX_LINKS
);
358 h
= find_next_bit(&sta_bitmap
, AP_MAX_LINKS
, h
+1)) {
359 if (!wl1271_is_active_sta(wl
, h
))
362 addr
= wl
->links
[h
].addr
;
365 sta
= ieee80211_find_sta(wl
->vif
, addr
);
367 wl1271_debug(DEBUG_EVENT
, "remove sta %d", h
);
368 ieee80211_report_low_ack(sta
, num_packets
);
374 if (wl
->vif
&& beacon_loss
)
375 ieee80211_connection_loss(wl
->vif
);
380 int wl1271_event_unmask(struct wl1271
*wl
)
384 ret
= wl1271_acx_event_mbox_mask(wl
, ~(wl
->event_mask
));
391 void wl1271_event_mbox_config(struct wl1271
*wl
)
393 wl
->mbox_ptr
[0] = wl1271_read32(wl
, REG_EVENT_MAILBOX_PTR
);
394 wl
->mbox_ptr
[1] = wl
->mbox_ptr
[0] + sizeof(struct event_mailbox
);
396 wl1271_debug(DEBUG_EVENT
, "MBOX ptrs: 0x%x 0x%x",
397 wl
->mbox_ptr
[0], wl
->mbox_ptr
[1]);
400 int wl1271_event_handle(struct wl1271
*wl
, u8 mbox_num
)
402 struct event_mailbox mbox
;
405 wl1271_debug(DEBUG_EVENT
, "EVENT on mbox %d", mbox_num
);
410 /* first we read the mbox descriptor */
411 wl1271_read(wl
, wl
->mbox_ptr
[mbox_num
], &mbox
,
412 sizeof(struct event_mailbox
), false);
414 /* process the descriptor */
415 ret
= wl1271_event_process(wl
, &mbox
);
419 /* then we let the firmware know it can go on...*/
420 wl1271_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_EVENT_ACK
);