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