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