blob: e22df6ce139ad439e9a9289848f22e9facb7a521 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
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
Shahar Levi00d20102010-11-08 11:20:10 +000024#include "wl12xx.h"
Luciano Coelho0f4e3122011-10-07 11:02:42 +030025#include "debug.h"
Shahar Levi00d20102010-11-08 11:20:10 +000026#include "reg.h"
27#include "io.h"
28#include "event.h"
29#include "ps.h"
30#include "scan.h"
Juuso Oikarinen66497dc2009-10-08 21:56:30 +030031#include "wl12xx_80211.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030032
Juuso Oikarinen90494a92010-07-08 17:50:00 +030033void wl1271_pspoll_work(struct work_struct *work)
34{
Eliad Pellerd2d66c52011-10-05 11:55:43 +020035 struct ieee80211_vif *vif;
36 struct wl12xx_vif *wlvif;
Juuso Oikarinen90494a92010-07-08 17:50:00 +030037 struct delayed_work *dwork;
38 struct wl1271 *wl;
Eliad Pellerc1b193e2011-03-23 22:22:15 +020039 int ret;
Juuso Oikarinen90494a92010-07-08 17:50:00 +030040
41 dwork = container_of(work, struct delayed_work, work);
Eliad Peller252efa42011-10-05 11:56:00 +020042 wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work);
43 vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
44 wl = wlvif->wl;
Juuso Oikarinen90494a92010-07-08 17:50:00 +030045
46 wl1271_debug(DEBUG_EVENT, "pspoll work");
47
48 mutex_lock(&wl->mutex);
49
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +020050 if (unlikely(wl->state == WL1271_STATE_OFF))
51 goto out;
52
Eliad Peller836d6602011-10-10 10:13:07 +020053 if (!test_and_clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags))
Juuso Oikarinen90494a92010-07-08 17:50:00 +030054 goto out;
55
Eliad Pellerba8447f2011-10-10 10:13:00 +020056 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
Juuso Oikarinen90494a92010-07-08 17:50:00 +030057 goto out;
58
59 /*
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.
63 */
Eliad Pellerc1b193e2011-03-23 22:22:15 +020064 ret = wl1271_ps_elp_wakeup(wl);
65 if (ret < 0)
66 goto out;
67
Eliad Peller0603d892011-10-05 11:55:51 +020068 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
69 wlvif->basic_rate, true);
Juuso Oikarinen90494a92010-07-08 17:50:00 +030070
Eliad Pellerc1b193e2011-03-23 22:22:15 +020071 wl1271_ps_elp_sleep(wl);
Juuso Oikarinen90494a92010-07-08 17:50:00 +030072out:
73 mutex_unlock(&wl->mutex);
74};
75
Eliad Pellerd2d66c52011-10-05 11:55:43 +020076static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl,
77 struct wl12xx_vif *wlvif)
Juuso Oikarinen90494a92010-07-08 17:50:00 +030078{
79 int delay = wl->conf.conn.ps_poll_recovery_period;
80 int ret;
81
Eliad Peller74ec8392011-10-05 11:56:02 +020082 wlvif->ps_poll_failures++;
83 if (wlvif->ps_poll_failures == 1)
Juuso Oikarinen90494a92010-07-08 17:50:00 +030084 wl1271_info("AP with dysfunctional ps-poll, "
85 "trying to work around it.");
86
87 /* force active mode receive data from the AP */
Eliad Pellerc29bb002011-10-10 10:13:03 +020088 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +020089 ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +020090 wlvif->basic_rate, true);
Juuso Oikarinen90494a92010-07-08 17:50:00 +030091 if (ret < 0)
92 return;
Eliad Peller836d6602011-10-10 10:13:07 +020093 set_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
Eliad Peller252efa42011-10-05 11:56:00 +020094 ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work,
Juuso Oikarinen90494a92010-07-08 17:50:00 +030095 msecs_to_jiffies(delay));
96 }
97
98 /*
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.
103 */
104}
105
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200106static int wl1271_event_ps_report(struct wl1271 *wl,
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200107 struct wl12xx_vif *wlvif,
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200108 struct event_mailbox *mbox,
109 bool *beacon_loss)
110{
111 int ret = 0;
Juuso Oikarinen65cddbf2010-08-24 06:28:03 +0300112 u32 total_retries = wl->conf.conn.psm_entry_retries;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200113
114 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
115
116 switch (mbox->ps_status) {
117 case EVENT_ENTER_POWER_SAVE_FAIL:
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200118 wl1271_debug(DEBUG_PSM, "PSM entry failed");
119
Eliad Pellerc29bb002011-10-10 10:13:03 +0200120 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200121 /* remain in active mode */
Eliad Peller74ec8392011-10-05 11:56:02 +0200122 wlvif->psm_entry_retry = 0;
Juuso Oikarinen461fa132009-11-23 23:22:13 +0200123 break;
124 }
125
Eliad Peller74ec8392011-10-05 11:56:02 +0200126 if (wlvif->psm_entry_retry < total_retries) {
127 wlvif->psm_entry_retry++;
Eliad Peller0603d892011-10-05 11:55:51 +0200128 ret = wl1271_ps_set_mode(wl, wlvif,
129 STATION_POWER_SAVE_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200130 wlvif->basic_rate, true);
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200131 } else {
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300132 wl1271_info("No ack to nullfunc from AP.");
Eliad Peller74ec8392011-10-05 11:56:02 +0200133 wlvif->psm_entry_retry = 0;
Juuso Oikarinend60772f2010-03-26 12:53:29 +0200134 *beacon_loss = true;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200135 }
136 break;
137 case EVENT_ENTER_POWER_SAVE_SUCCESS:
Eliad Peller74ec8392011-10-05 11:56:02 +0200138 wlvif->psm_entry_retry = 0;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200139
140 /* enable beacon filtering */
Eliad Peller0603d892011-10-05 11:55:51 +0200141 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200142 if (ret < 0)
143 break;
144
Shahar Levi0e44eb22011-05-16 15:35:30 +0300145 /*
146 * BET has only a minor effect in 5GHz and masks
147 * channel switch IEs, so we only enable BET on 2.4GHz
148 */
Eliad Peller1b92f152011-10-10 10:13:09 +0200149 if (wlvif->band == IEEE80211_BAND_2GHZ)
Shahar Levi0e44eb22011-05-16 15:35:30 +0300150 /* enable beacon early termination */
Eliad Peller0603d892011-10-05 11:55:51 +0200151 ret = wl1271_acx_bet_enable(wl, wlvif, true);
Eliad Peller94390642011-05-13 11:57:13 +0300152
Eliad Peller6ec45dc2011-10-05 11:56:01 +0200153 if (wlvif->ps_compl) {
154 complete(wlvif->ps_compl);
155 wlvif->ps_compl = NULL;
Eliad Peller94390642011-05-13 11:57:13 +0300156 }
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200157 break;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200158 default:
159 break;
160 }
161
162 return ret;
163}
164
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300165static void wl1271_event_rssi_trigger(struct wl1271 *wl,
Eliad Peller4b730b62011-10-10 10:12:57 +0200166 struct wl12xx_vif *wlvif,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300167 struct event_mailbox *mbox)
168{
Eliad Peller4b730b62011-10-10 10:12:57 +0200169 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300170 enum nl80211_cqm_rssi_threshold_event event;
171 s8 metric = mbox->rssi_snr_trigger_metric[0];
172
173 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
174
Eliad Peller04324d92011-10-05 11:56:03 +0200175 if (metric <= wlvif->rssi_thold)
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300176 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
177 else
178 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
179
Eliad Peller04324d92011-10-05 11:56:03 +0200180 if (event != wlvif->last_rssi_event)
181 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
182 wlvif->last_rssi_event = event;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300183}
184
Eliad Peller536129c2011-10-05 11:55:45 +0200185static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Shahar Levi70559a02011-05-22 16:10:22 +0300186{
Eliad Peller4b730b62011-10-10 10:12:57 +0200187 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
188
Eliad Peller536129c2011-10-05 11:55:45 +0200189 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200190 if (!wlvif->sta.ba_rx_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300191 return;
Eliad Peller4b730b62011-10-10 10:12:57 +0200192 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
193 vif->bss_conf.bssid);
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300194 } else {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200195 u8 hlid;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300196 struct wl1271_link *lnk;
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200197 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
198 WL12XX_MAX_LINKS) {
199 lnk = &wl->links[hlid];
200 if (!lnk->ba_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300201 continue;
Shahar Levi70559a02011-05-22 16:10:22 +0300202
Eliad Peller4b730b62011-10-10 10:12:57 +0200203 ieee80211_stop_rx_ba_session(vif,
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300204 lnk->ba_bitmap,
205 lnk->addr);
206 }
207 }
Shahar Levi70559a02011-05-22 16:10:22 +0300208}
209
Eliad Peller77ddaa12011-05-15 11:10:29 +0300210static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
211 u8 enable)
212{
Eliad Peller4b730b62011-10-10 10:12:57 +0200213 struct ieee80211_vif *vif;
214 struct wl12xx_vif *wlvif;
215
Eliad Peller77ddaa12011-05-15 11:10:29 +0300216 if (enable) {
217 /* disable dynamic PS when requested by the firmware */
Eliad Peller4b730b62011-10-10 10:12:57 +0200218 wl12xx_for_each_wlvif_sta(wl, wlvif) {
219 vif = wl12xx_wlvif_to_vif(wlvif);
220 ieee80211_disable_dyn_ps(vif);
221 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300222 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
223 } else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200224 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
Eliad Peller4b730b62011-10-10 10:12:57 +0200225 wl12xx_for_each_wlvif_sta(wl, wlvif) {
226 vif = wl12xx_wlvif_to_vif(wlvif);
227 ieee80211_enable_dyn_ps(vif);
Eliad Peller9eb599e2011-10-10 10:12:59 +0200228 wl1271_recalc_rx_streaming(wl, wlvif);
Eliad Peller4b730b62011-10-10 10:12:57 +0200229 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300230 }
231
232}
233
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300234static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
235{
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);
239}
240
241static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
242{
Eliad Peller4b730b62011-10-10 10:12:57 +0200243 struct ieee80211_vif *vif;
244 struct wl12xx_vif *wlvif;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300245 int ret;
246 u32 vector;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200247 bool beacon_loss = false;
Arik Nemtsov3618f302011-06-26 10:36:03 +0300248 bool disconnect_sta = false;
249 unsigned long sta_bitmap = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300250
251 wl1271_event_mbox_dump(mbox);
252
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300253 vector = le32_to_cpu(mbox->events_vector);
254 vector &= ~(le32_to_cpu(mbox->events_mask));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300255 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
256
257 if (vector & SCAN_COMPLETE_EVENT_ID) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300258 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
259 mbox->scheduled_scan_status);
260
Eliad Peller784f6942011-10-05 11:55:39 +0200261 wl1271_scan_stm(wl, wl->scan_vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300262 }
263
Luciano Coelho6394c012011-05-10 14:28:27 +0300264 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
265 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
266 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300267
268 wl1271_scan_sched_scan_results(wl);
Luciano Coelho6394c012011-05-10 14:28:27 +0300269 }
270
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);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300274 if (wl->sched_scanning) {
275 wl1271_scan_sched_scan_stop(wl);
276 ieee80211_sched_scan_stopped(wl->hw);
277 }
Luciano Coelho6394c012011-05-10 14:28:27 +0300278 }
279
Eliad Peller4b730b62011-10-10 10:12:57 +0200280 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300281 wl12xx_event_soft_gemini_sense(wl,
282 mbox->soft_gemini_sense_info);
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300283
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300284 /*
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.
Teemu Paasikivi64e29e42010-03-26 12:53:26 +0200288 *
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.
291 *
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300292 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200293 if (vector & BSS_LOSE_EVENT_ID) {
294 /* TODO: check for multi-role */
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300295 wl1271_info("Beacon loss detected.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300296
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300297 /* indicate to the stack, that beacons have been lost */
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200298 beacon_loss = true;
299 }
300
Eliad Peller4b730b62011-10-10 10:12:57 +0200301 if (vector & PS_REPORT_EVENT_ID) {
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200302 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200303 wl12xx_for_each_wlvif_sta(wl, wlvif) {
304 ret = wl1271_event_ps_report(wl, wlvif,
305 mbox, &beacon_loss);
306 if (ret < 0)
307 return ret;
308 }
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200309 }
310
Eliad Peller4b730b62011-10-10 10:12:57 +0200311 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
312 wl12xx_for_each_wlvif_sta(wl, wlvif) {
313 wl1271_event_pspoll_delivery_fail(wl, wlvif);
314 }
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300315
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300316 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200317 /* TODO: check actual multi-role support */
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300318 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200319 wl12xx_for_each_wlvif_sta(wl, wlvif) {
320 wl1271_event_rssi_trigger(wl, wlvif, mbox);
321 }
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300322 }
323
Eliad Peller4b730b62011-10-10 10:12:57 +0200324 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
325 u8 role_id = mbox->role_id;
Shahar Levi70559a02011-05-22 16:10:22 +0300326 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
Eliad Peller4b730b62011-10-10 10:12:57 +0200327 "ba_allowed = 0x%x, role_id=%d",
328 mbox->rx_ba_allowed, role_id);
Shahar Levi70559a02011-05-22 16:10:22 +0300329
Eliad Peller4b730b62011-10-10 10:12:57 +0200330 wl12xx_for_each_wlvif(wl, wlvif) {
331 if (role_id != 0xff && role_id != wlvif->role_id)
332 continue;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300333
Eliad Peller4b730b62011-10-10 10:12:57 +0200334 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
335 if (!wlvif->ba_allowed)
336 wl1271_stop_ba_event(wl, wlvif);
337 }
Shahar Levi70559a02011-05-22 16:10:22 +0300338 }
339
Eliad Peller4b730b62011-10-10 10:12:57 +0200340 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
Shahar Levi6d158ff2011-09-08 13:01:33 +0300341 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
342 "status = 0x%x",
343 mbox->channel_switch_status);
344 /*
345 * That event uses for two cases:
346 * 1) channel switch complete with status=0
347 * 2) channel switch failed status=1
348 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200349
Eliad Peller52630c52011-10-10 10:13:08 +0200350 /* TODO: configure only the relevant vif */
351 wl12xx_for_each_wlvif_sta(wl, wlvif) {
352 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
353 bool success;
354
355 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
356 &wl->flags))
357 continue;
358
359 success = mbox->channel_switch_status ? false : true;
360 ieee80211_chswitch_done(vif, success);
Eliad Peller4b730b62011-10-10 10:12:57 +0200361 }
Shahar Levi6d158ff2011-09-08 13:01:33 +0300362 }
363
Arik Nemtsov79ebec72011-08-14 13:17:18 +0300364 if ((vector & DUMMY_PACKET_EVENT_ID)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200365 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
Eliad Peller4b730b62011-10-10 10:12:57 +0200366 wl1271_tx_dummy_packet(wl);
Shahar Leviae47c452011-03-06 16:32:14 +0200367 }
368
Arik Nemtsov3618f302011-06-26 10:36:03 +0300369 /*
370 * "TX retries exceeded" has a different meaning according to mode.
371 * In AP mode the offending station is disconnected.
372 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200373 if (vector & MAX_TX_RETRY_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300374 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
375 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
376 disconnect_sta = true;
377 }
378
Eliad Peller4b730b62011-10-10 10:12:57 +0200379 if (vector & INACTIVE_STA_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300380 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
381 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
382 disconnect_sta = true;
383 }
384
Eliad Peller4b730b62011-10-10 10:12:57 +0200385 if (disconnect_sta) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300386 u32 num_packets = wl->conf.tx.max_tx_retries;
387 struct ieee80211_sta *sta;
388 const u8 *addr;
389 int h;
390
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200391 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200392 bool found = false;
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))
396 continue;
397 found = true;
398 break;
399 }
400 if (!found)
Arik Nemtsov3618f302011-06-26 10:36:03 +0300401 continue;
402
Eliad Peller4b730b62011-10-10 10:12:57 +0200403 vif = wl12xx_wlvif_to_vif(wlvif);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300404 addr = wl->links[h].addr;
405
406 rcu_read_lock();
Eliad Peller4b730b62011-10-10 10:12:57 +0200407 sta = ieee80211_find_sta(vif, addr);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300408 if (sta) {
409 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
410 ieee80211_report_low_ack(sta, num_packets);
411 }
412 rcu_read_unlock();
413 }
414 }
415
Eliad Peller4b730b62011-10-10 10:12:57 +0200416 if (beacon_loss)
417 wl12xx_for_each_wlvif_sta(wl, wlvif) {
418 vif = wl12xx_wlvif_to_vif(wlvif);
419 ieee80211_connection_loss(vif);
420 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300421
422 return 0;
423}
424
425int wl1271_event_unmask(struct wl1271 *wl)
426{
427 int ret;
428
429 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
430 if (ret < 0)
431 return ret;
432
433 return 0;
434}
435
436void wl1271_event_mbox_config(struct wl1271 *wl)
437{
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200438 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300439 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
440
441 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
442 wl->mbox_ptr[0], wl->mbox_ptr[1]);
443}
444
Juuso Oikarinen13f2dc52009-12-11 15:40:59 +0200445int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300446{
447 struct event_mailbox mbox;
448 int ret;
449
450 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
451
452 if (mbox_num > 1)
453 return -EINVAL;
454
455 /* first we read the mbox descriptor */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200456 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
457 sizeof(struct event_mailbox), false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300458
459 /* process the descriptor */
460 ret = wl1271_event_process(wl, &mbox);
461 if (ret < 0)
462 return ret;
463
464 /* then we let the firmware know it can go on...*/
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200465 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300466
467 return 0;
468}