wl12xx: increase scan timeout to 30s
[linux-2.6-block.git] / drivers / net / wireless / wl12xx / event.c
CommitLineData
f5fc0f86
LC
1/*
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
00d20100 24#include "wl12xx.h"
0f4e3122 25#include "debug.h"
00d20100
SL
26#include "reg.h"
27#include "io.h"
28#include "event.h"
29#include "ps.h"
30#include "scan.h"
66497dc3 31#include "wl12xx_80211.h"
f5fc0f86 32
00236aed 33static void wl1271_event_rssi_trigger(struct wl1271 *wl,
4b730b6a 34 struct wl12xx_vif *wlvif,
00236aed
JO
35 struct event_mailbox *mbox)
36{
4b730b6a 37 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
00236aed
JO
38 enum nl80211_cqm_rssi_threshold_event event;
39 s8 metric = mbox->rssi_snr_trigger_metric[0];
40
41 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
42
04324d99 43 if (metric <= wlvif->rssi_thold)
00236aed
JO
44 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
45 else
46 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
47
04324d99
EP
48 if (event != wlvif->last_rssi_event)
49 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
50 wlvif->last_rssi_event = event;
00236aed
JO
51}
52
536129c8 53static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
70559a06 54{
4b730b6a
EP
55 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
56
536129c8 57 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
d0802abd 58 if (!wlvif->sta.ba_rx_bitmap)
f4d3b6ab 59 return;
4b730b6a
EP
60 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
61 vif->bss_conf.bssid);
f4d3b6ab 62 } else {
c7ffb902 63 u8 hlid;
f4d3b6ab 64 struct wl1271_link *lnk;
c7ffb902
EP
65 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
66 WL12XX_MAX_LINKS) {
67 lnk = &wl->links[hlid];
68 if (!lnk->ba_bitmap)
f4d3b6ab
AN
69 continue;
70
4b730b6a 71 ieee80211_stop_rx_ba_session(vif,
f4d3b6ab
AN
72 lnk->ba_bitmap,
73 lnk->addr);
74 }
75 }
70559a06
SL
76}
77
77ddaa10
EP
78static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
79 u8 enable)
80{
4b730b6a
EP
81 struct wl12xx_vif *wlvif;
82
77ddaa10 83 if (enable) {
77ddaa10
EP
84 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
85 } else {
9eb599e9 86 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
4b730b6a 87 wl12xx_for_each_wlvif_sta(wl, wlvif) {
9eb599e9 88 wl1271_recalc_rx_streaming(wl, wlvif);
4b730b6a 89 }
77ddaa10
EP
90 }
91
92}
93
f5fc0f86
LC
94static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
95{
96 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
97 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
98 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
99}
100
690142e9 101static int wl1271_event_process(struct wl1271 *wl)
f5fc0f86 102{
690142e9 103 struct event_mailbox *mbox = wl->mbox;
4b730b6a
EP
104 struct ieee80211_vif *vif;
105 struct wl12xx_vif *wlvif;
f5fc0f86 106 u32 vector;
19ad0715 107 bool beacon_loss = false;
3618f30f
AN
108 bool disconnect_sta = false;
109 unsigned long sta_bitmap = 0;
f5fc0f86
LC
110
111 wl1271_event_mbox_dump(mbox);
112
d0f63b20
LC
113 vector = le32_to_cpu(mbox->events_vector);
114 vector &= ~(le32_to_cpu(mbox->events_mask));
f5fc0f86
LC
115 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
116
117 if (vector & SCAN_COMPLETE_EVENT_ID) {
34dd2aaa
LC
118 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
119 mbox->scheduled_scan_status);
120
784f694d 121 wl1271_scan_stm(wl, wl->scan_vif);
f5fc0f86
LC
122 }
123
6394c01b
LC
124 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
125 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
126 "(status 0x%0x)", mbox->scheduled_scan_status);
33c2c06c
LC
127
128 wl1271_scan_sched_scan_results(wl);
6394c01b
LC
129 }
130
131 if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
132 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
133 "(status 0x%0x)", mbox->scheduled_scan_status);
33c2c06c 134 if (wl->sched_scanning) {
33c2c06c 135 ieee80211_sched_scan_stopped(wl->hw);
ee91d185 136 wl->sched_scanning = false;
33c2c06c 137 }
6394c01b
LC
138 }
139
4b730b6a 140 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
77ddaa10
EP
141 wl12xx_event_soft_gemini_sense(wl,
142 mbox->soft_gemini_sense_info);
8d2ef7bd 143
b771eee5
JO
144 /*
145 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
146 * filtering) is enabled. Without PSM, the stack will receive all
147 * beacons and can detect beacon loss by itself.
64e29e44
TP
148 *
149 * As there's possibility that the driver disables PSM before receiving
150 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
151 *
b771eee5 152 */
4b730b6a
EP
153 if (vector & BSS_LOSE_EVENT_ID) {
154 /* TODO: check for multi-role */
1a186a51 155 wl1271_info("Beacon loss detected.");
f5fc0f86 156
b771eee5 157 /* indicate to the stack, that beacons have been lost */
19ad0715
JO
158 beacon_loss = true;
159 }
160
00236aed 161 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
4b730b6a 162 /* TODO: check actual multi-role support */
00236aed 163 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
4b730b6a
EP
164 wl12xx_for_each_wlvif_sta(wl, wlvif) {
165 wl1271_event_rssi_trigger(wl, wlvif, mbox);
166 }
00236aed
JO
167 }
168
4b730b6a
EP
169 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
170 u8 role_id = mbox->role_id;
70559a06 171 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
4b730b6a
EP
172 "ba_allowed = 0x%x, role_id=%d",
173 mbox->rx_ba_allowed, role_id);
70559a06 174
4b730b6a
EP
175 wl12xx_for_each_wlvif(wl, wlvif) {
176 if (role_id != 0xff && role_id != wlvif->role_id)
177 continue;
f4d3b6ab 178
4b730b6a
EP
179 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
180 if (!wlvif->ba_allowed)
181 wl1271_stop_ba_event(wl, wlvif);
182 }
70559a06
SL
183 }
184
4b730b6a 185 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
6d158ff3
SL
186 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
187 "status = 0x%x",
188 mbox->channel_switch_status);
189 /*
190 * That event uses for two cases:
191 * 1) channel switch complete with status=0
192 * 2) channel switch failed status=1
193 */
52630c5d
EP
194
195 /* TODO: configure only the relevant vif */
196 wl12xx_for_each_wlvif_sta(wl, wlvif) {
52630c5d
EP
197 bool success;
198
199 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
ec414c7c 200 &wlvif->flags))
52630c5d
EP
201 continue;
202
203 success = mbox->channel_switch_status ? false : true;
775e1a4b
LC
204 vif = wl12xx_wlvif_to_vif(wlvif);
205
52630c5d 206 ieee80211_chswitch_done(vif, success);
4b730b6a 207 }
6d158ff3
SL
208 }
209
79ebec76 210 if ((vector & DUMMY_PACKET_EVENT_ID)) {
ae47c45f 211 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
4b730b6a 212 wl1271_tx_dummy_packet(wl);
ae47c45f
SL
213 }
214
3618f30f
AN
215 /*
216 * "TX retries exceeded" has a different meaning according to mode.
217 * In AP mode the offending station is disconnected.
218 */
4b730b6a 219 if (vector & MAX_TX_RETRY_EVENT_ID) {
3618f30f
AN
220 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
221 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
222 disconnect_sta = true;
223 }
224
4b730b6a 225 if (vector & INACTIVE_STA_EVENT_ID) {
3618f30f
AN
226 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
227 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
228 disconnect_sta = true;
229 }
230
4b730b6a 231 if (disconnect_sta) {
3618f30f
AN
232 u32 num_packets = wl->conf.tx.max_tx_retries;
233 struct ieee80211_sta *sta;
234 const u8 *addr;
235 int h;
236
c7ffb902 237 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
4b730b6a
EP
238 bool found = false;
239 /* find the ap vif connected to this sta */
240 wl12xx_for_each_wlvif_ap(wl, wlvif) {
241 if (!test_bit(h, wlvif->ap.sta_hlid_map))
242 continue;
243 found = true;
244 break;
245 }
246 if (!found)
3618f30f
AN
247 continue;
248
4b730b6a 249 vif = wl12xx_wlvif_to_vif(wlvif);
3618f30f
AN
250 addr = wl->links[h].addr;
251
252 rcu_read_lock();
4b730b6a 253 sta = ieee80211_find_sta(vif, addr);
3618f30f
AN
254 if (sta) {
255 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
256 ieee80211_report_low_ack(sta, num_packets);
257 }
258 rcu_read_unlock();
259 }
260 }
261
4b730b6a
EP
262 if (beacon_loss)
263 wl12xx_for_each_wlvif_sta(wl, wlvif) {
264 vif = wl12xx_wlvif_to_vif(wlvif);
265 ieee80211_connection_loss(vif);
266 }
f5fc0f86
LC
267
268 return 0;
269}
270
271int wl1271_event_unmask(struct wl1271 *wl)
272{
273 int ret;
274
275 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
276 if (ret < 0)
277 return ret;
278
279 return 0;
280}
281
282void wl1271_event_mbox_config(struct wl1271 *wl)
283{
7b048c52 284 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
f5fc0f86
LC
285 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
286
287 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
288 wl->mbox_ptr[0], wl->mbox_ptr[1]);
289}
290
13f2dc52 291int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
f5fc0f86 292{
f5fc0f86
LC
293 int ret;
294
295 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
296
297 if (mbox_num > 1)
298 return -EINVAL;
299
300 /* first we read the mbox descriptor */
690142e9
MG
301 wl1271_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
302 sizeof(*wl->mbox), false);
f5fc0f86
LC
303
304 /* process the descriptor */
690142e9 305 ret = wl1271_event_process(wl);
f5fc0f86
LC
306 if (ret < 0)
307 return ret;
308
309 /* then we let the firmware know it can go on...*/
7b048c52 310 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
f5fc0f86
LC
311
312 return 0;
313}