wlcore: add support for ap csa
[deliverable/linux.git] / drivers / net / wireless / ti / wlcore / 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
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
c50a2825 32void wlcore_event_rssi_trigger(struct wl1271 *wl, s8 *metric_arr)
00236aed 33{
c50a2825
EP
34 struct wl12xx_vif *wlvif;
35 struct ieee80211_vif *vif;
00236aed 36 enum nl80211_cqm_rssi_threshold_event event;
c50a2825 37 s8 metric = metric_arr[0];
00236aed
JO
38
39 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
40
c50a2825
EP
41 /* TODO: check actual multi-role support */
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 }
00236aed 53}
c50a2825 54EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger);
00236aed 55
536129c8 56static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
70559a06 57{
4b730b6a
EP
58 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
59
536129c8 60 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
9ae5d8d4
AN
61 u8 hlid = wlvif->sta.hlid;
62 if (!wl->links[hlid].ba_bitmap)
f4d3b6ab 63 return;
9ae5d8d4 64 ieee80211_stop_rx_ba_session(vif, wl->links[hlid].ba_bitmap,
4b730b6a 65 vif->bss_conf.bssid);
f4d3b6ab 66 } else {
c7ffb902 67 u8 hlid;
f4d3b6ab 68 struct wl1271_link *lnk;
c7ffb902 69 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
da08fdfa 70 wl->num_links) {
c7ffb902
EP
71 lnk = &wl->links[hlid];
72 if (!lnk->ba_bitmap)
f4d3b6ab
AN
73 continue;
74
4b730b6a 75 ieee80211_stop_rx_ba_session(vif,
f4d3b6ab
AN
76 lnk->ba_bitmap,
77 lnk->addr);
78 }
79 }
70559a06
SL
80}
81
c50a2825 82void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
77ddaa10 83{
4b730b6a
EP
84 struct wl12xx_vif *wlvif;
85
77ddaa10 86 if (enable) {
77ddaa10
EP
87 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
88 } else {
9eb599e9 89 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
4b730b6a 90 wl12xx_for_each_wlvif_sta(wl, wlvif) {
9eb599e9 91 wl1271_recalc_rx_streaming(wl, wlvif);
4b730b6a 92 }
77ddaa10 93 }
77ddaa10 94}
c50a2825 95EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
77ddaa10 96
c50a2825
EP
97void wlcore_event_sched_scan_completed(struct wl1271 *wl,
98 u8 status)
f5fc0f86 99{
c50a2825
EP
100 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
101 status);
f5fc0f86 102
10199756 103 if (wl->sched_vif) {
c50a2825 104 ieee80211_sched_scan_stopped(wl->hw);
10199756 105 wl->sched_vif = NULL;
c50a2825
EP
106 }
107}
108EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
f5fc0f86 109
c50a2825
EP
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;
f5fc0f86 115
c50a2825
EP
116 wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
117 __func__, roles_bitmap, allowed_bitmap);
34dd2aaa 118
c50a2825
EP
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;
f5fc0f86 123
c50a2825
EP
124 wlvif->ba_allowed = !!test_bit(wlvif->role_id,
125 &allowed_bitmap);
126 if (!wlvif->ba_allowed)
127 wl1271_stop_ba_event(wl, wlvif);
6394c01b 128 }
c50a2825
EP
129}
130EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
6394c01b 131
c50a2825
EP
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;
6394c01b 138
c50a2825
EP
139 wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
140 __func__, roles_bitmap, success);
8d2ef7bd 141
534719f4 142 wl12xx_for_each_wlvif(wl, wlvif) {
c50a2825
EP
143 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
144 !test_bit(wlvif->role_id , &roles_bitmap))
145 continue;
6b8bf5bc 146
c50a2825
EP
147 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
148 &wlvif->flags))
149 continue;
9f5b424d 150
c50a2825 151 vif = wl12xx_wlvif_to_vif(wlvif);
9f5b424d 152
534719f4
EP
153 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
154 ieee80211_chswitch_done(vif, success);
155 cancel_delayed_work(&wlvif->channel_switch_work);
156 } else {
157 ieee80211_csa_finish(vif);
158 }
5f561f68 159 }
c50a2825
EP
160}
161EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
f5fc0f86 162
c50a2825
EP
163void wlcore_event_dummy_packet(struct wl1271 *wl)
164{
69aa1675
LC
165 if (wl->plt) {
166 wl1271_info("Got DUMMY_PACKET event in PLT mode. FW bug, ignoring.");
167 return;
168 }
169
c50a2825
EP
170 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
171 wl1271_tx_dummy_packet(wl);
172}
173EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
19ad0715 174
c50a2825
EP
175static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
176{
177 u32 num_packets = wl->conf.tx.max_tx_retries;
178 struct wl12xx_vif *wlvif;
179 struct ieee80211_vif *vif;
180 struct ieee80211_sta *sta;
181 const u8 *addr;
182 int h;
183
da08fdfa 184 for_each_set_bit(h, &sta_bitmap, wl->num_links) {
c50a2825
EP
185 bool found = false;
186 /* find the ap vif connected to this sta */
187 wl12xx_for_each_wlvif_ap(wl, wlvif) {
188 if (!test_bit(h, wlvif->ap.sta_hlid_map))
189 continue;
190 found = true;
191 break;
4b730b6a 192 }
c50a2825
EP
193 if (!found)
194 continue;
70559a06 195
c50a2825
EP
196 vif = wl12xx_wlvif_to_vif(wlvif);
197 addr = wl->links[h].addr;
f4d3b6ab 198
c50a2825
EP
199 rcu_read_lock();
200 sta = ieee80211_find_sta(vif, addr);
201 if (sta) {
202 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
203 ieee80211_report_low_ack(sta, num_packets);
4b730b6a 204 }
c50a2825 205 rcu_read_unlock();
70559a06 206 }
c50a2825 207}
70559a06 208
c50a2825
EP
209void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
210{
211 wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
212 wlcore_disconnect_sta(wl, sta_bitmap);
213}
214EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
775e1a4b 215
c50a2825
EP
216void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
217{
218 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
219 wlcore_disconnect_sta(wl, sta_bitmap);
220}
221EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
6d158ff3 222
c50a2825
EP
223void wlcore_event_roc_complete(struct wl1271 *wl)
224{
225 wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
226 if (wl->roc_vif)
227 ieee80211_ready_on_channel(wl->hw);
228}
229EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
ae47c45f 230
c50a2825
EP
231void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
232{
3618f30f 233 /*
c50a2825
EP
234 * We are HW_MONITOR device. On beacon loss - queue
235 * connection loss work. Cancel it on REGAINED event.
3618f30f 236 */
c50a2825
EP
237 struct wl12xx_vif *wlvif;
238 struct ieee80211_vif *vif;
239 int delay = wl->conf.conn.synch_fail_thold *
240 wl->conf.conn.bss_lose_timeout;
3618f30f 241
c50a2825 242 wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
dabf37db 243
c50a2825
EP
244 wl12xx_for_each_wlvif_sta(wl, wlvif) {
245 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
246 !test_bit(wlvif->role_id , &roles_bitmap))
247 continue;
3618f30f 248
c0ad2f2e
ES
249 vif = wl12xx_wlvif_to_vif(wlvif);
250
251 /* don't attempt roaming in case of p2p */
252 if (wlvif->p2p) {
253 ieee80211_connection_loss(vif);
254 continue;
255 }
256
c50a2825
EP
257 /*
258 * if the work is already queued, it should take place.
259 * We don't want to delay the connection loss
260 * indication any more.
261 */
262 ieee80211_queue_delayed_work(wl->hw,
263 &wlvif->connection_loss_work,
264 msecs_to_jiffies(delay));
3618f30f 265
98f03342 266 ieee80211_cqm_beacon_loss_notify(vif, GFP_KERNEL);
3618f30f 267 }
f5fc0f86 268}
c50a2825 269EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
f5fc0f86
LC
270
271int wl1271_event_unmask(struct wl1271 *wl)
272{
273 int ret;
274
71e996be 275 wl1271_debug(DEBUG_EVENT, "unmasking event_mask 0x%x", wl->event_mask);
f5fc0f86
LC
276 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
277 if (ret < 0)
278 return ret;
279
280 return 0;
281}
282
13f2dc52 283int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
f5fc0f86 284{
f5fc0f86
LC
285 int ret;
286
287 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
288
289 if (mbox_num > 1)
290 return -EINVAL;
291
292 /* first we read the mbox descriptor */
045b9b5f 293 ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
c50a2825 294 wl->mbox_size, false);
045b9b5f
IY
295 if (ret < 0)
296 return ret;
f5fc0f86
LC
297
298 /* process the descriptor */
c50a2825 299 ret = wl->ops->process_mailbox_events(wl);
f5fc0f86
LC
300 if (ret < 0)
301 return ret;
302
f16ff758
LC
303 /*
304 * TODO: we just need this because one bit is in a different
305 * place. Is there any better way?
306 */
b0f0ad39 307 ret = wl->ops->ack_event(wl);
f5fc0f86 308
b0f0ad39 309 return ret;
f5fc0f86 310}
This page took 0.670288 seconds and 5 git commands to generate.