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 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 24 | #include "wl12xx.h" |
| 25 | #include "reg.h" |
| 26 | #include "io.h" |
| 27 | #include "event.h" |
| 28 | #include "ps.h" |
| 29 | #include "scan.h" |
Juuso Oikarinen | 66497dc | 2009-10-08 21:56:30 +0300 | [diff] [blame] | 30 | #include "wl12xx_80211.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 31 | |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 32 | void wl1271_pspoll_work(struct work_struct *work) |
| 33 | { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 34 | struct ieee80211_vif *vif; |
| 35 | struct wl12xx_vif *wlvif; |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 36 | struct delayed_work *dwork; |
| 37 | struct wl1271 *wl; |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 38 | int ret; |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 39 | |
| 40 | dwork = container_of(work, struct delayed_work, work); |
| 41 | wl = container_of(dwork, struct wl1271, pspoll_work); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 42 | vif = wl->vif; /* TODO: move work into vif struct */ |
| 43 | wlvif = wl12xx_vif_to_data(vif); |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 44 | |
| 45 | wl1271_debug(DEBUG_EVENT, "pspoll work"); |
| 46 | |
| 47 | mutex_lock(&wl->mutex); |
| 48 | |
Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 49 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 50 | goto out; |
| 51 | |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 52 | if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) |
| 53 | goto out; |
| 54 | |
| 55 | if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) |
| 56 | goto out; |
| 57 | |
| 58 | /* |
| 59 | * if we end up here, then we were in powersave when the pspoll |
| 60 | * delivery failure occurred, and no-one changed state since, so |
| 61 | * we should go back to powersave. |
| 62 | */ |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 63 | ret = wl1271_ps_elp_wakeup(wl); |
| 64 | if (ret < 0) |
| 65 | goto out; |
| 66 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame^] | 67 | wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE, |
| 68 | wlvif->basic_rate, true); |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 69 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 70 | wl1271_ps_elp_sleep(wl); |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 71 | out: |
| 72 | mutex_unlock(&wl->mutex); |
| 73 | }; |
| 74 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 75 | static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl, |
| 76 | struct wl12xx_vif *wlvif) |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 77 | { |
| 78 | int delay = wl->conf.conn.ps_poll_recovery_period; |
| 79 | int ret; |
| 80 | |
| 81 | wl->ps_poll_failures++; |
| 82 | if (wl->ps_poll_failures == 1) |
| 83 | wl1271_info("AP with dysfunctional ps-poll, " |
| 84 | "trying to work around it."); |
| 85 | |
| 86 | /* force active mode receive data from the AP */ |
| 87 | if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame^] | 88 | ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 89 | wlvif->basic_rate, true); |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 90 | if (ret < 0) |
| 91 | return; |
| 92 | set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); |
| 93 | ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, |
| 94 | msecs_to_jiffies(delay)); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * If already in active mode, lets we should be getting data from |
| 99 | * the AP right away. If we enter PSM too fast after this, and data |
| 100 | * remains on the AP, we will get another event like this, and we'll |
| 101 | * go into active once more. |
| 102 | */ |
| 103 | } |
| 104 | |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 105 | static int wl1271_event_ps_report(struct wl1271 *wl, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 106 | struct wl12xx_vif *wlvif, |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 107 | struct event_mailbox *mbox, |
| 108 | bool *beacon_loss) |
| 109 | { |
| 110 | int ret = 0; |
Juuso Oikarinen | 65cddbf | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 111 | u32 total_retries = wl->conf.conn.psm_entry_retries; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 112 | |
| 113 | wl1271_debug(DEBUG_EVENT, "ps_status: 0x%x", mbox->ps_status); |
| 114 | |
| 115 | switch (mbox->ps_status) { |
| 116 | case EVENT_ENTER_POWER_SAVE_FAIL: |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 117 | wl1271_debug(DEBUG_PSM, "PSM entry failed"); |
| 118 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 119 | if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 120 | /* remain in active mode */ |
Juuso Oikarinen | 461fa13 | 2009-11-23 23:22:13 +0200 | [diff] [blame] | 121 | wl->psm_entry_retry = 0; |
| 122 | break; |
| 123 | } |
| 124 | |
Juuso Oikarinen | 65cddbf | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 125 | if (wl->psm_entry_retry < total_retries) { |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 126 | wl->psm_entry_retry++; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame^] | 127 | ret = wl1271_ps_set_mode(wl, wlvif, |
| 128 | STATION_POWER_SAVE_MODE, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 129 | wlvif->basic_rate, true); |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 130 | } else { |
Juuso Oikarinen | 1a186a5 | 2010-04-01 11:38:23 +0300 | [diff] [blame] | 131 | wl1271_info("No ack to nullfunc from AP."); |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 132 | wl->psm_entry_retry = 0; |
Juuso Oikarinen | d60772f | 2010-03-26 12:53:29 +0200 | [diff] [blame] | 133 | *beacon_loss = true; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 134 | } |
| 135 | break; |
| 136 | case EVENT_ENTER_POWER_SAVE_SUCCESS: |
| 137 | wl->psm_entry_retry = 0; |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 138 | |
| 139 | /* enable beacon filtering */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame^] | 140 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 141 | if (ret < 0) |
| 142 | break; |
| 143 | |
Shahar Levi | 0e44eb2 | 2011-05-16 15:35:30 +0300 | [diff] [blame] | 144 | /* |
| 145 | * BET has only a minor effect in 5GHz and masks |
| 146 | * channel switch IEs, so we only enable BET on 2.4GHz |
| 147 | */ |
| 148 | if (wl->band == IEEE80211_BAND_2GHZ) |
| 149 | /* enable beacon early termination */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame^] | 150 | ret = wl1271_acx_bet_enable(wl, wlvif, true); |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 151 | |
| 152 | if (wl->ps_compl) { |
| 153 | complete(wl->ps_compl); |
| 154 | wl->ps_compl = NULL; |
| 155 | } |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 156 | break; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | return ret; |
| 162 | } |
| 163 | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 164 | static void wl1271_event_rssi_trigger(struct wl1271 *wl, |
| 165 | struct event_mailbox *mbox) |
| 166 | { |
| 167 | enum nl80211_cqm_rssi_threshold_event event; |
| 168 | s8 metric = mbox->rssi_snr_trigger_metric[0]; |
| 169 | |
| 170 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); |
| 171 | |
| 172 | if (metric <= wl->rssi_thold) |
| 173 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; |
| 174 | else |
| 175 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; |
| 176 | |
| 177 | if (event != wl->last_rssi_event) |
| 178 | ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); |
| 179 | wl->last_rssi_event = event; |
| 180 | } |
| 181 | |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 182 | static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 183 | { |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 184 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 185 | if (!wl->ba_rx_bitmap) |
| 186 | return; |
| 187 | ieee80211_stop_rx_ba_session(wl->vif, wl->ba_rx_bitmap, |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 188 | wl->vif->bss_conf.bssid); |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 189 | } else { |
| 190 | int i; |
| 191 | struct wl1271_link *lnk; |
Arik Nemtsov | 6b66189 | 2011-09-22 09:52:06 +0300 | [diff] [blame] | 192 | for (i = WL1271_AP_STA_HLID_START; i < AP_MAX_LINKS; i++) { |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 193 | lnk = &wl->links[i]; |
| 194 | if (!wl1271_is_active_sta(wl, i) || !lnk->ba_bitmap) |
| 195 | continue; |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 196 | |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 197 | ieee80211_stop_rx_ba_session(wl->vif, |
| 198 | lnk->ba_bitmap, |
| 199 | lnk->addr); |
| 200 | } |
| 201 | } |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 202 | } |
| 203 | |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 204 | static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl, |
| 205 | u8 enable) |
| 206 | { |
| 207 | if (enable) { |
| 208 | /* disable dynamic PS when requested by the firmware */ |
| 209 | ieee80211_disable_dyn_ps(wl->vif); |
| 210 | set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); |
| 211 | } else { |
| 212 | ieee80211_enable_dyn_ps(wl->vif); |
| 213 | clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); |
| 214 | wl1271_recalc_rx_streaming(wl); |
| 215 | } |
| 216 | |
| 217 | } |
| 218 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 219 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) |
| 220 | { |
| 221 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); |
| 222 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); |
| 223 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); |
| 224 | } |
| 225 | |
| 226 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) |
| 227 | { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 228 | struct ieee80211_vif *vif = wl->vif; /* TODO: get as param */ |
| 229 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 230 | int ret; |
| 231 | u32 vector; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 232 | bool beacon_loss = false; |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 233 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 234 | bool disconnect_sta = false; |
| 235 | unsigned long sta_bitmap = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 236 | |
| 237 | wl1271_event_mbox_dump(mbox); |
| 238 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 239 | vector = le32_to_cpu(mbox->events_vector); |
| 240 | vector &= ~(le32_to_cpu(mbox->events_mask)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 241 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); |
| 242 | |
| 243 | if (vector & SCAN_COMPLETE_EVENT_ID) { |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 244 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", |
| 245 | mbox->scheduled_scan_status); |
| 246 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 247 | wl1271_scan_stm(wl, wl->scan_vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 248 | } |
| 249 | |
Luciano Coelho | 6394c01 | 2011-05-10 14:28:27 +0300 | [diff] [blame] | 250 | if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { |
| 251 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT " |
| 252 | "(status 0x%0x)", mbox->scheduled_scan_status); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 253 | |
| 254 | wl1271_scan_sched_scan_results(wl); |
Luciano Coelho | 6394c01 | 2011-05-10 14:28:27 +0300 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) { |
| 258 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT " |
| 259 | "(status 0x%0x)", mbox->scheduled_scan_status); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 260 | if (wl->sched_scanning) { |
| 261 | wl1271_scan_sched_scan_stop(wl); |
| 262 | ieee80211_sched_scan_stopped(wl->hw); |
| 263 | } |
Luciano Coelho | 6394c01 | 2011-05-10 14:28:27 +0300 | [diff] [blame] | 264 | } |
| 265 | |
Juuso Oikarinen | 8d2ef7b | 2010-07-08 17:50:03 +0300 | [diff] [blame] | 266 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID && |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 267 | wlvif->bss_type == BSS_TYPE_STA_BSS) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 268 | wl12xx_event_soft_gemini_sense(wl, |
| 269 | mbox->soft_gemini_sense_info); |
Juuso Oikarinen | 8d2ef7b | 2010-07-08 17:50:03 +0300 | [diff] [blame] | 270 | |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 271 | /* |
| 272 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon |
| 273 | * filtering) is enabled. Without PSM, the stack will receive all |
| 274 | * beacons and can detect beacon loss by itself. |
Teemu Paasikivi | 64e29e44 | 2010-03-26 12:53:26 +0200 | [diff] [blame] | 275 | * |
| 276 | * As there's possibility that the driver disables PSM before receiving |
| 277 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. |
| 278 | * |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 279 | */ |
Arik Nemtsov | 203c903 | 2010-10-25 11:17:44 +0200 | [diff] [blame] | 280 | if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { |
Juuso Oikarinen | 1a186a5 | 2010-04-01 11:38:23 +0300 | [diff] [blame] | 281 | wl1271_info("Beacon loss detected."); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 282 | |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 283 | /* indicate to the stack, that beacons have been lost */ |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 284 | beacon_loss = true; |
| 285 | } |
| 286 | |
Arik Nemtsov | 203c903 | 2010-10-25 11:17:44 +0200 | [diff] [blame] | 287 | if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 288 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 289 | ret = wl1271_event_ps_report(wl, wlvif, mbox, &beacon_loss); |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 290 | if (ret < 0) |
| 291 | return ret; |
| 292 | } |
| 293 | |
Arik Nemtsov | 203c903 | 2010-10-25 11:17:44 +0200 | [diff] [blame] | 294 | if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 295 | wl1271_event_pspoll_delivery_fail(wl, wlvif); |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 296 | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 297 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { |
| 298 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); |
| 299 | if (wl->vif) |
| 300 | wl1271_event_rssi_trigger(wl, mbox); |
| 301 | } |
| 302 | |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 303 | if ((vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)) { |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 304 | wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. " |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 305 | "ba_allowed = 0x%x", mbox->rx_ba_allowed); |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 306 | |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 307 | wl->ba_allowed = !!mbox->rx_ba_allowed; |
| 308 | |
| 309 | if (wl->vif && !wl->ba_allowed) |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 310 | wl1271_stop_ba_event(wl, wlvif); |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 311 | } |
| 312 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 313 | if ((vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) && !is_ap) { |
| 314 | wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. " |
| 315 | "status = 0x%x", |
| 316 | mbox->channel_switch_status); |
| 317 | /* |
| 318 | * That event uses for two cases: |
| 319 | * 1) channel switch complete with status=0 |
| 320 | * 2) channel switch failed status=1 |
| 321 | */ |
| 322 | if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags) && |
| 323 | (wl->vif)) |
| 324 | ieee80211_chswitch_done(wl->vif, |
| 325 | mbox->channel_switch_status ? false : true); |
| 326 | } |
| 327 | |
Arik Nemtsov | 79ebec7 | 2011-08-14 13:17:18 +0300 | [diff] [blame] | 328 | if ((vector & DUMMY_PACKET_EVENT_ID)) { |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 329 | wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); |
| 330 | if (wl->vif) |
| 331 | wl1271_tx_dummy_packet(wl); |
| 332 | } |
| 333 | |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 334 | /* |
| 335 | * "TX retries exceeded" has a different meaning according to mode. |
| 336 | * In AP mode the offending station is disconnected. |
| 337 | */ |
| 338 | if ((vector & MAX_TX_RETRY_EVENT_ID) && is_ap) { |
| 339 | wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID"); |
| 340 | sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded); |
| 341 | disconnect_sta = true; |
| 342 | } |
| 343 | |
| 344 | if ((vector & INACTIVE_STA_EVENT_ID) && is_ap) { |
| 345 | wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID"); |
| 346 | sta_bitmap |= le16_to_cpu(mbox->sta_aging_status); |
| 347 | disconnect_sta = true; |
| 348 | } |
| 349 | |
| 350 | if (is_ap && disconnect_sta) { |
| 351 | u32 num_packets = wl->conf.tx.max_tx_retries; |
| 352 | struct ieee80211_sta *sta; |
| 353 | const u8 *addr; |
| 354 | int h; |
| 355 | |
| 356 | for (h = find_first_bit(&sta_bitmap, AP_MAX_LINKS); |
| 357 | h < AP_MAX_LINKS; |
| 358 | h = find_next_bit(&sta_bitmap, AP_MAX_LINKS, h+1)) { |
| 359 | if (!wl1271_is_active_sta(wl, h)) |
| 360 | continue; |
| 361 | |
| 362 | addr = wl->links[h].addr; |
| 363 | |
| 364 | rcu_read_lock(); |
| 365 | sta = ieee80211_find_sta(wl->vif, addr); |
| 366 | if (sta) { |
| 367 | wl1271_debug(DEBUG_EVENT, "remove sta %d", h); |
| 368 | ieee80211_report_low_ack(sta, num_packets); |
| 369 | } |
| 370 | rcu_read_unlock(); |
| 371 | } |
| 372 | } |
| 373 | |
Juuso Oikarinen | d60772f | 2010-03-26 12:53:29 +0200 | [diff] [blame] | 374 | if (wl->vif && beacon_loss) |
| 375 | ieee80211_connection_loss(wl->vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | int wl1271_event_unmask(struct wl1271 *wl) |
| 381 | { |
| 382 | int ret; |
| 383 | |
| 384 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); |
| 385 | if (ret < 0) |
| 386 | return ret; |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | void wl1271_event_mbox_config(struct wl1271 *wl) |
| 392 | { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 393 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 394 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); |
| 395 | |
| 396 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", |
| 397 | wl->mbox_ptr[0], wl->mbox_ptr[1]); |
| 398 | } |
| 399 | |
Juuso Oikarinen | 13f2dc5 | 2009-12-11 15:40:59 +0200 | [diff] [blame] | 400 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 401 | { |
| 402 | struct event_mailbox mbox; |
| 403 | int ret; |
| 404 | |
| 405 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); |
| 406 | |
| 407 | if (mbox_num > 1) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | /* first we read the mbox descriptor */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 411 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, |
| 412 | sizeof(struct event_mailbox), false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 413 | |
| 414 | /* process the descriptor */ |
| 415 | ret = wl1271_event_process(wl, &mbox); |
| 416 | if (ret < 0) |
| 417 | return ret; |
| 418 | |
| 419 | /* then we let the firmware know it can go on...*/ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 420 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 421 | |
| 422 | return 0; |
| 423 | } |