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: |
| 69 | /* this one needs to be done in software */ |
| 70 | return 1; |
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 || |
Vasanthakumar Thiagarajan | 5484621 | 2015-03-02 17:45:28 +0530 | [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 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1512 | /**********************/ |
| 1513 | /* Station management */ |
| 1514 | /**********************/ |
| 1515 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1516 | static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar, |
| 1517 | struct ieee80211_vif *vif) |
| 1518 | { |
| 1519 | /* Some firmware revisions have unstable STA powersave when listen |
| 1520 | * interval is set too high (e.g. 5). The symptoms are firmware doesn't |
| 1521 | * generate NullFunc frames properly even if buffered frames have been |
| 1522 | * indicated in Beacon TIM. Firmware would seldom wake up to pull |
| 1523 | * buffered frames. Often pinging the device from AP would simply fail. |
| 1524 | * |
| 1525 | * As a workaround set it to 1. |
| 1526 | */ |
| 1527 | if (vif->type == NL80211_IFTYPE_STATION) |
| 1528 | return 1; |
| 1529 | |
| 1530 | return ar->hw->conf.listen_interval; |
| 1531 | } |
| 1532 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1533 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1534 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1535 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1536 | struct wmi_peer_assoc_complete_arg *arg) |
| 1537 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1538 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1539 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1540 | lockdep_assert_held(&ar->conf_mutex); |
| 1541 | |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 1542 | ether_addr_copy(arg->addr, sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1543 | arg->vdev_id = arvif->vdev_id; |
| 1544 | arg->peer_aid = sta->aid; |
| 1545 | arg->peer_flags |= WMI_PEER_AUTH; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1546 | arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1547 | arg->peer_num_spatial_streams = 1; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1548 | arg->peer_caps = vif->bss_conf.assoc_capability; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1552 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1553 | struct wmi_peer_assoc_complete_arg *arg) |
| 1554 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1555 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
| 1556 | struct cfg80211_bss *bss; |
| 1557 | const u8 *rsnie = NULL; |
| 1558 | const u8 *wpaie = NULL; |
| 1559 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1560 | lockdep_assert_held(&ar->conf_mutex); |
| 1561 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1562 | bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan, |
| 1563 | info->bssid, NULL, 0, 0, 0); |
| 1564 | if (bss) { |
| 1565 | const struct cfg80211_bss_ies *ies; |
| 1566 | |
| 1567 | rcu_read_lock(); |
| 1568 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); |
| 1569 | |
| 1570 | ies = rcu_dereference(bss->ies); |
| 1571 | |
| 1572 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1573 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 1574 | ies->data, |
| 1575 | ies->len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1576 | rcu_read_unlock(); |
| 1577 | cfg80211_put_bss(ar->hw->wiphy, bss); |
| 1578 | } |
| 1579 | |
| 1580 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ |
| 1581 | if (rsnie || wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1582 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1583 | arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; |
| 1584 | } |
| 1585 | |
| 1586 | if (wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1587 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1588 | arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; |
| 1589 | } |
| 1590 | } |
| 1591 | |
| 1592 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, |
| 1593 | struct ieee80211_sta *sta, |
| 1594 | struct wmi_peer_assoc_complete_arg *arg) |
| 1595 | { |
| 1596 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
| 1597 | const struct ieee80211_supported_band *sband; |
| 1598 | const struct ieee80211_rate *rates; |
| 1599 | u32 ratemask; |
| 1600 | int i; |
| 1601 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1602 | lockdep_assert_held(&ar->conf_mutex); |
| 1603 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1604 | sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band]; |
| 1605 | ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band]; |
| 1606 | rates = sband->bitrates; |
| 1607 | |
| 1608 | rateset->num_rates = 0; |
| 1609 | |
| 1610 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { |
| 1611 | if (!(ratemask & 1)) |
| 1612 | continue; |
| 1613 | |
| 1614 | rateset->rates[rateset->num_rates] = rates->hw_value; |
| 1615 | rateset->num_rates++; |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, |
| 1620 | struct ieee80211_sta *sta, |
| 1621 | struct wmi_peer_assoc_complete_arg *arg) |
| 1622 | { |
| 1623 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1624 | int i, n; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 1625 | u32 stbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1626 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1627 | lockdep_assert_held(&ar->conf_mutex); |
| 1628 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1629 | if (!ht_cap->ht_supported) |
| 1630 | return; |
| 1631 | |
| 1632 | arg->peer_flags |= WMI_PEER_HT; |
| 1633 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 1634 | ht_cap->ampdu_factor)) - 1; |
| 1635 | |
| 1636 | arg->peer_mpdu_density = |
| 1637 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); |
| 1638 | |
| 1639 | arg->peer_ht_caps = ht_cap->cap; |
| 1640 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; |
| 1641 | |
| 1642 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) |
| 1643 | arg->peer_flags |= WMI_PEER_LDPC; |
| 1644 | |
| 1645 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
| 1646 | arg->peer_flags |= WMI_PEER_40MHZ; |
| 1647 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; |
| 1648 | } |
| 1649 | |
| 1650 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) |
| 1651 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 1652 | |
| 1653 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) |
| 1654 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 1655 | |
| 1656 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { |
| 1657 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; |
| 1658 | arg->peer_flags |= WMI_PEER_STBC; |
| 1659 | } |
| 1660 | |
| 1661 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1662 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
| 1663 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 1664 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; |
| 1665 | arg->peer_rate_caps |= stbc; |
| 1666 | arg->peer_flags |= WMI_PEER_STBC; |
| 1667 | } |
| 1668 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1669 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
| 1670 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; |
| 1671 | else if (ht_cap->mcs.rx_mask[1]) |
| 1672 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; |
| 1673 | |
| 1674 | for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++) |
| 1675 | if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8)) |
| 1676 | arg->peer_ht_rates.rates[n++] = i; |
| 1677 | |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 1678 | /* |
| 1679 | * This is a workaround for HT-enabled STAs which break the spec |
| 1680 | * and have no HT capabilities RX mask (no HT RX MCS map). |
| 1681 | * |
| 1682 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), |
| 1683 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. |
| 1684 | * |
| 1685 | * Firmware asserts if such situation occurs. |
| 1686 | */ |
| 1687 | if (n == 0) { |
| 1688 | arg->peer_ht_rates.num_rates = 8; |
| 1689 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) |
| 1690 | arg->peer_ht_rates.rates[i] = i; |
| 1691 | } else { |
| 1692 | arg->peer_ht_rates.num_rates = n; |
| 1693 | arg->peer_num_spatial_streams = sta->rx_nss; |
| 1694 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1695 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1696 | 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] | 1697 | arg->addr, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1698 | arg->peer_ht_rates.num_rates, |
| 1699 | arg->peer_num_spatial_streams); |
| 1700 | } |
| 1701 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1702 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
| 1703 | struct ath10k_vif *arvif, |
| 1704 | struct ieee80211_sta *sta) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1705 | { |
| 1706 | u32 uapsd = 0; |
| 1707 | u32 max_sp = 0; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1708 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1709 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1710 | lockdep_assert_held(&ar->conf_mutex); |
| 1711 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1712 | if (sta->wme && sta->uapsd_queues) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1713 | 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] | 1714 | sta->uapsd_queues, sta->max_sp); |
| 1715 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1716 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 1717 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | |
| 1718 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; |
| 1719 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 1720 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | |
| 1721 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; |
| 1722 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 1723 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | |
| 1724 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; |
| 1725 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 1726 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | |
| 1727 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; |
| 1728 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1729 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
| 1730 | max_sp = sta->max_sp; |
| 1731 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1732 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 1733 | sta->addr, |
| 1734 | WMI_AP_PS_PEER_PARAM_UAPSD, |
| 1735 | uapsd); |
| 1736 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1737 | 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] | 1738 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1739 | return ret; |
| 1740 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1741 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1742 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 1743 | sta->addr, |
| 1744 | WMI_AP_PS_PEER_PARAM_MAX_SP, |
| 1745 | max_sp); |
| 1746 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1747 | 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] | 1748 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1749 | return ret; |
| 1750 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1751 | |
| 1752 | /* TODO setup this based on STA listen interval and |
| 1753 | beacon interval. Currently we don't know |
| 1754 | sta->listen_interval - mac80211 patch required. |
| 1755 | Currently use 10 seconds */ |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1756 | 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] | 1757 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, |
| 1758 | 10); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1759 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1760 | 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] | 1761 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1762 | return ret; |
| 1763 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1764 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1765 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1766 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, |
| 1770 | struct ieee80211_sta *sta, |
| 1771 | struct wmi_peer_assoc_complete_arg *arg) |
| 1772 | { |
| 1773 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 1774 | u8 ampdu_factor; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1775 | |
| 1776 | if (!vht_cap->vht_supported) |
| 1777 | return; |
| 1778 | |
| 1779 | arg->peer_flags |= WMI_PEER_VHT; |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 1780 | |
| 1781 | if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) |
| 1782 | arg->peer_flags |= WMI_PEER_VHT_2G; |
| 1783 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1784 | arg->peer_vht_caps = vht_cap->cap; |
| 1785 | |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 1786 | ampdu_factor = (vht_cap->cap & |
| 1787 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> |
| 1788 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 1789 | |
| 1790 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to |
| 1791 | * zero in VHT IE. Using it would result in degraded throughput. |
| 1792 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep |
| 1793 | * it if VHT max_mpdu is smaller. */ |
| 1794 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
| 1795 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 1796 | ampdu_factor)) - 1); |
| 1797 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1798 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 1799 | arg->peer_flags |= WMI_PEER_80MHZ; |
| 1800 | |
| 1801 | arg->peer_vht_rates.rx_max_rate = |
| 1802 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
| 1803 | arg->peer_vht_rates.rx_mcs_set = |
| 1804 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 1805 | arg->peer_vht_rates.tx_max_rate = |
| 1806 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); |
| 1807 | arg->peer_vht_rates.tx_mcs_set = |
| 1808 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); |
| 1809 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1810 | 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] | 1811 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1815 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1816 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1817 | struct wmi_peer_assoc_complete_arg *arg) |
| 1818 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1819 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1820 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1821 | switch (arvif->vdev_type) { |
| 1822 | case WMI_VDEV_TYPE_AP: |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1823 | if (sta->wme) |
| 1824 | arg->peer_flags |= WMI_PEER_QOS; |
| 1825 | |
| 1826 | if (sta->wme && sta->uapsd_queues) { |
| 1827 | arg->peer_flags |= WMI_PEER_APSD; |
| 1828 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; |
| 1829 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1830 | break; |
| 1831 | case WMI_VDEV_TYPE_STA: |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1832 | if (vif->bss_conf.qos) |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1833 | arg->peer_flags |= WMI_PEER_QOS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1834 | break; |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 1835 | case WMI_VDEV_TYPE_IBSS: |
| 1836 | if (sta->wme) |
| 1837 | arg->peer_flags |= WMI_PEER_QOS; |
| 1838 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1839 | default: |
| 1840 | break; |
| 1841 | } |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 1842 | |
| 1843 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n", |
| 1844 | sta->addr, !!(arg->peer_flags & WMI_PEER_QOS)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1845 | } |
| 1846 | |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 1847 | static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta) |
| 1848 | { |
| 1849 | /* First 4 rates in ath10k_rates are CCK (11b) rates. */ |
| 1850 | return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4; |
| 1851 | } |
| 1852 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1853 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1854 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1855 | struct ieee80211_sta *sta, |
| 1856 | struct wmi_peer_assoc_complete_arg *arg) |
| 1857 | { |
| 1858 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 1859 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1860 | switch (ar->hw->conf.chandef.chan->band) { |
| 1861 | case IEEE80211_BAND_2GHZ: |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 1862 | if (sta->vht_cap.vht_supported) { |
| 1863 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1864 | phymode = MODE_11AC_VHT40; |
| 1865 | else |
| 1866 | phymode = MODE_11AC_VHT20; |
| 1867 | } else if (sta->ht_cap.ht_supported) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1868 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1869 | phymode = MODE_11NG_HT40; |
| 1870 | else |
| 1871 | phymode = MODE_11NG_HT20; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 1872 | } else if (ath10k_mac_sta_has_11g_rates(sta)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1873 | phymode = MODE_11G; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 1874 | } else { |
| 1875 | phymode = MODE_11B; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | break; |
| 1879 | case IEEE80211_BAND_5GHZ: |
Sujith Manoharan | 7cc45e9 | 2013-09-08 18:19:55 +0300 | [diff] [blame] | 1880 | /* |
| 1881 | * Check VHT first. |
| 1882 | */ |
| 1883 | if (sta->vht_cap.vht_supported) { |
| 1884 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 1885 | phymode = MODE_11AC_VHT80; |
| 1886 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1887 | phymode = MODE_11AC_VHT40; |
| 1888 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 1889 | phymode = MODE_11AC_VHT20; |
| 1890 | } else if (sta->ht_cap.ht_supported) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1891 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1892 | phymode = MODE_11NA_HT40; |
| 1893 | else |
| 1894 | phymode = MODE_11NA_HT20; |
| 1895 | } else { |
| 1896 | phymode = MODE_11A; |
| 1897 | } |
| 1898 | |
| 1899 | break; |
| 1900 | default: |
| 1901 | break; |
| 1902 | } |
| 1903 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1904 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
Kalle Valo | 38a1d47 | 2013-09-08 17:56:14 +0300 | [diff] [blame] | 1905 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1906 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1907 | arg->peer_phymode = phymode; |
| 1908 | WARN_ON(phymode == MODE_UNKNOWN); |
| 1909 | } |
| 1910 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1911 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1912 | struct ieee80211_vif *vif, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1913 | struct ieee80211_sta *sta, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1914 | struct wmi_peer_assoc_complete_arg *arg) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1915 | { |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1916 | lockdep_assert_held(&ar->conf_mutex); |
| 1917 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1918 | memset(arg, 0, sizeof(*arg)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1919 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1920 | ath10k_peer_assoc_h_basic(ar, vif, sta, arg); |
| 1921 | ath10k_peer_assoc_h_crypto(ar, vif, arg); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1922 | ath10k_peer_assoc_h_rates(ar, sta, arg); |
| 1923 | ath10k_peer_assoc_h_ht(ar, sta, arg); |
| 1924 | ath10k_peer_assoc_h_vht(ar, sta, arg); |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1925 | ath10k_peer_assoc_h_qos(ar, vif, sta, arg); |
| 1926 | ath10k_peer_assoc_h_phymode(ar, vif, sta, arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1927 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1928 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1929 | } |
| 1930 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 1931 | static const u32 ath10k_smps_map[] = { |
| 1932 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, |
| 1933 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, |
| 1934 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, |
| 1935 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, |
| 1936 | }; |
| 1937 | |
| 1938 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, |
| 1939 | const u8 *addr, |
| 1940 | const struct ieee80211_sta_ht_cap *ht_cap) |
| 1941 | { |
| 1942 | int smps; |
| 1943 | |
| 1944 | if (!ht_cap->ht_supported) |
| 1945 | return 0; |
| 1946 | |
| 1947 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; |
| 1948 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 1949 | |
| 1950 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) |
| 1951 | return -EINVAL; |
| 1952 | |
| 1953 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, |
| 1954 | WMI_PEER_SMPS_STATE, |
| 1955 | ath10k_smps_map[smps]); |
| 1956 | } |
| 1957 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 1958 | static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, |
| 1959 | struct ieee80211_vif *vif, |
| 1960 | struct ieee80211_sta_vht_cap vht_cap) |
| 1961 | { |
| 1962 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1963 | int ret; |
| 1964 | u32 param; |
| 1965 | u32 value; |
| 1966 | |
| 1967 | if (!(ar->vht_cap_info & |
| 1968 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 1969 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | |
| 1970 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 1971 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 1972 | return 0; |
| 1973 | |
| 1974 | param = ar->wmi.vdev_param->txbf; |
| 1975 | value = 0; |
| 1976 | |
| 1977 | if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED)) |
| 1978 | return 0; |
| 1979 | |
| 1980 | /* The following logic is correct. If a remote STA advertises support |
| 1981 | * for being a beamformer then we should enable us being a beamformee. |
| 1982 | */ |
| 1983 | |
| 1984 | if (ar->vht_cap_info & |
| 1985 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 1986 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 1987 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) |
| 1988 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 1989 | |
| 1990 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) |
| 1991 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; |
| 1992 | } |
| 1993 | |
| 1994 | if (ar->vht_cap_info & |
| 1995 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 1996 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 1997 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) |
| 1998 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 1999 | |
| 2000 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) |
| 2001 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; |
| 2002 | } |
| 2003 | |
| 2004 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE) |
| 2005 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2006 | |
| 2007 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER) |
| 2008 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2009 | |
| 2010 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value); |
| 2011 | if (ret) { |
| 2012 | ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n", |
| 2013 | value, ret); |
| 2014 | return ret; |
| 2015 | } |
| 2016 | |
| 2017 | return 0; |
| 2018 | } |
| 2019 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2020 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
| 2021 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, |
| 2022 | struct ieee80211_vif *vif, |
| 2023 | struct ieee80211_bss_conf *bss_conf) |
| 2024 | { |
| 2025 | struct ath10k *ar = hw->priv; |
| 2026 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2027 | struct ieee80211_sta_ht_cap ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2028 | struct ieee80211_sta_vht_cap vht_cap; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2029 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2030 | struct ieee80211_sta *ap_sta; |
| 2031 | int ret; |
| 2032 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2033 | lockdep_assert_held(&ar->conf_mutex); |
| 2034 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2035 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", |
| 2036 | arvif->vdev_id, arvif->bssid, arvif->aid); |
| 2037 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2038 | rcu_read_lock(); |
| 2039 | |
| 2040 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 2041 | if (!ap_sta) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2042 | 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] | 2043 | bss_conf->bssid, arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2044 | rcu_read_unlock(); |
| 2045 | return; |
| 2046 | } |
| 2047 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2048 | /* ap_sta must be accessed only within rcu section which must be left |
| 2049 | * before calling ath10k_setup_peer_smps() which might sleep. */ |
| 2050 | ht_cap = ap_sta->ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2051 | vht_cap = ap_sta->vht_cap; |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2052 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2053 | ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2054 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2055 | 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] | 2056 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2057 | rcu_read_unlock(); |
| 2058 | return; |
| 2059 | } |
| 2060 | |
| 2061 | rcu_read_unlock(); |
| 2062 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2063 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2064 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2065 | 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] | 2066 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2067 | return; |
| 2068 | } |
| 2069 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2070 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
| 2071 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2072 | 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] | 2073 | arvif->vdev_id, ret); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2074 | return; |
| 2075 | } |
| 2076 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2077 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2078 | if (ret) { |
| 2079 | ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n", |
| 2080 | arvif->vdev_id, bss_conf->bssid, ret); |
| 2081 | return; |
| 2082 | } |
| 2083 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2084 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2085 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
| 2086 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); |
| 2087 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2088 | WARN_ON(arvif->is_up); |
| 2089 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2090 | arvif->aid = bss_conf->aid; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 2091 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2092 | |
| 2093 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); |
| 2094 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2095 | ath10k_warn(ar, "failed to set vdev %d up: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2096 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2097 | return; |
| 2098 | } |
| 2099 | |
| 2100 | arvif->is_up = true; |
Michal Kazior | 0a987fb | 2015-02-13 13:30:15 +0100 | [diff] [blame] | 2101 | |
| 2102 | /* Workaround: Some firmware revisions (tested with qca6174 |
| 2103 | * WLAN.RM.2.0-00073) have buggy powersave state machine and must be |
| 2104 | * poked with peer param command. |
| 2105 | */ |
| 2106 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid, |
| 2107 | WMI_PEER_DUMMY_VAR, 1); |
| 2108 | if (ret) { |
| 2109 | ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n", |
| 2110 | arvif->bssid, arvif->vdev_id, ret); |
| 2111 | return; |
| 2112 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2113 | } |
| 2114 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2115 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
| 2116 | struct ieee80211_vif *vif) |
| 2117 | { |
| 2118 | struct ath10k *ar = hw->priv; |
| 2119 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2120 | struct ieee80211_sta_vht_cap vht_cap = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2121 | int ret; |
| 2122 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2123 | lockdep_assert_held(&ar->conf_mutex); |
| 2124 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2125 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
| 2126 | arvif->vdev_id, arvif->bssid); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2127 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2128 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2129 | if (ret) |
| 2130 | ath10k_warn(ar, "faield to down vdev %i: %d\n", |
| 2131 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2132 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2133 | arvif->def_wep_key_idx = -1; |
| 2134 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2135 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2136 | if (ret) { |
| 2137 | ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n", |
| 2138 | arvif->vdev_id, ret); |
| 2139 | return; |
| 2140 | } |
| 2141 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2142 | arvif->is_up = false; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2143 | } |
| 2144 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2145 | static int ath10k_station_assoc(struct ath10k *ar, |
| 2146 | struct ieee80211_vif *vif, |
| 2147 | struct ieee80211_sta *sta, |
| 2148 | bool reassoc) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2149 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2150 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2151 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2152 | int ret = 0; |
| 2153 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2154 | lockdep_assert_held(&ar->conf_mutex); |
| 2155 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2156 | ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2157 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2158 | 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] | 2159 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2160 | return ret; |
| 2161 | } |
| 2162 | |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 2163 | peer_arg.peer_reassoc = reassoc; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2164 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2165 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2166 | 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] | 2167 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2168 | return ret; |
| 2169 | } |
| 2170 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2171 | /* Re-assoc is run only to update supported rates for given station. It |
| 2172 | * doesn't make much sense to reconfigure the peer completely. |
| 2173 | */ |
| 2174 | if (!reassoc) { |
| 2175 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, |
| 2176 | &sta->ht_cap); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2177 | if (ret) { |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2178 | 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] | 2179 | arvif->vdev_id, ret); |
| 2180 | return ret; |
| 2181 | } |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2182 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2183 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
| 2184 | if (ret) { |
| 2185 | ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", |
| 2186 | sta->addr, arvif->vdev_id, ret); |
| 2187 | return ret; |
| 2188 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2189 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2190 | if (!sta->wme) { |
| 2191 | arvif->num_legacy_stations++; |
| 2192 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 2193 | if (ret) { |
| 2194 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
| 2195 | arvif->vdev_id, ret); |
| 2196 | return ret; |
| 2197 | } |
| 2198 | } |
| 2199 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2200 | /* Plumb cached keys only for static WEP */ |
| 2201 | if (arvif->def_wep_key_idx != -1) { |
| 2202 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); |
| 2203 | if (ret) { |
| 2204 | ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", |
| 2205 | arvif->vdev_id, ret); |
| 2206 | return ret; |
| 2207 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2211 | return ret; |
| 2212 | } |
| 2213 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2214 | static int ath10k_station_disassoc(struct ath10k *ar, |
| 2215 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2216 | struct ieee80211_sta *sta) |
| 2217 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2218 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2219 | int ret = 0; |
| 2220 | |
| 2221 | lockdep_assert_held(&ar->conf_mutex); |
| 2222 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2223 | if (!sta->wme) { |
| 2224 | arvif->num_legacy_stations--; |
| 2225 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 2226 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2227 | 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] | 2228 | arvif->vdev_id, ret); |
| 2229 | return ret; |
| 2230 | } |
| 2231 | } |
| 2232 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2233 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
| 2234 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2235 | 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] | 2236 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2237 | return ret; |
| 2238 | } |
| 2239 | |
| 2240 | return ret; |
| 2241 | } |
| 2242 | |
| 2243 | /**************/ |
| 2244 | /* Regulatory */ |
| 2245 | /**************/ |
| 2246 | |
| 2247 | static int ath10k_update_channel_list(struct ath10k *ar) |
| 2248 | { |
| 2249 | struct ieee80211_hw *hw = ar->hw; |
| 2250 | struct ieee80211_supported_band **bands; |
| 2251 | enum ieee80211_band band; |
| 2252 | struct ieee80211_channel *channel; |
| 2253 | struct wmi_scan_chan_list_arg arg = {0}; |
| 2254 | struct wmi_channel_arg *ch; |
| 2255 | bool passive; |
| 2256 | int len; |
| 2257 | int ret; |
| 2258 | int i; |
| 2259 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2260 | lockdep_assert_held(&ar->conf_mutex); |
| 2261 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2262 | bands = hw->wiphy->bands; |
| 2263 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2264 | if (!bands[band]) |
| 2265 | continue; |
| 2266 | |
| 2267 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 2268 | if (bands[band]->channels[i].flags & |
| 2269 | IEEE80211_CHAN_DISABLED) |
| 2270 | continue; |
| 2271 | |
| 2272 | arg.n_channels++; |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; |
| 2277 | arg.channels = kzalloc(len, GFP_KERNEL); |
| 2278 | if (!arg.channels) |
| 2279 | return -ENOMEM; |
| 2280 | |
| 2281 | ch = arg.channels; |
| 2282 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2283 | if (!bands[band]) |
| 2284 | continue; |
| 2285 | |
| 2286 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 2287 | channel = &bands[band]->channels[i]; |
| 2288 | |
| 2289 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 2290 | continue; |
| 2291 | |
| 2292 | ch->allow_ht = true; |
| 2293 | |
| 2294 | /* FIXME: when should we really allow VHT? */ |
| 2295 | ch->allow_vht = true; |
| 2296 | |
| 2297 | ch->allow_ibss = |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2298 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2299 | |
| 2300 | ch->ht40plus = |
| 2301 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); |
| 2302 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 2303 | ch->chan_radar = |
| 2304 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
| 2305 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2306 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2307 | ch->passive = passive; |
| 2308 | |
| 2309 | ch->freq = channel->center_freq; |
Michal Kazior | 2d66721 | 2014-09-18 15:21:21 +0200 | [diff] [blame] | 2310 | ch->band_center_freq1 = channel->center_freq; |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 2311 | ch->min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 2312 | ch->max_power = channel->max_power * 2; |
| 2313 | ch->max_reg_power = channel->max_reg_power * 2; |
| 2314 | ch->max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2315 | ch->reg_class_id = 0; /* FIXME */ |
| 2316 | |
| 2317 | /* FIXME: why use only legacy modes, why not any |
| 2318 | * HT/VHT modes? Would that even make any |
| 2319 | * difference? */ |
| 2320 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 2321 | ch->mode = MODE_11G; |
| 2322 | else |
| 2323 | ch->mode = MODE_11A; |
| 2324 | |
| 2325 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) |
| 2326 | continue; |
| 2327 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2328 | ath10k_dbg(ar, ATH10K_DBG_WMI, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2329 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
| 2330 | ch - arg.channels, arg.n_channels, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2331 | ch->freq, ch->max_power, ch->max_reg_power, |
| 2332 | ch->max_antenna_gain, ch->mode); |
| 2333 | |
| 2334 | ch++; |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | ret = ath10k_wmi_scan_chan_list(ar, &arg); |
| 2339 | kfree(arg.channels); |
| 2340 | |
| 2341 | return ret; |
| 2342 | } |
| 2343 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2344 | static enum wmi_dfs_region |
| 2345 | ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region) |
| 2346 | { |
| 2347 | switch (dfs_region) { |
| 2348 | case NL80211_DFS_UNSET: |
| 2349 | return WMI_UNINIT_DFS_DOMAIN; |
| 2350 | case NL80211_DFS_FCC: |
| 2351 | return WMI_FCC_DFS_DOMAIN; |
| 2352 | case NL80211_DFS_ETSI: |
| 2353 | return WMI_ETSI_DFS_DOMAIN; |
| 2354 | case NL80211_DFS_JP: |
| 2355 | return WMI_MKK4_DFS_DOMAIN; |
| 2356 | } |
| 2357 | return WMI_UNINIT_DFS_DOMAIN; |
| 2358 | } |
| 2359 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2360 | static void ath10k_regd_update(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2361 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2362 | struct reg_dmn_pair_mapping *regpair; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2363 | int ret; |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2364 | enum wmi_dfs_region wmi_dfs_reg; |
| 2365 | enum nl80211_dfs_regions nl_dfs_reg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2366 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2367 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2368 | |
| 2369 | ret = ath10k_update_channel_list(ar); |
| 2370 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2371 | ath10k_warn(ar, "failed to update channel list: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2372 | |
| 2373 | regpair = ar->ath_common.regulatory.regpair; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2374 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2375 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
| 2376 | nl_dfs_reg = ar->dfs_detector->region; |
| 2377 | wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg); |
| 2378 | } else { |
| 2379 | wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN; |
| 2380 | } |
| 2381 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2382 | /* Target allows setting up per-band regdomain but ath_common provides |
| 2383 | * a combined one only */ |
| 2384 | ret = ath10k_wmi_pdev_set_regdomain(ar, |
Kalle Valo | ef8c001 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 2385 | regpair->reg_domain, |
| 2386 | regpair->reg_domain, /* 2ghz */ |
| 2387 | regpair->reg_domain, /* 5ghz */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2388 | regpair->reg_2ghz_ctl, |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2389 | regpair->reg_5ghz_ctl, |
| 2390 | wmi_dfs_reg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2391 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2392 | ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret); |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2393 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2394 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2395 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
| 2396 | struct regulatory_request *request) |
| 2397 | { |
| 2398 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 2399 | struct ath10k *ar = hw->priv; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2400 | bool result; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2401 | |
| 2402 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); |
| 2403 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2404 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2405 | ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2406 | request->dfs_region); |
| 2407 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, |
| 2408 | request->dfs_region); |
| 2409 | if (!result) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2410 | 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] | 2411 | request->dfs_region); |
| 2412 | } |
| 2413 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2414 | mutex_lock(&ar->conf_mutex); |
| 2415 | if (ar->state == ATH10K_STATE_ON) |
| 2416 | ath10k_regd_update(ar); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2417 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | /***************/ |
| 2421 | /* TX handlers */ |
| 2422 | /***************/ |
| 2423 | |
Michal Kazior | 42c3aa6 | 2013-10-02 11:03:38 +0200 | [diff] [blame] | 2424 | static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr) |
| 2425 | { |
| 2426 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 2427 | return HTT_DATA_TX_EXT_TID_MGMT; |
| 2428 | |
| 2429 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 2430 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 2431 | |
| 2432 | if (!is_unicast_ether_addr(ieee80211_get_DA(hdr))) |
| 2433 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 2434 | |
| 2435 | return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 2436 | } |
| 2437 | |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 2438 | 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] | 2439 | { |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 2440 | if (vif) |
| 2441 | return ath10k_vif_to_arvif(vif)->vdev_id; |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2442 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 2443 | if (ar->monitor_started) |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2444 | return ar->monitor_vdev_id; |
| 2445 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2446 | ath10k_warn(ar, "failed to resolve vdev id\n"); |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2447 | return 0; |
| 2448 | } |
| 2449 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2450 | /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS |
| 2451 | * Control in the header. |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2452 | */ |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2453 | 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] | 2454 | { |
| 2455 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2456 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2457 | u8 *qos_ctl; |
| 2458 | |
| 2459 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 2460 | return; |
| 2461 | |
| 2462 | qos_ctl = ieee80211_get_qos_ctl(hdr); |
Michal Kazior | ba0ccd7 | 2013-07-22 14:25:28 +0200 | [diff] [blame] | 2463 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
| 2464 | skb->data, (void *)qos_ctl - (void *)skb->data); |
| 2465 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2466 | |
| 2467 | /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc |
| 2468 | * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are |
| 2469 | * used only for CQM purposes (e.g. hostapd station keepalive ping) so |
| 2470 | * it is safe to downgrade to NullFunc. |
| 2471 | */ |
Michal Kazior | bf0a26d | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 2472 | hdr = (void *)skb->data; |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 2473 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) { |
| 2474 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
| 2475 | cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 2476 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2477 | } |
| 2478 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2479 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, |
| 2480 | struct ieee80211_vif *vif, |
| 2481 | struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2482 | { |
| 2483 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2484 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2485 | |
| 2486 | /* This is case only for P2P_GO */ |
| 2487 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP || |
| 2488 | arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) |
| 2489 | return; |
| 2490 | |
| 2491 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { |
| 2492 | spin_lock_bh(&ar->data_lock); |
| 2493 | if (arvif->u.ap.noa_data) |
| 2494 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, |
| 2495 | GFP_ATOMIC)) |
| 2496 | memcpy(skb_put(skb, arvif->u.ap.noa_len), |
| 2497 | arvif->u.ap.noa_data, |
| 2498 | arvif->u.ap.noa_len); |
| 2499 | spin_unlock_bh(&ar->data_lock); |
| 2500 | } |
| 2501 | } |
| 2502 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 2503 | static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar) |
| 2504 | { |
| 2505 | /* FIXME: Not really sure since when the behaviour changed. At some |
| 2506 | * point new firmware stopped requiring creation of peer entries for |
| 2507 | * offchannel tx (and actually creating them causes issues with wmi-htc |
| 2508 | * tx credit replenishment and reliability). Assuming it's at least 3.4 |
| 2509 | * because that's when the `freq` was introduced to TX_FRM HTT command. |
| 2510 | */ |
| 2511 | return !(ar->htt.target_version_major >= 3 && |
| 2512 | ar->htt.target_version_minor >= 4); |
| 2513 | } |
| 2514 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2515 | static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb) |
| 2516 | { |
| 2517 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2518 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2519 | |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 2520 | if (ar->htt.target_version_major >= 3) { |
| 2521 | /* Since HTT 3.0 there is no separate mgmt tx command */ |
| 2522 | ret = ath10k_htt_tx(&ar->htt, skb); |
| 2523 | goto exit; |
| 2524 | } |
| 2525 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2526 | if (ieee80211_is_mgmt(hdr->frame_control)) { |
| 2527 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
| 2528 | ar->fw_features)) { |
| 2529 | if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >= |
| 2530 | ATH10K_MAX_NUM_MGMT_PENDING) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2531 | ath10k_warn(ar, "reached WMI management transmit queue limit\n"); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2532 | ret = -EBUSY; |
| 2533 | goto exit; |
| 2534 | } |
| 2535 | |
| 2536 | skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb); |
| 2537 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); |
| 2538 | } else { |
| 2539 | ret = ath10k_htt_mgmt_tx(&ar->htt, skb); |
| 2540 | } |
| 2541 | } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
| 2542 | ar->fw_features) && |
| 2543 | ieee80211_is_nullfunc(hdr->frame_control)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2544 | /* FW does not report tx status properly for NullFunc frames |
| 2545 | * unless they are sent through mgmt tx path. mac80211 sends |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2546 | * those frames when it detects link/beacon loss and depends |
| 2547 | * on the tx status to be correct. */ |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 2548 | ret = ath10k_htt_mgmt_tx(&ar->htt, skb); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2549 | } else { |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 2550 | ret = ath10k_htt_tx(&ar->htt, skb); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2551 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2552 | |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 2553 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2554 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2555 | ath10k_warn(ar, "failed to transmit packet, dropping: %d\n", |
| 2556 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2557 | ieee80211_free_txskb(ar->hw, skb); |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | void ath10k_offchan_tx_purge(struct ath10k *ar) |
| 2562 | { |
| 2563 | struct sk_buff *skb; |
| 2564 | |
| 2565 | for (;;) { |
| 2566 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 2567 | if (!skb) |
| 2568 | break; |
| 2569 | |
| 2570 | ieee80211_free_txskb(ar->hw, skb); |
| 2571 | } |
| 2572 | } |
| 2573 | |
| 2574 | void ath10k_offchan_tx_work(struct work_struct *work) |
| 2575 | { |
| 2576 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); |
| 2577 | struct ath10k_peer *peer; |
| 2578 | struct ieee80211_hdr *hdr; |
| 2579 | struct sk_buff *skb; |
| 2580 | const u8 *peer_addr; |
| 2581 | int vdev_id; |
| 2582 | int ret; |
| 2583 | |
| 2584 | /* FW requirement: We must create a peer before FW will send out |
| 2585 | * an offchannel frame. Otherwise the frame will be stuck and |
| 2586 | * never transmitted. We delete the peer upon tx completion. |
| 2587 | * It is unlikely that a peer for offchannel tx will already be |
| 2588 | * present. However it may be in some rare cases so account for that. |
| 2589 | * Otherwise we might remove a legitimate peer and break stuff. */ |
| 2590 | |
| 2591 | for (;;) { |
| 2592 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 2593 | if (!skb) |
| 2594 | break; |
| 2595 | |
| 2596 | mutex_lock(&ar->conf_mutex); |
| 2597 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2598 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2599 | skb); |
| 2600 | |
| 2601 | hdr = (struct ieee80211_hdr *)skb->data; |
| 2602 | peer_addr = ieee80211_get_DA(hdr); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2603 | vdev_id = ATH10K_SKB_CB(skb)->vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2604 | |
| 2605 | spin_lock_bh(&ar->data_lock); |
| 2606 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); |
| 2607 | spin_unlock_bh(&ar->data_lock); |
| 2608 | |
| 2609 | if (peer) |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2610 | /* FIXME: should this use ath10k_warn()? */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2611 | 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] | 2612 | peer_addr, vdev_id); |
| 2613 | |
| 2614 | if (!peer) { |
| 2615 | ret = ath10k_peer_create(ar, vdev_id, peer_addr); |
| 2616 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2617 | 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] | 2618 | peer_addr, vdev_id, ret); |
| 2619 | } |
| 2620 | |
| 2621 | spin_lock_bh(&ar->data_lock); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 2622 | reinit_completion(&ar->offchan_tx_completed); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2623 | ar->offchan_tx_skb = skb; |
| 2624 | spin_unlock_bh(&ar->data_lock); |
| 2625 | |
| 2626 | ath10k_tx_htt(ar, skb); |
| 2627 | |
| 2628 | ret = wait_for_completion_timeout(&ar->offchan_tx_completed, |
| 2629 | 3 * HZ); |
Nicholas Mc Guire | 38e2a64 | 2015-01-08 13:27:34 +0100 | [diff] [blame] | 2630 | if (ret == 0) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2631 | ath10k_warn(ar, "timed out waiting for offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2632 | skb); |
| 2633 | |
| 2634 | if (!peer) { |
| 2635 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); |
| 2636 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2637 | 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] | 2638 | peer_addr, vdev_id, ret); |
| 2639 | } |
| 2640 | |
| 2641 | mutex_unlock(&ar->conf_mutex); |
| 2642 | } |
| 2643 | } |
| 2644 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2645 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
| 2646 | { |
| 2647 | struct sk_buff *skb; |
| 2648 | |
| 2649 | for (;;) { |
| 2650 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 2651 | if (!skb) |
| 2652 | break; |
| 2653 | |
| 2654 | ieee80211_free_txskb(ar->hw, skb); |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) |
| 2659 | { |
| 2660 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); |
| 2661 | struct sk_buff *skb; |
| 2662 | int ret; |
| 2663 | |
| 2664 | for (;;) { |
| 2665 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 2666 | if (!skb) |
| 2667 | break; |
| 2668 | |
| 2669 | ret = ath10k_wmi_mgmt_tx(ar, skb); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 2670 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2671 | ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 2672 | ret); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 2673 | ieee80211_free_txskb(ar->hw, skb); |
| 2674 | } |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2678 | /************/ |
| 2679 | /* Scanning */ |
| 2680 | /************/ |
| 2681 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2682 | void __ath10k_scan_finish(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2683 | { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2684 | lockdep_assert_held(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2685 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2686 | switch (ar->scan.state) { |
| 2687 | case ATH10K_SCAN_IDLE: |
| 2688 | break; |
| 2689 | case ATH10K_SCAN_RUNNING: |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2690 | if (ar->scan.is_roc) |
| 2691 | ieee80211_remain_on_channel_expired(ar->hw); |
John W. Linville | f6eaf1e | 2015-01-12 16:07:02 -0500 | [diff] [blame] | 2692 | /* fall through */ |
Michal Kazior | 7305d3e | 2014-11-24 14:58:33 +0100 | [diff] [blame] | 2693 | case ATH10K_SCAN_ABORTING: |
| 2694 | if (!ar->scan.is_roc) |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2695 | ieee80211_scan_completed(ar->hw, |
| 2696 | (ar->scan.state == |
| 2697 | ATH10K_SCAN_ABORTING)); |
| 2698 | /* fall through */ |
| 2699 | case ATH10K_SCAN_STARTING: |
| 2700 | ar->scan.state = ATH10K_SCAN_IDLE; |
| 2701 | ar->scan_channel = NULL; |
| 2702 | ath10k_offchan_tx_purge(ar); |
| 2703 | cancel_delayed_work(&ar->scan.timeout); |
| 2704 | complete_all(&ar->scan.completed); |
| 2705 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2706 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2707 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2708 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2709 | void ath10k_scan_finish(struct ath10k *ar) |
| 2710 | { |
| 2711 | spin_lock_bh(&ar->data_lock); |
| 2712 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2713 | spin_unlock_bh(&ar->data_lock); |
| 2714 | } |
| 2715 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2716 | static int ath10k_scan_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2717 | { |
| 2718 | struct wmi_stop_scan_arg arg = { |
| 2719 | .req_id = 1, /* FIXME */ |
| 2720 | .req_type = WMI_SCAN_STOP_ONE, |
| 2721 | .u.scan_id = ATH10K_SCAN_ID, |
| 2722 | }; |
| 2723 | int ret; |
| 2724 | |
| 2725 | lockdep_assert_held(&ar->conf_mutex); |
| 2726 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2727 | ret = ath10k_wmi_stop_scan(ar, &arg); |
| 2728 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2729 | ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2730 | goto out; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2731 | } |
| 2732 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2733 | ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2734 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2735 | ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2736 | ret = -ETIMEDOUT; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2737 | } else if (ret > 0) { |
| 2738 | ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2739 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2740 | |
| 2741 | out: |
| 2742 | /* Scan state should be updated upon scan completion but in case |
| 2743 | * firmware fails to deliver the event (for whatever reason) it is |
| 2744 | * desired to clean up scan state anyway. Firmware may have just |
| 2745 | * dropped the scan completion event delivery due to transport pipe |
| 2746 | * being overflown with data and/or it can recover on its own before |
| 2747 | * next scan request is submitted. |
| 2748 | */ |
| 2749 | spin_lock_bh(&ar->data_lock); |
| 2750 | if (ar->scan.state != ATH10K_SCAN_IDLE) |
| 2751 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2752 | spin_unlock_bh(&ar->data_lock); |
| 2753 | |
| 2754 | return ret; |
| 2755 | } |
| 2756 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2757 | static void ath10k_scan_abort(struct ath10k *ar) |
| 2758 | { |
| 2759 | int ret; |
| 2760 | |
| 2761 | lockdep_assert_held(&ar->conf_mutex); |
| 2762 | |
| 2763 | spin_lock_bh(&ar->data_lock); |
| 2764 | |
| 2765 | switch (ar->scan.state) { |
| 2766 | case ATH10K_SCAN_IDLE: |
| 2767 | /* This can happen if timeout worker kicked in and called |
| 2768 | * abortion while scan completion was being processed. |
| 2769 | */ |
| 2770 | break; |
| 2771 | case ATH10K_SCAN_STARTING: |
| 2772 | case ATH10K_SCAN_ABORTING: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2773 | 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] | 2774 | ath10k_scan_state_str(ar->scan.state), |
| 2775 | ar->scan.state); |
| 2776 | break; |
| 2777 | case ATH10K_SCAN_RUNNING: |
| 2778 | ar->scan.state = ATH10K_SCAN_ABORTING; |
| 2779 | spin_unlock_bh(&ar->data_lock); |
| 2780 | |
| 2781 | ret = ath10k_scan_stop(ar); |
| 2782 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2783 | ath10k_warn(ar, "failed to abort scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2784 | |
| 2785 | spin_lock_bh(&ar->data_lock); |
| 2786 | break; |
| 2787 | } |
| 2788 | |
| 2789 | spin_unlock_bh(&ar->data_lock); |
| 2790 | } |
| 2791 | |
| 2792 | void ath10k_scan_timeout_work(struct work_struct *work) |
| 2793 | { |
| 2794 | struct ath10k *ar = container_of(work, struct ath10k, |
| 2795 | scan.timeout.work); |
| 2796 | |
| 2797 | mutex_lock(&ar->conf_mutex); |
| 2798 | ath10k_scan_abort(ar); |
| 2799 | mutex_unlock(&ar->conf_mutex); |
| 2800 | } |
| 2801 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2802 | static int ath10k_start_scan(struct ath10k *ar, |
| 2803 | const struct wmi_start_scan_arg *arg) |
| 2804 | { |
| 2805 | int ret; |
| 2806 | |
| 2807 | lockdep_assert_held(&ar->conf_mutex); |
| 2808 | |
| 2809 | ret = ath10k_wmi_start_scan(ar, arg); |
| 2810 | if (ret) |
| 2811 | return ret; |
| 2812 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2813 | ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); |
| 2814 | if (ret == 0) { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2815 | ret = ath10k_scan_stop(ar); |
| 2816 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2817 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2818 | |
| 2819 | return -ETIMEDOUT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2820 | } |
| 2821 | |
Ben Greear | 2f9eec0 | 2015-02-15 16:50:38 +0200 | [diff] [blame] | 2822 | /* If we failed to start the scan, return error code at |
| 2823 | * this point. This is probably due to some issue in the |
| 2824 | * firmware, but no need to wedge the driver due to that... |
| 2825 | */ |
| 2826 | spin_lock_bh(&ar->data_lock); |
| 2827 | if (ar->scan.state == ATH10K_SCAN_IDLE) { |
| 2828 | spin_unlock_bh(&ar->data_lock); |
| 2829 | return -EINVAL; |
| 2830 | } |
| 2831 | spin_unlock_bh(&ar->data_lock); |
| 2832 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2833 | /* Add a 200ms margin to account for event/command processing */ |
| 2834 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
| 2835 | msecs_to_jiffies(arg->max_scan_time+200)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2836 | return 0; |
| 2837 | } |
| 2838 | |
| 2839 | /**********************/ |
| 2840 | /* mac80211 callbacks */ |
| 2841 | /**********************/ |
| 2842 | |
| 2843 | static void ath10k_tx(struct ieee80211_hw *hw, |
| 2844 | struct ieee80211_tx_control *control, |
| 2845 | struct sk_buff *skb) |
| 2846 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2847 | struct ath10k *ar = hw->priv; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2848 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2849 | struct ieee80211_vif *vif = info->control.vif; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2850 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2851 | |
| 2852 | /* We should disable CCK RATE due to P2P */ |
| 2853 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2854 | 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] | 2855 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2856 | ATH10K_SKB_CB(skb)->htt.is_offchan = false; |
| 2857 | ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr); |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 2858 | 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] | 2859 | |
Michal Kazior | cf84bd4 | 2013-07-16 11:04:54 +0200 | [diff] [blame] | 2860 | /* it makes no sense to process injected frames like that */ |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2861 | if (vif && vif->type != NL80211_IFTYPE_MONITOR) { |
| 2862 | ath10k_tx_h_nwifi(hw, skb); |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 2863 | ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb); |
| 2864 | ath10k_tx_h_seq_no(vif, skb); |
Michal Kazior | cf84bd4 | 2013-07-16 11:04:54 +0200 | [diff] [blame] | 2865 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2866 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2867 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { |
| 2868 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 2869 | ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2870 | ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2871 | spin_unlock_bh(&ar->data_lock); |
| 2872 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 2873 | if (ath10k_mac_need_offchan_tx_work(ar)) { |
| 2874 | ATH10K_SKB_CB(skb)->htt.freq = 0; |
| 2875 | ATH10K_SKB_CB(skb)->htt.is_offchan = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2876 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 2877 | ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n", |
| 2878 | skb); |
| 2879 | |
| 2880 | skb_queue_tail(&ar->offchan_tx_queue, skb); |
| 2881 | ieee80211_queue_work(hw, &ar->offchan_tx_work); |
| 2882 | return; |
| 2883 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | ath10k_tx_htt(ar, skb); |
| 2887 | } |
| 2888 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 2889 | /* 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] | 2890 | void ath10k_drain_tx(struct ath10k *ar) |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 2891 | { |
| 2892 | /* make sure rcu-protected mac80211 tx path itself is drained */ |
| 2893 | synchronize_net(); |
| 2894 | |
| 2895 | ath10k_offchan_tx_purge(ar); |
| 2896 | ath10k_mgmt_over_wmi_tx_purge(ar); |
| 2897 | |
| 2898 | cancel_work_sync(&ar->offchan_tx_work); |
| 2899 | cancel_work_sync(&ar->wmi_mgmt_tx_work); |
| 2900 | } |
| 2901 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2902 | void ath10k_halt(struct ath10k *ar) |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2903 | { |
Michal Kazior | d9bc4b9 | 2014-04-23 19:30:06 +0300 | [diff] [blame] | 2904 | struct ath10k_vif *arvif; |
| 2905 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2906 | lockdep_assert_held(&ar->conf_mutex); |
| 2907 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 2908 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 2909 | ar->filter_flags = 0; |
| 2910 | ar->monitor = false; |
| 2911 | |
| 2912 | if (ar->monitor_started) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 2913 | ath10k_monitor_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 2914 | |
| 2915 | ar->monitor_started = false; |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 2916 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 2917 | ath10k_scan_finish(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2918 | ath10k_peer_cleanup_all(ar); |
| 2919 | ath10k_core_stop(ar); |
| 2920 | ath10k_hif_power_down(ar); |
| 2921 | |
| 2922 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 2923 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 2924 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2925 | spin_unlock_bh(&ar->data_lock); |
| 2926 | } |
| 2927 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 2928 | static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 2929 | { |
| 2930 | struct ath10k *ar = hw->priv; |
| 2931 | |
| 2932 | mutex_lock(&ar->conf_mutex); |
| 2933 | |
| 2934 | if (ar->cfg_tx_chainmask) { |
| 2935 | *tx_ant = ar->cfg_tx_chainmask; |
| 2936 | *rx_ant = ar->cfg_rx_chainmask; |
| 2937 | } else { |
| 2938 | *tx_ant = ar->supp_tx_chainmask; |
| 2939 | *rx_ant = ar->supp_rx_chainmask; |
| 2940 | } |
| 2941 | |
| 2942 | mutex_unlock(&ar->conf_mutex); |
| 2943 | |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 2947 | static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg) |
| 2948 | { |
| 2949 | /* It is not clear that allowing gaps in chainmask |
| 2950 | * is helpful. Probably it will not do what user |
| 2951 | * is hoping for, so warn in that case. |
| 2952 | */ |
| 2953 | if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0) |
| 2954 | return; |
| 2955 | |
| 2956 | ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n", |
| 2957 | dbg, cm); |
| 2958 | } |
| 2959 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 2960 | static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant) |
| 2961 | { |
| 2962 | int ret; |
| 2963 | |
| 2964 | lockdep_assert_held(&ar->conf_mutex); |
| 2965 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 2966 | ath10k_check_chain_mask(ar, tx_ant, "tx"); |
| 2967 | ath10k_check_chain_mask(ar, rx_ant, "rx"); |
| 2968 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 2969 | ar->cfg_tx_chainmask = tx_ant; |
| 2970 | ar->cfg_rx_chainmask = rx_ant; |
| 2971 | |
| 2972 | if ((ar->state != ATH10K_STATE_ON) && |
| 2973 | (ar->state != ATH10K_STATE_RESTARTED)) |
| 2974 | return 0; |
| 2975 | |
| 2976 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask, |
| 2977 | tx_ant); |
| 2978 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2979 | ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n", |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 2980 | ret, tx_ant); |
| 2981 | return ret; |
| 2982 | } |
| 2983 | |
| 2984 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask, |
| 2985 | rx_ant); |
| 2986 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2987 | ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n", |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 2988 | ret, rx_ant); |
| 2989 | return ret; |
| 2990 | } |
| 2991 | |
| 2992 | return 0; |
| 2993 | } |
| 2994 | |
| 2995 | static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 2996 | { |
| 2997 | struct ath10k *ar = hw->priv; |
| 2998 | int ret; |
| 2999 | |
| 3000 | mutex_lock(&ar->conf_mutex); |
| 3001 | ret = __ath10k_set_antenna(ar, tx_ant, rx_ant); |
| 3002 | mutex_unlock(&ar->conf_mutex); |
| 3003 | return ret; |
| 3004 | } |
| 3005 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3006 | static int ath10k_start(struct ieee80211_hw *hw) |
| 3007 | { |
| 3008 | struct ath10k *ar = hw->priv; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3009 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3010 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3011 | /* |
| 3012 | * This makes sense only when restarting hw. It is harmless to call |
| 3013 | * uncoditionally. This is necessary to make sure no HTT/WMI tx |
| 3014 | * commands will be submitted while restarting. |
| 3015 | */ |
| 3016 | ath10k_drain_tx(ar); |
| 3017 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3018 | mutex_lock(&ar->conf_mutex); |
| 3019 | |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3020 | switch (ar->state) { |
| 3021 | case ATH10K_STATE_OFF: |
| 3022 | ar->state = ATH10K_STATE_ON; |
| 3023 | break; |
| 3024 | case ATH10K_STATE_RESTARTING: |
| 3025 | ath10k_halt(ar); |
| 3026 | ar->state = ATH10K_STATE_RESTARTED; |
| 3027 | break; |
| 3028 | case ATH10K_STATE_ON: |
| 3029 | case ATH10K_STATE_RESTARTED: |
| 3030 | case ATH10K_STATE_WEDGED: |
| 3031 | WARN_ON(1); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3032 | ret = -EINVAL; |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3033 | goto err; |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 3034 | case ATH10K_STATE_UTF: |
| 3035 | ret = -EBUSY; |
| 3036 | goto err; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | ret = ath10k_hif_power_up(ar); |
| 3040 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3041 | ath10k_err(ar, "Could not init hif: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3042 | goto err_off; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3043 | } |
| 3044 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 3045 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3046 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3047 | ath10k_err(ar, "Could not init core: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3048 | goto err_power_down; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3049 | } |
| 3050 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 3051 | 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] | 3052 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3053 | ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3054 | goto err_core_stop; |
| 3055 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3056 | |
Michal Kazior | c4dd0d0 | 2013-11-13 11:05:10 +0100 | [diff] [blame] | 3057 | 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] | 3058 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3059 | ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3060 | goto err_core_stop; |
| 3061 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3062 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3063 | if (ar->cfg_tx_chainmask) |
| 3064 | __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, |
| 3065 | ar->cfg_rx_chainmask); |
| 3066 | |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3067 | /* |
| 3068 | * By default FW set ARP frames ac to voice (6). In that case ARP |
| 3069 | * exchange is not working properly for UAPSD enabled AP. ARP requests |
| 3070 | * which arrives with access category 0 are processed by network stack |
| 3071 | * and send back with access category 0, but FW changes access category |
| 3072 | * to 6. Set ARP frames access category to best effort (0) solves |
| 3073 | * this problem. |
| 3074 | */ |
| 3075 | |
| 3076 | ret = ath10k_wmi_pdev_set_param(ar, |
| 3077 | ar->wmi.pdev_param->arp_ac_override, 0); |
| 3078 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3079 | ath10k_warn(ar, "failed to set arp ac override parameter: %d\n", |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3080 | ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3081 | goto err_core_stop; |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3082 | } |
| 3083 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3084 | ar->num_started_vdevs = 0; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3085 | ath10k_regd_update(ar); |
| 3086 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3087 | ath10k_spectral_start(ar); |
| 3088 | |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3089 | mutex_unlock(&ar->conf_mutex); |
| 3090 | return 0; |
| 3091 | |
| 3092 | err_core_stop: |
| 3093 | ath10k_core_stop(ar); |
| 3094 | |
| 3095 | err_power_down: |
| 3096 | ath10k_hif_power_down(ar); |
| 3097 | |
| 3098 | err_off: |
| 3099 | ar->state = ATH10K_STATE_OFF; |
| 3100 | |
| 3101 | err: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3102 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | c60bdd8 | 2014-01-29 07:26:31 +0100 | [diff] [blame] | 3103 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | static void ath10k_stop(struct ieee80211_hw *hw) |
| 3107 | { |
| 3108 | struct ath10k *ar = hw->priv; |
| 3109 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3110 | ath10k_drain_tx(ar); |
| 3111 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3112 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3113 | if (ar->state != ATH10K_STATE_OFF) { |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3114 | ath10k_halt(ar); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3115 | ar->state = ATH10K_STATE_OFF; |
| 3116 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3117 | mutex_unlock(&ar->conf_mutex); |
| 3118 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3119 | cancel_delayed_work_sync(&ar->scan.timeout); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3120 | cancel_work_sync(&ar->restart_work); |
| 3121 | } |
| 3122 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3123 | static int ath10k_config_ps(struct ath10k *ar) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3124 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3125 | struct ath10k_vif *arvif; |
| 3126 | int ret = 0; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3127 | |
| 3128 | lockdep_assert_held(&ar->conf_mutex); |
| 3129 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3130 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3131 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 3132 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3133 | ath10k_warn(ar, "failed to setup powersave: %d\n", ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3134 | break; |
| 3135 | } |
| 3136 | } |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3137 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3138 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3139 | } |
| 3140 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3141 | static const char *chandef_get_width(enum nl80211_chan_width width) |
| 3142 | { |
| 3143 | switch (width) { |
| 3144 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3145 | return "20 (noht)"; |
| 3146 | case NL80211_CHAN_WIDTH_20: |
| 3147 | return "20"; |
| 3148 | case NL80211_CHAN_WIDTH_40: |
| 3149 | return "40"; |
| 3150 | case NL80211_CHAN_WIDTH_80: |
| 3151 | return "80"; |
| 3152 | case NL80211_CHAN_WIDTH_80P80: |
| 3153 | return "80+80"; |
| 3154 | case NL80211_CHAN_WIDTH_160: |
| 3155 | return "160"; |
| 3156 | case NL80211_CHAN_WIDTH_5: |
| 3157 | return "5"; |
| 3158 | case NL80211_CHAN_WIDTH_10: |
| 3159 | return "10"; |
| 3160 | } |
| 3161 | return "?"; |
| 3162 | } |
| 3163 | |
| 3164 | static void ath10k_config_chan(struct ath10k *ar) |
| 3165 | { |
| 3166 | struct ath10k_vif *arvif; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3167 | int ret; |
| 3168 | |
| 3169 | lockdep_assert_held(&ar->conf_mutex); |
| 3170 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3171 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3172 | "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n", |
| 3173 | ar->chandef.chan->center_freq, |
| 3174 | ar->chandef.center_freq1, |
| 3175 | ar->chandef.center_freq2, |
| 3176 | chandef_get_width(ar->chandef.width)); |
| 3177 | |
| 3178 | /* First stop monitor interface. Some FW versions crash if there's a |
| 3179 | * lone monitor interface. */ |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3180 | if (ar->monitor_started) |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3181 | ath10k_monitor_stop(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3182 | |
| 3183 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3184 | if (!arvif->is_started) |
| 3185 | continue; |
| 3186 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3187 | if (!arvif->is_up) |
| 3188 | continue; |
| 3189 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3190 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 3191 | continue; |
| 3192 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3193 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3194 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3195 | ath10k_warn(ar, "failed to down vdev %d: %d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3196 | arvif->vdev_id, ret); |
| 3197 | continue; |
| 3198 | } |
| 3199 | } |
| 3200 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3201 | /* all vdevs are downed now - attempt to restart and re-up them */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3202 | |
| 3203 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3204 | if (!arvif->is_started) |
| 3205 | continue; |
| 3206 | |
| 3207 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 3208 | continue; |
| 3209 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3210 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 3211 | if (ret) |
| 3212 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 3213 | ret); |
| 3214 | |
| 3215 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 3216 | if (ret) |
| 3217 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 3218 | ret); |
| 3219 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 3220 | ret = ath10k_vdev_restart(arvif); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3221 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3222 | ath10k_warn(ar, "failed to restart vdev %d: %d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3223 | arvif->vdev_id, ret); |
| 3224 | continue; |
| 3225 | } |
| 3226 | |
| 3227 | if (!arvif->is_up) |
| 3228 | continue; |
| 3229 | |
| 3230 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 3231 | arvif->bssid); |
| 3232 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3233 | ath10k_warn(ar, "failed to bring vdev up %d: %d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3234 | arvif->vdev_id, ret); |
| 3235 | continue; |
| 3236 | } |
| 3237 | } |
| 3238 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3239 | ath10k_monitor_recalc(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3240 | } |
| 3241 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 3242 | static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower) |
| 3243 | { |
| 3244 | int ret; |
| 3245 | u32 param; |
| 3246 | |
| 3247 | lockdep_assert_held(&ar->conf_mutex); |
| 3248 | |
| 3249 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower); |
| 3250 | |
| 3251 | param = ar->wmi.pdev_param->txpower_limit2g; |
| 3252 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 3253 | if (ret) { |
| 3254 | ath10k_warn(ar, "failed to set 2g txpower %d: %d\n", |
| 3255 | txpower, ret); |
| 3256 | return ret; |
| 3257 | } |
| 3258 | |
| 3259 | param = ar->wmi.pdev_param->txpower_limit5g; |
| 3260 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 3261 | if (ret) { |
| 3262 | ath10k_warn(ar, "failed to set 5g txpower %d: %d\n", |
| 3263 | txpower, ret); |
| 3264 | return ret; |
| 3265 | } |
| 3266 | |
| 3267 | return 0; |
| 3268 | } |
| 3269 | |
| 3270 | static int ath10k_mac_txpower_recalc(struct ath10k *ar) |
| 3271 | { |
| 3272 | struct ath10k_vif *arvif; |
| 3273 | int ret, txpower = -1; |
| 3274 | |
| 3275 | lockdep_assert_held(&ar->conf_mutex); |
| 3276 | |
| 3277 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3278 | WARN_ON(arvif->txpower < 0); |
| 3279 | |
| 3280 | if (txpower == -1) |
| 3281 | txpower = arvif->txpower; |
| 3282 | else |
| 3283 | txpower = min(txpower, arvif->txpower); |
| 3284 | } |
| 3285 | |
| 3286 | if (WARN_ON(txpower == -1)) |
| 3287 | return -EINVAL; |
| 3288 | |
| 3289 | ret = ath10k_mac_txpower_setup(ar, txpower); |
| 3290 | if (ret) { |
| 3291 | ath10k_warn(ar, "failed to setup tx power %d: %d\n", |
| 3292 | txpower, ret); |
| 3293 | return ret; |
| 3294 | } |
| 3295 | |
| 3296 | return 0; |
| 3297 | } |
| 3298 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3299 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
| 3300 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3301 | struct ath10k *ar = hw->priv; |
| 3302 | struct ieee80211_conf *conf = &hw->conf; |
| 3303 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3304 | |
| 3305 | mutex_lock(&ar->conf_mutex); |
| 3306 | |
| 3307 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3308 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3309 | "mac config channel %dMHz flags 0x%x radar %d\n", |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3310 | conf->chandef.chan->center_freq, |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3311 | conf->chandef.chan->flags, |
| 3312 | conf->radar_enabled); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3313 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3314 | spin_lock_bh(&ar->data_lock); |
| 3315 | ar->rx_channel = conf->chandef.chan; |
| 3316 | spin_unlock_bh(&ar->data_lock); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3317 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3318 | ar->radar_enabled = conf->radar_enabled; |
| 3319 | ath10k_recalc_radar_detection(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 3320 | |
| 3321 | if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) { |
| 3322 | ar->chandef = conf->chandef; |
| 3323 | ath10k_config_chan(ar); |
| 3324 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3325 | } |
| 3326 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3327 | if (changed & IEEE80211_CONF_CHANGE_PS) |
| 3328 | ath10k_config_ps(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3329 | |
| 3330 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3331 | ar->monitor = conf->flags & IEEE80211_CONF_MONITOR; |
| 3332 | ret = ath10k_monitor_recalc(ar); |
| 3333 | if (ret) |
| 3334 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3335 | } |
| 3336 | |
| 3337 | mutex_unlock(&ar->conf_mutex); |
| 3338 | return ret; |
| 3339 | } |
| 3340 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3341 | static u32 get_nss_from_chainmask(u16 chain_mask) |
| 3342 | { |
| 3343 | if ((chain_mask & 0x15) == 0x15) |
| 3344 | return 4; |
| 3345 | else if ((chain_mask & 0x7) == 0x7) |
| 3346 | return 3; |
| 3347 | else if ((chain_mask & 0x3) == 0x3) |
| 3348 | return 2; |
| 3349 | return 1; |
| 3350 | } |
| 3351 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3352 | /* |
| 3353 | * TODO: |
| 3354 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, |
| 3355 | * because we will send mgmt frames without CCK. This requirement |
| 3356 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag |
| 3357 | * in the TX packet. |
| 3358 | */ |
| 3359 | static int ath10k_add_interface(struct ieee80211_hw *hw, |
| 3360 | struct ieee80211_vif *vif) |
| 3361 | { |
| 3362 | struct ath10k *ar = hw->priv; |
| 3363 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3364 | enum wmi_sta_powersave_param param; |
| 3365 | int ret = 0; |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 3366 | u32 value; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3367 | int bit; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3368 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3369 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 3370 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
| 3371 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3372 | mutex_lock(&ar->conf_mutex); |
| 3373 | |
Michal Kazior | 0dbd09e | 2013-07-31 10:55:14 +0200 | [diff] [blame] | 3374 | memset(arvif, 0, sizeof(*arvif)); |
| 3375 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3376 | arvif->ar = ar; |
| 3377 | arvif->vif = vif; |
| 3378 | |
Ben Greear | e63b33f | 2013-10-22 14:54:14 -0700 | [diff] [blame] | 3379 | INIT_LIST_HEAD(&arvif->list); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3380 | INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work); |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3381 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 3382 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3383 | 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] | 3384 | ret = -EBUSY; |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3385 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3386 | } |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3387 | bit = __ffs64(ar->free_vdev_map); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3388 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3389 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n", |
| 3390 | bit, ar->free_vdev_map); |
| 3391 | |
| 3392 | arvif->vdev_id = bit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3393 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3394 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3395 | switch (vif->type) { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 3396 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3397 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 3398 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; |
| 3399 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3400 | case NL80211_IFTYPE_UNSPECIFIED: |
| 3401 | case NL80211_IFTYPE_STATION: |
| 3402 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 3403 | if (vif->p2p) |
| 3404 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; |
| 3405 | break; |
| 3406 | case NL80211_IFTYPE_ADHOC: |
| 3407 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; |
| 3408 | break; |
| 3409 | case NL80211_IFTYPE_AP: |
| 3410 | arvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 3411 | |
| 3412 | if (vif->p2p) |
| 3413 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; |
| 3414 | break; |
| 3415 | case NL80211_IFTYPE_MONITOR: |
| 3416 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; |
| 3417 | break; |
| 3418 | default: |
| 3419 | WARN_ON(1); |
| 3420 | break; |
| 3421 | } |
| 3422 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3423 | /* Some firmware revisions don't wait for beacon tx completion before |
| 3424 | * sending another SWBA event. This could lead to hardware using old |
| 3425 | * (freed) beacon data in some cases, e.g. tx credit starvation |
| 3426 | * combined with missed TBTT. This is very very rare. |
| 3427 | * |
| 3428 | * On non-IOMMU-enabled hosts this could be a possible security issue |
| 3429 | * because hw could beacon some random data on the air. On |
| 3430 | * IOMMU-enabled hosts DMAR faults would occur in most cases and target |
| 3431 | * device would crash. |
| 3432 | * |
| 3433 | * Since there are no beacon tx completions (implicit nor explicit) |
| 3434 | * propagated to host the only workaround for this is to allocate a |
| 3435 | * DMA-coherent buffer for a lifetime of a vif and use it for all |
| 3436 | * beacon tx commands. Worst case for this approach is some beacons may |
| 3437 | * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap. |
| 3438 | */ |
| 3439 | if (vif->type == NL80211_IFTYPE_ADHOC || |
| 3440 | vif->type == NL80211_IFTYPE_AP) { |
| 3441 | arvif->beacon_buf = dma_zalloc_coherent(ar->dev, |
| 3442 | IEEE80211_MAX_FRAME_LEN, |
| 3443 | &arvif->beacon_paddr, |
Rajkumar Manoharan | 82d7aba | 2014-10-10 17:38:27 +0530 | [diff] [blame] | 3444 | GFP_ATOMIC); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3445 | if (!arvif->beacon_buf) { |
| 3446 | ret = -ENOMEM; |
| 3447 | ath10k_warn(ar, "failed to allocate beacon buffer: %d\n", |
| 3448 | ret); |
| 3449 | goto err; |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n", |
| 3454 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, |
| 3455 | arvif->beacon_buf ? "single-buf" : "per-skb"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3456 | |
| 3457 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, |
| 3458 | arvif->vdev_subtype, vif->addr); |
| 3459 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3460 | ath10k_warn(ar, "failed to create WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3461 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3462 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3463 | } |
| 3464 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3465 | ar->free_vdev_map &= ~(1LL << arvif->vdev_id); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3466 | list_add(&arvif->list, &ar->arvifs); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3467 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 3468 | /* It makes no sense to have firmware do keepalives. mac80211 already |
| 3469 | * takes care of this with idle connection polling. |
| 3470 | */ |
| 3471 | ret = ath10k_mac_vif_disable_keepalive(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3472 | if (ret) { |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 3473 | ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3474 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3475 | goto err_vdev_delete; |
| 3476 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3477 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 3478 | arvif->def_wep_key_idx = -1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3479 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3480 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
| 3481 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3482 | ATH10K_HW_TXRX_NATIVE_WIFI); |
Bartosz Markowski | ebc9abd | 2013-10-15 09:26:20 +0200 | [diff] [blame] | 3483 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3484 | if (ret && ret != -EOPNOTSUPP) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3485 | ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3486 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3487 | goto err_vdev_delete; |
| 3488 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3489 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3490 | if (ar->cfg_tx_chainmask) { |
| 3491 | u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
| 3492 | |
| 3493 | vdev_param = ar->wmi.vdev_param->nss; |
| 3494 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 3495 | nss); |
| 3496 | if (ret) { |
| 3497 | ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n", |
| 3498 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, |
| 3499 | ret); |
| 3500 | goto err_vdev_delete; |
| 3501 | } |
| 3502 | } |
| 3503 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3504 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 3505 | ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr); |
| 3506 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3507 | 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] | 3508 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3509 | goto err_vdev_delete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3510 | } |
Marek Puzyniak | cdf0740 | 2013-12-30 09:07:51 +0100 | [diff] [blame] | 3511 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 3512 | ret = ath10k_mac_set_kickout(arvif); |
| 3513 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3514 | ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3515 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 3516 | goto err_peer_delete; |
| 3517 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 3521 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; |
| 3522 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 3523 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 3524 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3525 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3526 | 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] | 3527 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3528 | goto err_peer_delete; |
| 3529 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3530 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3531 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3532 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3533 | 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] | 3534 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3535 | goto err_peer_delete; |
| 3536 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3537 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3538 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3539 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 3540 | 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] | 3541 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3542 | goto err_peer_delete; |
| 3543 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3544 | } |
| 3545 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 3546 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3547 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3548 | 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] | 3549 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3550 | goto err_peer_delete; |
| 3551 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 3552 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 3553 | ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3554 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3555 | 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] | 3556 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3557 | goto err_peer_delete; |
| 3558 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 3559 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 3560 | arvif->txpower = vif->bss_conf.txpower; |
| 3561 | ret = ath10k_mac_txpower_recalc(ar); |
| 3562 | if (ret) { |
| 3563 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 3564 | goto err_peer_delete; |
| 3565 | } |
| 3566 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3567 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3568 | return 0; |
| 3569 | |
| 3570 | err_peer_delete: |
| 3571 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 3572 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); |
| 3573 | |
| 3574 | err_vdev_delete: |
| 3575 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3576 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3577 | list_del(&arvif->list); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3578 | |
| 3579 | err: |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3580 | if (arvif->beacon_buf) { |
| 3581 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 3582 | arvif->beacon_buf, arvif->beacon_paddr); |
| 3583 | arvif->beacon_buf = NULL; |
| 3584 | } |
| 3585 | |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3586 | mutex_unlock(&ar->conf_mutex); |
| 3587 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3588 | return ret; |
| 3589 | } |
| 3590 | |
| 3591 | static void ath10k_remove_interface(struct ieee80211_hw *hw, |
| 3592 | struct ieee80211_vif *vif) |
| 3593 | { |
| 3594 | struct ath10k *ar = hw->priv; |
| 3595 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3596 | int ret; |
| 3597 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 3598 | cancel_work_sync(&arvif->ap_csa_work); |
| 3599 | |
Sujith Manoharan | 5d011f5 | 2014-11-25 11:47:00 +0530 | [diff] [blame] | 3600 | mutex_lock(&ar->conf_mutex); |
| 3601 | |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 3602 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3603 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 3604 | spin_unlock_bh(&ar->data_lock); |
| 3605 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3606 | ret = ath10k_spectral_vif_stop(arvif); |
| 3607 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3608 | ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3609 | arvif->vdev_id, ret); |
| 3610 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 3611 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 3612 | list_del(&arvif->list); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3613 | |
| 3614 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 3615 | ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id, |
| 3616 | vif->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3617 | if (ret) |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 3618 | 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] | 3619 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3620 | |
| 3621 | kfree(arvif->u.ap.noa_data); |
| 3622 | } |
| 3623 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3624 | 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] | 3625 | arvif->vdev_id); |
| 3626 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3627 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 3628 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3629 | ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3630 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3631 | |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 3632 | /* Some firmware revisions don't notify host about self-peer removal |
| 3633 | * until after associated vdev is deleted. |
| 3634 | */ |
| 3635 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 3636 | ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id, |
| 3637 | vif->addr); |
| 3638 | if (ret) |
| 3639 | ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n", |
| 3640 | arvif->vdev_id, ret); |
| 3641 | |
| 3642 | spin_lock_bh(&ar->data_lock); |
| 3643 | ar->num_peers--; |
| 3644 | spin_unlock_bh(&ar->data_lock); |
| 3645 | } |
| 3646 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3647 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
| 3648 | |
| 3649 | mutex_unlock(&ar->conf_mutex); |
| 3650 | } |
| 3651 | |
| 3652 | /* |
| 3653 | * FIXME: Has to be verified. |
| 3654 | */ |
| 3655 | #define SUPPORTED_FILTERS \ |
| 3656 | (FIF_PROMISC_IN_BSS | \ |
| 3657 | FIF_ALLMULTI | \ |
| 3658 | FIF_CONTROL | \ |
| 3659 | FIF_PSPOLL | \ |
| 3660 | FIF_OTHER_BSS | \ |
| 3661 | FIF_BCN_PRBRESP_PROMISC | \ |
| 3662 | FIF_PROBE_REQ | \ |
| 3663 | FIF_FCSFAIL) |
| 3664 | |
| 3665 | static void ath10k_configure_filter(struct ieee80211_hw *hw, |
| 3666 | unsigned int changed_flags, |
| 3667 | unsigned int *total_flags, |
| 3668 | u64 multicast) |
| 3669 | { |
| 3670 | struct ath10k *ar = hw->priv; |
| 3671 | int ret; |
| 3672 | |
| 3673 | mutex_lock(&ar->conf_mutex); |
| 3674 | |
| 3675 | changed_flags &= SUPPORTED_FILTERS; |
| 3676 | *total_flags &= SUPPORTED_FILTERS; |
| 3677 | ar->filter_flags = *total_flags; |
| 3678 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3679 | ret = ath10k_monitor_recalc(ar); |
| 3680 | if (ret) |
| 3681 | ath10k_warn(ar, "failed to recalc montior: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3682 | |
| 3683 | mutex_unlock(&ar->conf_mutex); |
| 3684 | } |
| 3685 | |
| 3686 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, |
| 3687 | struct ieee80211_vif *vif, |
| 3688 | struct ieee80211_bss_conf *info, |
| 3689 | u32 changed) |
| 3690 | { |
| 3691 | struct ath10k *ar = hw->priv; |
| 3692 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3693 | int ret = 0; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 3694 | u32 vdev_param, pdev_param, slottime, preamble; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3695 | |
| 3696 | mutex_lock(&ar->conf_mutex); |
| 3697 | |
| 3698 | if (changed & BSS_CHANGED_IBSS) |
| 3699 | ath10k_control_ibss(arvif, info, vif->addr); |
| 3700 | |
| 3701 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 3702 | arvif->beacon_interval = info->beacon_int; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3703 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
| 3704 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3705 | arvif->beacon_interval); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3706 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3707 | "mac vdev %d beacon_interval %d\n", |
| 3708 | arvif->vdev_id, arvif->beacon_interval); |
| 3709 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3710 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3711 | 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] | 3712 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | if (changed & BSS_CHANGED_BEACON) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3716 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3717 | "vdev %d set beacon tx mode to staggered\n", |
| 3718 | arvif->vdev_id); |
| 3719 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 3720 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
| 3721 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3722 | WMI_BEACON_STAGGERED_MODE); |
| 3723 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3724 | 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] | 3725 | arvif->vdev_id, ret); |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 3726 | |
| 3727 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 3728 | if (ret) |
| 3729 | ath10k_warn(ar, "failed to update beacon template: %d\n", |
| 3730 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3731 | } |
| 3732 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 3733 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { |
| 3734 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 3735 | if (ret) |
| 3736 | ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n", |
| 3737 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3738 | } |
| 3739 | |
Michal Kazior | ba2479f | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 3740 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3741 | arvif->dtim_period = info->dtim_period; |
| 3742 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3743 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3744 | "mac vdev %d dtim_period %d\n", |
| 3745 | arvif->vdev_id, arvif->dtim_period); |
| 3746 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3747 | vdev_param = ar->wmi.vdev_param->dtim_period; |
| 3748 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3749 | arvif->dtim_period); |
| 3750 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3751 | 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] | 3752 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3753 | } |
| 3754 | |
| 3755 | if (changed & BSS_CHANGED_SSID && |
| 3756 | vif->type == NL80211_IFTYPE_AP) { |
| 3757 | arvif->u.ap.ssid_len = info->ssid_len; |
| 3758 | if (info->ssid_len) |
| 3759 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); |
| 3760 | arvif->u.ap.hidden_ssid = info->hidden_ssid; |
| 3761 | } |
| 3762 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3763 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
| 3764 | ether_addr_copy(arvif->bssid, info->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3765 | |
| 3766 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
| 3767 | ath10k_control_beaconing(arvif, info); |
| 3768 | |
| 3769 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3770 | arvif->use_cts_prot = info->use_cts_prot; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3771 | 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] | 3772 | arvif->vdev_id, info->use_cts_prot); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3773 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3774 | ret = ath10k_recalc_rtscts_prot(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3775 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3776 | 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] | 3777 | arvif->vdev_id, ret); |
Michal Kazior | a87fd4b | 2015-03-02 11:21:17 +0100 | [diff] [blame] | 3778 | |
| 3779 | vdev_param = ar->wmi.vdev_param->protection_mode; |
| 3780 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 3781 | info->use_cts_prot ? 1 : 0); |
| 3782 | if (ret) |
| 3783 | ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n", |
| 3784 | info->use_cts_prot, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3788 | if (info->use_short_slot) |
| 3789 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ |
| 3790 | |
| 3791 | else |
| 3792 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ |
| 3793 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3794 | 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] | 3795 | arvif->vdev_id, slottime); |
| 3796 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3797 | vdev_param = ar->wmi.vdev_param->slot_time; |
| 3798 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3799 | slottime); |
| 3800 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3801 | 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] | 3802 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3806 | if (info->use_short_preamble) |
| 3807 | preamble = WMI_VDEV_PREAMBLE_SHORT; |
| 3808 | else |
| 3809 | preamble = WMI_VDEV_PREAMBLE_LONG; |
| 3810 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3811 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3812 | "mac vdev %d preamble %dn", |
| 3813 | arvif->vdev_id, preamble); |
| 3814 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 3815 | vdev_param = ar->wmi.vdev_param->preamble; |
| 3816 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3817 | preamble); |
| 3818 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3819 | ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 3820 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | if (changed & BSS_CHANGED_ASSOC) { |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 3824 | if (info->assoc) { |
| 3825 | /* Workaround: Make sure monitor vdev is not running |
| 3826 | * when associating to prevent some firmware revisions |
| 3827 | * (e.g. 10.1 and 10.2) from crashing. |
| 3828 | */ |
| 3829 | if (ar->monitor_started) |
| 3830 | ath10k_monitor_stop(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3831 | ath10k_bss_assoc(hw, vif, info); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 3832 | ath10k_monitor_recalc(ar); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3833 | } else { |
| 3834 | ath10k_bss_disassoc(hw, vif); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 3835 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3836 | } |
| 3837 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 3838 | if (changed & BSS_CHANGED_TXPOWER) { |
| 3839 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n", |
| 3840 | arvif->vdev_id, info->txpower); |
| 3841 | |
| 3842 | arvif->txpower = info->txpower; |
| 3843 | ret = ath10k_mac_txpower_recalc(ar); |
| 3844 | if (ret) |
| 3845 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 3846 | } |
| 3847 | |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 3848 | if (changed & BSS_CHANGED_PS) { |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 3849 | arvif->ps = vif->bss_conf.ps; |
| 3850 | |
| 3851 | ret = ath10k_config_ps(ar); |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 3852 | if (ret) |
| 3853 | ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n", |
| 3854 | arvif->vdev_id, ret); |
| 3855 | } |
| 3856 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3857 | mutex_unlock(&ar->conf_mutex); |
| 3858 | } |
| 3859 | |
| 3860 | static int ath10k_hw_scan(struct ieee80211_hw *hw, |
| 3861 | struct ieee80211_vif *vif, |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 3862 | struct ieee80211_scan_request *hw_req) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3863 | { |
| 3864 | struct ath10k *ar = hw->priv; |
| 3865 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 3866 | struct cfg80211_scan_request *req = &hw_req->req; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3867 | struct wmi_start_scan_arg arg; |
| 3868 | int ret = 0; |
| 3869 | int i; |
| 3870 | |
| 3871 | mutex_lock(&ar->conf_mutex); |
| 3872 | |
| 3873 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3874 | switch (ar->scan.state) { |
| 3875 | case ATH10K_SCAN_IDLE: |
| 3876 | reinit_completion(&ar->scan.started); |
| 3877 | reinit_completion(&ar->scan.completed); |
| 3878 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 3879 | ar->scan.is_roc = false; |
| 3880 | ar->scan.vdev_id = arvif->vdev_id; |
| 3881 | ret = 0; |
| 3882 | break; |
| 3883 | case ATH10K_SCAN_STARTING: |
| 3884 | case ATH10K_SCAN_RUNNING: |
| 3885 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3886 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3887 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3888 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3889 | spin_unlock_bh(&ar->data_lock); |
| 3890 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3891 | if (ret) |
| 3892 | goto exit; |
| 3893 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3894 | memset(&arg, 0, sizeof(arg)); |
| 3895 | ath10k_wmi_start_scan_init(ar, &arg); |
| 3896 | arg.vdev_id = arvif->vdev_id; |
| 3897 | arg.scan_id = ATH10K_SCAN_ID; |
| 3898 | |
| 3899 | if (!req->no_cck) |
| 3900 | arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES; |
| 3901 | |
| 3902 | if (req->ie_len) { |
| 3903 | arg.ie_len = req->ie_len; |
| 3904 | memcpy(arg.ie, req->ie, arg.ie_len); |
| 3905 | } |
| 3906 | |
| 3907 | if (req->n_ssids) { |
| 3908 | arg.n_ssids = req->n_ssids; |
| 3909 | for (i = 0; i < arg.n_ssids; i++) { |
| 3910 | arg.ssids[i].len = req->ssids[i].ssid_len; |
| 3911 | arg.ssids[i].ssid = req->ssids[i].ssid; |
| 3912 | } |
Michal Kazior | dcd4a56 | 2013-07-31 10:55:12 +0200 | [diff] [blame] | 3913 | } else { |
| 3914 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | if (req->n_channels) { |
| 3918 | arg.n_channels = req->n_channels; |
| 3919 | for (i = 0; i < arg.n_channels; i++) |
| 3920 | arg.channels[i] = req->channels[i]->center_freq; |
| 3921 | } |
| 3922 | |
| 3923 | ret = ath10k_start_scan(ar, &arg); |
| 3924 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3925 | ath10k_warn(ar, "failed to start hw scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3926 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3927 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3928 | spin_unlock_bh(&ar->data_lock); |
| 3929 | } |
| 3930 | |
| 3931 | exit: |
| 3932 | mutex_unlock(&ar->conf_mutex); |
| 3933 | return ret; |
| 3934 | } |
| 3935 | |
| 3936 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 3937 | struct ieee80211_vif *vif) |
| 3938 | { |
| 3939 | struct ath10k *ar = hw->priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3940 | |
| 3941 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3942 | ath10k_scan_abort(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3943 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 3944 | |
| 3945 | cancel_delayed_work_sync(&ar->scan.timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3946 | } |
| 3947 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 3948 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
| 3949 | struct ath10k_vif *arvif, |
| 3950 | enum set_key_cmd cmd, |
| 3951 | struct ieee80211_key_conf *key) |
| 3952 | { |
| 3953 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; |
| 3954 | int ret; |
| 3955 | |
| 3956 | /* 10.1 firmware branch requires default key index to be set to group |
| 3957 | * key index after installing it. Otherwise FW/HW Txes corrupted |
| 3958 | * frames with multi-vif APs. This is not required for main firmware |
| 3959 | * branch (e.g. 636). |
| 3960 | * |
| 3961 | * FIXME: This has been tested only in AP. It remains unknown if this |
| 3962 | * is required for multi-vif STA interfaces on 10.1 */ |
| 3963 | |
| 3964 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 3965 | return; |
| 3966 | |
| 3967 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 3968 | return; |
| 3969 | |
| 3970 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 3971 | return; |
| 3972 | |
| 3973 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 3974 | return; |
| 3975 | |
| 3976 | if (cmd != SET_KEY) |
| 3977 | return; |
| 3978 | |
| 3979 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 3980 | key->keyidx); |
| 3981 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3982 | 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] | 3983 | arvif->vdev_id, ret); |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 3984 | } |
| 3985 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3986 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 3987 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 3988 | struct ieee80211_key_conf *key) |
| 3989 | { |
| 3990 | struct ath10k *ar = hw->priv; |
| 3991 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3992 | struct ath10k_peer *peer; |
| 3993 | const u8 *peer_addr; |
| 3994 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3995 | key->cipher == WLAN_CIPHER_SUITE_WEP104; |
| 3996 | int ret = 0; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 3997 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3998 | |
| 3999 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
| 4000 | return -ENOSPC; |
| 4001 | |
| 4002 | mutex_lock(&ar->conf_mutex); |
| 4003 | |
| 4004 | if (sta) |
| 4005 | peer_addr = sta->addr; |
| 4006 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 4007 | peer_addr = vif->bss_conf.bssid; |
| 4008 | else |
| 4009 | peer_addr = vif->addr; |
| 4010 | |
| 4011 | key->hw_key_idx = key->keyidx; |
| 4012 | |
| 4013 | /* the peer should not disappear in mid-way (unless FW goes awry) since |
| 4014 | * we already hold conf_mutex. we just make sure its there now. */ |
| 4015 | spin_lock_bh(&ar->data_lock); |
| 4016 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 4017 | spin_unlock_bh(&ar->data_lock); |
| 4018 | |
| 4019 | if (!peer) { |
| 4020 | if (cmd == SET_KEY) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4021 | 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] | 4022 | peer_addr); |
| 4023 | ret = -EOPNOTSUPP; |
| 4024 | goto exit; |
| 4025 | } else { |
| 4026 | /* if the peer doesn't exist there is no key to disable |
| 4027 | * anymore */ |
| 4028 | goto exit; |
| 4029 | } |
| 4030 | } |
| 4031 | |
| 4032 | if (is_wep) { |
| 4033 | if (cmd == SET_KEY) |
| 4034 | arvif->wep_keys[key->keyidx] = key; |
| 4035 | else |
| 4036 | arvif->wep_keys[key->keyidx] = NULL; |
| 4037 | |
| 4038 | if (cmd == DISABLE_KEY) |
| 4039 | ath10k_clear_vdev_key(arvif, key); |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4040 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 4041 | /* When WEP keys are uploaded it's possible that there are |
| 4042 | * stations associated already (e.g. when merging) without any |
| 4043 | * keys. Static WEP needs an explicit per-peer key upload. |
| 4044 | */ |
| 4045 | if (vif->type == NL80211_IFTYPE_ADHOC && |
| 4046 | cmd == SET_KEY) |
| 4047 | ath10k_mac_vif_update_wep_key(arvif, key); |
| 4048 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4049 | /* 802.1x never sets the def_wep_key_idx so each set_key() |
| 4050 | * call changes default tx key. |
| 4051 | * |
| 4052 | * Static WEP sets def_wep_key_idx via .set_default_unicast_key |
| 4053 | * after first set_key(). |
| 4054 | */ |
| 4055 | if (cmd == SET_KEY && arvif->def_wep_key_idx == -1) |
| 4056 | flags |= WMI_KEY_TX_USAGE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4057 | } |
| 4058 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4059 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4060 | flags |= WMI_KEY_PAIRWISE; |
| 4061 | else |
| 4062 | flags |= WMI_KEY_GROUP; |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4063 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4064 | /* mac80211 uploads static WEP keys as groupwise while fw/hw requires |
| 4065 | * pairwise keys for non-self peers, i.e. BSSID in STA mode and |
| 4066 | * associated stations in AP/IBSS. |
| 4067 | * |
| 4068 | * Static WEP keys for peer_addr=vif->addr and 802.1X WEP keys work |
| 4069 | * fine when mapped directly from mac80211. |
| 4070 | * |
| 4071 | * Note: When installing first static WEP groupwise key (which should |
| 4072 | * be pairwise) def_wep_key_idx isn't known yet (it's equal to -1). |
| 4073 | * Since .set_default_unicast_key is called only for static WEP it's |
| 4074 | * used to re-upload the key as pairwise. |
| 4075 | */ |
| 4076 | if (arvif->def_wep_key_idx >= 0 && |
| 4077 | memcmp(peer_addr, arvif->vif->addr, ETH_ALEN)) { |
| 4078 | flags &= ~WMI_KEY_GROUP; |
| 4079 | flags |= WMI_KEY_PAIRWISE; |
| 4080 | } |
| 4081 | |
| 4082 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4083 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4084 | 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] | 4085 | arvif->vdev_id, peer_addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4086 | goto exit; |
| 4087 | } |
| 4088 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4089 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
| 4090 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4091 | spin_lock_bh(&ar->data_lock); |
| 4092 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 4093 | if (peer && cmd == SET_KEY) |
| 4094 | peer->keys[key->keyidx] = key; |
| 4095 | else if (peer && cmd == DISABLE_KEY) |
| 4096 | peer->keys[key->keyidx] = NULL; |
| 4097 | else if (peer == NULL) |
| 4098 | /* impossible unless FW goes crazy */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4099 | ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4100 | spin_unlock_bh(&ar->data_lock); |
| 4101 | |
| 4102 | exit: |
| 4103 | mutex_unlock(&ar->conf_mutex); |
| 4104 | return ret; |
| 4105 | } |
| 4106 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4107 | static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw, |
| 4108 | struct ieee80211_vif *vif, |
| 4109 | int keyidx) |
| 4110 | { |
| 4111 | struct ath10k *ar = hw->priv; |
| 4112 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4113 | int ret; |
| 4114 | |
| 4115 | mutex_lock(&arvif->ar->conf_mutex); |
| 4116 | |
| 4117 | if (arvif->ar->state != ATH10K_STATE_ON) |
| 4118 | goto unlock; |
| 4119 | |
| 4120 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", |
| 4121 | arvif->vdev_id, keyidx); |
| 4122 | |
| 4123 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 4124 | arvif->vdev_id, |
| 4125 | arvif->ar->wmi.vdev_param->def_keyid, |
| 4126 | keyidx); |
| 4127 | |
| 4128 | if (ret) { |
| 4129 | ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n", |
| 4130 | arvif->vdev_id, |
| 4131 | ret); |
| 4132 | goto unlock; |
| 4133 | } |
| 4134 | |
| 4135 | arvif->def_wep_key_idx = keyidx; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4136 | |
| 4137 | ret = ath10k_mac_vif_sta_fix_wep_key(arvif); |
| 4138 | if (ret) { |
| 4139 | ath10k_warn(ar, "failed to fix sta wep key on vdev %i: %d\n", |
| 4140 | arvif->vdev_id, ret); |
| 4141 | goto unlock; |
| 4142 | } |
| 4143 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4144 | unlock: |
| 4145 | mutex_unlock(&arvif->ar->conf_mutex); |
| 4146 | } |
| 4147 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4148 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
| 4149 | { |
| 4150 | struct ath10k *ar; |
| 4151 | struct ath10k_vif *arvif; |
| 4152 | struct ath10k_sta *arsta; |
| 4153 | struct ieee80211_sta *sta; |
| 4154 | u32 changed, bw, nss, smps; |
| 4155 | int err; |
| 4156 | |
| 4157 | arsta = container_of(wk, struct ath10k_sta, update_wk); |
| 4158 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); |
| 4159 | arvif = arsta->arvif; |
| 4160 | ar = arvif->ar; |
| 4161 | |
| 4162 | spin_lock_bh(&ar->data_lock); |
| 4163 | |
| 4164 | changed = arsta->changed; |
| 4165 | arsta->changed = 0; |
| 4166 | |
| 4167 | bw = arsta->bw; |
| 4168 | nss = arsta->nss; |
| 4169 | smps = arsta->smps; |
| 4170 | |
| 4171 | spin_unlock_bh(&ar->data_lock); |
| 4172 | |
| 4173 | mutex_lock(&ar->conf_mutex); |
| 4174 | |
| 4175 | if (changed & IEEE80211_RC_BW_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4176 | 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] | 4177 | sta->addr, bw); |
| 4178 | |
| 4179 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4180 | WMI_PEER_CHAN_WIDTH, bw); |
| 4181 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4182 | 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] | 4183 | sta->addr, bw, err); |
| 4184 | } |
| 4185 | |
| 4186 | if (changed & IEEE80211_RC_NSS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4187 | 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] | 4188 | sta->addr, nss); |
| 4189 | |
| 4190 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4191 | WMI_PEER_NSS, nss); |
| 4192 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4193 | ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4194 | sta->addr, nss, err); |
| 4195 | } |
| 4196 | |
| 4197 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4198 | 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] | 4199 | sta->addr, smps); |
| 4200 | |
| 4201 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4202 | WMI_PEER_SMPS_STATE, smps); |
| 4203 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4204 | ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4205 | sta->addr, smps, err); |
| 4206 | } |
| 4207 | |
Janusz Dziedzic | 55884c0 | 2014-12-17 12:30:02 +0200 | [diff] [blame] | 4208 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED || |
| 4209 | changed & IEEE80211_RC_NSS_CHANGED) { |
| 4210 | 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] | 4211 | sta->addr); |
| 4212 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4213 | err = ath10k_station_assoc(ar, arvif->vif, sta, true); |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4214 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4215 | ath10k_warn(ar, "failed to reassociate station: %pM\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4216 | sta->addr); |
| 4217 | } |
| 4218 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4219 | mutex_unlock(&ar->conf_mutex); |
| 4220 | } |
| 4221 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4222 | static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif) |
| 4223 | { |
| 4224 | struct ath10k *ar = arvif->ar; |
| 4225 | |
| 4226 | lockdep_assert_held(&ar->conf_mutex); |
| 4227 | |
| 4228 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 4229 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 4230 | return 0; |
| 4231 | |
| 4232 | if (ar->num_stations >= ar->max_num_stations) |
| 4233 | return -ENOBUFS; |
| 4234 | |
| 4235 | ar->num_stations++; |
| 4236 | |
| 4237 | return 0; |
| 4238 | } |
| 4239 | |
| 4240 | static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif) |
| 4241 | { |
| 4242 | struct ath10k *ar = arvif->ar; |
| 4243 | |
| 4244 | lockdep_assert_held(&ar->conf_mutex); |
| 4245 | |
| 4246 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 4247 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 4248 | return; |
| 4249 | |
| 4250 | ar->num_stations--; |
| 4251 | } |
| 4252 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4253 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
| 4254 | struct ieee80211_vif *vif, |
| 4255 | struct ieee80211_sta *sta, |
| 4256 | enum ieee80211_sta_state old_state, |
| 4257 | enum ieee80211_sta_state new_state) |
| 4258 | { |
| 4259 | struct ath10k *ar = hw->priv; |
| 4260 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4261 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4262 | int ret = 0; |
| 4263 | |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 4264 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 4265 | new_state == IEEE80211_STA_NONE) { |
| 4266 | memset(arsta, 0, sizeof(*arsta)); |
| 4267 | arsta->arvif = arvif; |
| 4268 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); |
| 4269 | } |
| 4270 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4271 | /* cancel must be done outside the mutex to avoid deadlock */ |
| 4272 | if ((old_state == IEEE80211_STA_NONE && |
| 4273 | new_state == IEEE80211_STA_NOTEXIST)) |
| 4274 | cancel_work_sync(&arsta->update_wk); |
| 4275 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4276 | mutex_lock(&ar->conf_mutex); |
| 4277 | |
| 4278 | if (old_state == IEEE80211_STA_NOTEXIST && |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4279 | new_state == IEEE80211_STA_NONE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4280 | /* |
| 4281 | * New station addition. |
| 4282 | */ |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4283 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 4284 | "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n", |
| 4285 | arvif->vdev_id, sta->addr, |
| 4286 | ar->num_stations + 1, ar->max_num_stations, |
| 4287 | ar->num_peers + 1, ar->max_num_peers); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 4288 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4289 | ret = ath10k_mac_inc_num_stations(arvif); |
| 4290 | if (ret) { |
| 4291 | ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n", |
| 4292 | ar->max_num_stations); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 4293 | goto exit; |
| 4294 | } |
| 4295 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4296 | ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 4297 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4298 | 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] | 4299 | sta->addr, arvif->vdev_id, ret); |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4300 | ath10k_mac_dec_num_stations(arvif); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 4301 | goto exit; |
| 4302 | } |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4303 | |
| 4304 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 4305 | WARN_ON(arvif->is_started); |
| 4306 | |
| 4307 | ret = ath10k_vdev_start(arvif); |
| 4308 | if (ret) { |
| 4309 | ath10k_warn(ar, "failed to start vdev %i: %d\n", |
| 4310 | arvif->vdev_id, ret); |
| 4311 | WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id, |
| 4312 | sta->addr)); |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4313 | ath10k_mac_dec_num_stations(arvif); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4314 | goto exit; |
| 4315 | } |
| 4316 | |
| 4317 | arvif->is_started = true; |
| 4318 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4319 | } else if ((old_state == IEEE80211_STA_NONE && |
| 4320 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 4321 | /* |
| 4322 | * Existing station deletion. |
| 4323 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4324 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4325 | "mac vdev %d peer delete %pM (sta gone)\n", |
| 4326 | arvif->vdev_id, sta->addr); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4327 | |
| 4328 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 4329 | WARN_ON(!arvif->is_started); |
| 4330 | |
| 4331 | ret = ath10k_vdev_stop(arvif); |
| 4332 | if (ret) |
| 4333 | ath10k_warn(ar, "failed to stop vdev %i: %d\n", |
| 4334 | arvif->vdev_id, ret); |
| 4335 | |
| 4336 | arvif->is_started = false; |
| 4337 | } |
| 4338 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4339 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 4340 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4341 | 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] | 4342 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4343 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4344 | ath10k_mac_dec_num_stations(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4345 | } else if (old_state == IEEE80211_STA_AUTH && |
| 4346 | new_state == IEEE80211_STA_ASSOC && |
| 4347 | (vif->type == NL80211_IFTYPE_AP || |
| 4348 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 4349 | /* |
| 4350 | * New association. |
| 4351 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4352 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4353 | sta->addr); |
| 4354 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4355 | ret = ath10k_station_assoc(ar, vif, sta, false); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4356 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4357 | 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] | 4358 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4359 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 4360 | new_state == IEEE80211_STA_AUTH && |
| 4361 | (vif->type == NL80211_IFTYPE_AP || |
| 4362 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 4363 | /* |
| 4364 | * Disassociation. |
| 4365 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4366 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4367 | sta->addr); |
| 4368 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4369 | ret = ath10k_station_disassoc(ar, vif, sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4370 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4371 | ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4372 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4373 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 4374 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4375 | mutex_unlock(&ar->conf_mutex); |
| 4376 | return ret; |
| 4377 | } |
| 4378 | |
| 4379 | 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] | 4380 | u16 ac, bool enable) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4381 | { |
| 4382 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4383 | struct wmi_sta_uapsd_auto_trig_arg arg = {}; |
| 4384 | u32 prio = 0, acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4385 | u32 value = 0; |
| 4386 | int ret = 0; |
| 4387 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4388 | lockdep_assert_held(&ar->conf_mutex); |
| 4389 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4390 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 4391 | return 0; |
| 4392 | |
| 4393 | switch (ac) { |
| 4394 | case IEEE80211_AC_VO: |
| 4395 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | |
| 4396 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4397 | prio = 7; |
| 4398 | acc = 3; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4399 | break; |
| 4400 | case IEEE80211_AC_VI: |
| 4401 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | |
| 4402 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4403 | prio = 5; |
| 4404 | acc = 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4405 | break; |
| 4406 | case IEEE80211_AC_BE: |
| 4407 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | |
| 4408 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4409 | prio = 2; |
| 4410 | acc = 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4411 | break; |
| 4412 | case IEEE80211_AC_BK: |
| 4413 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | |
| 4414 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4415 | prio = 0; |
| 4416 | acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4417 | break; |
| 4418 | } |
| 4419 | |
| 4420 | if (enable) |
| 4421 | arvif->u.sta.uapsd |= value; |
| 4422 | else |
| 4423 | arvif->u.sta.uapsd &= ~value; |
| 4424 | |
| 4425 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 4426 | WMI_STA_PS_PARAM_UAPSD, |
| 4427 | arvif->u.sta.uapsd); |
| 4428 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4429 | ath10k_warn(ar, "failed to set uapsd params: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4430 | goto exit; |
| 4431 | } |
| 4432 | |
| 4433 | if (arvif->u.sta.uapsd) |
| 4434 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
| 4435 | else |
| 4436 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 4437 | |
| 4438 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 4439 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, |
| 4440 | value); |
| 4441 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4442 | ath10k_warn(ar, "failed to set rx wake param: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4443 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 4444 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
| 4445 | if (ret) { |
| 4446 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
| 4447 | arvif->vdev_id, ret); |
| 4448 | return ret; |
| 4449 | } |
| 4450 | |
| 4451 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
| 4452 | if (ret) { |
| 4453 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
| 4454 | arvif->vdev_id, ret); |
| 4455 | return ret; |
| 4456 | } |
| 4457 | |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 4458 | if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) || |
| 4459 | test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) { |
| 4460 | /* Only userspace can make an educated decision when to send |
| 4461 | * trigger frame. The following effectively disables u-UAPSD |
| 4462 | * autotrigger in firmware (which is enabled by default |
| 4463 | * provided the autotrigger service is available). |
| 4464 | */ |
| 4465 | |
| 4466 | arg.wmm_ac = acc; |
| 4467 | arg.user_priority = prio; |
| 4468 | arg.service_interval = 0; |
| 4469 | arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 4470 | arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 4471 | |
| 4472 | ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id, |
| 4473 | arvif->bssid, &arg, 1); |
| 4474 | if (ret) { |
| 4475 | ath10k_warn(ar, "failed to set uapsd auto trigger %d\n", |
| 4476 | ret); |
| 4477 | return ret; |
| 4478 | } |
| 4479 | } |
| 4480 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4481 | exit: |
| 4482 | return ret; |
| 4483 | } |
| 4484 | |
| 4485 | static int ath10k_conf_tx(struct ieee80211_hw *hw, |
| 4486 | struct ieee80211_vif *vif, u16 ac, |
| 4487 | const struct ieee80211_tx_queue_params *params) |
| 4488 | { |
| 4489 | struct ath10k *ar = hw->priv; |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4490 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4491 | struct wmi_wmm_params_arg *p = NULL; |
| 4492 | int ret; |
| 4493 | |
| 4494 | mutex_lock(&ar->conf_mutex); |
| 4495 | |
| 4496 | switch (ac) { |
| 4497 | case IEEE80211_AC_VO: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4498 | p = &arvif->wmm_params.ac_vo; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4499 | break; |
| 4500 | case IEEE80211_AC_VI: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4501 | p = &arvif->wmm_params.ac_vi; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4502 | break; |
| 4503 | case IEEE80211_AC_BE: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4504 | p = &arvif->wmm_params.ac_be; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4505 | break; |
| 4506 | case IEEE80211_AC_BK: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 4507 | p = &arvif->wmm_params.ac_bk; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4508 | break; |
| 4509 | } |
| 4510 | |
| 4511 | if (WARN_ON(!p)) { |
| 4512 | ret = -EINVAL; |
| 4513 | goto exit; |
| 4514 | } |
| 4515 | |
| 4516 | p->cwmin = params->cw_min; |
| 4517 | p->cwmax = params->cw_max; |
| 4518 | p->aifs = params->aifs; |
| 4519 | |
| 4520 | /* |
| 4521 | * The channel time duration programmed in the HW is in absolute |
| 4522 | * microseconds, while mac80211 gives the txop in units of |
| 4523 | * 32 microseconds. |
| 4524 | */ |
| 4525 | p->txop = params->txop * 32; |
| 4526 | |
Michal Kazior | 7fc979a | 2015-01-28 09:57:28 +0200 | [diff] [blame] | 4527 | if (ar->wmi.ops->gen_vdev_wmm_conf) { |
| 4528 | ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id, |
| 4529 | &arvif->wmm_params); |
| 4530 | if (ret) { |
| 4531 | ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n", |
| 4532 | arvif->vdev_id, ret); |
| 4533 | goto exit; |
| 4534 | } |
| 4535 | } else { |
| 4536 | /* This won't work well with multi-interface cases but it's |
| 4537 | * better than nothing. |
| 4538 | */ |
| 4539 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params); |
| 4540 | if (ret) { |
| 4541 | ath10k_warn(ar, "failed to set wmm params: %d\n", ret); |
| 4542 | goto exit; |
| 4543 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); |
| 4547 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4548 | ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4549 | |
| 4550 | exit: |
| 4551 | mutex_unlock(&ar->conf_mutex); |
| 4552 | return ret; |
| 4553 | } |
| 4554 | |
| 4555 | #define ATH10K_ROC_TIMEOUT_HZ (2*HZ) |
| 4556 | |
| 4557 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, |
| 4558 | struct ieee80211_vif *vif, |
| 4559 | struct ieee80211_channel *chan, |
| 4560 | int duration, |
| 4561 | enum ieee80211_roc_type type) |
| 4562 | { |
| 4563 | struct ath10k *ar = hw->priv; |
| 4564 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4565 | struct wmi_start_scan_arg arg; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4566 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4567 | |
| 4568 | mutex_lock(&ar->conf_mutex); |
| 4569 | |
| 4570 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4571 | switch (ar->scan.state) { |
| 4572 | case ATH10K_SCAN_IDLE: |
| 4573 | reinit_completion(&ar->scan.started); |
| 4574 | reinit_completion(&ar->scan.completed); |
| 4575 | reinit_completion(&ar->scan.on_channel); |
| 4576 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 4577 | ar->scan.is_roc = true; |
| 4578 | ar->scan.vdev_id = arvif->vdev_id; |
| 4579 | ar->scan.roc_freq = chan->center_freq; |
| 4580 | ret = 0; |
| 4581 | break; |
| 4582 | case ATH10K_SCAN_STARTING: |
| 4583 | case ATH10K_SCAN_RUNNING: |
| 4584 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4585 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4586 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4587 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4588 | spin_unlock_bh(&ar->data_lock); |
| 4589 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4590 | if (ret) |
| 4591 | goto exit; |
| 4592 | |
Michal Kazior | dcca0bd | 2014-11-24 14:58:32 +0100 | [diff] [blame] | 4593 | duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC); |
| 4594 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4595 | memset(&arg, 0, sizeof(arg)); |
| 4596 | ath10k_wmi_start_scan_init(ar, &arg); |
| 4597 | arg.vdev_id = arvif->vdev_id; |
| 4598 | arg.scan_id = ATH10K_SCAN_ID; |
| 4599 | arg.n_channels = 1; |
| 4600 | arg.channels[0] = chan->center_freq; |
| 4601 | arg.dwell_time_active = duration; |
| 4602 | arg.dwell_time_passive = duration; |
| 4603 | arg.max_scan_time = 2 * duration; |
| 4604 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
| 4605 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; |
| 4606 | |
| 4607 | ret = ath10k_start_scan(ar, &arg); |
| 4608 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4609 | ath10k_warn(ar, "failed to start roc scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4610 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4611 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4612 | spin_unlock_bh(&ar->data_lock); |
| 4613 | goto exit; |
| 4614 | } |
| 4615 | |
| 4616 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ); |
| 4617 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4618 | ath10k_warn(ar, "failed to switch to channel for roc scan\n"); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4619 | |
| 4620 | ret = ath10k_scan_stop(ar); |
| 4621 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4622 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4623 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4624 | ret = -ETIMEDOUT; |
| 4625 | goto exit; |
| 4626 | } |
| 4627 | |
| 4628 | ret = 0; |
| 4629 | exit: |
| 4630 | mutex_unlock(&ar->conf_mutex); |
| 4631 | return ret; |
| 4632 | } |
| 4633 | |
| 4634 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 4635 | { |
| 4636 | struct ath10k *ar = hw->priv; |
| 4637 | |
| 4638 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4639 | ath10k_scan_abort(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4640 | mutex_unlock(&ar->conf_mutex); |
| 4641 | |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 4642 | cancel_delayed_work_sync(&ar->scan.timeout); |
| 4643 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4644 | return 0; |
| 4645 | } |
| 4646 | |
| 4647 | /* |
| 4648 | * Both RTS and Fragmentation threshold are interface-specific |
| 4649 | * in ath10k, but device-specific in mac80211. |
| 4650 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4651 | |
| 4652 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 4653 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4654 | struct ath10k *ar = hw->priv; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4655 | struct ath10k_vif *arvif; |
| 4656 | int ret = 0; |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4657 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4658 | mutex_lock(&ar->conf_mutex); |
| 4659 | list_for_each_entry(arvif, &ar->arvifs, list) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4660 | 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] | 4661 | arvif->vdev_id, value); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4662 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 4663 | ret = ath10k_mac_set_rts(arvif, value); |
| 4664 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4665 | 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] | 4666 | arvif->vdev_id, ret); |
| 4667 | break; |
| 4668 | } |
| 4669 | } |
| 4670 | mutex_unlock(&ar->conf_mutex); |
| 4671 | |
| 4672 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4673 | } |
| 4674 | |
Emmanuel Grumbach | 77be2c5 | 2014-03-27 11:30:29 +0200 | [diff] [blame] | 4675 | static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 4676 | u32 queues, bool drop) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4677 | { |
| 4678 | struct ath10k *ar = hw->priv; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4679 | bool skip; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4680 | int ret; |
| 4681 | |
| 4682 | /* mac80211 doesn't care if we really xmit queued frames or not |
| 4683 | * we'll collect those frames either way if we stop/delete vdevs */ |
| 4684 | if (drop) |
| 4685 | return; |
| 4686 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4687 | mutex_lock(&ar->conf_mutex); |
| 4688 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4689 | if (ar->state == ATH10K_STATE_WEDGED) |
| 4690 | goto skip; |
| 4691 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 4692 | ret = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4693 | bool empty; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4694 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 4695 | spin_lock_bh(&ar->htt.tx_lock); |
Michal Kazior | 0945baf | 2013-09-18 14:43:18 +0200 | [diff] [blame] | 4696 | empty = (ar->htt.num_pending_tx == 0); |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 4697 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4698 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 4699 | skip = (ar->state == ATH10K_STATE_WEDGED) || |
| 4700 | test_bit(ATH10K_FLAG_CRASH_FLUSH, |
| 4701 | &ar->dev_flags); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4702 | |
| 4703 | (empty || skip); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4704 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4705 | |
| 4706 | if (ret <= 0 || skip) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4707 | 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] | 4708 | skip, ar->state, ret); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4709 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4710 | skip: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4711 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | /* TODO: Implement this function properly |
| 4715 | * For now it is needed to reply to Probe Requests in IBSS mode. |
| 4716 | * Propably we need this information from FW. |
| 4717 | */ |
| 4718 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) |
| 4719 | { |
| 4720 | return 1; |
| 4721 | } |
| 4722 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4723 | #ifdef CONFIG_PM |
| 4724 | static int ath10k_suspend(struct ieee80211_hw *hw, |
| 4725 | struct cfg80211_wowlan *wowlan) |
| 4726 | { |
| 4727 | struct ath10k *ar = hw->priv; |
| 4728 | int ret; |
| 4729 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4730 | mutex_lock(&ar->conf_mutex); |
| 4731 | |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 4732 | ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND); |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4733 | if (ret) { |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 4734 | if (ret == -ETIMEDOUT) |
| 4735 | goto resume; |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4736 | ret = 1; |
| 4737 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4738 | } |
| 4739 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4740 | ret = ath10k_hif_suspend(ar); |
| 4741 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4742 | ath10k_warn(ar, "failed to suspend hif: %d\n", ret); |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4743 | goto resume; |
| 4744 | } |
| 4745 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4746 | ret = 0; |
| 4747 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4748 | resume: |
| 4749 | ret = ath10k_wmi_pdev_resume_target(ar); |
| 4750 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4751 | ath10k_warn(ar, "failed to resume target: %d\n", ret); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4752 | |
| 4753 | ret = 1; |
| 4754 | exit: |
| 4755 | mutex_unlock(&ar->conf_mutex); |
| 4756 | return ret; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | static int ath10k_resume(struct ieee80211_hw *hw) |
| 4760 | { |
| 4761 | struct ath10k *ar = hw->priv; |
| 4762 | int ret; |
| 4763 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4764 | mutex_lock(&ar->conf_mutex); |
| 4765 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4766 | ret = ath10k_hif_resume(ar); |
| 4767 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4768 | ath10k_warn(ar, "failed to resume hif: %d\n", ret); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4769 | ret = 1; |
| 4770 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | ret = ath10k_wmi_pdev_resume_target(ar); |
| 4774 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4775 | ath10k_warn(ar, "failed to resume target: %d\n", ret); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4776 | ret = 1; |
| 4777 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4778 | } |
| 4779 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 4780 | ret = 0; |
| 4781 | exit: |
| 4782 | mutex_unlock(&ar->conf_mutex); |
| 4783 | return ret; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4784 | } |
| 4785 | #endif |
| 4786 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 4787 | static void ath10k_reconfig_complete(struct ieee80211_hw *hw, |
| 4788 | enum ieee80211_reconfig_type reconfig_type) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4789 | { |
| 4790 | struct ath10k *ar = hw->priv; |
| 4791 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 4792 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
| 4793 | return; |
| 4794 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4795 | mutex_lock(&ar->conf_mutex); |
| 4796 | |
| 4797 | /* If device failed to restart it will be in a different state, e.g. |
| 4798 | * ATH10K_STATE_WEDGED */ |
| 4799 | if (ar->state == ATH10K_STATE_RESTARTED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4800 | ath10k_info(ar, "device successfully recovered\n"); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4801 | ar->state = ATH10K_STATE_ON; |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 4802 | ieee80211_wake_queues(ar->hw); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | mutex_unlock(&ar->conf_mutex); |
| 4806 | } |
| 4807 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 4808 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
| 4809 | struct survey_info *survey) |
| 4810 | { |
| 4811 | struct ath10k *ar = hw->priv; |
| 4812 | struct ieee80211_supported_band *sband; |
| 4813 | struct survey_info *ar_survey = &ar->survey[idx]; |
| 4814 | int ret = 0; |
| 4815 | |
| 4816 | mutex_lock(&ar->conf_mutex); |
| 4817 | |
| 4818 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 4819 | if (sband && idx >= sband->n_channels) { |
| 4820 | idx -= sband->n_channels; |
| 4821 | sband = NULL; |
| 4822 | } |
| 4823 | |
| 4824 | if (!sband) |
| 4825 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 4826 | |
| 4827 | if (!sband || idx >= sband->n_channels) { |
| 4828 | ret = -ENOENT; |
| 4829 | goto exit; |
| 4830 | } |
| 4831 | |
| 4832 | spin_lock_bh(&ar->data_lock); |
| 4833 | memcpy(survey, ar_survey, sizeof(*survey)); |
| 4834 | spin_unlock_bh(&ar->data_lock); |
| 4835 | |
| 4836 | survey->channel = &sband->channels[idx]; |
| 4837 | |
Felix Fietkau | fa1d4df | 2014-10-23 17:04:28 +0300 | [diff] [blame] | 4838 | if (ar->rx_channel == survey->channel) |
| 4839 | survey->filled |= SURVEY_INFO_IN_USE; |
| 4840 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 4841 | exit: |
| 4842 | mutex_unlock(&ar->conf_mutex); |
| 4843 | return ret; |
| 4844 | } |
| 4845 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4846 | /* Helper table for legacy fixed_rate/bitrate_mask */ |
| 4847 | static const u8 cck_ofdm_rate[] = { |
| 4848 | /* CCK */ |
| 4849 | 3, /* 1Mbps */ |
| 4850 | 2, /* 2Mbps */ |
| 4851 | 1, /* 5.5Mbps */ |
| 4852 | 0, /* 11Mbps */ |
| 4853 | /* OFDM */ |
| 4854 | 3, /* 6Mbps */ |
| 4855 | 7, /* 9Mbps */ |
| 4856 | 2, /* 12Mbps */ |
| 4857 | 6, /* 18Mbps */ |
| 4858 | 1, /* 24Mbps */ |
| 4859 | 5, /* 36Mbps */ |
| 4860 | 0, /* 48Mbps */ |
| 4861 | 4, /* 54Mbps */ |
| 4862 | }; |
| 4863 | |
| 4864 | /* Check if only one bit set */ |
| 4865 | static int ath10k_check_single_mask(u32 mask) |
| 4866 | { |
| 4867 | int bit; |
| 4868 | |
| 4869 | bit = ffs(mask); |
| 4870 | if (!bit) |
| 4871 | return 0; |
| 4872 | |
| 4873 | mask &= ~BIT(bit - 1); |
| 4874 | if (mask) |
| 4875 | return 2; |
| 4876 | |
| 4877 | return 1; |
| 4878 | } |
| 4879 | |
| 4880 | static bool |
| 4881 | ath10k_default_bitrate_mask(struct ath10k *ar, |
| 4882 | enum ieee80211_band band, |
| 4883 | const struct cfg80211_bitrate_mask *mask) |
| 4884 | { |
| 4885 | u32 legacy = 0x00ff; |
| 4886 | u8 ht = 0xff, i; |
| 4887 | u16 vht = 0x3ff; |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4888 | u16 nrf = ar->num_rf_chains; |
| 4889 | |
| 4890 | if (ar->cfg_tx_chainmask) |
| 4891 | nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4892 | |
| 4893 | switch (band) { |
| 4894 | case IEEE80211_BAND_2GHZ: |
| 4895 | legacy = 0x00fff; |
| 4896 | vht = 0; |
| 4897 | break; |
| 4898 | case IEEE80211_BAND_5GHZ: |
| 4899 | break; |
| 4900 | default: |
| 4901 | return false; |
| 4902 | } |
| 4903 | |
| 4904 | if (mask->control[band].legacy != legacy) |
| 4905 | return false; |
| 4906 | |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4907 | for (i = 0; i < nrf; i++) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4908 | if (mask->control[band].ht_mcs[i] != ht) |
| 4909 | return false; |
| 4910 | |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4911 | for (i = 0; i < nrf; i++) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4912 | if (mask->control[band].vht_mcs[i] != vht) |
| 4913 | return false; |
| 4914 | |
| 4915 | return true; |
| 4916 | } |
| 4917 | |
| 4918 | static bool |
| 4919 | ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask, |
| 4920 | enum ieee80211_band band, |
| 4921 | u8 *fixed_nss) |
| 4922 | { |
| 4923 | int ht_nss = 0, vht_nss = 0, i; |
| 4924 | |
| 4925 | /* check legacy */ |
| 4926 | if (ath10k_check_single_mask(mask->control[band].legacy)) |
| 4927 | return false; |
| 4928 | |
| 4929 | /* check HT */ |
| 4930 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
| 4931 | if (mask->control[band].ht_mcs[i] == 0xff) |
| 4932 | continue; |
| 4933 | else if (mask->control[band].ht_mcs[i] == 0x00) |
| 4934 | break; |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 4935 | |
| 4936 | return false; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | ht_nss = i; |
| 4940 | |
| 4941 | /* check VHT */ |
| 4942 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4943 | if (mask->control[band].vht_mcs[i] == 0x03ff) |
| 4944 | continue; |
| 4945 | else if (mask->control[band].vht_mcs[i] == 0x0000) |
| 4946 | break; |
Kalle Valo | d8bb26b | 2014-09-14 12:50:33 +0300 | [diff] [blame] | 4947 | |
| 4948 | return false; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | vht_nss = i; |
| 4952 | |
| 4953 | if (ht_nss > 0 && vht_nss > 0) |
| 4954 | return false; |
| 4955 | |
| 4956 | if (ht_nss) |
| 4957 | *fixed_nss = ht_nss; |
| 4958 | else if (vht_nss) |
| 4959 | *fixed_nss = vht_nss; |
| 4960 | else |
| 4961 | return false; |
| 4962 | |
| 4963 | return true; |
| 4964 | } |
| 4965 | |
| 4966 | static bool |
| 4967 | ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask, |
| 4968 | enum ieee80211_band band, |
| 4969 | enum wmi_rate_preamble *preamble) |
| 4970 | { |
| 4971 | int legacy = 0, ht = 0, vht = 0, i; |
| 4972 | |
| 4973 | *preamble = WMI_RATE_PREAMBLE_OFDM; |
| 4974 | |
| 4975 | /* check legacy */ |
| 4976 | legacy = ath10k_check_single_mask(mask->control[band].legacy); |
| 4977 | if (legacy > 1) |
| 4978 | return false; |
| 4979 | |
| 4980 | /* check HT */ |
| 4981 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4982 | ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]); |
| 4983 | if (ht > 1) |
| 4984 | return false; |
| 4985 | |
| 4986 | /* check VHT */ |
| 4987 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4988 | vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]); |
| 4989 | if (vht > 1) |
| 4990 | return false; |
| 4991 | |
| 4992 | /* Currently we support only one fixed_rate */ |
| 4993 | if ((legacy + ht + vht) != 1) |
| 4994 | return false; |
| 4995 | |
| 4996 | if (ht) |
| 4997 | *preamble = WMI_RATE_PREAMBLE_HT; |
| 4998 | else if (vht) |
| 4999 | *preamble = WMI_RATE_PREAMBLE_VHT; |
| 5000 | |
| 5001 | return true; |
| 5002 | } |
| 5003 | |
| 5004 | static bool |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5005 | ath10k_bitrate_mask_rate(struct ath10k *ar, |
| 5006 | const struct cfg80211_bitrate_mask *mask, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5007 | enum ieee80211_band band, |
| 5008 | u8 *fixed_rate, |
| 5009 | u8 *fixed_nss) |
| 5010 | { |
| 5011 | u8 rate = 0, pream = 0, nss = 0, i; |
| 5012 | enum wmi_rate_preamble preamble; |
| 5013 | |
| 5014 | /* Check if single rate correct */ |
| 5015 | if (!ath10k_bitrate_mask_correct(mask, band, &preamble)) |
| 5016 | return false; |
| 5017 | |
| 5018 | pream = preamble; |
| 5019 | |
| 5020 | switch (preamble) { |
| 5021 | case WMI_RATE_PREAMBLE_CCK: |
| 5022 | case WMI_RATE_PREAMBLE_OFDM: |
| 5023 | i = ffs(mask->control[band].legacy) - 1; |
| 5024 | |
| 5025 | if (band == IEEE80211_BAND_2GHZ && i < 4) |
| 5026 | pream = WMI_RATE_PREAMBLE_CCK; |
| 5027 | |
| 5028 | if (band == IEEE80211_BAND_5GHZ) |
| 5029 | i += 4; |
| 5030 | |
| 5031 | if (i >= ARRAY_SIZE(cck_ofdm_rate)) |
| 5032 | return false; |
| 5033 | |
| 5034 | rate = cck_ofdm_rate[i]; |
| 5035 | break; |
| 5036 | case WMI_RATE_PREAMBLE_HT: |
| 5037 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5038 | if (mask->control[band].ht_mcs[i]) |
| 5039 | break; |
| 5040 | |
| 5041 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
| 5042 | return false; |
| 5043 | |
| 5044 | rate = ffs(mask->control[band].ht_mcs[i]) - 1; |
| 5045 | nss = i; |
| 5046 | break; |
| 5047 | case WMI_RATE_PREAMBLE_VHT: |
| 5048 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 5049 | if (mask->control[band].vht_mcs[i]) |
| 5050 | break; |
| 5051 | |
| 5052 | if (i == NL80211_VHT_NSS_MAX) |
| 5053 | return false; |
| 5054 | |
| 5055 | rate = ffs(mask->control[band].vht_mcs[i]) - 1; |
| 5056 | nss = i; |
| 5057 | break; |
| 5058 | } |
| 5059 | |
| 5060 | *fixed_nss = nss + 1; |
| 5061 | nss <<= 4; |
| 5062 | pream <<= 6; |
| 5063 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5064 | 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] | 5065 | pream, nss, rate); |
| 5066 | |
| 5067 | *fixed_rate = pream | nss | rate; |
| 5068 | |
| 5069 | return true; |
| 5070 | } |
| 5071 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5072 | static bool ath10k_get_fixed_rate_nss(struct ath10k *ar, |
| 5073 | const struct cfg80211_bitrate_mask *mask, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5074 | enum ieee80211_band band, |
| 5075 | u8 *fixed_rate, |
| 5076 | u8 *fixed_nss) |
| 5077 | { |
| 5078 | /* First check full NSS mask, if we can simply limit NSS */ |
| 5079 | if (ath10k_bitrate_mask_nss(mask, band, fixed_nss)) |
| 5080 | return true; |
| 5081 | |
| 5082 | /* Next Check single rate is set */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5083 | return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif, |
| 5087 | u8 fixed_rate, |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5088 | u8 fixed_nss, |
| 5089 | u8 force_sgi) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5090 | { |
| 5091 | struct ath10k *ar = arvif->ar; |
| 5092 | u32 vdev_param; |
| 5093 | int ret = 0; |
| 5094 | |
| 5095 | mutex_lock(&ar->conf_mutex); |
| 5096 | |
| 5097 | if (arvif->fixed_rate == fixed_rate && |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5098 | arvif->fixed_nss == fixed_nss && |
| 5099 | arvif->force_sgi == force_sgi) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5100 | goto exit; |
| 5101 | |
| 5102 | if (fixed_rate == WMI_FIXED_RATE_NONE) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5103 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n"); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5104 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5105 | if (force_sgi) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5106 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n"); |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5107 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5108 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
| 5109 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5110 | vdev_param, fixed_rate); |
| 5111 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5112 | 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] | 5113 | fixed_rate, ret); |
| 5114 | ret = -EINVAL; |
| 5115 | goto exit; |
| 5116 | } |
| 5117 | |
| 5118 | arvif->fixed_rate = fixed_rate; |
| 5119 | |
| 5120 | vdev_param = ar->wmi.vdev_param->nss; |
| 5121 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5122 | vdev_param, fixed_nss); |
| 5123 | |
| 5124 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5125 | ath10k_warn(ar, "failed to set fixed nss param %d: %d\n", |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5126 | fixed_nss, ret); |
| 5127 | ret = -EINVAL; |
| 5128 | goto exit; |
| 5129 | } |
| 5130 | |
| 5131 | arvif->fixed_nss = fixed_nss; |
| 5132 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5133 | vdev_param = ar->wmi.vdev_param->sgi; |
| 5134 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5135 | force_sgi); |
| 5136 | |
| 5137 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5138 | ath10k_warn(ar, "failed to set sgi param %d: %d\n", |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5139 | force_sgi, ret); |
| 5140 | ret = -EINVAL; |
| 5141 | goto exit; |
| 5142 | } |
| 5143 | |
| 5144 | arvif->force_sgi = force_sgi; |
| 5145 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5146 | exit: |
| 5147 | mutex_unlock(&ar->conf_mutex); |
| 5148 | return ret; |
| 5149 | } |
| 5150 | |
| 5151 | static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw, |
| 5152 | struct ieee80211_vif *vif, |
| 5153 | const struct cfg80211_bitrate_mask *mask) |
| 5154 | { |
| 5155 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5156 | struct ath10k *ar = arvif->ar; |
| 5157 | enum ieee80211_band band = ar->hw->conf.chandef.chan->band; |
| 5158 | u8 fixed_rate = WMI_FIXED_RATE_NONE; |
| 5159 | u8 fixed_nss = ar->num_rf_chains; |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5160 | u8 force_sgi; |
| 5161 | |
Ben Greear | b116ea1 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5162 | if (ar->cfg_tx_chainmask) |
| 5163 | fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
| 5164 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5165 | force_sgi = mask->control[band].gi; |
| 5166 | if (force_sgi == NL80211_TXRATE_FORCE_LGI) |
| 5167 | return -EINVAL; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5168 | |
| 5169 | if (!ath10k_default_bitrate_mask(ar, band, mask)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5170 | if (!ath10k_get_fixed_rate_nss(ar, mask, band, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5171 | &fixed_rate, |
| 5172 | &fixed_nss)) |
| 5173 | return -EINVAL; |
| 5174 | } |
| 5175 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5176 | if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5177 | 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] | 5178 | return -EINVAL; |
| 5179 | } |
| 5180 | |
| 5181 | return ath10k_set_fixed_rate_param(arvif, fixed_rate, |
| 5182 | fixed_nss, force_sgi); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5183 | } |
| 5184 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5185 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
| 5186 | struct ieee80211_vif *vif, |
| 5187 | struct ieee80211_sta *sta, |
| 5188 | u32 changed) |
| 5189 | { |
| 5190 | struct ath10k *ar = hw->priv; |
| 5191 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 5192 | u32 bw, smps; |
| 5193 | |
| 5194 | spin_lock_bh(&ar->data_lock); |
| 5195 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5196 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5197 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
| 5198 | sta->addr, changed, sta->bandwidth, sta->rx_nss, |
| 5199 | sta->smps_mode); |
| 5200 | |
| 5201 | if (changed & IEEE80211_RC_BW_CHANGED) { |
| 5202 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5203 | |
| 5204 | switch (sta->bandwidth) { |
| 5205 | case IEEE80211_STA_RX_BW_20: |
| 5206 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5207 | break; |
| 5208 | case IEEE80211_STA_RX_BW_40: |
| 5209 | bw = WMI_PEER_CHWIDTH_40MHZ; |
| 5210 | break; |
| 5211 | case IEEE80211_STA_RX_BW_80: |
| 5212 | bw = WMI_PEER_CHWIDTH_80MHZ; |
| 5213 | break; |
| 5214 | case IEEE80211_STA_RX_BW_160: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5215 | ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 5216 | sta->bandwidth, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5217 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5218 | break; |
| 5219 | } |
| 5220 | |
| 5221 | arsta->bw = bw; |
| 5222 | } |
| 5223 | |
| 5224 | if (changed & IEEE80211_RC_NSS_CHANGED) |
| 5225 | arsta->nss = sta->rx_nss; |
| 5226 | |
| 5227 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 5228 | smps = WMI_PEER_SMPS_PS_NONE; |
| 5229 | |
| 5230 | switch (sta->smps_mode) { |
| 5231 | case IEEE80211_SMPS_AUTOMATIC: |
| 5232 | case IEEE80211_SMPS_OFF: |
| 5233 | smps = WMI_PEER_SMPS_PS_NONE; |
| 5234 | break; |
| 5235 | case IEEE80211_SMPS_STATIC: |
| 5236 | smps = WMI_PEER_SMPS_STATIC; |
| 5237 | break; |
| 5238 | case IEEE80211_SMPS_DYNAMIC: |
| 5239 | smps = WMI_PEER_SMPS_DYNAMIC; |
| 5240 | break; |
| 5241 | case IEEE80211_SMPS_NUM_MODES: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5242 | 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] | 5243 | sta->smps_mode, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5244 | smps = WMI_PEER_SMPS_PS_NONE; |
| 5245 | break; |
| 5246 | } |
| 5247 | |
| 5248 | arsta->smps = smps; |
| 5249 | } |
| 5250 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5251 | arsta->changed |= changed; |
| 5252 | |
| 5253 | spin_unlock_bh(&ar->data_lock); |
| 5254 | |
| 5255 | ieee80211_queue_work(hw, &arsta->update_wk); |
| 5256 | } |
| 5257 | |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 5258 | static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 5259 | { |
| 5260 | /* |
| 5261 | * FIXME: Return 0 for time being. Need to figure out whether FW |
| 5262 | * has the API to fetch 64-bit local TSF |
| 5263 | */ |
| 5264 | |
| 5265 | return 0; |
| 5266 | } |
| 5267 | |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5268 | static int ath10k_ampdu_action(struct ieee80211_hw *hw, |
| 5269 | struct ieee80211_vif *vif, |
| 5270 | enum ieee80211_ampdu_mlme_action action, |
| 5271 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 5272 | u8 buf_size) |
| 5273 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5274 | struct ath10k *ar = hw->priv; |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5275 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5276 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5277 | 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] | 5278 | arvif->vdev_id, sta->addr, tid, action); |
| 5279 | |
| 5280 | switch (action) { |
| 5281 | case IEEE80211_AMPDU_RX_START: |
| 5282 | case IEEE80211_AMPDU_RX_STOP: |
| 5283 | /* HTT AddBa/DelBa events trigger mac80211 Rx BA session |
| 5284 | * creation/removal. Do we need to verify this? |
| 5285 | */ |
| 5286 | return 0; |
| 5287 | case IEEE80211_AMPDU_TX_START: |
| 5288 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 5289 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 5290 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 5291 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 5292 | /* Firmware offloads Tx aggregation entirely so deny mac80211 |
| 5293 | * Tx aggregation requests. |
| 5294 | */ |
| 5295 | return -EOPNOTSUPP; |
| 5296 | } |
| 5297 | |
| 5298 | return -EINVAL; |
| 5299 | } |
| 5300 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5301 | static const struct ieee80211_ops ath10k_ops = { |
| 5302 | .tx = ath10k_tx, |
| 5303 | .start = ath10k_start, |
| 5304 | .stop = ath10k_stop, |
| 5305 | .config = ath10k_config, |
| 5306 | .add_interface = ath10k_add_interface, |
| 5307 | .remove_interface = ath10k_remove_interface, |
| 5308 | .configure_filter = ath10k_configure_filter, |
| 5309 | .bss_info_changed = ath10k_bss_info_changed, |
| 5310 | .hw_scan = ath10k_hw_scan, |
| 5311 | .cancel_hw_scan = ath10k_cancel_hw_scan, |
| 5312 | .set_key = ath10k_set_key, |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 5313 | .set_default_unicast_key = ath10k_set_default_unicast_key, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5314 | .sta_state = ath10k_sta_state, |
| 5315 | .conf_tx = ath10k_conf_tx, |
| 5316 | .remain_on_channel = ath10k_remain_on_channel, |
| 5317 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, |
| 5318 | .set_rts_threshold = ath10k_set_rts_threshold, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5319 | .flush = ath10k_flush, |
| 5320 | .tx_last_beacon = ath10k_tx_last_beacon, |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 5321 | .set_antenna = ath10k_set_antenna, |
| 5322 | .get_antenna = ath10k_get_antenna, |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 5323 | .reconfig_complete = ath10k_reconfig_complete, |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 5324 | .get_survey = ath10k_get_survey, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5325 | .set_bitrate_mask = ath10k_set_bitrate_mask, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5326 | .sta_rc_update = ath10k_sta_rc_update, |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 5327 | .get_tsf = ath10k_get_tsf, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 5328 | .ampdu_action = ath10k_ampdu_action, |
Ben Greear | 6cddcc7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 5329 | .get_et_sset_count = ath10k_debug_get_et_sset_count, |
| 5330 | .get_et_stats = ath10k_debug_get_et_stats, |
| 5331 | .get_et_strings = ath10k_debug_get_et_strings, |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 5332 | |
| 5333 | CFG80211_TESTMODE_CMD(ath10k_tm_cmd) |
| 5334 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 5335 | #ifdef CONFIG_PM |
| 5336 | .suspend = ath10k_suspend, |
| 5337 | .resume = ath10k_resume, |
| 5338 | #endif |
Rajkumar Manoharan | f504598 | 2015-01-12 14:07:27 +0200 | [diff] [blame] | 5339 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 5340 | .sta_add_debugfs = ath10k_sta_add_debugfs, |
| 5341 | #endif |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5342 | }; |
| 5343 | |
| 5344 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ |
| 5345 | .bitrate = (_rate), \ |
| 5346 | .flags = (_flags), \ |
| 5347 | .hw_value = (_rateid), \ |
| 5348 | } |
| 5349 | |
| 5350 | #define CHAN2G(_channel, _freq, _flags) { \ |
| 5351 | .band = IEEE80211_BAND_2GHZ, \ |
| 5352 | .hw_value = (_channel), \ |
| 5353 | .center_freq = (_freq), \ |
| 5354 | .flags = (_flags), \ |
| 5355 | .max_antenna_gain = 0, \ |
| 5356 | .max_power = 30, \ |
| 5357 | } |
| 5358 | |
| 5359 | #define CHAN5G(_channel, _freq, _flags) { \ |
| 5360 | .band = IEEE80211_BAND_5GHZ, \ |
| 5361 | .hw_value = (_channel), \ |
| 5362 | .center_freq = (_freq), \ |
| 5363 | .flags = (_flags), \ |
| 5364 | .max_antenna_gain = 0, \ |
| 5365 | .max_power = 30, \ |
| 5366 | } |
| 5367 | |
| 5368 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { |
| 5369 | CHAN2G(1, 2412, 0), |
| 5370 | CHAN2G(2, 2417, 0), |
| 5371 | CHAN2G(3, 2422, 0), |
| 5372 | CHAN2G(4, 2427, 0), |
| 5373 | CHAN2G(5, 2432, 0), |
| 5374 | CHAN2G(6, 2437, 0), |
| 5375 | CHAN2G(7, 2442, 0), |
| 5376 | CHAN2G(8, 2447, 0), |
| 5377 | CHAN2G(9, 2452, 0), |
| 5378 | CHAN2G(10, 2457, 0), |
| 5379 | CHAN2G(11, 2462, 0), |
| 5380 | CHAN2G(12, 2467, 0), |
| 5381 | CHAN2G(13, 2472, 0), |
| 5382 | CHAN2G(14, 2484, 0), |
| 5383 | }; |
| 5384 | |
| 5385 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 5386 | CHAN5G(36, 5180, 0), |
| 5387 | CHAN5G(40, 5200, 0), |
| 5388 | CHAN5G(44, 5220, 0), |
| 5389 | CHAN5G(48, 5240, 0), |
| 5390 | CHAN5G(52, 5260, 0), |
| 5391 | CHAN5G(56, 5280, 0), |
| 5392 | CHAN5G(60, 5300, 0), |
| 5393 | CHAN5G(64, 5320, 0), |
| 5394 | CHAN5G(100, 5500, 0), |
| 5395 | CHAN5G(104, 5520, 0), |
| 5396 | CHAN5G(108, 5540, 0), |
| 5397 | CHAN5G(112, 5560, 0), |
| 5398 | CHAN5G(116, 5580, 0), |
| 5399 | CHAN5G(120, 5600, 0), |
| 5400 | CHAN5G(124, 5620, 0), |
| 5401 | CHAN5G(128, 5640, 0), |
| 5402 | CHAN5G(132, 5660, 0), |
| 5403 | CHAN5G(136, 5680, 0), |
| 5404 | CHAN5G(140, 5700, 0), |
| 5405 | CHAN5G(149, 5745, 0), |
| 5406 | CHAN5G(153, 5765, 0), |
| 5407 | CHAN5G(157, 5785, 0), |
| 5408 | CHAN5G(161, 5805, 0), |
| 5409 | CHAN5G(165, 5825, 0), |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5410 | }; |
| 5411 | |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 5412 | /* Note: Be careful if you re-order these. There is code which depends on this |
| 5413 | * ordering. |
| 5414 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5415 | static struct ieee80211_rate ath10k_rates[] = { |
| 5416 | /* CCK */ |
| 5417 | RATETAB_ENT(10, 0x82, 0), |
| 5418 | RATETAB_ENT(20, 0x84, 0), |
| 5419 | RATETAB_ENT(55, 0x8b, 0), |
| 5420 | RATETAB_ENT(110, 0x96, 0), |
| 5421 | /* OFDM */ |
| 5422 | RATETAB_ENT(60, 0x0c, 0), |
| 5423 | RATETAB_ENT(90, 0x12, 0), |
| 5424 | RATETAB_ENT(120, 0x18, 0), |
| 5425 | RATETAB_ENT(180, 0x24, 0), |
| 5426 | RATETAB_ENT(240, 0x30, 0), |
| 5427 | RATETAB_ENT(360, 0x48, 0), |
| 5428 | RATETAB_ENT(480, 0x60, 0), |
| 5429 | RATETAB_ENT(540, 0x6c, 0), |
| 5430 | }; |
| 5431 | |
| 5432 | #define ath10k_a_rates (ath10k_rates + 4) |
| 5433 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4) |
| 5434 | #define ath10k_g_rates (ath10k_rates + 0) |
| 5435 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) |
| 5436 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 5437 | struct ath10k *ath10k_mac_create(size_t priv_size) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5438 | { |
| 5439 | struct ieee80211_hw *hw; |
| 5440 | struct ath10k *ar; |
| 5441 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 5442 | hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5443 | if (!hw) |
| 5444 | return NULL; |
| 5445 | |
| 5446 | ar = hw->priv; |
| 5447 | ar->hw = hw; |
| 5448 | |
| 5449 | return ar; |
| 5450 | } |
| 5451 | |
| 5452 | void ath10k_mac_destroy(struct ath10k *ar) |
| 5453 | { |
| 5454 | ieee80211_free_hw(ar->hw); |
| 5455 | } |
| 5456 | |
| 5457 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { |
| 5458 | { |
| 5459 | .max = 8, |
| 5460 | .types = BIT(NL80211_IFTYPE_STATION) |
| 5461 | | BIT(NL80211_IFTYPE_P2P_CLIENT) |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 5462 | }, |
| 5463 | { |
| 5464 | .max = 3, |
| 5465 | .types = BIT(NL80211_IFTYPE_P2P_GO) |
| 5466 | }, |
| 5467 | { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 5468 | .max = 1, |
| 5469 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) |
| 5470 | }, |
| 5471 | { |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 5472 | .max = 7, |
| 5473 | .types = BIT(NL80211_IFTYPE_AP) |
| 5474 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5475 | }; |
| 5476 | |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5477 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5478 | { |
| 5479 | .max = 8, |
| 5480 | .types = BIT(NL80211_IFTYPE_AP) |
| 5481 | }, |
| 5482 | }; |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5483 | |
| 5484 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { |
| 5485 | { |
| 5486 | .limits = ath10k_if_limits, |
| 5487 | .n_limits = ARRAY_SIZE(ath10k_if_limits), |
| 5488 | .max_interfaces = 8, |
| 5489 | .num_different_channels = 1, |
| 5490 | .beacon_int_infra_match = true, |
| 5491 | }, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5492 | }; |
| 5493 | |
| 5494 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5495 | { |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5496 | .limits = ath10k_10x_if_limits, |
| 5497 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5498 | .max_interfaces = 8, |
| 5499 | .num_different_channels = 1, |
| 5500 | .beacon_int_infra_match = true, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5501 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5502 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 5503 | BIT(NL80211_CHAN_WIDTH_20) | |
| 5504 | BIT(NL80211_CHAN_WIDTH_40) | |
| 5505 | BIT(NL80211_CHAN_WIDTH_80), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 5506 | #endif |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5507 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5508 | }; |
| 5509 | |
| 5510 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) |
| 5511 | { |
| 5512 | struct ieee80211_sta_vht_cap vht_cap = {0}; |
| 5513 | u16 mcs_map; |
Michal Kazior | bc657a36 | 2015-02-26 11:11:22 +0100 | [diff] [blame] | 5514 | u32 val; |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 5515 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5516 | |
| 5517 | vht_cap.vht_supported = 1; |
| 5518 | vht_cap.cap = ar->vht_cap_info; |
| 5519 | |
Michal Kazior | bc657a36 | 2015-02-26 11:11:22 +0100 | [diff] [blame] | 5520 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 5521 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 5522 | val = ar->num_rf_chains - 1; |
| 5523 | val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; |
| 5524 | val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 5525 | |
| 5526 | vht_cap.cap |= val; |
| 5527 | } |
| 5528 | |
| 5529 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 5530 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 5531 | val = ar->num_rf_chains - 1; |
| 5532 | val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; |
| 5533 | val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; |
| 5534 | |
| 5535 | vht_cap.cap |= val; |
| 5536 | } |
| 5537 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 5538 | mcs_map = 0; |
| 5539 | for (i = 0; i < 8; i++) { |
| 5540 | if (i < ar->num_rf_chains) |
| 5541 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2); |
| 5542 | else |
| 5543 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2); |
| 5544 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5545 | |
| 5546 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 5547 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 5548 | |
| 5549 | return vht_cap; |
| 5550 | } |
| 5551 | |
| 5552 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) |
| 5553 | { |
| 5554 | int i; |
| 5555 | struct ieee80211_sta_ht_cap ht_cap = {0}; |
| 5556 | |
| 5557 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) |
| 5558 | return ht_cap; |
| 5559 | |
| 5560 | ht_cap.ht_supported = 1; |
| 5561 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 5562 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; |
| 5563 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 5564 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 5565 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 5566 | |
| 5567 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) |
| 5568 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 5569 | |
| 5570 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) |
| 5571 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 5572 | |
| 5573 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { |
| 5574 | u32 smps; |
| 5575 | |
| 5576 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; |
| 5577 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 5578 | |
| 5579 | ht_cap.cap |= smps; |
| 5580 | } |
| 5581 | |
| 5582 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC) |
| 5583 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 5584 | |
| 5585 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { |
| 5586 | u32 stbc; |
| 5587 | |
| 5588 | stbc = ar->ht_cap_info; |
| 5589 | stbc &= WMI_HT_CAP_RX_STBC; |
| 5590 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; |
| 5591 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 5592 | stbc &= IEEE80211_HT_CAP_RX_STBC; |
| 5593 | |
| 5594 | ht_cap.cap |= stbc; |
| 5595 | } |
| 5596 | |
| 5597 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC) |
| 5598 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; |
| 5599 | |
| 5600 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) |
| 5601 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; |
| 5602 | |
| 5603 | /* max AMSDU is implicitly taken from vht_cap_info */ |
| 5604 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) |
| 5605 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
| 5606 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 5607 | for (i = 0; i < ar->num_rf_chains; i++) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5608 | ht_cap.mcs.rx_mask[i] = 0xFF; |
| 5609 | |
| 5610 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
| 5611 | |
| 5612 | return ht_cap; |
| 5613 | } |
| 5614 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5615 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
| 5616 | struct ieee80211_vif *vif) |
| 5617 | { |
| 5618 | struct ath10k_vif_iter *arvif_iter = data; |
| 5619 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5620 | |
| 5621 | if (arvif->vdev_id == arvif_iter->vdev_id) |
| 5622 | arvif_iter->arvif = arvif; |
| 5623 | } |
| 5624 | |
| 5625 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) |
| 5626 | { |
| 5627 | struct ath10k_vif_iter arvif_iter; |
| 5628 | u32 flags; |
| 5629 | |
| 5630 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); |
| 5631 | arvif_iter.vdev_id = vdev_id; |
| 5632 | |
| 5633 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; |
| 5634 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 5635 | flags, |
| 5636 | ath10k_get_arvif_iter, |
| 5637 | &arvif_iter); |
| 5638 | if (!arvif_iter.arvif) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5639 | ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5640 | return NULL; |
| 5641 | } |
| 5642 | |
| 5643 | return arvif_iter.arvif; |
| 5644 | } |
| 5645 | |
| 5646 | int ath10k_mac_register(struct ath10k *ar) |
| 5647 | { |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 5648 | static const u32 cipher_suites[] = { |
| 5649 | WLAN_CIPHER_SUITE_WEP40, |
| 5650 | WLAN_CIPHER_SUITE_WEP104, |
| 5651 | WLAN_CIPHER_SUITE_TKIP, |
| 5652 | WLAN_CIPHER_SUITE_CCMP, |
| 5653 | WLAN_CIPHER_SUITE_AES_CMAC, |
| 5654 | }; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5655 | struct ieee80211_supported_band *band; |
| 5656 | struct ieee80211_sta_vht_cap vht_cap; |
| 5657 | struct ieee80211_sta_ht_cap ht_cap; |
| 5658 | void *channels; |
| 5659 | int ret; |
| 5660 | |
| 5661 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); |
| 5662 | |
| 5663 | SET_IEEE80211_DEV(ar->hw, ar->dev); |
| 5664 | |
| 5665 | ht_cap = ath10k_get_ht_cap(ar); |
| 5666 | vht_cap = ath10k_create_vht_cap(ar); |
| 5667 | |
| 5668 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
| 5669 | channels = kmemdup(ath10k_2ghz_channels, |
| 5670 | sizeof(ath10k_2ghz_channels), |
| 5671 | GFP_KERNEL); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5672 | if (!channels) { |
| 5673 | ret = -ENOMEM; |
| 5674 | goto err_free; |
| 5675 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5676 | |
| 5677 | band = &ar->mac.sbands[IEEE80211_BAND_2GHZ]; |
| 5678 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); |
| 5679 | band->channels = channels; |
| 5680 | band->n_bitrates = ath10k_g_rates_size; |
| 5681 | band->bitrates = ath10k_g_rates; |
| 5682 | band->ht_cap = ht_cap; |
| 5683 | |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 5684 | /* Enable the VHT support at 2.4 GHz */ |
| 5685 | band->vht_cap = vht_cap; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5686 | |
| 5687 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band; |
| 5688 | } |
| 5689 | |
| 5690 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { |
| 5691 | channels = kmemdup(ath10k_5ghz_channels, |
| 5692 | sizeof(ath10k_5ghz_channels), |
| 5693 | GFP_KERNEL); |
| 5694 | if (!channels) { |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5695 | ret = -ENOMEM; |
| 5696 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5697 | } |
| 5698 | |
| 5699 | band = &ar->mac.sbands[IEEE80211_BAND_5GHZ]; |
| 5700 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); |
| 5701 | band->channels = channels; |
| 5702 | band->n_bitrates = ath10k_a_rates_size; |
| 5703 | band->bitrates = ath10k_a_rates; |
| 5704 | band->ht_cap = ht_cap; |
| 5705 | band->vht_cap = vht_cap; |
| 5706 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band; |
| 5707 | } |
| 5708 | |
| 5709 | ar->hw->wiphy->interface_modes = |
| 5710 | BIT(NL80211_IFTYPE_STATION) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 5711 | BIT(NL80211_IFTYPE_AP); |
| 5712 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 5713 | ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask; |
| 5714 | ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask; |
| 5715 | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 5716 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features)) |
| 5717 | ar->hw->wiphy->interface_modes |= |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 5718 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 5719 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 5720 | BIT(NL80211_IFTYPE_P2P_GO); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5721 | |
| 5722 | ar->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 5723 | IEEE80211_HW_SUPPORTS_PS | |
| 5724 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5725 | IEEE80211_HW_MFP_CAPABLE | |
| 5726 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 5727 | IEEE80211_HW_HAS_RATE_CONTROL | |
Janusz Dziedzic | 2f0f112 | 2014-02-26 18:42:09 +0200 | [diff] [blame] | 5728 | IEEE80211_HW_AP_LINK_PS | |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 5729 | IEEE80211_HW_SPECTRUM_MGMT | |
| 5730 | IEEE80211_HW_SW_CRYPTO_CONTROL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5731 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 5732 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
| 5733 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5734 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 5735 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5736 | |
| 5737 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { |
| 5738 | ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; |
| 5739 | ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW; |
| 5740 | } |
| 5741 | |
| 5742 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
| 5743 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; |
| 5744 | |
| 5745 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5746 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5747 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5748 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
| 5749 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 5750 | if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) { |
| 5751 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 5752 | |
| 5753 | /* Firmware delivers WPS/P2P Probe Requests frames to driver so |
| 5754 | * that userspace (e.g. wpa_supplicant/hostapd) can generate |
| 5755 | * correct Probe Responses. This is more of a hack advert.. |
| 5756 | */ |
| 5757 | ar->hw->wiphy->probe_resp_offload |= |
| 5758 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 5759 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 5760 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 5761 | } |
| 5762 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5763 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 5764 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5765 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 5766 | |
| 5767 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
Rajkumar Manoharan | 78157a1 | 2014-11-17 16:44:15 +0200 | [diff] [blame] | 5768 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE; |
| 5769 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5770 | /* |
| 5771 | * on LL hardware queues are managed entirely by the FW |
| 5772 | * so we only advertise to mac we can do the queues thing |
| 5773 | */ |
| 5774 | ar->hw->queues = 4; |
| 5775 | |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 5776 | switch (ar->wmi.op_version) { |
| 5777 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
| 5778 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5779 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
| 5780 | ar->hw->wiphy->n_iface_combinations = |
| 5781 | ARRAY_SIZE(ath10k_if_comb); |
Michal Kazior | cf850d1 | 2014-07-24 20:07:00 +0300 | [diff] [blame] | 5782 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 5783 | break; |
| 5784 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
| 5785 | case ATH10K_FW_WMI_OP_VERSION_10_2: |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 5786 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 5787 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
| 5788 | ar->hw->wiphy->n_iface_combinations = |
| 5789 | ARRAY_SIZE(ath10k_10x_if_comb); |
| 5790 | break; |
| 5791 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
| 5792 | case ATH10K_FW_WMI_OP_VERSION_MAX: |
| 5793 | WARN_ON(1); |
| 5794 | ret = -EINVAL; |
| 5795 | goto err_free; |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 5796 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5797 | |
Michal Kazior | 7c19999 | 2013-07-31 10:47:57 +0200 | [diff] [blame] | 5798 | ar->hw->netdev_features = NETIF_F_HW_CSUM; |
| 5799 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 5800 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
| 5801 | /* Init ath dfs pattern detector */ |
| 5802 | ar->ath_common.debug_mask = ATH_DBG_DFS; |
| 5803 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, |
| 5804 | NL80211_DFS_UNSET); |
| 5805 | |
| 5806 | if (!ar->dfs_detector) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5807 | ath10k_warn(ar, "failed to initialise DFS pattern detector\n"); |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 5808 | } |
| 5809 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5810 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
| 5811 | ath10k_reg_notifier); |
| 5812 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5813 | ath10k_err(ar, "failed to initialise regulatory: %i\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5814 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5815 | } |
| 5816 | |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 5817 | ar->hw->wiphy->cipher_suites = cipher_suites; |
| 5818 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 5819 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5820 | ret = ieee80211_register_hw(ar->hw); |
| 5821 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5822 | ath10k_err(ar, "failed to register ieee80211: %d\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5823 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5824 | } |
| 5825 | |
| 5826 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { |
| 5827 | ret = regulatory_hint(ar->hw->wiphy, |
| 5828 | ar->ath_common.regulatory.alpha2); |
| 5829 | if (ret) |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5830 | goto err_unregister; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | return 0; |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5834 | |
| 5835 | err_unregister: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5836 | ieee80211_unregister_hw(ar->hw); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 5837 | err_free: |
| 5838 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 5839 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 5840 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5841 | return ret; |
| 5842 | } |
| 5843 | |
| 5844 | void ath10k_mac_unregister(struct ath10k *ar) |
| 5845 | { |
| 5846 | ieee80211_unregister_hw(ar->hw); |
| 5847 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 5848 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
| 5849 | ar->dfs_detector->exit(ar->dfs_detector); |
| 5850 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5851 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 5852 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 5853 | |
| 5854 | SET_IEEE80211_DEV(ar->hw, NULL); |
| 5855 | } |