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