wlcore: Propagate errors from wl1271_read
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / net / wireless / ti / wlcore / event.c
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
24 #include "wlcore.h"
25 #include "debug.h"
26 #include "io.h"
27 #include "event.h"
28 #include "ps.h"
29 #include "scan.h"
30 #include "wl12xx_80211.h"
31
32 static void wl1271_event_rssi_trigger(struct wl1271 *wl,
33 struct wl12xx_vif *wlvif,
34 struct event_mailbox *mbox)
35 {
36 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
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
42 if (metric <= wlvif->rssi_thold)
43 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
44 else
45 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
46
47 if (event != wlvif->last_rssi_event)
48 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
49 wlvif->last_rssi_event = event;
50 }
51
52 static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
53 {
54 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
55
56 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
57 if (!wlvif->sta.ba_rx_bitmap)
58 return;
59 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
60 vif->bss_conf.bssid);
61 } else {
62 u8 hlid;
63 struct wl1271_link *lnk;
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)
68 continue;
69
70 ieee80211_stop_rx_ba_session(vif,
71 lnk->ba_bitmap,
72 lnk->addr);
73 }
74 }
75 }
76
77 static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
78 u8 enable)
79 {
80 struct wl12xx_vif *wlvif;
81
82 if (enable) {
83 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
84 } else {
85 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
86 wl12xx_for_each_wlvif_sta(wl, wlvif) {
87 wl1271_recalc_rx_streaming(wl, wlvif);
88 }
89 }
90
91 }
92
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
100 static int wl1271_event_process(struct wl1271 *wl)
101 {
102 struct event_mailbox *mbox = wl->mbox;
103 struct ieee80211_vif *vif;
104 struct wl12xx_vif *wlvif;
105 u32 vector;
106 bool disconnect_sta = false;
107 unsigned long sta_bitmap = 0;
108
109 wl1271_event_mbox_dump(mbox);
110
111 vector = le32_to_cpu(mbox->events_vector);
112 vector &= ~(le32_to_cpu(mbox->events_mask));
113 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
114
115 if (vector & SCAN_COMPLETE_EVENT_ID) {
116 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
117 mbox->scheduled_scan_status);
118
119 wl1271_scan_stm(wl, wl->scan_vif);
120 }
121
122 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
123 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
124 "(status 0x%0x)", mbox->scheduled_scan_status);
125
126 wl1271_scan_sched_scan_results(wl);
127 }
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);
132 if (wl->sched_scanning) {
133 ieee80211_sched_scan_stopped(wl->hw);
134 wl->sched_scanning = false;
135 }
136 }
137
138 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
139 wl12xx_event_soft_gemini_sense(wl,
140 mbox->soft_gemini_sense_info);
141
142 /*
143 * We are HW_MONITOR device. On beacon loss - queue
144 * connection loss work. Cancel it on REGAINED event.
145 */
146 if (vector & BSS_LOSE_EVENT_ID) {
147 /* TODO: check for multi-role */
148 int delay = wl->conf.conn.synch_fail_thold *
149 wl->conf.conn.bss_lose_timeout;
150 wl1271_info("Beacon loss detected.");
151
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 */
157 ieee80211_queue_delayed_work(wl->hw, &wl->connection_loss_work,
158 msecs_to_jiffies(delay));
159
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 }
168 }
169
170 if (vector & REGAINED_BSS_EVENT_ID) {
171 /* TODO: check for multi-role */
172 wl1271_info("Beacon regained.");
173 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");
178 }
179
180 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
181 /* TODO: check actual multi-role support */
182 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
183 wl12xx_for_each_wlvif_sta(wl, wlvif) {
184 wl1271_event_rssi_trigger(wl, wlvif, mbox);
185 }
186 }
187
188 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
189 u8 role_id = mbox->role_id;
190 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
191 "ba_allowed = 0x%x, role_id=%d",
192 mbox->rx_ba_allowed, role_id);
193
194 wl12xx_for_each_wlvif(wl, wlvif) {
195 if (role_id != 0xff && role_id != wlvif->role_id)
196 continue;
197
198 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
199 if (!wlvif->ba_allowed)
200 wl1271_stop_ba_event(wl, wlvif);
201 }
202 }
203
204 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
205 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 */
213
214 /* TODO: configure only the relevant vif */
215 wl12xx_for_each_wlvif_sta(wl, wlvif) {
216 bool success;
217
218 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
219 &wlvif->flags))
220 continue;
221
222 success = mbox->channel_switch_status ? false : true;
223 vif = wl12xx_wlvif_to_vif(wlvif);
224
225 ieee80211_chswitch_done(vif, success);
226 }
227 }
228
229 if ((vector & DUMMY_PACKET_EVENT_ID)) {
230 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
231 wl1271_tx_dummy_packet(wl);
232 }
233
234 /*
235 * "TX retries exceeded" has a different meaning according to mode.
236 * In AP mode the offending station is disconnected.
237 */
238 if (vector & MAX_TX_RETRY_EVENT_ID) {
239 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
244 if (vector & INACTIVE_STA_EVENT_ID) {
245 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
246 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
247 disconnect_sta = true;
248 }
249
250 if (disconnect_sta) {
251 u32 num_packets = wl->conf.tx.max_tx_retries;
252 struct ieee80211_sta *sta;
253 const u8 *addr;
254 int h;
255
256 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
257 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)
266 continue;
267
268 vif = wl12xx_wlvif_to_vif(wlvif);
269 addr = wl->links[h].addr;
270
271 rcu_read_lock();
272 sta = ieee80211_find_sta(vif, addr);
273 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 }
280 return 0;
281 }
282
283 int 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
294 int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
295 {
296 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 */
304 ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
305 sizeof(*wl->mbox), false);
306 if (ret < 0)
307 return ret;
308
309 /* process the descriptor */
310 ret = wl1271_event_process(wl);
311 if (ret < 0)
312 return ret;
313
314 /*
315 * TODO: we just need this because one bit is in a different
316 * place. Is there any better way?
317 */
318 wl->ops->ack_event(wl);
319
320 return 0;
321 }