2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <net/cfg80211.h>
22 #include <net/mac80211.h>
23 #include <linux/etherdevice.h>
24 #include <linux/acpi.h>
42 static struct ieee80211_rate ath10k_rates[] = {
44 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
46 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
47 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
48 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
50 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
51 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
52 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
54 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
55 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
56 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
58 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
59 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
60 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
61 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
62 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
63 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
64 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
65 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
68 static struct ieee80211_rate ath10k_rates_rev2[] = {
70 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
72 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
73 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
74 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
76 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
77 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
78 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
80 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
81 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
82 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
84 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
85 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
86 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
87 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
88 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
89 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
90 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
91 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
94 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
96 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
97 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
98 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
99 #define ath10k_g_rates (ath10k_rates + 0)
100 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
102 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
103 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
105 #define ath10k_wmi_legacy_rates ath10k_rates
107 static bool ath10k_mac_bitrate_is_cck(int bitrate)
120 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
122 return DIV_ROUND_UP(bitrate, 5) |
123 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
126 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
127 u8 hw_rate, bool cck)
129 const struct ieee80211_rate *rate;
132 for (i = 0; i < sband->n_bitrates; i++) {
133 rate = &sband->bitrates[i];
135 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
138 if (rate->hw_value == hw_rate)
140 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
141 rate->hw_value_short == hw_rate)
148 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
153 for (i = 0; i < sband->n_bitrates; i++)
154 if (sband->bitrates[i].bitrate == bitrate)
160 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
162 switch ((mcs_map >> (2 * nss)) & 0x3) {
163 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
164 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
165 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
171 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
175 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
176 if (ht_mcs_mask[nss])
183 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
187 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
188 if (vht_mcs_mask[nss])
194 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
196 enum wmi_host_platform_type platform_type;
199 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
200 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
202 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
204 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
206 if (ret && ret != -EOPNOTSUPP) {
207 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
218 static int ath10k_send_key(struct ath10k_vif *arvif,
219 struct ieee80211_key_conf *key,
220 enum set_key_cmd cmd,
221 const u8 *macaddr, u32 flags)
223 struct ath10k *ar = arvif->ar;
224 struct wmi_vdev_install_key_arg arg = {
225 .vdev_id = arvif->vdev_id,
226 .key_idx = key->keyidx,
227 .key_len = key->keylen,
228 .key_data = key->key,
233 lockdep_assert_held(&arvif->ar->conf_mutex);
235 switch (key->cipher) {
236 case WLAN_CIPHER_SUITE_CCMP:
237 arg.key_cipher = WMI_CIPHER_AES_CCM;
238 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
240 case WLAN_CIPHER_SUITE_TKIP:
241 arg.key_cipher = WMI_CIPHER_TKIP;
242 arg.key_txmic_len = 8;
243 arg.key_rxmic_len = 8;
245 case WLAN_CIPHER_SUITE_WEP40:
246 case WLAN_CIPHER_SUITE_WEP104:
247 arg.key_cipher = WMI_CIPHER_WEP;
249 case WLAN_CIPHER_SUITE_CCMP_256:
250 arg.key_cipher = WMI_CIPHER_AES_CCM;
252 case WLAN_CIPHER_SUITE_GCMP:
253 case WLAN_CIPHER_SUITE_GCMP_256:
254 arg.key_cipher = WMI_CIPHER_AES_GCM;
256 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
257 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
258 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
259 case WLAN_CIPHER_SUITE_AES_CMAC:
263 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
267 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
268 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
270 if (cmd == DISABLE_KEY) {
271 arg.key_cipher = WMI_CIPHER_NONE;
275 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
278 static int ath10k_install_key(struct ath10k_vif *arvif,
279 struct ieee80211_key_conf *key,
280 enum set_key_cmd cmd,
281 const u8 *macaddr, u32 flags)
283 struct ath10k *ar = arvif->ar;
285 unsigned long time_left;
287 lockdep_assert_held(&ar->conf_mutex);
289 reinit_completion(&ar->install_key_done);
291 if (arvif->nohwcrypt)
294 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
298 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
305 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
308 struct ath10k *ar = arvif->ar;
309 struct ath10k_peer *peer;
314 lockdep_assert_held(&ar->conf_mutex);
316 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
317 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
318 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
321 spin_lock_bh(&ar->data_lock);
322 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
323 spin_unlock_bh(&ar->data_lock);
328 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
329 if (arvif->wep_keys[i] == NULL)
332 switch (arvif->vif->type) {
333 case NL80211_IFTYPE_AP:
334 flags = WMI_KEY_PAIRWISE;
336 if (arvif->def_wep_key_idx == i)
337 flags |= WMI_KEY_TX_USAGE;
339 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
340 SET_KEY, addr, flags);
344 case NL80211_IFTYPE_ADHOC:
345 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
351 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
352 SET_KEY, addr, WMI_KEY_GROUP);
361 spin_lock_bh(&ar->data_lock);
362 peer->keys[i] = arvif->wep_keys[i];
363 spin_unlock_bh(&ar->data_lock);
366 /* In some cases (notably with static WEP IBSS with multiple keys)
367 * multicast Tx becomes broken. Both pairwise and groupwise keys are
368 * installed already. Using WMI_KEY_TX_USAGE in different combinations
369 * didn't seem help. Using def_keyid vdev parameter seems to be
370 * effective so use that.
372 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
374 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
377 if (arvif->def_wep_key_idx == -1)
380 ret = ath10k_wmi_vdev_set_param(arvif->ar,
382 arvif->ar->wmi.vdev_param->def_keyid,
383 arvif->def_wep_key_idx);
385 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
386 arvif->vdev_id, ret);
393 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
396 struct ath10k *ar = arvif->ar;
397 struct ath10k_peer *peer;
403 lockdep_assert_held(&ar->conf_mutex);
405 spin_lock_bh(&ar->data_lock);
406 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
407 spin_unlock_bh(&ar->data_lock);
412 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
413 if (peer->keys[i] == NULL)
416 /* key flags are not required to delete the key */
417 ret = ath10k_install_key(arvif, peer->keys[i],
418 DISABLE_KEY, addr, flags);
419 if (ret < 0 && first_errno == 0)
423 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
426 spin_lock_bh(&ar->data_lock);
427 peer->keys[i] = NULL;
428 spin_unlock_bh(&ar->data_lock);
434 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
437 struct ath10k_peer *peer;
440 lockdep_assert_held(&ar->data_lock);
442 /* We don't know which vdev this peer belongs to,
443 * since WMI doesn't give us that information.
445 * FIXME: multi-bss needs to be handled.
447 peer = ath10k_peer_find(ar, 0, addr);
451 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
452 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
459 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
460 struct ieee80211_key_conf *key)
462 struct ath10k *ar = arvif->ar;
463 struct ath10k_peer *peer;
470 lockdep_assert_held(&ar->conf_mutex);
473 /* since ath10k_install_key we can't hold data_lock all the
474 * time, so we try to remove the keys incrementally
476 spin_lock_bh(&ar->data_lock);
478 list_for_each_entry(peer, &ar->peers, list) {
479 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
480 if (peer->keys[i] == key) {
481 ether_addr_copy(addr, peer->addr);
482 peer->keys[i] = NULL;
487 if (i < ARRAY_SIZE(peer->keys))
490 spin_unlock_bh(&ar->data_lock);
492 if (i == ARRAY_SIZE(peer->keys))
494 /* key flags are not required to delete the key */
495 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
496 if (ret < 0 && first_errno == 0)
500 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
507 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
508 struct ieee80211_key_conf *key)
510 struct ath10k *ar = arvif->ar;
511 struct ath10k_peer *peer;
514 lockdep_assert_held(&ar->conf_mutex);
516 list_for_each_entry(peer, &ar->peers, list) {
517 if (ether_addr_equal(peer->addr, arvif->vif->addr))
520 if (ether_addr_equal(peer->addr, arvif->bssid))
523 if (peer->keys[key->keyidx] == key)
526 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
527 arvif->vdev_id, key->keyidx);
529 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
531 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
532 arvif->vdev_id, peer->addr, ret);
540 /*********************/
541 /* General utilities */
542 /*********************/
544 static inline enum wmi_phy_mode
545 chan_to_phymode(const struct cfg80211_chan_def *chandef)
547 enum wmi_phy_mode phymode = MODE_UNKNOWN;
549 switch (chandef->chan->band) {
550 case NL80211_BAND_2GHZ:
551 switch (chandef->width) {
552 case NL80211_CHAN_WIDTH_20_NOHT:
553 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
558 case NL80211_CHAN_WIDTH_20:
559 phymode = MODE_11NG_HT20;
561 case NL80211_CHAN_WIDTH_40:
562 phymode = MODE_11NG_HT40;
564 case NL80211_CHAN_WIDTH_5:
565 case NL80211_CHAN_WIDTH_10:
566 case NL80211_CHAN_WIDTH_80:
567 case NL80211_CHAN_WIDTH_80P80:
568 case NL80211_CHAN_WIDTH_160:
569 phymode = MODE_UNKNOWN;
573 case NL80211_BAND_5GHZ:
574 switch (chandef->width) {
575 case NL80211_CHAN_WIDTH_20_NOHT:
578 case NL80211_CHAN_WIDTH_20:
579 phymode = MODE_11NA_HT20;
581 case NL80211_CHAN_WIDTH_40:
582 phymode = MODE_11NA_HT40;
584 case NL80211_CHAN_WIDTH_80:
585 phymode = MODE_11AC_VHT80;
587 case NL80211_CHAN_WIDTH_160:
588 phymode = MODE_11AC_VHT160;
590 case NL80211_CHAN_WIDTH_80P80:
591 phymode = MODE_11AC_VHT80_80;
593 case NL80211_CHAN_WIDTH_5:
594 case NL80211_CHAN_WIDTH_10:
595 phymode = MODE_UNKNOWN;
603 WARN_ON(phymode == MODE_UNKNOWN);
607 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
610 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
611 * 0 for no restriction
620 switch (mpdudensity) {
626 /* Our lower layer calculations limit our precision to
643 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
644 struct cfg80211_chan_def *def)
646 struct ieee80211_chanctx_conf *conf;
649 conf = rcu_dereference(vif->chanctx_conf);
661 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
662 struct ieee80211_chanctx_conf *conf,
670 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
674 ieee80211_iter_chan_contexts_atomic(ar->hw,
675 ath10k_mac_num_chanctxs_iter,
682 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
683 struct ieee80211_chanctx_conf *conf,
686 struct cfg80211_chan_def **def = data;
691 static int ath10k_peer_create(struct ath10k *ar,
692 struct ieee80211_vif *vif,
693 struct ieee80211_sta *sta,
696 enum wmi_peer_type peer_type)
698 struct ath10k_vif *arvif;
699 struct ath10k_peer *peer;
703 lockdep_assert_held(&ar->conf_mutex);
705 num_peers = ar->num_peers;
707 /* Each vdev consumes a peer entry as well */
708 list_for_each_entry(arvif, &ar->arvifs, list)
711 if (num_peers >= ar->max_num_peers)
714 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
716 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
721 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
723 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
728 spin_lock_bh(&ar->data_lock);
730 peer = ath10k_peer_find(ar, vdev_id, addr);
732 spin_unlock_bh(&ar->data_lock);
733 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
735 ath10k_wmi_peer_delete(ar, vdev_id, addr);
742 spin_unlock_bh(&ar->data_lock);
749 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
751 struct ath10k *ar = arvif->ar;
755 param = ar->wmi.pdev_param->sta_kickout_th;
756 ret = ath10k_wmi_pdev_set_param(ar, param,
757 ATH10K_KICKOUT_THRESHOLD);
759 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
760 arvif->vdev_id, ret);
764 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
765 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
766 ATH10K_KEEPALIVE_MIN_IDLE);
768 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
769 arvif->vdev_id, ret);
773 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
774 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
775 ATH10K_KEEPALIVE_MAX_IDLE);
777 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
778 arvif->vdev_id, ret);
782 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
783 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
784 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
786 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
787 arvif->vdev_id, ret);
794 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
796 struct ath10k *ar = arvif->ar;
799 vdev_param = ar->wmi.vdev_param->rts_threshold;
800 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
803 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
807 lockdep_assert_held(&ar->conf_mutex);
809 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
813 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
822 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
824 struct ath10k_peer *peer, *tmp;
828 lockdep_assert_held(&ar->conf_mutex);
830 spin_lock_bh(&ar->data_lock);
831 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
832 if (peer->vdev_id != vdev_id)
835 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
836 peer->addr, vdev_id);
838 for_each_set_bit(peer_id, peer->peer_ids,
839 ATH10K_MAX_NUM_PEER_IDS) {
840 ar->peer_map[peer_id] = NULL;
843 /* Double check that peer is properly un-referenced from
846 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
847 if (ar->peer_map[i] == peer) {
848 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
849 peer->addr, peer, i);
850 ar->peer_map[i] = NULL;
854 list_del(&peer->list);
858 spin_unlock_bh(&ar->data_lock);
861 static void ath10k_peer_cleanup_all(struct ath10k *ar)
863 struct ath10k_peer *peer, *tmp;
866 lockdep_assert_held(&ar->conf_mutex);
868 spin_lock_bh(&ar->data_lock);
869 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
870 list_del(&peer->list);
874 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
875 ar->peer_map[i] = NULL;
877 spin_unlock_bh(&ar->data_lock);
880 ar->num_stations = 0;
883 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
884 struct ieee80211_sta *sta,
885 enum wmi_tdls_peer_state state)
888 struct wmi_tdls_peer_update_cmd_arg arg = {};
889 struct wmi_tdls_peer_capab_arg cap = {};
890 struct wmi_channel_arg chan_arg = {};
892 lockdep_assert_held(&ar->conf_mutex);
894 arg.vdev_id = vdev_id;
895 arg.peer_state = state;
896 ether_addr_copy(arg.addr, sta->addr);
898 cap.peer_max_sp = sta->max_sp;
899 cap.peer_uapsd_queues = sta->uapsd_queues;
901 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
902 !sta->tdls_initiator)
903 cap.is_peer_responder = 1;
905 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
907 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
908 arg.addr, vdev_id, ret);
915 /************************/
916 /* Interface management */
917 /************************/
919 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
921 struct ath10k *ar = arvif->ar;
923 lockdep_assert_held(&ar->data_lock);
928 if (!arvif->beacon_buf)
929 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
930 arvif->beacon->len, DMA_TO_DEVICE);
932 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
933 arvif->beacon_state != ATH10K_BEACON_SENT))
936 dev_kfree_skb_any(arvif->beacon);
938 arvif->beacon = NULL;
939 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
942 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
944 struct ath10k *ar = arvif->ar;
946 lockdep_assert_held(&ar->data_lock);
948 ath10k_mac_vif_beacon_free(arvif);
950 if (arvif->beacon_buf) {
951 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
952 arvif->beacon_buf, arvif->beacon_paddr);
953 arvif->beacon_buf = NULL;
957 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
959 unsigned long time_left;
961 lockdep_assert_held(&ar->conf_mutex);
963 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
966 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
967 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
971 return ar->last_wmi_vdev_start_status;
974 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
976 struct cfg80211_chan_def *chandef = NULL;
977 struct ieee80211_channel *channel = NULL;
978 struct wmi_vdev_start_request_arg arg = {};
981 lockdep_assert_held(&ar->conf_mutex);
983 ieee80211_iter_chan_contexts_atomic(ar->hw,
984 ath10k_mac_get_any_chandef_iter,
986 if (WARN_ON_ONCE(!chandef))
989 channel = chandef->chan;
991 arg.vdev_id = vdev_id;
992 arg.channel.freq = channel->center_freq;
993 arg.channel.band_center_freq1 = chandef->center_freq1;
994 arg.channel.band_center_freq2 = chandef->center_freq2;
996 /* TODO setup this dynamically, what in case we
997 * don't have any vifs?
999 arg.channel.mode = chan_to_phymode(chandef);
1000 arg.channel.chan_radar =
1001 !!(channel->flags & IEEE80211_CHAN_RADAR);
1003 arg.channel.min_power = 0;
1004 arg.channel.max_power = channel->max_power * 2;
1005 arg.channel.max_reg_power = channel->max_reg_power * 2;
1006 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
1008 reinit_completion(&ar->vdev_setup_done);
1010 ret = ath10k_wmi_vdev_start(ar, &arg);
1012 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1017 ret = ath10k_vdev_setup_sync(ar);
1019 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1024 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1026 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1031 ar->monitor_vdev_id = vdev_id;
1033 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1034 ar->monitor_vdev_id);
1038 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1040 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1041 ar->monitor_vdev_id, ret);
1046 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1050 lockdep_assert_held(&ar->conf_mutex);
1052 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1054 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1055 ar->monitor_vdev_id, ret);
1057 reinit_completion(&ar->vdev_setup_done);
1059 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1061 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1062 ar->monitor_vdev_id, ret);
1064 ret = ath10k_vdev_setup_sync(ar);
1066 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1067 ar->monitor_vdev_id, ret);
1069 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1070 ar->monitor_vdev_id);
1074 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1078 lockdep_assert_held(&ar->conf_mutex);
1080 if (ar->free_vdev_map == 0) {
1081 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1085 bit = __ffs64(ar->free_vdev_map);
1087 ar->monitor_vdev_id = bit;
1089 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1090 WMI_VDEV_TYPE_MONITOR,
1093 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1094 ar->monitor_vdev_id, ret);
1098 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1099 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1100 ar->monitor_vdev_id);
1105 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1109 lockdep_assert_held(&ar->conf_mutex);
1111 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1113 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1114 ar->monitor_vdev_id, ret);
1118 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1120 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1121 ar->monitor_vdev_id);
1125 static int ath10k_monitor_start(struct ath10k *ar)
1129 lockdep_assert_held(&ar->conf_mutex);
1131 ret = ath10k_monitor_vdev_create(ar);
1133 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1137 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1139 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1140 ath10k_monitor_vdev_delete(ar);
1144 ar->monitor_started = true;
1145 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1150 static int ath10k_monitor_stop(struct ath10k *ar)
1154 lockdep_assert_held(&ar->conf_mutex);
1156 ret = ath10k_monitor_vdev_stop(ar);
1158 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1162 ret = ath10k_monitor_vdev_delete(ar);
1164 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1168 ar->monitor_started = false;
1169 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1174 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1178 /* At least one chanctx is required to derive a channel to start
1181 num_ctx = ath10k_mac_num_chanctxs(ar);
1185 /* If there's already an existing special monitor interface then don't
1186 * bother creating another monitor vdev.
1188 if (ar->monitor_arvif)
1191 return ar->monitor ||
1192 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1193 ar->running_fw->fw_file.fw_features) &&
1194 (ar->filter_flags & FIF_OTHER_BSS)) ||
1195 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1198 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1202 num_ctx = ath10k_mac_num_chanctxs(ar);
1204 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1205 * shouldn't allow this but make sure to prevent handling the following
1206 * case anyway since multi-channel DFS hasn't been tested at all.
1208 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1214 static int ath10k_monitor_recalc(struct ath10k *ar)
1220 lockdep_assert_held(&ar->conf_mutex);
1222 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1223 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1225 ath10k_dbg(ar, ATH10K_DBG_MAC,
1226 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1227 ar->monitor_started, needed, allowed);
1229 if (WARN_ON(needed && !allowed)) {
1230 if (ar->monitor_started) {
1231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1233 ret = ath10k_monitor_stop(ar);
1235 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1243 if (needed == ar->monitor_started)
1247 return ath10k_monitor_start(ar);
1249 return ath10k_monitor_stop(ar);
1252 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1254 struct ath10k *ar = arvif->ar;
1256 lockdep_assert_held(&ar->conf_mutex);
1258 if (!arvif->is_started) {
1259 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1266 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1268 struct ath10k *ar = arvif->ar;
1271 lockdep_assert_held(&ar->conf_mutex);
1273 vdev_param = ar->wmi.vdev_param->protection_mode;
1275 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1276 arvif->vdev_id, arvif->use_cts_prot);
1278 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1279 arvif->use_cts_prot ? 1 : 0);
1282 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1284 struct ath10k *ar = arvif->ar;
1285 u32 vdev_param, rts_cts = 0;
1287 lockdep_assert_held(&ar->conf_mutex);
1289 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1291 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1293 if (arvif->num_legacy_stations > 0)
1294 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1295 WMI_RTSCTS_PROFILE);
1297 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1298 WMI_RTSCTS_PROFILE);
1300 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1301 arvif->vdev_id, rts_cts);
1303 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1307 static int ath10k_start_cac(struct ath10k *ar)
1311 lockdep_assert_held(&ar->conf_mutex);
1313 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1315 ret = ath10k_monitor_recalc(ar);
1317 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1318 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1322 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1323 ar->monitor_vdev_id);
1328 static int ath10k_stop_cac(struct ath10k *ar)
1330 lockdep_assert_held(&ar->conf_mutex);
1332 /* CAC is not running - do nothing */
1333 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1336 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1337 ath10k_monitor_stop(ar);
1339 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1344 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1345 struct ieee80211_chanctx_conf *conf,
1350 if (!*ret && conf->radar_enabled)
1354 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1356 bool has_radar = false;
1358 ieee80211_iter_chan_contexts_atomic(ar->hw,
1359 ath10k_mac_has_radar_iter,
1365 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1369 lockdep_assert_held(&ar->conf_mutex);
1371 ath10k_stop_cac(ar);
1373 if (!ath10k_mac_has_radar_enabled(ar))
1376 if (ar->num_started_vdevs > 0)
1379 ret = ath10k_start_cac(ar);
1382 * Not possible to start CAC on current channel so starting
1383 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1384 * by indicating that radar was detected.
1386 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1387 ieee80211_radar_detected(ar->hw);
1391 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1393 struct ath10k *ar = arvif->ar;
1396 lockdep_assert_held(&ar->conf_mutex);
1398 reinit_completion(&ar->vdev_setup_done);
1400 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1402 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1403 arvif->vdev_id, ret);
1407 ret = ath10k_vdev_setup_sync(ar);
1409 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1410 arvif->vdev_id, ret);
1414 WARN_ON(ar->num_started_vdevs == 0);
1416 if (ar->num_started_vdevs != 0) {
1417 ar->num_started_vdevs--;
1418 ath10k_recalc_radar_detection(ar);
1424 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1425 const struct cfg80211_chan_def *chandef,
1428 struct ath10k *ar = arvif->ar;
1429 struct wmi_vdev_start_request_arg arg = {};
1432 lockdep_assert_held(&ar->conf_mutex);
1434 reinit_completion(&ar->vdev_setup_done);
1436 arg.vdev_id = arvif->vdev_id;
1437 arg.dtim_period = arvif->dtim_period;
1438 arg.bcn_intval = arvif->beacon_interval;
1440 arg.channel.freq = chandef->chan->center_freq;
1441 arg.channel.band_center_freq1 = chandef->center_freq1;
1442 arg.channel.band_center_freq2 = chandef->center_freq2;
1443 arg.channel.mode = chan_to_phymode(chandef);
1445 arg.channel.min_power = 0;
1446 arg.channel.max_power = chandef->chan->max_power * 2;
1447 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1448 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1450 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1451 arg.ssid = arvif->u.ap.ssid;
1452 arg.ssid_len = arvif->u.ap.ssid_len;
1453 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1455 /* For now allow DFS for AP mode */
1456 arg.channel.chan_radar =
1457 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1458 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1459 arg.ssid = arvif->vif->bss_conf.ssid;
1460 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1463 ath10k_dbg(ar, ATH10K_DBG_MAC,
1464 "mac vdev %d start center_freq %d phymode %s\n",
1465 arg.vdev_id, arg.channel.freq,
1466 ath10k_wmi_phymode_str(arg.channel.mode));
1469 ret = ath10k_wmi_vdev_restart(ar, &arg);
1471 ret = ath10k_wmi_vdev_start(ar, &arg);
1474 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1479 ret = ath10k_vdev_setup_sync(ar);
1482 "failed to synchronize setup for vdev %i restart %d: %d\n",
1483 arg.vdev_id, restart, ret);
1487 ar->num_started_vdevs++;
1488 ath10k_recalc_radar_detection(ar);
1493 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1494 const struct cfg80211_chan_def *def)
1496 return ath10k_vdev_start_restart(arvif, def, false);
1499 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1500 const struct cfg80211_chan_def *def)
1502 return ath10k_vdev_start_restart(arvif, def, true);
1505 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1506 struct sk_buff *bcn)
1508 struct ath10k *ar = arvif->ar;
1509 struct ieee80211_mgmt *mgmt;
1513 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1516 mgmt = (void *)bcn->data;
1517 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1518 mgmt->u.beacon.variable,
1519 bcn->len - (mgmt->u.beacon.variable -
1524 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1526 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1527 arvif->vdev_id, ret);
1534 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1535 u8 oui_type, size_t ie_offset)
1542 if (WARN_ON(skb->len < ie_offset))
1545 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1546 skb->data + ie_offset,
1547 skb->len - ie_offset);
1552 end = skb->data + skb->len;
1555 if (WARN_ON(next > end))
1558 memmove(ie, next, end - next);
1559 skb_trim(skb, skb->len - len);
1564 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1566 struct ath10k *ar = arvif->ar;
1567 struct ieee80211_hw *hw = ar->hw;
1568 struct ieee80211_vif *vif = arvif->vif;
1569 struct ieee80211_mutable_offsets offs = {};
1570 struct sk_buff *bcn;
1573 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1576 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1577 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1580 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1582 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1586 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1588 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1593 /* P2P IE is inserted by firmware automatically (as configured above)
1594 * so remove it from the base beacon template to avoid duplicate P2P
1595 * IEs in beacon frames.
1597 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1598 offsetof(struct ieee80211_mgmt,
1599 u.beacon.variable));
1601 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1606 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1614 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1616 struct ath10k *ar = arvif->ar;
1617 struct ieee80211_hw *hw = ar->hw;
1618 struct ieee80211_vif *vif = arvif->vif;
1619 struct sk_buff *prb;
1622 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1625 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1628 /* For mesh, probe response and beacon share the same template */
1629 if (ieee80211_vif_is_mesh(vif))
1632 prb = ieee80211_proberesp_get(hw, vif);
1634 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1638 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1642 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1650 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1652 struct ath10k *ar = arvif->ar;
1653 struct cfg80211_chan_def def;
1656 /* When originally vdev is started during assign_vif_chanctx() some
1657 * information is missing, notably SSID. Firmware revisions with beacon
1658 * offloading require the SSID to be provided during vdev (re)start to
1659 * handle hidden SSID properly.
1661 * Vdev restart must be done after vdev has been both started and
1662 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1663 * deliver vdev restart response event causing timeouts during vdev
1664 * syncing in ath10k.
1666 * Note: The vdev down/up and template reinstallation could be skipped
1667 * since only wmi-tlv firmware are known to have beacon offload and
1668 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1669 * response delivery. It's probably more robust to keep it as is.
1671 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1674 if (WARN_ON(!arvif->is_started))
1677 if (WARN_ON(!arvif->is_up))
1680 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1683 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1685 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1686 arvif->vdev_id, ret);
1690 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1691 * firmware will crash upon vdev up.
1694 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1696 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1700 ret = ath10k_mac_setup_prb_tmpl(arvif);
1702 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1706 ret = ath10k_vdev_restart(arvif, &def);
1708 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1709 arvif->vdev_id, ret);
1713 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1716 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1717 arvif->vdev_id, ret);
1724 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1725 struct ieee80211_bss_conf *info)
1727 struct ath10k *ar = arvif->ar;
1730 lockdep_assert_held(&arvif->ar->conf_mutex);
1732 if (!info->enable_beacon) {
1733 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1735 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1736 arvif->vdev_id, ret);
1738 arvif->is_up = false;
1740 spin_lock_bh(&arvif->ar->data_lock);
1741 ath10k_mac_vif_beacon_free(arvif);
1742 spin_unlock_bh(&arvif->ar->data_lock);
1747 arvif->tx_seq_no = 0x1000;
1750 ether_addr_copy(arvif->bssid, info->bssid);
1752 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1755 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1756 arvif->vdev_id, ret);
1760 arvif->is_up = true;
1762 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1764 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1765 arvif->vdev_id, ret);
1769 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1772 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1773 struct ieee80211_bss_conf *info,
1774 const u8 self_peer[ETH_ALEN])
1776 struct ath10k *ar = arvif->ar;
1780 lockdep_assert_held(&arvif->ar->conf_mutex);
1782 if (!info->ibss_joined) {
1783 if (is_zero_ether_addr(arvif->bssid))
1786 eth_zero_addr(arvif->bssid);
1791 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1792 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1793 ATH10K_DEFAULT_ATIM);
1795 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1796 arvif->vdev_id, ret);
1799 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1801 struct ath10k *ar = arvif->ar;
1806 lockdep_assert_held(&arvif->ar->conf_mutex);
1808 if (arvif->u.sta.uapsd)
1809 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1811 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1813 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1814 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1816 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1817 value, arvif->vdev_id, ret);
1824 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1826 struct ath10k *ar = arvif->ar;
1831 lockdep_assert_held(&arvif->ar->conf_mutex);
1833 if (arvif->u.sta.uapsd)
1834 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1836 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1838 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1839 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1842 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1843 value, arvif->vdev_id, ret);
1850 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1852 struct ath10k_vif *arvif;
1855 lockdep_assert_held(&ar->conf_mutex);
1857 list_for_each_entry(arvif, &ar->arvifs, list)
1858 if (arvif->is_started)
1864 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1866 struct ath10k *ar = arvif->ar;
1867 struct ieee80211_vif *vif = arvif->vif;
1868 struct ieee80211_conf *conf = &ar->hw->conf;
1869 enum wmi_sta_powersave_param param;
1870 enum wmi_sta_ps_mode psmode;
1875 lockdep_assert_held(&arvif->ar->conf_mutex);
1877 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1880 enable_ps = arvif->ps;
1882 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1883 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1884 ar->running_fw->fw_file.fw_features)) {
1885 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1890 if (!arvif->is_started) {
1891 /* mac80211 can update vif powersave state while disconnected.
1892 * Firmware doesn't behave nicely and consumes more power than
1893 * necessary if PS is disabled on a non-started vdev. Hence
1894 * force-enable PS for non-running vdevs.
1896 psmode = WMI_STA_PS_MODE_ENABLED;
1897 } else if (enable_ps) {
1898 psmode = WMI_STA_PS_MODE_ENABLED;
1899 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1901 ps_timeout = conf->dynamic_ps_timeout;
1902 if (ps_timeout == 0) {
1903 /* Firmware doesn't like 0 */
1904 ps_timeout = ieee80211_tu_to_usec(
1905 vif->bss_conf.beacon_int) / 1000;
1908 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1911 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1912 arvif->vdev_id, ret);
1916 psmode = WMI_STA_PS_MODE_DISABLED;
1919 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1920 arvif->vdev_id, psmode ? "enable" : "disable");
1922 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1924 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1925 psmode, arvif->vdev_id, ret);
1932 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1934 struct ath10k *ar = arvif->ar;
1935 struct wmi_sta_keepalive_arg arg = {};
1938 lockdep_assert_held(&arvif->ar->conf_mutex);
1940 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1943 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1946 /* Some firmware revisions have a bug and ignore the `enabled` field.
1947 * Instead use the interval to disable the keepalive.
1949 arg.vdev_id = arvif->vdev_id;
1951 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1952 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1954 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1956 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1957 arvif->vdev_id, ret);
1964 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1966 struct ath10k *ar = arvif->ar;
1967 struct ieee80211_vif *vif = arvif->vif;
1970 lockdep_assert_held(&arvif->ar->conf_mutex);
1972 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1975 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1978 if (!vif->csa_active)
1984 if (!ieee80211_csa_is_complete(vif)) {
1985 ieee80211_csa_update_counter(vif);
1987 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1989 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1992 ret = ath10k_mac_setup_prb_tmpl(arvif);
1994 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1997 ieee80211_csa_finish(vif);
2001 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2003 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2005 struct ath10k *ar = arvif->ar;
2007 mutex_lock(&ar->conf_mutex);
2008 ath10k_mac_vif_ap_csa_count_down(arvif);
2009 mutex_unlock(&ar->conf_mutex);
2012 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2013 struct ieee80211_vif *vif)
2015 struct sk_buff *skb = data;
2016 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2017 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2019 if (vif->type != NL80211_IFTYPE_STATION)
2022 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2025 cancel_delayed_work(&arvif->connection_loss_work);
2028 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2030 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2031 IEEE80211_IFACE_ITER_NORMAL,
2032 ath10k_mac_handle_beacon_iter,
2036 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2037 struct ieee80211_vif *vif)
2039 u32 *vdev_id = data;
2040 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2041 struct ath10k *ar = arvif->ar;
2042 struct ieee80211_hw *hw = ar->hw;
2044 if (arvif->vdev_id != *vdev_id)
2050 ieee80211_beacon_loss(vif);
2052 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2053 * (done by mac80211) succeeds but beacons do not resume then it
2054 * doesn't make sense to continue operation. Queue connection loss work
2055 * which can be cancelled when beacon is received.
2057 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2058 ATH10K_CONNECTION_LOSS_HZ);
2061 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2063 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2064 IEEE80211_IFACE_ITER_NORMAL,
2065 ath10k_mac_handle_beacon_miss_iter,
2069 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2071 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2072 connection_loss_work.work);
2073 struct ieee80211_vif *vif = arvif->vif;
2078 ieee80211_connection_loss(vif);
2081 /**********************/
2082 /* Station management */
2083 /**********************/
2085 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2086 struct ieee80211_vif *vif)
2088 /* Some firmware revisions have unstable STA powersave when listen
2089 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2090 * generate NullFunc frames properly even if buffered frames have been
2091 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2092 * buffered frames. Often pinging the device from AP would simply fail.
2094 * As a workaround set it to 1.
2096 if (vif->type == NL80211_IFTYPE_STATION)
2099 return ar->hw->conf.listen_interval;
2102 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2103 struct ieee80211_vif *vif,
2104 struct ieee80211_sta *sta,
2105 struct wmi_peer_assoc_complete_arg *arg)
2107 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2110 lockdep_assert_held(&ar->conf_mutex);
2112 if (vif->type == NL80211_IFTYPE_STATION)
2113 aid = vif->bss_conf.aid;
2117 ether_addr_copy(arg->addr, sta->addr);
2118 arg->vdev_id = arvif->vdev_id;
2119 arg->peer_aid = aid;
2120 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2121 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2122 arg->peer_num_spatial_streams = 1;
2123 arg->peer_caps = vif->bss_conf.assoc_capability;
2126 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2127 struct ieee80211_vif *vif,
2128 struct ieee80211_sta *sta,
2129 struct wmi_peer_assoc_complete_arg *arg)
2131 struct ieee80211_bss_conf *info = &vif->bss_conf;
2132 struct cfg80211_chan_def def;
2133 struct cfg80211_bss *bss;
2134 const u8 *rsnie = NULL;
2135 const u8 *wpaie = NULL;
2137 lockdep_assert_held(&ar->conf_mutex);
2139 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2142 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2143 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2145 const struct cfg80211_bss_ies *ies;
2148 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2150 ies = rcu_dereference(bss->ies);
2152 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2153 WLAN_OUI_TYPE_MICROSOFT_WPA,
2157 cfg80211_put_bss(ar->hw->wiphy, bss);
2160 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2161 if (rsnie || wpaie) {
2162 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2163 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2167 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2168 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2172 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2173 ar->running_fw->fw_file.fw_features)) {
2174 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2178 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2179 struct ieee80211_vif *vif,
2180 struct ieee80211_sta *sta,
2181 struct wmi_peer_assoc_complete_arg *arg)
2183 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2184 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2185 struct cfg80211_chan_def def;
2186 const struct ieee80211_supported_band *sband;
2187 const struct ieee80211_rate *rates;
2188 enum nl80211_band band;
2193 lockdep_assert_held(&ar->conf_mutex);
2195 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2198 band = def.chan->band;
2199 sband = ar->hw->wiphy->bands[band];
2200 ratemask = sta->supp_rates[band];
2201 ratemask &= arvif->bitrate_mask.control[band].legacy;
2202 rates = sband->bitrates;
2204 rateset->num_rates = 0;
2206 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2207 if (!(ratemask & 1))
2210 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2211 rateset->rates[rateset->num_rates] = rate;
2212 rateset->num_rates++;
2217 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2221 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2222 if (ht_mcs_mask[nss])
2229 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2233 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2234 if (vht_mcs_mask[nss])
2240 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2241 struct ieee80211_vif *vif,
2242 struct ieee80211_sta *sta,
2243 struct wmi_peer_assoc_complete_arg *arg)
2245 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2246 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2247 struct cfg80211_chan_def def;
2248 enum nl80211_band band;
2249 const u8 *ht_mcs_mask;
2250 const u16 *vht_mcs_mask;
2255 lockdep_assert_held(&ar->conf_mutex);
2257 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2260 if (!ht_cap->ht_supported)
2263 band = def.chan->band;
2264 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2265 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2267 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2268 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2271 arg->peer_flags |= ar->wmi.peer_flags->ht;
2272 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2273 ht_cap->ampdu_factor)) - 1;
2275 arg->peer_mpdu_density =
2276 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2278 arg->peer_ht_caps = ht_cap->cap;
2279 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2281 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2282 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2284 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2285 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2286 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2289 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2290 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2291 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2293 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2294 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2297 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2298 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2299 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2302 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2303 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2304 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2305 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2306 arg->peer_rate_caps |= stbc;
2307 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2310 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2311 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2312 else if (ht_cap->mcs.rx_mask[1])
2313 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2315 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2316 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2317 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2318 max_nss = (i / 8) + 1;
2319 arg->peer_ht_rates.rates[n++] = i;
2323 * This is a workaround for HT-enabled STAs which break the spec
2324 * and have no HT capabilities RX mask (no HT RX MCS map).
2326 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2327 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2329 * Firmware asserts if such situation occurs.
2332 arg->peer_ht_rates.num_rates = 8;
2333 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2334 arg->peer_ht_rates.rates[i] = i;
2336 arg->peer_ht_rates.num_rates = n;
2337 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2340 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2342 arg->peer_ht_rates.num_rates,
2343 arg->peer_num_spatial_streams);
2346 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2347 struct ath10k_vif *arvif,
2348 struct ieee80211_sta *sta)
2354 lockdep_assert_held(&ar->conf_mutex);
2356 if (sta->wme && sta->uapsd_queues) {
2357 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2358 sta->uapsd_queues, sta->max_sp);
2360 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2361 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2362 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2363 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2364 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2365 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2366 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2367 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2368 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2369 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2370 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2371 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2373 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2374 max_sp = sta->max_sp;
2376 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2378 WMI_AP_PS_PEER_PARAM_UAPSD,
2381 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2382 arvif->vdev_id, ret);
2386 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2388 WMI_AP_PS_PEER_PARAM_MAX_SP,
2391 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2392 arvif->vdev_id, ret);
2396 /* TODO setup this based on STA listen interval and
2397 * beacon interval. Currently we don't know
2398 * sta->listen_interval - mac80211 patch required.
2399 * Currently use 10 seconds
2401 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2402 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2405 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2406 arvif->vdev_id, ret);
2415 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2416 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2423 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2424 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2428 idx_limit = fls(mcs_map) - 1;
2432 switch (idx_limit) {
2433 case 0: /* fall through */
2434 case 1: /* fall through */
2435 case 2: /* fall through */
2436 case 3: /* fall through */
2437 case 4: /* fall through */
2438 case 5: /* fall through */
2439 case 6: /* fall through */
2441 /* see ath10k_mac_can_set_bitrate_mask() */
2445 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2448 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2451 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2454 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2458 tx_mcs_set &= ~(0x3 << (nss * 2));
2459 tx_mcs_set |= mcs << (nss * 2);
2465 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2466 struct ieee80211_vif *vif,
2467 struct ieee80211_sta *sta,
2468 struct wmi_peer_assoc_complete_arg *arg)
2470 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2471 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2472 struct cfg80211_chan_def def;
2473 enum nl80211_band band;
2474 const u16 *vht_mcs_mask;
2476 u8 max_nss, vht_mcs;
2479 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2482 if (!vht_cap->vht_supported)
2485 band = def.chan->band;
2486 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2488 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2491 arg->peer_flags |= ar->wmi.peer_flags->vht;
2493 if (def.chan->band == NL80211_BAND_2GHZ)
2494 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2496 arg->peer_vht_caps = vht_cap->cap;
2498 ampdu_factor = (vht_cap->cap &
2499 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2500 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2502 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2503 * zero in VHT IE. Using it would result in degraded throughput.
2504 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2505 * it if VHT max_mpdu is smaller.
2507 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2508 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2509 ampdu_factor)) - 1);
2511 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2512 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2514 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2515 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2517 /* Calculate peer NSS capability from VHT capabilities if STA
2520 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2521 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2524 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2528 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2529 arg->peer_vht_rates.rx_max_rate =
2530 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2531 arg->peer_vht_rates.rx_mcs_set =
2532 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2533 arg->peer_vht_rates.tx_max_rate =
2534 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2535 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2536 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2538 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2539 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2541 if (arg->peer_vht_rates.rx_max_rate &&
2542 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2543 switch (arg->peer_vht_rates.rx_max_rate) {
2545 /* Must be 2x2 at 160Mhz is all it can do. */
2546 arg->peer_bw_rxnss_override = 2;
2549 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2550 arg->peer_bw_rxnss_override = 1;
2556 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2557 struct ieee80211_vif *vif,
2558 struct ieee80211_sta *sta,
2559 struct wmi_peer_assoc_complete_arg *arg)
2561 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2563 switch (arvif->vdev_type) {
2564 case WMI_VDEV_TYPE_AP:
2566 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2568 if (sta->wme && sta->uapsd_queues) {
2569 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2570 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2573 case WMI_VDEV_TYPE_STA:
2575 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2577 case WMI_VDEV_TYPE_IBSS:
2579 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2585 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2586 sta->addr, !!(arg->peer_flags &
2587 arvif->ar->wmi.peer_flags->qos));
2590 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2592 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2593 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2596 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2597 struct ieee80211_sta *sta)
2599 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2600 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2601 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2602 return MODE_11AC_VHT160;
2603 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2604 return MODE_11AC_VHT80_80;
2606 /* not sure if this is a valid case? */
2607 return MODE_11AC_VHT160;
2611 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2612 return MODE_11AC_VHT80;
2614 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2615 return MODE_11AC_VHT40;
2617 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2618 return MODE_11AC_VHT20;
2620 return MODE_UNKNOWN;
2623 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2624 struct ieee80211_vif *vif,
2625 struct ieee80211_sta *sta,
2626 struct wmi_peer_assoc_complete_arg *arg)
2628 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2629 struct cfg80211_chan_def def;
2630 enum nl80211_band band;
2631 const u8 *ht_mcs_mask;
2632 const u16 *vht_mcs_mask;
2633 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2635 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2638 band = def.chan->band;
2639 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2640 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2643 case NL80211_BAND_2GHZ:
2644 if (sta->vht_cap.vht_supported &&
2645 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2646 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2647 phymode = MODE_11AC_VHT40;
2649 phymode = MODE_11AC_VHT20;
2650 } else if (sta->ht_cap.ht_supported &&
2651 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2652 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2653 phymode = MODE_11NG_HT40;
2655 phymode = MODE_11NG_HT20;
2656 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2663 case NL80211_BAND_5GHZ:
2667 if (sta->vht_cap.vht_supported &&
2668 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2669 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2670 } else if (sta->ht_cap.ht_supported &&
2671 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2672 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2673 phymode = MODE_11NA_HT40;
2675 phymode = MODE_11NA_HT20;
2685 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2686 sta->addr, ath10k_wmi_phymode_str(phymode));
2688 arg->peer_phymode = phymode;
2689 WARN_ON(phymode == MODE_UNKNOWN);
2692 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2693 struct ieee80211_vif *vif,
2694 struct ieee80211_sta *sta,
2695 struct wmi_peer_assoc_complete_arg *arg)
2697 lockdep_assert_held(&ar->conf_mutex);
2699 memset(arg, 0, sizeof(*arg));
2701 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2702 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2703 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2704 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2705 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2706 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2707 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2712 static const u32 ath10k_smps_map[] = {
2713 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2714 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2715 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2716 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2719 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2721 const struct ieee80211_sta_ht_cap *ht_cap)
2725 if (!ht_cap->ht_supported)
2728 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2729 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2731 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2734 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2735 WMI_PEER_SMPS_STATE,
2736 ath10k_smps_map[smps]);
2739 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2740 struct ieee80211_vif *vif,
2741 struct ieee80211_sta_vht_cap vht_cap)
2743 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2748 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2751 if (!(ar->vht_cap_info &
2752 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2753 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2754 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2755 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2758 param = ar->wmi.vdev_param->txbf;
2761 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2764 /* The following logic is correct. If a remote STA advertises support
2765 * for being a beamformer then we should enable us being a beamformee.
2768 if (ar->vht_cap_info &
2769 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2770 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2771 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2772 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2774 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2775 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2778 if (ar->vht_cap_info &
2779 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2780 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2781 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2782 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2784 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2785 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2788 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2789 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2791 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2792 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2794 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2796 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2804 /* can be called only in mac80211 callbacks due to `key_count` usage */
2805 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2806 struct ieee80211_vif *vif,
2807 struct ieee80211_bss_conf *bss_conf)
2809 struct ath10k *ar = hw->priv;
2810 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2811 struct ieee80211_sta_ht_cap ht_cap;
2812 struct ieee80211_sta_vht_cap vht_cap;
2813 struct wmi_peer_assoc_complete_arg peer_arg;
2814 struct ieee80211_sta *ap_sta;
2817 lockdep_assert_held(&ar->conf_mutex);
2819 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2820 arvif->vdev_id, arvif->bssid, arvif->aid);
2824 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2826 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2827 bss_conf->bssid, arvif->vdev_id);
2832 /* ap_sta must be accessed only within rcu section which must be left
2833 * before calling ath10k_setup_peer_smps() which might sleep.
2835 ht_cap = ap_sta->ht_cap;
2836 vht_cap = ap_sta->vht_cap;
2838 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2840 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2841 bss_conf->bssid, arvif->vdev_id, ret);
2848 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2850 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2851 bss_conf->bssid, arvif->vdev_id, ret);
2855 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2857 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2858 arvif->vdev_id, ret);
2862 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2864 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2865 arvif->vdev_id, bss_conf->bssid, ret);
2869 ath10k_dbg(ar, ATH10K_DBG_MAC,
2870 "mac vdev %d up (associated) bssid %pM aid %d\n",
2871 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2873 WARN_ON(arvif->is_up);
2875 arvif->aid = bss_conf->aid;
2876 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2878 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2880 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2881 arvif->vdev_id, ret);
2885 arvif->is_up = true;
2887 /* Workaround: Some firmware revisions (tested with qca6174
2888 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2889 * poked with peer param command.
2891 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2892 WMI_PEER_DUMMY_VAR, 1);
2894 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2895 arvif->bssid, arvif->vdev_id, ret);
2900 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2901 struct ieee80211_vif *vif)
2903 struct ath10k *ar = hw->priv;
2904 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2905 struct ieee80211_sta_vht_cap vht_cap = {};
2908 lockdep_assert_held(&ar->conf_mutex);
2910 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2911 arvif->vdev_id, arvif->bssid);
2913 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2915 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2916 arvif->vdev_id, ret);
2918 arvif->def_wep_key_idx = -1;
2920 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2922 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2923 arvif->vdev_id, ret);
2927 arvif->is_up = false;
2929 cancel_delayed_work_sync(&arvif->connection_loss_work);
2932 static int ath10k_station_assoc(struct ath10k *ar,
2933 struct ieee80211_vif *vif,
2934 struct ieee80211_sta *sta,
2937 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2938 struct wmi_peer_assoc_complete_arg peer_arg;
2941 lockdep_assert_held(&ar->conf_mutex);
2943 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2945 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2946 sta->addr, arvif->vdev_id, ret);
2950 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2952 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2953 sta->addr, arvif->vdev_id, ret);
2957 /* Re-assoc is run only to update supported rates for given station. It
2958 * doesn't make much sense to reconfigure the peer completely.
2961 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2964 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2965 arvif->vdev_id, ret);
2969 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2971 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2972 sta->addr, arvif->vdev_id, ret);
2977 arvif->num_legacy_stations++;
2978 ret = ath10k_recalc_rtscts_prot(arvif);
2980 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2981 arvif->vdev_id, ret);
2986 /* Plumb cached keys only for static WEP */
2987 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
2988 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2990 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2991 arvif->vdev_id, ret);
3000 static int ath10k_station_disassoc(struct ath10k *ar,
3001 struct ieee80211_vif *vif,
3002 struct ieee80211_sta *sta)
3004 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3007 lockdep_assert_held(&ar->conf_mutex);
3010 arvif->num_legacy_stations--;
3011 ret = ath10k_recalc_rtscts_prot(arvif);
3013 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3014 arvif->vdev_id, ret);
3019 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3021 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3022 arvif->vdev_id, ret);
3033 static int ath10k_update_channel_list(struct ath10k *ar)
3035 struct ieee80211_hw *hw = ar->hw;
3036 struct ieee80211_supported_band **bands;
3037 enum nl80211_band band;
3038 struct ieee80211_channel *channel;
3039 struct wmi_scan_chan_list_arg arg = {0};
3040 struct wmi_channel_arg *ch;
3046 lockdep_assert_held(&ar->conf_mutex);
3048 bands = hw->wiphy->bands;
3049 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3053 for (i = 0; i < bands[band]->n_channels; i++) {
3054 if (bands[band]->channels[i].flags &
3055 IEEE80211_CHAN_DISABLED)
3062 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3063 arg.channels = kzalloc(len, GFP_KERNEL);
3068 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3072 for (i = 0; i < bands[band]->n_channels; i++) {
3073 channel = &bands[band]->channels[i];
3075 if (channel->flags & IEEE80211_CHAN_DISABLED)
3078 ch->allow_ht = true;
3080 /* FIXME: when should we really allow VHT? */
3081 ch->allow_vht = true;
3084 !(channel->flags & IEEE80211_CHAN_NO_IR);
3087 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3090 !!(channel->flags & IEEE80211_CHAN_RADAR);
3092 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3093 ch->passive = passive;
3095 /* the firmware is ignoring the "radar" flag of the
3096 * channel and is scanning actively using Probe Requests
3097 * on "Radar detection"/DFS channels which are not
3098 * marked as "available"
3100 ch->passive |= ch->chan_radar;
3102 ch->freq = channel->center_freq;
3103 ch->band_center_freq1 = channel->center_freq;
3105 ch->max_power = channel->max_power * 2;
3106 ch->max_reg_power = channel->max_reg_power * 2;
3107 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3108 ch->reg_class_id = 0; /* FIXME */
3110 /* FIXME: why use only legacy modes, why not any
3111 * HT/VHT modes? Would that even make any
3114 if (channel->band == NL80211_BAND_2GHZ)
3115 ch->mode = MODE_11G;
3117 ch->mode = MODE_11A;
3119 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3122 ath10k_dbg(ar, ATH10K_DBG_WMI,
3123 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3124 ch - arg.channels, arg.n_channels,
3125 ch->freq, ch->max_power, ch->max_reg_power,
3126 ch->max_antenna_gain, ch->mode);
3132 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3133 kfree(arg.channels);
3138 static enum wmi_dfs_region
3139 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3141 switch (dfs_region) {
3142 case NL80211_DFS_UNSET:
3143 return WMI_UNINIT_DFS_DOMAIN;
3144 case NL80211_DFS_FCC:
3145 return WMI_FCC_DFS_DOMAIN;
3146 case NL80211_DFS_ETSI:
3147 return WMI_ETSI_DFS_DOMAIN;
3148 case NL80211_DFS_JP:
3149 return WMI_MKK4_DFS_DOMAIN;
3151 return WMI_UNINIT_DFS_DOMAIN;
3154 static void ath10k_regd_update(struct ath10k *ar)
3156 struct reg_dmn_pair_mapping *regpair;
3158 enum wmi_dfs_region wmi_dfs_reg;
3159 enum nl80211_dfs_regions nl_dfs_reg;
3161 lockdep_assert_held(&ar->conf_mutex);
3163 ret = ath10k_update_channel_list(ar);
3165 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3167 regpair = ar->ath_common.regulatory.regpair;
3169 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3170 nl_dfs_reg = ar->dfs_detector->region;
3171 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3173 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3176 /* Target allows setting up per-band regdomain but ath_common provides
3177 * a combined one only
3179 ret = ath10k_wmi_pdev_set_regdomain(ar,
3180 regpair->reg_domain,
3181 regpair->reg_domain, /* 2ghz */
3182 regpair->reg_domain, /* 5ghz */
3183 regpair->reg_2ghz_ctl,
3184 regpair->reg_5ghz_ctl,
3187 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3190 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3191 struct ieee80211_supported_band *band)
3195 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3196 for (i = 0; i < band->n_channels; i++) {
3197 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3198 band->channels[i].center_freq > ar->high_5ghz_chan)
3199 band->channels[i].flags |=
3200 IEEE80211_CHAN_DISABLED;
3205 static void ath10k_reg_notifier(struct wiphy *wiphy,
3206 struct regulatory_request *request)
3208 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3209 struct ath10k *ar = hw->priv;
3212 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3214 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3215 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3216 request->dfs_region);
3217 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3218 request->dfs_region);
3220 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3221 request->dfs_region);
3224 mutex_lock(&ar->conf_mutex);
3225 if (ar->state == ATH10K_STATE_ON)
3226 ath10k_regd_update(ar);
3227 mutex_unlock(&ar->conf_mutex);
3229 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3230 ath10k_mac_update_channel_list(ar,
3231 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3234 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3236 spin_lock_bh(&ar->data_lock);
3237 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3238 spin_unlock_bh(&ar->data_lock);
3240 cancel_work_sync(&ar->radar_confirmation_work);
3247 enum ath10k_mac_tx_path {
3249 ATH10K_MAC_TX_HTT_MGMT,
3250 ATH10K_MAC_TX_WMI_MGMT,
3251 ATH10K_MAC_TX_UNKNOWN,
3254 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3256 lockdep_assert_held(&ar->htt.tx_lock);
3258 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3259 ar->tx_paused |= BIT(reason);
3260 ieee80211_stop_queues(ar->hw);
3263 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3264 struct ieee80211_vif *vif)
3266 struct ath10k *ar = data;
3267 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3269 if (arvif->tx_paused)
3272 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3275 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3277 lockdep_assert_held(&ar->htt.tx_lock);
3279 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3280 ar->tx_paused &= ~BIT(reason);
3285 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3286 IEEE80211_IFACE_ITER_RESUME_ALL,
3287 ath10k_mac_tx_unlock_iter,
3290 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3293 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3295 struct ath10k *ar = arvif->ar;
3297 lockdep_assert_held(&ar->htt.tx_lock);
3299 WARN_ON(reason >= BITS_PER_LONG);
3300 arvif->tx_paused |= BIT(reason);
3301 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3304 void ath10k_mac_vif_tx_unlock(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);
3316 if (arvif->tx_paused)
3319 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3322 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3323 enum wmi_tlv_tx_pause_id pause_id,
3324 enum wmi_tlv_tx_pause_action action)
3326 struct ath10k *ar = arvif->ar;
3328 lockdep_assert_held(&ar->htt.tx_lock);
3331 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3332 ath10k_mac_vif_tx_lock(arvif, pause_id);
3334 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3335 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3338 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3339 "received unknown tx pause action %d on vdev %i, ignoring\n",
3340 action, arvif->vdev_id);
3345 struct ath10k_mac_tx_pause {
3347 enum wmi_tlv_tx_pause_id pause_id;
3348 enum wmi_tlv_tx_pause_action action;
3351 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3352 struct ieee80211_vif *vif)
3354 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3355 struct ath10k_mac_tx_pause *arg = data;
3357 if (arvif->vdev_id != arg->vdev_id)
3360 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3363 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3364 enum wmi_tlv_tx_pause_id pause_id,
3365 enum wmi_tlv_tx_pause_action action)
3367 struct ath10k_mac_tx_pause arg = {
3369 .pause_id = pause_id,
3373 spin_lock_bh(&ar->htt.tx_lock);
3374 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3375 IEEE80211_IFACE_ITER_RESUME_ALL,
3376 ath10k_mac_handle_tx_pause_iter,
3378 spin_unlock_bh(&ar->htt.tx_lock);
3381 static enum ath10k_hw_txrx_mode
3382 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3383 struct ieee80211_vif *vif,
3384 struct ieee80211_sta *sta,
3385 struct sk_buff *skb)
3387 const struct ieee80211_hdr *hdr = (void *)skb->data;
3388 __le16 fc = hdr->frame_control;
3390 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3391 return ATH10K_HW_TXRX_RAW;
3393 if (ieee80211_is_mgmt(fc))
3394 return ATH10K_HW_TXRX_MGMT;
3398 * NullFunc frames are mostly used to ping if a client or AP are still
3399 * reachable and responsive. This implies tx status reports must be
3400 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3401 * come to a conclusion that the other end disappeared and tear down
3402 * BSS connection or it can never disconnect from BSS/client (which is
3405 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3406 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3407 * which seems to deliver correct tx reports for NullFunc frames. The
3408 * downside of using it is it ignores client powersave state so it can
3409 * end up disconnecting sleeping clients in AP mode. It should fix STA
3410 * mode though because AP don't sleep.
3412 if (ar->htt.target_version_major < 3 &&
3413 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3414 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3415 ar->running_fw->fw_file.fw_features))
3416 return ATH10K_HW_TXRX_MGMT;
3420 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3421 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3422 * to work with Ethernet txmode so use it.
3424 * FIXME: Check if raw mode works with TDLS.
3426 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3427 return ATH10K_HW_TXRX_ETHERNET;
3429 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3430 return ATH10K_HW_TXRX_RAW;
3432 return ATH10K_HW_TXRX_NATIVE_WIFI;
3435 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3436 struct sk_buff *skb)
3438 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3439 const struct ieee80211_hdr *hdr = (void *)skb->data;
3440 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3441 IEEE80211_TX_CTL_INJECTED;
3443 if (!ieee80211_has_protected(hdr->frame_control))
3446 if ((info->flags & mask) == mask)
3450 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3455 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3456 * Control in the header.
3458 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3460 struct ieee80211_hdr *hdr = (void *)skb->data;
3461 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3464 if (!ieee80211_is_data_qos(hdr->frame_control))
3467 qos_ctl = ieee80211_get_qos_ctl(hdr);
3468 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3469 skb->data, (void *)qos_ctl - (void *)skb->data);
3470 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3472 /* Some firmware revisions don't handle sending QoS NullFunc well.
3473 * These frames are mainly used for CQM purposes so it doesn't really
3474 * matter whether QoS NullFunc or NullFunc are sent.
3476 hdr = (void *)skb->data;
3477 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3478 cb->flags &= ~ATH10K_SKB_F_QOS;
3480 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3483 static void ath10k_tx_h_8023(struct sk_buff *skb)
3485 struct ieee80211_hdr *hdr;
3486 struct rfc1042_hdr *rfc1042;
3493 hdr = (void *)skb->data;
3494 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3495 rfc1042 = (void *)skb->data + hdrlen;
3497 ether_addr_copy(da, ieee80211_get_DA(hdr));
3498 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3499 type = rfc1042->snap_type;
3501 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3502 skb_push(skb, sizeof(*eth));
3504 eth = (void *)skb->data;
3505 ether_addr_copy(eth->h_dest, da);
3506 ether_addr_copy(eth->h_source, sa);
3507 eth->h_proto = type;
3510 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3511 struct ieee80211_vif *vif,
3512 struct sk_buff *skb)
3514 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3515 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3517 /* This is case only for P2P_GO */
3518 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3521 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3522 spin_lock_bh(&ar->data_lock);
3523 if (arvif->u.ap.noa_data)
3524 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3526 skb_put_data(skb, arvif->u.ap.noa_data,
3527 arvif->u.ap.noa_len);
3528 spin_unlock_bh(&ar->data_lock);
3532 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3533 struct ieee80211_vif *vif,
3534 struct ieee80211_txq *txq,
3535 struct sk_buff *skb)
3537 struct ieee80211_hdr *hdr = (void *)skb->data;
3538 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3541 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3542 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3544 if (ieee80211_is_mgmt(hdr->frame_control))
3545 cb->flags |= ATH10K_SKB_F_MGMT;
3547 if (ieee80211_is_data_qos(hdr->frame_control))
3548 cb->flags |= ATH10K_SKB_F_QOS;
3554 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3556 /* FIXME: Not really sure since when the behaviour changed. At some
3557 * point new firmware stopped requiring creation of peer entries for
3558 * offchannel tx (and actually creating them causes issues with wmi-htc
3559 * tx credit replenishment and reliability). Assuming it's at least 3.4
3560 * because that's when the `freq` was introduced to TX_FRM HTT command.
3562 return (ar->htt.target_version_major >= 3 &&
3563 ar->htt.target_version_minor >= 4 &&
3564 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3567 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3569 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3571 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3572 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3576 skb_queue_tail(q, skb);
3577 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3582 static enum ath10k_mac_tx_path
3583 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3584 struct sk_buff *skb,
3585 enum ath10k_hw_txrx_mode txmode)
3588 case ATH10K_HW_TXRX_RAW:
3589 case ATH10K_HW_TXRX_NATIVE_WIFI:
3590 case ATH10K_HW_TXRX_ETHERNET:
3591 return ATH10K_MAC_TX_HTT;
3592 case ATH10K_HW_TXRX_MGMT:
3593 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3594 ar->running_fw->fw_file.fw_features) ||
3595 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3597 return ATH10K_MAC_TX_WMI_MGMT;
3598 else if (ar->htt.target_version_major >= 3)
3599 return ATH10K_MAC_TX_HTT;
3601 return ATH10K_MAC_TX_HTT_MGMT;
3604 return ATH10K_MAC_TX_UNKNOWN;
3607 static int ath10k_mac_tx_submit(struct ath10k *ar,
3608 enum ath10k_hw_txrx_mode txmode,
3609 enum ath10k_mac_tx_path txpath,
3610 struct sk_buff *skb)
3612 struct ath10k_htt *htt = &ar->htt;
3616 case ATH10K_MAC_TX_HTT:
3617 ret = ath10k_htt_tx(htt, txmode, skb);
3619 case ATH10K_MAC_TX_HTT_MGMT:
3620 ret = ath10k_htt_mgmt_tx(htt, skb);
3622 case ATH10K_MAC_TX_WMI_MGMT:
3623 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3625 case ATH10K_MAC_TX_UNKNOWN:
3632 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3634 ieee80211_free_txskb(ar->hw, skb);
3640 /* This function consumes the sk_buff regardless of return value as far as
3641 * caller is concerned so no freeing is necessary afterwards.
3643 static int ath10k_mac_tx(struct ath10k *ar,
3644 struct ieee80211_vif *vif,
3645 enum ath10k_hw_txrx_mode txmode,
3646 enum ath10k_mac_tx_path txpath,
3647 struct sk_buff *skb, bool noque_offchan)
3649 struct ieee80211_hw *hw = ar->hw;
3650 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3653 /* We should disable CCK RATE due to P2P */
3654 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3655 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3658 case ATH10K_HW_TXRX_MGMT:
3659 case ATH10K_HW_TXRX_NATIVE_WIFI:
3660 ath10k_tx_h_nwifi(hw, skb);
3661 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3662 ath10k_tx_h_seq_no(vif, skb);
3664 case ATH10K_HW_TXRX_ETHERNET:
3665 ath10k_tx_h_8023(skb);
3667 case ATH10K_HW_TXRX_RAW:
3668 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3670 ieee80211_free_txskb(hw, skb);
3675 if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3676 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3677 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n",
3680 skb_queue_tail(&ar->offchan_tx_queue, skb);
3681 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3686 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3688 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3695 void ath10k_offchan_tx_purge(struct ath10k *ar)
3697 struct sk_buff *skb;
3700 skb = skb_dequeue(&ar->offchan_tx_queue);
3704 ieee80211_free_txskb(ar->hw, skb);
3708 void ath10k_offchan_tx_work(struct work_struct *work)
3710 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3711 struct ath10k_peer *peer;
3712 struct ath10k_vif *arvif;
3713 enum ath10k_hw_txrx_mode txmode;
3714 enum ath10k_mac_tx_path txpath;
3715 struct ieee80211_hdr *hdr;
3716 struct ieee80211_vif *vif;
3717 struct ieee80211_sta *sta;
3718 struct sk_buff *skb;
3719 const u8 *peer_addr;
3722 unsigned long time_left;
3723 bool tmp_peer_created = false;
3725 /* FW requirement: We must create a peer before FW will send out
3726 * an offchannel frame. Otherwise the frame will be stuck and
3727 * never transmitted. We delete the peer upon tx completion.
3728 * It is unlikely that a peer for offchannel tx will already be
3729 * present. However it may be in some rare cases so account for that.
3730 * Otherwise we might remove a legitimate peer and break stuff.
3734 skb = skb_dequeue(&ar->offchan_tx_queue);
3738 mutex_lock(&ar->conf_mutex);
3740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n",
3743 hdr = (struct ieee80211_hdr *)skb->data;
3744 peer_addr = ieee80211_get_DA(hdr);
3746 spin_lock_bh(&ar->data_lock);
3747 vdev_id = ar->scan.vdev_id;
3748 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3749 spin_unlock_bh(&ar->data_lock);
3752 /* FIXME: should this use ath10k_warn()? */
3753 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3754 peer_addr, vdev_id);
3757 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3759 WMI_PEER_TYPE_DEFAULT);
3761 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3762 peer_addr, vdev_id, ret);
3763 tmp_peer_created = (ret == 0);
3766 spin_lock_bh(&ar->data_lock);
3767 reinit_completion(&ar->offchan_tx_completed);
3768 ar->offchan_tx_skb = skb;
3769 spin_unlock_bh(&ar->data_lock);
3771 /* It's safe to access vif and sta - conf_mutex guarantees that
3772 * sta_state() and remove_interface() are locked exclusively
3773 * out wrt to this offchannel worker.
3775 arvif = ath10k_get_arvif(ar, vdev_id);
3778 sta = ieee80211_find_sta(vif, peer_addr);
3784 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3785 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3787 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true);
3789 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3795 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3797 ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n",
3800 if (!peer && tmp_peer_created) {
3801 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3803 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3804 peer_addr, vdev_id, ret);
3807 mutex_unlock(&ar->conf_mutex);
3811 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3813 struct sk_buff *skb;
3816 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3820 ieee80211_free_txskb(ar->hw, skb);
3824 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3826 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3827 struct sk_buff *skb;
3832 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3836 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
3837 ar->running_fw->fw_file.fw_features)) {
3838 paddr = dma_map_single(ar->dev, skb->data,
3839 skb->len, DMA_TO_DEVICE);
3840 if (dma_mapping_error(ar->dev, paddr)) {
3841 ieee80211_free_txskb(ar->hw, skb);
3844 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3846 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3848 /* remove this msdu from idr tracking */
3849 ath10k_wmi_cleanup_mgmt_tx_send(ar, skb);
3851 dma_unmap_single(ar->dev, paddr, skb->len,
3853 ieee80211_free_txskb(ar->hw, skb);
3856 ret = ath10k_wmi_mgmt_tx(ar, skb);
3858 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3860 ieee80211_free_txskb(ar->hw, skb);
3866 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3868 struct ath10k_txq *artxq;
3873 artxq = (void *)txq->drv_priv;
3874 INIT_LIST_HEAD(&artxq->list);
3877 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3879 struct ath10k_txq *artxq;
3880 struct ath10k_skb_cb *cb;
3881 struct sk_buff *msdu;
3887 artxq = (void *)txq->drv_priv;
3888 spin_lock_bh(&ar->txqs_lock);
3889 if (!list_empty(&artxq->list))
3890 list_del_init(&artxq->list);
3891 spin_unlock_bh(&ar->txqs_lock);
3893 spin_lock_bh(&ar->htt.tx_lock);
3894 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3895 cb = ATH10K_SKB_CB(msdu);
3899 spin_unlock_bh(&ar->htt.tx_lock);
3902 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3906 struct ath10k_peer *peer;
3908 lockdep_assert_held(&ar->data_lock);
3910 peer = ar->peer_map[peer_id];
3918 return peer->sta->txq[tid];
3920 return peer->vif->txq;
3925 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3926 struct ieee80211_txq *txq)
3928 struct ath10k *ar = hw->priv;
3929 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3931 /* No need to get locks */
3933 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3936 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3939 if (artxq->num_fw_queued < artxq->num_push_allowed)
3945 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3946 struct ieee80211_txq *txq)
3948 struct ath10k *ar = hw->priv;
3949 struct ath10k_htt *htt = &ar->htt;
3950 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3951 struct ieee80211_vif *vif = txq->vif;
3952 struct ieee80211_sta *sta = txq->sta;
3953 enum ath10k_hw_txrx_mode txmode;
3954 enum ath10k_mac_tx_path txpath;
3955 struct sk_buff *skb;
3956 struct ieee80211_hdr *hdr;
3958 bool is_mgmt, is_presp;
3961 spin_lock_bh(&ar->htt.tx_lock);
3962 ret = ath10k_htt_tx_inc_pending(htt);
3963 spin_unlock_bh(&ar->htt.tx_lock);
3968 skb = ieee80211_tx_dequeue(hw, txq);
3970 spin_lock_bh(&ar->htt.tx_lock);
3971 ath10k_htt_tx_dec_pending(htt);
3972 spin_unlock_bh(&ar->htt.tx_lock);
3977 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3980 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3981 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3982 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3985 hdr = (struct ieee80211_hdr *)skb->data;
3986 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3988 spin_lock_bh(&ar->htt.tx_lock);
3989 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3992 ath10k_htt_tx_dec_pending(htt);
3993 spin_unlock_bh(&ar->htt.tx_lock);
3996 spin_unlock_bh(&ar->htt.tx_lock);
3999 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4000 if (unlikely(ret)) {
4001 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4003 spin_lock_bh(&ar->htt.tx_lock);
4004 ath10k_htt_tx_dec_pending(htt);
4006 ath10k_htt_tx_mgmt_dec_pending(htt);
4007 spin_unlock_bh(&ar->htt.tx_lock);
4012 spin_lock_bh(&ar->htt.tx_lock);
4013 artxq->num_fw_queued++;
4014 spin_unlock_bh(&ar->htt.tx_lock);
4019 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4021 struct ieee80211_hw *hw = ar->hw;
4022 struct ieee80211_txq *txq;
4023 struct ath10k_txq *artxq;
4024 struct ath10k_txq *last;
4028 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4031 spin_lock_bh(&ar->txqs_lock);
4034 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
4035 while (!list_empty(&ar->txqs)) {
4036 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4037 txq = container_of((void *)artxq, struct ieee80211_txq,
4040 /* Prevent aggressive sta/tid taking over tx queue */
4041 max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE;
4043 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
4044 ret = ath10k_mac_tx_push_txq(hw, txq);
4049 list_del_init(&artxq->list);
4051 list_add_tail(&artxq->list, &ar->txqs);
4053 ath10k_htt_tx_txq_update(hw, txq);
4055 if (artxq == last || (ret < 0 && ret != -ENOENT))
4060 spin_unlock_bh(&ar->txqs_lock);
4062 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4068 void __ath10k_scan_finish(struct ath10k *ar)
4070 lockdep_assert_held(&ar->data_lock);
4072 switch (ar->scan.state) {
4073 case ATH10K_SCAN_IDLE:
4075 case ATH10K_SCAN_RUNNING:
4076 case ATH10K_SCAN_ABORTING:
4077 if (!ar->scan.is_roc) {
4078 struct cfg80211_scan_info info = {
4079 .aborted = (ar->scan.state ==
4080 ATH10K_SCAN_ABORTING),
4083 ieee80211_scan_completed(ar->hw, &info);
4084 } else if (ar->scan.roc_notify) {
4085 ieee80211_remain_on_channel_expired(ar->hw);
4088 case ATH10K_SCAN_STARTING:
4089 ar->scan.state = ATH10K_SCAN_IDLE;
4090 ar->scan_channel = NULL;
4091 ar->scan.roc_freq = 0;
4092 ath10k_offchan_tx_purge(ar);
4093 cancel_delayed_work(&ar->scan.timeout);
4094 complete(&ar->scan.completed);
4099 void ath10k_scan_finish(struct ath10k *ar)
4101 spin_lock_bh(&ar->data_lock);
4102 __ath10k_scan_finish(ar);
4103 spin_unlock_bh(&ar->data_lock);
4106 static int ath10k_scan_stop(struct ath10k *ar)
4108 struct wmi_stop_scan_arg arg = {
4109 .req_id = 1, /* FIXME */
4110 .req_type = WMI_SCAN_STOP_ONE,
4111 .u.scan_id = ATH10K_SCAN_ID,
4115 lockdep_assert_held(&ar->conf_mutex);
4117 ret = ath10k_wmi_stop_scan(ar, &arg);
4119 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4123 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4125 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4127 } else if (ret > 0) {
4132 /* Scan state should be updated upon scan completion but in case
4133 * firmware fails to deliver the event (for whatever reason) it is
4134 * desired to clean up scan state anyway. Firmware may have just
4135 * dropped the scan completion event delivery due to transport pipe
4136 * being overflown with data and/or it can recover on its own before
4137 * next scan request is submitted.
4139 spin_lock_bh(&ar->data_lock);
4140 if (ar->scan.state != ATH10K_SCAN_IDLE)
4141 __ath10k_scan_finish(ar);
4142 spin_unlock_bh(&ar->data_lock);
4147 static void ath10k_scan_abort(struct ath10k *ar)
4151 lockdep_assert_held(&ar->conf_mutex);
4153 spin_lock_bh(&ar->data_lock);
4155 switch (ar->scan.state) {
4156 case ATH10K_SCAN_IDLE:
4157 /* This can happen if timeout worker kicked in and called
4158 * abortion while scan completion was being processed.
4161 case ATH10K_SCAN_STARTING:
4162 case ATH10K_SCAN_ABORTING:
4163 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4164 ath10k_scan_state_str(ar->scan.state),
4167 case ATH10K_SCAN_RUNNING:
4168 ar->scan.state = ATH10K_SCAN_ABORTING;
4169 spin_unlock_bh(&ar->data_lock);
4171 ret = ath10k_scan_stop(ar);
4173 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4175 spin_lock_bh(&ar->data_lock);
4179 spin_unlock_bh(&ar->data_lock);
4182 void ath10k_scan_timeout_work(struct work_struct *work)
4184 struct ath10k *ar = container_of(work, struct ath10k,
4187 mutex_lock(&ar->conf_mutex);
4188 ath10k_scan_abort(ar);
4189 mutex_unlock(&ar->conf_mutex);
4192 static int ath10k_start_scan(struct ath10k *ar,
4193 const struct wmi_start_scan_arg *arg)
4197 lockdep_assert_held(&ar->conf_mutex);
4199 ret = ath10k_wmi_start_scan(ar, arg);
4203 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4205 ret = ath10k_scan_stop(ar);
4207 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4212 /* If we failed to start the scan, return error code at
4213 * this point. This is probably due to some issue in the
4214 * firmware, but no need to wedge the driver due to that...
4216 spin_lock_bh(&ar->data_lock);
4217 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4218 spin_unlock_bh(&ar->data_lock);
4221 spin_unlock_bh(&ar->data_lock);
4226 /**********************/
4227 /* mac80211 callbacks */
4228 /**********************/
4230 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4231 struct ieee80211_tx_control *control,
4232 struct sk_buff *skb)
4234 struct ath10k *ar = hw->priv;
4235 struct ath10k_htt *htt = &ar->htt;
4236 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4237 struct ieee80211_vif *vif = info->control.vif;
4238 struct ieee80211_sta *sta = control->sta;
4239 struct ieee80211_txq *txq = NULL;
4240 struct ieee80211_hdr *hdr = (void *)skb->data;
4241 enum ath10k_hw_txrx_mode txmode;
4242 enum ath10k_mac_tx_path txpath;
4248 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4250 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4251 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4252 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4253 txpath == ATH10K_MAC_TX_HTT_MGMT);
4254 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4257 spin_lock_bh(&ar->htt.tx_lock);
4258 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4260 ret = ath10k_htt_tx_inc_pending(htt);
4262 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4264 spin_unlock_bh(&ar->htt.tx_lock);
4265 ieee80211_free_txskb(ar->hw, skb);
4269 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4271 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4273 ath10k_htt_tx_dec_pending(htt);
4274 spin_unlock_bh(&ar->htt.tx_lock);
4275 ieee80211_free_txskb(ar->hw, skb);
4278 spin_unlock_bh(&ar->htt.tx_lock);
4281 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4283 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4285 spin_lock_bh(&ar->htt.tx_lock);
4286 ath10k_htt_tx_dec_pending(htt);
4288 ath10k_htt_tx_mgmt_dec_pending(htt);
4289 spin_unlock_bh(&ar->htt.tx_lock);
4295 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4296 struct ieee80211_txq *txq)
4298 struct ath10k *ar = hw->priv;
4299 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4300 struct ieee80211_txq *f_txq;
4301 struct ath10k_txq *f_artxq;
4303 int max = HTC_HOST_MAX_MSG_PER_TX_BUNDLE;
4305 spin_lock_bh(&ar->txqs_lock);
4306 if (list_empty(&artxq->list))
4307 list_add_tail(&artxq->list, &ar->txqs);
4309 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4310 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4311 list_del_init(&f_artxq->list);
4313 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4314 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4319 list_add_tail(&f_artxq->list, &ar->txqs);
4320 spin_unlock_bh(&ar->txqs_lock);
4322 ath10k_htt_tx_txq_update(hw, f_txq);
4323 ath10k_htt_tx_txq_update(hw, txq);
4326 /* Must not be called with conf_mutex held as workers can use that also. */
4327 void ath10k_drain_tx(struct ath10k *ar)
4329 /* make sure rcu-protected mac80211 tx path itself is drained */
4332 ath10k_offchan_tx_purge(ar);
4333 ath10k_mgmt_over_wmi_tx_purge(ar);
4335 cancel_work_sync(&ar->offchan_tx_work);
4336 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4339 void ath10k_halt(struct ath10k *ar)
4341 struct ath10k_vif *arvif;
4343 lockdep_assert_held(&ar->conf_mutex);
4345 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4346 ar->filter_flags = 0;
4347 ar->monitor = false;
4348 ar->monitor_arvif = NULL;
4350 if (ar->monitor_started)
4351 ath10k_monitor_stop(ar);
4353 ar->monitor_started = false;
4356 ath10k_scan_finish(ar);
4357 ath10k_peer_cleanup_all(ar);
4358 ath10k_stop_radar_confirmation(ar);
4359 ath10k_core_stop(ar);
4360 ath10k_hif_power_down(ar);
4362 spin_lock_bh(&ar->data_lock);
4363 list_for_each_entry(arvif, &ar->arvifs, list)
4364 ath10k_mac_vif_beacon_cleanup(arvif);
4365 spin_unlock_bh(&ar->data_lock);
4368 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4370 struct ath10k *ar = hw->priv;
4372 mutex_lock(&ar->conf_mutex);
4374 *tx_ant = ar->cfg_tx_chainmask;
4375 *rx_ant = ar->cfg_rx_chainmask;
4377 mutex_unlock(&ar->conf_mutex);
4382 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4384 /* It is not clear that allowing gaps in chainmask
4385 * is helpful. Probably it will not do what user
4386 * is hoping for, so warn in that case.
4388 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4391 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4395 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4397 int nsts = ar->vht_cap_info;
4399 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4400 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4402 /* If firmware does not deliver to host number of space-time
4403 * streams supported, assume it support up to 4 BF STS and return
4404 * the value for VHT CAP: nsts-1)
4412 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4414 int sound_dim = ar->vht_cap_info;
4416 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4417 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4419 /* If the sounding dimension is not advertised by the firmware,
4420 * let's use a default value of 1
4428 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4430 struct ieee80211_sta_vht_cap vht_cap = {0};
4431 struct ath10k_hw_params *hw = &ar->hw_params;
4436 vht_cap.vht_supported = 1;
4437 vht_cap.cap = ar->vht_cap_info;
4439 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4440 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4441 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4442 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4443 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4448 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4449 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4450 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4451 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4452 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4457 /* Currently the firmware seems to be buggy, don't enable 80+80
4458 * mode until that's resolved.
4460 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4461 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4462 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4465 for (i = 0; i < 8; i++) {
4466 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4467 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4469 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4472 if (ar->cfg_tx_chainmask <= 1)
4473 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4475 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4476 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4478 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4479 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4480 * user-space a clue if that is the case.
4482 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4483 (hw->vht160_mcs_rx_highest != 0 ||
4484 hw->vht160_mcs_tx_highest != 0)) {
4485 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4486 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4492 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4495 struct ieee80211_sta_ht_cap ht_cap = {0};
4497 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4500 ht_cap.ht_supported = 1;
4501 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4502 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4503 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4504 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4506 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4508 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4509 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4511 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4512 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4514 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4517 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4518 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4523 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4524 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4526 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4529 stbc = ar->ht_cap_info;
4530 stbc &= WMI_HT_CAP_RX_STBC;
4531 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4532 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4533 stbc &= IEEE80211_HT_CAP_RX_STBC;
4538 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4539 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4541 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4542 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4544 /* max AMSDU is implicitly taken from vht_cap_info */
4545 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4546 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4548 for (i = 0; i < ar->num_rf_chains; i++) {
4549 if (ar->cfg_rx_chainmask & BIT(i))
4550 ht_cap.mcs.rx_mask[i] = 0xFF;
4553 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4558 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4560 struct ieee80211_supported_band *band;
4561 struct ieee80211_sta_vht_cap vht_cap;
4562 struct ieee80211_sta_ht_cap ht_cap;
4564 ht_cap = ath10k_get_ht_cap(ar);
4565 vht_cap = ath10k_create_vht_cap(ar);
4567 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4568 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4569 band->ht_cap = ht_cap;
4571 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4572 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4573 band->ht_cap = ht_cap;
4574 band->vht_cap = vht_cap;
4578 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4582 lockdep_assert_held(&ar->conf_mutex);
4584 ath10k_check_chain_mask(ar, tx_ant, "tx");
4585 ath10k_check_chain_mask(ar, rx_ant, "rx");
4587 ar->cfg_tx_chainmask = tx_ant;
4588 ar->cfg_rx_chainmask = rx_ant;
4590 if ((ar->state != ATH10K_STATE_ON) &&
4591 (ar->state != ATH10K_STATE_RESTARTED))
4594 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4597 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4602 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4605 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4610 /* Reload HT/VHT capability */
4611 ath10k_mac_setup_ht_vht_cap(ar);
4616 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4618 struct ath10k *ar = hw->priv;
4621 mutex_lock(&ar->conf_mutex);
4622 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4623 mutex_unlock(&ar->conf_mutex);
4627 static int ath10k_start(struct ieee80211_hw *hw)
4629 struct ath10k *ar = hw->priv;
4634 * This makes sense only when restarting hw. It is harmless to call
4635 * unconditionally. This is necessary to make sure no HTT/WMI tx
4636 * commands will be submitted while restarting.
4638 ath10k_drain_tx(ar);
4640 mutex_lock(&ar->conf_mutex);
4642 switch (ar->state) {
4643 case ATH10K_STATE_OFF:
4644 ar->state = ATH10K_STATE_ON;
4646 case ATH10K_STATE_RESTARTING:
4647 ar->state = ATH10K_STATE_RESTARTED;
4649 case ATH10K_STATE_ON:
4650 case ATH10K_STATE_RESTARTED:
4651 case ATH10K_STATE_WEDGED:
4655 case ATH10K_STATE_UTF:
4660 ret = ath10k_hif_power_up(ar);
4662 ath10k_err(ar, "Could not init hif: %d\n", ret);
4666 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4667 &ar->normal_mode_fw);
4669 ath10k_err(ar, "Could not init core: %d\n", ret);
4670 goto err_power_down;
4673 param = ar->wmi.pdev_param->pmf_qos;
4674 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4676 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4680 param = ar->wmi.pdev_param->dynamic_bw;
4681 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4683 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4687 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
4688 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
4690 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
4695 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4696 ret = ath10k_wmi_adaptive_qcs(ar, true);
4698 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4704 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4705 param = ar->wmi.pdev_param->burst_enable;
4706 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4708 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4713 param = ar->wmi.pdev_param->idle_ps_config;
4714 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4715 if (ret && ret != -EOPNOTSUPP) {
4716 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4720 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4723 * By default FW set ARP frames ac to voice (6). In that case ARP
4724 * exchange is not working properly for UAPSD enabled AP. ARP requests
4725 * which arrives with access category 0 are processed by network stack
4726 * and send back with access category 0, but FW changes access category
4727 * to 6. Set ARP frames access category to best effort (0) solves
4731 param = ar->wmi.pdev_param->arp_ac_override;
4732 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4734 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4739 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4740 ar->running_fw->fw_file.fw_features)) {
4741 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4742 WMI_CCA_DETECT_LEVEL_AUTO,
4743 WMI_CCA_DETECT_MARGIN_AUTO);
4745 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4751 param = ar->wmi.pdev_param->ani_enable;
4752 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4754 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4759 ar->ani_enabled = true;
4761 if (ath10k_peer_stats_enabled(ar)) {
4762 param = ar->wmi.pdev_param->peer_stats_update_period;
4763 ret = ath10k_wmi_pdev_set_param(ar, param,
4764 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4767 "failed to set peer stats period : %d\n",
4773 param = ar->wmi.pdev_param->enable_btcoex;
4774 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4775 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4776 ar->running_fw->fw_file.fw_features)) {
4777 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4780 "failed to set btcoex param: %d\n", ret);
4783 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4786 ar->num_started_vdevs = 0;
4787 ath10k_regd_update(ar);
4789 ath10k_spectral_start(ar);
4790 ath10k_thermal_set_throttling(ar);
4792 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
4794 mutex_unlock(&ar->conf_mutex);
4798 ath10k_core_stop(ar);
4801 ath10k_hif_power_down(ar);
4804 ar->state = ATH10K_STATE_OFF;
4807 mutex_unlock(&ar->conf_mutex);
4811 static void ath10k_stop(struct ieee80211_hw *hw)
4813 struct ath10k *ar = hw->priv;
4815 ath10k_drain_tx(ar);
4817 mutex_lock(&ar->conf_mutex);
4818 if (ar->state != ATH10K_STATE_OFF) {
4820 ar->state = ATH10K_STATE_OFF;
4822 mutex_unlock(&ar->conf_mutex);
4824 cancel_work_sync(&ar->set_coverage_class_work);
4825 cancel_delayed_work_sync(&ar->scan.timeout);
4826 cancel_work_sync(&ar->restart_work);
4829 static int ath10k_config_ps(struct ath10k *ar)
4831 struct ath10k_vif *arvif;
4834 lockdep_assert_held(&ar->conf_mutex);
4836 list_for_each_entry(arvif, &ar->arvifs, list) {
4837 ret = ath10k_mac_vif_setup_ps(arvif);
4839 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4847 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4852 lockdep_assert_held(&ar->conf_mutex);
4854 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4856 param = ar->wmi.pdev_param->txpower_limit2g;
4857 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4859 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4864 param = ar->wmi.pdev_param->txpower_limit5g;
4865 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4867 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4875 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4877 struct ath10k_vif *arvif;
4878 int ret, txpower = -1;
4880 lockdep_assert_held(&ar->conf_mutex);
4882 list_for_each_entry(arvif, &ar->arvifs, list) {
4883 if (arvif->txpower <= 0)
4887 txpower = arvif->txpower;
4889 txpower = min(txpower, arvif->txpower);
4895 ret = ath10k_mac_txpower_setup(ar, txpower);
4897 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4905 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4907 struct ath10k *ar = hw->priv;
4908 struct ieee80211_conf *conf = &hw->conf;
4911 mutex_lock(&ar->conf_mutex);
4913 if (changed & IEEE80211_CONF_CHANGE_PS)
4914 ath10k_config_ps(ar);
4916 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4917 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4918 ret = ath10k_monitor_recalc(ar);
4920 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4923 mutex_unlock(&ar->conf_mutex);
4927 static u32 get_nss_from_chainmask(u16 chain_mask)
4929 if ((chain_mask & 0xf) == 0xf)
4931 else if ((chain_mask & 0x7) == 0x7)
4933 else if ((chain_mask & 0x3) == 0x3)
4938 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4941 struct ath10k *ar = arvif->ar;
4945 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4948 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4949 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4950 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4951 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4953 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4954 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4955 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4956 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4961 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4962 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4964 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4965 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4966 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4968 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4969 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4971 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4972 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4973 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4975 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4976 ar->wmi.vdev_param->txbf, value);
4981 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4982 * because we will send mgmt frames without CCK. This requirement
4983 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4986 static int ath10k_add_interface(struct ieee80211_hw *hw,
4987 struct ieee80211_vif *vif)
4989 struct ath10k *ar = hw->priv;
4990 struct ath10k_vif *arvif = (void *)vif->drv_priv;
4991 struct ath10k_peer *peer;
4992 enum wmi_sta_powersave_param param;
4999 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5001 mutex_lock(&ar->conf_mutex);
5003 memset(arvif, 0, sizeof(*arvif));
5004 ath10k_mac_txq_init(vif->txq);
5009 INIT_LIST_HEAD(&arvif->list);
5010 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5011 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5012 ath10k_mac_vif_sta_connection_loss_work);
5014 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5015 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5016 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5017 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5018 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5019 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5022 if (ar->num_peers >= ar->max_num_peers) {
5023 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5028 if (ar->free_vdev_map == 0) {
5029 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5033 bit = __ffs64(ar->free_vdev_map);
5035 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5036 bit, ar->free_vdev_map);
5038 arvif->vdev_id = bit;
5039 arvif->vdev_subtype =
5040 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5042 switch (vif->type) {
5043 case NL80211_IFTYPE_P2P_DEVICE:
5044 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5045 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5046 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5048 case NL80211_IFTYPE_UNSPECIFIED:
5049 case NL80211_IFTYPE_STATION:
5050 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5052 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5053 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5055 case NL80211_IFTYPE_ADHOC:
5056 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5058 case NL80211_IFTYPE_MESH_POINT:
5059 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5060 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5061 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5062 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5064 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5067 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5069 case NL80211_IFTYPE_AP:
5070 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5073 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5074 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5076 case NL80211_IFTYPE_MONITOR:
5077 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5084 /* Using vdev_id as queue number will make it very easy to do per-vif
5085 * tx queue locking. This shouldn't wrap due to interface combinations
5086 * but do a modulo for correctness sake and prevent using offchannel tx
5087 * queues for regular vif tx.
5089 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5090 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5091 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5093 /* Some firmware revisions don't wait for beacon tx completion before
5094 * sending another SWBA event. This could lead to hardware using old
5095 * (freed) beacon data in some cases, e.g. tx credit starvation
5096 * combined with missed TBTT. This is very very rare.
5098 * On non-IOMMU-enabled hosts this could be a possible security issue
5099 * because hw could beacon some random data on the air. On
5100 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5101 * device would crash.
5103 * Since there are no beacon tx completions (implicit nor explicit)
5104 * propagated to host the only workaround for this is to allocate a
5105 * DMA-coherent buffer for a lifetime of a vif and use it for all
5106 * beacon tx commands. Worst case for this approach is some beacons may
5107 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5109 if (vif->type == NL80211_IFTYPE_ADHOC ||
5110 vif->type == NL80211_IFTYPE_MESH_POINT ||
5111 vif->type == NL80211_IFTYPE_AP) {
5112 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
5113 IEEE80211_MAX_FRAME_LEN,
5114 &arvif->beacon_paddr,
5116 if (!arvif->beacon_buf) {
5118 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5123 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5124 arvif->nohwcrypt = true;
5126 if (arvif->nohwcrypt &&
5127 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5129 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5133 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5134 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5135 arvif->beacon_buf ? "single-buf" : "per-skb");
5137 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5138 arvif->vdev_subtype, vif->addr);
5140 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5141 arvif->vdev_id, ret);
5145 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5146 spin_lock_bh(&ar->data_lock);
5147 list_add(&arvif->list, &ar->arvifs);
5148 spin_unlock_bh(&ar->data_lock);
5150 /* It makes no sense to have firmware do keepalives. mac80211 already
5151 * takes care of this with idle connection polling.
5153 ret = ath10k_mac_vif_disable_keepalive(arvif);
5155 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5156 arvif->vdev_id, ret);
5157 goto err_vdev_delete;
5160 arvif->def_wep_key_idx = -1;
5162 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5163 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5164 ATH10K_HW_TXRX_NATIVE_WIFI);
5165 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5166 if (ret && ret != -EOPNOTSUPP) {
5167 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5168 arvif->vdev_id, ret);
5169 goto err_vdev_delete;
5172 /* Configuring number of spatial stream for monitor interface is causing
5173 * target assert in qca9888 and qca6174.
5175 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5176 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5178 vdev_param = ar->wmi.vdev_param->nss;
5179 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5182 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5183 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5185 goto err_vdev_delete;
5189 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5190 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5191 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5192 vif->addr, WMI_PEER_TYPE_DEFAULT);
5194 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5195 arvif->vdev_id, ret);
5196 goto err_vdev_delete;
5199 spin_lock_bh(&ar->data_lock);
5201 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5203 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5204 vif->addr, arvif->vdev_id);
5205 spin_unlock_bh(&ar->data_lock);
5207 goto err_peer_delete;
5210 arvif->peer_id = find_first_bit(peer->peer_ids,
5211 ATH10K_MAX_NUM_PEER_IDS);
5213 spin_unlock_bh(&ar->data_lock);
5215 arvif->peer_id = HTT_INVALID_PEERID;
5218 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5219 ret = ath10k_mac_set_kickout(arvif);
5221 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5222 arvif->vdev_id, ret);
5223 goto err_peer_delete;
5227 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5228 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5229 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5230 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5233 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5234 arvif->vdev_id, ret);
5235 goto err_peer_delete;
5238 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5240 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5241 arvif->vdev_id, ret);
5242 goto err_peer_delete;
5245 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5247 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5248 arvif->vdev_id, ret);
5249 goto err_peer_delete;
5253 ret = ath10k_mac_set_txbf_conf(arvif);
5255 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5256 arvif->vdev_id, ret);
5257 goto err_peer_delete;
5260 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5262 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5263 arvif->vdev_id, ret);
5264 goto err_peer_delete;
5267 arvif->txpower = vif->bss_conf.txpower;
5268 ret = ath10k_mac_txpower_recalc(ar);
5270 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5271 goto err_peer_delete;
5274 if (vif->type == NL80211_IFTYPE_MONITOR) {
5275 ar->monitor_arvif = arvif;
5276 ret = ath10k_monitor_recalc(ar);
5278 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5279 goto err_peer_delete;
5283 spin_lock_bh(&ar->htt.tx_lock);
5285 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5286 spin_unlock_bh(&ar->htt.tx_lock);
5288 mutex_unlock(&ar->conf_mutex);
5292 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5293 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5294 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5297 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5298 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5299 spin_lock_bh(&ar->data_lock);
5300 list_del(&arvif->list);
5301 spin_unlock_bh(&ar->data_lock);
5304 if (arvif->beacon_buf) {
5305 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5306 arvif->beacon_buf, arvif->beacon_paddr);
5307 arvif->beacon_buf = NULL;
5310 mutex_unlock(&ar->conf_mutex);
5315 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5319 for (i = 0; i < BITS_PER_LONG; i++)
5320 ath10k_mac_vif_tx_unlock(arvif, i);
5323 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5324 struct ieee80211_vif *vif)
5326 struct ath10k *ar = hw->priv;
5327 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5328 struct ath10k_peer *peer;
5332 cancel_work_sync(&arvif->ap_csa_work);
5333 cancel_delayed_work_sync(&arvif->connection_loss_work);
5335 mutex_lock(&ar->conf_mutex);
5337 spin_lock_bh(&ar->data_lock);
5338 ath10k_mac_vif_beacon_cleanup(arvif);
5339 spin_unlock_bh(&ar->data_lock);
5341 ret = ath10k_spectral_vif_stop(arvif);
5343 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5344 arvif->vdev_id, ret);
5346 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5347 spin_lock_bh(&ar->data_lock);
5348 list_del(&arvif->list);
5349 spin_unlock_bh(&ar->data_lock);
5351 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5352 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5353 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5356 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5357 arvif->vdev_id, ret);
5359 kfree(arvif->u.ap.noa_data);
5362 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5365 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5367 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5368 arvif->vdev_id, ret);
5370 /* Some firmware revisions don't notify host about self-peer removal
5371 * until after associated vdev is deleted.
5373 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5374 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5375 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5378 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5379 arvif->vdev_id, ret);
5381 spin_lock_bh(&ar->data_lock);
5383 spin_unlock_bh(&ar->data_lock);
5386 spin_lock_bh(&ar->data_lock);
5387 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5388 peer = ar->peer_map[i];
5392 if (peer->vif == vif) {
5393 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5394 vif->addr, arvif->vdev_id);
5398 spin_unlock_bh(&ar->data_lock);
5400 ath10k_peer_cleanup(ar, arvif->vdev_id);
5401 ath10k_mac_txq_unref(ar, vif->txq);
5403 if (vif->type == NL80211_IFTYPE_MONITOR) {
5404 ar->monitor_arvif = NULL;
5405 ret = ath10k_monitor_recalc(ar);
5407 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5410 ret = ath10k_mac_txpower_recalc(ar);
5412 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5414 spin_lock_bh(&ar->htt.tx_lock);
5415 ath10k_mac_vif_tx_unlock_all(arvif);
5416 spin_unlock_bh(&ar->htt.tx_lock);
5418 ath10k_mac_txq_unref(ar, vif->txq);
5420 mutex_unlock(&ar->conf_mutex);
5424 * FIXME: Has to be verified.
5426 #define SUPPORTED_FILTERS \
5431 FIF_BCN_PRBRESP_PROMISC | \
5435 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5436 unsigned int changed_flags,
5437 unsigned int *total_flags,
5440 struct ath10k *ar = hw->priv;
5443 mutex_lock(&ar->conf_mutex);
5445 changed_flags &= SUPPORTED_FILTERS;
5446 *total_flags &= SUPPORTED_FILTERS;
5447 ar->filter_flags = *total_flags;
5449 ret = ath10k_monitor_recalc(ar);
5451 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5453 mutex_unlock(&ar->conf_mutex);
5456 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5457 struct ieee80211_vif *vif,
5458 struct ieee80211_bss_conf *info,
5461 struct ath10k *ar = hw->priv;
5462 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5463 struct cfg80211_chan_def def;
5464 u32 vdev_param, pdev_param, slottime, preamble;
5465 u16 bitrate, hw_value;
5467 int rateidx, ret = 0;
5468 enum nl80211_band band;
5470 mutex_lock(&ar->conf_mutex);
5472 if (changed & BSS_CHANGED_IBSS)
5473 ath10k_control_ibss(arvif, info, vif->addr);
5475 if (changed & BSS_CHANGED_BEACON_INT) {
5476 arvif->beacon_interval = info->beacon_int;
5477 vdev_param = ar->wmi.vdev_param->beacon_interval;
5478 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5479 arvif->beacon_interval);
5480 ath10k_dbg(ar, ATH10K_DBG_MAC,
5481 "mac vdev %d beacon_interval %d\n",
5482 arvif->vdev_id, arvif->beacon_interval);
5485 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5486 arvif->vdev_id, ret);
5489 if (changed & BSS_CHANGED_BEACON) {
5490 ath10k_dbg(ar, ATH10K_DBG_MAC,
5491 "vdev %d set beacon tx mode to staggered\n",
5494 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5495 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5496 WMI_BEACON_STAGGERED_MODE);
5498 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5499 arvif->vdev_id, ret);
5501 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5503 ath10k_warn(ar, "failed to update beacon template: %d\n",
5506 if (ieee80211_vif_is_mesh(vif)) {
5507 /* mesh doesn't use SSID but firmware needs it */
5508 strncpy(arvif->u.ap.ssid, "mesh",
5509 sizeof(arvif->u.ap.ssid));
5510 arvif->u.ap.ssid_len = 4;
5514 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5515 ret = ath10k_mac_setup_prb_tmpl(arvif);
5517 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5518 arvif->vdev_id, ret);
5521 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5522 arvif->dtim_period = info->dtim_period;
5524 ath10k_dbg(ar, ATH10K_DBG_MAC,
5525 "mac vdev %d dtim_period %d\n",
5526 arvif->vdev_id, arvif->dtim_period);
5528 vdev_param = ar->wmi.vdev_param->dtim_period;
5529 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5530 arvif->dtim_period);
5532 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5533 arvif->vdev_id, ret);
5536 if (changed & BSS_CHANGED_SSID &&
5537 vif->type == NL80211_IFTYPE_AP) {
5538 arvif->u.ap.ssid_len = info->ssid_len;
5540 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5541 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5544 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5545 ether_addr_copy(arvif->bssid, info->bssid);
5547 if (changed & BSS_CHANGED_BEACON_ENABLED)
5548 ath10k_control_beaconing(arvif, info);
5550 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5551 arvif->use_cts_prot = info->use_cts_prot;
5553 ret = ath10k_recalc_rtscts_prot(arvif);
5555 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5556 arvif->vdev_id, ret);
5558 if (ath10k_mac_can_set_cts_prot(arvif)) {
5559 ret = ath10k_mac_set_cts_prot(arvif);
5561 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5562 arvif->vdev_id, ret);
5566 if (changed & BSS_CHANGED_ERP_SLOT) {
5567 if (info->use_short_slot)
5568 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5571 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5573 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5574 arvif->vdev_id, slottime);
5576 vdev_param = ar->wmi.vdev_param->slot_time;
5577 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5580 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5581 arvif->vdev_id, ret);
5584 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5585 if (info->use_short_preamble)
5586 preamble = WMI_VDEV_PREAMBLE_SHORT;
5588 preamble = WMI_VDEV_PREAMBLE_LONG;
5590 ath10k_dbg(ar, ATH10K_DBG_MAC,
5591 "mac vdev %d preamble %dn",
5592 arvif->vdev_id, preamble);
5594 vdev_param = ar->wmi.vdev_param->preamble;
5595 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5598 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5599 arvif->vdev_id, ret);
5602 if (changed & BSS_CHANGED_ASSOC) {
5604 /* Workaround: Make sure monitor vdev is not running
5605 * when associating to prevent some firmware revisions
5606 * (e.g. 10.1 and 10.2) from crashing.
5608 if (ar->monitor_started)
5609 ath10k_monitor_stop(ar);
5610 ath10k_bss_assoc(hw, vif, info);
5611 ath10k_monitor_recalc(ar);
5613 ath10k_bss_disassoc(hw, vif);
5617 if (changed & BSS_CHANGED_TXPOWER) {
5618 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5619 arvif->vdev_id, info->txpower);
5621 arvif->txpower = info->txpower;
5622 ret = ath10k_mac_txpower_recalc(ar);
5624 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5627 if (changed & BSS_CHANGED_PS) {
5628 arvif->ps = vif->bss_conf.ps;
5630 ret = ath10k_config_ps(ar);
5632 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5633 arvif->vdev_id, ret);
5636 if (changed & BSS_CHANGED_MCAST_RATE &&
5637 !ath10k_mac_vif_chan(arvif->vif, &def)) {
5638 band = def.chan->band;
5639 rateidx = vif->bss_conf.mcast_rate[band] - 1;
5641 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5642 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5644 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
5645 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
5646 if (ath10k_mac_bitrate_is_cck(bitrate))
5647 preamble = WMI_RATE_PREAMBLE_CCK;
5649 preamble = WMI_RATE_PREAMBLE_OFDM;
5651 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
5653 ath10k_dbg(ar, ATH10K_DBG_MAC,
5654 "mac vdev %d mcast_rate %x\n",
5655 arvif->vdev_id, rate);
5657 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5658 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5662 "failed to set mcast rate on vdev %i: %d\n",
5663 arvif->vdev_id, ret);
5665 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5666 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5670 "failed to set bcast rate on vdev %i: %d\n",
5671 arvif->vdev_id, ret);
5674 mutex_unlock(&ar->conf_mutex);
5677 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5679 struct ath10k *ar = hw->priv;
5681 /* This function should never be called if setting the coverage class
5682 * is not supported on this hardware.
5684 if (!ar->hw_params.hw_ops->set_coverage_class) {
5688 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5691 struct ath10k_mac_tdls_iter_data {
5692 u32 num_tdls_stations;
5693 struct ieee80211_vif *curr_vif;
5696 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5697 struct ieee80211_sta *sta)
5699 struct ath10k_mac_tdls_iter_data *iter_data = data;
5700 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5701 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5703 if (sta->tdls && sta_vif == iter_data->curr_vif)
5704 iter_data->num_tdls_stations++;
5707 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5708 struct ieee80211_vif *vif)
5710 struct ath10k_mac_tdls_iter_data data = {};
5712 data.curr_vif = vif;
5714 ieee80211_iterate_stations_atomic(hw,
5715 ath10k_mac_tdls_vif_stations_count_iter,
5717 return data.num_tdls_stations;
5720 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5721 struct ieee80211_vif *vif)
5723 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5724 int *num_tdls_vifs = data;
5726 if (vif->type != NL80211_IFTYPE_STATION)
5729 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5733 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5735 int num_tdls_vifs = 0;
5737 ieee80211_iterate_active_interfaces_atomic(hw,
5738 IEEE80211_IFACE_ITER_NORMAL,
5739 ath10k_mac_tdls_vifs_count_iter,
5741 return num_tdls_vifs;
5744 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5745 struct ieee80211_vif *vif,
5746 struct ieee80211_scan_request *hw_req)
5748 struct ath10k *ar = hw->priv;
5749 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5750 struct cfg80211_scan_request *req = &hw_req->req;
5751 struct wmi_start_scan_arg arg;
5756 mutex_lock(&ar->conf_mutex);
5758 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
5763 spin_lock_bh(&ar->data_lock);
5764 switch (ar->scan.state) {
5765 case ATH10K_SCAN_IDLE:
5766 reinit_completion(&ar->scan.started);
5767 reinit_completion(&ar->scan.completed);
5768 ar->scan.state = ATH10K_SCAN_STARTING;
5769 ar->scan.is_roc = false;
5770 ar->scan.vdev_id = arvif->vdev_id;
5773 case ATH10K_SCAN_STARTING:
5774 case ATH10K_SCAN_RUNNING:
5775 case ATH10K_SCAN_ABORTING:
5779 spin_unlock_bh(&ar->data_lock);
5784 memset(&arg, 0, sizeof(arg));
5785 ath10k_wmi_start_scan_init(ar, &arg);
5786 arg.vdev_id = arvif->vdev_id;
5787 arg.scan_id = ATH10K_SCAN_ID;
5790 arg.ie_len = req->ie_len;
5791 memcpy(arg.ie, req->ie, arg.ie_len);
5795 arg.n_ssids = req->n_ssids;
5796 for (i = 0; i < arg.n_ssids; i++) {
5797 arg.ssids[i].len = req->ssids[i].ssid_len;
5798 arg.ssids[i].ssid = req->ssids[i].ssid;
5801 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5804 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5805 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
5806 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
5807 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
5810 if (req->n_channels) {
5811 arg.n_channels = req->n_channels;
5812 for (i = 0; i < arg.n_channels; i++)
5813 arg.channels[i] = req->channels[i]->center_freq;
5816 /* if duration is set, default dwell times will be overwritten */
5817 if (req->duration) {
5818 arg.dwell_time_active = req->duration;
5819 arg.dwell_time_passive = req->duration;
5820 arg.burst_duration_ms = req->duration;
5822 scan_timeout = min_t(u32, arg.max_rest_time *
5823 (arg.n_channels - 1) + (req->duration +
5824 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
5825 arg.n_channels, arg.max_scan_time + 200);
5828 /* Add a 200ms margin to account for event/command processing */
5829 scan_timeout = arg.max_scan_time + 200;
5832 ret = ath10k_start_scan(ar, &arg);
5834 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5835 spin_lock_bh(&ar->data_lock);
5836 ar->scan.state = ATH10K_SCAN_IDLE;
5837 spin_unlock_bh(&ar->data_lock);
5840 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5841 msecs_to_jiffies(scan_timeout));
5844 mutex_unlock(&ar->conf_mutex);
5848 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5849 struct ieee80211_vif *vif)
5851 struct ath10k *ar = hw->priv;
5853 mutex_lock(&ar->conf_mutex);
5854 ath10k_scan_abort(ar);
5855 mutex_unlock(&ar->conf_mutex);
5857 cancel_delayed_work_sync(&ar->scan.timeout);
5860 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5861 struct ath10k_vif *arvif,
5862 enum set_key_cmd cmd,
5863 struct ieee80211_key_conf *key)
5865 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5868 /* 10.1 firmware branch requires default key index to be set to group
5869 * key index after installing it. Otherwise FW/HW Txes corrupted
5870 * frames with multi-vif APs. This is not required for main firmware
5871 * branch (e.g. 636).
5873 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5875 * FIXME: It remains unknown if this is required for multi-vif STA
5876 * interfaces on 10.1.
5879 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5880 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5883 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5886 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5889 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5895 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5898 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5899 arvif->vdev_id, ret);
5902 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5903 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5904 struct ieee80211_key_conf *key)
5906 struct ath10k *ar = hw->priv;
5907 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5908 struct ath10k_peer *peer;
5909 const u8 *peer_addr;
5910 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5911 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5917 /* this one needs to be done in software */
5918 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
5919 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
5920 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
5921 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
5924 if (arvif->nohwcrypt)
5927 if (key->keyidx > WMI_MAX_KEY_INDEX)
5930 mutex_lock(&ar->conf_mutex);
5933 peer_addr = sta->addr;
5934 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5935 peer_addr = vif->bss_conf.bssid;
5937 peer_addr = vif->addr;
5939 key->hw_key_idx = key->keyidx;
5943 arvif->wep_keys[key->keyidx] = key;
5945 arvif->wep_keys[key->keyidx] = NULL;
5948 /* the peer should not disappear in mid-way (unless FW goes awry) since
5949 * we already hold conf_mutex. we just make sure its there now.
5951 spin_lock_bh(&ar->data_lock);
5952 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5953 spin_unlock_bh(&ar->data_lock);
5956 if (cmd == SET_KEY) {
5957 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5962 /* if the peer doesn't exist there is no key to disable anymore */
5967 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5968 flags |= WMI_KEY_PAIRWISE;
5970 flags |= WMI_KEY_GROUP;
5973 if (cmd == DISABLE_KEY)
5974 ath10k_clear_vdev_key(arvif, key);
5976 /* When WEP keys are uploaded it's possible that there are
5977 * stations associated already (e.g. when merging) without any
5978 * keys. Static WEP needs an explicit per-peer key upload.
5980 if (vif->type == NL80211_IFTYPE_ADHOC &&
5982 ath10k_mac_vif_update_wep_key(arvif, key);
5984 /* 802.1x never sets the def_wep_key_idx so each set_key()
5985 * call changes default tx key.
5987 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5988 * after first set_key().
5990 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5991 flags |= WMI_KEY_TX_USAGE;
5994 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5997 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5998 arvif->vdev_id, peer_addr, ret);
6002 /* mac80211 sets static WEP keys as groupwise while firmware requires
6003 * them to be installed twice as both pairwise and groupwise.
6005 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6007 flags2 &= ~WMI_KEY_GROUP;
6008 flags2 |= WMI_KEY_PAIRWISE;
6010 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6013 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6014 arvif->vdev_id, peer_addr, ret);
6015 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6019 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6020 arvif->vdev_id, peer_addr, ret2);
6026 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6028 spin_lock_bh(&ar->data_lock);
6029 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6030 if (peer && cmd == SET_KEY)
6031 peer->keys[key->keyidx] = key;
6032 else if (peer && cmd == DISABLE_KEY)
6033 peer->keys[key->keyidx] = NULL;
6034 else if (peer == NULL)
6035 /* impossible unless FW goes crazy */
6036 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6037 spin_unlock_bh(&ar->data_lock);
6039 if (sta && sta->tdls)
6040 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6041 WMI_PEER_AUTHORIZE, 1);
6044 mutex_unlock(&ar->conf_mutex);
6048 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6049 struct ieee80211_vif *vif,
6052 struct ath10k *ar = hw->priv;
6053 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6056 mutex_lock(&arvif->ar->conf_mutex);
6058 if (arvif->ar->state != ATH10K_STATE_ON)
6061 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6062 arvif->vdev_id, keyidx);
6064 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6066 arvif->ar->wmi.vdev_param->def_keyid,
6070 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6076 arvif->def_wep_key_idx = keyidx;
6079 mutex_unlock(&arvif->ar->conf_mutex);
6082 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6085 struct ath10k_vif *arvif;
6086 struct ath10k_sta *arsta;
6087 struct ieee80211_sta *sta;
6088 struct cfg80211_chan_def def;
6089 enum nl80211_band band;
6090 const u8 *ht_mcs_mask;
6091 const u16 *vht_mcs_mask;
6092 u32 changed, bw, nss, smps;
6095 arsta = container_of(wk, struct ath10k_sta, update_wk);
6096 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6097 arvif = arsta->arvif;
6100 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6103 band = def.chan->band;
6104 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6105 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6107 spin_lock_bh(&ar->data_lock);
6109 changed = arsta->changed;
6116 spin_unlock_bh(&ar->data_lock);
6118 mutex_lock(&ar->conf_mutex);
6120 nss = max_t(u32, 1, nss);
6121 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6122 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6124 if (changed & IEEE80211_RC_BW_CHANGED) {
6125 enum wmi_phy_mode mode;
6127 mode = chan_to_phymode(&def);
6128 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
6129 sta->addr, bw, mode);
6131 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6132 WMI_PEER_PHYMODE, mode);
6134 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6135 sta->addr, mode, err);
6139 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6140 WMI_PEER_CHAN_WIDTH, bw);
6142 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6143 sta->addr, bw, err);
6146 if (changed & IEEE80211_RC_NSS_CHANGED) {
6147 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
6150 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6153 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6154 sta->addr, nss, err);
6157 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6158 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
6161 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6162 WMI_PEER_SMPS_STATE, smps);
6164 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6165 sta->addr, smps, err);
6168 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6169 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
6172 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6174 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6179 mutex_unlock(&ar->conf_mutex);
6182 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6183 struct ieee80211_sta *sta)
6185 struct ath10k *ar = arvif->ar;
6187 lockdep_assert_held(&ar->conf_mutex);
6189 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6192 if (ar->num_stations >= ar->max_num_stations)
6200 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6201 struct ieee80211_sta *sta)
6203 struct ath10k *ar = arvif->ar;
6205 lockdep_assert_held(&ar->conf_mutex);
6207 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6213 static int ath10k_sta_state(struct ieee80211_hw *hw,
6214 struct ieee80211_vif *vif,
6215 struct ieee80211_sta *sta,
6216 enum ieee80211_sta_state old_state,
6217 enum ieee80211_sta_state new_state)
6219 struct ath10k *ar = hw->priv;
6220 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6221 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6222 struct ath10k_peer *peer;
6226 if (old_state == IEEE80211_STA_NOTEXIST &&
6227 new_state == IEEE80211_STA_NONE) {
6228 memset(arsta, 0, sizeof(*arsta));
6229 arsta->arvif = arvif;
6230 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6232 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6233 ath10k_mac_txq_init(sta->txq[i]);
6236 /* cancel must be done outside the mutex to avoid deadlock */
6237 if ((old_state == IEEE80211_STA_NONE &&
6238 new_state == IEEE80211_STA_NOTEXIST))
6239 cancel_work_sync(&arsta->update_wk);
6241 mutex_lock(&ar->conf_mutex);
6243 if (old_state == IEEE80211_STA_NOTEXIST &&
6244 new_state == IEEE80211_STA_NONE) {
6246 * New station addition.
6248 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6249 u32 num_tdls_stations;
6252 ath10k_dbg(ar, ATH10K_DBG_MAC,
6253 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6254 arvif->vdev_id, sta->addr,
6255 ar->num_stations + 1, ar->max_num_stations,
6256 ar->num_peers + 1, ar->max_num_peers);
6258 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6259 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6262 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6263 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6265 ar->max_num_tdls_vdevs);
6269 peer_type = WMI_PEER_TYPE_TDLS;
6272 ret = ath10k_mac_inc_num_stations(arvif, sta);
6274 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6275 ar->max_num_stations);
6279 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6280 sta->addr, peer_type);
6282 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6283 sta->addr, arvif->vdev_id, ret);
6284 ath10k_mac_dec_num_stations(arvif, sta);
6288 spin_lock_bh(&ar->data_lock);
6290 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6292 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6293 vif->addr, arvif->vdev_id);
6294 spin_unlock_bh(&ar->data_lock);
6295 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6296 ath10k_mac_dec_num_stations(arvif, sta);
6301 arsta->peer_id = find_first_bit(peer->peer_ids,
6302 ATH10K_MAX_NUM_PEER_IDS);
6304 spin_unlock_bh(&ar->data_lock);
6309 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6310 WMI_TDLS_ENABLE_ACTIVE);
6312 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6313 arvif->vdev_id, ret);
6314 ath10k_peer_delete(ar, arvif->vdev_id,
6316 ath10k_mac_dec_num_stations(arvif, sta);
6320 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6321 WMI_TDLS_PEER_STATE_PEERING);
6324 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6325 sta->addr, arvif->vdev_id, ret);
6326 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6327 ath10k_mac_dec_num_stations(arvif, sta);
6329 if (num_tdls_stations != 0)
6331 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6334 } else if ((old_state == IEEE80211_STA_NONE &&
6335 new_state == IEEE80211_STA_NOTEXIST)) {
6337 * Existing station deletion.
6339 ath10k_dbg(ar, ATH10K_DBG_MAC,
6340 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6341 arvif->vdev_id, sta->addr, sta);
6344 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6346 WMI_TDLS_PEER_STATE_TEARDOWN);
6348 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6350 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6353 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6355 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6356 sta->addr, arvif->vdev_id, ret);
6358 ath10k_mac_dec_num_stations(arvif, sta);
6360 spin_lock_bh(&ar->data_lock);
6361 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6362 peer = ar->peer_map[i];
6366 if (peer->sta == sta) {
6367 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6368 sta->addr, peer, i, arvif->vdev_id);
6371 /* Clean up the peer object as well since we
6372 * must have failed to do this above.
6374 list_del(&peer->list);
6375 ar->peer_map[i] = NULL;
6380 spin_unlock_bh(&ar->data_lock);
6382 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6383 ath10k_mac_txq_unref(ar, sta->txq[i]);
6388 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6391 /* This was the last tdls peer in current vif */
6392 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6395 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6396 arvif->vdev_id, ret);
6398 } else if (old_state == IEEE80211_STA_AUTH &&
6399 new_state == IEEE80211_STA_ASSOC &&
6400 (vif->type == NL80211_IFTYPE_AP ||
6401 vif->type == NL80211_IFTYPE_MESH_POINT ||
6402 vif->type == NL80211_IFTYPE_ADHOC)) {
6406 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6409 ret = ath10k_station_assoc(ar, vif, sta, false);
6411 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6412 sta->addr, arvif->vdev_id, ret);
6413 } else if (old_state == IEEE80211_STA_ASSOC &&
6414 new_state == IEEE80211_STA_AUTHORIZED &&
6417 * Tdls station authorized.
6419 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6422 ret = ath10k_station_assoc(ar, vif, sta, false);
6424 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6425 sta->addr, arvif->vdev_id, ret);
6429 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6430 WMI_TDLS_PEER_STATE_CONNECTED);
6432 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6433 sta->addr, arvif->vdev_id, ret);
6434 } else if (old_state == IEEE80211_STA_ASSOC &&
6435 new_state == IEEE80211_STA_AUTH &&
6436 (vif->type == NL80211_IFTYPE_AP ||
6437 vif->type == NL80211_IFTYPE_MESH_POINT ||
6438 vif->type == NL80211_IFTYPE_ADHOC)) {
6442 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6445 ret = ath10k_station_disassoc(ar, vif, sta);
6447 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6448 sta->addr, arvif->vdev_id, ret);
6451 mutex_unlock(&ar->conf_mutex);
6455 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6456 u16 ac, bool enable)
6458 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6459 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6460 u32 prio = 0, acc = 0;
6464 lockdep_assert_held(&ar->conf_mutex);
6466 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6470 case IEEE80211_AC_VO:
6471 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6472 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6476 case IEEE80211_AC_VI:
6477 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6478 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6482 case IEEE80211_AC_BE:
6483 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6484 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6488 case IEEE80211_AC_BK:
6489 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6490 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6497 arvif->u.sta.uapsd |= value;
6499 arvif->u.sta.uapsd &= ~value;
6501 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6502 WMI_STA_PS_PARAM_UAPSD,
6503 arvif->u.sta.uapsd);
6505 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6509 if (arvif->u.sta.uapsd)
6510 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6512 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6514 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6515 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6518 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6520 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6522 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6523 arvif->vdev_id, ret);
6527 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6529 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6530 arvif->vdev_id, ret);
6534 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6535 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6536 /* Only userspace can make an educated decision when to send
6537 * trigger frame. The following effectively disables u-UAPSD
6538 * autotrigger in firmware (which is enabled by default
6539 * provided the autotrigger service is available).
6543 arg.user_priority = prio;
6544 arg.service_interval = 0;
6545 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6546 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6548 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6549 arvif->bssid, &arg, 1);
6551 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6561 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6562 struct ieee80211_vif *vif, u16 ac,
6563 const struct ieee80211_tx_queue_params *params)
6565 struct ath10k *ar = hw->priv;
6566 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6567 struct wmi_wmm_params_arg *p = NULL;
6570 mutex_lock(&ar->conf_mutex);
6573 case IEEE80211_AC_VO:
6574 p = &arvif->wmm_params.ac_vo;
6576 case IEEE80211_AC_VI:
6577 p = &arvif->wmm_params.ac_vi;
6579 case IEEE80211_AC_BE:
6580 p = &arvif->wmm_params.ac_be;
6582 case IEEE80211_AC_BK:
6583 p = &arvif->wmm_params.ac_bk;
6592 p->cwmin = params->cw_min;
6593 p->cwmax = params->cw_max;
6594 p->aifs = params->aifs;
6597 * The channel time duration programmed in the HW is in absolute
6598 * microseconds, while mac80211 gives the txop in units of
6601 p->txop = params->txop * 32;
6603 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6604 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6605 &arvif->wmm_params);
6607 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6608 arvif->vdev_id, ret);
6612 /* This won't work well with multi-interface cases but it's
6613 * better than nothing.
6615 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6617 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6622 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6624 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6627 mutex_unlock(&ar->conf_mutex);
6631 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6633 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6634 struct ieee80211_vif *vif,
6635 struct ieee80211_channel *chan,
6637 enum ieee80211_roc_type type)
6639 struct ath10k *ar = hw->priv;
6640 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6641 struct wmi_start_scan_arg arg;
6645 mutex_lock(&ar->conf_mutex);
6647 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6652 spin_lock_bh(&ar->data_lock);
6653 switch (ar->scan.state) {
6654 case ATH10K_SCAN_IDLE:
6655 reinit_completion(&ar->scan.started);
6656 reinit_completion(&ar->scan.completed);
6657 reinit_completion(&ar->scan.on_channel);
6658 ar->scan.state = ATH10K_SCAN_STARTING;
6659 ar->scan.is_roc = true;
6660 ar->scan.vdev_id = arvif->vdev_id;
6661 ar->scan.roc_freq = chan->center_freq;
6662 ar->scan.roc_notify = true;
6665 case ATH10K_SCAN_STARTING:
6666 case ATH10K_SCAN_RUNNING:
6667 case ATH10K_SCAN_ABORTING:
6671 spin_unlock_bh(&ar->data_lock);
6676 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6678 memset(&arg, 0, sizeof(arg));
6679 ath10k_wmi_start_scan_init(ar, &arg);
6680 arg.vdev_id = arvif->vdev_id;
6681 arg.scan_id = ATH10K_SCAN_ID;
6683 arg.channels[0] = chan->center_freq;
6684 arg.dwell_time_active = scan_time_msec;
6685 arg.dwell_time_passive = scan_time_msec;
6686 arg.max_scan_time = scan_time_msec;
6687 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6688 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6689 arg.burst_duration_ms = duration;
6691 ret = ath10k_start_scan(ar, &arg);
6693 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6694 spin_lock_bh(&ar->data_lock);
6695 ar->scan.state = ATH10K_SCAN_IDLE;
6696 spin_unlock_bh(&ar->data_lock);
6700 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6702 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6704 ret = ath10k_scan_stop(ar);
6706 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6712 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6713 msecs_to_jiffies(duration));
6717 mutex_unlock(&ar->conf_mutex);
6721 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6723 struct ath10k *ar = hw->priv;
6725 mutex_lock(&ar->conf_mutex);
6727 spin_lock_bh(&ar->data_lock);
6728 ar->scan.roc_notify = false;
6729 spin_unlock_bh(&ar->data_lock);
6731 ath10k_scan_abort(ar);
6733 mutex_unlock(&ar->conf_mutex);
6735 cancel_delayed_work_sync(&ar->scan.timeout);
6741 * Both RTS and Fragmentation threshold are interface-specific
6742 * in ath10k, but device-specific in mac80211.
6745 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6747 struct ath10k *ar = hw->priv;
6748 struct ath10k_vif *arvif;
6751 mutex_lock(&ar->conf_mutex);
6752 list_for_each_entry(arvif, &ar->arvifs, list) {
6753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6754 arvif->vdev_id, value);
6756 ret = ath10k_mac_set_rts(arvif, value);
6758 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6759 arvif->vdev_id, ret);
6763 mutex_unlock(&ar->conf_mutex);
6768 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6770 /* Even though there's a WMI enum for fragmentation threshold no known
6771 * firmware actually implements it. Moreover it is not possible to rely
6772 * frame fragmentation to mac80211 because firmware clears the "more
6773 * fragments" bit in frame control making it impossible for remote
6774 * devices to reassemble frames.
6776 * Hence implement a dummy callback just to say fragmentation isn't
6777 * supported. This effectively prevents mac80211 from doing frame
6778 * fragmentation in software.
6783 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6784 u32 queues, bool drop)
6786 struct ath10k *ar = hw->priv;
6790 /* mac80211 doesn't care if we really xmit queued frames or not
6791 * we'll collect those frames either way if we stop/delete vdevs
6796 mutex_lock(&ar->conf_mutex);
6798 if (ar->state == ATH10K_STATE_WEDGED)
6801 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6804 spin_lock_bh(&ar->htt.tx_lock);
6805 empty = (ar->htt.num_pending_tx == 0);
6806 spin_unlock_bh(&ar->htt.tx_lock);
6808 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6809 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6813 }), ATH10K_FLUSH_TIMEOUT_HZ);
6815 if (time_left == 0 || skip)
6816 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6817 skip, ar->state, time_left);
6820 mutex_unlock(&ar->conf_mutex);
6823 /* TODO: Implement this function properly
6824 * For now it is needed to reply to Probe Requests in IBSS mode.
6825 * Propably we need this information from FW.
6827 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6832 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6833 enum ieee80211_reconfig_type reconfig_type)
6835 struct ath10k *ar = hw->priv;
6837 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6840 mutex_lock(&ar->conf_mutex);
6842 /* If device failed to restart it will be in a different state, e.g.
6843 * ATH10K_STATE_WEDGED
6845 if (ar->state == ATH10K_STATE_RESTARTED) {
6846 ath10k_info(ar, "device successfully recovered\n");
6847 ar->state = ATH10K_STATE_ON;
6848 ieee80211_wake_queues(ar->hw);
6851 mutex_unlock(&ar->conf_mutex);
6855 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6856 struct ieee80211_channel *channel)
6859 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6861 lockdep_assert_held(&ar->conf_mutex);
6863 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6864 (ar->rx_channel != channel))
6867 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6868 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6872 reinit_completion(&ar->bss_survey_done);
6874 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6876 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6880 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6882 ath10k_warn(ar, "bss channel survey timed out\n");
6887 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6888 struct survey_info *survey)
6890 struct ath10k *ar = hw->priv;
6891 struct ieee80211_supported_band *sband;
6892 struct survey_info *ar_survey = &ar->survey[idx];
6895 mutex_lock(&ar->conf_mutex);
6897 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6898 if (sband && idx >= sband->n_channels) {
6899 idx -= sband->n_channels;
6904 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6906 if (!sband || idx >= sband->n_channels) {
6911 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6913 spin_lock_bh(&ar->data_lock);
6914 memcpy(survey, ar_survey, sizeof(*survey));
6915 spin_unlock_bh(&ar->data_lock);
6917 survey->channel = &sband->channels[idx];
6919 if (ar->rx_channel == survey->channel)
6920 survey->filled |= SURVEY_INFO_IN_USE;
6923 mutex_unlock(&ar->conf_mutex);
6928 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6929 enum nl80211_band band,
6930 const struct cfg80211_bitrate_mask *mask)
6935 num_rates += hweight32(mask->control[band].legacy);
6937 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6938 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6940 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6941 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6943 return num_rates == 1;
6947 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6948 enum nl80211_band band,
6949 const struct cfg80211_bitrate_mask *mask,
6952 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6953 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6955 u8 vht_nss_mask = 0;
6958 if (mask->control[band].legacy)
6961 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6962 if (mask->control[band].ht_mcs[i] == 0)
6964 else if (mask->control[band].ht_mcs[i] ==
6965 sband->ht_cap.mcs.rx_mask[i])
6966 ht_nss_mask |= BIT(i);
6971 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6972 if (mask->control[band].vht_mcs[i] == 0)
6974 else if (mask->control[band].vht_mcs[i] ==
6975 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6976 vht_nss_mask |= BIT(i);
6981 if (ht_nss_mask != vht_nss_mask)
6984 if (ht_nss_mask == 0)
6987 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6990 *nss = fls(ht_nss_mask);
6996 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6997 enum nl80211_band band,
6998 const struct cfg80211_bitrate_mask *mask,
7007 if (hweight32(mask->control[band].legacy) == 1) {
7008 rate_idx = ffs(mask->control[band].legacy) - 1;
7010 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
7011 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
7013 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
7014 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
7016 if (ath10k_mac_bitrate_is_cck(bitrate))
7017 preamble = WMI_RATE_PREAMBLE_CCK;
7019 preamble = WMI_RATE_PREAMBLE_OFDM;
7022 *rate = preamble << 6 |
7029 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7030 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
7032 *rate = WMI_RATE_PREAMBLE_HT << 6 |
7034 (ffs(mask->control[band].ht_mcs[i]) - 1);
7040 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7041 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
7043 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
7045 (ffs(mask->control[band].vht_mcs[i]) - 1);
7054 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
7055 u8 rate, u8 nss, u8 sgi, u8 ldpc)
7057 struct ath10k *ar = arvif->ar;
7061 lockdep_assert_held(&ar->conf_mutex);
7063 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7064 arvif->vdev_id, rate, nss, sgi);
7066 vdev_param = ar->wmi.vdev_param->fixed_rate;
7067 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
7069 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
7074 vdev_param = ar->wmi.vdev_param->nss;
7075 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
7077 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
7081 vdev_param = ar->wmi.vdev_param->sgi;
7082 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
7084 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
7088 vdev_param = ar->wmi.vdev_param->ldpc;
7089 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
7091 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
7099 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
7100 enum nl80211_band band,
7101 const struct cfg80211_bitrate_mask *mask)
7106 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7107 * to express all VHT MCS rate masks. Effectively only the following
7108 * ranges can be used: none, 0-7, 0-8 and 0-9.
7110 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7111 vht_mcs = mask->control[band].vht_mcs[i];
7120 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7128 static void ath10k_mac_set_bitrate_mask_iter(void *data,
7129 struct ieee80211_sta *sta)
7131 struct ath10k_vif *arvif = data;
7132 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7133 struct ath10k *ar = arvif->ar;
7135 if (arsta->arvif != arvif)
7138 spin_lock_bh(&ar->data_lock);
7139 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7140 spin_unlock_bh(&ar->data_lock);
7142 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7145 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7146 struct ieee80211_vif *vif,
7147 const struct cfg80211_bitrate_mask *mask)
7149 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7150 struct cfg80211_chan_def def;
7151 struct ath10k *ar = arvif->ar;
7152 enum nl80211_band band;
7153 const u8 *ht_mcs_mask;
7154 const u16 *vht_mcs_mask;
7162 if (ath10k_mac_vif_chan(vif, &def))
7165 band = def.chan->band;
7166 ht_mcs_mask = mask->control[band].ht_mcs;
7167 vht_mcs_mask = mask->control[band].vht_mcs;
7168 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7170 sgi = mask->control[band].gi;
7171 if (sgi == NL80211_TXRATE_FORCE_LGI)
7174 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7175 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7178 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7179 arvif->vdev_id, ret);
7182 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7184 rate = WMI_FIXED_RATE_NONE;
7187 rate = WMI_FIXED_RATE_NONE;
7188 nss = min(ar->num_rf_chains,
7189 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7190 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7192 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7195 mutex_lock(&ar->conf_mutex);
7197 arvif->bitrate_mask = *mask;
7198 ieee80211_iterate_stations_atomic(ar->hw,
7199 ath10k_mac_set_bitrate_mask_iter,
7202 mutex_unlock(&ar->conf_mutex);
7205 mutex_lock(&ar->conf_mutex);
7207 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7209 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7210 arvif->vdev_id, ret);
7215 mutex_unlock(&ar->conf_mutex);
7220 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7221 struct ieee80211_vif *vif,
7222 struct ieee80211_sta *sta,
7225 struct ath10k *ar = hw->priv;
7226 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7227 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7228 struct ath10k_peer *peer;
7231 spin_lock_bh(&ar->data_lock);
7233 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7235 spin_unlock_bh(&ar->data_lock);
7236 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7237 sta->addr, arvif->vdev_id);
7241 ath10k_dbg(ar, ATH10K_DBG_MAC,
7242 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7243 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7246 if (changed & IEEE80211_RC_BW_CHANGED) {
7247 bw = WMI_PEER_CHWIDTH_20MHZ;
7249 switch (sta->bandwidth) {
7250 case IEEE80211_STA_RX_BW_20:
7251 bw = WMI_PEER_CHWIDTH_20MHZ;
7253 case IEEE80211_STA_RX_BW_40:
7254 bw = WMI_PEER_CHWIDTH_40MHZ;
7256 case IEEE80211_STA_RX_BW_80:
7257 bw = WMI_PEER_CHWIDTH_80MHZ;
7259 case IEEE80211_STA_RX_BW_160:
7260 bw = WMI_PEER_CHWIDTH_160MHZ;
7263 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7264 sta->bandwidth, sta->addr);
7265 bw = WMI_PEER_CHWIDTH_20MHZ;
7272 if (changed & IEEE80211_RC_NSS_CHANGED)
7273 arsta->nss = sta->rx_nss;
7275 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7276 smps = WMI_PEER_SMPS_PS_NONE;
7278 switch (sta->smps_mode) {
7279 case IEEE80211_SMPS_AUTOMATIC:
7280 case IEEE80211_SMPS_OFF:
7281 smps = WMI_PEER_SMPS_PS_NONE;
7283 case IEEE80211_SMPS_STATIC:
7284 smps = WMI_PEER_SMPS_STATIC;
7286 case IEEE80211_SMPS_DYNAMIC:
7287 smps = WMI_PEER_SMPS_DYNAMIC;
7289 case IEEE80211_SMPS_NUM_MODES:
7290 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7291 sta->smps_mode, sta->addr);
7292 smps = WMI_PEER_SMPS_PS_NONE;
7299 arsta->changed |= changed;
7301 spin_unlock_bh(&ar->data_lock);
7303 ieee80211_queue_work(hw, &arsta->update_wk);
7306 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7307 struct ieee80211_vif *vif, s64 tsf_offset)
7309 struct ath10k *ar = hw->priv;
7310 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7311 u32 offset, vdev_param;
7314 if (tsf_offset < 0) {
7315 vdev_param = ar->wmi.vdev_param->dec_tsf;
7316 offset = -tsf_offset;
7318 vdev_param = ar->wmi.vdev_param->inc_tsf;
7319 offset = tsf_offset;
7322 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7323 vdev_param, offset);
7325 if (ret && ret != -EOPNOTSUPP)
7326 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7327 offset, vdev_param, ret);
7330 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7331 struct ieee80211_vif *vif,
7332 struct ieee80211_ampdu_params *params)
7334 struct ath10k *ar = hw->priv;
7335 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7336 struct ieee80211_sta *sta = params->sta;
7337 enum ieee80211_ampdu_mlme_action action = params->action;
7338 u16 tid = params->tid;
7340 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7341 arvif->vdev_id, sta->addr, tid, action);
7344 case IEEE80211_AMPDU_RX_START:
7345 case IEEE80211_AMPDU_RX_STOP:
7346 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7347 * creation/removal. Do we need to verify this?
7350 case IEEE80211_AMPDU_TX_START:
7351 case IEEE80211_AMPDU_TX_STOP_CONT:
7352 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7353 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7354 case IEEE80211_AMPDU_TX_OPERATIONAL:
7355 /* Firmware offloads Tx aggregation entirely so deny mac80211
7356 * Tx aggregation requests.
7365 ath10k_mac_update_rx_channel(struct ath10k *ar,
7366 struct ieee80211_chanctx_conf *ctx,
7367 struct ieee80211_vif_chanctx_switch *vifs,
7370 struct cfg80211_chan_def *def = NULL;
7372 /* Both locks are required because ar->rx_channel is modified. This
7373 * allows readers to hold either lock.
7375 lockdep_assert_held(&ar->conf_mutex);
7376 lockdep_assert_held(&ar->data_lock);
7378 WARN_ON(ctx && vifs);
7379 WARN_ON(vifs && !n_vifs);
7381 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7382 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7383 * ppdu on Rx may reduce performance on low-end systems. It should be
7384 * possible to make tables/hashmaps to speed the lookup up (be vary of
7385 * cpu data cache lines though regarding sizes) but to keep the initial
7386 * implementation simple and less intrusive fallback to the slow lookup
7387 * only for multi-channel cases. Single-channel cases will remain to
7388 * use the old channel derival and thus performance should not be
7392 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7393 ieee80211_iter_chan_contexts_atomic(ar->hw,
7394 ath10k_mac_get_any_chandef_iter,
7398 def = &vifs[0].new_ctx->def;
7400 ar->rx_channel = def->chan;
7401 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7402 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7403 /* During driver restart due to firmware assert, since mac80211
7404 * already has valid channel context for given radio, channel
7405 * context iteration return num_chanctx > 0. So fix rx_channel
7406 * when restart is in progress.
7408 ar->rx_channel = ctx->def.chan;
7410 ar->rx_channel = NULL;
7416 ath10k_mac_update_vif_chan(struct ath10k *ar,
7417 struct ieee80211_vif_chanctx_switch *vifs,
7420 struct ath10k_vif *arvif;
7424 lockdep_assert_held(&ar->conf_mutex);
7426 /* First stop monitor interface. Some FW versions crash if there's a
7427 * lone monitor interface.
7429 if (ar->monitor_started)
7430 ath10k_monitor_stop(ar);
7432 for (i = 0; i < n_vifs; i++) {
7433 arvif = (void *)vifs[i].vif->drv_priv;
7435 ath10k_dbg(ar, ATH10K_DBG_MAC,
7436 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7438 vifs[i].old_ctx->def.chan->center_freq,
7439 vifs[i].new_ctx->def.chan->center_freq,
7440 vifs[i].old_ctx->def.width,
7441 vifs[i].new_ctx->def.width);
7443 if (WARN_ON(!arvif->is_started))
7446 if (WARN_ON(!arvif->is_up))
7449 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7451 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7452 arvif->vdev_id, ret);
7457 /* All relevant vdevs are downed and associated channel resources
7458 * should be available for the channel switch now.
7461 spin_lock_bh(&ar->data_lock);
7462 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7463 spin_unlock_bh(&ar->data_lock);
7465 for (i = 0; i < n_vifs; i++) {
7466 arvif = (void *)vifs[i].vif->drv_priv;
7468 if (WARN_ON(!arvif->is_started))
7471 if (WARN_ON(!arvif->is_up))
7474 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7476 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7479 ret = ath10k_mac_setup_prb_tmpl(arvif);
7481 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7484 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7486 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7487 arvif->vdev_id, ret);
7491 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7494 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7495 arvif->vdev_id, ret);
7500 ath10k_monitor_recalc(ar);
7504 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7505 struct ieee80211_chanctx_conf *ctx)
7507 struct ath10k *ar = hw->priv;
7509 ath10k_dbg(ar, ATH10K_DBG_MAC,
7510 "mac chanctx add freq %hu width %d ptr %pK\n",
7511 ctx->def.chan->center_freq, ctx->def.width, ctx);
7513 mutex_lock(&ar->conf_mutex);
7515 spin_lock_bh(&ar->data_lock);
7516 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7517 spin_unlock_bh(&ar->data_lock);
7519 ath10k_recalc_radar_detection(ar);
7520 ath10k_monitor_recalc(ar);
7522 mutex_unlock(&ar->conf_mutex);
7528 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7529 struct ieee80211_chanctx_conf *ctx)
7531 struct ath10k *ar = hw->priv;
7533 ath10k_dbg(ar, ATH10K_DBG_MAC,
7534 "mac chanctx remove freq %hu width %d ptr %pK\n",
7535 ctx->def.chan->center_freq, ctx->def.width, ctx);
7537 mutex_lock(&ar->conf_mutex);
7539 spin_lock_bh(&ar->data_lock);
7540 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7541 spin_unlock_bh(&ar->data_lock);
7543 ath10k_recalc_radar_detection(ar);
7544 ath10k_monitor_recalc(ar);
7546 mutex_unlock(&ar->conf_mutex);
7549 struct ath10k_mac_change_chanctx_arg {
7550 struct ieee80211_chanctx_conf *ctx;
7551 struct ieee80211_vif_chanctx_switch *vifs;
7557 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7558 struct ieee80211_vif *vif)
7560 struct ath10k_mac_change_chanctx_arg *arg = data;
7562 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7569 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7570 struct ieee80211_vif *vif)
7572 struct ath10k_mac_change_chanctx_arg *arg = data;
7573 struct ieee80211_chanctx_conf *ctx;
7575 ctx = rcu_access_pointer(vif->chanctx_conf);
7576 if (ctx != arg->ctx)
7579 if (WARN_ON(arg->next_vif == arg->n_vifs))
7582 arg->vifs[arg->next_vif].vif = vif;
7583 arg->vifs[arg->next_vif].old_ctx = ctx;
7584 arg->vifs[arg->next_vif].new_ctx = ctx;
7589 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7590 struct ieee80211_chanctx_conf *ctx,
7593 struct ath10k *ar = hw->priv;
7594 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7596 mutex_lock(&ar->conf_mutex);
7598 ath10k_dbg(ar, ATH10K_DBG_MAC,
7599 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7600 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7602 /* This shouldn't really happen because channel switching should use
7603 * switch_vif_chanctx().
7605 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7608 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7609 ieee80211_iterate_active_interfaces_atomic(
7611 IEEE80211_IFACE_ITER_NORMAL,
7612 ath10k_mac_change_chanctx_cnt_iter,
7614 if (arg.n_vifs == 0)
7617 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7622 ieee80211_iterate_active_interfaces_atomic(
7624 IEEE80211_IFACE_ITER_NORMAL,
7625 ath10k_mac_change_chanctx_fill_iter,
7627 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7632 ath10k_recalc_radar_detection(ar);
7634 /* FIXME: How to configure Rx chains properly? */
7636 /* No other actions are actually necessary. Firmware maintains channel
7637 * definitions per vdev internally and there's no host-side channel
7638 * context abstraction to configure, e.g. channel width.
7642 mutex_unlock(&ar->conf_mutex);
7646 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7647 struct ieee80211_vif *vif,
7648 struct ieee80211_chanctx_conf *ctx)
7650 struct ath10k *ar = hw->priv;
7651 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7654 mutex_lock(&ar->conf_mutex);
7656 ath10k_dbg(ar, ATH10K_DBG_MAC,
7657 "mac chanctx assign ptr %pK vdev_id %i\n",
7658 ctx, arvif->vdev_id);
7660 if (WARN_ON(arvif->is_started)) {
7661 mutex_unlock(&ar->conf_mutex);
7665 ret = ath10k_vdev_start(arvif, &ctx->def);
7667 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7668 arvif->vdev_id, vif->addr,
7669 ctx->def.chan->center_freq, ret);
7673 arvif->is_started = true;
7675 ret = ath10k_mac_vif_setup_ps(arvif);
7677 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7678 arvif->vdev_id, ret);
7682 if (vif->type == NL80211_IFTYPE_MONITOR) {
7683 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7685 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7686 arvif->vdev_id, ret);
7690 arvif->is_up = true;
7693 if (ath10k_mac_can_set_cts_prot(arvif)) {
7694 ret = ath10k_mac_set_cts_prot(arvif);
7696 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7697 arvif->vdev_id, ret);
7700 if (ath10k_peer_stats_enabled(ar)) {
7701 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
7702 ret = ath10k_wmi_pdev_pktlog_enable(ar,
7705 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
7710 mutex_unlock(&ar->conf_mutex);
7714 ath10k_vdev_stop(arvif);
7715 arvif->is_started = false;
7716 ath10k_mac_vif_setup_ps(arvif);
7719 mutex_unlock(&ar->conf_mutex);
7724 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7725 struct ieee80211_vif *vif,
7726 struct ieee80211_chanctx_conf *ctx)
7728 struct ath10k *ar = hw->priv;
7729 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7732 mutex_lock(&ar->conf_mutex);
7734 ath10k_dbg(ar, ATH10K_DBG_MAC,
7735 "mac chanctx unassign ptr %pK vdev_id %i\n",
7736 ctx, arvif->vdev_id);
7738 WARN_ON(!arvif->is_started);
7740 if (vif->type == NL80211_IFTYPE_MONITOR) {
7741 WARN_ON(!arvif->is_up);
7743 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7745 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7746 arvif->vdev_id, ret);
7748 arvif->is_up = false;
7751 ret = ath10k_vdev_stop(arvif);
7753 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7754 arvif->vdev_id, ret);
7756 arvif->is_started = false;
7758 mutex_unlock(&ar->conf_mutex);
7762 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7763 struct ieee80211_vif_chanctx_switch *vifs,
7765 enum ieee80211_chanctx_switch_mode mode)
7767 struct ath10k *ar = hw->priv;
7769 mutex_lock(&ar->conf_mutex);
7771 ath10k_dbg(ar, ATH10K_DBG_MAC,
7772 "mac chanctx switch n_vifs %d mode %d\n",
7774 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7776 mutex_unlock(&ar->conf_mutex);
7780 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7781 struct ieee80211_vif *vif,
7782 struct ieee80211_sta *sta)
7785 struct ath10k_peer *peer;
7789 list_for_each_entry(peer, &ar->peers, list)
7790 if (peer->sta == sta)
7791 peer->removed = true;
7794 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
7795 struct ieee80211_vif *vif,
7796 struct ieee80211_sta *sta,
7797 struct station_info *sinfo)
7799 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7800 struct ath10k *ar = arsta->arvif->ar;
7802 if (!ath10k_peer_stats_enabled(ar))
7805 sinfo->rx_duration = arsta->rx_duration;
7806 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
7808 if (!arsta->txrate.legacy && !arsta->txrate.nss)
7811 if (arsta->txrate.legacy) {
7812 sinfo->txrate.legacy = arsta->txrate.legacy;
7814 sinfo->txrate.mcs = arsta->txrate.mcs;
7815 sinfo->txrate.nss = arsta->txrate.nss;
7816 sinfo->txrate.bw = arsta->txrate.bw;
7818 sinfo->txrate.flags = arsta->txrate.flags;
7819 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
7822 static const struct ieee80211_ops ath10k_ops = {
7823 .tx = ath10k_mac_op_tx,
7824 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7825 .start = ath10k_start,
7826 .stop = ath10k_stop,
7827 .config = ath10k_config,
7828 .add_interface = ath10k_add_interface,
7829 .remove_interface = ath10k_remove_interface,
7830 .configure_filter = ath10k_configure_filter,
7831 .bss_info_changed = ath10k_bss_info_changed,
7832 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7833 .hw_scan = ath10k_hw_scan,
7834 .cancel_hw_scan = ath10k_cancel_hw_scan,
7835 .set_key = ath10k_set_key,
7836 .set_default_unicast_key = ath10k_set_default_unicast_key,
7837 .sta_state = ath10k_sta_state,
7838 .conf_tx = ath10k_conf_tx,
7839 .remain_on_channel = ath10k_remain_on_channel,
7840 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7841 .set_rts_threshold = ath10k_set_rts_threshold,
7842 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7843 .flush = ath10k_flush,
7844 .tx_last_beacon = ath10k_tx_last_beacon,
7845 .set_antenna = ath10k_set_antenna,
7846 .get_antenna = ath10k_get_antenna,
7847 .reconfig_complete = ath10k_reconfig_complete,
7848 .get_survey = ath10k_get_survey,
7849 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7850 .sta_rc_update = ath10k_sta_rc_update,
7851 .offset_tsf = ath10k_offset_tsf,
7852 .ampdu_action = ath10k_ampdu_action,
7853 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7854 .get_et_stats = ath10k_debug_get_et_stats,
7855 .get_et_strings = ath10k_debug_get_et_strings,
7856 .add_chanctx = ath10k_mac_op_add_chanctx,
7857 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7858 .change_chanctx = ath10k_mac_op_change_chanctx,
7859 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7860 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7861 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7862 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7863 .sta_statistics = ath10k_sta_statistics,
7865 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7868 .suspend = ath10k_wow_op_suspend,
7869 .resume = ath10k_wow_op_resume,
7870 .set_wakeup = ath10k_wow_op_set_wakeup,
7872 #ifdef CONFIG_MAC80211_DEBUGFS
7873 .sta_add_debugfs = ath10k_sta_add_debugfs,
7877 #define CHAN2G(_channel, _freq, _flags) { \
7878 .band = NL80211_BAND_2GHZ, \
7879 .hw_value = (_channel), \
7880 .center_freq = (_freq), \
7881 .flags = (_flags), \
7882 .max_antenna_gain = 0, \
7886 #define CHAN5G(_channel, _freq, _flags) { \
7887 .band = NL80211_BAND_5GHZ, \
7888 .hw_value = (_channel), \
7889 .center_freq = (_freq), \
7890 .flags = (_flags), \
7891 .max_antenna_gain = 0, \
7895 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7905 CHAN2G(10, 2457, 0),
7906 CHAN2G(11, 2462, 0),
7907 CHAN2G(12, 2467, 0),
7908 CHAN2G(13, 2472, 0),
7909 CHAN2G(14, 2484, 0),
7912 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7913 CHAN5G(36, 5180, 0),
7914 CHAN5G(40, 5200, 0),
7915 CHAN5G(44, 5220, 0),
7916 CHAN5G(48, 5240, 0),
7917 CHAN5G(52, 5260, 0),
7918 CHAN5G(56, 5280, 0),
7919 CHAN5G(60, 5300, 0),
7920 CHAN5G(64, 5320, 0),
7921 CHAN5G(100, 5500, 0),
7922 CHAN5G(104, 5520, 0),
7923 CHAN5G(108, 5540, 0),
7924 CHAN5G(112, 5560, 0),
7925 CHAN5G(116, 5580, 0),
7926 CHAN5G(120, 5600, 0),
7927 CHAN5G(124, 5620, 0),
7928 CHAN5G(128, 5640, 0),
7929 CHAN5G(132, 5660, 0),
7930 CHAN5G(136, 5680, 0),
7931 CHAN5G(140, 5700, 0),
7932 CHAN5G(144, 5720, 0),
7933 CHAN5G(149, 5745, 0),
7934 CHAN5G(153, 5765, 0),
7935 CHAN5G(157, 5785, 0),
7936 CHAN5G(161, 5805, 0),
7937 CHAN5G(165, 5825, 0),
7938 CHAN5G(169, 5845, 0),
7939 CHAN5G(173, 5865, 0),
7940 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
7941 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
7944 struct ath10k *ath10k_mac_create(size_t priv_size)
7946 struct ieee80211_hw *hw;
7947 struct ieee80211_ops *ops;
7950 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7954 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7967 void ath10k_mac_destroy(struct ath10k *ar)
7969 struct ieee80211_ops *ops = ar->ops;
7971 ieee80211_free_hw(ar->hw);
7975 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7978 .types = BIT(NL80211_IFTYPE_STATION)
7979 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7983 .types = BIT(NL80211_IFTYPE_P2P_GO)
7987 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7991 .types = BIT(NL80211_IFTYPE_AP)
7992 #ifdef CONFIG_MAC80211_MESH
7993 | BIT(NL80211_IFTYPE_MESH_POINT)
7998 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
8001 .types = BIT(NL80211_IFTYPE_AP)
8002 #ifdef CONFIG_MAC80211_MESH
8003 | BIT(NL80211_IFTYPE_MESH_POINT)
8008 .types = BIT(NL80211_IFTYPE_STATION)
8012 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
8014 .limits = ath10k_if_limits,
8015 .n_limits = ARRAY_SIZE(ath10k_if_limits),
8016 .max_interfaces = 8,
8017 .num_different_channels = 1,
8018 .beacon_int_infra_match = true,
8022 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
8024 .limits = ath10k_10x_if_limits,
8025 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
8026 .max_interfaces = 8,
8027 .num_different_channels = 1,
8028 .beacon_int_infra_match = true,
8029 .beacon_int_min_gcd = 1,
8030 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8031 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8032 BIT(NL80211_CHAN_WIDTH_20) |
8033 BIT(NL80211_CHAN_WIDTH_40) |
8034 BIT(NL80211_CHAN_WIDTH_80),
8039 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
8042 .types = BIT(NL80211_IFTYPE_STATION),
8046 .types = BIT(NL80211_IFTYPE_AP) |
8047 #ifdef CONFIG_MAC80211_MESH
8048 BIT(NL80211_IFTYPE_MESH_POINT) |
8050 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8051 BIT(NL80211_IFTYPE_P2P_GO),
8055 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8059 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
8062 .types = BIT(NL80211_IFTYPE_STATION),
8066 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
8070 .types = BIT(NL80211_IFTYPE_AP) |
8071 #ifdef CONFIG_MAC80211_MESH
8072 BIT(NL80211_IFTYPE_MESH_POINT) |
8074 BIT(NL80211_IFTYPE_P2P_GO),
8078 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8082 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
8085 .types = BIT(NL80211_IFTYPE_STATION),
8089 .types = BIT(NL80211_IFTYPE_ADHOC),
8093 /* FIXME: This is not thouroughly tested. These combinations may over- or
8094 * underestimate hw/fw capabilities.
8096 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
8098 .limits = ath10k_tlv_if_limit,
8099 .num_different_channels = 1,
8100 .max_interfaces = 4,
8101 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8104 .limits = ath10k_tlv_if_limit_ibss,
8105 .num_different_channels = 1,
8106 .max_interfaces = 2,
8107 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8111 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
8113 .limits = ath10k_tlv_if_limit,
8114 .num_different_channels = 1,
8115 .max_interfaces = 4,
8116 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8119 .limits = ath10k_tlv_qcs_if_limit,
8120 .num_different_channels = 2,
8121 .max_interfaces = 4,
8122 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
8125 .limits = ath10k_tlv_if_limit_ibss,
8126 .num_different_channels = 1,
8127 .max_interfaces = 2,
8128 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8132 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8135 .types = BIT(NL80211_IFTYPE_STATION),
8139 .types = BIT(NL80211_IFTYPE_AP)
8140 #ifdef CONFIG_MAC80211_MESH
8141 | BIT(NL80211_IFTYPE_MESH_POINT)
8146 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8148 .limits = ath10k_10_4_if_limits,
8149 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8150 .max_interfaces = 16,
8151 .num_different_channels = 1,
8152 .beacon_int_infra_match = true,
8153 .beacon_int_min_gcd = 1,
8154 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8155 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8156 BIT(NL80211_CHAN_WIDTH_20) |
8157 BIT(NL80211_CHAN_WIDTH_40) |
8158 BIT(NL80211_CHAN_WIDTH_80),
8163 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8164 struct ieee80211_vif *vif)
8166 struct ath10k_vif_iter *arvif_iter = data;
8167 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8169 if (arvif->vdev_id == arvif_iter->vdev_id)
8170 arvif_iter->arvif = arvif;
8173 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8175 struct ath10k_vif_iter arvif_iter;
8178 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8179 arvif_iter.vdev_id = vdev_id;
8181 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8182 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8184 ath10k_get_arvif_iter,
8186 if (!arvif_iter.arvif) {
8187 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8191 return arvif_iter.arvif;
8194 #define WRD_METHOD "WRDD"
8195 #define WRDD_WIFI (0x07)
8197 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8199 union acpi_object *mcc_pkg;
8200 union acpi_object *domain_type;
8201 union acpi_object *mcc_value;
8204 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8205 wrdd->package.count < 2 ||
8206 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8207 wrdd->package.elements[0].integer.value != 0) {
8208 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8212 for (i = 1; i < wrdd->package.count; ++i) {
8213 mcc_pkg = &wrdd->package.elements[i];
8215 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8217 if (mcc_pkg->package.count < 2)
8219 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8220 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8223 domain_type = &mcc_pkg->package.elements[0];
8224 if (domain_type->integer.value != WRDD_WIFI)
8227 mcc_value = &mcc_pkg->package.elements[1];
8228 return mcc_value->integer.value;
8233 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8235 struct pci_dev __maybe_unused *pdev = to_pci_dev(ar->dev);
8236 acpi_handle root_handle;
8238 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8243 root_handle = ACPI_HANDLE(&pdev->dev);
8247 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8248 if (ACPI_FAILURE(status)) {
8249 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8250 "failed to get wrd method %d\n", status);
8254 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8255 if (ACPI_FAILURE(status)) {
8256 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8257 "failed to call wrdc %d\n", status);
8261 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8262 kfree(wrdd.pointer);
8266 alpha2[0] = (alpha2_code >> 8) & 0xff;
8267 alpha2[1] = (alpha2_code >> 0) & 0xff;
8270 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8271 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8273 *rd = ath_regd_find_country_by_name(alpha2);
8277 *rd |= COUNTRY_ERD_FLAG;
8281 static int ath10k_mac_init_rd(struct ath10k *ar)
8286 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8288 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8289 "fallback to eeprom programmed regulatory settings\n");
8290 rd = ar->hw_eeprom_rd;
8293 ar->ath_common.regulatory.current_rd = rd;
8297 int ath10k_mac_register(struct ath10k *ar)
8299 static const u32 cipher_suites[] = {
8300 WLAN_CIPHER_SUITE_WEP40,
8301 WLAN_CIPHER_SUITE_WEP104,
8302 WLAN_CIPHER_SUITE_TKIP,
8303 WLAN_CIPHER_SUITE_CCMP,
8305 /* Do not add hardware supported ciphers before this line.
8306 * Allow software encryption for all chips. Don't forget to
8307 * update n_cipher_suites below.
8309 WLAN_CIPHER_SUITE_AES_CMAC,
8310 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8311 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8312 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8314 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8315 * and CCMP-256 in hardware.
8317 WLAN_CIPHER_SUITE_GCMP,
8318 WLAN_CIPHER_SUITE_GCMP_256,
8319 WLAN_CIPHER_SUITE_CCMP_256,
8321 struct ieee80211_supported_band *band;
8325 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8327 SET_IEEE80211_DEV(ar->hw, ar->dev);
8329 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8330 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8333 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8334 channels = kmemdup(ath10k_2ghz_channels,
8335 sizeof(ath10k_2ghz_channels),
8342 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8343 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8344 band->channels = channels;
8346 if (ar->hw_params.cck_rate_map_rev2) {
8347 band->n_bitrates = ath10k_g_rates_rev2_size;
8348 band->bitrates = ath10k_g_rates_rev2;
8350 band->n_bitrates = ath10k_g_rates_size;
8351 band->bitrates = ath10k_g_rates;
8354 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8357 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8358 channels = kmemdup(ath10k_5ghz_channels,
8359 sizeof(ath10k_5ghz_channels),
8366 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8367 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8368 band->channels = channels;
8369 band->n_bitrates = ath10k_a_rates_size;
8370 band->bitrates = ath10k_a_rates;
8371 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8374 wiphy_read_of_freq_limits(ar->hw->wiphy);
8375 ath10k_mac_setup_ht_vht_cap(ar);
8377 ar->hw->wiphy->interface_modes =
8378 BIT(NL80211_IFTYPE_STATION) |
8379 BIT(NL80211_IFTYPE_AP) |
8380 BIT(NL80211_IFTYPE_MESH_POINT);
8382 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8383 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8385 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8386 ar->hw->wiphy->interface_modes |=
8387 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8388 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8389 BIT(NL80211_IFTYPE_P2P_GO);
8391 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8393 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
8394 ar->running_fw->fw_file.fw_features)) {
8395 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8396 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8399 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8400 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8401 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8402 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8403 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8404 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8405 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8406 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8407 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8408 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8409 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8410 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8411 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8413 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8414 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8416 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8417 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8419 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8420 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8422 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8423 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8424 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8427 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8428 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8430 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8431 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8432 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8434 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8436 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8437 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8439 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8440 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8441 * correct Probe Responses. This is more of a hack advert..
8443 ar->hw->wiphy->probe_resp_offload |=
8444 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8445 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8446 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8449 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8450 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8451 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8452 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
8453 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8456 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8457 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
8459 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8460 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8461 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8463 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8464 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8465 NL80211_FEATURE_AP_SCAN;
8467 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8469 ret = ath10k_wow_init(ar);
8471 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8475 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8476 wiphy_ext_feature_set(ar->hw->wiphy,
8477 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
8480 * on LL hardware queues are managed entirely by the FW
8481 * so we only advertise to mac we can do the queues thing
8483 ar->hw->queues = IEEE80211_MAX_QUEUES;
8485 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8486 * something that vdev_ids can't reach so that we don't stop the queue
8489 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8491 switch (ar->running_fw->fw_file.wmi_op_version) {
8492 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8493 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8494 ar->hw->wiphy->n_iface_combinations =
8495 ARRAY_SIZE(ath10k_if_comb);
8496 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8498 case ATH10K_FW_WMI_OP_VERSION_TLV:
8499 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8500 ar->hw->wiphy->iface_combinations =
8501 ath10k_tlv_qcs_if_comb;
8502 ar->hw->wiphy->n_iface_combinations =
8503 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8505 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8506 ar->hw->wiphy->n_iface_combinations =
8507 ARRAY_SIZE(ath10k_tlv_if_comb);
8509 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8511 case ATH10K_FW_WMI_OP_VERSION_10_1:
8512 case ATH10K_FW_WMI_OP_VERSION_10_2:
8513 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8514 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8515 ar->hw->wiphy->n_iface_combinations =
8516 ARRAY_SIZE(ath10k_10x_if_comb);
8518 case ATH10K_FW_WMI_OP_VERSION_10_4:
8519 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8520 ar->hw->wiphy->n_iface_combinations =
8521 ARRAY_SIZE(ath10k_10_4_if_comb);
8523 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8524 case ATH10K_FW_WMI_OP_VERSION_MAX:
8530 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8531 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8533 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8534 /* Init ath dfs pattern detector */
8535 ar->ath_common.debug_mask = ATH_DBG_DFS;
8536 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8539 if (!ar->dfs_detector)
8540 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8543 ret = ath10k_mac_init_rd(ar);
8545 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8546 goto err_dfs_detector_exit;
8549 /* Disable set_coverage_class for chipsets that do not support it. */
8550 if (!ar->hw_params.hw_ops->set_coverage_class)
8551 ar->ops->set_coverage_class = NULL;
8553 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8554 ath10k_reg_notifier);
8556 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8557 goto err_dfs_detector_exit;
8560 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
8561 ar->hw->wiphy->features |=
8562 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8565 ar->hw->wiphy->cipher_suites = cipher_suites;
8567 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
8568 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
8569 * from chip specific hw_param table.
8571 if (!ar->hw_params.n_cipher_suites ||
8572 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
8573 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
8574 ar->hw_params.n_cipher_suites);
8575 ar->hw_params.n_cipher_suites = 8;
8577 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
8579 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8581 ret = ieee80211_register_hw(ar->hw);
8583 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8584 goto err_dfs_detector_exit;
8587 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8588 ret = regulatory_hint(ar->hw->wiphy,
8589 ar->ath_common.regulatory.alpha2);
8591 goto err_unregister;
8597 ieee80211_unregister_hw(ar->hw);
8599 err_dfs_detector_exit:
8600 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8601 ar->dfs_detector->exit(ar->dfs_detector);
8604 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8605 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8607 SET_IEEE80211_DEV(ar->hw, NULL);
8611 void ath10k_mac_unregister(struct ath10k *ar)
8613 ieee80211_unregister_hw(ar->hw);
8615 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8616 ar->dfs_detector->exit(ar->dfs_detector);
8618 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8619 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8621 SET_IEEE80211_DEV(ar->hw, NULL);