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
31 #include "wl12xx_80211.h"
33 static void wl1271_event_rssi_trigger(struct wl1271
*wl
,
34 struct wl12xx_vif
*wlvif
,
35 struct event_mailbox
*mbox
)
37 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
38 enum nl80211_cqm_rssi_threshold_event event
;
39 s8 metric
= mbox
->rssi_snr_trigger_metric
[0];
41 wl1271_debug(DEBUG_EVENT
, "RSSI trigger metric: %d", metric
);
43 if (metric
<= wlvif
->rssi_thold
)
44 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
;
46 event
= NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
;
48 if (event
!= wlvif
->last_rssi_event
)
49 ieee80211_cqm_rssi_notify(vif
, event
, GFP_KERNEL
);
50 wlvif
->last_rssi_event
= event
;
53 static void wl1271_stop_ba_event(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
55 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
57 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
58 if (!wlvif
->sta
.ba_rx_bitmap
)
60 ieee80211_stop_rx_ba_session(vif
, wlvif
->sta
.ba_rx_bitmap
,
64 struct wl1271_link
*lnk
;
65 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
,
67 lnk
= &wl
->links
[hlid
];
71 ieee80211_stop_rx_ba_session(vif
,
78 static void wl12xx_event_soft_gemini_sense(struct wl1271
*wl
,
81 struct wl12xx_vif
*wlvif
;
84 set_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
86 clear_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
);
87 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
88 wl1271_recalc_rx_streaming(wl
, wlvif
);
94 static void wl1271_event_mbox_dump(struct event_mailbox
*mbox
)
96 wl1271_debug(DEBUG_EVENT
, "MBOX DUMP:");
97 wl1271_debug(DEBUG_EVENT
, "\tvector: 0x%x", mbox
->events_vector
);
98 wl1271_debug(DEBUG_EVENT
, "\tmask: 0x%x", mbox
->events_mask
);
101 static int wl1271_event_process(struct wl1271
*wl
, struct event_mailbox
*mbox
)
103 struct ieee80211_vif
*vif
;
104 struct wl12xx_vif
*wlvif
;
106 bool beacon_loss
= false;
107 bool disconnect_sta
= false;
108 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 * 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.
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.
152 if (vector
& BSS_LOSE_EVENT_ID
) {
153 /* TODO: check for multi-role */
154 wl1271_info("Beacon loss detected.");
156 /* indicate to the stack, that beacons have been lost */
160 if (vector
& RSSI_SNR_TRIGGER_0_EVENT_ID
) {
161 /* TODO: check actual multi-role support */
162 wl1271_debug(DEBUG_EVENT
, "RSSI_SNR_TRIGGER_0_EVENT");
163 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
164 wl1271_event_rssi_trigger(wl
, wlvif
, mbox
);
168 if (vector
& BA_SESSION_RX_CONSTRAINT_EVENT_ID
) {
169 u8 role_id
= mbox
->role_id
;
170 wl1271_debug(DEBUG_EVENT
, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
171 "ba_allowed = 0x%x, role_id=%d",
172 mbox
->rx_ba_allowed
, role_id
);
174 wl12xx_for_each_wlvif(wl
, wlvif
) {
175 if (role_id
!= 0xff && role_id
!= wlvif
->role_id
)
178 wlvif
->ba_allowed
= !!mbox
->rx_ba_allowed
;
179 if (!wlvif
->ba_allowed
)
180 wl1271_stop_ba_event(wl
, wlvif
);
184 if (vector
& CHANNEL_SWITCH_COMPLETE_EVENT_ID
) {
185 wl1271_debug(DEBUG_EVENT
, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
187 mbox
->channel_switch_status
);
189 * That event uses for two cases:
190 * 1) channel switch complete with status=0
191 * 2) channel switch failed status=1
194 /* TODO: configure only the relevant vif */
195 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
198 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
,
202 success
= mbox
->channel_switch_status
? false : true;
203 vif
= wl12xx_wlvif_to_vif(wlvif
);
205 ieee80211_chswitch_done(vif
, success
);
209 if ((vector
& DUMMY_PACKET_EVENT_ID
)) {
210 wl1271_debug(DEBUG_EVENT
, "DUMMY_PACKET_ID_EVENT_ID");
211 wl1271_tx_dummy_packet(wl
);
215 * "TX retries exceeded" has a different meaning according to mode.
216 * In AP mode the offending station is disconnected.
218 if (vector
& MAX_TX_RETRY_EVENT_ID
) {
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;
224 if (vector
& INACTIVE_STA_EVENT_ID
) {
225 wl1271_debug(DEBUG_EVENT
, "INACTIVE_STA_EVENT_ID");
226 sta_bitmap
|= le16_to_cpu(mbox
->sta_aging_status
);
227 disconnect_sta
= true;
230 if (disconnect_sta
) {
231 u32 num_packets
= wl
->conf
.tx
.max_tx_retries
;
232 struct ieee80211_sta
*sta
;
236 for_each_set_bit(h
, &sta_bitmap
, WL12XX_MAX_LINKS
) {
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
))
248 vif
= wl12xx_wlvif_to_vif(wlvif
);
249 addr
= wl
->links
[h
].addr
;
252 sta
= ieee80211_find_sta(vif
, addr
);
254 wl1271_debug(DEBUG_EVENT
, "remove sta %d", h
);
255 ieee80211_report_low_ack(sta
, num_packets
);
262 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
263 vif
= wl12xx_wlvif_to_vif(wlvif
);
264 ieee80211_connection_loss(vif
);
270 int wl1271_event_unmask(struct wl1271
*wl
)
274 ret
= wl1271_acx_event_mbox_mask(wl
, ~(wl
->event_mask
));
281 void wl1271_event_mbox_config(struct wl1271
*wl
)
283 wl
->mbox_ptr
[0] = wl1271_read32(wl
, REG_EVENT_MAILBOX_PTR
);
284 wl
->mbox_ptr
[1] = wl
->mbox_ptr
[0] + sizeof(struct event_mailbox
);
286 wl1271_debug(DEBUG_EVENT
, "MBOX ptrs: 0x%x 0x%x",
287 wl
->mbox_ptr
[0], wl
->mbox_ptr
[1]);
290 int wl1271_event_handle(struct wl1271
*wl
, u8 mbox_num
)
292 struct event_mailbox mbox
;
295 wl1271_debug(DEBUG_EVENT
, "EVENT on mbox %d", mbox_num
);
300 /* first we read the mbox descriptor */
301 wl1271_read(wl
, wl
->mbox_ptr
[mbox_num
], &mbox
,
302 sizeof(struct event_mailbox
), false);
304 /* process the descriptor */
305 ret
= wl1271_event_process(wl
, &mbox
);
309 /* then we let the firmware know it can go on...*/
310 wl1271_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_EVENT_ACK
);