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
25 #include "wl1271_reg.h"
26 #include "wl1271_io.h"
27 #include "wl1271_event.h"
28 #include "wl1271_ps.h"
29 #include "wl1271_scan.h"
30 #include "wl12xx_80211.h"
32 void wl1271_pspoll_work(struct work_struct *work)
34 struct delayed_work *dwork;
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1271, pspoll_work);
40 wl1271_debug(DEBUG_EVENT, "pspoll work");
42 mutex_lock(&wl->mutex);
44 if (unlikely(wl->state == WL1271_STATE_OFF))
47 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags))
50 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
54 * if we end up here, then we were in powersave when the pspoll
55 * delivery failure occurred, and no-one changed state since, so
56 * we should go back to powersave.
58 wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true);
61 mutex_unlock(&wl->mutex);
64 static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl)
66 int delay = wl->conf.conn.ps_poll_recovery_period;
69 wl->ps_poll_failures++;
70 if (wl->ps_poll_failures == 1)
71 wl1271_info("AP with dysfunctional ps-poll, "
72 "trying to work around it.");
74 /* force active mode receive data from the AP */
75 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
76 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
77 wl->basic_rate, true);
80 set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
81 ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work,
82 msecs_to_jiffies(delay));
86 * If already in active mode, lets we should be getting data from
87 * the AP right away. If we enter PSM too fast after this, and data
88 * remains on the AP, we will get another event like this, and we'll
89 * go into active once more.
93 static int wl1271_event_ps_report(struct wl1271 *wl,
94 struct event_mailbox *mbox,
98 u32 total_retries = wl->conf.conn.psm_entry_retries;
100 wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status);
102 switch (mbox->ps_status) {
103 case EVENT_ENTER_POWER_SAVE_FAIL:
104 wl1271_debug(DEBUG_PSM, "PSM entry failed");
106 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
107 /* remain in active mode */
108 wl->psm_entry_retry = 0;
112 if (wl->psm_entry_retry < total_retries) {
113 wl->psm_entry_retry++;
114 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
115 wl->basic_rate, true);
117 wl1271_info("No ack to nullfunc from AP.");
118 wl->psm_entry_retry = 0;
122 case EVENT_ENTER_POWER_SAVE_SUCCESS:
123 wl->psm_entry_retry = 0;
125 /* enable beacon filtering */
126 ret = wl1271_acx_beacon_filter_opt(wl, true);
130 /* enable beacon early termination */
131 ret = wl1271_acx_bet_enable(wl, true);
135 /* go to extremely low power mode */
136 wl1271_ps_elp_sleep(wl);
140 case EVENT_EXIT_POWER_SAVE_FAIL:
141 wl1271_debug(DEBUG_PSM, "PSM exit failed");
143 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
144 wl->psm_entry_retry = 0;
148 /* make sure the firmware goes to active mode - the frame to
149 be sent next will indicate to the AP, that we are active. */
150 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
151 wl->basic_rate, false);
153 case EVENT_EXIT_POWER_SAVE_SUCCESS:
161 static void wl1271_event_rssi_trigger(struct wl1271 *wl,
162 struct event_mailbox *mbox)
164 enum nl80211_cqm_rssi_threshold_event event;
165 s8 metric = mbox->rssi_snr_trigger_metric[0];
167 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
169 if (metric <= wl->rssi_thold)
170 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
172 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
174 if (event != wl->last_rssi_event)
175 ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL);
176 wl->last_rssi_event = event;
179 static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
181 wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
182 wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
183 wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
186 static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
190 bool beacon_loss = false;
192 wl1271_event_mbox_dump(mbox);
194 vector = le32_to_cpu(mbox->events_vector);
195 vector &= ~(le32_to_cpu(mbox->events_mask));
196 wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
198 if (vector & SCAN_COMPLETE_EVENT_ID) {
199 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
200 mbox->scheduled_scan_status);
205 /* disable dynamic PS when requested by the firmware */
206 if (vector & SOFT_GEMINI_SENSE_EVENT_ID &&
207 wl->bss_type == BSS_TYPE_STA_BSS) {
208 if (mbox->soft_gemini_sense_info)
209 ieee80211_disable_dyn_ps(wl->vif);
211 ieee80211_enable_dyn_ps(wl->vif);
215 * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
216 * filtering) is enabled. Without PSM, the stack will receive all
217 * beacons and can detect beacon loss by itself.
219 * As there's possibility that the driver disables PSM before receiving
220 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
223 if (vector & BSS_LOSE_EVENT_ID) {
224 wl1271_info("Beacon loss detected.");
226 /* indicate to the stack, that beacons have been lost */
230 if (vector & PS_REPORT_EVENT_ID) {
231 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
232 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss);
237 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
238 wl1271_event_pspoll_delivery_fail(wl);
240 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
241 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
243 wl1271_event_rssi_trigger(wl, mbox);
246 if (wl->vif && beacon_loss)
247 ieee80211_connection_loss(wl->vif);
252 int wl1271_event_unmask(struct wl1271 *wl)
256 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
263 void wl1271_event_mbox_config(struct wl1271 *wl)
265 wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
266 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
268 wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
269 wl->mbox_ptr[0], wl->mbox_ptr[1]);
272 int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
274 struct event_mailbox mbox;
277 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
282 /* first we read the mbox descriptor */
283 wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
284 sizeof(struct event_mailbox), false);
286 /* process the descriptor */
287 ret = wl1271_event_process(wl, &mbox);
291 /* then we let the firmware know it can go on...*/
292 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);