Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 1 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2 | /* |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame] | 3 | * This file is part of wlcore |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4 | * |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 5 | * Copyright (C) 2008-2010 Nokia Corporation |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame] | 6 | * Copyright (C) 2011-2013 Texas Instruments Inc. |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 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 <linux/module.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 25 | #include <linux/firmware.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 26 | #include <linux/etherdevice.h> |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 27 | #include <linux/vmalloc.h> |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 28 | #include <linux/wl12xx.h> |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 30 | |
Luciano Coelho | c31be25 | 2011-11-21 19:25:24 +0200 | [diff] [blame] | 31 | #include "wlcore.h" |
Luciano Coelho | 0f4e312 | 2011-10-07 11:02:42 +0300 | [diff] [blame] | 32 | #include "debug.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 33 | #include "wl12xx_80211.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 34 | #include "io.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 35 | #include "tx.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 36 | #include "ps.h" |
| 37 | #include "init.h" |
| 38 | #include "debugfs.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 39 | #include "testmode.h" |
| 40 | #include "scan.h" |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 41 | #include "hw_ops.h" |
Luciano Coelho | 33cab57 | 2013-05-04 02:46:38 +0300 | [diff] [blame^] | 42 | #include "sysfs.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 43 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 44 | #define WL1271_BOOT_RETRIES 3 |
| 45 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 46 | static char *fwlog_param; |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 47 | static int bug_on_recovery = -1; |
| 48 | static int no_recovery = -1; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 49 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 50 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 51 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 52 | bool reset_tx_queues); |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 53 | static void wlcore_op_stop_locked(struct wl1271 *wl); |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 54 | static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 55 | |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame] | 56 | static int wl12xx_set_authorized(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 57 | { |
| 58 | int ret; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 59 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 60 | if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS)) |
| 61 | return -EINVAL; |
| 62 | |
| 63 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 64 | return 0; |
| 65 | |
Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 66 | if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 67 | return 0; |
| 68 | |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 69 | ret = wl12xx_cmd_set_peer_state(wl, wlvif, wlvif->sta.hlid); |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 70 | if (ret < 0) |
| 71 | return ret; |
| 72 | |
| 73 | wl1271_info("Association completed."); |
| 74 | return 0; |
| 75 | } |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 76 | |
Luis R. Rodriguez | 0c0280b | 2013-01-11 18:39:36 +0000 | [diff] [blame] | 77 | static void wl1271_reg_notify(struct wiphy *wiphy, |
| 78 | struct regulatory_request *request) |
Luciano Coelho | 573c67c | 2010-11-26 13:44:59 +0200 | [diff] [blame] | 79 | { |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 80 | struct ieee80211_supported_band *band; |
| 81 | struct ieee80211_channel *ch; |
| 82 | int i; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 83 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 84 | struct wl1271 *wl = hw->priv; |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 85 | |
| 86 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 87 | for (i = 0; i < band->n_channels; i++) { |
| 88 | ch = &band->channels[i]; |
| 89 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 90 | continue; |
| 91 | |
| 92 | if (ch->flags & IEEE80211_CHAN_RADAR) |
| 93 | ch->flags |= IEEE80211_CHAN_NO_IBSS | |
| 94 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 95 | |
| 96 | } |
| 97 | |
Arik Nemtsov | 75592be | 2013-03-12 17:19:45 +0200 | [diff] [blame] | 98 | wlcore_regdomain_config(wl); |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 101 | static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 102 | bool enable) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 103 | { |
| 104 | int ret = 0; |
| 105 | |
| 106 | /* we should hold wl->mutex */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 107 | ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 108 | if (ret < 0) |
| 109 | goto out; |
| 110 | |
| 111 | if (enable) |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 112 | set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 113 | else |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 114 | clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 115 | out: |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * this function is being called when the rx_streaming interval |
| 121 | * has beed changed or rx_streaming should be disabled |
| 122 | */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 123 | int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 124 | { |
| 125 | int ret = 0; |
| 126 | int period = wl->conf.rx_streaming.interval; |
| 127 | |
| 128 | /* don't reconfigure if rx_streaming is disabled */ |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 129 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 130 | goto out; |
| 131 | |
| 132 | /* reconfigure/disable according to new streaming_period */ |
| 133 | if (period && |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 134 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 135 | (wl->conf.rx_streaming.always || |
| 136 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 137 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 138 | else { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 139 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 140 | /* don't cancel_work_sync since we might deadlock */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 141 | del_timer_sync(&wlvif->rx_streaming_timer); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 142 | } |
| 143 | out: |
| 144 | return ret; |
| 145 | } |
| 146 | |
| 147 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) |
| 148 | { |
| 149 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 150 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 151 | rx_streaming_enable_work); |
| 152 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 153 | |
| 154 | mutex_lock(&wl->mutex); |
| 155 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 156 | if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) || |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 157 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 158 | (!wl->conf.rx_streaming.always && |
| 159 | !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
| 160 | goto out; |
| 161 | |
| 162 | if (!wl->conf.rx_streaming.interval) |
| 163 | goto out; |
| 164 | |
| 165 | ret = wl1271_ps_elp_wakeup(wl); |
| 166 | if (ret < 0) |
| 167 | goto out; |
| 168 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 169 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 170 | if (ret < 0) |
| 171 | goto out_sleep; |
| 172 | |
| 173 | /* stop it after some time of inactivity */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 174 | mod_timer(&wlvif->rx_streaming_timer, |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 175 | jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); |
| 176 | |
| 177 | out_sleep: |
| 178 | wl1271_ps_elp_sleep(wl); |
| 179 | out: |
| 180 | mutex_unlock(&wl->mutex); |
| 181 | } |
| 182 | |
| 183 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) |
| 184 | { |
| 185 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 186 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 187 | rx_streaming_disable_work); |
| 188 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 189 | |
| 190 | mutex_lock(&wl->mutex); |
| 191 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 192 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 193 | goto out; |
| 194 | |
| 195 | ret = wl1271_ps_elp_wakeup(wl); |
| 196 | if (ret < 0) |
| 197 | goto out; |
| 198 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 199 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 200 | if (ret) |
| 201 | goto out_sleep; |
| 202 | |
| 203 | out_sleep: |
| 204 | wl1271_ps_elp_sleep(wl); |
| 205 | out: |
| 206 | mutex_unlock(&wl->mutex); |
| 207 | } |
| 208 | |
| 209 | static void wl1271_rx_streaming_timer(unsigned long data) |
| 210 | { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 211 | struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data; |
| 212 | struct wl1271 *wl = wlvif->wl; |
| 213 | ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 214 | } |
| 215 | |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 216 | /* wl->mutex must be taken */ |
| 217 | void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl) |
| 218 | { |
| 219 | /* if the watchdog is not armed, don't do anything */ |
| 220 | if (wl->tx_allocated_blocks == 0) |
| 221 | return; |
| 222 | |
| 223 | cancel_delayed_work(&wl->tx_watchdog_work); |
| 224 | ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work, |
| 225 | msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout)); |
| 226 | } |
| 227 | |
| 228 | static void wl12xx_tx_watchdog_work(struct work_struct *work) |
| 229 | { |
| 230 | struct delayed_work *dwork; |
| 231 | struct wl1271 *wl; |
| 232 | |
| 233 | dwork = container_of(work, struct delayed_work, work); |
| 234 | wl = container_of(dwork, struct wl1271, tx_watchdog_work); |
| 235 | |
| 236 | mutex_lock(&wl->mutex); |
| 237 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 238 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 239 | goto out; |
| 240 | |
| 241 | /* Tx went out in the meantime - everything is ok */ |
| 242 | if (unlikely(wl->tx_allocated_blocks == 0)) |
| 243 | goto out; |
| 244 | |
| 245 | /* |
| 246 | * if a ROC is in progress, we might not have any Tx for a long |
| 247 | * time (e.g. pending Tx on the non-ROC channels) |
| 248 | */ |
| 249 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { |
| 250 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC", |
| 251 | wl->conf.tx.tx_watchdog_timeout); |
| 252 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 253 | goto out; |
| 254 | } |
| 255 | |
| 256 | /* |
| 257 | * if a scan is in progress, we might not have any Tx for a long |
| 258 | * time |
| 259 | */ |
| 260 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { |
| 261 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan", |
| 262 | wl->conf.tx.tx_watchdog_timeout); |
| 263 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 264 | goto out; |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * AP might cache a frame for a long time for a sleeping station, |
| 269 | * so rearm the timer if there's an AP interface with stations. If |
| 270 | * Tx is genuinely stuck we will most hopefully discover it when all |
| 271 | * stations are removed due to inactivity. |
| 272 | */ |
| 273 | if (wl->active_sta_count) { |
| 274 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has " |
| 275 | " %d stations", |
| 276 | wl->conf.tx.tx_watchdog_timeout, |
| 277 | wl->active_sta_count); |
| 278 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 279 | goto out; |
| 280 | } |
| 281 | |
| 282 | wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery", |
| 283 | wl->conf.tx.tx_watchdog_timeout); |
| 284 | wl12xx_queue_recovery_work(wl); |
| 285 | |
| 286 | out: |
| 287 | mutex_unlock(&wl->mutex); |
| 288 | } |
| 289 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 290 | static void wlcore_adjust_conf(struct wl1271 *wl) |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 291 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 292 | /* Adjust settings according to optional module parameters */ |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 293 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 294 | if (fwlog_param) { |
| 295 | if (!strcmp(fwlog_param, "continuous")) { |
| 296 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 297 | } else if (!strcmp(fwlog_param, "ondemand")) { |
| 298 | wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; |
| 299 | } else if (!strcmp(fwlog_param, "dbgpins")) { |
| 300 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 301 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; |
| 302 | } else if (!strcmp(fwlog_param, "disable")) { |
| 303 | wl->conf.fwlog.mem_blocks = 0; |
| 304 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; |
| 305 | } else { |
| 306 | wl1271_error("Unknown fwlog parameter %s", fwlog_param); |
| 307 | } |
| 308 | } |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 309 | |
| 310 | if (bug_on_recovery != -1) |
| 311 | wl->conf.recovery.bug_on_recovery = (u8) bug_on_recovery; |
| 312 | |
| 313 | if (no_recovery != -1) |
| 314 | wl->conf.recovery.no_recovery = (u8) no_recovery; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 315 | } |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 316 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 317 | static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, |
| 318 | struct wl12xx_vif *wlvif, |
| 319 | u8 hlid, u8 tx_pkts) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 320 | { |
Arik Nemtsov | 37c68ea | 2013-03-12 17:19:36 +0200 | [diff] [blame] | 321 | bool fw_ps; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 322 | |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 323 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
| 324 | |
| 325 | /* |
| 326 | * Wake up from high level PS if the STA is asleep with too little |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 327 | * packets in FW or if the STA is awake. |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 328 | */ |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 329 | if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 330 | wl12xx_ps_link_end(wl, wlvif, hlid); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 331 | |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 332 | /* |
| 333 | * Start high-level PS if the STA is asleep with enough blocks in FW. |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 334 | * Make an exception if this is the only connected link. In this |
| 335 | * case FW-memory congestion is less of a problem. |
Arik Nemtsov | 37c68ea | 2013-03-12 17:19:36 +0200 | [diff] [blame] | 336 | * Note that a single connected STA means 3 active links, since we must |
| 337 | * account for the global and broadcast AP links. The "fw_ps" check |
| 338 | * assures us the third link is a STA connected to the AP. Otherwise |
| 339 | * the FW would not set the PSM bit. |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 340 | */ |
Arik Nemtsov | 37c68ea | 2013-03-12 17:19:36 +0200 | [diff] [blame] | 341 | else if (wl->active_link_count > 3 && fw_ps && |
| 342 | tx_pkts >= WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 343 | wl12xx_ps_link_start(wl, wlvif, hlid, true); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 346 | static void wl12xx_irq_update_links_status(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 347 | struct wl12xx_vif *wlvif, |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 348 | struct wl_fw_status_2 *status) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 349 | { |
| 350 | u32 cur_fw_ps_map; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 351 | u8 hlid; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 352 | |
| 353 | cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); |
| 354 | if (wl->ap_fw_ps_map != cur_fw_ps_map) { |
| 355 | wl1271_debug(DEBUG_PSM, |
| 356 | "link ps prev 0x%x cur 0x%x changed 0x%x", |
| 357 | wl->ap_fw_ps_map, cur_fw_ps_map, |
| 358 | wl->ap_fw_ps_map ^ cur_fw_ps_map); |
| 359 | |
| 360 | wl->ap_fw_ps_map = cur_fw_ps_map; |
| 361 | } |
| 362 | |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 363 | for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 364 | wl12xx_irq_ps_regulate_link(wl, wlvif, hlid, |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 365 | wl->links[hlid].allocated_pkts); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 366 | } |
| 367 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 368 | static int wlcore_fw_status(struct wl1271 *wl, |
| 369 | struct wl_fw_status_1 *status_1, |
| 370 | struct wl_fw_status_2 *status_2) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 371 | { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 372 | struct wl12xx_vif *wlvif; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 373 | struct timespec ts; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 374 | u32 old_tx_blk_count = wl->tx_blocks_available; |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 375 | int avail, freed_blocks; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 376 | int i; |
Arik Nemtsov | 6bac40a | 2011-12-12 12:08:25 +0200 | [diff] [blame] | 377 | size_t status_len; |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 378 | int ret; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 379 | struct wl1271_link *lnk; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 380 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 381 | status_len = WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) + |
| 382 | sizeof(*status_2) + wl->fw_status_priv_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 383 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 384 | ret = wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status_1, |
| 385 | status_len, false); |
| 386 | if (ret < 0) |
| 387 | return ret; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 388 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 389 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " |
| 390 | "drv_rx_counter = %d, tx_results_counter = %d)", |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 391 | status_1->intr, |
| 392 | status_1->fw_rx_counter, |
| 393 | status_1->drv_rx_counter, |
| 394 | status_1->tx_results_counter); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 395 | |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 396 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 397 | /* prevent wrap-around in freed-packets counter */ |
Arik Nemtsov | 742246f | 2011-08-14 13:17:33 +0300 | [diff] [blame] | 398 | wl->tx_allocated_pkts[i] -= |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 399 | (status_2->counters.tx_released_pkts[i] - |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 400 | wl->tx_pkts_freed[i]) & 0xff; |
| 401 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 402 | wl->tx_pkts_freed[i] = status_2->counters.tx_released_pkts[i]; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 403 | } |
| 404 | |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 405 | |
| 406 | for_each_set_bit(i, wl->links_map, WL12XX_MAX_LINKS) { |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 407 | u8 diff; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 408 | lnk = &wl->links[i]; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 409 | |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 410 | /* prevent wrap-around in freed-packets counter */ |
| 411 | diff = (status_2->counters.tx_lnk_free_pkts[i] - |
| 412 | lnk->prev_freed_pkts) & 0xff; |
| 413 | |
| 414 | if (diff == 0) |
| 415 | continue; |
| 416 | |
| 417 | lnk->allocated_pkts -= diff; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 418 | lnk->prev_freed_pkts = status_2->counters.tx_lnk_free_pkts[i]; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 419 | |
| 420 | /* accumulate the prev_freed_pkts counter */ |
| 421 | lnk->total_freed_pkts += diff; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 422 | } |
| 423 | |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 424 | /* prevent wrap-around in total blocks counter */ |
| 425 | if (likely(wl->tx_blocks_freed <= |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 426 | le32_to_cpu(status_2->total_released_blks))) |
| 427 | freed_blocks = le32_to_cpu(status_2->total_released_blks) - |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 428 | wl->tx_blocks_freed; |
| 429 | else |
| 430 | freed_blocks = 0x100000000LL - wl->tx_blocks_freed + |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 431 | le32_to_cpu(status_2->total_released_blks); |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 432 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 433 | wl->tx_blocks_freed = le32_to_cpu(status_2->total_released_blks); |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 434 | |
Arik Nemtsov | 7bb5d6c | 2011-08-14 13:17:00 +0300 | [diff] [blame] | 435 | wl->tx_allocated_blocks -= freed_blocks; |
| 436 | |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 437 | /* |
| 438 | * If the FW freed some blocks: |
| 439 | * If we still have allocated blocks - re-arm the timer, Tx is |
| 440 | * not stuck. Otherwise, cancel the timer (no Tx currently). |
| 441 | */ |
| 442 | if (freed_blocks) { |
| 443 | if (wl->tx_allocated_blocks) |
| 444 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 445 | else |
| 446 | cancel_delayed_work(&wl->tx_watchdog_work); |
| 447 | } |
| 448 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 449 | avail = le32_to_cpu(status_2->tx_total) - wl->tx_allocated_blocks; |
Ido Yariv | d2f4d47 | 2011-03-31 10:07:00 +0200 | [diff] [blame] | 450 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 451 | /* |
| 452 | * The FW might change the total number of TX memblocks before |
| 453 | * we get a notification about blocks being released. Thus, the |
| 454 | * available blocks calculation might yield a temporary result |
| 455 | * which is lower than the actual available blocks. Keeping in |
| 456 | * mind that only blocks that were allocated can be moved from |
| 457 | * TX to RX, tx_blocks_available should never decrease here. |
| 458 | */ |
| 459 | wl->tx_blocks_available = max((int)wl->tx_blocks_available, |
| 460 | avail); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 461 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 462 | /* if more blocks are available now, tx work can be scheduled */ |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 463 | if (wl->tx_blocks_available > old_tx_blk_count) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 464 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 465 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 466 | /* for AP update num of allocated TX blocks per link and ps status */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 467 | wl12xx_for_each_wlvif_ap(wl, wlvif) { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 468 | wl12xx_irq_update_links_status(wl, wlvif, status_2); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 469 | } |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 470 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 471 | /* update the host-chipset time offset */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 472 | getnstimeofday(&ts); |
| 473 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 474 | (s64)le32_to_cpu(status_2->fw_localtime); |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 475 | |
Arik Nemtsov | 0e81047 | 2012-11-27 08:45:00 +0200 | [diff] [blame] | 476 | wl->fw_fast_lnk_map = le32_to_cpu(status_2->link_fast_bitmap); |
| 477 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 478 | return 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 479 | } |
| 480 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 481 | static void wl1271_flush_deferred_work(struct wl1271 *wl) |
| 482 | { |
| 483 | struct sk_buff *skb; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 484 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 485 | /* Pass all received frames to the network stack */ |
| 486 | while ((skb = skb_dequeue(&wl->deferred_rx_queue))) |
| 487 | ieee80211_rx_ni(wl->hw, skb); |
| 488 | |
| 489 | /* Return sent skbs to the network stack */ |
| 490 | while ((skb = skb_dequeue(&wl->deferred_tx_queue))) |
Eliad Peller | c27d3ac | 2011-06-07 10:40:39 +0300 | [diff] [blame] | 491 | ieee80211_tx_status_ni(wl->hw, skb); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static void wl1271_netstack_work(struct work_struct *work) |
| 495 | { |
| 496 | struct wl1271 *wl = |
| 497 | container_of(work, struct wl1271, netstack_work); |
| 498 | |
| 499 | do { |
| 500 | wl1271_flush_deferred_work(wl); |
| 501 | } while (skb_queue_len(&wl->deferred_rx_queue)); |
| 502 | } |
| 503 | |
| 504 | #define WL1271_IRQ_MAX_LOOPS 256 |
| 505 | |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 506 | static int wlcore_irq_locked(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 507 | { |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 508 | int ret = 0; |
Juuso Oikarinen | c15f63b | 2009-10-12 15:08:50 +0300 | [diff] [blame] | 509 | u32 intr; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 510 | int loopcount = WL1271_IRQ_MAX_LOOPS; |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 511 | bool done = false; |
| 512 | unsigned int defer_count; |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 513 | unsigned long flags; |
| 514 | |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 515 | /* |
| 516 | * In case edge triggered interrupt must be used, we cannot iterate |
| 517 | * more than once without introducing race conditions with the hardirq. |
| 518 | */ |
| 519 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 520 | loopcount = 1; |
| 521 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 522 | wl1271_debug(DEBUG_IRQ, "IRQ work"); |
| 523 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 524 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 525 | goto out; |
| 526 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 527 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 528 | if (ret < 0) |
| 529 | goto out; |
| 530 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 531 | while (!done && loopcount--) { |
| 532 | /* |
| 533 | * In order to avoid a race with the hardirq, clear the flag |
| 534 | * before acknowledging the chip. Since the mutex is held, |
| 535 | * wl1271_ps_elp_wakeup cannot be called concurrently. |
| 536 | */ |
| 537 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 538 | smp_mb__after_clear_bit(); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 539 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 540 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 541 | if (ret < 0) |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 542 | goto out; |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 543 | |
| 544 | wlcore_hw_tx_immediate_compl(wl); |
| 545 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 546 | intr = le32_to_cpu(wl->fw_status_1->intr); |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 547 | intr &= WLCORE_ALL_INTR_MASK; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 548 | if (!intr) { |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 549 | done = true; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 550 | continue; |
| 551 | } |
| 552 | |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 553 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 554 | wl1271_error("HW watchdog interrupt received! starting recovery."); |
| 555 | wl->watchdog_recovery = true; |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 556 | ret = -EIO; |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 557 | |
| 558 | /* restarting the chip. ignore any other interrupt. */ |
| 559 | goto out; |
| 560 | } |
| 561 | |
| 562 | if (unlikely(intr & WL1271_ACX_SW_INTR_WATCHDOG)) { |
| 563 | wl1271_error("SW watchdog interrupt received! " |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 564 | "starting recovery."); |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 565 | wl->watchdog_recovery = true; |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 566 | ret = -EIO; |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 567 | |
| 568 | /* restarting the chip. ignore any other interrupt. */ |
| 569 | goto out; |
| 570 | } |
| 571 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 572 | if (likely(intr & WL1271_ACX_INTR_DATA)) { |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 573 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); |
| 574 | |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 575 | ret = wlcore_rx(wl, wl->fw_status_1); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 576 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 577 | goto out; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 578 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 579 | /* Check if any tx blocks were freed */ |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 580 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 581 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 582 | wl1271_tx_total_queue_count(wl) > 0) { |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 583 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 584 | /* |
| 585 | * In order to avoid starvation of the TX path, |
| 586 | * call the work function directly. |
| 587 | */ |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 588 | ret = wlcore_tx_work_locked(wl); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 589 | if (ret < 0) |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 590 | goto out; |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 591 | } else { |
| 592 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 593 | } |
| 594 | |
Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 595 | /* check for tx results */ |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 596 | ret = wlcore_hw_tx_delayed_compl(wl); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 597 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 598 | goto out; |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 599 | |
| 600 | /* Make sure the deferred queues don't get too long */ |
| 601 | defer_count = skb_queue_len(&wl->deferred_tx_queue) + |
| 602 | skb_queue_len(&wl->deferred_rx_queue); |
| 603 | if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) |
| 604 | wl1271_flush_deferred_work(wl); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | if (intr & WL1271_ACX_INTR_EVENT_A) { |
| 608 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 609 | ret = wl1271_event_handle(wl, 0); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 610 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 611 | goto out; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | if (intr & WL1271_ACX_INTR_EVENT_B) { |
| 615 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 616 | ret = wl1271_event_handle(wl, 1); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 617 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 618 | goto out; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
| 622 | wl1271_debug(DEBUG_IRQ, |
| 623 | "WL1271_ACX_INTR_INIT_COMPLETE"); |
| 624 | |
| 625 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
| 626 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 627 | } |
| 628 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 629 | wl1271_ps_elp_sleep(wl); |
| 630 | |
| 631 | out: |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | static irqreturn_t wlcore_irq(int irq, void *cookie) |
| 636 | { |
| 637 | int ret; |
| 638 | unsigned long flags; |
| 639 | struct wl1271 *wl = cookie; |
| 640 | |
Luciano Coelho | 97236a0 | 2013-03-08 09:41:53 +0200 | [diff] [blame] | 641 | /* complete the ELP completion */ |
| 642 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 643 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 644 | if (wl->elp_compl) { |
| 645 | complete(wl->elp_compl); |
| 646 | wl->elp_compl = NULL; |
| 647 | } |
| 648 | |
| 649 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { |
| 650 | /* don't enqueue a work right now. mark it as pending */ |
| 651 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); |
| 652 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); |
| 653 | disable_irq_nosync(wl->irq); |
| 654 | pm_wakeup_event(wl->dev, 0); |
| 655 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 656 | return IRQ_HANDLED; |
| 657 | } |
| 658 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 659 | |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 660 | /* TX might be handled here, avoid redundant work */ |
| 661 | set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 662 | cancel_work_sync(&wl->tx_work); |
| 663 | |
| 664 | mutex_lock(&wl->mutex); |
| 665 | |
| 666 | ret = wlcore_irq_locked(wl); |
| 667 | if (ret) |
| 668 | wl12xx_queue_recovery_work(wl); |
| 669 | |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 670 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 671 | /* In case TX was not handled here, queue TX work */ |
| 672 | clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 673 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 674 | wl1271_tx_total_queue_count(wl) > 0) |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 675 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
| 676 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 677 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 678 | mutex_unlock(&wl->mutex); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 679 | |
| 680 | return IRQ_HANDLED; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 681 | } |
| 682 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 683 | struct vif_counter_data { |
| 684 | u8 counter; |
| 685 | |
| 686 | struct ieee80211_vif *cur_vif; |
| 687 | bool cur_vif_running; |
| 688 | }; |
| 689 | |
| 690 | static void wl12xx_vif_count_iter(void *data, u8 *mac, |
| 691 | struct ieee80211_vif *vif) |
| 692 | { |
| 693 | struct vif_counter_data *counter = data; |
| 694 | |
| 695 | counter->counter++; |
| 696 | if (counter->cur_vif == vif) |
| 697 | counter->cur_vif_running = true; |
| 698 | } |
| 699 | |
| 700 | /* caller must not hold wl->mutex, as it might deadlock */ |
| 701 | static void wl12xx_get_vif_count(struct ieee80211_hw *hw, |
| 702 | struct ieee80211_vif *cur_vif, |
| 703 | struct vif_counter_data *data) |
| 704 | { |
| 705 | memset(data, 0, sizeof(*data)); |
| 706 | data->cur_vif = cur_vif; |
| 707 | |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 708 | ieee80211_iterate_active_interfaces(hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 709 | wl12xx_vif_count_iter, data); |
| 710 | } |
| 711 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 712 | static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 713 | { |
| 714 | const struct firmware *fw; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 715 | const char *fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 716 | enum wl12xx_fw_type fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 717 | int ret; |
| 718 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 719 | if (plt) { |
| 720 | fw_type = WL12XX_FW_TYPE_PLT; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 721 | fw_name = wl->plt_fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 722 | } else { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 723 | /* |
| 724 | * we can't call wl12xx_get_vif_count() here because |
| 725 | * wl->mutex is taken, so use the cached last_vif_count value |
| 726 | */ |
Eliad Peller | 9b1a0a7 | 2012-07-25 14:22:21 +0300 | [diff] [blame] | 727 | if (wl->last_vif_count > 1 && wl->mr_fw_name) { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 728 | fw_type = WL12XX_FW_TYPE_MULTI; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 729 | fw_name = wl->mr_fw_name; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 730 | } else { |
| 731 | fw_type = WL12XX_FW_TYPE_NORMAL; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 732 | fw_name = wl->sr_fw_name; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 733 | } |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | if (wl->fw_type == fw_type) |
| 737 | return 0; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 738 | |
| 739 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); |
| 740 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 741 | ret = request_firmware(&fw, fw_name, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 742 | |
| 743 | if (ret < 0) { |
Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 744 | wl1271_error("could not get firmware %s: %d", fw_name, ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 745 | return ret; |
| 746 | } |
| 747 | |
| 748 | if (fw->size % 4) { |
| 749 | wl1271_error("firmware size is not multiple of 32 bits: %zu", |
| 750 | fw->size); |
| 751 | ret = -EILSEQ; |
| 752 | goto out; |
| 753 | } |
| 754 | |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 755 | vfree(wl->fw); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 756 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 757 | wl->fw_len = fw->size; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 758 | wl->fw = vmalloc(wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 759 | |
| 760 | if (!wl->fw) { |
| 761 | wl1271_error("could not allocate memory for the firmware"); |
| 762 | ret = -ENOMEM; |
| 763 | goto out; |
| 764 | } |
| 765 | |
| 766 | memcpy(wl->fw, fw->data, wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 767 | ret = 0; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 768 | wl->fw_type = fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 769 | out: |
| 770 | release_firmware(fw); |
| 771 | |
| 772 | return ret; |
| 773 | } |
| 774 | |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 775 | void wl12xx_queue_recovery_work(struct wl1271 *wl) |
| 776 | { |
Eyal Shapira | 680c605 | 2012-06-26 10:41:17 +0300 | [diff] [blame] | 777 | WARN_ON(!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); |
| 778 | |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 779 | /* Avoid a recursive recovery */ |
Ido Yariv | 792a58a | 2012-08-15 15:09:30 +0300 | [diff] [blame] | 780 | if (wl->state == WLCORE_STATE_ON) { |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 781 | wl->state = WLCORE_STATE_RESTARTING; |
Ido Yariv | 792a58a | 2012-08-15 15:09:30 +0300 | [diff] [blame] | 782 | set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 783 | wlcore_disable_interrupts_nosync(wl); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 784 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 785 | } |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 786 | } |
| 787 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 788 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) |
| 789 | { |
| 790 | size_t len = 0; |
| 791 | |
| 792 | /* The FW log is a length-value list, find where the log end */ |
| 793 | while (len < maxlen) { |
| 794 | if (memblock[len] == 0) |
| 795 | break; |
| 796 | if (len + memblock[len] + 1 > maxlen) |
| 797 | break; |
| 798 | len += memblock[len] + 1; |
| 799 | } |
| 800 | |
| 801 | /* Make sure we have enough room */ |
| 802 | len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); |
| 803 | |
| 804 | /* Fill the FW log file, consumed by the sysfs fwlog entry */ |
| 805 | memcpy(wl->fwlog + wl->fwlog_size, memblock, len); |
| 806 | wl->fwlog_size += len; |
| 807 | |
| 808 | return len; |
| 809 | } |
| 810 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 811 | #define WLCORE_FW_LOG_END 0x2000000 |
| 812 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 813 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) |
| 814 | { |
| 815 | u32 addr; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 816 | u32 offset; |
| 817 | u32 end_of_log; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 818 | u8 *block; |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 819 | int ret; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 820 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 821 | if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) || |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 822 | (wl->conf.fwlog.mem_blocks == 0)) |
| 823 | return; |
| 824 | |
| 825 | wl1271_info("Reading FW panic log"); |
| 826 | |
| 827 | block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); |
| 828 | if (!block) |
| 829 | return; |
| 830 | |
| 831 | /* |
| 832 | * Make sure the chip is awake and the logger isn't active. |
Eliad Peller | 847cbeb | 2012-11-26 18:05:42 +0200 | [diff] [blame] | 833 | * Do not send a stop fwlog command if the fw is hanged or if |
| 834 | * dbgpins are used (due to some fw bug). |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 835 | */ |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 836 | if (wl1271_ps_elp_wakeup(wl)) |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 837 | goto out; |
Eliad Peller | 847cbeb | 2012-11-26 18:05:42 +0200 | [diff] [blame] | 838 | if (!wl->watchdog_recovery && |
| 839 | wl->conf.fwlog.output != WL12XX_FWLOG_OUTPUT_DBG_PINS) |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 840 | wl12xx_cmd_stop_fwlog(wl); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 841 | |
| 842 | /* Read the first memory block address */ |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 843 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
| 844 | if (ret < 0) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 845 | goto out; |
| 846 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 847 | addr = le32_to_cpu(wl->fw_status_2->log_start_addr); |
| 848 | if (!addr) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 849 | goto out; |
| 850 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 851 | if (wl->conf.fwlog.mode == WL12XX_FWLOG_CONTINUOUS) { |
| 852 | offset = sizeof(addr) + sizeof(struct wl1271_rx_descriptor); |
| 853 | end_of_log = WLCORE_FW_LOG_END; |
| 854 | } else { |
| 855 | offset = sizeof(addr); |
| 856 | end_of_log = addr; |
| 857 | } |
| 858 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 859 | /* Traverse the memory blocks linked list */ |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 860 | do { |
| 861 | memset(block, 0, WL12XX_HW_BLOCK_SIZE); |
Ido Yariv | 2b80040 | 2012-06-18 18:15:50 +0300 | [diff] [blame] | 862 | ret = wlcore_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, |
| 863 | false); |
| 864 | if (ret < 0) |
| 865 | goto out; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 866 | |
| 867 | /* |
| 868 | * Memory blocks are linked to one another. The first 4 bytes |
| 869 | * of each memory block hold the hardware address of the next |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 870 | * one. The last memory block points to the first one in |
| 871 | * on demand mode and is equal to 0x2000000 in continuous mode. |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 872 | */ |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 873 | addr = le32_to_cpup((__le32 *)block); |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 874 | if (!wl12xx_copy_fwlog(wl, block + offset, |
| 875 | WL12XX_HW_BLOCK_SIZE - offset)) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 876 | break; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 877 | } while (addr && (addr != end_of_log)); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 878 | |
| 879 | wake_up_interruptible(&wl->fwlog_waitq); |
| 880 | |
| 881 | out: |
| 882 | kfree(block); |
| 883 | } |
| 884 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 885 | static void wlcore_print_recovery(struct wl1271 *wl) |
| 886 | { |
| 887 | u32 pc = 0; |
| 888 | u32 hint_sts = 0; |
| 889 | int ret; |
| 890 | |
| 891 | wl1271_info("Hardware recovery in progress. FW ver: %s", |
| 892 | wl->chip.fw_ver_str); |
| 893 | |
| 894 | /* change partitions momentarily so we can read the FW pc */ |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 895 | ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
| 896 | if (ret < 0) |
| 897 | return; |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 898 | |
| 899 | ret = wlcore_read_reg(wl, REG_PC_ON_RECOVERY, &pc); |
| 900 | if (ret < 0) |
| 901 | return; |
| 902 | |
| 903 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &hint_sts); |
| 904 | if (ret < 0) |
| 905 | return; |
| 906 | |
Luciano Coelho | c108c90 | 2012-11-26 18:05:49 +0200 | [diff] [blame] | 907 | wl1271_info("pc: 0x%x, hint_sts: 0x%08x count: %d", |
| 908 | pc, hint_sts, ++wl->recovery_count); |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 909 | |
| 910 | wlcore_set_partition(wl, &wl->ptable[PART_WORK]); |
| 911 | } |
| 912 | |
| 913 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 914 | static void wl1271_recovery_work(struct work_struct *work) |
| 915 | { |
| 916 | struct wl1271 *wl = |
| 917 | container_of(work, struct wl1271, recovery_work); |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 918 | struct wl12xx_vif *wlvif; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 919 | struct ieee80211_vif *vif; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 920 | |
| 921 | mutex_lock(&wl->mutex); |
| 922 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 923 | if (wl->state == WLCORE_STATE_OFF || wl->plt) |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 924 | goto out_unlock; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 925 | |
Arik Nemtsov | aafec11 | 2012-06-25 22:26:19 +0300 | [diff] [blame] | 926 | if (!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)) { |
| 927 | wl12xx_read_fwlog_panic(wl); |
| 928 | wlcore_print_recovery(wl); |
| 929 | } |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 930 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 931 | BUG_ON(wl->conf.recovery.bug_on_recovery && |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 932 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 933 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 934 | if (wl->conf.recovery.no_recovery) { |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 935 | wl1271_info("No recovery (chosen on module load). Fw will remain stuck."); |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 936 | goto out_unlock; |
| 937 | } |
| 938 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 939 | /* Prevent spurious TX during FW restart */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 940 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 941 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 942 | /* reboot the chipset */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 943 | while (!list_empty(&wl->wlvif_list)) { |
| 944 | wlvif = list_first_entry(&wl->wlvif_list, |
| 945 | struct wl12xx_vif, list); |
| 946 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 947 | __wl1271_op_remove_interface(wl, vif, false); |
| 948 | } |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 949 | |
| 950 | wlcore_op_stop_locked(wl); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 951 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 952 | ieee80211_restart_hw(wl->hw); |
| 953 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 954 | /* |
| 955 | * Its safe to enable TX now - the queues are stopped after a request |
| 956 | * to restart the HW. |
| 957 | */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 958 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 959 | |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 960 | out_unlock: |
Arik Nemtsov | b034fd6 | 2012-06-25 22:26:20 +0300 | [diff] [blame] | 961 | wl->watchdog_recovery = false; |
| 962 | clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 963 | mutex_unlock(&wl->mutex); |
| 964 | } |
| 965 | |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 966 | static int wlcore_fw_wakeup(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 967 | { |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 968 | return wlcore_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | static int wl1271_setup(struct wl1271 *wl) |
| 972 | { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 973 | wl->fw_status_1 = kmalloc(WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) + |
Luciano Coelho | 4f64a1e | 2012-05-10 12:14:00 +0300 | [diff] [blame] | 974 | sizeof(*wl->fw_status_2) + |
| 975 | wl->fw_status_priv_len, GFP_KERNEL); |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 976 | if (!wl->fw_status_1) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 977 | return -ENOMEM; |
| 978 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 979 | wl->fw_status_2 = (struct wl_fw_status_2 *) |
| 980 | (((u8 *) wl->fw_status_1) + |
| 981 | WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc)); |
| 982 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 983 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); |
| 984 | if (!wl->tx_res_if) { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 985 | kfree(wl->fw_status_1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 986 | return -ENOMEM; |
| 987 | } |
| 988 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 992 | static int wl12xx_set_power_on(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 993 | { |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 994 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 995 | |
Juuso Oikarinen | 01ac17e | 2009-12-11 15:41:02 +0200 | [diff] [blame] | 996 | msleep(WL1271_PRE_POWER_ON_SLEEP); |
Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 997 | ret = wl1271_power_on(wl); |
| 998 | if (ret < 0) |
| 999 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1000 | msleep(WL1271_POWER_ON_SLEEP); |
Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 1001 | wl1271_io_reset(wl); |
| 1002 | wl1271_io_init(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1003 | |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 1004 | ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
| 1005 | if (ret < 0) |
| 1006 | goto fail; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1007 | |
| 1008 | /* ELP module wake up */ |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 1009 | ret = wlcore_fw_wakeup(wl); |
| 1010 | if (ret < 0) |
| 1011 | goto fail; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1012 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1013 | out: |
| 1014 | return ret; |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 1015 | |
| 1016 | fail: |
| 1017 | wl1271_power_off(wl); |
| 1018 | return ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1019 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1020 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1021 | static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt) |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1022 | { |
| 1023 | int ret = 0; |
| 1024 | |
| 1025 | ret = wl12xx_set_power_on(wl); |
| 1026 | if (ret < 0) |
| 1027 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1028 | |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 1029 | /* |
| 1030 | * For wl127x based devices we could use the default block |
| 1031 | * size (512 bytes), but due to a bug in the sdio driver, we |
| 1032 | * need to set it explicitly after the chip is powered on. To |
| 1033 | * simplify the code and since the performance impact is |
| 1034 | * negligible, we use the same block size for all different |
| 1035 | * chip types. |
Luciano Coelho | b5d6d9b | 2012-06-05 00:02:25 +0300 | [diff] [blame] | 1036 | * |
| 1037 | * Check if the bus supports blocksize alignment and, if it |
| 1038 | * doesn't, make sure we don't have the quirk. |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 1039 | */ |
Luciano Coelho | b5d6d9b | 2012-06-05 00:02:25 +0300 | [diff] [blame] | 1040 | if (!wl1271_set_block_size(wl)) |
| 1041 | wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1042 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 1043 | /* TODO: make sure the lower driver has set things up correctly */ |
| 1044 | |
| 1045 | ret = wl1271_setup(wl); |
| 1046 | if (ret < 0) |
| 1047 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1048 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1049 | ret = wl12xx_fetch_firmware(wl, plt); |
| 1050 | if (ret < 0) |
| 1051 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1052 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1053 | out: |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1057 | int wl1271_plt_start(struct wl1271 *wl, const enum plt_mode plt_mode) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1058 | { |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1059 | int retries = WL1271_BOOT_RETRIES; |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1060 | struct wiphy *wiphy = wl->hw->wiphy; |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1061 | |
| 1062 | static const char* const PLT_MODE[] = { |
| 1063 | "PLT_OFF", |
| 1064 | "PLT_ON", |
| 1065 | "PLT_FEM_DETECT" |
| 1066 | }; |
| 1067 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1068 | int ret; |
| 1069 | |
| 1070 | mutex_lock(&wl->mutex); |
| 1071 | |
| 1072 | wl1271_notice("power up"); |
| 1073 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1074 | if (wl->state != WLCORE_STATE_OFF) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1075 | wl1271_error("cannot go into PLT state because not " |
| 1076 | "in off state: %d", wl->state); |
| 1077 | ret = -EBUSY; |
| 1078 | goto out; |
| 1079 | } |
| 1080 | |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1081 | /* Indicate to lower levels that we are now in PLT mode */ |
| 1082 | wl->plt = true; |
| 1083 | wl->plt_mode = plt_mode; |
| 1084 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1085 | while (retries) { |
| 1086 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1087 | ret = wl12xx_chip_wakeup(wl, true); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1088 | if (ret < 0) |
| 1089 | goto power_off; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1090 | |
Luciano Coelho | c331b34 | 2012-05-10 12:13:49 +0300 | [diff] [blame] | 1091 | ret = wl->ops->plt_init(wl); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1092 | if (ret < 0) |
| 1093 | goto power_off; |
| 1094 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1095 | wl->state = WLCORE_STATE_ON; |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1096 | wl1271_notice("firmware booted in PLT mode %s (%s)", |
| 1097 | PLT_MODE[plt_mode], |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 1098 | wl->chip.fw_ver_str); |
Luciano Coelho | e7ddf54 | 2011-03-10 15:24:57 +0200 | [diff] [blame] | 1099 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1100 | /* update hw/fw version info in wiphy struct */ |
| 1101 | wiphy->hw_version = wl->chip.id; |
| 1102 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 1103 | sizeof(wiphy->fw_version)); |
| 1104 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1105 | goto out; |
| 1106 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1107 | power_off: |
| 1108 | wl1271_power_off(wl); |
| 1109 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1110 | |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1111 | wl->plt = false; |
| 1112 | wl->plt_mode = PLT_OFF; |
| 1113 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1114 | wl1271_error("firmware boot in PLT mode failed despite %d retries", |
| 1115 | WL1271_BOOT_RETRIES); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1116 | out: |
| 1117 | mutex_unlock(&wl->mutex); |
| 1118 | |
| 1119 | return ret; |
| 1120 | } |
| 1121 | |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1122 | int wl1271_plt_stop(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1123 | { |
| 1124 | int ret = 0; |
| 1125 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1126 | wl1271_notice("power down"); |
| 1127 | |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1128 | /* |
| 1129 | * Interrupts must be disabled before setting the state to OFF. |
| 1130 | * Otherwise, the interrupt handler might be called and exit without |
| 1131 | * reading the interrupt status. |
| 1132 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1133 | wlcore_disable_interrupts(wl); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1134 | mutex_lock(&wl->mutex); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1135 | if (!wl->plt) { |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1136 | mutex_unlock(&wl->mutex); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1137 | |
| 1138 | /* |
| 1139 | * This will not necessarily enable interrupts as interrupts |
| 1140 | * may have been disabled when op_stop was called. It will, |
| 1141 | * however, balance the above call to disable_interrupts(). |
| 1142 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1143 | wlcore_enable_interrupts(wl); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1144 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1145 | wl1271_error("cannot power down because not in PLT " |
| 1146 | "state: %d", wl->state); |
| 1147 | ret = -EBUSY; |
| 1148 | goto out; |
| 1149 | } |
| 1150 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1151 | mutex_unlock(&wl->mutex); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1152 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1153 | wl1271_flush_deferred_work(wl); |
| 1154 | cancel_work_sync(&wl->netstack_work); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1155 | cancel_work_sync(&wl->recovery_work); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1156 | cancel_delayed_work_sync(&wl->elp_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1157 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1158 | |
| 1159 | mutex_lock(&wl->mutex); |
| 1160 | wl1271_power_off(wl); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1161 | wl->flags = 0; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 1162 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1163 | wl->state = WLCORE_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1164 | wl->plt = false; |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1165 | wl->plt_mode = PLT_OFF; |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1166 | wl->rx_counter = 0; |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1167 | mutex_unlock(&wl->mutex); |
| 1168 | |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 1169 | out: |
| 1170 | return ret; |
| 1171 | } |
Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 1172 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1173 | static void wl1271_op_tx(struct ieee80211_hw *hw, |
| 1174 | struct ieee80211_tx_control *control, |
| 1175 | struct sk_buff *skb) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1176 | { |
| 1177 | struct wl1271 *wl = hw->priv; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1178 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1179 | struct ieee80211_vif *vif = info->control.vif; |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1180 | struct wl12xx_vif *wlvif = NULL; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1181 | unsigned long flags; |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1182 | int q, mapping; |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1183 | u8 hlid; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1184 | |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1185 | if (!vif) { |
| 1186 | wl1271_debug(DEBUG_TX, "DROP skb with no vif"); |
| 1187 | ieee80211_free_txskb(hw, skb); |
| 1188 | return; |
| 1189 | } |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1190 | |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1191 | wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1192 | mapping = skb_get_queue_mapping(skb); |
| 1193 | q = wl1271_tx_get_queue(mapping); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1194 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1195 | hlid = wl12xx_tx_get_hlid(wl, wlvif, skb, control->sta); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1196 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1197 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1198 | |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1199 | /* |
| 1200 | * drop the packet if the link is invalid or the queue is stopped |
| 1201 | * for any reason but watermark. Watermark is a "soft"-stop so we |
| 1202 | * allow these packets through. |
| 1203 | */ |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1204 | if (hlid == WL12XX_INVALID_LINK_ID || |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1205 | (!test_bit(hlid, wlvif->links_map)) || |
Arik Nemtsov | d6037d2 | 2012-11-28 11:42:44 +0200 | [diff] [blame] | 1206 | (wlcore_is_queue_stopped_locked(wl, wlvif, q) && |
| 1207 | !wlcore_is_queue_stopped_by_reason_locked(wl, wlvif, q, |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1208 | WLCORE_QUEUE_STOP_REASON_WATERMARK))) { |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1209 | wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); |
Eliad Peller | 5de8eef | 2011-12-13 15:26:38 +0200 | [diff] [blame] | 1210 | ieee80211_free_txskb(hw, skb); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1211 | goto out; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 1212 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1213 | |
Eliad Peller | 8ccd16e | 2012-03-04 10:55:55 +0200 | [diff] [blame] | 1214 | wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d", |
| 1215 | hlid, q, skb->len); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1216 | skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); |
| 1217 | |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1218 | wl->tx_queue_count[q]++; |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1219 | wlvif->tx_queue_count[q]++; |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1220 | |
| 1221 | /* |
| 1222 | * The workqueue is slow to process the tx_queue and we need stop |
| 1223 | * the queue here, otherwise the queue will get too long. |
| 1224 | */ |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 1225 | if (wlvif->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK && |
Arik Nemtsov | d6037d2 | 2012-11-28 11:42:44 +0200 | [diff] [blame] | 1226 | !wlcore_is_queue_stopped_by_reason_locked(wl, wlvif, q, |
Arik Nemtsov | 8cdc44a | 2012-06-25 22:26:17 +0300 | [diff] [blame] | 1227 | WLCORE_QUEUE_STOP_REASON_WATERMARK)) { |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1228 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 1229 | wlcore_stop_queue_locked(wl, wlvif, q, |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1230 | WLCORE_QUEUE_STOP_REASON_WATERMARK); |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1231 | } |
| 1232 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1233 | /* |
| 1234 | * The chip specific setup must run before the first TX packet - |
| 1235 | * before that, the tx_work will not be initialized! |
| 1236 | */ |
| 1237 | |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1238 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
| 1239 | !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 1240 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1241 | |
Arik Nemtsov | 04216da | 2011-08-14 13:17:38 +0300 | [diff] [blame] | 1242 | out: |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1243 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1244 | } |
| 1245 | |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1246 | int wl1271_tx_dummy_packet(struct wl1271 *wl) |
| 1247 | { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1248 | unsigned long flags; |
Arik Nemtsov | 1462378 | 2011-08-28 15:11:57 +0300 | [diff] [blame] | 1249 | int q; |
| 1250 | |
| 1251 | /* no need to queue a new dummy packet if one is already pending */ |
| 1252 | if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) |
| 1253 | return 0; |
| 1254 | |
| 1255 | q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1256 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1257 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1258 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 1259 | wl->tx_queue_count[q]++; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1260 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 1261 | |
| 1262 | /* The FW is low on RX memory blocks, so send the dummy packet asap */ |
| 1263 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 1264 | return wlcore_tx_work_locked(wl); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1265 | |
| 1266 | /* |
| 1267 | * If the FW TX is busy, TX work will be scheduled by the threaded |
| 1268 | * interrupt handler function |
| 1269 | */ |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | /* |
| 1274 | * The size of the dummy packet should be at least 1400 bytes. However, in |
| 1275 | * order to minimize the number of bus transactions, aligning it to 512 bytes |
| 1276 | * boundaries could be beneficial, performance wise |
| 1277 | */ |
| 1278 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) |
| 1279 | |
Luciano Coelho | cf27d86 | 2011-04-01 21:08:23 +0300 | [diff] [blame] | 1280 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1281 | { |
| 1282 | struct sk_buff *skb; |
| 1283 | struct ieee80211_hdr_3addr *hdr; |
| 1284 | unsigned int dummy_packet_size; |
| 1285 | |
| 1286 | dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - |
| 1287 | sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); |
| 1288 | |
| 1289 | skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1290 | if (!skb) { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1291 | wl1271_warning("Failed to allocate a dummy packet skb"); |
| 1292 | return NULL; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 1296 | |
| 1297 | hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); |
| 1298 | memset(hdr, 0, sizeof(*hdr)); |
| 1299 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1300 | IEEE80211_STYPE_NULLFUNC | |
| 1301 | IEEE80211_FCTL_TODS); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1302 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1303 | memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1304 | |
Luciano Coelho | 18b92ff | 2011-03-21 16:35:21 +0200 | [diff] [blame] | 1305 | /* Dummy packets require the TID to be management */ |
| 1306 | skb->priority = WL1271_TID_MGMT; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1307 | |
| 1308 | /* Initialize all fields that might be used */ |
Hauke Mehrtens | 86c438f | 2011-04-26 23:27:44 +0200 | [diff] [blame] | 1309 | skb_set_queue_mapping(skb, 0); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1310 | memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1311 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1312 | return skb; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1313 | } |
| 1314 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1315 | |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1316 | #ifdef CONFIG_PM |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 1317 | static int |
| 1318 | wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p) |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1319 | { |
| 1320 | int num_fields = 0, in_field = 0, fields_size = 0; |
| 1321 | int i, pattern_len = 0; |
| 1322 | |
| 1323 | if (!p->mask) { |
| 1324 | wl1271_warning("No mask in WoWLAN pattern"); |
| 1325 | return -EINVAL; |
| 1326 | } |
| 1327 | |
| 1328 | /* |
| 1329 | * The pattern is broken up into segments of bytes at different offsets |
| 1330 | * that need to be checked by the FW filter. Each segment is called |
| 1331 | * a field in the FW API. We verify that the total number of fields |
| 1332 | * required for this pattern won't exceed FW limits (8) |
| 1333 | * as well as the total fields buffer won't exceed the FW limit. |
| 1334 | * Note that if there's a pattern which crosses Ethernet/IP header |
| 1335 | * boundary a new field is required. |
| 1336 | */ |
| 1337 | for (i = 0; i < p->pattern_len; i++) { |
| 1338 | if (test_bit(i, (unsigned long *)p->mask)) { |
| 1339 | if (!in_field) { |
| 1340 | in_field = 1; |
| 1341 | pattern_len = 1; |
| 1342 | } else { |
| 1343 | if (i == WL1271_RX_FILTER_ETH_HEADER_SIZE) { |
| 1344 | num_fields++; |
| 1345 | fields_size += pattern_len + |
| 1346 | RX_FILTER_FIELD_OVERHEAD; |
| 1347 | pattern_len = 1; |
| 1348 | } else |
| 1349 | pattern_len++; |
| 1350 | } |
| 1351 | } else { |
| 1352 | if (in_field) { |
| 1353 | in_field = 0; |
| 1354 | fields_size += pattern_len + |
| 1355 | RX_FILTER_FIELD_OVERHEAD; |
| 1356 | num_fields++; |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | if (in_field) { |
| 1362 | fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD; |
| 1363 | num_fields++; |
| 1364 | } |
| 1365 | |
| 1366 | if (num_fields > WL1271_RX_FILTER_MAX_FIELDS) { |
| 1367 | wl1271_warning("RX Filter too complex. Too many segments"); |
| 1368 | return -EINVAL; |
| 1369 | } |
| 1370 | |
| 1371 | if (fields_size > WL1271_RX_FILTER_MAX_FIELDS_SIZE) { |
| 1372 | wl1271_warning("RX filter pattern is too big"); |
| 1373 | return -E2BIG; |
| 1374 | } |
| 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
Eyal Shapira | a6eab0c | 2012-03-14 06:32:07 +0200 | [diff] [blame] | 1379 | struct wl12xx_rx_filter *wl1271_rx_filter_alloc(void) |
| 1380 | { |
| 1381 | return kzalloc(sizeof(struct wl12xx_rx_filter), GFP_KERNEL); |
| 1382 | } |
| 1383 | |
| 1384 | void wl1271_rx_filter_free(struct wl12xx_rx_filter *filter) |
| 1385 | { |
| 1386 | int i; |
| 1387 | |
| 1388 | if (filter == NULL) |
| 1389 | return; |
| 1390 | |
| 1391 | for (i = 0; i < filter->num_fields; i++) |
| 1392 | kfree(filter->fields[i].pattern); |
| 1393 | |
| 1394 | kfree(filter); |
| 1395 | } |
| 1396 | |
| 1397 | int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter *filter, |
| 1398 | u16 offset, u8 flags, |
| 1399 | u8 *pattern, u8 len) |
| 1400 | { |
| 1401 | struct wl12xx_rx_filter_field *field; |
| 1402 | |
| 1403 | if (filter->num_fields == WL1271_RX_FILTER_MAX_FIELDS) { |
| 1404 | wl1271_warning("Max fields per RX filter. can't alloc another"); |
| 1405 | return -EINVAL; |
| 1406 | } |
| 1407 | |
| 1408 | field = &filter->fields[filter->num_fields]; |
| 1409 | |
| 1410 | field->pattern = kzalloc(len, GFP_KERNEL); |
| 1411 | if (!field->pattern) { |
| 1412 | wl1271_warning("Failed to allocate RX filter pattern"); |
| 1413 | return -ENOMEM; |
| 1414 | } |
| 1415 | |
| 1416 | filter->num_fields++; |
| 1417 | |
| 1418 | field->offset = cpu_to_le16(offset); |
| 1419 | field->flags = flags; |
| 1420 | field->len = len; |
| 1421 | memcpy(field->pattern, pattern, len); |
| 1422 | |
| 1423 | return 0; |
| 1424 | } |
| 1425 | |
| 1426 | int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter *filter) |
| 1427 | { |
| 1428 | int i, fields_size = 0; |
| 1429 | |
| 1430 | for (i = 0; i < filter->num_fields; i++) |
| 1431 | fields_size += filter->fields[i].len + |
| 1432 | sizeof(struct wl12xx_rx_filter_field) - |
| 1433 | sizeof(u8 *); |
| 1434 | |
| 1435 | return fields_size; |
| 1436 | } |
| 1437 | |
| 1438 | void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter, |
| 1439 | u8 *buf) |
| 1440 | { |
| 1441 | int i; |
| 1442 | struct wl12xx_rx_filter_field *field; |
| 1443 | |
| 1444 | for (i = 0; i < filter->num_fields; i++) { |
| 1445 | field = (struct wl12xx_rx_filter_field *)buf; |
| 1446 | |
| 1447 | field->offset = filter->fields[i].offset; |
| 1448 | field->flags = filter->fields[i].flags; |
| 1449 | field->len = filter->fields[i].len; |
| 1450 | |
| 1451 | memcpy(&field->pattern, filter->fields[i].pattern, field->len); |
| 1452 | buf += sizeof(struct wl12xx_rx_filter_field) - |
| 1453 | sizeof(u8 *) + field->len; |
| 1454 | } |
| 1455 | } |
| 1456 | |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1457 | /* |
| 1458 | * Allocates an RX filter returned through f |
| 1459 | * which needs to be freed using rx_filter_free() |
| 1460 | */ |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 1461 | static int wl1271_convert_wowlan_pattern_to_rx_filter( |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1462 | struct cfg80211_wowlan_trig_pkt_pattern *p, |
| 1463 | struct wl12xx_rx_filter **f) |
| 1464 | { |
| 1465 | int i, j, ret = 0; |
| 1466 | struct wl12xx_rx_filter *filter; |
| 1467 | u16 offset; |
| 1468 | u8 flags, len; |
| 1469 | |
| 1470 | filter = wl1271_rx_filter_alloc(); |
| 1471 | if (!filter) { |
| 1472 | wl1271_warning("Failed to alloc rx filter"); |
| 1473 | ret = -ENOMEM; |
| 1474 | goto err; |
| 1475 | } |
| 1476 | |
| 1477 | i = 0; |
| 1478 | while (i < p->pattern_len) { |
| 1479 | if (!test_bit(i, (unsigned long *)p->mask)) { |
| 1480 | i++; |
| 1481 | continue; |
| 1482 | } |
| 1483 | |
| 1484 | for (j = i; j < p->pattern_len; j++) { |
| 1485 | if (!test_bit(j, (unsigned long *)p->mask)) |
| 1486 | break; |
| 1487 | |
| 1488 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE && |
| 1489 | j >= WL1271_RX_FILTER_ETH_HEADER_SIZE) |
| 1490 | break; |
| 1491 | } |
| 1492 | |
| 1493 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE) { |
| 1494 | offset = i; |
| 1495 | flags = WL1271_RX_FILTER_FLAG_ETHERNET_HEADER; |
| 1496 | } else { |
| 1497 | offset = i - WL1271_RX_FILTER_ETH_HEADER_SIZE; |
| 1498 | flags = WL1271_RX_FILTER_FLAG_IP_HEADER; |
| 1499 | } |
| 1500 | |
| 1501 | len = j - i; |
| 1502 | |
| 1503 | ret = wl1271_rx_filter_alloc_field(filter, |
| 1504 | offset, |
| 1505 | flags, |
| 1506 | &p->pattern[i], len); |
| 1507 | if (ret) |
| 1508 | goto err; |
| 1509 | |
| 1510 | i = j; |
| 1511 | } |
| 1512 | |
| 1513 | filter->action = FILTER_SIGNAL; |
| 1514 | |
| 1515 | *f = filter; |
| 1516 | return 0; |
| 1517 | |
| 1518 | err: |
| 1519 | wl1271_rx_filter_free(filter); |
| 1520 | *f = NULL; |
| 1521 | |
| 1522 | return ret; |
| 1523 | } |
| 1524 | |
| 1525 | static int wl1271_configure_wowlan(struct wl1271 *wl, |
| 1526 | struct cfg80211_wowlan *wow) |
| 1527 | { |
| 1528 | int i, ret; |
| 1529 | |
| 1530 | if (!wow || wow->any || !wow->n_patterns) { |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1531 | ret = wl1271_acx_default_rx_filter_enable(wl, 0, |
| 1532 | FILTER_SIGNAL); |
| 1533 | if (ret) |
| 1534 | goto out; |
| 1535 | |
| 1536 | ret = wl1271_rx_filter_clear_all(wl); |
| 1537 | if (ret) |
| 1538 | goto out; |
| 1539 | |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | if (WARN_ON(wow->n_patterns > WL1271_MAX_RX_FILTERS)) |
| 1544 | return -EINVAL; |
| 1545 | |
| 1546 | /* Validate all incoming patterns before clearing current FW state */ |
| 1547 | for (i = 0; i < wow->n_patterns; i++) { |
| 1548 | ret = wl1271_validate_wowlan_pattern(&wow->patterns[i]); |
| 1549 | if (ret) { |
| 1550 | wl1271_warning("Bad wowlan pattern %d", i); |
| 1551 | return ret; |
| 1552 | } |
| 1553 | } |
| 1554 | |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1555 | ret = wl1271_acx_default_rx_filter_enable(wl, 0, FILTER_SIGNAL); |
| 1556 | if (ret) |
| 1557 | goto out; |
| 1558 | |
| 1559 | ret = wl1271_rx_filter_clear_all(wl); |
| 1560 | if (ret) |
| 1561 | goto out; |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1562 | |
| 1563 | /* Translate WoWLAN patterns into filters */ |
| 1564 | for (i = 0; i < wow->n_patterns; i++) { |
| 1565 | struct cfg80211_wowlan_trig_pkt_pattern *p; |
| 1566 | struct wl12xx_rx_filter *filter = NULL; |
| 1567 | |
| 1568 | p = &wow->patterns[i]; |
| 1569 | |
| 1570 | ret = wl1271_convert_wowlan_pattern_to_rx_filter(p, &filter); |
| 1571 | if (ret) { |
| 1572 | wl1271_warning("Failed to create an RX filter from " |
| 1573 | "wowlan pattern %d", i); |
| 1574 | goto out; |
| 1575 | } |
| 1576 | |
| 1577 | ret = wl1271_rx_filter_enable(wl, i, 1, filter); |
| 1578 | |
| 1579 | wl1271_rx_filter_free(filter); |
| 1580 | if (ret) |
| 1581 | goto out; |
| 1582 | } |
| 1583 | |
| 1584 | ret = wl1271_acx_default_rx_filter_enable(wl, 1, FILTER_DROP); |
| 1585 | |
| 1586 | out: |
| 1587 | return ret; |
| 1588 | } |
| 1589 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1590 | static int wl1271_configure_suspend_sta(struct wl1271 *wl, |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1591 | struct wl12xx_vif *wlvif, |
| 1592 | struct cfg80211_wowlan *wow) |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1593 | { |
| 1594 | int ret = 0; |
| 1595 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1596 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1597 | goto out; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1598 | |
| 1599 | ret = wl1271_ps_elp_wakeup(wl); |
| 1600 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1601 | goto out; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1602 | |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1603 | ret = wl1271_configure_wowlan(wl, wow); |
| 1604 | if (ret < 0) |
| 1605 | goto out_sleep; |
| 1606 | |
Eyal Shapira | 11bc97e | 2012-08-02 07:15:19 +0300 | [diff] [blame] | 1607 | if ((wl->conf.conn.suspend_wake_up_event == |
| 1608 | wl->conf.conn.wake_up_event) && |
| 1609 | (wl->conf.conn.suspend_listen_interval == |
| 1610 | wl->conf.conn.listen_interval)) |
| 1611 | goto out_sleep; |
| 1612 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1613 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1614 | wl->conf.conn.suspend_wake_up_event, |
| 1615 | wl->conf.conn.suspend_listen_interval); |
| 1616 | |
| 1617 | if (ret < 0) |
| 1618 | wl1271_error("suspend: set wake up conditions failed: %d", ret); |
| 1619 | |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1620 | out_sleep: |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1621 | wl1271_ps_elp_sleep(wl); |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1622 | out: |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1623 | return ret; |
| 1624 | |
| 1625 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1626 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1627 | static int wl1271_configure_suspend_ap(struct wl1271 *wl, |
| 1628 | struct wl12xx_vif *wlvif) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1629 | { |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1630 | int ret = 0; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1631 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1632 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1633 | goto out; |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1634 | |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1635 | ret = wl1271_ps_elp_wakeup(wl); |
| 1636 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1637 | goto out; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1638 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1639 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1640 | |
| 1641 | wl1271_ps_elp_sleep(wl); |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1642 | out: |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1643 | return ret; |
| 1644 | |
| 1645 | } |
| 1646 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1647 | static int wl1271_configure_suspend(struct wl1271 *wl, |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1648 | struct wl12xx_vif *wlvif, |
| 1649 | struct cfg80211_wowlan *wow) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1650 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1651 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1652 | return wl1271_configure_suspend_sta(wl, wlvif, wow); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1653 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1654 | return wl1271_configure_suspend_ap(wl, wlvif); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1655 | return 0; |
| 1656 | } |
| 1657 | |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame] | 1658 | static void wl1271_configure_resume(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1659 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1660 | int ret = 0; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1661 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1662 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1663 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1664 | if ((!is_ap) && (!is_sta)) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1665 | return; |
| 1666 | |
Eliad Peller | d49524d | 2012-08-01 18:44:22 +0300 | [diff] [blame] | 1667 | if (is_sta && !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 1668 | return; |
| 1669 | |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1670 | ret = wl1271_ps_elp_wakeup(wl); |
| 1671 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1672 | return; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1673 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1674 | if (is_sta) { |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1675 | wl1271_configure_wowlan(wl, NULL); |
| 1676 | |
Eyal Shapira | 11bc97e | 2012-08-02 07:15:19 +0300 | [diff] [blame] | 1677 | if ((wl->conf.conn.suspend_wake_up_event == |
| 1678 | wl->conf.conn.wake_up_event) && |
| 1679 | (wl->conf.conn.suspend_listen_interval == |
| 1680 | wl->conf.conn.listen_interval)) |
| 1681 | goto out_sleep; |
| 1682 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1683 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1684 | wl->conf.conn.wake_up_event, |
| 1685 | wl->conf.conn.listen_interval); |
| 1686 | |
| 1687 | if (ret < 0) |
| 1688 | wl1271_error("resume: wake up conditions failed: %d", |
| 1689 | ret); |
| 1690 | |
| 1691 | } else if (is_ap) { |
| 1692 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false); |
| 1693 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1694 | |
Eyal Shapira | 11bc97e | 2012-08-02 07:15:19 +0300 | [diff] [blame] | 1695 | out_sleep: |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1696 | wl1271_ps_elp_sleep(wl); |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1697 | } |
| 1698 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1699 | static int wl1271_op_suspend(struct ieee80211_hw *hw, |
| 1700 | struct cfg80211_wowlan *wow) |
| 1701 | { |
| 1702 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1703 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1704 | int ret; |
| 1705 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1706 | wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1707 | WARN_ON(!wow); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1708 | |
Arik Nemtsov | 96caded | 2012-06-21 18:10:47 +0300 | [diff] [blame] | 1709 | /* we want to perform the recovery before suspending */ |
| 1710 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 1711 | wl1271_warning("postponing suspend to perform recovery"); |
| 1712 | return -EBUSY; |
| 1713 | } |
| 1714 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 1715 | wl1271_tx_flush(wl); |
| 1716 | |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1717 | mutex_lock(&wl->mutex); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1718 | wl->wow_enabled = true; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1719 | wl12xx_for_each_wlvif(wl, wlvif) { |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1720 | ret = wl1271_configure_suspend(wl, wlvif, wow); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1721 | if (ret < 0) { |
Dan Carpenter | cd840f6 | 2012-04-16 13:57:02 +0300 | [diff] [blame] | 1722 | mutex_unlock(&wl->mutex); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1723 | wl1271_warning("couldn't prepare device to suspend"); |
| 1724 | return ret; |
| 1725 | } |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1726 | } |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1727 | mutex_unlock(&wl->mutex); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1728 | /* flush any remaining work */ |
| 1729 | wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1730 | |
| 1731 | /* |
| 1732 | * disable and re-enable interrupts in order to flush |
| 1733 | * the threaded_irq |
| 1734 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1735 | wlcore_disable_interrupts(wl); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1736 | |
| 1737 | /* |
| 1738 | * set suspended flag to avoid triggering a new threaded_irq |
| 1739 | * work. no need for spinlock as interrupts are disabled. |
| 1740 | */ |
| 1741 | set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1742 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1743 | wlcore_enable_interrupts(wl); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1744 | flush_work(&wl->tx_work); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1745 | flush_delayed_work(&wl->elp_work); |
| 1746 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1747 | return 0; |
| 1748 | } |
| 1749 | |
| 1750 | static int wl1271_op_resume(struct ieee80211_hw *hw) |
| 1751 | { |
| 1752 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1753 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1754 | unsigned long flags; |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1755 | bool run_irq_work = false, pending_recovery; |
Arik Nemtsov | 725b827 | 2012-06-21 18:10:52 +0300 | [diff] [blame] | 1756 | int ret; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1757 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1758 | wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", |
| 1759 | wl->wow_enabled); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1760 | WARN_ON(!wl->wow_enabled); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1761 | |
| 1762 | /* |
| 1763 | * re-enable irq_work enqueuing, and call irq_work directly if |
| 1764 | * there is a pending work. |
| 1765 | */ |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1766 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1767 | clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1768 | if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) |
| 1769 | run_irq_work = true; |
| 1770 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1771 | |
Arik Nemtsov | 725b827 | 2012-06-21 18:10:52 +0300 | [diff] [blame] | 1772 | mutex_lock(&wl->mutex); |
| 1773 | |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1774 | /* test the recovery flag before calling any SDIO functions */ |
| 1775 | pending_recovery = test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, |
| 1776 | &wl->flags); |
| 1777 | |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1778 | if (run_irq_work) { |
| 1779 | wl1271_debug(DEBUG_MAC80211, |
| 1780 | "run postponed irq_work directly"); |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1781 | |
| 1782 | /* don't talk to the HW if recovery is pending */ |
Arik Nemtsov | 725b827 | 2012-06-21 18:10:52 +0300 | [diff] [blame] | 1783 | if (!pending_recovery) { |
| 1784 | ret = wlcore_irq_locked(wl); |
| 1785 | if (ret) |
| 1786 | wl12xx_queue_recovery_work(wl); |
| 1787 | } |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1788 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1789 | wlcore_enable_interrupts(wl); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1790 | } |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1791 | |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1792 | if (pending_recovery) { |
| 1793 | wl1271_warning("queuing forgotten recovery on resume"); |
| 1794 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
| 1795 | goto out; |
| 1796 | } |
| 1797 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1798 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 1799 | wl1271_configure_resume(wl, wlvif); |
| 1800 | } |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1801 | |
| 1802 | out: |
Eliad Peller | ff91afc | 2011-06-06 12:21:53 +0300 | [diff] [blame] | 1803 | wl->wow_enabled = false; |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1804 | mutex_unlock(&wl->mutex); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1805 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1806 | return 0; |
| 1807 | } |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1808 | #endif |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1809 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1810 | static int wl1271_op_start(struct ieee80211_hw *hw) |
| 1811 | { |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1812 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); |
| 1813 | |
| 1814 | /* |
| 1815 | * We have to delay the booting of the hardware because |
| 1816 | * we need to know the local MAC address before downloading and |
| 1817 | * initializing the firmware. The MAC address cannot be changed |
| 1818 | * after boot, and without the proper MAC address, the firmware |
| 1819 | * will not function properly. |
| 1820 | * |
| 1821 | * The MAC address is first known when the corresponding interface |
| 1822 | * is added. That is where we will initialize the hardware. |
| 1823 | */ |
| 1824 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 1825 | return 0; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1826 | } |
| 1827 | |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1828 | static void wlcore_op_stop_locked(struct wl1271 *wl) |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1829 | { |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1830 | int i; |
| 1831 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1832 | if (wl->state == WLCORE_STATE_OFF) { |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 1833 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, |
| 1834 | &wl->flags)) |
| 1835 | wlcore_enable_interrupts(wl); |
| 1836 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1837 | return; |
| 1838 | } |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1839 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1840 | /* |
| 1841 | * this must be before the cancel_work calls below, so that the work |
| 1842 | * functions don't perform further work. |
| 1843 | */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1844 | wl->state = WLCORE_STATE_OFF; |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1845 | |
| 1846 | /* |
| 1847 | * Use the nosync variant to disable interrupts, so the mutex could be |
| 1848 | * held while doing so without deadlocking. |
| 1849 | */ |
| 1850 | wlcore_disable_interrupts_nosync(wl); |
| 1851 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1852 | mutex_unlock(&wl->mutex); |
| 1853 | |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1854 | wlcore_synchronize_interrupts(wl); |
Eliad Peller | 6dbc5fc | 2012-07-29 14:37:29 +0300 | [diff] [blame] | 1855 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 1856 | cancel_work_sync(&wl->recovery_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1857 | wl1271_flush_deferred_work(wl); |
| 1858 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 1859 | cancel_work_sync(&wl->netstack_work); |
| 1860 | cancel_work_sync(&wl->tx_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1861 | cancel_delayed_work_sync(&wl->elp_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1862 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1863 | |
| 1864 | /* let's notify MAC80211 about the remaining pending TX frames */ |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1865 | mutex_lock(&wl->mutex); |
Arik Nemtsov | d935e38 | 2012-11-27 08:44:53 +0200 | [diff] [blame] | 1866 | wl12xx_tx_reset(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1867 | |
| 1868 | wl1271_power_off(wl); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 1869 | /* |
| 1870 | * In case a recovery was scheduled, interrupts were disabled to avoid |
| 1871 | * an interrupt storm. Now that the power is down, it is safe to |
| 1872 | * re-enable interrupts to balance the disable depth |
| 1873 | */ |
| 1874 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 1875 | wlcore_enable_interrupts(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1876 | |
| 1877 | wl->band = IEEE80211_BAND_2GHZ; |
| 1878 | |
| 1879 | wl->rx_counter = 0; |
| 1880 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 1881 | wl->channel_type = NL80211_CHAN_NO_HT; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1882 | wl->tx_blocks_available = 0; |
| 1883 | wl->tx_allocated_blocks = 0; |
| 1884 | wl->tx_results_count = 0; |
| 1885 | wl->tx_packets_count = 0; |
| 1886 | wl->time_offset = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1887 | wl->ap_fw_ps_map = 0; |
| 1888 | wl->ap_ps_map = 0; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 1889 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1890 | memset(wl->roles_map, 0, sizeof(wl->roles_map)); |
| 1891 | memset(wl->links_map, 0, sizeof(wl->links_map)); |
| 1892 | memset(wl->roc_map, 0, sizeof(wl->roc_map)); |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 1893 | memset(wl->session_ids, 0, sizeof(wl->session_ids)); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1894 | wl->active_sta_count = 0; |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 1895 | wl->active_link_count = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1896 | |
| 1897 | /* The system link is always allocated */ |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 1898 | wl->links[WL12XX_SYSTEM_HLID].allocated_pkts = 0; |
| 1899 | wl->links[WL12XX_SYSTEM_HLID].prev_freed_pkts = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1900 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 1901 | |
| 1902 | /* |
| 1903 | * this is performed after the cancel_work calls and the associated |
| 1904 | * mutex_lock, so that wl1271_op_add_interface does not accidentally |
| 1905 | * get executed before all these vars have been reset. |
| 1906 | */ |
| 1907 | wl->flags = 0; |
| 1908 | |
| 1909 | wl->tx_blocks_freed = 0; |
| 1910 | |
| 1911 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 1912 | wl->tx_pkts_freed[i] = 0; |
| 1913 | wl->tx_allocated_pkts[i] = 0; |
| 1914 | } |
| 1915 | |
| 1916 | wl1271_debugfs_reset(wl); |
| 1917 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 1918 | kfree(wl->fw_status_1); |
| 1919 | wl->fw_status_1 = NULL; |
| 1920 | wl->fw_status_2 = NULL; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1921 | kfree(wl->tx_res_if); |
| 1922 | wl->tx_res_if = NULL; |
| 1923 | kfree(wl->target_mem_map); |
| 1924 | wl->target_mem_map = NULL; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1925 | |
| 1926 | /* |
| 1927 | * FW channels must be re-calibrated after recovery, |
| 1928 | * clear the last Reg-Domain channel configuration. |
| 1929 | */ |
| 1930 | memset(wl->reg_ch_conf_last, 0, sizeof(wl->reg_ch_conf_last)); |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | static void wlcore_op_stop(struct ieee80211_hw *hw) |
| 1934 | { |
| 1935 | struct wl1271 *wl = hw->priv; |
| 1936 | |
| 1937 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); |
| 1938 | |
| 1939 | mutex_lock(&wl->mutex); |
| 1940 | |
| 1941 | wlcore_op_stop_locked(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1942 | |
| 1943 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1944 | } |
| 1945 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 1946 | static void wlcore_channel_switch_work(struct work_struct *work) |
| 1947 | { |
| 1948 | struct delayed_work *dwork; |
| 1949 | struct wl1271 *wl; |
| 1950 | struct ieee80211_vif *vif; |
| 1951 | struct wl12xx_vif *wlvif; |
| 1952 | int ret; |
| 1953 | |
| 1954 | dwork = container_of(work, struct delayed_work, work); |
| 1955 | wlvif = container_of(dwork, struct wl12xx_vif, channel_switch_work); |
| 1956 | wl = wlvif->wl; |
| 1957 | |
| 1958 | wl1271_info("channel switch failed (role_id: %d).", wlvif->role_id); |
| 1959 | |
| 1960 | mutex_lock(&wl->mutex); |
| 1961 | |
| 1962 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 1963 | goto out; |
| 1964 | |
| 1965 | /* check the channel switch is still ongoing */ |
| 1966 | if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) |
| 1967 | goto out; |
| 1968 | |
| 1969 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 1970 | ieee80211_chswitch_done(vif, false); |
| 1971 | |
| 1972 | ret = wl1271_ps_elp_wakeup(wl); |
| 1973 | if (ret < 0) |
| 1974 | goto out; |
| 1975 | |
| 1976 | wl12xx_cmd_stop_channel_switch(wl, wlvif); |
| 1977 | |
| 1978 | wl1271_ps_elp_sleep(wl); |
| 1979 | out: |
| 1980 | mutex_unlock(&wl->mutex); |
| 1981 | } |
| 1982 | |
| 1983 | static void wlcore_connection_loss_work(struct work_struct *work) |
| 1984 | { |
| 1985 | struct delayed_work *dwork; |
| 1986 | struct wl1271 *wl; |
| 1987 | struct ieee80211_vif *vif; |
| 1988 | struct wl12xx_vif *wlvif; |
| 1989 | |
| 1990 | dwork = container_of(work, struct delayed_work, work); |
| 1991 | wlvif = container_of(dwork, struct wl12xx_vif, connection_loss_work); |
| 1992 | wl = wlvif->wl; |
| 1993 | |
| 1994 | wl1271_info("Connection loss work (role_id: %d).", wlvif->role_id); |
| 1995 | |
| 1996 | mutex_lock(&wl->mutex); |
| 1997 | |
| 1998 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 1999 | goto out; |
| 2000 | |
| 2001 | /* Call mac80211 connection loss */ |
| 2002 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 2003 | goto out; |
| 2004 | |
| 2005 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 2006 | ieee80211_connection_loss(vif); |
| 2007 | out: |
| 2008 | mutex_unlock(&wl->mutex); |
| 2009 | } |
| 2010 | |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2011 | static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) |
| 2012 | { |
| 2013 | u8 policy = find_first_zero_bit(wl->rate_policies_map, |
| 2014 | WL12XX_MAX_RATE_POLICIES); |
| 2015 | if (policy >= WL12XX_MAX_RATE_POLICIES) |
| 2016 | return -EBUSY; |
| 2017 | |
| 2018 | __set_bit(policy, wl->rate_policies_map); |
| 2019 | *idx = policy; |
| 2020 | return 0; |
| 2021 | } |
| 2022 | |
| 2023 | static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx) |
| 2024 | { |
| 2025 | if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES)) |
| 2026 | return; |
| 2027 | |
| 2028 | __clear_bit(*idx, wl->rate_policies_map); |
| 2029 | *idx = WL12XX_MAX_RATE_POLICIES; |
| 2030 | } |
| 2031 | |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2032 | static int wlcore_allocate_klv_template(struct wl1271 *wl, u8 *idx) |
| 2033 | { |
| 2034 | u8 policy = find_first_zero_bit(wl->klv_templates_map, |
| 2035 | WLCORE_MAX_KLV_TEMPLATES); |
| 2036 | if (policy >= WLCORE_MAX_KLV_TEMPLATES) |
| 2037 | return -EBUSY; |
| 2038 | |
| 2039 | __set_bit(policy, wl->klv_templates_map); |
| 2040 | *idx = policy; |
| 2041 | return 0; |
| 2042 | } |
| 2043 | |
| 2044 | static void wlcore_free_klv_template(struct wl1271 *wl, u8 *idx) |
| 2045 | { |
| 2046 | if (WARN_ON(*idx >= WLCORE_MAX_KLV_TEMPLATES)) |
| 2047 | return; |
| 2048 | |
| 2049 | __clear_bit(*idx, wl->klv_templates_map); |
| 2050 | *idx = WLCORE_MAX_KLV_TEMPLATES; |
| 2051 | } |
| 2052 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2053 | static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2054 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2055 | switch (wlvif->bss_type) { |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2056 | case BSS_TYPE_AP_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 2057 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2058 | return WL1271_ROLE_P2P_GO; |
| 2059 | else |
| 2060 | return WL1271_ROLE_AP; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2061 | |
| 2062 | case BSS_TYPE_STA_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 2063 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2064 | return WL1271_ROLE_P2P_CL; |
| 2065 | else |
| 2066 | return WL1271_ROLE_STA; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2067 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2068 | case BSS_TYPE_IBSS: |
| 2069 | return WL1271_ROLE_IBSS; |
| 2070 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2071 | default: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2072 | wl1271_error("invalid bss_type: %d", wlvif->bss_type); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2073 | } |
| 2074 | return WL12XX_INVALID_ROLE_TYPE; |
| 2075 | } |
| 2076 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2077 | static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2078 | { |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2079 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2080 | int i; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2081 | |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2082 | /* clear everything but the persistent data */ |
| 2083 | memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent)); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2084 | |
| 2085 | switch (ieee80211_vif_type_p2p(vif)) { |
| 2086 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2087 | wlvif->p2p = 1; |
| 2088 | /* fall-through */ |
| 2089 | case NL80211_IFTYPE_STATION: |
| 2090 | wlvif->bss_type = BSS_TYPE_STA_BSS; |
| 2091 | break; |
| 2092 | case NL80211_IFTYPE_ADHOC: |
| 2093 | wlvif->bss_type = BSS_TYPE_IBSS; |
| 2094 | break; |
| 2095 | case NL80211_IFTYPE_P2P_GO: |
| 2096 | wlvif->p2p = 1; |
| 2097 | /* fall-through */ |
| 2098 | case NL80211_IFTYPE_AP: |
| 2099 | wlvif->bss_type = BSS_TYPE_AP_BSS; |
| 2100 | break; |
| 2101 | default: |
| 2102 | wlvif->bss_type = MAX_BSS_TYPE; |
| 2103 | return -EOPNOTSUPP; |
| 2104 | } |
| 2105 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2106 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2107 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2108 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2109 | |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2110 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2111 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2112 | /* init sta/ibss data */ |
| 2113 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2114 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2115 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2116 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2117 | wlcore_allocate_klv_template(wl, &wlvif->sta.klv_template_id); |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 2118 | wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC; |
| 2119 | wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC; |
| 2120 | wlvif->rate_set = CONF_TX_RATE_MASK_BASIC; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2121 | } else { |
| 2122 | /* init ap data */ |
| 2123 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2124 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2125 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2126 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2127 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2128 | wl12xx_allocate_rate_policy(wl, |
| 2129 | &wlvif->ap.ucast_rate_idx[i]); |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 2130 | wlvif->basic_rate_set = CONF_TX_ENABLED_RATES; |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 2131 | /* |
| 2132 | * TODO: check if basic_rate shouldn't be |
| 2133 | * wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 2134 | * instead (the same thing for STA above). |
| 2135 | */ |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 2136 | wlvif->basic_rate = CONF_TX_ENABLED_RATES; |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 2137 | /* TODO: this seems to be used only for STA, check it */ |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 2138 | wlvif->rate_set = CONF_TX_ENABLED_RATES; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2139 | } |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2140 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2141 | wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; |
| 2142 | wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 2143 | wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; |
| 2144 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2145 | /* |
| 2146 | * mac80211 configures some values globally, while we treat them |
| 2147 | * per-interface. thus, on init, we have to copy them from wl |
| 2148 | */ |
| 2149 | wlvif->band = wl->band; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2150 | wlvif->channel = wl->channel; |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2151 | wlvif->power_level = wl->power_level; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 2152 | wlvif->channel_type = wl->channel_type; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2153 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2154 | INIT_WORK(&wlvif->rx_streaming_enable_work, |
| 2155 | wl1271_rx_streaming_enable_work); |
| 2156 | INIT_WORK(&wlvif->rx_streaming_disable_work, |
| 2157 | wl1271_rx_streaming_disable_work); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2158 | INIT_DELAYED_WORK(&wlvif->channel_switch_work, |
| 2159 | wlcore_channel_switch_work); |
| 2160 | INIT_DELAYED_WORK(&wlvif->connection_loss_work, |
| 2161 | wlcore_connection_loss_work); |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2162 | INIT_LIST_HEAD(&wlvif->list); |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2163 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2164 | setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, |
| 2165 | (unsigned long) wlvif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2166 | return 0; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2167 | } |
| 2168 | |
Luciano Coelho | 5dc283f | 2013-01-30 10:53:14 +0200 | [diff] [blame] | 2169 | static int wl12xx_init_fw(struct wl1271 *wl) |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2170 | { |
| 2171 | int retries = WL1271_BOOT_RETRIES; |
| 2172 | bool booted = false; |
| 2173 | struct wiphy *wiphy = wl->hw->wiphy; |
| 2174 | int ret; |
| 2175 | |
| 2176 | while (retries) { |
| 2177 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2178 | ret = wl12xx_chip_wakeup(wl, false); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2179 | if (ret < 0) |
| 2180 | goto power_off; |
| 2181 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 2182 | ret = wl->ops->boot(wl); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2183 | if (ret < 0) |
| 2184 | goto power_off; |
| 2185 | |
| 2186 | ret = wl1271_hw_init(wl); |
| 2187 | if (ret < 0) |
| 2188 | goto irq_disable; |
| 2189 | |
| 2190 | booted = true; |
| 2191 | break; |
| 2192 | |
| 2193 | irq_disable: |
| 2194 | mutex_unlock(&wl->mutex); |
| 2195 | /* Unlocking the mutex in the middle of handling is |
| 2196 | inherently unsafe. In this case we deem it safe to do, |
| 2197 | because we need to let any possibly pending IRQ out of |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2198 | the system (and while we are WLCORE_STATE_OFF the IRQ |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2199 | work function will not do anything.) Also, any other |
| 2200 | possible concurrent operations will fail due to the |
| 2201 | current state, hence the wl1271 struct should be safe. */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 2202 | wlcore_disable_interrupts(wl); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2203 | wl1271_flush_deferred_work(wl); |
| 2204 | cancel_work_sync(&wl->netstack_work); |
| 2205 | mutex_lock(&wl->mutex); |
| 2206 | power_off: |
| 2207 | wl1271_power_off(wl); |
| 2208 | } |
| 2209 | |
| 2210 | if (!booted) { |
| 2211 | wl1271_error("firmware boot failed despite %d retries", |
| 2212 | WL1271_BOOT_RETRIES); |
| 2213 | goto out; |
| 2214 | } |
| 2215 | |
| 2216 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); |
| 2217 | |
| 2218 | /* update hw/fw version info in wiphy struct */ |
| 2219 | wiphy->hw_version = wl->chip.id; |
| 2220 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 2221 | sizeof(wiphy->fw_version)); |
| 2222 | |
| 2223 | /* |
| 2224 | * Now we know if 11a is supported (info from the NVS), so disable |
| 2225 | * 11a channels if not supported |
| 2226 | */ |
| 2227 | if (!wl->enable_11a) |
| 2228 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; |
| 2229 | |
| 2230 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", |
| 2231 | wl->enable_11a ? "" : "not "); |
| 2232 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2233 | wl->state = WLCORE_STATE_ON; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2234 | out: |
Luciano Coelho | 5dc283f | 2013-01-30 10:53:14 +0200 | [diff] [blame] | 2235 | return ret; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2238 | static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif) |
| 2239 | { |
| 2240 | return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID; |
| 2241 | } |
| 2242 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2243 | /* |
| 2244 | * Check whether a fw switch (i.e. moving from one loaded |
| 2245 | * fw to another) is needed. This function is also responsible |
| 2246 | * for updating wl->last_vif_count, so it must be called before |
| 2247 | * loading a non-plt fw (so the correct fw (single-role/multi-role) |
| 2248 | * will be used). |
| 2249 | */ |
| 2250 | static bool wl12xx_need_fw_change(struct wl1271 *wl, |
| 2251 | struct vif_counter_data vif_counter_data, |
| 2252 | bool add) |
| 2253 | { |
| 2254 | enum wl12xx_fw_type current_fw = wl->fw_type; |
| 2255 | u8 vif_count = vif_counter_data.counter; |
| 2256 | |
| 2257 | if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags)) |
| 2258 | return false; |
| 2259 | |
| 2260 | /* increase the vif count if this is a new vif */ |
| 2261 | if (add && !vif_counter_data.cur_vif_running) |
| 2262 | vif_count++; |
| 2263 | |
| 2264 | wl->last_vif_count = vif_count; |
| 2265 | |
| 2266 | /* no need for fw change if the device is OFF */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2267 | if (wl->state == WLCORE_STATE_OFF) |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2268 | return false; |
| 2269 | |
Eliad Peller | 9b1a0a7 | 2012-07-25 14:22:21 +0300 | [diff] [blame] | 2270 | /* no need for fw change if a single fw is used */ |
| 2271 | if (!wl->mr_fw_name) |
| 2272 | return false; |
| 2273 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2274 | if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL) |
| 2275 | return true; |
| 2276 | if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI) |
| 2277 | return true; |
| 2278 | |
| 2279 | return false; |
| 2280 | } |
| 2281 | |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2282 | /* |
| 2283 | * Enter "forced psm". Make sure the sta is in psm against the ap, |
| 2284 | * to make the fw switch a bit more disconnection-persistent. |
| 2285 | */ |
| 2286 | static void wl12xx_force_active_psm(struct wl1271 *wl) |
| 2287 | { |
| 2288 | struct wl12xx_vif *wlvif; |
| 2289 | |
| 2290 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 2291 | wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE); |
| 2292 | } |
| 2293 | } |
| 2294 | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 2295 | struct wlcore_hw_queue_iter_data { |
| 2296 | unsigned long hw_queue_map[BITS_TO_LONGS(WLCORE_NUM_MAC_ADDRESSES)]; |
| 2297 | /* current vif */ |
| 2298 | struct ieee80211_vif *vif; |
| 2299 | /* is the current vif among those iterated */ |
| 2300 | bool cur_running; |
| 2301 | }; |
| 2302 | |
| 2303 | static void wlcore_hw_queue_iter(void *data, u8 *mac, |
| 2304 | struct ieee80211_vif *vif) |
| 2305 | { |
| 2306 | struct wlcore_hw_queue_iter_data *iter_data = data; |
| 2307 | |
| 2308 | if (WARN_ON_ONCE(vif->hw_queue[0] == IEEE80211_INVAL_HW_QUEUE)) |
| 2309 | return; |
| 2310 | |
| 2311 | if (iter_data->cur_running || vif == iter_data->vif) { |
| 2312 | iter_data->cur_running = true; |
| 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | __set_bit(vif->hw_queue[0] / NUM_TX_QUEUES, iter_data->hw_queue_map); |
| 2317 | } |
| 2318 | |
| 2319 | static int wlcore_allocate_hw_queue_base(struct wl1271 *wl, |
| 2320 | struct wl12xx_vif *wlvif) |
| 2321 | { |
| 2322 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2323 | struct wlcore_hw_queue_iter_data iter_data = {}; |
| 2324 | int i, q_base; |
| 2325 | |
| 2326 | iter_data.vif = vif; |
| 2327 | |
| 2328 | /* mark all bits taken by active interfaces */ |
| 2329 | ieee80211_iterate_active_interfaces_atomic(wl->hw, |
| 2330 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 2331 | wlcore_hw_queue_iter, &iter_data); |
| 2332 | |
| 2333 | /* the current vif is already running in mac80211 (resume/recovery) */ |
| 2334 | if (iter_data.cur_running) { |
| 2335 | wlvif->hw_queue_base = vif->hw_queue[0]; |
| 2336 | wl1271_debug(DEBUG_MAC80211, |
| 2337 | "using pre-allocated hw queue base %d", |
| 2338 | wlvif->hw_queue_base); |
| 2339 | |
| 2340 | /* interface type might have changed type */ |
| 2341 | goto adjust_cab_queue; |
| 2342 | } |
| 2343 | |
| 2344 | q_base = find_first_zero_bit(iter_data.hw_queue_map, |
| 2345 | WLCORE_NUM_MAC_ADDRESSES); |
| 2346 | if (q_base >= WLCORE_NUM_MAC_ADDRESSES) |
| 2347 | return -EBUSY; |
| 2348 | |
| 2349 | wlvif->hw_queue_base = q_base * NUM_TX_QUEUES; |
| 2350 | wl1271_debug(DEBUG_MAC80211, "allocating hw queue base: %d", |
| 2351 | wlvif->hw_queue_base); |
| 2352 | |
| 2353 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 2354 | wl->queue_stop_reasons[wlvif->hw_queue_base + i] = 0; |
| 2355 | /* register hw queues in mac80211 */ |
| 2356 | vif->hw_queue[i] = wlvif->hw_queue_base + i; |
| 2357 | } |
| 2358 | |
| 2359 | adjust_cab_queue: |
| 2360 | /* the last places are reserved for cab queues per interface */ |
| 2361 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2362 | vif->cab_queue = NUM_TX_QUEUES * WLCORE_NUM_MAC_ADDRESSES + |
| 2363 | wlvif->hw_queue_base / NUM_TX_QUEUES; |
| 2364 | else |
| 2365 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; |
| 2366 | |
| 2367 | return 0; |
| 2368 | } |
| 2369 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2370 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, |
| 2371 | struct ieee80211_vif *vif) |
| 2372 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2373 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2374 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2375 | struct vif_counter_data vif_count; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2376 | int ret = 0; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2377 | u8 role_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2378 | |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2379 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 2380 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 2381 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2382 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2383 | ieee80211_vif_type_p2p(vif), vif->addr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2384 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2385 | wl12xx_get_vif_count(hw, vif, &vif_count); |
| 2386 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2387 | mutex_lock(&wl->mutex); |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2388 | ret = wl1271_ps_elp_wakeup(wl); |
| 2389 | if (ret < 0) |
| 2390 | goto out_unlock; |
| 2391 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2392 | /* |
| 2393 | * in some very corner case HW recovery scenarios its possible to |
| 2394 | * get here before __wl1271_op_remove_interface is complete, so |
| 2395 | * opt out if that is the case. |
| 2396 | */ |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2397 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) || |
| 2398 | test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) { |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2399 | ret = -EBUSY; |
| 2400 | goto out; |
| 2401 | } |
| 2402 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2403 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2404 | ret = wl12xx_init_vif_data(wl, vif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2405 | if (ret < 0) |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2406 | goto out; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2407 | |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2408 | wlvif->wl = wl; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2409 | role_type = wl12xx_get_role_type(wl, wlvif); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2410 | if (role_type == WL12XX_INVALID_ROLE_TYPE) { |
| 2411 | ret = -EINVAL; |
| 2412 | goto out; |
| 2413 | } |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2414 | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 2415 | ret = wlcore_allocate_hw_queue_base(wl, wlvif); |
| 2416 | if (ret < 0) |
| 2417 | goto out; |
| 2418 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2419 | if (wl12xx_need_fw_change(wl, vif_count, true)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2420 | wl12xx_force_active_psm(wl); |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2421 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2422 | mutex_unlock(&wl->mutex); |
| 2423 | wl1271_recovery_work(&wl->recovery_work); |
| 2424 | return 0; |
| 2425 | } |
| 2426 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2427 | /* |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2428 | * TODO: after the nvs issue will be solved, move this block |
| 2429 | * to start(), and make sure here the driver is ON. |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2430 | */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2431 | if (wl->state == WLCORE_STATE_OFF) { |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2432 | /* |
| 2433 | * we still need this in order to configure the fw |
| 2434 | * while uploading the nvs |
| 2435 | */ |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 2436 | memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2437 | |
Luciano Coelho | 5dc283f | 2013-01-30 10:53:14 +0200 | [diff] [blame] | 2438 | ret = wl12xx_init_fw(wl); |
| 2439 | if (ret < 0) |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2440 | goto out; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2441 | } |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2442 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2443 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
| 2444 | role_type, &wlvif->role_id); |
| 2445 | if (ret < 0) |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2446 | goto out; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2447 | |
| 2448 | ret = wl1271_init_vif_specific(wl, vif); |
| 2449 | if (ret < 0) |
| 2450 | goto out; |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2451 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2452 | list_add(&wlvif->list, &wl->wlvif_list); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2453 | set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags); |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2454 | |
| 2455 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2456 | wl->ap_count++; |
| 2457 | else |
| 2458 | wl->sta_count++; |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 2459 | out: |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2460 | wl1271_ps_elp_sleep(wl); |
| 2461 | out_unlock: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2462 | mutex_unlock(&wl->mutex); |
| 2463 | |
| 2464 | return ret; |
| 2465 | } |
| 2466 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2467 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2468 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2469 | bool reset_tx_queues) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2470 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2471 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2472 | int i, ret; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2473 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2474 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2475 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2476 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2477 | if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2478 | return; |
| 2479 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2480 | /* because of hardware recovery, we may get here twice */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2481 | if (wl->state == WLCORE_STATE_OFF) |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2482 | return; |
| 2483 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2484 | wl1271_info("down"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2485 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2486 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE && |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2487 | wl->scan_wlvif == wlvif) { |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 2488 | /* |
| 2489 | * Rearm the tx watchdog just before idling scan. This |
| 2490 | * prevents just-finished scans from triggering the watchdog |
| 2491 | */ |
| 2492 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 2493 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 2494 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 2495 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2496 | wl->scan_wlvif = NULL; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 2497 | wl->scan.req = NULL; |
Juuso Oikarinen | 76a029f | 2010-07-29 04:54:45 +0300 | [diff] [blame] | 2498 | ieee80211_scan_completed(wl->hw, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2499 | } |
| 2500 | |
Eliad Peller | 1019975 | 2012-11-22 18:06:23 +0200 | [diff] [blame] | 2501 | if (wl->sched_vif == wlvif) { |
| 2502 | ieee80211_sched_scan_stopped(wl->hw); |
| 2503 | wl->sched_vif = NULL; |
| 2504 | } |
| 2505 | |
Arik Nemtsov | 5d979f3 | 2012-11-27 08:44:48 +0200 | [diff] [blame] | 2506 | if (wl->roc_vif == vif) { |
| 2507 | wl->roc_vif = NULL; |
| 2508 | ieee80211_remain_on_channel_expired(wl->hw); |
| 2509 | } |
| 2510 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2511 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 2512 | /* disable active roles */ |
| 2513 | ret = wl1271_ps_elp_wakeup(wl); |
| 2514 | if (ret < 0) |
| 2515 | goto deinit; |
| 2516 | |
Eliad Peller | b890f4c | 2011-12-18 20:25:44 +0200 | [diff] [blame] | 2517 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2518 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2519 | if (wl12xx_dev_role_started(wlvif)) |
| 2520 | wl12xx_stop_dev(wl, wlvif); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2521 | } |
| 2522 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2523 | ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2524 | if (ret < 0) |
| 2525 | goto deinit; |
| 2526 | |
| 2527 | wl1271_ps_elp_sleep(wl); |
| 2528 | } |
| 2529 | deinit: |
Arik Nemtsov | 5a99610 | 2013-03-12 17:19:43 +0200 | [diff] [blame] | 2530 | wl12xx_tx_reset_wlvif(wl, wlvif); |
| 2531 | |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 2532 | /* clear all hlids (except system_hlid) */ |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2533 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2534 | |
| 2535 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2536 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2537 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
| 2538 | wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2539 | wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2540 | wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2541 | wlcore_free_klv_template(wl, &wlvif->sta.klv_template_id); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2542 | } else { |
| 2543 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2544 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
| 2545 | wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2546 | wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2547 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2548 | wl12xx_free_rate_policy(wl, |
| 2549 | &wlvif->ap.ucast_rate_idx[i]); |
Eliad Peller | 830be7e | 2012-03-19 11:32:55 +0200 | [diff] [blame] | 2550 | wl1271_free_ap_keys(wl, wlvif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2551 | } |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2552 | |
Eyal Shapira | 3eba4a0 | 2012-03-19 12:06:27 +0200 | [diff] [blame] | 2553 | dev_kfree_skb(wlvif->probereq); |
| 2554 | wlvif->probereq = NULL; |
Eliad Peller | e4120df | 2011-10-10 10:13:17 +0200 | [diff] [blame] | 2555 | if (wl->last_wlvif == wlvif) |
| 2556 | wl->last_wlvif = NULL; |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2557 | list_del(&wlvif->list); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 2558 | memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map)); |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2559 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2560 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Luciano Coelho | d6e19d1 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 2561 | |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2562 | if (is_ap) |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2563 | wl->ap_count--; |
| 2564 | else |
| 2565 | wl->sta_count--; |
| 2566 | |
Arik Nemtsov | 42066f9 | 2012-07-10 10:45:01 +0300 | [diff] [blame] | 2567 | /* |
| 2568 | * Last AP, have more stations. Configure sleep auth according to STA. |
| 2569 | * Don't do thin on unintended recovery. |
| 2570 | */ |
| 2571 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) && |
| 2572 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)) |
| 2573 | goto unlock; |
| 2574 | |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2575 | if (wl->ap_count == 0 && is_ap && wl->sta_count) { |
| 2576 | u8 sta_auth = wl->conf.conn.sta_sleep_auth; |
| 2577 | /* Configure for power according to debugfs */ |
| 2578 | if (sta_auth != WL1271_PSM_ILLEGAL) |
| 2579 | wl1271_acx_sleep_auth(wl, sta_auth); |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2580 | /* Configure for ELP power saving */ |
| 2581 | else |
| 2582 | wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); |
| 2583 | } |
| 2584 | |
Arik Nemtsov | 42066f9 | 2012-07-10 10:45:01 +0300 | [diff] [blame] | 2585 | unlock: |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2586 | mutex_unlock(&wl->mutex); |
Eyal Shapira | d6bf9ad | 2012-01-31 11:57:20 +0200 | [diff] [blame] | 2587 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2588 | del_timer_sync(&wlvif->rx_streaming_timer); |
| 2589 | cancel_work_sync(&wlvif->rx_streaming_enable_work); |
| 2590 | cancel_work_sync(&wlvif->rx_streaming_disable_work); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2591 | cancel_delayed_work_sync(&wlvif->connection_loss_work); |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 2592 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2593 | mutex_lock(&wl->mutex); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2594 | } |
Juuso Oikarinen | bd9dc49 | 2010-04-09 11:07:26 +0300 | [diff] [blame] | 2595 | |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2596 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, |
| 2597 | struct ieee80211_vif *vif) |
| 2598 | { |
| 2599 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2600 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2601 | struct wl12xx_vif *iter; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2602 | struct vif_counter_data vif_count; |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2603 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2604 | wl12xx_get_vif_count(hw, vif, &vif_count); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2605 | mutex_lock(&wl->mutex); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2606 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2607 | if (wl->state == WLCORE_STATE_OFF || |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2608 | !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2609 | goto out; |
| 2610 | |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2611 | /* |
| 2612 | * wl->vif can be null here if someone shuts down the interface |
| 2613 | * just when hardware recovery has been started. |
| 2614 | */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2615 | wl12xx_for_each_wlvif(wl, iter) { |
| 2616 | if (iter != wlvif) |
| 2617 | continue; |
| 2618 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2619 | __wl1271_op_remove_interface(wl, vif, true); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2620 | break; |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2621 | } |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2622 | WARN_ON(iter != wlvif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2623 | if (wl12xx_need_fw_change(wl, vif_count, false)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2624 | wl12xx_force_active_psm(wl); |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2625 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2626 | wl12xx_queue_recovery_work(wl); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2627 | } |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2628 | out: |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2629 | mutex_unlock(&wl->mutex); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2630 | } |
| 2631 | |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2632 | static int wl12xx_op_change_interface(struct ieee80211_hw *hw, |
| 2633 | struct ieee80211_vif *vif, |
| 2634 | enum nl80211_iftype new_type, bool p2p) |
| 2635 | { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2636 | struct wl1271 *wl = hw->priv; |
| 2637 | int ret; |
| 2638 | |
| 2639 | set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2640 | wl1271_op_remove_interface(hw, vif); |
| 2641 | |
Eliad Peller | 249e969 | 2012-03-04 10:55:50 +0200 | [diff] [blame] | 2642 | vif->type = new_type; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2643 | vif->p2p = p2p; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2644 | ret = wl1271_op_add_interface(hw, vif); |
| 2645 | |
| 2646 | clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
| 2647 | return ret; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2648 | } |
| 2649 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2650 | static int wlcore_join(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2651 | { |
| 2652 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2653 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2654 | |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2655 | /* |
| 2656 | * One of the side effects of the JOIN command is that is clears |
| 2657 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated |
| 2658 | * to a WPA/WPA2 access point will therefore kill the data-path. |
Ohad Ben-Cohen | 8bf69aa | 2011-03-30 19:18:31 +0200 | [diff] [blame] | 2659 | * Currently the only valid scenario for JOIN during association |
| 2660 | * is on roaming, in which case we will also be given new keys. |
| 2661 | * Keep the below message for now, unless it starts bothering |
| 2662 | * users who really like to roam a lot :) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2663 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2664 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2665 | wl1271_info("JOIN while associated."); |
| 2666 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 2667 | /* clear encryption type */ |
| 2668 | wlvif->encryption_type = KEY_NONE; |
| 2669 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2670 | if (is_ibss) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2671 | ret = wl12xx_cmd_role_start_ibss(wl, wlvif); |
Eliad Peller | 18eab43 | 2012-11-20 13:20:02 +0200 | [diff] [blame] | 2672 | else { |
| 2673 | if (wl->quirks & WLCORE_QUIRK_START_STA_FAILS) { |
| 2674 | /* |
| 2675 | * TODO: this is an ugly workaround for wl12xx fw |
| 2676 | * bug - we are not able to tx/rx after the first |
| 2677 | * start_sta, so make dummy start+stop calls, |
| 2678 | * and then call start_sta again. |
| 2679 | * this should be fixed in the fw. |
| 2680 | */ |
| 2681 | wl12xx_cmd_role_start_sta(wl, wlvif); |
| 2682 | wl12xx_cmd_role_stop_sta(wl, wlvif); |
| 2683 | } |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2684 | |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2685 | ret = wl12xx_cmd_role_start_sta(wl, wlvif); |
Eliad Peller | 18eab43 | 2012-11-20 13:20:02 +0200 | [diff] [blame] | 2686 | } |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2687 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2688 | return ret; |
| 2689 | } |
| 2690 | |
| 2691 | static int wl1271_ssid_set(struct wl12xx_vif *wlvif, struct sk_buff *skb, |
| 2692 | int offset) |
| 2693 | { |
| 2694 | u8 ssid_len; |
| 2695 | const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, |
| 2696 | skb->len - offset); |
| 2697 | |
| 2698 | if (!ptr) { |
| 2699 | wl1271_error("No SSID in IEs!"); |
| 2700 | return -ENOENT; |
| 2701 | } |
| 2702 | |
| 2703 | ssid_len = ptr[1]; |
| 2704 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 2705 | wl1271_error("SSID is too long!"); |
| 2706 | return -EINVAL; |
| 2707 | } |
| 2708 | |
| 2709 | wlvif->ssid_len = ssid_len; |
| 2710 | memcpy(wlvif->ssid, ptr+2, ssid_len); |
| 2711 | return 0; |
| 2712 | } |
| 2713 | |
| 2714 | static int wlcore_set_ssid(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 2715 | { |
| 2716 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2717 | struct sk_buff *skb; |
| 2718 | int ieoffset; |
| 2719 | |
| 2720 | /* we currently only support setting the ssid from the ap probe req */ |
| 2721 | if (wlvif->bss_type != BSS_TYPE_STA_BSS) |
| 2722 | return -EINVAL; |
| 2723 | |
| 2724 | skb = ieee80211_ap_probereq_get(wl->hw, vif); |
| 2725 | if (!skb) |
| 2726 | return -EINVAL; |
| 2727 | |
| 2728 | ieoffset = offsetof(struct ieee80211_mgmt, |
| 2729 | u.probe_req.variable); |
| 2730 | wl1271_ssid_set(wlvif, skb, ieoffset); |
| 2731 | dev_kfree_skb(skb); |
| 2732 | |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
| 2736 | static int wlcore_set_assoc(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 2737 | struct ieee80211_bss_conf *bss_conf, |
| 2738 | u32 sta_rate_set) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2739 | { |
| 2740 | int ieoffset; |
| 2741 | int ret; |
| 2742 | |
| 2743 | wlvif->aid = bss_conf->aid; |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 2744 | wlvif->channel_type = cfg80211_get_chandef_type(&bss_conf->chandef); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2745 | wlvif->beacon_int = bss_conf->beacon_int; |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 2746 | wlvif->wmm_enabled = bss_conf->qos; |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2747 | |
| 2748 | set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags); |
| 2749 | |
| 2750 | /* |
| 2751 | * with wl1271, we don't need to update the |
| 2752 | * beacon_int and dtim_period, because the firmware |
| 2753 | * updates it by itself when the first beacon is |
| 2754 | * received after a join. |
| 2755 | */ |
| 2756 | ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid); |
| 2757 | if (ret < 0) |
| 2758 | return ret; |
| 2759 | |
| 2760 | /* |
| 2761 | * Get a template for hardware connection maintenance |
| 2762 | */ |
| 2763 | dev_kfree_skb(wlvif->probereq); |
| 2764 | wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl, |
| 2765 | wlvif, |
| 2766 | NULL); |
| 2767 | ieoffset = offsetof(struct ieee80211_mgmt, |
| 2768 | u.probe_req.variable); |
| 2769 | wl1271_ssid_set(wlvif, wlvif->probereq, ieoffset); |
| 2770 | |
| 2771 | /* enable the connection monitoring feature */ |
| 2772 | ret = wl1271_acx_conn_monit_params(wl, wlvif, true); |
| 2773 | if (ret < 0) |
| 2774 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2775 | |
| 2776 | /* |
| 2777 | * The join command disable the keep-alive mode, shut down its process, |
| 2778 | * and also clear the template config, so we need to reset it all after |
| 2779 | * the join. The acx_aid starts the keep-alive process, and the order |
| 2780 | * of the commands below is relevant. |
| 2781 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2782 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, true); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2783 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2784 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2785 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2786 | ret = wl1271_acx_aid(wl, wlvif, wlvif->aid); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2787 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2788 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2789 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2790 | ret = wl12xx_cmd_build_klv_null_data(wl, wlvif); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2791 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2792 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2793 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2794 | ret = wl1271_acx_keep_alive_config(wl, wlvif, |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2795 | wlvif->sta.klv_template_id, |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2796 | ACX_KEEP_ALIVE_TPL_VALID); |
| 2797 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2798 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2799 | |
Eliad Peller | 6c7b519 | 2012-11-20 13:20:07 +0200 | [diff] [blame] | 2800 | /* |
| 2801 | * The default fw psm configuration is AUTO, while mac80211 default |
| 2802 | * setting is off (ACTIVE), so sync the fw with the correct value. |
| 2803 | */ |
| 2804 | ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE); |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 2805 | if (ret < 0) |
| 2806 | return ret; |
| 2807 | |
| 2808 | if (sta_rate_set) { |
| 2809 | wlvif->rate_set = |
| 2810 | wl1271_tx_enabled_rates_get(wl, |
| 2811 | sta_rate_set, |
| 2812 | wlvif->band); |
| 2813 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 2814 | if (ret < 0) |
| 2815 | return ret; |
| 2816 | } |
Eliad Peller | 6c7b519 | 2012-11-20 13:20:07 +0200 | [diff] [blame] | 2817 | |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2818 | return ret; |
| 2819 | } |
| 2820 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2821 | static int wlcore_unset_assoc(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2822 | { |
| 2823 | int ret; |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2824 | bool sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
| 2825 | |
| 2826 | /* make sure we are connected (sta) joined */ |
| 2827 | if (sta && |
| 2828 | !test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 2829 | return false; |
| 2830 | |
| 2831 | /* make sure we are joined (ibss) */ |
| 2832 | if (!sta && |
| 2833 | test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) |
| 2834 | return false; |
| 2835 | |
| 2836 | if (sta) { |
| 2837 | /* use defaults when not associated */ |
| 2838 | wlvif->aid = 0; |
| 2839 | |
| 2840 | /* free probe-request template */ |
| 2841 | dev_kfree_skb(wlvif->probereq); |
| 2842 | wlvif->probereq = NULL; |
| 2843 | |
| 2844 | /* disable connection monitor features */ |
| 2845 | ret = wl1271_acx_conn_monit_params(wl, wlvif, false); |
| 2846 | if (ret < 0) |
| 2847 | return ret; |
| 2848 | |
| 2849 | /* Disable the keep-alive feature */ |
| 2850 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, false); |
| 2851 | if (ret < 0) |
| 2852 | return ret; |
| 2853 | } |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2854 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 2855 | if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2856 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2857 | |
Eliad Peller | fcab189 | 2012-11-22 18:06:18 +0200 | [diff] [blame] | 2858 | wl12xx_cmd_stop_channel_switch(wl, wlvif); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2859 | ieee80211_chswitch_done(vif, false); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2860 | cancel_delayed_work(&wlvif->channel_switch_work); |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2861 | } |
| 2862 | |
Eliad Peller | 4137c17 | 2012-08-16 13:32:32 +0300 | [diff] [blame] | 2863 | /* invalidate keep-alive template */ |
| 2864 | wl1271_acx_keep_alive_config(wl, wlvif, |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2865 | wlvif->sta.klv_template_id, |
Eliad Peller | 4137c17 | 2012-08-16 13:32:32 +0300 | [diff] [blame] | 2866 | ACX_KEEP_ALIVE_TPL_INVALID); |
| 2867 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2868 | return 0; |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2869 | } |
| 2870 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2871 | static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2872 | { |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2873 | wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band]; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2874 | wlvif->rate_set = wlvif->basic_rate_set; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2875 | } |
| 2876 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2877 | static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2878 | struct ieee80211_conf *conf, u32 changed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2879 | { |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 2880 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2881 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2882 | if (conf->power_level != wlvif->power_level) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2883 | ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2884 | if (ret < 0) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2885 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2886 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2887 | wlvif->power_level = conf->power_level; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2888 | } |
| 2889 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2890 | return 0; |
| 2891 | } |
| 2892 | |
| 2893 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) |
| 2894 | { |
| 2895 | struct wl1271 *wl = hw->priv; |
| 2896 | struct wl12xx_vif *wlvif; |
| 2897 | struct ieee80211_conf *conf = &hw->conf; |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 2898 | int ret = 0; |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2899 | |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 2900 | wl1271_debug(DEBUG_MAC80211, "mac80211 config psm %s power %d %s" |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2901 | " changed 0x%x", |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2902 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", |
| 2903 | conf->power_level, |
| 2904 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", |
| 2905 | changed); |
| 2906 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2907 | mutex_lock(&wl->mutex); |
| 2908 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2909 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 2910 | wl->power_level = conf->power_level; |
| 2911 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2912 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2913 | goto out; |
| 2914 | |
| 2915 | ret = wl1271_ps_elp_wakeup(wl); |
| 2916 | if (ret < 0) |
| 2917 | goto out; |
| 2918 | |
| 2919 | /* configure each interface */ |
| 2920 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 2921 | ret = wl12xx_config_vif(wl, wlvif, conf, changed); |
| 2922 | if (ret < 0) |
| 2923 | goto out_sleep; |
| 2924 | } |
| 2925 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2926 | out_sleep: |
| 2927 | wl1271_ps_elp_sleep(wl); |
| 2928 | |
| 2929 | out: |
| 2930 | mutex_unlock(&wl->mutex); |
| 2931 | |
| 2932 | return ret; |
| 2933 | } |
| 2934 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2935 | struct wl1271_filter_params { |
| 2936 | bool enabled; |
| 2937 | int mc_list_length; |
| 2938 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; |
| 2939 | }; |
| 2940 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2941 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, |
| 2942 | struct netdev_hw_addr_list *mc_list) |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2943 | { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2944 | struct wl1271_filter_params *fp; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2945 | struct netdev_hw_addr *ha; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2946 | |
Juuso Oikarinen | 7444113 | 2009-10-13 12:47:53 +0300 | [diff] [blame] | 2947 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2948 | if (!fp) { |
| 2949 | wl1271_error("Out of memory setting filters."); |
| 2950 | return 0; |
| 2951 | } |
| 2952 | |
| 2953 | /* update multicast filtering parameters */ |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2954 | fp->mc_list_length = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2955 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { |
| 2956 | fp->enabled = false; |
| 2957 | } else { |
| 2958 | fp->enabled = true; |
| 2959 | netdev_hw_addr_list_for_each(ha, mc_list) { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2960 | memcpy(fp->mc_list[fp->mc_list_length], |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2961 | ha->addr, ETH_ALEN); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2962 | fp->mc_list_length++; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2963 | } |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2964 | } |
| 2965 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2966 | return (u64)(unsigned long)fp; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2967 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2968 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2969 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ |
| 2970 | FIF_ALLMULTI | \ |
| 2971 | FIF_FCSFAIL | \ |
| 2972 | FIF_BCN_PRBRESP_PROMISC | \ |
| 2973 | FIF_CONTROL | \ |
| 2974 | FIF_OTHER_BSS) |
| 2975 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2976 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, |
| 2977 | unsigned int changed, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2978 | unsigned int *total, u64 multicast) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2979 | { |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2980 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2981 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2982 | struct wl12xx_vif *wlvif; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2983 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2984 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2985 | |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2986 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" |
| 2987 | " total %x", changed, *total); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2988 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2989 | mutex_lock(&wl->mutex); |
| 2990 | |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2991 | *total &= WL1271_SUPPORTED_FILTERS; |
| 2992 | changed &= WL1271_SUPPORTED_FILTERS; |
| 2993 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2994 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2995 | goto out; |
| 2996 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 2997 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2998 | if (ret < 0) |
| 2999 | goto out; |
| 3000 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3001 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 3002 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { |
| 3003 | if (*total & FIF_ALLMULTI) |
| 3004 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 3005 | false, |
| 3006 | NULL, 0); |
| 3007 | else if (fp) |
| 3008 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 3009 | fp->enabled, |
| 3010 | fp->mc_list, |
| 3011 | fp->mc_list_length); |
| 3012 | if (ret < 0) |
| 3013 | goto out_sleep; |
| 3014 | } |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 3015 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3016 | |
Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 3017 | /* |
| 3018 | * the fw doesn't provide an api to configure the filters. instead, |
| 3019 | * the filters configuration is based on the active roles / ROC |
| 3020 | * state. |
| 3021 | */ |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 3022 | |
| 3023 | out_sleep: |
| 3024 | wl1271_ps_elp_sleep(wl); |
| 3025 | |
| 3026 | out: |
| 3027 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 14b228a | 2010-03-18 12:26:43 +0200 | [diff] [blame] | 3028 | kfree(fp); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3029 | } |
| 3030 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3031 | static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 3032 | u8 id, u8 key_type, u8 key_size, |
| 3033 | const u8 *key, u8 hlid, u32 tx_seq_32, |
| 3034 | u16 tx_seq_16) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3035 | { |
| 3036 | struct wl1271_ap_key *ap_key; |
| 3037 | int i; |
| 3038 | |
| 3039 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); |
| 3040 | |
| 3041 | if (key_size > MAX_KEY_SIZE) |
| 3042 | return -EINVAL; |
| 3043 | |
| 3044 | /* |
| 3045 | * Find next free entry in ap_keys. Also check we are not replacing |
| 3046 | * an existing key. |
| 3047 | */ |
| 3048 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3049 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3050 | break; |
| 3051 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3052 | if (wlvif->ap.recorded_keys[i]->id == id) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3053 | wl1271_warning("trying to record key replacement"); |
| 3054 | return -EINVAL; |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | if (i == MAX_NUM_KEYS) |
| 3059 | return -EBUSY; |
| 3060 | |
| 3061 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); |
| 3062 | if (!ap_key) |
| 3063 | return -ENOMEM; |
| 3064 | |
| 3065 | ap_key->id = id; |
| 3066 | ap_key->key_type = key_type; |
| 3067 | ap_key->key_size = key_size; |
| 3068 | memcpy(ap_key->key, key, key_size); |
| 3069 | ap_key->hlid = hlid; |
| 3070 | ap_key->tx_seq_32 = tx_seq_32; |
| 3071 | ap_key->tx_seq_16 = tx_seq_16; |
| 3072 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3073 | wlvif->ap.recorded_keys[i] = ap_key; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3074 | return 0; |
| 3075 | } |
| 3076 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3077 | static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3078 | { |
| 3079 | int i; |
| 3080 | |
| 3081 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3082 | kfree(wlvif->ap.recorded_keys[i]); |
| 3083 | wlvif->ap.recorded_keys[i] = NULL; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3084 | } |
| 3085 | } |
| 3086 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3087 | static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3088 | { |
| 3089 | int i, ret = 0; |
| 3090 | struct wl1271_ap_key *key; |
| 3091 | bool wep_key_added = false; |
| 3092 | |
| 3093 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3094 | u8 hlid; |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3095 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3096 | break; |
| 3097 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3098 | key = wlvif->ap.recorded_keys[i]; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3099 | hlid = key->hlid; |
| 3100 | if (hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3101 | hlid = wlvif->ap.bcast_hlid; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3102 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3103 | ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3104 | key->id, key->key_type, |
| 3105 | key->key_size, key->key, |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3106 | hlid, key->tx_seq_32, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3107 | key->tx_seq_16); |
| 3108 | if (ret < 0) |
| 3109 | goto out; |
| 3110 | |
| 3111 | if (key->key_type == KEY_WEP) |
| 3112 | wep_key_added = true; |
| 3113 | } |
| 3114 | |
| 3115 | if (wep_key_added) { |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 3116 | ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key, |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3117 | wlvif->ap.bcast_hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3118 | if (ret < 0) |
| 3119 | goto out; |
| 3120 | } |
| 3121 | |
| 3122 | out: |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3123 | wl1271_free_ap_keys(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3124 | return ret; |
| 3125 | } |
| 3126 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3127 | static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 3128 | u16 action, u8 id, u8 key_type, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3129 | u8 key_size, const u8 *key, u32 tx_seq_32, |
| 3130 | u16 tx_seq_16, struct ieee80211_sta *sta) |
| 3131 | { |
| 3132 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3133 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3134 | |
| 3135 | if (is_ap) { |
| 3136 | struct wl1271_station *wl_sta; |
| 3137 | u8 hlid; |
| 3138 | |
| 3139 | if (sta) { |
| 3140 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 3141 | hlid = wl_sta->hlid; |
| 3142 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3143 | hlid = wlvif->ap.bcast_hlid; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3144 | } |
| 3145 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3146 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3147 | /* |
| 3148 | * We do not support removing keys after AP shutdown. |
| 3149 | * Pretend we do to make mac80211 happy. |
| 3150 | */ |
| 3151 | if (action != KEY_ADD_OR_REPLACE) |
| 3152 | return 0; |
| 3153 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3154 | ret = wl1271_record_ap_key(wl, wlvif, id, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3155 | key_type, key_size, |
| 3156 | key, hlid, tx_seq_32, |
| 3157 | tx_seq_16); |
| 3158 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3159 | ret = wl1271_cmd_set_ap_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3160 | id, key_type, key_size, |
| 3161 | key, hlid, tx_seq_32, |
| 3162 | tx_seq_16); |
| 3163 | } |
| 3164 | |
| 3165 | if (ret < 0) |
| 3166 | return ret; |
| 3167 | } else { |
| 3168 | const u8 *addr; |
| 3169 | static const u8 bcast_addr[ETH_ALEN] = { |
| 3170 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 3171 | }; |
| 3172 | |
| 3173 | addr = sta ? sta->addr : bcast_addr; |
| 3174 | |
| 3175 | if (is_zero_ether_addr(addr)) { |
| 3176 | /* We dont support TX only encryption */ |
| 3177 | return -EOPNOTSUPP; |
| 3178 | } |
| 3179 | |
| 3180 | /* The wl1271 does not allow to remove unicast keys - they |
| 3181 | will be cleared automatically on next CMD_JOIN. Ignore the |
| 3182 | request silently, as we dont want the mac80211 to emit |
| 3183 | an error message. */ |
| 3184 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) |
| 3185 | return 0; |
| 3186 | |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3187 | /* don't remove key if hlid was already deleted */ |
| 3188 | if (action == KEY_REMOVE && |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3189 | wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3190 | return 0; |
| 3191 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3192 | ret = wl1271_cmd_set_sta_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3193 | id, key_type, key_size, |
| 3194 | key, addr, tx_seq_32, |
| 3195 | tx_seq_16); |
| 3196 | if (ret < 0) |
| 3197 | return ret; |
| 3198 | |
| 3199 | /* the default WEP key needs to be configured at least once */ |
| 3200 | if (key_type == KEY_WEP) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 3201 | ret = wl12xx_cmd_set_default_wep_key(wl, |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 3202 | wlvif->default_key, |
| 3203 | wlvif->sta.hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3204 | if (ret < 0) |
| 3205 | return ret; |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | return 0; |
| 3210 | } |
| 3211 | |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3212 | static int wlcore_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3213 | struct ieee80211_vif *vif, |
| 3214 | struct ieee80211_sta *sta, |
| 3215 | struct ieee80211_key_conf *key_conf) |
| 3216 | { |
| 3217 | struct wl1271 *wl = hw->priv; |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3218 | int ret; |
| 3219 | bool might_change_spare = |
| 3220 | key_conf->cipher == WL1271_CIPHER_SUITE_GEM || |
| 3221 | key_conf->cipher == WLAN_CIPHER_SUITE_TKIP; |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3222 | |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3223 | if (might_change_spare) { |
| 3224 | /* |
| 3225 | * stop the queues and flush to ensure the next packets are |
| 3226 | * in sync with FW spare block accounting |
| 3227 | */ |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3228 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3229 | wl1271_tx_flush(wl); |
| 3230 | } |
| 3231 | |
| 3232 | mutex_lock(&wl->mutex); |
| 3233 | |
| 3234 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
| 3235 | ret = -EAGAIN; |
| 3236 | goto out_wake_queues; |
| 3237 | } |
| 3238 | |
| 3239 | ret = wl1271_ps_elp_wakeup(wl); |
| 3240 | if (ret < 0) |
| 3241 | goto out_wake_queues; |
| 3242 | |
| 3243 | ret = wlcore_hw_set_key(wl, cmd, vif, sta, key_conf); |
| 3244 | |
| 3245 | wl1271_ps_elp_sleep(wl); |
| 3246 | |
| 3247 | out_wake_queues: |
| 3248 | if (might_change_spare) |
| 3249 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK); |
| 3250 | |
| 3251 | mutex_unlock(&wl->mutex); |
| 3252 | |
| 3253 | return ret; |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd, |
| 3257 | struct ieee80211_vif *vif, |
| 3258 | struct ieee80211_sta *sta, |
| 3259 | struct ieee80211_key_conf *key_conf) |
| 3260 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3261 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3262 | int ret; |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 3263 | u32 tx_seq_32 = 0; |
| 3264 | u16 tx_seq_16 = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3265 | u8 key_type; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 3266 | u8 hlid; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3267 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3268 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); |
| 3269 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3270 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3271 | wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x", |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3272 | key_conf->cipher, key_conf->keyidx, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3273 | key_conf->keylen, key_conf->flags); |
| 3274 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); |
| 3275 | |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 3276 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 3277 | if (sta) { |
| 3278 | struct wl1271_station *wl_sta = (void *)sta->drv_priv; |
| 3279 | hlid = wl_sta->hlid; |
| 3280 | } else { |
| 3281 | hlid = wlvif->ap.bcast_hlid; |
| 3282 | } |
| 3283 | else |
| 3284 | hlid = wlvif->sta.hlid; |
| 3285 | |
| 3286 | if (hlid != WL12XX_INVALID_LINK_ID) { |
| 3287 | u64 tx_seq = wl->links[hlid].total_freed_pkts; |
| 3288 | tx_seq_32 = WL1271_TX_SECURITY_HI32(tx_seq); |
| 3289 | tx_seq_16 = WL1271_TX_SECURITY_LO16(tx_seq); |
| 3290 | } |
| 3291 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3292 | switch (key_conf->cipher) { |
| 3293 | case WLAN_CIPHER_SUITE_WEP40: |
| 3294 | case WLAN_CIPHER_SUITE_WEP104: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3295 | key_type = KEY_WEP; |
| 3296 | |
| 3297 | key_conf->hw_key_idx = key_conf->keyidx; |
| 3298 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3299 | case WLAN_CIPHER_SUITE_TKIP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3300 | key_type = KEY_TKIP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3301 | key_conf->hw_key_idx = key_conf->keyidx; |
| 3302 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3303 | case WLAN_CIPHER_SUITE_CCMP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3304 | key_type = KEY_AES; |
Arik Nemtsov | 12d4b97 | 2011-10-23 08:21:54 +0200 | [diff] [blame] | 3305 | key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3306 | break; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3307 | case WL1271_CIPHER_SUITE_GEM: |
| 3308 | key_type = KEY_GEM; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3309 | break; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3310 | default: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3311 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3312 | |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3313 | return -EOPNOTSUPP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | switch (cmd) { |
| 3317 | case SET_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3318 | ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3319 | key_conf->keyidx, key_type, |
| 3320 | key_conf->keylen, key_conf->key, |
| 3321 | tx_seq_32, tx_seq_16, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3322 | if (ret < 0) { |
| 3323 | wl1271_error("Could not add or replace key"); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3324 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3325 | } |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3326 | |
| 3327 | /* |
| 3328 | * reconfiguring arp response if the unicast (or common) |
| 3329 | * encryption key type was changed |
| 3330 | */ |
| 3331 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 3332 | (sta || key_type == KEY_WEP) && |
| 3333 | wlvif->encryption_type != key_type) { |
| 3334 | wlvif->encryption_type = key_type; |
| 3335 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 3336 | if (ret < 0) { |
| 3337 | wl1271_warning("build arp rsp failed: %d", ret); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3338 | return ret; |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3339 | } |
| 3340 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3341 | break; |
| 3342 | |
| 3343 | case DISABLE_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3344 | ret = wl1271_set_key(wl, wlvif, KEY_REMOVE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3345 | key_conf->keyidx, key_type, |
| 3346 | key_conf->keylen, key_conf->key, |
| 3347 | 0, 0, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3348 | if (ret < 0) { |
| 3349 | wl1271_error("Could not remove key"); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3350 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3351 | } |
| 3352 | break; |
| 3353 | |
| 3354 | default: |
| 3355 | wl1271_error("Unsupported key cmd 0x%x", cmd); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3356 | return -EOPNOTSUPP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3357 | } |
| 3358 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3359 | return ret; |
| 3360 | } |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3361 | EXPORT_SYMBOL_GPL(wlcore_set_key); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3362 | |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 3363 | void wlcore_regdomain_config(struct wl1271 *wl) |
| 3364 | { |
| 3365 | int ret; |
| 3366 | |
| 3367 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) |
| 3368 | return; |
| 3369 | |
| 3370 | mutex_lock(&wl->mutex); |
Arik Nemtsov | 75592be | 2013-03-12 17:19:45 +0200 | [diff] [blame] | 3371 | |
| 3372 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 3373 | goto out; |
| 3374 | |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 3375 | ret = wl1271_ps_elp_wakeup(wl); |
| 3376 | if (ret < 0) |
| 3377 | goto out; |
| 3378 | |
| 3379 | ret = wlcore_cmd_regdomain_config_locked(wl); |
| 3380 | if (ret < 0) { |
| 3381 | wl12xx_queue_recovery_work(wl); |
| 3382 | goto out; |
| 3383 | } |
| 3384 | |
| 3385 | wl1271_ps_elp_sleep(wl); |
| 3386 | out: |
| 3387 | mutex_unlock(&wl->mutex); |
| 3388 | } |
| 3389 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3390 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, |
Johannes Berg | a060bbf | 2010-04-27 11:59:34 +0200 | [diff] [blame] | 3391 | struct ieee80211_vif *vif, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3392 | struct cfg80211_scan_request *req) |
| 3393 | { |
| 3394 | struct wl1271 *wl = hw->priv; |
| 3395 | int ret; |
| 3396 | u8 *ssid = NULL; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3397 | size_t len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3398 | |
| 3399 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); |
| 3400 | |
| 3401 | if (req->n_ssids) { |
| 3402 | ssid = req->ssids[0].ssid; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3403 | len = req->ssids[0].ssid_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | mutex_lock(&wl->mutex); |
| 3407 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3408 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 3409 | /* |
| 3410 | * We cannot return -EBUSY here because cfg80211 will expect |
| 3411 | * a call to ieee80211_scan_completed if we do - in this case |
| 3412 | * there won't be any call. |
| 3413 | */ |
| 3414 | ret = -EAGAIN; |
| 3415 | goto out; |
| 3416 | } |
| 3417 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3418 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3419 | if (ret < 0) |
| 3420 | goto out; |
| 3421 | |
Eliad Peller | 97fd311 | 2012-03-04 10:55:52 +0200 | [diff] [blame] | 3422 | /* fail if there is any role in ROC */ |
| 3423 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3424 | /* don't allow scanning right now */ |
| 3425 | ret = -EBUSY; |
| 3426 | goto out_sleep; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3427 | } |
| 3428 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3429 | ret = wlcore_scan(hw->priv, vif, ssid, len, req); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3430 | out_sleep: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3431 | wl1271_ps_elp_sleep(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3432 | out: |
| 3433 | mutex_unlock(&wl->mutex); |
| 3434 | |
| 3435 | return ret; |
| 3436 | } |
| 3437 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3438 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, |
| 3439 | struct ieee80211_vif *vif) |
| 3440 | { |
| 3441 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3442 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3443 | int ret; |
| 3444 | |
| 3445 | wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); |
| 3446 | |
| 3447 | mutex_lock(&wl->mutex); |
| 3448 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3449 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3450 | goto out; |
| 3451 | |
| 3452 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) |
| 3453 | goto out; |
| 3454 | |
| 3455 | ret = wl1271_ps_elp_wakeup(wl); |
| 3456 | if (ret < 0) |
| 3457 | goto out; |
| 3458 | |
| 3459 | if (wl->scan.state != WL1271_SCAN_STATE_DONE) { |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3460 | ret = wl->ops->scan_stop(wl, wlvif); |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3461 | if (ret < 0) |
| 3462 | goto out_sleep; |
| 3463 | } |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 3464 | |
| 3465 | /* |
| 3466 | * Rearm the tx watchdog just before idling scan. This |
| 3467 | * prevents just-finished scans from triggering the watchdog |
| 3468 | */ |
| 3469 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 3470 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3471 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
| 3472 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 3473 | wl->scan_wlvif = NULL; |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3474 | wl->scan.req = NULL; |
| 3475 | ieee80211_scan_completed(wl->hw, true); |
| 3476 | |
| 3477 | out_sleep: |
| 3478 | wl1271_ps_elp_sleep(wl); |
| 3479 | out: |
| 3480 | mutex_unlock(&wl->mutex); |
| 3481 | |
| 3482 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 3483 | } |
| 3484 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3485 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, |
| 3486 | struct ieee80211_vif *vif, |
| 3487 | struct cfg80211_sched_scan_request *req, |
| 3488 | struct ieee80211_sched_scan_ies *ies) |
| 3489 | { |
| 3490 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3491 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3492 | int ret; |
| 3493 | |
| 3494 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); |
| 3495 | |
| 3496 | mutex_lock(&wl->mutex); |
| 3497 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3498 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3499 | ret = -EAGAIN; |
| 3500 | goto out; |
| 3501 | } |
| 3502 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3503 | ret = wl1271_ps_elp_wakeup(wl); |
| 3504 | if (ret < 0) |
| 3505 | goto out; |
| 3506 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3507 | ret = wl->ops->sched_scan_start(wl, wlvif, req, ies); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3508 | if (ret < 0) |
| 3509 | goto out_sleep; |
| 3510 | |
Eliad Peller | 1019975 | 2012-11-22 18:06:23 +0200 | [diff] [blame] | 3511 | wl->sched_vif = wlvif; |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3512 | |
| 3513 | out_sleep: |
| 3514 | wl1271_ps_elp_sleep(wl); |
| 3515 | out: |
| 3516 | mutex_unlock(&wl->mutex); |
| 3517 | return ret; |
| 3518 | } |
| 3519 | |
| 3520 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, |
| 3521 | struct ieee80211_vif *vif) |
| 3522 | { |
| 3523 | struct wl1271 *wl = hw->priv; |
Yoni Divinsky | 78f85f5 | 2012-05-16 11:34:17 +0300 | [diff] [blame] | 3524 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3525 | int ret; |
| 3526 | |
| 3527 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); |
| 3528 | |
| 3529 | mutex_lock(&wl->mutex); |
| 3530 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3531 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3532 | goto out; |
| 3533 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3534 | ret = wl1271_ps_elp_wakeup(wl); |
| 3535 | if (ret < 0) |
| 3536 | goto out; |
| 3537 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3538 | wl->ops->sched_scan_stop(wl, wlvif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3539 | |
| 3540 | wl1271_ps_elp_sleep(wl); |
| 3541 | out: |
| 3542 | mutex_unlock(&wl->mutex); |
| 3543 | } |
| 3544 | |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3545 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 3546 | { |
| 3547 | struct wl1271 *wl = hw->priv; |
| 3548 | int ret = 0; |
| 3549 | |
| 3550 | mutex_lock(&wl->mutex); |
| 3551 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3552 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3553 | ret = -EAGAIN; |
| 3554 | goto out; |
| 3555 | } |
| 3556 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3557 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3558 | if (ret < 0) |
| 3559 | goto out; |
| 3560 | |
Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 3561 | ret = wl1271_acx_frag_threshold(wl, value); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3562 | if (ret < 0) |
| 3563 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); |
| 3564 | |
| 3565 | wl1271_ps_elp_sleep(wl); |
| 3566 | |
| 3567 | out: |
| 3568 | mutex_unlock(&wl->mutex); |
| 3569 | |
| 3570 | return ret; |
| 3571 | } |
| 3572 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3573 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 3574 | { |
| 3575 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3576 | struct wl12xx_vif *wlvif; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3577 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3578 | |
| 3579 | mutex_lock(&wl->mutex); |
| 3580 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3581 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3582 | ret = -EAGAIN; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3583 | goto out; |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3584 | } |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3585 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3586 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3587 | if (ret < 0) |
| 3588 | goto out; |
| 3589 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3590 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 3591 | ret = wl1271_acx_rts_threshold(wl, wlvif, value); |
| 3592 | if (ret < 0) |
| 3593 | wl1271_warning("set rts threshold failed: %d", ret); |
| 3594 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3595 | wl1271_ps_elp_sleep(wl); |
| 3596 | |
| 3597 | out: |
| 3598 | mutex_unlock(&wl->mutex); |
| 3599 | |
| 3600 | return ret; |
| 3601 | } |
| 3602 | |
Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3603 | static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset) |
| 3604 | { |
| 3605 | int len; |
| 3606 | const u8 *next, *end = skb->data + skb->len; |
| 3607 | u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset, |
| 3608 | skb->len - ieoffset); |
| 3609 | if (!ie) |
| 3610 | return; |
| 3611 | len = ie[1] + 2; |
| 3612 | next = ie + len; |
| 3613 | memmove(ie, next, end - next); |
| 3614 | skb_trim(skb, skb->len - len); |
| 3615 | } |
| 3616 | |
Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3617 | static void wl12xx_remove_vendor_ie(struct sk_buff *skb, |
| 3618 | unsigned int oui, u8 oui_type, |
| 3619 | int ieoffset) |
| 3620 | { |
| 3621 | int len; |
| 3622 | const u8 *next, *end = skb->data + skb->len; |
| 3623 | u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 3624 | skb->data + ieoffset, |
| 3625 | skb->len - ieoffset); |
| 3626 | if (!ie) |
| 3627 | return; |
| 3628 | len = ie[1] + 2; |
| 3629 | next = ie + len; |
| 3630 | memmove(ie, next, end - next); |
| 3631 | skb_trim(skb, skb->len - len); |
| 3632 | } |
| 3633 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3634 | static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates, |
| 3635 | struct ieee80211_vif *vif) |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3636 | { |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3637 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3638 | struct sk_buff *skb; |
| 3639 | int ret; |
| 3640 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3641 | skb = ieee80211_proberesp_get(wl->hw, vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3642 | if (!skb) |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3643 | return -EOPNOTSUPP; |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3644 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3645 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3646 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3647 | skb->data, |
| 3648 | skb->len, 0, |
| 3649 | rates); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3650 | dev_kfree_skb(skb); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3651 | |
| 3652 | if (ret < 0) |
| 3653 | goto out; |
| 3654 | |
| 3655 | wl1271_debug(DEBUG_AP, "probe response updated"); |
| 3656 | set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags); |
| 3657 | |
| 3658 | out: |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3659 | return ret; |
| 3660 | } |
| 3661 | |
| 3662 | static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl, |
| 3663 | struct ieee80211_vif *vif, |
| 3664 | u8 *probe_rsp_data, |
| 3665 | size_t probe_rsp_len, |
| 3666 | u32 rates) |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3667 | { |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3668 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3669 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3670 | u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; |
| 3671 | int ssid_ie_offset, ie_offset, templ_len; |
| 3672 | const u8 *ptr; |
| 3673 | |
| 3674 | /* no need to change probe response if the SSID is set correctly */ |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3675 | if (wlvif->ssid_len > 0) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3676 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3677 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3678 | probe_rsp_data, |
| 3679 | probe_rsp_len, 0, |
| 3680 | rates); |
| 3681 | |
| 3682 | if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) { |
| 3683 | wl1271_error("probe_rsp template too big"); |
| 3684 | return -EINVAL; |
| 3685 | } |
| 3686 | |
| 3687 | /* start searching from IE offset */ |
| 3688 | ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 3689 | |
| 3690 | ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset, |
| 3691 | probe_rsp_len - ie_offset); |
| 3692 | if (!ptr) { |
| 3693 | wl1271_error("No SSID in beacon!"); |
| 3694 | return -EINVAL; |
| 3695 | } |
| 3696 | |
| 3697 | ssid_ie_offset = ptr - probe_rsp_data; |
| 3698 | ptr += (ptr[1] + 2); |
| 3699 | |
| 3700 | memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset); |
| 3701 | |
| 3702 | /* insert SSID from bss_conf */ |
| 3703 | probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID; |
| 3704 | probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len; |
| 3705 | memcpy(probe_rsp_templ + ssid_ie_offset + 2, |
| 3706 | bss_conf->ssid, bss_conf->ssid_len); |
| 3707 | templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len; |
| 3708 | |
| 3709 | memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len, |
| 3710 | ptr, probe_rsp_len - (ptr - probe_rsp_data)); |
| 3711 | templ_len += probe_rsp_len - (ptr - probe_rsp_data); |
| 3712 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3713 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3714 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3715 | probe_rsp_templ, |
| 3716 | templ_len, 0, |
| 3717 | rates); |
| 3718 | } |
| 3719 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3720 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3721 | struct ieee80211_vif *vif, |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3722 | struct ieee80211_bss_conf *bss_conf, |
| 3723 | u32 changed) |
| 3724 | { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3725 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3726 | int ret = 0; |
| 3727 | |
| 3728 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 3729 | if (bss_conf->use_short_slot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3730 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3731 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3732 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3733 | if (ret < 0) { |
| 3734 | wl1271_warning("Set slot time failed %d", ret); |
| 3735 | goto out; |
| 3736 | } |
| 3737 | } |
| 3738 | |
| 3739 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 3740 | if (bss_conf->use_short_preamble) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3741 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3742 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3743 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 3747 | if (bss_conf->use_cts_prot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3748 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3749 | CTSPROTECT_ENABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3750 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3751 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3752 | CTSPROTECT_DISABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3753 | if (ret < 0) { |
| 3754 | wl1271_warning("Set ctsprotect failed %d", ret); |
| 3755 | goto out; |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | out: |
| 3760 | return ret; |
| 3761 | } |
| 3762 | |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3763 | static int wlcore_set_beacon_template(struct wl1271 *wl, |
| 3764 | struct ieee80211_vif *vif, |
| 3765 | bool is_ap) |
| 3766 | { |
| 3767 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3768 | struct ieee80211_hdr *hdr; |
| 3769 | u32 min_rate; |
| 3770 | int ret; |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame] | 3771 | int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3772 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); |
| 3773 | u16 tmpl_id; |
| 3774 | |
| 3775 | if (!beacon) { |
| 3776 | ret = -EINVAL; |
| 3777 | goto out; |
| 3778 | } |
| 3779 | |
| 3780 | wl1271_debug(DEBUG_MASTER, "beacon updated"); |
| 3781 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 3782 | ret = wl1271_ssid_set(wlvif, beacon, ieoffset); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3783 | if (ret < 0) { |
| 3784 | dev_kfree_skb(beacon); |
| 3785 | goto out; |
| 3786 | } |
| 3787 | min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 3788 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : |
| 3789 | CMD_TEMPL_BEACON; |
| 3790 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id, |
| 3791 | beacon->data, |
| 3792 | beacon->len, 0, |
| 3793 | min_rate); |
| 3794 | if (ret < 0) { |
| 3795 | dev_kfree_skb(beacon); |
| 3796 | goto out; |
| 3797 | } |
| 3798 | |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 3799 | wlvif->wmm_enabled = |
| 3800 | cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
| 3801 | WLAN_OUI_TYPE_MICROSOFT_WMM, |
| 3802 | beacon->data + ieoffset, |
| 3803 | beacon->len - ieoffset); |
| 3804 | |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3805 | /* |
| 3806 | * In case we already have a probe-resp beacon set explicitly |
| 3807 | * by usermode, don't use the beacon data. |
| 3808 | */ |
| 3809 | if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags)) |
| 3810 | goto end_bcn; |
| 3811 | |
| 3812 | /* remove TIM ie from probe response */ |
| 3813 | wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); |
| 3814 | |
| 3815 | /* |
| 3816 | * remove p2p ie from probe response. |
| 3817 | * the fw reponds to probe requests that don't include |
| 3818 | * the p2p ie. probe requests with p2p ie will be passed, |
| 3819 | * and will be responded by the supplicant (the spec |
| 3820 | * forbids including the p2p ie when responding to probe |
| 3821 | * requests that didn't include it). |
| 3822 | */ |
| 3823 | wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA, |
| 3824 | WLAN_OUI_TYPE_WFA_P2P, ieoffset); |
| 3825 | |
| 3826 | hdr = (struct ieee80211_hdr *) beacon->data; |
| 3827 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 3828 | IEEE80211_STYPE_PROBE_RESP); |
| 3829 | if (is_ap) |
| 3830 | ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif, |
| 3831 | beacon->data, |
| 3832 | beacon->len, |
| 3833 | min_rate); |
| 3834 | else |
| 3835 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 3836 | CMD_TEMPL_PROBE_RESPONSE, |
| 3837 | beacon->data, |
| 3838 | beacon->len, 0, |
| 3839 | min_rate); |
| 3840 | end_bcn: |
| 3841 | dev_kfree_skb(beacon); |
| 3842 | if (ret < 0) |
| 3843 | goto out; |
| 3844 | |
| 3845 | out: |
| 3846 | return ret; |
| 3847 | } |
| 3848 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3849 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, |
| 3850 | struct ieee80211_vif *vif, |
| 3851 | struct ieee80211_bss_conf *bss_conf, |
| 3852 | u32 changed) |
| 3853 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3854 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3855 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3856 | int ret = 0; |
| 3857 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 3858 | if (changed & BSS_CHANGED_BEACON_INT) { |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3859 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", |
| 3860 | bss_conf->beacon_int); |
| 3861 | |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 3862 | wlvif->beacon_int = bss_conf->beacon_int; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3863 | } |
| 3864 | |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3865 | if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { |
| 3866 | u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3867 | |
| 3868 | wl1271_ap_set_probe_resp_tmpl(wl, rate, vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3869 | } |
| 3870 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 3871 | if (changed & BSS_CHANGED_BEACON) { |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3872 | ret = wlcore_set_beacon_template(wl, vif, is_ap); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3873 | if (ret < 0) |
| 3874 | goto out; |
| 3875 | } |
| 3876 | |
| 3877 | out: |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3878 | if (ret != 0) |
| 3879 | wl1271_error("beacon info change failed: %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3880 | return ret; |
| 3881 | } |
| 3882 | |
| 3883 | /* AP mode changes */ |
| 3884 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3885 | struct ieee80211_vif *vif, |
| 3886 | struct ieee80211_bss_conf *bss_conf, |
| 3887 | u32 changed) |
| 3888 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3889 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3890 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3891 | |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 3892 | if (changed & BSS_CHANGED_BASIC_RATES) { |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3893 | u32 rates = bss_conf->basic_rates; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3894 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3895 | wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3896 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3897 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3898 | wlvif->basic_rate_set); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3899 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3900 | ret = wl1271_init_ap_rates(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3901 | if (ret < 0) { |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 3902 | wl1271_error("AP rate policy change failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3903 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3904 | } |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3905 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3906 | ret = wl1271_ap_init_templates(wl, vif); |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3907 | if (ret < 0) |
| 3908 | goto out; |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3909 | |
| 3910 | ret = wl1271_ap_set_probe_resp_tmpl(wl, wlvif->basic_rate, vif); |
| 3911 | if (ret < 0) |
| 3912 | goto out; |
| 3913 | |
| 3914 | ret = wlcore_set_beacon_template(wl, vif, true); |
| 3915 | if (ret < 0) |
| 3916 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3917 | } |
| 3918 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3919 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); |
| 3920 | if (ret < 0) |
| 3921 | goto out; |
| 3922 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 3923 | if (changed & BSS_CHANGED_BEACON_ENABLED) { |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3924 | if (bss_conf->enable_beacon) { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3925 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3926 | ret = wl12xx_cmd_role_start_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3927 | if (ret < 0) |
| 3928 | goto out; |
| 3929 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3930 | ret = wl1271_ap_init_hwenc(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3931 | if (ret < 0) |
| 3932 | goto out; |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3933 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3934 | set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3935 | wl1271_debug(DEBUG_AP, "started AP"); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3936 | } |
| 3937 | } else { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3938 | if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3939 | ret = wl12xx_cmd_role_stop_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3940 | if (ret < 0) |
| 3941 | goto out; |
| 3942 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3943 | clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3944 | clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, |
| 3945 | &wlvif->flags); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3946 | wl1271_debug(DEBUG_AP, "stopped AP"); |
| 3947 | } |
| 3948 | } |
| 3949 | } |
| 3950 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3951 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3952 | if (ret < 0) |
| 3953 | goto out; |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3954 | |
| 3955 | /* Handle HT information change */ |
| 3956 | if ((changed & BSS_CHANGED_HT) && |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 3957 | (bss_conf->chandef.width != NL80211_CHAN_WIDTH_20_NOHT)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3958 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3959 | bss_conf->ht_operation_mode); |
| 3960 | if (ret < 0) { |
| 3961 | wl1271_warning("Set ht information failed %d", ret); |
| 3962 | goto out; |
| 3963 | } |
| 3964 | } |
| 3965 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3966 | out: |
| 3967 | return; |
| 3968 | } |
| 3969 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 3970 | static int wlcore_set_bssid(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 3971 | struct ieee80211_bss_conf *bss_conf, |
| 3972 | u32 sta_rate_set) |
| 3973 | { |
| 3974 | u32 rates; |
| 3975 | int ret; |
| 3976 | |
| 3977 | wl1271_debug(DEBUG_MAC80211, |
| 3978 | "changed_bssid: %pM, aid: %d, bcn_int: %d, brates: 0x%x sta_rate_set: 0x%x", |
| 3979 | bss_conf->bssid, bss_conf->aid, |
| 3980 | bss_conf->beacon_int, |
| 3981 | bss_conf->basic_rates, sta_rate_set); |
| 3982 | |
| 3983 | wlvif->beacon_int = bss_conf->beacon_int; |
| 3984 | rates = bss_conf->basic_rates; |
| 3985 | wlvif->basic_rate_set = |
| 3986 | wl1271_tx_enabled_rates_get(wl, rates, |
| 3987 | wlvif->band); |
| 3988 | wlvif->basic_rate = |
| 3989 | wl1271_tx_min_rate_get(wl, |
| 3990 | wlvif->basic_rate_set); |
| 3991 | |
| 3992 | if (sta_rate_set) |
| 3993 | wlvif->rate_set = |
| 3994 | wl1271_tx_enabled_rates_get(wl, |
| 3995 | sta_rate_set, |
| 3996 | wlvif->band); |
| 3997 | |
| 3998 | /* we only support sched_scan while not connected */ |
Eliad Peller | 1019975 | 2012-11-22 18:06:23 +0200 | [diff] [blame] | 3999 | if (wl->sched_vif == wlvif) |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 4000 | wl->ops->sched_scan_stop(wl, wlvif); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4001 | |
| 4002 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4003 | if (ret < 0) |
| 4004 | return ret; |
| 4005 | |
| 4006 | ret = wl12xx_cmd_build_null_data(wl, wlvif); |
| 4007 | if (ret < 0) |
| 4008 | return ret; |
| 4009 | |
| 4010 | ret = wl1271_build_qos_null_data(wl, wl12xx_wlvif_to_vif(wlvif)); |
| 4011 | if (ret < 0) |
| 4012 | return ret; |
| 4013 | |
| 4014 | wlcore_set_ssid(wl, wlvif); |
| 4015 | |
| 4016 | set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
| 4017 | |
| 4018 | return 0; |
| 4019 | } |
| 4020 | |
| 4021 | static int wlcore_clear_bssid(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 4022 | { |
| 4023 | int ret; |
| 4024 | |
| 4025 | /* revert back to minimum rates for the current band */ |
| 4026 | wl1271_set_band_rate(wl, wlvif); |
| 4027 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 4028 | |
| 4029 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4030 | if (ret < 0) |
| 4031 | return ret; |
| 4032 | |
| 4033 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 4034 | test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags)) { |
| 4035 | ret = wl12xx_cmd_role_stop_sta(wl, wlvif); |
| 4036 | if (ret < 0) |
| 4037 | return ret; |
| 4038 | } |
| 4039 | |
| 4040 | clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
| 4041 | return 0; |
| 4042 | } |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4043 | /* STA/IBSS mode changes */ |
| 4044 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, |
| 4045 | struct ieee80211_vif *vif, |
| 4046 | struct ieee80211_bss_conf *bss_conf, |
| 4047 | u32 changed) |
| 4048 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 4049 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4050 | bool do_join = false; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4051 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4052 | bool ibss_joined = false; |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4053 | u32 sta_rate_set = 0; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4054 | int ret; |
Luciano Coelho | 2d6e4e76 | 2011-01-11 19:07:21 +0100 | [diff] [blame] | 4055 | struct ieee80211_sta *sta; |
Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 4056 | bool sta_exists = false; |
| 4057 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4058 | |
| 4059 | if (is_ibss) { |
| 4060 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, |
| 4061 | changed); |
| 4062 | if (ret < 0) |
| 4063 | goto out; |
| 4064 | } |
| 4065 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4066 | if (changed & BSS_CHANGED_IBSS) { |
| 4067 | if (bss_conf->ibss_joined) { |
Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 4068 | set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4069 | ibss_joined = true; |
| 4070 | } else { |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4071 | wlcore_unset_assoc(wl, wlvif); |
| 4072 | wl12xx_cmd_role_stop_sta(wl, wlvif); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4077 | do_join = true; |
| 4078 | |
| 4079 | /* Need to update the SSID (for filtering etc) */ |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4080 | if ((changed & BSS_CHANGED_BEACON) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4081 | do_join = true; |
| 4082 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4083 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) { |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 4084 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", |
| 4085 | bss_conf->enable_beacon ? "enabled" : "disabled"); |
| 4086 | |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 4087 | do_join = true; |
| 4088 | } |
| 4089 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 4090 | if (changed & BSS_CHANGED_CQM) { |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 4091 | bool enable = false; |
| 4092 | if (bss_conf->cqm_rssi_thold) |
| 4093 | enable = true; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4094 | ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable, |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 4095 | bss_conf->cqm_rssi_thold, |
| 4096 | bss_conf->cqm_rssi_hyst); |
| 4097 | if (ret < 0) |
| 4098 | goto out; |
Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 4099 | wlvif->rssi_thold = bss_conf->cqm_rssi_thold; |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 4100 | } |
| 4101 | |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 4102 | if (changed & (BSS_CHANGED_BSSID | BSS_CHANGED_HT | |
| 4103 | BSS_CHANGED_ASSOC)) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4104 | rcu_read_lock(); |
| 4105 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
Luciano Coelho | ef08d02 | 2012-11-20 11:03:31 +0200 | [diff] [blame] | 4106 | if (sta) { |
| 4107 | u8 *rx_mask = sta->ht_cap.mcs.rx_mask; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4108 | |
Luciano Coelho | ef08d02 | 2012-11-20 11:03:31 +0200 | [diff] [blame] | 4109 | /* save the supp_rates of the ap */ |
| 4110 | sta_rate_set = sta->supp_rates[wlvif->band]; |
| 4111 | if (sta->ht_cap.ht_supported) |
| 4112 | sta_rate_set |= |
| 4113 | (rx_mask[0] << HW_HT_RATES_OFFSET) | |
| 4114 | (rx_mask[1] << HW_MIMO_RATES_OFFSET); |
| 4115 | sta_ht_cap = sta->ht_cap; |
| 4116 | sta_exists = true; |
| 4117 | } |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4118 | |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4119 | rcu_read_unlock(); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4120 | } |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4121 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4122 | if (changed & BSS_CHANGED_BSSID) { |
| 4123 | if (!is_zero_ether_addr(bss_conf->bssid)) { |
| 4124 | ret = wlcore_set_bssid(wl, wlvif, bss_conf, |
| 4125 | sta_rate_set); |
| 4126 | if (ret < 0) |
| 4127 | goto out; |
| 4128 | |
| 4129 | /* Need to update the BSSID (for filtering etc) */ |
Eliad Peller | 446f5ca | 2012-03-12 14:53:04 +0200 | [diff] [blame] | 4130 | do_join = true; |
Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 4131 | } else { |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4132 | ret = wlcore_clear_bssid(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 4133 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4134 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4135 | } |
| 4136 | } |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 4137 | |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 4138 | if (changed & BSS_CHANGED_IBSS) { |
| 4139 | wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", |
| 4140 | bss_conf->ibss_joined); |
| 4141 | |
| 4142 | if (bss_conf->ibss_joined) { |
| 4143 | u32 rates = bss_conf->basic_rates; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 4144 | wlvif->basic_rate_set = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4145 | wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4146 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 4147 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 4148 | wl1271_tx_min_rate_get(wl, |
| 4149 | wlvif->basic_rate_set); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 4150 | |
Shahar Levi | 06b660e | 2011-09-05 13:54:36 +0300 | [diff] [blame] | 4151 | /* by default, use 11b + OFDM rates */ |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 4152 | wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES; |
| 4153 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 4154 | if (ret < 0) |
| 4155 | goto out; |
| 4156 | } |
| 4157 | } |
| 4158 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4159 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4160 | if (ret < 0) |
| 4161 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4162 | |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 4163 | if (do_join) { |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4164 | ret = wlcore_join(wl, wlvif); |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 4165 | if (ret < 0) { |
| 4166 | wl1271_warning("cmd join failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4167 | goto out; |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 4168 | } |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4169 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 4170 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4171 | if (changed & BSS_CHANGED_ASSOC) { |
| 4172 | if (bss_conf->assoc) { |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 4173 | ret = wlcore_set_assoc(wl, wlvif, bss_conf, |
| 4174 | sta_rate_set); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 4175 | if (ret < 0) |
| 4176 | goto out; |
| 4177 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4178 | if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags)) |
| 4179 | wl12xx_set_authorized(wl, wlvif); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4180 | } else { |
| 4181 | wlcore_unset_assoc(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 4182 | } |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 4183 | } |
| 4184 | |
Eliad Peller | 518b680 | 2012-11-26 18:05:47 +0200 | [diff] [blame] | 4185 | if (changed & BSS_CHANGED_PS) { |
| 4186 | if ((bss_conf->ps) && |
| 4187 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
| 4188 | !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
| 4189 | int ps_mode; |
| 4190 | char *ps_mode_str; |
| 4191 | |
| 4192 | if (wl->conf.conn.forced_ps) { |
| 4193 | ps_mode = STATION_POWER_SAVE_MODE; |
| 4194 | ps_mode_str = "forced"; |
| 4195 | } else { |
| 4196 | ps_mode = STATION_AUTO_PS_MODE; |
| 4197 | ps_mode_str = "auto"; |
| 4198 | } |
| 4199 | |
| 4200 | wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str); |
| 4201 | |
| 4202 | ret = wl1271_ps_set_mode(wl, wlvif, ps_mode); |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4203 | if (ret < 0) |
Eliad Peller | 518b680 | 2012-11-26 18:05:47 +0200 | [diff] [blame] | 4204 | wl1271_warning("enter %s ps failed %d", |
| 4205 | ps_mode_str, ret); |
| 4206 | } else if (!bss_conf->ps && |
| 4207 | test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
| 4208 | wl1271_debug(DEBUG_PSM, "auto ps disabled"); |
| 4209 | |
| 4210 | ret = wl1271_ps_set_mode(wl, wlvif, |
| 4211 | STATION_ACTIVE_MODE); |
| 4212 | if (ret < 0) |
| 4213 | wl1271_warning("exit auto ps failed %d", ret); |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4214 | } |
| 4215 | } |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4216 | |
| 4217 | /* Handle new association with HT. Do this after join. */ |
Eliad Peller | 58321b2 | 2012-11-20 13:20:10 +0200 | [diff] [blame] | 4218 | if (sta_exists && |
| 4219 | (changed & BSS_CHANGED_HT)) { |
| 4220 | bool enabled = |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4221 | bss_conf->chandef.width != NL80211_CHAN_WIDTH_20_NOHT; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4222 | |
Eliad Peller | 530abe1 | 2012-11-28 11:42:31 +0200 | [diff] [blame] | 4223 | ret = wlcore_hw_set_peer_cap(wl, |
| 4224 | &sta_ht_cap, |
| 4225 | enabled, |
| 4226 | wlvif->rate_set, |
| 4227 | wlvif->sta.hlid); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4228 | if (ret < 0) { |
Eliad Peller | 58321b2 | 2012-11-20 13:20:10 +0200 | [diff] [blame] | 4229 | wl1271_warning("Set ht cap failed %d", ret); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4230 | goto out; |
Eliad Peller | 58321b2 | 2012-11-20 13:20:10 +0200 | [diff] [blame] | 4231 | |
| 4232 | } |
| 4233 | |
| 4234 | if (enabled) { |
| 4235 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
| 4236 | bss_conf->ht_operation_mode); |
| 4237 | if (ret < 0) { |
| 4238 | wl1271_warning("Set ht information failed %d", |
| 4239 | ret); |
| 4240 | goto out; |
| 4241 | } |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4242 | } |
| 4243 | } |
| 4244 | |
Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 4245 | /* Handle arp filtering. Done after join. */ |
| 4246 | if ((changed & BSS_CHANGED_ARP_FILTER) || |
| 4247 | (!is_ibss && (changed & BSS_CHANGED_QOS))) { |
| 4248 | __be32 addr = bss_conf->arp_addr_list[0]; |
| 4249 | wlvif->sta.qos = bss_conf->qos; |
| 4250 | WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS); |
| 4251 | |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 4252 | if (bss_conf->arp_addr_cnt == 1 && bss_conf->assoc) { |
Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 4253 | wlvif->ip_addr = addr; |
| 4254 | /* |
| 4255 | * The template should have been configured only upon |
| 4256 | * association. however, it seems that the correct ip |
| 4257 | * isn't being set (when sending), so we have to |
| 4258 | * reconfigure the template upon every ip change. |
| 4259 | */ |
| 4260 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 4261 | if (ret < 0) { |
| 4262 | wl1271_warning("build arp rsp failed: %d", ret); |
| 4263 | goto out; |
| 4264 | } |
| 4265 | |
| 4266 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, |
| 4267 | (ACX_ARP_FILTER_ARP_FILTERING | |
| 4268 | ACX_ARP_FILTER_AUTO_ARP), |
| 4269 | addr); |
| 4270 | } else { |
| 4271 | wlvif->ip_addr = 0; |
| 4272 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr); |
| 4273 | } |
| 4274 | |
| 4275 | if (ret < 0) |
| 4276 | goto out; |
| 4277 | } |
| 4278 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4279 | out: |
| 4280 | return; |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4281 | } |
| 4282 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4283 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, |
| 4284 | struct ieee80211_vif *vif, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4285 | struct ieee80211_bss_conf *bss_conf, |
| 4286 | u32 changed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4287 | { |
| 4288 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4289 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4290 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4291 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4292 | |
Eliad Peller | d3f5a1b | 2012-11-19 17:14:05 +0200 | [diff] [blame] | 4293 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info role %d changed 0x%x", |
| 4294 | wlvif->role_id, (int)changed); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4295 | |
Arik Nemtsov | 6b8bf5b | 2012-05-15 17:08:54 +0300 | [diff] [blame] | 4296 | /* |
| 4297 | * make sure to cancel pending disconnections if our association |
| 4298 | * state changed |
| 4299 | */ |
| 4300 | if (!is_ap && (changed & BSS_CHANGED_ASSOC)) |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4301 | cancel_delayed_work_sync(&wlvif->connection_loss_work); |
Arik Nemtsov | 6b8bf5b | 2012-05-15 17:08:54 +0300 | [diff] [blame] | 4302 | |
Eliad Peller | b515d83 | 2012-05-15 17:08:56 +0300 | [diff] [blame] | 4303 | if (is_ap && (changed & BSS_CHANGED_BEACON_ENABLED) && |
| 4304 | !bss_conf->enable_beacon) |
| 4305 | wl1271_tx_flush(wl); |
| 4306 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4307 | mutex_lock(&wl->mutex); |
| 4308 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4309 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4310 | goto out; |
| 4311 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 4312 | if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))) |
| 4313 | goto out; |
| 4314 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4315 | ret = wl1271_ps_elp_wakeup(wl); |
| 4316 | if (ret < 0) |
| 4317 | goto out; |
| 4318 | |
| 4319 | if (is_ap) |
| 4320 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); |
| 4321 | else |
| 4322 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); |
| 4323 | |
| 4324 | wl1271_ps_elp_sleep(wl); |
| 4325 | |
| 4326 | out: |
| 4327 | mutex_unlock(&wl->mutex); |
| 4328 | } |
| 4329 | |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4330 | static int wlcore_op_add_chanctx(struct ieee80211_hw *hw, |
| 4331 | struct ieee80211_chanctx_conf *ctx) |
| 4332 | { |
| 4333 | wl1271_debug(DEBUG_MAC80211, "mac80211 add chanctx %d (type %d)", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4334 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4335 | cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4336 | return 0; |
| 4337 | } |
| 4338 | |
| 4339 | static void wlcore_op_remove_chanctx(struct ieee80211_hw *hw, |
| 4340 | struct ieee80211_chanctx_conf *ctx) |
| 4341 | { |
| 4342 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove chanctx %d (type %d)", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4343 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4344 | cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | static void wlcore_op_change_chanctx(struct ieee80211_hw *hw, |
| 4348 | struct ieee80211_chanctx_conf *ctx, |
| 4349 | u32 changed) |
| 4350 | { |
| 4351 | wl1271_debug(DEBUG_MAC80211, |
| 4352 | "mac80211 change chanctx %d (type %d) changed 0x%x", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4353 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4354 | cfg80211_get_chandef_type(&ctx->def), changed); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | static int wlcore_op_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 4358 | struct ieee80211_vif *vif, |
| 4359 | struct ieee80211_chanctx_conf *ctx) |
| 4360 | { |
| 4361 | struct wl1271 *wl = hw->priv; |
| 4362 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4363 | int channel = ieee80211_frequency_to_channel( |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4364 | ctx->def.chan->center_freq); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4365 | |
| 4366 | wl1271_debug(DEBUG_MAC80211, |
| 4367 | "mac80211 assign chanctx (role %d) %d (type %d)", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4368 | wlvif->role_id, channel, cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4369 | |
| 4370 | mutex_lock(&wl->mutex); |
| 4371 | |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4372 | wlvif->band = ctx->def.chan->band; |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4373 | wlvif->channel = channel; |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4374 | wlvif->channel_type = cfg80211_get_chandef_type(&ctx->def); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4375 | |
| 4376 | /* update default rates according to the band */ |
| 4377 | wl1271_set_band_rate(wl, wlvif); |
| 4378 | |
| 4379 | mutex_unlock(&wl->mutex); |
| 4380 | |
| 4381 | return 0; |
| 4382 | } |
| 4383 | |
| 4384 | static void wlcore_op_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 4385 | struct ieee80211_vif *vif, |
| 4386 | struct ieee80211_chanctx_conf *ctx) |
| 4387 | { |
| 4388 | struct wl1271 *wl = hw->priv; |
| 4389 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4390 | |
| 4391 | wl1271_debug(DEBUG_MAC80211, |
| 4392 | "mac80211 unassign chanctx (role %d) %d (type %d)", |
| 4393 | wlvif->role_id, |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4394 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4395 | cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4396 | |
| 4397 | wl1271_tx_flush(wl); |
| 4398 | } |
| 4399 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 4400 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, |
| 4401 | struct ieee80211_vif *vif, u16 queue, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4402 | const struct ieee80211_tx_queue_params *params) |
| 4403 | { |
| 4404 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4405 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4406 | u8 ps_scheme; |
| 4407 | int ret = 0; |
| 4408 | |
| 4409 | mutex_lock(&wl->mutex); |
| 4410 | |
| 4411 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); |
| 4412 | |
| 4413 | if (params->uapsd) |
| 4414 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; |
| 4415 | else |
| 4416 | ps_scheme = CONF_PS_SCHEME_LEGACY; |
| 4417 | |
Eliad Peller | 5b37ddf | 2011-12-18 20:25:40 +0200 | [diff] [blame] | 4418 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4419 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4420 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4421 | ret = wl1271_ps_elp_wakeup(wl); |
| 4422 | if (ret < 0) |
| 4423 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4424 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4425 | /* |
| 4426 | * the txop is confed in units of 32us by the mac80211, |
| 4427 | * we need us |
| 4428 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4429 | ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4430 | params->cw_min, params->cw_max, |
| 4431 | params->aifs, params->txop << 5); |
| 4432 | if (ret < 0) |
| 4433 | goto out_sleep; |
| 4434 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4435 | ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4436 | CONF_CHANNEL_TYPE_EDCF, |
| 4437 | wl1271_tx_get_queue(queue), |
| 4438 | ps_scheme, CONF_ACK_POLICY_LEGACY, |
| 4439 | 0, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4440 | |
| 4441 | out_sleep: |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4442 | wl1271_ps_elp_sleep(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4443 | |
| 4444 | out: |
| 4445 | mutex_unlock(&wl->mutex); |
| 4446 | |
| 4447 | return ret; |
| 4448 | } |
| 4449 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 4450 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw, |
| 4451 | struct ieee80211_vif *vif) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4452 | { |
| 4453 | |
| 4454 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4455 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4456 | u64 mactime = ULLONG_MAX; |
| 4457 | int ret; |
| 4458 | |
| 4459 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); |
| 4460 | |
| 4461 | mutex_lock(&wl->mutex); |
| 4462 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4463 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4464 | goto out; |
| 4465 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4466 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4467 | if (ret < 0) |
| 4468 | goto out; |
| 4469 | |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4470 | ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4471 | if (ret < 0) |
| 4472 | goto out_sleep; |
| 4473 | |
| 4474 | out_sleep: |
| 4475 | wl1271_ps_elp_sleep(wl); |
| 4476 | |
| 4477 | out: |
| 4478 | mutex_unlock(&wl->mutex); |
| 4479 | return mactime; |
| 4480 | } |
| 4481 | |
| 4482 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, |
| 4483 | struct survey_info *survey) |
| 4484 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4485 | struct ieee80211_conf *conf = &hw->conf; |
| 4486 | |
| 4487 | if (idx != 0) |
| 4488 | return -ENOENT; |
| 4489 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4490 | survey->channel = conf->chandef.chan; |
Yoni Divinsky | add779a0 | 2012-06-13 18:56:54 +0300 | [diff] [blame] | 4491 | survey->filled = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4492 | return 0; |
| 4493 | } |
| 4494 | |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4495 | static int wl1271_allocate_sta(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4496 | struct wl12xx_vif *wlvif, |
| 4497 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4498 | { |
| 4499 | struct wl1271_station *wl_sta; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4500 | int ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4501 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4502 | |
| 4503 | if (wl->active_sta_count >= AP_MAX_STATIONS) { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4504 | wl1271_warning("could not allocate HLID - too much stations"); |
| 4505 | return -EBUSY; |
| 4506 | } |
| 4507 | |
| 4508 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4509 | ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid); |
| 4510 | if (ret < 0) { |
| 4511 | wl1271_warning("could not allocate HLID - too many links"); |
| 4512 | return -EBUSY; |
| 4513 | } |
| 4514 | |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 4515 | /* use the previous security seq, if this is a recovery/resume */ |
| 4516 | wl->links[wl_sta->hlid].total_freed_pkts = wl_sta->total_freed_pkts; |
| 4517 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4518 | set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4519 | memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4520 | wl->active_sta_count++; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4521 | return 0; |
| 4522 | } |
| 4523 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4524 | void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4525 | { |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 4526 | struct wl1271_station *wl_sta; |
| 4527 | struct ieee80211_sta *sta; |
| 4528 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 4529 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4530 | if (!test_bit(hlid, wlvif->ap.sta_hlid_map)) |
Arik Nemtsov | f1acea9 | 2011-08-25 12:43:17 +0300 | [diff] [blame] | 4531 | return; |
| 4532 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4533 | clear_bit(hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4534 | __clear_bit(hlid, &wl->ap_ps_map); |
| 4535 | __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 4536 | |
| 4537 | /* |
| 4538 | * save the last used PN in the private part of iee80211_sta, |
| 4539 | * in case of recovery/suspend |
| 4540 | */ |
| 4541 | rcu_read_lock(); |
| 4542 | sta = ieee80211_find_sta(vif, wl->links[hlid].addr); |
| 4543 | if (sta) { |
| 4544 | wl_sta = (void *)sta->drv_priv; |
| 4545 | wl_sta->total_freed_pkts = wl->links[hlid].total_freed_pkts; |
| 4546 | |
| 4547 | /* |
| 4548 | * increment the initial seq number on recovery to account for |
| 4549 | * transmitted packets that we haven't yet got in the FW status |
| 4550 | */ |
| 4551 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 4552 | wl_sta->total_freed_pkts += |
| 4553 | WL1271_TX_SQN_POST_RECOVERY_PADDING; |
| 4554 | } |
| 4555 | rcu_read_unlock(); |
| 4556 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4557 | wl12xx_free_link(wl, wlvif, &hlid); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4558 | wl->active_sta_count--; |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 4559 | |
| 4560 | /* |
| 4561 | * rearm the tx watchdog when the last STA is freed - give the FW a |
| 4562 | * chance to return STA-buffered packets before complaining. |
| 4563 | */ |
| 4564 | if (wl->active_sta_count == 0) |
| 4565 | wl12xx_rearm_tx_watchdog_locked(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4566 | } |
| 4567 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4568 | static int wl12xx_sta_add(struct wl1271 *wl, |
| 4569 | struct wl12xx_vif *wlvif, |
| 4570 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4571 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4572 | struct wl1271_station *wl_sta; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4573 | int ret = 0; |
| 4574 | u8 hlid; |
| 4575 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4576 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); |
| 4577 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4578 | ret = wl1271_allocate_sta(wl, wlvif, sta); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4579 | if (ret < 0) |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4580 | return ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4581 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4582 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4583 | hlid = wl_sta->hlid; |
| 4584 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4585 | ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4586 | if (ret < 0) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4587 | wl1271_free_sta(wl, wlvif, hlid); |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4588 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4589 | return ret; |
| 4590 | } |
| 4591 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4592 | static int wl12xx_sta_remove(struct wl1271 *wl, |
| 4593 | struct wl12xx_vif *wlvif, |
| 4594 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4595 | { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4596 | struct wl1271_station *wl_sta; |
| 4597 | int ret = 0, id; |
| 4598 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4599 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); |
| 4600 | |
| 4601 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4602 | id = wl_sta->hlid; |
| 4603 | if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map))) |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4604 | return -EINVAL; |
| 4605 | |
| 4606 | ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid); |
| 4607 | if (ret < 0) |
| 4608 | return ret; |
| 4609 | |
| 4610 | wl1271_free_sta(wl, wlvif, wl_sta->hlid); |
| 4611 | return ret; |
| 4612 | } |
| 4613 | |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4614 | static void wlcore_roc_if_possible(struct wl1271 *wl, |
| 4615 | struct wl12xx_vif *wlvif) |
| 4616 | { |
| 4617 | if (find_first_bit(wl->roc_map, |
| 4618 | WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) |
| 4619 | return; |
| 4620 | |
| 4621 | if (WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID)) |
| 4622 | return; |
| 4623 | |
| 4624 | wl12xx_roc(wl, wlvif, wlvif->role_id, wlvif->band, wlvif->channel); |
| 4625 | } |
| 4626 | |
| 4627 | static void wlcore_update_inconn_sta(struct wl1271 *wl, |
| 4628 | struct wl12xx_vif *wlvif, |
| 4629 | struct wl1271_station *wl_sta, |
| 4630 | bool in_connection) |
| 4631 | { |
| 4632 | if (in_connection) { |
| 4633 | if (WARN_ON(wl_sta->in_connection)) |
| 4634 | return; |
| 4635 | wl_sta->in_connection = true; |
| 4636 | if (!wlvif->inconn_count++) |
| 4637 | wlcore_roc_if_possible(wl, wlvif); |
| 4638 | } else { |
| 4639 | if (!wl_sta->in_connection) |
| 4640 | return; |
| 4641 | |
| 4642 | wl_sta->in_connection = false; |
| 4643 | wlvif->inconn_count--; |
| 4644 | if (WARN_ON(wlvif->inconn_count < 0)) |
| 4645 | return; |
| 4646 | |
| 4647 | if (!wlvif->inconn_count) |
| 4648 | if (test_bit(wlvif->role_id, wl->roc_map)) |
| 4649 | wl12xx_croc(wl, wlvif->role_id); |
| 4650 | } |
| 4651 | } |
| 4652 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4653 | static int wl12xx_update_sta_state(struct wl1271 *wl, |
| 4654 | struct wl12xx_vif *wlvif, |
| 4655 | struct ieee80211_sta *sta, |
| 4656 | enum ieee80211_sta_state old_state, |
| 4657 | enum ieee80211_sta_state new_state) |
| 4658 | { |
| 4659 | struct wl1271_station *wl_sta; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4660 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
| 4661 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
| 4662 | int ret; |
| 4663 | |
| 4664 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4665 | |
| 4666 | /* Add station (AP mode) */ |
| 4667 | if (is_ap && |
| 4668 | old_state == IEEE80211_STA_NOTEXIST && |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4669 | new_state == IEEE80211_STA_NONE) { |
| 4670 | ret = wl12xx_sta_add(wl, wlvif, sta); |
| 4671 | if (ret) |
| 4672 | return ret; |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4673 | |
| 4674 | wlcore_update_inconn_sta(wl, wlvif, wl_sta, true); |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4675 | } |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4676 | |
| 4677 | /* Remove station (AP mode) */ |
| 4678 | if (is_ap && |
| 4679 | old_state == IEEE80211_STA_NONE && |
| 4680 | new_state == IEEE80211_STA_NOTEXIST) { |
| 4681 | /* must not fail */ |
| 4682 | wl12xx_sta_remove(wl, wlvif, sta); |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4683 | |
| 4684 | wlcore_update_inconn_sta(wl, wlvif, wl_sta, false); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | /* Authorize station (AP mode) */ |
| 4688 | if (is_ap && |
| 4689 | new_state == IEEE80211_STA_AUTHORIZED) { |
Arik Nemtsov | 2fec3d2 | 2013-03-12 17:19:37 +0200 | [diff] [blame] | 4690 | ret = wl12xx_cmd_set_peer_state(wl, wlvif, wl_sta->hlid); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4691 | if (ret < 0) |
| 4692 | return ret; |
| 4693 | |
| 4694 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, |
Arik Nemtsov | 2fec3d2 | 2013-03-12 17:19:37 +0200 | [diff] [blame] | 4695 | wl_sta->hlid); |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4696 | if (ret) |
| 4697 | return ret; |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4698 | |
| 4699 | wlcore_update_inconn_sta(wl, wlvif, wl_sta, false); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4700 | } |
| 4701 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4702 | /* Authorize station */ |
| 4703 | if (is_sta && |
| 4704 | new_state == IEEE80211_STA_AUTHORIZED) { |
| 4705 | set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4706 | ret = wl12xx_set_authorized(wl, wlvif); |
| 4707 | if (ret) |
| 4708 | return ret; |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4709 | } |
| 4710 | |
| 4711 | if (is_sta && |
| 4712 | old_state == IEEE80211_STA_AUTHORIZED && |
| 4713 | new_state == IEEE80211_STA_ASSOC) { |
| 4714 | clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4715 | clear_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags); |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4716 | } |
| 4717 | |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4718 | /* clear ROCs on failure or authorization */ |
| 4719 | if (is_sta && |
| 4720 | (new_state == IEEE80211_STA_AUTHORIZED || |
| 4721 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 4722 | if (test_bit(wlvif->role_id, wl->roc_map)) |
| 4723 | wl12xx_croc(wl, wlvif->role_id); |
| 4724 | } |
| 4725 | |
| 4726 | if (is_sta && |
| 4727 | old_state == IEEE80211_STA_NOTEXIST && |
| 4728 | new_state == IEEE80211_STA_NONE) { |
| 4729 | if (find_first_bit(wl->roc_map, |
| 4730 | WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) { |
| 4731 | WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID); |
| 4732 | wl12xx_roc(wl, wlvif, wlvif->role_id, |
| 4733 | wlvif->band, wlvif->channel); |
| 4734 | } |
| 4735 | } |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4736 | return 0; |
| 4737 | } |
| 4738 | |
| 4739 | static int wl12xx_op_sta_state(struct ieee80211_hw *hw, |
| 4740 | struct ieee80211_vif *vif, |
| 4741 | struct ieee80211_sta *sta, |
| 4742 | enum ieee80211_sta_state old_state, |
| 4743 | enum ieee80211_sta_state new_state) |
| 4744 | { |
| 4745 | struct wl1271 *wl = hw->priv; |
| 4746 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4747 | int ret; |
| 4748 | |
| 4749 | wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d", |
| 4750 | sta->aid, old_state, new_state); |
| 4751 | |
| 4752 | mutex_lock(&wl->mutex); |
| 4753 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4754 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4755 | ret = -EBUSY; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4756 | goto out; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4757 | } |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4758 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4759 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4760 | if (ret < 0) |
| 4761 | goto out; |
| 4762 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4763 | ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4764 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4765 | wl1271_ps_elp_sleep(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4766 | out: |
| 4767 | mutex_unlock(&wl->mutex); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4768 | if (new_state < old_state) |
| 4769 | return 0; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4770 | return ret; |
| 4771 | } |
| 4772 | |
Luciano Coelho | 4623ec7 | 2011-03-21 19:26:41 +0200 | [diff] [blame] | 4773 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, |
| 4774 | struct ieee80211_vif *vif, |
| 4775 | enum ieee80211_ampdu_mlme_action action, |
| 4776 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 4777 | u8 buf_size) |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4778 | { |
| 4779 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4780 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4781 | int ret; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4782 | u8 hlid, *ba_bitmap; |
| 4783 | |
| 4784 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action, |
| 4785 | tid); |
| 4786 | |
| 4787 | /* sanity check - the fields in FW are only 8bits wide */ |
| 4788 | if (WARN_ON(tid > 0xFF)) |
| 4789 | return -ENOTSUPP; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4790 | |
| 4791 | mutex_lock(&wl->mutex); |
| 4792 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4793 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4794 | ret = -EAGAIN; |
| 4795 | goto out; |
| 4796 | } |
| 4797 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4798 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) { |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4799 | hlid = wlvif->sta.hlid; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4800 | } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4801 | struct wl1271_station *wl_sta; |
| 4802 | |
| 4803 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4804 | hlid = wl_sta->hlid; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4805 | } else { |
| 4806 | ret = -EINVAL; |
| 4807 | goto out; |
| 4808 | } |
| 4809 | |
Arik Nemtsov | 9ae5d8d | 2012-11-28 11:42:45 +0200 | [diff] [blame] | 4810 | ba_bitmap = &wl->links[hlid].ba_bitmap; |
| 4811 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4812 | ret = wl1271_ps_elp_wakeup(wl); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4813 | if (ret < 0) |
| 4814 | goto out; |
| 4815 | |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 4816 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", |
| 4817 | tid, action); |
| 4818 | |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4819 | switch (action) { |
| 4820 | case IEEE80211_AMPDU_RX_START: |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4821 | if (!wlvif->ba_support || !wlvif->ba_allowed) { |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4822 | ret = -ENOTSUPP; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4823 | break; |
| 4824 | } |
| 4825 | |
Igal Chernobelsky | d21553f | 2013-03-12 17:19:35 +0200 | [diff] [blame] | 4826 | if (wl->ba_rx_session_count >= wl->ba_rx_session_count_max) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4827 | ret = -EBUSY; |
| 4828 | wl1271_error("exceeded max RX BA sessions"); |
| 4829 | break; |
| 4830 | } |
| 4831 | |
| 4832 | if (*ba_bitmap & BIT(tid)) { |
| 4833 | ret = -EINVAL; |
| 4834 | wl1271_error("cannot enable RX BA session on active " |
| 4835 | "tid: %d", tid); |
| 4836 | break; |
| 4837 | } |
| 4838 | |
| 4839 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true, |
| 4840 | hlid); |
| 4841 | if (!ret) { |
| 4842 | *ba_bitmap |= BIT(tid); |
| 4843 | wl->ba_rx_session_count++; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4844 | } |
| 4845 | break; |
| 4846 | |
| 4847 | case IEEE80211_AMPDU_RX_STOP: |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4848 | if (!(*ba_bitmap & BIT(tid))) { |
Arik Nemtsov | c954910 | 2012-06-06 10:48:56 +0300 | [diff] [blame] | 4849 | /* |
| 4850 | * this happens on reconfig - so only output a debug |
| 4851 | * message for now, and don't fail the function. |
| 4852 | */ |
| 4853 | wl1271_debug(DEBUG_MAC80211, |
| 4854 | "no active RX BA session on tid: %d", |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4855 | tid); |
Arik Nemtsov | c954910 | 2012-06-06 10:48:56 +0300 | [diff] [blame] | 4856 | ret = 0; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4857 | break; |
| 4858 | } |
| 4859 | |
| 4860 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false, |
| 4861 | hlid); |
| 4862 | if (!ret) { |
| 4863 | *ba_bitmap &= ~BIT(tid); |
| 4864 | wl->ba_rx_session_count--; |
| 4865 | } |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4866 | break; |
| 4867 | |
| 4868 | /* |
| 4869 | * The BA initiator session management in FW independently. |
| 4870 | * Falling break here on purpose for all TX APDU commands. |
| 4871 | */ |
| 4872 | case IEEE80211_AMPDU_TX_START: |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 4873 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 4874 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 4875 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4876 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 4877 | ret = -EINVAL; |
| 4878 | break; |
| 4879 | |
| 4880 | default: |
| 4881 | wl1271_error("Incorrect ampdu action id=%x\n", action); |
| 4882 | ret = -EINVAL; |
| 4883 | } |
| 4884 | |
| 4885 | wl1271_ps_elp_sleep(wl); |
| 4886 | |
| 4887 | out: |
| 4888 | mutex_unlock(&wl->mutex); |
| 4889 | |
| 4890 | return ret; |
| 4891 | } |
| 4892 | |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4893 | static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw, |
| 4894 | struct ieee80211_vif *vif, |
| 4895 | const struct cfg80211_bitrate_mask *mask) |
| 4896 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4897 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4898 | struct wl1271 *wl = hw->priv; |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4899 | int i, ret = 0; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4900 | |
| 4901 | wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", |
| 4902 | mask->control[NL80211_BAND_2GHZ].legacy, |
| 4903 | mask->control[NL80211_BAND_5GHZ].legacy); |
| 4904 | |
| 4905 | mutex_lock(&wl->mutex); |
| 4906 | |
Arik Nemtsov | 091185d | 2012-07-03 09:11:03 +0300 | [diff] [blame] | 4907 | for (i = 0; i < WLCORE_NUM_BANDS; i++) |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4908 | wlvif->bitrate_masks[i] = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4909 | wl1271_tx_enabled_rates_get(wl, |
| 4910 | mask->control[i].legacy, |
| 4911 | i); |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4912 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4913 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4914 | goto out; |
| 4915 | |
| 4916 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 4917 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) { |
| 4918 | |
| 4919 | ret = wl1271_ps_elp_wakeup(wl); |
| 4920 | if (ret < 0) |
| 4921 | goto out; |
| 4922 | |
| 4923 | wl1271_set_band_rate(wl, wlvif); |
| 4924 | wlvif->basic_rate = |
| 4925 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 4926 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4927 | |
| 4928 | wl1271_ps_elp_sleep(wl); |
| 4929 | } |
| 4930 | out: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4931 | mutex_unlock(&wl->mutex); |
| 4932 | |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4933 | return ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4934 | } |
| 4935 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4936 | static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, |
| 4937 | struct ieee80211_channel_switch *ch_switch) |
| 4938 | { |
| 4939 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4940 | struct wl12xx_vif *wlvif; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4941 | int ret; |
| 4942 | |
| 4943 | wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); |
| 4944 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 4945 | wl1271_tx_flush(wl); |
| 4946 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4947 | mutex_lock(&wl->mutex); |
| 4948 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4949 | if (unlikely(wl->state == WLCORE_STATE_OFF)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 4950 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 4951 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 4952 | ieee80211_chswitch_done(vif, false); |
| 4953 | } |
| 4954 | goto out; |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4955 | } else if (unlikely(wl->state != WLCORE_STATE_ON)) { |
| 4956 | goto out; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | ret = wl1271_ps_elp_wakeup(wl); |
| 4960 | if (ret < 0) |
| 4961 | goto out; |
| 4962 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4963 | /* TODO: change mac80211 to pass vif as param */ |
| 4964 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4965 | unsigned long delay_usec; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4966 | |
Eliad Peller | fcab189 | 2012-11-22 18:06:18 +0200 | [diff] [blame] | 4967 | ret = wl->ops->channel_switch(wl, wlvif, ch_switch); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4968 | if (ret) |
| 4969 | goto out_sleep; |
| 4970 | |
| 4971 | set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags); |
| 4972 | |
| 4973 | /* indicate failure 5 seconds after channel switch time */ |
| 4974 | delay_usec = ieee80211_tu_to_usec(wlvif->beacon_int) * |
| 4975 | ch_switch->count; |
| 4976 | ieee80211_queue_delayed_work(hw, &wlvif->channel_switch_work, |
| 4977 | usecs_to_jiffies(delay_usec) + |
| 4978 | msecs_to_jiffies(5000)); |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4979 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4980 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4981 | out_sleep: |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4982 | wl1271_ps_elp_sleep(wl); |
| 4983 | |
| 4984 | out: |
| 4985 | mutex_unlock(&wl->mutex); |
| 4986 | } |
| 4987 | |
Johannes Berg | 39ecc01 | 2013-02-13 12:11:00 +0100 | [diff] [blame] | 4988 | static void wlcore_op_flush(struct ieee80211_hw *hw, u32 queues, bool drop) |
Eliad Peller | d8ae5a2 | 2012-06-25 13:52:33 +0300 | [diff] [blame] | 4989 | { |
| 4990 | struct wl1271 *wl = hw->priv; |
| 4991 | |
| 4992 | wl1271_tx_flush(wl); |
| 4993 | } |
| 4994 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 4995 | static int wlcore_op_remain_on_channel(struct ieee80211_hw *hw, |
| 4996 | struct ieee80211_vif *vif, |
| 4997 | struct ieee80211_channel *chan, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 4998 | int duration, |
| 4999 | enum ieee80211_roc_type type) |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5000 | { |
| 5001 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 5002 | struct wl1271 *wl = hw->priv; |
| 5003 | int channel, ret = 0; |
| 5004 | |
| 5005 | channel = ieee80211_frequency_to_channel(chan->center_freq); |
| 5006 | |
| 5007 | wl1271_debug(DEBUG_MAC80211, "mac80211 roc %d (%d)", |
| 5008 | channel, wlvif->role_id); |
| 5009 | |
| 5010 | mutex_lock(&wl->mutex); |
| 5011 | |
| 5012 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 5013 | goto out; |
| 5014 | |
| 5015 | /* return EBUSY if we can't ROC right now */ |
| 5016 | if (WARN_ON(wl->roc_vif || |
| 5017 | find_first_bit(wl->roc_map, |
| 5018 | WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES)) { |
| 5019 | ret = -EBUSY; |
| 5020 | goto out; |
| 5021 | } |
| 5022 | |
| 5023 | ret = wl1271_ps_elp_wakeup(wl); |
| 5024 | if (ret < 0) |
| 5025 | goto out; |
| 5026 | |
| 5027 | ret = wl12xx_start_dev(wl, wlvif, chan->band, channel); |
| 5028 | if (ret < 0) |
| 5029 | goto out_sleep; |
| 5030 | |
| 5031 | wl->roc_vif = vif; |
| 5032 | ieee80211_queue_delayed_work(hw, &wl->roc_complete_work, |
| 5033 | msecs_to_jiffies(duration)); |
| 5034 | out_sleep: |
| 5035 | wl1271_ps_elp_sleep(wl); |
| 5036 | out: |
| 5037 | mutex_unlock(&wl->mutex); |
| 5038 | return ret; |
| 5039 | } |
| 5040 | |
| 5041 | static int __wlcore_roc_completed(struct wl1271 *wl) |
| 5042 | { |
| 5043 | struct wl12xx_vif *wlvif; |
| 5044 | int ret; |
| 5045 | |
| 5046 | /* already completed */ |
| 5047 | if (unlikely(!wl->roc_vif)) |
| 5048 | return 0; |
| 5049 | |
| 5050 | wlvif = wl12xx_vif_to_data(wl->roc_vif); |
| 5051 | |
| 5052 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 5053 | return -EBUSY; |
| 5054 | |
| 5055 | ret = wl12xx_stop_dev(wl, wlvif); |
| 5056 | if (ret < 0) |
| 5057 | return ret; |
| 5058 | |
| 5059 | wl->roc_vif = NULL; |
| 5060 | |
| 5061 | return 0; |
| 5062 | } |
| 5063 | |
| 5064 | static int wlcore_roc_completed(struct wl1271 *wl) |
| 5065 | { |
| 5066 | int ret; |
| 5067 | |
| 5068 | wl1271_debug(DEBUG_MAC80211, "roc complete"); |
| 5069 | |
| 5070 | mutex_lock(&wl->mutex); |
| 5071 | |
| 5072 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
| 5073 | ret = -EBUSY; |
| 5074 | goto out; |
| 5075 | } |
| 5076 | |
| 5077 | ret = wl1271_ps_elp_wakeup(wl); |
| 5078 | if (ret < 0) |
| 5079 | goto out; |
| 5080 | |
| 5081 | ret = __wlcore_roc_completed(wl); |
| 5082 | |
| 5083 | wl1271_ps_elp_sleep(wl); |
| 5084 | out: |
| 5085 | mutex_unlock(&wl->mutex); |
| 5086 | |
| 5087 | return ret; |
| 5088 | } |
| 5089 | |
| 5090 | static void wlcore_roc_complete_work(struct work_struct *work) |
| 5091 | { |
| 5092 | struct delayed_work *dwork; |
| 5093 | struct wl1271 *wl; |
| 5094 | int ret; |
| 5095 | |
| 5096 | dwork = container_of(work, struct delayed_work, work); |
| 5097 | wl = container_of(dwork, struct wl1271, roc_complete_work); |
| 5098 | |
| 5099 | ret = wlcore_roc_completed(wl); |
| 5100 | if (!ret) |
| 5101 | ieee80211_remain_on_channel_expired(wl->hw); |
| 5102 | } |
| 5103 | |
| 5104 | static int wlcore_op_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 5105 | { |
| 5106 | struct wl1271 *wl = hw->priv; |
| 5107 | |
| 5108 | wl1271_debug(DEBUG_MAC80211, "mac80211 croc"); |
| 5109 | |
| 5110 | /* TODO: per-vif */ |
| 5111 | wl1271_tx_flush(wl); |
| 5112 | |
| 5113 | /* |
| 5114 | * we can't just flush_work here, because it might deadlock |
| 5115 | * (as we might get called from the same workqueue) |
| 5116 | */ |
| 5117 | cancel_delayed_work_sync(&wl->roc_complete_work); |
| 5118 | wlcore_roc_completed(wl); |
| 5119 | |
| 5120 | return 0; |
| 5121 | } |
| 5122 | |
Arik Nemtsov | 5f9b677 | 2012-11-26 18:05:41 +0200 | [diff] [blame] | 5123 | static void wlcore_op_sta_rc_update(struct ieee80211_hw *hw, |
| 5124 | struct ieee80211_vif *vif, |
| 5125 | struct ieee80211_sta *sta, |
| 5126 | u32 changed) |
| 5127 | { |
| 5128 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 5129 | struct wl1271 *wl = hw->priv; |
| 5130 | |
| 5131 | wlcore_hw_sta_rc_update(wl, wlvif, sta, changed); |
| 5132 | } |
| 5133 | |
Nadim Zubidat | 0a9ffac | 2013-03-12 17:19:39 +0200 | [diff] [blame] | 5134 | static int wlcore_op_get_rssi(struct ieee80211_hw *hw, |
| 5135 | struct ieee80211_vif *vif, |
| 5136 | struct ieee80211_sta *sta, |
| 5137 | s8 *rssi_dbm) |
| 5138 | { |
| 5139 | struct wl1271 *wl = hw->priv; |
| 5140 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 5141 | int ret = 0; |
| 5142 | |
| 5143 | wl1271_debug(DEBUG_MAC80211, "mac80211 get_rssi"); |
| 5144 | |
| 5145 | mutex_lock(&wl->mutex); |
| 5146 | |
| 5147 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 5148 | goto out; |
| 5149 | |
| 5150 | ret = wl1271_ps_elp_wakeup(wl); |
| 5151 | if (ret < 0) |
| 5152 | goto out_sleep; |
| 5153 | |
| 5154 | ret = wlcore_acx_average_rssi(wl, wlvif, rssi_dbm); |
| 5155 | if (ret < 0) |
| 5156 | goto out_sleep; |
| 5157 | |
| 5158 | out_sleep: |
| 5159 | wl1271_ps_elp_sleep(wl); |
| 5160 | |
| 5161 | out: |
| 5162 | mutex_unlock(&wl->mutex); |
| 5163 | |
| 5164 | return ret; |
| 5165 | } |
| 5166 | |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5167 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) |
| 5168 | { |
| 5169 | struct wl1271 *wl = hw->priv; |
| 5170 | bool ret = false; |
| 5171 | |
| 5172 | mutex_lock(&wl->mutex); |
| 5173 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 5174 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5175 | goto out; |
| 5176 | |
| 5177 | /* packets are considered pending if in the TX queue or the FW */ |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 5178 | ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0); |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5179 | out: |
| 5180 | mutex_unlock(&wl->mutex); |
| 5181 | |
| 5182 | return ret; |
| 5183 | } |
| 5184 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5185 | /* can't be const, mac80211 writes to this */ |
| 5186 | static struct ieee80211_rate wl1271_rates[] = { |
| 5187 | { .bitrate = 10, |
| 5188 | .hw_value = CONF_HW_BIT_RATE_1MBPS, |
| 5189 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, |
| 5190 | { .bitrate = 20, |
| 5191 | .hw_value = CONF_HW_BIT_RATE_2MBPS, |
| 5192 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, |
| 5193 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 5194 | { .bitrate = 55, |
| 5195 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, |
| 5196 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, |
| 5197 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 5198 | { .bitrate = 110, |
| 5199 | .hw_value = CONF_HW_BIT_RATE_11MBPS, |
| 5200 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, |
| 5201 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 5202 | { .bitrate = 60, |
| 5203 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 5204 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
| 5205 | { .bitrate = 90, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5206 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 5207 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5208 | { .bitrate = 120, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5209 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 5210 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5211 | { .bitrate = 180, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5212 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 5213 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5214 | { .bitrate = 240, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5215 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 5216 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5217 | { .bitrate = 360, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5218 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 5219 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5220 | { .bitrate = 480, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5221 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 5222 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5223 | { .bitrate = 540, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5224 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 5225 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5226 | }; |
| 5227 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 5228 | /* can't be const, mac80211 writes to this */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5229 | static struct ieee80211_channel wl1271_channels[] = { |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5230 | { .hw_value = 1, .center_freq = 2412, .max_power = WLCORE_MAX_TXPWR }, |
| 5231 | { .hw_value = 2, .center_freq = 2417, .max_power = WLCORE_MAX_TXPWR }, |
| 5232 | { .hw_value = 3, .center_freq = 2422, .max_power = WLCORE_MAX_TXPWR }, |
| 5233 | { .hw_value = 4, .center_freq = 2427, .max_power = WLCORE_MAX_TXPWR }, |
| 5234 | { .hw_value = 5, .center_freq = 2432, .max_power = WLCORE_MAX_TXPWR }, |
| 5235 | { .hw_value = 6, .center_freq = 2437, .max_power = WLCORE_MAX_TXPWR }, |
| 5236 | { .hw_value = 7, .center_freq = 2442, .max_power = WLCORE_MAX_TXPWR }, |
| 5237 | { .hw_value = 8, .center_freq = 2447, .max_power = WLCORE_MAX_TXPWR }, |
| 5238 | { .hw_value = 9, .center_freq = 2452, .max_power = WLCORE_MAX_TXPWR }, |
| 5239 | { .hw_value = 10, .center_freq = 2457, .max_power = WLCORE_MAX_TXPWR }, |
| 5240 | { .hw_value = 11, .center_freq = 2462, .max_power = WLCORE_MAX_TXPWR }, |
| 5241 | { .hw_value = 12, .center_freq = 2467, .max_power = WLCORE_MAX_TXPWR }, |
| 5242 | { .hw_value = 13, .center_freq = 2472, .max_power = WLCORE_MAX_TXPWR }, |
| 5243 | { .hw_value = 14, .center_freq = 2484, .max_power = WLCORE_MAX_TXPWR }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5244 | }; |
| 5245 | |
| 5246 | /* can't be const, mac80211 writes to this */ |
| 5247 | static struct ieee80211_supported_band wl1271_band_2ghz = { |
| 5248 | .channels = wl1271_channels, |
| 5249 | .n_channels = ARRAY_SIZE(wl1271_channels), |
| 5250 | .bitrates = wl1271_rates, |
| 5251 | .n_bitrates = ARRAY_SIZE(wl1271_rates), |
| 5252 | }; |
| 5253 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5254 | /* 5 GHz data rates for WL1273 */ |
| 5255 | static struct ieee80211_rate wl1271_rates_5ghz[] = { |
| 5256 | { .bitrate = 60, |
| 5257 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 5258 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
| 5259 | { .bitrate = 90, |
| 5260 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 5261 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
| 5262 | { .bitrate = 120, |
| 5263 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 5264 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
| 5265 | { .bitrate = 180, |
| 5266 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 5267 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
| 5268 | { .bitrate = 240, |
| 5269 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 5270 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
| 5271 | { .bitrate = 360, |
| 5272 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 5273 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
| 5274 | { .bitrate = 480, |
| 5275 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 5276 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
| 5277 | { .bitrate = 540, |
| 5278 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 5279 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
| 5280 | }; |
| 5281 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 5282 | /* 5 GHz band channels for WL1273 */ |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5283 | static struct ieee80211_channel wl1271_channels_5ghz[] = { |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5284 | { .hw_value = 7, .center_freq = 5035, .max_power = WLCORE_MAX_TXPWR }, |
| 5285 | { .hw_value = 8, .center_freq = 5040, .max_power = WLCORE_MAX_TXPWR }, |
| 5286 | { .hw_value = 9, .center_freq = 5045, .max_power = WLCORE_MAX_TXPWR }, |
| 5287 | { .hw_value = 11, .center_freq = 5055, .max_power = WLCORE_MAX_TXPWR }, |
| 5288 | { .hw_value = 12, .center_freq = 5060, .max_power = WLCORE_MAX_TXPWR }, |
| 5289 | { .hw_value = 16, .center_freq = 5080, .max_power = WLCORE_MAX_TXPWR }, |
| 5290 | { .hw_value = 34, .center_freq = 5170, .max_power = WLCORE_MAX_TXPWR }, |
| 5291 | { .hw_value = 36, .center_freq = 5180, .max_power = WLCORE_MAX_TXPWR }, |
| 5292 | { .hw_value = 38, .center_freq = 5190, .max_power = WLCORE_MAX_TXPWR }, |
| 5293 | { .hw_value = 40, .center_freq = 5200, .max_power = WLCORE_MAX_TXPWR }, |
| 5294 | { .hw_value = 42, .center_freq = 5210, .max_power = WLCORE_MAX_TXPWR }, |
| 5295 | { .hw_value = 44, .center_freq = 5220, .max_power = WLCORE_MAX_TXPWR }, |
| 5296 | { .hw_value = 46, .center_freq = 5230, .max_power = WLCORE_MAX_TXPWR }, |
| 5297 | { .hw_value = 48, .center_freq = 5240, .max_power = WLCORE_MAX_TXPWR }, |
| 5298 | { .hw_value = 52, .center_freq = 5260, .max_power = WLCORE_MAX_TXPWR }, |
| 5299 | { .hw_value = 56, .center_freq = 5280, .max_power = WLCORE_MAX_TXPWR }, |
| 5300 | { .hw_value = 60, .center_freq = 5300, .max_power = WLCORE_MAX_TXPWR }, |
| 5301 | { .hw_value = 64, .center_freq = 5320, .max_power = WLCORE_MAX_TXPWR }, |
| 5302 | { .hw_value = 100, .center_freq = 5500, .max_power = WLCORE_MAX_TXPWR }, |
| 5303 | { .hw_value = 104, .center_freq = 5520, .max_power = WLCORE_MAX_TXPWR }, |
| 5304 | { .hw_value = 108, .center_freq = 5540, .max_power = WLCORE_MAX_TXPWR }, |
| 5305 | { .hw_value = 112, .center_freq = 5560, .max_power = WLCORE_MAX_TXPWR }, |
| 5306 | { .hw_value = 116, .center_freq = 5580, .max_power = WLCORE_MAX_TXPWR }, |
| 5307 | { .hw_value = 120, .center_freq = 5600, .max_power = WLCORE_MAX_TXPWR }, |
| 5308 | { .hw_value = 124, .center_freq = 5620, .max_power = WLCORE_MAX_TXPWR }, |
| 5309 | { .hw_value = 128, .center_freq = 5640, .max_power = WLCORE_MAX_TXPWR }, |
| 5310 | { .hw_value = 132, .center_freq = 5660, .max_power = WLCORE_MAX_TXPWR }, |
| 5311 | { .hw_value = 136, .center_freq = 5680, .max_power = WLCORE_MAX_TXPWR }, |
| 5312 | { .hw_value = 140, .center_freq = 5700, .max_power = WLCORE_MAX_TXPWR }, |
| 5313 | { .hw_value = 149, .center_freq = 5745, .max_power = WLCORE_MAX_TXPWR }, |
| 5314 | { .hw_value = 153, .center_freq = 5765, .max_power = WLCORE_MAX_TXPWR }, |
| 5315 | { .hw_value = 157, .center_freq = 5785, .max_power = WLCORE_MAX_TXPWR }, |
| 5316 | { .hw_value = 161, .center_freq = 5805, .max_power = WLCORE_MAX_TXPWR }, |
| 5317 | { .hw_value = 165, .center_freq = 5825, .max_power = WLCORE_MAX_TXPWR }, |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5318 | }; |
| 5319 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5320 | static struct ieee80211_supported_band wl1271_band_5ghz = { |
| 5321 | .channels = wl1271_channels_5ghz, |
| 5322 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), |
| 5323 | .bitrates = wl1271_rates_5ghz, |
| 5324 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5325 | }; |
| 5326 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5327 | static const struct ieee80211_ops wl1271_ops = { |
| 5328 | .start = wl1271_op_start, |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 5329 | .stop = wlcore_op_stop, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5330 | .add_interface = wl1271_op_add_interface, |
| 5331 | .remove_interface = wl1271_op_remove_interface, |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 5332 | .change_interface = wl12xx_op_change_interface, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 5333 | #ifdef CONFIG_PM |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 5334 | .suspend = wl1271_op_suspend, |
| 5335 | .resume = wl1271_op_resume, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 5336 | #endif |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5337 | .config = wl1271_op_config, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 5338 | .prepare_multicast = wl1271_op_prepare_multicast, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5339 | .configure_filter = wl1271_op_configure_filter, |
| 5340 | .tx = wl1271_op_tx, |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 5341 | .set_key = wlcore_op_set_key, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5342 | .hw_scan = wl1271_op_hw_scan, |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 5343 | .cancel_hw_scan = wl1271_op_cancel_hw_scan, |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 5344 | .sched_scan_start = wl1271_op_sched_scan_start, |
| 5345 | .sched_scan_stop = wl1271_op_sched_scan_stop, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5346 | .bss_info_changed = wl1271_op_bss_info_changed, |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 5347 | .set_frag_threshold = wl1271_op_set_frag_threshold, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5348 | .set_rts_threshold = wl1271_op_set_rts_threshold, |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 5349 | .conf_tx = wl1271_op_conf_tx, |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 5350 | .get_tsf = wl1271_op_get_tsf, |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 5351 | .get_survey = wl1271_op_get_survey, |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 5352 | .sta_state = wl12xx_op_sta_state, |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 5353 | .ampdu_action = wl1271_op_ampdu_action, |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5354 | .tx_frames_pending = wl1271_tx_frames_pending, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 5355 | .set_bitrate_mask = wl12xx_set_bitrate_mask, |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 5356 | .channel_switch = wl12xx_op_channel_switch, |
Eliad Peller | d8ae5a2 | 2012-06-25 13:52:33 +0300 | [diff] [blame] | 5357 | .flush = wlcore_op_flush, |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5358 | .remain_on_channel = wlcore_op_remain_on_channel, |
| 5359 | .cancel_remain_on_channel = wlcore_op_cancel_remain_on_channel, |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 5360 | .add_chanctx = wlcore_op_add_chanctx, |
| 5361 | .remove_chanctx = wlcore_op_remove_chanctx, |
| 5362 | .change_chanctx = wlcore_op_change_chanctx, |
| 5363 | .assign_vif_chanctx = wlcore_op_assign_vif_chanctx, |
| 5364 | .unassign_vif_chanctx = wlcore_op_unassign_vif_chanctx, |
Arik Nemtsov | 5f9b677 | 2012-11-26 18:05:41 +0200 | [diff] [blame] | 5365 | .sta_rc_update = wlcore_op_sta_rc_update, |
Nadim Zubidat | 0a9ffac | 2013-03-12 17:19:39 +0200 | [diff] [blame] | 5366 | .get_rssi = wlcore_op_get_rssi, |
Kalle Valo | c8c9087 | 2010-02-18 13:25:53 +0200 | [diff] [blame] | 5367 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5368 | }; |
| 5369 | |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5370 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5371 | u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band) |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5372 | { |
| 5373 | u8 idx; |
| 5374 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5375 | BUG_ON(band >= 2); |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5376 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5377 | if (unlikely(rate >= wl->hw_tx_rate_tbl_size)) { |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5378 | wl1271_error("Illegal RX rate from HW: %d", rate); |
| 5379 | return 0; |
| 5380 | } |
| 5381 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5382 | idx = wl->band_rate_to_idx[band][rate]; |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5383 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { |
| 5384 | wl1271_error("Unsupported RX rate from HW: %d", rate); |
| 5385 | return 0; |
| 5386 | } |
| 5387 | |
| 5388 | return idx; |
| 5389 | } |
| 5390 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5391 | static void wl12xx_derive_mac_addresses(struct wl1271 *wl, u32 oui, u32 nic) |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5392 | { |
| 5393 | int i; |
| 5394 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5395 | wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x", |
| 5396 | oui, nic); |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5397 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5398 | if (nic + WLCORE_NUM_MAC_ADDRESSES - wl->num_mac_addr > 0xffffff) |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5399 | wl1271_warning("NIC part of the MAC address wraps around!"); |
| 5400 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5401 | for (i = 0; i < wl->num_mac_addr; i++) { |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5402 | wl->addresses[i].addr[0] = (u8)(oui >> 16); |
| 5403 | wl->addresses[i].addr[1] = (u8)(oui >> 8); |
| 5404 | wl->addresses[i].addr[2] = (u8) oui; |
| 5405 | wl->addresses[i].addr[3] = (u8)(nic >> 16); |
| 5406 | wl->addresses[i].addr[4] = (u8)(nic >> 8); |
| 5407 | wl->addresses[i].addr[5] = (u8) nic; |
| 5408 | nic++; |
| 5409 | } |
| 5410 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5411 | /* we may be one address short at the most */ |
| 5412 | WARN_ON(wl->num_mac_addr + 1 < WLCORE_NUM_MAC_ADDRESSES); |
| 5413 | |
| 5414 | /* |
| 5415 | * turn on the LAA bit in the first address and use it as |
| 5416 | * the last address. |
| 5417 | */ |
| 5418 | if (wl->num_mac_addr < WLCORE_NUM_MAC_ADDRESSES) { |
| 5419 | int idx = WLCORE_NUM_MAC_ADDRESSES - 1; |
| 5420 | memcpy(&wl->addresses[idx], &wl->addresses[0], |
| 5421 | sizeof(wl->addresses[0])); |
| 5422 | /* LAA bit */ |
| 5423 | wl->addresses[idx].addr[2] |= BIT(1); |
| 5424 | } |
| 5425 | |
| 5426 | wl->hw->wiphy->n_addresses = WLCORE_NUM_MAC_ADDRESSES; |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5427 | wl->hw->wiphy->addresses = wl->addresses; |
| 5428 | } |
| 5429 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5430 | static int wl12xx_get_hw_info(struct wl1271 *wl) |
| 5431 | { |
| 5432 | int ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5433 | |
| 5434 | ret = wl12xx_set_power_on(wl); |
| 5435 | if (ret < 0) |
Julia Lawall | 4fb4e0b | 2012-10-21 12:52:04 +0200 | [diff] [blame] | 5436 | return ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5437 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5438 | ret = wlcore_read_reg(wl, REG_CHIP_ID_B, &wl->chip.id); |
| 5439 | if (ret < 0) |
| 5440 | goto out; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5441 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 5442 | wl->fuse_oui_addr = 0; |
| 5443 | wl->fuse_nic_addr = 0; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5444 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5445 | ret = wl->ops->get_pg_ver(wl, &wl->hw_pg_ver); |
| 5446 | if (ret < 0) |
| 5447 | goto out; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5448 | |
Luciano Coelho | 30d9b4a | 2012-04-11 11:07:28 +0300 | [diff] [blame] | 5449 | if (wl->ops->get_mac) |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5450 | ret = wl->ops->get_mac(wl); |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5451 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5452 | out: |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5453 | wl1271_power_off(wl); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5454 | return ret; |
| 5455 | } |
| 5456 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5457 | static int wl1271_register_hw(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5458 | { |
| 5459 | int ret; |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5460 | u32 oui_addr = 0, nic_addr = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5461 | |
| 5462 | if (wl->mac80211_registered) |
| 5463 | return 0; |
| 5464 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5465 | if (wl->nvs_len >= 12) { |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 5466 | /* NOTE: The wl->nvs->nvs element must be first, in |
| 5467 | * order to simplify the casting, we assume it is at |
| 5468 | * the beginning of the wl->nvs structure. |
| 5469 | */ |
| 5470 | u8 *nvs_ptr = (u8 *)wl->nvs; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5471 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5472 | oui_addr = |
| 5473 | (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6]; |
| 5474 | nic_addr = |
| 5475 | (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3]; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5476 | } |
| 5477 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5478 | /* if the MAC address is zeroed in the NVS derive from fuse */ |
| 5479 | if (oui_addr == 0 && nic_addr == 0) { |
| 5480 | oui_addr = wl->fuse_oui_addr; |
| 5481 | /* fuse has the BD_ADDR, the WLAN addresses are the next two */ |
| 5482 | nic_addr = wl->fuse_nic_addr + 1; |
| 5483 | } |
| 5484 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5485 | wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5486 | |
| 5487 | ret = ieee80211_register_hw(wl->hw); |
| 5488 | if (ret < 0) { |
| 5489 | wl1271_error("unable to register mac80211 hw: %d", ret); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5490 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5491 | } |
| 5492 | |
| 5493 | wl->mac80211_registered = true; |
| 5494 | |
Eliad Peller | d60080a | 2010-11-24 12:53:16 +0200 | [diff] [blame] | 5495 | wl1271_debugfs_init(wl); |
| 5496 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5497 | wl1271_notice("loaded"); |
| 5498 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5499 | out: |
| 5500 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5501 | } |
| 5502 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5503 | static void wl1271_unregister_hw(struct wl1271 *wl) |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5504 | { |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5505 | if (wl->plt) |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 5506 | wl1271_plt_stop(wl); |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 5507 | |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5508 | ieee80211_unregister_hw(wl->hw); |
| 5509 | wl->mac80211_registered = false; |
| 5510 | |
| 5511 | } |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5512 | |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5513 | static const struct ieee80211_iface_limit wlcore_iface_limits[] = { |
| 5514 | { |
Arik Nemtsov | e7a6ba29 | 2012-08-02 22:00:34 +0300 | [diff] [blame] | 5515 | .max = 3, |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5516 | .types = BIT(NL80211_IFTYPE_STATION), |
| 5517 | }, |
| 5518 | { |
| 5519 | .max = 1, |
| 5520 | .types = BIT(NL80211_IFTYPE_AP) | |
| 5521 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 5522 | BIT(NL80211_IFTYPE_P2P_CLIENT), |
| 5523 | }, |
| 5524 | }; |
| 5525 | |
Arik Nemtsov | de40750 | 2012-11-26 18:05:44 +0200 | [diff] [blame] | 5526 | static struct ieee80211_iface_combination |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5527 | wlcore_iface_combinations[] = { |
| 5528 | { |
Arik Nemtsov | e7a6ba29 | 2012-08-02 22:00:34 +0300 | [diff] [blame] | 5529 | .max_interfaces = 3, |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5530 | .limits = wlcore_iface_limits, |
| 5531 | .n_limits = ARRAY_SIZE(wlcore_iface_limits), |
| 5532 | }, |
| 5533 | }; |
| 5534 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5535 | static int wl1271_init_ieee80211(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5536 | { |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5537 | int i; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5538 | static const u32 cipher_suites[] = { |
| 5539 | WLAN_CIPHER_SUITE_WEP40, |
| 5540 | WLAN_CIPHER_SUITE_WEP104, |
| 5541 | WLAN_CIPHER_SUITE_TKIP, |
| 5542 | WLAN_CIPHER_SUITE_CCMP, |
| 5543 | WL1271_CIPHER_SUITE_GEM, |
| 5544 | }; |
| 5545 | |
Arik Nemtsov | 2c0133a | 2012-05-18 07:46:36 +0300 | [diff] [blame] | 5546 | /* The tx descriptor buffer */ |
| 5547 | wl->hw->extra_tx_headroom = sizeof(struct wl1271_tx_hw_descr); |
| 5548 | |
| 5549 | if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) |
| 5550 | wl->hw->extra_tx_headroom += WL1271_EXTRA_SPACE_TKIP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5551 | |
| 5552 | /* unit us */ |
| 5553 | /* FIXME: find a proper value */ |
| 5554 | wl->hw->channel_change_time = 10000; |
Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 5555 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5556 | |
| 5557 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Juuso Oikarinen | 0a34332 | 2010-02-22 08:38:41 +0200 | [diff] [blame] | 5558 | IEEE80211_HW_SUPPORTS_PS | |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 5559 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 5560 | IEEE80211_HW_SUPPORTS_UAPSD | |
Juuso Oikarinen | a9af092 | 2010-03-26 12:53:30 +0200 | [diff] [blame] | 5561 | IEEE80211_HW_HAS_RATE_CONTROL | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 5562 | IEEE80211_HW_CONNECTION_MONITOR | |
Luciano Coelho | 25eaea30 | 2011-05-02 12:37:33 +0300 | [diff] [blame] | 5563 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
Shahar Levi | fcd23b6 | 2011-05-11 12:12:56 +0300 | [diff] [blame] | 5564 | IEEE80211_HW_SPECTRUM_MGMT | |
Arik Nemtsov | 93f8c8e | 2011-08-30 09:34:01 +0300 | [diff] [blame] | 5565 | IEEE80211_HW_AP_LINK_PS | |
| 5566 | IEEE80211_HW_AMPDU_AGGREGATION | |
Eliad Peller | 79aba1b | 2012-02-02 13:15:35 +0200 | [diff] [blame] | 5567 | IEEE80211_HW_TX_AMPDU_SETUP_IN_HW | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 5568 | IEEE80211_HW_QUEUE_CONTROL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5569 | |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5570 | wl->hw->wiphy->cipher_suites = cipher_suites; |
| 5571 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 5572 | |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 5573 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 5574 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) | |
| 5575 | BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5576 | wl->hw->wiphy->max_scan_ssids = 1; |
Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 5577 | wl->hw->wiphy->max_sched_scan_ssids = 16; |
| 5578 | wl->hw->wiphy->max_match_sets = 16; |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5579 | /* |
| 5580 | * Maximum length of elements in scanning probe request templates |
| 5581 | * should be the maximum length possible for a template, without |
| 5582 | * the IEEE80211 header of the template |
| 5583 | */ |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5584 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5585 | sizeof(struct ieee80211_header); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5586 | |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5587 | wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
Luciano Coelho | c9e79a4 | 2011-09-27 16:22:35 +0300 | [diff] [blame] | 5588 | sizeof(struct ieee80211_header); |
| 5589 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5590 | wl->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 5591 | |
Johannes Berg | 81ddbb5 | 2012-03-26 18:47:18 +0200 | [diff] [blame] | 5592 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD | |
| 5593 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 5594 | |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 5595 | /* make sure all our channels fit in the scanned_ch bitmask */ |
| 5596 | BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + |
| 5597 | ARRAY_SIZE(wl1271_channels_5ghz) > |
| 5598 | WL1271_MAX_CHANNELS); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5599 | /* |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5600 | * clear channel flags from the previous usage |
| 5601 | * and restore max_power & max_antenna_gain values. |
| 5602 | */ |
| 5603 | for (i = 0; i < ARRAY_SIZE(wl1271_channels); i++) { |
| 5604 | wl1271_band_2ghz.channels[i].flags = 0; |
| 5605 | wl1271_band_2ghz.channels[i].max_power = WLCORE_MAX_TXPWR; |
| 5606 | wl1271_band_2ghz.channels[i].max_antenna_gain = 0; |
| 5607 | } |
| 5608 | |
| 5609 | for (i = 0; i < ARRAY_SIZE(wl1271_channels_5ghz); i++) { |
| 5610 | wl1271_band_5ghz.channels[i].flags = 0; |
| 5611 | wl1271_band_5ghz.channels[i].max_power = WLCORE_MAX_TXPWR; |
| 5612 | wl1271_band_5ghz.channels[i].max_antenna_gain = 0; |
| 5613 | } |
| 5614 | |
| 5615 | /* |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5616 | * We keep local copies of the band structs because we need to |
| 5617 | * modify them on a per-device basis. |
| 5618 | */ |
| 5619 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, |
| 5620 | sizeof(wl1271_band_2ghz)); |
Eliad Peller | bfb92ca | 2012-05-15 17:09:00 +0300 | [diff] [blame] | 5621 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, |
| 5622 | &wl->ht_cap[IEEE80211_BAND_2GHZ], |
| 5623 | sizeof(*wl->ht_cap)); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5624 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, |
| 5625 | sizeof(wl1271_band_5ghz)); |
Eliad Peller | bfb92ca | 2012-05-15 17:09:00 +0300 | [diff] [blame] | 5626 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, |
| 5627 | &wl->ht_cap[IEEE80211_BAND_5GHZ], |
| 5628 | sizeof(*wl->ht_cap)); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5629 | |
| 5630 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 5631 | &wl->bands[IEEE80211_BAND_2GHZ]; |
| 5632 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 5633 | &wl->bands[IEEE80211_BAND_5GHZ]; |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5634 | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 5635 | /* |
| 5636 | * allow 4 queues per mac address we support + |
| 5637 | * 1 cab queue per mac + one global offchannel Tx queue |
| 5638 | */ |
| 5639 | wl->hw->queues = (NUM_TX_QUEUES + 1) * WLCORE_NUM_MAC_ADDRESSES + 1; |
| 5640 | |
| 5641 | /* the last queue is the offchannel queue */ |
| 5642 | wl->hw->offchannel_tx_hw_queue = wl->hw->queues - 1; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 5643 | wl->hw->max_rates = 1; |
Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5644 | |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 5645 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; |
| 5646 | |
Arik Nemtsov | 9c1b190 | 2011-11-08 18:46:55 +0200 | [diff] [blame] | 5647 | /* the FW answers probe-requests in AP-mode */ |
| 5648 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 5649 | wl->hw->wiphy->probe_resp_offload = |
| 5650 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 5651 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 5652 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 5653 | |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5654 | /* allowed interface combinations */ |
Arik Nemtsov | de40750 | 2012-11-26 18:05:44 +0200 | [diff] [blame] | 5655 | wlcore_iface_combinations[0].num_different_channels = wl->num_channels; |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5656 | wl->hw->wiphy->iface_combinations = wlcore_iface_combinations; |
| 5657 | wl->hw->wiphy->n_iface_combinations = |
| 5658 | ARRAY_SIZE(wlcore_iface_combinations); |
| 5659 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5660 | SET_IEEE80211_DEV(wl->hw, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5661 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5662 | wl->hw->sta_data_size = sizeof(struct wl1271_station); |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 5663 | wl->hw->vif_data_size = sizeof(struct wl12xx_vif); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5664 | |
Arik Nemtsov | ba421f8 | 2012-01-06 00:05:51 +0200 | [diff] [blame] | 5665 | wl->hw->max_rx_aggregation_subframes = wl->conf.ht.rx_ba_win_size; |
Luciano Coelho | 4c9cfa7 | 2011-01-12 14:27:03 +0100 | [diff] [blame] | 5666 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5667 | return 0; |
| 5668 | } |
| 5669 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 5670 | struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size, u32 aggr_buf_size, |
| 5671 | u32 mbox_size) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5672 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5673 | struct ieee80211_hw *hw; |
| 5674 | struct wl1271 *wl; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5675 | int i, j, ret; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5676 | unsigned int order; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5677 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5678 | BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS); |
Arik Nemtsov | f80c2d1 | 2011-09-22 09:52:05 +0300 | [diff] [blame] | 5679 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5680 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); |
| 5681 | if (!hw) { |
| 5682 | wl1271_error("could not alloc ieee80211_hw"); |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5683 | ret = -ENOMEM; |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5684 | goto err_hw_alloc; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | wl = hw->priv; |
| 5688 | memset(wl, 0, sizeof(*wl)); |
| 5689 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5690 | wl->priv = kzalloc(priv_size, GFP_KERNEL); |
| 5691 | if (!wl->priv) { |
| 5692 | wl1271_error("could not alloc wl priv"); |
| 5693 | ret = -ENOMEM; |
| 5694 | goto err_priv_alloc; |
| 5695 | } |
| 5696 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 5697 | INIT_LIST_HEAD(&wl->wlvif_list); |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 5698 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5699 | wl->hw = hw; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5700 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 5701 | for (i = 0; i < NUM_TX_QUEUES; i++) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5702 | for (j = 0; j < WL12XX_MAX_LINKS; j++) |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5703 | skb_queue_head_init(&wl->links[j].tx_queue[i]); |
| 5704 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5705 | skb_queue_head_init(&wl->deferred_rx_queue); |
| 5706 | skb_queue_head_init(&wl->deferred_tx_queue); |
| 5707 | |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 5708 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5709 | INIT_WORK(&wl->netstack_work, wl1271_netstack_work); |
Juuso Oikarinen | 117b38d | 2010-09-30 10:43:28 +0200 | [diff] [blame] | 5710 | INIT_WORK(&wl->tx_work, wl1271_tx_work); |
| 5711 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); |
| 5712 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5713 | INIT_DELAYED_WORK(&wl->roc_complete_work, wlcore_roc_complete_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 5714 | INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 5715 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5716 | wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); |
| 5717 | if (!wl->freezable_wq) { |
| 5718 | ret = -ENOMEM; |
| 5719 | goto err_hw; |
| 5720 | } |
| 5721 | |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame] | 5722 | wl->channel = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5723 | wl->rx_counter = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5724 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 5725 | wl->band = IEEE80211_BAND_2GHZ; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 5726 | wl->channel_type = NL80211_CHAN_NO_HT; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 5727 | wl->flags = 0; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5728 | wl->sg_enabled = true; |
Arik Nemtsov | 66340e5 | 2012-06-10 17:09:22 +0300 | [diff] [blame] | 5729 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Luciano Coelho | c108c90 | 2012-11-26 18:05:49 +0200 | [diff] [blame] | 5730 | wl->recovery_count = 0; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5731 | wl->hw_pg_ver = -1; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 5732 | wl->ap_ps_map = 0; |
| 5733 | wl->ap_fw_ps_map = 0; |
Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 5734 | wl->quirks = 0; |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 5735 | wl->platform_quirks = 0; |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5736 | wl->system_hlid = WL12XX_SYSTEM_HLID; |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 5737 | wl->active_sta_count = 0; |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 5738 | wl->active_link_count = 0; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5739 | wl->fwlog_size = 0; |
| 5740 | init_waitqueue_head(&wl->fwlog_waitq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5741 | |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5742 | /* The system link is always allocated */ |
| 5743 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 5744 | |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 5745 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 5746 | for (i = 0; i < wl->num_tx_desc; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5747 | wl->tx_frames[i] = NULL; |
| 5748 | |
| 5749 | spin_lock_init(&wl->wl_lock); |
| 5750 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 5751 | wl->state = WLCORE_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5752 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5753 | mutex_init(&wl->mutex); |
Arik Nemtsov | 2c38849 | 2012-05-18 07:46:39 +0300 | [diff] [blame] | 5754 | mutex_init(&wl->flush_mutex); |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5755 | init_completion(&wl->nvs_loading_complete); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5756 | |
Igal Chernobelsky | 26a309c | 2012-07-29 18:21:12 +0300 | [diff] [blame] | 5757 | order = get_order(aggr_buf_size); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5758 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); |
| 5759 | if (!wl->aggr_buf) { |
| 5760 | ret = -ENOMEM; |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5761 | goto err_wq; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5762 | } |
Igal Chernobelsky | 26a309c | 2012-07-29 18:21:12 +0300 | [diff] [blame] | 5763 | wl->aggr_buf_size = aggr_buf_size; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5764 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5765 | wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); |
| 5766 | if (!wl->dummy_packet) { |
| 5767 | ret = -ENOMEM; |
| 5768 | goto err_aggr; |
| 5769 | } |
| 5770 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5771 | /* Allocate one page for the FW log */ |
| 5772 | wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); |
| 5773 | if (!wl->fwlog) { |
| 5774 | ret = -ENOMEM; |
| 5775 | goto err_dummy_packet; |
| 5776 | } |
| 5777 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 5778 | wl->mbox_size = mbox_size; |
| 5779 | wl->mbox = kmalloc(wl->mbox_size, GFP_KERNEL | GFP_DMA); |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 5780 | if (!wl->mbox) { |
| 5781 | ret = -ENOMEM; |
| 5782 | goto err_fwlog; |
| 5783 | } |
| 5784 | |
Ido Yariv | 2e07d02 | 2012-11-28 11:42:49 +0200 | [diff] [blame] | 5785 | wl->buffer_32 = kmalloc(sizeof(*wl->buffer_32), GFP_KERNEL); |
| 5786 | if (!wl->buffer_32) { |
| 5787 | ret = -ENOMEM; |
| 5788 | goto err_mbox; |
| 5789 | } |
| 5790 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5791 | return hw; |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5792 | |
Ido Yariv | 2e07d02 | 2012-11-28 11:42:49 +0200 | [diff] [blame] | 5793 | err_mbox: |
| 5794 | kfree(wl->mbox); |
| 5795 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 5796 | err_fwlog: |
| 5797 | free_page((unsigned long)wl->fwlog); |
| 5798 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5799 | err_dummy_packet: |
| 5800 | dev_kfree_skb(wl->dummy_packet); |
| 5801 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5802 | err_aggr: |
| 5803 | free_pages((unsigned long)wl->aggr_buf, order); |
| 5804 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5805 | err_wq: |
| 5806 | destroy_workqueue(wl->freezable_wq); |
| 5807 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5808 | err_hw: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5809 | wl1271_debugfs_exit(wl); |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5810 | kfree(wl->priv); |
| 5811 | |
| 5812 | err_priv_alloc: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5813 | ieee80211_free_hw(hw); |
| 5814 | |
| 5815 | err_hw_alloc: |
| 5816 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5817 | return ERR_PTR(ret); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5818 | } |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5819 | EXPORT_SYMBOL_GPL(wlcore_alloc_hw); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5820 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5821 | int wlcore_free_hw(struct wl1271 *wl) |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5822 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5823 | /* Unblock any fwlog readers */ |
| 5824 | mutex_lock(&wl->mutex); |
| 5825 | wl->fwlog_size = -1; |
| 5826 | wake_up_interruptible_all(&wl->fwlog_waitq); |
| 5827 | mutex_unlock(&wl->mutex); |
| 5828 | |
Luciano Coelho | 33cab57 | 2013-05-04 02:46:38 +0300 | [diff] [blame^] | 5829 | wlcore_sysfs_free(wl); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5830 | |
Ido Yariv | 2e07d02 | 2012-11-28 11:42:49 +0200 | [diff] [blame] | 5831 | kfree(wl->buffer_32); |
Eliad Peller | a8e2782 | 2012-11-19 17:14:06 +0200 | [diff] [blame] | 5832 | kfree(wl->mbox); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5833 | free_page((unsigned long)wl->fwlog); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5834 | dev_kfree_skb(wl->dummy_packet); |
Igal Chernobelsky | 26a309c | 2012-07-29 18:21:12 +0300 | [diff] [blame] | 5835 | free_pages((unsigned long)wl->aggr_buf, get_order(wl->aggr_buf_size)); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5836 | |
| 5837 | wl1271_debugfs_exit(wl); |
| 5838 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5839 | vfree(wl->fw); |
| 5840 | wl->fw = NULL; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5841 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5842 | kfree(wl->nvs); |
| 5843 | wl->nvs = NULL; |
| 5844 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 5845 | kfree(wl->fw_status_1); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5846 | kfree(wl->tx_res_if); |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5847 | destroy_workqueue(wl->freezable_wq); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5848 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5849 | kfree(wl->priv); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5850 | ieee80211_free_hw(wl->hw); |
| 5851 | |
| 5852 | return 0; |
| 5853 | } |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5854 | EXPORT_SYMBOL_GPL(wlcore_free_hw); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5855 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 5856 | #ifdef CONFIG_PM |
| 5857 | static const struct wiphy_wowlan_support wlcore_wowlan_support = { |
| 5858 | .flags = WIPHY_WOWLAN_ANY, |
| 5859 | .n_patterns = WL1271_MAX_RX_FILTERS, |
| 5860 | .pattern_min_len = 1, |
| 5861 | .pattern_max_len = WL1271_RX_FILTER_MAX_PATTERN_SIZE, |
| 5862 | }; |
| 5863 | #endif |
| 5864 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5865 | static void wlcore_nvs_cb(const struct firmware *fw, void *context) |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5866 | { |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5867 | struct wl1271 *wl = context; |
| 5868 | struct platform_device *pdev = wl->pdev; |
Luciano Coelho | afb43e6 | 2013-01-25 11:57:48 +0200 | [diff] [blame] | 5869 | struct wlcore_platdev_data *pdev_data = pdev->dev.platform_data; |
| 5870 | struct wl12xx_platform_data *pdata = pdev_data->pdata; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5871 | unsigned long irqflags; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5872 | int ret; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5873 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5874 | if (fw) { |
| 5875 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); |
| 5876 | if (!wl->nvs) { |
| 5877 | wl1271_error("Could not allocate nvs data"); |
| 5878 | goto out; |
| 5879 | } |
| 5880 | wl->nvs_len = fw->size; |
| 5881 | } else { |
| 5882 | wl1271_debug(DEBUG_BOOT, "Could not get nvs file %s", |
| 5883 | WL12XX_NVS_NAME); |
| 5884 | wl->nvs = NULL; |
| 5885 | wl->nvs_len = 0; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5886 | } |
| 5887 | |
Ido Yariv | 3992eb2 | 2012-09-02 12:29:27 +0300 | [diff] [blame] | 5888 | ret = wl->ops->setup(wl); |
| 5889 | if (ret < 0) |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5890 | goto out_free_nvs; |
Ido Yariv | 3992eb2 | 2012-09-02 12:29:27 +0300 | [diff] [blame] | 5891 | |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 5892 | BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS); |
| 5893 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 5894 | /* adjust some runtime configuration parameters */ |
| 5895 | wlcore_adjust_conf(wl); |
| 5896 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5897 | wl->irq = platform_get_irq(pdev, 0); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5898 | wl->platform_quirks = pdata->platform_quirks; |
Luciano Coelho | afb43e6 | 2013-01-25 11:57:48 +0200 | [diff] [blame] | 5899 | wl->if_ops = pdev_data->if_ops; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5900 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5901 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 5902 | irqflags = IRQF_TRIGGER_RISING; |
| 5903 | else |
| 5904 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; |
| 5905 | |
Luciano Coelho | 97236a0 | 2013-03-08 09:41:53 +0200 | [diff] [blame] | 5906 | ret = request_threaded_irq(wl->irq, NULL, wlcore_irq, |
| 5907 | irqflags, pdev->name, wl); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5908 | if (ret < 0) { |
| 5909 | wl1271_error("request_irq() failed: %d", ret); |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5910 | goto out_free_nvs; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5911 | } |
| 5912 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 5913 | #ifdef CONFIG_PM |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5914 | ret = enable_irq_wake(wl->irq); |
| 5915 | if (!ret) { |
| 5916 | wl->irq_wake_enabled = true; |
| 5917 | device_init_wakeup(wl->dev, 1); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 5918 | if (pdata->pwr_in_suspend) |
| 5919 | wl->hw->wiphy->wowlan = &wlcore_wowlan_support; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5920 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 5921 | #endif |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5922 | disable_irq(wl->irq); |
| 5923 | |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 5924 | ret = wl12xx_get_hw_info(wl); |
| 5925 | if (ret < 0) { |
| 5926 | wl1271_error("couldn't get hw info"); |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 5927 | goto out_irq; |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 5928 | } |
| 5929 | |
| 5930 | ret = wl->ops->identify_chip(wl); |
| 5931 | if (ret < 0) |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 5932 | goto out_irq; |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 5933 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5934 | ret = wl1271_init_ieee80211(wl); |
| 5935 | if (ret) |
| 5936 | goto out_irq; |
| 5937 | |
| 5938 | ret = wl1271_register_hw(wl); |
| 5939 | if (ret) |
| 5940 | goto out_irq; |
| 5941 | |
Luciano Coelho | 33cab57 | 2013-05-04 02:46:38 +0300 | [diff] [blame^] | 5942 | ret = wlcore_sysfs_init(wl); |
| 5943 | if (ret) |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 5944 | goto out_unreg; |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5945 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5946 | wl->initialized = true; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5947 | goto out; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5948 | |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 5949 | out_unreg: |
| 5950 | wl1271_unregister_hw(wl); |
| 5951 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5952 | out_irq: |
| 5953 | free_irq(wl->irq, wl); |
| 5954 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5955 | out_free_nvs: |
| 5956 | kfree(wl->nvs); |
| 5957 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5958 | out: |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5959 | release_firmware(fw); |
| 5960 | complete_all(&wl->nvs_loading_complete); |
| 5961 | } |
| 5962 | |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 5963 | int wlcore_probe(struct wl1271 *wl, struct platform_device *pdev) |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5964 | { |
| 5965 | int ret; |
| 5966 | |
| 5967 | if (!wl->ops || !wl->ptable) |
| 5968 | return -EINVAL; |
| 5969 | |
| 5970 | wl->dev = &pdev->dev; |
| 5971 | wl->pdev = pdev; |
| 5972 | platform_set_drvdata(pdev, wl); |
| 5973 | |
| 5974 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 5975 | WL12XX_NVS_NAME, &pdev->dev, GFP_KERNEL, |
| 5976 | wl, wlcore_nvs_cb); |
| 5977 | if (ret < 0) { |
| 5978 | wl1271_error("request_firmware_nowait failed: %d", ret); |
| 5979 | complete_all(&wl->nvs_loading_complete); |
| 5980 | } |
| 5981 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5982 | return ret; |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5983 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 5984 | EXPORT_SYMBOL_GPL(wlcore_probe); |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5985 | |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 5986 | int wlcore_remove(struct platform_device *pdev) |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5987 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5988 | struct wl1271 *wl = platform_get_drvdata(pdev); |
| 5989 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5990 | wait_for_completion(&wl->nvs_loading_complete); |
| 5991 | if (!wl->initialized) |
| 5992 | return 0; |
| 5993 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5994 | if (wl->irq_wake_enabled) { |
| 5995 | device_init_wakeup(wl->dev, 0); |
| 5996 | disable_irq_wake(wl->irq); |
| 5997 | } |
| 5998 | wl1271_unregister_hw(wl); |
| 5999 | free_irq(wl->irq, wl); |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 6000 | wlcore_free_hw(wl); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6001 | |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6002 | return 0; |
| 6003 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 6004 | EXPORT_SYMBOL_GPL(wlcore_remove); |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6005 | |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 6006 | u32 wl12xx_debug_level = DEBUG_NONE; |
Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 6007 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 6008 | module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR); |
Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 6009 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); |
| 6010 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 6011 | module_param_named(fwlog, fwlog_param, charp, 0); |
Luciano Coelho | 2c882fa | 2012-02-07 12:37:33 +0200 | [diff] [blame] | 6012 | MODULE_PARM_DESC(fwlog, |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 6013 | "FW logger options: continuous, ondemand, dbgpins or disable"); |
| 6014 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 6015 | module_param(bug_on_recovery, int, S_IRUSR | S_IWUSR); |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 6016 | MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery"); |
| 6017 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 6018 | module_param(no_recovery, int, S_IRUSR | S_IWUSR); |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 6019 | MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck."); |
| 6020 | |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 6021 | MODULE_LICENSE("GPL"); |
Luciano Coelho | b1a48ca | 2011-02-22 14:19:28 +0200 | [diff] [blame] | 6022 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 6023 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |
Tim Gardner | 0635ad4 | 2012-08-29 13:09:33 -0600 | [diff] [blame] | 6024 | MODULE_FIRMWARE(WL12XX_NVS_NAME); |