2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
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.
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.
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
30 #include "wl12xx_80211.h"
32 static void wl1271_event_rssi_trigger(struct wl1271 *wl,
33 struct wl12xx_vif *wlvif,
34 struct event_mailbox *mbox)
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];
40 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
42 if (metric <= wlvif->rssi_thold)
43 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
45 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
47 if (event != wlvif->last_rssi_event)
48 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
49 wlvif->last_rssi_event = event;
52 static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
54 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
56 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
57 if (!wlvif->sta.ba_rx_bitmap)
59 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
63 struct wl1271_link *lnk;
64 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
66 lnk = &wl->links[hlid];
70 ieee80211_stop_rx_ba_session(vif,
77 static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
80 struct wl12xx_vif *wlvif;
83 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
85 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
86 wl12xx_for_each_wlvif_sta(wl, wlvif) {
87 wl1271_recalc_rx_streaming(wl, wlvif);
93 static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
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);
100 static int wl1271_event_process(struct wl1271 *wl)
102 struct event_mailbox *mbox = wl->mbox;
103 struct ieee80211_vif *vif;
104 struct wl12xx_vif *wlvif;
106 bool disconnect_sta = false;
107 unsigned long sta_bitmap = 0;
110 wl1271_event_mbox_dump(mbox);
112 vector = le32_to_cpu(mbox->events_vector);
113 vector &= ~(le32_to_cpu(mbox->events_mask));
114 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
116 if (vector & SCAN_COMPLETE_EVENT_ID) {
117 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
118 mbox->scheduled_scan_status);
120 wl1271_scan_stm(wl, wl->scan_vif);
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);
127 wl1271_scan_sched_scan_results(wl);
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);
133 if (wl->sched_scanning) {
134 ieee80211_sched_scan_stopped(wl->hw);
135 wl->sched_scanning = false;
139 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
140 wl12xx_event_soft_gemini_sense(wl,
141 mbox->soft_gemini_sense_info);
144 * We are HW_MONITOR device. On beacon loss - queue
145 * connection loss work. Cancel it on REGAINED event.
147 if (vector & BSS_LOSE_EVENT_ID) {
148 /* TODO: check for multi-role */
149 int delay = wl->conf.conn.synch_fail_thold *
150 wl->conf.conn.bss_lose_timeout;
151 wl1271_info("Beacon loss detected.");
154 * if the work is already queued, it should take place. We
155 * don't want to delay the connection loss indication
158 ieee80211_queue_delayed_work(wl->hw, &wl->connection_loss_work,
159 msecs_to_jiffies(delay));
161 wl12xx_for_each_wlvif_sta(wl, wlvif) {
162 vif = wl12xx_wlvif_to_vif(wlvif);
164 ieee80211_cqm_rssi_notify(
166 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
171 if (vector & REGAINED_BSS_EVENT_ID) {
172 /* TODO: check for multi-role */
173 wl1271_info("Beacon regained.");
174 cancel_delayed_work(&wl->connection_loss_work);
176 /* sanity check - we can't lose and gain the beacon together */
177 WARN(vector & BSS_LOSE_EVENT_ID,
178 "Concurrent beacon loss and gain from FW");
181 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
182 /* TODO: check actual multi-role support */
183 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
184 wl12xx_for_each_wlvif_sta(wl, wlvif) {
185 wl1271_event_rssi_trigger(wl, wlvif, mbox);
189 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
190 u8 role_id = mbox->role_id;
191 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
192 "ba_allowed = 0x%x, role_id=%d",
193 mbox->rx_ba_allowed, role_id);
195 wl12xx_for_each_wlvif(wl, wlvif) {
196 if (role_id != 0xff && role_id != wlvif->role_id)
199 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
200 if (!wlvif->ba_allowed)
201 wl1271_stop_ba_event(wl, wlvif);
205 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
206 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
208 mbox->channel_switch_status);
210 * That event uses for two cases:
211 * 1) channel switch complete with status=0
212 * 2) channel switch failed status=1
215 /* TODO: configure only the relevant vif */
216 wl12xx_for_each_wlvif_sta(wl, wlvif) {
219 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
223 success = mbox->channel_switch_status ? false : true;
224 vif = wl12xx_wlvif_to_vif(wlvif);
226 ieee80211_chswitch_done(vif, success);
230 if ((vector & DUMMY_PACKET_EVENT_ID)) {
231 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
232 ret = wl1271_tx_dummy_packet(wl);
238 * "TX retries exceeded" has a different meaning according to mode.
239 * In AP mode the offending station is disconnected.
241 if (vector & MAX_TX_RETRY_EVENT_ID) {
242 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
243 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
244 disconnect_sta = true;
247 if (vector & INACTIVE_STA_EVENT_ID) {
248 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
249 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
250 disconnect_sta = true;
253 if (disconnect_sta) {
254 u32 num_packets = wl->conf.tx.max_tx_retries;
255 struct ieee80211_sta *sta;
259 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
261 /* find the ap vif connected to this sta */
262 wl12xx_for_each_wlvif_ap(wl, wlvif) {
263 if (!test_bit(h, wlvif->ap.sta_hlid_map))
271 vif = wl12xx_wlvif_to_vif(wlvif);
272 addr = wl->links[h].addr;
275 sta = ieee80211_find_sta(vif, addr);
277 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
278 ieee80211_report_low_ack(sta, num_packets);
286 int wl1271_event_unmask(struct wl1271 *wl)
290 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
297 int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
301 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
306 /* first we read the mbox descriptor */
307 ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
308 sizeof(*wl->mbox), false);
312 /* process the descriptor */
313 ret = wl1271_event_process(wl);
318 * TODO: we just need this because one bit is in a different
319 * place. Is there any better way?
321 ret = wl->ops->ack_event(wl);