Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 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 | |
| 24 | #include "wl1271.h" |
| 25 | #include "wl1271_reg.h" |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 26 | #include "wl1271_io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 27 | #include "wl1271_event.h" |
| 28 | #include "wl1271_ps.h" |
Juuso Oikarinen | 66497dc | 2009-10-08 21:56:30 +0300 | [diff] [blame] | 29 | #include "wl12xx_80211.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 30 | |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 31 | void wl1271_pspoll_work(struct work_struct *work) |
| 32 | { |
| 33 | struct delayed_work *dwork; |
| 34 | struct wl1271 *wl; |
| 35 | |
| 36 | dwork = container_of(work, struct delayed_work, work); |
| 37 | wl = container_of(dwork, struct wl1271, pspoll_work); |
| 38 | |
| 39 | wl1271_debug(DEBUG_EVENT, "pspoll work"); |
| 40 | |
| 41 | mutex_lock(&wl->mutex); |
| 42 | |
| 43 | if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) |
| 44 | goto out; |
| 45 | |
| 46 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) |
| 47 | goto out; |
| 48 | |
| 49 | /* |
| 50 | * if we end up here, then we were in powersave when the pspoll |
| 51 | * delivery failure occurred, and no-one changed state since, so |
| 52 | * we should go back to powersave. |
| 53 | */ |
| 54 | wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, true); |
| 55 | |
| 56 | out: |
| 57 | mutex_unlock(&wl->mutex); |
| 58 | }; |
| 59 | |
| 60 | static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl) |
| 61 | { |
| 62 | int delay = wl->conf.conn.ps_poll_recovery_period; |
| 63 | int ret; |
| 64 | |
| 65 | wl->ps_poll_failures++; |
| 66 | if (wl->ps_poll_failures == 1) |
| 67 | wl1271_info("AP with dysfunctional ps-poll, " |
| 68 | "trying to work around it."); |
| 69 | |
| 70 | /* force active mode receive data from the AP */ |
| 71 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
| 72 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, true); |
| 73 | if (ret < 0) |
| 74 | return; |
| 75 | set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); |
| 76 | ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, |
| 77 | msecs_to_jiffies(delay)); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * If already in active mode, lets we should be getting data from |
| 82 | * the AP right away. If we enter PSM too fast after this, and data |
| 83 | * remains on the AP, we will get another event like this, and we'll |
| 84 | * go into active once more. |
| 85 | */ |
| 86 | } |
| 87 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 88 | static int wl1271_event_scan_complete(struct wl1271 *wl, |
| 89 | struct event_mailbox *mbox) |
| 90 | { |
| 91 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", |
| 92 | mbox->scheduled_scan_status); |
| 93 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 94 | if (test_bit(WL1271_FLAG_SCANNING, &wl->flags)) { |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 95 | if (wl->scan.state == WL1271_SCAN_BAND_DUAL) { |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 96 | /* 2.4 GHz band scanned, scan 5 GHz band, pretend |
| 97 | * to the wl1271_cmd_scan function that we are not |
| 98 | * scanning as it checks that. |
| 99 | */ |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 100 | clear_bit(WL1271_FLAG_SCANNING, &wl->flags); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 101 | /* FIXME: ie missing! */ |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 102 | wl1271_cmd_scan(wl, wl->scan.ssid, wl->scan.ssid_len, |
Juuso Oikarinen | 4fb26fa | 2010-05-24 11:18:20 +0300 | [diff] [blame] | 103 | wl->scan.req, |
| 104 | wl->scan.active, |
| 105 | wl->scan.high_prio, |
| 106 | WL1271_SCAN_BAND_5_GHZ, |
| 107 | wl->scan.probe_requests); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 108 | } else { |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 109 | mutex_unlock(&wl->mutex); |
| 110 | ieee80211_scan_completed(wl->hw, false); |
| 111 | mutex_lock(&wl->mutex); |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 112 | clear_bit(WL1271_FLAG_SCANNING, &wl->flags); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 113 | } |
| 114 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 118 | static int wl1271_event_ps_report(struct wl1271 *wl, |
| 119 | struct event_mailbox *mbox, |
| 120 | bool *beacon_loss) |
| 121 | { |
| 122 | int ret = 0; |
| 123 | |
| 124 | wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status); |
| 125 | |
| 126 | switch (mbox->ps_status) { |
| 127 | case EVENT_ENTER_POWER_SAVE_FAIL: |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 128 | wl1271_debug(DEBUG_PSM, "PSM entry failed"); |
| 129 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 130 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 131 | /* remain in active mode */ |
Juuso Oikarinen | 461fa13 | 2009-11-23 23:22:13 +0200 | [diff] [blame] | 132 | wl->psm_entry_retry = 0; |
| 133 | break; |
| 134 | } |
| 135 | |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 136 | if (wl->psm_entry_retry < wl->conf.conn.psm_entry_retries) { |
| 137 | wl->psm_entry_retry++; |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 138 | ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, |
| 139 | true); |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 140 | } else { |
Juuso Oikarinen | 1a186a5 | 2010-04-01 11:38:23 +0300 | [diff] [blame] | 141 | wl1271_info("No ack to nullfunc from AP."); |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 142 | wl->psm_entry_retry = 0; |
Juuso Oikarinen | d60772f | 2010-03-26 12:53:29 +0200 | [diff] [blame] | 143 | *beacon_loss = true; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 144 | } |
| 145 | break; |
| 146 | case EVENT_ENTER_POWER_SAVE_SUCCESS: |
| 147 | wl->psm_entry_retry = 0; |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 148 | |
| 149 | /* enable beacon filtering */ |
| 150 | ret = wl1271_acx_beacon_filter_opt(wl, true); |
| 151 | if (ret < 0) |
| 152 | break; |
| 153 | |
| 154 | /* enable beacon early termination */ |
| 155 | ret = wl1271_acx_bet_enable(wl, true); |
| 156 | if (ret < 0) |
| 157 | break; |
| 158 | |
| 159 | /* go to extremely low power mode */ |
| 160 | wl1271_ps_elp_sleep(wl); |
| 161 | if (ret < 0) |
| 162 | break; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 163 | break; |
| 164 | case EVENT_EXIT_POWER_SAVE_FAIL: |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 165 | wl1271_debug(DEBUG_PSM, "PSM exit failed"); |
| 166 | |
| 167 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
| 168 | wl->psm_entry_retry = 0; |
| 169 | break; |
| 170 | } |
| 171 | |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 172 | /* make sure the firmware goes to active mode - the frame to |
| 173 | be sent next will indicate to the AP, that we are active. */ |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 174 | ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, |
| 175 | false); |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 176 | break; |
| 177 | case EVENT_EXIT_POWER_SAVE_SUCCESS: |
| 178 | default: |
| 179 | break; |
| 180 | } |
| 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 185 | static void wl1271_event_rssi_trigger(struct wl1271 *wl, |
| 186 | struct event_mailbox *mbox) |
| 187 | { |
| 188 | enum nl80211_cqm_rssi_threshold_event event; |
| 189 | s8 metric = mbox->rssi_snr_trigger_metric[0]; |
| 190 | |
| 191 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); |
| 192 | |
| 193 | if (metric <= wl->rssi_thold) |
| 194 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; |
| 195 | else |
| 196 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; |
| 197 | |
| 198 | if (event != wl->last_rssi_event) |
| 199 | ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); |
| 200 | wl->last_rssi_event = event; |
| 201 | } |
| 202 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 203 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) |
| 204 | { |
| 205 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); |
| 206 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); |
| 207 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); |
| 208 | } |
| 209 | |
| 210 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) |
| 211 | { |
| 212 | int ret; |
| 213 | u32 vector; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 214 | bool beacon_loss = false; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 215 | |
| 216 | wl1271_event_mbox_dump(mbox); |
| 217 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 218 | vector = le32_to_cpu(mbox->events_vector); |
| 219 | vector &= ~(le32_to_cpu(mbox->events_mask)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 220 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); |
| 221 | |
| 222 | if (vector & SCAN_COMPLETE_EVENT_ID) { |
| 223 | ret = wl1271_event_scan_complete(wl, mbox); |
| 224 | if (ret < 0) |
| 225 | return ret; |
| 226 | } |
| 227 | |
Juuso Oikarinen | 8d2ef7b | 2010-07-08 17:50:03 +0300 | [diff] [blame] | 228 | /* disable dynamic PS when requested by the firmware */ |
| 229 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID && |
| 230 | wl->bss_type == BSS_TYPE_STA_BSS) { |
| 231 | if (mbox->soft_gemini_sense_info) |
| 232 | ieee80211_disable_dyn_ps(wl->vif, true); |
| 233 | else |
| 234 | ieee80211_disable_dyn_ps(wl->vif, false); |
| 235 | } |
| 236 | |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 237 | /* |
| 238 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon |
| 239 | * filtering) is enabled. Without PSM, the stack will receive all |
| 240 | * beacons and can detect beacon loss by itself. |
Teemu Paasikivi | 64e29e44 | 2010-03-26 12:53:26 +0200 | [diff] [blame] | 241 | * |
| 242 | * As there's possibility that the driver disables PSM before receiving |
| 243 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. |
| 244 | * |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 245 | */ |
Teemu Paasikivi | 64e29e44 | 2010-03-26 12:53:26 +0200 | [diff] [blame] | 246 | if (vector & BSS_LOSE_EVENT_ID) { |
Juuso Oikarinen | 1a186a5 | 2010-04-01 11:38:23 +0300 | [diff] [blame] | 247 | wl1271_info("Beacon loss detected."); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 248 | |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 249 | /* indicate to the stack, that beacons have been lost */ |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 250 | beacon_loss = true; |
| 251 | } |
| 252 | |
| 253 | if (vector & PS_REPORT_EVENT_ID) { |
| 254 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); |
| 255 | ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); |
| 256 | if (ret < 0) |
| 257 | return ret; |
| 258 | } |
| 259 | |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 260 | if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) |
| 261 | wl1271_event_pspoll_delivery_fail(wl); |
| 262 | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 263 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { |
| 264 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); |
| 265 | if (wl->vif) |
| 266 | wl1271_event_rssi_trigger(wl, mbox); |
| 267 | } |
| 268 | |
Juuso Oikarinen | d60772f | 2010-03-26 12:53:29 +0200 | [diff] [blame] | 269 | if (wl->vif && beacon_loss) |
| 270 | ieee80211_connection_loss(wl->vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | int wl1271_event_unmask(struct wl1271 *wl) |
| 276 | { |
| 277 | int ret; |
| 278 | |
| 279 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); |
| 280 | if (ret < 0) |
| 281 | return ret; |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | void wl1271_event_mbox_config(struct wl1271 *wl) |
| 287 | { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 288 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 289 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); |
| 290 | |
| 291 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", |
| 292 | wl->mbox_ptr[0], wl->mbox_ptr[1]); |
| 293 | } |
| 294 | |
Juuso Oikarinen | 13f2dc5 | 2009-12-11 15:40:59 +0200 | [diff] [blame] | 295 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 296 | { |
| 297 | struct event_mailbox mbox; |
| 298 | int ret; |
| 299 | |
| 300 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); |
| 301 | |
| 302 | if (mbox_num > 1) |
| 303 | return -EINVAL; |
| 304 | |
| 305 | /* first we read the mbox descriptor */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 306 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, |
| 307 | sizeof(struct event_mailbox), false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 308 | |
| 309 | /* process the descriptor */ |
| 310 | ret = wl1271_event_process(wl, &mbox); |
| 311 | if (ret < 0) |
| 312 | return ret; |
| 313 | |
| 314 | /* then we let the firmware know it can go on...*/ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 315 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 316 | |
| 317 | return 0; |
| 318 | } |