Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
| 3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. |
| 4 | * |
| 5 | * Permission to use, copy, modify, and/or distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | #include "mac.h" |
| 19 | |
| 20 | #include <net/mac80211.h> |
| 21 | #include <linux/etherdevice.h> |
| 22 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 23 | #include "hif.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 24 | #include "core.h" |
| 25 | #include "debug.h" |
| 26 | #include "wmi.h" |
| 27 | #include "htt.h" |
| 28 | #include "txrx.h" |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 29 | #include "testmode.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 30 | #include "wmi.h" |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 31 | #include "wmi-tlv.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 32 | #include "wmi-ops.h" |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 33 | #include "wow.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 34 | |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 35 | /*********/ |
| 36 | /* Rates */ |
| 37 | /*********/ |
| 38 | |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 39 | static struct ieee80211_rate ath10k_rates[] = { |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 40 | { .bitrate = 10, |
| 41 | .hw_value = ATH10K_HW_RATE_CCK_LP_1M }, |
| 42 | { .bitrate = 20, |
| 43 | .hw_value = ATH10K_HW_RATE_CCK_LP_2M, |
| 44 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M, |
| 45 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 46 | { .bitrate = 55, |
| 47 | .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M, |
| 48 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M, |
| 49 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 50 | { .bitrate = 110, |
| 51 | .hw_value = ATH10K_HW_RATE_CCK_LP_11M, |
| 52 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M, |
| 53 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
Michal Kazior | 5653b39 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 54 | |
Michal Kazior | af00148 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 55 | { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M }, |
| 56 | { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M }, |
| 57 | { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M }, |
| 58 | { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M }, |
| 59 | { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M }, |
| 60 | { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M }, |
| 61 | { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M }, |
| 62 | { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M }, |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 63 | }; |
| 64 | |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 65 | #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4 |
| 66 | |
| 67 | #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX) |
| 68 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \ |
| 69 | ATH10K_MAC_FIRST_OFDM_RATE_IDX) |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 70 | #define ath10k_g_rates (ath10k_rates + 0) |
| 71 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) |
| 72 | |
Michal Kazior | 486017c | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 73 | static bool ath10k_mac_bitrate_is_cck(int bitrate) |
| 74 | { |
| 75 | switch (bitrate) { |
| 76 | case 10: |
| 77 | case 20: |
| 78 | case 55: |
| 79 | case 110: |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | static u8 ath10k_mac_bitrate_to_rate(int bitrate) |
| 87 | { |
| 88 | return DIV_ROUND_UP(bitrate, 5) | |
| 89 | (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); |
| 90 | } |
| 91 | |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 92 | u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, |
| 93 | u8 hw_rate) |
| 94 | { |
| 95 | const struct ieee80211_rate *rate; |
| 96 | int i; |
| 97 | |
| 98 | for (i = 0; i < sband->n_bitrates; i++) { |
| 99 | rate = &sband->bitrates[i]; |
| 100 | |
| 101 | if (rate->hw_value == hw_rate) |
| 102 | return i; |
| 103 | else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && |
| 104 | rate->hw_value_short == hw_rate) |
| 105 | return i; |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Michal Kazior | 01cebe1 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 111 | u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, |
| 112 | u32 bitrate) |
| 113 | { |
| 114 | int i; |
| 115 | |
| 116 | for (i = 0; i < sband->n_bitrates; i++) |
| 117 | if (sband->bitrates[i].bitrate == bitrate) |
| 118 | return i; |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 123 | static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) |
| 124 | { |
| 125 | switch ((mcs_map >> (2 * nss)) & 0x3) { |
| 126 | case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; |
| 127 | case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; |
| 128 | case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; |
| 129 | } |
| 130 | return 0; |
| 131 | } |
| 132 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 133 | static u32 |
| 134 | ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) |
| 135 | { |
| 136 | int nss; |
| 137 | |
| 138 | for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) |
| 139 | if (ht_mcs_mask[nss]) |
| 140 | return nss + 1; |
| 141 | |
| 142 | return 1; |
| 143 | } |
| 144 | |
| 145 | static u32 |
| 146 | ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 147 | { |
| 148 | int nss; |
| 149 | |
| 150 | for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) |
| 151 | if (vht_mcs_mask[nss]) |
| 152 | return nss + 1; |
| 153 | |
| 154 | return 1; |
| 155 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 156 | |
| 157 | /**********/ |
| 158 | /* Crypto */ |
| 159 | /**********/ |
| 160 | |
| 161 | static int ath10k_send_key(struct ath10k_vif *arvif, |
| 162 | struct ieee80211_key_conf *key, |
| 163 | enum set_key_cmd cmd, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 164 | const u8 *macaddr, u32 flags) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 165 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 166 | struct ath10k *ar = arvif->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 167 | struct wmi_vdev_install_key_arg arg = { |
| 168 | .vdev_id = arvif->vdev_id, |
| 169 | .key_idx = key->keyidx, |
| 170 | .key_len = key->keylen, |
| 171 | .key_data = key->key, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 172 | .key_flags = flags, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 173 | .macaddr = macaddr, |
| 174 | }; |
| 175 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 176 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 177 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 178 | switch (key->cipher) { |
| 179 | case WLAN_CIPHER_SUITE_CCMP: |
| 180 | arg.key_cipher = WMI_CIPHER_AES_CCM; |
Marek Kwaczynski | e4e82e9 | 2015-01-24 12:14:53 +0200 | [diff] [blame] | 181 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 182 | break; |
| 183 | case WLAN_CIPHER_SUITE_TKIP: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 184 | arg.key_cipher = WMI_CIPHER_TKIP; |
| 185 | arg.key_txmic_len = 8; |
| 186 | arg.key_rxmic_len = 8; |
| 187 | break; |
| 188 | case WLAN_CIPHER_SUITE_WEP40: |
| 189 | case WLAN_CIPHER_SUITE_WEP104: |
| 190 | arg.key_cipher = WMI_CIPHER_WEP; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 191 | break; |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 192 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 193 | WARN_ON(1); |
| 194 | return -EINVAL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 195 | default: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 196 | ath10k_warn(ar, "cipher %d is not supported\n", key->cipher); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 197 | return -EOPNOTSUPP; |
| 198 | } |
| 199 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 200 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
| 201 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 202 | } |
| 203 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 204 | if (cmd == DISABLE_KEY) { |
| 205 | arg.key_cipher = WMI_CIPHER_NONE; |
| 206 | arg.key_data = NULL; |
| 207 | } |
| 208 | |
| 209 | return ath10k_wmi_vdev_install_key(arvif->ar, &arg); |
| 210 | } |
| 211 | |
| 212 | static int ath10k_install_key(struct ath10k_vif *arvif, |
| 213 | struct ieee80211_key_conf *key, |
| 214 | enum set_key_cmd cmd, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 215 | const u8 *macaddr, u32 flags) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 216 | { |
| 217 | struct ath10k *ar = arvif->ar; |
| 218 | int ret; |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 219 | unsigned long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 220 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 221 | lockdep_assert_held(&ar->conf_mutex); |
| 222 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 223 | reinit_completion(&ar->install_key_done); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 224 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 225 | if (arvif->nohwcrypt) |
| 226 | return 1; |
| 227 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 228 | ret = ath10k_send_key(arvif, key, cmd, macaddr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 229 | if (ret) |
| 230 | return ret; |
| 231 | |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 232 | time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ); |
| 233 | if (time_left == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 234 | return -ETIMEDOUT; |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif, |
| 240 | const u8 *addr) |
| 241 | { |
| 242 | struct ath10k *ar = arvif->ar; |
| 243 | struct ath10k_peer *peer; |
| 244 | int ret; |
| 245 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 246 | u32 flags; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 247 | |
| 248 | lockdep_assert_held(&ar->conf_mutex); |
| 249 | |
| 250 | spin_lock_bh(&ar->data_lock); |
| 251 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 252 | spin_unlock_bh(&ar->data_lock); |
| 253 | |
| 254 | if (!peer) |
| 255 | return -ENOENT; |
| 256 | |
| 257 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { |
| 258 | if (arvif->wep_keys[i] == NULL) |
| 259 | continue; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 260 | |
| 261 | flags = 0; |
| 262 | flags |= WMI_KEY_PAIRWISE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 263 | |
| 264 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY, |
Michal Kazior | ce90b27 | 2015-04-10 13:23:21 +0000 | [diff] [blame] | 265 | addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 266 | if (ret < 0) |
Michal Kazior | ce90b27 | 2015-04-10 13:23:21 +0000 | [diff] [blame] | 267 | return ret; |
| 268 | |
| 269 | flags = 0; |
| 270 | flags |= WMI_KEY_GROUP; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 271 | |
| 272 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 273 | addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 274 | if (ret < 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 275 | return ret; |
| 276 | |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 277 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 278 | peer->keys[i] = arvif->wep_keys[i]; |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 279 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 280 | } |
| 281 | |
Michal Kazior | ce90b27 | 2015-04-10 13:23:21 +0000 | [diff] [blame] | 282 | /* In some cases (notably with static WEP IBSS with multiple keys) |
| 283 | * multicast Tx becomes broken. Both pairwise and groupwise keys are |
| 284 | * installed already. Using WMI_KEY_TX_USAGE in different combinations |
| 285 | * didn't seem help. Using def_keyid vdev parameter seems to be |
| 286 | * effective so use that. |
| 287 | * |
| 288 | * FIXME: Revisit. Perhaps this can be done in a less hacky way. |
| 289 | */ |
| 290 | if (arvif->def_wep_key_idx == -1) |
| 291 | return 0; |
| 292 | |
| 293 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 294 | arvif->vdev_id, |
| 295 | arvif->ar->wmi.vdev_param->def_keyid, |
| 296 | arvif->def_wep_key_idx); |
| 297 | if (ret) { |
| 298 | ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n", |
| 299 | arvif->vdev_id, ret); |
| 300 | return ret; |
| 301 | } |
| 302 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int ath10k_clear_peer_keys(struct ath10k_vif *arvif, |
| 307 | const u8 *addr) |
| 308 | { |
| 309 | struct ath10k *ar = arvif->ar; |
| 310 | struct ath10k_peer *peer; |
| 311 | int first_errno = 0; |
| 312 | int ret; |
| 313 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 314 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 315 | |
| 316 | lockdep_assert_held(&ar->conf_mutex); |
| 317 | |
| 318 | spin_lock_bh(&ar->data_lock); |
| 319 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 320 | spin_unlock_bh(&ar->data_lock); |
| 321 | |
| 322 | if (!peer) |
| 323 | return -ENOENT; |
| 324 | |
| 325 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 326 | if (peer->keys[i] == NULL) |
| 327 | continue; |
| 328 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 329 | /* key flags are not required to delete the key */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 330 | ret = ath10k_install_key(arvif, peer->keys[i], |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 331 | DISABLE_KEY, addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 332 | if (ret < 0 && first_errno == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 333 | first_errno = ret; |
| 334 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 335 | if (ret < 0) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 336 | ath10k_warn(ar, "failed to remove peer wep key %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 337 | i, ret); |
| 338 | |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 339 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 340 | peer->keys[i] = NULL; |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 341 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | return first_errno; |
| 345 | } |
| 346 | |
Sujith Manoharan | 504f6cd | 2014-11-25 11:46:58 +0530 | [diff] [blame] | 347 | bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr, |
| 348 | u8 keyidx) |
| 349 | { |
| 350 | struct ath10k_peer *peer; |
| 351 | int i; |
| 352 | |
| 353 | lockdep_assert_held(&ar->data_lock); |
| 354 | |
| 355 | /* We don't know which vdev this peer belongs to, |
| 356 | * since WMI doesn't give us that information. |
| 357 | * |
| 358 | * FIXME: multi-bss needs to be handled. |
| 359 | */ |
| 360 | peer = ath10k_peer_find(ar, 0, addr); |
| 361 | if (!peer) |
| 362 | return false; |
| 363 | |
| 364 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 365 | if (peer->keys[i] && peer->keys[i]->keyidx == keyidx) |
| 366 | return true; |
| 367 | } |
| 368 | |
| 369 | return false; |
| 370 | } |
| 371 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 372 | static int ath10k_clear_vdev_key(struct ath10k_vif *arvif, |
| 373 | struct ieee80211_key_conf *key) |
| 374 | { |
| 375 | struct ath10k *ar = arvif->ar; |
| 376 | struct ath10k_peer *peer; |
| 377 | u8 addr[ETH_ALEN]; |
| 378 | int first_errno = 0; |
| 379 | int ret; |
| 380 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 381 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 382 | |
| 383 | lockdep_assert_held(&ar->conf_mutex); |
| 384 | |
| 385 | for (;;) { |
| 386 | /* since ath10k_install_key we can't hold data_lock all the |
| 387 | * time, so we try to remove the keys incrementally */ |
| 388 | spin_lock_bh(&ar->data_lock); |
| 389 | i = 0; |
| 390 | list_for_each_entry(peer, &ar->peers, list) { |
| 391 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 392 | if (peer->keys[i] == key) { |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 393 | ether_addr_copy(addr, peer->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 394 | peer->keys[i] = NULL; |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | if (i < ARRAY_SIZE(peer->keys)) |
| 400 | break; |
| 401 | } |
| 402 | spin_unlock_bh(&ar->data_lock); |
| 403 | |
| 404 | if (i == ARRAY_SIZE(peer->keys)) |
| 405 | break; |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 406 | /* key flags are not required to delete the key */ |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 407 | ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 408 | if (ret < 0 && first_errno == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 409 | first_errno = ret; |
| 410 | |
| 411 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 412 | ath10k_warn(ar, "failed to remove key for %pM: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 413 | addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | return first_errno; |
| 417 | } |
| 418 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 419 | static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif, |
| 420 | struct ieee80211_key_conf *key) |
| 421 | { |
| 422 | struct ath10k *ar = arvif->ar; |
| 423 | struct ath10k_peer *peer; |
| 424 | int ret; |
| 425 | |
| 426 | lockdep_assert_held(&ar->conf_mutex); |
| 427 | |
| 428 | list_for_each_entry(peer, &ar->peers, list) { |
| 429 | if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN)) |
| 430 | continue; |
| 431 | |
| 432 | if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN)) |
| 433 | continue; |
| 434 | |
| 435 | if (peer->keys[key->keyidx] == key) |
| 436 | continue; |
| 437 | |
| 438 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n", |
| 439 | arvif->vdev_id, key->keyidx); |
| 440 | |
| 441 | ret = ath10k_install_peer_wep_keys(arvif, peer->addr); |
| 442 | if (ret) { |
| 443 | ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n", |
| 444 | arvif->vdev_id, peer->addr, ret); |
| 445 | return ret; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 452 | /*********************/ |
| 453 | /* General utilities */ |
| 454 | /*********************/ |
| 455 | |
| 456 | static inline enum wmi_phy_mode |
| 457 | chan_to_phymode(const struct cfg80211_chan_def *chandef) |
| 458 | { |
| 459 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 460 | |
| 461 | switch (chandef->chan->band) { |
| 462 | case IEEE80211_BAND_2GHZ: |
| 463 | switch (chandef->width) { |
| 464 | case NL80211_CHAN_WIDTH_20_NOHT: |
Peter Oh | 6faab12 | 2014-12-18 10:13:00 -0800 | [diff] [blame] | 465 | if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM) |
| 466 | phymode = MODE_11B; |
| 467 | else |
| 468 | phymode = MODE_11G; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 469 | break; |
| 470 | case NL80211_CHAN_WIDTH_20: |
| 471 | phymode = MODE_11NG_HT20; |
| 472 | break; |
| 473 | case NL80211_CHAN_WIDTH_40: |
| 474 | phymode = MODE_11NG_HT40; |
| 475 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 476 | case NL80211_CHAN_WIDTH_5: |
| 477 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 478 | case NL80211_CHAN_WIDTH_80: |
| 479 | case NL80211_CHAN_WIDTH_80P80: |
| 480 | case NL80211_CHAN_WIDTH_160: |
| 481 | phymode = MODE_UNKNOWN; |
| 482 | break; |
| 483 | } |
| 484 | break; |
| 485 | case IEEE80211_BAND_5GHZ: |
| 486 | switch (chandef->width) { |
| 487 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 488 | phymode = MODE_11A; |
| 489 | break; |
| 490 | case NL80211_CHAN_WIDTH_20: |
| 491 | phymode = MODE_11NA_HT20; |
| 492 | break; |
| 493 | case NL80211_CHAN_WIDTH_40: |
| 494 | phymode = MODE_11NA_HT40; |
| 495 | break; |
| 496 | case NL80211_CHAN_WIDTH_80: |
| 497 | phymode = MODE_11AC_VHT80; |
| 498 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 499 | case NL80211_CHAN_WIDTH_5: |
| 500 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 501 | case NL80211_CHAN_WIDTH_80P80: |
| 502 | case NL80211_CHAN_WIDTH_160: |
| 503 | phymode = MODE_UNKNOWN; |
| 504 | break; |
| 505 | } |
| 506 | break; |
| 507 | default: |
| 508 | break; |
| 509 | } |
| 510 | |
| 511 | WARN_ON(phymode == MODE_UNKNOWN); |
| 512 | return phymode; |
| 513 | } |
| 514 | |
| 515 | static u8 ath10k_parse_mpdudensity(u8 mpdudensity) |
| 516 | { |
| 517 | /* |
| 518 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 519 | * 0 for no restriction |
| 520 | * 1 for 1/4 us |
| 521 | * 2 for 1/2 us |
| 522 | * 3 for 1 us |
| 523 | * 4 for 2 us |
| 524 | * 5 for 4 us |
| 525 | * 6 for 8 us |
| 526 | * 7 for 16 us |
| 527 | */ |
| 528 | switch (mpdudensity) { |
| 529 | case 0: |
| 530 | return 0; |
| 531 | case 1: |
| 532 | case 2: |
| 533 | case 3: |
| 534 | /* Our lower layer calculations limit our precision to |
| 535 | 1 microsecond */ |
| 536 | return 1; |
| 537 | case 4: |
| 538 | return 2; |
| 539 | case 5: |
| 540 | return 4; |
| 541 | case 6: |
| 542 | return 8; |
| 543 | case 7: |
| 544 | return 16; |
| 545 | default: |
| 546 | return 0; |
| 547 | } |
| 548 | } |
| 549 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 550 | int ath10k_mac_vif_chan(struct ieee80211_vif *vif, |
| 551 | struct cfg80211_chan_def *def) |
| 552 | { |
| 553 | struct ieee80211_chanctx_conf *conf; |
| 554 | |
| 555 | rcu_read_lock(); |
| 556 | conf = rcu_dereference(vif->chanctx_conf); |
| 557 | if (!conf) { |
| 558 | rcu_read_unlock(); |
| 559 | return -ENOENT; |
| 560 | } |
| 561 | |
| 562 | *def = conf->def; |
| 563 | rcu_read_unlock(); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw, |
| 569 | struct ieee80211_chanctx_conf *conf, |
| 570 | void *data) |
| 571 | { |
| 572 | int *num = data; |
| 573 | |
| 574 | (*num)++; |
| 575 | } |
| 576 | |
| 577 | static int ath10k_mac_num_chanctxs(struct ath10k *ar) |
| 578 | { |
| 579 | int num = 0; |
| 580 | |
| 581 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 582 | ath10k_mac_num_chanctxs_iter, |
| 583 | &num); |
| 584 | |
| 585 | return num; |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw, |
| 590 | struct ieee80211_chanctx_conf *conf, |
| 591 | void *data) |
| 592 | { |
| 593 | struct cfg80211_chan_def **def = data; |
| 594 | |
| 595 | *def = &conf->def; |
| 596 | } |
| 597 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 598 | static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr, |
| 599 | enum wmi_peer_type peer_type) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 600 | { |
| 601 | int ret; |
| 602 | |
| 603 | lockdep_assert_held(&ar->conf_mutex); |
| 604 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 605 | if (ar->num_peers >= ar->max_num_peers) |
| 606 | return -ENOBUFS; |
| 607 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 608 | ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 609 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 610 | 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] | 611 | addr, vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 612 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 613 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 614 | |
| 615 | ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 616 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 617 | 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] | 618 | addr, vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 619 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 620 | } |
Michal Kazior | 292a753 | 2014-11-25 15:16:04 +0100 | [diff] [blame] | 621 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 622 | ar->num_peers++; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 623 | |
| 624 | return 0; |
| 625 | } |
| 626 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 627 | static int ath10k_mac_set_kickout(struct ath10k_vif *arvif) |
| 628 | { |
| 629 | struct ath10k *ar = arvif->ar; |
| 630 | u32 param; |
| 631 | int ret; |
| 632 | |
| 633 | param = ar->wmi.pdev_param->sta_kickout_th; |
| 634 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 635 | ATH10K_KICKOUT_THRESHOLD); |
| 636 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 637 | 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] | 638 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs; |
| 643 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 644 | ATH10K_KEEPALIVE_MIN_IDLE); |
| 645 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 646 | 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] | 647 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs; |
| 652 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 653 | ATH10K_KEEPALIVE_MAX_IDLE); |
| 654 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 655 | 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] | 656 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 657 | return ret; |
| 658 | } |
| 659 | |
| 660 | param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs; |
| 661 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 662 | ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); |
| 663 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 664 | 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] | 665 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 666 | return ret; |
| 667 | } |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Vivek Natarajan | acab640 | 2014-11-26 09:06:12 +0200 | [diff] [blame] | 672 | static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value) |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 673 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 674 | struct ath10k *ar = arvif->ar; |
| 675 | u32 vdev_param; |
| 676 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 677 | vdev_param = ar->wmi.vdev_param->rts_threshold; |
| 678 | 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] | 679 | } |
| 680 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 681 | static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
| 682 | { |
| 683 | int ret; |
| 684 | |
| 685 | lockdep_assert_held(&ar->conf_mutex); |
| 686 | |
| 687 | ret = ath10k_wmi_peer_delete(ar, vdev_id, addr); |
| 688 | if (ret) |
| 689 | return ret; |
| 690 | |
| 691 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); |
| 692 | if (ret) |
| 693 | return ret; |
| 694 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 695 | ar->num_peers--; |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 696 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id) |
| 701 | { |
| 702 | struct ath10k_peer *peer, *tmp; |
| 703 | |
| 704 | lockdep_assert_held(&ar->conf_mutex); |
| 705 | |
| 706 | spin_lock_bh(&ar->data_lock); |
| 707 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 708 | if (peer->vdev_id != vdev_id) |
| 709 | continue; |
| 710 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 711 | ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 712 | peer->addr, vdev_id); |
| 713 | |
| 714 | list_del(&peer->list); |
| 715 | kfree(peer); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 716 | ar->num_peers--; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 717 | } |
| 718 | spin_unlock_bh(&ar->data_lock); |
| 719 | } |
| 720 | |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 721 | static void ath10k_peer_cleanup_all(struct ath10k *ar) |
| 722 | { |
| 723 | struct ath10k_peer *peer, *tmp; |
| 724 | |
| 725 | lockdep_assert_held(&ar->conf_mutex); |
| 726 | |
| 727 | spin_lock_bh(&ar->data_lock); |
| 728 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 729 | list_del(&peer->list); |
| 730 | kfree(peer); |
| 731 | } |
| 732 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | 292a753 | 2014-11-25 15:16:04 +0100 | [diff] [blame] | 733 | |
| 734 | ar->num_peers = 0; |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 735 | ar->num_stations = 0; |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 736 | } |
| 737 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 738 | static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id, |
| 739 | struct ieee80211_sta *sta, |
| 740 | enum wmi_tdls_peer_state state) |
| 741 | { |
| 742 | int ret; |
| 743 | struct wmi_tdls_peer_update_cmd_arg arg = {}; |
| 744 | struct wmi_tdls_peer_capab_arg cap = {}; |
| 745 | struct wmi_channel_arg chan_arg = {}; |
| 746 | |
| 747 | lockdep_assert_held(&ar->conf_mutex); |
| 748 | |
| 749 | arg.vdev_id = vdev_id; |
| 750 | arg.peer_state = state; |
| 751 | ether_addr_copy(arg.addr, sta->addr); |
| 752 | |
| 753 | cap.peer_max_sp = sta->max_sp; |
| 754 | cap.peer_uapsd_queues = sta->uapsd_queues; |
| 755 | |
| 756 | if (state == WMI_TDLS_PEER_STATE_CONNECTED && |
| 757 | !sta->tdls_initiator) |
| 758 | cap.is_peer_responder = 1; |
| 759 | |
| 760 | ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg); |
| 761 | if (ret) { |
| 762 | ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n", |
| 763 | arg.addr, vdev_id, ret); |
| 764 | return ret; |
| 765 | } |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 770 | /************************/ |
| 771 | /* Interface management */ |
| 772 | /************************/ |
| 773 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 774 | void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif) |
| 775 | { |
| 776 | struct ath10k *ar = arvif->ar; |
| 777 | |
| 778 | lockdep_assert_held(&ar->data_lock); |
| 779 | |
| 780 | if (!arvif->beacon) |
| 781 | return; |
| 782 | |
| 783 | if (!arvif->beacon_buf) |
| 784 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr, |
| 785 | arvif->beacon->len, DMA_TO_DEVICE); |
| 786 | |
Michal Kazior | af21319 | 2015-01-29 14:29:52 +0200 | [diff] [blame] | 787 | if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED && |
| 788 | arvif->beacon_state != ATH10K_BEACON_SENT)) |
| 789 | return; |
| 790 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 791 | dev_kfree_skb_any(arvif->beacon); |
| 792 | |
| 793 | arvif->beacon = NULL; |
Michal Kazior | af21319 | 2015-01-29 14:29:52 +0200 | [diff] [blame] | 794 | arvif->beacon_state = ATH10K_BEACON_SCHEDULED; |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif) |
| 798 | { |
| 799 | struct ath10k *ar = arvif->ar; |
| 800 | |
| 801 | lockdep_assert_held(&ar->data_lock); |
| 802 | |
| 803 | ath10k_mac_vif_beacon_free(arvif); |
| 804 | |
| 805 | if (arvif->beacon_buf) { |
| 806 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 807 | arvif->beacon_buf, arvif->beacon_paddr); |
| 808 | arvif->beacon_buf = NULL; |
| 809 | } |
| 810 | } |
| 811 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 812 | static inline int ath10k_vdev_setup_sync(struct ath10k *ar) |
| 813 | { |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 814 | unsigned long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 815 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 816 | lockdep_assert_held(&ar->conf_mutex); |
| 817 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 818 | if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) |
| 819 | return -ESHUTDOWN; |
| 820 | |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 821 | time_left = wait_for_completion_timeout(&ar->vdev_setup_done, |
| 822 | ATH10K_VDEV_SETUP_TIMEOUT_HZ); |
| 823 | if (time_left == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 824 | return -ETIMEDOUT; |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 829 | static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 830 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 831 | struct cfg80211_chan_def *chandef = NULL; |
Maninder Singh | 19be9e9 | 2015-07-16 09:25:33 +0530 | [diff] [blame] | 832 | struct ieee80211_channel *channel = NULL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 833 | struct wmi_vdev_start_request_arg arg = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 834 | int ret = 0; |
| 835 | |
| 836 | lockdep_assert_held(&ar->conf_mutex); |
| 837 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 838 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 839 | ath10k_mac_get_any_chandef_iter, |
| 840 | &chandef); |
| 841 | if (WARN_ON_ONCE(!chandef)) |
| 842 | return -ENOENT; |
| 843 | |
| 844 | channel = chandef->chan; |
| 845 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 846 | arg.vdev_id = vdev_id; |
| 847 | arg.channel.freq = channel->center_freq; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 848 | arg.channel.band_center_freq1 = chandef->center_freq1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 849 | |
| 850 | /* TODO setup this dynamically, what in case we |
| 851 | don't have any vifs? */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 852 | arg.channel.mode = chan_to_phymode(chandef); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 853 | arg.channel.chan_radar = |
| 854 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 855 | |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 856 | arg.channel.min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 857 | arg.channel.max_power = channel->max_power * 2; |
| 858 | arg.channel.max_reg_power = channel->max_reg_power * 2; |
| 859 | arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 860 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 861 | reinit_completion(&ar->vdev_setup_done); |
| 862 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 863 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 864 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 865 | ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 866 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 867 | return ret; |
| 868 | } |
| 869 | |
| 870 | ret = ath10k_vdev_setup_sync(ar); |
| 871 | if (ret) { |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 872 | ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 873 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); |
| 878 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 879 | ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 880 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 881 | goto vdev_stop; |
| 882 | } |
| 883 | |
| 884 | ar->monitor_vdev_id = vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 885 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 886 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n", |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 887 | ar->monitor_vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 888 | return 0; |
| 889 | |
| 890 | vdev_stop: |
| 891 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 892 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 893 | 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] | 894 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 895 | |
| 896 | return ret; |
| 897 | } |
| 898 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 899 | static int ath10k_monitor_vdev_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 900 | { |
| 901 | int ret = 0; |
| 902 | |
| 903 | lockdep_assert_held(&ar->conf_mutex); |
| 904 | |
Marek Puzyniak | 52fa019 | 2013-09-24 14:06:24 +0200 | [diff] [blame] | 905 | ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
| 906 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 907 | ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 908 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 909 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 910 | reinit_completion(&ar->vdev_setup_done); |
| 911 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 912 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 913 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 914 | 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] | 915 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 916 | |
| 917 | ret = ath10k_vdev_setup_sync(ar); |
| 918 | if (ret) |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 919 | ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 920 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 921 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 922 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n", |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 923 | ar->monitor_vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 924 | return ret; |
| 925 | } |
| 926 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 927 | static int ath10k_monitor_vdev_create(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 928 | { |
| 929 | int bit, ret = 0; |
| 930 | |
| 931 | lockdep_assert_held(&ar->conf_mutex); |
| 932 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 933 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 934 | 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] | 935 | return -ENOMEM; |
| 936 | } |
| 937 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 938 | bit = __ffs64(ar->free_vdev_map); |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 939 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 940 | ar->monitor_vdev_id = bit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 941 | |
| 942 | ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, |
| 943 | WMI_VDEV_TYPE_MONITOR, |
| 944 | 0, ar->mac_addr); |
| 945 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 946 | ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 947 | ar->monitor_vdev_id, ret); |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 948 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 949 | } |
| 950 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 951 | ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 952 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 953 | ar->monitor_vdev_id); |
| 954 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 955 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 956 | } |
| 957 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 958 | static int ath10k_monitor_vdev_delete(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 959 | { |
| 960 | int ret = 0; |
| 961 | |
| 962 | lockdep_assert_held(&ar->conf_mutex); |
| 963 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 964 | ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
| 965 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 966 | 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] | 967 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 968 | return ret; |
| 969 | } |
| 970 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 971 | ar->free_vdev_map |= 1LL << ar->monitor_vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 972 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 973 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 974 | ar->monitor_vdev_id); |
| 975 | return ret; |
| 976 | } |
| 977 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 978 | static int ath10k_monitor_start(struct ath10k *ar) |
| 979 | { |
| 980 | int ret; |
| 981 | |
| 982 | lockdep_assert_held(&ar->conf_mutex); |
| 983 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 984 | ret = ath10k_monitor_vdev_create(ar); |
| 985 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 986 | ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 987 | return ret; |
| 988 | } |
| 989 | |
| 990 | ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id); |
| 991 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 992 | ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 993 | ath10k_monitor_vdev_delete(ar); |
| 994 | return ret; |
| 995 | } |
| 996 | |
| 997 | ar->monitor_started = true; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 998 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n"); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1003 | static int ath10k_monitor_stop(struct ath10k *ar) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1004 | { |
| 1005 | int ret; |
| 1006 | |
| 1007 | lockdep_assert_held(&ar->conf_mutex); |
| 1008 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1009 | ret = ath10k_monitor_vdev_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1010 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1011 | ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1012 | return ret; |
| 1013 | } |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1014 | |
| 1015 | ret = ath10k_monitor_vdev_delete(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1016 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1017 | ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1018 | return ret; |
| 1019 | } |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1020 | |
| 1021 | ar->monitor_started = false; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1022 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n"); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1027 | static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar) |
| 1028 | { |
| 1029 | int num_ctx; |
| 1030 | |
| 1031 | /* At least one chanctx is required to derive a channel to start |
| 1032 | * monitor vdev on. |
| 1033 | */ |
| 1034 | num_ctx = ath10k_mac_num_chanctxs(ar); |
| 1035 | if (num_ctx == 0) |
| 1036 | return false; |
| 1037 | |
| 1038 | /* If there's already an existing special monitor interface then don't |
| 1039 | * bother creating another monitor vdev. |
| 1040 | */ |
| 1041 | if (ar->monitor_arvif) |
| 1042 | return false; |
| 1043 | |
| 1044 | return ar->monitor || |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1045 | test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 1046 | } |
| 1047 | |
| 1048 | static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar) |
| 1049 | { |
| 1050 | int num_ctx; |
| 1051 | |
| 1052 | num_ctx = ath10k_mac_num_chanctxs(ar); |
| 1053 | |
| 1054 | /* FIXME: Current interface combinations and cfg80211/mac80211 code |
| 1055 | * shouldn't allow this but make sure to prevent handling the following |
| 1056 | * case anyway since multi-channel DFS hasn't been tested at all. |
| 1057 | */ |
| 1058 | if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1) |
| 1059 | return false; |
| 1060 | |
| 1061 | return true; |
| 1062 | } |
| 1063 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1064 | static int ath10k_monitor_recalc(struct ath10k *ar) |
| 1065 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1066 | bool needed; |
| 1067 | bool allowed; |
| 1068 | int ret; |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1069 | |
| 1070 | lockdep_assert_held(&ar->conf_mutex); |
| 1071 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1072 | needed = ath10k_mac_monitor_vdev_is_needed(ar); |
| 1073 | allowed = ath10k_mac_monitor_vdev_is_allowed(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1074 | |
| 1075 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1076 | "mac monitor recalc started? %d needed? %d allowed? %d\n", |
| 1077 | ar->monitor_started, needed, allowed); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1078 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1079 | if (WARN_ON(needed && !allowed)) { |
| 1080 | if (ar->monitor_started) { |
| 1081 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n"); |
| 1082 | |
| 1083 | ret = ath10k_monitor_stop(ar); |
| 1084 | if (ret) |
| 1085 | ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret); |
| 1086 | /* not serious */ |
| 1087 | } |
| 1088 | |
| 1089 | return -EPERM; |
| 1090 | } |
| 1091 | |
| 1092 | if (needed == ar->monitor_started) |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1093 | return 0; |
| 1094 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1095 | if (needed) |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1096 | return ath10k_monitor_start(ar); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1097 | else |
| 1098 | return ath10k_monitor_stop(ar); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1099 | } |
| 1100 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1101 | static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif) |
| 1102 | { |
| 1103 | struct ath10k *ar = arvif->ar; |
| 1104 | u32 vdev_param, rts_cts = 0; |
| 1105 | |
| 1106 | lockdep_assert_held(&ar->conf_mutex); |
| 1107 | |
| 1108 | vdev_param = ar->wmi.vdev_param->enable_rtscts; |
| 1109 | |
Rajkumar Manoharan | 9a5ab0f | 2015-03-19 16:03:29 +0200 | [diff] [blame] | 1110 | rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1111 | |
| 1112 | if (arvif->num_legacy_stations > 0) |
| 1113 | rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES, |
| 1114 | WMI_RTSCTS_PROFILE); |
Rajkumar Manoharan | 9a5ab0f | 2015-03-19 16:03:29 +0200 | [diff] [blame] | 1115 | else |
| 1116 | rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES, |
| 1117 | WMI_RTSCTS_PROFILE); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1118 | |
| 1119 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 1120 | rts_cts); |
| 1121 | } |
| 1122 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1123 | static int ath10k_start_cac(struct ath10k *ar) |
| 1124 | { |
| 1125 | int ret; |
| 1126 | |
| 1127 | lockdep_assert_held(&ar->conf_mutex); |
| 1128 | |
| 1129 | set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 1130 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1131 | ret = ath10k_monitor_recalc(ar); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1132 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1133 | ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1134 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 1135 | return ret; |
| 1136 | } |
| 1137 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1138 | 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] | 1139 | ar->monitor_vdev_id); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | static int ath10k_stop_cac(struct ath10k *ar) |
| 1145 | { |
| 1146 | lockdep_assert_held(&ar->conf_mutex); |
| 1147 | |
| 1148 | /* CAC is not running - do nothing */ |
| 1149 | if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) |
| 1150 | return 0; |
| 1151 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1152 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1153 | ath10k_monitor_stop(ar); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1154 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1155 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n"); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1156 | |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1160 | static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw, |
| 1161 | struct ieee80211_chanctx_conf *conf, |
| 1162 | void *data) |
| 1163 | { |
| 1164 | bool *ret = data; |
| 1165 | |
| 1166 | if (!*ret && conf->radar_enabled) |
| 1167 | *ret = true; |
| 1168 | } |
| 1169 | |
| 1170 | static bool ath10k_mac_has_radar_enabled(struct ath10k *ar) |
| 1171 | { |
| 1172 | bool has_radar = false; |
| 1173 | |
| 1174 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 1175 | ath10k_mac_has_radar_iter, |
| 1176 | &has_radar); |
| 1177 | |
| 1178 | return has_radar; |
| 1179 | } |
| 1180 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1181 | static void ath10k_recalc_radar_detection(struct ath10k *ar) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1182 | { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1183 | int ret; |
| 1184 | |
| 1185 | lockdep_assert_held(&ar->conf_mutex); |
| 1186 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1187 | ath10k_stop_cac(ar); |
| 1188 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1189 | if (!ath10k_mac_has_radar_enabled(ar)) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1190 | return; |
| 1191 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1192 | if (ar->num_started_vdevs > 0) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1193 | return; |
| 1194 | |
| 1195 | ret = ath10k_start_cac(ar); |
| 1196 | if (ret) { |
| 1197 | /* |
| 1198 | * Not possible to start CAC on current channel so starting |
| 1199 | * radiation is not allowed, make this channel DFS_UNAVAILABLE |
| 1200 | * by indicating that radar was detected. |
| 1201 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1202 | ath10k_warn(ar, "failed to start CAC: %d\n", ret); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1203 | ieee80211_radar_detected(ar->hw); |
| 1204 | } |
| 1205 | } |
| 1206 | |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 1207 | static int ath10k_vdev_stop(struct ath10k_vif *arvif) |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1208 | { |
| 1209 | struct ath10k *ar = arvif->ar; |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 1210 | int ret; |
| 1211 | |
| 1212 | lockdep_assert_held(&ar->conf_mutex); |
| 1213 | |
| 1214 | reinit_completion(&ar->vdev_setup_done); |
| 1215 | |
| 1216 | ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); |
| 1217 | if (ret) { |
| 1218 | ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n", |
| 1219 | arvif->vdev_id, ret); |
| 1220 | return ret; |
| 1221 | } |
| 1222 | |
| 1223 | ret = ath10k_vdev_setup_sync(ar); |
| 1224 | if (ret) { |
| 1225 | ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n", |
| 1226 | arvif->vdev_id, ret); |
| 1227 | return ret; |
| 1228 | } |
| 1229 | |
| 1230 | WARN_ON(ar->num_started_vdevs == 0); |
| 1231 | |
| 1232 | if (ar->num_started_vdevs != 0) { |
| 1233 | ar->num_started_vdevs--; |
| 1234 | ath10k_recalc_radar_detection(ar); |
| 1235 | } |
| 1236 | |
| 1237 | return ret; |
| 1238 | } |
| 1239 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1240 | static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, |
| 1241 | const struct cfg80211_chan_def *chandef, |
| 1242 | bool restart) |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1243 | { |
| 1244 | struct ath10k *ar = arvif->ar; |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1245 | struct wmi_vdev_start_request_arg arg = {}; |
| 1246 | int ret = 0; |
| 1247 | |
| 1248 | lockdep_assert_held(&ar->conf_mutex); |
| 1249 | |
| 1250 | reinit_completion(&ar->vdev_setup_done); |
| 1251 | |
| 1252 | arg.vdev_id = arvif->vdev_id; |
| 1253 | arg.dtim_period = arvif->dtim_period; |
| 1254 | arg.bcn_intval = arvif->beacon_interval; |
| 1255 | |
| 1256 | arg.channel.freq = chandef->chan->center_freq; |
| 1257 | arg.channel.band_center_freq1 = chandef->center_freq1; |
| 1258 | arg.channel.mode = chan_to_phymode(chandef); |
| 1259 | |
| 1260 | arg.channel.min_power = 0; |
| 1261 | arg.channel.max_power = chandef->chan->max_power * 2; |
| 1262 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; |
| 1263 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; |
| 1264 | |
| 1265 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 1266 | arg.ssid = arvif->u.ap.ssid; |
| 1267 | arg.ssid_len = arvif->u.ap.ssid_len; |
| 1268 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; |
| 1269 | |
| 1270 | /* For now allow DFS for AP mode */ |
| 1271 | arg.channel.chan_radar = |
| 1272 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); |
| 1273 | } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
| 1274 | arg.ssid = arvif->vif->bss_conf.ssid; |
| 1275 | arg.ssid_len = arvif->vif->bss_conf.ssid_len; |
| 1276 | } |
| 1277 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1278 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1279 | "mac vdev %d start center_freq %d phymode %s\n", |
| 1280 | arg.vdev_id, arg.channel.freq, |
| 1281 | ath10k_wmi_phymode_str(arg.channel.mode)); |
| 1282 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1283 | if (restart) |
| 1284 | ret = ath10k_wmi_vdev_restart(ar, &arg); |
| 1285 | else |
| 1286 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 1287 | |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1288 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1289 | ath10k_warn(ar, "failed to start WMI vdev %i: %d\n", |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1290 | arg.vdev_id, ret); |
| 1291 | return ret; |
| 1292 | } |
| 1293 | |
| 1294 | ret = ath10k_vdev_setup_sync(ar); |
| 1295 | if (ret) { |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 1296 | ath10k_warn(ar, |
| 1297 | "failed to synchronize setup for vdev %i restart %d: %d\n", |
| 1298 | arg.vdev_id, restart, ret); |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1299 | return ret; |
| 1300 | } |
| 1301 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1302 | ar->num_started_vdevs++; |
| 1303 | ath10k_recalc_radar_detection(ar); |
| 1304 | |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1305 | return ret; |
| 1306 | } |
| 1307 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1308 | static int ath10k_vdev_start(struct ath10k_vif *arvif, |
| 1309 | const struct cfg80211_chan_def *def) |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1310 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1311 | return ath10k_vdev_start_restart(arvif, def, false); |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1312 | } |
| 1313 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1314 | static int ath10k_vdev_restart(struct ath10k_vif *arvif, |
| 1315 | const struct cfg80211_chan_def *def) |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1316 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1317 | return ath10k_vdev_start_restart(arvif, def, true); |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1318 | } |
| 1319 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1320 | static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif, |
| 1321 | struct sk_buff *bcn) |
| 1322 | { |
| 1323 | struct ath10k *ar = arvif->ar; |
| 1324 | struct ieee80211_mgmt *mgmt; |
| 1325 | const u8 *p2p_ie; |
| 1326 | int ret; |
| 1327 | |
| 1328 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1329 | return 0; |
| 1330 | |
| 1331 | if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) |
| 1332 | return 0; |
| 1333 | |
| 1334 | mgmt = (void *)bcn->data; |
| 1335 | p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1336 | mgmt->u.beacon.variable, |
| 1337 | bcn->len - (mgmt->u.beacon.variable - |
| 1338 | bcn->data)); |
| 1339 | if (!p2p_ie) |
| 1340 | return -ENOENT; |
| 1341 | |
| 1342 | ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); |
| 1343 | if (ret) { |
| 1344 | ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n", |
| 1345 | arvif->vdev_id, ret); |
| 1346 | return ret; |
| 1347 | } |
| 1348 | |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
| 1352 | static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, |
| 1353 | u8 oui_type, size_t ie_offset) |
| 1354 | { |
| 1355 | size_t len; |
| 1356 | const u8 *next; |
| 1357 | const u8 *end; |
| 1358 | u8 *ie; |
| 1359 | |
| 1360 | if (WARN_ON(skb->len < ie_offset)) |
| 1361 | return -EINVAL; |
| 1362 | |
| 1363 | ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 1364 | skb->data + ie_offset, |
| 1365 | skb->len - ie_offset); |
| 1366 | if (!ie) |
| 1367 | return -ENOENT; |
| 1368 | |
| 1369 | len = ie[1] + 2; |
| 1370 | end = skb->data + skb->len; |
| 1371 | next = ie + len; |
| 1372 | |
| 1373 | if (WARN_ON(next > end)) |
| 1374 | return -EINVAL; |
| 1375 | |
| 1376 | memmove(ie, next, end - next); |
| 1377 | skb_trim(skb, skb->len - len); |
| 1378 | |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
| 1382 | static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif) |
| 1383 | { |
| 1384 | struct ath10k *ar = arvif->ar; |
| 1385 | struct ieee80211_hw *hw = ar->hw; |
| 1386 | struct ieee80211_vif *vif = arvif->vif; |
| 1387 | struct ieee80211_mutable_offsets offs = {}; |
| 1388 | struct sk_buff *bcn; |
| 1389 | int ret; |
| 1390 | |
| 1391 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1392 | return 0; |
| 1393 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1394 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 1395 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 1396 | return 0; |
| 1397 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1398 | bcn = ieee80211_beacon_get_template(hw, vif, &offs); |
| 1399 | if (!bcn) { |
| 1400 | ath10k_warn(ar, "failed to get beacon template from mac80211\n"); |
| 1401 | return -EPERM; |
| 1402 | } |
| 1403 | |
| 1404 | ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn); |
| 1405 | if (ret) { |
| 1406 | ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret); |
| 1407 | kfree_skb(bcn); |
| 1408 | return ret; |
| 1409 | } |
| 1410 | |
| 1411 | /* P2P IE is inserted by firmware automatically (as configured above) |
| 1412 | * so remove it from the base beacon template to avoid duplicate P2P |
| 1413 | * IEs in beacon frames. |
| 1414 | */ |
| 1415 | ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1416 | offsetof(struct ieee80211_mgmt, |
| 1417 | u.beacon.variable)); |
| 1418 | |
| 1419 | ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0, |
| 1420 | 0, NULL, 0); |
| 1421 | kfree_skb(bcn); |
| 1422 | |
| 1423 | if (ret) { |
| 1424 | ath10k_warn(ar, "failed to submit beacon template command: %d\n", |
| 1425 | ret); |
| 1426 | return ret; |
| 1427 | } |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
| 1431 | |
| 1432 | static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif) |
| 1433 | { |
| 1434 | struct ath10k *ar = arvif->ar; |
| 1435 | struct ieee80211_hw *hw = ar->hw; |
| 1436 | struct ieee80211_vif *vif = arvif->vif; |
| 1437 | struct sk_buff *prb; |
| 1438 | int ret; |
| 1439 | |
| 1440 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1441 | return 0; |
| 1442 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1443 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1444 | return 0; |
| 1445 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1446 | prb = ieee80211_proberesp_get(hw, vif); |
| 1447 | if (!prb) { |
| 1448 | ath10k_warn(ar, "failed to get probe resp template from mac80211\n"); |
| 1449 | return -EPERM; |
| 1450 | } |
| 1451 | |
| 1452 | ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb); |
| 1453 | kfree_skb(prb); |
| 1454 | |
| 1455 | if (ret) { |
| 1456 | ath10k_warn(ar, "failed to submit probe resp template command: %d\n", |
| 1457 | ret); |
| 1458 | return ret; |
| 1459 | } |
| 1460 | |
| 1461 | return 0; |
| 1462 | } |
| 1463 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1464 | static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif) |
| 1465 | { |
| 1466 | struct ath10k *ar = arvif->ar; |
| 1467 | struct cfg80211_chan_def def; |
| 1468 | int ret; |
| 1469 | |
| 1470 | /* When originally vdev is started during assign_vif_chanctx() some |
| 1471 | * information is missing, notably SSID. Firmware revisions with beacon |
| 1472 | * offloading require the SSID to be provided during vdev (re)start to |
| 1473 | * handle hidden SSID properly. |
| 1474 | * |
| 1475 | * Vdev restart must be done after vdev has been both started and |
| 1476 | * upped. Otherwise some firmware revisions (at least 10.2) fail to |
| 1477 | * deliver vdev restart response event causing timeouts during vdev |
| 1478 | * syncing in ath10k. |
| 1479 | * |
| 1480 | * Note: The vdev down/up and template reinstallation could be skipped |
| 1481 | * since only wmi-tlv firmware are known to have beacon offload and |
| 1482 | * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart |
| 1483 | * response delivery. It's probably more robust to keep it as is. |
| 1484 | */ |
| 1485 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1486 | return 0; |
| 1487 | |
| 1488 | if (WARN_ON(!arvif->is_started)) |
| 1489 | return -EINVAL; |
| 1490 | |
| 1491 | if (WARN_ON(!arvif->is_up)) |
| 1492 | return -EINVAL; |
| 1493 | |
| 1494 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) |
| 1495 | return -EINVAL; |
| 1496 | |
| 1497 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 1498 | if (ret) { |
| 1499 | ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n", |
| 1500 | arvif->vdev_id, ret); |
| 1501 | return ret; |
| 1502 | } |
| 1503 | |
| 1504 | /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise |
| 1505 | * firmware will crash upon vdev up. |
| 1506 | */ |
| 1507 | |
| 1508 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 1509 | if (ret) { |
| 1510 | ath10k_warn(ar, "failed to update beacon template: %d\n", ret); |
| 1511 | return ret; |
| 1512 | } |
| 1513 | |
| 1514 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 1515 | if (ret) { |
| 1516 | ath10k_warn(ar, "failed to update presp template: %d\n", ret); |
| 1517 | return ret; |
| 1518 | } |
| 1519 | |
| 1520 | ret = ath10k_vdev_restart(arvif, &def); |
| 1521 | if (ret) { |
| 1522 | ath10k_warn(ar, "failed to restart ap vdev %i: %d\n", |
| 1523 | arvif->vdev_id, ret); |
| 1524 | return ret; |
| 1525 | } |
| 1526 | |
| 1527 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 1528 | arvif->bssid); |
| 1529 | if (ret) { |
| 1530 | ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n", |
| 1531 | arvif->vdev_id, ret); |
| 1532 | return ret; |
| 1533 | } |
| 1534 | |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1538 | static void ath10k_control_beaconing(struct ath10k_vif *arvif, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1539 | struct ieee80211_bss_conf *info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1540 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1541 | struct ath10k *ar = arvif->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1542 | int ret = 0; |
| 1543 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1544 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1545 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1546 | if (!info->enable_beacon) { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1547 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 1548 | if (ret) |
| 1549 | ath10k_warn(ar, "failed to down vdev_id %i: %d\n", |
| 1550 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1551 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1552 | arvif->is_up = false; |
| 1553 | |
Michal Kazior | 748afc4 | 2014-01-23 12:48:21 +0100 | [diff] [blame] | 1554 | spin_lock_bh(&arvif->ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 1555 | ath10k_mac_vif_beacon_free(arvif); |
Michal Kazior | 748afc4 | 2014-01-23 12:48:21 +0100 | [diff] [blame] | 1556 | spin_unlock_bh(&arvif->ar->data_lock); |
| 1557 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1558 | return; |
| 1559 | } |
| 1560 | |
| 1561 | arvif->tx_seq_no = 0x1000; |
| 1562 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1563 | arvif->aid = 0; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 1564 | ether_addr_copy(arvif->bssid, info->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1565 | |
| 1566 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 1567 | arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1568 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1569 | ath10k_warn(ar, "failed to bring up vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1570 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1571 | return; |
| 1572 | } |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1573 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1574 | arvif->is_up = true; |
| 1575 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1576 | ret = ath10k_mac_vif_fix_hidden_ssid(arvif); |
| 1577 | if (ret) { |
| 1578 | ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n", |
| 1579 | arvif->vdev_id, ret); |
| 1580 | return; |
| 1581 | } |
| 1582 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1583 | 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] | 1584 | } |
| 1585 | |
| 1586 | static void ath10k_control_ibss(struct ath10k_vif *arvif, |
| 1587 | struct ieee80211_bss_conf *info, |
| 1588 | const u8 self_peer[ETH_ALEN]) |
| 1589 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1590 | struct ath10k *ar = arvif->ar; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 1591 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1592 | int ret = 0; |
| 1593 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1594 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1595 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1596 | if (!info->ibss_joined) { |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1597 | if (is_zero_ether_addr(arvif->bssid)) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1598 | return; |
| 1599 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1600 | eth_zero_addr(arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1601 | |
| 1602 | return; |
| 1603 | } |
| 1604 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 1605 | vdev_param = arvif->ar->wmi.vdev_param->atim_window; |
| 1606 | 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] | 1607 | ATH10K_DEFAULT_ATIM); |
| 1608 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1609 | 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] | 1610 | arvif->vdev_id, ret); |
| 1611 | } |
| 1612 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 1613 | static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif) |
| 1614 | { |
| 1615 | struct ath10k *ar = arvif->ar; |
| 1616 | u32 param; |
| 1617 | u32 value; |
| 1618 | int ret; |
| 1619 | |
| 1620 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1621 | |
| 1622 | if (arvif->u.sta.uapsd) |
| 1623 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER; |
| 1624 | else |
| 1625 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; |
| 1626 | |
| 1627 | param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; |
| 1628 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value); |
| 1629 | if (ret) { |
| 1630 | ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n", |
| 1631 | value, arvif->vdev_id, ret); |
| 1632 | return ret; |
| 1633 | } |
| 1634 | |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
| 1638 | static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif) |
| 1639 | { |
| 1640 | struct ath10k *ar = arvif->ar; |
| 1641 | u32 param; |
| 1642 | u32 value; |
| 1643 | int ret; |
| 1644 | |
| 1645 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1646 | |
| 1647 | if (arvif->u.sta.uapsd) |
| 1648 | value = WMI_STA_PS_PSPOLL_COUNT_UAPSD; |
| 1649 | else |
| 1650 | value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; |
| 1651 | |
| 1652 | param = WMI_STA_PS_PARAM_PSPOLL_COUNT; |
| 1653 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 1654 | param, value); |
| 1655 | if (ret) { |
| 1656 | ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n", |
| 1657 | value, arvif->vdev_id, ret); |
| 1658 | return ret; |
| 1659 | } |
| 1660 | |
| 1661 | return 0; |
| 1662 | } |
| 1663 | |
Michal Kazior | 424f263 | 2015-07-09 13:08:35 +0200 | [diff] [blame] | 1664 | static int ath10k_mac_num_vifs_started(struct ath10k *ar) |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1665 | { |
| 1666 | struct ath10k_vif *arvif; |
| 1667 | int num = 0; |
| 1668 | |
| 1669 | lockdep_assert_held(&ar->conf_mutex); |
| 1670 | |
| 1671 | list_for_each_entry(arvif, &ar->arvifs, list) |
Michal Kazior | 424f263 | 2015-07-09 13:08:35 +0200 | [diff] [blame] | 1672 | if (arvif->is_started) |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1673 | num++; |
| 1674 | |
| 1675 | return num; |
| 1676 | } |
| 1677 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1678 | static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1679 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1680 | struct ath10k *ar = arvif->ar; |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1681 | struct ieee80211_vif *vif = arvif->vif; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1682 | struct ieee80211_conf *conf = &ar->hw->conf; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1683 | enum wmi_sta_powersave_param param; |
| 1684 | enum wmi_sta_ps_mode psmode; |
| 1685 | int ret; |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1686 | int ps_timeout; |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1687 | bool enable_ps; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1688 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1689 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1690 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1691 | if (arvif->vif->type != NL80211_IFTYPE_STATION) |
| 1692 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1693 | |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1694 | enable_ps = arvif->ps; |
| 1695 | |
Michal Kazior | 424f263 | 2015-07-09 13:08:35 +0200 | [diff] [blame] | 1696 | if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 && |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1697 | !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT, |
| 1698 | ar->fw_features)) { |
| 1699 | ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n", |
| 1700 | arvif->vdev_id); |
| 1701 | enable_ps = false; |
| 1702 | } |
| 1703 | |
Janusz Dziedzic | 917826b | 2015-05-18 09:38:17 +0000 | [diff] [blame] | 1704 | if (!arvif->is_started) { |
| 1705 | /* mac80211 can update vif powersave state while disconnected. |
| 1706 | * Firmware doesn't behave nicely and consumes more power than |
| 1707 | * necessary if PS is disabled on a non-started vdev. Hence |
| 1708 | * force-enable PS for non-running vdevs. |
| 1709 | */ |
| 1710 | psmode = WMI_STA_PS_MODE_ENABLED; |
| 1711 | } else if (enable_ps) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1712 | psmode = WMI_STA_PS_MODE_ENABLED; |
| 1713 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; |
| 1714 | |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1715 | ps_timeout = conf->dynamic_ps_timeout; |
| 1716 | if (ps_timeout == 0) { |
| 1717 | /* Firmware doesn't like 0 */ |
| 1718 | ps_timeout = ieee80211_tu_to_usec( |
| 1719 | vif->bss_conf.beacon_int) / 1000; |
| 1720 | } |
| 1721 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1722 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1723 | ps_timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1724 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1725 | 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] | 1726 | arvif->vdev_id, ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1727 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1728 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1729 | } else { |
| 1730 | psmode = WMI_STA_PS_MODE_DISABLED; |
| 1731 | } |
| 1732 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1733 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1734 | arvif->vdev_id, psmode ? "enable" : "disable"); |
| 1735 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1736 | ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode); |
| 1737 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1738 | 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] | 1739 | psmode, arvif->vdev_id, ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1740 | return ret; |
| 1741 | } |
| 1742 | |
| 1743 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1744 | } |
| 1745 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 1746 | static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif) |
| 1747 | { |
| 1748 | struct ath10k *ar = arvif->ar; |
| 1749 | struct wmi_sta_keepalive_arg arg = {}; |
| 1750 | int ret; |
| 1751 | |
| 1752 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1753 | |
| 1754 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 1755 | return 0; |
| 1756 | |
| 1757 | if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map)) |
| 1758 | return 0; |
| 1759 | |
| 1760 | /* Some firmware revisions have a bug and ignore the `enabled` field. |
| 1761 | * Instead use the interval to disable the keepalive. |
| 1762 | */ |
| 1763 | arg.vdev_id = arvif->vdev_id; |
| 1764 | arg.enabled = 1; |
| 1765 | arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME; |
| 1766 | arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE; |
| 1767 | |
| 1768 | ret = ath10k_wmi_sta_keepalive(ar, &arg); |
| 1769 | if (ret) { |
| 1770 | ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n", |
| 1771 | arvif->vdev_id, ret); |
| 1772 | return ret; |
| 1773 | } |
| 1774 | |
| 1775 | return 0; |
| 1776 | } |
| 1777 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1778 | static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif) |
| 1779 | { |
| 1780 | struct ath10k *ar = arvif->ar; |
| 1781 | struct ieee80211_vif *vif = arvif->vif; |
| 1782 | int ret; |
| 1783 | |
Michal Kazior | 8513d95 | 2015-03-09 14:19:24 +0100 | [diff] [blame] | 1784 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1785 | |
| 1786 | if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))) |
| 1787 | return; |
| 1788 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1789 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1790 | return; |
| 1791 | |
| 1792 | if (!vif->csa_active) |
| 1793 | return; |
| 1794 | |
| 1795 | if (!arvif->is_up) |
| 1796 | return; |
| 1797 | |
| 1798 | if (!ieee80211_csa_is_complete(vif)) { |
| 1799 | ieee80211_csa_update_counter(vif); |
| 1800 | |
| 1801 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 1802 | if (ret) |
| 1803 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 1804 | ret); |
| 1805 | |
| 1806 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 1807 | if (ret) |
| 1808 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 1809 | ret); |
| 1810 | } else { |
| 1811 | ieee80211_csa_finish(vif); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | static void ath10k_mac_vif_ap_csa_work(struct work_struct *work) |
| 1816 | { |
| 1817 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 1818 | ap_csa_work); |
| 1819 | struct ath10k *ar = arvif->ar; |
| 1820 | |
| 1821 | mutex_lock(&ar->conf_mutex); |
| 1822 | ath10k_mac_vif_ap_csa_count_down(arvif); |
| 1823 | mutex_unlock(&ar->conf_mutex); |
| 1824 | } |
| 1825 | |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 1826 | static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac, |
| 1827 | struct ieee80211_vif *vif) |
| 1828 | { |
| 1829 | struct sk_buff *skb = data; |
| 1830 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 1831 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1832 | |
| 1833 | if (vif->type != NL80211_IFTYPE_STATION) |
| 1834 | return; |
| 1835 | |
| 1836 | if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) |
| 1837 | return; |
| 1838 | |
| 1839 | cancel_delayed_work(&arvif->connection_loss_work); |
| 1840 | } |
| 1841 | |
| 1842 | void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb) |
| 1843 | { |
| 1844 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 1845 | IEEE80211_IFACE_ITER_NORMAL, |
| 1846 | ath10k_mac_handle_beacon_iter, |
| 1847 | skb); |
| 1848 | } |
| 1849 | |
| 1850 | static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac, |
| 1851 | struct ieee80211_vif *vif) |
| 1852 | { |
| 1853 | u32 *vdev_id = data; |
| 1854 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 1855 | struct ath10k *ar = arvif->ar; |
| 1856 | struct ieee80211_hw *hw = ar->hw; |
| 1857 | |
| 1858 | if (arvif->vdev_id != *vdev_id) |
| 1859 | return; |
| 1860 | |
| 1861 | if (!arvif->is_up) |
| 1862 | return; |
| 1863 | |
| 1864 | ieee80211_beacon_loss(vif); |
| 1865 | |
| 1866 | /* Firmware doesn't report beacon loss events repeatedly. If AP probe |
| 1867 | * (done by mac80211) succeeds but beacons do not resume then it |
| 1868 | * doesn't make sense to continue operation. Queue connection loss work |
| 1869 | * which can be cancelled when beacon is received. |
| 1870 | */ |
| 1871 | ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, |
| 1872 | ATH10K_CONNECTION_LOSS_HZ); |
| 1873 | } |
| 1874 | |
| 1875 | void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id) |
| 1876 | { |
| 1877 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 1878 | IEEE80211_IFACE_ITER_NORMAL, |
| 1879 | ath10k_mac_handle_beacon_miss_iter, |
| 1880 | &vdev_id); |
| 1881 | } |
| 1882 | |
| 1883 | static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work) |
| 1884 | { |
| 1885 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 1886 | connection_loss_work.work); |
| 1887 | struct ieee80211_vif *vif = arvif->vif; |
| 1888 | |
| 1889 | if (!arvif->is_up) |
| 1890 | return; |
| 1891 | |
| 1892 | ieee80211_connection_loss(vif); |
| 1893 | } |
| 1894 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1895 | /**********************/ |
| 1896 | /* Station management */ |
| 1897 | /**********************/ |
| 1898 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1899 | static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar, |
| 1900 | struct ieee80211_vif *vif) |
| 1901 | { |
| 1902 | /* Some firmware revisions have unstable STA powersave when listen |
| 1903 | * interval is set too high (e.g. 5). The symptoms are firmware doesn't |
| 1904 | * generate NullFunc frames properly even if buffered frames have been |
| 1905 | * indicated in Beacon TIM. Firmware would seldom wake up to pull |
| 1906 | * buffered frames. Often pinging the device from AP would simply fail. |
| 1907 | * |
| 1908 | * As a workaround set it to 1. |
| 1909 | */ |
| 1910 | if (vif->type == NL80211_IFTYPE_STATION) |
| 1911 | return 1; |
| 1912 | |
| 1913 | return ar->hw->conf.listen_interval; |
| 1914 | } |
| 1915 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1916 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1917 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1918 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1919 | struct wmi_peer_assoc_complete_arg *arg) |
| 1920 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1921 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | c51880e | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 1922 | u32 aid; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1923 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1924 | lockdep_assert_held(&ar->conf_mutex); |
| 1925 | |
Michal Kazior | c51880e | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 1926 | if (vif->type == NL80211_IFTYPE_STATION) |
| 1927 | aid = vif->bss_conf.aid; |
| 1928 | else |
| 1929 | aid = sta->aid; |
| 1930 | |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 1931 | ether_addr_copy(arg->addr, sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1932 | arg->vdev_id = arvif->vdev_id; |
Michal Kazior | c51880e | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 1933 | arg->peer_aid = aid; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1934 | arg->peer_flags |= WMI_PEER_AUTH; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1935 | arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1936 | arg->peer_num_spatial_streams = 1; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1937 | arg->peer_caps = vif->bss_conf.assoc_capability; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 1941 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1942 | struct wmi_peer_assoc_complete_arg *arg) |
| 1943 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1944 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1945 | struct cfg80211_chan_def def; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1946 | struct cfg80211_bss *bss; |
| 1947 | const u8 *rsnie = NULL; |
| 1948 | const u8 *wpaie = NULL; |
| 1949 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1950 | lockdep_assert_held(&ar->conf_mutex); |
| 1951 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1952 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 1953 | return; |
| 1954 | |
| 1955 | bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0, |
| 1956 | IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1957 | if (bss) { |
| 1958 | const struct cfg80211_bss_ies *ies; |
| 1959 | |
| 1960 | rcu_read_lock(); |
| 1961 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); |
| 1962 | |
| 1963 | ies = rcu_dereference(bss->ies); |
| 1964 | |
| 1965 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1966 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 1967 | ies->data, |
| 1968 | ies->len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1969 | rcu_read_unlock(); |
| 1970 | cfg80211_put_bss(ar->hw->wiphy, bss); |
| 1971 | } |
| 1972 | |
| 1973 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ |
| 1974 | if (rsnie || wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1975 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1976 | arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY; |
| 1977 | } |
| 1978 | |
| 1979 | if (wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1980 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1981 | arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY; |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1986 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1987 | struct ieee80211_sta *sta, |
| 1988 | struct wmi_peer_assoc_complete_arg *arg) |
| 1989 | { |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 1990 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1991 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1992 | struct cfg80211_chan_def def; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1993 | const struct ieee80211_supported_band *sband; |
| 1994 | const struct ieee80211_rate *rates; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 1995 | enum ieee80211_band band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1996 | u32 ratemask; |
Michal Kazior | 486017c | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 1997 | u8 rate; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1998 | int i; |
| 1999 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2000 | lockdep_assert_held(&ar->conf_mutex); |
| 2001 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2002 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2003 | return; |
| 2004 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2005 | band = def.chan->band; |
| 2006 | sband = ar->hw->wiphy->bands[band]; |
| 2007 | ratemask = sta->supp_rates[band]; |
| 2008 | ratemask &= arvif->bitrate_mask.control[band].legacy; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2009 | rates = sband->bitrates; |
| 2010 | |
| 2011 | rateset->num_rates = 0; |
| 2012 | |
| 2013 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { |
| 2014 | if (!(ratemask & 1)) |
| 2015 | continue; |
| 2016 | |
Michal Kazior | 486017c | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 2017 | rate = ath10k_mac_bitrate_to_rate(rates->bitrate); |
| 2018 | rateset->rates[rateset->num_rates] = rate; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2019 | rateset->num_rates++; |
| 2020 | } |
| 2021 | } |
| 2022 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2023 | static bool |
| 2024 | ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) |
| 2025 | { |
| 2026 | int nss; |
| 2027 | |
| 2028 | for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) |
| 2029 | if (ht_mcs_mask[nss]) |
| 2030 | return false; |
| 2031 | |
| 2032 | return true; |
| 2033 | } |
| 2034 | |
| 2035 | static bool |
| 2036 | ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 2037 | { |
| 2038 | int nss; |
| 2039 | |
| 2040 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) |
| 2041 | if (vht_mcs_mask[nss]) |
| 2042 | return false; |
| 2043 | |
| 2044 | return true; |
| 2045 | } |
| 2046 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2047 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2048 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2049 | struct ieee80211_sta *sta, |
| 2050 | struct wmi_peer_assoc_complete_arg *arg) |
| 2051 | { |
| 2052 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2053 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2054 | struct cfg80211_chan_def def; |
| 2055 | enum ieee80211_band band; |
| 2056 | const u8 *ht_mcs_mask; |
| 2057 | const u16 *vht_mcs_mask; |
| 2058 | int i, n, max_nss; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 2059 | u32 stbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2060 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2061 | lockdep_assert_held(&ar->conf_mutex); |
| 2062 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2063 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2064 | return; |
| 2065 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2066 | if (!ht_cap->ht_supported) |
| 2067 | return; |
| 2068 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2069 | band = def.chan->band; |
| 2070 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 2071 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2072 | |
| 2073 | if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) && |
| 2074 | ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) |
| 2075 | return; |
| 2076 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2077 | arg->peer_flags |= WMI_PEER_HT; |
| 2078 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 2079 | ht_cap->ampdu_factor)) - 1; |
| 2080 | |
| 2081 | arg->peer_mpdu_density = |
| 2082 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); |
| 2083 | |
| 2084 | arg->peer_ht_caps = ht_cap->cap; |
| 2085 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; |
| 2086 | |
| 2087 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) |
| 2088 | arg->peer_flags |= WMI_PEER_LDPC; |
| 2089 | |
| 2090 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
| 2091 | arg->peer_flags |= WMI_PEER_40MHZ; |
| 2092 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; |
| 2093 | } |
| 2094 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2095 | if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { |
| 2096 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) |
| 2097 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2098 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2099 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) |
| 2100 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 2101 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2102 | |
| 2103 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { |
| 2104 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; |
| 2105 | arg->peer_flags |= WMI_PEER_STBC; |
| 2106 | } |
| 2107 | |
| 2108 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2109 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
| 2110 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 2111 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; |
| 2112 | arg->peer_rate_caps |= stbc; |
| 2113 | arg->peer_flags |= WMI_PEER_STBC; |
| 2114 | } |
| 2115 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2116 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
| 2117 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; |
| 2118 | else if (ht_cap->mcs.rx_mask[1]) |
| 2119 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; |
| 2120 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2121 | for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) |
| 2122 | if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && |
| 2123 | (ht_mcs_mask[i / 8] & BIT(i % 8))) { |
| 2124 | max_nss = (i / 8) + 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2125 | arg->peer_ht_rates.rates[n++] = i; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2126 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2127 | |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 2128 | /* |
| 2129 | * This is a workaround for HT-enabled STAs which break the spec |
| 2130 | * and have no HT capabilities RX mask (no HT RX MCS map). |
| 2131 | * |
| 2132 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), |
| 2133 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. |
| 2134 | * |
| 2135 | * Firmware asserts if such situation occurs. |
| 2136 | */ |
| 2137 | if (n == 0) { |
| 2138 | arg->peer_ht_rates.num_rates = 8; |
| 2139 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) |
| 2140 | arg->peer_ht_rates.rates[i] = i; |
| 2141 | } else { |
| 2142 | arg->peer_ht_rates.num_rates = n; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2143 | arg->peer_num_spatial_streams = max_nss; |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 2144 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2145 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2146 | 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] | 2147 | arg->addr, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2148 | arg->peer_ht_rates.num_rates, |
| 2149 | arg->peer_num_spatial_streams); |
| 2150 | } |
| 2151 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2152 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
| 2153 | struct ath10k_vif *arvif, |
| 2154 | struct ieee80211_sta *sta) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2155 | { |
| 2156 | u32 uapsd = 0; |
| 2157 | u32 max_sp = 0; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2158 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2159 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2160 | lockdep_assert_held(&ar->conf_mutex); |
| 2161 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2162 | if (sta->wme && sta->uapsd_queues) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2163 | 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] | 2164 | sta->uapsd_queues, sta->max_sp); |
| 2165 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2166 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 2167 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | |
| 2168 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; |
| 2169 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 2170 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | |
| 2171 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; |
| 2172 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 2173 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | |
| 2174 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; |
| 2175 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 2176 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | |
| 2177 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; |
| 2178 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2179 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
| 2180 | max_sp = sta->max_sp; |
| 2181 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2182 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 2183 | sta->addr, |
| 2184 | WMI_AP_PS_PEER_PARAM_UAPSD, |
| 2185 | uapsd); |
| 2186 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2187 | 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] | 2188 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2189 | return ret; |
| 2190 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2191 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2192 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 2193 | sta->addr, |
| 2194 | WMI_AP_PS_PEER_PARAM_MAX_SP, |
| 2195 | max_sp); |
| 2196 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2197 | 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] | 2198 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2199 | return ret; |
| 2200 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2201 | |
| 2202 | /* TODO setup this based on STA listen interval and |
| 2203 | beacon interval. Currently we don't know |
| 2204 | sta->listen_interval - mac80211 patch required. |
| 2205 | Currently use 10 seconds */ |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2206 | 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] | 2207 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, |
| 2208 | 10); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2209 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2210 | 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] | 2211 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2212 | return ret; |
| 2213 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2214 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2215 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2216 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2217 | } |
| 2218 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2219 | static u16 |
| 2220 | ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set, |
| 2221 | const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) |
| 2222 | { |
| 2223 | int idx_limit; |
| 2224 | int nss; |
| 2225 | u16 mcs_map; |
| 2226 | u16 mcs; |
| 2227 | |
| 2228 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 2229 | mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & |
| 2230 | vht_mcs_limit[nss]; |
| 2231 | |
| 2232 | if (mcs_map) |
| 2233 | idx_limit = fls(mcs_map) - 1; |
| 2234 | else |
| 2235 | idx_limit = -1; |
| 2236 | |
| 2237 | switch (idx_limit) { |
| 2238 | case 0: /* fall through */ |
| 2239 | case 1: /* fall through */ |
| 2240 | case 2: /* fall through */ |
| 2241 | case 3: /* fall through */ |
| 2242 | case 4: /* fall through */ |
| 2243 | case 5: /* fall through */ |
| 2244 | case 6: /* fall through */ |
| 2245 | default: |
| 2246 | /* see ath10k_mac_can_set_bitrate_mask() */ |
| 2247 | WARN_ON(1); |
| 2248 | /* fall through */ |
| 2249 | case -1: |
| 2250 | mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 2251 | break; |
| 2252 | case 7: |
| 2253 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; |
| 2254 | break; |
| 2255 | case 8: |
| 2256 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; |
| 2257 | break; |
| 2258 | case 9: |
| 2259 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; |
| 2260 | break; |
| 2261 | } |
| 2262 | |
| 2263 | tx_mcs_set &= ~(0x3 << (nss * 2)); |
| 2264 | tx_mcs_set |= mcs << (nss * 2); |
| 2265 | } |
| 2266 | |
| 2267 | return tx_mcs_set; |
| 2268 | } |
| 2269 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2270 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2271 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2272 | struct ieee80211_sta *sta, |
| 2273 | struct wmi_peer_assoc_complete_arg *arg) |
| 2274 | { |
| 2275 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2276 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2277 | struct cfg80211_chan_def def; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2278 | enum ieee80211_band band; |
| 2279 | const u16 *vht_mcs_mask; |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 2280 | u8 ampdu_factor; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2281 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2282 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2283 | return; |
| 2284 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2285 | if (!vht_cap->vht_supported) |
| 2286 | return; |
| 2287 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2288 | band = def.chan->band; |
| 2289 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2290 | |
| 2291 | if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) |
| 2292 | return; |
| 2293 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2294 | arg->peer_flags |= WMI_PEER_VHT; |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 2295 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2296 | if (def.chan->band == IEEE80211_BAND_2GHZ) |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 2297 | arg->peer_flags |= WMI_PEER_VHT_2G; |
| 2298 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2299 | arg->peer_vht_caps = vht_cap->cap; |
| 2300 | |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 2301 | ampdu_factor = (vht_cap->cap & |
| 2302 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> |
| 2303 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 2304 | |
| 2305 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to |
| 2306 | * zero in VHT IE. Using it would result in degraded throughput. |
| 2307 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep |
| 2308 | * it if VHT max_mpdu is smaller. */ |
| 2309 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
| 2310 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 2311 | ampdu_factor)) - 1); |
| 2312 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2313 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 2314 | arg->peer_flags |= WMI_PEER_80MHZ; |
| 2315 | |
| 2316 | arg->peer_vht_rates.rx_max_rate = |
| 2317 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
| 2318 | arg->peer_vht_rates.rx_mcs_set = |
| 2319 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 2320 | arg->peer_vht_rates.tx_max_rate = |
| 2321 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2322 | arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit( |
| 2323 | __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2324 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2325 | 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] | 2326 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2330 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2331 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2332 | struct wmi_peer_assoc_complete_arg *arg) |
| 2333 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2334 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2335 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2336 | switch (arvif->vdev_type) { |
| 2337 | case WMI_VDEV_TYPE_AP: |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2338 | if (sta->wme) |
| 2339 | arg->peer_flags |= WMI_PEER_QOS; |
| 2340 | |
| 2341 | if (sta->wme && sta->uapsd_queues) { |
| 2342 | arg->peer_flags |= WMI_PEER_APSD; |
| 2343 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; |
| 2344 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2345 | break; |
| 2346 | case WMI_VDEV_TYPE_STA: |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2347 | if (vif->bss_conf.qos) |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2348 | arg->peer_flags |= WMI_PEER_QOS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2349 | break; |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 2350 | case WMI_VDEV_TYPE_IBSS: |
| 2351 | if (sta->wme) |
| 2352 | arg->peer_flags |= WMI_PEER_QOS; |
| 2353 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2354 | default: |
| 2355 | break; |
| 2356 | } |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 2357 | |
| 2358 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n", |
| 2359 | sta->addr, !!(arg->peer_flags & WMI_PEER_QOS)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2360 | } |
| 2361 | |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2362 | static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta) |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 2363 | { |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2364 | return sta->supp_rates[IEEE80211_BAND_2GHZ] >> |
| 2365 | ATH10K_MAC_FIRST_OFDM_RATE_IDX; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2368 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2369 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2370 | struct ieee80211_sta *sta, |
| 2371 | struct wmi_peer_assoc_complete_arg *arg) |
| 2372 | { |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2373 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2374 | struct cfg80211_chan_def def; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2375 | enum ieee80211_band band; |
| 2376 | const u8 *ht_mcs_mask; |
| 2377 | const u16 *vht_mcs_mask; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2378 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 2379 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2380 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2381 | return; |
| 2382 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2383 | band = def.chan->band; |
| 2384 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 2385 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2386 | |
| 2387 | switch (band) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2388 | case IEEE80211_BAND_2GHZ: |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2389 | if (sta->vht_cap.vht_supported && |
| 2390 | !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 2391 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2392 | phymode = MODE_11AC_VHT40; |
| 2393 | else |
| 2394 | phymode = MODE_11AC_VHT20; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2395 | } else if (sta->ht_cap.ht_supported && |
| 2396 | !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2397 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2398 | phymode = MODE_11NG_HT40; |
| 2399 | else |
| 2400 | phymode = MODE_11NG_HT20; |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2401 | } else if (ath10k_mac_sta_has_ofdm_only(sta)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2402 | phymode = MODE_11G; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 2403 | } else { |
| 2404 | phymode = MODE_11B; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | break; |
| 2408 | case IEEE80211_BAND_5GHZ: |
Sujith Manoharan | 7cc45e9 | 2013-09-08 18:19:55 +0300 | [diff] [blame] | 2409 | /* |
| 2410 | * Check VHT first. |
| 2411 | */ |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2412 | if (sta->vht_cap.vht_supported && |
| 2413 | !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
Sujith Manoharan | 7cc45e9 | 2013-09-08 18:19:55 +0300 | [diff] [blame] | 2414 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 2415 | phymode = MODE_11AC_VHT80; |
| 2416 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2417 | phymode = MODE_11AC_VHT40; |
| 2418 | else if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 2419 | phymode = MODE_11AC_VHT20; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2420 | } else if (sta->ht_cap.ht_supported && |
| 2421 | !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
| 2422 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2423 | phymode = MODE_11NA_HT40; |
| 2424 | else |
| 2425 | phymode = MODE_11NA_HT20; |
| 2426 | } else { |
| 2427 | phymode = MODE_11A; |
| 2428 | } |
| 2429 | |
| 2430 | break; |
| 2431 | default: |
| 2432 | break; |
| 2433 | } |
| 2434 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2435 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
Kalle Valo | 38a1d47 | 2013-09-08 17:56:14 +0300 | [diff] [blame] | 2436 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2437 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2438 | arg->peer_phymode = phymode; |
| 2439 | WARN_ON(phymode == MODE_UNKNOWN); |
| 2440 | } |
| 2441 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2442 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2443 | struct ieee80211_vif *vif, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2444 | struct ieee80211_sta *sta, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2445 | struct wmi_peer_assoc_complete_arg *arg) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2446 | { |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2447 | lockdep_assert_held(&ar->conf_mutex); |
| 2448 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2449 | memset(arg, 0, sizeof(*arg)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2450 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2451 | ath10k_peer_assoc_h_basic(ar, vif, sta, arg); |
| 2452 | ath10k_peer_assoc_h_crypto(ar, vif, arg); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2453 | ath10k_peer_assoc_h_rates(ar, vif, sta, arg); |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2454 | ath10k_peer_assoc_h_ht(ar, vif, sta, arg); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2455 | ath10k_peer_assoc_h_vht(ar, vif, sta, arg); |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2456 | ath10k_peer_assoc_h_qos(ar, vif, sta, arg); |
| 2457 | ath10k_peer_assoc_h_phymode(ar, vif, sta, arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2458 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2459 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2460 | } |
| 2461 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2462 | static const u32 ath10k_smps_map[] = { |
| 2463 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, |
| 2464 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, |
| 2465 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, |
| 2466 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, |
| 2467 | }; |
| 2468 | |
| 2469 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, |
| 2470 | const u8 *addr, |
| 2471 | const struct ieee80211_sta_ht_cap *ht_cap) |
| 2472 | { |
| 2473 | int smps; |
| 2474 | |
| 2475 | if (!ht_cap->ht_supported) |
| 2476 | return 0; |
| 2477 | |
| 2478 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; |
| 2479 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 2480 | |
| 2481 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) |
| 2482 | return -EINVAL; |
| 2483 | |
| 2484 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, |
| 2485 | WMI_PEER_SMPS_STATE, |
| 2486 | ath10k_smps_map[smps]); |
| 2487 | } |
| 2488 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2489 | static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, |
| 2490 | struct ieee80211_vif *vif, |
| 2491 | struct ieee80211_sta_vht_cap vht_cap) |
| 2492 | { |
| 2493 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2494 | int ret; |
| 2495 | u32 param; |
| 2496 | u32 value; |
| 2497 | |
| 2498 | if (!(ar->vht_cap_info & |
| 2499 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 2500 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | |
| 2501 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 2502 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 2503 | return 0; |
| 2504 | |
| 2505 | param = ar->wmi.vdev_param->txbf; |
| 2506 | value = 0; |
| 2507 | |
| 2508 | if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED)) |
| 2509 | return 0; |
| 2510 | |
| 2511 | /* The following logic is correct. If a remote STA advertises support |
| 2512 | * for being a beamformer then we should enable us being a beamformee. |
| 2513 | */ |
| 2514 | |
| 2515 | if (ar->vht_cap_info & |
| 2516 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 2517 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 2518 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) |
| 2519 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2520 | |
| 2521 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) |
| 2522 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; |
| 2523 | } |
| 2524 | |
| 2525 | if (ar->vht_cap_info & |
| 2526 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 2527 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 2528 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) |
| 2529 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2530 | |
| 2531 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) |
| 2532 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; |
| 2533 | } |
| 2534 | |
| 2535 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE) |
| 2536 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2537 | |
| 2538 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER) |
| 2539 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2540 | |
| 2541 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value); |
| 2542 | if (ret) { |
| 2543 | ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n", |
| 2544 | value, ret); |
| 2545 | return ret; |
| 2546 | } |
| 2547 | |
| 2548 | return 0; |
| 2549 | } |
| 2550 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2551 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
| 2552 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, |
| 2553 | struct ieee80211_vif *vif, |
| 2554 | struct ieee80211_bss_conf *bss_conf) |
| 2555 | { |
| 2556 | struct ath10k *ar = hw->priv; |
| 2557 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2558 | struct ieee80211_sta_ht_cap ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2559 | struct ieee80211_sta_vht_cap vht_cap; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2560 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2561 | struct ieee80211_sta *ap_sta; |
| 2562 | int ret; |
| 2563 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2564 | lockdep_assert_held(&ar->conf_mutex); |
| 2565 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2566 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", |
| 2567 | arvif->vdev_id, arvif->bssid, arvif->aid); |
| 2568 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2569 | rcu_read_lock(); |
| 2570 | |
| 2571 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 2572 | if (!ap_sta) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2573 | 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] | 2574 | bss_conf->bssid, arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2575 | rcu_read_unlock(); |
| 2576 | return; |
| 2577 | } |
| 2578 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2579 | /* ap_sta must be accessed only within rcu section which must be left |
| 2580 | * before calling ath10k_setup_peer_smps() which might sleep. */ |
| 2581 | ht_cap = ap_sta->ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2582 | vht_cap = ap_sta->vht_cap; |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2583 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2584 | ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2585 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2586 | 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] | 2587 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2588 | rcu_read_unlock(); |
| 2589 | return; |
| 2590 | } |
| 2591 | |
| 2592 | rcu_read_unlock(); |
| 2593 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2594 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2595 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2596 | 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] | 2597 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2598 | return; |
| 2599 | } |
| 2600 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2601 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
| 2602 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2603 | 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] | 2604 | arvif->vdev_id, ret); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2605 | return; |
| 2606 | } |
| 2607 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2608 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2609 | if (ret) { |
| 2610 | ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n", |
| 2611 | arvif->vdev_id, bss_conf->bssid, ret); |
| 2612 | return; |
| 2613 | } |
| 2614 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2615 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2616 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
| 2617 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); |
| 2618 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2619 | WARN_ON(arvif->is_up); |
| 2620 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2621 | arvif->aid = bss_conf->aid; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 2622 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2623 | |
| 2624 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); |
| 2625 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2626 | ath10k_warn(ar, "failed to set vdev %d up: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2627 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2628 | return; |
| 2629 | } |
| 2630 | |
| 2631 | arvif->is_up = true; |
Michal Kazior | 0a987fb | 2015-02-13 13:30:15 +0100 | [diff] [blame] | 2632 | |
| 2633 | /* Workaround: Some firmware revisions (tested with qca6174 |
| 2634 | * WLAN.RM.2.0-00073) have buggy powersave state machine and must be |
| 2635 | * poked with peer param command. |
| 2636 | */ |
| 2637 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid, |
| 2638 | WMI_PEER_DUMMY_VAR, 1); |
| 2639 | if (ret) { |
| 2640 | ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n", |
| 2641 | arvif->bssid, arvif->vdev_id, ret); |
| 2642 | return; |
| 2643 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2644 | } |
| 2645 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2646 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
| 2647 | struct ieee80211_vif *vif) |
| 2648 | { |
| 2649 | struct ath10k *ar = hw->priv; |
| 2650 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2651 | struct ieee80211_sta_vht_cap vht_cap = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2652 | int ret; |
| 2653 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2654 | lockdep_assert_held(&ar->conf_mutex); |
| 2655 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2656 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
| 2657 | arvif->vdev_id, arvif->bssid); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2658 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2659 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2660 | if (ret) |
| 2661 | ath10k_warn(ar, "faield to down vdev %i: %d\n", |
| 2662 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2663 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2664 | arvif->def_wep_key_idx = -1; |
| 2665 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2666 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2667 | if (ret) { |
| 2668 | ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n", |
| 2669 | arvif->vdev_id, ret); |
| 2670 | return; |
| 2671 | } |
| 2672 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2673 | arvif->is_up = false; |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 2674 | |
| 2675 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2676 | } |
| 2677 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2678 | static int ath10k_station_assoc(struct ath10k *ar, |
| 2679 | struct ieee80211_vif *vif, |
| 2680 | struct ieee80211_sta *sta, |
| 2681 | bool reassoc) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2682 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2683 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2684 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2685 | int ret = 0; |
| 2686 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2687 | lockdep_assert_held(&ar->conf_mutex); |
| 2688 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2689 | ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2690 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2691 | 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] | 2692 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2693 | return ret; |
| 2694 | } |
| 2695 | |
| 2696 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2697 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2698 | 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] | 2699 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2700 | return ret; |
| 2701 | } |
| 2702 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2703 | /* Re-assoc is run only to update supported rates for given station. It |
| 2704 | * doesn't make much sense to reconfigure the peer completely. |
| 2705 | */ |
| 2706 | if (!reassoc) { |
| 2707 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, |
| 2708 | &sta->ht_cap); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2709 | if (ret) { |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2710 | ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n", |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2711 | arvif->vdev_id, ret); |
| 2712 | return ret; |
| 2713 | } |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2714 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2715 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
| 2716 | if (ret) { |
| 2717 | ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", |
| 2718 | sta->addr, arvif->vdev_id, ret); |
| 2719 | return ret; |
| 2720 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2721 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2722 | if (!sta->wme) { |
| 2723 | arvif->num_legacy_stations++; |
| 2724 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 2725 | if (ret) { |
| 2726 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
| 2727 | arvif->vdev_id, ret); |
| 2728 | return ret; |
| 2729 | } |
| 2730 | } |
| 2731 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2732 | /* Plumb cached keys only for static WEP */ |
| 2733 | if (arvif->def_wep_key_idx != -1) { |
| 2734 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); |
| 2735 | if (ret) { |
| 2736 | ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", |
| 2737 | arvif->vdev_id, ret); |
| 2738 | return ret; |
| 2739 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2740 | } |
| 2741 | } |
| 2742 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2743 | return ret; |
| 2744 | } |
| 2745 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2746 | static int ath10k_station_disassoc(struct ath10k *ar, |
| 2747 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2748 | struct ieee80211_sta *sta) |
| 2749 | { |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2750 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2751 | int ret = 0; |
| 2752 | |
| 2753 | lockdep_assert_held(&ar->conf_mutex); |
| 2754 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 2755 | if (!sta->wme) { |
| 2756 | arvif->num_legacy_stations--; |
| 2757 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 2758 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2759 | 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] | 2760 | arvif->vdev_id, ret); |
| 2761 | return ret; |
| 2762 | } |
| 2763 | } |
| 2764 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2765 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
| 2766 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2767 | 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] | 2768 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2769 | return ret; |
| 2770 | } |
| 2771 | |
| 2772 | return ret; |
| 2773 | } |
| 2774 | |
| 2775 | /**************/ |
| 2776 | /* Regulatory */ |
| 2777 | /**************/ |
| 2778 | |
| 2779 | static int ath10k_update_channel_list(struct ath10k *ar) |
| 2780 | { |
| 2781 | struct ieee80211_hw *hw = ar->hw; |
| 2782 | struct ieee80211_supported_band **bands; |
| 2783 | enum ieee80211_band band; |
| 2784 | struct ieee80211_channel *channel; |
| 2785 | struct wmi_scan_chan_list_arg arg = {0}; |
| 2786 | struct wmi_channel_arg *ch; |
| 2787 | bool passive; |
| 2788 | int len; |
| 2789 | int ret; |
| 2790 | int i; |
| 2791 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2792 | lockdep_assert_held(&ar->conf_mutex); |
| 2793 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2794 | bands = hw->wiphy->bands; |
| 2795 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2796 | if (!bands[band]) |
| 2797 | continue; |
| 2798 | |
| 2799 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 2800 | if (bands[band]->channels[i].flags & |
| 2801 | IEEE80211_CHAN_DISABLED) |
| 2802 | continue; |
| 2803 | |
| 2804 | arg.n_channels++; |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; |
| 2809 | arg.channels = kzalloc(len, GFP_KERNEL); |
| 2810 | if (!arg.channels) |
| 2811 | return -ENOMEM; |
| 2812 | |
| 2813 | ch = arg.channels; |
| 2814 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2815 | if (!bands[band]) |
| 2816 | continue; |
| 2817 | |
| 2818 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 2819 | channel = &bands[band]->channels[i]; |
| 2820 | |
| 2821 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 2822 | continue; |
| 2823 | |
| 2824 | ch->allow_ht = true; |
| 2825 | |
| 2826 | /* FIXME: when should we really allow VHT? */ |
| 2827 | ch->allow_vht = true; |
| 2828 | |
| 2829 | ch->allow_ibss = |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2830 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2831 | |
| 2832 | ch->ht40plus = |
| 2833 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); |
| 2834 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 2835 | ch->chan_radar = |
| 2836 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
| 2837 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 2838 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2839 | ch->passive = passive; |
| 2840 | |
| 2841 | ch->freq = channel->center_freq; |
Michal Kazior | 2d66721 | 2014-09-18 15:21:21 +0200 | [diff] [blame] | 2842 | ch->band_center_freq1 = channel->center_freq; |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 2843 | ch->min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 2844 | ch->max_power = channel->max_power * 2; |
| 2845 | ch->max_reg_power = channel->max_reg_power * 2; |
| 2846 | ch->max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2847 | ch->reg_class_id = 0; /* FIXME */ |
| 2848 | |
| 2849 | /* FIXME: why use only legacy modes, why not any |
| 2850 | * HT/VHT modes? Would that even make any |
| 2851 | * difference? */ |
| 2852 | if (channel->band == IEEE80211_BAND_2GHZ) |
| 2853 | ch->mode = MODE_11G; |
| 2854 | else |
| 2855 | ch->mode = MODE_11A; |
| 2856 | |
| 2857 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) |
| 2858 | continue; |
| 2859 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2860 | ath10k_dbg(ar, ATH10K_DBG_WMI, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2861 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
| 2862 | ch - arg.channels, arg.n_channels, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2863 | ch->freq, ch->max_power, ch->max_reg_power, |
| 2864 | ch->max_antenna_gain, ch->mode); |
| 2865 | |
| 2866 | ch++; |
| 2867 | } |
| 2868 | } |
| 2869 | |
| 2870 | ret = ath10k_wmi_scan_chan_list(ar, &arg); |
| 2871 | kfree(arg.channels); |
| 2872 | |
| 2873 | return ret; |
| 2874 | } |
| 2875 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2876 | static enum wmi_dfs_region |
| 2877 | ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region) |
| 2878 | { |
| 2879 | switch (dfs_region) { |
| 2880 | case NL80211_DFS_UNSET: |
| 2881 | return WMI_UNINIT_DFS_DOMAIN; |
| 2882 | case NL80211_DFS_FCC: |
| 2883 | return WMI_FCC_DFS_DOMAIN; |
| 2884 | case NL80211_DFS_ETSI: |
| 2885 | return WMI_ETSI_DFS_DOMAIN; |
| 2886 | case NL80211_DFS_JP: |
| 2887 | return WMI_MKK4_DFS_DOMAIN; |
| 2888 | } |
| 2889 | return WMI_UNINIT_DFS_DOMAIN; |
| 2890 | } |
| 2891 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2892 | static void ath10k_regd_update(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2893 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2894 | struct reg_dmn_pair_mapping *regpair; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2895 | int ret; |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2896 | enum wmi_dfs_region wmi_dfs_reg; |
| 2897 | enum nl80211_dfs_regions nl_dfs_reg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2898 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2899 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2900 | |
| 2901 | ret = ath10k_update_channel_list(ar); |
| 2902 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2903 | ath10k_warn(ar, "failed to update channel list: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2904 | |
| 2905 | regpair = ar->ath_common.regulatory.regpair; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2906 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2907 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
| 2908 | nl_dfs_reg = ar->dfs_detector->region; |
| 2909 | wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg); |
| 2910 | } else { |
| 2911 | wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN; |
| 2912 | } |
| 2913 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2914 | /* Target allows setting up per-band regdomain but ath_common provides |
| 2915 | * a combined one only */ |
| 2916 | ret = ath10k_wmi_pdev_set_regdomain(ar, |
Kalle Valo | ef8c001 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 2917 | regpair->reg_domain, |
| 2918 | regpair->reg_domain, /* 2ghz */ |
| 2919 | regpair->reg_domain, /* 5ghz */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2920 | regpair->reg_2ghz_ctl, |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 2921 | regpair->reg_5ghz_ctl, |
| 2922 | wmi_dfs_reg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2923 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2924 | ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret); |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2925 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2926 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2927 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
| 2928 | struct regulatory_request *request) |
| 2929 | { |
| 2930 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 2931 | struct ath10k *ar = hw->priv; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2932 | bool result; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2933 | |
| 2934 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); |
| 2935 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2936 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2937 | ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 2938 | request->dfs_region); |
| 2939 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, |
| 2940 | request->dfs_region); |
| 2941 | if (!result) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2942 | 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] | 2943 | request->dfs_region); |
| 2944 | } |
| 2945 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 2946 | mutex_lock(&ar->conf_mutex); |
| 2947 | if (ar->state == ATH10K_STATE_ON) |
| 2948 | ath10k_regd_update(ar); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2949 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | /***************/ |
| 2953 | /* TX handlers */ |
| 2954 | /***************/ |
| 2955 | |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 2956 | void ath10k_mac_tx_lock(struct ath10k *ar, int reason) |
| 2957 | { |
| 2958 | lockdep_assert_held(&ar->htt.tx_lock); |
| 2959 | |
| 2960 | WARN_ON(reason >= ATH10K_TX_PAUSE_MAX); |
| 2961 | ar->tx_paused |= BIT(reason); |
| 2962 | ieee80211_stop_queues(ar->hw); |
| 2963 | } |
| 2964 | |
| 2965 | static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac, |
| 2966 | struct ieee80211_vif *vif) |
| 2967 | { |
| 2968 | struct ath10k *ar = data; |
| 2969 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 2970 | |
| 2971 | if (arvif->tx_paused) |
| 2972 | return; |
| 2973 | |
| 2974 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); |
| 2975 | } |
| 2976 | |
| 2977 | void ath10k_mac_tx_unlock(struct ath10k *ar, int reason) |
| 2978 | { |
| 2979 | lockdep_assert_held(&ar->htt.tx_lock); |
| 2980 | |
| 2981 | WARN_ON(reason >= ATH10K_TX_PAUSE_MAX); |
| 2982 | ar->tx_paused &= ~BIT(reason); |
| 2983 | |
| 2984 | if (ar->tx_paused) |
| 2985 | return; |
| 2986 | |
| 2987 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 2988 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 2989 | ath10k_mac_tx_unlock_iter, |
| 2990 | ar); |
| 2991 | } |
| 2992 | |
| 2993 | void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason) |
| 2994 | { |
| 2995 | struct ath10k *ar = arvif->ar; |
| 2996 | |
| 2997 | lockdep_assert_held(&ar->htt.tx_lock); |
| 2998 | |
| 2999 | WARN_ON(reason >= BITS_PER_LONG); |
| 3000 | arvif->tx_paused |= BIT(reason); |
| 3001 | ieee80211_stop_queue(ar->hw, arvif->vdev_id); |
| 3002 | } |
| 3003 | |
| 3004 | void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason) |
| 3005 | { |
| 3006 | struct ath10k *ar = arvif->ar; |
| 3007 | |
| 3008 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3009 | |
| 3010 | WARN_ON(reason >= BITS_PER_LONG); |
| 3011 | arvif->tx_paused &= ~BIT(reason); |
| 3012 | |
| 3013 | if (ar->tx_paused) |
| 3014 | return; |
| 3015 | |
| 3016 | if (arvif->tx_paused) |
| 3017 | return; |
| 3018 | |
| 3019 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); |
| 3020 | } |
| 3021 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3022 | static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif, |
| 3023 | enum wmi_tlv_tx_pause_id pause_id, |
| 3024 | enum wmi_tlv_tx_pause_action action) |
| 3025 | { |
| 3026 | struct ath10k *ar = arvif->ar; |
| 3027 | |
| 3028 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3029 | |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3030 | switch (action) { |
| 3031 | case WMI_TLV_TX_PAUSE_ACTION_STOP: |
| 3032 | ath10k_mac_vif_tx_lock(arvif, pause_id); |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3033 | break; |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3034 | case WMI_TLV_TX_PAUSE_ACTION_WAKE: |
| 3035 | ath10k_mac_vif_tx_unlock(arvif, pause_id); |
| 3036 | break; |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3037 | default: |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3038 | ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n", |
| 3039 | action, arvif->vdev_id); |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3040 | break; |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | struct ath10k_mac_tx_pause { |
| 3045 | u32 vdev_id; |
| 3046 | enum wmi_tlv_tx_pause_id pause_id; |
| 3047 | enum wmi_tlv_tx_pause_action action; |
| 3048 | }; |
| 3049 | |
| 3050 | static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac, |
| 3051 | struct ieee80211_vif *vif) |
| 3052 | { |
| 3053 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3054 | struct ath10k_mac_tx_pause *arg = data; |
| 3055 | |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3056 | if (arvif->vdev_id != arg->vdev_id) |
| 3057 | return; |
| 3058 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3059 | ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action); |
| 3060 | } |
| 3061 | |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3062 | void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id, |
| 3063 | enum wmi_tlv_tx_pause_id pause_id, |
| 3064 | enum wmi_tlv_tx_pause_action action) |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3065 | { |
| 3066 | struct ath10k_mac_tx_pause arg = { |
| 3067 | .vdev_id = vdev_id, |
| 3068 | .pause_id = pause_id, |
| 3069 | .action = action, |
| 3070 | }; |
| 3071 | |
| 3072 | spin_lock_bh(&ar->htt.tx_lock); |
| 3073 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 3074 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 3075 | ath10k_mac_handle_tx_pause_iter, |
| 3076 | &arg); |
| 3077 | spin_unlock_bh(&ar->htt.tx_lock); |
| 3078 | } |
| 3079 | |
Michal Kazior | 42c3aa6 | 2013-10-02 11:03:38 +0200 | [diff] [blame] | 3080 | static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr) |
| 3081 | { |
| 3082 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 3083 | return HTT_DATA_TX_EXT_TID_MGMT; |
| 3084 | |
| 3085 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 3086 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 3087 | |
| 3088 | if (!is_unicast_ether_addr(ieee80211_get_DA(hdr))) |
| 3089 | return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
| 3090 | |
| 3091 | return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK; |
| 3092 | } |
| 3093 | |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 3094 | 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] | 3095 | { |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 3096 | if (vif) |
| 3097 | return ath10k_vif_to_arvif(vif)->vdev_id; |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 3098 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3099 | if (ar->monitor_started) |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 3100 | return ar->monitor_vdev_id; |
| 3101 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3102 | ath10k_warn(ar, "failed to resolve vdev id\n"); |
Michal Kazior | ddb6ad7 | 2013-10-02 11:03:39 +0200 | [diff] [blame] | 3103 | return 0; |
| 3104 | } |
| 3105 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3106 | static enum ath10k_hw_txrx_mode |
| 3107 | ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif, |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3108 | struct ieee80211_sta *sta, struct sk_buff *skb) |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3109 | { |
| 3110 | const struct ieee80211_hdr *hdr = (void *)skb->data; |
| 3111 | __le16 fc = hdr->frame_control; |
| 3112 | |
| 3113 | if (!vif || vif->type == NL80211_IFTYPE_MONITOR) |
| 3114 | return ATH10K_HW_TXRX_RAW; |
| 3115 | |
| 3116 | if (ieee80211_is_mgmt(fc)) |
| 3117 | return ATH10K_HW_TXRX_MGMT; |
| 3118 | |
| 3119 | /* Workaround: |
| 3120 | * |
| 3121 | * NullFunc frames are mostly used to ping if a client or AP are still |
| 3122 | * reachable and responsive. This implies tx status reports must be |
| 3123 | * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can |
| 3124 | * come to a conclusion that the other end disappeared and tear down |
| 3125 | * BSS connection or it can never disconnect from BSS/client (which is |
| 3126 | * the case). |
| 3127 | * |
| 3128 | * Firmware with HTT older than 3.0 delivers incorrect tx status for |
| 3129 | * NullFunc frames to driver. However there's a HTT Mgmt Tx command |
| 3130 | * which seems to deliver correct tx reports for NullFunc frames. The |
| 3131 | * downside of using it is it ignores client powersave state so it can |
| 3132 | * end up disconnecting sleeping clients in AP mode. It should fix STA |
| 3133 | * mode though because AP don't sleep. |
| 3134 | */ |
| 3135 | if (ar->htt.target_version_major < 3 && |
| 3136 | (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) && |
| 3137 | !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features)) |
| 3138 | return ATH10K_HW_TXRX_MGMT; |
| 3139 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3140 | /* Workaround: |
| 3141 | * |
| 3142 | * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for |
| 3143 | * NativeWifi txmode - it selects AP key instead of peer key. It seems |
| 3144 | * to work with Ethernet txmode so use it. |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3145 | * |
| 3146 | * FIXME: Check if raw mode works with TDLS. |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3147 | */ |
| 3148 | if (ieee80211_is_data_present(fc) && sta && sta->tdls) |
| 3149 | return ATH10K_HW_TXRX_ETHERNET; |
| 3150 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3151 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
| 3152 | return ATH10K_HW_TXRX_RAW; |
| 3153 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3154 | return ATH10K_HW_TXRX_NATIVE_WIFI; |
| 3155 | } |
| 3156 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3157 | static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif, |
| 3158 | struct sk_buff *skb) { |
| 3159 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 3160 | const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 3161 | IEEE80211_TX_CTL_INJECTED; |
| 3162 | if ((info->flags & mask) == mask) |
| 3163 | return false; |
| 3164 | if (vif) |
| 3165 | return !ath10k_vif_to_arvif(vif)->nohwcrypt; |
| 3166 | return true; |
| 3167 | } |
| 3168 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3169 | /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS |
| 3170 | * Control in the header. |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3171 | */ |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3172 | 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] | 3173 | { |
| 3174 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3175 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3176 | u8 *qos_ctl; |
| 3177 | |
| 3178 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 3179 | return; |
| 3180 | |
| 3181 | qos_ctl = ieee80211_get_qos_ctl(hdr); |
Michal Kazior | ba0ccd7 | 2013-07-22 14:25:28 +0200 | [diff] [blame] | 3182 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
| 3183 | skb->data, (void *)qos_ctl - (void *)skb->data); |
| 3184 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3185 | |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 3186 | /* Some firmware revisions don't handle sending QoS NullFunc well. |
| 3187 | * These frames are mainly used for CQM purposes so it doesn't really |
| 3188 | * matter whether QoS NullFunc or NullFunc are sent. |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3189 | */ |
Michal Kazior | bf0a26d | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 3190 | hdr = (void *)skb->data; |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 3191 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3192 | cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST; |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 3193 | |
| 3194 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3195 | } |
| 3196 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3197 | static void ath10k_tx_h_8023(struct sk_buff *skb) |
| 3198 | { |
| 3199 | struct ieee80211_hdr *hdr; |
| 3200 | struct rfc1042_hdr *rfc1042; |
| 3201 | struct ethhdr *eth; |
| 3202 | size_t hdrlen; |
| 3203 | u8 da[ETH_ALEN]; |
| 3204 | u8 sa[ETH_ALEN]; |
| 3205 | __be16 type; |
| 3206 | |
| 3207 | hdr = (void *)skb->data; |
| 3208 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 3209 | rfc1042 = (void *)skb->data + hdrlen; |
| 3210 | |
| 3211 | ether_addr_copy(da, ieee80211_get_DA(hdr)); |
| 3212 | ether_addr_copy(sa, ieee80211_get_SA(hdr)); |
| 3213 | type = rfc1042->snap_type; |
| 3214 | |
| 3215 | skb_pull(skb, hdrlen + sizeof(*rfc1042)); |
| 3216 | skb_push(skb, sizeof(*eth)); |
| 3217 | |
| 3218 | eth = (void *)skb->data; |
| 3219 | ether_addr_copy(eth->h_dest, da); |
| 3220 | ether_addr_copy(eth->h_source, sa); |
| 3221 | eth->h_proto = type; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3222 | } |
| 3223 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3224 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, |
| 3225 | struct ieee80211_vif *vif, |
| 3226 | struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3227 | { |
| 3228 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3229 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 3230 | |
| 3231 | /* This is case only for P2P_GO */ |
| 3232 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP || |
| 3233 | arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO) |
| 3234 | return; |
| 3235 | |
| 3236 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { |
| 3237 | spin_lock_bh(&ar->data_lock); |
| 3238 | if (arvif->u.ap.noa_data) |
| 3239 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, |
| 3240 | GFP_ATOMIC)) |
| 3241 | memcpy(skb_put(skb, arvif->u.ap.noa_len), |
| 3242 | arvif->u.ap.noa_data, |
| 3243 | arvif->u.ap.noa_len); |
| 3244 | spin_unlock_bh(&ar->data_lock); |
| 3245 | } |
| 3246 | } |
| 3247 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3248 | static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar) |
| 3249 | { |
| 3250 | /* FIXME: Not really sure since when the behaviour changed. At some |
| 3251 | * point new firmware stopped requiring creation of peer entries for |
| 3252 | * offchannel tx (and actually creating them causes issues with wmi-htc |
| 3253 | * tx credit replenishment and reliability). Assuming it's at least 3.4 |
| 3254 | * because that's when the `freq` was introduced to TX_FRM HTT command. |
| 3255 | */ |
| 3256 | return !(ar->htt.target_version_major >= 3 && |
| 3257 | ar->htt.target_version_minor >= 4); |
| 3258 | } |
| 3259 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3260 | static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3261 | { |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3262 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3263 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3264 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3265 | spin_lock_bh(&ar->data_lock); |
| 3266 | |
| 3267 | if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) { |
| 3268 | ath10k_warn(ar, "wmi mgmt tx queue is full\n"); |
| 3269 | ret = -ENOSPC; |
| 3270 | goto unlock; |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 3271 | } |
| 3272 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3273 | __skb_queue_tail(q, skb); |
| 3274 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); |
| 3275 | |
| 3276 | unlock: |
| 3277 | spin_unlock_bh(&ar->data_lock); |
| 3278 | |
| 3279 | return ret; |
| 3280 | } |
| 3281 | |
| 3282 | static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb) |
| 3283 | { |
| 3284 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
| 3285 | struct ath10k_htt *htt = &ar->htt; |
| 3286 | int ret = 0; |
| 3287 | |
| 3288 | switch (cb->txmode) { |
| 3289 | case ATH10K_HW_TXRX_RAW: |
| 3290 | case ATH10K_HW_TXRX_NATIVE_WIFI: |
| 3291 | case ATH10K_HW_TXRX_ETHERNET: |
| 3292 | ret = ath10k_htt_tx(htt, skb); |
| 3293 | break; |
| 3294 | case ATH10K_HW_TXRX_MGMT: |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3295 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3296 | ar->fw_features)) |
| 3297 | ret = ath10k_mac_tx_wmi_mgmt(ar, skb); |
| 3298 | else if (ar->htt.target_version_major >= 3) |
| 3299 | ret = ath10k_htt_tx(htt, skb); |
| 3300 | else |
| 3301 | ret = ath10k_htt_mgmt_tx(htt, skb); |
| 3302 | break; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3303 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3304 | |
| 3305 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3306 | ath10k_warn(ar, "failed to transmit packet, dropping: %d\n", |
| 3307 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3308 | ieee80211_free_txskb(ar->hw, skb); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | void ath10k_offchan_tx_purge(struct ath10k *ar) |
| 3313 | { |
| 3314 | struct sk_buff *skb; |
| 3315 | |
| 3316 | for (;;) { |
| 3317 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 3318 | if (!skb) |
| 3319 | break; |
| 3320 | |
| 3321 | ieee80211_free_txskb(ar->hw, skb); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | void ath10k_offchan_tx_work(struct work_struct *work) |
| 3326 | { |
| 3327 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); |
| 3328 | struct ath10k_peer *peer; |
| 3329 | struct ieee80211_hdr *hdr; |
| 3330 | struct sk_buff *skb; |
| 3331 | const u8 *peer_addr; |
| 3332 | int vdev_id; |
| 3333 | int ret; |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 3334 | unsigned long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3335 | |
| 3336 | /* FW requirement: We must create a peer before FW will send out |
| 3337 | * an offchannel frame. Otherwise the frame will be stuck and |
| 3338 | * never transmitted. We delete the peer upon tx completion. |
| 3339 | * It is unlikely that a peer for offchannel tx will already be |
| 3340 | * present. However it may be in some rare cases so account for that. |
| 3341 | * Otherwise we might remove a legitimate peer and break stuff. */ |
| 3342 | |
| 3343 | for (;;) { |
| 3344 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 3345 | if (!skb) |
| 3346 | break; |
| 3347 | |
| 3348 | mutex_lock(&ar->conf_mutex); |
| 3349 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3350 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3351 | skb); |
| 3352 | |
| 3353 | hdr = (struct ieee80211_hdr *)skb->data; |
| 3354 | peer_addr = ieee80211_get_DA(hdr); |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3355 | vdev_id = ATH10K_SKB_CB(skb)->vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3356 | |
| 3357 | spin_lock_bh(&ar->data_lock); |
| 3358 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); |
| 3359 | spin_unlock_bh(&ar->data_lock); |
| 3360 | |
| 3361 | if (peer) |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3362 | /* FIXME: should this use ath10k_warn()? */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3363 | 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] | 3364 | peer_addr, vdev_id); |
| 3365 | |
| 3366 | if (!peer) { |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 3367 | ret = ath10k_peer_create(ar, vdev_id, peer_addr, |
| 3368 | WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3369 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3370 | 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] | 3371 | peer_addr, vdev_id, ret); |
| 3372 | } |
| 3373 | |
| 3374 | spin_lock_bh(&ar->data_lock); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 3375 | reinit_completion(&ar->offchan_tx_completed); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3376 | ar->offchan_tx_skb = skb; |
| 3377 | spin_unlock_bh(&ar->data_lock); |
| 3378 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3379 | ath10k_mac_tx(ar, skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3380 | |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 3381 | time_left = |
| 3382 | wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ); |
| 3383 | if (time_left == 0) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3384 | ath10k_warn(ar, "timed out waiting for offchannel skb %p\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3385 | skb); |
| 3386 | |
| 3387 | if (!peer) { |
| 3388 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); |
| 3389 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3390 | 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] | 3391 | peer_addr, vdev_id, ret); |
| 3392 | } |
| 3393 | |
| 3394 | mutex_unlock(&ar->conf_mutex); |
| 3395 | } |
| 3396 | } |
| 3397 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3398 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
| 3399 | { |
| 3400 | struct sk_buff *skb; |
| 3401 | |
| 3402 | for (;;) { |
| 3403 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 3404 | if (!skb) |
| 3405 | break; |
| 3406 | |
| 3407 | ieee80211_free_txskb(ar->hw, skb); |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) |
| 3412 | { |
| 3413 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); |
| 3414 | struct sk_buff *skb; |
| 3415 | int ret; |
| 3416 | |
| 3417 | for (;;) { |
| 3418 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 3419 | if (!skb) |
| 3420 | break; |
| 3421 | |
| 3422 | ret = ath10k_wmi_mgmt_tx(ar, skb); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 3423 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3424 | ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 3425 | ret); |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 3426 | ieee80211_free_txskb(ar->hw, skb); |
| 3427 | } |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3428 | } |
| 3429 | } |
| 3430 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3431 | /************/ |
| 3432 | /* Scanning */ |
| 3433 | /************/ |
| 3434 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3435 | void __ath10k_scan_finish(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3436 | { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3437 | lockdep_assert_held(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3438 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3439 | switch (ar->scan.state) { |
| 3440 | case ATH10K_SCAN_IDLE: |
| 3441 | break; |
| 3442 | case ATH10K_SCAN_RUNNING: |
Michal Kazior | 7305d3e | 2014-11-24 14:58:33 +0100 | [diff] [blame] | 3443 | case ATH10K_SCAN_ABORTING: |
| 3444 | if (!ar->scan.is_roc) |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3445 | ieee80211_scan_completed(ar->hw, |
| 3446 | (ar->scan.state == |
| 3447 | ATH10K_SCAN_ABORTING)); |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 3448 | else if (ar->scan.roc_notify) |
| 3449 | ieee80211_remain_on_channel_expired(ar->hw); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3450 | /* fall through */ |
| 3451 | case ATH10K_SCAN_STARTING: |
| 3452 | ar->scan.state = ATH10K_SCAN_IDLE; |
| 3453 | ar->scan_channel = NULL; |
| 3454 | ath10k_offchan_tx_purge(ar); |
| 3455 | cancel_delayed_work(&ar->scan.timeout); |
| 3456 | complete_all(&ar->scan.completed); |
| 3457 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3458 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3459 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3460 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3461 | void ath10k_scan_finish(struct ath10k *ar) |
| 3462 | { |
| 3463 | spin_lock_bh(&ar->data_lock); |
| 3464 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3465 | spin_unlock_bh(&ar->data_lock); |
| 3466 | } |
| 3467 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3468 | static int ath10k_scan_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3469 | { |
| 3470 | struct wmi_stop_scan_arg arg = { |
| 3471 | .req_id = 1, /* FIXME */ |
| 3472 | .req_type = WMI_SCAN_STOP_ONE, |
| 3473 | .u.scan_id = ATH10K_SCAN_ID, |
| 3474 | }; |
| 3475 | int ret; |
| 3476 | |
| 3477 | lockdep_assert_held(&ar->conf_mutex); |
| 3478 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3479 | ret = ath10k_wmi_stop_scan(ar, &arg); |
| 3480 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3481 | ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3482 | goto out; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3483 | } |
| 3484 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3485 | ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3486 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3487 | ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3488 | ret = -ETIMEDOUT; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3489 | } else if (ret > 0) { |
| 3490 | ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3491 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3492 | |
| 3493 | out: |
| 3494 | /* Scan state should be updated upon scan completion but in case |
| 3495 | * firmware fails to deliver the event (for whatever reason) it is |
| 3496 | * desired to clean up scan state anyway. Firmware may have just |
| 3497 | * dropped the scan completion event delivery due to transport pipe |
| 3498 | * being overflown with data and/or it can recover on its own before |
| 3499 | * next scan request is submitted. |
| 3500 | */ |
| 3501 | spin_lock_bh(&ar->data_lock); |
| 3502 | if (ar->scan.state != ATH10K_SCAN_IDLE) |
| 3503 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3504 | spin_unlock_bh(&ar->data_lock); |
| 3505 | |
| 3506 | return ret; |
| 3507 | } |
| 3508 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3509 | static void ath10k_scan_abort(struct ath10k *ar) |
| 3510 | { |
| 3511 | int ret; |
| 3512 | |
| 3513 | lockdep_assert_held(&ar->conf_mutex); |
| 3514 | |
| 3515 | spin_lock_bh(&ar->data_lock); |
| 3516 | |
| 3517 | switch (ar->scan.state) { |
| 3518 | case ATH10K_SCAN_IDLE: |
| 3519 | /* This can happen if timeout worker kicked in and called |
| 3520 | * abortion while scan completion was being processed. |
| 3521 | */ |
| 3522 | break; |
| 3523 | case ATH10K_SCAN_STARTING: |
| 3524 | case ATH10K_SCAN_ABORTING: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3525 | 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] | 3526 | ath10k_scan_state_str(ar->scan.state), |
| 3527 | ar->scan.state); |
| 3528 | break; |
| 3529 | case ATH10K_SCAN_RUNNING: |
| 3530 | ar->scan.state = ATH10K_SCAN_ABORTING; |
| 3531 | spin_unlock_bh(&ar->data_lock); |
| 3532 | |
| 3533 | ret = ath10k_scan_stop(ar); |
| 3534 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3535 | ath10k_warn(ar, "failed to abort scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3536 | |
| 3537 | spin_lock_bh(&ar->data_lock); |
| 3538 | break; |
| 3539 | } |
| 3540 | |
| 3541 | spin_unlock_bh(&ar->data_lock); |
| 3542 | } |
| 3543 | |
| 3544 | void ath10k_scan_timeout_work(struct work_struct *work) |
| 3545 | { |
| 3546 | struct ath10k *ar = container_of(work, struct ath10k, |
| 3547 | scan.timeout.work); |
| 3548 | |
| 3549 | mutex_lock(&ar->conf_mutex); |
| 3550 | ath10k_scan_abort(ar); |
| 3551 | mutex_unlock(&ar->conf_mutex); |
| 3552 | } |
| 3553 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3554 | static int ath10k_start_scan(struct ath10k *ar, |
| 3555 | const struct wmi_start_scan_arg *arg) |
| 3556 | { |
| 3557 | int ret; |
| 3558 | |
| 3559 | lockdep_assert_held(&ar->conf_mutex); |
| 3560 | |
| 3561 | ret = ath10k_wmi_start_scan(ar, arg); |
| 3562 | if (ret) |
| 3563 | return ret; |
| 3564 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3565 | ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ); |
| 3566 | if (ret == 0) { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3567 | ret = ath10k_scan_stop(ar); |
| 3568 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3569 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3570 | |
| 3571 | return -ETIMEDOUT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3572 | } |
| 3573 | |
Ben Greear | 2f9eec0 | 2015-02-15 16:50:38 +0200 | [diff] [blame] | 3574 | /* If we failed to start the scan, return error code at |
| 3575 | * this point. This is probably due to some issue in the |
| 3576 | * firmware, but no need to wedge the driver due to that... |
| 3577 | */ |
| 3578 | spin_lock_bh(&ar->data_lock); |
| 3579 | if (ar->scan.state == ATH10K_SCAN_IDLE) { |
| 3580 | spin_unlock_bh(&ar->data_lock); |
| 3581 | return -EINVAL; |
| 3582 | } |
| 3583 | spin_unlock_bh(&ar->data_lock); |
| 3584 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3585 | /* Add a 200ms margin to account for event/command processing */ |
| 3586 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
| 3587 | msecs_to_jiffies(arg->max_scan_time+200)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3588 | return 0; |
| 3589 | } |
| 3590 | |
| 3591 | /**********************/ |
| 3592 | /* mac80211 callbacks */ |
| 3593 | /**********************/ |
| 3594 | |
| 3595 | static void ath10k_tx(struct ieee80211_hw *hw, |
| 3596 | struct ieee80211_tx_control *control, |
| 3597 | struct sk_buff *skb) |
| 3598 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3599 | struct ath10k *ar = hw->priv; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3600 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 3601 | struct ieee80211_vif *vif = info->control.vif; |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3602 | struct ieee80211_sta *sta = control->sta; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3603 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3604 | __le16 fc = hdr->frame_control; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3605 | |
| 3606 | /* We should disable CCK RATE due to P2P */ |
| 3607 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3608 | 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] | 3609 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3610 | ATH10K_SKB_CB(skb)->htt.is_offchan = false; |
Michal Kazior | 6fcafef | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3611 | ATH10K_SKB_CB(skb)->htt.freq = 0; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3612 | ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3613 | ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb); |
Michal Kazior | 2b37c29 | 2014-09-02 11:00:22 +0300 | [diff] [blame] | 3614 | ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3615 | ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb); |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3616 | ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3617 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3618 | switch (ATH10K_SKB_CB(skb)->txmode) { |
| 3619 | case ATH10K_HW_TXRX_MGMT: |
| 3620 | case ATH10K_HW_TXRX_NATIVE_WIFI: |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3621 | ath10k_tx_h_nwifi(hw, skb); |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3622 | ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb); |
| 3623 | ath10k_tx_h_seq_no(vif, skb); |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3624 | break; |
| 3625 | case ATH10K_HW_TXRX_ETHERNET: |
| 3626 | ath10k_tx_h_8023(skb); |
| 3627 | break; |
| 3628 | case ATH10K_HW_TXRX_RAW: |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3629 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
| 3630 | WARN_ON_ONCE(1); |
| 3631 | ieee80211_free_txskb(hw, skb); |
| 3632 | return; |
| 3633 | } |
Michal Kazior | cf84bd4 | 2013-07-16 11:04:54 +0200 | [diff] [blame] | 3634 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3635 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3636 | if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { |
| 3637 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3638 | ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3639 | ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3640 | spin_unlock_bh(&ar->data_lock); |
| 3641 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3642 | if (ath10k_mac_need_offchan_tx_work(ar)) { |
| 3643 | ATH10K_SKB_CB(skb)->htt.freq = 0; |
| 3644 | ATH10K_SKB_CB(skb)->htt.is_offchan = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3645 | |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3646 | ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n", |
| 3647 | skb); |
| 3648 | |
| 3649 | skb_queue_tail(&ar->offchan_tx_queue, skb); |
| 3650 | ieee80211_queue_work(hw, &ar->offchan_tx_work); |
| 3651 | return; |
| 3652 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3653 | } |
| 3654 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3655 | ath10k_mac_tx(ar, skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3656 | } |
| 3657 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3658 | /* Must not be called with conf_mutex held as workers can use that also. */ |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 3659 | void ath10k_drain_tx(struct ath10k *ar) |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3660 | { |
| 3661 | /* make sure rcu-protected mac80211 tx path itself is drained */ |
| 3662 | synchronize_net(); |
| 3663 | |
| 3664 | ath10k_offchan_tx_purge(ar); |
| 3665 | ath10k_mgmt_over_wmi_tx_purge(ar); |
| 3666 | |
| 3667 | cancel_work_sync(&ar->offchan_tx_work); |
| 3668 | cancel_work_sync(&ar->wmi_mgmt_tx_work); |
| 3669 | } |
| 3670 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3671 | void ath10k_halt(struct ath10k *ar) |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3672 | { |
Michal Kazior | d9bc4b9 | 2014-04-23 19:30:06 +0300 | [diff] [blame] | 3673 | struct ath10k_vif *arvif; |
| 3674 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3675 | lockdep_assert_held(&ar->conf_mutex); |
| 3676 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3677 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 3678 | ar->filter_flags = 0; |
| 3679 | ar->monitor = false; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 3680 | ar->monitor_arvif = NULL; |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3681 | |
| 3682 | if (ar->monitor_started) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3683 | ath10k_monitor_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 3684 | |
| 3685 | ar->monitor_started = false; |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 3686 | ar->tx_paused = 0; |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 3687 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3688 | ath10k_scan_finish(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3689 | ath10k_peer_cleanup_all(ar); |
| 3690 | ath10k_core_stop(ar); |
| 3691 | ath10k_hif_power_down(ar); |
| 3692 | |
| 3693 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 3694 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 3695 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3696 | spin_unlock_bh(&ar->data_lock); |
| 3697 | } |
| 3698 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3699 | static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 3700 | { |
| 3701 | struct ath10k *ar = hw->priv; |
| 3702 | |
| 3703 | mutex_lock(&ar->conf_mutex); |
| 3704 | |
| 3705 | if (ar->cfg_tx_chainmask) { |
| 3706 | *tx_ant = ar->cfg_tx_chainmask; |
| 3707 | *rx_ant = ar->cfg_rx_chainmask; |
| 3708 | } else { |
| 3709 | *tx_ant = ar->supp_tx_chainmask; |
| 3710 | *rx_ant = ar->supp_rx_chainmask; |
| 3711 | } |
| 3712 | |
| 3713 | mutex_unlock(&ar->conf_mutex); |
| 3714 | |
| 3715 | return 0; |
| 3716 | } |
| 3717 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3718 | static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg) |
| 3719 | { |
| 3720 | /* It is not clear that allowing gaps in chainmask |
| 3721 | * is helpful. Probably it will not do what user |
| 3722 | * is hoping for, so warn in that case. |
| 3723 | */ |
| 3724 | if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0) |
| 3725 | return; |
| 3726 | |
| 3727 | ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n", |
| 3728 | dbg, cm); |
| 3729 | } |
| 3730 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3731 | static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant) |
| 3732 | { |
| 3733 | int ret; |
| 3734 | |
| 3735 | lockdep_assert_held(&ar->conf_mutex); |
| 3736 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 3737 | ath10k_check_chain_mask(ar, tx_ant, "tx"); |
| 3738 | ath10k_check_chain_mask(ar, rx_ant, "rx"); |
| 3739 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3740 | ar->cfg_tx_chainmask = tx_ant; |
| 3741 | ar->cfg_rx_chainmask = rx_ant; |
| 3742 | |
| 3743 | if ((ar->state != ATH10K_STATE_ON) && |
| 3744 | (ar->state != ATH10K_STATE_RESTARTED)) |
| 3745 | return 0; |
| 3746 | |
| 3747 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask, |
| 3748 | tx_ant); |
| 3749 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3750 | 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] | 3751 | ret, tx_ant); |
| 3752 | return ret; |
| 3753 | } |
| 3754 | |
| 3755 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask, |
| 3756 | rx_ant); |
| 3757 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3758 | 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] | 3759 | ret, rx_ant); |
| 3760 | return ret; |
| 3761 | } |
| 3762 | |
| 3763 | return 0; |
| 3764 | } |
| 3765 | |
| 3766 | static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 3767 | { |
| 3768 | struct ath10k *ar = hw->priv; |
| 3769 | int ret; |
| 3770 | |
| 3771 | mutex_lock(&ar->conf_mutex); |
| 3772 | ret = __ath10k_set_antenna(ar, tx_ant, rx_ant); |
| 3773 | mutex_unlock(&ar->conf_mutex); |
| 3774 | return ret; |
| 3775 | } |
| 3776 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3777 | static int ath10k_start(struct ieee80211_hw *hw) |
| 3778 | { |
| 3779 | struct ath10k *ar = hw->priv; |
Janusz Dziedzic | 24ab13e | 2015-04-01 22:53:18 +0300 | [diff] [blame] | 3780 | u32 burst_enable; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3781 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3782 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3783 | /* |
| 3784 | * This makes sense only when restarting hw. It is harmless to call |
| 3785 | * uncoditionally. This is necessary to make sure no HTT/WMI tx |
| 3786 | * commands will be submitted while restarting. |
| 3787 | */ |
| 3788 | ath10k_drain_tx(ar); |
| 3789 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3790 | mutex_lock(&ar->conf_mutex); |
| 3791 | |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3792 | switch (ar->state) { |
| 3793 | case ATH10K_STATE_OFF: |
| 3794 | ar->state = ATH10K_STATE_ON; |
| 3795 | break; |
| 3796 | case ATH10K_STATE_RESTARTING: |
| 3797 | ath10k_halt(ar); |
| 3798 | ar->state = ATH10K_STATE_RESTARTED; |
| 3799 | break; |
| 3800 | case ATH10K_STATE_ON: |
| 3801 | case ATH10K_STATE_RESTARTED: |
| 3802 | case ATH10K_STATE_WEDGED: |
| 3803 | WARN_ON(1); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3804 | ret = -EINVAL; |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3805 | goto err; |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 3806 | case ATH10K_STATE_UTF: |
| 3807 | ret = -EBUSY; |
| 3808 | goto err; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | ret = ath10k_hif_power_up(ar); |
| 3812 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3813 | ath10k_err(ar, "Could not init hif: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3814 | goto err_off; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3815 | } |
| 3816 | |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 3817 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3818 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3819 | ath10k_err(ar, "Could not init core: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3820 | goto err_power_down; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3821 | } |
| 3822 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 3823 | 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] | 3824 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3825 | ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3826 | goto err_core_stop; |
| 3827 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3828 | |
Michal Kazior | c4dd0d0 | 2013-11-13 11:05:10 +0100 | [diff] [blame] | 3829 | 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] | 3830 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3831 | ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3832 | goto err_core_stop; |
| 3833 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3834 | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 3835 | if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) { |
| 3836 | ret = ath10k_wmi_adaptive_qcs(ar, true); |
| 3837 | if (ret) { |
| 3838 | ath10k_warn(ar, "failed to enable adaptive qcs: %d\n", |
| 3839 | ret); |
| 3840 | goto err_core_stop; |
| 3841 | } |
| 3842 | } |
| 3843 | |
Janusz Dziedzic | 24ab13e | 2015-04-01 22:53:18 +0300 | [diff] [blame] | 3844 | if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) { |
| 3845 | burst_enable = ar->wmi.pdev_param->burst_enable; |
| 3846 | ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0); |
| 3847 | if (ret) { |
| 3848 | ath10k_warn(ar, "failed to disable burst: %d\n", ret); |
| 3849 | goto err_core_stop; |
| 3850 | } |
| 3851 | } |
| 3852 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 3853 | if (ar->cfg_tx_chainmask) |
| 3854 | __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, |
| 3855 | ar->cfg_rx_chainmask); |
| 3856 | |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3857 | /* |
| 3858 | * By default FW set ARP frames ac to voice (6). In that case ARP |
| 3859 | * exchange is not working properly for UAPSD enabled AP. ARP requests |
| 3860 | * which arrives with access category 0 are processed by network stack |
| 3861 | * and send back with access category 0, but FW changes access category |
| 3862 | * to 6. Set ARP frames access category to best effort (0) solves |
| 3863 | * this problem. |
| 3864 | */ |
| 3865 | |
| 3866 | ret = ath10k_wmi_pdev_set_param(ar, |
| 3867 | ar->wmi.pdev_param->arp_ac_override, 0); |
| 3868 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3869 | ath10k_warn(ar, "failed to set arp ac override parameter: %d\n", |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3870 | ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3871 | goto err_core_stop; |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 3872 | } |
| 3873 | |
Ashok Raj Nagarajan | 575f1c3 | 2015-03-19 16:37:59 +0530 | [diff] [blame] | 3874 | ret = ath10k_wmi_pdev_set_param(ar, |
| 3875 | ar->wmi.pdev_param->ani_enable, 1); |
| 3876 | if (ret) { |
| 3877 | ath10k_warn(ar, "failed to enable ani by default: %d\n", |
| 3878 | ret); |
| 3879 | goto err_core_stop; |
| 3880 | } |
| 3881 | |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 3882 | ar->ani_enabled = true; |
| 3883 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 3884 | ar->num_started_vdevs = 0; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3885 | ath10k_regd_update(ar); |
| 3886 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3887 | ath10k_spectral_start(ar); |
Rajkumar Manoharan | 8515b5c | 2015-03-15 20:36:22 +0530 | [diff] [blame] | 3888 | ath10k_thermal_set_throttling(ar); |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 3889 | |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 3890 | mutex_unlock(&ar->conf_mutex); |
| 3891 | return 0; |
| 3892 | |
| 3893 | err_core_stop: |
| 3894 | ath10k_core_stop(ar); |
| 3895 | |
| 3896 | err_power_down: |
| 3897 | ath10k_hif_power_down(ar); |
| 3898 | |
| 3899 | err_off: |
| 3900 | ar->state = ATH10K_STATE_OFF; |
| 3901 | |
| 3902 | err: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3903 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | c60bdd8 | 2014-01-29 07:26:31 +0100 | [diff] [blame] | 3904 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | static void ath10k_stop(struct ieee80211_hw *hw) |
| 3908 | { |
| 3909 | struct ath10k *ar = hw->priv; |
| 3910 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3911 | ath10k_drain_tx(ar); |
| 3912 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3913 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3914 | if (ar->state != ATH10K_STATE_OFF) { |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 3915 | ath10k_halt(ar); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 3916 | ar->state = ATH10K_STATE_OFF; |
| 3917 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3918 | mutex_unlock(&ar->conf_mutex); |
| 3919 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 3920 | cancel_delayed_work_sync(&ar->scan.timeout); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3921 | cancel_work_sync(&ar->restart_work); |
| 3922 | } |
| 3923 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3924 | static int ath10k_config_ps(struct ath10k *ar) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3925 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3926 | struct ath10k_vif *arvif; |
| 3927 | int ret = 0; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3928 | |
| 3929 | lockdep_assert_held(&ar->conf_mutex); |
| 3930 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3931 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3932 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 3933 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3934 | ath10k_warn(ar, "failed to setup powersave: %d\n", ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3935 | break; |
| 3936 | } |
| 3937 | } |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 3938 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 3939 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3940 | } |
| 3941 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 3942 | static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower) |
| 3943 | { |
| 3944 | int ret; |
| 3945 | u32 param; |
| 3946 | |
| 3947 | lockdep_assert_held(&ar->conf_mutex); |
| 3948 | |
| 3949 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower); |
| 3950 | |
| 3951 | param = ar->wmi.pdev_param->txpower_limit2g; |
| 3952 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 3953 | if (ret) { |
| 3954 | ath10k_warn(ar, "failed to set 2g txpower %d: %d\n", |
| 3955 | txpower, ret); |
| 3956 | return ret; |
| 3957 | } |
| 3958 | |
| 3959 | param = ar->wmi.pdev_param->txpower_limit5g; |
| 3960 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 3961 | if (ret) { |
| 3962 | ath10k_warn(ar, "failed to set 5g txpower %d: %d\n", |
| 3963 | txpower, ret); |
| 3964 | return ret; |
| 3965 | } |
| 3966 | |
| 3967 | return 0; |
| 3968 | } |
| 3969 | |
| 3970 | static int ath10k_mac_txpower_recalc(struct ath10k *ar) |
| 3971 | { |
| 3972 | struct ath10k_vif *arvif; |
| 3973 | int ret, txpower = -1; |
| 3974 | |
| 3975 | lockdep_assert_held(&ar->conf_mutex); |
| 3976 | |
| 3977 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 3978 | WARN_ON(arvif->txpower < 0); |
| 3979 | |
| 3980 | if (txpower == -1) |
| 3981 | txpower = arvif->txpower; |
| 3982 | else |
| 3983 | txpower = min(txpower, arvif->txpower); |
| 3984 | } |
| 3985 | |
| 3986 | if (WARN_ON(txpower == -1)) |
| 3987 | return -EINVAL; |
| 3988 | |
| 3989 | ret = ath10k_mac_txpower_setup(ar, txpower); |
| 3990 | if (ret) { |
| 3991 | ath10k_warn(ar, "failed to setup tx power %d: %d\n", |
| 3992 | txpower, ret); |
| 3993 | return ret; |
| 3994 | } |
| 3995 | |
| 3996 | return 0; |
| 3997 | } |
| 3998 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3999 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
| 4000 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4001 | struct ath10k *ar = hw->priv; |
| 4002 | struct ieee80211_conf *conf = &hw->conf; |
| 4003 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4004 | |
| 4005 | mutex_lock(&ar->conf_mutex); |
| 4006 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4007 | if (changed & IEEE80211_CONF_CHANGE_PS) |
| 4008 | ath10k_config_ps(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4009 | |
| 4010 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 4011 | ar->monitor = conf->flags & IEEE80211_CONF_MONITOR; |
| 4012 | ret = ath10k_monitor_recalc(ar); |
| 4013 | if (ret) |
| 4014 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4015 | } |
| 4016 | |
| 4017 | mutex_unlock(&ar->conf_mutex); |
| 4018 | return ret; |
| 4019 | } |
| 4020 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4021 | static u32 get_nss_from_chainmask(u16 chain_mask) |
| 4022 | { |
| 4023 | if ((chain_mask & 0x15) == 0x15) |
| 4024 | return 4; |
| 4025 | else if ((chain_mask & 0x7) == 0x7) |
| 4026 | return 3; |
| 4027 | else if ((chain_mask & 0x3) == 0x3) |
| 4028 | return 2; |
| 4029 | return 1; |
| 4030 | } |
| 4031 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4032 | /* |
| 4033 | * TODO: |
| 4034 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, |
| 4035 | * because we will send mgmt frames without CCK. This requirement |
| 4036 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag |
| 4037 | * in the TX packet. |
| 4038 | */ |
| 4039 | static int ath10k_add_interface(struct ieee80211_hw *hw, |
| 4040 | struct ieee80211_vif *vif) |
| 4041 | { |
| 4042 | struct ath10k *ar = hw->priv; |
| 4043 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4044 | enum wmi_sta_powersave_param param; |
| 4045 | int ret = 0; |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 4046 | u32 value; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4047 | int bit; |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 4048 | int i; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 4049 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4050 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 4051 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
| 4052 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4053 | mutex_lock(&ar->conf_mutex); |
| 4054 | |
Michal Kazior | 0dbd09e | 2013-07-31 10:55:14 +0200 | [diff] [blame] | 4055 | memset(arvif, 0, sizeof(*arvif)); |
| 4056 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4057 | arvif->ar = ar; |
| 4058 | arvif->vif = vif; |
| 4059 | |
Ben Greear | e63b33f | 2013-10-22 14:54:14 -0700 | [diff] [blame] | 4060 | INIT_LIST_HEAD(&arvif->list); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 4061 | INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work); |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 4062 | INIT_DELAYED_WORK(&arvif->connection_loss_work, |
| 4063 | ath10k_mac_vif_sta_connection_loss_work); |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4064 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 4065 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { |
| 4066 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; |
| 4067 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, |
| 4068 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); |
| 4069 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, |
| 4070 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); |
| 4071 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4072 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 4073 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4074 | 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] | 4075 | ret = -EBUSY; |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4076 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4077 | } |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 4078 | bit = __ffs64(ar->free_vdev_map); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4079 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 4080 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n", |
| 4081 | bit, ar->free_vdev_map); |
| 4082 | |
| 4083 | arvif->vdev_id = bit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4084 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4085 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4086 | switch (vif->type) { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 4087 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4088 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 4089 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE; |
| 4090 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4091 | case NL80211_IFTYPE_UNSPECIFIED: |
| 4092 | case NL80211_IFTYPE_STATION: |
| 4093 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 4094 | if (vif->p2p) |
| 4095 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT; |
| 4096 | break; |
| 4097 | case NL80211_IFTYPE_ADHOC: |
| 4098 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; |
| 4099 | break; |
| 4100 | case NL80211_IFTYPE_AP: |
| 4101 | arvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 4102 | |
| 4103 | if (vif->p2p) |
| 4104 | arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO; |
| 4105 | break; |
| 4106 | case NL80211_IFTYPE_MONITOR: |
| 4107 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; |
| 4108 | break; |
| 4109 | default: |
| 4110 | WARN_ON(1); |
| 4111 | break; |
| 4112 | } |
| 4113 | |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 4114 | /* Using vdev_id as queue number will make it very easy to do per-vif |
| 4115 | * tx queue locking. This shouldn't wrap due to interface combinations |
| 4116 | * but do a modulo for correctness sake and prevent using offchannel tx |
| 4117 | * queues for regular vif tx. |
| 4118 | */ |
| 4119 | vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1); |
| 4120 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) |
| 4121 | vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1); |
| 4122 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 4123 | /* Some firmware revisions don't wait for beacon tx completion before |
| 4124 | * sending another SWBA event. This could lead to hardware using old |
| 4125 | * (freed) beacon data in some cases, e.g. tx credit starvation |
| 4126 | * combined with missed TBTT. This is very very rare. |
| 4127 | * |
| 4128 | * On non-IOMMU-enabled hosts this could be a possible security issue |
| 4129 | * because hw could beacon some random data on the air. On |
| 4130 | * IOMMU-enabled hosts DMAR faults would occur in most cases and target |
| 4131 | * device would crash. |
| 4132 | * |
| 4133 | * Since there are no beacon tx completions (implicit nor explicit) |
| 4134 | * propagated to host the only workaround for this is to allocate a |
| 4135 | * DMA-coherent buffer for a lifetime of a vif and use it for all |
| 4136 | * beacon tx commands. Worst case for this approach is some beacons may |
| 4137 | * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap. |
| 4138 | */ |
| 4139 | if (vif->type == NL80211_IFTYPE_ADHOC || |
| 4140 | vif->type == NL80211_IFTYPE_AP) { |
| 4141 | arvif->beacon_buf = dma_zalloc_coherent(ar->dev, |
| 4142 | IEEE80211_MAX_FRAME_LEN, |
| 4143 | &arvif->beacon_paddr, |
Rajkumar Manoharan | 82d7aba | 2014-10-10 17:38:27 +0530 | [diff] [blame] | 4144 | GFP_ATOMIC); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 4145 | if (!arvif->beacon_buf) { |
| 4146 | ret = -ENOMEM; |
| 4147 | ath10k_warn(ar, "failed to allocate beacon buffer: %d\n", |
| 4148 | ret); |
| 4149 | goto err; |
| 4150 | } |
| 4151 | } |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 4152 | if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags)) |
| 4153 | arvif->nohwcrypt = true; |
| 4154 | |
| 4155 | if (arvif->nohwcrypt && |
| 4156 | !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
| 4157 | ath10k_warn(ar, "cryptmode module param needed for sw crypto\n"); |
| 4158 | goto err; |
| 4159 | } |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 4160 | |
| 4161 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n", |
| 4162 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, |
| 4163 | arvif->beacon_buf ? "single-buf" : "per-skb"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4164 | |
| 4165 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, |
| 4166 | arvif->vdev_subtype, vif->addr); |
| 4167 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4168 | ath10k_warn(ar, "failed to create WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4169 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4170 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4171 | } |
| 4172 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 4173 | ar->free_vdev_map &= ~(1LL << arvif->vdev_id); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4174 | list_add(&arvif->list, &ar->arvifs); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4175 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 4176 | /* It makes no sense to have firmware do keepalives. mac80211 already |
| 4177 | * takes care of this with idle connection polling. |
| 4178 | */ |
| 4179 | ret = ath10k_mac_vif_disable_keepalive(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4180 | if (ret) { |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 4181 | ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4182 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4183 | goto err_vdev_delete; |
| 4184 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4185 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4186 | arvif->def_wep_key_idx = -1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4187 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 4188 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
| 4189 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4190 | ATH10K_HW_TXRX_NATIVE_WIFI); |
Bartosz Markowski | ebc9abd | 2013-10-15 09:26:20 +0200 | [diff] [blame] | 4191 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4192 | if (ret && ret != -EOPNOTSUPP) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4193 | ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4194 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4195 | goto err_vdev_delete; |
| 4196 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4197 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4198 | if (ar->cfg_tx_chainmask) { |
| 4199 | u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
| 4200 | |
| 4201 | vdev_param = ar->wmi.vdev_param->nss; |
| 4202 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 4203 | nss); |
| 4204 | if (ret) { |
| 4205 | ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n", |
| 4206 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, |
| 4207 | ret); |
| 4208 | goto err_vdev_delete; |
| 4209 | } |
| 4210 | } |
| 4211 | |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4212 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 4213 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 4214 | ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr, |
| 4215 | WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4216 | if (ret) { |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4217 | ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4218 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4219 | goto err_vdev_delete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4220 | } |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4221 | } |
Marek Puzyniak | cdf0740 | 2013-12-30 09:07:51 +0100 | [diff] [blame] | 4222 | |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4223 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 4224 | ret = ath10k_mac_set_kickout(arvif); |
| 4225 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4226 | ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4227 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 4228 | goto err_peer_delete; |
| 4229 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 4233 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; |
| 4234 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 4235 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 4236 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4237 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4238 | 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] | 4239 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4240 | goto err_peer_delete; |
| 4241 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4242 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 4243 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4244 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 4245 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4246 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4247 | goto err_peer_delete; |
| 4248 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4249 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 4250 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4251 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 4252 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4253 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4254 | goto err_peer_delete; |
| 4255 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4256 | } |
| 4257 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 4258 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4259 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4260 | 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] | 4261 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4262 | goto err_peer_delete; |
| 4263 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 4264 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 4265 | arvif->txpower = vif->bss_conf.txpower; |
| 4266 | ret = ath10k_mac_txpower_recalc(ar); |
| 4267 | if (ret) { |
| 4268 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 4269 | goto err_peer_delete; |
| 4270 | } |
| 4271 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 4272 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 4273 | ar->monitor_arvif = arvif; |
| 4274 | ret = ath10k_monitor_recalc(ar); |
| 4275 | if (ret) { |
| 4276 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
| 4277 | goto err_peer_delete; |
| 4278 | } |
| 4279 | } |
| 4280 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4281 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4282 | return 0; |
| 4283 | |
| 4284 | err_peer_delete: |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4285 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 4286 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4287 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); |
| 4288 | |
| 4289 | err_vdev_delete: |
| 4290 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 4291 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4292 | list_del(&arvif->list); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4293 | |
| 4294 | err: |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 4295 | if (arvif->beacon_buf) { |
| 4296 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 4297 | arvif->beacon_buf, arvif->beacon_paddr); |
| 4298 | arvif->beacon_buf = NULL; |
| 4299 | } |
| 4300 | |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4301 | mutex_unlock(&ar->conf_mutex); |
| 4302 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4303 | return ret; |
| 4304 | } |
| 4305 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 4306 | static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif) |
| 4307 | { |
| 4308 | int i; |
| 4309 | |
| 4310 | for (i = 0; i < BITS_PER_LONG; i++) |
| 4311 | ath10k_mac_vif_tx_unlock(arvif, i); |
| 4312 | } |
| 4313 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4314 | static void ath10k_remove_interface(struct ieee80211_hw *hw, |
| 4315 | struct ieee80211_vif *vif) |
| 4316 | { |
| 4317 | struct ath10k *ar = hw->priv; |
| 4318 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4319 | int ret; |
| 4320 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 4321 | cancel_work_sync(&arvif->ap_csa_work); |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 4322 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 4323 | |
Sujith Manoharan | 5d011f5 | 2014-11-25 11:47:00 +0530 | [diff] [blame] | 4324 | mutex_lock(&ar->conf_mutex); |
| 4325 | |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 4326 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 4327 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | ed54388 | 2013-09-13 14:16:56 +0200 | [diff] [blame] | 4328 | spin_unlock_bh(&ar->data_lock); |
| 4329 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 4330 | ret = ath10k_spectral_vif_stop(arvif); |
| 4331 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4332 | ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 4333 | arvif->vdev_id, ret); |
| 4334 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 4335 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 4336 | list_del(&arvif->list); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4337 | |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4338 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 4339 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 4340 | ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id, |
| 4341 | vif->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4342 | if (ret) |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4343 | ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4344 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4345 | |
| 4346 | kfree(arvif->u.ap.noa_data); |
| 4347 | } |
| 4348 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4349 | 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] | 4350 | arvif->vdev_id); |
| 4351 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4352 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 4353 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4354 | ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4355 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4356 | |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 4357 | /* Some firmware revisions don't notify host about self-peer removal |
| 4358 | * until after associated vdev is deleted. |
| 4359 | */ |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 4360 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 4361 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 4362 | ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id, |
| 4363 | vif->addr); |
| 4364 | if (ret) |
| 4365 | ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n", |
| 4366 | arvif->vdev_id, ret); |
| 4367 | |
| 4368 | spin_lock_bh(&ar->data_lock); |
| 4369 | ar->num_peers--; |
| 4370 | spin_unlock_bh(&ar->data_lock); |
| 4371 | } |
| 4372 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4373 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
| 4374 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 4375 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 4376 | ar->monitor_arvif = NULL; |
| 4377 | ret = ath10k_monitor_recalc(ar); |
| 4378 | if (ret) |
| 4379 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
| 4380 | } |
| 4381 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 4382 | spin_lock_bh(&ar->htt.tx_lock); |
| 4383 | ath10k_mac_vif_tx_unlock_all(arvif); |
| 4384 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4385 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4386 | mutex_unlock(&ar->conf_mutex); |
| 4387 | } |
| 4388 | |
| 4389 | /* |
| 4390 | * FIXME: Has to be verified. |
| 4391 | */ |
| 4392 | #define SUPPORTED_FILTERS \ |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 4393 | (FIF_ALLMULTI | \ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4394 | FIF_CONTROL | \ |
| 4395 | FIF_PSPOLL | \ |
| 4396 | FIF_OTHER_BSS | \ |
| 4397 | FIF_BCN_PRBRESP_PROMISC | \ |
| 4398 | FIF_PROBE_REQ | \ |
| 4399 | FIF_FCSFAIL) |
| 4400 | |
| 4401 | static void ath10k_configure_filter(struct ieee80211_hw *hw, |
| 4402 | unsigned int changed_flags, |
| 4403 | unsigned int *total_flags, |
| 4404 | u64 multicast) |
| 4405 | { |
| 4406 | struct ath10k *ar = hw->priv; |
| 4407 | int ret; |
| 4408 | |
| 4409 | mutex_lock(&ar->conf_mutex); |
| 4410 | |
| 4411 | changed_flags &= SUPPORTED_FILTERS; |
| 4412 | *total_flags &= SUPPORTED_FILTERS; |
| 4413 | ar->filter_flags = *total_flags; |
| 4414 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 4415 | ret = ath10k_monitor_recalc(ar); |
| 4416 | if (ret) |
| 4417 | ath10k_warn(ar, "failed to recalc montior: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4418 | |
| 4419 | mutex_unlock(&ar->conf_mutex); |
| 4420 | } |
| 4421 | |
| 4422 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, |
| 4423 | struct ieee80211_vif *vif, |
| 4424 | struct ieee80211_bss_conf *info, |
| 4425 | u32 changed) |
| 4426 | { |
| 4427 | struct ath10k *ar = hw->priv; |
| 4428 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4429 | int ret = 0; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 4430 | u32 vdev_param, pdev_param, slottime, preamble; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4431 | |
| 4432 | mutex_lock(&ar->conf_mutex); |
| 4433 | |
| 4434 | if (changed & BSS_CHANGED_IBSS) |
| 4435 | ath10k_control_ibss(arvif, info, vif->addr); |
| 4436 | |
| 4437 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 4438 | arvif->beacon_interval = info->beacon_int; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 4439 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
| 4440 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4441 | arvif->beacon_interval); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4442 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4443 | "mac vdev %d beacon_interval %d\n", |
| 4444 | arvif->vdev_id, arvif->beacon_interval); |
| 4445 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4446 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4447 | 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] | 4448 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | if (changed & BSS_CHANGED_BEACON) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4452 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4453 | "vdev %d set beacon tx mode to staggered\n", |
| 4454 | arvif->vdev_id); |
| 4455 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 4456 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
| 4457 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4458 | WMI_BEACON_STAGGERED_MODE); |
| 4459 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4460 | 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] | 4461 | arvif->vdev_id, ret); |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 4462 | |
| 4463 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 4464 | if (ret) |
| 4465 | ath10k_warn(ar, "failed to update beacon template: %d\n", |
| 4466 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4467 | } |
| 4468 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 4469 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { |
| 4470 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 4471 | if (ret) |
| 4472 | ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n", |
| 4473 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4474 | } |
| 4475 | |
Michal Kazior | ba2479f | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 4476 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4477 | arvif->dtim_period = info->dtim_period; |
| 4478 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4479 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4480 | "mac vdev %d dtim_period %d\n", |
| 4481 | arvif->vdev_id, arvif->dtim_period); |
| 4482 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 4483 | vdev_param = ar->wmi.vdev_param->dtim_period; |
| 4484 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4485 | arvif->dtim_period); |
| 4486 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4487 | 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] | 4488 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | if (changed & BSS_CHANGED_SSID && |
| 4492 | vif->type == NL80211_IFTYPE_AP) { |
| 4493 | arvif->u.ap.ssid_len = info->ssid_len; |
| 4494 | if (info->ssid_len) |
| 4495 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); |
| 4496 | arvif->u.ap.hidden_ssid = info->hidden_ssid; |
| 4497 | } |
| 4498 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4499 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
| 4500 | ether_addr_copy(arvif->bssid, info->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4501 | |
| 4502 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
| 4503 | ath10k_control_beaconing(arvif, info); |
| 4504 | |
| 4505 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 4506 | arvif->use_cts_prot = info->use_cts_prot; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4507 | 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] | 4508 | arvif->vdev_id, info->use_cts_prot); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4509 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 4510 | ret = ath10k_recalc_rtscts_prot(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4511 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4512 | 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] | 4513 | arvif->vdev_id, ret); |
Michal Kazior | a87fd4b | 2015-03-02 11:21:17 +0100 | [diff] [blame] | 4514 | |
| 4515 | vdev_param = ar->wmi.vdev_param->protection_mode; |
| 4516 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 4517 | info->use_cts_prot ? 1 : 0); |
| 4518 | if (ret) |
| 4519 | ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n", |
| 4520 | info->use_cts_prot, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4524 | if (info->use_short_slot) |
| 4525 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ |
| 4526 | |
| 4527 | else |
| 4528 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ |
| 4529 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4530 | 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] | 4531 | arvif->vdev_id, slottime); |
| 4532 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 4533 | vdev_param = ar->wmi.vdev_param->slot_time; |
| 4534 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4535 | slottime); |
| 4536 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4537 | 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] | 4538 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4542 | if (info->use_short_preamble) |
| 4543 | preamble = WMI_VDEV_PREAMBLE_SHORT; |
| 4544 | else |
| 4545 | preamble = WMI_VDEV_PREAMBLE_LONG; |
| 4546 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4547 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 4548 | "mac vdev %d preamble %dn", |
| 4549 | arvif->vdev_id, preamble); |
| 4550 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 4551 | vdev_param = ar->wmi.vdev_param->preamble; |
| 4552 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4553 | preamble); |
| 4554 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4555 | ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 4556 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4557 | } |
| 4558 | |
| 4559 | if (changed & BSS_CHANGED_ASSOC) { |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 4560 | if (info->assoc) { |
| 4561 | /* Workaround: Make sure monitor vdev is not running |
| 4562 | * when associating to prevent some firmware revisions |
| 4563 | * (e.g. 10.1 and 10.2) from crashing. |
| 4564 | */ |
| 4565 | if (ar->monitor_started) |
| 4566 | ath10k_monitor_stop(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4567 | ath10k_bss_assoc(hw, vif, info); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 4568 | ath10k_monitor_recalc(ar); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4569 | } else { |
| 4570 | ath10k_bss_disassoc(hw, vif); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 4571 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4572 | } |
| 4573 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 4574 | if (changed & BSS_CHANGED_TXPOWER) { |
| 4575 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n", |
| 4576 | arvif->vdev_id, info->txpower); |
| 4577 | |
| 4578 | arvif->txpower = info->txpower; |
| 4579 | ret = ath10k_mac_txpower_recalc(ar); |
| 4580 | if (ret) |
| 4581 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 4582 | } |
| 4583 | |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 4584 | if (changed & BSS_CHANGED_PS) { |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 4585 | arvif->ps = vif->bss_conf.ps; |
| 4586 | |
| 4587 | ret = ath10k_config_ps(ar); |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 4588 | if (ret) |
| 4589 | ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n", |
| 4590 | arvif->vdev_id, ret); |
| 4591 | } |
| 4592 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4593 | mutex_unlock(&ar->conf_mutex); |
| 4594 | } |
| 4595 | |
| 4596 | static int ath10k_hw_scan(struct ieee80211_hw *hw, |
| 4597 | struct ieee80211_vif *vif, |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 4598 | struct ieee80211_scan_request *hw_req) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4599 | { |
| 4600 | struct ath10k *ar = hw->priv; |
| 4601 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 4602 | struct cfg80211_scan_request *req = &hw_req->req; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4603 | struct wmi_start_scan_arg arg; |
| 4604 | int ret = 0; |
| 4605 | int i; |
| 4606 | |
| 4607 | mutex_lock(&ar->conf_mutex); |
| 4608 | |
| 4609 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4610 | switch (ar->scan.state) { |
| 4611 | case ATH10K_SCAN_IDLE: |
| 4612 | reinit_completion(&ar->scan.started); |
| 4613 | reinit_completion(&ar->scan.completed); |
| 4614 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 4615 | ar->scan.is_roc = false; |
| 4616 | ar->scan.vdev_id = arvif->vdev_id; |
| 4617 | ret = 0; |
| 4618 | break; |
| 4619 | case ATH10K_SCAN_STARTING: |
| 4620 | case ATH10K_SCAN_RUNNING: |
| 4621 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4622 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4623 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4624 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4625 | spin_unlock_bh(&ar->data_lock); |
| 4626 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4627 | if (ret) |
| 4628 | goto exit; |
| 4629 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4630 | memset(&arg, 0, sizeof(arg)); |
| 4631 | ath10k_wmi_start_scan_init(ar, &arg); |
| 4632 | arg.vdev_id = arvif->vdev_id; |
| 4633 | arg.scan_id = ATH10K_SCAN_ID; |
| 4634 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4635 | if (req->ie_len) { |
| 4636 | arg.ie_len = req->ie_len; |
| 4637 | memcpy(arg.ie, req->ie, arg.ie_len); |
| 4638 | } |
| 4639 | |
| 4640 | if (req->n_ssids) { |
| 4641 | arg.n_ssids = req->n_ssids; |
| 4642 | for (i = 0; i < arg.n_ssids; i++) { |
| 4643 | arg.ssids[i].len = req->ssids[i].ssid_len; |
| 4644 | arg.ssids[i].ssid = req->ssids[i].ssid; |
| 4645 | } |
Michal Kazior | dcd4a56 | 2013-07-31 10:55:12 +0200 | [diff] [blame] | 4646 | } else { |
| 4647 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | if (req->n_channels) { |
| 4651 | arg.n_channels = req->n_channels; |
| 4652 | for (i = 0; i < arg.n_channels; i++) |
| 4653 | arg.channels[i] = req->channels[i]->center_freq; |
| 4654 | } |
| 4655 | |
| 4656 | ret = ath10k_start_scan(ar, &arg); |
| 4657 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4658 | ath10k_warn(ar, "failed to start hw scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4659 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4660 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4661 | spin_unlock_bh(&ar->data_lock); |
| 4662 | } |
| 4663 | |
| 4664 | exit: |
| 4665 | mutex_unlock(&ar->conf_mutex); |
| 4666 | return ret; |
| 4667 | } |
| 4668 | |
| 4669 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 4670 | struct ieee80211_vif *vif) |
| 4671 | { |
| 4672 | struct ath10k *ar = hw->priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4673 | |
| 4674 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4675 | ath10k_scan_abort(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4676 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 4677 | |
| 4678 | cancel_delayed_work_sync(&ar->scan.timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4679 | } |
| 4680 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4681 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
| 4682 | struct ath10k_vif *arvif, |
| 4683 | enum set_key_cmd cmd, |
| 4684 | struct ieee80211_key_conf *key) |
| 4685 | { |
| 4686 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; |
| 4687 | int ret; |
| 4688 | |
| 4689 | /* 10.1 firmware branch requires default key index to be set to group |
| 4690 | * key index after installing it. Otherwise FW/HW Txes corrupted |
| 4691 | * frames with multi-vif APs. This is not required for main firmware |
| 4692 | * branch (e.g. 636). |
| 4693 | * |
Michal Kazior | 8461baf | 2015-04-10 13:23:22 +0000 | [diff] [blame] | 4694 | * This is also needed for 636 fw for IBSS-RSN to work more reliably. |
| 4695 | * |
| 4696 | * FIXME: It remains unknown if this is required for multi-vif STA |
| 4697 | * interfaces on 10.1. |
| 4698 | */ |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4699 | |
Michal Kazior | 8461baf | 2015-04-10 13:23:22 +0000 | [diff] [blame] | 4700 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 4701 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4702 | return; |
| 4703 | |
| 4704 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 4705 | return; |
| 4706 | |
| 4707 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 4708 | return; |
| 4709 | |
| 4710 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4711 | return; |
| 4712 | |
| 4713 | if (cmd != SET_KEY) |
| 4714 | return; |
| 4715 | |
| 4716 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 4717 | key->keyidx); |
| 4718 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4719 | 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] | 4720 | arvif->vdev_id, ret); |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4721 | } |
| 4722 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4723 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 4724 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 4725 | struct ieee80211_key_conf *key) |
| 4726 | { |
| 4727 | struct ath10k *ar = hw->priv; |
| 4728 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4729 | struct ath10k_peer *peer; |
| 4730 | const u8 *peer_addr; |
| 4731 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 4732 | key->cipher == WLAN_CIPHER_SUITE_WEP104; |
| 4733 | int ret = 0; |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 4734 | int ret2; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4735 | u32 flags = 0; |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 4736 | u32 flags2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4737 | |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 4738 | /* this one needs to be done in software */ |
| 4739 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 4740 | return 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4741 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 4742 | if (arvif->nohwcrypt) |
| 4743 | return 1; |
| 4744 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4745 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
| 4746 | return -ENOSPC; |
| 4747 | |
| 4748 | mutex_lock(&ar->conf_mutex); |
| 4749 | |
| 4750 | if (sta) |
| 4751 | peer_addr = sta->addr; |
| 4752 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 4753 | peer_addr = vif->bss_conf.bssid; |
| 4754 | else |
| 4755 | peer_addr = vif->addr; |
| 4756 | |
| 4757 | key->hw_key_idx = key->keyidx; |
| 4758 | |
Michal Kazior | 7c8cc7e | 2015-04-01 22:53:19 +0300 | [diff] [blame] | 4759 | if (is_wep) { |
| 4760 | if (cmd == SET_KEY) |
| 4761 | arvif->wep_keys[key->keyidx] = key; |
| 4762 | else |
| 4763 | arvif->wep_keys[key->keyidx] = NULL; |
| 4764 | } |
| 4765 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4766 | /* the peer should not disappear in mid-way (unless FW goes awry) since |
| 4767 | * we already hold conf_mutex. we just make sure its there now. */ |
| 4768 | spin_lock_bh(&ar->data_lock); |
| 4769 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 4770 | spin_unlock_bh(&ar->data_lock); |
| 4771 | |
| 4772 | if (!peer) { |
| 4773 | if (cmd == SET_KEY) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4774 | 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] | 4775 | peer_addr); |
| 4776 | ret = -EOPNOTSUPP; |
| 4777 | goto exit; |
| 4778 | } else { |
| 4779 | /* if the peer doesn't exist there is no key to disable |
| 4780 | * anymore */ |
| 4781 | goto exit; |
| 4782 | } |
| 4783 | } |
| 4784 | |
Michal Kazior | 7cc4573 | 2015-03-09 14:24:17 +0100 | [diff] [blame] | 4785 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 4786 | flags |= WMI_KEY_PAIRWISE; |
| 4787 | else |
| 4788 | flags |= WMI_KEY_GROUP; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4789 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4790 | if (is_wep) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4791 | if (cmd == DISABLE_KEY) |
| 4792 | ath10k_clear_vdev_key(arvif, key); |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4793 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 4794 | /* When WEP keys are uploaded it's possible that there are |
| 4795 | * stations associated already (e.g. when merging) without any |
| 4796 | * keys. Static WEP needs an explicit per-peer key upload. |
| 4797 | */ |
| 4798 | if (vif->type == NL80211_IFTYPE_ADHOC && |
| 4799 | cmd == SET_KEY) |
| 4800 | ath10k_mac_vif_update_wep_key(arvif, key); |
| 4801 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4802 | /* 802.1x never sets the def_wep_key_idx so each set_key() |
| 4803 | * call changes default tx key. |
| 4804 | * |
| 4805 | * Static WEP sets def_wep_key_idx via .set_default_unicast_key |
| 4806 | * after first set_key(). |
| 4807 | */ |
| 4808 | if (cmd == SET_KEY && arvif->def_wep_key_idx == -1) |
| 4809 | flags |= WMI_KEY_TX_USAGE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4810 | } |
| 4811 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4812 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4813 | if (ret) { |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 4814 | WARN_ON(ret > 0); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4815 | 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] | 4816 | arvif->vdev_id, peer_addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4817 | goto exit; |
| 4818 | } |
| 4819 | |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 4820 | /* mac80211 sets static WEP keys as groupwise while firmware requires |
| 4821 | * them to be installed twice as both pairwise and groupwise. |
| 4822 | */ |
| 4823 | if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) { |
| 4824 | flags2 = flags; |
| 4825 | flags2 &= ~WMI_KEY_GROUP; |
| 4826 | flags2 |= WMI_KEY_PAIRWISE; |
| 4827 | |
| 4828 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2); |
| 4829 | if (ret) { |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 4830 | WARN_ON(ret > 0); |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 4831 | ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n", |
| 4832 | arvif->vdev_id, peer_addr, ret); |
| 4833 | ret2 = ath10k_install_key(arvif, key, DISABLE_KEY, |
| 4834 | peer_addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 4835 | if (ret2) { |
| 4836 | WARN_ON(ret2 > 0); |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 4837 | ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n", |
| 4838 | arvif->vdev_id, peer_addr, ret2); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 4839 | } |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 4840 | goto exit; |
| 4841 | } |
| 4842 | } |
| 4843 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 4844 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
| 4845 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4846 | spin_lock_bh(&ar->data_lock); |
| 4847 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 4848 | if (peer && cmd == SET_KEY) |
| 4849 | peer->keys[key->keyidx] = key; |
| 4850 | else if (peer && cmd == DISABLE_KEY) |
| 4851 | peer->keys[key->keyidx] = NULL; |
| 4852 | else if (peer == NULL) |
| 4853 | /* impossible unless FW goes crazy */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4854 | ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4855 | spin_unlock_bh(&ar->data_lock); |
| 4856 | |
| 4857 | exit: |
| 4858 | mutex_unlock(&ar->conf_mutex); |
| 4859 | return ret; |
| 4860 | } |
| 4861 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4862 | static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw, |
| 4863 | struct ieee80211_vif *vif, |
| 4864 | int keyidx) |
| 4865 | { |
| 4866 | struct ath10k *ar = hw->priv; |
| 4867 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 4868 | int ret; |
| 4869 | |
| 4870 | mutex_lock(&arvif->ar->conf_mutex); |
| 4871 | |
| 4872 | if (arvif->ar->state != ATH10K_STATE_ON) |
| 4873 | goto unlock; |
| 4874 | |
| 4875 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", |
| 4876 | arvif->vdev_id, keyidx); |
| 4877 | |
| 4878 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 4879 | arvif->vdev_id, |
| 4880 | arvif->ar->wmi.vdev_param->def_keyid, |
| 4881 | keyidx); |
| 4882 | |
| 4883 | if (ret) { |
| 4884 | ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n", |
| 4885 | arvif->vdev_id, |
| 4886 | ret); |
| 4887 | goto unlock; |
| 4888 | } |
| 4889 | |
| 4890 | arvif->def_wep_key_idx = keyidx; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 4891 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 4892 | unlock: |
| 4893 | mutex_unlock(&arvif->ar->conf_mutex); |
| 4894 | } |
| 4895 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4896 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
| 4897 | { |
| 4898 | struct ath10k *ar; |
| 4899 | struct ath10k_vif *arvif; |
| 4900 | struct ath10k_sta *arsta; |
| 4901 | struct ieee80211_sta *sta; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 4902 | struct cfg80211_chan_def def; |
| 4903 | enum ieee80211_band band; |
| 4904 | const u8 *ht_mcs_mask; |
| 4905 | const u16 *vht_mcs_mask; |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4906 | u32 changed, bw, nss, smps; |
| 4907 | int err; |
| 4908 | |
| 4909 | arsta = container_of(wk, struct ath10k_sta, update_wk); |
| 4910 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); |
| 4911 | arvif = arsta->arvif; |
| 4912 | ar = arvif->ar; |
| 4913 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 4914 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) |
| 4915 | return; |
| 4916 | |
| 4917 | band = def.chan->band; |
| 4918 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 4919 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 4920 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4921 | spin_lock_bh(&ar->data_lock); |
| 4922 | |
| 4923 | changed = arsta->changed; |
| 4924 | arsta->changed = 0; |
| 4925 | |
| 4926 | bw = arsta->bw; |
| 4927 | nss = arsta->nss; |
| 4928 | smps = arsta->smps; |
| 4929 | |
| 4930 | spin_unlock_bh(&ar->data_lock); |
| 4931 | |
| 4932 | mutex_lock(&ar->conf_mutex); |
| 4933 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 4934 | nss = max_t(u32, 1, nss); |
| 4935 | nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask), |
| 4936 | ath10k_mac_max_vht_nss(vht_mcs_mask))); |
| 4937 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4938 | if (changed & IEEE80211_RC_BW_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4939 | 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] | 4940 | sta->addr, bw); |
| 4941 | |
| 4942 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4943 | WMI_PEER_CHAN_WIDTH, bw); |
| 4944 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4945 | 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] | 4946 | sta->addr, bw, err); |
| 4947 | } |
| 4948 | |
| 4949 | if (changed & IEEE80211_RC_NSS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4950 | 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] | 4951 | sta->addr, nss); |
| 4952 | |
| 4953 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4954 | WMI_PEER_NSS, nss); |
| 4955 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4956 | ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4957 | sta->addr, nss, err); |
| 4958 | } |
| 4959 | |
| 4960 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4961 | 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] | 4962 | sta->addr, smps); |
| 4963 | |
| 4964 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 4965 | WMI_PEER_SMPS_STATE, smps); |
| 4966 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4967 | ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4968 | sta->addr, smps, err); |
| 4969 | } |
| 4970 | |
Janusz Dziedzic | 55884c0 | 2014-12-17 12:30:02 +0200 | [diff] [blame] | 4971 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED || |
| 4972 | changed & IEEE80211_RC_NSS_CHANGED) { |
| 4973 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4974 | sta->addr); |
| 4975 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 4976 | err = ath10k_station_assoc(ar, arvif->vif, sta, true); |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4977 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4978 | ath10k_warn(ar, "failed to reassociate station: %pM\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 4979 | sta->addr); |
| 4980 | } |
| 4981 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 4982 | mutex_unlock(&ar->conf_mutex); |
| 4983 | } |
| 4984 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 4985 | static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif, |
| 4986 | struct ieee80211_sta *sta) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4987 | { |
| 4988 | struct ath10k *ar = arvif->ar; |
| 4989 | |
| 4990 | lockdep_assert_held(&ar->conf_mutex); |
| 4991 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 4992 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 4993 | return 0; |
| 4994 | |
| 4995 | if (ar->num_stations >= ar->max_num_stations) |
| 4996 | return -ENOBUFS; |
| 4997 | |
| 4998 | ar->num_stations++; |
| 4999 | |
| 5000 | return 0; |
| 5001 | } |
| 5002 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 5003 | static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif, |
| 5004 | struct ieee80211_sta *sta) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 5005 | { |
| 5006 | struct ath10k *ar = arvif->ar; |
| 5007 | |
| 5008 | lockdep_assert_held(&ar->conf_mutex); |
| 5009 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 5010 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 5011 | return; |
| 5012 | |
| 5013 | ar->num_stations--; |
| 5014 | } |
| 5015 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5016 | struct ath10k_mac_tdls_iter_data { |
| 5017 | u32 num_tdls_stations; |
| 5018 | struct ieee80211_vif *curr_vif; |
| 5019 | }; |
| 5020 | |
| 5021 | static void ath10k_mac_tdls_vif_stations_count_iter(void *data, |
| 5022 | struct ieee80211_sta *sta) |
| 5023 | { |
| 5024 | struct ath10k_mac_tdls_iter_data *iter_data = data; |
| 5025 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 5026 | struct ieee80211_vif *sta_vif = arsta->arvif->vif; |
| 5027 | |
| 5028 | if (sta->tdls && sta_vif == iter_data->curr_vif) |
| 5029 | iter_data->num_tdls_stations++; |
| 5030 | } |
| 5031 | |
| 5032 | static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw, |
| 5033 | struct ieee80211_vif *vif) |
| 5034 | { |
| 5035 | struct ath10k_mac_tdls_iter_data data = {}; |
| 5036 | |
| 5037 | data.curr_vif = vif; |
| 5038 | |
| 5039 | ieee80211_iterate_stations_atomic(hw, |
| 5040 | ath10k_mac_tdls_vif_stations_count_iter, |
| 5041 | &data); |
| 5042 | return data.num_tdls_stations; |
| 5043 | } |
| 5044 | |
| 5045 | static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac, |
| 5046 | struct ieee80211_vif *vif) |
| 5047 | { |
| 5048 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5049 | int *num_tdls_vifs = data; |
| 5050 | |
| 5051 | if (vif->type != NL80211_IFTYPE_STATION) |
| 5052 | return; |
| 5053 | |
| 5054 | if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0) |
| 5055 | (*num_tdls_vifs)++; |
| 5056 | } |
| 5057 | |
| 5058 | static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw) |
| 5059 | { |
| 5060 | int num_tdls_vifs = 0; |
| 5061 | |
| 5062 | ieee80211_iterate_active_interfaces_atomic(hw, |
| 5063 | IEEE80211_IFACE_ITER_NORMAL, |
| 5064 | ath10k_mac_tdls_vifs_count_iter, |
| 5065 | &num_tdls_vifs); |
| 5066 | return num_tdls_vifs; |
| 5067 | } |
| 5068 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5069 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
| 5070 | struct ieee80211_vif *vif, |
| 5071 | struct ieee80211_sta *sta, |
| 5072 | enum ieee80211_sta_state old_state, |
| 5073 | enum ieee80211_sta_state new_state) |
| 5074 | { |
| 5075 | struct ath10k *ar = hw->priv; |
| 5076 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5077 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5078 | int ret = 0; |
| 5079 | |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 5080 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 5081 | new_state == IEEE80211_STA_NONE) { |
| 5082 | memset(arsta, 0, sizeof(*arsta)); |
| 5083 | arsta->arvif = arvif; |
| 5084 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); |
| 5085 | } |
| 5086 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5087 | /* cancel must be done outside the mutex to avoid deadlock */ |
| 5088 | if ((old_state == IEEE80211_STA_NONE && |
| 5089 | new_state == IEEE80211_STA_NOTEXIST)) |
| 5090 | cancel_work_sync(&arsta->update_wk); |
| 5091 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5092 | mutex_lock(&ar->conf_mutex); |
| 5093 | |
| 5094 | if (old_state == IEEE80211_STA_NOTEXIST && |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5095 | new_state == IEEE80211_STA_NONE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5096 | /* |
| 5097 | * New station addition. |
| 5098 | */ |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5099 | enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT; |
| 5100 | u32 num_tdls_stations; |
| 5101 | u32 num_tdls_vifs; |
| 5102 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 5103 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 5104 | "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n", |
| 5105 | arvif->vdev_id, sta->addr, |
| 5106 | ar->num_stations + 1, ar->max_num_stations, |
| 5107 | ar->num_peers + 1, ar->max_num_peers); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 5108 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 5109 | ret = ath10k_mac_inc_num_stations(arvif, sta); |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 5110 | if (ret) { |
| 5111 | ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n", |
| 5112 | ar->max_num_stations); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 5113 | goto exit; |
| 5114 | } |
| 5115 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5116 | if (sta->tdls) |
| 5117 | peer_type = WMI_PEER_TYPE_TDLS; |
| 5118 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 5119 | ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr, |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5120 | peer_type); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 5121 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5122 | 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] | 5123 | sta->addr, arvif->vdev_id, ret); |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 5124 | ath10k_mac_dec_num_stations(arvif, sta); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 5125 | goto exit; |
| 5126 | } |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5127 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5128 | if (!sta->tdls) |
| 5129 | goto exit; |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5130 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5131 | num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif); |
| 5132 | num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw); |
| 5133 | |
| 5134 | if (num_tdls_vifs >= ar->max_num_tdls_vdevs && |
| 5135 | num_tdls_stations == 0) { |
| 5136 | ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n", |
| 5137 | arvif->vdev_id, ar->max_num_tdls_vdevs); |
| 5138 | ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 5139 | ath10k_mac_dec_num_stations(arvif, sta); |
| 5140 | ret = -ENOBUFS; |
| 5141 | goto exit; |
| 5142 | } |
| 5143 | |
| 5144 | if (num_tdls_stations == 0) { |
| 5145 | /* This is the first tdls peer in current vif */ |
| 5146 | enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE; |
| 5147 | |
| 5148 | ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
| 5149 | state); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5150 | if (ret) { |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5151 | ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n", |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5152 | arvif->vdev_id, ret); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5153 | ath10k_peer_delete(ar, arvif->vdev_id, |
| 5154 | sta->addr); |
| 5155 | ath10k_mac_dec_num_stations(arvif, sta); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5156 | goto exit; |
| 5157 | } |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5158 | } |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5159 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5160 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, |
| 5161 | WMI_TDLS_PEER_STATE_PEERING); |
| 5162 | if (ret) { |
| 5163 | ath10k_warn(ar, |
| 5164 | "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n", |
| 5165 | sta->addr, arvif->vdev_id, ret); |
| 5166 | ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 5167 | ath10k_mac_dec_num_stations(arvif, sta); |
| 5168 | |
| 5169 | if (num_tdls_stations != 0) |
| 5170 | goto exit; |
| 5171 | ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
| 5172 | WMI_TDLS_DISABLE); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5173 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5174 | } else if ((old_state == IEEE80211_STA_NONE && |
| 5175 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 5176 | /* |
| 5177 | * Existing station deletion. |
| 5178 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5179 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5180 | "mac vdev %d peer delete %pM (sta gone)\n", |
| 5181 | arvif->vdev_id, sta->addr); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5182 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5183 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 5184 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5185 | 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] | 5186 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5187 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 5188 | ath10k_mac_dec_num_stations(arvif, sta); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5189 | |
| 5190 | if (!sta->tdls) |
| 5191 | goto exit; |
| 5192 | |
| 5193 | if (ath10k_mac_tdls_vif_stations_count(hw, vif)) |
| 5194 | goto exit; |
| 5195 | |
| 5196 | /* This was the last tdls peer in current vif */ |
| 5197 | ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
| 5198 | WMI_TDLS_DISABLE); |
| 5199 | if (ret) { |
| 5200 | ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n", |
| 5201 | arvif->vdev_id, ret); |
| 5202 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5203 | } else if (old_state == IEEE80211_STA_AUTH && |
| 5204 | new_state == IEEE80211_STA_ASSOC && |
| 5205 | (vif->type == NL80211_IFTYPE_AP || |
| 5206 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 5207 | /* |
| 5208 | * New association. |
| 5209 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5210 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5211 | sta->addr); |
| 5212 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5213 | ret = ath10k_station_assoc(ar, vif, sta, false); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5214 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5215 | 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] | 5216 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5217 | } else if (old_state == IEEE80211_STA_ASSOC && |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 5218 | new_state == IEEE80211_STA_AUTHORIZED && |
| 5219 | sta->tdls) { |
| 5220 | /* |
| 5221 | * Tdls station authorized. |
| 5222 | */ |
| 5223 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n", |
| 5224 | sta->addr); |
| 5225 | |
| 5226 | ret = ath10k_station_assoc(ar, vif, sta, false); |
| 5227 | if (ret) { |
| 5228 | ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n", |
| 5229 | sta->addr, arvif->vdev_id, ret); |
| 5230 | goto exit; |
| 5231 | } |
| 5232 | |
| 5233 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, |
| 5234 | WMI_TDLS_PEER_STATE_CONNECTED); |
| 5235 | if (ret) |
| 5236 | ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n", |
| 5237 | sta->addr, arvif->vdev_id, ret); |
| 5238 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 5239 | new_state == IEEE80211_STA_AUTH && |
| 5240 | (vif->type == NL80211_IFTYPE_AP || |
| 5241 | vif->type == NL80211_IFTYPE_ADHOC)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5242 | /* |
| 5243 | * Disassociation. |
| 5244 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5245 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5246 | sta->addr); |
| 5247 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5248 | ret = ath10k_station_disassoc(ar, vif, sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5249 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5250 | ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5251 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5252 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 5253 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5254 | mutex_unlock(&ar->conf_mutex); |
| 5255 | return ret; |
| 5256 | } |
| 5257 | |
| 5258 | 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] | 5259 | u16 ac, bool enable) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5260 | { |
| 5261 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 5262 | struct wmi_sta_uapsd_auto_trig_arg arg = {}; |
| 5263 | u32 prio = 0, acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5264 | u32 value = 0; |
| 5265 | int ret = 0; |
| 5266 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5267 | lockdep_assert_held(&ar->conf_mutex); |
| 5268 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5269 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 5270 | return 0; |
| 5271 | |
| 5272 | switch (ac) { |
| 5273 | case IEEE80211_AC_VO: |
| 5274 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | |
| 5275 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 5276 | prio = 7; |
| 5277 | acc = 3; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5278 | break; |
| 5279 | case IEEE80211_AC_VI: |
| 5280 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | |
| 5281 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 5282 | prio = 5; |
| 5283 | acc = 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5284 | break; |
| 5285 | case IEEE80211_AC_BE: |
| 5286 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | |
| 5287 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 5288 | prio = 2; |
| 5289 | acc = 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5290 | break; |
| 5291 | case IEEE80211_AC_BK: |
| 5292 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | |
| 5293 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 5294 | prio = 0; |
| 5295 | acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5296 | break; |
| 5297 | } |
| 5298 | |
| 5299 | if (enable) |
| 5300 | arvif->u.sta.uapsd |= value; |
| 5301 | else |
| 5302 | arvif->u.sta.uapsd &= ~value; |
| 5303 | |
| 5304 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 5305 | WMI_STA_PS_PARAM_UAPSD, |
| 5306 | arvif->u.sta.uapsd); |
| 5307 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5308 | ath10k_warn(ar, "failed to set uapsd params: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5309 | goto exit; |
| 5310 | } |
| 5311 | |
| 5312 | if (arvif->u.sta.uapsd) |
| 5313 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
| 5314 | else |
| 5315 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 5316 | |
| 5317 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 5318 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, |
| 5319 | value); |
| 5320 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5321 | ath10k_warn(ar, "failed to set rx wake param: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5322 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 5323 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
| 5324 | if (ret) { |
| 5325 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
| 5326 | arvif->vdev_id, ret); |
| 5327 | return ret; |
| 5328 | } |
| 5329 | |
| 5330 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
| 5331 | if (ret) { |
| 5332 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
| 5333 | arvif->vdev_id, ret); |
| 5334 | return ret; |
| 5335 | } |
| 5336 | |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 5337 | if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) || |
| 5338 | test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) { |
| 5339 | /* Only userspace can make an educated decision when to send |
| 5340 | * trigger frame. The following effectively disables u-UAPSD |
| 5341 | * autotrigger in firmware (which is enabled by default |
| 5342 | * provided the autotrigger service is available). |
| 5343 | */ |
| 5344 | |
| 5345 | arg.wmm_ac = acc; |
| 5346 | arg.user_priority = prio; |
| 5347 | arg.service_interval = 0; |
| 5348 | arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 5349 | arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 5350 | |
| 5351 | ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id, |
| 5352 | arvif->bssid, &arg, 1); |
| 5353 | if (ret) { |
| 5354 | ath10k_warn(ar, "failed to set uapsd auto trigger %d\n", |
| 5355 | ret); |
| 5356 | return ret; |
| 5357 | } |
| 5358 | } |
| 5359 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5360 | exit: |
| 5361 | return ret; |
| 5362 | } |
| 5363 | |
| 5364 | static int ath10k_conf_tx(struct ieee80211_hw *hw, |
| 5365 | struct ieee80211_vif *vif, u16 ac, |
| 5366 | const struct ieee80211_tx_queue_params *params) |
| 5367 | { |
| 5368 | struct ath10k *ar = hw->priv; |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 5369 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5370 | struct wmi_wmm_params_arg *p = NULL; |
| 5371 | int ret; |
| 5372 | |
| 5373 | mutex_lock(&ar->conf_mutex); |
| 5374 | |
| 5375 | switch (ac) { |
| 5376 | case IEEE80211_AC_VO: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 5377 | p = &arvif->wmm_params.ac_vo; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5378 | break; |
| 5379 | case IEEE80211_AC_VI: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 5380 | p = &arvif->wmm_params.ac_vi; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5381 | break; |
| 5382 | case IEEE80211_AC_BE: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 5383 | p = &arvif->wmm_params.ac_be; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5384 | break; |
| 5385 | case IEEE80211_AC_BK: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 5386 | p = &arvif->wmm_params.ac_bk; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5387 | break; |
| 5388 | } |
| 5389 | |
| 5390 | if (WARN_ON(!p)) { |
| 5391 | ret = -EINVAL; |
| 5392 | goto exit; |
| 5393 | } |
| 5394 | |
| 5395 | p->cwmin = params->cw_min; |
| 5396 | p->cwmax = params->cw_max; |
| 5397 | p->aifs = params->aifs; |
| 5398 | |
| 5399 | /* |
| 5400 | * The channel time duration programmed in the HW is in absolute |
| 5401 | * microseconds, while mac80211 gives the txop in units of |
| 5402 | * 32 microseconds. |
| 5403 | */ |
| 5404 | p->txop = params->txop * 32; |
| 5405 | |
Michal Kazior | 7fc979a | 2015-01-28 09:57:28 +0200 | [diff] [blame] | 5406 | if (ar->wmi.ops->gen_vdev_wmm_conf) { |
| 5407 | ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id, |
| 5408 | &arvif->wmm_params); |
| 5409 | if (ret) { |
| 5410 | ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n", |
| 5411 | arvif->vdev_id, ret); |
| 5412 | goto exit; |
| 5413 | } |
| 5414 | } else { |
| 5415 | /* This won't work well with multi-interface cases but it's |
| 5416 | * better than nothing. |
| 5417 | */ |
| 5418 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params); |
| 5419 | if (ret) { |
| 5420 | ath10k_warn(ar, "failed to set wmm params: %d\n", ret); |
| 5421 | goto exit; |
| 5422 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5423 | } |
| 5424 | |
| 5425 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); |
| 5426 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5427 | ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5428 | |
| 5429 | exit: |
| 5430 | mutex_unlock(&ar->conf_mutex); |
| 5431 | return ret; |
| 5432 | } |
| 5433 | |
| 5434 | #define ATH10K_ROC_TIMEOUT_HZ (2*HZ) |
| 5435 | |
| 5436 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, |
| 5437 | struct ieee80211_vif *vif, |
| 5438 | struct ieee80211_channel *chan, |
| 5439 | int duration, |
| 5440 | enum ieee80211_roc_type type) |
| 5441 | { |
| 5442 | struct ath10k *ar = hw->priv; |
| 5443 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 5444 | struct wmi_start_scan_arg arg; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5445 | int ret = 0; |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 5446 | u32 scan_time_msec; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5447 | |
| 5448 | mutex_lock(&ar->conf_mutex); |
| 5449 | |
| 5450 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5451 | switch (ar->scan.state) { |
| 5452 | case ATH10K_SCAN_IDLE: |
| 5453 | reinit_completion(&ar->scan.started); |
| 5454 | reinit_completion(&ar->scan.completed); |
| 5455 | reinit_completion(&ar->scan.on_channel); |
| 5456 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 5457 | ar->scan.is_roc = true; |
| 5458 | ar->scan.vdev_id = arvif->vdev_id; |
| 5459 | ar->scan.roc_freq = chan->center_freq; |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 5460 | ar->scan.roc_notify = true; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5461 | ret = 0; |
| 5462 | break; |
| 5463 | case ATH10K_SCAN_STARTING: |
| 5464 | case ATH10K_SCAN_RUNNING: |
| 5465 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5466 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5467 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5468 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5469 | spin_unlock_bh(&ar->data_lock); |
| 5470 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5471 | if (ret) |
| 5472 | goto exit; |
| 5473 | |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 5474 | scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2; |
Michal Kazior | dcca0bd | 2014-11-24 14:58:32 +0100 | [diff] [blame] | 5475 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5476 | memset(&arg, 0, sizeof(arg)); |
| 5477 | ath10k_wmi_start_scan_init(ar, &arg); |
| 5478 | arg.vdev_id = arvif->vdev_id; |
| 5479 | arg.scan_id = ATH10K_SCAN_ID; |
| 5480 | arg.n_channels = 1; |
| 5481 | arg.channels[0] = chan->center_freq; |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 5482 | arg.dwell_time_active = scan_time_msec; |
| 5483 | arg.dwell_time_passive = scan_time_msec; |
| 5484 | arg.max_scan_time = scan_time_msec; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5485 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
| 5486 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; |
Michal Kazior | dbd3f9f | 2015-03-31 11:03:48 +0000 | [diff] [blame] | 5487 | arg.burst_duration_ms = duration; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5488 | |
| 5489 | ret = ath10k_start_scan(ar, &arg); |
| 5490 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5491 | ath10k_warn(ar, "failed to start roc scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5492 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5493 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5494 | spin_unlock_bh(&ar->data_lock); |
| 5495 | goto exit; |
| 5496 | } |
| 5497 | |
| 5498 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ); |
| 5499 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5500 | ath10k_warn(ar, "failed to switch to channel for roc scan\n"); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5501 | |
| 5502 | ret = ath10k_scan_stop(ar); |
| 5503 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5504 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5505 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5506 | ret = -ETIMEDOUT; |
| 5507 | goto exit; |
| 5508 | } |
| 5509 | |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 5510 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
| 5511 | msecs_to_jiffies(duration)); |
| 5512 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5513 | ret = 0; |
| 5514 | exit: |
| 5515 | mutex_unlock(&ar->conf_mutex); |
| 5516 | return ret; |
| 5517 | } |
| 5518 | |
| 5519 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 5520 | { |
| 5521 | struct ath10k *ar = hw->priv; |
| 5522 | |
| 5523 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 5524 | |
| 5525 | spin_lock_bh(&ar->data_lock); |
| 5526 | ar->scan.roc_notify = false; |
| 5527 | spin_unlock_bh(&ar->data_lock); |
| 5528 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5529 | ath10k_scan_abort(ar); |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 5530 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5531 | mutex_unlock(&ar->conf_mutex); |
| 5532 | |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 5533 | cancel_delayed_work_sync(&ar->scan.timeout); |
| 5534 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5535 | return 0; |
| 5536 | } |
| 5537 | |
| 5538 | /* |
| 5539 | * Both RTS and Fragmentation threshold are interface-specific |
| 5540 | * in ath10k, but device-specific in mac80211. |
| 5541 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5542 | |
| 5543 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 5544 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5545 | struct ath10k *ar = hw->priv; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5546 | struct ath10k_vif *arvif; |
| 5547 | int ret = 0; |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5548 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5549 | mutex_lock(&ar->conf_mutex); |
| 5550 | list_for_each_entry(arvif, &ar->arvifs, list) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5551 | 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] | 5552 | arvif->vdev_id, value); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5553 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5554 | ret = ath10k_mac_set_rts(arvif, value); |
| 5555 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5556 | 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] | 5557 | arvif->vdev_id, ret); |
| 5558 | break; |
| 5559 | } |
| 5560 | } |
| 5561 | mutex_unlock(&ar->conf_mutex); |
| 5562 | |
| 5563 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5564 | } |
| 5565 | |
Michal Kazior | 92092fe | 2015-08-03 11:16:43 +0200 | [diff] [blame^] | 5566 | static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 5567 | { |
| 5568 | /* Even though there's a WMI enum for fragmentation threshold no known |
| 5569 | * firmware actually implements it. Moreover it is not possible to rely |
| 5570 | * frame fragmentation to mac80211 because firmware clears the "more |
| 5571 | * fragments" bit in frame control making it impossible for remote |
| 5572 | * devices to reassemble frames. |
| 5573 | * |
| 5574 | * Hence implement a dummy callback just to say fragmentation isn't |
| 5575 | * supported. This effectively prevents mac80211 from doing frame |
| 5576 | * fragmentation in software. |
| 5577 | */ |
| 5578 | return -EOPNOTSUPP; |
| 5579 | } |
| 5580 | |
Emmanuel Grumbach | 77be2c5 | 2014-03-27 11:30:29 +0200 | [diff] [blame] | 5581 | static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 5582 | u32 queues, bool drop) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5583 | { |
| 5584 | struct ath10k *ar = hw->priv; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5585 | bool skip; |
Nicholas Mc Guire | d4298a3 | 2015-06-15 14:46:43 +0300 | [diff] [blame] | 5586 | long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5587 | |
| 5588 | /* mac80211 doesn't care if we really xmit queued frames or not |
| 5589 | * we'll collect those frames either way if we stop/delete vdevs */ |
| 5590 | if (drop) |
| 5591 | return; |
| 5592 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5593 | mutex_lock(&ar->conf_mutex); |
| 5594 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5595 | if (ar->state == ATH10K_STATE_WEDGED) |
| 5596 | goto skip; |
| 5597 | |
Nicholas Mc Guire | d4298a3 | 2015-06-15 14:46:43 +0300 | [diff] [blame] | 5598 | time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5599 | bool empty; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5600 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 5601 | spin_lock_bh(&ar->htt.tx_lock); |
Michal Kazior | 0945baf | 2013-09-18 14:43:18 +0200 | [diff] [blame] | 5602 | empty = (ar->htt.num_pending_tx == 0); |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 5603 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5604 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 5605 | skip = (ar->state == ATH10K_STATE_WEDGED) || |
| 5606 | test_bit(ATH10K_FLAG_CRASH_FLUSH, |
| 5607 | &ar->dev_flags); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5608 | |
| 5609 | (empty || skip); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5610 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5611 | |
Nicholas Mc Guire | d4298a3 | 2015-06-15 14:46:43 +0300 | [diff] [blame] | 5612 | if (time_left == 0 || skip) |
| 5613 | ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n", |
| 5614 | skip, ar->state, time_left); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5615 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5616 | skip: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5617 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | /* TODO: Implement this function properly |
| 5621 | * For now it is needed to reply to Probe Requests in IBSS mode. |
| 5622 | * Propably we need this information from FW. |
| 5623 | */ |
| 5624 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) |
| 5625 | { |
| 5626 | return 1; |
| 5627 | } |
| 5628 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 5629 | static void ath10k_reconfig_complete(struct ieee80211_hw *hw, |
| 5630 | enum ieee80211_reconfig_type reconfig_type) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5631 | { |
| 5632 | struct ath10k *ar = hw->priv; |
| 5633 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 5634 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
| 5635 | return; |
| 5636 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5637 | mutex_lock(&ar->conf_mutex); |
| 5638 | |
| 5639 | /* If device failed to restart it will be in a different state, e.g. |
| 5640 | * ATH10K_STATE_WEDGED */ |
| 5641 | if (ar->state == ATH10K_STATE_RESTARTED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5642 | ath10k_info(ar, "device successfully recovered\n"); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5643 | ar->state = ATH10K_STATE_ON; |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 5644 | ieee80211_wake_queues(ar->hw); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | mutex_unlock(&ar->conf_mutex); |
| 5648 | } |
| 5649 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 5650 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
| 5651 | struct survey_info *survey) |
| 5652 | { |
| 5653 | struct ath10k *ar = hw->priv; |
| 5654 | struct ieee80211_supported_band *sband; |
| 5655 | struct survey_info *ar_survey = &ar->survey[idx]; |
| 5656 | int ret = 0; |
| 5657 | |
| 5658 | mutex_lock(&ar->conf_mutex); |
| 5659 | |
| 5660 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 5661 | if (sband && idx >= sband->n_channels) { |
| 5662 | idx -= sband->n_channels; |
| 5663 | sband = NULL; |
| 5664 | } |
| 5665 | |
| 5666 | if (!sband) |
| 5667 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 5668 | |
| 5669 | if (!sband || idx >= sband->n_channels) { |
| 5670 | ret = -ENOENT; |
| 5671 | goto exit; |
| 5672 | } |
| 5673 | |
| 5674 | spin_lock_bh(&ar->data_lock); |
| 5675 | memcpy(survey, ar_survey, sizeof(*survey)); |
| 5676 | spin_unlock_bh(&ar->data_lock); |
| 5677 | |
| 5678 | survey->channel = &sband->channels[idx]; |
| 5679 | |
Felix Fietkau | fa1d4df | 2014-10-23 17:04:28 +0300 | [diff] [blame] | 5680 | if (ar->rx_channel == survey->channel) |
| 5681 | survey->filled |= SURVEY_INFO_IN_USE; |
| 5682 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 5683 | exit: |
| 5684 | mutex_unlock(&ar->conf_mutex); |
| 5685 | return ret; |
| 5686 | } |
| 5687 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5688 | static bool |
| 5689 | ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar, |
| 5690 | enum ieee80211_band band, |
| 5691 | const struct cfg80211_bitrate_mask *mask) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5692 | { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5693 | int num_rates = 0; |
| 5694 | int i; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5695 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5696 | num_rates += hweight32(mask->control[band].legacy); |
| 5697 | |
| 5698 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) |
| 5699 | num_rates += hweight8(mask->control[band].ht_mcs[i]); |
| 5700 | |
| 5701 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) |
| 5702 | num_rates += hweight16(mask->control[band].vht_mcs[i]); |
| 5703 | |
| 5704 | return num_rates == 1; |
| 5705 | } |
| 5706 | |
| 5707 | static bool |
| 5708 | ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar, |
| 5709 | enum ieee80211_band band, |
| 5710 | const struct cfg80211_bitrate_mask *mask, |
| 5711 | int *nss) |
| 5712 | { |
| 5713 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; |
| 5714 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 5715 | u8 ht_nss_mask = 0; |
| 5716 | u8 vht_nss_mask = 0; |
| 5717 | int i; |
| 5718 | |
| 5719 | if (mask->control[band].legacy) |
| 5720 | return false; |
| 5721 | |
| 5722 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
| 5723 | if (mask->control[band].ht_mcs[i] == 0) |
| 5724 | continue; |
| 5725 | else if (mask->control[band].ht_mcs[i] == |
| 5726 | sband->ht_cap.mcs.rx_mask[i]) |
| 5727 | ht_nss_mask |= BIT(i); |
| 5728 | else |
| 5729 | return false; |
| 5730 | } |
| 5731 | |
| 5732 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 5733 | if (mask->control[band].vht_mcs[i] == 0) |
| 5734 | continue; |
| 5735 | else if (mask->control[band].vht_mcs[i] == |
| 5736 | ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) |
| 5737 | vht_nss_mask |= BIT(i); |
| 5738 | else |
| 5739 | return false; |
| 5740 | } |
| 5741 | |
| 5742 | if (ht_nss_mask != vht_nss_mask) |
| 5743 | return false; |
| 5744 | |
| 5745 | if (ht_nss_mask == 0) |
| 5746 | return false; |
| 5747 | |
| 5748 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) |
| 5749 | return false; |
| 5750 | |
| 5751 | *nss = fls(ht_nss_mask); |
| 5752 | |
| 5753 | return true; |
| 5754 | } |
| 5755 | |
| 5756 | static int |
| 5757 | ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar, |
| 5758 | enum ieee80211_band band, |
| 5759 | const struct cfg80211_bitrate_mask *mask, |
| 5760 | u8 *rate, u8 *nss) |
| 5761 | { |
| 5762 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; |
| 5763 | int rate_idx; |
| 5764 | int i; |
| 5765 | u16 bitrate; |
| 5766 | u8 preamble; |
| 5767 | u8 hw_rate; |
| 5768 | |
| 5769 | if (hweight32(mask->control[band].legacy) == 1) { |
| 5770 | rate_idx = ffs(mask->control[band].legacy) - 1; |
| 5771 | |
| 5772 | hw_rate = sband->bitrates[rate_idx].hw_value; |
| 5773 | bitrate = sband->bitrates[rate_idx].bitrate; |
| 5774 | |
| 5775 | if (ath10k_mac_bitrate_is_cck(bitrate)) |
| 5776 | preamble = WMI_RATE_PREAMBLE_CCK; |
| 5777 | else |
| 5778 | preamble = WMI_RATE_PREAMBLE_OFDM; |
| 5779 | |
| 5780 | *nss = 1; |
| 5781 | *rate = preamble << 6 | |
| 5782 | (*nss - 1) << 4 | |
| 5783 | hw_rate << 0; |
| 5784 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5785 | return 0; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5786 | } |
| 5787 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5788 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
| 5789 | if (hweight8(mask->control[band].ht_mcs[i]) == 1) { |
| 5790 | *nss = i + 1; |
| 5791 | *rate = WMI_RATE_PREAMBLE_HT << 6 | |
| 5792 | (*nss - 1) << 4 | |
| 5793 | (ffs(mask->control[band].ht_mcs[i]) - 1); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5794 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5795 | return 0; |
| 5796 | } |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5797 | } |
| 5798 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5799 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 5800 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { |
| 5801 | *nss = i + 1; |
| 5802 | *rate = WMI_RATE_PREAMBLE_VHT << 6 | |
| 5803 | (*nss - 1) << 4 | |
| 5804 | (ffs(mask->control[band].vht_mcs[i]) - 1); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5805 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5806 | return 0; |
| 5807 | } |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5808 | } |
| 5809 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5810 | return -EINVAL; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5811 | } |
| 5812 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5813 | static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif, |
| 5814 | u8 rate, u8 nss, u8 sgi) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5815 | { |
| 5816 | struct ath10k *ar = arvif->ar; |
| 5817 | u32 vdev_param; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5818 | int ret; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5819 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5820 | lockdep_assert_held(&ar->conf_mutex); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5821 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5822 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n", |
| 5823 | arvif->vdev_id, rate, nss, sgi); |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5824 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5825 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5826 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5827 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5828 | ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n", |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5829 | rate, ret); |
| 5830 | return ret; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5831 | } |
| 5832 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5833 | vdev_param = ar->wmi.vdev_param->nss; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5834 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5835 | if (ret) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5836 | ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret); |
| 5837 | return ret; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5838 | } |
| 5839 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5840 | vdev_param = ar->wmi.vdev_param->sgi; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5841 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi); |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5842 | if (ret) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5843 | ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret); |
| 5844 | return ret; |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5845 | } |
| 5846 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5847 | return 0; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5848 | } |
| 5849 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 5850 | static bool |
| 5851 | ath10k_mac_can_set_bitrate_mask(struct ath10k *ar, |
| 5852 | enum ieee80211_band band, |
| 5853 | const struct cfg80211_bitrate_mask *mask) |
| 5854 | { |
| 5855 | int i; |
| 5856 | u16 vht_mcs; |
| 5857 | |
| 5858 | /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible |
| 5859 | * to express all VHT MCS rate masks. Effectively only the following |
| 5860 | * ranges can be used: none, 0-7, 0-8 and 0-9. |
| 5861 | */ |
| 5862 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 5863 | vht_mcs = mask->control[band].vht_mcs[i]; |
| 5864 | |
| 5865 | switch (vht_mcs) { |
| 5866 | case 0: |
| 5867 | case BIT(8) - 1: |
| 5868 | case BIT(9) - 1: |
| 5869 | case BIT(10) - 1: |
| 5870 | break; |
| 5871 | default: |
| 5872 | ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n"); |
| 5873 | return false; |
| 5874 | } |
| 5875 | } |
| 5876 | |
| 5877 | return true; |
| 5878 | } |
| 5879 | |
| 5880 | static void ath10k_mac_set_bitrate_mask_iter(void *data, |
| 5881 | struct ieee80211_sta *sta) |
| 5882 | { |
| 5883 | struct ath10k_vif *arvif = data; |
| 5884 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 5885 | struct ath10k *ar = arvif->ar; |
| 5886 | |
| 5887 | if (arsta->arvif != arvif) |
| 5888 | return; |
| 5889 | |
| 5890 | spin_lock_bh(&ar->data_lock); |
| 5891 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; |
| 5892 | spin_unlock_bh(&ar->data_lock); |
| 5893 | |
| 5894 | ieee80211_queue_work(ar->hw, &arsta->update_wk); |
| 5895 | } |
| 5896 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5897 | static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, |
| 5898 | struct ieee80211_vif *vif, |
| 5899 | const struct cfg80211_bitrate_mask *mask) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5900 | { |
| 5901 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5902 | struct cfg80211_chan_def def; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5903 | struct ath10k *ar = arvif->ar; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5904 | enum ieee80211_band band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 5905 | const u8 *ht_mcs_mask; |
| 5906 | const u16 *vht_mcs_mask; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5907 | u8 rate; |
| 5908 | u8 nss; |
| 5909 | u8 sgi; |
| 5910 | int single_nss; |
| 5911 | int ret; |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5912 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5913 | if (ath10k_mac_vif_chan(vif, &def)) |
| 5914 | return -EPERM; |
| 5915 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5916 | band = def.chan->band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 5917 | ht_mcs_mask = mask->control[band].ht_mcs; |
| 5918 | vht_mcs_mask = mask->control[band].vht_mcs; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5919 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5920 | sgi = mask->control[band].gi; |
| 5921 | if (sgi == NL80211_TXRATE_FORCE_LGI) |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 5922 | return -EINVAL; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5923 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5924 | if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) { |
| 5925 | ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask, |
| 5926 | &rate, &nss); |
| 5927 | if (ret) { |
| 5928 | ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n", |
| 5929 | arvif->vdev_id, ret); |
| 5930 | return ret; |
| 5931 | } |
| 5932 | } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask, |
| 5933 | &single_nss)) { |
| 5934 | rate = WMI_FIXED_RATE_NONE; |
| 5935 | nss = single_nss; |
| 5936 | } else { |
| 5937 | rate = WMI_FIXED_RATE_NONE; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 5938 | nss = min(ar->num_rf_chains, |
| 5939 | max(ath10k_mac_max_ht_nss(ht_mcs_mask), |
| 5940 | ath10k_mac_max_vht_nss(vht_mcs_mask))); |
| 5941 | |
| 5942 | if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask)) |
| 5943 | return -EINVAL; |
| 5944 | |
| 5945 | mutex_lock(&ar->conf_mutex); |
| 5946 | |
| 5947 | arvif->bitrate_mask = *mask; |
| 5948 | ieee80211_iterate_stations_atomic(ar->hw, |
| 5949 | ath10k_mac_set_bitrate_mask_iter, |
| 5950 | arvif); |
| 5951 | |
| 5952 | mutex_unlock(&ar->conf_mutex); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5953 | } |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5954 | |
| 5955 | mutex_lock(&ar->conf_mutex); |
| 5956 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5957 | ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5958 | if (ret) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5959 | ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n", |
| 5960 | arvif->vdev_id, ret); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5961 | goto exit; |
| 5962 | } |
| 5963 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5964 | exit: |
| 5965 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 5966 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 5967 | return ret; |
| 5968 | } |
| 5969 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5970 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
| 5971 | struct ieee80211_vif *vif, |
| 5972 | struct ieee80211_sta *sta, |
| 5973 | u32 changed) |
| 5974 | { |
| 5975 | struct ath10k *ar = hw->priv; |
| 5976 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 5977 | u32 bw, smps; |
| 5978 | |
| 5979 | spin_lock_bh(&ar->data_lock); |
| 5980 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5981 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 5982 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
| 5983 | sta->addr, changed, sta->bandwidth, sta->rx_nss, |
| 5984 | sta->smps_mode); |
| 5985 | |
| 5986 | if (changed & IEEE80211_RC_BW_CHANGED) { |
| 5987 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5988 | |
| 5989 | switch (sta->bandwidth) { |
| 5990 | case IEEE80211_STA_RX_BW_20: |
| 5991 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 5992 | break; |
| 5993 | case IEEE80211_STA_RX_BW_40: |
| 5994 | bw = WMI_PEER_CHWIDTH_40MHZ; |
| 5995 | break; |
| 5996 | case IEEE80211_STA_RX_BW_80: |
| 5997 | bw = WMI_PEER_CHWIDTH_80MHZ; |
| 5998 | break; |
| 5999 | case IEEE80211_STA_RX_BW_160: |
Masanari Iida | d939be3 | 2015-02-27 23:52:31 +0900 | [diff] [blame] | 6000 | ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 6001 | sta->bandwidth, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6002 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 6003 | break; |
| 6004 | } |
| 6005 | |
| 6006 | arsta->bw = bw; |
| 6007 | } |
| 6008 | |
| 6009 | if (changed & IEEE80211_RC_NSS_CHANGED) |
| 6010 | arsta->nss = sta->rx_nss; |
| 6011 | |
| 6012 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 6013 | smps = WMI_PEER_SMPS_PS_NONE; |
| 6014 | |
| 6015 | switch (sta->smps_mode) { |
| 6016 | case IEEE80211_SMPS_AUTOMATIC: |
| 6017 | case IEEE80211_SMPS_OFF: |
| 6018 | smps = WMI_PEER_SMPS_PS_NONE; |
| 6019 | break; |
| 6020 | case IEEE80211_SMPS_STATIC: |
| 6021 | smps = WMI_PEER_SMPS_STATIC; |
| 6022 | break; |
| 6023 | case IEEE80211_SMPS_DYNAMIC: |
| 6024 | smps = WMI_PEER_SMPS_DYNAMIC; |
| 6025 | break; |
| 6026 | case IEEE80211_SMPS_NUM_MODES: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6027 | 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] | 6028 | sta->smps_mode, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6029 | smps = WMI_PEER_SMPS_PS_NONE; |
| 6030 | break; |
| 6031 | } |
| 6032 | |
| 6033 | arsta->smps = smps; |
| 6034 | } |
| 6035 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6036 | arsta->changed |= changed; |
| 6037 | |
| 6038 | spin_unlock_bh(&ar->data_lock); |
| 6039 | |
| 6040 | ieee80211_queue_work(hw, &arsta->update_wk); |
| 6041 | } |
| 6042 | |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 6043 | static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 6044 | { |
| 6045 | /* |
| 6046 | * FIXME: Return 0 for time being. Need to figure out whether FW |
| 6047 | * has the API to fetch 64-bit local TSF |
| 6048 | */ |
| 6049 | |
| 6050 | return 0; |
| 6051 | } |
| 6052 | |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 6053 | static int ath10k_ampdu_action(struct ieee80211_hw *hw, |
| 6054 | struct ieee80211_vif *vif, |
| 6055 | enum ieee80211_ampdu_mlme_action action, |
| 6056 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 6057 | u8 buf_size) |
| 6058 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6059 | struct ath10k *ar = hw->priv; |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 6060 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 6061 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6062 | 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] | 6063 | arvif->vdev_id, sta->addr, tid, action); |
| 6064 | |
| 6065 | switch (action) { |
| 6066 | case IEEE80211_AMPDU_RX_START: |
| 6067 | case IEEE80211_AMPDU_RX_STOP: |
| 6068 | /* HTT AddBa/DelBa events trigger mac80211 Rx BA session |
| 6069 | * creation/removal. Do we need to verify this? |
| 6070 | */ |
| 6071 | return 0; |
| 6072 | case IEEE80211_AMPDU_TX_START: |
| 6073 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 6074 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 6075 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 6076 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 6077 | /* Firmware offloads Tx aggregation entirely so deny mac80211 |
| 6078 | * Tx aggregation requests. |
| 6079 | */ |
| 6080 | return -EOPNOTSUPP; |
| 6081 | } |
| 6082 | |
| 6083 | return -EINVAL; |
| 6084 | } |
| 6085 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6086 | static void |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6087 | ath10k_mac_update_rx_channel(struct ath10k *ar, |
| 6088 | struct ieee80211_chanctx_conf *ctx, |
| 6089 | struct ieee80211_vif_chanctx_switch *vifs, |
| 6090 | int n_vifs) |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6091 | { |
| 6092 | struct cfg80211_chan_def *def = NULL; |
| 6093 | |
| 6094 | /* Both locks are required because ar->rx_channel is modified. This |
| 6095 | * allows readers to hold either lock. |
| 6096 | */ |
| 6097 | lockdep_assert_held(&ar->conf_mutex); |
| 6098 | lockdep_assert_held(&ar->data_lock); |
| 6099 | |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6100 | WARN_ON(ctx && vifs); |
| 6101 | WARN_ON(vifs && n_vifs != 1); |
| 6102 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6103 | /* FIXME: Sort of an optimization and a workaround. Peers and vifs are |
| 6104 | * on a linked list now. Doing a lookup peer -> vif -> chanctx for each |
| 6105 | * ppdu on Rx may reduce performance on low-end systems. It should be |
| 6106 | * possible to make tables/hashmaps to speed the lookup up (be vary of |
| 6107 | * cpu data cache lines though regarding sizes) but to keep the initial |
| 6108 | * implementation simple and less intrusive fallback to the slow lookup |
| 6109 | * only for multi-channel cases. Single-channel cases will remain to |
| 6110 | * use the old channel derival and thus performance should not be |
| 6111 | * affected much. |
| 6112 | */ |
| 6113 | rcu_read_lock(); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6114 | if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6115 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 6116 | ath10k_mac_get_any_chandef_iter, |
| 6117 | &def); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6118 | |
| 6119 | if (vifs) |
| 6120 | def = &vifs[0].new_ctx->def; |
| 6121 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6122 | ar->rx_channel = def->chan; |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6123 | } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) { |
| 6124 | ar->rx_channel = ctx->def.chan; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6125 | } else { |
| 6126 | ar->rx_channel = NULL; |
| 6127 | } |
| 6128 | rcu_read_unlock(); |
| 6129 | } |
| 6130 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6131 | static int |
| 6132 | ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw, |
| 6133 | struct ieee80211_chanctx_conf *ctx) |
| 6134 | { |
| 6135 | struct ath10k *ar = hw->priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6136 | |
| 6137 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 6138 | "mac chanctx add freq %hu width %d ptr %p\n", |
| 6139 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
| 6140 | |
| 6141 | mutex_lock(&ar->conf_mutex); |
| 6142 | |
| 6143 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6144 | ath10k_mac_update_rx_channel(ar, ctx, NULL, 0); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6145 | spin_unlock_bh(&ar->data_lock); |
| 6146 | |
| 6147 | ath10k_recalc_radar_detection(ar); |
| 6148 | ath10k_monitor_recalc(ar); |
| 6149 | |
| 6150 | mutex_unlock(&ar->conf_mutex); |
| 6151 | |
| 6152 | return 0; |
| 6153 | } |
| 6154 | |
| 6155 | static void |
| 6156 | ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw, |
| 6157 | struct ieee80211_chanctx_conf *ctx) |
| 6158 | { |
| 6159 | struct ath10k *ar = hw->priv; |
| 6160 | |
| 6161 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 6162 | "mac chanctx remove freq %hu width %d ptr %p\n", |
| 6163 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
| 6164 | |
| 6165 | mutex_lock(&ar->conf_mutex); |
| 6166 | |
| 6167 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6168 | ath10k_mac_update_rx_channel(ar, NULL, NULL, 0); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6169 | spin_unlock_bh(&ar->data_lock); |
| 6170 | |
| 6171 | ath10k_recalc_radar_detection(ar); |
| 6172 | ath10k_monitor_recalc(ar); |
| 6173 | |
| 6174 | mutex_unlock(&ar->conf_mutex); |
| 6175 | } |
| 6176 | |
| 6177 | static void |
| 6178 | ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw, |
| 6179 | struct ieee80211_chanctx_conf *ctx, |
| 6180 | u32 changed) |
| 6181 | { |
| 6182 | struct ath10k *ar = hw->priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6183 | |
| 6184 | mutex_lock(&ar->conf_mutex); |
| 6185 | |
| 6186 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 6187 | "mac chanctx change freq %hu width %d ptr %p changed %x\n", |
| 6188 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6189 | |
| 6190 | /* This shouldn't really happen because channel switching should use |
| 6191 | * switch_vif_chanctx(). |
| 6192 | */ |
| 6193 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) |
| 6194 | goto unlock; |
| 6195 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6196 | ath10k_recalc_radar_detection(ar); |
| 6197 | |
| 6198 | /* FIXME: How to configure Rx chains properly? */ |
| 6199 | |
| 6200 | /* No other actions are actually necessary. Firmware maintains channel |
| 6201 | * definitions per vdev internally and there's no host-side channel |
| 6202 | * context abstraction to configure, e.g. channel width. |
| 6203 | */ |
| 6204 | |
| 6205 | unlock: |
| 6206 | mutex_unlock(&ar->conf_mutex); |
| 6207 | } |
| 6208 | |
| 6209 | static int |
| 6210 | ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 6211 | struct ieee80211_vif *vif, |
| 6212 | struct ieee80211_chanctx_conf *ctx) |
| 6213 | { |
| 6214 | struct ath10k *ar = hw->priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6215 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 6216 | int ret; |
| 6217 | |
| 6218 | mutex_lock(&ar->conf_mutex); |
| 6219 | |
| 6220 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 6221 | "mac chanctx assign ptr %p vdev_id %i\n", |
| 6222 | ctx, arvif->vdev_id); |
| 6223 | |
| 6224 | if (WARN_ON(arvif->is_started)) { |
| 6225 | mutex_unlock(&ar->conf_mutex); |
| 6226 | return -EBUSY; |
| 6227 | } |
| 6228 | |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 6229 | ret = ath10k_vdev_start(arvif, &ctx->def); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6230 | if (ret) { |
| 6231 | ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n", |
| 6232 | arvif->vdev_id, vif->addr, |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 6233 | ctx->def.chan->center_freq, ret); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6234 | goto err; |
| 6235 | } |
| 6236 | |
| 6237 | arvif->is_started = true; |
| 6238 | |
Michal Kazior | f23e587e | 2015-07-09 13:08:37 +0200 | [diff] [blame] | 6239 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 6240 | if (ret) { |
| 6241 | ath10k_warn(ar, "failed to update vdev %i ps: %d\n", |
| 6242 | arvif->vdev_id, ret); |
| 6243 | goto err_stop; |
| 6244 | } |
| 6245 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6246 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 6247 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr); |
| 6248 | if (ret) { |
| 6249 | ath10k_warn(ar, "failed to up monitor vdev %i: %d\n", |
| 6250 | arvif->vdev_id, ret); |
| 6251 | goto err_stop; |
| 6252 | } |
| 6253 | |
| 6254 | arvif->is_up = true; |
| 6255 | } |
| 6256 | |
| 6257 | mutex_unlock(&ar->conf_mutex); |
| 6258 | return 0; |
| 6259 | |
| 6260 | err_stop: |
| 6261 | ath10k_vdev_stop(arvif); |
| 6262 | arvif->is_started = false; |
Michal Kazior | f23e587e | 2015-07-09 13:08:37 +0200 | [diff] [blame] | 6263 | ath10k_mac_vif_setup_ps(arvif); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6264 | |
| 6265 | err: |
| 6266 | mutex_unlock(&ar->conf_mutex); |
| 6267 | return ret; |
| 6268 | } |
| 6269 | |
| 6270 | static void |
| 6271 | ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 6272 | struct ieee80211_vif *vif, |
| 6273 | struct ieee80211_chanctx_conf *ctx) |
| 6274 | { |
| 6275 | struct ath10k *ar = hw->priv; |
| 6276 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 6277 | int ret; |
| 6278 | |
| 6279 | mutex_lock(&ar->conf_mutex); |
| 6280 | |
| 6281 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 6282 | "mac chanctx unassign ptr %p vdev_id %i\n", |
| 6283 | ctx, arvif->vdev_id); |
| 6284 | |
| 6285 | WARN_ON(!arvif->is_started); |
| 6286 | |
| 6287 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 6288 | WARN_ON(!arvif->is_up); |
| 6289 | |
| 6290 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 6291 | if (ret) |
| 6292 | ath10k_warn(ar, "failed to down monitor vdev %i: %d\n", |
| 6293 | arvif->vdev_id, ret); |
| 6294 | |
| 6295 | arvif->is_up = false; |
| 6296 | } |
| 6297 | |
| 6298 | ret = ath10k_vdev_stop(arvif); |
| 6299 | if (ret) |
| 6300 | ath10k_warn(ar, "failed to stop vdev %i: %d\n", |
| 6301 | arvif->vdev_id, ret); |
| 6302 | |
| 6303 | arvif->is_started = false; |
| 6304 | |
| 6305 | mutex_unlock(&ar->conf_mutex); |
| 6306 | } |
| 6307 | |
| 6308 | static int |
| 6309 | ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, |
| 6310 | struct ieee80211_vif_chanctx_switch *vifs, |
| 6311 | int n_vifs, |
| 6312 | enum ieee80211_chanctx_switch_mode mode) |
| 6313 | { |
| 6314 | struct ath10k *ar = hw->priv; |
| 6315 | struct ath10k_vif *arvif; |
Michal Kazior | 0e6eb41 | 2015-06-03 12:16:56 +0200 | [diff] [blame] | 6316 | int ret; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6317 | int i; |
| 6318 | |
| 6319 | mutex_lock(&ar->conf_mutex); |
| 6320 | |
| 6321 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 6322 | "mac chanctx switch n_vifs %d mode %d\n", |
| 6323 | n_vifs, mode); |
| 6324 | |
Michal Kazior | 0e6eb41 | 2015-06-03 12:16:56 +0200 | [diff] [blame] | 6325 | /* First stop monitor interface. Some FW versions crash if there's a |
| 6326 | * lone monitor interface. |
| 6327 | */ |
| 6328 | if (ar->monitor_started) |
| 6329 | ath10k_monitor_stop(ar); |
| 6330 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6331 | for (i = 0; i < n_vifs; i++) { |
| 6332 | arvif = ath10k_vif_to_arvif(vifs[i].vif); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6333 | |
| 6334 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 6335 | "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n", |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6336 | arvif->vdev_id, |
| 6337 | vifs[i].old_ctx->def.chan->center_freq, |
| 6338 | vifs[i].new_ctx->def.chan->center_freq, |
| 6339 | vifs[i].old_ctx->def.width, |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 6340 | vifs[i].new_ctx->def.width); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6341 | |
Michal Kazior | 0e6eb41 | 2015-06-03 12:16:56 +0200 | [diff] [blame] | 6342 | if (WARN_ON(!arvif->is_started)) |
| 6343 | continue; |
| 6344 | |
| 6345 | if (WARN_ON(!arvif->is_up)) |
| 6346 | continue; |
| 6347 | |
| 6348 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 6349 | if (ret) { |
| 6350 | ath10k_warn(ar, "failed to down vdev %d: %d\n", |
| 6351 | arvif->vdev_id, ret); |
| 6352 | continue; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6353 | } |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6354 | } |
Michal Kazior | 0e6eb41 | 2015-06-03 12:16:56 +0200 | [diff] [blame] | 6355 | |
| 6356 | /* All relevant vdevs are downed and associated channel resources |
| 6357 | * should be available for the channel switch now. |
| 6358 | */ |
| 6359 | |
| 6360 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 6361 | ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6362 | spin_unlock_bh(&ar->data_lock); |
| 6363 | |
Michal Kazior | 0e6eb41 | 2015-06-03 12:16:56 +0200 | [diff] [blame] | 6364 | for (i = 0; i < n_vifs; i++) { |
| 6365 | arvif = ath10k_vif_to_arvif(vifs[i].vif); |
| 6366 | |
| 6367 | if (WARN_ON(!arvif->is_started)) |
| 6368 | continue; |
| 6369 | |
| 6370 | if (WARN_ON(!arvif->is_up)) |
| 6371 | continue; |
| 6372 | |
| 6373 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 6374 | if (ret) |
| 6375 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 6376 | ret); |
| 6377 | |
| 6378 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 6379 | if (ret) |
| 6380 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 6381 | ret); |
| 6382 | |
| 6383 | ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def); |
| 6384 | if (ret) { |
| 6385 | ath10k_warn(ar, "failed to restart vdev %d: %d\n", |
| 6386 | arvif->vdev_id, ret); |
| 6387 | continue; |
| 6388 | } |
| 6389 | |
| 6390 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 6391 | arvif->bssid); |
| 6392 | if (ret) { |
| 6393 | ath10k_warn(ar, "failed to bring vdev up %d: %d\n", |
| 6394 | arvif->vdev_id, ret); |
| 6395 | continue; |
| 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | ath10k_monitor_recalc(ar); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6400 | |
| 6401 | mutex_unlock(&ar->conf_mutex); |
| 6402 | return 0; |
| 6403 | } |
| 6404 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6405 | static const struct ieee80211_ops ath10k_ops = { |
| 6406 | .tx = ath10k_tx, |
| 6407 | .start = ath10k_start, |
| 6408 | .stop = ath10k_stop, |
| 6409 | .config = ath10k_config, |
| 6410 | .add_interface = ath10k_add_interface, |
| 6411 | .remove_interface = ath10k_remove_interface, |
| 6412 | .configure_filter = ath10k_configure_filter, |
| 6413 | .bss_info_changed = ath10k_bss_info_changed, |
| 6414 | .hw_scan = ath10k_hw_scan, |
| 6415 | .cancel_hw_scan = ath10k_cancel_hw_scan, |
| 6416 | .set_key = ath10k_set_key, |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 6417 | .set_default_unicast_key = ath10k_set_default_unicast_key, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6418 | .sta_state = ath10k_sta_state, |
| 6419 | .conf_tx = ath10k_conf_tx, |
| 6420 | .remain_on_channel = ath10k_remain_on_channel, |
| 6421 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, |
| 6422 | .set_rts_threshold = ath10k_set_rts_threshold, |
Michal Kazior | 92092fe | 2015-08-03 11:16:43 +0200 | [diff] [blame^] | 6423 | .set_frag_threshold = ath10k_mac_op_set_frag_threshold, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6424 | .flush = ath10k_flush, |
| 6425 | .tx_last_beacon = ath10k_tx_last_beacon, |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 6426 | .set_antenna = ath10k_set_antenna, |
| 6427 | .get_antenna = ath10k_get_antenna, |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 6428 | .reconfig_complete = ath10k_reconfig_complete, |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 6429 | .get_survey = ath10k_get_survey, |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 6430 | .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6431 | .sta_rc_update = ath10k_sta_rc_update, |
Chun-Yeow Yeoh | 26ebbcc | 2014-02-25 09:29:54 +0200 | [diff] [blame] | 6432 | .get_tsf = ath10k_get_tsf, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 6433 | .ampdu_action = ath10k_ampdu_action, |
Ben Greear | 6cddcc7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 6434 | .get_et_sset_count = ath10k_debug_get_et_sset_count, |
| 6435 | .get_et_stats = ath10k_debug_get_et_stats, |
| 6436 | .get_et_strings = ath10k_debug_get_et_strings, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 6437 | .add_chanctx = ath10k_mac_op_add_chanctx, |
| 6438 | .remove_chanctx = ath10k_mac_op_remove_chanctx, |
| 6439 | .change_chanctx = ath10k_mac_op_change_chanctx, |
| 6440 | .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx, |
| 6441 | .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx, |
| 6442 | .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx, |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 6443 | |
| 6444 | CFG80211_TESTMODE_CMD(ath10k_tm_cmd) |
| 6445 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 6446 | #ifdef CONFIG_PM |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 6447 | .suspend = ath10k_wow_op_suspend, |
| 6448 | .resume = ath10k_wow_op_resume, |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 6449 | #endif |
Rajkumar Manoharan | f504598 | 2015-01-12 14:07:27 +0200 | [diff] [blame] | 6450 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 6451 | .sta_add_debugfs = ath10k_sta_add_debugfs, |
| 6452 | #endif |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6453 | }; |
| 6454 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6455 | #define CHAN2G(_channel, _freq, _flags) { \ |
| 6456 | .band = IEEE80211_BAND_2GHZ, \ |
| 6457 | .hw_value = (_channel), \ |
| 6458 | .center_freq = (_freq), \ |
| 6459 | .flags = (_flags), \ |
| 6460 | .max_antenna_gain = 0, \ |
| 6461 | .max_power = 30, \ |
| 6462 | } |
| 6463 | |
| 6464 | #define CHAN5G(_channel, _freq, _flags) { \ |
| 6465 | .band = IEEE80211_BAND_5GHZ, \ |
| 6466 | .hw_value = (_channel), \ |
| 6467 | .center_freq = (_freq), \ |
| 6468 | .flags = (_flags), \ |
| 6469 | .max_antenna_gain = 0, \ |
| 6470 | .max_power = 30, \ |
| 6471 | } |
| 6472 | |
| 6473 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { |
| 6474 | CHAN2G(1, 2412, 0), |
| 6475 | CHAN2G(2, 2417, 0), |
| 6476 | CHAN2G(3, 2422, 0), |
| 6477 | CHAN2G(4, 2427, 0), |
| 6478 | CHAN2G(5, 2432, 0), |
| 6479 | CHAN2G(6, 2437, 0), |
| 6480 | CHAN2G(7, 2442, 0), |
| 6481 | CHAN2G(8, 2447, 0), |
| 6482 | CHAN2G(9, 2452, 0), |
| 6483 | CHAN2G(10, 2457, 0), |
| 6484 | CHAN2G(11, 2462, 0), |
| 6485 | CHAN2G(12, 2467, 0), |
| 6486 | CHAN2G(13, 2472, 0), |
| 6487 | CHAN2G(14, 2484, 0), |
| 6488 | }; |
| 6489 | |
| 6490 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 6491 | CHAN5G(36, 5180, 0), |
| 6492 | CHAN5G(40, 5200, 0), |
| 6493 | CHAN5G(44, 5220, 0), |
| 6494 | CHAN5G(48, 5240, 0), |
| 6495 | CHAN5G(52, 5260, 0), |
| 6496 | CHAN5G(56, 5280, 0), |
| 6497 | CHAN5G(60, 5300, 0), |
| 6498 | CHAN5G(64, 5320, 0), |
| 6499 | CHAN5G(100, 5500, 0), |
| 6500 | CHAN5G(104, 5520, 0), |
| 6501 | CHAN5G(108, 5540, 0), |
| 6502 | CHAN5G(112, 5560, 0), |
| 6503 | CHAN5G(116, 5580, 0), |
| 6504 | CHAN5G(120, 5600, 0), |
| 6505 | CHAN5G(124, 5620, 0), |
| 6506 | CHAN5G(128, 5640, 0), |
| 6507 | CHAN5G(132, 5660, 0), |
| 6508 | CHAN5G(136, 5680, 0), |
| 6509 | CHAN5G(140, 5700, 0), |
Peter Oh | 4a7898f | 2015-03-18 11:39:18 -0700 | [diff] [blame] | 6510 | CHAN5G(144, 5720, 0), |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 6511 | CHAN5G(149, 5745, 0), |
| 6512 | CHAN5G(153, 5765, 0), |
| 6513 | CHAN5G(157, 5785, 0), |
| 6514 | CHAN5G(161, 5805, 0), |
| 6515 | CHAN5G(165, 5825, 0), |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6516 | }; |
| 6517 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 6518 | struct ath10k *ath10k_mac_create(size_t priv_size) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6519 | { |
| 6520 | struct ieee80211_hw *hw; |
| 6521 | struct ath10k *ar; |
| 6522 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 6523 | hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6524 | if (!hw) |
| 6525 | return NULL; |
| 6526 | |
| 6527 | ar = hw->priv; |
| 6528 | ar->hw = hw; |
| 6529 | |
| 6530 | return ar; |
| 6531 | } |
| 6532 | |
| 6533 | void ath10k_mac_destroy(struct ath10k *ar) |
| 6534 | { |
| 6535 | ieee80211_free_hw(ar->hw); |
| 6536 | } |
| 6537 | |
| 6538 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { |
| 6539 | { |
| 6540 | .max = 8, |
| 6541 | .types = BIT(NL80211_IFTYPE_STATION) |
| 6542 | | BIT(NL80211_IFTYPE_P2P_CLIENT) |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 6543 | }, |
| 6544 | { |
| 6545 | .max = 3, |
| 6546 | .types = BIT(NL80211_IFTYPE_P2P_GO) |
| 6547 | }, |
| 6548 | { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 6549 | .max = 1, |
| 6550 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) |
| 6551 | }, |
| 6552 | { |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 6553 | .max = 7, |
| 6554 | .types = BIT(NL80211_IFTYPE_AP) |
| 6555 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6556 | }; |
| 6557 | |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 6558 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 6559 | { |
| 6560 | .max = 8, |
| 6561 | .types = BIT(NL80211_IFTYPE_AP) |
| 6562 | }, |
| 6563 | }; |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 6564 | |
| 6565 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { |
| 6566 | { |
| 6567 | .limits = ath10k_if_limits, |
| 6568 | .n_limits = ARRAY_SIZE(ath10k_if_limits), |
| 6569 | .max_interfaces = 8, |
| 6570 | .num_different_channels = 1, |
| 6571 | .beacon_int_infra_match = true, |
| 6572 | }, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 6573 | }; |
| 6574 | |
| 6575 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 6576 | { |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 6577 | .limits = ath10k_10x_if_limits, |
| 6578 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 6579 | .max_interfaces = 8, |
| 6580 | .num_different_channels = 1, |
| 6581 | .beacon_int_infra_match = true, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 6582 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 6583 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 6584 | BIT(NL80211_CHAN_WIDTH_20) | |
| 6585 | BIT(NL80211_CHAN_WIDTH_40) | |
| 6586 | BIT(NL80211_CHAN_WIDTH_80), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 6587 | #endif |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 6588 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6589 | }; |
| 6590 | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 6591 | static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = { |
| 6592 | { |
| 6593 | .max = 2, |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 6594 | .types = BIT(NL80211_IFTYPE_STATION), |
| 6595 | }, |
| 6596 | { |
| 6597 | .max = 2, |
| 6598 | .types = BIT(NL80211_IFTYPE_AP) | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 6599 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6600 | BIT(NL80211_IFTYPE_P2P_GO), |
| 6601 | }, |
| 6602 | { |
| 6603 | .max = 1, |
| 6604 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 6605 | }, |
| 6606 | }; |
| 6607 | |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 6608 | static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = { |
| 6609 | { |
| 6610 | .max = 2, |
| 6611 | .types = BIT(NL80211_IFTYPE_STATION), |
| 6612 | }, |
| 6613 | { |
| 6614 | .max = 2, |
| 6615 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT), |
| 6616 | }, |
| 6617 | { |
| 6618 | .max = 1, |
| 6619 | .types = BIT(NL80211_IFTYPE_AP) | |
| 6620 | BIT(NL80211_IFTYPE_P2P_GO), |
| 6621 | }, |
| 6622 | { |
| 6623 | .max = 1, |
| 6624 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 6625 | }, |
| 6626 | }; |
| 6627 | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 6628 | static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = { |
| 6629 | { |
| 6630 | .max = 1, |
| 6631 | .types = BIT(NL80211_IFTYPE_STATION), |
| 6632 | }, |
| 6633 | { |
| 6634 | .max = 1, |
| 6635 | .types = BIT(NL80211_IFTYPE_ADHOC), |
| 6636 | }, |
| 6637 | }; |
| 6638 | |
| 6639 | /* FIXME: This is not thouroughly tested. These combinations may over- or |
| 6640 | * underestimate hw/fw capabilities. |
| 6641 | */ |
| 6642 | static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = { |
| 6643 | { |
| 6644 | .limits = ath10k_tlv_if_limit, |
| 6645 | .num_different_channels = 1, |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 6646 | .max_interfaces = 4, |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 6647 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit), |
| 6648 | }, |
| 6649 | { |
| 6650 | .limits = ath10k_tlv_if_limit_ibss, |
| 6651 | .num_different_channels = 1, |
| 6652 | .max_interfaces = 2, |
| 6653 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss), |
| 6654 | }, |
| 6655 | }; |
| 6656 | |
| 6657 | static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = { |
| 6658 | { |
| 6659 | .limits = ath10k_tlv_if_limit, |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 6660 | .num_different_channels = 1, |
| 6661 | .max_interfaces = 4, |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 6662 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit), |
| 6663 | }, |
| 6664 | { |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 6665 | .limits = ath10k_tlv_qcs_if_limit, |
| 6666 | .num_different_channels = 2, |
| 6667 | .max_interfaces = 4, |
| 6668 | .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit), |
| 6669 | }, |
| 6670 | { |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 6671 | .limits = ath10k_tlv_if_limit_ibss, |
| 6672 | .num_different_channels = 1, |
| 6673 | .max_interfaces = 2, |
| 6674 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss), |
| 6675 | }, |
| 6676 | }; |
| 6677 | |
Raja Mani | cf36fef | 2015-06-22 20:22:25 +0530 | [diff] [blame] | 6678 | static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = { |
| 6679 | { |
| 6680 | .max = 1, |
| 6681 | .types = BIT(NL80211_IFTYPE_STATION), |
| 6682 | }, |
| 6683 | { |
| 6684 | .max = 16, |
| 6685 | .types = BIT(NL80211_IFTYPE_AP) |
| 6686 | }, |
| 6687 | }; |
| 6688 | |
| 6689 | static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = { |
| 6690 | { |
| 6691 | .limits = ath10k_10_4_if_limits, |
| 6692 | .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits), |
| 6693 | .max_interfaces = 16, |
| 6694 | .num_different_channels = 1, |
| 6695 | .beacon_int_infra_match = true, |
| 6696 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
| 6697 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 6698 | BIT(NL80211_CHAN_WIDTH_20) | |
| 6699 | BIT(NL80211_CHAN_WIDTH_40) | |
| 6700 | BIT(NL80211_CHAN_WIDTH_80), |
| 6701 | #endif |
| 6702 | }, |
| 6703 | }; |
| 6704 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6705 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) |
| 6706 | { |
| 6707 | struct ieee80211_sta_vht_cap vht_cap = {0}; |
| 6708 | u16 mcs_map; |
Michal Kazior | bc657a36 | 2015-02-26 11:11:22 +0100 | [diff] [blame] | 6709 | u32 val; |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 6710 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6711 | |
| 6712 | vht_cap.vht_supported = 1; |
| 6713 | vht_cap.cap = ar->vht_cap_info; |
| 6714 | |
Michal Kazior | bc657a36 | 2015-02-26 11:11:22 +0100 | [diff] [blame] | 6715 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 6716 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 6717 | val = ar->num_rf_chains - 1; |
| 6718 | val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; |
| 6719 | val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 6720 | |
| 6721 | vht_cap.cap |= val; |
| 6722 | } |
| 6723 | |
| 6724 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 6725 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 6726 | val = ar->num_rf_chains - 1; |
| 6727 | val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; |
| 6728 | val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; |
| 6729 | |
| 6730 | vht_cap.cap |= val; |
| 6731 | } |
| 6732 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 6733 | mcs_map = 0; |
| 6734 | for (i = 0; i < 8; i++) { |
| 6735 | if (i < ar->num_rf_chains) |
| 6736 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2); |
| 6737 | else |
| 6738 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2); |
| 6739 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6740 | |
| 6741 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 6742 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 6743 | |
| 6744 | return vht_cap; |
| 6745 | } |
| 6746 | |
| 6747 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) |
| 6748 | { |
| 6749 | int i; |
| 6750 | struct ieee80211_sta_ht_cap ht_cap = {0}; |
| 6751 | |
| 6752 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) |
| 6753 | return ht_cap; |
| 6754 | |
| 6755 | ht_cap.ht_supported = 1; |
| 6756 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 6757 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; |
| 6758 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 6759 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
| 6760 | ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 6761 | |
| 6762 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) |
| 6763 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 6764 | |
| 6765 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) |
| 6766 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 6767 | |
| 6768 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { |
| 6769 | u32 smps; |
| 6770 | |
| 6771 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; |
| 6772 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 6773 | |
| 6774 | ht_cap.cap |= smps; |
| 6775 | } |
| 6776 | |
| 6777 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC) |
| 6778 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 6779 | |
| 6780 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { |
| 6781 | u32 stbc; |
| 6782 | |
| 6783 | stbc = ar->ht_cap_info; |
| 6784 | stbc &= WMI_HT_CAP_RX_STBC; |
| 6785 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; |
| 6786 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 6787 | stbc &= IEEE80211_HT_CAP_RX_STBC; |
| 6788 | |
| 6789 | ht_cap.cap |= stbc; |
| 6790 | } |
| 6791 | |
| 6792 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC) |
| 6793 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; |
| 6794 | |
| 6795 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) |
| 6796 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; |
| 6797 | |
| 6798 | /* max AMSDU is implicitly taken from vht_cap_info */ |
| 6799 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) |
| 6800 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
| 6801 | |
Michal Kazior | 8865bee4 | 2013-07-24 12:36:46 +0200 | [diff] [blame] | 6802 | for (i = 0; i < ar->num_rf_chains; i++) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6803 | ht_cap.mcs.rx_mask[i] = 0xFF; |
| 6804 | |
| 6805 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
| 6806 | |
| 6807 | return ht_cap; |
| 6808 | } |
| 6809 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6810 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
| 6811 | struct ieee80211_vif *vif) |
| 6812 | { |
| 6813 | struct ath10k_vif_iter *arvif_iter = data; |
| 6814 | struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif); |
| 6815 | |
| 6816 | if (arvif->vdev_id == arvif_iter->vdev_id) |
| 6817 | arvif_iter->arvif = arvif; |
| 6818 | } |
| 6819 | |
| 6820 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) |
| 6821 | { |
| 6822 | struct ath10k_vif_iter arvif_iter; |
| 6823 | u32 flags; |
| 6824 | |
| 6825 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); |
| 6826 | arvif_iter.vdev_id = vdev_id; |
| 6827 | |
| 6828 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; |
| 6829 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 6830 | flags, |
| 6831 | ath10k_get_arvif_iter, |
| 6832 | &arvif_iter); |
| 6833 | if (!arvif_iter.arvif) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6834 | ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6835 | return NULL; |
| 6836 | } |
| 6837 | |
| 6838 | return arvif_iter.arvif; |
| 6839 | } |
| 6840 | |
| 6841 | int ath10k_mac_register(struct ath10k *ar) |
| 6842 | { |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 6843 | static const u32 cipher_suites[] = { |
| 6844 | WLAN_CIPHER_SUITE_WEP40, |
| 6845 | WLAN_CIPHER_SUITE_WEP104, |
| 6846 | WLAN_CIPHER_SUITE_TKIP, |
| 6847 | WLAN_CIPHER_SUITE_CCMP, |
| 6848 | WLAN_CIPHER_SUITE_AES_CMAC, |
| 6849 | }; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6850 | struct ieee80211_supported_band *band; |
| 6851 | struct ieee80211_sta_vht_cap vht_cap; |
| 6852 | struct ieee80211_sta_ht_cap ht_cap; |
| 6853 | void *channels; |
| 6854 | int ret; |
| 6855 | |
| 6856 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); |
| 6857 | |
| 6858 | SET_IEEE80211_DEV(ar->hw, ar->dev); |
| 6859 | |
| 6860 | ht_cap = ath10k_get_ht_cap(ar); |
| 6861 | vht_cap = ath10k_create_vht_cap(ar); |
| 6862 | |
Michal Kazior | c94aa7e | 2015-03-24 12:38:11 +0000 | [diff] [blame] | 6863 | BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) + |
| 6864 | ARRAY_SIZE(ath10k_5ghz_channels)) != |
| 6865 | ATH10K_NUM_CHANS); |
| 6866 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6867 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
| 6868 | channels = kmemdup(ath10k_2ghz_channels, |
| 6869 | sizeof(ath10k_2ghz_channels), |
| 6870 | GFP_KERNEL); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 6871 | if (!channels) { |
| 6872 | ret = -ENOMEM; |
| 6873 | goto err_free; |
| 6874 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6875 | |
| 6876 | band = &ar->mac.sbands[IEEE80211_BAND_2GHZ]; |
| 6877 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); |
| 6878 | band->channels = channels; |
| 6879 | band->n_bitrates = ath10k_g_rates_size; |
| 6880 | band->bitrates = ath10k_g_rates; |
| 6881 | band->ht_cap = ht_cap; |
| 6882 | |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 6883 | /* Enable the VHT support at 2.4 GHz */ |
| 6884 | band->vht_cap = vht_cap; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6885 | |
| 6886 | ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band; |
| 6887 | } |
| 6888 | |
| 6889 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { |
| 6890 | channels = kmemdup(ath10k_5ghz_channels, |
| 6891 | sizeof(ath10k_5ghz_channels), |
| 6892 | GFP_KERNEL); |
| 6893 | if (!channels) { |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 6894 | ret = -ENOMEM; |
| 6895 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | band = &ar->mac.sbands[IEEE80211_BAND_5GHZ]; |
| 6899 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); |
| 6900 | band->channels = channels; |
| 6901 | band->n_bitrates = ath10k_a_rates_size; |
| 6902 | band->bitrates = ath10k_a_rates; |
| 6903 | band->ht_cap = ht_cap; |
| 6904 | band->vht_cap = vht_cap; |
| 6905 | ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band; |
| 6906 | } |
| 6907 | |
| 6908 | ar->hw->wiphy->interface_modes = |
| 6909 | BIT(NL80211_IFTYPE_STATION) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 6910 | BIT(NL80211_IFTYPE_AP); |
| 6911 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 6912 | ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask; |
| 6913 | ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask; |
| 6914 | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 6915 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features)) |
| 6916 | ar->hw->wiphy->interface_modes |= |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 6917 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 6918 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 6919 | BIT(NL80211_IFTYPE_P2P_GO); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6920 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 6921 | ieee80211_hw_set(ar->hw, SIGNAL_DBM); |
| 6922 | ieee80211_hw_set(ar->hw, SUPPORTS_PS); |
| 6923 | ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS); |
| 6924 | ieee80211_hw_set(ar->hw, MFP_CAPABLE); |
| 6925 | ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS); |
| 6926 | ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL); |
| 6927 | ieee80211_hw_set(ar->hw, AP_LINK_PS); |
| 6928 | ieee80211_hw_set(ar->hw, SPECTRUM_MGMT); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 6929 | ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT); |
| 6930 | ieee80211_hw_set(ar->hw, CONNECTION_MONITOR); |
| 6931 | ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK); |
| 6932 | ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF); |
| 6933 | ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA); |
| 6934 | ieee80211_hw_set(ar->hw, QUEUE_CONTROL); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6935 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 6936 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
| 6937 | ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL); |
| 6938 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 6939 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
Janusz Dziedzic | 0cd9bc1 | 2015-04-10 13:23:23 +0000 | [diff] [blame] | 6940 | ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 6941 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6942 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 6943 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6944 | |
| 6945 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 6946 | ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION); |
| 6947 | ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
| 6951 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; |
| 6952 | |
| 6953 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6954 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6955 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6956 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
| 6957 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 6958 | if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) { |
| 6959 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 6960 | |
| 6961 | /* Firmware delivers WPS/P2P Probe Requests frames to driver so |
| 6962 | * that userspace (e.g. wpa_supplicant/hostapd) can generate |
| 6963 | * correct Probe Responses. This is more of a hack advert.. |
| 6964 | */ |
| 6965 | ar->hw->wiphy->probe_resp_offload |= |
| 6966 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 6967 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 6968 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 6969 | } |
| 6970 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6971 | if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map)) |
| 6972 | ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
| 6973 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6974 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 6975 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6976 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 6977 | |
| 6978 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
Rajkumar Manoharan | 78157a1 | 2014-11-17 16:44:15 +0200 | [diff] [blame] | 6979 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE; |
| 6980 | |
Janusz.Dziedzic@tieto.com | 37a0b39 | 2015-03-12 13:11:41 +0100 | [diff] [blame] | 6981 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; |
| 6982 | |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 6983 | ret = ath10k_wow_init(ar); |
| 6984 | if (ret) { |
| 6985 | ath10k_warn(ar, "failed to init wow: %d\n", ret); |
| 6986 | goto err_free; |
| 6987 | } |
| 6988 | |
Janusz Dziedzic | c702534 | 2015-06-15 14:46:41 +0300 | [diff] [blame] | 6989 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
| 6990 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6991 | /* |
| 6992 | * on LL hardware queues are managed entirely by the FW |
| 6993 | * so we only advertise to mac we can do the queues thing |
| 6994 | */ |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 6995 | ar->hw->queues = IEEE80211_MAX_QUEUES; |
| 6996 | |
| 6997 | /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is |
| 6998 | * something that vdev_ids can't reach so that we don't stop the queue |
| 6999 | * accidentally. |
| 7000 | */ |
| 7001 | ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7002 | |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 7003 | switch (ar->wmi.op_version) { |
| 7004 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 7005 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
| 7006 | ar->hw->wiphy->n_iface_combinations = |
| 7007 | ARRAY_SIZE(ath10k_if_comb); |
Michal Kazior | cf850d1 | 2014-07-24 20:07:00 +0300 | [diff] [blame] | 7008 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 7009 | break; |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 7010 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
| 7011 | if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) { |
| 7012 | ar->hw->wiphy->iface_combinations = |
| 7013 | ath10k_tlv_qcs_if_comb; |
| 7014 | ar->hw->wiphy->n_iface_combinations = |
| 7015 | ARRAY_SIZE(ath10k_tlv_qcs_if_comb); |
| 7016 | } else { |
| 7017 | ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb; |
| 7018 | ar->hw->wiphy->n_iface_combinations = |
| 7019 | ARRAY_SIZE(ath10k_tlv_if_comb); |
| 7020 | } |
| 7021 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
| 7022 | break; |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 7023 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
| 7024 | case ATH10K_FW_WMI_OP_VERSION_10_2: |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 7025 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 7026 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
| 7027 | ar->hw->wiphy->n_iface_combinations = |
| 7028 | ARRAY_SIZE(ath10k_10x_if_comb); |
| 7029 | break; |
Raja Mani | 9bd2132 | 2015-06-22 20:10:09 +0530 | [diff] [blame] | 7030 | case ATH10K_FW_WMI_OP_VERSION_10_4: |
Raja Mani | cf36fef | 2015-06-22 20:22:25 +0530 | [diff] [blame] | 7031 | ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb; |
| 7032 | ar->hw->wiphy->n_iface_combinations = |
| 7033 | ARRAY_SIZE(ath10k_10_4_if_comb); |
Raja Mani | 9bd2132 | 2015-06-22 20:10:09 +0530 | [diff] [blame] | 7034 | break; |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 7035 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
| 7036 | case ATH10K_FW_WMI_OP_VERSION_MAX: |
| 7037 | WARN_ON(1); |
| 7038 | ret = -EINVAL; |
| 7039 | goto err_free; |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 7040 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7041 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 7042 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
| 7043 | ar->hw->netdev_features = NETIF_F_HW_CSUM; |
Michal Kazior | 7c19999 | 2013-07-31 10:47:57 +0200 | [diff] [blame] | 7044 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 7045 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) { |
| 7046 | /* Init ath dfs pattern detector */ |
| 7047 | ar->ath_common.debug_mask = ATH_DBG_DFS; |
| 7048 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, |
| 7049 | NL80211_DFS_UNSET); |
| 7050 | |
| 7051 | if (!ar->dfs_detector) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7052 | ath10k_warn(ar, "failed to initialise DFS pattern detector\n"); |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 7053 | } |
| 7054 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7055 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
| 7056 | ath10k_reg_notifier); |
| 7057 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7058 | ath10k_err(ar, "failed to initialise regulatory: %i\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 7059 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7060 | } |
| 7061 | |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 7062 | ar->hw->wiphy->cipher_suites = cipher_suites; |
| 7063 | ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites); |
| 7064 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7065 | ret = ieee80211_register_hw(ar->hw); |
| 7066 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7067 | ath10k_err(ar, "failed to register ieee80211: %d\n", ret); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 7068 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7069 | } |
| 7070 | |
| 7071 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { |
| 7072 | ret = regulatory_hint(ar->hw->wiphy, |
| 7073 | ar->ath_common.regulatory.alpha2); |
| 7074 | if (ret) |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 7075 | goto err_unregister; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | return 0; |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 7079 | |
| 7080 | err_unregister: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7081 | ieee80211_unregister_hw(ar->hw); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 7082 | err_free: |
| 7083 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 7084 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 7085 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7086 | return ret; |
| 7087 | } |
| 7088 | |
| 7089 | void ath10k_mac_unregister(struct ath10k *ar) |
| 7090 | { |
| 7091 | ieee80211_unregister_hw(ar->hw); |
| 7092 | |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 7093 | if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
| 7094 | ar->dfs_detector->exit(ar->dfs_detector); |
| 7095 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7096 | kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels); |
| 7097 | kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels); |
| 7098 | |
| 7099 | SET_IEEE80211_DEV(ar->hw, NULL); |
| 7100 | } |