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