blob: cfc38ea21e4a5489aa6196ec5b44ff53e5bb9ed4 [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
Shahar Levi0e44eb22011-05-16 15:35:30 +0300140 /*
141 * BET has only a minor effect in 5GHz and masks
142 * channel switch IEs, so we only enable BET on 2.4GHz
143 */
Eliad Peller1b92f152011-10-10 10:13:09 +0200144 if (wlvif->band == IEEE80211_BAND_2GHZ)
Shahar Levi0e44eb22011-05-16 15:35:30 +0300145 /* enable beacon early termination */
Eliad Peller0603d892011-10-05 11:55:51 +0200146 ret = wl1271_acx_bet_enable(wl, wlvif, true);
Eliad Peller94390642011-05-13 11:57:13 +0300147
Eliad Peller6ec45dc2011-10-05 11:56:01 +0200148 if (wlvif->ps_compl) {
149 complete(wlvif->ps_compl);
150 wlvif->ps_compl = NULL;
Eliad Peller94390642011-05-13 11:57:13 +0300151 }
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200152 break;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200153 default:
154 break;
155 }
156
157 return ret;
158}
159
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300160static void wl1271_event_rssi_trigger(struct wl1271 *wl,
Eliad Peller4b730b62011-10-10 10:12:57 +0200161 struct wl12xx_vif *wlvif,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300162 struct event_mailbox *mbox)
163{
Eliad Peller4b730b62011-10-10 10:12:57 +0200164 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300165 enum nl80211_cqm_rssi_threshold_event event;
166 s8 metric = mbox->rssi_snr_trigger_metric[0];
167
168 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
169
Eliad Peller04324d92011-10-05 11:56:03 +0200170 if (metric <= wlvif->rssi_thold)
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300171 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
172 else
173 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
174
Eliad Peller04324d92011-10-05 11:56:03 +0200175 if (event != wlvif->last_rssi_event)
176 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
177 wlvif->last_rssi_event = event;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300178}
179
Eliad Peller536129c2011-10-05 11:55:45 +0200180static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Shahar Levi70559a02011-05-22 16:10:22 +0300181{
Eliad Peller4b730b62011-10-10 10:12:57 +0200182 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
183
Eliad Peller536129c2011-10-05 11:55:45 +0200184 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200185 if (!wlvif->sta.ba_rx_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300186 return;
Eliad Peller4b730b62011-10-10 10:12:57 +0200187 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
188 vif->bss_conf.bssid);
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300189 } else {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200190 u8 hlid;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300191 struct wl1271_link *lnk;
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200192 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
193 WL12XX_MAX_LINKS) {
194 lnk = &wl->links[hlid];
195 if (!lnk->ba_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300196 continue;
Shahar Levi70559a02011-05-22 16:10:22 +0300197
Eliad Peller4b730b62011-10-10 10:12:57 +0200198 ieee80211_stop_rx_ba_session(vif,
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300199 lnk->ba_bitmap,
200 lnk->addr);
201 }
202 }
Shahar Levi70559a02011-05-22 16:10:22 +0300203}
204
Eliad Peller77ddaa12011-05-15 11:10:29 +0300205static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
206 u8 enable)
207{
Eliad Peller4b730b62011-10-10 10:12:57 +0200208 struct ieee80211_vif *vif;
209 struct wl12xx_vif *wlvif;
210
Eliad Peller77ddaa12011-05-15 11:10:29 +0300211 if (enable) {
212 /* disable dynamic PS when requested by the firmware */
Eliad Peller4b730b62011-10-10 10:12:57 +0200213 wl12xx_for_each_wlvif_sta(wl, wlvif) {
214 vif = wl12xx_wlvif_to_vif(wlvif);
215 ieee80211_disable_dyn_ps(vif);
216 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300217 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
218 } else {
Eliad Peller9eb599e2011-10-10 10:12:59 +0200219 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
Eliad Peller4b730b62011-10-10 10:12:57 +0200220 wl12xx_for_each_wlvif_sta(wl, wlvif) {
221 vif = wl12xx_wlvif_to_vif(wlvif);
222 ieee80211_enable_dyn_ps(vif);
Eliad Peller9eb599e2011-10-10 10:12:59 +0200223 wl1271_recalc_rx_streaming(wl, wlvif);
Eliad Peller4b730b62011-10-10 10:12:57 +0200224 }
Eliad Peller77ddaa12011-05-15 11:10:29 +0300225 }
226
227}
228
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300229static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
230{
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);
234}
235
236static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
237{
Eliad Peller4b730b62011-10-10 10:12:57 +0200238 struct ieee80211_vif *vif;
239 struct wl12xx_vif *wlvif;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300240 int ret;
241 u32 vector;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200242 bool beacon_loss = false;
Arik Nemtsov3618f302011-06-26 10:36:03 +0300243 bool disconnect_sta = false;
244 unsigned long sta_bitmap = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300245
246 wl1271_event_mbox_dump(mbox);
247
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300248 vector = le32_to_cpu(mbox->events_vector);
249 vector &= ~(le32_to_cpu(mbox->events_mask));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300250 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
251
252 if (vector & SCAN_COMPLETE_EVENT_ID) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300253 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
254 mbox->scheduled_scan_status);
255
Eliad Peller784f6942011-10-05 11:55:39 +0200256 wl1271_scan_stm(wl, wl->scan_vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300257 }
258
Luciano Coelho6394c012011-05-10 14:28:27 +0300259 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
260 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
261 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300262
263 wl1271_scan_sched_scan_results(wl);
Luciano Coelho6394c012011-05-10 14:28:27 +0300264 }
265
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);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300269 if (wl->sched_scanning) {
Luciano Coelho33c2c062011-05-10 14:46:02 +0300270 ieee80211_sched_scan_stopped(wl->hw);
Eyal Shapiraee91d182011-12-20 14:55:38 +0200271 wl->sched_scanning = false;
Luciano Coelho33c2c062011-05-10 14:46:02 +0300272 }
Luciano Coelho6394c012011-05-10 14:28:27 +0300273 }
274
Eliad Peller4b730b62011-10-10 10:12:57 +0200275 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300276 wl12xx_event_soft_gemini_sense(wl,
277 mbox->soft_gemini_sense_info);
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300278
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300279 /*
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.
Teemu Paasikivi64e29e42010-03-26 12:53:26 +0200283 *
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.
286 *
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300287 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200288 if (vector & BSS_LOSE_EVENT_ID) {
289 /* TODO: check for multi-role */
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300290 wl1271_info("Beacon loss detected.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300291
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300292 /* indicate to the stack, that beacons have been lost */
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200293 beacon_loss = true;
294 }
295
Eliad Peller4b730b62011-10-10 10:12:57 +0200296 if (vector & PS_REPORT_EVENT_ID) {
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200297 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200298 wl12xx_for_each_wlvif_sta(wl, wlvif) {
299 ret = wl1271_event_ps_report(wl, wlvif,
300 mbox, &beacon_loss);
301 if (ret < 0)
302 return ret;
303 }
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200304 }
305
Eliad Peller4b730b62011-10-10 10:12:57 +0200306 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
307 wl12xx_for_each_wlvif_sta(wl, wlvif) {
308 wl1271_event_pspoll_delivery_fail(wl, wlvif);
309 }
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300310
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300311 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200312 /* TODO: check actual multi-role support */
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300313 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200314 wl12xx_for_each_wlvif_sta(wl, wlvif) {
315 wl1271_event_rssi_trigger(wl, wlvif, mbox);
316 }
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300317 }
318
Eliad Peller4b730b62011-10-10 10:12:57 +0200319 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
320 u8 role_id = mbox->role_id;
Shahar Levi70559a02011-05-22 16:10:22 +0300321 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
Eliad Peller4b730b62011-10-10 10:12:57 +0200322 "ba_allowed = 0x%x, role_id=%d",
323 mbox->rx_ba_allowed, role_id);
Shahar Levi70559a02011-05-22 16:10:22 +0300324
Eliad Peller4b730b62011-10-10 10:12:57 +0200325 wl12xx_for_each_wlvif(wl, wlvif) {
326 if (role_id != 0xff && role_id != wlvif->role_id)
327 continue;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300328
Eliad Peller4b730b62011-10-10 10:12:57 +0200329 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
330 if (!wlvif->ba_allowed)
331 wl1271_stop_ba_event(wl, wlvif);
332 }
Shahar Levi70559a02011-05-22 16:10:22 +0300333 }
334
Eliad Peller4b730b62011-10-10 10:12:57 +0200335 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
Shahar Levi6d158ff2011-09-08 13:01:33 +0300336 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
337 "status = 0x%x",
338 mbox->channel_switch_status);
339 /*
340 * That event uses for two cases:
341 * 1) channel switch complete with status=0
342 * 2) channel switch failed status=1
343 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200344
Eliad Peller52630c52011-10-10 10:13:08 +0200345 /* TODO: configure only the relevant vif */
346 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller52630c52011-10-10 10:13:08 +0200347 bool success;
348
349 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
350 &wl->flags))
351 continue;
352
353 success = mbox->channel_switch_status ? false : true;
Luciano Coelho775e1a42012-01-24 11:46:32 +0200354 vif = wl12xx_wlvif_to_vif(wlvif);
355
Eliad Peller52630c52011-10-10 10:13:08 +0200356 ieee80211_chswitch_done(vif, success);
Eliad Peller4b730b62011-10-10 10:12:57 +0200357 }
Shahar Levi6d158ff2011-09-08 13:01:33 +0300358 }
359
Arik Nemtsov79ebec72011-08-14 13:17:18 +0300360 if ((vector & DUMMY_PACKET_EVENT_ID)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200361 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
Eliad Peller4b730b62011-10-10 10:12:57 +0200362 wl1271_tx_dummy_packet(wl);
Shahar Leviae47c452011-03-06 16:32:14 +0200363 }
364
Arik Nemtsov3618f302011-06-26 10:36:03 +0300365 /*
366 * "TX retries exceeded" has a different meaning according to mode.
367 * In AP mode the offending station is disconnected.
368 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200369 if (vector & MAX_TX_RETRY_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300370 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
371 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
372 disconnect_sta = true;
373 }
374
Eliad Peller4b730b62011-10-10 10:12:57 +0200375 if (vector & INACTIVE_STA_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300376 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
377 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
378 disconnect_sta = true;
379 }
380
Eliad Peller4b730b62011-10-10 10:12:57 +0200381 if (disconnect_sta) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300382 u32 num_packets = wl->conf.tx.max_tx_retries;
383 struct ieee80211_sta *sta;
384 const u8 *addr;
385 int h;
386
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200387 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200388 bool found = false;
389 /* find the ap vif connected to this sta */
390 wl12xx_for_each_wlvif_ap(wl, wlvif) {
391 if (!test_bit(h, wlvif->ap.sta_hlid_map))
392 continue;
393 found = true;
394 break;
395 }
396 if (!found)
Arik Nemtsov3618f302011-06-26 10:36:03 +0300397 continue;
398
Eliad Peller4b730b62011-10-10 10:12:57 +0200399 vif = wl12xx_wlvif_to_vif(wlvif);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300400 addr = wl->links[h].addr;
401
402 rcu_read_lock();
Eliad Peller4b730b62011-10-10 10:12:57 +0200403 sta = ieee80211_find_sta(vif, addr);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300404 if (sta) {
405 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
406 ieee80211_report_low_ack(sta, num_packets);
407 }
408 rcu_read_unlock();
409 }
410 }
411
Eliad Peller4b730b62011-10-10 10:12:57 +0200412 if (beacon_loss)
413 wl12xx_for_each_wlvif_sta(wl, wlvif) {
414 vif = wl12xx_wlvif_to_vif(wlvif);
415 ieee80211_connection_loss(vif);
416 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300417
418 return 0;
419}
420
421int wl1271_event_unmask(struct wl1271 *wl)
422{
423 int ret;
424
425 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
426 if (ret < 0)
427 return ret;
428
429 return 0;
430}
431
432void wl1271_event_mbox_config(struct wl1271 *wl)
433{
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200434 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300435 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
436
437 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
438 wl->mbox_ptr[0], wl->mbox_ptr[1]);
439}
440
Juuso Oikarinen13f2dc52009-12-11 15:40:59 +0200441int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300442{
443 struct event_mailbox mbox;
444 int ret;
445
446 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
447
448 if (mbox_num > 1)
449 return -EINVAL;
450
451 /* first we read the mbox descriptor */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200452 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
453 sizeof(struct event_mailbox), false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300454
455 /* process the descriptor */
456 ret = wl1271_event_process(wl, &mbox);
457 if (ret < 0)
458 return ret;
459
460 /* then we let the firmware know it can go on...*/
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200461 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300462
463 return 0;
464}