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