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 | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 42 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 43 | #define WL1271_BOOT_RETRIES 3 |
| 44 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 45 | static char *fwlog_param; |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 46 | static int bug_on_recovery = -1; |
| 47 | static int no_recovery = -1; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 48 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 49 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 50 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 51 | bool reset_tx_queues); |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 52 | static void wlcore_op_stop_locked(struct wl1271 *wl); |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 53 | 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] | 54 | |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame^] | 55 | static int wl12xx_set_authorized(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 56 | { |
| 57 | int ret; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 58 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 59 | if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS)) |
| 60 | return -EINVAL; |
| 61 | |
| 62 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 63 | return 0; |
| 64 | |
Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 65 | if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 66 | return 0; |
| 67 | |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 68 | ret = wl12xx_cmd_set_peer_state(wl, wlvif, wlvif->sta.hlid); |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 69 | if (ret < 0) |
| 70 | return ret; |
| 71 | |
| 72 | wl1271_info("Association completed."); |
| 73 | return 0; |
| 74 | } |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 75 | |
Luis R. Rodriguez | 0c0280b | 2013-01-11 18:39:36 +0000 | [diff] [blame] | 76 | static void wl1271_reg_notify(struct wiphy *wiphy, |
| 77 | struct regulatory_request *request) |
Luciano Coelho | 573c67c | 2010-11-26 13:44:59 +0200 | [diff] [blame] | 78 | { |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 79 | struct ieee80211_supported_band *band; |
| 80 | struct ieee80211_channel *ch; |
| 81 | int i; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 82 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 83 | struct wl1271 *wl = hw->priv; |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 84 | |
| 85 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 86 | for (i = 0; i < band->n_channels; i++) { |
| 87 | ch = &band->channels[i]; |
| 88 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 89 | continue; |
| 90 | |
| 91 | if (ch->flags & IEEE80211_CHAN_RADAR) |
| 92 | ch->flags |= IEEE80211_CHAN_NO_IBSS | |
| 93 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 94 | |
| 95 | } |
| 96 | |
Arik Nemtsov | 75592be | 2013-03-12 17:19:45 +0200 | [diff] [blame] | 97 | wlcore_regdomain_config(wl); |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 100 | static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 101 | bool enable) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 102 | { |
| 103 | int ret = 0; |
| 104 | |
| 105 | /* we should hold wl->mutex */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 106 | ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 107 | if (ret < 0) |
| 108 | goto out; |
| 109 | |
| 110 | if (enable) |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 111 | set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 112 | else |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 113 | clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 114 | out: |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * this function is being called when the rx_streaming interval |
| 120 | * has beed changed or rx_streaming should be disabled |
| 121 | */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 122 | int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 123 | { |
| 124 | int ret = 0; |
| 125 | int period = wl->conf.rx_streaming.interval; |
| 126 | |
| 127 | /* don't reconfigure if rx_streaming is disabled */ |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 128 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 129 | goto out; |
| 130 | |
| 131 | /* reconfigure/disable according to new streaming_period */ |
| 132 | if (period && |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 133 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 134 | (wl->conf.rx_streaming.always || |
| 135 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 136 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 137 | else { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 138 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 139 | /* don't cancel_work_sync since we might deadlock */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 140 | del_timer_sync(&wlvif->rx_streaming_timer); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 141 | } |
| 142 | out: |
| 143 | return ret; |
| 144 | } |
| 145 | |
| 146 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) |
| 147 | { |
| 148 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 149 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 150 | rx_streaming_enable_work); |
| 151 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 152 | |
| 153 | mutex_lock(&wl->mutex); |
| 154 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 155 | if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) || |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 156 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 157 | (!wl->conf.rx_streaming.always && |
| 158 | !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
| 159 | goto out; |
| 160 | |
| 161 | if (!wl->conf.rx_streaming.interval) |
| 162 | goto out; |
| 163 | |
| 164 | ret = wl1271_ps_elp_wakeup(wl); |
| 165 | if (ret < 0) |
| 166 | goto out; |
| 167 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 168 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 169 | if (ret < 0) |
| 170 | goto out_sleep; |
| 171 | |
| 172 | /* stop it after some time of inactivity */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 173 | mod_timer(&wlvif->rx_streaming_timer, |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 174 | jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); |
| 175 | |
| 176 | out_sleep: |
| 177 | wl1271_ps_elp_sleep(wl); |
| 178 | out: |
| 179 | mutex_unlock(&wl->mutex); |
| 180 | } |
| 181 | |
| 182 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) |
| 183 | { |
| 184 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 185 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 186 | rx_streaming_disable_work); |
| 187 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 188 | |
| 189 | mutex_lock(&wl->mutex); |
| 190 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 191 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 192 | goto out; |
| 193 | |
| 194 | ret = wl1271_ps_elp_wakeup(wl); |
| 195 | if (ret < 0) |
| 196 | goto out; |
| 197 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 198 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 199 | if (ret) |
| 200 | goto out_sleep; |
| 201 | |
| 202 | out_sleep: |
| 203 | wl1271_ps_elp_sleep(wl); |
| 204 | out: |
| 205 | mutex_unlock(&wl->mutex); |
| 206 | } |
| 207 | |
| 208 | static void wl1271_rx_streaming_timer(unsigned long data) |
| 209 | { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 210 | struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data; |
| 211 | struct wl1271 *wl = wlvif->wl; |
| 212 | ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 213 | } |
| 214 | |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 215 | /* wl->mutex must be taken */ |
| 216 | void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl) |
| 217 | { |
| 218 | /* if the watchdog is not armed, don't do anything */ |
| 219 | if (wl->tx_allocated_blocks == 0) |
| 220 | return; |
| 221 | |
| 222 | cancel_delayed_work(&wl->tx_watchdog_work); |
| 223 | ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work, |
| 224 | msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout)); |
| 225 | } |
| 226 | |
| 227 | static void wl12xx_tx_watchdog_work(struct work_struct *work) |
| 228 | { |
| 229 | struct delayed_work *dwork; |
| 230 | struct wl1271 *wl; |
| 231 | |
| 232 | dwork = container_of(work, struct delayed_work, work); |
| 233 | wl = container_of(dwork, struct wl1271, tx_watchdog_work); |
| 234 | |
| 235 | mutex_lock(&wl->mutex); |
| 236 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 237 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 238 | goto out; |
| 239 | |
| 240 | /* Tx went out in the meantime - everything is ok */ |
| 241 | if (unlikely(wl->tx_allocated_blocks == 0)) |
| 242 | goto out; |
| 243 | |
| 244 | /* |
| 245 | * if a ROC is in progress, we might not have any Tx for a long |
| 246 | * time (e.g. pending Tx on the non-ROC channels) |
| 247 | */ |
| 248 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { |
| 249 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC", |
| 250 | wl->conf.tx.tx_watchdog_timeout); |
| 251 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 252 | goto out; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * if a scan is in progress, we might not have any Tx for a long |
| 257 | * time |
| 258 | */ |
| 259 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { |
| 260 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan", |
| 261 | wl->conf.tx.tx_watchdog_timeout); |
| 262 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 263 | goto out; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * AP might cache a frame for a long time for a sleeping station, |
| 268 | * so rearm the timer if there's an AP interface with stations. If |
| 269 | * Tx is genuinely stuck we will most hopefully discover it when all |
| 270 | * stations are removed due to inactivity. |
| 271 | */ |
| 272 | if (wl->active_sta_count) { |
| 273 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has " |
| 274 | " %d stations", |
| 275 | wl->conf.tx.tx_watchdog_timeout, |
| 276 | wl->active_sta_count); |
| 277 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 278 | goto out; |
| 279 | } |
| 280 | |
| 281 | wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery", |
| 282 | wl->conf.tx.tx_watchdog_timeout); |
| 283 | wl12xx_queue_recovery_work(wl); |
| 284 | |
| 285 | out: |
| 286 | mutex_unlock(&wl->mutex); |
| 287 | } |
| 288 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 289 | static void wlcore_adjust_conf(struct wl1271 *wl) |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 290 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 291 | /* Adjust settings according to optional module parameters */ |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 292 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 293 | if (fwlog_param) { |
| 294 | if (!strcmp(fwlog_param, "continuous")) { |
| 295 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 296 | } else if (!strcmp(fwlog_param, "ondemand")) { |
| 297 | wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; |
| 298 | } else if (!strcmp(fwlog_param, "dbgpins")) { |
| 299 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 300 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; |
| 301 | } else if (!strcmp(fwlog_param, "disable")) { |
| 302 | wl->conf.fwlog.mem_blocks = 0; |
| 303 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; |
| 304 | } else { |
| 305 | wl1271_error("Unknown fwlog parameter %s", fwlog_param); |
| 306 | } |
| 307 | } |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 308 | |
| 309 | if (bug_on_recovery != -1) |
| 310 | wl->conf.recovery.bug_on_recovery = (u8) bug_on_recovery; |
| 311 | |
| 312 | if (no_recovery != -1) |
| 313 | wl->conf.recovery.no_recovery = (u8) no_recovery; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 314 | } |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 315 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 316 | static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, |
| 317 | struct wl12xx_vif *wlvif, |
| 318 | u8 hlid, u8 tx_pkts) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 319 | { |
Arik Nemtsov | 37c68ea | 2013-03-12 17:19:36 +0200 | [diff] [blame] | 320 | bool fw_ps; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 321 | |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 322 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
| 323 | |
| 324 | /* |
| 325 | * 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] | 326 | * packets in FW or if the STA is awake. |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 327 | */ |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 328 | if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 329 | wl12xx_ps_link_end(wl, wlvif, hlid); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 330 | |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 331 | /* |
| 332 | * 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] | 333 | * Make an exception if this is the only connected link. In this |
| 334 | * case FW-memory congestion is less of a problem. |
Arik Nemtsov | 37c68ea | 2013-03-12 17:19:36 +0200 | [diff] [blame] | 335 | * Note that a single connected STA means 3 active links, since we must |
| 336 | * account for the global and broadcast AP links. The "fw_ps" check |
| 337 | * assures us the third link is a STA connected to the AP. Otherwise |
| 338 | * the FW would not set the PSM bit. |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 339 | */ |
Arik Nemtsov | 37c68ea | 2013-03-12 17:19:36 +0200 | [diff] [blame] | 340 | else if (wl->active_link_count > 3 && fw_ps && |
| 341 | tx_pkts >= WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 342 | wl12xx_ps_link_start(wl, wlvif, hlid, true); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 345 | static void wl12xx_irq_update_links_status(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 346 | struct wl12xx_vif *wlvif, |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 347 | struct wl_fw_status_2 *status) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 348 | { |
| 349 | u32 cur_fw_ps_map; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 350 | u8 hlid; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 351 | |
| 352 | cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); |
| 353 | if (wl->ap_fw_ps_map != cur_fw_ps_map) { |
| 354 | wl1271_debug(DEBUG_PSM, |
| 355 | "link ps prev 0x%x cur 0x%x changed 0x%x", |
| 356 | wl->ap_fw_ps_map, cur_fw_ps_map, |
| 357 | wl->ap_fw_ps_map ^ cur_fw_ps_map); |
| 358 | |
| 359 | wl->ap_fw_ps_map = cur_fw_ps_map; |
| 360 | } |
| 361 | |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 362 | 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] | 363 | wl12xx_irq_ps_regulate_link(wl, wlvif, hlid, |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 364 | wl->links[hlid].allocated_pkts); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 367 | static int wlcore_fw_status(struct wl1271 *wl, |
| 368 | struct wl_fw_status_1 *status_1, |
| 369 | struct wl_fw_status_2 *status_2) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 370 | { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 371 | struct wl12xx_vif *wlvif; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 372 | struct timespec ts; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 373 | u32 old_tx_blk_count = wl->tx_blocks_available; |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 374 | int avail, freed_blocks; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 375 | int i; |
Arik Nemtsov | 6bac40a | 2011-12-12 12:08:25 +0200 | [diff] [blame] | 376 | size_t status_len; |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 377 | int ret; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 378 | struct wl1271_link *lnk; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 379 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 380 | status_len = WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) + |
| 381 | sizeof(*status_2) + wl->fw_status_priv_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 382 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 383 | ret = wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status_1, |
| 384 | status_len, false); |
| 385 | if (ret < 0) |
| 386 | return ret; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 387 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 388 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " |
| 389 | "drv_rx_counter = %d, tx_results_counter = %d)", |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 390 | status_1->intr, |
| 391 | status_1->fw_rx_counter, |
| 392 | status_1->drv_rx_counter, |
| 393 | status_1->tx_results_counter); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 394 | |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 395 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 396 | /* prevent wrap-around in freed-packets counter */ |
Arik Nemtsov | 742246f | 2011-08-14 13:17:33 +0300 | [diff] [blame] | 397 | wl->tx_allocated_pkts[i] -= |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 398 | (status_2->counters.tx_released_pkts[i] - |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 399 | wl->tx_pkts_freed[i]) & 0xff; |
| 400 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 401 | wl->tx_pkts_freed[i] = status_2->counters.tx_released_pkts[i]; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 402 | } |
| 403 | |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 404 | |
| 405 | for_each_set_bit(i, wl->links_map, WL12XX_MAX_LINKS) { |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 406 | u8 diff; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 407 | lnk = &wl->links[i]; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 408 | |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 409 | /* prevent wrap-around in freed-packets counter */ |
| 410 | diff = (status_2->counters.tx_lnk_free_pkts[i] - |
| 411 | lnk->prev_freed_pkts) & 0xff; |
| 412 | |
| 413 | if (diff == 0) |
| 414 | continue; |
| 415 | |
| 416 | lnk->allocated_pkts -= diff; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 417 | lnk->prev_freed_pkts = status_2->counters.tx_lnk_free_pkts[i]; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 418 | |
| 419 | /* accumulate the prev_freed_pkts counter */ |
| 420 | lnk->total_freed_pkts += diff; |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 423 | /* prevent wrap-around in total blocks counter */ |
| 424 | if (likely(wl->tx_blocks_freed <= |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 425 | le32_to_cpu(status_2->total_released_blks))) |
| 426 | freed_blocks = le32_to_cpu(status_2->total_released_blks) - |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 427 | wl->tx_blocks_freed; |
| 428 | else |
| 429 | freed_blocks = 0x100000000LL - wl->tx_blocks_freed + |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 430 | le32_to_cpu(status_2->total_released_blks); |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 431 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 432 | wl->tx_blocks_freed = le32_to_cpu(status_2->total_released_blks); |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 433 | |
Arik Nemtsov | 7bb5d6c | 2011-08-14 13:17:00 +0300 | [diff] [blame] | 434 | wl->tx_allocated_blocks -= freed_blocks; |
| 435 | |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 436 | /* |
| 437 | * If the FW freed some blocks: |
| 438 | * If we still have allocated blocks - re-arm the timer, Tx is |
| 439 | * not stuck. Otherwise, cancel the timer (no Tx currently). |
| 440 | */ |
| 441 | if (freed_blocks) { |
| 442 | if (wl->tx_allocated_blocks) |
| 443 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 444 | else |
| 445 | cancel_delayed_work(&wl->tx_watchdog_work); |
| 446 | } |
| 447 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 448 | avail = le32_to_cpu(status_2->tx_total) - wl->tx_allocated_blocks; |
Ido Yariv | d2f4d47 | 2011-03-31 10:07:00 +0200 | [diff] [blame] | 449 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 450 | /* |
| 451 | * The FW might change the total number of TX memblocks before |
| 452 | * we get a notification about blocks being released. Thus, the |
| 453 | * available blocks calculation might yield a temporary result |
| 454 | * which is lower than the actual available blocks. Keeping in |
| 455 | * mind that only blocks that were allocated can be moved from |
| 456 | * TX to RX, tx_blocks_available should never decrease here. |
| 457 | */ |
| 458 | wl->tx_blocks_available = max((int)wl->tx_blocks_available, |
| 459 | avail); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 460 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 461 | /* if more blocks are available now, tx work can be scheduled */ |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 462 | if (wl->tx_blocks_available > old_tx_blk_count) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 463 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 464 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 465 | /* 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] | 466 | wl12xx_for_each_wlvif_ap(wl, wlvif) { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 467 | wl12xx_irq_update_links_status(wl, wlvif, status_2); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 468 | } |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 469 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 470 | /* update the host-chipset time offset */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 471 | getnstimeofday(&ts); |
| 472 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 473 | (s64)le32_to_cpu(status_2->fw_localtime); |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 474 | |
Arik Nemtsov | 0e81047 | 2012-11-27 08:45:00 +0200 | [diff] [blame] | 475 | wl->fw_fast_lnk_map = le32_to_cpu(status_2->link_fast_bitmap); |
| 476 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 477 | return 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 478 | } |
| 479 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 480 | static void wl1271_flush_deferred_work(struct wl1271 *wl) |
| 481 | { |
| 482 | struct sk_buff *skb; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 483 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 484 | /* Pass all received frames to the network stack */ |
| 485 | while ((skb = skb_dequeue(&wl->deferred_rx_queue))) |
| 486 | ieee80211_rx_ni(wl->hw, skb); |
| 487 | |
| 488 | /* Return sent skbs to the network stack */ |
| 489 | while ((skb = skb_dequeue(&wl->deferred_tx_queue))) |
Eliad Peller | c27d3ac | 2011-06-07 10:40:39 +0300 | [diff] [blame] | 490 | ieee80211_tx_status_ni(wl->hw, skb); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void wl1271_netstack_work(struct work_struct *work) |
| 494 | { |
| 495 | struct wl1271 *wl = |
| 496 | container_of(work, struct wl1271, netstack_work); |
| 497 | |
| 498 | do { |
| 499 | wl1271_flush_deferred_work(wl); |
| 500 | } while (skb_queue_len(&wl->deferred_rx_queue)); |
| 501 | } |
| 502 | |
| 503 | #define WL1271_IRQ_MAX_LOOPS 256 |
| 504 | |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 505 | static int wlcore_irq_locked(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 506 | { |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 507 | int ret = 0; |
Juuso Oikarinen | c15f63b | 2009-10-12 15:08:50 +0300 | [diff] [blame] | 508 | u32 intr; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 509 | int loopcount = WL1271_IRQ_MAX_LOOPS; |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 510 | bool done = false; |
| 511 | unsigned int defer_count; |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 512 | unsigned long flags; |
| 513 | |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 514 | /* |
| 515 | * In case edge triggered interrupt must be used, we cannot iterate |
| 516 | * more than once without introducing race conditions with the hardirq. |
| 517 | */ |
| 518 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 519 | loopcount = 1; |
| 520 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 521 | wl1271_debug(DEBUG_IRQ, "IRQ work"); |
| 522 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 523 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 524 | goto out; |
| 525 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 526 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 527 | if (ret < 0) |
| 528 | goto out; |
| 529 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 530 | while (!done && loopcount--) { |
| 531 | /* |
| 532 | * In order to avoid a race with the hardirq, clear the flag |
| 533 | * before acknowledging the chip. Since the mutex is held, |
| 534 | * wl1271_ps_elp_wakeup cannot be called concurrently. |
| 535 | */ |
| 536 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 537 | smp_mb__after_clear_bit(); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 538 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 539 | 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] | 540 | if (ret < 0) |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 541 | goto out; |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 542 | |
| 543 | wlcore_hw_tx_immediate_compl(wl); |
| 544 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 545 | intr = le32_to_cpu(wl->fw_status_1->intr); |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 546 | intr &= WLCORE_ALL_INTR_MASK; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 547 | if (!intr) { |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 548 | done = true; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 549 | continue; |
| 550 | } |
| 551 | |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 552 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 553 | wl1271_error("HW watchdog interrupt received! starting recovery."); |
| 554 | wl->watchdog_recovery = true; |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 555 | ret = -EIO; |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 556 | |
| 557 | /* restarting the chip. ignore any other interrupt. */ |
| 558 | goto out; |
| 559 | } |
| 560 | |
| 561 | if (unlikely(intr & WL1271_ACX_SW_INTR_WATCHDOG)) { |
| 562 | wl1271_error("SW watchdog interrupt received! " |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 563 | "starting recovery."); |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 564 | wl->watchdog_recovery = true; |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 565 | ret = -EIO; |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 566 | |
| 567 | /* restarting the chip. ignore any other interrupt. */ |
| 568 | goto out; |
| 569 | } |
| 570 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 571 | if (likely(intr & WL1271_ACX_INTR_DATA)) { |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 572 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); |
| 573 | |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 574 | ret = wlcore_rx(wl, wl->fw_status_1); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 575 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 576 | goto out; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 577 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 578 | /* Check if any tx blocks were freed */ |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 579 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 580 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 581 | wl1271_tx_total_queue_count(wl) > 0) { |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 582 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 583 | /* |
| 584 | * In order to avoid starvation of the TX path, |
| 585 | * call the work function directly. |
| 586 | */ |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 587 | ret = wlcore_tx_work_locked(wl); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 588 | if (ret < 0) |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 589 | goto out; |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 590 | } else { |
| 591 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 592 | } |
| 593 | |
Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 594 | /* check for tx results */ |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 595 | ret = wlcore_hw_tx_delayed_compl(wl); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 596 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 597 | goto out; |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 598 | |
| 599 | /* Make sure the deferred queues don't get too long */ |
| 600 | defer_count = skb_queue_len(&wl->deferred_tx_queue) + |
| 601 | skb_queue_len(&wl->deferred_rx_queue); |
| 602 | if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) |
| 603 | wl1271_flush_deferred_work(wl); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | if (intr & WL1271_ACX_INTR_EVENT_A) { |
| 607 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 608 | ret = wl1271_event_handle(wl, 0); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 609 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 610 | goto out; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | if (intr & WL1271_ACX_INTR_EVENT_B) { |
| 614 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 615 | ret = wl1271_event_handle(wl, 1); |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 616 | if (ret < 0) |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 617 | goto out; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
| 621 | wl1271_debug(DEBUG_IRQ, |
| 622 | "WL1271_ACX_INTR_INIT_COMPLETE"); |
| 623 | |
| 624 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
| 625 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 626 | } |
| 627 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 628 | wl1271_ps_elp_sleep(wl); |
| 629 | |
| 630 | out: |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | static irqreturn_t wlcore_irq(int irq, void *cookie) |
| 635 | { |
| 636 | int ret; |
| 637 | unsigned long flags; |
| 638 | struct wl1271 *wl = cookie; |
| 639 | |
Luciano Coelho | 97236a0 | 2013-03-08 09:41:53 +0200 | [diff] [blame] | 640 | /* complete the ELP completion */ |
| 641 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 642 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 643 | if (wl->elp_compl) { |
| 644 | complete(wl->elp_compl); |
| 645 | wl->elp_compl = NULL; |
| 646 | } |
| 647 | |
| 648 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { |
| 649 | /* don't enqueue a work right now. mark it as pending */ |
| 650 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); |
| 651 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); |
| 652 | disable_irq_nosync(wl->irq); |
| 653 | pm_wakeup_event(wl->dev, 0); |
| 654 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 655 | return IRQ_HANDLED; |
| 656 | } |
| 657 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 658 | |
Arik Nemtsov | b5b45b3 | 2012-06-21 18:10:51 +0300 | [diff] [blame] | 659 | /* TX might be handled here, avoid redundant work */ |
| 660 | set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 661 | cancel_work_sync(&wl->tx_work); |
| 662 | |
| 663 | mutex_lock(&wl->mutex); |
| 664 | |
| 665 | ret = wlcore_irq_locked(wl); |
| 666 | if (ret) |
| 667 | wl12xx_queue_recovery_work(wl); |
| 668 | |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 669 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 670 | /* In case TX was not handled here, queue TX work */ |
| 671 | clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 672 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 673 | wl1271_tx_total_queue_count(wl) > 0) |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 674 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
| 675 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 676 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 677 | mutex_unlock(&wl->mutex); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 678 | |
| 679 | return IRQ_HANDLED; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 680 | } |
| 681 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 682 | struct vif_counter_data { |
| 683 | u8 counter; |
| 684 | |
| 685 | struct ieee80211_vif *cur_vif; |
| 686 | bool cur_vif_running; |
| 687 | }; |
| 688 | |
| 689 | static void wl12xx_vif_count_iter(void *data, u8 *mac, |
| 690 | struct ieee80211_vif *vif) |
| 691 | { |
| 692 | struct vif_counter_data *counter = data; |
| 693 | |
| 694 | counter->counter++; |
| 695 | if (counter->cur_vif == vif) |
| 696 | counter->cur_vif_running = true; |
| 697 | } |
| 698 | |
| 699 | /* caller must not hold wl->mutex, as it might deadlock */ |
| 700 | static void wl12xx_get_vif_count(struct ieee80211_hw *hw, |
| 701 | struct ieee80211_vif *cur_vif, |
| 702 | struct vif_counter_data *data) |
| 703 | { |
| 704 | memset(data, 0, sizeof(*data)); |
| 705 | data->cur_vif = cur_vif; |
| 706 | |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 707 | ieee80211_iterate_active_interfaces(hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 708 | wl12xx_vif_count_iter, data); |
| 709 | } |
| 710 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 711 | static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 712 | { |
| 713 | const struct firmware *fw; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 714 | const char *fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 715 | enum wl12xx_fw_type fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 716 | int ret; |
| 717 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 718 | if (plt) { |
| 719 | fw_type = WL12XX_FW_TYPE_PLT; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 720 | fw_name = wl->plt_fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 721 | } else { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 722 | /* |
| 723 | * we can't call wl12xx_get_vif_count() here because |
| 724 | * wl->mutex is taken, so use the cached last_vif_count value |
| 725 | */ |
Eliad Peller | 9b1a0a7 | 2012-07-25 14:22:21 +0300 | [diff] [blame] | 726 | if (wl->last_vif_count > 1 && wl->mr_fw_name) { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 727 | fw_type = WL12XX_FW_TYPE_MULTI; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 728 | fw_name = wl->mr_fw_name; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 729 | } else { |
| 730 | fw_type = WL12XX_FW_TYPE_NORMAL; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 731 | fw_name = wl->sr_fw_name; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 732 | } |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | if (wl->fw_type == fw_type) |
| 736 | return 0; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 737 | |
| 738 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); |
| 739 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 740 | ret = request_firmware(&fw, fw_name, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 741 | |
| 742 | if (ret < 0) { |
Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 743 | wl1271_error("could not get firmware %s: %d", fw_name, ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 744 | return ret; |
| 745 | } |
| 746 | |
| 747 | if (fw->size % 4) { |
| 748 | wl1271_error("firmware size is not multiple of 32 bits: %zu", |
| 749 | fw->size); |
| 750 | ret = -EILSEQ; |
| 751 | goto out; |
| 752 | } |
| 753 | |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 754 | vfree(wl->fw); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 755 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 756 | wl->fw_len = fw->size; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 757 | wl->fw = vmalloc(wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 758 | |
| 759 | if (!wl->fw) { |
| 760 | wl1271_error("could not allocate memory for the firmware"); |
| 761 | ret = -ENOMEM; |
| 762 | goto out; |
| 763 | } |
| 764 | |
| 765 | memcpy(wl->fw, fw->data, wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 766 | ret = 0; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 767 | wl->fw_type = fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 768 | out: |
| 769 | release_firmware(fw); |
| 770 | |
| 771 | return ret; |
| 772 | } |
| 773 | |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 774 | void wl12xx_queue_recovery_work(struct wl1271 *wl) |
| 775 | { |
Eyal Shapira | 680c605 | 2012-06-26 10:41:17 +0300 | [diff] [blame] | 776 | WARN_ON(!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); |
| 777 | |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 778 | /* Avoid a recursive recovery */ |
Ido Yariv | 792a58a | 2012-08-15 15:09:30 +0300 | [diff] [blame] | 779 | if (wl->state == WLCORE_STATE_ON) { |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 780 | wl->state = WLCORE_STATE_RESTARTING; |
Ido Yariv | 792a58a | 2012-08-15 15:09:30 +0300 | [diff] [blame] | 781 | set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 782 | wlcore_disable_interrupts_nosync(wl); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 783 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 784 | } |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 785 | } |
| 786 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 787 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) |
| 788 | { |
| 789 | size_t len = 0; |
| 790 | |
| 791 | /* The FW log is a length-value list, find where the log end */ |
| 792 | while (len < maxlen) { |
| 793 | if (memblock[len] == 0) |
| 794 | break; |
| 795 | if (len + memblock[len] + 1 > maxlen) |
| 796 | break; |
| 797 | len += memblock[len] + 1; |
| 798 | } |
| 799 | |
| 800 | /* Make sure we have enough room */ |
| 801 | len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); |
| 802 | |
| 803 | /* Fill the FW log file, consumed by the sysfs fwlog entry */ |
| 804 | memcpy(wl->fwlog + wl->fwlog_size, memblock, len); |
| 805 | wl->fwlog_size += len; |
| 806 | |
| 807 | return len; |
| 808 | } |
| 809 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 810 | #define WLCORE_FW_LOG_END 0x2000000 |
| 811 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 812 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) |
| 813 | { |
| 814 | u32 addr; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 815 | u32 offset; |
| 816 | u32 end_of_log; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 817 | u8 *block; |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 818 | int ret; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 819 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 820 | if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) || |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 821 | (wl->conf.fwlog.mem_blocks == 0)) |
| 822 | return; |
| 823 | |
| 824 | wl1271_info("Reading FW panic log"); |
| 825 | |
| 826 | block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); |
| 827 | if (!block) |
| 828 | return; |
| 829 | |
| 830 | /* |
| 831 | * Make sure the chip is awake and the logger isn't active. |
Eliad Peller | 847cbeb | 2012-11-26 18:05:42 +0200 | [diff] [blame] | 832 | * Do not send a stop fwlog command if the fw is hanged or if |
| 833 | * dbgpins are used (due to some fw bug). |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 834 | */ |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 835 | if (wl1271_ps_elp_wakeup(wl)) |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 836 | goto out; |
Eliad Peller | 847cbeb | 2012-11-26 18:05:42 +0200 | [diff] [blame] | 837 | if (!wl->watchdog_recovery && |
| 838 | wl->conf.fwlog.output != WL12XX_FWLOG_OUTPUT_DBG_PINS) |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 839 | wl12xx_cmd_stop_fwlog(wl); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 840 | |
| 841 | /* Read the first memory block address */ |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame] | 842 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
| 843 | if (ret < 0) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 844 | goto out; |
| 845 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 846 | addr = le32_to_cpu(wl->fw_status_2->log_start_addr); |
| 847 | if (!addr) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 848 | goto out; |
| 849 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 850 | if (wl->conf.fwlog.mode == WL12XX_FWLOG_CONTINUOUS) { |
| 851 | offset = sizeof(addr) + sizeof(struct wl1271_rx_descriptor); |
| 852 | end_of_log = WLCORE_FW_LOG_END; |
| 853 | } else { |
| 854 | offset = sizeof(addr); |
| 855 | end_of_log = addr; |
| 856 | } |
| 857 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 858 | /* Traverse the memory blocks linked list */ |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 859 | do { |
| 860 | memset(block, 0, WL12XX_HW_BLOCK_SIZE); |
Ido Yariv | 2b80040 | 2012-06-18 18:15:50 +0300 | [diff] [blame] | 861 | ret = wlcore_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, |
| 862 | false); |
| 863 | if (ret < 0) |
| 864 | goto out; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 865 | |
| 866 | /* |
| 867 | * Memory blocks are linked to one another. The first 4 bytes |
| 868 | * of each memory block hold the hardware address of the next |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 869 | * one. The last memory block points to the first one in |
| 870 | * on demand mode and is equal to 0x2000000 in continuous mode. |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 871 | */ |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 872 | addr = le32_to_cpup((__le32 *)block); |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 873 | if (!wl12xx_copy_fwlog(wl, block + offset, |
| 874 | WL12XX_HW_BLOCK_SIZE - offset)) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 875 | break; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 876 | } while (addr && (addr != end_of_log)); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 877 | |
| 878 | wake_up_interruptible(&wl->fwlog_waitq); |
| 879 | |
| 880 | out: |
| 881 | kfree(block); |
| 882 | } |
| 883 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 884 | static void wlcore_print_recovery(struct wl1271 *wl) |
| 885 | { |
| 886 | u32 pc = 0; |
| 887 | u32 hint_sts = 0; |
| 888 | int ret; |
| 889 | |
| 890 | wl1271_info("Hardware recovery in progress. FW ver: %s", |
| 891 | wl->chip.fw_ver_str); |
| 892 | |
| 893 | /* change partitions momentarily so we can read the FW pc */ |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 894 | ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
| 895 | if (ret < 0) |
| 896 | return; |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 897 | |
| 898 | ret = wlcore_read_reg(wl, REG_PC_ON_RECOVERY, &pc); |
| 899 | if (ret < 0) |
| 900 | return; |
| 901 | |
| 902 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &hint_sts); |
| 903 | if (ret < 0) |
| 904 | return; |
| 905 | |
Luciano Coelho | c108c90 | 2012-11-26 18:05:49 +0200 | [diff] [blame] | 906 | wl1271_info("pc: 0x%x, hint_sts: 0x%08x count: %d", |
| 907 | pc, hint_sts, ++wl->recovery_count); |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 908 | |
| 909 | wlcore_set_partition(wl, &wl->ptable[PART_WORK]); |
| 910 | } |
| 911 | |
| 912 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 913 | static void wl1271_recovery_work(struct work_struct *work) |
| 914 | { |
| 915 | struct wl1271 *wl = |
| 916 | container_of(work, struct wl1271, recovery_work); |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 917 | struct wl12xx_vif *wlvif; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 918 | struct ieee80211_vif *vif; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 919 | |
| 920 | mutex_lock(&wl->mutex); |
| 921 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 922 | if (wl->state == WLCORE_STATE_OFF || wl->plt) |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 923 | goto out_unlock; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 924 | |
Arik Nemtsov | aafec11 | 2012-06-25 22:26:19 +0300 | [diff] [blame] | 925 | if (!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)) { |
| 926 | wl12xx_read_fwlog_panic(wl); |
| 927 | wlcore_print_recovery(wl); |
| 928 | } |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 929 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 930 | BUG_ON(wl->conf.recovery.bug_on_recovery && |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 931 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 932 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 933 | if (wl->conf.recovery.no_recovery) { |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 934 | wl1271_info("No recovery (chosen on module load). Fw will remain stuck."); |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 935 | goto out_unlock; |
| 936 | } |
| 937 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 938 | /* Prevent spurious TX during FW restart */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 939 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 940 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 941 | /* reboot the chipset */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 942 | while (!list_empty(&wl->wlvif_list)) { |
| 943 | wlvif = list_first_entry(&wl->wlvif_list, |
| 944 | struct wl12xx_vif, list); |
| 945 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 946 | __wl1271_op_remove_interface(wl, vif, false); |
| 947 | } |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 948 | |
| 949 | wlcore_op_stop_locked(wl); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 950 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 951 | ieee80211_restart_hw(wl->hw); |
| 952 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 953 | /* |
| 954 | * Its safe to enable TX now - the queues are stopped after a request |
| 955 | * to restart the HW. |
| 956 | */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 957 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 958 | |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 959 | out_unlock: |
Arik Nemtsov | b034fd6 | 2012-06-25 22:26:20 +0300 | [diff] [blame] | 960 | wl->watchdog_recovery = false; |
| 961 | clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 962 | mutex_unlock(&wl->mutex); |
| 963 | } |
| 964 | |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 965 | static int wlcore_fw_wakeup(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 966 | { |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 967 | 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] | 968 | } |
| 969 | |
| 970 | static int wl1271_setup(struct wl1271 *wl) |
| 971 | { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 972 | 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] | 973 | sizeof(*wl->fw_status_2) + |
| 974 | wl->fw_status_priv_len, GFP_KERNEL); |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 975 | if (!wl->fw_status_1) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 976 | return -ENOMEM; |
| 977 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 978 | wl->fw_status_2 = (struct wl_fw_status_2 *) |
| 979 | (((u8 *) wl->fw_status_1) + |
| 980 | WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc)); |
| 981 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 982 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); |
| 983 | if (!wl->tx_res_if) { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 984 | kfree(wl->fw_status_1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 985 | return -ENOMEM; |
| 986 | } |
| 987 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 988 | return 0; |
| 989 | } |
| 990 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 991 | static int wl12xx_set_power_on(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 992 | { |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 993 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 994 | |
Juuso Oikarinen | 01ac17e | 2009-12-11 15:41:02 +0200 | [diff] [blame] | 995 | msleep(WL1271_PRE_POWER_ON_SLEEP); |
Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 996 | ret = wl1271_power_on(wl); |
| 997 | if (ret < 0) |
| 998 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 999 | msleep(WL1271_POWER_ON_SLEEP); |
Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 1000 | wl1271_io_reset(wl); |
| 1001 | wl1271_io_init(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1002 | |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 1003 | ret = wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
| 1004 | if (ret < 0) |
| 1005 | goto fail; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1006 | |
| 1007 | /* ELP module wake up */ |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 1008 | ret = wlcore_fw_wakeup(wl); |
| 1009 | if (ret < 0) |
| 1010 | goto fail; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1011 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1012 | out: |
| 1013 | return ret; |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 1014 | |
| 1015 | fail: |
| 1016 | wl1271_power_off(wl); |
| 1017 | return ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1018 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1019 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1020 | static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt) |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 1021 | { |
| 1022 | int ret = 0; |
| 1023 | |
| 1024 | ret = wl12xx_set_power_on(wl); |
| 1025 | if (ret < 0) |
| 1026 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1027 | |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 1028 | /* |
| 1029 | * For wl127x based devices we could use the default block |
| 1030 | * size (512 bytes), but due to a bug in the sdio driver, we |
| 1031 | * need to set it explicitly after the chip is powered on. To |
| 1032 | * simplify the code and since the performance impact is |
| 1033 | * negligible, we use the same block size for all different |
| 1034 | * chip types. |
Luciano Coelho | b5d6d9b | 2012-06-05 00:02:25 +0300 | [diff] [blame] | 1035 | * |
| 1036 | * Check if the bus supports blocksize alignment and, if it |
| 1037 | * doesn't, make sure we don't have the quirk. |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 1038 | */ |
Luciano Coelho | b5d6d9b | 2012-06-05 00:02:25 +0300 | [diff] [blame] | 1039 | if (!wl1271_set_block_size(wl)) |
| 1040 | wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1041 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 1042 | /* TODO: make sure the lower driver has set things up correctly */ |
| 1043 | |
| 1044 | ret = wl1271_setup(wl); |
| 1045 | if (ret < 0) |
| 1046 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1047 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1048 | ret = wl12xx_fetch_firmware(wl, plt); |
| 1049 | if (ret < 0) |
| 1050 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1051 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1052 | out: |
| 1053 | return ret; |
| 1054 | } |
| 1055 | |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1056 | 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] | 1057 | { |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1058 | int retries = WL1271_BOOT_RETRIES; |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1059 | struct wiphy *wiphy = wl->hw->wiphy; |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1060 | |
| 1061 | static const char* const PLT_MODE[] = { |
| 1062 | "PLT_OFF", |
| 1063 | "PLT_ON", |
| 1064 | "PLT_FEM_DETECT" |
| 1065 | }; |
| 1066 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1067 | int ret; |
| 1068 | |
| 1069 | mutex_lock(&wl->mutex); |
| 1070 | |
| 1071 | wl1271_notice("power up"); |
| 1072 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1073 | if (wl->state != WLCORE_STATE_OFF) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1074 | wl1271_error("cannot go into PLT state because not " |
| 1075 | "in off state: %d", wl->state); |
| 1076 | ret = -EBUSY; |
| 1077 | goto out; |
| 1078 | } |
| 1079 | |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1080 | /* Indicate to lower levels that we are now in PLT mode */ |
| 1081 | wl->plt = true; |
| 1082 | wl->plt_mode = plt_mode; |
| 1083 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1084 | while (retries) { |
| 1085 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1086 | ret = wl12xx_chip_wakeup(wl, true); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1087 | if (ret < 0) |
| 1088 | goto power_off; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1089 | |
Luciano Coelho | c331b34 | 2012-05-10 12:13:49 +0300 | [diff] [blame] | 1090 | ret = wl->ops->plt_init(wl); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1091 | if (ret < 0) |
| 1092 | goto power_off; |
| 1093 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1094 | wl->state = WLCORE_STATE_ON; |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1095 | wl1271_notice("firmware booted in PLT mode %s (%s)", |
| 1096 | PLT_MODE[plt_mode], |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 1097 | wl->chip.fw_ver_str); |
Luciano Coelho | e7ddf54 | 2011-03-10 15:24:57 +0200 | [diff] [blame] | 1098 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1099 | /* update hw/fw version info in wiphy struct */ |
| 1100 | wiphy->hw_version = wl->chip.id; |
| 1101 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 1102 | sizeof(wiphy->fw_version)); |
| 1103 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1104 | goto out; |
| 1105 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1106 | power_off: |
| 1107 | wl1271_power_off(wl); |
| 1108 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1109 | |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1110 | wl->plt = false; |
| 1111 | wl->plt_mode = PLT_OFF; |
| 1112 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1113 | wl1271_error("firmware boot in PLT mode failed despite %d retries", |
| 1114 | WL1271_BOOT_RETRIES); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1115 | out: |
| 1116 | mutex_unlock(&wl->mutex); |
| 1117 | |
| 1118 | return ret; |
| 1119 | } |
| 1120 | |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1121 | int wl1271_plt_stop(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1122 | { |
| 1123 | int ret = 0; |
| 1124 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1125 | wl1271_notice("power down"); |
| 1126 | |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1127 | /* |
| 1128 | * Interrupts must be disabled before setting the state to OFF. |
| 1129 | * Otherwise, the interrupt handler might be called and exit without |
| 1130 | * reading the interrupt status. |
| 1131 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1132 | wlcore_disable_interrupts(wl); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1133 | mutex_lock(&wl->mutex); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1134 | if (!wl->plt) { |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1135 | mutex_unlock(&wl->mutex); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1136 | |
| 1137 | /* |
| 1138 | * This will not necessarily enable interrupts as interrupts |
| 1139 | * may have been disabled when op_stop was called. It will, |
| 1140 | * however, balance the above call to disable_interrupts(). |
| 1141 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1142 | wlcore_enable_interrupts(wl); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1143 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1144 | wl1271_error("cannot power down because not in PLT " |
| 1145 | "state: %d", wl->state); |
| 1146 | ret = -EBUSY; |
| 1147 | goto out; |
| 1148 | } |
| 1149 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1150 | mutex_unlock(&wl->mutex); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1151 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1152 | wl1271_flush_deferred_work(wl); |
| 1153 | cancel_work_sync(&wl->netstack_work); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1154 | cancel_work_sync(&wl->recovery_work); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1155 | cancel_delayed_work_sync(&wl->elp_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1156 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1157 | |
| 1158 | mutex_lock(&wl->mutex); |
| 1159 | wl1271_power_off(wl); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1160 | wl->flags = 0; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 1161 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1162 | wl->state = WLCORE_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1163 | wl->plt = false; |
Yair Shapira | 7019c80 | 2012-07-11 18:48:04 +0300 | [diff] [blame] | 1164 | wl->plt_mode = PLT_OFF; |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1165 | wl->rx_counter = 0; |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1166 | mutex_unlock(&wl->mutex); |
| 1167 | |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 1168 | out: |
| 1169 | return ret; |
| 1170 | } |
Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 1171 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1172 | static void wl1271_op_tx(struct ieee80211_hw *hw, |
| 1173 | struct ieee80211_tx_control *control, |
| 1174 | struct sk_buff *skb) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1175 | { |
| 1176 | struct wl1271 *wl = hw->priv; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1177 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1178 | struct ieee80211_vif *vif = info->control.vif; |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1179 | struct wl12xx_vif *wlvif = NULL; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1180 | unsigned long flags; |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1181 | int q, mapping; |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1182 | u8 hlid; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1183 | |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1184 | if (!vif) { |
| 1185 | wl1271_debug(DEBUG_TX, "DROP skb with no vif"); |
| 1186 | ieee80211_free_txskb(hw, skb); |
| 1187 | return; |
| 1188 | } |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1189 | |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1190 | wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1191 | mapping = skb_get_queue_mapping(skb); |
| 1192 | q = wl1271_tx_get_queue(mapping); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1193 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1194 | hlid = wl12xx_tx_get_hlid(wl, wlvif, skb, control->sta); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1195 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1196 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1197 | |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1198 | /* |
| 1199 | * drop the packet if the link is invalid or the queue is stopped |
| 1200 | * for any reason but watermark. Watermark is a "soft"-stop so we |
| 1201 | * allow these packets through. |
| 1202 | */ |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1203 | if (hlid == WL12XX_INVALID_LINK_ID || |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1204 | (!test_bit(hlid, wlvif->links_map)) || |
Arik Nemtsov | d6037d2 | 2012-11-28 11:42:44 +0200 | [diff] [blame] | 1205 | (wlcore_is_queue_stopped_locked(wl, wlvif, q) && |
| 1206 | !wlcore_is_queue_stopped_by_reason_locked(wl, wlvif, q, |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1207 | WLCORE_QUEUE_STOP_REASON_WATERMARK))) { |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1208 | wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); |
Eliad Peller | 5de8eef | 2011-12-13 15:26:38 +0200 | [diff] [blame] | 1209 | ieee80211_free_txskb(hw, skb); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1210 | goto out; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 1211 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1212 | |
Eliad Peller | 8ccd16e | 2012-03-04 10:55:55 +0200 | [diff] [blame] | 1213 | wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d", |
| 1214 | hlid, q, skb->len); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1215 | skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); |
| 1216 | |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1217 | wl->tx_queue_count[q]++; |
Arik Nemtsov | f4d0200 | 2012-11-28 11:42:33 +0200 | [diff] [blame] | 1218 | wlvif->tx_queue_count[q]++; |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1219 | |
| 1220 | /* |
| 1221 | * The workqueue is slow to process the tx_queue and we need stop |
| 1222 | * the queue here, otherwise the queue will get too long. |
| 1223 | */ |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 1224 | if (wlvif->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK && |
Arik Nemtsov | d6037d2 | 2012-11-28 11:42:44 +0200 | [diff] [blame] | 1225 | !wlcore_is_queue_stopped_by_reason_locked(wl, wlvif, q, |
Arik Nemtsov | 8cdc44a | 2012-06-25 22:26:17 +0300 | [diff] [blame] | 1226 | WLCORE_QUEUE_STOP_REASON_WATERMARK)) { |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1227 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 1228 | wlcore_stop_queue_locked(wl, wlvif, q, |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1229 | WLCORE_QUEUE_STOP_REASON_WATERMARK); |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1230 | } |
| 1231 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1232 | /* |
| 1233 | * The chip specific setup must run before the first TX packet - |
| 1234 | * before that, the tx_work will not be initialized! |
| 1235 | */ |
| 1236 | |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1237 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
| 1238 | !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 1239 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1240 | |
Arik Nemtsov | 04216da | 2011-08-14 13:17:38 +0300 | [diff] [blame] | 1241 | out: |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1242 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1243 | } |
| 1244 | |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1245 | int wl1271_tx_dummy_packet(struct wl1271 *wl) |
| 1246 | { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1247 | unsigned long flags; |
Arik Nemtsov | 1462378 | 2011-08-28 15:11:57 +0300 | [diff] [blame] | 1248 | int q; |
| 1249 | |
| 1250 | /* no need to queue a new dummy packet if one is already pending */ |
| 1251 | if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) |
| 1252 | return 0; |
| 1253 | |
| 1254 | q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1255 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1256 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1257 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 1258 | wl->tx_queue_count[q]++; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1259 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 1260 | |
| 1261 | /* The FW is low on RX memory blocks, so send the dummy packet asap */ |
| 1262 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 1263 | return wlcore_tx_work_locked(wl); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1264 | |
| 1265 | /* |
| 1266 | * If the FW TX is busy, TX work will be scheduled by the threaded |
| 1267 | * interrupt handler function |
| 1268 | */ |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | /* |
| 1273 | * The size of the dummy packet should be at least 1400 bytes. However, in |
| 1274 | * order to minimize the number of bus transactions, aligning it to 512 bytes |
| 1275 | * boundaries could be beneficial, performance wise |
| 1276 | */ |
| 1277 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) |
| 1278 | |
Luciano Coelho | cf27d86 | 2011-04-01 21:08:23 +0300 | [diff] [blame] | 1279 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1280 | { |
| 1281 | struct sk_buff *skb; |
| 1282 | struct ieee80211_hdr_3addr *hdr; |
| 1283 | unsigned int dummy_packet_size; |
| 1284 | |
| 1285 | dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - |
| 1286 | sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); |
| 1287 | |
| 1288 | skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1289 | if (!skb) { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1290 | wl1271_warning("Failed to allocate a dummy packet skb"); |
| 1291 | return NULL; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 1295 | |
| 1296 | hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); |
| 1297 | memset(hdr, 0, sizeof(*hdr)); |
| 1298 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1299 | IEEE80211_STYPE_NULLFUNC | |
| 1300 | IEEE80211_FCTL_TODS); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1301 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1302 | memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1303 | |
Luciano Coelho | 18b92ff | 2011-03-21 16:35:21 +0200 | [diff] [blame] | 1304 | /* Dummy packets require the TID to be management */ |
| 1305 | skb->priority = WL1271_TID_MGMT; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1306 | |
| 1307 | /* Initialize all fields that might be used */ |
Hauke Mehrtens | 86c438f | 2011-04-26 23:27:44 +0200 | [diff] [blame] | 1308 | skb_set_queue_mapping(skb, 0); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1309 | memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1310 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1311 | return skb; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1314 | |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1315 | #ifdef CONFIG_PM |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 1316 | static int |
| 1317 | wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p) |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1318 | { |
| 1319 | int num_fields = 0, in_field = 0, fields_size = 0; |
| 1320 | int i, pattern_len = 0; |
| 1321 | |
| 1322 | if (!p->mask) { |
| 1323 | wl1271_warning("No mask in WoWLAN pattern"); |
| 1324 | return -EINVAL; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
| 1328 | * The pattern is broken up into segments of bytes at different offsets |
| 1329 | * that need to be checked by the FW filter. Each segment is called |
| 1330 | * a field in the FW API. We verify that the total number of fields |
| 1331 | * required for this pattern won't exceed FW limits (8) |
| 1332 | * as well as the total fields buffer won't exceed the FW limit. |
| 1333 | * Note that if there's a pattern which crosses Ethernet/IP header |
| 1334 | * boundary a new field is required. |
| 1335 | */ |
| 1336 | for (i = 0; i < p->pattern_len; i++) { |
| 1337 | if (test_bit(i, (unsigned long *)p->mask)) { |
| 1338 | if (!in_field) { |
| 1339 | in_field = 1; |
| 1340 | pattern_len = 1; |
| 1341 | } else { |
| 1342 | if (i == WL1271_RX_FILTER_ETH_HEADER_SIZE) { |
| 1343 | num_fields++; |
| 1344 | fields_size += pattern_len + |
| 1345 | RX_FILTER_FIELD_OVERHEAD; |
| 1346 | pattern_len = 1; |
| 1347 | } else |
| 1348 | pattern_len++; |
| 1349 | } |
| 1350 | } else { |
| 1351 | if (in_field) { |
| 1352 | in_field = 0; |
| 1353 | fields_size += pattern_len + |
| 1354 | RX_FILTER_FIELD_OVERHEAD; |
| 1355 | num_fields++; |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | if (in_field) { |
| 1361 | fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD; |
| 1362 | num_fields++; |
| 1363 | } |
| 1364 | |
| 1365 | if (num_fields > WL1271_RX_FILTER_MAX_FIELDS) { |
| 1366 | wl1271_warning("RX Filter too complex. Too many segments"); |
| 1367 | return -EINVAL; |
| 1368 | } |
| 1369 | |
| 1370 | if (fields_size > WL1271_RX_FILTER_MAX_FIELDS_SIZE) { |
| 1371 | wl1271_warning("RX filter pattern is too big"); |
| 1372 | return -E2BIG; |
| 1373 | } |
| 1374 | |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
Eyal Shapira | a6eab0c | 2012-03-14 06:32:07 +0200 | [diff] [blame] | 1378 | struct wl12xx_rx_filter *wl1271_rx_filter_alloc(void) |
| 1379 | { |
| 1380 | return kzalloc(sizeof(struct wl12xx_rx_filter), GFP_KERNEL); |
| 1381 | } |
| 1382 | |
| 1383 | void wl1271_rx_filter_free(struct wl12xx_rx_filter *filter) |
| 1384 | { |
| 1385 | int i; |
| 1386 | |
| 1387 | if (filter == NULL) |
| 1388 | return; |
| 1389 | |
| 1390 | for (i = 0; i < filter->num_fields; i++) |
| 1391 | kfree(filter->fields[i].pattern); |
| 1392 | |
| 1393 | kfree(filter); |
| 1394 | } |
| 1395 | |
| 1396 | int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter *filter, |
| 1397 | u16 offset, u8 flags, |
| 1398 | u8 *pattern, u8 len) |
| 1399 | { |
| 1400 | struct wl12xx_rx_filter_field *field; |
| 1401 | |
| 1402 | if (filter->num_fields == WL1271_RX_FILTER_MAX_FIELDS) { |
| 1403 | wl1271_warning("Max fields per RX filter. can't alloc another"); |
| 1404 | return -EINVAL; |
| 1405 | } |
| 1406 | |
| 1407 | field = &filter->fields[filter->num_fields]; |
| 1408 | |
| 1409 | field->pattern = kzalloc(len, GFP_KERNEL); |
| 1410 | if (!field->pattern) { |
| 1411 | wl1271_warning("Failed to allocate RX filter pattern"); |
| 1412 | return -ENOMEM; |
| 1413 | } |
| 1414 | |
| 1415 | filter->num_fields++; |
| 1416 | |
| 1417 | field->offset = cpu_to_le16(offset); |
| 1418 | field->flags = flags; |
| 1419 | field->len = len; |
| 1420 | memcpy(field->pattern, pattern, len); |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter *filter) |
| 1426 | { |
| 1427 | int i, fields_size = 0; |
| 1428 | |
| 1429 | for (i = 0; i < filter->num_fields; i++) |
| 1430 | fields_size += filter->fields[i].len + |
| 1431 | sizeof(struct wl12xx_rx_filter_field) - |
| 1432 | sizeof(u8 *); |
| 1433 | |
| 1434 | return fields_size; |
| 1435 | } |
| 1436 | |
| 1437 | void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter, |
| 1438 | u8 *buf) |
| 1439 | { |
| 1440 | int i; |
| 1441 | struct wl12xx_rx_filter_field *field; |
| 1442 | |
| 1443 | for (i = 0; i < filter->num_fields; i++) { |
| 1444 | field = (struct wl12xx_rx_filter_field *)buf; |
| 1445 | |
| 1446 | field->offset = filter->fields[i].offset; |
| 1447 | field->flags = filter->fields[i].flags; |
| 1448 | field->len = filter->fields[i].len; |
| 1449 | |
| 1450 | memcpy(&field->pattern, filter->fields[i].pattern, field->len); |
| 1451 | buf += sizeof(struct wl12xx_rx_filter_field) - |
| 1452 | sizeof(u8 *) + field->len; |
| 1453 | } |
| 1454 | } |
| 1455 | |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1456 | /* |
| 1457 | * Allocates an RX filter returned through f |
| 1458 | * which needs to be freed using rx_filter_free() |
| 1459 | */ |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 1460 | static int wl1271_convert_wowlan_pattern_to_rx_filter( |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1461 | struct cfg80211_wowlan_trig_pkt_pattern *p, |
| 1462 | struct wl12xx_rx_filter **f) |
| 1463 | { |
| 1464 | int i, j, ret = 0; |
| 1465 | struct wl12xx_rx_filter *filter; |
| 1466 | u16 offset; |
| 1467 | u8 flags, len; |
| 1468 | |
| 1469 | filter = wl1271_rx_filter_alloc(); |
| 1470 | if (!filter) { |
| 1471 | wl1271_warning("Failed to alloc rx filter"); |
| 1472 | ret = -ENOMEM; |
| 1473 | goto err; |
| 1474 | } |
| 1475 | |
| 1476 | i = 0; |
| 1477 | while (i < p->pattern_len) { |
| 1478 | if (!test_bit(i, (unsigned long *)p->mask)) { |
| 1479 | i++; |
| 1480 | continue; |
| 1481 | } |
| 1482 | |
| 1483 | for (j = i; j < p->pattern_len; j++) { |
| 1484 | if (!test_bit(j, (unsigned long *)p->mask)) |
| 1485 | break; |
| 1486 | |
| 1487 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE && |
| 1488 | j >= WL1271_RX_FILTER_ETH_HEADER_SIZE) |
| 1489 | break; |
| 1490 | } |
| 1491 | |
| 1492 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE) { |
| 1493 | offset = i; |
| 1494 | flags = WL1271_RX_FILTER_FLAG_ETHERNET_HEADER; |
| 1495 | } else { |
| 1496 | offset = i - WL1271_RX_FILTER_ETH_HEADER_SIZE; |
| 1497 | flags = WL1271_RX_FILTER_FLAG_IP_HEADER; |
| 1498 | } |
| 1499 | |
| 1500 | len = j - i; |
| 1501 | |
| 1502 | ret = wl1271_rx_filter_alloc_field(filter, |
| 1503 | offset, |
| 1504 | flags, |
| 1505 | &p->pattern[i], len); |
| 1506 | if (ret) |
| 1507 | goto err; |
| 1508 | |
| 1509 | i = j; |
| 1510 | } |
| 1511 | |
| 1512 | filter->action = FILTER_SIGNAL; |
| 1513 | |
| 1514 | *f = filter; |
| 1515 | return 0; |
| 1516 | |
| 1517 | err: |
| 1518 | wl1271_rx_filter_free(filter); |
| 1519 | *f = NULL; |
| 1520 | |
| 1521 | return ret; |
| 1522 | } |
| 1523 | |
| 1524 | static int wl1271_configure_wowlan(struct wl1271 *wl, |
| 1525 | struct cfg80211_wowlan *wow) |
| 1526 | { |
| 1527 | int i, ret; |
| 1528 | |
| 1529 | if (!wow || wow->any || !wow->n_patterns) { |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1530 | ret = wl1271_acx_default_rx_filter_enable(wl, 0, |
| 1531 | FILTER_SIGNAL); |
| 1532 | if (ret) |
| 1533 | goto out; |
| 1534 | |
| 1535 | ret = wl1271_rx_filter_clear_all(wl); |
| 1536 | if (ret) |
| 1537 | goto out; |
| 1538 | |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1539 | return 0; |
| 1540 | } |
| 1541 | |
| 1542 | if (WARN_ON(wow->n_patterns > WL1271_MAX_RX_FILTERS)) |
| 1543 | return -EINVAL; |
| 1544 | |
| 1545 | /* Validate all incoming patterns before clearing current FW state */ |
| 1546 | for (i = 0; i < wow->n_patterns; i++) { |
| 1547 | ret = wl1271_validate_wowlan_pattern(&wow->patterns[i]); |
| 1548 | if (ret) { |
| 1549 | wl1271_warning("Bad wowlan pattern %d", i); |
| 1550 | return ret; |
| 1551 | } |
| 1552 | } |
| 1553 | |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1554 | ret = wl1271_acx_default_rx_filter_enable(wl, 0, FILTER_SIGNAL); |
| 1555 | if (ret) |
| 1556 | goto out; |
| 1557 | |
| 1558 | ret = wl1271_rx_filter_clear_all(wl); |
| 1559 | if (ret) |
| 1560 | goto out; |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1561 | |
| 1562 | /* Translate WoWLAN patterns into filters */ |
| 1563 | for (i = 0; i < wow->n_patterns; i++) { |
| 1564 | struct cfg80211_wowlan_trig_pkt_pattern *p; |
| 1565 | struct wl12xx_rx_filter *filter = NULL; |
| 1566 | |
| 1567 | p = &wow->patterns[i]; |
| 1568 | |
| 1569 | ret = wl1271_convert_wowlan_pattern_to_rx_filter(p, &filter); |
| 1570 | if (ret) { |
| 1571 | wl1271_warning("Failed to create an RX filter from " |
| 1572 | "wowlan pattern %d", i); |
| 1573 | goto out; |
| 1574 | } |
| 1575 | |
| 1576 | ret = wl1271_rx_filter_enable(wl, i, 1, filter); |
| 1577 | |
| 1578 | wl1271_rx_filter_free(filter); |
| 1579 | if (ret) |
| 1580 | goto out; |
| 1581 | } |
| 1582 | |
| 1583 | ret = wl1271_acx_default_rx_filter_enable(wl, 1, FILTER_DROP); |
| 1584 | |
| 1585 | out: |
| 1586 | return ret; |
| 1587 | } |
| 1588 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1589 | static int wl1271_configure_suspend_sta(struct wl1271 *wl, |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1590 | struct wl12xx_vif *wlvif, |
| 1591 | struct cfg80211_wowlan *wow) |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1592 | { |
| 1593 | int ret = 0; |
| 1594 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1595 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1596 | goto out; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1597 | |
| 1598 | ret = wl1271_ps_elp_wakeup(wl); |
| 1599 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1600 | goto out; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1601 | |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1602 | ret = wl1271_configure_wowlan(wl, wow); |
| 1603 | if (ret < 0) |
| 1604 | goto out_sleep; |
| 1605 | |
Eyal Shapira | 11bc97e | 2012-08-02 07:15:19 +0300 | [diff] [blame] | 1606 | if ((wl->conf.conn.suspend_wake_up_event == |
| 1607 | wl->conf.conn.wake_up_event) && |
| 1608 | (wl->conf.conn.suspend_listen_interval == |
| 1609 | wl->conf.conn.listen_interval)) |
| 1610 | goto out_sleep; |
| 1611 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1612 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1613 | wl->conf.conn.suspend_wake_up_event, |
| 1614 | wl->conf.conn.suspend_listen_interval); |
| 1615 | |
| 1616 | if (ret < 0) |
| 1617 | wl1271_error("suspend: set wake up conditions failed: %d", ret); |
| 1618 | |
Arik Nemtsov | c439a1c | 2012-06-21 18:10:50 +0300 | [diff] [blame] | 1619 | out_sleep: |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1620 | wl1271_ps_elp_sleep(wl); |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1621 | out: |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1622 | return ret; |
| 1623 | |
| 1624 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1625 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1626 | static int wl1271_configure_suspend_ap(struct wl1271 *wl, |
| 1627 | struct wl12xx_vif *wlvif) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1628 | { |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1629 | int ret = 0; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1630 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1631 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1632 | goto out; |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1633 | |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1634 | ret = wl1271_ps_elp_wakeup(wl); |
| 1635 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1636 | goto out; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1637 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1638 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1639 | |
| 1640 | wl1271_ps_elp_sleep(wl); |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1641 | out: |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1642 | return ret; |
| 1643 | |
| 1644 | } |
| 1645 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1646 | static int wl1271_configure_suspend(struct wl1271 *wl, |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1647 | struct wl12xx_vif *wlvif, |
| 1648 | struct cfg80211_wowlan *wow) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1649 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1650 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1651 | return wl1271_configure_suspend_sta(wl, wlvif, wow); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1652 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1653 | return wl1271_configure_suspend_ap(wl, wlvif); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1654 | return 0; |
| 1655 | } |
| 1656 | |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame^] | 1657 | static void wl1271_configure_resume(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1658 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1659 | int ret = 0; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1660 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1661 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1662 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1663 | if ((!is_ap) && (!is_sta)) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1664 | return; |
| 1665 | |
Eliad Peller | d49524d | 2012-08-01 18:44:22 +0300 | [diff] [blame] | 1666 | if (is_sta && !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 1667 | return; |
| 1668 | |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1669 | ret = wl1271_ps_elp_wakeup(wl); |
| 1670 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1671 | return; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1672 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1673 | if (is_sta) { |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1674 | wl1271_configure_wowlan(wl, NULL); |
| 1675 | |
Eyal Shapira | 11bc97e | 2012-08-02 07:15:19 +0300 | [diff] [blame] | 1676 | if ((wl->conf.conn.suspend_wake_up_event == |
| 1677 | wl->conf.conn.wake_up_event) && |
| 1678 | (wl->conf.conn.suspend_listen_interval == |
| 1679 | wl->conf.conn.listen_interval)) |
| 1680 | goto out_sleep; |
| 1681 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1682 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1683 | wl->conf.conn.wake_up_event, |
| 1684 | wl->conf.conn.listen_interval); |
| 1685 | |
| 1686 | if (ret < 0) |
| 1687 | wl1271_error("resume: wake up conditions failed: %d", |
| 1688 | ret); |
| 1689 | |
| 1690 | } else if (is_ap) { |
| 1691 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false); |
| 1692 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1693 | |
Eyal Shapira | 11bc97e | 2012-08-02 07:15:19 +0300 | [diff] [blame] | 1694 | out_sleep: |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1695 | wl1271_ps_elp_sleep(wl); |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1696 | } |
| 1697 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1698 | static int wl1271_op_suspend(struct ieee80211_hw *hw, |
| 1699 | struct cfg80211_wowlan *wow) |
| 1700 | { |
| 1701 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1702 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1703 | int ret; |
| 1704 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1705 | wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1706 | WARN_ON(!wow); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1707 | |
Arik Nemtsov | 96caded | 2012-06-21 18:10:47 +0300 | [diff] [blame] | 1708 | /* we want to perform the recovery before suspending */ |
| 1709 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 1710 | wl1271_warning("postponing suspend to perform recovery"); |
| 1711 | return -EBUSY; |
| 1712 | } |
| 1713 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 1714 | wl1271_tx_flush(wl); |
| 1715 | |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1716 | mutex_lock(&wl->mutex); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1717 | wl->wow_enabled = true; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1718 | wl12xx_for_each_wlvif(wl, wlvif) { |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1719 | ret = wl1271_configure_suspend(wl, wlvif, wow); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1720 | if (ret < 0) { |
Dan Carpenter | cd840f6 | 2012-04-16 13:57:02 +0300 | [diff] [blame] | 1721 | mutex_unlock(&wl->mutex); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1722 | wl1271_warning("couldn't prepare device to suspend"); |
| 1723 | return ret; |
| 1724 | } |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1725 | } |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1726 | mutex_unlock(&wl->mutex); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1727 | /* flush any remaining work */ |
| 1728 | wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1729 | |
| 1730 | /* |
| 1731 | * disable and re-enable interrupts in order to flush |
| 1732 | * the threaded_irq |
| 1733 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1734 | wlcore_disable_interrupts(wl); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1735 | |
| 1736 | /* |
| 1737 | * set suspended flag to avoid triggering a new threaded_irq |
| 1738 | * work. no need for spinlock as interrupts are disabled. |
| 1739 | */ |
| 1740 | set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1741 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1742 | wlcore_enable_interrupts(wl); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1743 | flush_work(&wl->tx_work); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1744 | flush_delayed_work(&wl->elp_work); |
| 1745 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1746 | return 0; |
| 1747 | } |
| 1748 | |
| 1749 | static int wl1271_op_resume(struct ieee80211_hw *hw) |
| 1750 | { |
| 1751 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1752 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1753 | unsigned long flags; |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1754 | bool run_irq_work = false, pending_recovery; |
Arik Nemtsov | 725b827 | 2012-06-21 18:10:52 +0300 | [diff] [blame] | 1755 | int ret; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1756 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1757 | wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", |
| 1758 | wl->wow_enabled); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1759 | WARN_ON(!wl->wow_enabled); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1760 | |
| 1761 | /* |
| 1762 | * re-enable irq_work enqueuing, and call irq_work directly if |
| 1763 | * there is a pending work. |
| 1764 | */ |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1765 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1766 | clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1767 | if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) |
| 1768 | run_irq_work = true; |
| 1769 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1770 | |
Arik Nemtsov | 725b827 | 2012-06-21 18:10:52 +0300 | [diff] [blame] | 1771 | mutex_lock(&wl->mutex); |
| 1772 | |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1773 | /* test the recovery flag before calling any SDIO functions */ |
| 1774 | pending_recovery = test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, |
| 1775 | &wl->flags); |
| 1776 | |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1777 | if (run_irq_work) { |
| 1778 | wl1271_debug(DEBUG_MAC80211, |
| 1779 | "run postponed irq_work directly"); |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1780 | |
| 1781 | /* don't talk to the HW if recovery is pending */ |
Arik Nemtsov | 725b827 | 2012-06-21 18:10:52 +0300 | [diff] [blame] | 1782 | if (!pending_recovery) { |
| 1783 | ret = wlcore_irq_locked(wl); |
| 1784 | if (ret) |
| 1785 | wl12xx_queue_recovery_work(wl); |
| 1786 | } |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1787 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1788 | wlcore_enable_interrupts(wl); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1789 | } |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1790 | |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1791 | if (pending_recovery) { |
| 1792 | wl1271_warning("queuing forgotten recovery on resume"); |
| 1793 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
| 1794 | goto out; |
| 1795 | } |
| 1796 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1797 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 1798 | wl1271_configure_resume(wl, wlvif); |
| 1799 | } |
Arik Nemtsov | ea0a3cf | 2012-06-21 18:10:49 +0300 | [diff] [blame] | 1800 | |
| 1801 | out: |
Eliad Peller | ff91afc | 2011-06-06 12:21:53 +0300 | [diff] [blame] | 1802 | wl->wow_enabled = false; |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1803 | mutex_unlock(&wl->mutex); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1804 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1805 | return 0; |
| 1806 | } |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1807 | #endif |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1808 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1809 | static int wl1271_op_start(struct ieee80211_hw *hw) |
| 1810 | { |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1811 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); |
| 1812 | |
| 1813 | /* |
| 1814 | * We have to delay the booting of the hardware because |
| 1815 | * we need to know the local MAC address before downloading and |
| 1816 | * initializing the firmware. The MAC address cannot be changed |
| 1817 | * after boot, and without the proper MAC address, the firmware |
| 1818 | * will not function properly. |
| 1819 | * |
| 1820 | * The MAC address is first known when the corresponding interface |
| 1821 | * is added. That is where we will initialize the hardware. |
| 1822 | */ |
| 1823 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 1824 | return 0; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1825 | } |
| 1826 | |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1827 | static void wlcore_op_stop_locked(struct wl1271 *wl) |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1828 | { |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1829 | int i; |
| 1830 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1831 | if (wl->state == WLCORE_STATE_OFF) { |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 1832 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, |
| 1833 | &wl->flags)) |
| 1834 | wlcore_enable_interrupts(wl); |
| 1835 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1836 | return; |
| 1837 | } |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1838 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1839 | /* |
| 1840 | * this must be before the cancel_work calls below, so that the work |
| 1841 | * functions don't perform further work. |
| 1842 | */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 1843 | wl->state = WLCORE_STATE_OFF; |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1844 | |
| 1845 | /* |
| 1846 | * Use the nosync variant to disable interrupts, so the mutex could be |
| 1847 | * held while doing so without deadlocking. |
| 1848 | */ |
| 1849 | wlcore_disable_interrupts_nosync(wl); |
| 1850 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1851 | mutex_unlock(&wl->mutex); |
| 1852 | |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 1853 | wlcore_synchronize_interrupts(wl); |
Eliad Peller | 6dbc5fc | 2012-07-29 14:37:29 +0300 | [diff] [blame] | 1854 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 1855 | cancel_work_sync(&wl->recovery_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1856 | wl1271_flush_deferred_work(wl); |
| 1857 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 1858 | cancel_work_sync(&wl->netstack_work); |
| 1859 | cancel_work_sync(&wl->tx_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1860 | cancel_delayed_work_sync(&wl->elp_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1861 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1862 | |
| 1863 | /* let's notify MAC80211 about the remaining pending TX frames */ |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1864 | mutex_lock(&wl->mutex); |
Arik Nemtsov | d935e38 | 2012-11-27 08:44:53 +0200 | [diff] [blame] | 1865 | wl12xx_tx_reset(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1866 | |
| 1867 | wl1271_power_off(wl); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 1868 | /* |
| 1869 | * In case a recovery was scheduled, interrupts were disabled to avoid |
| 1870 | * an interrupt storm. Now that the power is down, it is safe to |
| 1871 | * re-enable interrupts to balance the disable depth |
| 1872 | */ |
| 1873 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 1874 | wlcore_enable_interrupts(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1875 | |
| 1876 | wl->band = IEEE80211_BAND_2GHZ; |
| 1877 | |
| 1878 | wl->rx_counter = 0; |
| 1879 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 1880 | wl->channel_type = NL80211_CHAN_NO_HT; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1881 | wl->tx_blocks_available = 0; |
| 1882 | wl->tx_allocated_blocks = 0; |
| 1883 | wl->tx_results_count = 0; |
| 1884 | wl->tx_packets_count = 0; |
| 1885 | wl->time_offset = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1886 | wl->ap_fw_ps_map = 0; |
| 1887 | wl->ap_ps_map = 0; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 1888 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1889 | memset(wl->roles_map, 0, sizeof(wl->roles_map)); |
| 1890 | memset(wl->links_map, 0, sizeof(wl->links_map)); |
| 1891 | memset(wl->roc_map, 0, sizeof(wl->roc_map)); |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 1892 | memset(wl->session_ids, 0, sizeof(wl->session_ids)); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1893 | wl->active_sta_count = 0; |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 1894 | wl->active_link_count = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1895 | |
| 1896 | /* The system link is always allocated */ |
Arik Nemtsov | 9ebcb23 | 2012-11-27 08:44:59 +0200 | [diff] [blame] | 1897 | wl->links[WL12XX_SYSTEM_HLID].allocated_pkts = 0; |
| 1898 | wl->links[WL12XX_SYSTEM_HLID].prev_freed_pkts = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1899 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 1900 | |
| 1901 | /* |
| 1902 | * this is performed after the cancel_work calls and the associated |
| 1903 | * mutex_lock, so that wl1271_op_add_interface does not accidentally |
| 1904 | * get executed before all these vars have been reset. |
| 1905 | */ |
| 1906 | wl->flags = 0; |
| 1907 | |
| 1908 | wl->tx_blocks_freed = 0; |
| 1909 | |
| 1910 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 1911 | wl->tx_pkts_freed[i] = 0; |
| 1912 | wl->tx_allocated_pkts[i] = 0; |
| 1913 | } |
| 1914 | |
| 1915 | wl1271_debugfs_reset(wl); |
| 1916 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 1917 | kfree(wl->fw_status_1); |
| 1918 | wl->fw_status_1 = NULL; |
| 1919 | wl->fw_status_2 = NULL; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1920 | kfree(wl->tx_res_if); |
| 1921 | wl->tx_res_if = NULL; |
| 1922 | kfree(wl->target_mem_map); |
| 1923 | wl->target_mem_map = NULL; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1924 | |
| 1925 | /* |
| 1926 | * FW channels must be re-calibrated after recovery, |
| 1927 | * clear the last Reg-Domain channel configuration. |
| 1928 | */ |
| 1929 | 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] | 1930 | } |
| 1931 | |
| 1932 | static void wlcore_op_stop(struct ieee80211_hw *hw) |
| 1933 | { |
| 1934 | struct wl1271 *wl = hw->priv; |
| 1935 | |
| 1936 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); |
| 1937 | |
| 1938 | mutex_lock(&wl->mutex); |
| 1939 | |
| 1940 | wlcore_op_stop_locked(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1941 | |
| 1942 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 1945 | static void wlcore_channel_switch_work(struct work_struct *work) |
| 1946 | { |
| 1947 | struct delayed_work *dwork; |
| 1948 | struct wl1271 *wl; |
| 1949 | struct ieee80211_vif *vif; |
| 1950 | struct wl12xx_vif *wlvif; |
| 1951 | int ret; |
| 1952 | |
| 1953 | dwork = container_of(work, struct delayed_work, work); |
| 1954 | wlvif = container_of(dwork, struct wl12xx_vif, channel_switch_work); |
| 1955 | wl = wlvif->wl; |
| 1956 | |
| 1957 | wl1271_info("channel switch failed (role_id: %d).", wlvif->role_id); |
| 1958 | |
| 1959 | mutex_lock(&wl->mutex); |
| 1960 | |
| 1961 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 1962 | goto out; |
| 1963 | |
| 1964 | /* check the channel switch is still ongoing */ |
| 1965 | if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) |
| 1966 | goto out; |
| 1967 | |
| 1968 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 1969 | ieee80211_chswitch_done(vif, false); |
| 1970 | |
| 1971 | ret = wl1271_ps_elp_wakeup(wl); |
| 1972 | if (ret < 0) |
| 1973 | goto out; |
| 1974 | |
| 1975 | wl12xx_cmd_stop_channel_switch(wl, wlvif); |
| 1976 | |
| 1977 | wl1271_ps_elp_sleep(wl); |
| 1978 | out: |
| 1979 | mutex_unlock(&wl->mutex); |
| 1980 | } |
| 1981 | |
| 1982 | static void wlcore_connection_loss_work(struct work_struct *work) |
| 1983 | { |
| 1984 | struct delayed_work *dwork; |
| 1985 | struct wl1271 *wl; |
| 1986 | struct ieee80211_vif *vif; |
| 1987 | struct wl12xx_vif *wlvif; |
| 1988 | |
| 1989 | dwork = container_of(work, struct delayed_work, work); |
| 1990 | wlvif = container_of(dwork, struct wl12xx_vif, connection_loss_work); |
| 1991 | wl = wlvif->wl; |
| 1992 | |
| 1993 | wl1271_info("Connection loss work (role_id: %d).", wlvif->role_id); |
| 1994 | |
| 1995 | mutex_lock(&wl->mutex); |
| 1996 | |
| 1997 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 1998 | goto out; |
| 1999 | |
| 2000 | /* Call mac80211 connection loss */ |
| 2001 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 2002 | goto out; |
| 2003 | |
| 2004 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 2005 | ieee80211_connection_loss(vif); |
| 2006 | out: |
| 2007 | mutex_unlock(&wl->mutex); |
| 2008 | } |
| 2009 | |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2010 | static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) |
| 2011 | { |
| 2012 | u8 policy = find_first_zero_bit(wl->rate_policies_map, |
| 2013 | WL12XX_MAX_RATE_POLICIES); |
| 2014 | if (policy >= WL12XX_MAX_RATE_POLICIES) |
| 2015 | return -EBUSY; |
| 2016 | |
| 2017 | __set_bit(policy, wl->rate_policies_map); |
| 2018 | *idx = policy; |
| 2019 | return 0; |
| 2020 | } |
| 2021 | |
| 2022 | static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx) |
| 2023 | { |
| 2024 | if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES)) |
| 2025 | return; |
| 2026 | |
| 2027 | __clear_bit(*idx, wl->rate_policies_map); |
| 2028 | *idx = WL12XX_MAX_RATE_POLICIES; |
| 2029 | } |
| 2030 | |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2031 | static int wlcore_allocate_klv_template(struct wl1271 *wl, u8 *idx) |
| 2032 | { |
| 2033 | u8 policy = find_first_zero_bit(wl->klv_templates_map, |
| 2034 | WLCORE_MAX_KLV_TEMPLATES); |
| 2035 | if (policy >= WLCORE_MAX_KLV_TEMPLATES) |
| 2036 | return -EBUSY; |
| 2037 | |
| 2038 | __set_bit(policy, wl->klv_templates_map); |
| 2039 | *idx = policy; |
| 2040 | return 0; |
| 2041 | } |
| 2042 | |
| 2043 | static void wlcore_free_klv_template(struct wl1271 *wl, u8 *idx) |
| 2044 | { |
| 2045 | if (WARN_ON(*idx >= WLCORE_MAX_KLV_TEMPLATES)) |
| 2046 | return; |
| 2047 | |
| 2048 | __clear_bit(*idx, wl->klv_templates_map); |
| 2049 | *idx = WLCORE_MAX_KLV_TEMPLATES; |
| 2050 | } |
| 2051 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2052 | 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] | 2053 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2054 | switch (wlvif->bss_type) { |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2055 | case BSS_TYPE_AP_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 2056 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2057 | return WL1271_ROLE_P2P_GO; |
| 2058 | else |
| 2059 | return WL1271_ROLE_AP; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2060 | |
| 2061 | case BSS_TYPE_STA_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 2062 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2063 | return WL1271_ROLE_P2P_CL; |
| 2064 | else |
| 2065 | return WL1271_ROLE_STA; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2066 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2067 | case BSS_TYPE_IBSS: |
| 2068 | return WL1271_ROLE_IBSS; |
| 2069 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2070 | default: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2071 | wl1271_error("invalid bss_type: %d", wlvif->bss_type); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2072 | } |
| 2073 | return WL12XX_INVALID_ROLE_TYPE; |
| 2074 | } |
| 2075 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2076 | 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] | 2077 | { |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2078 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2079 | int i; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2080 | |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2081 | /* clear everything but the persistent data */ |
| 2082 | memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent)); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2083 | |
| 2084 | switch (ieee80211_vif_type_p2p(vif)) { |
| 2085 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2086 | wlvif->p2p = 1; |
| 2087 | /* fall-through */ |
| 2088 | case NL80211_IFTYPE_STATION: |
| 2089 | wlvif->bss_type = BSS_TYPE_STA_BSS; |
| 2090 | break; |
| 2091 | case NL80211_IFTYPE_ADHOC: |
| 2092 | wlvif->bss_type = BSS_TYPE_IBSS; |
| 2093 | break; |
| 2094 | case NL80211_IFTYPE_P2P_GO: |
| 2095 | wlvif->p2p = 1; |
| 2096 | /* fall-through */ |
| 2097 | case NL80211_IFTYPE_AP: |
| 2098 | wlvif->bss_type = BSS_TYPE_AP_BSS; |
| 2099 | break; |
| 2100 | default: |
| 2101 | wlvif->bss_type = MAX_BSS_TYPE; |
| 2102 | return -EOPNOTSUPP; |
| 2103 | } |
| 2104 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2105 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2106 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2107 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2108 | |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2109 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2110 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2111 | /* init sta/ibss data */ |
| 2112 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2113 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2114 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2115 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2116 | wlcore_allocate_klv_template(wl, &wlvif->sta.klv_template_id); |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 2117 | wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC; |
| 2118 | wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC; |
| 2119 | wlvif->rate_set = CONF_TX_RATE_MASK_BASIC; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2120 | } else { |
| 2121 | /* init ap data */ |
| 2122 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2123 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2124 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2125 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2126 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2127 | wl12xx_allocate_rate_policy(wl, |
| 2128 | &wlvif->ap.ucast_rate_idx[i]); |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 2129 | wlvif->basic_rate_set = CONF_TX_ENABLED_RATES; |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 2130 | /* |
| 2131 | * TODO: check if basic_rate shouldn't be |
| 2132 | * wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 2133 | * instead (the same thing for STA above). |
| 2134 | */ |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 2135 | wlvif->basic_rate = CONF_TX_ENABLED_RATES; |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 2136 | /* TODO: this seems to be used only for STA, check it */ |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 2137 | wlvif->rate_set = CONF_TX_ENABLED_RATES; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2138 | } |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2139 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2140 | wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; |
| 2141 | wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 2142 | wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; |
| 2143 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2144 | /* |
| 2145 | * mac80211 configures some values globally, while we treat them |
| 2146 | * per-interface. thus, on init, we have to copy them from wl |
| 2147 | */ |
| 2148 | wlvif->band = wl->band; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2149 | wlvif->channel = wl->channel; |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2150 | wlvif->power_level = wl->power_level; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 2151 | wlvif->channel_type = wl->channel_type; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2152 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2153 | INIT_WORK(&wlvif->rx_streaming_enable_work, |
| 2154 | wl1271_rx_streaming_enable_work); |
| 2155 | INIT_WORK(&wlvif->rx_streaming_disable_work, |
| 2156 | wl1271_rx_streaming_disable_work); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2157 | INIT_DELAYED_WORK(&wlvif->channel_switch_work, |
| 2158 | wlcore_channel_switch_work); |
| 2159 | INIT_DELAYED_WORK(&wlvif->connection_loss_work, |
| 2160 | wlcore_connection_loss_work); |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2161 | INIT_LIST_HEAD(&wlvif->list); |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2162 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2163 | setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, |
| 2164 | (unsigned long) wlvif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2165 | return 0; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2166 | } |
| 2167 | |
Luciano Coelho | 5dc283f | 2013-01-30 10:53:14 +0200 | [diff] [blame] | 2168 | static int wl12xx_init_fw(struct wl1271 *wl) |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2169 | { |
| 2170 | int retries = WL1271_BOOT_RETRIES; |
| 2171 | bool booted = false; |
| 2172 | struct wiphy *wiphy = wl->hw->wiphy; |
| 2173 | int ret; |
| 2174 | |
| 2175 | while (retries) { |
| 2176 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2177 | ret = wl12xx_chip_wakeup(wl, false); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2178 | if (ret < 0) |
| 2179 | goto power_off; |
| 2180 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 2181 | ret = wl->ops->boot(wl); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2182 | if (ret < 0) |
| 2183 | goto power_off; |
| 2184 | |
| 2185 | ret = wl1271_hw_init(wl); |
| 2186 | if (ret < 0) |
| 2187 | goto irq_disable; |
| 2188 | |
| 2189 | booted = true; |
| 2190 | break; |
| 2191 | |
| 2192 | irq_disable: |
| 2193 | mutex_unlock(&wl->mutex); |
| 2194 | /* Unlocking the mutex in the middle of handling is |
| 2195 | inherently unsafe. In this case we deem it safe to do, |
| 2196 | because we need to let any possibly pending IRQ out of |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2197 | the system (and while we are WLCORE_STATE_OFF the IRQ |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2198 | work function will not do anything.) Also, any other |
| 2199 | possible concurrent operations will fail due to the |
| 2200 | current state, hence the wl1271 struct should be safe. */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 2201 | wlcore_disable_interrupts(wl); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2202 | wl1271_flush_deferred_work(wl); |
| 2203 | cancel_work_sync(&wl->netstack_work); |
| 2204 | mutex_lock(&wl->mutex); |
| 2205 | power_off: |
| 2206 | wl1271_power_off(wl); |
| 2207 | } |
| 2208 | |
| 2209 | if (!booted) { |
| 2210 | wl1271_error("firmware boot failed despite %d retries", |
| 2211 | WL1271_BOOT_RETRIES); |
| 2212 | goto out; |
| 2213 | } |
| 2214 | |
| 2215 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); |
| 2216 | |
| 2217 | /* update hw/fw version info in wiphy struct */ |
| 2218 | wiphy->hw_version = wl->chip.id; |
| 2219 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 2220 | sizeof(wiphy->fw_version)); |
| 2221 | |
| 2222 | /* |
| 2223 | * Now we know if 11a is supported (info from the NVS), so disable |
| 2224 | * 11a channels if not supported |
| 2225 | */ |
| 2226 | if (!wl->enable_11a) |
| 2227 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; |
| 2228 | |
| 2229 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", |
| 2230 | wl->enable_11a ? "" : "not "); |
| 2231 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2232 | wl->state = WLCORE_STATE_ON; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2233 | out: |
Luciano Coelho | 5dc283f | 2013-01-30 10:53:14 +0200 | [diff] [blame] | 2234 | return ret; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2237 | static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif) |
| 2238 | { |
| 2239 | return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID; |
| 2240 | } |
| 2241 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2242 | /* |
| 2243 | * Check whether a fw switch (i.e. moving from one loaded |
| 2244 | * fw to another) is needed. This function is also responsible |
| 2245 | * for updating wl->last_vif_count, so it must be called before |
| 2246 | * loading a non-plt fw (so the correct fw (single-role/multi-role) |
| 2247 | * will be used). |
| 2248 | */ |
| 2249 | static bool wl12xx_need_fw_change(struct wl1271 *wl, |
| 2250 | struct vif_counter_data vif_counter_data, |
| 2251 | bool add) |
| 2252 | { |
| 2253 | enum wl12xx_fw_type current_fw = wl->fw_type; |
| 2254 | u8 vif_count = vif_counter_data.counter; |
| 2255 | |
| 2256 | if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags)) |
| 2257 | return false; |
| 2258 | |
| 2259 | /* increase the vif count if this is a new vif */ |
| 2260 | if (add && !vif_counter_data.cur_vif_running) |
| 2261 | vif_count++; |
| 2262 | |
| 2263 | wl->last_vif_count = vif_count; |
| 2264 | |
| 2265 | /* no need for fw change if the device is OFF */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2266 | if (wl->state == WLCORE_STATE_OFF) |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2267 | return false; |
| 2268 | |
Eliad Peller | 9b1a0a7 | 2012-07-25 14:22:21 +0300 | [diff] [blame] | 2269 | /* no need for fw change if a single fw is used */ |
| 2270 | if (!wl->mr_fw_name) |
| 2271 | return false; |
| 2272 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2273 | if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL) |
| 2274 | return true; |
| 2275 | if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI) |
| 2276 | return true; |
| 2277 | |
| 2278 | return false; |
| 2279 | } |
| 2280 | |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2281 | /* |
| 2282 | * Enter "forced psm". Make sure the sta is in psm against the ap, |
| 2283 | * to make the fw switch a bit more disconnection-persistent. |
| 2284 | */ |
| 2285 | static void wl12xx_force_active_psm(struct wl1271 *wl) |
| 2286 | { |
| 2287 | struct wl12xx_vif *wlvif; |
| 2288 | |
| 2289 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 2290 | wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE); |
| 2291 | } |
| 2292 | } |
| 2293 | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 2294 | struct wlcore_hw_queue_iter_data { |
| 2295 | unsigned long hw_queue_map[BITS_TO_LONGS(WLCORE_NUM_MAC_ADDRESSES)]; |
| 2296 | /* current vif */ |
| 2297 | struct ieee80211_vif *vif; |
| 2298 | /* is the current vif among those iterated */ |
| 2299 | bool cur_running; |
| 2300 | }; |
| 2301 | |
| 2302 | static void wlcore_hw_queue_iter(void *data, u8 *mac, |
| 2303 | struct ieee80211_vif *vif) |
| 2304 | { |
| 2305 | struct wlcore_hw_queue_iter_data *iter_data = data; |
| 2306 | |
| 2307 | if (WARN_ON_ONCE(vif->hw_queue[0] == IEEE80211_INVAL_HW_QUEUE)) |
| 2308 | return; |
| 2309 | |
| 2310 | if (iter_data->cur_running || vif == iter_data->vif) { |
| 2311 | iter_data->cur_running = true; |
| 2312 | return; |
| 2313 | } |
| 2314 | |
| 2315 | __set_bit(vif->hw_queue[0] / NUM_TX_QUEUES, iter_data->hw_queue_map); |
| 2316 | } |
| 2317 | |
| 2318 | static int wlcore_allocate_hw_queue_base(struct wl1271 *wl, |
| 2319 | struct wl12xx_vif *wlvif) |
| 2320 | { |
| 2321 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2322 | struct wlcore_hw_queue_iter_data iter_data = {}; |
| 2323 | int i, q_base; |
| 2324 | |
| 2325 | iter_data.vif = vif; |
| 2326 | |
| 2327 | /* mark all bits taken by active interfaces */ |
| 2328 | ieee80211_iterate_active_interfaces_atomic(wl->hw, |
| 2329 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 2330 | wlcore_hw_queue_iter, &iter_data); |
| 2331 | |
| 2332 | /* the current vif is already running in mac80211 (resume/recovery) */ |
| 2333 | if (iter_data.cur_running) { |
| 2334 | wlvif->hw_queue_base = vif->hw_queue[0]; |
| 2335 | wl1271_debug(DEBUG_MAC80211, |
| 2336 | "using pre-allocated hw queue base %d", |
| 2337 | wlvif->hw_queue_base); |
| 2338 | |
| 2339 | /* interface type might have changed type */ |
| 2340 | goto adjust_cab_queue; |
| 2341 | } |
| 2342 | |
| 2343 | q_base = find_first_zero_bit(iter_data.hw_queue_map, |
| 2344 | WLCORE_NUM_MAC_ADDRESSES); |
| 2345 | if (q_base >= WLCORE_NUM_MAC_ADDRESSES) |
| 2346 | return -EBUSY; |
| 2347 | |
| 2348 | wlvif->hw_queue_base = q_base * NUM_TX_QUEUES; |
| 2349 | wl1271_debug(DEBUG_MAC80211, "allocating hw queue base: %d", |
| 2350 | wlvif->hw_queue_base); |
| 2351 | |
| 2352 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 2353 | wl->queue_stop_reasons[wlvif->hw_queue_base + i] = 0; |
| 2354 | /* register hw queues in mac80211 */ |
| 2355 | vif->hw_queue[i] = wlvif->hw_queue_base + i; |
| 2356 | } |
| 2357 | |
| 2358 | adjust_cab_queue: |
| 2359 | /* the last places are reserved for cab queues per interface */ |
| 2360 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2361 | vif->cab_queue = NUM_TX_QUEUES * WLCORE_NUM_MAC_ADDRESSES + |
| 2362 | wlvif->hw_queue_base / NUM_TX_QUEUES; |
| 2363 | else |
| 2364 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; |
| 2365 | |
| 2366 | return 0; |
| 2367 | } |
| 2368 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2369 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, |
| 2370 | struct ieee80211_vif *vif) |
| 2371 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2372 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2373 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2374 | struct vif_counter_data vif_count; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2375 | int ret = 0; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2376 | u8 role_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2377 | |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2378 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 2379 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 2380 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2381 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2382 | ieee80211_vif_type_p2p(vif), vif->addr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2383 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2384 | wl12xx_get_vif_count(hw, vif, &vif_count); |
| 2385 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2386 | mutex_lock(&wl->mutex); |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2387 | ret = wl1271_ps_elp_wakeup(wl); |
| 2388 | if (ret < 0) |
| 2389 | goto out_unlock; |
| 2390 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2391 | /* |
| 2392 | * in some very corner case HW recovery scenarios its possible to |
| 2393 | * get here before __wl1271_op_remove_interface is complete, so |
| 2394 | * opt out if that is the case. |
| 2395 | */ |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2396 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) || |
| 2397 | test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) { |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2398 | ret = -EBUSY; |
| 2399 | goto out; |
| 2400 | } |
| 2401 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2402 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2403 | ret = wl12xx_init_vif_data(wl, vif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2404 | if (ret < 0) |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2405 | goto out; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2406 | |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2407 | wlvif->wl = wl; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2408 | role_type = wl12xx_get_role_type(wl, wlvif); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2409 | if (role_type == WL12XX_INVALID_ROLE_TYPE) { |
| 2410 | ret = -EINVAL; |
| 2411 | goto out; |
| 2412 | } |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2413 | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 2414 | ret = wlcore_allocate_hw_queue_base(wl, wlvif); |
| 2415 | if (ret < 0) |
| 2416 | goto out; |
| 2417 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2418 | if (wl12xx_need_fw_change(wl, vif_count, true)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2419 | wl12xx_force_active_psm(wl); |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2420 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2421 | mutex_unlock(&wl->mutex); |
| 2422 | wl1271_recovery_work(&wl->recovery_work); |
| 2423 | return 0; |
| 2424 | } |
| 2425 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2426 | /* |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2427 | * TODO: after the nvs issue will be solved, move this block |
| 2428 | * to start(), and make sure here the driver is ON. |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2429 | */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2430 | if (wl->state == WLCORE_STATE_OFF) { |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2431 | /* |
| 2432 | * we still need this in order to configure the fw |
| 2433 | * while uploading the nvs |
| 2434 | */ |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 2435 | memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2436 | |
Luciano Coelho | 5dc283f | 2013-01-30 10:53:14 +0200 | [diff] [blame] | 2437 | ret = wl12xx_init_fw(wl); |
| 2438 | if (ret < 0) |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2439 | goto out; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2440 | } |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2441 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2442 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
| 2443 | role_type, &wlvif->role_id); |
| 2444 | if (ret < 0) |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2445 | goto out; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2446 | |
| 2447 | ret = wl1271_init_vif_specific(wl, vif); |
| 2448 | if (ret < 0) |
| 2449 | goto out; |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2450 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2451 | list_add(&wlvif->list, &wl->wlvif_list); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2452 | set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags); |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2453 | |
| 2454 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2455 | wl->ap_count++; |
| 2456 | else |
| 2457 | wl->sta_count++; |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 2458 | out: |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2459 | wl1271_ps_elp_sleep(wl); |
| 2460 | out_unlock: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2461 | mutex_unlock(&wl->mutex); |
| 2462 | |
| 2463 | return ret; |
| 2464 | } |
| 2465 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2466 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2467 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2468 | bool reset_tx_queues) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2469 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2470 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2471 | int i, ret; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2472 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2473 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2474 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2475 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2476 | if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2477 | return; |
| 2478 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2479 | /* because of hardware recovery, we may get here twice */ |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2480 | if (wl->state == WLCORE_STATE_OFF) |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2481 | return; |
| 2482 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2483 | wl1271_info("down"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2484 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2485 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE && |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2486 | wl->scan_wlvif == wlvif) { |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 2487 | /* |
| 2488 | * Rearm the tx watchdog just before idling scan. This |
| 2489 | * prevents just-finished scans from triggering the watchdog |
| 2490 | */ |
| 2491 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 2492 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 2493 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 2494 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2495 | wl->scan_wlvif = NULL; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 2496 | wl->scan.req = NULL; |
Juuso Oikarinen | 76a029f | 2010-07-29 04:54:45 +0300 | [diff] [blame] | 2497 | ieee80211_scan_completed(wl->hw, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2498 | } |
| 2499 | |
Eliad Peller | 1019975 | 2012-11-22 18:06:23 +0200 | [diff] [blame] | 2500 | if (wl->sched_vif == wlvif) { |
| 2501 | ieee80211_sched_scan_stopped(wl->hw); |
| 2502 | wl->sched_vif = NULL; |
| 2503 | } |
| 2504 | |
Arik Nemtsov | 5d979f3 | 2012-11-27 08:44:48 +0200 | [diff] [blame] | 2505 | if (wl->roc_vif == vif) { |
| 2506 | wl->roc_vif = NULL; |
| 2507 | ieee80211_remain_on_channel_expired(wl->hw); |
| 2508 | } |
| 2509 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2510 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 2511 | /* disable active roles */ |
| 2512 | ret = wl1271_ps_elp_wakeup(wl); |
| 2513 | if (ret < 0) |
| 2514 | goto deinit; |
| 2515 | |
Eliad Peller | b890f4c | 2011-12-18 20:25:44 +0200 | [diff] [blame] | 2516 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2517 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2518 | if (wl12xx_dev_role_started(wlvif)) |
| 2519 | wl12xx_stop_dev(wl, wlvif); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2520 | } |
| 2521 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2522 | ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2523 | if (ret < 0) |
| 2524 | goto deinit; |
| 2525 | |
| 2526 | wl1271_ps_elp_sleep(wl); |
| 2527 | } |
| 2528 | deinit: |
Arik Nemtsov | 5a99610 | 2013-03-12 17:19:43 +0200 | [diff] [blame] | 2529 | wl12xx_tx_reset_wlvif(wl, wlvif); |
| 2530 | |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 2531 | /* clear all hlids (except system_hlid) */ |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2532 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2533 | |
| 2534 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2535 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2536 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
| 2537 | wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2538 | wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2539 | wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2540 | wlcore_free_klv_template(wl, &wlvif->sta.klv_template_id); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2541 | } else { |
| 2542 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2543 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
| 2544 | wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2545 | wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2546 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2547 | wl12xx_free_rate_policy(wl, |
| 2548 | &wlvif->ap.ucast_rate_idx[i]); |
Eliad Peller | 830be7e | 2012-03-19 11:32:55 +0200 | [diff] [blame] | 2549 | wl1271_free_ap_keys(wl, wlvif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2550 | } |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2551 | |
Eyal Shapira | 3eba4a0 | 2012-03-19 12:06:27 +0200 | [diff] [blame] | 2552 | dev_kfree_skb(wlvif->probereq); |
| 2553 | wlvif->probereq = NULL; |
Eliad Peller | e4120df | 2011-10-10 10:13:17 +0200 | [diff] [blame] | 2554 | if (wl->last_wlvif == wlvif) |
| 2555 | wl->last_wlvif = NULL; |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2556 | list_del(&wlvif->list); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 2557 | 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] | 2558 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2559 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Luciano Coelho | d6e19d1 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 2560 | |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2561 | if (is_ap) |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2562 | wl->ap_count--; |
| 2563 | else |
| 2564 | wl->sta_count--; |
| 2565 | |
Arik Nemtsov | 42066f9 | 2012-07-10 10:45:01 +0300 | [diff] [blame] | 2566 | /* |
| 2567 | * Last AP, have more stations. Configure sleep auth according to STA. |
| 2568 | * Don't do thin on unintended recovery. |
| 2569 | */ |
| 2570 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) && |
| 2571 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)) |
| 2572 | goto unlock; |
| 2573 | |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2574 | if (wl->ap_count == 0 && is_ap && wl->sta_count) { |
| 2575 | u8 sta_auth = wl->conf.conn.sta_sleep_auth; |
| 2576 | /* Configure for power according to debugfs */ |
| 2577 | if (sta_auth != WL1271_PSM_ILLEGAL) |
| 2578 | wl1271_acx_sleep_auth(wl, sta_auth); |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2579 | /* Configure for ELP power saving */ |
| 2580 | else |
| 2581 | wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); |
| 2582 | } |
| 2583 | |
Arik Nemtsov | 42066f9 | 2012-07-10 10:45:01 +0300 | [diff] [blame] | 2584 | unlock: |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2585 | mutex_unlock(&wl->mutex); |
Eyal Shapira | d6bf9ad | 2012-01-31 11:57:20 +0200 | [diff] [blame] | 2586 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2587 | del_timer_sync(&wlvif->rx_streaming_timer); |
| 2588 | cancel_work_sync(&wlvif->rx_streaming_enable_work); |
| 2589 | cancel_work_sync(&wlvif->rx_streaming_disable_work); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2590 | cancel_delayed_work_sync(&wlvif->connection_loss_work); |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 2591 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2592 | mutex_lock(&wl->mutex); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2593 | } |
Juuso Oikarinen | bd9dc49 | 2010-04-09 11:07:26 +0300 | [diff] [blame] | 2594 | |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2595 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, |
| 2596 | struct ieee80211_vif *vif) |
| 2597 | { |
| 2598 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2599 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2600 | struct wl12xx_vif *iter; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2601 | struct vif_counter_data vif_count; |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2602 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2603 | wl12xx_get_vif_count(hw, vif, &vif_count); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2604 | mutex_lock(&wl->mutex); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2605 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2606 | if (wl->state == WLCORE_STATE_OFF || |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2607 | !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2608 | goto out; |
| 2609 | |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2610 | /* |
| 2611 | * wl->vif can be null here if someone shuts down the interface |
| 2612 | * just when hardware recovery has been started. |
| 2613 | */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2614 | wl12xx_for_each_wlvif(wl, iter) { |
| 2615 | if (iter != wlvif) |
| 2616 | continue; |
| 2617 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2618 | __wl1271_op_remove_interface(wl, vif, true); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2619 | break; |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2620 | } |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2621 | WARN_ON(iter != wlvif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2622 | if (wl12xx_need_fw_change(wl, vif_count, false)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2623 | wl12xx_force_active_psm(wl); |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2624 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2625 | wl12xx_queue_recovery_work(wl); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2626 | } |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2627 | out: |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2628 | mutex_unlock(&wl->mutex); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2629 | } |
| 2630 | |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2631 | static int wl12xx_op_change_interface(struct ieee80211_hw *hw, |
| 2632 | struct ieee80211_vif *vif, |
| 2633 | enum nl80211_iftype new_type, bool p2p) |
| 2634 | { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2635 | struct wl1271 *wl = hw->priv; |
| 2636 | int ret; |
| 2637 | |
| 2638 | set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2639 | wl1271_op_remove_interface(hw, vif); |
| 2640 | |
Eliad Peller | 249e969 | 2012-03-04 10:55:50 +0200 | [diff] [blame] | 2641 | vif->type = new_type; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2642 | vif->p2p = p2p; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2643 | ret = wl1271_op_add_interface(hw, vif); |
| 2644 | |
| 2645 | clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
| 2646 | return ret; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2647 | } |
| 2648 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2649 | static int wlcore_join(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2650 | { |
| 2651 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2652 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2653 | |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2654 | /* |
| 2655 | * One of the side effects of the JOIN command is that is clears |
| 2656 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated |
| 2657 | * 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] | 2658 | * Currently the only valid scenario for JOIN during association |
| 2659 | * is on roaming, in which case we will also be given new keys. |
| 2660 | * Keep the below message for now, unless it starts bothering |
| 2661 | * users who really like to roam a lot :) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2662 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2663 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2664 | wl1271_info("JOIN while associated."); |
| 2665 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 2666 | /* clear encryption type */ |
| 2667 | wlvif->encryption_type = KEY_NONE; |
| 2668 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2669 | if (is_ibss) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2670 | ret = wl12xx_cmd_role_start_ibss(wl, wlvif); |
Eliad Peller | 18eab43 | 2012-11-20 13:20:02 +0200 | [diff] [blame] | 2671 | else { |
| 2672 | if (wl->quirks & WLCORE_QUIRK_START_STA_FAILS) { |
| 2673 | /* |
| 2674 | * TODO: this is an ugly workaround for wl12xx fw |
| 2675 | * bug - we are not able to tx/rx after the first |
| 2676 | * start_sta, so make dummy start+stop calls, |
| 2677 | * and then call start_sta again. |
| 2678 | * this should be fixed in the fw. |
| 2679 | */ |
| 2680 | wl12xx_cmd_role_start_sta(wl, wlvif); |
| 2681 | wl12xx_cmd_role_stop_sta(wl, wlvif); |
| 2682 | } |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2683 | |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2684 | ret = wl12xx_cmd_role_start_sta(wl, wlvif); |
Eliad Peller | 18eab43 | 2012-11-20 13:20:02 +0200 | [diff] [blame] | 2685 | } |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2686 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2687 | return ret; |
| 2688 | } |
| 2689 | |
| 2690 | static int wl1271_ssid_set(struct wl12xx_vif *wlvif, struct sk_buff *skb, |
| 2691 | int offset) |
| 2692 | { |
| 2693 | u8 ssid_len; |
| 2694 | const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, |
| 2695 | skb->len - offset); |
| 2696 | |
| 2697 | if (!ptr) { |
| 2698 | wl1271_error("No SSID in IEs!"); |
| 2699 | return -ENOENT; |
| 2700 | } |
| 2701 | |
| 2702 | ssid_len = ptr[1]; |
| 2703 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 2704 | wl1271_error("SSID is too long!"); |
| 2705 | return -EINVAL; |
| 2706 | } |
| 2707 | |
| 2708 | wlvif->ssid_len = ssid_len; |
| 2709 | memcpy(wlvif->ssid, ptr+2, ssid_len); |
| 2710 | return 0; |
| 2711 | } |
| 2712 | |
| 2713 | static int wlcore_set_ssid(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 2714 | { |
| 2715 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2716 | struct sk_buff *skb; |
| 2717 | int ieoffset; |
| 2718 | |
| 2719 | /* we currently only support setting the ssid from the ap probe req */ |
| 2720 | if (wlvif->bss_type != BSS_TYPE_STA_BSS) |
| 2721 | return -EINVAL; |
| 2722 | |
| 2723 | skb = ieee80211_ap_probereq_get(wl->hw, vif); |
| 2724 | if (!skb) |
| 2725 | return -EINVAL; |
| 2726 | |
| 2727 | ieoffset = offsetof(struct ieee80211_mgmt, |
| 2728 | u.probe_req.variable); |
| 2729 | wl1271_ssid_set(wlvif, skb, ieoffset); |
| 2730 | dev_kfree_skb(skb); |
| 2731 | |
| 2732 | return 0; |
| 2733 | } |
| 2734 | |
| 2735 | static int wlcore_set_assoc(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 2736 | struct ieee80211_bss_conf *bss_conf, |
| 2737 | u32 sta_rate_set) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2738 | { |
| 2739 | int ieoffset; |
| 2740 | int ret; |
| 2741 | |
| 2742 | wlvif->aid = bss_conf->aid; |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 2743 | wlvif->channel_type = cfg80211_get_chandef_type(&bss_conf->chandef); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2744 | wlvif->beacon_int = bss_conf->beacon_int; |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 2745 | wlvif->wmm_enabled = bss_conf->qos; |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2746 | |
| 2747 | set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags); |
| 2748 | |
| 2749 | /* |
| 2750 | * with wl1271, we don't need to update the |
| 2751 | * beacon_int and dtim_period, because the firmware |
| 2752 | * updates it by itself when the first beacon is |
| 2753 | * received after a join. |
| 2754 | */ |
| 2755 | ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid); |
| 2756 | if (ret < 0) |
| 2757 | return ret; |
| 2758 | |
| 2759 | /* |
| 2760 | * Get a template for hardware connection maintenance |
| 2761 | */ |
| 2762 | dev_kfree_skb(wlvif->probereq); |
| 2763 | wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl, |
| 2764 | wlvif, |
| 2765 | NULL); |
| 2766 | ieoffset = offsetof(struct ieee80211_mgmt, |
| 2767 | u.probe_req.variable); |
| 2768 | wl1271_ssid_set(wlvif, wlvif->probereq, ieoffset); |
| 2769 | |
| 2770 | /* enable the connection monitoring feature */ |
| 2771 | ret = wl1271_acx_conn_monit_params(wl, wlvif, true); |
| 2772 | if (ret < 0) |
| 2773 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2774 | |
| 2775 | /* |
| 2776 | * The join command disable the keep-alive mode, shut down its process, |
| 2777 | * and also clear the template config, so we need to reset it all after |
| 2778 | * the join. The acx_aid starts the keep-alive process, and the order |
| 2779 | * of the commands below is relevant. |
| 2780 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2781 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, true); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2782 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2783 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2784 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2785 | ret = wl1271_acx_aid(wl, wlvif, wlvif->aid); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2786 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2787 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2788 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2789 | ret = wl12xx_cmd_build_klv_null_data(wl, wlvif); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2790 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2791 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2792 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2793 | ret = wl1271_acx_keep_alive_config(wl, wlvif, |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2794 | wlvif->sta.klv_template_id, |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2795 | ACX_KEEP_ALIVE_TPL_VALID); |
| 2796 | if (ret < 0) |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2797 | return ret; |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2798 | |
Eliad Peller | 6c7b519 | 2012-11-20 13:20:07 +0200 | [diff] [blame] | 2799 | /* |
| 2800 | * The default fw psm configuration is AUTO, while mac80211 default |
| 2801 | * setting is off (ACTIVE), so sync the fw with the correct value. |
| 2802 | */ |
| 2803 | ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE); |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 2804 | if (ret < 0) |
| 2805 | return ret; |
| 2806 | |
| 2807 | if (sta_rate_set) { |
| 2808 | wlvif->rate_set = |
| 2809 | wl1271_tx_enabled_rates_get(wl, |
| 2810 | sta_rate_set, |
| 2811 | wlvif->band); |
| 2812 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 2813 | if (ret < 0) |
| 2814 | return ret; |
| 2815 | } |
Eliad Peller | 6c7b519 | 2012-11-20 13:20:07 +0200 | [diff] [blame] | 2816 | |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2817 | return ret; |
| 2818 | } |
| 2819 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2820 | static int wlcore_unset_assoc(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2821 | { |
| 2822 | int ret; |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2823 | bool sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
| 2824 | |
| 2825 | /* make sure we are connected (sta) joined */ |
| 2826 | if (sta && |
| 2827 | !test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 2828 | return false; |
| 2829 | |
| 2830 | /* make sure we are joined (ibss) */ |
| 2831 | if (!sta && |
| 2832 | test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) |
| 2833 | return false; |
| 2834 | |
| 2835 | if (sta) { |
| 2836 | /* use defaults when not associated */ |
| 2837 | wlvif->aid = 0; |
| 2838 | |
| 2839 | /* free probe-request template */ |
| 2840 | dev_kfree_skb(wlvif->probereq); |
| 2841 | wlvif->probereq = NULL; |
| 2842 | |
| 2843 | /* disable connection monitor features */ |
| 2844 | ret = wl1271_acx_conn_monit_params(wl, wlvif, false); |
| 2845 | if (ret < 0) |
| 2846 | return ret; |
| 2847 | |
| 2848 | /* Disable the keep-alive feature */ |
| 2849 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, false); |
| 2850 | if (ret < 0) |
| 2851 | return ret; |
| 2852 | } |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2853 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 2854 | if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2855 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2856 | |
Eliad Peller | fcab189 | 2012-11-22 18:06:18 +0200 | [diff] [blame] | 2857 | wl12xx_cmd_stop_channel_switch(wl, wlvif); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2858 | ieee80211_chswitch_done(vif, false); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 2859 | cancel_delayed_work(&wlvif->channel_switch_work); |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2860 | } |
| 2861 | |
Eliad Peller | 4137c17 | 2012-08-16 13:32:32 +0300 | [diff] [blame] | 2862 | /* invalidate keep-alive template */ |
| 2863 | wl1271_acx_keep_alive_config(wl, wlvif, |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 2864 | wlvif->sta.klv_template_id, |
Eliad Peller | 4137c17 | 2012-08-16 13:32:32 +0300 | [diff] [blame] | 2865 | ACX_KEEP_ALIVE_TPL_INVALID); |
| 2866 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 2867 | return 0; |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2868 | } |
| 2869 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2870 | 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] | 2871 | { |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2872 | wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band]; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2873 | wlvif->rate_set = wlvif->basic_rate_set; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2874 | } |
| 2875 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2876 | static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2877 | struct ieee80211_conf *conf, u32 changed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2878 | { |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 2879 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2880 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2881 | if (conf->power_level != wlvif->power_level) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2882 | ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2883 | if (ret < 0) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2884 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2885 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2886 | wlvif->power_level = conf->power_level; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2887 | } |
| 2888 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2889 | return 0; |
| 2890 | } |
| 2891 | |
| 2892 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) |
| 2893 | { |
| 2894 | struct wl1271 *wl = hw->priv; |
| 2895 | struct wl12xx_vif *wlvif; |
| 2896 | struct ieee80211_conf *conf = &hw->conf; |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 2897 | int ret = 0; |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2898 | |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 2899 | wl1271_debug(DEBUG_MAC80211, "mac80211 config psm %s power %d %s" |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2900 | " changed 0x%x", |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2901 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", |
| 2902 | conf->power_level, |
| 2903 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", |
| 2904 | changed); |
| 2905 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2906 | mutex_lock(&wl->mutex); |
| 2907 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2908 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 2909 | wl->power_level = conf->power_level; |
| 2910 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2911 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2912 | goto out; |
| 2913 | |
| 2914 | ret = wl1271_ps_elp_wakeup(wl); |
| 2915 | if (ret < 0) |
| 2916 | goto out; |
| 2917 | |
| 2918 | /* configure each interface */ |
| 2919 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 2920 | ret = wl12xx_config_vif(wl, wlvif, conf, changed); |
| 2921 | if (ret < 0) |
| 2922 | goto out_sleep; |
| 2923 | } |
| 2924 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2925 | out_sleep: |
| 2926 | wl1271_ps_elp_sleep(wl); |
| 2927 | |
| 2928 | out: |
| 2929 | mutex_unlock(&wl->mutex); |
| 2930 | |
| 2931 | return ret; |
| 2932 | } |
| 2933 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2934 | struct wl1271_filter_params { |
| 2935 | bool enabled; |
| 2936 | int mc_list_length; |
| 2937 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; |
| 2938 | }; |
| 2939 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2940 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, |
| 2941 | struct netdev_hw_addr_list *mc_list) |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2942 | { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2943 | struct wl1271_filter_params *fp; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2944 | struct netdev_hw_addr *ha; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2945 | |
Juuso Oikarinen | 7444113 | 2009-10-13 12:47:53 +0300 | [diff] [blame] | 2946 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2947 | if (!fp) { |
| 2948 | wl1271_error("Out of memory setting filters."); |
| 2949 | return 0; |
| 2950 | } |
| 2951 | |
| 2952 | /* update multicast filtering parameters */ |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2953 | fp->mc_list_length = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2954 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { |
| 2955 | fp->enabled = false; |
| 2956 | } else { |
| 2957 | fp->enabled = true; |
| 2958 | netdev_hw_addr_list_for_each(ha, mc_list) { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2959 | memcpy(fp->mc_list[fp->mc_list_length], |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2960 | ha->addr, ETH_ALEN); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2961 | fp->mc_list_length++; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2962 | } |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2963 | } |
| 2964 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2965 | return (u64)(unsigned long)fp; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2966 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2967 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2968 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ |
| 2969 | FIF_ALLMULTI | \ |
| 2970 | FIF_FCSFAIL | \ |
| 2971 | FIF_BCN_PRBRESP_PROMISC | \ |
| 2972 | FIF_CONTROL | \ |
| 2973 | FIF_OTHER_BSS) |
| 2974 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2975 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, |
| 2976 | unsigned int changed, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2977 | unsigned int *total, u64 multicast) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2978 | { |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2979 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2980 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2981 | struct wl12xx_vif *wlvif; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2982 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2983 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2984 | |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2985 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" |
| 2986 | " total %x", changed, *total); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2987 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2988 | mutex_lock(&wl->mutex); |
| 2989 | |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2990 | *total &= WL1271_SUPPORTED_FILTERS; |
| 2991 | changed &= WL1271_SUPPORTED_FILTERS; |
| 2992 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 2993 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2994 | goto out; |
| 2995 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 2996 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2997 | if (ret < 0) |
| 2998 | goto out; |
| 2999 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3000 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 3001 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { |
| 3002 | if (*total & FIF_ALLMULTI) |
| 3003 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 3004 | false, |
| 3005 | NULL, 0); |
| 3006 | else if (fp) |
| 3007 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 3008 | fp->enabled, |
| 3009 | fp->mc_list, |
| 3010 | fp->mc_list_length); |
| 3011 | if (ret < 0) |
| 3012 | goto out_sleep; |
| 3013 | } |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 3014 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3015 | |
Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 3016 | /* |
| 3017 | * the fw doesn't provide an api to configure the filters. instead, |
| 3018 | * the filters configuration is based on the active roles / ROC |
| 3019 | * state. |
| 3020 | */ |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 3021 | |
| 3022 | out_sleep: |
| 3023 | wl1271_ps_elp_sleep(wl); |
| 3024 | |
| 3025 | out: |
| 3026 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 14b228a | 2010-03-18 12:26:43 +0200 | [diff] [blame] | 3027 | kfree(fp); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3028 | } |
| 3029 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3030 | static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 3031 | u8 id, u8 key_type, u8 key_size, |
| 3032 | const u8 *key, u8 hlid, u32 tx_seq_32, |
| 3033 | u16 tx_seq_16) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3034 | { |
| 3035 | struct wl1271_ap_key *ap_key; |
| 3036 | int i; |
| 3037 | |
| 3038 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); |
| 3039 | |
| 3040 | if (key_size > MAX_KEY_SIZE) |
| 3041 | return -EINVAL; |
| 3042 | |
| 3043 | /* |
| 3044 | * Find next free entry in ap_keys. Also check we are not replacing |
| 3045 | * an existing key. |
| 3046 | */ |
| 3047 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3048 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3049 | break; |
| 3050 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3051 | if (wlvif->ap.recorded_keys[i]->id == id) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3052 | wl1271_warning("trying to record key replacement"); |
| 3053 | return -EINVAL; |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | if (i == MAX_NUM_KEYS) |
| 3058 | return -EBUSY; |
| 3059 | |
| 3060 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); |
| 3061 | if (!ap_key) |
| 3062 | return -ENOMEM; |
| 3063 | |
| 3064 | ap_key->id = id; |
| 3065 | ap_key->key_type = key_type; |
| 3066 | ap_key->key_size = key_size; |
| 3067 | memcpy(ap_key->key, key, key_size); |
| 3068 | ap_key->hlid = hlid; |
| 3069 | ap_key->tx_seq_32 = tx_seq_32; |
| 3070 | ap_key->tx_seq_16 = tx_seq_16; |
| 3071 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3072 | wlvif->ap.recorded_keys[i] = ap_key; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3073 | return 0; |
| 3074 | } |
| 3075 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3076 | 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] | 3077 | { |
| 3078 | int i; |
| 3079 | |
| 3080 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3081 | kfree(wlvif->ap.recorded_keys[i]); |
| 3082 | wlvif->ap.recorded_keys[i] = NULL; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3086 | 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] | 3087 | { |
| 3088 | int i, ret = 0; |
| 3089 | struct wl1271_ap_key *key; |
| 3090 | bool wep_key_added = false; |
| 3091 | |
| 3092 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3093 | u8 hlid; |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3094 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3095 | break; |
| 3096 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3097 | key = wlvif->ap.recorded_keys[i]; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3098 | hlid = key->hlid; |
| 3099 | if (hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3100 | hlid = wlvif->ap.bcast_hlid; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3101 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3102 | ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3103 | key->id, key->key_type, |
| 3104 | key->key_size, key->key, |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 3105 | hlid, key->tx_seq_32, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3106 | key->tx_seq_16); |
| 3107 | if (ret < 0) |
| 3108 | goto out; |
| 3109 | |
| 3110 | if (key->key_type == KEY_WEP) |
| 3111 | wep_key_added = true; |
| 3112 | } |
| 3113 | |
| 3114 | if (wep_key_added) { |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 3115 | ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key, |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3116 | wlvif->ap.bcast_hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3117 | if (ret < 0) |
| 3118 | goto out; |
| 3119 | } |
| 3120 | |
| 3121 | out: |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3122 | wl1271_free_ap_keys(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3123 | return ret; |
| 3124 | } |
| 3125 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3126 | static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 3127 | u16 action, u8 id, u8 key_type, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3128 | u8 key_size, const u8 *key, u32 tx_seq_32, |
| 3129 | u16 tx_seq_16, struct ieee80211_sta *sta) |
| 3130 | { |
| 3131 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3132 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3133 | |
| 3134 | if (is_ap) { |
| 3135 | struct wl1271_station *wl_sta; |
| 3136 | u8 hlid; |
| 3137 | |
| 3138 | if (sta) { |
| 3139 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 3140 | hlid = wl_sta->hlid; |
| 3141 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3142 | hlid = wlvif->ap.bcast_hlid; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3143 | } |
| 3144 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3145 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3146 | /* |
| 3147 | * We do not support removing keys after AP shutdown. |
| 3148 | * Pretend we do to make mac80211 happy. |
| 3149 | */ |
| 3150 | if (action != KEY_ADD_OR_REPLACE) |
| 3151 | return 0; |
| 3152 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 3153 | ret = wl1271_record_ap_key(wl, wlvif, id, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3154 | key_type, key_size, |
| 3155 | key, hlid, tx_seq_32, |
| 3156 | tx_seq_16); |
| 3157 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3158 | ret = wl1271_cmd_set_ap_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3159 | id, key_type, key_size, |
| 3160 | key, hlid, tx_seq_32, |
| 3161 | tx_seq_16); |
| 3162 | } |
| 3163 | |
| 3164 | if (ret < 0) |
| 3165 | return ret; |
| 3166 | } else { |
| 3167 | const u8 *addr; |
| 3168 | static const u8 bcast_addr[ETH_ALEN] = { |
| 3169 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 3170 | }; |
| 3171 | |
| 3172 | addr = sta ? sta->addr : bcast_addr; |
| 3173 | |
| 3174 | if (is_zero_ether_addr(addr)) { |
| 3175 | /* We dont support TX only encryption */ |
| 3176 | return -EOPNOTSUPP; |
| 3177 | } |
| 3178 | |
| 3179 | /* The wl1271 does not allow to remove unicast keys - they |
| 3180 | will be cleared automatically on next CMD_JOIN. Ignore the |
| 3181 | request silently, as we dont want the mac80211 to emit |
| 3182 | an error message. */ |
| 3183 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) |
| 3184 | return 0; |
| 3185 | |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3186 | /* don't remove key if hlid was already deleted */ |
| 3187 | if (action == KEY_REMOVE && |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3188 | wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 3189 | return 0; |
| 3190 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3191 | ret = wl1271_cmd_set_sta_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3192 | id, key_type, key_size, |
| 3193 | key, addr, tx_seq_32, |
| 3194 | tx_seq_16); |
| 3195 | if (ret < 0) |
| 3196 | return ret; |
| 3197 | |
| 3198 | /* the default WEP key needs to be configured at least once */ |
| 3199 | if (key_type == KEY_WEP) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 3200 | ret = wl12xx_cmd_set_default_wep_key(wl, |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 3201 | wlvif->default_key, |
| 3202 | wlvif->sta.hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3203 | if (ret < 0) |
| 3204 | return ret; |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | return 0; |
| 3209 | } |
| 3210 | |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3211 | 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] | 3212 | struct ieee80211_vif *vif, |
| 3213 | struct ieee80211_sta *sta, |
| 3214 | struct ieee80211_key_conf *key_conf) |
| 3215 | { |
| 3216 | struct wl1271 *wl = hw->priv; |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3217 | int ret; |
| 3218 | bool might_change_spare = |
| 3219 | key_conf->cipher == WL1271_CIPHER_SUITE_GEM || |
| 3220 | key_conf->cipher == WLAN_CIPHER_SUITE_TKIP; |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3221 | |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3222 | if (might_change_spare) { |
| 3223 | /* |
| 3224 | * stop the queues and flush to ensure the next packets are |
| 3225 | * in sync with FW spare block accounting |
| 3226 | */ |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3227 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3228 | wl1271_tx_flush(wl); |
| 3229 | } |
| 3230 | |
| 3231 | mutex_lock(&wl->mutex); |
| 3232 | |
| 3233 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
| 3234 | ret = -EAGAIN; |
| 3235 | goto out_wake_queues; |
| 3236 | } |
| 3237 | |
| 3238 | ret = wl1271_ps_elp_wakeup(wl); |
| 3239 | if (ret < 0) |
| 3240 | goto out_wake_queues; |
| 3241 | |
| 3242 | ret = wlcore_hw_set_key(wl, cmd, vif, sta, key_conf); |
| 3243 | |
| 3244 | wl1271_ps_elp_sleep(wl); |
| 3245 | |
| 3246 | out_wake_queues: |
| 3247 | if (might_change_spare) |
| 3248 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK); |
| 3249 | |
| 3250 | mutex_unlock(&wl->mutex); |
| 3251 | |
| 3252 | return ret; |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd, |
| 3256 | struct ieee80211_vif *vif, |
| 3257 | struct ieee80211_sta *sta, |
| 3258 | struct ieee80211_key_conf *key_conf) |
| 3259 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3260 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3261 | int ret; |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 3262 | u32 tx_seq_32 = 0; |
| 3263 | u16 tx_seq_16 = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3264 | u8 key_type; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 3265 | u8 hlid; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3266 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3267 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); |
| 3268 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3269 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3270 | 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] | 3271 | key_conf->cipher, key_conf->keyidx, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3272 | key_conf->keylen, key_conf->flags); |
| 3273 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); |
| 3274 | |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 3275 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 3276 | if (sta) { |
| 3277 | struct wl1271_station *wl_sta = (void *)sta->drv_priv; |
| 3278 | hlid = wl_sta->hlid; |
| 3279 | } else { |
| 3280 | hlid = wlvif->ap.bcast_hlid; |
| 3281 | } |
| 3282 | else |
| 3283 | hlid = wlvif->sta.hlid; |
| 3284 | |
| 3285 | if (hlid != WL12XX_INVALID_LINK_ID) { |
| 3286 | u64 tx_seq = wl->links[hlid].total_freed_pkts; |
| 3287 | tx_seq_32 = WL1271_TX_SECURITY_HI32(tx_seq); |
| 3288 | tx_seq_16 = WL1271_TX_SECURITY_LO16(tx_seq); |
| 3289 | } |
| 3290 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3291 | switch (key_conf->cipher) { |
| 3292 | case WLAN_CIPHER_SUITE_WEP40: |
| 3293 | case WLAN_CIPHER_SUITE_WEP104: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3294 | key_type = KEY_WEP; |
| 3295 | |
| 3296 | key_conf->hw_key_idx = key_conf->keyidx; |
| 3297 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3298 | case WLAN_CIPHER_SUITE_TKIP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3299 | key_type = KEY_TKIP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3300 | key_conf->hw_key_idx = key_conf->keyidx; |
| 3301 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3302 | case WLAN_CIPHER_SUITE_CCMP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3303 | key_type = KEY_AES; |
Arik Nemtsov | 12d4b97 | 2011-10-23 08:21:54 +0200 | [diff] [blame] | 3304 | key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3305 | break; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3306 | case WL1271_CIPHER_SUITE_GEM: |
| 3307 | key_type = KEY_GEM; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3308 | break; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3309 | default: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3310 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3311 | |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3312 | return -EOPNOTSUPP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | switch (cmd) { |
| 3316 | case SET_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3317 | ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3318 | key_conf->keyidx, key_type, |
| 3319 | key_conf->keylen, key_conf->key, |
| 3320 | tx_seq_32, tx_seq_16, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3321 | if (ret < 0) { |
| 3322 | wl1271_error("Could not add or replace key"); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3323 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3324 | } |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3325 | |
| 3326 | /* |
| 3327 | * reconfiguring arp response if the unicast (or common) |
| 3328 | * encryption key type was changed |
| 3329 | */ |
| 3330 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 3331 | (sta || key_type == KEY_WEP) && |
| 3332 | wlvif->encryption_type != key_type) { |
| 3333 | wlvif->encryption_type = key_type; |
| 3334 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 3335 | if (ret < 0) { |
| 3336 | wl1271_warning("build arp rsp failed: %d", ret); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3337 | return ret; |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3338 | } |
| 3339 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3340 | break; |
| 3341 | |
| 3342 | case DISABLE_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3343 | ret = wl1271_set_key(wl, wlvif, KEY_REMOVE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3344 | key_conf->keyidx, key_type, |
| 3345 | key_conf->keylen, key_conf->key, |
| 3346 | 0, 0, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3347 | if (ret < 0) { |
| 3348 | wl1271_error("Could not remove key"); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3349 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3350 | } |
| 3351 | break; |
| 3352 | |
| 3353 | default: |
| 3354 | wl1271_error("Unsupported key cmd 0x%x", cmd); |
Eliad Peller | af390f4 | 2012-09-03 18:27:58 +0300 | [diff] [blame] | 3355 | return -EOPNOTSUPP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3356 | } |
| 3357 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3358 | return ret; |
| 3359 | } |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3360 | EXPORT_SYMBOL_GPL(wlcore_set_key); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3361 | |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 3362 | void wlcore_regdomain_config(struct wl1271 *wl) |
| 3363 | { |
| 3364 | int ret; |
| 3365 | |
| 3366 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) |
| 3367 | return; |
| 3368 | |
| 3369 | mutex_lock(&wl->mutex); |
Arik Nemtsov | 75592be | 2013-03-12 17:19:45 +0200 | [diff] [blame] | 3370 | |
| 3371 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 3372 | goto out; |
| 3373 | |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 3374 | ret = wl1271_ps_elp_wakeup(wl); |
| 3375 | if (ret < 0) |
| 3376 | goto out; |
| 3377 | |
| 3378 | ret = wlcore_cmd_regdomain_config_locked(wl); |
| 3379 | if (ret < 0) { |
| 3380 | wl12xx_queue_recovery_work(wl); |
| 3381 | goto out; |
| 3382 | } |
| 3383 | |
| 3384 | wl1271_ps_elp_sleep(wl); |
| 3385 | out: |
| 3386 | mutex_unlock(&wl->mutex); |
| 3387 | } |
| 3388 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3389 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, |
Johannes Berg | a060bbf | 2010-04-27 11:59:34 +0200 | [diff] [blame] | 3390 | struct ieee80211_vif *vif, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3391 | struct cfg80211_scan_request *req) |
| 3392 | { |
| 3393 | struct wl1271 *wl = hw->priv; |
| 3394 | int ret; |
| 3395 | u8 *ssid = NULL; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3396 | size_t len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3397 | |
| 3398 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); |
| 3399 | |
| 3400 | if (req->n_ssids) { |
| 3401 | ssid = req->ssids[0].ssid; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3402 | len = req->ssids[0].ssid_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | mutex_lock(&wl->mutex); |
| 3406 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3407 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 3408 | /* |
| 3409 | * We cannot return -EBUSY here because cfg80211 will expect |
| 3410 | * a call to ieee80211_scan_completed if we do - in this case |
| 3411 | * there won't be any call. |
| 3412 | */ |
| 3413 | ret = -EAGAIN; |
| 3414 | goto out; |
| 3415 | } |
| 3416 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3417 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3418 | if (ret < 0) |
| 3419 | goto out; |
| 3420 | |
Eliad Peller | 97fd311 | 2012-03-04 10:55:52 +0200 | [diff] [blame] | 3421 | /* fail if there is any role in ROC */ |
| 3422 | 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] | 3423 | /* don't allow scanning right now */ |
| 3424 | ret = -EBUSY; |
| 3425 | goto out_sleep; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3426 | } |
| 3427 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3428 | ret = wlcore_scan(hw->priv, vif, ssid, len, req); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3429 | out_sleep: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3430 | wl1271_ps_elp_sleep(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3431 | out: |
| 3432 | mutex_unlock(&wl->mutex); |
| 3433 | |
| 3434 | return ret; |
| 3435 | } |
| 3436 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3437 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, |
| 3438 | struct ieee80211_vif *vif) |
| 3439 | { |
| 3440 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3441 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3442 | int ret; |
| 3443 | |
| 3444 | wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); |
| 3445 | |
| 3446 | mutex_lock(&wl->mutex); |
| 3447 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3448 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3449 | goto out; |
| 3450 | |
| 3451 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) |
| 3452 | goto out; |
| 3453 | |
| 3454 | ret = wl1271_ps_elp_wakeup(wl); |
| 3455 | if (ret < 0) |
| 3456 | goto out; |
| 3457 | |
| 3458 | if (wl->scan.state != WL1271_SCAN_STATE_DONE) { |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3459 | ret = wl->ops->scan_stop(wl, wlvif); |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3460 | if (ret < 0) |
| 3461 | goto out_sleep; |
| 3462 | } |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 3463 | |
| 3464 | /* |
| 3465 | * Rearm the tx watchdog just before idling scan. This |
| 3466 | * prevents just-finished scans from triggering the watchdog |
| 3467 | */ |
| 3468 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 3469 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3470 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
| 3471 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 3472 | wl->scan_wlvif = NULL; |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3473 | wl->scan.req = NULL; |
| 3474 | ieee80211_scan_completed(wl->hw, true); |
| 3475 | |
| 3476 | out_sleep: |
| 3477 | wl1271_ps_elp_sleep(wl); |
| 3478 | out: |
| 3479 | mutex_unlock(&wl->mutex); |
| 3480 | |
| 3481 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 3482 | } |
| 3483 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3484 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, |
| 3485 | struct ieee80211_vif *vif, |
| 3486 | struct cfg80211_sched_scan_request *req, |
| 3487 | struct ieee80211_sched_scan_ies *ies) |
| 3488 | { |
| 3489 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3490 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3491 | int ret; |
| 3492 | |
| 3493 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); |
| 3494 | |
| 3495 | mutex_lock(&wl->mutex); |
| 3496 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3497 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3498 | ret = -EAGAIN; |
| 3499 | goto out; |
| 3500 | } |
| 3501 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3502 | ret = wl1271_ps_elp_wakeup(wl); |
| 3503 | if (ret < 0) |
| 3504 | goto out; |
| 3505 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3506 | ret = wl->ops->sched_scan_start(wl, wlvif, req, ies); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3507 | if (ret < 0) |
| 3508 | goto out_sleep; |
| 3509 | |
Eliad Peller | 1019975 | 2012-11-22 18:06:23 +0200 | [diff] [blame] | 3510 | wl->sched_vif = wlvif; |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3511 | |
| 3512 | out_sleep: |
| 3513 | wl1271_ps_elp_sleep(wl); |
| 3514 | out: |
| 3515 | mutex_unlock(&wl->mutex); |
| 3516 | return ret; |
| 3517 | } |
| 3518 | |
| 3519 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, |
| 3520 | struct ieee80211_vif *vif) |
| 3521 | { |
| 3522 | struct wl1271 *wl = hw->priv; |
Yoni Divinsky | 78f85f5 | 2012-05-16 11:34:17 +0300 | [diff] [blame] | 3523 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3524 | int ret; |
| 3525 | |
| 3526 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); |
| 3527 | |
| 3528 | mutex_lock(&wl->mutex); |
| 3529 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3530 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3531 | goto out; |
| 3532 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3533 | ret = wl1271_ps_elp_wakeup(wl); |
| 3534 | if (ret < 0) |
| 3535 | goto out; |
| 3536 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3537 | wl->ops->sched_scan_stop(wl, wlvif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3538 | |
| 3539 | wl1271_ps_elp_sleep(wl); |
| 3540 | out: |
| 3541 | mutex_unlock(&wl->mutex); |
| 3542 | } |
| 3543 | |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3544 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 3545 | { |
| 3546 | struct wl1271 *wl = hw->priv; |
| 3547 | int ret = 0; |
| 3548 | |
| 3549 | mutex_lock(&wl->mutex); |
| 3550 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3551 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3552 | ret = -EAGAIN; |
| 3553 | goto out; |
| 3554 | } |
| 3555 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3556 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3557 | if (ret < 0) |
| 3558 | goto out; |
| 3559 | |
Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 3560 | ret = wl1271_acx_frag_threshold(wl, value); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3561 | if (ret < 0) |
| 3562 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); |
| 3563 | |
| 3564 | wl1271_ps_elp_sleep(wl); |
| 3565 | |
| 3566 | out: |
| 3567 | mutex_unlock(&wl->mutex); |
| 3568 | |
| 3569 | return ret; |
| 3570 | } |
| 3571 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3572 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 3573 | { |
| 3574 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3575 | struct wl12xx_vif *wlvif; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3576 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3577 | |
| 3578 | mutex_lock(&wl->mutex); |
| 3579 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 3580 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3581 | ret = -EAGAIN; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3582 | goto out; |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3583 | } |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3584 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3585 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3586 | if (ret < 0) |
| 3587 | goto out; |
| 3588 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3589 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 3590 | ret = wl1271_acx_rts_threshold(wl, wlvif, value); |
| 3591 | if (ret < 0) |
| 3592 | wl1271_warning("set rts threshold failed: %d", ret); |
| 3593 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3594 | wl1271_ps_elp_sleep(wl); |
| 3595 | |
| 3596 | out: |
| 3597 | mutex_unlock(&wl->mutex); |
| 3598 | |
| 3599 | return ret; |
| 3600 | } |
| 3601 | |
Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3602 | static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset) |
| 3603 | { |
| 3604 | int len; |
| 3605 | const u8 *next, *end = skb->data + skb->len; |
| 3606 | u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset, |
| 3607 | skb->len - ieoffset); |
| 3608 | if (!ie) |
| 3609 | return; |
| 3610 | len = ie[1] + 2; |
| 3611 | next = ie + len; |
| 3612 | memmove(ie, next, end - next); |
| 3613 | skb_trim(skb, skb->len - len); |
| 3614 | } |
| 3615 | |
Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3616 | static void wl12xx_remove_vendor_ie(struct sk_buff *skb, |
| 3617 | unsigned int oui, u8 oui_type, |
| 3618 | int ieoffset) |
| 3619 | { |
| 3620 | int len; |
| 3621 | const u8 *next, *end = skb->data + skb->len; |
| 3622 | u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 3623 | skb->data + ieoffset, |
| 3624 | skb->len - ieoffset); |
| 3625 | if (!ie) |
| 3626 | return; |
| 3627 | len = ie[1] + 2; |
| 3628 | next = ie + len; |
| 3629 | memmove(ie, next, end - next); |
| 3630 | skb_trim(skb, skb->len - len); |
| 3631 | } |
| 3632 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3633 | static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates, |
| 3634 | struct ieee80211_vif *vif) |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3635 | { |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3636 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3637 | struct sk_buff *skb; |
| 3638 | int ret; |
| 3639 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3640 | skb = ieee80211_proberesp_get(wl->hw, vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3641 | if (!skb) |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3642 | return -EOPNOTSUPP; |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3643 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3644 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3645 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3646 | skb->data, |
| 3647 | skb->len, 0, |
| 3648 | rates); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3649 | dev_kfree_skb(skb); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3650 | |
| 3651 | if (ret < 0) |
| 3652 | goto out; |
| 3653 | |
| 3654 | wl1271_debug(DEBUG_AP, "probe response updated"); |
| 3655 | set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags); |
| 3656 | |
| 3657 | out: |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3658 | return ret; |
| 3659 | } |
| 3660 | |
| 3661 | static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl, |
| 3662 | struct ieee80211_vif *vif, |
| 3663 | u8 *probe_rsp_data, |
| 3664 | size_t probe_rsp_len, |
| 3665 | u32 rates) |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3666 | { |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3667 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3668 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3669 | u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; |
| 3670 | int ssid_ie_offset, ie_offset, templ_len; |
| 3671 | const u8 *ptr; |
| 3672 | |
| 3673 | /* no need to change probe response if the SSID is set correctly */ |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3674 | if (wlvif->ssid_len > 0) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3675 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3676 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3677 | probe_rsp_data, |
| 3678 | probe_rsp_len, 0, |
| 3679 | rates); |
| 3680 | |
| 3681 | if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) { |
| 3682 | wl1271_error("probe_rsp template too big"); |
| 3683 | return -EINVAL; |
| 3684 | } |
| 3685 | |
| 3686 | /* start searching from IE offset */ |
| 3687 | ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 3688 | |
| 3689 | ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset, |
| 3690 | probe_rsp_len - ie_offset); |
| 3691 | if (!ptr) { |
| 3692 | wl1271_error("No SSID in beacon!"); |
| 3693 | return -EINVAL; |
| 3694 | } |
| 3695 | |
| 3696 | ssid_ie_offset = ptr - probe_rsp_data; |
| 3697 | ptr += (ptr[1] + 2); |
| 3698 | |
| 3699 | memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset); |
| 3700 | |
| 3701 | /* insert SSID from bss_conf */ |
| 3702 | probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID; |
| 3703 | probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len; |
| 3704 | memcpy(probe_rsp_templ + ssid_ie_offset + 2, |
| 3705 | bss_conf->ssid, bss_conf->ssid_len); |
| 3706 | templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len; |
| 3707 | |
| 3708 | memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len, |
| 3709 | ptr, probe_rsp_len - (ptr - probe_rsp_data)); |
| 3710 | templ_len += probe_rsp_len - (ptr - probe_rsp_data); |
| 3711 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3712 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3713 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3714 | probe_rsp_templ, |
| 3715 | templ_len, 0, |
| 3716 | rates); |
| 3717 | } |
| 3718 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3719 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3720 | struct ieee80211_vif *vif, |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3721 | struct ieee80211_bss_conf *bss_conf, |
| 3722 | u32 changed) |
| 3723 | { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3724 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3725 | int ret = 0; |
| 3726 | |
| 3727 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 3728 | if (bss_conf->use_short_slot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3729 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3730 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3731 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3732 | if (ret < 0) { |
| 3733 | wl1271_warning("Set slot time failed %d", ret); |
| 3734 | goto out; |
| 3735 | } |
| 3736 | } |
| 3737 | |
| 3738 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 3739 | if (bss_conf->use_short_preamble) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3740 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3741 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3742 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 3746 | if (bss_conf->use_cts_prot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3747 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3748 | CTSPROTECT_ENABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3749 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3750 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3751 | CTSPROTECT_DISABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3752 | if (ret < 0) { |
| 3753 | wl1271_warning("Set ctsprotect failed %d", ret); |
| 3754 | goto out; |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | out: |
| 3759 | return ret; |
| 3760 | } |
| 3761 | |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3762 | static int wlcore_set_beacon_template(struct wl1271 *wl, |
| 3763 | struct ieee80211_vif *vif, |
| 3764 | bool is_ap) |
| 3765 | { |
| 3766 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3767 | struct ieee80211_hdr *hdr; |
| 3768 | u32 min_rate; |
| 3769 | int ret; |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame^] | 3770 | int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3771 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); |
| 3772 | u16 tmpl_id; |
| 3773 | |
| 3774 | if (!beacon) { |
| 3775 | ret = -EINVAL; |
| 3776 | goto out; |
| 3777 | } |
| 3778 | |
| 3779 | wl1271_debug(DEBUG_MASTER, "beacon updated"); |
| 3780 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 3781 | ret = wl1271_ssid_set(wlvif, beacon, ieoffset); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3782 | if (ret < 0) { |
| 3783 | dev_kfree_skb(beacon); |
| 3784 | goto out; |
| 3785 | } |
| 3786 | min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 3787 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : |
| 3788 | CMD_TEMPL_BEACON; |
| 3789 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id, |
| 3790 | beacon->data, |
| 3791 | beacon->len, 0, |
| 3792 | min_rate); |
| 3793 | if (ret < 0) { |
| 3794 | dev_kfree_skb(beacon); |
| 3795 | goto out; |
| 3796 | } |
| 3797 | |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 3798 | wlvif->wmm_enabled = |
| 3799 | cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
| 3800 | WLAN_OUI_TYPE_MICROSOFT_WMM, |
| 3801 | beacon->data + ieoffset, |
| 3802 | beacon->len - ieoffset); |
| 3803 | |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3804 | /* |
| 3805 | * In case we already have a probe-resp beacon set explicitly |
| 3806 | * by usermode, don't use the beacon data. |
| 3807 | */ |
| 3808 | if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags)) |
| 3809 | goto end_bcn; |
| 3810 | |
| 3811 | /* remove TIM ie from probe response */ |
| 3812 | wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); |
| 3813 | |
| 3814 | /* |
| 3815 | * remove p2p ie from probe response. |
| 3816 | * the fw reponds to probe requests that don't include |
| 3817 | * the p2p ie. probe requests with p2p ie will be passed, |
| 3818 | * and will be responded by the supplicant (the spec |
| 3819 | * forbids including the p2p ie when responding to probe |
| 3820 | * requests that didn't include it). |
| 3821 | */ |
| 3822 | wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA, |
| 3823 | WLAN_OUI_TYPE_WFA_P2P, ieoffset); |
| 3824 | |
| 3825 | hdr = (struct ieee80211_hdr *) beacon->data; |
| 3826 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 3827 | IEEE80211_STYPE_PROBE_RESP); |
| 3828 | if (is_ap) |
| 3829 | ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif, |
| 3830 | beacon->data, |
| 3831 | beacon->len, |
| 3832 | min_rate); |
| 3833 | else |
| 3834 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 3835 | CMD_TEMPL_PROBE_RESPONSE, |
| 3836 | beacon->data, |
| 3837 | beacon->len, 0, |
| 3838 | min_rate); |
| 3839 | end_bcn: |
| 3840 | dev_kfree_skb(beacon); |
| 3841 | if (ret < 0) |
| 3842 | goto out; |
| 3843 | |
| 3844 | out: |
| 3845 | return ret; |
| 3846 | } |
| 3847 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3848 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, |
| 3849 | struct ieee80211_vif *vif, |
| 3850 | struct ieee80211_bss_conf *bss_conf, |
| 3851 | u32 changed) |
| 3852 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3853 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3854 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3855 | int ret = 0; |
| 3856 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 3857 | if (changed & BSS_CHANGED_BEACON_INT) { |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3858 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", |
| 3859 | bss_conf->beacon_int); |
| 3860 | |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 3861 | wlvif->beacon_int = bss_conf->beacon_int; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3862 | } |
| 3863 | |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3864 | if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { |
| 3865 | u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3866 | |
| 3867 | wl1271_ap_set_probe_resp_tmpl(wl, rate, vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3868 | } |
| 3869 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 3870 | if (changed & BSS_CHANGED_BEACON) { |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3871 | ret = wlcore_set_beacon_template(wl, vif, is_ap); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3872 | if (ret < 0) |
| 3873 | goto out; |
| 3874 | } |
| 3875 | |
| 3876 | out: |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3877 | if (ret != 0) |
| 3878 | wl1271_error("beacon info change failed: %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3879 | return ret; |
| 3880 | } |
| 3881 | |
| 3882 | /* AP mode changes */ |
| 3883 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3884 | struct ieee80211_vif *vif, |
| 3885 | struct ieee80211_bss_conf *bss_conf, |
| 3886 | u32 changed) |
| 3887 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3888 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3889 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3890 | |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 3891 | if (changed & BSS_CHANGED_BASIC_RATES) { |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3892 | u32 rates = bss_conf->basic_rates; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3893 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3894 | wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3895 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3896 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3897 | wlvif->basic_rate_set); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3898 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3899 | ret = wl1271_init_ap_rates(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3900 | if (ret < 0) { |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 3901 | wl1271_error("AP rate policy change failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3902 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3903 | } |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3904 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3905 | ret = wl1271_ap_init_templates(wl, vif); |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3906 | if (ret < 0) |
| 3907 | goto out; |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3908 | |
| 3909 | ret = wl1271_ap_set_probe_resp_tmpl(wl, wlvif->basic_rate, vif); |
| 3910 | if (ret < 0) |
| 3911 | goto out; |
| 3912 | |
| 3913 | ret = wlcore_set_beacon_template(wl, vif, true); |
| 3914 | if (ret < 0) |
| 3915 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3916 | } |
| 3917 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3918 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); |
| 3919 | if (ret < 0) |
| 3920 | goto out; |
| 3921 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 3922 | if (changed & BSS_CHANGED_BEACON_ENABLED) { |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3923 | if (bss_conf->enable_beacon) { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3924 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3925 | ret = wl12xx_cmd_role_start_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3926 | if (ret < 0) |
| 3927 | goto out; |
| 3928 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3929 | ret = wl1271_ap_init_hwenc(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3930 | if (ret < 0) |
| 3931 | goto out; |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3932 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3933 | set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3934 | wl1271_debug(DEBUG_AP, "started AP"); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3935 | } |
| 3936 | } else { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3937 | if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3938 | ret = wl12xx_cmd_role_stop_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3939 | if (ret < 0) |
| 3940 | goto out; |
| 3941 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3942 | clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3943 | clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, |
| 3944 | &wlvif->flags); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3945 | wl1271_debug(DEBUG_AP, "stopped AP"); |
| 3946 | } |
| 3947 | } |
| 3948 | } |
| 3949 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3950 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3951 | if (ret < 0) |
| 3952 | goto out; |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3953 | |
| 3954 | /* Handle HT information change */ |
| 3955 | if ((changed & BSS_CHANGED_HT) && |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 3956 | (bss_conf->chandef.width != NL80211_CHAN_WIDTH_20_NOHT)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3957 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3958 | bss_conf->ht_operation_mode); |
| 3959 | if (ret < 0) { |
| 3960 | wl1271_warning("Set ht information failed %d", ret); |
| 3961 | goto out; |
| 3962 | } |
| 3963 | } |
| 3964 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3965 | out: |
| 3966 | return; |
| 3967 | } |
| 3968 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 3969 | static int wlcore_set_bssid(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 3970 | struct ieee80211_bss_conf *bss_conf, |
| 3971 | u32 sta_rate_set) |
| 3972 | { |
| 3973 | u32 rates; |
| 3974 | int ret; |
| 3975 | |
| 3976 | wl1271_debug(DEBUG_MAC80211, |
| 3977 | "changed_bssid: %pM, aid: %d, bcn_int: %d, brates: 0x%x sta_rate_set: 0x%x", |
| 3978 | bss_conf->bssid, bss_conf->aid, |
| 3979 | bss_conf->beacon_int, |
| 3980 | bss_conf->basic_rates, sta_rate_set); |
| 3981 | |
| 3982 | wlvif->beacon_int = bss_conf->beacon_int; |
| 3983 | rates = bss_conf->basic_rates; |
| 3984 | wlvif->basic_rate_set = |
| 3985 | wl1271_tx_enabled_rates_get(wl, rates, |
| 3986 | wlvif->band); |
| 3987 | wlvif->basic_rate = |
| 3988 | wl1271_tx_min_rate_get(wl, |
| 3989 | wlvif->basic_rate_set); |
| 3990 | |
| 3991 | if (sta_rate_set) |
| 3992 | wlvif->rate_set = |
| 3993 | wl1271_tx_enabled_rates_get(wl, |
| 3994 | sta_rate_set, |
| 3995 | wlvif->band); |
| 3996 | |
| 3997 | /* we only support sched_scan while not connected */ |
Eliad Peller | 1019975 | 2012-11-22 18:06:23 +0200 | [diff] [blame] | 3998 | if (wl->sched_vif == wlvif) |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 3999 | wl->ops->sched_scan_stop(wl, wlvif); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4000 | |
| 4001 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4002 | if (ret < 0) |
| 4003 | return ret; |
| 4004 | |
| 4005 | ret = wl12xx_cmd_build_null_data(wl, wlvif); |
| 4006 | if (ret < 0) |
| 4007 | return ret; |
| 4008 | |
| 4009 | ret = wl1271_build_qos_null_data(wl, wl12xx_wlvif_to_vif(wlvif)); |
| 4010 | if (ret < 0) |
| 4011 | return ret; |
| 4012 | |
| 4013 | wlcore_set_ssid(wl, wlvif); |
| 4014 | |
| 4015 | set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
| 4016 | |
| 4017 | return 0; |
| 4018 | } |
| 4019 | |
| 4020 | static int wlcore_clear_bssid(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 4021 | { |
| 4022 | int ret; |
| 4023 | |
| 4024 | /* revert back to minimum rates for the current band */ |
| 4025 | wl1271_set_band_rate(wl, wlvif); |
| 4026 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 4027 | |
| 4028 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4029 | if (ret < 0) |
| 4030 | return ret; |
| 4031 | |
| 4032 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 4033 | test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags)) { |
| 4034 | ret = wl12xx_cmd_role_stop_sta(wl, wlvif); |
| 4035 | if (ret < 0) |
| 4036 | return ret; |
| 4037 | } |
| 4038 | |
| 4039 | clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
| 4040 | return 0; |
| 4041 | } |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4042 | /* STA/IBSS mode changes */ |
| 4043 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, |
| 4044 | struct ieee80211_vif *vif, |
| 4045 | struct ieee80211_bss_conf *bss_conf, |
| 4046 | u32 changed) |
| 4047 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 4048 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4049 | bool do_join = false; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4050 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4051 | bool ibss_joined = false; |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4052 | u32 sta_rate_set = 0; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4053 | int ret; |
Luciano Coelho | 2d6e4e76 | 2011-01-11 19:07:21 +0100 | [diff] [blame] | 4054 | struct ieee80211_sta *sta; |
Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 4055 | bool sta_exists = false; |
| 4056 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4057 | |
| 4058 | if (is_ibss) { |
| 4059 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, |
| 4060 | changed); |
| 4061 | if (ret < 0) |
| 4062 | goto out; |
| 4063 | } |
| 4064 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4065 | if (changed & BSS_CHANGED_IBSS) { |
| 4066 | if (bss_conf->ibss_joined) { |
Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 4067 | set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4068 | ibss_joined = true; |
| 4069 | } else { |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4070 | wlcore_unset_assoc(wl, wlvif); |
| 4071 | wl12xx_cmd_role_stop_sta(wl, wlvif); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4076 | do_join = true; |
| 4077 | |
| 4078 | /* Need to update the SSID (for filtering etc) */ |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4079 | if ((changed & BSS_CHANGED_BEACON) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4080 | do_join = true; |
| 4081 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 4082 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) { |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 4083 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", |
| 4084 | bss_conf->enable_beacon ? "enabled" : "disabled"); |
| 4085 | |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 4086 | do_join = true; |
| 4087 | } |
| 4088 | |
Luciano Coelho | 48af2eb | 2012-11-20 11:03:32 +0200 | [diff] [blame] | 4089 | if (changed & BSS_CHANGED_CQM) { |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 4090 | bool enable = false; |
| 4091 | if (bss_conf->cqm_rssi_thold) |
| 4092 | enable = true; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4093 | ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable, |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 4094 | bss_conf->cqm_rssi_thold, |
| 4095 | bss_conf->cqm_rssi_hyst); |
| 4096 | if (ret < 0) |
| 4097 | goto out; |
Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 4098 | wlvif->rssi_thold = bss_conf->cqm_rssi_thold; |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 4099 | } |
| 4100 | |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 4101 | if (changed & (BSS_CHANGED_BSSID | BSS_CHANGED_HT | |
| 4102 | BSS_CHANGED_ASSOC)) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4103 | rcu_read_lock(); |
| 4104 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
Luciano Coelho | ef08d02 | 2012-11-20 11:03:31 +0200 | [diff] [blame] | 4105 | if (sta) { |
| 4106 | u8 *rx_mask = sta->ht_cap.mcs.rx_mask; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4107 | |
Luciano Coelho | ef08d02 | 2012-11-20 11:03:31 +0200 | [diff] [blame] | 4108 | /* save the supp_rates of the ap */ |
| 4109 | sta_rate_set = sta->supp_rates[wlvif->band]; |
| 4110 | if (sta->ht_cap.ht_supported) |
| 4111 | sta_rate_set |= |
| 4112 | (rx_mask[0] << HW_HT_RATES_OFFSET) | |
| 4113 | (rx_mask[1] << HW_MIMO_RATES_OFFSET); |
| 4114 | sta_ht_cap = sta->ht_cap; |
| 4115 | sta_exists = true; |
| 4116 | } |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4117 | |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4118 | rcu_read_unlock(); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4119 | } |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 4120 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4121 | if (changed & BSS_CHANGED_BSSID) { |
| 4122 | if (!is_zero_ether_addr(bss_conf->bssid)) { |
| 4123 | ret = wlcore_set_bssid(wl, wlvif, bss_conf, |
| 4124 | sta_rate_set); |
| 4125 | if (ret < 0) |
| 4126 | goto out; |
| 4127 | |
| 4128 | /* Need to update the BSSID (for filtering etc) */ |
Eliad Peller | 446f5ca | 2012-03-12 14:53:04 +0200 | [diff] [blame] | 4129 | do_join = true; |
Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 4130 | } else { |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4131 | ret = wlcore_clear_bssid(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 4132 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4133 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4134 | } |
| 4135 | } |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 4136 | |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 4137 | if (changed & BSS_CHANGED_IBSS) { |
| 4138 | wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", |
| 4139 | bss_conf->ibss_joined); |
| 4140 | |
| 4141 | if (bss_conf->ibss_joined) { |
| 4142 | u32 rates = bss_conf->basic_rates; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 4143 | wlvif->basic_rate_set = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4144 | wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4145 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 4146 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 4147 | wl1271_tx_min_rate_get(wl, |
| 4148 | wlvif->basic_rate_set); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 4149 | |
Shahar Levi | 06b660e | 2011-09-05 13:54:36 +0300 | [diff] [blame] | 4150 | /* by default, use 11b + OFDM rates */ |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 4151 | wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES; |
| 4152 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 4153 | if (ret < 0) |
| 4154 | goto out; |
| 4155 | } |
| 4156 | } |
| 4157 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4158 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4159 | if (ret < 0) |
| 4160 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4161 | |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 4162 | if (do_join) { |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4163 | ret = wlcore_join(wl, wlvif); |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 4164 | if (ret < 0) { |
| 4165 | wl1271_warning("cmd join failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4166 | goto out; |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 4167 | } |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4168 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 4169 | |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4170 | if (changed & BSS_CHANGED_ASSOC) { |
| 4171 | if (bss_conf->assoc) { |
Eliad Peller | ec87011 | 2012-11-20 13:20:09 +0200 | [diff] [blame] | 4172 | ret = wlcore_set_assoc(wl, wlvif, bss_conf, |
| 4173 | sta_rate_set); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 4174 | if (ret < 0) |
| 4175 | goto out; |
| 4176 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4177 | if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags)) |
| 4178 | wl12xx_set_authorized(wl, wlvif); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4179 | } else { |
| 4180 | wlcore_unset_assoc(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 4181 | } |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 4182 | } |
| 4183 | |
Eliad Peller | 518b680 | 2012-11-26 18:05:47 +0200 | [diff] [blame] | 4184 | if (changed & BSS_CHANGED_PS) { |
| 4185 | if ((bss_conf->ps) && |
| 4186 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
| 4187 | !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
| 4188 | int ps_mode; |
| 4189 | char *ps_mode_str; |
| 4190 | |
| 4191 | if (wl->conf.conn.forced_ps) { |
| 4192 | ps_mode = STATION_POWER_SAVE_MODE; |
| 4193 | ps_mode_str = "forced"; |
| 4194 | } else { |
| 4195 | ps_mode = STATION_AUTO_PS_MODE; |
| 4196 | ps_mode_str = "auto"; |
| 4197 | } |
| 4198 | |
| 4199 | wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str); |
| 4200 | |
| 4201 | ret = wl1271_ps_set_mode(wl, wlvif, ps_mode); |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4202 | if (ret < 0) |
Eliad Peller | 518b680 | 2012-11-26 18:05:47 +0200 | [diff] [blame] | 4203 | wl1271_warning("enter %s ps failed %d", |
| 4204 | ps_mode_str, ret); |
| 4205 | } else if (!bss_conf->ps && |
| 4206 | test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
| 4207 | wl1271_debug(DEBUG_PSM, "auto ps disabled"); |
| 4208 | |
| 4209 | ret = wl1271_ps_set_mode(wl, wlvif, |
| 4210 | STATION_ACTIVE_MODE); |
| 4211 | if (ret < 0) |
| 4212 | wl1271_warning("exit auto ps failed %d", ret); |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4213 | } |
| 4214 | } |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4215 | |
| 4216 | /* Handle new association with HT. Do this after join. */ |
Eliad Peller | 58321b2 | 2012-11-20 13:20:10 +0200 | [diff] [blame] | 4217 | if (sta_exists && |
| 4218 | (changed & BSS_CHANGED_HT)) { |
| 4219 | bool enabled = |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4220 | bss_conf->chandef.width != NL80211_CHAN_WIDTH_20_NOHT; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4221 | |
Eliad Peller | 530abe1 | 2012-11-28 11:42:31 +0200 | [diff] [blame] | 4222 | ret = wlcore_hw_set_peer_cap(wl, |
| 4223 | &sta_ht_cap, |
| 4224 | enabled, |
| 4225 | wlvif->rate_set, |
| 4226 | wlvif->sta.hlid); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4227 | if (ret < 0) { |
Eliad Peller | 58321b2 | 2012-11-20 13:20:10 +0200 | [diff] [blame] | 4228 | wl1271_warning("Set ht cap failed %d", ret); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4229 | goto out; |
Eliad Peller | 58321b2 | 2012-11-20 13:20:10 +0200 | [diff] [blame] | 4230 | |
| 4231 | } |
| 4232 | |
| 4233 | if (enabled) { |
| 4234 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
| 4235 | bss_conf->ht_operation_mode); |
| 4236 | if (ret < 0) { |
| 4237 | wl1271_warning("Set ht information failed %d", |
| 4238 | ret); |
| 4239 | goto out; |
| 4240 | } |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4241 | } |
| 4242 | } |
| 4243 | |
Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 4244 | /* Handle arp filtering. Done after join. */ |
| 4245 | if ((changed & BSS_CHANGED_ARP_FILTER) || |
| 4246 | (!is_ibss && (changed & BSS_CHANGED_QOS))) { |
| 4247 | __be32 addr = bss_conf->arp_addr_list[0]; |
| 4248 | wlvif->sta.qos = bss_conf->qos; |
| 4249 | WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS); |
| 4250 | |
Johannes Berg | 0f19b41 | 2013-01-14 16:39:07 +0100 | [diff] [blame] | 4251 | if (bss_conf->arp_addr_cnt == 1 && bss_conf->assoc) { |
Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 4252 | wlvif->ip_addr = addr; |
| 4253 | /* |
| 4254 | * The template should have been configured only upon |
| 4255 | * association. however, it seems that the correct ip |
| 4256 | * isn't being set (when sending), so we have to |
| 4257 | * reconfigure the template upon every ip change. |
| 4258 | */ |
| 4259 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 4260 | if (ret < 0) { |
| 4261 | wl1271_warning("build arp rsp failed: %d", ret); |
| 4262 | goto out; |
| 4263 | } |
| 4264 | |
| 4265 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, |
| 4266 | (ACX_ARP_FILTER_ARP_FILTERING | |
| 4267 | ACX_ARP_FILTER_AUTO_ARP), |
| 4268 | addr); |
| 4269 | } else { |
| 4270 | wlvif->ip_addr = 0; |
| 4271 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr); |
| 4272 | } |
| 4273 | |
| 4274 | if (ret < 0) |
| 4275 | goto out; |
| 4276 | } |
| 4277 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4278 | out: |
| 4279 | return; |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4280 | } |
| 4281 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4282 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, |
| 4283 | struct ieee80211_vif *vif, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4284 | struct ieee80211_bss_conf *bss_conf, |
| 4285 | u32 changed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4286 | { |
| 4287 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4288 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4289 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4290 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4291 | |
Eliad Peller | d3f5a1b | 2012-11-19 17:14:05 +0200 | [diff] [blame] | 4292 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info role %d changed 0x%x", |
| 4293 | wlvif->role_id, (int)changed); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4294 | |
Arik Nemtsov | 6b8bf5b | 2012-05-15 17:08:54 +0300 | [diff] [blame] | 4295 | /* |
| 4296 | * make sure to cancel pending disconnections if our association |
| 4297 | * state changed |
| 4298 | */ |
| 4299 | if (!is_ap && (changed & BSS_CHANGED_ASSOC)) |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4300 | cancel_delayed_work_sync(&wlvif->connection_loss_work); |
Arik Nemtsov | 6b8bf5b | 2012-05-15 17:08:54 +0300 | [diff] [blame] | 4301 | |
Eliad Peller | b515d83 | 2012-05-15 17:08:56 +0300 | [diff] [blame] | 4302 | if (is_ap && (changed & BSS_CHANGED_BEACON_ENABLED) && |
| 4303 | !bss_conf->enable_beacon) |
| 4304 | wl1271_tx_flush(wl); |
| 4305 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4306 | mutex_lock(&wl->mutex); |
| 4307 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4308 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4309 | goto out; |
| 4310 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 4311 | if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))) |
| 4312 | goto out; |
| 4313 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4314 | ret = wl1271_ps_elp_wakeup(wl); |
| 4315 | if (ret < 0) |
| 4316 | goto out; |
| 4317 | |
| 4318 | if (is_ap) |
| 4319 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); |
| 4320 | else |
| 4321 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); |
| 4322 | |
| 4323 | wl1271_ps_elp_sleep(wl); |
| 4324 | |
| 4325 | out: |
| 4326 | mutex_unlock(&wl->mutex); |
| 4327 | } |
| 4328 | |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4329 | static int wlcore_op_add_chanctx(struct ieee80211_hw *hw, |
| 4330 | struct ieee80211_chanctx_conf *ctx) |
| 4331 | { |
| 4332 | wl1271_debug(DEBUG_MAC80211, "mac80211 add chanctx %d (type %d)", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4333 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4334 | cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4335 | return 0; |
| 4336 | } |
| 4337 | |
| 4338 | static void wlcore_op_remove_chanctx(struct ieee80211_hw *hw, |
| 4339 | struct ieee80211_chanctx_conf *ctx) |
| 4340 | { |
| 4341 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove chanctx %d (type %d)", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4342 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4343 | cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | static void wlcore_op_change_chanctx(struct ieee80211_hw *hw, |
| 4347 | struct ieee80211_chanctx_conf *ctx, |
| 4348 | u32 changed) |
| 4349 | { |
| 4350 | wl1271_debug(DEBUG_MAC80211, |
| 4351 | "mac80211 change chanctx %d (type %d) changed 0x%x", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4352 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4353 | cfg80211_get_chandef_type(&ctx->def), changed); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | static int wlcore_op_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 4357 | struct ieee80211_vif *vif, |
| 4358 | struct ieee80211_chanctx_conf *ctx) |
| 4359 | { |
| 4360 | struct wl1271 *wl = hw->priv; |
| 4361 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4362 | int channel = ieee80211_frequency_to_channel( |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4363 | ctx->def.chan->center_freq); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4364 | |
| 4365 | wl1271_debug(DEBUG_MAC80211, |
| 4366 | "mac80211 assign chanctx (role %d) %d (type %d)", |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4367 | wlvif->role_id, channel, cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4368 | |
| 4369 | mutex_lock(&wl->mutex); |
| 4370 | |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4371 | wlvif->band = ctx->def.chan->band; |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4372 | wlvif->channel = channel; |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4373 | wlvif->channel_type = cfg80211_get_chandef_type(&ctx->def); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4374 | |
| 4375 | /* update default rates according to the band */ |
| 4376 | wl1271_set_band_rate(wl, wlvif); |
| 4377 | |
| 4378 | mutex_unlock(&wl->mutex); |
| 4379 | |
| 4380 | return 0; |
| 4381 | } |
| 4382 | |
| 4383 | static void wlcore_op_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 4384 | struct ieee80211_vif *vif, |
| 4385 | struct ieee80211_chanctx_conf *ctx) |
| 4386 | { |
| 4387 | struct wl1271 *wl = hw->priv; |
| 4388 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4389 | |
| 4390 | wl1271_debug(DEBUG_MAC80211, |
| 4391 | "mac80211 unassign chanctx (role %d) %d (type %d)", |
| 4392 | wlvif->role_id, |
Luciano Coelho | aaabee8 | 2012-12-04 16:39:47 +0200 | [diff] [blame] | 4393 | ieee80211_frequency_to_channel(ctx->def.chan->center_freq), |
| 4394 | cfg80211_get_chandef_type(&ctx->def)); |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 4395 | |
| 4396 | wl1271_tx_flush(wl); |
| 4397 | } |
| 4398 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 4399 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, |
| 4400 | struct ieee80211_vif *vif, u16 queue, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4401 | const struct ieee80211_tx_queue_params *params) |
| 4402 | { |
| 4403 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4404 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4405 | u8 ps_scheme; |
| 4406 | int ret = 0; |
| 4407 | |
| 4408 | mutex_lock(&wl->mutex); |
| 4409 | |
| 4410 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); |
| 4411 | |
| 4412 | if (params->uapsd) |
| 4413 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; |
| 4414 | else |
| 4415 | ps_scheme = CONF_PS_SCHEME_LEGACY; |
| 4416 | |
Eliad Peller | 5b37ddf | 2011-12-18 20:25:40 +0200 | [diff] [blame] | 4417 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4418 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4419 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4420 | ret = wl1271_ps_elp_wakeup(wl); |
| 4421 | if (ret < 0) |
| 4422 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4423 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4424 | /* |
| 4425 | * the txop is confed in units of 32us by the mac80211, |
| 4426 | * we need us |
| 4427 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4428 | ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4429 | params->cw_min, params->cw_max, |
| 4430 | params->aifs, params->txop << 5); |
| 4431 | if (ret < 0) |
| 4432 | goto out_sleep; |
| 4433 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4434 | ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4435 | CONF_CHANNEL_TYPE_EDCF, |
| 4436 | wl1271_tx_get_queue(queue), |
| 4437 | ps_scheme, CONF_ACK_POLICY_LEGACY, |
| 4438 | 0, 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4439 | |
| 4440 | out_sleep: |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4441 | wl1271_ps_elp_sleep(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4442 | |
| 4443 | out: |
| 4444 | mutex_unlock(&wl->mutex); |
| 4445 | |
| 4446 | return ret; |
| 4447 | } |
| 4448 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 4449 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw, |
| 4450 | struct ieee80211_vif *vif) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4451 | { |
| 4452 | |
| 4453 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4454 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4455 | u64 mactime = ULLONG_MAX; |
| 4456 | int ret; |
| 4457 | |
| 4458 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); |
| 4459 | |
| 4460 | mutex_lock(&wl->mutex); |
| 4461 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4462 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4463 | goto out; |
| 4464 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4465 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4466 | if (ret < 0) |
| 4467 | goto out; |
| 4468 | |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4469 | ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4470 | if (ret < 0) |
| 4471 | goto out_sleep; |
| 4472 | |
| 4473 | out_sleep: |
| 4474 | wl1271_ps_elp_sleep(wl); |
| 4475 | |
| 4476 | out: |
| 4477 | mutex_unlock(&wl->mutex); |
| 4478 | return mactime; |
| 4479 | } |
| 4480 | |
| 4481 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, |
| 4482 | struct survey_info *survey) |
| 4483 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4484 | struct ieee80211_conf *conf = &hw->conf; |
| 4485 | |
| 4486 | if (idx != 0) |
| 4487 | return -ENOENT; |
| 4488 | |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 4489 | survey->channel = conf->chandef.chan; |
Yoni Divinsky | add779a0 | 2012-06-13 18:56:54 +0300 | [diff] [blame] | 4490 | survey->filled = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4491 | return 0; |
| 4492 | } |
| 4493 | |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4494 | static int wl1271_allocate_sta(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4495 | struct wl12xx_vif *wlvif, |
| 4496 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4497 | { |
| 4498 | struct wl1271_station *wl_sta; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4499 | int ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4500 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4501 | |
| 4502 | if (wl->active_sta_count >= AP_MAX_STATIONS) { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4503 | wl1271_warning("could not allocate HLID - too much stations"); |
| 4504 | return -EBUSY; |
| 4505 | } |
| 4506 | |
| 4507 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4508 | ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid); |
| 4509 | if (ret < 0) { |
| 4510 | wl1271_warning("could not allocate HLID - too many links"); |
| 4511 | return -EBUSY; |
| 4512 | } |
| 4513 | |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 4514 | /* use the previous security seq, if this is a recovery/resume */ |
| 4515 | wl->links[wl_sta->hlid].total_freed_pkts = wl_sta->total_freed_pkts; |
| 4516 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4517 | set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4518 | memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4519 | wl->active_sta_count++; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4520 | return 0; |
| 4521 | } |
| 4522 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4523 | 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] | 4524 | { |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 4525 | struct wl1271_station *wl_sta; |
| 4526 | struct ieee80211_sta *sta; |
| 4527 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 4528 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4529 | if (!test_bit(hlid, wlvif->ap.sta_hlid_map)) |
Arik Nemtsov | f1acea9 | 2011-08-25 12:43:17 +0300 | [diff] [blame] | 4530 | return; |
| 4531 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4532 | clear_bit(hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4533 | __clear_bit(hlid, &wl->ap_ps_map); |
| 4534 | __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 4535 | |
| 4536 | /* |
| 4537 | * save the last used PN in the private part of iee80211_sta, |
| 4538 | * in case of recovery/suspend |
| 4539 | */ |
| 4540 | rcu_read_lock(); |
| 4541 | sta = ieee80211_find_sta(vif, wl->links[hlid].addr); |
| 4542 | if (sta) { |
| 4543 | wl_sta = (void *)sta->drv_priv; |
| 4544 | wl_sta->total_freed_pkts = wl->links[hlid].total_freed_pkts; |
| 4545 | |
| 4546 | /* |
| 4547 | * increment the initial seq number on recovery to account for |
| 4548 | * transmitted packets that we haven't yet got in the FW status |
| 4549 | */ |
| 4550 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 4551 | wl_sta->total_freed_pkts += |
| 4552 | WL1271_TX_SQN_POST_RECOVERY_PADDING; |
| 4553 | } |
| 4554 | rcu_read_unlock(); |
| 4555 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4556 | wl12xx_free_link(wl, wlvif, &hlid); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4557 | wl->active_sta_count--; |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 4558 | |
| 4559 | /* |
| 4560 | * rearm the tx watchdog when the last STA is freed - give the FW a |
| 4561 | * chance to return STA-buffered packets before complaining. |
| 4562 | */ |
| 4563 | if (wl->active_sta_count == 0) |
| 4564 | wl12xx_rearm_tx_watchdog_locked(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4565 | } |
| 4566 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4567 | static int wl12xx_sta_add(struct wl1271 *wl, |
| 4568 | struct wl12xx_vif *wlvif, |
| 4569 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4570 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4571 | struct wl1271_station *wl_sta; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4572 | int ret = 0; |
| 4573 | u8 hlid; |
| 4574 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4575 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); |
| 4576 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4577 | ret = wl1271_allocate_sta(wl, wlvif, sta); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4578 | if (ret < 0) |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4579 | return ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4580 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4581 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4582 | hlid = wl_sta->hlid; |
| 4583 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4584 | ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4585 | if (ret < 0) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4586 | wl1271_free_sta(wl, wlvif, hlid); |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4587 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4588 | return ret; |
| 4589 | } |
| 4590 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4591 | static int wl12xx_sta_remove(struct wl1271 *wl, |
| 4592 | struct wl12xx_vif *wlvif, |
| 4593 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4594 | { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4595 | struct wl1271_station *wl_sta; |
| 4596 | int ret = 0, id; |
| 4597 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4598 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); |
| 4599 | |
| 4600 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4601 | id = wl_sta->hlid; |
| 4602 | if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map))) |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4603 | return -EINVAL; |
| 4604 | |
| 4605 | ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid); |
| 4606 | if (ret < 0) |
| 4607 | return ret; |
| 4608 | |
| 4609 | wl1271_free_sta(wl, wlvif, wl_sta->hlid); |
| 4610 | return ret; |
| 4611 | } |
| 4612 | |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4613 | static void wlcore_roc_if_possible(struct wl1271 *wl, |
| 4614 | struct wl12xx_vif *wlvif) |
| 4615 | { |
| 4616 | if (find_first_bit(wl->roc_map, |
| 4617 | WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) |
| 4618 | return; |
| 4619 | |
| 4620 | if (WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID)) |
| 4621 | return; |
| 4622 | |
| 4623 | wl12xx_roc(wl, wlvif, wlvif->role_id, wlvif->band, wlvif->channel); |
| 4624 | } |
| 4625 | |
| 4626 | static void wlcore_update_inconn_sta(struct wl1271 *wl, |
| 4627 | struct wl12xx_vif *wlvif, |
| 4628 | struct wl1271_station *wl_sta, |
| 4629 | bool in_connection) |
| 4630 | { |
| 4631 | if (in_connection) { |
| 4632 | if (WARN_ON(wl_sta->in_connection)) |
| 4633 | return; |
| 4634 | wl_sta->in_connection = true; |
| 4635 | if (!wlvif->inconn_count++) |
| 4636 | wlcore_roc_if_possible(wl, wlvif); |
| 4637 | } else { |
| 4638 | if (!wl_sta->in_connection) |
| 4639 | return; |
| 4640 | |
| 4641 | wl_sta->in_connection = false; |
| 4642 | wlvif->inconn_count--; |
| 4643 | if (WARN_ON(wlvif->inconn_count < 0)) |
| 4644 | return; |
| 4645 | |
| 4646 | if (!wlvif->inconn_count) |
| 4647 | if (test_bit(wlvif->role_id, wl->roc_map)) |
| 4648 | wl12xx_croc(wl, wlvif->role_id); |
| 4649 | } |
| 4650 | } |
| 4651 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4652 | static int wl12xx_update_sta_state(struct wl1271 *wl, |
| 4653 | struct wl12xx_vif *wlvif, |
| 4654 | struct ieee80211_sta *sta, |
| 4655 | enum ieee80211_sta_state old_state, |
| 4656 | enum ieee80211_sta_state new_state) |
| 4657 | { |
| 4658 | struct wl1271_station *wl_sta; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4659 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
| 4660 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
| 4661 | int ret; |
| 4662 | |
| 4663 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4664 | |
| 4665 | /* Add station (AP mode) */ |
| 4666 | if (is_ap && |
| 4667 | old_state == IEEE80211_STA_NOTEXIST && |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4668 | new_state == IEEE80211_STA_NONE) { |
| 4669 | ret = wl12xx_sta_add(wl, wlvif, sta); |
| 4670 | if (ret) |
| 4671 | return ret; |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4672 | |
| 4673 | wlcore_update_inconn_sta(wl, wlvif, wl_sta, true); |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4674 | } |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4675 | |
| 4676 | /* Remove station (AP mode) */ |
| 4677 | if (is_ap && |
| 4678 | old_state == IEEE80211_STA_NONE && |
| 4679 | new_state == IEEE80211_STA_NOTEXIST) { |
| 4680 | /* must not fail */ |
| 4681 | wl12xx_sta_remove(wl, wlvif, sta); |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4682 | |
| 4683 | wlcore_update_inconn_sta(wl, wlvif, wl_sta, false); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | /* Authorize station (AP mode) */ |
| 4687 | if (is_ap && |
| 4688 | new_state == IEEE80211_STA_AUTHORIZED) { |
Arik Nemtsov | 2fec3d2 | 2013-03-12 17:19:37 +0200 | [diff] [blame] | 4689 | ret = wl12xx_cmd_set_peer_state(wl, wlvif, wl_sta->hlid); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4690 | if (ret < 0) |
| 4691 | return ret; |
| 4692 | |
| 4693 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, |
Arik Nemtsov | 2fec3d2 | 2013-03-12 17:19:37 +0200 | [diff] [blame] | 4694 | wl_sta->hlid); |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4695 | if (ret) |
| 4696 | return ret; |
Eliad Peller | 426001a | 2012-11-26 18:05:45 +0200 | [diff] [blame] | 4697 | |
| 4698 | wlcore_update_inconn_sta(wl, wlvif, wl_sta, false); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4699 | } |
| 4700 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4701 | /* Authorize station */ |
| 4702 | if (is_sta && |
| 4703 | new_state == IEEE80211_STA_AUTHORIZED) { |
| 4704 | set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4705 | ret = wl12xx_set_authorized(wl, wlvif); |
| 4706 | if (ret) |
| 4707 | return ret; |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | if (is_sta && |
| 4711 | old_state == IEEE80211_STA_AUTHORIZED && |
| 4712 | new_state == IEEE80211_STA_ASSOC) { |
| 4713 | clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); |
Eliad Peller | 3230f35 | 2012-11-20 13:20:01 +0200 | [diff] [blame] | 4714 | clear_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags); |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4715 | } |
| 4716 | |
Eliad Peller | 2993626 | 2012-11-20 13:20:06 +0200 | [diff] [blame] | 4717 | /* clear ROCs on failure or authorization */ |
| 4718 | if (is_sta && |
| 4719 | (new_state == IEEE80211_STA_AUTHORIZED || |
| 4720 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 4721 | if (test_bit(wlvif->role_id, wl->roc_map)) |
| 4722 | wl12xx_croc(wl, wlvif->role_id); |
| 4723 | } |
| 4724 | |
| 4725 | if (is_sta && |
| 4726 | old_state == IEEE80211_STA_NOTEXIST && |
| 4727 | new_state == IEEE80211_STA_NONE) { |
| 4728 | if (find_first_bit(wl->roc_map, |
| 4729 | WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) { |
| 4730 | WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID); |
| 4731 | wl12xx_roc(wl, wlvif, wlvif->role_id, |
| 4732 | wlvif->band, wlvif->channel); |
| 4733 | } |
| 4734 | } |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4735 | return 0; |
| 4736 | } |
| 4737 | |
| 4738 | static int wl12xx_op_sta_state(struct ieee80211_hw *hw, |
| 4739 | struct ieee80211_vif *vif, |
| 4740 | struct ieee80211_sta *sta, |
| 4741 | enum ieee80211_sta_state old_state, |
| 4742 | enum ieee80211_sta_state new_state) |
| 4743 | { |
| 4744 | struct wl1271 *wl = hw->priv; |
| 4745 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4746 | int ret; |
| 4747 | |
| 4748 | wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d", |
| 4749 | sta->aid, old_state, new_state); |
| 4750 | |
| 4751 | mutex_lock(&wl->mutex); |
| 4752 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4753 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4754 | ret = -EBUSY; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4755 | goto out; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4756 | } |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4757 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4758 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4759 | if (ret < 0) |
| 4760 | goto out; |
| 4761 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4762 | ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4763 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4764 | wl1271_ps_elp_sleep(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4765 | out: |
| 4766 | mutex_unlock(&wl->mutex); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4767 | if (new_state < old_state) |
| 4768 | return 0; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4769 | return ret; |
| 4770 | } |
| 4771 | |
Luciano Coelho | 4623ec7 | 2011-03-21 19:26:41 +0200 | [diff] [blame] | 4772 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, |
| 4773 | struct ieee80211_vif *vif, |
| 4774 | enum ieee80211_ampdu_mlme_action action, |
| 4775 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 4776 | u8 buf_size) |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4777 | { |
| 4778 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4779 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4780 | int ret; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4781 | u8 hlid, *ba_bitmap; |
| 4782 | |
| 4783 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action, |
| 4784 | tid); |
| 4785 | |
| 4786 | /* sanity check - the fields in FW are only 8bits wide */ |
| 4787 | if (WARN_ON(tid > 0xFF)) |
| 4788 | return -ENOTSUPP; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4789 | |
| 4790 | mutex_lock(&wl->mutex); |
| 4791 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4792 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4793 | ret = -EAGAIN; |
| 4794 | goto out; |
| 4795 | } |
| 4796 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4797 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) { |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4798 | hlid = wlvif->sta.hlid; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4799 | } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4800 | struct wl1271_station *wl_sta; |
| 4801 | |
| 4802 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4803 | hlid = wl_sta->hlid; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4804 | } else { |
| 4805 | ret = -EINVAL; |
| 4806 | goto out; |
| 4807 | } |
| 4808 | |
Arik Nemtsov | 9ae5d8d | 2012-11-28 11:42:45 +0200 | [diff] [blame] | 4809 | ba_bitmap = &wl->links[hlid].ba_bitmap; |
| 4810 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4811 | ret = wl1271_ps_elp_wakeup(wl); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4812 | if (ret < 0) |
| 4813 | goto out; |
| 4814 | |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 4815 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", |
| 4816 | tid, action); |
| 4817 | |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4818 | switch (action) { |
| 4819 | case IEEE80211_AMPDU_RX_START: |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4820 | if (!wlvif->ba_support || !wlvif->ba_allowed) { |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4821 | ret = -ENOTSUPP; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4822 | break; |
| 4823 | } |
| 4824 | |
Igal Chernobelsky | d21553f | 2013-03-12 17:19:35 +0200 | [diff] [blame] | 4825 | if (wl->ba_rx_session_count >= wl->ba_rx_session_count_max) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4826 | ret = -EBUSY; |
| 4827 | wl1271_error("exceeded max RX BA sessions"); |
| 4828 | break; |
| 4829 | } |
| 4830 | |
| 4831 | if (*ba_bitmap & BIT(tid)) { |
| 4832 | ret = -EINVAL; |
| 4833 | wl1271_error("cannot enable RX BA session on active " |
| 4834 | "tid: %d", tid); |
| 4835 | break; |
| 4836 | } |
| 4837 | |
| 4838 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true, |
| 4839 | hlid); |
| 4840 | if (!ret) { |
| 4841 | *ba_bitmap |= BIT(tid); |
| 4842 | wl->ba_rx_session_count++; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4843 | } |
| 4844 | break; |
| 4845 | |
| 4846 | case IEEE80211_AMPDU_RX_STOP: |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4847 | if (!(*ba_bitmap & BIT(tid))) { |
Arik Nemtsov | c954910 | 2012-06-06 10:48:56 +0300 | [diff] [blame] | 4848 | /* |
| 4849 | * this happens on reconfig - so only output a debug |
| 4850 | * message for now, and don't fail the function. |
| 4851 | */ |
| 4852 | wl1271_debug(DEBUG_MAC80211, |
| 4853 | "no active RX BA session on tid: %d", |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4854 | tid); |
Arik Nemtsov | c954910 | 2012-06-06 10:48:56 +0300 | [diff] [blame] | 4855 | ret = 0; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4856 | break; |
| 4857 | } |
| 4858 | |
| 4859 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false, |
| 4860 | hlid); |
| 4861 | if (!ret) { |
| 4862 | *ba_bitmap &= ~BIT(tid); |
| 4863 | wl->ba_rx_session_count--; |
| 4864 | } |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4865 | break; |
| 4866 | |
| 4867 | /* |
| 4868 | * The BA initiator session management in FW independently. |
| 4869 | * Falling break here on purpose for all TX APDU commands. |
| 4870 | */ |
| 4871 | case IEEE80211_AMPDU_TX_START: |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 4872 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 4873 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 4874 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4875 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 4876 | ret = -EINVAL; |
| 4877 | break; |
| 4878 | |
| 4879 | default: |
| 4880 | wl1271_error("Incorrect ampdu action id=%x\n", action); |
| 4881 | ret = -EINVAL; |
| 4882 | } |
| 4883 | |
| 4884 | wl1271_ps_elp_sleep(wl); |
| 4885 | |
| 4886 | out: |
| 4887 | mutex_unlock(&wl->mutex); |
| 4888 | |
| 4889 | return ret; |
| 4890 | } |
| 4891 | |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4892 | static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw, |
| 4893 | struct ieee80211_vif *vif, |
| 4894 | const struct cfg80211_bitrate_mask *mask) |
| 4895 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4896 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4897 | struct wl1271 *wl = hw->priv; |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4898 | int i, ret = 0; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4899 | |
| 4900 | wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", |
| 4901 | mask->control[NL80211_BAND_2GHZ].legacy, |
| 4902 | mask->control[NL80211_BAND_5GHZ].legacy); |
| 4903 | |
| 4904 | mutex_lock(&wl->mutex); |
| 4905 | |
Arik Nemtsov | 091185d | 2012-07-03 09:11:03 +0300 | [diff] [blame] | 4906 | for (i = 0; i < WLCORE_NUM_BANDS; i++) |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4907 | wlvif->bitrate_masks[i] = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4908 | wl1271_tx_enabled_rates_get(wl, |
| 4909 | mask->control[i].legacy, |
| 4910 | i); |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4911 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4912 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4913 | goto out; |
| 4914 | |
| 4915 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 4916 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) { |
| 4917 | |
| 4918 | ret = wl1271_ps_elp_wakeup(wl); |
| 4919 | if (ret < 0) |
| 4920 | goto out; |
| 4921 | |
| 4922 | wl1271_set_band_rate(wl, wlvif); |
| 4923 | wlvif->basic_rate = |
| 4924 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 4925 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4926 | |
| 4927 | wl1271_ps_elp_sleep(wl); |
| 4928 | } |
| 4929 | out: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4930 | mutex_unlock(&wl->mutex); |
| 4931 | |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4932 | return ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4933 | } |
| 4934 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4935 | static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, |
| 4936 | struct ieee80211_channel_switch *ch_switch) |
| 4937 | { |
| 4938 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4939 | struct wl12xx_vif *wlvif; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4940 | int ret; |
| 4941 | |
| 4942 | wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); |
| 4943 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 4944 | wl1271_tx_flush(wl); |
| 4945 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4946 | mutex_lock(&wl->mutex); |
| 4947 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4948 | if (unlikely(wl->state == WLCORE_STATE_OFF)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 4949 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 4950 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 4951 | ieee80211_chswitch_done(vif, false); |
| 4952 | } |
| 4953 | goto out; |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 4954 | } else if (unlikely(wl->state != WLCORE_STATE_ON)) { |
| 4955 | goto out; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4956 | } |
| 4957 | |
| 4958 | ret = wl1271_ps_elp_wakeup(wl); |
| 4959 | if (ret < 0) |
| 4960 | goto out; |
| 4961 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4962 | /* TODO: change mac80211 to pass vif as param */ |
| 4963 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4964 | unsigned long delay_usec; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4965 | |
Eliad Peller | fcab189 | 2012-11-22 18:06:18 +0200 | [diff] [blame] | 4966 | ret = wl->ops->channel_switch(wl, wlvif, ch_switch); |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4967 | if (ret) |
| 4968 | goto out_sleep; |
| 4969 | |
| 4970 | set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags); |
| 4971 | |
| 4972 | /* indicate failure 5 seconds after channel switch time */ |
| 4973 | delay_usec = ieee80211_tu_to_usec(wlvif->beacon_int) * |
| 4974 | ch_switch->count; |
| 4975 | ieee80211_queue_delayed_work(hw, &wlvif->channel_switch_work, |
| 4976 | usecs_to_jiffies(delay_usec) + |
| 4977 | msecs_to_jiffies(5000)); |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4978 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4979 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 4980 | out_sleep: |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4981 | wl1271_ps_elp_sleep(wl); |
| 4982 | |
| 4983 | out: |
| 4984 | mutex_unlock(&wl->mutex); |
| 4985 | } |
| 4986 | |
Johannes Berg | 39ecc01 | 2013-02-13 12:11:00 +0100 | [diff] [blame] | 4987 | 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] | 4988 | { |
| 4989 | struct wl1271 *wl = hw->priv; |
| 4990 | |
| 4991 | wl1271_tx_flush(wl); |
| 4992 | } |
| 4993 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 4994 | static int wlcore_op_remain_on_channel(struct ieee80211_hw *hw, |
| 4995 | struct ieee80211_vif *vif, |
| 4996 | struct ieee80211_channel *chan, |
Ilan Peer | d339d5c | 2013-02-12 09:34:13 +0200 | [diff] [blame] | 4997 | int duration, |
| 4998 | enum ieee80211_roc_type type) |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 4999 | { |
| 5000 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 5001 | struct wl1271 *wl = hw->priv; |
| 5002 | int channel, ret = 0; |
| 5003 | |
| 5004 | channel = ieee80211_frequency_to_channel(chan->center_freq); |
| 5005 | |
| 5006 | wl1271_debug(DEBUG_MAC80211, "mac80211 roc %d (%d)", |
| 5007 | channel, wlvif->role_id); |
| 5008 | |
| 5009 | mutex_lock(&wl->mutex); |
| 5010 | |
| 5011 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 5012 | goto out; |
| 5013 | |
| 5014 | /* return EBUSY if we can't ROC right now */ |
| 5015 | if (WARN_ON(wl->roc_vif || |
| 5016 | find_first_bit(wl->roc_map, |
| 5017 | WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES)) { |
| 5018 | ret = -EBUSY; |
| 5019 | goto out; |
| 5020 | } |
| 5021 | |
| 5022 | ret = wl1271_ps_elp_wakeup(wl); |
| 5023 | if (ret < 0) |
| 5024 | goto out; |
| 5025 | |
| 5026 | ret = wl12xx_start_dev(wl, wlvif, chan->band, channel); |
| 5027 | if (ret < 0) |
| 5028 | goto out_sleep; |
| 5029 | |
| 5030 | wl->roc_vif = vif; |
| 5031 | ieee80211_queue_delayed_work(hw, &wl->roc_complete_work, |
| 5032 | msecs_to_jiffies(duration)); |
| 5033 | out_sleep: |
| 5034 | wl1271_ps_elp_sleep(wl); |
| 5035 | out: |
| 5036 | mutex_unlock(&wl->mutex); |
| 5037 | return ret; |
| 5038 | } |
| 5039 | |
| 5040 | static int __wlcore_roc_completed(struct wl1271 *wl) |
| 5041 | { |
| 5042 | struct wl12xx_vif *wlvif; |
| 5043 | int ret; |
| 5044 | |
| 5045 | /* already completed */ |
| 5046 | if (unlikely(!wl->roc_vif)) |
| 5047 | return 0; |
| 5048 | |
| 5049 | wlvif = wl12xx_vif_to_data(wl->roc_vif); |
| 5050 | |
| 5051 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 5052 | return -EBUSY; |
| 5053 | |
| 5054 | ret = wl12xx_stop_dev(wl, wlvif); |
| 5055 | if (ret < 0) |
| 5056 | return ret; |
| 5057 | |
| 5058 | wl->roc_vif = NULL; |
| 5059 | |
| 5060 | return 0; |
| 5061 | } |
| 5062 | |
| 5063 | static int wlcore_roc_completed(struct wl1271 *wl) |
| 5064 | { |
| 5065 | int ret; |
| 5066 | |
| 5067 | wl1271_debug(DEBUG_MAC80211, "roc complete"); |
| 5068 | |
| 5069 | mutex_lock(&wl->mutex); |
| 5070 | |
| 5071 | if (unlikely(wl->state != WLCORE_STATE_ON)) { |
| 5072 | ret = -EBUSY; |
| 5073 | goto out; |
| 5074 | } |
| 5075 | |
| 5076 | ret = wl1271_ps_elp_wakeup(wl); |
| 5077 | if (ret < 0) |
| 5078 | goto out; |
| 5079 | |
| 5080 | ret = __wlcore_roc_completed(wl); |
| 5081 | |
| 5082 | wl1271_ps_elp_sleep(wl); |
| 5083 | out: |
| 5084 | mutex_unlock(&wl->mutex); |
| 5085 | |
| 5086 | return ret; |
| 5087 | } |
| 5088 | |
| 5089 | static void wlcore_roc_complete_work(struct work_struct *work) |
| 5090 | { |
| 5091 | struct delayed_work *dwork; |
| 5092 | struct wl1271 *wl; |
| 5093 | int ret; |
| 5094 | |
| 5095 | dwork = container_of(work, struct delayed_work, work); |
| 5096 | wl = container_of(dwork, struct wl1271, roc_complete_work); |
| 5097 | |
| 5098 | ret = wlcore_roc_completed(wl); |
| 5099 | if (!ret) |
| 5100 | ieee80211_remain_on_channel_expired(wl->hw); |
| 5101 | } |
| 5102 | |
| 5103 | static int wlcore_op_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 5104 | { |
| 5105 | struct wl1271 *wl = hw->priv; |
| 5106 | |
| 5107 | wl1271_debug(DEBUG_MAC80211, "mac80211 croc"); |
| 5108 | |
| 5109 | /* TODO: per-vif */ |
| 5110 | wl1271_tx_flush(wl); |
| 5111 | |
| 5112 | /* |
| 5113 | * we can't just flush_work here, because it might deadlock |
| 5114 | * (as we might get called from the same workqueue) |
| 5115 | */ |
| 5116 | cancel_delayed_work_sync(&wl->roc_complete_work); |
| 5117 | wlcore_roc_completed(wl); |
| 5118 | |
| 5119 | return 0; |
| 5120 | } |
| 5121 | |
Arik Nemtsov | 5f9b677 | 2012-11-26 18:05:41 +0200 | [diff] [blame] | 5122 | static void wlcore_op_sta_rc_update(struct ieee80211_hw *hw, |
| 5123 | struct ieee80211_vif *vif, |
| 5124 | struct ieee80211_sta *sta, |
| 5125 | u32 changed) |
| 5126 | { |
| 5127 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 5128 | struct wl1271 *wl = hw->priv; |
| 5129 | |
| 5130 | wlcore_hw_sta_rc_update(wl, wlvif, sta, changed); |
| 5131 | } |
| 5132 | |
Nadim Zubidat | 0a9ffac | 2013-03-12 17:19:39 +0200 | [diff] [blame] | 5133 | static int wlcore_op_get_rssi(struct ieee80211_hw *hw, |
| 5134 | struct ieee80211_vif *vif, |
| 5135 | struct ieee80211_sta *sta, |
| 5136 | s8 *rssi_dbm) |
| 5137 | { |
| 5138 | struct wl1271 *wl = hw->priv; |
| 5139 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 5140 | int ret = 0; |
| 5141 | |
| 5142 | wl1271_debug(DEBUG_MAC80211, "mac80211 get_rssi"); |
| 5143 | |
| 5144 | mutex_lock(&wl->mutex); |
| 5145 | |
| 5146 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
| 5147 | goto out; |
| 5148 | |
| 5149 | ret = wl1271_ps_elp_wakeup(wl); |
| 5150 | if (ret < 0) |
| 5151 | goto out_sleep; |
| 5152 | |
| 5153 | ret = wlcore_acx_average_rssi(wl, wlvif, rssi_dbm); |
| 5154 | if (ret < 0) |
| 5155 | goto out_sleep; |
| 5156 | |
| 5157 | out_sleep: |
| 5158 | wl1271_ps_elp_sleep(wl); |
| 5159 | |
| 5160 | out: |
| 5161 | mutex_unlock(&wl->mutex); |
| 5162 | |
| 5163 | return ret; |
| 5164 | } |
| 5165 | |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5166 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) |
| 5167 | { |
| 5168 | struct wl1271 *wl = hw->priv; |
| 5169 | bool ret = false; |
| 5170 | |
| 5171 | mutex_lock(&wl->mutex); |
| 5172 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 5173 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5174 | goto out; |
| 5175 | |
| 5176 | /* packets are considered pending if in the TX queue or the FW */ |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 5177 | 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] | 5178 | out: |
| 5179 | mutex_unlock(&wl->mutex); |
| 5180 | |
| 5181 | return ret; |
| 5182 | } |
| 5183 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5184 | /* can't be const, mac80211 writes to this */ |
| 5185 | static struct ieee80211_rate wl1271_rates[] = { |
| 5186 | { .bitrate = 10, |
| 5187 | .hw_value = CONF_HW_BIT_RATE_1MBPS, |
| 5188 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, |
| 5189 | { .bitrate = 20, |
| 5190 | .hw_value = CONF_HW_BIT_RATE_2MBPS, |
| 5191 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, |
| 5192 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 5193 | { .bitrate = 55, |
| 5194 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, |
| 5195 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, |
| 5196 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 5197 | { .bitrate = 110, |
| 5198 | .hw_value = CONF_HW_BIT_RATE_11MBPS, |
| 5199 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, |
| 5200 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 5201 | { .bitrate = 60, |
| 5202 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 5203 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
| 5204 | { .bitrate = 90, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5205 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 5206 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5207 | { .bitrate = 120, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5208 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 5209 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5210 | { .bitrate = 180, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5211 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 5212 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5213 | { .bitrate = 240, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5214 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 5215 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5216 | { .bitrate = 360, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5217 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 5218 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5219 | { .bitrate = 480, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5220 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 5221 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5222 | { .bitrate = 540, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 5223 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 5224 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5225 | }; |
| 5226 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 5227 | /* can't be const, mac80211 writes to this */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5228 | static struct ieee80211_channel wl1271_channels[] = { |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5229 | { .hw_value = 1, .center_freq = 2412, .max_power = WLCORE_MAX_TXPWR }, |
| 5230 | { .hw_value = 2, .center_freq = 2417, .max_power = WLCORE_MAX_TXPWR }, |
| 5231 | { .hw_value = 3, .center_freq = 2422, .max_power = WLCORE_MAX_TXPWR }, |
| 5232 | { .hw_value = 4, .center_freq = 2427, .max_power = WLCORE_MAX_TXPWR }, |
| 5233 | { .hw_value = 5, .center_freq = 2432, .max_power = WLCORE_MAX_TXPWR }, |
| 5234 | { .hw_value = 6, .center_freq = 2437, .max_power = WLCORE_MAX_TXPWR }, |
| 5235 | { .hw_value = 7, .center_freq = 2442, .max_power = WLCORE_MAX_TXPWR }, |
| 5236 | { .hw_value = 8, .center_freq = 2447, .max_power = WLCORE_MAX_TXPWR }, |
| 5237 | { .hw_value = 9, .center_freq = 2452, .max_power = WLCORE_MAX_TXPWR }, |
| 5238 | { .hw_value = 10, .center_freq = 2457, .max_power = WLCORE_MAX_TXPWR }, |
| 5239 | { .hw_value = 11, .center_freq = 2462, .max_power = WLCORE_MAX_TXPWR }, |
| 5240 | { .hw_value = 12, .center_freq = 2467, .max_power = WLCORE_MAX_TXPWR }, |
| 5241 | { .hw_value = 13, .center_freq = 2472, .max_power = WLCORE_MAX_TXPWR }, |
| 5242 | { .hw_value = 14, .center_freq = 2484, .max_power = WLCORE_MAX_TXPWR }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5243 | }; |
| 5244 | |
| 5245 | /* can't be const, mac80211 writes to this */ |
| 5246 | static struct ieee80211_supported_band wl1271_band_2ghz = { |
| 5247 | .channels = wl1271_channels, |
| 5248 | .n_channels = ARRAY_SIZE(wl1271_channels), |
| 5249 | .bitrates = wl1271_rates, |
| 5250 | .n_bitrates = ARRAY_SIZE(wl1271_rates), |
| 5251 | }; |
| 5252 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5253 | /* 5 GHz data rates for WL1273 */ |
| 5254 | static struct ieee80211_rate wl1271_rates_5ghz[] = { |
| 5255 | { .bitrate = 60, |
| 5256 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 5257 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
| 5258 | { .bitrate = 90, |
| 5259 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 5260 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
| 5261 | { .bitrate = 120, |
| 5262 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 5263 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
| 5264 | { .bitrate = 180, |
| 5265 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 5266 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
| 5267 | { .bitrate = 240, |
| 5268 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 5269 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
| 5270 | { .bitrate = 360, |
| 5271 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 5272 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
| 5273 | { .bitrate = 480, |
| 5274 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 5275 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
| 5276 | { .bitrate = 540, |
| 5277 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 5278 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
| 5279 | }; |
| 5280 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 5281 | /* 5 GHz band channels for WL1273 */ |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5282 | static struct ieee80211_channel wl1271_channels_5ghz[] = { |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5283 | { .hw_value = 7, .center_freq = 5035, .max_power = WLCORE_MAX_TXPWR }, |
| 5284 | { .hw_value = 8, .center_freq = 5040, .max_power = WLCORE_MAX_TXPWR }, |
| 5285 | { .hw_value = 9, .center_freq = 5045, .max_power = WLCORE_MAX_TXPWR }, |
| 5286 | { .hw_value = 11, .center_freq = 5055, .max_power = WLCORE_MAX_TXPWR }, |
| 5287 | { .hw_value = 12, .center_freq = 5060, .max_power = WLCORE_MAX_TXPWR }, |
| 5288 | { .hw_value = 16, .center_freq = 5080, .max_power = WLCORE_MAX_TXPWR }, |
| 5289 | { .hw_value = 34, .center_freq = 5170, .max_power = WLCORE_MAX_TXPWR }, |
| 5290 | { .hw_value = 36, .center_freq = 5180, .max_power = WLCORE_MAX_TXPWR }, |
| 5291 | { .hw_value = 38, .center_freq = 5190, .max_power = WLCORE_MAX_TXPWR }, |
| 5292 | { .hw_value = 40, .center_freq = 5200, .max_power = WLCORE_MAX_TXPWR }, |
| 5293 | { .hw_value = 42, .center_freq = 5210, .max_power = WLCORE_MAX_TXPWR }, |
| 5294 | { .hw_value = 44, .center_freq = 5220, .max_power = WLCORE_MAX_TXPWR }, |
| 5295 | { .hw_value = 46, .center_freq = 5230, .max_power = WLCORE_MAX_TXPWR }, |
| 5296 | { .hw_value = 48, .center_freq = 5240, .max_power = WLCORE_MAX_TXPWR }, |
| 5297 | { .hw_value = 52, .center_freq = 5260, .max_power = WLCORE_MAX_TXPWR }, |
| 5298 | { .hw_value = 56, .center_freq = 5280, .max_power = WLCORE_MAX_TXPWR }, |
| 5299 | { .hw_value = 60, .center_freq = 5300, .max_power = WLCORE_MAX_TXPWR }, |
| 5300 | { .hw_value = 64, .center_freq = 5320, .max_power = WLCORE_MAX_TXPWR }, |
| 5301 | { .hw_value = 100, .center_freq = 5500, .max_power = WLCORE_MAX_TXPWR }, |
| 5302 | { .hw_value = 104, .center_freq = 5520, .max_power = WLCORE_MAX_TXPWR }, |
| 5303 | { .hw_value = 108, .center_freq = 5540, .max_power = WLCORE_MAX_TXPWR }, |
| 5304 | { .hw_value = 112, .center_freq = 5560, .max_power = WLCORE_MAX_TXPWR }, |
| 5305 | { .hw_value = 116, .center_freq = 5580, .max_power = WLCORE_MAX_TXPWR }, |
| 5306 | { .hw_value = 120, .center_freq = 5600, .max_power = WLCORE_MAX_TXPWR }, |
| 5307 | { .hw_value = 124, .center_freq = 5620, .max_power = WLCORE_MAX_TXPWR }, |
| 5308 | { .hw_value = 128, .center_freq = 5640, .max_power = WLCORE_MAX_TXPWR }, |
| 5309 | { .hw_value = 132, .center_freq = 5660, .max_power = WLCORE_MAX_TXPWR }, |
| 5310 | { .hw_value = 136, .center_freq = 5680, .max_power = WLCORE_MAX_TXPWR }, |
| 5311 | { .hw_value = 140, .center_freq = 5700, .max_power = WLCORE_MAX_TXPWR }, |
| 5312 | { .hw_value = 149, .center_freq = 5745, .max_power = WLCORE_MAX_TXPWR }, |
| 5313 | { .hw_value = 153, .center_freq = 5765, .max_power = WLCORE_MAX_TXPWR }, |
| 5314 | { .hw_value = 157, .center_freq = 5785, .max_power = WLCORE_MAX_TXPWR }, |
| 5315 | { .hw_value = 161, .center_freq = 5805, .max_power = WLCORE_MAX_TXPWR }, |
| 5316 | { .hw_value = 165, .center_freq = 5825, .max_power = WLCORE_MAX_TXPWR }, |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5317 | }; |
| 5318 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5319 | static struct ieee80211_supported_band wl1271_band_5ghz = { |
| 5320 | .channels = wl1271_channels_5ghz, |
| 5321 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), |
| 5322 | .bitrates = wl1271_rates_5ghz, |
| 5323 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5324 | }; |
| 5325 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5326 | static const struct ieee80211_ops wl1271_ops = { |
| 5327 | .start = wl1271_op_start, |
Ido Yariv | c24ec83 | 2012-06-26 21:08:58 +0300 | [diff] [blame] | 5328 | .stop = wlcore_op_stop, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5329 | .add_interface = wl1271_op_add_interface, |
| 5330 | .remove_interface = wl1271_op_remove_interface, |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 5331 | .change_interface = wl12xx_op_change_interface, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 5332 | #ifdef CONFIG_PM |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 5333 | .suspend = wl1271_op_suspend, |
| 5334 | .resume = wl1271_op_resume, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 5335 | #endif |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5336 | .config = wl1271_op_config, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 5337 | .prepare_multicast = wl1271_op_prepare_multicast, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5338 | .configure_filter = wl1271_op_configure_filter, |
| 5339 | .tx = wl1271_op_tx, |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 5340 | .set_key = wlcore_op_set_key, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5341 | .hw_scan = wl1271_op_hw_scan, |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 5342 | .cancel_hw_scan = wl1271_op_cancel_hw_scan, |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 5343 | .sched_scan_start = wl1271_op_sched_scan_start, |
| 5344 | .sched_scan_stop = wl1271_op_sched_scan_stop, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5345 | .bss_info_changed = wl1271_op_bss_info_changed, |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 5346 | .set_frag_threshold = wl1271_op_set_frag_threshold, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5347 | .set_rts_threshold = wl1271_op_set_rts_threshold, |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 5348 | .conf_tx = wl1271_op_conf_tx, |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 5349 | .get_tsf = wl1271_op_get_tsf, |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 5350 | .get_survey = wl1271_op_get_survey, |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 5351 | .sta_state = wl12xx_op_sta_state, |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 5352 | .ampdu_action = wl1271_op_ampdu_action, |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 5353 | .tx_frames_pending = wl1271_tx_frames_pending, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 5354 | .set_bitrate_mask = wl12xx_set_bitrate_mask, |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 5355 | .channel_switch = wl12xx_op_channel_switch, |
Eliad Peller | d8ae5a2 | 2012-06-25 13:52:33 +0300 | [diff] [blame] | 5356 | .flush = wlcore_op_flush, |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5357 | .remain_on_channel = wlcore_op_remain_on_channel, |
| 5358 | .cancel_remain_on_channel = wlcore_op_cancel_remain_on_channel, |
Eliad Peller | b6970ee | 2012-11-20 13:20:05 +0200 | [diff] [blame] | 5359 | .add_chanctx = wlcore_op_add_chanctx, |
| 5360 | .remove_chanctx = wlcore_op_remove_chanctx, |
| 5361 | .change_chanctx = wlcore_op_change_chanctx, |
| 5362 | .assign_vif_chanctx = wlcore_op_assign_vif_chanctx, |
| 5363 | .unassign_vif_chanctx = wlcore_op_unassign_vif_chanctx, |
Arik Nemtsov | 5f9b677 | 2012-11-26 18:05:41 +0200 | [diff] [blame] | 5364 | .sta_rc_update = wlcore_op_sta_rc_update, |
Nadim Zubidat | 0a9ffac | 2013-03-12 17:19:39 +0200 | [diff] [blame] | 5365 | .get_rssi = wlcore_op_get_rssi, |
Kalle Valo | c8c9087 | 2010-02-18 13:25:53 +0200 | [diff] [blame] | 5366 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5367 | }; |
| 5368 | |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5369 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5370 | 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] | 5371 | { |
| 5372 | u8 idx; |
| 5373 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5374 | BUG_ON(band >= 2); |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5375 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5376 | if (unlikely(rate >= wl->hw_tx_rate_tbl_size)) { |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5377 | wl1271_error("Illegal RX rate from HW: %d", rate); |
| 5378 | return 0; |
| 5379 | } |
| 5380 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 5381 | idx = wl->band_rate_to_idx[band][rate]; |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 5382 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { |
| 5383 | wl1271_error("Unsupported RX rate from HW: %d", rate); |
| 5384 | return 0; |
| 5385 | } |
| 5386 | |
| 5387 | return idx; |
| 5388 | } |
| 5389 | |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5390 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, |
| 5391 | struct device_attribute *attr, |
| 5392 | char *buf) |
| 5393 | { |
| 5394 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 5395 | ssize_t len; |
| 5396 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 5397 | len = PAGE_SIZE; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5398 | |
| 5399 | mutex_lock(&wl->mutex); |
| 5400 | len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", |
| 5401 | wl->sg_enabled); |
| 5402 | mutex_unlock(&wl->mutex); |
| 5403 | |
| 5404 | return len; |
| 5405 | |
| 5406 | } |
| 5407 | |
| 5408 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, |
| 5409 | struct device_attribute *attr, |
| 5410 | const char *buf, size_t count) |
| 5411 | { |
| 5412 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 5413 | unsigned long res; |
| 5414 | int ret; |
| 5415 | |
Luciano Coelho | 6277ed6 | 2011-04-01 17:49:54 +0300 | [diff] [blame] | 5416 | ret = kstrtoul(buf, 10, &res); |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5417 | if (ret < 0) { |
| 5418 | wl1271_warning("incorrect value written to bt_coex_mode"); |
| 5419 | return count; |
| 5420 | } |
| 5421 | |
| 5422 | mutex_lock(&wl->mutex); |
| 5423 | |
| 5424 | res = !!res; |
| 5425 | |
| 5426 | if (res == wl->sg_enabled) |
| 5427 | goto out; |
| 5428 | |
| 5429 | wl->sg_enabled = res; |
| 5430 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 5431 | if (unlikely(wl->state != WLCORE_STATE_ON)) |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5432 | goto out; |
| 5433 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5434 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5435 | if (ret < 0) |
| 5436 | goto out; |
| 5437 | |
| 5438 | wl1271_acx_sg_enable(wl, wl->sg_enabled); |
| 5439 | wl1271_ps_elp_sleep(wl); |
| 5440 | |
| 5441 | out: |
| 5442 | mutex_unlock(&wl->mutex); |
| 5443 | return count; |
| 5444 | } |
| 5445 | |
| 5446 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, |
| 5447 | wl1271_sysfs_show_bt_coex_state, |
| 5448 | wl1271_sysfs_store_bt_coex_state); |
| 5449 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5450 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, |
| 5451 | struct device_attribute *attr, |
| 5452 | char *buf) |
| 5453 | { |
| 5454 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 5455 | ssize_t len; |
| 5456 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 5457 | len = PAGE_SIZE; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5458 | |
| 5459 | mutex_lock(&wl->mutex); |
| 5460 | if (wl->hw_pg_ver >= 0) |
| 5461 | len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); |
| 5462 | else |
| 5463 | len = snprintf(buf, len, "n/a\n"); |
| 5464 | mutex_unlock(&wl->mutex); |
| 5465 | |
| 5466 | return len; |
| 5467 | } |
| 5468 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5469 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO, |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5470 | wl1271_sysfs_show_hw_pg_ver, NULL); |
| 5471 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5472 | static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj, |
| 5473 | struct bin_attribute *bin_attr, |
| 5474 | char *buffer, loff_t pos, size_t count) |
| 5475 | { |
| 5476 | struct device *dev = container_of(kobj, struct device, kobj); |
| 5477 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 5478 | ssize_t len; |
| 5479 | int ret; |
| 5480 | |
| 5481 | ret = mutex_lock_interruptible(&wl->mutex); |
| 5482 | if (ret < 0) |
| 5483 | return -ERESTARTSYS; |
| 5484 | |
| 5485 | /* Let only one thread read the log at a time, blocking others */ |
| 5486 | while (wl->fwlog_size == 0) { |
| 5487 | DEFINE_WAIT(wait); |
| 5488 | |
| 5489 | prepare_to_wait_exclusive(&wl->fwlog_waitq, |
| 5490 | &wait, |
| 5491 | TASK_INTERRUPTIBLE); |
| 5492 | |
| 5493 | if (wl->fwlog_size != 0) { |
| 5494 | finish_wait(&wl->fwlog_waitq, &wait); |
| 5495 | break; |
| 5496 | } |
| 5497 | |
| 5498 | mutex_unlock(&wl->mutex); |
| 5499 | |
| 5500 | schedule(); |
| 5501 | finish_wait(&wl->fwlog_waitq, &wait); |
| 5502 | |
| 5503 | if (signal_pending(current)) |
| 5504 | return -ERESTARTSYS; |
| 5505 | |
| 5506 | ret = mutex_lock_interruptible(&wl->mutex); |
| 5507 | if (ret < 0) |
| 5508 | return -ERESTARTSYS; |
| 5509 | } |
| 5510 | |
| 5511 | /* Check if the fwlog is still valid */ |
| 5512 | if (wl->fwlog_size < 0) { |
| 5513 | mutex_unlock(&wl->mutex); |
| 5514 | return 0; |
| 5515 | } |
| 5516 | |
| 5517 | /* Seeking is not supported - old logs are not kept. Disregard pos. */ |
| 5518 | len = min(count, (size_t)wl->fwlog_size); |
| 5519 | wl->fwlog_size -= len; |
| 5520 | memcpy(buffer, wl->fwlog, len); |
| 5521 | |
| 5522 | /* Make room for new messages */ |
| 5523 | memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size); |
| 5524 | |
| 5525 | mutex_unlock(&wl->mutex); |
| 5526 | |
| 5527 | return len; |
| 5528 | } |
| 5529 | |
| 5530 | static struct bin_attribute fwlog_attr = { |
| 5531 | .attr = {.name = "fwlog", .mode = S_IRUSR}, |
| 5532 | .read = wl1271_sysfs_read_fwlog, |
| 5533 | }; |
| 5534 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5535 | 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] | 5536 | { |
| 5537 | int i; |
| 5538 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5539 | wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x", |
| 5540 | oui, nic); |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5541 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5542 | if (nic + WLCORE_NUM_MAC_ADDRESSES - wl->num_mac_addr > 0xffffff) |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5543 | wl1271_warning("NIC part of the MAC address wraps around!"); |
| 5544 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5545 | for (i = 0; i < wl->num_mac_addr; i++) { |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5546 | wl->addresses[i].addr[0] = (u8)(oui >> 16); |
| 5547 | wl->addresses[i].addr[1] = (u8)(oui >> 8); |
| 5548 | wl->addresses[i].addr[2] = (u8) oui; |
| 5549 | wl->addresses[i].addr[3] = (u8)(nic >> 16); |
| 5550 | wl->addresses[i].addr[4] = (u8)(nic >> 8); |
| 5551 | wl->addresses[i].addr[5] = (u8) nic; |
| 5552 | nic++; |
| 5553 | } |
| 5554 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5555 | /* we may be one address short at the most */ |
| 5556 | WARN_ON(wl->num_mac_addr + 1 < WLCORE_NUM_MAC_ADDRESSES); |
| 5557 | |
| 5558 | /* |
| 5559 | * turn on the LAA bit in the first address and use it as |
| 5560 | * the last address. |
| 5561 | */ |
| 5562 | if (wl->num_mac_addr < WLCORE_NUM_MAC_ADDRESSES) { |
| 5563 | int idx = WLCORE_NUM_MAC_ADDRESSES - 1; |
| 5564 | memcpy(&wl->addresses[idx], &wl->addresses[0], |
| 5565 | sizeof(wl->addresses[0])); |
| 5566 | /* LAA bit */ |
| 5567 | wl->addresses[idx].addr[2] |= BIT(1); |
| 5568 | } |
| 5569 | |
| 5570 | wl->hw->wiphy->n_addresses = WLCORE_NUM_MAC_ADDRESSES; |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5571 | wl->hw->wiphy->addresses = wl->addresses; |
| 5572 | } |
| 5573 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5574 | static int wl12xx_get_hw_info(struct wl1271 *wl) |
| 5575 | { |
| 5576 | int ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5577 | |
| 5578 | ret = wl12xx_set_power_on(wl); |
| 5579 | if (ret < 0) |
Julia Lawall | 4fb4e0b | 2012-10-21 12:52:04 +0200 | [diff] [blame] | 5580 | return ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5581 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5582 | ret = wlcore_read_reg(wl, REG_CHIP_ID_B, &wl->chip.id); |
| 5583 | if (ret < 0) |
| 5584 | goto out; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5585 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 5586 | wl->fuse_oui_addr = 0; |
| 5587 | wl->fuse_nic_addr = 0; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5588 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5589 | ret = wl->ops->get_pg_ver(wl, &wl->hw_pg_ver); |
| 5590 | if (ret < 0) |
| 5591 | goto out; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5592 | |
Luciano Coelho | 30d9b4a | 2012-04-11 11:07:28 +0300 | [diff] [blame] | 5593 | if (wl->ops->get_mac) |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5594 | ret = wl->ops->get_mac(wl); |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5595 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5596 | out: |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 5597 | wl1271_power_off(wl); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5598 | return ret; |
| 5599 | } |
| 5600 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5601 | static int wl1271_register_hw(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5602 | { |
| 5603 | int ret; |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5604 | u32 oui_addr = 0, nic_addr = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5605 | |
| 5606 | if (wl->mac80211_registered) |
| 5607 | return 0; |
| 5608 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5609 | if (wl->nvs_len >= 12) { |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 5610 | /* NOTE: The wl->nvs->nvs element must be first, in |
| 5611 | * order to simplify the casting, we assume it is at |
| 5612 | * the beginning of the wl->nvs structure. |
| 5613 | */ |
| 5614 | u8 *nvs_ptr = (u8 *)wl->nvs; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5615 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5616 | oui_addr = |
| 5617 | (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6]; |
| 5618 | nic_addr = |
| 5619 | (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3]; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 5620 | } |
| 5621 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 5622 | /* if the MAC address is zeroed in the NVS derive from fuse */ |
| 5623 | if (oui_addr == 0 && nic_addr == 0) { |
| 5624 | oui_addr = wl->fuse_oui_addr; |
| 5625 | /* fuse has the BD_ADDR, the WLAN addresses are the next two */ |
| 5626 | nic_addr = wl->fuse_nic_addr + 1; |
| 5627 | } |
| 5628 | |
Arik Nemtsov | f4afbed | 2012-08-02 20:37:21 +0300 | [diff] [blame] | 5629 | wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5630 | |
| 5631 | ret = ieee80211_register_hw(wl->hw); |
| 5632 | if (ret < 0) { |
| 5633 | wl1271_error("unable to register mac80211 hw: %d", ret); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5634 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | wl->mac80211_registered = true; |
| 5638 | |
Eliad Peller | d60080a | 2010-11-24 12:53:16 +0200 | [diff] [blame] | 5639 | wl1271_debugfs_init(wl); |
| 5640 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5641 | wl1271_notice("loaded"); |
| 5642 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5643 | out: |
| 5644 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5645 | } |
| 5646 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5647 | static void wl1271_unregister_hw(struct wl1271 *wl) |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5648 | { |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5649 | if (wl->plt) |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 5650 | wl1271_plt_stop(wl); |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 5651 | |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5652 | ieee80211_unregister_hw(wl->hw); |
| 5653 | wl->mac80211_registered = false; |
| 5654 | |
| 5655 | } |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5656 | |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5657 | static const struct ieee80211_iface_limit wlcore_iface_limits[] = { |
| 5658 | { |
Arik Nemtsov | e7a6ba29 | 2012-08-02 22:00:34 +0300 | [diff] [blame] | 5659 | .max = 3, |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5660 | .types = BIT(NL80211_IFTYPE_STATION), |
| 5661 | }, |
| 5662 | { |
| 5663 | .max = 1, |
| 5664 | .types = BIT(NL80211_IFTYPE_AP) | |
| 5665 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 5666 | BIT(NL80211_IFTYPE_P2P_CLIENT), |
| 5667 | }, |
| 5668 | }; |
| 5669 | |
Arik Nemtsov | de40750 | 2012-11-26 18:05:44 +0200 | [diff] [blame] | 5670 | static struct ieee80211_iface_combination |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5671 | wlcore_iface_combinations[] = { |
| 5672 | { |
Arik Nemtsov | e7a6ba29 | 2012-08-02 22:00:34 +0300 | [diff] [blame] | 5673 | .max_interfaces = 3, |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5674 | .limits = wlcore_iface_limits, |
| 5675 | .n_limits = ARRAY_SIZE(wlcore_iface_limits), |
| 5676 | }, |
| 5677 | }; |
| 5678 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5679 | static int wl1271_init_ieee80211(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5680 | { |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5681 | int i; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5682 | static const u32 cipher_suites[] = { |
| 5683 | WLAN_CIPHER_SUITE_WEP40, |
| 5684 | WLAN_CIPHER_SUITE_WEP104, |
| 5685 | WLAN_CIPHER_SUITE_TKIP, |
| 5686 | WLAN_CIPHER_SUITE_CCMP, |
| 5687 | WL1271_CIPHER_SUITE_GEM, |
| 5688 | }; |
| 5689 | |
Arik Nemtsov | 2c0133a | 2012-05-18 07:46:36 +0300 | [diff] [blame] | 5690 | /* The tx descriptor buffer */ |
| 5691 | wl->hw->extra_tx_headroom = sizeof(struct wl1271_tx_hw_descr); |
| 5692 | |
| 5693 | if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) |
| 5694 | wl->hw->extra_tx_headroom += WL1271_EXTRA_SPACE_TKIP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5695 | |
| 5696 | /* unit us */ |
| 5697 | /* FIXME: find a proper value */ |
| 5698 | wl->hw->channel_change_time = 10000; |
Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 5699 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5700 | |
| 5701 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Juuso Oikarinen | 0a34332 | 2010-02-22 08:38:41 +0200 | [diff] [blame] | 5702 | IEEE80211_HW_SUPPORTS_PS | |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 5703 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 5704 | IEEE80211_HW_SUPPORTS_UAPSD | |
Juuso Oikarinen | a9af092 | 2010-03-26 12:53:30 +0200 | [diff] [blame] | 5705 | IEEE80211_HW_HAS_RATE_CONTROL | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 5706 | IEEE80211_HW_CONNECTION_MONITOR | |
Luciano Coelho | 25eaea30 | 2011-05-02 12:37:33 +0300 | [diff] [blame] | 5707 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
Shahar Levi | fcd23b6 | 2011-05-11 12:12:56 +0300 | [diff] [blame] | 5708 | IEEE80211_HW_SPECTRUM_MGMT | |
Arik Nemtsov | 93f8c8e | 2011-08-30 09:34:01 +0300 | [diff] [blame] | 5709 | IEEE80211_HW_AP_LINK_PS | |
| 5710 | IEEE80211_HW_AMPDU_AGGREGATION | |
Eliad Peller | 79aba1b | 2012-02-02 13:15:35 +0200 | [diff] [blame] | 5711 | IEEE80211_HW_TX_AMPDU_SETUP_IN_HW | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 5712 | IEEE80211_HW_QUEUE_CONTROL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5713 | |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5714 | wl->hw->wiphy->cipher_suites = cipher_suites; |
| 5715 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 5716 | |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 5717 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 5718 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) | |
| 5719 | BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5720 | wl->hw->wiphy->max_scan_ssids = 1; |
Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 5721 | wl->hw->wiphy->max_sched_scan_ssids = 16; |
| 5722 | wl->hw->wiphy->max_match_sets = 16; |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5723 | /* |
| 5724 | * Maximum length of elements in scanning probe request templates |
| 5725 | * should be the maximum length possible for a template, without |
| 5726 | * the IEEE80211 header of the template |
| 5727 | */ |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5728 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5729 | sizeof(struct ieee80211_header); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5730 | |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5731 | 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] | 5732 | sizeof(struct ieee80211_header); |
| 5733 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5734 | wl->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 5735 | |
Johannes Berg | 81ddbb5 | 2012-03-26 18:47:18 +0200 | [diff] [blame] | 5736 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD | |
| 5737 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 5738 | |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 5739 | /* make sure all our channels fit in the scanned_ch bitmask */ |
| 5740 | BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + |
| 5741 | ARRAY_SIZE(wl1271_channels_5ghz) > |
| 5742 | WL1271_MAX_CHANNELS); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5743 | /* |
Victor Goldenshtein | 583f816 | 2012-11-27 08:44:55 +0200 | [diff] [blame] | 5744 | * clear channel flags from the previous usage |
| 5745 | * and restore max_power & max_antenna_gain values. |
| 5746 | */ |
| 5747 | for (i = 0; i < ARRAY_SIZE(wl1271_channels); i++) { |
| 5748 | wl1271_band_2ghz.channels[i].flags = 0; |
| 5749 | wl1271_band_2ghz.channels[i].max_power = WLCORE_MAX_TXPWR; |
| 5750 | wl1271_band_2ghz.channels[i].max_antenna_gain = 0; |
| 5751 | } |
| 5752 | |
| 5753 | for (i = 0; i < ARRAY_SIZE(wl1271_channels_5ghz); i++) { |
| 5754 | wl1271_band_5ghz.channels[i].flags = 0; |
| 5755 | wl1271_band_5ghz.channels[i].max_power = WLCORE_MAX_TXPWR; |
| 5756 | wl1271_band_5ghz.channels[i].max_antenna_gain = 0; |
| 5757 | } |
| 5758 | |
| 5759 | /* |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5760 | * We keep local copies of the band structs because we need to |
| 5761 | * modify them on a per-device basis. |
| 5762 | */ |
| 5763 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, |
| 5764 | sizeof(wl1271_band_2ghz)); |
Eliad Peller | bfb92ca | 2012-05-15 17:09:00 +0300 | [diff] [blame] | 5765 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, |
| 5766 | &wl->ht_cap[IEEE80211_BAND_2GHZ], |
| 5767 | sizeof(*wl->ht_cap)); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5768 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, |
| 5769 | sizeof(wl1271_band_5ghz)); |
Eliad Peller | bfb92ca | 2012-05-15 17:09:00 +0300 | [diff] [blame] | 5770 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, |
| 5771 | &wl->ht_cap[IEEE80211_BAND_5GHZ], |
| 5772 | sizeof(*wl->ht_cap)); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5773 | |
| 5774 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 5775 | &wl->bands[IEEE80211_BAND_2GHZ]; |
| 5776 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 5777 | &wl->bands[IEEE80211_BAND_5GHZ]; |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5778 | |
Arik Nemtsov | 1c33db7 | 2012-11-30 00:48:03 +0200 | [diff] [blame] | 5779 | /* |
| 5780 | * allow 4 queues per mac address we support + |
| 5781 | * 1 cab queue per mac + one global offchannel Tx queue |
| 5782 | */ |
| 5783 | wl->hw->queues = (NUM_TX_QUEUES + 1) * WLCORE_NUM_MAC_ADDRESSES + 1; |
| 5784 | |
| 5785 | /* the last queue is the offchannel queue */ |
| 5786 | wl->hw->offchannel_tx_hw_queue = wl->hw->queues - 1; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 5787 | wl->hw->max_rates = 1; |
Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5788 | |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 5789 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; |
| 5790 | |
Arik Nemtsov | 9c1b190 | 2011-11-08 18:46:55 +0200 | [diff] [blame] | 5791 | /* the FW answers probe-requests in AP-mode */ |
| 5792 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 5793 | wl->hw->wiphy->probe_resp_offload = |
| 5794 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 5795 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 5796 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 5797 | |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5798 | /* allowed interface combinations */ |
Arik Nemtsov | de40750 | 2012-11-26 18:05:44 +0200 | [diff] [blame] | 5799 | wlcore_iface_combinations[0].num_different_channels = wl->num_channels; |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5800 | wl->hw->wiphy->iface_combinations = wlcore_iface_combinations; |
| 5801 | wl->hw->wiphy->n_iface_combinations = |
| 5802 | ARRAY_SIZE(wlcore_iface_combinations); |
| 5803 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5804 | SET_IEEE80211_DEV(wl->hw, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5805 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5806 | wl->hw->sta_data_size = sizeof(struct wl1271_station); |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 5807 | wl->hw->vif_data_size = sizeof(struct wl12xx_vif); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5808 | |
Arik Nemtsov | ba421f8 | 2012-01-06 00:05:51 +0200 | [diff] [blame] | 5809 | 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] | 5810 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5811 | return 0; |
| 5812 | } |
| 5813 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 5814 | struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size, u32 aggr_buf_size, |
| 5815 | u32 mbox_size) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5816 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5817 | struct ieee80211_hw *hw; |
| 5818 | struct wl1271 *wl; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5819 | int i, j, ret; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5820 | unsigned int order; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5821 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5822 | BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS); |
Arik Nemtsov | f80c2d1 | 2011-09-22 09:52:05 +0300 | [diff] [blame] | 5823 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5824 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); |
| 5825 | if (!hw) { |
| 5826 | wl1271_error("could not alloc ieee80211_hw"); |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5827 | ret = -ENOMEM; |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5828 | goto err_hw_alloc; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | wl = hw->priv; |
| 5832 | memset(wl, 0, sizeof(*wl)); |
| 5833 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5834 | wl->priv = kzalloc(priv_size, GFP_KERNEL); |
| 5835 | if (!wl->priv) { |
| 5836 | wl1271_error("could not alloc wl priv"); |
| 5837 | ret = -ENOMEM; |
| 5838 | goto err_priv_alloc; |
| 5839 | } |
| 5840 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 5841 | INIT_LIST_HEAD(&wl->wlvif_list); |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 5842 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5843 | wl->hw = hw; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5844 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 5845 | for (i = 0; i < NUM_TX_QUEUES; i++) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5846 | for (j = 0; j < WL12XX_MAX_LINKS; j++) |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5847 | skb_queue_head_init(&wl->links[j].tx_queue[i]); |
| 5848 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5849 | skb_queue_head_init(&wl->deferred_rx_queue); |
| 5850 | skb_queue_head_init(&wl->deferred_tx_queue); |
| 5851 | |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 5852 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5853 | INIT_WORK(&wl->netstack_work, wl1271_netstack_work); |
Juuso Oikarinen | 117b38d | 2010-09-30 10:43:28 +0200 | [diff] [blame] | 5854 | INIT_WORK(&wl->tx_work, wl1271_tx_work); |
| 5855 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); |
| 5856 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 5857 | INIT_DELAYED_WORK(&wl->roc_complete_work, wlcore_roc_complete_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 5858 | INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 5859 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5860 | wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); |
| 5861 | if (!wl->freezable_wq) { |
| 5862 | ret = -ENOMEM; |
| 5863 | goto err_hw; |
| 5864 | } |
| 5865 | |
Luciano Coelho | 8f6ac53 | 2013-05-04 01:06:11 +0300 | [diff] [blame^] | 5866 | wl->channel = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5867 | wl->rx_counter = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5868 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 5869 | wl->band = IEEE80211_BAND_2GHZ; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 5870 | wl->channel_type = NL80211_CHAN_NO_HT; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 5871 | wl->flags = 0; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5872 | wl->sg_enabled = true; |
Arik Nemtsov | 66340e5 | 2012-06-10 17:09:22 +0300 | [diff] [blame] | 5873 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Luciano Coelho | c108c90 | 2012-11-26 18:05:49 +0200 | [diff] [blame] | 5874 | wl->recovery_count = 0; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5875 | wl->hw_pg_ver = -1; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 5876 | wl->ap_ps_map = 0; |
| 5877 | wl->ap_fw_ps_map = 0; |
Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 5878 | wl->quirks = 0; |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 5879 | wl->platform_quirks = 0; |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5880 | wl->system_hlid = WL12XX_SYSTEM_HLID; |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 5881 | wl->active_sta_count = 0; |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 5882 | wl->active_link_count = 0; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5883 | wl->fwlog_size = 0; |
| 5884 | init_waitqueue_head(&wl->fwlog_waitq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5885 | |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5886 | /* The system link is always allocated */ |
| 5887 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 5888 | |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 5889 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 5890 | for (i = 0; i < wl->num_tx_desc; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5891 | wl->tx_frames[i] = NULL; |
| 5892 | |
| 5893 | spin_lock_init(&wl->wl_lock); |
| 5894 | |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 5895 | wl->state = WLCORE_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5896 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5897 | mutex_init(&wl->mutex); |
Arik Nemtsov | 2c38849 | 2012-05-18 07:46:39 +0300 | [diff] [blame] | 5898 | mutex_init(&wl->flush_mutex); |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 5899 | init_completion(&wl->nvs_loading_complete); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5900 | |
Igal Chernobelsky | 26a309c | 2012-07-29 18:21:12 +0300 | [diff] [blame] | 5901 | order = get_order(aggr_buf_size); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5902 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); |
| 5903 | if (!wl->aggr_buf) { |
| 5904 | ret = -ENOMEM; |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5905 | goto err_wq; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5906 | } |
Igal Chernobelsky | 26a309c | 2012-07-29 18:21:12 +0300 | [diff] [blame] | 5907 | wl->aggr_buf_size = aggr_buf_size; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5908 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5909 | wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); |
| 5910 | if (!wl->dummy_packet) { |
| 5911 | ret = -ENOMEM; |
| 5912 | goto err_aggr; |
| 5913 | } |
| 5914 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5915 | /* Allocate one page for the FW log */ |
| 5916 | wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); |
| 5917 | if (!wl->fwlog) { |
| 5918 | ret = -ENOMEM; |
| 5919 | goto err_dummy_packet; |
| 5920 | } |
| 5921 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 5922 | wl->mbox_size = mbox_size; |
| 5923 | wl->mbox = kmalloc(wl->mbox_size, GFP_KERNEL | GFP_DMA); |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 5924 | if (!wl->mbox) { |
| 5925 | ret = -ENOMEM; |
| 5926 | goto err_fwlog; |
| 5927 | } |
| 5928 | |
Ido Yariv | 2e07d02 | 2012-11-28 11:42:49 +0200 | [diff] [blame] | 5929 | wl->buffer_32 = kmalloc(sizeof(*wl->buffer_32), GFP_KERNEL); |
| 5930 | if (!wl->buffer_32) { |
| 5931 | ret = -ENOMEM; |
| 5932 | goto err_mbox; |
| 5933 | } |
| 5934 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5935 | return hw; |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5936 | |
Ido Yariv | 2e07d02 | 2012-11-28 11:42:49 +0200 | [diff] [blame] | 5937 | err_mbox: |
| 5938 | kfree(wl->mbox); |
| 5939 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 5940 | err_fwlog: |
| 5941 | free_page((unsigned long)wl->fwlog); |
| 5942 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5943 | err_dummy_packet: |
| 5944 | dev_kfree_skb(wl->dummy_packet); |
| 5945 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5946 | err_aggr: |
| 5947 | free_pages((unsigned long)wl->aggr_buf, order); |
| 5948 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5949 | err_wq: |
| 5950 | destroy_workqueue(wl->freezable_wq); |
| 5951 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5952 | err_hw: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5953 | wl1271_debugfs_exit(wl); |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5954 | kfree(wl->priv); |
| 5955 | |
| 5956 | err_priv_alloc: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5957 | ieee80211_free_hw(hw); |
| 5958 | |
| 5959 | err_hw_alloc: |
| 5960 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5961 | return ERR_PTR(ret); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5962 | } |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5963 | EXPORT_SYMBOL_GPL(wlcore_alloc_hw); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5964 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5965 | int wlcore_free_hw(struct wl1271 *wl) |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5966 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5967 | /* Unblock any fwlog readers */ |
| 5968 | mutex_lock(&wl->mutex); |
| 5969 | wl->fwlog_size = -1; |
| 5970 | wake_up_interruptible_all(&wl->fwlog_waitq); |
| 5971 | mutex_unlock(&wl->mutex); |
| 5972 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5973 | device_remove_bin_file(wl->dev, &fwlog_attr); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5974 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5975 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5976 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5977 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
Ido Yariv | 2e07d02 | 2012-11-28 11:42:49 +0200 | [diff] [blame] | 5978 | kfree(wl->buffer_32); |
Eliad Peller | a8e2782 | 2012-11-19 17:14:06 +0200 | [diff] [blame] | 5979 | kfree(wl->mbox); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5980 | free_page((unsigned long)wl->fwlog); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5981 | dev_kfree_skb(wl->dummy_packet); |
Igal Chernobelsky | 26a309c | 2012-07-29 18:21:12 +0300 | [diff] [blame] | 5982 | 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] | 5983 | |
| 5984 | wl1271_debugfs_exit(wl); |
| 5985 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5986 | vfree(wl->fw); |
| 5987 | wl->fw = NULL; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5988 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5989 | kfree(wl->nvs); |
| 5990 | wl->nvs = NULL; |
| 5991 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 5992 | kfree(wl->fw_status_1); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5993 | kfree(wl->tx_res_if); |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5994 | destroy_workqueue(wl->freezable_wq); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5995 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5996 | kfree(wl->priv); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5997 | ieee80211_free_hw(wl->hw); |
| 5998 | |
| 5999 | return 0; |
| 6000 | } |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 6001 | EXPORT_SYMBOL_GPL(wlcore_free_hw); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 6002 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 6003 | #ifdef CONFIG_PM |
| 6004 | static const struct wiphy_wowlan_support wlcore_wowlan_support = { |
| 6005 | .flags = WIPHY_WOWLAN_ANY, |
| 6006 | .n_patterns = WL1271_MAX_RX_FILTERS, |
| 6007 | .pattern_min_len = 1, |
| 6008 | .pattern_max_len = WL1271_RX_FILTER_MAX_PATTERN_SIZE, |
| 6009 | }; |
| 6010 | #endif |
| 6011 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6012 | static void wlcore_nvs_cb(const struct firmware *fw, void *context) |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6013 | { |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6014 | struct wl1271 *wl = context; |
| 6015 | struct platform_device *pdev = wl->pdev; |
Luciano Coelho | afb43e6 | 2013-01-25 11:57:48 +0200 | [diff] [blame] | 6016 | struct wlcore_platdev_data *pdev_data = pdev->dev.platform_data; |
| 6017 | struct wl12xx_platform_data *pdata = pdev_data->pdata; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6018 | unsigned long irqflags; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 6019 | int ret; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6020 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6021 | if (fw) { |
| 6022 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); |
| 6023 | if (!wl->nvs) { |
| 6024 | wl1271_error("Could not allocate nvs data"); |
| 6025 | goto out; |
| 6026 | } |
| 6027 | wl->nvs_len = fw->size; |
| 6028 | } else { |
| 6029 | wl1271_debug(DEBUG_BOOT, "Could not get nvs file %s", |
| 6030 | WL12XX_NVS_NAME); |
| 6031 | wl->nvs = NULL; |
| 6032 | wl->nvs_len = 0; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6033 | } |
| 6034 | |
Ido Yariv | 3992eb2 | 2012-09-02 12:29:27 +0300 | [diff] [blame] | 6035 | ret = wl->ops->setup(wl); |
| 6036 | if (ret < 0) |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6037 | goto out_free_nvs; |
Ido Yariv | 3992eb2 | 2012-09-02 12:29:27 +0300 | [diff] [blame] | 6038 | |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 6039 | BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS); |
| 6040 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 6041 | /* adjust some runtime configuration parameters */ |
| 6042 | wlcore_adjust_conf(wl); |
| 6043 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6044 | wl->irq = platform_get_irq(pdev, 0); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6045 | wl->platform_quirks = pdata->platform_quirks; |
Luciano Coelho | afb43e6 | 2013-01-25 11:57:48 +0200 | [diff] [blame] | 6046 | wl->if_ops = pdev_data->if_ops; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6047 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6048 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 6049 | irqflags = IRQF_TRIGGER_RISING; |
| 6050 | else |
| 6051 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; |
| 6052 | |
Luciano Coelho | 97236a0 | 2013-03-08 09:41:53 +0200 | [diff] [blame] | 6053 | ret = request_threaded_irq(wl->irq, NULL, wlcore_irq, |
| 6054 | irqflags, pdev->name, wl); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6055 | if (ret < 0) { |
| 6056 | wl1271_error("request_irq() failed: %d", ret); |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6057 | goto out_free_nvs; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6058 | } |
| 6059 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6060 | #ifdef CONFIG_PM |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6061 | ret = enable_irq_wake(wl->irq); |
| 6062 | if (!ret) { |
| 6063 | wl->irq_wake_enabled = true; |
| 6064 | device_init_wakeup(wl->dev, 1); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 6065 | if (pdata->pwr_in_suspend) |
| 6066 | wl->hw->wiphy->wowlan = &wlcore_wowlan_support; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6067 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 6068 | #endif |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6069 | disable_irq(wl->irq); |
| 6070 | |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 6071 | ret = wl12xx_get_hw_info(wl); |
| 6072 | if (ret < 0) { |
| 6073 | wl1271_error("couldn't get hw info"); |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 6074 | goto out_irq; |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | ret = wl->ops->identify_chip(wl); |
| 6078 | if (ret < 0) |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 6079 | goto out_irq; |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 6080 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6081 | ret = wl1271_init_ieee80211(wl); |
| 6082 | if (ret) |
| 6083 | goto out_irq; |
| 6084 | |
| 6085 | ret = wl1271_register_hw(wl); |
| 6086 | if (ret) |
| 6087 | goto out_irq; |
| 6088 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 6089 | /* Create sysfs file to control bt coex state */ |
| 6090 | ret = device_create_file(wl->dev, &dev_attr_bt_coex_state); |
| 6091 | if (ret < 0) { |
| 6092 | wl1271_error("failed to create sysfs file bt_coex_state"); |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 6093 | goto out_unreg; |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 6094 | } |
| 6095 | |
| 6096 | /* Create sysfs file to get HW PG version */ |
| 6097 | ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver); |
| 6098 | if (ret < 0) { |
| 6099 | wl1271_error("failed to create sysfs file hw_pg_ver"); |
| 6100 | goto out_bt_coex_state; |
| 6101 | } |
| 6102 | |
| 6103 | /* Create sysfs file for the FW log */ |
| 6104 | ret = device_create_bin_file(wl->dev, &fwlog_attr); |
| 6105 | if (ret < 0) { |
| 6106 | wl1271_error("failed to create sysfs file fwlog"); |
| 6107 | goto out_hw_pg_ver; |
| 6108 | } |
| 6109 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6110 | wl->initialized = true; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 6111 | goto out; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6112 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 6113 | out_hw_pg_ver: |
| 6114 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
| 6115 | |
| 6116 | out_bt_coex_state: |
| 6117 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
| 6118 | |
Luciano Coelho | 8b425e6 | 2012-06-25 14:41:20 +0300 | [diff] [blame] | 6119 | out_unreg: |
| 6120 | wl1271_unregister_hw(wl); |
| 6121 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6122 | out_irq: |
| 6123 | free_irq(wl->irq, wl); |
| 6124 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6125 | out_free_nvs: |
| 6126 | kfree(wl->nvs); |
| 6127 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6128 | out: |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6129 | release_firmware(fw); |
| 6130 | complete_all(&wl->nvs_loading_complete); |
| 6131 | } |
| 6132 | |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 6133 | int wlcore_probe(struct wl1271 *wl, struct platform_device *pdev) |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6134 | { |
| 6135 | int ret; |
| 6136 | |
| 6137 | if (!wl->ops || !wl->ptable) |
| 6138 | return -EINVAL; |
| 6139 | |
| 6140 | wl->dev = &pdev->dev; |
| 6141 | wl->pdev = pdev; |
| 6142 | platform_set_drvdata(pdev, wl); |
| 6143 | |
| 6144 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, |
| 6145 | WL12XX_NVS_NAME, &pdev->dev, GFP_KERNEL, |
| 6146 | wl, wlcore_nvs_cb); |
| 6147 | if (ret < 0) { |
| 6148 | wl1271_error("request_firmware_nowait failed: %d", ret); |
| 6149 | complete_all(&wl->nvs_loading_complete); |
| 6150 | } |
| 6151 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6152 | return ret; |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6153 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 6154 | EXPORT_SYMBOL_GPL(wlcore_probe); |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6155 | |
Bill Pemberton | b74324d | 2012-12-03 09:56:42 -0500 | [diff] [blame] | 6156 | int wlcore_remove(struct platform_device *pdev) |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6157 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6158 | struct wl1271 *wl = platform_get_drvdata(pdev); |
| 6159 | |
Ido Yariv | 6f8d6b2 | 2012-09-02 01:32:47 +0300 | [diff] [blame] | 6160 | wait_for_completion(&wl->nvs_loading_complete); |
| 6161 | if (!wl->initialized) |
| 6162 | return 0; |
| 6163 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6164 | if (wl->irq_wake_enabled) { |
| 6165 | device_init_wakeup(wl->dev, 0); |
| 6166 | disable_irq_wake(wl->irq); |
| 6167 | } |
| 6168 | wl1271_unregister_hw(wl); |
| 6169 | free_irq(wl->irq, wl); |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 6170 | wlcore_free_hw(wl); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 6171 | |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6172 | return 0; |
| 6173 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 6174 | EXPORT_SYMBOL_GPL(wlcore_remove); |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 6175 | |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 6176 | u32 wl12xx_debug_level = DEBUG_NONE; |
Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 6177 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 6178 | 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] | 6179 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); |
| 6180 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 6181 | module_param_named(fwlog, fwlog_param, charp, 0); |
Luciano Coelho | 2c882fa | 2012-02-07 12:37:33 +0200 | [diff] [blame] | 6182 | MODULE_PARM_DESC(fwlog, |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 6183 | "FW logger options: continuous, ondemand, dbgpins or disable"); |
| 6184 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 6185 | module_param(bug_on_recovery, int, S_IRUSR | S_IWUSR); |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 6186 | MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery"); |
| 6187 | |
Yair Shapira | 7230341 | 2012-11-26 18:05:50 +0200 | [diff] [blame] | 6188 | module_param(no_recovery, int, S_IRUSR | S_IWUSR); |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 6189 | MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck."); |
| 6190 | |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 6191 | MODULE_LICENSE("GPL"); |
Luciano Coelho | b1a48ca | 2011-02-22 14:19:28 +0200 | [diff] [blame] | 6192 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 6193 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |
Tim Gardner | 0635ad4 | 2012-08-29 13:09:33 -0600 | [diff] [blame] | 6194 | MODULE_FIRMWARE(WL12XX_NVS_NAME); |