2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018, 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>
41 static struct ieee80211_rate ath10k_rates[] = {
43 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
45 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
46 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
47 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
49 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
50 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
51 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
53 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
54 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
55 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
57 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
58 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
59 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
60 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
61 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
62 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
63 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
64 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
67 static struct ieee80211_rate ath10k_rates_rev2[] = {
69 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
71 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
72 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
73 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
75 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
76 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
77 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
79 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
80 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
81 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
83 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
84 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
85 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
86 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
87 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
88 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
89 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
90 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
93 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
95 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
96 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
97 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
98 #define ath10k_g_rates (ath10k_rates + 0)
99 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
101 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
102 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
104 #define ath10k_wmi_legacy_rates ath10k_rates
106 static bool ath10k_mac_bitrate_is_cck(int bitrate)
119 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
121 return DIV_ROUND_UP(bitrate, 5) |
122 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
125 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
126 u8 hw_rate, bool cck)
128 const struct ieee80211_rate *rate;
131 for (i = 0; i < sband->n_bitrates; i++) {
132 rate = &sband->bitrates[i];
134 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
137 if (rate->hw_value == hw_rate)
139 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
140 rate->hw_value_short == hw_rate)
147 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
152 for (i = 0; i < sband->n_bitrates; i++)
153 if (sband->bitrates[i].bitrate == bitrate)
159 static int ath10k_mac_get_rate_hw_value(int bitrate)
162 u8 hw_value_prefix = 0;
164 if (ath10k_mac_bitrate_is_cck(bitrate))
165 hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
167 for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
168 if (ath10k_rates[i].bitrate == bitrate)
169 return hw_value_prefix | ath10k_rates[i].hw_value;
175 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
177 switch ((mcs_map >> (2 * nss)) & 0x3) {
178 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
179 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
180 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
186 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
190 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
191 if (ht_mcs_mask[nss])
198 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
202 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
203 if (vht_mcs_mask[nss])
209 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
211 enum wmi_host_platform_type platform_type;
214 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
215 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
217 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
219 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
221 if (ret && ret != -EOPNOTSUPP) {
222 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
233 static int ath10k_send_key(struct ath10k_vif *arvif,
234 struct ieee80211_key_conf *key,
235 enum set_key_cmd cmd,
236 const u8 *macaddr, u32 flags)
238 struct ath10k *ar = arvif->ar;
239 struct wmi_vdev_install_key_arg arg = {
240 .vdev_id = arvif->vdev_id,
241 .key_idx = key->keyidx,
242 .key_len = key->keylen,
243 .key_data = key->key,
248 lockdep_assert_held(&arvif->ar->conf_mutex);
250 switch (key->cipher) {
251 case WLAN_CIPHER_SUITE_CCMP:
252 arg.key_cipher = WMI_CIPHER_AES_CCM;
253 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
255 case WLAN_CIPHER_SUITE_TKIP:
256 arg.key_cipher = WMI_CIPHER_TKIP;
257 arg.key_txmic_len = 8;
258 arg.key_rxmic_len = 8;
260 case WLAN_CIPHER_SUITE_WEP40:
261 case WLAN_CIPHER_SUITE_WEP104:
262 arg.key_cipher = WMI_CIPHER_WEP;
264 case WLAN_CIPHER_SUITE_CCMP_256:
265 arg.key_cipher = WMI_CIPHER_AES_CCM;
267 case WLAN_CIPHER_SUITE_GCMP:
268 case WLAN_CIPHER_SUITE_GCMP_256:
269 arg.key_cipher = WMI_CIPHER_AES_GCM;
271 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
272 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
273 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
274 case WLAN_CIPHER_SUITE_AES_CMAC:
278 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
282 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
283 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
285 if (cmd == DISABLE_KEY) {
286 arg.key_cipher = WMI_CIPHER_NONE;
290 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
293 static int ath10k_install_key(struct ath10k_vif *arvif,
294 struct ieee80211_key_conf *key,
295 enum set_key_cmd cmd,
296 const u8 *macaddr, u32 flags)
298 struct ath10k *ar = arvif->ar;
300 unsigned long time_left;
302 lockdep_assert_held(&ar->conf_mutex);
304 reinit_completion(&ar->install_key_done);
306 if (arvif->nohwcrypt)
309 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
313 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
320 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
323 struct ath10k *ar = arvif->ar;
324 struct ath10k_peer *peer;
329 lockdep_assert_held(&ar->conf_mutex);
331 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
332 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
333 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
336 spin_lock_bh(&ar->data_lock);
337 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
338 spin_unlock_bh(&ar->data_lock);
343 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
344 if (arvif->wep_keys[i] == NULL)
347 switch (arvif->vif->type) {
348 case NL80211_IFTYPE_AP:
349 flags = WMI_KEY_PAIRWISE;
351 if (arvif->def_wep_key_idx == i)
352 flags |= WMI_KEY_TX_USAGE;
354 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
355 SET_KEY, addr, flags);
359 case NL80211_IFTYPE_ADHOC:
360 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
366 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
367 SET_KEY, addr, WMI_KEY_GROUP);
376 spin_lock_bh(&ar->data_lock);
377 peer->keys[i] = arvif->wep_keys[i];
378 spin_unlock_bh(&ar->data_lock);
381 /* In some cases (notably with static WEP IBSS with multiple keys)
382 * multicast Tx becomes broken. Both pairwise and groupwise keys are
383 * installed already. Using WMI_KEY_TX_USAGE in different combinations
384 * didn't seem help. Using def_keyid vdev parameter seems to be
385 * effective so use that.
387 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
389 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
392 if (arvif->def_wep_key_idx == -1)
395 ret = ath10k_wmi_vdev_set_param(arvif->ar,
397 arvif->ar->wmi.vdev_param->def_keyid,
398 arvif->def_wep_key_idx);
400 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
401 arvif->vdev_id, ret);
408 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
411 struct ath10k *ar = arvif->ar;
412 struct ath10k_peer *peer;
418 lockdep_assert_held(&ar->conf_mutex);
420 spin_lock_bh(&ar->data_lock);
421 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
422 spin_unlock_bh(&ar->data_lock);
427 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
428 if (peer->keys[i] == NULL)
431 /* key flags are not required to delete the key */
432 ret = ath10k_install_key(arvif, peer->keys[i],
433 DISABLE_KEY, addr, flags);
434 if (ret < 0 && first_errno == 0)
438 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
441 spin_lock_bh(&ar->data_lock);
442 peer->keys[i] = NULL;
443 spin_unlock_bh(&ar->data_lock);
449 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
452 struct ath10k_peer *peer;
455 lockdep_assert_held(&ar->data_lock);
457 /* We don't know which vdev this peer belongs to,
458 * since WMI doesn't give us that information.
460 * FIXME: multi-bss needs to be handled.
462 peer = ath10k_peer_find(ar, 0, addr);
466 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
467 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
474 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
475 struct ieee80211_key_conf *key)
477 struct ath10k *ar = arvif->ar;
478 struct ath10k_peer *peer;
485 lockdep_assert_held(&ar->conf_mutex);
488 /* since ath10k_install_key we can't hold data_lock all the
489 * time, so we try to remove the keys incrementally
491 spin_lock_bh(&ar->data_lock);
493 list_for_each_entry(peer, &ar->peers, list) {
494 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
495 if (peer->keys[i] == key) {
496 ether_addr_copy(addr, peer->addr);
497 peer->keys[i] = NULL;
502 if (i < ARRAY_SIZE(peer->keys))
505 spin_unlock_bh(&ar->data_lock);
507 if (i == ARRAY_SIZE(peer->keys))
509 /* key flags are not required to delete the key */
510 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
511 if (ret < 0 && first_errno == 0)
515 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
522 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
523 struct ieee80211_key_conf *key)
525 struct ath10k *ar = arvif->ar;
526 struct ath10k_peer *peer;
529 lockdep_assert_held(&ar->conf_mutex);
531 list_for_each_entry(peer, &ar->peers, list) {
532 if (ether_addr_equal(peer->addr, arvif->vif->addr))
535 if (ether_addr_equal(peer->addr, arvif->bssid))
538 if (peer->keys[key->keyidx] == key)
541 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
542 arvif->vdev_id, key->keyidx);
544 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
546 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
547 arvif->vdev_id, peer->addr, ret);
555 /*********************/
556 /* General utilities */
557 /*********************/
559 static inline enum wmi_phy_mode
560 chan_to_phymode(const struct cfg80211_chan_def *chandef)
562 enum wmi_phy_mode phymode = MODE_UNKNOWN;
564 switch (chandef->chan->band) {
565 case NL80211_BAND_2GHZ:
566 switch (chandef->width) {
567 case NL80211_CHAN_WIDTH_20_NOHT:
568 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
573 case NL80211_CHAN_WIDTH_20:
574 phymode = MODE_11NG_HT20;
576 case NL80211_CHAN_WIDTH_40:
577 phymode = MODE_11NG_HT40;
579 case NL80211_CHAN_WIDTH_5:
580 case NL80211_CHAN_WIDTH_10:
581 case NL80211_CHAN_WIDTH_80:
582 case NL80211_CHAN_WIDTH_80P80:
583 case NL80211_CHAN_WIDTH_160:
584 phymode = MODE_UNKNOWN;
588 case NL80211_BAND_5GHZ:
589 switch (chandef->width) {
590 case NL80211_CHAN_WIDTH_20_NOHT:
593 case NL80211_CHAN_WIDTH_20:
594 phymode = MODE_11NA_HT20;
596 case NL80211_CHAN_WIDTH_40:
597 phymode = MODE_11NA_HT40;
599 case NL80211_CHAN_WIDTH_80:
600 phymode = MODE_11AC_VHT80;
602 case NL80211_CHAN_WIDTH_160:
603 phymode = MODE_11AC_VHT160;
605 case NL80211_CHAN_WIDTH_80P80:
606 phymode = MODE_11AC_VHT80_80;
608 case NL80211_CHAN_WIDTH_5:
609 case NL80211_CHAN_WIDTH_10:
610 phymode = MODE_UNKNOWN;
618 WARN_ON(phymode == MODE_UNKNOWN);
622 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
625 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
626 * 0 for no restriction
635 switch (mpdudensity) {
641 /* Our lower layer calculations limit our precision to
658 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
659 struct cfg80211_chan_def *def)
661 struct ieee80211_chanctx_conf *conf;
664 conf = rcu_dereference(vif->chanctx_conf);
676 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
677 struct ieee80211_chanctx_conf *conf,
685 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
689 ieee80211_iter_chan_contexts_atomic(ar->hw,
690 ath10k_mac_num_chanctxs_iter,
697 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
698 struct ieee80211_chanctx_conf *conf,
701 struct cfg80211_chan_def **def = data;
706 static int ath10k_peer_create(struct ath10k *ar,
707 struct ieee80211_vif *vif,
708 struct ieee80211_sta *sta,
711 enum wmi_peer_type peer_type)
713 struct ath10k_vif *arvif;
714 struct ath10k_peer *peer;
718 lockdep_assert_held(&ar->conf_mutex);
720 num_peers = ar->num_peers;
722 /* Each vdev consumes a peer entry as well */
723 list_for_each_entry(arvif, &ar->arvifs, list)
726 if (num_peers >= ar->max_num_peers)
729 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
731 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
736 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
738 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
743 spin_lock_bh(&ar->data_lock);
745 peer = ath10k_peer_find(ar, vdev_id, addr);
747 spin_unlock_bh(&ar->data_lock);
748 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
750 ath10k_wmi_peer_delete(ar, vdev_id, addr);
757 spin_unlock_bh(&ar->data_lock);
764 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
766 struct ath10k *ar = arvif->ar;
770 param = ar->wmi.pdev_param->sta_kickout_th;
771 ret = ath10k_wmi_pdev_set_param(ar, param,
772 ATH10K_KICKOUT_THRESHOLD);
774 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
775 arvif->vdev_id, ret);
779 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
780 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
781 ATH10K_KEEPALIVE_MIN_IDLE);
783 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
784 arvif->vdev_id, ret);
788 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
789 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
790 ATH10K_KEEPALIVE_MAX_IDLE);
792 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
793 arvif->vdev_id, ret);
797 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
798 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
799 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
801 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
802 arvif->vdev_id, ret);
809 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
811 struct ath10k *ar = arvif->ar;
814 vdev_param = ar->wmi.vdev_param->rts_threshold;
815 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
818 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
822 lockdep_assert_held(&ar->conf_mutex);
824 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
828 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
837 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
839 struct ath10k_peer *peer, *tmp;
843 lockdep_assert_held(&ar->conf_mutex);
845 spin_lock_bh(&ar->data_lock);
846 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
847 if (peer->vdev_id != vdev_id)
850 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
851 peer->addr, vdev_id);
853 for_each_set_bit(peer_id, peer->peer_ids,
854 ATH10K_MAX_NUM_PEER_IDS) {
855 ar->peer_map[peer_id] = NULL;
858 /* Double check that peer is properly un-referenced from
861 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
862 if (ar->peer_map[i] == peer) {
863 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
864 peer->addr, peer, i);
865 ar->peer_map[i] = NULL;
869 list_del(&peer->list);
873 spin_unlock_bh(&ar->data_lock);
876 static void ath10k_peer_cleanup_all(struct ath10k *ar)
878 struct ath10k_peer *peer, *tmp;
881 lockdep_assert_held(&ar->conf_mutex);
883 spin_lock_bh(&ar->data_lock);
884 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
885 list_del(&peer->list);
889 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
890 ar->peer_map[i] = NULL;
892 spin_unlock_bh(&ar->data_lock);
895 ar->num_stations = 0;
898 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
899 struct ieee80211_sta *sta,
900 enum wmi_tdls_peer_state state)
903 struct wmi_tdls_peer_update_cmd_arg arg = {};
904 struct wmi_tdls_peer_capab_arg cap = {};
905 struct wmi_channel_arg chan_arg = {};
907 lockdep_assert_held(&ar->conf_mutex);
909 arg.vdev_id = vdev_id;
910 arg.peer_state = state;
911 ether_addr_copy(arg.addr, sta->addr);
913 cap.peer_max_sp = sta->max_sp;
914 cap.peer_uapsd_queues = sta->uapsd_queues;
916 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
917 !sta->tdls_initiator)
918 cap.is_peer_responder = 1;
920 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
922 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
923 arg.addr, vdev_id, ret);
930 /************************/
931 /* Interface management */
932 /************************/
934 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
936 struct ath10k *ar = arvif->ar;
938 lockdep_assert_held(&ar->data_lock);
943 if (!arvif->beacon_buf)
944 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
945 arvif->beacon->len, DMA_TO_DEVICE);
947 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
948 arvif->beacon_state != ATH10K_BEACON_SENT))
951 dev_kfree_skb_any(arvif->beacon);
953 arvif->beacon = NULL;
954 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
957 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
959 struct ath10k *ar = arvif->ar;
961 lockdep_assert_held(&ar->data_lock);
963 ath10k_mac_vif_beacon_free(arvif);
965 if (arvif->beacon_buf) {
966 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
967 arvif->beacon_buf, arvif->beacon_paddr);
968 arvif->beacon_buf = NULL;
972 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
974 unsigned long time_left;
976 lockdep_assert_held(&ar->conf_mutex);
978 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
981 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
982 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
986 return ar->last_wmi_vdev_start_status;
989 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
991 struct cfg80211_chan_def *chandef = NULL;
992 struct ieee80211_channel *channel = NULL;
993 struct wmi_vdev_start_request_arg arg = {};
996 lockdep_assert_held(&ar->conf_mutex);
998 ieee80211_iter_chan_contexts_atomic(ar->hw,
999 ath10k_mac_get_any_chandef_iter,
1001 if (WARN_ON_ONCE(!chandef))
1004 channel = chandef->chan;
1006 arg.vdev_id = vdev_id;
1007 arg.channel.freq = channel->center_freq;
1008 arg.channel.band_center_freq1 = chandef->center_freq1;
1009 arg.channel.band_center_freq2 = chandef->center_freq2;
1011 /* TODO setup this dynamically, what in case we
1012 * don't have any vifs?
1014 arg.channel.mode = chan_to_phymode(chandef);
1015 arg.channel.chan_radar =
1016 !!(channel->flags & IEEE80211_CHAN_RADAR);
1018 arg.channel.min_power = 0;
1019 arg.channel.max_power = channel->max_power * 2;
1020 arg.channel.max_reg_power = channel->max_reg_power * 2;
1021 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
1023 reinit_completion(&ar->vdev_setup_done);
1025 ret = ath10k_wmi_vdev_start(ar, &arg);
1027 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1032 ret = ath10k_vdev_setup_sync(ar);
1034 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1039 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1041 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1046 ar->monitor_vdev_id = vdev_id;
1048 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1049 ar->monitor_vdev_id);
1053 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1055 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1056 ar->monitor_vdev_id, ret);
1061 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1065 lockdep_assert_held(&ar->conf_mutex);
1067 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1069 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1070 ar->monitor_vdev_id, ret);
1072 reinit_completion(&ar->vdev_setup_done);
1074 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1076 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1077 ar->monitor_vdev_id, ret);
1079 ret = ath10k_vdev_setup_sync(ar);
1081 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1082 ar->monitor_vdev_id, ret);
1084 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1085 ar->monitor_vdev_id);
1089 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1093 lockdep_assert_held(&ar->conf_mutex);
1095 if (ar->free_vdev_map == 0) {
1096 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1100 bit = __ffs64(ar->free_vdev_map);
1102 ar->monitor_vdev_id = bit;
1104 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1105 WMI_VDEV_TYPE_MONITOR,
1108 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1109 ar->monitor_vdev_id, ret);
1113 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1114 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1115 ar->monitor_vdev_id);
1120 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1124 lockdep_assert_held(&ar->conf_mutex);
1126 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1128 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1129 ar->monitor_vdev_id, ret);
1133 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1136 ar->monitor_vdev_id);
1140 static int ath10k_monitor_start(struct ath10k *ar)
1144 lockdep_assert_held(&ar->conf_mutex);
1146 ret = ath10k_monitor_vdev_create(ar);
1148 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1152 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1154 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1155 ath10k_monitor_vdev_delete(ar);
1159 ar->monitor_started = true;
1160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1165 static int ath10k_monitor_stop(struct ath10k *ar)
1169 lockdep_assert_held(&ar->conf_mutex);
1171 ret = ath10k_monitor_vdev_stop(ar);
1173 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1177 ret = ath10k_monitor_vdev_delete(ar);
1179 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1183 ar->monitor_started = false;
1184 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1189 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1193 /* At least one chanctx is required to derive a channel to start
1196 num_ctx = ath10k_mac_num_chanctxs(ar);
1200 /* If there's already an existing special monitor interface then don't
1201 * bother creating another monitor vdev.
1203 if (ar->monitor_arvif)
1206 return ar->monitor ||
1207 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1208 ar->running_fw->fw_file.fw_features) &&
1209 (ar->filter_flags & FIF_OTHER_BSS)) ||
1210 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1213 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1217 num_ctx = ath10k_mac_num_chanctxs(ar);
1219 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1220 * shouldn't allow this but make sure to prevent handling the following
1221 * case anyway since multi-channel DFS hasn't been tested at all.
1223 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1229 static int ath10k_monitor_recalc(struct ath10k *ar)
1235 lockdep_assert_held(&ar->conf_mutex);
1237 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1238 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1240 ath10k_dbg(ar, ATH10K_DBG_MAC,
1241 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1242 ar->monitor_started, needed, allowed);
1244 if (WARN_ON(needed && !allowed)) {
1245 if (ar->monitor_started) {
1246 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1248 ret = ath10k_monitor_stop(ar);
1250 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1258 if (needed == ar->monitor_started)
1262 return ath10k_monitor_start(ar);
1264 return ath10k_monitor_stop(ar);
1267 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1269 struct ath10k *ar = arvif->ar;
1271 lockdep_assert_held(&ar->conf_mutex);
1273 if (!arvif->is_started) {
1274 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1281 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1283 struct ath10k *ar = arvif->ar;
1286 lockdep_assert_held(&ar->conf_mutex);
1288 vdev_param = ar->wmi.vdev_param->protection_mode;
1290 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1291 arvif->vdev_id, arvif->use_cts_prot);
1293 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1294 arvif->use_cts_prot ? 1 : 0);
1297 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1299 struct ath10k *ar = arvif->ar;
1300 u32 vdev_param, rts_cts = 0;
1302 lockdep_assert_held(&ar->conf_mutex);
1304 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1306 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1308 if (arvif->num_legacy_stations > 0)
1309 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1310 WMI_RTSCTS_PROFILE);
1312 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1313 WMI_RTSCTS_PROFILE);
1315 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1316 arvif->vdev_id, rts_cts);
1318 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1322 static int ath10k_start_cac(struct ath10k *ar)
1326 lockdep_assert_held(&ar->conf_mutex);
1328 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1330 ret = ath10k_monitor_recalc(ar);
1332 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1333 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1337 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1338 ar->monitor_vdev_id);
1343 static int ath10k_stop_cac(struct ath10k *ar)
1345 lockdep_assert_held(&ar->conf_mutex);
1347 /* CAC is not running - do nothing */
1348 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1351 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1352 ath10k_monitor_stop(ar);
1354 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1359 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1360 struct ieee80211_chanctx_conf *conf,
1365 if (!*ret && conf->radar_enabled)
1369 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1371 bool has_radar = false;
1373 ieee80211_iter_chan_contexts_atomic(ar->hw,
1374 ath10k_mac_has_radar_iter,
1380 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1384 lockdep_assert_held(&ar->conf_mutex);
1386 ath10k_stop_cac(ar);
1388 if (!ath10k_mac_has_radar_enabled(ar))
1391 if (ar->num_started_vdevs > 0)
1394 ret = ath10k_start_cac(ar);
1397 * Not possible to start CAC on current channel so starting
1398 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1399 * by indicating that radar was detected.
1401 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1402 ieee80211_radar_detected(ar->hw);
1406 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1408 struct ath10k *ar = arvif->ar;
1411 lockdep_assert_held(&ar->conf_mutex);
1413 reinit_completion(&ar->vdev_setup_done);
1415 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1417 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1418 arvif->vdev_id, ret);
1422 ret = ath10k_vdev_setup_sync(ar);
1424 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1425 arvif->vdev_id, ret);
1429 WARN_ON(ar->num_started_vdevs == 0);
1431 if (ar->num_started_vdevs != 0) {
1432 ar->num_started_vdevs--;
1433 ath10k_recalc_radar_detection(ar);
1439 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1440 const struct cfg80211_chan_def *chandef,
1443 struct ath10k *ar = arvif->ar;
1444 struct wmi_vdev_start_request_arg arg = {};
1447 lockdep_assert_held(&ar->conf_mutex);
1449 reinit_completion(&ar->vdev_setup_done);
1451 arg.vdev_id = arvif->vdev_id;
1452 arg.dtim_period = arvif->dtim_period;
1453 arg.bcn_intval = arvif->beacon_interval;
1455 arg.channel.freq = chandef->chan->center_freq;
1456 arg.channel.band_center_freq1 = chandef->center_freq1;
1457 arg.channel.band_center_freq2 = chandef->center_freq2;
1458 arg.channel.mode = chan_to_phymode(chandef);
1460 arg.channel.min_power = 0;
1461 arg.channel.max_power = chandef->chan->max_power * 2;
1462 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1463 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1465 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1466 arg.ssid = arvif->u.ap.ssid;
1467 arg.ssid_len = arvif->u.ap.ssid_len;
1468 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1470 /* For now allow DFS for AP mode */
1471 arg.channel.chan_radar =
1472 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1473 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1474 arg.ssid = arvif->vif->bss_conf.ssid;
1475 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1478 ath10k_dbg(ar, ATH10K_DBG_MAC,
1479 "mac vdev %d start center_freq %d phymode %s\n",
1480 arg.vdev_id, arg.channel.freq,
1481 ath10k_wmi_phymode_str(arg.channel.mode));
1484 ret = ath10k_wmi_vdev_restart(ar, &arg);
1486 ret = ath10k_wmi_vdev_start(ar, &arg);
1489 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1494 ret = ath10k_vdev_setup_sync(ar);
1497 "failed to synchronize setup for vdev %i restart %d: %d\n",
1498 arg.vdev_id, restart, ret);
1502 ar->num_started_vdevs++;
1503 ath10k_recalc_radar_detection(ar);
1508 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1509 const struct cfg80211_chan_def *def)
1511 return ath10k_vdev_start_restart(arvif, def, false);
1514 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1515 const struct cfg80211_chan_def *def)
1517 return ath10k_vdev_start_restart(arvif, def, true);
1520 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1521 struct sk_buff *bcn)
1523 struct ath10k *ar = arvif->ar;
1524 struct ieee80211_mgmt *mgmt;
1528 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1531 mgmt = (void *)bcn->data;
1532 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1533 mgmt->u.beacon.variable,
1534 bcn->len - (mgmt->u.beacon.variable -
1539 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1541 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1542 arvif->vdev_id, ret);
1549 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1550 u8 oui_type, size_t ie_offset)
1557 if (WARN_ON(skb->len < ie_offset))
1560 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1561 skb->data + ie_offset,
1562 skb->len - ie_offset);
1567 end = skb->data + skb->len;
1570 if (WARN_ON(next > end))
1573 memmove(ie, next, end - next);
1574 skb_trim(skb, skb->len - len);
1579 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1581 struct ath10k *ar = arvif->ar;
1582 struct ieee80211_hw *hw = ar->hw;
1583 struct ieee80211_vif *vif = arvif->vif;
1584 struct ieee80211_mutable_offsets offs = {};
1585 struct sk_buff *bcn;
1588 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1591 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1592 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1595 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1597 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1601 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1603 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1608 /* P2P IE is inserted by firmware automatically (as configured above)
1609 * so remove it from the base beacon template to avoid duplicate P2P
1610 * IEs in beacon frames.
1612 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1613 offsetof(struct ieee80211_mgmt,
1614 u.beacon.variable));
1616 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1621 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1629 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1631 struct ath10k *ar = arvif->ar;
1632 struct ieee80211_hw *hw = ar->hw;
1633 struct ieee80211_vif *vif = arvif->vif;
1634 struct sk_buff *prb;
1637 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1640 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1643 prb = ieee80211_proberesp_get(hw, vif);
1645 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1649 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1653 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1661 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1663 struct ath10k *ar = arvif->ar;
1664 struct cfg80211_chan_def def;
1667 /* When originally vdev is started during assign_vif_chanctx() some
1668 * information is missing, notably SSID. Firmware revisions with beacon
1669 * offloading require the SSID to be provided during vdev (re)start to
1670 * handle hidden SSID properly.
1672 * Vdev restart must be done after vdev has been both started and
1673 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1674 * deliver vdev restart response event causing timeouts during vdev
1675 * syncing in ath10k.
1677 * Note: The vdev down/up and template reinstallation could be skipped
1678 * since only wmi-tlv firmware are known to have beacon offload and
1679 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1680 * response delivery. It's probably more robust to keep it as is.
1682 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1685 if (WARN_ON(!arvif->is_started))
1688 if (WARN_ON(!arvif->is_up))
1691 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1694 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1696 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1697 arvif->vdev_id, ret);
1701 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1702 * firmware will crash upon vdev up.
1705 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1707 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1711 ret = ath10k_mac_setup_prb_tmpl(arvif);
1713 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1717 ret = ath10k_vdev_restart(arvif, &def);
1719 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1720 arvif->vdev_id, ret);
1724 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1727 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1728 arvif->vdev_id, ret);
1735 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1736 struct ieee80211_bss_conf *info)
1738 struct ath10k *ar = arvif->ar;
1741 lockdep_assert_held(&arvif->ar->conf_mutex);
1743 if (!info->enable_beacon) {
1744 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1746 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1747 arvif->vdev_id, ret);
1749 arvif->is_up = false;
1751 spin_lock_bh(&arvif->ar->data_lock);
1752 ath10k_mac_vif_beacon_free(arvif);
1753 spin_unlock_bh(&arvif->ar->data_lock);
1758 arvif->tx_seq_no = 0x1000;
1761 ether_addr_copy(arvif->bssid, info->bssid);
1763 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1766 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1767 arvif->vdev_id, ret);
1771 arvif->is_up = true;
1773 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1775 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1776 arvif->vdev_id, ret);
1780 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1783 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1784 struct ieee80211_bss_conf *info,
1785 const u8 self_peer[ETH_ALEN])
1787 struct ath10k *ar = arvif->ar;
1791 lockdep_assert_held(&arvif->ar->conf_mutex);
1793 if (!info->ibss_joined) {
1794 if (is_zero_ether_addr(arvif->bssid))
1797 eth_zero_addr(arvif->bssid);
1802 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1803 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1804 ATH10K_DEFAULT_ATIM);
1806 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1807 arvif->vdev_id, ret);
1810 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1812 struct ath10k *ar = arvif->ar;
1817 lockdep_assert_held(&arvif->ar->conf_mutex);
1819 if (arvif->u.sta.uapsd)
1820 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1822 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1824 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1825 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1827 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1828 value, arvif->vdev_id, ret);
1835 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1837 struct ath10k *ar = arvif->ar;
1842 lockdep_assert_held(&arvif->ar->conf_mutex);
1844 if (arvif->u.sta.uapsd)
1845 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1847 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1849 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1850 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1853 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1854 value, arvif->vdev_id, ret);
1861 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1863 struct ath10k_vif *arvif;
1866 lockdep_assert_held(&ar->conf_mutex);
1868 list_for_each_entry(arvif, &ar->arvifs, list)
1869 if (arvif->is_started)
1875 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1877 struct ath10k *ar = arvif->ar;
1878 struct ieee80211_vif *vif = arvif->vif;
1879 struct ieee80211_conf *conf = &ar->hw->conf;
1880 enum wmi_sta_powersave_param param;
1881 enum wmi_sta_ps_mode psmode;
1886 lockdep_assert_held(&arvif->ar->conf_mutex);
1888 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1891 enable_ps = arvif->ps;
1893 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1894 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1895 ar->running_fw->fw_file.fw_features)) {
1896 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1901 if (!arvif->is_started) {
1902 /* mac80211 can update vif powersave state while disconnected.
1903 * Firmware doesn't behave nicely and consumes more power than
1904 * necessary if PS is disabled on a non-started vdev. Hence
1905 * force-enable PS for non-running vdevs.
1907 psmode = WMI_STA_PS_MODE_ENABLED;
1908 } else if (enable_ps) {
1909 psmode = WMI_STA_PS_MODE_ENABLED;
1910 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1912 ps_timeout = conf->dynamic_ps_timeout;
1913 if (ps_timeout == 0) {
1914 /* Firmware doesn't like 0 */
1915 ps_timeout = ieee80211_tu_to_usec(
1916 vif->bss_conf.beacon_int) / 1000;
1919 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1922 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1923 arvif->vdev_id, ret);
1927 psmode = WMI_STA_PS_MODE_DISABLED;
1930 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1931 arvif->vdev_id, psmode ? "enable" : "disable");
1933 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1935 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1936 psmode, arvif->vdev_id, ret);
1943 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1945 struct ath10k *ar = arvif->ar;
1946 struct wmi_sta_keepalive_arg arg = {};
1949 lockdep_assert_held(&arvif->ar->conf_mutex);
1951 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1954 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1957 /* Some firmware revisions have a bug and ignore the `enabled` field.
1958 * Instead use the interval to disable the keepalive.
1960 arg.vdev_id = arvif->vdev_id;
1962 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1963 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1965 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1967 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1968 arvif->vdev_id, ret);
1975 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1977 struct ath10k *ar = arvif->ar;
1978 struct ieee80211_vif *vif = arvif->vif;
1981 lockdep_assert_held(&arvif->ar->conf_mutex);
1983 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1986 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1989 if (!vif->csa_active)
1995 if (!ieee80211_csa_is_complete(vif)) {
1996 ieee80211_csa_update_counter(vif);
1998 ret = ath10k_mac_setup_bcn_tmpl(arvif);
2000 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
2003 ret = ath10k_mac_setup_prb_tmpl(arvif);
2005 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
2008 ieee80211_csa_finish(vif);
2012 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2014 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2016 struct ath10k *ar = arvif->ar;
2018 mutex_lock(&ar->conf_mutex);
2019 ath10k_mac_vif_ap_csa_count_down(arvif);
2020 mutex_unlock(&ar->conf_mutex);
2023 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2024 struct ieee80211_vif *vif)
2026 struct sk_buff *skb = data;
2027 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2028 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2030 if (vif->type != NL80211_IFTYPE_STATION)
2033 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2036 cancel_delayed_work(&arvif->connection_loss_work);
2039 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2041 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2042 IEEE80211_IFACE_ITER_NORMAL,
2043 ath10k_mac_handle_beacon_iter,
2047 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2048 struct ieee80211_vif *vif)
2050 u32 *vdev_id = data;
2051 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2052 struct ath10k *ar = arvif->ar;
2053 struct ieee80211_hw *hw = ar->hw;
2055 if (arvif->vdev_id != *vdev_id)
2061 ieee80211_beacon_loss(vif);
2063 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2064 * (done by mac80211) succeeds but beacons do not resume then it
2065 * doesn't make sense to continue operation. Queue connection loss work
2066 * which can be cancelled when beacon is received.
2068 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2069 ATH10K_CONNECTION_LOSS_HZ);
2072 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2074 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2075 IEEE80211_IFACE_ITER_NORMAL,
2076 ath10k_mac_handle_beacon_miss_iter,
2080 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2082 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2083 connection_loss_work.work);
2084 struct ieee80211_vif *vif = arvif->vif;
2089 ieee80211_connection_loss(vif);
2092 /**********************/
2093 /* Station management */
2094 /**********************/
2096 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2097 struct ieee80211_vif *vif)
2099 /* Some firmware revisions have unstable STA powersave when listen
2100 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2101 * generate NullFunc frames properly even if buffered frames have been
2102 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2103 * buffered frames. Often pinging the device from AP would simply fail.
2105 * As a workaround set it to 1.
2107 if (vif->type == NL80211_IFTYPE_STATION)
2110 return ar->hw->conf.listen_interval;
2113 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2114 struct ieee80211_vif *vif,
2115 struct ieee80211_sta *sta,
2116 struct wmi_peer_assoc_complete_arg *arg)
2118 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2121 lockdep_assert_held(&ar->conf_mutex);
2123 if (vif->type == NL80211_IFTYPE_STATION)
2124 aid = vif->bss_conf.aid;
2128 ether_addr_copy(arg->addr, sta->addr);
2129 arg->vdev_id = arvif->vdev_id;
2130 arg->peer_aid = aid;
2131 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2132 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2133 arg->peer_num_spatial_streams = 1;
2134 arg->peer_caps = vif->bss_conf.assoc_capability;
2137 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2138 struct ieee80211_vif *vif,
2139 struct ieee80211_sta *sta,
2140 struct wmi_peer_assoc_complete_arg *arg)
2142 struct ieee80211_bss_conf *info = &vif->bss_conf;
2143 struct cfg80211_chan_def def;
2144 struct cfg80211_bss *bss;
2145 const u8 *rsnie = NULL;
2146 const u8 *wpaie = NULL;
2148 lockdep_assert_held(&ar->conf_mutex);
2150 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2153 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2154 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2156 const struct cfg80211_bss_ies *ies;
2159 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2161 ies = rcu_dereference(bss->ies);
2163 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2164 WLAN_OUI_TYPE_MICROSOFT_WPA,
2168 cfg80211_put_bss(ar->hw->wiphy, bss);
2171 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2172 if (rsnie || wpaie) {
2173 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2174 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2178 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2179 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2183 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2184 ar->running_fw->fw_file.fw_features)) {
2185 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2189 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2190 struct ieee80211_vif *vif,
2191 struct ieee80211_sta *sta,
2192 struct wmi_peer_assoc_complete_arg *arg)
2194 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2195 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2196 struct cfg80211_chan_def def;
2197 const struct ieee80211_supported_band *sband;
2198 const struct ieee80211_rate *rates;
2199 enum nl80211_band band;
2204 lockdep_assert_held(&ar->conf_mutex);
2206 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2209 band = def.chan->band;
2210 sband = ar->hw->wiphy->bands[band];
2211 ratemask = sta->supp_rates[band];
2212 ratemask &= arvif->bitrate_mask.control[band].legacy;
2213 rates = sband->bitrates;
2215 rateset->num_rates = 0;
2217 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2218 if (!(ratemask & 1))
2221 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2222 rateset->rates[rateset->num_rates] = rate;
2223 rateset->num_rates++;
2228 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2232 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2233 if (ht_mcs_mask[nss])
2240 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2244 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2245 if (vht_mcs_mask[nss])
2251 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2252 struct ieee80211_vif *vif,
2253 struct ieee80211_sta *sta,
2254 struct wmi_peer_assoc_complete_arg *arg)
2256 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2257 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2258 struct cfg80211_chan_def def;
2259 enum nl80211_band band;
2260 const u8 *ht_mcs_mask;
2261 const u16 *vht_mcs_mask;
2266 lockdep_assert_held(&ar->conf_mutex);
2268 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2271 if (!ht_cap->ht_supported)
2274 band = def.chan->band;
2275 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2276 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2278 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2279 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2282 arg->peer_flags |= ar->wmi.peer_flags->ht;
2283 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2284 ht_cap->ampdu_factor)) - 1;
2286 arg->peer_mpdu_density =
2287 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2289 arg->peer_ht_caps = ht_cap->cap;
2290 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2292 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2293 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2295 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2296 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2297 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2300 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2301 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2302 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2304 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2305 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2308 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2309 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2310 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2313 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2314 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2315 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2316 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2317 arg->peer_rate_caps |= stbc;
2318 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2321 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2322 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2323 else if (ht_cap->mcs.rx_mask[1])
2324 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2326 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2327 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2328 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2329 max_nss = (i / 8) + 1;
2330 arg->peer_ht_rates.rates[n++] = i;
2334 * This is a workaround for HT-enabled STAs which break the spec
2335 * and have no HT capabilities RX mask (no HT RX MCS map).
2337 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2338 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2340 * Firmware asserts if such situation occurs.
2343 arg->peer_ht_rates.num_rates = 8;
2344 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2345 arg->peer_ht_rates.rates[i] = i;
2347 arg->peer_ht_rates.num_rates = n;
2348 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2351 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2353 arg->peer_ht_rates.num_rates,
2354 arg->peer_num_spatial_streams);
2357 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2358 struct ath10k_vif *arvif,
2359 struct ieee80211_sta *sta)
2365 lockdep_assert_held(&ar->conf_mutex);
2367 if (sta->wme && sta->uapsd_queues) {
2368 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2369 sta->uapsd_queues, sta->max_sp);
2371 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2372 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2373 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2374 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2375 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2376 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2377 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2378 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2379 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2380 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2381 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2382 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2384 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2385 max_sp = sta->max_sp;
2387 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2389 WMI_AP_PS_PEER_PARAM_UAPSD,
2392 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2393 arvif->vdev_id, ret);
2397 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2399 WMI_AP_PS_PEER_PARAM_MAX_SP,
2402 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2403 arvif->vdev_id, ret);
2407 /* TODO setup this based on STA listen interval and
2408 * beacon interval. Currently we don't know
2409 * sta->listen_interval - mac80211 patch required.
2410 * Currently use 10 seconds
2412 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2413 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2416 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2417 arvif->vdev_id, ret);
2426 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2427 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2434 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2435 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2439 idx_limit = fls(mcs_map) - 1;
2443 switch (idx_limit) {
2444 case 0: /* fall through */
2445 case 1: /* fall through */
2446 case 2: /* fall through */
2447 case 3: /* fall through */
2448 case 4: /* fall through */
2449 case 5: /* fall through */
2450 case 6: /* fall through */
2452 /* see ath10k_mac_can_set_bitrate_mask() */
2456 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2459 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2462 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2465 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2469 tx_mcs_set &= ~(0x3 << (nss * 2));
2470 tx_mcs_set |= mcs << (nss * 2);
2476 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2477 struct ieee80211_vif *vif,
2478 struct ieee80211_sta *sta,
2479 struct wmi_peer_assoc_complete_arg *arg)
2481 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2482 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2483 struct cfg80211_chan_def def;
2484 enum nl80211_band band;
2485 const u16 *vht_mcs_mask;
2487 u8 max_nss, vht_mcs;
2490 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2493 if (!vht_cap->vht_supported)
2496 band = def.chan->band;
2497 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2499 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2502 arg->peer_flags |= ar->wmi.peer_flags->vht;
2504 if (def.chan->band == NL80211_BAND_2GHZ)
2505 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2507 arg->peer_vht_caps = vht_cap->cap;
2509 ampdu_factor = (vht_cap->cap &
2510 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2511 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2513 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2514 * zero in VHT IE. Using it would result in degraded throughput.
2515 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2516 * it if VHT max_mpdu is smaller.
2518 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2519 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2520 ampdu_factor)) - 1);
2522 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2523 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2525 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2526 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2528 /* Calculate peer NSS capability from VHT capabilities if STA
2531 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2532 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2535 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2539 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2540 arg->peer_vht_rates.rx_max_rate =
2541 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2542 arg->peer_vht_rates.rx_mcs_set =
2543 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2544 arg->peer_vht_rates.tx_max_rate =
2545 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2546 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2547 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2549 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2550 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2552 if (arg->peer_vht_rates.rx_max_rate &&
2553 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2554 switch (arg->peer_vht_rates.rx_max_rate) {
2556 /* Must be 2x2 at 160Mhz is all it can do. */
2557 arg->peer_bw_rxnss_override = 2;
2560 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2561 arg->peer_bw_rxnss_override = 1;
2567 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2568 struct ieee80211_vif *vif,
2569 struct ieee80211_sta *sta,
2570 struct wmi_peer_assoc_complete_arg *arg)
2572 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2574 switch (arvif->vdev_type) {
2575 case WMI_VDEV_TYPE_AP:
2577 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2579 if (sta->wme && sta->uapsd_queues) {
2580 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2581 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2584 case WMI_VDEV_TYPE_STA:
2586 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2588 case WMI_VDEV_TYPE_IBSS:
2590 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2597 sta->addr, !!(arg->peer_flags &
2598 arvif->ar->wmi.peer_flags->qos));
2601 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2603 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2604 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2607 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2608 struct ieee80211_sta *sta)
2610 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2611 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2612 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2613 return MODE_11AC_VHT160;
2614 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2615 return MODE_11AC_VHT80_80;
2617 /* not sure if this is a valid case? */
2618 return MODE_11AC_VHT160;
2622 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2623 return MODE_11AC_VHT80;
2625 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2626 return MODE_11AC_VHT40;
2628 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2629 return MODE_11AC_VHT20;
2631 return MODE_UNKNOWN;
2634 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2635 struct ieee80211_vif *vif,
2636 struct ieee80211_sta *sta,
2637 struct wmi_peer_assoc_complete_arg *arg)
2639 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2640 struct cfg80211_chan_def def;
2641 enum nl80211_band band;
2642 const u8 *ht_mcs_mask;
2643 const u16 *vht_mcs_mask;
2644 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2646 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2649 band = def.chan->band;
2650 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2651 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2654 case NL80211_BAND_2GHZ:
2655 if (sta->vht_cap.vht_supported &&
2656 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2657 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2658 phymode = MODE_11AC_VHT40;
2660 phymode = MODE_11AC_VHT20;
2661 } else if (sta->ht_cap.ht_supported &&
2662 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2663 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2664 phymode = MODE_11NG_HT40;
2666 phymode = MODE_11NG_HT20;
2667 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2674 case NL80211_BAND_5GHZ:
2678 if (sta->vht_cap.vht_supported &&
2679 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2680 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2681 } else if (sta->ht_cap.ht_supported &&
2682 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2683 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2684 phymode = MODE_11NA_HT40;
2686 phymode = MODE_11NA_HT20;
2696 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2697 sta->addr, ath10k_wmi_phymode_str(phymode));
2699 arg->peer_phymode = phymode;
2700 WARN_ON(phymode == MODE_UNKNOWN);
2703 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2704 struct ieee80211_vif *vif,
2705 struct ieee80211_sta *sta,
2706 struct wmi_peer_assoc_complete_arg *arg)
2708 lockdep_assert_held(&ar->conf_mutex);
2710 memset(arg, 0, sizeof(*arg));
2712 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2713 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2714 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2715 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2716 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2717 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2718 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2723 static const u32 ath10k_smps_map[] = {
2724 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2725 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2726 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2727 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2730 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2732 const struct ieee80211_sta_ht_cap *ht_cap)
2736 if (!ht_cap->ht_supported)
2739 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2740 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2742 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2745 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2746 WMI_PEER_SMPS_STATE,
2747 ath10k_smps_map[smps]);
2750 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2751 struct ieee80211_vif *vif,
2752 struct ieee80211_sta_vht_cap vht_cap)
2754 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2759 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2762 if (!(ar->vht_cap_info &
2763 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2764 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2765 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2766 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2769 param = ar->wmi.vdev_param->txbf;
2772 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2775 /* The following logic is correct. If a remote STA advertises support
2776 * for being a beamformer then we should enable us being a beamformee.
2779 if (ar->vht_cap_info &
2780 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2781 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2782 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2783 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2785 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2786 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2789 if (ar->vht_cap_info &
2790 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2791 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2792 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2793 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2795 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2796 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2799 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2800 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2802 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2803 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2805 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2807 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2815 /* can be called only in mac80211 callbacks due to `key_count` usage */
2816 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2817 struct ieee80211_vif *vif,
2818 struct ieee80211_bss_conf *bss_conf)
2820 struct ath10k *ar = hw->priv;
2821 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2822 struct ieee80211_sta_ht_cap ht_cap;
2823 struct ieee80211_sta_vht_cap vht_cap;
2824 struct wmi_peer_assoc_complete_arg peer_arg;
2825 struct ieee80211_sta *ap_sta;
2828 lockdep_assert_held(&ar->conf_mutex);
2830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2831 arvif->vdev_id, arvif->bssid, arvif->aid);
2835 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2837 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2838 bss_conf->bssid, arvif->vdev_id);
2843 /* ap_sta must be accessed only within rcu section which must be left
2844 * before calling ath10k_setup_peer_smps() which might sleep.
2846 ht_cap = ap_sta->ht_cap;
2847 vht_cap = ap_sta->vht_cap;
2849 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2851 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2852 bss_conf->bssid, arvif->vdev_id, ret);
2859 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2861 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2862 bss_conf->bssid, arvif->vdev_id, ret);
2866 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2868 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2869 arvif->vdev_id, ret);
2873 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2875 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2876 arvif->vdev_id, bss_conf->bssid, ret);
2880 ath10k_dbg(ar, ATH10K_DBG_MAC,
2881 "mac vdev %d up (associated) bssid %pM aid %d\n",
2882 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2884 WARN_ON(arvif->is_up);
2886 arvif->aid = bss_conf->aid;
2887 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2889 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2891 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2892 arvif->vdev_id, ret);
2896 arvif->is_up = true;
2898 /* Workaround: Some firmware revisions (tested with qca6174
2899 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2900 * poked with peer param command.
2902 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2903 WMI_PEER_DUMMY_VAR, 1);
2905 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2906 arvif->bssid, arvif->vdev_id, ret);
2911 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2912 struct ieee80211_vif *vif)
2914 struct ath10k *ar = hw->priv;
2915 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2916 struct ieee80211_sta_vht_cap vht_cap = {};
2919 lockdep_assert_held(&ar->conf_mutex);
2921 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2922 arvif->vdev_id, arvif->bssid);
2924 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2926 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2927 arvif->vdev_id, ret);
2929 arvif->def_wep_key_idx = -1;
2931 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2933 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2934 arvif->vdev_id, ret);
2938 arvif->is_up = false;
2940 cancel_delayed_work_sync(&arvif->connection_loss_work);
2943 static int ath10k_station_assoc(struct ath10k *ar,
2944 struct ieee80211_vif *vif,
2945 struct ieee80211_sta *sta,
2948 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2949 struct wmi_peer_assoc_complete_arg peer_arg;
2952 lockdep_assert_held(&ar->conf_mutex);
2954 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2956 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2957 sta->addr, arvif->vdev_id, ret);
2961 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2963 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2964 sta->addr, arvif->vdev_id, ret);
2968 /* Re-assoc is run only to update supported rates for given station. It
2969 * doesn't make much sense to reconfigure the peer completely.
2972 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2975 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2976 arvif->vdev_id, ret);
2980 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2982 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2983 sta->addr, arvif->vdev_id, ret);
2988 arvif->num_legacy_stations++;
2989 ret = ath10k_recalc_rtscts_prot(arvif);
2991 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2992 arvif->vdev_id, ret);
2997 /* Plumb cached keys only for static WEP */
2998 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
2999 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
3001 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
3002 arvif->vdev_id, ret);
3011 static int ath10k_station_disassoc(struct ath10k *ar,
3012 struct ieee80211_vif *vif,
3013 struct ieee80211_sta *sta)
3015 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3018 lockdep_assert_held(&ar->conf_mutex);
3021 arvif->num_legacy_stations--;
3022 ret = ath10k_recalc_rtscts_prot(arvif);
3024 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3025 arvif->vdev_id, ret);
3030 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3032 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3033 arvif->vdev_id, ret);
3044 static int ath10k_update_channel_list(struct ath10k *ar)
3046 struct ieee80211_hw *hw = ar->hw;
3047 struct ieee80211_supported_band **bands;
3048 enum nl80211_band band;
3049 struct ieee80211_channel *channel;
3050 struct wmi_scan_chan_list_arg arg = {0};
3051 struct wmi_channel_arg *ch;
3057 lockdep_assert_held(&ar->conf_mutex);
3059 bands = hw->wiphy->bands;
3060 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3064 for (i = 0; i < bands[band]->n_channels; i++) {
3065 if (bands[band]->channels[i].flags &
3066 IEEE80211_CHAN_DISABLED)
3073 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3074 arg.channels = kzalloc(len, GFP_KERNEL);
3079 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3083 for (i = 0; i < bands[band]->n_channels; i++) {
3084 channel = &bands[band]->channels[i];
3086 if (channel->flags & IEEE80211_CHAN_DISABLED)
3089 ch->allow_ht = true;
3091 /* FIXME: when should we really allow VHT? */
3092 ch->allow_vht = true;
3095 !(channel->flags & IEEE80211_CHAN_NO_IR);
3098 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3101 !!(channel->flags & IEEE80211_CHAN_RADAR);
3103 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3104 ch->passive = passive;
3106 /* the firmware is ignoring the "radar" flag of the
3107 * channel and is scanning actively using Probe Requests
3108 * on "Radar detection"/DFS channels which are not
3109 * marked as "available"
3111 ch->passive |= ch->chan_radar;
3113 ch->freq = channel->center_freq;
3114 ch->band_center_freq1 = channel->center_freq;
3116 ch->max_power = channel->max_power * 2;
3117 ch->max_reg_power = channel->max_reg_power * 2;
3118 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3119 ch->reg_class_id = 0; /* FIXME */
3121 /* FIXME: why use only legacy modes, why not any
3122 * HT/VHT modes? Would that even make any
3125 if (channel->band == NL80211_BAND_2GHZ)
3126 ch->mode = MODE_11G;
3128 ch->mode = MODE_11A;
3130 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3133 ath10k_dbg(ar, ATH10K_DBG_WMI,
3134 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3135 ch - arg.channels, arg.n_channels,
3136 ch->freq, ch->max_power, ch->max_reg_power,
3137 ch->max_antenna_gain, ch->mode);
3143 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3144 kfree(arg.channels);
3149 static enum wmi_dfs_region
3150 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3152 switch (dfs_region) {
3153 case NL80211_DFS_UNSET:
3154 return WMI_UNINIT_DFS_DOMAIN;
3155 case NL80211_DFS_FCC:
3156 return WMI_FCC_DFS_DOMAIN;
3157 case NL80211_DFS_ETSI:
3158 return WMI_ETSI_DFS_DOMAIN;
3159 case NL80211_DFS_JP:
3160 return WMI_MKK4_DFS_DOMAIN;
3162 return WMI_UNINIT_DFS_DOMAIN;
3165 static void ath10k_regd_update(struct ath10k *ar)
3167 struct reg_dmn_pair_mapping *regpair;
3169 enum wmi_dfs_region wmi_dfs_reg;
3170 enum nl80211_dfs_regions nl_dfs_reg;
3172 lockdep_assert_held(&ar->conf_mutex);
3174 ret = ath10k_update_channel_list(ar);
3176 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3178 regpair = ar->ath_common.regulatory.regpair;
3180 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3181 nl_dfs_reg = ar->dfs_detector->region;
3182 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3184 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3187 /* Target allows setting up per-band regdomain but ath_common provides
3188 * a combined one only
3190 ret = ath10k_wmi_pdev_set_regdomain(ar,
3191 regpair->reg_domain,
3192 regpair->reg_domain, /* 2ghz */
3193 regpair->reg_domain, /* 5ghz */
3194 regpair->reg_2ghz_ctl,
3195 regpair->reg_5ghz_ctl,
3198 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3201 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3202 struct ieee80211_supported_band *band)
3206 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3207 for (i = 0; i < band->n_channels; i++) {
3208 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3209 band->channels[i].center_freq > ar->high_5ghz_chan)
3210 band->channels[i].flags |=
3211 IEEE80211_CHAN_DISABLED;
3216 static void ath10k_reg_notifier(struct wiphy *wiphy,
3217 struct regulatory_request *request)
3219 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3220 struct ath10k *ar = hw->priv;
3223 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3225 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3226 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3227 request->dfs_region);
3228 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3229 request->dfs_region);
3231 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3232 request->dfs_region);
3235 mutex_lock(&ar->conf_mutex);
3236 if (ar->state == ATH10K_STATE_ON)
3237 ath10k_regd_update(ar);
3238 mutex_unlock(&ar->conf_mutex);
3240 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3241 ath10k_mac_update_channel_list(ar,
3242 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3245 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3247 spin_lock_bh(&ar->data_lock);
3248 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3249 spin_unlock_bh(&ar->data_lock);
3251 cancel_work_sync(&ar->radar_confirmation_work);
3258 enum ath10k_mac_tx_path {
3260 ATH10K_MAC_TX_HTT_MGMT,
3261 ATH10K_MAC_TX_WMI_MGMT,
3262 ATH10K_MAC_TX_UNKNOWN,
3265 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3267 lockdep_assert_held(&ar->htt.tx_lock);
3269 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3270 ar->tx_paused |= BIT(reason);
3271 ieee80211_stop_queues(ar->hw);
3274 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3275 struct ieee80211_vif *vif)
3277 struct ath10k *ar = data;
3278 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3280 if (arvif->tx_paused)
3283 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3286 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3288 lockdep_assert_held(&ar->htt.tx_lock);
3290 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3291 ar->tx_paused &= ~BIT(reason);
3296 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3297 IEEE80211_IFACE_ITER_RESUME_ALL,
3298 ath10k_mac_tx_unlock_iter,
3301 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3304 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3306 struct ath10k *ar = arvif->ar;
3308 lockdep_assert_held(&ar->htt.tx_lock);
3310 WARN_ON(reason >= BITS_PER_LONG);
3311 arvif->tx_paused |= BIT(reason);
3312 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3315 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3317 struct ath10k *ar = arvif->ar;
3319 lockdep_assert_held(&ar->htt.tx_lock);
3321 WARN_ON(reason >= BITS_PER_LONG);
3322 arvif->tx_paused &= ~BIT(reason);
3327 if (arvif->tx_paused)
3330 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3333 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3334 enum wmi_tlv_tx_pause_id pause_id,
3335 enum wmi_tlv_tx_pause_action action)
3337 struct ath10k *ar = arvif->ar;
3339 lockdep_assert_held(&ar->htt.tx_lock);
3342 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3343 ath10k_mac_vif_tx_lock(arvif, pause_id);
3345 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3346 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3349 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3350 "received unknown tx pause action %d on vdev %i, ignoring\n",
3351 action, arvif->vdev_id);
3356 struct ath10k_mac_tx_pause {
3358 enum wmi_tlv_tx_pause_id pause_id;
3359 enum wmi_tlv_tx_pause_action action;
3362 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3363 struct ieee80211_vif *vif)
3365 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3366 struct ath10k_mac_tx_pause *arg = data;
3368 if (arvif->vdev_id != arg->vdev_id)
3371 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3374 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3375 enum wmi_tlv_tx_pause_id pause_id,
3376 enum wmi_tlv_tx_pause_action action)
3378 struct ath10k_mac_tx_pause arg = {
3380 .pause_id = pause_id,
3384 spin_lock_bh(&ar->htt.tx_lock);
3385 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3386 IEEE80211_IFACE_ITER_RESUME_ALL,
3387 ath10k_mac_handle_tx_pause_iter,
3389 spin_unlock_bh(&ar->htt.tx_lock);
3392 static enum ath10k_hw_txrx_mode
3393 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3394 struct ieee80211_vif *vif,
3395 struct ieee80211_sta *sta,
3396 struct sk_buff *skb)
3398 const struct ieee80211_hdr *hdr = (void *)skb->data;
3399 __le16 fc = hdr->frame_control;
3401 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3402 return ATH10K_HW_TXRX_RAW;
3404 if (ieee80211_is_mgmt(fc))
3405 return ATH10K_HW_TXRX_MGMT;
3409 * NullFunc frames are mostly used to ping if a client or AP are still
3410 * reachable and responsive. This implies tx status reports must be
3411 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3412 * come to a conclusion that the other end disappeared and tear down
3413 * BSS connection or it can never disconnect from BSS/client (which is
3416 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3417 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3418 * which seems to deliver correct tx reports for NullFunc frames. The
3419 * downside of using it is it ignores client powersave state so it can
3420 * end up disconnecting sleeping clients in AP mode. It should fix STA
3421 * mode though because AP don't sleep.
3423 if (ar->htt.target_version_major < 3 &&
3424 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3425 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3426 ar->running_fw->fw_file.fw_features))
3427 return ATH10K_HW_TXRX_MGMT;
3431 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3432 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3433 * to work with Ethernet txmode so use it.
3435 * FIXME: Check if raw mode works with TDLS.
3437 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3438 return ATH10K_HW_TXRX_ETHERNET;
3440 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3441 return ATH10K_HW_TXRX_RAW;
3443 return ATH10K_HW_TXRX_NATIVE_WIFI;
3446 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3447 struct sk_buff *skb)
3449 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3450 const struct ieee80211_hdr *hdr = (void *)skb->data;
3451 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3452 IEEE80211_TX_CTL_INJECTED;
3454 if (!ieee80211_has_protected(hdr->frame_control))
3457 if ((info->flags & mask) == mask)
3461 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3466 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3467 * Control in the header.
3469 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3471 struct ieee80211_hdr *hdr = (void *)skb->data;
3472 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3475 if (!ieee80211_is_data_qos(hdr->frame_control))
3478 qos_ctl = ieee80211_get_qos_ctl(hdr);
3479 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3480 skb->data, (void *)qos_ctl - (void *)skb->data);
3481 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3483 /* Some firmware revisions don't handle sending QoS NullFunc well.
3484 * These frames are mainly used for CQM purposes so it doesn't really
3485 * matter whether QoS NullFunc or NullFunc are sent.
3487 hdr = (void *)skb->data;
3488 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3489 cb->flags &= ~ATH10K_SKB_F_QOS;
3491 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3494 static void ath10k_tx_h_8023(struct sk_buff *skb)
3496 struct ieee80211_hdr *hdr;
3497 struct rfc1042_hdr *rfc1042;
3504 hdr = (void *)skb->data;
3505 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3506 rfc1042 = (void *)skb->data + hdrlen;
3508 ether_addr_copy(da, ieee80211_get_DA(hdr));
3509 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3510 type = rfc1042->snap_type;
3512 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3513 skb_push(skb, sizeof(*eth));
3515 eth = (void *)skb->data;
3516 ether_addr_copy(eth->h_dest, da);
3517 ether_addr_copy(eth->h_source, sa);
3518 eth->h_proto = type;
3521 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3522 struct ieee80211_vif *vif,
3523 struct sk_buff *skb)
3525 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3526 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3528 /* This is case only for P2P_GO */
3529 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3532 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3533 spin_lock_bh(&ar->data_lock);
3534 if (arvif->u.ap.noa_data)
3535 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3537 skb_put_data(skb, arvif->u.ap.noa_data,
3538 arvif->u.ap.noa_len);
3539 spin_unlock_bh(&ar->data_lock);
3543 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3544 struct ieee80211_vif *vif,
3545 struct ieee80211_txq *txq,
3546 struct sk_buff *skb)
3548 struct ieee80211_hdr *hdr = (void *)skb->data;
3549 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3552 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3553 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3555 if (ieee80211_is_mgmt(hdr->frame_control))
3556 cb->flags |= ATH10K_SKB_F_MGMT;
3558 if (ieee80211_is_data_qos(hdr->frame_control))
3559 cb->flags |= ATH10K_SKB_F_QOS;
3565 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3567 /* FIXME: Not really sure since when the behaviour changed. At some
3568 * point new firmware stopped requiring creation of peer entries for
3569 * offchannel tx (and actually creating them causes issues with wmi-htc
3570 * tx credit replenishment and reliability). Assuming it's at least 3.4
3571 * because that's when the `freq` was introduced to TX_FRM HTT command.
3573 return (ar->htt.target_version_major >= 3 &&
3574 ar->htt.target_version_minor >= 4 &&
3575 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3578 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3580 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3583 spin_lock_bh(&ar->data_lock);
3585 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3586 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3591 __skb_queue_tail(q, skb);
3592 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3595 spin_unlock_bh(&ar->data_lock);
3600 static enum ath10k_mac_tx_path
3601 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3602 struct sk_buff *skb,
3603 enum ath10k_hw_txrx_mode txmode)
3606 case ATH10K_HW_TXRX_RAW:
3607 case ATH10K_HW_TXRX_NATIVE_WIFI:
3608 case ATH10K_HW_TXRX_ETHERNET:
3609 return ATH10K_MAC_TX_HTT;
3610 case ATH10K_HW_TXRX_MGMT:
3611 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3612 ar->running_fw->fw_file.fw_features) ||
3613 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3615 return ATH10K_MAC_TX_WMI_MGMT;
3616 else if (ar->htt.target_version_major >= 3)
3617 return ATH10K_MAC_TX_HTT;
3619 return ATH10K_MAC_TX_HTT_MGMT;
3622 return ATH10K_MAC_TX_UNKNOWN;
3625 static int ath10k_mac_tx_submit(struct ath10k *ar,
3626 enum ath10k_hw_txrx_mode txmode,
3627 enum ath10k_mac_tx_path txpath,
3628 struct sk_buff *skb)
3630 struct ath10k_htt *htt = &ar->htt;
3634 case ATH10K_MAC_TX_HTT:
3635 ret = ath10k_htt_tx(htt, txmode, skb);
3637 case ATH10K_MAC_TX_HTT_MGMT:
3638 ret = ath10k_htt_mgmt_tx(htt, skb);
3640 case ATH10K_MAC_TX_WMI_MGMT:
3641 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3643 case ATH10K_MAC_TX_UNKNOWN:
3650 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3652 ieee80211_free_txskb(ar->hw, skb);
3658 /* This function consumes the sk_buff regardless of return value as far as
3659 * caller is concerned so no freeing is necessary afterwards.
3661 static int ath10k_mac_tx(struct ath10k *ar,
3662 struct ieee80211_vif *vif,
3663 enum ath10k_hw_txrx_mode txmode,
3664 enum ath10k_mac_tx_path txpath,
3665 struct sk_buff *skb)
3667 struct ieee80211_hw *hw = ar->hw;
3668 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3671 /* We should disable CCK RATE due to P2P */
3672 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3673 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3676 case ATH10K_HW_TXRX_MGMT:
3677 case ATH10K_HW_TXRX_NATIVE_WIFI:
3678 ath10k_tx_h_nwifi(hw, skb);
3679 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3680 ath10k_tx_h_seq_no(vif, skb);
3682 case ATH10K_HW_TXRX_ETHERNET:
3683 ath10k_tx_h_8023(skb);
3685 case ATH10K_HW_TXRX_RAW:
3686 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3688 ieee80211_free_txskb(hw, skb);
3693 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3694 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3695 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3698 skb_queue_tail(&ar->offchan_tx_queue, skb);
3699 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3704 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3706 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3713 void ath10k_offchan_tx_purge(struct ath10k *ar)
3715 struct sk_buff *skb;
3718 skb = skb_dequeue(&ar->offchan_tx_queue);
3722 ieee80211_free_txskb(ar->hw, skb);
3726 void ath10k_offchan_tx_work(struct work_struct *work)
3728 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3729 struct ath10k_peer *peer;
3730 struct ath10k_vif *arvif;
3731 enum ath10k_hw_txrx_mode txmode;
3732 enum ath10k_mac_tx_path txpath;
3733 struct ieee80211_hdr *hdr;
3734 struct ieee80211_vif *vif;
3735 struct ieee80211_sta *sta;
3736 struct sk_buff *skb;
3737 const u8 *peer_addr;
3740 unsigned long time_left;
3741 bool tmp_peer_created = false;
3743 /* FW requirement: We must create a peer before FW will send out
3744 * an offchannel frame. Otherwise the frame will be stuck and
3745 * never transmitted. We delete the peer upon tx completion.
3746 * It is unlikely that a peer for offchannel tx will already be
3747 * present. However it may be in some rare cases so account for that.
3748 * Otherwise we might remove a legitimate peer and break stuff.
3752 skb = skb_dequeue(&ar->offchan_tx_queue);
3756 mutex_lock(&ar->conf_mutex);
3758 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3761 hdr = (struct ieee80211_hdr *)skb->data;
3762 peer_addr = ieee80211_get_DA(hdr);
3764 spin_lock_bh(&ar->data_lock);
3765 vdev_id = ar->scan.vdev_id;
3766 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3767 spin_unlock_bh(&ar->data_lock);
3770 /* FIXME: should this use ath10k_warn()? */
3771 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3772 peer_addr, vdev_id);
3775 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3777 WMI_PEER_TYPE_DEFAULT);
3779 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3780 peer_addr, vdev_id, ret);
3781 tmp_peer_created = (ret == 0);
3784 spin_lock_bh(&ar->data_lock);
3785 reinit_completion(&ar->offchan_tx_completed);
3786 ar->offchan_tx_skb = skb;
3787 spin_unlock_bh(&ar->data_lock);
3789 /* It's safe to access vif and sta - conf_mutex guarantees that
3790 * sta_state() and remove_interface() are locked exclusively
3791 * out wrt to this offchannel worker.
3793 arvif = ath10k_get_arvif(ar, vdev_id);
3796 sta = ieee80211_find_sta(vif, peer_addr);
3802 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3803 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3805 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
3807 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3813 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3815 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3818 if (!peer && tmp_peer_created) {
3819 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3821 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3822 peer_addr, vdev_id, ret);
3825 mutex_unlock(&ar->conf_mutex);
3829 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3831 struct sk_buff *skb;
3834 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3838 ieee80211_free_txskb(ar->hw, skb);
3842 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3844 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3845 struct sk_buff *skb;
3850 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3854 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
3855 ar->running_fw->fw_file.fw_features)) {
3856 paddr = dma_map_single(ar->dev, skb->data,
3857 skb->len, DMA_TO_DEVICE);
3860 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3862 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3864 dma_unmap_single(ar->dev, paddr, skb->len,
3866 ieee80211_free_txskb(ar->hw, skb);
3869 ret = ath10k_wmi_mgmt_tx(ar, skb);
3871 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3873 ieee80211_free_txskb(ar->hw, skb);
3879 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3881 struct ath10k_txq *artxq;
3886 artxq = (void *)txq->drv_priv;
3887 INIT_LIST_HEAD(&artxq->list);
3890 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3892 struct ath10k_txq *artxq;
3893 struct ath10k_skb_cb *cb;
3894 struct sk_buff *msdu;
3900 artxq = (void *)txq->drv_priv;
3901 spin_lock_bh(&ar->txqs_lock);
3902 if (!list_empty(&artxq->list))
3903 list_del_init(&artxq->list);
3904 spin_unlock_bh(&ar->txqs_lock);
3906 spin_lock_bh(&ar->htt.tx_lock);
3907 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3908 cb = ATH10K_SKB_CB(msdu);
3912 spin_unlock_bh(&ar->htt.tx_lock);
3915 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3919 struct ath10k_peer *peer;
3921 lockdep_assert_held(&ar->data_lock);
3923 peer = ar->peer_map[peer_id];
3931 return peer->sta->txq[tid];
3933 return peer->vif->txq;
3938 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3939 struct ieee80211_txq *txq)
3941 struct ath10k *ar = hw->priv;
3942 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3944 /* No need to get locks */
3946 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3949 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3952 if (artxq->num_fw_queued < artxq->num_push_allowed)
3958 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3959 struct ieee80211_txq *txq)
3961 struct ath10k *ar = hw->priv;
3962 struct ath10k_htt *htt = &ar->htt;
3963 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3964 struct ieee80211_vif *vif = txq->vif;
3965 struct ieee80211_sta *sta = txq->sta;
3966 enum ath10k_hw_txrx_mode txmode;
3967 enum ath10k_mac_tx_path txpath;
3968 struct sk_buff *skb;
3969 struct ieee80211_hdr *hdr;
3971 bool is_mgmt, is_presp;
3974 spin_lock_bh(&ar->htt.tx_lock);
3975 ret = ath10k_htt_tx_inc_pending(htt);
3976 spin_unlock_bh(&ar->htt.tx_lock);
3981 skb = ieee80211_tx_dequeue(hw, txq);
3983 spin_lock_bh(&ar->htt.tx_lock);
3984 ath10k_htt_tx_dec_pending(htt);
3985 spin_unlock_bh(&ar->htt.tx_lock);
3990 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3993 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3994 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3995 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3998 hdr = (struct ieee80211_hdr *)skb->data;
3999 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4001 spin_lock_bh(&ar->htt.tx_lock);
4002 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4005 ath10k_htt_tx_dec_pending(htt);
4006 spin_unlock_bh(&ar->htt.tx_lock);
4009 spin_unlock_bh(&ar->htt.tx_lock);
4012 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4013 if (unlikely(ret)) {
4014 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4016 spin_lock_bh(&ar->htt.tx_lock);
4017 ath10k_htt_tx_dec_pending(htt);
4019 ath10k_htt_tx_mgmt_dec_pending(htt);
4020 spin_unlock_bh(&ar->htt.tx_lock);
4025 spin_lock_bh(&ar->htt.tx_lock);
4026 artxq->num_fw_queued++;
4027 spin_unlock_bh(&ar->htt.tx_lock);
4032 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4034 struct ieee80211_hw *hw = ar->hw;
4035 struct ieee80211_txq *txq;
4036 struct ath10k_txq *artxq;
4037 struct ath10k_txq *last;
4041 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4044 spin_lock_bh(&ar->txqs_lock);
4047 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
4048 while (!list_empty(&ar->txqs)) {
4049 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4050 txq = container_of((void *)artxq, struct ieee80211_txq,
4053 /* Prevent aggressive sta/tid taking over tx queue */
4054 max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE;
4056 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
4057 ret = ath10k_mac_tx_push_txq(hw, txq);
4062 list_del_init(&artxq->list);
4064 list_add_tail(&artxq->list, &ar->txqs);
4066 ath10k_htt_tx_txq_update(hw, txq);
4068 if (artxq == last || (ret < 0 && ret != -ENOENT))
4073 spin_unlock_bh(&ar->txqs_lock);
4075 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4081 void __ath10k_scan_finish(struct ath10k *ar)
4083 lockdep_assert_held(&ar->data_lock);
4085 switch (ar->scan.state) {
4086 case ATH10K_SCAN_IDLE:
4088 case ATH10K_SCAN_RUNNING:
4089 case ATH10K_SCAN_ABORTING:
4090 if (!ar->scan.is_roc) {
4091 struct cfg80211_scan_info info = {
4092 .aborted = (ar->scan.state ==
4093 ATH10K_SCAN_ABORTING),
4096 ieee80211_scan_completed(ar->hw, &info);
4097 } else if (ar->scan.roc_notify) {
4098 ieee80211_remain_on_channel_expired(ar->hw);
4101 case ATH10K_SCAN_STARTING:
4102 ar->scan.state = ATH10K_SCAN_IDLE;
4103 ar->scan_channel = NULL;
4104 ar->scan.roc_freq = 0;
4105 ath10k_offchan_tx_purge(ar);
4106 cancel_delayed_work(&ar->scan.timeout);
4107 complete(&ar->scan.completed);
4112 void ath10k_scan_finish(struct ath10k *ar)
4114 spin_lock_bh(&ar->data_lock);
4115 __ath10k_scan_finish(ar);
4116 spin_unlock_bh(&ar->data_lock);
4119 static int ath10k_scan_stop(struct ath10k *ar)
4121 struct wmi_stop_scan_arg arg = {
4122 .req_id = 1, /* FIXME */
4123 .req_type = WMI_SCAN_STOP_ONE,
4124 .u.scan_id = ATH10K_SCAN_ID,
4128 lockdep_assert_held(&ar->conf_mutex);
4130 ret = ath10k_wmi_stop_scan(ar, &arg);
4132 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4136 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4138 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4140 } else if (ret > 0) {
4145 /* Scan state should be updated upon scan completion but in case
4146 * firmware fails to deliver the event (for whatever reason) it is
4147 * desired to clean up scan state anyway. Firmware may have just
4148 * dropped the scan completion event delivery due to transport pipe
4149 * being overflown with data and/or it can recover on its own before
4150 * next scan request is submitted.
4152 spin_lock_bh(&ar->data_lock);
4153 if (ar->scan.state != ATH10K_SCAN_IDLE)
4154 __ath10k_scan_finish(ar);
4155 spin_unlock_bh(&ar->data_lock);
4160 static void ath10k_scan_abort(struct ath10k *ar)
4164 lockdep_assert_held(&ar->conf_mutex);
4166 spin_lock_bh(&ar->data_lock);
4168 switch (ar->scan.state) {
4169 case ATH10K_SCAN_IDLE:
4170 /* This can happen if timeout worker kicked in and called
4171 * abortion while scan completion was being processed.
4174 case ATH10K_SCAN_STARTING:
4175 case ATH10K_SCAN_ABORTING:
4176 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4177 ath10k_scan_state_str(ar->scan.state),
4180 case ATH10K_SCAN_RUNNING:
4181 ar->scan.state = ATH10K_SCAN_ABORTING;
4182 spin_unlock_bh(&ar->data_lock);
4184 ret = ath10k_scan_stop(ar);
4186 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4188 spin_lock_bh(&ar->data_lock);
4192 spin_unlock_bh(&ar->data_lock);
4195 void ath10k_scan_timeout_work(struct work_struct *work)
4197 struct ath10k *ar = container_of(work, struct ath10k,
4200 mutex_lock(&ar->conf_mutex);
4201 ath10k_scan_abort(ar);
4202 mutex_unlock(&ar->conf_mutex);
4205 static int ath10k_start_scan(struct ath10k *ar,
4206 const struct wmi_start_scan_arg *arg)
4210 lockdep_assert_held(&ar->conf_mutex);
4212 ret = ath10k_wmi_start_scan(ar, arg);
4216 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4218 ret = ath10k_scan_stop(ar);
4220 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4225 /* If we failed to start the scan, return error code at
4226 * this point. This is probably due to some issue in the
4227 * firmware, but no need to wedge the driver due to that...
4229 spin_lock_bh(&ar->data_lock);
4230 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4231 spin_unlock_bh(&ar->data_lock);
4234 spin_unlock_bh(&ar->data_lock);
4239 /**********************/
4240 /* mac80211 callbacks */
4241 /**********************/
4243 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4244 struct ieee80211_tx_control *control,
4245 struct sk_buff *skb)
4247 struct ath10k *ar = hw->priv;
4248 struct ath10k_htt *htt = &ar->htt;
4249 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4250 struct ieee80211_vif *vif = info->control.vif;
4251 struct ieee80211_sta *sta = control->sta;
4252 struct ieee80211_txq *txq = NULL;
4253 struct ieee80211_hdr *hdr = (void *)skb->data;
4254 enum ath10k_hw_txrx_mode txmode;
4255 enum ath10k_mac_tx_path txpath;
4261 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4263 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4264 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4265 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4266 txpath == ATH10K_MAC_TX_HTT_MGMT);
4267 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4270 spin_lock_bh(&ar->htt.tx_lock);
4271 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4273 ret = ath10k_htt_tx_inc_pending(htt);
4275 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4277 spin_unlock_bh(&ar->htt.tx_lock);
4278 ieee80211_free_txskb(ar->hw, skb);
4282 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4284 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4286 ath10k_htt_tx_dec_pending(htt);
4287 spin_unlock_bh(&ar->htt.tx_lock);
4288 ieee80211_free_txskb(ar->hw, skb);
4291 spin_unlock_bh(&ar->htt.tx_lock);
4294 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4296 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4298 spin_lock_bh(&ar->htt.tx_lock);
4299 ath10k_htt_tx_dec_pending(htt);
4301 ath10k_htt_tx_mgmt_dec_pending(htt);
4302 spin_unlock_bh(&ar->htt.tx_lock);
4308 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4309 struct ieee80211_txq *txq)
4311 struct ath10k *ar = hw->priv;
4312 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4313 struct ieee80211_txq *f_txq;
4314 struct ath10k_txq *f_artxq;
4316 int max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE;
4318 spin_lock_bh(&ar->txqs_lock);
4319 if (list_empty(&artxq->list))
4320 list_add_tail(&artxq->list, &ar->txqs);
4322 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4323 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4324 list_del_init(&f_artxq->list);
4326 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4327 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4332 list_add_tail(&f_artxq->list, &ar->txqs);
4333 spin_unlock_bh(&ar->txqs_lock);
4335 ath10k_htt_tx_txq_update(hw, f_txq);
4336 ath10k_htt_tx_txq_update(hw, txq);
4339 /* Must not be called with conf_mutex held as workers can use that also. */
4340 void ath10k_drain_tx(struct ath10k *ar)
4342 /* make sure rcu-protected mac80211 tx path itself is drained */
4345 ath10k_offchan_tx_purge(ar);
4346 ath10k_mgmt_over_wmi_tx_purge(ar);
4348 cancel_work_sync(&ar->offchan_tx_work);
4349 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4352 void ath10k_halt(struct ath10k *ar)
4354 struct ath10k_vif *arvif;
4356 lockdep_assert_held(&ar->conf_mutex);
4358 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4359 ar->filter_flags = 0;
4360 ar->monitor = false;
4361 ar->monitor_arvif = NULL;
4363 if (ar->monitor_started)
4364 ath10k_monitor_stop(ar);
4366 ar->monitor_started = false;
4369 ath10k_scan_finish(ar);
4370 ath10k_peer_cleanup_all(ar);
4371 ath10k_stop_radar_confirmation(ar);
4372 ath10k_core_stop(ar);
4373 ath10k_hif_power_down(ar);
4375 spin_lock_bh(&ar->data_lock);
4376 list_for_each_entry(arvif, &ar->arvifs, list)
4377 ath10k_mac_vif_beacon_cleanup(arvif);
4378 spin_unlock_bh(&ar->data_lock);
4381 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4383 struct ath10k *ar = hw->priv;
4385 mutex_lock(&ar->conf_mutex);
4387 *tx_ant = ar->cfg_tx_chainmask;
4388 *rx_ant = ar->cfg_rx_chainmask;
4390 mutex_unlock(&ar->conf_mutex);
4395 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4397 /* It is not clear that allowing gaps in chainmask
4398 * is helpful. Probably it will not do what user
4399 * is hoping for, so warn in that case.
4401 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4404 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4408 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4410 int nsts = ar->vht_cap_info;
4412 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4413 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4415 /* If firmware does not deliver to host number of space-time
4416 * streams supported, assume it support up to 4 BF STS and return
4417 * the value for VHT CAP: nsts-1)
4425 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4427 int sound_dim = ar->vht_cap_info;
4429 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4430 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4432 /* If the sounding dimension is not advertised by the firmware,
4433 * let's use a default value of 1
4441 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4443 struct ieee80211_sta_vht_cap vht_cap = {0};
4444 struct ath10k_hw_params *hw = &ar->hw_params;
4449 vht_cap.vht_supported = 1;
4450 vht_cap.cap = ar->vht_cap_info;
4452 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4453 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4454 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4455 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4456 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4461 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4462 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4463 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4464 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4465 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4470 /* Currently the firmware seems to be buggy, don't enable 80+80
4471 * mode until that's resolved.
4473 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4474 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4475 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4478 for (i = 0; i < 8; i++) {
4479 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4480 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4482 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4485 if (ar->cfg_tx_chainmask <= 1)
4486 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4488 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4489 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4491 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4492 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4493 * user-space a clue if that is the case.
4495 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4496 (hw->vht160_mcs_rx_highest != 0 ||
4497 hw->vht160_mcs_tx_highest != 0)) {
4498 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4499 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4505 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4508 struct ieee80211_sta_ht_cap ht_cap = {0};
4510 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4513 ht_cap.ht_supported = 1;
4514 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4515 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4516 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4517 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4519 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4521 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4522 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4524 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4525 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4527 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4530 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4531 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4536 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4537 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4539 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4542 stbc = ar->ht_cap_info;
4543 stbc &= WMI_HT_CAP_RX_STBC;
4544 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4545 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4546 stbc &= IEEE80211_HT_CAP_RX_STBC;
4551 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4552 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4554 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4555 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4557 /* max AMSDU is implicitly taken from vht_cap_info */
4558 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4559 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4561 for (i = 0; i < ar->num_rf_chains; i++) {
4562 if (ar->cfg_rx_chainmask & BIT(i))
4563 ht_cap.mcs.rx_mask[i] = 0xFF;
4566 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4571 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4573 struct ieee80211_supported_band *band;
4574 struct ieee80211_sta_vht_cap vht_cap;
4575 struct ieee80211_sta_ht_cap ht_cap;
4577 ht_cap = ath10k_get_ht_cap(ar);
4578 vht_cap = ath10k_create_vht_cap(ar);
4580 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4581 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4582 band->ht_cap = ht_cap;
4584 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4585 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4586 band->ht_cap = ht_cap;
4587 band->vht_cap = vht_cap;
4591 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4595 lockdep_assert_held(&ar->conf_mutex);
4597 ath10k_check_chain_mask(ar, tx_ant, "tx");
4598 ath10k_check_chain_mask(ar, rx_ant, "rx");
4600 ar->cfg_tx_chainmask = tx_ant;
4601 ar->cfg_rx_chainmask = rx_ant;
4603 if ((ar->state != ATH10K_STATE_ON) &&
4604 (ar->state != ATH10K_STATE_RESTARTED))
4607 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4610 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4615 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4618 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4623 /* Reload HT/VHT capability */
4624 ath10k_mac_setup_ht_vht_cap(ar);
4629 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4631 struct ath10k *ar = hw->priv;
4634 mutex_lock(&ar->conf_mutex);
4635 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4636 mutex_unlock(&ar->conf_mutex);
4640 static int ath10k_start(struct ieee80211_hw *hw)
4642 struct ath10k *ar = hw->priv;
4647 * This makes sense only when restarting hw. It is harmless to call
4648 * unconditionally. This is necessary to make sure no HTT/WMI tx
4649 * commands will be submitted while restarting.
4651 ath10k_drain_tx(ar);
4653 mutex_lock(&ar->conf_mutex);
4655 switch (ar->state) {
4656 case ATH10K_STATE_OFF:
4657 ar->state = ATH10K_STATE_ON;
4659 case ATH10K_STATE_RESTARTING:
4660 ar->state = ATH10K_STATE_RESTARTED;
4662 case ATH10K_STATE_ON:
4663 case ATH10K_STATE_RESTARTED:
4664 case ATH10K_STATE_WEDGED:
4668 case ATH10K_STATE_UTF:
4673 ret = ath10k_hif_power_up(ar);
4675 ath10k_err(ar, "Could not init hif: %d\n", ret);
4679 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4680 &ar->normal_mode_fw);
4682 ath10k_err(ar, "Could not init core: %d\n", ret);
4683 goto err_power_down;
4686 param = ar->wmi.pdev_param->pmf_qos;
4687 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4689 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4693 param = ar->wmi.pdev_param->dynamic_bw;
4694 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4696 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4700 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
4701 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
4703 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
4708 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4709 ret = ath10k_wmi_adaptive_qcs(ar, true);
4711 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4717 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4718 param = ar->wmi.pdev_param->burst_enable;
4719 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4721 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4726 param = ar->wmi.pdev_param->idle_ps_config;
4727 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4728 if (ret && ret != -EOPNOTSUPP) {
4729 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4733 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4736 * By default FW set ARP frames ac to voice (6). In that case ARP
4737 * exchange is not working properly for UAPSD enabled AP. ARP requests
4738 * which arrives with access category 0 are processed by network stack
4739 * and send back with access category 0, but FW changes access category
4740 * to 6. Set ARP frames access category to best effort (0) solves
4744 param = ar->wmi.pdev_param->arp_ac_override;
4745 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4747 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4752 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4753 ar->running_fw->fw_file.fw_features)) {
4754 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4755 WMI_CCA_DETECT_LEVEL_AUTO,
4756 WMI_CCA_DETECT_MARGIN_AUTO);
4758 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4764 param = ar->wmi.pdev_param->ani_enable;
4765 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4767 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4772 ar->ani_enabled = true;
4774 if (ath10k_peer_stats_enabled(ar)) {
4775 param = ar->wmi.pdev_param->peer_stats_update_period;
4776 ret = ath10k_wmi_pdev_set_param(ar, param,
4777 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4780 "failed to set peer stats period : %d\n",
4786 param = ar->wmi.pdev_param->enable_btcoex;
4787 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4788 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4789 ar->running_fw->fw_file.fw_features)) {
4790 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4793 "failed to set btcoex param: %d\n", ret);
4796 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4799 ar->num_started_vdevs = 0;
4800 ath10k_regd_update(ar);
4802 ath10k_spectral_start(ar);
4803 ath10k_thermal_set_throttling(ar);
4805 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
4807 mutex_unlock(&ar->conf_mutex);
4811 ath10k_core_stop(ar);
4814 ath10k_hif_power_down(ar);
4817 ar->state = ATH10K_STATE_OFF;
4820 mutex_unlock(&ar->conf_mutex);
4824 static void ath10k_stop(struct ieee80211_hw *hw)
4826 struct ath10k *ar = hw->priv;
4828 ath10k_drain_tx(ar);
4830 mutex_lock(&ar->conf_mutex);
4831 if (ar->state != ATH10K_STATE_OFF) {
4833 ar->state = ATH10K_STATE_OFF;
4835 mutex_unlock(&ar->conf_mutex);
4837 cancel_work_sync(&ar->set_coverage_class_work);
4838 cancel_delayed_work_sync(&ar->scan.timeout);
4839 cancel_work_sync(&ar->restart_work);
4842 static int ath10k_config_ps(struct ath10k *ar)
4844 struct ath10k_vif *arvif;
4847 lockdep_assert_held(&ar->conf_mutex);
4849 list_for_each_entry(arvif, &ar->arvifs, list) {
4850 ret = ath10k_mac_vif_setup_ps(arvif);
4852 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4860 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4865 lockdep_assert_held(&ar->conf_mutex);
4867 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4869 param = ar->wmi.pdev_param->txpower_limit2g;
4870 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4872 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4877 param = ar->wmi.pdev_param->txpower_limit5g;
4878 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4880 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4888 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4890 struct ath10k_vif *arvif;
4891 int ret, txpower = -1;
4893 lockdep_assert_held(&ar->conf_mutex);
4895 list_for_each_entry(arvif, &ar->arvifs, list) {
4896 if (arvif->txpower <= 0)
4900 txpower = arvif->txpower;
4902 txpower = min(txpower, arvif->txpower);
4908 ret = ath10k_mac_txpower_setup(ar, txpower);
4910 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4918 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4920 struct ath10k *ar = hw->priv;
4921 struct ieee80211_conf *conf = &hw->conf;
4924 mutex_lock(&ar->conf_mutex);
4926 if (changed & IEEE80211_CONF_CHANGE_PS)
4927 ath10k_config_ps(ar);
4929 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4930 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4931 ret = ath10k_monitor_recalc(ar);
4933 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4936 mutex_unlock(&ar->conf_mutex);
4940 static u32 get_nss_from_chainmask(u16 chain_mask)
4942 if ((chain_mask & 0xf) == 0xf)
4944 else if ((chain_mask & 0x7) == 0x7)
4946 else if ((chain_mask & 0x3) == 0x3)
4951 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4954 struct ath10k *ar = arvif->ar;
4958 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4961 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4962 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4963 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4964 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4966 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4967 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4968 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4969 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4974 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4975 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4977 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4978 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4979 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4981 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4982 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4984 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4985 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4986 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4988 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4989 ar->wmi.vdev_param->txbf, value);
4994 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4995 * because we will send mgmt frames without CCK. This requirement
4996 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4999 static int ath10k_add_interface(struct ieee80211_hw *hw,
5000 struct ieee80211_vif *vif)
5002 struct ath10k *ar = hw->priv;
5003 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5004 struct ath10k_peer *peer;
5005 enum wmi_sta_powersave_param param;
5012 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5014 mutex_lock(&ar->conf_mutex);
5016 memset(arvif, 0, sizeof(*arvif));
5017 ath10k_mac_txq_init(vif->txq);
5022 INIT_LIST_HEAD(&arvif->list);
5023 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5024 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5025 ath10k_mac_vif_sta_connection_loss_work);
5027 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5028 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5029 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5030 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5031 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5032 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5035 if (ar->num_peers >= ar->max_num_peers) {
5036 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5041 if (ar->free_vdev_map == 0) {
5042 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5046 bit = __ffs64(ar->free_vdev_map);
5048 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5049 bit, ar->free_vdev_map);
5051 arvif->vdev_id = bit;
5052 arvif->vdev_subtype =
5053 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5055 switch (vif->type) {
5056 case NL80211_IFTYPE_P2P_DEVICE:
5057 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5058 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5059 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5061 case NL80211_IFTYPE_UNSPECIFIED:
5062 case NL80211_IFTYPE_STATION:
5063 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5065 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5066 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5068 case NL80211_IFTYPE_ADHOC:
5069 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5071 case NL80211_IFTYPE_MESH_POINT:
5072 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5073 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5074 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5075 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5077 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5080 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5082 case NL80211_IFTYPE_AP:
5083 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5086 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5087 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5089 case NL80211_IFTYPE_MONITOR:
5090 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5097 /* Using vdev_id as queue number will make it very easy to do per-vif
5098 * tx queue locking. This shouldn't wrap due to interface combinations
5099 * but do a modulo for correctness sake and prevent using offchannel tx
5100 * queues for regular vif tx.
5102 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5103 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5104 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5106 /* Some firmware revisions don't wait for beacon tx completion before
5107 * sending another SWBA event. This could lead to hardware using old
5108 * (freed) beacon data in some cases, e.g. tx credit starvation
5109 * combined with missed TBTT. This is very very rare.
5111 * On non-IOMMU-enabled hosts this could be a possible security issue
5112 * because hw could beacon some random data on the air. On
5113 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5114 * device would crash.
5116 * Since there are no beacon tx completions (implicit nor explicit)
5117 * propagated to host the only workaround for this is to allocate a
5118 * DMA-coherent buffer for a lifetime of a vif and use it for all
5119 * beacon tx commands. Worst case for this approach is some beacons may
5120 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5122 if (vif->type == NL80211_IFTYPE_ADHOC ||
5123 vif->type == NL80211_IFTYPE_MESH_POINT ||
5124 vif->type == NL80211_IFTYPE_AP) {
5125 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
5126 IEEE80211_MAX_FRAME_LEN,
5127 &arvif->beacon_paddr,
5129 if (!arvif->beacon_buf) {
5131 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5136 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5137 arvif->nohwcrypt = true;
5139 if (arvif->nohwcrypt &&
5140 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5141 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5145 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5146 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5147 arvif->beacon_buf ? "single-buf" : "per-skb");
5149 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5150 arvif->vdev_subtype, vif->addr);
5152 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5153 arvif->vdev_id, ret);
5157 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5158 spin_lock_bh(&ar->data_lock);
5159 list_add(&arvif->list, &ar->arvifs);
5160 spin_unlock_bh(&ar->data_lock);
5162 /* It makes no sense to have firmware do keepalives. mac80211 already
5163 * takes care of this with idle connection polling.
5165 ret = ath10k_mac_vif_disable_keepalive(arvif);
5167 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5168 arvif->vdev_id, ret);
5169 goto err_vdev_delete;
5172 arvif->def_wep_key_idx = -1;
5174 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5175 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5176 ATH10K_HW_TXRX_NATIVE_WIFI);
5177 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5178 if (ret && ret != -EOPNOTSUPP) {
5179 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5180 arvif->vdev_id, ret);
5181 goto err_vdev_delete;
5184 /* Configuring number of spatial stream for monitor interface is causing
5185 * target assert in qca9888 and qca6174.
5187 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5188 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5190 vdev_param = ar->wmi.vdev_param->nss;
5191 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5194 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5195 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5197 goto err_vdev_delete;
5201 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5202 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5203 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5204 vif->addr, WMI_PEER_TYPE_DEFAULT);
5206 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5207 arvif->vdev_id, ret);
5208 goto err_vdev_delete;
5211 spin_lock_bh(&ar->data_lock);
5213 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5215 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5216 vif->addr, arvif->vdev_id);
5217 spin_unlock_bh(&ar->data_lock);
5219 goto err_peer_delete;
5222 arvif->peer_id = find_first_bit(peer->peer_ids,
5223 ATH10K_MAX_NUM_PEER_IDS);
5225 spin_unlock_bh(&ar->data_lock);
5227 arvif->peer_id = HTT_INVALID_PEERID;
5230 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5231 ret = ath10k_mac_set_kickout(arvif);
5233 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5234 arvif->vdev_id, ret);
5235 goto err_peer_delete;
5239 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5240 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5241 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5242 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5245 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5246 arvif->vdev_id, ret);
5247 goto err_peer_delete;
5250 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5252 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5253 arvif->vdev_id, ret);
5254 goto err_peer_delete;
5257 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5259 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5260 arvif->vdev_id, ret);
5261 goto err_peer_delete;
5265 ret = ath10k_mac_set_txbf_conf(arvif);
5267 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5268 arvif->vdev_id, ret);
5269 goto err_peer_delete;
5272 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5274 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5275 arvif->vdev_id, ret);
5276 goto err_peer_delete;
5279 arvif->txpower = vif->bss_conf.txpower;
5280 ret = ath10k_mac_txpower_recalc(ar);
5282 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5283 goto err_peer_delete;
5286 if (vif->type == NL80211_IFTYPE_MONITOR) {
5287 ar->monitor_arvif = arvif;
5288 ret = ath10k_monitor_recalc(ar);
5290 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5291 goto err_peer_delete;
5295 spin_lock_bh(&ar->htt.tx_lock);
5297 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5298 spin_unlock_bh(&ar->htt.tx_lock);
5300 mutex_unlock(&ar->conf_mutex);
5304 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5305 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5306 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5309 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5310 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5311 spin_lock_bh(&ar->data_lock);
5312 list_del(&arvif->list);
5313 spin_unlock_bh(&ar->data_lock);
5316 if (arvif->beacon_buf) {
5317 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5318 arvif->beacon_buf, arvif->beacon_paddr);
5319 arvif->beacon_buf = NULL;
5322 mutex_unlock(&ar->conf_mutex);
5327 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5331 for (i = 0; i < BITS_PER_LONG; i++)
5332 ath10k_mac_vif_tx_unlock(arvif, i);
5335 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5336 struct ieee80211_vif *vif)
5338 struct ath10k *ar = hw->priv;
5339 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5340 struct ath10k_peer *peer;
5344 cancel_work_sync(&arvif->ap_csa_work);
5345 cancel_delayed_work_sync(&arvif->connection_loss_work);
5347 mutex_lock(&ar->conf_mutex);
5349 spin_lock_bh(&ar->data_lock);
5350 ath10k_mac_vif_beacon_cleanup(arvif);
5351 spin_unlock_bh(&ar->data_lock);
5353 ret = ath10k_spectral_vif_stop(arvif);
5355 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5356 arvif->vdev_id, ret);
5358 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5359 spin_lock_bh(&ar->data_lock);
5360 list_del(&arvif->list);
5361 spin_unlock_bh(&ar->data_lock);
5363 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5364 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5365 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5368 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5369 arvif->vdev_id, ret);
5371 kfree(arvif->u.ap.noa_data);
5374 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5377 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5379 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5380 arvif->vdev_id, ret);
5382 /* Some firmware revisions don't notify host about self-peer removal
5383 * until after associated vdev is deleted.
5385 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5386 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5387 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5390 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5391 arvif->vdev_id, ret);
5393 spin_lock_bh(&ar->data_lock);
5395 spin_unlock_bh(&ar->data_lock);
5398 spin_lock_bh(&ar->data_lock);
5399 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5400 peer = ar->peer_map[i];
5404 if (peer->vif == vif) {
5405 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5406 vif->addr, arvif->vdev_id);
5410 spin_unlock_bh(&ar->data_lock);
5412 ath10k_peer_cleanup(ar, arvif->vdev_id);
5413 ath10k_mac_txq_unref(ar, vif->txq);
5415 if (vif->type == NL80211_IFTYPE_MONITOR) {
5416 ar->monitor_arvif = NULL;
5417 ret = ath10k_monitor_recalc(ar);
5419 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5422 ret = ath10k_mac_txpower_recalc(ar);
5424 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5426 spin_lock_bh(&ar->htt.tx_lock);
5427 ath10k_mac_vif_tx_unlock_all(arvif);
5428 spin_unlock_bh(&ar->htt.tx_lock);
5430 ath10k_mac_txq_unref(ar, vif->txq);
5432 mutex_unlock(&ar->conf_mutex);
5436 * FIXME: Has to be verified.
5438 #define SUPPORTED_FILTERS \
5443 FIF_BCN_PRBRESP_PROMISC | \
5447 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5448 unsigned int changed_flags,
5449 unsigned int *total_flags,
5452 struct ath10k *ar = hw->priv;
5455 mutex_lock(&ar->conf_mutex);
5457 changed_flags &= SUPPORTED_FILTERS;
5458 *total_flags &= SUPPORTED_FILTERS;
5459 ar->filter_flags = *total_flags;
5461 ret = ath10k_monitor_recalc(ar);
5463 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5465 mutex_unlock(&ar->conf_mutex);
5468 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5469 struct ieee80211_vif *vif,
5470 struct ieee80211_bss_conf *info,
5473 struct ath10k *ar = hw->priv;
5474 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5475 struct cfg80211_chan_def def;
5476 u32 vdev_param, pdev_param, slottime, preamble;
5477 u16 bitrate, hw_value;
5478 u8 rate, basic_rate_idx;
5479 int rateidx, ret = 0, hw_rate_code;
5480 enum nl80211_band band;
5481 const struct ieee80211_supported_band *sband;
5483 mutex_lock(&ar->conf_mutex);
5485 if (changed & BSS_CHANGED_IBSS)
5486 ath10k_control_ibss(arvif, info, vif->addr);
5488 if (changed & BSS_CHANGED_BEACON_INT) {
5489 arvif->beacon_interval = info->beacon_int;
5490 vdev_param = ar->wmi.vdev_param->beacon_interval;
5491 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5492 arvif->beacon_interval);
5493 ath10k_dbg(ar, ATH10K_DBG_MAC,
5494 "mac vdev %d beacon_interval %d\n",
5495 arvif->vdev_id, arvif->beacon_interval);
5498 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5499 arvif->vdev_id, ret);
5502 if (changed & BSS_CHANGED_BEACON) {
5503 ath10k_dbg(ar, ATH10K_DBG_MAC,
5504 "vdev %d set beacon tx mode to staggered\n",
5507 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5508 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5509 WMI_BEACON_STAGGERED_MODE);
5511 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5512 arvif->vdev_id, ret);
5514 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5516 ath10k_warn(ar, "failed to update beacon template: %d\n",
5519 if (ieee80211_vif_is_mesh(vif)) {
5520 /* mesh doesn't use SSID but firmware needs it */
5521 strncpy(arvif->u.ap.ssid, "mesh",
5522 sizeof(arvif->u.ap.ssid));
5523 arvif->u.ap.ssid_len = 4;
5527 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5528 ret = ath10k_mac_setup_prb_tmpl(arvif);
5530 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5531 arvif->vdev_id, ret);
5534 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5535 arvif->dtim_period = info->dtim_period;
5537 ath10k_dbg(ar, ATH10K_DBG_MAC,
5538 "mac vdev %d dtim_period %d\n",
5539 arvif->vdev_id, arvif->dtim_period);
5541 vdev_param = ar->wmi.vdev_param->dtim_period;
5542 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5543 arvif->dtim_period);
5545 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5546 arvif->vdev_id, ret);
5549 if (changed & BSS_CHANGED_SSID &&
5550 vif->type == NL80211_IFTYPE_AP) {
5551 arvif->u.ap.ssid_len = info->ssid_len;
5553 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5554 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5557 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5558 ether_addr_copy(arvif->bssid, info->bssid);
5560 if (changed & BSS_CHANGED_BEACON_ENABLED)
5561 ath10k_control_beaconing(arvif, info);
5563 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5564 arvif->use_cts_prot = info->use_cts_prot;
5566 ret = ath10k_recalc_rtscts_prot(arvif);
5568 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5569 arvif->vdev_id, ret);
5571 if (ath10k_mac_can_set_cts_prot(arvif)) {
5572 ret = ath10k_mac_set_cts_prot(arvif);
5574 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5575 arvif->vdev_id, ret);
5579 if (changed & BSS_CHANGED_ERP_SLOT) {
5580 if (info->use_short_slot)
5581 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5584 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5586 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5587 arvif->vdev_id, slottime);
5589 vdev_param = ar->wmi.vdev_param->slot_time;
5590 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5593 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5594 arvif->vdev_id, ret);
5597 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5598 if (info->use_short_preamble)
5599 preamble = WMI_VDEV_PREAMBLE_SHORT;
5601 preamble = WMI_VDEV_PREAMBLE_LONG;
5603 ath10k_dbg(ar, ATH10K_DBG_MAC,
5604 "mac vdev %d preamble %dn",
5605 arvif->vdev_id, preamble);
5607 vdev_param = ar->wmi.vdev_param->preamble;
5608 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5611 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5612 arvif->vdev_id, ret);
5615 if (changed & BSS_CHANGED_ASSOC) {
5617 /* Workaround: Make sure monitor vdev is not running
5618 * when associating to prevent some firmware revisions
5619 * (e.g. 10.1 and 10.2) from crashing.
5621 if (ar->monitor_started)
5622 ath10k_monitor_stop(ar);
5623 ath10k_bss_assoc(hw, vif, info);
5624 ath10k_monitor_recalc(ar);
5626 ath10k_bss_disassoc(hw, vif);
5630 if (changed & BSS_CHANGED_TXPOWER) {
5631 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5632 arvif->vdev_id, info->txpower);
5634 arvif->txpower = info->txpower;
5635 ret = ath10k_mac_txpower_recalc(ar);
5637 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5640 if (changed & BSS_CHANGED_PS) {
5641 arvif->ps = vif->bss_conf.ps;
5643 ret = ath10k_config_ps(ar);
5645 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5646 arvif->vdev_id, ret);
5649 if (changed & BSS_CHANGED_MCAST_RATE &&
5650 !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) {
5651 band = def.chan->band;
5652 rateidx = vif->bss_conf.mcast_rate[band] - 1;
5654 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5655 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5657 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
5658 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
5659 if (ath10k_mac_bitrate_is_cck(bitrate))
5660 preamble = WMI_RATE_PREAMBLE_CCK;
5662 preamble = WMI_RATE_PREAMBLE_OFDM;
5664 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
5666 ath10k_dbg(ar, ATH10K_DBG_MAC,
5667 "mac vdev %d mcast_rate %x\n",
5668 arvif->vdev_id, rate);
5670 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5671 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5675 "failed to set mcast rate on vdev %i: %d\n",
5676 arvif->vdev_id, ret);
5678 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5679 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5683 "failed to set bcast rate on vdev %i: %d\n",
5684 arvif->vdev_id, ret);
5687 if (changed & BSS_CHANGED_BASIC_RATES) {
5688 if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) {
5689 mutex_unlock(&ar->conf_mutex);
5693 sband = ar->hw->wiphy->bands[def.chan->band];
5694 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
5695 bitrate = sband->bitrates[basic_rate_idx].bitrate;
5697 hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
5698 if (hw_rate_code < 0) {
5699 ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
5700 mutex_unlock(&ar->conf_mutex);
5704 vdev_param = ar->wmi.vdev_param->mgmt_rate;
5705 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5708 ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
5711 mutex_unlock(&ar->conf_mutex);
5714 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5716 struct ath10k *ar = hw->priv;
5718 /* This function should never be called if setting the coverage class
5719 * is not supported on this hardware.
5721 if (!ar->hw_params.hw_ops->set_coverage_class) {
5725 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5728 struct ath10k_mac_tdls_iter_data {
5729 u32 num_tdls_stations;
5730 struct ieee80211_vif *curr_vif;
5733 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5734 struct ieee80211_sta *sta)
5736 struct ath10k_mac_tdls_iter_data *iter_data = data;
5737 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5738 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5740 if (sta->tdls && sta_vif == iter_data->curr_vif)
5741 iter_data->num_tdls_stations++;
5744 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5745 struct ieee80211_vif *vif)
5747 struct ath10k_mac_tdls_iter_data data = {};
5749 data.curr_vif = vif;
5751 ieee80211_iterate_stations_atomic(hw,
5752 ath10k_mac_tdls_vif_stations_count_iter,
5754 return data.num_tdls_stations;
5757 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5758 struct ieee80211_vif *vif)
5760 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5761 int *num_tdls_vifs = data;
5763 if (vif->type != NL80211_IFTYPE_STATION)
5766 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5770 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5772 int num_tdls_vifs = 0;
5774 ieee80211_iterate_active_interfaces_atomic(hw,
5775 IEEE80211_IFACE_ITER_NORMAL,
5776 ath10k_mac_tdls_vifs_count_iter,
5778 return num_tdls_vifs;
5781 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5782 struct ieee80211_vif *vif,
5783 struct ieee80211_scan_request *hw_req)
5785 struct ath10k *ar = hw->priv;
5786 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5787 struct cfg80211_scan_request *req = &hw_req->req;
5788 struct wmi_start_scan_arg arg;
5793 mutex_lock(&ar->conf_mutex);
5795 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
5800 spin_lock_bh(&ar->data_lock);
5801 switch (ar->scan.state) {
5802 case ATH10K_SCAN_IDLE:
5803 reinit_completion(&ar->scan.started);
5804 reinit_completion(&ar->scan.completed);
5805 ar->scan.state = ATH10K_SCAN_STARTING;
5806 ar->scan.is_roc = false;
5807 ar->scan.vdev_id = arvif->vdev_id;
5810 case ATH10K_SCAN_STARTING:
5811 case ATH10K_SCAN_RUNNING:
5812 case ATH10K_SCAN_ABORTING:
5816 spin_unlock_bh(&ar->data_lock);
5821 memset(&arg, 0, sizeof(arg));
5822 ath10k_wmi_start_scan_init(ar, &arg);
5823 arg.vdev_id = arvif->vdev_id;
5824 arg.scan_id = ATH10K_SCAN_ID;
5827 arg.ie_len = req->ie_len;
5828 memcpy(arg.ie, req->ie, arg.ie_len);
5832 arg.n_ssids = req->n_ssids;
5833 for (i = 0; i < arg.n_ssids; i++) {
5834 arg.ssids[i].len = req->ssids[i].ssid_len;
5835 arg.ssids[i].ssid = req->ssids[i].ssid;
5838 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5841 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5842 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
5843 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
5844 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
5847 if (req->n_channels) {
5848 arg.n_channels = req->n_channels;
5849 for (i = 0; i < arg.n_channels; i++)
5850 arg.channels[i] = req->channels[i]->center_freq;
5853 /* if duration is set, default dwell times will be overwritten */
5854 if (req->duration) {
5855 arg.dwell_time_active = req->duration;
5856 arg.dwell_time_passive = req->duration;
5857 arg.burst_duration_ms = req->duration;
5859 scan_timeout = min_t(u32, arg.max_rest_time *
5860 (arg.n_channels - 1) + (req->duration +
5861 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
5862 arg.n_channels, arg.max_scan_time + 200);
5865 /* Add a 200ms margin to account for event/command processing */
5866 scan_timeout = arg.max_scan_time + 200;
5869 ret = ath10k_start_scan(ar, &arg);
5871 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5872 spin_lock_bh(&ar->data_lock);
5873 ar->scan.state = ATH10K_SCAN_IDLE;
5874 spin_unlock_bh(&ar->data_lock);
5877 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5878 msecs_to_jiffies(scan_timeout));
5881 mutex_unlock(&ar->conf_mutex);
5885 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5886 struct ieee80211_vif *vif)
5888 struct ath10k *ar = hw->priv;
5890 mutex_lock(&ar->conf_mutex);
5891 ath10k_scan_abort(ar);
5892 mutex_unlock(&ar->conf_mutex);
5894 cancel_delayed_work_sync(&ar->scan.timeout);
5897 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5898 struct ath10k_vif *arvif,
5899 enum set_key_cmd cmd,
5900 struct ieee80211_key_conf *key)
5902 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5905 /* 10.1 firmware branch requires default key index to be set to group
5906 * key index after installing it. Otherwise FW/HW Txes corrupted
5907 * frames with multi-vif APs. This is not required for main firmware
5908 * branch (e.g. 636).
5910 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5912 * FIXME: It remains unknown if this is required for multi-vif STA
5913 * interfaces on 10.1.
5916 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5917 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5920 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5923 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5926 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5932 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5935 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5936 arvif->vdev_id, ret);
5939 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5940 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5941 struct ieee80211_key_conf *key)
5943 struct ath10k *ar = hw->priv;
5944 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5945 struct ath10k_peer *peer;
5946 const u8 *peer_addr;
5947 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5948 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5954 /* this one needs to be done in software */
5955 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
5956 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
5957 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
5958 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
5961 if (arvif->nohwcrypt)
5964 if (key->keyidx > WMI_MAX_KEY_INDEX)
5967 mutex_lock(&ar->conf_mutex);
5970 peer_addr = sta->addr;
5971 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5972 peer_addr = vif->bss_conf.bssid;
5974 peer_addr = vif->addr;
5976 key->hw_key_idx = key->keyidx;
5980 arvif->wep_keys[key->keyidx] = key;
5982 arvif->wep_keys[key->keyidx] = NULL;
5985 /* the peer should not disappear in mid-way (unless FW goes awry) since
5986 * we already hold conf_mutex. we just make sure its there now.
5988 spin_lock_bh(&ar->data_lock);
5989 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5990 spin_unlock_bh(&ar->data_lock);
5993 if (cmd == SET_KEY) {
5994 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5999 /* if the peer doesn't exist there is no key to disable anymore */
6004 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6005 flags |= WMI_KEY_PAIRWISE;
6007 flags |= WMI_KEY_GROUP;
6010 if (cmd == DISABLE_KEY)
6011 ath10k_clear_vdev_key(arvif, key);
6013 /* When WEP keys are uploaded it's possible that there are
6014 * stations associated already (e.g. when merging) without any
6015 * keys. Static WEP needs an explicit per-peer key upload.
6017 if (vif->type == NL80211_IFTYPE_ADHOC &&
6019 ath10k_mac_vif_update_wep_key(arvif, key);
6021 /* 802.1x never sets the def_wep_key_idx so each set_key()
6022 * call changes default tx key.
6024 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6025 * after first set_key().
6027 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
6028 flags |= WMI_KEY_TX_USAGE;
6031 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
6034 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
6035 arvif->vdev_id, peer_addr, ret);
6039 /* mac80211 sets static WEP keys as groupwise while firmware requires
6040 * them to be installed twice as both pairwise and groupwise.
6042 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6044 flags2 &= ~WMI_KEY_GROUP;
6045 flags2 |= WMI_KEY_PAIRWISE;
6047 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6050 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6051 arvif->vdev_id, peer_addr, ret);
6052 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6056 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6057 arvif->vdev_id, peer_addr, ret2);
6063 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6065 spin_lock_bh(&ar->data_lock);
6066 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6067 if (peer && cmd == SET_KEY)
6068 peer->keys[key->keyidx] = key;
6069 else if (peer && cmd == DISABLE_KEY)
6070 peer->keys[key->keyidx] = NULL;
6071 else if (peer == NULL)
6072 /* impossible unless FW goes crazy */
6073 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6074 spin_unlock_bh(&ar->data_lock);
6076 if (sta && sta->tdls)
6077 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6078 WMI_PEER_AUTHORIZE, 1);
6081 mutex_unlock(&ar->conf_mutex);
6085 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6086 struct ieee80211_vif *vif,
6089 struct ath10k *ar = hw->priv;
6090 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6093 mutex_lock(&arvif->ar->conf_mutex);
6095 if (arvif->ar->state != ATH10K_STATE_ON)
6098 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6099 arvif->vdev_id, keyidx);
6101 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6103 arvif->ar->wmi.vdev_param->def_keyid,
6107 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6113 arvif->def_wep_key_idx = keyidx;
6116 mutex_unlock(&arvif->ar->conf_mutex);
6119 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6122 struct ath10k_vif *arvif;
6123 struct ath10k_sta *arsta;
6124 struct ieee80211_sta *sta;
6125 struct cfg80211_chan_def def;
6126 enum nl80211_band band;
6127 const u8 *ht_mcs_mask;
6128 const u16 *vht_mcs_mask;
6129 u32 changed, bw, nss, smps;
6132 arsta = container_of(wk, struct ath10k_sta, update_wk);
6133 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6134 arvif = arsta->arvif;
6137 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6140 band = def.chan->band;
6141 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6142 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6144 spin_lock_bh(&ar->data_lock);
6146 changed = arsta->changed;
6153 spin_unlock_bh(&ar->data_lock);
6155 mutex_lock(&ar->conf_mutex);
6157 nss = max_t(u32, 1, nss);
6158 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6159 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6161 if (changed & IEEE80211_RC_BW_CHANGED) {
6162 enum wmi_phy_mode mode;
6164 mode = chan_to_phymode(&def);
6165 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
6166 sta->addr, bw, mode);
6168 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6169 WMI_PEER_PHYMODE, mode);
6171 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6172 sta->addr, mode, err);
6176 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6177 WMI_PEER_CHAN_WIDTH, bw);
6179 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6180 sta->addr, bw, err);
6183 if (changed & IEEE80211_RC_NSS_CHANGED) {
6184 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
6187 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6190 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6191 sta->addr, nss, err);
6194 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6195 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
6198 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6199 WMI_PEER_SMPS_STATE, smps);
6201 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6202 sta->addr, smps, err);
6205 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6206 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
6209 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6211 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6216 mutex_unlock(&ar->conf_mutex);
6219 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6220 struct ieee80211_sta *sta)
6222 struct ath10k *ar = arvif->ar;
6224 lockdep_assert_held(&ar->conf_mutex);
6226 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6229 if (ar->num_stations >= ar->max_num_stations)
6237 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6238 struct ieee80211_sta *sta)
6240 struct ath10k *ar = arvif->ar;
6242 lockdep_assert_held(&ar->conf_mutex);
6244 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6250 static int ath10k_sta_state(struct ieee80211_hw *hw,
6251 struct ieee80211_vif *vif,
6252 struct ieee80211_sta *sta,
6253 enum ieee80211_sta_state old_state,
6254 enum ieee80211_sta_state new_state)
6256 struct ath10k *ar = hw->priv;
6257 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6258 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6259 struct ath10k_peer *peer;
6263 if (old_state == IEEE80211_STA_NOTEXIST &&
6264 new_state == IEEE80211_STA_NONE) {
6265 memset(arsta, 0, sizeof(*arsta));
6266 arsta->arvif = arvif;
6267 arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
6268 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6270 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6271 ath10k_mac_txq_init(sta->txq[i]);
6274 /* cancel must be done outside the mutex to avoid deadlock */
6275 if ((old_state == IEEE80211_STA_NONE &&
6276 new_state == IEEE80211_STA_NOTEXIST))
6277 cancel_work_sync(&arsta->update_wk);
6279 mutex_lock(&ar->conf_mutex);
6281 if (old_state == IEEE80211_STA_NOTEXIST &&
6282 new_state == IEEE80211_STA_NONE) {
6284 * New station addition.
6286 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6287 u32 num_tdls_stations;
6290 ath10k_dbg(ar, ATH10K_DBG_MAC,
6291 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6292 arvif->vdev_id, sta->addr,
6293 ar->num_stations + 1, ar->max_num_stations,
6294 ar->num_peers + 1, ar->max_num_peers);
6296 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6297 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats),
6299 if (!arsta->tx_stats)
6303 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6304 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6307 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6308 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6310 ar->max_num_tdls_vdevs);
6314 peer_type = WMI_PEER_TYPE_TDLS;
6317 ret = ath10k_mac_inc_num_stations(arvif, sta);
6319 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6320 ar->max_num_stations);
6324 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6325 sta->addr, peer_type);
6327 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6328 sta->addr, arvif->vdev_id, ret);
6329 ath10k_mac_dec_num_stations(arvif, sta);
6333 spin_lock_bh(&ar->data_lock);
6335 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6337 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6338 vif->addr, arvif->vdev_id);
6339 spin_unlock_bh(&ar->data_lock);
6340 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6341 ath10k_mac_dec_num_stations(arvif, sta);
6346 arsta->peer_id = find_first_bit(peer->peer_ids,
6347 ATH10K_MAX_NUM_PEER_IDS);
6349 spin_unlock_bh(&ar->data_lock);
6354 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6355 WMI_TDLS_ENABLE_ACTIVE);
6357 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6358 arvif->vdev_id, ret);
6359 ath10k_peer_delete(ar, arvif->vdev_id,
6361 ath10k_mac_dec_num_stations(arvif, sta);
6365 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6366 WMI_TDLS_PEER_STATE_PEERING);
6369 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6370 sta->addr, arvif->vdev_id, ret);
6371 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6372 ath10k_mac_dec_num_stations(arvif, sta);
6374 if (num_tdls_stations != 0)
6376 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6379 } else if ((old_state == IEEE80211_STA_NONE &&
6380 new_state == IEEE80211_STA_NOTEXIST)) {
6382 * Existing station deletion.
6384 ath10k_dbg(ar, ATH10K_DBG_MAC,
6385 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6386 arvif->vdev_id, sta->addr, sta);
6388 if (ath10k_debug_is_extd_tx_stats_enabled(ar))
6389 kfree(arsta->tx_stats);
6392 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6394 WMI_TDLS_PEER_STATE_TEARDOWN);
6396 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6398 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6401 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6403 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6404 sta->addr, arvif->vdev_id, ret);
6406 ath10k_mac_dec_num_stations(arvif, sta);
6408 spin_lock_bh(&ar->data_lock);
6409 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6410 peer = ar->peer_map[i];
6414 if (peer->sta == sta) {
6415 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6416 sta->addr, peer, i, arvif->vdev_id);
6419 /* Clean up the peer object as well since we
6420 * must have failed to do this above.
6422 list_del(&peer->list);
6423 ar->peer_map[i] = NULL;
6428 spin_unlock_bh(&ar->data_lock);
6430 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6431 ath10k_mac_txq_unref(ar, sta->txq[i]);
6436 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6439 /* This was the last tdls peer in current vif */
6440 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6443 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6444 arvif->vdev_id, ret);
6446 } else if (old_state == IEEE80211_STA_AUTH &&
6447 new_state == IEEE80211_STA_ASSOC &&
6448 (vif->type == NL80211_IFTYPE_AP ||
6449 vif->type == NL80211_IFTYPE_MESH_POINT ||
6450 vif->type == NL80211_IFTYPE_ADHOC)) {
6454 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6457 ret = ath10k_station_assoc(ar, vif, sta, false);
6459 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6460 sta->addr, arvif->vdev_id, ret);
6461 } else if (old_state == IEEE80211_STA_ASSOC &&
6462 new_state == IEEE80211_STA_AUTHORIZED &&
6465 * Tdls station authorized.
6467 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6470 ret = ath10k_station_assoc(ar, vif, sta, false);
6472 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6473 sta->addr, arvif->vdev_id, ret);
6477 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6478 WMI_TDLS_PEER_STATE_CONNECTED);
6480 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6481 sta->addr, arvif->vdev_id, ret);
6482 } else if (old_state == IEEE80211_STA_ASSOC &&
6483 new_state == IEEE80211_STA_AUTH &&
6484 (vif->type == NL80211_IFTYPE_AP ||
6485 vif->type == NL80211_IFTYPE_MESH_POINT ||
6486 vif->type == NL80211_IFTYPE_ADHOC)) {
6490 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6493 ret = ath10k_station_disassoc(ar, vif, sta);
6495 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6496 sta->addr, arvif->vdev_id, ret);
6499 mutex_unlock(&ar->conf_mutex);
6503 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6504 u16 ac, bool enable)
6506 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6507 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6508 u32 prio = 0, acc = 0;
6512 lockdep_assert_held(&ar->conf_mutex);
6514 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6518 case IEEE80211_AC_VO:
6519 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6520 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6524 case IEEE80211_AC_VI:
6525 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6526 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6530 case IEEE80211_AC_BE:
6531 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6532 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6536 case IEEE80211_AC_BK:
6537 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6538 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6545 arvif->u.sta.uapsd |= value;
6547 arvif->u.sta.uapsd &= ~value;
6549 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6550 WMI_STA_PS_PARAM_UAPSD,
6551 arvif->u.sta.uapsd);
6553 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6557 if (arvif->u.sta.uapsd)
6558 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6560 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6562 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6563 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6566 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6568 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6570 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6571 arvif->vdev_id, ret);
6575 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6577 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6578 arvif->vdev_id, ret);
6582 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6583 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6584 /* Only userspace can make an educated decision when to send
6585 * trigger frame. The following effectively disables u-UAPSD
6586 * autotrigger in firmware (which is enabled by default
6587 * provided the autotrigger service is available).
6591 arg.user_priority = prio;
6592 arg.service_interval = 0;
6593 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6594 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6596 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6597 arvif->bssid, &arg, 1);
6599 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6609 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6610 struct ieee80211_vif *vif, u16 ac,
6611 const struct ieee80211_tx_queue_params *params)
6613 struct ath10k *ar = hw->priv;
6614 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6615 struct wmi_wmm_params_arg *p = NULL;
6618 mutex_lock(&ar->conf_mutex);
6621 case IEEE80211_AC_VO:
6622 p = &arvif->wmm_params.ac_vo;
6624 case IEEE80211_AC_VI:
6625 p = &arvif->wmm_params.ac_vi;
6627 case IEEE80211_AC_BE:
6628 p = &arvif->wmm_params.ac_be;
6630 case IEEE80211_AC_BK:
6631 p = &arvif->wmm_params.ac_bk;
6640 p->cwmin = params->cw_min;
6641 p->cwmax = params->cw_max;
6642 p->aifs = params->aifs;
6645 * The channel time duration programmed in the HW is in absolute
6646 * microseconds, while mac80211 gives the txop in units of
6649 p->txop = params->txop * 32;
6651 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6652 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6653 &arvif->wmm_params);
6655 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6656 arvif->vdev_id, ret);
6660 /* This won't work well with multi-interface cases but it's
6661 * better than nothing.
6663 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6665 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6670 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6672 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6675 mutex_unlock(&ar->conf_mutex);
6679 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6681 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6682 struct ieee80211_vif *vif,
6683 struct ieee80211_channel *chan,
6685 enum ieee80211_roc_type type)
6687 struct ath10k *ar = hw->priv;
6688 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6689 struct wmi_start_scan_arg arg;
6693 mutex_lock(&ar->conf_mutex);
6695 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6700 spin_lock_bh(&ar->data_lock);
6701 switch (ar->scan.state) {
6702 case ATH10K_SCAN_IDLE:
6703 reinit_completion(&ar->scan.started);
6704 reinit_completion(&ar->scan.completed);
6705 reinit_completion(&ar->scan.on_channel);
6706 ar->scan.state = ATH10K_SCAN_STARTING;
6707 ar->scan.is_roc = true;
6708 ar->scan.vdev_id = arvif->vdev_id;
6709 ar->scan.roc_freq = chan->center_freq;
6710 ar->scan.roc_notify = true;
6713 case ATH10K_SCAN_STARTING:
6714 case ATH10K_SCAN_RUNNING:
6715 case ATH10K_SCAN_ABORTING:
6719 spin_unlock_bh(&ar->data_lock);
6724 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6726 memset(&arg, 0, sizeof(arg));
6727 ath10k_wmi_start_scan_init(ar, &arg);
6728 arg.vdev_id = arvif->vdev_id;
6729 arg.scan_id = ATH10K_SCAN_ID;
6731 arg.channels[0] = chan->center_freq;
6732 arg.dwell_time_active = scan_time_msec;
6733 arg.dwell_time_passive = scan_time_msec;
6734 arg.max_scan_time = scan_time_msec;
6735 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6736 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6737 arg.burst_duration_ms = duration;
6739 ret = ath10k_start_scan(ar, &arg);
6741 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6742 spin_lock_bh(&ar->data_lock);
6743 ar->scan.state = ATH10K_SCAN_IDLE;
6744 spin_unlock_bh(&ar->data_lock);
6748 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6750 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6752 ret = ath10k_scan_stop(ar);
6754 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6760 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6761 msecs_to_jiffies(duration));
6765 mutex_unlock(&ar->conf_mutex);
6769 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6771 struct ath10k *ar = hw->priv;
6773 mutex_lock(&ar->conf_mutex);
6775 spin_lock_bh(&ar->data_lock);
6776 ar->scan.roc_notify = false;
6777 spin_unlock_bh(&ar->data_lock);
6779 ath10k_scan_abort(ar);
6781 mutex_unlock(&ar->conf_mutex);
6783 cancel_delayed_work_sync(&ar->scan.timeout);
6789 * Both RTS and Fragmentation threshold are interface-specific
6790 * in ath10k, but device-specific in mac80211.
6793 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6795 struct ath10k *ar = hw->priv;
6796 struct ath10k_vif *arvif;
6799 mutex_lock(&ar->conf_mutex);
6800 list_for_each_entry(arvif, &ar->arvifs, list) {
6801 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6802 arvif->vdev_id, value);
6804 ret = ath10k_mac_set_rts(arvif, value);
6806 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6807 arvif->vdev_id, ret);
6811 mutex_unlock(&ar->conf_mutex);
6816 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6818 /* Even though there's a WMI enum for fragmentation threshold no known
6819 * firmware actually implements it. Moreover it is not possible to rely
6820 * frame fragmentation to mac80211 because firmware clears the "more
6821 * fragments" bit in frame control making it impossible for remote
6822 * devices to reassemble frames.
6824 * Hence implement a dummy callback just to say fragmentation isn't
6825 * supported. This effectively prevents mac80211 from doing frame
6826 * fragmentation in software.
6831 void ath10k_mac_wait_tx_complete(struct ath10k *ar)
6836 /* mac80211 doesn't care if we really xmit queued frames or not
6837 * we'll collect those frames either way if we stop/delete vdevs
6840 if (ar->state == ATH10K_STATE_WEDGED)
6843 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6846 spin_lock_bh(&ar->htt.tx_lock);
6847 empty = (ar->htt.num_pending_tx == 0);
6848 spin_unlock_bh(&ar->htt.tx_lock);
6850 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6851 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6855 }), ATH10K_FLUSH_TIMEOUT_HZ);
6857 if (time_left == 0 || skip)
6858 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6859 skip, ar->state, time_left);
6862 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6863 u32 queues, bool drop)
6865 struct ath10k *ar = hw->priv;
6866 struct ath10k_vif *arvif;
6870 if (vif->type == NL80211_IFTYPE_STATION) {
6871 bitmap = ~(1 << WMI_MGMT_TID);
6872 list_for_each_entry(arvif, &ar->arvifs, list) {
6873 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6874 ath10k_wmi_peer_flush(ar, arvif->vdev_id,
6875 arvif->bssid, bitmap);
6881 mutex_lock(&ar->conf_mutex);
6882 ath10k_mac_wait_tx_complete(ar);
6883 mutex_unlock(&ar->conf_mutex);
6886 /* TODO: Implement this function properly
6887 * For now it is needed to reply to Probe Requests in IBSS mode.
6888 * Propably we need this information from FW.
6890 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6895 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6896 enum ieee80211_reconfig_type reconfig_type)
6898 struct ath10k *ar = hw->priv;
6900 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6903 mutex_lock(&ar->conf_mutex);
6905 /* If device failed to restart it will be in a different state, e.g.
6906 * ATH10K_STATE_WEDGED
6908 if (ar->state == ATH10K_STATE_RESTARTED) {
6909 ath10k_info(ar, "device successfully recovered\n");
6910 ar->state = ATH10K_STATE_ON;
6911 ieee80211_wake_queues(ar->hw);
6914 mutex_unlock(&ar->conf_mutex);
6918 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6919 struct ieee80211_channel *channel)
6922 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6924 lockdep_assert_held(&ar->conf_mutex);
6926 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6927 (ar->rx_channel != channel))
6930 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6931 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6935 reinit_completion(&ar->bss_survey_done);
6937 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6939 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6943 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6945 ath10k_warn(ar, "bss channel survey timed out\n");
6950 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6951 struct survey_info *survey)
6953 struct ath10k *ar = hw->priv;
6954 struct ieee80211_supported_band *sband;
6955 struct survey_info *ar_survey = &ar->survey[idx];
6958 mutex_lock(&ar->conf_mutex);
6960 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6961 if (sband && idx >= sband->n_channels) {
6962 idx -= sband->n_channels;
6967 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6969 if (!sband || idx >= sband->n_channels) {
6974 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6976 spin_lock_bh(&ar->data_lock);
6977 memcpy(survey, ar_survey, sizeof(*survey));
6978 spin_unlock_bh(&ar->data_lock);
6980 survey->channel = &sband->channels[idx];
6982 if (ar->rx_channel == survey->channel)
6983 survey->filled |= SURVEY_INFO_IN_USE;
6986 mutex_unlock(&ar->conf_mutex);
6991 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6992 enum nl80211_band band,
6993 const struct cfg80211_bitrate_mask *mask)
6998 num_rates += hweight32(mask->control[band].legacy);
7000 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
7001 num_rates += hweight8(mask->control[band].ht_mcs[i]);
7003 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
7004 num_rates += hweight16(mask->control[band].vht_mcs[i]);
7006 return num_rates == 1;
7010 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
7011 enum nl80211_band band,
7012 const struct cfg80211_bitrate_mask *mask,
7015 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
7016 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7018 u8 vht_nss_mask = 0;
7021 if (mask->control[band].legacy)
7024 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7025 if (mask->control[band].ht_mcs[i] == 0)
7027 else if (mask->control[band].ht_mcs[i] ==
7028 sband->ht_cap.mcs.rx_mask[i])
7029 ht_nss_mask |= BIT(i);
7034 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7035 if (mask->control[band].vht_mcs[i] == 0)
7037 else if (mask->control[band].vht_mcs[i] ==
7038 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
7039 vht_nss_mask |= BIT(i);
7044 if (ht_nss_mask != vht_nss_mask)
7047 if (ht_nss_mask == 0)
7050 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
7053 *nss = fls(ht_nss_mask);
7059 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
7060 enum nl80211_band band,
7061 const struct cfg80211_bitrate_mask *mask,
7070 if (hweight32(mask->control[band].legacy) == 1) {
7071 rate_idx = ffs(mask->control[band].legacy) - 1;
7073 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
7074 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
7076 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
7077 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
7079 if (ath10k_mac_bitrate_is_cck(bitrate))
7080 preamble = WMI_RATE_PREAMBLE_CCK;
7082 preamble = WMI_RATE_PREAMBLE_OFDM;
7085 *rate = preamble << 6 |
7092 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7093 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
7095 *rate = WMI_RATE_PREAMBLE_HT << 6 |
7097 (ffs(mask->control[band].ht_mcs[i]) - 1);
7103 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7104 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
7106 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
7108 (ffs(mask->control[band].vht_mcs[i]) - 1);
7117 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
7118 u8 rate, u8 nss, u8 sgi, u8 ldpc)
7120 struct ath10k *ar = arvif->ar;
7124 lockdep_assert_held(&ar->conf_mutex);
7126 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7127 arvif->vdev_id, rate, nss, sgi);
7129 vdev_param = ar->wmi.vdev_param->fixed_rate;
7130 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
7132 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
7137 vdev_param = ar->wmi.vdev_param->nss;
7138 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
7140 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
7144 vdev_param = ar->wmi.vdev_param->sgi;
7145 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
7147 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
7151 vdev_param = ar->wmi.vdev_param->ldpc;
7152 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
7154 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
7162 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
7163 enum nl80211_band band,
7164 const struct cfg80211_bitrate_mask *mask)
7169 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7170 * to express all VHT MCS rate masks. Effectively only the following
7171 * ranges can be used: none, 0-7, 0-8 and 0-9.
7173 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7174 vht_mcs = mask->control[band].vht_mcs[i];
7183 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7191 static void ath10k_mac_set_bitrate_mask_iter(void *data,
7192 struct ieee80211_sta *sta)
7194 struct ath10k_vif *arvif = data;
7195 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7196 struct ath10k *ar = arvif->ar;
7198 if (arsta->arvif != arvif)
7201 spin_lock_bh(&ar->data_lock);
7202 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7203 spin_unlock_bh(&ar->data_lock);
7205 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7208 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7209 struct ieee80211_vif *vif,
7210 const struct cfg80211_bitrate_mask *mask)
7212 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7213 struct cfg80211_chan_def def;
7214 struct ath10k *ar = arvif->ar;
7215 enum nl80211_band band;
7216 const u8 *ht_mcs_mask;
7217 const u16 *vht_mcs_mask;
7225 if (ath10k_mac_vif_chan(vif, &def))
7228 band = def.chan->band;
7229 ht_mcs_mask = mask->control[band].ht_mcs;
7230 vht_mcs_mask = mask->control[band].vht_mcs;
7231 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7233 sgi = mask->control[band].gi;
7234 if (sgi == NL80211_TXRATE_FORCE_LGI)
7237 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7238 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7241 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7242 arvif->vdev_id, ret);
7245 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7247 rate = WMI_FIXED_RATE_NONE;
7250 rate = WMI_FIXED_RATE_NONE;
7251 nss = min(ar->num_rf_chains,
7252 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7253 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7255 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7258 mutex_lock(&ar->conf_mutex);
7260 arvif->bitrate_mask = *mask;
7261 ieee80211_iterate_stations_atomic(ar->hw,
7262 ath10k_mac_set_bitrate_mask_iter,
7265 mutex_unlock(&ar->conf_mutex);
7268 mutex_lock(&ar->conf_mutex);
7270 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7272 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7273 arvif->vdev_id, ret);
7278 mutex_unlock(&ar->conf_mutex);
7283 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7284 struct ieee80211_vif *vif,
7285 struct ieee80211_sta *sta,
7288 struct ath10k *ar = hw->priv;
7289 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7290 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7291 struct ath10k_peer *peer;
7294 spin_lock_bh(&ar->data_lock);
7296 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7298 spin_unlock_bh(&ar->data_lock);
7299 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7300 sta->addr, arvif->vdev_id);
7304 ath10k_dbg(ar, ATH10K_DBG_MAC,
7305 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7306 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7309 if (changed & IEEE80211_RC_BW_CHANGED) {
7310 bw = WMI_PEER_CHWIDTH_20MHZ;
7312 switch (sta->bandwidth) {
7313 case IEEE80211_STA_RX_BW_20:
7314 bw = WMI_PEER_CHWIDTH_20MHZ;
7316 case IEEE80211_STA_RX_BW_40:
7317 bw = WMI_PEER_CHWIDTH_40MHZ;
7319 case IEEE80211_STA_RX_BW_80:
7320 bw = WMI_PEER_CHWIDTH_80MHZ;
7322 case IEEE80211_STA_RX_BW_160:
7323 bw = WMI_PEER_CHWIDTH_160MHZ;
7326 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7327 sta->bandwidth, sta->addr);
7328 bw = WMI_PEER_CHWIDTH_20MHZ;
7335 if (changed & IEEE80211_RC_NSS_CHANGED)
7336 arsta->nss = sta->rx_nss;
7338 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7339 smps = WMI_PEER_SMPS_PS_NONE;
7341 switch (sta->smps_mode) {
7342 case IEEE80211_SMPS_AUTOMATIC:
7343 case IEEE80211_SMPS_OFF:
7344 smps = WMI_PEER_SMPS_PS_NONE;
7346 case IEEE80211_SMPS_STATIC:
7347 smps = WMI_PEER_SMPS_STATIC;
7349 case IEEE80211_SMPS_DYNAMIC:
7350 smps = WMI_PEER_SMPS_DYNAMIC;
7352 case IEEE80211_SMPS_NUM_MODES:
7353 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7354 sta->smps_mode, sta->addr);
7355 smps = WMI_PEER_SMPS_PS_NONE;
7362 arsta->changed |= changed;
7364 spin_unlock_bh(&ar->data_lock);
7366 ieee80211_queue_work(hw, &arsta->update_wk);
7369 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7370 struct ieee80211_vif *vif, s64 tsf_offset)
7372 struct ath10k *ar = hw->priv;
7373 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7374 u32 offset, vdev_param;
7377 if (tsf_offset < 0) {
7378 vdev_param = ar->wmi.vdev_param->dec_tsf;
7379 offset = -tsf_offset;
7381 vdev_param = ar->wmi.vdev_param->inc_tsf;
7382 offset = tsf_offset;
7385 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7386 vdev_param, offset);
7388 if (ret && ret != -EOPNOTSUPP)
7389 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7390 offset, vdev_param, ret);
7393 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7394 struct ieee80211_vif *vif,
7395 struct ieee80211_ampdu_params *params)
7397 struct ath10k *ar = hw->priv;
7398 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7399 struct ieee80211_sta *sta = params->sta;
7400 enum ieee80211_ampdu_mlme_action action = params->action;
7401 u16 tid = params->tid;
7403 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7404 arvif->vdev_id, sta->addr, tid, action);
7407 case IEEE80211_AMPDU_RX_START:
7408 case IEEE80211_AMPDU_RX_STOP:
7409 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7410 * creation/removal. Do we need to verify this?
7413 case IEEE80211_AMPDU_TX_START:
7414 case IEEE80211_AMPDU_TX_STOP_CONT:
7415 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7416 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7417 case IEEE80211_AMPDU_TX_OPERATIONAL:
7418 /* Firmware offloads Tx aggregation entirely so deny mac80211
7419 * Tx aggregation requests.
7428 ath10k_mac_update_rx_channel(struct ath10k *ar,
7429 struct ieee80211_chanctx_conf *ctx,
7430 struct ieee80211_vif_chanctx_switch *vifs,
7433 struct cfg80211_chan_def *def = NULL;
7435 /* Both locks are required because ar->rx_channel is modified. This
7436 * allows readers to hold either lock.
7438 lockdep_assert_held(&ar->conf_mutex);
7439 lockdep_assert_held(&ar->data_lock);
7441 WARN_ON(ctx && vifs);
7442 WARN_ON(vifs && !n_vifs);
7444 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7445 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7446 * ppdu on Rx may reduce performance on low-end systems. It should be
7447 * possible to make tables/hashmaps to speed the lookup up (be vary of
7448 * cpu data cache lines though regarding sizes) but to keep the initial
7449 * implementation simple and less intrusive fallback to the slow lookup
7450 * only for multi-channel cases. Single-channel cases will remain to
7451 * use the old channel derival and thus performance should not be
7455 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7456 ieee80211_iter_chan_contexts_atomic(ar->hw,
7457 ath10k_mac_get_any_chandef_iter,
7461 def = &vifs[0].new_ctx->def;
7463 ar->rx_channel = def->chan;
7464 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7465 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7466 /* During driver restart due to firmware assert, since mac80211
7467 * already has valid channel context for given radio, channel
7468 * context iteration return num_chanctx > 0. So fix rx_channel
7469 * when restart is in progress.
7471 ar->rx_channel = ctx->def.chan;
7473 ar->rx_channel = NULL;
7479 ath10k_mac_update_vif_chan(struct ath10k *ar,
7480 struct ieee80211_vif_chanctx_switch *vifs,
7483 struct ath10k_vif *arvif;
7487 lockdep_assert_held(&ar->conf_mutex);
7489 /* First stop monitor interface. Some FW versions crash if there's a
7490 * lone monitor interface.
7492 if (ar->monitor_started)
7493 ath10k_monitor_stop(ar);
7495 for (i = 0; i < n_vifs; i++) {
7496 arvif = (void *)vifs[i].vif->drv_priv;
7498 ath10k_dbg(ar, ATH10K_DBG_MAC,
7499 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7501 vifs[i].old_ctx->def.chan->center_freq,
7502 vifs[i].new_ctx->def.chan->center_freq,
7503 vifs[i].old_ctx->def.width,
7504 vifs[i].new_ctx->def.width);
7506 if (WARN_ON(!arvif->is_started))
7509 if (WARN_ON(!arvif->is_up))
7512 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7514 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7515 arvif->vdev_id, ret);
7520 /* All relevant vdevs are downed and associated channel resources
7521 * should be available for the channel switch now.
7524 spin_lock_bh(&ar->data_lock);
7525 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7526 spin_unlock_bh(&ar->data_lock);
7528 for (i = 0; i < n_vifs; i++) {
7529 arvif = (void *)vifs[i].vif->drv_priv;
7531 if (WARN_ON(!arvif->is_started))
7534 if (WARN_ON(!arvif->is_up))
7537 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7539 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7542 ret = ath10k_mac_setup_prb_tmpl(arvif);
7544 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7547 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7549 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7550 arvif->vdev_id, ret);
7554 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7557 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7558 arvif->vdev_id, ret);
7563 ath10k_monitor_recalc(ar);
7567 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7568 struct ieee80211_chanctx_conf *ctx)
7570 struct ath10k *ar = hw->priv;
7572 ath10k_dbg(ar, ATH10K_DBG_MAC,
7573 "mac chanctx add freq %hu width %d ptr %pK\n",
7574 ctx->def.chan->center_freq, ctx->def.width, ctx);
7576 mutex_lock(&ar->conf_mutex);
7578 spin_lock_bh(&ar->data_lock);
7579 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7580 spin_unlock_bh(&ar->data_lock);
7582 ath10k_recalc_radar_detection(ar);
7583 ath10k_monitor_recalc(ar);
7585 mutex_unlock(&ar->conf_mutex);
7591 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7592 struct ieee80211_chanctx_conf *ctx)
7594 struct ath10k *ar = hw->priv;
7596 ath10k_dbg(ar, ATH10K_DBG_MAC,
7597 "mac chanctx remove freq %hu width %d ptr %pK\n",
7598 ctx->def.chan->center_freq, ctx->def.width, ctx);
7600 mutex_lock(&ar->conf_mutex);
7602 spin_lock_bh(&ar->data_lock);
7603 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7604 spin_unlock_bh(&ar->data_lock);
7606 ath10k_recalc_radar_detection(ar);
7607 ath10k_monitor_recalc(ar);
7609 mutex_unlock(&ar->conf_mutex);
7612 struct ath10k_mac_change_chanctx_arg {
7613 struct ieee80211_chanctx_conf *ctx;
7614 struct ieee80211_vif_chanctx_switch *vifs;
7620 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7621 struct ieee80211_vif *vif)
7623 struct ath10k_mac_change_chanctx_arg *arg = data;
7625 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7632 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7633 struct ieee80211_vif *vif)
7635 struct ath10k_mac_change_chanctx_arg *arg = data;
7636 struct ieee80211_chanctx_conf *ctx;
7638 ctx = rcu_access_pointer(vif->chanctx_conf);
7639 if (ctx != arg->ctx)
7642 if (WARN_ON(arg->next_vif == arg->n_vifs))
7645 arg->vifs[arg->next_vif].vif = vif;
7646 arg->vifs[arg->next_vif].old_ctx = ctx;
7647 arg->vifs[arg->next_vif].new_ctx = ctx;
7652 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7653 struct ieee80211_chanctx_conf *ctx,
7656 struct ath10k *ar = hw->priv;
7657 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7659 mutex_lock(&ar->conf_mutex);
7661 ath10k_dbg(ar, ATH10K_DBG_MAC,
7662 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7663 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7665 /* This shouldn't really happen because channel switching should use
7666 * switch_vif_chanctx().
7668 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7671 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7672 ieee80211_iterate_active_interfaces_atomic(
7674 IEEE80211_IFACE_ITER_NORMAL,
7675 ath10k_mac_change_chanctx_cnt_iter,
7677 if (arg.n_vifs == 0)
7680 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7685 ieee80211_iterate_active_interfaces_atomic(
7687 IEEE80211_IFACE_ITER_NORMAL,
7688 ath10k_mac_change_chanctx_fill_iter,
7690 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7695 ath10k_recalc_radar_detection(ar);
7697 /* FIXME: How to configure Rx chains properly? */
7699 /* No other actions are actually necessary. Firmware maintains channel
7700 * definitions per vdev internally and there's no host-side channel
7701 * context abstraction to configure, e.g. channel width.
7705 mutex_unlock(&ar->conf_mutex);
7709 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7710 struct ieee80211_vif *vif,
7711 struct ieee80211_chanctx_conf *ctx)
7713 struct ath10k *ar = hw->priv;
7714 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7717 mutex_lock(&ar->conf_mutex);
7719 ath10k_dbg(ar, ATH10K_DBG_MAC,
7720 "mac chanctx assign ptr %pK vdev_id %i\n",
7721 ctx, arvif->vdev_id);
7723 if (WARN_ON(arvif->is_started)) {
7724 mutex_unlock(&ar->conf_mutex);
7728 ret = ath10k_vdev_start(arvif, &ctx->def);
7730 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7731 arvif->vdev_id, vif->addr,
7732 ctx->def.chan->center_freq, ret);
7736 arvif->is_started = true;
7738 ret = ath10k_mac_vif_setup_ps(arvif);
7740 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7741 arvif->vdev_id, ret);
7745 if (vif->type == NL80211_IFTYPE_MONITOR) {
7746 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7748 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7749 arvif->vdev_id, ret);
7753 arvif->is_up = true;
7756 if (ath10k_mac_can_set_cts_prot(arvif)) {
7757 ret = ath10k_mac_set_cts_prot(arvif);
7759 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7760 arvif->vdev_id, ret);
7763 if (ath10k_peer_stats_enabled(ar)) {
7764 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
7765 ret = ath10k_wmi_pdev_pktlog_enable(ar,
7768 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
7773 mutex_unlock(&ar->conf_mutex);
7777 ath10k_vdev_stop(arvif);
7778 arvif->is_started = false;
7779 ath10k_mac_vif_setup_ps(arvif);
7782 mutex_unlock(&ar->conf_mutex);
7787 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7788 struct ieee80211_vif *vif,
7789 struct ieee80211_chanctx_conf *ctx)
7791 struct ath10k *ar = hw->priv;
7792 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7795 mutex_lock(&ar->conf_mutex);
7797 ath10k_dbg(ar, ATH10K_DBG_MAC,
7798 "mac chanctx unassign ptr %pK vdev_id %i\n",
7799 ctx, arvif->vdev_id);
7801 WARN_ON(!arvif->is_started);
7803 if (vif->type == NL80211_IFTYPE_MONITOR) {
7804 WARN_ON(!arvif->is_up);
7806 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7808 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7809 arvif->vdev_id, ret);
7811 arvif->is_up = false;
7814 ret = ath10k_vdev_stop(arvif);
7816 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7817 arvif->vdev_id, ret);
7819 arvif->is_started = false;
7821 mutex_unlock(&ar->conf_mutex);
7825 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7826 struct ieee80211_vif_chanctx_switch *vifs,
7828 enum ieee80211_chanctx_switch_mode mode)
7830 struct ath10k *ar = hw->priv;
7832 mutex_lock(&ar->conf_mutex);
7834 ath10k_dbg(ar, ATH10K_DBG_MAC,
7835 "mac chanctx switch n_vifs %d mode %d\n",
7837 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7839 mutex_unlock(&ar->conf_mutex);
7843 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7844 struct ieee80211_vif *vif,
7845 struct ieee80211_sta *sta)
7848 struct ath10k_peer *peer;
7852 list_for_each_entry(peer, &ar->peers, list)
7853 if (peer->sta == sta)
7854 peer->removed = true;
7857 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
7858 struct ieee80211_vif *vif,
7859 struct ieee80211_sta *sta,
7860 struct station_info *sinfo)
7862 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7863 struct ath10k *ar = arsta->arvif->ar;
7865 if (!ath10k_peer_stats_enabled(ar))
7868 sinfo->rx_duration = arsta->rx_duration;
7869 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
7871 if (!arsta->txrate.legacy && !arsta->txrate.nss)
7874 if (arsta->txrate.legacy) {
7875 sinfo->txrate.legacy = arsta->txrate.legacy;
7877 sinfo->txrate.mcs = arsta->txrate.mcs;
7878 sinfo->txrate.nss = arsta->txrate.nss;
7879 sinfo->txrate.bw = arsta->txrate.bw;
7881 sinfo->txrate.flags = arsta->txrate.flags;
7882 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
7885 static const struct ieee80211_ops ath10k_ops = {
7886 .tx = ath10k_mac_op_tx,
7887 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7888 .start = ath10k_start,
7889 .stop = ath10k_stop,
7890 .config = ath10k_config,
7891 .add_interface = ath10k_add_interface,
7892 .remove_interface = ath10k_remove_interface,
7893 .configure_filter = ath10k_configure_filter,
7894 .bss_info_changed = ath10k_bss_info_changed,
7895 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7896 .hw_scan = ath10k_hw_scan,
7897 .cancel_hw_scan = ath10k_cancel_hw_scan,
7898 .set_key = ath10k_set_key,
7899 .set_default_unicast_key = ath10k_set_default_unicast_key,
7900 .sta_state = ath10k_sta_state,
7901 .conf_tx = ath10k_conf_tx,
7902 .remain_on_channel = ath10k_remain_on_channel,
7903 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7904 .set_rts_threshold = ath10k_set_rts_threshold,
7905 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7906 .flush = ath10k_flush,
7907 .tx_last_beacon = ath10k_tx_last_beacon,
7908 .set_antenna = ath10k_set_antenna,
7909 .get_antenna = ath10k_get_antenna,
7910 .reconfig_complete = ath10k_reconfig_complete,
7911 .get_survey = ath10k_get_survey,
7912 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7913 .sta_rc_update = ath10k_sta_rc_update,
7914 .offset_tsf = ath10k_offset_tsf,
7915 .ampdu_action = ath10k_ampdu_action,
7916 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7917 .get_et_stats = ath10k_debug_get_et_stats,
7918 .get_et_strings = ath10k_debug_get_et_strings,
7919 .add_chanctx = ath10k_mac_op_add_chanctx,
7920 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7921 .change_chanctx = ath10k_mac_op_change_chanctx,
7922 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7923 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7924 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7925 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7926 .sta_statistics = ath10k_sta_statistics,
7928 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7931 .suspend = ath10k_wow_op_suspend,
7932 .resume = ath10k_wow_op_resume,
7933 .set_wakeup = ath10k_wow_op_set_wakeup,
7935 #ifdef CONFIG_MAC80211_DEBUGFS
7936 .sta_add_debugfs = ath10k_sta_add_debugfs,
7940 #define CHAN2G(_channel, _freq, _flags) { \
7941 .band = NL80211_BAND_2GHZ, \
7942 .hw_value = (_channel), \
7943 .center_freq = (_freq), \
7944 .flags = (_flags), \
7945 .max_antenna_gain = 0, \
7949 #define CHAN5G(_channel, _freq, _flags) { \
7950 .band = NL80211_BAND_5GHZ, \
7951 .hw_value = (_channel), \
7952 .center_freq = (_freq), \
7953 .flags = (_flags), \
7954 .max_antenna_gain = 0, \
7958 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7968 CHAN2G(10, 2457, 0),
7969 CHAN2G(11, 2462, 0),
7970 CHAN2G(12, 2467, 0),
7971 CHAN2G(13, 2472, 0),
7972 CHAN2G(14, 2484, 0),
7975 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7976 CHAN5G(36, 5180, 0),
7977 CHAN5G(40, 5200, 0),
7978 CHAN5G(44, 5220, 0),
7979 CHAN5G(48, 5240, 0),
7980 CHAN5G(52, 5260, 0),
7981 CHAN5G(56, 5280, 0),
7982 CHAN5G(60, 5300, 0),
7983 CHAN5G(64, 5320, 0),
7984 CHAN5G(100, 5500, 0),
7985 CHAN5G(104, 5520, 0),
7986 CHAN5G(108, 5540, 0),
7987 CHAN5G(112, 5560, 0),
7988 CHAN5G(116, 5580, 0),
7989 CHAN5G(120, 5600, 0),
7990 CHAN5G(124, 5620, 0),
7991 CHAN5G(128, 5640, 0),
7992 CHAN5G(132, 5660, 0),
7993 CHAN5G(136, 5680, 0),
7994 CHAN5G(140, 5700, 0),
7995 CHAN5G(144, 5720, 0),
7996 CHAN5G(149, 5745, 0),
7997 CHAN5G(153, 5765, 0),
7998 CHAN5G(157, 5785, 0),
7999 CHAN5G(161, 5805, 0),
8000 CHAN5G(165, 5825, 0),
8001 CHAN5G(169, 5845, 0),
8002 CHAN5G(173, 5865, 0),
8003 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
8004 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
8007 struct ath10k *ath10k_mac_create(size_t priv_size)
8009 struct ieee80211_hw *hw;
8010 struct ieee80211_ops *ops;
8013 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
8017 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
8030 void ath10k_mac_destroy(struct ath10k *ar)
8032 struct ieee80211_ops *ops = ar->ops;
8034 ieee80211_free_hw(ar->hw);
8038 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
8041 .types = BIT(NL80211_IFTYPE_STATION)
8042 | BIT(NL80211_IFTYPE_P2P_CLIENT)
8046 .types = BIT(NL80211_IFTYPE_P2P_GO)
8050 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
8054 .types = BIT(NL80211_IFTYPE_AP)
8055 #ifdef CONFIG_MAC80211_MESH
8056 | BIT(NL80211_IFTYPE_MESH_POINT)
8061 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
8064 .types = BIT(NL80211_IFTYPE_AP)
8065 #ifdef CONFIG_MAC80211_MESH
8066 | BIT(NL80211_IFTYPE_MESH_POINT)
8071 .types = BIT(NL80211_IFTYPE_STATION)
8075 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
8077 .limits = ath10k_if_limits,
8078 .n_limits = ARRAY_SIZE(ath10k_if_limits),
8079 .max_interfaces = 8,
8080 .num_different_channels = 1,
8081 .beacon_int_infra_match = true,
8085 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
8087 .limits = ath10k_10x_if_limits,
8088 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
8089 .max_interfaces = 8,
8090 .num_different_channels = 1,
8091 .beacon_int_infra_match = true,
8092 .beacon_int_min_gcd = 1,
8093 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8094 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8095 BIT(NL80211_CHAN_WIDTH_20) |
8096 BIT(NL80211_CHAN_WIDTH_40) |
8097 BIT(NL80211_CHAN_WIDTH_80),
8102 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
8105 .types = BIT(NL80211_IFTYPE_STATION),
8109 .types = BIT(NL80211_IFTYPE_AP) |
8110 #ifdef CONFIG_MAC80211_MESH
8111 BIT(NL80211_IFTYPE_MESH_POINT) |
8113 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8114 BIT(NL80211_IFTYPE_P2P_GO),
8118 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8122 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
8125 .types = BIT(NL80211_IFTYPE_STATION),
8129 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
8133 .types = BIT(NL80211_IFTYPE_AP) |
8134 #ifdef CONFIG_MAC80211_MESH
8135 BIT(NL80211_IFTYPE_MESH_POINT) |
8137 BIT(NL80211_IFTYPE_P2P_GO),
8141 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8145 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
8148 .types = BIT(NL80211_IFTYPE_STATION),
8152 .types = BIT(NL80211_IFTYPE_ADHOC),
8156 /* FIXME: This is not thouroughly tested. These combinations may over- or
8157 * underestimate hw/fw capabilities.
8159 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
8161 .limits = ath10k_tlv_if_limit,
8162 .num_different_channels = 1,
8163 .max_interfaces = 4,
8164 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8167 .limits = ath10k_tlv_if_limit_ibss,
8168 .num_different_channels = 1,
8169 .max_interfaces = 2,
8170 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8174 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
8176 .limits = ath10k_tlv_if_limit,
8177 .num_different_channels = 1,
8178 .max_interfaces = 4,
8179 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8182 .limits = ath10k_tlv_qcs_if_limit,
8183 .num_different_channels = 2,
8184 .max_interfaces = 4,
8185 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
8188 .limits = ath10k_tlv_if_limit_ibss,
8189 .num_different_channels = 1,
8190 .max_interfaces = 2,
8191 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8195 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8198 .types = BIT(NL80211_IFTYPE_STATION),
8202 .types = BIT(NL80211_IFTYPE_AP)
8203 #ifdef CONFIG_MAC80211_MESH
8204 | BIT(NL80211_IFTYPE_MESH_POINT)
8209 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8211 .limits = ath10k_10_4_if_limits,
8212 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8213 .max_interfaces = 16,
8214 .num_different_channels = 1,
8215 .beacon_int_infra_match = true,
8216 .beacon_int_min_gcd = 1,
8217 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8218 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8219 BIT(NL80211_CHAN_WIDTH_20) |
8220 BIT(NL80211_CHAN_WIDTH_40) |
8221 BIT(NL80211_CHAN_WIDTH_80),
8227 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = {
8229 .limits = ath10k_10_4_if_limits,
8230 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8231 .max_interfaces = 16,
8232 .num_different_channels = 1,
8233 .beacon_int_infra_match = true,
8234 .beacon_int_min_gcd = 100,
8235 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8236 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8237 BIT(NL80211_CHAN_WIDTH_20) |
8238 BIT(NL80211_CHAN_WIDTH_40) |
8239 BIT(NL80211_CHAN_WIDTH_80),
8244 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8245 struct ieee80211_vif *vif)
8247 struct ath10k_vif_iter *arvif_iter = data;
8248 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8250 if (arvif->vdev_id == arvif_iter->vdev_id)
8251 arvif_iter->arvif = arvif;
8254 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8256 struct ath10k_vif_iter arvif_iter;
8259 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8260 arvif_iter.vdev_id = vdev_id;
8262 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8263 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8265 ath10k_get_arvif_iter,
8267 if (!arvif_iter.arvif) {
8268 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8272 return arvif_iter.arvif;
8275 #define WRD_METHOD "WRDD"
8276 #define WRDD_WIFI (0x07)
8278 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8280 union acpi_object *mcc_pkg;
8281 union acpi_object *domain_type;
8282 union acpi_object *mcc_value;
8285 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8286 wrdd->package.count < 2 ||
8287 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8288 wrdd->package.elements[0].integer.value != 0) {
8289 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8293 for (i = 1; i < wrdd->package.count; ++i) {
8294 mcc_pkg = &wrdd->package.elements[i];
8296 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8298 if (mcc_pkg->package.count < 2)
8300 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8301 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8304 domain_type = &mcc_pkg->package.elements[0];
8305 if (domain_type->integer.value != WRDD_WIFI)
8308 mcc_value = &mcc_pkg->package.elements[1];
8309 return mcc_value->integer.value;
8314 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8316 struct pci_dev __maybe_unused *pdev = to_pci_dev(ar->dev);
8317 acpi_handle root_handle;
8319 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8324 root_handle = ACPI_HANDLE(&pdev->dev);
8328 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8329 if (ACPI_FAILURE(status)) {
8330 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8331 "failed to get wrd method %d\n", status);
8335 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8336 if (ACPI_FAILURE(status)) {
8337 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8338 "failed to call wrdc %d\n", status);
8342 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8343 kfree(wrdd.pointer);
8347 alpha2[0] = (alpha2_code >> 8) & 0xff;
8348 alpha2[1] = (alpha2_code >> 0) & 0xff;
8351 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8352 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8354 *rd = ath_regd_find_country_by_name(alpha2);
8358 *rd |= COUNTRY_ERD_FLAG;
8362 static int ath10k_mac_init_rd(struct ath10k *ar)
8367 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8369 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8370 "fallback to eeprom programmed regulatory settings\n");
8371 rd = ar->hw_eeprom_rd;
8374 ar->ath_common.regulatory.current_rd = rd;
8378 int ath10k_mac_register(struct ath10k *ar)
8380 static const u32 cipher_suites[] = {
8381 WLAN_CIPHER_SUITE_WEP40,
8382 WLAN_CIPHER_SUITE_WEP104,
8383 WLAN_CIPHER_SUITE_TKIP,
8384 WLAN_CIPHER_SUITE_CCMP,
8386 /* Do not add hardware supported ciphers before this line.
8387 * Allow software encryption for all chips. Don't forget to
8388 * update n_cipher_suites below.
8390 WLAN_CIPHER_SUITE_AES_CMAC,
8391 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8392 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8393 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8395 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8396 * and CCMP-256 in hardware.
8398 WLAN_CIPHER_SUITE_GCMP,
8399 WLAN_CIPHER_SUITE_GCMP_256,
8400 WLAN_CIPHER_SUITE_CCMP_256,
8402 struct ieee80211_supported_band *band;
8406 if (!is_valid_ether_addr(ar->mac_addr)) {
8407 ath10k_warn(ar, "invalid MAC address; choosing random\n");
8408 eth_random_addr(ar->mac_addr);
8410 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8412 SET_IEEE80211_DEV(ar->hw, ar->dev);
8414 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8415 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8418 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8419 channels = kmemdup(ath10k_2ghz_channels,
8420 sizeof(ath10k_2ghz_channels),
8427 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8428 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8429 band->channels = channels;
8431 if (ar->hw_params.cck_rate_map_rev2) {
8432 band->n_bitrates = ath10k_g_rates_rev2_size;
8433 band->bitrates = ath10k_g_rates_rev2;
8435 band->n_bitrates = ath10k_g_rates_size;
8436 band->bitrates = ath10k_g_rates;
8439 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8442 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8443 channels = kmemdup(ath10k_5ghz_channels,
8444 sizeof(ath10k_5ghz_channels),
8451 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8452 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8453 band->channels = channels;
8454 band->n_bitrates = ath10k_a_rates_size;
8455 band->bitrates = ath10k_a_rates;
8456 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8459 wiphy_read_of_freq_limits(ar->hw->wiphy);
8460 ath10k_mac_setup_ht_vht_cap(ar);
8462 ar->hw->wiphy->interface_modes =
8463 BIT(NL80211_IFTYPE_STATION) |
8464 BIT(NL80211_IFTYPE_AP) |
8465 BIT(NL80211_IFTYPE_MESH_POINT);
8467 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8468 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8470 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8471 ar->hw->wiphy->interface_modes |=
8472 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8473 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8474 BIT(NL80211_IFTYPE_P2P_GO);
8476 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8478 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
8479 ar->running_fw->fw_file.fw_features)) {
8480 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8481 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8484 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8485 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8486 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8487 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8488 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8489 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8490 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8491 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8492 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8493 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8494 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8495 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8496 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8498 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8499 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8501 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8502 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8504 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8505 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8507 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8508 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8509 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8512 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8513 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8515 if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
8516 ar->hw->wiphy->max_sched_scan_reqs = 1;
8517 ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
8518 ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
8519 ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
8520 ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
8521 ar->hw->wiphy->max_sched_scan_plan_interval =
8522 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
8523 ar->hw->wiphy->max_sched_scan_plan_iterations =
8524 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
8527 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8528 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8529 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8531 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8533 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8534 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8536 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8537 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8538 * correct Probe Responses. This is more of a hack advert..
8540 ar->hw->wiphy->probe_resp_offload |=
8541 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8542 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8543 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8546 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8547 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8548 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8549 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
8550 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8553 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8554 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
8556 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8557 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8558 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8560 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8561 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8562 NL80211_FEATURE_AP_SCAN;
8564 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8566 ret = ath10k_wow_init(ar);
8568 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8572 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8573 wiphy_ext_feature_set(ar->hw->wiphy,
8574 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
8576 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) ||
8577 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map))
8578 wiphy_ext_feature_set(ar->hw->wiphy,
8579 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
8582 * on LL hardware queues are managed entirely by the FW
8583 * so we only advertise to mac we can do the queues thing
8585 ar->hw->queues = IEEE80211_MAX_QUEUES;
8587 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8588 * something that vdev_ids can't reach so that we don't stop the queue
8591 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8593 switch (ar->running_fw->fw_file.wmi_op_version) {
8594 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8595 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8596 ar->hw->wiphy->n_iface_combinations =
8597 ARRAY_SIZE(ath10k_if_comb);
8598 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8600 case ATH10K_FW_WMI_OP_VERSION_TLV:
8601 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8602 ar->hw->wiphy->iface_combinations =
8603 ath10k_tlv_qcs_if_comb;
8604 ar->hw->wiphy->n_iface_combinations =
8605 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8607 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8608 ar->hw->wiphy->n_iface_combinations =
8609 ARRAY_SIZE(ath10k_tlv_if_comb);
8611 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8613 case ATH10K_FW_WMI_OP_VERSION_10_1:
8614 case ATH10K_FW_WMI_OP_VERSION_10_2:
8615 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8616 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8617 ar->hw->wiphy->n_iface_combinations =
8618 ARRAY_SIZE(ath10k_10x_if_comb);
8620 case ATH10K_FW_WMI_OP_VERSION_10_4:
8621 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8622 ar->hw->wiphy->n_iface_combinations =
8623 ARRAY_SIZE(ath10k_10_4_if_comb);
8624 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT,
8626 ar->hw->wiphy->iface_combinations =
8627 ath10k_10_4_bcn_int_if_comb;
8628 ar->hw->wiphy->n_iface_combinations =
8629 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb);
8632 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8633 case ATH10K_FW_WMI_OP_VERSION_MAX:
8639 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8640 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8642 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8643 /* Init ath dfs pattern detector */
8644 ar->ath_common.debug_mask = ATH_DBG_DFS;
8645 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8648 if (!ar->dfs_detector)
8649 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8652 ret = ath10k_mac_init_rd(ar);
8654 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8655 goto err_dfs_detector_exit;
8658 /* Disable set_coverage_class for chipsets that do not support it. */
8659 if (!ar->hw_params.hw_ops->set_coverage_class)
8660 ar->ops->set_coverage_class = NULL;
8662 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8663 ath10k_reg_notifier);
8665 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8666 goto err_dfs_detector_exit;
8669 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
8670 ar->hw->wiphy->features |=
8671 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8674 ar->hw->wiphy->cipher_suites = cipher_suites;
8676 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
8677 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
8678 * from chip specific hw_param table.
8680 if (!ar->hw_params.n_cipher_suites ||
8681 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
8682 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
8683 ar->hw_params.n_cipher_suites);
8684 ar->hw_params.n_cipher_suites = 8;
8686 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
8688 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8690 ret = ieee80211_register_hw(ar->hw);
8692 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8693 goto err_dfs_detector_exit;
8696 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8697 ret = regulatory_hint(ar->hw->wiphy,
8698 ar->ath_common.regulatory.alpha2);
8700 goto err_unregister;
8706 ieee80211_unregister_hw(ar->hw);
8708 err_dfs_detector_exit:
8709 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8710 ar->dfs_detector->exit(ar->dfs_detector);
8713 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8714 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8716 SET_IEEE80211_DEV(ar->hw, NULL);
8720 void ath10k_mac_unregister(struct ath10k *ar)
8722 ieee80211_unregister_hw(ar->hw);
8724 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8725 ar->dfs_detector->exit(ar->dfs_detector);
8727 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8728 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8730 SET_IEEE80211_DEV(ar->hw, NULL);