blob: be9e1121c8f883b8a927f9822bf383d38c6111c3 [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"
25#include "reg.h"
26#include "io.h"
27#include "event.h"
28#include "ps.h"
29#include "scan.h"
Juuso Oikarinen66497dc2009-10-08 21:56:30 +030030#include "wl12xx_80211.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030031
Juuso Oikarinen90494a92010-07-08 17:50:00 +030032void wl1271_pspoll_work(struct work_struct *work)
33{
Eliad Pellerd2d66c52011-10-05 11:55:43 +020034 struct ieee80211_vif *vif;
35 struct wl12xx_vif *wlvif;
Juuso Oikarinen90494a92010-07-08 17:50:00 +030036 struct delayed_work *dwork;
37 struct wl1271 *wl;
Eliad Pellerc1b193e2011-03-23 22:22:15 +020038 int ret;
Juuso Oikarinen90494a92010-07-08 17:50:00 +030039
40 dwork = container_of(work, struct delayed_work, work);
Eliad Peller252efa42011-10-05 11:56:00 +020041 wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work);
42 vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
43 wl = wlvif->wl;
Juuso Oikarinen90494a92010-07-08 17:50:00 +030044
45 wl1271_debug(DEBUG_EVENT, "pspoll work");
46
47 mutex_lock(&wl->mutex);
48
Juuso Oikarinen8c7f4f32010-09-21 06:23:29 +020049 if (unlikely(wl->state == WL1271_STATE_OFF))
50 goto out;
51
Juuso Oikarinen90494a92010-07-08 17:50:00 +030052 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags))
53 goto out;
54
55 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->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 */
Eliad Pellerc1b193e2011-03-23 22:22:15 +020063 ret = wl1271_ps_elp_wakeup(wl);
64 if (ret < 0)
65 goto out;
66
Eliad Peller0603d892011-10-05 11:55:51 +020067 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
68 wlvif->basic_rate, true);
Juuso Oikarinen90494a92010-07-08 17:50:00 +030069
Eliad Pellerc1b193e2011-03-23 22:22:15 +020070 wl1271_ps_elp_sleep(wl);
Juuso Oikarinen90494a92010-07-08 17:50:00 +030071out:
72 mutex_unlock(&wl->mutex);
73};
74
Eliad Pellerd2d66c52011-10-05 11:55:43 +020075static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl,
76 struct wl12xx_vif *wlvif)
Juuso Oikarinen90494a92010-07-08 17:50:00 +030077{
78 int delay = wl->conf.conn.ps_poll_recovery_period;
79 int ret;
80
Eliad Peller74ec8392011-10-05 11:56:02 +020081 wlvif->ps_poll_failures++;
82 if (wlvif->ps_poll_failures == 1)
Juuso Oikarinen90494a92010-07-08 17:50:00 +030083 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(WL1271_FLAG_PSM, &wl->flags)) {
Eliad Peller0603d892011-10-05 11:55:51 +020088 ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +020089 wlvif->basic_rate, true);
Juuso Oikarinen90494a92010-07-08 17:50:00 +030090 if (ret < 0)
91 return;
92 set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
Eliad Peller252efa42011-10-05 11:56:00 +020093 ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work,
Juuso Oikarinen90494a92010-07-08 17:50:00 +030094 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
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200105static int wl1271_event_ps_report(struct wl1271 *wl,
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200106 struct wl12xx_vif *wlvif,
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200107 struct event_mailbox *mbox,
108 bool *beacon_loss)
109{
110 int ret = 0;
Juuso Oikarinen65cddbf2010-08-24 06:28:03 +0300111 u32 total_retries = wl->conf.conn.psm_entry_retries;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200112
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:
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200117 wl1271_debug(DEBUG_PSM, "PSM entry failed");
118
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200119 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200120 /* remain in active mode */
Eliad Peller74ec8392011-10-05 11:56:02 +0200121 wlvif->psm_entry_retry = 0;
Juuso Oikarinen461fa132009-11-23 23:22:13 +0200122 break;
123 }
124
Eliad Peller74ec8392011-10-05 11:56:02 +0200125 if (wlvif->psm_entry_retry < total_retries) {
126 wlvif->psm_entry_retry++;
Eliad Peller0603d892011-10-05 11:55:51 +0200127 ret = wl1271_ps_set_mode(wl, wlvif,
128 STATION_POWER_SAVE_MODE,
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200129 wlvif->basic_rate, true);
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200130 } else {
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300131 wl1271_info("No ack to nullfunc from AP.");
Eliad Peller74ec8392011-10-05 11:56:02 +0200132 wlvif->psm_entry_retry = 0;
Juuso Oikarinend60772f2010-03-26 12:53:29 +0200133 *beacon_loss = true;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200134 }
135 break;
136 case EVENT_ENTER_POWER_SAVE_SUCCESS:
Eliad Peller74ec8392011-10-05 11:56:02 +0200137 wlvif->psm_entry_retry = 0;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200138
139 /* enable beacon filtering */
Eliad Peller0603d892011-10-05 11:55:51 +0200140 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200141 if (ret < 0)
142 break;
143
Shahar Levi0e44eb22011-05-16 15:35:30 +0300144 /*
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 */
Eliad Peller0603d892011-10-05 11:55:51 +0200150 ret = wl1271_acx_bet_enable(wl, wlvif, true);
Eliad Peller94390642011-05-13 11:57:13 +0300151
Eliad Peller6ec45dc2011-10-05 11:56:01 +0200152 if (wlvif->ps_compl) {
153 complete(wlvif->ps_compl);
154 wlvif->ps_compl = NULL;
Eliad Peller94390642011-05-13 11:57:13 +0300155 }
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200156 break;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200157 default:
158 break;
159 }
160
161 return ret;
162}
163
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300164static void wl1271_event_rssi_trigger(struct wl1271 *wl,
Eliad Peller4b730b62011-10-10 10:12:57 +0200165 struct wl12xx_vif *wlvif,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300166 struct event_mailbox *mbox)
167{
Eliad Peller4b730b62011-10-10 10:12:57 +0200168 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300169 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
Eliad Peller04324d92011-10-05 11:56:03 +0200174 if (metric <= wlvif->rssi_thold)
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300175 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
176 else
177 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
178
Eliad Peller04324d92011-10-05 11:56:03 +0200179 if (event != wlvif->last_rssi_event)
180 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
181 wlvif->last_rssi_event = event;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300182}
183
Eliad Peller536129c82011-10-05 11:55:45 +0200184static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Shahar Levi70559a02011-05-22 16:10:22 +0300185{
Eliad Peller4b730b62011-10-10 10:12:57 +0200186 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
187
Eliad Peller536129c82011-10-05 11:55:45 +0200188 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200189 if (!wlvif->sta.ba_rx_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300190 return;
Eliad Peller4b730b62011-10-10 10:12:57 +0200191 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
192 vif->bss_conf.bssid);
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300193 } else {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200194 u8 hlid;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300195 struct wl1271_link *lnk;
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200196 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
197 WL12XX_MAX_LINKS) {
198 lnk = &wl->links[hlid];
199 if (!lnk->ba_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300200 continue;
Shahar Levi70559a02011-05-22 16:10:22 +0300201
Eliad Peller4b730b62011-10-10 10:12:57 +0200202 ieee80211_stop_rx_ba_session(vif,
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300203 lnk->ba_bitmap,
204 lnk->addr);
205 }
206 }
Shahar Levi70559a02011-05-22 16:10:22 +0300207}
208
Eliad Peller77ddaa12011-05-15 11:10:29 +0300209static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
210 u8 enable)
211{
Eliad Peller4b730b62011-10-10 10:12:57 +0200212 struct ieee80211_vif *vif;
213 struct wl12xx_vif *wlvif;
214
Eliad Peller77ddaa12011-05-15 11:10:29 +0300215 if (enable) {
216 /* disable dynamic PS when requested by the firmware */
Eliad Peller4b730b62011-10-10 10:12:57 +0200217 wl12xx_for_each_wlvif_sta(wl, wlvif) {
218 vif = wl12xx_wlvif_to_vif(wlvif);
219 ieee80211_disable_dyn_ps(vif);
220 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300221 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
222 } else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200223 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
Eliad Peller4b730b62011-10-10 10:12:57 +0200224 wl12xx_for_each_wlvif_sta(wl, wlvif) {
225 vif = wl12xx_wlvif_to_vif(wlvif);
226 ieee80211_enable_dyn_ps(vif);
Eliad Peller9eb599e2011-10-10 10:12:59 +0200227 wl1271_recalc_rx_streaming(wl, wlvif);
Eliad Peller4b730b62011-10-10 10:12:57 +0200228 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300229 }
230
231}
232
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300233static 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
240static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
241{
Eliad Peller4b730b62011-10-10 10:12:57 +0200242 struct ieee80211_vif *vif;
243 struct wl12xx_vif *wlvif;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300244 int ret;
245 u32 vector;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200246 bool beacon_loss = false;
Arik Nemtsov3618f302011-06-26 10:36:03 +0300247 bool disconnect_sta = false;
248 unsigned long sta_bitmap = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300249
250 wl1271_event_mbox_dump(mbox);
251
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300252 vector = le32_to_cpu(mbox->events_vector);
253 vector &= ~(le32_to_cpu(mbox->events_mask));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300254 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
255
256 if (vector & SCAN_COMPLETE_EVENT_ID) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300257 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
258 mbox->scheduled_scan_status);
259
Eliad Peller784f6942011-10-05 11:55:39 +0200260 wl1271_scan_stm(wl, wl->scan_vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300261 }
262
Luciano Coelho6394c012011-05-10 14:28:27 +0300263 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
264 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
265 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300266
267 wl1271_scan_sched_scan_results(wl);
Luciano Coelho6394c012011-05-10 14:28:27 +0300268 }
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);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300273 if (wl->sched_scanning) {
274 wl1271_scan_sched_scan_stop(wl);
275 ieee80211_sched_scan_stopped(wl->hw);
276 }
Luciano Coelho6394c012011-05-10 14:28:27 +0300277 }
278
Eliad Peller4b730b62011-10-10 10:12:57 +0200279 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300280 wl12xx_event_soft_gemini_sense(wl,
281 mbox->soft_gemini_sense_info);
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300282
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300283 /*
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.
Teemu Paasikivi64e29e442010-03-26 12:53:26 +0200287 *
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 *
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300291 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200292 if (vector & BSS_LOSE_EVENT_ID) {
293 /* TODO: check for multi-role */
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300294 wl1271_info("Beacon loss detected.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300295
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300296 /* indicate to the stack, that beacons have been lost */
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200297 beacon_loss = true;
298 }
299
Eliad Peller4b730b62011-10-10 10:12:57 +0200300 if (vector & PS_REPORT_EVENT_ID) {
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200301 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200302 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 }
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200308 }
309
Eliad Peller4b730b62011-10-10 10:12:57 +0200310 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
311 wl12xx_for_each_wlvif_sta(wl, wlvif) {
312 wl1271_event_pspoll_delivery_fail(wl, wlvif);
313 }
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300314
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300315 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200316 /* TODO: check actual multi-role support */
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300317 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200318 wl12xx_for_each_wlvif_sta(wl, wlvif) {
319 wl1271_event_rssi_trigger(wl, wlvif, mbox);
320 }
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300321 }
322
Eliad Peller4b730b62011-10-10 10:12:57 +0200323 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
324 u8 role_id = mbox->role_id;
Shahar Levi70559a02011-05-22 16:10:22 +0300325 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
Eliad Peller4b730b62011-10-10 10:12:57 +0200326 "ba_allowed = 0x%x, role_id=%d",
327 mbox->rx_ba_allowed, role_id);
Shahar Levi70559a02011-05-22 16:10:22 +0300328
Eliad Peller4b730b62011-10-10 10:12:57 +0200329 wl12xx_for_each_wlvif(wl, wlvif) {
330 if (role_id != 0xff && role_id != wlvif->role_id)
331 continue;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300332
Eliad Peller4b730b62011-10-10 10:12:57 +0200333 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
334 if (!wlvif->ba_allowed)
335 wl1271_stop_ba_event(wl, wlvif);
336 }
Shahar Levi70559a02011-05-22 16:10:22 +0300337 }
338
Eliad Peller4b730b62011-10-10 10:12:57 +0200339 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
Shahar Levi6d158ff2011-09-08 13:01:33 +0300340 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 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200348 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags)) {
349 /* TODO: configure only the relevant vif */
350 wl12xx_for_each_wlvif_sta(wl, wlvif) {
351 struct ieee80211_vif *vif =
352 wl12xx_wlvif_to_vif(wlvif);
353 bool success = mbox->channel_switch_status ?
354 false : true;
355
356 ieee80211_chswitch_done(vif, success);
357 }
358 }
Shahar Levi6d158ff2011-09-08 13:01:33 +0300359 }
360
Arik Nemtsov79ebec72011-08-14 13:17:18 +0300361 if ((vector & DUMMY_PACKET_EVENT_ID)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200362 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
Eliad Peller4b730b62011-10-10 10:12:57 +0200363 wl1271_tx_dummy_packet(wl);
Shahar Leviae47c452011-03-06 16:32:14 +0200364 }
365
Arik Nemtsov3618f302011-06-26 10:36:03 +0300366 /*
367 * "TX retries exceeded" has a different meaning according to mode.
368 * In AP mode the offending station is disconnected.
369 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200370 if (vector & MAX_TX_RETRY_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300371 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
372 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
373 disconnect_sta = true;
374 }
375
Eliad Peller4b730b62011-10-10 10:12:57 +0200376 if (vector & INACTIVE_STA_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300377 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
378 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
379 disconnect_sta = true;
380 }
381
Eliad Peller4b730b62011-10-10 10:12:57 +0200382 if (disconnect_sta) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300383 u32 num_packets = wl->conf.tx.max_tx_retries;
384 struct ieee80211_sta *sta;
385 const u8 *addr;
386 int h;
387
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200388 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200389 bool found = false;
390 /* find the ap vif connected to this sta */
391 wl12xx_for_each_wlvif_ap(wl, wlvif) {
392 if (!test_bit(h, wlvif->ap.sta_hlid_map))
393 continue;
394 found = true;
395 break;
396 }
397 if (!found)
Arik Nemtsov3618f302011-06-26 10:36:03 +0300398 continue;
399
Eliad Peller4b730b62011-10-10 10:12:57 +0200400 vif = wl12xx_wlvif_to_vif(wlvif);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300401 addr = wl->links[h].addr;
402
403 rcu_read_lock();
Eliad Peller4b730b62011-10-10 10:12:57 +0200404 sta = ieee80211_find_sta(vif, addr);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300405 if (sta) {
406 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
407 ieee80211_report_low_ack(sta, num_packets);
408 }
409 rcu_read_unlock();
410 }
411 }
412
Eliad Peller4b730b62011-10-10 10:12:57 +0200413 if (beacon_loss)
414 wl12xx_for_each_wlvif_sta(wl, wlvif) {
415 vif = wl12xx_wlvif_to_vif(wlvif);
416 ieee80211_connection_loss(vif);
417 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300418
419 return 0;
420}
421
422int wl1271_event_unmask(struct wl1271 *wl)
423{
424 int ret;
425
426 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
427 if (ret < 0)
428 return ret;
429
430 return 0;
431}
432
433void wl1271_event_mbox_config(struct wl1271 *wl)
434{
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200435 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300436 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
437
438 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
439 wl->mbox_ptr[0], wl->mbox_ptr[1]);
440}
441
Juuso Oikarinen13f2dc52009-12-11 15:40:59 +0200442int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300443{
444 struct event_mailbox mbox;
445 int ret;
446
447 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
448
449 if (mbox_num > 1)
450 return -EINVAL;
451
452 /* first we read the mbox descriptor */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200453 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
454 sizeof(struct event_mailbox), false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300455
456 /* process the descriptor */
457 ret = wl1271_event_process(wl, &mbox);
458 if (ret < 0)
459 return ret;
460
461 /* then we let the firmware know it can go on...*/
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200462 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300463
464 return 0;
465}