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