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