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" |
| 29 | |
| 30 | /**********/ |
| 31 | /* Crypto */ |
| 32 | /**********/ |
| 33 | |
| 34 | static int ath10k_send_key(struct ath10k_vif *arvif, |
| 35 | struct ieee80211_key_conf *key, |
| 36 | enum set_key_cmd cmd, |
| 37 | const u8 *macaddr) |
| 38 | { |
| 39 | struct wmi_vdev_install_key_arg arg = { |
| 40 | .vdev_id = arvif->vdev_id, |
| 41 | .key_idx = key->keyidx, |
| 42 | .key_len = key->keylen, |
| 43 | .key_data = key->key, |
| 44 | .macaddr = macaddr, |
| 45 | }; |
| 46 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 47 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 48 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 49 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 50 | arg.key_flags = WMI_KEY_PAIRWISE; |
| 51 | else |
| 52 | arg.key_flags = WMI_KEY_GROUP; |
| 53 | |
| 54 | switch (key->cipher) { |
| 55 | case WLAN_CIPHER_SUITE_CCMP: |
| 56 | arg.key_cipher = WMI_CIPHER_AES_CCM; |
| 57 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
| 58 | break; |
| 59 | case WLAN_CIPHER_SUITE_TKIP: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 60 | arg.key_cipher = WMI_CIPHER_TKIP; |
| 61 | arg.key_txmic_len = 8; |
| 62 | arg.key_rxmic_len = 8; |
| 63 | break; |
| 64 | case WLAN_CIPHER_SUITE_WEP40: |
| 65 | case WLAN_CIPHER_SUITE_WEP104: |
| 66 | arg.key_cipher = WMI_CIPHER_WEP; |
| 67 | /* AP/IBSS mode requires self-key to be groupwise |
| 68 | * Otherwise pairwise key must be set */ |
| 69 | if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN)) |
| 70 | arg.key_flags = WMI_KEY_PAIRWISE; |
| 71 | break; |
| 72 | default: |
| 73 | ath10k_warn("cipher %d is not supported\n", key->cipher); |
| 74 | return -EOPNOTSUPP; |
| 75 | } |
| 76 | |
| 77 | if (cmd == DISABLE_KEY) { |
| 78 | arg.key_cipher = WMI_CIPHER_NONE; |
| 79 | arg.key_data = NULL; |
| 80 | } |
| 81 | |
| 82 | return ath10k_wmi_vdev_install_key(arvif->ar, &arg); |
| 83 | } |
| 84 | |
| 85 | static int ath10k_install_key(struct ath10k_vif *arvif, |
| 86 | struct ieee80211_key_conf *key, |
| 87 | enum set_key_cmd cmd, |
| 88 | const u8 *macaddr) |
| 89 | { |
| 90 | struct ath10k *ar = arvif->ar; |
| 91 | int ret; |
| 92 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 93 | lockdep_assert_held(&ar->conf_mutex); |
| 94 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 95 | reinit_completion(&ar->install_key_done); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 96 | |
| 97 | ret = ath10k_send_key(arvif, key, cmd, macaddr); |
| 98 | if (ret) |
| 99 | return ret; |
| 100 | |
| 101 | ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ); |
| 102 | if (ret == 0) |
| 103 | return -ETIMEDOUT; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif, |
| 109 | const u8 *addr) |
| 110 | { |
| 111 | struct ath10k *ar = arvif->ar; |
| 112 | struct ath10k_peer *peer; |
| 113 | int ret; |
| 114 | int i; |
| 115 | |
| 116 | lockdep_assert_held(&ar->conf_mutex); |
| 117 | |
| 118 | spin_lock_bh(&ar->data_lock); |
| 119 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 120 | spin_unlock_bh(&ar->data_lock); |
| 121 | |
| 122 | if (!peer) |
| 123 | return -ENOENT; |
| 124 | |
| 125 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { |
| 126 | if (arvif->wep_keys[i] == NULL) |
| 127 | continue; |
| 128 | |
| 129 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY, |
| 130 | addr); |
| 131 | if (ret) |
| 132 | return ret; |
| 133 | |
| 134 | peer->keys[i] = arvif->wep_keys[i]; |
| 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | static int ath10k_clear_peer_keys(struct ath10k_vif *arvif, |
| 141 | const u8 *addr) |
| 142 | { |
| 143 | struct ath10k *ar = arvif->ar; |
| 144 | struct ath10k_peer *peer; |
| 145 | int first_errno = 0; |
| 146 | int ret; |
| 147 | int i; |
| 148 | |
| 149 | lockdep_assert_held(&ar->conf_mutex); |
| 150 | |
| 151 | spin_lock_bh(&ar->data_lock); |
| 152 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 153 | spin_unlock_bh(&ar->data_lock); |
| 154 | |
| 155 | if (!peer) |
| 156 | return -ENOENT; |
| 157 | |
| 158 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 159 | if (peer->keys[i] == NULL) |
| 160 | continue; |
| 161 | |
| 162 | ret = ath10k_install_key(arvif, peer->keys[i], |
| 163 | DISABLE_KEY, addr); |
| 164 | if (ret && first_errno == 0) |
| 165 | first_errno = ret; |
| 166 | |
| 167 | if (ret) |
| 168 | ath10k_warn("could not remove peer wep key %d (%d)\n", |
| 169 | i, ret); |
| 170 | |
| 171 | peer->keys[i] = NULL; |
| 172 | } |
| 173 | |
| 174 | return first_errno; |
| 175 | } |
| 176 | |
| 177 | static int ath10k_clear_vdev_key(struct ath10k_vif *arvif, |
| 178 | struct ieee80211_key_conf *key) |
| 179 | { |
| 180 | struct ath10k *ar = arvif->ar; |
| 181 | struct ath10k_peer *peer; |
| 182 | u8 addr[ETH_ALEN]; |
| 183 | int first_errno = 0; |
| 184 | int ret; |
| 185 | int i; |
| 186 | |
| 187 | lockdep_assert_held(&ar->conf_mutex); |
| 188 | |
| 189 | for (;;) { |
| 190 | /* since ath10k_install_key we can't hold data_lock all the |
| 191 | * time, so we try to remove the keys incrementally */ |
| 192 | spin_lock_bh(&ar->data_lock); |
| 193 | i = 0; |
| 194 | list_for_each_entry(peer, &ar->peers, list) { |
| 195 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 196 | if (peer->keys[i] == key) { |
| 197 | memcpy(addr, peer->addr, ETH_ALEN); |
| 198 | peer->keys[i] = NULL; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (i < ARRAY_SIZE(peer->keys)) |
| 204 | break; |
| 205 | } |
| 206 | spin_unlock_bh(&ar->data_lock); |
| 207 | |
| 208 | if (i == ARRAY_SIZE(peer->keys)) |
| 209 | break; |
| 210 | |
| 211 | ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr); |
| 212 | if (ret && first_errno == 0) |
| 213 | first_errno = ret; |
| 214 | |
| 215 | if (ret) |
| 216 | ath10k_warn("could not remove key for %pM\n", addr); |
| 217 | } |
| 218 | |
| 219 | return first_errno; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /*********************/ |
| 224 | /* General utilities */ |
| 225 | /*********************/ |
| 226 | |
| 227 | static inline enum wmi_phy_mode |
| 228 | chan_to_phymode(const struct cfg80211_chan_def *chandef) |
| 229 | { |
| 230 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 231 | |
| 232 | switch (chandef->chan->band) { |
| 233 | case IEEE80211_BAND_2GHZ: |
| 234 | switch (chandef->width) { |
| 235 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 236 | phymode = MODE_11G; |
| 237 | break; |
| 238 | case NL80211_CHAN_WIDTH_20: |
| 239 | phymode = MODE_11NG_HT20; |
| 240 | break; |
| 241 | case NL80211_CHAN_WIDTH_40: |
| 242 | phymode = MODE_11NG_HT40; |
| 243 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 244 | case NL80211_CHAN_WIDTH_5: |
| 245 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 246 | case NL80211_CHAN_WIDTH_80: |
| 247 | case NL80211_CHAN_WIDTH_80P80: |
| 248 | case NL80211_CHAN_WIDTH_160: |
| 249 | phymode = MODE_UNKNOWN; |
| 250 | break; |
| 251 | } |
| 252 | break; |
| 253 | case IEEE80211_BAND_5GHZ: |
| 254 | switch (chandef->width) { |
| 255 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 256 | phymode = MODE_11A; |
| 257 | break; |
| 258 | case NL80211_CHAN_WIDTH_20: |
| 259 | phymode = MODE_11NA_HT20; |
| 260 | break; |
| 261 | case NL80211_CHAN_WIDTH_40: |
| 262 | phymode = MODE_11NA_HT40; |
| 263 | break; |
| 264 | case NL80211_CHAN_WIDTH_80: |
| 265 | phymode = MODE_11AC_VHT80; |
| 266 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 267 | case NL80211_CHAN_WIDTH_5: |
| 268 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 269 | case NL80211_CHAN_WIDTH_80P80: |
| 270 | case NL80211_CHAN_WIDTH_160: |
| 271 | phymode = MODE_UNKNOWN; |
| 272 | break; |
| 273 | } |
| 274 | break; |
| 275 | default: |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | WARN_ON(phymode == MODE_UNKNOWN); |
| 280 | return phymode; |
| 281 | } |
| 282 | |
| 283 | static u8 ath10k_parse_mpdudensity(u8 mpdudensity) |
| 284 | { |
| 285 | /* |
| 286 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 287 | * 0 for no restriction |
| 288 | * 1 for 1/4 us |
| 289 | * 2 for 1/2 us |
| 290 | * 3 for 1 us |
| 291 | * 4 for 2 us |
| 292 | * 5 for 4 us |
| 293 | * 6 for 8 us |
| 294 | * 7 for 16 us |
| 295 | */ |
| 296 | switch (mpdudensity) { |
| 297 | case 0: |
| 298 | return 0; |
| 299 | case 1: |
| 300 | case 2: |
| 301 | case 3: |
| 302 | /* Our lower layer calculations limit our precision to |
| 303 | 1 microsecond */ |
| 304 | return 1; |
| 305 | case 4: |
| 306 | return 2; |
| 307 | case 5: |
| 308 | return 4; |
| 309 | case 6: |
| 310 | return 8; |
| 311 | case 7: |
| 312 | return 16; |
| 313 | default: |
| 314 | return 0; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
| 319 | { |
| 320 | int ret; |
| 321 | |
| 322 | lockdep_assert_held(&ar->conf_mutex); |
| 323 | |
| 324 | ret = ath10k_wmi_peer_create(ar, vdev_id, addr); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 325 | if (ret) { |
| 326 | ath10k_warn("Failed to create wmi peer: %i\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 327 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 328 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 329 | |
| 330 | ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 331 | if (ret) { |
| 332 | ath10k_warn("Failed to wait for created wmi peer: %i\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 333 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 334 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 335 | spin_lock_bh(&ar->data_lock); |
| 336 | ar->num_peers++; |
| 337 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 342 | static int ath10k_mac_set_kickout(struct ath10k_vif *arvif) |
| 343 | { |
| 344 | struct ath10k *ar = arvif->ar; |
| 345 | u32 param; |
| 346 | int ret; |
| 347 | |
| 348 | param = ar->wmi.pdev_param->sta_kickout_th; |
| 349 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 350 | ATH10K_KICKOUT_THRESHOLD); |
| 351 | if (ret) { |
| 352 | ath10k_warn("Failed to set kickout threshold: %d\n", ret); |
| 353 | return ret; |
| 354 | } |
| 355 | |
| 356 | param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs; |
| 357 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 358 | ATH10K_KEEPALIVE_MIN_IDLE); |
| 359 | if (ret) { |
| 360 | ath10k_warn("Failed to set keepalive minimum idle time : %d\n", |
| 361 | ret); |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs; |
| 366 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 367 | ATH10K_KEEPALIVE_MAX_IDLE); |
| 368 | if (ret) { |
| 369 | ath10k_warn("Failed to set keepalive maximum idle time: %d\n", |
| 370 | ret); |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs; |
| 375 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 376 | ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); |
| 377 | if (ret) { |
| 378 | ath10k_warn("Failed to set keepalive maximum unresponsive time: %d\n", |
| 379 | ret); |
| 380 | return ret; |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 386 | static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value) |
| 387 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 388 | struct ath10k *ar = arvif->ar; |
| 389 | u32 vdev_param; |
| 390 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 391 | if (value != 0xFFFFFFFF) |
| 392 | value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold, |
| 393 | ATH10K_RTS_MAX); |
| 394 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 395 | vdev_param = ar->wmi.vdev_param->rts_threshold; |
| 396 | 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] | 397 | } |
| 398 | |
| 399 | static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value) |
| 400 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 401 | struct ath10k *ar = arvif->ar; |
| 402 | u32 vdev_param; |
| 403 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 404 | if (value != 0xFFFFFFFF) |
| 405 | value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold, |
| 406 | ATH10K_FRAGMT_THRESHOLD_MIN, |
| 407 | ATH10K_FRAGMT_THRESHOLD_MAX); |
| 408 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 409 | vdev_param = ar->wmi.vdev_param->fragmentation_threshold; |
| 410 | 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] | 411 | } |
| 412 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 413 | static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
| 414 | { |
| 415 | int ret; |
| 416 | |
| 417 | lockdep_assert_held(&ar->conf_mutex); |
| 418 | |
| 419 | ret = ath10k_wmi_peer_delete(ar, vdev_id, addr); |
| 420 | if (ret) |
| 421 | return ret; |
| 422 | |
| 423 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); |
| 424 | if (ret) |
| 425 | return ret; |
| 426 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 427 | spin_lock_bh(&ar->data_lock); |
| 428 | ar->num_peers--; |
| 429 | spin_unlock_bh(&ar->data_lock); |
| 430 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id) |
| 435 | { |
| 436 | struct ath10k_peer *peer, *tmp; |
| 437 | |
| 438 | lockdep_assert_held(&ar->conf_mutex); |
| 439 | |
| 440 | spin_lock_bh(&ar->data_lock); |
| 441 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 442 | if (peer->vdev_id != vdev_id) |
| 443 | continue; |
| 444 | |
| 445 | ath10k_warn("removing stale peer %pM from vdev_id %d\n", |
| 446 | peer->addr, vdev_id); |
| 447 | |
| 448 | list_del(&peer->list); |
| 449 | kfree(peer); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 450 | ar->num_peers--; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 451 | } |
| 452 | spin_unlock_bh(&ar->data_lock); |
| 453 | } |
| 454 | |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 455 | static void ath10k_peer_cleanup_all(struct ath10k *ar) |
| 456 | { |
| 457 | struct ath10k_peer *peer, *tmp; |
| 458 | |
| 459 | lockdep_assert_held(&ar->conf_mutex); |
| 460 | |
| 461 | spin_lock_bh(&ar->data_lock); |
| 462 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 463 | list_del(&peer->list); |
| 464 | kfree(peer); |
| 465 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 466 | ar->num_peers = 0; |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 467 | spin_unlock_bh(&ar->data_lock); |
| 468 | } |
| 469 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 470 | /************************/ |
| 471 | /* Interface management */ |
| 472 | /************************/ |
| 473 | |
| 474 | static inline int ath10k_vdev_setup_sync(struct ath10k *ar) |
| 475 | { |
| 476 | int ret; |
| 477 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 478 | lockdep_assert_held(&ar->conf_mutex); |
| 479 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 480 | ret = wait_for_completion_timeout(&ar->vdev_setup_done, |
| 481 | ATH10K_VDEV_SETUP_TIMEOUT_HZ); |
| 482 | if (ret == 0) |
| 483 | return -ETIMEDOUT; |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static int ath10k_vdev_start(struct ath10k_vif *arvif) |
| 489 | { |
| 490 | struct ath10k *ar = arvif->ar; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 491 | struct cfg80211_chan_def *chandef = &ar->chandef; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 492 | struct wmi_vdev_start_request_arg arg = {}; |
| 493 | int ret = 0; |
| 494 | |
| 495 | lockdep_assert_held(&ar->conf_mutex); |
| 496 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 497 | reinit_completion(&ar->vdev_setup_done); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 498 | |
| 499 | arg.vdev_id = arvif->vdev_id; |
| 500 | arg.dtim_period = arvif->dtim_period; |
| 501 | arg.bcn_intval = arvif->beacon_interval; |
| 502 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 503 | arg.channel.freq = chandef->chan->center_freq; |
| 504 | arg.channel.band_center_freq1 = chandef->center_freq1; |
| 505 | arg.channel.mode = chan_to_phymode(chandef); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 506 | |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 507 | arg.channel.min_power = 0; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 508 | arg.channel.max_power = chandef->chan->max_power * 2; |
| 509 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; |
| 510 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 511 | |
| 512 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 513 | arg.ssid = arvif->u.ap.ssid; |
| 514 | arg.ssid_len = arvif->u.ap.ssid_len; |
| 515 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 516 | |
| 517 | /* For now allow DFS for AP mode */ |
| 518 | arg.channel.chan_radar = |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 519 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 520 | } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
| 521 | arg.ssid = arvif->vif->bss_conf.ssid; |
| 522 | arg.ssid_len = arvif->vif->bss_conf.ssid_len; |
| 523 | } |
| 524 | |
Kalle Valo | 38a1d47 | 2013-09-08 17:56:14 +0300 | [diff] [blame] | 525 | ath10k_dbg(ATH10K_DBG_MAC, |
| 526 | "mac vdev %d start center_freq %d phymode %s\n", |
| 527 | arg.vdev_id, arg.channel.freq, |
| 528 | ath10k_wmi_phymode_str(arg.channel.mode)); |
| 529 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 530 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 531 | if (ret) { |
| 532 | ath10k_warn("WMI vdev start failed: ret %d\n", ret); |
| 533 | return ret; |
| 534 | } |
| 535 | |
| 536 | ret = ath10k_vdev_setup_sync(ar); |
| 537 | if (ret) { |
| 538 | ath10k_warn("vdev setup failed %d\n", ret); |
| 539 | return ret; |
| 540 | } |
| 541 | |
| 542 | return ret; |
| 543 | } |
| 544 | |
| 545 | static int ath10k_vdev_stop(struct ath10k_vif *arvif) |
| 546 | { |
| 547 | struct ath10k *ar = arvif->ar; |
| 548 | int ret; |
| 549 | |
| 550 | lockdep_assert_held(&ar->conf_mutex); |
| 551 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 552 | reinit_completion(&ar->vdev_setup_done); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 553 | |
| 554 | ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); |
| 555 | if (ret) { |
| 556 | ath10k_warn("WMI vdev stop failed: ret %d\n", ret); |
| 557 | return ret; |
| 558 | } |
| 559 | |
| 560 | ret = ath10k_vdev_setup_sync(ar); |
| 561 | if (ret) { |
| 562 | ath10k_warn("vdev setup failed %d\n", ret); |
| 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | return ret; |
| 567 | } |
| 568 | |
| 569 | static int ath10k_monitor_start(struct ath10k *ar, int vdev_id) |
| 570 | { |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 571 | struct cfg80211_chan_def *chandef = &ar->chandef; |
| 572 | struct ieee80211_channel *channel = chandef->chan; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 573 | struct wmi_vdev_start_request_arg arg = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 574 | int ret = 0; |
| 575 | |
| 576 | lockdep_assert_held(&ar->conf_mutex); |
| 577 | |
Michal Kazior | 0ed00ee | 2013-10-16 16:45:48 +0300 | [diff] [blame] | 578 | if (!ar->monitor_present) { |
| 579 | ath10k_warn("mac montor stop -- monitor is not present\n"); |
| 580 | return -EINVAL; |
| 581 | } |
| 582 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 583 | arg.vdev_id = vdev_id; |
| 584 | arg.channel.freq = channel->center_freq; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 585 | arg.channel.band_center_freq1 = chandef->center_freq1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 586 | |
| 587 | /* TODO setup this dynamically, what in case we |
| 588 | don't have any vifs? */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 589 | arg.channel.mode = chan_to_phymode(chandef); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 590 | arg.channel.chan_radar = |
| 591 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 592 | |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 593 | arg.channel.min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 594 | arg.channel.max_power = channel->max_power * 2; |
| 595 | arg.channel.max_reg_power = channel->max_reg_power * 2; |
| 596 | arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 597 | |
| 598 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 599 | if (ret) { |
| 600 | ath10k_warn("Monitor vdev start failed: ret %d\n", ret); |
| 601 | return ret; |
| 602 | } |
| 603 | |
| 604 | ret = ath10k_vdev_setup_sync(ar); |
| 605 | if (ret) { |
| 606 | ath10k_warn("Monitor vdev setup failed %d\n", ret); |
| 607 | return ret; |
| 608 | } |
| 609 | |
| 610 | ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); |
| 611 | if (ret) { |
| 612 | ath10k_warn("Monitor vdev up failed: %d\n", ret); |
| 613 | goto vdev_stop; |
| 614 | } |
| 615 | |
| 616 | ar->monitor_vdev_id = vdev_id; |
| 617 | ar->monitor_enabled = true; |
| 618 | |
| 619 | return 0; |
| 620 | |
| 621 | vdev_stop: |
| 622 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 623 | if (ret) |
| 624 | ath10k_warn("Monitor vdev stop failed: %d\n", ret); |
| 625 | |
| 626 | return ret; |
| 627 | } |
| 628 | |
| 629 | static int ath10k_monitor_stop(struct ath10k *ar) |
| 630 | { |
| 631 | int ret = 0; |
| 632 | |
| 633 | lockdep_assert_held(&ar->conf_mutex); |
| 634 | |
Michal Kazior | 0ed00ee | 2013-10-16 16:45:48 +0300 | [diff] [blame] | 635 | if (!ar->monitor_present) { |
| 636 | ath10k_warn("mac montor stop -- monitor is not present\n"); |
| 637 | return -EINVAL; |
| 638 | } |
| 639 | |
| 640 | if (!ar->monitor_enabled) { |
| 641 | ath10k_warn("mac montor stop -- monitor is not enabled\n"); |
| 642 | return -EINVAL; |
| 643 | } |
| 644 | |
Marek Puzyniak | 52fa019 | 2013-09-24 14:06:24 +0200 | [diff] [blame] | 645 | ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
| 646 | if (ret) |
| 647 | ath10k_warn("Monitor vdev down failed: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 648 | |
| 649 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 650 | if (ret) |
| 651 | ath10k_warn("Monitor vdev stop failed: %d\n", ret); |
| 652 | |
| 653 | ret = ath10k_vdev_setup_sync(ar); |
| 654 | if (ret) |
| 655 | ath10k_warn("Monitor_down sync failed: %d\n", ret); |
| 656 | |
| 657 | ar->monitor_enabled = false; |
| 658 | return ret; |
| 659 | } |
| 660 | |
| 661 | static int ath10k_monitor_create(struct ath10k *ar) |
| 662 | { |
| 663 | int bit, ret = 0; |
| 664 | |
| 665 | lockdep_assert_held(&ar->conf_mutex); |
| 666 | |
| 667 | if (ar->monitor_present) { |
| 668 | ath10k_warn("Monitor mode already enabled\n"); |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | bit = ffs(ar->free_vdev_map); |
| 673 | if (bit == 0) { |
| 674 | ath10k_warn("No free VDEV slots\n"); |
| 675 | return -ENOMEM; |
| 676 | } |
| 677 | |
| 678 | ar->monitor_vdev_id = bit - 1; |
| 679 | ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id); |
| 680 | |
| 681 | ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, |
| 682 | WMI_VDEV_TYPE_MONITOR, |
| 683 | 0, ar->mac_addr); |
| 684 | if (ret) { |
| 685 | ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret); |
| 686 | goto vdev_fail; |
| 687 | } |
| 688 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 689 | ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 690 | ar->monitor_vdev_id); |
| 691 | |
| 692 | ar->monitor_present = true; |
| 693 | return 0; |
| 694 | |
| 695 | vdev_fail: |
| 696 | /* |
| 697 | * Restore the ID to the global map. |
| 698 | */ |
| 699 | ar->free_vdev_map |= 1 << (ar->monitor_vdev_id); |
| 700 | return ret; |
| 701 | } |
| 702 | |
| 703 | static int ath10k_monitor_destroy(struct ath10k *ar) |
| 704 | { |
| 705 | int ret = 0; |
| 706 | |
| 707 | lockdep_assert_held(&ar->conf_mutex); |
| 708 | |
| 709 | if (!ar->monitor_present) |
| 710 | return 0; |
| 711 | |
| 712 | ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
| 713 | if (ret) { |
| 714 | ath10k_warn("WMI vdev monitor delete failed: %d\n", ret); |
| 715 | return ret; |
| 716 | } |
| 717 | |
| 718 | ar->free_vdev_map |= 1 << (ar->monitor_vdev_id); |
| 719 | ar->monitor_present = false; |
| 720 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 721 | ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 722 | ar->monitor_vdev_id); |
| 723 | return ret; |
| 724 | } |
| 725 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 726 | static int ath10k_start_cac(struct ath10k *ar) |
| 727 | { |
| 728 | int ret; |
| 729 | |
| 730 | lockdep_assert_held(&ar->conf_mutex); |
| 731 | |
| 732 | set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 733 | |
| 734 | ret = ath10k_monitor_create(ar); |
| 735 | if (ret) { |
| 736 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 737 | return ret; |
| 738 | } |
| 739 | |
| 740 | ret = ath10k_monitor_start(ar, ar->monitor_vdev_id); |
| 741 | if (ret) { |
| 742 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 743 | ath10k_monitor_destroy(ar); |
| 744 | return ret; |
| 745 | } |
| 746 | |
| 747 | ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n", |
| 748 | ar->monitor_vdev_id); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | static int ath10k_stop_cac(struct ath10k *ar) |
| 754 | { |
| 755 | lockdep_assert_held(&ar->conf_mutex); |
| 756 | |
| 757 | /* CAC is not running - do nothing */ |
| 758 | if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) |
| 759 | return 0; |
| 760 | |
| 761 | ath10k_monitor_stop(ar); |
| 762 | ath10k_monitor_destroy(ar); |
| 763 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 764 | |
| 765 | ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n"); |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state) |
| 771 | { |
| 772 | switch (dfs_state) { |
| 773 | case NL80211_DFS_USABLE: |
| 774 | return "USABLE"; |
| 775 | case NL80211_DFS_UNAVAILABLE: |
| 776 | return "UNAVAILABLE"; |
| 777 | case NL80211_DFS_AVAILABLE: |
| 778 | return "AVAILABLE"; |
| 779 | default: |
| 780 | WARN_ON(1); |
| 781 | return "bug"; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | static void ath10k_config_radar_detection(struct ath10k *ar) |
| 786 | { |
| 787 | struct ieee80211_channel *chan = ar->hw->conf.chandef.chan; |
| 788 | bool radar = ar->hw->conf.radar_enabled; |
| 789 | bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR); |
| 790 | enum nl80211_dfs_state dfs_state = chan->dfs_state; |
| 791 | int ret; |
| 792 | |
| 793 | lockdep_assert_held(&ar->conf_mutex); |
| 794 | |
| 795 | ath10k_dbg(ATH10K_DBG_MAC, |
| 796 | "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n", |
| 797 | chan->center_freq, radar, chan_radar, |
| 798 | ath10k_dfs_state(dfs_state)); |
| 799 | |
| 800 | /* |
| 801 | * It's safe to call it even if CAC is not started. |
| 802 | * This call here guarantees changing channel, etc. will stop CAC. |
| 803 | */ |
| 804 | ath10k_stop_cac(ar); |
| 805 | |
| 806 | if (!radar) |
| 807 | return; |
| 808 | |
| 809 | if (!chan_radar) |
| 810 | return; |
| 811 | |
| 812 | if (dfs_state != NL80211_DFS_USABLE) |
| 813 | return; |
| 814 | |
| 815 | ret = ath10k_start_cac(ar); |
| 816 | if (ret) { |
| 817 | /* |
| 818 | * Not possible to start CAC on current channel so starting |
| 819 | * radiation is not allowed, make this channel DFS_UNAVAILABLE |
| 820 | * by indicating that radar was detected. |
| 821 | */ |
| 822 | ath10k_warn("failed to start CAC (%d)\n", ret); |
| 823 | ieee80211_radar_detected(ar->hw); |
| 824 | } |
| 825 | } |
| 826 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 827 | static void ath10k_control_beaconing(struct ath10k_vif *arvif, |
| 828 | struct ieee80211_bss_conf *info) |
| 829 | { |
| 830 | int ret = 0; |
| 831 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 832 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 833 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 834 | if (!info->enable_beacon) { |
| 835 | ath10k_vdev_stop(arvif); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 836 | |
| 837 | arvif->is_started = false; |
| 838 | arvif->is_up = false; |
| 839 | |
Michal Kazior | 748afc4 | 2014-01-23 12:48:21 +0100 | [diff] [blame] | 840 | spin_lock_bh(&arvif->ar->data_lock); |
| 841 | if (arvif->beacon) { |
| 842 | ath10k_skb_unmap(arvif->ar->dev, arvif->beacon); |
| 843 | dev_kfree_skb_any(arvif->beacon); |
| 844 | |
| 845 | arvif->beacon = NULL; |
| 846 | arvif->beacon_sent = false; |
| 847 | } |
| 848 | spin_unlock_bh(&arvif->ar->data_lock); |
| 849 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 850 | return; |
| 851 | } |
| 852 | |
| 853 | arvif->tx_seq_no = 0x1000; |
| 854 | |
| 855 | ret = ath10k_vdev_start(arvif); |
| 856 | if (ret) |
| 857 | return; |
| 858 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 859 | arvif->aid = 0; |
| 860 | memcpy(arvif->bssid, info->bssid, ETH_ALEN); |
| 861 | |
| 862 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 863 | arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 864 | if (ret) { |
| 865 | ath10k_warn("Failed to bring up VDEV: %d\n", |
| 866 | arvif->vdev_id); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 867 | ath10k_vdev_stop(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 868 | return; |
| 869 | } |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 870 | |
| 871 | arvif->is_started = true; |
| 872 | arvif->is_up = true; |
| 873 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 874 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static void ath10k_control_ibss(struct ath10k_vif *arvif, |
| 878 | struct ieee80211_bss_conf *info, |
| 879 | const u8 self_peer[ETH_ALEN]) |
| 880 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 881 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 882 | int ret = 0; |
| 883 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 884 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 885 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 886 | if (!info->ibss_joined) { |
| 887 | ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer); |
| 888 | if (ret) |
| 889 | ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n", |
| 890 | self_peer, arvif->vdev_id, ret); |
| 891 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 892 | if (is_zero_ether_addr(arvif->bssid)) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 893 | return; |
| 894 | |
| 895 | ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 896 | arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 897 | if (ret) { |
| 898 | ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n", |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 899 | arvif->bssid, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 903 | memset(arvif->bssid, 0, ETH_ALEN); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 904 | |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer); |
| 909 | if (ret) { |
| 910 | ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n", |
| 911 | self_peer, arvif->vdev_id, ret); |
| 912 | return; |
| 913 | } |
| 914 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 915 | vdev_param = arvif->ar->wmi.vdev_param->atim_window; |
| 916 | 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] | 917 | ATH10K_DEFAULT_ATIM); |
| 918 | if (ret) |
| 919 | ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n", |
| 920 | arvif->vdev_id, ret); |
| 921 | } |
| 922 | |
| 923 | /* |
| 924 | * Review this when mac80211 gains per-interface powersave support. |
| 925 | */ |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 926 | static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 927 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 928 | struct ath10k *ar = arvif->ar; |
| 929 | struct ieee80211_conf *conf = &ar->hw->conf; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 930 | enum wmi_sta_powersave_param param; |
| 931 | enum wmi_sta_ps_mode psmode; |
| 932 | int ret; |
| 933 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 934 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 935 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 936 | if (arvif->vif->type != NL80211_IFTYPE_STATION) |
| 937 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 938 | |
| 939 | if (conf->flags & IEEE80211_CONF_PS) { |
| 940 | psmode = WMI_STA_PS_MODE_ENABLED; |
| 941 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; |
| 942 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 943 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 944 | conf->dynamic_ps_timeout); |
| 945 | if (ret) { |
| 946 | ath10k_warn("Failed to set inactivity time for VDEV: %d\n", |
| 947 | arvif->vdev_id); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 948 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 949 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 950 | } else { |
| 951 | psmode = WMI_STA_PS_MODE_DISABLED; |
| 952 | } |
| 953 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 954 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n", |
| 955 | arvif->vdev_id, psmode ? "enable" : "disable"); |
| 956 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 957 | ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode); |
| 958 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 959 | ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n", |
| 960 | psmode, arvif->vdev_id); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 961 | return ret; |
| 962 | } |
| 963 | |
| 964 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | /**********************/ |
| 968 | /* Station management */ |
| 969 | /**********************/ |
| 970 | |
| 971 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
| 972 | struct ath10k_vif *arvif, |
| 973 | struct ieee80211_sta *sta, |
| 974 | struct ieee80211_bss_conf *bss_conf, |
| 975 | struct wmi_peer_assoc_complete_arg *arg) |
| 976 | { |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 977 | lockdep_assert_held(&ar->conf_mutex); |
| 978 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 979 | memcpy(arg->addr, sta->addr, ETH_ALEN); |
| 980 | arg->vdev_id = arvif->vdev_id; |
| 981 | arg->peer_aid = sta->aid; |
| 982 | arg->peer_flags |= WMI_PEER_AUTH; |
| 983 | |
| 984 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 985 | /* |
| 986 | * Seems FW have problems with Power Save in STA |
| 987 | * mode when we setup this parameter to high (eg. 5). |
| 988 | * Often we see that FW don't send NULL (with clean P flags) |
| 989 | * frame even there is info about buffered frames in beacons. |
| 990 | * Sometimes we have to wait more than 10 seconds before FW |
| 991 | * will wakeup. Often sending one ping from AP to our device |
| 992 | * just fail (more than 50%). |
| 993 | * |
| 994 | * Seems setting this FW parameter to 1 couse FW |
| 995 | * will check every beacon and will wakup immediately |
| 996 | * after detection buffered data. |
| 997 | */ |
| 998 | arg->peer_listen_intval = 1; |
| 999 | else |
| 1000 | arg->peer_listen_intval = ar->hw->conf.listen_interval; |
| 1001 | |
| 1002 | arg->peer_num_spatial_streams = 1; |
| 1003 | |
| 1004 | /* |
| 1005 | * The assoc capabilities are available only in managed mode. |
| 1006 | */ |
| 1007 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf) |
| 1008 | arg->peer_caps = bss_conf->assoc_capability; |
| 1009 | } |
| 1010 | |
| 1011 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, |
| 1012 | struct ath10k_vif *arvif, |
| 1013 | struct wmi_peer_assoc_complete_arg *arg) |
| 1014 | { |
| 1015 | struct ieee80211_vif *vif = arvif->vif; |
| 1016 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
| 1017 | struct cfg80211_bss *bss; |
| 1018 | const u8 *rsnie = NULL; |
| 1019 | const u8 *wpaie = NULL; |
| 1020 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1021 | lockdep_assert_held(&ar->conf_mutex); |
| 1022 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1023 | bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan, |
| 1024 | info->bssid, NULL, 0, 0, 0); |
| 1025 | if (bss) { |
| 1026 | const struct cfg80211_bss_ies *ies; |
| 1027 | |
| 1028 | rcu_read_lock(); |
| 1029 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); |
| 1030 | |
| 1031 | ies = rcu_dereference(bss->ies); |
| 1032 | |
| 1033 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
| 1034 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 1035 | ies->data, |
| 1036 | ies->len); |
| 1037 | rcu_read_unlock(); |
| 1038 | cfg80211_put_bss(ar->hw->wiphy, bss); |
| 1039 | } |
| 1040 | |
| 1041 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ |
| 1042 | if (rsnie || wpaie) { |
| 1043 | ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
| 1044 | arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; |
| 1045 | } |
| 1046 | |
| 1047 | if (wpaie) { |
| 1048 | ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
| 1049 | arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, |
| 1054 | struct ieee80211_sta *sta, |
| 1055 | struct wmi_peer_assoc_complete_arg *arg) |
| 1056 | { |
| 1057 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
| 1058 | const struct ieee80211_supported_band *sband; |
| 1059 | const struct ieee80211_rate *rates; |
| 1060 | u32 ratemask; |
| 1061 | int i; |
| 1062 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1063 | lockdep_assert_held(&ar->conf_mutex); |
| 1064 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1065 | sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band]; |
| 1066 | ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band]; |
| 1067 | rates = sband->bitrates; |
| 1068 | |
| 1069 | rateset->num_rates = 0; |
| 1070 | |
| 1071 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { |
| 1072 | if (!(ratemask & 1)) |
| 1073 | continue; |
| 1074 | |
| 1075 | rateset->rates[rateset->num_rates] = rates->hw_value; |
| 1076 | rateset->num_rates++; |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, |
| 1081 | struct ieee80211_sta *sta, |
| 1082 | struct wmi_peer_assoc_complete_arg *arg) |
| 1083 | { |
| 1084 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1085 | int i, n; |
| 1086 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1087 | lockdep_assert_held(&ar->conf_mutex); |
| 1088 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1089 | if (!ht_cap->ht_supported) |
| 1090 | return; |
| 1091 | |
| 1092 | arg->peer_flags |= WMI_PEER_HT; |
| 1093 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 1094 | ht_cap->ampdu_factor)) - 1; |
| 1095 | |
| 1096 | arg->peer_mpdu_density = |
| 1097 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); |
| 1098 | |
| 1099 | arg->peer_ht_caps = ht_cap->cap; |
| 1100 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; |
| 1101 | |
| 1102 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) |
| 1103 | arg->peer_flags |= WMI_PEER_LDPC; |
| 1104 | |
| 1105 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
| 1106 | arg->peer_flags |= WMI_PEER_40MHZ; |
| 1107 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; |
| 1108 | } |
| 1109 | |
| 1110 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) |
| 1111 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 1112 | |
| 1113 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) |
| 1114 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 1115 | |
| 1116 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { |
| 1117 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; |
| 1118 | arg->peer_flags |= WMI_PEER_STBC; |
| 1119 | } |
| 1120 | |
| 1121 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { |
| 1122 | u32 stbc; |
| 1123 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
| 1124 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 1125 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; |
| 1126 | arg->peer_rate_caps |= stbc; |
| 1127 | arg->peer_flags |= WMI_PEER_STBC; |
| 1128 | } |
| 1129 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1130 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
| 1131 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; |
| 1132 | else if (ht_cap->mcs.rx_mask[1]) |
| 1133 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; |
| 1134 | |
| 1135 | for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++) |
| 1136 | if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8)) |
| 1137 | arg->peer_ht_rates.rates[n++] = i; |
| 1138 | |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 1139 | /* |
| 1140 | * This is a workaround for HT-enabled STAs which break the spec |
| 1141 | * and have no HT capabilities RX mask (no HT RX MCS map). |
| 1142 | * |
| 1143 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), |
| 1144 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. |
| 1145 | * |
| 1146 | * Firmware asserts if such situation occurs. |
| 1147 | */ |
| 1148 | if (n == 0) { |
| 1149 | arg->peer_ht_rates.num_rates = 8; |
| 1150 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) |
| 1151 | arg->peer_ht_rates.rates[i] = i; |
| 1152 | } else { |
| 1153 | arg->peer_ht_rates.num_rates = n; |
| 1154 | arg->peer_num_spatial_streams = sta->rx_nss; |
| 1155 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1156 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1157 | ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n", |
| 1158 | arg->addr, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1159 | arg->peer_ht_rates.num_rates, |
| 1160 | arg->peer_num_spatial_streams); |
| 1161 | } |
| 1162 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1163 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
| 1164 | struct ath10k_vif *arvif, |
| 1165 | struct ieee80211_sta *sta) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1166 | { |
| 1167 | u32 uapsd = 0; |
| 1168 | u32 max_sp = 0; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1169 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1170 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1171 | lockdep_assert_held(&ar->conf_mutex); |
| 1172 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1173 | if (sta->wme && sta->uapsd_queues) { |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1174 | ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1175 | sta->uapsd_queues, sta->max_sp); |
| 1176 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1177 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 1178 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | |
| 1179 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; |
| 1180 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 1181 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | |
| 1182 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; |
| 1183 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 1184 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | |
| 1185 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; |
| 1186 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 1187 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | |
| 1188 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; |
| 1189 | |
| 1190 | |
| 1191 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
| 1192 | max_sp = sta->max_sp; |
| 1193 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1194 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 1195 | sta->addr, |
| 1196 | WMI_AP_PS_PEER_PARAM_UAPSD, |
| 1197 | uapsd); |
| 1198 | if (ret) { |
| 1199 | ath10k_warn("failed to set ap ps peer param uapsd: %d\n", |
| 1200 | ret); |
| 1201 | return ret; |
| 1202 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1203 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1204 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 1205 | sta->addr, |
| 1206 | WMI_AP_PS_PEER_PARAM_MAX_SP, |
| 1207 | max_sp); |
| 1208 | if (ret) { |
| 1209 | ath10k_warn("failed to set ap ps peer param max sp: %d\n", |
| 1210 | ret); |
| 1211 | return ret; |
| 1212 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1213 | |
| 1214 | /* TODO setup this based on STA listen interval and |
| 1215 | beacon interval. Currently we don't know |
| 1216 | sta->listen_interval - mac80211 patch required. |
| 1217 | Currently use 10 seconds */ |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1218 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr, |
| 1219 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10); |
| 1220 | if (ret) { |
| 1221 | ath10k_warn("failed to set ap ps peer param ageout time: %d\n", |
| 1222 | ret); |
| 1223 | return ret; |
| 1224 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1225 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1226 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1227 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, |
| 1231 | struct ieee80211_sta *sta, |
| 1232 | struct wmi_peer_assoc_complete_arg *arg) |
| 1233 | { |
| 1234 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 1235 | u8 ampdu_factor; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1236 | |
| 1237 | if (!vht_cap->vht_supported) |
| 1238 | return; |
| 1239 | |
| 1240 | arg->peer_flags |= WMI_PEER_VHT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1241 | arg->peer_vht_caps = vht_cap->cap; |
| 1242 | |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 1243 | |
| 1244 | ampdu_factor = (vht_cap->cap & |
| 1245 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> |
| 1246 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 1247 | |
| 1248 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to |
| 1249 | * zero in VHT IE. Using it would result in degraded throughput. |
| 1250 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep |
| 1251 | * it if VHT max_mpdu is smaller. */ |
| 1252 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
| 1253 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 1254 | ampdu_factor)) - 1); |
| 1255 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1256 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 1257 | arg->peer_flags |= WMI_PEER_80MHZ; |
| 1258 | |
| 1259 | arg->peer_vht_rates.rx_max_rate = |
| 1260 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
| 1261 | arg->peer_vht_rates.rx_mcs_set = |
| 1262 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 1263 | arg->peer_vht_rates.tx_max_rate = |
| 1264 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); |
| 1265 | arg->peer_vht_rates.tx_mcs_set = |
| 1266 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map); |
| 1267 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1268 | ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n", |
| 1269 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, |
| 1273 | struct ath10k_vif *arvif, |
| 1274 | struct ieee80211_sta *sta, |
| 1275 | struct ieee80211_bss_conf *bss_conf, |
| 1276 | struct wmi_peer_assoc_complete_arg *arg) |
| 1277 | { |
| 1278 | switch (arvif->vdev_type) { |
| 1279 | case WMI_VDEV_TYPE_AP: |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1280 | if (sta->wme) |
| 1281 | arg->peer_flags |= WMI_PEER_QOS; |
| 1282 | |
| 1283 | if (sta->wme && sta->uapsd_queues) { |
| 1284 | arg->peer_flags |= WMI_PEER_APSD; |
| 1285 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; |
| 1286 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1287 | break; |
| 1288 | case WMI_VDEV_TYPE_STA: |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1289 | if (bss_conf->qos) |
| 1290 | arg->peer_flags |= WMI_PEER_QOS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1291 | break; |
| 1292 | default: |
| 1293 | break; |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
| 1298 | struct ath10k_vif *arvif, |
| 1299 | struct ieee80211_sta *sta, |
| 1300 | struct wmi_peer_assoc_complete_arg *arg) |
| 1301 | { |
| 1302 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 1303 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1304 | switch (ar->hw->conf.chandef.chan->band) { |
| 1305 | case IEEE80211_BAND_2GHZ: |
| 1306 | if (sta->ht_cap.ht_supported) { |
| 1307 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1308 | phymode = MODE_11NG_HT40; |
| 1309 | else |
| 1310 | phymode = MODE_11NG_HT20; |
| 1311 | } else { |
| 1312 | phymode = MODE_11G; |
| 1313 | } |
| 1314 | |
| 1315 | break; |
| 1316 | case IEEE80211_BAND_5GHZ: |
Sujith Manoharan | 7cc45e9 | 2013-09-08 18:19:55 +0300 | [diff] [blame] | 1317 | /* |
| 1318 | * Check VHT first. |
| 1319 | */ |
| 1320 | if (sta->vht_cap.vht_supported) { |
| 1321 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 1322 | phymode = MODE_11AC_VHT80; |
| 1323 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1324 | phymode = MODE_11AC_VHT40; |
| 1325 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 1326 | phymode = MODE_11AC_VHT20; |
| 1327 | } else if (sta->ht_cap.ht_supported) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1328 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 1329 | phymode = MODE_11NA_HT40; |
| 1330 | else |
| 1331 | phymode = MODE_11NA_HT20; |
| 1332 | } else { |
| 1333 | phymode = MODE_11A; |
| 1334 | } |
| 1335 | |
| 1336 | break; |
| 1337 | default: |
| 1338 | break; |
| 1339 | } |
| 1340 | |
Kalle Valo | 38a1d47 | 2013-09-08 17:56:14 +0300 | [diff] [blame] | 1341 | ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
| 1342 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1343 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1344 | arg->peer_phymode = phymode; |
| 1345 | WARN_ON(phymode == MODE_UNKNOWN); |
| 1346 | } |
| 1347 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1348 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
| 1349 | struct ath10k_vif *arvif, |
| 1350 | struct ieee80211_sta *sta, |
| 1351 | struct ieee80211_bss_conf *bss_conf, |
| 1352 | struct wmi_peer_assoc_complete_arg *arg) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1353 | { |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1354 | lockdep_assert_held(&ar->conf_mutex); |
| 1355 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1356 | memset(arg, 0, sizeof(*arg)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1357 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1358 | ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg); |
| 1359 | ath10k_peer_assoc_h_crypto(ar, arvif, arg); |
| 1360 | ath10k_peer_assoc_h_rates(ar, sta, arg); |
| 1361 | ath10k_peer_assoc_h_ht(ar, sta, arg); |
| 1362 | ath10k_peer_assoc_h_vht(ar, sta, arg); |
| 1363 | ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg); |
| 1364 | ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1365 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1366 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1367 | } |
| 1368 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 1369 | static const u32 ath10k_smps_map[] = { |
| 1370 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, |
| 1371 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, |
| 1372 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, |
| 1373 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, |
| 1374 | }; |
| 1375 | |
| 1376 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, |
| 1377 | const u8 *addr, |
| 1378 | const struct ieee80211_sta_ht_cap *ht_cap) |
| 1379 | { |
| 1380 | int smps; |
| 1381 | |
| 1382 | if (!ht_cap->ht_supported) |
| 1383 | return 0; |
| 1384 | |
| 1385 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; |
| 1386 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 1387 | |
| 1388 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) |
| 1389 | return -EINVAL; |
| 1390 | |
| 1391 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, |
| 1392 | WMI_PEER_SMPS_STATE, |
| 1393 | ath10k_smps_map[smps]); |
| 1394 | } |
| 1395 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1396 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
| 1397 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, |
| 1398 | struct ieee80211_vif *vif, |
| 1399 | struct ieee80211_bss_conf *bss_conf) |
| 1400 | { |
| 1401 | struct ath10k *ar = hw->priv; |
| 1402 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 1403 | struct ieee80211_sta_ht_cap ht_cap; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1404 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1405 | struct ieee80211_sta *ap_sta; |
| 1406 | int ret; |
| 1407 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1408 | lockdep_assert_held(&ar->conf_mutex); |
| 1409 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1410 | rcu_read_lock(); |
| 1411 | |
| 1412 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 1413 | if (!ap_sta) { |
| 1414 | ath10k_warn("Failed to find station entry for %pM\n", |
| 1415 | bss_conf->bssid); |
| 1416 | rcu_read_unlock(); |
| 1417 | return; |
| 1418 | } |
| 1419 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 1420 | /* ap_sta must be accessed only within rcu section which must be left |
| 1421 | * before calling ath10k_setup_peer_smps() which might sleep. */ |
| 1422 | ht_cap = ap_sta->ht_cap; |
| 1423 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1424 | ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta, |
| 1425 | bss_conf, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1426 | if (ret) { |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1427 | ath10k_warn("Peer assoc prepare failed for %pM\n: %d", |
| 1428 | bss_conf->bssid, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1429 | rcu_read_unlock(); |
| 1430 | return; |
| 1431 | } |
| 1432 | |
| 1433 | rcu_read_unlock(); |
| 1434 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1435 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 1436 | if (ret) { |
| 1437 | ath10k_warn("Peer assoc failed for %pM\n: %d", |
| 1438 | bss_conf->bssid, ret); |
| 1439 | return; |
| 1440 | } |
| 1441 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 1442 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
| 1443 | if (ret) { |
| 1444 | ath10k_warn("failed to setup peer SMPS: %d\n", ret); |
| 1445 | return; |
| 1446 | } |
| 1447 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1448 | ath10k_dbg(ATH10K_DBG_MAC, |
| 1449 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
| 1450 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); |
| 1451 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1452 | arvif->aid = bss_conf->aid; |
| 1453 | memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN); |
| 1454 | |
| 1455 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); |
| 1456 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1457 | ath10k_warn("VDEV: %d up failed: ret %d\n", |
| 1458 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | arvif->is_up = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | /* |
| 1466 | * FIXME: flush TIDs |
| 1467 | */ |
| 1468 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
| 1469 | struct ieee80211_vif *vif) |
| 1470 | { |
| 1471 | struct ath10k *ar = hw->priv; |
| 1472 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1473 | int ret; |
| 1474 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1475 | lockdep_assert_held(&ar->conf_mutex); |
| 1476 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1477 | /* |
| 1478 | * For some reason, calling VDEV-DOWN before VDEV-STOP |
| 1479 | * makes the FW to send frames via HTT after disassociation. |
| 1480 | * No idea why this happens, even though VDEV-DOWN is supposed |
| 1481 | * to be analogous to link down, so just stop the VDEV. |
| 1482 | */ |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1483 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n", |
| 1484 | arvif->vdev_id); |
| 1485 | |
| 1486 | /* FIXME: check return value */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1487 | ret = ath10k_vdev_stop(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1488 | |
| 1489 | /* |
| 1490 | * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and |
| 1491 | * report beacons from previously associated network through HTT. |
| 1492 | * This in turn would spam mac80211 WARN_ON if we bring down all |
| 1493 | * interfaces as it expects there is no rx when no interface is |
| 1494 | * running. |
| 1495 | */ |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1496 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id); |
| 1497 | |
| 1498 | /* FIXME: why don't we print error if wmi call fails? */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1499 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1500 | |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 1501 | arvif->def_wep_key_idx = 0; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1502 | |
| 1503 | arvif->is_started = false; |
| 1504 | arvif->is_up = false; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif, |
| 1508 | struct ieee80211_sta *sta) |
| 1509 | { |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1510 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1511 | int ret = 0; |
| 1512 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1513 | lockdep_assert_held(&ar->conf_mutex); |
| 1514 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1515 | ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1516 | if (ret) { |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1517 | ath10k_warn("WMI peer assoc prepare failed for %pM\n", |
| 1518 | sta->addr); |
| 1519 | return ret; |
| 1520 | } |
| 1521 | |
| 1522 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 1523 | if (ret) { |
| 1524 | ath10k_warn("Peer assoc failed for STA %pM\n: %d", |
| 1525 | sta->addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1526 | return ret; |
| 1527 | } |
| 1528 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 1529 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap); |
| 1530 | if (ret) { |
| 1531 | ath10k_warn("failed to setup peer SMPS: %d\n", ret); |
| 1532 | return ret; |
| 1533 | } |
| 1534 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1535 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); |
| 1536 | if (ret) { |
| 1537 | ath10k_warn("could not install peer wep keys (%d)\n", ret); |
| 1538 | return ret; |
| 1539 | } |
| 1540 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 1541 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
| 1542 | if (ret) { |
| 1543 | ath10k_warn("could not set qos params for STA %pM, %d\n", |
| 1544 | sta->addr, ret); |
| 1545 | return ret; |
| 1546 | } |
| 1547 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1548 | return ret; |
| 1549 | } |
| 1550 | |
| 1551 | static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif, |
| 1552 | struct ieee80211_sta *sta) |
| 1553 | { |
| 1554 | int ret = 0; |
| 1555 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1556 | lockdep_assert_held(&ar->conf_mutex); |
| 1557 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1558 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
| 1559 | if (ret) { |
| 1560 | ath10k_warn("could not clear all peer wep keys (%d)\n", ret); |
| 1561 | return ret; |
| 1562 | } |
| 1563 | |
| 1564 | return ret; |
| 1565 | } |
| 1566 | |
| 1567 | /**************/ |
| 1568 | /* Regulatory */ |
| 1569 | /**************/ |
| 1570 | |
| 1571 | static int ath10k_update_channel_list(struct ath10k *ar) |
| 1572 | { |
| 1573 | struct ieee80211_hw *hw = ar->hw; |
| 1574 | struct ieee80211_supported_band **bands; |
| 1575 | enum ieee80211_band band; |
| 1576 | struct ieee80211_channel *channel; |
| 1577 | struct wmi_scan_chan_list_arg arg = {0}; |
| 1578 | struct wmi_channel_arg *ch; |
| 1579 | bool passive; |
| 1580 | int len; |
| 1581 | int ret; |
| 1582 | int i; |
| 1583 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1584 | lockdep_assert_held(&ar->conf_mutex); |
| 1585 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1586 | bands = hw->wiphy->bands; |
| 1587 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1588 | if (!bands[band]) |
| 1589 | continue; |
| 1590 | |
| 1591 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 1592 | if (bands[band]->channels[i].flags & |
| 1593 | IEEE80211_CHAN_DISABLED) |
| 1594 | continue; |
| 1595 | |
| 1596 | arg.n_channels++; |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; |
| 1601 | arg.channels = kzalloc(len, GFP_KERNEL); |
| 1602 | if (!arg.channels) |
| 1603 | return -ENOMEM; |
| 1604 | |
| 1605 | ch = arg.channels; |
| 1606 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1607 | if (!bands[band]) |
| 1608 | continue; |
| 1609 | |
| 1610 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 1611 | channel = &bands[band]->channels[i]; |
| 1612 | |
| 1613 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 1614 | continue; |
| 1615 | |
| 1616 | ch->allow_ht = true; |
| 1617 | |
| 1618 | /* FIXME: when should we really allow VHT? */ |
| 1619 | ch->allow_vht = true; |
| 1620 | |
| 1621 | ch->allow_ibss = |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 1622 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1623 | |
| 1624 | ch->ht40plus = |
| 1625 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); |
| 1626 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1627 | ch->chan_radar = |
| 1628 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
| 1629 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 1630 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1631 | ch->passive = passive; |
| 1632 | |
| 1633 | ch->freq = channel->center_freq; |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 1634 | ch->min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 1635 | ch->max_power = channel->max_power * 2; |
| 1636 | ch->max_reg_power = channel->max_reg_power * 2; |
| 1637 | ch->max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1638 | ch->reg_class_id = 0; /* FIXME */ |
| 1639 | |
| 1640 | /* FIXME: why use only legacy modes, why not any |
| 1641 | * HT/VHT modes? Would that even make any |
| 1642 | * difference? */ |
| 1643 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 1644 | ch->mode = MODE_11G; |
| 1645 | else |
| 1646 | ch->mode = MODE_11A; |
| 1647 | |
| 1648 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) |
| 1649 | continue; |
| 1650 | |
| 1651 | ath10k_dbg(ATH10K_DBG_WMI, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1652 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
| 1653 | ch - arg.channels, arg.n_channels, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1654 | ch->freq, ch->max_power, ch->max_reg_power, |
| 1655 | ch->max_antenna_gain, ch->mode); |
| 1656 | |
| 1657 | ch++; |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | ret = ath10k_wmi_scan_chan_list(ar, &arg); |
| 1662 | kfree(arg.channels); |
| 1663 | |
| 1664 | return ret; |
| 1665 | } |
| 1666 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1667 | static void ath10k_regd_update(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1668 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1669 | struct reg_dmn_pair_mapping *regpair; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1670 | int ret; |
| 1671 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1672 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1673 | |
| 1674 | ret = ath10k_update_channel_list(ar); |
| 1675 | if (ret) |
| 1676 | ath10k_warn("could not update channel list (%d)\n", ret); |
| 1677 | |
| 1678 | regpair = ar->ath_common.regulatory.regpair; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1679 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1680 | /* Target allows setting up per-band regdomain but ath_common provides |
| 1681 | * a combined one only */ |
| 1682 | ret = ath10k_wmi_pdev_set_regdomain(ar, |
Kalle Valo | ef8c001 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 1683 | regpair->reg_domain, |
| 1684 | regpair->reg_domain, /* 2ghz */ |
| 1685 | regpair->reg_domain, /* 5ghz */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1686 | regpair->reg_2ghz_ctl, |
| 1687 | regpair->reg_5ghz_ctl); |
| 1688 | if (ret) |
| 1689 | ath10k_warn("could not set pdev regdomain (%d)\n", ret); |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1690 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1691 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1692 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
| 1693 | struct regulatory_request *request) |
| 1694 | { |
| 1695 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 1696 | struct ath10k *ar = hw->priv; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1697 | bool result; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1698 | |
| 1699 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); |
| 1700 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 1701 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
| 1702 | ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
| 1703 | request->dfs_region); |
| 1704 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, |
| 1705 | request->dfs_region); |
| 1706 | if (!result) |
| 1707 | ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n", |
| 1708 | request->dfs_region); |
| 1709 | } |
| 1710 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 1711 | mutex_lock(&ar->conf_mutex); |
| 1712 | if (ar->state == ATH10K_STATE_ON) |
| 1713 | ath10k_regd_update(ar); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1714 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /***************/ |
| 1718 | /* TX handlers */ |
| 1719 | /***************/ |
| 1720 | |
Michal Kazior | 42c3aa6 | 2013-10-02 11:03:38 +0200 | [diff] [blame] | 1721 | static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr) |
| 1722 | { |
| 1723 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 1724 | return HTT_DATA_TX_EXT_TID_MGMT; |
| 1725 | |
| 1726 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 1727 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 1728 | |
| 1729 | if (!is_unicast_ether_addr(ieee80211_get_DA(hdr))) |
| 1730 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 1731 | |
| 1732 | return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 1733 | } |
| 1734 | |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 1735 | static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, |
| 1736 | struct ieee80211_tx_info *info) |
| 1737 | { |
| 1738 | if (info->control.vif) |
| 1739 | return ath10k_vif_to_arvif(info->control.vif)->vdev_id; |
| 1740 | |
| 1741 | if (ar->monitor_enabled) |
| 1742 | return ar->monitor_vdev_id; |
| 1743 | |
| 1744 | ath10k_warn("could not resolve vdev id\n"); |
| 1745 | return 0; |
| 1746 | } |
| 1747 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1748 | /* |
| 1749 | * Frames sent to the FW have to be in "Native Wifi" format. |
| 1750 | * Strip the QoS field from the 802.11 header. |
| 1751 | */ |
| 1752 | static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw, |
| 1753 | struct ieee80211_tx_control *control, |
| 1754 | struct sk_buff *skb) |
| 1755 | { |
| 1756 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 1757 | u8 *qos_ctl; |
| 1758 | |
| 1759 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 1760 | return; |
| 1761 | |
| 1762 | qos_ctl = ieee80211_get_qos_ctl(hdr); |
Michal Kazior | ba0ccd7 | 2013-07-22 14:25:28 +0200 | [diff] [blame] | 1763 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
| 1764 | skb->data, (void *)qos_ctl - (void *)skb->data); |
| 1765 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1766 | } |
| 1767 | |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 1768 | static void ath10k_tx_wep_key_work(struct work_struct *work) |
| 1769 | { |
| 1770 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 1771 | wep_key_work); |
| 1772 | int ret, keyidx = arvif->def_wep_key_newidx; |
| 1773 | |
| 1774 | if (arvif->def_wep_key_idx == keyidx) |
| 1775 | return; |
| 1776 | |
| 1777 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", |
| 1778 | arvif->vdev_id, keyidx); |
| 1779 | |
| 1780 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 1781 | arvif->vdev_id, |
| 1782 | arvif->ar->wmi.vdev_param->def_keyid, |
| 1783 | keyidx); |
| 1784 | if (ret) { |
| 1785 | ath10k_warn("could not update wep keyidx (%d)\n", ret); |
| 1786 | return; |
| 1787 | } |
| 1788 | |
| 1789 | arvif->def_wep_key_idx = keyidx; |
| 1790 | } |
| 1791 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1792 | static void ath10k_tx_h_update_wep_key(struct sk_buff *skb) |
| 1793 | { |
| 1794 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1795 | struct ieee80211_vif *vif = info->control.vif; |
| 1796 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1797 | struct ath10k *ar = arvif->ar; |
| 1798 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1799 | struct ieee80211_key_conf *key = info->control.hw_key; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1800 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1801 | if (!ieee80211_has_protected(hdr->frame_control)) |
| 1802 | return; |
| 1803 | |
| 1804 | if (!key) |
| 1805 | return; |
| 1806 | |
| 1807 | if (key->cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1808 | key->cipher != WLAN_CIPHER_SUITE_WEP104) |
| 1809 | return; |
| 1810 | |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 1811 | if (key->keyidx == arvif->def_wep_key_idx) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1812 | return; |
| 1813 | |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 1814 | /* FIXME: Most likely a few frames will be TXed with an old key. Simply |
| 1815 | * queueing frames until key index is updated is not an option because |
| 1816 | * sk_buff may need more processing to be done, e.g. offchannel */ |
| 1817 | arvif->def_wep_key_newidx = key->keyidx; |
| 1818 | ieee80211_queue_work(ar->hw, &arvif->wep_key_work); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb) |
| 1822 | { |
| 1823 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1824 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1825 | struct ieee80211_vif *vif = info->control.vif; |
| 1826 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1827 | |
| 1828 | /* This is case only for P2P_GO */ |
| 1829 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP || |
| 1830 | arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) |
| 1831 | return; |
| 1832 | |
| 1833 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { |
| 1834 | spin_lock_bh(&ar->data_lock); |
| 1835 | if (arvif->u.ap.noa_data) |
| 1836 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, |
| 1837 | GFP_ATOMIC)) |
| 1838 | memcpy(skb_put(skb, arvif->u.ap.noa_len), |
| 1839 | arvif->u.ap.noa_data, |
| 1840 | arvif->u.ap.noa_len); |
| 1841 | spin_unlock_bh(&ar->data_lock); |
| 1842 | } |
| 1843 | } |
| 1844 | |
| 1845 | static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb) |
| 1846 | { |
| 1847 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1848 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1849 | |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 1850 | if (ar->htt.target_version_major >= 3) { |
| 1851 | /* Since HTT 3.0 there is no separate mgmt tx command */ |
| 1852 | ret = ath10k_htt_tx(&ar->htt, skb); |
| 1853 | goto exit; |
| 1854 | } |
| 1855 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1856 | if (ieee80211_is_mgmt(hdr->frame_control)) { |
| 1857 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
| 1858 | ar->fw_features)) { |
| 1859 | if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >= |
| 1860 | ATH10K_MAX_NUM_MGMT_PENDING) { |
| 1861 | ath10k_warn("wmi mgmt_tx queue limit reached\n"); |
| 1862 | ret = -EBUSY; |
| 1863 | goto exit; |
| 1864 | } |
| 1865 | |
| 1866 | skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb); |
| 1867 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); |
| 1868 | } else { |
| 1869 | ret = ath10k_htt_mgmt_tx(&ar->htt, skb); |
| 1870 | } |
| 1871 | } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
| 1872 | ar->fw_features) && |
| 1873 | ieee80211_is_nullfunc(hdr->frame_control)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1874 | /* FW does not report tx status properly for NullFunc frames |
| 1875 | * unless they are sent through mgmt tx path. mac80211 sends |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1876 | * those frames when it detects link/beacon loss and depends |
| 1877 | * on the tx status to be correct. */ |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 1878 | ret = ath10k_htt_mgmt_tx(&ar->htt, skb); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1879 | } else { |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 1880 | ret = ath10k_htt_tx(&ar->htt, skb); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1881 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1882 | |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 1883 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1884 | if (ret) { |
| 1885 | ath10k_warn("tx failed (%d). dropping packet.\n", ret); |
| 1886 | ieee80211_free_txskb(ar->hw, skb); |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | void ath10k_offchan_tx_purge(struct ath10k *ar) |
| 1891 | { |
| 1892 | struct sk_buff *skb; |
| 1893 | |
| 1894 | for (;;) { |
| 1895 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 1896 | if (!skb) |
| 1897 | break; |
| 1898 | |
| 1899 | ieee80211_free_txskb(ar->hw, skb); |
| 1900 | } |
| 1901 | } |
| 1902 | |
| 1903 | void ath10k_offchan_tx_work(struct work_struct *work) |
| 1904 | { |
| 1905 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); |
| 1906 | struct ath10k_peer *peer; |
| 1907 | struct ieee80211_hdr *hdr; |
| 1908 | struct sk_buff *skb; |
| 1909 | const u8 *peer_addr; |
| 1910 | int vdev_id; |
| 1911 | int ret; |
| 1912 | |
| 1913 | /* FW requirement: We must create a peer before FW will send out |
| 1914 | * an offchannel frame. Otherwise the frame will be stuck and |
| 1915 | * never transmitted. We delete the peer upon tx completion. |
| 1916 | * It is unlikely that a peer for offchannel tx will already be |
| 1917 | * present. However it may be in some rare cases so account for that. |
| 1918 | * Otherwise we might remove a legitimate peer and break stuff. */ |
| 1919 | |
| 1920 | for (;;) { |
| 1921 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 1922 | if (!skb) |
| 1923 | break; |
| 1924 | |
| 1925 | mutex_lock(&ar->conf_mutex); |
| 1926 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1927 | ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1928 | skb); |
| 1929 | |
| 1930 | hdr = (struct ieee80211_hdr *)skb->data; |
| 1931 | peer_addr = ieee80211_get_DA(hdr); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1932 | vdev_id = ATH10K_SKB_CB(skb)->vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1933 | |
| 1934 | spin_lock_bh(&ar->data_lock); |
| 1935 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); |
| 1936 | spin_unlock_bh(&ar->data_lock); |
| 1937 | |
| 1938 | if (peer) |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1939 | /* FIXME: should this use ath10k_warn()? */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1940 | ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n", |
| 1941 | peer_addr, vdev_id); |
| 1942 | |
| 1943 | if (!peer) { |
| 1944 | ret = ath10k_peer_create(ar, vdev_id, peer_addr); |
| 1945 | if (ret) |
| 1946 | ath10k_warn("peer %pM on vdev %d not created (%d)\n", |
| 1947 | peer_addr, vdev_id, ret); |
| 1948 | } |
| 1949 | |
| 1950 | spin_lock_bh(&ar->data_lock); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 1951 | reinit_completion(&ar->offchan_tx_completed); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1952 | ar->offchan_tx_skb = skb; |
| 1953 | spin_unlock_bh(&ar->data_lock); |
| 1954 | |
| 1955 | ath10k_tx_htt(ar, skb); |
| 1956 | |
| 1957 | ret = wait_for_completion_timeout(&ar->offchan_tx_completed, |
| 1958 | 3 * HZ); |
| 1959 | if (ret <= 0) |
| 1960 | ath10k_warn("timed out waiting for offchannel skb %p\n", |
| 1961 | skb); |
| 1962 | |
| 1963 | if (!peer) { |
| 1964 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); |
| 1965 | if (ret) |
| 1966 | ath10k_warn("peer %pM on vdev %d not deleted (%d)\n", |
| 1967 | peer_addr, vdev_id, ret); |
| 1968 | } |
| 1969 | |
| 1970 | mutex_unlock(&ar->conf_mutex); |
| 1971 | } |
| 1972 | } |
| 1973 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 1974 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
| 1975 | { |
| 1976 | struct sk_buff *skb; |
| 1977 | |
| 1978 | for (;;) { |
| 1979 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 1980 | if (!skb) |
| 1981 | break; |
| 1982 | |
| 1983 | ieee80211_free_txskb(ar->hw, skb); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) |
| 1988 | { |
| 1989 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); |
| 1990 | struct sk_buff *skb; |
| 1991 | int ret; |
| 1992 | |
| 1993 | for (;;) { |
| 1994 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 1995 | if (!skb) |
| 1996 | break; |
| 1997 | |
| 1998 | ret = ath10k_wmi_mgmt_tx(ar, skb); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 1999 | if (ret) { |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2000 | ath10k_warn("wmi mgmt_tx failed (%d)\n", ret); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 2001 | ieee80211_free_txskb(ar->hw, skb); |
| 2002 | } |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2006 | /************/ |
| 2007 | /* Scanning */ |
| 2008 | /************/ |
| 2009 | |
| 2010 | /* |
| 2011 | * This gets called if we dont get a heart-beat during scan. |
| 2012 | * This may indicate the FW has hung and we need to abort the |
| 2013 | * scan manually to prevent cancel_hw_scan() from deadlocking |
| 2014 | */ |
| 2015 | void ath10k_reset_scan(unsigned long ptr) |
| 2016 | { |
| 2017 | struct ath10k *ar = (struct ath10k *)ptr; |
| 2018 | |
| 2019 | spin_lock_bh(&ar->data_lock); |
| 2020 | if (!ar->scan.in_progress) { |
| 2021 | spin_unlock_bh(&ar->data_lock); |
| 2022 | return; |
| 2023 | } |
| 2024 | |
| 2025 | ath10k_warn("scan timeout. resetting. fw issue?\n"); |
| 2026 | |
| 2027 | if (ar->scan.is_roc) |
| 2028 | ieee80211_remain_on_channel_expired(ar->hw); |
| 2029 | else |
| 2030 | ieee80211_scan_completed(ar->hw, 1 /* aborted */); |
| 2031 | |
| 2032 | ar->scan.in_progress = false; |
| 2033 | complete_all(&ar->scan.completed); |
| 2034 | spin_unlock_bh(&ar->data_lock); |
| 2035 | } |
| 2036 | |
| 2037 | static int ath10k_abort_scan(struct ath10k *ar) |
| 2038 | { |
| 2039 | struct wmi_stop_scan_arg arg = { |
| 2040 | .req_id = 1, /* FIXME */ |
| 2041 | .req_type = WMI_SCAN_STOP_ONE, |
| 2042 | .u.scan_id = ATH10K_SCAN_ID, |
| 2043 | }; |
| 2044 | int ret; |
| 2045 | |
| 2046 | lockdep_assert_held(&ar->conf_mutex); |
| 2047 | |
| 2048 | del_timer_sync(&ar->scan.timeout); |
| 2049 | |
| 2050 | spin_lock_bh(&ar->data_lock); |
| 2051 | if (!ar->scan.in_progress) { |
| 2052 | spin_unlock_bh(&ar->data_lock); |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
| 2056 | ar->scan.aborting = true; |
| 2057 | spin_unlock_bh(&ar->data_lock); |
| 2058 | |
| 2059 | ret = ath10k_wmi_stop_scan(ar, &arg); |
| 2060 | if (ret) { |
| 2061 | ath10k_warn("could not submit wmi stop scan (%d)\n", ret); |
Michal Kazior | adb8c9b | 2013-07-05 16:15:16 +0300 | [diff] [blame] | 2062 | spin_lock_bh(&ar->data_lock); |
| 2063 | ar->scan.in_progress = false; |
| 2064 | ath10k_offchan_tx_purge(ar); |
| 2065 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2066 | return -EIO; |
| 2067 | } |
| 2068 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2069 | ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); |
| 2070 | if (ret == 0) |
| 2071 | ath10k_warn("timed out while waiting for scan to stop\n"); |
| 2072 | |
| 2073 | /* scan completion may be done right after we timeout here, so let's |
| 2074 | * check the in_progress and tell mac80211 scan is completed. if we |
| 2075 | * don't do that and FW fails to send us scan completion indication |
| 2076 | * then userspace won't be able to scan anymore */ |
| 2077 | ret = 0; |
| 2078 | |
| 2079 | spin_lock_bh(&ar->data_lock); |
| 2080 | if (ar->scan.in_progress) { |
| 2081 | ath10k_warn("could not stop scan. its still in progress\n"); |
| 2082 | ar->scan.in_progress = false; |
| 2083 | ath10k_offchan_tx_purge(ar); |
| 2084 | ret = -ETIMEDOUT; |
| 2085 | } |
| 2086 | spin_unlock_bh(&ar->data_lock); |
| 2087 | |
| 2088 | return ret; |
| 2089 | } |
| 2090 | |
| 2091 | static int ath10k_start_scan(struct ath10k *ar, |
| 2092 | const struct wmi_start_scan_arg *arg) |
| 2093 | { |
| 2094 | int ret; |
| 2095 | |
| 2096 | lockdep_assert_held(&ar->conf_mutex); |
| 2097 | |
| 2098 | ret = ath10k_wmi_start_scan(ar, arg); |
| 2099 | if (ret) |
| 2100 | return ret; |
| 2101 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2102 | ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); |
| 2103 | if (ret == 0) { |
| 2104 | ath10k_abort_scan(ar); |
| 2105 | return ret; |
| 2106 | } |
| 2107 | |
| 2108 | /* the scan can complete earlier, before we even |
| 2109 | * start the timer. in that case the timer handler |
| 2110 | * checks ar->scan.in_progress and bails out if its |
| 2111 | * false. Add a 200ms margin to account event/command |
| 2112 | * processing. */ |
| 2113 | mod_timer(&ar->scan.timeout, jiffies + |
| 2114 | msecs_to_jiffies(arg->max_scan_time+200)); |
| 2115 | return 0; |
| 2116 | } |
| 2117 | |
| 2118 | /**********************/ |
| 2119 | /* mac80211 callbacks */ |
| 2120 | /**********************/ |
| 2121 | |
| 2122 | static void ath10k_tx(struct ieee80211_hw *hw, |
| 2123 | struct ieee80211_tx_control *control, |
| 2124 | struct sk_buff *skb) |
| 2125 | { |
| 2126 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2127 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 2128 | struct ath10k *ar = hw->priv; |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2129 | u8 tid, vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2130 | |
| 2131 | /* We should disable CCK RATE due to P2P */ |
| 2132 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) |
| 2133 | ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n"); |
| 2134 | |
| 2135 | /* we must calculate tid before we apply qos workaround |
| 2136 | * as we'd lose the qos control field */ |
Michal Kazior | 42c3aa6 | 2013-10-02 11:03:38 +0200 | [diff] [blame] | 2137 | tid = ath10k_tx_h_get_tid(hdr); |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 2138 | vdev_id = ath10k_tx_h_get_vdev_id(ar, info); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2139 | |
Michal Kazior | cf84bd4 | 2013-07-16 11:04:54 +0200 | [diff] [blame] | 2140 | /* it makes no sense to process injected frames like that */ |
| 2141 | if (info->control.vif && |
| 2142 | info->control.vif->type != NL80211_IFTYPE_MONITOR) { |
| 2143 | ath10k_tx_h_qos_workaround(hw, control, skb); |
| 2144 | ath10k_tx_h_update_wep_key(skb); |
| 2145 | ath10k_tx_h_add_p2p_noa_ie(ar, skb); |
| 2146 | ath10k_tx_h_seq_no(skb); |
| 2147 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2148 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2149 | ATH10K_SKB_CB(skb)->vdev_id = vdev_id; |
Michal Kazior | 27bb178 | 2013-09-18 14:43:19 +0200 | [diff] [blame] | 2150 | ATH10K_SKB_CB(skb)->htt.is_offchan = false; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2151 | ATH10K_SKB_CB(skb)->htt.tid = tid; |
| 2152 | |
| 2153 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { |
| 2154 | spin_lock_bh(&ar->data_lock); |
| 2155 | ATH10K_SKB_CB(skb)->htt.is_offchan = true; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2156 | ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2157 | spin_unlock_bh(&ar->data_lock); |
| 2158 | |
| 2159 | ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb); |
| 2160 | |
| 2161 | skb_queue_tail(&ar->offchan_tx_queue, skb); |
| 2162 | ieee80211_queue_work(hw, &ar->offchan_tx_work); |
| 2163 | return; |
| 2164 | } |
| 2165 | |
| 2166 | ath10k_tx_htt(ar, skb); |
| 2167 | } |
| 2168 | |
| 2169 | /* |
| 2170 | * Initialize various parameters with default vaules. |
| 2171 | */ |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2172 | void ath10k_halt(struct ath10k *ar) |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2173 | { |
| 2174 | lockdep_assert_held(&ar->conf_mutex); |
| 2175 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 2176 | ath10k_stop_cac(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2177 | del_timer_sync(&ar->scan.timeout); |
| 2178 | ath10k_offchan_tx_purge(ar); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2179 | ath10k_mgmt_over_wmi_tx_purge(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2180 | ath10k_peer_cleanup_all(ar); |
| 2181 | ath10k_core_stop(ar); |
| 2182 | ath10k_hif_power_down(ar); |
| 2183 | |
| 2184 | spin_lock_bh(&ar->data_lock); |
| 2185 | if (ar->scan.in_progress) { |
| 2186 | del_timer(&ar->scan.timeout); |
| 2187 | ar->scan.in_progress = false; |
| 2188 | ieee80211_scan_completed(ar->hw, true); |
| 2189 | } |
| 2190 | spin_unlock_bh(&ar->data_lock); |
| 2191 | } |
| 2192 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2193 | static int ath10k_start(struct ieee80211_hw *hw) |
| 2194 | { |
| 2195 | struct ath10k *ar = hw->priv; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2196 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2197 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2198 | mutex_lock(&ar->conf_mutex); |
| 2199 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2200 | if (ar->state != ATH10K_STATE_OFF && |
| 2201 | ar->state != ATH10K_STATE_RESTARTING) { |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2202 | ret = -EINVAL; |
| 2203 | goto exit; |
| 2204 | } |
| 2205 | |
| 2206 | ret = ath10k_hif_power_up(ar); |
| 2207 | if (ret) { |
| 2208 | ath10k_err("could not init hif (%d)\n", ret); |
| 2209 | ar->state = ATH10K_STATE_OFF; |
| 2210 | goto exit; |
| 2211 | } |
| 2212 | |
| 2213 | ret = ath10k_core_start(ar); |
| 2214 | if (ret) { |
| 2215 | ath10k_err("could not init core (%d)\n", ret); |
| 2216 | ath10k_hif_power_down(ar); |
| 2217 | ar->state = ATH10K_STATE_OFF; |
| 2218 | goto exit; |
| 2219 | } |
| 2220 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2221 | if (ar->state == ATH10K_STATE_OFF) |
| 2222 | ar->state = ATH10K_STATE_ON; |
| 2223 | else if (ar->state == ATH10K_STATE_RESTARTING) |
| 2224 | ar->state = ATH10K_STATE_RESTARTED; |
| 2225 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 2226 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2227 | if (ret) |
| 2228 | ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n", |
| 2229 | ret); |
| 2230 | |
Michal Kazior | c4dd0d0 | 2013-11-13 11:05:10 +0100 | [diff] [blame] | 2231 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2232 | if (ret) |
| 2233 | ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n", |
| 2234 | ret); |
| 2235 | |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 2236 | /* |
| 2237 | * By default FW set ARP frames ac to voice (6). In that case ARP |
| 2238 | * exchange is not working properly for UAPSD enabled AP. ARP requests |
| 2239 | * which arrives with access category 0 are processed by network stack |
| 2240 | * and send back with access category 0, but FW changes access category |
| 2241 | * to 6. Set ARP frames access category to best effort (0) solves |
| 2242 | * this problem. |
| 2243 | */ |
| 2244 | |
| 2245 | ret = ath10k_wmi_pdev_set_param(ar, |
| 2246 | ar->wmi.pdev_param->arp_ac_override, 0); |
| 2247 | if (ret) { |
| 2248 | ath10k_warn("could not set arp ac override parameter: %d\n", |
| 2249 | ret); |
| 2250 | goto exit; |
| 2251 | } |
| 2252 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2253 | ath10k_regd_update(ar); |
Michal Kazior | c60bdd8 | 2014-01-29 07:26:31 +0100 | [diff] [blame] | 2254 | ret = 0; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2255 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2256 | exit: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2257 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | c60bdd8 | 2014-01-29 07:26:31 +0100 | [diff] [blame] | 2258 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | static void ath10k_stop(struct ieee80211_hw *hw) |
| 2262 | { |
| 2263 | struct ath10k *ar = hw->priv; |
| 2264 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2265 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2266 | if (ar->state == ATH10K_STATE_ON || |
| 2267 | ar->state == ATH10K_STATE_RESTARTED || |
| 2268 | ar->state == ATH10K_STATE_WEDGED) |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 2269 | ath10k_halt(ar); |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 2270 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2271 | ar->state = ATH10K_STATE_OFF; |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2272 | mutex_unlock(&ar->conf_mutex); |
| 2273 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2274 | ath10k_mgmt_over_wmi_tx_purge(ar); |
| 2275 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2276 | cancel_work_sync(&ar->offchan_tx_work); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 2277 | cancel_work_sync(&ar->wmi_mgmt_tx_work); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2278 | cancel_work_sync(&ar->restart_work); |
| 2279 | } |
| 2280 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2281 | static int ath10k_config_ps(struct ath10k *ar) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2282 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2283 | struct ath10k_vif *arvif; |
| 2284 | int ret = 0; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2285 | |
| 2286 | lockdep_assert_held(&ar->conf_mutex); |
| 2287 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2288 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 2289 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 2290 | if (ret) { |
| 2291 | ath10k_warn("could not setup powersave (%d)\n", ret); |
| 2292 | break; |
| 2293 | } |
| 2294 | } |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2295 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2296 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2297 | } |
| 2298 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2299 | static const char *chandef_get_width(enum nl80211_chan_width width) |
| 2300 | { |
| 2301 | switch (width) { |
| 2302 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2303 | return "20 (noht)"; |
| 2304 | case NL80211_CHAN_WIDTH_20: |
| 2305 | return "20"; |
| 2306 | case NL80211_CHAN_WIDTH_40: |
| 2307 | return "40"; |
| 2308 | case NL80211_CHAN_WIDTH_80: |
| 2309 | return "80"; |
| 2310 | case NL80211_CHAN_WIDTH_80P80: |
| 2311 | return "80+80"; |
| 2312 | case NL80211_CHAN_WIDTH_160: |
| 2313 | return "160"; |
| 2314 | case NL80211_CHAN_WIDTH_5: |
| 2315 | return "5"; |
| 2316 | case NL80211_CHAN_WIDTH_10: |
| 2317 | return "10"; |
| 2318 | } |
| 2319 | return "?"; |
| 2320 | } |
| 2321 | |
| 2322 | static void ath10k_config_chan(struct ath10k *ar) |
| 2323 | { |
| 2324 | struct ath10k_vif *arvif; |
| 2325 | bool monitor_was_enabled; |
| 2326 | int ret; |
| 2327 | |
| 2328 | lockdep_assert_held(&ar->conf_mutex); |
| 2329 | |
| 2330 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2331 | "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n", |
| 2332 | ar->chandef.chan->center_freq, |
| 2333 | ar->chandef.center_freq1, |
| 2334 | ar->chandef.center_freq2, |
| 2335 | chandef_get_width(ar->chandef.width)); |
| 2336 | |
| 2337 | /* First stop monitor interface. Some FW versions crash if there's a |
| 2338 | * lone monitor interface. */ |
| 2339 | monitor_was_enabled = ar->monitor_enabled; |
| 2340 | |
| 2341 | if (ar->monitor_enabled) |
| 2342 | ath10k_monitor_stop(ar); |
| 2343 | |
| 2344 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 2345 | if (!arvif->is_started) |
| 2346 | continue; |
| 2347 | |
| 2348 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 2349 | continue; |
| 2350 | |
| 2351 | ret = ath10k_vdev_stop(arvif); |
| 2352 | if (ret) { |
| 2353 | ath10k_warn("could not stop vdev %d (%d)\n", |
| 2354 | arvif->vdev_id, ret); |
| 2355 | continue; |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | /* all vdevs are now stopped - now attempt to restart them */ |
| 2360 | |
| 2361 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 2362 | if (!arvif->is_started) |
| 2363 | continue; |
| 2364 | |
| 2365 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 2366 | continue; |
| 2367 | |
| 2368 | ret = ath10k_vdev_start(arvif); |
| 2369 | if (ret) { |
| 2370 | ath10k_warn("could not start vdev %d (%d)\n", |
| 2371 | arvif->vdev_id, ret); |
| 2372 | continue; |
| 2373 | } |
| 2374 | |
| 2375 | if (!arvif->is_up) |
| 2376 | continue; |
| 2377 | |
| 2378 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 2379 | arvif->bssid); |
| 2380 | if (ret) { |
| 2381 | ath10k_warn("could not bring vdev up %d (%d)\n", |
| 2382 | arvif->vdev_id, ret); |
| 2383 | continue; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | if (monitor_was_enabled) |
| 2388 | ath10k_monitor_start(ar, ar->monitor_vdev_id); |
| 2389 | } |
| 2390 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2391 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
| 2392 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2393 | struct ath10k *ar = hw->priv; |
| 2394 | struct ieee80211_conf *conf = &hw->conf; |
| 2395 | int ret = 0; |
Michal Kazior | 5474efe | 2013-10-23 04:02:15 -0700 | [diff] [blame] | 2396 | u32 param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2397 | |
| 2398 | mutex_lock(&ar->conf_mutex); |
| 2399 | |
| 2400 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 2401 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2402 | "mac config channel %d mhz flags 0x%x\n", |
| 2403 | conf->chandef.chan->center_freq, |
| 2404 | conf->chandef.chan->flags); |
| 2405 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2406 | spin_lock_bh(&ar->data_lock); |
| 2407 | ar->rx_channel = conf->chandef.chan; |
| 2408 | spin_unlock_bh(&ar->data_lock); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 2409 | |
| 2410 | ath10k_config_radar_detection(ar); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2411 | |
| 2412 | if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) { |
| 2413 | ar->chandef = conf->chandef; |
| 2414 | ath10k_config_chan(ar); |
| 2415 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2416 | } |
| 2417 | |
Michal Kazior | 5474efe | 2013-10-23 04:02:15 -0700 | [diff] [blame] | 2418 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
| 2419 | ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n", |
| 2420 | hw->conf.power_level); |
| 2421 | |
| 2422 | param = ar->wmi.pdev_param->txpower_limit2g; |
| 2423 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 2424 | hw->conf.power_level * 2); |
| 2425 | if (ret) |
| 2426 | ath10k_warn("mac failed to set 2g txpower %d (%d)\n", |
| 2427 | hw->conf.power_level, ret); |
| 2428 | |
| 2429 | param = ar->wmi.pdev_param->txpower_limit5g; |
| 2430 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 2431 | hw->conf.power_level * 2); |
| 2432 | if (ret) |
| 2433 | ath10k_warn("mac failed to set 5g txpower %d (%d)\n", |
| 2434 | hw->conf.power_level, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2435 | } |
| 2436 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 2437 | if (changed & IEEE80211_CONF_CHANGE_PS) |
| 2438 | ath10k_config_ps(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2439 | |
| 2440 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
| 2441 | if (conf->flags & IEEE80211_CONF_MONITOR) |
| 2442 | ret = ath10k_monitor_create(ar); |
| 2443 | else |
| 2444 | ret = ath10k_monitor_destroy(ar); |
| 2445 | } |
| 2446 | |
| 2447 | mutex_unlock(&ar->conf_mutex); |
| 2448 | return ret; |
| 2449 | } |
| 2450 | |
| 2451 | /* |
| 2452 | * TODO: |
| 2453 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, |
| 2454 | * because we will send mgmt frames without CCK. This requirement |
| 2455 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag |
| 2456 | * in the TX packet. |
| 2457 | */ |
| 2458 | static int ath10k_add_interface(struct ieee80211_hw *hw, |
| 2459 | struct ieee80211_vif *vif) |
| 2460 | { |
| 2461 | struct ath10k *ar = hw->priv; |
| 2462 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2463 | enum wmi_sta_powersave_param param; |
| 2464 | int ret = 0; |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 2465 | u32 value; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2466 | int bit; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2467 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2468 | |
| 2469 | mutex_lock(&ar->conf_mutex); |
| 2470 | |
Michal Kazior | 0dbd09e | 2013-07-31 10:55:14 +0200 | [diff] [blame] | 2471 | memset(arvif, 0, sizeof(*arvif)); |
| 2472 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2473 | arvif->ar = ar; |
| 2474 | arvif->vif = vif; |
| 2475 | |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2476 | INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work); |
Ben Greear | e63b33f | 2013-10-22 14:54:14 -0700 | [diff] [blame] | 2477 | INIT_LIST_HEAD(&arvif->list); |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2478 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2479 | if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) { |
| 2480 | ath10k_warn("Only one monitor interface allowed\n"); |
| 2481 | ret = -EBUSY; |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2482 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | bit = ffs(ar->free_vdev_map); |
| 2486 | if (bit == 0) { |
| 2487 | ret = -EBUSY; |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2488 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | arvif->vdev_id = bit - 1; |
| 2492 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2493 | |
| 2494 | if (ar->p2p) |
| 2495 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; |
| 2496 | |
| 2497 | switch (vif->type) { |
| 2498 | case NL80211_IFTYPE_UNSPECIFIED: |
| 2499 | case NL80211_IFTYPE_STATION: |
| 2500 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 2501 | if (vif->p2p) |
| 2502 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; |
| 2503 | break; |
| 2504 | case NL80211_IFTYPE_ADHOC: |
| 2505 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; |
| 2506 | break; |
| 2507 | case NL80211_IFTYPE_AP: |
| 2508 | arvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 2509 | |
| 2510 | if (vif->p2p) |
| 2511 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; |
| 2512 | break; |
| 2513 | case NL80211_IFTYPE_MONITOR: |
| 2514 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; |
| 2515 | break; |
| 2516 | default: |
| 2517 | WARN_ON(1); |
| 2518 | break; |
| 2519 | } |
| 2520 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2521 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2522 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype); |
| 2523 | |
| 2524 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, |
| 2525 | arvif->vdev_subtype, vif->addr); |
| 2526 | if (ret) { |
| 2527 | ath10k_warn("WMI vdev create failed: ret %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2528 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2529 | } |
| 2530 | |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2531 | ar->free_vdev_map &= ~BIT(arvif->vdev_id); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2532 | list_add(&arvif->list, &ar->arvifs); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2533 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2534 | vdev_param = ar->wmi.vdev_param->def_keyid; |
| 2535 | ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param, |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2536 | arvif->def_wep_key_idx); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2537 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2538 | ath10k_warn("Failed to set default keyid: %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2539 | goto err_vdev_delete; |
| 2540 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2541 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2542 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
| 2543 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2544 | ATH10K_HW_TXRX_NATIVE_WIFI); |
Bartosz Markowski | ebc9abd | 2013-10-15 09:26:20 +0200 | [diff] [blame] | 2545 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2546 | if (ret && ret != -EOPNOTSUPP) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2547 | ath10k_warn("Failed to set TX encap: %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2548 | goto err_vdev_delete; |
| 2549 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2550 | |
| 2551 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 2552 | ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr); |
| 2553 | if (ret) { |
| 2554 | ath10k_warn("Failed to create peer for AP: %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2555 | goto err_vdev_delete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2556 | } |
Marek Puzyniak | cdf0740 | 2013-12-30 09:07:51 +0100 | [diff] [blame] | 2557 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 2558 | ret = ath10k_mac_set_kickout(arvif); |
| 2559 | if (ret) { |
| 2560 | ath10k_warn("Failed to set kickout parameters: %d\n", |
| 2561 | ret); |
| 2562 | goto err_peer_delete; |
| 2563 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 2567 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; |
| 2568 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 2569 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 2570 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2571 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2572 | ath10k_warn("Failed to set RX wake policy: %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2573 | goto err_peer_delete; |
| 2574 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2575 | |
| 2576 | param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; |
| 2577 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; |
| 2578 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 2579 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2580 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2581 | ath10k_warn("Failed to set TX wake thresh: %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2582 | goto err_peer_delete; |
| 2583 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2584 | |
| 2585 | param = WMI_STA_PS_PARAM_PSPOLL_COUNT; |
| 2586 | value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; |
| 2587 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 2588 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2589 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2590 | ath10k_warn("Failed to set PSPOLL count: %d\n", ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2591 | goto err_peer_delete; |
| 2592 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2593 | } |
| 2594 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 2595 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2596 | if (ret) { |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 2597 | ath10k_warn("failed to set rts threshold for vdev %d (%d)\n", |
| 2598 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2599 | goto err_peer_delete; |
| 2600 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 2601 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 2602 | ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2603 | if (ret) { |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 2604 | ath10k_warn("failed to set frag threshold for vdev %d (%d)\n", |
| 2605 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2606 | goto err_peer_delete; |
| 2607 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 2608 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2609 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 2610 | ar->monitor_present = true; |
| 2611 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2612 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2613 | return 0; |
| 2614 | |
| 2615 | err_peer_delete: |
| 2616 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) |
| 2617 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); |
| 2618 | |
| 2619 | err_vdev_delete: |
| 2620 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 2621 | ar->free_vdev_map &= ~BIT(arvif->vdev_id); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2622 | list_del(&arvif->list); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2623 | |
| 2624 | err: |
| 2625 | mutex_unlock(&ar->conf_mutex); |
| 2626 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2627 | return ret; |
| 2628 | } |
| 2629 | |
| 2630 | static void ath10k_remove_interface(struct ieee80211_hw *hw, |
| 2631 | struct ieee80211_vif *vif) |
| 2632 | { |
| 2633 | struct ath10k *ar = hw->priv; |
| 2634 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2635 | int ret; |
| 2636 | |
| 2637 | mutex_lock(&ar->conf_mutex); |
| 2638 | |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2639 | cancel_work_sync(&arvif->wep_key_work); |
| 2640 | |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 2641 | spin_lock_bh(&ar->data_lock); |
| 2642 | if (arvif->beacon) { |
| 2643 | dev_kfree_skb_any(arvif->beacon); |
| 2644 | arvif->beacon = NULL; |
| 2645 | } |
| 2646 | spin_unlock_bh(&ar->data_lock); |
| 2647 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2648 | ar->free_vdev_map |= 1 << (arvif->vdev_id); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 2649 | list_del(&arvif->list); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2650 | |
| 2651 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 2652 | ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr); |
| 2653 | if (ret) |
| 2654 | ath10k_warn("Failed to remove peer for AP: %d\n", ret); |
| 2655 | |
| 2656 | kfree(arvif->u.ap.noa_data); |
| 2657 | } |
| 2658 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2659 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n", |
| 2660 | arvif->vdev_id); |
| 2661 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2662 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 2663 | if (ret) |
| 2664 | ath10k_warn("WMI vdev delete failed: %d\n", ret); |
| 2665 | |
| 2666 | if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) |
| 2667 | ar->monitor_present = false; |
| 2668 | |
| 2669 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
| 2670 | |
| 2671 | mutex_unlock(&ar->conf_mutex); |
| 2672 | } |
| 2673 | |
| 2674 | /* |
| 2675 | * FIXME: Has to be verified. |
| 2676 | */ |
| 2677 | #define SUPPORTED_FILTERS \ |
| 2678 | (FIF_PROMISC_IN_BSS | \ |
| 2679 | FIF_ALLMULTI | \ |
| 2680 | FIF_CONTROL | \ |
| 2681 | FIF_PSPOLL | \ |
| 2682 | FIF_OTHER_BSS | \ |
| 2683 | FIF_BCN_PRBRESP_PROMISC | \ |
| 2684 | FIF_PROBE_REQ | \ |
| 2685 | FIF_FCSFAIL) |
| 2686 | |
| 2687 | static void ath10k_configure_filter(struct ieee80211_hw *hw, |
| 2688 | unsigned int changed_flags, |
| 2689 | unsigned int *total_flags, |
| 2690 | u64 multicast) |
| 2691 | { |
| 2692 | struct ath10k *ar = hw->priv; |
| 2693 | int ret; |
| 2694 | |
| 2695 | mutex_lock(&ar->conf_mutex); |
| 2696 | |
| 2697 | changed_flags &= SUPPORTED_FILTERS; |
| 2698 | *total_flags &= SUPPORTED_FILTERS; |
| 2699 | ar->filter_flags = *total_flags; |
| 2700 | |
Michal Kazior | afd0922 | 2013-10-16 16:45:41 +0300 | [diff] [blame] | 2701 | /* Monitor must not be started if it wasn't created first. |
| 2702 | * Promiscuous mode may be started on a non-monitor interface - in |
| 2703 | * such case the monitor vdev is not created so starting the |
| 2704 | * monitor makes no sense. Since ath10k uses no special RX filters |
| 2705 | * (only BSS filter in STA mode) there's no need for any special |
| 2706 | * action here. */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2707 | if ((ar->filter_flags & FIF_PROMISC_IN_BSS) && |
Michal Kazior | afd0922 | 2013-10-16 16:45:41 +0300 | [diff] [blame] | 2708 | !ar->monitor_enabled && ar->monitor_present) { |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2709 | ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n", |
| 2710 | ar->monitor_vdev_id); |
| 2711 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2712 | ret = ath10k_monitor_start(ar, ar->monitor_vdev_id); |
| 2713 | if (ret) |
| 2714 | ath10k_warn("Unable to start monitor mode\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2715 | } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) && |
Michal Kazior | afd0922 | 2013-10-16 16:45:41 +0300 | [diff] [blame] | 2716 | ar->monitor_enabled && ar->monitor_present) { |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2717 | ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n", |
| 2718 | ar->monitor_vdev_id); |
| 2719 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2720 | ret = ath10k_monitor_stop(ar); |
| 2721 | if (ret) |
| 2722 | ath10k_warn("Unable to stop monitor mode\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | mutex_unlock(&ar->conf_mutex); |
| 2726 | } |
| 2727 | |
| 2728 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, |
| 2729 | struct ieee80211_vif *vif, |
| 2730 | struct ieee80211_bss_conf *info, |
| 2731 | u32 changed) |
| 2732 | { |
| 2733 | struct ath10k *ar = hw->priv; |
| 2734 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2735 | int ret = 0; |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 2736 | u32 vdev_param, pdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2737 | |
| 2738 | mutex_lock(&ar->conf_mutex); |
| 2739 | |
| 2740 | if (changed & BSS_CHANGED_IBSS) |
| 2741 | ath10k_control_ibss(arvif, info, vif->addr); |
| 2742 | |
| 2743 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 2744 | arvif->beacon_interval = info->beacon_int; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2745 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
| 2746 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2747 | arvif->beacon_interval); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2748 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2749 | "mac vdev %d beacon_interval %d\n", |
| 2750 | arvif->vdev_id, arvif->beacon_interval); |
| 2751 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2752 | if (ret) |
| 2753 | ath10k_warn("Failed to set beacon interval for VDEV: %d\n", |
| 2754 | arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | if (changed & BSS_CHANGED_BEACON) { |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2758 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2759 | "vdev %d set beacon tx mode to staggered\n", |
| 2760 | arvif->vdev_id); |
| 2761 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 2762 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
| 2763 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2764 | WMI_BEACON_STAGGERED_MODE); |
| 2765 | if (ret) |
| 2766 | ath10k_warn("Failed to set beacon mode for VDEV: %d\n", |
| 2767 | arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2768 | } |
| 2769 | |
John W. Linville | b70727e8 | 2013-06-13 13:34:29 -0400 | [diff] [blame] | 2770 | if (changed & BSS_CHANGED_BEACON_INFO) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2771 | arvif->dtim_period = info->dtim_period; |
| 2772 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2773 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2774 | "mac vdev %d dtim_period %d\n", |
| 2775 | arvif->vdev_id, arvif->dtim_period); |
| 2776 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2777 | vdev_param = ar->wmi.vdev_param->dtim_period; |
| 2778 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2779 | arvif->dtim_period); |
| 2780 | if (ret) |
| 2781 | ath10k_warn("Failed to set dtim period for VDEV: %d\n", |
| 2782 | arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | if (changed & BSS_CHANGED_SSID && |
| 2786 | vif->type == NL80211_IFTYPE_AP) { |
| 2787 | arvif->u.ap.ssid_len = info->ssid_len; |
| 2788 | if (info->ssid_len) |
| 2789 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); |
| 2790 | arvif->u.ap.hidden_ssid = info->hidden_ssid; |
| 2791 | } |
| 2792 | |
| 2793 | if (changed & BSS_CHANGED_BSSID) { |
| 2794 | if (!is_zero_ether_addr(info->bssid)) { |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2795 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2796 | "mac vdev %d create peer %pM\n", |
| 2797 | arvif->vdev_id, info->bssid); |
| 2798 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2799 | ret = ath10k_peer_create(ar, arvif->vdev_id, |
| 2800 | info->bssid); |
| 2801 | if (ret) |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 2802 | ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n", |
| 2803 | info->bssid, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2804 | |
| 2805 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 2806 | /* |
| 2807 | * this is never erased as we it for crypto key |
| 2808 | * clearing; this is FW requirement |
| 2809 | */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2810 | memcpy(arvif->bssid, info->bssid, ETH_ALEN); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2811 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2812 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2813 | "mac vdev %d start %pM\n", |
| 2814 | arvif->vdev_id, info->bssid); |
| 2815 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2816 | ret = ath10k_vdev_start(arvif); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2817 | if (ret) { |
| 2818 | ath10k_warn("failed to start vdev: %d\n", |
| 2819 | ret); |
Kalle Valo | 75459e3 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 2820 | goto exit; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2821 | } |
| 2822 | |
| 2823 | arvif->is_started = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | /* |
| 2827 | * Mac80211 does not keep IBSS bssid when leaving IBSS, |
| 2828 | * so driver need to store it. It is needed when leaving |
| 2829 | * IBSS in order to remove BSSID peer. |
| 2830 | */ |
| 2831 | if (vif->type == NL80211_IFTYPE_ADHOC) |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2832 | memcpy(arvif->bssid, info->bssid, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2833 | ETH_ALEN); |
| 2834 | } |
| 2835 | } |
| 2836 | |
| 2837 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
| 2838 | ath10k_control_beaconing(arvif, info); |
| 2839 | |
| 2840 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 2841 | u32 cts_prot; |
| 2842 | if (info->use_cts_prot) |
| 2843 | cts_prot = 1; |
| 2844 | else |
| 2845 | cts_prot = 0; |
| 2846 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2847 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n", |
| 2848 | arvif->vdev_id, cts_prot); |
| 2849 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2850 | vdev_param = ar->wmi.vdev_param->enable_rtscts; |
| 2851 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2852 | cts_prot); |
| 2853 | if (ret) |
| 2854 | ath10k_warn("Failed to set CTS prot for VDEV: %d\n", |
| 2855 | arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 2859 | u32 slottime; |
| 2860 | if (info->use_short_slot) |
| 2861 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ |
| 2862 | |
| 2863 | else |
| 2864 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ |
| 2865 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2866 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n", |
| 2867 | arvif->vdev_id, slottime); |
| 2868 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2869 | vdev_param = ar->wmi.vdev_param->slot_time; |
| 2870 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2871 | slottime); |
| 2872 | if (ret) |
| 2873 | ath10k_warn("Failed to set erp slot for VDEV: %d\n", |
| 2874 | arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 2878 | u32 preamble; |
| 2879 | if (info->use_short_preamble) |
| 2880 | preamble = WMI_VDEV_PREAMBLE_SHORT; |
| 2881 | else |
| 2882 | preamble = WMI_VDEV_PREAMBLE_LONG; |
| 2883 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2884 | ath10k_dbg(ATH10K_DBG_MAC, |
| 2885 | "mac vdev %d preamble %dn", |
| 2886 | arvif->vdev_id, preamble); |
| 2887 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 2888 | vdev_param = ar->wmi.vdev_param->preamble; |
| 2889 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2890 | preamble); |
| 2891 | if (ret) |
| 2892 | ath10k_warn("Failed to set preamble for VDEV: %d\n", |
| 2893 | arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | if (changed & BSS_CHANGED_ASSOC) { |
| 2897 | if (info->assoc) |
| 2898 | ath10k_bss_assoc(hw, vif, info); |
| 2899 | } |
| 2900 | |
Kalle Valo | 75459e3 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 2901 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2902 | mutex_unlock(&ar->conf_mutex); |
| 2903 | } |
| 2904 | |
| 2905 | static int ath10k_hw_scan(struct ieee80211_hw *hw, |
| 2906 | struct ieee80211_vif *vif, |
| 2907 | struct cfg80211_scan_request *req) |
| 2908 | { |
| 2909 | struct ath10k *ar = hw->priv; |
| 2910 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2911 | struct wmi_start_scan_arg arg; |
| 2912 | int ret = 0; |
| 2913 | int i; |
| 2914 | |
| 2915 | mutex_lock(&ar->conf_mutex); |
| 2916 | |
| 2917 | spin_lock_bh(&ar->data_lock); |
| 2918 | if (ar->scan.in_progress) { |
| 2919 | spin_unlock_bh(&ar->data_lock); |
| 2920 | ret = -EBUSY; |
| 2921 | goto exit; |
| 2922 | } |
| 2923 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 2924 | reinit_completion(&ar->scan.started); |
| 2925 | reinit_completion(&ar->scan.completed); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2926 | ar->scan.in_progress = true; |
| 2927 | ar->scan.aborting = false; |
| 2928 | ar->scan.is_roc = false; |
| 2929 | ar->scan.vdev_id = arvif->vdev_id; |
| 2930 | spin_unlock_bh(&ar->data_lock); |
| 2931 | |
| 2932 | memset(&arg, 0, sizeof(arg)); |
| 2933 | ath10k_wmi_start_scan_init(ar, &arg); |
| 2934 | arg.vdev_id = arvif->vdev_id; |
| 2935 | arg.scan_id = ATH10K_SCAN_ID; |
| 2936 | |
| 2937 | if (!req->no_cck) |
| 2938 | arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES; |
| 2939 | |
| 2940 | if (req->ie_len) { |
| 2941 | arg.ie_len = req->ie_len; |
| 2942 | memcpy(arg.ie, req->ie, arg.ie_len); |
| 2943 | } |
| 2944 | |
| 2945 | if (req->n_ssids) { |
| 2946 | arg.n_ssids = req->n_ssids; |
| 2947 | for (i = 0; i < arg.n_ssids; i++) { |
| 2948 | arg.ssids[i].len = req->ssids[i].ssid_len; |
| 2949 | arg.ssids[i].ssid = req->ssids[i].ssid; |
| 2950 | } |
Michal Kazior | dcd4a56 | 2013-07-31 10:55:12 +0200 | [diff] [blame] | 2951 | } else { |
| 2952 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | if (req->n_channels) { |
| 2956 | arg.n_channels = req->n_channels; |
| 2957 | for (i = 0; i < arg.n_channels; i++) |
| 2958 | arg.channels[i] = req->channels[i]->center_freq; |
| 2959 | } |
| 2960 | |
| 2961 | ret = ath10k_start_scan(ar, &arg); |
| 2962 | if (ret) { |
| 2963 | ath10k_warn("could not start hw scan (%d)\n", ret); |
| 2964 | spin_lock_bh(&ar->data_lock); |
| 2965 | ar->scan.in_progress = false; |
| 2966 | spin_unlock_bh(&ar->data_lock); |
| 2967 | } |
| 2968 | |
| 2969 | exit: |
| 2970 | mutex_unlock(&ar->conf_mutex); |
| 2971 | return ret; |
| 2972 | } |
| 2973 | |
| 2974 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 2975 | struct ieee80211_vif *vif) |
| 2976 | { |
| 2977 | struct ath10k *ar = hw->priv; |
| 2978 | int ret; |
| 2979 | |
| 2980 | mutex_lock(&ar->conf_mutex); |
| 2981 | ret = ath10k_abort_scan(ar); |
| 2982 | if (ret) { |
| 2983 | ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n", |
| 2984 | ret); |
| 2985 | ieee80211_scan_completed(hw, 1 /* aborted */); |
| 2986 | } |
| 2987 | mutex_unlock(&ar->conf_mutex); |
| 2988 | } |
| 2989 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 2990 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
| 2991 | struct ath10k_vif *arvif, |
| 2992 | enum set_key_cmd cmd, |
| 2993 | struct ieee80211_key_conf *key) |
| 2994 | { |
| 2995 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; |
| 2996 | int ret; |
| 2997 | |
| 2998 | /* 10.1 firmware branch requires default key index to be set to group |
| 2999 | * key index after installing it. Otherwise FW/HW Txes corrupted |
| 3000 | * frames with multi-vif APs. This is not required for main firmware |
| 3001 | * branch (e.g. 636). |
| 3002 | * |
| 3003 | * FIXME: This has been tested only in AP. It remains unknown if this |
| 3004 | * is required for multi-vif STA interfaces on 10.1 */ |
| 3005 | |
| 3006 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 3007 | return; |
| 3008 | |
| 3009 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 3010 | return; |
| 3011 | |
| 3012 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 3013 | return; |
| 3014 | |
| 3015 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 3016 | return; |
| 3017 | |
| 3018 | if (cmd != SET_KEY) |
| 3019 | return; |
| 3020 | |
| 3021 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 3022 | key->keyidx); |
| 3023 | if (ret) |
| 3024 | ath10k_warn("failed to set group key as default key: %d\n", |
| 3025 | ret); |
| 3026 | } |
| 3027 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3028 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 3029 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 3030 | struct ieee80211_key_conf *key) |
| 3031 | { |
| 3032 | struct ath10k *ar = hw->priv; |
| 3033 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3034 | struct ath10k_peer *peer; |
| 3035 | const u8 *peer_addr; |
| 3036 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3037 | key->cipher == WLAN_CIPHER_SUITE_WEP104; |
| 3038 | int ret = 0; |
| 3039 | |
| 3040 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
| 3041 | return -ENOSPC; |
| 3042 | |
| 3043 | mutex_lock(&ar->conf_mutex); |
| 3044 | |
| 3045 | if (sta) |
| 3046 | peer_addr = sta->addr; |
| 3047 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 3048 | peer_addr = vif->bss_conf.bssid; |
| 3049 | else |
| 3050 | peer_addr = vif->addr; |
| 3051 | |
| 3052 | key->hw_key_idx = key->keyidx; |
| 3053 | |
| 3054 | /* the peer should not disappear in mid-way (unless FW goes awry) since |
| 3055 | * we already hold conf_mutex. we just make sure its there now. */ |
| 3056 | spin_lock_bh(&ar->data_lock); |
| 3057 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 3058 | spin_unlock_bh(&ar->data_lock); |
| 3059 | |
| 3060 | if (!peer) { |
| 3061 | if (cmd == SET_KEY) { |
| 3062 | ath10k_warn("cannot install key for non-existent peer %pM\n", |
| 3063 | peer_addr); |
| 3064 | ret = -EOPNOTSUPP; |
| 3065 | goto exit; |
| 3066 | } else { |
| 3067 | /* if the peer doesn't exist there is no key to disable |
| 3068 | * anymore */ |
| 3069 | goto exit; |
| 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | if (is_wep) { |
| 3074 | if (cmd == SET_KEY) |
| 3075 | arvif->wep_keys[key->keyidx] = key; |
| 3076 | else |
| 3077 | arvif->wep_keys[key->keyidx] = NULL; |
| 3078 | |
| 3079 | if (cmd == DISABLE_KEY) |
| 3080 | ath10k_clear_vdev_key(arvif, key); |
| 3081 | } |
| 3082 | |
| 3083 | ret = ath10k_install_key(arvif, key, cmd, peer_addr); |
| 3084 | if (ret) { |
| 3085 | ath10k_warn("ath10k_install_key failed (%d)\n", ret); |
| 3086 | goto exit; |
| 3087 | } |
| 3088 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 3089 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
| 3090 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3091 | spin_lock_bh(&ar->data_lock); |
| 3092 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 3093 | if (peer && cmd == SET_KEY) |
| 3094 | peer->keys[key->keyidx] = key; |
| 3095 | else if (peer && cmd == DISABLE_KEY) |
| 3096 | peer->keys[key->keyidx] = NULL; |
| 3097 | else if (peer == NULL) |
| 3098 | /* impossible unless FW goes crazy */ |
| 3099 | ath10k_warn("peer %pM disappeared!\n", peer_addr); |
| 3100 | spin_unlock_bh(&ar->data_lock); |
| 3101 | |
| 3102 | exit: |
| 3103 | mutex_unlock(&ar->conf_mutex); |
| 3104 | return ret; |
| 3105 | } |
| 3106 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 3107 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
| 3108 | { |
| 3109 | struct ath10k *ar; |
| 3110 | struct ath10k_vif *arvif; |
| 3111 | struct ath10k_sta *arsta; |
| 3112 | struct ieee80211_sta *sta; |
| 3113 | u32 changed, bw, nss, smps; |
| 3114 | int err; |
| 3115 | |
| 3116 | arsta = container_of(wk, struct ath10k_sta, update_wk); |
| 3117 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); |
| 3118 | arvif = arsta->arvif; |
| 3119 | ar = arvif->ar; |
| 3120 | |
| 3121 | spin_lock_bh(&ar->data_lock); |
| 3122 | |
| 3123 | changed = arsta->changed; |
| 3124 | arsta->changed = 0; |
| 3125 | |
| 3126 | bw = arsta->bw; |
| 3127 | nss = arsta->nss; |
| 3128 | smps = arsta->smps; |
| 3129 | |
| 3130 | spin_unlock_bh(&ar->data_lock); |
| 3131 | |
| 3132 | mutex_lock(&ar->conf_mutex); |
| 3133 | |
| 3134 | if (changed & IEEE80211_RC_BW_CHANGED) { |
| 3135 | ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n", |
| 3136 | sta->addr, bw); |
| 3137 | |
| 3138 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 3139 | WMI_PEER_CHAN_WIDTH, bw); |
| 3140 | if (err) |
| 3141 | ath10k_warn("failed to update STA %pM peer bw %d: %d\n", |
| 3142 | sta->addr, bw, err); |
| 3143 | } |
| 3144 | |
| 3145 | if (changed & IEEE80211_RC_NSS_CHANGED) { |
| 3146 | ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n", |
| 3147 | sta->addr, nss); |
| 3148 | |
| 3149 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 3150 | WMI_PEER_NSS, nss); |
| 3151 | if (err) |
| 3152 | ath10k_warn("failed to update STA %pM nss %d: %d\n", |
| 3153 | sta->addr, nss, err); |
| 3154 | } |
| 3155 | |
| 3156 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 3157 | ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n", |
| 3158 | sta->addr, smps); |
| 3159 | |
| 3160 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 3161 | WMI_PEER_SMPS_STATE, smps); |
| 3162 | if (err) |
| 3163 | ath10k_warn("failed to update STA %pM smps %d: %d\n", |
| 3164 | sta->addr, smps, err); |
| 3165 | } |
| 3166 | |
| 3167 | mutex_unlock(&ar->conf_mutex); |
| 3168 | } |
| 3169 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3170 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
| 3171 | struct ieee80211_vif *vif, |
| 3172 | struct ieee80211_sta *sta, |
| 3173 | enum ieee80211_sta_state old_state, |
| 3174 | enum ieee80211_sta_state new_state) |
| 3175 | { |
| 3176 | struct ath10k *ar = hw->priv; |
| 3177 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 3178 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 3179 | int max_num_peers; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3180 | int ret = 0; |
| 3181 | |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame^] | 3182 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 3183 | new_state == IEEE80211_STA_NONE) { |
| 3184 | memset(arsta, 0, sizeof(*arsta)); |
| 3185 | arsta->arvif = arvif; |
| 3186 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); |
| 3187 | } |
| 3188 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 3189 | /* cancel must be done outside the mutex to avoid deadlock */ |
| 3190 | if ((old_state == IEEE80211_STA_NONE && |
| 3191 | new_state == IEEE80211_STA_NOTEXIST)) |
| 3192 | cancel_work_sync(&arsta->update_wk); |
| 3193 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3194 | mutex_lock(&ar->conf_mutex); |
| 3195 | |
| 3196 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 3197 | new_state == IEEE80211_STA_NONE && |
| 3198 | vif->type != NL80211_IFTYPE_STATION) { |
| 3199 | /* |
| 3200 | * New station addition. |
| 3201 | */ |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 3202 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) |
| 3203 | max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1; |
| 3204 | else |
| 3205 | max_num_peers = TARGET_NUM_PEERS; |
| 3206 | |
| 3207 | if (ar->num_peers >= max_num_peers) { |
| 3208 | ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n", |
| 3209 | ar->num_peers, max_num_peers); |
| 3210 | ret = -ENOBUFS; |
| 3211 | goto exit; |
| 3212 | } |
| 3213 | |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3214 | ath10k_dbg(ATH10K_DBG_MAC, |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 3215 | "mac vdev %d peer create %pM (new sta) num_peers %d\n", |
| 3216 | arvif->vdev_id, sta->addr, ar->num_peers); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3217 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3218 | ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr); |
| 3219 | if (ret) |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 3220 | ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n", |
| 3221 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3222 | } else if ((old_state == IEEE80211_STA_NONE && |
| 3223 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 3224 | /* |
| 3225 | * Existing station deletion. |
| 3226 | */ |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3227 | ath10k_dbg(ATH10K_DBG_MAC, |
| 3228 | "mac vdev %d peer delete %pM (sta gone)\n", |
| 3229 | arvif->vdev_id, sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3230 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 3231 | if (ret) |
| 3232 | ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n", |
| 3233 | sta->addr, arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3234 | |
| 3235 | if (vif->type == NL80211_IFTYPE_STATION) |
| 3236 | ath10k_bss_disassoc(hw, vif); |
| 3237 | } else if (old_state == IEEE80211_STA_AUTH && |
| 3238 | new_state == IEEE80211_STA_ASSOC && |
| 3239 | (vif->type == NL80211_IFTYPE_AP || |
| 3240 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 3241 | /* |
| 3242 | * New association. |
| 3243 | */ |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3244 | ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n", |
| 3245 | sta->addr); |
| 3246 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3247 | ret = ath10k_station_assoc(ar, arvif, sta); |
| 3248 | if (ret) |
| 3249 | ath10k_warn("Failed to associate station: %pM\n", |
| 3250 | sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3251 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 3252 | new_state == IEEE80211_STA_AUTH && |
| 3253 | (vif->type == NL80211_IFTYPE_AP || |
| 3254 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 3255 | /* |
| 3256 | * Disassociation. |
| 3257 | */ |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3258 | ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
| 3259 | sta->addr); |
| 3260 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3261 | ret = ath10k_station_disassoc(ar, arvif, sta); |
| 3262 | if (ret) |
| 3263 | ath10k_warn("Failed to disassociate station: %pM\n", |
| 3264 | sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3265 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 3266 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3267 | mutex_unlock(&ar->conf_mutex); |
| 3268 | return ret; |
| 3269 | } |
| 3270 | |
| 3271 | static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif, |
| 3272 | u16 ac, bool enable) |
| 3273 | { |
| 3274 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3275 | u32 value = 0; |
| 3276 | int ret = 0; |
| 3277 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3278 | lockdep_assert_held(&ar->conf_mutex); |
| 3279 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3280 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 3281 | return 0; |
| 3282 | |
| 3283 | switch (ac) { |
| 3284 | case IEEE80211_AC_VO: |
| 3285 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | |
| 3286 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; |
| 3287 | break; |
| 3288 | case IEEE80211_AC_VI: |
| 3289 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | |
| 3290 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; |
| 3291 | break; |
| 3292 | case IEEE80211_AC_BE: |
| 3293 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | |
| 3294 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; |
| 3295 | break; |
| 3296 | case IEEE80211_AC_BK: |
| 3297 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | |
| 3298 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; |
| 3299 | break; |
| 3300 | } |
| 3301 | |
| 3302 | if (enable) |
| 3303 | arvif->u.sta.uapsd |= value; |
| 3304 | else |
| 3305 | arvif->u.sta.uapsd &= ~value; |
| 3306 | |
| 3307 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 3308 | WMI_STA_PS_PARAM_UAPSD, |
| 3309 | arvif->u.sta.uapsd); |
| 3310 | if (ret) { |
| 3311 | ath10k_warn("could not set uapsd params %d\n", ret); |
| 3312 | goto exit; |
| 3313 | } |
| 3314 | |
| 3315 | if (arvif->u.sta.uapsd) |
| 3316 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
| 3317 | else |
| 3318 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 3319 | |
| 3320 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 3321 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, |
| 3322 | value); |
| 3323 | if (ret) |
| 3324 | ath10k_warn("could not set rx wake param %d\n", ret); |
| 3325 | |
| 3326 | exit: |
| 3327 | return ret; |
| 3328 | } |
| 3329 | |
| 3330 | static int ath10k_conf_tx(struct ieee80211_hw *hw, |
| 3331 | struct ieee80211_vif *vif, u16 ac, |
| 3332 | const struct ieee80211_tx_queue_params *params) |
| 3333 | { |
| 3334 | struct ath10k *ar = hw->priv; |
| 3335 | struct wmi_wmm_params_arg *p = NULL; |
| 3336 | int ret; |
| 3337 | |
| 3338 | mutex_lock(&ar->conf_mutex); |
| 3339 | |
| 3340 | switch (ac) { |
| 3341 | case IEEE80211_AC_VO: |
| 3342 | p = &ar->wmm_params.ac_vo; |
| 3343 | break; |
| 3344 | case IEEE80211_AC_VI: |
| 3345 | p = &ar->wmm_params.ac_vi; |
| 3346 | break; |
| 3347 | case IEEE80211_AC_BE: |
| 3348 | p = &ar->wmm_params.ac_be; |
| 3349 | break; |
| 3350 | case IEEE80211_AC_BK: |
| 3351 | p = &ar->wmm_params.ac_bk; |
| 3352 | break; |
| 3353 | } |
| 3354 | |
| 3355 | if (WARN_ON(!p)) { |
| 3356 | ret = -EINVAL; |
| 3357 | goto exit; |
| 3358 | } |
| 3359 | |
| 3360 | p->cwmin = params->cw_min; |
| 3361 | p->cwmax = params->cw_max; |
| 3362 | p->aifs = params->aifs; |
| 3363 | |
| 3364 | /* |
| 3365 | * The channel time duration programmed in the HW is in absolute |
| 3366 | * microseconds, while mac80211 gives the txop in units of |
| 3367 | * 32 microseconds. |
| 3368 | */ |
| 3369 | p->txop = params->txop * 32; |
| 3370 | |
| 3371 | /* FIXME: FW accepts wmm params per hw, not per vif */ |
| 3372 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params); |
| 3373 | if (ret) { |
| 3374 | ath10k_warn("could not set wmm params %d\n", ret); |
| 3375 | goto exit; |
| 3376 | } |
| 3377 | |
| 3378 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); |
| 3379 | if (ret) |
| 3380 | ath10k_warn("could not set sta uapsd %d\n", ret); |
| 3381 | |
| 3382 | exit: |
| 3383 | mutex_unlock(&ar->conf_mutex); |
| 3384 | return ret; |
| 3385 | } |
| 3386 | |
| 3387 | #define ATH10K_ROC_TIMEOUT_HZ (2*HZ) |
| 3388 | |
| 3389 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, |
| 3390 | struct ieee80211_vif *vif, |
| 3391 | struct ieee80211_channel *chan, |
| 3392 | int duration, |
| 3393 | enum ieee80211_roc_type type) |
| 3394 | { |
| 3395 | struct ath10k *ar = hw->priv; |
| 3396 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3397 | struct wmi_start_scan_arg arg; |
| 3398 | int ret; |
| 3399 | |
| 3400 | mutex_lock(&ar->conf_mutex); |
| 3401 | |
| 3402 | spin_lock_bh(&ar->data_lock); |
| 3403 | if (ar->scan.in_progress) { |
| 3404 | spin_unlock_bh(&ar->data_lock); |
| 3405 | ret = -EBUSY; |
| 3406 | goto exit; |
| 3407 | } |
| 3408 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 3409 | reinit_completion(&ar->scan.started); |
| 3410 | reinit_completion(&ar->scan.completed); |
| 3411 | reinit_completion(&ar->scan.on_channel); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3412 | ar->scan.in_progress = true; |
| 3413 | ar->scan.aborting = false; |
| 3414 | ar->scan.is_roc = true; |
| 3415 | ar->scan.vdev_id = arvif->vdev_id; |
| 3416 | ar->scan.roc_freq = chan->center_freq; |
| 3417 | spin_unlock_bh(&ar->data_lock); |
| 3418 | |
| 3419 | memset(&arg, 0, sizeof(arg)); |
| 3420 | ath10k_wmi_start_scan_init(ar, &arg); |
| 3421 | arg.vdev_id = arvif->vdev_id; |
| 3422 | arg.scan_id = ATH10K_SCAN_ID; |
| 3423 | arg.n_channels = 1; |
| 3424 | arg.channels[0] = chan->center_freq; |
| 3425 | arg.dwell_time_active = duration; |
| 3426 | arg.dwell_time_passive = duration; |
| 3427 | arg.max_scan_time = 2 * duration; |
| 3428 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
| 3429 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; |
| 3430 | |
| 3431 | ret = ath10k_start_scan(ar, &arg); |
| 3432 | if (ret) { |
| 3433 | ath10k_warn("could not start roc scan (%d)\n", ret); |
| 3434 | spin_lock_bh(&ar->data_lock); |
| 3435 | ar->scan.in_progress = false; |
| 3436 | spin_unlock_bh(&ar->data_lock); |
| 3437 | goto exit; |
| 3438 | } |
| 3439 | |
| 3440 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ); |
| 3441 | if (ret == 0) { |
| 3442 | ath10k_warn("could not switch to channel for roc scan\n"); |
| 3443 | ath10k_abort_scan(ar); |
| 3444 | ret = -ETIMEDOUT; |
| 3445 | goto exit; |
| 3446 | } |
| 3447 | |
| 3448 | ret = 0; |
| 3449 | exit: |
| 3450 | mutex_unlock(&ar->conf_mutex); |
| 3451 | return ret; |
| 3452 | } |
| 3453 | |
| 3454 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 3455 | { |
| 3456 | struct ath10k *ar = hw->priv; |
| 3457 | |
| 3458 | mutex_lock(&ar->conf_mutex); |
| 3459 | ath10k_abort_scan(ar); |
| 3460 | mutex_unlock(&ar->conf_mutex); |
| 3461 | |
| 3462 | return 0; |
| 3463 | } |
| 3464 | |
| 3465 | /* |
| 3466 | * Both RTS and Fragmentation threshold are interface-specific |
| 3467 | * in ath10k, but device-specific in mac80211. |
| 3468 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3469 | |
| 3470 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 3471 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3472 | struct ath10k *ar = hw->priv; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3473 | struct ath10k_vif *arvif; |
| 3474 | int ret = 0; |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3475 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3476 | mutex_lock(&ar->conf_mutex); |
| 3477 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3478 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n", |
| 3479 | arvif->vdev_id, value); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3480 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3481 | ret = ath10k_mac_set_rts(arvif, value); |
| 3482 | if (ret) { |
| 3483 | ath10k_warn("could not set rts threshold for vdev %d (%d)\n", |
| 3484 | arvif->vdev_id, ret); |
| 3485 | break; |
| 3486 | } |
| 3487 | } |
| 3488 | mutex_unlock(&ar->conf_mutex); |
| 3489 | |
| 3490 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 3494 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3495 | struct ath10k *ar = hw->priv; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3496 | struct ath10k_vif *arvif; |
| 3497 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3498 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3499 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3500 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3501 | ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n", |
| 3502 | arvif->vdev_id, value); |
| 3503 | |
| 3504 | ret = ath10k_mac_set_rts(arvif, value); |
| 3505 | if (ret) { |
| 3506 | ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n", |
| 3507 | arvif->vdev_id, ret); |
| 3508 | break; |
| 3509 | } |
| 3510 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3511 | mutex_unlock(&ar->conf_mutex); |
| 3512 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3513 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop) |
| 3517 | { |
| 3518 | struct ath10k *ar = hw->priv; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3519 | bool skip; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3520 | int ret; |
| 3521 | |
| 3522 | /* mac80211 doesn't care if we really xmit queued frames or not |
| 3523 | * we'll collect those frames either way if we stop/delete vdevs */ |
| 3524 | if (drop) |
| 3525 | return; |
| 3526 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3527 | mutex_lock(&ar->conf_mutex); |
| 3528 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3529 | if (ar->state == ATH10K_STATE_WEDGED) |
| 3530 | goto skip; |
| 3531 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 3532 | ret = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3533 | bool empty; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3534 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 3535 | spin_lock_bh(&ar->htt.tx_lock); |
Michal Kazior | 0945baf | 2013-09-18 14:43:18 +0200 | [diff] [blame] | 3536 | empty = (ar->htt.num_pending_tx == 0); |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 3537 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3538 | |
| 3539 | skip = (ar->state == ATH10K_STATE_WEDGED); |
| 3540 | |
| 3541 | (empty || skip); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3542 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3543 | |
| 3544 | if (ret <= 0 || skip) |
Ben Greear | 9ba4c78 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 3545 | ath10k_warn("tx not flushed (skip %i ar-state %i): %i\n", |
| 3546 | skip, ar->state, ret); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3547 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3548 | skip: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3549 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | /* TODO: Implement this function properly |
| 3553 | * For now it is needed to reply to Probe Requests in IBSS mode. |
| 3554 | * Propably we need this information from FW. |
| 3555 | */ |
| 3556 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) |
| 3557 | { |
| 3558 | return 1; |
| 3559 | } |
| 3560 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3561 | #ifdef CONFIG_PM |
| 3562 | static int ath10k_suspend(struct ieee80211_hw *hw, |
| 3563 | struct cfg80211_wowlan *wowlan) |
| 3564 | { |
| 3565 | struct ath10k *ar = hw->priv; |
| 3566 | int ret; |
| 3567 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3568 | mutex_lock(&ar->conf_mutex); |
| 3569 | |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 3570 | ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND); |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3571 | if (ret) { |
Marek Puzyniak | 00f5482 | 2014-02-10 17:14:24 +0100 | [diff] [blame] | 3572 | if (ret == -ETIMEDOUT) |
| 3573 | goto resume; |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3574 | ret = 1; |
| 3575 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3576 | } |
| 3577 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3578 | ret = ath10k_hif_suspend(ar); |
| 3579 | if (ret) { |
| 3580 | ath10k_warn("could not suspend hif (%d)\n", ret); |
| 3581 | goto resume; |
| 3582 | } |
| 3583 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3584 | ret = 0; |
| 3585 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3586 | resume: |
| 3587 | ret = ath10k_wmi_pdev_resume_target(ar); |
| 3588 | if (ret) |
| 3589 | ath10k_warn("could not resume target (%d)\n", ret); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3590 | |
| 3591 | ret = 1; |
| 3592 | exit: |
| 3593 | mutex_unlock(&ar->conf_mutex); |
| 3594 | return ret; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | static int ath10k_resume(struct ieee80211_hw *hw) |
| 3598 | { |
| 3599 | struct ath10k *ar = hw->priv; |
| 3600 | int ret; |
| 3601 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3602 | mutex_lock(&ar->conf_mutex); |
| 3603 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3604 | ret = ath10k_hif_resume(ar); |
| 3605 | if (ret) { |
| 3606 | ath10k_warn("could not resume hif (%d)\n", ret); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3607 | ret = 1; |
| 3608 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | ret = ath10k_wmi_pdev_resume_target(ar); |
| 3612 | if (ret) { |
| 3613 | ath10k_warn("could not resume target (%d)\n", ret); |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3614 | ret = 1; |
| 3615 | goto exit; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3616 | } |
| 3617 | |
Marek Puzyniak | 9042e17 | 2014-02-10 17:14:23 +0100 | [diff] [blame] | 3618 | ret = 0; |
| 3619 | exit: |
| 3620 | mutex_unlock(&ar->conf_mutex); |
| 3621 | return ret; |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 3622 | } |
| 3623 | #endif |
| 3624 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3625 | static void ath10k_restart_complete(struct ieee80211_hw *hw) |
| 3626 | { |
| 3627 | struct ath10k *ar = hw->priv; |
| 3628 | |
| 3629 | mutex_lock(&ar->conf_mutex); |
| 3630 | |
| 3631 | /* If device failed to restart it will be in a different state, e.g. |
| 3632 | * ATH10K_STATE_WEDGED */ |
| 3633 | if (ar->state == ATH10K_STATE_RESTARTED) { |
| 3634 | ath10k_info("device successfully recovered\n"); |
| 3635 | ar->state = ATH10K_STATE_ON; |
| 3636 | } |
| 3637 | |
| 3638 | mutex_unlock(&ar->conf_mutex); |
| 3639 | } |
| 3640 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 3641 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
| 3642 | struct survey_info *survey) |
| 3643 | { |
| 3644 | struct ath10k *ar = hw->priv; |
| 3645 | struct ieee80211_supported_band *sband; |
| 3646 | struct survey_info *ar_survey = &ar->survey[idx]; |
| 3647 | int ret = 0; |
| 3648 | |
| 3649 | mutex_lock(&ar->conf_mutex); |
| 3650 | |
| 3651 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 3652 | if (sband && idx >= sband->n_channels) { |
| 3653 | idx -= sband->n_channels; |
| 3654 | sband = NULL; |
| 3655 | } |
| 3656 | |
| 3657 | if (!sband) |
| 3658 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 3659 | |
| 3660 | if (!sband || idx >= sband->n_channels) { |
| 3661 | ret = -ENOENT; |
| 3662 | goto exit; |
| 3663 | } |
| 3664 | |
| 3665 | spin_lock_bh(&ar->data_lock); |
| 3666 | memcpy(survey, ar_survey, sizeof(*survey)); |
| 3667 | spin_unlock_bh(&ar->data_lock); |
| 3668 | |
| 3669 | survey->channel = &sband->channels[idx]; |
| 3670 | |
| 3671 | exit: |
| 3672 | mutex_unlock(&ar->conf_mutex); |
| 3673 | return ret; |
| 3674 | } |
| 3675 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 3676 | /* Helper table for legacy fixed_rate/bitrate_mask */ |
| 3677 | static const u8 cck_ofdm_rate[] = { |
| 3678 | /* CCK */ |
| 3679 | 3, /* 1Mbps */ |
| 3680 | 2, /* 2Mbps */ |
| 3681 | 1, /* 5.5Mbps */ |
| 3682 | 0, /* 11Mbps */ |
| 3683 | /* OFDM */ |
| 3684 | 3, /* 6Mbps */ |
| 3685 | 7, /* 9Mbps */ |
| 3686 | 2, /* 12Mbps */ |
| 3687 | 6, /* 18Mbps */ |
| 3688 | 1, /* 24Mbps */ |
| 3689 | 5, /* 36Mbps */ |
| 3690 | 0, /* 48Mbps */ |
| 3691 | 4, /* 54Mbps */ |
| 3692 | }; |
| 3693 | |
| 3694 | /* Check if only one bit set */ |
| 3695 | static int ath10k_check_single_mask(u32 mask) |
| 3696 | { |
| 3697 | int bit; |
| 3698 | |
| 3699 | bit = ffs(mask); |
| 3700 | if (!bit) |
| 3701 | return 0; |
| 3702 | |
| 3703 | mask &= ~BIT(bit - 1); |
| 3704 | if (mask) |
| 3705 | return 2; |
| 3706 | |
| 3707 | return 1; |
| 3708 | } |
| 3709 | |
| 3710 | static bool |
| 3711 | ath10k_default_bitrate_mask(struct ath10k *ar, |
| 3712 | enum ieee80211_band band, |
| 3713 | const struct cfg80211_bitrate_mask *mask) |
| 3714 | { |
| 3715 | u32 legacy = 0x00ff; |
| 3716 | u8 ht = 0xff, i; |
| 3717 | u16 vht = 0x3ff; |
| 3718 | |
| 3719 | switch (band) { |
| 3720 | case IEEE80211_BAND_2GHZ: |
| 3721 | legacy = 0x00fff; |
| 3722 | vht = 0; |
| 3723 | break; |
| 3724 | case IEEE80211_BAND_5GHZ: |
| 3725 | break; |
| 3726 | default: |
| 3727 | return false; |
| 3728 | } |
| 3729 | |
| 3730 | if (mask->control[band].legacy != legacy) |
| 3731 | return false; |
| 3732 | |
| 3733 | for (i = 0; i < ar->num_rf_chains; i++) |
| 3734 | if (mask->control[band].ht_mcs[i] != ht) |
| 3735 | return false; |
| 3736 | |
| 3737 | for (i = 0; i < ar->num_rf_chains; i++) |
| 3738 | if (mask->control[band].vht_mcs[i] != vht) |
| 3739 | return false; |
| 3740 | |
| 3741 | return true; |
| 3742 | } |
| 3743 | |
| 3744 | static bool |
| 3745 | ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask, |
| 3746 | enum ieee80211_band band, |
| 3747 | u8 *fixed_nss) |
| 3748 | { |
| 3749 | int ht_nss = 0, vht_nss = 0, i; |
| 3750 | |
| 3751 | /* check legacy */ |
| 3752 | if (ath10k_check_single_mask(mask->control[band].legacy)) |
| 3753 | return false; |
| 3754 | |
| 3755 | /* check HT */ |
| 3756 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
| 3757 | if (mask->control[band].ht_mcs[i] == 0xff) |
| 3758 | continue; |
| 3759 | else if (mask->control[band].ht_mcs[i] == 0x00) |
| 3760 | break; |
| 3761 | else |
| 3762 | return false; |
| 3763 | } |
| 3764 | |
| 3765 | ht_nss = i; |
| 3766 | |
| 3767 | /* check VHT */ |
| 3768 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3769 | if (mask->control[band].vht_mcs[i] == 0x03ff) |
| 3770 | continue; |
| 3771 | else if (mask->control[band].vht_mcs[i] == 0x0000) |
| 3772 | break; |
| 3773 | else |
| 3774 | return false; |
| 3775 | } |
| 3776 | |
| 3777 | vht_nss = i; |
| 3778 | |
| 3779 | if (ht_nss > 0 && vht_nss > 0) |
| 3780 | return false; |
| 3781 | |
| 3782 | if (ht_nss) |
| 3783 | *fixed_nss = ht_nss; |
| 3784 | else if (vht_nss) |
| 3785 | *fixed_nss = vht_nss; |
| 3786 | else |
| 3787 | return false; |
| 3788 | |
| 3789 | return true; |
| 3790 | } |
| 3791 | |
| 3792 | static bool |
| 3793 | ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask, |
| 3794 | enum ieee80211_band band, |
| 3795 | enum wmi_rate_preamble *preamble) |
| 3796 | { |
| 3797 | int legacy = 0, ht = 0, vht = 0, i; |
| 3798 | |
| 3799 | *preamble = WMI_RATE_PREAMBLE_OFDM; |
| 3800 | |
| 3801 | /* check legacy */ |
| 3802 | legacy = ath10k_check_single_mask(mask->control[band].legacy); |
| 3803 | if (legacy > 1) |
| 3804 | return false; |
| 3805 | |
| 3806 | /* check HT */ |
| 3807 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3808 | ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]); |
| 3809 | if (ht > 1) |
| 3810 | return false; |
| 3811 | |
| 3812 | /* check VHT */ |
| 3813 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3814 | vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]); |
| 3815 | if (vht > 1) |
| 3816 | return false; |
| 3817 | |
| 3818 | /* Currently we support only one fixed_rate */ |
| 3819 | if ((legacy + ht + vht) != 1) |
| 3820 | return false; |
| 3821 | |
| 3822 | if (ht) |
| 3823 | *preamble = WMI_RATE_PREAMBLE_HT; |
| 3824 | else if (vht) |
| 3825 | *preamble = WMI_RATE_PREAMBLE_VHT; |
| 3826 | |
| 3827 | return true; |
| 3828 | } |
| 3829 | |
| 3830 | static bool |
| 3831 | ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask, |
| 3832 | enum ieee80211_band band, |
| 3833 | u8 *fixed_rate, |
| 3834 | u8 *fixed_nss) |
| 3835 | { |
| 3836 | u8 rate = 0, pream = 0, nss = 0, i; |
| 3837 | enum wmi_rate_preamble preamble; |
| 3838 | |
| 3839 | /* Check if single rate correct */ |
| 3840 | if (!ath10k_bitrate_mask_correct(mask, band, &preamble)) |
| 3841 | return false; |
| 3842 | |
| 3843 | pream = preamble; |
| 3844 | |
| 3845 | switch (preamble) { |
| 3846 | case WMI_RATE_PREAMBLE_CCK: |
| 3847 | case WMI_RATE_PREAMBLE_OFDM: |
| 3848 | i = ffs(mask->control[band].legacy) - 1; |
| 3849 | |
| 3850 | if (band == IEEE80211_BAND_2GHZ && i < 4) |
| 3851 | pream = WMI_RATE_PREAMBLE_CCK; |
| 3852 | |
| 3853 | if (band == IEEE80211_BAND_5GHZ) |
| 3854 | i += 4; |
| 3855 | |
| 3856 | if (i >= ARRAY_SIZE(cck_ofdm_rate)) |
| 3857 | return false; |
| 3858 | |
| 3859 | rate = cck_ofdm_rate[i]; |
| 3860 | break; |
| 3861 | case WMI_RATE_PREAMBLE_HT: |
| 3862 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3863 | if (mask->control[band].ht_mcs[i]) |
| 3864 | break; |
| 3865 | |
| 3866 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
| 3867 | return false; |
| 3868 | |
| 3869 | rate = ffs(mask->control[band].ht_mcs[i]) - 1; |
| 3870 | nss = i; |
| 3871 | break; |
| 3872 | case WMI_RATE_PREAMBLE_VHT: |
| 3873 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3874 | if (mask->control[band].vht_mcs[i]) |
| 3875 | break; |
| 3876 | |
| 3877 | if (i == NL80211_VHT_NSS_MAX) |
| 3878 | return false; |
| 3879 | |
| 3880 | rate = ffs(mask->control[band].vht_mcs[i]) - 1; |
| 3881 | nss = i; |
| 3882 | break; |
| 3883 | } |
| 3884 | |
| 3885 | *fixed_nss = nss + 1; |
| 3886 | nss <<= 4; |
| 3887 | pream <<= 6; |
| 3888 | |
| 3889 | ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n", |
| 3890 | pream, nss, rate); |
| 3891 | |
| 3892 | *fixed_rate = pream | nss | rate; |
| 3893 | |
| 3894 | return true; |
| 3895 | } |
| 3896 | |
| 3897 | static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask, |
| 3898 | enum ieee80211_band band, |
| 3899 | u8 *fixed_rate, |
| 3900 | u8 *fixed_nss) |
| 3901 | { |
| 3902 | /* First check full NSS mask, if we can simply limit NSS */ |
| 3903 | if (ath10k_bitrate_mask_nss(mask, band, fixed_nss)) |
| 3904 | return true; |
| 3905 | |
| 3906 | /* Next Check single rate is set */ |
| 3907 | return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss); |
| 3908 | } |
| 3909 | |
| 3910 | static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif, |
| 3911 | u8 fixed_rate, |
| 3912 | u8 fixed_nss) |
| 3913 | { |
| 3914 | struct ath10k *ar = arvif->ar; |
| 3915 | u32 vdev_param; |
| 3916 | int ret = 0; |
| 3917 | |
| 3918 | mutex_lock(&ar->conf_mutex); |
| 3919 | |
| 3920 | if (arvif->fixed_rate == fixed_rate && |
| 3921 | arvif->fixed_nss == fixed_nss) |
| 3922 | goto exit; |
| 3923 | |
| 3924 | if (fixed_rate == WMI_FIXED_RATE_NONE) |
| 3925 | ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n"); |
| 3926 | |
| 3927 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
| 3928 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 3929 | vdev_param, fixed_rate); |
| 3930 | if (ret) { |
| 3931 | ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n", |
| 3932 | fixed_rate, ret); |
| 3933 | ret = -EINVAL; |
| 3934 | goto exit; |
| 3935 | } |
| 3936 | |
| 3937 | arvif->fixed_rate = fixed_rate; |
| 3938 | |
| 3939 | vdev_param = ar->wmi.vdev_param->nss; |
| 3940 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 3941 | vdev_param, fixed_nss); |
| 3942 | |
| 3943 | if (ret) { |
| 3944 | ath10k_warn("Could not set fixed_nss param %d: %d\n", |
| 3945 | fixed_nss, ret); |
| 3946 | ret = -EINVAL; |
| 3947 | goto exit; |
| 3948 | } |
| 3949 | |
| 3950 | arvif->fixed_nss = fixed_nss; |
| 3951 | |
| 3952 | exit: |
| 3953 | mutex_unlock(&ar->conf_mutex); |
| 3954 | return ret; |
| 3955 | } |
| 3956 | |
| 3957 | static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw, |
| 3958 | struct ieee80211_vif *vif, |
| 3959 | const struct cfg80211_bitrate_mask *mask) |
| 3960 | { |
| 3961 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3962 | struct ath10k *ar = arvif->ar; |
| 3963 | enum ieee80211_band band = ar->hw->conf.chandef.chan->band; |
| 3964 | u8 fixed_rate = WMI_FIXED_RATE_NONE; |
| 3965 | u8 fixed_nss = ar->num_rf_chains; |
| 3966 | |
| 3967 | if (!ath10k_default_bitrate_mask(ar, band, mask)) { |
| 3968 | if (!ath10k_get_fixed_rate_nss(mask, band, |
| 3969 | &fixed_rate, |
| 3970 | &fixed_nss)) |
| 3971 | return -EINVAL; |
| 3972 | } |
| 3973 | |
| 3974 | return ath10k_set_fixed_rate_param(arvif, fixed_rate, fixed_nss); |
| 3975 | } |
| 3976 | |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 3977 | static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw, |
| 3978 | struct ieee80211_vif *vif, |
| 3979 | struct cfg80211_chan_def *chandef) |
| 3980 | { |
| 3981 | /* there's no need to do anything here. vif->csa_active is enough */ |
| 3982 | return; |
| 3983 | } |
| 3984 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 3985 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
| 3986 | struct ieee80211_vif *vif, |
| 3987 | struct ieee80211_sta *sta, |
| 3988 | u32 changed) |
| 3989 | { |
| 3990 | struct ath10k *ar = hw->priv; |
| 3991 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 3992 | u32 bw, smps; |
| 3993 | |
| 3994 | spin_lock_bh(&ar->data_lock); |
| 3995 | |
| 3996 | ath10k_dbg(ATH10K_DBG_MAC, |
| 3997 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
| 3998 | sta->addr, changed, sta->bandwidth, sta->rx_nss, |
| 3999 | sta->smps_mode); |
| 4000 | |
| 4001 | if (changed & IEEE80211_RC_BW_CHANGED) { |
| 4002 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 4003 | |
| 4004 | switch (sta->bandwidth) { |
| 4005 | case IEEE80211_STA_RX_BW_20: |
| 4006 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 4007 | break; |
| 4008 | case IEEE80211_STA_RX_BW_40: |
| 4009 | bw = WMI_PEER_CHWIDTH_40MHZ; |
| 4010 | break; |
| 4011 | case IEEE80211_STA_RX_BW_80: |
| 4012 | bw = WMI_PEER_CHWIDTH_80MHZ; |
| 4013 | break; |
| 4014 | case IEEE80211_STA_RX_BW_160: |
| 4015 | ath10k_warn("mac sta rc update for %pM: invalid bw %d\n", |
| 4016 | sta->addr, sta->bandwidth); |
| 4017 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 4018 | break; |
| 4019 | } |
| 4020 | |
| 4021 | arsta->bw = bw; |
| 4022 | } |
| 4023 | |
| 4024 | if (changed & IEEE80211_RC_NSS_CHANGED) |
| 4025 | arsta->nss = sta->rx_nss; |
| 4026 | |
| 4027 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 4028 | smps = WMI_PEER_SMPS_PS_NONE; |
| 4029 | |
| 4030 | switch (sta->smps_mode) { |
| 4031 | case IEEE80211_SMPS_AUTOMATIC: |
| 4032 | case IEEE80211_SMPS_OFF: |
| 4033 | smps = WMI_PEER_SMPS_PS_NONE; |
| 4034 | break; |
| 4035 | case IEEE80211_SMPS_STATIC: |
| 4036 | smps = WMI_PEER_SMPS_STATIC; |
| 4037 | break; |
| 4038 | case IEEE80211_SMPS_DYNAMIC: |
| 4039 | smps = WMI_PEER_SMPS_DYNAMIC; |
| 4040 | break; |
| 4041 | case IEEE80211_SMPS_NUM_MODES: |
| 4042 | ath10k_warn("mac sta rc update for %pM: invalid smps: %d\n", |
| 4043 | sta->addr, sta->smps_mode); |
| 4044 | smps = WMI_PEER_SMPS_PS_NONE; |
| 4045 | break; |
| 4046 | } |
| 4047 | |
| 4048 | arsta->smps = smps; |
| 4049 | } |
| 4050 | |
| 4051 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { |
| 4052 | /* FIXME: Not implemented. Probably the only way to do it would |
| 4053 | * be to re-assoc the peer. */ |
| 4054 | changed &= ~IEEE80211_RC_SUPP_RATES_CHANGED; |
| 4055 | ath10k_dbg(ATH10K_DBG_MAC, |
| 4056 | "mac sta rc update for %pM: changing supported rates not implemented\n", |
| 4057 | sta->addr); |
| 4058 | } |
| 4059 | |
| 4060 | arsta->changed |= changed; |
| 4061 | |
| 4062 | spin_unlock_bh(&ar->data_lock); |
| 4063 | |
| 4064 | ieee80211_queue_work(hw, &arsta->update_wk); |
| 4065 | } |
| 4066 | |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 4067 | static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 4068 | { |
| 4069 | /* |
| 4070 | * FIXME: Return 0 for time being. Need to figure out whether FW |
| 4071 | * has the API to fetch 64-bit local TSF |
| 4072 | */ |
| 4073 | |
| 4074 | return 0; |
| 4075 | } |
| 4076 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4077 | static const struct ieee80211_ops ath10k_ops = { |
| 4078 | .tx = ath10k_tx, |
| 4079 | .start = ath10k_start, |
| 4080 | .stop = ath10k_stop, |
| 4081 | .config = ath10k_config, |
| 4082 | .add_interface = ath10k_add_interface, |
| 4083 | .remove_interface = ath10k_remove_interface, |
| 4084 | .configure_filter = ath10k_configure_filter, |
| 4085 | .bss_info_changed = ath10k_bss_info_changed, |
| 4086 | .hw_scan = ath10k_hw_scan, |
| 4087 | .cancel_hw_scan = ath10k_cancel_hw_scan, |
| 4088 | .set_key = ath10k_set_key, |
| 4089 | .sta_state = ath10k_sta_state, |
| 4090 | .conf_tx = ath10k_conf_tx, |
| 4091 | .remain_on_channel = ath10k_remain_on_channel, |
| 4092 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, |
| 4093 | .set_rts_threshold = ath10k_set_rts_threshold, |
| 4094 | .set_frag_threshold = ath10k_set_frag_threshold, |
| 4095 | .flush = ath10k_flush, |
| 4096 | .tx_last_beacon = ath10k_tx_last_beacon, |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4097 | .restart_complete = ath10k_restart_complete, |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 4098 | .get_survey = ath10k_get_survey, |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 4099 | .set_bitrate_mask = ath10k_set_bitrate_mask, |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 4100 | .channel_switch_beacon = ath10k_channel_switch_beacon, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4101 | .sta_rc_update = ath10k_sta_rc_update, |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 4102 | .get_tsf = ath10k_get_tsf, |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 4103 | #ifdef CONFIG_PM |
| 4104 | .suspend = ath10k_suspend, |
| 4105 | .resume = ath10k_resume, |
| 4106 | #endif |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4107 | }; |
| 4108 | |
| 4109 | #define RATETAB_ENT(_rate, _rateid, _flags) { \ |
| 4110 | .bitrate = (_rate), \ |
| 4111 | .flags = (_flags), \ |
| 4112 | .hw_value = (_rateid), \ |
| 4113 | } |
| 4114 | |
| 4115 | #define CHAN2G(_channel, _freq, _flags) { \ |
| 4116 | .band = IEEE80211_BAND_2GHZ, \ |
| 4117 | .hw_value = (_channel), \ |
| 4118 | .center_freq = (_freq), \ |
| 4119 | .flags = (_flags), \ |
| 4120 | .max_antenna_gain = 0, \ |
| 4121 | .max_power = 30, \ |
| 4122 | } |
| 4123 | |
| 4124 | #define CHAN5G(_channel, _freq, _flags) { \ |
| 4125 | .band = IEEE80211_BAND_5GHZ, \ |
| 4126 | .hw_value = (_channel), \ |
| 4127 | .center_freq = (_freq), \ |
| 4128 | .flags = (_flags), \ |
| 4129 | .max_antenna_gain = 0, \ |
| 4130 | .max_power = 30, \ |
| 4131 | } |
| 4132 | |
| 4133 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { |
| 4134 | CHAN2G(1, 2412, 0), |
| 4135 | CHAN2G(2, 2417, 0), |
| 4136 | CHAN2G(3, 2422, 0), |
| 4137 | CHAN2G(4, 2427, 0), |
| 4138 | CHAN2G(5, 2432, 0), |
| 4139 | CHAN2G(6, 2437, 0), |
| 4140 | CHAN2G(7, 2442, 0), |
| 4141 | CHAN2G(8, 2447, 0), |
| 4142 | CHAN2G(9, 2452, 0), |
| 4143 | CHAN2G(10, 2457, 0), |
| 4144 | CHAN2G(11, 2462, 0), |
| 4145 | CHAN2G(12, 2467, 0), |
| 4146 | CHAN2G(13, 2472, 0), |
| 4147 | CHAN2G(14, 2484, 0), |
| 4148 | }; |
| 4149 | |
| 4150 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 4151 | CHAN5G(36, 5180, 0), |
| 4152 | CHAN5G(40, 5200, 0), |
| 4153 | CHAN5G(44, 5220, 0), |
| 4154 | CHAN5G(48, 5240, 0), |
| 4155 | CHAN5G(52, 5260, 0), |
| 4156 | CHAN5G(56, 5280, 0), |
| 4157 | CHAN5G(60, 5300, 0), |
| 4158 | CHAN5G(64, 5320, 0), |
| 4159 | CHAN5G(100, 5500, 0), |
| 4160 | CHAN5G(104, 5520, 0), |
| 4161 | CHAN5G(108, 5540, 0), |
| 4162 | CHAN5G(112, 5560, 0), |
| 4163 | CHAN5G(116, 5580, 0), |
| 4164 | CHAN5G(120, 5600, 0), |
| 4165 | CHAN5G(124, 5620, 0), |
| 4166 | CHAN5G(128, 5640, 0), |
| 4167 | CHAN5G(132, 5660, 0), |
| 4168 | CHAN5G(136, 5680, 0), |
| 4169 | CHAN5G(140, 5700, 0), |
| 4170 | CHAN5G(149, 5745, 0), |
| 4171 | CHAN5G(153, 5765, 0), |
| 4172 | CHAN5G(157, 5785, 0), |
| 4173 | CHAN5G(161, 5805, 0), |
| 4174 | CHAN5G(165, 5825, 0), |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4175 | }; |
| 4176 | |
| 4177 | static struct ieee80211_rate ath10k_rates[] = { |
| 4178 | /* CCK */ |
| 4179 | RATETAB_ENT(10, 0x82, 0), |
| 4180 | RATETAB_ENT(20, 0x84, 0), |
| 4181 | RATETAB_ENT(55, 0x8b, 0), |
| 4182 | RATETAB_ENT(110, 0x96, 0), |
| 4183 | /* OFDM */ |
| 4184 | RATETAB_ENT(60, 0x0c, 0), |
| 4185 | RATETAB_ENT(90, 0x12, 0), |
| 4186 | RATETAB_ENT(120, 0x18, 0), |
| 4187 | RATETAB_ENT(180, 0x24, 0), |
| 4188 | RATETAB_ENT(240, 0x30, 0), |
| 4189 | RATETAB_ENT(360, 0x48, 0), |
| 4190 | RATETAB_ENT(480, 0x60, 0), |
| 4191 | RATETAB_ENT(540, 0x6c, 0), |
| 4192 | }; |
| 4193 | |
| 4194 | #define ath10k_a_rates (ath10k_rates + 4) |
| 4195 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4) |
| 4196 | #define ath10k_g_rates (ath10k_rates + 0) |
| 4197 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) |
| 4198 | |
| 4199 | struct ath10k *ath10k_mac_create(void) |
| 4200 | { |
| 4201 | struct ieee80211_hw *hw; |
| 4202 | struct ath10k *ar; |
| 4203 | |
| 4204 | hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops); |
| 4205 | if (!hw) |
| 4206 | return NULL; |
| 4207 | |
| 4208 | ar = hw->priv; |
| 4209 | ar->hw = hw; |
| 4210 | |
| 4211 | return ar; |
| 4212 | } |
| 4213 | |
| 4214 | void ath10k_mac_destroy(struct ath10k *ar) |
| 4215 | { |
| 4216 | ieee80211_free_hw(ar->hw); |
| 4217 | } |
| 4218 | |
| 4219 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { |
| 4220 | { |
| 4221 | .max = 8, |
| 4222 | .types = BIT(NL80211_IFTYPE_STATION) |
| 4223 | | BIT(NL80211_IFTYPE_P2P_CLIENT) |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 4224 | }, |
| 4225 | { |
| 4226 | .max = 3, |
| 4227 | .types = BIT(NL80211_IFTYPE_P2P_GO) |
| 4228 | }, |
| 4229 | { |
| 4230 | .max = 7, |
| 4231 | .types = BIT(NL80211_IFTYPE_AP) |
| 4232 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4233 | }; |
| 4234 | |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 4235 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 4236 | { |
| 4237 | .max = 8, |
| 4238 | .types = BIT(NL80211_IFTYPE_AP) |
| 4239 | }, |
| 4240 | }; |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 4241 | |
| 4242 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { |
| 4243 | { |
| 4244 | .limits = ath10k_if_limits, |
| 4245 | .n_limits = ARRAY_SIZE(ath10k_if_limits), |
| 4246 | .max_interfaces = 8, |
| 4247 | .num_different_channels = 1, |
| 4248 | .beacon_int_infra_match = true, |
| 4249 | }, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 4250 | }; |
| 4251 | |
| 4252 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 4253 | { |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 4254 | .limits = ath10k_10x_if_limits, |
| 4255 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 4256 | .max_interfaces = 8, |
| 4257 | .num_different_channels = 1, |
| 4258 | .beacon_int_infra_match = true, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 4259 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 4260 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 4261 | BIT(NL80211_CHAN_WIDTH_20) | |
| 4262 | BIT(NL80211_CHAN_WIDTH_40) | |
| 4263 | BIT(NL80211_CHAN_WIDTH_80), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 4264 | #endif |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 4265 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4266 | }; |
| 4267 | |
| 4268 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) |
| 4269 | { |
| 4270 | struct ieee80211_sta_vht_cap vht_cap = {0}; |
| 4271 | u16 mcs_map; |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 4272 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4273 | |
| 4274 | vht_cap.vht_supported = 1; |
| 4275 | vht_cap.cap = ar->vht_cap_info; |
| 4276 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 4277 | mcs_map = 0; |
| 4278 | for (i = 0; i < 8; i++) { |
| 4279 | if (i < ar->num_rf_chains) |
| 4280 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2); |
| 4281 | else |
| 4282 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2); |
| 4283 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4284 | |
| 4285 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 4286 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 4287 | |
| 4288 | return vht_cap; |
| 4289 | } |
| 4290 | |
| 4291 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) |
| 4292 | { |
| 4293 | int i; |
| 4294 | struct ieee80211_sta_ht_cap ht_cap = {0}; |
| 4295 | |
| 4296 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) |
| 4297 | return ht_cap; |
| 4298 | |
| 4299 | ht_cap.ht_supported = 1; |
| 4300 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 4301 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; |
| 4302 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 4303 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 4304 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 4305 | |
| 4306 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) |
| 4307 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 4308 | |
| 4309 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) |
| 4310 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 4311 | |
| 4312 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { |
| 4313 | u32 smps; |
| 4314 | |
| 4315 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; |
| 4316 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 4317 | |
| 4318 | ht_cap.cap |= smps; |
| 4319 | } |
| 4320 | |
| 4321 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC) |
| 4322 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 4323 | |
| 4324 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { |
| 4325 | u32 stbc; |
| 4326 | |
| 4327 | stbc = ar->ht_cap_info; |
| 4328 | stbc &= WMI_HT_CAP_RX_STBC; |
| 4329 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; |
| 4330 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 4331 | stbc &= IEEE80211_HT_CAP_RX_STBC; |
| 4332 | |
| 4333 | ht_cap.cap |= stbc; |
| 4334 | } |
| 4335 | |
| 4336 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC) |
| 4337 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; |
| 4338 | |
| 4339 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) |
| 4340 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; |
| 4341 | |
| 4342 | /* max AMSDU is implicitly taken from vht_cap_info */ |
| 4343 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) |
| 4344 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
| 4345 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 4346 | for (i = 0; i < ar->num_rf_chains; i++) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4347 | ht_cap.mcs.rx_mask[i] = 0xFF; |
| 4348 | |
| 4349 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
| 4350 | |
| 4351 | return ht_cap; |
| 4352 | } |
| 4353 | |
| 4354 | |
| 4355 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
| 4356 | struct ieee80211_vif *vif) |
| 4357 | { |
| 4358 | struct ath10k_vif_iter *arvif_iter = data; |
| 4359 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4360 | |
| 4361 | if (arvif->vdev_id == arvif_iter->vdev_id) |
| 4362 | arvif_iter->arvif = arvif; |
| 4363 | } |
| 4364 | |
| 4365 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) |
| 4366 | { |
| 4367 | struct ath10k_vif_iter arvif_iter; |
| 4368 | u32 flags; |
| 4369 | |
| 4370 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); |
| 4371 | arvif_iter.vdev_id = vdev_id; |
| 4372 | |
| 4373 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; |
| 4374 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 4375 | flags, |
| 4376 | ath10k_get_arvif_iter, |
| 4377 | &arvif_iter); |
| 4378 | if (!arvif_iter.arvif) { |
| 4379 | ath10k_warn("No VIF found for VDEV: %d\n", vdev_id); |
| 4380 | return NULL; |
| 4381 | } |
| 4382 | |
| 4383 | return arvif_iter.arvif; |
| 4384 | } |
| 4385 | |
| 4386 | int ath10k_mac_register(struct ath10k *ar) |
| 4387 | { |
| 4388 | struct ieee80211_supported_band *band; |
| 4389 | struct ieee80211_sta_vht_cap vht_cap; |
| 4390 | struct ieee80211_sta_ht_cap ht_cap; |
| 4391 | void *channels; |
| 4392 | int ret; |
| 4393 | |
| 4394 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); |
| 4395 | |
| 4396 | SET_IEEE80211_DEV(ar->hw, ar->dev); |
| 4397 | |
| 4398 | ht_cap = ath10k_get_ht_cap(ar); |
| 4399 | vht_cap = ath10k_create_vht_cap(ar); |
| 4400 | |
| 4401 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
| 4402 | channels = kmemdup(ath10k_2ghz_channels, |
| 4403 | sizeof(ath10k_2ghz_channels), |
| 4404 | GFP_KERNEL); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4405 | if (!channels) { |
| 4406 | ret = -ENOMEM; |
| 4407 | goto err_free; |
| 4408 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4409 | |
| 4410 | band = &ar->mac.sbands[IEEE80211_BAND_2GHZ]; |
| 4411 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); |
| 4412 | band->channels = channels; |
| 4413 | band->n_bitrates = ath10k_g_rates_size; |
| 4414 | band->bitrates = ath10k_g_rates; |
| 4415 | band->ht_cap = ht_cap; |
| 4416 | |
| 4417 | /* vht is not supported in 2.4 GHz */ |
| 4418 | |
| 4419 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band; |
| 4420 | } |
| 4421 | |
| 4422 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { |
| 4423 | channels = kmemdup(ath10k_5ghz_channels, |
| 4424 | sizeof(ath10k_5ghz_channels), |
| 4425 | GFP_KERNEL); |
| 4426 | if (!channels) { |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4427 | ret = -ENOMEM; |
| 4428 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | band = &ar->mac.sbands[IEEE80211_BAND_5GHZ]; |
| 4432 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); |
| 4433 | band->channels = channels; |
| 4434 | band->n_bitrates = ath10k_a_rates_size; |
| 4435 | band->bitrates = ath10k_a_rates; |
| 4436 | band->ht_cap = ht_cap; |
| 4437 | band->vht_cap = vht_cap; |
| 4438 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band; |
| 4439 | } |
| 4440 | |
| 4441 | ar->hw->wiphy->interface_modes = |
| 4442 | BIT(NL80211_IFTYPE_STATION) | |
| 4443 | BIT(NL80211_IFTYPE_ADHOC) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 4444 | BIT(NL80211_IFTYPE_AP); |
| 4445 | |
| 4446 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features)) |
| 4447 | ar->hw->wiphy->interface_modes |= |
| 4448 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 4449 | BIT(NL80211_IFTYPE_P2P_GO); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4450 | |
| 4451 | ar->hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 4452 | IEEE80211_HW_SUPPORTS_PS | |
| 4453 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS | |
| 4454 | IEEE80211_HW_SUPPORTS_UAPSD | |
| 4455 | IEEE80211_HW_MFP_CAPABLE | |
| 4456 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | |
| 4457 | IEEE80211_HW_HAS_RATE_CONTROL | |
| 4458 | IEEE80211_HW_SUPPORTS_STATIC_SMPS | |
| 4459 | IEEE80211_HW_WANT_MONITOR_VIF | |
| 4460 | IEEE80211_HW_AP_LINK_PS; |
| 4461 | |
Michal Kazior | 1f8bb15 | 2013-09-18 14:43:22 +0200 | [diff] [blame] | 4462 | /* MSDU can have HTT TX fragment pushed in front. The additional 4 |
| 4463 | * bytes is used for padding/alignment if necessary. */ |
| 4464 | ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4; |
| 4465 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4466 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
| 4467 | ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS; |
| 4468 | |
| 4469 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { |
| 4470 | ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION; |
| 4471 | ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW; |
| 4472 | } |
| 4473 | |
| 4474 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
| 4475 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; |
| 4476 | |
| 4477 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4478 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4479 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4480 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
| 4481 | |
| 4482 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 4483 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4484 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 4485 | |
| 4486 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
| 4487 | /* |
| 4488 | * on LL hardware queues are managed entirely by the FW |
| 4489 | * so we only advertise to mac we can do the queues thing |
| 4490 | */ |
| 4491 | ar->hw->queues = 4; |
| 4492 | |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 4493 | if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) { |
| 4494 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
| 4495 | ar->hw->wiphy->n_iface_combinations = |
| 4496 | ARRAY_SIZE(ath10k_10x_if_comb); |
| 4497 | } else { |
| 4498 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
| 4499 | ar->hw->wiphy->n_iface_combinations = |
| 4500 | ARRAY_SIZE(ath10k_if_comb); |
| 4501 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4502 | |
Michal Kazior | 7c19999 | 2013-07-31 10:47:57 +0200 | [diff] [blame] | 4503 | ar->hw->netdev_features = NETIF_F_HW_CSUM; |
| 4504 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 4505 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
| 4506 | /* Init ath dfs pattern detector */ |
| 4507 | ar->ath_common.debug_mask = ATH_DBG_DFS; |
| 4508 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, |
| 4509 | NL80211_DFS_UNSET); |
| 4510 | |
| 4511 | if (!ar->dfs_detector) |
| 4512 | ath10k_warn("dfs pattern detector init failed\n"); |
| 4513 | } |
| 4514 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4515 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
| 4516 | ath10k_reg_notifier); |
| 4517 | if (ret) { |
| 4518 | ath10k_err("Regulatory initialization failed\n"); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4519 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4520 | } |
| 4521 | |
| 4522 | ret = ieee80211_register_hw(ar->hw); |
| 4523 | if (ret) { |
| 4524 | ath10k_err("ieee80211 registration failed: %d\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4525 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { |
| 4529 | ret = regulatory_hint(ar->hw->wiphy, |
| 4530 | ar->ath_common.regulatory.alpha2); |
| 4531 | if (ret) |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4532 | goto err_unregister; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | return 0; |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4536 | |
| 4537 | err_unregister: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4538 | ieee80211_unregister_hw(ar->hw); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 4539 | err_free: |
| 4540 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 4541 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 4542 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4543 | return ret; |
| 4544 | } |
| 4545 | |
| 4546 | void ath10k_mac_unregister(struct ath10k *ar) |
| 4547 | { |
| 4548 | ieee80211_unregister_hw(ar->hw); |
| 4549 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 4550 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
| 4551 | ar->dfs_detector->exit(ar->dfs_detector); |
| 4552 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4553 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 4554 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 4555 | |
| 4556 | SET_IEEE80211_DEV(ar->hw, NULL); |
| 4557 | } |