blob: 486c8ee0101abeb8c6f7bc06cc56f29d4245f504 [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 Peller04324d92011-10-05 11:56:03 +0200165 struct ieee80211_vif *vif,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300166 struct event_mailbox *mbox)
167{
Eliad Peller04324d92011-10-05 11:56:03 +0200168 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
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 Peller536129c82011-10-05 11:55:45 +0200186 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200187 if (!wlvif->sta.ba_rx_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300188 return;
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200189 ieee80211_stop_rx_ba_session(wl->vif, wlvif->sta.ba_rx_bitmap,
Eliad Pellercdf09492011-10-05 11:55:44 +0200190 wl->vif->bss_conf.bssid);
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300191 } else {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200192 u8 hlid;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300193 struct wl1271_link *lnk;
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200194 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
195 WL12XX_MAX_LINKS) {
196 lnk = &wl->links[hlid];
197 if (!lnk->ba_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300198 continue;
Shahar Levi70559a02011-05-22 16:10:22 +0300199
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300200 ieee80211_stop_rx_ba_session(wl->vif,
201 lnk->ba_bitmap,
202 lnk->addr);
203 }
204 }
Shahar Levi70559a02011-05-22 16:10:22 +0300205}
206
Eliad Peller77ddaa12011-05-15 11:10:29 +0300207static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
208 u8 enable)
209{
210 if (enable) {
211 /* disable dynamic PS when requested by the firmware */
212 ieee80211_disable_dyn_ps(wl->vif);
213 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
214 } else {
215 ieee80211_enable_dyn_ps(wl->vif);
216 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
217 wl1271_recalc_rx_streaming(wl);
218 }
219
220}
221
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300222static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
223{
224 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
225 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
226 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
227}
228
229static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
230{
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200231 struct ieee80211_vif *vif = wl->vif; /* TODO: get as param */
232 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300233 int ret;
234 u32 vector;
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200235 bool beacon_loss = false;
Eliad Peller536129c82011-10-05 11:55:45 +0200236 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300237 bool disconnect_sta = false;
238 unsigned long sta_bitmap = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300239
240 wl1271_event_mbox_dump(mbox);
241
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300242 vector = le32_to_cpu(mbox->events_vector);
243 vector &= ~(le32_to_cpu(mbox->events_mask));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300244 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
245
246 if (vector & SCAN_COMPLETE_EVENT_ID) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300247 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
248 mbox->scheduled_scan_status);
249
Eliad Peller784f6942011-10-05 11:55:39 +0200250 wl1271_scan_stm(wl, wl->scan_vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300251 }
252
Luciano Coelho6394c012011-05-10 14:28:27 +0300253 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
254 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
255 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300256
257 wl1271_scan_sched_scan_results(wl);
Luciano Coelho6394c012011-05-10 14:28:27 +0300258 }
259
260 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
261 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
262 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300263 if (wl->sched_scanning) {
264 wl1271_scan_sched_scan_stop(wl);
265 ieee80211_sched_scan_stopped(wl->hw);
266 }
Luciano Coelho6394c012011-05-10 14:28:27 +0300267 }
268
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300269 if (vector & SOFT_GEMINI_SENSE_EVENT_ID &&
Eliad Peller536129c82011-10-05 11:55:45 +0200270 wlvif->bss_type == BSS_TYPE_STA_BSS)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300271 wl12xx_event_soft_gemini_sense(wl,
272 mbox->soft_gemini_sense_info);
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300273
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300274 /*
275 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
276 * filtering) is enabled. Without PSM, the stack will receive all
277 * beacons and can detect beacon loss by itself.
Teemu Paasikivi64e29e442010-03-26 12:53:26 +0200278 *
279 * As there's possibility that the driver disables PSM before receiving
280 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
281 *
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300282 */
Arik Nemtsov203c9032010-10-25 11:17:44 +0200283 if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) {
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300284 wl1271_info("Beacon loss detected.");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300285
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300286 /* indicate to the stack, that beacons have been lost */
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200287 beacon_loss = true;
288 }
289
Arik Nemtsov203c9032010-10-25 11:17:44 +0200290 if ((vector & PS_REPORT_EVENT_ID) && !is_ap) {
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200291 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200292 ret = wl1271_event_ps_report(wl, wlvif, mbox, &beacon_loss);
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200293 if (ret < 0)
294 return ret;
295 }
296
Arik Nemtsov203c9032010-10-25 11:17:44 +0200297 if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap)
Eliad Pellerd2d66c52011-10-05 11:55:43 +0200298 wl1271_event_pspoll_delivery_fail(wl, wlvif);
Juuso Oikarinen90494a92010-07-08 17:50:00 +0300299
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300300 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
301 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
302 if (wl->vif)
Eliad Peller04324d92011-10-05 11:56:03 +0200303 wl1271_event_rssi_trigger(wl, vif, mbox);
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300304 }
305
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300306 if ((vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)) {
Shahar Levi70559a02011-05-22 16:10:22 +0300307 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
Eliad Pellerc690ec82011-08-14 13:17:07 +0300308 "ba_allowed = 0x%x", mbox->rx_ba_allowed);
Shahar Levi70559a02011-05-22 16:10:22 +0300309
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200310 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300311
Eliad Pellerd0802ab2011-10-05 11:56:04 +0200312 if (wl->vif && !wlvif->ba_allowed)
Eliad Peller536129c82011-10-05 11:55:45 +0200313 wl1271_stop_ba_event(wl, wlvif);
Shahar Levi70559a02011-05-22 16:10:22 +0300314 }
315
Shahar Levi6d158ff2011-09-08 13:01:33 +0300316 if ((vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) && !is_ap) {
317 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
318 "status = 0x%x",
319 mbox->channel_switch_status);
320 /*
321 * That event uses for two cases:
322 * 1) channel switch complete with status=0
323 * 2) channel switch failed status=1
324 */
325 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags) &&
326 (wl->vif))
327 ieee80211_chswitch_done(wl->vif,
328 mbox->channel_switch_status ? false : true);
329 }
330
Arik Nemtsov79ebec72011-08-14 13:17:18 +0300331 if ((vector & DUMMY_PACKET_EVENT_ID)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200332 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
333 if (wl->vif)
334 wl1271_tx_dummy_packet(wl);
335 }
336
Arik Nemtsov3618f302011-06-26 10:36:03 +0300337 /*
338 * "TX retries exceeded" has a different meaning according to mode.
339 * In AP mode the offending station is disconnected.
340 */
341 if ((vector & MAX_TX_RETRY_EVENT_ID) && is_ap) {
342 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
343 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
344 disconnect_sta = true;
345 }
346
347 if ((vector & INACTIVE_STA_EVENT_ID) && is_ap) {
348 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
349 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
350 disconnect_sta = true;
351 }
352
353 if (is_ap && disconnect_sta) {
354 u32 num_packets = wl->conf.tx.max_tx_retries;
355 struct ieee80211_sta *sta;
356 const u8 *addr;
357 int h;
358
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200359 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
360 if (!test_bit(h, wlvif->ap.sta_hlid_map))
Arik Nemtsov3618f302011-06-26 10:36:03 +0300361 continue;
362
363 addr = wl->links[h].addr;
364
365 rcu_read_lock();
366 sta = ieee80211_find_sta(wl->vif, addr);
367 if (sta) {
368 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
369 ieee80211_report_low_ack(sta, num_packets);
370 }
371 rcu_read_unlock();
372 }
373 }
374
Juuso Oikarinend60772f2010-03-26 12:53:29 +0200375 if (wl->vif && beacon_loss)
376 ieee80211_connection_loss(wl->vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300377
378 return 0;
379}
380
381int wl1271_event_unmask(struct wl1271 *wl)
382{
383 int ret;
384
385 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
386 if (ret < 0)
387 return ret;
388
389 return 0;
390}
391
392void wl1271_event_mbox_config(struct wl1271 *wl)
393{
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200394 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300395 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
396
397 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
398 wl->mbox_ptr[0], wl->mbox_ptr[1]);
399}
400
Juuso Oikarinen13f2dc52009-12-11 15:40:59 +0200401int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300402{
403 struct event_mailbox mbox;
404 int ret;
405
406 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
407
408 if (mbox_num > 1)
409 return -EINVAL;
410
411 /* first we read the mbox descriptor */
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200412 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
413 sizeof(struct event_mailbox), false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300414
415 /* process the descriptor */
416 ret = wl1271_event_process(wl, &mbox);
417 if (ret < 0)
418 return ret;
419
420 /* then we let the firmware know it can go on...*/
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200421 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300422
423 return 0;
424}