1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
32void wlcore_event_rssi_trigger(struct wl1271 *wl, s8 *metric_arr)
33{
34 struct wl12xx_vif *wlvif;
35 struct ieee80211_vif *vif;
36 enum nl80211_cqm_rssi_threshold_event event;
37 s8 metric = metric_arr[0];
38
39 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
40
41
42 wl12xx_for_each_wlvif_sta(wl, wlvif) {
43 if (metric <= wlvif->rssi_thold)
44 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
45 else
46 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
47
48 vif = wl12xx_wlvif_to_vif(wlvif);
49 if (event != wlvif->last_rssi_event)
50 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
51 wlvif->last_rssi_event = event;
52 }
53}
54EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger);
55
56static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
57{
58 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
59
60 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
61 u8 hlid = wlvif->sta.hlid;
62 if (!wl->links[hlid].ba_bitmap)
63 return;
64 ieee80211_stop_rx_ba_session(vif, wl->links[hlid].ba_bitmap,
65 vif->bss_conf.bssid);
66 } else {
67 u8 hlid;
68 struct wl1271_link *lnk;
69 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
70 wl->num_links) {
71 lnk = &wl->links[hlid];
72 if (!lnk->ba_bitmap)
73 continue;
74
75 ieee80211_stop_rx_ba_session(vif,
76 lnk->ba_bitmap,
77 lnk->addr);
78 }
79 }
80}
81
82void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
83{
84 struct wl12xx_vif *wlvif;
85
86 if (enable) {
87 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
88 } else {
89 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
90 wl12xx_for_each_wlvif_sta(wl, wlvif) {
91 wl1271_recalc_rx_streaming(wl, wlvif);
92 }
93 }
94}
95EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
96
97void wlcore_event_sched_scan_completed(struct wl1271 *wl,
98 u8 status)
99{
100 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
101 status);
102
103 if (wl->sched_vif) {
104 ieee80211_sched_scan_stopped(wl->hw);
105 wl->sched_vif = NULL;
106 }
107}
108EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
109
110void wlcore_event_ba_rx_constraint(struct wl1271 *wl,
111 unsigned long roles_bitmap,
112 unsigned long allowed_bitmap)
113{
114 struct wl12xx_vif *wlvif;
115
116 wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
117 __func__, roles_bitmap, allowed_bitmap);
118
119 wl12xx_for_each_wlvif(wl, wlvif) {
120 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
121 !test_bit(wlvif->role_id , &roles_bitmap))
122 continue;
123
124 wlvif->ba_allowed = !!test_bit(wlvif->role_id,
125 &allowed_bitmap);
126 if (!wlvif->ba_allowed)
127 wl1271_stop_ba_event(wl, wlvif);
128 }
129}
130EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
131
132void wlcore_event_channel_switch(struct wl1271 *wl,
133 unsigned long roles_bitmap,
134 bool success)
135{
136 struct wl12xx_vif *wlvif;
137 struct ieee80211_vif *vif;
138
139 wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
140 __func__, roles_bitmap, success);
141
142 wl12xx_for_each_wlvif_sta(wl, wlvif) {
143 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
144 !test_bit(wlvif->role_id , &roles_bitmap))
145 continue;
146
147 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
148 &wlvif->flags))
149 continue;
150
151 vif = wl12xx_wlvif_to_vif(wlvif);
152
153 ieee80211_chswitch_done(vif, success);
154 cancel_delayed_work(&wlvif->channel_switch_work);
155 }
156}
157EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
158
159void wlcore_event_dummy_packet(struct wl1271 *wl)
160{
161 if (wl->plt) {
162 wl1271_info("Got DUMMY_PACKET event in PLT mode. FW bug, ignoring.");
163 return;
164 }
165
166 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
167 wl1271_tx_dummy_packet(wl);
168}
169EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
170
171static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
172{
173 u32 num_packets = wl->conf.tx.max_tx_retries;
174 struct wl12xx_vif *wlvif;
175 struct ieee80211_vif *vif;
176 struct ieee80211_sta *sta;
177 const u8 *addr;
178 int h;
179
180 for_each_set_bit(h, &sta_bitmap, wl->num_links) {
181 bool found = false;
182
183 wl12xx_for_each_wlvif_ap(wl, wlvif) {
184 if (!test_bit(h, wlvif->ap.sta_hlid_map))
185 continue;
186 found = true;
187 break;
188 }
189 if (!found)
190 continue;
191
192 vif = wl12xx_wlvif_to_vif(wlvif);
193 addr = wl->links[h].addr;
194
195 rcu_read_lock();
196 sta = ieee80211_find_sta(vif, addr);
197 if (sta) {
198 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
199 ieee80211_report_low_ack(sta, num_packets);
200 }
201 rcu_read_unlock();
202 }
203}
204
205void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
206{
207 wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
208 wlcore_disconnect_sta(wl, sta_bitmap);
209}
210EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
211
212void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
213{
214 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
215 wlcore_disconnect_sta(wl, sta_bitmap);
216}
217EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
218
219void wlcore_event_roc_complete(struct wl1271 *wl)
220{
221 wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
222 if (wl->roc_vif)
223 ieee80211_ready_on_channel(wl->hw);
224}
225EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
226
227void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
228{
229
230
231
232
233 struct wl12xx_vif *wlvif;
234 struct ieee80211_vif *vif;
235 int delay = wl->conf.conn.synch_fail_thold *
236 wl->conf.conn.bss_lose_timeout;
237
238 wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
239
240 wl12xx_for_each_wlvif_sta(wl, wlvif) {
241 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
242 !test_bit(wlvif->role_id , &roles_bitmap))
243 continue;
244
245 vif = wl12xx_wlvif_to_vif(wlvif);
246
247
248 if (wlvif->p2p) {
249 ieee80211_connection_loss(vif);
250 continue;
251 }
252
253
254
255
256
257
258 ieee80211_queue_delayed_work(wl->hw,
259 &wlvif->connection_loss_work,
260 msecs_to_jiffies(delay));
261
262 ieee80211_cqm_beacon_loss_notify(vif, GFP_KERNEL);
263 }
264}
265EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
266
267int wl1271_event_unmask(struct wl1271 *wl)
268{
269 int ret;
270
271 wl1271_debug(DEBUG_EVENT, "unmasking event_mask 0x%x", wl->event_mask);
272 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
273 if (ret < 0)
274 return ret;
275
276 return 0;
277}
278
279int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
280{
281 int ret;
282
283 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
284
285 if (mbox_num > 1)
286 return -EINVAL;
287
288
289 ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
290 wl->mbox_size, false);
291 if (ret < 0)
292 return ret;
293
294
295 ret = wl->ops->process_mailbox_events(wl);
296 if (ret < 0)
297 return ret;
298
299
300
301
302
303 ret = wl->ops->ack_event(wl);
304
305 return ret;
306}
307