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