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); |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 41 | wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work); |
| 42 | vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv); |
| 43 | wl = wlvif->wl; |
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 | |
Eliad Peller | 74ec839 | 2011-10-05 11:56:02 +0200 | [diff] [blame] | 81 | wlvif->ps_poll_failures++; |
| 82 | if (wlvif->ps_poll_failures == 1) |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 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); |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 93 | ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work, |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 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 */ |
Eliad Peller | 74ec839 | 2011-10-05 11:56:02 +0200 | [diff] [blame] | 121 | wlvif->psm_entry_retry = 0; |
Juuso Oikarinen | 461fa13 | 2009-11-23 23:22:13 +0200 | [diff] [blame] | 122 | break; |
| 123 | } |
| 124 | |
Eliad Peller | 74ec839 | 2011-10-05 11:56:02 +0200 | [diff] [blame] | 125 | if (wlvif->psm_entry_retry < total_retries) { |
| 126 | wlvif->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."); |
Eliad Peller | 74ec839 | 2011-10-05 11:56:02 +0200 | [diff] [blame] | 132 | wlvif->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: |
Eliad Peller | 74ec839 | 2011-10-05 11:56:02 +0200 | [diff] [blame] | 137 | wlvif->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 | |
Eliad Peller | 6ec45dc | 2011-10-05 11:56:01 +0200 | [diff] [blame] | 152 | if (wlvif->ps_compl) { |
| 153 | complete(wlvif->ps_compl); |
| 154 | wlvif->ps_compl = NULL; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 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, |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 165 | struct wl12xx_vif *wlvif, |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 166 | struct event_mailbox *mbox) |
| 167 | { |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 168 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 169 | enum nl80211_cqm_rssi_threshold_event event; |
| 170 | s8 metric = mbox->rssi_snr_trigger_metric[0]; |
| 171 | |
| 172 | wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); |
| 173 | |
Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 174 | if (metric <= wlvif->rssi_thold) |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 175 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; |
| 176 | else |
| 177 | event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; |
| 178 | |
Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 179 | if (event != wlvif->last_rssi_event) |
| 180 | ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL); |
| 181 | wlvif->last_rssi_event = event; |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 182 | } |
| 183 | |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 184 | 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] | 185 | { |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 186 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 187 | |
Eliad Peller | 536129c8 | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 188 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 189 | if (!wlvif->sta.ba_rx_bitmap) |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 190 | return; |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 191 | ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap, |
| 192 | vif->bss_conf.bssid); |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 193 | } else { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 194 | u8 hlid; |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 195 | struct wl1271_link *lnk; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 196 | for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, |
| 197 | WL12XX_MAX_LINKS) { |
| 198 | lnk = &wl->links[hlid]; |
| 199 | if (!lnk->ba_bitmap) |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 200 | continue; |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 201 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 202 | ieee80211_stop_rx_ba_session(vif, |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 203 | lnk->ba_bitmap, |
| 204 | lnk->addr); |
| 205 | } |
| 206 | } |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 207 | } |
| 208 | |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 209 | static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl, |
| 210 | u8 enable) |
| 211 | { |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 212 | struct ieee80211_vif *vif; |
| 213 | struct wl12xx_vif *wlvif; |
| 214 | |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 215 | if (enable) { |
| 216 | /* disable dynamic PS when requested by the firmware */ |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 217 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 218 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 219 | ieee80211_disable_dyn_ps(vif); |
| 220 | } |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 221 | set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); |
| 222 | } else { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame^] | 223 | clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 224 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 225 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 226 | ieee80211_enable_dyn_ps(vif); |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame^] | 227 | wl1271_recalc_rx_streaming(wl, wlvif); |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 228 | } |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | } |
| 232 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 233 | static void wl1271_event_mbox_dump(struct event_mailbox *mbox) |
| 234 | { |
| 235 | wl1271_debug(DEBUG_EVENT, "MBOX DUMP:"); |
| 236 | wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector); |
| 237 | wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask); |
| 238 | } |
| 239 | |
| 240 | static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) |
| 241 | { |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 242 | struct ieee80211_vif *vif; |
| 243 | struct wl12xx_vif *wlvif; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 244 | int ret; |
| 245 | u32 vector; |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 246 | bool beacon_loss = false; |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 247 | bool disconnect_sta = false; |
| 248 | unsigned long sta_bitmap = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 249 | |
| 250 | wl1271_event_mbox_dump(mbox); |
| 251 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 252 | vector = le32_to_cpu(mbox->events_vector); |
| 253 | vector &= ~(le32_to_cpu(mbox->events_mask)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 254 | wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector); |
| 255 | |
| 256 | if (vector & SCAN_COMPLETE_EVENT_ID) { |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 257 | wl1271_debug(DEBUG_EVENT, "status: 0x%x", |
| 258 | mbox->scheduled_scan_status); |
| 259 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 260 | wl1271_scan_stm(wl, wl->scan_vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 261 | } |
| 262 | |
Luciano Coelho | 6394c01 | 2011-05-10 14:28:27 +0300 | [diff] [blame] | 263 | if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { |
| 264 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT " |
| 265 | "(status 0x%0x)", mbox->scheduled_scan_status); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 266 | |
| 267 | wl1271_scan_sched_scan_results(wl); |
Luciano Coelho | 6394c01 | 2011-05-10 14:28:27 +0300 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) { |
| 271 | wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT " |
| 272 | "(status 0x%0x)", mbox->scheduled_scan_status); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 273 | if (wl->sched_scanning) { |
| 274 | wl1271_scan_sched_scan_stop(wl); |
| 275 | ieee80211_sched_scan_stopped(wl->hw); |
| 276 | } |
Luciano Coelho | 6394c01 | 2011-05-10 14:28:27 +0300 | [diff] [blame] | 277 | } |
| 278 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 279 | if (vector & SOFT_GEMINI_SENSE_EVENT_ID) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 280 | wl12xx_event_soft_gemini_sense(wl, |
| 281 | mbox->soft_gemini_sense_info); |
Juuso Oikarinen | 8d2ef7b | 2010-07-08 17:50:03 +0300 | [diff] [blame] | 282 | |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 283 | /* |
| 284 | * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon |
| 285 | * filtering) is enabled. Without PSM, the stack will receive all |
| 286 | * beacons and can detect beacon loss by itself. |
Teemu Paasikivi | 64e29e44 | 2010-03-26 12:53:26 +0200 | [diff] [blame] | 287 | * |
| 288 | * As there's possibility that the driver disables PSM before receiving |
| 289 | * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. |
| 290 | * |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 291 | */ |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 292 | if (vector & BSS_LOSE_EVENT_ID) { |
| 293 | /* TODO: check for multi-role */ |
Juuso Oikarinen | 1a186a5 | 2010-04-01 11:38:23 +0300 | [diff] [blame] | 294 | wl1271_info("Beacon loss detected."); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 295 | |
Juuso Oikarinen | b771eee | 2009-10-08 21:56:34 +0300 | [diff] [blame] | 296 | /* indicate to the stack, that beacons have been lost */ |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 297 | beacon_loss = true; |
| 298 | } |
| 299 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 300 | if (vector & PS_REPORT_EVENT_ID) { |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 301 | wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 302 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 303 | ret = wl1271_event_ps_report(wl, wlvif, |
| 304 | mbox, &beacon_loss); |
| 305 | if (ret < 0) |
| 306 | return ret; |
| 307 | } |
Juuso Oikarinen | 19ad071 | 2009-11-02 20:22:11 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 310 | if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) |
| 311 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 312 | wl1271_event_pspoll_delivery_fail(wl, wlvif); |
| 313 | } |
Juuso Oikarinen | 90494a9 | 2010-07-08 17:50:00 +0300 | [diff] [blame] | 314 | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 315 | if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 316 | /* TODO: check actual multi-role support */ |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 317 | wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 318 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 319 | wl1271_event_rssi_trigger(wl, wlvif, mbox); |
| 320 | } |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 321 | } |
| 322 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 323 | if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) { |
| 324 | u8 role_id = mbox->role_id; |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 325 | wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. " |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 326 | "ba_allowed = 0x%x, role_id=%d", |
| 327 | mbox->rx_ba_allowed, role_id); |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 328 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 329 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 330 | if (role_id != 0xff && role_id != wlvif->role_id) |
| 331 | continue; |
Arik Nemtsov | f4d3b6a | 2011-08-25 12:43:16 +0300 | [diff] [blame] | 332 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 333 | wlvif->ba_allowed = !!mbox->rx_ba_allowed; |
| 334 | if (!wlvif->ba_allowed) |
| 335 | wl1271_stop_ba_event(wl, wlvif); |
| 336 | } |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 337 | } |
| 338 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 339 | if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) { |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 340 | wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. " |
| 341 | "status = 0x%x", |
| 342 | mbox->channel_switch_status); |
| 343 | /* |
| 344 | * That event uses for two cases: |
| 345 | * 1) channel switch complete with status=0 |
| 346 | * 2) channel switch failed status=1 |
| 347 | */ |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 348 | if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags)) { |
| 349 | /* TODO: configure only the relevant vif */ |
| 350 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 351 | struct ieee80211_vif *vif = |
| 352 | wl12xx_wlvif_to_vif(wlvif); |
| 353 | bool success = mbox->channel_switch_status ? |
| 354 | false : true; |
| 355 | |
| 356 | ieee80211_chswitch_done(vif, success); |
| 357 | } |
| 358 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 359 | } |
| 360 | |
Arik Nemtsov | 79ebec7 | 2011-08-14 13:17:18 +0300 | [diff] [blame] | 361 | if ((vector & DUMMY_PACKET_EVENT_ID)) { |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 362 | wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 363 | wl1271_tx_dummy_packet(wl); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 366 | /* |
| 367 | * "TX retries exceeded" has a different meaning according to mode. |
| 368 | * In AP mode the offending station is disconnected. |
| 369 | */ |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 370 | if (vector & MAX_TX_RETRY_EVENT_ID) { |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 371 | wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID"); |
| 372 | sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded); |
| 373 | disconnect_sta = true; |
| 374 | } |
| 375 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 376 | if (vector & INACTIVE_STA_EVENT_ID) { |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 377 | wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID"); |
| 378 | sta_bitmap |= le16_to_cpu(mbox->sta_aging_status); |
| 379 | disconnect_sta = true; |
| 380 | } |
| 381 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 382 | if (disconnect_sta) { |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 383 | u32 num_packets = wl->conf.tx.max_tx_retries; |
| 384 | struct ieee80211_sta *sta; |
| 385 | const u8 *addr; |
| 386 | int h; |
| 387 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 388 | for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) { |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 389 | bool found = false; |
| 390 | /* find the ap vif connected to this sta */ |
| 391 | wl12xx_for_each_wlvif_ap(wl, wlvif) { |
| 392 | if (!test_bit(h, wlvif->ap.sta_hlid_map)) |
| 393 | continue; |
| 394 | found = true; |
| 395 | break; |
| 396 | } |
| 397 | if (!found) |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 398 | continue; |
| 399 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 400 | vif = wl12xx_wlvif_to_vif(wlvif); |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 401 | addr = wl->links[h].addr; |
| 402 | |
| 403 | rcu_read_lock(); |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 404 | sta = ieee80211_find_sta(vif, addr); |
Arik Nemtsov | 3618f30 | 2011-06-26 10:36:03 +0300 | [diff] [blame] | 405 | if (sta) { |
| 406 | wl1271_debug(DEBUG_EVENT, "remove sta %d", h); |
| 407 | ieee80211_report_low_ack(sta, num_packets); |
| 408 | } |
| 409 | rcu_read_unlock(); |
| 410 | } |
| 411 | } |
| 412 | |
Eliad Peller | 4b730b6 | 2011-10-10 10:12:57 +0200 | [diff] [blame] | 413 | if (beacon_loss) |
| 414 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 415 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 416 | ieee80211_connection_loss(vif); |
| 417 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | int wl1271_event_unmask(struct wl1271 *wl) |
| 423 | { |
| 424 | int ret; |
| 425 | |
| 426 | ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask)); |
| 427 | if (ret < 0) |
| 428 | return ret; |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | void wl1271_event_mbox_config(struct wl1271 *wl) |
| 434 | { |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 435 | wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 436 | wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox); |
| 437 | |
| 438 | wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x", |
| 439 | wl->mbox_ptr[0], wl->mbox_ptr[1]); |
| 440 | } |
| 441 | |
Juuso Oikarinen | 13f2dc5 | 2009-12-11 15:40:59 +0200 | [diff] [blame] | 442 | int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 443 | { |
| 444 | struct event_mailbox mbox; |
| 445 | int ret; |
| 446 | |
| 447 | wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num); |
| 448 | |
| 449 | if (mbox_num > 1) |
| 450 | return -EINVAL; |
| 451 | |
| 452 | /* first we read the mbox descriptor */ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 453 | wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox, |
| 454 | sizeof(struct event_mailbox), false); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 455 | |
| 456 | /* process the descriptor */ |
| 457 | ret = wl1271_event_process(wl, &mbox); |
| 458 | if (ret < 0) |
| 459 | return ret; |
| 460 | |
| 461 | /* then we let the firmware know it can go on...*/ |
Teemu Paasikivi | 7b048c5 | 2010-02-18 13:25:55 +0200 | [diff] [blame] | 462 | wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |