blob: c976f04098655b08ad4812ddcbeadc6be0de79e6 [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
Luciano Coelhoc31be252011-11-21 19:25:24 +020024#include "wlcore.h"
Luciano Coelho0f4e3122011-10-07 11:02:42 +030025#include "debug.h"
Shahar Levi00d20102010-11-08 11:20:10 +000026#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 Oikarinen00236aed2010-04-09 11:07:30 +030032static void wl1271_event_rssi_trigger(struct wl1271 *wl,
Eliad Peller4b730b62011-10-10 10:12:57 +020033 struct wl12xx_vif *wlvif,
Juuso Oikarinen00236aed2010-04-09 11:07:30 +030034 struct event_mailbox *mbox)
35{
Eliad Peller4b730b62011-10-10 10:12:57 +020036 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Juuso Oikarinen00236aed2010-04-09 11:07:30 +030037 enum nl80211_cqm_rssi_threshold_event event;
38 s8 metric = mbox->rssi_snr_trigger_metric[0];
39
40 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
41
Eliad Peller04324d92011-10-05 11:56:03 +020042 if (metric <= wlvif->rssi_thold)
Juuso Oikarinen00236aed2010-04-09 11:07:30 +030043 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
44 else
45 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
46
Eliad Peller04324d92011-10-05 11:56:03 +020047 if (event != wlvif->last_rssi_event)
48 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
49 wlvif->last_rssi_event = event;
Juuso Oikarinen00236aed2010-04-09 11:07:30 +030050}
51
Eliad Peller536129c2011-10-05 11:55:45 +020052static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Shahar Levi70559a02011-05-22 16:10:22 +030053{
Eliad Peller4b730b62011-10-10 10:12:57 +020054 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
55
Eliad Peller536129c2011-10-05 11:55:45 +020056 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
Eliad Pellerd0802ab2011-10-05 11:56:04 +020057 if (!wlvif->sta.ba_rx_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +030058 return;
Eliad Peller4b730b62011-10-10 10:12:57 +020059 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
60 vif->bss_conf.bssid);
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +030061 } else {
Eliad Pellerc7ffb902011-10-05 11:56:05 +020062 u8 hlid;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +030063 struct wl1271_link *lnk;
Eliad Pellerc7ffb902011-10-05 11:56:05 +020064 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
65 WL12XX_MAX_LINKS) {
66 lnk = &wl->links[hlid];
67 if (!lnk->ba_bitmap)
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +030068 continue;
Shahar Levi70559a02011-05-22 16:10:22 +030069
Eliad Peller4b730b62011-10-10 10:12:57 +020070 ieee80211_stop_rx_ba_session(vif,
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +030071 lnk->ba_bitmap,
72 lnk->addr);
73 }
74 }
Shahar Levi70559a02011-05-22 16:10:22 +030075}
76
Eliad Peller77ddaa12011-05-15 11:10:29 +030077static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
78 u8 enable)
79{
Eliad Peller4b730b62011-10-10 10:12:57 +020080 struct wl12xx_vif *wlvif;
81
Eliad Peller77ddaa12011-05-15 11:10:29 +030082 if (enable) {
Eliad Peller77ddaa12011-05-15 11:10:29 +030083 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
84 } else {
Eliad Peller9eb599e2011-10-10 10:12:59 +020085 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
Eliad Peller4b730b62011-10-10 10:12:57 +020086 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller9eb599e2011-10-10 10:12:59 +020087 wl1271_recalc_rx_streaming(wl, wlvif);
Eliad Peller4b730b62011-10-10 10:12:57 +020088 }
Eliad Peller77ddaa12011-05-15 11:10:29 +030089 }
90
91}
92
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030093static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
94{
95 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
96 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
97 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
98}
99
Mircea Gherzan690142e2012-03-17 18:41:53 +0100100static int wl1271_event_process(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300101{
Mircea Gherzan690142e2012-03-17 18:41:53 +0100102 struct event_mailbox *mbox = wl->mbox;
Eliad Peller4b730b62011-10-10 10:12:57 +0200103 struct ieee80211_vif *vif;
104 struct wl12xx_vif *wlvif;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300105 u32 vector;
Arik Nemtsov3618f302011-06-26 10:36:03 +0300106 bool disconnect_sta = false;
107 unsigned long sta_bitmap = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300108
109 wl1271_event_mbox_dump(mbox);
110
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300111 vector = le32_to_cpu(mbox->events_vector);
112 vector &= ~(le32_to_cpu(mbox->events_mask));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300113 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
114
115 if (vector & SCAN_COMPLETE_EVENT_ID) {
Luciano Coelho34dd2aa2010-07-08 17:50:06 +0300116 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
117 mbox->scheduled_scan_status);
118
Eliad Peller784f6942011-10-05 11:55:39 +0200119 wl1271_scan_stm(wl, wl->scan_vif);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300120 }
121
Luciano Coelho6394c012011-05-10 14:28:27 +0300122 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
123 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
124 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300125
126 wl1271_scan_sched_scan_results(wl);
Luciano Coelho6394c012011-05-10 14:28:27 +0300127 }
128
129 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
130 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
131 "(status 0x%0x)", mbox->scheduled_scan_status);
Luciano Coelho33c2c062011-05-10 14:46:02 +0300132 if (wl->sched_scanning) {
Luciano Coelho33c2c062011-05-10 14:46:02 +0300133 ieee80211_sched_scan_stopped(wl->hw);
Eyal Shapiraee91d182011-12-20 14:55:38 +0200134 wl->sched_scanning = false;
Luciano Coelho33c2c062011-05-10 14:46:02 +0300135 }
Luciano Coelho6394c012011-05-10 14:28:27 +0300136 }
137
Eliad Peller4b730b62011-10-10 10:12:57 +0200138 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
Eliad Peller77ddaa12011-05-15 11:10:29 +0300139 wl12xx_event_soft_gemini_sense(wl,
140 mbox->soft_gemini_sense_info);
Juuso Oikarinen8d2ef7b2010-07-08 17:50:03 +0300141
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300142 /*
Bartosz.Markowski@tieto.com5f561f62012-04-26 10:35:07 +0300143 * We are HW_MONITOR device. On beacon loss - queue
144 * connection loss work. Cancel it on REGAINED event.
Juuso Oikarinenb771eee2009-10-08 21:56:34 +0300145 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200146 if (vector & BSS_LOSE_EVENT_ID) {
147 /* TODO: check for multi-role */
Bartosz.Markowski@tieto.com5f561f62012-04-26 10:35:07 +0300148 int delay = wl->conf.conn.synch_fail_thold *
149 wl->conf.conn.bss_lose_timeout;
Juuso Oikarinen1a186a52010-04-01 11:38:23 +0300150 wl1271_info("Beacon loss detected.");
Arik Nemtsov6b8bf5b2012-05-15 17:08:54 +0300151
152 /*
153 * if the work is already queued, it should take place. We
154 * don't want to delay the connection loss indication
155 * any more.
156 */
Bartosz.Markowski@tieto.com5f561f62012-04-26 10:35:07 +0300157 ieee80211_queue_delayed_work(wl->hw, &wl->connection_loss_work,
Arik Nemtsov6b8bf5b2012-05-15 17:08:54 +0300158 msecs_to_jiffies(delay));
Eliad Peller9f5b4242012-05-15 14:53:17 +0300159
160 wl12xx_for_each_wlvif_sta(wl, wlvif) {
161 vif = wl12xx_wlvif_to_vif(wlvif);
162
163 ieee80211_cqm_rssi_notify(
164 vif,
165 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
166 GFP_KERNEL);
167 }
Bartosz.Markowski@tieto.com5f561f62012-04-26 10:35:07 +0300168 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300169
Bartosz.Markowski@tieto.com5f561f62012-04-26 10:35:07 +0300170 if (vector & REGAINED_BSS_EVENT_ID) {
171 /* TODO: check for multi-role */
172 wl1271_info("Beacon regained.");
Arik Nemtsov6b8bf5b2012-05-15 17:08:54 +0300173 cancel_delayed_work(&wl->connection_loss_work);
174
175 /* sanity check - we can't lose and gain the beacon together */
176 WARN(vector & BSS_LOSE_EVENT_ID,
177 "Concurrent beacon loss and gain from FW");
Juuso Oikarinen19ad0712009-11-02 20:22:11 +0200178 }
179
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300180 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200181 /* TODO: check actual multi-role support */
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300182 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
Eliad Peller4b730b62011-10-10 10:12:57 +0200183 wl12xx_for_each_wlvif_sta(wl, wlvif) {
184 wl1271_event_rssi_trigger(wl, wlvif, mbox);
185 }
Juuso Oikarinen00236aed2010-04-09 11:07:30 +0300186 }
187
Eliad Peller4b730b62011-10-10 10:12:57 +0200188 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
189 u8 role_id = mbox->role_id;
Shahar Levi70559a02011-05-22 16:10:22 +0300190 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
Eliad Peller4b730b62011-10-10 10:12:57 +0200191 "ba_allowed = 0x%x, role_id=%d",
192 mbox->rx_ba_allowed, role_id);
Shahar Levi70559a02011-05-22 16:10:22 +0300193
Eliad Peller4b730b62011-10-10 10:12:57 +0200194 wl12xx_for_each_wlvif(wl, wlvif) {
195 if (role_id != 0xff && role_id != wlvif->role_id)
196 continue;
Arik Nemtsovf4d3b6a2011-08-25 12:43:16 +0300197
Eliad Peller4b730b62011-10-10 10:12:57 +0200198 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
199 if (!wlvif->ba_allowed)
200 wl1271_stop_ba_event(wl, wlvif);
201 }
Shahar Levi70559a02011-05-22 16:10:22 +0300202 }
203
Eliad Peller4b730b62011-10-10 10:12:57 +0200204 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
Shahar Levi6d158ff2011-09-08 13:01:33 +0300205 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
206 "status = 0x%x",
207 mbox->channel_switch_status);
208 /*
209 * That event uses for two cases:
210 * 1) channel switch complete with status=0
211 * 2) channel switch failed status=1
212 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200213
Eliad Peller52630c52011-10-10 10:13:08 +0200214 /* TODO: configure only the relevant vif */
215 wl12xx_for_each_wlvif_sta(wl, wlvif) {
Eliad Peller52630c52011-10-10 10:13:08 +0200216 bool success;
217
218 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
Victor Goldenshteinec414c72012-03-12 16:36:48 +0200219 &wlvif->flags))
Eliad Peller52630c52011-10-10 10:13:08 +0200220 continue;
221
222 success = mbox->channel_switch_status ? false : true;
Luciano Coelho775e1a42012-01-24 11:46:32 +0200223 vif = wl12xx_wlvif_to_vif(wlvif);
224
Eliad Peller52630c52011-10-10 10:13:08 +0200225 ieee80211_chswitch_done(vif, success);
Eliad Peller4b730b62011-10-10 10:12:57 +0200226 }
Shahar Levi6d158ff2011-09-08 13:01:33 +0300227 }
228
Arik Nemtsov79ebec72011-08-14 13:17:18 +0300229 if ((vector & DUMMY_PACKET_EVENT_ID)) {
Shahar Leviae47c452011-03-06 16:32:14 +0200230 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
Eliad Peller4b730b62011-10-10 10:12:57 +0200231 wl1271_tx_dummy_packet(wl);
Shahar Leviae47c452011-03-06 16:32:14 +0200232 }
233
Arik Nemtsov3618f302011-06-26 10:36:03 +0300234 /*
235 * "TX retries exceeded" has a different meaning according to mode.
236 * In AP mode the offending station is disconnected.
237 */
Eliad Peller4b730b62011-10-10 10:12:57 +0200238 if (vector & MAX_TX_RETRY_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300239 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
240 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
241 disconnect_sta = true;
242 }
243
Eliad Peller4b730b62011-10-10 10:12:57 +0200244 if (vector & INACTIVE_STA_EVENT_ID) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300245 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
246 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
247 disconnect_sta = true;
248 }
249
Eliad Peller4b730b62011-10-10 10:12:57 +0200250 if (disconnect_sta) {
Arik Nemtsov3618f302011-06-26 10:36:03 +0300251 u32 num_packets = wl->conf.tx.max_tx_retries;
252 struct ieee80211_sta *sta;
253 const u8 *addr;
254 int h;
255
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200256 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
Eliad Peller4b730b62011-10-10 10:12:57 +0200257 bool found = false;
258 /* find the ap vif connected to this sta */
259 wl12xx_for_each_wlvif_ap(wl, wlvif) {
260 if (!test_bit(h, wlvif->ap.sta_hlid_map))
261 continue;
262 found = true;
263 break;
264 }
265 if (!found)
Arik Nemtsov3618f302011-06-26 10:36:03 +0300266 continue;
267
Eliad Peller4b730b62011-10-10 10:12:57 +0200268 vif = wl12xx_wlvif_to_vif(wlvif);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300269 addr = wl->links[h].addr;
270
271 rcu_read_lock();
Eliad Peller4b730b62011-10-10 10:12:57 +0200272 sta = ieee80211_find_sta(vif, addr);
Arik Nemtsov3618f302011-06-26 10:36:03 +0300273 if (sta) {
274 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
275 ieee80211_report_low_ack(sta, num_packets);
276 }
277 rcu_read_unlock();
278 }
279 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300280 return 0;
281}
282
283int wl1271_event_unmask(struct wl1271 *wl)
284{
285 int ret;
286
287 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
288 if (ret < 0)
289 return ret;
290
291 return 0;
292}
293
Juuso Oikarinen13f2dc52009-12-11 15:40:59 +0200294int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300295{
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300296 int ret;
297
298 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
299
300 if (mbox_num > 1)
301 return -EINVAL;
302
303 /* first we read the mbox descriptor */
Mircea Gherzan690142e2012-03-17 18:41:53 +0100304 wl1271_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
305 sizeof(*wl->mbox), false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300306
307 /* process the descriptor */
Mircea Gherzan690142e2012-03-17 18:41:53 +0100308 ret = wl1271_event_process(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300309 if (ret < 0)
310 return ret;
311
Luciano Coelhof16ff752012-04-11 10:15:46 +0300312 /*
313 * TODO: we just need this because one bit is in a different
314 * place. Is there any better way?
315 */
316 wl->ops->ack_event(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300317
318 return 0;
319}