Kalle Valo | f0553ca | 2019-02-19 19:45:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: ISC |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
Kalle Valo | 8b1083d | 2017-12-22 18:31:13 +0200 | [diff] [blame] | 4 | * Copyright (c) 2011-2017 Qualcomm Atheros, Inc. |
Rakesh Pillai | 6e8a899 | 2019-01-25 09:51:06 +0530 | [diff] [blame] | 5 | * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved. |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "mac.h" |
| 9 | |
Sven Eckelmann | 34d5629 | 2018-08-24 15:04:59 +0300 | [diff] [blame] | 10 | #include <net/cfg80211.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 11 | #include <net/mac80211.h> |
| 12 | #include <linux/etherdevice.h> |
Bartosz Markowski | 209b2a6 | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 13 | #include <linux/acpi.h> |
Bhagavathi Perumal S | 84758d4 | 2018-12-20 14:26:00 +0200 | [diff] [blame] | 14 | #include <linux/of.h> |
Wen Gong | 1382993 | 2019-10-01 15:04:56 +0300 | [diff] [blame] | 15 | #include <linux/bitfield.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 16 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 17 | #include "hif.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 18 | #include "core.h" |
| 19 | #include "debug.h" |
| 20 | #include "wmi.h" |
| 21 | #include "htt.h" |
| 22 | #include "txrx.h" |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 23 | #include "testmode.h" |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 24 | #include "wmi-tlv.h" |
Michal Kazior | d7579d1 | 2014-12-03 10:10:54 +0200 | [diff] [blame] | 25 | #include "wmi-ops.h" |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 26 | #include "wow.h" |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 27 | |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 28 | /*********/ |
| 29 | /* Rates */ |
| 30 | /*********/ |
| 31 | |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 32 | static struct ieee80211_rate ath10k_rates[] = { |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 33 | { .bitrate = 10, |
| 34 | .hw_value = ATH10K_HW_RATE_CCK_LP_1M }, |
| 35 | { .bitrate = 20, |
| 36 | .hw_value = ATH10K_HW_RATE_CCK_LP_2M, |
| 37 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M, |
| 38 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 39 | { .bitrate = 55, |
| 40 | .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M, |
| 41 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M, |
| 42 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 43 | { .bitrate = 110, |
| 44 | .hw_value = ATH10K_HW_RATE_CCK_LP_11M, |
| 45 | .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M, |
| 46 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
Michal Kazior | 5653b39 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 47 | |
Michal Kazior | af00148 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 48 | { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M }, |
| 49 | { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M }, |
| 50 | { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M }, |
| 51 | { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M }, |
| 52 | { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M }, |
| 53 | { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M }, |
| 54 | { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M }, |
| 55 | { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M }, |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 56 | }; |
| 57 | |
Mohammed Shafi Shajakhan | 5269c65 | 2016-06-07 15:47:04 +0300 | [diff] [blame] | 58 | static struct ieee80211_rate ath10k_rates_rev2[] = { |
| 59 | { .bitrate = 10, |
| 60 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M }, |
| 61 | { .bitrate = 20, |
| 62 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M, |
| 63 | .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M, |
| 64 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 65 | { .bitrate = 55, |
| 66 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M, |
| 67 | .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M, |
| 68 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 69 | { .bitrate = 110, |
| 70 | .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M, |
| 71 | .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M, |
| 72 | .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 73 | |
| 74 | { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M }, |
| 75 | { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M }, |
| 76 | { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M }, |
| 77 | { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M }, |
| 78 | { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M }, |
| 79 | { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M }, |
| 80 | { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M }, |
| 81 | { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M }, |
| 82 | }; |
| 83 | |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 84 | #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4 |
| 85 | |
| 86 | #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX) |
| 87 | #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \ |
| 88 | ATH10K_MAC_FIRST_OFDM_RATE_IDX) |
Michal Kazior | dcc3309 | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 89 | #define ath10k_g_rates (ath10k_rates + 0) |
| 90 | #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates)) |
| 91 | |
Mohammed Shafi Shajakhan | 5269c65 | 2016-06-07 15:47:04 +0300 | [diff] [blame] | 92 | #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0) |
| 93 | #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2)) |
| 94 | |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 95 | #define ath10k_wmi_legacy_rates ath10k_rates |
| 96 | |
Michal Kazior | 486017c | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 97 | static bool ath10k_mac_bitrate_is_cck(int bitrate) |
| 98 | { |
| 99 | switch (bitrate) { |
| 100 | case 10: |
| 101 | case 20: |
| 102 | case 55: |
| 103 | case 110: |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | static u8 ath10k_mac_bitrate_to_rate(int bitrate) |
| 111 | { |
| 112 | return DIV_ROUND_UP(bitrate, 5) | |
| 113 | (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0); |
| 114 | } |
| 115 | |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 116 | u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband, |
Yanbo Li | 4b7f353 | 2015-11-12 10:36:10 -0800 | [diff] [blame] | 117 | u8 hw_rate, bool cck) |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 118 | { |
| 119 | const struct ieee80211_rate *rate; |
| 120 | int i; |
| 121 | |
| 122 | for (i = 0; i < sband->n_bitrates; i++) { |
| 123 | rate = &sband->bitrates[i]; |
| 124 | |
Yanbo Li | 4b7f353 | 2015-11-12 10:36:10 -0800 | [diff] [blame] | 125 | if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck) |
| 126 | continue; |
| 127 | |
Michal Kazior | 5528e03 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 128 | if (rate->hw_value == hw_rate) |
| 129 | return i; |
| 130 | else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE && |
| 131 | rate->hw_value_short == hw_rate) |
| 132 | return i; |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Michal Kazior | 01cebe1 | 2015-03-30 09:51:56 +0300 | [diff] [blame] | 138 | u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband, |
| 139 | u32 bitrate) |
| 140 | { |
| 141 | int i; |
| 142 | |
| 143 | for (i = 0; i < sband->n_bitrates; i++) |
| 144 | if (sband->bitrates[i].bitrate == bitrate) |
| 145 | return i; |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Sriram R | f279294e | 2018-09-10 11:09:40 +0530 | [diff] [blame] | 150 | static int ath10k_mac_get_rate_hw_value(int bitrate) |
| 151 | { |
| 152 | int i; |
| 153 | u8 hw_value_prefix = 0; |
| 154 | |
| 155 | if (ath10k_mac_bitrate_is_cck(bitrate)) |
| 156 | hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6; |
| 157 | |
Sriram R | 34e141e | 2018-10-03 08:43:50 +0530 | [diff] [blame] | 158 | for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) { |
Sriram R | f279294e | 2018-09-10 11:09:40 +0530 | [diff] [blame] | 159 | if (ath10k_rates[i].bitrate == bitrate) |
| 160 | return hw_value_prefix | ath10k_rates[i].hw_value; |
| 161 | } |
| 162 | |
| 163 | return -EINVAL; |
| 164 | } |
| 165 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 166 | static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss) |
| 167 | { |
| 168 | switch ((mcs_map >> (2 * nss)) & 0x3) { |
| 169 | case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1; |
| 170 | case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1; |
| 171 | case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1; |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 176 | static u32 |
| 177 | ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) |
| 178 | { |
| 179 | int nss; |
| 180 | |
| 181 | for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--) |
| 182 | if (ht_mcs_mask[nss]) |
| 183 | return nss + 1; |
| 184 | |
| 185 | return 1; |
| 186 | } |
| 187 | |
| 188 | static u32 |
| 189 | ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 190 | { |
| 191 | int nss; |
| 192 | |
| 193 | for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--) |
| 194 | if (vht_mcs_mask[nss]) |
| 195 | return nss + 1; |
| 196 | |
| 197 | return 1; |
| 198 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 199 | |
Raja Mani | 7e247a9 | 2016-04-12 20:15:53 +0530 | [diff] [blame] | 200 | int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val) |
| 201 | { |
| 202 | enum wmi_host_platform_type platform_type; |
| 203 | int ret; |
| 204 | |
| 205 | if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map)) |
| 206 | platform_type = WMI_HOST_PLATFORM_LOW_PERF; |
| 207 | else |
| 208 | platform_type = WMI_HOST_PLATFORM_HIGH_PERF; |
| 209 | |
| 210 | ret = ath10k_wmi_ext_resource_config(ar, platform_type, val); |
| 211 | |
| 212 | if (ret && ret != -EOPNOTSUPP) { |
| 213 | ath10k_warn(ar, "failed to configure ext resource: %d\n", ret); |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 220 | /**********/ |
| 221 | /* Crypto */ |
| 222 | /**********/ |
| 223 | |
| 224 | static int ath10k_send_key(struct ath10k_vif *arvif, |
| 225 | struct ieee80211_key_conf *key, |
| 226 | enum set_key_cmd cmd, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 227 | const u8 *macaddr, u32 flags) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 228 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 229 | struct ath10k *ar = arvif->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 230 | struct wmi_vdev_install_key_arg arg = { |
| 231 | .vdev_id = arvif->vdev_id, |
| 232 | .key_idx = key->keyidx, |
| 233 | .key_len = key->keylen, |
| 234 | .key_data = key->key, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 235 | .key_flags = flags, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 236 | .macaddr = macaddr, |
| 237 | }; |
| 238 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 239 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 240 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 241 | switch (key->cipher) { |
| 242 | case WLAN_CIPHER_SUITE_CCMP: |
Abhishek Ambure | 7d94f86 | 2019-02-08 14:55:26 +0200 | [diff] [blame] | 243 | arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM]; |
Marek Kwaczynski | e4e82e9 | 2015-01-24 12:14:53 +0200 | [diff] [blame] | 244 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 245 | break; |
| 246 | case WLAN_CIPHER_SUITE_TKIP: |
Abhishek Ambure | 7d94f86 | 2019-02-08 14:55:26 +0200 | [diff] [blame] | 247 | arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_TKIP]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 248 | arg.key_txmic_len = 8; |
| 249 | arg.key_rxmic_len = 8; |
| 250 | break; |
| 251 | case WLAN_CIPHER_SUITE_WEP40: |
| 252 | case WLAN_CIPHER_SUITE_WEP104: |
Abhishek Ambure | 7d94f86 | 2019-02-08 14:55:26 +0200 | [diff] [blame] | 253 | arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_WEP]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 254 | break; |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 255 | case WLAN_CIPHER_SUITE_CCMP_256: |
Abhishek Ambure | 7d94f86 | 2019-02-08 14:55:26 +0200 | [diff] [blame] | 256 | arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM]; |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 257 | break; |
| 258 | case WLAN_CIPHER_SUITE_GCMP: |
| 259 | case WLAN_CIPHER_SUITE_GCMP_256: |
Abhishek Ambure | 7d94f86 | 2019-02-08 14:55:26 +0200 | [diff] [blame] | 260 | arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_GCM]; |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 261 | break; |
| 262 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 263 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 264 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 265 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 266 | WARN_ON(1); |
| 267 | return -EINVAL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 268 | default: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 269 | ath10k_warn(ar, "cipher %d is not supported\n", key->cipher); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 270 | return -EOPNOTSUPP; |
| 271 | } |
| 272 | |
Kalle Valo | b9e284e | 2015-10-05 17:56:35 +0300 | [diff] [blame] | 273 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 274 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 275 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 276 | if (cmd == DISABLE_KEY) { |
Abhishek Ambure | 7d94f86 | 2019-02-08 14:55:26 +0200 | [diff] [blame] | 277 | arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_NONE]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 278 | arg.key_data = NULL; |
| 279 | } |
| 280 | |
| 281 | return ath10k_wmi_vdev_install_key(arvif->ar, &arg); |
| 282 | } |
| 283 | |
| 284 | static int ath10k_install_key(struct ath10k_vif *arvif, |
| 285 | struct ieee80211_key_conf *key, |
| 286 | enum set_key_cmd cmd, |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 287 | const u8 *macaddr, u32 flags) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 288 | { |
| 289 | struct ath10k *ar = arvif->ar; |
| 290 | int ret; |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 291 | unsigned long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 292 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 293 | lockdep_assert_held(&ar->conf_mutex); |
| 294 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 295 | reinit_completion(&ar->install_key_done); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 296 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 297 | if (arvif->nohwcrypt) |
| 298 | return 1; |
| 299 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 300 | ret = ath10k_send_key(arvif, key, cmd, macaddr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 301 | if (ret) |
| 302 | return ret; |
| 303 | |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 304 | time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ); |
| 305 | if (time_left == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 306 | return -ETIMEDOUT; |
| 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif, |
| 312 | const u8 *addr) |
| 313 | { |
| 314 | struct ath10k *ar = arvif->ar; |
| 315 | struct ath10k_peer *peer; |
| 316 | int ret; |
| 317 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 318 | u32 flags; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 319 | |
| 320 | lockdep_assert_held(&ar->conf_mutex); |
| 321 | |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 322 | if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP && |
Peter Oh | 7c97b72 | 2015-12-03 09:50:55 -0800 | [diff] [blame] | 323 | arvif->vif->type != NL80211_IFTYPE_ADHOC && |
| 324 | arvif->vif->type != NL80211_IFTYPE_MESH_POINT)) |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 325 | return -EINVAL; |
| 326 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 327 | spin_lock_bh(&ar->data_lock); |
| 328 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 329 | spin_unlock_bh(&ar->data_lock); |
| 330 | |
| 331 | if (!peer) |
| 332 | return -ENOENT; |
| 333 | |
| 334 | for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) { |
| 335 | if (arvif->wep_keys[i] == NULL) |
| 336 | continue; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 337 | |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 338 | switch (arvif->vif->type) { |
| 339 | case NL80211_IFTYPE_AP: |
| 340 | flags = WMI_KEY_PAIRWISE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 341 | |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 342 | if (arvif->def_wep_key_idx == i) |
| 343 | flags |= WMI_KEY_TX_USAGE; |
Michal Kazior | ce90b27 | 2015-04-10 13:23:21 +0000 | [diff] [blame] | 344 | |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 345 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], |
| 346 | SET_KEY, addr, flags); |
| 347 | if (ret < 0) |
| 348 | return ret; |
| 349 | break; |
| 350 | case NL80211_IFTYPE_ADHOC: |
| 351 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], |
| 352 | SET_KEY, addr, |
| 353 | WMI_KEY_PAIRWISE); |
| 354 | if (ret < 0) |
| 355 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 356 | |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 357 | ret = ath10k_install_key(arvif, arvif->wep_keys[i], |
| 358 | SET_KEY, addr, WMI_KEY_GROUP); |
| 359 | if (ret < 0) |
| 360 | return ret; |
| 361 | break; |
| 362 | default: |
| 363 | WARN_ON(1); |
| 364 | return -EINVAL; |
| 365 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 366 | |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 367 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 368 | peer->keys[i] = arvif->wep_keys[i]; |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 369 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 370 | } |
| 371 | |
Michal Kazior | ce90b27 | 2015-04-10 13:23:21 +0000 | [diff] [blame] | 372 | /* In some cases (notably with static WEP IBSS with multiple keys) |
| 373 | * multicast Tx becomes broken. Both pairwise and groupwise keys are |
| 374 | * installed already. Using WMI_KEY_TX_USAGE in different combinations |
| 375 | * didn't seem help. Using def_keyid vdev parameter seems to be |
| 376 | * effective so use that. |
| 377 | * |
| 378 | * FIXME: Revisit. Perhaps this can be done in a less hacky way. |
| 379 | */ |
Michal Kazior | 8674d90 | 2015-08-13 14:10:46 +0200 | [diff] [blame] | 380 | if (arvif->vif->type != NL80211_IFTYPE_ADHOC) |
| 381 | return 0; |
| 382 | |
Michal Kazior | ce90b27 | 2015-04-10 13:23:21 +0000 | [diff] [blame] | 383 | if (arvif->def_wep_key_idx == -1) |
| 384 | return 0; |
| 385 | |
| 386 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 387 | arvif->vdev_id, |
| 388 | arvif->ar->wmi.vdev_param->def_keyid, |
| 389 | arvif->def_wep_key_idx); |
| 390 | if (ret) { |
| 391 | ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n", |
| 392 | arvif->vdev_id, ret); |
| 393 | return ret; |
| 394 | } |
| 395 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static int ath10k_clear_peer_keys(struct ath10k_vif *arvif, |
| 400 | const u8 *addr) |
| 401 | { |
| 402 | struct ath10k *ar = arvif->ar; |
| 403 | struct ath10k_peer *peer; |
| 404 | int first_errno = 0; |
| 405 | int ret; |
| 406 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 407 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 408 | |
| 409 | lockdep_assert_held(&ar->conf_mutex); |
| 410 | |
| 411 | spin_lock_bh(&ar->data_lock); |
| 412 | peer = ath10k_peer_find(ar, arvif->vdev_id, addr); |
| 413 | spin_unlock_bh(&ar->data_lock); |
| 414 | |
| 415 | if (!peer) |
| 416 | return -ENOENT; |
| 417 | |
| 418 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 419 | if (peer->keys[i] == NULL) |
| 420 | continue; |
| 421 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 422 | /* key flags are not required to delete the key */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 423 | ret = ath10k_install_key(arvif, peer->keys[i], |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 424 | DISABLE_KEY, addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 425 | if (ret < 0 && first_errno == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 426 | first_errno = ret; |
| 427 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 428 | if (ret < 0) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 429 | ath10k_warn(ar, "failed to remove peer wep key %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 430 | i, ret); |
| 431 | |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 432 | spin_lock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 433 | peer->keys[i] = NULL; |
Sujith Manoharan | ae16713 | 2014-11-25 11:46:59 +0530 | [diff] [blame] | 434 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | return first_errno; |
| 438 | } |
| 439 | |
Sujith Manoharan | 504f6cd | 2014-11-25 11:46:58 +0530 | [diff] [blame] | 440 | bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr, |
| 441 | u8 keyidx) |
| 442 | { |
| 443 | struct ath10k_peer *peer; |
| 444 | int i; |
| 445 | |
| 446 | lockdep_assert_held(&ar->data_lock); |
| 447 | |
| 448 | /* We don't know which vdev this peer belongs to, |
| 449 | * since WMI doesn't give us that information. |
| 450 | * |
| 451 | * FIXME: multi-bss needs to be handled. |
| 452 | */ |
| 453 | peer = ath10k_peer_find(ar, 0, addr); |
| 454 | if (!peer) |
| 455 | return false; |
| 456 | |
| 457 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 458 | if (peer->keys[i] && peer->keys[i]->keyidx == keyidx) |
| 459 | return true; |
| 460 | } |
| 461 | |
| 462 | return false; |
| 463 | } |
| 464 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 465 | static int ath10k_clear_vdev_key(struct ath10k_vif *arvif, |
| 466 | struct ieee80211_key_conf *key) |
| 467 | { |
| 468 | struct ath10k *ar = arvif->ar; |
| 469 | struct ath10k_peer *peer; |
| 470 | u8 addr[ETH_ALEN]; |
| 471 | int first_errno = 0; |
| 472 | int ret; |
| 473 | int i; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 474 | u32 flags = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 475 | |
| 476 | lockdep_assert_held(&ar->conf_mutex); |
| 477 | |
| 478 | for (;;) { |
| 479 | /* since ath10k_install_key we can't hold data_lock all the |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 480 | * time, so we try to remove the keys incrementally |
| 481 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 482 | spin_lock_bh(&ar->data_lock); |
| 483 | i = 0; |
| 484 | list_for_each_entry(peer, &ar->peers, list) { |
| 485 | for (i = 0; i < ARRAY_SIZE(peer->keys); i++) { |
| 486 | if (peer->keys[i] == key) { |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 487 | ether_addr_copy(addr, peer->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 488 | peer->keys[i] = NULL; |
| 489 | break; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | if (i < ARRAY_SIZE(peer->keys)) |
| 494 | break; |
| 495 | } |
| 496 | spin_unlock_bh(&ar->data_lock); |
| 497 | |
| 498 | if (i == ARRAY_SIZE(peer->keys)) |
| 499 | break; |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 500 | /* key flags are not required to delete the key */ |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 501 | ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 502 | if (ret < 0 && first_errno == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 503 | first_errno = ret; |
| 504 | |
| 505 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 506 | ath10k_warn(ar, "failed to remove key for %pM: %d\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 507 | addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | return first_errno; |
| 511 | } |
| 512 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 513 | static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif, |
| 514 | struct ieee80211_key_conf *key) |
| 515 | { |
| 516 | struct ath10k *ar = arvif->ar; |
| 517 | struct ath10k_peer *peer; |
| 518 | int ret; |
| 519 | |
| 520 | lockdep_assert_held(&ar->conf_mutex); |
| 521 | |
| 522 | list_for_each_entry(peer, &ar->peers, list) { |
Kalle Valo | c178da5 | 2016-04-13 14:13:49 +0300 | [diff] [blame] | 523 | if (ether_addr_equal(peer->addr, arvif->vif->addr)) |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 524 | continue; |
| 525 | |
Kalle Valo | c178da5 | 2016-04-13 14:13:49 +0300 | [diff] [blame] | 526 | if (ether_addr_equal(peer->addr, arvif->bssid)) |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 527 | continue; |
| 528 | |
| 529 | if (peer->keys[key->keyidx] == key) |
| 530 | continue; |
| 531 | |
| 532 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n", |
| 533 | arvif->vdev_id, key->keyidx); |
| 534 | |
| 535 | ret = ath10k_install_peer_wep_keys(arvif, peer->addr); |
| 536 | if (ret) { |
| 537 | ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n", |
| 538 | arvif->vdev_id, peer->addr, ret); |
| 539 | return ret; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 546 | /*********************/ |
| 547 | /* General utilities */ |
| 548 | /*********************/ |
| 549 | |
| 550 | static inline enum wmi_phy_mode |
| 551 | chan_to_phymode(const struct cfg80211_chan_def *chandef) |
| 552 | { |
| 553 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 554 | |
| 555 | switch (chandef->chan->band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 556 | case NL80211_BAND_2GHZ: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 557 | switch (chandef->width) { |
| 558 | case NL80211_CHAN_WIDTH_20_NOHT: |
Peter Oh | 6faab12 | 2014-12-18 10:13:00 -0800 | [diff] [blame] | 559 | if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM) |
| 560 | phymode = MODE_11B; |
| 561 | else |
| 562 | phymode = MODE_11G; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 563 | break; |
| 564 | case NL80211_CHAN_WIDTH_20: |
| 565 | phymode = MODE_11NG_HT20; |
| 566 | break; |
| 567 | case NL80211_CHAN_WIDTH_40: |
| 568 | phymode = MODE_11NG_HT40; |
| 569 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 570 | case NL80211_CHAN_WIDTH_5: |
| 571 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 572 | case NL80211_CHAN_WIDTH_80: |
| 573 | case NL80211_CHAN_WIDTH_80P80: |
| 574 | case NL80211_CHAN_WIDTH_160: |
| 575 | phymode = MODE_UNKNOWN; |
| 576 | break; |
| 577 | } |
| 578 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 579 | case NL80211_BAND_5GHZ: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 580 | switch (chandef->width) { |
| 581 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 582 | phymode = MODE_11A; |
| 583 | break; |
| 584 | case NL80211_CHAN_WIDTH_20: |
| 585 | phymode = MODE_11NA_HT20; |
| 586 | break; |
| 587 | case NL80211_CHAN_WIDTH_40: |
| 588 | phymode = MODE_11NA_HT40; |
| 589 | break; |
| 590 | case NL80211_CHAN_WIDTH_80: |
| 591 | phymode = MODE_11AC_VHT80; |
| 592 | break; |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 593 | case NL80211_CHAN_WIDTH_160: |
| 594 | phymode = MODE_11AC_VHT160; |
| 595 | break; |
| 596 | case NL80211_CHAN_WIDTH_80P80: |
| 597 | phymode = MODE_11AC_VHT80_80; |
| 598 | break; |
John W. Linville | 0f817ed | 2013-06-27 13:50:09 -0400 | [diff] [blame] | 599 | case NL80211_CHAN_WIDTH_5: |
| 600 | case NL80211_CHAN_WIDTH_10: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 601 | phymode = MODE_UNKNOWN; |
| 602 | break; |
| 603 | } |
| 604 | break; |
| 605 | default: |
| 606 | break; |
| 607 | } |
| 608 | |
| 609 | WARN_ON(phymode == MODE_UNKNOWN); |
| 610 | return phymode; |
| 611 | } |
| 612 | |
| 613 | static u8 ath10k_parse_mpdudensity(u8 mpdudensity) |
| 614 | { |
| 615 | /* |
| 616 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 617 | * 0 for no restriction |
| 618 | * 1 for 1/4 us |
| 619 | * 2 for 1/2 us |
| 620 | * 3 for 1 us |
| 621 | * 4 for 2 us |
| 622 | * 5 for 4 us |
| 623 | * 6 for 8 us |
| 624 | * 7 for 16 us |
| 625 | */ |
| 626 | switch (mpdudensity) { |
| 627 | case 0: |
| 628 | return 0; |
| 629 | case 1: |
| 630 | case 2: |
| 631 | case 3: |
| 632 | /* Our lower layer calculations limit our precision to |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 633 | * 1 microsecond |
| 634 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 635 | return 1; |
| 636 | case 4: |
| 637 | return 2; |
| 638 | case 5: |
| 639 | return 4; |
| 640 | case 6: |
| 641 | return 8; |
| 642 | case 7: |
| 643 | return 16; |
| 644 | default: |
| 645 | return 0; |
| 646 | } |
| 647 | } |
| 648 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 649 | int ath10k_mac_vif_chan(struct ieee80211_vif *vif, |
| 650 | struct cfg80211_chan_def *def) |
| 651 | { |
| 652 | struct ieee80211_chanctx_conf *conf; |
| 653 | |
| 654 | rcu_read_lock(); |
| 655 | conf = rcu_dereference(vif->chanctx_conf); |
| 656 | if (!conf) { |
| 657 | rcu_read_unlock(); |
| 658 | return -ENOENT; |
| 659 | } |
| 660 | |
| 661 | *def = conf->def; |
| 662 | rcu_read_unlock(); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw, |
| 668 | struct ieee80211_chanctx_conf *conf, |
| 669 | void *data) |
| 670 | { |
| 671 | int *num = data; |
| 672 | |
| 673 | (*num)++; |
| 674 | } |
| 675 | |
| 676 | static int ath10k_mac_num_chanctxs(struct ath10k *ar) |
| 677 | { |
| 678 | int num = 0; |
| 679 | |
| 680 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 681 | ath10k_mac_num_chanctxs_iter, |
| 682 | &num); |
| 683 | |
| 684 | return num; |
| 685 | } |
| 686 | |
| 687 | static void |
| 688 | ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw, |
| 689 | struct ieee80211_chanctx_conf *conf, |
| 690 | void *data) |
| 691 | { |
| 692 | struct cfg80211_chan_def **def = data; |
| 693 | |
| 694 | *def = &conf->def; |
| 695 | } |
| 696 | |
Dundi Raviteja | c6f537a | 2019-06-03 17:41:51 +0300 | [diff] [blame] | 697 | static void ath10k_wait_for_peer_delete_done(struct ath10k *ar, u32 vdev_id, |
| 698 | const u8 *addr) |
| 699 | { |
| 700 | unsigned long time_left; |
| 701 | int ret; |
| 702 | |
| 703 | if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) { |
| 704 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); |
| 705 | if (ret) { |
| 706 | ath10k_warn(ar, "failed wait for peer deleted"); |
| 707 | return; |
| 708 | } |
| 709 | |
| 710 | time_left = wait_for_completion_timeout(&ar->peer_delete_done, |
| 711 | 5 * HZ); |
| 712 | if (!time_left) |
| 713 | ath10k_warn(ar, "Timeout in receiving peer delete response\n"); |
| 714 | } |
| 715 | } |
| 716 | |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 717 | static int ath10k_peer_create(struct ath10k *ar, |
| 718 | struct ieee80211_vif *vif, |
| 719 | struct ieee80211_sta *sta, |
| 720 | u32 vdev_id, |
| 721 | const u8 *addr, |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 722 | enum wmi_peer_type peer_type) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 723 | { |
Michal Kazior | e04cafb | 2015-08-05 12:15:24 +0200 | [diff] [blame] | 724 | struct ath10k_vif *arvif; |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 725 | struct ath10k_peer *peer; |
Michal Kazior | e04cafb | 2015-08-05 12:15:24 +0200 | [diff] [blame] | 726 | int num_peers = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 727 | int ret; |
| 728 | |
| 729 | lockdep_assert_held(&ar->conf_mutex); |
| 730 | |
Michal Kazior | e04cafb | 2015-08-05 12:15:24 +0200 | [diff] [blame] | 731 | num_peers = ar->num_peers; |
| 732 | |
| 733 | /* Each vdev consumes a peer entry as well */ |
| 734 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 735 | num_peers++; |
| 736 | |
| 737 | if (num_peers >= ar->max_num_peers) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 738 | return -ENOBUFS; |
| 739 | |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 740 | ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 741 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 742 | 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] | 743 | addr, vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 744 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 745 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 746 | |
| 747 | ret = ath10k_wait_for_peer_created(ar, vdev_id, addr); |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 748 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 749 | 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] | 750 | addr, vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 751 | return ret; |
Ben Greear | 479398b | 2013-11-04 09:19:34 -0800 | [diff] [blame] | 752 | } |
Michal Kazior | 292a753 | 2014-11-25 15:16:04 +0100 | [diff] [blame] | 753 | |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 754 | spin_lock_bh(&ar->data_lock); |
| 755 | |
| 756 | peer = ath10k_peer_find(ar, vdev_id, addr); |
| 757 | if (!peer) { |
Ben Greear | fee48cf | 2016-04-01 14:12:12 -0700 | [diff] [blame] | 758 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 759 | ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n", |
| 760 | addr, vdev_id); |
Dundi Raviteja | c6f537a | 2019-06-03 17:41:51 +0300 | [diff] [blame] | 761 | ath10k_wait_for_peer_delete_done(ar, vdev_id, addr); |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 762 | return -ENOENT; |
| 763 | } |
| 764 | |
| 765 | peer->vif = vif; |
| 766 | peer->sta = sta; |
| 767 | |
| 768 | spin_unlock_bh(&ar->data_lock); |
| 769 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 770 | ar->num_peers++; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 775 | static int ath10k_mac_set_kickout(struct ath10k_vif *arvif) |
| 776 | { |
| 777 | struct ath10k *ar = arvif->ar; |
| 778 | u32 param; |
| 779 | int ret; |
| 780 | |
| 781 | param = ar->wmi.pdev_param->sta_kickout_th; |
| 782 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 783 | ATH10K_KICKOUT_THRESHOLD); |
| 784 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 785 | 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] | 786 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 787 | return ret; |
| 788 | } |
| 789 | |
| 790 | param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs; |
| 791 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 792 | ATH10K_KEEPALIVE_MIN_IDLE); |
| 793 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 794 | 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] | 795 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 796 | return ret; |
| 797 | } |
| 798 | |
| 799 | param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs; |
| 800 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 801 | ATH10K_KEEPALIVE_MAX_IDLE); |
| 802 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 803 | 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] | 804 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 805 | return ret; |
| 806 | } |
| 807 | |
| 808 | param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs; |
| 809 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, |
| 810 | ATH10K_KEEPALIVE_MAX_UNRESPONSIVE); |
| 811 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 812 | 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] | 813 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 814 | return ret; |
| 815 | } |
| 816 | |
| 817 | return 0; |
| 818 | } |
| 819 | |
Vivek Natarajan | acab640 | 2014-11-26 09:06:12 +0200 | [diff] [blame] | 820 | static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value) |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 821 | { |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 822 | struct ath10k *ar = arvif->ar; |
| 823 | u32 vdev_param; |
| 824 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 825 | vdev_param = ar->wmi.vdev_param->rts_threshold; |
| 826 | 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] | 827 | } |
| 828 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 829 | static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr) |
| 830 | { |
| 831 | int ret; |
| 832 | |
| 833 | lockdep_assert_held(&ar->conf_mutex); |
| 834 | |
| 835 | ret = ath10k_wmi_peer_delete(ar, vdev_id, addr); |
| 836 | if (ret) |
| 837 | return ret; |
| 838 | |
| 839 | ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr); |
| 840 | if (ret) |
| 841 | return ret; |
| 842 | |
Dundi Raviteja | c6f537a | 2019-06-03 17:41:51 +0300 | [diff] [blame] | 843 | if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) { |
| 844 | unsigned long time_left; |
| 845 | |
| 846 | time_left = wait_for_completion_timeout |
| 847 | (&ar->peer_delete_done, 5 * HZ); |
| 848 | |
| 849 | if (!time_left) { |
| 850 | ath10k_warn(ar, "Timeout in receiving peer delete response\n"); |
| 851 | return -ETIMEDOUT; |
| 852 | } |
| 853 | } |
| 854 | |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 855 | ar->num_peers--; |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 856 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id) |
| 861 | { |
| 862 | struct ath10k_peer *peer, *tmp; |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 863 | int peer_id; |
Ben Greear | 6d68f79 | 2016-06-30 15:23:53 +0300 | [diff] [blame] | 864 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 865 | |
| 866 | lockdep_assert_held(&ar->conf_mutex); |
| 867 | |
| 868 | spin_lock_bh(&ar->data_lock); |
| 869 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 870 | if (peer->vdev_id != vdev_id) |
| 871 | continue; |
| 872 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 873 | ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 874 | peer->addr, vdev_id); |
| 875 | |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 876 | for_each_set_bit(peer_id, peer->peer_ids, |
| 877 | ATH10K_MAX_NUM_PEER_IDS) { |
| 878 | ar->peer_map[peer_id] = NULL; |
| 879 | } |
| 880 | |
Ben Greear | 6d68f79 | 2016-06-30 15:23:53 +0300 | [diff] [blame] | 881 | /* Double check that peer is properly un-referenced from |
| 882 | * the peer_map |
| 883 | */ |
| 884 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) { |
| 885 | if (ar->peer_map[i] == peer) { |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 886 | ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n", |
Ben Greear | 6d68f79 | 2016-06-30 15:23:53 +0300 | [diff] [blame] | 887 | peer->addr, peer, i); |
| 888 | ar->peer_map[i] = NULL; |
| 889 | } |
| 890 | } |
| 891 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 892 | list_del(&peer->list); |
| 893 | kfree(peer); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 894 | ar->num_peers--; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 895 | } |
| 896 | spin_unlock_bh(&ar->data_lock); |
| 897 | } |
| 898 | |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 899 | static void ath10k_peer_cleanup_all(struct ath10k *ar) |
| 900 | { |
| 901 | struct ath10k_peer *peer, *tmp; |
Ben Greear | 6d68f79 | 2016-06-30 15:23:53 +0300 | [diff] [blame] | 902 | int i; |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 903 | |
| 904 | lockdep_assert_held(&ar->conf_mutex); |
| 905 | |
| 906 | spin_lock_bh(&ar->data_lock); |
| 907 | list_for_each_entry_safe(peer, tmp, &ar->peers, list) { |
| 908 | list_del(&peer->list); |
| 909 | kfree(peer); |
| 910 | } |
Ben Greear | 6d68f79 | 2016-06-30 15:23:53 +0300 | [diff] [blame] | 911 | |
| 912 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) |
| 913 | ar->peer_map[i] = NULL; |
| 914 | |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 915 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | 292a753 | 2014-11-25 15:16:04 +0100 | [diff] [blame] | 916 | |
| 917 | ar->num_peers = 0; |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 918 | ar->num_stations = 0; |
Michal Kazior | a96d774 | 2013-07-16 09:38:56 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 921 | static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id, |
| 922 | struct ieee80211_sta *sta, |
| 923 | enum wmi_tdls_peer_state state) |
| 924 | { |
| 925 | int ret; |
| 926 | struct wmi_tdls_peer_update_cmd_arg arg = {}; |
| 927 | struct wmi_tdls_peer_capab_arg cap = {}; |
| 928 | struct wmi_channel_arg chan_arg = {}; |
| 929 | |
| 930 | lockdep_assert_held(&ar->conf_mutex); |
| 931 | |
| 932 | arg.vdev_id = vdev_id; |
| 933 | arg.peer_state = state; |
| 934 | ether_addr_copy(arg.addr, sta->addr); |
| 935 | |
| 936 | cap.peer_max_sp = sta->max_sp; |
| 937 | cap.peer_uapsd_queues = sta->uapsd_queues; |
| 938 | |
| 939 | if (state == WMI_TDLS_PEER_STATE_CONNECTED && |
| 940 | !sta->tdls_initiator) |
| 941 | cap.is_peer_responder = 1; |
| 942 | |
| 943 | ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg); |
| 944 | if (ret) { |
| 945 | ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n", |
| 946 | arg.addr, vdev_id, ret); |
| 947 | return ret; |
| 948 | } |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 953 | /************************/ |
| 954 | /* Interface management */ |
| 955 | /************************/ |
| 956 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 957 | void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif) |
| 958 | { |
| 959 | struct ath10k *ar = arvif->ar; |
| 960 | |
| 961 | lockdep_assert_held(&ar->data_lock); |
| 962 | |
| 963 | if (!arvif->beacon) |
| 964 | return; |
| 965 | |
| 966 | if (!arvif->beacon_buf) |
| 967 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr, |
| 968 | arvif->beacon->len, DMA_TO_DEVICE); |
| 969 | |
Michal Kazior | af21319 | 2015-01-29 14:29:52 +0200 | [diff] [blame] | 970 | if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED && |
| 971 | arvif->beacon_state != ATH10K_BEACON_SENT)) |
| 972 | return; |
| 973 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 974 | dev_kfree_skb_any(arvif->beacon); |
| 975 | |
| 976 | arvif->beacon = NULL; |
Michal Kazior | af21319 | 2015-01-29 14:29:52 +0200 | [diff] [blame] | 977 | arvif->beacon_state = ATH10K_BEACON_SCHEDULED; |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif) |
| 981 | { |
| 982 | struct ath10k *ar = arvif->ar; |
| 983 | |
| 984 | lockdep_assert_held(&ar->data_lock); |
| 985 | |
| 986 | ath10k_mac_vif_beacon_free(arvif); |
| 987 | |
| 988 | if (arvif->beacon_buf) { |
| 989 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 990 | arvif->beacon_buf, arvif->beacon_paddr); |
| 991 | arvif->beacon_buf = NULL; |
| 992 | } |
| 993 | } |
| 994 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 995 | static inline int ath10k_vdev_setup_sync(struct ath10k *ar) |
| 996 | { |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 997 | unsigned long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 998 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 999 | lockdep_assert_held(&ar->conf_mutex); |
| 1000 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1001 | if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) |
| 1002 | return -ESHUTDOWN; |
| 1003 | |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 1004 | time_left = wait_for_completion_timeout(&ar->vdev_setup_done, |
| 1005 | ATH10K_VDEV_SETUP_TIMEOUT_HZ); |
| 1006 | if (time_left == 0) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1007 | return -ETIMEDOUT; |
| 1008 | |
Ben Greear | 833fd34 | 2018-09-06 19:46:20 +0300 | [diff] [blame] | 1009 | return ar->last_wmi_vdev_start_status; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1010 | } |
| 1011 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1012 | static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1013 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1014 | struct cfg80211_chan_def *chandef = NULL; |
Maninder Singh | 19be9e9 | 2015-07-16 09:25:33 +0530 | [diff] [blame] | 1015 | struct ieee80211_channel *channel = NULL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1016 | struct wmi_vdev_start_request_arg arg = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1017 | int ret = 0; |
| 1018 | |
| 1019 | lockdep_assert_held(&ar->conf_mutex); |
| 1020 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1021 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 1022 | ath10k_mac_get_any_chandef_iter, |
| 1023 | &chandef); |
| 1024 | if (WARN_ON_ONCE(!chandef)) |
| 1025 | return -ENOENT; |
| 1026 | |
| 1027 | channel = chandef->chan; |
| 1028 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1029 | arg.vdev_id = vdev_id; |
| 1030 | arg.channel.freq = channel->center_freq; |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1031 | arg.channel.band_center_freq1 = chandef->center_freq1; |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 1032 | arg.channel.band_center_freq2 = chandef->center_freq2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1033 | |
| 1034 | /* TODO setup this dynamically, what in case we |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 1035 | * don't have any vifs? |
| 1036 | */ |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1037 | arg.channel.mode = chan_to_phymode(chandef); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1038 | arg.channel.chan_radar = |
| 1039 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1040 | |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 1041 | arg.channel.min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 1042 | arg.channel.max_power = channel->max_power * 2; |
| 1043 | arg.channel.max_reg_power = channel->max_reg_power * 2; |
| 1044 | arg.channel.max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1045 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1046 | reinit_completion(&ar->vdev_setup_done); |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 1047 | reinit_completion(&ar->vdev_delete_done); |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1048 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1049 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 1050 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1051 | ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1052 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1053 | return ret; |
| 1054 | } |
| 1055 | |
| 1056 | ret = ath10k_vdev_setup_sync(ar); |
| 1057 | if (ret) { |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 1058 | 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] | 1059 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1060 | return ret; |
| 1061 | } |
| 1062 | |
| 1063 | ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr); |
| 1064 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1065 | ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1066 | vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1067 | goto vdev_stop; |
| 1068 | } |
| 1069 | |
| 1070 | ar->monitor_vdev_id = vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1071 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1072 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n", |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1073 | ar->monitor_vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1074 | return 0; |
| 1075 | |
| 1076 | vdev_stop: |
| 1077 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 1078 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1079 | 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] | 1080 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1081 | |
| 1082 | return ret; |
| 1083 | } |
| 1084 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1085 | static int ath10k_monitor_vdev_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1086 | { |
| 1087 | int ret = 0; |
| 1088 | |
| 1089 | lockdep_assert_held(&ar->conf_mutex); |
| 1090 | |
Marek Puzyniak | 52fa019 | 2013-09-24 14:06:24 +0200 | [diff] [blame] | 1091 | ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id); |
| 1092 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1093 | ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1094 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1095 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1096 | reinit_completion(&ar->vdev_setup_done); |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 1097 | reinit_completion(&ar->vdev_delete_done); |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 1098 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1099 | ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id); |
| 1100 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1101 | 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] | 1102 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1103 | |
| 1104 | ret = ath10k_vdev_setup_sync(ar); |
| 1105 | if (ret) |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 1106 | ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1107 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1108 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1109 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n", |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1110 | ar->monitor_vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1111 | return ret; |
| 1112 | } |
| 1113 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1114 | static int ath10k_monitor_vdev_create(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1115 | { |
| 1116 | int bit, ret = 0; |
| 1117 | |
| 1118 | lockdep_assert_held(&ar->conf_mutex); |
| 1119 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 1120 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1121 | 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] | 1122 | return -ENOMEM; |
| 1123 | } |
| 1124 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 1125 | bit = __ffs64(ar->free_vdev_map); |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 1126 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 1127 | ar->monitor_vdev_id = bit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1128 | |
| 1129 | ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id, |
| 1130 | WMI_VDEV_TYPE_MONITOR, |
| 1131 | 0, ar->mac_addr); |
| 1132 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1133 | ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1134 | ar->monitor_vdev_id, ret); |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 1135 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1136 | } |
| 1137 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 1138 | ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1139 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1140 | ar->monitor_vdev_id); |
| 1141 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1142 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1143 | } |
| 1144 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1145 | static int ath10k_monitor_vdev_delete(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1146 | { |
| 1147 | int ret = 0; |
| 1148 | |
| 1149 | lockdep_assert_held(&ar->conf_mutex); |
| 1150 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1151 | ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id); |
| 1152 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1153 | 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] | 1154 | ar->monitor_vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1155 | return ret; |
| 1156 | } |
| 1157 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 1158 | ar->free_vdev_map |= 1LL << ar->monitor_vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1159 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1160 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1161 | ar->monitor_vdev_id); |
| 1162 | return ret; |
| 1163 | } |
| 1164 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1165 | static int ath10k_monitor_start(struct ath10k *ar) |
| 1166 | { |
| 1167 | int ret; |
| 1168 | |
| 1169 | lockdep_assert_held(&ar->conf_mutex); |
| 1170 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1171 | ret = ath10k_monitor_vdev_create(ar); |
| 1172 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1173 | ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1174 | return ret; |
| 1175 | } |
| 1176 | |
| 1177 | ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id); |
| 1178 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1179 | ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1180 | ath10k_monitor_vdev_delete(ar); |
| 1181 | return ret; |
| 1182 | } |
| 1183 | |
| 1184 | ar->monitor_started = true; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1185 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n"); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1186 | |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1190 | static int ath10k_monitor_stop(struct ath10k *ar) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1191 | { |
| 1192 | int ret; |
| 1193 | |
| 1194 | lockdep_assert_held(&ar->conf_mutex); |
| 1195 | |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1196 | ret = ath10k_monitor_vdev_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1197 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1198 | ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1199 | return ret; |
| 1200 | } |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1201 | |
| 1202 | ret = ath10k_monitor_vdev_delete(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1203 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1204 | ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1205 | return ret; |
| 1206 | } |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1207 | |
| 1208 | ar->monitor_started = false; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1209 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n"); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1210 | |
| 1211 | return 0; |
| 1212 | } |
| 1213 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1214 | static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar) |
| 1215 | { |
| 1216 | int num_ctx; |
| 1217 | |
| 1218 | /* At least one chanctx is required to derive a channel to start |
| 1219 | * monitor vdev on. |
| 1220 | */ |
| 1221 | num_ctx = ath10k_mac_num_chanctxs(ar); |
| 1222 | if (num_ctx == 0) |
| 1223 | return false; |
| 1224 | |
| 1225 | /* If there's already an existing special monitor interface then don't |
| 1226 | * bother creating another monitor vdev. |
| 1227 | */ |
| 1228 | if (ar->monitor_arvif) |
| 1229 | return false; |
| 1230 | |
| 1231 | return ar->monitor || |
Manoharan, Rajkumar | 705d7aa | 2016-11-23 16:58:11 +0200 | [diff] [blame] | 1232 | (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST, |
| 1233 | ar->running_fw->fw_file.fw_features) && |
| 1234 | (ar->filter_flags & FIF_OTHER_BSS)) || |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1235 | test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 1236 | } |
| 1237 | |
| 1238 | static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar) |
| 1239 | { |
| 1240 | int num_ctx; |
| 1241 | |
| 1242 | num_ctx = ath10k_mac_num_chanctxs(ar); |
| 1243 | |
| 1244 | /* FIXME: Current interface combinations and cfg80211/mac80211 code |
| 1245 | * shouldn't allow this but make sure to prevent handling the following |
| 1246 | * case anyway since multi-channel DFS hasn't been tested at all. |
| 1247 | */ |
| 1248 | if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1) |
| 1249 | return false; |
| 1250 | |
| 1251 | return true; |
| 1252 | } |
| 1253 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1254 | static int ath10k_monitor_recalc(struct ath10k *ar) |
| 1255 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1256 | bool needed; |
| 1257 | bool allowed; |
| 1258 | int ret; |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1259 | |
| 1260 | lockdep_assert_held(&ar->conf_mutex); |
| 1261 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1262 | needed = ath10k_mac_monitor_vdev_is_needed(ar); |
| 1263 | allowed = ath10k_mac_monitor_vdev_is_allowed(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1264 | |
| 1265 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1266 | "mac monitor recalc started? %d needed? %d allowed? %d\n", |
| 1267 | ar->monitor_started, needed, allowed); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1268 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1269 | if (WARN_ON(needed && !allowed)) { |
| 1270 | if (ar->monitor_started) { |
| 1271 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n"); |
| 1272 | |
| 1273 | ret = ath10k_monitor_stop(ar); |
| 1274 | if (ret) |
Kalle Valo | 2a99508 | 2015-10-05 17:56:37 +0300 | [diff] [blame] | 1275 | ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", |
| 1276 | ret); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1277 | /* not serious */ |
| 1278 | } |
| 1279 | |
| 1280 | return -EPERM; |
| 1281 | } |
| 1282 | |
| 1283 | if (needed == ar->monitor_started) |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1284 | return 0; |
| 1285 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1286 | if (needed) |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1287 | return ath10k_monitor_start(ar); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1288 | else |
| 1289 | return ath10k_monitor_stop(ar); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1290 | } |
| 1291 | |
Bartosz Markowski | 7cfe045 | 2016-12-15 11:23:24 +0200 | [diff] [blame] | 1292 | static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif) |
| 1293 | { |
| 1294 | struct ath10k *ar = arvif->ar; |
| 1295 | |
| 1296 | lockdep_assert_held(&ar->conf_mutex); |
| 1297 | |
| 1298 | if (!arvif->is_started) { |
| 1299 | ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n"); |
| 1300 | return false; |
| 1301 | } |
| 1302 | |
| 1303 | return true; |
| 1304 | } |
| 1305 | |
| 1306 | static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif) |
| 1307 | { |
| 1308 | struct ath10k *ar = arvif->ar; |
| 1309 | u32 vdev_param; |
| 1310 | |
| 1311 | lockdep_assert_held(&ar->conf_mutex); |
| 1312 | |
| 1313 | vdev_param = ar->wmi.vdev_param->protection_mode; |
| 1314 | |
| 1315 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n", |
| 1316 | arvif->vdev_id, arvif->use_cts_prot); |
| 1317 | |
| 1318 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 1319 | arvif->use_cts_prot ? 1 : 0); |
| 1320 | } |
| 1321 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1322 | static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif) |
| 1323 | { |
| 1324 | struct ath10k *ar = arvif->ar; |
| 1325 | u32 vdev_param, rts_cts = 0; |
| 1326 | |
| 1327 | lockdep_assert_held(&ar->conf_mutex); |
| 1328 | |
| 1329 | vdev_param = ar->wmi.vdev_param->enable_rtscts; |
| 1330 | |
Rajkumar Manoharan | 9a5ab0f | 2015-03-19 16:03:29 +0200 | [diff] [blame] | 1331 | rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1332 | |
| 1333 | if (arvif->num_legacy_stations > 0) |
| 1334 | rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES, |
| 1335 | WMI_RTSCTS_PROFILE); |
Rajkumar Manoharan | 9a5ab0f | 2015-03-19 16:03:29 +0200 | [diff] [blame] | 1336 | else |
| 1337 | rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES, |
| 1338 | WMI_RTSCTS_PROFILE); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1339 | |
Bartosz Markowski | 8617690 | 2016-12-15 11:23:24 +0200 | [diff] [blame] | 1340 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n", |
| 1341 | arvif->vdev_id, rts_cts); |
| 1342 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 1343 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 1344 | rts_cts); |
| 1345 | } |
| 1346 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1347 | static int ath10k_start_cac(struct ath10k *ar) |
| 1348 | { |
| 1349 | int ret; |
| 1350 | |
| 1351 | lockdep_assert_held(&ar->conf_mutex); |
| 1352 | |
| 1353 | set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 1354 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 1355 | ret = ath10k_monitor_recalc(ar); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1356 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1357 | ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1358 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 1359 | return ret; |
| 1360 | } |
| 1361 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1362 | 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] | 1363 | ar->monitor_vdev_id); |
| 1364 | |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | static int ath10k_stop_cac(struct ath10k *ar) |
| 1369 | { |
| 1370 | lockdep_assert_held(&ar->conf_mutex); |
| 1371 | |
| 1372 | /* CAC is not running - do nothing */ |
| 1373 | if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags)) |
| 1374 | return 0; |
| 1375 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1376 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 1377 | ath10k_monitor_stop(ar); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1378 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1379 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n"); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1380 | |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1384 | static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw, |
| 1385 | struct ieee80211_chanctx_conf *conf, |
| 1386 | void *data) |
| 1387 | { |
| 1388 | bool *ret = data; |
| 1389 | |
| 1390 | if (!*ret && conf->radar_enabled) |
| 1391 | *ret = true; |
| 1392 | } |
| 1393 | |
| 1394 | static bool ath10k_mac_has_radar_enabled(struct ath10k *ar) |
| 1395 | { |
| 1396 | bool has_radar = false; |
| 1397 | |
| 1398 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
| 1399 | ath10k_mac_has_radar_iter, |
| 1400 | &has_radar); |
| 1401 | |
| 1402 | return has_radar; |
| 1403 | } |
| 1404 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1405 | static void ath10k_recalc_radar_detection(struct ath10k *ar) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1406 | { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1407 | int ret; |
| 1408 | |
| 1409 | lockdep_assert_held(&ar->conf_mutex); |
| 1410 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1411 | ath10k_stop_cac(ar); |
| 1412 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1413 | if (!ath10k_mac_has_radar_enabled(ar)) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1414 | return; |
| 1415 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1416 | if (ar->num_started_vdevs > 0) |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1417 | return; |
| 1418 | |
| 1419 | ret = ath10k_start_cac(ar); |
| 1420 | if (ret) { |
| 1421 | /* |
| 1422 | * Not possible to start CAC on current channel so starting |
| 1423 | * radiation is not allowed, make this channel DFS_UNAVAILABLE |
| 1424 | * by indicating that radar was detected. |
| 1425 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1426 | ath10k_warn(ar, "failed to start CAC: %d\n", ret); |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 1427 | ieee80211_radar_detected(ar->hw); |
| 1428 | } |
| 1429 | } |
| 1430 | |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 1431 | static int ath10k_vdev_stop(struct ath10k_vif *arvif) |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1432 | { |
| 1433 | struct ath10k *ar = arvif->ar; |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 1434 | int ret; |
| 1435 | |
| 1436 | lockdep_assert_held(&ar->conf_mutex); |
| 1437 | |
| 1438 | reinit_completion(&ar->vdev_setup_done); |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 1439 | reinit_completion(&ar->vdev_delete_done); |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 1440 | |
| 1441 | ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id); |
| 1442 | if (ret) { |
| 1443 | ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n", |
| 1444 | arvif->vdev_id, ret); |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | ret = ath10k_vdev_setup_sync(ar); |
| 1449 | if (ret) { |
Colin Ian King | 23de579 | 2017-06-25 22:29:32 +0100 | [diff] [blame] | 1450 | ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n", |
Vasanthakumar Thiagarajan | 822b7e0 | 2015-03-02 17:45:27 +0530 | [diff] [blame] | 1451 | arvif->vdev_id, ret); |
| 1452 | return ret; |
| 1453 | } |
| 1454 | |
| 1455 | WARN_ON(ar->num_started_vdevs == 0); |
| 1456 | |
| 1457 | if (ar->num_started_vdevs != 0) { |
| 1458 | ar->num_started_vdevs--; |
| 1459 | ath10k_recalc_radar_detection(ar); |
| 1460 | } |
| 1461 | |
| 1462 | return ret; |
| 1463 | } |
| 1464 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1465 | static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, |
| 1466 | const struct cfg80211_chan_def *chandef, |
| 1467 | bool restart) |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1468 | { |
| 1469 | struct ath10k *ar = arvif->ar; |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1470 | struct wmi_vdev_start_request_arg arg = {}; |
| 1471 | int ret = 0; |
| 1472 | |
| 1473 | lockdep_assert_held(&ar->conf_mutex); |
| 1474 | |
| 1475 | reinit_completion(&ar->vdev_setup_done); |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 1476 | reinit_completion(&ar->vdev_delete_done); |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1477 | |
| 1478 | arg.vdev_id = arvif->vdev_id; |
| 1479 | arg.dtim_period = arvif->dtim_period; |
| 1480 | arg.bcn_intval = arvif->beacon_interval; |
| 1481 | |
| 1482 | arg.channel.freq = chandef->chan->center_freq; |
| 1483 | arg.channel.band_center_freq1 = chandef->center_freq1; |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 1484 | arg.channel.band_center_freq2 = chandef->center_freq2; |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1485 | arg.channel.mode = chan_to_phymode(chandef); |
| 1486 | |
| 1487 | arg.channel.min_power = 0; |
| 1488 | arg.channel.max_power = chandef->chan->max_power * 2; |
| 1489 | arg.channel.max_reg_power = chandef->chan->max_reg_power * 2; |
| 1490 | arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2; |
| 1491 | |
| 1492 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
| 1493 | arg.ssid = arvif->u.ap.ssid; |
| 1494 | arg.ssid_len = arvif->u.ap.ssid_len; |
| 1495 | arg.hidden_ssid = arvif->u.ap.hidden_ssid; |
| 1496 | |
| 1497 | /* For now allow DFS for AP mode */ |
| 1498 | arg.channel.chan_radar = |
| 1499 | !!(chandef->chan->flags & IEEE80211_CHAN_RADAR); |
| 1500 | } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
| 1501 | arg.ssid = arvif->vif->bss_conf.ssid; |
| 1502 | arg.ssid_len = arvif->vif->bss_conf.ssid_len; |
| 1503 | } |
| 1504 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1505 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1506 | "mac vdev %d start center_freq %d phymode %s\n", |
| 1507 | arg.vdev_id, arg.channel.freq, |
| 1508 | ath10k_wmi_phymode_str(arg.channel.mode)); |
| 1509 | |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1510 | if (restart) |
| 1511 | ret = ath10k_wmi_vdev_restart(ar, &arg); |
| 1512 | else |
| 1513 | ret = ath10k_wmi_vdev_start(ar, &arg); |
| 1514 | |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1515 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1516 | ath10k_warn(ar, "failed to start WMI vdev %i: %d\n", |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1517 | arg.vdev_id, ret); |
| 1518 | return ret; |
| 1519 | } |
| 1520 | |
| 1521 | ret = ath10k_vdev_setup_sync(ar); |
| 1522 | if (ret) { |
Ben Greear | 60028a8 | 2015-02-15 16:50:39 +0200 | [diff] [blame] | 1523 | ath10k_warn(ar, |
| 1524 | "failed to synchronize setup for vdev %i restart %d: %d\n", |
| 1525 | arg.vdev_id, restart, ret); |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1526 | return ret; |
| 1527 | } |
| 1528 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1529 | ar->num_started_vdevs++; |
| 1530 | ath10k_recalc_radar_detection(ar); |
| 1531 | |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1532 | return ret; |
| 1533 | } |
| 1534 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1535 | static int ath10k_vdev_start(struct ath10k_vif *arvif, |
| 1536 | const struct cfg80211_chan_def *def) |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1537 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1538 | return ath10k_vdev_start_restart(arvif, def, false); |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1539 | } |
| 1540 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1541 | static int ath10k_vdev_restart(struct ath10k_vif *arvif, |
| 1542 | const struct cfg80211_chan_def *def) |
Michal Kazior | dc55e30 | 2014-07-29 12:53:36 +0300 | [diff] [blame] | 1543 | { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1544 | return ath10k_vdev_start_restart(arvif, def, true); |
Michal Kazior | 72654fa | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 1545 | } |
| 1546 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1547 | static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif, |
| 1548 | struct sk_buff *bcn) |
| 1549 | { |
| 1550 | struct ath10k *ar = arvif->ar; |
| 1551 | struct ieee80211_mgmt *mgmt; |
| 1552 | const u8 *p2p_ie; |
| 1553 | int ret; |
| 1554 | |
Peter Oh | 08c27be | 2016-01-28 13:54:09 -0800 | [diff] [blame] | 1555 | if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p) |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1556 | return 0; |
| 1557 | |
| 1558 | mgmt = (void *)bcn->data; |
| 1559 | p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1560 | mgmt->u.beacon.variable, |
| 1561 | bcn->len - (mgmt->u.beacon.variable - |
| 1562 | bcn->data)); |
| 1563 | if (!p2p_ie) |
| 1564 | return -ENOENT; |
| 1565 | |
| 1566 | ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie); |
| 1567 | if (ret) { |
| 1568 | ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n", |
| 1569 | arvif->vdev_id, ret); |
| 1570 | return ret; |
| 1571 | } |
| 1572 | |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
| 1576 | static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui, |
| 1577 | u8 oui_type, size_t ie_offset) |
| 1578 | { |
| 1579 | size_t len; |
| 1580 | const u8 *next; |
| 1581 | const u8 *end; |
| 1582 | u8 *ie; |
| 1583 | |
| 1584 | if (WARN_ON(skb->len < ie_offset)) |
| 1585 | return -EINVAL; |
| 1586 | |
| 1587 | ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type, |
| 1588 | skb->data + ie_offset, |
| 1589 | skb->len - ie_offset); |
| 1590 | if (!ie) |
| 1591 | return -ENOENT; |
| 1592 | |
| 1593 | len = ie[1] + 2; |
| 1594 | end = skb->data + skb->len; |
| 1595 | next = ie + len; |
| 1596 | |
| 1597 | if (WARN_ON(next > end)) |
| 1598 | return -EINVAL; |
| 1599 | |
| 1600 | memmove(ie, next, end - next); |
| 1601 | skb_trim(skb, skb->len - len); |
| 1602 | |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
| 1606 | static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif) |
| 1607 | { |
| 1608 | struct ath10k *ar = arvif->ar; |
| 1609 | struct ieee80211_hw *hw = ar->hw; |
| 1610 | struct ieee80211_vif *vif = arvif->vif; |
| 1611 | struct ieee80211_mutable_offsets offs = {}; |
| 1612 | struct sk_buff *bcn; |
| 1613 | int ret; |
| 1614 | |
| 1615 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1616 | return 0; |
| 1617 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1618 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 1619 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
| 1620 | return 0; |
| 1621 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1622 | bcn = ieee80211_beacon_get_template(hw, vif, &offs); |
| 1623 | if (!bcn) { |
| 1624 | ath10k_warn(ar, "failed to get beacon template from mac80211\n"); |
| 1625 | return -EPERM; |
| 1626 | } |
| 1627 | |
| 1628 | ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn); |
| 1629 | if (ret) { |
| 1630 | ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret); |
| 1631 | kfree_skb(bcn); |
| 1632 | return ret; |
| 1633 | } |
| 1634 | |
| 1635 | /* P2P IE is inserted by firmware automatically (as configured above) |
| 1636 | * so remove it from the base beacon template to avoid duplicate P2P |
| 1637 | * IEs in beacon frames. |
| 1638 | */ |
| 1639 | ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P, |
| 1640 | offsetof(struct ieee80211_mgmt, |
| 1641 | u.beacon.variable)); |
| 1642 | |
| 1643 | ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0, |
| 1644 | 0, NULL, 0); |
| 1645 | kfree_skb(bcn); |
| 1646 | |
| 1647 | if (ret) { |
| 1648 | ath10k_warn(ar, "failed to submit beacon template command: %d\n", |
| 1649 | ret); |
| 1650 | return ret; |
| 1651 | } |
| 1652 | |
| 1653 | return 0; |
| 1654 | } |
| 1655 | |
| 1656 | static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif) |
| 1657 | { |
| 1658 | struct ath10k *ar = arvif->ar; |
| 1659 | struct ieee80211_hw *hw = ar->hw; |
| 1660 | struct ieee80211_vif *vif = arvif->vif; |
| 1661 | struct sk_buff *prb; |
| 1662 | int ret; |
| 1663 | |
| 1664 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1665 | return 0; |
| 1666 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 1667 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 1668 | return 0; |
| 1669 | |
Surabhi Vishnoi | 97354f2c | 2019-04-17 14:01:46 +0530 | [diff] [blame] | 1670 | /* For mesh, probe response and beacon share the same template */ |
| 1671 | if (ieee80211_vif_is_mesh(vif)) |
| 1672 | return 0; |
| 1673 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 1674 | prb = ieee80211_proberesp_get(hw, vif); |
| 1675 | if (!prb) { |
| 1676 | ath10k_warn(ar, "failed to get probe resp template from mac80211\n"); |
| 1677 | return -EPERM; |
| 1678 | } |
| 1679 | |
| 1680 | ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb); |
| 1681 | kfree_skb(prb); |
| 1682 | |
| 1683 | if (ret) { |
| 1684 | ath10k_warn(ar, "failed to submit probe resp template command: %d\n", |
| 1685 | ret); |
| 1686 | return ret; |
| 1687 | } |
| 1688 | |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1692 | static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif) |
| 1693 | { |
| 1694 | struct ath10k *ar = arvif->ar; |
| 1695 | struct cfg80211_chan_def def; |
| 1696 | int ret; |
| 1697 | |
| 1698 | /* When originally vdev is started during assign_vif_chanctx() some |
| 1699 | * information is missing, notably SSID. Firmware revisions with beacon |
| 1700 | * offloading require the SSID to be provided during vdev (re)start to |
| 1701 | * handle hidden SSID properly. |
| 1702 | * |
| 1703 | * Vdev restart must be done after vdev has been both started and |
| 1704 | * upped. Otherwise some firmware revisions (at least 10.2) fail to |
| 1705 | * deliver vdev restart response event causing timeouts during vdev |
| 1706 | * syncing in ath10k. |
| 1707 | * |
| 1708 | * Note: The vdev down/up and template reinstallation could be skipped |
| 1709 | * since only wmi-tlv firmware are known to have beacon offload and |
| 1710 | * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart |
| 1711 | * response delivery. It's probably more robust to keep it as is. |
| 1712 | */ |
| 1713 | if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) |
| 1714 | return 0; |
| 1715 | |
| 1716 | if (WARN_ON(!arvif->is_started)) |
| 1717 | return -EINVAL; |
| 1718 | |
| 1719 | if (WARN_ON(!arvif->is_up)) |
| 1720 | return -EINVAL; |
| 1721 | |
| 1722 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) |
| 1723 | return -EINVAL; |
| 1724 | |
| 1725 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 1726 | if (ret) { |
| 1727 | ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n", |
| 1728 | arvif->vdev_id, ret); |
| 1729 | return ret; |
| 1730 | } |
| 1731 | |
| 1732 | /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise |
| 1733 | * firmware will crash upon vdev up. |
| 1734 | */ |
| 1735 | |
| 1736 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 1737 | if (ret) { |
| 1738 | ath10k_warn(ar, "failed to update beacon template: %d\n", ret); |
| 1739 | return ret; |
| 1740 | } |
| 1741 | |
| 1742 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 1743 | if (ret) { |
| 1744 | ath10k_warn(ar, "failed to update presp template: %d\n", ret); |
| 1745 | return ret; |
| 1746 | } |
| 1747 | |
| 1748 | ret = ath10k_vdev_restart(arvif, &def); |
| 1749 | if (ret) { |
| 1750 | ath10k_warn(ar, "failed to restart ap vdev %i: %d\n", |
| 1751 | arvif->vdev_id, ret); |
| 1752 | return ret; |
| 1753 | } |
| 1754 | |
| 1755 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 1756 | arvif->bssid); |
| 1757 | if (ret) { |
| 1758 | ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n", |
| 1759 | arvif->vdev_id, ret); |
| 1760 | return ret; |
| 1761 | } |
| 1762 | |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1766 | static void ath10k_control_beaconing(struct ath10k_vif *arvif, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1767 | struct ieee80211_bss_conf *info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1768 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1769 | struct ath10k *ar = arvif->ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1770 | int ret = 0; |
| 1771 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1772 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1773 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1774 | if (!info->enable_beacon) { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1775 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 1776 | if (ret) |
| 1777 | ath10k_warn(ar, "failed to down vdev_id %i: %d\n", |
| 1778 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1779 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1780 | arvif->is_up = false; |
| 1781 | |
Michal Kazior | 748afc4 | 2014-01-23 12:48:21 +0100 | [diff] [blame] | 1782 | spin_lock_bh(&arvif->ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 1783 | ath10k_mac_vif_beacon_free(arvif); |
Michal Kazior | 748afc4 | 2014-01-23 12:48:21 +0100 | [diff] [blame] | 1784 | spin_unlock_bh(&arvif->ar->data_lock); |
| 1785 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1786 | return; |
| 1787 | } |
| 1788 | |
| 1789 | arvif->tx_seq_no = 0x1000; |
| 1790 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1791 | arvif->aid = 0; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 1792 | ether_addr_copy(arvif->bssid, info->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1793 | |
| 1794 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 1795 | arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1796 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1797 | ath10k_warn(ar, "failed to bring up vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 1798 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1799 | return; |
| 1800 | } |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1801 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1802 | arvif->is_up = true; |
| 1803 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 1804 | ret = ath10k_mac_vif_fix_hidden_ssid(arvif); |
| 1805 | if (ret) { |
| 1806 | ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n", |
| 1807 | arvif->vdev_id, ret); |
| 1808 | return; |
| 1809 | } |
| 1810 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1811 | 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] | 1812 | } |
| 1813 | |
| 1814 | static void ath10k_control_ibss(struct ath10k_vif *arvif, |
| 1815 | struct ieee80211_bss_conf *info, |
| 1816 | const u8 self_peer[ETH_ALEN]) |
| 1817 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1818 | struct ath10k *ar = arvif->ar; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 1819 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1820 | int ret = 0; |
| 1821 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1822 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1823 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1824 | if (!info->ibss_joined) { |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 1825 | if (is_zero_ether_addr(arvif->bssid)) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1826 | return; |
| 1827 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1828 | eth_zero_addr(arvif->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1829 | |
| 1830 | return; |
| 1831 | } |
| 1832 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 1833 | vdev_param = arvif->ar->wmi.vdev_param->atim_window; |
| 1834 | 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] | 1835 | ATH10K_DEFAULT_ATIM); |
| 1836 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1837 | 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] | 1838 | arvif->vdev_id, ret); |
| 1839 | } |
| 1840 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 1841 | static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif) |
| 1842 | { |
| 1843 | struct ath10k *ar = arvif->ar; |
| 1844 | u32 param; |
| 1845 | u32 value; |
| 1846 | int ret; |
| 1847 | |
| 1848 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1849 | |
| 1850 | if (arvif->u.sta.uapsd) |
| 1851 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER; |
| 1852 | else |
| 1853 | value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS; |
| 1854 | |
| 1855 | param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD; |
| 1856 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value); |
| 1857 | if (ret) { |
| 1858 | ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n", |
| 1859 | value, arvif->vdev_id, ret); |
| 1860 | return ret; |
| 1861 | } |
| 1862 | |
| 1863 | return 0; |
| 1864 | } |
| 1865 | |
| 1866 | static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif) |
| 1867 | { |
| 1868 | struct ath10k *ar = arvif->ar; |
| 1869 | u32 param; |
| 1870 | u32 value; |
| 1871 | int ret; |
| 1872 | |
| 1873 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1874 | |
| 1875 | if (arvif->u.sta.uapsd) |
| 1876 | value = WMI_STA_PS_PSPOLL_COUNT_UAPSD; |
| 1877 | else |
| 1878 | value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX; |
| 1879 | |
| 1880 | param = WMI_STA_PS_PARAM_PSPOLL_COUNT; |
| 1881 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 1882 | param, value); |
| 1883 | if (ret) { |
| 1884 | ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n", |
| 1885 | value, arvif->vdev_id, ret); |
| 1886 | return ret; |
| 1887 | } |
| 1888 | |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
Michal Kazior | 424f263 | 2015-07-09 13:08:35 +0200 | [diff] [blame] | 1892 | static int ath10k_mac_num_vifs_started(struct ath10k *ar) |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1893 | { |
| 1894 | struct ath10k_vif *arvif; |
| 1895 | int num = 0; |
| 1896 | |
| 1897 | lockdep_assert_held(&ar->conf_mutex); |
| 1898 | |
| 1899 | list_for_each_entry(arvif, &ar->arvifs, list) |
Michal Kazior | 424f263 | 2015-07-09 13:08:35 +0200 | [diff] [blame] | 1900 | if (arvif->is_started) |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1901 | num++; |
| 1902 | |
| 1903 | return num; |
| 1904 | } |
| 1905 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1906 | static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1907 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1908 | struct ath10k *ar = arvif->ar; |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1909 | struct ieee80211_vif *vif = arvif->vif; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1910 | struct ieee80211_conf *conf = &ar->hw->conf; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1911 | enum wmi_sta_powersave_param param; |
| 1912 | enum wmi_sta_ps_mode psmode; |
| 1913 | int ret; |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1914 | int ps_timeout; |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1915 | bool enable_ps; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1916 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 1917 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1918 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1919 | if (arvif->vif->type != NL80211_IFTYPE_STATION) |
| 1920 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1921 | |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1922 | enable_ps = arvif->ps; |
| 1923 | |
Michal Kazior | 424f263 | 2015-07-09 13:08:35 +0200 | [diff] [blame] | 1924 | if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 && |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1925 | !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT, |
Kalle Valo | c4cdf75 | 2016-04-20 19:45:18 +0300 | [diff] [blame] | 1926 | ar->running_fw->fw_file.fw_features)) { |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 1927 | ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n", |
| 1928 | arvif->vdev_id); |
| 1929 | enable_ps = false; |
| 1930 | } |
| 1931 | |
Janusz Dziedzic | 917826b | 2015-05-18 09:38:17 +0000 | [diff] [blame] | 1932 | if (!arvif->is_started) { |
| 1933 | /* mac80211 can update vif powersave state while disconnected. |
| 1934 | * Firmware doesn't behave nicely and consumes more power than |
| 1935 | * necessary if PS is disabled on a non-started vdev. Hence |
| 1936 | * force-enable PS for non-running vdevs. |
| 1937 | */ |
| 1938 | psmode = WMI_STA_PS_MODE_ENABLED; |
| 1939 | } else if (enable_ps) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1940 | psmode = WMI_STA_PS_MODE_ENABLED; |
| 1941 | param = WMI_STA_PS_PARAM_INACTIVITY_TIME; |
| 1942 | |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1943 | ps_timeout = conf->dynamic_ps_timeout; |
| 1944 | if (ps_timeout == 0) { |
| 1945 | /* Firmware doesn't like 0 */ |
| 1946 | ps_timeout = ieee80211_tu_to_usec( |
| 1947 | vif->bss_conf.beacon_int) / 1000; |
| 1948 | } |
| 1949 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1950 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, |
Michal Kazior | 526549a | 2014-12-12 12:41:37 +0100 | [diff] [blame] | 1951 | ps_timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1952 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1953 | 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] | 1954 | arvif->vdev_id, ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1955 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1956 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1957 | } else { |
| 1958 | psmode = WMI_STA_PS_MODE_DISABLED; |
| 1959 | } |
| 1960 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1961 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 1962 | arvif->vdev_id, psmode ? "enable" : "disable"); |
| 1963 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1964 | ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode); |
| 1965 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1966 | 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] | 1967 | psmode, arvif->vdev_id, ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 1968 | return ret; |
| 1969 | } |
| 1970 | |
| 1971 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1972 | } |
| 1973 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 1974 | static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif) |
| 1975 | { |
| 1976 | struct ath10k *ar = arvif->ar; |
| 1977 | struct wmi_sta_keepalive_arg arg = {}; |
| 1978 | int ret; |
| 1979 | |
| 1980 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 1981 | |
| 1982 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 1983 | return 0; |
| 1984 | |
| 1985 | if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map)) |
| 1986 | return 0; |
| 1987 | |
| 1988 | /* Some firmware revisions have a bug and ignore the `enabled` field. |
| 1989 | * Instead use the interval to disable the keepalive. |
| 1990 | */ |
| 1991 | arg.vdev_id = arvif->vdev_id; |
| 1992 | arg.enabled = 1; |
| 1993 | arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME; |
| 1994 | arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE; |
| 1995 | |
| 1996 | ret = ath10k_wmi_sta_keepalive(ar, &arg); |
| 1997 | if (ret) { |
| 1998 | ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n", |
| 1999 | arvif->vdev_id, ret); |
| 2000 | return ret; |
| 2001 | } |
| 2002 | |
| 2003 | return 0; |
| 2004 | } |
| 2005 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 2006 | static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif) |
| 2007 | { |
| 2008 | struct ath10k *ar = arvif->ar; |
| 2009 | struct ieee80211_vif *vif = arvif->vif; |
| 2010 | int ret; |
| 2011 | |
Michal Kazior | 8513d95 | 2015-03-09 14:19:24 +0100 | [diff] [blame] | 2012 | lockdep_assert_held(&arvif->ar->conf_mutex); |
| 2013 | |
| 2014 | if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))) |
| 2015 | return; |
| 2016 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 2017 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP) |
| 2018 | return; |
| 2019 | |
| 2020 | if (!vif->csa_active) |
| 2021 | return; |
| 2022 | |
| 2023 | if (!arvif->is_up) |
| 2024 | return; |
| 2025 | |
| 2026 | if (!ieee80211_csa_is_complete(vif)) { |
| 2027 | ieee80211_csa_update_counter(vif); |
| 2028 | |
| 2029 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 2030 | if (ret) |
| 2031 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 2032 | ret); |
| 2033 | |
| 2034 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 2035 | if (ret) |
| 2036 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 2037 | ret); |
| 2038 | } else { |
| 2039 | ieee80211_csa_finish(vif); |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | static void ath10k_mac_vif_ap_csa_work(struct work_struct *work) |
| 2044 | { |
| 2045 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 2046 | ap_csa_work); |
| 2047 | struct ath10k *ar = arvif->ar; |
| 2048 | |
| 2049 | mutex_lock(&ar->conf_mutex); |
| 2050 | ath10k_mac_vif_ap_csa_count_down(arvif); |
| 2051 | mutex_unlock(&ar->conf_mutex); |
| 2052 | } |
| 2053 | |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 2054 | static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac, |
| 2055 | struct ieee80211_vif *vif) |
| 2056 | { |
| 2057 | struct sk_buff *skb = data; |
| 2058 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2059 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 2060 | |
| 2061 | if (vif->type != NL80211_IFTYPE_STATION) |
| 2062 | return; |
| 2063 | |
| 2064 | if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid)) |
| 2065 | return; |
| 2066 | |
| 2067 | cancel_delayed_work(&arvif->connection_loss_work); |
| 2068 | } |
| 2069 | |
| 2070 | void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb) |
| 2071 | { |
| 2072 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 2073 | IEEE80211_IFACE_ITER_NORMAL, |
| 2074 | ath10k_mac_handle_beacon_iter, |
| 2075 | skb); |
| 2076 | } |
| 2077 | |
| 2078 | static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac, |
| 2079 | struct ieee80211_vif *vif) |
| 2080 | { |
| 2081 | u32 *vdev_id = data; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2082 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 2083 | struct ath10k *ar = arvif->ar; |
| 2084 | struct ieee80211_hw *hw = ar->hw; |
| 2085 | |
| 2086 | if (arvif->vdev_id != *vdev_id) |
| 2087 | return; |
| 2088 | |
| 2089 | if (!arvif->is_up) |
| 2090 | return; |
| 2091 | |
| 2092 | ieee80211_beacon_loss(vif); |
| 2093 | |
| 2094 | /* Firmware doesn't report beacon loss events repeatedly. If AP probe |
| 2095 | * (done by mac80211) succeeds but beacons do not resume then it |
| 2096 | * doesn't make sense to continue operation. Queue connection loss work |
| 2097 | * which can be cancelled when beacon is received. |
| 2098 | */ |
| 2099 | ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work, |
| 2100 | ATH10K_CONNECTION_LOSS_HZ); |
| 2101 | } |
| 2102 | |
| 2103 | void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id) |
| 2104 | { |
| 2105 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 2106 | IEEE80211_IFACE_ITER_NORMAL, |
| 2107 | ath10k_mac_handle_beacon_miss_iter, |
| 2108 | &vdev_id); |
| 2109 | } |
| 2110 | |
| 2111 | static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work) |
| 2112 | { |
| 2113 | struct ath10k_vif *arvif = container_of(work, struct ath10k_vif, |
| 2114 | connection_loss_work.work); |
| 2115 | struct ieee80211_vif *vif = arvif->vif; |
| 2116 | |
| 2117 | if (!arvif->is_up) |
| 2118 | return; |
| 2119 | |
| 2120 | ieee80211_connection_loss(vif); |
| 2121 | } |
| 2122 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2123 | /**********************/ |
| 2124 | /* Station management */ |
| 2125 | /**********************/ |
| 2126 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2127 | static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar, |
| 2128 | struct ieee80211_vif *vif) |
| 2129 | { |
| 2130 | /* Some firmware revisions have unstable STA powersave when listen |
| 2131 | * interval is set too high (e.g. 5). The symptoms are firmware doesn't |
| 2132 | * generate NullFunc frames properly even if buffered frames have been |
| 2133 | * indicated in Beacon TIM. Firmware would seldom wake up to pull |
| 2134 | * buffered frames. Often pinging the device from AP would simply fail. |
| 2135 | * |
| 2136 | * As a workaround set it to 1. |
| 2137 | */ |
| 2138 | if (vif->type == NL80211_IFTYPE_STATION) |
| 2139 | return 1; |
| 2140 | |
| 2141 | return ar->hw->conf.listen_interval; |
| 2142 | } |
| 2143 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2144 | static void ath10k_peer_assoc_h_basic(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2145 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2146 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2147 | struct wmi_peer_assoc_complete_arg *arg) |
| 2148 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2149 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | c51880e | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2150 | u32 aid; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2151 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2152 | lockdep_assert_held(&ar->conf_mutex); |
| 2153 | |
Michal Kazior | c51880e | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2154 | if (vif->type == NL80211_IFTYPE_STATION) |
| 2155 | aid = vif->bss_conf.aid; |
| 2156 | else |
| 2157 | aid = sta->aid; |
| 2158 | |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 2159 | ether_addr_copy(arg->addr, sta->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2160 | arg->vdev_id = arvif->vdev_id; |
Michal Kazior | c51880e | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2161 | arg->peer_aid = aid; |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2162 | arg->peer_flags |= arvif->ar->wmi.peer_flags->auth; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2163 | arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2164 | arg->peer_num_spatial_streams = 1; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2165 | arg->peer_caps = vif->bss_conf.assoc_capability; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | static void ath10k_peer_assoc_h_crypto(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2169 | struct ieee80211_vif *vif, |
Tamizh chelvam | 90eceb3 | 2015-10-29 14:27:42 +0200 | [diff] [blame] | 2170 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2171 | struct wmi_peer_assoc_complete_arg *arg) |
| 2172 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2173 | struct ieee80211_bss_conf *info = &vif->bss_conf; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2174 | struct cfg80211_chan_def def; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2175 | struct cfg80211_bss *bss; |
| 2176 | const u8 *rsnie = NULL; |
| 2177 | const u8 *wpaie = NULL; |
| 2178 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2179 | lockdep_assert_held(&ar->conf_mutex); |
| 2180 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2181 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2182 | return; |
| 2183 | |
| 2184 | bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0, |
| 2185 | IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2186 | if (bss) { |
| 2187 | const struct cfg80211_bss_ies *ies; |
| 2188 | |
| 2189 | rcu_read_lock(); |
| 2190 | rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN); |
| 2191 | |
| 2192 | ies = rcu_dereference(bss->ies); |
| 2193 | |
| 2194 | wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 2195 | WLAN_OUI_TYPE_MICROSOFT_WPA, |
| 2196 | ies->data, |
| 2197 | ies->len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2198 | rcu_read_unlock(); |
| 2199 | cfg80211_put_bss(ar->hw->wiphy, bss); |
| 2200 | } |
| 2201 | |
| 2202 | /* FIXME: base on RSN IE/WPA IE is a correct idea? */ |
| 2203 | if (rsnie || wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2204 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__); |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2205 | arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | if (wpaie) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2209 | ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__); |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2210 | arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2211 | } |
Tamizh chelvam | 90eceb3 | 2015-10-29 14:27:42 +0200 | [diff] [blame] | 2212 | |
| 2213 | if (sta->mfp && |
Kalle Valo | c4cdf75 | 2016-04-20 19:45:18 +0300 | [diff] [blame] | 2214 | test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT, |
| 2215 | ar->running_fw->fw_file.fw_features)) { |
Tamizh chelvam | 90eceb3 | 2015-10-29 14:27:42 +0200 | [diff] [blame] | 2216 | arg->peer_flags |= ar->wmi.peer_flags->pmf; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | static void ath10k_peer_assoc_h_rates(struct ath10k *ar, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2221 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2222 | struct ieee80211_sta *sta, |
| 2223 | struct wmi_peer_assoc_complete_arg *arg) |
| 2224 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2225 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2226 | struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2227 | struct cfg80211_chan_def def; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2228 | const struct ieee80211_supported_band *sband; |
| 2229 | const struct ieee80211_rate *rates; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2230 | enum nl80211_band band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2231 | u32 ratemask; |
Michal Kazior | 486017c | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 2232 | u8 rate; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2233 | int i; |
| 2234 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2235 | lockdep_assert_held(&ar->conf_mutex); |
| 2236 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2237 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2238 | return; |
| 2239 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2240 | band = def.chan->band; |
| 2241 | sband = ar->hw->wiphy->bands[band]; |
| 2242 | ratemask = sta->supp_rates[band]; |
| 2243 | ratemask &= arvif->bitrate_mask.control[band].legacy; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2244 | rates = sband->bitrates; |
| 2245 | |
| 2246 | rateset->num_rates = 0; |
| 2247 | |
| 2248 | for (i = 0; i < 32; i++, ratemask >>= 1, rates++) { |
| 2249 | if (!(ratemask & 1)) |
| 2250 | continue; |
| 2251 | |
Michal Kazior | 486017c | 2015-03-30 09:51:54 +0300 | [diff] [blame] | 2252 | rate = ath10k_mac_bitrate_to_rate(rates->bitrate); |
| 2253 | rateset->rates[rateset->num_rates] = rate; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2254 | rateset->num_rates++; |
| 2255 | } |
| 2256 | } |
| 2257 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2258 | static bool |
| 2259 | ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN]) |
| 2260 | { |
| 2261 | int nss; |
| 2262 | |
| 2263 | for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++) |
| 2264 | if (ht_mcs_mask[nss]) |
| 2265 | return false; |
| 2266 | |
| 2267 | return true; |
| 2268 | } |
| 2269 | |
| 2270 | static bool |
| 2271 | ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 2272 | { |
| 2273 | int nss; |
| 2274 | |
| 2275 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) |
| 2276 | if (vht_mcs_mask[nss]) |
| 2277 | return false; |
| 2278 | |
| 2279 | return true; |
| 2280 | } |
| 2281 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2282 | static void ath10k_peer_assoc_h_ht(struct ath10k *ar, |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2283 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2284 | struct ieee80211_sta *sta, |
| 2285 | struct wmi_peer_assoc_complete_arg *arg) |
| 2286 | { |
| 2287 | const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2288 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2289 | struct cfg80211_chan_def def; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2290 | enum nl80211_band band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2291 | const u8 *ht_mcs_mask; |
| 2292 | const u16 *vht_mcs_mask; |
Vivek Natarajan | 72f8cef | 2015-10-06 15:19:34 +0300 | [diff] [blame] | 2293 | int i, n; |
| 2294 | u8 max_nss; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 2295 | u32 stbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2296 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2297 | lockdep_assert_held(&ar->conf_mutex); |
| 2298 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2299 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2300 | return; |
| 2301 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2302 | if (!ht_cap->ht_supported) |
| 2303 | return; |
| 2304 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2305 | band = def.chan->band; |
| 2306 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 2307 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2308 | |
| 2309 | if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) && |
| 2310 | ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) |
| 2311 | return; |
| 2312 | |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2313 | arg->peer_flags |= ar->wmi.peer_flags->ht; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2314 | arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 2315 | ht_cap->ampdu_factor)) - 1; |
| 2316 | |
| 2317 | arg->peer_mpdu_density = |
| 2318 | ath10k_parse_mpdudensity(ht_cap->ampdu_density); |
| 2319 | |
| 2320 | arg->peer_ht_caps = ht_cap->cap; |
| 2321 | arg->peer_rate_caps |= WMI_RC_HT_FLAG; |
| 2322 | |
| 2323 | if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING) |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2324 | arg->peer_flags |= ar->wmi.peer_flags->ldbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2325 | |
| 2326 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) { |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2327 | arg->peer_flags |= ar->wmi.peer_flags->bw40; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2328 | arg->peer_rate_caps |= WMI_RC_CW40_FLAG; |
| 2329 | } |
| 2330 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2331 | if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) { |
| 2332 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20) |
| 2333 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2334 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2335 | if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40) |
| 2336 | arg->peer_rate_caps |= WMI_RC_SGI_FLAG; |
| 2337 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2338 | |
| 2339 | if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) { |
| 2340 | arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG; |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2341 | arg->peer_flags |= ar->wmi.peer_flags->stbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2345 | stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC; |
| 2346 | stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 2347 | stbc = stbc << WMI_RC_RX_STBC_FLAG_S; |
| 2348 | arg->peer_rate_caps |= stbc; |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2349 | arg->peer_flags |= ar->wmi.peer_flags->stbc; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2350 | } |
| 2351 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2352 | if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2]) |
| 2353 | arg->peer_rate_caps |= WMI_RC_TS_FLAG; |
| 2354 | else if (ht_cap->mcs.rx_mask[1]) |
| 2355 | arg->peer_rate_caps |= WMI_RC_DS_FLAG; |
| 2356 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2357 | for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++) |
| 2358 | if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) && |
| 2359 | (ht_mcs_mask[i / 8] & BIT(i % 8))) { |
| 2360 | max_nss = (i / 8) + 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2361 | arg->peer_ht_rates.rates[n++] = i; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2362 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2363 | |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 2364 | /* |
| 2365 | * This is a workaround for HT-enabled STAs which break the spec |
| 2366 | * and have no HT capabilities RX mask (no HT RX MCS map). |
| 2367 | * |
| 2368 | * As per spec, in section 20.3.5 Modulation and coding scheme (MCS), |
| 2369 | * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs. |
| 2370 | * |
| 2371 | * Firmware asserts if such situation occurs. |
| 2372 | */ |
| 2373 | if (n == 0) { |
| 2374 | arg->peer_ht_rates.num_rates = 8; |
| 2375 | for (i = 0; i < arg->peer_ht_rates.num_rates; i++) |
| 2376 | arg->peer_ht_rates.rates[i] = i; |
| 2377 | } else { |
| 2378 | arg->peer_ht_rates.num_rates = n; |
Vivek Natarajan | 72f8cef | 2015-10-06 15:19:34 +0300 | [diff] [blame] | 2379 | arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss); |
Bartosz Markowski | fd71f80 | 2014-02-10 13:12:55 +0100 | [diff] [blame] | 2380 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2381 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2382 | 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] | 2383 | arg->addr, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2384 | arg->peer_ht_rates.num_rates, |
| 2385 | arg->peer_num_spatial_streams); |
| 2386 | } |
| 2387 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2388 | static int ath10k_peer_assoc_qos_ap(struct ath10k *ar, |
| 2389 | struct ath10k_vif *arvif, |
| 2390 | struct ieee80211_sta *sta) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2391 | { |
| 2392 | u32 uapsd = 0; |
| 2393 | u32 max_sp = 0; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2394 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2395 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2396 | lockdep_assert_held(&ar->conf_mutex); |
| 2397 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2398 | if (sta->wme && sta->uapsd_queues) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2399 | 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] | 2400 | sta->uapsd_queues, sta->max_sp); |
| 2401 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2402 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 2403 | uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN | |
| 2404 | WMI_AP_PS_UAPSD_AC3_TRIGGER_EN; |
| 2405 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 2406 | uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN | |
| 2407 | WMI_AP_PS_UAPSD_AC2_TRIGGER_EN; |
| 2408 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 2409 | uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN | |
| 2410 | WMI_AP_PS_UAPSD_AC1_TRIGGER_EN; |
| 2411 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 2412 | uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN | |
| 2413 | WMI_AP_PS_UAPSD_AC0_TRIGGER_EN; |
| 2414 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2415 | if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP) |
| 2416 | max_sp = sta->max_sp; |
| 2417 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2418 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 2419 | sta->addr, |
| 2420 | WMI_AP_PS_PEER_PARAM_UAPSD, |
| 2421 | uapsd); |
| 2422 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2423 | 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] | 2424 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2425 | return ret; |
| 2426 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2427 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2428 | ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, |
| 2429 | sta->addr, |
| 2430 | WMI_AP_PS_PEER_PARAM_MAX_SP, |
| 2431 | max_sp); |
| 2432 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2433 | 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] | 2434 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2435 | return ret; |
| 2436 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2437 | |
| 2438 | /* TODO setup this based on STA listen interval and |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 2439 | * beacon interval. Currently we don't know |
| 2440 | * sta->listen_interval - mac80211 patch required. |
| 2441 | * Currently use 10 seconds |
| 2442 | */ |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2443 | 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] | 2444 | WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, |
| 2445 | 10); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2446 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2447 | 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] | 2448 | arvif->vdev_id, ret); |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2449 | return ret; |
| 2450 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2451 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2452 | |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2453 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2454 | } |
| 2455 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2456 | static u16 |
| 2457 | ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set, |
| 2458 | const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX]) |
| 2459 | { |
| 2460 | int idx_limit; |
| 2461 | int nss; |
| 2462 | u16 mcs_map; |
| 2463 | u16 mcs; |
| 2464 | |
| 2465 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 2466 | mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) & |
| 2467 | vht_mcs_limit[nss]; |
| 2468 | |
| 2469 | if (mcs_map) |
| 2470 | idx_limit = fls(mcs_map) - 1; |
| 2471 | else |
| 2472 | idx_limit = -1; |
| 2473 | |
| 2474 | switch (idx_limit) { |
| 2475 | case 0: /* fall through */ |
| 2476 | case 1: /* fall through */ |
| 2477 | case 2: /* fall through */ |
| 2478 | case 3: /* fall through */ |
| 2479 | case 4: /* fall through */ |
| 2480 | case 5: /* fall through */ |
| 2481 | case 6: /* fall through */ |
| 2482 | default: |
| 2483 | /* see ath10k_mac_can_set_bitrate_mask() */ |
| 2484 | WARN_ON(1); |
| 2485 | /* fall through */ |
| 2486 | case -1: |
| 2487 | mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED; |
| 2488 | break; |
| 2489 | case 7: |
| 2490 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_7; |
| 2491 | break; |
| 2492 | case 8: |
| 2493 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_8; |
| 2494 | break; |
| 2495 | case 9: |
| 2496 | mcs = IEEE80211_VHT_MCS_SUPPORT_0_9; |
| 2497 | break; |
| 2498 | } |
| 2499 | |
| 2500 | tx_mcs_set &= ~(0x3 << (nss * 2)); |
| 2501 | tx_mcs_set |= mcs << (nss * 2); |
| 2502 | } |
| 2503 | |
| 2504 | return tx_mcs_set; |
| 2505 | } |
| 2506 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2507 | static void ath10k_peer_assoc_h_vht(struct ath10k *ar, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2508 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2509 | struct ieee80211_sta *sta, |
| 2510 | struct wmi_peer_assoc_complete_arg *arg) |
| 2511 | { |
| 2512 | const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2513 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2514 | struct cfg80211_chan_def def; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2515 | enum nl80211_band band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2516 | const u16 *vht_mcs_mask; |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 2517 | u8 ampdu_factor; |
Venkateswara Rao Naralasetty | fefcd11 | 2017-03-24 13:27:28 +0530 | [diff] [blame] | 2518 | u8 max_nss, vht_mcs; |
| 2519 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2520 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2521 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2522 | return; |
| 2523 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2524 | if (!vht_cap->vht_supported) |
| 2525 | return; |
| 2526 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2527 | band = def.chan->band; |
| 2528 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2529 | |
| 2530 | if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) |
| 2531 | return; |
| 2532 | |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2533 | arg->peer_flags |= ar->wmi.peer_flags->vht; |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 2534 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2535 | if (def.chan->band == NL80211_BAND_2GHZ) |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2536 | arg->peer_flags |= ar->wmi.peer_flags->vht_2g; |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 2537 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2538 | arg->peer_vht_caps = vht_cap->cap; |
| 2539 | |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 2540 | ampdu_factor = (vht_cap->cap & |
| 2541 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >> |
| 2542 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 2543 | |
| 2544 | /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to |
| 2545 | * zero in VHT IE. Using it would result in degraded throughput. |
| 2546 | * arg->peer_max_mpdu at this point contains HT max_mpdu so keep |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 2547 | * it if VHT max_mpdu is smaller. |
| 2548 | */ |
Sujith Manoharan | a24b88b | 2013-10-07 19:51:57 -0700 | [diff] [blame] | 2549 | arg->peer_max_mpdu = max(arg->peer_max_mpdu, |
| 2550 | (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR + |
| 2551 | ampdu_factor)) - 1); |
| 2552 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2553 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2554 | arg->peer_flags |= ar->wmi.peer_flags->bw80; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2555 | |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 2556 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 2557 | arg->peer_flags |= ar->wmi.peer_flags->bw160; |
| 2558 | |
Venkateswara Rao Naralasetty | fefcd11 | 2017-03-24 13:27:28 +0530 | [diff] [blame] | 2559 | /* Calculate peer NSS capability from VHT capabilities if STA |
| 2560 | * supports VHT. |
| 2561 | */ |
| 2562 | for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 2563 | vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >> |
| 2564 | (2 * i) & 3; |
| 2565 | |
| 2566 | if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) && |
| 2567 | vht_mcs_mask[i]) |
| 2568 | max_nss = i + 1; |
| 2569 | } |
| 2570 | arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2571 | arg->peer_vht_rates.rx_max_rate = |
| 2572 | __le16_to_cpu(vht_cap->vht_mcs.rx_highest); |
| 2573 | arg->peer_vht_rates.rx_mcs_set = |
| 2574 | __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map); |
| 2575 | arg->peer_vht_rates.tx_max_rate = |
| 2576 | __le16_to_cpu(vht_cap->vht_mcs.tx_highest); |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2577 | arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit( |
| 2578 | __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] | 2579 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2580 | 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] | 2581 | sta->addr, arg->peer_max_mpdu, arg->peer_flags); |
Ben Greear | cc914a5 | 2017-06-16 10:37:45 +0300 | [diff] [blame] | 2582 | |
| 2583 | if (arg->peer_vht_rates.rx_max_rate && |
| 2584 | (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) { |
| 2585 | switch (arg->peer_vht_rates.rx_max_rate) { |
| 2586 | case 1560: |
| 2587 | /* Must be 2x2 at 160Mhz is all it can do. */ |
| 2588 | arg->peer_bw_rxnss_override = 2; |
| 2589 | break; |
| 2590 | case 780: |
| 2591 | /* Can only do 1x1 at 160Mhz (Long Guard Interval) */ |
| 2592 | arg->peer_bw_rxnss_override = 1; |
| 2593 | break; |
| 2594 | } |
| 2595 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | static void ath10k_peer_assoc_h_qos(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2599 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2600 | struct ieee80211_sta *sta, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2601 | struct wmi_peer_assoc_complete_arg *arg) |
| 2602 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2603 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2604 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2605 | switch (arvif->vdev_type) { |
| 2606 | case WMI_VDEV_TYPE_AP: |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2607 | if (sta->wme) |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2608 | arg->peer_flags |= arvif->ar->wmi.peer_flags->qos; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2609 | |
| 2610 | if (sta->wme && sta->uapsd_queues) { |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2611 | arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd; |
Janusz Dziedzic | d3d3ff4 | 2014-01-21 07:06:53 +0100 | [diff] [blame] | 2612 | arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG; |
| 2613 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2614 | break; |
| 2615 | case WMI_VDEV_TYPE_STA: |
Balaji Pothunoori | 07ffb44 | 2017-12-07 16:58:04 +0200 | [diff] [blame] | 2616 | if (sta->wme) |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2617 | arg->peer_flags |= arvif->ar->wmi.peer_flags->qos; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2618 | break; |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 2619 | case WMI_VDEV_TYPE_IBSS: |
| 2620 | if (sta->wme) |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2621 | arg->peer_flags |= arvif->ar->wmi.peer_flags->qos; |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 2622 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2623 | default: |
| 2624 | break; |
| 2625 | } |
Janusz Dziedzic | 627d984 | 2014-12-17 12:29:54 +0200 | [diff] [blame] | 2626 | |
| 2627 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n", |
Tamizh chelvam | 3fab30f | 2015-10-29 14:27:37 +0200 | [diff] [blame] | 2628 | sta->addr, !!(arg->peer_flags & |
| 2629 | arvif->ar->wmi.peer_flags->qos)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2630 | } |
| 2631 | |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2632 | static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta) |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 2633 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2634 | return sta->supp_rates[NL80211_BAND_2GHZ] >> |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2635 | ATH10K_MAC_FIRST_OFDM_RATE_IDX; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 2636 | } |
| 2637 | |
Kalle Valo | 06efdbe | 2017-01-12 13:02:11 +0200 | [diff] [blame] | 2638 | static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar, |
| 2639 | struct ieee80211_sta *sta) |
| 2640 | { |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 2641 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) { |
| 2642 | switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) { |
| 2643 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ: |
| 2644 | return MODE_11AC_VHT160; |
| 2645 | case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ: |
| 2646 | return MODE_11AC_VHT80_80; |
| 2647 | default: |
| 2648 | /* not sure if this is a valid case? */ |
| 2649 | return MODE_11AC_VHT160; |
| 2650 | } |
| 2651 | } |
| 2652 | |
Kalle Valo | 06efdbe | 2017-01-12 13:02:11 +0200 | [diff] [blame] | 2653 | if (sta->bandwidth == IEEE80211_STA_RX_BW_80) |
| 2654 | return MODE_11AC_VHT80; |
| 2655 | |
| 2656 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2657 | return MODE_11AC_VHT40; |
| 2658 | |
| 2659 | if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
| 2660 | return MODE_11AC_VHT20; |
| 2661 | |
| 2662 | return MODE_UNKNOWN; |
| 2663 | } |
| 2664 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2665 | static void ath10k_peer_assoc_h_phymode(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2666 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2667 | struct ieee80211_sta *sta, |
| 2668 | struct wmi_peer_assoc_complete_arg *arg) |
| 2669 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2670 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2671 | struct cfg80211_chan_def def; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2672 | enum nl80211_band band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2673 | const u8 *ht_mcs_mask; |
| 2674 | const u16 *vht_mcs_mask; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2675 | enum wmi_phy_mode phymode = MODE_UNKNOWN; |
| 2676 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2677 | if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) |
| 2678 | return; |
| 2679 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2680 | band = def.chan->band; |
| 2681 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 2682 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 2683 | |
| 2684 | switch (band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2685 | case NL80211_BAND_2GHZ: |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2686 | if (sta->vht_cap.vht_supported && |
| 2687 | !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
Yanbo Li | d68bb12 | 2015-01-23 08:18:20 +0800 | [diff] [blame] | 2688 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2689 | phymode = MODE_11AC_VHT40; |
| 2690 | else |
| 2691 | phymode = MODE_11AC_VHT20; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2692 | } else if (sta->ht_cap.ht_supported && |
| 2693 | !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2694 | if (sta->bandwidth == IEEE80211_STA_RX_BW_40) |
| 2695 | phymode = MODE_11NG_HT40; |
| 2696 | else |
| 2697 | phymode = MODE_11NG_HT20; |
Michal Kazior | 8d7aa6b | 2015-03-30 09:51:57 +0300 | [diff] [blame] | 2698 | } else if (ath10k_mac_sta_has_ofdm_only(sta)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2699 | phymode = MODE_11G; |
Michal Kazior | 91b1208 | 2014-12-12 12:41:35 +0100 | [diff] [blame] | 2700 | } else { |
| 2701 | phymode = MODE_11B; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2705 | case NL80211_BAND_5GHZ: |
Sujith Manoharan | 7cc45e9 | 2013-09-08 18:19:55 +0300 | [diff] [blame] | 2706 | /* |
| 2707 | * Check VHT first. |
| 2708 | */ |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2709 | if (sta->vht_cap.vht_supported && |
| 2710 | !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) { |
Kalle Valo | 06efdbe | 2017-01-12 13:02:11 +0200 | [diff] [blame] | 2711 | phymode = ath10k_mac_get_phymode_vht(ar, sta); |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2712 | } else if (sta->ht_cap.ht_supported && |
| 2713 | !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) { |
| 2714 | if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2715 | phymode = MODE_11NA_HT40; |
| 2716 | else |
| 2717 | phymode = MODE_11NA_HT20; |
| 2718 | } else { |
| 2719 | phymode = MODE_11A; |
| 2720 | } |
| 2721 | |
| 2722 | break; |
| 2723 | default: |
| 2724 | break; |
| 2725 | } |
| 2726 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2727 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n", |
Kalle Valo | 38a1d47 | 2013-09-08 17:56:14 +0300 | [diff] [blame] | 2728 | sta->addr, ath10k_wmi_phymode_str(phymode)); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2729 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2730 | arg->peer_phymode = phymode; |
| 2731 | WARN_ON(phymode == MODE_UNKNOWN); |
| 2732 | } |
| 2733 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2734 | static int ath10k_peer_assoc_prepare(struct ath10k *ar, |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2735 | struct ieee80211_vif *vif, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2736 | struct ieee80211_sta *sta, |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2737 | struct wmi_peer_assoc_complete_arg *arg) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2738 | { |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2739 | lockdep_assert_held(&ar->conf_mutex); |
| 2740 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2741 | memset(arg, 0, sizeof(*arg)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2742 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2743 | ath10k_peer_assoc_h_basic(ar, vif, sta, arg); |
Tamizh chelvam | 90eceb3 | 2015-10-29 14:27:42 +0200 | [diff] [blame] | 2744 | ath10k_peer_assoc_h_crypto(ar, vif, sta, arg); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2745 | ath10k_peer_assoc_h_rates(ar, vif, sta, arg); |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 2746 | ath10k_peer_assoc_h_ht(ar, vif, sta, arg); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 2747 | ath10k_peer_assoc_h_vht(ar, vif, sta, arg); |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2748 | ath10k_peer_assoc_h_qos(ar, vif, sta, arg); |
| 2749 | ath10k_peer_assoc_h_phymode(ar, vif, sta, arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2750 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2751 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2752 | } |
| 2753 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2754 | static const u32 ath10k_smps_map[] = { |
| 2755 | [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC, |
| 2756 | [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC, |
| 2757 | [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE, |
| 2758 | [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE, |
| 2759 | }; |
| 2760 | |
| 2761 | static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif, |
| 2762 | const u8 *addr, |
| 2763 | const struct ieee80211_sta_ht_cap *ht_cap) |
| 2764 | { |
| 2765 | int smps; |
| 2766 | |
| 2767 | if (!ht_cap->ht_supported) |
| 2768 | return 0; |
| 2769 | |
| 2770 | smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS; |
| 2771 | smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 2772 | |
| 2773 | if (smps >= ARRAY_SIZE(ath10k_smps_map)) |
| 2774 | return -EINVAL; |
| 2775 | |
| 2776 | return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 2777 | ar->wmi.peer_param->smps_state, |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2778 | ath10k_smps_map[smps]); |
| 2779 | } |
| 2780 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2781 | static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar, |
| 2782 | struct ieee80211_vif *vif, |
| 2783 | struct ieee80211_sta_vht_cap vht_cap) |
| 2784 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2785 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2786 | int ret; |
| 2787 | u32 param; |
| 2788 | u32 value; |
| 2789 | |
Vivek Natarajan | 08e75ea | 2015-08-04 10:45:11 +0530 | [diff] [blame] | 2790 | if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC) |
| 2791 | return 0; |
| 2792 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2793 | if (!(ar->vht_cap_info & |
| 2794 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 2795 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | |
| 2796 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 2797 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))) |
| 2798 | return 0; |
| 2799 | |
| 2800 | param = ar->wmi.vdev_param->txbf; |
| 2801 | value = 0; |
| 2802 | |
| 2803 | if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED)) |
| 2804 | return 0; |
| 2805 | |
| 2806 | /* The following logic is correct. If a remote STA advertises support |
| 2807 | * for being a beamformer then we should enable us being a beamformee. |
| 2808 | */ |
| 2809 | |
| 2810 | if (ar->vht_cap_info & |
| 2811 | (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 2812 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 2813 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) |
| 2814 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2815 | |
| 2816 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) |
| 2817 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE; |
| 2818 | } |
| 2819 | |
| 2820 | if (ar->vht_cap_info & |
| 2821 | (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 2822 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 2823 | if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) |
| 2824 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2825 | |
| 2826 | if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) |
| 2827 | value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER; |
| 2828 | } |
| 2829 | |
| 2830 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE) |
| 2831 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 2832 | |
| 2833 | if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER) |
| 2834 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 2835 | |
| 2836 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value); |
| 2837 | if (ret) { |
| 2838 | ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n", |
| 2839 | value, ret); |
| 2840 | return ret; |
| 2841 | } |
| 2842 | |
| 2843 | return 0; |
| 2844 | } |
| 2845 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2846 | /* can be called only in mac80211 callbacks due to `key_count` usage */ |
| 2847 | static void ath10k_bss_assoc(struct ieee80211_hw *hw, |
| 2848 | struct ieee80211_vif *vif, |
| 2849 | struct ieee80211_bss_conf *bss_conf) |
| 2850 | { |
| 2851 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2852 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2853 | struct ieee80211_sta_ht_cap ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2854 | struct ieee80211_sta_vht_cap vht_cap; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2855 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2856 | struct ieee80211_sta *ap_sta; |
| 2857 | int ret; |
| 2858 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2859 | lockdep_assert_held(&ar->conf_mutex); |
| 2860 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2861 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n", |
| 2862 | arvif->vdev_id, arvif->bssid, arvif->aid); |
| 2863 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2864 | rcu_read_lock(); |
| 2865 | |
| 2866 | ap_sta = ieee80211_find_sta(vif, bss_conf->bssid); |
| 2867 | if (!ap_sta) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2868 | 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] | 2869 | bss_conf->bssid, arvif->vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2870 | rcu_read_unlock(); |
| 2871 | return; |
| 2872 | } |
| 2873 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2874 | /* ap_sta must be accessed only within rcu section which must be left |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 2875 | * before calling ath10k_setup_peer_smps() which might sleep. |
| 2876 | */ |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2877 | ht_cap = ap_sta->ht_cap; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2878 | vht_cap = ap_sta->vht_cap; |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2879 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2880 | ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2881 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2882 | 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] | 2883 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2884 | rcu_read_unlock(); |
| 2885 | return; |
| 2886 | } |
| 2887 | |
| 2888 | rcu_read_unlock(); |
| 2889 | |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2890 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2891 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2892 | 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] | 2893 | bss_conf->bssid, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2894 | return; |
| 2895 | } |
| 2896 | |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2897 | ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap); |
| 2898 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2899 | 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] | 2900 | arvif->vdev_id, ret); |
Michal Kazior | 90046f5 | 2014-02-14 14:45:51 +0100 | [diff] [blame] | 2901 | return; |
| 2902 | } |
| 2903 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2904 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2905 | if (ret) { |
| 2906 | ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n", |
| 2907 | arvif->vdev_id, bss_conf->bssid, ret); |
| 2908 | return; |
| 2909 | } |
| 2910 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2911 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2912 | "mac vdev %d up (associated) bssid %pM aid %d\n", |
| 2913 | arvif->vdev_id, bss_conf->bssid, bss_conf->aid); |
| 2914 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2915 | WARN_ON(arvif->is_up); |
| 2916 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2917 | arvif->aid = bss_conf->aid; |
Kalle Valo | b25f32c | 2014-09-14 12:50:49 +0300 | [diff] [blame] | 2918 | ether_addr_copy(arvif->bssid, bss_conf->bssid); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2919 | |
| 2920 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid); |
| 2921 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2922 | ath10k_warn(ar, "failed to set vdev %d up: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2923 | arvif->vdev_id, ret); |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2924 | return; |
| 2925 | } |
| 2926 | |
| 2927 | arvif->is_up = true; |
Michal Kazior | 0a987fb | 2015-02-13 13:30:15 +0100 | [diff] [blame] | 2928 | |
| 2929 | /* Workaround: Some firmware revisions (tested with qca6174 |
| 2930 | * WLAN.RM.2.0-00073) have buggy powersave state machine and must be |
| 2931 | * poked with peer param command. |
| 2932 | */ |
| 2933 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 2934 | ar->wmi.peer_param->dummy_var, 1); |
Michal Kazior | 0a987fb | 2015-02-13 13:30:15 +0100 | [diff] [blame] | 2935 | if (ret) { |
| 2936 | ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n", |
| 2937 | arvif->bssid, arvif->vdev_id, ret); |
| 2938 | return; |
| 2939 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2940 | } |
| 2941 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2942 | static void ath10k_bss_disassoc(struct ieee80211_hw *hw, |
| 2943 | struct ieee80211_vif *vif) |
| 2944 | { |
| 2945 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2946 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2947 | struct ieee80211_sta_vht_cap vht_cap = {}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2948 | int ret; |
| 2949 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2950 | lockdep_assert_held(&ar->conf_mutex); |
| 2951 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2952 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n", |
| 2953 | arvif->vdev_id, arvif->bssid); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 2954 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2955 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2956 | if (ret) |
Ben Greear | aa66ba0 | 2016-09-26 21:56:25 +0300 | [diff] [blame] | 2957 | ath10k_warn(ar, "failed to down vdev %i: %d\n", |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2958 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2959 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 2960 | arvif->def_wep_key_idx = -1; |
| 2961 | |
Michal Kazior | 139e170 | 2015-02-15 16:50:42 +0200 | [diff] [blame] | 2962 | ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap); |
| 2963 | if (ret) { |
| 2964 | ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n", |
| 2965 | arvif->vdev_id, ret); |
| 2966 | return; |
| 2967 | } |
| 2968 | |
Michal Kazior | c930f74 | 2014-01-23 11:38:25 +0100 | [diff] [blame] | 2969 | arvif->is_up = false; |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 2970 | |
| 2971 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2972 | } |
| 2973 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2974 | static int ath10k_station_assoc(struct ath10k *ar, |
| 2975 | struct ieee80211_vif *vif, |
| 2976 | struct ieee80211_sta *sta, |
| 2977 | bool reassoc) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2978 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 2979 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2980 | struct wmi_peer_assoc_complete_arg peer_arg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2981 | int ret = 0; |
| 2982 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 2983 | lockdep_assert_held(&ar->conf_mutex); |
| 2984 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2985 | ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2986 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2987 | 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] | 2988 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | b9ada65 | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 2989 | return ret; |
| 2990 | } |
| 2991 | |
| 2992 | ret = ath10k_wmi_peer_assoc(ar, &peer_arg); |
| 2993 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2994 | 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] | 2995 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2996 | return ret; |
| 2997 | } |
| 2998 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 2999 | /* Re-assoc is run only to update supported rates for given station. It |
| 3000 | * doesn't make much sense to reconfigure the peer completely. |
| 3001 | */ |
| 3002 | if (!reassoc) { |
| 3003 | ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, |
| 3004 | &sta->ht_cap); |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3005 | if (ret) { |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3006 | 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] | 3007 | arvif->vdev_id, ret); |
| 3008 | return ret; |
| 3009 | } |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3010 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3011 | ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta); |
| 3012 | if (ret) { |
| 3013 | ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n", |
| 3014 | sta->addr, arvif->vdev_id, ret); |
| 3015 | return ret; |
| 3016 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3017 | |
Michal Kazior | b1ecde3 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3018 | if (!sta->wme) { |
| 3019 | arvif->num_legacy_stations++; |
| 3020 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 3021 | if (ret) { |
| 3022 | ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n", |
| 3023 | arvif->vdev_id, ret); |
| 3024 | return ret; |
| 3025 | } |
| 3026 | } |
| 3027 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 3028 | /* Plumb cached keys only for static WEP */ |
Yingying Tang | c3816c9 | 2018-03-28 12:15:23 +0300 | [diff] [blame] | 3029 | if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) { |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 3030 | ret = ath10k_install_peer_wep_keys(arvif, sta->addr); |
| 3031 | if (ret) { |
| 3032 | ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n", |
| 3033 | arvif->vdev_id, ret); |
| 3034 | return ret; |
| 3035 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3039 | return ret; |
| 3040 | } |
| 3041 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 3042 | static int ath10k_station_disassoc(struct ath10k *ar, |
| 3043 | struct ieee80211_vif *vif, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3044 | struct ieee80211_sta *sta) |
| 3045 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 3046 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3047 | int ret = 0; |
| 3048 | |
| 3049 | lockdep_assert_held(&ar->conf_mutex); |
| 3050 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 3051 | if (!sta->wme) { |
| 3052 | arvif->num_legacy_stations--; |
| 3053 | ret = ath10k_recalc_rtscts_prot(arvif); |
| 3054 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3055 | 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] | 3056 | arvif->vdev_id, ret); |
| 3057 | return ret; |
| 3058 | } |
| 3059 | } |
| 3060 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3061 | ret = ath10k_clear_peer_keys(arvif, sta->addr); |
| 3062 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3063 | 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] | 3064 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3065 | return ret; |
| 3066 | } |
| 3067 | |
| 3068 | return ret; |
| 3069 | } |
| 3070 | |
| 3071 | /**************/ |
| 3072 | /* Regulatory */ |
| 3073 | /**************/ |
| 3074 | |
| 3075 | static int ath10k_update_channel_list(struct ath10k *ar) |
| 3076 | { |
| 3077 | struct ieee80211_hw *hw = ar->hw; |
| 3078 | struct ieee80211_supported_band **bands; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3079 | enum nl80211_band band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3080 | struct ieee80211_channel *channel; |
| 3081 | struct wmi_scan_chan_list_arg arg = {0}; |
| 3082 | struct wmi_channel_arg *ch; |
| 3083 | bool passive; |
| 3084 | int len; |
| 3085 | int ret; |
| 3086 | int i; |
| 3087 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3088 | lockdep_assert_held(&ar->conf_mutex); |
| 3089 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3090 | bands = hw->wiphy->bands; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3091 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3092 | if (!bands[band]) |
| 3093 | continue; |
| 3094 | |
| 3095 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 3096 | if (bands[band]->channels[i].flags & |
| 3097 | IEEE80211_CHAN_DISABLED) |
| 3098 | continue; |
| 3099 | |
| 3100 | arg.n_channels++; |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | len = sizeof(struct wmi_channel_arg) * arg.n_channels; |
| 3105 | arg.channels = kzalloc(len, GFP_KERNEL); |
| 3106 | if (!arg.channels) |
| 3107 | return -ENOMEM; |
| 3108 | |
| 3109 | ch = arg.channels; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3110 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3111 | if (!bands[band]) |
| 3112 | continue; |
| 3113 | |
| 3114 | for (i = 0; i < bands[band]->n_channels; i++) { |
| 3115 | channel = &bands[band]->channels[i]; |
| 3116 | |
| 3117 | if (channel->flags & IEEE80211_CHAN_DISABLED) |
| 3118 | continue; |
| 3119 | |
Eduardo Abinader | 9802977 | 2016-06-30 15:23:55 +0300 | [diff] [blame] | 3120 | ch->allow_ht = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3121 | |
| 3122 | /* FIXME: when should we really allow VHT? */ |
| 3123 | ch->allow_vht = true; |
| 3124 | |
| 3125 | ch->allow_ibss = |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 3126 | !(channel->flags & IEEE80211_CHAN_NO_IR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3127 | |
| 3128 | ch->ht40plus = |
| 3129 | !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS); |
| 3130 | |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 3131 | ch->chan_radar = |
| 3132 | !!(channel->flags & IEEE80211_CHAN_RADAR); |
| 3133 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 3134 | passive = channel->flags & IEEE80211_CHAN_NO_IR; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3135 | ch->passive = passive; |
| 3136 | |
Sven Eckelmann | 3f25911 | 2018-07-26 15:59:48 +0200 | [diff] [blame] | 3137 | /* the firmware is ignoring the "radar" flag of the |
| 3138 | * channel and is scanning actively using Probe Requests |
| 3139 | * on "Radar detection"/DFS channels which are not |
| 3140 | * marked as "available" |
| 3141 | */ |
| 3142 | ch->passive |= ch->chan_radar; |
| 3143 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3144 | ch->freq = channel->center_freq; |
Michal Kazior | 2d66721 | 2014-09-18 15:21:21 +0200 | [diff] [blame] | 3145 | ch->band_center_freq1 = channel->center_freq; |
Michal Kazior | 89c5c84 | 2013-10-23 04:02:13 -0700 | [diff] [blame] | 3146 | ch->min_power = 0; |
Michal Kazior | 0225693 | 2013-10-23 04:02:14 -0700 | [diff] [blame] | 3147 | ch->max_power = channel->max_power * 2; |
| 3148 | ch->max_reg_power = channel->max_reg_power * 2; |
| 3149 | ch->max_antenna_gain = channel->max_antenna_gain * 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3150 | ch->reg_class_id = 0; /* FIXME */ |
| 3151 | |
| 3152 | /* FIXME: why use only legacy modes, why not any |
| 3153 | * HT/VHT modes? Would that even make any |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 3154 | * difference? |
| 3155 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3156 | if (channel->band == NL80211_BAND_2GHZ) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3157 | ch->mode = MODE_11G; |
| 3158 | else |
| 3159 | ch->mode = MODE_11A; |
| 3160 | |
| 3161 | if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN)) |
| 3162 | continue; |
| 3163 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3164 | ath10k_dbg(ar, ATH10K_DBG_WMI, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3165 | "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n", |
| 3166 | ch - arg.channels, arg.n_channels, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3167 | ch->freq, ch->max_power, ch->max_reg_power, |
| 3168 | ch->max_antenna_gain, ch->mode); |
| 3169 | |
| 3170 | ch++; |
| 3171 | } |
| 3172 | } |
| 3173 | |
| 3174 | ret = ath10k_wmi_scan_chan_list(ar, &arg); |
| 3175 | kfree(arg.channels); |
| 3176 | |
| 3177 | return ret; |
| 3178 | } |
| 3179 | |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 3180 | static enum wmi_dfs_region |
| 3181 | ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region) |
| 3182 | { |
| 3183 | switch (dfs_region) { |
| 3184 | case NL80211_DFS_UNSET: |
| 3185 | return WMI_UNINIT_DFS_DOMAIN; |
| 3186 | case NL80211_DFS_FCC: |
| 3187 | return WMI_FCC_DFS_DOMAIN; |
| 3188 | case NL80211_DFS_ETSI: |
| 3189 | return WMI_ETSI_DFS_DOMAIN; |
| 3190 | case NL80211_DFS_JP: |
| 3191 | return WMI_MKK4_DFS_DOMAIN; |
| 3192 | } |
| 3193 | return WMI_UNINIT_DFS_DOMAIN; |
| 3194 | } |
| 3195 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3196 | static void ath10k_regd_update(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3197 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3198 | struct reg_dmn_pair_mapping *regpair; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3199 | int ret; |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 3200 | enum wmi_dfs_region wmi_dfs_reg; |
| 3201 | enum nl80211_dfs_regions nl_dfs_reg; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3202 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3203 | lockdep_assert_held(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3204 | |
| 3205 | ret = ath10k_update_channel_list(ar); |
| 3206 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3207 | ath10k_warn(ar, "failed to update channel list: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3208 | |
| 3209 | regpair = ar->ath_common.regulatory.regpair; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3210 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 3211 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 3212 | nl_dfs_reg = ar->dfs_detector->region; |
| 3213 | wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg); |
| 3214 | } else { |
| 3215 | wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN; |
| 3216 | } |
| 3217 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3218 | /* Target allows setting up per-band regdomain but ath_common provides |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 3219 | * a combined one only |
| 3220 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3221 | ret = ath10k_wmi_pdev_set_regdomain(ar, |
Kalle Valo | ef8c001 | 2014-02-13 18:13:12 +0200 | [diff] [blame] | 3222 | regpair->reg_domain, |
| 3223 | regpair->reg_domain, /* 2ghz */ |
| 3224 | regpair->reg_domain, /* 5ghz */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3225 | regpair->reg_2ghz_ctl, |
Marek Puzyniak | 821af6a | 2014-03-21 17:46:57 +0200 | [diff] [blame] | 3226 | regpair->reg_5ghz_ctl, |
| 3227 | wmi_dfs_reg); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3228 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3229 | ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret); |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3230 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3231 | |
Kalle Valo | 46bc92b | 2017-03-16 11:11:02 +0200 | [diff] [blame] | 3232 | static void ath10k_mac_update_channel_list(struct ath10k *ar, |
| 3233 | struct ieee80211_supported_band *band) |
Tamizh chelvam | 523f670 | 2017-02-23 18:48:22 +0530 | [diff] [blame] | 3234 | { |
| 3235 | int i; |
| 3236 | |
| 3237 | if (ar->low_5ghz_chan && ar->high_5ghz_chan) { |
| 3238 | for (i = 0; i < band->n_channels; i++) { |
| 3239 | if (band->channels[i].center_freq < ar->low_5ghz_chan || |
| 3240 | band->channels[i].center_freq > ar->high_5ghz_chan) |
| 3241 | band->channels[i].flags |= |
| 3242 | IEEE80211_CHAN_DISABLED; |
| 3243 | } |
| 3244 | } |
| 3245 | } |
| 3246 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3247 | static void ath10k_reg_notifier(struct wiphy *wiphy, |
| 3248 | struct regulatory_request *request) |
| 3249 | { |
| 3250 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 3251 | struct ath10k *ar = hw->priv; |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 3252 | bool result; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3253 | |
| 3254 | ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory); |
| 3255 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 3256 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3257 | ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n", |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 3258 | request->dfs_region); |
| 3259 | result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector, |
| 3260 | request->dfs_region); |
| 3261 | if (!result) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3262 | 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] | 3263 | request->dfs_region); |
| 3264 | } |
| 3265 | |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 3266 | mutex_lock(&ar->conf_mutex); |
| 3267 | if (ar->state == ATH10K_STATE_ON) |
| 3268 | ath10k_regd_update(ar); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 3269 | mutex_unlock(&ar->conf_mutex); |
Tamizh chelvam | 523f670 | 2017-02-23 18:48:22 +0530 | [diff] [blame] | 3270 | |
| 3271 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) |
| 3272 | ath10k_mac_update_channel_list(ar, |
Kalle Valo | 46bc92b | 2017-03-16 11:11:02 +0200 | [diff] [blame] | 3273 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ]); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3274 | } |
| 3275 | |
Sriram R | 6f6eb1b | 2018-05-15 14:39:49 +0530 | [diff] [blame] | 3276 | static void ath10k_stop_radar_confirmation(struct ath10k *ar) |
| 3277 | { |
| 3278 | spin_lock_bh(&ar->data_lock); |
| 3279 | ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED; |
| 3280 | spin_unlock_bh(&ar->data_lock); |
| 3281 | |
| 3282 | cancel_work_sync(&ar->radar_confirmation_work); |
| 3283 | } |
| 3284 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3285 | /***************/ |
| 3286 | /* TX handlers */ |
| 3287 | /***************/ |
| 3288 | |
Michal Kazior | a30c7d0 | 2016-03-06 16:14:23 +0200 | [diff] [blame] | 3289 | enum ath10k_mac_tx_path { |
| 3290 | ATH10K_MAC_TX_HTT, |
| 3291 | ATH10K_MAC_TX_HTT_MGMT, |
| 3292 | ATH10K_MAC_TX_WMI_MGMT, |
| 3293 | ATH10K_MAC_TX_UNKNOWN, |
| 3294 | }; |
| 3295 | |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 3296 | void ath10k_mac_tx_lock(struct ath10k *ar, int reason) |
| 3297 | { |
| 3298 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3299 | |
| 3300 | WARN_ON(reason >= ATH10K_TX_PAUSE_MAX); |
| 3301 | ar->tx_paused |= BIT(reason); |
| 3302 | ieee80211_stop_queues(ar->hw); |
| 3303 | } |
| 3304 | |
| 3305 | static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac, |
| 3306 | struct ieee80211_vif *vif) |
| 3307 | { |
| 3308 | struct ath10k *ar = data; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 3309 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 3310 | |
| 3311 | if (arvif->tx_paused) |
| 3312 | return; |
| 3313 | |
| 3314 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); |
| 3315 | } |
| 3316 | |
| 3317 | void ath10k_mac_tx_unlock(struct ath10k *ar, int reason) |
| 3318 | { |
| 3319 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3320 | |
| 3321 | WARN_ON(reason >= ATH10K_TX_PAUSE_MAX); |
| 3322 | ar->tx_paused &= ~BIT(reason); |
| 3323 | |
| 3324 | if (ar->tx_paused) |
| 3325 | return; |
| 3326 | |
| 3327 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 3328 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 3329 | ath10k_mac_tx_unlock_iter, |
| 3330 | ar); |
Michal Kazior | 3a73d1a | 2015-08-06 14:46:54 +0200 | [diff] [blame] | 3331 | |
| 3332 | ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue); |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason) |
| 3336 | { |
| 3337 | struct ath10k *ar = arvif->ar; |
| 3338 | |
| 3339 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3340 | |
| 3341 | WARN_ON(reason >= BITS_PER_LONG); |
| 3342 | arvif->tx_paused |= BIT(reason); |
| 3343 | ieee80211_stop_queue(ar->hw, arvif->vdev_id); |
| 3344 | } |
| 3345 | |
| 3346 | void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason) |
| 3347 | { |
| 3348 | struct ath10k *ar = arvif->ar; |
| 3349 | |
| 3350 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3351 | |
| 3352 | WARN_ON(reason >= BITS_PER_LONG); |
| 3353 | arvif->tx_paused &= ~BIT(reason); |
| 3354 | |
| 3355 | if (ar->tx_paused) |
| 3356 | return; |
| 3357 | |
| 3358 | if (arvif->tx_paused) |
| 3359 | return; |
| 3360 | |
| 3361 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); |
| 3362 | } |
| 3363 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3364 | static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif, |
| 3365 | enum wmi_tlv_tx_pause_id pause_id, |
| 3366 | enum wmi_tlv_tx_pause_action action) |
| 3367 | { |
| 3368 | struct ath10k *ar = arvif->ar; |
| 3369 | |
| 3370 | lockdep_assert_held(&ar->htt.tx_lock); |
| 3371 | |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3372 | switch (action) { |
| 3373 | case WMI_TLV_TX_PAUSE_ACTION_STOP: |
| 3374 | ath10k_mac_vif_tx_lock(arvif, pause_id); |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3375 | break; |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3376 | case WMI_TLV_TX_PAUSE_ACTION_WAKE: |
| 3377 | ath10k_mac_vif_tx_unlock(arvif, pause_id); |
| 3378 | break; |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3379 | default: |
Bartosz Markowski | 209b2a6 | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 3380 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 3381 | "received unknown tx pause action %d on vdev %i, ignoring\n", |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3382 | action, arvif->vdev_id); |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3383 | break; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | struct ath10k_mac_tx_pause { |
| 3388 | u32 vdev_id; |
| 3389 | enum wmi_tlv_tx_pause_id pause_id; |
| 3390 | enum wmi_tlv_tx_pause_action action; |
| 3391 | }; |
| 3392 | |
| 3393 | static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac, |
| 3394 | struct ieee80211_vif *vif) |
| 3395 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 3396 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3397 | struct ath10k_mac_tx_pause *arg = data; |
| 3398 | |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3399 | if (arvif->vdev_id != arg->vdev_id) |
| 3400 | return; |
| 3401 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3402 | ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action); |
| 3403 | } |
| 3404 | |
Michal Kazior | acd0b27 | 2015-07-09 13:08:38 +0200 | [diff] [blame] | 3405 | void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id, |
| 3406 | enum wmi_tlv_tx_pause_id pause_id, |
| 3407 | enum wmi_tlv_tx_pause_action action) |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 3408 | { |
| 3409 | struct ath10k_mac_tx_pause arg = { |
| 3410 | .vdev_id = vdev_id, |
| 3411 | .pause_id = pause_id, |
| 3412 | .action = action, |
| 3413 | }; |
| 3414 | |
| 3415 | spin_lock_bh(&ar->htt.tx_lock); |
| 3416 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 3417 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 3418 | ath10k_mac_handle_tx_pause_iter, |
| 3419 | &arg); |
| 3420 | spin_unlock_bh(&ar->htt.tx_lock); |
| 3421 | } |
| 3422 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3423 | static enum ath10k_hw_txrx_mode |
Michal Kazior | 6a2636d | 2015-11-18 06:59:16 +0100 | [diff] [blame] | 3424 | ath10k_mac_tx_h_get_txmode(struct ath10k *ar, |
| 3425 | struct ieee80211_vif *vif, |
| 3426 | struct ieee80211_sta *sta, |
| 3427 | struct sk_buff *skb) |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3428 | { |
| 3429 | const struct ieee80211_hdr *hdr = (void *)skb->data; |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 3430 | const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb); |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3431 | __le16 fc = hdr->frame_control; |
| 3432 | |
| 3433 | if (!vif || vif->type == NL80211_IFTYPE_MONITOR) |
| 3434 | return ATH10K_HW_TXRX_RAW; |
| 3435 | |
| 3436 | if (ieee80211_is_mgmt(fc)) |
| 3437 | return ATH10K_HW_TXRX_MGMT; |
| 3438 | |
| 3439 | /* Workaround: |
| 3440 | * |
| 3441 | * NullFunc frames are mostly used to ping if a client or AP are still |
| 3442 | * reachable and responsive. This implies tx status reports must be |
| 3443 | * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can |
| 3444 | * come to a conclusion that the other end disappeared and tear down |
| 3445 | * BSS connection or it can never disconnect from BSS/client (which is |
| 3446 | * the case). |
| 3447 | * |
| 3448 | * Firmware with HTT older than 3.0 delivers incorrect tx status for |
| 3449 | * NullFunc frames to driver. However there's a HTT Mgmt Tx command |
| 3450 | * which seems to deliver correct tx reports for NullFunc frames. The |
| 3451 | * downside of using it is it ignores client powersave state so it can |
| 3452 | * end up disconnecting sleeping clients in AP mode. It should fix STA |
| 3453 | * mode though because AP don't sleep. |
| 3454 | */ |
| 3455 | if (ar->htt.target_version_major < 3 && |
| 3456 | (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) && |
Kalle Valo | c4cdf75 | 2016-04-20 19:45:18 +0300 | [diff] [blame] | 3457 | !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
| 3458 | ar->running_fw->fw_file.fw_features)) |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3459 | return ATH10K_HW_TXRX_MGMT; |
| 3460 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3461 | /* Workaround: |
| 3462 | * |
| 3463 | * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for |
| 3464 | * NativeWifi txmode - it selects AP key instead of peer key. It seems |
| 3465 | * to work with Ethernet txmode so use it. |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3466 | * |
| 3467 | * FIXME: Check if raw mode works with TDLS. |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 3468 | */ |
| 3469 | if (ieee80211_is_data_present(fc) && sta && sta->tdls) |
| 3470 | return ATH10K_HW_TXRX_ETHERNET; |
| 3471 | |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 3472 | if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) || |
| 3473 | skb_cb->flags & ATH10K_SKB_F_RAW_TX) |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3474 | return ATH10K_HW_TXRX_RAW; |
| 3475 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3476 | return ATH10K_HW_TXRX_NATIVE_WIFI; |
| 3477 | } |
| 3478 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3479 | static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif, |
Michal Kazior | fd12cb3 | 2015-11-18 06:59:15 +0100 | [diff] [blame] | 3480 | struct sk_buff *skb) |
| 3481 | { |
| 3482 | const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 3483 | const struct ieee80211_hdr *hdr = (void *)skb->data; |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3484 | const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 3485 | IEEE80211_TX_CTL_INJECTED; |
Michal Kazior | fd12cb3 | 2015-11-18 06:59:15 +0100 | [diff] [blame] | 3486 | |
| 3487 | if (!ieee80211_has_protected(hdr->frame_control)) |
| 3488 | return false; |
| 3489 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3490 | if ((info->flags & mask) == mask) |
| 3491 | return false; |
Michal Kazior | fd12cb3 | 2015-11-18 06:59:15 +0100 | [diff] [blame] | 3492 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3493 | if (vif) |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 3494 | return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt; |
Michal Kazior | fd12cb3 | 2015-11-18 06:59:15 +0100 | [diff] [blame] | 3495 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 3496 | return true; |
| 3497 | } |
| 3498 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3499 | /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS |
| 3500 | * Control in the header. |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3501 | */ |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3502 | 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] | 3503 | { |
| 3504 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3505 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3506 | u8 *qos_ctl; |
| 3507 | |
| 3508 | if (!ieee80211_is_data_qos(hdr->frame_control)) |
| 3509 | return; |
| 3510 | |
| 3511 | qos_ctl = ieee80211_get_qos_ctl(hdr); |
Michal Kazior | ba0ccd7 | 2013-07-22 14:25:28 +0200 | [diff] [blame] | 3512 | memmove(skb->data + IEEE80211_QOS_CTL_LEN, |
| 3513 | skb->data, (void *)qos_ctl - (void *)skb->data); |
| 3514 | skb_pull(skb, IEEE80211_QOS_CTL_LEN); |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3515 | |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 3516 | /* Some firmware revisions don't handle sending QoS NullFunc well. |
| 3517 | * These frames are mainly used for CQM purposes so it doesn't really |
| 3518 | * matter whether QoS NullFunc or NullFunc are sent. |
Michal Kazior | c21c64d | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 3519 | */ |
Michal Kazior | bf0a26d | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 3520 | hdr = (void *)skb->data; |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 3521 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
Michal Kazior | 609db22 | 2015-11-18 06:59:22 +0100 | [diff] [blame] | 3522 | cb->flags &= ~ATH10K_SKB_F_QOS; |
Michal Kazior | 8bad8dc | 2015-03-11 14:25:26 +0100 | [diff] [blame] | 3523 | |
| 3524 | hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3525 | } |
| 3526 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3527 | static void ath10k_tx_h_8023(struct sk_buff *skb) |
| 3528 | { |
| 3529 | struct ieee80211_hdr *hdr; |
| 3530 | struct rfc1042_hdr *rfc1042; |
| 3531 | struct ethhdr *eth; |
| 3532 | size_t hdrlen; |
| 3533 | u8 da[ETH_ALEN]; |
| 3534 | u8 sa[ETH_ALEN]; |
| 3535 | __be16 type; |
| 3536 | |
| 3537 | hdr = (void *)skb->data; |
| 3538 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 3539 | rfc1042 = (void *)skb->data + hdrlen; |
| 3540 | |
| 3541 | ether_addr_copy(da, ieee80211_get_DA(hdr)); |
| 3542 | ether_addr_copy(sa, ieee80211_get_SA(hdr)); |
| 3543 | type = rfc1042->snap_type; |
| 3544 | |
| 3545 | skb_pull(skb, hdrlen + sizeof(*rfc1042)); |
| 3546 | skb_push(skb, sizeof(*eth)); |
| 3547 | |
| 3548 | eth = (void *)skb->data; |
| 3549 | ether_addr_copy(eth->h_dest, da); |
| 3550 | ether_addr_copy(eth->h_source, sa); |
| 3551 | eth->h_proto = type; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3552 | } |
| 3553 | |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 3554 | static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, |
| 3555 | struct ieee80211_vif *vif, |
| 3556 | struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3557 | { |
| 3558 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 3559 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3560 | |
| 3561 | /* This is case only for P2P_GO */ |
Peter Oh | 08c27be | 2016-01-28 13:54:09 -0800 | [diff] [blame] | 3562 | if (vif->type != NL80211_IFTYPE_AP || !vif->p2p) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3563 | return; |
| 3564 | |
| 3565 | if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) { |
| 3566 | spin_lock_bh(&ar->data_lock); |
| 3567 | if (arvif->u.ap.noa_data) |
| 3568 | if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len, |
| 3569 | GFP_ATOMIC)) |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 3570 | skb_put_data(skb, arvif->u.ap.noa_data, |
| 3571 | arvif->u.ap.noa_len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3572 | spin_unlock_bh(&ar->data_lock); |
| 3573 | } |
| 3574 | } |
| 3575 | |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3576 | static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar, |
| 3577 | struct ieee80211_vif *vif, |
Michal Kazior | dd4717b | 2016-03-06 16:14:39 +0200 | [diff] [blame] | 3578 | struct ieee80211_txq *txq, |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 3579 | struct sk_buff *skb, u16 airtime) |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3580 | { |
| 3581 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 3582 | struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb); |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 3583 | const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 3584 | bool is_data = ieee80211_is_data(hdr->frame_control) || |
| 3585 | ieee80211_is_data_qos(hdr->frame_control); |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3586 | |
| 3587 | cb->flags = 0; |
| 3588 | if (!ath10k_tx_h_use_hwcrypto(vif, skb)) |
| 3589 | cb->flags |= ATH10K_SKB_F_NO_HWCRYPT; |
| 3590 | |
| 3591 | if (ieee80211_is_mgmt(hdr->frame_control)) |
| 3592 | cb->flags |= ATH10K_SKB_F_MGMT; |
| 3593 | |
| 3594 | if (ieee80211_is_data_qos(hdr->frame_control)) |
| 3595 | cb->flags |= ATH10K_SKB_F_QOS; |
| 3596 | |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 3597 | /* Data frames encrypted in software will be posted to firmware |
| 3598 | * with tx encap mode set to RAW. Ex: Multicast traffic generated |
| 3599 | * for a specific VLAN group will always be encrypted in software. |
| 3600 | */ |
| 3601 | if (is_data && ieee80211_has_protected(hdr->frame_control) && |
| 3602 | !info->control.hw_key) { |
| 3603 | cb->flags |= ATH10K_SKB_F_NO_HWCRYPT; |
| 3604 | cb->flags |= ATH10K_SKB_F_RAW_TX; |
| 3605 | } |
| 3606 | |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3607 | cb->vif = vif; |
Michal Kazior | dd4717b | 2016-03-06 16:14:39 +0200 | [diff] [blame] | 3608 | cb->txq = txq; |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 3609 | cb->airtime_est = airtime; |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3610 | } |
| 3611 | |
Vasanthakumar Thiagarajan | d39de99 | 2015-11-05 11:34:00 +0530 | [diff] [blame] | 3612 | bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar) |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3613 | { |
| 3614 | /* FIXME: Not really sure since when the behaviour changed. At some |
| 3615 | * point new firmware stopped requiring creation of peer entries for |
| 3616 | * offchannel tx (and actually creating them causes issues with wmi-htc |
| 3617 | * tx credit replenishment and reliability). Assuming it's at least 3.4 |
| 3618 | * because that's when the `freq` was introduced to TX_FRM HTT command. |
| 3619 | */ |
Vasanthakumar Thiagarajan | 8921f5f | 2015-11-05 11:33:59 +0530 | [diff] [blame] | 3620 | return (ar->htt.target_version_major >= 3 && |
Vasanthakumar Thiagarajan | d39de99 | 2015-11-05 11:34:00 +0530 | [diff] [blame] | 3621 | ar->htt.target_version_minor >= 4 && |
Kalle Valo | 77561f9 | 2016-04-20 19:45:47 +0300 | [diff] [blame] | 3622 | ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV); |
Michal Kazior | 8d6d362 | 2014-11-24 14:58:31 +0100 | [diff] [blame] | 3623 | } |
| 3624 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3625 | 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] | 3626 | { |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3627 | struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3628 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3629 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3630 | spin_lock_bh(&ar->data_lock); |
| 3631 | |
| 3632 | if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) { |
| 3633 | ath10k_warn(ar, "wmi mgmt tx queue is full\n"); |
| 3634 | ret = -ENOSPC; |
| 3635 | goto unlock; |
Michal Kazior | 961d4c3 | 2013-08-09 10:13:34 +0200 | [diff] [blame] | 3636 | } |
| 3637 | |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3638 | __skb_queue_tail(q, skb); |
| 3639 | ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work); |
| 3640 | |
| 3641 | unlock: |
| 3642 | spin_unlock_bh(&ar->data_lock); |
| 3643 | |
| 3644 | return ret; |
| 3645 | } |
| 3646 | |
Michal Kazior | a30c7d0 | 2016-03-06 16:14:23 +0200 | [diff] [blame] | 3647 | static enum ath10k_mac_tx_path |
| 3648 | ath10k_mac_tx_h_get_txpath(struct ath10k *ar, |
| 3649 | struct sk_buff *skb, |
| 3650 | enum ath10k_hw_txrx_mode txmode) |
| 3651 | { |
| 3652 | switch (txmode) { |
| 3653 | case ATH10K_HW_TXRX_RAW: |
| 3654 | case ATH10K_HW_TXRX_NATIVE_WIFI: |
| 3655 | case ATH10K_HW_TXRX_ETHERNET: |
| 3656 | return ATH10K_MAC_TX_HTT; |
| 3657 | case ATH10K_HW_TXRX_MGMT: |
| 3658 | if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, |
Rakesh Pillai | 229329f | 2017-12-11 19:52:52 +0530 | [diff] [blame] | 3659 | ar->running_fw->fw_file.fw_features) || |
| 3660 | test_bit(WMI_SERVICE_MGMT_TX_WMI, |
| 3661 | ar->wmi.svc_map)) |
Michal Kazior | a30c7d0 | 2016-03-06 16:14:23 +0200 | [diff] [blame] | 3662 | return ATH10K_MAC_TX_WMI_MGMT; |
| 3663 | else if (ar->htt.target_version_major >= 3) |
| 3664 | return ATH10K_MAC_TX_HTT; |
| 3665 | else |
| 3666 | return ATH10K_MAC_TX_HTT_MGMT; |
| 3667 | } |
| 3668 | |
| 3669 | return ATH10K_MAC_TX_UNKNOWN; |
| 3670 | } |
| 3671 | |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3672 | static int ath10k_mac_tx_submit(struct ath10k *ar, |
| 3673 | enum ath10k_hw_txrx_mode txmode, |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 3674 | enum ath10k_mac_tx_path txpath, |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3675 | struct sk_buff *skb) |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3676 | { |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3677 | struct ath10k_htt *htt = &ar->htt; |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 3678 | int ret = -EINVAL; |
Michal Kazior | a30c7d0 | 2016-03-06 16:14:23 +0200 | [diff] [blame] | 3679 | |
| 3680 | switch (txpath) { |
| 3681 | case ATH10K_MAC_TX_HTT: |
Erik Stromdahl | 5df6e13 | 2018-04-15 14:22:27 +0200 | [diff] [blame] | 3682 | ret = ath10k_htt_tx(htt, txmode, skb); |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3683 | break; |
Michal Kazior | a30c7d0 | 2016-03-06 16:14:23 +0200 | [diff] [blame] | 3684 | case ATH10K_MAC_TX_HTT_MGMT: |
| 3685 | ret = ath10k_htt_mgmt_tx(htt, skb); |
| 3686 | break; |
| 3687 | case ATH10K_MAC_TX_WMI_MGMT: |
| 3688 | ret = ath10k_mac_tx_wmi_mgmt(ar, skb); |
| 3689 | break; |
| 3690 | case ATH10K_MAC_TX_UNKNOWN: |
| 3691 | WARN_ON_ONCE(1); |
| 3692 | ret = -EINVAL; |
Michal Kazior | d740d8f | 2015-03-30 09:51:51 +0300 | [diff] [blame] | 3693 | break; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3694 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3695 | |
| 3696 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3697 | ath10k_warn(ar, "failed to transmit packet, dropping: %d\n", |
| 3698 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3699 | ieee80211_free_txskb(ar->hw, skb); |
| 3700 | } |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3701 | |
| 3702 | return ret; |
| 3703 | } |
| 3704 | |
| 3705 | /* This function consumes the sk_buff regardless of return value as far as |
| 3706 | * caller is concerned so no freeing is necessary afterwards. |
| 3707 | */ |
| 3708 | static int ath10k_mac_tx(struct ath10k *ar, |
| 3709 | struct ieee80211_vif *vif, |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3710 | enum ath10k_hw_txrx_mode txmode, |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 3711 | enum ath10k_mac_tx_path txpath, |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 3712 | struct sk_buff *skb, bool noque_offchan) |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3713 | { |
| 3714 | struct ieee80211_hw *hw = ar->hw; |
| 3715 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 3716 | const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb); |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3717 | int ret; |
| 3718 | |
| 3719 | /* We should disable CCK RATE due to P2P */ |
| 3720 | if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE) |
| 3721 | ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n"); |
| 3722 | |
| 3723 | switch (txmode) { |
| 3724 | case ATH10K_HW_TXRX_MGMT: |
| 3725 | case ATH10K_HW_TXRX_NATIVE_WIFI: |
| 3726 | ath10k_tx_h_nwifi(hw, skb); |
| 3727 | ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb); |
| 3728 | ath10k_tx_h_seq_no(vif, skb); |
| 3729 | break; |
| 3730 | case ATH10K_HW_TXRX_ETHERNET: |
| 3731 | ath10k_tx_h_8023(skb); |
| 3732 | break; |
| 3733 | case ATH10K_HW_TXRX_RAW: |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 3734 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) && |
| 3735 | !(skb_cb->flags & ATH10K_SKB_F_RAW_TX)) { |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3736 | WARN_ON_ONCE(1); |
| 3737 | ieee80211_free_txskb(hw, skb); |
| 3738 | return -ENOTSUPP; |
| 3739 | } |
| 3740 | } |
| 3741 | |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 3742 | if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) { |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3743 | if (!ath10k_mac_tx_frm_has_freq(ar)) { |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 3744 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n", |
| 3745 | skb, skb->len); |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3746 | |
| 3747 | skb_queue_tail(&ar->offchan_tx_queue, skb); |
| 3748 | ieee80211_queue_work(hw, &ar->offchan_tx_work); |
| 3749 | return 0; |
| 3750 | } |
| 3751 | } |
| 3752 | |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 3753 | ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb); |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3754 | if (ret) { |
| 3755 | ath10k_warn(ar, "failed to submit frame: %d\n", ret); |
| 3756 | return ret; |
| 3757 | } |
| 3758 | |
| 3759 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | void ath10k_offchan_tx_purge(struct ath10k *ar) |
| 3763 | { |
| 3764 | struct sk_buff *skb; |
| 3765 | |
| 3766 | for (;;) { |
| 3767 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 3768 | if (!skb) |
| 3769 | break; |
| 3770 | |
| 3771 | ieee80211_free_txskb(ar->hw, skb); |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | void ath10k_offchan_tx_work(struct work_struct *work) |
| 3776 | { |
| 3777 | struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work); |
| 3778 | struct ath10k_peer *peer; |
Michal Kazior | 8a93396 | 2015-11-18 06:59:17 +0100 | [diff] [blame] | 3779 | struct ath10k_vif *arvif; |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3780 | enum ath10k_hw_txrx_mode txmode; |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 3781 | enum ath10k_mac_tx_path txpath; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3782 | struct ieee80211_hdr *hdr; |
Michal Kazior | 8a93396 | 2015-11-18 06:59:17 +0100 | [diff] [blame] | 3783 | struct ieee80211_vif *vif; |
| 3784 | struct ieee80211_sta *sta; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3785 | struct sk_buff *skb; |
| 3786 | const u8 *peer_addr; |
| 3787 | int vdev_id; |
| 3788 | int ret; |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 3789 | unsigned long time_left; |
Michal Kazior | adaeed7 | 2015-08-05 12:15:23 +0200 | [diff] [blame] | 3790 | bool tmp_peer_created = false; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3791 | |
| 3792 | /* FW requirement: We must create a peer before FW will send out |
| 3793 | * an offchannel frame. Otherwise the frame will be stuck and |
| 3794 | * never transmitted. We delete the peer upon tx completion. |
| 3795 | * It is unlikely that a peer for offchannel tx will already be |
| 3796 | * present. However it may be in some rare cases so account for that. |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 3797 | * Otherwise we might remove a legitimate peer and break stuff. |
| 3798 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3799 | |
| 3800 | for (;;) { |
| 3801 | skb = skb_dequeue(&ar->offchan_tx_queue); |
| 3802 | if (!skb) |
| 3803 | break; |
| 3804 | |
| 3805 | mutex_lock(&ar->conf_mutex); |
| 3806 | |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 3807 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n", |
| 3808 | skb, skb->len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3809 | |
| 3810 | hdr = (struct ieee80211_hdr *)skb->data; |
| 3811 | peer_addr = ieee80211_get_DA(hdr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3812 | |
| 3813 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 609db22 | 2015-11-18 06:59:22 +0100 | [diff] [blame] | 3814 | vdev_id = ar->scan.vdev_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3815 | peer = ath10k_peer_find(ar, vdev_id, peer_addr); |
| 3816 | spin_unlock_bh(&ar->data_lock); |
| 3817 | |
| 3818 | if (peer) |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 3819 | /* FIXME: should this use ath10k_warn()? */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3820 | 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] | 3821 | peer_addr, vdev_id); |
| 3822 | |
| 3823 | if (!peer) { |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 3824 | ret = ath10k_peer_create(ar, NULL, NULL, vdev_id, |
| 3825 | peer_addr, |
Marek Puzyniak | 7390ed3 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 3826 | WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3827 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3828 | 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] | 3829 | peer_addr, vdev_id, ret); |
Michal Kazior | adaeed7 | 2015-08-05 12:15:23 +0200 | [diff] [blame] | 3830 | tmp_peer_created = (ret == 0); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | spin_lock_bh(&ar->data_lock); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 3834 | reinit_completion(&ar->offchan_tx_completed); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3835 | ar->offchan_tx_skb = skb; |
| 3836 | spin_unlock_bh(&ar->data_lock); |
| 3837 | |
Michal Kazior | 8a93396 | 2015-11-18 06:59:17 +0100 | [diff] [blame] | 3838 | /* It's safe to access vif and sta - conf_mutex guarantees that |
| 3839 | * sta_state() and remove_interface() are locked exclusively |
| 3840 | * out wrt to this offchannel worker. |
| 3841 | */ |
| 3842 | arvif = ath10k_get_arvif(ar, vdev_id); |
| 3843 | if (arvif) { |
| 3844 | vif = arvif->vif; |
| 3845 | sta = ieee80211_find_sta(vif, peer_addr); |
| 3846 | } else { |
| 3847 | vif = NULL; |
| 3848 | sta = NULL; |
| 3849 | } |
| 3850 | |
| 3851 | txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 3852 | txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode); |
Michal Kazior | 8a93396 | 2015-11-18 06:59:17 +0100 | [diff] [blame] | 3853 | |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 3854 | ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true); |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 3855 | if (ret) { |
| 3856 | ath10k_warn(ar, "failed to transmit offchannel frame: %d\n", |
| 3857 | ret); |
| 3858 | /* not serious */ |
| 3859 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3860 | |
Nicholas Mc Guire | 8e9904f5 | 2015-03-30 15:39:19 +0300 | [diff] [blame] | 3861 | time_left = |
| 3862 | wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ); |
| 3863 | if (time_left == 0) |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 3864 | ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n", |
| 3865 | skb, skb->len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3866 | |
Michal Kazior | adaeed7 | 2015-08-05 12:15:23 +0200 | [diff] [blame] | 3867 | if (!peer && tmp_peer_created) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 3868 | ret = ath10k_peer_delete(ar, vdev_id, peer_addr); |
| 3869 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 3870 | 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] | 3871 | peer_addr, vdev_id, ret); |
| 3872 | } |
| 3873 | |
| 3874 | mutex_unlock(&ar->conf_mutex); |
| 3875 | } |
| 3876 | } |
| 3877 | |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3878 | void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar) |
| 3879 | { |
| 3880 | struct sk_buff *skb; |
| 3881 | |
| 3882 | for (;;) { |
| 3883 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 3884 | if (!skb) |
| 3885 | break; |
| 3886 | |
| 3887 | ieee80211_free_txskb(ar->hw, skb); |
| 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work) |
| 3892 | { |
| 3893 | struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work); |
| 3894 | struct sk_buff *skb; |
Rakesh Pillai | 38a1390 | 2018-02-27 19:09:07 +0200 | [diff] [blame] | 3895 | dma_addr_t paddr; |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3896 | int ret; |
| 3897 | |
| 3898 | for (;;) { |
| 3899 | skb = skb_dequeue(&ar->wmi_mgmt_tx_queue); |
| 3900 | if (!skb) |
| 3901 | break; |
| 3902 | |
Rakesh Pillai | 38a1390 | 2018-02-27 19:09:07 +0200 | [diff] [blame] | 3903 | if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF, |
| 3904 | ar->running_fw->fw_file.fw_features)) { |
| 3905 | paddr = dma_map_single(ar->dev, skb->data, |
| 3906 | skb->len, DMA_TO_DEVICE); |
Bjorn Andersson | d43810b | 2019-10-11 11:28:17 -0700 | [diff] [blame] | 3907 | if (dma_mapping_error(ar->dev, paddr)) { |
| 3908 | ieee80211_free_txskb(ar->hw, skb); |
Rakesh Pillai | 38a1390 | 2018-02-27 19:09:07 +0200 | [diff] [blame] | 3909 | continue; |
Bjorn Andersson | d43810b | 2019-10-11 11:28:17 -0700 | [diff] [blame] | 3910 | } |
Rakesh Pillai | 38a1390 | 2018-02-27 19:09:07 +0200 | [diff] [blame] | 3911 | ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr); |
| 3912 | if (ret) { |
| 3913 | ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n", |
| 3914 | ret); |
| 3915 | dma_unmap_single(ar->dev, paddr, skb->len, |
Rakesh Pillai | 6e8a899 | 2019-01-25 09:51:06 +0530 | [diff] [blame] | 3916 | DMA_TO_DEVICE); |
Rakesh Pillai | 38a1390 | 2018-02-27 19:09:07 +0200 | [diff] [blame] | 3917 | ieee80211_free_txskb(ar->hw, skb); |
| 3918 | } |
| 3919 | } else { |
| 3920 | ret = ath10k_wmi_mgmt_tx(ar, skb); |
| 3921 | if (ret) { |
| 3922 | ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n", |
| 3923 | ret); |
| 3924 | ieee80211_free_txskb(ar->hw, skb); |
| 3925 | } |
Michal Kazior | 5fb5e41 | 2013-10-28 07:18:13 +0100 | [diff] [blame] | 3926 | } |
Bartosz Markowski | 5e00d31 | 2013-09-26 17:47:12 +0200 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3930 | static void ath10k_mac_txq_init(struct ieee80211_txq *txq) |
| 3931 | { |
Bob Copeland | a66cd73 | 2016-06-29 19:29:25 +0300 | [diff] [blame] | 3932 | struct ath10k_txq *artxq; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3933 | |
| 3934 | if (!txq) |
| 3935 | return; |
| 3936 | |
Bob Copeland | a66cd73 | 2016-06-29 19:29:25 +0300 | [diff] [blame] | 3937 | artxq = (void *)txq->drv_priv; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3938 | INIT_LIST_HEAD(&artxq->list); |
| 3939 | } |
| 3940 | |
| 3941 | static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq) |
| 3942 | { |
Michal Kazior | dd4717b | 2016-03-06 16:14:39 +0200 | [diff] [blame] | 3943 | struct ath10k_skb_cb *cb; |
| 3944 | struct sk_buff *msdu; |
| 3945 | int msdu_id; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3946 | |
| 3947 | if (!txq) |
| 3948 | return; |
| 3949 | |
Michal Kazior | dd4717b | 2016-03-06 16:14:39 +0200 | [diff] [blame] | 3950 | spin_lock_bh(&ar->htt.tx_lock); |
| 3951 | idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) { |
| 3952 | cb = ATH10K_SKB_CB(msdu); |
| 3953 | if (cb->txq == txq) |
| 3954 | cb->txq = NULL; |
| 3955 | } |
| 3956 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3957 | } |
| 3958 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 3959 | struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar, |
| 3960 | u16 peer_id, |
| 3961 | u8 tid) |
| 3962 | { |
| 3963 | struct ath10k_peer *peer; |
| 3964 | |
| 3965 | lockdep_assert_held(&ar->data_lock); |
| 3966 | |
| 3967 | peer = ar->peer_map[peer_id]; |
| 3968 | if (!peer) |
| 3969 | return NULL; |
| 3970 | |
Michal Kazior | 0a744d9 | 2017-01-12 16:14:30 +0100 | [diff] [blame] | 3971 | if (peer->removed) |
| 3972 | return NULL; |
| 3973 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 3974 | if (peer->sta) |
| 3975 | return peer->sta->txq[tid]; |
| 3976 | else if (peer->vif) |
| 3977 | return peer->vif->txq; |
| 3978 | else |
| 3979 | return NULL; |
| 3980 | } |
| 3981 | |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3982 | static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw, |
| 3983 | struct ieee80211_txq *txq) |
| 3984 | { |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 3985 | struct ath10k *ar = hw->priv; |
| 3986 | struct ath10k_txq *artxq = (void *)txq->drv_priv; |
| 3987 | |
| 3988 | /* No need to get locks */ |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 3989 | if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH) |
| 3990 | return true; |
| 3991 | |
| 3992 | if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed) |
| 3993 | return true; |
| 3994 | |
| 3995 | if (artxq->num_fw_queued < artxq->num_push_allowed) |
| 3996 | return true; |
| 3997 | |
| 3998 | return false; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 3999 | } |
| 4000 | |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 4001 | /* Return estimated airtime in microsecond, which is calculated using last |
| 4002 | * reported TX rate. This is just a rough estimation because host driver has no |
| 4003 | * knowledge of the actual transmit rate, retries or aggregation. If actual |
| 4004 | * airtime can be reported by firmware, then delta between estimated and actual |
| 4005 | * airtime can be adjusted from deficit. |
| 4006 | */ |
| 4007 | #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */ |
| 4008 | #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */ |
| 4009 | static u16 ath10k_mac_update_airtime(struct ath10k *ar, |
| 4010 | struct ieee80211_txq *txq, |
| 4011 | struct sk_buff *skb) |
| 4012 | { |
| 4013 | struct ath10k_sta *arsta; |
| 4014 | u32 pktlen; |
| 4015 | u16 airtime = 0; |
| 4016 | |
| 4017 | if (!txq || !txq->sta) |
| 4018 | return airtime; |
| 4019 | |
Manikanta Pubbisetty | bb31b7c | 2019-02-11 18:47:59 +0200 | [diff] [blame] | 4020 | if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map)) |
| 4021 | return airtime; |
| 4022 | |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 4023 | spin_lock_bh(&ar->data_lock); |
| 4024 | arsta = (struct ath10k_sta *)txq->sta->drv_priv; |
| 4025 | |
| 4026 | pktlen = skb->len + 38; /* Assume MAC header 30, SNAP 8 for most case */ |
| 4027 | if (arsta->last_tx_bitrate) { |
| 4028 | /* airtime in us, last_tx_bitrate in 100kbps */ |
| 4029 | airtime = (pktlen * 8 * (1000 / 100)) |
| 4030 | / arsta->last_tx_bitrate; |
| 4031 | /* overhead for media access time and IFS */ |
| 4032 | airtime += IEEE80211_ATF_OVERHEAD_IFS; |
| 4033 | } else { |
| 4034 | /* This is mostly for throttle excessive BC/MC frames, and the |
| 4035 | * airtime/rate doesn't need be exact. Airtime of BC/MC frames |
| 4036 | * in 2G get some discount, which helps prevent very low rate |
| 4037 | * frames from being blocked for too long. |
| 4038 | */ |
| 4039 | airtime = (pktlen * 8 * (1000 / 100)) / 60; /* 6M */ |
| 4040 | airtime += IEEE80211_ATF_OVERHEAD; |
| 4041 | } |
| 4042 | spin_unlock_bh(&ar->data_lock); |
| 4043 | |
| 4044 | return airtime; |
| 4045 | } |
| 4046 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 4047 | int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, |
| 4048 | struct ieee80211_txq *txq) |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4049 | { |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4050 | struct ath10k *ar = hw->priv; |
| 4051 | struct ath10k_htt *htt = &ar->htt; |
Michal Kazior | 3cc0fef | 2016-03-06 16:14:41 +0200 | [diff] [blame] | 4052 | struct ath10k_txq *artxq = (void *)txq->drv_priv; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4053 | struct ieee80211_vif *vif = txq->vif; |
| 4054 | struct ieee80211_sta *sta = txq->sta; |
| 4055 | enum ath10k_hw_txrx_mode txmode; |
| 4056 | enum ath10k_mac_tx_path txpath; |
| 4057 | struct sk_buff *skb; |
Ashok Raj Nagarajan | e4fd726 | 2016-08-18 15:30:04 +0530 | [diff] [blame] | 4058 | struct ieee80211_hdr *hdr; |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 4059 | size_t skb_len; |
Ashok Raj Nagarajan | e4fd726 | 2016-08-18 15:30:04 +0530 | [diff] [blame] | 4060 | bool is_mgmt, is_presp; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4061 | int ret; |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 4062 | u16 airtime; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4063 | |
| 4064 | spin_lock_bh(&ar->htt.tx_lock); |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4065 | ret = ath10k_htt_tx_inc_pending(htt); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4066 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4067 | |
| 4068 | if (ret) |
| 4069 | return ret; |
| 4070 | |
Erik Stromdahl | 3065476 | 2019-06-17 22:01:40 +0200 | [diff] [blame] | 4071 | skb = ieee80211_tx_dequeue_ni(hw, txq); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4072 | if (!skb) { |
| 4073 | spin_lock_bh(&ar->htt.tx_lock); |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4074 | ath10k_htt_tx_dec_pending(htt); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4075 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4076 | |
| 4077 | return -ENOENT; |
| 4078 | } |
| 4079 | |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 4080 | airtime = ath10k_mac_update_airtime(ar, txq, skb); |
| 4081 | ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb, airtime); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4082 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 4083 | skb_len = skb->len; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4084 | txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb); |
| 4085 | txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode); |
Ashok Raj Nagarajan | e4fd726 | 2016-08-18 15:30:04 +0530 | [diff] [blame] | 4086 | is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT); |
| 4087 | |
| 4088 | if (is_mgmt) { |
| 4089 | hdr = (struct ieee80211_hdr *)skb->data; |
| 4090 | is_presp = ieee80211_is_probe_resp(hdr->frame_control); |
| 4091 | |
| 4092 | spin_lock_bh(&ar->htt.tx_lock); |
| 4093 | ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp); |
| 4094 | |
| 4095 | if (ret) { |
| 4096 | ath10k_htt_tx_dec_pending(htt); |
| 4097 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4098 | return ret; |
| 4099 | } |
| 4100 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4101 | } |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4102 | |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 4103 | ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4104 | if (unlikely(ret)) { |
| 4105 | ath10k_warn(ar, "failed to push frame: %d\n", ret); |
| 4106 | |
| 4107 | spin_lock_bh(&ar->htt.tx_lock); |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4108 | ath10k_htt_tx_dec_pending(htt); |
Ashok Raj Nagarajan | e4fd726 | 2016-08-18 15:30:04 +0530 | [diff] [blame] | 4109 | if (is_mgmt) |
| 4110 | ath10k_htt_tx_mgmt_dec_pending(htt); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4111 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4112 | |
| 4113 | return ret; |
| 4114 | } |
| 4115 | |
Michal Kazior | 3cc0fef | 2016-03-06 16:14:41 +0200 | [diff] [blame] | 4116 | spin_lock_bh(&ar->htt.tx_lock); |
| 4117 | artxq->num_fw_queued++; |
| 4118 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4119 | |
Michal Kazior | 426e10e | 2016-03-06 16:14:43 +0200 | [diff] [blame] | 4120 | return skb_len; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4121 | } |
| 4122 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4123 | static int ath10k_mac_schedule_txq(struct ieee80211_hw *hw, u32 ac) |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4124 | { |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4125 | struct ieee80211_txq *txq; |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4126 | int ret = 0; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4127 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4128 | ieee80211_txq_schedule_start(hw, ac); |
| 4129 | while ((txq = ieee80211_next_txq(hw, ac))) { |
| 4130 | while (ath10k_mac_tx_can_push(hw, txq)) { |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4131 | ret = ath10k_mac_tx_push_txq(hw, txq); |
| 4132 | if (ret < 0) |
| 4133 | break; |
| 4134 | } |
Felix Fietkau | 2b4a669 | 2019-03-18 12:00:58 +0100 | [diff] [blame] | 4135 | ieee80211_return_txq(hw, txq, false); |
Michal Kazior | c1a43d9 | 2016-03-06 16:14:36 +0200 | [diff] [blame] | 4136 | ath10k_htt_tx_txq_update(hw, txq); |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4137 | if (ret == -EBUSY) |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4138 | break; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4139 | } |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4140 | ieee80211_txq_schedule_end(hw, ac); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4141 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4142 | return ret; |
| 4143 | } |
| 4144 | |
| 4145 | void ath10k_mac_tx_push_pending(struct ath10k *ar) |
| 4146 | { |
| 4147 | struct ieee80211_hw *hw = ar->hw; |
| 4148 | u32 ac; |
| 4149 | |
| 4150 | if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH) |
| 4151 | return; |
| 4152 | |
| 4153 | if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2)) |
| 4154 | return; |
| 4155 | |
| 4156 | rcu_read_lock(); |
| 4157 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 4158 | if (ath10k_mac_schedule_txq(hw, ac) == -EBUSY) |
| 4159 | break; |
| 4160 | } |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4161 | rcu_read_unlock(); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4162 | } |
Niklas Cassel | 3f04950 | 2018-06-18 17:00:49 +0300 | [diff] [blame] | 4163 | EXPORT_SYMBOL(ath10k_mac_tx_push_pending); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4164 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4165 | /************/ |
| 4166 | /* Scanning */ |
| 4167 | /************/ |
| 4168 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4169 | void __ath10k_scan_finish(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4170 | { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4171 | lockdep_assert_held(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4172 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4173 | switch (ar->scan.state) { |
| 4174 | case ATH10K_SCAN_IDLE: |
| 4175 | break; |
| 4176 | case ATH10K_SCAN_RUNNING: |
Michal Kazior | 7305d3e | 2014-11-24 14:58:33 +0100 | [diff] [blame] | 4177 | case ATH10K_SCAN_ABORTING: |
Avraham Stern | 7947d3e | 2016-07-05 15:23:12 +0300 | [diff] [blame] | 4178 | if (!ar->scan.is_roc) { |
| 4179 | struct cfg80211_scan_info info = { |
| 4180 | .aborted = (ar->scan.state == |
| 4181 | ATH10K_SCAN_ABORTING), |
| 4182 | }; |
| 4183 | |
| 4184 | ieee80211_scan_completed(ar->hw, &info); |
| 4185 | } else if (ar->scan.roc_notify) { |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 4186 | ieee80211_remain_on_channel_expired(ar->hw); |
Avraham Stern | 7947d3e | 2016-07-05 15:23:12 +0300 | [diff] [blame] | 4187 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4188 | /* fall through */ |
| 4189 | case ATH10K_SCAN_STARTING: |
| 4190 | ar->scan.state = ATH10K_SCAN_IDLE; |
| 4191 | ar->scan_channel = NULL; |
Michal Kazior | bd87744 | 2015-11-18 06:59:19 +0100 | [diff] [blame] | 4192 | ar->scan.roc_freq = 0; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4193 | ath10k_offchan_tx_purge(ar); |
| 4194 | cancel_delayed_work(&ar->scan.timeout); |
Daniel Wagner | 881ed54 | 2016-08-18 15:12:06 +0200 | [diff] [blame] | 4195 | complete(&ar->scan.completed); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4196 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4197 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4198 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4199 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4200 | void ath10k_scan_finish(struct ath10k *ar) |
| 4201 | { |
| 4202 | spin_lock_bh(&ar->data_lock); |
| 4203 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4204 | spin_unlock_bh(&ar->data_lock); |
| 4205 | } |
| 4206 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4207 | static int ath10k_scan_stop(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4208 | { |
| 4209 | struct wmi_stop_scan_arg arg = { |
| 4210 | .req_id = 1, /* FIXME */ |
| 4211 | .req_type = WMI_SCAN_STOP_ONE, |
| 4212 | .u.scan_id = ATH10K_SCAN_ID, |
| 4213 | }; |
| 4214 | int ret; |
| 4215 | |
| 4216 | lockdep_assert_held(&ar->conf_mutex); |
| 4217 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4218 | ret = ath10k_wmi_stop_scan(ar, &arg); |
| 4219 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4220 | ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4221 | goto out; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4222 | } |
| 4223 | |
Kalle Valo | 14e105c | 2016-04-13 14:13:21 +0300 | [diff] [blame] | 4224 | ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4225 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4226 | ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4227 | ret = -ETIMEDOUT; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4228 | } else if (ret > 0) { |
| 4229 | ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4230 | } |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4231 | |
| 4232 | out: |
| 4233 | /* Scan state should be updated upon scan completion but in case |
| 4234 | * firmware fails to deliver the event (for whatever reason) it is |
| 4235 | * desired to clean up scan state anyway. Firmware may have just |
| 4236 | * dropped the scan completion event delivery due to transport pipe |
| 4237 | * being overflown with data and/or it can recover on its own before |
| 4238 | * next scan request is submitted. |
| 4239 | */ |
| 4240 | spin_lock_bh(&ar->data_lock); |
| 4241 | if (ar->scan.state != ATH10K_SCAN_IDLE) |
| 4242 | __ath10k_scan_finish(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4243 | spin_unlock_bh(&ar->data_lock); |
| 4244 | |
| 4245 | return ret; |
| 4246 | } |
| 4247 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4248 | static void ath10k_scan_abort(struct ath10k *ar) |
| 4249 | { |
| 4250 | int ret; |
| 4251 | |
| 4252 | lockdep_assert_held(&ar->conf_mutex); |
| 4253 | |
| 4254 | spin_lock_bh(&ar->data_lock); |
| 4255 | |
| 4256 | switch (ar->scan.state) { |
| 4257 | case ATH10K_SCAN_IDLE: |
| 4258 | /* This can happen if timeout worker kicked in and called |
| 4259 | * abortion while scan completion was being processed. |
| 4260 | */ |
| 4261 | break; |
| 4262 | case ATH10K_SCAN_STARTING: |
| 4263 | case ATH10K_SCAN_ABORTING: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4264 | 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] | 4265 | ath10k_scan_state_str(ar->scan.state), |
| 4266 | ar->scan.state); |
| 4267 | break; |
| 4268 | case ATH10K_SCAN_RUNNING: |
| 4269 | ar->scan.state = ATH10K_SCAN_ABORTING; |
| 4270 | spin_unlock_bh(&ar->data_lock); |
| 4271 | |
| 4272 | ret = ath10k_scan_stop(ar); |
| 4273 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4274 | ath10k_warn(ar, "failed to abort scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4275 | |
| 4276 | spin_lock_bh(&ar->data_lock); |
| 4277 | break; |
| 4278 | } |
| 4279 | |
| 4280 | spin_unlock_bh(&ar->data_lock); |
| 4281 | } |
| 4282 | |
| 4283 | void ath10k_scan_timeout_work(struct work_struct *work) |
| 4284 | { |
| 4285 | struct ath10k *ar = container_of(work, struct ath10k, |
| 4286 | scan.timeout.work); |
| 4287 | |
| 4288 | mutex_lock(&ar->conf_mutex); |
| 4289 | ath10k_scan_abort(ar); |
| 4290 | mutex_unlock(&ar->conf_mutex); |
| 4291 | } |
| 4292 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4293 | static int ath10k_start_scan(struct ath10k *ar, |
| 4294 | const struct wmi_start_scan_arg *arg) |
| 4295 | { |
| 4296 | int ret; |
| 4297 | |
| 4298 | lockdep_assert_held(&ar->conf_mutex); |
| 4299 | |
| 4300 | ret = ath10k_wmi_start_scan(ar, arg); |
| 4301 | if (ret) |
| 4302 | return ret; |
| 4303 | |
Kalle Valo | 14e105c | 2016-04-13 14:13:21 +0300 | [diff] [blame] | 4304 | ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4305 | if (ret == 0) { |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4306 | ret = ath10k_scan_stop(ar); |
| 4307 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4308 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4309 | |
| 4310 | return -ETIMEDOUT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4311 | } |
| 4312 | |
Ben Greear | 2f9eec0 | 2015-02-15 16:50:38 +0200 | [diff] [blame] | 4313 | /* If we failed to start the scan, return error code at |
| 4314 | * this point. This is probably due to some issue in the |
| 4315 | * firmware, but no need to wedge the driver due to that... |
| 4316 | */ |
| 4317 | spin_lock_bh(&ar->data_lock); |
| 4318 | if (ar->scan.state == ATH10K_SCAN_IDLE) { |
| 4319 | spin_unlock_bh(&ar->data_lock); |
| 4320 | return -EINVAL; |
| 4321 | } |
| 4322 | spin_unlock_bh(&ar->data_lock); |
| 4323 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4324 | return 0; |
| 4325 | } |
| 4326 | |
| 4327 | /**********************/ |
| 4328 | /* mac80211 callbacks */ |
| 4329 | /**********************/ |
| 4330 | |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 4331 | static void ath10k_mac_op_tx(struct ieee80211_hw *hw, |
| 4332 | struct ieee80211_tx_control *control, |
| 4333 | struct sk_buff *skb) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4334 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4335 | struct ath10k *ar = hw->priv; |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4336 | struct ath10k_htt *htt = &ar->htt; |
Michal Kazior | 4b60455 | 2014-07-21 21:03:09 +0300 | [diff] [blame] | 4337 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 4338 | struct ieee80211_vif *vif = info->control.vif; |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 4339 | struct ieee80211_sta *sta = control->sta; |
Michal Kazior | dd4717b | 2016-03-06 16:14:39 +0200 | [diff] [blame] | 4340 | struct ieee80211_txq *txq = NULL; |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4341 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Michal Kazior | 8a93396 | 2015-11-18 06:59:17 +0100 | [diff] [blame] | 4342 | enum ath10k_hw_txrx_mode txmode; |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4343 | enum ath10k_mac_tx_path txpath; |
| 4344 | bool is_htt; |
| 4345 | bool is_mgmt; |
| 4346 | bool is_presp; |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 4347 | int ret; |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 4348 | u16 airtime; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4349 | |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 4350 | airtime = ath10k_mac_update_airtime(ar, txq, skb); |
| 4351 | ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb, airtime); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4352 | |
Michal Kazior | 8a93396 | 2015-11-18 06:59:17 +0100 | [diff] [blame] | 4353 | txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4354 | txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode); |
| 4355 | is_htt = (txpath == ATH10K_MAC_TX_HTT || |
| 4356 | txpath == ATH10K_MAC_TX_HTT_MGMT); |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4357 | is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4358 | |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4359 | if (is_htt) { |
| 4360 | spin_lock_bh(&ar->htt.tx_lock); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4361 | is_presp = ieee80211_is_probe_resp(hdr->frame_control); |
| 4362 | |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4363 | ret = ath10k_htt_tx_inc_pending(htt); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4364 | if (ret) { |
| 4365 | ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n", |
| 4366 | ret); |
| 4367 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4368 | ieee80211_free_txskb(ar->hw, skb); |
| 4369 | return; |
| 4370 | } |
| 4371 | |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4372 | ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp); |
| 4373 | if (ret) { |
Rajkumar Manoharan | dd7c280 | 2016-04-07 12:07:30 +0530 | [diff] [blame] | 4374 | ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n", |
| 4375 | ret); |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4376 | ath10k_htt_tx_dec_pending(htt); |
| 4377 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4378 | ieee80211_free_txskb(ar->hw, skb); |
| 4379 | return; |
| 4380 | } |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4381 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4382 | } |
| 4383 | |
Ben Greear | cc6df01 | 2017-10-17 17:03:12 -0700 | [diff] [blame] | 4384 | ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4385 | if (ret) { |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 4386 | ath10k_warn(ar, "failed to transmit frame: %d\n", ret); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4387 | if (is_htt) { |
| 4388 | spin_lock_bh(&ar->htt.tx_lock); |
Rajkumar Manoharan | cac0855 | 2016-03-09 20:25:46 +0530 | [diff] [blame] | 4389 | ath10k_htt_tx_dec_pending(htt); |
| 4390 | if (is_mgmt) |
| 4391 | ath10k_htt_tx_mgmt_dec_pending(htt); |
Michal Kazior | 6421969f | 2016-03-06 16:14:25 +0200 | [diff] [blame] | 4392 | spin_unlock_bh(&ar->htt.tx_lock); |
| 4393 | } |
| 4394 | return; |
| 4395 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4396 | } |
| 4397 | |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4398 | static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw, |
| 4399 | struct ieee80211_txq *txq) |
| 4400 | { |
| 4401 | struct ath10k *ar = hw->priv; |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4402 | int ret; |
| 4403 | u8 ac; |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4404 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4405 | ath10k_htt_tx_txq_update(hw, txq); |
| 4406 | if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH) |
| 4407 | return; |
Rajkumar Manoharan | 83e164b | 2016-08-17 21:02:53 +0530 | [diff] [blame] | 4408 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4409 | ac = txq->ac; |
| 4410 | ieee80211_txq_schedule_start(hw, ac); |
| 4411 | txq = ieee80211_next_txq(hw, ac); |
| 4412 | if (!txq) |
| 4413 | goto out; |
Rajkumar Manoharan | 83e164b | 2016-08-17 21:02:53 +0530 | [diff] [blame] | 4414 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4415 | while (ath10k_mac_tx_can_push(hw, txq)) { |
| 4416 | ret = ath10k_mac_tx_push_txq(hw, txq); |
Erik Stromdahl | e3148cc | 2018-05-06 15:25:00 +0200 | [diff] [blame] | 4417 | if (ret < 0) |
Rajkumar Manoharan | 83e164b | 2016-08-17 21:02:53 +0530 | [diff] [blame] | 4418 | break; |
| 4419 | } |
Felix Fietkau | 2b4a669 | 2019-03-18 12:00:58 +0100 | [diff] [blame] | 4420 | ieee80211_return_txq(hw, txq, false); |
Michal Kazior | c1a43d9 | 2016-03-06 16:14:36 +0200 | [diff] [blame] | 4421 | ath10k_htt_tx_txq_update(hw, txq); |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 4422 | out: |
| 4423 | ieee80211_txq_schedule_end(hw, ac); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 4424 | } |
| 4425 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 4426 | /* 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] | 4427 | void ath10k_drain_tx(struct ath10k *ar) |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 4428 | { |
| 4429 | /* make sure rcu-protected mac80211 tx path itself is drained */ |
| 4430 | synchronize_net(); |
| 4431 | |
| 4432 | ath10k_offchan_tx_purge(ar); |
| 4433 | ath10k_mgmt_over_wmi_tx_purge(ar); |
| 4434 | |
| 4435 | cancel_work_sync(&ar->offchan_tx_work); |
| 4436 | cancel_work_sync(&ar->wmi_mgmt_tx_work); |
| 4437 | } |
| 4438 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 4439 | void ath10k_halt(struct ath10k *ar) |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4440 | { |
Michal Kazior | d9bc4b9 | 2014-04-23 19:30:06 +0300 | [diff] [blame] | 4441 | struct ath10k_vif *arvif; |
| 4442 | |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4443 | lockdep_assert_held(&ar->conf_mutex); |
| 4444 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 4445 | clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags); |
| 4446 | ar->filter_flags = 0; |
| 4447 | ar->monitor = false; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 4448 | ar->monitor_arvif = NULL; |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 4449 | |
| 4450 | if (ar->monitor_started) |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 4451 | ath10k_monitor_stop(ar); |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 4452 | |
| 4453 | ar->monitor_started = false; |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 4454 | ar->tx_paused = 0; |
Michal Kazior | 1bbc097 | 2014-04-08 09:45:47 +0300 | [diff] [blame] | 4455 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 4456 | ath10k_scan_finish(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4457 | ath10k_peer_cleanup_all(ar); |
Sriram R | 6f6eb1b | 2018-05-15 14:39:49 +0530 | [diff] [blame] | 4458 | ath10k_stop_radar_confirmation(ar); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4459 | ath10k_core_stop(ar); |
| 4460 | ath10k_hif_power_down(ar); |
| 4461 | |
| 4462 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 4463 | list_for_each_entry(arvif, &ar->arvifs, list) |
| 4464 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4465 | spin_unlock_bh(&ar->data_lock); |
| 4466 | } |
| 4467 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 4468 | static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 4469 | { |
| 4470 | struct ath10k *ar = hw->priv; |
| 4471 | |
| 4472 | mutex_lock(&ar->conf_mutex); |
| 4473 | |
Rajkumar Manoharan | 166de3f | 2015-10-27 17:51:11 +0530 | [diff] [blame] | 4474 | *tx_ant = ar->cfg_tx_chainmask; |
| 4475 | *rx_ant = ar->cfg_rx_chainmask; |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 4476 | |
| 4477 | mutex_unlock(&ar->conf_mutex); |
| 4478 | |
| 4479 | return 0; |
| 4480 | } |
| 4481 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4482 | static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg) |
| 4483 | { |
| 4484 | /* It is not clear that allowing gaps in chainmask |
| 4485 | * is helpful. Probably it will not do what user |
| 4486 | * is hoping for, so warn in that case. |
| 4487 | */ |
| 4488 | if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0) |
| 4489 | return; |
| 4490 | |
| 4491 | ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n", |
| 4492 | dbg, cm); |
| 4493 | } |
| 4494 | |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4495 | static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar) |
| 4496 | { |
| 4497 | int nsts = ar->vht_cap_info; |
| 4498 | |
| 4499 | nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 4500 | nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; |
| 4501 | |
| 4502 | /* If firmware does not deliver to host number of space-time |
| 4503 | * streams supported, assume it support up to 4 BF STS and return |
| 4504 | * the value for VHT CAP: nsts-1) |
| 4505 | */ |
| 4506 | if (nsts == 0) |
| 4507 | return 3; |
| 4508 | |
| 4509 | return nsts; |
| 4510 | } |
| 4511 | |
| 4512 | static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar) |
| 4513 | { |
| 4514 | int sound_dim = ar->vht_cap_info; |
| 4515 | |
| 4516 | sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; |
| 4517 | sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; |
| 4518 | |
| 4519 | /* If the sounding dimension is not advertised by the firmware, |
| 4520 | * let's use a default value of 1 |
| 4521 | */ |
| 4522 | if (sound_dim == 0) |
| 4523 | return 1; |
| 4524 | |
| 4525 | return sound_dim; |
| 4526 | } |
| 4527 | |
| 4528 | static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar) |
| 4529 | { |
| 4530 | struct ieee80211_sta_vht_cap vht_cap = {0}; |
Ben Greear | cc914a5 | 2017-06-16 10:37:45 +0300 | [diff] [blame] | 4531 | struct ath10k_hw_params *hw = &ar->hw_params; |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4532 | u16 mcs_map; |
| 4533 | u32 val; |
| 4534 | int i; |
| 4535 | |
| 4536 | vht_cap.vht_supported = 1; |
| 4537 | vht_cap.cap = ar->vht_cap_info; |
| 4538 | |
| 4539 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 4540 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) { |
| 4541 | val = ath10k_mac_get_vht_cap_bf_sts(ar); |
| 4542 | val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT; |
| 4543 | val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK; |
| 4544 | |
| 4545 | vht_cap.cap |= val; |
| 4546 | } |
| 4547 | |
| 4548 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 4549 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { |
| 4550 | val = ath10k_mac_get_vht_cap_bf_sound_dim(ar); |
| 4551 | val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; |
| 4552 | val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; |
| 4553 | |
| 4554 | vht_cap.cap |= val; |
| 4555 | } |
| 4556 | |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 4557 | /* Currently the firmware seems to be buggy, don't enable 80+80 |
| 4558 | * mode until that's resolved. |
| 4559 | */ |
| 4560 | if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) && |
Ben Greear | e509e59 | 2017-06-16 10:37:44 +0300 | [diff] [blame] | 4561 | (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0) |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 4562 | vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 4563 | |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4564 | mcs_map = 0; |
| 4565 | for (i = 0; i < 8; i++) { |
| 4566 | if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i))) |
| 4567 | mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2); |
| 4568 | else |
| 4569 | mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2); |
| 4570 | } |
| 4571 | |
Mohammed Shafi Shajakhan | 3466324 | 2016-06-29 19:29:27 +0300 | [diff] [blame] | 4572 | if (ar->cfg_tx_chainmask <= 1) |
| 4573 | vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC; |
| 4574 | |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4575 | vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 4576 | vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 4577 | |
Ben Greear | cc914a5 | 2017-06-16 10:37:45 +0300 | [diff] [blame] | 4578 | /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do |
| 4579 | * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give |
| 4580 | * user-space a clue if that is the case. |
| 4581 | */ |
| 4582 | if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) && |
| 4583 | (hw->vht160_mcs_rx_highest != 0 || |
| 4584 | hw->vht160_mcs_tx_highest != 0)) { |
| 4585 | vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest); |
| 4586 | vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest); |
| 4587 | } |
| 4588 | |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4589 | return vht_cap; |
| 4590 | } |
| 4591 | |
| 4592 | static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar) |
| 4593 | { |
| 4594 | int i; |
| 4595 | struct ieee80211_sta_ht_cap ht_cap = {0}; |
| 4596 | |
| 4597 | if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED)) |
| 4598 | return ht_cap; |
| 4599 | |
| 4600 | ht_cap.ht_supported = 1; |
| 4601 | ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 4602 | ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8; |
| 4603 | ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 4604 | ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40; |
Peter Oh | e33a99e | 2015-12-31 15:26:20 +0200 | [diff] [blame] | 4605 | ht_cap.cap |= |
| 4606 | WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT; |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4607 | |
| 4608 | if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI) |
| 4609 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_20; |
| 4610 | |
| 4611 | if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI) |
| 4612 | ht_cap.cap |= IEEE80211_HT_CAP_SGI_40; |
| 4613 | |
| 4614 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) { |
| 4615 | u32 smps; |
| 4616 | |
| 4617 | smps = WLAN_HT_CAP_SM_PS_DYNAMIC; |
| 4618 | smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 4619 | |
| 4620 | ht_cap.cap |= smps; |
| 4621 | } |
| 4622 | |
Mohammed Shafi Shajakhan | 3466324 | 2016-06-29 19:29:27 +0300 | [diff] [blame] | 4623 | if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1)) |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4624 | ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC; |
| 4625 | |
| 4626 | if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) { |
| 4627 | u32 stbc; |
| 4628 | |
| 4629 | stbc = ar->ht_cap_info; |
| 4630 | stbc &= WMI_HT_CAP_RX_STBC; |
| 4631 | stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT; |
| 4632 | stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT; |
| 4633 | stbc &= IEEE80211_HT_CAP_RX_STBC; |
| 4634 | |
| 4635 | ht_cap.cap |= stbc; |
| 4636 | } |
| 4637 | |
Surabhi Vishnoi | ff488d0 | 2019-02-01 11:04:22 +0530 | [diff] [blame] | 4638 | if (ar->ht_cap_info & WMI_HT_CAP_LDPC || (ar->ht_cap_info & |
| 4639 | WMI_HT_CAP_RX_LDPC && (ar->ht_cap_info & WMI_HT_CAP_TX_LDPC))) |
Rajkumar Manoharan | f58512f | 2015-10-27 17:51:13 +0530 | [diff] [blame] | 4640 | ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; |
| 4641 | |
| 4642 | if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT) |
| 4643 | ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT; |
| 4644 | |
| 4645 | /* max AMSDU is implicitly taken from vht_cap_info */ |
| 4646 | if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK) |
| 4647 | ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU; |
| 4648 | |
| 4649 | for (i = 0; i < ar->num_rf_chains; i++) { |
| 4650 | if (ar->cfg_rx_chainmask & BIT(i)) |
| 4651 | ht_cap.mcs.rx_mask[i] = 0xFF; |
| 4652 | } |
| 4653 | |
| 4654 | ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED; |
| 4655 | |
| 4656 | return ht_cap; |
| 4657 | } |
| 4658 | |
Rajkumar Manoharan | 5036fe0 | 2015-10-27 17:51:14 +0530 | [diff] [blame] | 4659 | static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar) |
| 4660 | { |
| 4661 | struct ieee80211_supported_band *band; |
| 4662 | struct ieee80211_sta_vht_cap vht_cap; |
| 4663 | struct ieee80211_sta_ht_cap ht_cap; |
| 4664 | |
| 4665 | ht_cap = ath10k_get_ht_cap(ar); |
| 4666 | vht_cap = ath10k_create_vht_cap(ar); |
| 4667 | |
| 4668 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 4669 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
Rajkumar Manoharan | 5036fe0 | 2015-10-27 17:51:14 +0530 | [diff] [blame] | 4670 | band->ht_cap = ht_cap; |
Rajkumar Manoharan | 5036fe0 | 2015-10-27 17:51:14 +0530 | [diff] [blame] | 4671 | } |
| 4672 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 4673 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; |
Rajkumar Manoharan | 5036fe0 | 2015-10-27 17:51:14 +0530 | [diff] [blame] | 4674 | band->ht_cap = ht_cap; |
| 4675 | band->vht_cap = vht_cap; |
| 4676 | } |
| 4677 | } |
| 4678 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 4679 | static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant) |
| 4680 | { |
| 4681 | int ret; |
| 4682 | |
| 4683 | lockdep_assert_held(&ar->conf_mutex); |
| 4684 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 4685 | ath10k_check_chain_mask(ar, tx_ant, "tx"); |
| 4686 | ath10k_check_chain_mask(ar, rx_ant, "rx"); |
| 4687 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 4688 | ar->cfg_tx_chainmask = tx_ant; |
| 4689 | ar->cfg_rx_chainmask = rx_ant; |
| 4690 | |
| 4691 | if ((ar->state != ATH10K_STATE_ON) && |
| 4692 | (ar->state != ATH10K_STATE_RESTARTED)) |
| 4693 | return 0; |
| 4694 | |
| 4695 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask, |
| 4696 | tx_ant); |
| 4697 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4698 | 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] | 4699 | ret, tx_ant); |
| 4700 | return ret; |
| 4701 | } |
| 4702 | |
| 4703 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask, |
| 4704 | rx_ant); |
| 4705 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4706 | 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] | 4707 | ret, rx_ant); |
| 4708 | return ret; |
| 4709 | } |
| 4710 | |
Rajkumar Manoharan | 5036fe0 | 2015-10-27 17:51:14 +0530 | [diff] [blame] | 4711 | /* Reload HT/VHT capability */ |
| 4712 | ath10k_mac_setup_ht_vht_cap(ar); |
| 4713 | |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 4714 | return 0; |
| 4715 | } |
| 4716 | |
| 4717 | static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 4718 | { |
| 4719 | struct ath10k *ar = hw->priv; |
| 4720 | int ret; |
| 4721 | |
| 4722 | mutex_lock(&ar->conf_mutex); |
| 4723 | ret = __ath10k_set_antenna(ar, tx_ant, rx_ant); |
| 4724 | mutex_unlock(&ar->conf_mutex); |
| 4725 | return ret; |
| 4726 | } |
| 4727 | |
Bhagavathi Perumal S | 84758d4 | 2018-12-20 14:26:00 +0200 | [diff] [blame] | 4728 | static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar, |
| 4729 | struct wmi_bb_timing_cfg_arg *bb_timing) |
| 4730 | { |
| 4731 | struct device_node *node; |
| 4732 | const char *fem_name; |
| 4733 | int ret; |
| 4734 | |
| 4735 | node = ar->dev->of_node; |
| 4736 | if (!node) |
| 4737 | return -ENOENT; |
| 4738 | |
| 4739 | ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name); |
| 4740 | if (ret) |
| 4741 | return -ENOENT; |
| 4742 | |
| 4743 | /* |
| 4744 | * If external Front End module used in hardware, then default base band timing |
| 4745 | * parameter cannot be used since they were fine tuned for reference hardware, |
| 4746 | * so choosing different value suitable for that external FEM. |
| 4747 | */ |
| 4748 | if (!strcmp("microsemi-lx5586", fem_name)) { |
| 4749 | bb_timing->bb_tx_timing = 0x00; |
| 4750 | bb_timing->bb_xpa_timing = 0x0101; |
| 4751 | } else { |
| 4752 | return -ENOENT; |
| 4753 | } |
| 4754 | |
| 4755 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n", |
| 4756 | bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing); |
| 4757 | return 0; |
| 4758 | } |
| 4759 | |
Wen Gong | 1382993 | 2019-10-01 15:04:56 +0300 | [diff] [blame] | 4760 | static int ath10k_mac_rfkill_config(struct ath10k *ar) |
| 4761 | { |
| 4762 | u32 param; |
| 4763 | int ret; |
| 4764 | |
| 4765 | if (ar->hw_values->rfkill_pin == 0) { |
| 4766 | ath10k_warn(ar, "ath10k does not support hardware rfkill with this device\n"); |
| 4767 | return -EOPNOTSUPP; |
| 4768 | } |
| 4769 | |
| 4770 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 4771 | "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d", |
| 4772 | ar->hw_values->rfkill_pin, ar->hw_values->rfkill_cfg, |
| 4773 | ar->hw_values->rfkill_on_level); |
| 4774 | |
| 4775 | param = FIELD_PREP(WMI_TLV_RFKILL_CFG_RADIO_LEVEL, |
| 4776 | ar->hw_values->rfkill_on_level) | |
| 4777 | FIELD_PREP(WMI_TLV_RFKILL_CFG_GPIO_PIN_NUM, |
| 4778 | ar->hw_values->rfkill_pin) | |
| 4779 | FIELD_PREP(WMI_TLV_RFKILL_CFG_PIN_AS_GPIO, |
| 4780 | ar->hw_values->rfkill_cfg); |
| 4781 | |
| 4782 | ret = ath10k_wmi_pdev_set_param(ar, |
| 4783 | ar->wmi.pdev_param->rfkill_config, |
| 4784 | param); |
| 4785 | if (ret) { |
| 4786 | ath10k_warn(ar, |
| 4787 | "failed to set rfkill config 0x%x: %d\n", |
| 4788 | param, ret); |
| 4789 | return ret; |
| 4790 | } |
| 4791 | return 0; |
| 4792 | } |
| 4793 | |
| 4794 | int ath10k_mac_rfkill_enable_radio(struct ath10k *ar, bool enable) |
| 4795 | { |
| 4796 | enum wmi_tlv_rfkill_enable_radio param; |
| 4797 | int ret; |
| 4798 | |
| 4799 | if (enable) |
| 4800 | param = WMI_TLV_RFKILL_ENABLE_RADIO_ON; |
| 4801 | else |
| 4802 | param = WMI_TLV_RFKILL_ENABLE_RADIO_OFF; |
| 4803 | |
| 4804 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac rfkill enable %d", param); |
| 4805 | |
| 4806 | ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rfkill_enable, |
| 4807 | param); |
| 4808 | if (ret) { |
| 4809 | ath10k_warn(ar, "failed to set rfkill enable param %d: %d\n", |
| 4810 | param, ret); |
| 4811 | return ret; |
| 4812 | } |
| 4813 | |
| 4814 | return 0; |
| 4815 | } |
| 4816 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4817 | static int ath10k_start(struct ieee80211_hw *hw) |
| 4818 | { |
| 4819 | struct ath10k *ar = hw->priv; |
Mohammed Shafi Shajakhan | 1fe374f | 2016-01-13 21:16:30 +0530 | [diff] [blame] | 4820 | u32 param; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4821 | int ret = 0; |
Bhagavathi Perumal S | 84758d4 | 2018-12-20 14:26:00 +0200 | [diff] [blame] | 4822 | struct wmi_bb_timing_cfg_arg bb_timing = {0}; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4823 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 4824 | /* |
| 4825 | * This makes sense only when restarting hw. It is harmless to call |
Mohammed Shafi Shajakhan | 6dfdbfc | 2016-04-26 14:41:36 +0300 | [diff] [blame] | 4826 | * unconditionally. This is necessary to make sure no HTT/WMI tx |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 4827 | * commands will be submitted while restarting. |
| 4828 | */ |
| 4829 | ath10k_drain_tx(ar); |
| 4830 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 4831 | mutex_lock(&ar->conf_mutex); |
| 4832 | |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 4833 | switch (ar->state) { |
| 4834 | case ATH10K_STATE_OFF: |
| 4835 | ar->state = ATH10K_STATE_ON; |
| 4836 | break; |
| 4837 | case ATH10K_STATE_RESTARTING: |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 4838 | ar->state = ATH10K_STATE_RESTARTED; |
| 4839 | break; |
| 4840 | case ATH10K_STATE_ON: |
| 4841 | case ATH10K_STATE_RESTARTED: |
| 4842 | case ATH10K_STATE_WEDGED: |
| 4843 | WARN_ON(1); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4844 | ret = -EINVAL; |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4845 | goto err; |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 4846 | case ATH10K_STATE_UTF: |
| 4847 | ret = -EBUSY; |
| 4848 | goto err; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4849 | } |
| 4850 | |
Wen Gong | 1382993 | 2019-10-01 15:04:56 +0300 | [diff] [blame] | 4851 | spin_lock_bh(&ar->data_lock); |
| 4852 | |
| 4853 | if (ar->hw_rfkill_on) { |
| 4854 | ar->hw_rfkill_on = false; |
| 4855 | spin_unlock_bh(&ar->data_lock); |
| 4856 | goto err; |
| 4857 | } |
| 4858 | |
| 4859 | spin_unlock_bh(&ar->data_lock); |
| 4860 | |
Rakesh Pillai | 3c545a2 | 2019-02-08 15:50:10 +0200 | [diff] [blame] | 4861 | ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4862 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4863 | ath10k_err(ar, "Could not init hif: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4864 | goto err_off; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4865 | } |
| 4866 | |
Kalle Valo | 7ebf721 | 2016-04-20 19:44:51 +0300 | [diff] [blame] | 4867 | ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL, |
| 4868 | &ar->normal_mode_fw); |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4869 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4870 | ath10k_err(ar, "Could not init core: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4871 | goto err_power_down; |
Michal Kazior | 818bdd1 | 2013-07-16 09:38:57 +0200 | [diff] [blame] | 4872 | } |
| 4873 | |
Wen Gong | 1382993 | 2019-10-01 15:04:56 +0300 | [diff] [blame] | 4874 | if (ar->sys_cap_info & WMI_TLV_SYS_CAP_INFO_RFKILL) { |
| 4875 | ret = ath10k_mac_rfkill_config(ar); |
| 4876 | if (ret && ret != -EOPNOTSUPP) { |
| 4877 | ath10k_warn(ar, "failed to configure rfkill: %d", ret); |
| 4878 | goto err_core_stop; |
| 4879 | } |
| 4880 | } |
| 4881 | |
Mohammed Shafi Shajakhan | 1fe374f | 2016-01-13 21:16:30 +0530 | [diff] [blame] | 4882 | param = ar->wmi.pdev_param->pmf_qos; |
| 4883 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4884 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4885 | ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4886 | goto err_core_stop; |
| 4887 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4888 | |
Mohammed Shafi Shajakhan | 1fe374f | 2016-01-13 21:16:30 +0530 | [diff] [blame] | 4889 | param = ar->wmi.pdev_param->dynamic_bw; |
| 4890 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4891 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4892 | ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4893 | goto err_core_stop; |
| 4894 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 4895 | |
Rakesh Pillai | f115769 | 2018-10-02 23:33:13 +0530 | [diff] [blame] | 4896 | if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) { |
| 4897 | ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr); |
| 4898 | if (ret) { |
| 4899 | ath10k_err(ar, "failed to set prob req oui: %i\n", ret); |
| 4900 | goto err_core_stop; |
| 4901 | } |
| 4902 | } |
| 4903 | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 4904 | if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) { |
| 4905 | ret = ath10k_wmi_adaptive_qcs(ar, true); |
| 4906 | if (ret) { |
| 4907 | ath10k_warn(ar, "failed to enable adaptive qcs: %d\n", |
| 4908 | ret); |
| 4909 | goto err_core_stop; |
| 4910 | } |
| 4911 | } |
| 4912 | |
Janusz Dziedzic | 24ab13e | 2015-04-01 22:53:18 +0300 | [diff] [blame] | 4913 | if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) { |
Mohammed Shafi Shajakhan | 1fe374f | 2016-01-13 21:16:30 +0530 | [diff] [blame] | 4914 | param = ar->wmi.pdev_param->burst_enable; |
| 4915 | ret = ath10k_wmi_pdev_set_param(ar, param, 0); |
Janusz Dziedzic | 24ab13e | 2015-04-01 22:53:18 +0300 | [diff] [blame] | 4916 | if (ret) { |
| 4917 | ath10k_warn(ar, "failed to disable burst: %d\n", ret); |
| 4918 | goto err_core_stop; |
| 4919 | } |
| 4920 | } |
| 4921 | |
Govind Singh | d5cded1 | 2018-04-17 17:37:01 +0530 | [diff] [blame] | 4922 | param = ar->wmi.pdev_param->idle_ps_config; |
| 4923 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); |
| 4924 | if (ret && ret != -EOPNOTSUPP) { |
| 4925 | ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret); |
| 4926 | goto err_core_stop; |
| 4927 | } |
| 4928 | |
Rajkumar Manoharan | 166de3f | 2015-10-27 17:51:11 +0530 | [diff] [blame] | 4929 | __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask); |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 4930 | |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 4931 | /* |
| 4932 | * By default FW set ARP frames ac to voice (6). In that case ARP |
| 4933 | * exchange is not working properly for UAPSD enabled AP. ARP requests |
| 4934 | * which arrives with access category 0 are processed by network stack |
| 4935 | * and send back with access category 0, but FW changes access category |
| 4936 | * to 6. Set ARP frames access category to best effort (0) solves |
| 4937 | * this problem. |
| 4938 | */ |
| 4939 | |
Mohammed Shafi Shajakhan | 1fe374f | 2016-01-13 21:16:30 +0530 | [diff] [blame] | 4940 | param = ar->wmi.pdev_param->arp_ac_override; |
| 4941 | ret = ath10k_wmi_pdev_set_param(ar, param, 0); |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 4942 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 4943 | ath10k_warn(ar, "failed to set arp ac override parameter: %d\n", |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 4944 | ret); |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 4945 | goto err_core_stop; |
Marek Puzyniak | ab6258e | 2014-01-29 15:03:31 +0200 | [diff] [blame] | 4946 | } |
| 4947 | |
Maharaja | 62f77f0 | 2015-10-21 11:49:18 +0300 | [diff] [blame] | 4948 | if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA, |
Kalle Valo | c4cdf75 | 2016-04-20 19:45:18 +0300 | [diff] [blame] | 4949 | ar->running_fw->fw_file.fw_features)) { |
Maharaja | 62f77f0 | 2015-10-21 11:49:18 +0300 | [diff] [blame] | 4950 | ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1, |
| 4951 | WMI_CCA_DETECT_LEVEL_AUTO, |
| 4952 | WMI_CCA_DETECT_MARGIN_AUTO); |
| 4953 | if (ret) { |
| 4954 | ath10k_warn(ar, "failed to enable adaptive cca: %d\n", |
| 4955 | ret); |
| 4956 | goto err_core_stop; |
| 4957 | } |
| 4958 | } |
| 4959 | |
Mohammed Shafi Shajakhan | 1fe374f | 2016-01-13 21:16:30 +0530 | [diff] [blame] | 4960 | param = ar->wmi.pdev_param->ani_enable; |
| 4961 | ret = ath10k_wmi_pdev_set_param(ar, param, 1); |
Ashok Raj Nagarajan | 575f1c3 | 2015-03-19 16:37:59 +0530 | [diff] [blame] | 4962 | if (ret) { |
| 4963 | ath10k_warn(ar, "failed to enable ani by default: %d\n", |
| 4964 | ret); |
| 4965 | goto err_core_stop; |
| 4966 | } |
| 4967 | |
Ashok Raj Nagarajan | b3e71d7 | 2015-03-19 16:38:00 +0530 | [diff] [blame] | 4968 | ar->ani_enabled = true; |
| 4969 | |
Mohammed Shafi Shajakhan | cc61a1b | 2016-03-16 18:13:32 +0530 | [diff] [blame] | 4970 | if (ath10k_peer_stats_enabled(ar)) { |
Mohammed Shafi Shajakhan | 8351c05 | 2016-01-13 21:16:33 +0530 | [diff] [blame] | 4971 | param = ar->wmi.pdev_param->peer_stats_update_period; |
| 4972 | ret = ath10k_wmi_pdev_set_param(ar, param, |
| 4973 | PEER_DEFAULT_STATS_UPDATE_PERIOD); |
| 4974 | if (ret) { |
| 4975 | ath10k_warn(ar, |
| 4976 | "failed to set peer stats period : %d\n", |
| 4977 | ret); |
| 4978 | goto err_core_stop; |
| 4979 | } |
| 4980 | } |
| 4981 | |
Rajkumar Manoharan | 3913624 | 2016-05-27 20:15:59 +0530 | [diff] [blame] | 4982 | param = ar->wmi.pdev_param->enable_btcoex; |
| 4983 | if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) && |
| 4984 | test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM, |
| 4985 | ar->running_fw->fw_file.fw_features)) { |
| 4986 | ret = ath10k_wmi_pdev_set_param(ar, param, 0); |
| 4987 | if (ret) { |
| 4988 | ath10k_warn(ar, |
| 4989 | "failed to set btcoex param: %d\n", ret); |
| 4990 | goto err_core_stop; |
| 4991 | } |
| 4992 | clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags); |
| 4993 | } |
| 4994 | |
Bhagavathi Perumal S | 84758d4 | 2018-12-20 14:26:00 +0200 | [diff] [blame] | 4995 | if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) { |
| 4996 | ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing); |
| 4997 | if (!ret) { |
| 4998 | ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing); |
| 4999 | if (ret) { |
| 5000 | ath10k_warn(ar, |
| 5001 | "failed to set bb timings: %d\n", |
| 5002 | ret); |
| 5003 | goto err_core_stop; |
| 5004 | } |
| 5005 | } |
| 5006 | } |
| 5007 | |
Michal Kazior | d650097 | 2014-04-08 09:56:09 +0300 | [diff] [blame] | 5008 | ar->num_started_vdevs = 0; |
Michal Kazior | f7843d7 | 2013-07-16 09:38:52 +0200 | [diff] [blame] | 5009 | ath10k_regd_update(ar); |
| 5010 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 5011 | ath10k_spectral_start(ar); |
Rajkumar Manoharan | 8515b5c | 2015-03-15 20:36:22 +0530 | [diff] [blame] | 5012 | ath10k_thermal_set_throttling(ar); |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 5013 | |
Sriram R | 6f6eb1b | 2018-05-15 14:39:49 +0530 | [diff] [blame] | 5014 | ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE; |
| 5015 | |
Michal Kazior | ae25443 | 2014-05-26 12:46:02 +0300 | [diff] [blame] | 5016 | mutex_unlock(&ar->conf_mutex); |
| 5017 | return 0; |
| 5018 | |
| 5019 | err_core_stop: |
| 5020 | ath10k_core_stop(ar); |
| 5021 | |
| 5022 | err_power_down: |
| 5023 | ath10k_hif_power_down(ar); |
| 5024 | |
| 5025 | err_off: |
| 5026 | ar->state = ATH10K_STATE_OFF; |
| 5027 | |
| 5028 | err: |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5029 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | c60bdd8 | 2014-01-29 07:26:31 +0100 | [diff] [blame] | 5030 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | static void ath10k_stop(struct ieee80211_hw *hw) |
| 5034 | { |
| 5035 | struct ath10k *ar = hw->priv; |
| 5036 | |
Michal Kazior | bca7baf | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 5037 | ath10k_drain_tx(ar); |
| 5038 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5039 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 5040 | if (ar->state != ATH10K_STATE_OFF) { |
Wen Gong | 1382993 | 2019-10-01 15:04:56 +0300 | [diff] [blame] | 5041 | if (!ar->hw_rfkill_on) |
| 5042 | ath10k_halt(ar); |
Michal Kazior | c5058f5 | 2014-05-26 12:46:03 +0300 | [diff] [blame] | 5043 | ar->state = ATH10K_STATE_OFF; |
| 5044 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 5045 | mutex_unlock(&ar->conf_mutex); |
| 5046 | |
Mohammed Shafi Shajakhan | d94475c | 2017-03-31 17:28:41 +0530 | [diff] [blame] | 5047 | cancel_work_sync(&ar->set_coverage_class_work); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 5048 | cancel_delayed_work_sync(&ar->scan.timeout); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5049 | cancel_work_sync(&ar->restart_work); |
| 5050 | } |
| 5051 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5052 | static int ath10k_config_ps(struct ath10k *ar) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5053 | { |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5054 | struct ath10k_vif *arvif; |
| 5055 | int ret = 0; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5056 | |
| 5057 | lockdep_assert_held(&ar->conf_mutex); |
| 5058 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5059 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 5060 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 5061 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5062 | ath10k_warn(ar, "failed to setup powersave: %d\n", ret); |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5063 | break; |
| 5064 | } |
| 5065 | } |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5066 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 5067 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5068 | } |
| 5069 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 5070 | static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower) |
| 5071 | { |
| 5072 | int ret; |
| 5073 | u32 param; |
| 5074 | |
| 5075 | lockdep_assert_held(&ar->conf_mutex); |
| 5076 | |
| 5077 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower); |
| 5078 | |
| 5079 | param = ar->wmi.pdev_param->txpower_limit2g; |
| 5080 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 5081 | if (ret) { |
| 5082 | ath10k_warn(ar, "failed to set 2g txpower %d: %d\n", |
| 5083 | txpower, ret); |
| 5084 | return ret; |
| 5085 | } |
| 5086 | |
| 5087 | param = ar->wmi.pdev_param->txpower_limit5g; |
| 5088 | ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2); |
| 5089 | if (ret) { |
| 5090 | ath10k_warn(ar, "failed to set 5g txpower %d: %d\n", |
| 5091 | txpower, ret); |
| 5092 | return ret; |
| 5093 | } |
| 5094 | |
| 5095 | return 0; |
| 5096 | } |
| 5097 | |
| 5098 | static int ath10k_mac_txpower_recalc(struct ath10k *ar) |
| 5099 | { |
| 5100 | struct ath10k_vif *arvif; |
| 5101 | int ret, txpower = -1; |
| 5102 | |
| 5103 | lockdep_assert_held(&ar->conf_mutex); |
| 5104 | |
| 5105 | list_for_each_entry(arvif, &ar->arvifs, list) { |
Ryan Hsu | 88407be | 2016-12-13 14:55:19 -0800 | [diff] [blame] | 5106 | if (arvif->txpower <= 0) |
| 5107 | continue; |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 5108 | |
| 5109 | if (txpower == -1) |
| 5110 | txpower = arvif->txpower; |
| 5111 | else |
| 5112 | txpower = min(txpower, arvif->txpower); |
| 5113 | } |
| 5114 | |
Ryan Hsu | 88407be | 2016-12-13 14:55:19 -0800 | [diff] [blame] | 5115 | if (txpower == -1) |
| 5116 | return 0; |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 5117 | |
| 5118 | ret = ath10k_mac_txpower_setup(ar, txpower); |
| 5119 | if (ret) { |
| 5120 | ath10k_warn(ar, "failed to setup tx power %d: %d\n", |
| 5121 | txpower, ret); |
| 5122 | return ret; |
| 5123 | } |
| 5124 | |
| 5125 | return 0; |
| 5126 | } |
| 5127 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5128 | static int ath10k_config(struct ieee80211_hw *hw, u32 changed) |
| 5129 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5130 | struct ath10k *ar = hw->priv; |
| 5131 | struct ieee80211_conf *conf = &hw->conf; |
| 5132 | int ret = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5133 | |
| 5134 | mutex_lock(&ar->conf_mutex); |
| 5135 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 5136 | if (changed & IEEE80211_CONF_CHANGE_PS) |
| 5137 | ath10k_config_ps(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5138 | |
| 5139 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 5140 | ar->monitor = conf->flags & IEEE80211_CONF_MONITOR; |
| 5141 | ret = ath10k_monitor_recalc(ar); |
| 5142 | if (ret) |
| 5143 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | mutex_unlock(&ar->conf_mutex); |
| 5147 | return ret; |
| 5148 | } |
| 5149 | |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5150 | static u32 get_nss_from_chainmask(u16 chain_mask) |
| 5151 | { |
Rajkumar Manoharan | f680f70 | 2015-11-03 11:51:33 +0530 | [diff] [blame] | 5152 | if ((chain_mask & 0xf) == 0xf) |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5153 | return 4; |
| 5154 | else if ((chain_mask & 0x7) == 0x7) |
| 5155 | return 3; |
| 5156 | else if ((chain_mask & 0x3) == 0x3) |
| 5157 | return 2; |
| 5158 | return 1; |
| 5159 | } |
| 5160 | |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5161 | static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif) |
| 5162 | { |
| 5163 | u32 value = 0; |
| 5164 | struct ath10k *ar = arvif->ar; |
Bartosz Markowski | 707a0c8 | 2015-09-02 13:20:19 +0200 | [diff] [blame] | 5165 | int nsts; |
Bartosz Markowski | 0c6d6f2 | 2015-09-02 13:20:20 +0200 | [diff] [blame] | 5166 | int sound_dim; |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5167 | |
| 5168 | if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC) |
| 5169 | return 0; |
| 5170 | |
Bartosz Markowski | 707a0c8 | 2015-09-02 13:20:19 +0200 | [diff] [blame] | 5171 | nsts = ath10k_mac_get_vht_cap_bf_sts(ar); |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5172 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 5173 | IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) |
Bartosz Markowski | 707a0c8 | 2015-09-02 13:20:19 +0200 | [diff] [blame] | 5174 | value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET); |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5175 | |
Bartosz Markowski | 0c6d6f2 | 2015-09-02 13:20:20 +0200 | [diff] [blame] | 5176 | sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar); |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5177 | if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 5178 | IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) |
Bartosz Markowski | 0c6d6f2 | 2015-09-02 13:20:20 +0200 | [diff] [blame] | 5179 | value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET); |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5180 | |
| 5181 | if (!value) |
| 5182 | return 0; |
| 5183 | |
| 5184 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) |
| 5185 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER; |
| 5186 | |
| 5187 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) |
| 5188 | value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER | |
| 5189 | WMI_VDEV_PARAM_TXBF_SU_TX_BFER); |
| 5190 | |
| 5191 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) |
| 5192 | value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE; |
| 5193 | |
| 5194 | if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) |
| 5195 | value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE | |
| 5196 | WMI_VDEV_PARAM_TXBF_SU_TX_BFEE); |
| 5197 | |
| 5198 | return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5199 | ar->wmi.vdev_param->txbf, value); |
| 5200 | } |
| 5201 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5202 | /* |
| 5203 | * TODO: |
| 5204 | * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE, |
| 5205 | * because we will send mgmt frames without CCK. This requirement |
| 5206 | * for P2P_FIND/GO_NEG should be handled by checking CCK flag |
| 5207 | * in the TX packet. |
| 5208 | */ |
| 5209 | static int ath10k_add_interface(struct ieee80211_hw *hw, |
| 5210 | struct ieee80211_vif *vif) |
| 5211 | { |
| 5212 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 5213 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | bb8f0c6 | 2016-03-06 16:14:27 +0200 | [diff] [blame] | 5214 | struct ath10k_peer *peer; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5215 | enum wmi_sta_powersave_param param; |
| 5216 | int ret = 0; |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 5217 | u32 value; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5218 | int bit; |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 5219 | int i; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 5220 | u32 vdev_param; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5221 | |
Johannes Berg | 848955c | 2014-11-11 12:48:42 +0100 | [diff] [blame] | 5222 | vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; |
| 5223 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5224 | mutex_lock(&ar->conf_mutex); |
| 5225 | |
Michal Kazior | 0dbd09e | 2013-07-31 10:55:14 +0200 | [diff] [blame] | 5226 | memset(arvif, 0, sizeof(*arvif)); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 5227 | ath10k_mac_txq_init(vif->txq); |
Michal Kazior | 0dbd09e | 2013-07-31 10:55:14 +0200 | [diff] [blame] | 5228 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5229 | arvif->ar = ar; |
| 5230 | arvif->vif = vif; |
| 5231 | |
Ben Greear | e63b33f | 2013-10-22 14:54:14 -0700 | [diff] [blame] | 5232 | INIT_LIST_HEAD(&arvif->list); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 5233 | INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work); |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 5234 | INIT_DELAYED_WORK(&arvif->connection_loss_work, |
| 5235 | ath10k_mac_vif_sta_connection_loss_work); |
Michal Kazior | cc4827b | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5236 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 5237 | for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) { |
| 5238 | arvif->bitrate_mask.control[i].legacy = 0xffffffff; |
| 5239 | memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff, |
| 5240 | sizeof(arvif->bitrate_mask.control[i].ht_mcs)); |
| 5241 | memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff, |
| 5242 | sizeof(arvif->bitrate_mask.control[i].vht_mcs)); |
| 5243 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5244 | |
Michal Kazior | e04cafb | 2015-08-05 12:15:24 +0200 | [diff] [blame] | 5245 | if (ar->num_peers >= ar->max_num_peers) { |
| 5246 | ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n"); |
Michal Kazior | 503422d | 2015-08-19 13:08:53 +0200 | [diff] [blame] | 5247 | ret = -ENOBUFS; |
| 5248 | goto err; |
Michal Kazior | e04cafb | 2015-08-05 12:15:24 +0200 | [diff] [blame] | 5249 | } |
| 5250 | |
Ben Greear | a9aefb3 | 2014-08-12 11:02:19 +0300 | [diff] [blame] | 5251 | if (ar->free_vdev_map == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5252 | 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] | 5253 | ret = -EBUSY; |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5254 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5255 | } |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 5256 | bit = __ffs64(ar->free_vdev_map); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5257 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 5258 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n", |
| 5259 | bit, ar->free_vdev_map); |
| 5260 | |
| 5261 | arvif->vdev_id = bit; |
Peter Oh | 6e4de1a | 2016-01-28 13:54:10 -0800 | [diff] [blame] | 5262 | arvif->vdev_subtype = |
| 5263 | ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5264 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5265 | switch (vif->type) { |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 5266 | case NL80211_IFTYPE_P2P_DEVICE: |
| 5267 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
Peter Oh | 6e4de1a | 2016-01-28 13:54:10 -0800 | [diff] [blame] | 5268 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
| 5269 | (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE); |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 5270 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5271 | case NL80211_IFTYPE_UNSPECIFIED: |
| 5272 | case NL80211_IFTYPE_STATION: |
| 5273 | arvif->vdev_type = WMI_VDEV_TYPE_STA; |
| 5274 | if (vif->p2p) |
Peter Oh | 6e4de1a | 2016-01-28 13:54:10 -0800 | [diff] [blame] | 5275 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
| 5276 | (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5277 | break; |
| 5278 | case NL80211_IFTYPE_ADHOC: |
| 5279 | arvif->vdev_type = WMI_VDEV_TYPE_IBSS; |
| 5280 | break; |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 5281 | case NL80211_IFTYPE_MESH_POINT: |
Peter Oh | 0b3d76e | 2016-01-28 13:54:07 -0800 | [diff] [blame] | 5282 | if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) { |
Peter Oh | 6e4de1a | 2016-01-28 13:54:10 -0800 | [diff] [blame] | 5283 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
| 5284 | (ar, WMI_VDEV_SUBTYPE_MESH_11S); |
Peter Oh | bb58b89 | 2015-11-24 09:37:35 -0800 | [diff] [blame] | 5285 | } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 5286 | ret = -EINVAL; |
| 5287 | ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n"); |
| 5288 | goto err; |
| 5289 | } |
| 5290 | arvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 5291 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5292 | case NL80211_IFTYPE_AP: |
| 5293 | arvif->vdev_type = WMI_VDEV_TYPE_AP; |
| 5294 | |
| 5295 | if (vif->p2p) |
Peter Oh | 6e4de1a | 2016-01-28 13:54:10 -0800 | [diff] [blame] | 5296 | arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype |
| 5297 | (ar, WMI_VDEV_SUBTYPE_P2P_GO); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5298 | break; |
| 5299 | case NL80211_IFTYPE_MONITOR: |
| 5300 | arvif->vdev_type = WMI_VDEV_TYPE_MONITOR; |
| 5301 | break; |
| 5302 | default: |
| 5303 | WARN_ON(1); |
| 5304 | break; |
| 5305 | } |
| 5306 | |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 5307 | /* Using vdev_id as queue number will make it very easy to do per-vif |
| 5308 | * tx queue locking. This shouldn't wrap due to interface combinations |
| 5309 | * but do a modulo for correctness sake and prevent using offchannel tx |
| 5310 | * queues for regular vif tx. |
| 5311 | */ |
| 5312 | vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1); |
| 5313 | for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++) |
| 5314 | vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1); |
| 5315 | |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 5316 | /* Some firmware revisions don't wait for beacon tx completion before |
| 5317 | * sending another SWBA event. This could lead to hardware using old |
| 5318 | * (freed) beacon data in some cases, e.g. tx credit starvation |
| 5319 | * combined with missed TBTT. This is very very rare. |
| 5320 | * |
| 5321 | * On non-IOMMU-enabled hosts this could be a possible security issue |
| 5322 | * because hw could beacon some random data on the air. On |
| 5323 | * IOMMU-enabled hosts DMAR faults would occur in most cases and target |
| 5324 | * device would crash. |
| 5325 | * |
| 5326 | * Since there are no beacon tx completions (implicit nor explicit) |
| 5327 | * propagated to host the only workaround for this is to allocate a |
| 5328 | * DMA-coherent buffer for a lifetime of a vif and use it for all |
| 5329 | * beacon tx commands. Worst case for this approach is some beacons may |
| 5330 | * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap. |
| 5331 | */ |
| 5332 | if (vif->type == NL80211_IFTYPE_ADHOC || |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 5333 | vif->type == NL80211_IFTYPE_MESH_POINT || |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 5334 | vif->type == NL80211_IFTYPE_AP) { |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5335 | arvif->beacon_buf = dma_alloc_coherent(ar->dev, |
| 5336 | IEEE80211_MAX_FRAME_LEN, |
| 5337 | &arvif->beacon_paddr, |
| 5338 | GFP_ATOMIC); |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 5339 | if (!arvif->beacon_buf) { |
| 5340 | ret = -ENOMEM; |
| 5341 | ath10k_warn(ar, "failed to allocate beacon buffer: %d\n", |
| 5342 | ret); |
| 5343 | goto err; |
| 5344 | } |
| 5345 | } |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 5346 | if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags)) |
| 5347 | arvif->nohwcrypt = true; |
| 5348 | |
| 5349 | if (arvif->nohwcrypt && |
| 5350 | !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) { |
| 5351 | ath10k_warn(ar, "cryptmode module param needed for sw crypto\n"); |
| 5352 | goto err; |
| 5353 | } |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 5354 | |
| 5355 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n", |
| 5356 | arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype, |
| 5357 | arvif->beacon_buf ? "single-buf" : "per-skb"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5358 | |
| 5359 | ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type, |
| 5360 | arvif->vdev_subtype, vif->addr); |
| 5361 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5362 | ath10k_warn(ar, "failed to create WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5363 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5364 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5365 | } |
| 5366 | |
Sathishkumar Muruganandam | 68c295f | 2018-12-20 09:53:30 +0200 | [diff] [blame] | 5367 | if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT, |
| 5368 | ar->wmi.svc_map)) { |
| 5369 | vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn; |
| 5370 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5371 | WMI_VDEV_DISABLE_4_ADDR_SRC_LRN); |
| 5372 | if (ret && ret != -EOPNOTSUPP) { |
| 5373 | ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n", |
| 5374 | arvif->vdev_id, ret); |
| 5375 | } |
| 5376 | } |
| 5377 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 5378 | ar->free_vdev_map &= ~(1LL << arvif->vdev_id); |
Vasanthakumar Thiagarajan | ebaa4b1 | 2016-10-10 19:51:18 +0530 | [diff] [blame] | 5379 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5380 | list_add(&arvif->list, &ar->arvifs); |
Vasanthakumar Thiagarajan | ebaa4b1 | 2016-10-10 19:51:18 +0530 | [diff] [blame] | 5381 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5382 | |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 5383 | /* It makes no sense to have firmware do keepalives. mac80211 already |
| 5384 | * takes care of this with idle connection polling. |
| 5385 | */ |
| 5386 | ret = ath10k_mac_vif_disable_keepalive(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5387 | if (ret) { |
Michal Kazior | 46725b15 | 2015-01-28 09:57:49 +0200 | [diff] [blame] | 5388 | ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5389 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5390 | goto err_vdev_delete; |
| 5391 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5392 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 5393 | arvif->def_wep_key_idx = -1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5394 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 5395 | vdev_param = ar->wmi.vdev_param->tx_encap_type; |
| 5396 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5397 | ATH10K_HW_TXRX_NATIVE_WIFI); |
Bartosz Markowski | ebc9abd | 2013-10-15 09:26:20 +0200 | [diff] [blame] | 5398 | /* 10.X firmware does not support this VDEV parameter. Do not warn */ |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5399 | if (ret && ret != -EOPNOTSUPP) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5400 | ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5401 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5402 | goto err_vdev_delete; |
| 5403 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5404 | |
Rajkumar Manoharan | 8a75fc5 | 2016-03-02 20:13:52 +0530 | [diff] [blame] | 5405 | /* Configuring number of spatial stream for monitor interface is causing |
| 5406 | * target assert in qca9888 and qca6174. |
| 5407 | */ |
| 5408 | if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) { |
Ben Greear | 5572a95 | 2014-11-24 16:22:10 +0200 | [diff] [blame] | 5409 | u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask); |
| 5410 | |
| 5411 | vdev_param = ar->wmi.vdev_param->nss; |
| 5412 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5413 | nss); |
| 5414 | if (ret) { |
| 5415 | ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n", |
| 5416 | arvif->vdev_id, ar->cfg_tx_chainmask, nss, |
| 5417 | ret); |
| 5418 | goto err_vdev_delete; |
| 5419 | } |
| 5420 | } |
| 5421 | |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5422 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 5423 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 5424 | ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id, |
| 5425 | vif->addr, WMI_PEER_TYPE_DEFAULT); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5426 | if (ret) { |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5427 | 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] | 5428 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5429 | goto err_vdev_delete; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5430 | } |
Michal Kazior | bb8f0c6 | 2016-03-06 16:14:27 +0200 | [diff] [blame] | 5431 | |
| 5432 | spin_lock_bh(&ar->data_lock); |
| 5433 | |
| 5434 | peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr); |
| 5435 | if (!peer) { |
| 5436 | ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n", |
| 5437 | vif->addr, arvif->vdev_id); |
| 5438 | spin_unlock_bh(&ar->data_lock); |
| 5439 | ret = -ENOENT; |
| 5440 | goto err_peer_delete; |
| 5441 | } |
| 5442 | |
| 5443 | arvif->peer_id = find_first_bit(peer->peer_ids, |
| 5444 | ATH10K_MAX_NUM_PEER_IDS); |
| 5445 | |
| 5446 | spin_unlock_bh(&ar->data_lock); |
| 5447 | } else { |
| 5448 | arvif->peer_id = HTT_INVALID_PEERID; |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5449 | } |
Marek Puzyniak | cdf0740 | 2013-12-30 09:07:51 +0100 | [diff] [blame] | 5450 | |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5451 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP) { |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 5452 | ret = ath10k_mac_set_kickout(arvif); |
| 5453 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5454 | ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5455 | arvif->vdev_id, ret); |
Kalle Valo | 5a13e76 | 2014-01-20 11:01:46 +0200 | [diff] [blame] | 5456 | goto err_peer_delete; |
| 5457 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5458 | } |
| 5459 | |
| 5460 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) { |
| 5461 | param = WMI_STA_PS_PARAM_RX_WAKE_POLICY; |
| 5462 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 5463 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 5464 | param, value); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5465 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5466 | 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] | 5467 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5468 | goto err_peer_delete; |
| 5469 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5470 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 5471 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5472 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 5473 | 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] | 5474 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5475 | goto err_peer_delete; |
| 5476 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5477 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 5478 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5479 | if (ret) { |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 5480 | 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] | 5481 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5482 | goto err_peer_delete; |
| 5483 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5484 | } |
| 5485 | |
Vivek Natarajan | a48e2cc | 2015-08-04 10:45:12 +0530 | [diff] [blame] | 5486 | ret = ath10k_mac_set_txbf_conf(arvif); |
| 5487 | if (ret) { |
| 5488 | ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n", |
| 5489 | arvif->vdev_id, ret); |
| 5490 | goto err_peer_delete; |
| 5491 | } |
| 5492 | |
Michal Kazior | 424121c | 2013-07-22 14:13:31 +0200 | [diff] [blame] | 5493 | ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5494 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5495 | 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] | 5496 | arvif->vdev_id, ret); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5497 | goto err_peer_delete; |
| 5498 | } |
Michal Kazior | 679c54a | 2013-07-05 16:15:04 +0300 | [diff] [blame] | 5499 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 5500 | arvif->txpower = vif->bss_conf.txpower; |
| 5501 | ret = ath10k_mac_txpower_recalc(ar); |
| 5502 | if (ret) { |
| 5503 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 5504 | goto err_peer_delete; |
| 5505 | } |
| 5506 | |
Pradeep Kumar Chitrapu | 059104b | 2019-02-11 18:47:54 +0200 | [diff] [blame] | 5507 | if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) { |
| 5508 | vdev_param = ar->wmi.vdev_param->rtt_responder_role; |
| 5509 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5510 | arvif->ftm_responder); |
| 5511 | |
| 5512 | /* It is harmless to not set FTM role. Do not warn */ |
| 5513 | if (ret && ret != -EOPNOTSUPP) |
| 5514 | ath10k_warn(ar, "failed to set vdev %i FTM Responder: %d\n", |
| 5515 | arvif->vdev_id, ret); |
| 5516 | } |
| 5517 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5518 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 5519 | ar->monitor_arvif = arvif; |
| 5520 | ret = ath10k_monitor_recalc(ar); |
| 5521 | if (ret) { |
| 5522 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
| 5523 | goto err_peer_delete; |
| 5524 | } |
| 5525 | } |
| 5526 | |
Michal Kazior | 6d2d51e | 2015-08-07 09:08:21 +0200 | [diff] [blame] | 5527 | spin_lock_bh(&ar->htt.tx_lock); |
| 5528 | if (!ar->tx_paused) |
| 5529 | ieee80211_wake_queue(ar->hw, arvif->vdev_id); |
| 5530 | spin_unlock_bh(&ar->htt.tx_lock); |
| 5531 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5532 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5533 | return 0; |
| 5534 | |
| 5535 | err_peer_delete: |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5536 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
Dundi Raviteja | c6f537a | 2019-06-03 17:41:51 +0300 | [diff] [blame] | 5537 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5538 | ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr); |
Dundi Raviteja | c6f537a | 2019-06-03 17:41:51 +0300 | [diff] [blame] | 5539 | ath10k_wait_for_peer_delete_done(ar, arvif->vdev_id, |
| 5540 | vif->addr); |
| 5541 | } |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5542 | |
| 5543 | err_vdev_delete: |
| 5544 | ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 5545 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Vasanthakumar Thiagarajan | ebaa4b1 | 2016-10-10 19:51:18 +0530 | [diff] [blame] | 5546 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5547 | list_del(&arvif->list); |
Vasanthakumar Thiagarajan | ebaa4b1 | 2016-10-10 19:51:18 +0530 | [diff] [blame] | 5548 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5549 | |
| 5550 | err: |
Michal Kazior | 64badcb | 2014-09-18 11:18:02 +0300 | [diff] [blame] | 5551 | if (arvif->beacon_buf) { |
| 5552 | dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN, |
| 5553 | arvif->beacon_buf, arvif->beacon_paddr); |
| 5554 | arvif->beacon_buf = NULL; |
| 5555 | } |
| 5556 | |
Michal Kazior | 9dad14ae | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5557 | mutex_unlock(&ar->conf_mutex); |
| 5558 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5559 | return ret; |
| 5560 | } |
| 5561 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 5562 | static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif) |
| 5563 | { |
| 5564 | int i; |
| 5565 | |
| 5566 | for (i = 0; i < BITS_PER_LONG; i++) |
| 5567 | ath10k_mac_vif_tx_unlock(arvif, i); |
| 5568 | } |
| 5569 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5570 | static void ath10k_remove_interface(struct ieee80211_hw *hw, |
| 5571 | struct ieee80211_vif *vif) |
| 5572 | { |
| 5573 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 5574 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 5575 | struct ath10k_peer *peer; |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 5576 | unsigned long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5577 | int ret; |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 5578 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5579 | |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 5580 | cancel_work_sync(&arvif->ap_csa_work); |
Michal Kazior | cc9904e | 2015-03-10 16:22:01 +0200 | [diff] [blame] | 5581 | cancel_delayed_work_sync(&arvif->connection_loss_work); |
Michal Kazior | 81a9a17 | 2015-03-05 16:02:17 +0200 | [diff] [blame] | 5582 | |
Sujith Manoharan | 5d011f5 | 2014-11-25 11:47:00 +0530 | [diff] [blame] | 5583 | mutex_lock(&ar->conf_mutex); |
| 5584 | |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 5585 | ret = ath10k_spectral_vif_stop(arvif); |
| 5586 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5587 | ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n", |
Simon Wunderlich | 855aed1 | 2014-08-02 09:12:54 +0300 | [diff] [blame] | 5588 | arvif->vdev_id, ret); |
| 5589 | |
Ben Greear | 16c1117 | 2014-09-23 14:17:16 -0700 | [diff] [blame] | 5590 | ar->free_vdev_map |= 1LL << arvif->vdev_id; |
Vasanthakumar Thiagarajan | ebaa4b1 | 2016-10-10 19:51:18 +0530 | [diff] [blame] | 5591 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 0579119 | 2013-10-16 15:44:45 +0300 | [diff] [blame] | 5592 | list_del(&arvif->list); |
Vasanthakumar Thiagarajan | ebaa4b1 | 2016-10-10 19:51:18 +0530 | [diff] [blame] | 5593 | spin_unlock_bh(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5594 | |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5595 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 5596 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 5597 | ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id, |
| 5598 | vif->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5599 | if (ret) |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5600 | 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] | 5601 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5602 | |
Dundi Raviteja | c6f537a | 2019-06-03 17:41:51 +0300 | [diff] [blame] | 5603 | ath10k_wait_for_peer_delete_done(ar, arvif->vdev_id, |
| 5604 | vif->addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5605 | kfree(arvif->u.ap.noa_data); |
| 5606 | } |
| 5607 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5608 | 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] | 5609 | arvif->vdev_id); |
| 5610 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5611 | ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id); |
| 5612 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5613 | ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5614 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5615 | |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 5616 | if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) { |
| 5617 | time_left = wait_for_completion_timeout(&ar->vdev_delete_done, |
| 5618 | ATH10K_VDEV_DELETE_TIMEOUT_HZ); |
| 5619 | if (time_left == 0) { |
| 5620 | ath10k_warn(ar, "Timeout in receiving vdev delete response\n"); |
| 5621 | goto out; |
| 5622 | } |
| 5623 | } |
| 5624 | |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 5625 | /* Some firmware revisions don't notify host about self-peer removal |
| 5626 | * until after associated vdev is deleted. |
| 5627 | */ |
Michal Kazior | e57e057 | 2015-03-24 13:14:03 +0000 | [diff] [blame] | 5628 | if (arvif->vdev_type == WMI_VDEV_TYPE_AP || |
| 5629 | arvif->vdev_type == WMI_VDEV_TYPE_IBSS) { |
Michal Kazior | 2c51205 | 2015-02-15 16:50:40 +0200 | [diff] [blame] | 5630 | ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id, |
| 5631 | vif->addr); |
| 5632 | if (ret) |
| 5633 | ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n", |
| 5634 | arvif->vdev_id, ret); |
| 5635 | |
| 5636 | spin_lock_bh(&ar->data_lock); |
| 5637 | ar->num_peers--; |
| 5638 | spin_unlock_bh(&ar->data_lock); |
| 5639 | } |
| 5640 | |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 5641 | spin_lock_bh(&ar->data_lock); |
| 5642 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) { |
| 5643 | peer = ar->peer_map[i]; |
| 5644 | if (!peer) |
| 5645 | continue; |
| 5646 | |
| 5647 | if (peer->vif == vif) { |
| 5648 | ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n", |
| 5649 | vif->addr, arvif->vdev_id); |
| 5650 | peer->vif = NULL; |
| 5651 | } |
| 5652 | } |
Ben Greear | b3281c6 | 2019-09-10 16:46:15 +0300 | [diff] [blame] | 5653 | |
| 5654 | /* Clean this up late, less opportunity for firmware to access |
| 5655 | * DMA memory we have deleted. |
| 5656 | */ |
| 5657 | ath10k_mac_vif_beacon_cleanup(arvif); |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 5658 | spin_unlock_bh(&ar->data_lock); |
| 5659 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5660 | ath10k_peer_cleanup(ar, arvif->vdev_id); |
Michal Kazior | dd4717b | 2016-03-06 16:14:39 +0200 | [diff] [blame] | 5661 | ath10k_mac_txq_unref(ar, vif->txq); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5662 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 5663 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 5664 | ar->monitor_arvif = NULL; |
| 5665 | ret = ath10k_monitor_recalc(ar); |
| 5666 | if (ret) |
| 5667 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
| 5668 | } |
| 5669 | |
Ryan Hsu | d679fa1 | 2016-12-22 14:31:46 -0800 | [diff] [blame] | 5670 | ret = ath10k_mac_txpower_recalc(ar); |
| 5671 | if (ret) |
| 5672 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 5673 | |
Michal Kazior | b4aa539 | 2015-03-31 10:26:24 +0000 | [diff] [blame] | 5674 | spin_lock_bh(&ar->htt.tx_lock); |
| 5675 | ath10k_mac_vif_tx_unlock_all(arvif); |
| 5676 | spin_unlock_bh(&ar->htt.tx_lock); |
| 5677 | |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 5678 | ath10k_mac_txq_unref(ar, vif->txq); |
| 5679 | |
Rakesh Pillai | fe36e70 | 2019-06-03 17:41:33 +0300 | [diff] [blame] | 5680 | out: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5681 | mutex_unlock(&ar->conf_mutex); |
| 5682 | } |
| 5683 | |
| 5684 | /* |
| 5685 | * FIXME: Has to be verified. |
| 5686 | */ |
| 5687 | #define SUPPORTED_FILTERS \ |
Johannes Berg | df14046 | 2015-04-22 14:40:58 +0200 | [diff] [blame] | 5688 | (FIF_ALLMULTI | \ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5689 | FIF_CONTROL | \ |
| 5690 | FIF_PSPOLL | \ |
| 5691 | FIF_OTHER_BSS | \ |
| 5692 | FIF_BCN_PRBRESP_PROMISC | \ |
| 5693 | FIF_PROBE_REQ | \ |
| 5694 | FIF_FCSFAIL) |
| 5695 | |
| 5696 | static void ath10k_configure_filter(struct ieee80211_hw *hw, |
| 5697 | unsigned int changed_flags, |
| 5698 | unsigned int *total_flags, |
| 5699 | u64 multicast) |
| 5700 | { |
| 5701 | struct ath10k *ar = hw->priv; |
| 5702 | int ret; |
| 5703 | |
| 5704 | mutex_lock(&ar->conf_mutex); |
| 5705 | |
| 5706 | changed_flags &= SUPPORTED_FILTERS; |
| 5707 | *total_flags &= SUPPORTED_FILTERS; |
| 5708 | ar->filter_flags = *total_flags; |
| 5709 | |
Michal Kazior | 1933747 | 2014-08-28 12:58:16 +0200 | [diff] [blame] | 5710 | ret = ath10k_monitor_recalc(ar); |
| 5711 | if (ret) |
Colin Ian King | 7f03d30 | 2016-08-26 19:08:52 +0100 | [diff] [blame] | 5712 | ath10k_warn(ar, "failed to recalc monitor: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5713 | |
| 5714 | mutex_unlock(&ar->conf_mutex); |
| 5715 | } |
| 5716 | |
Sven Eckelmann | 0227ff36 | 2019-07-03 16:19:49 +0200 | [diff] [blame] | 5717 | static void ath10k_recalculate_mgmt_rate(struct ath10k *ar, |
| 5718 | struct ieee80211_vif *vif, |
| 5719 | struct cfg80211_chan_def *def) |
| 5720 | { |
| 5721 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 5722 | const struct ieee80211_supported_band *sband; |
| 5723 | u8 basic_rate_idx; |
| 5724 | int hw_rate_code; |
| 5725 | u32 vdev_param; |
| 5726 | u16 bitrate; |
| 5727 | int ret; |
| 5728 | |
| 5729 | lockdep_assert_held(&ar->conf_mutex); |
| 5730 | |
| 5731 | sband = ar->hw->wiphy->bands[def->chan->band]; |
| 5732 | basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1; |
| 5733 | bitrate = sband->bitrates[basic_rate_idx].bitrate; |
| 5734 | |
| 5735 | hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate); |
| 5736 | if (hw_rate_code < 0) { |
| 5737 | ath10k_warn(ar, "bitrate not supported %d\n", bitrate); |
| 5738 | return; |
| 5739 | } |
| 5740 | |
| 5741 | vdev_param = ar->wmi.vdev_param->mgmt_rate; |
| 5742 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5743 | hw_rate_code); |
| 5744 | if (ret) |
| 5745 | ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret); |
| 5746 | } |
| 5747 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5748 | static void ath10k_bss_info_changed(struct ieee80211_hw *hw, |
| 5749 | struct ieee80211_vif *vif, |
| 5750 | struct ieee80211_bss_conf *info, |
| 5751 | u32 changed) |
| 5752 | { |
| 5753 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 5754 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 5755 | struct cfg80211_chan_def def; |
Kalle Valo | af762c0 | 2014-09-14 12:50:17 +0300 | [diff] [blame] | 5756 | u32 vdev_param, pdev_param, slottime, preamble; |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 5757 | u16 bitrate, hw_value; |
Sven Eckelmann | 0227ff36 | 2019-07-03 16:19:49 +0200 | [diff] [blame] | 5758 | u8 rate, rateidx; |
| 5759 | int ret = 0, mcast_rate; |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 5760 | enum nl80211_band band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5761 | |
| 5762 | mutex_lock(&ar->conf_mutex); |
| 5763 | |
| 5764 | if (changed & BSS_CHANGED_IBSS) |
| 5765 | ath10k_control_ibss(arvif, info, vif->addr); |
| 5766 | |
| 5767 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 5768 | arvif->beacon_interval = info->beacon_int; |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 5769 | vdev_param = ar->wmi.vdev_param->beacon_interval; |
| 5770 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5771 | arvif->beacon_interval); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5772 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5773 | "mac vdev %d beacon_interval %d\n", |
| 5774 | arvif->vdev_id, arvif->beacon_interval); |
| 5775 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5776 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5777 | 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] | 5778 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | if (changed & BSS_CHANGED_BEACON) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5782 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5783 | "vdev %d set beacon tx mode to staggered\n", |
| 5784 | arvif->vdev_id); |
| 5785 | |
Bartosz Markowski | 226a339 | 2013-09-26 17:47:16 +0200 | [diff] [blame] | 5786 | pdev_param = ar->wmi.pdev_param->beacon_tx_mode; |
| 5787 | ret = ath10k_wmi_pdev_set_param(ar, pdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5788 | WMI_BEACON_STAGGERED_MODE); |
| 5789 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5790 | 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] | 5791 | arvif->vdev_id, ret); |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 5792 | |
| 5793 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 5794 | if (ret) |
| 5795 | ath10k_warn(ar, "failed to update beacon template: %d\n", |
| 5796 | ret); |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 5797 | |
| 5798 | if (ieee80211_vif_is_mesh(vif)) { |
| 5799 | /* mesh doesn't use SSID but firmware needs it */ |
| 5800 | strncpy(arvif->u.ap.ssid, "mesh", |
| 5801 | sizeof(arvif->u.ap.ssid)); |
| 5802 | arvif->u.ap.ssid_len = 4; |
| 5803 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5804 | } |
| 5805 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 5806 | if (changed & BSS_CHANGED_AP_PROBE_RESP) { |
| 5807 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 5808 | if (ret) |
| 5809 | ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n", |
| 5810 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5811 | } |
| 5812 | |
Michal Kazior | ba2479f | 2015-01-24 12:14:51 +0200 | [diff] [blame] | 5813 | if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5814 | arvif->dtim_period = info->dtim_period; |
| 5815 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5816 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5817 | "mac vdev %d dtim_period %d\n", |
| 5818 | arvif->vdev_id, arvif->dtim_period); |
| 5819 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 5820 | vdev_param = ar->wmi.vdev_param->dtim_period; |
| 5821 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5822 | arvif->dtim_period); |
| 5823 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5824 | 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] | 5825 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5826 | } |
| 5827 | |
| 5828 | if (changed & BSS_CHANGED_SSID && |
| 5829 | vif->type == NL80211_IFTYPE_AP) { |
| 5830 | arvif->u.ap.ssid_len = info->ssid_len; |
| 5831 | if (info->ssid_len) |
| 5832 | memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len); |
| 5833 | arvif->u.ap.hidden_ssid = info->hidden_ssid; |
| 5834 | } |
| 5835 | |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5836 | if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid)) |
| 5837 | ether_addr_copy(arvif->bssid, info->bssid); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5838 | |
Pradeep Kumar Chitrapu | 059104b | 2019-02-11 18:47:54 +0200 | [diff] [blame] | 5839 | if (changed & BSS_CHANGED_FTM_RESPONDER && |
| 5840 | arvif->ftm_responder != info->ftm_responder && |
| 5841 | test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) { |
| 5842 | arvif->ftm_responder = info->ftm_responder; |
| 5843 | |
| 5844 | vdev_param = ar->wmi.vdev_param->rtt_responder_role; |
| 5845 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 5846 | arvif->ftm_responder); |
| 5847 | |
| 5848 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 5849 | "mac vdev %d ftm_responder %d:ret %d\n", |
| 5850 | arvif->vdev_id, arvif->ftm_responder, ret); |
| 5851 | } |
| 5852 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5853 | if (changed & BSS_CHANGED_BEACON_ENABLED) |
| 5854 | ath10k_control_beaconing(arvif, info); |
| 5855 | |
| 5856 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 5857 | arvif->use_cts_prot = info->use_cts_prot; |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5858 | |
Marek Kwaczynski | e81bd10 | 2014-03-11 12:58:00 +0200 | [diff] [blame] | 5859 | ret = ath10k_recalc_rtscts_prot(arvif); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5860 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5861 | 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] | 5862 | arvif->vdev_id, ret); |
Michal Kazior | a87fd4b | 2015-03-02 11:21:17 +0100 | [diff] [blame] | 5863 | |
Bartosz Markowski | 7cfe045 | 2016-12-15 11:23:24 +0200 | [diff] [blame] | 5864 | if (ath10k_mac_can_set_cts_prot(arvif)) { |
| 5865 | ret = ath10k_mac_set_cts_prot(arvif); |
| 5866 | if (ret) |
| 5867 | ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n", |
| 5868 | arvif->vdev_id, ret); |
| 5869 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | if (changed & BSS_CHANGED_ERP_SLOT) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5873 | if (info->use_short_slot) |
| 5874 | slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */ |
| 5875 | |
| 5876 | else |
| 5877 | slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */ |
| 5878 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5879 | 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] | 5880 | arvif->vdev_id, slottime); |
| 5881 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 5882 | vdev_param = ar->wmi.vdev_param->slot_time; |
| 5883 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5884 | slottime); |
| 5885 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5886 | 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] | 5887 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5891 | if (info->use_short_preamble) |
| 5892 | preamble = WMI_VDEV_PREAMBLE_SHORT; |
| 5893 | else |
| 5894 | preamble = WMI_VDEV_PREAMBLE_LONG; |
| 5895 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5896 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 5897 | "mac vdev %d preamble %dn", |
| 5898 | arvif->vdev_id, preamble); |
| 5899 | |
Bartosz Markowski | 6d1506e | 2013-09-26 17:47:15 +0200 | [diff] [blame] | 5900 | vdev_param = ar->wmi.vdev_param->preamble; |
| 5901 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5902 | preamble); |
| 5903 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 5904 | ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 5905 | arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | if (changed & BSS_CHANGED_ASSOC) { |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 5909 | if (info->assoc) { |
| 5910 | /* Workaround: Make sure monitor vdev is not running |
| 5911 | * when associating to prevent some firmware revisions |
| 5912 | * (e.g. 10.1 and 10.2) from crashing. |
| 5913 | */ |
| 5914 | if (ar->monitor_started) |
| 5915 | ath10k_monitor_stop(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5916 | ath10k_bss_assoc(hw, vif, info); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 5917 | ath10k_monitor_recalc(ar); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 5918 | } else { |
| 5919 | ath10k_bss_disassoc(hw, vif); |
Michal Kazior | e556f11 | 2014-08-28 12:58:17 +0200 | [diff] [blame] | 5920 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5921 | } |
| 5922 | |
Michal Kazior | 7d9d558 | 2014-10-21 10:40:15 +0300 | [diff] [blame] | 5923 | if (changed & BSS_CHANGED_TXPOWER) { |
| 5924 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n", |
| 5925 | arvif->vdev_id, info->txpower); |
| 5926 | |
| 5927 | arvif->txpower = info->txpower; |
| 5928 | ret = ath10k_mac_txpower_recalc(ar); |
| 5929 | if (ret) |
| 5930 | ath10k_warn(ar, "failed to recalc tx power: %d\n", ret); |
| 5931 | } |
| 5932 | |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 5933 | if (changed & BSS_CHANGED_PS) { |
Michal Kazior | cffb41f | 2015-02-13 13:30:16 +0100 | [diff] [blame] | 5934 | arvif->ps = vif->bss_conf.ps; |
| 5935 | |
| 5936 | ret = ath10k_config_ps(ar); |
Michal Kazior | bf14e65 | 2014-12-12 12:41:38 +0100 | [diff] [blame] | 5937 | if (ret) |
| 5938 | ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n", |
| 5939 | arvif->vdev_id, ret); |
| 5940 | } |
| 5941 | |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 5942 | if (changed & BSS_CHANGED_MCAST_RATE && |
Rafael J. Wysocki | 9e80ad3 | 2019-03-03 18:24:33 +0100 | [diff] [blame] | 5943 | !ath10k_mac_vif_chan(arvif->vif, &def)) { |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 5944 | band = def.chan->band; |
Pradeep kumar Chitrapu | 93ee3d1 | 2019-04-23 16:43:28 +0300 | [diff] [blame] | 5945 | mcast_rate = vif->bss_conf.mcast_rate[band]; |
| 5946 | if (mcast_rate > 0) |
| 5947 | rateidx = mcast_rate - 1; |
| 5948 | else |
| 5949 | rateidx = ffs(vif->bss_conf.basic_rates) - 1; |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 5950 | |
| 5951 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) |
| 5952 | rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX; |
| 5953 | |
| 5954 | bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate; |
| 5955 | hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value; |
| 5956 | if (ath10k_mac_bitrate_is_cck(bitrate)) |
| 5957 | preamble = WMI_RATE_PREAMBLE_CCK; |
| 5958 | else |
| 5959 | preamble = WMI_RATE_PREAMBLE_OFDM; |
| 5960 | |
| 5961 | rate = ATH10K_HW_RATECODE(hw_value, 0, preamble); |
| 5962 | |
| 5963 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 5964 | "mac vdev %d mcast_rate %x\n", |
| 5965 | arvif->vdev_id, rate); |
| 5966 | |
| 5967 | vdev_param = ar->wmi.vdev_param->mcast_data_rate; |
| 5968 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5969 | vdev_param, rate); |
| 5970 | if (ret) |
| 5971 | ath10k_warn(ar, |
| 5972 | "failed to set mcast rate on vdev %i: %d\n", |
| 5973 | arvif->vdev_id, ret); |
| 5974 | |
| 5975 | vdev_param = ar->wmi.vdev_param->bcast_data_rate; |
| 5976 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
| 5977 | vdev_param, rate); |
| 5978 | if (ret) |
| 5979 | ath10k_warn(ar, |
| 5980 | "failed to set bcast rate on vdev %i: %d\n", |
| 5981 | arvif->vdev_id, ret); |
| 5982 | } |
| 5983 | |
Sven Eckelmann | 0227ff36 | 2019-07-03 16:19:49 +0200 | [diff] [blame] | 5984 | if (changed & BSS_CHANGED_BASIC_RATES && |
| 5985 | !ath10k_mac_vif_chan(arvif->vif, &def)) |
| 5986 | ath10k_recalculate_mgmt_rate(ar, vif, &def); |
Sriram R | f279294e | 2018-09-10 11:09:40 +0530 | [diff] [blame] | 5987 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 5988 | mutex_unlock(&ar->conf_mutex); |
| 5989 | } |
| 5990 | |
Benjamin Berg | ebee76f | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 5991 | static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value) |
| 5992 | { |
| 5993 | struct ath10k *ar = hw->priv; |
| 5994 | |
| 5995 | /* This function should never be called if setting the coverage class |
| 5996 | * is not supported on this hardware. |
| 5997 | */ |
| 5998 | if (!ar->hw_params.hw_ops->set_coverage_class) { |
| 5999 | WARN_ON_ONCE(1); |
| 6000 | return; |
| 6001 | } |
| 6002 | ar->hw_params.hw_ops->set_coverage_class(ar, value); |
| 6003 | } |
| 6004 | |
Anilkumar Kolli | dd0f9cd | 2017-10-27 11:12:27 +0300 | [diff] [blame] | 6005 | struct ath10k_mac_tdls_iter_data { |
| 6006 | u32 num_tdls_stations; |
| 6007 | struct ieee80211_vif *curr_vif; |
| 6008 | }; |
| 6009 | |
| 6010 | static void ath10k_mac_tdls_vif_stations_count_iter(void *data, |
| 6011 | struct ieee80211_sta *sta) |
| 6012 | { |
| 6013 | struct ath10k_mac_tdls_iter_data *iter_data = data; |
| 6014 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 6015 | struct ieee80211_vif *sta_vif = arsta->arvif->vif; |
| 6016 | |
| 6017 | if (sta->tdls && sta_vif == iter_data->curr_vif) |
| 6018 | iter_data->num_tdls_stations++; |
| 6019 | } |
| 6020 | |
| 6021 | static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw, |
| 6022 | struct ieee80211_vif *vif) |
| 6023 | { |
| 6024 | struct ath10k_mac_tdls_iter_data data = {}; |
| 6025 | |
| 6026 | data.curr_vif = vif; |
| 6027 | |
| 6028 | ieee80211_iterate_stations_atomic(hw, |
| 6029 | ath10k_mac_tdls_vif_stations_count_iter, |
| 6030 | &data); |
| 6031 | return data.num_tdls_stations; |
| 6032 | } |
| 6033 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6034 | static int ath10k_hw_scan(struct ieee80211_hw *hw, |
| 6035 | struct ieee80211_vif *vif, |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 6036 | struct ieee80211_scan_request *hw_req) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6037 | { |
| 6038 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6039 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
David Spinadel | c56ef67 | 2014-02-05 15:21:13 +0200 | [diff] [blame] | 6040 | struct cfg80211_scan_request *req = &hw_req->req; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6041 | struct wmi_start_scan_arg arg; |
| 6042 | int ret = 0; |
| 6043 | int i; |
Pradeep Kumar Chitrapu | be8cce9 | 2018-05-23 11:09:09 +0300 | [diff] [blame] | 6044 | u32 scan_timeout; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6045 | |
| 6046 | mutex_lock(&ar->conf_mutex); |
| 6047 | |
Anilkumar Kolli | a608093 | 2017-10-27 11:12:28 +0300 | [diff] [blame] | 6048 | if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) { |
| 6049 | ret = -EBUSY; |
| 6050 | goto exit; |
| 6051 | } |
| 6052 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6053 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6054 | switch (ar->scan.state) { |
| 6055 | case ATH10K_SCAN_IDLE: |
| 6056 | reinit_completion(&ar->scan.started); |
| 6057 | reinit_completion(&ar->scan.completed); |
| 6058 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 6059 | ar->scan.is_roc = false; |
| 6060 | ar->scan.vdev_id = arvif->vdev_id; |
| 6061 | ret = 0; |
| 6062 | break; |
| 6063 | case ATH10K_SCAN_STARTING: |
| 6064 | case ATH10K_SCAN_RUNNING: |
| 6065 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6066 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6067 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6068 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6069 | spin_unlock_bh(&ar->data_lock); |
| 6070 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6071 | if (ret) |
| 6072 | goto exit; |
| 6073 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6074 | memset(&arg, 0, sizeof(arg)); |
| 6075 | ath10k_wmi_start_scan_init(ar, &arg); |
| 6076 | arg.vdev_id = arvif->vdev_id; |
| 6077 | arg.scan_id = ATH10K_SCAN_ID; |
| 6078 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6079 | if (req->ie_len) { |
| 6080 | arg.ie_len = req->ie_len; |
| 6081 | memcpy(arg.ie, req->ie, arg.ie_len); |
| 6082 | } |
| 6083 | |
| 6084 | if (req->n_ssids) { |
| 6085 | arg.n_ssids = req->n_ssids; |
| 6086 | for (i = 0; i < arg.n_ssids; i++) { |
| 6087 | arg.ssids[i].len = req->ssids[i].ssid_len; |
| 6088 | arg.ssids[i].ssid = req->ssids[i].ssid; |
| 6089 | } |
Michal Kazior | dcd4a56 | 2013-07-31 10:55:12 +0200 | [diff] [blame] | 6090 | } else { |
| 6091 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6092 | } |
| 6093 | |
Carl Huang | 60e1d0f | 2018-04-19 19:39:40 +0300 | [diff] [blame] | 6094 | if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6095 | arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ; |
| 6096 | ether_addr_copy(arg.mac_addr.addr, req->mac_addr); |
| 6097 | ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask); |
| 6098 | } |
| 6099 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6100 | if (req->n_channels) { |
| 6101 | arg.n_channels = req->n_channels; |
| 6102 | for (i = 0; i < arg.n_channels; i++) |
| 6103 | arg.channels[i] = req->channels[i]->center_freq; |
| 6104 | } |
| 6105 | |
Pradeep Kumar Chitrapu | be8cce9 | 2018-05-23 11:09:09 +0300 | [diff] [blame] | 6106 | /* if duration is set, default dwell times will be overwritten */ |
| 6107 | if (req->duration) { |
| 6108 | arg.dwell_time_active = req->duration; |
| 6109 | arg.dwell_time_passive = req->duration; |
| 6110 | arg.burst_duration_ms = req->duration; |
| 6111 | |
| 6112 | scan_timeout = min_t(u32, arg.max_rest_time * |
| 6113 | (arg.n_channels - 1) + (req->duration + |
| 6114 | ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) * |
| 6115 | arg.n_channels, arg.max_scan_time + 200); |
| 6116 | |
| 6117 | } else { |
| 6118 | /* Add a 200ms margin to account for event/command processing */ |
| 6119 | scan_timeout = arg.max_scan_time + 200; |
| 6120 | } |
| 6121 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6122 | ret = ath10k_start_scan(ar, &arg); |
| 6123 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6124 | ath10k_warn(ar, "failed to start hw scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6125 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6126 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6127 | spin_unlock_bh(&ar->data_lock); |
| 6128 | } |
| 6129 | |
Michal Kazior | 634349b | 2015-09-03 10:43:45 +0200 | [diff] [blame] | 6130 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
Pradeep Kumar Chitrapu | be8cce9 | 2018-05-23 11:09:09 +0300 | [diff] [blame] | 6131 | msecs_to_jiffies(scan_timeout)); |
Michal Kazior | 634349b | 2015-09-03 10:43:45 +0200 | [diff] [blame] | 6132 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6133 | exit: |
| 6134 | mutex_unlock(&ar->conf_mutex); |
| 6135 | return ret; |
| 6136 | } |
| 6137 | |
| 6138 | static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 6139 | struct ieee80211_vif *vif) |
| 6140 | { |
| 6141 | struct ath10k *ar = hw->priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6142 | |
| 6143 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6144 | ath10k_scan_abort(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6145 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 6146 | |
| 6147 | cancel_delayed_work_sync(&ar->scan.timeout); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6148 | } |
| 6149 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 6150 | static void ath10k_set_key_h_def_keyidx(struct ath10k *ar, |
| 6151 | struct ath10k_vif *arvif, |
| 6152 | enum set_key_cmd cmd, |
| 6153 | struct ieee80211_key_conf *key) |
| 6154 | { |
| 6155 | u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid; |
| 6156 | int ret; |
| 6157 | |
| 6158 | /* 10.1 firmware branch requires default key index to be set to group |
| 6159 | * key index after installing it. Otherwise FW/HW Txes corrupted |
| 6160 | * frames with multi-vif APs. This is not required for main firmware |
| 6161 | * branch (e.g. 636). |
| 6162 | * |
Michal Kazior | 8461baf | 2015-04-10 13:23:22 +0000 | [diff] [blame] | 6163 | * This is also needed for 636 fw for IBSS-RSN to work more reliably. |
| 6164 | * |
| 6165 | * FIXME: It remains unknown if this is required for multi-vif STA |
| 6166 | * interfaces on 10.1. |
| 6167 | */ |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 6168 | |
Michal Kazior | 8461baf | 2015-04-10 13:23:22 +0000 | [diff] [blame] | 6169 | if (arvif->vdev_type != WMI_VDEV_TYPE_AP && |
| 6170 | arvif->vdev_type != WMI_VDEV_TYPE_IBSS) |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 6171 | return; |
| 6172 | |
| 6173 | if (key->cipher == WLAN_CIPHER_SUITE_WEP40) |
| 6174 | return; |
| 6175 | |
| 6176 | if (key->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 6177 | return; |
| 6178 | |
| 6179 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 6180 | return; |
| 6181 | |
| 6182 | if (cmd != SET_KEY) |
| 6183 | return; |
| 6184 | |
| 6185 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, |
| 6186 | key->keyidx); |
| 6187 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6188 | 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] | 6189 | arvif->vdev_id, ret); |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 6190 | } |
| 6191 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6192 | static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 6193 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 6194 | struct ieee80211_key_conf *key) |
| 6195 | { |
| 6196 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6197 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6198 | struct ath10k_peer *peer; |
| 6199 | const u8 *peer_addr; |
| 6200 | bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 6201 | key->cipher == WLAN_CIPHER_SUITE_WEP104; |
| 6202 | int ret = 0; |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 6203 | int ret2; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 6204 | u32 flags = 0; |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 6205 | u32 flags2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6206 | |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 6207 | /* this one needs to be done in software */ |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 6208 | if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 6209 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 6210 | key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 || |
| 6211 | key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256) |
Bartosz Markowski | d7131c0 | 2015-03-10 14:32:19 +0100 | [diff] [blame] | 6212 | return 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6213 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 6214 | if (arvif->nohwcrypt) |
| 6215 | return 1; |
| 6216 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6217 | if (key->keyidx > WMI_MAX_KEY_INDEX) |
| 6218 | return -ENOSPC; |
| 6219 | |
| 6220 | mutex_lock(&ar->conf_mutex); |
| 6221 | |
| 6222 | if (sta) |
| 6223 | peer_addr = sta->addr; |
| 6224 | else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 6225 | peer_addr = vif->bss_conf.bssid; |
| 6226 | else |
| 6227 | peer_addr = vif->addr; |
| 6228 | |
| 6229 | key->hw_key_idx = key->keyidx; |
| 6230 | |
Michal Kazior | 7c8cc7e | 2015-04-01 22:53:19 +0300 | [diff] [blame] | 6231 | if (is_wep) { |
| 6232 | if (cmd == SET_KEY) |
| 6233 | arvif->wep_keys[key->keyidx] = key; |
| 6234 | else |
| 6235 | arvif->wep_keys[key->keyidx] = NULL; |
| 6236 | } |
| 6237 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6238 | /* the peer should not disappear in mid-way (unless FW goes awry) since |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 6239 | * we already hold conf_mutex. we just make sure its there now. |
| 6240 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6241 | spin_lock_bh(&ar->data_lock); |
| 6242 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 6243 | spin_unlock_bh(&ar->data_lock); |
| 6244 | |
| 6245 | if (!peer) { |
| 6246 | if (cmd == SET_KEY) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6247 | 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] | 6248 | peer_addr); |
| 6249 | ret = -EOPNOTSUPP; |
| 6250 | goto exit; |
| 6251 | } else { |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 6252 | /* if the peer doesn't exist there is no key to disable anymore */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6253 | goto exit; |
| 6254 | } |
| 6255 | } |
| 6256 | |
Michal Kazior | 7cc4573 | 2015-03-09 14:24:17 +0100 | [diff] [blame] | 6257 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 6258 | flags |= WMI_KEY_PAIRWISE; |
| 6259 | else |
| 6260 | flags |= WMI_KEY_GROUP; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6261 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6262 | if (is_wep) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6263 | if (cmd == DISABLE_KEY) |
| 6264 | ath10k_clear_vdev_key(arvif, key); |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 6265 | |
Michal Kazior | ad325cb | 2015-02-18 14:02:27 +0100 | [diff] [blame] | 6266 | /* When WEP keys are uploaded it's possible that there are |
| 6267 | * stations associated already (e.g. when merging) without any |
| 6268 | * keys. Static WEP needs an explicit per-peer key upload. |
| 6269 | */ |
| 6270 | if (vif->type == NL80211_IFTYPE_ADHOC && |
| 6271 | cmd == SET_KEY) |
| 6272 | ath10k_mac_vif_update_wep_key(arvif, key); |
| 6273 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 6274 | /* 802.1x never sets the def_wep_key_idx so each set_key() |
| 6275 | * call changes default tx key. |
| 6276 | * |
| 6277 | * Static WEP sets def_wep_key_idx via .set_default_unicast_key |
| 6278 | * after first set_key(). |
| 6279 | */ |
| 6280 | if (cmd == SET_KEY && arvif->def_wep_key_idx == -1) |
| 6281 | flags |= WMI_KEY_TX_USAGE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6282 | } |
| 6283 | |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 6284 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6285 | if (ret) { |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 6286 | WARN_ON(ret > 0); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6287 | 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] | 6288 | arvif->vdev_id, peer_addr, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6289 | goto exit; |
| 6290 | } |
| 6291 | |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 6292 | /* mac80211 sets static WEP keys as groupwise while firmware requires |
| 6293 | * them to be installed twice as both pairwise and groupwise. |
| 6294 | */ |
| 6295 | if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) { |
| 6296 | flags2 = flags; |
| 6297 | flags2 &= ~WMI_KEY_GROUP; |
| 6298 | flags2 |= WMI_KEY_PAIRWISE; |
| 6299 | |
| 6300 | ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2); |
| 6301 | if (ret) { |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 6302 | WARN_ON(ret > 0); |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 6303 | ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n", |
| 6304 | arvif->vdev_id, peer_addr, ret); |
| 6305 | ret2 = ath10k_install_key(arvif, key, DISABLE_KEY, |
| 6306 | peer_addr, flags); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 6307 | if (ret2) { |
| 6308 | WARN_ON(ret2 > 0); |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 6309 | ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n", |
| 6310 | arvif->vdev_id, peer_addr, ret2); |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 6311 | } |
Michal Kazior | 29a1000 | 2015-04-10 13:05:58 +0000 | [diff] [blame] | 6312 | goto exit; |
| 6313 | } |
| 6314 | } |
| 6315 | |
Michal Kazior | cfb27d2 | 2013-12-02 09:06:36 +0100 | [diff] [blame] | 6316 | ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key); |
| 6317 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6318 | spin_lock_bh(&ar->data_lock); |
| 6319 | peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr); |
| 6320 | if (peer && cmd == SET_KEY) |
| 6321 | peer->keys[key->keyidx] = key; |
| 6322 | else if (peer && cmd == DISABLE_KEY) |
| 6323 | peer->keys[key->keyidx] = NULL; |
| 6324 | else if (peer == NULL) |
| 6325 | /* impossible unless FW goes crazy */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6326 | ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6327 | spin_unlock_bh(&ar->data_lock); |
| 6328 | |
Yingying Tang | 9cdd005 | 2018-03-28 12:15:35 +0300 | [diff] [blame] | 6329 | if (sta && sta->tdls) |
| 6330 | ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 6331 | ar->wmi.peer_param->authorize, 1); |
Yingying Tang | 9cdd005 | 2018-03-28 12:15:35 +0300 | [diff] [blame] | 6332 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6333 | exit: |
| 6334 | mutex_unlock(&ar->conf_mutex); |
| 6335 | return ret; |
| 6336 | } |
| 6337 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 6338 | static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw, |
| 6339 | struct ieee80211_vif *vif, |
| 6340 | int keyidx) |
| 6341 | { |
| 6342 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6343 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 6344 | int ret; |
| 6345 | |
| 6346 | mutex_lock(&arvif->ar->conf_mutex); |
| 6347 | |
| 6348 | if (arvif->ar->state != ATH10K_STATE_ON) |
| 6349 | goto unlock; |
| 6350 | |
| 6351 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", |
| 6352 | arvif->vdev_id, keyidx); |
| 6353 | |
| 6354 | ret = ath10k_wmi_vdev_set_param(arvif->ar, |
| 6355 | arvif->vdev_id, |
| 6356 | arvif->ar->wmi.vdev_param->def_keyid, |
| 6357 | keyidx); |
| 6358 | |
| 6359 | if (ret) { |
| 6360 | ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n", |
| 6361 | arvif->vdev_id, |
| 6362 | ret); |
| 6363 | goto unlock; |
| 6364 | } |
| 6365 | |
| 6366 | arvif->def_wep_key_idx = keyidx; |
Michal Kazior | 370e567 | 2015-02-18 14:02:26 +0100 | [diff] [blame] | 6367 | |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 6368 | unlock: |
| 6369 | mutex_unlock(&arvif->ar->conf_mutex); |
| 6370 | } |
| 6371 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6372 | static void ath10k_sta_rc_update_wk(struct work_struct *wk) |
| 6373 | { |
| 6374 | struct ath10k *ar; |
| 6375 | struct ath10k_vif *arvif; |
| 6376 | struct ath10k_sta *arsta; |
| 6377 | struct ieee80211_sta *sta; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 6378 | struct cfg80211_chan_def def; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6379 | enum nl80211_band band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 6380 | const u8 *ht_mcs_mask; |
| 6381 | const u16 *vht_mcs_mask; |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6382 | u32 changed, bw, nss, smps; |
| 6383 | int err; |
| 6384 | |
| 6385 | arsta = container_of(wk, struct ath10k_sta, update_wk); |
| 6386 | sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); |
| 6387 | arvif = arsta->arvif; |
| 6388 | ar = arvif->ar; |
| 6389 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 6390 | if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) |
| 6391 | return; |
| 6392 | |
| 6393 | band = def.chan->band; |
| 6394 | ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs; |
| 6395 | vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs; |
| 6396 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6397 | spin_lock_bh(&ar->data_lock); |
| 6398 | |
| 6399 | changed = arsta->changed; |
| 6400 | arsta->changed = 0; |
| 6401 | |
| 6402 | bw = arsta->bw; |
| 6403 | nss = arsta->nss; |
| 6404 | smps = arsta->smps; |
| 6405 | |
| 6406 | spin_unlock_bh(&ar->data_lock); |
| 6407 | |
| 6408 | mutex_lock(&ar->conf_mutex); |
| 6409 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 6410 | nss = max_t(u32, 1, nss); |
| 6411 | nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask), |
| 6412 | ath10k_mac_max_vht_nss(vht_mcs_mask))); |
| 6413 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6414 | if (changed & IEEE80211_RC_BW_CHANGED) { |
Ryan Hsu | 9191fc2a | 2018-06-18 17:00:04 +0300 | [diff] [blame] | 6415 | enum wmi_phy_mode mode; |
| 6416 | |
| 6417 | mode = chan_to_phymode(&def); |
| 6418 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n", |
Kalle Valo | ebfac1d | 2018-07-30 21:56:43 +0300 | [diff] [blame] | 6419 | sta->addr, bw, mode); |
Ryan Hsu | 9191fc2a | 2018-06-18 17:00:04 +0300 | [diff] [blame] | 6420 | |
| 6421 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 6422 | ar->wmi.peer_param->phymode, mode); |
Ryan Hsu | 9191fc2a | 2018-06-18 17:00:04 +0300 | [diff] [blame] | 6423 | if (err) { |
| 6424 | ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n", |
Kalle Valo | ebfac1d | 2018-07-30 21:56:43 +0300 | [diff] [blame] | 6425 | sta->addr, mode, err); |
Ryan Hsu | 9191fc2a | 2018-06-18 17:00:04 +0300 | [diff] [blame] | 6426 | goto exit; |
| 6427 | } |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6428 | |
| 6429 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 6430 | ar->wmi.peer_param->chan_width, bw); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6431 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6432 | 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] | 6433 | sta->addr, bw, err); |
| 6434 | } |
| 6435 | |
| 6436 | if (changed & IEEE80211_RC_NSS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6437 | 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] | 6438 | sta->addr, nss); |
| 6439 | |
| 6440 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 6441 | ar->wmi.peer_param->nss, nss); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6442 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6443 | ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6444 | sta->addr, nss, err); |
| 6445 | } |
| 6446 | |
| 6447 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6448 | 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] | 6449 | sta->addr, smps); |
| 6450 | |
| 6451 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 6452 | ar->wmi.peer_param->smps_state, smps); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6453 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6454 | ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n", |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6455 | sta->addr, smps, err); |
| 6456 | } |
| 6457 | |
Karthikeyan Periyasamy | 55cc11d | 2018-03-27 11:25:29 +0300 | [diff] [blame] | 6458 | if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) { |
| 6459 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 6460 | sta->addr); |
| 6461 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6462 | err = ath10k_station_assoc(ar, arvif->vif, sta, true); |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 6463 | if (err) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6464 | ath10k_warn(ar, "failed to reassociate station: %pM\n", |
Chun-Yeow Yeoh | 44d6fa9 | 2014-03-07 10:19:30 +0200 | [diff] [blame] | 6465 | sta->addr); |
| 6466 | } |
| 6467 | |
Ryan Hsu | 9191fc2a | 2018-06-18 17:00:04 +0300 | [diff] [blame] | 6468 | exit: |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6469 | mutex_unlock(&ar->conf_mutex); |
| 6470 | } |
| 6471 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6472 | static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif, |
| 6473 | struct ieee80211_sta *sta) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 6474 | { |
| 6475 | struct ath10k *ar = arvif->ar; |
| 6476 | |
| 6477 | lockdep_assert_held(&ar->conf_mutex); |
| 6478 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6479 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 6480 | return 0; |
| 6481 | |
| 6482 | if (ar->num_stations >= ar->max_num_stations) |
| 6483 | return -ENOBUFS; |
| 6484 | |
| 6485 | ar->num_stations++; |
| 6486 | |
| 6487 | return 0; |
| 6488 | } |
| 6489 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6490 | static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif, |
| 6491 | struct ieee80211_sta *sta) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 6492 | { |
| 6493 | struct ath10k *ar = arvif->ar; |
| 6494 | |
| 6495 | lockdep_assert_held(&ar->conf_mutex); |
| 6496 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6497 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls) |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 6498 | return; |
| 6499 | |
| 6500 | ar->num_stations--; |
| 6501 | } |
| 6502 | |
Ashok Raj Nagarajan | 33410a5 | 2019-06-03 18:09:02 +0300 | [diff] [blame] | 6503 | static int ath10k_sta_set_txpwr(struct ieee80211_hw *hw, |
| 6504 | struct ieee80211_vif *vif, |
| 6505 | struct ieee80211_sta *sta) |
| 6506 | { |
| 6507 | struct ath10k *ar = hw->priv; |
| 6508 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 6509 | int ret = 0; |
| 6510 | s16 txpwr; |
| 6511 | |
| 6512 | if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) { |
| 6513 | txpwr = 0; |
| 6514 | } else { |
| 6515 | txpwr = sta->txpwr.power; |
| 6516 | if (!txpwr) |
| 6517 | return -EINVAL; |
| 6518 | } |
| 6519 | |
| 6520 | if (txpwr > ATH10K_TX_POWER_MAX_VAL || txpwr < ATH10K_TX_POWER_MIN_VAL) |
| 6521 | return -EINVAL; |
| 6522 | |
| 6523 | mutex_lock(&ar->conf_mutex); |
| 6524 | |
| 6525 | ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
Rakesh Pillai | c0e33fe | 2019-02-19 11:39:36 +0530 | [diff] [blame] | 6526 | ar->wmi.peer_param->use_fixed_power, txpwr); |
Ashok Raj Nagarajan | 33410a5 | 2019-06-03 18:09:02 +0300 | [diff] [blame] | 6527 | if (ret) { |
| 6528 | ath10k_warn(ar, "failed to set tx power for station ret: %d\n", |
| 6529 | ret); |
| 6530 | goto out; |
| 6531 | } |
| 6532 | |
| 6533 | out: |
| 6534 | mutex_unlock(&ar->conf_mutex); |
| 6535 | return ret; |
| 6536 | } |
| 6537 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6538 | static int ath10k_sta_state(struct ieee80211_hw *hw, |
| 6539 | struct ieee80211_vif *vif, |
| 6540 | struct ieee80211_sta *sta, |
| 6541 | enum ieee80211_sta_state old_state, |
| 6542 | enum ieee80211_sta_state new_state) |
| 6543 | { |
| 6544 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6545 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6546 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
Michal Kazior | bb8f0c6 | 2016-03-06 16:14:27 +0200 | [diff] [blame] | 6547 | struct ath10k_peer *peer; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6548 | int ret = 0; |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 6549 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6550 | |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 6551 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 6552 | new_state == IEEE80211_STA_NONE) { |
| 6553 | memset(arsta, 0, sizeof(*arsta)); |
| 6554 | arsta->arvif = arvif; |
Maharaja Kennadyrajan | d70c0d4 | 2018-09-18 12:04:27 +0530 | [diff] [blame] | 6555 | arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED; |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 6556 | INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 6557 | |
| 6558 | for (i = 0; i < ARRAY_SIZE(sta->txq); i++) |
| 6559 | ath10k_mac_txq_init(sta->txq[i]); |
Michal Kazior | 76f9002 | 2014-02-25 09:29:57 +0200 | [diff] [blame] | 6560 | } |
| 6561 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 6562 | /* cancel must be done outside the mutex to avoid deadlock */ |
| 6563 | if ((old_state == IEEE80211_STA_NONE && |
| 6564 | new_state == IEEE80211_STA_NOTEXIST)) |
| 6565 | cancel_work_sync(&arsta->update_wk); |
| 6566 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6567 | mutex_lock(&ar->conf_mutex); |
| 6568 | |
| 6569 | if (old_state == IEEE80211_STA_NOTEXIST && |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6570 | new_state == IEEE80211_STA_NONE) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6571 | /* |
| 6572 | * New station addition. |
| 6573 | */ |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6574 | enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT; |
| 6575 | u32 num_tdls_stations; |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6576 | |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 6577 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 6578 | "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n", |
| 6579 | arvif->vdev_id, sta->addr, |
| 6580 | ar->num_stations + 1, ar->max_num_stations, |
| 6581 | ar->num_peers + 1, ar->max_num_peers); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 6582 | |
Ryan Hsu | 9a993cc | 2017-05-31 14:21:28 +0300 | [diff] [blame] | 6583 | num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif); |
Ryan Hsu | 9a993cc | 2017-05-31 14:21:28 +0300 | [diff] [blame] | 6584 | |
| 6585 | if (sta->tdls) { |
| 6586 | if (num_tdls_stations >= ar->max_num_tdls_vdevs) { |
| 6587 | ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n", |
| 6588 | arvif->vdev_id, |
| 6589 | ar->max_num_tdls_vdevs); |
| 6590 | ret = -ELNRNG; |
| 6591 | goto exit; |
| 6592 | } |
| 6593 | peer_type = WMI_PEER_TYPE_TDLS; |
| 6594 | } |
| 6595 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6596 | ret = ath10k_mac_inc_num_stations(arvif, sta); |
Michal Kazior | cfd1061 | 2014-11-25 15:16:05 +0100 | [diff] [blame] | 6597 | if (ret) { |
| 6598 | ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n", |
| 6599 | ar->max_num_stations); |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 6600 | goto exit; |
| 6601 | } |
| 6602 | |
Zhi Chen | 386f97e | 2018-12-20 14:25:18 +0200 | [diff] [blame] | 6603 | if (ath10k_debug_is_extd_tx_stats_enabled(ar)) { |
| 6604 | arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), |
| 6605 | GFP_KERNEL); |
| 6606 | if (!arsta->tx_stats) { |
Zhi Chen | 402838a | 2019-11-06 20:04:42 +0200 | [diff] [blame] | 6607 | ath10k_mac_dec_num_stations(arvif, sta); |
Zhi Chen | 386f97e | 2018-12-20 14:25:18 +0200 | [diff] [blame] | 6608 | ret = -ENOMEM; |
| 6609 | goto exit; |
| 6610 | } |
| 6611 | } |
| 6612 | |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 6613 | ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id, |
| 6614 | sta->addr, peer_type); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 6615 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6616 | 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] | 6617 | sta->addr, arvif->vdev_id, ret); |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6618 | ath10k_mac_dec_num_stations(arvif, sta); |
Zhi Chen | 386f97e | 2018-12-20 14:25:18 +0200 | [diff] [blame] | 6619 | kfree(arsta->tx_stats); |
Michal Kazior | a52c028 | 2014-11-25 15:16:03 +0100 | [diff] [blame] | 6620 | goto exit; |
| 6621 | } |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6622 | |
Michal Kazior | bb8f0c6 | 2016-03-06 16:14:27 +0200 | [diff] [blame] | 6623 | spin_lock_bh(&ar->data_lock); |
| 6624 | |
| 6625 | peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr); |
| 6626 | if (!peer) { |
| 6627 | ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n", |
| 6628 | vif->addr, arvif->vdev_id); |
| 6629 | spin_unlock_bh(&ar->data_lock); |
| 6630 | ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 6631 | ath10k_mac_dec_num_stations(arvif, sta); |
Zhi Chen | 386f97e | 2018-12-20 14:25:18 +0200 | [diff] [blame] | 6632 | kfree(arsta->tx_stats); |
Michal Kazior | bb8f0c6 | 2016-03-06 16:14:27 +0200 | [diff] [blame] | 6633 | ret = -ENOENT; |
| 6634 | goto exit; |
| 6635 | } |
| 6636 | |
| 6637 | arsta->peer_id = find_first_bit(peer->peer_ids, |
| 6638 | ATH10K_MAX_NUM_PEER_IDS); |
| 6639 | |
| 6640 | spin_unlock_bh(&ar->data_lock); |
| 6641 | |
Bjorn Andersson | f4fe2e5 | 2019-11-13 12:26:44 -0800 | [diff] [blame] | 6642 | if (!sta->tdls) |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6643 | goto exit; |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6644 | |
Ryan Hsu | 9a993cc | 2017-05-31 14:21:28 +0300 | [diff] [blame] | 6645 | ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
| 6646 | WMI_TDLS_ENABLE_ACTIVE); |
| 6647 | if (ret) { |
| 6648 | ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n", |
| 6649 | arvif->vdev_id, ret); |
| 6650 | ath10k_peer_delete(ar, arvif->vdev_id, |
| 6651 | sta->addr); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6652 | ath10k_mac_dec_num_stations(arvif, sta); |
Zhi Chen | 386f97e | 2018-12-20 14:25:18 +0200 | [diff] [blame] | 6653 | kfree(arsta->tx_stats); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6654 | goto exit; |
| 6655 | } |
| 6656 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6657 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, |
| 6658 | WMI_TDLS_PEER_STATE_PEERING); |
| 6659 | if (ret) { |
| 6660 | ath10k_warn(ar, |
| 6661 | "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n", |
| 6662 | sta->addr, arvif->vdev_id, ret); |
| 6663 | ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 6664 | ath10k_mac_dec_num_stations(arvif, sta); |
Zhi Chen | 386f97e | 2018-12-20 14:25:18 +0200 | [diff] [blame] | 6665 | kfree(arsta->tx_stats); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6666 | |
| 6667 | if (num_tdls_stations != 0) |
| 6668 | goto exit; |
| 6669 | ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
| 6670 | WMI_TDLS_DISABLE); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6671 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6672 | } else if ((old_state == IEEE80211_STA_NONE && |
| 6673 | new_state == IEEE80211_STA_NOTEXIST)) { |
| 6674 | /* |
| 6675 | * Existing station deletion. |
| 6676 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6677 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Ben Greear | 3040420 | 2016-08-18 18:26:35 -0700 | [diff] [blame] | 6678 | "mac vdev %d peer delete %pM sta %pK (sta gone)\n", |
| 6679 | arvif->vdev_id, sta->addr, sta); |
Michal Kazior | 077efc8 | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6680 | |
Manikanta Pubbisetty | 424ea0d | 2017-11-06 13:39:31 +0530 | [diff] [blame] | 6681 | if (sta->tdls) { |
| 6682 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, |
| 6683 | sta, |
| 6684 | WMI_TDLS_PEER_STATE_TEARDOWN); |
| 6685 | if (ret) |
| 6686 | ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n", |
| 6687 | sta->addr, |
| 6688 | WMI_TDLS_PEER_STATE_TEARDOWN, ret); |
| 6689 | } |
| 6690 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6691 | ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr); |
| 6692 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6693 | 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] | 6694 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6695 | |
Marek Puzyniak | 7c35424 | 2015-03-30 09:51:52 +0300 | [diff] [blame] | 6696 | ath10k_mac_dec_num_stations(arvif, sta); |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6697 | |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 6698 | spin_lock_bh(&ar->data_lock); |
| 6699 | for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) { |
| 6700 | peer = ar->peer_map[i]; |
| 6701 | if (!peer) |
| 6702 | continue; |
| 6703 | |
| 6704 | if (peer->sta == sta) { |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 6705 | ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n", |
Ben Greear | d0eeafa | 2016-06-30 15:23:59 +0300 | [diff] [blame] | 6706 | sta->addr, peer, i, arvif->vdev_id); |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 6707 | peer->sta = NULL; |
Ben Greear | d0eeafa | 2016-06-30 15:23:59 +0300 | [diff] [blame] | 6708 | |
| 6709 | /* Clean up the peer object as well since we |
| 6710 | * must have failed to do this above. |
| 6711 | */ |
| 6712 | list_del(&peer->list); |
| 6713 | ar->peer_map[i] = NULL; |
| 6714 | kfree(peer); |
| 6715 | ar->num_peers--; |
Michal Kazior | 6942726 | 2016-03-06 16:14:30 +0200 | [diff] [blame] | 6716 | } |
| 6717 | } |
| 6718 | spin_unlock_bh(&ar->data_lock); |
| 6719 | |
Karthikeyan Periyasamy | 553a7cc | 2018-12-20 09:53:17 +0200 | [diff] [blame] | 6720 | if (ath10k_debug_is_extd_tx_stats_enabled(ar)) { |
| 6721 | kfree(arsta->tx_stats); |
| 6722 | arsta->tx_stats = NULL; |
| 6723 | } |
| 6724 | |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 6725 | for (i = 0; i < ARRAY_SIZE(sta->txq); i++) |
| 6726 | ath10k_mac_txq_unref(ar, sta->txq[i]); |
| 6727 | |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6728 | if (!sta->tdls) |
| 6729 | goto exit; |
| 6730 | |
| 6731 | if (ath10k_mac_tdls_vif_stations_count(hw, vif)) |
| 6732 | goto exit; |
| 6733 | |
| 6734 | /* This was the last tdls peer in current vif */ |
| 6735 | ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id, |
| 6736 | WMI_TDLS_DISABLE); |
| 6737 | if (ret) { |
| 6738 | ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n", |
| 6739 | arvif->vdev_id, ret); |
| 6740 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6741 | } else if (old_state == IEEE80211_STA_AUTH && |
| 6742 | new_state == IEEE80211_STA_ASSOC && |
| 6743 | (vif->type == NL80211_IFTYPE_AP || |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 6744 | vif->type == NL80211_IFTYPE_MESH_POINT || |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6745 | vif->type == NL80211_IFTYPE_ADHOC)) { |
| 6746 | /* |
| 6747 | * New association. |
| 6748 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6749 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 6750 | sta->addr); |
| 6751 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6752 | ret = ath10k_station_assoc(ar, vif, sta, false); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6753 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6754 | 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] | 6755 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6756 | } else if (old_state == IEEE80211_STA_ASSOC && |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6757 | new_state == IEEE80211_STA_AUTHORIZED && |
| 6758 | sta->tdls) { |
| 6759 | /* |
| 6760 | * Tdls station authorized. |
| 6761 | */ |
| 6762 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n", |
| 6763 | sta->addr); |
| 6764 | |
| 6765 | ret = ath10k_station_assoc(ar, vif, sta, false); |
| 6766 | if (ret) { |
| 6767 | ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n", |
| 6768 | sta->addr, arvif->vdev_id, ret); |
| 6769 | goto exit; |
| 6770 | } |
| 6771 | |
| 6772 | ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta, |
| 6773 | WMI_TDLS_PEER_STATE_CONNECTED); |
| 6774 | if (ret) |
| 6775 | ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n", |
| 6776 | sta->addr, arvif->vdev_id, ret); |
| 6777 | } else if (old_state == IEEE80211_STA_ASSOC && |
| 6778 | new_state == IEEE80211_STA_AUTH && |
| 6779 | (vif->type == NL80211_IFTYPE_AP || |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 6780 | vif->type == NL80211_IFTYPE_MESH_POINT || |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 6781 | vif->type == NL80211_IFTYPE_ADHOC)) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6782 | /* |
| 6783 | * Disassociation. |
| 6784 | */ |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6785 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n", |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 6786 | sta->addr); |
| 6787 | |
Michal Kazior | 590922a | 2014-10-21 10:10:29 +0300 | [diff] [blame] | 6788 | ret = ath10k_station_disassoc(ar, vif, sta); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6789 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6790 | ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n", |
Ben Greear | 69244e5 | 2014-02-27 18:50:00 +0200 | [diff] [blame] | 6791 | sta->addr, arvif->vdev_id, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6792 | } |
Bartosz Markowski | 0e759f3 | 2014-01-02 14:38:33 +0100 | [diff] [blame] | 6793 | exit: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6794 | mutex_unlock(&ar->conf_mutex); |
| 6795 | return ret; |
| 6796 | } |
| 6797 | |
| 6798 | 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] | 6799 | u16 ac, bool enable) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6800 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6801 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 6802 | struct wmi_sta_uapsd_auto_trig_arg arg = {}; |
| 6803 | u32 prio = 0, acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6804 | u32 value = 0; |
| 6805 | int ret = 0; |
| 6806 | |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 6807 | lockdep_assert_held(&ar->conf_mutex); |
| 6808 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6809 | if (arvif->vdev_type != WMI_VDEV_TYPE_STA) |
| 6810 | return 0; |
| 6811 | |
| 6812 | switch (ac) { |
| 6813 | case IEEE80211_AC_VO: |
| 6814 | value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN | |
| 6815 | WMI_STA_PS_UAPSD_AC3_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 6816 | prio = 7; |
| 6817 | acc = 3; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6818 | break; |
| 6819 | case IEEE80211_AC_VI: |
| 6820 | value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN | |
| 6821 | WMI_STA_PS_UAPSD_AC2_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 6822 | prio = 5; |
| 6823 | acc = 2; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6824 | break; |
| 6825 | case IEEE80211_AC_BE: |
| 6826 | value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN | |
| 6827 | WMI_STA_PS_UAPSD_AC1_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 6828 | prio = 2; |
| 6829 | acc = 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6830 | break; |
| 6831 | case IEEE80211_AC_BK: |
| 6832 | value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN | |
| 6833 | WMI_STA_PS_UAPSD_AC0_TRIGGER_EN; |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 6834 | prio = 0; |
| 6835 | acc = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6836 | break; |
| 6837 | } |
| 6838 | |
| 6839 | if (enable) |
| 6840 | arvif->u.sta.uapsd |= value; |
| 6841 | else |
| 6842 | arvif->u.sta.uapsd &= ~value; |
| 6843 | |
| 6844 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 6845 | WMI_STA_PS_PARAM_UAPSD, |
| 6846 | arvif->u.sta.uapsd); |
| 6847 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6848 | ath10k_warn(ar, "failed to set uapsd params: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6849 | goto exit; |
| 6850 | } |
| 6851 | |
| 6852 | if (arvif->u.sta.uapsd) |
| 6853 | value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD; |
| 6854 | else |
| 6855 | value = WMI_STA_PS_RX_WAKE_POLICY_WAKE; |
| 6856 | |
| 6857 | ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, |
| 6858 | WMI_STA_PS_PARAM_RX_WAKE_POLICY, |
| 6859 | value); |
| 6860 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6861 | ath10k_warn(ar, "failed to set rx wake param: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6862 | |
Michal Kazior | 9f9b574 | 2014-12-12 12:41:36 +0100 | [diff] [blame] | 6863 | ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif); |
| 6864 | if (ret) { |
| 6865 | ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n", |
| 6866 | arvif->vdev_id, ret); |
| 6867 | return ret; |
| 6868 | } |
| 6869 | |
| 6870 | ret = ath10k_mac_vif_recalc_ps_poll_count(arvif); |
| 6871 | if (ret) { |
| 6872 | ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n", |
| 6873 | arvif->vdev_id, ret); |
| 6874 | return ret; |
| 6875 | } |
| 6876 | |
Michal Kazior | b0e5615 | 2015-01-24 12:14:52 +0200 | [diff] [blame] | 6877 | if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) || |
| 6878 | test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) { |
| 6879 | /* Only userspace can make an educated decision when to send |
| 6880 | * trigger frame. The following effectively disables u-UAPSD |
| 6881 | * autotrigger in firmware (which is enabled by default |
| 6882 | * provided the autotrigger service is available). |
| 6883 | */ |
| 6884 | |
| 6885 | arg.wmm_ac = acc; |
| 6886 | arg.user_priority = prio; |
| 6887 | arg.service_interval = 0; |
| 6888 | arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 6889 | arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC; |
| 6890 | |
| 6891 | ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id, |
| 6892 | arvif->bssid, &arg, 1); |
| 6893 | if (ret) { |
| 6894 | ath10k_warn(ar, "failed to set uapsd auto trigger %d\n", |
| 6895 | ret); |
| 6896 | return ret; |
| 6897 | } |
| 6898 | } |
| 6899 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6900 | exit: |
| 6901 | return ret; |
| 6902 | } |
| 6903 | |
| 6904 | static int ath10k_conf_tx(struct ieee80211_hw *hw, |
| 6905 | struct ieee80211_vif *vif, u16 ac, |
| 6906 | const struct ieee80211_tx_queue_params *params) |
| 6907 | { |
| 6908 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6909 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6910 | struct wmi_wmm_params_arg *p = NULL; |
| 6911 | int ret; |
| 6912 | |
| 6913 | mutex_lock(&ar->conf_mutex); |
| 6914 | |
| 6915 | switch (ac) { |
| 6916 | case IEEE80211_AC_VO: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 6917 | p = &arvif->wmm_params.ac_vo; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6918 | break; |
| 6919 | case IEEE80211_AC_VI: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 6920 | p = &arvif->wmm_params.ac_vi; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6921 | break; |
| 6922 | case IEEE80211_AC_BE: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 6923 | p = &arvif->wmm_params.ac_be; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6924 | break; |
| 6925 | case IEEE80211_AC_BK: |
Michal Kazior | 5e752e4 | 2015-01-19 09:53:41 +0100 | [diff] [blame] | 6926 | p = &arvif->wmm_params.ac_bk; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6927 | break; |
| 6928 | } |
| 6929 | |
| 6930 | if (WARN_ON(!p)) { |
| 6931 | ret = -EINVAL; |
| 6932 | goto exit; |
| 6933 | } |
| 6934 | |
| 6935 | p->cwmin = params->cw_min; |
| 6936 | p->cwmax = params->cw_max; |
| 6937 | p->aifs = params->aifs; |
| 6938 | |
| 6939 | /* |
| 6940 | * The channel time duration programmed in the HW is in absolute |
| 6941 | * microseconds, while mac80211 gives the txop in units of |
| 6942 | * 32 microseconds. |
| 6943 | */ |
| 6944 | p->txop = params->txop * 32; |
| 6945 | |
Michal Kazior | 7fc979a | 2015-01-28 09:57:28 +0200 | [diff] [blame] | 6946 | if (ar->wmi.ops->gen_vdev_wmm_conf) { |
| 6947 | ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id, |
| 6948 | &arvif->wmm_params); |
| 6949 | if (ret) { |
| 6950 | ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n", |
| 6951 | arvif->vdev_id, ret); |
| 6952 | goto exit; |
| 6953 | } |
| 6954 | } else { |
| 6955 | /* This won't work well with multi-interface cases but it's |
| 6956 | * better than nothing. |
| 6957 | */ |
| 6958 | ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params); |
| 6959 | if (ret) { |
| 6960 | ath10k_warn(ar, "failed to set wmm params: %d\n", ret); |
| 6961 | goto exit; |
| 6962 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd); |
| 6966 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 6967 | ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6968 | |
| 6969 | exit: |
| 6970 | mutex_unlock(&ar->conf_mutex); |
| 6971 | return ret; |
| 6972 | } |
| 6973 | |
Kalle Valo | 14e105c | 2016-04-13 14:13:21 +0300 | [diff] [blame] | 6974 | #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6975 | |
| 6976 | static int ath10k_remain_on_channel(struct ieee80211_hw *hw, |
| 6977 | struct ieee80211_vif *vif, |
| 6978 | struct ieee80211_channel *chan, |
| 6979 | int duration, |
| 6980 | enum ieee80211_roc_type type) |
| 6981 | { |
| 6982 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 6983 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6984 | struct wmi_start_scan_arg arg; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6985 | int ret = 0; |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 6986 | u32 scan_time_msec; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6987 | |
| 6988 | mutex_lock(&ar->conf_mutex); |
| 6989 | |
Anilkumar Kolli | a608093 | 2017-10-27 11:12:28 +0300 | [diff] [blame] | 6990 | if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) { |
| 6991 | ret = -EBUSY; |
| 6992 | goto exit; |
| 6993 | } |
| 6994 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 6995 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 6996 | switch (ar->scan.state) { |
| 6997 | case ATH10K_SCAN_IDLE: |
| 6998 | reinit_completion(&ar->scan.started); |
| 6999 | reinit_completion(&ar->scan.completed); |
| 7000 | reinit_completion(&ar->scan.on_channel); |
| 7001 | ar->scan.state = ATH10K_SCAN_STARTING; |
| 7002 | ar->scan.is_roc = true; |
| 7003 | ar->scan.vdev_id = arvif->vdev_id; |
| 7004 | ar->scan.roc_freq = chan->center_freq; |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 7005 | ar->scan.roc_notify = true; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7006 | ret = 0; |
| 7007 | break; |
| 7008 | case ATH10K_SCAN_STARTING: |
| 7009 | case ATH10K_SCAN_RUNNING: |
| 7010 | case ATH10K_SCAN_ABORTING: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7011 | ret = -EBUSY; |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7012 | break; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7013 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7014 | spin_unlock_bh(&ar->data_lock); |
| 7015 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7016 | if (ret) |
| 7017 | goto exit; |
| 7018 | |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 7019 | scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2; |
Michal Kazior | dcca0bd | 2014-11-24 14:58:32 +0100 | [diff] [blame] | 7020 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7021 | memset(&arg, 0, sizeof(arg)); |
| 7022 | ath10k_wmi_start_scan_init(ar, &arg); |
| 7023 | arg.vdev_id = arvif->vdev_id; |
| 7024 | arg.scan_id = ATH10K_SCAN_ID; |
| 7025 | arg.n_channels = 1; |
| 7026 | arg.channels[0] = chan->center_freq; |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 7027 | arg.dwell_time_active = scan_time_msec; |
| 7028 | arg.dwell_time_passive = scan_time_msec; |
| 7029 | arg.max_scan_time = scan_time_msec; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7030 | arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE; |
| 7031 | arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ; |
Michal Kazior | dbd3f9f | 2015-03-31 11:03:48 +0000 | [diff] [blame] | 7032 | arg.burst_duration_ms = duration; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7033 | |
| 7034 | ret = ath10k_start_scan(ar, &arg); |
| 7035 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7036 | ath10k_warn(ar, "failed to start roc scan: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7037 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7038 | ar->scan.state = ATH10K_SCAN_IDLE; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7039 | spin_unlock_bh(&ar->data_lock); |
| 7040 | goto exit; |
| 7041 | } |
| 7042 | |
Kalle Valo | 14e105c | 2016-04-13 14:13:21 +0300 | [diff] [blame] | 7043 | ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7044 | if (ret == 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7045 | ath10k_warn(ar, "failed to switch to channel for roc scan\n"); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7046 | |
| 7047 | ret = ath10k_scan_stop(ar); |
| 7048 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7049 | ath10k_warn(ar, "failed to stop scan: %d\n", ret); |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7050 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7051 | ret = -ETIMEDOUT; |
| 7052 | goto exit; |
| 7053 | } |
| 7054 | |
Michal Kazior | fcf9844 | 2015-03-31 11:03:47 +0000 | [diff] [blame] | 7055 | ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout, |
| 7056 | msecs_to_jiffies(duration)); |
| 7057 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7058 | ret = 0; |
| 7059 | exit: |
| 7060 | mutex_unlock(&ar->conf_mutex); |
| 7061 | return ret; |
| 7062 | } |
| 7063 | |
Emmanuel Grumbach | 5db4c4b | 2019-07-23 21:00:01 +0300 | [diff] [blame] | 7064 | static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw, |
| 7065 | struct ieee80211_vif *vif) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7066 | { |
| 7067 | struct ath10k *ar = hw->priv; |
| 7068 | |
| 7069 | mutex_lock(&ar->conf_mutex); |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 7070 | |
| 7071 | spin_lock_bh(&ar->data_lock); |
| 7072 | ar->scan.roc_notify = false; |
| 7073 | spin_unlock_bh(&ar->data_lock); |
| 7074 | |
Michal Kazior | 5c81c7f | 2014-08-05 14:54:44 +0200 | [diff] [blame] | 7075 | ath10k_scan_abort(ar); |
Michal Kazior | d710e75 | 2015-07-09 13:08:36 +0200 | [diff] [blame] | 7076 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7077 | mutex_unlock(&ar->conf_mutex); |
| 7078 | |
Michal Kazior | 4eb2e16 | 2014-10-28 10:23:09 +0100 | [diff] [blame] | 7079 | cancel_delayed_work_sync(&ar->scan.timeout); |
| 7080 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7081 | return 0; |
| 7082 | } |
| 7083 | |
| 7084 | /* |
| 7085 | * Both RTS and Fragmentation threshold are interface-specific |
| 7086 | * in ath10k, but device-specific in mac80211. |
| 7087 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7088 | |
| 7089 | static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
| 7090 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7091 | struct ath10k *ar = hw->priv; |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 7092 | struct ath10k_vif *arvif; |
| 7093 | int ret = 0; |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 7094 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 7095 | mutex_lock(&ar->conf_mutex); |
| 7096 | list_for_each_entry(arvif, &ar->arvifs, list) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7097 | 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] | 7098 | arvif->vdev_id, value); |
Kalle Valo | 60c3daa | 2013-09-08 17:56:07 +0300 | [diff] [blame] | 7099 | |
Michal Kazior | ad088bf | 2013-10-16 15:44:46 +0300 | [diff] [blame] | 7100 | ret = ath10k_mac_set_rts(arvif, value); |
| 7101 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7102 | 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] | 7103 | arvif->vdev_id, ret); |
| 7104 | break; |
| 7105 | } |
| 7106 | } |
| 7107 | mutex_unlock(&ar->conf_mutex); |
| 7108 | |
| 7109 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7110 | } |
| 7111 | |
Michal Kazior | 92092fe | 2015-08-03 11:16:43 +0200 | [diff] [blame] | 7112 | static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value) |
| 7113 | { |
| 7114 | /* Even though there's a WMI enum for fragmentation threshold no known |
| 7115 | * firmware actually implements it. Moreover it is not possible to rely |
| 7116 | * frame fragmentation to mac80211 because firmware clears the "more |
| 7117 | * fragments" bit in frame control making it impossible for remote |
| 7118 | * devices to reassemble frames. |
| 7119 | * |
| 7120 | * Hence implement a dummy callback just to say fragmentation isn't |
| 7121 | * supported. This effectively prevents mac80211 from doing frame |
| 7122 | * fragmentation in software. |
| 7123 | */ |
| 7124 | return -EOPNOTSUPP; |
| 7125 | } |
| 7126 | |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7127 | void ath10k_mac_wait_tx_complete(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7128 | { |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7129 | bool skip; |
Nicholas Mc Guire | d4298a3 | 2015-06-15 14:46:43 +0300 | [diff] [blame] | 7130 | long time_left; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7131 | |
| 7132 | /* mac80211 doesn't care if we really xmit queued frames or not |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 7133 | * we'll collect those frames either way if we stop/delete vdevs |
| 7134 | */ |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 7135 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7136 | if (ar->state == ATH10K_STATE_WEDGED) |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7137 | return; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7138 | |
Nicholas Mc Guire | d4298a3 | 2015-06-15 14:46:43 +0300 | [diff] [blame] | 7139 | time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7140 | bool empty; |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7141 | |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 7142 | spin_lock_bh(&ar->htt.tx_lock); |
Michal Kazior | 0945baf | 2013-09-18 14:43:18 +0200 | [diff] [blame] | 7143 | empty = (ar->htt.num_pending_tx == 0); |
Michal Kazior | edb8236 | 2013-07-05 16:15:14 +0300 | [diff] [blame] | 7144 | spin_unlock_bh(&ar->htt.tx_lock); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7145 | |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 7146 | skip = (ar->state == ATH10K_STATE_WEDGED) || |
| 7147 | test_bit(ATH10K_FLAG_CRASH_FLUSH, |
| 7148 | &ar->dev_flags); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7149 | |
| 7150 | (empty || skip); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7151 | }), ATH10K_FLUSH_TIMEOUT_HZ); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7152 | |
Nicholas Mc Guire | d4298a3 | 2015-06-15 14:46:43 +0300 | [diff] [blame] | 7153 | if (time_left == 0 || skip) |
| 7154 | ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n", |
| 7155 | skip, ar->state, time_left); |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7156 | } |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 7157 | |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7158 | static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 7159 | u32 queues, bool drop) |
| 7160 | { |
| 7161 | struct ath10k *ar = hw->priv; |
Wen Gong | 9de4162 | 2018-10-08 17:02:43 +0800 | [diff] [blame] | 7162 | struct ath10k_vif *arvif; |
| 7163 | u32 bitmap; |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7164 | |
Wen Gong | 9de4162 | 2018-10-08 17:02:43 +0800 | [diff] [blame] | 7165 | if (drop) { |
Brian Norris | d987f78 | 2018-11-07 16:40:35 -0800 | [diff] [blame] | 7166 | if (vif && vif->type == NL80211_IFTYPE_STATION) { |
Wen Gong | 9de4162 | 2018-10-08 17:02:43 +0800 | [diff] [blame] | 7167 | bitmap = ~(1 << WMI_MGMT_TID); |
| 7168 | list_for_each_entry(arvif, &ar->arvifs, list) { |
| 7169 | if (arvif->vdev_type == WMI_VDEV_TYPE_STA) |
| 7170 | ath10k_wmi_peer_flush(ar, arvif->vdev_id, |
| 7171 | arvif->bssid, bitmap); |
| 7172 | } |
| 7173 | } |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7174 | return; |
Wen Gong | 9de4162 | 2018-10-08 17:02:43 +0800 | [diff] [blame] | 7175 | } |
Wen Gong | 828853a | 2018-08-28 19:48:42 +0300 | [diff] [blame] | 7176 | |
| 7177 | mutex_lock(&ar->conf_mutex); |
| 7178 | ath10k_mac_wait_tx_complete(ar); |
Michal Kazior | 548db54 | 2013-07-05 16:15:15 +0300 | [diff] [blame] | 7179 | mutex_unlock(&ar->conf_mutex); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 7180 | } |
| 7181 | |
| 7182 | /* TODO: Implement this function properly |
| 7183 | * For now it is needed to reply to Probe Requests in IBSS mode. |
| 7184 | * Propably we need this information from FW. |
| 7185 | */ |
| 7186 | static int ath10k_tx_last_beacon(struct ieee80211_hw *hw) |
| 7187 | { |
| 7188 | return 1; |
| 7189 | } |
| 7190 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 7191 | static void ath10k_reconfig_complete(struct ieee80211_hw *hw, |
| 7192 | enum ieee80211_reconfig_type reconfig_type) |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7193 | { |
| 7194 | struct ath10k *ar = hw->priv; |
| 7195 | |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 7196 | if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART) |
| 7197 | return; |
| 7198 | |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7199 | mutex_lock(&ar->conf_mutex); |
| 7200 | |
| 7201 | /* If device failed to restart it will be in a different state, e.g. |
Marcin Rokicki | d6dfe25c | 2017-02-20 14:39:57 +0100 | [diff] [blame] | 7202 | * ATH10K_STATE_WEDGED |
| 7203 | */ |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7204 | if (ar->state == ATH10K_STATE_RESTARTED) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7205 | ath10k_info(ar, "device successfully recovered\n"); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7206 | ar->state = ATH10K_STATE_ON; |
Michal Kazior | 7962b0d | 2014-10-28 10:34:38 +0100 | [diff] [blame] | 7207 | ieee80211_wake_queues(ar->hw); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 7208 | } |
| 7209 | |
| 7210 | mutex_unlock(&ar->conf_mutex); |
| 7211 | } |
| 7212 | |
Rajkumar Manoharan | fa7937e | 2016-04-27 16:23:22 +0530 | [diff] [blame] | 7213 | static void |
| 7214 | ath10k_mac_update_bss_chan_survey(struct ath10k *ar, |
| 7215 | struct ieee80211_channel *channel) |
| 7216 | { |
| 7217 | int ret; |
| 7218 | enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR; |
| 7219 | |
| 7220 | lockdep_assert_held(&ar->conf_mutex); |
| 7221 | |
| 7222 | if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) || |
| 7223 | (ar->rx_channel != channel)) |
| 7224 | return; |
| 7225 | |
| 7226 | if (ar->scan.state != ATH10K_SCAN_IDLE) { |
| 7227 | ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n"); |
| 7228 | return; |
| 7229 | } |
| 7230 | |
| 7231 | reinit_completion(&ar->bss_survey_done); |
| 7232 | |
| 7233 | ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type); |
| 7234 | if (ret) { |
| 7235 | ath10k_warn(ar, "failed to send pdev bss chan info request\n"); |
| 7236 | return; |
| 7237 | } |
| 7238 | |
| 7239 | ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ); |
| 7240 | if (!ret) { |
| 7241 | ath10k_warn(ar, "bss channel survey timed out\n"); |
| 7242 | return; |
| 7243 | } |
| 7244 | } |
| 7245 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 7246 | static int ath10k_get_survey(struct ieee80211_hw *hw, int idx, |
| 7247 | struct survey_info *survey) |
| 7248 | { |
| 7249 | struct ath10k *ar = hw->priv; |
| 7250 | struct ieee80211_supported_band *sband; |
| 7251 | struct survey_info *ar_survey = &ar->survey[idx]; |
| 7252 | int ret = 0; |
| 7253 | |
| 7254 | mutex_lock(&ar->conf_mutex); |
| 7255 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7256 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 7257 | if (sband && idx >= sband->n_channels) { |
| 7258 | idx -= sband->n_channels; |
| 7259 | sband = NULL; |
| 7260 | } |
| 7261 | |
| 7262 | if (!sband) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7263 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 7264 | |
| 7265 | if (!sband || idx >= sband->n_channels) { |
| 7266 | ret = -ENOENT; |
| 7267 | goto exit; |
| 7268 | } |
| 7269 | |
Ashok Raj Nagarajan | 77eb3d6 | 2016-09-02 10:59:53 +0530 | [diff] [blame] | 7270 | ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]); |
Rajkumar Manoharan | fa7937e | 2016-04-27 16:23:22 +0530 | [diff] [blame] | 7271 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 7272 | spin_lock_bh(&ar->data_lock); |
| 7273 | memcpy(survey, ar_survey, sizeof(*survey)); |
| 7274 | spin_unlock_bh(&ar->data_lock); |
| 7275 | |
| 7276 | survey->channel = &sband->channels[idx]; |
| 7277 | |
Felix Fietkau | fa1d4df | 2014-10-23 17:04:28 +0300 | [diff] [blame] | 7278 | if (ar->rx_channel == survey->channel) |
| 7279 | survey->filled |= SURVEY_INFO_IN_USE; |
| 7280 | |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 7281 | exit: |
| 7282 | mutex_unlock(&ar->conf_mutex); |
| 7283 | return ret; |
| 7284 | } |
| 7285 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7286 | static bool |
| 7287 | ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7288 | enum nl80211_band band, |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7289 | const struct cfg80211_bitrate_mask *mask, |
| 7290 | int *vht_num_rates) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7291 | { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7292 | int num_rates = 0; |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7293 | int i, tmp; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7294 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7295 | num_rates += hweight32(mask->control[band].legacy); |
| 7296 | |
| 7297 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) |
| 7298 | num_rates += hweight8(mask->control[band].ht_mcs[i]); |
| 7299 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7300 | *vht_num_rates = 0; |
| 7301 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 7302 | tmp = hweight16(mask->control[band].vht_mcs[i]); |
| 7303 | num_rates += tmp; |
| 7304 | *vht_num_rates += tmp; |
| 7305 | } |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7306 | |
| 7307 | return num_rates == 1; |
| 7308 | } |
| 7309 | |
| 7310 | static bool |
| 7311 | ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7312 | enum nl80211_band band, |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7313 | const struct cfg80211_bitrate_mask *mask, |
| 7314 | int *nss) |
| 7315 | { |
| 7316 | struct ieee80211_supported_band *sband = &ar->mac.sbands[band]; |
| 7317 | u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7318 | u8 ht_nss_mask = 0; |
| 7319 | u8 vht_nss_mask = 0; |
| 7320 | int i; |
| 7321 | |
| 7322 | if (mask->control[band].legacy) |
| 7323 | return false; |
| 7324 | |
| 7325 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
| 7326 | if (mask->control[band].ht_mcs[i] == 0) |
| 7327 | continue; |
| 7328 | else if (mask->control[band].ht_mcs[i] == |
| 7329 | sband->ht_cap.mcs.rx_mask[i]) |
| 7330 | ht_nss_mask |= BIT(i); |
| 7331 | else |
| 7332 | return false; |
| 7333 | } |
| 7334 | |
| 7335 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 7336 | if (mask->control[band].vht_mcs[i] == 0) |
| 7337 | continue; |
| 7338 | else if (mask->control[band].vht_mcs[i] == |
| 7339 | ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i)) |
| 7340 | vht_nss_mask |= BIT(i); |
| 7341 | else |
| 7342 | return false; |
| 7343 | } |
| 7344 | |
| 7345 | if (ht_nss_mask != vht_nss_mask) |
| 7346 | return false; |
| 7347 | |
| 7348 | if (ht_nss_mask == 0) |
| 7349 | return false; |
| 7350 | |
| 7351 | if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask) |
| 7352 | return false; |
| 7353 | |
| 7354 | *nss = fls(ht_nss_mask); |
| 7355 | |
| 7356 | return true; |
| 7357 | } |
| 7358 | |
| 7359 | static int |
| 7360 | ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7361 | enum nl80211_band band, |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7362 | const struct cfg80211_bitrate_mask *mask, |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7363 | u8 *rate, u8 *nss, bool vht_only) |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7364 | { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7365 | int rate_idx; |
| 7366 | int i; |
| 7367 | u16 bitrate; |
| 7368 | u8 preamble; |
| 7369 | u8 hw_rate; |
| 7370 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7371 | if (vht_only) |
| 7372 | goto next; |
| 7373 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7374 | if (hweight32(mask->control[band].legacy) == 1) { |
| 7375 | rate_idx = ffs(mask->control[band].legacy) - 1; |
| 7376 | |
Pradeep Kumar Chitrapu | cd93b83 | 2018-07-25 10:59:39 +0300 | [diff] [blame] | 7377 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) |
| 7378 | rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX; |
| 7379 | |
| 7380 | hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value; |
| 7381 | bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7382 | |
| 7383 | if (ath10k_mac_bitrate_is_cck(bitrate)) |
| 7384 | preamble = WMI_RATE_PREAMBLE_CCK; |
| 7385 | else |
| 7386 | preamble = WMI_RATE_PREAMBLE_OFDM; |
| 7387 | |
| 7388 | *nss = 1; |
| 7389 | *rate = preamble << 6 | |
| 7390 | (*nss - 1) << 4 | |
| 7391 | hw_rate << 0; |
| 7392 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7393 | return 0; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7394 | } |
| 7395 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7396 | for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) { |
| 7397 | if (hweight8(mask->control[band].ht_mcs[i]) == 1) { |
| 7398 | *nss = i + 1; |
| 7399 | *rate = WMI_RATE_PREAMBLE_HT << 6 | |
| 7400 | (*nss - 1) << 4 | |
| 7401 | (ffs(mask->control[band].ht_mcs[i]) - 1); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7402 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7403 | return 0; |
| 7404 | } |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7405 | } |
| 7406 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7407 | next: |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7408 | for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) { |
| 7409 | if (hweight16(mask->control[band].vht_mcs[i]) == 1) { |
| 7410 | *nss = i + 1; |
| 7411 | *rate = WMI_RATE_PREAMBLE_VHT << 6 | |
| 7412 | (*nss - 1) << 4 | |
| 7413 | (ffs(mask->control[band].vht_mcs[i]) - 1); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7414 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7415 | return 0; |
| 7416 | } |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7417 | } |
| 7418 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7419 | return -EINVAL; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7420 | } |
| 7421 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7422 | static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif, |
Rajkumar Manoharan | bd4a41e | 2015-09-16 13:19:00 +0530 | [diff] [blame] | 7423 | u8 rate, u8 nss, u8 sgi, u8 ldpc) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7424 | { |
| 7425 | struct ath10k *ar = arvif->ar; |
| 7426 | u32 vdev_param; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7427 | int ret; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7428 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7429 | lockdep_assert_held(&ar->conf_mutex); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7430 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7431 | ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n", |
| 7432 | arvif->vdev_id, rate, nss, sgi); |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 7433 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7434 | vdev_param = ar->wmi.vdev_param->fixed_rate; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7435 | 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] | 7436 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7437 | 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] | 7438 | rate, ret); |
| 7439 | return ret; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7440 | } |
| 7441 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7442 | vdev_param = ar->wmi.vdev_param->nss; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7443 | 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] | 7444 | if (ret) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7445 | ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret); |
| 7446 | return ret; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7447 | } |
| 7448 | |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 7449 | vdev_param = ar->wmi.vdev_param->sgi; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7450 | 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] | 7451 | if (ret) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7452 | ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret); |
| 7453 | return ret; |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 7454 | } |
| 7455 | |
Rajkumar Manoharan | bd4a41e | 2015-09-16 13:19:00 +0530 | [diff] [blame] | 7456 | vdev_param = ar->wmi.vdev_param->ldpc; |
| 7457 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc); |
| 7458 | if (ret) { |
| 7459 | ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret); |
| 7460 | return ret; |
| 7461 | } |
| 7462 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7463 | return 0; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7464 | } |
| 7465 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7466 | static bool |
| 7467 | ath10k_mac_can_set_bitrate_mask(struct ath10k *ar, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7468 | enum nl80211_band band, |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7469 | const struct cfg80211_bitrate_mask *mask, |
| 7470 | bool allow_pfr) |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7471 | { |
| 7472 | int i; |
| 7473 | u16 vht_mcs; |
| 7474 | |
| 7475 | /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible |
| 7476 | * to express all VHT MCS rate masks. Effectively only the following |
| 7477 | * ranges can be used: none, 0-7, 0-8 and 0-9. |
| 7478 | */ |
| 7479 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7480 | vht_mcs = mask->control[band].vht_mcs[i]; |
| 7481 | |
| 7482 | switch (vht_mcs) { |
| 7483 | case 0: |
| 7484 | case BIT(8) - 1: |
| 7485 | case BIT(9) - 1: |
| 7486 | case BIT(10) - 1: |
| 7487 | break; |
| 7488 | default: |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7489 | if (!allow_pfr) |
| 7490 | ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n"); |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7491 | return false; |
| 7492 | } |
| 7493 | } |
| 7494 | |
| 7495 | return true; |
| 7496 | } |
| 7497 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7498 | static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k *ar, |
| 7499 | struct ath10k_vif *arvif, |
| 7500 | struct ieee80211_sta *sta) |
| 7501 | { |
| 7502 | int err; |
| 7503 | u8 rate = arvif->vht_pfr; |
| 7504 | |
| 7505 | /* skip non vht and multiple rate peers */ |
| 7506 | if (!sta->vht_cap.vht_supported || arvif->vht_num_rates != 1) |
| 7507 | return false; |
| 7508 | |
| 7509 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 7510 | WMI_PEER_PARAM_FIXED_RATE, rate); |
| 7511 | if (err) |
Colin Ian King | 0976465 | 2019-09-13 08:43:39 +0100 | [diff] [blame] | 7512 | ath10k_warn(ar, "failed to enable STA %pM peer fixed rate: %d\n", |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7513 | sta->addr, err); |
| 7514 | |
| 7515 | return true; |
| 7516 | } |
| 7517 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7518 | static void ath10k_mac_set_bitrate_mask_iter(void *data, |
| 7519 | struct ieee80211_sta *sta) |
| 7520 | { |
| 7521 | struct ath10k_vif *arvif = data; |
| 7522 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 7523 | struct ath10k *ar = arvif->ar; |
| 7524 | |
| 7525 | if (arsta->arvif != arvif) |
| 7526 | return; |
| 7527 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7528 | if (ath10k_mac_set_vht_bitrate_mask_fixup(ar, arvif, sta)) |
| 7529 | return; |
| 7530 | |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7531 | spin_lock_bh(&ar->data_lock); |
| 7532 | arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED; |
| 7533 | spin_unlock_bh(&ar->data_lock); |
| 7534 | |
| 7535 | ieee80211_queue_work(ar->hw, &arsta->update_wk); |
| 7536 | } |
| 7537 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7538 | static void ath10k_mac_clr_bitrate_mask_iter(void *data, |
| 7539 | struct ieee80211_sta *sta) |
| 7540 | { |
| 7541 | struct ath10k_vif *arvif = data; |
| 7542 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 7543 | struct ath10k *ar = arvif->ar; |
| 7544 | int err; |
| 7545 | |
| 7546 | /* clear vht peers only */ |
| 7547 | if (arsta->arvif != arvif || !sta->vht_cap.vht_supported) |
| 7548 | return; |
| 7549 | |
| 7550 | err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr, |
| 7551 | WMI_PEER_PARAM_FIXED_RATE, |
| 7552 | WMI_FIXED_RATE_NONE); |
| 7553 | if (err) |
| 7554 | ath10k_warn(ar, "failed to clear STA %pM peer fixed rate: %d\n", |
| 7555 | sta->addr, err); |
| 7556 | } |
| 7557 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7558 | static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, |
| 7559 | struct ieee80211_vif *vif, |
| 7560 | const struct cfg80211_bitrate_mask *mask) |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7561 | { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 7562 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7563 | struct cfg80211_chan_def def; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7564 | struct ath10k *ar = arvif->ar; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7565 | enum nl80211_band band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7566 | const u8 *ht_mcs_mask; |
| 7567 | const u16 *vht_mcs_mask; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7568 | u8 rate; |
| 7569 | u8 nss; |
| 7570 | u8 sgi; |
Rajkumar Manoharan | bd4a41e | 2015-09-16 13:19:00 +0530 | [diff] [blame] | 7571 | u8 ldpc; |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7572 | int single_nss; |
| 7573 | int ret; |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7574 | int vht_num_rates, allow_pfr; |
| 7575 | u8 vht_pfr; |
| 7576 | bool update_bitrate_mask = true; |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 7577 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7578 | if (ath10k_mac_vif_chan(vif, &def)) |
| 7579 | return -EPERM; |
| 7580 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7581 | band = def.chan->band; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7582 | ht_mcs_mask = mask->control[band].ht_mcs; |
| 7583 | vht_mcs_mask = mask->control[band].vht_mcs; |
Rajkumar Manoharan | bd4a41e | 2015-09-16 13:19:00 +0530 | [diff] [blame] | 7584 | ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7585 | |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7586 | sgi = mask->control[band].gi; |
| 7587 | if (sgi == NL80211_TXRATE_FORCE_LGI) |
Janusz Dziedzic | 9f81f72 | 2014-01-17 20:04:14 +0100 | [diff] [blame] | 7588 | return -EINVAL; |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7589 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7590 | allow_pfr = test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE, |
| 7591 | ar->normal_mode_fw.fw_file.fw_features); |
| 7592 | if (allow_pfr) { |
| 7593 | mutex_lock(&ar->conf_mutex); |
| 7594 | ieee80211_iterate_stations_atomic(ar->hw, |
| 7595 | ath10k_mac_clr_bitrate_mask_iter, |
| 7596 | arvif); |
| 7597 | mutex_unlock(&ar->conf_mutex); |
| 7598 | } |
| 7599 | |
| 7600 | if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask, |
| 7601 | &vht_num_rates)) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7602 | ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask, |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7603 | &rate, &nss, |
| 7604 | false); |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7605 | if (ret) { |
| 7606 | ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n", |
| 7607 | arvif->vdev_id, ret); |
| 7608 | return ret; |
| 7609 | } |
| 7610 | } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask, |
| 7611 | &single_nss)) { |
| 7612 | rate = WMI_FIXED_RATE_NONE; |
| 7613 | nss = single_nss; |
| 7614 | } else { |
| 7615 | rate = WMI_FIXED_RATE_NONE; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7616 | nss = min(ar->num_rf_chains, |
| 7617 | max(ath10k_mac_max_ht_nss(ht_mcs_mask), |
| 7618 | ath10k_mac_max_vht_nss(vht_mcs_mask))); |
| 7619 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7620 | if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask, |
| 7621 | allow_pfr)) { |
| 7622 | u8 vht_nss; |
| 7623 | |
| 7624 | if (!allow_pfr || vht_num_rates != 1) |
| 7625 | return -EINVAL; |
| 7626 | |
| 7627 | /* Reach here, firmware supports peer fixed rate and has |
| 7628 | * single vht rate, and don't update vif birate_mask, as |
| 7629 | * the rate only for specific peer. |
| 7630 | */ |
| 7631 | ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask, |
| 7632 | &vht_pfr, |
| 7633 | &vht_nss, |
| 7634 | true); |
| 7635 | update_bitrate_mask = false; |
Arnd Bergmann | ff414f3 | 2019-07-08 14:50:06 +0200 | [diff] [blame] | 7636 | } else { |
| 7637 | vht_pfr = 0; |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7638 | } |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7639 | |
| 7640 | mutex_lock(&ar->conf_mutex); |
| 7641 | |
Miaoqing Pan | 8b97b05 | 2019-05-29 16:13:28 +0800 | [diff] [blame] | 7642 | if (update_bitrate_mask) |
| 7643 | arvif->bitrate_mask = *mask; |
| 7644 | arvif->vht_num_rates = vht_num_rates; |
| 7645 | arvif->vht_pfr = vht_pfr; |
Michal Kazior | 45c9abc | 2015-04-21 20:42:58 +0300 | [diff] [blame] | 7646 | ieee80211_iterate_stations_atomic(ar->hw, |
| 7647 | ath10k_mac_set_bitrate_mask_iter, |
| 7648 | arvif); |
| 7649 | |
| 7650 | mutex_unlock(&ar->conf_mutex); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7651 | } |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7652 | |
| 7653 | mutex_lock(&ar->conf_mutex); |
| 7654 | |
Rajkumar Manoharan | bd4a41e | 2015-09-16 13:19:00 +0530 | [diff] [blame] | 7655 | ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7656 | if (ret) { |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7657 | ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n", |
| 7658 | arvif->vdev_id, ret); |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7659 | goto exit; |
| 7660 | } |
| 7661 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7662 | exit: |
| 7663 | mutex_unlock(&ar->conf_mutex); |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 7664 | |
Janusz Dziedzic | 51ab1a0 | 2014-01-08 09:08:33 +0100 | [diff] [blame] | 7665 | return ret; |
| 7666 | } |
| 7667 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 7668 | static void ath10k_sta_rc_update(struct ieee80211_hw *hw, |
| 7669 | struct ieee80211_vif *vif, |
| 7670 | struct ieee80211_sta *sta, |
| 7671 | u32 changed) |
| 7672 | { |
| 7673 | struct ath10k *ar = hw->priv; |
| 7674 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
Karthikeyan Periyasamy | 8b2d93d | 2018-03-12 17:09:40 +0530 | [diff] [blame] | 7675 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 7676 | struct ath10k_peer *peer; |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 7677 | u32 bw, smps; |
| 7678 | |
| 7679 | spin_lock_bh(&ar->data_lock); |
| 7680 | |
Karthikeyan Periyasamy | 8b2d93d | 2018-03-12 17:09:40 +0530 | [diff] [blame] | 7681 | peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr); |
| 7682 | if (!peer) { |
| 7683 | spin_unlock_bh(&ar->data_lock); |
| 7684 | ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n", |
| 7685 | sta->addr, arvif->vdev_id); |
| 7686 | return; |
| 7687 | } |
| 7688 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7689 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 7690 | "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n", |
| 7691 | sta->addr, changed, sta->bandwidth, sta->rx_nss, |
| 7692 | sta->smps_mode); |
| 7693 | |
| 7694 | if (changed & IEEE80211_RC_BW_CHANGED) { |
| 7695 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 7696 | |
| 7697 | switch (sta->bandwidth) { |
| 7698 | case IEEE80211_STA_RX_BW_20: |
| 7699 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 7700 | break; |
| 7701 | case IEEE80211_STA_RX_BW_40: |
| 7702 | bw = WMI_PEER_CHWIDTH_40MHZ; |
| 7703 | break; |
| 7704 | case IEEE80211_STA_RX_BW_80: |
| 7705 | bw = WMI_PEER_CHWIDTH_80MHZ; |
| 7706 | break; |
| 7707 | case IEEE80211_STA_RX_BW_160: |
Sebastian Gottschall | bc1efd7 | 2017-01-12 13:02:12 +0200 | [diff] [blame] | 7708 | bw = WMI_PEER_CHWIDTH_160MHZ; |
| 7709 | break; |
| 7710 | default: |
Masanari Iida | d939be3 | 2015-02-27 23:52:31 +0900 | [diff] [blame] | 7711 | ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n", |
Kalle Valo | be6546f | 2014-03-25 14:18:51 +0200 | [diff] [blame] | 7712 | sta->bandwidth, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 7713 | bw = WMI_PEER_CHWIDTH_20MHZ; |
| 7714 | break; |
| 7715 | } |
| 7716 | |
| 7717 | arsta->bw = bw; |
| 7718 | } |
| 7719 | |
| 7720 | if (changed & IEEE80211_RC_NSS_CHANGED) |
| 7721 | arsta->nss = sta->rx_nss; |
| 7722 | |
| 7723 | if (changed & IEEE80211_RC_SMPS_CHANGED) { |
| 7724 | smps = WMI_PEER_SMPS_PS_NONE; |
| 7725 | |
| 7726 | switch (sta->smps_mode) { |
| 7727 | case IEEE80211_SMPS_AUTOMATIC: |
| 7728 | case IEEE80211_SMPS_OFF: |
| 7729 | smps = WMI_PEER_SMPS_PS_NONE; |
| 7730 | break; |
| 7731 | case IEEE80211_SMPS_STATIC: |
| 7732 | smps = WMI_PEER_SMPS_STATIC; |
| 7733 | break; |
| 7734 | case IEEE80211_SMPS_DYNAMIC: |
| 7735 | smps = WMI_PEER_SMPS_DYNAMIC; |
| 7736 | break; |
| 7737 | case IEEE80211_SMPS_NUM_MODES: |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7738 | 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] | 7739 | sta->smps_mode, sta->addr); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 7740 | smps = WMI_PEER_SMPS_PS_NONE; |
| 7741 | break; |
| 7742 | } |
| 7743 | |
| 7744 | arsta->smps = smps; |
| 7745 | } |
| 7746 | |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 7747 | arsta->changed |= changed; |
| 7748 | |
| 7749 | spin_unlock_bh(&ar->data_lock); |
| 7750 | |
| 7751 | ieee80211_queue_work(hw, &arsta->update_wk); |
| 7752 | } |
| 7753 | |
Pedersen, Thomas | 973324f | 2016-09-28 16:56:29 -0700 | [diff] [blame] | 7754 | static void ath10k_offset_tsf(struct ieee80211_hw *hw, |
| 7755 | struct ieee80211_vif *vif, s64 tsf_offset) |
Peter Oh | 9f0b7e7 | 2016-04-04 16:19:14 -0700 | [diff] [blame] | 7756 | { |
| 7757 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 7758 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Pedersen, Thomas | 973324f | 2016-09-28 16:56:29 -0700 | [diff] [blame] | 7759 | u32 offset, vdev_param; |
Peter Oh | 9f0b7e7 | 2016-04-04 16:19:14 -0700 | [diff] [blame] | 7760 | int ret; |
| 7761 | |
Pedersen, Thomas | 973324f | 2016-09-28 16:56:29 -0700 | [diff] [blame] | 7762 | if (tsf_offset < 0) { |
| 7763 | vdev_param = ar->wmi.vdev_param->dec_tsf; |
| 7764 | offset = -tsf_offset; |
| 7765 | } else { |
| 7766 | vdev_param = ar->wmi.vdev_param->inc_tsf; |
| 7767 | offset = tsf_offset; |
| 7768 | } |
| 7769 | |
Peter Oh | 9f0b7e7 | 2016-04-04 16:19:14 -0700 | [diff] [blame] | 7770 | ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, |
Pedersen, Thomas | 973324f | 2016-09-28 16:56:29 -0700 | [diff] [blame] | 7771 | vdev_param, offset); |
| 7772 | |
Peter Oh | 9f0b7e7 | 2016-04-04 16:19:14 -0700 | [diff] [blame] | 7773 | if (ret && ret != -EOPNOTSUPP) |
Pedersen, Thomas | 973324f | 2016-09-28 16:56:29 -0700 | [diff] [blame] | 7774 | ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n", |
| 7775 | offset, vdev_param, ret); |
Peter Oh | 9f0b7e7 | 2016-04-04 16:19:14 -0700 | [diff] [blame] | 7776 | } |
| 7777 | |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 7778 | static int ath10k_ampdu_action(struct ieee80211_hw *hw, |
| 7779 | struct ieee80211_vif *vif, |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 7780 | struct ieee80211_ampdu_params *params) |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 7781 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7782 | struct ath10k *ar = hw->priv; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 7783 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Sara Sharon | 50ea05e | 2015-12-30 16:06:04 +0200 | [diff] [blame] | 7784 | struct ieee80211_sta *sta = params->sta; |
| 7785 | enum ieee80211_ampdu_mlme_action action = params->action; |
| 7786 | u16 tid = params->tid; |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 7787 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 7788 | 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] | 7789 | arvif->vdev_id, sta->addr, tid, action); |
| 7790 | |
| 7791 | switch (action) { |
| 7792 | case IEEE80211_AMPDU_RX_START: |
| 7793 | case IEEE80211_AMPDU_RX_STOP: |
| 7794 | /* HTT AddBa/DelBa events trigger mac80211 Rx BA session |
| 7795 | * creation/removal. Do we need to verify this? |
| 7796 | */ |
| 7797 | return 0; |
| 7798 | case IEEE80211_AMPDU_TX_START: |
| 7799 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 7800 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 7801 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 7802 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 7803 | /* Firmware offloads Tx aggregation entirely so deny mac80211 |
| 7804 | * Tx aggregation requests. |
| 7805 | */ |
| 7806 | return -EOPNOTSUPP; |
| 7807 | } |
| 7808 | |
| 7809 | return -EINVAL; |
| 7810 | } |
| 7811 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7812 | static void |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7813 | ath10k_mac_update_rx_channel(struct ath10k *ar, |
| 7814 | struct ieee80211_chanctx_conf *ctx, |
| 7815 | struct ieee80211_vif_chanctx_switch *vifs, |
| 7816 | int n_vifs) |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7817 | { |
| 7818 | struct cfg80211_chan_def *def = NULL; |
| 7819 | |
| 7820 | /* Both locks are required because ar->rx_channel is modified. This |
| 7821 | * allows readers to hold either lock. |
| 7822 | */ |
| 7823 | lockdep_assert_held(&ar->conf_mutex); |
| 7824 | lockdep_assert_held(&ar->data_lock); |
| 7825 | |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7826 | WARN_ON(ctx && vifs); |
Mohammed Shafi Shajakhan | c73f8c0 | 2017-03-08 13:52:06 +0200 | [diff] [blame] | 7827 | WARN_ON(vifs && !n_vifs); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7828 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7829 | /* FIXME: Sort of an optimization and a workaround. Peers and vifs are |
| 7830 | * on a linked list now. Doing a lookup peer -> vif -> chanctx for each |
| 7831 | * ppdu on Rx may reduce performance on low-end systems. It should be |
| 7832 | * possible to make tables/hashmaps to speed the lookup up (be vary of |
| 7833 | * cpu data cache lines though regarding sizes) but to keep the initial |
| 7834 | * implementation simple and less intrusive fallback to the slow lookup |
| 7835 | * only for multi-channel cases. Single-channel cases will remain to |
| 7836 | * use the old channel derival and thus performance should not be |
| 7837 | * affected much. |
| 7838 | */ |
| 7839 | rcu_read_lock(); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7840 | if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) { |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7841 | ieee80211_iter_chan_contexts_atomic(ar->hw, |
Kalle Valo | 617b0f4 | 2015-10-05 17:56:35 +0300 | [diff] [blame] | 7842 | ath10k_mac_get_any_chandef_iter, |
| 7843 | &def); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7844 | |
| 7845 | if (vifs) |
| 7846 | def = &vifs[0].new_ctx->def; |
| 7847 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7848 | ar->rx_channel = def->chan; |
Rajkumar Manoharan | 1ce8c14 | 2016-04-07 12:11:54 +0530 | [diff] [blame] | 7849 | } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) || |
| 7850 | (ctx && (ar->state == ATH10K_STATE_RESTARTED))) { |
| 7851 | /* During driver restart due to firmware assert, since mac80211 |
| 7852 | * already has valid channel context for given radio, channel |
| 7853 | * context iteration return num_chanctx > 0. So fix rx_channel |
| 7854 | * when restart is in progress. |
| 7855 | */ |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7856 | ar->rx_channel = ctx->def.chan; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7857 | } else { |
| 7858 | ar->rx_channel = NULL; |
| 7859 | } |
| 7860 | rcu_read_unlock(); |
| 7861 | } |
| 7862 | |
Michal Kazior | 7be6d1b | 2015-09-03 10:44:51 +0200 | [diff] [blame] | 7863 | static void |
| 7864 | ath10k_mac_update_vif_chan(struct ath10k *ar, |
| 7865 | struct ieee80211_vif_chanctx_switch *vifs, |
| 7866 | int n_vifs) |
| 7867 | { |
| 7868 | struct ath10k_vif *arvif; |
| 7869 | int ret; |
| 7870 | int i; |
| 7871 | |
| 7872 | lockdep_assert_held(&ar->conf_mutex); |
| 7873 | |
| 7874 | /* First stop monitor interface. Some FW versions crash if there's a |
| 7875 | * lone monitor interface. |
| 7876 | */ |
| 7877 | if (ar->monitor_started) |
| 7878 | ath10k_monitor_stop(ar); |
| 7879 | |
| 7880 | for (i = 0; i < n_vifs; i++) { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 7881 | arvif = (void *)vifs[i].vif->drv_priv; |
Michal Kazior | 7be6d1b | 2015-09-03 10:44:51 +0200 | [diff] [blame] | 7882 | |
| 7883 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 7884 | "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n", |
| 7885 | arvif->vdev_id, |
| 7886 | vifs[i].old_ctx->def.chan->center_freq, |
| 7887 | vifs[i].new_ctx->def.chan->center_freq, |
| 7888 | vifs[i].old_ctx->def.width, |
| 7889 | vifs[i].new_ctx->def.width); |
| 7890 | |
| 7891 | if (WARN_ON(!arvif->is_started)) |
| 7892 | continue; |
| 7893 | |
| 7894 | if (WARN_ON(!arvif->is_up)) |
| 7895 | continue; |
| 7896 | |
| 7897 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 7898 | if (ret) { |
| 7899 | ath10k_warn(ar, "failed to down vdev %d: %d\n", |
| 7900 | arvif->vdev_id, ret); |
| 7901 | continue; |
| 7902 | } |
| 7903 | } |
| 7904 | |
| 7905 | /* All relevant vdevs are downed and associated channel resources |
| 7906 | * should be available for the channel switch now. |
| 7907 | */ |
| 7908 | |
| 7909 | spin_lock_bh(&ar->data_lock); |
| 7910 | ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs); |
| 7911 | spin_unlock_bh(&ar->data_lock); |
| 7912 | |
| 7913 | for (i = 0; i < n_vifs; i++) { |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 7914 | arvif = (void *)vifs[i].vif->drv_priv; |
Michal Kazior | 7be6d1b | 2015-09-03 10:44:51 +0200 | [diff] [blame] | 7915 | |
| 7916 | if (WARN_ON(!arvif->is_started)) |
| 7917 | continue; |
| 7918 | |
| 7919 | if (WARN_ON(!arvif->is_up)) |
| 7920 | continue; |
| 7921 | |
| 7922 | ret = ath10k_mac_setup_bcn_tmpl(arvif); |
| 7923 | if (ret) |
| 7924 | ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n", |
| 7925 | ret); |
| 7926 | |
| 7927 | ret = ath10k_mac_setup_prb_tmpl(arvif); |
| 7928 | if (ret) |
| 7929 | ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n", |
| 7930 | ret); |
| 7931 | |
| 7932 | ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def); |
| 7933 | if (ret) { |
| 7934 | ath10k_warn(ar, "failed to restart vdev %d: %d\n", |
| 7935 | arvif->vdev_id, ret); |
| 7936 | continue; |
| 7937 | } |
| 7938 | |
| 7939 | ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid, |
| 7940 | arvif->bssid); |
| 7941 | if (ret) { |
| 7942 | ath10k_warn(ar, "failed to bring vdev up %d: %d\n", |
| 7943 | arvif->vdev_id, ret); |
| 7944 | continue; |
| 7945 | } |
| 7946 | } |
| 7947 | |
| 7948 | ath10k_monitor_recalc(ar); |
| 7949 | } |
| 7950 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7951 | static int |
| 7952 | ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw, |
| 7953 | struct ieee80211_chanctx_conf *ctx) |
| 7954 | { |
| 7955 | struct ath10k *ar = hw->priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7956 | |
| 7957 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 7958 | "mac chanctx add freq %hu width %d ptr %pK\n", |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7959 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
| 7960 | |
| 7961 | mutex_lock(&ar->conf_mutex); |
| 7962 | |
| 7963 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7964 | ath10k_mac_update_rx_channel(ar, ctx, NULL, 0); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7965 | spin_unlock_bh(&ar->data_lock); |
| 7966 | |
| 7967 | ath10k_recalc_radar_detection(ar); |
| 7968 | ath10k_monitor_recalc(ar); |
| 7969 | |
| 7970 | mutex_unlock(&ar->conf_mutex); |
| 7971 | |
| 7972 | return 0; |
| 7973 | } |
| 7974 | |
| 7975 | static void |
| 7976 | ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw, |
| 7977 | struct ieee80211_chanctx_conf *ctx) |
| 7978 | { |
| 7979 | struct ath10k *ar = hw->priv; |
| 7980 | |
| 7981 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 7982 | "mac chanctx remove freq %hu width %d ptr %pK\n", |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7983 | ctx->def.chan->center_freq, ctx->def.width, ctx); |
| 7984 | |
| 7985 | mutex_lock(&ar->conf_mutex); |
| 7986 | |
| 7987 | spin_lock_bh(&ar->data_lock); |
Michal Kazior | d7bf4b4 | 2015-06-03 12:16:54 +0200 | [diff] [blame] | 7988 | ath10k_mac_update_rx_channel(ar, NULL, NULL, 0); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 7989 | spin_unlock_bh(&ar->data_lock); |
| 7990 | |
| 7991 | ath10k_recalc_radar_detection(ar); |
| 7992 | ath10k_monitor_recalc(ar); |
| 7993 | |
| 7994 | mutex_unlock(&ar->conf_mutex); |
| 7995 | } |
| 7996 | |
Michal Kazior | 9713e3d | 2015-09-03 10:44:52 +0200 | [diff] [blame] | 7997 | struct ath10k_mac_change_chanctx_arg { |
| 7998 | struct ieee80211_chanctx_conf *ctx; |
| 7999 | struct ieee80211_vif_chanctx_switch *vifs; |
| 8000 | int n_vifs; |
| 8001 | int next_vif; |
| 8002 | }; |
| 8003 | |
| 8004 | static void |
| 8005 | ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac, |
| 8006 | struct ieee80211_vif *vif) |
| 8007 | { |
| 8008 | struct ath10k_mac_change_chanctx_arg *arg = data; |
| 8009 | |
| 8010 | if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx) |
| 8011 | return; |
| 8012 | |
| 8013 | arg->n_vifs++; |
| 8014 | } |
| 8015 | |
| 8016 | static void |
| 8017 | ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac, |
| 8018 | struct ieee80211_vif *vif) |
| 8019 | { |
| 8020 | struct ath10k_mac_change_chanctx_arg *arg = data; |
| 8021 | struct ieee80211_chanctx_conf *ctx; |
| 8022 | |
| 8023 | ctx = rcu_access_pointer(vif->chanctx_conf); |
| 8024 | if (ctx != arg->ctx) |
| 8025 | return; |
| 8026 | |
| 8027 | if (WARN_ON(arg->next_vif == arg->n_vifs)) |
| 8028 | return; |
| 8029 | |
| 8030 | arg->vifs[arg->next_vif].vif = vif; |
| 8031 | arg->vifs[arg->next_vif].old_ctx = ctx; |
| 8032 | arg->vifs[arg->next_vif].new_ctx = ctx; |
| 8033 | arg->next_vif++; |
| 8034 | } |
| 8035 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8036 | static void |
| 8037 | ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw, |
| 8038 | struct ieee80211_chanctx_conf *ctx, |
| 8039 | u32 changed) |
| 8040 | { |
| 8041 | struct ath10k *ar = hw->priv; |
Michal Kazior | 9713e3d | 2015-09-03 10:44:52 +0200 | [diff] [blame] | 8042 | struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx }; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8043 | |
| 8044 | mutex_lock(&ar->conf_mutex); |
| 8045 | |
| 8046 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 8047 | "mac chanctx change freq %hu width %d ptr %pK changed %x\n", |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 8048 | ctx->def.chan->center_freq, ctx->def.width, ctx, changed); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8049 | |
| 8050 | /* This shouldn't really happen because channel switching should use |
| 8051 | * switch_vif_chanctx(). |
| 8052 | */ |
| 8053 | if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL)) |
| 8054 | goto unlock; |
| 8055 | |
Michal Kazior | 9713e3d | 2015-09-03 10:44:52 +0200 | [diff] [blame] | 8056 | if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) { |
| 8057 | ieee80211_iterate_active_interfaces_atomic( |
| 8058 | hw, |
| 8059 | IEEE80211_IFACE_ITER_NORMAL, |
| 8060 | ath10k_mac_change_chanctx_cnt_iter, |
| 8061 | &arg); |
| 8062 | if (arg.n_vifs == 0) |
| 8063 | goto radar; |
| 8064 | |
| 8065 | arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), |
| 8066 | GFP_KERNEL); |
| 8067 | if (!arg.vifs) |
| 8068 | goto radar; |
| 8069 | |
| 8070 | ieee80211_iterate_active_interfaces_atomic( |
| 8071 | hw, |
| 8072 | IEEE80211_IFACE_ITER_NORMAL, |
| 8073 | ath10k_mac_change_chanctx_fill_iter, |
| 8074 | &arg); |
| 8075 | ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs); |
| 8076 | kfree(arg.vifs); |
| 8077 | } |
| 8078 | |
| 8079 | radar: |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8080 | ath10k_recalc_radar_detection(ar); |
| 8081 | |
| 8082 | /* FIXME: How to configure Rx chains properly? */ |
| 8083 | |
| 8084 | /* No other actions are actually necessary. Firmware maintains channel |
| 8085 | * definitions per vdev internally and there's no host-side channel |
| 8086 | * context abstraction to configure, e.g. channel width. |
| 8087 | */ |
| 8088 | |
| 8089 | unlock: |
| 8090 | mutex_unlock(&ar->conf_mutex); |
| 8091 | } |
| 8092 | |
| 8093 | static int |
| 8094 | ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 8095 | struct ieee80211_vif *vif, |
| 8096 | struct ieee80211_chanctx_conf *ctx) |
| 8097 | { |
| 8098 | struct ath10k *ar = hw->priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8099 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 8100 | int ret; |
| 8101 | |
| 8102 | mutex_lock(&ar->conf_mutex); |
| 8103 | |
| 8104 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 8105 | "mac chanctx assign ptr %pK vdev_id %i\n", |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8106 | ctx, arvif->vdev_id); |
| 8107 | |
| 8108 | if (WARN_ON(arvif->is_started)) { |
| 8109 | mutex_unlock(&ar->conf_mutex); |
| 8110 | return -EBUSY; |
| 8111 | } |
| 8112 | |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 8113 | ret = ath10k_vdev_start(arvif, &ctx->def); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8114 | if (ret) { |
| 8115 | ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n", |
| 8116 | arvif->vdev_id, vif->addr, |
Michal Kazior | 089ab7a | 2015-06-03 12:16:55 +0200 | [diff] [blame] | 8117 | ctx->def.chan->center_freq, ret); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8118 | goto err; |
| 8119 | } |
| 8120 | |
| 8121 | arvif->is_started = true; |
| 8122 | |
Michal Kazior | f23e587e | 2015-07-09 13:08:37 +0200 | [diff] [blame] | 8123 | ret = ath10k_mac_vif_setup_ps(arvif); |
| 8124 | if (ret) { |
| 8125 | ath10k_warn(ar, "failed to update vdev %i ps: %d\n", |
| 8126 | arvif->vdev_id, ret); |
| 8127 | goto err_stop; |
| 8128 | } |
| 8129 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8130 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 8131 | ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr); |
| 8132 | if (ret) { |
| 8133 | ath10k_warn(ar, "failed to up monitor vdev %i: %d\n", |
| 8134 | arvif->vdev_id, ret); |
| 8135 | goto err_stop; |
| 8136 | } |
| 8137 | |
| 8138 | arvif->is_up = true; |
| 8139 | } |
| 8140 | |
Bartosz Markowski | 7cfe045 | 2016-12-15 11:23:24 +0200 | [diff] [blame] | 8141 | if (ath10k_mac_can_set_cts_prot(arvif)) { |
| 8142 | ret = ath10k_mac_set_cts_prot(arvif); |
| 8143 | if (ret) |
| 8144 | ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n", |
| 8145 | arvif->vdev_id, ret); |
| 8146 | } |
| 8147 | |
Balaji Pothunoori | 4fa42ad | 2019-05-13 20:23:07 +0530 | [diff] [blame] | 8148 | if (ath10k_peer_stats_enabled(ar) && |
| 8149 | ar->hw_params.tx_stats_over_pktlog) { |
Anilkumar Kolli | e8123bb | 2017-12-05 19:01:25 +0530 | [diff] [blame] | 8150 | ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS; |
| 8151 | ret = ath10k_wmi_pdev_pktlog_enable(ar, |
| 8152 | ar->pktlog_filter); |
| 8153 | if (ret) { |
| 8154 | ath10k_warn(ar, "failed to enable pktlog %d\n", ret); |
| 8155 | goto err_stop; |
| 8156 | } |
| 8157 | } |
| 8158 | |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8159 | mutex_unlock(&ar->conf_mutex); |
| 8160 | return 0; |
| 8161 | |
| 8162 | err_stop: |
| 8163 | ath10k_vdev_stop(arvif); |
| 8164 | arvif->is_started = false; |
Michal Kazior | f23e587e | 2015-07-09 13:08:37 +0200 | [diff] [blame] | 8165 | ath10k_mac_vif_setup_ps(arvif); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8166 | |
| 8167 | err: |
| 8168 | mutex_unlock(&ar->conf_mutex); |
| 8169 | return ret; |
| 8170 | } |
| 8171 | |
| 8172 | static void |
| 8173 | ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 8174 | struct ieee80211_vif *vif, |
| 8175 | struct ieee80211_chanctx_conf *ctx) |
| 8176 | { |
| 8177 | struct ath10k *ar = hw->priv; |
| 8178 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
| 8179 | int ret; |
| 8180 | |
| 8181 | mutex_lock(&ar->conf_mutex); |
| 8182 | |
| 8183 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
Maharaja Kennadyrajan | 75b3480 | 2016-08-04 19:21:51 +0530 | [diff] [blame] | 8184 | "mac chanctx unassign ptr %pK vdev_id %i\n", |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8185 | ctx, arvif->vdev_id); |
| 8186 | |
| 8187 | WARN_ON(!arvif->is_started); |
| 8188 | |
| 8189 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 8190 | WARN_ON(!arvif->is_up); |
| 8191 | |
| 8192 | ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id); |
| 8193 | if (ret) |
| 8194 | ath10k_warn(ar, "failed to down monitor vdev %i: %d\n", |
| 8195 | arvif->vdev_id, ret); |
| 8196 | |
| 8197 | arvif->is_up = false; |
| 8198 | } |
| 8199 | |
| 8200 | ret = ath10k_vdev_stop(arvif); |
| 8201 | if (ret) |
| 8202 | ath10k_warn(ar, "failed to stop vdev %i: %d\n", |
| 8203 | arvif->vdev_id, ret); |
| 8204 | |
| 8205 | arvif->is_started = false; |
| 8206 | |
| 8207 | mutex_unlock(&ar->conf_mutex); |
| 8208 | } |
| 8209 | |
| 8210 | static int |
| 8211 | ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw, |
| 8212 | struct ieee80211_vif_chanctx_switch *vifs, |
| 8213 | int n_vifs, |
| 8214 | enum ieee80211_chanctx_switch_mode mode) |
| 8215 | { |
| 8216 | struct ath10k *ar = hw->priv; |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8217 | |
| 8218 | mutex_lock(&ar->conf_mutex); |
| 8219 | |
| 8220 | ath10k_dbg(ar, ATH10K_DBG_MAC, |
| 8221 | "mac chanctx switch n_vifs %d mode %d\n", |
| 8222 | n_vifs, mode); |
Michal Kazior | 7be6d1b | 2015-09-03 10:44:51 +0200 | [diff] [blame] | 8223 | ath10k_mac_update_vif_chan(ar, vifs, n_vifs); |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8224 | |
| 8225 | mutex_unlock(&ar->conf_mutex); |
| 8226 | return 0; |
| 8227 | } |
| 8228 | |
Michal Kazior | 0a744d9 | 2017-01-12 16:14:30 +0100 | [diff] [blame] | 8229 | static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw, |
| 8230 | struct ieee80211_vif *vif, |
| 8231 | struct ieee80211_sta *sta) |
| 8232 | { |
| 8233 | struct ath10k *ar; |
| 8234 | struct ath10k_peer *peer; |
| 8235 | |
| 8236 | ar = hw->priv; |
| 8237 | |
| 8238 | list_for_each_entry(peer, &ar->peers, list) |
| 8239 | if (peer->sta == sta) |
| 8240 | peer->removed = true; |
| 8241 | } |
| 8242 | |
Anilkumar Kolli | 6a7f891 | 2017-12-05 19:01:23 +0530 | [diff] [blame] | 8243 | static void ath10k_sta_statistics(struct ieee80211_hw *hw, |
| 8244 | struct ieee80211_vif *vif, |
| 8245 | struct ieee80211_sta *sta, |
| 8246 | struct station_info *sinfo) |
| 8247 | { |
| 8248 | struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv; |
| 8249 | struct ath10k *ar = arsta->arvif->ar; |
| 8250 | |
| 8251 | if (!ath10k_peer_stats_enabled(ar)) |
| 8252 | return; |
| 8253 | |
| 8254 | sinfo->rx_duration = arsta->rx_duration; |
Omer Efrat | 22d0d2f | 2018-06-17 13:07:13 +0300 | [diff] [blame] | 8255 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION); |
Anilkumar Kolli | 6a7f891 | 2017-12-05 19:01:23 +0530 | [diff] [blame] | 8256 | |
| 8257 | if (!arsta->txrate.legacy && !arsta->txrate.nss) |
| 8258 | return; |
| 8259 | |
| 8260 | if (arsta->txrate.legacy) { |
| 8261 | sinfo->txrate.legacy = arsta->txrate.legacy; |
| 8262 | } else { |
| 8263 | sinfo->txrate.mcs = arsta->txrate.mcs; |
| 8264 | sinfo->txrate.nss = arsta->txrate.nss; |
| 8265 | sinfo->txrate.bw = arsta->txrate.bw; |
| 8266 | } |
| 8267 | sinfo->txrate.flags = arsta->txrate.flags; |
Omer Efrat | 22d0d2f | 2018-06-17 13:07:13 +0300 | [diff] [blame] | 8268 | sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); |
Anilkumar Kolli | 6a7f891 | 2017-12-05 19:01:23 +0530 | [diff] [blame] | 8269 | } |
| 8270 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8271 | static const struct ieee80211_ops ath10k_ops = { |
Michal Kazior | f2f6eca | 2016-03-01 11:32:46 +0100 | [diff] [blame] | 8272 | .tx = ath10k_mac_op_tx, |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 8273 | .wake_tx_queue = ath10k_mac_op_wake_tx_queue, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8274 | .start = ath10k_start, |
| 8275 | .stop = ath10k_stop, |
| 8276 | .config = ath10k_config, |
| 8277 | .add_interface = ath10k_add_interface, |
| 8278 | .remove_interface = ath10k_remove_interface, |
| 8279 | .configure_filter = ath10k_configure_filter, |
| 8280 | .bss_info_changed = ath10k_bss_info_changed, |
Benjamin Berg | ebee76f | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 8281 | .set_coverage_class = ath10k_mac_op_set_coverage_class, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8282 | .hw_scan = ath10k_hw_scan, |
| 8283 | .cancel_hw_scan = ath10k_cancel_hw_scan, |
| 8284 | .set_key = ath10k_set_key, |
SenthilKumar Jegadeesan | 627613f | 2015-01-29 13:50:38 +0200 | [diff] [blame] | 8285 | .set_default_unicast_key = ath10k_set_default_unicast_key, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8286 | .sta_state = ath10k_sta_state, |
Ashok Raj Nagarajan | 33410a5 | 2019-06-03 18:09:02 +0300 | [diff] [blame] | 8287 | .sta_set_txpwr = ath10k_sta_set_txpwr, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8288 | .conf_tx = ath10k_conf_tx, |
| 8289 | .remain_on_channel = ath10k_remain_on_channel, |
| 8290 | .cancel_remain_on_channel = ath10k_cancel_remain_on_channel, |
| 8291 | .set_rts_threshold = ath10k_set_rts_threshold, |
Michal Kazior | 92092fe | 2015-08-03 11:16:43 +0200 | [diff] [blame] | 8292 | .set_frag_threshold = ath10k_mac_op_set_frag_threshold, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8293 | .flush = ath10k_flush, |
| 8294 | .tx_last_beacon = ath10k_tx_last_beacon, |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 8295 | .set_antenna = ath10k_set_antenna, |
| 8296 | .get_antenna = ath10k_get_antenna, |
Eliad Peller | cf2c92d | 2014-11-04 11:43:54 +0200 | [diff] [blame] | 8297 | .reconfig_complete = ath10k_reconfig_complete, |
Michal Kazior | 2e1dea4 | 2013-07-31 10:32:40 +0200 | [diff] [blame] | 8298 | .get_survey = ath10k_get_survey, |
Michal Kazior | 3ae5422 | 2015-03-31 10:49:20 +0000 | [diff] [blame] | 8299 | .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask, |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 8300 | .sta_rc_update = ath10k_sta_rc_update, |
Pedersen, Thomas | 973324f | 2016-09-28 16:56:29 -0700 | [diff] [blame] | 8301 | .offset_tsf = ath10k_offset_tsf, |
Michal Kazior | aa5b4fb | 2014-07-23 12:20:33 +0200 | [diff] [blame] | 8302 | .ampdu_action = ath10k_ampdu_action, |
Ben Greear | 6cddcc7 | 2014-09-29 14:41:46 +0300 | [diff] [blame] | 8303 | .get_et_sset_count = ath10k_debug_get_et_sset_count, |
| 8304 | .get_et_stats = ath10k_debug_get_et_stats, |
| 8305 | .get_et_strings = ath10k_debug_get_et_strings, |
Michal Kazior | 500ff9f | 2015-03-31 10:26:21 +0000 | [diff] [blame] | 8306 | .add_chanctx = ath10k_mac_op_add_chanctx, |
| 8307 | .remove_chanctx = ath10k_mac_op_remove_chanctx, |
| 8308 | .change_chanctx = ath10k_mac_op_change_chanctx, |
| 8309 | .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx, |
| 8310 | .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx, |
| 8311 | .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx, |
Michal Kazior | 0a744d9 | 2017-01-12 16:14:30 +0100 | [diff] [blame] | 8312 | .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove, |
Anilkumar Kolli | 6a7f891 | 2017-12-05 19:01:23 +0530 | [diff] [blame] | 8313 | .sta_statistics = ath10k_sta_statistics, |
Kalle Valo | 43d2a30 | 2014-09-10 18:23:30 +0300 | [diff] [blame] | 8314 | |
| 8315 | CFG80211_TESTMODE_CMD(ath10k_tm_cmd) |
| 8316 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 8317 | #ifdef CONFIG_PM |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 8318 | .suspend = ath10k_wow_op_suspend, |
| 8319 | .resume = ath10k_wow_op_resume, |
Ryan Hsu | 393b706 | 2017-08-31 15:36:16 +0300 | [diff] [blame] | 8320 | .set_wakeup = ath10k_wow_op_set_wakeup, |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 8321 | #endif |
Rajkumar Manoharan | f504598 | 2015-01-12 14:07:27 +0200 | [diff] [blame] | 8322 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 8323 | .sta_add_debugfs = ath10k_sta_add_debugfs, |
| 8324 | #endif |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8325 | }; |
| 8326 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8327 | #define CHAN2G(_channel, _freq, _flags) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8328 | .band = NL80211_BAND_2GHZ, \ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8329 | .hw_value = (_channel), \ |
| 8330 | .center_freq = (_freq), \ |
| 8331 | .flags = (_flags), \ |
| 8332 | .max_antenna_gain = 0, \ |
| 8333 | .max_power = 30, \ |
| 8334 | } |
| 8335 | |
| 8336 | #define CHAN5G(_channel, _freq, _flags) { \ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8337 | .band = NL80211_BAND_5GHZ, \ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8338 | .hw_value = (_channel), \ |
| 8339 | .center_freq = (_freq), \ |
| 8340 | .flags = (_flags), \ |
| 8341 | .max_antenna_gain = 0, \ |
| 8342 | .max_power = 30, \ |
| 8343 | } |
| 8344 | |
| 8345 | static const struct ieee80211_channel ath10k_2ghz_channels[] = { |
| 8346 | CHAN2G(1, 2412, 0), |
| 8347 | CHAN2G(2, 2417, 0), |
| 8348 | CHAN2G(3, 2422, 0), |
| 8349 | CHAN2G(4, 2427, 0), |
| 8350 | CHAN2G(5, 2432, 0), |
| 8351 | CHAN2G(6, 2437, 0), |
| 8352 | CHAN2G(7, 2442, 0), |
| 8353 | CHAN2G(8, 2447, 0), |
| 8354 | CHAN2G(9, 2452, 0), |
| 8355 | CHAN2G(10, 2457, 0), |
| 8356 | CHAN2G(11, 2462, 0), |
| 8357 | CHAN2G(12, 2467, 0), |
| 8358 | CHAN2G(13, 2472, 0), |
| 8359 | CHAN2G(14, 2484, 0), |
| 8360 | }; |
| 8361 | |
| 8362 | static const struct ieee80211_channel ath10k_5ghz_channels[] = { |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 8363 | CHAN5G(36, 5180, 0), |
| 8364 | CHAN5G(40, 5200, 0), |
| 8365 | CHAN5G(44, 5220, 0), |
| 8366 | CHAN5G(48, 5240, 0), |
| 8367 | CHAN5G(52, 5260, 0), |
| 8368 | CHAN5G(56, 5280, 0), |
| 8369 | CHAN5G(60, 5300, 0), |
| 8370 | CHAN5G(64, 5320, 0), |
| 8371 | CHAN5G(100, 5500, 0), |
| 8372 | CHAN5G(104, 5520, 0), |
| 8373 | CHAN5G(108, 5540, 0), |
| 8374 | CHAN5G(112, 5560, 0), |
| 8375 | CHAN5G(116, 5580, 0), |
| 8376 | CHAN5G(120, 5600, 0), |
| 8377 | CHAN5G(124, 5620, 0), |
| 8378 | CHAN5G(128, 5640, 0), |
| 8379 | CHAN5G(132, 5660, 0), |
| 8380 | CHAN5G(136, 5680, 0), |
| 8381 | CHAN5G(140, 5700, 0), |
Peter Oh | 4a7898f | 2015-03-18 11:39:18 -0700 | [diff] [blame] | 8382 | CHAN5G(144, 5720, 0), |
Michal Kazior | 429ff56 | 2013-06-26 08:54:54 +0200 | [diff] [blame] | 8383 | CHAN5G(149, 5745, 0), |
| 8384 | CHAN5G(153, 5765, 0), |
| 8385 | CHAN5G(157, 5785, 0), |
| 8386 | CHAN5G(161, 5805, 0), |
| 8387 | CHAN5G(165, 5825, 0), |
Mohammed Shafi Shajakhan | 34c30b0 | 2016-12-27 20:53:35 +0530 | [diff] [blame] | 8388 | CHAN5G(169, 5845, 0), |
Ben Greear | 38441fb | 2018-01-02 16:51:01 -0800 | [diff] [blame] | 8389 | CHAN5G(173, 5865, 0), |
| 8390 | /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */ |
| 8391 | /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8392 | }; |
| 8393 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 8394 | struct ath10k *ath10k_mac_create(size_t priv_size) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8395 | { |
| 8396 | struct ieee80211_hw *hw; |
Michal Kazior | 4ca1807 | 2016-07-18 23:22:18 +0300 | [diff] [blame] | 8397 | struct ieee80211_ops *ops; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8398 | struct ath10k *ar; |
| 8399 | |
Michal Kazior | 4ca1807 | 2016-07-18 23:22:18 +0300 | [diff] [blame] | 8400 | ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL); |
| 8401 | if (!ops) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8402 | return NULL; |
| 8403 | |
Michal Kazior | 4ca1807 | 2016-07-18 23:22:18 +0300 | [diff] [blame] | 8404 | hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops); |
| 8405 | if (!hw) { |
| 8406 | kfree(ops); |
| 8407 | return NULL; |
| 8408 | } |
| 8409 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8410 | ar = hw->priv; |
| 8411 | ar->hw = hw; |
Michal Kazior | 4ca1807 | 2016-07-18 23:22:18 +0300 | [diff] [blame] | 8412 | ar->ops = ops; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8413 | |
| 8414 | return ar; |
| 8415 | } |
| 8416 | |
| 8417 | void ath10k_mac_destroy(struct ath10k *ar) |
| 8418 | { |
Michal Kazior | 4ca1807 | 2016-07-18 23:22:18 +0300 | [diff] [blame] | 8419 | struct ieee80211_ops *ops = ar->ops; |
| 8420 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8421 | ieee80211_free_hw(ar->hw); |
Michal Kazior | 4ca1807 | 2016-07-18 23:22:18 +0300 | [diff] [blame] | 8422 | kfree(ops); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8423 | } |
| 8424 | |
| 8425 | static const struct ieee80211_iface_limit ath10k_if_limits[] = { |
| 8426 | { |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8427 | .max = 8, |
| 8428 | .types = BIT(NL80211_IFTYPE_STATION) |
| 8429 | | BIT(NL80211_IFTYPE_P2P_CLIENT) |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 8430 | }, |
| 8431 | { |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8432 | .max = 3, |
| 8433 | .types = BIT(NL80211_IFTYPE_P2P_GO) |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 8434 | }, |
| 8435 | { |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8436 | .max = 1, |
| 8437 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE) |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 8438 | }, |
| 8439 | { |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8440 | .max = 7, |
| 8441 | .types = BIT(NL80211_IFTYPE_AP) |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8442 | #ifdef CONFIG_MAC80211_MESH |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8443 | | BIT(NL80211_IFTYPE_MESH_POINT) |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8444 | #endif |
Michal Kazior | d531cb8 | 2013-07-31 10:55:13 +0200 | [diff] [blame] | 8445 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8446 | }; |
| 8447 | |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 8448 | static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8449 | { |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8450 | .max = 8, |
| 8451 | .types = BIT(NL80211_IFTYPE_AP) |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8452 | #ifdef CONFIG_MAC80211_MESH |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8453 | | BIT(NL80211_IFTYPE_MESH_POINT) |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8454 | #endif |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8455 | }, |
Mohammed Shafi Shajakhan | 78f7aeb | 2015-11-21 15:24:41 +0530 | [diff] [blame] | 8456 | { |
| 8457 | .max = 1, |
| 8458 | .types = BIT(NL80211_IFTYPE_STATION) |
| 8459 | }, |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8460 | }; |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8461 | |
| 8462 | static const struct ieee80211_iface_combination ath10k_if_comb[] = { |
| 8463 | { |
| 8464 | .limits = ath10k_if_limits, |
| 8465 | .n_limits = ARRAY_SIZE(ath10k_if_limits), |
| 8466 | .max_interfaces = 8, |
| 8467 | .num_different_channels = 1, |
| 8468 | .beacon_int_infra_match = true, |
| 8469 | }, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 8470 | }; |
| 8471 | |
| 8472 | static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = { |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8473 | { |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 8474 | .limits = ath10k_10x_if_limits, |
| 8475 | .n_limits = ARRAY_SIZE(ath10k_10x_if_limits), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8476 | .max_interfaces = 8, |
| 8477 | .num_different_channels = 1, |
| 8478 | .beacon_int_infra_match = true, |
Anilkumar Kolli | 8ebee73 | 2018-03-28 12:19:40 +0300 | [diff] [blame] | 8479 | .beacon_int_min_gcd = 1, |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 8480 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8481 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 8482 | BIT(NL80211_CHAN_WIDTH_20) | |
| 8483 | BIT(NL80211_CHAN_WIDTH_40) | |
| 8484 | BIT(NL80211_CHAN_WIDTH_80), |
Marek Puzyniak | e8a50f8 | 2013-11-20 09:59:47 +0200 | [diff] [blame] | 8485 | #endif |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 8486 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8487 | }; |
| 8488 | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8489 | static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = { |
| 8490 | { |
| 8491 | .max = 2, |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 8492 | .types = BIT(NL80211_IFTYPE_STATION), |
| 8493 | }, |
| 8494 | { |
| 8495 | .max = 2, |
| 8496 | .types = BIT(NL80211_IFTYPE_AP) | |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8497 | #ifdef CONFIG_MAC80211_MESH |
| 8498 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 8499 | #endif |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8500 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 8501 | BIT(NL80211_IFTYPE_P2P_GO), |
| 8502 | }, |
| 8503 | { |
| 8504 | .max = 1, |
| 8505 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 8506 | }, |
| 8507 | }; |
| 8508 | |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 8509 | static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = { |
| 8510 | { |
| 8511 | .max = 2, |
| 8512 | .types = BIT(NL80211_IFTYPE_STATION), |
| 8513 | }, |
| 8514 | { |
| 8515 | .max = 2, |
| 8516 | .types = BIT(NL80211_IFTYPE_P2P_CLIENT), |
| 8517 | }, |
| 8518 | { |
| 8519 | .max = 1, |
| 8520 | .types = BIT(NL80211_IFTYPE_AP) | |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8521 | #ifdef CONFIG_MAC80211_MESH |
| 8522 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 8523 | #endif |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 8524 | BIT(NL80211_IFTYPE_P2P_GO), |
| 8525 | }, |
| 8526 | { |
| 8527 | .max = 1, |
| 8528 | .types = BIT(NL80211_IFTYPE_P2P_DEVICE), |
| 8529 | }, |
| 8530 | }; |
| 8531 | |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8532 | static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = { |
| 8533 | { |
| 8534 | .max = 1, |
| 8535 | .types = BIT(NL80211_IFTYPE_STATION), |
| 8536 | }, |
| 8537 | { |
| 8538 | .max = 1, |
| 8539 | .types = BIT(NL80211_IFTYPE_ADHOC), |
| 8540 | }, |
| 8541 | }; |
| 8542 | |
| 8543 | /* FIXME: This is not thouroughly tested. These combinations may over- or |
| 8544 | * underestimate hw/fw capabilities. |
| 8545 | */ |
| 8546 | static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = { |
| 8547 | { |
| 8548 | .limits = ath10k_tlv_if_limit, |
| 8549 | .num_different_channels = 1, |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 8550 | .max_interfaces = 4, |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8551 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit), |
| 8552 | }, |
| 8553 | { |
| 8554 | .limits = ath10k_tlv_if_limit_ibss, |
| 8555 | .num_different_channels = 1, |
| 8556 | .max_interfaces = 2, |
| 8557 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss), |
| 8558 | }, |
| 8559 | }; |
| 8560 | |
| 8561 | static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = { |
| 8562 | { |
| 8563 | .limits = ath10k_tlv_if_limit, |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 8564 | .num_different_channels = 1, |
| 8565 | .max_interfaces = 4, |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8566 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit), |
| 8567 | }, |
| 8568 | { |
Michal Kazior | ed25b11 | 2015-07-09 13:08:39 +0200 | [diff] [blame] | 8569 | .limits = ath10k_tlv_qcs_if_limit, |
| 8570 | .num_different_channels = 2, |
| 8571 | .max_interfaces = 4, |
| 8572 | .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit), |
| 8573 | }, |
| 8574 | { |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8575 | .limits = ath10k_tlv_if_limit_ibss, |
| 8576 | .num_different_channels = 1, |
| 8577 | .max_interfaces = 2, |
| 8578 | .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss), |
| 8579 | }, |
| 8580 | }; |
| 8581 | |
Raja Mani | cf36fef | 2015-06-22 20:22:25 +0530 | [diff] [blame] | 8582 | static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = { |
| 8583 | { |
| 8584 | .max = 1, |
| 8585 | .types = BIT(NL80211_IFTYPE_STATION), |
| 8586 | }, |
| 8587 | { |
| 8588 | .max = 16, |
| 8589 | .types = BIT(NL80211_IFTYPE_AP) |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8590 | #ifdef CONFIG_MAC80211_MESH |
| 8591 | | BIT(NL80211_IFTYPE_MESH_POINT) |
| 8592 | #endif |
Raja Mani | cf36fef | 2015-06-22 20:22:25 +0530 | [diff] [blame] | 8593 | }, |
| 8594 | }; |
| 8595 | |
| 8596 | static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = { |
| 8597 | { |
| 8598 | .limits = ath10k_10_4_if_limits, |
| 8599 | .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits), |
| 8600 | .max_interfaces = 16, |
| 8601 | .num_different_channels = 1, |
| 8602 | .beacon_int_infra_match = true, |
Anilkumar Kolli | 8ebee73 | 2018-03-28 12:19:40 +0300 | [diff] [blame] | 8603 | .beacon_int_min_gcd = 1, |
Raja Mani | cf36fef | 2015-06-22 20:22:25 +0530 | [diff] [blame] | 8604 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
| 8605 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 8606 | BIT(NL80211_CHAN_WIDTH_20) | |
| 8607 | BIT(NL80211_CHAN_WIDTH_40) | |
| 8608 | BIT(NL80211_CHAN_WIDTH_80), |
| 8609 | #endif |
| 8610 | }, |
| 8611 | }; |
| 8612 | |
Maharaja Kennadyrajan | 4600563 | 2018-09-18 17:37:26 +0530 | [diff] [blame] | 8613 | static const struct |
| 8614 | ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = { |
| 8615 | { |
| 8616 | .limits = ath10k_10_4_if_limits, |
| 8617 | .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits), |
| 8618 | .max_interfaces = 16, |
| 8619 | .num_different_channels = 1, |
| 8620 | .beacon_int_infra_match = true, |
| 8621 | .beacon_int_min_gcd = 100, |
| 8622 | #ifdef CONFIG_ATH10K_DFS_CERTIFIED |
| 8623 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 8624 | BIT(NL80211_CHAN_WIDTH_20) | |
| 8625 | BIT(NL80211_CHAN_WIDTH_40) | |
| 8626 | BIT(NL80211_CHAN_WIDTH_80), |
| 8627 | #endif |
| 8628 | }, |
| 8629 | }; |
| 8630 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8631 | static void ath10k_get_arvif_iter(void *data, u8 *mac, |
| 8632 | struct ieee80211_vif *vif) |
| 8633 | { |
| 8634 | struct ath10k_vif_iter *arvif_iter = data; |
Amadeusz Sławiński | 56ac13b | 2017-02-13 12:38:37 +0200 | [diff] [blame] | 8635 | struct ath10k_vif *arvif = (void *)vif->drv_priv; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8636 | |
| 8637 | if (arvif->vdev_id == arvif_iter->vdev_id) |
| 8638 | arvif_iter->arvif = arvif; |
| 8639 | } |
| 8640 | |
| 8641 | struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id) |
| 8642 | { |
| 8643 | struct ath10k_vif_iter arvif_iter; |
| 8644 | u32 flags; |
| 8645 | |
| 8646 | memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter)); |
| 8647 | arvif_iter.vdev_id = vdev_id; |
| 8648 | |
| 8649 | flags = IEEE80211_IFACE_ITER_RESUME_ALL; |
| 8650 | ieee80211_iterate_active_interfaces_atomic(ar->hw, |
| 8651 | flags, |
| 8652 | ath10k_get_arvif_iter, |
| 8653 | &arvif_iter); |
| 8654 | if (!arvif_iter.arvif) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 8655 | ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8656 | return NULL; |
| 8657 | } |
| 8658 | |
| 8659 | return arvif_iter.arvif; |
| 8660 | } |
| 8661 | |
Bartosz Markowski | 209b2a6 | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 8662 | #define WRD_METHOD "WRDD" |
| 8663 | #define WRDD_WIFI (0x07) |
| 8664 | |
| 8665 | static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd) |
| 8666 | { |
| 8667 | union acpi_object *mcc_pkg; |
| 8668 | union acpi_object *domain_type; |
| 8669 | union acpi_object *mcc_value; |
| 8670 | u32 i; |
| 8671 | |
| 8672 | if (wrdd->type != ACPI_TYPE_PACKAGE || |
| 8673 | wrdd->package.count < 2 || |
| 8674 | wrdd->package.elements[0].type != ACPI_TYPE_INTEGER || |
| 8675 | wrdd->package.elements[0].integer.value != 0) { |
| 8676 | ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n"); |
| 8677 | return 0; |
| 8678 | } |
| 8679 | |
| 8680 | for (i = 1; i < wrdd->package.count; ++i) { |
| 8681 | mcc_pkg = &wrdd->package.elements[i]; |
| 8682 | |
| 8683 | if (mcc_pkg->type != ACPI_TYPE_PACKAGE) |
| 8684 | continue; |
| 8685 | if (mcc_pkg->package.count < 2) |
| 8686 | continue; |
| 8687 | if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER || |
| 8688 | mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) |
| 8689 | continue; |
| 8690 | |
| 8691 | domain_type = &mcc_pkg->package.elements[0]; |
| 8692 | if (domain_type->integer.value != WRDD_WIFI) |
| 8693 | continue; |
| 8694 | |
| 8695 | mcc_value = &mcc_pkg->package.elements[1]; |
| 8696 | return mcc_value->integer.value; |
| 8697 | } |
| 8698 | return 0; |
| 8699 | } |
| 8700 | |
| 8701 | static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd) |
| 8702 | { |
Bartosz Markowski | 209b2a6 | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 8703 | acpi_handle root_handle; |
| 8704 | acpi_handle handle; |
| 8705 | struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 8706 | acpi_status status; |
| 8707 | u32 alpha2_code; |
| 8708 | char alpha2[3]; |
| 8709 | |
Brian Norris | 79169f1 | 2018-11-02 10:17:48 -0700 | [diff] [blame] | 8710 | root_handle = ACPI_HANDLE(ar->dev); |
Bartosz Markowski | 209b2a6 | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 8711 | if (!root_handle) |
| 8712 | return -EOPNOTSUPP; |
| 8713 | |
| 8714 | status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle); |
| 8715 | if (ACPI_FAILURE(status)) { |
| 8716 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 8717 | "failed to get wrd method %d\n", status); |
| 8718 | return -EIO; |
| 8719 | } |
| 8720 | |
| 8721 | status = acpi_evaluate_object(handle, NULL, NULL, &wrdd); |
| 8722 | if (ACPI_FAILURE(status)) { |
| 8723 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 8724 | "failed to call wrdc %d\n", status); |
| 8725 | return -EIO; |
| 8726 | } |
| 8727 | |
| 8728 | alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer); |
| 8729 | kfree(wrdd.pointer); |
| 8730 | if (!alpha2_code) |
| 8731 | return -EIO; |
| 8732 | |
| 8733 | alpha2[0] = (alpha2_code >> 8) & 0xff; |
| 8734 | alpha2[1] = (alpha2_code >> 0) & 0xff; |
| 8735 | alpha2[2] = '\0'; |
| 8736 | |
| 8737 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 8738 | "regulatory hint from WRDD (alpha2-code): %s\n", alpha2); |
| 8739 | |
| 8740 | *rd = ath_regd_find_country_by_name(alpha2); |
| 8741 | if (*rd == 0xffff) |
| 8742 | return -EIO; |
| 8743 | |
| 8744 | *rd |= COUNTRY_ERD_FLAG; |
| 8745 | return 0; |
| 8746 | } |
| 8747 | |
| 8748 | static int ath10k_mac_init_rd(struct ath10k *ar) |
| 8749 | { |
| 8750 | int ret; |
| 8751 | u16 rd; |
| 8752 | |
| 8753 | ret = ath10k_mac_get_wrdd_regulatory(ar, &rd); |
| 8754 | if (ret) { |
| 8755 | ath10k_dbg(ar, ATH10K_DBG_BOOT, |
| 8756 | "fallback to eeprom programmed regulatory settings\n"); |
| 8757 | rd = ar->hw_eeprom_rd; |
| 8758 | } |
| 8759 | |
| 8760 | ar->ath_common.regulatory.current_rd = rd; |
| 8761 | return 0; |
| 8762 | } |
| 8763 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8764 | int ath10k_mac_register(struct ath10k *ar) |
| 8765 | { |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 8766 | static const u32 cipher_suites[] = { |
| 8767 | WLAN_CIPHER_SUITE_WEP40, |
| 8768 | WLAN_CIPHER_SUITE_WEP104, |
| 8769 | WLAN_CIPHER_SUITE_TKIP, |
| 8770 | WLAN_CIPHER_SUITE_CCMP, |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 8771 | |
| 8772 | /* Do not add hardware supported ciphers before this line. |
| 8773 | * Allow software encryption for all chips. Don't forget to |
| 8774 | * update n_cipher_suites below. |
| 8775 | */ |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 8776 | WLAN_CIPHER_SUITE_AES_CMAC, |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 8777 | WLAN_CIPHER_SUITE_BIP_CMAC_256, |
| 8778 | WLAN_CIPHER_SUITE_BIP_GMAC_128, |
| 8779 | WLAN_CIPHER_SUITE_BIP_GMAC_256, |
| 8780 | |
| 8781 | /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256 |
| 8782 | * and CCMP-256 in hardware. |
| 8783 | */ |
| 8784 | WLAN_CIPHER_SUITE_GCMP, |
| 8785 | WLAN_CIPHER_SUITE_GCMP_256, |
| 8786 | WLAN_CIPHER_SUITE_CCMP_256, |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 8787 | }; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8788 | struct ieee80211_supported_band *band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8789 | void *channels; |
| 8790 | int ret; |
| 8791 | |
Brian Norris | 234e430 | 2018-09-07 10:21:57 -0700 | [diff] [blame] | 8792 | if (!is_valid_ether_addr(ar->mac_addr)) { |
| 8793 | ath10k_warn(ar, "invalid MAC address; choosing random\n"); |
| 8794 | eth_random_addr(ar->mac_addr); |
| 8795 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8796 | SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr); |
| 8797 | |
| 8798 | SET_IEEE80211_DEV(ar->hw, ar->dev); |
| 8799 | |
Michal Kazior | c94aa7e | 2015-03-24 12:38:11 +0000 | [diff] [blame] | 8800 | BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) + |
| 8801 | ARRAY_SIZE(ath10k_5ghz_channels)) != |
| 8802 | ATH10K_NUM_CHANS); |
| 8803 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8804 | if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) { |
| 8805 | channels = kmemdup(ath10k_2ghz_channels, |
| 8806 | sizeof(ath10k_2ghz_channels), |
| 8807 | GFP_KERNEL); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 8808 | if (!channels) { |
| 8809 | ret = -ENOMEM; |
| 8810 | goto err_free; |
| 8811 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8812 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8813 | band = &ar->mac.sbands[NL80211_BAND_2GHZ]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8814 | band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels); |
| 8815 | band->channels = channels; |
Mohammed Shafi Shajakhan | 5269c65 | 2016-06-07 15:47:04 +0300 | [diff] [blame] | 8816 | |
| 8817 | if (ar->hw_params.cck_rate_map_rev2) { |
| 8818 | band->n_bitrates = ath10k_g_rates_rev2_size; |
| 8819 | band->bitrates = ath10k_g_rates_rev2; |
| 8820 | } else { |
| 8821 | band->n_bitrates = ath10k_g_rates_size; |
| 8822 | band->bitrates = ath10k_g_rates; |
| 8823 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8824 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8825 | ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8826 | } |
| 8827 | |
| 8828 | if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) { |
| 8829 | channels = kmemdup(ath10k_5ghz_channels, |
| 8830 | sizeof(ath10k_5ghz_channels), |
| 8831 | GFP_KERNEL); |
| 8832 | if (!channels) { |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 8833 | ret = -ENOMEM; |
| 8834 | goto err_free; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8835 | } |
| 8836 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8837 | band = &ar->mac.sbands[NL80211_BAND_5GHZ]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8838 | band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels); |
| 8839 | band->channels = channels; |
| 8840 | band->n_bitrates = ath10k_a_rates_size; |
| 8841 | band->bitrates = ath10k_a_rates; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8842 | ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8843 | } |
| 8844 | |
Sven Eckelmann | 34d5629 | 2018-08-24 15:04:59 +0300 | [diff] [blame] | 8845 | wiphy_read_of_freq_limits(ar->hw->wiphy); |
Rajkumar Manoharan | 5036fe0 | 2015-10-27 17:51:14 +0530 | [diff] [blame] | 8846 | ath10k_mac_setup_ht_vht_cap(ar); |
| 8847 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8848 | ar->hw->wiphy->interface_modes = |
| 8849 | BIT(NL80211_IFTYPE_STATION) | |
Bob Copeland | b6c7baf | 2015-09-09 12:47:36 -0400 | [diff] [blame] | 8850 | BIT(NL80211_IFTYPE_AP) | |
| 8851 | BIT(NL80211_IFTYPE_MESH_POINT); |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 8852 | |
Rajkumar Manoharan | 166de3f | 2015-10-27 17:51:11 +0530 | [diff] [blame] | 8853 | ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask; |
| 8854 | ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask; |
Ben Greear | 46acf7bb | 2014-05-16 17:15:38 +0300 | [diff] [blame] | 8855 | |
Kalle Valo | c4cdf75 | 2016-04-20 19:45:18 +0300 | [diff] [blame] | 8856 | if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features)) |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 8857 | ar->hw->wiphy->interface_modes |= |
Michal Kazior | 75d2bd4 | 2014-12-12 12:41:39 +0100 | [diff] [blame] | 8858 | BIT(NL80211_IFTYPE_P2P_DEVICE) | |
Bartosz Markowski | d354181 | 2013-12-10 16:20:40 +0100 | [diff] [blame] | 8859 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 8860 | BIT(NL80211_IFTYPE_P2P_GO); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8861 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 8862 | ieee80211_hw_set(ar->hw, SIGNAL_DBM); |
Venkateswara Naralasetty | 36d9cdb | 2017-10-04 12:22:57 +0300 | [diff] [blame] | 8863 | |
| 8864 | if (!test_bit(ATH10K_FW_FEATURE_NO_PS, |
| 8865 | ar->running_fw->fw_file.fw_features)) { |
| 8866 | ieee80211_hw_set(ar->hw, SUPPORTS_PS); |
| 8867 | ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS); |
| 8868 | } |
| 8869 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 8870 | ieee80211_hw_set(ar->hw, MFP_CAPABLE); |
| 8871 | ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS); |
| 8872 | ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL); |
| 8873 | ieee80211_hw_set(ar->hw, AP_LINK_PS); |
| 8874 | ieee80211_hw_set(ar->hw, SPECTRUM_MGMT); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 8875 | ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT); |
| 8876 | ieee80211_hw_set(ar->hw, CONNECTION_MONITOR); |
| 8877 | ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK); |
| 8878 | ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF); |
| 8879 | ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA); |
| 8880 | ieee80211_hw_set(ar->hw, QUEUE_CONTROL); |
Sara Sharon | f3fe4e9 | 2016-10-18 23:12:11 +0300 | [diff] [blame] | 8881 | ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG); |
Rajkumar Manoharan | ff32eeb | 2016-09-06 12:38:41 +0530 | [diff] [blame] | 8882 | ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8883 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 8884 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
| 8885 | ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL); |
| 8886 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 8887 | ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS; |
Janusz Dziedzic | 0cd9bc1 | 2015-04-10 13:23:23 +0000 | [diff] [blame] | 8888 | ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 8889 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8890 | if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 8891 | ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8892 | |
| 8893 | if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 8894 | ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION); |
| 8895 | ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8896 | } |
| 8897 | |
| 8898 | ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID; |
| 8899 | ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN; |
| 8900 | |
Wen Gong | ce834e2 | 2018-10-04 08:45:31 +0300 | [diff] [blame] | 8901 | if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) { |
| 8902 | ar->hw->wiphy->max_sched_scan_reqs = 1; |
| 8903 | ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS; |
| 8904 | ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS; |
| 8905 | ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH; |
| 8906 | ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS; |
| 8907 | ar->hw->wiphy->max_sched_scan_plan_interval = |
| 8908 | WMI_PNO_MAX_SCHED_SCAN_PLAN_INT; |
| 8909 | ar->hw->wiphy->max_sched_scan_plan_iterations = |
| 8910 | WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS; |
| 8911 | } |
| 8912 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8913 | ar->hw->vif_data_size = sizeof(struct ath10k_vif); |
Michal Kazior | 9797feb | 2014-02-14 14:49:48 +0100 | [diff] [blame] | 8914 | ar->hw->sta_data_size = sizeof(struct ath10k_sta); |
Michal Kazior | 2994687 | 2016-03-06 16:14:34 +0200 | [diff] [blame] | 8915 | ar->hw->txq_data_size = sizeof(struct ath10k_txq); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8916 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8917 | ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL; |
| 8918 | |
Michal Kazior | fbb8f1b | 2015-01-13 16:30:12 +0200 | [diff] [blame] | 8919 | if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) { |
| 8920 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD; |
| 8921 | |
| 8922 | /* Firmware delivers WPS/P2P Probe Requests frames to driver so |
| 8923 | * that userspace (e.g. wpa_supplicant/hostapd) can generate |
| 8924 | * correct Probe Responses. This is more of a hack advert.. |
| 8925 | */ |
| 8926 | ar->hw->wiphy->probe_resp_offload |= |
| 8927 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS | |
| 8928 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 | |
| 8929 | NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P; |
| 8930 | } |
| 8931 | |
Manikanta Pubbisetty | add6cd8 | 2017-07-28 15:15:42 +0300 | [diff] [blame] | 8932 | if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) || |
| 8933 | test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) { |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 8934 | ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
Balaji Pothunoori | 14d6577 | 2017-12-21 20:00:42 +0530 | [diff] [blame] | 8935 | if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map)) |
| 8936 | ieee80211_hw_set(ar->hw, TDLS_WIDER_BW); |
Manikanta Pubbisetty | add6cd8 | 2017-07-28 15:15:42 +0300 | [diff] [blame] | 8937 | } |
Marek Puzyniak | 75d85fd | 2015-03-30 09:51:53 +0300 | [diff] [blame] | 8938 | |
Yingying Tang | 802ca33 | 2018-03-28 12:12:52 +0300 | [diff] [blame] | 8939 | if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map)) |
| 8940 | ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA); |
| 8941 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8942 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Michal Kazior | c2df44b | 2014-01-23 11:38:26 +0100 | [diff] [blame] | 8943 | ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8944 | ar->hw->wiphy->max_remain_on_channel_duration = 5000; |
| 8945 | |
| 8946 | ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
Vasanthakumar Thiagarajan | bf031bc | 2016-03-15 15:25:53 +0530 | [diff] [blame] | 8947 | ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
| 8948 | NL80211_FEATURE_AP_SCAN; |
Rajkumar Manoharan | 78157a1 | 2014-11-17 16:44:15 +0200 | [diff] [blame] | 8949 | |
Janusz.Dziedzic@tieto.com | 37a0b39 | 2015-03-12 13:11:41 +0100 | [diff] [blame] | 8950 | ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations; |
| 8951 | |
Janusz Dziedzic | 5fd3ac3 | 2015-03-23 17:32:53 +0200 | [diff] [blame] | 8952 | ret = ath10k_wow_init(ar); |
| 8953 | if (ret) { |
| 8954 | ath10k_warn(ar, "failed to init wow: %d\n", ret); |
| 8955 | goto err_free; |
| 8956 | } |
| 8957 | |
Janusz Dziedzic | c702534 | 2015-06-15 14:46:41 +0300 | [diff] [blame] | 8958 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
Pradeep Kumar Chitrapu | be8cce9 | 2018-05-23 11:09:09 +0300 | [diff] [blame] | 8959 | wiphy_ext_feature_set(ar->hw->wiphy, |
| 8960 | NL80211_EXT_FEATURE_SET_SCAN_DWELL); |
Janusz Dziedzic | c702534 | 2015-06-15 14:46:41 +0300 | [diff] [blame] | 8961 | |
Balaji Pothunoori | 6bc1795 | 2018-09-10 11:54:30 +0530 | [diff] [blame] | 8962 | if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) || |
| 8963 | test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map)) |
Balaji Pothunoori | c7fd8d2 | 2018-09-04 12:52:18 +0300 | [diff] [blame] | 8964 | wiphy_ext_feature_set(ar->hw->wiphy, |
Balaji Pothunoori | 6bc1795 | 2018-09-10 11:54:30 +0530 | [diff] [blame] | 8965 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT); |
Balaji Pothunoori | c7fd8d2 | 2018-09-04 12:52:18 +0300 | [diff] [blame] | 8966 | |
Manikanta Pubbisetty | bb31b7c | 2019-02-11 18:47:59 +0200 | [diff] [blame] | 8967 | if (ath10k_peer_stats_enabled(ar) || |
| 8968 | test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map)) |
Kan Yan | d1ce37b | 2019-02-11 18:47:52 +0200 | [diff] [blame] | 8969 | wiphy_ext_feature_set(ar->hw->wiphy, |
| 8970 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS); |
Pradeep Kumar Chitrapu | 059104b | 2019-02-11 18:47:54 +0200 | [diff] [blame] | 8971 | |
| 8972 | if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) |
| 8973 | wiphy_ext_feature_set(ar->hw->wiphy, |
| 8974 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); |
| 8975 | |
Ashok Raj Nagarajan | 33410a5 | 2019-06-03 18:09:02 +0300 | [diff] [blame] | 8976 | if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER, ar->wmi.svc_map)) |
| 8977 | wiphy_ext_feature_set(ar->hw->wiphy, |
| 8978 | NL80211_EXT_FEATURE_STA_TX_PWR); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8979 | /* |
| 8980 | * on LL hardware queues are managed entirely by the FW |
| 8981 | * so we only advertise to mac we can do the queues thing |
| 8982 | */ |
Michal Kazior | 96d828d | 2015-03-31 10:26:23 +0000 | [diff] [blame] | 8983 | ar->hw->queues = IEEE80211_MAX_QUEUES; |
| 8984 | |
| 8985 | /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is |
| 8986 | * something that vdev_ids can't reach so that we don't stop the queue |
| 8987 | * accidentally. |
| 8988 | */ |
| 8989 | ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 8990 | |
Kalle Valo | bf3c13a | 2016-04-20 19:45:33 +0300 | [diff] [blame] | 8991 | switch (ar->running_fw->fw_file.wmi_op_version) { |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 8992 | case ATH10K_FW_WMI_OP_VERSION_MAIN: |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 8993 | ar->hw->wiphy->iface_combinations = ath10k_if_comb; |
| 8994 | ar->hw->wiphy->n_iface_combinations = |
| 8995 | ARRAY_SIZE(ath10k_if_comb); |
Michal Kazior | cf850d1 | 2014-07-24 20:07:00 +0300 | [diff] [blame] | 8996 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 8997 | break; |
Michal Kazior | cf32784 | 2015-03-31 10:26:25 +0000 | [diff] [blame] | 8998 | case ATH10K_FW_WMI_OP_VERSION_TLV: |
| 8999 | if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) { |
| 9000 | ar->hw->wiphy->iface_combinations = |
| 9001 | ath10k_tlv_qcs_if_comb; |
| 9002 | ar->hw->wiphy->n_iface_combinations = |
| 9003 | ARRAY_SIZE(ath10k_tlv_qcs_if_comb); |
| 9004 | } else { |
| 9005 | ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb; |
| 9006 | ar->hw->wiphy->n_iface_combinations = |
| 9007 | ARRAY_SIZE(ath10k_tlv_if_comb); |
| 9008 | } |
| 9009 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC); |
| 9010 | break; |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 9011 | case ATH10K_FW_WMI_OP_VERSION_10_1: |
| 9012 | case ATH10K_FW_WMI_OP_VERSION_10_2: |
Rajkumar Manoharan | 4a16fbe | 2014-12-17 12:21:12 +0200 | [diff] [blame] | 9013 | case ATH10K_FW_WMI_OP_VERSION_10_2_4: |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 9014 | ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb; |
| 9015 | ar->hw->wiphy->n_iface_combinations = |
| 9016 | ARRAY_SIZE(ath10k_10x_if_comb); |
| 9017 | break; |
Raja Mani | 9bd2132 | 2015-06-22 20:10:09 +0530 | [diff] [blame] | 9018 | case ATH10K_FW_WMI_OP_VERSION_10_4: |
Raja Mani | cf36fef | 2015-06-22 20:22:25 +0530 | [diff] [blame] | 9019 | ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb; |
| 9020 | ar->hw->wiphy->n_iface_combinations = |
| 9021 | ARRAY_SIZE(ath10k_10_4_if_comb); |
Maharaja Kennadyrajan | 4600563 | 2018-09-18 17:37:26 +0530 | [diff] [blame] | 9022 | if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT, |
| 9023 | ar->wmi.svc_map)) { |
| 9024 | ar->hw->wiphy->iface_combinations = |
| 9025 | ath10k_10_4_bcn_int_if_comb; |
| 9026 | ar->hw->wiphy->n_iface_combinations = |
| 9027 | ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb); |
| 9028 | } |
Raja Mani | 9bd2132 | 2015-06-22 20:10:09 +0530 | [diff] [blame] | 9029 | break; |
Kalle Valo | 5cc7caf | 2014-12-17 12:20:54 +0200 | [diff] [blame] | 9030 | case ATH10K_FW_WMI_OP_VERSION_UNSET: |
| 9031 | case ATH10K_FW_WMI_OP_VERSION_MAX: |
| 9032 | WARN_ON(1); |
| 9033 | ret = -EINVAL; |
| 9034 | goto err_free; |
Bartosz Markowski | f259509 | 2013-12-10 16:20:39 +0100 | [diff] [blame] | 9035 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9036 | |
David Liu | ccec903 | 2015-07-24 20:25:32 +0300 | [diff] [blame] | 9037 | if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) |
| 9038 | ar->hw->netdev_features = NETIF_F_HW_CSUM; |
Michal Kazior | 7c19999 | 2013-07-31 10:47:57 +0200 | [diff] [blame] | 9039 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 9040 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) { |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 9041 | /* Init ath dfs pattern detector */ |
| 9042 | ar->ath_common.debug_mask = ATH_DBG_DFS; |
| 9043 | ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common, |
| 9044 | NL80211_DFS_UNSET); |
| 9045 | |
| 9046 | if (!ar->dfs_detector) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 9047 | ath10k_warn(ar, "failed to initialise DFS pattern detector\n"); |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 9048 | } |
| 9049 | |
Bartosz Markowski | 209b2a6 | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 9050 | ret = ath10k_mac_init_rd(ar); |
| 9051 | if (ret) { |
| 9052 | ath10k_err(ar, "failed to derive regdom: %d\n", ret); |
| 9053 | goto err_dfs_detector_exit; |
| 9054 | } |
| 9055 | |
Benjamin Berg | ebee76f | 2016-09-28 15:11:58 +0300 | [diff] [blame] | 9056 | /* Disable set_coverage_class for chipsets that do not support it. */ |
| 9057 | if (!ar->hw_params.hw_ops->set_coverage_class) |
| 9058 | ar->ops->set_coverage_class = NULL; |
| 9059 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9060 | ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy, |
| 9061 | ath10k_reg_notifier); |
| 9062 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 9063 | ath10k_err(ar, "failed to initialise regulatory: %i\n", ret); |
Jeff Johnson | 0e33944 | 2015-10-08 09:15:53 -0700 | [diff] [blame] | 9064 | goto err_dfs_detector_exit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9065 | } |
| 9066 | |
Carl Huang | 60e1d0f | 2018-04-19 19:39:40 +0300 | [diff] [blame] | 9067 | if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) { |
Carl Huang | 60e1d0f | 2018-04-19 19:39:40 +0300 | [diff] [blame] | 9068 | ar->hw->wiphy->features |= |
| 9069 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 9070 | } |
| 9071 | |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 9072 | ar->hw->wiphy->cipher_suites = cipher_suites; |
Rajkumar Manoharan | 2ea9f12 | 2017-09-25 15:29:41 -0700 | [diff] [blame] | 9073 | |
| 9074 | /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128 |
| 9075 | * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported |
| 9076 | * from chip specific hw_param table. |
| 9077 | */ |
| 9078 | if (!ar->hw_params.n_cipher_suites || |
| 9079 | ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) { |
| 9080 | ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n", |
| 9081 | ar->hw_params.n_cipher_suites); |
| 9082 | ar->hw_params.n_cipher_suites = 8; |
| 9083 | } |
| 9084 | ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites; |
Johannes Berg | 3cb1094 | 2015-01-22 21:38:45 +0100 | [diff] [blame] | 9085 | |
Andrew Zaborowski | ae44b50 | 2017-02-10 04:50:23 +0100 | [diff] [blame] | 9086 | wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); |
| 9087 | |
Toke Høiland-Jørgensen | bb2edb7 | 2019-02-11 18:47:49 +0200 | [diff] [blame] | 9088 | ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER; |
| 9089 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9090 | ret = ieee80211_register_hw(ar->hw); |
| 9091 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 9092 | ath10k_err(ar, "failed to register ieee80211: %d\n", ret); |
Jeff Johnson | 0e33944 | 2015-10-08 09:15:53 -0700 | [diff] [blame] | 9093 | goto err_dfs_detector_exit; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9094 | } |
| 9095 | |
Manikanta Pubbisetty | 4920ce3 | 2019-02-11 18:47:56 +0200 | [diff] [blame] | 9096 | if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT, ar->wmi.svc_map)) { |
| 9097 | ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN); |
| 9098 | ar->hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN); |
| 9099 | } |
| 9100 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9101 | if (!ath_is_world_regd(&ar->ath_common.regulatory)) { |
| 9102 | ret = regulatory_hint(ar->hw->wiphy, |
| 9103 | ar->ath_common.regulatory.alpha2); |
| 9104 | if (ret) |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 9105 | goto err_unregister; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9106 | } |
| 9107 | |
| 9108 | return 0; |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 9109 | |
| 9110 | err_unregister: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9111 | ieee80211_unregister_hw(ar->hw); |
Jeff Johnson | 0e33944 | 2015-10-08 09:15:53 -0700 | [diff] [blame] | 9112 | |
| 9113 | err_dfs_detector_exit: |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 9114 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
Jeff Johnson | 0e33944 | 2015-10-08 09:15:53 -0700 | [diff] [blame] | 9115 | ar->dfs_detector->exit(ar->dfs_detector); |
| 9116 | |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 9117 | err_free: |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9118 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 9119 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); |
Michal Kazior | d6015b2 | 2013-07-22 14:13:30 +0200 | [diff] [blame] | 9120 | |
Jeff Johnson | 0e33944 | 2015-10-08 09:15:53 -0700 | [diff] [blame] | 9121 | SET_IEEE80211_DEV(ar->hw, NULL); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9122 | return ret; |
| 9123 | } |
| 9124 | |
| 9125 | void ath10k_mac_unregister(struct ath10k *ar) |
| 9126 | { |
| 9127 | ieee80211_unregister_hw(ar->hw); |
| 9128 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 9129 | if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) |
Janusz Dziedzic | 9702c68 | 2013-11-20 09:59:41 +0200 | [diff] [blame] | 9130 | ar->dfs_detector->exit(ar->dfs_detector); |
| 9131 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9132 | kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels); |
| 9133 | kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 9134 | |
| 9135 | SET_IEEE80211_DEV(ar->hw, NULL); |
| 9136 | } |