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 | /* |
| 3 | * This file is part of wl1271 |
| 4 | * |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 5 | * Copyright (C) 2008-2010 Nokia Corporation |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 6 | * |
| 7 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * version 2 as published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 21 | * 02110-1301 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <linux/module.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 26 | #include <linux/firmware.h> |
| 27 | #include <linux/delay.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 28 | #include <linux/spi/spi.h> |
| 29 | #include <linux/crc32.h> |
| 30 | #include <linux/etherdevice.h> |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 31 | #include <linux/vmalloc.h> |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 34 | #include <linux/wl12xx.h> |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 35 | #include <linux/sched.h> |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 37 | |
Luciano Coelho | c31be25 | 2011-11-21 19:25:24 +0200 | [diff] [blame] | 38 | #include "wlcore.h" |
Luciano Coelho | 0f4e312 | 2011-10-07 11:02:42 +0300 | [diff] [blame] | 39 | #include "debug.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 40 | #include "wl12xx_80211.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 41 | #include "io.h" |
| 42 | #include "event.h" |
| 43 | #include "tx.h" |
| 44 | #include "rx.h" |
| 45 | #include "ps.h" |
| 46 | #include "init.h" |
| 47 | #include "debugfs.h" |
| 48 | #include "cmd.h" |
| 49 | #include "boot.h" |
| 50 | #include "testmode.h" |
| 51 | #include "scan.h" |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 52 | #include "hw_ops.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 54 | #define WL1271_BOOT_RETRIES 3 |
| 55 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 56 | #define WL1271_BOOT_RETRIES 3 |
Juuso Oikarinen | 8a08048 | 2009-10-13 12:47:44 +0300 | [diff] [blame] | 57 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 58 | static char *fwlog_param; |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 59 | static bool bug_on_recovery; |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 60 | static bool no_recovery; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 61 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 62 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 63 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 64 | bool reset_tx_queues); |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 65 | static void wl1271_op_stop(struct ieee80211_hw *hw); |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 66 | 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] | 67 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 68 | static int wl12xx_set_authorized(struct wl1271 *wl, |
| 69 | struct wl12xx_vif *wlvif) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 70 | { |
| 71 | int ret; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 72 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 73 | if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS)) |
| 74 | return -EINVAL; |
| 75 | |
| 76 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 77 | return 0; |
| 78 | |
Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 79 | if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags)) |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 80 | return 0; |
| 81 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 82 | ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid); |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 83 | if (ret < 0) |
| 84 | return ret; |
| 85 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 86 | wl12xx_croc(wl, wlvif->role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 87 | |
Eliad Peller | ef4b29e | 2011-06-06 13:03:12 +0300 | [diff] [blame] | 88 | wl1271_info("Association completed."); |
| 89 | return 0; |
| 90 | } |
Juuso Oikarinen | c2c192a | 2010-07-27 03:30:09 +0300 | [diff] [blame] | 91 | |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 92 | static int wl1271_reg_notify(struct wiphy *wiphy, |
Luciano Coelho | 573c67c | 2010-11-26 13:44:59 +0200 | [diff] [blame] | 93 | struct regulatory_request *request) |
| 94 | { |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 95 | struct ieee80211_supported_band *band; |
| 96 | struct ieee80211_channel *ch; |
| 97 | int i; |
| 98 | |
| 99 | band = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 100 | for (i = 0; i < band->n_channels; i++) { |
| 101 | ch = &band->channels[i]; |
| 102 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 103 | continue; |
| 104 | |
| 105 | if (ch->flags & IEEE80211_CHAN_RADAR) |
| 106 | ch->flags |= IEEE80211_CHAN_NO_IBSS | |
| 107 | IEEE80211_CHAN_PASSIVE_SCAN; |
| 108 | |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 114 | static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 115 | bool enable) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 116 | { |
| 117 | int ret = 0; |
| 118 | |
| 119 | /* we should hold wl->mutex */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 120 | ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 121 | if (ret < 0) |
| 122 | goto out; |
| 123 | |
| 124 | if (enable) |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 125 | set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 126 | else |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 127 | clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 128 | out: |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * this function is being called when the rx_streaming interval |
| 134 | * has beed changed or rx_streaming should be disabled |
| 135 | */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 136 | int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 137 | { |
| 138 | int ret = 0; |
| 139 | int period = wl->conf.rx_streaming.interval; |
| 140 | |
| 141 | /* don't reconfigure if rx_streaming is disabled */ |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 142 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 143 | goto out; |
| 144 | |
| 145 | /* reconfigure/disable according to new streaming_period */ |
| 146 | if (period && |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 147 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 148 | (wl->conf.rx_streaming.always || |
| 149 | test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 150 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 151 | else { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 152 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 153 | /* don't cancel_work_sync since we might deadlock */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 154 | del_timer_sync(&wlvif->rx_streaming_timer); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 155 | } |
| 156 | out: |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | static void wl1271_rx_streaming_enable_work(struct work_struct *work) |
| 161 | { |
| 162 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 163 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 164 | rx_streaming_enable_work); |
| 165 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 166 | |
| 167 | mutex_lock(&wl->mutex); |
| 168 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 169 | if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) || |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 170 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 171 | (!wl->conf.rx_streaming.always && |
| 172 | !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) |
| 173 | goto out; |
| 174 | |
| 175 | if (!wl->conf.rx_streaming.interval) |
| 176 | goto out; |
| 177 | |
| 178 | ret = wl1271_ps_elp_wakeup(wl); |
| 179 | if (ret < 0) |
| 180 | goto out; |
| 181 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 182 | ret = wl1271_set_rx_streaming(wl, wlvif, true); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 183 | if (ret < 0) |
| 184 | goto out_sleep; |
| 185 | |
| 186 | /* stop it after some time of inactivity */ |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 187 | mod_timer(&wlvif->rx_streaming_timer, |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 188 | jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); |
| 189 | |
| 190 | out_sleep: |
| 191 | wl1271_ps_elp_sleep(wl); |
| 192 | out: |
| 193 | mutex_unlock(&wl->mutex); |
| 194 | } |
| 195 | |
| 196 | static void wl1271_rx_streaming_disable_work(struct work_struct *work) |
| 197 | { |
| 198 | int ret; |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 199 | struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif, |
| 200 | rx_streaming_disable_work); |
| 201 | struct wl1271 *wl = wlvif->wl; |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 202 | |
| 203 | mutex_lock(&wl->mutex); |
| 204 | |
Eliad Peller | 0744bdb | 2011-10-10 10:13:05 +0200 | [diff] [blame] | 205 | if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags)) |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 206 | goto out; |
| 207 | |
| 208 | ret = wl1271_ps_elp_wakeup(wl); |
| 209 | if (ret < 0) |
| 210 | goto out; |
| 211 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 212 | ret = wl1271_set_rx_streaming(wl, wlvif, false); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 213 | if (ret) |
| 214 | goto out_sleep; |
| 215 | |
| 216 | out_sleep: |
| 217 | wl1271_ps_elp_sleep(wl); |
| 218 | out: |
| 219 | mutex_unlock(&wl->mutex); |
| 220 | } |
| 221 | |
| 222 | static void wl1271_rx_streaming_timer(unsigned long data) |
| 223 | { |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 224 | struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data; |
| 225 | struct wl1271 *wl = wlvif->wl; |
| 226 | ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 227 | } |
| 228 | |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 229 | /* wl->mutex must be taken */ |
| 230 | void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl) |
| 231 | { |
| 232 | /* if the watchdog is not armed, don't do anything */ |
| 233 | if (wl->tx_allocated_blocks == 0) |
| 234 | return; |
| 235 | |
| 236 | cancel_delayed_work(&wl->tx_watchdog_work); |
| 237 | ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work, |
| 238 | msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout)); |
| 239 | } |
| 240 | |
| 241 | static void wl12xx_tx_watchdog_work(struct work_struct *work) |
| 242 | { |
| 243 | struct delayed_work *dwork; |
| 244 | struct wl1271 *wl; |
| 245 | |
| 246 | dwork = container_of(work, struct delayed_work, work); |
| 247 | wl = container_of(dwork, struct wl1271, tx_watchdog_work); |
| 248 | |
| 249 | mutex_lock(&wl->mutex); |
| 250 | |
| 251 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 252 | goto out; |
| 253 | |
| 254 | /* Tx went out in the meantime - everything is ok */ |
| 255 | if (unlikely(wl->tx_allocated_blocks == 0)) |
| 256 | goto out; |
| 257 | |
| 258 | /* |
| 259 | * if a ROC is in progress, we might not have any Tx for a long |
| 260 | * time (e.g. pending Tx on the non-ROC channels) |
| 261 | */ |
| 262 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) { |
| 263 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC", |
| 264 | wl->conf.tx.tx_watchdog_timeout); |
| 265 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 266 | goto out; |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * if a scan is in progress, we might not have any Tx for a long |
| 271 | * time |
| 272 | */ |
| 273 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { |
| 274 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan", |
| 275 | wl->conf.tx.tx_watchdog_timeout); |
| 276 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 277 | goto out; |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | * AP might cache a frame for a long time for a sleeping station, |
| 282 | * so rearm the timer if there's an AP interface with stations. If |
| 283 | * Tx is genuinely stuck we will most hopefully discover it when all |
| 284 | * stations are removed due to inactivity. |
| 285 | */ |
| 286 | if (wl->active_sta_count) { |
| 287 | wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has " |
| 288 | " %d stations", |
| 289 | wl->conf.tx.tx_watchdog_timeout, |
| 290 | wl->active_sta_count); |
| 291 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 292 | goto out; |
| 293 | } |
| 294 | |
| 295 | wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery", |
| 296 | wl->conf.tx.tx_watchdog_timeout); |
| 297 | wl12xx_queue_recovery_work(wl); |
| 298 | |
| 299 | out: |
| 300 | mutex_unlock(&wl->mutex); |
| 301 | } |
| 302 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 303 | static void wlcore_adjust_conf(struct wl1271 *wl) |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 304 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 305 | /* Adjust settings according to optional module parameters */ |
| 306 | if (fwlog_param) { |
| 307 | if (!strcmp(fwlog_param, "continuous")) { |
| 308 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 309 | } else if (!strcmp(fwlog_param, "ondemand")) { |
| 310 | wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND; |
| 311 | } else if (!strcmp(fwlog_param, "dbgpins")) { |
| 312 | wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS; |
| 313 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS; |
| 314 | } else if (!strcmp(fwlog_param, "disable")) { |
| 315 | wl->conf.fwlog.mem_blocks = 0; |
| 316 | wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE; |
| 317 | } else { |
| 318 | wl1271_error("Unknown fwlog parameter %s", fwlog_param); |
| 319 | } |
| 320 | } |
| 321 | } |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 322 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 323 | static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, |
| 324 | struct wl12xx_vif *wlvif, |
| 325 | u8 hlid, u8 tx_pkts) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 326 | { |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 327 | bool fw_ps, single_sta; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 328 | |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 329 | fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 330 | single_sta = (wl->active_sta_count == 1); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 331 | |
| 332 | /* |
| 333 | * 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] | 334 | * packets in FW or if the STA is awake. |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 335 | */ |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 336 | if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 337 | wl12xx_ps_link_end(wl, wlvif, hlid); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 338 | |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 339 | /* |
| 340 | * Start high-level PS if the STA is asleep with enough blocks in FW. |
| 341 | * Make an exception if this is the only connected station. In this |
| 342 | * case FW-memory congestion is not a problem. |
| 343 | */ |
| 344 | else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 345 | wl12xx_ps_link_start(wl, wlvif, hlid, true); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 348 | static void wl12xx_irq_update_links_status(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 349 | struct wl12xx_vif *wlvif, |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 350 | struct wl_fw_status_2 *status) |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 351 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 352 | struct wl1271_link *lnk; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 353 | u32 cur_fw_ps_map; |
Arik Nemtsov | 9b17f1b | 2011-08-14 13:17:35 +0300 | [diff] [blame] | 354 | u8 hlid, cnt; |
| 355 | |
| 356 | /* TODO: also use link_fast_bitmap here */ |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 357 | |
| 358 | cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap); |
| 359 | if (wl->ap_fw_ps_map != cur_fw_ps_map) { |
| 360 | wl1271_debug(DEBUG_PSM, |
| 361 | "link ps prev 0x%x cur 0x%x changed 0x%x", |
| 362 | wl->ap_fw_ps_map, cur_fw_ps_map, |
| 363 | wl->ap_fw_ps_map ^ cur_fw_ps_map); |
| 364 | |
| 365 | wl->ap_fw_ps_map = cur_fw_ps_map; |
| 366 | } |
| 367 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 368 | for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) { |
| 369 | lnk = &wl->links[hlid]; |
Arik Nemtsov | 6bac40a | 2011-12-12 12:08:25 +0200 | [diff] [blame] | 370 | cnt = status->counters.tx_lnk_free_pkts[hlid] - |
| 371 | lnk->prev_freed_pkts; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 372 | |
Arik Nemtsov | 6bac40a | 2011-12-12 12:08:25 +0200 | [diff] [blame] | 373 | lnk->prev_freed_pkts = status->counters.tx_lnk_free_pkts[hlid]; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 374 | lnk->allocated_pkts -= cnt; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 375 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 376 | wl12xx_irq_ps_regulate_link(wl, wlvif, hlid, |
| 377 | lnk->allocated_pkts); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 381 | static int wlcore_fw_status(struct wl1271 *wl, |
| 382 | struct wl_fw_status_1 *status_1, |
| 383 | struct wl_fw_status_2 *status_2) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 384 | { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 385 | struct wl12xx_vif *wlvif; |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 386 | struct timespec ts; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 387 | u32 old_tx_blk_count = wl->tx_blocks_available; |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 388 | int avail, freed_blocks; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 389 | int i; |
Arik Nemtsov | 6bac40a | 2011-12-12 12:08:25 +0200 | [diff] [blame] | 390 | size_t status_len; |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 391 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 392 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 393 | status_len = WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) + |
| 394 | sizeof(*status_2) + wl->fw_status_priv_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 395 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 396 | ret = wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status_1, |
| 397 | status_len, false); |
| 398 | if (ret < 0) |
| 399 | return ret; |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 400 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 401 | wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " |
| 402 | "drv_rx_counter = %d, tx_results_counter = %d)", |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 403 | status_1->intr, |
| 404 | status_1->fw_rx_counter, |
| 405 | status_1->drv_rx_counter, |
| 406 | status_1->tx_results_counter); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 407 | |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 408 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 409 | /* prevent wrap-around in freed-packets counter */ |
Arik Nemtsov | 742246f | 2011-08-14 13:17:33 +0300 | [diff] [blame] | 410 | wl->tx_allocated_pkts[i] -= |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 411 | (status_2->counters.tx_released_pkts[i] - |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 412 | wl->tx_pkts_freed[i]) & 0xff; |
| 413 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 414 | wl->tx_pkts_freed[i] = status_2->counters.tx_released_pkts[i]; |
Arik Nemtsov | bf54e30 | 2011-08-14 13:17:32 +0300 | [diff] [blame] | 415 | } |
| 416 | |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 417 | /* prevent wrap-around in total blocks counter */ |
| 418 | if (likely(wl->tx_blocks_freed <= |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 419 | le32_to_cpu(status_2->total_released_blks))) |
| 420 | freed_blocks = le32_to_cpu(status_2->total_released_blks) - |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 421 | wl->tx_blocks_freed; |
| 422 | else |
| 423 | freed_blocks = 0x100000000LL - wl->tx_blocks_freed + |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 424 | le32_to_cpu(status_2->total_released_blks); |
Arik Nemtsov | bdf91cf | 2011-08-14 13:17:34 +0300 | [diff] [blame] | 425 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 426 | wl->tx_blocks_freed = le32_to_cpu(status_2->total_released_blks); |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 427 | |
Arik Nemtsov | 7bb5d6c | 2011-08-14 13:17:00 +0300 | [diff] [blame] | 428 | wl->tx_allocated_blocks -= freed_blocks; |
| 429 | |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 430 | /* |
| 431 | * If the FW freed some blocks: |
| 432 | * If we still have allocated blocks - re-arm the timer, Tx is |
| 433 | * not stuck. Otherwise, cancel the timer (no Tx currently). |
| 434 | */ |
| 435 | if (freed_blocks) { |
| 436 | if (wl->tx_allocated_blocks) |
| 437 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 438 | else |
| 439 | cancel_delayed_work(&wl->tx_watchdog_work); |
| 440 | } |
| 441 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 442 | avail = le32_to_cpu(status_2->tx_total) - wl->tx_allocated_blocks; |
Ido Yariv | d2f4d47 | 2011-03-31 10:07:00 +0200 | [diff] [blame] | 443 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 444 | /* |
| 445 | * The FW might change the total number of TX memblocks before |
| 446 | * we get a notification about blocks being released. Thus, the |
| 447 | * available blocks calculation might yield a temporary result |
| 448 | * which is lower than the actual available blocks. Keeping in |
| 449 | * mind that only blocks that were allocated can be moved from |
| 450 | * TX to RX, tx_blocks_available should never decrease here. |
| 451 | */ |
| 452 | wl->tx_blocks_available = max((int)wl->tx_blocks_available, |
| 453 | avail); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 454 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 455 | /* if more blocks are available now, tx work can be scheduled */ |
Shahar Levi | 13b107d | 2011-03-06 16:32:12 +0200 | [diff] [blame] | 456 | if (wl->tx_blocks_available > old_tx_blk_count) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 457 | clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 458 | |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 459 | /* 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] | 460 | wl12xx_for_each_wlvif_ap(wl, wlvif) { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 461 | wl12xx_irq_update_links_status(wl, wlvif, status_2); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 462 | } |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 463 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 464 | /* update the host-chipset time offset */ |
Juuso Oikarinen | ac5e1e3 | 2010-02-22 08:38:38 +0200 | [diff] [blame] | 465 | getnstimeofday(&ts); |
| 466 | wl->time_offset = (timespec_to_ns(&ts) >> 10) - |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 467 | (s64)le32_to_cpu(status_2->fw_localtime); |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 468 | |
| 469 | return 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 470 | } |
| 471 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 472 | static void wl1271_flush_deferred_work(struct wl1271 *wl) |
| 473 | { |
| 474 | struct sk_buff *skb; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 475 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 476 | /* Pass all received frames to the network stack */ |
| 477 | while ((skb = skb_dequeue(&wl->deferred_rx_queue))) |
| 478 | ieee80211_rx_ni(wl->hw, skb); |
| 479 | |
| 480 | /* Return sent skbs to the network stack */ |
| 481 | while ((skb = skb_dequeue(&wl->deferred_tx_queue))) |
Eliad Peller | c27d3ac | 2011-06-07 10:40:39 +0300 | [diff] [blame] | 482 | ieee80211_tx_status_ni(wl->hw, skb); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | static void wl1271_netstack_work(struct work_struct *work) |
| 486 | { |
| 487 | struct wl1271 *wl = |
| 488 | container_of(work, struct wl1271, netstack_work); |
| 489 | |
| 490 | do { |
| 491 | wl1271_flush_deferred_work(wl); |
| 492 | } while (skb_queue_len(&wl->deferred_rx_queue)); |
| 493 | } |
| 494 | |
| 495 | #define WL1271_IRQ_MAX_LOOPS 256 |
| 496 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 497 | static irqreturn_t wl1271_irq(int irq, void *cookie) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 498 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 499 | int ret; |
Juuso Oikarinen | c15f63b | 2009-10-12 15:08:50 +0300 | [diff] [blame] | 500 | u32 intr; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 501 | int loopcount = WL1271_IRQ_MAX_LOOPS; |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 502 | struct wl1271 *wl = (struct wl1271 *)cookie; |
| 503 | bool done = false; |
| 504 | unsigned int defer_count; |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 505 | unsigned long flags; |
| 506 | |
| 507 | /* TX might be handled here, avoid redundant work */ |
| 508 | set_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 509 | cancel_work_sync(&wl->tx_work); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 510 | |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 511 | /* |
| 512 | * In case edge triggered interrupt must be used, we cannot iterate |
| 513 | * more than once without introducing race conditions with the hardirq. |
| 514 | */ |
| 515 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 516 | loopcount = 1; |
| 517 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 518 | mutex_lock(&wl->mutex); |
| 519 | |
| 520 | wl1271_debug(DEBUG_IRQ, "IRQ work"); |
| 521 | |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 522 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 523 | goto out; |
| 524 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 525 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 526 | if (ret < 0) |
| 527 | goto out; |
| 528 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 529 | while (!done && loopcount--) { |
| 530 | /* |
| 531 | * In order to avoid a race with the hardirq, clear the flag |
| 532 | * before acknowledging the chip. Since the mutex is held, |
| 533 | * wl1271_ps_elp_wakeup cannot be called concurrently. |
| 534 | */ |
| 535 | clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 536 | smp_mb__after_clear_bit(); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 537 | |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 538 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
| 539 | if (ret < 0) { |
| 540 | wl12xx_queue_recovery_work(wl); |
| 541 | goto out; |
| 542 | } |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 543 | |
| 544 | wlcore_hw_tx_immediate_compl(wl); |
| 545 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 546 | intr = le32_to_cpu(wl->fw_status_1->intr); |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 547 | intr &= WLCORE_ALL_INTR_MASK; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 548 | if (!intr) { |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 549 | done = true; |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 550 | continue; |
| 551 | } |
| 552 | |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 553 | if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { |
Ido Reis | f5755fe | 2012-04-23 17:35:25 +0300 | [diff] [blame] | 554 | wl1271_error("HW watchdog interrupt received! starting recovery."); |
| 555 | wl->watchdog_recovery = true; |
| 556 | wl12xx_queue_recovery_work(wl); |
| 557 | |
| 558 | /* restarting the chip. ignore any other interrupt. */ |
| 559 | goto out; |
| 560 | } |
| 561 | |
| 562 | if (unlikely(intr & WL1271_ACX_SW_INTR_WATCHDOG)) { |
| 563 | wl1271_error("SW watchdog interrupt received! " |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 564 | "starting recovery."); |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 565 | wl->watchdog_recovery = true; |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 566 | wl12xx_queue_recovery_work(wl); |
Eliad Peller | ccc83b0 | 2010-10-27 14:09:57 +0200 | [diff] [blame] | 567 | |
| 568 | /* restarting the chip. ignore any other interrupt. */ |
| 569 | goto out; |
| 570 | } |
| 571 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 572 | if (likely(intr & WL1271_ACX_INTR_DATA)) { |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 573 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); |
| 574 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 575 | wl12xx_rx(wl, wl->fw_status_1); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 576 | |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 577 | /* Check if any tx blocks were freed */ |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 578 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 579 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 580 | wl1271_tx_total_queue_count(wl) > 0) { |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 581 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 582 | /* |
| 583 | * In order to avoid starvation of the TX path, |
| 584 | * call the work function directly. |
| 585 | */ |
Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 586 | wl1271_tx_work_locked(wl); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 587 | } else { |
| 588 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 589 | } |
| 590 | |
Ido Yariv | 8aad246 | 2011-03-01 15:14:38 +0200 | [diff] [blame] | 591 | /* check for tx results */ |
Arik Nemtsov | 53d67a5 | 2011-12-12 11:32:37 +0200 | [diff] [blame] | 592 | wlcore_hw_tx_delayed_compl(wl); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 593 | |
| 594 | /* Make sure the deferred queues don't get too long */ |
| 595 | defer_count = skb_queue_len(&wl->deferred_tx_queue) + |
| 596 | skb_queue_len(&wl->deferred_rx_queue); |
| 597 | if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT) |
| 598 | wl1271_flush_deferred_work(wl); |
Juuso Oikarinen | 1e73eb6 | 2010-02-22 08:38:37 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | if (intr & WL1271_ACX_INTR_EVENT_A) { |
| 602 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A"); |
| 603 | wl1271_event_handle(wl, 0); |
| 604 | } |
| 605 | |
| 606 | if (intr & WL1271_ACX_INTR_EVENT_B) { |
| 607 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B"); |
| 608 | wl1271_event_handle(wl, 1); |
| 609 | } |
| 610 | |
| 611 | if (intr & WL1271_ACX_INTR_INIT_COMPLETE) |
| 612 | wl1271_debug(DEBUG_IRQ, |
| 613 | "WL1271_ACX_INTR_INIT_COMPLETE"); |
| 614 | |
| 615 | if (intr & WL1271_ACX_INTR_HW_AVAILABLE) |
| 616 | wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 617 | } |
| 618 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 619 | wl1271_ps_elp_sleep(wl); |
| 620 | |
| 621 | out: |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 622 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 623 | /* In case TX was not handled here, queue TX work */ |
| 624 | clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags); |
| 625 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 626 | wl1271_tx_total_queue_count(wl) > 0) |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 627 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
| 628 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 629 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 630 | mutex_unlock(&wl->mutex); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 631 | |
| 632 | return IRQ_HANDLED; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 633 | } |
| 634 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 635 | struct vif_counter_data { |
| 636 | u8 counter; |
| 637 | |
| 638 | struct ieee80211_vif *cur_vif; |
| 639 | bool cur_vif_running; |
| 640 | }; |
| 641 | |
| 642 | static void wl12xx_vif_count_iter(void *data, u8 *mac, |
| 643 | struct ieee80211_vif *vif) |
| 644 | { |
| 645 | struct vif_counter_data *counter = data; |
| 646 | |
| 647 | counter->counter++; |
| 648 | if (counter->cur_vif == vif) |
| 649 | counter->cur_vif_running = true; |
| 650 | } |
| 651 | |
| 652 | /* caller must not hold wl->mutex, as it might deadlock */ |
| 653 | static void wl12xx_get_vif_count(struct ieee80211_hw *hw, |
| 654 | struct ieee80211_vif *cur_vif, |
| 655 | struct vif_counter_data *data) |
| 656 | { |
| 657 | memset(data, 0, sizeof(*data)); |
| 658 | data->cur_vif = cur_vif; |
| 659 | |
| 660 | ieee80211_iterate_active_interfaces(hw, |
| 661 | wl12xx_vif_count_iter, data); |
| 662 | } |
| 663 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 664 | static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 665 | { |
| 666 | const struct firmware *fw; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 667 | const char *fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 668 | enum wl12xx_fw_type fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 669 | int ret; |
| 670 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 671 | if (plt) { |
| 672 | fw_type = WL12XX_FW_TYPE_PLT; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 673 | fw_name = wl->plt_fw_name; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 674 | } else { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 675 | /* |
| 676 | * we can't call wl12xx_get_vif_count() here because |
| 677 | * wl->mutex is taken, so use the cached last_vif_count value |
| 678 | */ |
| 679 | if (wl->last_vif_count > 1) { |
| 680 | fw_type = WL12XX_FW_TYPE_MULTI; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 681 | fw_name = wl->mr_fw_name; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 682 | } else { |
| 683 | fw_type = WL12XX_FW_TYPE_NORMAL; |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 684 | fw_name = wl->sr_fw_name; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 685 | } |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | if (wl->fw_type == fw_type) |
| 689 | return 0; |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 690 | |
| 691 | wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); |
| 692 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 693 | ret = request_firmware(&fw, fw_name, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 694 | |
| 695 | if (ret < 0) { |
Pontus Fuchs | 3589893 | 2011-11-30 15:35:09 +0100 | [diff] [blame] | 696 | wl1271_error("could not get firmware %s: %d", fw_name, ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 697 | return ret; |
| 698 | } |
| 699 | |
| 700 | if (fw->size % 4) { |
| 701 | wl1271_error("firmware size is not multiple of 32 bits: %zu", |
| 702 | fw->size); |
| 703 | ret = -EILSEQ; |
| 704 | goto out; |
| 705 | } |
| 706 | |
Arik Nemtsov | 166d504 | 2010-10-16 21:44:57 +0200 | [diff] [blame] | 707 | vfree(wl->fw); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 708 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 709 | wl->fw_len = fw->size; |
Juuso Oikarinen | 1fba497 | 2009-10-08 21:56:32 +0300 | [diff] [blame] | 710 | wl->fw = vmalloc(wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 711 | |
| 712 | if (!wl->fw) { |
| 713 | wl1271_error("could not allocate memory for the firmware"); |
| 714 | ret = -ENOMEM; |
| 715 | goto out; |
| 716 | } |
| 717 | |
| 718 | memcpy(wl->fw, fw->data, wl->fw_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 719 | ret = 0; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 720 | wl->fw_type = fw_type; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 721 | out: |
| 722 | release_firmware(fw); |
| 723 | |
| 724 | return ret; |
| 725 | } |
| 726 | |
Arik Nemtsov | 3e3947f | 2012-05-29 18:38:05 +0300 | [diff] [blame] | 727 | static void wl1271_fetch_nvs(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 728 | { |
| 729 | const struct firmware *fw; |
| 730 | int ret; |
| 731 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 732 | ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 733 | |
| 734 | if (ret < 0) { |
Arik Nemtsov | 3e3947f | 2012-05-29 18:38:05 +0300 | [diff] [blame] | 735 | wl1271_debug(DEBUG_BOOT, "could not get nvs file %s: %d", |
| 736 | WL12XX_NVS_NAME, ret); |
| 737 | return; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 738 | } |
| 739 | |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 740 | wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 741 | |
| 742 | if (!wl->nvs) { |
| 743 | wl1271_error("could not allocate memory for the nvs file"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 744 | goto out; |
| 745 | } |
| 746 | |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 747 | wl->nvs_len = fw->size; |
| 748 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 749 | out: |
| 750 | release_firmware(fw); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 751 | } |
| 752 | |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 753 | void wl12xx_queue_recovery_work(struct wl1271 *wl) |
| 754 | { |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 755 | /* Avoid a recursive recovery */ |
| 756 | if (!test_and_set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 757 | wlcore_disable_interrupts_nosync(wl); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 758 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 759 | } |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 760 | } |
| 761 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 762 | size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen) |
| 763 | { |
| 764 | size_t len = 0; |
| 765 | |
| 766 | /* The FW log is a length-value list, find where the log end */ |
| 767 | while (len < maxlen) { |
| 768 | if (memblock[len] == 0) |
| 769 | break; |
| 770 | if (len + memblock[len] + 1 > maxlen) |
| 771 | break; |
| 772 | len += memblock[len] + 1; |
| 773 | } |
| 774 | |
| 775 | /* Make sure we have enough room */ |
| 776 | len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size)); |
| 777 | |
| 778 | /* Fill the FW log file, consumed by the sysfs fwlog entry */ |
| 779 | memcpy(wl->fwlog + wl->fwlog_size, memblock, len); |
| 780 | wl->fwlog_size += len; |
| 781 | |
| 782 | return len; |
| 783 | } |
| 784 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 785 | #define WLCORE_FW_LOG_END 0x2000000 |
| 786 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 787 | static void wl12xx_read_fwlog_panic(struct wl1271 *wl) |
| 788 | { |
| 789 | u32 addr; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 790 | u32 offset; |
| 791 | u32 end_of_log; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 792 | u8 *block; |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 793 | int ret; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 794 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 795 | if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) || |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 796 | (wl->conf.fwlog.mem_blocks == 0)) |
| 797 | return; |
| 798 | |
| 799 | wl1271_info("Reading FW panic log"); |
| 800 | |
| 801 | block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL); |
| 802 | if (!block) |
| 803 | return; |
| 804 | |
| 805 | /* |
| 806 | * Make sure the chip is awake and the logger isn't active. |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 807 | * Do not send a stop fwlog command if the fw is hanged. |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 808 | */ |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 809 | if (wl1271_ps_elp_wakeup(wl)) |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 810 | goto out; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 811 | if (!wl->watchdog_recovery) |
| 812 | wl12xx_cmd_stop_fwlog(wl); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 813 | |
| 814 | /* Read the first memory block address */ |
Ido Yariv | 8b7c0fc | 2012-06-17 21:59:42 +0300 | [diff] [blame^] | 815 | ret = wlcore_fw_status(wl, wl->fw_status_1, wl->fw_status_2); |
| 816 | if (ret < 0) |
| 817 | goto out; |
| 818 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 819 | addr = le32_to_cpu(wl->fw_status_2->log_start_addr); |
| 820 | if (!addr) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 821 | goto out; |
| 822 | |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 823 | if (wl->conf.fwlog.mode == WL12XX_FWLOG_CONTINUOUS) { |
| 824 | offset = sizeof(addr) + sizeof(struct wl1271_rx_descriptor); |
| 825 | end_of_log = WLCORE_FW_LOG_END; |
| 826 | } else { |
| 827 | offset = sizeof(addr); |
| 828 | end_of_log = addr; |
| 829 | } |
| 830 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 831 | /* Traverse the memory blocks linked list */ |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 832 | do { |
| 833 | memset(block, 0, WL12XX_HW_BLOCK_SIZE); |
| 834 | wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE, |
| 835 | false); |
| 836 | |
| 837 | /* |
| 838 | * Memory blocks are linked to one another. The first 4 bytes |
| 839 | * of each memory block hold the hardware address of the next |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 840 | * one. The last memory block points to the first one in |
| 841 | * on demand mode and is equal to 0x2000000 in continuous mode. |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 842 | */ |
Eliad Peller | 4d56ad9 | 2011-08-14 13:17:05 +0300 | [diff] [blame] | 843 | addr = le32_to_cpup((__le32 *)block); |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 844 | if (!wl12xx_copy_fwlog(wl, block + offset, |
| 845 | WL12XX_HW_BLOCK_SIZE - offset)) |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 846 | break; |
Igal Chernobelsky | 1e41213 | 2012-06-18 11:05:39 +0300 | [diff] [blame] | 847 | } while (addr && (addr != end_of_log)); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 848 | |
| 849 | wake_up_interruptible(&wl->fwlog_waitq); |
| 850 | |
| 851 | out: |
| 852 | kfree(block); |
| 853 | } |
| 854 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 855 | static void wl1271_recovery_work(struct work_struct *work) |
| 856 | { |
| 857 | struct wl1271 *wl = |
| 858 | container_of(work, struct wl1271, recovery_work); |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 859 | struct wl12xx_vif *wlvif; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 860 | struct ieee80211_vif *vif; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 861 | |
| 862 | mutex_lock(&wl->mutex); |
| 863 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 864 | if (wl->state != WL1271_STATE_ON || wl->plt) |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 865 | goto out_unlock; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 866 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 867 | wl12xx_read_fwlog_panic(wl); |
| 868 | |
Arik Nemtsov | 1c351da | 2012-05-10 12:13:39 +0300 | [diff] [blame] | 869 | /* change partitions momentarily so we can read the FW pc */ |
| 870 | wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
Luciano Coelho | 06bba80 | 2012-05-10 12:14:12 +0300 | [diff] [blame] | 871 | wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x " |
| 872 | "hint_sts: 0x%08x", |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 873 | wl->chip.fw_ver_str, |
Luciano Coelho | 06bba80 | 2012-05-10 12:14:12 +0300 | [diff] [blame] | 874 | wlcore_read_reg(wl, REG_PC_ON_RECOVERY), |
| 875 | wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR)); |
Arik Nemtsov | 1c351da | 2012-05-10 12:13:39 +0300 | [diff] [blame] | 876 | wlcore_set_partition(wl, &wl->ptable[PART_WORK]); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 877 | |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 878 | BUG_ON(bug_on_recovery && |
| 879 | !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 880 | |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 881 | if (no_recovery) { |
| 882 | wl1271_info("No recovery (chosen on module load). Fw will remain stuck."); |
| 883 | clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); |
| 884 | goto out_unlock; |
| 885 | } |
| 886 | |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 887 | /* |
| 888 | * Advance security sequence number to overcome potential progress |
| 889 | * in the firmware during recovery. This doens't hurt if the network is |
| 890 | * not encrypted. |
| 891 | */ |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 892 | wl12xx_for_each_wlvif(wl, wlvif) { |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 893 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) || |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 894 | test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 895 | wlvif->tx_security_seq += |
| 896 | WL1271_TX_SQN_POST_RECOVERY_PADDING; |
| 897 | } |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 898 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 899 | /* Prevent spurious TX during FW restart */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 900 | wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 901 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 902 | if (wl->sched_scanning) { |
| 903 | ieee80211_sched_scan_stopped(wl->hw); |
| 904 | wl->sched_scanning = false; |
| 905 | } |
| 906 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 907 | /* reboot the chipset */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 908 | while (!list_empty(&wl->wlvif_list)) { |
| 909 | wlvif = list_first_entry(&wl->wlvif_list, |
| 910 | struct wl12xx_vif, list); |
| 911 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 912 | __wl1271_op_remove_interface(wl, vif, false); |
| 913 | } |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 914 | wl->watchdog_recovery = false; |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 915 | mutex_unlock(&wl->mutex); |
| 916 | wl1271_op_stop(wl->hw); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 917 | |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 918 | ieee80211_restart_hw(wl->hw); |
| 919 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 920 | /* |
| 921 | * Its safe to enable TX now - the queues are stopped after a request |
| 922 | * to restart the HW. |
| 923 | */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 924 | wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART); |
Eliad Peller | f027743 | 2011-10-10 10:13:14 +0200 | [diff] [blame] | 925 | return; |
| 926 | out_unlock: |
Yoni Divinsky | afbe371 | 2012-05-16 11:34:18 +0300 | [diff] [blame] | 927 | wl->watchdog_recovery = false; |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 928 | mutex_unlock(&wl->mutex); |
| 929 | } |
| 930 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 931 | static void wl1271_fw_wakeup(struct wl1271 *wl) |
| 932 | { |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 933 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | static int wl1271_setup(struct wl1271 *wl) |
| 937 | { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 938 | 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] | 939 | sizeof(*wl->fw_status_2) + |
| 940 | wl->fw_status_priv_len, GFP_KERNEL); |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 941 | if (!wl->fw_status_1) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 942 | return -ENOMEM; |
| 943 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 944 | wl->fw_status_2 = (struct wl_fw_status_2 *) |
| 945 | (((u8 *) wl->fw_status_1) + |
| 946 | WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc)); |
| 947 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 948 | wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); |
| 949 | if (!wl->tx_res_if) { |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 950 | kfree(wl->fw_status_1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 951 | return -ENOMEM; |
| 952 | } |
| 953 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 954 | return 0; |
| 955 | } |
| 956 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 957 | static int wl12xx_set_power_on(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 958 | { |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 959 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 960 | |
Juuso Oikarinen | 01ac17e | 2009-12-11 15:41:02 +0200 | [diff] [blame] | 961 | msleep(WL1271_PRE_POWER_ON_SLEEP); |
Ohad Ben-Cohen | 2cc78ff | 2010-09-16 01:22:04 +0200 | [diff] [blame] | 962 | ret = wl1271_power_on(wl); |
| 963 | if (ret < 0) |
| 964 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 965 | msleep(WL1271_POWER_ON_SLEEP); |
Teemu Paasikivi | 9b28072 | 2010-02-18 13:25:56 +0200 | [diff] [blame] | 966 | wl1271_io_reset(wl); |
| 967 | wl1271_io_init(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 968 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 969 | wlcore_set_partition(wl, &wl->ptable[PART_BOOT]); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 970 | |
| 971 | /* ELP module wake up */ |
| 972 | wl1271_fw_wakeup(wl); |
| 973 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 974 | out: |
| 975 | return ret; |
| 976 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 977 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 978 | static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt) |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 979 | { |
| 980 | int ret = 0; |
| 981 | |
| 982 | ret = wl12xx_set_power_on(wl); |
| 983 | if (ret < 0) |
| 984 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 985 | |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 986 | /* |
| 987 | * For wl127x based devices we could use the default block |
| 988 | * size (512 bytes), but due to a bug in the sdio driver, we |
| 989 | * need to set it explicitly after the chip is powered on. To |
| 990 | * simplify the code and since the performance impact is |
| 991 | * negligible, we use the same block size for all different |
| 992 | * chip types. |
Luciano Coelho | b5d6d9b | 2012-06-05 00:02:25 +0300 | [diff] [blame] | 993 | * |
| 994 | * Check if the bus supports blocksize alignment and, if it |
| 995 | * doesn't, make sure we don't have the quirk. |
Luciano Coelho | e62c9ce | 2011-11-03 08:44:42 +0200 | [diff] [blame] | 996 | */ |
Luciano Coelho | b5d6d9b | 2012-06-05 00:02:25 +0300 | [diff] [blame] | 997 | if (!wl1271_set_block_size(wl)) |
| 998 | wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 999 | |
Luciano Coelho | 6f7dd16 | 2011-11-29 16:27:31 +0200 | [diff] [blame] | 1000 | /* TODO: make sure the lower driver has set things up correctly */ |
| 1001 | |
| 1002 | ret = wl1271_setup(wl); |
| 1003 | if (ret < 0) |
| 1004 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1005 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1006 | ret = wl12xx_fetch_firmware(wl, plt); |
| 1007 | if (ret < 0) |
| 1008 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1009 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1010 | out: |
| 1011 | return ret; |
| 1012 | } |
| 1013 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1014 | int wl1271_plt_start(struct wl1271 *wl) |
| 1015 | { |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1016 | int retries = WL1271_BOOT_RETRIES; |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1017 | struct wiphy *wiphy = wl->hw->wiphy; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1018 | int ret; |
| 1019 | |
| 1020 | mutex_lock(&wl->mutex); |
| 1021 | |
| 1022 | wl1271_notice("power up"); |
| 1023 | |
| 1024 | if (wl->state != WL1271_STATE_OFF) { |
| 1025 | wl1271_error("cannot go into PLT state because not " |
| 1026 | "in off state: %d", wl->state); |
| 1027 | ret = -EBUSY; |
| 1028 | goto out; |
| 1029 | } |
| 1030 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1031 | while (retries) { |
| 1032 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1033 | ret = wl12xx_chip_wakeup(wl, true); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1034 | if (ret < 0) |
| 1035 | goto power_off; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1036 | |
Luciano Coelho | c331b34 | 2012-05-10 12:13:49 +0300 | [diff] [blame] | 1037 | ret = wl->ops->plt_init(wl); |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1038 | if (ret < 0) |
| 1039 | goto power_off; |
| 1040 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1041 | wl->plt = true; |
| 1042 | wl->state = WL1271_STATE_ON; |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1043 | wl1271_notice("firmware booted in PLT mode (%s)", |
Levi, Shahar | 4b7fac7 | 2011-01-23 07:27:22 +0100 | [diff] [blame] | 1044 | wl->chip.fw_ver_str); |
Luciano Coelho | e7ddf54 | 2011-03-10 15:24:57 +0200 | [diff] [blame] | 1045 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 1046 | /* update hw/fw version info in wiphy struct */ |
| 1047 | wiphy->hw_version = wl->chip.id; |
| 1048 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 1049 | sizeof(wiphy->fw_version)); |
| 1050 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1051 | goto out; |
| 1052 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1053 | power_off: |
| 1054 | wl1271_power_off(wl); |
| 1055 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1056 | |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 1057 | wl1271_error("firmware boot in PLT mode failed despite %d retries", |
| 1058 | WL1271_BOOT_RETRIES); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1059 | out: |
| 1060 | mutex_unlock(&wl->mutex); |
| 1061 | |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1065 | int wl1271_plt_stop(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1066 | { |
| 1067 | int ret = 0; |
| 1068 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1069 | wl1271_notice("power down"); |
| 1070 | |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1071 | /* |
| 1072 | * Interrupts must be disabled before setting the state to OFF. |
| 1073 | * Otherwise, the interrupt handler might be called and exit without |
| 1074 | * reading the interrupt status. |
| 1075 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1076 | wlcore_disable_interrupts(wl); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1077 | mutex_lock(&wl->mutex); |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1078 | if (!wl->plt) { |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1079 | mutex_unlock(&wl->mutex); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1080 | |
| 1081 | /* |
| 1082 | * This will not necessarily enable interrupts as interrupts |
| 1083 | * may have been disabled when op_stop was called. It will, |
| 1084 | * however, balance the above call to disable_interrupts(). |
| 1085 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1086 | wlcore_enable_interrupts(wl); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1087 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1088 | wl1271_error("cannot power down because not in PLT " |
| 1089 | "state: %d", wl->state); |
| 1090 | ret = -EBUSY; |
| 1091 | goto out; |
| 1092 | } |
| 1093 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1094 | mutex_unlock(&wl->mutex); |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 1095 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 1096 | wl1271_flush_deferred_work(wl); |
| 1097 | cancel_work_sync(&wl->netstack_work); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 1098 | cancel_work_sync(&wl->recovery_work); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1099 | cancel_delayed_work_sync(&wl->elp_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1100 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
Bartosz.Markowski@tieto.com | 5f561f6 | 2012-04-26 10:35:07 +0300 | [diff] [blame] | 1101 | cancel_delayed_work_sync(&wl->connection_loss_work); |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1102 | |
| 1103 | mutex_lock(&wl->mutex); |
| 1104 | wl1271_power_off(wl); |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1105 | wl->flags = 0; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 1106 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1107 | wl->state = WL1271_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1108 | wl->plt = false; |
Luciano Coelho | f6fbecc | 2012-01-11 09:42:42 +0200 | [diff] [blame] | 1109 | wl->rx_counter = 0; |
Ido Yariv | a454969 | 2012-01-11 09:42:40 +0200 | [diff] [blame] | 1110 | mutex_unlock(&wl->mutex); |
| 1111 | |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 1112 | out: |
| 1113 | return ret; |
| 1114 | } |
Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 1115 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1116 | static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1117 | { |
| 1118 | struct wl1271 *wl = hw->priv; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1119 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1120 | struct ieee80211_vif *vif = info->control.vif; |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1121 | struct wl12xx_vif *wlvif = NULL; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1122 | unsigned long flags; |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1123 | int q, mapping; |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1124 | u8 hlid; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1125 | |
Eliad Peller | 0f16801 | 2011-10-11 13:52:25 +0200 | [diff] [blame] | 1126 | if (vif) |
| 1127 | wlvif = wl12xx_vif_to_data(vif); |
| 1128 | |
Arik Nemtsov | 708bb3c | 2011-06-24 13:03:37 +0300 | [diff] [blame] | 1129 | mapping = skb_get_queue_mapping(skb); |
| 1130 | q = wl1271_tx_get_queue(mapping); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1131 | |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1132 | hlid = wl12xx_tx_get_hlid(wl, wlvif, skb); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1133 | |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 1134 | spin_lock_irqsave(&wl->wl_lock, flags); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1135 | |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1136 | /* |
| 1137 | * drop the packet if the link is invalid or the queue is stopped |
| 1138 | * for any reason but watermark. Watermark is a "soft"-stop so we |
| 1139 | * allow these packets through. |
| 1140 | */ |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1141 | if (hlid == WL12XX_INVALID_LINK_ID || |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1142 | (wlvif && !test_bit(hlid, wlvif->links_map)) || |
| 1143 | (wlcore_is_queue_stopped(wl, q) && |
| 1144 | !wlcore_is_queue_stopped_by_reason(wl, q, |
| 1145 | WLCORE_QUEUE_STOP_REASON_WATERMARK))) { |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1146 | wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); |
Eliad Peller | 5de8eef | 2011-12-13 15:26:38 +0200 | [diff] [blame] | 1147 | ieee80211_free_txskb(hw, skb); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1148 | goto out; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 1149 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1150 | |
Eliad Peller | 8ccd16e | 2012-03-04 10:55:55 +0200 | [diff] [blame] | 1151 | wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d", |
| 1152 | hlid, q, skb->len); |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 1153 | skb_queue_tail(&wl->links[hlid].tx_queue[q], skb); |
| 1154 | |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1155 | wl->tx_queue_count[q]++; |
| 1156 | |
| 1157 | /* |
| 1158 | * The workqueue is slow to process the tx_queue and we need stop |
| 1159 | * the queue here, otherwise the queue will get too long. |
| 1160 | */ |
| 1161 | if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) { |
| 1162 | wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1163 | wlcore_stop_queue_locked(wl, q, |
| 1164 | WLCORE_QUEUE_STOP_REASON_WATERMARK); |
Arik Nemtsov | 04b4d69 | 2011-08-14 13:17:39 +0300 | [diff] [blame] | 1165 | } |
| 1166 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1167 | /* |
| 1168 | * The chip specific setup must run before the first TX packet - |
| 1169 | * before that, the tx_work will not be initialized! |
| 1170 | */ |
| 1171 | |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1172 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) && |
| 1173 | !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags)) |
Ido Yariv | a522550 | 2010-10-12 14:49:10 +0200 | [diff] [blame] | 1174 | ieee80211_queue_work(wl->hw, &wl->tx_work); |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1175 | |
Arik Nemtsov | 04216da | 2011-08-14 13:17:38 +0300 | [diff] [blame] | 1176 | out: |
Ido Yariv | b07d403 | 2011-03-01 15:14:43 +0200 | [diff] [blame] | 1177 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1178 | } |
| 1179 | |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1180 | int wl1271_tx_dummy_packet(struct wl1271 *wl) |
| 1181 | { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1182 | unsigned long flags; |
Arik Nemtsov | 1462378 | 2011-08-28 15:11:57 +0300 | [diff] [blame] | 1183 | int q; |
| 1184 | |
| 1185 | /* no need to queue a new dummy packet if one is already pending */ |
| 1186 | if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) |
| 1187 | return 0; |
| 1188 | |
| 1189 | q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1190 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1191 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1192 | set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 1193 | wl->tx_queue_count[q]++; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1194 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 1195 | |
| 1196 | /* The FW is low on RX memory blocks, so send the dummy packet asap */ |
| 1197 | if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags)) |
Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 1198 | wl1271_tx_work_locked(wl); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1199 | |
| 1200 | /* |
| 1201 | * If the FW TX is busy, TX work will be scheduled by the threaded |
| 1202 | * interrupt handler function |
| 1203 | */ |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | /* |
| 1208 | * The size of the dummy packet should be at least 1400 bytes. However, in |
| 1209 | * order to minimize the number of bus transactions, aligning it to 512 bytes |
| 1210 | * boundaries could be beneficial, performance wise |
| 1211 | */ |
| 1212 | #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512)) |
| 1213 | |
Luciano Coelho | cf27d86 | 2011-04-01 21:08:23 +0300 | [diff] [blame] | 1214 | static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl) |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1215 | { |
| 1216 | struct sk_buff *skb; |
| 1217 | struct ieee80211_hdr_3addr *hdr; |
| 1218 | unsigned int dummy_packet_size; |
| 1219 | |
| 1220 | dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE - |
| 1221 | sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr); |
| 1222 | |
| 1223 | skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1224 | if (!skb) { |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1225 | wl1271_warning("Failed to allocate a dummy packet skb"); |
| 1226 | return NULL; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr)); |
| 1230 | |
| 1231 | hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr)); |
| 1232 | memset(hdr, 0, sizeof(*hdr)); |
| 1233 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1234 | IEEE80211_STYPE_NULLFUNC | |
| 1235 | IEEE80211_FCTL_TODS); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1236 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1237 | memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1238 | |
Luciano Coelho | 18b92ff | 2011-03-21 16:35:21 +0200 | [diff] [blame] | 1239 | /* Dummy packets require the TID to be management */ |
| 1240 | skb->priority = WL1271_TID_MGMT; |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1241 | |
| 1242 | /* Initialize all fields that might be used */ |
Hauke Mehrtens | 86c438f | 2011-04-26 23:27:44 +0200 | [diff] [blame] | 1243 | skb_set_queue_mapping(skb, 0); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1244 | memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info)); |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1245 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1246 | return skb; |
Shahar Levi | ae47c45 | 2011-03-06 16:32:14 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 1249 | |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1250 | #ifdef CONFIG_PM |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 1251 | static int |
| 1252 | wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p) |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1253 | { |
| 1254 | int num_fields = 0, in_field = 0, fields_size = 0; |
| 1255 | int i, pattern_len = 0; |
| 1256 | |
| 1257 | if (!p->mask) { |
| 1258 | wl1271_warning("No mask in WoWLAN pattern"); |
| 1259 | return -EINVAL; |
| 1260 | } |
| 1261 | |
| 1262 | /* |
| 1263 | * The pattern is broken up into segments of bytes at different offsets |
| 1264 | * that need to be checked by the FW filter. Each segment is called |
| 1265 | * a field in the FW API. We verify that the total number of fields |
| 1266 | * required for this pattern won't exceed FW limits (8) |
| 1267 | * as well as the total fields buffer won't exceed the FW limit. |
| 1268 | * Note that if there's a pattern which crosses Ethernet/IP header |
| 1269 | * boundary a new field is required. |
| 1270 | */ |
| 1271 | for (i = 0; i < p->pattern_len; i++) { |
| 1272 | if (test_bit(i, (unsigned long *)p->mask)) { |
| 1273 | if (!in_field) { |
| 1274 | in_field = 1; |
| 1275 | pattern_len = 1; |
| 1276 | } else { |
| 1277 | if (i == WL1271_RX_FILTER_ETH_HEADER_SIZE) { |
| 1278 | num_fields++; |
| 1279 | fields_size += pattern_len + |
| 1280 | RX_FILTER_FIELD_OVERHEAD; |
| 1281 | pattern_len = 1; |
| 1282 | } else |
| 1283 | pattern_len++; |
| 1284 | } |
| 1285 | } else { |
| 1286 | if (in_field) { |
| 1287 | in_field = 0; |
| 1288 | fields_size += pattern_len + |
| 1289 | RX_FILTER_FIELD_OVERHEAD; |
| 1290 | num_fields++; |
| 1291 | } |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | if (in_field) { |
| 1296 | fields_size += pattern_len + RX_FILTER_FIELD_OVERHEAD; |
| 1297 | num_fields++; |
| 1298 | } |
| 1299 | |
| 1300 | if (num_fields > WL1271_RX_FILTER_MAX_FIELDS) { |
| 1301 | wl1271_warning("RX Filter too complex. Too many segments"); |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
| 1305 | if (fields_size > WL1271_RX_FILTER_MAX_FIELDS_SIZE) { |
| 1306 | wl1271_warning("RX filter pattern is too big"); |
| 1307 | return -E2BIG; |
| 1308 | } |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
Eyal Shapira | a6eab0c | 2012-03-14 06:32:07 +0200 | [diff] [blame] | 1313 | struct wl12xx_rx_filter *wl1271_rx_filter_alloc(void) |
| 1314 | { |
| 1315 | return kzalloc(sizeof(struct wl12xx_rx_filter), GFP_KERNEL); |
| 1316 | } |
| 1317 | |
| 1318 | void wl1271_rx_filter_free(struct wl12xx_rx_filter *filter) |
| 1319 | { |
| 1320 | int i; |
| 1321 | |
| 1322 | if (filter == NULL) |
| 1323 | return; |
| 1324 | |
| 1325 | for (i = 0; i < filter->num_fields; i++) |
| 1326 | kfree(filter->fields[i].pattern); |
| 1327 | |
| 1328 | kfree(filter); |
| 1329 | } |
| 1330 | |
| 1331 | int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter *filter, |
| 1332 | u16 offset, u8 flags, |
| 1333 | u8 *pattern, u8 len) |
| 1334 | { |
| 1335 | struct wl12xx_rx_filter_field *field; |
| 1336 | |
| 1337 | if (filter->num_fields == WL1271_RX_FILTER_MAX_FIELDS) { |
| 1338 | wl1271_warning("Max fields per RX filter. can't alloc another"); |
| 1339 | return -EINVAL; |
| 1340 | } |
| 1341 | |
| 1342 | field = &filter->fields[filter->num_fields]; |
| 1343 | |
| 1344 | field->pattern = kzalloc(len, GFP_KERNEL); |
| 1345 | if (!field->pattern) { |
| 1346 | wl1271_warning("Failed to allocate RX filter pattern"); |
| 1347 | return -ENOMEM; |
| 1348 | } |
| 1349 | |
| 1350 | filter->num_fields++; |
| 1351 | |
| 1352 | field->offset = cpu_to_le16(offset); |
| 1353 | field->flags = flags; |
| 1354 | field->len = len; |
| 1355 | memcpy(field->pattern, pattern, len); |
| 1356 | |
| 1357 | return 0; |
| 1358 | } |
| 1359 | |
| 1360 | int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter *filter) |
| 1361 | { |
| 1362 | int i, fields_size = 0; |
| 1363 | |
| 1364 | for (i = 0; i < filter->num_fields; i++) |
| 1365 | fields_size += filter->fields[i].len + |
| 1366 | sizeof(struct wl12xx_rx_filter_field) - |
| 1367 | sizeof(u8 *); |
| 1368 | |
| 1369 | return fields_size; |
| 1370 | } |
| 1371 | |
| 1372 | void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter, |
| 1373 | u8 *buf) |
| 1374 | { |
| 1375 | int i; |
| 1376 | struct wl12xx_rx_filter_field *field; |
| 1377 | |
| 1378 | for (i = 0; i < filter->num_fields; i++) { |
| 1379 | field = (struct wl12xx_rx_filter_field *)buf; |
| 1380 | |
| 1381 | field->offset = filter->fields[i].offset; |
| 1382 | field->flags = filter->fields[i].flags; |
| 1383 | field->len = filter->fields[i].len; |
| 1384 | |
| 1385 | memcpy(&field->pattern, filter->fields[i].pattern, field->len); |
| 1386 | buf += sizeof(struct wl12xx_rx_filter_field) - |
| 1387 | sizeof(u8 *) + field->len; |
| 1388 | } |
| 1389 | } |
| 1390 | |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1391 | /* |
| 1392 | * Allocates an RX filter returned through f |
| 1393 | * which needs to be freed using rx_filter_free() |
| 1394 | */ |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 1395 | static int wl1271_convert_wowlan_pattern_to_rx_filter( |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1396 | struct cfg80211_wowlan_trig_pkt_pattern *p, |
| 1397 | struct wl12xx_rx_filter **f) |
| 1398 | { |
| 1399 | int i, j, ret = 0; |
| 1400 | struct wl12xx_rx_filter *filter; |
| 1401 | u16 offset; |
| 1402 | u8 flags, len; |
| 1403 | |
| 1404 | filter = wl1271_rx_filter_alloc(); |
| 1405 | if (!filter) { |
| 1406 | wl1271_warning("Failed to alloc rx filter"); |
| 1407 | ret = -ENOMEM; |
| 1408 | goto err; |
| 1409 | } |
| 1410 | |
| 1411 | i = 0; |
| 1412 | while (i < p->pattern_len) { |
| 1413 | if (!test_bit(i, (unsigned long *)p->mask)) { |
| 1414 | i++; |
| 1415 | continue; |
| 1416 | } |
| 1417 | |
| 1418 | for (j = i; j < p->pattern_len; j++) { |
| 1419 | if (!test_bit(j, (unsigned long *)p->mask)) |
| 1420 | break; |
| 1421 | |
| 1422 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE && |
| 1423 | j >= WL1271_RX_FILTER_ETH_HEADER_SIZE) |
| 1424 | break; |
| 1425 | } |
| 1426 | |
| 1427 | if (i < WL1271_RX_FILTER_ETH_HEADER_SIZE) { |
| 1428 | offset = i; |
| 1429 | flags = WL1271_RX_FILTER_FLAG_ETHERNET_HEADER; |
| 1430 | } else { |
| 1431 | offset = i - WL1271_RX_FILTER_ETH_HEADER_SIZE; |
| 1432 | flags = WL1271_RX_FILTER_FLAG_IP_HEADER; |
| 1433 | } |
| 1434 | |
| 1435 | len = j - i; |
| 1436 | |
| 1437 | ret = wl1271_rx_filter_alloc_field(filter, |
| 1438 | offset, |
| 1439 | flags, |
| 1440 | &p->pattern[i], len); |
| 1441 | if (ret) |
| 1442 | goto err; |
| 1443 | |
| 1444 | i = j; |
| 1445 | } |
| 1446 | |
| 1447 | filter->action = FILTER_SIGNAL; |
| 1448 | |
| 1449 | *f = filter; |
| 1450 | return 0; |
| 1451 | |
| 1452 | err: |
| 1453 | wl1271_rx_filter_free(filter); |
| 1454 | *f = NULL; |
| 1455 | |
| 1456 | return ret; |
| 1457 | } |
| 1458 | |
| 1459 | static int wl1271_configure_wowlan(struct wl1271 *wl, |
| 1460 | struct cfg80211_wowlan *wow) |
| 1461 | { |
| 1462 | int i, ret; |
| 1463 | |
| 1464 | if (!wow || wow->any || !wow->n_patterns) { |
| 1465 | wl1271_acx_default_rx_filter_enable(wl, 0, FILTER_SIGNAL); |
| 1466 | wl1271_rx_filter_clear_all(wl); |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | if (WARN_ON(wow->n_patterns > WL1271_MAX_RX_FILTERS)) |
| 1471 | return -EINVAL; |
| 1472 | |
| 1473 | /* Validate all incoming patterns before clearing current FW state */ |
| 1474 | for (i = 0; i < wow->n_patterns; i++) { |
| 1475 | ret = wl1271_validate_wowlan_pattern(&wow->patterns[i]); |
| 1476 | if (ret) { |
| 1477 | wl1271_warning("Bad wowlan pattern %d", i); |
| 1478 | return ret; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | wl1271_acx_default_rx_filter_enable(wl, 0, FILTER_SIGNAL); |
| 1483 | wl1271_rx_filter_clear_all(wl); |
| 1484 | |
| 1485 | /* Translate WoWLAN patterns into filters */ |
| 1486 | for (i = 0; i < wow->n_patterns; i++) { |
| 1487 | struct cfg80211_wowlan_trig_pkt_pattern *p; |
| 1488 | struct wl12xx_rx_filter *filter = NULL; |
| 1489 | |
| 1490 | p = &wow->patterns[i]; |
| 1491 | |
| 1492 | ret = wl1271_convert_wowlan_pattern_to_rx_filter(p, &filter); |
| 1493 | if (ret) { |
| 1494 | wl1271_warning("Failed to create an RX filter from " |
| 1495 | "wowlan pattern %d", i); |
| 1496 | goto out; |
| 1497 | } |
| 1498 | |
| 1499 | ret = wl1271_rx_filter_enable(wl, i, 1, filter); |
| 1500 | |
| 1501 | wl1271_rx_filter_free(filter); |
| 1502 | if (ret) |
| 1503 | goto out; |
| 1504 | } |
| 1505 | |
| 1506 | ret = wl1271_acx_default_rx_filter_enable(wl, 1, FILTER_DROP); |
| 1507 | |
| 1508 | out: |
| 1509 | return ret; |
| 1510 | } |
| 1511 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1512 | static int wl1271_configure_suspend_sta(struct wl1271 *wl, |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1513 | struct wl12xx_vif *wlvif, |
| 1514 | struct cfg80211_wowlan *wow) |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1515 | { |
| 1516 | int ret = 0; |
| 1517 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1518 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1519 | goto out; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1520 | |
| 1521 | ret = wl1271_ps_elp_wakeup(wl); |
| 1522 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1523 | goto out; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1524 | |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1525 | wl1271_configure_wowlan(wl, wow); |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1526 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1527 | wl->conf.conn.suspend_wake_up_event, |
| 1528 | wl->conf.conn.suspend_listen_interval); |
| 1529 | |
| 1530 | if (ret < 0) |
| 1531 | wl1271_error("suspend: set wake up conditions failed: %d", ret); |
| 1532 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1533 | wl1271_ps_elp_sleep(wl); |
| 1534 | |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1535 | out: |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1536 | return ret; |
| 1537 | |
| 1538 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1539 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1540 | static int wl1271_configure_suspend_ap(struct wl1271 *wl, |
| 1541 | struct wl12xx_vif *wlvif) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1542 | { |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1543 | int ret = 0; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1544 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 1545 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1546 | goto out; |
Eliad Peller | e85d162 | 2011-06-27 13:06:43 +0300 | [diff] [blame] | 1547 | |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1548 | ret = wl1271_ps_elp_wakeup(wl); |
| 1549 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1550 | goto out; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1551 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1552 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1553 | |
| 1554 | wl1271_ps_elp_sleep(wl); |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1555 | out: |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1556 | return ret; |
| 1557 | |
| 1558 | } |
| 1559 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1560 | static int wl1271_configure_suspend(struct wl1271 *wl, |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1561 | struct wl12xx_vif *wlvif, |
| 1562 | struct cfg80211_wowlan *wow) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1563 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1564 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1565 | return wl1271_configure_suspend_sta(wl, wlvif, wow); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1566 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1567 | return wl1271_configure_suspend_ap(wl, wlvif); |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1568 | return 0; |
| 1569 | } |
| 1570 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1571 | static void wl1271_configure_resume(struct wl1271 *wl, |
| 1572 | struct wl12xx_vif *wlvif) |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1573 | { |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1574 | int ret = 0; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1575 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1576 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
Eliad Peller | 8a7cf3f | 2011-06-06 12:21:54 +0300 | [diff] [blame] | 1577 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1578 | if ((!is_ap) && (!is_sta)) |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1579 | return; |
| 1580 | |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1581 | ret = wl1271_ps_elp_wakeup(wl); |
| 1582 | if (ret < 0) |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1583 | return; |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1584 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1585 | if (is_sta) { |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1586 | wl1271_configure_wowlan(wl, NULL); |
| 1587 | |
Eyal Shapira | dae728f | 2012-02-02 12:03:39 +0200 | [diff] [blame] | 1588 | ret = wl1271_acx_wake_up_conditions(wl, wlvif, |
| 1589 | wl->conf.conn.wake_up_event, |
| 1590 | wl->conf.conn.listen_interval); |
| 1591 | |
| 1592 | if (ret < 0) |
| 1593 | wl1271_error("resume: wake up conditions failed: %d", |
| 1594 | ret); |
| 1595 | |
| 1596 | } else if (is_ap) { |
| 1597 | ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false); |
| 1598 | } |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1599 | |
| 1600 | wl1271_ps_elp_sleep(wl); |
Eliad Peller | 9439064 | 2011-05-13 11:57:13 +0300 | [diff] [blame] | 1601 | } |
| 1602 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1603 | static int wl1271_op_suspend(struct ieee80211_hw *hw, |
| 1604 | struct cfg80211_wowlan *wow) |
| 1605 | { |
| 1606 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1607 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1608 | int ret; |
| 1609 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1610 | wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1611 | WARN_ON(!wow); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1612 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 1613 | wl1271_tx_flush(wl); |
| 1614 | |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1615 | mutex_lock(&wl->mutex); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1616 | wl->wow_enabled = true; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1617 | wl12xx_for_each_wlvif(wl, wlvif) { |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 1618 | ret = wl1271_configure_suspend(wl, wlvif, wow); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1619 | if (ret < 0) { |
Dan Carpenter | cd840f6 | 2012-04-16 13:57:02 +0300 | [diff] [blame] | 1620 | mutex_unlock(&wl->mutex); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1621 | wl1271_warning("couldn't prepare device to suspend"); |
| 1622 | return ret; |
| 1623 | } |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1624 | } |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1625 | mutex_unlock(&wl->mutex); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1626 | /* flush any remaining work */ |
| 1627 | wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1628 | |
| 1629 | /* |
| 1630 | * disable and re-enable interrupts in order to flush |
| 1631 | * the threaded_irq |
| 1632 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1633 | wlcore_disable_interrupts(wl); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1634 | |
| 1635 | /* |
| 1636 | * set suspended flag to avoid triggering a new threaded_irq |
| 1637 | * work. no need for spinlock as interrupts are disabled. |
| 1638 | */ |
| 1639 | set_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1640 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1641 | wlcore_enable_interrupts(wl); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1642 | flush_work(&wl->tx_work); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1643 | flush_delayed_work(&wl->elp_work); |
| 1644 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | static int wl1271_op_resume(struct ieee80211_hw *hw) |
| 1649 | { |
| 1650 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1651 | struct wl12xx_vif *wlvif; |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1652 | unsigned long flags; |
| 1653 | bool run_irq_work = false; |
| 1654 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1655 | wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d", |
| 1656 | wl->wow_enabled); |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1657 | WARN_ON(!wl->wow_enabled); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1658 | |
| 1659 | /* |
| 1660 | * re-enable irq_work enqueuing, and call irq_work directly if |
| 1661 | * there is a pending work. |
| 1662 | */ |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1663 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 1664 | clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags); |
| 1665 | if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags)) |
| 1666 | run_irq_work = true; |
| 1667 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1668 | |
Eliad Peller | 4a859df | 2011-06-06 12:21:52 +0300 | [diff] [blame] | 1669 | if (run_irq_work) { |
| 1670 | wl1271_debug(DEBUG_MAC80211, |
| 1671 | "run postponed irq_work directly"); |
| 1672 | wl1271_irq(0, wl); |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1673 | wlcore_enable_interrupts(wl); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1674 | } |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1675 | |
| 1676 | mutex_lock(&wl->mutex); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1677 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 1678 | wl1271_configure_resume(wl, wlvif); |
| 1679 | } |
Eliad Peller | ff91afc | 2011-06-06 12:21:53 +0300 | [diff] [blame] | 1680 | wl->wow_enabled = false; |
Eyal Shapira | c56dbd5 | 2012-03-13 20:03:21 +0200 | [diff] [blame] | 1681 | mutex_unlock(&wl->mutex); |
Eliad Peller | f44e586 | 2011-05-13 11:57:11 +0300 | [diff] [blame] | 1682 | |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 1685 | #endif |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 1686 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1687 | static int wl1271_op_start(struct ieee80211_hw *hw) |
| 1688 | { |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1689 | wl1271_debug(DEBUG_MAC80211, "mac80211 start"); |
| 1690 | |
| 1691 | /* |
| 1692 | * We have to delay the booting of the hardware because |
| 1693 | * we need to know the local MAC address before downloading and |
| 1694 | * initializing the firmware. The MAC address cannot be changed |
| 1695 | * after boot, and without the proper MAC address, the firmware |
| 1696 | * will not function properly. |
| 1697 | * |
| 1698 | * The MAC address is first known when the corresponding interface |
| 1699 | * is added. That is where we will initialize the hardware. |
| 1700 | */ |
| 1701 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 1702 | return 0; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | static void wl1271_op_stop(struct ieee80211_hw *hw) |
| 1706 | { |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1707 | struct wl1271 *wl = hw->priv; |
| 1708 | int i; |
| 1709 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1710 | wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1711 | |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1712 | /* |
| 1713 | * Interrupts must be disabled before setting the state to OFF. |
| 1714 | * Otherwise, the interrupt handler might be called and exit without |
| 1715 | * reading the interrupt status. |
| 1716 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1717 | wlcore_disable_interrupts(wl); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1718 | mutex_lock(&wl->mutex); |
| 1719 | if (wl->state == WL1271_STATE_OFF) { |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 1720 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, |
| 1721 | &wl->flags)) |
| 1722 | wlcore_enable_interrupts(wl); |
| 1723 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1724 | mutex_unlock(&wl->mutex); |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1725 | |
| 1726 | /* |
| 1727 | * This will not necessarily enable interrupts as interrupts |
| 1728 | * may have been disabled when op_stop was called. It will, |
| 1729 | * however, balance the above call to disable_interrupts(). |
| 1730 | */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1731 | wlcore_enable_interrupts(wl); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1732 | return; |
| 1733 | } |
Ido Yariv | 46b0cc9 | 2012-01-11 09:42:41 +0200 | [diff] [blame] | 1734 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1735 | /* |
| 1736 | * this must be before the cancel_work calls below, so that the work |
| 1737 | * functions don't perform further work. |
| 1738 | */ |
| 1739 | wl->state = WL1271_STATE_OFF; |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 1740 | mutex_unlock(&wl->mutex); |
| 1741 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1742 | wl1271_flush_deferred_work(wl); |
| 1743 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 1744 | cancel_work_sync(&wl->netstack_work); |
| 1745 | cancel_work_sync(&wl->tx_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1746 | cancel_delayed_work_sync(&wl->elp_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1747 | cancel_delayed_work_sync(&wl->tx_watchdog_work); |
Bartosz.Markowski@tieto.com | 5f561f6 | 2012-04-26 10:35:07 +0300 | [diff] [blame] | 1748 | cancel_delayed_work_sync(&wl->connection_loss_work); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1749 | |
| 1750 | /* let's notify MAC80211 about the remaining pending TX frames */ |
Arik Nemtsov | 6639611 | 2012-05-18 07:46:38 +0300 | [diff] [blame] | 1751 | wl12xx_tx_reset(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1752 | mutex_lock(&wl->mutex); |
| 1753 | |
| 1754 | wl1271_power_off(wl); |
Ido Yariv | b666bb7 | 2012-05-21 01:10:11 +0300 | [diff] [blame] | 1755 | /* |
| 1756 | * In case a recovery was scheduled, interrupts were disabled to avoid |
| 1757 | * an interrupt storm. Now that the power is down, it is safe to |
| 1758 | * re-enable interrupts to balance the disable depth |
| 1759 | */ |
| 1760 | if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
| 1761 | wlcore_enable_interrupts(wl); |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1762 | |
| 1763 | wl->band = IEEE80211_BAND_2GHZ; |
| 1764 | |
| 1765 | wl->rx_counter = 0; |
| 1766 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 1767 | wl->channel_type = NL80211_CHAN_NO_HT; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1768 | wl->tx_blocks_available = 0; |
| 1769 | wl->tx_allocated_blocks = 0; |
| 1770 | wl->tx_results_count = 0; |
| 1771 | wl->tx_packets_count = 0; |
| 1772 | wl->time_offset = 0; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1773 | wl->ap_fw_ps_map = 0; |
| 1774 | wl->ap_ps_map = 0; |
| 1775 | wl->sched_scanning = false; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 1776 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1777 | memset(wl->roles_map, 0, sizeof(wl->roles_map)); |
| 1778 | memset(wl->links_map, 0, sizeof(wl->links_map)); |
| 1779 | memset(wl->roc_map, 0, sizeof(wl->roc_map)); |
| 1780 | wl->active_sta_count = 0; |
| 1781 | |
| 1782 | /* The system link is always allocated */ |
| 1783 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 1784 | |
| 1785 | /* |
| 1786 | * this is performed after the cancel_work calls and the associated |
| 1787 | * mutex_lock, so that wl1271_op_add_interface does not accidentally |
| 1788 | * get executed before all these vars have been reset. |
| 1789 | */ |
| 1790 | wl->flags = 0; |
| 1791 | |
| 1792 | wl->tx_blocks_freed = 0; |
| 1793 | |
| 1794 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 1795 | wl->tx_pkts_freed[i] = 0; |
| 1796 | wl->tx_allocated_pkts[i] = 0; |
| 1797 | } |
| 1798 | |
| 1799 | wl1271_debugfs_reset(wl); |
| 1800 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 1801 | kfree(wl->fw_status_1); |
| 1802 | wl->fw_status_1 = NULL; |
| 1803 | wl->fw_status_2 = NULL; |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 1804 | kfree(wl->tx_res_if); |
| 1805 | wl->tx_res_if = NULL; |
| 1806 | kfree(wl->target_mem_map); |
| 1807 | wl->target_mem_map = NULL; |
| 1808 | |
| 1809 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 1810 | } |
| 1811 | |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1812 | static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx) |
| 1813 | { |
| 1814 | u8 policy = find_first_zero_bit(wl->rate_policies_map, |
| 1815 | WL12XX_MAX_RATE_POLICIES); |
| 1816 | if (policy >= WL12XX_MAX_RATE_POLICIES) |
| 1817 | return -EBUSY; |
| 1818 | |
| 1819 | __set_bit(policy, wl->rate_policies_map); |
| 1820 | *idx = policy; |
| 1821 | return 0; |
| 1822 | } |
| 1823 | |
| 1824 | static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx) |
| 1825 | { |
| 1826 | if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES)) |
| 1827 | return; |
| 1828 | |
| 1829 | __clear_bit(*idx, wl->rate_policies_map); |
| 1830 | *idx = WL12XX_MAX_RATE_POLICIES; |
| 1831 | } |
| 1832 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1833 | 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] | 1834 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1835 | switch (wlvif->bss_type) { |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1836 | case BSS_TYPE_AP_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 1837 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 1838 | return WL1271_ROLE_P2P_GO; |
| 1839 | else |
| 1840 | return WL1271_ROLE_AP; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1841 | |
| 1842 | case BSS_TYPE_STA_BSS: |
Eliad Peller | fb0e707 | 2011-10-05 11:55:47 +0200 | [diff] [blame] | 1843 | if (wlvif->p2p) |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 1844 | return WL1271_ROLE_P2P_CL; |
| 1845 | else |
| 1846 | return WL1271_ROLE_STA; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1847 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 1848 | case BSS_TYPE_IBSS: |
| 1849 | return WL1271_ROLE_IBSS; |
| 1850 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1851 | default: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1852 | wl1271_error("invalid bss_type: %d", wlvif->bss_type); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 1853 | } |
| 1854 | return WL12XX_INVALID_ROLE_TYPE; |
| 1855 | } |
| 1856 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1857 | 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] | 1858 | { |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1859 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1860 | int i; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1861 | |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 1862 | /* clear everything but the persistent data */ |
| 1863 | memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent)); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1864 | |
| 1865 | switch (ieee80211_vif_type_p2p(vif)) { |
| 1866 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1867 | wlvif->p2p = 1; |
| 1868 | /* fall-through */ |
| 1869 | case NL80211_IFTYPE_STATION: |
| 1870 | wlvif->bss_type = BSS_TYPE_STA_BSS; |
| 1871 | break; |
| 1872 | case NL80211_IFTYPE_ADHOC: |
| 1873 | wlvif->bss_type = BSS_TYPE_IBSS; |
| 1874 | break; |
| 1875 | case NL80211_IFTYPE_P2P_GO: |
| 1876 | wlvif->p2p = 1; |
| 1877 | /* fall-through */ |
| 1878 | case NL80211_IFTYPE_AP: |
| 1879 | wlvif->bss_type = BSS_TYPE_AP_BSS; |
| 1880 | break; |
| 1881 | default: |
| 1882 | wlvif->bss_type = MAX_BSS_TYPE; |
| 1883 | return -EOPNOTSUPP; |
| 1884 | } |
| 1885 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1886 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 1887 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 1888 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1889 | |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1890 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 1891 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 1892 | /* init sta/ibss data */ |
| 1893 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1894 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 1895 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 1896 | wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 1897 | wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC; |
| 1898 | wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC; |
| 1899 | wlvif->rate_set = CONF_TX_RATE_MASK_BASIC; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1900 | } else { |
| 1901 | /* init ap data */ |
| 1902 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 1903 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 1904 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 1905 | wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 1906 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 1907 | wl12xx_allocate_rate_policy(wl, |
| 1908 | &wlvif->ap.ucast_rate_idx[i]); |
Luciano Coelho | 15e05bc | 2012-05-10 12:14:05 +0300 | [diff] [blame] | 1909 | wlvif->basic_rate_set = CONF_TX_AP_ENABLED_RATES; |
| 1910 | /* |
| 1911 | * TODO: check if basic_rate shouldn't be |
| 1912 | * wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 1913 | * instead (the same thing for STA above). |
| 1914 | */ |
| 1915 | wlvif->basic_rate = CONF_TX_AP_ENABLED_RATES; |
| 1916 | /* TODO: this seems to be used only for STA, check it */ |
| 1917 | wlvif->rate_set = CONF_TX_AP_ENABLED_RATES; |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1918 | } |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1919 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1920 | wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; |
| 1921 | wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 1922 | wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; |
| 1923 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1924 | /* |
| 1925 | * mac80211 configures some values globally, while we treat them |
| 1926 | * per-interface. thus, on init, we have to copy them from wl |
| 1927 | */ |
| 1928 | wlvif->band = wl->band; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 1929 | wlvif->channel = wl->channel; |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 1930 | wlvif->power_level = wl->power_level; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 1931 | wlvif->channel_type = wl->channel_type; |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1932 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 1933 | INIT_WORK(&wlvif->rx_streaming_enable_work, |
| 1934 | wl1271_rx_streaming_enable_work); |
| 1935 | INIT_WORK(&wlvif->rx_streaming_disable_work, |
| 1936 | wl1271_rx_streaming_disable_work); |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 1937 | INIT_LIST_HEAD(&wlvif->list); |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 1938 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 1939 | setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer, |
| 1940 | (unsigned long) wlvif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 1941 | return 0; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 1944 | static bool wl12xx_init_fw(struct wl1271 *wl) |
| 1945 | { |
| 1946 | int retries = WL1271_BOOT_RETRIES; |
| 1947 | bool booted = false; |
| 1948 | struct wiphy *wiphy = wl->hw->wiphy; |
| 1949 | int ret; |
| 1950 | |
| 1951 | while (retries) { |
| 1952 | retries--; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 1953 | ret = wl12xx_chip_wakeup(wl, false); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 1954 | if (ret < 0) |
| 1955 | goto power_off; |
| 1956 | |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1957 | ret = wl->ops->boot(wl); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 1958 | if (ret < 0) |
| 1959 | goto power_off; |
| 1960 | |
| 1961 | ret = wl1271_hw_init(wl); |
| 1962 | if (ret < 0) |
| 1963 | goto irq_disable; |
| 1964 | |
| 1965 | booted = true; |
| 1966 | break; |
| 1967 | |
| 1968 | irq_disable: |
| 1969 | mutex_unlock(&wl->mutex); |
| 1970 | /* Unlocking the mutex in the middle of handling is |
| 1971 | inherently unsafe. In this case we deem it safe to do, |
| 1972 | because we need to let any possibly pending IRQ out of |
| 1973 | the system (and while we are WL1271_STATE_OFF the IRQ |
| 1974 | work function will not do anything.) Also, any other |
| 1975 | possible concurrent operations will fail due to the |
| 1976 | current state, hence the wl1271 struct should be safe. */ |
Luciano Coelho | dd5512e | 2012-04-11 11:03:14 +0300 | [diff] [blame] | 1977 | wlcore_disable_interrupts(wl); |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 1978 | wl1271_flush_deferred_work(wl); |
| 1979 | cancel_work_sync(&wl->netstack_work); |
| 1980 | mutex_lock(&wl->mutex); |
| 1981 | power_off: |
| 1982 | wl1271_power_off(wl); |
| 1983 | } |
| 1984 | |
| 1985 | if (!booted) { |
| 1986 | wl1271_error("firmware boot failed despite %d retries", |
| 1987 | WL1271_BOOT_RETRIES); |
| 1988 | goto out; |
| 1989 | } |
| 1990 | |
| 1991 | wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); |
| 1992 | |
| 1993 | /* update hw/fw version info in wiphy struct */ |
| 1994 | wiphy->hw_version = wl->chip.id; |
| 1995 | strncpy(wiphy->fw_version, wl->chip.fw_ver_str, |
| 1996 | sizeof(wiphy->fw_version)); |
| 1997 | |
| 1998 | /* |
| 1999 | * Now we know if 11a is supported (info from the NVS), so disable |
| 2000 | * 11a channels if not supported |
| 2001 | */ |
| 2002 | if (!wl->enable_11a) |
| 2003 | wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0; |
| 2004 | |
| 2005 | wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", |
| 2006 | wl->enable_11a ? "" : "not "); |
| 2007 | |
| 2008 | wl->state = WL1271_STATE_ON; |
| 2009 | out: |
| 2010 | return booted; |
| 2011 | } |
| 2012 | |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2013 | static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif) |
| 2014 | { |
| 2015 | return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID; |
| 2016 | } |
| 2017 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2018 | /* |
| 2019 | * Check whether a fw switch (i.e. moving from one loaded |
| 2020 | * fw to another) is needed. This function is also responsible |
| 2021 | * for updating wl->last_vif_count, so it must be called before |
| 2022 | * loading a non-plt fw (so the correct fw (single-role/multi-role) |
| 2023 | * will be used). |
| 2024 | */ |
| 2025 | static bool wl12xx_need_fw_change(struct wl1271 *wl, |
| 2026 | struct vif_counter_data vif_counter_data, |
| 2027 | bool add) |
| 2028 | { |
| 2029 | enum wl12xx_fw_type current_fw = wl->fw_type; |
| 2030 | u8 vif_count = vif_counter_data.counter; |
| 2031 | |
| 2032 | if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags)) |
| 2033 | return false; |
| 2034 | |
| 2035 | /* increase the vif count if this is a new vif */ |
| 2036 | if (add && !vif_counter_data.cur_vif_running) |
| 2037 | vif_count++; |
| 2038 | |
| 2039 | wl->last_vif_count = vif_count; |
| 2040 | |
| 2041 | /* no need for fw change if the device is OFF */ |
| 2042 | if (wl->state == WL1271_STATE_OFF) |
| 2043 | return false; |
| 2044 | |
| 2045 | if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL) |
| 2046 | return true; |
| 2047 | if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI) |
| 2048 | return true; |
| 2049 | |
| 2050 | return false; |
| 2051 | } |
| 2052 | |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2053 | /* |
| 2054 | * Enter "forced psm". Make sure the sta is in psm against the ap, |
| 2055 | * to make the fw switch a bit more disconnection-persistent. |
| 2056 | */ |
| 2057 | static void wl12xx_force_active_psm(struct wl1271 *wl) |
| 2058 | { |
| 2059 | struct wl12xx_vif *wlvif; |
| 2060 | |
| 2061 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 2062 | wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE); |
| 2063 | } |
| 2064 | } |
| 2065 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2066 | static int wl1271_op_add_interface(struct ieee80211_hw *hw, |
| 2067 | struct ieee80211_vif *vif) |
| 2068 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2069 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2070 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2071 | struct vif_counter_data vif_count; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2072 | int ret = 0; |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2073 | u8 role_type; |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2074 | bool booted = false; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2075 | |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2076 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | |
| 2077 | IEEE80211_VIF_SUPPORTS_CQM_RSSI; |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 2078 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2079 | wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM", |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 2080 | ieee80211_vif_type_p2p(vif), vif->addr); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2081 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2082 | wl12xx_get_vif_count(hw, vif, &vif_count); |
| 2083 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2084 | mutex_lock(&wl->mutex); |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2085 | ret = wl1271_ps_elp_wakeup(wl); |
| 2086 | if (ret < 0) |
| 2087 | goto out_unlock; |
| 2088 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2089 | /* |
| 2090 | * in some very corner case HW recovery scenarios its possible to |
| 2091 | * get here before __wl1271_op_remove_interface is complete, so |
| 2092 | * opt out if that is the case. |
| 2093 | */ |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2094 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) || |
| 2095 | test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) { |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2096 | ret = -EBUSY; |
| 2097 | goto out; |
| 2098 | } |
| 2099 | |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 2100 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 2101 | ret = wl12xx_init_vif_data(wl, vif); |
Eliad Peller | e936bbe | 2011-10-05 11:55:56 +0200 | [diff] [blame] | 2102 | if (ret < 0) |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2103 | goto out; |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2104 | |
Eliad Peller | 252efa4 | 2011-10-05 11:56:00 +0200 | [diff] [blame] | 2105 | wlvif->wl = wl; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2106 | role_type = wl12xx_get_role_type(wl, wlvif); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2107 | if (role_type == WL12XX_INVALID_ROLE_TYPE) { |
| 2108 | ret = -EINVAL; |
| 2109 | goto out; |
| 2110 | } |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2111 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2112 | if (wl12xx_need_fw_change(wl, vif_count, true)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2113 | wl12xx_force_active_psm(wl); |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2114 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2115 | mutex_unlock(&wl->mutex); |
| 2116 | wl1271_recovery_work(&wl->recovery_work); |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2120 | /* |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2121 | * TODO: after the nvs issue will be solved, move this block |
| 2122 | * to start(), and make sure here the driver is ON. |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2123 | */ |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2124 | if (wl->state == WL1271_STATE_OFF) { |
| 2125 | /* |
| 2126 | * we still need this in order to configure the fw |
| 2127 | * while uploading the nvs |
| 2128 | */ |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 2129 | memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2130 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2131 | booted = wl12xx_init_fw(wl); |
| 2132 | if (!booted) { |
| 2133 | ret = -EINVAL; |
| 2134 | goto out; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2135 | } |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2136 | } |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2137 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2138 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2139 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2140 | /* |
| 2141 | * The device role is a special role used for |
| 2142 | * rx and tx frames prior to association (as |
| 2143 | * the STA role can get packets only from |
| 2144 | * its associated bssid) |
| 2145 | */ |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2146 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2147 | WL1271_ROLE_DEVICE, |
| 2148 | &wlvif->dev_role_id); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2149 | if (ret < 0) |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2150 | goto out; |
Juuso Oikarinen | 9ccd921 | 2009-12-11 15:41:01 +0200 | [diff] [blame] | 2151 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2152 | |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2153 | ret = wl12xx_cmd_role_enable(wl, vif->addr, |
| 2154 | role_type, &wlvif->role_id); |
| 2155 | if (ret < 0) |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2156 | goto out; |
Eliad Peller | 1d09547 | 2011-10-10 10:12:49 +0200 | [diff] [blame] | 2157 | |
| 2158 | ret = wl1271_init_vif_specific(wl, vif); |
| 2159 | if (ret < 0) |
| 2160 | goto out; |
Eliad Peller | 71125ab | 2010-10-28 21:46:43 +0200 | [diff] [blame] | 2161 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2162 | list_add(&wlvif->list, &wl->wlvif_list); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2163 | set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags); |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2164 | |
| 2165 | if (wlvif->bss_type == BSS_TYPE_AP_BSS) |
| 2166 | wl->ap_count++; |
| 2167 | else |
| 2168 | wl->sta_count++; |
Juuso Oikarinen | eb5b28d | 2009-10-13 12:47:45 +0300 | [diff] [blame] | 2169 | out: |
Eliad Peller | f750c82 | 2011-10-10 10:13:16 +0200 | [diff] [blame] | 2170 | wl1271_ps_elp_sleep(wl); |
| 2171 | out_unlock: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2172 | mutex_unlock(&wl->mutex); |
| 2173 | |
| 2174 | return ret; |
| 2175 | } |
| 2176 | |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2177 | static void __wl1271_op_remove_interface(struct wl1271 *wl, |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2178 | struct ieee80211_vif *vif, |
Arik Nemtsov | 7dece1c | 2011-04-18 14:15:28 +0300 | [diff] [blame] | 2179 | bool reset_tx_queues) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2180 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2181 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2182 | int i, ret; |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2183 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2184 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2185 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2186 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2187 | if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2188 | return; |
| 2189 | |
Juuso Oikarinen | 13026de | 2011-03-29 16:43:50 +0300 | [diff] [blame] | 2190 | /* because of hardware recovery, we may get here twice */ |
| 2191 | if (wl->state != WL1271_STATE_ON) |
| 2192 | return; |
| 2193 | |
Juuso Oikarinen | 1b72aec | 2010-03-18 12:26:39 +0200 | [diff] [blame] | 2194 | wl1271_info("down"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2195 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2196 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE && |
| 2197 | wl->scan_vif == vif) { |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 2198 | /* |
| 2199 | * Rearm the tx watchdog just before idling scan. This |
| 2200 | * prevents just-finished scans from triggering the watchdog |
| 2201 | */ |
| 2202 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 2203 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 2204 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 2205 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 2206 | wl->scan_vif = NULL; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 2207 | wl->scan.req = NULL; |
Juuso Oikarinen | 76a029f | 2010-07-29 04:54:45 +0300 | [diff] [blame] | 2208 | ieee80211_scan_completed(wl->hw, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2209 | } |
| 2210 | |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2211 | if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) { |
| 2212 | /* disable active roles */ |
| 2213 | ret = wl1271_ps_elp_wakeup(wl); |
| 2214 | if (ret < 0) |
| 2215 | goto deinit; |
| 2216 | |
Eliad Peller | b890f4c | 2011-12-18 20:25:44 +0200 | [diff] [blame] | 2217 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2218 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2219 | if (wl12xx_dev_role_started(wlvif)) |
| 2220 | wl12xx_stop_dev(wl, wlvif); |
| 2221 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2222 | ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 2223 | if (ret < 0) |
| 2224 | goto deinit; |
| 2225 | } |
| 2226 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2227 | ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id); |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2228 | if (ret < 0) |
| 2229 | goto deinit; |
| 2230 | |
| 2231 | wl1271_ps_elp_sleep(wl); |
| 2232 | } |
| 2233 | deinit: |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 2234 | /* clear all hlids (except system_hlid) */ |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 2235 | wlvif->dev_hlid = WL12XX_INVALID_LINK_ID; |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2236 | |
| 2237 | if (wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2238 | wlvif->bss_type == BSS_TYPE_IBSS) { |
| 2239 | wlvif->sta.hlid = WL12XX_INVALID_LINK_ID; |
| 2240 | wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx); |
| 2241 | wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx); |
| 2242 | wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx); |
| 2243 | } else { |
| 2244 | wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; |
| 2245 | wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID; |
| 2246 | wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx); |
| 2247 | wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx); |
| 2248 | for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) |
| 2249 | wl12xx_free_rate_policy(wl, |
| 2250 | &wlvif->ap.ucast_rate_idx[i]); |
Eliad Peller | 830be7e | 2012-03-19 11:32:55 +0200 | [diff] [blame] | 2251 | wl1271_free_ap_keys(wl, wlvif); |
Eliad Peller | e5a359f | 2011-10-10 10:13:15 +0200 | [diff] [blame] | 2252 | } |
Eliad Peller | b78b47e | 2011-08-14 13:17:08 +0300 | [diff] [blame] | 2253 | |
Eyal Shapira | 3eba4a0 | 2012-03-19 12:06:27 +0200 | [diff] [blame] | 2254 | dev_kfree_skb(wlvif->probereq); |
| 2255 | wlvif->probereq = NULL; |
Eliad Peller | d6a3cc2 | 2011-10-10 10:12:51 +0200 | [diff] [blame] | 2256 | wl12xx_tx_reset_wlvif(wl, wlvif); |
Eliad Peller | e4120df | 2011-10-10 10:13:17 +0200 | [diff] [blame] | 2257 | if (wl->last_wlvif == wlvif) |
| 2258 | wl->last_wlvif = NULL; |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 2259 | list_del(&wlvif->list); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 2260 | 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] | 2261 | wlvif->role_id = WL12XX_INVALID_ROLE_ID; |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 2262 | wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID; |
Luciano Coelho | d6e19d1 | 2009-10-12 15:08:43 +0300 | [diff] [blame] | 2263 | |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2264 | if (is_ap) |
Eliad Peller | a4e4130 | 2011-10-11 11:49:15 +0200 | [diff] [blame] | 2265 | wl->ap_count--; |
| 2266 | else |
| 2267 | wl->sta_count--; |
| 2268 | |
Arik Nemtsov | 2f18cf7 | 2012-06-10 19:10:45 +0300 | [diff] [blame] | 2269 | /* Last AP, have more stations. Configure according to STA. */ |
| 2270 | if (wl->ap_count == 0 && is_ap && wl->sta_count) { |
| 2271 | u8 sta_auth = wl->conf.conn.sta_sleep_auth; |
| 2272 | /* Configure for power according to debugfs */ |
| 2273 | if (sta_auth != WL1271_PSM_ILLEGAL) |
| 2274 | wl1271_acx_sleep_auth(wl, sta_auth); |
| 2275 | /* Configure for power always on */ |
| 2276 | else if (wl->quirks & WLCORE_QUIRK_NO_ELP) |
| 2277 | wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM); |
| 2278 | /* Configure for ELP power saving */ |
| 2279 | else |
| 2280 | wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP); |
| 2281 | } |
| 2282 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2283 | mutex_unlock(&wl->mutex); |
Eyal Shapira | d6bf9ad | 2012-01-31 11:57:20 +0200 | [diff] [blame] | 2284 | |
Eliad Peller | 9eb599e | 2011-10-10 10:12:59 +0200 | [diff] [blame] | 2285 | del_timer_sync(&wlvif->rx_streaming_timer); |
| 2286 | cancel_work_sync(&wlvif->rx_streaming_enable_work); |
| 2287 | cancel_work_sync(&wlvif->rx_streaming_disable_work); |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 2288 | |
Eliad Peller | baf6277 | 2011-10-10 10:12:52 +0200 | [diff] [blame] | 2289 | mutex_lock(&wl->mutex); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2290 | } |
Juuso Oikarinen | bd9dc49 | 2010-04-09 11:07:26 +0300 | [diff] [blame] | 2291 | |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2292 | static void wl1271_op_remove_interface(struct ieee80211_hw *hw, |
| 2293 | struct ieee80211_vif *vif) |
| 2294 | { |
| 2295 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2296 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2297 | struct wl12xx_vif *iter; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2298 | struct vif_counter_data vif_count; |
| 2299 | bool cancel_recovery = true; |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2300 | |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2301 | wl12xx_get_vif_count(hw, vif, &vif_count); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 2302 | mutex_lock(&wl->mutex); |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2303 | |
| 2304 | if (wl->state == WL1271_STATE_OFF || |
| 2305 | !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
| 2306 | goto out; |
| 2307 | |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2308 | /* |
| 2309 | * wl->vif can be null here if someone shuts down the interface |
| 2310 | * just when hardware recovery has been started. |
| 2311 | */ |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2312 | wl12xx_for_each_wlvif(wl, iter) { |
| 2313 | if (iter != wlvif) |
| 2314 | continue; |
| 2315 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2316 | __wl1271_op_remove_interface(wl, vif, true); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2317 | break; |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2318 | } |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2319 | WARN_ON(iter != wlvif); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2320 | if (wl12xx_need_fw_change(wl, vif_count, false)) { |
Eliad Peller | 3dee439 | 2012-02-06 12:47:56 +0200 | [diff] [blame] | 2321 | wl12xx_force_active_psm(wl); |
Eliad Peller | e9ba715 | 2012-03-04 10:55:54 +0200 | [diff] [blame] | 2322 | set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2323 | wl12xx_queue_recovery_work(wl); |
| 2324 | cancel_recovery = false; |
| 2325 | } |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 2326 | out: |
Juuso Oikarinen | 6735329 | 2010-11-18 15:19:02 +0200 | [diff] [blame] | 2327 | mutex_unlock(&wl->mutex); |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2328 | if (cancel_recovery) |
| 2329 | cancel_work_sync(&wl->recovery_work); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2330 | } |
| 2331 | |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2332 | static int wl12xx_op_change_interface(struct ieee80211_hw *hw, |
| 2333 | struct ieee80211_vif *vif, |
| 2334 | enum nl80211_iftype new_type, bool p2p) |
| 2335 | { |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2336 | struct wl1271 *wl = hw->priv; |
| 2337 | int ret; |
| 2338 | |
| 2339 | set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2340 | wl1271_op_remove_interface(hw, vif); |
| 2341 | |
Eliad Peller | 249e969 | 2012-03-04 10:55:50 +0200 | [diff] [blame] | 2342 | vif->type = new_type; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2343 | vif->p2p = p2p; |
Eliad Peller | 4549d09 | 2012-02-06 13:07:52 +0200 | [diff] [blame] | 2344 | ret = wl1271_op_add_interface(hw, vif); |
| 2345 | |
| 2346 | clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags); |
| 2347 | return ret; |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 2348 | } |
| 2349 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2350 | static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2351 | bool set_assoc) |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2352 | { |
| 2353 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2354 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2355 | |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2356 | /* |
| 2357 | * One of the side effects of the JOIN command is that is clears |
| 2358 | * WPA/WPA2 keys from the chipset. Performing a JOIN while associated |
| 2359 | * 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] | 2360 | * Currently the only valid scenario for JOIN during association |
| 2361 | * is on roaming, in which case we will also be given new keys. |
| 2362 | * Keep the below message for now, unless it starts bothering |
| 2363 | * users who really like to roam a lot :) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2364 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2365 | if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2366 | wl1271_info("JOIN while associated."); |
| 2367 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 2368 | /* clear encryption type */ |
| 2369 | wlvif->encryption_type = KEY_NONE; |
| 2370 | |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2371 | if (set_assoc) |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2372 | set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags); |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2373 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2374 | if (is_ibss) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2375 | ret = wl12xx_cmd_role_start_ibss(wl, wlvif); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 2376 | else |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2377 | ret = wl12xx_cmd_role_start_sta(wl, wlvif); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2378 | if (ret < 0) |
| 2379 | goto out; |
| 2380 | |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2381 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2382 | goto out; |
| 2383 | |
| 2384 | /* |
| 2385 | * The join command disable the keep-alive mode, shut down its process, |
| 2386 | * and also clear the template config, so we need to reset it all after |
| 2387 | * the join. The acx_aid starts the keep-alive process, and the order |
| 2388 | * of the commands below is relevant. |
| 2389 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2390 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, true); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2391 | if (ret < 0) |
| 2392 | goto out; |
| 2393 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2394 | ret = wl1271_acx_aid(wl, wlvif, wlvif->aid); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2395 | if (ret < 0) |
| 2396 | goto out; |
| 2397 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2398 | ret = wl12xx_cmd_build_klv_null_data(wl, wlvif); |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2399 | if (ret < 0) |
| 2400 | goto out; |
| 2401 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2402 | ret = wl1271_acx_keep_alive_config(wl, wlvif, |
| 2403 | CMD_TEMPL_KLV_IDX_NULL_DATA, |
Juuso Oikarinen | 82429d3 | 2010-04-28 09:50:01 +0300 | [diff] [blame] | 2404 | ACX_KEEP_ALIVE_TPL_VALID); |
| 2405 | if (ret < 0) |
| 2406 | goto out; |
| 2407 | |
| 2408 | out: |
| 2409 | return ret; |
| 2410 | } |
| 2411 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2412 | static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2413 | { |
| 2414 | int ret; |
| 2415 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 2416 | if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2417 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 2418 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2419 | wl12xx_cmd_stop_channel_switch(wl); |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2420 | ieee80211_chswitch_done(vif, false); |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 2421 | } |
| 2422 | |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2423 | /* to stop listening to a channel, we disconnect */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2424 | ret = wl12xx_cmd_role_stop_sta(wl, wlvif); |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2425 | if (ret < 0) |
| 2426 | goto out; |
| 2427 | |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 2428 | /* reset TX security counters on a clean disconnect */ |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2429 | wlvif->tx_security_last_seq_lsb = 0; |
| 2430 | wlvif->tx_security_seq = 0; |
Oz Krakowski | b992c68 | 2011-06-26 10:36:02 +0300 | [diff] [blame] | 2431 | |
Luciano Coelho | c7f43e4 | 2009-12-11 15:40:44 +0200 | [diff] [blame] | 2432 | out: |
| 2433 | return ret; |
| 2434 | } |
| 2435 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2436 | 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] | 2437 | { |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2438 | wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band]; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2439 | wlvif->rate_set = wlvif->basic_rate_set; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2440 | } |
| 2441 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2442 | static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2443 | bool idle) |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2444 | { |
| 2445 | int ret; |
Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2446 | bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
| 2447 | |
| 2448 | if (idle == cur_idle) |
| 2449 | return 0; |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2450 | |
| 2451 | if (idle) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2452 | /* no need to croc if we weren't busy (e.g. during boot) */ |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 2453 | if (wl12xx_dev_role_started(wlvif)) { |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2454 | ret = wl12xx_stop_dev(wl, wlvif); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2455 | if (ret < 0) |
| 2456 | goto out; |
| 2457 | } |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2458 | wlvif->rate_set = |
| 2459 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 2460 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2461 | if (ret < 0) |
| 2462 | goto out; |
| 2463 | ret = wl1271_acx_keep_alive_config( |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2464 | wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA, |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2465 | ACX_KEEP_ALIVE_TPL_INVALID); |
| 2466 | if (ret < 0) |
| 2467 | goto out; |
Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2468 | clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2469 | } else { |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 2470 | /* The current firmware only supports sched_scan in idle */ |
| 2471 | if (wl->sched_scanning) { |
Yoni Divinsky | 78f85f5 | 2012-05-16 11:34:17 +0300 | [diff] [blame] | 2472 | wl1271_scan_sched_scan_stop(wl, wlvif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 2473 | ieee80211_sched_scan_stopped(wl->hw); |
| 2474 | } |
| 2475 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2476 | ret = wl12xx_start_dev(wl, wlvif); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2477 | if (ret < 0) |
| 2478 | goto out; |
Eliad Peller | a0c7b78 | 2011-12-18 20:25:41 +0200 | [diff] [blame] | 2479 | set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags); |
Juuso Oikarinen | 0d58cbf | 2010-05-24 11:18:16 +0300 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | out: |
| 2483 | return ret; |
| 2484 | } |
| 2485 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2486 | static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2487 | struct ieee80211_conf *conf, u32 changed) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2488 | { |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2489 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
| 2490 | int channel, ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2491 | |
| 2492 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
| 2493 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2494 | /* if the channel changes while joined, join again */ |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 2495 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL && |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 2496 | ((wlvif->band != conf->channel->band) || |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 2497 | (wlvif->channel != channel) || |
| 2498 | (wlvif->channel_type != conf->channel_type))) { |
Eliad Peller | c6930b0 | 2011-09-15 13:00:01 +0300 | [diff] [blame] | 2499 | /* send all pending packets */ |
Eliad Peller | a32d0cd | 2011-10-10 10:12:55 +0200 | [diff] [blame] | 2500 | wl1271_tx_work_locked(wl); |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 2501 | wlvif->band = conf->channel->band; |
| 2502 | wlvif->channel = channel; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 2503 | wlvif->channel_type = conf->channel_type; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2504 | |
Arik Nemtsov | ebc7e57 | 2012-05-10 12:13:34 +0300 | [diff] [blame] | 2505 | if (is_ap) { |
Eliad Peller | 2812eef | 2012-06-12 12:45:27 +0300 | [diff] [blame] | 2506 | wl1271_set_band_rate(wl, wlvif); |
Arik Nemtsov | ebc7e57 | 2012-05-10 12:13:34 +0300 | [diff] [blame] | 2507 | ret = wl1271_init_ap_rates(wl, wlvif); |
| 2508 | if (ret < 0) |
| 2509 | wl1271_error("AP rate policy change failed %d", |
| 2510 | ret); |
| 2511 | } else { |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2512 | /* |
| 2513 | * FIXME: the mac80211 should really provide a fixed |
| 2514 | * rate to use here. for now, just use the smallest |
| 2515 | * possible rate for the band as a fixed rate for |
| 2516 | * association frames and other control messages. |
| 2517 | */ |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 2518 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2519 | wl1271_set_band_rate(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2520 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 2521 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 2522 | wl1271_tx_min_rate_get(wl, |
| 2523 | wlvif->basic_rate_set); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 2524 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2525 | if (ret < 0) |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2526 | wl1271_warning("rate policy for channel " |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2527 | "failed %d", ret); |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2528 | |
Eliad Peller | 121af04 | 2012-03-04 10:55:51 +0200 | [diff] [blame] | 2529 | /* |
| 2530 | * change the ROC channel. do it only if we are |
| 2531 | * not idle. otherwise, CROC will be called |
| 2532 | * anyway. |
| 2533 | */ |
| 2534 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, |
| 2535 | &wlvif->flags) && |
| 2536 | wl12xx_dev_role_started(wlvif) && |
| 2537 | !(conf->flags & IEEE80211_CONF_IDLE)) { |
| 2538 | ret = wl12xx_stop_dev(wl, wlvif); |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2539 | if (ret < 0) |
Eliad Peller | 121af04 | 2012-03-04 10:55:51 +0200 | [diff] [blame] | 2540 | return ret; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 2541 | |
Eliad Peller | 121af04 | 2012-03-04 10:55:51 +0200 | [diff] [blame] | 2542 | ret = wl12xx_start_dev(wl, wlvif); |
| 2543 | if (ret < 0) |
| 2544 | return ret; |
Arik Nemtsov | bee0ffe | 2010-10-16 19:17:02 +0200 | [diff] [blame] | 2545 | } |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2549 | if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2550 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2551 | if ((conf->flags & IEEE80211_CONF_PS) && |
| 2552 | test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) && |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2553 | !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2554 | |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2555 | int ps_mode; |
| 2556 | char *ps_mode_str; |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2557 | |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2558 | if (wl->conf.conn.forced_ps) { |
| 2559 | ps_mode = STATION_POWER_SAVE_MODE; |
| 2560 | ps_mode_str = "forced"; |
| 2561 | } else { |
| 2562 | ps_mode = STATION_AUTO_PS_MODE; |
| 2563 | ps_mode_str = "auto"; |
| 2564 | } |
| 2565 | |
| 2566 | wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str); |
| 2567 | |
| 2568 | ret = wl1271_ps_set_mode(wl, wlvif, ps_mode); |
| 2569 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2570 | if (ret < 0) |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2571 | wl1271_warning("enter %s ps failed %d", |
| 2572 | ps_mode_str, ret); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2573 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2574 | } else if (!(conf->flags & IEEE80211_CONF_PS) && |
Eyal Shapira | 5c0dc2f | 2012-02-02 19:06:45 +0200 | [diff] [blame] | 2575 | test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2576 | |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2577 | wl1271_debug(DEBUG_PSM, "auto ps disabled"); |
| 2578 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2579 | ret = wl1271_ps_set_mode(wl, wlvif, |
Eyal Shapira | 248a001 | 2012-01-31 11:57:23 +0200 | [diff] [blame] | 2580 | STATION_ACTIVE_MODE); |
Eyal Shapira | d18da7f | 2012-01-31 11:57:25 +0200 | [diff] [blame] | 2581 | if (ret < 0) |
| 2582 | wl1271_warning("exit auto ps failed %d", ret); |
| 2583 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2584 | } |
| 2585 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2586 | if (conf->power_level != wlvif->power_level) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 2587 | ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2588 | if (ret < 0) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2589 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2590 | |
Eliad Peller | 6bd6502 | 2011-10-10 10:13:11 +0200 | [diff] [blame] | 2591 | wlvif->power_level = conf->power_level; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2592 | } |
| 2593 | |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2594 | return 0; |
| 2595 | } |
| 2596 | |
| 2597 | static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) |
| 2598 | { |
| 2599 | struct wl1271 *wl = hw->priv; |
| 2600 | struct wl12xx_vif *wlvif; |
| 2601 | struct ieee80211_conf *conf = &hw->conf; |
| 2602 | int channel, ret = 0; |
| 2603 | |
| 2604 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
| 2605 | |
| 2606 | wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s" |
| 2607 | " changed 0x%x", |
| 2608 | channel, |
| 2609 | conf->flags & IEEE80211_CONF_PS ? "on" : "off", |
| 2610 | conf->power_level, |
| 2611 | conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use", |
| 2612 | changed); |
| 2613 | |
| 2614 | /* |
| 2615 | * mac80211 will go to idle nearly immediately after transmitting some |
| 2616 | * frames, such as the deauth. To make sure those frames reach the air, |
| 2617 | * wait here until the TX queue is fully flushed. |
| 2618 | */ |
Eliad Peller | d1bcb53 | 2012-05-15 16:46:56 +0300 | [diff] [blame] | 2619 | if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || |
| 2620 | ((changed & IEEE80211_CONF_CHANGE_IDLE) && |
| 2621 | (conf->flags & IEEE80211_CONF_IDLE))) |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2622 | wl1271_tx_flush(wl); |
| 2623 | |
| 2624 | mutex_lock(&wl->mutex); |
| 2625 | |
| 2626 | /* we support configuring the channel and band even while off */ |
| 2627 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
| 2628 | wl->band = conf->channel->band; |
| 2629 | wl->channel = channel; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 2630 | wl->channel_type = conf->channel_type; |
Eliad Peller | 9f259c4 | 2011-10-10 10:13:12 +0200 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 2634 | wl->power_level = conf->power_level; |
| 2635 | |
| 2636 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 2637 | goto out; |
| 2638 | |
| 2639 | ret = wl1271_ps_elp_wakeup(wl); |
| 2640 | if (ret < 0) |
| 2641 | goto out; |
| 2642 | |
| 2643 | /* configure each interface */ |
| 2644 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 2645 | ret = wl12xx_config_vif(wl, wlvif, conf, changed); |
| 2646 | if (ret < 0) |
| 2647 | goto out_sleep; |
| 2648 | } |
| 2649 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2650 | out_sleep: |
| 2651 | wl1271_ps_elp_sleep(wl); |
| 2652 | |
| 2653 | out: |
| 2654 | mutex_unlock(&wl->mutex); |
| 2655 | |
| 2656 | return ret; |
| 2657 | } |
| 2658 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2659 | struct wl1271_filter_params { |
| 2660 | bool enabled; |
| 2661 | int mc_list_length; |
| 2662 | u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN]; |
| 2663 | }; |
| 2664 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2665 | static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw, |
| 2666 | struct netdev_hw_addr_list *mc_list) |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2667 | { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2668 | struct wl1271_filter_params *fp; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2669 | struct netdev_hw_addr *ha; |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2670 | struct wl1271 *wl = hw->priv; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2671 | |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2672 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 2673 | return 0; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2674 | |
Juuso Oikarinen | 7444113 | 2009-10-13 12:47:53 +0300 | [diff] [blame] | 2675 | fp = kzalloc(sizeof(*fp), GFP_ATOMIC); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2676 | if (!fp) { |
| 2677 | wl1271_error("Out of memory setting filters."); |
| 2678 | return 0; |
| 2679 | } |
| 2680 | |
| 2681 | /* update multicast filtering parameters */ |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2682 | fp->mc_list_length = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2683 | if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) { |
| 2684 | fp->enabled = false; |
| 2685 | } else { |
| 2686 | fp->enabled = true; |
| 2687 | netdev_hw_addr_list_for_each(ha, mc_list) { |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2688 | memcpy(fp->mc_list[fp->mc_list_length], |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2689 | ha->addr, ETH_ALEN); |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2690 | fp->mc_list_length++; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 2691 | } |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2692 | } |
| 2693 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2694 | return (u64)(unsigned long)fp; |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2695 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2696 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2697 | #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \ |
| 2698 | FIF_ALLMULTI | \ |
| 2699 | FIF_FCSFAIL | \ |
| 2700 | FIF_BCN_PRBRESP_PROMISC | \ |
| 2701 | FIF_CONTROL | \ |
| 2702 | FIF_OTHER_BSS) |
| 2703 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2704 | static void wl1271_op_configure_filter(struct ieee80211_hw *hw, |
| 2705 | unsigned int changed, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 2706 | unsigned int *total, u64 multicast) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2707 | { |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2708 | struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2709 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2710 | struct wl12xx_vif *wlvif; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2711 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2712 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2713 | |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2714 | wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" |
| 2715 | " total %x", changed, *total); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2716 | |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2717 | mutex_lock(&wl->mutex); |
| 2718 | |
Saravanan Dhanabal | 2c10bb9 | 2010-04-09 11:07:27 +0300 | [diff] [blame] | 2719 | *total &= WL1271_SUPPORTED_FILTERS; |
| 2720 | changed &= WL1271_SUPPORTED_FILTERS; |
| 2721 | |
| 2722 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2723 | goto out; |
| 2724 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 2725 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2726 | if (ret < 0) |
| 2727 | goto out; |
| 2728 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 2729 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 2730 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) { |
| 2731 | if (*total & FIF_ALLMULTI) |
| 2732 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 2733 | false, |
| 2734 | NULL, 0); |
| 2735 | else if (fp) |
| 2736 | ret = wl1271_acx_group_address_tbl(wl, wlvif, |
| 2737 | fp->enabled, |
| 2738 | fp->mc_list, |
| 2739 | fp->mc_list_length); |
| 2740 | if (ret < 0) |
| 2741 | goto out_sleep; |
| 2742 | } |
Arik Nemtsov | 7d05786 | 2010-10-16 19:25:35 +0200 | [diff] [blame] | 2743 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2744 | |
Eliad Peller | 08c1d1c | 2011-08-14 13:17:04 +0300 | [diff] [blame] | 2745 | /* |
| 2746 | * the fw doesn't provide an api to configure the filters. instead, |
| 2747 | * the filters configuration is based on the active roles / ROC |
| 2748 | * state. |
| 2749 | */ |
Juuso Oikarinen | b54853f | 2009-10-13 12:47:59 +0300 | [diff] [blame] | 2750 | |
| 2751 | out_sleep: |
| 2752 | wl1271_ps_elp_sleep(wl); |
| 2753 | |
| 2754 | out: |
| 2755 | mutex_unlock(&wl->mutex); |
Juuso Oikarinen | 14b228a | 2010-03-18 12:26:43 +0200 | [diff] [blame] | 2756 | kfree(fp); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2757 | } |
| 2758 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2759 | static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2760 | u8 id, u8 key_type, u8 key_size, |
| 2761 | const u8 *key, u8 hlid, u32 tx_seq_32, |
| 2762 | u16 tx_seq_16) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2763 | { |
| 2764 | struct wl1271_ap_key *ap_key; |
| 2765 | int i; |
| 2766 | |
| 2767 | wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id); |
| 2768 | |
| 2769 | if (key_size > MAX_KEY_SIZE) |
| 2770 | return -EINVAL; |
| 2771 | |
| 2772 | /* |
| 2773 | * Find next free entry in ap_keys. Also check we are not replacing |
| 2774 | * an existing key. |
| 2775 | */ |
| 2776 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2777 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2778 | break; |
| 2779 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2780 | if (wlvif->ap.recorded_keys[i]->id == id) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2781 | wl1271_warning("trying to record key replacement"); |
| 2782 | return -EINVAL; |
| 2783 | } |
| 2784 | } |
| 2785 | |
| 2786 | if (i == MAX_NUM_KEYS) |
| 2787 | return -EBUSY; |
| 2788 | |
| 2789 | ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL); |
| 2790 | if (!ap_key) |
| 2791 | return -ENOMEM; |
| 2792 | |
| 2793 | ap_key->id = id; |
| 2794 | ap_key->key_type = key_type; |
| 2795 | ap_key->key_size = key_size; |
| 2796 | memcpy(ap_key->key, key, key_size); |
| 2797 | ap_key->hlid = hlid; |
| 2798 | ap_key->tx_seq_32 = tx_seq_32; |
| 2799 | ap_key->tx_seq_16 = tx_seq_16; |
| 2800 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2801 | wlvif->ap.recorded_keys[i] = ap_key; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2802 | return 0; |
| 2803 | } |
| 2804 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2805 | 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] | 2806 | { |
| 2807 | int i; |
| 2808 | |
| 2809 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2810 | kfree(wlvif->ap.recorded_keys[i]); |
| 2811 | wlvif->ap.recorded_keys[i] = NULL; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2812 | } |
| 2813 | } |
| 2814 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2815 | 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] | 2816 | { |
| 2817 | int i, ret = 0; |
| 2818 | struct wl1271_ap_key *key; |
| 2819 | bool wep_key_added = false; |
| 2820 | |
| 2821 | for (i = 0; i < MAX_NUM_KEYS; i++) { |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2822 | u8 hlid; |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2823 | if (wlvif->ap.recorded_keys[i] == NULL) |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2824 | break; |
| 2825 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2826 | key = wlvif->ap.recorded_keys[i]; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2827 | hlid = key->hlid; |
| 2828 | if (hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2829 | hlid = wlvif->ap.bcast_hlid; |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2830 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2831 | ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2832 | key->id, key->key_type, |
| 2833 | key->key_size, key->key, |
Eliad Peller | 7f97b48 | 2011-08-14 13:17:30 +0300 | [diff] [blame] | 2834 | hlid, key->tx_seq_32, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2835 | key->tx_seq_16); |
| 2836 | if (ret < 0) |
| 2837 | goto out; |
| 2838 | |
| 2839 | if (key->key_type == KEY_WEP) |
| 2840 | wep_key_added = true; |
| 2841 | } |
| 2842 | |
| 2843 | if (wep_key_added) { |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 2844 | ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key, |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2845 | wlvif->ap.bcast_hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2846 | if (ret < 0) |
| 2847 | goto out; |
| 2848 | } |
| 2849 | |
| 2850 | out: |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2851 | wl1271_free_ap_keys(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2852 | return ret; |
| 2853 | } |
| 2854 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2855 | static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2856 | u16 action, u8 id, u8 key_type, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2857 | u8 key_size, const u8 *key, u32 tx_seq_32, |
| 2858 | u16 tx_seq_16, struct ieee80211_sta *sta) |
| 2859 | { |
| 2860 | int ret; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2861 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2862 | |
| 2863 | if (is_ap) { |
| 2864 | struct wl1271_station *wl_sta; |
| 2865 | u8 hlid; |
| 2866 | |
| 2867 | if (sta) { |
| 2868 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 2869 | hlid = wl_sta->hlid; |
| 2870 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2871 | hlid = wlvif->ap.bcast_hlid; |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2872 | } |
| 2873 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 2874 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2875 | /* |
| 2876 | * We do not support removing keys after AP shutdown. |
| 2877 | * Pretend we do to make mac80211 happy. |
| 2878 | */ |
| 2879 | if (action != KEY_ADD_OR_REPLACE) |
| 2880 | return 0; |
| 2881 | |
Eliad Peller | 170d0e6 | 2011-10-05 11:56:06 +0200 | [diff] [blame] | 2882 | ret = wl1271_record_ap_key(wl, wlvif, id, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2883 | key_type, key_size, |
| 2884 | key, hlid, tx_seq_32, |
| 2885 | tx_seq_16); |
| 2886 | } else { |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2887 | ret = wl1271_cmd_set_ap_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2888 | id, key_type, key_size, |
| 2889 | key, hlid, tx_seq_32, |
| 2890 | tx_seq_16); |
| 2891 | } |
| 2892 | |
| 2893 | if (ret < 0) |
| 2894 | return ret; |
| 2895 | } else { |
| 2896 | const u8 *addr; |
| 2897 | static const u8 bcast_addr[ETH_ALEN] = { |
| 2898 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff |
| 2899 | }; |
| 2900 | |
| 2901 | addr = sta ? sta->addr : bcast_addr; |
| 2902 | |
| 2903 | if (is_zero_ether_addr(addr)) { |
| 2904 | /* We dont support TX only encryption */ |
| 2905 | return -EOPNOTSUPP; |
| 2906 | } |
| 2907 | |
| 2908 | /* The wl1271 does not allow to remove unicast keys - they |
| 2909 | will be cleared automatically on next CMD_JOIN. Ignore the |
| 2910 | request silently, as we dont want the mac80211 to emit |
| 2911 | an error message. */ |
| 2912 | if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr)) |
| 2913 | return 0; |
| 2914 | |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 2915 | /* don't remove key if hlid was already deleted */ |
| 2916 | if (action == KEY_REMOVE && |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 2917 | wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | 010d3d3 | 2011-08-14 13:17:31 +0300 | [diff] [blame] | 2918 | return 0; |
| 2919 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 2920 | ret = wl1271_cmd_set_sta_key(wl, wlvif, action, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2921 | id, key_type, key_size, |
| 2922 | key, addr, tx_seq_32, |
| 2923 | tx_seq_16); |
| 2924 | if (ret < 0) |
| 2925 | return ret; |
| 2926 | |
| 2927 | /* the default WEP key needs to be configured at least once */ |
| 2928 | if (key_type == KEY_WEP) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 2929 | ret = wl12xx_cmd_set_default_wep_key(wl, |
Eliad Peller | f75c753f | 2011-10-05 11:55:59 +0200 | [diff] [blame] | 2930 | wlvif->default_key, |
| 2931 | wlvif->sta.hlid); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2932 | if (ret < 0) |
| 2933 | return ret; |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | return 0; |
| 2938 | } |
| 2939 | |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 2940 | 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] | 2941 | struct ieee80211_vif *vif, |
| 2942 | struct ieee80211_sta *sta, |
| 2943 | struct ieee80211_key_conf *key_conf) |
| 2944 | { |
| 2945 | struct wl1271 *wl = hw->priv; |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 2946 | |
| 2947 | return wlcore_hw_set_key(wl, cmd, vif, sta, key_conf); |
| 2948 | } |
| 2949 | |
| 2950 | int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd, |
| 2951 | struct ieee80211_vif *vif, |
| 2952 | struct ieee80211_sta *sta, |
| 2953 | struct ieee80211_key_conf *key_conf) |
| 2954 | { |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 2955 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2956 | int ret; |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 2957 | u32 tx_seq_32 = 0; |
| 2958 | u16 tx_seq_16 = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2959 | u8 key_type; |
| 2960 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2961 | wl1271_debug(DEBUG_MAC80211, "mac80211 set key"); |
| 2962 | |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 2963 | wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2964 | 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] | 2965 | key_conf->cipher, key_conf->keyidx, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2966 | key_conf->keylen, key_conf->flags); |
| 2967 | wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen); |
| 2968 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2969 | mutex_lock(&wl->mutex); |
| 2970 | |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 2971 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 2972 | ret = -EAGAIN; |
| 2973 | goto out_unlock; |
| 2974 | } |
| 2975 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 2976 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2977 | if (ret < 0) |
| 2978 | goto out_unlock; |
| 2979 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 2980 | switch (key_conf->cipher) { |
| 2981 | case WLAN_CIPHER_SUITE_WEP40: |
| 2982 | case WLAN_CIPHER_SUITE_WEP104: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2983 | key_type = KEY_WEP; |
| 2984 | |
| 2985 | key_conf->hw_key_idx = key_conf->keyidx; |
| 2986 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 2987 | case WLAN_CIPHER_SUITE_TKIP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2988 | key_type = KEY_TKIP; |
| 2989 | |
| 2990 | key_conf->hw_key_idx = key_conf->keyidx; |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2991 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
| 2992 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2993 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 2994 | case WLAN_CIPHER_SUITE_CCMP: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 2995 | key_type = KEY_AES; |
| 2996 | |
Arik Nemtsov | 12d4b97 | 2011-10-23 08:21:54 +0200 | [diff] [blame] | 2997 | key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 2998 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
| 2999 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3000 | break; |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3001 | case WL1271_CIPHER_SUITE_GEM: |
| 3002 | key_type = KEY_GEM; |
Eliad Peller | 48e93e4 | 2011-10-10 10:12:58 +0200 | [diff] [blame] | 3003 | tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq); |
| 3004 | tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq); |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 3005 | break; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3006 | default: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3007 | wl1271_error("Unknown key algo 0x%x", key_conf->cipher); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3008 | |
| 3009 | ret = -EOPNOTSUPP; |
| 3010 | goto out_sleep; |
| 3011 | } |
| 3012 | |
| 3013 | switch (cmd) { |
| 3014 | case SET_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3015 | ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3016 | key_conf->keyidx, key_type, |
| 3017 | key_conf->keylen, key_conf->key, |
| 3018 | tx_seq_32, tx_seq_16, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3019 | if (ret < 0) { |
| 3020 | wl1271_error("Could not add or replace key"); |
| 3021 | goto out_sleep; |
| 3022 | } |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 3023 | |
| 3024 | /* |
| 3025 | * reconfiguring arp response if the unicast (or common) |
| 3026 | * encryption key type was changed |
| 3027 | */ |
| 3028 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 3029 | (sta || key_type == KEY_WEP) && |
| 3030 | wlvif->encryption_type != key_type) { |
| 3031 | wlvif->encryption_type = key_type; |
| 3032 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 3033 | if (ret < 0) { |
| 3034 | wl1271_warning("build arp rsp failed: %d", ret); |
| 3035 | goto out_sleep; |
| 3036 | } |
| 3037 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3038 | break; |
| 3039 | |
| 3040 | case DISABLE_KEY: |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3041 | ret = wl1271_set_key(wl, wlvif, KEY_REMOVE, |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3042 | key_conf->keyidx, key_type, |
| 3043 | key_conf->keylen, key_conf->key, |
| 3044 | 0, 0, sta); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3045 | if (ret < 0) { |
| 3046 | wl1271_error("Could not remove key"); |
| 3047 | goto out_sleep; |
| 3048 | } |
| 3049 | break; |
| 3050 | |
| 3051 | default: |
| 3052 | wl1271_error("Unsupported key cmd 0x%x", cmd); |
| 3053 | ret = -EOPNOTSUPP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3054 | break; |
| 3055 | } |
| 3056 | |
| 3057 | out_sleep: |
| 3058 | wl1271_ps_elp_sleep(wl); |
| 3059 | |
| 3060 | out_unlock: |
| 3061 | mutex_unlock(&wl->mutex); |
| 3062 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3063 | return ret; |
| 3064 | } |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 3065 | EXPORT_SYMBOL_GPL(wlcore_set_key); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3066 | |
| 3067 | static int wl1271_op_hw_scan(struct ieee80211_hw *hw, |
Johannes Berg | a060bbf | 2010-04-27 11:59:34 +0200 | [diff] [blame] | 3068 | struct ieee80211_vif *vif, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3069 | struct cfg80211_scan_request *req) |
| 3070 | { |
| 3071 | struct wl1271 *wl = hw->priv; |
| 3072 | int ret; |
| 3073 | u8 *ssid = NULL; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3074 | size_t len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3075 | |
| 3076 | wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan"); |
| 3077 | |
| 3078 | if (req->n_ssids) { |
| 3079 | ssid = req->ssids[0].ssid; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 3080 | len = req->ssids[0].ssid_len; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | mutex_lock(&wl->mutex); |
| 3084 | |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 3085 | if (wl->state == WL1271_STATE_OFF) { |
| 3086 | /* |
| 3087 | * We cannot return -EBUSY here because cfg80211 will expect |
| 3088 | * a call to ieee80211_scan_completed if we do - in this case |
| 3089 | * there won't be any call. |
| 3090 | */ |
| 3091 | ret = -EAGAIN; |
| 3092 | goto out; |
| 3093 | } |
| 3094 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3095 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3096 | if (ret < 0) |
| 3097 | goto out; |
| 3098 | |
Eliad Peller | 97fd311 | 2012-03-04 10:55:52 +0200 | [diff] [blame] | 3099 | /* fail if there is any role in ROC */ |
| 3100 | 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] | 3101 | /* don't allow scanning right now */ |
| 3102 | ret = -EBUSY; |
| 3103 | goto out_sleep; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3104 | } |
| 3105 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3106 | ret = wl1271_scan(hw->priv, vif, ssid, len, req); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3107 | out_sleep: |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3108 | wl1271_ps_elp_sleep(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3109 | out: |
| 3110 | mutex_unlock(&wl->mutex); |
| 3111 | |
| 3112 | return ret; |
| 3113 | } |
| 3114 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3115 | static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw, |
| 3116 | struct ieee80211_vif *vif) |
| 3117 | { |
| 3118 | struct wl1271 *wl = hw->priv; |
| 3119 | int ret; |
| 3120 | |
| 3121 | wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan"); |
| 3122 | |
| 3123 | mutex_lock(&wl->mutex); |
| 3124 | |
| 3125 | if (wl->state == WL1271_STATE_OFF) |
| 3126 | goto out; |
| 3127 | |
| 3128 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) |
| 3129 | goto out; |
| 3130 | |
| 3131 | ret = wl1271_ps_elp_wakeup(wl); |
| 3132 | if (ret < 0) |
| 3133 | goto out; |
| 3134 | |
| 3135 | if (wl->scan.state != WL1271_SCAN_STATE_DONE) { |
| 3136 | ret = wl1271_scan_stop(wl); |
| 3137 | if (ret < 0) |
| 3138 | goto out_sleep; |
| 3139 | } |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 3140 | |
| 3141 | /* |
| 3142 | * Rearm the tx watchdog just before idling scan. This |
| 3143 | * prevents just-finished scans from triggering the watchdog |
| 3144 | */ |
| 3145 | wl12xx_rearm_tx_watchdog_locked(wl); |
| 3146 | |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3147 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
| 3148 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3149 | wl->scan_vif = NULL; |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 3150 | wl->scan.req = NULL; |
| 3151 | ieee80211_scan_completed(wl->hw, true); |
| 3152 | |
| 3153 | out_sleep: |
| 3154 | wl1271_ps_elp_sleep(wl); |
| 3155 | out: |
| 3156 | mutex_unlock(&wl->mutex); |
| 3157 | |
| 3158 | cancel_delayed_work_sync(&wl->scan_complete_work); |
| 3159 | } |
| 3160 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3161 | static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw, |
| 3162 | struct ieee80211_vif *vif, |
| 3163 | struct cfg80211_sched_scan_request *req, |
| 3164 | struct ieee80211_sched_scan_ies *ies) |
| 3165 | { |
| 3166 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3167 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3168 | int ret; |
| 3169 | |
| 3170 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); |
| 3171 | |
| 3172 | mutex_lock(&wl->mutex); |
| 3173 | |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3174 | if (wl->state == WL1271_STATE_OFF) { |
| 3175 | ret = -EAGAIN; |
| 3176 | goto out; |
| 3177 | } |
| 3178 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3179 | ret = wl1271_ps_elp_wakeup(wl); |
| 3180 | if (ret < 0) |
| 3181 | goto out; |
| 3182 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3183 | ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3184 | if (ret < 0) |
| 3185 | goto out_sleep; |
| 3186 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3187 | ret = wl1271_scan_sched_scan_start(wl, wlvif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3188 | if (ret < 0) |
| 3189 | goto out_sleep; |
| 3190 | |
| 3191 | wl->sched_scanning = true; |
| 3192 | |
| 3193 | out_sleep: |
| 3194 | wl1271_ps_elp_sleep(wl); |
| 3195 | out: |
| 3196 | mutex_unlock(&wl->mutex); |
| 3197 | return ret; |
| 3198 | } |
| 3199 | |
| 3200 | static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw, |
| 3201 | struct ieee80211_vif *vif) |
| 3202 | { |
| 3203 | struct wl1271 *wl = hw->priv; |
Yoni Divinsky | 78f85f5 | 2012-05-16 11:34:17 +0300 | [diff] [blame] | 3204 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3205 | int ret; |
| 3206 | |
| 3207 | wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); |
| 3208 | |
| 3209 | mutex_lock(&wl->mutex); |
| 3210 | |
Pontus Fuchs | 9e0dc89 | 2012-01-11 14:22:42 +0100 | [diff] [blame] | 3211 | if (wl->state == WL1271_STATE_OFF) |
| 3212 | goto out; |
| 3213 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3214 | ret = wl1271_ps_elp_wakeup(wl); |
| 3215 | if (ret < 0) |
| 3216 | goto out; |
| 3217 | |
Yoni Divinsky | 78f85f5 | 2012-05-16 11:34:17 +0300 | [diff] [blame] | 3218 | wl1271_scan_sched_scan_stop(wl, wlvif); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 3219 | |
| 3220 | wl1271_ps_elp_sleep(wl); |
| 3221 | out: |
| 3222 | mutex_unlock(&wl->mutex); |
| 3223 | } |
| 3224 | |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3225 | static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 3226 | { |
| 3227 | struct wl1271 *wl = hw->priv; |
| 3228 | int ret = 0; |
| 3229 | |
| 3230 | mutex_lock(&wl->mutex); |
| 3231 | |
| 3232 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 3233 | ret = -EAGAIN; |
| 3234 | goto out; |
| 3235 | } |
| 3236 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3237 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3238 | if (ret < 0) |
| 3239 | goto out; |
| 3240 | |
Arik Nemtsov | 5f704d1 | 2011-04-18 14:15:21 +0300 | [diff] [blame] | 3241 | ret = wl1271_acx_frag_threshold(wl, value); |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 3242 | if (ret < 0) |
| 3243 | wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret); |
| 3244 | |
| 3245 | wl1271_ps_elp_sleep(wl); |
| 3246 | |
| 3247 | out: |
| 3248 | mutex_unlock(&wl->mutex); |
| 3249 | |
| 3250 | return ret; |
| 3251 | } |
| 3252 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3253 | static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 3254 | { |
| 3255 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3256 | struct wl12xx_vif *wlvif; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3257 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3258 | |
| 3259 | mutex_lock(&wl->mutex); |
| 3260 | |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3261 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 3262 | ret = -EAGAIN; |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3263 | goto out; |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 3264 | } |
Saravanan Dhanabal | aecb056 | 2010-04-09 11:07:28 +0300 | [diff] [blame] | 3265 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 3266 | ret = wl1271_ps_elp_wakeup(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3267 | if (ret < 0) |
| 3268 | goto out; |
| 3269 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 3270 | wl12xx_for_each_wlvif(wl, wlvif) { |
| 3271 | ret = wl1271_acx_rts_threshold(wl, wlvif, value); |
| 3272 | if (ret < 0) |
| 3273 | wl1271_warning("set rts threshold failed: %d", ret); |
| 3274 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3275 | wl1271_ps_elp_sleep(wl); |
| 3276 | |
| 3277 | out: |
| 3278 | mutex_unlock(&wl->mutex); |
| 3279 | |
| 3280 | return ret; |
| 3281 | } |
| 3282 | |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3283 | static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb, |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3284 | int offset) |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3285 | { |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3286 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3287 | u8 ssid_len; |
| 3288 | const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, |
| 3289 | skb->len - offset); |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3290 | |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3291 | if (!ptr) { |
| 3292 | wl1271_error("No SSID in IEs!"); |
| 3293 | return -ENOENT; |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3294 | } |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3295 | |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3296 | ssid_len = ptr[1]; |
| 3297 | if (ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3298 | wl1271_error("SSID is too long!"); |
| 3299 | return -EINVAL; |
| 3300 | } |
| 3301 | |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3302 | wlvif->ssid_len = ssid_len; |
| 3303 | memcpy(wlvif->ssid, ptr+2, ssid_len); |
Eliad Peller | 889cb36 | 2011-05-01 09:56:45 +0300 | [diff] [blame] | 3304 | return 0; |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3305 | } |
| 3306 | |
Eliad Peller | d48055d | 2011-09-15 12:07:04 +0300 | [diff] [blame] | 3307 | static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset) |
| 3308 | { |
| 3309 | int len; |
| 3310 | const u8 *next, *end = skb->data + skb->len; |
| 3311 | u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset, |
| 3312 | skb->len - ieoffset); |
| 3313 | if (!ie) |
| 3314 | return; |
| 3315 | len = ie[1] + 2; |
| 3316 | next = ie + len; |
| 3317 | memmove(ie, next, end - next); |
| 3318 | skb_trim(skb, skb->len - len); |
| 3319 | } |
| 3320 | |
Eliad Peller | 26b4bf2 | 2011-09-15 12:07:05 +0300 | [diff] [blame] | 3321 | static void wl12xx_remove_vendor_ie(struct sk_buff *skb, |
| 3322 | unsigned int oui, u8 oui_type, |
| 3323 | int ieoffset) |
| 3324 | { |
| 3325 | int len; |
| 3326 | const u8 *next, *end = skb->data + skb->len; |
| 3327 | u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 3328 | skb->data + ieoffset, |
| 3329 | skb->len - ieoffset); |
| 3330 | if (!ie) |
| 3331 | return; |
| 3332 | len = ie[1] + 2; |
| 3333 | next = ie + len; |
| 3334 | memmove(ie, next, end - next); |
| 3335 | skb_trim(skb, skb->len - len); |
| 3336 | } |
| 3337 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3338 | static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates, |
| 3339 | struct ieee80211_vif *vif) |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3340 | { |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3341 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3342 | struct sk_buff *skb; |
| 3343 | int ret; |
| 3344 | |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3345 | skb = ieee80211_proberesp_get(wl->hw, vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3346 | if (!skb) |
Arik Nemtsov | 341f2c1 | 2011-11-22 19:52:59 +0200 | [diff] [blame] | 3347 | return -EOPNOTSUPP; |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3348 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3349 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3350 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3351 | skb->data, |
| 3352 | skb->len, 0, |
| 3353 | rates); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3354 | dev_kfree_skb(skb); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3355 | |
| 3356 | if (ret < 0) |
| 3357 | goto out; |
| 3358 | |
| 3359 | wl1271_debug(DEBUG_AP, "probe response updated"); |
| 3360 | set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags); |
| 3361 | |
| 3362 | out: |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3363 | return ret; |
| 3364 | } |
| 3365 | |
| 3366 | static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl, |
| 3367 | struct ieee80211_vif *vif, |
| 3368 | u8 *probe_rsp_data, |
| 3369 | size_t probe_rsp_len, |
| 3370 | u32 rates) |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3371 | { |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3372 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3373 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3374 | u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; |
| 3375 | int ssid_ie_offset, ie_offset, templ_len; |
| 3376 | const u8 *ptr; |
| 3377 | |
| 3378 | /* no need to change probe response if the SSID is set correctly */ |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 3379 | if (wlvif->ssid_len > 0) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3380 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3381 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3382 | probe_rsp_data, |
| 3383 | probe_rsp_len, 0, |
| 3384 | rates); |
| 3385 | |
| 3386 | if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) { |
| 3387 | wl1271_error("probe_rsp template too big"); |
| 3388 | return -EINVAL; |
| 3389 | } |
| 3390 | |
| 3391 | /* start searching from IE offset */ |
| 3392 | ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 3393 | |
| 3394 | ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset, |
| 3395 | probe_rsp_len - ie_offset); |
| 3396 | if (!ptr) { |
| 3397 | wl1271_error("No SSID in beacon!"); |
| 3398 | return -EINVAL; |
| 3399 | } |
| 3400 | |
| 3401 | ssid_ie_offset = ptr - probe_rsp_data; |
| 3402 | ptr += (ptr[1] + 2); |
| 3403 | |
| 3404 | memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset); |
| 3405 | |
| 3406 | /* insert SSID from bss_conf */ |
| 3407 | probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID; |
| 3408 | probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len; |
| 3409 | memcpy(probe_rsp_templ + ssid_ie_offset + 2, |
| 3410 | bss_conf->ssid, bss_conf->ssid_len); |
| 3411 | templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len; |
| 3412 | |
| 3413 | memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len, |
| 3414 | ptr, probe_rsp_len - (ptr - probe_rsp_data)); |
| 3415 | templ_len += probe_rsp_len - (ptr - probe_rsp_data); |
| 3416 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 3417 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 3418 | CMD_TEMPL_AP_PROBE_RESPONSE, |
| 3419 | probe_rsp_templ, |
| 3420 | templ_len, 0, |
| 3421 | rates); |
| 3422 | } |
| 3423 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3424 | static int wl1271_bss_erp_info_changed(struct wl1271 *wl, |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3425 | struct ieee80211_vif *vif, |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3426 | struct ieee80211_bss_conf *bss_conf, |
| 3427 | u32 changed) |
| 3428 | { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3429 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3430 | int ret = 0; |
| 3431 | |
| 3432 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 3433 | if (bss_conf->use_short_slot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3434 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3435 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3436 | ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3437 | if (ret < 0) { |
| 3438 | wl1271_warning("Set slot time failed %d", ret); |
| 3439 | goto out; |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 3444 | if (bss_conf->use_short_preamble) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3445 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3446 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3447 | wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 3451 | if (bss_conf->use_cts_prot) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3452 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3453 | CTSPROTECT_ENABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3454 | else |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3455 | ret = wl1271_acx_cts_protect(wl, wlvif, |
| 3456 | CTSPROTECT_DISABLE); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3457 | if (ret < 0) { |
| 3458 | wl1271_warning("Set ctsprotect failed %d", ret); |
| 3459 | goto out; |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | out: |
| 3464 | return ret; |
| 3465 | } |
| 3466 | |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3467 | static int wlcore_set_beacon_template(struct wl1271 *wl, |
| 3468 | struct ieee80211_vif *vif, |
| 3469 | bool is_ap) |
| 3470 | { |
| 3471 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 3472 | struct ieee80211_hdr *hdr; |
| 3473 | u32 min_rate; |
| 3474 | int ret; |
| 3475 | int ieoffset = offsetof(struct ieee80211_mgmt, |
| 3476 | u.beacon.variable); |
| 3477 | struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); |
| 3478 | u16 tmpl_id; |
| 3479 | |
| 3480 | if (!beacon) { |
| 3481 | ret = -EINVAL; |
| 3482 | goto out; |
| 3483 | } |
| 3484 | |
| 3485 | wl1271_debug(DEBUG_MASTER, "beacon updated"); |
| 3486 | |
| 3487 | ret = wl1271_ssid_set(vif, beacon, ieoffset); |
| 3488 | if (ret < 0) { |
| 3489 | dev_kfree_skb(beacon); |
| 3490 | goto out; |
| 3491 | } |
| 3492 | min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 3493 | tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : |
| 3494 | CMD_TEMPL_BEACON; |
| 3495 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id, |
| 3496 | beacon->data, |
| 3497 | beacon->len, 0, |
| 3498 | min_rate); |
| 3499 | if (ret < 0) { |
| 3500 | dev_kfree_skb(beacon); |
| 3501 | goto out; |
| 3502 | } |
| 3503 | |
| 3504 | /* |
| 3505 | * In case we already have a probe-resp beacon set explicitly |
| 3506 | * by usermode, don't use the beacon data. |
| 3507 | */ |
| 3508 | if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags)) |
| 3509 | goto end_bcn; |
| 3510 | |
| 3511 | /* remove TIM ie from probe response */ |
| 3512 | wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); |
| 3513 | |
| 3514 | /* |
| 3515 | * remove p2p ie from probe response. |
| 3516 | * the fw reponds to probe requests that don't include |
| 3517 | * the p2p ie. probe requests with p2p ie will be passed, |
| 3518 | * and will be responded by the supplicant (the spec |
| 3519 | * forbids including the p2p ie when responding to probe |
| 3520 | * requests that didn't include it). |
| 3521 | */ |
| 3522 | wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA, |
| 3523 | WLAN_OUI_TYPE_WFA_P2P, ieoffset); |
| 3524 | |
| 3525 | hdr = (struct ieee80211_hdr *) beacon->data; |
| 3526 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 3527 | IEEE80211_STYPE_PROBE_RESP); |
| 3528 | if (is_ap) |
| 3529 | ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif, |
| 3530 | beacon->data, |
| 3531 | beacon->len, |
| 3532 | min_rate); |
| 3533 | else |
| 3534 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 3535 | CMD_TEMPL_PROBE_RESPONSE, |
| 3536 | beacon->data, |
| 3537 | beacon->len, 0, |
| 3538 | min_rate); |
| 3539 | end_bcn: |
| 3540 | dev_kfree_skb(beacon); |
| 3541 | if (ret < 0) |
| 3542 | goto out; |
| 3543 | |
| 3544 | out: |
| 3545 | return ret; |
| 3546 | } |
| 3547 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3548 | static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, |
| 3549 | struct ieee80211_vif *vif, |
| 3550 | struct ieee80211_bss_conf *bss_conf, |
| 3551 | u32 changed) |
| 3552 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3553 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3554 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3555 | int ret = 0; |
| 3556 | |
| 3557 | if ((changed & BSS_CHANGED_BEACON_INT)) { |
| 3558 | wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", |
| 3559 | bss_conf->beacon_int); |
| 3560 | |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 3561 | wlvif->beacon_int = bss_conf->beacon_int; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3562 | } |
| 3563 | |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3564 | if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { |
| 3565 | u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3566 | |
| 3567 | wl1271_ap_set_probe_resp_tmpl(wl, rate, vif); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3568 | } |
| 3569 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3570 | if ((changed & BSS_CHANGED_BEACON)) { |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3571 | ret = wlcore_set_beacon_template(wl, vif, is_ap); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3572 | if (ret < 0) |
| 3573 | goto out; |
| 3574 | } |
| 3575 | |
| 3576 | out: |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3577 | if (ret != 0) |
| 3578 | wl1271_error("beacon info change failed: %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3579 | return ret; |
| 3580 | } |
| 3581 | |
| 3582 | /* AP mode changes */ |
| 3583 | static void wl1271_bss_info_changed_ap(struct wl1271 *wl, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3584 | struct ieee80211_vif *vif, |
| 3585 | struct ieee80211_bss_conf *bss_conf, |
| 3586 | u32 changed) |
| 3587 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3588 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3589 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3590 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3591 | if ((changed & BSS_CHANGED_BASIC_RATES)) { |
| 3592 | u32 rates = bss_conf->basic_rates; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3593 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3594 | wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3595 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3596 | wlvif->basic_rate = wl1271_tx_min_rate_get(wl, |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3597 | wlvif->basic_rate_set); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3598 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3599 | ret = wl1271_init_ap_rates(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3600 | if (ret < 0) { |
Arik Nemtsov | 70f4742 | 2011-04-18 14:15:25 +0300 | [diff] [blame] | 3601 | wl1271_error("AP rate policy change failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3602 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3603 | } |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3604 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3605 | ret = wl1271_ap_init_templates(wl, vif); |
Arik Nemtsov | c45a85b | 2011-04-18 14:15:26 +0300 | [diff] [blame] | 3606 | if (ret < 0) |
| 3607 | goto out; |
Luciano Coelho | 62c2e57 | 2012-05-10 12:14:04 +0300 | [diff] [blame] | 3608 | |
| 3609 | ret = wl1271_ap_set_probe_resp_tmpl(wl, wlvif->basic_rate, vif); |
| 3610 | if (ret < 0) |
| 3611 | goto out; |
| 3612 | |
| 3613 | ret = wlcore_set_beacon_template(wl, vif, true); |
| 3614 | if (ret < 0) |
| 3615 | goto out; |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 3616 | } |
| 3617 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3618 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); |
| 3619 | if (ret < 0) |
| 3620 | goto out; |
| 3621 | |
| 3622 | if ((changed & BSS_CHANGED_BEACON_ENABLED)) { |
| 3623 | if (bss_conf->enable_beacon) { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3624 | if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3625 | ret = wl12xx_cmd_role_start_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3626 | if (ret < 0) |
| 3627 | goto out; |
| 3628 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 3629 | ret = wl1271_ap_init_hwenc(wl, wlvif); |
Arik Nemtsov | 7f179b4 | 2010-10-16 21:39:06 +0200 | [diff] [blame] | 3630 | if (ret < 0) |
| 3631 | goto out; |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3632 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3633 | set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | cf42039 | 2011-08-14 13:17:37 +0300 | [diff] [blame] | 3634 | wl1271_debug(DEBUG_AP, "started AP"); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3635 | } |
| 3636 | } else { |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3637 | if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3638 | ret = wl12xx_cmd_role_stop_ap(wl, wlvif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3639 | if (ret < 0) |
| 3640 | goto out; |
| 3641 | |
Eliad Peller | 53d40d0 | 2011-10-10 10:13:02 +0200 | [diff] [blame] | 3642 | clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags); |
Arik Nemtsov | 560f00241 | 2011-11-08 18:46:54 +0200 | [diff] [blame] | 3643 | clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, |
| 3644 | &wlvif->flags); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3645 | wl1271_debug(DEBUG_AP, "stopped AP"); |
| 3646 | } |
| 3647 | } |
| 3648 | } |
| 3649 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3650 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3651 | if (ret < 0) |
| 3652 | goto out; |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3653 | |
| 3654 | /* Handle HT information change */ |
| 3655 | if ((changed & BSS_CHANGED_HT) && |
| 3656 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3657 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3658 | bss_conf->ht_operation_mode); |
| 3659 | if (ret < 0) { |
| 3660 | wl1271_warning("Set ht information failed %d", ret); |
| 3661 | goto out; |
| 3662 | } |
| 3663 | } |
| 3664 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3665 | out: |
| 3666 | return; |
| 3667 | } |
| 3668 | |
| 3669 | /* STA/IBSS mode changes */ |
| 3670 | static void wl1271_bss_info_changed_sta(struct wl1271 *wl, |
| 3671 | struct ieee80211_vif *vif, |
| 3672 | struct ieee80211_bss_conf *bss_conf, |
| 3673 | u32 changed) |
| 3674 | { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3675 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3676 | bool do_join = false, set_assoc = false; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 3677 | bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3678 | bool ibss_joined = false; |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3679 | u32 sta_rate_set = 0; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3680 | int ret; |
Luciano Coelho | 2d6e4e76 | 2011-01-11 19:07:21 +0100 | [diff] [blame] | 3681 | struct ieee80211_sta *sta; |
Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 3682 | bool sta_exists = false; |
| 3683 | struct ieee80211_sta_ht_cap sta_ht_cap; |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3684 | |
| 3685 | if (is_ibss) { |
| 3686 | ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, |
| 3687 | changed); |
| 3688 | if (ret < 0) |
| 3689 | goto out; |
| 3690 | } |
| 3691 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3692 | if (changed & BSS_CHANGED_IBSS) { |
| 3693 | if (bss_conf->ibss_joined) { |
Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 3694 | set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3695 | ibss_joined = true; |
| 3696 | } else { |
Eliad Peller | eee514e | 2011-10-10 10:13:01 +0200 | [diff] [blame] | 3697 | if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED, |
Eliad Peller | 349345a | 2012-03-04 10:55:45 +0200 | [diff] [blame] | 3698 | &wlvif->flags)) |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3699 | wl1271_unjoin(wl, wlvif); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3700 | } |
| 3701 | } |
| 3702 | |
| 3703 | if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3704 | do_join = true; |
| 3705 | |
| 3706 | /* Need to update the SSID (for filtering etc) */ |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3707 | if ((changed & BSS_CHANGED_BEACON) && ibss_joined) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3708 | do_join = true; |
| 3709 | |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 3710 | if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) { |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 3711 | wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", |
| 3712 | bss_conf->enable_beacon ? "enabled" : "disabled"); |
| 3713 | |
Juuso Oikarinen | 5da11dc | 2010-03-26 12:53:24 +0200 | [diff] [blame] | 3714 | do_join = true; |
| 3715 | } |
| 3716 | |
Eliad Peller | 349345a | 2012-03-04 10:55:45 +0200 | [diff] [blame] | 3717 | if (changed & BSS_CHANGED_IDLE && !is_ibss) { |
Eliad Peller | c31e494 | 2011-10-23 08:21:55 +0200 | [diff] [blame] | 3718 | ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle); |
| 3719 | if (ret < 0) |
| 3720 | wl1271_warning("idle mode change failed %d", ret); |
| 3721 | } |
| 3722 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3723 | if ((changed & BSS_CHANGED_CQM)) { |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3724 | bool enable = false; |
| 3725 | if (bss_conf->cqm_rssi_thold) |
| 3726 | enable = true; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3727 | ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable, |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3728 | bss_conf->cqm_rssi_thold, |
| 3729 | bss_conf->cqm_rssi_hyst); |
| 3730 | if (ret < 0) |
| 3731 | goto out; |
Eliad Peller | 04324d9 | 2011-10-05 11:56:03 +0200 | [diff] [blame] | 3732 | wlvif->rssi_thold = bss_conf->cqm_rssi_thold; |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 3733 | } |
| 3734 | |
Eliad Peller | 446f5ca | 2012-03-12 14:53:04 +0200 | [diff] [blame] | 3735 | if (changed & BSS_CHANGED_BSSID) |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 3736 | if (!is_zero_ether_addr(bss_conf->bssid)) { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3737 | ret = wl12xx_cmd_build_null_data(wl, wlvif); |
Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3738 | if (ret < 0) |
| 3739 | goto out; |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3740 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 3741 | ret = wl1271_build_qos_null_data(wl, vif); |
Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3742 | if (ret < 0) |
| 3743 | goto out; |
Eliad Peller | fa287b8 | 2010-12-26 09:27:50 +0100 | [diff] [blame] | 3744 | } |
Juuso Oikarinen | 30240fc | 2010-02-18 13:25:38 +0200 | [diff] [blame] | 3745 | |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3746 | if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) { |
| 3747 | rcu_read_lock(); |
| 3748 | sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 3749 | if (!sta) |
| 3750 | goto sta_not_found; |
| 3751 | |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3752 | /* save the supp_rates of the ap */ |
| 3753 | sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band]; |
| 3754 | if (sta->ht_cap.ht_supported) |
| 3755 | sta_rate_set |= |
Arik Nemtsov | b3a47ee | 2012-05-10 12:13:33 +0300 | [diff] [blame] | 3756 | (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) | |
| 3757 | (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET); |
Arik Nemtsov | a100885 | 2011-02-12 23:24:20 +0200 | [diff] [blame] | 3758 | sta_ht_cap = sta->ht_cap; |
| 3759 | sta_exists = true; |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3760 | |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3761 | sta_not_found: |
| 3762 | rcu_read_unlock(); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3763 | } |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3764 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3765 | if ((changed & BSS_CHANGED_ASSOC)) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3766 | if (bss_conf->assoc) { |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3767 | u32 rates; |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3768 | int ieoffset; |
Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3769 | wlvif->aid = bss_conf->aid; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 3770 | wlvif->channel_type = bss_conf->channel_type; |
Eliad Peller | 6667776 | 2012-03-04 10:55:53 +0200 | [diff] [blame] | 3771 | wlvif->beacon_int = bss_conf->beacon_int; |
Eliad Peller | 446f5ca | 2012-03-12 14:53:04 +0200 | [diff] [blame] | 3772 | do_join = true; |
Juuso Oikarinen | 69e5434 | 2010-05-07 11:39:00 +0300 | [diff] [blame] | 3773 | set_assoc = true; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3774 | |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 3775 | /* |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3776 | * use basic rates from AP, and determine lowest rate |
| 3777 | * to use with control frames. |
| 3778 | */ |
| 3779 | rates = bss_conf->basic_rates; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3780 | wlvif->basic_rate_set = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3781 | wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3782 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3783 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3784 | wl1271_tx_min_rate_get(wl, |
| 3785 | wlvif->basic_rate_set); |
Eliad Peller | 72c2d9e | 2011-02-02 09:59:37 +0200 | [diff] [blame] | 3786 | if (sta_rate_set) |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3787 | wlvif->rate_set = |
| 3788 | wl1271_tx_enabled_rates_get(wl, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3789 | sta_rate_set, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3790 | wlvif->band); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3791 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3792 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3793 | goto out; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3794 | |
| 3795 | /* |
Luciano Coelho | ae751ba | 2009-10-12 15:08:57 +0300 | [diff] [blame] | 3796 | * with wl1271, we don't need to update the |
| 3797 | * beacon_int and dtim_period, because the firmware |
| 3798 | * updates it by itself when the first beacon is |
| 3799 | * received after a join. |
| 3800 | */ |
Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3801 | ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3802 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3803 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3804 | |
Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3805 | /* |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3806 | * Get a template for hardware connection maintenance |
Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3807 | */ |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3808 | dev_kfree_skb(wlvif->probereq); |
| 3809 | wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl, |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 3810 | wlvif, |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3811 | NULL); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3812 | ieoffset = offsetof(struct ieee80211_mgmt, |
| 3813 | u.probe_req.variable); |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3814 | wl1271_ssid_set(vif, wlvif->probereq, ieoffset); |
Juuso Oikarinen | c2b2d99 | 2010-03-26 12:53:28 +0200 | [diff] [blame] | 3815 | |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3816 | /* enable the connection monitoring feature */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3817 | ret = wl1271_acx_conn_monit_params(wl, wlvif, true); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3818 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3819 | goto out; |
Juuso Oikarinen | d94cd29 | 2009-10-08 21:56:25 +0300 | [diff] [blame] | 3820 | } else { |
| 3821 | /* use defaults when not associated */ |
Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3822 | bool was_assoc = |
Eliad Peller | ba8447f | 2011-10-10 10:13:00 +0200 | [diff] [blame] | 3823 | !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED, |
| 3824 | &wlvif->flags); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3825 | bool was_ifup = |
Eliad Peller | 8181aec | 2011-10-10 10:13:04 +0200 | [diff] [blame] | 3826 | !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT, |
| 3827 | &wlvif->flags); |
Eliad Peller | 6840e37 | 2011-10-05 11:55:50 +0200 | [diff] [blame] | 3828 | wlvif->aid = 0; |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3829 | |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3830 | /* free probe-request template */ |
Eliad Peller | bddb29b | 2011-10-05 11:55:49 +0200 | [diff] [blame] | 3831 | dev_kfree_skb(wlvif->probereq); |
| 3832 | wlvif->probereq = NULL; |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 3833 | |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3834 | /* revert back to minimum rates for the current band */ |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3835 | wl1271_set_band_rate(wl, wlvif); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3836 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3837 | wl1271_tx_min_rate_get(wl, |
| 3838 | wlvif->basic_rate_set); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3839 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3840 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3841 | goto out; |
Juuso Oikarinen | ebba60c | 2010-04-01 11:38:20 +0300 | [diff] [blame] | 3842 | |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3843 | /* disable connection monitor features */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3844 | ret = wl1271_acx_conn_monit_params(wl, wlvif, false); |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 3845 | |
| 3846 | /* Disable the keep-alive feature */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3847 | ret = wl1271_acx_keep_alive_mode(wl, wlvif, false); |
Juuso Oikarinen | 6ccbb92 | 2010-03-26 12:53:23 +0200 | [diff] [blame] | 3848 | if (ret < 0) |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3849 | goto out; |
Juuso Oikarinen | b84a7d3 | 2010-11-22 12:59:08 +0200 | [diff] [blame] | 3850 | |
| 3851 | /* restore the bssid filter and go to dummy bssid */ |
Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3852 | if (was_assoc) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3853 | /* |
| 3854 | * we might have to disable roc, if there was |
| 3855 | * no IF_OPER_UP notification. |
| 3856 | */ |
| 3857 | if (!was_ifup) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3858 | ret = wl12xx_croc(wl, wlvif->role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3859 | if (ret < 0) |
| 3860 | goto out; |
| 3861 | } |
| 3862 | /* |
| 3863 | * (we also need to disable roc in case of |
| 3864 | * roaming on the same channel. until we will |
| 3865 | * have a better flow...) |
| 3866 | */ |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 3867 | if (test_bit(wlvif->dev_role_id, wl->roc_map)) { |
| 3868 | ret = wl12xx_croc(wl, |
| 3869 | wlvif->dev_role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3870 | if (ret < 0) |
| 3871 | goto out; |
| 3872 | } |
| 3873 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3874 | wl1271_unjoin(wl, wlvif); |
Eliad Peller | 8a6a84a | 2012-03-04 10:55:46 +0200 | [diff] [blame] | 3875 | if (!bss_conf->idle) |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 3876 | wl12xx_start_dev(wl, wlvif); |
Eliad Peller | 30df14d | 2011-04-05 19:13:28 +0300 | [diff] [blame] | 3877 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3878 | } |
| 3879 | } |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 3880 | |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3881 | if (changed & BSS_CHANGED_IBSS) { |
| 3882 | wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d", |
| 3883 | bss_conf->ibss_joined); |
| 3884 | |
| 3885 | if (bss_conf->ibss_joined) { |
| 3886 | u32 rates = bss_conf->basic_rates; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3887 | wlvif->basic_rate_set = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 3888 | wl1271_tx_enabled_rates_get(wl, rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3889 | wlvif->band); |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 3890 | wlvif->basic_rate = |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3891 | wl1271_tx_min_rate_get(wl, |
| 3892 | wlvif->basic_rate_set); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3893 | |
Shahar Levi | 06b660e | 2011-09-05 13:54:36 +0300 | [diff] [blame] | 3894 | /* by default, use 11b + OFDM rates */ |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 3895 | wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES; |
| 3896 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
Eliad Peller | d192d26 | 2011-05-24 14:33:08 +0300 | [diff] [blame] | 3897 | if (ret < 0) |
| 3898 | goto out; |
| 3899 | } |
| 3900 | } |
| 3901 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3902 | ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3903 | if (ret < 0) |
| 3904 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 3905 | |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3906 | if (do_join) { |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 3907 | ret = wl1271_join(wl, wlvif, set_assoc); |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3908 | if (ret < 0) { |
| 3909 | wl1271_warning("cmd join failed %d", ret); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 3910 | goto out; |
Juuso Oikarinen | 8bf29b0 | 2010-02-18 13:25:51 +0200 | [diff] [blame] | 3911 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3912 | |
| 3913 | /* ROC until connected (after EAPOL exchange) */ |
| 3914 | if (!is_ibss) { |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 3915 | ret = wl12xx_roc(wl, wlvif, wlvif->role_id); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3916 | if (ret < 0) |
| 3917 | goto out; |
| 3918 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 3919 | if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags)) |
| 3920 | wl12xx_set_authorized(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3921 | } |
| 3922 | /* |
| 3923 | * stop device role if started (we might already be in |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3924 | * STA/IBSS role). |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3925 | */ |
Eliad Peller | 92e712d | 2011-12-18 20:25:43 +0200 | [diff] [blame] | 3926 | if (wl12xx_dev_role_started(wlvif)) { |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 3927 | ret = wl12xx_stop_dev(wl, wlvif); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 3928 | if (ret < 0) |
| 3929 | goto out; |
| 3930 | } |
Juuso Oikarinen | c189955 | 2010-03-26 12:53:32 +0200 | [diff] [blame] | 3931 | } |
| 3932 | |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3933 | /* Handle new association with HT. Do this after join. */ |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3934 | if (sta_exists) { |
| 3935 | if ((changed & BSS_CHANGED_HT) && |
| 3936 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3937 | ret = wl1271_acx_set_ht_capabilities(wl, |
| 3938 | &sta_ht_cap, |
| 3939 | true, |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3940 | wlvif->sta.hlid); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3941 | if (ret < 0) { |
| 3942 | wl1271_warning("Set ht cap true failed %d", |
| 3943 | ret); |
| 3944 | goto out; |
| 3945 | } |
| 3946 | } |
| 3947 | /* handle new association without HT and disassociation */ |
| 3948 | else if (changed & BSS_CHANGED_ASSOC) { |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3949 | ret = wl1271_acx_set_ht_capabilities(wl, |
| 3950 | &sta_ht_cap, |
| 3951 | false, |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 3952 | wlvif->sta.hlid); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3953 | if (ret < 0) { |
| 3954 | wl1271_warning("Set ht cap false failed %d", |
| 3955 | ret); |
| 3956 | goto out; |
| 3957 | } |
| 3958 | } |
| 3959 | } |
| 3960 | |
Arik Nemtsov | 0b932ab | 2011-08-14 13:17:27 +0300 | [diff] [blame] | 3961 | /* Handle HT information change. Done after join. */ |
| 3962 | if ((changed & BSS_CHANGED_HT) && |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3963 | (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 3964 | ret = wl1271_acx_set_ht_information(wl, wlvif, |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 3965 | bss_conf->ht_operation_mode); |
| 3966 | if (ret < 0) { |
| 3967 | wl1271_warning("Set ht information failed %d", ret); |
| 3968 | goto out; |
| 3969 | } |
| 3970 | } |
| 3971 | |
Eliad Peller | 76a74c8 | 2012-02-02 12:22:11 +0200 | [diff] [blame] | 3972 | /* Handle arp filtering. Done after join. */ |
| 3973 | if ((changed & BSS_CHANGED_ARP_FILTER) || |
| 3974 | (!is_ibss && (changed & BSS_CHANGED_QOS))) { |
| 3975 | __be32 addr = bss_conf->arp_addr_list[0]; |
| 3976 | wlvif->sta.qos = bss_conf->qos; |
| 3977 | WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS); |
| 3978 | |
| 3979 | if (bss_conf->arp_addr_cnt == 1 && |
| 3980 | bss_conf->arp_filter_enabled) { |
| 3981 | wlvif->ip_addr = addr; |
| 3982 | /* |
| 3983 | * The template should have been configured only upon |
| 3984 | * association. however, it seems that the correct ip |
| 3985 | * isn't being set (when sending), so we have to |
| 3986 | * reconfigure the template upon every ip change. |
| 3987 | */ |
| 3988 | ret = wl1271_cmd_build_arp_rsp(wl, wlvif); |
| 3989 | if (ret < 0) { |
| 3990 | wl1271_warning("build arp rsp failed: %d", ret); |
| 3991 | goto out; |
| 3992 | } |
| 3993 | |
| 3994 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, |
| 3995 | (ACX_ARP_FILTER_ARP_FILTERING | |
| 3996 | ACX_ARP_FILTER_AUTO_ARP), |
| 3997 | addr); |
| 3998 | } else { |
| 3999 | wlvif->ip_addr = 0; |
| 4000 | ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr); |
| 4001 | } |
| 4002 | |
| 4003 | if (ret < 0) |
| 4004 | goto out; |
| 4005 | } |
| 4006 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4007 | out: |
| 4008 | return; |
| 4009 | } |
| 4010 | |
| 4011 | static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw, |
| 4012 | struct ieee80211_vif *vif, |
| 4013 | struct ieee80211_bss_conf *bss_conf, |
| 4014 | u32 changed) |
| 4015 | { |
| 4016 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4017 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4018 | bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4019 | int ret; |
| 4020 | |
| 4021 | wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", |
| 4022 | (int)changed); |
| 4023 | |
Arik Nemtsov | 6b8bf5b | 2012-05-15 17:08:54 +0300 | [diff] [blame] | 4024 | /* |
| 4025 | * make sure to cancel pending disconnections if our association |
| 4026 | * state changed |
| 4027 | */ |
| 4028 | if (!is_ap && (changed & BSS_CHANGED_ASSOC)) |
| 4029 | cancel_delayed_work_sync(&wl->connection_loss_work); |
| 4030 | |
Eliad Peller | b515d83 | 2012-05-15 17:08:56 +0300 | [diff] [blame] | 4031 | if (is_ap && (changed & BSS_CHANGED_BEACON_ENABLED) && |
| 4032 | !bss_conf->enable_beacon) |
| 4033 | wl1271_tx_flush(wl); |
| 4034 | |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4035 | mutex_lock(&wl->mutex); |
| 4036 | |
| 4037 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4038 | goto out; |
| 4039 | |
Eliad Peller | 10c8cd0 | 2011-10-10 10:13:06 +0200 | [diff] [blame] | 4040 | if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))) |
| 4041 | goto out; |
| 4042 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4043 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | e78a287 | 2010-10-16 19:07:21 +0200 | [diff] [blame] | 4044 | if (ret < 0) |
| 4045 | goto out; |
| 4046 | |
| 4047 | if (is_ap) |
| 4048 | wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed); |
| 4049 | else |
| 4050 | wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed); |
| 4051 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4052 | wl1271_ps_elp_sleep(wl); |
| 4053 | |
| 4054 | out: |
| 4055 | mutex_unlock(&wl->mutex); |
| 4056 | } |
| 4057 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 4058 | static int wl1271_op_conf_tx(struct ieee80211_hw *hw, |
| 4059 | struct ieee80211_vif *vif, u16 queue, |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4060 | const struct ieee80211_tx_queue_params *params) |
| 4061 | { |
| 4062 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4063 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4064 | u8 ps_scheme; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4065 | int ret = 0; |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4066 | |
| 4067 | mutex_lock(&wl->mutex); |
| 4068 | |
| 4069 | wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue); |
| 4070 | |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 4071 | if (params->uapsd) |
| 4072 | ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER; |
| 4073 | else |
| 4074 | ps_scheme = CONF_PS_SCHEME_LEGACY; |
| 4075 | |
Eliad Peller | 5b37ddf | 2011-12-18 20:25:40 +0200 | [diff] [blame] | 4076 | if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4077 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4078 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4079 | ret = wl1271_ps_elp_wakeup(wl); |
| 4080 | if (ret < 0) |
| 4081 | goto out; |
Arik Nemtsov | 488fc54 | 2010-10-16 20:33:45 +0200 | [diff] [blame] | 4082 | |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4083 | /* |
| 4084 | * the txop is confed in units of 32us by the mac80211, |
| 4085 | * we need us |
| 4086 | */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4087 | ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4088 | params->cw_min, params->cw_max, |
| 4089 | params->aifs, params->txop << 5); |
| 4090 | if (ret < 0) |
| 4091 | goto out_sleep; |
| 4092 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 4093 | ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue), |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4094 | CONF_CHANNEL_TYPE_EDCF, |
| 4095 | wl1271_tx_get_queue(queue), |
| 4096 | ps_scheme, CONF_ACK_POLICY_LEGACY, |
| 4097 | 0, 0); |
Kalle Valo | c82c1dd | 2010-02-18 13:25:47 +0200 | [diff] [blame] | 4098 | |
| 4099 | out_sleep: |
Eliad Peller | c1b193e | 2011-03-23 22:22:15 +0200 | [diff] [blame] | 4100 | wl1271_ps_elp_sleep(wl); |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4101 | |
| 4102 | out: |
| 4103 | mutex_unlock(&wl->mutex); |
| 4104 | |
| 4105 | return ret; |
| 4106 | } |
| 4107 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 4108 | static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw, |
| 4109 | struct ieee80211_vif *vif) |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4110 | { |
| 4111 | |
| 4112 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4113 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4114 | u64 mactime = ULLONG_MAX; |
| 4115 | int ret; |
| 4116 | |
| 4117 | wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf"); |
| 4118 | |
| 4119 | mutex_lock(&wl->mutex); |
| 4120 | |
Juuso Oikarinen | f8d9802 | 2010-10-26 13:24:39 +0200 | [diff] [blame] | 4121 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4122 | goto out; |
| 4123 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4124 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4125 | if (ret < 0) |
| 4126 | goto out; |
| 4127 | |
Eliad Peller | 9c53114 | 2012-01-31 11:57:18 +0200 | [diff] [blame] | 4128 | ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime); |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4129 | if (ret < 0) |
| 4130 | goto out_sleep; |
| 4131 | |
| 4132 | out_sleep: |
| 4133 | wl1271_ps_elp_sleep(wl); |
| 4134 | |
| 4135 | out: |
| 4136 | mutex_unlock(&wl->mutex); |
| 4137 | return mactime; |
| 4138 | } |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4139 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4140 | static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx, |
| 4141 | struct survey_info *survey) |
| 4142 | { |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4143 | struct ieee80211_conf *conf = &hw->conf; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4144 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4145 | if (idx != 0) |
| 4146 | return -ENOENT; |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 4147 | |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4148 | survey->channel = conf->channel; |
Yoni Divinsky | add779a0 | 2012-06-13 18:56:54 +0300 | [diff] [blame] | 4149 | survey->filled = 0; |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4150 | return 0; |
| 4151 | } |
| 4152 | |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4153 | static int wl1271_allocate_sta(struct wl1271 *wl, |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4154 | struct wl12xx_vif *wlvif, |
| 4155 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4156 | { |
| 4157 | struct wl1271_station *wl_sta; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4158 | int ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4159 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4160 | |
| 4161 | if (wl->active_sta_count >= AP_MAX_STATIONS) { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4162 | wl1271_warning("could not allocate HLID - too much stations"); |
| 4163 | return -EBUSY; |
| 4164 | } |
| 4165 | |
| 4166 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4167 | ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid); |
| 4168 | if (ret < 0) { |
| 4169 | wl1271_warning("could not allocate HLID - too many links"); |
| 4170 | return -EBUSY; |
| 4171 | } |
| 4172 | |
| 4173 | set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4174 | memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4175 | wl->active_sta_count++; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4176 | return 0; |
| 4177 | } |
| 4178 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4179 | 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] | 4180 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4181 | if (!test_bit(hlid, wlvif->ap.sta_hlid_map)) |
Arik Nemtsov | f1acea9 | 2011-08-25 12:43:17 +0300 | [diff] [blame] | 4182 | return; |
| 4183 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4184 | clear_bit(hlid, wlvif->ap.sta_hlid_map); |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4185 | memset(wl->links[hlid].addr, 0, ETH_ALEN); |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4186 | wl->links[hlid].ba_bitmap = 0; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 4187 | __clear_bit(hlid, &wl->ap_ps_map); |
| 4188 | __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4189 | wl12xx_free_link(wl, wlvif, &hlid); |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 4190 | wl->active_sta_count--; |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 4191 | |
| 4192 | /* |
| 4193 | * rearm the tx watchdog when the last STA is freed - give the FW a |
| 4194 | * chance to return STA-buffered packets before complaining. |
| 4195 | */ |
| 4196 | if (wl->active_sta_count == 0) |
| 4197 | wl12xx_rearm_tx_watchdog_locked(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4198 | } |
| 4199 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4200 | static int wl12xx_sta_add(struct wl1271 *wl, |
| 4201 | struct wl12xx_vif *wlvif, |
| 4202 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4203 | { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4204 | struct wl1271_station *wl_sta; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4205 | int ret = 0; |
| 4206 | u8 hlid; |
| 4207 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4208 | wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); |
| 4209 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4210 | ret = wl1271_allocate_sta(wl, wlvif, sta); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4211 | if (ret < 0) |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4212 | return ret; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4213 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4214 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4215 | hlid = wl_sta->hlid; |
| 4216 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 4217 | ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4218 | if (ret < 0) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4219 | wl1271_free_sta(wl, wlvif, hlid); |
Arik Nemtsov | 409622e | 2011-02-23 00:22:29 +0200 | [diff] [blame] | 4220 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4221 | return ret; |
| 4222 | } |
| 4223 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4224 | static int wl12xx_sta_remove(struct wl1271 *wl, |
| 4225 | struct wl12xx_vif *wlvif, |
| 4226 | struct ieee80211_sta *sta) |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4227 | { |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4228 | struct wl1271_station *wl_sta; |
| 4229 | int ret = 0, id; |
| 4230 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4231 | wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); |
| 4232 | |
| 4233 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 4234 | id = wl_sta->hlid; |
| 4235 | if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map))) |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4236 | return -EINVAL; |
| 4237 | |
| 4238 | ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid); |
| 4239 | if (ret < 0) |
| 4240 | return ret; |
| 4241 | |
| 4242 | wl1271_free_sta(wl, wlvif, wl_sta->hlid); |
| 4243 | return ret; |
| 4244 | } |
| 4245 | |
| 4246 | static int wl12xx_update_sta_state(struct wl1271 *wl, |
| 4247 | struct wl12xx_vif *wlvif, |
| 4248 | struct ieee80211_sta *sta, |
| 4249 | enum ieee80211_sta_state old_state, |
| 4250 | enum ieee80211_sta_state new_state) |
| 4251 | { |
| 4252 | struct wl1271_station *wl_sta; |
| 4253 | u8 hlid; |
| 4254 | bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS; |
| 4255 | bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS; |
| 4256 | int ret; |
| 4257 | |
| 4258 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4259 | hlid = wl_sta->hlid; |
| 4260 | |
| 4261 | /* Add station (AP mode) */ |
| 4262 | if (is_ap && |
| 4263 | old_state == IEEE80211_STA_NOTEXIST && |
| 4264 | new_state == IEEE80211_STA_NONE) |
| 4265 | return wl12xx_sta_add(wl, wlvif, sta); |
| 4266 | |
| 4267 | /* Remove station (AP mode) */ |
| 4268 | if (is_ap && |
| 4269 | old_state == IEEE80211_STA_NONE && |
| 4270 | new_state == IEEE80211_STA_NOTEXIST) { |
| 4271 | /* must not fail */ |
| 4272 | wl12xx_sta_remove(wl, wlvif, sta); |
| 4273 | return 0; |
| 4274 | } |
| 4275 | |
| 4276 | /* Authorize station (AP mode) */ |
| 4277 | if (is_ap && |
| 4278 | new_state == IEEE80211_STA_AUTHORIZED) { |
| 4279 | ret = wl12xx_cmd_set_peer_state(wl, hlid); |
| 4280 | if (ret < 0) |
| 4281 | return ret; |
| 4282 | |
| 4283 | ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true, |
| 4284 | hlid); |
| 4285 | return ret; |
| 4286 | } |
| 4287 | |
Eliad Peller | 9fd6f21 | 2012-03-04 10:55:48 +0200 | [diff] [blame] | 4288 | /* Authorize station */ |
| 4289 | if (is_sta && |
| 4290 | new_state == IEEE80211_STA_AUTHORIZED) { |
| 4291 | set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); |
| 4292 | return wl12xx_set_authorized(wl, wlvif); |
| 4293 | } |
| 4294 | |
| 4295 | if (is_sta && |
| 4296 | old_state == IEEE80211_STA_AUTHORIZED && |
| 4297 | new_state == IEEE80211_STA_ASSOC) { |
| 4298 | clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags); |
| 4299 | return 0; |
| 4300 | } |
| 4301 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4302 | return 0; |
| 4303 | } |
| 4304 | |
| 4305 | static int wl12xx_op_sta_state(struct ieee80211_hw *hw, |
| 4306 | struct ieee80211_vif *vif, |
| 4307 | struct ieee80211_sta *sta, |
| 4308 | enum ieee80211_sta_state old_state, |
| 4309 | enum ieee80211_sta_state new_state) |
| 4310 | { |
| 4311 | struct wl1271 *wl = hw->priv; |
| 4312 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
| 4313 | int ret; |
| 4314 | |
| 4315 | wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d", |
| 4316 | sta->aid, old_state, new_state); |
| 4317 | |
| 4318 | mutex_lock(&wl->mutex); |
| 4319 | |
| 4320 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 4321 | ret = -EBUSY; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4322 | goto out; |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4323 | } |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4324 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4325 | ret = wl1271_ps_elp_wakeup(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4326 | if (ret < 0) |
| 4327 | goto out; |
| 4328 | |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4329 | ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4330 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4331 | wl1271_ps_elp_sleep(wl); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4332 | out: |
| 4333 | mutex_unlock(&wl->mutex); |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4334 | if (new_state < old_state) |
| 4335 | return 0; |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 4336 | return ret; |
| 4337 | } |
| 4338 | |
Luciano Coelho | 4623ec7 | 2011-03-21 19:26:41 +0200 | [diff] [blame] | 4339 | static int wl1271_op_ampdu_action(struct ieee80211_hw *hw, |
| 4340 | struct ieee80211_vif *vif, |
| 4341 | enum ieee80211_ampdu_mlme_action action, |
| 4342 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 4343 | u8 buf_size) |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4344 | { |
| 4345 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4346 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4347 | int ret; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4348 | u8 hlid, *ba_bitmap; |
| 4349 | |
| 4350 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action, |
| 4351 | tid); |
| 4352 | |
| 4353 | /* sanity check - the fields in FW are only 8bits wide */ |
| 4354 | if (WARN_ON(tid > 0xFF)) |
| 4355 | return -ENOTSUPP; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4356 | |
| 4357 | mutex_lock(&wl->mutex); |
| 4358 | |
| 4359 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
| 4360 | ret = -EAGAIN; |
| 4361 | goto out; |
| 4362 | } |
| 4363 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4364 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) { |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 4365 | hlid = wlvif->sta.hlid; |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4366 | ba_bitmap = &wlvif->sta.ba_rx_bitmap; |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 4367 | } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) { |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4368 | struct wl1271_station *wl_sta; |
| 4369 | |
| 4370 | wl_sta = (struct wl1271_station *)sta->drv_priv; |
| 4371 | hlid = wl_sta->hlid; |
| 4372 | ba_bitmap = &wl->links[hlid].ba_bitmap; |
| 4373 | } else { |
| 4374 | ret = -EINVAL; |
| 4375 | goto out; |
| 4376 | } |
| 4377 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4378 | ret = wl1271_ps_elp_wakeup(wl); |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4379 | if (ret < 0) |
| 4380 | goto out; |
| 4381 | |
Shahar Levi | 70559a0 | 2011-05-22 16:10:22 +0300 | [diff] [blame] | 4382 | wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d", |
| 4383 | tid, action); |
| 4384 | |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4385 | switch (action) { |
| 4386 | case IEEE80211_AMPDU_RX_START: |
Eliad Peller | d0802ab | 2011-10-05 11:56:04 +0200 | [diff] [blame] | 4387 | if (!wlvif->ba_support || !wlvif->ba_allowed) { |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4388 | ret = -ENOTSUPP; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4389 | break; |
| 4390 | } |
| 4391 | |
| 4392 | if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) { |
| 4393 | ret = -EBUSY; |
| 4394 | wl1271_error("exceeded max RX BA sessions"); |
| 4395 | break; |
| 4396 | } |
| 4397 | |
| 4398 | if (*ba_bitmap & BIT(tid)) { |
| 4399 | ret = -EINVAL; |
| 4400 | wl1271_error("cannot enable RX BA session on active " |
| 4401 | "tid: %d", tid); |
| 4402 | break; |
| 4403 | } |
| 4404 | |
| 4405 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true, |
| 4406 | hlid); |
| 4407 | if (!ret) { |
| 4408 | *ba_bitmap |= BIT(tid); |
| 4409 | wl->ba_rx_session_count++; |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4410 | } |
| 4411 | break; |
| 4412 | |
| 4413 | case IEEE80211_AMPDU_RX_STOP: |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4414 | if (!(*ba_bitmap & BIT(tid))) { |
Arik Nemtsov | c954910 | 2012-06-06 10:48:56 +0300 | [diff] [blame] | 4415 | /* |
| 4416 | * this happens on reconfig - so only output a debug |
| 4417 | * message for now, and don't fail the function. |
| 4418 | */ |
| 4419 | wl1271_debug(DEBUG_MAC80211, |
| 4420 | "no active RX BA session on tid: %d", |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4421 | tid); |
Arik Nemtsov | c954910 | 2012-06-06 10:48:56 +0300 | [diff] [blame] | 4422 | ret = 0; |
Arik Nemtsov | 0f9c825 | 2011-08-17 10:45:49 +0300 | [diff] [blame] | 4423 | break; |
| 4424 | } |
| 4425 | |
| 4426 | ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false, |
| 4427 | hlid); |
| 4428 | if (!ret) { |
| 4429 | *ba_bitmap &= ~BIT(tid); |
| 4430 | wl->ba_rx_session_count--; |
| 4431 | } |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4432 | break; |
| 4433 | |
| 4434 | /* |
| 4435 | * The BA initiator session management in FW independently. |
| 4436 | * Falling break here on purpose for all TX APDU commands. |
| 4437 | */ |
| 4438 | case IEEE80211_AMPDU_TX_START: |
| 4439 | case IEEE80211_AMPDU_TX_STOP: |
| 4440 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 4441 | ret = -EINVAL; |
| 4442 | break; |
| 4443 | |
| 4444 | default: |
| 4445 | wl1271_error("Incorrect ampdu action id=%x\n", action); |
| 4446 | ret = -EINVAL; |
| 4447 | } |
| 4448 | |
| 4449 | wl1271_ps_elp_sleep(wl); |
| 4450 | |
| 4451 | out: |
| 4452 | mutex_unlock(&wl->mutex); |
| 4453 | |
| 4454 | return ret; |
| 4455 | } |
| 4456 | |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4457 | static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw, |
| 4458 | struct ieee80211_vif *vif, |
| 4459 | const struct cfg80211_bitrate_mask *mask) |
| 4460 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4461 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4462 | struct wl1271 *wl = hw->priv; |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4463 | int i, ret = 0; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4464 | |
| 4465 | wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", |
| 4466 | mask->control[NL80211_BAND_2GHZ].legacy, |
| 4467 | mask->control[NL80211_BAND_5GHZ].legacy); |
| 4468 | |
| 4469 | mutex_lock(&wl->mutex); |
| 4470 | |
| 4471 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 4472 | wlvif->bitrate_masks[i] = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4473 | wl1271_tx_enabled_rates_get(wl, |
| 4474 | mask->control[i].legacy, |
| 4475 | i); |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4476 | |
| 4477 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4478 | goto out; |
| 4479 | |
| 4480 | if (wlvif->bss_type == BSS_TYPE_STA_BSS && |
| 4481 | !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) { |
| 4482 | |
| 4483 | ret = wl1271_ps_elp_wakeup(wl); |
| 4484 | if (ret < 0) |
| 4485 | goto out; |
| 4486 | |
| 4487 | wl1271_set_band_rate(wl, wlvif); |
| 4488 | wlvif->basic_rate = |
| 4489 | wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); |
| 4490 | ret = wl1271_acx_sta_rate_policies(wl, wlvif); |
| 4491 | |
| 4492 | wl1271_ps_elp_sleep(wl); |
| 4493 | } |
| 4494 | out: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4495 | mutex_unlock(&wl->mutex); |
| 4496 | |
Eliad Peller | d6fa37c | 2011-10-11 11:57:39 +0200 | [diff] [blame] | 4497 | return ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4498 | } |
| 4499 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4500 | static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, |
| 4501 | struct ieee80211_channel_switch *ch_switch) |
| 4502 | { |
| 4503 | struct wl1271 *wl = hw->priv; |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4504 | struct wl12xx_vif *wlvif; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4505 | int ret; |
| 4506 | |
| 4507 | wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); |
| 4508 | |
Arik Nemtsov | b9239b6 | 2012-02-28 00:41:33 +0200 | [diff] [blame] | 4509 | wl1271_tx_flush(wl); |
| 4510 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4511 | mutex_lock(&wl->mutex); |
| 4512 | |
| 4513 | if (unlikely(wl->state == WL1271_STATE_OFF)) { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 4514 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 4515 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 4516 | ieee80211_chswitch_done(vif, false); |
| 4517 | } |
| 4518 | goto out; |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | ret = wl1271_ps_elp_wakeup(wl); |
| 4522 | if (ret < 0) |
| 4523 | goto out; |
| 4524 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4525 | /* TODO: change mac80211 to pass vif as param */ |
| 4526 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 4527 | ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch); |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4528 | |
Eliad Peller | 52630c5 | 2011-10-10 10:13:08 +0200 | [diff] [blame] | 4529 | if (!ret) |
| 4530 | set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags); |
| 4531 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4532 | |
| 4533 | wl1271_ps_elp_sleep(wl); |
| 4534 | |
| 4535 | out: |
| 4536 | mutex_unlock(&wl->mutex); |
| 4537 | } |
| 4538 | |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4539 | static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw) |
| 4540 | { |
| 4541 | struct wl1271 *wl = hw->priv; |
| 4542 | bool ret = false; |
| 4543 | |
| 4544 | mutex_lock(&wl->mutex); |
| 4545 | |
| 4546 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4547 | goto out; |
| 4548 | |
| 4549 | /* packets are considered pending if in the TX queue or the FW */ |
Arik Nemtsov | f1a4638 | 2011-07-07 14:25:23 +0300 | [diff] [blame] | 4550 | 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] | 4551 | out: |
| 4552 | mutex_unlock(&wl->mutex); |
| 4553 | |
| 4554 | return ret; |
| 4555 | } |
| 4556 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4557 | /* can't be const, mac80211 writes to this */ |
| 4558 | static struct ieee80211_rate wl1271_rates[] = { |
| 4559 | { .bitrate = 10, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4560 | .hw_value = CONF_HW_BIT_RATE_1MBPS, |
| 4561 | .hw_value_short = CONF_HW_BIT_RATE_1MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4562 | { .bitrate = 20, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4563 | .hw_value = CONF_HW_BIT_RATE_2MBPS, |
| 4564 | .hw_value_short = CONF_HW_BIT_RATE_2MBPS, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4565 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 4566 | { .bitrate = 55, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4567 | .hw_value = CONF_HW_BIT_RATE_5_5MBPS, |
| 4568 | .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4569 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 4570 | { .bitrate = 110, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4571 | .hw_value = CONF_HW_BIT_RATE_11MBPS, |
| 4572 | .hw_value_short = CONF_HW_BIT_RATE_11MBPS, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4573 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 4574 | { .bitrate = 60, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4575 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 4576 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4577 | { .bitrate = 90, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4578 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 4579 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4580 | { .bitrate = 120, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4581 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 4582 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4583 | { .bitrate = 180, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4584 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 4585 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4586 | { .bitrate = 240, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4587 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 4588 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4589 | { .bitrate = 360, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4590 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 4591 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4592 | { .bitrate = 480, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4593 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 4594 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4595 | { .bitrate = 540, |
Juuso Oikarinen | 2b60100b | 2009-10-13 12:47:39 +0300 | [diff] [blame] | 4596 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 4597 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4598 | }; |
| 4599 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4600 | /* can't be const, mac80211 writes to this */ |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4601 | static struct ieee80211_channel wl1271_channels[] = { |
Luciano Coelho | a2d0e3f | 2009-12-11 15:40:46 +0200 | [diff] [blame] | 4602 | { .hw_value = 1, .center_freq = 2412, .max_power = 25 }, |
Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4603 | { .hw_value = 2, .center_freq = 2417, .max_power = 25 }, |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4604 | { .hw_value = 3, .center_freq = 2422, .max_power = 25 }, |
| 4605 | { .hw_value = 4, .center_freq = 2427, .max_power = 25 }, |
| 4606 | { .hw_value = 5, .center_freq = 2432, .max_power = 25 }, |
Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4607 | { .hw_value = 6, .center_freq = 2437, .max_power = 25 }, |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4608 | { .hw_value = 7, .center_freq = 2442, .max_power = 25 }, |
| 4609 | { .hw_value = 8, .center_freq = 2447, .max_power = 25 }, |
| 4610 | { .hw_value = 9, .center_freq = 2452, .max_power = 25 }, |
Juuso Oikarinen | fa21c7a | 2010-08-10 08:22:02 +0200 | [diff] [blame] | 4611 | { .hw_value = 10, .center_freq = 2457, .max_power = 25 }, |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4612 | { .hw_value = 11, .center_freq = 2462, .max_power = 25 }, |
| 4613 | { .hw_value = 12, .center_freq = 2467, .max_power = 25 }, |
| 4614 | { .hw_value = 13, .center_freq = 2472, .max_power = 25 }, |
Arik Nemtsov | 6c89b7b | 2011-01-18 20:39:52 +0100 | [diff] [blame] | 4615 | { .hw_value = 14, .center_freq = 2484, .max_power = 25 }, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4616 | }; |
| 4617 | |
| 4618 | /* can't be const, mac80211 writes to this */ |
| 4619 | static struct ieee80211_supported_band wl1271_band_2ghz = { |
| 4620 | .channels = wl1271_channels, |
| 4621 | .n_channels = ARRAY_SIZE(wl1271_channels), |
| 4622 | .bitrates = wl1271_rates, |
| 4623 | .n_bitrates = ARRAY_SIZE(wl1271_rates), |
| 4624 | }; |
| 4625 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4626 | /* 5 GHz data rates for WL1273 */ |
| 4627 | static struct ieee80211_rate wl1271_rates_5ghz[] = { |
| 4628 | { .bitrate = 60, |
| 4629 | .hw_value = CONF_HW_BIT_RATE_6MBPS, |
| 4630 | .hw_value_short = CONF_HW_BIT_RATE_6MBPS, }, |
| 4631 | { .bitrate = 90, |
| 4632 | .hw_value = CONF_HW_BIT_RATE_9MBPS, |
| 4633 | .hw_value_short = CONF_HW_BIT_RATE_9MBPS, }, |
| 4634 | { .bitrate = 120, |
| 4635 | .hw_value = CONF_HW_BIT_RATE_12MBPS, |
| 4636 | .hw_value_short = CONF_HW_BIT_RATE_12MBPS, }, |
| 4637 | { .bitrate = 180, |
| 4638 | .hw_value = CONF_HW_BIT_RATE_18MBPS, |
| 4639 | .hw_value_short = CONF_HW_BIT_RATE_18MBPS, }, |
| 4640 | { .bitrate = 240, |
| 4641 | .hw_value = CONF_HW_BIT_RATE_24MBPS, |
| 4642 | .hw_value_short = CONF_HW_BIT_RATE_24MBPS, }, |
| 4643 | { .bitrate = 360, |
| 4644 | .hw_value = CONF_HW_BIT_RATE_36MBPS, |
| 4645 | .hw_value_short = CONF_HW_BIT_RATE_36MBPS, }, |
| 4646 | { .bitrate = 480, |
| 4647 | .hw_value = CONF_HW_BIT_RATE_48MBPS, |
| 4648 | .hw_value_short = CONF_HW_BIT_RATE_48MBPS, }, |
| 4649 | { .bitrate = 540, |
| 4650 | .hw_value = CONF_HW_BIT_RATE_54MBPS, |
| 4651 | .hw_value_short = CONF_HW_BIT_RATE_54MBPS, }, |
| 4652 | }; |
| 4653 | |
Juuso Oikarinen | fa97f46 | 2010-11-10 11:27:20 +0100 | [diff] [blame] | 4654 | /* 5 GHz band channels for WL1273 */ |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4655 | static struct ieee80211_channel wl1271_channels_5ghz[] = { |
Arik Nemtsov | 6cfa5cf | 2011-06-27 22:06:33 +0300 | [diff] [blame] | 4656 | { .hw_value = 7, .center_freq = 5035, .max_power = 25 }, |
| 4657 | { .hw_value = 8, .center_freq = 5040, .max_power = 25 }, |
| 4658 | { .hw_value = 9, .center_freq = 5045, .max_power = 25 }, |
| 4659 | { .hw_value = 11, .center_freq = 5055, .max_power = 25 }, |
| 4660 | { .hw_value = 12, .center_freq = 5060, .max_power = 25 }, |
| 4661 | { .hw_value = 16, .center_freq = 5080, .max_power = 25 }, |
| 4662 | { .hw_value = 34, .center_freq = 5170, .max_power = 25 }, |
| 4663 | { .hw_value = 36, .center_freq = 5180, .max_power = 25 }, |
| 4664 | { .hw_value = 38, .center_freq = 5190, .max_power = 25 }, |
| 4665 | { .hw_value = 40, .center_freq = 5200, .max_power = 25 }, |
| 4666 | { .hw_value = 42, .center_freq = 5210, .max_power = 25 }, |
| 4667 | { .hw_value = 44, .center_freq = 5220, .max_power = 25 }, |
| 4668 | { .hw_value = 46, .center_freq = 5230, .max_power = 25 }, |
| 4669 | { .hw_value = 48, .center_freq = 5240, .max_power = 25 }, |
| 4670 | { .hw_value = 52, .center_freq = 5260, .max_power = 25 }, |
| 4671 | { .hw_value = 56, .center_freq = 5280, .max_power = 25 }, |
| 4672 | { .hw_value = 60, .center_freq = 5300, .max_power = 25 }, |
| 4673 | { .hw_value = 64, .center_freq = 5320, .max_power = 25 }, |
| 4674 | { .hw_value = 100, .center_freq = 5500, .max_power = 25 }, |
| 4675 | { .hw_value = 104, .center_freq = 5520, .max_power = 25 }, |
| 4676 | { .hw_value = 108, .center_freq = 5540, .max_power = 25 }, |
| 4677 | { .hw_value = 112, .center_freq = 5560, .max_power = 25 }, |
| 4678 | { .hw_value = 116, .center_freq = 5580, .max_power = 25 }, |
| 4679 | { .hw_value = 120, .center_freq = 5600, .max_power = 25 }, |
| 4680 | { .hw_value = 124, .center_freq = 5620, .max_power = 25 }, |
| 4681 | { .hw_value = 128, .center_freq = 5640, .max_power = 25 }, |
| 4682 | { .hw_value = 132, .center_freq = 5660, .max_power = 25 }, |
| 4683 | { .hw_value = 136, .center_freq = 5680, .max_power = 25 }, |
| 4684 | { .hw_value = 140, .center_freq = 5700, .max_power = 25 }, |
| 4685 | { .hw_value = 149, .center_freq = 5745, .max_power = 25 }, |
| 4686 | { .hw_value = 153, .center_freq = 5765, .max_power = 25 }, |
| 4687 | { .hw_value = 157, .center_freq = 5785, .max_power = 25 }, |
| 4688 | { .hw_value = 161, .center_freq = 5805, .max_power = 25 }, |
| 4689 | { .hw_value = 165, .center_freq = 5825, .max_power = 25 }, |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4690 | }; |
| 4691 | |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 4692 | static struct ieee80211_supported_band wl1271_band_5ghz = { |
| 4693 | .channels = wl1271_channels_5ghz, |
| 4694 | .n_channels = ARRAY_SIZE(wl1271_channels_5ghz), |
| 4695 | .bitrates = wl1271_rates_5ghz, |
| 4696 | .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz), |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4697 | }; |
| 4698 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4699 | static const struct ieee80211_ops wl1271_ops = { |
| 4700 | .start = wl1271_op_start, |
| 4701 | .stop = wl1271_op_stop, |
| 4702 | .add_interface = wl1271_op_add_interface, |
| 4703 | .remove_interface = wl1271_op_remove_interface, |
Eliad Peller | c0fad1b | 2011-12-19 12:00:03 +0200 | [diff] [blame] | 4704 | .change_interface = wl12xx_op_change_interface, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 4705 | #ifdef CONFIG_PM |
Eliad Peller | 402e4861 | 2011-05-13 11:57:09 +0300 | [diff] [blame] | 4706 | .suspend = wl1271_op_suspend, |
| 4707 | .resume = wl1271_op_resume, |
Luciano Coelho | f634a4e | 2011-05-18 16:51:26 -0400 | [diff] [blame] | 4708 | #endif |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4709 | .config = wl1271_op_config, |
Juuso Oikarinen | c87dec9 | 2009-10-08 21:56:31 +0300 | [diff] [blame] | 4710 | .prepare_multicast = wl1271_op_prepare_multicast, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4711 | .configure_filter = wl1271_op_configure_filter, |
| 4712 | .tx = wl1271_op_tx, |
Arik Nemtsov | a1c597f | 2012-05-18 07:46:40 +0300 | [diff] [blame] | 4713 | .set_key = wlcore_op_set_key, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4714 | .hw_scan = wl1271_op_hw_scan, |
Eliad Peller | 73ecce3 | 2011-06-27 13:06:45 +0300 | [diff] [blame] | 4715 | .cancel_hw_scan = wl1271_op_cancel_hw_scan, |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 4716 | .sched_scan_start = wl1271_op_sched_scan_start, |
| 4717 | .sched_scan_stop = wl1271_op_sched_scan_stop, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4718 | .bss_info_changed = wl1271_op_bss_info_changed, |
Arik Nemtsov | 68d069c | 2010-11-08 10:51:07 +0100 | [diff] [blame] | 4719 | .set_frag_threshold = wl1271_op_set_frag_threshold, |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4720 | .set_rts_threshold = wl1271_op_set_rts_threshold, |
Kalle Valo | c6999d8 | 2010-02-18 13:25:41 +0200 | [diff] [blame] | 4721 | .conf_tx = wl1271_op_conf_tx, |
Juuso Oikarinen | bbbb538 | 2010-07-08 17:49:57 +0300 | [diff] [blame] | 4722 | .get_tsf = wl1271_op_get_tsf, |
John W. Linville | ece550d | 2010-07-28 16:41:06 -0400 | [diff] [blame] | 4723 | .get_survey = wl1271_op_get_survey, |
Eliad Peller | 2d6cf2b | 2012-03-04 10:55:47 +0200 | [diff] [blame] | 4724 | .sta_state = wl12xx_op_sta_state, |
Levi, Shahar | bbba3e6 | 2011-01-23 07:27:23 +0100 | [diff] [blame] | 4725 | .ampdu_action = wl1271_op_ampdu_action, |
Arik Nemtsov | 3343789 | 2011-04-26 23:35:39 +0300 | [diff] [blame] | 4726 | .tx_frames_pending = wl1271_tx_frames_pending, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 4727 | .set_bitrate_mask = wl12xx_set_bitrate_mask, |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 4728 | .channel_switch = wl12xx_op_channel_switch, |
Kalle Valo | c8c9087 | 2010-02-18 13:25:53 +0200 | [diff] [blame] | 4729 | CFG80211_TESTMODE_CMD(wl1271_tm_cmd) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4730 | }; |
| 4731 | |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4732 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 4733 | 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] | 4734 | { |
| 4735 | u8 idx; |
| 4736 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 4737 | BUG_ON(band >= 2); |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4738 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 4739 | if (unlikely(rate >= wl->hw_tx_rate_tbl_size)) { |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4740 | wl1271_error("Illegal RX rate from HW: %d", rate); |
| 4741 | return 0; |
| 4742 | } |
| 4743 | |
Arik Nemtsov | 43a8bc5 | 2011-12-08 00:43:48 +0200 | [diff] [blame] | 4744 | idx = wl->band_rate_to_idx[band][rate]; |
Juuso Oikarinen | f876bb9 | 2010-03-26 12:53:11 +0200 | [diff] [blame] | 4745 | if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) { |
| 4746 | wl1271_error("Unsupported RX rate from HW: %d", rate); |
| 4747 | return 0; |
| 4748 | } |
| 4749 | |
| 4750 | return idx; |
| 4751 | } |
| 4752 | |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4753 | static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev, |
| 4754 | struct device_attribute *attr, |
| 4755 | char *buf) |
| 4756 | { |
| 4757 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4758 | ssize_t len; |
| 4759 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 4760 | len = PAGE_SIZE; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4761 | |
| 4762 | mutex_lock(&wl->mutex); |
| 4763 | len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n", |
| 4764 | wl->sg_enabled); |
| 4765 | mutex_unlock(&wl->mutex); |
| 4766 | |
| 4767 | return len; |
| 4768 | |
| 4769 | } |
| 4770 | |
| 4771 | static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev, |
| 4772 | struct device_attribute *attr, |
| 4773 | const char *buf, size_t count) |
| 4774 | { |
| 4775 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4776 | unsigned long res; |
| 4777 | int ret; |
| 4778 | |
Luciano Coelho | 6277ed6 | 2011-04-01 17:49:54 +0300 | [diff] [blame] | 4779 | ret = kstrtoul(buf, 10, &res); |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4780 | if (ret < 0) { |
| 4781 | wl1271_warning("incorrect value written to bt_coex_mode"); |
| 4782 | return count; |
| 4783 | } |
| 4784 | |
| 4785 | mutex_lock(&wl->mutex); |
| 4786 | |
| 4787 | res = !!res; |
| 4788 | |
| 4789 | if (res == wl->sg_enabled) |
| 4790 | goto out; |
| 4791 | |
| 4792 | wl->sg_enabled = res; |
| 4793 | |
| 4794 | if (wl->state == WL1271_STATE_OFF) |
| 4795 | goto out; |
| 4796 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 4797 | ret = wl1271_ps_elp_wakeup(wl); |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 4798 | if (ret < 0) |
| 4799 | goto out; |
| 4800 | |
| 4801 | wl1271_acx_sg_enable(wl, wl->sg_enabled); |
| 4802 | wl1271_ps_elp_sleep(wl); |
| 4803 | |
| 4804 | out: |
| 4805 | mutex_unlock(&wl->mutex); |
| 4806 | return count; |
| 4807 | } |
| 4808 | |
| 4809 | static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR, |
| 4810 | wl1271_sysfs_show_bt_coex_state, |
| 4811 | wl1271_sysfs_store_bt_coex_state); |
| 4812 | |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4813 | static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev, |
| 4814 | struct device_attribute *attr, |
| 4815 | char *buf) |
| 4816 | { |
| 4817 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4818 | ssize_t len; |
| 4819 | |
Juuso Oikarinen | 2f63b01 | 2010-08-10 06:38:35 +0200 | [diff] [blame] | 4820 | len = PAGE_SIZE; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4821 | |
| 4822 | mutex_lock(&wl->mutex); |
| 4823 | if (wl->hw_pg_ver >= 0) |
| 4824 | len = snprintf(buf, len, "%d\n", wl->hw_pg_ver); |
| 4825 | else |
| 4826 | len = snprintf(buf, len, "n/a\n"); |
| 4827 | mutex_unlock(&wl->mutex); |
| 4828 | |
| 4829 | return len; |
| 4830 | } |
| 4831 | |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 4832 | static DEVICE_ATTR(hw_pg_ver, S_IRUGO, |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 4833 | wl1271_sysfs_show_hw_pg_ver, NULL); |
| 4834 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 4835 | static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj, |
| 4836 | struct bin_attribute *bin_attr, |
| 4837 | char *buffer, loff_t pos, size_t count) |
| 4838 | { |
| 4839 | struct device *dev = container_of(kobj, struct device, kobj); |
| 4840 | struct wl1271 *wl = dev_get_drvdata(dev); |
| 4841 | ssize_t len; |
| 4842 | int ret; |
| 4843 | |
| 4844 | ret = mutex_lock_interruptible(&wl->mutex); |
| 4845 | if (ret < 0) |
| 4846 | return -ERESTARTSYS; |
| 4847 | |
| 4848 | /* Let only one thread read the log at a time, blocking others */ |
| 4849 | while (wl->fwlog_size == 0) { |
| 4850 | DEFINE_WAIT(wait); |
| 4851 | |
| 4852 | prepare_to_wait_exclusive(&wl->fwlog_waitq, |
| 4853 | &wait, |
| 4854 | TASK_INTERRUPTIBLE); |
| 4855 | |
| 4856 | if (wl->fwlog_size != 0) { |
| 4857 | finish_wait(&wl->fwlog_waitq, &wait); |
| 4858 | break; |
| 4859 | } |
| 4860 | |
| 4861 | mutex_unlock(&wl->mutex); |
| 4862 | |
| 4863 | schedule(); |
| 4864 | finish_wait(&wl->fwlog_waitq, &wait); |
| 4865 | |
| 4866 | if (signal_pending(current)) |
| 4867 | return -ERESTARTSYS; |
| 4868 | |
| 4869 | ret = mutex_lock_interruptible(&wl->mutex); |
| 4870 | if (ret < 0) |
| 4871 | return -ERESTARTSYS; |
| 4872 | } |
| 4873 | |
| 4874 | /* Check if the fwlog is still valid */ |
| 4875 | if (wl->fwlog_size < 0) { |
| 4876 | mutex_unlock(&wl->mutex); |
| 4877 | return 0; |
| 4878 | } |
| 4879 | |
| 4880 | /* Seeking is not supported - old logs are not kept. Disregard pos. */ |
| 4881 | len = min(count, (size_t)wl->fwlog_size); |
| 4882 | wl->fwlog_size -= len; |
| 4883 | memcpy(buffer, wl->fwlog, len); |
| 4884 | |
| 4885 | /* Make room for new messages */ |
| 4886 | memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size); |
| 4887 | |
| 4888 | mutex_unlock(&wl->mutex); |
| 4889 | |
| 4890 | return len; |
| 4891 | } |
| 4892 | |
| 4893 | static struct bin_attribute fwlog_attr = { |
| 4894 | .attr = {.name = "fwlog", .mode = S_IRUSR}, |
| 4895 | .read = wl1271_sysfs_read_fwlog, |
| 4896 | }; |
| 4897 | |
Luciano Coelho | 2247997 | 2012-05-16 06:00:00 +0300 | [diff] [blame] | 4898 | static void wl1271_connection_loss_work(struct work_struct *work) |
Bartosz.Markowski@tieto.com | 5f561f6 | 2012-04-26 10:35:07 +0300 | [diff] [blame] | 4899 | { |
| 4900 | struct delayed_work *dwork; |
| 4901 | struct wl1271 *wl; |
| 4902 | struct ieee80211_vif *vif; |
| 4903 | struct wl12xx_vif *wlvif; |
| 4904 | |
| 4905 | dwork = container_of(work, struct delayed_work, work); |
| 4906 | wl = container_of(dwork, struct wl1271, connection_loss_work); |
| 4907 | |
| 4908 | wl1271_info("Connection loss work."); |
| 4909 | |
| 4910 | mutex_lock(&wl->mutex); |
| 4911 | |
| 4912 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 4913 | goto out; |
| 4914 | |
| 4915 | /* Call mac80211 connection loss */ |
| 4916 | wl12xx_for_each_wlvif_sta(wl, wlvif) { |
| 4917 | if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) |
| 4918 | goto out; |
| 4919 | vif = wl12xx_wlvif_to_vif(wlvif); |
| 4920 | ieee80211_connection_loss(vif); |
| 4921 | } |
| 4922 | out: |
| 4923 | mutex_unlock(&wl->mutex); |
| 4924 | } |
| 4925 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 4926 | static void wl12xx_derive_mac_addresses(struct wl1271 *wl, |
| 4927 | u32 oui, u32 nic, int n) |
| 4928 | { |
| 4929 | int i; |
| 4930 | |
| 4931 | wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d", |
| 4932 | oui, nic, n); |
| 4933 | |
| 4934 | if (nic + n - 1 > 0xffffff) |
| 4935 | wl1271_warning("NIC part of the MAC address wraps around!"); |
| 4936 | |
| 4937 | for (i = 0; i < n; i++) { |
| 4938 | wl->addresses[i].addr[0] = (u8)(oui >> 16); |
| 4939 | wl->addresses[i].addr[1] = (u8)(oui >> 8); |
| 4940 | wl->addresses[i].addr[2] = (u8) oui; |
| 4941 | wl->addresses[i].addr[3] = (u8)(nic >> 16); |
| 4942 | wl->addresses[i].addr[4] = (u8)(nic >> 8); |
| 4943 | wl->addresses[i].addr[5] = (u8) nic; |
| 4944 | nic++; |
| 4945 | } |
| 4946 | |
| 4947 | wl->hw->wiphy->n_addresses = n; |
| 4948 | wl->hw->wiphy->addresses = wl->addresses; |
| 4949 | } |
| 4950 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 4951 | static int wl12xx_get_hw_info(struct wl1271 *wl) |
| 4952 | { |
| 4953 | int ret; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 4954 | |
| 4955 | ret = wl12xx_set_power_on(wl); |
| 4956 | if (ret < 0) |
| 4957 | goto out; |
| 4958 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 4959 | wl->chip.id = wlcore_read_reg(wl, REG_CHIP_ID_B); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 4960 | |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 4961 | wl->fuse_oui_addr = 0; |
| 4962 | wl->fuse_nic_addr = 0; |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 4963 | |
Luciano Coelho | 4ded91c | 2012-04-11 10:54:52 +0300 | [diff] [blame] | 4964 | wl->hw_pg_ver = wl->ops->get_pg_ver(wl); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 4965 | |
Luciano Coelho | 30d9b4a | 2012-04-11 11:07:28 +0300 | [diff] [blame] | 4966 | if (wl->ops->get_mac) |
| 4967 | wl->ops->get_mac(wl); |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 4968 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 4969 | wl1271_power_off(wl); |
| 4970 | out: |
| 4971 | return ret; |
| 4972 | } |
| 4973 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 4974 | static int wl1271_register_hw(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4975 | { |
| 4976 | int ret; |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 4977 | u32 oui_addr = 0, nic_addr = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 4978 | |
| 4979 | if (wl->mac80211_registered) |
| 4980 | return 0; |
| 4981 | |
Arik Nemtsov | 3e3947f | 2012-05-29 18:38:05 +0300 | [diff] [blame] | 4982 | wl1271_fetch_nvs(wl); |
| 4983 | if (wl->nvs != NULL) { |
Shahar Levi | bc765bf | 2011-03-06 16:32:10 +0200 | [diff] [blame] | 4984 | /* NOTE: The wl->nvs->nvs element must be first, in |
| 4985 | * order to simplify the casting, we assume it is at |
| 4986 | * the beginning of the wl->nvs structure. |
| 4987 | */ |
| 4988 | u8 *nvs_ptr = (u8 *)wl->nvs; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 4989 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 4990 | oui_addr = |
| 4991 | (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6]; |
| 4992 | nic_addr = |
| 4993 | (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3]; |
Arik Nemtsov | 31d26ec | 2010-10-16 21:49:52 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
Luciano Coelho | 5e037e7 | 2011-12-23 09:32:17 +0200 | [diff] [blame] | 4996 | /* if the MAC address is zeroed in the NVS derive from fuse */ |
| 4997 | if (oui_addr == 0 && nic_addr == 0) { |
| 4998 | oui_addr = wl->fuse_oui_addr; |
| 4999 | /* fuse has the BD_ADDR, the WLAN addresses are the next two */ |
| 5000 | nic_addr = wl->fuse_nic_addr + 1; |
| 5001 | } |
| 5002 | |
| 5003 | wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5004 | |
| 5005 | ret = ieee80211_register_hw(wl->hw); |
| 5006 | if (ret < 0) { |
| 5007 | wl1271_error("unable to register mac80211 hw: %d", ret); |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5008 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | wl->mac80211_registered = true; |
| 5012 | |
Eliad Peller | d60080a | 2010-11-24 12:53:16 +0200 | [diff] [blame] | 5013 | wl1271_debugfs_init(wl); |
| 5014 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5015 | wl1271_notice("loaded"); |
| 5016 | |
Luciano Coelho | 30c5dbd | 2012-01-18 14:53:22 +0200 | [diff] [blame] | 5017 | out: |
| 5018 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5019 | } |
| 5020 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5021 | static void wl1271_unregister_hw(struct wl1271 *wl) |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5022 | { |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5023 | if (wl->plt) |
Ido Yariv | f3df133 | 2012-01-11 09:42:39 +0200 | [diff] [blame] | 5024 | wl1271_plt_stop(wl); |
Juuso Oikarinen | 4ae3fa8 | 2011-01-14 12:48:46 +0100 | [diff] [blame] | 5025 | |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5026 | ieee80211_unregister_hw(wl->hw); |
| 5027 | wl->mac80211_registered = false; |
| 5028 | |
| 5029 | } |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5030 | |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5031 | static const struct ieee80211_iface_limit wlcore_iface_limits[] = { |
| 5032 | { |
| 5033 | .max = 2, |
| 5034 | .types = BIT(NL80211_IFTYPE_STATION), |
| 5035 | }, |
| 5036 | { |
| 5037 | .max = 1, |
| 5038 | .types = BIT(NL80211_IFTYPE_AP) | |
| 5039 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 5040 | BIT(NL80211_IFTYPE_P2P_CLIENT), |
| 5041 | }, |
| 5042 | }; |
| 5043 | |
| 5044 | static const struct ieee80211_iface_combination |
| 5045 | wlcore_iface_combinations[] = { |
| 5046 | { |
| 5047 | .num_different_channels = 1, |
| 5048 | .max_interfaces = 2, |
| 5049 | .limits = wlcore_iface_limits, |
| 5050 | .n_limits = ARRAY_SIZE(wlcore_iface_limits), |
| 5051 | }, |
| 5052 | }; |
| 5053 | |
Felipe Balbi | 4b32a2c | 2011-10-06 10:46:20 +0300 | [diff] [blame] | 5054 | static int wl1271_init_ieee80211(struct wl1271 *wl) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5055 | { |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5056 | static const u32 cipher_suites[] = { |
| 5057 | WLAN_CIPHER_SUITE_WEP40, |
| 5058 | WLAN_CIPHER_SUITE_WEP104, |
| 5059 | WLAN_CIPHER_SUITE_TKIP, |
| 5060 | WLAN_CIPHER_SUITE_CCMP, |
| 5061 | WL1271_CIPHER_SUITE_GEM, |
| 5062 | }; |
| 5063 | |
Arik Nemtsov | 2c0133a | 2012-05-18 07:46:36 +0300 | [diff] [blame] | 5064 | /* The tx descriptor buffer */ |
| 5065 | wl->hw->extra_tx_headroom = sizeof(struct wl1271_tx_hw_descr); |
| 5066 | |
| 5067 | if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) |
| 5068 | wl->hw->extra_tx_headroom += WL1271_EXTRA_SPACE_TKIP; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5069 | |
| 5070 | /* unit us */ |
| 5071 | /* FIXME: find a proper value */ |
| 5072 | wl->hw->channel_change_time = 10000; |
Juuso Oikarinen | 50c500a | 2010-04-01 11:38:22 +0300 | [diff] [blame] | 5073 | wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5074 | |
| 5075 | wl->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Juuso Oikarinen | 0a34332 | 2010-02-22 08:38:41 +0200 | [diff] [blame] | 5076 | IEEE80211_HW_SUPPORTS_PS | |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 5077 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Kalle Valo | 4695dc9 | 2010-03-18 12:26:38 +0200 | [diff] [blame] | 5078 | IEEE80211_HW_SUPPORTS_UAPSD | |
Juuso Oikarinen | a9af092 | 2010-03-26 12:53:30 +0200 | [diff] [blame] | 5079 | IEEE80211_HW_HAS_RATE_CONTROL | |
Juuso Oikarinen | 00236aed | 2010-04-09 11:07:30 +0300 | [diff] [blame] | 5080 | IEEE80211_HW_CONNECTION_MONITOR | |
Luciano Coelho | 25eaea30 | 2011-05-02 12:37:33 +0300 | [diff] [blame] | 5081 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
Shahar Levi | fcd23b6 | 2011-05-11 12:12:56 +0300 | [diff] [blame] | 5082 | IEEE80211_HW_SPECTRUM_MGMT | |
Arik Nemtsov | 93f8c8e | 2011-08-30 09:34:01 +0300 | [diff] [blame] | 5083 | IEEE80211_HW_AP_LINK_PS | |
| 5084 | IEEE80211_HW_AMPDU_AGGREGATION | |
Eliad Peller | 79aba1b | 2012-02-02 13:15:35 +0200 | [diff] [blame] | 5085 | IEEE80211_HW_TX_AMPDU_SETUP_IN_HW | |
| 5086 | IEEE80211_HW_SCAN_WHILE_IDLE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5087 | |
Juuso Oikarinen | 7a55724 | 2010-09-27 12:42:07 +0200 | [diff] [blame] | 5088 | wl->hw->wiphy->cipher_suites = cipher_suites; |
| 5089 | wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 5090 | |
Juuso Oikarinen | e0d8bbf | 2009-12-11 15:41:04 +0200 | [diff] [blame] | 5091 | wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | |
Eliad Peller | 045c745 | 2011-08-28 15:23:01 +0300 | [diff] [blame] | 5092 | BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) | |
| 5093 | BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5094 | wl->hw->wiphy->max_scan_ssids = 1; |
Luciano Coelho | 221737d | 2011-09-02 14:28:22 +0300 | [diff] [blame] | 5095 | wl->hw->wiphy->max_sched_scan_ssids = 16; |
| 5096 | wl->hw->wiphy->max_match_sets = 16; |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5097 | /* |
| 5098 | * Maximum length of elements in scanning probe request templates |
| 5099 | * should be the maximum length possible for a template, without |
| 5100 | * the IEEE80211 header of the template |
| 5101 | */ |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5102 | wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE - |
Guy Eilam | ea559b4 | 2010-12-09 16:54:59 +0200 | [diff] [blame] | 5103 | sizeof(struct ieee80211_header); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5104 | |
Ido Reis | c08e371 | 2012-02-02 13:54:27 +0200 | [diff] [blame] | 5105 | 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] | 5106 | sizeof(struct ieee80211_header); |
| 5107 | |
Johannes Berg | 81ddbb5 | 2012-03-26 18:47:18 +0200 | [diff] [blame] | 5108 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD | |
| 5109 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 5110 | |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 5111 | /* make sure all our channels fit in the scanned_ch bitmask */ |
| 5112 | BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) + |
| 5113 | ARRAY_SIZE(wl1271_channels_5ghz) > |
| 5114 | WL1271_MAX_CHANNELS); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5115 | /* |
| 5116 | * We keep local copies of the band structs because we need to |
| 5117 | * modify them on a per-device basis. |
| 5118 | */ |
| 5119 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, |
| 5120 | sizeof(wl1271_band_2ghz)); |
Eliad Peller | bfb92ca | 2012-05-15 17:09:00 +0300 | [diff] [blame] | 5121 | memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, |
| 5122 | &wl->ht_cap[IEEE80211_BAND_2GHZ], |
| 5123 | sizeof(*wl->ht_cap)); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5124 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, |
| 5125 | sizeof(wl1271_band_5ghz)); |
Eliad Peller | bfb92ca | 2012-05-15 17:09:00 +0300 | [diff] [blame] | 5126 | memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, |
| 5127 | &wl->ht_cap[IEEE80211_BAND_5GHZ], |
| 5128 | sizeof(*wl->ht_cap)); |
Luciano Coelho | a8aaaf5 | 2011-01-11 18:25:18 +0100 | [diff] [blame] | 5129 | |
| 5130 | wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 5131 | &wl->bands[IEEE80211_BAND_2GHZ]; |
| 5132 | wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 5133 | &wl->bands[IEEE80211_BAND_5GHZ]; |
Teemu Paasikivi | 1ebec3d | 2009-10-13 12:47:48 +0300 | [diff] [blame] | 5134 | |
Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5135 | wl->hw->queues = 4; |
Juuso Oikarinen | 31627dc | 2010-03-26 12:53:12 +0200 | [diff] [blame] | 5136 | wl->hw->max_rates = 1; |
Kalle Valo | 12bd894 | 2010-03-18 12:26:33 +0200 | [diff] [blame] | 5137 | |
Juuso Oikarinen | b7417d9 | 2010-11-10 11:27:19 +0100 | [diff] [blame] | 5138 | wl->hw->wiphy->reg_notifier = wl1271_reg_notify; |
| 5139 | |
Arik Nemtsov | 9c1b190 | 2011-11-08 18:46:55 +0200 | [diff] [blame] | 5140 | /* the FW answers probe-requests in AP-mode */ |
| 5141 | wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 5142 | wl->hw->wiphy->probe_resp_offload = |
| 5143 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 5144 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 5145 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 5146 | |
Eliad Peller | bcab320b | 2012-06-13 20:29:16 +0300 | [diff] [blame] | 5147 | /* allowed interface combinations */ |
| 5148 | wl->hw->wiphy->iface_combinations = wlcore_iface_combinations; |
| 5149 | wl->hw->wiphy->n_iface_combinations = |
| 5150 | ARRAY_SIZE(wlcore_iface_combinations); |
| 5151 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5152 | SET_IEEE80211_DEV(wl->hw, wl->dev); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5153 | |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5154 | wl->hw->sta_data_size = sizeof(struct wl1271_station); |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 5155 | wl->hw->vif_data_size = sizeof(struct wl12xx_vif); |
Arik Nemtsov | f84f7d7 | 2010-10-16 20:21:23 +0200 | [diff] [blame] | 5156 | |
Arik Nemtsov | ba421f8 | 2012-01-06 00:05:51 +0200 | [diff] [blame] | 5157 | 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] | 5158 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5159 | return 0; |
| 5160 | } |
| 5161 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5162 | #define WL1271_DEFAULT_CHANNEL 0 |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5163 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5164 | struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5165 | { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5166 | struct ieee80211_hw *hw; |
| 5167 | struct wl1271 *wl; |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5168 | int i, j, ret; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5169 | unsigned int order; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5170 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5171 | BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS); |
Arik Nemtsov | f80c2d1 | 2011-09-22 09:52:05 +0300 | [diff] [blame] | 5172 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5173 | hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); |
| 5174 | if (!hw) { |
| 5175 | wl1271_error("could not alloc ieee80211_hw"); |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5176 | ret = -ENOMEM; |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5177 | goto err_hw_alloc; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | wl = hw->priv; |
| 5181 | memset(wl, 0, sizeof(*wl)); |
| 5182 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5183 | wl->priv = kzalloc(priv_size, GFP_KERNEL); |
| 5184 | if (!wl->priv) { |
| 5185 | wl1271_error("could not alloc wl priv"); |
| 5186 | ret = -ENOMEM; |
| 5187 | goto err_priv_alloc; |
| 5188 | } |
| 5189 | |
Eliad Peller | 8762721 | 2011-10-10 10:12:54 +0200 | [diff] [blame] | 5190 | INIT_LIST_HEAD(&wl->wlvif_list); |
Juuso Oikarinen | 01c0916 | 2009-10-13 12:47:55 +0300 | [diff] [blame] | 5191 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5192 | wl->hw = hw; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5193 | |
Juuso Oikarinen | 6742f55 | 2010-12-13 09:52:37 +0200 | [diff] [blame] | 5194 | for (i = 0; i < NUM_TX_QUEUES; i++) |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 5195 | for (j = 0; j < WL12XX_MAX_LINKS; j++) |
Arik Nemtsov | a8c0ddb | 2011-02-23 00:22:26 +0200 | [diff] [blame] | 5196 | skb_queue_head_init(&wl->links[j].tx_queue[i]); |
| 5197 | |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5198 | skb_queue_head_init(&wl->deferred_rx_queue); |
| 5199 | skb_queue_head_init(&wl->deferred_tx_queue); |
| 5200 | |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 5201 | INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); |
Ido Yariv | a620865 | 2011-03-01 15:14:41 +0200 | [diff] [blame] | 5202 | INIT_WORK(&wl->netstack_work, wl1271_netstack_work); |
Juuso Oikarinen | 117b38d | 2010-09-30 10:43:28 +0200 | [diff] [blame] | 5203 | INIT_WORK(&wl->tx_work, wl1271_tx_work); |
| 5204 | INIT_WORK(&wl->recovery_work, wl1271_recovery_work); |
| 5205 | INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 5206 | INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work); |
Bartosz.Markowski@tieto.com | 5f561f6 | 2012-04-26 10:35:07 +0300 | [diff] [blame] | 5207 | INIT_DELAYED_WORK(&wl->connection_loss_work, |
| 5208 | wl1271_connection_loss_work); |
Eliad Peller | 77ddaa1 | 2011-05-15 11:10:29 +0300 | [diff] [blame] | 5209 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5210 | wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); |
| 5211 | if (!wl->freezable_wq) { |
| 5212 | ret = -ENOMEM; |
| 5213 | goto err_hw; |
| 5214 | } |
| 5215 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5216 | wl->channel = WL1271_DEFAULT_CHANNEL; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5217 | wl->rx_counter = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5218 | wl->power_level = WL1271_DEFAULT_POWER_LEVEL; |
Juuso Oikarinen | 8a5a37a | 2009-10-08 21:56:24 +0300 | [diff] [blame] | 5219 | wl->band = IEEE80211_BAND_2GHZ; |
Arik Nemtsov | 83d08d3 | 2012-05-10 12:13:30 +0300 | [diff] [blame] | 5220 | wl->channel_type = NL80211_CHAN_NO_HT; |
Juuso Oikarinen | 830fb67 | 2009-12-11 15:41:06 +0200 | [diff] [blame] | 5221 | wl->flags = 0; |
Juuso Oikarinen | 7fc3a86 | 2010-03-18 12:26:32 +0200 | [diff] [blame] | 5222 | wl->sg_enabled = true; |
Arik Nemtsov | 66340e5 | 2012-06-10 17:09:22 +0300 | [diff] [blame] | 5223 | wl->sleep_auth = WL1271_PSM_ILLEGAL; |
Juuso Oikarinen | d717fd6 | 2010-05-07 11:38:58 +0300 | [diff] [blame] | 5224 | wl->hw_pg_ver = -1; |
Arik Nemtsov | b622d99 | 2011-02-23 00:22:31 +0200 | [diff] [blame] | 5225 | wl->ap_ps_map = 0; |
| 5226 | wl->ap_fw_ps_map = 0; |
Ido Yariv | 606ea9f | 2011-03-01 15:14:39 +0200 | [diff] [blame] | 5227 | wl->quirks = 0; |
Ido Yariv | 341b7cd | 2011-03-31 10:07:01 +0200 | [diff] [blame] | 5228 | wl->platform_quirks = 0; |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 5229 | wl->sched_scanning = false; |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5230 | wl->system_hlid = WL12XX_SYSTEM_HLID; |
Arik Nemtsov | da03209 | 2011-08-25 12:43:15 +0300 | [diff] [blame] | 5231 | wl->active_sta_count = 0; |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5232 | wl->fwlog_size = 0; |
| 5233 | init_waitqueue_head(&wl->fwlog_waitq); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5234 | |
Eliad Peller | f4df1bd | 2011-08-14 13:17:15 +0300 | [diff] [blame] | 5235 | /* The system link is always allocated */ |
| 5236 | __set_bit(WL12XX_SYSTEM_HLID, wl->links_map); |
| 5237 | |
Ido Yariv | 25eeb9e | 2010-10-12 16:20:06 +0200 | [diff] [blame] | 5238 | memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map)); |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 5239 | for (i = 0; i < wl->num_tx_desc; i++) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5240 | wl->tx_frames[i] = NULL; |
| 5241 | |
| 5242 | spin_lock_init(&wl->wl_lock); |
| 5243 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5244 | wl->state = WL1271_STATE_OFF; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5245 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5246 | mutex_init(&wl->mutex); |
Arik Nemtsov | 2c38849 | 2012-05-18 07:46:39 +0300 | [diff] [blame] | 5247 | mutex_init(&wl->flush_mutex); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5248 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5249 | order = get_order(WL1271_AGGR_BUFFER_SIZE); |
| 5250 | wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); |
| 5251 | if (!wl->aggr_buf) { |
| 5252 | ret = -ENOMEM; |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5253 | goto err_wq; |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5254 | } |
| 5255 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5256 | wl->dummy_packet = wl12xx_alloc_dummy_packet(wl); |
| 5257 | if (!wl->dummy_packet) { |
| 5258 | ret = -ENOMEM; |
| 5259 | goto err_aggr; |
| 5260 | } |
| 5261 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5262 | /* Allocate one page for the FW log */ |
| 5263 | wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL); |
| 5264 | if (!wl->fwlog) { |
| 5265 | ret = -ENOMEM; |
| 5266 | goto err_dummy_packet; |
| 5267 | } |
| 5268 | |
Luciano Coelho | fd492ed | 2012-05-03 10:31:02 +0300 | [diff] [blame] | 5269 | wl->mbox = kmalloc(sizeof(*wl->mbox), GFP_KERNEL | GFP_DMA); |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 5270 | if (!wl->mbox) { |
| 5271 | ret = -ENOMEM; |
| 5272 | goto err_fwlog; |
| 5273 | } |
| 5274 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5275 | return hw; |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5276 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 5277 | err_fwlog: |
| 5278 | free_page((unsigned long)wl->fwlog); |
| 5279 | |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5280 | err_dummy_packet: |
| 5281 | dev_kfree_skb(wl->dummy_packet); |
| 5282 | |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5283 | err_aggr: |
| 5284 | free_pages((unsigned long)wl->aggr_buf, order); |
| 5285 | |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5286 | err_wq: |
| 5287 | destroy_workqueue(wl->freezable_wq); |
| 5288 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5289 | err_hw: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5290 | wl1271_debugfs_exit(wl); |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5291 | kfree(wl->priv); |
| 5292 | |
| 5293 | err_priv_alloc: |
Teemu Paasikivi | 3b56dd6 | 2010-03-18 12:26:46 +0200 | [diff] [blame] | 5294 | ieee80211_free_hw(hw); |
| 5295 | |
| 5296 | err_hw_alloc: |
| 5297 | |
Juuso Oikarinen | a1dd818 | 2010-03-18 12:26:31 +0200 | [diff] [blame] | 5298 | return ERR_PTR(ret); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5299 | } |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5300 | EXPORT_SYMBOL_GPL(wlcore_alloc_hw); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5301 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5302 | int wlcore_free_hw(struct wl1271 *wl) |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5303 | { |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5304 | /* Unblock any fwlog readers */ |
| 5305 | mutex_lock(&wl->mutex); |
| 5306 | wl->fwlog_size = -1; |
| 5307 | wake_up_interruptible_all(&wl->fwlog_waitq); |
| 5308 | mutex_unlock(&wl->mutex); |
| 5309 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5310 | device_remove_bin_file(wl->dev, &fwlog_attr); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5311 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5312 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
Gery Kahn | 6f07b72 | 2011-07-18 14:21:49 +0300 | [diff] [blame] | 5313 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5314 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5315 | free_page((unsigned long)wl->fwlog); |
Ido Yariv | 990f5de | 2011-03-31 10:06:59 +0200 | [diff] [blame] | 5316 | dev_kfree_skb(wl->dummy_packet); |
Ido Yariv | 1f37cbc | 2010-09-30 13:28:27 +0200 | [diff] [blame] | 5317 | free_pages((unsigned long)wl->aggr_buf, |
| 5318 | get_order(WL1271_AGGR_BUFFER_SIZE)); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5319 | |
| 5320 | wl1271_debugfs_exit(wl); |
| 5321 | |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5322 | vfree(wl->fw); |
| 5323 | wl->fw = NULL; |
Eliad Peller | 3fcdab7 | 2012-02-06 12:47:54 +0200 | [diff] [blame] | 5324 | wl->fw_type = WL12XX_FW_TYPE_NONE; |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5325 | kfree(wl->nvs); |
| 5326 | wl->nvs = NULL; |
| 5327 | |
Arik Nemtsov | 0afd04e | 2012-05-10 12:13:54 +0300 | [diff] [blame] | 5328 | kfree(wl->fw_status_1); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5329 | kfree(wl->tx_res_if); |
Eliad Peller | 92ef896 | 2011-06-07 12:50:46 +0300 | [diff] [blame] | 5330 | destroy_workqueue(wl->freezable_wq); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5331 | |
Arik Nemtsov | 96e0c68 | 2011-12-07 21:09:03 +0200 | [diff] [blame] | 5332 | kfree(wl->priv); |
Teemu Paasikivi | c332a4b | 2010-02-18 13:25:57 +0200 | [diff] [blame] | 5333 | ieee80211_free_hw(wl->hw); |
| 5334 | |
| 5335 | return 0; |
| 5336 | } |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5337 | EXPORT_SYMBOL_GPL(wlcore_free_hw); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5338 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5339 | static irqreturn_t wl12xx_hardirq(int irq, void *cookie) |
| 5340 | { |
| 5341 | struct wl1271 *wl = cookie; |
| 5342 | unsigned long flags; |
| 5343 | |
| 5344 | wl1271_debug(DEBUG_IRQ, "IRQ"); |
| 5345 | |
| 5346 | /* complete the ELP completion */ |
| 5347 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 5348 | set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); |
| 5349 | if (wl->elp_compl) { |
| 5350 | complete(wl->elp_compl); |
| 5351 | wl->elp_compl = NULL; |
| 5352 | } |
| 5353 | |
| 5354 | if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) { |
| 5355 | /* don't enqueue a work right now. mark it as pending */ |
| 5356 | set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags); |
| 5357 | wl1271_debug(DEBUG_IRQ, "should not enqueue work"); |
| 5358 | disable_irq_nosync(wl->irq); |
| 5359 | pm_wakeup_event(wl->dev, 0); |
| 5360 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 5361 | return IRQ_HANDLED; |
| 5362 | } |
| 5363 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 5364 | |
| 5365 | return IRQ_WAKE_THREAD; |
| 5366 | } |
| 5367 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5368 | int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev) |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5369 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5370 | struct wl12xx_platform_data *pdata = pdev->dev.platform_data; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5371 | unsigned long irqflags; |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5372 | int ret; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5373 | |
Luciano Coelho | 25a43d7 | 2011-11-21 20:37:14 +0200 | [diff] [blame] | 5374 | if (!wl->ops || !wl->ptable) { |
Luciano Coelho | c31be25 | 2011-11-21 19:25:24 +0200 | [diff] [blame] | 5375 | ret = -EINVAL; |
| 5376 | goto out_free_hw; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5377 | } |
| 5378 | |
Arik Nemtsov | 72b0624 | 2011-12-07 21:21:51 +0200 | [diff] [blame] | 5379 | BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS); |
| 5380 | |
Luciano Coelho | e87288f | 2011-12-05 16:12:54 +0200 | [diff] [blame] | 5381 | /* adjust some runtime configuration parameters */ |
| 5382 | wlcore_adjust_conf(wl); |
| 5383 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5384 | wl->irq = platform_get_irq(pdev, 0); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5385 | wl->platform_quirks = pdata->platform_quirks; |
| 5386 | wl->set_power = pdata->set_power; |
| 5387 | wl->dev = &pdev->dev; |
| 5388 | wl->if_ops = pdata->ops; |
| 5389 | |
| 5390 | platform_set_drvdata(pdev, wl); |
| 5391 | |
| 5392 | if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) |
| 5393 | irqflags = IRQF_TRIGGER_RISING; |
| 5394 | else |
| 5395 | irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; |
| 5396 | |
| 5397 | ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq, |
| 5398 | irqflags, |
| 5399 | pdev->name, wl); |
| 5400 | if (ret < 0) { |
| 5401 | wl1271_error("request_irq() failed: %d", ret); |
| 5402 | goto out_free_hw; |
| 5403 | } |
| 5404 | |
| 5405 | ret = enable_irq_wake(wl->irq); |
| 5406 | if (!ret) { |
| 5407 | wl->irq_wake_enabled = true; |
| 5408 | device_init_wakeup(wl->dev, 1); |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 5409 | if (pdata->pwr_in_suspend) { |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5410 | wl->hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; |
Eyal Shapira | b95d7ce | 2012-03-14 06:32:10 +0200 | [diff] [blame] | 5411 | wl->hw->wiphy->wowlan.n_patterns = |
| 5412 | WL1271_MAX_RX_FILTERS; |
| 5413 | wl->hw->wiphy->wowlan.pattern_min_len = 1; |
| 5414 | wl->hw->wiphy->wowlan.pattern_max_len = |
| 5415 | WL1271_RX_FILTER_MAX_PATTERN_SIZE; |
| 5416 | } |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5417 | } |
| 5418 | disable_irq(wl->irq); |
| 5419 | |
Luciano Coelho | 4afc37a | 2012-05-10 12:14:02 +0300 | [diff] [blame] | 5420 | ret = wl12xx_get_hw_info(wl); |
| 5421 | if (ret < 0) { |
| 5422 | wl1271_error("couldn't get hw info"); |
| 5423 | goto out; |
| 5424 | } |
| 5425 | |
| 5426 | ret = wl->ops->identify_chip(wl); |
| 5427 | if (ret < 0) |
| 5428 | goto out; |
| 5429 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5430 | ret = wl1271_init_ieee80211(wl); |
| 5431 | if (ret) |
| 5432 | goto out_irq; |
| 5433 | |
| 5434 | ret = wl1271_register_hw(wl); |
| 5435 | if (ret) |
| 5436 | goto out_irq; |
| 5437 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5438 | /* Create sysfs file to control bt coex state */ |
| 5439 | ret = device_create_file(wl->dev, &dev_attr_bt_coex_state); |
| 5440 | if (ret < 0) { |
| 5441 | wl1271_error("failed to create sysfs file bt_coex_state"); |
| 5442 | goto out_irq; |
| 5443 | } |
| 5444 | |
| 5445 | /* Create sysfs file to get HW PG version */ |
| 5446 | ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver); |
| 5447 | if (ret < 0) { |
| 5448 | wl1271_error("failed to create sysfs file hw_pg_ver"); |
| 5449 | goto out_bt_coex_state; |
| 5450 | } |
| 5451 | |
| 5452 | /* Create sysfs file for the FW log */ |
| 5453 | ret = device_create_bin_file(wl->dev, &fwlog_attr); |
| 5454 | if (ret < 0) { |
| 5455 | wl1271_error("failed to create sysfs file fwlog"); |
| 5456 | goto out_hw_pg_ver; |
| 5457 | } |
| 5458 | |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5459 | goto out; |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5460 | |
Felipe Balbi | f79f890 | 2011-10-06 13:05:25 +0300 | [diff] [blame] | 5461 | out_hw_pg_ver: |
| 5462 | device_remove_file(wl->dev, &dev_attr_hw_pg_ver); |
| 5463 | |
| 5464 | out_bt_coex_state: |
| 5465 | device_remove_file(wl->dev, &dev_attr_bt_coex_state); |
| 5466 | |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5467 | out_irq: |
| 5468 | free_irq(wl->irq, wl); |
| 5469 | |
| 5470 | out_free_hw: |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5471 | wlcore_free_hw(wl); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5472 | |
| 5473 | out: |
| 5474 | return ret; |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5475 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 5476 | EXPORT_SYMBOL_GPL(wlcore_probe); |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5477 | |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 5478 | int __devexit wlcore_remove(struct platform_device *pdev) |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5479 | { |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5480 | struct wl1271 *wl = platform_get_drvdata(pdev); |
| 5481 | |
| 5482 | if (wl->irq_wake_enabled) { |
| 5483 | device_init_wakeup(wl->dev, 0); |
| 5484 | disable_irq_wake(wl->irq); |
| 5485 | } |
| 5486 | wl1271_unregister_hw(wl); |
| 5487 | free_irq(wl->irq, wl); |
Luciano Coelho | ffeb501 | 2011-11-21 18:55:51 +0200 | [diff] [blame] | 5488 | wlcore_free_hw(wl); |
Felipe Balbi | a390e85 | 2011-10-06 10:07:44 +0300 | [diff] [blame] | 5489 | |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5490 | return 0; |
| 5491 | } |
Luciano Coelho | b2ba99f | 2011-11-20 23:32:10 +0200 | [diff] [blame] | 5492 | EXPORT_SYMBOL_GPL(wlcore_remove); |
Felipe Balbi | ce2a217 | 2011-10-05 14:12:55 +0300 | [diff] [blame] | 5493 | |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 5494 | u32 wl12xx_debug_level = DEBUG_NONE; |
Eliad Peller | 17c1755 | 2010-12-12 12:15:35 +0200 | [diff] [blame] | 5495 | EXPORT_SYMBOL_GPL(wl12xx_debug_level); |
Guy Eilam | 491bbd6 | 2011-01-12 10:33:29 +0100 | [diff] [blame] | 5496 | 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] | 5497 | MODULE_PARM_DESC(debug_level, "wl12xx debugging level"); |
| 5498 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5499 | module_param_named(fwlog, fwlog_param, charp, 0); |
Luciano Coelho | 2c882fa | 2012-02-07 12:37:33 +0200 | [diff] [blame] | 5500 | MODULE_PARM_DESC(fwlog, |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 5501 | "FW logger options: continuous, ondemand, dbgpins or disable"); |
| 5502 | |
Eliad Peller | 2a5bff0 | 2011-08-25 18:10:59 +0300 | [diff] [blame] | 5503 | module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR); |
| 5504 | MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery"); |
| 5505 | |
Arik Nemtsov | 34785be | 2011-12-08 13:06:45 +0200 | [diff] [blame] | 5506 | module_param(no_recovery, bool, S_IRUSR | S_IWUSR); |
| 5507 | MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck."); |
| 5508 | |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5509 | MODULE_LICENSE("GPL"); |
Luciano Coelho | b1a48ca | 2011-02-22 14:19:28 +0200 | [diff] [blame] | 5510 | MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); |
Teemu Paasikivi | 50b3eb4 | 2010-02-22 08:38:26 +0200 | [diff] [blame] | 5511 | MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); |