Commit | Line | Data |
---|---|---|
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 | ||
00d20100 SL |
24 | #include "wl12xx.h" |
25 | #include "reg.h" | |
26 | #include "io.h" | |
27 | #include "event.h" | |
28 | #include "ps.h" | |
29 | #include "scan.h" | |
66497dc3 | 30 | #include "wl12xx_80211.h" |
f5fc0f86 | 31 | |
90494a90 JO |
32 | void wl1271_pspoll_work(struct work_struct *work) |
33 | { | |
34 | struct delayed_work *dwork; | |
35 | struct wl1271 *wl; | |
36 | ||
37 | dwork = container_of(work, struct delayed_work, work); | |
38 | wl = container_of(dwork, struct wl1271, pspoll_work); | |
39 | ||
40 | wl1271_debug(DEBUG_EVENT, "pspoll work"); | |
41 | ||
42 | mutex_lock(&wl->mutex); | |
43 | ||
8c7f4f31 JO |
44 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
45 | goto out; | |
46 | ||
90494a90 JO |
47 | if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) |
48 | goto out; | |
49 | ||
50 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) | |
51 | goto out; | |
52 | ||
53 | /* | |
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. | |
57 | */ | |
65cddbf1 | 58 | wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true); |
90494a90 JO |
59 | |
60 | out: | |
61 | mutex_unlock(&wl->mutex); | |
62 | }; | |
63 | ||
64 | static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl) | |
65 | { | |
66 | int delay = wl->conf.conn.ps_poll_recovery_period; | |
67 | int ret; | |
68 | ||
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."); | |
73 | ||
74 | /* force active mode receive data from the AP */ | |
75 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { | |
65cddbf1 JO |
76 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, |
77 | wl->basic_rate, true); | |
90494a90 JO |
78 | if (ret < 0) |
79 | return; | |
80 | set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); | |
81 | ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, | |
82 | msecs_to_jiffies(delay)); | |
83 | } | |
84 | ||
85 | /* | |
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. | |
90 | */ | |
91 | } | |
92 | ||
19ad0715 JO |
93 | static int wl1271_event_ps_report(struct wl1271 *wl, |
94 | struct event_mailbox *mbox, | |
95 | bool *beacon_loss) | |
96 | { | |
97 | int ret = 0; | |
65cddbf1 | 98 | u32 total_retries = wl->conf.conn.psm_entry_retries; |
19ad0715 JO |
99 | |
100 | wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status); | |
101 | ||
102 | switch (mbox->ps_status) { | |
103 | case EVENT_ENTER_POWER_SAVE_FAIL: | |
d8c42c0c JO |
104 | wl1271_debug(DEBUG_PSM, "PSM entry failed"); |
105 | ||
71449f8d | 106 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
d8c42c0c | 107 | /* remain in active mode */ |
461fa136 JO |
108 | wl->psm_entry_retry = 0; |
109 | break; | |
110 | } | |
111 | ||
65cddbf1 | 112 | if (wl->psm_entry_retry < total_retries) { |
19ad0715 | 113 | wl->psm_entry_retry++; |
d8c42c0c | 114 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, |
8eab7b47 | 115 | wl->basic_rate, true); |
19ad0715 | 116 | } else { |
1a186a51 | 117 | wl1271_info("No ack to nullfunc from AP."); |
19ad0715 | 118 | wl->psm_entry_retry = 0; |
d60772f6 | 119 | *beacon_loss = true; |
19ad0715 JO |
120 | } |
121 | break; | |
122 | case EVENT_ENTER_POWER_SAVE_SUCCESS: | |
123 | wl->psm_entry_retry = 0; | |
d8c42c0c JO |
124 | |
125 | /* enable beacon filtering */ | |
126 | ret = wl1271_acx_beacon_filter_opt(wl, true); | |
127 | if (ret < 0) | |
128 | break; | |
129 | ||
130 | /* enable beacon early termination */ | |
131 | ret = wl1271_acx_bet_enable(wl, true); | |
132 | if (ret < 0) | |
133 | break; | |
134 | ||
135 | /* go to extremely low power mode */ | |
136 | wl1271_ps_elp_sleep(wl); | |
19ad0715 | 137 | break; |
19ad0715 JO |
138 | default: |
139 | break; | |
140 | } | |
141 | ||
142 | return ret; | |
143 | } | |
144 | ||
00236aed JO |
145 | static void wl1271_event_rssi_trigger(struct wl1271 *wl, |
146 | struct event_mailbox *mbox) | |
147 | { | |
148 | enum nl80211_cqm_rssi_threshold_event event; | |
149 | s8 metric = mbox->rssi_snr_trigger_metric[0]; | |
150 | ||
151 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); | |
152 | ||
153 | if (metric <= wl->rssi_thold) | |
154 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; | |
155 | else | |
156 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; | |
157 | ||
158 | if (event != wl->last_rssi_event) | |
159 | ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); | |
160 | wl->last_rssi_event = event; | |
161 | } | |
162 | ||
f5fc0f86 LC |
163 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) |
164 | { | |
165 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); | |
166 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); | |
167 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); | |
168 | } | |
169 | ||
170 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) | |
171 | { | |
172 | int ret; | |
173 | u32 vector; | |
19ad0715 | 174 | bool beacon_loss = false; |
203c903c | 175 | bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); |
f5fc0f86 LC |
176 | |
177 | wl1271_event_mbox_dump(mbox); | |
178 | ||
d0f63b20 LC |
179 | vector = le32_to_cpu(mbox->events_vector); |
180 | vector &= ~(le32_to_cpu(mbox->events_mask)); | |
f5fc0f86 LC |
181 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); |
182 | ||
183 | if (vector & SCAN_COMPLETE_EVENT_ID) { | |
34dd2aaa LC |
184 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", |
185 | mbox->scheduled_scan_status); | |
186 | ||
08688d6b | 187 | wl1271_scan_stm(wl); |
f5fc0f86 LC |
188 | } |
189 | ||
8d2ef7bd JO |
190 | /* disable dynamic PS when requested by the firmware */ |
191 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID && | |
192 | wl->bss_type == BSS_TYPE_STA_BSS) { | |
193 | if (mbox->soft_gemini_sense_info) | |
f532be6d | 194 | ieee80211_disable_dyn_ps(wl->vif); |
8d2ef7bd | 195 | else |
f532be6d | 196 | ieee80211_enable_dyn_ps(wl->vif); |
8d2ef7bd JO |
197 | } |
198 | ||
b771eee5 JO |
199 | /* |
200 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon | |
201 | * filtering) is enabled. Without PSM, the stack will receive all | |
202 | * beacons and can detect beacon loss by itself. | |
64e29e44 TP |
203 | * |
204 | * As there's possibility that the driver disables PSM before receiving | |
205 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. | |
206 | * | |
b771eee5 | 207 | */ |
203c903c | 208 | if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { |
1a186a51 | 209 | wl1271_info("Beacon loss detected."); |
f5fc0f86 | 210 | |
b771eee5 | 211 | /* indicate to the stack, that beacons have been lost */ |
19ad0715 JO |
212 | beacon_loss = true; |
213 | } | |
214 | ||
203c903c | 215 | if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { |
19ad0715 JO |
216 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); |
217 | ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); | |
218 | if (ret < 0) | |
219 | return ret; | |
220 | } | |
221 | ||
203c903c | 222 | if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) |
90494a90 JO |
223 | wl1271_event_pspoll_delivery_fail(wl); |
224 | ||
00236aed JO |
225 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { |
226 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); | |
227 | if (wl->vif) | |
228 | wl1271_event_rssi_trigger(wl, mbox); | |
229 | } | |
230 | ||
d60772f6 JO |
231 | if (wl->vif && beacon_loss) |
232 | ieee80211_connection_loss(wl->vif); | |
f5fc0f86 LC |
233 | |
234 | return 0; | |
235 | } | |
236 | ||
237 | int wl1271_event_unmask(struct wl1271 *wl) | |
238 | { | |
239 | int ret; | |
240 | ||
241 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); | |
242 | if (ret < 0) | |
243 | return ret; | |
244 | ||
245 | return 0; | |
246 | } | |
247 | ||
248 | void wl1271_event_mbox_config(struct wl1271 *wl) | |
249 | { | |
7b048c52 | 250 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
f5fc0f86 LC |
251 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); |
252 | ||
253 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", | |
254 | wl->mbox_ptr[0], wl->mbox_ptr[1]); | |
255 | } | |
256 | ||
13f2dc52 | 257 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) |
f5fc0f86 LC |
258 | { |
259 | struct event_mailbox mbox; | |
260 | int ret; | |
261 | ||
262 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); | |
263 | ||
264 | if (mbox_num > 1) | |
265 | return -EINVAL; | |
266 | ||
267 | /* first we read the mbox descriptor */ | |
7b048c52 TP |
268 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, |
269 | sizeof(struct event_mailbox), false); | |
f5fc0f86 LC |
270 | |
271 | /* process the descriptor */ | |
272 | ret = wl1271_event_process(wl, &mbox); | |
273 | if (ret < 0) | |
274 | return ret; | |
275 | ||
276 | /* then we let the firmware know it can go on...*/ | |
7b048c52 | 277 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); |
f5fc0f86 LC |
278 | |
279 | return 0; | |
280 | } |