2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <net/cfg80211.h>
22 #include <net/mac80211.h>
23 #include <linux/etherdevice.h>
24 #include <linux/acpi.h>
42 static struct ieee80211_rate ath10k_rates[] = {
44 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
46 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
47 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
48 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
50 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
51 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
52 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
54 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
55 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
56 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
58 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
59 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
60 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
61 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
62 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
63 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
64 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
65 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
68 static struct ieee80211_rate ath10k_rates_rev2[] = {
70 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
72 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
73 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
74 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
76 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
77 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
78 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
80 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
81 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
82 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
84 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
85 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
86 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
87 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
88 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
89 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
90 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
91 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
94 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
96 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
97 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
98 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
99 #define ath10k_g_rates (ath10k_rates + 0)
100 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
102 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
103 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
105 #define ath10k_wmi_legacy_rates ath10k_rates
107 static bool ath10k_mac_bitrate_is_cck(int bitrate)
120 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
122 return DIV_ROUND_UP(bitrate, 5) |
123 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
126 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
127 u8 hw_rate, bool cck)
129 const struct ieee80211_rate *rate;
132 for (i = 0; i < sband->n_bitrates; i++) {
133 rate = &sband->bitrates[i];
135 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
138 if (rate->hw_value == hw_rate)
140 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
141 rate->hw_value_short == hw_rate)
148 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
153 for (i = 0; i < sband->n_bitrates; i++)
154 if (sband->bitrates[i].bitrate == bitrate)
160 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
162 switch ((mcs_map >> (2 * nss)) & 0x3) {
163 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
164 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
165 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
171 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
175 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
176 if (ht_mcs_mask[nss])
183 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
187 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
188 if (vht_mcs_mask[nss])
194 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
196 enum wmi_host_platform_type platform_type;
199 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
200 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
202 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
204 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
206 if (ret && ret != -EOPNOTSUPP) {
207 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
218 static int ath10k_send_key(struct ath10k_vif *arvif,
219 struct ieee80211_key_conf *key,
220 enum set_key_cmd cmd,
221 const u8 *macaddr, u32 flags)
223 struct ath10k *ar = arvif->ar;
224 struct wmi_vdev_install_key_arg arg = {
225 .vdev_id = arvif->vdev_id,
226 .key_idx = key->keyidx,
227 .key_len = key->keylen,
228 .key_data = key->key,
233 lockdep_assert_held(&arvif->ar->conf_mutex);
235 switch (key->cipher) {
236 case WLAN_CIPHER_SUITE_CCMP:
237 arg.key_cipher = WMI_CIPHER_AES_CCM;
238 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
240 case WLAN_CIPHER_SUITE_TKIP:
241 arg.key_cipher = WMI_CIPHER_TKIP;
242 arg.key_txmic_len = 8;
243 arg.key_rxmic_len = 8;
245 case WLAN_CIPHER_SUITE_WEP40:
246 case WLAN_CIPHER_SUITE_WEP104:
247 arg.key_cipher = WMI_CIPHER_WEP;
249 case WLAN_CIPHER_SUITE_CCMP_256:
250 arg.key_cipher = WMI_CIPHER_AES_CCM;
252 case WLAN_CIPHER_SUITE_GCMP:
253 case WLAN_CIPHER_SUITE_GCMP_256:
254 arg.key_cipher = WMI_CIPHER_AES_GCM;
256 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
257 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
258 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
259 case WLAN_CIPHER_SUITE_AES_CMAC:
263 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
267 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
268 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
270 if (cmd == DISABLE_KEY) {
271 arg.key_cipher = WMI_CIPHER_NONE;
275 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
278 static int ath10k_install_key(struct ath10k_vif *arvif,
279 struct ieee80211_key_conf *key,
280 enum set_key_cmd cmd,
281 const u8 *macaddr, u32 flags)
283 struct ath10k *ar = arvif->ar;
285 unsigned long time_left;
287 lockdep_assert_held(&ar->conf_mutex);
289 reinit_completion(&ar->install_key_done);
291 if (arvif->nohwcrypt)
294 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
298 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
305 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
308 struct ath10k *ar = arvif->ar;
309 struct ath10k_peer *peer;
314 lockdep_assert_held(&ar->conf_mutex);
316 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
317 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
318 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
321 spin_lock_bh(&ar->data_lock);
322 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
323 spin_unlock_bh(&ar->data_lock);
328 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
329 if (arvif->wep_keys[i] == NULL)
332 switch (arvif->vif->type) {
333 case NL80211_IFTYPE_AP:
334 flags = WMI_KEY_PAIRWISE;
336 if (arvif->def_wep_key_idx == i)
337 flags |= WMI_KEY_TX_USAGE;
339 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
340 SET_KEY, addr, flags);
344 case NL80211_IFTYPE_ADHOC:
345 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
351 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
352 SET_KEY, addr, WMI_KEY_GROUP);
361 spin_lock_bh(&ar->data_lock);
362 peer->keys[i] = arvif->wep_keys[i];
363 spin_unlock_bh(&ar->data_lock);
366 /* In some cases (notably with static WEP IBSS with multiple keys)
367 * multicast Tx becomes broken. Both pairwise and groupwise keys are
368 * installed already. Using WMI_KEY_TX_USAGE in different combinations
369 * didn't seem help. Using def_keyid vdev parameter seems to be
370 * effective so use that.
372 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
374 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
377 if (arvif->def_wep_key_idx == -1)
380 ret = ath10k_wmi_vdev_set_param(arvif->ar,
382 arvif->ar->wmi.vdev_param->def_keyid,
383 arvif->def_wep_key_idx);
385 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
386 arvif->vdev_id, ret);
393 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
396 struct ath10k *ar = arvif->ar;
397 struct ath10k_peer *peer;
403 lockdep_assert_held(&ar->conf_mutex);
405 spin_lock_bh(&ar->data_lock);
406 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
407 spin_unlock_bh(&ar->data_lock);
412 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
413 if (peer->keys[i] == NULL)
416 /* key flags are not required to delete the key */
417 ret = ath10k_install_key(arvif, peer->keys[i],
418 DISABLE_KEY, addr, flags);
419 if (ret < 0 && first_errno == 0)
423 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
426 spin_lock_bh(&ar->data_lock);
427 peer->keys[i] = NULL;
428 spin_unlock_bh(&ar->data_lock);
434 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
437 struct ath10k_peer *peer;
440 lockdep_assert_held(&ar->data_lock);
442 /* We don't know which vdev this peer belongs to,
443 * since WMI doesn't give us that information.
445 * FIXME: multi-bss needs to be handled.
447 peer = ath10k_peer_find(ar, 0, addr);
451 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
452 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
459 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
460 struct ieee80211_key_conf *key)
462 struct ath10k *ar = arvif->ar;
463 struct ath10k_peer *peer;
470 lockdep_assert_held(&ar->conf_mutex);
473 /* since ath10k_install_key we can't hold data_lock all the
474 * time, so we try to remove the keys incrementally
476 spin_lock_bh(&ar->data_lock);
478 list_for_each_entry(peer, &ar->peers, list) {
479 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
480 if (peer->keys[i] == key) {
481 ether_addr_copy(addr, peer->addr);
482 peer->keys[i] = NULL;
487 if (i < ARRAY_SIZE(peer->keys))
490 spin_unlock_bh(&ar->data_lock);
492 if (i == ARRAY_SIZE(peer->keys))
494 /* key flags are not required to delete the key */
495 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
496 if (ret < 0 && first_errno == 0)
500 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
507 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
508 struct ieee80211_key_conf *key)
510 struct ath10k *ar = arvif->ar;
511 struct ath10k_peer *peer;
514 lockdep_assert_held(&ar->conf_mutex);
516 list_for_each_entry(peer, &ar->peers, list) {
517 if (ether_addr_equal(peer->addr, arvif->vif->addr))
520 if (ether_addr_equal(peer->addr, arvif->bssid))
523 if (peer->keys[key->keyidx] == key)
526 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
527 arvif->vdev_id, key->keyidx);
529 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
531 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
532 arvif->vdev_id, peer->addr, ret);
540 /*********************/
541 /* General utilities */
542 /*********************/
544 static inline enum wmi_phy_mode
545 chan_to_phymode(const struct cfg80211_chan_def *chandef)
547 enum wmi_phy_mode phymode = MODE_UNKNOWN;
549 switch (chandef->chan->band) {
550 case NL80211_BAND_2GHZ:
551 switch (chandef->width) {
552 case NL80211_CHAN_WIDTH_20_NOHT:
553 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
558 case NL80211_CHAN_WIDTH_20:
559 phymode = MODE_11NG_HT20;
561 case NL80211_CHAN_WIDTH_40:
562 phymode = MODE_11NG_HT40;
564 case NL80211_CHAN_WIDTH_5:
565 case NL80211_CHAN_WIDTH_10:
566 case NL80211_CHAN_WIDTH_80:
567 case NL80211_CHAN_WIDTH_80P80:
568 case NL80211_CHAN_WIDTH_160:
569 phymode = MODE_UNKNOWN;
573 case NL80211_BAND_5GHZ:
574 switch (chandef->width) {
575 case NL80211_CHAN_WIDTH_20_NOHT:
578 case NL80211_CHAN_WIDTH_20:
579 phymode = MODE_11NA_HT20;
581 case NL80211_CHAN_WIDTH_40:
582 phymode = MODE_11NA_HT40;
584 case NL80211_CHAN_WIDTH_80:
585 phymode = MODE_11AC_VHT80;
587 case NL80211_CHAN_WIDTH_160:
588 phymode = MODE_11AC_VHT160;
590 case NL80211_CHAN_WIDTH_80P80:
591 phymode = MODE_11AC_VHT80_80;
593 case NL80211_CHAN_WIDTH_5:
594 case NL80211_CHAN_WIDTH_10:
595 phymode = MODE_UNKNOWN;
603 WARN_ON(phymode == MODE_UNKNOWN);
607 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
610 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
611 * 0 for no restriction
620 switch (mpdudensity) {
626 /* Our lower layer calculations limit our precision to
643 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
644 struct cfg80211_chan_def *def)
646 struct ieee80211_chanctx_conf *conf;
649 conf = rcu_dereference(vif->chanctx_conf);
661 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
662 struct ieee80211_chanctx_conf *conf,
670 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
674 ieee80211_iter_chan_contexts_atomic(ar->hw,
675 ath10k_mac_num_chanctxs_iter,
682 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
683 struct ieee80211_chanctx_conf *conf,
686 struct cfg80211_chan_def **def = data;
691 static int ath10k_peer_create(struct ath10k *ar,
692 struct ieee80211_vif *vif,
693 struct ieee80211_sta *sta,
696 enum wmi_peer_type peer_type)
698 struct ath10k_vif *arvif;
699 struct ath10k_peer *peer;
703 lockdep_assert_held(&ar->conf_mutex);
705 num_peers = ar->num_peers;
707 /* Each vdev consumes a peer entry as well */
708 list_for_each_entry(arvif, &ar->arvifs, list)
711 if (num_peers >= ar->max_num_peers)
714 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
716 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
721 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
723 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
728 spin_lock_bh(&ar->data_lock);
730 peer = ath10k_peer_find(ar, vdev_id, addr);
732 spin_unlock_bh(&ar->data_lock);
733 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
735 ath10k_wmi_peer_delete(ar, vdev_id, addr);
742 spin_unlock_bh(&ar->data_lock);
749 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
751 struct ath10k *ar = arvif->ar;
755 param = ar->wmi.pdev_param->sta_kickout_th;
756 ret = ath10k_wmi_pdev_set_param(ar, param,
757 ATH10K_KICKOUT_THRESHOLD);
759 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
760 arvif->vdev_id, ret);
764 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
765 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
766 ATH10K_KEEPALIVE_MIN_IDLE);
768 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
769 arvif->vdev_id, ret);
773 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
774 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
775 ATH10K_KEEPALIVE_MAX_IDLE);
777 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
778 arvif->vdev_id, ret);
782 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
783 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
784 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
786 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
787 arvif->vdev_id, ret);
794 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
796 struct ath10k *ar = arvif->ar;
799 vdev_param = ar->wmi.vdev_param->rts_threshold;
800 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
803 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
807 lockdep_assert_held(&ar->conf_mutex);
809 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
813 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
822 static void ath10k_peer_map_cleanup(struct ath10k *ar, struct ath10k_peer *peer)
826 lockdep_assert_held(&ar->conf_mutex);
828 for_each_set_bit(peer_id, peer->peer_ids,
829 ATH10K_MAX_NUM_PEER_IDS) {
830 ar->peer_map[peer_id] = NULL;
833 /* Double check that peer is properly un-referenced from
836 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
837 if (ar->peer_map[i] == peer) {
838 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
839 peer->addr, peer, i);
840 ar->peer_map[i] = NULL;
844 list_del(&peer->list);
849 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
851 struct ath10k_peer *peer, *tmp;
853 lockdep_assert_held(&ar->conf_mutex);
855 spin_lock_bh(&ar->data_lock);
856 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
857 if (peer->vdev_id != vdev_id)
860 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
861 peer->addr, vdev_id);
863 ath10k_peer_map_cleanup(ar, peer);
865 spin_unlock_bh(&ar->data_lock);
868 static void ath10k_peer_cleanup_all(struct ath10k *ar)
870 struct ath10k_peer *peer, *tmp;
873 lockdep_assert_held(&ar->conf_mutex);
875 spin_lock_bh(&ar->data_lock);
876 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
877 list_del(&peer->list);
881 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
882 ar->peer_map[i] = NULL;
884 spin_unlock_bh(&ar->data_lock);
887 ar->num_stations = 0;
890 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
891 struct ieee80211_sta *sta,
892 enum wmi_tdls_peer_state state)
895 struct wmi_tdls_peer_update_cmd_arg arg = {};
896 struct wmi_tdls_peer_capab_arg cap = {};
897 struct wmi_channel_arg chan_arg = {};
899 lockdep_assert_held(&ar->conf_mutex);
901 arg.vdev_id = vdev_id;
902 arg.peer_state = state;
903 ether_addr_copy(arg.addr, sta->addr);
905 cap.peer_max_sp = sta->max_sp;
906 cap.peer_uapsd_queues = sta->uapsd_queues;
908 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
909 !sta->tdls_initiator)
910 cap.is_peer_responder = 1;
912 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
914 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
915 arg.addr, vdev_id, ret);
922 /************************/
923 /* Interface management */
924 /************************/
926 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
928 struct ath10k *ar = arvif->ar;
930 lockdep_assert_held(&ar->data_lock);
935 if (!arvif->beacon_buf)
936 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
937 arvif->beacon->len, DMA_TO_DEVICE);
939 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
940 arvif->beacon_state != ATH10K_BEACON_SENT))
943 dev_kfree_skb_any(arvif->beacon);
945 arvif->beacon = NULL;
946 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
949 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
951 struct ath10k *ar = arvif->ar;
953 lockdep_assert_held(&ar->data_lock);
955 ath10k_mac_vif_beacon_free(arvif);
957 if (arvif->beacon_buf) {
958 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
959 arvif->beacon_buf, arvif->beacon_paddr);
960 arvif->beacon_buf = NULL;
964 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
966 unsigned long time_left;
968 lockdep_assert_held(&ar->conf_mutex);
970 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
973 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
974 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
978 return ar->last_wmi_vdev_start_status;
981 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
983 struct cfg80211_chan_def *chandef = NULL;
984 struct ieee80211_channel *channel = NULL;
985 struct wmi_vdev_start_request_arg arg = {};
988 lockdep_assert_held(&ar->conf_mutex);
990 ieee80211_iter_chan_contexts_atomic(ar->hw,
991 ath10k_mac_get_any_chandef_iter,
993 if (WARN_ON_ONCE(!chandef))
996 channel = chandef->chan;
998 arg.vdev_id = vdev_id;
999 arg.channel.freq = channel->center_freq;
1000 arg.channel.band_center_freq1 = chandef->center_freq1;
1001 arg.channel.band_center_freq2 = chandef->center_freq2;
1003 /* TODO setup this dynamically, what in case we
1004 * don't have any vifs?
1006 arg.channel.mode = chan_to_phymode(chandef);
1007 arg.channel.chan_radar =
1008 !!(channel->flags & IEEE80211_CHAN_RADAR);
1010 arg.channel.min_power = 0;
1011 arg.channel.max_power = channel->max_power * 2;
1012 arg.channel.max_reg_power = channel->max_reg_power * 2;
1013 arg.channel.max_antenna_gain = channel->max_antenna_gain;
1015 reinit_completion(&ar->vdev_setup_done);
1017 ret = ath10k_wmi_vdev_start(ar, &arg);
1019 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1024 ret = ath10k_vdev_setup_sync(ar);
1026 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1031 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1033 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1038 ar->monitor_vdev_id = vdev_id;
1040 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1041 ar->monitor_vdev_id);
1045 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1047 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1048 ar->monitor_vdev_id, ret);
1053 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1057 lockdep_assert_held(&ar->conf_mutex);
1059 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1061 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1062 ar->monitor_vdev_id, ret);
1064 reinit_completion(&ar->vdev_setup_done);
1066 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1068 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1069 ar->monitor_vdev_id, ret);
1071 ret = ath10k_vdev_setup_sync(ar);
1073 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1074 ar->monitor_vdev_id, ret);
1076 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1077 ar->monitor_vdev_id);
1081 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1085 lockdep_assert_held(&ar->conf_mutex);
1087 if (ar->free_vdev_map == 0) {
1088 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1092 bit = __ffs64(ar->free_vdev_map);
1094 ar->monitor_vdev_id = bit;
1096 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1097 WMI_VDEV_TYPE_MONITOR,
1100 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1101 ar->monitor_vdev_id, ret);
1105 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1106 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1107 ar->monitor_vdev_id);
1112 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1116 lockdep_assert_held(&ar->conf_mutex);
1118 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1120 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1121 ar->monitor_vdev_id, ret);
1125 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1127 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1128 ar->monitor_vdev_id);
1132 static int ath10k_monitor_start(struct ath10k *ar)
1136 lockdep_assert_held(&ar->conf_mutex);
1138 ret = ath10k_monitor_vdev_create(ar);
1140 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1144 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1146 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1147 ath10k_monitor_vdev_delete(ar);
1151 ar->monitor_started = true;
1152 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1157 static int ath10k_monitor_stop(struct ath10k *ar)
1161 lockdep_assert_held(&ar->conf_mutex);
1163 ret = ath10k_monitor_vdev_stop(ar);
1165 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1169 ret = ath10k_monitor_vdev_delete(ar);
1171 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1175 ar->monitor_started = false;
1176 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1181 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1185 /* At least one chanctx is required to derive a channel to start
1188 num_ctx = ath10k_mac_num_chanctxs(ar);
1192 /* If there's already an existing special monitor interface then don't
1193 * bother creating another monitor vdev.
1195 if (ar->monitor_arvif)
1198 return ar->monitor ||
1199 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1200 ar->running_fw->fw_file.fw_features) &&
1201 (ar->filter_flags & FIF_OTHER_BSS)) ||
1202 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1205 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1209 num_ctx = ath10k_mac_num_chanctxs(ar);
1211 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1212 * shouldn't allow this but make sure to prevent handling the following
1213 * case anyway since multi-channel DFS hasn't been tested at all.
1215 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1221 static int ath10k_monitor_recalc(struct ath10k *ar)
1227 lockdep_assert_held(&ar->conf_mutex);
1229 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1230 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1232 ath10k_dbg(ar, ATH10K_DBG_MAC,
1233 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1234 ar->monitor_started, needed, allowed);
1236 if (WARN_ON(needed && !allowed)) {
1237 if (ar->monitor_started) {
1238 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1240 ret = ath10k_monitor_stop(ar);
1242 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1250 if (needed == ar->monitor_started)
1254 return ath10k_monitor_start(ar);
1256 return ath10k_monitor_stop(ar);
1259 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1261 struct ath10k *ar = arvif->ar;
1263 lockdep_assert_held(&ar->conf_mutex);
1265 if (!arvif->is_started) {
1266 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1273 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1275 struct ath10k *ar = arvif->ar;
1278 lockdep_assert_held(&ar->conf_mutex);
1280 vdev_param = ar->wmi.vdev_param->protection_mode;
1282 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1283 arvif->vdev_id, arvif->use_cts_prot);
1285 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1286 arvif->use_cts_prot ? 1 : 0);
1289 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1291 struct ath10k *ar = arvif->ar;
1292 u32 vdev_param, rts_cts = 0;
1294 lockdep_assert_held(&ar->conf_mutex);
1296 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1298 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1300 if (arvif->num_legacy_stations > 0)
1301 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1302 WMI_RTSCTS_PROFILE);
1304 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1305 WMI_RTSCTS_PROFILE);
1307 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1308 arvif->vdev_id, rts_cts);
1310 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1314 static int ath10k_start_cac(struct ath10k *ar)
1318 lockdep_assert_held(&ar->conf_mutex);
1320 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1322 ret = ath10k_monitor_recalc(ar);
1324 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1325 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1329 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1330 ar->monitor_vdev_id);
1335 static int ath10k_stop_cac(struct ath10k *ar)
1337 lockdep_assert_held(&ar->conf_mutex);
1339 /* CAC is not running - do nothing */
1340 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1343 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1344 ath10k_monitor_stop(ar);
1346 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1351 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1352 struct ieee80211_chanctx_conf *conf,
1357 if (!*ret && conf->radar_enabled)
1361 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1363 bool has_radar = false;
1365 ieee80211_iter_chan_contexts_atomic(ar->hw,
1366 ath10k_mac_has_radar_iter,
1372 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1376 lockdep_assert_held(&ar->conf_mutex);
1378 ath10k_stop_cac(ar);
1380 if (!ath10k_mac_has_radar_enabled(ar))
1383 if (ar->num_started_vdevs > 0)
1386 ret = ath10k_start_cac(ar);
1389 * Not possible to start CAC on current channel so starting
1390 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1391 * by indicating that radar was detected.
1393 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1394 ieee80211_radar_detected(ar->hw);
1398 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1400 struct ath10k *ar = arvif->ar;
1403 lockdep_assert_held(&ar->conf_mutex);
1405 reinit_completion(&ar->vdev_setup_done);
1407 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1409 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1410 arvif->vdev_id, ret);
1414 ret = ath10k_vdev_setup_sync(ar);
1416 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1417 arvif->vdev_id, ret);
1421 WARN_ON(ar->num_started_vdevs == 0);
1423 if (ar->num_started_vdevs != 0) {
1424 ar->num_started_vdevs--;
1425 ath10k_recalc_radar_detection(ar);
1431 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1432 const struct cfg80211_chan_def *chandef,
1435 struct ath10k *ar = arvif->ar;
1436 struct wmi_vdev_start_request_arg arg = {};
1439 lockdep_assert_held(&ar->conf_mutex);
1441 reinit_completion(&ar->vdev_setup_done);
1443 arg.vdev_id = arvif->vdev_id;
1444 arg.dtim_period = arvif->dtim_period;
1445 arg.bcn_intval = arvif->beacon_interval;
1447 arg.channel.freq = chandef->chan->center_freq;
1448 arg.channel.band_center_freq1 = chandef->center_freq1;
1449 arg.channel.band_center_freq2 = chandef->center_freq2;
1450 arg.channel.mode = chan_to_phymode(chandef);
1452 arg.channel.min_power = 0;
1453 arg.channel.max_power = chandef->chan->max_power * 2;
1454 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1455 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
1457 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1458 arg.ssid = arvif->u.ap.ssid;
1459 arg.ssid_len = arvif->u.ap.ssid_len;
1460 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1462 /* For now allow DFS for AP mode */
1463 arg.channel.chan_radar =
1464 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1465 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1466 arg.ssid = arvif->vif->bss_conf.ssid;
1467 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1470 ath10k_dbg(ar, ATH10K_DBG_MAC,
1471 "mac vdev %d start center_freq %d phymode %s\n",
1472 arg.vdev_id, arg.channel.freq,
1473 ath10k_wmi_phymode_str(arg.channel.mode));
1476 ret = ath10k_wmi_vdev_restart(ar, &arg);
1478 ret = ath10k_wmi_vdev_start(ar, &arg);
1481 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1486 ret = ath10k_vdev_setup_sync(ar);
1489 "failed to synchronize setup for vdev %i restart %d: %d\n",
1490 arg.vdev_id, restart, ret);
1494 ar->num_started_vdevs++;
1495 ath10k_recalc_radar_detection(ar);
1500 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1501 const struct cfg80211_chan_def *def)
1503 return ath10k_vdev_start_restart(arvif, def, false);
1506 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1507 const struct cfg80211_chan_def *def)
1509 return ath10k_vdev_start_restart(arvif, def, true);
1512 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1513 struct sk_buff *bcn)
1515 struct ath10k *ar = arvif->ar;
1516 struct ieee80211_mgmt *mgmt;
1520 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1523 mgmt = (void *)bcn->data;
1524 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1525 mgmt->u.beacon.variable,
1526 bcn->len - (mgmt->u.beacon.variable -
1531 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1533 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1534 arvif->vdev_id, ret);
1541 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1542 u8 oui_type, size_t ie_offset)
1549 if (WARN_ON(skb->len < ie_offset))
1552 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1553 skb->data + ie_offset,
1554 skb->len - ie_offset);
1559 end = skb->data + skb->len;
1562 if (WARN_ON(next > end))
1565 memmove(ie, next, end - next);
1566 skb_trim(skb, skb->len - len);
1571 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1573 struct ath10k *ar = arvif->ar;
1574 struct ieee80211_hw *hw = ar->hw;
1575 struct ieee80211_vif *vif = arvif->vif;
1576 struct ieee80211_mutable_offsets offs = {};
1577 struct sk_buff *bcn;
1580 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1583 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1584 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1587 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1589 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1593 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1595 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1600 /* P2P IE is inserted by firmware automatically (as configured above)
1601 * so remove it from the base beacon template to avoid duplicate P2P
1602 * IEs in beacon frames.
1604 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1605 offsetof(struct ieee80211_mgmt,
1606 u.beacon.variable));
1608 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1613 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1621 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1623 struct ath10k *ar = arvif->ar;
1624 struct ieee80211_hw *hw = ar->hw;
1625 struct ieee80211_vif *vif = arvif->vif;
1626 struct sk_buff *prb;
1629 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1632 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1635 /* For mesh, probe response and beacon share the same template */
1636 if (ieee80211_vif_is_mesh(vif))
1639 prb = ieee80211_proberesp_get(hw, vif);
1641 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1645 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1649 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1657 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1659 struct ath10k *ar = arvif->ar;
1660 struct cfg80211_chan_def def;
1663 /* When originally vdev is started during assign_vif_chanctx() some
1664 * information is missing, notably SSID. Firmware revisions with beacon
1665 * offloading require the SSID to be provided during vdev (re)start to
1666 * handle hidden SSID properly.
1668 * Vdev restart must be done after vdev has been both started and
1669 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1670 * deliver vdev restart response event causing timeouts during vdev
1671 * syncing in ath10k.
1673 * Note: The vdev down/up and template reinstallation could be skipped
1674 * since only wmi-tlv firmware are known to have beacon offload and
1675 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1676 * response delivery. It's probably more robust to keep it as is.
1678 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1681 if (WARN_ON(!arvif->is_started))
1684 if (WARN_ON(!arvif->is_up))
1687 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1690 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1692 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1693 arvif->vdev_id, ret);
1697 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1698 * firmware will crash upon vdev up.
1701 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1703 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1707 ret = ath10k_mac_setup_prb_tmpl(arvif);
1709 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1713 ret = ath10k_vdev_restart(arvif, &def);
1715 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1716 arvif->vdev_id, ret);
1720 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1723 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1724 arvif->vdev_id, ret);
1731 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1732 struct ieee80211_bss_conf *info)
1734 struct ath10k *ar = arvif->ar;
1737 lockdep_assert_held(&arvif->ar->conf_mutex);
1739 if (!info->enable_beacon) {
1740 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1742 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1743 arvif->vdev_id, ret);
1745 arvif->is_up = false;
1747 spin_lock_bh(&arvif->ar->data_lock);
1748 ath10k_mac_vif_beacon_free(arvif);
1749 spin_unlock_bh(&arvif->ar->data_lock);
1754 arvif->tx_seq_no = 0x1000;
1757 ether_addr_copy(arvif->bssid, info->bssid);
1759 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1762 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1763 arvif->vdev_id, ret);
1767 arvif->is_up = true;
1769 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1771 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1772 arvif->vdev_id, ret);
1776 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1779 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1780 struct ieee80211_bss_conf *info,
1781 const u8 self_peer[ETH_ALEN])
1783 struct ath10k *ar = arvif->ar;
1787 lockdep_assert_held(&arvif->ar->conf_mutex);
1789 if (!info->ibss_joined) {
1790 if (is_zero_ether_addr(arvif->bssid))
1793 eth_zero_addr(arvif->bssid);
1798 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1799 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1800 ATH10K_DEFAULT_ATIM);
1802 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1803 arvif->vdev_id, ret);
1806 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1808 struct ath10k *ar = arvif->ar;
1813 lockdep_assert_held(&arvif->ar->conf_mutex);
1815 if (arvif->u.sta.uapsd)
1816 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1818 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1820 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1821 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1823 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1824 value, arvif->vdev_id, ret);
1831 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1833 struct ath10k *ar = arvif->ar;
1838 lockdep_assert_held(&arvif->ar->conf_mutex);
1840 if (arvif->u.sta.uapsd)
1841 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1843 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1845 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1846 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1849 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1850 value, arvif->vdev_id, ret);
1857 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1859 struct ath10k_vif *arvif;
1862 lockdep_assert_held(&ar->conf_mutex);
1864 list_for_each_entry(arvif, &ar->arvifs, list)
1865 if (arvif->is_started)
1871 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1873 struct ath10k *ar = arvif->ar;
1874 struct ieee80211_vif *vif = arvif->vif;
1875 struct ieee80211_conf *conf = &ar->hw->conf;
1876 enum wmi_sta_powersave_param param;
1877 enum wmi_sta_ps_mode psmode;
1882 lockdep_assert_held(&arvif->ar->conf_mutex);
1884 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1887 enable_ps = arvif->ps;
1889 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1890 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1891 ar->running_fw->fw_file.fw_features)) {
1892 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1897 if (!arvif->is_started) {
1898 /* mac80211 can update vif powersave state while disconnected.
1899 * Firmware doesn't behave nicely and consumes more power than
1900 * necessary if PS is disabled on a non-started vdev. Hence
1901 * force-enable PS for non-running vdevs.
1903 psmode = WMI_STA_PS_MODE_ENABLED;
1904 } else if (enable_ps) {
1905 psmode = WMI_STA_PS_MODE_ENABLED;
1906 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1908 ps_timeout = conf->dynamic_ps_timeout;
1909 if (ps_timeout == 0) {
1910 /* Firmware doesn't like 0 */
1911 ps_timeout = ieee80211_tu_to_usec(
1912 vif->bss_conf.beacon_int) / 1000;
1915 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1918 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1919 arvif->vdev_id, ret);
1923 psmode = WMI_STA_PS_MODE_DISABLED;
1926 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1927 arvif->vdev_id, psmode ? "enable" : "disable");
1929 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1931 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1932 psmode, arvif->vdev_id, ret);
1939 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1941 struct ath10k *ar = arvif->ar;
1942 struct wmi_sta_keepalive_arg arg = {};
1945 lockdep_assert_held(&arvif->ar->conf_mutex);
1947 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1950 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1953 /* Some firmware revisions have a bug and ignore the `enabled` field.
1954 * Instead use the interval to disable the keepalive.
1956 arg.vdev_id = arvif->vdev_id;
1958 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1959 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1961 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1963 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1964 arvif->vdev_id, ret);
1971 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1973 struct ath10k *ar = arvif->ar;
1974 struct ieee80211_vif *vif = arvif->vif;
1977 lockdep_assert_held(&arvif->ar->conf_mutex);
1979 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1982 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1985 if (!vif->csa_active)
1991 if (!ieee80211_csa_is_complete(vif)) {
1992 ieee80211_csa_update_counter(vif);
1994 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1996 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1999 ret = ath10k_mac_setup_prb_tmpl(arvif);
2001 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
2004 ieee80211_csa_finish(vif);
2008 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2010 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2012 struct ath10k *ar = arvif->ar;
2014 mutex_lock(&ar->conf_mutex);
2015 ath10k_mac_vif_ap_csa_count_down(arvif);
2016 mutex_unlock(&ar->conf_mutex);
2019 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2020 struct ieee80211_vif *vif)
2022 struct sk_buff *skb = data;
2023 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2024 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2026 if (vif->type != NL80211_IFTYPE_STATION)
2029 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2032 cancel_delayed_work(&arvif->connection_loss_work);
2035 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2037 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2038 IEEE80211_IFACE_ITER_NORMAL,
2039 ath10k_mac_handle_beacon_iter,
2043 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2044 struct ieee80211_vif *vif)
2046 u32 *vdev_id = data;
2047 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2048 struct ath10k *ar = arvif->ar;
2049 struct ieee80211_hw *hw = ar->hw;
2051 if (arvif->vdev_id != *vdev_id)
2057 ieee80211_beacon_loss(vif);
2059 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2060 * (done by mac80211) succeeds but beacons do not resume then it
2061 * doesn't make sense to continue operation. Queue connection loss work
2062 * which can be cancelled when beacon is received.
2064 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2065 ATH10K_CONNECTION_LOSS_HZ);
2068 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2070 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2071 IEEE80211_IFACE_ITER_NORMAL,
2072 ath10k_mac_handle_beacon_miss_iter,
2076 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2078 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2079 connection_loss_work.work);
2080 struct ieee80211_vif *vif = arvif->vif;
2085 ieee80211_connection_loss(vif);
2088 /**********************/
2089 /* Station management */
2090 /**********************/
2092 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2093 struct ieee80211_vif *vif)
2095 /* Some firmware revisions have unstable STA powersave when listen
2096 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2097 * generate NullFunc frames properly even if buffered frames have been
2098 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2099 * buffered frames. Often pinging the device from AP would simply fail.
2101 * As a workaround set it to 1.
2103 if (vif->type == NL80211_IFTYPE_STATION)
2106 return ar->hw->conf.listen_interval;
2109 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2110 struct ieee80211_vif *vif,
2111 struct ieee80211_sta *sta,
2112 struct wmi_peer_assoc_complete_arg *arg)
2114 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2117 lockdep_assert_held(&ar->conf_mutex);
2119 if (vif->type == NL80211_IFTYPE_STATION)
2120 aid = vif->bss_conf.aid;
2124 ether_addr_copy(arg->addr, sta->addr);
2125 arg->vdev_id = arvif->vdev_id;
2126 arg->peer_aid = aid;
2127 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2128 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2129 arg->peer_num_spatial_streams = 1;
2130 arg->peer_caps = vif->bss_conf.assoc_capability;
2133 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2134 struct ieee80211_vif *vif,
2135 struct ieee80211_sta *sta,
2136 struct wmi_peer_assoc_complete_arg *arg)
2138 struct ieee80211_bss_conf *info = &vif->bss_conf;
2139 struct cfg80211_chan_def def;
2140 struct cfg80211_bss *bss;
2141 const u8 *rsnie = NULL;
2142 const u8 *wpaie = NULL;
2144 lockdep_assert_held(&ar->conf_mutex);
2146 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2149 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2150 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2152 const struct cfg80211_bss_ies *ies;
2155 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2157 ies = rcu_dereference(bss->ies);
2159 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2160 WLAN_OUI_TYPE_MICROSOFT_WPA,
2164 cfg80211_put_bss(ar->hw->wiphy, bss);
2167 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2168 if (rsnie || wpaie) {
2169 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2170 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2174 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2175 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2179 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2180 ar->running_fw->fw_file.fw_features)) {
2181 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2185 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2186 struct ieee80211_vif *vif,
2187 struct ieee80211_sta *sta,
2188 struct wmi_peer_assoc_complete_arg *arg)
2190 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2191 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2192 struct cfg80211_chan_def def;
2193 const struct ieee80211_supported_band *sband;
2194 const struct ieee80211_rate *rates;
2195 enum nl80211_band band;
2200 lockdep_assert_held(&ar->conf_mutex);
2202 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2205 band = def.chan->band;
2206 sband = ar->hw->wiphy->bands[band];
2207 ratemask = sta->supp_rates[band];
2208 ratemask &= arvif->bitrate_mask.control[band].legacy;
2209 rates = sband->bitrates;
2211 rateset->num_rates = 0;
2213 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2214 if (!(ratemask & 1))
2217 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2218 rateset->rates[rateset->num_rates] = rate;
2219 rateset->num_rates++;
2224 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2228 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2229 if (ht_mcs_mask[nss])
2236 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2240 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2241 if (vht_mcs_mask[nss])
2247 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2248 struct ieee80211_vif *vif,
2249 struct ieee80211_sta *sta,
2250 struct wmi_peer_assoc_complete_arg *arg)
2252 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2253 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2254 struct cfg80211_chan_def def;
2255 enum nl80211_band band;
2256 const u8 *ht_mcs_mask;
2257 const u16 *vht_mcs_mask;
2262 lockdep_assert_held(&ar->conf_mutex);
2264 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2267 if (!ht_cap->ht_supported)
2270 band = def.chan->band;
2271 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2272 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2274 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2275 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2278 arg->peer_flags |= ar->wmi.peer_flags->ht;
2279 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2280 ht_cap->ampdu_factor)) - 1;
2282 arg->peer_mpdu_density =
2283 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2285 arg->peer_ht_caps = ht_cap->cap;
2286 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2288 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2289 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2291 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2292 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2293 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2296 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2297 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2298 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2300 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2301 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2304 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2305 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2306 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2309 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2310 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2311 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2312 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2313 arg->peer_rate_caps |= stbc;
2314 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2317 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2318 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2319 else if (ht_cap->mcs.rx_mask[1])
2320 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2322 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2323 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2324 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2325 max_nss = (i / 8) + 1;
2326 arg->peer_ht_rates.rates[n++] = i;
2330 * This is a workaround for HT-enabled STAs which break the spec
2331 * and have no HT capabilities RX mask (no HT RX MCS map).
2333 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2334 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2336 * Firmware asserts if such situation occurs.
2339 arg->peer_ht_rates.num_rates = 8;
2340 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2341 arg->peer_ht_rates.rates[i] = i;
2343 arg->peer_ht_rates.num_rates = n;
2344 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2347 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2349 arg->peer_ht_rates.num_rates,
2350 arg->peer_num_spatial_streams);
2353 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2354 struct ath10k_vif *arvif,
2355 struct ieee80211_sta *sta)
2361 lockdep_assert_held(&ar->conf_mutex);
2363 if (sta->wme && sta->uapsd_queues) {
2364 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2365 sta->uapsd_queues, sta->max_sp);
2367 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2368 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2369 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2370 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2371 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2372 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2373 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2374 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2375 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2376 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2377 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2378 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2380 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2381 max_sp = sta->max_sp;
2383 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2385 WMI_AP_PS_PEER_PARAM_UAPSD,
2388 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2389 arvif->vdev_id, ret);
2393 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2395 WMI_AP_PS_PEER_PARAM_MAX_SP,
2398 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2399 arvif->vdev_id, ret);
2403 /* TODO setup this based on STA listen interval and
2404 * beacon interval. Currently we don't know
2405 * sta->listen_interval - mac80211 patch required.
2406 * Currently use 10 seconds
2408 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2409 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2412 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2413 arvif->vdev_id, ret);
2422 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2423 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2430 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2431 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2435 idx_limit = fls(mcs_map) - 1;
2439 switch (idx_limit) {
2440 case 0: /* fall through */
2441 case 1: /* fall through */
2442 case 2: /* fall through */
2443 case 3: /* fall through */
2444 case 4: /* fall through */
2445 case 5: /* fall through */
2446 case 6: /* fall through */
2448 /* see ath10k_mac_can_set_bitrate_mask() */
2452 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2455 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2458 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2461 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2465 tx_mcs_set &= ~(0x3 << (nss * 2));
2466 tx_mcs_set |= mcs << (nss * 2);
2472 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2473 struct ieee80211_vif *vif,
2474 struct ieee80211_sta *sta,
2475 struct wmi_peer_assoc_complete_arg *arg)
2477 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2478 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2479 struct cfg80211_chan_def def;
2480 enum nl80211_band band;
2481 const u16 *vht_mcs_mask;
2483 u8 max_nss, vht_mcs;
2486 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2489 if (!vht_cap->vht_supported)
2492 band = def.chan->band;
2493 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2495 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2498 arg->peer_flags |= ar->wmi.peer_flags->vht;
2500 if (def.chan->band == NL80211_BAND_2GHZ)
2501 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2503 arg->peer_vht_caps = vht_cap->cap;
2505 ampdu_factor = (vht_cap->cap &
2506 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2507 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2509 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2510 * zero in VHT IE. Using it would result in degraded throughput.
2511 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2512 * it if VHT max_mpdu is smaller.
2514 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2515 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2516 ampdu_factor)) - 1);
2518 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2519 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2521 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2522 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2524 /* Calculate peer NSS capability from VHT capabilities if STA
2527 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2528 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2531 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2535 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2536 arg->peer_vht_rates.rx_max_rate =
2537 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2538 arg->peer_vht_rates.rx_mcs_set =
2539 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2540 arg->peer_vht_rates.tx_max_rate =
2541 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2542 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2543 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2545 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2546 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2548 if (arg->peer_vht_rates.rx_max_rate &&
2549 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2550 switch (arg->peer_vht_rates.rx_max_rate) {
2552 /* Must be 2x2 at 160Mhz is all it can do. */
2553 arg->peer_bw_rxnss_override = 2;
2556 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2557 arg->peer_bw_rxnss_override = 1;
2563 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2564 struct ieee80211_vif *vif,
2565 struct ieee80211_sta *sta,
2566 struct wmi_peer_assoc_complete_arg *arg)
2568 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2570 switch (arvif->vdev_type) {
2571 case WMI_VDEV_TYPE_AP:
2573 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2575 if (sta->wme && sta->uapsd_queues) {
2576 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2577 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2580 case WMI_VDEV_TYPE_STA:
2582 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2584 case WMI_VDEV_TYPE_IBSS:
2586 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2592 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2593 sta->addr, !!(arg->peer_flags &
2594 arvif->ar->wmi.peer_flags->qos));
2597 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2599 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2600 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2603 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2604 struct ieee80211_sta *sta)
2606 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2607 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2608 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2609 return MODE_11AC_VHT160;
2610 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2611 return MODE_11AC_VHT80_80;
2613 /* not sure if this is a valid case? */
2614 return MODE_11AC_VHT160;
2618 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2619 return MODE_11AC_VHT80;
2621 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2622 return MODE_11AC_VHT40;
2624 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2625 return MODE_11AC_VHT20;
2627 return MODE_UNKNOWN;
2630 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2631 struct ieee80211_vif *vif,
2632 struct ieee80211_sta *sta,
2633 struct wmi_peer_assoc_complete_arg *arg)
2635 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2636 struct cfg80211_chan_def def;
2637 enum nl80211_band band;
2638 const u8 *ht_mcs_mask;
2639 const u16 *vht_mcs_mask;
2640 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2642 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2645 band = def.chan->band;
2646 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2647 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2650 case NL80211_BAND_2GHZ:
2651 if (sta->vht_cap.vht_supported &&
2652 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2653 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2654 phymode = MODE_11AC_VHT40;
2656 phymode = MODE_11AC_VHT20;
2657 } else if (sta->ht_cap.ht_supported &&
2658 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2659 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2660 phymode = MODE_11NG_HT40;
2662 phymode = MODE_11NG_HT20;
2663 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2670 case NL80211_BAND_5GHZ:
2674 if (sta->vht_cap.vht_supported &&
2675 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2676 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2677 } else if (sta->ht_cap.ht_supported &&
2678 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2679 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2680 phymode = MODE_11NA_HT40;
2682 phymode = MODE_11NA_HT20;
2692 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2693 sta->addr, ath10k_wmi_phymode_str(phymode));
2695 arg->peer_phymode = phymode;
2696 WARN_ON(phymode == MODE_UNKNOWN);
2699 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2700 struct ieee80211_vif *vif,
2701 struct ieee80211_sta *sta,
2702 struct wmi_peer_assoc_complete_arg *arg)
2704 lockdep_assert_held(&ar->conf_mutex);
2706 memset(arg, 0, sizeof(*arg));
2708 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2709 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2710 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2711 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2712 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2713 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2714 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2719 static const u32 ath10k_smps_map[] = {
2720 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2721 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2722 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2723 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2726 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2728 const struct ieee80211_sta_ht_cap *ht_cap)
2732 if (!ht_cap->ht_supported)
2735 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2736 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2738 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2741 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2742 WMI_PEER_SMPS_STATE,
2743 ath10k_smps_map[smps]);
2746 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2747 struct ieee80211_vif *vif,
2748 struct ieee80211_sta_vht_cap vht_cap)
2750 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2755 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2758 if (!(ar->vht_cap_info &
2759 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2760 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2761 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2762 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2765 param = ar->wmi.vdev_param->txbf;
2768 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2771 /* The following logic is correct. If a remote STA advertises support
2772 * for being a beamformer then we should enable us being a beamformee.
2775 if (ar->vht_cap_info &
2776 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2777 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2778 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2779 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2781 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2782 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2785 if (ar->vht_cap_info &
2786 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2787 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2788 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2789 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2791 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2792 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2795 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2796 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2798 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2799 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2801 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2803 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2811 /* can be called only in mac80211 callbacks due to `key_count` usage */
2812 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2813 struct ieee80211_vif *vif,
2814 struct ieee80211_bss_conf *bss_conf)
2816 struct ath10k *ar = hw->priv;
2817 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2818 struct ieee80211_sta_ht_cap ht_cap;
2819 struct ieee80211_sta_vht_cap vht_cap;
2820 struct wmi_peer_assoc_complete_arg peer_arg;
2821 struct ieee80211_sta *ap_sta;
2824 lockdep_assert_held(&ar->conf_mutex);
2826 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2827 arvif->vdev_id, arvif->bssid, arvif->aid);
2831 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2833 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2834 bss_conf->bssid, arvif->vdev_id);
2839 /* ap_sta must be accessed only within rcu section which must be left
2840 * before calling ath10k_setup_peer_smps() which might sleep.
2842 ht_cap = ap_sta->ht_cap;
2843 vht_cap = ap_sta->vht_cap;
2845 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2847 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2848 bss_conf->bssid, arvif->vdev_id, ret);
2855 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2857 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2858 bss_conf->bssid, arvif->vdev_id, ret);
2862 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2864 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2865 arvif->vdev_id, ret);
2869 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2871 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2872 arvif->vdev_id, bss_conf->bssid, ret);
2876 ath10k_dbg(ar, ATH10K_DBG_MAC,
2877 "mac vdev %d up (associated) bssid %pM aid %d\n",
2878 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2880 WARN_ON(arvif->is_up);
2882 arvif->aid = bss_conf->aid;
2883 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2885 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2887 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2888 arvif->vdev_id, ret);
2892 arvif->is_up = true;
2894 /* Workaround: Some firmware revisions (tested with qca6174
2895 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2896 * poked with peer param command.
2898 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2899 WMI_PEER_DUMMY_VAR, 1);
2901 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2902 arvif->bssid, arvif->vdev_id, ret);
2907 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2908 struct ieee80211_vif *vif)
2910 struct ath10k *ar = hw->priv;
2911 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2912 struct ieee80211_sta_vht_cap vht_cap = {};
2915 lockdep_assert_held(&ar->conf_mutex);
2917 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2918 arvif->vdev_id, arvif->bssid);
2920 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2922 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2923 arvif->vdev_id, ret);
2925 arvif->def_wep_key_idx = -1;
2927 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2929 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2930 arvif->vdev_id, ret);
2934 arvif->is_up = false;
2936 cancel_delayed_work_sync(&arvif->connection_loss_work);
2939 static int ath10k_station_assoc(struct ath10k *ar,
2940 struct ieee80211_vif *vif,
2941 struct ieee80211_sta *sta,
2944 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2945 struct wmi_peer_assoc_complete_arg peer_arg;
2948 lockdep_assert_held(&ar->conf_mutex);
2950 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2952 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2953 sta->addr, arvif->vdev_id, ret);
2957 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2959 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2960 sta->addr, arvif->vdev_id, ret);
2964 /* Re-assoc is run only to update supported rates for given station. It
2965 * doesn't make much sense to reconfigure the peer completely.
2968 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2971 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2972 arvif->vdev_id, ret);
2976 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2978 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2979 sta->addr, arvif->vdev_id, ret);
2984 arvif->num_legacy_stations++;
2985 ret = ath10k_recalc_rtscts_prot(arvif);
2987 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2988 arvif->vdev_id, ret);
2993 /* Plumb cached keys only for static WEP */
2994 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
2995 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2997 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2998 arvif->vdev_id, ret);
3007 static int ath10k_station_disassoc(struct ath10k *ar,
3008 struct ieee80211_vif *vif,
3009 struct ieee80211_sta *sta)
3011 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3014 lockdep_assert_held(&ar->conf_mutex);
3017 arvif->num_legacy_stations--;
3018 ret = ath10k_recalc_rtscts_prot(arvif);
3020 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3021 arvif->vdev_id, ret);
3026 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3028 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3029 arvif->vdev_id, ret);
3040 static int ath10k_update_channel_list(struct ath10k *ar)
3042 struct ieee80211_hw *hw = ar->hw;
3043 struct ieee80211_supported_band **bands;
3044 enum nl80211_band band;
3045 struct ieee80211_channel *channel;
3046 struct wmi_scan_chan_list_arg arg = {0};
3047 struct wmi_channel_arg *ch;
3053 lockdep_assert_held(&ar->conf_mutex);
3055 bands = hw->wiphy->bands;
3056 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3060 for (i = 0; i < bands[band]->n_channels; i++) {
3061 if (bands[band]->channels[i].flags &
3062 IEEE80211_CHAN_DISABLED)
3069 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3070 arg.channels = kzalloc(len, GFP_KERNEL);
3075 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3079 for (i = 0; i < bands[band]->n_channels; i++) {
3080 channel = &bands[band]->channels[i];
3082 if (channel->flags & IEEE80211_CHAN_DISABLED)
3085 ch->allow_ht = true;
3087 /* FIXME: when should we really allow VHT? */
3088 ch->allow_vht = true;
3091 !(channel->flags & IEEE80211_CHAN_NO_IR);
3094 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3097 !!(channel->flags & IEEE80211_CHAN_RADAR);
3099 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3100 ch->passive = passive;
3102 /* the firmware is ignoring the "radar" flag of the
3103 * channel and is scanning actively using Probe Requests
3104 * on "Radar detection"/DFS channels which are not
3105 * marked as "available"
3107 ch->passive |= ch->chan_radar;
3109 ch->freq = channel->center_freq;
3110 ch->band_center_freq1 = channel->center_freq;
3112 ch->max_power = channel->max_power * 2;
3113 ch->max_reg_power = channel->max_reg_power * 2;
3114 ch->max_antenna_gain = channel->max_antenna_gain;
3115 ch->reg_class_id = 0; /* FIXME */
3117 /* FIXME: why use only legacy modes, why not any
3118 * HT/VHT modes? Would that even make any
3121 if (channel->band == NL80211_BAND_2GHZ)
3122 ch->mode = MODE_11G;
3124 ch->mode = MODE_11A;
3126 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3129 ath10k_dbg(ar, ATH10K_DBG_WMI,
3130 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3131 ch - arg.channels, arg.n_channels,
3132 ch->freq, ch->max_power, ch->max_reg_power,
3133 ch->max_antenna_gain, ch->mode);
3139 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3140 kfree(arg.channels);
3145 static enum wmi_dfs_region
3146 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3148 switch (dfs_region) {
3149 case NL80211_DFS_UNSET:
3150 return WMI_UNINIT_DFS_DOMAIN;
3151 case NL80211_DFS_FCC:
3152 return WMI_FCC_DFS_DOMAIN;
3153 case NL80211_DFS_ETSI:
3154 return WMI_ETSI_DFS_DOMAIN;
3155 case NL80211_DFS_JP:
3156 return WMI_MKK4_DFS_DOMAIN;
3158 return WMI_UNINIT_DFS_DOMAIN;
3161 static void ath10k_regd_update(struct ath10k *ar)
3163 struct reg_dmn_pair_mapping *regpair;
3165 enum wmi_dfs_region wmi_dfs_reg;
3166 enum nl80211_dfs_regions nl_dfs_reg;
3168 lockdep_assert_held(&ar->conf_mutex);
3170 ret = ath10k_update_channel_list(ar);
3172 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3174 regpair = ar->ath_common.regulatory.regpair;
3176 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3177 nl_dfs_reg = ar->dfs_detector->region;
3178 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3180 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3183 /* Target allows setting up per-band regdomain but ath_common provides
3184 * a combined one only
3186 ret = ath10k_wmi_pdev_set_regdomain(ar,
3187 regpair->reg_domain,
3188 regpair->reg_domain, /* 2ghz */
3189 regpair->reg_domain, /* 5ghz */
3190 regpair->reg_2ghz_ctl,
3191 regpair->reg_5ghz_ctl,
3194 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3197 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3198 struct ieee80211_supported_band *band)
3202 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3203 for (i = 0; i < band->n_channels; i++) {
3204 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3205 band->channels[i].center_freq > ar->high_5ghz_chan)
3206 band->channels[i].flags |=
3207 IEEE80211_CHAN_DISABLED;
3212 static void ath10k_reg_notifier(struct wiphy *wiphy,
3213 struct regulatory_request *request)
3215 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3216 struct ath10k *ar = hw->priv;
3219 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3221 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3222 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3223 request->dfs_region);
3224 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3225 request->dfs_region);
3227 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3228 request->dfs_region);
3231 mutex_lock(&ar->conf_mutex);
3232 if (ar->state == ATH10K_STATE_ON)
3233 ath10k_regd_update(ar);
3234 mutex_unlock(&ar->conf_mutex);
3236 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3237 ath10k_mac_update_channel_list(ar,
3238 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3241 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3243 spin_lock_bh(&ar->data_lock);
3244 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3245 spin_unlock_bh(&ar->data_lock);
3247 cancel_work_sync(&ar->radar_confirmation_work);
3254 enum ath10k_mac_tx_path {
3256 ATH10K_MAC_TX_HTT_MGMT,
3257 ATH10K_MAC_TX_WMI_MGMT,
3258 ATH10K_MAC_TX_UNKNOWN,
3261 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3263 lockdep_assert_held(&ar->htt.tx_lock);
3265 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3266 ar->tx_paused |= BIT(reason);
3267 ieee80211_stop_queues(ar->hw);
3270 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3271 struct ieee80211_vif *vif)
3273 struct ath10k *ar = data;
3274 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3276 if (arvif->tx_paused)
3279 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3282 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3284 lockdep_assert_held(&ar->htt.tx_lock);
3286 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3287 ar->tx_paused &= ~BIT(reason);
3292 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3293 IEEE80211_IFACE_ITER_RESUME_ALL,
3294 ath10k_mac_tx_unlock_iter,
3297 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3300 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3302 struct ath10k *ar = arvif->ar;
3304 lockdep_assert_held(&ar->htt.tx_lock);
3306 WARN_ON(reason >= BITS_PER_LONG);
3307 arvif->tx_paused |= BIT(reason);
3308 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3311 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3313 struct ath10k *ar = arvif->ar;
3315 lockdep_assert_held(&ar->htt.tx_lock);
3317 WARN_ON(reason >= BITS_PER_LONG);
3318 arvif->tx_paused &= ~BIT(reason);
3323 if (arvif->tx_paused)
3326 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3329 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3330 enum wmi_tlv_tx_pause_id pause_id,
3331 enum wmi_tlv_tx_pause_action action)
3333 struct ath10k *ar = arvif->ar;
3335 lockdep_assert_held(&ar->htt.tx_lock);
3338 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3339 ath10k_mac_vif_tx_lock(arvif, pause_id);
3341 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3342 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3345 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3346 "received unknown tx pause action %d on vdev %i, ignoring\n",
3347 action, arvif->vdev_id);
3352 struct ath10k_mac_tx_pause {
3354 enum wmi_tlv_tx_pause_id pause_id;
3355 enum wmi_tlv_tx_pause_action action;
3358 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3359 struct ieee80211_vif *vif)
3361 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3362 struct ath10k_mac_tx_pause *arg = data;
3364 if (arvif->vdev_id != arg->vdev_id)
3367 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3370 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3371 enum wmi_tlv_tx_pause_id pause_id,
3372 enum wmi_tlv_tx_pause_action action)
3374 struct ath10k_mac_tx_pause arg = {
3376 .pause_id = pause_id,
3380 spin_lock_bh(&ar->htt.tx_lock);
3381 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3382 IEEE80211_IFACE_ITER_RESUME_ALL,
3383 ath10k_mac_handle_tx_pause_iter,
3385 spin_unlock_bh(&ar->htt.tx_lock);
3388 static enum ath10k_hw_txrx_mode
3389 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3390 struct ieee80211_vif *vif,
3391 struct ieee80211_sta *sta,
3392 struct sk_buff *skb)
3394 const struct ieee80211_hdr *hdr = (void *)skb->data;
3395 __le16 fc = hdr->frame_control;
3397 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3398 return ATH10K_HW_TXRX_RAW;
3400 if (ieee80211_is_mgmt(fc))
3401 return ATH10K_HW_TXRX_MGMT;
3405 * NullFunc frames are mostly used to ping if a client or AP are still
3406 * reachable and responsive. This implies tx status reports must be
3407 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3408 * come to a conclusion that the other end disappeared and tear down
3409 * BSS connection or it can never disconnect from BSS/client (which is
3412 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3413 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3414 * which seems to deliver correct tx reports for NullFunc frames. The
3415 * downside of using it is it ignores client powersave state so it can
3416 * end up disconnecting sleeping clients in AP mode. It should fix STA
3417 * mode though because AP don't sleep.
3419 if (ar->htt.target_version_major < 3 &&
3420 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3421 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3422 ar->running_fw->fw_file.fw_features))
3423 return ATH10K_HW_TXRX_MGMT;
3427 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3428 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3429 * to work with Ethernet txmode so use it.
3431 * FIXME: Check if raw mode works with TDLS.
3433 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3434 return ATH10K_HW_TXRX_ETHERNET;
3436 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3437 return ATH10K_HW_TXRX_RAW;
3439 return ATH10K_HW_TXRX_NATIVE_WIFI;
3442 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3443 struct sk_buff *skb)
3445 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3446 const struct ieee80211_hdr *hdr = (void *)skb->data;
3447 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3448 IEEE80211_TX_CTL_INJECTED;
3450 if (!ieee80211_has_protected(hdr->frame_control))
3453 if ((info->flags & mask) == mask)
3457 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3462 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3463 * Control in the header.
3465 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3467 struct ieee80211_hdr *hdr = (void *)skb->data;
3468 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3471 if (!ieee80211_is_data_qos(hdr->frame_control))
3474 qos_ctl = ieee80211_get_qos_ctl(hdr);
3475 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3476 skb->data, (void *)qos_ctl - (void *)skb->data);
3477 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3479 /* Some firmware revisions don't handle sending QoS NullFunc well.
3480 * These frames are mainly used for CQM purposes so it doesn't really
3481 * matter whether QoS NullFunc or NullFunc are sent.
3483 hdr = (void *)skb->data;
3484 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3485 cb->flags &= ~ATH10K_SKB_F_QOS;
3487 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3490 static void ath10k_tx_h_8023(struct sk_buff *skb)
3492 struct ieee80211_hdr *hdr;
3493 struct rfc1042_hdr *rfc1042;
3500 hdr = (void *)skb->data;
3501 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3502 rfc1042 = (void *)skb->data + hdrlen;
3504 ether_addr_copy(da, ieee80211_get_DA(hdr));
3505 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3506 type = rfc1042->snap_type;
3508 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3509 skb_push(skb, sizeof(*eth));
3511 eth = (void *)skb->data;
3512 ether_addr_copy(eth->h_dest, da);
3513 ether_addr_copy(eth->h_source, sa);
3514 eth->h_proto = type;
3517 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3518 struct ieee80211_vif *vif,
3519 struct sk_buff *skb)
3521 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3522 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3524 /* This is case only for P2P_GO */
3525 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3528 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3529 spin_lock_bh(&ar->data_lock);
3530 if (arvif->u.ap.noa_data)
3531 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3533 skb_put_data(skb, arvif->u.ap.noa_data,
3534 arvif->u.ap.noa_len);
3535 spin_unlock_bh(&ar->data_lock);
3539 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3540 struct ieee80211_vif *vif,
3541 struct ieee80211_txq *txq,
3542 struct sk_buff *skb)
3544 struct ieee80211_hdr *hdr = (void *)skb->data;
3545 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3548 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3549 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3551 if (ieee80211_is_mgmt(hdr->frame_control))
3552 cb->flags |= ATH10K_SKB_F_MGMT;
3554 if (ieee80211_is_data_qos(hdr->frame_control))
3555 cb->flags |= ATH10K_SKB_F_QOS;
3561 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3563 /* FIXME: Not really sure since when the behaviour changed. At some
3564 * point new firmware stopped requiring creation of peer entries for
3565 * offchannel tx (and actually creating them causes issues with wmi-htc
3566 * tx credit replenishment and reliability). Assuming it's at least 3.4
3567 * because that's when the `freq` was introduced to TX_FRM HTT command.
3569 return (ar->htt.target_version_major >= 3 &&
3570 ar->htt.target_version_minor >= 4 &&
3571 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3574 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3576 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3578 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3579 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3583 skb_queue_tail(q, skb);
3584 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3589 static enum ath10k_mac_tx_path
3590 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3591 struct sk_buff *skb,
3592 enum ath10k_hw_txrx_mode txmode)
3595 case ATH10K_HW_TXRX_RAW:
3596 case ATH10K_HW_TXRX_NATIVE_WIFI:
3597 case ATH10K_HW_TXRX_ETHERNET:
3598 return ATH10K_MAC_TX_HTT;
3599 case ATH10K_HW_TXRX_MGMT:
3600 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3601 ar->running_fw->fw_file.fw_features) ||
3602 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3604 return ATH10K_MAC_TX_WMI_MGMT;
3605 else if (ar->htt.target_version_major >= 3)
3606 return ATH10K_MAC_TX_HTT;
3608 return ATH10K_MAC_TX_HTT_MGMT;
3611 return ATH10K_MAC_TX_UNKNOWN;
3614 static int ath10k_mac_tx_submit(struct ath10k *ar,
3615 enum ath10k_hw_txrx_mode txmode,
3616 enum ath10k_mac_tx_path txpath,
3617 struct sk_buff *skb)
3619 struct ath10k_htt *htt = &ar->htt;
3623 case ATH10K_MAC_TX_HTT:
3624 ret = ath10k_htt_tx(htt, txmode, skb);
3626 case ATH10K_MAC_TX_HTT_MGMT:
3627 ret = ath10k_htt_mgmt_tx(htt, skb);
3629 case ATH10K_MAC_TX_WMI_MGMT:
3630 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3632 case ATH10K_MAC_TX_UNKNOWN:
3639 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3641 ieee80211_free_txskb(ar->hw, skb);
3647 /* This function consumes the sk_buff regardless of return value as far as
3648 * caller is concerned so no freeing is necessary afterwards.
3650 static int ath10k_mac_tx(struct ath10k *ar,
3651 struct ieee80211_vif *vif,
3652 enum ath10k_hw_txrx_mode txmode,
3653 enum ath10k_mac_tx_path txpath,
3654 struct sk_buff *skb, bool noque_offchan)
3656 struct ieee80211_hw *hw = ar->hw;
3657 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3660 /* We should disable CCK RATE due to P2P */
3661 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3662 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3665 case ATH10K_HW_TXRX_MGMT:
3666 case ATH10K_HW_TXRX_NATIVE_WIFI:
3667 ath10k_tx_h_nwifi(hw, skb);
3668 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3669 ath10k_tx_h_seq_no(vif, skb);
3671 case ATH10K_HW_TXRX_ETHERNET:
3672 ath10k_tx_h_8023(skb);
3674 case ATH10K_HW_TXRX_RAW:
3675 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3677 ieee80211_free_txskb(hw, skb);
3682 if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3683 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3684 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n",
3687 skb_queue_tail(&ar->offchan_tx_queue, skb);
3688 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3693 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3695 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3702 void ath10k_offchan_tx_purge(struct ath10k *ar)
3704 struct sk_buff *skb;
3707 skb = skb_dequeue(&ar->offchan_tx_queue);
3711 ieee80211_free_txskb(ar->hw, skb);
3715 void ath10k_offchan_tx_work(struct work_struct *work)
3717 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3718 struct ath10k_peer *peer;
3719 struct ath10k_vif *arvif;
3720 enum ath10k_hw_txrx_mode txmode;
3721 enum ath10k_mac_tx_path txpath;
3722 struct ieee80211_hdr *hdr;
3723 struct ieee80211_vif *vif;
3724 struct ieee80211_sta *sta;
3725 struct sk_buff *skb;
3726 const u8 *peer_addr;
3729 unsigned long time_left;
3730 bool tmp_peer_created = false;
3732 /* FW requirement: We must create a peer before FW will send out
3733 * an offchannel frame. Otherwise the frame will be stuck and
3734 * never transmitted. We delete the peer upon tx completion.
3735 * It is unlikely that a peer for offchannel tx will already be
3736 * present. However it may be in some rare cases so account for that.
3737 * Otherwise we might remove a legitimate peer and break stuff.
3741 skb = skb_dequeue(&ar->offchan_tx_queue);
3745 mutex_lock(&ar->conf_mutex);
3747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n",
3750 hdr = (struct ieee80211_hdr *)skb->data;
3751 peer_addr = ieee80211_get_DA(hdr);
3753 spin_lock_bh(&ar->data_lock);
3754 vdev_id = ar->scan.vdev_id;
3755 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3756 spin_unlock_bh(&ar->data_lock);
3759 /* FIXME: should this use ath10k_warn()? */
3760 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3761 peer_addr, vdev_id);
3764 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3766 WMI_PEER_TYPE_DEFAULT);
3768 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3769 peer_addr, vdev_id, ret);
3770 tmp_peer_created = (ret == 0);
3773 spin_lock_bh(&ar->data_lock);
3774 reinit_completion(&ar->offchan_tx_completed);
3775 ar->offchan_tx_skb = skb;
3776 spin_unlock_bh(&ar->data_lock);
3778 /* It's safe to access vif and sta - conf_mutex guarantees that
3779 * sta_state() and remove_interface() are locked exclusively
3780 * out wrt to this offchannel worker.
3782 arvif = ath10k_get_arvif(ar, vdev_id);
3785 sta = ieee80211_find_sta(vif, peer_addr);
3791 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3792 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3794 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true);
3796 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3802 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3804 ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n",
3807 if (!peer && tmp_peer_created) {
3808 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3810 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3811 peer_addr, vdev_id, ret);
3814 mutex_unlock(&ar->conf_mutex);
3818 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3820 struct sk_buff *skb;
3823 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3827 ieee80211_free_txskb(ar->hw, skb);
3831 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3833 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3834 struct sk_buff *skb;
3839 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3843 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
3844 ar->running_fw->fw_file.fw_features)) {
3845 paddr = dma_map_single(ar->dev, skb->data,
3846 skb->len, DMA_TO_DEVICE);
3847 if (dma_mapping_error(ar->dev, paddr)) {
3848 ieee80211_free_txskb(ar->hw, skb);
3851 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3853 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3855 /* remove this msdu from idr tracking */
3856 ath10k_wmi_cleanup_mgmt_tx_send(ar, skb);
3858 dma_unmap_single(ar->dev, paddr, skb->len,
3860 ieee80211_free_txskb(ar->hw, skb);
3863 ret = ath10k_wmi_mgmt_tx(ar, skb);
3865 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3867 ieee80211_free_txskb(ar->hw, skb);
3873 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3875 struct ath10k_txq *artxq;
3880 artxq = (void *)txq->drv_priv;
3881 INIT_LIST_HEAD(&artxq->list);
3884 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3886 struct ath10k_txq *artxq;
3887 struct ath10k_skb_cb *cb;
3888 struct sk_buff *msdu;
3894 artxq = (void *)txq->drv_priv;
3895 spin_lock_bh(&ar->txqs_lock);
3896 if (!list_empty(&artxq->list))
3897 list_del_init(&artxq->list);
3898 spin_unlock_bh(&ar->txqs_lock);
3900 spin_lock_bh(&ar->htt.tx_lock);
3901 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3902 cb = ATH10K_SKB_CB(msdu);
3906 spin_unlock_bh(&ar->htt.tx_lock);
3909 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3913 struct ath10k_peer *peer;
3915 lockdep_assert_held(&ar->data_lock);
3917 peer = ar->peer_map[peer_id];
3925 return peer->sta->txq[tid];
3927 return peer->vif->txq;
3932 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3933 struct ieee80211_txq *txq)
3935 struct ath10k *ar = hw->priv;
3936 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3938 /* No need to get locks */
3940 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3943 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3946 if (artxq->num_fw_queued < artxq->num_push_allowed)
3952 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3953 struct ieee80211_txq *txq)
3955 struct ath10k *ar = hw->priv;
3956 struct ath10k_htt *htt = &ar->htt;
3957 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3958 struct ieee80211_vif *vif = txq->vif;
3959 struct ieee80211_sta *sta = txq->sta;
3960 enum ath10k_hw_txrx_mode txmode;
3961 enum ath10k_mac_tx_path txpath;
3962 struct sk_buff *skb;
3963 struct ieee80211_hdr *hdr;
3965 bool is_mgmt, is_presp;
3968 spin_lock_bh(&ar->htt.tx_lock);
3969 ret = ath10k_htt_tx_inc_pending(htt);
3970 spin_unlock_bh(&ar->htt.tx_lock);
3975 skb = ieee80211_tx_dequeue(hw, txq);
3977 spin_lock_bh(&ar->htt.tx_lock);
3978 ath10k_htt_tx_dec_pending(htt);
3979 spin_unlock_bh(&ar->htt.tx_lock);
3984 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3987 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3988 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3989 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3992 hdr = (struct ieee80211_hdr *)skb->data;
3993 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3995 spin_lock_bh(&ar->htt.tx_lock);
3996 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3999 ath10k_htt_tx_dec_pending(htt);
4000 spin_unlock_bh(&ar->htt.tx_lock);
4003 spin_unlock_bh(&ar->htt.tx_lock);
4006 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4007 if (unlikely(ret)) {
4008 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4010 spin_lock_bh(&ar->htt.tx_lock);
4011 ath10k_htt_tx_dec_pending(htt);
4013 ath10k_htt_tx_mgmt_dec_pending(htt);
4014 spin_unlock_bh(&ar->htt.tx_lock);
4019 spin_lock_bh(&ar->htt.tx_lock);
4020 artxq->num_fw_queued++;
4021 spin_unlock_bh(&ar->htt.tx_lock);
4026 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4028 struct ieee80211_hw *hw = ar->hw;
4029 struct ieee80211_txq *txq;
4030 struct ath10k_txq *artxq;
4031 struct ath10k_txq *last;
4035 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4038 spin_lock_bh(&ar->txqs_lock);
4041 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
4042 while (!list_empty(&ar->txqs)) {
4043 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4044 txq = container_of((void *)artxq, struct ieee80211_txq,
4047 /* Prevent aggressive sta/tid taking over tx queue */
4048 max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE;
4050 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
4051 ret = ath10k_mac_tx_push_txq(hw, txq);
4056 list_del_init(&artxq->list);
4058 list_add_tail(&artxq->list, &ar->txqs);
4060 ath10k_htt_tx_txq_update(hw, txq);
4062 if (artxq == last || (ret < 0 && ret != -ENOENT))
4067 spin_unlock_bh(&ar->txqs_lock);
4069 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4075 void __ath10k_scan_finish(struct ath10k *ar)
4077 lockdep_assert_held(&ar->data_lock);
4079 switch (ar->scan.state) {
4080 case ATH10K_SCAN_IDLE:
4082 case ATH10K_SCAN_RUNNING:
4083 case ATH10K_SCAN_ABORTING:
4084 if (!ar->scan.is_roc) {
4085 struct cfg80211_scan_info info = {
4086 .aborted = (ar->scan.state ==
4087 ATH10K_SCAN_ABORTING),
4090 ieee80211_scan_completed(ar->hw, &info);
4091 } else if (ar->scan.roc_notify) {
4092 ieee80211_remain_on_channel_expired(ar->hw);
4095 case ATH10K_SCAN_STARTING:
4096 ar->scan.state = ATH10K_SCAN_IDLE;
4097 ar->scan_channel = NULL;
4098 ar->scan.roc_freq = 0;
4099 ath10k_offchan_tx_purge(ar);
4100 cancel_delayed_work(&ar->scan.timeout);
4101 complete(&ar->scan.completed);
4106 void ath10k_scan_finish(struct ath10k *ar)
4108 spin_lock_bh(&ar->data_lock);
4109 __ath10k_scan_finish(ar);
4110 spin_unlock_bh(&ar->data_lock);
4113 static int ath10k_scan_stop(struct ath10k *ar)
4115 struct wmi_stop_scan_arg arg = {
4116 .req_id = 1, /* FIXME */
4117 .req_type = WMI_SCAN_STOP_ONE,
4118 .u.scan_id = ATH10K_SCAN_ID,
4122 lockdep_assert_held(&ar->conf_mutex);
4124 ret = ath10k_wmi_stop_scan(ar, &arg);
4126 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4130 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4132 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4134 } else if (ret > 0) {
4139 /* Scan state should be updated upon scan completion but in case
4140 * firmware fails to deliver the event (for whatever reason) it is
4141 * desired to clean up scan state anyway. Firmware may have just
4142 * dropped the scan completion event delivery due to transport pipe
4143 * being overflown with data and/or it can recover on its own before
4144 * next scan request is submitted.
4146 spin_lock_bh(&ar->data_lock);
4147 if (ar->scan.state != ATH10K_SCAN_IDLE)
4148 __ath10k_scan_finish(ar);
4149 spin_unlock_bh(&ar->data_lock);
4154 static void ath10k_scan_abort(struct ath10k *ar)
4158 lockdep_assert_held(&ar->conf_mutex);
4160 spin_lock_bh(&ar->data_lock);
4162 switch (ar->scan.state) {
4163 case ATH10K_SCAN_IDLE:
4164 /* This can happen if timeout worker kicked in and called
4165 * abortion while scan completion was being processed.
4168 case ATH10K_SCAN_STARTING:
4169 case ATH10K_SCAN_ABORTING:
4170 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4171 ath10k_scan_state_str(ar->scan.state),
4174 case ATH10K_SCAN_RUNNING:
4175 ar->scan.state = ATH10K_SCAN_ABORTING;
4176 spin_unlock_bh(&ar->data_lock);
4178 ret = ath10k_scan_stop(ar);
4180 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4182 spin_lock_bh(&ar->data_lock);
4186 spin_unlock_bh(&ar->data_lock);
4189 void ath10k_scan_timeout_work(struct work_struct *work)
4191 struct ath10k *ar = container_of(work, struct ath10k,
4194 mutex_lock(&ar->conf_mutex);
4195 ath10k_scan_abort(ar);
4196 mutex_unlock(&ar->conf_mutex);
4199 static int ath10k_start_scan(struct ath10k *ar,
4200 const struct wmi_start_scan_arg *arg)
4204 lockdep_assert_held(&ar->conf_mutex);
4206 ret = ath10k_wmi_start_scan(ar, arg);
4210 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4212 ret = ath10k_scan_stop(ar);
4214 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4219 /* If we failed to start the scan, return error code at
4220 * this point. This is probably due to some issue in the
4221 * firmware, but no need to wedge the driver due to that...
4223 spin_lock_bh(&ar->data_lock);
4224 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4225 spin_unlock_bh(&ar->data_lock);
4228 spin_unlock_bh(&ar->data_lock);
4233 /**********************/
4234 /* mac80211 callbacks */
4235 /**********************/
4237 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4238 struct ieee80211_tx_control *control,
4239 struct sk_buff *skb)
4241 struct ath10k *ar = hw->priv;
4242 struct ath10k_htt *htt = &ar->htt;
4243 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4244 struct ieee80211_vif *vif = info->control.vif;
4245 struct ieee80211_sta *sta = control->sta;
4246 struct ieee80211_txq *txq = NULL;
4247 struct ieee80211_hdr *hdr = (void *)skb->data;
4248 enum ath10k_hw_txrx_mode txmode;
4249 enum ath10k_mac_tx_path txpath;
4255 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4257 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4258 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4259 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4260 txpath == ATH10K_MAC_TX_HTT_MGMT);
4261 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4264 spin_lock_bh(&ar->htt.tx_lock);
4265 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4267 ret = ath10k_htt_tx_inc_pending(htt);
4269 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4271 spin_unlock_bh(&ar->htt.tx_lock);
4272 ieee80211_free_txskb(ar->hw, skb);
4276 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4278 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4280 ath10k_htt_tx_dec_pending(htt);
4281 spin_unlock_bh(&ar->htt.tx_lock);
4282 ieee80211_free_txskb(ar->hw, skb);
4285 spin_unlock_bh(&ar->htt.tx_lock);
4288 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4290 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4292 spin_lock_bh(&ar->htt.tx_lock);
4293 ath10k_htt_tx_dec_pending(htt);
4295 ath10k_htt_tx_mgmt_dec_pending(htt);
4296 spin_unlock_bh(&ar->htt.tx_lock);
4302 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4303 struct ieee80211_txq *txq)
4305 struct ath10k *ar = hw->priv;
4306 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4307 struct ieee80211_txq *f_txq;
4308 struct ath10k_txq *f_artxq;
4310 int max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE;
4312 spin_lock_bh(&ar->txqs_lock);
4313 if (list_empty(&artxq->list))
4314 list_add_tail(&artxq->list, &ar->txqs);
4316 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4317 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4318 list_del_init(&f_artxq->list);
4320 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4321 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4326 list_add_tail(&f_artxq->list, &ar->txqs);
4327 spin_unlock_bh(&ar->txqs_lock);
4329 ath10k_htt_tx_txq_update(hw, f_txq);
4330 ath10k_htt_tx_txq_update(hw, txq);
4333 /* Must not be called with conf_mutex held as workers can use that also. */
4334 void ath10k_drain_tx(struct ath10k *ar)
4336 /* make sure rcu-protected mac80211 tx path itself is drained */
4339 ath10k_offchan_tx_purge(ar);
4340 ath10k_mgmt_over_wmi_tx_purge(ar);
4342 cancel_work_sync(&ar->offchan_tx_work);
4343 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4346 void ath10k_halt(struct ath10k *ar)
4348 struct ath10k_vif *arvif;
4350 lockdep_assert_held(&ar->conf_mutex);
4352 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4353 ar->filter_flags = 0;
4354 ar->monitor = false;
4355 ar->monitor_arvif = NULL;
4357 if (ar->monitor_started)
4358 ath10k_monitor_stop(ar);
4360 ar->monitor_started = false;
4363 ath10k_scan_finish(ar);
4364 ath10k_peer_cleanup_all(ar);
4365 ath10k_stop_radar_confirmation(ar);
4366 ath10k_core_stop(ar);
4367 ath10k_hif_power_down(ar);
4369 spin_lock_bh(&ar->data_lock);
4370 list_for_each_entry(arvif, &ar->arvifs, list)
4371 ath10k_mac_vif_beacon_cleanup(arvif);
4372 spin_unlock_bh(&ar->data_lock);
4375 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4377 struct ath10k *ar = hw->priv;
4379 mutex_lock(&ar->conf_mutex);
4381 *tx_ant = ar->cfg_tx_chainmask;
4382 *rx_ant = ar->cfg_rx_chainmask;
4384 mutex_unlock(&ar->conf_mutex);
4389 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4391 /* It is not clear that allowing gaps in chainmask
4392 * is helpful. Probably it will not do what user
4393 * is hoping for, so warn in that case.
4395 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4398 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4402 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4404 int nsts = ar->vht_cap_info;
4406 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4407 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4409 /* If firmware does not deliver to host number of space-time
4410 * streams supported, assume it support up to 4 BF STS and return
4411 * the value for VHT CAP: nsts-1)
4419 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4421 int sound_dim = ar->vht_cap_info;
4423 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4424 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4426 /* If the sounding dimension is not advertised by the firmware,
4427 * let's use a default value of 1
4435 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4437 struct ieee80211_sta_vht_cap vht_cap = {0};
4438 struct ath10k_hw_params *hw = &ar->hw_params;
4443 vht_cap.vht_supported = 1;
4444 vht_cap.cap = ar->vht_cap_info;
4446 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4447 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4448 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4449 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4450 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4455 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4456 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4457 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4458 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4459 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4464 /* Currently the firmware seems to be buggy, don't enable 80+80
4465 * mode until that's resolved.
4467 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4468 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4469 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4472 for (i = 0; i < 8; i++) {
4473 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4474 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4476 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4479 if (ar->cfg_tx_chainmask <= 1)
4480 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4482 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4483 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4485 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4486 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4487 * user-space a clue if that is the case.
4489 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4490 (hw->vht160_mcs_rx_highest != 0 ||
4491 hw->vht160_mcs_tx_highest != 0)) {
4492 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4493 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4499 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4502 struct ieee80211_sta_ht_cap ht_cap = {0};
4504 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4507 ht_cap.ht_supported = 1;
4508 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4509 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4510 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4511 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4513 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4515 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4516 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4518 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4519 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4521 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4524 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4525 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4530 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4531 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4533 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4536 stbc = ar->ht_cap_info;
4537 stbc &= WMI_HT_CAP_RX_STBC;
4538 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4539 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4540 stbc &= IEEE80211_HT_CAP_RX_STBC;
4545 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4546 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4548 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4549 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4551 /* max AMSDU is implicitly taken from vht_cap_info */
4552 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4553 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4555 for (i = 0; i < ar->num_rf_chains; i++) {
4556 if (ar->cfg_rx_chainmask & BIT(i))
4557 ht_cap.mcs.rx_mask[i] = 0xFF;
4560 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4565 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4567 struct ieee80211_supported_band *band;
4568 struct ieee80211_sta_vht_cap vht_cap;
4569 struct ieee80211_sta_ht_cap ht_cap;
4571 ht_cap = ath10k_get_ht_cap(ar);
4572 vht_cap = ath10k_create_vht_cap(ar);
4574 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4575 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4576 band->ht_cap = ht_cap;
4578 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4579 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4580 band->ht_cap = ht_cap;
4581 band->vht_cap = vht_cap;
4585 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4589 lockdep_assert_held(&ar->conf_mutex);
4591 ath10k_check_chain_mask(ar, tx_ant, "tx");
4592 ath10k_check_chain_mask(ar, rx_ant, "rx");
4594 ar->cfg_tx_chainmask = tx_ant;
4595 ar->cfg_rx_chainmask = rx_ant;
4597 if ((ar->state != ATH10K_STATE_ON) &&
4598 (ar->state != ATH10K_STATE_RESTARTED))
4601 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4604 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4609 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4612 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4617 /* Reload HT/VHT capability */
4618 ath10k_mac_setup_ht_vht_cap(ar);
4623 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4625 struct ath10k *ar = hw->priv;
4628 mutex_lock(&ar->conf_mutex);
4629 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4630 mutex_unlock(&ar->conf_mutex);
4634 static int ath10k_start(struct ieee80211_hw *hw)
4636 struct ath10k *ar = hw->priv;
4641 * This makes sense only when restarting hw. It is harmless to call
4642 * unconditionally. This is necessary to make sure no HTT/WMI tx
4643 * commands will be submitted while restarting.
4645 ath10k_drain_tx(ar);
4647 mutex_lock(&ar->conf_mutex);
4649 switch (ar->state) {
4650 case ATH10K_STATE_OFF:
4651 ar->state = ATH10K_STATE_ON;
4653 case ATH10K_STATE_RESTARTING:
4654 ar->state = ATH10K_STATE_RESTARTED;
4656 case ATH10K_STATE_ON:
4657 case ATH10K_STATE_RESTARTED:
4658 case ATH10K_STATE_WEDGED:
4662 case ATH10K_STATE_UTF:
4667 ret = ath10k_hif_power_up(ar);
4669 ath10k_err(ar, "Could not init hif: %d\n", ret);
4673 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4674 &ar->normal_mode_fw);
4676 ath10k_err(ar, "Could not init core: %d\n", ret);
4677 goto err_power_down;
4680 param = ar->wmi.pdev_param->pmf_qos;
4681 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4683 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4687 param = ar->wmi.pdev_param->dynamic_bw;
4688 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4690 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4694 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
4695 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
4697 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
4702 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4703 ret = ath10k_wmi_adaptive_qcs(ar, true);
4705 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4711 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4712 param = ar->wmi.pdev_param->burst_enable;
4713 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4715 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4720 param = ar->wmi.pdev_param->idle_ps_config;
4721 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4722 if (ret && ret != -EOPNOTSUPP) {
4723 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4727 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4730 * By default FW set ARP frames ac to voice (6). In that case ARP
4731 * exchange is not working properly for UAPSD enabled AP. ARP requests
4732 * which arrives with access category 0 are processed by network stack
4733 * and send back with access category 0, but FW changes access category
4734 * to 6. Set ARP frames access category to best effort (0) solves
4738 param = ar->wmi.pdev_param->arp_ac_override;
4739 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4741 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4746 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4747 ar->running_fw->fw_file.fw_features)) {
4748 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4749 WMI_CCA_DETECT_LEVEL_AUTO,
4750 WMI_CCA_DETECT_MARGIN_AUTO);
4752 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4758 param = ar->wmi.pdev_param->ani_enable;
4759 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4761 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4766 ar->ani_enabled = true;
4768 if (ath10k_peer_stats_enabled(ar)) {
4769 param = ar->wmi.pdev_param->peer_stats_update_period;
4770 ret = ath10k_wmi_pdev_set_param(ar, param,
4771 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4774 "failed to set peer stats period : %d\n",
4780 param = ar->wmi.pdev_param->enable_btcoex;
4781 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4782 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4783 ar->running_fw->fw_file.fw_features)) {
4784 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4787 "failed to set btcoex param: %d\n", ret);
4790 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4793 ar->num_started_vdevs = 0;
4794 ath10k_regd_update(ar);
4796 ath10k_spectral_start(ar);
4797 ath10k_thermal_set_throttling(ar);
4799 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
4801 mutex_unlock(&ar->conf_mutex);
4805 ath10k_core_stop(ar);
4808 ath10k_hif_power_down(ar);
4811 ar->state = ATH10K_STATE_OFF;
4814 mutex_unlock(&ar->conf_mutex);
4818 static void ath10k_stop(struct ieee80211_hw *hw)
4820 struct ath10k *ar = hw->priv;
4822 ath10k_drain_tx(ar);
4824 mutex_lock(&ar->conf_mutex);
4825 if (ar->state != ATH10K_STATE_OFF) {
4827 ar->state = ATH10K_STATE_OFF;
4829 mutex_unlock(&ar->conf_mutex);
4831 cancel_work_sync(&ar->set_coverage_class_work);
4832 cancel_delayed_work_sync(&ar->scan.timeout);
4833 cancel_work_sync(&ar->restart_work);
4836 static int ath10k_config_ps(struct ath10k *ar)
4838 struct ath10k_vif *arvif;
4841 lockdep_assert_held(&ar->conf_mutex);
4843 list_for_each_entry(arvif, &ar->arvifs, list) {
4844 ret = ath10k_mac_vif_setup_ps(arvif);
4846 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4854 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4859 lockdep_assert_held(&ar->conf_mutex);
4861 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4863 param = ar->wmi.pdev_param->txpower_limit2g;
4864 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4866 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4871 param = ar->wmi.pdev_param->txpower_limit5g;
4872 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4874 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4882 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4884 struct ath10k_vif *arvif;
4885 int ret, txpower = -1;
4887 lockdep_assert_held(&ar->conf_mutex);
4889 list_for_each_entry(arvif, &ar->arvifs, list) {
4890 if (arvif->txpower <= 0)
4894 txpower = arvif->txpower;
4896 txpower = min(txpower, arvif->txpower);
4902 ret = ath10k_mac_txpower_setup(ar, txpower);
4904 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4912 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4914 struct ath10k *ar = hw->priv;
4915 struct ieee80211_conf *conf = &hw->conf;
4918 mutex_lock(&ar->conf_mutex);
4920 if (changed & IEEE80211_CONF_CHANGE_PS)
4921 ath10k_config_ps(ar);
4923 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4924 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4925 ret = ath10k_monitor_recalc(ar);
4927 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4930 mutex_unlock(&ar->conf_mutex);
4934 static u32 get_nss_from_chainmask(u16 chain_mask)
4936 if ((chain_mask & 0xf) == 0xf)
4938 else if ((chain_mask & 0x7) == 0x7)
4940 else if ((chain_mask & 0x3) == 0x3)
4945 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4948 struct ath10k *ar = arvif->ar;
4952 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4955 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4956 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4957 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4958 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4960 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4961 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4962 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4963 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4968 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4969 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4971 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4972 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4973 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4975 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4976 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4978 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4979 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4980 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4982 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4983 ar->wmi.vdev_param->txbf, value);
4988 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4989 * because we will send mgmt frames without CCK. This requirement
4990 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4993 static int ath10k_add_interface(struct ieee80211_hw *hw,
4994 struct ieee80211_vif *vif)
4996 struct ath10k *ar = hw->priv;
4997 struct ath10k_vif *arvif = (void *)vif->drv_priv;
4998 struct ath10k_peer *peer;
4999 enum wmi_sta_powersave_param param;
5006 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5008 mutex_lock(&ar->conf_mutex);
5010 memset(arvif, 0, sizeof(*arvif));
5011 ath10k_mac_txq_init(vif->txq);
5016 INIT_LIST_HEAD(&arvif->list);
5017 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5018 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5019 ath10k_mac_vif_sta_connection_loss_work);
5021 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5022 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5023 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5024 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5025 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5026 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5029 if (ar->num_peers >= ar->max_num_peers) {
5030 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5035 if (ar->free_vdev_map == 0) {
5036 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5040 bit = __ffs64(ar->free_vdev_map);
5042 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5043 bit, ar->free_vdev_map);
5045 arvif->vdev_id = bit;
5046 arvif->vdev_subtype =
5047 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5049 switch (vif->type) {
5050 case NL80211_IFTYPE_P2P_DEVICE:
5051 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5052 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5053 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5055 case NL80211_IFTYPE_UNSPECIFIED:
5056 case NL80211_IFTYPE_STATION:
5057 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5059 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5060 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5062 case NL80211_IFTYPE_ADHOC:
5063 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5065 case NL80211_IFTYPE_MESH_POINT:
5066 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5067 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5068 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5069 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5071 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5074 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5076 case NL80211_IFTYPE_AP:
5077 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5080 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5081 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5083 case NL80211_IFTYPE_MONITOR:
5084 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5091 /* Using vdev_id as queue number will make it very easy to do per-vif
5092 * tx queue locking. This shouldn't wrap due to interface combinations
5093 * but do a modulo for correctness sake and prevent using offchannel tx
5094 * queues for regular vif tx.
5096 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5097 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5098 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5100 /* Some firmware revisions don't wait for beacon tx completion before
5101 * sending another SWBA event. This could lead to hardware using old
5102 * (freed) beacon data in some cases, e.g. tx credit starvation
5103 * combined with missed TBTT. This is very very rare.
5105 * On non-IOMMU-enabled hosts this could be a possible security issue
5106 * because hw could beacon some random data on the air. On
5107 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5108 * device would crash.
5110 * Since there are no beacon tx completions (implicit nor explicit)
5111 * propagated to host the only workaround for this is to allocate a
5112 * DMA-coherent buffer for a lifetime of a vif and use it for all
5113 * beacon tx commands. Worst case for this approach is some beacons may
5114 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5116 if (vif->type == NL80211_IFTYPE_ADHOC ||
5117 vif->type == NL80211_IFTYPE_MESH_POINT ||
5118 vif->type == NL80211_IFTYPE_AP) {
5119 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
5120 IEEE80211_MAX_FRAME_LEN,
5121 &arvif->beacon_paddr,
5123 if (!arvif->beacon_buf) {
5125 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5130 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5131 arvif->nohwcrypt = true;
5133 if (arvif->nohwcrypt &&
5134 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5136 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5140 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5141 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5142 arvif->beacon_buf ? "single-buf" : "per-skb");
5144 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5145 arvif->vdev_subtype, vif->addr);
5147 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5148 arvif->vdev_id, ret);
5152 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5153 spin_lock_bh(&ar->data_lock);
5154 list_add(&arvif->list, &ar->arvifs);
5155 spin_unlock_bh(&ar->data_lock);
5157 /* It makes no sense to have firmware do keepalives. mac80211 already
5158 * takes care of this with idle connection polling.
5160 ret = ath10k_mac_vif_disable_keepalive(arvif);
5162 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5163 arvif->vdev_id, ret);
5164 goto err_vdev_delete;
5167 arvif->def_wep_key_idx = -1;
5169 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5170 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5171 ATH10K_HW_TXRX_NATIVE_WIFI);
5172 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5173 if (ret && ret != -EOPNOTSUPP) {
5174 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5175 arvif->vdev_id, ret);
5176 goto err_vdev_delete;
5179 /* Configuring number of spatial stream for monitor interface is causing
5180 * target assert in qca9888 and qca6174.
5182 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5183 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5185 vdev_param = ar->wmi.vdev_param->nss;
5186 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5189 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5190 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5192 goto err_vdev_delete;
5196 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5197 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5198 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5199 vif->addr, WMI_PEER_TYPE_DEFAULT);
5201 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5202 arvif->vdev_id, ret);
5203 goto err_vdev_delete;
5206 spin_lock_bh(&ar->data_lock);
5208 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5210 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5211 vif->addr, arvif->vdev_id);
5212 spin_unlock_bh(&ar->data_lock);
5214 goto err_peer_delete;
5217 arvif->peer_id = find_first_bit(peer->peer_ids,
5218 ATH10K_MAX_NUM_PEER_IDS);
5220 spin_unlock_bh(&ar->data_lock);
5222 arvif->peer_id = HTT_INVALID_PEERID;
5225 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5226 ret = ath10k_mac_set_kickout(arvif);
5228 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5229 arvif->vdev_id, ret);
5230 goto err_peer_delete;
5234 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5235 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5236 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5237 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5240 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5241 arvif->vdev_id, ret);
5242 goto err_peer_delete;
5245 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5247 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5248 arvif->vdev_id, ret);
5249 goto err_peer_delete;
5252 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5254 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5255 arvif->vdev_id, ret);
5256 goto err_peer_delete;
5260 ret = ath10k_mac_set_txbf_conf(arvif);
5262 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5263 arvif->vdev_id, ret);
5264 goto err_peer_delete;
5267 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5269 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5270 arvif->vdev_id, ret);
5271 goto err_peer_delete;
5274 arvif->txpower = vif->bss_conf.txpower;
5275 ret = ath10k_mac_txpower_recalc(ar);
5277 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5278 goto err_peer_delete;
5281 if (vif->type == NL80211_IFTYPE_MONITOR) {
5282 ar->monitor_arvif = arvif;
5283 ret = ath10k_monitor_recalc(ar);
5285 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5286 goto err_peer_delete;
5290 spin_lock_bh(&ar->htt.tx_lock);
5292 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5293 spin_unlock_bh(&ar->htt.tx_lock);
5295 mutex_unlock(&ar->conf_mutex);
5299 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5300 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5301 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5304 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5305 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5306 spin_lock_bh(&ar->data_lock);
5307 list_del(&arvif->list);
5308 spin_unlock_bh(&ar->data_lock);
5311 if (arvif->beacon_buf) {
5312 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5313 arvif->beacon_buf, arvif->beacon_paddr);
5314 arvif->beacon_buf = NULL;
5317 mutex_unlock(&ar->conf_mutex);
5322 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5326 for (i = 0; i < BITS_PER_LONG; i++)
5327 ath10k_mac_vif_tx_unlock(arvif, i);
5330 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5331 struct ieee80211_vif *vif)
5333 struct ath10k *ar = hw->priv;
5334 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5335 struct ath10k_peer *peer;
5339 cancel_work_sync(&arvif->ap_csa_work);
5340 cancel_delayed_work_sync(&arvif->connection_loss_work);
5342 mutex_lock(&ar->conf_mutex);
5344 spin_lock_bh(&ar->data_lock);
5345 ath10k_mac_vif_beacon_cleanup(arvif);
5346 spin_unlock_bh(&ar->data_lock);
5348 ret = ath10k_spectral_vif_stop(arvif);
5350 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5351 arvif->vdev_id, ret);
5353 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5354 spin_lock_bh(&ar->data_lock);
5355 list_del(&arvif->list);
5356 spin_unlock_bh(&ar->data_lock);
5358 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5359 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5360 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5363 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5364 arvif->vdev_id, ret);
5366 kfree(arvif->u.ap.noa_data);
5369 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5372 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5374 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5375 arvif->vdev_id, ret);
5377 /* Some firmware revisions don't notify host about self-peer removal
5378 * until after associated vdev is deleted.
5380 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5381 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5382 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5385 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5386 arvif->vdev_id, ret);
5388 spin_lock_bh(&ar->data_lock);
5390 spin_unlock_bh(&ar->data_lock);
5393 spin_lock_bh(&ar->data_lock);
5394 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5395 peer = ar->peer_map[i];
5399 if (peer->vif == vif) {
5400 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5401 vif->addr, arvif->vdev_id);
5405 spin_unlock_bh(&ar->data_lock);
5407 ath10k_peer_cleanup(ar, arvif->vdev_id);
5408 ath10k_mac_txq_unref(ar, vif->txq);
5410 if (vif->type == NL80211_IFTYPE_MONITOR) {
5411 ar->monitor_arvif = NULL;
5412 ret = ath10k_monitor_recalc(ar);
5414 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5417 ret = ath10k_mac_txpower_recalc(ar);
5419 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5421 spin_lock_bh(&ar->htt.tx_lock);
5422 ath10k_mac_vif_tx_unlock_all(arvif);
5423 spin_unlock_bh(&ar->htt.tx_lock);
5425 ath10k_mac_txq_unref(ar, vif->txq);
5427 mutex_unlock(&ar->conf_mutex);
5431 * FIXME: Has to be verified.
5433 #define SUPPORTED_FILTERS \
5438 FIF_BCN_PRBRESP_PROMISC | \
5442 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5443 unsigned int changed_flags,
5444 unsigned int *total_flags,
5447 struct ath10k *ar = hw->priv;
5450 mutex_lock(&ar->conf_mutex);
5452 changed_flags &= SUPPORTED_FILTERS;
5453 *total_flags &= SUPPORTED_FILTERS;
5454 ar->filter_flags = *total_flags;
5456 ret = ath10k_monitor_recalc(ar);
5458 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5460 mutex_unlock(&ar->conf_mutex);
5463 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5464 struct ieee80211_vif *vif,
5465 struct ieee80211_bss_conf *info,
5468 struct ath10k *ar = hw->priv;
5469 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5470 struct cfg80211_chan_def def;
5471 u32 vdev_param, pdev_param, slottime, preamble;
5472 u16 bitrate, hw_value;
5474 int rateidx, ret = 0;
5475 enum nl80211_band band;
5477 mutex_lock(&ar->conf_mutex);
5479 if (changed & BSS_CHANGED_IBSS)
5480 ath10k_control_ibss(arvif, info, vif->addr);
5482 if (changed & BSS_CHANGED_BEACON_INT) {
5483 arvif->beacon_interval = info->beacon_int;
5484 vdev_param = ar->wmi.vdev_param->beacon_interval;
5485 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5486 arvif->beacon_interval);
5487 ath10k_dbg(ar, ATH10K_DBG_MAC,
5488 "mac vdev %d beacon_interval %d\n",
5489 arvif->vdev_id, arvif->beacon_interval);
5492 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5493 arvif->vdev_id, ret);
5496 if (changed & BSS_CHANGED_BEACON) {
5497 ath10k_dbg(ar, ATH10K_DBG_MAC,
5498 "vdev %d set beacon tx mode to staggered\n",
5501 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5502 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5503 WMI_BEACON_STAGGERED_MODE);
5505 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5506 arvif->vdev_id, ret);
5508 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5510 ath10k_warn(ar, "failed to update beacon template: %d\n",
5513 if (ieee80211_vif_is_mesh(vif)) {
5514 /* mesh doesn't use SSID but firmware needs it */
5515 strncpy(arvif->u.ap.ssid, "mesh",
5516 sizeof(arvif->u.ap.ssid));
5517 arvif->u.ap.ssid_len = 4;
5521 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5522 ret = ath10k_mac_setup_prb_tmpl(arvif);
5524 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5525 arvif->vdev_id, ret);
5528 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5529 arvif->dtim_period = info->dtim_period;
5531 ath10k_dbg(ar, ATH10K_DBG_MAC,
5532 "mac vdev %d dtim_period %d\n",
5533 arvif->vdev_id, arvif->dtim_period);
5535 vdev_param = ar->wmi.vdev_param->dtim_period;
5536 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5537 arvif->dtim_period);
5539 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5540 arvif->vdev_id, ret);
5543 if (changed & BSS_CHANGED_SSID &&
5544 vif->type == NL80211_IFTYPE_AP) {
5545 arvif->u.ap.ssid_len = info->ssid_len;
5547 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5548 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5551 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5552 ether_addr_copy(arvif->bssid, info->bssid);
5554 if (changed & BSS_CHANGED_BEACON_ENABLED)
5555 ath10k_control_beaconing(arvif, info);
5557 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5558 arvif->use_cts_prot = info->use_cts_prot;
5560 ret = ath10k_recalc_rtscts_prot(arvif);
5562 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5563 arvif->vdev_id, ret);
5565 if (ath10k_mac_can_set_cts_prot(arvif)) {
5566 ret = ath10k_mac_set_cts_prot(arvif);
5568 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5569 arvif->vdev_id, ret);
5573 if (changed & BSS_CHANGED_ERP_SLOT) {
5574 if (info->use_short_slot)
5575 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5578 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5580 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5581 arvif->vdev_id, slottime);
5583 vdev_param = ar->wmi.vdev_param->slot_time;
5584 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5587 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5588 arvif->vdev_id, ret);
5591 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5592 if (info->use_short_preamble)
5593 preamble = WMI_VDEV_PREAMBLE_SHORT;
5595 preamble = WMI_VDEV_PREAMBLE_LONG;
5597 ath10k_dbg(ar, ATH10K_DBG_MAC,
5598 "mac vdev %d preamble %dn",
5599 arvif->vdev_id, preamble);
5601 vdev_param = ar->wmi.vdev_param->preamble;
5602 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5605 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5606 arvif->vdev_id, ret);
5609 if (changed & BSS_CHANGED_ASSOC) {
5611 /* Workaround: Make sure monitor vdev is not running
5612 * when associating to prevent some firmware revisions
5613 * (e.g. 10.1 and 10.2) from crashing.
5615 if (ar->monitor_started)
5616 ath10k_monitor_stop(ar);
5617 ath10k_bss_assoc(hw, vif, info);
5618 ath10k_monitor_recalc(ar);
5620 ath10k_bss_disassoc(hw, vif);
5624 if (changed & BSS_CHANGED_TXPOWER) {
5625 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5626 arvif->vdev_id, info->txpower);
5628 arvif->txpower = info->txpower;
5629 ret = ath10k_mac_txpower_recalc(ar);
5631 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5634 if (changed & BSS_CHANGED_PS) {
5635 arvif->ps = vif->bss_conf.ps;
5637 ret = ath10k_config_ps(ar);
5639 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5640 arvif->vdev_id, ret);
5643 if (changed & BSS_CHANGED_MCAST_RATE &&
5644 !ath10k_mac_vif_chan(arvif->vif, &def)) {
5645 band = def.chan->band;
5646 rateidx = vif->bss_conf.mcast_rate[band] - 1;
5648 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5649 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5651 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
5652 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
5653 if (ath10k_mac_bitrate_is_cck(bitrate))
5654 preamble = WMI_RATE_PREAMBLE_CCK;
5656 preamble = WMI_RATE_PREAMBLE_OFDM;
5658 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
5660 ath10k_dbg(ar, ATH10K_DBG_MAC,
5661 "mac vdev %d mcast_rate %x\n",
5662 arvif->vdev_id, rate);
5664 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5665 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5669 "failed to set mcast rate on vdev %i: %d\n",
5670 arvif->vdev_id, ret);
5672 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5673 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5677 "failed to set bcast rate on vdev %i: %d\n",
5678 arvif->vdev_id, ret);
5681 mutex_unlock(&ar->conf_mutex);
5684 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5686 struct ath10k *ar = hw->priv;
5688 /* This function should never be called if setting the coverage class
5689 * is not supported on this hardware.
5691 if (!ar->hw_params.hw_ops->set_coverage_class) {
5695 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5698 struct ath10k_mac_tdls_iter_data {
5699 u32 num_tdls_stations;
5700 struct ieee80211_vif *curr_vif;
5703 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5704 struct ieee80211_sta *sta)
5706 struct ath10k_mac_tdls_iter_data *iter_data = data;
5707 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5708 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5710 if (sta->tdls && sta_vif == iter_data->curr_vif)
5711 iter_data->num_tdls_stations++;
5714 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5715 struct ieee80211_vif *vif)
5717 struct ath10k_mac_tdls_iter_data data = {};
5719 data.curr_vif = vif;
5721 ieee80211_iterate_stations_atomic(hw,
5722 ath10k_mac_tdls_vif_stations_count_iter,
5724 return data.num_tdls_stations;
5727 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5728 struct ieee80211_vif *vif)
5730 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5731 int *num_tdls_vifs = data;
5733 if (vif->type != NL80211_IFTYPE_STATION)
5736 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5740 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5742 int num_tdls_vifs = 0;
5744 ieee80211_iterate_active_interfaces_atomic(hw,
5745 IEEE80211_IFACE_ITER_NORMAL,
5746 ath10k_mac_tdls_vifs_count_iter,
5748 return num_tdls_vifs;
5751 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5752 struct ieee80211_vif *vif,
5753 struct ieee80211_scan_request *hw_req)
5755 struct ath10k *ar = hw->priv;
5756 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5757 struct cfg80211_scan_request *req = &hw_req->req;
5758 struct wmi_start_scan_arg arg;
5763 mutex_lock(&ar->conf_mutex);
5765 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
5770 spin_lock_bh(&ar->data_lock);
5771 switch (ar->scan.state) {
5772 case ATH10K_SCAN_IDLE:
5773 reinit_completion(&ar->scan.started);
5774 reinit_completion(&ar->scan.completed);
5775 ar->scan.state = ATH10K_SCAN_STARTING;
5776 ar->scan.is_roc = false;
5777 ar->scan.vdev_id = arvif->vdev_id;
5780 case ATH10K_SCAN_STARTING:
5781 case ATH10K_SCAN_RUNNING:
5782 case ATH10K_SCAN_ABORTING:
5786 spin_unlock_bh(&ar->data_lock);
5791 memset(&arg, 0, sizeof(arg));
5792 ath10k_wmi_start_scan_init(ar, &arg);
5793 arg.vdev_id = arvif->vdev_id;
5794 arg.scan_id = ATH10K_SCAN_ID;
5797 arg.ie_len = req->ie_len;
5798 memcpy(arg.ie, req->ie, arg.ie_len);
5802 arg.n_ssids = req->n_ssids;
5803 for (i = 0; i < arg.n_ssids; i++) {
5804 arg.ssids[i].len = req->ssids[i].ssid_len;
5805 arg.ssids[i].ssid = req->ssids[i].ssid;
5808 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5811 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5812 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
5813 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
5814 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
5817 if (req->n_channels) {
5818 arg.n_channels = req->n_channels;
5819 for (i = 0; i < arg.n_channels; i++)
5820 arg.channels[i] = req->channels[i]->center_freq;
5823 /* if duration is set, default dwell times will be overwritten */
5824 if (req->duration) {
5825 arg.dwell_time_active = req->duration;
5826 arg.dwell_time_passive = req->duration;
5827 arg.burst_duration_ms = req->duration;
5829 scan_timeout = min_t(u32, arg.max_rest_time *
5830 (arg.n_channels - 1) + (req->duration +
5831 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
5832 arg.n_channels, arg.max_scan_time + 200);
5835 /* Add a 200ms margin to account for event/command processing */
5836 scan_timeout = arg.max_scan_time + 200;
5839 ret = ath10k_start_scan(ar, &arg);
5841 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5842 spin_lock_bh(&ar->data_lock);
5843 ar->scan.state = ATH10K_SCAN_IDLE;
5844 spin_unlock_bh(&ar->data_lock);
5847 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5848 msecs_to_jiffies(scan_timeout));
5851 mutex_unlock(&ar->conf_mutex);
5855 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5856 struct ieee80211_vif *vif)
5858 struct ath10k *ar = hw->priv;
5860 mutex_lock(&ar->conf_mutex);
5861 ath10k_scan_abort(ar);
5862 mutex_unlock(&ar->conf_mutex);
5864 cancel_delayed_work_sync(&ar->scan.timeout);
5867 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5868 struct ath10k_vif *arvif,
5869 enum set_key_cmd cmd,
5870 struct ieee80211_key_conf *key)
5872 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5875 /* 10.1 firmware branch requires default key index to be set to group
5876 * key index after installing it. Otherwise FW/HW Txes corrupted
5877 * frames with multi-vif APs. This is not required for main firmware
5878 * branch (e.g. 636).
5880 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5882 * FIXME: It remains unknown if this is required for multi-vif STA
5883 * interfaces on 10.1.
5886 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5887 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5890 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5893 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5896 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5902 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5905 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5906 arvif->vdev_id, ret);
5909 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5910 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5911 struct ieee80211_key_conf *key)
5913 struct ath10k *ar = hw->priv;
5914 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5915 struct ath10k_peer *peer;
5916 const u8 *peer_addr;
5917 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5918 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5924 /* this one needs to be done in software */
5925 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
5926 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
5927 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
5928 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
5931 if (arvif->nohwcrypt)
5934 if (key->keyidx > WMI_MAX_KEY_INDEX)
5937 mutex_lock(&ar->conf_mutex);
5940 peer_addr = sta->addr;
5941 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5942 peer_addr = vif->bss_conf.bssid;
5944 peer_addr = vif->addr;
5946 key->hw_key_idx = key->keyidx;
5950 arvif->wep_keys[key->keyidx] = key;
5952 arvif->wep_keys[key->keyidx] = NULL;
5955 /* the peer should not disappear in mid-way (unless FW goes awry) since
5956 * we already hold conf_mutex. we just make sure its there now.
5958 spin_lock_bh(&ar->data_lock);
5959 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5960 spin_unlock_bh(&ar->data_lock);
5963 if (cmd == SET_KEY) {
5964 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5969 /* if the peer doesn't exist there is no key to disable anymore */
5974 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5975 flags |= WMI_KEY_PAIRWISE;
5977 flags |= WMI_KEY_GROUP;
5980 if (cmd == DISABLE_KEY)
5981 ath10k_clear_vdev_key(arvif, key);
5983 /* When WEP keys are uploaded it's possible that there are
5984 * stations associated already (e.g. when merging) without any
5985 * keys. Static WEP needs an explicit per-peer key upload.
5987 if (vif->type == NL80211_IFTYPE_ADHOC &&
5989 ath10k_mac_vif_update_wep_key(arvif, key);
5991 /* 802.1x never sets the def_wep_key_idx so each set_key()
5992 * call changes default tx key.
5994 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5995 * after first set_key().
5997 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5998 flags |= WMI_KEY_TX_USAGE;
6001 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
6004 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
6005 arvif->vdev_id, peer_addr, ret);
6009 /* mac80211 sets static WEP keys as groupwise while firmware requires
6010 * them to be installed twice as both pairwise and groupwise.
6012 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6014 flags2 &= ~WMI_KEY_GROUP;
6015 flags2 |= WMI_KEY_PAIRWISE;
6017 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6020 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6021 arvif->vdev_id, peer_addr, ret);
6022 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6026 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6027 arvif->vdev_id, peer_addr, ret2);
6033 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6035 spin_lock_bh(&ar->data_lock);
6036 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6037 if (peer && cmd == SET_KEY)
6038 peer->keys[key->keyidx] = key;
6039 else if (peer && cmd == DISABLE_KEY)
6040 peer->keys[key->keyidx] = NULL;
6041 else if (peer == NULL)
6042 /* impossible unless FW goes crazy */
6043 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6044 spin_unlock_bh(&ar->data_lock);
6046 if (sta && sta->tdls)
6047 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6048 WMI_PEER_AUTHORIZE, 1);
6051 mutex_unlock(&ar->conf_mutex);
6055 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6056 struct ieee80211_vif *vif,
6059 struct ath10k *ar = hw->priv;
6060 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6063 mutex_lock(&arvif->ar->conf_mutex);
6065 if (arvif->ar->state != ATH10K_STATE_ON)
6068 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6069 arvif->vdev_id, keyidx);
6071 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6073 arvif->ar->wmi.vdev_param->def_keyid,
6077 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6083 arvif->def_wep_key_idx = keyidx;
6086 mutex_unlock(&arvif->ar->conf_mutex);
6089 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6092 struct ath10k_vif *arvif;
6093 struct ath10k_sta *arsta;
6094 struct ieee80211_sta *sta;
6095 struct cfg80211_chan_def def;
6096 enum nl80211_band band;
6097 const u8 *ht_mcs_mask;
6098 const u16 *vht_mcs_mask;
6099 u32 changed, bw, nss, smps;
6102 arsta = container_of(wk, struct ath10k_sta, update_wk);
6103 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6104 arvif = arsta->arvif;
6107 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6110 band = def.chan->band;
6111 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6112 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6114 spin_lock_bh(&ar->data_lock);
6116 changed = arsta->changed;
6123 spin_unlock_bh(&ar->data_lock);
6125 mutex_lock(&ar->conf_mutex);
6127 nss = max_t(u32, 1, nss);
6128 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6129 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6131 if (changed & IEEE80211_RC_BW_CHANGED) {
6132 enum wmi_phy_mode mode;
6134 mode = chan_to_phymode(&def);
6135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
6136 sta->addr, bw, mode);
6138 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6139 WMI_PEER_PHYMODE, mode);
6141 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6142 sta->addr, mode, err);
6146 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6147 WMI_PEER_CHAN_WIDTH, bw);
6149 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6150 sta->addr, bw, err);
6153 if (changed & IEEE80211_RC_NSS_CHANGED) {
6154 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
6157 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6160 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6161 sta->addr, nss, err);
6164 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6165 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
6168 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6169 WMI_PEER_SMPS_STATE, smps);
6171 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6172 sta->addr, smps, err);
6175 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6176 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
6179 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6181 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6186 mutex_unlock(&ar->conf_mutex);
6189 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6190 struct ieee80211_sta *sta)
6192 struct ath10k *ar = arvif->ar;
6194 lockdep_assert_held(&ar->conf_mutex);
6196 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6199 if (ar->num_stations >= ar->max_num_stations)
6207 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6208 struct ieee80211_sta *sta)
6210 struct ath10k *ar = arvif->ar;
6212 lockdep_assert_held(&ar->conf_mutex);
6214 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6220 static int ath10k_sta_state(struct ieee80211_hw *hw,
6221 struct ieee80211_vif *vif,
6222 struct ieee80211_sta *sta,
6223 enum ieee80211_sta_state old_state,
6224 enum ieee80211_sta_state new_state)
6226 struct ath10k *ar = hw->priv;
6227 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6228 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6229 struct ath10k_peer *peer;
6233 if (old_state == IEEE80211_STA_NOTEXIST &&
6234 new_state == IEEE80211_STA_NONE) {
6235 memset(arsta, 0, sizeof(*arsta));
6236 arsta->arvif = arvif;
6237 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6239 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6240 ath10k_mac_txq_init(sta->txq[i]);
6243 /* cancel must be done outside the mutex to avoid deadlock */
6244 if ((old_state == IEEE80211_STA_NONE &&
6245 new_state == IEEE80211_STA_NOTEXIST))
6246 cancel_work_sync(&arsta->update_wk);
6248 mutex_lock(&ar->conf_mutex);
6250 if (old_state == IEEE80211_STA_NOTEXIST &&
6251 new_state == IEEE80211_STA_NONE) {
6253 * New station addition.
6255 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6256 u32 num_tdls_stations;
6259 ath10k_dbg(ar, ATH10K_DBG_MAC,
6260 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6261 arvif->vdev_id, sta->addr,
6262 ar->num_stations + 1, ar->max_num_stations,
6263 ar->num_peers + 1, ar->max_num_peers);
6265 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6266 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6269 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6270 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6272 ar->max_num_tdls_vdevs);
6276 peer_type = WMI_PEER_TYPE_TDLS;
6279 ret = ath10k_mac_inc_num_stations(arvif, sta);
6281 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6282 ar->max_num_stations);
6286 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6287 sta->addr, peer_type);
6289 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6290 sta->addr, arvif->vdev_id, ret);
6291 ath10k_mac_dec_num_stations(arvif, sta);
6295 spin_lock_bh(&ar->data_lock);
6297 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6299 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6300 vif->addr, arvif->vdev_id);
6301 spin_unlock_bh(&ar->data_lock);
6302 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6303 ath10k_mac_dec_num_stations(arvif, sta);
6308 arsta->peer_id = find_first_bit(peer->peer_ids,
6309 ATH10K_MAX_NUM_PEER_IDS);
6311 spin_unlock_bh(&ar->data_lock);
6316 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6317 WMI_TDLS_ENABLE_ACTIVE);
6319 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6320 arvif->vdev_id, ret);
6321 ath10k_peer_delete(ar, arvif->vdev_id,
6323 ath10k_mac_dec_num_stations(arvif, sta);
6327 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6328 WMI_TDLS_PEER_STATE_PEERING);
6331 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6332 sta->addr, arvif->vdev_id, ret);
6333 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6334 ath10k_mac_dec_num_stations(arvif, sta);
6336 if (num_tdls_stations != 0)
6338 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6341 } else if ((old_state == IEEE80211_STA_NONE &&
6342 new_state == IEEE80211_STA_NOTEXIST)) {
6344 * Existing station deletion.
6346 ath10k_dbg(ar, ATH10K_DBG_MAC,
6347 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6348 arvif->vdev_id, sta->addr, sta);
6351 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6353 WMI_TDLS_PEER_STATE_TEARDOWN);
6355 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6357 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6360 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6362 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6363 sta->addr, arvif->vdev_id, ret);
6365 ath10k_mac_dec_num_stations(arvif, sta);
6367 spin_lock_bh(&ar->data_lock);
6368 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6369 peer = ar->peer_map[i];
6373 if (peer->sta == sta) {
6374 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6375 sta->addr, peer, i, arvif->vdev_id);
6378 /* Clean up the peer object as well since we
6379 * must have failed to do this above.
6381 ath10k_peer_map_cleanup(ar, peer);
6384 spin_unlock_bh(&ar->data_lock);
6386 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6387 ath10k_mac_txq_unref(ar, sta->txq[i]);
6392 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6395 /* This was the last tdls peer in current vif */
6396 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6399 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6400 arvif->vdev_id, ret);
6402 } else if (old_state == IEEE80211_STA_AUTH &&
6403 new_state == IEEE80211_STA_ASSOC &&
6404 (vif->type == NL80211_IFTYPE_AP ||
6405 vif->type == NL80211_IFTYPE_MESH_POINT ||
6406 vif->type == NL80211_IFTYPE_ADHOC)) {
6410 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6413 ret = ath10k_station_assoc(ar, vif, sta, false);
6415 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6416 sta->addr, arvif->vdev_id, ret);
6417 } else if (old_state == IEEE80211_STA_ASSOC &&
6418 new_state == IEEE80211_STA_AUTHORIZED &&
6421 * Tdls station authorized.
6423 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6426 ret = ath10k_station_assoc(ar, vif, sta, false);
6428 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6429 sta->addr, arvif->vdev_id, ret);
6433 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6434 WMI_TDLS_PEER_STATE_CONNECTED);
6436 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6437 sta->addr, arvif->vdev_id, ret);
6438 } else if (old_state == IEEE80211_STA_ASSOC &&
6439 new_state == IEEE80211_STA_AUTH &&
6440 (vif->type == NL80211_IFTYPE_AP ||
6441 vif->type == NL80211_IFTYPE_MESH_POINT ||
6442 vif->type == NL80211_IFTYPE_ADHOC)) {
6446 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6449 ret = ath10k_station_disassoc(ar, vif, sta);
6451 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6452 sta->addr, arvif->vdev_id, ret);
6455 mutex_unlock(&ar->conf_mutex);
6459 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6460 u16 ac, bool enable)
6462 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6463 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6464 u32 prio = 0, acc = 0;
6468 lockdep_assert_held(&ar->conf_mutex);
6470 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6474 case IEEE80211_AC_VO:
6475 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6476 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6480 case IEEE80211_AC_VI:
6481 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6482 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6486 case IEEE80211_AC_BE:
6487 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6488 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6492 case IEEE80211_AC_BK:
6493 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6494 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6501 arvif->u.sta.uapsd |= value;
6503 arvif->u.sta.uapsd &= ~value;
6505 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6506 WMI_STA_PS_PARAM_UAPSD,
6507 arvif->u.sta.uapsd);
6509 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6513 if (arvif->u.sta.uapsd)
6514 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6516 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6518 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6519 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6522 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6524 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6526 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6527 arvif->vdev_id, ret);
6531 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6533 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6534 arvif->vdev_id, ret);
6538 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6539 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6540 /* Only userspace can make an educated decision when to send
6541 * trigger frame. The following effectively disables u-UAPSD
6542 * autotrigger in firmware (which is enabled by default
6543 * provided the autotrigger service is available).
6547 arg.user_priority = prio;
6548 arg.service_interval = 0;
6549 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6550 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6552 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6553 arvif->bssid, &arg, 1);
6555 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6565 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6566 struct ieee80211_vif *vif, u16 ac,
6567 const struct ieee80211_tx_queue_params *params)
6569 struct ath10k *ar = hw->priv;
6570 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6571 struct wmi_wmm_params_arg *p = NULL;
6574 mutex_lock(&ar->conf_mutex);
6577 case IEEE80211_AC_VO:
6578 p = &arvif->wmm_params.ac_vo;
6580 case IEEE80211_AC_VI:
6581 p = &arvif->wmm_params.ac_vi;
6583 case IEEE80211_AC_BE:
6584 p = &arvif->wmm_params.ac_be;
6586 case IEEE80211_AC_BK:
6587 p = &arvif->wmm_params.ac_bk;
6596 p->cwmin = params->cw_min;
6597 p->cwmax = params->cw_max;
6598 p->aifs = params->aifs;
6601 * The channel time duration programmed in the HW is in absolute
6602 * microseconds, while mac80211 gives the txop in units of
6605 p->txop = params->txop * 32;
6607 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6608 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6609 &arvif->wmm_params);
6611 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6612 arvif->vdev_id, ret);
6616 /* This won't work well with multi-interface cases but it's
6617 * better than nothing.
6619 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6621 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6626 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6628 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6631 mutex_unlock(&ar->conf_mutex);
6635 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6637 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6638 struct ieee80211_vif *vif,
6639 struct ieee80211_channel *chan,
6641 enum ieee80211_roc_type type)
6643 struct ath10k *ar = hw->priv;
6644 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6645 struct wmi_start_scan_arg arg;
6649 mutex_lock(&ar->conf_mutex);
6651 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6656 spin_lock_bh(&ar->data_lock);
6657 switch (ar->scan.state) {
6658 case ATH10K_SCAN_IDLE:
6659 reinit_completion(&ar->scan.started);
6660 reinit_completion(&ar->scan.completed);
6661 reinit_completion(&ar->scan.on_channel);
6662 ar->scan.state = ATH10K_SCAN_STARTING;
6663 ar->scan.is_roc = true;
6664 ar->scan.vdev_id = arvif->vdev_id;
6665 ar->scan.roc_freq = chan->center_freq;
6666 ar->scan.roc_notify = true;
6669 case ATH10K_SCAN_STARTING:
6670 case ATH10K_SCAN_RUNNING:
6671 case ATH10K_SCAN_ABORTING:
6675 spin_unlock_bh(&ar->data_lock);
6680 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6682 memset(&arg, 0, sizeof(arg));
6683 ath10k_wmi_start_scan_init(ar, &arg);
6684 arg.vdev_id = arvif->vdev_id;
6685 arg.scan_id = ATH10K_SCAN_ID;
6687 arg.channels[0] = chan->center_freq;
6688 arg.dwell_time_active = scan_time_msec;
6689 arg.dwell_time_passive = scan_time_msec;
6690 arg.max_scan_time = scan_time_msec;
6691 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6692 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6693 arg.burst_duration_ms = duration;
6695 ret = ath10k_start_scan(ar, &arg);
6697 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6698 spin_lock_bh(&ar->data_lock);
6699 ar->scan.state = ATH10K_SCAN_IDLE;
6700 spin_unlock_bh(&ar->data_lock);
6704 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6706 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6708 ret = ath10k_scan_stop(ar);
6710 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6716 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6717 msecs_to_jiffies(duration));
6721 mutex_unlock(&ar->conf_mutex);
6725 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6727 struct ath10k *ar = hw->priv;
6729 mutex_lock(&ar->conf_mutex);
6731 spin_lock_bh(&ar->data_lock);
6732 ar->scan.roc_notify = false;
6733 spin_unlock_bh(&ar->data_lock);
6735 ath10k_scan_abort(ar);
6737 mutex_unlock(&ar->conf_mutex);
6739 cancel_delayed_work_sync(&ar->scan.timeout);
6745 * Both RTS and Fragmentation threshold are interface-specific
6746 * in ath10k, but device-specific in mac80211.
6749 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6751 struct ath10k *ar = hw->priv;
6752 struct ath10k_vif *arvif;
6755 mutex_lock(&ar->conf_mutex);
6756 list_for_each_entry(arvif, &ar->arvifs, list) {
6757 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6758 arvif->vdev_id, value);
6760 ret = ath10k_mac_set_rts(arvif, value);
6762 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6763 arvif->vdev_id, ret);
6767 mutex_unlock(&ar->conf_mutex);
6772 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6774 /* Even though there's a WMI enum for fragmentation threshold no known
6775 * firmware actually implements it. Moreover it is not possible to rely
6776 * frame fragmentation to mac80211 because firmware clears the "more
6777 * fragments" bit in frame control making it impossible for remote
6778 * devices to reassemble frames.
6780 * Hence implement a dummy callback just to say fragmentation isn't
6781 * supported. This effectively prevents mac80211 from doing frame
6782 * fragmentation in software.
6787 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6788 u32 queues, bool drop)
6790 struct ath10k *ar = hw->priv;
6794 /* mac80211 doesn't care if we really xmit queued frames or not
6795 * we'll collect those frames either way if we stop/delete vdevs
6800 mutex_lock(&ar->conf_mutex);
6802 if (ar->state == ATH10K_STATE_WEDGED)
6805 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6808 spin_lock_bh(&ar->htt.tx_lock);
6809 empty = (ar->htt.num_pending_tx == 0);
6810 spin_unlock_bh(&ar->htt.tx_lock);
6812 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6813 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6817 }), ATH10K_FLUSH_TIMEOUT_HZ);
6819 if (time_left == 0 || skip)
6820 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6821 skip, ar->state, time_left);
6824 mutex_unlock(&ar->conf_mutex);
6827 /* TODO: Implement this function properly
6828 * For now it is needed to reply to Probe Requests in IBSS mode.
6829 * Propably we need this information from FW.
6831 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6836 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6837 enum ieee80211_reconfig_type reconfig_type)
6839 struct ath10k *ar = hw->priv;
6841 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6844 mutex_lock(&ar->conf_mutex);
6846 /* If device failed to restart it will be in a different state, e.g.
6847 * ATH10K_STATE_WEDGED
6849 if (ar->state == ATH10K_STATE_RESTARTED) {
6850 ath10k_info(ar, "device successfully recovered\n");
6851 ar->state = ATH10K_STATE_ON;
6852 ieee80211_wake_queues(ar->hw);
6855 mutex_unlock(&ar->conf_mutex);
6859 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6860 struct ieee80211_channel *channel)
6863 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6865 lockdep_assert_held(&ar->conf_mutex);
6867 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6868 (ar->rx_channel != channel))
6871 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6872 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6876 reinit_completion(&ar->bss_survey_done);
6878 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6880 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6884 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6886 ath10k_warn(ar, "bss channel survey timed out\n");
6891 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6892 struct survey_info *survey)
6894 struct ath10k *ar = hw->priv;
6895 struct ieee80211_supported_band *sband;
6896 struct survey_info *ar_survey = &ar->survey[idx];
6899 mutex_lock(&ar->conf_mutex);
6901 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6902 if (sband && idx >= sband->n_channels) {
6903 idx -= sband->n_channels;
6908 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6910 if (!sband || idx >= sband->n_channels) {
6915 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6917 spin_lock_bh(&ar->data_lock);
6918 memcpy(survey, ar_survey, sizeof(*survey));
6919 spin_unlock_bh(&ar->data_lock);
6921 survey->channel = &sband->channels[idx];
6923 if (ar->rx_channel == survey->channel)
6924 survey->filled |= SURVEY_INFO_IN_USE;
6927 mutex_unlock(&ar->conf_mutex);
6932 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6933 enum nl80211_band band,
6934 const struct cfg80211_bitrate_mask *mask)
6939 num_rates += hweight32(mask->control[band].legacy);
6941 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6942 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6944 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6945 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6947 return num_rates == 1;
6951 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6952 enum nl80211_band band,
6953 const struct cfg80211_bitrate_mask *mask,
6956 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6957 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6959 u8 vht_nss_mask = 0;
6962 if (mask->control[band].legacy)
6965 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6966 if (mask->control[band].ht_mcs[i] == 0)
6968 else if (mask->control[band].ht_mcs[i] ==
6969 sband->ht_cap.mcs.rx_mask[i])
6970 ht_nss_mask |= BIT(i);
6975 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6976 if (mask->control[band].vht_mcs[i] == 0)
6978 else if (mask->control[band].vht_mcs[i] ==
6979 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6980 vht_nss_mask |= BIT(i);
6985 if (ht_nss_mask != vht_nss_mask)
6988 if (ht_nss_mask == 0)
6991 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6994 *nss = fls(ht_nss_mask);
7000 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
7001 enum nl80211_band band,
7002 const struct cfg80211_bitrate_mask *mask,
7011 if (hweight32(mask->control[band].legacy) == 1) {
7012 rate_idx = ffs(mask->control[band].legacy) - 1;
7014 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
7015 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
7017 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
7018 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
7020 if (ath10k_mac_bitrate_is_cck(bitrate))
7021 preamble = WMI_RATE_PREAMBLE_CCK;
7023 preamble = WMI_RATE_PREAMBLE_OFDM;
7026 *rate = preamble << 6 |
7033 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7034 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
7036 *rate = WMI_RATE_PREAMBLE_HT << 6 |
7038 (ffs(mask->control[band].ht_mcs[i]) - 1);
7044 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7045 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
7047 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
7049 (ffs(mask->control[band].vht_mcs[i]) - 1);
7058 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
7059 u8 rate, u8 nss, u8 sgi, u8 ldpc)
7061 struct ath10k *ar = arvif->ar;
7065 lockdep_assert_held(&ar->conf_mutex);
7067 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7068 arvif->vdev_id, rate, nss, sgi);
7070 vdev_param = ar->wmi.vdev_param->fixed_rate;
7071 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
7073 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
7078 vdev_param = ar->wmi.vdev_param->nss;
7079 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
7081 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
7085 vdev_param = ar->wmi.vdev_param->sgi;
7086 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
7088 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
7092 vdev_param = ar->wmi.vdev_param->ldpc;
7093 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
7095 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
7103 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
7104 enum nl80211_band band,
7105 const struct cfg80211_bitrate_mask *mask)
7110 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7111 * to express all VHT MCS rate masks. Effectively only the following
7112 * ranges can be used: none, 0-7, 0-8 and 0-9.
7114 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7115 vht_mcs = mask->control[band].vht_mcs[i];
7124 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7132 static void ath10k_mac_set_bitrate_mask_iter(void *data,
7133 struct ieee80211_sta *sta)
7135 struct ath10k_vif *arvif = data;
7136 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7137 struct ath10k *ar = arvif->ar;
7139 if (arsta->arvif != arvif)
7142 spin_lock_bh(&ar->data_lock);
7143 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7144 spin_unlock_bh(&ar->data_lock);
7146 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7149 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7150 struct ieee80211_vif *vif,
7151 const struct cfg80211_bitrate_mask *mask)
7153 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7154 struct cfg80211_chan_def def;
7155 struct ath10k *ar = arvif->ar;
7156 enum nl80211_band band;
7157 const u8 *ht_mcs_mask;
7158 const u16 *vht_mcs_mask;
7166 if (ath10k_mac_vif_chan(vif, &def))
7169 band = def.chan->band;
7170 ht_mcs_mask = mask->control[band].ht_mcs;
7171 vht_mcs_mask = mask->control[band].vht_mcs;
7172 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7174 sgi = mask->control[band].gi;
7175 if (sgi == NL80211_TXRATE_FORCE_LGI)
7178 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7179 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7182 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7183 arvif->vdev_id, ret);
7186 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7188 rate = WMI_FIXED_RATE_NONE;
7191 rate = WMI_FIXED_RATE_NONE;
7192 nss = min(ar->num_rf_chains,
7193 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7194 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7196 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7199 mutex_lock(&ar->conf_mutex);
7201 arvif->bitrate_mask = *mask;
7202 ieee80211_iterate_stations_atomic(ar->hw,
7203 ath10k_mac_set_bitrate_mask_iter,
7206 mutex_unlock(&ar->conf_mutex);
7209 mutex_lock(&ar->conf_mutex);
7211 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7213 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7214 arvif->vdev_id, ret);
7219 mutex_unlock(&ar->conf_mutex);
7224 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7225 struct ieee80211_vif *vif,
7226 struct ieee80211_sta *sta,
7229 struct ath10k *ar = hw->priv;
7230 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7231 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7232 struct ath10k_peer *peer;
7235 spin_lock_bh(&ar->data_lock);
7237 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7239 spin_unlock_bh(&ar->data_lock);
7240 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7241 sta->addr, arvif->vdev_id);
7245 ath10k_dbg(ar, ATH10K_DBG_MAC,
7246 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7247 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7250 if (changed & IEEE80211_RC_BW_CHANGED) {
7251 bw = WMI_PEER_CHWIDTH_20MHZ;
7253 switch (sta->bandwidth) {
7254 case IEEE80211_STA_RX_BW_20:
7255 bw = WMI_PEER_CHWIDTH_20MHZ;
7257 case IEEE80211_STA_RX_BW_40:
7258 bw = WMI_PEER_CHWIDTH_40MHZ;
7260 case IEEE80211_STA_RX_BW_80:
7261 bw = WMI_PEER_CHWIDTH_80MHZ;
7263 case IEEE80211_STA_RX_BW_160:
7264 bw = WMI_PEER_CHWIDTH_160MHZ;
7267 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7268 sta->bandwidth, sta->addr);
7269 bw = WMI_PEER_CHWIDTH_20MHZ;
7276 if (changed & IEEE80211_RC_NSS_CHANGED)
7277 arsta->nss = sta->rx_nss;
7279 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7280 smps = WMI_PEER_SMPS_PS_NONE;
7282 switch (sta->smps_mode) {
7283 case IEEE80211_SMPS_AUTOMATIC:
7284 case IEEE80211_SMPS_OFF:
7285 smps = WMI_PEER_SMPS_PS_NONE;
7287 case IEEE80211_SMPS_STATIC:
7288 smps = WMI_PEER_SMPS_STATIC;
7290 case IEEE80211_SMPS_DYNAMIC:
7291 smps = WMI_PEER_SMPS_DYNAMIC;
7293 case IEEE80211_SMPS_NUM_MODES:
7294 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7295 sta->smps_mode, sta->addr);
7296 smps = WMI_PEER_SMPS_PS_NONE;
7303 arsta->changed |= changed;
7305 spin_unlock_bh(&ar->data_lock);
7307 ieee80211_queue_work(hw, &arsta->update_wk);
7310 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7311 struct ieee80211_vif *vif, s64 tsf_offset)
7313 struct ath10k *ar = hw->priv;
7314 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7315 u32 offset, vdev_param;
7318 if (tsf_offset < 0) {
7319 vdev_param = ar->wmi.vdev_param->dec_tsf;
7320 offset = -tsf_offset;
7322 vdev_param = ar->wmi.vdev_param->inc_tsf;
7323 offset = tsf_offset;
7326 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7327 vdev_param, offset);
7329 if (ret && ret != -EOPNOTSUPP)
7330 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7331 offset, vdev_param, ret);
7334 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7335 struct ieee80211_vif *vif,
7336 struct ieee80211_ampdu_params *params)
7338 struct ath10k *ar = hw->priv;
7339 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7340 struct ieee80211_sta *sta = params->sta;
7341 enum ieee80211_ampdu_mlme_action action = params->action;
7342 u16 tid = params->tid;
7344 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7345 arvif->vdev_id, sta->addr, tid, action);
7348 case IEEE80211_AMPDU_RX_START:
7349 case IEEE80211_AMPDU_RX_STOP:
7350 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7351 * creation/removal. Do we need to verify this?
7354 case IEEE80211_AMPDU_TX_START:
7355 case IEEE80211_AMPDU_TX_STOP_CONT:
7356 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7357 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7358 case IEEE80211_AMPDU_TX_OPERATIONAL:
7359 /* Firmware offloads Tx aggregation entirely so deny mac80211
7360 * Tx aggregation requests.
7369 ath10k_mac_update_rx_channel(struct ath10k *ar,
7370 struct ieee80211_chanctx_conf *ctx,
7371 struct ieee80211_vif_chanctx_switch *vifs,
7374 struct cfg80211_chan_def *def = NULL;
7376 /* Both locks are required because ar->rx_channel is modified. This
7377 * allows readers to hold either lock.
7379 lockdep_assert_held(&ar->conf_mutex);
7380 lockdep_assert_held(&ar->data_lock);
7382 WARN_ON(ctx && vifs);
7383 WARN_ON(vifs && !n_vifs);
7385 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7386 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7387 * ppdu on Rx may reduce performance on low-end systems. It should be
7388 * possible to make tables/hashmaps to speed the lookup up (be vary of
7389 * cpu data cache lines though regarding sizes) but to keep the initial
7390 * implementation simple and less intrusive fallback to the slow lookup
7391 * only for multi-channel cases. Single-channel cases will remain to
7392 * use the old channel derival and thus performance should not be
7396 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7397 ieee80211_iter_chan_contexts_atomic(ar->hw,
7398 ath10k_mac_get_any_chandef_iter,
7402 def = &vifs[0].new_ctx->def;
7404 ar->rx_channel = def->chan;
7405 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7406 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7407 /* During driver restart due to firmware assert, since mac80211
7408 * already has valid channel context for given radio, channel
7409 * context iteration return num_chanctx > 0. So fix rx_channel
7410 * when restart is in progress.
7412 ar->rx_channel = ctx->def.chan;
7414 ar->rx_channel = NULL;
7420 ath10k_mac_update_vif_chan(struct ath10k *ar,
7421 struct ieee80211_vif_chanctx_switch *vifs,
7424 struct ath10k_vif *arvif;
7428 lockdep_assert_held(&ar->conf_mutex);
7430 /* First stop monitor interface. Some FW versions crash if there's a
7431 * lone monitor interface.
7433 if (ar->monitor_started)
7434 ath10k_monitor_stop(ar);
7436 for (i = 0; i < n_vifs; i++) {
7437 arvif = (void *)vifs[i].vif->drv_priv;
7439 ath10k_dbg(ar, ATH10K_DBG_MAC,
7440 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7442 vifs[i].old_ctx->def.chan->center_freq,
7443 vifs[i].new_ctx->def.chan->center_freq,
7444 vifs[i].old_ctx->def.width,
7445 vifs[i].new_ctx->def.width);
7447 if (WARN_ON(!arvif->is_started))
7450 if (WARN_ON(!arvif->is_up))
7453 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7455 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7456 arvif->vdev_id, ret);
7461 /* All relevant vdevs are downed and associated channel resources
7462 * should be available for the channel switch now.
7465 spin_lock_bh(&ar->data_lock);
7466 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7467 spin_unlock_bh(&ar->data_lock);
7469 for (i = 0; i < n_vifs; i++) {
7470 arvif = (void *)vifs[i].vif->drv_priv;
7472 if (WARN_ON(!arvif->is_started))
7475 if (WARN_ON(!arvif->is_up))
7478 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7480 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7483 ret = ath10k_mac_setup_prb_tmpl(arvif);
7485 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7488 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7490 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7491 arvif->vdev_id, ret);
7495 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7498 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7499 arvif->vdev_id, ret);
7504 ath10k_monitor_recalc(ar);
7508 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7509 struct ieee80211_chanctx_conf *ctx)
7511 struct ath10k *ar = hw->priv;
7513 ath10k_dbg(ar, ATH10K_DBG_MAC,
7514 "mac chanctx add freq %hu width %d ptr %pK\n",
7515 ctx->def.chan->center_freq, ctx->def.width, ctx);
7517 mutex_lock(&ar->conf_mutex);
7519 spin_lock_bh(&ar->data_lock);
7520 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7521 spin_unlock_bh(&ar->data_lock);
7523 ath10k_recalc_radar_detection(ar);
7524 ath10k_monitor_recalc(ar);
7526 mutex_unlock(&ar->conf_mutex);
7532 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7533 struct ieee80211_chanctx_conf *ctx)
7535 struct ath10k *ar = hw->priv;
7537 ath10k_dbg(ar, ATH10K_DBG_MAC,
7538 "mac chanctx remove freq %hu width %d ptr %pK\n",
7539 ctx->def.chan->center_freq, ctx->def.width, ctx);
7541 mutex_lock(&ar->conf_mutex);
7543 spin_lock_bh(&ar->data_lock);
7544 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7545 spin_unlock_bh(&ar->data_lock);
7547 ath10k_recalc_radar_detection(ar);
7548 ath10k_monitor_recalc(ar);
7550 mutex_unlock(&ar->conf_mutex);
7553 struct ath10k_mac_change_chanctx_arg {
7554 struct ieee80211_chanctx_conf *ctx;
7555 struct ieee80211_vif_chanctx_switch *vifs;
7561 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7562 struct ieee80211_vif *vif)
7564 struct ath10k_mac_change_chanctx_arg *arg = data;
7566 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7573 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7574 struct ieee80211_vif *vif)
7576 struct ath10k_mac_change_chanctx_arg *arg = data;
7577 struct ieee80211_chanctx_conf *ctx;
7579 ctx = rcu_access_pointer(vif->chanctx_conf);
7580 if (ctx != arg->ctx)
7583 if (WARN_ON(arg->next_vif == arg->n_vifs))
7586 arg->vifs[arg->next_vif].vif = vif;
7587 arg->vifs[arg->next_vif].old_ctx = ctx;
7588 arg->vifs[arg->next_vif].new_ctx = ctx;
7593 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7594 struct ieee80211_chanctx_conf *ctx,
7597 struct ath10k *ar = hw->priv;
7598 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7600 mutex_lock(&ar->conf_mutex);
7602 ath10k_dbg(ar, ATH10K_DBG_MAC,
7603 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7604 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7606 /* This shouldn't really happen because channel switching should use
7607 * switch_vif_chanctx().
7609 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7612 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7613 ieee80211_iterate_active_interfaces_atomic(
7615 IEEE80211_IFACE_ITER_NORMAL,
7616 ath10k_mac_change_chanctx_cnt_iter,
7618 if (arg.n_vifs == 0)
7621 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7626 ieee80211_iterate_active_interfaces_atomic(
7628 IEEE80211_IFACE_ITER_NORMAL,
7629 ath10k_mac_change_chanctx_fill_iter,
7631 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7636 ath10k_recalc_radar_detection(ar);
7638 /* FIXME: How to configure Rx chains properly? */
7640 /* No other actions are actually necessary. Firmware maintains channel
7641 * definitions per vdev internally and there's no host-side channel
7642 * context abstraction to configure, e.g. channel width.
7646 mutex_unlock(&ar->conf_mutex);
7650 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7651 struct ieee80211_vif *vif,
7652 struct ieee80211_chanctx_conf *ctx)
7654 struct ath10k *ar = hw->priv;
7655 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7658 mutex_lock(&ar->conf_mutex);
7660 ath10k_dbg(ar, ATH10K_DBG_MAC,
7661 "mac chanctx assign ptr %pK vdev_id %i\n",
7662 ctx, arvif->vdev_id);
7664 if (WARN_ON(arvif->is_started)) {
7665 mutex_unlock(&ar->conf_mutex);
7669 ret = ath10k_vdev_start(arvif, &ctx->def);
7671 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7672 arvif->vdev_id, vif->addr,
7673 ctx->def.chan->center_freq, ret);
7677 arvif->is_started = true;
7679 ret = ath10k_mac_vif_setup_ps(arvif);
7681 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7682 arvif->vdev_id, ret);
7686 if (vif->type == NL80211_IFTYPE_MONITOR) {
7687 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7689 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7690 arvif->vdev_id, ret);
7694 arvif->is_up = true;
7697 if (ath10k_mac_can_set_cts_prot(arvif)) {
7698 ret = ath10k_mac_set_cts_prot(arvif);
7700 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7701 arvif->vdev_id, ret);
7704 if (ath10k_peer_stats_enabled(ar)) {
7705 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
7706 ret = ath10k_wmi_pdev_pktlog_enable(ar,
7709 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
7714 mutex_unlock(&ar->conf_mutex);
7718 ath10k_vdev_stop(arvif);
7719 arvif->is_started = false;
7720 ath10k_mac_vif_setup_ps(arvif);
7723 mutex_unlock(&ar->conf_mutex);
7728 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7729 struct ieee80211_vif *vif,
7730 struct ieee80211_chanctx_conf *ctx)
7732 struct ath10k *ar = hw->priv;
7733 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7736 mutex_lock(&ar->conf_mutex);
7738 ath10k_dbg(ar, ATH10K_DBG_MAC,
7739 "mac chanctx unassign ptr %pK vdev_id %i\n",
7740 ctx, arvif->vdev_id);
7742 WARN_ON(!arvif->is_started);
7744 if (vif->type == NL80211_IFTYPE_MONITOR) {
7745 WARN_ON(!arvif->is_up);
7747 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7749 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7750 arvif->vdev_id, ret);
7752 arvif->is_up = false;
7755 ret = ath10k_vdev_stop(arvif);
7757 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7758 arvif->vdev_id, ret);
7760 arvif->is_started = false;
7762 mutex_unlock(&ar->conf_mutex);
7766 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7767 struct ieee80211_vif_chanctx_switch *vifs,
7769 enum ieee80211_chanctx_switch_mode mode)
7771 struct ath10k *ar = hw->priv;
7773 mutex_lock(&ar->conf_mutex);
7775 ath10k_dbg(ar, ATH10K_DBG_MAC,
7776 "mac chanctx switch n_vifs %d mode %d\n",
7778 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7780 mutex_unlock(&ar->conf_mutex);
7784 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7785 struct ieee80211_vif *vif,
7786 struct ieee80211_sta *sta)
7789 struct ath10k_peer *peer;
7793 list_for_each_entry(peer, &ar->peers, list)
7794 if (peer->sta == sta)
7795 peer->removed = true;
7798 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
7799 struct ieee80211_vif *vif,
7800 struct ieee80211_sta *sta,
7801 struct station_info *sinfo)
7803 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7804 struct ath10k *ar = arsta->arvif->ar;
7806 if (!ath10k_peer_stats_enabled(ar))
7809 sinfo->rx_duration = arsta->rx_duration;
7810 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
7812 if (!arsta->txrate.legacy && !arsta->txrate.nss)
7815 if (arsta->txrate.legacy) {
7816 sinfo->txrate.legacy = arsta->txrate.legacy;
7818 sinfo->txrate.mcs = arsta->txrate.mcs;
7819 sinfo->txrate.nss = arsta->txrate.nss;
7820 sinfo->txrate.bw = arsta->txrate.bw;
7822 sinfo->txrate.flags = arsta->txrate.flags;
7823 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
7826 static const struct ieee80211_ops ath10k_ops = {
7827 .tx = ath10k_mac_op_tx,
7828 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7829 .start = ath10k_start,
7830 .stop = ath10k_stop,
7831 .config = ath10k_config,
7832 .add_interface = ath10k_add_interface,
7833 .remove_interface = ath10k_remove_interface,
7834 .configure_filter = ath10k_configure_filter,
7835 .bss_info_changed = ath10k_bss_info_changed,
7836 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7837 .hw_scan = ath10k_hw_scan,
7838 .cancel_hw_scan = ath10k_cancel_hw_scan,
7839 .set_key = ath10k_set_key,
7840 .set_default_unicast_key = ath10k_set_default_unicast_key,
7841 .sta_state = ath10k_sta_state,
7842 .conf_tx = ath10k_conf_tx,
7843 .remain_on_channel = ath10k_remain_on_channel,
7844 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7845 .set_rts_threshold = ath10k_set_rts_threshold,
7846 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7847 .flush = ath10k_flush,
7848 .tx_last_beacon = ath10k_tx_last_beacon,
7849 .set_antenna = ath10k_set_antenna,
7850 .get_antenna = ath10k_get_antenna,
7851 .reconfig_complete = ath10k_reconfig_complete,
7852 .get_survey = ath10k_get_survey,
7853 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7854 .sta_rc_update = ath10k_sta_rc_update,
7855 .offset_tsf = ath10k_offset_tsf,
7856 .ampdu_action = ath10k_ampdu_action,
7857 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7858 .get_et_stats = ath10k_debug_get_et_stats,
7859 .get_et_strings = ath10k_debug_get_et_strings,
7860 .add_chanctx = ath10k_mac_op_add_chanctx,
7861 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7862 .change_chanctx = ath10k_mac_op_change_chanctx,
7863 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7864 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7865 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7866 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7867 .sta_statistics = ath10k_sta_statistics,
7869 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7872 .suspend = ath10k_wow_op_suspend,
7873 .resume = ath10k_wow_op_resume,
7874 .set_wakeup = ath10k_wow_op_set_wakeup,
7876 #ifdef CONFIG_MAC80211_DEBUGFS
7877 .sta_add_debugfs = ath10k_sta_add_debugfs,
7881 #define CHAN2G(_channel, _freq, _flags) { \
7882 .band = NL80211_BAND_2GHZ, \
7883 .hw_value = (_channel), \
7884 .center_freq = (_freq), \
7885 .flags = (_flags), \
7886 .max_antenna_gain = 0, \
7890 #define CHAN5G(_channel, _freq, _flags) { \
7891 .band = NL80211_BAND_5GHZ, \
7892 .hw_value = (_channel), \
7893 .center_freq = (_freq), \
7894 .flags = (_flags), \
7895 .max_antenna_gain = 0, \
7899 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7909 CHAN2G(10, 2457, 0),
7910 CHAN2G(11, 2462, 0),
7911 CHAN2G(12, 2467, 0),
7912 CHAN2G(13, 2472, 0),
7913 CHAN2G(14, 2484, 0),
7916 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7917 CHAN5G(36, 5180, 0),
7918 CHAN5G(40, 5200, 0),
7919 CHAN5G(44, 5220, 0),
7920 CHAN5G(48, 5240, 0),
7921 CHAN5G(52, 5260, 0),
7922 CHAN5G(56, 5280, 0),
7923 CHAN5G(60, 5300, 0),
7924 CHAN5G(64, 5320, 0),
7925 CHAN5G(100, 5500, 0),
7926 CHAN5G(104, 5520, 0),
7927 CHAN5G(108, 5540, 0),
7928 CHAN5G(112, 5560, 0),
7929 CHAN5G(116, 5580, 0),
7930 CHAN5G(120, 5600, 0),
7931 CHAN5G(124, 5620, 0),
7932 CHAN5G(128, 5640, 0),
7933 CHAN5G(132, 5660, 0),
7934 CHAN5G(136, 5680, 0),
7935 CHAN5G(140, 5700, 0),
7936 CHAN5G(144, 5720, 0),
7937 CHAN5G(149, 5745, 0),
7938 CHAN5G(153, 5765, 0),
7939 CHAN5G(157, 5785, 0),
7940 CHAN5G(161, 5805, 0),
7941 CHAN5G(165, 5825, 0),
7942 CHAN5G(169, 5845, 0),
7943 CHAN5G(173, 5865, 0),
7944 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
7945 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
7948 struct ath10k *ath10k_mac_create(size_t priv_size)
7950 struct ieee80211_hw *hw;
7951 struct ieee80211_ops *ops;
7954 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7958 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7971 void ath10k_mac_destroy(struct ath10k *ar)
7973 struct ieee80211_ops *ops = ar->ops;
7975 ieee80211_free_hw(ar->hw);
7979 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7982 .types = BIT(NL80211_IFTYPE_STATION)
7983 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7987 .types = BIT(NL80211_IFTYPE_P2P_GO)
7991 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7995 .types = BIT(NL80211_IFTYPE_AP)
7996 #ifdef CONFIG_MAC80211_MESH
7997 | BIT(NL80211_IFTYPE_MESH_POINT)
8002 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
8005 .types = BIT(NL80211_IFTYPE_AP)
8006 #ifdef CONFIG_MAC80211_MESH
8007 | BIT(NL80211_IFTYPE_MESH_POINT)
8012 .types = BIT(NL80211_IFTYPE_STATION)
8016 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
8018 .limits = ath10k_if_limits,
8019 .n_limits = ARRAY_SIZE(ath10k_if_limits),
8020 .max_interfaces = 8,
8021 .num_different_channels = 1,
8022 .beacon_int_infra_match = true,
8026 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
8028 .limits = ath10k_10x_if_limits,
8029 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
8030 .max_interfaces = 8,
8031 .num_different_channels = 1,
8032 .beacon_int_infra_match = true,
8033 .beacon_int_min_gcd = 1,
8034 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8035 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8036 BIT(NL80211_CHAN_WIDTH_20) |
8037 BIT(NL80211_CHAN_WIDTH_40) |
8038 BIT(NL80211_CHAN_WIDTH_80),
8043 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
8046 .types = BIT(NL80211_IFTYPE_STATION),
8050 .types = BIT(NL80211_IFTYPE_AP) |
8051 #ifdef CONFIG_MAC80211_MESH
8052 BIT(NL80211_IFTYPE_MESH_POINT) |
8054 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8055 BIT(NL80211_IFTYPE_P2P_GO),
8059 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8063 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
8066 .types = BIT(NL80211_IFTYPE_STATION),
8070 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
8074 .types = BIT(NL80211_IFTYPE_AP) |
8075 #ifdef CONFIG_MAC80211_MESH
8076 BIT(NL80211_IFTYPE_MESH_POINT) |
8078 BIT(NL80211_IFTYPE_P2P_GO),
8082 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8086 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
8089 .types = BIT(NL80211_IFTYPE_STATION),
8093 .types = BIT(NL80211_IFTYPE_ADHOC),
8097 /* FIXME: This is not thouroughly tested. These combinations may over- or
8098 * underestimate hw/fw capabilities.
8100 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
8102 .limits = ath10k_tlv_if_limit,
8103 .num_different_channels = 1,
8104 .max_interfaces = 4,
8105 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8108 .limits = ath10k_tlv_if_limit_ibss,
8109 .num_different_channels = 1,
8110 .max_interfaces = 2,
8111 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8115 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
8117 .limits = ath10k_tlv_if_limit,
8118 .num_different_channels = 1,
8119 .max_interfaces = 4,
8120 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8123 .limits = ath10k_tlv_qcs_if_limit,
8124 .num_different_channels = 2,
8125 .max_interfaces = 4,
8126 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
8129 .limits = ath10k_tlv_if_limit_ibss,
8130 .num_different_channels = 1,
8131 .max_interfaces = 2,
8132 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8136 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8139 .types = BIT(NL80211_IFTYPE_STATION),
8143 .types = BIT(NL80211_IFTYPE_AP)
8144 #ifdef CONFIG_MAC80211_MESH
8145 | BIT(NL80211_IFTYPE_MESH_POINT)
8150 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8152 .limits = ath10k_10_4_if_limits,
8153 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8154 .max_interfaces = 16,
8155 .num_different_channels = 1,
8156 .beacon_int_infra_match = true,
8157 .beacon_int_min_gcd = 1,
8158 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8159 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8160 BIT(NL80211_CHAN_WIDTH_20) |
8161 BIT(NL80211_CHAN_WIDTH_40) |
8162 BIT(NL80211_CHAN_WIDTH_80),
8167 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8168 struct ieee80211_vif *vif)
8170 struct ath10k_vif_iter *arvif_iter = data;
8171 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8173 if (arvif->vdev_id == arvif_iter->vdev_id)
8174 arvif_iter->arvif = arvif;
8177 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8179 struct ath10k_vif_iter arvif_iter;
8182 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8183 arvif_iter.vdev_id = vdev_id;
8185 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8186 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8188 ath10k_get_arvif_iter,
8190 if (!arvif_iter.arvif) {
8191 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8195 return arvif_iter.arvif;
8198 #define WRD_METHOD "WRDD"
8199 #define WRDD_WIFI (0x07)
8201 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8203 union acpi_object *mcc_pkg;
8204 union acpi_object *domain_type;
8205 union acpi_object *mcc_value;
8208 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8209 wrdd->package.count < 2 ||
8210 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8211 wrdd->package.elements[0].integer.value != 0) {
8212 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8216 for (i = 1; i < wrdd->package.count; ++i) {
8217 mcc_pkg = &wrdd->package.elements[i];
8219 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8221 if (mcc_pkg->package.count < 2)
8223 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8224 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8227 domain_type = &mcc_pkg->package.elements[0];
8228 if (domain_type->integer.value != WRDD_WIFI)
8231 mcc_value = &mcc_pkg->package.elements[1];
8232 return mcc_value->integer.value;
8237 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8239 struct pci_dev __maybe_unused *pdev = to_pci_dev(ar->dev);
8240 acpi_handle root_handle;
8242 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8247 root_handle = ACPI_HANDLE(&pdev->dev);
8251 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8252 if (ACPI_FAILURE(status)) {
8253 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8254 "failed to get wrd method %d\n", status);
8258 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8259 if (ACPI_FAILURE(status)) {
8260 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8261 "failed to call wrdc %d\n", status);
8265 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8266 kfree(wrdd.pointer);
8270 alpha2[0] = (alpha2_code >> 8) & 0xff;
8271 alpha2[1] = (alpha2_code >> 0) & 0xff;
8274 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8275 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8277 *rd = ath_regd_find_country_by_name(alpha2);
8281 *rd |= COUNTRY_ERD_FLAG;
8285 static int ath10k_mac_init_rd(struct ath10k *ar)
8290 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8292 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8293 "fallback to eeprom programmed regulatory settings\n");
8294 rd = ar->hw_eeprom_rd;
8297 ar->ath_common.regulatory.current_rd = rd;
8301 int ath10k_mac_register(struct ath10k *ar)
8303 static const u32 cipher_suites[] = {
8304 WLAN_CIPHER_SUITE_WEP40,
8305 WLAN_CIPHER_SUITE_WEP104,
8306 WLAN_CIPHER_SUITE_TKIP,
8307 WLAN_CIPHER_SUITE_CCMP,
8309 /* Do not add hardware supported ciphers before this line.
8310 * Allow software encryption for all chips. Don't forget to
8311 * update n_cipher_suites below.
8313 WLAN_CIPHER_SUITE_AES_CMAC,
8314 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8315 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8316 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8318 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8319 * and CCMP-256 in hardware.
8321 WLAN_CIPHER_SUITE_GCMP,
8322 WLAN_CIPHER_SUITE_GCMP_256,
8323 WLAN_CIPHER_SUITE_CCMP_256,
8325 struct ieee80211_supported_band *band;
8329 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8331 SET_IEEE80211_DEV(ar->hw, ar->dev);
8333 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8334 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8337 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8338 channels = kmemdup(ath10k_2ghz_channels,
8339 sizeof(ath10k_2ghz_channels),
8346 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8347 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8348 band->channels = channels;
8350 if (ar->hw_params.cck_rate_map_rev2) {
8351 band->n_bitrates = ath10k_g_rates_rev2_size;
8352 band->bitrates = ath10k_g_rates_rev2;
8354 band->n_bitrates = ath10k_g_rates_size;
8355 band->bitrates = ath10k_g_rates;
8358 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8361 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8362 channels = kmemdup(ath10k_5ghz_channels,
8363 sizeof(ath10k_5ghz_channels),
8370 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8371 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8372 band->channels = channels;
8373 band->n_bitrates = ath10k_a_rates_size;
8374 band->bitrates = ath10k_a_rates;
8375 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8378 wiphy_read_of_freq_limits(ar->hw->wiphy);
8379 ath10k_mac_setup_ht_vht_cap(ar);
8381 ar->hw->wiphy->interface_modes =
8382 BIT(NL80211_IFTYPE_STATION) |
8383 BIT(NL80211_IFTYPE_AP) |
8384 BIT(NL80211_IFTYPE_MESH_POINT);
8386 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8387 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8389 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8390 ar->hw->wiphy->interface_modes |=
8391 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8392 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8393 BIT(NL80211_IFTYPE_P2P_GO);
8395 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8397 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
8398 ar->running_fw->fw_file.fw_features)) {
8399 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8400 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8403 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8404 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8405 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8406 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8407 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8408 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8409 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8410 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8411 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8412 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8413 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8414 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8415 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8417 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8418 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8420 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8421 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8423 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8424 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8426 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8427 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8428 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8431 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8432 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8434 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8435 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8436 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8438 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8440 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8441 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8443 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8444 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8445 * correct Probe Responses. This is more of a hack advert..
8447 ar->hw->wiphy->probe_resp_offload |=
8448 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8449 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8450 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8453 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8454 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8455 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8456 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
8457 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8460 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8461 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
8463 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8464 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8465 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8467 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8468 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8469 NL80211_FEATURE_AP_SCAN;
8471 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8473 ret = ath10k_wow_init(ar);
8475 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8479 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8480 wiphy_ext_feature_set(ar->hw->wiphy,
8481 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
8484 * on LL hardware queues are managed entirely by the FW
8485 * so we only advertise to mac we can do the queues thing
8487 ar->hw->queues = IEEE80211_MAX_QUEUES;
8489 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8490 * something that vdev_ids can't reach so that we don't stop the queue
8493 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8495 switch (ar->running_fw->fw_file.wmi_op_version) {
8496 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8497 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8498 ar->hw->wiphy->n_iface_combinations =
8499 ARRAY_SIZE(ath10k_if_comb);
8500 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8502 case ATH10K_FW_WMI_OP_VERSION_TLV:
8503 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8504 ar->hw->wiphy->iface_combinations =
8505 ath10k_tlv_qcs_if_comb;
8506 ar->hw->wiphy->n_iface_combinations =
8507 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8509 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8510 ar->hw->wiphy->n_iface_combinations =
8511 ARRAY_SIZE(ath10k_tlv_if_comb);
8513 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8515 case ATH10K_FW_WMI_OP_VERSION_10_1:
8516 case ATH10K_FW_WMI_OP_VERSION_10_2:
8517 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8518 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8519 ar->hw->wiphy->n_iface_combinations =
8520 ARRAY_SIZE(ath10k_10x_if_comb);
8522 case ATH10K_FW_WMI_OP_VERSION_10_4:
8523 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8524 ar->hw->wiphy->n_iface_combinations =
8525 ARRAY_SIZE(ath10k_10_4_if_comb);
8527 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8528 case ATH10K_FW_WMI_OP_VERSION_MAX:
8534 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8535 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8537 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8538 /* Init ath dfs pattern detector */
8539 ar->ath_common.debug_mask = ATH_DBG_DFS;
8540 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8543 if (!ar->dfs_detector)
8544 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8547 ret = ath10k_mac_init_rd(ar);
8549 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8550 goto err_dfs_detector_exit;
8553 /* Disable set_coverage_class for chipsets that do not support it. */
8554 if (!ar->hw_params.hw_ops->set_coverage_class)
8555 ar->ops->set_coverage_class = NULL;
8557 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8558 ath10k_reg_notifier);
8560 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8561 goto err_dfs_detector_exit;
8564 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
8565 ar->hw->wiphy->features |=
8566 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8569 ar->hw->wiphy->cipher_suites = cipher_suites;
8571 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
8572 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
8573 * from chip specific hw_param table.
8575 if (!ar->hw_params.n_cipher_suites ||
8576 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
8577 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
8578 ar->hw_params.n_cipher_suites);
8579 ar->hw_params.n_cipher_suites = 8;
8581 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
8583 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8585 ret = ieee80211_register_hw(ar->hw);
8587 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8588 goto err_dfs_detector_exit;
8591 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8592 ret = regulatory_hint(ar->hw->wiphy,
8593 ar->ath_common.regulatory.alpha2);
8595 goto err_unregister;
8601 ieee80211_unregister_hw(ar->hw);
8603 err_dfs_detector_exit:
8604 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8605 ar->dfs_detector->exit(ar->dfs_detector);
8608 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8609 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8611 SET_IEEE80211_DEV(ar->hw, NULL);
8615 void ath10k_mac_unregister(struct ath10k *ar)
8617 ieee80211_unregister_hw(ar->hw);
8619 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8620 ar->dfs_detector->exit(ar->dfs_detector);
8622 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8623 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8625 SET_IEEE80211_DEV(ar->hw, NULL);