Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
| 3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. |
| 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | #include "mac.h" |
| 19 | |
| 20 | #include <net/mac80211.h> |
| 21 | #include <linux/etherdevice.h> |
| 22 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 23 | #include "hif.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 24 | #include "core.h" |
| 25 | #include "debug.h" |
| 26 | #include "wmi.h" |
| 27 | #include "htt.h" |
| 28 | #include "txrx.h" |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 29 | #include "testmode.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 30 | #include "wmi.h" |
| 31 | #include "wmi-ops.h" |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 32 | #include "wow.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 33 | |
| 34 | /**********/ |
| 35 | /* Crypto */ |
| 36 | /**********/ |
| 37 | |
| 38 | static int ath10k_send_key(struct ath10k_vif *arvif, |
| 39 | struct ieee80211_key_conf *key, |
| 40 | enum set_key_cmd cmd, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 41 | const u8 *macaddr, u32 flags) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 42 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 43 | struct ath10k *ar = arvif->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 44 | struct wmi_vdev_install_key_arg arg = { |
| 45 | .vdev_id = arvif->vdev_id, |
| 46 | .key_idx = key->keyidx, |
| 47 | .key_len = key->keylen, |
| 48 | .key_data = key->key, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 49 | .key_flags = flags, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 50 | .macaddr = macaddr, |
| 51 | }; |
| 52 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 53 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 54 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 55 | switch (key->cipher) { |
| 56 | case WLAN_CIPHER_SUITE_CCMP: |
| 57 | arg.key_cipher = WMI_CIPHER_AES_CCM; |
Marek Kwaczynski | e4e82e9 | 2015-01-24 12:14:53 +0200 | [diff] [blame] | 58 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 59 | break; |
| 60 | case WLAN_CIPHER_SUITE_TKIP: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 61 | arg.key_cipher = WMI_CIPHER_TKIP; |
| 62 | arg.key_txmic_len = 8; |
| 63 | arg.key_rxmic_len = 8; |
| 64 | break; |
| 65 | case WLAN_CIPHER_SUITE_WEP40: |
| 66 | case WLAN_CIPHER_SUITE_WEP104: |
| 67 | arg.key_cipher = WMI_CIPHER_WEP; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 68 | break; |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 69 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 70 | WARN_ON(1); |
| 71 | return -EINVAL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 72 | default: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 73 | ath10k_warn(ar, "cipher %d is not supported\n", key->cipher); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 74 | return -EOPNOTSUPP; |
| 75 | } |
| 76 | |
| 77 | if (cmd == DISABLE_KEY) { |
| 78 | arg.key_cipher = WMI_CIPHER_NONE; |
| 79 | arg.key_data = NULL; |
| 80 | } |
| 81 | |
| 82 | return ath10k_wmi_vdev_install_key(arvif->ar, &arg); |
| 83 | } |
| 84 | |
| 85 | static int ath10k_install_key(struct ath10k_vif *arvif, |
| 86 | struct ieee80211_key_conf *key, |
| 87 | enum set_key_cmd cmd, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 88 | const u8 *macaddr, u32 flags) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 89 | { |
| 90 | struct ath10k *ar = arvif->ar; |
| 91 | int ret; |
| 92 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 93 | lockdep_assert_held(&ar->conf_mutex); |
| 94 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 95 | reinit_completion(&ar->install_key_done); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 96 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 97 | ret = ath10k_send_key(arvif, key, cmd, macaddr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 98 | if (ret) |
| 99 | return ret; |
| 100 | |
| 101 | ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ); |
| 102 | if (ret == 0) |
| 103 | return -ETIMEDOUT; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif, |
| 109 | const u8 *addr) |
| 110 | { |
| 111 | struct ath10k *ar = arvif->ar; |
| 112 | struct ath10k_peer *peer; |
| 113 | int ret; |
| 114 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 115 | u32 flags; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 116 | |
| 117 | lockdep_assert_held(&ar->conf_mutex); |
| 118 | |
| 119 | spin_lock_bh(&ar->data_lock); |
| 120 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 121 | spin_unlock_bh(&ar->data_lock); |
| 122 | |
| 123 | if (!peer) |
| 124 | return -ENOENT; |
| 125 | |
| 126 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { |
| 127 | if (arvif->wep_keys[i] == NULL) |
| 128 | continue; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 129 | |
| 130 | flags = 0; |
| 131 | flags |= WMI_KEY_PAIRWISE; |
| 132 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 133 | /* set TX_USAGE flag for default key id */ |
| 134 | if (arvif->def_wep_key_idx == i) |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 135 | flags |= WMI_KEY_TX_USAGE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 136 | |
| 137 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 138 | addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 139 | if (ret) |
| 140 | return ret; |
| 141 | |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 142 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 143 | peer->keys[i] = arvif->wep_keys[i]; |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 144 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static int ath10k_clear_peer_keys(struct ath10k_vif *arvif, |
| 151 | const u8 *addr) |
| 152 | { |
| 153 | struct ath10k *ar = arvif->ar; |
| 154 | struct ath10k_peer *peer; |
| 155 | int first_errno = 0; |
| 156 | int ret; |
| 157 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 158 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 159 | |
| 160 | lockdep_assert_held(&ar->conf_mutex); |
| 161 | |
| 162 | spin_lock_bh(&ar->data_lock); |
| 163 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 164 | spin_unlock_bh(&ar->data_lock); |
| 165 | |
| 166 | if (!peer) |
| 167 | return -ENOENT; |
| 168 | |
| 169 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 170 | if (peer->keys[i] == NULL) |
| 171 | continue; |
| 172 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 173 | /* key flags are not required to delete the key */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 174 | ret = ath10k_install_key(arvif, peer->keys[i], |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 175 | DISABLE_KEY, addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 176 | if (ret && first_errno == 0) |
| 177 | first_errno = ret; |
| 178 | |
| 179 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 180 | ath10k_warn(ar, "failed to remove peer wep key %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 181 | i, ret); |
| 182 | |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 183 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 184 | peer->keys[i] = NULL; |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 185 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | return first_errno; |
| 189 | } |
| 190 | |
Sujith Manoharan | 504f6cd | 2014-11-25 11:46:58 +0530 | [diff] [blame] | 191 | bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr, |
| 192 | u8 keyidx) |
| 193 | { |
| 194 | struct ath10k_peer *peer; |
| 195 | int i; |
| 196 | |
| 197 | lockdep_assert_held(&ar->data_lock); |
| 198 | |
| 199 | /* We don't know which vdev this peer belongs to, |
| 200 | * since WMI doesn't give us that information. |
| 201 | * |
| 202 | * FIXME: multi-bss needs to be handled. |
| 203 | */ |
| 204 | peer = ath10k_peer_find(ar, 0, addr); |
| 205 | if (!peer) |
| 206 | return false; |
| 207 | |
| 208 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 209 | if (peer->keys[i] && peer->keys[i]->keyidx == keyidx) |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | return false; |
| 214 | } |
| 215 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 216 | static int ath10k_clear_vdev_key(struct ath10k_vif *arvif, |
| 217 | struct ieee80211_key_conf *key) |
| 218 | { |
| 219 | struct ath10k *ar = arvif->ar; |
| 220 | struct ath10k_peer *peer; |
| 221 | u8 addr[ETH_ALEN]; |
| 222 | int first_errno = 0; |
| 223 | int ret; |
| 224 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 225 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 226 | |
| 227 | lockdep_assert_held(&ar->conf_mutex); |
| 228 | |
| 229 | for (;;) { |
| 230 | /* since ath10k_install_key we can't hold data_lock all the |
| 231 | * time, so we try to remove the keys incrementally */ |
| 232 | spin_lock_bh(&ar->data_lock); |
| 233 | i = 0; |
| 234 | list_for_each_entry(peer, &ar->peers, list) { |
| 235 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 236 | if (peer->keys[i] == key) { |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 237 | ether_addr_copy(addr, peer->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 238 | peer->keys[i] = NULL; |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | if (i < ARRAY_SIZE(peer->keys)) |
| 244 | break; |
| 245 | } |
| 246 | spin_unlock_bh(&ar->data_lock); |
| 247 | |
| 248 | if (i == ARRAY_SIZE(peer->keys)) |
| 249 | break; |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 250 | /* key flags are not required to delete the key */ |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 251 | ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 252 | if (ret && first_errno == 0) |
| 253 | first_errno = ret; |
| 254 | |
| 255 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 256 | ath10k_warn(ar, "failed to remove key for %pM: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 257 | addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | return first_errno; |
| 261 | } |
| 262 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 263 | static int ath10k_mac_vif_sta_fix_wep_key(struct ath10k_vif *arvif) |
| 264 | { |
| 265 | struct ath10k *ar = arvif->ar; |
| 266 | enum nl80211_iftype iftype = arvif->vif->type; |
| 267 | struct ieee80211_key_conf *key; |
| 268 | u32 flags = 0; |
| 269 | int num = 0; |
| 270 | int i; |
| 271 | int ret; |
| 272 | |
| 273 | lockdep_assert_held(&ar->conf_mutex); |
| 274 | |
| 275 | if (iftype != NL80211_IFTYPE_STATION) |
| 276 | return 0; |
| 277 | |
| 278 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { |
| 279 | if (arvif->wep_keys[i]) { |
| 280 | key = arvif->wep_keys[i]; |
| 281 | ++num; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | if (num != 1) |
| 286 | return 0; |
| 287 | |
| 288 | flags |= WMI_KEY_PAIRWISE; |
| 289 | flags |= WMI_KEY_TX_USAGE; |
| 290 | |
| 291 | ret = ath10k_install_key(arvif, key, SET_KEY, arvif->bssid, flags); |
| 292 | if (ret) { |
| 293 | ath10k_warn(ar, "failed to install key %i on vdev %i: %d\n", |
| 294 | key->keyidx, arvif->vdev_id, ret); |
| 295 | return ret; |
| 296 | } |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 301 | static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif, |
| 302 | struct ieee80211_key_conf *key) |
| 303 | { |
| 304 | struct ath10k *ar = arvif->ar; |
| 305 | struct ath10k_peer *peer; |
| 306 | int ret; |
| 307 | |
| 308 | lockdep_assert_held(&ar->conf_mutex); |
| 309 | |
| 310 | list_for_each_entry(peer, &ar->peers, list) { |
| 311 | if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN)) |
| 312 | continue; |
| 313 | |
| 314 | if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN)) |
| 315 | continue; |
| 316 | |
| 317 | if (peer->keys[key->keyidx] == key) |
| 318 | continue; |
| 319 | |
| 320 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n", |
| 321 | arvif->vdev_id, key->keyidx); |
| 322 | |
| 323 | ret = ath10k_install_peer_wep_keys(arvif, peer->addr); |
| 324 | if (ret) { |
| 325 | ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n", |
| 326 | arvif->vdev_id, peer->addr, ret); |
| 327 | return ret; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 334 | /*********************/ |
| 335 | /* General utilities */ |
| 336 | /*********************/ |
| 337 | |
| 338 | static inline enum wmi_phy_mode |
| 339 | chan_to_phymode(const struct cfg80211_chan_def *chandef) |
| 340 | { |
| 341 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 342 | |
| 343 | switch (chandef->chan->band) { |
| 344 | case IEEE80211_BAND_2GHZ: |
| 345 | switch (chandef->width) { |
| 346 | case NL80211_CHAN_WIDTH_20_NOHT: |
Peter Oh | 6faab12 | 2014-12-18 10:13:00 -0800 | [diff] [blame] | 347 | if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM) |
| 348 | phymode = MODE_11B; |
| 349 | else |
| 350 | phymode = MODE_11G; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 351 | break; |
| 352 | case NL80211_CHAN_WIDTH_20: |
| 353 | phymode = MODE_11NG_HT20; |
| 354 | break; |
| 355 | case NL80211_CHAN_WIDTH_40: |
| 356 | phymode = MODE_11NG_HT40; |
| 357 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 358 | case NL80211_CHAN_WIDTH_5: |
| 359 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 360 | case NL80211_CHAN_WIDTH_80: |
| 361 | case NL80211_CHAN_WIDTH_80P80: |
| 362 | case NL80211_CHAN_WIDTH_160: |
| 363 | phymode = MODE_UNKNOWN; |
| 364 | break; |
| 365 | } |
| 366 | break; |
| 367 | case IEEE80211_BAND_5GHZ: |
| 368 | switch (chandef->width) { |
| 369 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 370 | phymode = MODE_11A; |
| 371 | break; |
| 372 | case NL80211_CHAN_WIDTH_20: |
| 373 | phymode = MODE_11NA_HT20; |
| 374 | break; |
| 375 | case NL80211_CHAN_WIDTH_40: |
| 376 | phymode = MODE_11NA_HT40; |
| 377 | break; |
| 378 | case NL80211_CHAN_WIDTH_80: |
| 379 | phymode = MODE_11AC_VHT80; |
| 380 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 381 | case NL80211_CHAN_WIDTH_5: |
| 382 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 383 | case NL80211_CHAN_WIDTH_80P80: |
| 384 | case NL80211_CHAN_WIDTH_160: |
| 385 | phymode = MODE_UNKNOWN; |
| 386 | break; |
| 387 | } |
| 388 | break; |
| 389 | default: |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | WARN_ON(phymode == MODE_UNKNOWN); |
| 394 | return phymode; |
| 395 | } |
| 396 | |
| 397 | static u8 ath10k_parse_mpdudensity(u8 mpdudensity) |
| 398 | { |
| 399 | /* |
| 400 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 401 | * 0 for no restriction |
| 402 | * 1 for 1/4 us |
| 403 | * 2 for 1/2 us |
| 404 | * 3 for 1 us |
| 405 | * 4 for 2 us |
| 406 | * 5 for 4 us |
| 407 | * 6 for 8 us |
| 408 | * 7 for 16 us |
| 409 | */ |
| 410 | switch (mpdudensity) { |
| 411 | case 0: |
| 412 | return 0; |
| 413 | case 1: |
| 414 | case 2: |
| 415 | case 3: |
| 416 | /* Our lower layer calculations limit our precision to |
| 417 | 1 microsecond */ |
| 418 | return 1; |
| 419 | case 4: |
| 420 | return 2; |
| 421 | case 5: |
| 422 | return 4; |
| 423 | case 6: |
| 424 | return 8; |
| 425 | case 7: |
| 426 | return 16; |
| 427 | default: |
| 428 | return 0; |
| 429 | } |
| 430 | } |
| 431 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 432 | static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr, |
| 433 | enum wmi_peer_type peer_type) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 434 | { |
| 435 | int ret; |
| 436 | |
| 437 | lockdep_assert_held(&ar->conf_mutex); |
| 438 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 439 | if (ar->num_peers >= ar->max_num_peers) |
| 440 | return -ENOBUFS; |
| 441 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 442 | ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 443 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 444 | ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 445 | addr, vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 446 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 447 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 448 | |
| 449 | ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 450 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 451 | ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 452 | addr, vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 453 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 454 | } |
Michal Kazior | 292a753 | 2014-11-25 15:16:04 +0100 | [diff] [blame] | 455 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 456 | ar->num_peers++; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 461 | static int ath10k_mac_set_kickout(struct ath10k_vif *arvif) |
| 462 | { |
| 463 | struct ath10k *ar = arvif->ar; |
| 464 | u32 param; |
| 465 | int ret; |
| 466 | |
| 467 | param = ar->wmi.pdev_param->sta_kickout_th; |
| 468 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 469 | ATH10K_KICKOUT_THRESHOLD); |
| 470 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 471 | ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 472 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs; |
| 477 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 478 | ATH10K_KEEPALIVE_MIN_IDLE); |
| 479 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 480 | ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 481 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs; |
| 486 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 487 | ATH10K_KEEPALIVE_MAX_IDLE); |
| 488 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 489 | ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 490 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs; |
| 495 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 496 | ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); |
| 497 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 498 | ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 499 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
Vivek Natarajan | acab640 | 2014-11-26 09:06:12 +0200 | [diff] [blame] | 506 | static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value) |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 507 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 508 | struct ath10k *ar = arvif->ar; |
| 509 | u32 vdev_param; |
| 510 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 511 | vdev_param = ar->wmi.vdev_param->rts_threshold; |
| 512 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value); |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value) |
| 516 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 517 | struct ath10k *ar = arvif->ar; |
| 518 | u32 vdev_param; |
| 519 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 520 | if (value != 0xFFFFFFFF) |
| 521 | value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold, |
| 522 | ATH10K_FRAGMT_THRESHOLD_MIN, |
| 523 | ATH10K_FRAGMT_THRESHOLD_MAX); |
| 524 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 525 | vdev_param = ar->wmi.vdev_param->fragmentation_threshold; |
| 526 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value); |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 529 | static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
| 530 | { |
| 531 | int ret; |
| 532 | |
| 533 | lockdep_assert_held(&ar->conf_mutex); |
| 534 | |
| 535 | ret = ath10k_wmi_peer_delete(ar, vdev_id, addr); |
| 536 | if (ret) |
| 537 | return ret; |
| 538 | |
| 539 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); |
| 540 | if (ret) |
| 541 | return ret; |
| 542 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 543 | ar->num_peers--; |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 544 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id) |
| 549 | { |
| 550 | struct ath10k_peer *peer, *tmp; |
| 551 | |
| 552 | lockdep_assert_held(&ar->conf_mutex); |
| 553 | |
| 554 | spin_lock_bh(&ar->data_lock); |
| 555 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 556 | if (peer->vdev_id != vdev_id) |
| 557 | continue; |
| 558 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 559 | ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 560 | peer->addr, vdev_id); |
| 561 | |
| 562 | list_del(&peer->list); |
| 563 | kfree(peer); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 564 | ar->num_peers--; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 565 | } |
| 566 | spin_unlock_bh(&ar->data_lock); |
| 567 | } |
| 568 | |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 569 | static void ath10k_peer_cleanup_all(struct ath10k *ar) |
| 570 | { |
| 571 | struct ath10k_peer *peer, *tmp; |
| 572 | |
| 573 | lockdep_assert_held(&ar->conf_mutex); |
| 574 | |
| 575 | spin_lock_bh(&ar->data_lock); |
| 576 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 577 | list_del(&peer->list); |
| 578 | kfree(peer); |
| 579 | } |
| 580 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | 292a753 | 2014-11-25 15:16:04 +0100 | [diff] [blame] | 581 | |
| 582 | ar->num_peers = 0; |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 583 | ar->num_stations = 0; |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 584 | } |
| 585 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 586 | /************************/ |
| 587 | /* Interface management */ |
| 588 | /************************/ |
| 589 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 590 | void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif) |
| 591 | { |
| 592 | struct ath10k *ar = arvif->ar; |
| 593 | |
| 594 | lockdep_assert_held(&ar->data_lock); |
| 595 | |
| 596 | if (!arvif->beacon) |
| 597 | return; |
| 598 | |
| 599 | if (!arvif->beacon_buf) |
| 600 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr, |
| 601 | arvif->beacon->len, DMA_TO_DEVICE); |
| 602 | |
Michal Kazior | af21319 | 2015-01-29 14:29:52 +0200 | [diff] [blame] | 603 | if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED && |
| 604 | arvif->beacon_state != ATH10K_BEACON_SENT)) |
| 605 | return; |
| 606 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 607 | dev_kfree_skb_any(arvif->beacon); |
| 608 | |
| 609 | arvif->beacon = NULL; |
Michal Kazior | af21319 | 2015-01-29 14:29:52 +0200 | [diff] [blame] | 610 | arvif->beacon_state = ATH10K_BEACON_SCHEDULED; |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif) |
| 614 | { |
| 615 | struct ath10k *ar = arvif->ar; |
| 616 | |
| 617 | lockdep_assert_held(&ar->data_lock); |
| 618 | |
| 619 | ath10k_mac_vif_beacon_free(arvif); |
| 620 | |
| 621 | if (arvif->beacon_buf) { |
| 622 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 623 | arvif->beacon_buf, arvif->beacon_paddr); |
| 624 | arvif->beacon_buf = NULL; |
| 625 | } |
| 626 | } |
| 627 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 628 | static inline int ath10k_vdev_setup_sync(struct ath10k *ar) |
| 629 | { |
| 630 | int ret; |
| 631 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 632 | lockdep_assert_held(&ar->conf_mutex); |
| 633 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 634 | if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) |
| 635 | return -ESHUTDOWN; |
| 636 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 637 | ret = wait_for_completion_timeout(&ar->vdev_setup_done, |
| 638 | ATH10K_VDEV_SETUP_TIMEOUT_HZ); |
| 639 | if (ret == 0) |
| 640 | return -ETIMEDOUT; |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 645 | static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 646 | { |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 647 | struct cfg80211_chan_def *chandef = &ar->chandef; |
| 648 | struct ieee80211_channel *channel = chandef->chan; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 649 | struct wmi_vdev_start_request_arg arg = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 650 | int ret = 0; |
| 651 | |
| 652 | lockdep_assert_held(&ar->conf_mutex); |
| 653 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 654 | arg.vdev_id = vdev_id; |
| 655 | arg.channel.freq = channel->center_freq; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 656 | arg.channel.band_center_freq1 = chandef->center_freq1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 657 | |
| 658 | /* TODO setup this dynamically, what in case we |
| 659 | don't have any vifs? */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 660 | arg.channel.mode = chan_to_phymode(chandef); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 661 | arg.channel.chan_radar = |
| 662 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 663 | |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 664 | arg.channel.min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 665 | arg.channel.max_power = channel->max_power * 2; |
| 666 | arg.channel.max_reg_power = channel->max_reg_power * 2; |
| 667 | arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 668 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 669 | reinit_completion(&ar->vdev_setup_done); |
| 670 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 671 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 672 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 673 | ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 674 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 675 | return ret; |
| 676 | } |
| 677 | |
| 678 | ret = ath10k_vdev_setup_sync(ar); |
| 679 | if (ret) { |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 680 | ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 681 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 682 | return ret; |
| 683 | } |
| 684 | |
| 685 | ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); |
| 686 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 687 | ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 688 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 689 | goto vdev_stop; |
| 690 | } |
| 691 | |
| 692 | ar->monitor_vdev_id = vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 693 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 694 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n", |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 695 | ar->monitor_vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 696 | return 0; |
| 697 | |
| 698 | vdev_stop: |
| 699 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 700 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 701 | ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 702 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 703 | |
| 704 | return ret; |
| 705 | } |
| 706 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 707 | static int ath10k_monitor_vdev_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 708 | { |
| 709 | int ret = 0; |
| 710 | |
| 711 | lockdep_assert_held(&ar->conf_mutex); |
| 712 | |
Marek Puzyniak | 52fa019 | 2013-09-24 14:06:24 +0200 | [diff] [blame] | 713 | ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
| 714 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 715 | ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 716 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 717 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 718 | reinit_completion(&ar->vdev_setup_done); |
| 719 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 720 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 721 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 722 | ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 723 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 724 | |
| 725 | ret = ath10k_vdev_setup_sync(ar); |
| 726 | if (ret) |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 727 | ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 728 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 729 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 730 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n", |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 731 | ar->monitor_vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 732 | return ret; |
| 733 | } |
| 734 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 735 | static int ath10k_monitor_vdev_create(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 736 | { |
| 737 | int bit, ret = 0; |
| 738 | |
| 739 | lockdep_assert_held(&ar->conf_mutex); |
| 740 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 741 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 742 | ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 743 | return -ENOMEM; |
| 744 | } |
| 745 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 746 | bit = __ffs64(ar->free_vdev_map); |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 747 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 748 | ar->monitor_vdev_id = bit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 749 | |
| 750 | ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, |
| 751 | WMI_VDEV_TYPE_MONITOR, |
| 752 | 0, ar->mac_addr); |
| 753 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 754 | ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 755 | ar->monitor_vdev_id, ret); |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 756 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 757 | } |
| 758 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 759 | ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 760 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 761 | ar->monitor_vdev_id); |
| 762 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 763 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 764 | } |
| 765 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 766 | static int ath10k_monitor_vdev_delete(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 767 | { |
| 768 | int ret = 0; |
| 769 | |
| 770 | lockdep_assert_held(&ar->conf_mutex); |
| 771 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 772 | ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
| 773 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 774 | ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 775 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 776 | return ret; |
| 777 | } |
| 778 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 779 | ar->free_vdev_map |= 1LL << ar->monitor_vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 780 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 781 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 782 | ar->monitor_vdev_id); |
| 783 | return ret; |
| 784 | } |
| 785 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 786 | static int ath10k_monitor_start(struct ath10k *ar) |
| 787 | { |
| 788 | int ret; |
| 789 | |
| 790 | lockdep_assert_held(&ar->conf_mutex); |
| 791 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 792 | ret = ath10k_monitor_vdev_create(ar); |
| 793 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 794 | ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 795 | return ret; |
| 796 | } |
| 797 | |
| 798 | ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id); |
| 799 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 800 | ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 801 | ath10k_monitor_vdev_delete(ar); |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | ar->monitor_started = true; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 806 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n"); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 807 | |
| 808 | return 0; |
| 809 | } |
| 810 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 811 | static int ath10k_monitor_stop(struct ath10k *ar) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 812 | { |
| 813 | int ret; |
| 814 | |
| 815 | lockdep_assert_held(&ar->conf_mutex); |
| 816 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 817 | ret = ath10k_monitor_vdev_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 818 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 819 | ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 820 | return ret; |
| 821 | } |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 822 | |
| 823 | ret = ath10k_monitor_vdev_delete(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 824 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 825 | ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 826 | return ret; |
| 827 | } |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 828 | |
| 829 | ar->monitor_started = false; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 830 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n"); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 831 | |
| 832 | return 0; |
| 833 | } |
| 834 | |
Vasanthakumar Thiagarajan | 5484621 | 2015-03-02 17:45:28 +0530 | [diff] [blame] | 835 | static bool ath10k_mac_should_disable_promisc(struct ath10k *ar) |
| 836 | { |
| 837 | struct ath10k_vif *arvif; |
| 838 | |
| 839 | if (!(ar->filter_flags & FIF_PROMISC_IN_BSS)) |
| 840 | return true; |
| 841 | |
| 842 | if (!ar->num_started_vdevs) |
| 843 | return false; |
| 844 | |
| 845 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 846 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 847 | return false; |
| 848 | |
| 849 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 850 | "mac disabling promiscuous mode because vdev is started\n"); |
| 851 | return true; |
| 852 | } |
| 853 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 854 | static int ath10k_monitor_recalc(struct ath10k *ar) |
| 855 | { |
| 856 | bool should_start; |
| 857 | |
| 858 | lockdep_assert_held(&ar->conf_mutex); |
| 859 | |
| 860 | should_start = ar->monitor || |
Michal Kazior | bff414c | 2015-03-09 14:20:55 +0100 | [diff] [blame] | 861 | !ath10k_mac_should_disable_promisc(ar) || |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 862 | test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 863 | |
| 864 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 865 | "mac monitor recalc started? %d should? %d\n", |
| 866 | ar->monitor_started, should_start); |
| 867 | |
| 868 | if (should_start == ar->monitor_started) |
| 869 | return 0; |
| 870 | |
| 871 | if (should_start) |
| 872 | return ath10k_monitor_start(ar); |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 873 | |
| 874 | return ath10k_monitor_stop(ar); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 875 | } |
| 876 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 877 | static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif) |
| 878 | { |
| 879 | struct ath10k *ar = arvif->ar; |
| 880 | u32 vdev_param, rts_cts = 0; |
| 881 | |
| 882 | lockdep_assert_held(&ar->conf_mutex); |
| 883 | |
| 884 | vdev_param = ar->wmi.vdev_param->enable_rtscts; |
| 885 | |
Rajkumar Manoharan | 9a5ab0f | 2015-03-19 16:03:29 +0200 | [diff] [blame] | 886 | rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 887 | |
| 888 | if (arvif->num_legacy_stations > 0) |
| 889 | rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES, |
| 890 | WMI_RTSCTS_PROFILE); |
Rajkumar Manoharan | 9a5ab0f | 2015-03-19 16:03:29 +0200 | [diff] [blame] | 891 | else |
| 892 | rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES, |
| 893 | WMI_RTSCTS_PROFILE); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 894 | |
| 895 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 896 | rts_cts); |
| 897 | } |
| 898 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 899 | static int ath10k_start_cac(struct ath10k *ar) |
| 900 | { |
| 901 | int ret; |
| 902 | |
| 903 | lockdep_assert_held(&ar->conf_mutex); |
| 904 | |
| 905 | set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 906 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 907 | ret = ath10k_monitor_recalc(ar); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 908 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 909 | ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 910 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 911 | return ret; |
| 912 | } |
| 913 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 914 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n", |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 915 | ar->monitor_vdev_id); |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static int ath10k_stop_cac(struct ath10k *ar) |
| 921 | { |
| 922 | lockdep_assert_held(&ar->conf_mutex); |
| 923 | |
| 924 | /* CAC is not running - do nothing */ |
| 925 | if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) |
| 926 | return 0; |
| 927 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 928 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 929 | ath10k_monitor_stop(ar); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 930 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 931 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n"); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 936 | static void ath10k_recalc_radar_detection(struct ath10k *ar) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 937 | { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 938 | int ret; |
| 939 | |
| 940 | lockdep_assert_held(&ar->conf_mutex); |
| 941 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 942 | ath10k_stop_cac(ar); |
| 943 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 944 | if (!ar->radar_enabled) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 945 | return; |
| 946 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 947 | if (ar->num_started_vdevs > 0) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 948 | return; |
| 949 | |
| 950 | ret = ath10k_start_cac(ar); |
| 951 | if (ret) { |
| 952 | /* |
| 953 | * Not possible to start CAC on current channel so starting |
| 954 | * radiation is not allowed, make this channel DFS_UNAVAILABLE |
| 955 | * by indicating that radar was detected. |
| 956 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 957 | ath10k_warn(ar, "failed to start CAC: %d\n", ret); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 958 | ieee80211_radar_detected(ar->hw); |
| 959 | } |
| 960 | } |
| 961 | |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 962 | static int ath10k_vdev_stop(struct ath10k_vif *arvif) |
| 963 | { |
| 964 | struct ath10k *ar = arvif->ar; |
| 965 | int ret; |
| 966 | |
| 967 | lockdep_assert_held(&ar->conf_mutex); |
| 968 | |
| 969 | reinit_completion(&ar->vdev_setup_done); |
| 970 | |
| 971 | ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); |
| 972 | if (ret) { |
| 973 | ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n", |
| 974 | arvif->vdev_id, ret); |
| 975 | return ret; |
| 976 | } |
| 977 | |
| 978 | ret = ath10k_vdev_setup_sync(ar); |
| 979 | if (ret) { |
| 980 | ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n", |
| 981 | arvif->vdev_id, ret); |
| 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | WARN_ON(ar->num_started_vdevs == 0); |
| 986 | |
| 987 | if (ar->num_started_vdevs != 0) { |
| 988 | ar->num_started_vdevs--; |
| 989 | ath10k_recalc_radar_detection(ar); |
| 990 | } |
| 991 | |
| 992 | return ret; |
| 993 | } |
| 994 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 995 | static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart) |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 996 | { |
| 997 | struct ath10k *ar = arvif->ar; |
| 998 | struct cfg80211_chan_def *chandef = &ar->chandef; |
| 999 | struct wmi_vdev_start_request_arg arg = {}; |
Vasanthakumar Thiagarajan | 5484621 | 2015-03-02 17:45:28 +0530 | [diff] [blame] | 1000 | int ret = 0, ret2; |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1001 | |
| 1002 | lockdep_assert_held(&ar->conf_mutex); |
| 1003 | |
| 1004 | reinit_completion(&ar->vdev_setup_done); |
| 1005 | |
| 1006 | arg.vdev_id = arvif->vdev_id; |
| 1007 | arg.dtim_period = arvif->dtim_period; |
| 1008 | arg.bcn_intval = arvif->beacon_interval; |
| 1009 | |
| 1010 | arg.channel.freq = chandef->chan->center_freq; |
| 1011 | arg.channel.band_center_freq1 = chandef->center_freq1; |
| 1012 | arg.channel.mode = chan_to_phymode(chandef); |
| 1013 | |
| 1014 | arg.channel.min_power = 0; |
| 1015 | arg.channel.max_power = chandef->chan->max_power * 2; |
| 1016 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; |
| 1017 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; |
| 1018 | |
| 1019 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 1020 | arg.ssid = arvif->u.ap.ssid; |
| 1021 | arg.ssid_len = arvif->u.ap.ssid_len; |
| 1022 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; |
| 1023 | |
| 1024 | /* For now allow DFS for AP mode */ |
| 1025 | arg.channel.chan_radar = |
| 1026 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); |
| 1027 | } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
| 1028 | arg.ssid = arvif->vif->bss_conf.ssid; |
| 1029 | arg.ssid_len = arvif->vif->bss_conf.ssid_len; |
| 1030 | } |
| 1031 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1032 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1033 | "mac vdev %d start center_freq %d phymode %s\n", |
| 1034 | arg.vdev_id, arg.channel.freq, |
| 1035 | ath10k_wmi_phymode_str(arg.channel.mode)); |
| 1036 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1037 | if (restart) |
| 1038 | ret = ath10k_wmi_vdev_restart(ar, &arg); |
| 1039 | else |
| 1040 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 1041 | |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1042 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1043 | ath10k_warn(ar, "failed to start WMI vdev %i: %d\n", |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1044 | arg.vdev_id, ret); |
| 1045 | return ret; |
| 1046 | } |
| 1047 | |
| 1048 | ret = ath10k_vdev_setup_sync(ar); |
| 1049 | if (ret) { |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 1050 | ath10k_warn(ar, |
| 1051 | "failed to synchronize setup for vdev %i restart %d: %d\n", |
| 1052 | arg.vdev_id, restart, ret); |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1053 | return ret; |
| 1054 | } |
| 1055 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1056 | ar->num_started_vdevs++; |
| 1057 | ath10k_recalc_radar_detection(ar); |
| 1058 | |
Vasanthakumar Thiagarajan | 5484621 | 2015-03-02 17:45:28 +0530 | [diff] [blame] | 1059 | ret = ath10k_monitor_recalc(ar); |
| 1060 | if (ret) { |
| 1061 | ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n", |
| 1062 | arg.vdev_id, restart, ret); |
| 1063 | ret2 = ath10k_vdev_stop(arvif); |
| 1064 | if (ret2) |
| 1065 | ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n", |
| 1066 | arg.vdev_id, restart, ret2); |
| 1067 | } |
| 1068 | |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1069 | return ret; |
| 1070 | } |
| 1071 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1072 | static int ath10k_vdev_start(struct ath10k_vif *arvif) |
| 1073 | { |
| 1074 | return ath10k_vdev_start_restart(arvif, false); |
| 1075 | } |
| 1076 | |
| 1077 | static int ath10k_vdev_restart(struct ath10k_vif *arvif) |
| 1078 | { |
| 1079 | return ath10k_vdev_start_restart(arvif, true); |
| 1080 | } |
| 1081 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1082 | static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif, |
| 1083 | struct sk_buff *bcn) |
| 1084 | { |
| 1085 | struct ath10k *ar = arvif->ar; |
| 1086 | struct ieee80211_mgmt *mgmt; |
| 1087 | const u8 *p2p_ie; |
| 1088 | int ret; |
| 1089 | |
| 1090 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1091 | return 0; |
| 1092 | |
| 1093 | if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) |
| 1094 | return 0; |
| 1095 | |
| 1096 | mgmt = (void *)bcn->data; |
| 1097 | p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1098 | mgmt->u.beacon.variable, |
| 1099 | bcn->len - (mgmt->u.beacon.variable - |
| 1100 | bcn->data)); |
| 1101 | if (!p2p_ie) |
| 1102 | return -ENOENT; |
| 1103 | |
| 1104 | ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); |
| 1105 | if (ret) { |
| 1106 | ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n", |
| 1107 | arvif->vdev_id, ret); |
| 1108 | return ret; |
| 1109 | } |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, |
| 1115 | u8 oui_type, size_t ie_offset) |
| 1116 | { |
| 1117 | size_t len; |
| 1118 | const u8 *next; |
| 1119 | const u8 *end; |
| 1120 | u8 *ie; |
| 1121 | |
| 1122 | if (WARN_ON(skb->len < ie_offset)) |
| 1123 | return -EINVAL; |
| 1124 | |
| 1125 | ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 1126 | skb->data + ie_offset, |
| 1127 | skb->len - ie_offset); |
| 1128 | if (!ie) |
| 1129 | return -ENOENT; |
| 1130 | |
| 1131 | len = ie[1] + 2; |
| 1132 | end = skb->data + skb->len; |
| 1133 | next = ie + len; |
| 1134 | |
| 1135 | if (WARN_ON(next > end)) |
| 1136 | return -EINVAL; |
| 1137 | |
| 1138 | memmove(ie, next, end - next); |
| 1139 | skb_trim(skb, skb->len - len); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif) |
| 1145 | { |
| 1146 | struct ath10k *ar = arvif->ar; |
| 1147 | struct ieee80211_hw *hw = ar->hw; |
| 1148 | struct ieee80211_vif *vif = arvif->vif; |
| 1149 | struct ieee80211_mutable_offsets offs = {}; |
| 1150 | struct sk_buff *bcn; |
| 1151 | int ret; |
| 1152 | |
| 1153 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1154 | return 0; |
| 1155 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1156 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 1157 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 1158 | return 0; |
| 1159 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1160 | bcn = ieee80211_beacon_get_template(hw, vif, &offs); |
| 1161 | if (!bcn) { |
| 1162 | ath10k_warn(ar, "failed to get beacon template from mac80211\n"); |
| 1163 | return -EPERM; |
| 1164 | } |
| 1165 | |
| 1166 | ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn); |
| 1167 | if (ret) { |
| 1168 | ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret); |
| 1169 | kfree_skb(bcn); |
| 1170 | return ret; |
| 1171 | } |
| 1172 | |
| 1173 | /* P2P IE is inserted by firmware automatically (as configured above) |
| 1174 | * so remove it from the base beacon template to avoid duplicate P2P |
| 1175 | * IEs in beacon frames. |
| 1176 | */ |
| 1177 | ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1178 | offsetof(struct ieee80211_mgmt, |
| 1179 | u.beacon.variable)); |
| 1180 | |
| 1181 | ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0, |
| 1182 | 0, NULL, 0); |
| 1183 | kfree_skb(bcn); |
| 1184 | |
| 1185 | if (ret) { |
| 1186 | ath10k_warn(ar, "failed to submit beacon template command: %d\n", |
| 1187 | ret); |
| 1188 | return ret; |
| 1189 | } |
| 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif) |
| 1195 | { |
| 1196 | struct ath10k *ar = arvif->ar; |
| 1197 | struct ieee80211_hw *hw = ar->hw; |
| 1198 | struct ieee80211_vif *vif = arvif->vif; |
| 1199 | struct sk_buff *prb; |
| 1200 | int ret; |
| 1201 | |
| 1202 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1203 | return 0; |
| 1204 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1205 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1206 | return 0; |
| 1207 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1208 | prb = ieee80211_proberesp_get(hw, vif); |
| 1209 | if (!prb) { |
| 1210 | ath10k_warn(ar, "failed to get probe resp template from mac80211\n"); |
| 1211 | return -EPERM; |
| 1212 | } |
| 1213 | |
| 1214 | ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb); |
| 1215 | kfree_skb(prb); |
| 1216 | |
| 1217 | if (ret) { |
| 1218 | ath10k_warn(ar, "failed to submit probe resp template command: %d\n", |
| 1219 | ret); |
| 1220 | return ret; |
| 1221 | } |
| 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1226 | static void ath10k_control_beaconing(struct ath10k_vif *arvif, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1227 | struct ieee80211_bss_conf *info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1228 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1229 | struct ath10k *ar = arvif->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1230 | int ret = 0; |
| 1231 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1232 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1233 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1234 | if (!info->enable_beacon) { |
| 1235 | ath10k_vdev_stop(arvif); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1236 | |
| 1237 | arvif->is_started = false; |
| 1238 | arvif->is_up = false; |
Michal Kazior | 8513d95 | 2015-03-09 14:19:24 +0100 | [diff] [blame] | 1239 | |
| 1240 | spin_lock_bh(&arvif->ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 1241 | ath10k_mac_vif_beacon_free(arvif); |
Michal Kazior | 748afc4 | 2014-01-23 12:48:21 +0100 | [diff] [blame] | 1242 | spin_unlock_bh(&arvif->ar->data_lock); |
| 1243 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1244 | return; |
| 1245 | } |
| 1246 | |
| 1247 | arvif->tx_seq_no = 0x1000; |
| 1248 | |
| 1249 | ret = ath10k_vdev_start(arvif); |
| 1250 | if (ret) |
| 1251 | return; |
| 1252 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1253 | arvif->aid = 0; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 1254 | ether_addr_copy(arvif->bssid, info->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1255 | |
| 1256 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 1257 | arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1258 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1259 | ath10k_warn(ar, "failed to bring up vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1260 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1261 | ath10k_vdev_stop(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1262 | return; |
| 1263 | } |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1264 | |
| 1265 | arvif->is_started = true; |
| 1266 | arvif->is_up = true; |
| 1267 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1268 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | static void ath10k_control_ibss(struct ath10k_vif *arvif, |
| 1272 | struct ieee80211_bss_conf *info, |
| 1273 | const u8 self_peer[ETH_ALEN]) |
| 1274 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1275 | struct ath10k *ar = arvif->ar; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 1276 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1277 | int ret = 0; |
| 1278 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1279 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1280 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1281 | if (!info->ibss_joined) { |
| 1282 | ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer); |
| 1283 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1284 | ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1285 | self_peer, arvif->vdev_id, ret); |
| 1286 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1287 | if (is_zero_ether_addr(arvif->bssid)) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1288 | return; |
| 1289 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1290 | memset(arvif->bssid, 0, ETH_ALEN); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1291 | |
| 1292 | return; |
| 1293 | } |
| 1294 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 1295 | ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer, |
| 1296 | WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1297 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1298 | ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1299 | self_peer, arvif->vdev_id, ret); |
| 1300 | return; |
| 1301 | } |
| 1302 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 1303 | vdev_param = arvif->ar->wmi.vdev_param->atim_window; |
| 1304 | ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1305 | ATH10K_DEFAULT_ATIM); |
| 1306 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1307 | ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1308 | arvif->vdev_id, ret); |
| 1309 | } |
| 1310 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 1311 | static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif) |
| 1312 | { |
| 1313 | struct ath10k *ar = arvif->ar; |
| 1314 | u32 param; |
| 1315 | u32 value; |
| 1316 | int ret; |
| 1317 | |
| 1318 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1319 | |
| 1320 | if (arvif->u.sta.uapsd) |
| 1321 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER; |
| 1322 | else |
| 1323 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; |
| 1324 | |
| 1325 | param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; |
| 1326 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value); |
| 1327 | if (ret) { |
| 1328 | ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n", |
| 1329 | value, arvif->vdev_id, ret); |
| 1330 | return ret; |
| 1331 | } |
| 1332 | |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
| 1336 | static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif) |
| 1337 | { |
| 1338 | struct ath10k *ar = arvif->ar; |
| 1339 | u32 param; |
| 1340 | u32 value; |
| 1341 | int ret; |
| 1342 | |
| 1343 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1344 | |
| 1345 | if (arvif->u.sta.uapsd) |
| 1346 | value = WMI_STA_PS_PSPOLL_COUNT_UAPSD; |
| 1347 | else |
| 1348 | value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; |
| 1349 | |
| 1350 | param = WMI_STA_PS_PARAM_PSPOLL_COUNT; |
| 1351 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 1352 | param, value); |
| 1353 | if (ret) { |
| 1354 | ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n", |
| 1355 | value, arvif->vdev_id, ret); |
| 1356 | return ret; |
| 1357 | } |
| 1358 | |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1362 | static int ath10k_mac_ps_vif_count(struct ath10k *ar) |
| 1363 | { |
| 1364 | struct ath10k_vif *arvif; |
| 1365 | int num = 0; |
| 1366 | |
| 1367 | lockdep_assert_held(&ar->conf_mutex); |
| 1368 | |
| 1369 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 1370 | if (arvif->ps) |
| 1371 | num++; |
| 1372 | |
| 1373 | return num; |
| 1374 | } |
| 1375 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1376 | static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1377 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1378 | struct ath10k *ar = arvif->ar; |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1379 | struct ieee80211_vif *vif = arvif->vif; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1380 | struct ieee80211_conf *conf = &ar->hw->conf; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1381 | enum wmi_sta_powersave_param param; |
| 1382 | enum wmi_sta_ps_mode psmode; |
| 1383 | int ret; |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1384 | int ps_timeout; |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1385 | bool enable_ps; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1386 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1387 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1388 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1389 | if (arvif->vif->type != NL80211_IFTYPE_STATION) |
| 1390 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1391 | |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1392 | enable_ps = arvif->ps; |
| 1393 | |
| 1394 | if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 && |
| 1395 | !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT, |
| 1396 | ar->fw_features)) { |
| 1397 | ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n", |
| 1398 | arvif->vdev_id); |
| 1399 | enable_ps = false; |
| 1400 | } |
| 1401 | |
| 1402 | if (enable_ps) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1403 | psmode = WMI_STA_PS_MODE_ENABLED; |
| 1404 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; |
| 1405 | |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1406 | ps_timeout = conf->dynamic_ps_timeout; |
| 1407 | if (ps_timeout == 0) { |
| 1408 | /* Firmware doesn't like 0 */ |
| 1409 | ps_timeout = ieee80211_tu_to_usec( |
| 1410 | vif->bss_conf.beacon_int) / 1000; |
| 1411 | } |
| 1412 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1413 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1414 | ps_timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1415 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1416 | ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1417 | arvif->vdev_id, ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1418 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1419 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1420 | } else { |
| 1421 | psmode = WMI_STA_PS_MODE_DISABLED; |
| 1422 | } |
| 1423 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1424 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1425 | arvif->vdev_id, psmode ? "enable" : "disable"); |
| 1426 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1427 | ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode); |
| 1428 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1429 | ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 1430 | psmode, arvif->vdev_id, ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1431 | return ret; |
| 1432 | } |
| 1433 | |
| 1434 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1435 | } |
| 1436 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 1437 | static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif) |
| 1438 | { |
| 1439 | struct ath10k *ar = arvif->ar; |
| 1440 | struct wmi_sta_keepalive_arg arg = {}; |
| 1441 | int ret; |
| 1442 | |
| 1443 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1444 | |
| 1445 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 1446 | return 0; |
| 1447 | |
| 1448 | if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map)) |
| 1449 | return 0; |
| 1450 | |
| 1451 | /* Some firmware revisions have a bug and ignore the `enabled` field. |
| 1452 | * Instead use the interval to disable the keepalive. |
| 1453 | */ |
| 1454 | arg.vdev_id = arvif->vdev_id; |
| 1455 | arg.enabled = 1; |
| 1456 | arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME; |
| 1457 | arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE; |
| 1458 | |
| 1459 | ret = ath10k_wmi_sta_keepalive(ar, &arg); |
| 1460 | if (ret) { |
| 1461 | ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n", |
| 1462 | arvif->vdev_id, ret); |
| 1463 | return ret; |
| 1464 | } |
| 1465 | |
| 1466 | return 0; |
| 1467 | } |
| 1468 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1469 | static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif) |
| 1470 | { |
| 1471 | struct ath10k *ar = arvif->ar; |
| 1472 | struct ieee80211_vif *vif = arvif->vif; |
| 1473 | int ret; |
| 1474 | |
Michal Kazior | 8513d95 | 2015-03-09 14:19:24 +0100 | [diff] [blame] | 1475 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1476 | |
| 1477 | if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))) |
| 1478 | return; |
| 1479 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1480 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1481 | return; |
| 1482 | |
| 1483 | if (!vif->csa_active) |
| 1484 | return; |
| 1485 | |
| 1486 | if (!arvif->is_up) |
| 1487 | return; |
| 1488 | |
| 1489 | if (!ieee80211_csa_is_complete(vif)) { |
| 1490 | ieee80211_csa_update_counter(vif); |
| 1491 | |
| 1492 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 1493 | if (ret) |
| 1494 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 1495 | ret); |
| 1496 | |
| 1497 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 1498 | if (ret) |
| 1499 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 1500 | ret); |
| 1501 | } else { |
| 1502 | ieee80211_csa_finish(vif); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | static void ath10k_mac_vif_ap_csa_work(struct work_struct *work) |
| 1507 | { |
| 1508 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 1509 | ap_csa_work); |
| 1510 | struct ath10k *ar = arvif->ar; |
| 1511 | |
| 1512 | mutex_lock(&ar->conf_mutex); |
| 1513 | ath10k_mac_vif_ap_csa_count_down(arvif); |
| 1514 | mutex_unlock(&ar->conf_mutex); |
| 1515 | } |
| 1516 | |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 1517 | static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac, |
| 1518 | struct ieee80211_vif *vif) |
| 1519 | { |
| 1520 | struct sk_buff *skb = data; |
| 1521 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 1522 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1523 | |
| 1524 | if (vif->type != NL80211_IFTYPE_STATION) |
| 1525 | return; |
| 1526 | |
| 1527 | if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) |
| 1528 | return; |
| 1529 | |
| 1530 | cancel_delayed_work(&arvif->connection_loss_work); |
| 1531 | } |
| 1532 | |
| 1533 | void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb) |
| 1534 | { |
| 1535 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 1536 | IEEE80211_IFACE_ITER_NORMAL, |
| 1537 | ath10k_mac_handle_beacon_iter, |
| 1538 | skb); |
| 1539 | } |
| 1540 | |
| 1541 | static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac, |
| 1542 | struct ieee80211_vif *vif) |
| 1543 | { |
| 1544 | u32 *vdev_id = data; |
| 1545 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1546 | struct ath10k *ar = arvif->ar; |
| 1547 | struct ieee80211_hw *hw = ar->hw; |
| 1548 | |
| 1549 | if (arvif->vdev_id != *vdev_id) |
| 1550 | return; |
| 1551 | |
| 1552 | if (!arvif->is_up) |
| 1553 | return; |
| 1554 | |
| 1555 | ieee80211_beacon_loss(vif); |
| 1556 | |
| 1557 | /* Firmware doesn't report beacon loss events repeatedly. If AP probe |
| 1558 | * (done by mac80211) succeeds but beacons do not resume then it |
| 1559 | * doesn't make sense to continue operation. Queue connection loss work |
| 1560 | * which can be cancelled when beacon is received. |
| 1561 | */ |
| 1562 | ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, |
| 1563 | ATH10K_CONNECTION_LOSS_HZ); |
| 1564 | } |
| 1565 | |
| 1566 | void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id) |
| 1567 | { |
| 1568 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 1569 | IEEE80211_IFACE_ITER_NORMAL, |
| 1570 | ath10k_mac_handle_beacon_miss_iter, |
| 1571 | &vdev_id); |
| 1572 | } |
| 1573 | |
| 1574 | static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work) |
| 1575 | { |
| 1576 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 1577 | connection_loss_work.work); |
| 1578 | struct ieee80211_vif *vif = arvif->vif; |
| 1579 | |
| 1580 | if (!arvif->is_up) |
| 1581 | return; |
| 1582 | |
| 1583 | ieee80211_connection_loss(vif); |
| 1584 | } |
| 1585 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1586 | /**********************/ |
| 1587 | /* Station management */ |
| 1588 | /**********************/ |
| 1589 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1590 | static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar, |
| 1591 | struct ieee80211_vif *vif) |
| 1592 | { |
| 1593 | /* Some firmware revisions have unstable STA powersave when listen |
| 1594 | * interval is set too high (e.g. 5). The symptoms are firmware doesn't |
| 1595 | * generate NullFunc frames properly even if buffered frames have been |
| 1596 | * indicated in Beacon TIM. Firmware would seldom wake up to pull |
| 1597 | * buffered frames. Often pinging the device from AP would simply fail. |
| 1598 | * |
| 1599 | * As a workaround set it to 1. |
| 1600 | */ |
| 1601 | if (vif->type == NL80211_IFTYPE_STATION) |
| 1602 | return 1; |
| 1603 | |
| 1604 | return ar->hw->conf.listen_interval; |
| 1605 | } |
| 1606 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1607 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1608 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1609 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1610 | struct wmi_peer_assoc_complete_arg *arg) |
| 1611 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1612 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1613 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1614 | lockdep_assert_held(&ar->conf_mutex); |
| 1615 | |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 1616 | ether_addr_copy(arg->addr, sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1617 | arg->vdev_id = arvif->vdev_id; |
| 1618 | arg->peer_aid = sta->aid; |
| 1619 | arg->peer_flags |= WMI_PEER_AUTH; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1620 | arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1621 | arg->peer_num_spatial_streams = 1; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1622 | arg->peer_caps = vif->bss_conf.assoc_capability; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1626 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1627 | struct wmi_peer_assoc_complete_arg *arg) |
| 1628 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1629 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
| 1630 | struct cfg80211_bss *bss; |
| 1631 | const u8 *rsnie = NULL; |
| 1632 | const u8 *wpaie = NULL; |
| 1633 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1634 | lockdep_assert_held(&ar->conf_mutex); |
| 1635 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1636 | bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan, |
Dedy Lansky | 6eb1813 | 2015-02-08 15:52:03 +0200 | [diff] [blame] | 1637 | info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY, |
| 1638 | IEEE80211_PRIVACY_ANY); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1639 | if (bss) { |
| 1640 | const struct cfg80211_bss_ies *ies; |
| 1641 | |
| 1642 | rcu_read_lock(); |
| 1643 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); |
| 1644 | |
| 1645 | ies = rcu_dereference(bss->ies); |
| 1646 | |
| 1647 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1648 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 1649 | ies->data, |
| 1650 | ies->len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1651 | rcu_read_unlock(); |
| 1652 | cfg80211_put_bss(ar->hw->wiphy, bss); |
| 1653 | } |
| 1654 | |
| 1655 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ |
| 1656 | if (rsnie || wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1657 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1658 | arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; |
| 1659 | } |
| 1660 | |
| 1661 | if (wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1662 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1663 | arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; |
| 1664 | } |
| 1665 | } |
| 1666 | |
| 1667 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, |
| 1668 | struct ieee80211_sta *sta, |
| 1669 | struct wmi_peer_assoc_complete_arg *arg) |
| 1670 | { |
| 1671 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
| 1672 | const struct ieee80211_supported_band *sband; |
| 1673 | const struct ieee80211_rate *rates; |
| 1674 | u32 ratemask; |
| 1675 | int i; |
| 1676 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1677 | lockdep_assert_held(&ar->conf_mutex); |
| 1678 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1679 | sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band]; |
| 1680 | ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band]; |
| 1681 | rates = sband->bitrates; |
| 1682 | |
| 1683 | rateset->num_rates = 0; |
| 1684 | |
| 1685 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { |
| 1686 | if (!(ratemask & 1)) |
| 1687 | continue; |
| 1688 | |
| 1689 | rateset->rates[rateset->num_rates] = rates->hw_value; |
| 1690 | rateset->num_rates++; |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, |
| 1695 | struct ieee80211_sta *sta, |
| 1696 | struct wmi_peer_assoc_complete_arg *arg) |
| 1697 | { |
| 1698 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1699 | int i, n; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 1700 | u32 stbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1701 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1702 | lockdep_assert_held(&ar->conf_mutex); |
| 1703 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1704 | if (!ht_cap->ht_supported) |
| 1705 | return; |
| 1706 | |
| 1707 | arg->peer_flags |= WMI_PEER_HT; |
| 1708 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 1709 | ht_cap->ampdu_factor)) - 1; |
| 1710 | |
| 1711 | arg->peer_mpdu_density = |
| 1712 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); |
| 1713 | |
| 1714 | arg->peer_ht_caps = ht_cap->cap; |
| 1715 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; |
| 1716 | |
| 1717 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) |
| 1718 | arg->peer_flags |= WMI_PEER_LDPC; |
| 1719 | |
| 1720 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
| 1721 | arg->peer_flags |= WMI_PEER_40MHZ; |
| 1722 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; |
| 1723 | } |
| 1724 | |
| 1725 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) |
| 1726 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 1727 | |
| 1728 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) |
| 1729 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 1730 | |
| 1731 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { |
| 1732 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; |
| 1733 | arg->peer_flags |= WMI_PEER_STBC; |
| 1734 | } |
| 1735 | |
| 1736 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1737 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
| 1738 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 1739 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; |
| 1740 | arg->peer_rate_caps |= stbc; |
| 1741 | arg->peer_flags |= WMI_PEER_STBC; |
| 1742 | } |
| 1743 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1744 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
| 1745 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; |
| 1746 | else if (ht_cap->mcs.rx_mask[1]) |
| 1747 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; |
| 1748 | |
| 1749 | for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++) |
| 1750 | if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8)) |
| 1751 | arg->peer_ht_rates.rates[n++] = i; |
| 1752 | |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 1753 | /* |
| 1754 | * This is a workaround for HT-enabled STAs which break the spec |
| 1755 | * and have no HT capabilities RX mask (no HT RX MCS map). |
| 1756 | * |
| 1757 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), |
| 1758 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. |
| 1759 | * |
| 1760 | * Firmware asserts if such situation occurs. |
| 1761 | */ |
| 1762 | if (n == 0) { |
| 1763 | arg->peer_ht_rates.num_rates = 8; |
| 1764 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) |
| 1765 | arg->peer_ht_rates.rates[i] = i; |
| 1766 | } else { |
| 1767 | arg->peer_ht_rates.num_rates = n; |
| 1768 | arg->peer_num_spatial_streams = sta->rx_nss; |
| 1769 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1770 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1771 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1772 | arg->addr, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1773 | arg->peer_ht_rates.num_rates, |
| 1774 | arg->peer_num_spatial_streams); |
| 1775 | } |
| 1776 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1777 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
| 1778 | struct ath10k_vif *arvif, |
| 1779 | struct ieee80211_sta *sta) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1780 | { |
| 1781 | u32 uapsd = 0; |
| 1782 | u32 max_sp = 0; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1783 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1784 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1785 | lockdep_assert_held(&ar->conf_mutex); |
| 1786 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1787 | if (sta->wme && sta->uapsd_queues) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1788 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1789 | sta->uapsd_queues, sta->max_sp); |
| 1790 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1791 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 1792 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | |
| 1793 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; |
| 1794 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 1795 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | |
| 1796 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; |
| 1797 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 1798 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | |
| 1799 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; |
| 1800 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 1801 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | |
| 1802 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; |
| 1803 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1804 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
| 1805 | max_sp = sta->max_sp; |
| 1806 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1807 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 1808 | sta->addr, |
| 1809 | WMI_AP_PS_PEER_PARAM_UAPSD, |
| 1810 | uapsd); |
| 1811 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1812 | ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1813 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1814 | return ret; |
| 1815 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1816 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1817 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 1818 | sta->addr, |
| 1819 | WMI_AP_PS_PEER_PARAM_MAX_SP, |
| 1820 | max_sp); |
| 1821 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1822 | ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1823 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1824 | return ret; |
| 1825 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1826 | |
| 1827 | /* TODO setup this based on STA listen interval and |
| 1828 | beacon interval. Currently we don't know |
| 1829 | sta->listen_interval - mac80211 patch required. |
| 1830 | Currently use 10 seconds */ |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1831 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1832 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, |
| 1833 | 10); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1834 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1835 | ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1836 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1837 | return ret; |
| 1838 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1839 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1840 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1841 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, |
| 1845 | struct ieee80211_sta *sta, |
| 1846 | struct wmi_peer_assoc_complete_arg *arg) |
| 1847 | { |
| 1848 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 1849 | u8 ampdu_factor; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1850 | |
| 1851 | if (!vht_cap->vht_supported) |
| 1852 | return; |
| 1853 | |
| 1854 | arg->peer_flags |= WMI_PEER_VHT; |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 1855 | |
| 1856 | if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) |
| 1857 | arg->peer_flags |= WMI_PEER_VHT_2G; |
| 1858 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1859 | arg->peer_vht_caps = vht_cap->cap; |
| 1860 | |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 1861 | ampdu_factor = (vht_cap->cap & |
| 1862 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> |
| 1863 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 1864 | |
| 1865 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to |
| 1866 | * zero in VHT IE. Using it would result in degraded throughput. |
| 1867 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep |
| 1868 | * it if VHT max_mpdu is smaller. */ |
| 1869 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
| 1870 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 1871 | ampdu_factor)) - 1); |
| 1872 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1873 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 1874 | arg->peer_flags |= WMI_PEER_80MHZ; |
| 1875 | |
| 1876 | arg->peer_vht_rates.rx_max_rate = |
| 1877 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
| 1878 | arg->peer_vht_rates.rx_mcs_set = |
| 1879 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 1880 | arg->peer_vht_rates.tx_max_rate = |
| 1881 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); |
| 1882 | arg->peer_vht_rates.tx_mcs_set = |
| 1883 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); |
| 1884 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1885 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1886 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1890 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1891 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1892 | struct wmi_peer_assoc_complete_arg *arg) |
| 1893 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1894 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1895 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1896 | switch (arvif->vdev_type) { |
| 1897 | case WMI_VDEV_TYPE_AP: |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1898 | if (sta->wme) |
| 1899 | arg->peer_flags |= WMI_PEER_QOS; |
| 1900 | |
| 1901 | if (sta->wme && sta->uapsd_queues) { |
| 1902 | arg->peer_flags |= WMI_PEER_APSD; |
| 1903 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; |
| 1904 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1905 | break; |
| 1906 | case WMI_VDEV_TYPE_STA: |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1907 | if (vif->bss_conf.qos) |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1908 | arg->peer_flags |= WMI_PEER_QOS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1909 | break; |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 1910 | case WMI_VDEV_TYPE_IBSS: |
| 1911 | if (sta->wme) |
| 1912 | arg->peer_flags |= WMI_PEER_QOS; |
| 1913 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1914 | default: |
| 1915 | break; |
| 1916 | } |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 1917 | |
| 1918 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n", |
| 1919 | sta->addr, !!(arg->peer_flags & WMI_PEER_QOS)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1920 | } |
| 1921 | |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 1922 | static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta) |
| 1923 | { |
| 1924 | /* First 4 rates in ath10k_rates are CCK (11b) rates. */ |
| 1925 | return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4; |
| 1926 | } |
| 1927 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1928 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1929 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1930 | struct ieee80211_sta *sta, |
| 1931 | struct wmi_peer_assoc_complete_arg *arg) |
| 1932 | { |
| 1933 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 1934 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1935 | switch (ar->hw->conf.chandef.chan->band) { |
| 1936 | case IEEE80211_BAND_2GHZ: |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 1937 | if (sta->vht_cap.vht_supported) { |
| 1938 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1939 | phymode = MODE_11AC_VHT40; |
| 1940 | else |
| 1941 | phymode = MODE_11AC_VHT20; |
| 1942 | } else if (sta->ht_cap.ht_supported) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1943 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1944 | phymode = MODE_11NG_HT40; |
| 1945 | else |
| 1946 | phymode = MODE_11NG_HT20; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 1947 | } else if (ath10k_mac_sta_has_11g_rates(sta)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1948 | phymode = MODE_11G; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 1949 | } else { |
| 1950 | phymode = MODE_11B; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | break; |
| 1954 | case IEEE80211_BAND_5GHZ: |
Sujith Manoharan | 7cc45e9 | 2013-09-08 18:19:55 +0300 | [diff] [blame] | 1955 | /* |
| 1956 | * Check VHT first. |
| 1957 | */ |
| 1958 | if (sta->vht_cap.vht_supported) { |
| 1959 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 1960 | phymode = MODE_11AC_VHT80; |
| 1961 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1962 | phymode = MODE_11AC_VHT40; |
| 1963 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 1964 | phymode = MODE_11AC_VHT20; |
| 1965 | } else if (sta->ht_cap.ht_supported) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1966 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1967 | phymode = MODE_11NA_HT40; |
| 1968 | else |
| 1969 | phymode = MODE_11NA_HT20; |
| 1970 | } else { |
| 1971 | phymode = MODE_11A; |
| 1972 | } |
| 1973 | |
| 1974 | break; |
| 1975 | default: |
| 1976 | break; |
| 1977 | } |
| 1978 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1979 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
Kalle Valo | 38a1d47 | 2013-09-08 17:56:14 +0300 | [diff] [blame] | 1980 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1981 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1982 | arg->peer_phymode = phymode; |
| 1983 | WARN_ON(phymode == MODE_UNKNOWN); |
| 1984 | } |
| 1985 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1986 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1987 | struct ieee80211_vif *vif, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1988 | struct ieee80211_sta *sta, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1989 | struct wmi_peer_assoc_complete_arg *arg) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1990 | { |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1991 | lockdep_assert_held(&ar->conf_mutex); |
| 1992 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1993 | memset(arg, 0, sizeof(*arg)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1994 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1995 | ath10k_peer_assoc_h_basic(ar, vif, sta, arg); |
| 1996 | ath10k_peer_assoc_h_crypto(ar, vif, arg); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1997 | ath10k_peer_assoc_h_rates(ar, sta, arg); |
| 1998 | ath10k_peer_assoc_h_ht(ar, sta, arg); |
| 1999 | ath10k_peer_assoc_h_vht(ar, sta, arg); |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2000 | ath10k_peer_assoc_h_qos(ar, vif, sta, arg); |
| 2001 | ath10k_peer_assoc_h_phymode(ar, vif, sta, arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2002 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2003 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2004 | } |
| 2005 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2006 | static const u32 ath10k_smps_map[] = { |
| 2007 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, |
| 2008 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, |
| 2009 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, |
| 2010 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, |
| 2011 | }; |
| 2012 | |
| 2013 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, |
| 2014 | const u8 *addr, |
| 2015 | const struct ieee80211_sta_ht_cap *ht_cap) |
| 2016 | { |
| 2017 | int smps; |
| 2018 | |
| 2019 | if (!ht_cap->ht_supported) |
| 2020 | return 0; |
| 2021 | |
| 2022 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; |
| 2023 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 2024 | |
| 2025 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) |
| 2026 | return -EINVAL; |
| 2027 | |
| 2028 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, |
| 2029 | WMI_PEER_SMPS_STATE, |
| 2030 | ath10k_smps_map[smps]); |
| 2031 | } |
| 2032 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2033 | static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, |
| 2034 | struct ieee80211_vif *vif, |
| 2035 | struct ieee80211_sta_vht_cap vht_cap) |
| 2036 | { |
| 2037 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2038 | int ret; |
| 2039 | u32 param; |
| 2040 | u32 value; |
| 2041 | |
| 2042 | if (!(ar->vht_cap_info & |
| 2043 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 2044 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | |
| 2045 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 2046 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 2047 | return 0; |
| 2048 | |
| 2049 | param = ar->wmi.vdev_param->txbf; |
| 2050 | value = 0; |
| 2051 | |
| 2052 | if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED)) |
| 2053 | return 0; |
| 2054 | |
| 2055 | /* The following logic is correct. If a remote STA advertises support |
| 2056 | * for being a beamformer then we should enable us being a beamformee. |
| 2057 | */ |
| 2058 | |
| 2059 | if (ar->vht_cap_info & |
| 2060 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 2061 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 2062 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) |
| 2063 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2064 | |
| 2065 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) |
| 2066 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; |
| 2067 | } |
| 2068 | |
| 2069 | if (ar->vht_cap_info & |
| 2070 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 2071 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 2072 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) |
| 2073 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2074 | |
| 2075 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) |
| 2076 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; |
| 2077 | } |
| 2078 | |
| 2079 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE) |
| 2080 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2081 | |
| 2082 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER) |
| 2083 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2084 | |
| 2085 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value); |
| 2086 | if (ret) { |
| 2087 | ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n", |
| 2088 | value, ret); |
| 2089 | return ret; |
| 2090 | } |
| 2091 | |
| 2092 | return 0; |
| 2093 | } |
| 2094 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2095 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
| 2096 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, |
| 2097 | struct ieee80211_vif *vif, |
| 2098 | struct ieee80211_bss_conf *bss_conf) |
| 2099 | { |
| 2100 | struct ath10k *ar = hw->priv; |
| 2101 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2102 | struct ieee80211_sta_ht_cap ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2103 | struct ieee80211_sta_vht_cap vht_cap; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2104 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2105 | struct ieee80211_sta *ap_sta; |
| 2106 | int ret; |
| 2107 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2108 | lockdep_assert_held(&ar->conf_mutex); |
| 2109 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2110 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", |
| 2111 | arvif->vdev_id, arvif->bssid, arvif->aid); |
| 2112 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2113 | rcu_read_lock(); |
| 2114 | |
| 2115 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 2116 | if (!ap_sta) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2117 | ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2118 | bss_conf->bssid, arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2119 | rcu_read_unlock(); |
| 2120 | return; |
| 2121 | } |
| 2122 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2123 | /* ap_sta must be accessed only within rcu section which must be left |
| 2124 | * before calling ath10k_setup_peer_smps() which might sleep. */ |
| 2125 | ht_cap = ap_sta->ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2126 | vht_cap = ap_sta->vht_cap; |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2127 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2128 | ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2129 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2130 | ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2131 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2132 | rcu_read_unlock(); |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | rcu_read_unlock(); |
| 2137 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2138 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2139 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2140 | ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2141 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2142 | return; |
| 2143 | } |
| 2144 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2145 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
| 2146 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2147 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2148 | arvif->vdev_id, ret); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2149 | return; |
| 2150 | } |
| 2151 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2152 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2153 | if (ret) { |
| 2154 | ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n", |
| 2155 | arvif->vdev_id, bss_conf->bssid, ret); |
| 2156 | return; |
| 2157 | } |
| 2158 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2159 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2160 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
| 2161 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); |
| 2162 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2163 | WARN_ON(arvif->is_up); |
| 2164 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2165 | arvif->aid = bss_conf->aid; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 2166 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2167 | |
| 2168 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); |
| 2169 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2170 | ath10k_warn(ar, "failed to set vdev %d up: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2171 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2172 | return; |
| 2173 | } |
| 2174 | |
| 2175 | arvif->is_up = true; |
Michal Kazior | 0a987fb | 2015-02-13 13:30:15 +0100 | [diff] [blame] | 2176 | |
| 2177 | /* Workaround: Some firmware revisions (tested with qca6174 |
| 2178 | * WLAN.RM.2.0-00073) have buggy powersave state machine and must be |
| 2179 | * poked with peer param command. |
| 2180 | */ |
| 2181 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid, |
| 2182 | WMI_PEER_DUMMY_VAR, 1); |
| 2183 | if (ret) { |
| 2184 | ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n", |
| 2185 | arvif->bssid, arvif->vdev_id, ret); |
| 2186 | return; |
| 2187 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2188 | } |
| 2189 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2190 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
| 2191 | struct ieee80211_vif *vif) |
| 2192 | { |
| 2193 | struct ath10k *ar = hw->priv; |
| 2194 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2195 | struct ieee80211_sta_vht_cap vht_cap = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2196 | int ret; |
| 2197 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2198 | lockdep_assert_held(&ar->conf_mutex); |
| 2199 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2200 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
| 2201 | arvif->vdev_id, arvif->bssid); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2202 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2203 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2204 | if (ret) |
| 2205 | ath10k_warn(ar, "faield to down vdev %i: %d\n", |
| 2206 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2207 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2208 | arvif->def_wep_key_idx = -1; |
| 2209 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2210 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2211 | if (ret) { |
| 2212 | ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n", |
| 2213 | arvif->vdev_id, ret); |
| 2214 | return; |
| 2215 | } |
| 2216 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2217 | arvif->is_up = false; |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 2218 | |
| 2219 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2220 | } |
| 2221 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2222 | static int ath10k_station_assoc(struct ath10k *ar, |
| 2223 | struct ieee80211_vif *vif, |
| 2224 | struct ieee80211_sta *sta, |
| 2225 | bool reassoc) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2226 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2227 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2228 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2229 | int ret = 0; |
| 2230 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2231 | lockdep_assert_held(&ar->conf_mutex); |
| 2232 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2233 | ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2234 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2235 | ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2236 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2237 | return ret; |
| 2238 | } |
| 2239 | |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 2240 | peer_arg.peer_reassoc = reassoc; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2241 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2242 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2243 | ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2244 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2245 | return ret; |
| 2246 | } |
| 2247 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2248 | /* Re-assoc is run only to update supported rates for given station. It |
| 2249 | * doesn't make much sense to reconfigure the peer completely. |
| 2250 | */ |
| 2251 | if (!reassoc) { |
| 2252 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, |
| 2253 | &sta->ht_cap); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2254 | if (ret) { |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2255 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n", |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2256 | arvif->vdev_id, ret); |
| 2257 | return ret; |
| 2258 | } |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2259 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2260 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
| 2261 | if (ret) { |
| 2262 | ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", |
| 2263 | sta->addr, arvif->vdev_id, ret); |
| 2264 | return ret; |
| 2265 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2266 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2267 | if (!sta->wme) { |
| 2268 | arvif->num_legacy_stations++; |
| 2269 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 2270 | if (ret) { |
| 2271 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
| 2272 | arvif->vdev_id, ret); |
| 2273 | return ret; |
| 2274 | } |
| 2275 | } |
| 2276 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2277 | /* Plumb cached keys only for static WEP */ |
| 2278 | if (arvif->def_wep_key_idx != -1) { |
| 2279 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); |
| 2280 | if (ret) { |
| 2281 | ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", |
| 2282 | arvif->vdev_id, ret); |
| 2283 | return ret; |
| 2284 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2285 | } |
| 2286 | } |
| 2287 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2288 | return ret; |
| 2289 | } |
| 2290 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2291 | static int ath10k_station_disassoc(struct ath10k *ar, |
| 2292 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2293 | struct ieee80211_sta *sta) |
| 2294 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2295 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2296 | int ret = 0; |
| 2297 | |
| 2298 | lockdep_assert_held(&ar->conf_mutex); |
| 2299 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2300 | if (!sta->wme) { |
| 2301 | arvif->num_legacy_stations--; |
| 2302 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 2303 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2304 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2305 | arvif->vdev_id, ret); |
| 2306 | return ret; |
| 2307 | } |
| 2308 | } |
| 2309 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2310 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
| 2311 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2312 | ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 2313 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2314 | return ret; |
| 2315 | } |
| 2316 | |
| 2317 | return ret; |
| 2318 | } |
| 2319 | |
| 2320 | /**************/ |
| 2321 | /* Regulatory */ |
| 2322 | /**************/ |
| 2323 | |
| 2324 | static int ath10k_update_channel_list(struct ath10k *ar) |
| 2325 | { |
| 2326 | struct ieee80211_hw *hw = ar->hw; |
| 2327 | struct ieee80211_supported_band **bands; |
| 2328 | enum ieee80211_band band; |
| 2329 | struct ieee80211_channel *channel; |
| 2330 | struct wmi_scan_chan_list_arg arg = {0}; |
| 2331 | struct wmi_channel_arg *ch; |
| 2332 | bool passive; |
| 2333 | int len; |
| 2334 | int ret; |
| 2335 | int i; |
| 2336 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2337 | lockdep_assert_held(&ar->conf_mutex); |
| 2338 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2339 | bands = hw->wiphy->bands; |
| 2340 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2341 | if (!bands[band]) |
| 2342 | continue; |
| 2343 | |
| 2344 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 2345 | if (bands[band]->channels[i].flags & |
| 2346 | IEEE80211_CHAN_DISABLED) |
| 2347 | continue; |
| 2348 | |
| 2349 | arg.n_channels++; |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; |
| 2354 | arg.channels = kzalloc(len, GFP_KERNEL); |
| 2355 | if (!arg.channels) |
| 2356 | return -ENOMEM; |
| 2357 | |
| 2358 | ch = arg.channels; |
| 2359 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2360 | if (!bands[band]) |
| 2361 | continue; |
| 2362 | |
| 2363 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 2364 | channel = &bands[band]->channels[i]; |
| 2365 | |
| 2366 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 2367 | continue; |
| 2368 | |
| 2369 | ch->allow_ht = true; |
| 2370 | |
| 2371 | /* FIXME: when should we really allow VHT? */ |
| 2372 | ch->allow_vht = true; |
| 2373 | |
| 2374 | ch->allow_ibss = |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2375 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2376 | |
| 2377 | ch->ht40plus = |
| 2378 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); |
| 2379 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 2380 | ch->chan_radar = |
| 2381 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
| 2382 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2383 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2384 | ch->passive = passive; |
| 2385 | |
| 2386 | ch->freq = channel->center_freq; |
Michal Kazior | 2d66721 | 2014-09-18 15:21:21 +0200 | [diff] [blame] | 2387 | ch->band_center_freq1 = channel->center_freq; |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 2388 | ch->min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 2389 | ch->max_power = channel->max_power * 2; |
| 2390 | ch->max_reg_power = channel->max_reg_power * 2; |
| 2391 | ch->max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2392 | ch->reg_class_id = 0; /* FIXME */ |
| 2393 | |
| 2394 | /* FIXME: why use only legacy modes, why not any |
| 2395 | * HT/VHT modes? Would that even make any |
| 2396 | * difference? */ |
| 2397 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 2398 | ch->mode = MODE_11G; |
| 2399 | else |
| 2400 | ch->mode = MODE_11A; |
| 2401 | |
| 2402 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) |
| 2403 | continue; |
| 2404 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2405 | ath10k_dbg(ar, ATH10K_DBG_WMI, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2406 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
| 2407 | ch - arg.channels, arg.n_channels, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2408 | ch->freq, ch->max_power, ch->max_reg_power, |
| 2409 | ch->max_antenna_gain, ch->mode); |
| 2410 | |
| 2411 | ch++; |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | ret = ath10k_wmi_scan_chan_list(ar, &arg); |
| 2416 | kfree(arg.channels); |
| 2417 | |
| 2418 | return ret; |
| 2419 | } |
| 2420 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2421 | static enum wmi_dfs_region |
| 2422 | ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region) |
| 2423 | { |
| 2424 | switch (dfs_region) { |
| 2425 | case NL80211_DFS_UNSET: |
| 2426 | return WMI_UNINIT_DFS_DOMAIN; |
| 2427 | case NL80211_DFS_FCC: |
| 2428 | return WMI_FCC_DFS_DOMAIN; |
| 2429 | case NL80211_DFS_ETSI: |
| 2430 | return WMI_ETSI_DFS_DOMAIN; |
| 2431 | case NL80211_DFS_JP: |
| 2432 | return WMI_MKK4_DFS_DOMAIN; |
| 2433 | } |
| 2434 | return WMI_UNINIT_DFS_DOMAIN; |
| 2435 | } |
| 2436 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2437 | static void ath10k_regd_update(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2438 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2439 | struct reg_dmn_pair_mapping *regpair; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2440 | int ret; |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2441 | enum wmi_dfs_region wmi_dfs_reg; |
| 2442 | enum nl80211_dfs_regions nl_dfs_reg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2443 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2444 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2445 | |
| 2446 | ret = ath10k_update_channel_list(ar); |
| 2447 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2448 | ath10k_warn(ar, "failed to update channel list: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2449 | |
| 2450 | regpair = ar->ath_common.regulatory.regpair; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2451 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2452 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
| 2453 | nl_dfs_reg = ar->dfs_detector->region; |
| 2454 | wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg); |
| 2455 | } else { |
| 2456 | wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN; |
| 2457 | } |
| 2458 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2459 | /* Target allows setting up per-band regdomain but ath_common provides |
| 2460 | * a combined one only */ |
| 2461 | ret = ath10k_wmi_pdev_set_regdomain(ar, |
Kalle Valo | ef8c001 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 2462 | regpair->reg_domain, |
| 2463 | regpair->reg_domain, /* 2ghz */ |
| 2464 | regpair->reg_domain, /* 5ghz */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2465 | regpair->reg_2ghz_ctl, |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2466 | regpair->reg_5ghz_ctl, |
| 2467 | wmi_dfs_reg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2468 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2469 | ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret); |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2470 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2471 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2472 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
| 2473 | struct regulatory_request *request) |
| 2474 | { |
| 2475 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 2476 | struct ath10k *ar = hw->priv; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2477 | bool result; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2478 | |
| 2479 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); |
| 2480 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2481 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2482 | ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2483 | request->dfs_region); |
| 2484 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, |
| 2485 | request->dfs_region); |
| 2486 | if (!result) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2487 | ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n", |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2488 | request->dfs_region); |
| 2489 | } |
| 2490 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2491 | mutex_lock(&ar->conf_mutex); |
| 2492 | if (ar->state == ATH10K_STATE_ON) |
| 2493 | ath10k_regd_update(ar); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2494 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | /***************/ |
| 2498 | /* TX handlers */ |
| 2499 | /***************/ |
| 2500 | |
Michal Kazior | 42c3aa6 | 2013-10-02 11:03:38 +0200 | [diff] [blame] | 2501 | static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr) |
| 2502 | { |
| 2503 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 2504 | return HTT_DATA_TX_EXT_TID_MGMT; |
| 2505 | |
| 2506 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 2507 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 2508 | |
| 2509 | if (!is_unicast_ether_addr(ieee80211_get_DA(hdr))) |
| 2510 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 2511 | |
| 2512 | return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 2513 | } |
| 2514 | |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 2515 | static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif) |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2516 | { |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 2517 | if (vif) |
| 2518 | return ath10k_vif_to_arvif(vif)->vdev_id; |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2519 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 2520 | if (ar->monitor_started) |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2521 | return ar->monitor_vdev_id; |
| 2522 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2523 | ath10k_warn(ar, "failed to resolve vdev id\n"); |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2524 | return 0; |
| 2525 | } |
| 2526 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2527 | static enum ath10k_hw_txrx_mode |
| 2528 | ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif, |
| 2529 | struct sk_buff *skb) |
| 2530 | { |
| 2531 | const struct ieee80211_hdr *hdr = (void *)skb->data; |
| 2532 | __le16 fc = hdr->frame_control; |
| 2533 | |
| 2534 | if (!vif || vif->type == NL80211_IFTYPE_MONITOR) |
| 2535 | return ATH10K_HW_TXRX_RAW; |
| 2536 | |
| 2537 | if (ieee80211_is_mgmt(fc)) |
| 2538 | return ATH10K_HW_TXRX_MGMT; |
| 2539 | |
| 2540 | /* Workaround: |
| 2541 | * |
| 2542 | * NullFunc frames are mostly used to ping if a client or AP are still |
| 2543 | * reachable and responsive. This implies tx status reports must be |
| 2544 | * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can |
| 2545 | * come to a conclusion that the other end disappeared and tear down |
| 2546 | * BSS connection or it can never disconnect from BSS/client (which is |
| 2547 | * the case). |
| 2548 | * |
| 2549 | * Firmware with HTT older than 3.0 delivers incorrect tx status for |
| 2550 | * NullFunc frames to driver. However there's a HTT Mgmt Tx command |
| 2551 | * which seems to deliver correct tx reports for NullFunc frames. The |
| 2552 | * downside of using it is it ignores client powersave state so it can |
| 2553 | * end up disconnecting sleeping clients in AP mode. It should fix STA |
| 2554 | * mode though because AP don't sleep. |
| 2555 | */ |
| 2556 | if (ar->htt.target_version_major < 3 && |
| 2557 | (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) && |
| 2558 | !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features)) |
| 2559 | return ATH10K_HW_TXRX_MGMT; |
| 2560 | |
| 2561 | return ATH10K_HW_TXRX_NATIVE_WIFI; |
| 2562 | } |
| 2563 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2564 | /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS |
| 2565 | * Control in the header. |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2566 | */ |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2567 | static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2568 | { |
| 2569 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2570 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2571 | u8 *qos_ctl; |
| 2572 | |
| 2573 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 2574 | return; |
| 2575 | |
| 2576 | qos_ctl = ieee80211_get_qos_ctl(hdr); |
Michal Kazior | ba0ccd7 | 2013-07-22 14:25:28 +0200 | [diff] [blame] | 2577 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
| 2578 | skb->data, (void *)qos_ctl - (void *)skb->data); |
| 2579 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2580 | |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 2581 | /* Some firmware revisions don't handle sending QoS NullFunc well. |
| 2582 | * These frames are mainly used for CQM purposes so it doesn't really |
| 2583 | * matter whether QoS NullFunc or NullFunc are sent. |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2584 | */ |
Michal Kazior | bf0a26d | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 2585 | hdr = (void *)skb->data; |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 2586 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2587 | cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 2588 | |
| 2589 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2590 | } |
| 2591 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2592 | static void ath10k_tx_h_8023(struct sk_buff *skb) |
| 2593 | { |
| 2594 | struct ieee80211_hdr *hdr; |
| 2595 | struct rfc1042_hdr *rfc1042; |
| 2596 | struct ethhdr *eth; |
| 2597 | size_t hdrlen; |
| 2598 | u8 da[ETH_ALEN]; |
| 2599 | u8 sa[ETH_ALEN]; |
| 2600 | __be16 type; |
| 2601 | |
| 2602 | hdr = (void *)skb->data; |
| 2603 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 2604 | rfc1042 = (void *)skb->data + hdrlen; |
| 2605 | |
| 2606 | ether_addr_copy(da, ieee80211_get_DA(hdr)); |
| 2607 | ether_addr_copy(sa, ieee80211_get_SA(hdr)); |
| 2608 | type = rfc1042->snap_type; |
| 2609 | |
| 2610 | skb_pull(skb, hdrlen + sizeof(*rfc1042)); |
| 2611 | skb_push(skb, sizeof(*eth)); |
| 2612 | |
| 2613 | eth = (void *)skb->data; |
| 2614 | ether_addr_copy(eth->h_dest, da); |
| 2615 | ether_addr_copy(eth->h_source, sa); |
| 2616 | eth->h_proto = type; |
| 2617 | } |
| 2618 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2619 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, |
| 2620 | struct ieee80211_vif *vif, |
| 2621 | struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2622 | { |
| 2623 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2624 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2625 | |
| 2626 | /* This is case only for P2P_GO */ |
| 2627 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP || |
| 2628 | arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) |
| 2629 | return; |
| 2630 | |
| 2631 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { |
| 2632 | spin_lock_bh(&ar->data_lock); |
| 2633 | if (arvif->u.ap.noa_data) |
| 2634 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, |
| 2635 | GFP_ATOMIC)) |
| 2636 | memcpy(skb_put(skb, arvif->u.ap.noa_len), |
| 2637 | arvif->u.ap.noa_data, |
| 2638 | arvif->u.ap.noa_len); |
| 2639 | spin_unlock_bh(&ar->data_lock); |
| 2640 | } |
| 2641 | } |
| 2642 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 2643 | static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar) |
| 2644 | { |
| 2645 | /* FIXME: Not really sure since when the behaviour changed. At some |
| 2646 | * point new firmware stopped requiring creation of peer entries for |
| 2647 | * offchannel tx (and actually creating them causes issues with wmi-htc |
| 2648 | * tx credit replenishment and reliability). Assuming it's at least 3.4 |
| 2649 | * because that's when the `freq` was introduced to TX_FRM HTT command. |
| 2650 | */ |
| 2651 | return !(ar->htt.target_version_major >= 3 && |
| 2652 | ar->htt.target_version_minor >= 4); |
| 2653 | } |
| 2654 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2655 | static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2656 | { |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2657 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2658 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2659 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2660 | spin_lock_bh(&ar->data_lock); |
| 2661 | |
| 2662 | if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) { |
| 2663 | ath10k_warn(ar, "wmi mgmt tx queue is full\n"); |
| 2664 | ret = -ENOSPC; |
| 2665 | goto unlock; |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 2666 | } |
| 2667 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2668 | __skb_queue_tail(q, skb); |
| 2669 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); |
| 2670 | |
| 2671 | unlock: |
| 2672 | spin_unlock_bh(&ar->data_lock); |
| 2673 | |
| 2674 | return ret; |
| 2675 | } |
| 2676 | |
| 2677 | static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb) |
| 2678 | { |
| 2679 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
| 2680 | struct ath10k_htt *htt = &ar->htt; |
| 2681 | int ret = 0; |
| 2682 | |
| 2683 | switch (cb->txmode) { |
| 2684 | case ATH10K_HW_TXRX_RAW: |
| 2685 | case ATH10K_HW_TXRX_NATIVE_WIFI: |
| 2686 | case ATH10K_HW_TXRX_ETHERNET: |
| 2687 | ret = ath10k_htt_tx(htt, skb); |
| 2688 | break; |
| 2689 | case ATH10K_HW_TXRX_MGMT: |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2690 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2691 | ar->fw_features)) |
| 2692 | ret = ath10k_mac_tx_wmi_mgmt(ar, skb); |
| 2693 | else if (ar->htt.target_version_major >= 3) |
| 2694 | ret = ath10k_htt_tx(htt, skb); |
| 2695 | else |
| 2696 | ret = ath10k_htt_mgmt_tx(htt, skb); |
| 2697 | break; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2698 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2699 | |
| 2700 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2701 | ath10k_warn(ar, "failed to transmit packet, dropping: %d\n", |
| 2702 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2703 | ieee80211_free_txskb(ar->hw, skb); |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | void ath10k_offchan_tx_purge(struct ath10k *ar) |
| 2708 | { |
| 2709 | struct sk_buff *skb; |
| 2710 | |
| 2711 | for (;;) { |
| 2712 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 2713 | if (!skb) |
| 2714 | break; |
| 2715 | |
| 2716 | ieee80211_free_txskb(ar->hw, skb); |
| 2717 | } |
| 2718 | } |
| 2719 | |
| 2720 | void ath10k_offchan_tx_work(struct work_struct *work) |
| 2721 | { |
| 2722 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); |
| 2723 | struct ath10k_peer *peer; |
| 2724 | struct ieee80211_hdr *hdr; |
| 2725 | struct sk_buff *skb; |
| 2726 | const u8 *peer_addr; |
| 2727 | int vdev_id; |
| 2728 | int ret; |
| 2729 | |
| 2730 | /* FW requirement: We must create a peer before FW will send out |
| 2731 | * an offchannel frame. Otherwise the frame will be stuck and |
| 2732 | * never transmitted. We delete the peer upon tx completion. |
| 2733 | * It is unlikely that a peer for offchannel tx will already be |
| 2734 | * present. However it may be in some rare cases so account for that. |
| 2735 | * Otherwise we might remove a legitimate peer and break stuff. */ |
| 2736 | |
| 2737 | for (;;) { |
| 2738 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 2739 | if (!skb) |
| 2740 | break; |
| 2741 | |
| 2742 | mutex_lock(&ar->conf_mutex); |
| 2743 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2744 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2745 | skb); |
| 2746 | |
| 2747 | hdr = (struct ieee80211_hdr *)skb->data; |
| 2748 | peer_addr = ieee80211_get_DA(hdr); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2749 | vdev_id = ATH10K_SKB_CB(skb)->vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2750 | |
| 2751 | spin_lock_bh(&ar->data_lock); |
| 2752 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); |
| 2753 | spin_unlock_bh(&ar->data_lock); |
| 2754 | |
| 2755 | if (peer) |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2756 | /* FIXME: should this use ath10k_warn()? */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2757 | ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2758 | peer_addr, vdev_id); |
| 2759 | |
| 2760 | if (!peer) { |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 2761 | ret = ath10k_peer_create(ar, vdev_id, peer_addr, |
| 2762 | WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2763 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2764 | ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2765 | peer_addr, vdev_id, ret); |
| 2766 | } |
| 2767 | |
| 2768 | spin_lock_bh(&ar->data_lock); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 2769 | reinit_completion(&ar->offchan_tx_completed); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2770 | ar->offchan_tx_skb = skb; |
| 2771 | spin_unlock_bh(&ar->data_lock); |
| 2772 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2773 | ath10k_mac_tx(ar, skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2774 | |
| 2775 | ret = wait_for_completion_timeout(&ar->offchan_tx_completed, |
| 2776 | 3 * HZ); |
Nicholas Mc Guire | 38e2a64 | 2015-01-08 13:27:34 +0100 | [diff] [blame] | 2777 | if (ret == 0) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2778 | ath10k_warn(ar, "timed out waiting for offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2779 | skb); |
| 2780 | |
| 2781 | if (!peer) { |
| 2782 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); |
| 2783 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2784 | ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2785 | peer_addr, vdev_id, ret); |
| 2786 | } |
| 2787 | |
| 2788 | mutex_unlock(&ar->conf_mutex); |
| 2789 | } |
| 2790 | } |
| 2791 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2792 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
| 2793 | { |
| 2794 | struct sk_buff *skb; |
| 2795 | |
| 2796 | for (;;) { |
| 2797 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 2798 | if (!skb) |
| 2799 | break; |
| 2800 | |
| 2801 | ieee80211_free_txskb(ar->hw, skb); |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) |
| 2806 | { |
| 2807 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); |
| 2808 | struct sk_buff *skb; |
| 2809 | int ret; |
| 2810 | |
| 2811 | for (;;) { |
| 2812 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 2813 | if (!skb) |
| 2814 | break; |
| 2815 | |
| 2816 | ret = ath10k_wmi_mgmt_tx(ar, skb); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 2817 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2818 | ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 2819 | ret); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 2820 | ieee80211_free_txskb(ar->hw, skb); |
| 2821 | } |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2825 | /************/ |
| 2826 | /* Scanning */ |
| 2827 | /************/ |
| 2828 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2829 | void __ath10k_scan_finish(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2830 | { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2831 | lockdep_assert_held(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2832 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2833 | switch (ar->scan.state) { |
| 2834 | case ATH10K_SCAN_IDLE: |
| 2835 | break; |
| 2836 | case ATH10K_SCAN_RUNNING: |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2837 | if (ar->scan.is_roc) |
| 2838 | ieee80211_remain_on_channel_expired(ar->hw); |
John W. Linville | f6eaf1e | 2015-01-12 16:07:02 -0500 | [diff] [blame] | 2839 | /* fall through */ |
Michal Kazior | 7305d3e | 2014-11-24 14:58:33 +0100 | [diff] [blame] | 2840 | case ATH10K_SCAN_ABORTING: |
| 2841 | if (!ar->scan.is_roc) |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2842 | ieee80211_scan_completed(ar->hw, |
| 2843 | (ar->scan.state == |
| 2844 | ATH10K_SCAN_ABORTING)); |
| 2845 | /* fall through */ |
| 2846 | case ATH10K_SCAN_STARTING: |
| 2847 | ar->scan.state = ATH10K_SCAN_IDLE; |
| 2848 | ar->scan_channel = NULL; |
| 2849 | ath10k_offchan_tx_purge(ar); |
| 2850 | cancel_delayed_work(&ar->scan.timeout); |
| 2851 | complete_all(&ar->scan.completed); |
| 2852 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2853 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2854 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2855 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2856 | void ath10k_scan_finish(struct ath10k *ar) |
| 2857 | { |
| 2858 | spin_lock_bh(&ar->data_lock); |
| 2859 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2860 | spin_unlock_bh(&ar->data_lock); |
| 2861 | } |
| 2862 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2863 | static int ath10k_scan_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2864 | { |
| 2865 | struct wmi_stop_scan_arg arg = { |
| 2866 | .req_id = 1, /* FIXME */ |
| 2867 | .req_type = WMI_SCAN_STOP_ONE, |
| 2868 | .u.scan_id = ATH10K_SCAN_ID, |
| 2869 | }; |
| 2870 | int ret; |
| 2871 | |
| 2872 | lockdep_assert_held(&ar->conf_mutex); |
| 2873 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2874 | ret = ath10k_wmi_stop_scan(ar, &arg); |
| 2875 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2876 | ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2877 | goto out; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2878 | } |
| 2879 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2880 | ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2881 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2882 | ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2883 | ret = -ETIMEDOUT; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2884 | } else if (ret > 0) { |
| 2885 | ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2886 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2887 | |
| 2888 | out: |
| 2889 | /* Scan state should be updated upon scan completion but in case |
| 2890 | * firmware fails to deliver the event (for whatever reason) it is |
| 2891 | * desired to clean up scan state anyway. Firmware may have just |
| 2892 | * dropped the scan completion event delivery due to transport pipe |
| 2893 | * being overflown with data and/or it can recover on its own before |
| 2894 | * next scan request is submitted. |
| 2895 | */ |
| 2896 | spin_lock_bh(&ar->data_lock); |
| 2897 | if (ar->scan.state != ATH10K_SCAN_IDLE) |
| 2898 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2899 | spin_unlock_bh(&ar->data_lock); |
| 2900 | |
| 2901 | return ret; |
| 2902 | } |
| 2903 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2904 | static void ath10k_scan_abort(struct ath10k *ar) |
| 2905 | { |
| 2906 | int ret; |
| 2907 | |
| 2908 | lockdep_assert_held(&ar->conf_mutex); |
| 2909 | |
| 2910 | spin_lock_bh(&ar->data_lock); |
| 2911 | |
| 2912 | switch (ar->scan.state) { |
| 2913 | case ATH10K_SCAN_IDLE: |
| 2914 | /* This can happen if timeout worker kicked in and called |
| 2915 | * abortion while scan completion was being processed. |
| 2916 | */ |
| 2917 | break; |
| 2918 | case ATH10K_SCAN_STARTING: |
| 2919 | case ATH10K_SCAN_ABORTING: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2920 | ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n", |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2921 | ath10k_scan_state_str(ar->scan.state), |
| 2922 | ar->scan.state); |
| 2923 | break; |
| 2924 | case ATH10K_SCAN_RUNNING: |
| 2925 | ar->scan.state = ATH10K_SCAN_ABORTING; |
| 2926 | spin_unlock_bh(&ar->data_lock); |
| 2927 | |
| 2928 | ret = ath10k_scan_stop(ar); |
| 2929 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2930 | ath10k_warn(ar, "failed to abort scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2931 | |
| 2932 | spin_lock_bh(&ar->data_lock); |
| 2933 | break; |
| 2934 | } |
| 2935 | |
| 2936 | spin_unlock_bh(&ar->data_lock); |
| 2937 | } |
| 2938 | |
| 2939 | void ath10k_scan_timeout_work(struct work_struct *work) |
| 2940 | { |
| 2941 | struct ath10k *ar = container_of(work, struct ath10k, |
| 2942 | scan.timeout.work); |
| 2943 | |
| 2944 | mutex_lock(&ar->conf_mutex); |
| 2945 | ath10k_scan_abort(ar); |
| 2946 | mutex_unlock(&ar->conf_mutex); |
| 2947 | } |
| 2948 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2949 | static int ath10k_start_scan(struct ath10k *ar, |
| 2950 | const struct wmi_start_scan_arg *arg) |
| 2951 | { |
| 2952 | int ret; |
| 2953 | |
| 2954 | lockdep_assert_held(&ar->conf_mutex); |
| 2955 | |
| 2956 | ret = ath10k_wmi_start_scan(ar, arg); |
| 2957 | if (ret) |
| 2958 | return ret; |
| 2959 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2960 | ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); |
| 2961 | if (ret == 0) { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2962 | ret = ath10k_scan_stop(ar); |
| 2963 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2964 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2965 | |
| 2966 | return -ETIMEDOUT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2967 | } |
| 2968 | |
Ben Greear | 2f9eec0 | 2015-02-15 16:50:38 +0200 | [diff] [blame] | 2969 | /* If we failed to start the scan, return error code at |
| 2970 | * this point. This is probably due to some issue in the |
| 2971 | * firmware, but no need to wedge the driver due to that... |
| 2972 | */ |
| 2973 | spin_lock_bh(&ar->data_lock); |
| 2974 | if (ar->scan.state == ATH10K_SCAN_IDLE) { |
| 2975 | spin_unlock_bh(&ar->data_lock); |
| 2976 | return -EINVAL; |
| 2977 | } |
| 2978 | spin_unlock_bh(&ar->data_lock); |
| 2979 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2980 | /* Add a 200ms margin to account for event/command processing */ |
| 2981 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
| 2982 | msecs_to_jiffies(arg->max_scan_time+200)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2983 | return 0; |
| 2984 | } |
| 2985 | |
| 2986 | /**********************/ |
| 2987 | /* mac80211 callbacks */ |
| 2988 | /**********************/ |
| 2989 | |
| 2990 | static void ath10k_tx(struct ieee80211_hw *hw, |
| 2991 | struct ieee80211_tx_control *control, |
| 2992 | struct sk_buff *skb) |
| 2993 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2994 | struct ath10k *ar = hw->priv; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2995 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2996 | struct ieee80211_vif *vif = info->control.vif; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2997 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 2998 | __le16 fc = hdr->frame_control; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2999 | |
| 3000 | /* We should disable CCK RATE due to P2P */ |
| 3001 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3002 | ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3003 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3004 | ATH10K_SKB_CB(skb)->htt.is_offchan = false; |
Michal Kazior | 6fcafef | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3005 | ATH10K_SKB_CB(skb)->htt.freq = 0; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3006 | ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr); |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 3007 | ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif); |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3008 | ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, skb); |
| 3009 | ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3010 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3011 | switch (ATH10K_SKB_CB(skb)->txmode) { |
| 3012 | case ATH10K_HW_TXRX_MGMT: |
| 3013 | case ATH10K_HW_TXRX_NATIVE_WIFI: |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3014 | ath10k_tx_h_nwifi(hw, skb); |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3015 | ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb); |
| 3016 | ath10k_tx_h_seq_no(vif, skb); |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3017 | break; |
| 3018 | case ATH10K_HW_TXRX_ETHERNET: |
| 3019 | ath10k_tx_h_8023(skb); |
| 3020 | break; |
| 3021 | case ATH10K_HW_TXRX_RAW: |
| 3022 | /* FIXME: Packet injection isn't implemented. It should be |
| 3023 | * doable with firmware 10.2 on qca988x. |
| 3024 | */ |
| 3025 | WARN_ON_ONCE(1); |
| 3026 | ieee80211_free_txskb(hw, skb); |
| 3027 | return; |
Michal Kazior | cf84bd4 | 2013-07-16 11:04:54 +0200 | [diff] [blame] | 3028 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3029 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3030 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { |
| 3031 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3032 | ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3033 | ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3034 | spin_unlock_bh(&ar->data_lock); |
| 3035 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3036 | if (ath10k_mac_need_offchan_tx_work(ar)) { |
| 3037 | ATH10K_SKB_CB(skb)->htt.freq = 0; |
| 3038 | ATH10K_SKB_CB(skb)->htt.is_offchan = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3039 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3040 | ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n", |
| 3041 | skb); |
| 3042 | |
| 3043 | skb_queue_tail(&ar->offchan_tx_queue, skb); |
| 3044 | ieee80211_queue_work(hw, &ar->offchan_tx_work); |
| 3045 | return; |
| 3046 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3047 | } |
| 3048 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3049 | ath10k_mac_tx(ar, skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3050 | } |
| 3051 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3052 | /* Must not be called with conf_mutex held as workers can use that also. */ |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 3053 | void ath10k_drain_tx(struct ath10k *ar) |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3054 | { |
| 3055 | /* make sure rcu-protected mac80211 tx path itself is drained */ |
| 3056 | synchronize_net(); |
| 3057 | |
| 3058 | ath10k_offchan_tx_purge(ar); |
| 3059 | ath10k_mgmt_over_wmi_tx_purge(ar); |
| 3060 | |
| 3061 | cancel_work_sync(&ar->offchan_tx_work); |
| 3062 | cancel_work_sync(&ar->wmi_mgmt_tx_work); |
| 3063 | } |
| 3064 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3065 | void ath10k_halt(struct ath10k *ar) |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3066 | { |
Michal Kazior | d9bc4b9 | 2014-04-23 19:30:06 +0300 | [diff] [blame] | 3067 | struct ath10k_vif *arvif; |
| 3068 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3069 | lockdep_assert_held(&ar->conf_mutex); |
| 3070 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3071 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 3072 | ar->filter_flags = 0; |
| 3073 | ar->monitor = false; |
| 3074 | |
| 3075 | if (ar->monitor_started) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3076 | ath10k_monitor_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3077 | |
| 3078 | ar->monitor_started = false; |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3079 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3080 | ath10k_scan_finish(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3081 | ath10k_peer_cleanup_all(ar); |
| 3082 | ath10k_core_stop(ar); |
| 3083 | ath10k_hif_power_down(ar); |
| 3084 | |
| 3085 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3086 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 3087 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3088 | spin_unlock_bh(&ar->data_lock); |
| 3089 | } |
| 3090 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3091 | static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 3092 | { |
| 3093 | struct ath10k *ar = hw->priv; |
| 3094 | |
| 3095 | mutex_lock(&ar->conf_mutex); |
| 3096 | |
| 3097 | if (ar->cfg_tx_chainmask) { |
| 3098 | *tx_ant = ar->cfg_tx_chainmask; |
| 3099 | *rx_ant = ar->cfg_rx_chainmask; |
| 3100 | } else { |
| 3101 | *tx_ant = ar->supp_tx_chainmask; |
| 3102 | *rx_ant = ar->supp_rx_chainmask; |
| 3103 | } |
| 3104 | |
| 3105 | mutex_unlock(&ar->conf_mutex); |
| 3106 | |
| 3107 | return 0; |
| 3108 | } |
| 3109 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3110 | static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg) |
| 3111 | { |
| 3112 | /* It is not clear that allowing gaps in chainmask |
| 3113 | * is helpful. Probably it will not do what user |
| 3114 | * is hoping for, so warn in that case. |
| 3115 | */ |
| 3116 | if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0) |
| 3117 | return; |
| 3118 | |
| 3119 | ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n", |
| 3120 | dbg, cm); |
| 3121 | } |
| 3122 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3123 | static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant) |
| 3124 | { |
| 3125 | int ret; |
| 3126 | |
| 3127 | lockdep_assert_held(&ar->conf_mutex); |
| 3128 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3129 | ath10k_check_chain_mask(ar, tx_ant, "tx"); |
| 3130 | ath10k_check_chain_mask(ar, rx_ant, "rx"); |
| 3131 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3132 | ar->cfg_tx_chainmask = tx_ant; |
| 3133 | ar->cfg_rx_chainmask = rx_ant; |
| 3134 | |
| 3135 | if ((ar->state != ATH10K_STATE_ON) && |
| 3136 | (ar->state != ATH10K_STATE_RESTARTED)) |
| 3137 | return 0; |
| 3138 | |
| 3139 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask, |
| 3140 | tx_ant); |
| 3141 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3142 | ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n", |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3143 | ret, tx_ant); |
| 3144 | return ret; |
| 3145 | } |
| 3146 | |
| 3147 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask, |
| 3148 | rx_ant); |
| 3149 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3150 | ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n", |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3151 | ret, rx_ant); |
| 3152 | return ret; |
| 3153 | } |
| 3154 | |
| 3155 | return 0; |
| 3156 | } |
| 3157 | |
| 3158 | static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 3159 | { |
| 3160 | struct ath10k *ar = hw->priv; |
| 3161 | int ret; |
| 3162 | |
| 3163 | mutex_lock(&ar->conf_mutex); |
| 3164 | ret = __ath10k_set_antenna(ar, tx_ant, rx_ant); |
| 3165 | mutex_unlock(&ar->conf_mutex); |
| 3166 | return ret; |
| 3167 | } |
| 3168 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3169 | static int ath10k_start(struct ieee80211_hw *hw) |
| 3170 | { |
| 3171 | struct ath10k *ar = hw->priv; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3172 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3173 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3174 | /* |
| 3175 | * This makes sense only when restarting hw. It is harmless to call |
| 3176 | * uncoditionally. This is necessary to make sure no HTT/WMI tx |
| 3177 | * commands will be submitted while restarting. |
| 3178 | */ |
| 3179 | ath10k_drain_tx(ar); |
| 3180 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3181 | mutex_lock(&ar->conf_mutex); |
| 3182 | |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3183 | switch (ar->state) { |
| 3184 | case ATH10K_STATE_OFF: |
| 3185 | ar->state = ATH10K_STATE_ON; |
| 3186 | break; |
| 3187 | case ATH10K_STATE_RESTARTING: |
| 3188 | ath10k_halt(ar); |
| 3189 | ar->state = ATH10K_STATE_RESTARTED; |
| 3190 | break; |
| 3191 | case ATH10K_STATE_ON: |
| 3192 | case ATH10K_STATE_RESTARTED: |
| 3193 | case ATH10K_STATE_WEDGED: |
| 3194 | WARN_ON(1); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3195 | ret = -EINVAL; |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3196 | goto err; |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 3197 | case ATH10K_STATE_UTF: |
| 3198 | ret = -EBUSY; |
| 3199 | goto err; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | ret = ath10k_hif_power_up(ar); |
| 3203 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3204 | ath10k_err(ar, "Could not init hif: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3205 | goto err_off; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3206 | } |
| 3207 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 3208 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3209 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3210 | ath10k_err(ar, "Could not init core: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3211 | goto err_power_down; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3212 | } |
| 3213 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 3214 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3215 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3216 | ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3217 | goto err_core_stop; |
| 3218 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3219 | |
Michal Kazior | c4dd0d0 | 2013-11-13 11:05:10 +0100 | [diff] [blame] | 3220 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3221 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3222 | ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3223 | goto err_core_stop; |
| 3224 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3225 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3226 | if (ar->cfg_tx_chainmask) |
| 3227 | __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, |
| 3228 | ar->cfg_rx_chainmask); |
| 3229 | |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3230 | /* |
| 3231 | * By default FW set ARP frames ac to voice (6). In that case ARP |
| 3232 | * exchange is not working properly for UAPSD enabled AP. ARP requests |
| 3233 | * which arrives with access category 0 are processed by network stack |
| 3234 | * and send back with access category 0, but FW changes access category |
| 3235 | * to 6. Set ARP frames access category to best effort (0) solves |
| 3236 | * this problem. |
| 3237 | */ |
| 3238 | |
| 3239 | ret = ath10k_wmi_pdev_set_param(ar, |
| 3240 | ar->wmi.pdev_param->arp_ac_override, 0); |
| 3241 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3242 | ath10k_warn(ar, "failed to set arp ac override parameter: %d\n", |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3243 | ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3244 | goto err_core_stop; |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3245 | } |
| 3246 | |
Ashok Raj Nagarajan | 575f1c3 | 2015-03-19 16:37:59 +0530 | [diff] [blame] | 3247 | ret = ath10k_wmi_pdev_set_param(ar, |
| 3248 | ar->wmi.pdev_param->ani_enable, 1); |
| 3249 | if (ret) { |
| 3250 | ath10k_warn(ar, "failed to enable ani by default: %d\n", |
| 3251 | ret); |
| 3252 | goto err_core_stop; |
| 3253 | } |
| 3254 | |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 3255 | ar->ani_enabled = true; |
| 3256 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3257 | ar->num_started_vdevs = 0; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3258 | ath10k_regd_update(ar); |
| 3259 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3260 | ath10k_spectral_start(ar); |
Rajkumar Manoharan | 8515b5c | 2015-03-15 20:36:22 +0530 | [diff] [blame] | 3261 | ath10k_thermal_set_throttling(ar); |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3262 | |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3263 | mutex_unlock(&ar->conf_mutex); |
| 3264 | return 0; |
| 3265 | |
| 3266 | err_core_stop: |
| 3267 | ath10k_core_stop(ar); |
| 3268 | |
| 3269 | err_power_down: |
| 3270 | ath10k_hif_power_down(ar); |
| 3271 | |
| 3272 | err_off: |
| 3273 | ar->state = ATH10K_STATE_OFF; |
| 3274 | |
| 3275 | err: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3276 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | c60bdd8 | 2014-01-29 07:26:31 +0100 | [diff] [blame] | 3277 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | static void ath10k_stop(struct ieee80211_hw *hw) |
| 3281 | { |
| 3282 | struct ath10k *ar = hw->priv; |
| 3283 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3284 | ath10k_drain_tx(ar); |
| 3285 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3286 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3287 | if (ar->state != ATH10K_STATE_OFF) { |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3288 | ath10k_halt(ar); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3289 | ar->state = ATH10K_STATE_OFF; |
| 3290 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3291 | mutex_unlock(&ar->conf_mutex); |
| 3292 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3293 | cancel_delayed_work_sync(&ar->scan.timeout); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3294 | cancel_work_sync(&ar->restart_work); |
| 3295 | } |
| 3296 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3297 | static int ath10k_config_ps(struct ath10k *ar) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3298 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3299 | struct ath10k_vif *arvif; |
| 3300 | int ret = 0; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3301 | |
| 3302 | lockdep_assert_held(&ar->conf_mutex); |
| 3303 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3304 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3305 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 3306 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3307 | ath10k_warn(ar, "failed to setup powersave: %d\n", ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3308 | break; |
| 3309 | } |
| 3310 | } |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3311 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3312 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3313 | } |
| 3314 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3315 | static const char *chandef_get_width(enum nl80211_chan_width width) |
| 3316 | { |
| 3317 | switch (width) { |
| 3318 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3319 | return "20 (noht)"; |
| 3320 | case NL80211_CHAN_WIDTH_20: |
| 3321 | return "20"; |
| 3322 | case NL80211_CHAN_WIDTH_40: |
| 3323 | return "40"; |
| 3324 | case NL80211_CHAN_WIDTH_80: |
| 3325 | return "80"; |
| 3326 | case NL80211_CHAN_WIDTH_80P80: |
| 3327 | return "80+80"; |
| 3328 | case NL80211_CHAN_WIDTH_160: |
| 3329 | return "160"; |
| 3330 | case NL80211_CHAN_WIDTH_5: |
| 3331 | return "5"; |
| 3332 | case NL80211_CHAN_WIDTH_10: |
| 3333 | return "10"; |
| 3334 | } |
| 3335 | return "?"; |
| 3336 | } |
| 3337 | |
| 3338 | static void ath10k_config_chan(struct ath10k *ar) |
| 3339 | { |
| 3340 | struct ath10k_vif *arvif; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3341 | int ret; |
| 3342 | |
| 3343 | lockdep_assert_held(&ar->conf_mutex); |
| 3344 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3345 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3346 | "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n", |
| 3347 | ar->chandef.chan->center_freq, |
| 3348 | ar->chandef.center_freq1, |
| 3349 | ar->chandef.center_freq2, |
| 3350 | chandef_get_width(ar->chandef.width)); |
| 3351 | |
| 3352 | /* First stop monitor interface. Some FW versions crash if there's a |
| 3353 | * lone monitor interface. */ |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3354 | if (ar->monitor_started) |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3355 | ath10k_monitor_stop(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3356 | |
| 3357 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3358 | if (!arvif->is_started) |
| 3359 | continue; |
| 3360 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3361 | if (!arvif->is_up) |
| 3362 | continue; |
| 3363 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3364 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 3365 | continue; |
| 3366 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3367 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3368 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3369 | ath10k_warn(ar, "failed to down vdev %d: %d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3370 | arvif->vdev_id, ret); |
| 3371 | continue; |
| 3372 | } |
| 3373 | } |
| 3374 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3375 | /* all vdevs are downed now - attempt to restart and re-up them */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3376 | |
| 3377 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3378 | if (!arvif->is_started) |
| 3379 | continue; |
| 3380 | |
| 3381 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 3382 | continue; |
| 3383 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3384 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 3385 | if (ret) |
| 3386 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 3387 | ret); |
| 3388 | |
| 3389 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 3390 | if (ret) |
| 3391 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 3392 | ret); |
| 3393 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3394 | ret = ath10k_vdev_restart(arvif); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3395 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3396 | ath10k_warn(ar, "failed to restart vdev %d: %d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3397 | arvif->vdev_id, ret); |
| 3398 | continue; |
| 3399 | } |
| 3400 | |
| 3401 | if (!arvif->is_up) |
| 3402 | continue; |
| 3403 | |
| 3404 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 3405 | arvif->bssid); |
| 3406 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3407 | ath10k_warn(ar, "failed to bring vdev up %d: %d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3408 | arvif->vdev_id, ret); |
| 3409 | continue; |
| 3410 | } |
| 3411 | } |
| 3412 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3413 | ath10k_monitor_recalc(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3414 | } |
| 3415 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 3416 | static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower) |
| 3417 | { |
| 3418 | int ret; |
| 3419 | u32 param; |
| 3420 | |
| 3421 | lockdep_assert_held(&ar->conf_mutex); |
| 3422 | |
| 3423 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower); |
| 3424 | |
| 3425 | param = ar->wmi.pdev_param->txpower_limit2g; |
| 3426 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 3427 | if (ret) { |
| 3428 | ath10k_warn(ar, "failed to set 2g txpower %d: %d\n", |
| 3429 | txpower, ret); |
| 3430 | return ret; |
| 3431 | } |
| 3432 | |
| 3433 | param = ar->wmi.pdev_param->txpower_limit5g; |
| 3434 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 3435 | if (ret) { |
| 3436 | ath10k_warn(ar, "failed to set 5g txpower %d: %d\n", |
| 3437 | txpower, ret); |
| 3438 | return ret; |
| 3439 | } |
| 3440 | |
| 3441 | return 0; |
| 3442 | } |
| 3443 | |
| 3444 | static int ath10k_mac_txpower_recalc(struct ath10k *ar) |
| 3445 | { |
| 3446 | struct ath10k_vif *arvif; |
| 3447 | int ret, txpower = -1; |
| 3448 | |
| 3449 | lockdep_assert_held(&ar->conf_mutex); |
| 3450 | |
| 3451 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3452 | WARN_ON(arvif->txpower < 0); |
| 3453 | |
| 3454 | if (txpower == -1) |
| 3455 | txpower = arvif->txpower; |
| 3456 | else |
| 3457 | txpower = min(txpower, arvif->txpower); |
| 3458 | } |
| 3459 | |
| 3460 | if (WARN_ON(txpower == -1)) |
| 3461 | return -EINVAL; |
| 3462 | |
| 3463 | ret = ath10k_mac_txpower_setup(ar, txpower); |
| 3464 | if (ret) { |
| 3465 | ath10k_warn(ar, "failed to setup tx power %d: %d\n", |
| 3466 | txpower, ret); |
| 3467 | return ret; |
| 3468 | } |
| 3469 | |
| 3470 | return 0; |
| 3471 | } |
| 3472 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3473 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
| 3474 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3475 | struct ath10k *ar = hw->priv; |
| 3476 | struct ieee80211_conf *conf = &hw->conf; |
| 3477 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3478 | |
| 3479 | mutex_lock(&ar->conf_mutex); |
| 3480 | |
| 3481 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3482 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3483 | "mac config channel %dMHz flags 0x%x radar %d\n", |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3484 | conf->chandef.chan->center_freq, |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3485 | conf->chandef.chan->flags, |
| 3486 | conf->radar_enabled); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3487 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3488 | spin_lock_bh(&ar->data_lock); |
| 3489 | ar->rx_channel = conf->chandef.chan; |
| 3490 | spin_unlock_bh(&ar->data_lock); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3491 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3492 | ar->radar_enabled = conf->radar_enabled; |
| 3493 | ath10k_recalc_radar_detection(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3494 | |
| 3495 | if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) { |
| 3496 | ar->chandef = conf->chandef; |
| 3497 | ath10k_config_chan(ar); |
| 3498 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3499 | } |
| 3500 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3501 | if (changed & IEEE80211_CONF_CHANGE_PS) |
| 3502 | ath10k_config_ps(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3503 | |
| 3504 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3505 | ar->monitor = conf->flags & IEEE80211_CONF_MONITOR; |
| 3506 | ret = ath10k_monitor_recalc(ar); |
| 3507 | if (ret) |
| 3508 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | mutex_unlock(&ar->conf_mutex); |
| 3512 | return ret; |
| 3513 | } |
| 3514 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3515 | static u32 get_nss_from_chainmask(u16 chain_mask) |
| 3516 | { |
| 3517 | if ((chain_mask & 0x15) == 0x15) |
| 3518 | return 4; |
| 3519 | else if ((chain_mask & 0x7) == 0x7) |
| 3520 | return 3; |
| 3521 | else if ((chain_mask & 0x3) == 0x3) |
| 3522 | return 2; |
| 3523 | return 1; |
| 3524 | } |
| 3525 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3526 | /* |
| 3527 | * TODO: |
| 3528 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, |
| 3529 | * because we will send mgmt frames without CCK. This requirement |
| 3530 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag |
| 3531 | * in the TX packet. |
| 3532 | */ |
| 3533 | static int ath10k_add_interface(struct ieee80211_hw *hw, |
| 3534 | struct ieee80211_vif *vif) |
| 3535 | { |
| 3536 | struct ath10k *ar = hw->priv; |
| 3537 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3538 | enum wmi_sta_powersave_param param; |
| 3539 | int ret = 0; |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 3540 | u32 value; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3541 | int bit; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3542 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3543 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 3544 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
| 3545 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3546 | mutex_lock(&ar->conf_mutex); |
| 3547 | |
Michal Kazior | 0dbd09e | 2013-07-31 10:55:14 +0200 | [diff] [blame] | 3548 | memset(arvif, 0, sizeof(*arvif)); |
| 3549 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3550 | arvif->ar = ar; |
| 3551 | arvif->vif = vif; |
| 3552 | |
Ben Greear | e63b33f | 2013-10-22 14:54:14 -0700 | [diff] [blame] | 3553 | INIT_LIST_HEAD(&arvif->list); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3554 | INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work); |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 3555 | INIT_DELAYED_WORK(&arvif->connection_loss_work, |
| 3556 | ath10k_mac_vif_sta_connection_loss_work); |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3557 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 3558 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3559 | ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3560 | ret = -EBUSY; |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3561 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3562 | } |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3563 | bit = __ffs64(ar->free_vdev_map); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3564 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3565 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n", |
| 3566 | bit, ar->free_vdev_map); |
| 3567 | |
| 3568 | arvif->vdev_id = bit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3569 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3570 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3571 | switch (vif->type) { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 3572 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3573 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 3574 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; |
| 3575 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3576 | case NL80211_IFTYPE_UNSPECIFIED: |
| 3577 | case NL80211_IFTYPE_STATION: |
| 3578 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 3579 | if (vif->p2p) |
| 3580 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; |
| 3581 | break; |
| 3582 | case NL80211_IFTYPE_ADHOC: |
| 3583 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; |
| 3584 | break; |
| 3585 | case NL80211_IFTYPE_AP: |
| 3586 | arvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 3587 | |
| 3588 | if (vif->p2p) |
| 3589 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; |
| 3590 | break; |
| 3591 | case NL80211_IFTYPE_MONITOR: |
| 3592 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; |
| 3593 | break; |
| 3594 | default: |
| 3595 | WARN_ON(1); |
| 3596 | break; |
| 3597 | } |
| 3598 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3599 | /* Some firmware revisions don't wait for beacon tx completion before |
| 3600 | * sending another SWBA event. This could lead to hardware using old |
| 3601 | * (freed) beacon data in some cases, e.g. tx credit starvation |
| 3602 | * combined with missed TBTT. This is very very rare. |
| 3603 | * |
| 3604 | * On non-IOMMU-enabled hosts this could be a possible security issue |
| 3605 | * because hw could beacon some random data on the air. On |
| 3606 | * IOMMU-enabled hosts DMAR faults would occur in most cases and target |
| 3607 | * device would crash. |
| 3608 | * |
| 3609 | * Since there are no beacon tx completions (implicit nor explicit) |
| 3610 | * propagated to host the only workaround for this is to allocate a |
| 3611 | * DMA-coherent buffer for a lifetime of a vif and use it for all |
| 3612 | * beacon tx commands. Worst case for this approach is some beacons may |
| 3613 | * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap. |
| 3614 | */ |
| 3615 | if (vif->type == NL80211_IFTYPE_ADHOC || |
| 3616 | vif->type == NL80211_IFTYPE_AP) { |
| 3617 | arvif->beacon_buf = dma_zalloc_coherent(ar->dev, |
| 3618 | IEEE80211_MAX_FRAME_LEN, |
| 3619 | &arvif->beacon_paddr, |
Rajkumar Manoharan | 82d7aba | 2014-10-10 17:38:27 +0530 | [diff] [blame] | 3620 | GFP_ATOMIC); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3621 | if (!arvif->beacon_buf) { |
| 3622 | ret = -ENOMEM; |
| 3623 | ath10k_warn(ar, "failed to allocate beacon buffer: %d\n", |
| 3624 | ret); |
| 3625 | goto err; |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n", |
| 3630 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, |
| 3631 | arvif->beacon_buf ? "single-buf" : "per-skb"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3632 | |
| 3633 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, |
| 3634 | arvif->vdev_subtype, vif->addr); |
| 3635 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3636 | ath10k_warn(ar, "failed to create WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3637 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3638 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3639 | } |
| 3640 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3641 | ar->free_vdev_map &= ~(1LL << arvif->vdev_id); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3642 | list_add(&arvif->list, &ar->arvifs); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3643 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 3644 | /* It makes no sense to have firmware do keepalives. mac80211 already |
| 3645 | * takes care of this with idle connection polling. |
| 3646 | */ |
| 3647 | ret = ath10k_mac_vif_disable_keepalive(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3648 | if (ret) { |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 3649 | ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3650 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3651 | goto err_vdev_delete; |
| 3652 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3653 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 3654 | arvif->def_wep_key_idx = -1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3655 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3656 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
| 3657 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3658 | ATH10K_HW_TXRX_NATIVE_WIFI); |
Bartosz Markowski | ebc9abd | 2013-10-15 09:26:20 +0200 | [diff] [blame] | 3659 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3660 | if (ret && ret != -EOPNOTSUPP) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3661 | ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3662 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3663 | goto err_vdev_delete; |
| 3664 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3665 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3666 | if (ar->cfg_tx_chainmask) { |
| 3667 | u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
| 3668 | |
| 3669 | vdev_param = ar->wmi.vdev_param->nss; |
| 3670 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 3671 | nss); |
| 3672 | if (ret) { |
| 3673 | ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n", |
| 3674 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, |
| 3675 | ret); |
| 3676 | goto err_vdev_delete; |
| 3677 | } |
| 3678 | } |
| 3679 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3680 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 3681 | ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr, |
| 3682 | WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3683 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3684 | ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3685 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3686 | goto err_vdev_delete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3687 | } |
Marek Puzyniak | cdf0740 | 2013-12-30 09:07:51 +0100 | [diff] [blame] | 3688 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 3689 | ret = ath10k_mac_set_kickout(arvif); |
| 3690 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3691 | ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3692 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 3693 | goto err_peer_delete; |
| 3694 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 3698 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; |
| 3699 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 3700 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 3701 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3702 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3703 | ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3704 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3705 | goto err_peer_delete; |
| 3706 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3707 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3708 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3709 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3710 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3711 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3712 | goto err_peer_delete; |
| 3713 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3714 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3715 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3716 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3717 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3718 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3719 | goto err_peer_delete; |
| 3720 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3721 | } |
| 3722 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 3723 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3724 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3725 | ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n", |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 3726 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3727 | goto err_peer_delete; |
| 3728 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 3729 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 3730 | ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3731 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3732 | ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n", |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 3733 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3734 | goto err_peer_delete; |
| 3735 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 3736 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 3737 | arvif->txpower = vif->bss_conf.txpower; |
| 3738 | ret = ath10k_mac_txpower_recalc(ar); |
| 3739 | if (ret) { |
| 3740 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 3741 | goto err_peer_delete; |
| 3742 | } |
| 3743 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3744 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3745 | return 0; |
| 3746 | |
| 3747 | err_peer_delete: |
| 3748 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 3749 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); |
| 3750 | |
| 3751 | err_vdev_delete: |
| 3752 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3753 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3754 | list_del(&arvif->list); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3755 | |
| 3756 | err: |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3757 | if (arvif->beacon_buf) { |
| 3758 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 3759 | arvif->beacon_buf, arvif->beacon_paddr); |
| 3760 | arvif->beacon_buf = NULL; |
| 3761 | } |
| 3762 | |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3763 | mutex_unlock(&ar->conf_mutex); |
| 3764 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3765 | return ret; |
| 3766 | } |
| 3767 | |
| 3768 | static void ath10k_remove_interface(struct ieee80211_hw *hw, |
| 3769 | struct ieee80211_vif *vif) |
| 3770 | { |
| 3771 | struct ath10k *ar = hw->priv; |
| 3772 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3773 | int ret; |
| 3774 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3775 | cancel_work_sync(&arvif->ap_csa_work); |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 3776 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3777 | |
Sujith Manoharan | 5d011f5 | 2014-11-25 11:47:00 +0530 | [diff] [blame] | 3778 | mutex_lock(&ar->conf_mutex); |
| 3779 | |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 3780 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3781 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 3782 | spin_unlock_bh(&ar->data_lock); |
| 3783 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3784 | ret = ath10k_spectral_vif_stop(arvif); |
| 3785 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3786 | ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3787 | arvif->vdev_id, ret); |
| 3788 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3789 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3790 | list_del(&arvif->list); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3791 | |
| 3792 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 3793 | ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id, |
| 3794 | vif->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3795 | if (ret) |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 3796 | ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3797 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3798 | |
| 3799 | kfree(arvif->u.ap.noa_data); |
| 3800 | } |
| 3801 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3802 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3803 | arvif->vdev_id); |
| 3804 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3805 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 3806 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3807 | ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3808 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3809 | |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 3810 | /* Some firmware revisions don't notify host about self-peer removal |
| 3811 | * until after associated vdev is deleted. |
| 3812 | */ |
| 3813 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 3814 | ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id, |
| 3815 | vif->addr); |
| 3816 | if (ret) |
| 3817 | ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n", |
| 3818 | arvif->vdev_id, ret); |
| 3819 | |
| 3820 | spin_lock_bh(&ar->data_lock); |
| 3821 | ar->num_peers--; |
| 3822 | spin_unlock_bh(&ar->data_lock); |
| 3823 | } |
| 3824 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3825 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
| 3826 | |
| 3827 | mutex_unlock(&ar->conf_mutex); |
| 3828 | } |
| 3829 | |
| 3830 | /* |
| 3831 | * FIXME: Has to be verified. |
| 3832 | */ |
| 3833 | #define SUPPORTED_FILTERS \ |
| 3834 | (FIF_PROMISC_IN_BSS | \ |
| 3835 | FIF_ALLMULTI | \ |
| 3836 | FIF_CONTROL | \ |
| 3837 | FIF_PSPOLL | \ |
| 3838 | FIF_OTHER_BSS | \ |
| 3839 | FIF_BCN_PRBRESP_PROMISC | \ |
| 3840 | FIF_PROBE_REQ | \ |
| 3841 | FIF_FCSFAIL) |
| 3842 | |
| 3843 | static void ath10k_configure_filter(struct ieee80211_hw *hw, |
| 3844 | unsigned int changed_flags, |
| 3845 | unsigned int *total_flags, |
| 3846 | u64 multicast) |
| 3847 | { |
| 3848 | struct ath10k *ar = hw->priv; |
| 3849 | int ret; |
| 3850 | |
| 3851 | mutex_lock(&ar->conf_mutex); |
| 3852 | |
| 3853 | changed_flags &= SUPPORTED_FILTERS; |
| 3854 | *total_flags &= SUPPORTED_FILTERS; |
| 3855 | ar->filter_flags = *total_flags; |
| 3856 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3857 | ret = ath10k_monitor_recalc(ar); |
| 3858 | if (ret) |
| 3859 | ath10k_warn(ar, "failed to recalc montior: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3860 | |
| 3861 | mutex_unlock(&ar->conf_mutex); |
| 3862 | } |
| 3863 | |
| 3864 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, |
| 3865 | struct ieee80211_vif *vif, |
| 3866 | struct ieee80211_bss_conf *info, |
| 3867 | u32 changed) |
| 3868 | { |
| 3869 | struct ath10k *ar = hw->priv; |
| 3870 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3871 | int ret = 0; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 3872 | u32 vdev_param, pdev_param, slottime, preamble; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3873 | |
| 3874 | mutex_lock(&ar->conf_mutex); |
| 3875 | |
| 3876 | if (changed & BSS_CHANGED_IBSS) |
| 3877 | ath10k_control_ibss(arvif, info, vif->addr); |
| 3878 | |
| 3879 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 3880 | arvif->beacon_interval = info->beacon_int; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3881 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
| 3882 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3883 | arvif->beacon_interval); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3884 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3885 | "mac vdev %d beacon_interval %d\n", |
| 3886 | arvif->vdev_id, arvif->beacon_interval); |
| 3887 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3888 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3889 | ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3890 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | if (changed & BSS_CHANGED_BEACON) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3894 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3895 | "vdev %d set beacon tx mode to staggered\n", |
| 3896 | arvif->vdev_id); |
| 3897 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 3898 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
| 3899 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3900 | WMI_BEACON_STAGGERED_MODE); |
| 3901 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3902 | ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3903 | arvif->vdev_id, ret); |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 3904 | |
| 3905 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 3906 | if (ret) |
| 3907 | ath10k_warn(ar, "failed to update beacon template: %d\n", |
| 3908 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3909 | } |
| 3910 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 3911 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { |
| 3912 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 3913 | if (ret) |
| 3914 | ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n", |
| 3915 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3916 | } |
| 3917 | |
Michal Kazior | ba2479f | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 3918 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3919 | arvif->dtim_period = info->dtim_period; |
| 3920 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3921 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3922 | "mac vdev %d dtim_period %d\n", |
| 3923 | arvif->vdev_id, arvif->dtim_period); |
| 3924 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3925 | vdev_param = ar->wmi.vdev_param->dtim_period; |
| 3926 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3927 | arvif->dtim_period); |
| 3928 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3929 | ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3930 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | if (changed & BSS_CHANGED_SSID && |
| 3934 | vif->type == NL80211_IFTYPE_AP) { |
| 3935 | arvif->u.ap.ssid_len = info->ssid_len; |
| 3936 | if (info->ssid_len) |
| 3937 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); |
| 3938 | arvif->u.ap.hidden_ssid = info->hidden_ssid; |
| 3939 | } |
| 3940 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3941 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
| 3942 | ether_addr_copy(arvif->bssid, info->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3943 | |
| 3944 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
| 3945 | ath10k_control_beaconing(arvif, info); |
| 3946 | |
| 3947 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3948 | arvif->use_cts_prot = info->use_cts_prot; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3949 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n", |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3950 | arvif->vdev_id, info->use_cts_prot); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3951 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3952 | ret = ath10k_recalc_rtscts_prot(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3953 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3954 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3955 | arvif->vdev_id, ret); |
Michal Kazior | a87fd4b | 2015-03-02 11:21:17 +0100 | [diff] [blame] | 3956 | |
| 3957 | vdev_param = ar->wmi.vdev_param->protection_mode; |
| 3958 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 3959 | info->use_cts_prot ? 1 : 0); |
| 3960 | if (ret) |
| 3961 | ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n", |
| 3962 | info->use_cts_prot, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3966 | if (info->use_short_slot) |
| 3967 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ |
| 3968 | |
| 3969 | else |
| 3970 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ |
| 3971 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3972 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3973 | arvif->vdev_id, slottime); |
| 3974 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3975 | vdev_param = ar->wmi.vdev_param->slot_time; |
| 3976 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3977 | slottime); |
| 3978 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3979 | ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3980 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3984 | if (info->use_short_preamble) |
| 3985 | preamble = WMI_VDEV_PREAMBLE_SHORT; |
| 3986 | else |
| 3987 | preamble = WMI_VDEV_PREAMBLE_LONG; |
| 3988 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3989 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3990 | "mac vdev %d preamble %dn", |
| 3991 | arvif->vdev_id, preamble); |
| 3992 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3993 | vdev_param = ar->wmi.vdev_param->preamble; |
| 3994 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3995 | preamble); |
| 3996 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3997 | ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3998 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | if (changed & BSS_CHANGED_ASSOC) { |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 4002 | if (info->assoc) { |
| 4003 | /* Workaround: Make sure monitor vdev is not running |
| 4004 | * when associating to prevent some firmware revisions |
| 4005 | * (e.g. 10.1 and 10.2) from crashing. |
| 4006 | */ |
| 4007 | if (ar->monitor_started) |
| 4008 | ath10k_monitor_stop(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4009 | ath10k_bss_assoc(hw, vif, info); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 4010 | ath10k_monitor_recalc(ar); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4011 | } else { |
| 4012 | ath10k_bss_disassoc(hw, vif); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 4013 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4014 | } |
| 4015 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 4016 | if (changed & BSS_CHANGED_TXPOWER) { |
| 4017 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n", |
| 4018 | arvif->vdev_id, info->txpower); |
| 4019 | |
| 4020 | arvif->txpower = info->txpower; |
| 4021 | ret = ath10k_mac_txpower_recalc(ar); |
| 4022 | if (ret) |
| 4023 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 4024 | } |
| 4025 | |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 4026 | if (changed & BSS_CHANGED_PS) { |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 4027 | arvif->ps = vif->bss_conf.ps; |
| 4028 | |
| 4029 | ret = ath10k_config_ps(ar); |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 4030 | if (ret) |
| 4031 | ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n", |
| 4032 | arvif->vdev_id, ret); |
| 4033 | } |
| 4034 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4035 | mutex_unlock(&ar->conf_mutex); |
| 4036 | } |
| 4037 | |
| 4038 | static int ath10k_hw_scan(struct ieee80211_hw *hw, |
| 4039 | struct ieee80211_vif *vif, |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 4040 | struct ieee80211_scan_request *hw_req) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4041 | { |
| 4042 | struct ath10k *ar = hw->priv; |
| 4043 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 4044 | struct cfg80211_scan_request *req = &hw_req->req; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4045 | struct wmi_start_scan_arg arg; |
| 4046 | int ret = 0; |
| 4047 | int i; |
| 4048 | |
| 4049 | mutex_lock(&ar->conf_mutex); |
| 4050 | |
| 4051 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4052 | switch (ar->scan.state) { |
| 4053 | case ATH10K_SCAN_IDLE: |
| 4054 | reinit_completion(&ar->scan.started); |
| 4055 | reinit_completion(&ar->scan.completed); |
| 4056 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 4057 | ar->scan.is_roc = false; |
| 4058 | ar->scan.vdev_id = arvif->vdev_id; |
| 4059 | ret = 0; |
| 4060 | break; |
| 4061 | case ATH10K_SCAN_STARTING: |
| 4062 | case ATH10K_SCAN_RUNNING: |
| 4063 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4064 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4065 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4066 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4067 | spin_unlock_bh(&ar->data_lock); |
| 4068 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4069 | if (ret) |
| 4070 | goto exit; |
| 4071 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4072 | memset(&arg, 0, sizeof(arg)); |
| 4073 | ath10k_wmi_start_scan_init(ar, &arg); |
| 4074 | arg.vdev_id = arvif->vdev_id; |
| 4075 | arg.scan_id = ATH10K_SCAN_ID; |
| 4076 | |
| 4077 | if (!req->no_cck) |
| 4078 | arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES; |
| 4079 | |
| 4080 | if (req->ie_len) { |
| 4081 | arg.ie_len = req->ie_len; |
| 4082 | memcpy(arg.ie, req->ie, arg.ie_len); |
| 4083 | } |
| 4084 | |
| 4085 | if (req->n_ssids) { |
| 4086 | arg.n_ssids = req->n_ssids; |
| 4087 | for (i = 0; i < arg.n_ssids; i++) { |
| 4088 | arg.ssids[i].len = req->ssids[i].ssid_len; |
| 4089 | arg.ssids[i].ssid = req->ssids[i].ssid; |
| 4090 | } |
Michal Kazior | dcd4a56 | 2013-07-31 10:55:12 +0200 | [diff] [blame] | 4091 | } else { |
| 4092 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | if (req->n_channels) { |
| 4096 | arg.n_channels = req->n_channels; |
| 4097 | for (i = 0; i < arg.n_channels; i++) |
| 4098 | arg.channels[i] = req->channels[i]->center_freq; |
| 4099 | } |
| 4100 | |
| 4101 | ret = ath10k_start_scan(ar, &arg); |
| 4102 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4103 | ath10k_warn(ar, "failed to start hw scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4104 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4105 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4106 | spin_unlock_bh(&ar->data_lock); |
| 4107 | } |
| 4108 | |
| 4109 | exit: |
| 4110 | mutex_unlock(&ar->conf_mutex); |
| 4111 | return ret; |
| 4112 | } |
| 4113 | |
| 4114 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 4115 | struct ieee80211_vif *vif) |
| 4116 | { |
| 4117 | struct ath10k *ar = hw->priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4118 | |
| 4119 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4120 | ath10k_scan_abort(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4121 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 4122 | |
| 4123 | cancel_delayed_work_sync(&ar->scan.timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4124 | } |
| 4125 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4126 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
| 4127 | struct ath10k_vif *arvif, |
| 4128 | enum set_key_cmd cmd, |
| 4129 | struct ieee80211_key_conf *key) |
| 4130 | { |
| 4131 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; |
| 4132 | int ret; |
| 4133 | |
| 4134 | /* 10.1 firmware branch requires default key index to be set to group |
| 4135 | * key index after installing it. Otherwise FW/HW Txes corrupted |
| 4136 | * frames with multi-vif APs. This is not required for main firmware |
| 4137 | * branch (e.g. 636). |
| 4138 | * |
| 4139 | * FIXME: This has been tested only in AP. It remains unknown if this |
| 4140 | * is required for multi-vif STA interfaces on 10.1 */ |
| 4141 | |
| 4142 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 4143 | return; |
| 4144 | |
| 4145 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 4146 | return; |
| 4147 | |
| 4148 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 4149 | return; |
| 4150 | |
| 4151 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4152 | return; |
| 4153 | |
| 4154 | if (cmd != SET_KEY) |
| 4155 | return; |
| 4156 | |
| 4157 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 4158 | key->keyidx); |
| 4159 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4160 | ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4161 | arvif->vdev_id, ret); |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4162 | } |
| 4163 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4164 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 4165 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 4166 | struct ieee80211_key_conf *key) |
| 4167 | { |
| 4168 | struct ath10k *ar = hw->priv; |
| 4169 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4170 | struct ath10k_peer *peer; |
| 4171 | const u8 *peer_addr; |
| 4172 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 4173 | key->cipher == WLAN_CIPHER_SUITE_WEP104; |
| 4174 | int ret = 0; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4175 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4176 | |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 4177 | /* this one needs to be done in software */ |
| 4178 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 4179 | return 1; |
| 4180 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4181 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
| 4182 | return -ENOSPC; |
| 4183 | |
| 4184 | mutex_lock(&ar->conf_mutex); |
| 4185 | |
| 4186 | if (sta) |
| 4187 | peer_addr = sta->addr; |
| 4188 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 4189 | peer_addr = vif->bss_conf.bssid; |
| 4190 | else |
| 4191 | peer_addr = vif->addr; |
| 4192 | |
| 4193 | key->hw_key_idx = key->keyidx; |
| 4194 | |
| 4195 | /* the peer should not disappear in mid-way (unless FW goes awry) since |
| 4196 | * we already hold conf_mutex. we just make sure its there now. */ |
| 4197 | spin_lock_bh(&ar->data_lock); |
| 4198 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 4199 | spin_unlock_bh(&ar->data_lock); |
| 4200 | |
| 4201 | if (!peer) { |
| 4202 | if (cmd == SET_KEY) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4203 | ath10k_warn(ar, "failed to install key for non-existent peer %pM\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4204 | peer_addr); |
| 4205 | ret = -EOPNOTSUPP; |
| 4206 | goto exit; |
| 4207 | } else { |
| 4208 | /* if the peer doesn't exist there is no key to disable |
| 4209 | * anymore */ |
| 4210 | goto exit; |
| 4211 | } |
| 4212 | } |
| 4213 | |
Michal Kazior | 7cc4573 | 2015-03-09 14:24:17 +0100 | [diff] [blame] | 4214 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4215 | flags |= WMI_KEY_PAIRWISE; |
| 4216 | else |
| 4217 | flags |= WMI_KEY_GROUP; |
| 4218 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4219 | if (is_wep) { |
| 4220 | if (cmd == SET_KEY) |
| 4221 | arvif->wep_keys[key->keyidx] = key; |
| 4222 | else |
| 4223 | arvif->wep_keys[key->keyidx] = NULL; |
| 4224 | |
| 4225 | if (cmd == DISABLE_KEY) |
| 4226 | ath10k_clear_vdev_key(arvif, key); |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4227 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 4228 | /* When WEP keys are uploaded it's possible that there are |
| 4229 | * stations associated already (e.g. when merging) without any |
| 4230 | * keys. Static WEP needs an explicit per-peer key upload. |
| 4231 | */ |
| 4232 | if (vif->type == NL80211_IFTYPE_ADHOC && |
| 4233 | cmd == SET_KEY) |
| 4234 | ath10k_mac_vif_update_wep_key(arvif, key); |
| 4235 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4236 | /* 802.1x never sets the def_wep_key_idx so each set_key() |
| 4237 | * call changes default tx key. |
| 4238 | * |
| 4239 | * Static WEP sets def_wep_key_idx via .set_default_unicast_key |
| 4240 | * after first set_key(). |
| 4241 | */ |
| 4242 | if (cmd == SET_KEY && arvif->def_wep_key_idx == -1) |
| 4243 | flags |= WMI_KEY_TX_USAGE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4244 | |
Michal Kazior | 7cc4573 | 2015-03-09 14:24:17 +0100 | [diff] [blame] | 4245 | /* mac80211 uploads static WEP keys as groupwise while fw/hw |
| 4246 | * requires pairwise keys for non-self peers, i.e. BSSID in STA |
| 4247 | * mode and associated stations in AP/IBSS. |
| 4248 | * |
| 4249 | * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys |
| 4250 | * work fine when mapped directly from mac80211. |
| 4251 | * |
| 4252 | * Note: When installing first static WEP groupwise key (which |
| 4253 | * should be pairwise) def_wep_key_idx isn't known yet (it's |
| 4254 | * equal to -1). Since .set_default_unicast_key is called only |
| 4255 | * for static WEP it's used to re-upload the key as pairwise. |
| 4256 | */ |
| 4257 | if (arvif->def_wep_key_idx >= 0 && |
| 4258 | memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) { |
| 4259 | flags &= ~WMI_KEY_GROUP; |
| 4260 | flags |= WMI_KEY_PAIRWISE; |
| 4261 | } |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4265 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4266 | ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4267 | arvif->vdev_id, peer_addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4268 | goto exit; |
| 4269 | } |
| 4270 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4271 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
| 4272 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4273 | spin_lock_bh(&ar->data_lock); |
| 4274 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 4275 | if (peer && cmd == SET_KEY) |
| 4276 | peer->keys[key->keyidx] = key; |
| 4277 | else if (peer && cmd == DISABLE_KEY) |
| 4278 | peer->keys[key->keyidx] = NULL; |
| 4279 | else if (peer == NULL) |
| 4280 | /* impossible unless FW goes crazy */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4281 | ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4282 | spin_unlock_bh(&ar->data_lock); |
| 4283 | |
| 4284 | exit: |
| 4285 | mutex_unlock(&ar->conf_mutex); |
| 4286 | return ret; |
| 4287 | } |
| 4288 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4289 | static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw, |
| 4290 | struct ieee80211_vif *vif, |
| 4291 | int keyidx) |
| 4292 | { |
| 4293 | struct ath10k *ar = hw->priv; |
| 4294 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4295 | int ret; |
| 4296 | |
| 4297 | mutex_lock(&arvif->ar->conf_mutex); |
| 4298 | |
| 4299 | if (arvif->ar->state != ATH10K_STATE_ON) |
| 4300 | goto unlock; |
| 4301 | |
| 4302 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", |
| 4303 | arvif->vdev_id, keyidx); |
| 4304 | |
| 4305 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 4306 | arvif->vdev_id, |
| 4307 | arvif->ar->wmi.vdev_param->def_keyid, |
| 4308 | keyidx); |
| 4309 | |
| 4310 | if (ret) { |
| 4311 | ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n", |
| 4312 | arvif->vdev_id, |
| 4313 | ret); |
| 4314 | goto unlock; |
| 4315 | } |
| 4316 | |
| 4317 | arvif->def_wep_key_idx = keyidx; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4318 | |
| 4319 | ret = ath10k_mac_vif_sta_fix_wep_key(arvif); |
| 4320 | if (ret) { |
| 4321 | ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n", |
| 4322 | arvif->vdev_id, ret); |
| 4323 | goto unlock; |
| 4324 | } |
| 4325 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4326 | unlock: |
| 4327 | mutex_unlock(&arvif->ar->conf_mutex); |
| 4328 | } |
| 4329 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4330 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
| 4331 | { |
| 4332 | struct ath10k *ar; |
| 4333 | struct ath10k_vif *arvif; |
| 4334 | struct ath10k_sta *arsta; |
| 4335 | struct ieee80211_sta *sta; |
| 4336 | u32 changed, bw, nss, smps; |
| 4337 | int err; |
| 4338 | |
| 4339 | arsta = container_of(wk, struct ath10k_sta, update_wk); |
| 4340 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); |
| 4341 | arvif = arsta->arvif; |
| 4342 | ar = arvif->ar; |
| 4343 | |
| 4344 | spin_lock_bh(&ar->data_lock); |
| 4345 | |
| 4346 | changed = arsta->changed; |
| 4347 | arsta->changed = 0; |
| 4348 | |
| 4349 | bw = arsta->bw; |
| 4350 | nss = arsta->nss; |
| 4351 | smps = arsta->smps; |
| 4352 | |
| 4353 | spin_unlock_bh(&ar->data_lock); |
| 4354 | |
| 4355 | mutex_lock(&ar->conf_mutex); |
| 4356 | |
| 4357 | if (changed & IEEE80211_RC_BW_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4358 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4359 | sta->addr, bw); |
| 4360 | |
| 4361 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4362 | WMI_PEER_CHAN_WIDTH, bw); |
| 4363 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4364 | ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4365 | sta->addr, bw, err); |
| 4366 | } |
| 4367 | |
| 4368 | if (changed & IEEE80211_RC_NSS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4369 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4370 | sta->addr, nss); |
| 4371 | |
| 4372 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4373 | WMI_PEER_NSS, nss); |
| 4374 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4375 | ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4376 | sta->addr, nss, err); |
| 4377 | } |
| 4378 | |
| 4379 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4380 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4381 | sta->addr, smps); |
| 4382 | |
| 4383 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4384 | WMI_PEER_SMPS_STATE, smps); |
| 4385 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4386 | ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4387 | sta->addr, smps, err); |
| 4388 | } |
| 4389 | |
Janusz Dziedzic | 55884c0 | 2014-12-17 12:30:02 +0200 | [diff] [blame] | 4390 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED || |
| 4391 | changed & IEEE80211_RC_NSS_CHANGED) { |
| 4392 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4393 | sta->addr); |
| 4394 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4395 | err = ath10k_station_assoc(ar, arvif->vif, sta, true); |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4396 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4397 | ath10k_warn(ar, "failed to reassociate station: %pM\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4398 | sta->addr); |
| 4399 | } |
| 4400 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4401 | mutex_unlock(&ar->conf_mutex); |
| 4402 | } |
| 4403 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4404 | static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif) |
| 4405 | { |
| 4406 | struct ath10k *ar = arvif->ar; |
| 4407 | |
| 4408 | lockdep_assert_held(&ar->conf_mutex); |
| 4409 | |
| 4410 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 4411 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 4412 | return 0; |
| 4413 | |
| 4414 | if (ar->num_stations >= ar->max_num_stations) |
| 4415 | return -ENOBUFS; |
| 4416 | |
| 4417 | ar->num_stations++; |
| 4418 | |
| 4419 | return 0; |
| 4420 | } |
| 4421 | |
| 4422 | static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif) |
| 4423 | { |
| 4424 | struct ath10k *ar = arvif->ar; |
| 4425 | |
| 4426 | lockdep_assert_held(&ar->conf_mutex); |
| 4427 | |
| 4428 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 4429 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 4430 | return; |
| 4431 | |
| 4432 | ar->num_stations--; |
| 4433 | } |
| 4434 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4435 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
| 4436 | struct ieee80211_vif *vif, |
| 4437 | struct ieee80211_sta *sta, |
| 4438 | enum ieee80211_sta_state old_state, |
| 4439 | enum ieee80211_sta_state new_state) |
| 4440 | { |
| 4441 | struct ath10k *ar = hw->priv; |
| 4442 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4443 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4444 | int ret = 0; |
| 4445 | |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 4446 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 4447 | new_state == IEEE80211_STA_NONE) { |
| 4448 | memset(arsta, 0, sizeof(*arsta)); |
| 4449 | arsta->arvif = arvif; |
| 4450 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); |
| 4451 | } |
| 4452 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4453 | /* cancel must be done outside the mutex to avoid deadlock */ |
| 4454 | if ((old_state == IEEE80211_STA_NONE && |
| 4455 | new_state == IEEE80211_STA_NOTEXIST)) |
| 4456 | cancel_work_sync(&arsta->update_wk); |
| 4457 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4458 | mutex_lock(&ar->conf_mutex); |
| 4459 | |
| 4460 | if (old_state == IEEE80211_STA_NOTEXIST && |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4461 | new_state == IEEE80211_STA_NONE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4462 | /* |
| 4463 | * New station addition. |
| 4464 | */ |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4465 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 4466 | "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n", |
| 4467 | arvif->vdev_id, sta->addr, |
| 4468 | ar->num_stations + 1, ar->max_num_stations, |
| 4469 | ar->num_peers + 1, ar->max_num_peers); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 4470 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4471 | ret = ath10k_mac_inc_num_stations(arvif); |
| 4472 | if (ret) { |
| 4473 | ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n", |
| 4474 | ar->max_num_stations); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 4475 | goto exit; |
| 4476 | } |
| 4477 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 4478 | ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr, |
| 4479 | WMI_PEER_TYPE_DEFAULT); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 4480 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4481 | ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n", |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 4482 | sta->addr, arvif->vdev_id, ret); |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4483 | ath10k_mac_dec_num_stations(arvif); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 4484 | goto exit; |
| 4485 | } |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4486 | |
| 4487 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 4488 | WARN_ON(arvif->is_started); |
| 4489 | |
| 4490 | ret = ath10k_vdev_start(arvif); |
| 4491 | if (ret) { |
| 4492 | ath10k_warn(ar, "failed to start vdev %i: %d\n", |
| 4493 | arvif->vdev_id, ret); |
| 4494 | WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id, |
| 4495 | sta->addr)); |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4496 | ath10k_mac_dec_num_stations(arvif); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4497 | goto exit; |
| 4498 | } |
| 4499 | |
| 4500 | arvif->is_started = true; |
| 4501 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4502 | } else if ((old_state == IEEE80211_STA_NONE && |
| 4503 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 4504 | /* |
| 4505 | * Existing station deletion. |
| 4506 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4507 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4508 | "mac vdev %d peer delete %pM (sta gone)\n", |
| 4509 | arvif->vdev_id, sta->addr); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4510 | |
| 4511 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 4512 | WARN_ON(!arvif->is_started); |
| 4513 | |
| 4514 | ret = ath10k_vdev_stop(arvif); |
| 4515 | if (ret) |
| 4516 | ath10k_warn(ar, "failed to stop vdev %i: %d\n", |
| 4517 | arvif->vdev_id, ret); |
| 4518 | |
| 4519 | arvif->is_started = false; |
| 4520 | } |
| 4521 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4522 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 4523 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4524 | ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4525 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4526 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4527 | ath10k_mac_dec_num_stations(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4528 | } else if (old_state == IEEE80211_STA_AUTH && |
| 4529 | new_state == IEEE80211_STA_ASSOC && |
| 4530 | (vif->type == NL80211_IFTYPE_AP || |
| 4531 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 4532 | /* |
| 4533 | * New association. |
| 4534 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4535 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4536 | sta->addr); |
| 4537 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4538 | ret = ath10k_station_assoc(ar, vif, sta, false); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4539 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4540 | ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4541 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4542 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 4543 | new_state == IEEE80211_STA_AUTH && |
| 4544 | (vif->type == NL80211_IFTYPE_AP || |
| 4545 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 4546 | /* |
| 4547 | * Disassociation. |
| 4548 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4549 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4550 | sta->addr); |
| 4551 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4552 | ret = ath10k_station_disassoc(ar, vif, sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4553 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4554 | ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4555 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4556 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 4557 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4558 | mutex_unlock(&ar->conf_mutex); |
| 4559 | return ret; |
| 4560 | } |
| 4561 | |
| 4562 | static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 4563 | u16 ac, bool enable) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4564 | { |
| 4565 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4566 | struct wmi_sta_uapsd_auto_trig_arg arg = {}; |
| 4567 | u32 prio = 0, acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4568 | u32 value = 0; |
| 4569 | int ret = 0; |
| 4570 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4571 | lockdep_assert_held(&ar->conf_mutex); |
| 4572 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4573 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 4574 | return 0; |
| 4575 | |
| 4576 | switch (ac) { |
| 4577 | case IEEE80211_AC_VO: |
| 4578 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | |
| 4579 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4580 | prio = 7; |
| 4581 | acc = 3; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4582 | break; |
| 4583 | case IEEE80211_AC_VI: |
| 4584 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | |
| 4585 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4586 | prio = 5; |
| 4587 | acc = 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4588 | break; |
| 4589 | case IEEE80211_AC_BE: |
| 4590 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | |
| 4591 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4592 | prio = 2; |
| 4593 | acc = 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4594 | break; |
| 4595 | case IEEE80211_AC_BK: |
| 4596 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | |
| 4597 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4598 | prio = 0; |
| 4599 | acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4600 | break; |
| 4601 | } |
| 4602 | |
| 4603 | if (enable) |
| 4604 | arvif->u.sta.uapsd |= value; |
| 4605 | else |
| 4606 | arvif->u.sta.uapsd &= ~value; |
| 4607 | |
| 4608 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 4609 | WMI_STA_PS_PARAM_UAPSD, |
| 4610 | arvif->u.sta.uapsd); |
| 4611 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4612 | ath10k_warn(ar, "failed to set uapsd params: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4613 | goto exit; |
| 4614 | } |
| 4615 | |
| 4616 | if (arvif->u.sta.uapsd) |
| 4617 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
| 4618 | else |
| 4619 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 4620 | |
| 4621 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 4622 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, |
| 4623 | value); |
| 4624 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4625 | ath10k_warn(ar, "failed to set rx wake param: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4626 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 4627 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
| 4628 | if (ret) { |
| 4629 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
| 4630 | arvif->vdev_id, ret); |
| 4631 | return ret; |
| 4632 | } |
| 4633 | |
| 4634 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
| 4635 | if (ret) { |
| 4636 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
| 4637 | arvif->vdev_id, ret); |
| 4638 | return ret; |
| 4639 | } |
| 4640 | |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4641 | if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) || |
| 4642 | test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) { |
| 4643 | /* Only userspace can make an educated decision when to send |
| 4644 | * trigger frame. The following effectively disables u-UAPSD |
| 4645 | * autotrigger in firmware (which is enabled by default |
| 4646 | * provided the autotrigger service is available). |
| 4647 | */ |
| 4648 | |
| 4649 | arg.wmm_ac = acc; |
| 4650 | arg.user_priority = prio; |
| 4651 | arg.service_interval = 0; |
| 4652 | arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 4653 | arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 4654 | |
| 4655 | ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id, |
| 4656 | arvif->bssid, &arg, 1); |
| 4657 | if (ret) { |
| 4658 | ath10k_warn(ar, "failed to set uapsd auto trigger %d\n", |
| 4659 | ret); |
| 4660 | return ret; |
| 4661 | } |
| 4662 | } |
| 4663 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4664 | exit: |
| 4665 | return ret; |
| 4666 | } |
| 4667 | |
| 4668 | static int ath10k_conf_tx(struct ieee80211_hw *hw, |
| 4669 | struct ieee80211_vif *vif, u16 ac, |
| 4670 | const struct ieee80211_tx_queue_params *params) |
| 4671 | { |
| 4672 | struct ath10k *ar = hw->priv; |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4673 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4674 | struct wmi_wmm_params_arg *p = NULL; |
| 4675 | int ret; |
| 4676 | |
| 4677 | mutex_lock(&ar->conf_mutex); |
| 4678 | |
| 4679 | switch (ac) { |
| 4680 | case IEEE80211_AC_VO: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4681 | p = &arvif->wmm_params.ac_vo; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4682 | break; |
| 4683 | case IEEE80211_AC_VI: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4684 | p = &arvif->wmm_params.ac_vi; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4685 | break; |
| 4686 | case IEEE80211_AC_BE: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4687 | p = &arvif->wmm_params.ac_be; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4688 | break; |
| 4689 | case IEEE80211_AC_BK: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4690 | p = &arvif->wmm_params.ac_bk; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4691 | break; |
| 4692 | } |
| 4693 | |
| 4694 | if (WARN_ON(!p)) { |
| 4695 | ret = -EINVAL; |
| 4696 | goto exit; |
| 4697 | } |
| 4698 | |
| 4699 | p->cwmin = params->cw_min; |
| 4700 | p->cwmax = params->cw_max; |
| 4701 | p->aifs = params->aifs; |
| 4702 | |
| 4703 | /* |
| 4704 | * The channel time duration programmed in the HW is in absolute |
| 4705 | * microseconds, while mac80211 gives the txop in units of |
| 4706 | * 32 microseconds. |
| 4707 | */ |
| 4708 | p->txop = params->txop * 32; |
| 4709 | |
Michal Kazior | 7fc979a | 2015-01-28 09:57:28 +0200 | [diff] [blame] | 4710 | if (ar->wmi.ops->gen_vdev_wmm_conf) { |
| 4711 | ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id, |
| 4712 | &arvif->wmm_params); |
| 4713 | if (ret) { |
| 4714 | ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n", |
| 4715 | arvif->vdev_id, ret); |
| 4716 | goto exit; |
| 4717 | } |
| 4718 | } else { |
| 4719 | /* This won't work well with multi-interface cases but it's |
| 4720 | * better than nothing. |
| 4721 | */ |
| 4722 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params); |
| 4723 | if (ret) { |
| 4724 | ath10k_warn(ar, "failed to set wmm params: %d\n", ret); |
| 4725 | goto exit; |
| 4726 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4727 | } |
| 4728 | |
| 4729 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); |
| 4730 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4731 | ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4732 | |
| 4733 | exit: |
| 4734 | mutex_unlock(&ar->conf_mutex); |
| 4735 | return ret; |
| 4736 | } |
| 4737 | |
| 4738 | #define ATH10K_ROC_TIMEOUT_HZ (2*HZ) |
| 4739 | |
| 4740 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, |
| 4741 | struct ieee80211_vif *vif, |
| 4742 | struct ieee80211_channel *chan, |
| 4743 | int duration, |
| 4744 | enum ieee80211_roc_type type) |
| 4745 | { |
| 4746 | struct ath10k *ar = hw->priv; |
| 4747 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4748 | struct wmi_start_scan_arg arg; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4749 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4750 | |
| 4751 | mutex_lock(&ar->conf_mutex); |
| 4752 | |
| 4753 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4754 | switch (ar->scan.state) { |
| 4755 | case ATH10K_SCAN_IDLE: |
| 4756 | reinit_completion(&ar->scan.started); |
| 4757 | reinit_completion(&ar->scan.completed); |
| 4758 | reinit_completion(&ar->scan.on_channel); |
| 4759 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 4760 | ar->scan.is_roc = true; |
| 4761 | ar->scan.vdev_id = arvif->vdev_id; |
| 4762 | ar->scan.roc_freq = chan->center_freq; |
| 4763 | ret = 0; |
| 4764 | break; |
| 4765 | case ATH10K_SCAN_STARTING: |
| 4766 | case ATH10K_SCAN_RUNNING: |
| 4767 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4768 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4769 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4770 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4771 | spin_unlock_bh(&ar->data_lock); |
| 4772 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4773 | if (ret) |
| 4774 | goto exit; |
| 4775 | |
Michal Kazior | dcca0bd | 2014-11-24 14:58:32 +0100 | [diff] [blame] | 4776 | duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC); |
| 4777 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4778 | memset(&arg, 0, sizeof(arg)); |
| 4779 | ath10k_wmi_start_scan_init(ar, &arg); |
| 4780 | arg.vdev_id = arvif->vdev_id; |
| 4781 | arg.scan_id = ATH10K_SCAN_ID; |
| 4782 | arg.n_channels = 1; |
| 4783 | arg.channels[0] = chan->center_freq; |
| 4784 | arg.dwell_time_active = duration; |
| 4785 | arg.dwell_time_passive = duration; |
| 4786 | arg.max_scan_time = 2 * duration; |
| 4787 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
| 4788 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; |
| 4789 | |
| 4790 | ret = ath10k_start_scan(ar, &arg); |
| 4791 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4792 | ath10k_warn(ar, "failed to start roc scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4793 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4794 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4795 | spin_unlock_bh(&ar->data_lock); |
| 4796 | goto exit; |
| 4797 | } |
| 4798 | |
| 4799 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ); |
| 4800 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4801 | ath10k_warn(ar, "failed to switch to channel for roc scan\n"); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4802 | |
| 4803 | ret = ath10k_scan_stop(ar); |
| 4804 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4805 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4806 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4807 | ret = -ETIMEDOUT; |
| 4808 | goto exit; |
| 4809 | } |
| 4810 | |
| 4811 | ret = 0; |
| 4812 | exit: |
| 4813 | mutex_unlock(&ar->conf_mutex); |
| 4814 | return ret; |
| 4815 | } |
| 4816 | |
| 4817 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 4818 | { |
| 4819 | struct ath10k *ar = hw->priv; |
| 4820 | |
| 4821 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4822 | ath10k_scan_abort(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4823 | mutex_unlock(&ar->conf_mutex); |
| 4824 | |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 4825 | cancel_delayed_work_sync(&ar->scan.timeout); |
| 4826 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4827 | return 0; |
| 4828 | } |
| 4829 | |
| 4830 | /* |
| 4831 | * Both RTS and Fragmentation threshold are interface-specific |
| 4832 | * in ath10k, but device-specific in mac80211. |
| 4833 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4834 | |
| 4835 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 4836 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4837 | struct ath10k *ar = hw->priv; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4838 | struct ath10k_vif *arvif; |
| 4839 | int ret = 0; |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4840 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4841 | mutex_lock(&ar->conf_mutex); |
| 4842 | list_for_each_entry(arvif, &ar->arvifs, list) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4843 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n", |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4844 | arvif->vdev_id, value); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4845 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4846 | ret = ath10k_mac_set_rts(arvif, value); |
| 4847 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4848 | ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n", |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4849 | arvif->vdev_id, ret); |
| 4850 | break; |
| 4851 | } |
| 4852 | } |
| 4853 | mutex_unlock(&ar->conf_mutex); |
| 4854 | |
| 4855 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4856 | } |
| 4857 | |
Emmanuel Grumbach | 77be2c5 | 2014-03-27 11:30:29 +0200 | [diff] [blame] | 4858 | static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4859 | u32 queues, bool drop) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4860 | { |
| 4861 | struct ath10k *ar = hw->priv; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4862 | bool skip; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4863 | int ret; |
| 4864 | |
| 4865 | /* mac80211 doesn't care if we really xmit queued frames or not |
| 4866 | * we'll collect those frames either way if we stop/delete vdevs */ |
| 4867 | if (drop) |
| 4868 | return; |
| 4869 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4870 | mutex_lock(&ar->conf_mutex); |
| 4871 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4872 | if (ar->state == ATH10K_STATE_WEDGED) |
| 4873 | goto skip; |
| 4874 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 4875 | ret = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4876 | bool empty; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4877 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 4878 | spin_lock_bh(&ar->htt.tx_lock); |
Michal Kazior | 0945baf | 2013-09-18 14:43:18 +0200 | [diff] [blame] | 4879 | empty = (ar->htt.num_pending_tx == 0); |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 4880 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4881 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 4882 | skip = (ar->state == ATH10K_STATE_WEDGED) || |
| 4883 | test_bit(ATH10K_FLAG_CRASH_FLUSH, |
| 4884 | &ar->dev_flags); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4885 | |
| 4886 | (empty || skip); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4887 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4888 | |
| 4889 | if (ret <= 0 || skip) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4890 | ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n", |
Ben Greear | 9ba4c78 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 4891 | skip, ar->state, ret); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4892 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4893 | skip: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4894 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | /* TODO: Implement this function properly |
| 4898 | * For now it is needed to reply to Probe Requests in IBSS mode. |
| 4899 | * Propably we need this information from FW. |
| 4900 | */ |
| 4901 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) |
| 4902 | { |
| 4903 | return 1; |
| 4904 | } |
| 4905 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 4906 | static void ath10k_reconfig_complete(struct ieee80211_hw *hw, |
| 4907 | enum ieee80211_reconfig_type reconfig_type) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4908 | { |
| 4909 | struct ath10k *ar = hw->priv; |
| 4910 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 4911 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
| 4912 | return; |
| 4913 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4914 | mutex_lock(&ar->conf_mutex); |
| 4915 | |
| 4916 | /* If device failed to restart it will be in a different state, e.g. |
| 4917 | * ATH10K_STATE_WEDGED */ |
| 4918 | if (ar->state == ATH10K_STATE_RESTARTED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4919 | ath10k_info(ar, "device successfully recovered\n"); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4920 | ar->state = ATH10K_STATE_ON; |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 4921 | ieee80211_wake_queues(ar->hw); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | mutex_unlock(&ar->conf_mutex); |
| 4925 | } |
| 4926 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 4927 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
| 4928 | struct survey_info *survey) |
| 4929 | { |
| 4930 | struct ath10k *ar = hw->priv; |
| 4931 | struct ieee80211_supported_band *sband; |
| 4932 | struct survey_info *ar_survey = &ar->survey[idx]; |
| 4933 | int ret = 0; |
| 4934 | |
| 4935 | mutex_lock(&ar->conf_mutex); |
| 4936 | |
| 4937 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 4938 | if (sband && idx >= sband->n_channels) { |
| 4939 | idx -= sband->n_channels; |
| 4940 | sband = NULL; |
| 4941 | } |
| 4942 | |
| 4943 | if (!sband) |
| 4944 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 4945 | |
| 4946 | if (!sband || idx >= sband->n_channels) { |
| 4947 | ret = -ENOENT; |
| 4948 | goto exit; |
| 4949 | } |
| 4950 | |
| 4951 | spin_lock_bh(&ar->data_lock); |
| 4952 | memcpy(survey, ar_survey, sizeof(*survey)); |
| 4953 | spin_unlock_bh(&ar->data_lock); |
| 4954 | |
| 4955 | survey->channel = &sband->channels[idx]; |
| 4956 | |
Felix Fietkau | fa1d4df | 2014-10-23 17:04:28 +0300 | [diff] [blame] | 4957 | if (ar->rx_channel == survey->channel) |
| 4958 | survey->filled |= SURVEY_INFO_IN_USE; |
| 4959 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 4960 | exit: |
| 4961 | mutex_unlock(&ar->conf_mutex); |
| 4962 | return ret; |
| 4963 | } |
| 4964 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4965 | /* Helper table for legacy fixed_rate/bitrate_mask */ |
| 4966 | static const u8 cck_ofdm_rate[] = { |
| 4967 | /* CCK */ |
| 4968 | 3, /* 1Mbps */ |
| 4969 | 2, /* 2Mbps */ |
| 4970 | 1, /* 5.5Mbps */ |
| 4971 | 0, /* 11Mbps */ |
| 4972 | /* OFDM */ |
| 4973 | 3, /* 6Mbps */ |
| 4974 | 7, /* 9Mbps */ |
| 4975 | 2, /* 12Mbps */ |
| 4976 | 6, /* 18Mbps */ |
| 4977 | 1, /* 24Mbps */ |
| 4978 | 5, /* 36Mbps */ |
| 4979 | 0, /* 48Mbps */ |
| 4980 | 4, /* 54Mbps */ |
| 4981 | }; |
| 4982 | |
| 4983 | /* Check if only one bit set */ |
| 4984 | static int ath10k_check_single_mask(u32 mask) |
| 4985 | { |
| 4986 | int bit; |
| 4987 | |
| 4988 | bit = ffs(mask); |
| 4989 | if (!bit) |
| 4990 | return 0; |
| 4991 | |
| 4992 | mask &= ~BIT(bit - 1); |
| 4993 | if (mask) |
| 4994 | return 2; |
| 4995 | |
| 4996 | return 1; |
| 4997 | } |
| 4998 | |
| 4999 | static bool |
| 5000 | ath10k_default_bitrate_mask(struct ath10k *ar, |
| 5001 | enum ieee80211_band band, |
| 5002 | const struct cfg80211_bitrate_mask *mask) |
| 5003 | { |
| 5004 | u32 legacy = 0x00ff; |
| 5005 | u8 ht = 0xff, i; |
| 5006 | u16 vht = 0x3ff; |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5007 | u16 nrf = ar->num_rf_chains; |
| 5008 | |
| 5009 | if (ar->cfg_tx_chainmask) |
| 5010 | nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5011 | |
| 5012 | switch (band) { |
| 5013 | case IEEE80211_BAND_2GHZ: |
| 5014 | legacy = 0x00fff; |
| 5015 | vht = 0; |
| 5016 | break; |
| 5017 | case IEEE80211_BAND_5GHZ: |
| 5018 | break; |
| 5019 | default: |
| 5020 | return false; |
| 5021 | } |
| 5022 | |
| 5023 | if (mask->control[band].legacy != legacy) |
| 5024 | return false; |
| 5025 | |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5026 | for (i = 0; i < nrf; i++) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5027 | if (mask->control[band].ht_mcs[i] != ht) |
| 5028 | return false; |
| 5029 | |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5030 | for (i = 0; i < nrf; i++) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5031 | if (mask->control[band].vht_mcs[i] != vht) |
| 5032 | return false; |
| 5033 | |
| 5034 | return true; |
| 5035 | } |
| 5036 | |
| 5037 | static bool |
| 5038 | ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask, |
| 5039 | enum ieee80211_band band, |
| 5040 | u8 *fixed_nss) |
| 5041 | { |
| 5042 | int ht_nss = 0, vht_nss = 0, i; |
| 5043 | |
| 5044 | /* check legacy */ |
| 5045 | if (ath10k_check_single_mask(mask->control[band].legacy)) |
| 5046 | return false; |
| 5047 | |
| 5048 | /* check HT */ |
| 5049 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
| 5050 | if (mask->control[band].ht_mcs[i] == 0xff) |
| 5051 | continue; |
| 5052 | else if (mask->control[band].ht_mcs[i] == 0x00) |
| 5053 | break; |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 5054 | |
| 5055 | return false; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | ht_nss = i; |
| 5059 | |
| 5060 | /* check VHT */ |
| 5061 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 5062 | if (mask->control[band].vht_mcs[i] == 0x03ff) |
| 5063 | continue; |
| 5064 | else if (mask->control[band].vht_mcs[i] == 0x0000) |
| 5065 | break; |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 5066 | |
| 5067 | return false; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5068 | } |
| 5069 | |
| 5070 | vht_nss = i; |
| 5071 | |
| 5072 | if (ht_nss > 0 && vht_nss > 0) |
| 5073 | return false; |
| 5074 | |
| 5075 | if (ht_nss) |
| 5076 | *fixed_nss = ht_nss; |
| 5077 | else if (vht_nss) |
| 5078 | *fixed_nss = vht_nss; |
| 5079 | else |
| 5080 | return false; |
| 5081 | |
| 5082 | return true; |
| 5083 | } |
| 5084 | |
| 5085 | static bool |
| 5086 | ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask, |
| 5087 | enum ieee80211_band band, |
| 5088 | enum wmi_rate_preamble *preamble) |
| 5089 | { |
| 5090 | int legacy = 0, ht = 0, vht = 0, i; |
| 5091 | |
| 5092 | *preamble = WMI_RATE_PREAMBLE_OFDM; |
| 5093 | |
| 5094 | /* check legacy */ |
| 5095 | legacy = ath10k_check_single_mask(mask->control[band].legacy); |
| 5096 | if (legacy > 1) |
| 5097 | return false; |
| 5098 | |
| 5099 | /* check HT */ |
| 5100 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5101 | ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]); |
| 5102 | if (ht > 1) |
| 5103 | return false; |
| 5104 | |
| 5105 | /* check VHT */ |
| 5106 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 5107 | vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]); |
| 5108 | if (vht > 1) |
| 5109 | return false; |
| 5110 | |
| 5111 | /* Currently we support only one fixed_rate */ |
| 5112 | if ((legacy + ht + vht) != 1) |
| 5113 | return false; |
| 5114 | |
| 5115 | if (ht) |
| 5116 | *preamble = WMI_RATE_PREAMBLE_HT; |
| 5117 | else if (vht) |
| 5118 | *preamble = WMI_RATE_PREAMBLE_VHT; |
| 5119 | |
| 5120 | return true; |
| 5121 | } |
| 5122 | |
| 5123 | static bool |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5124 | ath10k_bitrate_mask_rate(struct ath10k *ar, |
| 5125 | const struct cfg80211_bitrate_mask *mask, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5126 | enum ieee80211_band band, |
| 5127 | u8 *fixed_rate, |
| 5128 | u8 *fixed_nss) |
| 5129 | { |
| 5130 | u8 rate = 0, pream = 0, nss = 0, i; |
| 5131 | enum wmi_rate_preamble preamble; |
| 5132 | |
| 5133 | /* Check if single rate correct */ |
| 5134 | if (!ath10k_bitrate_mask_correct(mask, band, &preamble)) |
| 5135 | return false; |
| 5136 | |
| 5137 | pream = preamble; |
| 5138 | |
| 5139 | switch (preamble) { |
| 5140 | case WMI_RATE_PREAMBLE_CCK: |
| 5141 | case WMI_RATE_PREAMBLE_OFDM: |
| 5142 | i = ffs(mask->control[band].legacy) - 1; |
| 5143 | |
| 5144 | if (band == IEEE80211_BAND_2GHZ && i < 4) |
| 5145 | pream = WMI_RATE_PREAMBLE_CCK; |
| 5146 | |
| 5147 | if (band == IEEE80211_BAND_5GHZ) |
| 5148 | i += 4; |
| 5149 | |
| 5150 | if (i >= ARRAY_SIZE(cck_ofdm_rate)) |
| 5151 | return false; |
| 5152 | |
| 5153 | rate = cck_ofdm_rate[i]; |
| 5154 | break; |
| 5155 | case WMI_RATE_PREAMBLE_HT: |
| 5156 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5157 | if (mask->control[band].ht_mcs[i]) |
| 5158 | break; |
| 5159 | |
| 5160 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
| 5161 | return false; |
| 5162 | |
| 5163 | rate = ffs(mask->control[band].ht_mcs[i]) - 1; |
| 5164 | nss = i; |
| 5165 | break; |
| 5166 | case WMI_RATE_PREAMBLE_VHT: |
| 5167 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 5168 | if (mask->control[band].vht_mcs[i]) |
| 5169 | break; |
| 5170 | |
| 5171 | if (i == NL80211_VHT_NSS_MAX) |
| 5172 | return false; |
| 5173 | |
| 5174 | rate = ffs(mask->control[band].vht_mcs[i]) - 1; |
| 5175 | nss = i; |
| 5176 | break; |
| 5177 | } |
| 5178 | |
| 5179 | *fixed_nss = nss + 1; |
| 5180 | nss <<= 4; |
| 5181 | pream <<= 6; |
| 5182 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5183 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n", |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5184 | pream, nss, rate); |
| 5185 | |
| 5186 | *fixed_rate = pream | nss | rate; |
| 5187 | |
| 5188 | return true; |
| 5189 | } |
| 5190 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5191 | static bool ath10k_get_fixed_rate_nss(struct ath10k *ar, |
| 5192 | const struct cfg80211_bitrate_mask *mask, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5193 | enum ieee80211_band band, |
| 5194 | u8 *fixed_rate, |
| 5195 | u8 *fixed_nss) |
| 5196 | { |
| 5197 | /* First check full NSS mask, if we can simply limit NSS */ |
| 5198 | if (ath10k_bitrate_mask_nss(mask, band, fixed_nss)) |
| 5199 | return true; |
| 5200 | |
| 5201 | /* Next Check single rate is set */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5202 | return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif, |
| 5206 | u8 fixed_rate, |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5207 | u8 fixed_nss, |
| 5208 | u8 force_sgi) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5209 | { |
| 5210 | struct ath10k *ar = arvif->ar; |
| 5211 | u32 vdev_param; |
| 5212 | int ret = 0; |
| 5213 | |
| 5214 | mutex_lock(&ar->conf_mutex); |
| 5215 | |
| 5216 | if (arvif->fixed_rate == fixed_rate && |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5217 | arvif->fixed_nss == fixed_nss && |
| 5218 | arvif->force_sgi == force_sgi) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5219 | goto exit; |
| 5220 | |
| 5221 | if (fixed_rate == WMI_FIXED_RATE_NONE) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5222 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n"); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5223 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5224 | if (force_sgi) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5225 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n"); |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5226 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5227 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
| 5228 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5229 | vdev_param, fixed_rate); |
| 5230 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5231 | ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n", |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5232 | fixed_rate, ret); |
| 5233 | ret = -EINVAL; |
| 5234 | goto exit; |
| 5235 | } |
| 5236 | |
| 5237 | arvif->fixed_rate = fixed_rate; |
| 5238 | |
| 5239 | vdev_param = ar->wmi.vdev_param->nss; |
| 5240 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5241 | vdev_param, fixed_nss); |
| 5242 | |
| 5243 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5244 | ath10k_warn(ar, "failed to set fixed nss param %d: %d\n", |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5245 | fixed_nss, ret); |
| 5246 | ret = -EINVAL; |
| 5247 | goto exit; |
| 5248 | } |
| 5249 | |
| 5250 | arvif->fixed_nss = fixed_nss; |
| 5251 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5252 | vdev_param = ar->wmi.vdev_param->sgi; |
| 5253 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5254 | force_sgi); |
| 5255 | |
| 5256 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5257 | ath10k_warn(ar, "failed to set sgi param %d: %d\n", |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5258 | force_sgi, ret); |
| 5259 | ret = -EINVAL; |
| 5260 | goto exit; |
| 5261 | } |
| 5262 | |
| 5263 | arvif->force_sgi = force_sgi; |
| 5264 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5265 | exit: |
| 5266 | mutex_unlock(&ar->conf_mutex); |
| 5267 | return ret; |
| 5268 | } |
| 5269 | |
| 5270 | static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw, |
| 5271 | struct ieee80211_vif *vif, |
| 5272 | const struct cfg80211_bitrate_mask *mask) |
| 5273 | { |
| 5274 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5275 | struct ath10k *ar = arvif->ar; |
| 5276 | enum ieee80211_band band = ar->hw->conf.chandef.chan->band; |
| 5277 | u8 fixed_rate = WMI_FIXED_RATE_NONE; |
| 5278 | u8 fixed_nss = ar->num_rf_chains; |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5279 | u8 force_sgi; |
| 5280 | |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5281 | if (ar->cfg_tx_chainmask) |
| 5282 | fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
| 5283 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5284 | force_sgi = mask->control[band].gi; |
| 5285 | if (force_sgi == NL80211_TXRATE_FORCE_LGI) |
| 5286 | return -EINVAL; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5287 | |
| 5288 | if (!ath10k_default_bitrate_mask(ar, band, mask)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5289 | if (!ath10k_get_fixed_rate_nss(ar, mask, band, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5290 | &fixed_rate, |
| 5291 | &fixed_nss)) |
| 5292 | return -EINVAL; |
| 5293 | } |
| 5294 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5295 | if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5296 | ath10k_warn(ar, "failed to force SGI usage for default rate settings\n"); |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5297 | return -EINVAL; |
| 5298 | } |
| 5299 | |
| 5300 | return ath10k_set_fixed_rate_param(arvif, fixed_rate, |
| 5301 | fixed_nss, force_sgi); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5302 | } |
| 5303 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5304 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
| 5305 | struct ieee80211_vif *vif, |
| 5306 | struct ieee80211_sta *sta, |
| 5307 | u32 changed) |
| 5308 | { |
| 5309 | struct ath10k *ar = hw->priv; |
| 5310 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 5311 | u32 bw, smps; |
| 5312 | |
| 5313 | spin_lock_bh(&ar->data_lock); |
| 5314 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5315 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5316 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
| 5317 | sta->addr, changed, sta->bandwidth, sta->rx_nss, |
| 5318 | sta->smps_mode); |
| 5319 | |
| 5320 | if (changed & IEEE80211_RC_BW_CHANGED) { |
| 5321 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5322 | |
| 5323 | switch (sta->bandwidth) { |
| 5324 | case IEEE80211_STA_RX_BW_20: |
| 5325 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5326 | break; |
| 5327 | case IEEE80211_STA_RX_BW_40: |
| 5328 | bw = WMI_PEER_CHWIDTH_40MHZ; |
| 5329 | break; |
| 5330 | case IEEE80211_STA_RX_BW_80: |
| 5331 | bw = WMI_PEER_CHWIDTH_80MHZ; |
| 5332 | break; |
| 5333 | case IEEE80211_STA_RX_BW_160: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5334 | ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 5335 | sta->bandwidth, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5336 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5337 | break; |
| 5338 | } |
| 5339 | |
| 5340 | arsta->bw = bw; |
| 5341 | } |
| 5342 | |
| 5343 | if (changed & IEEE80211_RC_NSS_CHANGED) |
| 5344 | arsta->nss = sta->rx_nss; |
| 5345 | |
| 5346 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 5347 | smps = WMI_PEER_SMPS_PS_NONE; |
| 5348 | |
| 5349 | switch (sta->smps_mode) { |
| 5350 | case IEEE80211_SMPS_AUTOMATIC: |
| 5351 | case IEEE80211_SMPS_OFF: |
| 5352 | smps = WMI_PEER_SMPS_PS_NONE; |
| 5353 | break; |
| 5354 | case IEEE80211_SMPS_STATIC: |
| 5355 | smps = WMI_PEER_SMPS_STATIC; |
| 5356 | break; |
| 5357 | case IEEE80211_SMPS_DYNAMIC: |
| 5358 | smps = WMI_PEER_SMPS_DYNAMIC; |
| 5359 | break; |
| 5360 | case IEEE80211_SMPS_NUM_MODES: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5361 | ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 5362 | sta->smps_mode, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5363 | smps = WMI_PEER_SMPS_PS_NONE; |
| 5364 | break; |
| 5365 | } |
| 5366 | |
| 5367 | arsta->smps = smps; |
| 5368 | } |
| 5369 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5370 | arsta->changed |= changed; |
| 5371 | |
| 5372 | spin_unlock_bh(&ar->data_lock); |
| 5373 | |
| 5374 | ieee80211_queue_work(hw, &arsta->update_wk); |
| 5375 | } |
| 5376 | |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 5377 | static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 5378 | { |
| 5379 | /* |
| 5380 | * FIXME: Return 0 for time being. Need to figure out whether FW |
| 5381 | * has the API to fetch 64-bit local TSF |
| 5382 | */ |
| 5383 | |
| 5384 | return 0; |
| 5385 | } |
| 5386 | |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5387 | static int ath10k_ampdu_action(struct ieee80211_hw *hw, |
| 5388 | struct ieee80211_vif *vif, |
| 5389 | enum ieee80211_ampdu_mlme_action action, |
| 5390 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 5391 | u8 buf_size) |
| 5392 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5393 | struct ath10k *ar = hw->priv; |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5394 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5395 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5396 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n", |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5397 | arvif->vdev_id, sta->addr, tid, action); |
| 5398 | |
| 5399 | switch (action) { |
| 5400 | case IEEE80211_AMPDU_RX_START: |
| 5401 | case IEEE80211_AMPDU_RX_STOP: |
| 5402 | /* HTT AddBa/DelBa events trigger mac80211 Rx BA session |
| 5403 | * creation/removal. Do we need to verify this? |
| 5404 | */ |
| 5405 | return 0; |
| 5406 | case IEEE80211_AMPDU_TX_START: |
| 5407 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 5408 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 5409 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 5410 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 5411 | /* Firmware offloads Tx aggregation entirely so deny mac80211 |
| 5412 | * Tx aggregation requests. |
| 5413 | */ |
| 5414 | return -EOPNOTSUPP; |
| 5415 | } |
| 5416 | |
| 5417 | return -EINVAL; |
| 5418 | } |
| 5419 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5420 | static const struct ieee80211_ops ath10k_ops = { |
| 5421 | .tx = ath10k_tx, |
| 5422 | .start = ath10k_start, |
| 5423 | .stop = ath10k_stop, |
| 5424 | .config = ath10k_config, |
| 5425 | .add_interface = ath10k_add_interface, |
| 5426 | .remove_interface = ath10k_remove_interface, |
| 5427 | .configure_filter = ath10k_configure_filter, |
| 5428 | .bss_info_changed = ath10k_bss_info_changed, |
| 5429 | .hw_scan = ath10k_hw_scan, |
| 5430 | .cancel_hw_scan = ath10k_cancel_hw_scan, |
| 5431 | .set_key = ath10k_set_key, |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 5432 | .set_default_unicast_key = ath10k_set_default_unicast_key, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5433 | .sta_state = ath10k_sta_state, |
| 5434 | .conf_tx = ath10k_conf_tx, |
| 5435 | .remain_on_channel = ath10k_remain_on_channel, |
| 5436 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, |
| 5437 | .set_rts_threshold = ath10k_set_rts_threshold, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5438 | .flush = ath10k_flush, |
| 5439 | .tx_last_beacon = ath10k_tx_last_beacon, |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 5440 | .set_antenna = ath10k_set_antenna, |
| 5441 | .get_antenna = ath10k_get_antenna, |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 5442 | .reconfig_complete = ath10k_reconfig_complete, |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 5443 | .get_survey = ath10k_get_survey, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5444 | .set_bitrate_mask = ath10k_set_bitrate_mask, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5445 | .sta_rc_update = ath10k_sta_rc_update, |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 5446 | .get_tsf = ath10k_get_tsf, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5447 | .ampdu_action = ath10k_ampdu_action, |
Ben Greear | 6cddcc7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 5448 | .get_et_sset_count = ath10k_debug_get_et_sset_count, |
| 5449 | .get_et_stats = ath10k_debug_get_et_stats, |
| 5450 | .get_et_strings = ath10k_debug_get_et_strings, |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 5451 | |
| 5452 | CFG80211_TESTMODE_CMD(ath10k_tm_cmd) |
| 5453 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 5454 | #ifdef CONFIG_PM |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 5455 | .suspend = ath10k_wow_op_suspend, |
| 5456 | .resume = ath10k_wow_op_resume, |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 5457 | #endif |
Rajkumar Manoharan | f504598 | 2015-01-12 14:07:27 +0200 | [diff] [blame] | 5458 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 5459 | .sta_add_debugfs = ath10k_sta_add_debugfs, |
| 5460 | #endif |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5461 | }; |
| 5462 | |
| 5463 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ |
| 5464 | .bitrate = (_rate), \ |
| 5465 | .flags = (_flags), \ |
| 5466 | .hw_value = (_rateid), \ |
| 5467 | } |
| 5468 | |
| 5469 | #define CHAN2G(_channel, _freq, _flags) { \ |
| 5470 | .band = IEEE80211_BAND_2GHZ, \ |
| 5471 | .hw_value = (_channel), \ |
| 5472 | .center_freq = (_freq), \ |
| 5473 | .flags = (_flags), \ |
| 5474 | .max_antenna_gain = 0, \ |
| 5475 | .max_power = 30, \ |
| 5476 | } |
| 5477 | |
| 5478 | #define CHAN5G(_channel, _freq, _flags) { \ |
| 5479 | .band = IEEE80211_BAND_5GHZ, \ |
| 5480 | .hw_value = (_channel), \ |
| 5481 | .center_freq = (_freq), \ |
| 5482 | .flags = (_flags), \ |
| 5483 | .max_antenna_gain = 0, \ |
| 5484 | .max_power = 30, \ |
| 5485 | } |
| 5486 | |
| 5487 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { |
| 5488 | CHAN2G(1, 2412, 0), |
| 5489 | CHAN2G(2, 2417, 0), |
| 5490 | CHAN2G(3, 2422, 0), |
| 5491 | CHAN2G(4, 2427, 0), |
| 5492 | CHAN2G(5, 2432, 0), |
| 5493 | CHAN2G(6, 2437, 0), |
| 5494 | CHAN2G(7, 2442, 0), |
| 5495 | CHAN2G(8, 2447, 0), |
| 5496 | CHAN2G(9, 2452, 0), |
| 5497 | CHAN2G(10, 2457, 0), |
| 5498 | CHAN2G(11, 2462, 0), |
| 5499 | CHAN2G(12, 2467, 0), |
| 5500 | CHAN2G(13, 2472, 0), |
| 5501 | CHAN2G(14, 2484, 0), |
| 5502 | }; |
| 5503 | |
| 5504 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 5505 | CHAN5G(36, 5180, 0), |
| 5506 | CHAN5G(40, 5200, 0), |
| 5507 | CHAN5G(44, 5220, 0), |
| 5508 | CHAN5G(48, 5240, 0), |
| 5509 | CHAN5G(52, 5260, 0), |
| 5510 | CHAN5G(56, 5280, 0), |
| 5511 | CHAN5G(60, 5300, 0), |
| 5512 | CHAN5G(64, 5320, 0), |
| 5513 | CHAN5G(100, 5500, 0), |
| 5514 | CHAN5G(104, 5520, 0), |
| 5515 | CHAN5G(108, 5540, 0), |
| 5516 | CHAN5G(112, 5560, 0), |
| 5517 | CHAN5G(116, 5580, 0), |
| 5518 | CHAN5G(120, 5600, 0), |
| 5519 | CHAN5G(124, 5620, 0), |
| 5520 | CHAN5G(128, 5640, 0), |
| 5521 | CHAN5G(132, 5660, 0), |
| 5522 | CHAN5G(136, 5680, 0), |
| 5523 | CHAN5G(140, 5700, 0), |
Peter Oh | 4a7898f | 2015-03-18 11:39:18 -0700 | [diff] [blame] | 5524 | CHAN5G(144, 5720, 0), |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 5525 | CHAN5G(149, 5745, 0), |
| 5526 | CHAN5G(153, 5765, 0), |
| 5527 | CHAN5G(157, 5785, 0), |
| 5528 | CHAN5G(161, 5805, 0), |
| 5529 | CHAN5G(165, 5825, 0), |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5530 | }; |
| 5531 | |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 5532 | /* Note: Be careful if you re-order these. There is code which depends on this |
| 5533 | * ordering. |
| 5534 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5535 | static struct ieee80211_rate ath10k_rates[] = { |
| 5536 | /* CCK */ |
| 5537 | RATETAB_ENT(10, 0x82, 0), |
| 5538 | RATETAB_ENT(20, 0x84, 0), |
| 5539 | RATETAB_ENT(55, 0x8b, 0), |
| 5540 | RATETAB_ENT(110, 0x96, 0), |
| 5541 | /* OFDM */ |
| 5542 | RATETAB_ENT(60, 0x0c, 0), |
| 5543 | RATETAB_ENT(90, 0x12, 0), |
| 5544 | RATETAB_ENT(120, 0x18, 0), |
| 5545 | RATETAB_ENT(180, 0x24, 0), |
| 5546 | RATETAB_ENT(240, 0x30, 0), |
| 5547 | RATETAB_ENT(360, 0x48, 0), |
| 5548 | RATETAB_ENT(480, 0x60, 0), |
| 5549 | RATETAB_ENT(540, 0x6c, 0), |
| 5550 | }; |
| 5551 | |
| 5552 | #define ath10k_a_rates (ath10k_rates + 4) |
| 5553 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4) |
| 5554 | #define ath10k_g_rates (ath10k_rates + 0) |
| 5555 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) |
| 5556 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 5557 | struct ath10k *ath10k_mac_create(size_t priv_size) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5558 | { |
| 5559 | struct ieee80211_hw *hw; |
| 5560 | struct ath10k *ar; |
| 5561 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 5562 | hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5563 | if (!hw) |
| 5564 | return NULL; |
| 5565 | |
| 5566 | ar = hw->priv; |
| 5567 | ar->hw = hw; |
| 5568 | |
| 5569 | return ar; |
| 5570 | } |
| 5571 | |
| 5572 | void ath10k_mac_destroy(struct ath10k *ar) |
| 5573 | { |
| 5574 | ieee80211_free_hw(ar->hw); |
| 5575 | } |
| 5576 | |
| 5577 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { |
| 5578 | { |
| 5579 | .max = 8, |
| 5580 | .types = BIT(NL80211_IFTYPE_STATION) |
| 5581 | | BIT(NL80211_IFTYPE_P2P_CLIENT) |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 5582 | }, |
| 5583 | { |
| 5584 | .max = 3, |
| 5585 | .types = BIT(NL80211_IFTYPE_P2P_GO) |
| 5586 | }, |
| 5587 | { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 5588 | .max = 1, |
| 5589 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) |
| 5590 | }, |
| 5591 | { |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 5592 | .max = 7, |
| 5593 | .types = BIT(NL80211_IFTYPE_AP) |
| 5594 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5595 | }; |
| 5596 | |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5597 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5598 | { |
| 5599 | .max = 8, |
| 5600 | .types = BIT(NL80211_IFTYPE_AP) |
| 5601 | }, |
| 5602 | }; |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5603 | |
| 5604 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { |
| 5605 | { |
| 5606 | .limits = ath10k_if_limits, |
| 5607 | .n_limits = ARRAY_SIZE(ath10k_if_limits), |
| 5608 | .max_interfaces = 8, |
| 5609 | .num_different_channels = 1, |
| 5610 | .beacon_int_infra_match = true, |
| 5611 | }, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5612 | }; |
| 5613 | |
| 5614 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5615 | { |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5616 | .limits = ath10k_10x_if_limits, |
| 5617 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5618 | .max_interfaces = 8, |
| 5619 | .num_different_channels = 1, |
| 5620 | .beacon_int_infra_match = true, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5621 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5622 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 5623 | BIT(NL80211_CHAN_WIDTH_20) | |
| 5624 | BIT(NL80211_CHAN_WIDTH_40) | |
| 5625 | BIT(NL80211_CHAN_WIDTH_80), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5626 | #endif |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5627 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5628 | }; |
| 5629 | |
| 5630 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) |
| 5631 | { |
| 5632 | struct ieee80211_sta_vht_cap vht_cap = {0}; |
| 5633 | u16 mcs_map; |
Michal Kazior | bc657a36 | 2015-02-26 11:11:22 +0100 | [diff] [blame] | 5634 | u32 val; |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 5635 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5636 | |
| 5637 | vht_cap.vht_supported = 1; |
| 5638 | vht_cap.cap = ar->vht_cap_info; |
| 5639 | |
Michal Kazior | bc657a36 | 2015-02-26 11:11:22 +0100 | [diff] [blame] | 5640 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 5641 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 5642 | val = ar->num_rf_chains - 1; |
| 5643 | val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; |
| 5644 | val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 5645 | |
| 5646 | vht_cap.cap |= val; |
| 5647 | } |
| 5648 | |
| 5649 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 5650 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 5651 | val = ar->num_rf_chains - 1; |
| 5652 | val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; |
| 5653 | val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; |
| 5654 | |
| 5655 | vht_cap.cap |= val; |
| 5656 | } |
| 5657 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 5658 | mcs_map = 0; |
| 5659 | for (i = 0; i < 8; i++) { |
| 5660 | if (i < ar->num_rf_chains) |
| 5661 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2); |
| 5662 | else |
| 5663 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2); |
| 5664 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5665 | |
| 5666 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 5667 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 5668 | |
| 5669 | return vht_cap; |
| 5670 | } |
| 5671 | |
| 5672 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) |
| 5673 | { |
| 5674 | int i; |
| 5675 | struct ieee80211_sta_ht_cap ht_cap = {0}; |
| 5676 | |
| 5677 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) |
| 5678 | return ht_cap; |
| 5679 | |
| 5680 | ht_cap.ht_supported = 1; |
| 5681 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 5682 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; |
| 5683 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 5684 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 5685 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 5686 | |
| 5687 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) |
| 5688 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 5689 | |
| 5690 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) |
| 5691 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 5692 | |
| 5693 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { |
| 5694 | u32 smps; |
| 5695 | |
| 5696 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; |
| 5697 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 5698 | |
| 5699 | ht_cap.cap |= smps; |
| 5700 | } |
| 5701 | |
| 5702 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC) |
| 5703 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 5704 | |
| 5705 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { |
| 5706 | u32 stbc; |
| 5707 | |
| 5708 | stbc = ar->ht_cap_info; |
| 5709 | stbc &= WMI_HT_CAP_RX_STBC; |
| 5710 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; |
| 5711 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 5712 | stbc &= IEEE80211_HT_CAP_RX_STBC; |
| 5713 | |
| 5714 | ht_cap.cap |= stbc; |
| 5715 | } |
| 5716 | |
| 5717 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC) |
| 5718 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; |
| 5719 | |
| 5720 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) |
| 5721 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; |
| 5722 | |
| 5723 | /* max AMSDU is implicitly taken from vht_cap_info */ |
| 5724 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) |
| 5725 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
| 5726 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 5727 | for (i = 0; i < ar->num_rf_chains; i++) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5728 | ht_cap.mcs.rx_mask[i] = 0xFF; |
| 5729 | |
| 5730 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
| 5731 | |
| 5732 | return ht_cap; |
| 5733 | } |
| 5734 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5735 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
| 5736 | struct ieee80211_vif *vif) |
| 5737 | { |
| 5738 | struct ath10k_vif_iter *arvif_iter = data; |
| 5739 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5740 | |
| 5741 | if (arvif->vdev_id == arvif_iter->vdev_id) |
| 5742 | arvif_iter->arvif = arvif; |
| 5743 | } |
| 5744 | |
| 5745 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) |
| 5746 | { |
| 5747 | struct ath10k_vif_iter arvif_iter; |
| 5748 | u32 flags; |
| 5749 | |
| 5750 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); |
| 5751 | arvif_iter.vdev_id = vdev_id; |
| 5752 | |
| 5753 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; |
| 5754 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 5755 | flags, |
| 5756 | ath10k_get_arvif_iter, |
| 5757 | &arvif_iter); |
| 5758 | if (!arvif_iter.arvif) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5759 | ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5760 | return NULL; |
| 5761 | } |
| 5762 | |
| 5763 | return arvif_iter.arvif; |
| 5764 | } |
| 5765 | |
| 5766 | int ath10k_mac_register(struct ath10k *ar) |
| 5767 | { |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 5768 | static const u32 cipher_suites[] = { |
| 5769 | WLAN_CIPHER_SUITE_WEP40, |
| 5770 | WLAN_CIPHER_SUITE_WEP104, |
| 5771 | WLAN_CIPHER_SUITE_TKIP, |
| 5772 | WLAN_CIPHER_SUITE_CCMP, |
| 5773 | WLAN_CIPHER_SUITE_AES_CMAC, |
| 5774 | }; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5775 | struct ieee80211_supported_band *band; |
| 5776 | struct ieee80211_sta_vht_cap vht_cap; |
| 5777 | struct ieee80211_sta_ht_cap ht_cap; |
| 5778 | void *channels; |
| 5779 | int ret; |
| 5780 | |
| 5781 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); |
| 5782 | |
| 5783 | SET_IEEE80211_DEV(ar->hw, ar->dev); |
| 5784 | |
| 5785 | ht_cap = ath10k_get_ht_cap(ar); |
| 5786 | vht_cap = ath10k_create_vht_cap(ar); |
| 5787 | |
| 5788 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
| 5789 | channels = kmemdup(ath10k_2ghz_channels, |
| 5790 | sizeof(ath10k_2ghz_channels), |
| 5791 | GFP_KERNEL); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5792 | if (!channels) { |
| 5793 | ret = -ENOMEM; |
| 5794 | goto err_free; |
| 5795 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5796 | |
| 5797 | band = &ar->mac.sbands[IEEE80211_BAND_2GHZ]; |
| 5798 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); |
| 5799 | band->channels = channels; |
| 5800 | band->n_bitrates = ath10k_g_rates_size; |
| 5801 | band->bitrates = ath10k_g_rates; |
| 5802 | band->ht_cap = ht_cap; |
| 5803 | |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 5804 | /* Enable the VHT support at 2.4 GHz */ |
| 5805 | band->vht_cap = vht_cap; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5806 | |
| 5807 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band; |
| 5808 | } |
| 5809 | |
| 5810 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { |
| 5811 | channels = kmemdup(ath10k_5ghz_channels, |
| 5812 | sizeof(ath10k_5ghz_channels), |
| 5813 | GFP_KERNEL); |
| 5814 | if (!channels) { |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5815 | ret = -ENOMEM; |
| 5816 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | band = &ar->mac.sbands[IEEE80211_BAND_5GHZ]; |
| 5820 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); |
| 5821 | band->channels = channels; |
| 5822 | band->n_bitrates = ath10k_a_rates_size; |
| 5823 | band->bitrates = ath10k_a_rates; |
| 5824 | band->ht_cap = ht_cap; |
| 5825 | band->vht_cap = vht_cap; |
| 5826 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band; |
| 5827 | } |
| 5828 | |
| 5829 | ar->hw->wiphy->interface_modes = |
| 5830 | BIT(NL80211_IFTYPE_STATION) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 5831 | BIT(NL80211_IFTYPE_AP); |
| 5832 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 5833 | ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask; |
| 5834 | ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask; |
| 5835 | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 5836 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features)) |
| 5837 | ar->hw->wiphy->interface_modes |= |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 5838 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 5839 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5840 | BIT(NL80211_IFTYPE_P2P_GO); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5841 | |
| 5842 | ar->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 5843 | IEEE80211_HW_SUPPORTS_PS | |
| 5844 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5845 | IEEE80211_HW_MFP_CAPABLE | |
| 5846 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 5847 | IEEE80211_HW_HAS_RATE_CONTROL | |
Janusz Dziedzic | 2f0f112 | 2014-02-26 18:42:09 +0200 | [diff] [blame] | 5848 | IEEE80211_HW_AP_LINK_PS | |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 5849 | IEEE80211_HW_SPECTRUM_MGMT | |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 5850 | IEEE80211_HW_SW_CRYPTO_CONTROL | |
| 5851 | IEEE80211_HW_CONNECTION_MONITOR; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5852 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 5853 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
| 5854 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5855 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 5856 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5857 | |
| 5858 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { |
| 5859 | ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; |
| 5860 | ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW; |
| 5861 | } |
| 5862 | |
| 5863 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
| 5864 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; |
| 5865 | |
| 5866 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5867 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5868 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5869 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
| 5870 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 5871 | if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) { |
| 5872 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 5873 | |
| 5874 | /* Firmware delivers WPS/P2P Probe Requests frames to driver so |
| 5875 | * that userspace (e.g. wpa_supplicant/hostapd) can generate |
| 5876 | * correct Probe Responses. This is more of a hack advert.. |
| 5877 | */ |
| 5878 | ar->hw->wiphy->probe_resp_offload |= |
| 5879 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 5880 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 5881 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 5882 | } |
| 5883 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5884 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 5885 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5886 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 5887 | |
| 5888 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
Rajkumar Manoharan | 78157a1 | 2014-11-17 16:44:15 +0200 | [diff] [blame] | 5889 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE; |
| 5890 | |
Janusz.Dziedzic@tieto.com | 37a0b39 | 2015-03-12 13:11:41 +0100 | [diff] [blame] | 5891 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; |
| 5892 | |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 5893 | ret = ath10k_wow_init(ar); |
| 5894 | if (ret) { |
| 5895 | ath10k_warn(ar, "failed to init wow: %d\n", ret); |
| 5896 | goto err_free; |
| 5897 | } |
| 5898 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5899 | /* |
| 5900 | * on LL hardware queues are managed entirely by the FW |
| 5901 | * so we only advertise to mac we can do the queues thing |
| 5902 | */ |
| 5903 | ar->hw->queues = 4; |
| 5904 | |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 5905 | switch (ar->wmi.op_version) { |
| 5906 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
| 5907 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5908 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
| 5909 | ar->hw->wiphy->n_iface_combinations = |
| 5910 | ARRAY_SIZE(ath10k_if_comb); |
Michal Kazior | cf850d1 | 2014-07-24 20:07:00 +0300 | [diff] [blame] | 5911 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 5912 | break; |
| 5913 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
| 5914 | case ATH10K_FW_WMI_OP_VERSION_10_2: |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 5915 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 5916 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
| 5917 | ar->hw->wiphy->n_iface_combinations = |
| 5918 | ARRAY_SIZE(ath10k_10x_if_comb); |
| 5919 | break; |
| 5920 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
| 5921 | case ATH10K_FW_WMI_OP_VERSION_MAX: |
| 5922 | WARN_ON(1); |
| 5923 | ret = -EINVAL; |
| 5924 | goto err_free; |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5925 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5926 | |
Michal Kazior | 7c19999 | 2013-07-31 10:47:57 +0200 | [diff] [blame] | 5927 | ar->hw->netdev_features = NETIF_F_HW_CSUM; |
| 5928 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 5929 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
| 5930 | /* Init ath dfs pattern detector */ |
| 5931 | ar->ath_common.debug_mask = ATH_DBG_DFS; |
| 5932 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, |
| 5933 | NL80211_DFS_UNSET); |
| 5934 | |
| 5935 | if (!ar->dfs_detector) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5936 | ath10k_warn(ar, "failed to initialise DFS pattern detector\n"); |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 5937 | } |
| 5938 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5939 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
| 5940 | ath10k_reg_notifier); |
| 5941 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5942 | ath10k_err(ar, "failed to initialise regulatory: %i\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5943 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5944 | } |
| 5945 | |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 5946 | ar->hw->wiphy->cipher_suites = cipher_suites; |
| 5947 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 5948 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5949 | ret = ieee80211_register_hw(ar->hw); |
| 5950 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5951 | ath10k_err(ar, "failed to register ieee80211: %d\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5952 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5953 | } |
| 5954 | |
| 5955 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { |
| 5956 | ret = regulatory_hint(ar->hw->wiphy, |
| 5957 | ar->ath_common.regulatory.alpha2); |
| 5958 | if (ret) |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5959 | goto err_unregister; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | return 0; |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5963 | |
| 5964 | err_unregister: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5965 | ieee80211_unregister_hw(ar->hw); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5966 | err_free: |
| 5967 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 5968 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 5969 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5970 | return ret; |
| 5971 | } |
| 5972 | |
| 5973 | void ath10k_mac_unregister(struct ath10k *ar) |
| 5974 | { |
| 5975 | ieee80211_unregister_hw(ar->hw); |
| 5976 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 5977 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
| 5978 | ar->dfs_detector->exit(ar->dfs_detector); |
| 5979 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5980 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 5981 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 5982 | |
| 5983 | SET_IEEE80211_DEV(ar->hw, NULL); |
| 5984 | } |