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