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