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_rate_hw_value(int bitrate)
163 u8 hw_value_prefix = 0;
165 if (ath10k_mac_bitrate_is_cck(bitrate))
166 hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
168 for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
169 if (ath10k_rates[i].bitrate == bitrate)
170 return hw_value_prefix | ath10k_rates[i].hw_value;
176 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
178 switch ((mcs_map >> (2 * nss)) & 0x3) {
179 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
180 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
181 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
187 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
191 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
192 if (ht_mcs_mask[nss])
199 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
203 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
204 if (vht_mcs_mask[nss])
210 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
212 enum wmi_host_platform_type platform_type;
215 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
216 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
218 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
220 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
222 if (ret && ret != -EOPNOTSUPP) {
223 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
234 static int ath10k_send_key(struct ath10k_vif *arvif,
235 struct ieee80211_key_conf *key,
236 enum set_key_cmd cmd,
237 const u8 *macaddr, u32 flags)
239 struct ath10k *ar = arvif->ar;
240 struct wmi_vdev_install_key_arg arg = {
241 .vdev_id = arvif->vdev_id,
242 .key_idx = key->keyidx,
243 .key_len = key->keylen,
244 .key_data = key->key,
249 lockdep_assert_held(&arvif->ar->conf_mutex);
251 switch (key->cipher) {
252 case WLAN_CIPHER_SUITE_CCMP:
253 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
254 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
256 case WLAN_CIPHER_SUITE_TKIP:
257 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_TKIP];
258 arg.key_txmic_len = 8;
259 arg.key_rxmic_len = 8;
261 case WLAN_CIPHER_SUITE_WEP40:
262 case WLAN_CIPHER_SUITE_WEP104:
263 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_WEP];
265 case WLAN_CIPHER_SUITE_CCMP_256:
266 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
268 case WLAN_CIPHER_SUITE_GCMP:
269 case WLAN_CIPHER_SUITE_GCMP_256:
270 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_GCM];
272 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
273 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
274 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
275 case WLAN_CIPHER_SUITE_AES_CMAC:
279 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
283 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
284 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
286 if (cmd == DISABLE_KEY) {
287 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_NONE];
291 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
294 static int ath10k_install_key(struct ath10k_vif *arvif,
295 struct ieee80211_key_conf *key,
296 enum set_key_cmd cmd,
297 const u8 *macaddr, u32 flags)
299 struct ath10k *ar = arvif->ar;
301 unsigned long time_left;
303 lockdep_assert_held(&ar->conf_mutex);
305 reinit_completion(&ar->install_key_done);
307 if (arvif->nohwcrypt)
310 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
314 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
321 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
324 struct ath10k *ar = arvif->ar;
325 struct ath10k_peer *peer;
330 lockdep_assert_held(&ar->conf_mutex);
332 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
333 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
334 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
337 spin_lock_bh(&ar->data_lock);
338 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
339 spin_unlock_bh(&ar->data_lock);
344 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
345 if (arvif->wep_keys[i] == NULL)
348 switch (arvif->vif->type) {
349 case NL80211_IFTYPE_AP:
350 flags = WMI_KEY_PAIRWISE;
352 if (arvif->def_wep_key_idx == i)
353 flags |= WMI_KEY_TX_USAGE;
355 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
356 SET_KEY, addr, flags);
360 case NL80211_IFTYPE_ADHOC:
361 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
367 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
368 SET_KEY, addr, WMI_KEY_GROUP);
377 spin_lock_bh(&ar->data_lock);
378 peer->keys[i] = arvif->wep_keys[i];
379 spin_unlock_bh(&ar->data_lock);
382 /* In some cases (notably with static WEP IBSS with multiple keys)
383 * multicast Tx becomes broken. Both pairwise and groupwise keys are
384 * installed already. Using WMI_KEY_TX_USAGE in different combinations
385 * didn't seem help. Using def_keyid vdev parameter seems to be
386 * effective so use that.
388 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
390 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
393 if (arvif->def_wep_key_idx == -1)
396 ret = ath10k_wmi_vdev_set_param(arvif->ar,
398 arvif->ar->wmi.vdev_param->def_keyid,
399 arvif->def_wep_key_idx);
401 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
402 arvif->vdev_id, ret);
409 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
412 struct ath10k *ar = arvif->ar;
413 struct ath10k_peer *peer;
419 lockdep_assert_held(&ar->conf_mutex);
421 spin_lock_bh(&ar->data_lock);
422 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
423 spin_unlock_bh(&ar->data_lock);
428 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
429 if (peer->keys[i] == NULL)
432 /* key flags are not required to delete the key */
433 ret = ath10k_install_key(arvif, peer->keys[i],
434 DISABLE_KEY, addr, flags);
435 if (ret < 0 && first_errno == 0)
439 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
442 spin_lock_bh(&ar->data_lock);
443 peer->keys[i] = NULL;
444 spin_unlock_bh(&ar->data_lock);
450 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
453 struct ath10k_peer *peer;
456 lockdep_assert_held(&ar->data_lock);
458 /* We don't know which vdev this peer belongs to,
459 * since WMI doesn't give us that information.
461 * FIXME: multi-bss needs to be handled.
463 peer = ath10k_peer_find(ar, 0, addr);
467 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
468 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
475 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
476 struct ieee80211_key_conf *key)
478 struct ath10k *ar = arvif->ar;
479 struct ath10k_peer *peer;
486 lockdep_assert_held(&ar->conf_mutex);
489 /* since ath10k_install_key we can't hold data_lock all the
490 * time, so we try to remove the keys incrementally
492 spin_lock_bh(&ar->data_lock);
494 list_for_each_entry(peer, &ar->peers, list) {
495 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
496 if (peer->keys[i] == key) {
497 ether_addr_copy(addr, peer->addr);
498 peer->keys[i] = NULL;
503 if (i < ARRAY_SIZE(peer->keys))
506 spin_unlock_bh(&ar->data_lock);
508 if (i == ARRAY_SIZE(peer->keys))
510 /* key flags are not required to delete the key */
511 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
512 if (ret < 0 && first_errno == 0)
516 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
523 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
524 struct ieee80211_key_conf *key)
526 struct ath10k *ar = arvif->ar;
527 struct ath10k_peer *peer;
530 lockdep_assert_held(&ar->conf_mutex);
532 list_for_each_entry(peer, &ar->peers, list) {
533 if (ether_addr_equal(peer->addr, arvif->vif->addr))
536 if (ether_addr_equal(peer->addr, arvif->bssid))
539 if (peer->keys[key->keyidx] == key)
542 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
543 arvif->vdev_id, key->keyidx);
545 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
547 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
548 arvif->vdev_id, peer->addr, ret);
556 /*********************/
557 /* General utilities */
558 /*********************/
560 static inline enum wmi_phy_mode
561 chan_to_phymode(const struct cfg80211_chan_def *chandef)
563 enum wmi_phy_mode phymode = MODE_UNKNOWN;
565 switch (chandef->chan->band) {
566 case NL80211_BAND_2GHZ:
567 switch (chandef->width) {
568 case NL80211_CHAN_WIDTH_20_NOHT:
569 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
574 case NL80211_CHAN_WIDTH_20:
575 phymode = MODE_11NG_HT20;
577 case NL80211_CHAN_WIDTH_40:
578 phymode = MODE_11NG_HT40;
580 case NL80211_CHAN_WIDTH_5:
581 case NL80211_CHAN_WIDTH_10:
582 case NL80211_CHAN_WIDTH_80:
583 case NL80211_CHAN_WIDTH_80P80:
584 case NL80211_CHAN_WIDTH_160:
585 phymode = MODE_UNKNOWN;
589 case NL80211_BAND_5GHZ:
590 switch (chandef->width) {
591 case NL80211_CHAN_WIDTH_20_NOHT:
594 case NL80211_CHAN_WIDTH_20:
595 phymode = MODE_11NA_HT20;
597 case NL80211_CHAN_WIDTH_40:
598 phymode = MODE_11NA_HT40;
600 case NL80211_CHAN_WIDTH_80:
601 phymode = MODE_11AC_VHT80;
603 case NL80211_CHAN_WIDTH_160:
604 phymode = MODE_11AC_VHT160;
606 case NL80211_CHAN_WIDTH_80P80:
607 phymode = MODE_11AC_VHT80_80;
609 case NL80211_CHAN_WIDTH_5:
610 case NL80211_CHAN_WIDTH_10:
611 phymode = MODE_UNKNOWN;
619 WARN_ON(phymode == MODE_UNKNOWN);
623 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
626 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
627 * 0 for no restriction
636 switch (mpdudensity) {
642 /* Our lower layer calculations limit our precision to
659 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
660 struct cfg80211_chan_def *def)
662 struct ieee80211_chanctx_conf *conf;
665 conf = rcu_dereference(vif->chanctx_conf);
677 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
678 struct ieee80211_chanctx_conf *conf,
686 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
690 ieee80211_iter_chan_contexts_atomic(ar->hw,
691 ath10k_mac_num_chanctxs_iter,
698 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
699 struct ieee80211_chanctx_conf *conf,
702 struct cfg80211_chan_def **def = data;
707 static int ath10k_peer_create(struct ath10k *ar,
708 struct ieee80211_vif *vif,
709 struct ieee80211_sta *sta,
712 enum wmi_peer_type peer_type)
714 struct ath10k_vif *arvif;
715 struct ath10k_peer *peer;
719 lockdep_assert_held(&ar->conf_mutex);
721 num_peers = ar->num_peers;
723 /* Each vdev consumes a peer entry as well */
724 list_for_each_entry(arvif, &ar->arvifs, list)
727 if (num_peers >= ar->max_num_peers)
730 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
732 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
737 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
739 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
744 spin_lock_bh(&ar->data_lock);
746 peer = ath10k_peer_find(ar, vdev_id, addr);
748 spin_unlock_bh(&ar->data_lock);
749 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
751 ath10k_wmi_peer_delete(ar, vdev_id, addr);
758 spin_unlock_bh(&ar->data_lock);
765 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
767 struct ath10k *ar = arvif->ar;
771 param = ar->wmi.pdev_param->sta_kickout_th;
772 ret = ath10k_wmi_pdev_set_param(ar, param,
773 ATH10K_KICKOUT_THRESHOLD);
775 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
776 arvif->vdev_id, ret);
780 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
781 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
782 ATH10K_KEEPALIVE_MIN_IDLE);
784 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
785 arvif->vdev_id, ret);
789 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
790 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
791 ATH10K_KEEPALIVE_MAX_IDLE);
793 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
794 arvif->vdev_id, ret);
798 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
799 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
800 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
802 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
803 arvif->vdev_id, ret);
810 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
812 struct ath10k *ar = arvif->ar;
815 vdev_param = ar->wmi.vdev_param->rts_threshold;
816 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
819 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
823 lockdep_assert_held(&ar->conf_mutex);
825 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
829 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
838 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
840 struct ath10k_peer *peer, *tmp;
844 lockdep_assert_held(&ar->conf_mutex);
846 spin_lock_bh(&ar->data_lock);
847 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
848 if (peer->vdev_id != vdev_id)
851 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
852 peer->addr, vdev_id);
854 for_each_set_bit(peer_id, peer->peer_ids,
855 ATH10K_MAX_NUM_PEER_IDS) {
856 ar->peer_map[peer_id] = NULL;
859 /* Double check that peer is properly un-referenced from
862 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
863 if (ar->peer_map[i] == peer) {
864 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
865 peer->addr, peer, i);
866 ar->peer_map[i] = NULL;
870 list_del(&peer->list);
874 spin_unlock_bh(&ar->data_lock);
877 static void ath10k_peer_cleanup_all(struct ath10k *ar)
879 struct ath10k_peer *peer, *tmp;
882 lockdep_assert_held(&ar->conf_mutex);
884 spin_lock_bh(&ar->data_lock);
885 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
886 list_del(&peer->list);
890 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
891 ar->peer_map[i] = NULL;
893 spin_unlock_bh(&ar->data_lock);
896 ar->num_stations = 0;
899 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
900 struct ieee80211_sta *sta,
901 enum wmi_tdls_peer_state state)
904 struct wmi_tdls_peer_update_cmd_arg arg = {};
905 struct wmi_tdls_peer_capab_arg cap = {};
906 struct wmi_channel_arg chan_arg = {};
908 lockdep_assert_held(&ar->conf_mutex);
910 arg.vdev_id = vdev_id;
911 arg.peer_state = state;
912 ether_addr_copy(arg.addr, sta->addr);
914 cap.peer_max_sp = sta->max_sp;
915 cap.peer_uapsd_queues = sta->uapsd_queues;
917 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
918 !sta->tdls_initiator)
919 cap.is_peer_responder = 1;
921 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
923 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
924 arg.addr, vdev_id, ret);
931 /************************/
932 /* Interface management */
933 /************************/
935 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
937 struct ath10k *ar = arvif->ar;
939 lockdep_assert_held(&ar->data_lock);
944 if (!arvif->beacon_buf)
945 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
946 arvif->beacon->len, DMA_TO_DEVICE);
948 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
949 arvif->beacon_state != ATH10K_BEACON_SENT))
952 dev_kfree_skb_any(arvif->beacon);
954 arvif->beacon = NULL;
955 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
958 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
960 struct ath10k *ar = arvif->ar;
962 lockdep_assert_held(&ar->data_lock);
964 ath10k_mac_vif_beacon_free(arvif);
966 if (arvif->beacon_buf) {
967 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
968 arvif->beacon_buf, arvif->beacon_paddr);
969 arvif->beacon_buf = NULL;
973 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
975 unsigned long time_left;
977 lockdep_assert_held(&ar->conf_mutex);
979 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
982 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
983 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
987 return ar->last_wmi_vdev_start_status;
990 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
992 struct cfg80211_chan_def *chandef = NULL;
993 struct ieee80211_channel *channel = NULL;
994 struct wmi_vdev_start_request_arg arg = {};
997 lockdep_assert_held(&ar->conf_mutex);
999 ieee80211_iter_chan_contexts_atomic(ar->hw,
1000 ath10k_mac_get_any_chandef_iter,
1002 if (WARN_ON_ONCE(!chandef))
1005 channel = chandef->chan;
1007 arg.vdev_id = vdev_id;
1008 arg.channel.freq = channel->center_freq;
1009 arg.channel.band_center_freq1 = chandef->center_freq1;
1010 arg.channel.band_center_freq2 = chandef->center_freq2;
1012 /* TODO setup this dynamically, what in case we
1013 * don't have any vifs?
1015 arg.channel.mode = chan_to_phymode(chandef);
1016 arg.channel.chan_radar =
1017 !!(channel->flags & IEEE80211_CHAN_RADAR);
1019 arg.channel.min_power = 0;
1020 arg.channel.max_power = channel->max_power * 2;
1021 arg.channel.max_reg_power = channel->max_reg_power * 2;
1022 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
1024 reinit_completion(&ar->vdev_setup_done);
1026 ret = ath10k_wmi_vdev_start(ar, &arg);
1028 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1033 ret = ath10k_vdev_setup_sync(ar);
1035 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1040 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1042 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1047 ar->monitor_vdev_id = vdev_id;
1049 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1050 ar->monitor_vdev_id);
1054 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1056 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1057 ar->monitor_vdev_id, ret);
1062 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1066 lockdep_assert_held(&ar->conf_mutex);
1068 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1070 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1071 ar->monitor_vdev_id, ret);
1073 reinit_completion(&ar->vdev_setup_done);
1075 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1077 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1078 ar->monitor_vdev_id, ret);
1080 ret = ath10k_vdev_setup_sync(ar);
1082 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1083 ar->monitor_vdev_id, ret);
1085 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1086 ar->monitor_vdev_id);
1090 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1094 lockdep_assert_held(&ar->conf_mutex);
1096 if (ar->free_vdev_map == 0) {
1097 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1101 bit = __ffs64(ar->free_vdev_map);
1103 ar->monitor_vdev_id = bit;
1105 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1106 WMI_VDEV_TYPE_MONITOR,
1109 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1110 ar->monitor_vdev_id, ret);
1114 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1115 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1116 ar->monitor_vdev_id);
1121 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1125 lockdep_assert_held(&ar->conf_mutex);
1127 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1129 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1130 ar->monitor_vdev_id, ret);
1134 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1136 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1137 ar->monitor_vdev_id);
1141 static int ath10k_monitor_start(struct ath10k *ar)
1145 lockdep_assert_held(&ar->conf_mutex);
1147 ret = ath10k_monitor_vdev_create(ar);
1149 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1153 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1155 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1156 ath10k_monitor_vdev_delete(ar);
1160 ar->monitor_started = true;
1161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1166 static int ath10k_monitor_stop(struct ath10k *ar)
1170 lockdep_assert_held(&ar->conf_mutex);
1172 ret = ath10k_monitor_vdev_stop(ar);
1174 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1178 ret = ath10k_monitor_vdev_delete(ar);
1180 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1184 ar->monitor_started = false;
1185 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1190 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1194 /* At least one chanctx is required to derive a channel to start
1197 num_ctx = ath10k_mac_num_chanctxs(ar);
1201 /* If there's already an existing special monitor interface then don't
1202 * bother creating another monitor vdev.
1204 if (ar->monitor_arvif)
1207 return ar->monitor ||
1208 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1209 ar->running_fw->fw_file.fw_features) &&
1210 (ar->filter_flags & FIF_OTHER_BSS)) ||
1211 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1214 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1218 num_ctx = ath10k_mac_num_chanctxs(ar);
1220 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1221 * shouldn't allow this but make sure to prevent handling the following
1222 * case anyway since multi-channel DFS hasn't been tested at all.
1224 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1230 static int ath10k_monitor_recalc(struct ath10k *ar)
1236 lockdep_assert_held(&ar->conf_mutex);
1238 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1239 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1241 ath10k_dbg(ar, ATH10K_DBG_MAC,
1242 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1243 ar->monitor_started, needed, allowed);
1245 if (WARN_ON(needed && !allowed)) {
1246 if (ar->monitor_started) {
1247 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1249 ret = ath10k_monitor_stop(ar);
1251 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1259 if (needed == ar->monitor_started)
1263 return ath10k_monitor_start(ar);
1265 return ath10k_monitor_stop(ar);
1268 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1270 struct ath10k *ar = arvif->ar;
1272 lockdep_assert_held(&ar->conf_mutex);
1274 if (!arvif->is_started) {
1275 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1282 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1284 struct ath10k *ar = arvif->ar;
1287 lockdep_assert_held(&ar->conf_mutex);
1289 vdev_param = ar->wmi.vdev_param->protection_mode;
1291 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1292 arvif->vdev_id, arvif->use_cts_prot);
1294 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1295 arvif->use_cts_prot ? 1 : 0);
1298 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1300 struct ath10k *ar = arvif->ar;
1301 u32 vdev_param, rts_cts = 0;
1303 lockdep_assert_held(&ar->conf_mutex);
1305 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1307 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1309 if (arvif->num_legacy_stations > 0)
1310 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1311 WMI_RTSCTS_PROFILE);
1313 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1314 WMI_RTSCTS_PROFILE);
1316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1317 arvif->vdev_id, rts_cts);
1319 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1323 static int ath10k_start_cac(struct ath10k *ar)
1327 lockdep_assert_held(&ar->conf_mutex);
1329 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1331 ret = ath10k_monitor_recalc(ar);
1333 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1334 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1338 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1339 ar->monitor_vdev_id);
1344 static int ath10k_stop_cac(struct ath10k *ar)
1346 lockdep_assert_held(&ar->conf_mutex);
1348 /* CAC is not running - do nothing */
1349 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1352 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1353 ath10k_monitor_stop(ar);
1355 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1360 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1361 struct ieee80211_chanctx_conf *conf,
1366 if (!*ret && conf->radar_enabled)
1370 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1372 bool has_radar = false;
1374 ieee80211_iter_chan_contexts_atomic(ar->hw,
1375 ath10k_mac_has_radar_iter,
1381 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1385 lockdep_assert_held(&ar->conf_mutex);
1387 ath10k_stop_cac(ar);
1389 if (!ath10k_mac_has_radar_enabled(ar))
1392 if (ar->num_started_vdevs > 0)
1395 ret = ath10k_start_cac(ar);
1398 * Not possible to start CAC on current channel so starting
1399 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1400 * by indicating that radar was detected.
1402 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1403 ieee80211_radar_detected(ar->hw);
1407 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1409 struct ath10k *ar = arvif->ar;
1412 lockdep_assert_held(&ar->conf_mutex);
1414 reinit_completion(&ar->vdev_setup_done);
1416 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1418 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1419 arvif->vdev_id, ret);
1423 ret = ath10k_vdev_setup_sync(ar);
1425 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1426 arvif->vdev_id, ret);
1430 WARN_ON(ar->num_started_vdevs == 0);
1432 if (ar->num_started_vdevs != 0) {
1433 ar->num_started_vdevs--;
1434 ath10k_recalc_radar_detection(ar);
1440 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1441 const struct cfg80211_chan_def *chandef,
1444 struct ath10k *ar = arvif->ar;
1445 struct wmi_vdev_start_request_arg arg = {};
1448 lockdep_assert_held(&ar->conf_mutex);
1450 reinit_completion(&ar->vdev_setup_done);
1452 arg.vdev_id = arvif->vdev_id;
1453 arg.dtim_period = arvif->dtim_period;
1454 arg.bcn_intval = arvif->beacon_interval;
1456 arg.channel.freq = chandef->chan->center_freq;
1457 arg.channel.band_center_freq1 = chandef->center_freq1;
1458 arg.channel.band_center_freq2 = chandef->center_freq2;
1459 arg.channel.mode = chan_to_phymode(chandef);
1461 arg.channel.min_power = 0;
1462 arg.channel.max_power = chandef->chan->max_power * 2;
1463 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1464 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1466 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1467 arg.ssid = arvif->u.ap.ssid;
1468 arg.ssid_len = arvif->u.ap.ssid_len;
1469 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1471 /* For now allow DFS for AP mode */
1472 arg.channel.chan_radar =
1473 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1474 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1475 arg.ssid = arvif->vif->bss_conf.ssid;
1476 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1479 ath10k_dbg(ar, ATH10K_DBG_MAC,
1480 "mac vdev %d start center_freq %d phymode %s\n",
1481 arg.vdev_id, arg.channel.freq,
1482 ath10k_wmi_phymode_str(arg.channel.mode));
1485 ret = ath10k_wmi_vdev_restart(ar, &arg);
1487 ret = ath10k_wmi_vdev_start(ar, &arg);
1490 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1495 ret = ath10k_vdev_setup_sync(ar);
1498 "failed to synchronize setup for vdev %i restart %d: %d\n",
1499 arg.vdev_id, restart, ret);
1503 ar->num_started_vdevs++;
1504 ath10k_recalc_radar_detection(ar);
1509 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1510 const struct cfg80211_chan_def *def)
1512 return ath10k_vdev_start_restart(arvif, def, false);
1515 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1516 const struct cfg80211_chan_def *def)
1518 return ath10k_vdev_start_restart(arvif, def, true);
1521 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1522 struct sk_buff *bcn)
1524 struct ath10k *ar = arvif->ar;
1525 struct ieee80211_mgmt *mgmt;
1529 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1532 mgmt = (void *)bcn->data;
1533 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1534 mgmt->u.beacon.variable,
1535 bcn->len - (mgmt->u.beacon.variable -
1540 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1542 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1543 arvif->vdev_id, ret);
1550 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1551 u8 oui_type, size_t ie_offset)
1558 if (WARN_ON(skb->len < ie_offset))
1561 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1562 skb->data + ie_offset,
1563 skb->len - ie_offset);
1568 end = skb->data + skb->len;
1571 if (WARN_ON(next > end))
1574 memmove(ie, next, end - next);
1575 skb_trim(skb, skb->len - len);
1580 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1582 struct ath10k *ar = arvif->ar;
1583 struct ieee80211_hw *hw = ar->hw;
1584 struct ieee80211_vif *vif = arvif->vif;
1585 struct ieee80211_mutable_offsets offs = {};
1586 struct sk_buff *bcn;
1589 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1592 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1593 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1596 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1598 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1602 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1604 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1609 /* P2P IE is inserted by firmware automatically (as configured above)
1610 * so remove it from the base beacon template to avoid duplicate P2P
1611 * IEs in beacon frames.
1613 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1614 offsetof(struct ieee80211_mgmt,
1615 u.beacon.variable));
1617 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1622 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1630 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1632 struct ath10k *ar = arvif->ar;
1633 struct ieee80211_hw *hw = ar->hw;
1634 struct ieee80211_vif *vif = arvif->vif;
1635 struct sk_buff *prb;
1638 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1641 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1644 prb = ieee80211_proberesp_get(hw, vif);
1646 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1650 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1654 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1662 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1664 struct ath10k *ar = arvif->ar;
1665 struct cfg80211_chan_def def;
1668 /* When originally vdev is started during assign_vif_chanctx() some
1669 * information is missing, notably SSID. Firmware revisions with beacon
1670 * offloading require the SSID to be provided during vdev (re)start to
1671 * handle hidden SSID properly.
1673 * Vdev restart must be done after vdev has been both started and
1674 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1675 * deliver vdev restart response event causing timeouts during vdev
1676 * syncing in ath10k.
1678 * Note: The vdev down/up and template reinstallation could be skipped
1679 * since only wmi-tlv firmware are known to have beacon offload and
1680 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1681 * response delivery. It's probably more robust to keep it as is.
1683 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1686 if (WARN_ON(!arvif->is_started))
1689 if (WARN_ON(!arvif->is_up))
1692 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1695 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1697 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1698 arvif->vdev_id, ret);
1702 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1703 * firmware will crash upon vdev up.
1706 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1708 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1712 ret = ath10k_mac_setup_prb_tmpl(arvif);
1714 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1718 ret = ath10k_vdev_restart(arvif, &def);
1720 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1721 arvif->vdev_id, ret);
1725 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1728 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1729 arvif->vdev_id, ret);
1736 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1737 struct ieee80211_bss_conf *info)
1739 struct ath10k *ar = arvif->ar;
1742 lockdep_assert_held(&arvif->ar->conf_mutex);
1744 if (!info->enable_beacon) {
1745 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1747 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1748 arvif->vdev_id, ret);
1750 arvif->is_up = false;
1752 spin_lock_bh(&arvif->ar->data_lock);
1753 ath10k_mac_vif_beacon_free(arvif);
1754 spin_unlock_bh(&arvif->ar->data_lock);
1759 arvif->tx_seq_no = 0x1000;
1762 ether_addr_copy(arvif->bssid, info->bssid);
1764 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1767 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1768 arvif->vdev_id, ret);
1772 arvif->is_up = true;
1774 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1776 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1777 arvif->vdev_id, ret);
1781 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1784 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1785 struct ieee80211_bss_conf *info,
1786 const u8 self_peer[ETH_ALEN])
1788 struct ath10k *ar = arvif->ar;
1792 lockdep_assert_held(&arvif->ar->conf_mutex);
1794 if (!info->ibss_joined) {
1795 if (is_zero_ether_addr(arvif->bssid))
1798 eth_zero_addr(arvif->bssid);
1803 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1804 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1805 ATH10K_DEFAULT_ATIM);
1807 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1808 arvif->vdev_id, ret);
1811 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1813 struct ath10k *ar = arvif->ar;
1818 lockdep_assert_held(&arvif->ar->conf_mutex);
1820 if (arvif->u.sta.uapsd)
1821 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1823 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1825 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1826 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1828 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1829 value, arvif->vdev_id, ret);
1836 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1838 struct ath10k *ar = arvif->ar;
1843 lockdep_assert_held(&arvif->ar->conf_mutex);
1845 if (arvif->u.sta.uapsd)
1846 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1848 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1850 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1851 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1854 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1855 value, arvif->vdev_id, ret);
1862 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1864 struct ath10k_vif *arvif;
1867 lockdep_assert_held(&ar->conf_mutex);
1869 list_for_each_entry(arvif, &ar->arvifs, list)
1870 if (arvif->is_started)
1876 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1878 struct ath10k *ar = arvif->ar;
1879 struct ieee80211_vif *vif = arvif->vif;
1880 struct ieee80211_conf *conf = &ar->hw->conf;
1881 enum wmi_sta_powersave_param param;
1882 enum wmi_sta_ps_mode psmode;
1887 lockdep_assert_held(&arvif->ar->conf_mutex);
1889 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1892 enable_ps = arvif->ps;
1894 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1895 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1896 ar->running_fw->fw_file.fw_features)) {
1897 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1902 if (!arvif->is_started) {
1903 /* mac80211 can update vif powersave state while disconnected.
1904 * Firmware doesn't behave nicely and consumes more power than
1905 * necessary if PS is disabled on a non-started vdev. Hence
1906 * force-enable PS for non-running vdevs.
1908 psmode = WMI_STA_PS_MODE_ENABLED;
1909 } else if (enable_ps) {
1910 psmode = WMI_STA_PS_MODE_ENABLED;
1911 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1913 ps_timeout = conf->dynamic_ps_timeout;
1914 if (ps_timeout == 0) {
1915 /* Firmware doesn't like 0 */
1916 ps_timeout = ieee80211_tu_to_usec(
1917 vif->bss_conf.beacon_int) / 1000;
1920 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1923 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1924 arvif->vdev_id, ret);
1928 psmode = WMI_STA_PS_MODE_DISABLED;
1931 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1932 arvif->vdev_id, psmode ? "enable" : "disable");
1934 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1936 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1937 psmode, arvif->vdev_id, ret);
1944 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1946 struct ath10k *ar = arvif->ar;
1947 struct wmi_sta_keepalive_arg arg = {};
1950 lockdep_assert_held(&arvif->ar->conf_mutex);
1952 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1955 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1958 /* Some firmware revisions have a bug and ignore the `enabled` field.
1959 * Instead use the interval to disable the keepalive.
1961 arg.vdev_id = arvif->vdev_id;
1963 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1964 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1966 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1968 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1969 arvif->vdev_id, ret);
1976 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1978 struct ath10k *ar = arvif->ar;
1979 struct ieee80211_vif *vif = arvif->vif;
1982 lockdep_assert_held(&arvif->ar->conf_mutex);
1984 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1987 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1990 if (!vif->csa_active)
1996 if (!ieee80211_csa_is_complete(vif)) {
1997 ieee80211_csa_update_counter(vif);
1999 ret = ath10k_mac_setup_bcn_tmpl(arvif);
2001 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
2004 ret = ath10k_mac_setup_prb_tmpl(arvif);
2006 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
2009 ieee80211_csa_finish(vif);
2013 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2015 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2017 struct ath10k *ar = arvif->ar;
2019 mutex_lock(&ar->conf_mutex);
2020 ath10k_mac_vif_ap_csa_count_down(arvif);
2021 mutex_unlock(&ar->conf_mutex);
2024 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2025 struct ieee80211_vif *vif)
2027 struct sk_buff *skb = data;
2028 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2029 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2031 if (vif->type != NL80211_IFTYPE_STATION)
2034 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2037 cancel_delayed_work(&arvif->connection_loss_work);
2040 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2042 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2043 IEEE80211_IFACE_ITER_NORMAL,
2044 ath10k_mac_handle_beacon_iter,
2048 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2049 struct ieee80211_vif *vif)
2051 u32 *vdev_id = data;
2052 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2053 struct ath10k *ar = arvif->ar;
2054 struct ieee80211_hw *hw = ar->hw;
2056 if (arvif->vdev_id != *vdev_id)
2062 ieee80211_beacon_loss(vif);
2064 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2065 * (done by mac80211) succeeds but beacons do not resume then it
2066 * doesn't make sense to continue operation. Queue connection loss work
2067 * which can be cancelled when beacon is received.
2069 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2070 ATH10K_CONNECTION_LOSS_HZ);
2073 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2075 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2076 IEEE80211_IFACE_ITER_NORMAL,
2077 ath10k_mac_handle_beacon_miss_iter,
2081 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2083 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2084 connection_loss_work.work);
2085 struct ieee80211_vif *vif = arvif->vif;
2090 ieee80211_connection_loss(vif);
2093 /**********************/
2094 /* Station management */
2095 /**********************/
2097 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2098 struct ieee80211_vif *vif)
2100 /* Some firmware revisions have unstable STA powersave when listen
2101 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2102 * generate NullFunc frames properly even if buffered frames have been
2103 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2104 * buffered frames. Often pinging the device from AP would simply fail.
2106 * As a workaround set it to 1.
2108 if (vif->type == NL80211_IFTYPE_STATION)
2111 return ar->hw->conf.listen_interval;
2114 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2115 struct ieee80211_vif *vif,
2116 struct ieee80211_sta *sta,
2117 struct wmi_peer_assoc_complete_arg *arg)
2119 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2122 lockdep_assert_held(&ar->conf_mutex);
2124 if (vif->type == NL80211_IFTYPE_STATION)
2125 aid = vif->bss_conf.aid;
2129 ether_addr_copy(arg->addr, sta->addr);
2130 arg->vdev_id = arvif->vdev_id;
2131 arg->peer_aid = aid;
2132 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2133 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2134 arg->peer_num_spatial_streams = 1;
2135 arg->peer_caps = vif->bss_conf.assoc_capability;
2138 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2139 struct ieee80211_vif *vif,
2140 struct ieee80211_sta *sta,
2141 struct wmi_peer_assoc_complete_arg *arg)
2143 struct ieee80211_bss_conf *info = &vif->bss_conf;
2144 struct cfg80211_chan_def def;
2145 struct cfg80211_bss *bss;
2146 const u8 *rsnie = NULL;
2147 const u8 *wpaie = NULL;
2149 lockdep_assert_held(&ar->conf_mutex);
2151 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2154 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2155 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2157 const struct cfg80211_bss_ies *ies;
2160 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2162 ies = rcu_dereference(bss->ies);
2164 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2165 WLAN_OUI_TYPE_MICROSOFT_WPA,
2169 cfg80211_put_bss(ar->hw->wiphy, bss);
2172 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2173 if (rsnie || wpaie) {
2174 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2175 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2179 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2180 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2184 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2185 ar->running_fw->fw_file.fw_features)) {
2186 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2190 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2191 struct ieee80211_vif *vif,
2192 struct ieee80211_sta *sta,
2193 struct wmi_peer_assoc_complete_arg *arg)
2195 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2196 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2197 struct cfg80211_chan_def def;
2198 const struct ieee80211_supported_band *sband;
2199 const struct ieee80211_rate *rates;
2200 enum nl80211_band band;
2205 lockdep_assert_held(&ar->conf_mutex);
2207 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2210 band = def.chan->band;
2211 sband = ar->hw->wiphy->bands[band];
2212 ratemask = sta->supp_rates[band];
2213 ratemask &= arvif->bitrate_mask.control[band].legacy;
2214 rates = sband->bitrates;
2216 rateset->num_rates = 0;
2218 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2219 if (!(ratemask & 1))
2222 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2223 rateset->rates[rateset->num_rates] = rate;
2224 rateset->num_rates++;
2229 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2233 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2234 if (ht_mcs_mask[nss])
2241 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2245 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2246 if (vht_mcs_mask[nss])
2252 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2253 struct ieee80211_vif *vif,
2254 struct ieee80211_sta *sta,
2255 struct wmi_peer_assoc_complete_arg *arg)
2257 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2258 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2259 struct cfg80211_chan_def def;
2260 enum nl80211_band band;
2261 const u8 *ht_mcs_mask;
2262 const u16 *vht_mcs_mask;
2267 lockdep_assert_held(&ar->conf_mutex);
2269 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2272 if (!ht_cap->ht_supported)
2275 band = def.chan->band;
2276 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2277 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2279 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2280 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2283 arg->peer_flags |= ar->wmi.peer_flags->ht;
2284 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2285 ht_cap->ampdu_factor)) - 1;
2287 arg->peer_mpdu_density =
2288 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2290 arg->peer_ht_caps = ht_cap->cap;
2291 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2293 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2294 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2296 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2297 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2298 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2301 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2302 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2303 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2305 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2306 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2309 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2310 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2311 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2314 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2315 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2316 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2317 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2318 arg->peer_rate_caps |= stbc;
2319 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2322 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2323 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2324 else if (ht_cap->mcs.rx_mask[1])
2325 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2327 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2328 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2329 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2330 max_nss = (i / 8) + 1;
2331 arg->peer_ht_rates.rates[n++] = i;
2335 * This is a workaround for HT-enabled STAs which break the spec
2336 * and have no HT capabilities RX mask (no HT RX MCS map).
2338 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2339 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2341 * Firmware asserts if such situation occurs.
2344 arg->peer_ht_rates.num_rates = 8;
2345 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2346 arg->peer_ht_rates.rates[i] = i;
2348 arg->peer_ht_rates.num_rates = n;
2349 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2352 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2354 arg->peer_ht_rates.num_rates,
2355 arg->peer_num_spatial_streams);
2358 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2359 struct ath10k_vif *arvif,
2360 struct ieee80211_sta *sta)
2366 lockdep_assert_held(&ar->conf_mutex);
2368 if (sta->wme && sta->uapsd_queues) {
2369 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2370 sta->uapsd_queues, sta->max_sp);
2372 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2373 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2374 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2375 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2376 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2377 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2378 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2379 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2380 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2381 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2382 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2383 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2385 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2386 max_sp = sta->max_sp;
2388 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2390 WMI_AP_PS_PEER_PARAM_UAPSD,
2393 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2394 arvif->vdev_id, ret);
2398 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2400 WMI_AP_PS_PEER_PARAM_MAX_SP,
2403 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2404 arvif->vdev_id, ret);
2408 /* TODO setup this based on STA listen interval and
2409 * beacon interval. Currently we don't know
2410 * sta->listen_interval - mac80211 patch required.
2411 * Currently use 10 seconds
2413 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2414 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2417 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2418 arvif->vdev_id, ret);
2427 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2428 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2435 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2436 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2440 idx_limit = fls(mcs_map) - 1;
2444 switch (idx_limit) {
2445 case 0: /* fall through */
2446 case 1: /* fall through */
2447 case 2: /* fall through */
2448 case 3: /* fall through */
2449 case 4: /* fall through */
2450 case 5: /* fall through */
2451 case 6: /* fall through */
2453 /* see ath10k_mac_can_set_bitrate_mask() */
2457 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2460 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2463 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2466 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2470 tx_mcs_set &= ~(0x3 << (nss * 2));
2471 tx_mcs_set |= mcs << (nss * 2);
2477 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2478 struct ieee80211_vif *vif,
2479 struct ieee80211_sta *sta,
2480 struct wmi_peer_assoc_complete_arg *arg)
2482 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2483 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2484 struct cfg80211_chan_def def;
2485 enum nl80211_band band;
2486 const u16 *vht_mcs_mask;
2488 u8 max_nss, vht_mcs;
2491 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2494 if (!vht_cap->vht_supported)
2497 band = def.chan->band;
2498 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2500 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2503 arg->peer_flags |= ar->wmi.peer_flags->vht;
2505 if (def.chan->band == NL80211_BAND_2GHZ)
2506 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2508 arg->peer_vht_caps = vht_cap->cap;
2510 ampdu_factor = (vht_cap->cap &
2511 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2512 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2514 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2515 * zero in VHT IE. Using it would result in degraded throughput.
2516 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2517 * it if VHT max_mpdu is smaller.
2519 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2520 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2521 ampdu_factor)) - 1);
2523 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2524 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2526 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2527 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2529 /* Calculate peer NSS capability from VHT capabilities if STA
2532 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2533 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2536 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2540 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2541 arg->peer_vht_rates.rx_max_rate =
2542 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2543 arg->peer_vht_rates.rx_mcs_set =
2544 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2545 arg->peer_vht_rates.tx_max_rate =
2546 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2547 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2548 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2550 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2551 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2553 if (arg->peer_vht_rates.rx_max_rate &&
2554 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2555 switch (arg->peer_vht_rates.rx_max_rate) {
2557 /* Must be 2x2 at 160Mhz is all it can do. */
2558 arg->peer_bw_rxnss_override = 2;
2561 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2562 arg->peer_bw_rxnss_override = 1;
2568 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2569 struct ieee80211_vif *vif,
2570 struct ieee80211_sta *sta,
2571 struct wmi_peer_assoc_complete_arg *arg)
2573 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2575 switch (arvif->vdev_type) {
2576 case WMI_VDEV_TYPE_AP:
2578 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2580 if (sta->wme && sta->uapsd_queues) {
2581 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2582 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2585 case WMI_VDEV_TYPE_STA:
2587 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2589 case WMI_VDEV_TYPE_IBSS:
2591 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2597 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2598 sta->addr, !!(arg->peer_flags &
2599 arvif->ar->wmi.peer_flags->qos));
2602 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2604 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2605 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2608 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2609 struct ieee80211_sta *sta)
2611 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2612 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2613 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2614 return MODE_11AC_VHT160;
2615 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2616 return MODE_11AC_VHT80_80;
2618 /* not sure if this is a valid case? */
2619 return MODE_11AC_VHT160;
2623 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2624 return MODE_11AC_VHT80;
2626 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2627 return MODE_11AC_VHT40;
2629 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2630 return MODE_11AC_VHT20;
2632 return MODE_UNKNOWN;
2635 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2636 struct ieee80211_vif *vif,
2637 struct ieee80211_sta *sta,
2638 struct wmi_peer_assoc_complete_arg *arg)
2640 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2641 struct cfg80211_chan_def def;
2642 enum nl80211_band band;
2643 const u8 *ht_mcs_mask;
2644 const u16 *vht_mcs_mask;
2645 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2647 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2650 band = def.chan->band;
2651 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2652 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2655 case NL80211_BAND_2GHZ:
2656 if (sta->vht_cap.vht_supported &&
2657 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2658 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2659 phymode = MODE_11AC_VHT40;
2661 phymode = MODE_11AC_VHT20;
2662 } else if (sta->ht_cap.ht_supported &&
2663 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2664 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2665 phymode = MODE_11NG_HT40;
2667 phymode = MODE_11NG_HT20;
2668 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2675 case NL80211_BAND_5GHZ:
2679 if (sta->vht_cap.vht_supported &&
2680 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2681 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2682 } else if (sta->ht_cap.ht_supported &&
2683 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2684 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2685 phymode = MODE_11NA_HT40;
2687 phymode = MODE_11NA_HT20;
2697 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2698 sta->addr, ath10k_wmi_phymode_str(phymode));
2700 arg->peer_phymode = phymode;
2701 WARN_ON(phymode == MODE_UNKNOWN);
2704 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2705 struct ieee80211_vif *vif,
2706 struct ieee80211_sta *sta,
2707 struct wmi_peer_assoc_complete_arg *arg)
2709 lockdep_assert_held(&ar->conf_mutex);
2711 memset(arg, 0, sizeof(*arg));
2713 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2714 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2715 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2716 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2717 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2718 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2719 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2724 static const u32 ath10k_smps_map[] = {
2725 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2726 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2727 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2728 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2731 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2733 const struct ieee80211_sta_ht_cap *ht_cap)
2737 if (!ht_cap->ht_supported)
2740 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2741 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2743 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2746 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2747 WMI_PEER_SMPS_STATE,
2748 ath10k_smps_map[smps]);
2751 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2752 struct ieee80211_vif *vif,
2753 struct ieee80211_sta_vht_cap vht_cap)
2755 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2760 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2763 if (!(ar->vht_cap_info &
2764 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2765 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2766 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2767 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2770 param = ar->wmi.vdev_param->txbf;
2773 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2776 /* The following logic is correct. If a remote STA advertises support
2777 * for being a beamformer then we should enable us being a beamformee.
2780 if (ar->vht_cap_info &
2781 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2782 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2783 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2784 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2786 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2787 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2790 if (ar->vht_cap_info &
2791 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2792 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2793 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2794 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2796 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2797 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2800 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2801 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2803 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2804 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2806 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2808 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2816 /* can be called only in mac80211 callbacks due to `key_count` usage */
2817 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2818 struct ieee80211_vif *vif,
2819 struct ieee80211_bss_conf *bss_conf)
2821 struct ath10k *ar = hw->priv;
2822 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2823 struct ieee80211_sta_ht_cap ht_cap;
2824 struct ieee80211_sta_vht_cap vht_cap;
2825 struct wmi_peer_assoc_complete_arg peer_arg;
2826 struct ieee80211_sta *ap_sta;
2829 lockdep_assert_held(&ar->conf_mutex);
2831 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2832 arvif->vdev_id, arvif->bssid, arvif->aid);
2836 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2838 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2839 bss_conf->bssid, arvif->vdev_id);
2844 /* ap_sta must be accessed only within rcu section which must be left
2845 * before calling ath10k_setup_peer_smps() which might sleep.
2847 ht_cap = ap_sta->ht_cap;
2848 vht_cap = ap_sta->vht_cap;
2850 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2852 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2853 bss_conf->bssid, arvif->vdev_id, ret);
2860 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2862 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2863 bss_conf->bssid, arvif->vdev_id, ret);
2867 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2869 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2870 arvif->vdev_id, ret);
2874 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2876 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2877 arvif->vdev_id, bss_conf->bssid, ret);
2881 ath10k_dbg(ar, ATH10K_DBG_MAC,
2882 "mac vdev %d up (associated) bssid %pM aid %d\n",
2883 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2885 WARN_ON(arvif->is_up);
2887 arvif->aid = bss_conf->aid;
2888 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2890 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2892 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2893 arvif->vdev_id, ret);
2897 arvif->is_up = true;
2899 /* Workaround: Some firmware revisions (tested with qca6174
2900 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2901 * poked with peer param command.
2903 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2904 WMI_PEER_DUMMY_VAR, 1);
2906 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2907 arvif->bssid, arvif->vdev_id, ret);
2912 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2913 struct ieee80211_vif *vif)
2915 struct ath10k *ar = hw->priv;
2916 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2917 struct ieee80211_sta_vht_cap vht_cap = {};
2920 lockdep_assert_held(&ar->conf_mutex);
2922 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2923 arvif->vdev_id, arvif->bssid);
2925 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2927 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2928 arvif->vdev_id, ret);
2930 arvif->def_wep_key_idx = -1;
2932 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2934 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2935 arvif->vdev_id, ret);
2939 arvif->is_up = false;
2941 cancel_delayed_work_sync(&arvif->connection_loss_work);
2944 static int ath10k_station_assoc(struct ath10k *ar,
2945 struct ieee80211_vif *vif,
2946 struct ieee80211_sta *sta,
2949 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2950 struct wmi_peer_assoc_complete_arg peer_arg;
2953 lockdep_assert_held(&ar->conf_mutex);
2955 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2957 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2958 sta->addr, arvif->vdev_id, ret);
2962 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2964 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2965 sta->addr, arvif->vdev_id, ret);
2969 /* Re-assoc is run only to update supported rates for given station. It
2970 * doesn't make much sense to reconfigure the peer completely.
2973 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2976 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2977 arvif->vdev_id, ret);
2981 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2983 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2984 sta->addr, arvif->vdev_id, ret);
2989 arvif->num_legacy_stations++;
2990 ret = ath10k_recalc_rtscts_prot(arvif);
2992 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2993 arvif->vdev_id, ret);
2998 /* Plumb cached keys only for static WEP */
2999 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
3000 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
3002 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
3003 arvif->vdev_id, ret);
3012 static int ath10k_station_disassoc(struct ath10k *ar,
3013 struct ieee80211_vif *vif,
3014 struct ieee80211_sta *sta)
3016 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3019 lockdep_assert_held(&ar->conf_mutex);
3022 arvif->num_legacy_stations--;
3023 ret = ath10k_recalc_rtscts_prot(arvif);
3025 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3026 arvif->vdev_id, ret);
3031 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3033 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3034 arvif->vdev_id, ret);
3045 static int ath10k_update_channel_list(struct ath10k *ar)
3047 struct ieee80211_hw *hw = ar->hw;
3048 struct ieee80211_supported_band **bands;
3049 enum nl80211_band band;
3050 struct ieee80211_channel *channel;
3051 struct wmi_scan_chan_list_arg arg = {0};
3052 struct wmi_channel_arg *ch;
3058 lockdep_assert_held(&ar->conf_mutex);
3060 bands = hw->wiphy->bands;
3061 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3065 for (i = 0; i < bands[band]->n_channels; i++) {
3066 if (bands[band]->channels[i].flags &
3067 IEEE80211_CHAN_DISABLED)
3074 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3075 arg.channels = kzalloc(len, GFP_KERNEL);
3080 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3084 for (i = 0; i < bands[band]->n_channels; i++) {
3085 channel = &bands[band]->channels[i];
3087 if (channel->flags & IEEE80211_CHAN_DISABLED)
3090 ch->allow_ht = true;
3092 /* FIXME: when should we really allow VHT? */
3093 ch->allow_vht = true;
3096 !(channel->flags & IEEE80211_CHAN_NO_IR);
3099 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3102 !!(channel->flags & IEEE80211_CHAN_RADAR);
3104 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3105 ch->passive = passive;
3107 /* the firmware is ignoring the "radar" flag of the
3108 * channel and is scanning actively using Probe Requests
3109 * on "Radar detection"/DFS channels which are not
3110 * marked as "available"
3112 ch->passive |= ch->chan_radar;
3114 ch->freq = channel->center_freq;
3115 ch->band_center_freq1 = channel->center_freq;
3117 ch->max_power = channel->max_power * 2;
3118 ch->max_reg_power = channel->max_reg_power * 2;
3119 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3120 ch->reg_class_id = 0; /* FIXME */
3122 /* FIXME: why use only legacy modes, why not any
3123 * HT/VHT modes? Would that even make any
3126 if (channel->band == NL80211_BAND_2GHZ)
3127 ch->mode = MODE_11G;
3129 ch->mode = MODE_11A;
3131 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3134 ath10k_dbg(ar, ATH10K_DBG_WMI,
3135 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3136 ch - arg.channels, arg.n_channels,
3137 ch->freq, ch->max_power, ch->max_reg_power,
3138 ch->max_antenna_gain, ch->mode);
3144 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3145 kfree(arg.channels);
3150 static enum wmi_dfs_region
3151 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3153 switch (dfs_region) {
3154 case NL80211_DFS_UNSET:
3155 return WMI_UNINIT_DFS_DOMAIN;
3156 case NL80211_DFS_FCC:
3157 return WMI_FCC_DFS_DOMAIN;
3158 case NL80211_DFS_ETSI:
3159 return WMI_ETSI_DFS_DOMAIN;
3160 case NL80211_DFS_JP:
3161 return WMI_MKK4_DFS_DOMAIN;
3163 return WMI_UNINIT_DFS_DOMAIN;
3166 static void ath10k_regd_update(struct ath10k *ar)
3168 struct reg_dmn_pair_mapping *regpair;
3170 enum wmi_dfs_region wmi_dfs_reg;
3171 enum nl80211_dfs_regions nl_dfs_reg;
3173 lockdep_assert_held(&ar->conf_mutex);
3175 ret = ath10k_update_channel_list(ar);
3177 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3179 regpair = ar->ath_common.regulatory.regpair;
3181 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3182 nl_dfs_reg = ar->dfs_detector->region;
3183 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3185 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3188 /* Target allows setting up per-band regdomain but ath_common provides
3189 * a combined one only
3191 ret = ath10k_wmi_pdev_set_regdomain(ar,
3192 regpair->reg_domain,
3193 regpair->reg_domain, /* 2ghz */
3194 regpair->reg_domain, /* 5ghz */
3195 regpair->reg_2ghz_ctl,
3196 regpair->reg_5ghz_ctl,
3199 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3202 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3203 struct ieee80211_supported_band *band)
3207 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3208 for (i = 0; i < band->n_channels; i++) {
3209 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3210 band->channels[i].center_freq > ar->high_5ghz_chan)
3211 band->channels[i].flags |=
3212 IEEE80211_CHAN_DISABLED;
3217 static void ath10k_reg_notifier(struct wiphy *wiphy,
3218 struct regulatory_request *request)
3220 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3221 struct ath10k *ar = hw->priv;
3224 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3226 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3227 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3228 request->dfs_region);
3229 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3230 request->dfs_region);
3232 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3233 request->dfs_region);
3236 mutex_lock(&ar->conf_mutex);
3237 if (ar->state == ATH10K_STATE_ON)
3238 ath10k_regd_update(ar);
3239 mutex_unlock(&ar->conf_mutex);
3241 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3242 ath10k_mac_update_channel_list(ar,
3243 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3246 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3248 spin_lock_bh(&ar->data_lock);
3249 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3250 spin_unlock_bh(&ar->data_lock);
3252 cancel_work_sync(&ar->radar_confirmation_work);
3259 enum ath10k_mac_tx_path {
3261 ATH10K_MAC_TX_HTT_MGMT,
3262 ATH10K_MAC_TX_WMI_MGMT,
3263 ATH10K_MAC_TX_UNKNOWN,
3266 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3268 lockdep_assert_held(&ar->htt.tx_lock);
3270 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3271 ar->tx_paused |= BIT(reason);
3272 ieee80211_stop_queues(ar->hw);
3275 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3276 struct ieee80211_vif *vif)
3278 struct ath10k *ar = data;
3279 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3281 if (arvif->tx_paused)
3284 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3287 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3289 lockdep_assert_held(&ar->htt.tx_lock);
3291 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3292 ar->tx_paused &= ~BIT(reason);
3297 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3298 IEEE80211_IFACE_ITER_RESUME_ALL,
3299 ath10k_mac_tx_unlock_iter,
3302 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3305 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3307 struct ath10k *ar = arvif->ar;
3309 lockdep_assert_held(&ar->htt.tx_lock);
3311 WARN_ON(reason >= BITS_PER_LONG);
3312 arvif->tx_paused |= BIT(reason);
3313 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3316 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3318 struct ath10k *ar = arvif->ar;
3320 lockdep_assert_held(&ar->htt.tx_lock);
3322 WARN_ON(reason >= BITS_PER_LONG);
3323 arvif->tx_paused &= ~BIT(reason);
3328 if (arvif->tx_paused)
3331 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3334 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3335 enum wmi_tlv_tx_pause_id pause_id,
3336 enum wmi_tlv_tx_pause_action action)
3338 struct ath10k *ar = arvif->ar;
3340 lockdep_assert_held(&ar->htt.tx_lock);
3343 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3344 ath10k_mac_vif_tx_lock(arvif, pause_id);
3346 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3347 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3350 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3351 "received unknown tx pause action %d on vdev %i, ignoring\n",
3352 action, arvif->vdev_id);
3357 struct ath10k_mac_tx_pause {
3359 enum wmi_tlv_tx_pause_id pause_id;
3360 enum wmi_tlv_tx_pause_action action;
3363 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3364 struct ieee80211_vif *vif)
3366 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3367 struct ath10k_mac_tx_pause *arg = data;
3369 if (arvif->vdev_id != arg->vdev_id)
3372 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3375 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3376 enum wmi_tlv_tx_pause_id pause_id,
3377 enum wmi_tlv_tx_pause_action action)
3379 struct ath10k_mac_tx_pause arg = {
3381 .pause_id = pause_id,
3385 spin_lock_bh(&ar->htt.tx_lock);
3386 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3387 IEEE80211_IFACE_ITER_RESUME_ALL,
3388 ath10k_mac_handle_tx_pause_iter,
3390 spin_unlock_bh(&ar->htt.tx_lock);
3393 static enum ath10k_hw_txrx_mode
3394 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3395 struct ieee80211_vif *vif,
3396 struct ieee80211_sta *sta,
3397 struct sk_buff *skb)
3399 const struct ieee80211_hdr *hdr = (void *)skb->data;
3400 __le16 fc = hdr->frame_control;
3402 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3403 return ATH10K_HW_TXRX_RAW;
3405 if (ieee80211_is_mgmt(fc))
3406 return ATH10K_HW_TXRX_MGMT;
3410 * NullFunc frames are mostly used to ping if a client or AP are still
3411 * reachable and responsive. This implies tx status reports must be
3412 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3413 * come to a conclusion that the other end disappeared and tear down
3414 * BSS connection or it can never disconnect from BSS/client (which is
3417 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3418 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3419 * which seems to deliver correct tx reports for NullFunc frames. The
3420 * downside of using it is it ignores client powersave state so it can
3421 * end up disconnecting sleeping clients in AP mode. It should fix STA
3422 * mode though because AP don't sleep.
3424 if (ar->htt.target_version_major < 3 &&
3425 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3426 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3427 ar->running_fw->fw_file.fw_features))
3428 return ATH10K_HW_TXRX_MGMT;
3432 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3433 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3434 * to work with Ethernet txmode so use it.
3436 * FIXME: Check if raw mode works with TDLS.
3438 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3439 return ATH10K_HW_TXRX_ETHERNET;
3441 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3442 return ATH10K_HW_TXRX_RAW;
3444 return ATH10K_HW_TXRX_NATIVE_WIFI;
3447 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3448 struct sk_buff *skb)
3450 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3451 const struct ieee80211_hdr *hdr = (void *)skb->data;
3452 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3453 IEEE80211_TX_CTL_INJECTED;
3455 if (!ieee80211_has_protected(hdr->frame_control))
3458 if ((info->flags & mask) == mask)
3462 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3467 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3468 * Control in the header.
3470 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3472 struct ieee80211_hdr *hdr = (void *)skb->data;
3473 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3476 if (!ieee80211_is_data_qos(hdr->frame_control))
3479 qos_ctl = ieee80211_get_qos_ctl(hdr);
3480 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3481 skb->data, (void *)qos_ctl - (void *)skb->data);
3482 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3484 /* Some firmware revisions don't handle sending QoS NullFunc well.
3485 * These frames are mainly used for CQM purposes so it doesn't really
3486 * matter whether QoS NullFunc or NullFunc are sent.
3488 hdr = (void *)skb->data;
3489 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3490 cb->flags &= ~ATH10K_SKB_F_QOS;
3492 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3495 static void ath10k_tx_h_8023(struct sk_buff *skb)
3497 struct ieee80211_hdr *hdr;
3498 struct rfc1042_hdr *rfc1042;
3505 hdr = (void *)skb->data;
3506 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3507 rfc1042 = (void *)skb->data + hdrlen;
3509 ether_addr_copy(da, ieee80211_get_DA(hdr));
3510 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3511 type = rfc1042->snap_type;
3513 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3514 skb_push(skb, sizeof(*eth));
3516 eth = (void *)skb->data;
3517 ether_addr_copy(eth->h_dest, da);
3518 ether_addr_copy(eth->h_source, sa);
3519 eth->h_proto = type;
3522 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3523 struct ieee80211_vif *vif,
3524 struct sk_buff *skb)
3526 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3527 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3529 /* This is case only for P2P_GO */
3530 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3533 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3534 spin_lock_bh(&ar->data_lock);
3535 if (arvif->u.ap.noa_data)
3536 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3538 skb_put_data(skb, arvif->u.ap.noa_data,
3539 arvif->u.ap.noa_len);
3540 spin_unlock_bh(&ar->data_lock);
3544 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3545 struct ieee80211_vif *vif,
3546 struct ieee80211_txq *txq,
3547 struct sk_buff *skb)
3549 struct ieee80211_hdr *hdr = (void *)skb->data;
3550 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3553 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3554 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3556 if (ieee80211_is_mgmt(hdr->frame_control))
3557 cb->flags |= ATH10K_SKB_F_MGMT;
3559 if (ieee80211_is_data_qos(hdr->frame_control))
3560 cb->flags |= ATH10K_SKB_F_QOS;
3566 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3568 /* FIXME: Not really sure since when the behaviour changed. At some
3569 * point new firmware stopped requiring creation of peer entries for
3570 * offchannel tx (and actually creating them causes issues with wmi-htc
3571 * tx credit replenishment and reliability). Assuming it's at least 3.4
3572 * because that's when the `freq` was introduced to TX_FRM HTT command.
3574 return (ar->htt.target_version_major >= 3 &&
3575 ar->htt.target_version_minor >= 4 &&
3576 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3579 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3581 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3584 spin_lock_bh(&ar->data_lock);
3586 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3587 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3592 __skb_queue_tail(q, skb);
3593 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3596 spin_unlock_bh(&ar->data_lock);
3601 static enum ath10k_mac_tx_path
3602 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3603 struct sk_buff *skb,
3604 enum ath10k_hw_txrx_mode txmode)
3607 case ATH10K_HW_TXRX_RAW:
3608 case ATH10K_HW_TXRX_NATIVE_WIFI:
3609 case ATH10K_HW_TXRX_ETHERNET:
3610 return ATH10K_MAC_TX_HTT;
3611 case ATH10K_HW_TXRX_MGMT:
3612 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3613 ar->running_fw->fw_file.fw_features) ||
3614 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3616 return ATH10K_MAC_TX_WMI_MGMT;
3617 else if (ar->htt.target_version_major >= 3)
3618 return ATH10K_MAC_TX_HTT;
3620 return ATH10K_MAC_TX_HTT_MGMT;
3623 return ATH10K_MAC_TX_UNKNOWN;
3626 static int ath10k_mac_tx_submit(struct ath10k *ar,
3627 enum ath10k_hw_txrx_mode txmode,
3628 enum ath10k_mac_tx_path txpath,
3629 struct sk_buff *skb)
3631 struct ath10k_htt *htt = &ar->htt;
3635 case ATH10K_MAC_TX_HTT:
3636 ret = ath10k_htt_tx(htt, txmode, skb);
3638 case ATH10K_MAC_TX_HTT_MGMT:
3639 ret = ath10k_htt_mgmt_tx(htt, skb);
3641 case ATH10K_MAC_TX_WMI_MGMT:
3642 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3644 case ATH10K_MAC_TX_UNKNOWN:
3651 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3653 ieee80211_free_txskb(ar->hw, skb);
3659 /* This function consumes the sk_buff regardless of return value as far as
3660 * caller is concerned so no freeing is necessary afterwards.
3662 static int ath10k_mac_tx(struct ath10k *ar,
3663 struct ieee80211_vif *vif,
3664 enum ath10k_hw_txrx_mode txmode,
3665 enum ath10k_mac_tx_path txpath,
3666 struct sk_buff *skb)
3668 struct ieee80211_hw *hw = ar->hw;
3669 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3672 /* We should disable CCK RATE due to P2P */
3673 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3674 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3677 case ATH10K_HW_TXRX_MGMT:
3678 case ATH10K_HW_TXRX_NATIVE_WIFI:
3679 ath10k_tx_h_nwifi(hw, skb);
3680 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3681 ath10k_tx_h_seq_no(vif, skb);
3683 case ATH10K_HW_TXRX_ETHERNET:
3684 ath10k_tx_h_8023(skb);
3686 case ATH10K_HW_TXRX_RAW:
3687 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3689 ieee80211_free_txskb(hw, skb);
3694 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3695 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3696 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3699 skb_queue_tail(&ar->offchan_tx_queue, skb);
3700 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3705 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3707 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3714 void ath10k_offchan_tx_purge(struct ath10k *ar)
3716 struct sk_buff *skb;
3719 skb = skb_dequeue(&ar->offchan_tx_queue);
3723 ieee80211_free_txskb(ar->hw, skb);
3727 void ath10k_offchan_tx_work(struct work_struct *work)
3729 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3730 struct ath10k_peer *peer;
3731 struct ath10k_vif *arvif;
3732 enum ath10k_hw_txrx_mode txmode;
3733 enum ath10k_mac_tx_path txpath;
3734 struct ieee80211_hdr *hdr;
3735 struct ieee80211_vif *vif;
3736 struct ieee80211_sta *sta;
3737 struct sk_buff *skb;
3738 const u8 *peer_addr;
3741 unsigned long time_left;
3742 bool tmp_peer_created = false;
3744 /* FW requirement: We must create a peer before FW will send out
3745 * an offchannel frame. Otherwise the frame will be stuck and
3746 * never transmitted. We delete the peer upon tx completion.
3747 * It is unlikely that a peer for offchannel tx will already be
3748 * present. However it may be in some rare cases so account for that.
3749 * Otherwise we might remove a legitimate peer and break stuff.
3753 skb = skb_dequeue(&ar->offchan_tx_queue);
3757 mutex_lock(&ar->conf_mutex);
3759 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3762 hdr = (struct ieee80211_hdr *)skb->data;
3763 peer_addr = ieee80211_get_DA(hdr);
3765 spin_lock_bh(&ar->data_lock);
3766 vdev_id = ar->scan.vdev_id;
3767 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3768 spin_unlock_bh(&ar->data_lock);
3771 /* FIXME: should this use ath10k_warn()? */
3772 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3773 peer_addr, vdev_id);
3776 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3778 WMI_PEER_TYPE_DEFAULT);
3780 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3781 peer_addr, vdev_id, ret);
3782 tmp_peer_created = (ret == 0);
3785 spin_lock_bh(&ar->data_lock);
3786 reinit_completion(&ar->offchan_tx_completed);
3787 ar->offchan_tx_skb = skb;
3788 spin_unlock_bh(&ar->data_lock);
3790 /* It's safe to access vif and sta - conf_mutex guarantees that
3791 * sta_state() and remove_interface() are locked exclusively
3792 * out wrt to this offchannel worker.
3794 arvif = ath10k_get_arvif(ar, vdev_id);
3797 sta = ieee80211_find_sta(vif, peer_addr);
3803 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3804 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3806 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
3808 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3814 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3816 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3819 if (!peer && tmp_peer_created) {
3820 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3822 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3823 peer_addr, vdev_id, ret);
3826 mutex_unlock(&ar->conf_mutex);
3830 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3832 struct sk_buff *skb;
3835 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3839 ieee80211_free_txskb(ar->hw, skb);
3843 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3845 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3846 struct sk_buff *skb;
3851 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3855 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
3856 ar->running_fw->fw_file.fw_features)) {
3857 paddr = dma_map_single(ar->dev, skb->data,
3858 skb->len, DMA_TO_DEVICE);
3861 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3863 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3865 dma_unmap_single(ar->dev, paddr, skb->len,
3867 ieee80211_free_txskb(ar->hw, skb);
3870 ret = ath10k_wmi_mgmt_tx(ar, skb);
3872 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3874 ieee80211_free_txskb(ar->hw, skb);
3880 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3882 struct ath10k_txq *artxq;
3887 artxq = (void *)txq->drv_priv;
3888 INIT_LIST_HEAD(&artxq->list);
3891 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3893 struct ath10k_skb_cb *cb;
3894 struct sk_buff *msdu;
3900 spin_lock_bh(&ar->htt.tx_lock);
3901 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3902 cb = ATH10K_SKB_CB(msdu);
3906 spin_unlock_bh(&ar->htt.tx_lock);
3909 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3913 struct ath10k_peer *peer;
3915 lockdep_assert_held(&ar->data_lock);
3917 peer = ar->peer_map[peer_id];
3925 return peer->sta->txq[tid];
3927 return peer->vif->txq;
3932 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3933 struct ieee80211_txq *txq)
3935 struct ath10k *ar = hw->priv;
3936 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3938 /* No need to get locks */
3939 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3942 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3945 if (artxq->num_fw_queued < artxq->num_push_allowed)
3951 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3952 struct ieee80211_txq *txq)
3954 struct ath10k *ar = hw->priv;
3955 struct ath10k_htt *htt = &ar->htt;
3956 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3957 struct ieee80211_vif *vif = txq->vif;
3958 struct ieee80211_sta *sta = txq->sta;
3959 enum ath10k_hw_txrx_mode txmode;
3960 enum ath10k_mac_tx_path txpath;
3961 struct sk_buff *skb;
3962 struct ieee80211_hdr *hdr;
3964 bool is_mgmt, is_presp;
3967 spin_lock_bh(&ar->htt.tx_lock);
3968 ret = ath10k_htt_tx_inc_pending(htt);
3969 spin_unlock_bh(&ar->htt.tx_lock);
3974 skb = ieee80211_tx_dequeue(hw, txq);
3976 spin_lock_bh(&ar->htt.tx_lock);
3977 ath10k_htt_tx_dec_pending(htt);
3978 spin_unlock_bh(&ar->htt.tx_lock);
3983 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3986 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3987 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3988 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3991 hdr = (struct ieee80211_hdr *)skb->data;
3992 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3994 spin_lock_bh(&ar->htt.tx_lock);
3995 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3998 ath10k_htt_tx_dec_pending(htt);
3999 spin_unlock_bh(&ar->htt.tx_lock);
4002 spin_unlock_bh(&ar->htt.tx_lock);
4005 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4006 if (unlikely(ret)) {
4007 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4009 spin_lock_bh(&ar->htt.tx_lock);
4010 ath10k_htt_tx_dec_pending(htt);
4012 ath10k_htt_tx_mgmt_dec_pending(htt);
4013 spin_unlock_bh(&ar->htt.tx_lock);
4018 spin_lock_bh(&ar->htt.tx_lock);
4019 artxq->num_fw_queued++;
4020 spin_unlock_bh(&ar->htt.tx_lock);
4025 static int ath10k_mac_schedule_txq(struct ieee80211_hw *hw, u32 ac)
4027 struct ieee80211_txq *txq;
4030 ieee80211_txq_schedule_start(hw, ac);
4031 while ((txq = ieee80211_next_txq(hw, ac))) {
4032 while (ath10k_mac_tx_can_push(hw, txq)) {
4033 ret = ath10k_mac_tx_push_txq(hw, txq);
4037 ieee80211_return_txq(hw, txq);
4038 ath10k_htt_tx_txq_update(hw, txq);
4042 ieee80211_txq_schedule_end(hw, ac);
4047 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4049 struct ieee80211_hw *hw = ar->hw;
4052 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4055 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4059 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4060 if (ath10k_mac_schedule_txq(hw, ac) == -EBUSY)
4065 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4071 void __ath10k_scan_finish(struct ath10k *ar)
4073 lockdep_assert_held(&ar->data_lock);
4075 switch (ar->scan.state) {
4076 case ATH10K_SCAN_IDLE:
4078 case ATH10K_SCAN_RUNNING:
4079 case ATH10K_SCAN_ABORTING:
4080 if (!ar->scan.is_roc) {
4081 struct cfg80211_scan_info info = {
4082 .aborted = (ar->scan.state ==
4083 ATH10K_SCAN_ABORTING),
4086 ieee80211_scan_completed(ar->hw, &info);
4087 } else if (ar->scan.roc_notify) {
4088 ieee80211_remain_on_channel_expired(ar->hw);
4091 case ATH10K_SCAN_STARTING:
4092 ar->scan.state = ATH10K_SCAN_IDLE;
4093 ar->scan_channel = NULL;
4094 ar->scan.roc_freq = 0;
4095 ath10k_offchan_tx_purge(ar);
4096 cancel_delayed_work(&ar->scan.timeout);
4097 complete(&ar->scan.completed);
4102 void ath10k_scan_finish(struct ath10k *ar)
4104 spin_lock_bh(&ar->data_lock);
4105 __ath10k_scan_finish(ar);
4106 spin_unlock_bh(&ar->data_lock);
4109 static int ath10k_scan_stop(struct ath10k *ar)
4111 struct wmi_stop_scan_arg arg = {
4112 .req_id = 1, /* FIXME */
4113 .req_type = WMI_SCAN_STOP_ONE,
4114 .u.scan_id = ATH10K_SCAN_ID,
4118 lockdep_assert_held(&ar->conf_mutex);
4120 ret = ath10k_wmi_stop_scan(ar, &arg);
4122 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4126 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4128 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4130 } else if (ret > 0) {
4135 /* Scan state should be updated upon scan completion but in case
4136 * firmware fails to deliver the event (for whatever reason) it is
4137 * desired to clean up scan state anyway. Firmware may have just
4138 * dropped the scan completion event delivery due to transport pipe
4139 * being overflown with data and/or it can recover on its own before
4140 * next scan request is submitted.
4142 spin_lock_bh(&ar->data_lock);
4143 if (ar->scan.state != ATH10K_SCAN_IDLE)
4144 __ath10k_scan_finish(ar);
4145 spin_unlock_bh(&ar->data_lock);
4150 static void ath10k_scan_abort(struct ath10k *ar)
4154 lockdep_assert_held(&ar->conf_mutex);
4156 spin_lock_bh(&ar->data_lock);
4158 switch (ar->scan.state) {
4159 case ATH10K_SCAN_IDLE:
4160 /* This can happen if timeout worker kicked in and called
4161 * abortion while scan completion was being processed.
4164 case ATH10K_SCAN_STARTING:
4165 case ATH10K_SCAN_ABORTING:
4166 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4167 ath10k_scan_state_str(ar->scan.state),
4170 case ATH10K_SCAN_RUNNING:
4171 ar->scan.state = ATH10K_SCAN_ABORTING;
4172 spin_unlock_bh(&ar->data_lock);
4174 ret = ath10k_scan_stop(ar);
4176 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4178 spin_lock_bh(&ar->data_lock);
4182 spin_unlock_bh(&ar->data_lock);
4185 void ath10k_scan_timeout_work(struct work_struct *work)
4187 struct ath10k *ar = container_of(work, struct ath10k,
4190 mutex_lock(&ar->conf_mutex);
4191 ath10k_scan_abort(ar);
4192 mutex_unlock(&ar->conf_mutex);
4195 static int ath10k_start_scan(struct ath10k *ar,
4196 const struct wmi_start_scan_arg *arg)
4200 lockdep_assert_held(&ar->conf_mutex);
4202 ret = ath10k_wmi_start_scan(ar, arg);
4206 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4208 ret = ath10k_scan_stop(ar);
4210 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4215 /* If we failed to start the scan, return error code at
4216 * this point. This is probably due to some issue in the
4217 * firmware, but no need to wedge the driver due to that...
4219 spin_lock_bh(&ar->data_lock);
4220 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4221 spin_unlock_bh(&ar->data_lock);
4224 spin_unlock_bh(&ar->data_lock);
4229 /**********************/
4230 /* mac80211 callbacks */
4231 /**********************/
4233 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4234 struct ieee80211_tx_control *control,
4235 struct sk_buff *skb)
4237 struct ath10k *ar = hw->priv;
4238 struct ath10k_htt *htt = &ar->htt;
4239 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4240 struct ieee80211_vif *vif = info->control.vif;
4241 struct ieee80211_sta *sta = control->sta;
4242 struct ieee80211_txq *txq = NULL;
4243 struct ieee80211_hdr *hdr = (void *)skb->data;
4244 enum ath10k_hw_txrx_mode txmode;
4245 enum ath10k_mac_tx_path txpath;
4251 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4253 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4254 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4255 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4256 txpath == ATH10K_MAC_TX_HTT_MGMT);
4257 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4260 spin_lock_bh(&ar->htt.tx_lock);
4261 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4263 ret = ath10k_htt_tx_inc_pending(htt);
4265 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4267 spin_unlock_bh(&ar->htt.tx_lock);
4268 ieee80211_free_txskb(ar->hw, skb);
4272 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4274 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4276 ath10k_htt_tx_dec_pending(htt);
4277 spin_unlock_bh(&ar->htt.tx_lock);
4278 ieee80211_free_txskb(ar->hw, skb);
4281 spin_unlock_bh(&ar->htt.tx_lock);
4284 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4286 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4288 spin_lock_bh(&ar->htt.tx_lock);
4289 ath10k_htt_tx_dec_pending(htt);
4291 ath10k_htt_tx_mgmt_dec_pending(htt);
4292 spin_unlock_bh(&ar->htt.tx_lock);
4298 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4299 struct ieee80211_txq *txq)
4301 struct ath10k *ar = hw->priv;
4305 ath10k_htt_tx_txq_update(hw, txq);
4306 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4310 ieee80211_txq_schedule_start(hw, ac);
4311 txq = ieee80211_next_txq(hw, ac);
4315 while (ath10k_mac_tx_can_push(hw, txq)) {
4316 ret = ath10k_mac_tx_push_txq(hw, txq);
4320 ieee80211_return_txq(hw, txq);
4321 ath10k_htt_tx_txq_update(hw, txq);
4323 ieee80211_txq_schedule_end(hw, ac);
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 || (ar->ht_cap_info &
4539 WMI_HT_CAP_RX_LDPC && (ar->ht_cap_info & WMI_HT_CAP_TX_LDPC)))
4540 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4542 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4543 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4545 /* max AMSDU is implicitly taken from vht_cap_info */
4546 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4547 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4549 for (i = 0; i < ar->num_rf_chains; i++) {
4550 if (ar->cfg_rx_chainmask & BIT(i))
4551 ht_cap.mcs.rx_mask[i] = 0xFF;
4554 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4559 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4561 struct ieee80211_supported_band *band;
4562 struct ieee80211_sta_vht_cap vht_cap;
4563 struct ieee80211_sta_ht_cap ht_cap;
4565 ht_cap = ath10k_get_ht_cap(ar);
4566 vht_cap = ath10k_create_vht_cap(ar);
4568 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4569 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4570 band->ht_cap = ht_cap;
4572 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4573 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4574 band->ht_cap = ht_cap;
4575 band->vht_cap = vht_cap;
4579 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4583 lockdep_assert_held(&ar->conf_mutex);
4585 ath10k_check_chain_mask(ar, tx_ant, "tx");
4586 ath10k_check_chain_mask(ar, rx_ant, "rx");
4588 ar->cfg_tx_chainmask = tx_ant;
4589 ar->cfg_rx_chainmask = rx_ant;
4591 if ((ar->state != ATH10K_STATE_ON) &&
4592 (ar->state != ATH10K_STATE_RESTARTED))
4595 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4598 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4603 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4606 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4611 /* Reload HT/VHT capability */
4612 ath10k_mac_setup_ht_vht_cap(ar);
4617 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4619 struct ath10k *ar = hw->priv;
4622 mutex_lock(&ar->conf_mutex);
4623 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4624 mutex_unlock(&ar->conf_mutex);
4628 static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar,
4629 struct wmi_bb_timing_cfg_arg *bb_timing)
4631 struct device_node *node;
4632 const char *fem_name;
4635 node = ar->dev->of_node;
4639 ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name);
4644 * If external Front End module used in hardware, then default base band timing
4645 * parameter cannot be used since they were fine tuned for reference hardware,
4646 * so choosing different value suitable for that external FEM.
4648 if (!strcmp("microsemi-lx5586", fem_name)) {
4649 bb_timing->bb_tx_timing = 0x00;
4650 bb_timing->bb_xpa_timing = 0x0101;
4655 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
4656 bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing);
4660 static int ath10k_start(struct ieee80211_hw *hw)
4662 struct ath10k *ar = hw->priv;
4665 struct wmi_bb_timing_cfg_arg bb_timing = {0};
4668 * This makes sense only when restarting hw. It is harmless to call
4669 * unconditionally. This is necessary to make sure no HTT/WMI tx
4670 * commands will be submitted while restarting.
4672 ath10k_drain_tx(ar);
4674 mutex_lock(&ar->conf_mutex);
4676 switch (ar->state) {
4677 case ATH10K_STATE_OFF:
4678 ar->state = ATH10K_STATE_ON;
4680 case ATH10K_STATE_RESTARTING:
4681 ar->state = ATH10K_STATE_RESTARTED;
4683 case ATH10K_STATE_ON:
4684 case ATH10K_STATE_RESTARTED:
4685 case ATH10K_STATE_WEDGED:
4689 case ATH10K_STATE_UTF:
4694 ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
4696 ath10k_err(ar, "Could not init hif: %d\n", ret);
4700 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4701 &ar->normal_mode_fw);
4703 ath10k_err(ar, "Could not init core: %d\n", ret);
4704 goto err_power_down;
4707 param = ar->wmi.pdev_param->pmf_qos;
4708 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4710 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4714 param = ar->wmi.pdev_param->dynamic_bw;
4715 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4717 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4721 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
4722 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
4724 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
4729 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4730 ret = ath10k_wmi_adaptive_qcs(ar, true);
4732 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4738 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4739 param = ar->wmi.pdev_param->burst_enable;
4740 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4742 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4747 param = ar->wmi.pdev_param->idle_ps_config;
4748 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4749 if (ret && ret != -EOPNOTSUPP) {
4750 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4754 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4757 * By default FW set ARP frames ac to voice (6). In that case ARP
4758 * exchange is not working properly for UAPSD enabled AP. ARP requests
4759 * which arrives with access category 0 are processed by network stack
4760 * and send back with access category 0, but FW changes access category
4761 * to 6. Set ARP frames access category to best effort (0) solves
4765 param = ar->wmi.pdev_param->arp_ac_override;
4766 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4768 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4773 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4774 ar->running_fw->fw_file.fw_features)) {
4775 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4776 WMI_CCA_DETECT_LEVEL_AUTO,
4777 WMI_CCA_DETECT_MARGIN_AUTO);
4779 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4785 param = ar->wmi.pdev_param->ani_enable;
4786 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4788 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4793 ar->ani_enabled = true;
4795 if (ath10k_peer_stats_enabled(ar)) {
4796 param = ar->wmi.pdev_param->peer_stats_update_period;
4797 ret = ath10k_wmi_pdev_set_param(ar, param,
4798 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4801 "failed to set peer stats period : %d\n",
4807 param = ar->wmi.pdev_param->enable_btcoex;
4808 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4809 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4810 ar->running_fw->fw_file.fw_features)) {
4811 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4814 "failed to set btcoex param: %d\n", ret);
4817 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4820 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) {
4821 ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing);
4823 ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing);
4826 "failed to set bb timings: %d\n",
4833 ar->num_started_vdevs = 0;
4834 ath10k_regd_update(ar);
4836 ath10k_spectral_start(ar);
4837 ath10k_thermal_set_throttling(ar);
4839 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
4841 mutex_unlock(&ar->conf_mutex);
4845 ath10k_core_stop(ar);
4848 ath10k_hif_power_down(ar);
4851 ar->state = ATH10K_STATE_OFF;
4854 mutex_unlock(&ar->conf_mutex);
4858 static void ath10k_stop(struct ieee80211_hw *hw)
4860 struct ath10k *ar = hw->priv;
4862 ath10k_drain_tx(ar);
4864 mutex_lock(&ar->conf_mutex);
4865 if (ar->state != ATH10K_STATE_OFF) {
4867 ar->state = ATH10K_STATE_OFF;
4869 mutex_unlock(&ar->conf_mutex);
4871 cancel_work_sync(&ar->set_coverage_class_work);
4872 cancel_delayed_work_sync(&ar->scan.timeout);
4873 cancel_work_sync(&ar->restart_work);
4876 static int ath10k_config_ps(struct ath10k *ar)
4878 struct ath10k_vif *arvif;
4881 lockdep_assert_held(&ar->conf_mutex);
4883 list_for_each_entry(arvif, &ar->arvifs, list) {
4884 ret = ath10k_mac_vif_setup_ps(arvif);
4886 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4894 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4899 lockdep_assert_held(&ar->conf_mutex);
4901 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4903 param = ar->wmi.pdev_param->txpower_limit2g;
4904 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4906 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4911 param = ar->wmi.pdev_param->txpower_limit5g;
4912 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4914 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4922 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4924 struct ath10k_vif *arvif;
4925 int ret, txpower = -1;
4927 lockdep_assert_held(&ar->conf_mutex);
4929 list_for_each_entry(arvif, &ar->arvifs, list) {
4930 if (arvif->txpower <= 0)
4934 txpower = arvif->txpower;
4936 txpower = min(txpower, arvif->txpower);
4942 ret = ath10k_mac_txpower_setup(ar, txpower);
4944 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4952 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4954 struct ath10k *ar = hw->priv;
4955 struct ieee80211_conf *conf = &hw->conf;
4958 mutex_lock(&ar->conf_mutex);
4960 if (changed & IEEE80211_CONF_CHANGE_PS)
4961 ath10k_config_ps(ar);
4963 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4964 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4965 ret = ath10k_monitor_recalc(ar);
4967 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4970 mutex_unlock(&ar->conf_mutex);
4974 static u32 get_nss_from_chainmask(u16 chain_mask)
4976 if ((chain_mask & 0xf) == 0xf)
4978 else if ((chain_mask & 0x7) == 0x7)
4980 else if ((chain_mask & 0x3) == 0x3)
4985 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4988 struct ath10k *ar = arvif->ar;
4992 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4995 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4996 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4997 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4998 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
5000 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
5001 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5002 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
5003 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
5008 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
5009 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
5011 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
5012 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
5013 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
5015 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
5016 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
5018 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
5019 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
5020 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
5022 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5023 ar->wmi.vdev_param->txbf, value);
5028 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5029 * because we will send mgmt frames without CCK. This requirement
5030 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5033 static int ath10k_add_interface(struct ieee80211_hw *hw,
5034 struct ieee80211_vif *vif)
5036 struct ath10k *ar = hw->priv;
5037 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5038 struct ath10k_peer *peer;
5039 enum wmi_sta_powersave_param param;
5046 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5048 mutex_lock(&ar->conf_mutex);
5050 memset(arvif, 0, sizeof(*arvif));
5051 ath10k_mac_txq_init(vif->txq);
5056 INIT_LIST_HEAD(&arvif->list);
5057 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5058 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5059 ath10k_mac_vif_sta_connection_loss_work);
5061 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5062 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5063 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5064 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5065 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5066 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5069 if (ar->num_peers >= ar->max_num_peers) {
5070 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5075 if (ar->free_vdev_map == 0) {
5076 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5080 bit = __ffs64(ar->free_vdev_map);
5082 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5083 bit, ar->free_vdev_map);
5085 arvif->vdev_id = bit;
5086 arvif->vdev_subtype =
5087 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5089 switch (vif->type) {
5090 case NL80211_IFTYPE_P2P_DEVICE:
5091 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5092 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5093 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5095 case NL80211_IFTYPE_UNSPECIFIED:
5096 case NL80211_IFTYPE_STATION:
5097 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5099 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5100 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5102 case NL80211_IFTYPE_ADHOC:
5103 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5105 case NL80211_IFTYPE_MESH_POINT:
5106 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5107 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5108 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5109 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5111 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5114 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5116 case NL80211_IFTYPE_AP:
5117 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5120 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5121 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5123 case NL80211_IFTYPE_MONITOR:
5124 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5131 /* Using vdev_id as queue number will make it very easy to do per-vif
5132 * tx queue locking. This shouldn't wrap due to interface combinations
5133 * but do a modulo for correctness sake and prevent using offchannel tx
5134 * queues for regular vif tx.
5136 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5137 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5138 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5140 /* Some firmware revisions don't wait for beacon tx completion before
5141 * sending another SWBA event. This could lead to hardware using old
5142 * (freed) beacon data in some cases, e.g. tx credit starvation
5143 * combined with missed TBTT. This is very very rare.
5145 * On non-IOMMU-enabled hosts this could be a possible security issue
5146 * because hw could beacon some random data on the air. On
5147 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5148 * device would crash.
5150 * Since there are no beacon tx completions (implicit nor explicit)
5151 * propagated to host the only workaround for this is to allocate a
5152 * DMA-coherent buffer for a lifetime of a vif and use it for all
5153 * beacon tx commands. Worst case for this approach is some beacons may
5154 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5156 if (vif->type == NL80211_IFTYPE_ADHOC ||
5157 vif->type == NL80211_IFTYPE_MESH_POINT ||
5158 vif->type == NL80211_IFTYPE_AP) {
5159 arvif->beacon_buf = dma_alloc_coherent(ar->dev,
5160 IEEE80211_MAX_FRAME_LEN,
5161 &arvif->beacon_paddr,
5163 if (!arvif->beacon_buf) {
5165 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5170 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5171 arvif->nohwcrypt = true;
5173 if (arvif->nohwcrypt &&
5174 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5175 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5179 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5180 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5181 arvif->beacon_buf ? "single-buf" : "per-skb");
5183 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5184 arvif->vdev_subtype, vif->addr);
5186 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5187 arvif->vdev_id, ret);
5191 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT,
5193 vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn;
5194 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5195 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN);
5196 if (ret && ret != -EOPNOTSUPP) {
5197 ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n",
5198 arvif->vdev_id, ret);
5202 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5203 spin_lock_bh(&ar->data_lock);
5204 list_add(&arvif->list, &ar->arvifs);
5205 spin_unlock_bh(&ar->data_lock);
5207 /* It makes no sense to have firmware do keepalives. mac80211 already
5208 * takes care of this with idle connection polling.
5210 ret = ath10k_mac_vif_disable_keepalive(arvif);
5212 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5213 arvif->vdev_id, ret);
5214 goto err_vdev_delete;
5217 arvif->def_wep_key_idx = -1;
5219 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5220 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5221 ATH10K_HW_TXRX_NATIVE_WIFI);
5222 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5223 if (ret && ret != -EOPNOTSUPP) {
5224 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5225 arvif->vdev_id, ret);
5226 goto err_vdev_delete;
5229 /* Configuring number of spatial stream for monitor interface is causing
5230 * target assert in qca9888 and qca6174.
5232 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5233 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5235 vdev_param = ar->wmi.vdev_param->nss;
5236 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5239 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5240 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5242 goto err_vdev_delete;
5246 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5247 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5248 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5249 vif->addr, WMI_PEER_TYPE_DEFAULT);
5251 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5252 arvif->vdev_id, ret);
5253 goto err_vdev_delete;
5256 spin_lock_bh(&ar->data_lock);
5258 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5260 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5261 vif->addr, arvif->vdev_id);
5262 spin_unlock_bh(&ar->data_lock);
5264 goto err_peer_delete;
5267 arvif->peer_id = find_first_bit(peer->peer_ids,
5268 ATH10K_MAX_NUM_PEER_IDS);
5270 spin_unlock_bh(&ar->data_lock);
5272 arvif->peer_id = HTT_INVALID_PEERID;
5275 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5276 ret = ath10k_mac_set_kickout(arvif);
5278 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5279 arvif->vdev_id, ret);
5280 goto err_peer_delete;
5284 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5285 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5286 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5287 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5290 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5291 arvif->vdev_id, ret);
5292 goto err_peer_delete;
5295 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5297 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5298 arvif->vdev_id, ret);
5299 goto err_peer_delete;
5302 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5304 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5305 arvif->vdev_id, ret);
5306 goto err_peer_delete;
5310 ret = ath10k_mac_set_txbf_conf(arvif);
5312 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5313 arvif->vdev_id, ret);
5314 goto err_peer_delete;
5317 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5319 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5320 arvif->vdev_id, ret);
5321 goto err_peer_delete;
5324 arvif->txpower = vif->bss_conf.txpower;
5325 ret = ath10k_mac_txpower_recalc(ar);
5327 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5328 goto err_peer_delete;
5331 if (vif->type == NL80211_IFTYPE_MONITOR) {
5332 ar->monitor_arvif = arvif;
5333 ret = ath10k_monitor_recalc(ar);
5335 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5336 goto err_peer_delete;
5340 spin_lock_bh(&ar->htt.tx_lock);
5342 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5343 spin_unlock_bh(&ar->htt.tx_lock);
5345 mutex_unlock(&ar->conf_mutex);
5349 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5350 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5351 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5354 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5355 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5356 spin_lock_bh(&ar->data_lock);
5357 list_del(&arvif->list);
5358 spin_unlock_bh(&ar->data_lock);
5361 if (arvif->beacon_buf) {
5362 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5363 arvif->beacon_buf, arvif->beacon_paddr);
5364 arvif->beacon_buf = NULL;
5367 mutex_unlock(&ar->conf_mutex);
5372 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5376 for (i = 0; i < BITS_PER_LONG; i++)
5377 ath10k_mac_vif_tx_unlock(arvif, i);
5380 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5381 struct ieee80211_vif *vif)
5383 struct ath10k *ar = hw->priv;
5384 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5385 struct ath10k_peer *peer;
5389 cancel_work_sync(&arvif->ap_csa_work);
5390 cancel_delayed_work_sync(&arvif->connection_loss_work);
5392 mutex_lock(&ar->conf_mutex);
5394 spin_lock_bh(&ar->data_lock);
5395 ath10k_mac_vif_beacon_cleanup(arvif);
5396 spin_unlock_bh(&ar->data_lock);
5398 ret = ath10k_spectral_vif_stop(arvif);
5400 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5401 arvif->vdev_id, ret);
5403 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5404 spin_lock_bh(&ar->data_lock);
5405 list_del(&arvif->list);
5406 spin_unlock_bh(&ar->data_lock);
5408 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5409 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5410 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5413 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5414 arvif->vdev_id, ret);
5416 kfree(arvif->u.ap.noa_data);
5419 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5422 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5424 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5425 arvif->vdev_id, ret);
5427 /* Some firmware revisions don't notify host about self-peer removal
5428 * until after associated vdev is deleted.
5430 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5431 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5432 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5435 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5436 arvif->vdev_id, ret);
5438 spin_lock_bh(&ar->data_lock);
5440 spin_unlock_bh(&ar->data_lock);
5443 spin_lock_bh(&ar->data_lock);
5444 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5445 peer = ar->peer_map[i];
5449 if (peer->vif == vif) {
5450 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5451 vif->addr, arvif->vdev_id);
5455 spin_unlock_bh(&ar->data_lock);
5457 ath10k_peer_cleanup(ar, arvif->vdev_id);
5458 ath10k_mac_txq_unref(ar, vif->txq);
5460 if (vif->type == NL80211_IFTYPE_MONITOR) {
5461 ar->monitor_arvif = NULL;
5462 ret = ath10k_monitor_recalc(ar);
5464 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5467 ret = ath10k_mac_txpower_recalc(ar);
5469 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5471 spin_lock_bh(&ar->htt.tx_lock);
5472 ath10k_mac_vif_tx_unlock_all(arvif);
5473 spin_unlock_bh(&ar->htt.tx_lock);
5475 ath10k_mac_txq_unref(ar, vif->txq);
5477 mutex_unlock(&ar->conf_mutex);
5481 * FIXME: Has to be verified.
5483 #define SUPPORTED_FILTERS \
5488 FIF_BCN_PRBRESP_PROMISC | \
5492 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5493 unsigned int changed_flags,
5494 unsigned int *total_flags,
5497 struct ath10k *ar = hw->priv;
5500 mutex_lock(&ar->conf_mutex);
5502 changed_flags &= SUPPORTED_FILTERS;
5503 *total_flags &= SUPPORTED_FILTERS;
5504 ar->filter_flags = *total_flags;
5506 ret = ath10k_monitor_recalc(ar);
5508 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5510 mutex_unlock(&ar->conf_mutex);
5513 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5514 struct ieee80211_vif *vif,
5515 struct ieee80211_bss_conf *info,
5518 struct ath10k *ar = hw->priv;
5519 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5520 struct cfg80211_chan_def def;
5521 u32 vdev_param, pdev_param, slottime, preamble;
5522 u16 bitrate, hw_value;
5523 u8 rate, basic_rate_idx;
5524 int rateidx, ret = 0, hw_rate_code;
5525 enum nl80211_band band;
5526 const struct ieee80211_supported_band *sband;
5528 mutex_lock(&ar->conf_mutex);
5530 if (changed & BSS_CHANGED_IBSS)
5531 ath10k_control_ibss(arvif, info, vif->addr);
5533 if (changed & BSS_CHANGED_BEACON_INT) {
5534 arvif->beacon_interval = info->beacon_int;
5535 vdev_param = ar->wmi.vdev_param->beacon_interval;
5536 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5537 arvif->beacon_interval);
5538 ath10k_dbg(ar, ATH10K_DBG_MAC,
5539 "mac vdev %d beacon_interval %d\n",
5540 arvif->vdev_id, arvif->beacon_interval);
5543 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5544 arvif->vdev_id, ret);
5547 if (changed & BSS_CHANGED_BEACON) {
5548 ath10k_dbg(ar, ATH10K_DBG_MAC,
5549 "vdev %d set beacon tx mode to staggered\n",
5552 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5553 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5554 WMI_BEACON_STAGGERED_MODE);
5556 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5557 arvif->vdev_id, ret);
5559 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5561 ath10k_warn(ar, "failed to update beacon template: %d\n",
5564 if (ieee80211_vif_is_mesh(vif)) {
5565 /* mesh doesn't use SSID but firmware needs it */
5566 strncpy(arvif->u.ap.ssid, "mesh",
5567 sizeof(arvif->u.ap.ssid));
5568 arvif->u.ap.ssid_len = 4;
5572 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5573 ret = ath10k_mac_setup_prb_tmpl(arvif);
5575 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5576 arvif->vdev_id, ret);
5579 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5580 arvif->dtim_period = info->dtim_period;
5582 ath10k_dbg(ar, ATH10K_DBG_MAC,
5583 "mac vdev %d dtim_period %d\n",
5584 arvif->vdev_id, arvif->dtim_period);
5586 vdev_param = ar->wmi.vdev_param->dtim_period;
5587 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5588 arvif->dtim_period);
5590 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5591 arvif->vdev_id, ret);
5594 if (changed & BSS_CHANGED_SSID &&
5595 vif->type == NL80211_IFTYPE_AP) {
5596 arvif->u.ap.ssid_len = info->ssid_len;
5598 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5599 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5602 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5603 ether_addr_copy(arvif->bssid, info->bssid);
5605 if (changed & BSS_CHANGED_BEACON_ENABLED)
5606 ath10k_control_beaconing(arvif, info);
5608 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5609 arvif->use_cts_prot = info->use_cts_prot;
5611 ret = ath10k_recalc_rtscts_prot(arvif);
5613 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5614 arvif->vdev_id, ret);
5616 if (ath10k_mac_can_set_cts_prot(arvif)) {
5617 ret = ath10k_mac_set_cts_prot(arvif);
5619 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5620 arvif->vdev_id, ret);
5624 if (changed & BSS_CHANGED_ERP_SLOT) {
5625 if (info->use_short_slot)
5626 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5629 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5631 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5632 arvif->vdev_id, slottime);
5634 vdev_param = ar->wmi.vdev_param->slot_time;
5635 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5638 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5639 arvif->vdev_id, ret);
5642 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5643 if (info->use_short_preamble)
5644 preamble = WMI_VDEV_PREAMBLE_SHORT;
5646 preamble = WMI_VDEV_PREAMBLE_LONG;
5648 ath10k_dbg(ar, ATH10K_DBG_MAC,
5649 "mac vdev %d preamble %dn",
5650 arvif->vdev_id, preamble);
5652 vdev_param = ar->wmi.vdev_param->preamble;
5653 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5656 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5657 arvif->vdev_id, ret);
5660 if (changed & BSS_CHANGED_ASSOC) {
5662 /* Workaround: Make sure monitor vdev is not running
5663 * when associating to prevent some firmware revisions
5664 * (e.g. 10.1 and 10.2) from crashing.
5666 if (ar->monitor_started)
5667 ath10k_monitor_stop(ar);
5668 ath10k_bss_assoc(hw, vif, info);
5669 ath10k_monitor_recalc(ar);
5671 ath10k_bss_disassoc(hw, vif);
5675 if (changed & BSS_CHANGED_TXPOWER) {
5676 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5677 arvif->vdev_id, info->txpower);
5679 arvif->txpower = info->txpower;
5680 ret = ath10k_mac_txpower_recalc(ar);
5682 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5685 if (changed & BSS_CHANGED_PS) {
5686 arvif->ps = vif->bss_conf.ps;
5688 ret = ath10k_config_ps(ar);
5690 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5691 arvif->vdev_id, ret);
5694 if (changed & BSS_CHANGED_MCAST_RATE &&
5695 !WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def))) {
5696 band = def.chan->band;
5697 rateidx = vif->bss_conf.mcast_rate[band] - 1;
5699 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5700 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5702 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
5703 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
5704 if (ath10k_mac_bitrate_is_cck(bitrate))
5705 preamble = WMI_RATE_PREAMBLE_CCK;
5707 preamble = WMI_RATE_PREAMBLE_OFDM;
5709 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
5711 ath10k_dbg(ar, ATH10K_DBG_MAC,
5712 "mac vdev %d mcast_rate %x\n",
5713 arvif->vdev_id, rate);
5715 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5716 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5720 "failed to set mcast rate on vdev %i: %d\n",
5721 arvif->vdev_id, ret);
5723 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5724 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5728 "failed to set bcast rate on vdev %i: %d\n",
5729 arvif->vdev_id, ret);
5732 if (changed & BSS_CHANGED_BASIC_RATES) {
5733 if (WARN_ON(ath10k_mac_vif_chan(vif, &def))) {
5734 mutex_unlock(&ar->conf_mutex);
5738 sband = ar->hw->wiphy->bands[def.chan->band];
5739 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
5740 bitrate = sband->bitrates[basic_rate_idx].bitrate;
5742 hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
5743 if (hw_rate_code < 0) {
5744 ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
5745 mutex_unlock(&ar->conf_mutex);
5749 vdev_param = ar->wmi.vdev_param->mgmt_rate;
5750 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5753 ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
5756 mutex_unlock(&ar->conf_mutex);
5759 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5761 struct ath10k *ar = hw->priv;
5763 /* This function should never be called if setting the coverage class
5764 * is not supported on this hardware.
5766 if (!ar->hw_params.hw_ops->set_coverage_class) {
5770 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5773 struct ath10k_mac_tdls_iter_data {
5774 u32 num_tdls_stations;
5775 struct ieee80211_vif *curr_vif;
5778 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5779 struct ieee80211_sta *sta)
5781 struct ath10k_mac_tdls_iter_data *iter_data = data;
5782 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5783 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5785 if (sta->tdls && sta_vif == iter_data->curr_vif)
5786 iter_data->num_tdls_stations++;
5789 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5790 struct ieee80211_vif *vif)
5792 struct ath10k_mac_tdls_iter_data data = {};
5794 data.curr_vif = vif;
5796 ieee80211_iterate_stations_atomic(hw,
5797 ath10k_mac_tdls_vif_stations_count_iter,
5799 return data.num_tdls_stations;
5802 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5803 struct ieee80211_vif *vif,
5804 struct ieee80211_scan_request *hw_req)
5806 struct ath10k *ar = hw->priv;
5807 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5808 struct cfg80211_scan_request *req = &hw_req->req;
5809 struct wmi_start_scan_arg arg;
5814 mutex_lock(&ar->conf_mutex);
5816 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
5821 spin_lock_bh(&ar->data_lock);
5822 switch (ar->scan.state) {
5823 case ATH10K_SCAN_IDLE:
5824 reinit_completion(&ar->scan.started);
5825 reinit_completion(&ar->scan.completed);
5826 ar->scan.state = ATH10K_SCAN_STARTING;
5827 ar->scan.is_roc = false;
5828 ar->scan.vdev_id = arvif->vdev_id;
5831 case ATH10K_SCAN_STARTING:
5832 case ATH10K_SCAN_RUNNING:
5833 case ATH10K_SCAN_ABORTING:
5837 spin_unlock_bh(&ar->data_lock);
5842 memset(&arg, 0, sizeof(arg));
5843 ath10k_wmi_start_scan_init(ar, &arg);
5844 arg.vdev_id = arvif->vdev_id;
5845 arg.scan_id = ATH10K_SCAN_ID;
5848 arg.ie_len = req->ie_len;
5849 memcpy(arg.ie, req->ie, arg.ie_len);
5853 arg.n_ssids = req->n_ssids;
5854 for (i = 0; i < arg.n_ssids; i++) {
5855 arg.ssids[i].len = req->ssids[i].ssid_len;
5856 arg.ssids[i].ssid = req->ssids[i].ssid;
5859 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5862 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5863 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
5864 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
5865 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
5868 if (req->n_channels) {
5869 arg.n_channels = req->n_channels;
5870 for (i = 0; i < arg.n_channels; i++)
5871 arg.channels[i] = req->channels[i]->center_freq;
5874 /* if duration is set, default dwell times will be overwritten */
5875 if (req->duration) {
5876 arg.dwell_time_active = req->duration;
5877 arg.dwell_time_passive = req->duration;
5878 arg.burst_duration_ms = req->duration;
5880 scan_timeout = min_t(u32, arg.max_rest_time *
5881 (arg.n_channels - 1) + (req->duration +
5882 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
5883 arg.n_channels, arg.max_scan_time + 200);
5886 /* Add a 200ms margin to account for event/command processing */
5887 scan_timeout = arg.max_scan_time + 200;
5890 ret = ath10k_start_scan(ar, &arg);
5892 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5893 spin_lock_bh(&ar->data_lock);
5894 ar->scan.state = ATH10K_SCAN_IDLE;
5895 spin_unlock_bh(&ar->data_lock);
5898 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5899 msecs_to_jiffies(scan_timeout));
5902 mutex_unlock(&ar->conf_mutex);
5906 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5907 struct ieee80211_vif *vif)
5909 struct ath10k *ar = hw->priv;
5911 mutex_lock(&ar->conf_mutex);
5912 ath10k_scan_abort(ar);
5913 mutex_unlock(&ar->conf_mutex);
5915 cancel_delayed_work_sync(&ar->scan.timeout);
5918 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5919 struct ath10k_vif *arvif,
5920 enum set_key_cmd cmd,
5921 struct ieee80211_key_conf *key)
5923 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5926 /* 10.1 firmware branch requires default key index to be set to group
5927 * key index after installing it. Otherwise FW/HW Txes corrupted
5928 * frames with multi-vif APs. This is not required for main firmware
5929 * branch (e.g. 636).
5931 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5933 * FIXME: It remains unknown if this is required for multi-vif STA
5934 * interfaces on 10.1.
5937 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5938 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5941 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5944 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5947 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5953 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5956 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5957 arvif->vdev_id, ret);
5960 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5961 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5962 struct ieee80211_key_conf *key)
5964 struct ath10k *ar = hw->priv;
5965 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5966 struct ath10k_peer *peer;
5967 const u8 *peer_addr;
5968 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5969 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5975 /* this one needs to be done in software */
5976 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
5977 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
5978 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
5979 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
5982 if (arvif->nohwcrypt)
5985 if (key->keyidx > WMI_MAX_KEY_INDEX)
5988 mutex_lock(&ar->conf_mutex);
5991 peer_addr = sta->addr;
5992 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5993 peer_addr = vif->bss_conf.bssid;
5995 peer_addr = vif->addr;
5997 key->hw_key_idx = key->keyidx;
6001 arvif->wep_keys[key->keyidx] = key;
6003 arvif->wep_keys[key->keyidx] = NULL;
6006 /* the peer should not disappear in mid-way (unless FW goes awry) since
6007 * we already hold conf_mutex. we just make sure its there now.
6009 spin_lock_bh(&ar->data_lock);
6010 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6011 spin_unlock_bh(&ar->data_lock);
6014 if (cmd == SET_KEY) {
6015 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
6020 /* if the peer doesn't exist there is no key to disable anymore */
6025 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6026 flags |= WMI_KEY_PAIRWISE;
6028 flags |= WMI_KEY_GROUP;
6031 if (cmd == DISABLE_KEY)
6032 ath10k_clear_vdev_key(arvif, key);
6034 /* When WEP keys are uploaded it's possible that there are
6035 * stations associated already (e.g. when merging) without any
6036 * keys. Static WEP needs an explicit per-peer key upload.
6038 if (vif->type == NL80211_IFTYPE_ADHOC &&
6040 ath10k_mac_vif_update_wep_key(arvif, key);
6042 /* 802.1x never sets the def_wep_key_idx so each set_key()
6043 * call changes default tx key.
6045 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6046 * after first set_key().
6048 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
6049 flags |= WMI_KEY_TX_USAGE;
6052 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
6055 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
6056 arvif->vdev_id, peer_addr, ret);
6060 /* mac80211 sets static WEP keys as groupwise while firmware requires
6061 * them to be installed twice as both pairwise and groupwise.
6063 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6065 flags2 &= ~WMI_KEY_GROUP;
6066 flags2 |= WMI_KEY_PAIRWISE;
6068 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6071 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6072 arvif->vdev_id, peer_addr, ret);
6073 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6077 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6078 arvif->vdev_id, peer_addr, ret2);
6084 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6086 spin_lock_bh(&ar->data_lock);
6087 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6088 if (peer && cmd == SET_KEY)
6089 peer->keys[key->keyidx] = key;
6090 else if (peer && cmd == DISABLE_KEY)
6091 peer->keys[key->keyidx] = NULL;
6092 else if (peer == NULL)
6093 /* impossible unless FW goes crazy */
6094 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6095 spin_unlock_bh(&ar->data_lock);
6097 if (sta && sta->tdls)
6098 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6099 WMI_PEER_AUTHORIZE, 1);
6102 mutex_unlock(&ar->conf_mutex);
6106 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6107 struct ieee80211_vif *vif,
6110 struct ath10k *ar = hw->priv;
6111 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6114 mutex_lock(&arvif->ar->conf_mutex);
6116 if (arvif->ar->state != ATH10K_STATE_ON)
6119 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6120 arvif->vdev_id, keyidx);
6122 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6124 arvif->ar->wmi.vdev_param->def_keyid,
6128 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6134 arvif->def_wep_key_idx = keyidx;
6137 mutex_unlock(&arvif->ar->conf_mutex);
6140 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6143 struct ath10k_vif *arvif;
6144 struct ath10k_sta *arsta;
6145 struct ieee80211_sta *sta;
6146 struct cfg80211_chan_def def;
6147 enum nl80211_band band;
6148 const u8 *ht_mcs_mask;
6149 const u16 *vht_mcs_mask;
6150 u32 changed, bw, nss, smps;
6153 arsta = container_of(wk, struct ath10k_sta, update_wk);
6154 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6155 arvif = arsta->arvif;
6158 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6161 band = def.chan->band;
6162 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6163 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6165 spin_lock_bh(&ar->data_lock);
6167 changed = arsta->changed;
6174 spin_unlock_bh(&ar->data_lock);
6176 mutex_lock(&ar->conf_mutex);
6178 nss = max_t(u32, 1, nss);
6179 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6180 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6182 if (changed & IEEE80211_RC_BW_CHANGED) {
6183 enum wmi_phy_mode mode;
6185 mode = chan_to_phymode(&def);
6186 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
6187 sta->addr, bw, mode);
6189 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6190 WMI_PEER_PHYMODE, mode);
6192 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6193 sta->addr, mode, err);
6197 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6198 WMI_PEER_CHAN_WIDTH, bw);
6200 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6201 sta->addr, bw, err);
6204 if (changed & IEEE80211_RC_NSS_CHANGED) {
6205 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
6208 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6211 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6212 sta->addr, nss, err);
6215 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6216 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
6219 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6220 WMI_PEER_SMPS_STATE, smps);
6222 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6223 sta->addr, smps, err);
6226 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6227 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
6230 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6232 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6237 mutex_unlock(&ar->conf_mutex);
6240 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6241 struct ieee80211_sta *sta)
6243 struct ath10k *ar = arvif->ar;
6245 lockdep_assert_held(&ar->conf_mutex);
6247 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6250 if (ar->num_stations >= ar->max_num_stations)
6258 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6259 struct ieee80211_sta *sta)
6261 struct ath10k *ar = arvif->ar;
6263 lockdep_assert_held(&ar->conf_mutex);
6265 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6271 static int ath10k_sta_state(struct ieee80211_hw *hw,
6272 struct ieee80211_vif *vif,
6273 struct ieee80211_sta *sta,
6274 enum ieee80211_sta_state old_state,
6275 enum ieee80211_sta_state new_state)
6277 struct ath10k *ar = hw->priv;
6278 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6279 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6280 struct ath10k_peer *peer;
6284 if (old_state == IEEE80211_STA_NOTEXIST &&
6285 new_state == IEEE80211_STA_NONE) {
6286 memset(arsta, 0, sizeof(*arsta));
6287 arsta->arvif = arvif;
6288 arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
6289 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6291 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6292 ath10k_mac_txq_init(sta->txq[i]);
6295 /* cancel must be done outside the mutex to avoid deadlock */
6296 if ((old_state == IEEE80211_STA_NONE &&
6297 new_state == IEEE80211_STA_NOTEXIST))
6298 cancel_work_sync(&arsta->update_wk);
6300 mutex_lock(&ar->conf_mutex);
6302 if (old_state == IEEE80211_STA_NOTEXIST &&
6303 new_state == IEEE80211_STA_NONE) {
6305 * New station addition.
6307 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6308 u32 num_tdls_stations;
6310 ath10k_dbg(ar, ATH10K_DBG_MAC,
6311 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6312 arvif->vdev_id, sta->addr,
6313 ar->num_stations + 1, ar->max_num_stations,
6314 ar->num_peers + 1, ar->max_num_peers);
6316 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6319 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6320 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6322 ar->max_num_tdls_vdevs);
6326 peer_type = WMI_PEER_TYPE_TDLS;
6329 ret = ath10k_mac_inc_num_stations(arvif, sta);
6331 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6332 ar->max_num_stations);
6336 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6337 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats),
6339 if (!arsta->tx_stats) {
6345 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6346 sta->addr, peer_type);
6348 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6349 sta->addr, arvif->vdev_id, ret);
6350 ath10k_mac_dec_num_stations(arvif, sta);
6351 kfree(arsta->tx_stats);
6355 spin_lock_bh(&ar->data_lock);
6357 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6359 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6360 vif->addr, arvif->vdev_id);
6361 spin_unlock_bh(&ar->data_lock);
6362 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6363 ath10k_mac_dec_num_stations(arvif, sta);
6364 kfree(arsta->tx_stats);
6369 arsta->peer_id = find_first_bit(peer->peer_ids,
6370 ATH10K_MAX_NUM_PEER_IDS);
6372 spin_unlock_bh(&ar->data_lock);
6377 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6378 WMI_TDLS_ENABLE_ACTIVE);
6380 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6381 arvif->vdev_id, ret);
6382 ath10k_peer_delete(ar, arvif->vdev_id,
6384 ath10k_mac_dec_num_stations(arvif, sta);
6385 kfree(arsta->tx_stats);
6389 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6390 WMI_TDLS_PEER_STATE_PEERING);
6393 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6394 sta->addr, arvif->vdev_id, ret);
6395 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6396 ath10k_mac_dec_num_stations(arvif, sta);
6397 kfree(arsta->tx_stats);
6399 if (num_tdls_stations != 0)
6401 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6404 } else if ((old_state == IEEE80211_STA_NONE &&
6405 new_state == IEEE80211_STA_NOTEXIST)) {
6407 * Existing station deletion.
6409 ath10k_dbg(ar, ATH10K_DBG_MAC,
6410 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6411 arvif->vdev_id, sta->addr, sta);
6414 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6416 WMI_TDLS_PEER_STATE_TEARDOWN);
6418 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6420 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6423 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6425 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6426 sta->addr, arvif->vdev_id, ret);
6428 ath10k_mac_dec_num_stations(arvif, sta);
6430 spin_lock_bh(&ar->data_lock);
6431 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6432 peer = ar->peer_map[i];
6436 if (peer->sta == sta) {
6437 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6438 sta->addr, peer, i, arvif->vdev_id);
6441 /* Clean up the peer object as well since we
6442 * must have failed to do this above.
6444 list_del(&peer->list);
6445 ar->peer_map[i] = NULL;
6450 spin_unlock_bh(&ar->data_lock);
6452 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6453 kfree(arsta->tx_stats);
6454 arsta->tx_stats = NULL;
6457 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6458 ath10k_mac_txq_unref(ar, sta->txq[i]);
6463 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6466 /* This was the last tdls peer in current vif */
6467 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6470 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6471 arvif->vdev_id, ret);
6473 } else if (old_state == IEEE80211_STA_AUTH &&
6474 new_state == IEEE80211_STA_ASSOC &&
6475 (vif->type == NL80211_IFTYPE_AP ||
6476 vif->type == NL80211_IFTYPE_MESH_POINT ||
6477 vif->type == NL80211_IFTYPE_ADHOC)) {
6481 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6484 ret = ath10k_station_assoc(ar, vif, sta, false);
6486 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6487 sta->addr, arvif->vdev_id, ret);
6488 } else if (old_state == IEEE80211_STA_ASSOC &&
6489 new_state == IEEE80211_STA_AUTHORIZED &&
6492 * Tdls station authorized.
6494 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6497 ret = ath10k_station_assoc(ar, vif, sta, false);
6499 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6500 sta->addr, arvif->vdev_id, ret);
6504 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6505 WMI_TDLS_PEER_STATE_CONNECTED);
6507 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6508 sta->addr, arvif->vdev_id, ret);
6509 } else if (old_state == IEEE80211_STA_ASSOC &&
6510 new_state == IEEE80211_STA_AUTH &&
6511 (vif->type == NL80211_IFTYPE_AP ||
6512 vif->type == NL80211_IFTYPE_MESH_POINT ||
6513 vif->type == NL80211_IFTYPE_ADHOC)) {
6517 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6520 ret = ath10k_station_disassoc(ar, vif, sta);
6522 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6523 sta->addr, arvif->vdev_id, ret);
6526 mutex_unlock(&ar->conf_mutex);
6530 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6531 u16 ac, bool enable)
6533 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6534 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6535 u32 prio = 0, acc = 0;
6539 lockdep_assert_held(&ar->conf_mutex);
6541 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6545 case IEEE80211_AC_VO:
6546 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6547 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6551 case IEEE80211_AC_VI:
6552 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6553 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6557 case IEEE80211_AC_BE:
6558 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6559 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6563 case IEEE80211_AC_BK:
6564 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6565 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6572 arvif->u.sta.uapsd |= value;
6574 arvif->u.sta.uapsd &= ~value;
6576 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6577 WMI_STA_PS_PARAM_UAPSD,
6578 arvif->u.sta.uapsd);
6580 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6584 if (arvif->u.sta.uapsd)
6585 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6587 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6589 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6590 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6593 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6595 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6597 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6598 arvif->vdev_id, ret);
6602 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6604 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6605 arvif->vdev_id, ret);
6609 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6610 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6611 /* Only userspace can make an educated decision when to send
6612 * trigger frame. The following effectively disables u-UAPSD
6613 * autotrigger in firmware (which is enabled by default
6614 * provided the autotrigger service is available).
6618 arg.user_priority = prio;
6619 arg.service_interval = 0;
6620 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6621 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6623 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6624 arvif->bssid, &arg, 1);
6626 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6636 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6637 struct ieee80211_vif *vif, u16 ac,
6638 const struct ieee80211_tx_queue_params *params)
6640 struct ath10k *ar = hw->priv;
6641 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6642 struct wmi_wmm_params_arg *p = NULL;
6645 mutex_lock(&ar->conf_mutex);
6648 case IEEE80211_AC_VO:
6649 p = &arvif->wmm_params.ac_vo;
6651 case IEEE80211_AC_VI:
6652 p = &arvif->wmm_params.ac_vi;
6654 case IEEE80211_AC_BE:
6655 p = &arvif->wmm_params.ac_be;
6657 case IEEE80211_AC_BK:
6658 p = &arvif->wmm_params.ac_bk;
6667 p->cwmin = params->cw_min;
6668 p->cwmax = params->cw_max;
6669 p->aifs = params->aifs;
6672 * The channel time duration programmed in the HW is in absolute
6673 * microseconds, while mac80211 gives the txop in units of
6676 p->txop = params->txop * 32;
6678 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6679 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6680 &arvif->wmm_params);
6682 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6683 arvif->vdev_id, ret);
6687 /* This won't work well with multi-interface cases but it's
6688 * better than nothing.
6690 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6692 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6697 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6699 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6702 mutex_unlock(&ar->conf_mutex);
6706 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6708 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6709 struct ieee80211_vif *vif,
6710 struct ieee80211_channel *chan,
6712 enum ieee80211_roc_type type)
6714 struct ath10k *ar = hw->priv;
6715 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6716 struct wmi_start_scan_arg arg;
6720 mutex_lock(&ar->conf_mutex);
6722 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6727 spin_lock_bh(&ar->data_lock);
6728 switch (ar->scan.state) {
6729 case ATH10K_SCAN_IDLE:
6730 reinit_completion(&ar->scan.started);
6731 reinit_completion(&ar->scan.completed);
6732 reinit_completion(&ar->scan.on_channel);
6733 ar->scan.state = ATH10K_SCAN_STARTING;
6734 ar->scan.is_roc = true;
6735 ar->scan.vdev_id = arvif->vdev_id;
6736 ar->scan.roc_freq = chan->center_freq;
6737 ar->scan.roc_notify = true;
6740 case ATH10K_SCAN_STARTING:
6741 case ATH10K_SCAN_RUNNING:
6742 case ATH10K_SCAN_ABORTING:
6746 spin_unlock_bh(&ar->data_lock);
6751 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6753 memset(&arg, 0, sizeof(arg));
6754 ath10k_wmi_start_scan_init(ar, &arg);
6755 arg.vdev_id = arvif->vdev_id;
6756 arg.scan_id = ATH10K_SCAN_ID;
6758 arg.channels[0] = chan->center_freq;
6759 arg.dwell_time_active = scan_time_msec;
6760 arg.dwell_time_passive = scan_time_msec;
6761 arg.max_scan_time = scan_time_msec;
6762 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6763 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6764 arg.burst_duration_ms = duration;
6766 ret = ath10k_start_scan(ar, &arg);
6768 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6769 spin_lock_bh(&ar->data_lock);
6770 ar->scan.state = ATH10K_SCAN_IDLE;
6771 spin_unlock_bh(&ar->data_lock);
6775 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6777 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6779 ret = ath10k_scan_stop(ar);
6781 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6787 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6788 msecs_to_jiffies(duration));
6792 mutex_unlock(&ar->conf_mutex);
6796 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6798 struct ath10k *ar = hw->priv;
6800 mutex_lock(&ar->conf_mutex);
6802 spin_lock_bh(&ar->data_lock);
6803 ar->scan.roc_notify = false;
6804 spin_unlock_bh(&ar->data_lock);
6806 ath10k_scan_abort(ar);
6808 mutex_unlock(&ar->conf_mutex);
6810 cancel_delayed_work_sync(&ar->scan.timeout);
6816 * Both RTS and Fragmentation threshold are interface-specific
6817 * in ath10k, but device-specific in mac80211.
6820 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6822 struct ath10k *ar = hw->priv;
6823 struct ath10k_vif *arvif;
6826 mutex_lock(&ar->conf_mutex);
6827 list_for_each_entry(arvif, &ar->arvifs, list) {
6828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6829 arvif->vdev_id, value);
6831 ret = ath10k_mac_set_rts(arvif, value);
6833 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6834 arvif->vdev_id, ret);
6838 mutex_unlock(&ar->conf_mutex);
6843 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6845 /* Even though there's a WMI enum for fragmentation threshold no known
6846 * firmware actually implements it. Moreover it is not possible to rely
6847 * frame fragmentation to mac80211 because firmware clears the "more
6848 * fragments" bit in frame control making it impossible for remote
6849 * devices to reassemble frames.
6851 * Hence implement a dummy callback just to say fragmentation isn't
6852 * supported. This effectively prevents mac80211 from doing frame
6853 * fragmentation in software.
6858 void ath10k_mac_wait_tx_complete(struct ath10k *ar)
6863 /* mac80211 doesn't care if we really xmit queued frames or not
6864 * we'll collect those frames either way if we stop/delete vdevs
6867 if (ar->state == ATH10K_STATE_WEDGED)
6870 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6873 spin_lock_bh(&ar->htt.tx_lock);
6874 empty = (ar->htt.num_pending_tx == 0);
6875 spin_unlock_bh(&ar->htt.tx_lock);
6877 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6878 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6882 }), ATH10K_FLUSH_TIMEOUT_HZ);
6884 if (time_left == 0 || skip)
6885 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6886 skip, ar->state, time_left);
6889 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6890 u32 queues, bool drop)
6892 struct ath10k *ar = hw->priv;
6893 struct ath10k_vif *arvif;
6897 if (vif && vif->type == NL80211_IFTYPE_STATION) {
6898 bitmap = ~(1 << WMI_MGMT_TID);
6899 list_for_each_entry(arvif, &ar->arvifs, list) {
6900 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6901 ath10k_wmi_peer_flush(ar, arvif->vdev_id,
6902 arvif->bssid, bitmap);
6908 mutex_lock(&ar->conf_mutex);
6909 ath10k_mac_wait_tx_complete(ar);
6910 mutex_unlock(&ar->conf_mutex);
6913 /* TODO: Implement this function properly
6914 * For now it is needed to reply to Probe Requests in IBSS mode.
6915 * Propably we need this information from FW.
6917 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6922 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6923 enum ieee80211_reconfig_type reconfig_type)
6925 struct ath10k *ar = hw->priv;
6927 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6930 mutex_lock(&ar->conf_mutex);
6932 /* If device failed to restart it will be in a different state, e.g.
6933 * ATH10K_STATE_WEDGED
6935 if (ar->state == ATH10K_STATE_RESTARTED) {
6936 ath10k_info(ar, "device successfully recovered\n");
6937 ar->state = ATH10K_STATE_ON;
6938 ieee80211_wake_queues(ar->hw);
6941 mutex_unlock(&ar->conf_mutex);
6945 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6946 struct ieee80211_channel *channel)
6949 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6951 lockdep_assert_held(&ar->conf_mutex);
6953 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6954 (ar->rx_channel != channel))
6957 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6958 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6962 reinit_completion(&ar->bss_survey_done);
6964 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6966 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6970 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6972 ath10k_warn(ar, "bss channel survey timed out\n");
6977 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6978 struct survey_info *survey)
6980 struct ath10k *ar = hw->priv;
6981 struct ieee80211_supported_band *sband;
6982 struct survey_info *ar_survey = &ar->survey[idx];
6985 mutex_lock(&ar->conf_mutex);
6987 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6988 if (sband && idx >= sband->n_channels) {
6989 idx -= sband->n_channels;
6994 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6996 if (!sband || idx >= sband->n_channels) {
7001 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
7003 spin_lock_bh(&ar->data_lock);
7004 memcpy(survey, ar_survey, sizeof(*survey));
7005 spin_unlock_bh(&ar->data_lock);
7007 survey->channel = &sband->channels[idx];
7009 if (ar->rx_channel == survey->channel)
7010 survey->filled |= SURVEY_INFO_IN_USE;
7013 mutex_unlock(&ar->conf_mutex);
7018 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
7019 enum nl80211_band band,
7020 const struct cfg80211_bitrate_mask *mask)
7025 num_rates += hweight32(mask->control[band].legacy);
7027 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
7028 num_rates += hweight8(mask->control[band].ht_mcs[i]);
7030 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
7031 num_rates += hweight16(mask->control[band].vht_mcs[i]);
7033 return num_rates == 1;
7037 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
7038 enum nl80211_band band,
7039 const struct cfg80211_bitrate_mask *mask,
7042 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
7043 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7045 u8 vht_nss_mask = 0;
7048 if (mask->control[band].legacy)
7051 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7052 if (mask->control[band].ht_mcs[i] == 0)
7054 else if (mask->control[band].ht_mcs[i] ==
7055 sband->ht_cap.mcs.rx_mask[i])
7056 ht_nss_mask |= BIT(i);
7061 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7062 if (mask->control[band].vht_mcs[i] == 0)
7064 else if (mask->control[band].vht_mcs[i] ==
7065 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
7066 vht_nss_mask |= BIT(i);
7071 if (ht_nss_mask != vht_nss_mask)
7074 if (ht_nss_mask == 0)
7077 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
7080 *nss = fls(ht_nss_mask);
7086 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
7087 enum nl80211_band band,
7088 const struct cfg80211_bitrate_mask *mask,
7097 if (hweight32(mask->control[band].legacy) == 1) {
7098 rate_idx = ffs(mask->control[band].legacy) - 1;
7100 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
7101 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
7103 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
7104 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
7106 if (ath10k_mac_bitrate_is_cck(bitrate))
7107 preamble = WMI_RATE_PREAMBLE_CCK;
7109 preamble = WMI_RATE_PREAMBLE_OFDM;
7112 *rate = preamble << 6 |
7119 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7120 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
7122 *rate = WMI_RATE_PREAMBLE_HT << 6 |
7124 (ffs(mask->control[band].ht_mcs[i]) - 1);
7130 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7131 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
7133 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
7135 (ffs(mask->control[band].vht_mcs[i]) - 1);
7144 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
7145 u8 rate, u8 nss, u8 sgi, u8 ldpc)
7147 struct ath10k *ar = arvif->ar;
7151 lockdep_assert_held(&ar->conf_mutex);
7153 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7154 arvif->vdev_id, rate, nss, sgi);
7156 vdev_param = ar->wmi.vdev_param->fixed_rate;
7157 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
7159 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
7164 vdev_param = ar->wmi.vdev_param->nss;
7165 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
7167 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
7171 vdev_param = ar->wmi.vdev_param->sgi;
7172 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
7174 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
7178 vdev_param = ar->wmi.vdev_param->ldpc;
7179 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
7181 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
7189 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
7190 enum nl80211_band band,
7191 const struct cfg80211_bitrate_mask *mask)
7196 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7197 * to express all VHT MCS rate masks. Effectively only the following
7198 * ranges can be used: none, 0-7, 0-8 and 0-9.
7200 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7201 vht_mcs = mask->control[band].vht_mcs[i];
7210 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7218 static void ath10k_mac_set_bitrate_mask_iter(void *data,
7219 struct ieee80211_sta *sta)
7221 struct ath10k_vif *arvif = data;
7222 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7223 struct ath10k *ar = arvif->ar;
7225 if (arsta->arvif != arvif)
7228 spin_lock_bh(&ar->data_lock);
7229 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7230 spin_unlock_bh(&ar->data_lock);
7232 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7235 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7236 struct ieee80211_vif *vif,
7237 const struct cfg80211_bitrate_mask *mask)
7239 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7240 struct cfg80211_chan_def def;
7241 struct ath10k *ar = arvif->ar;
7242 enum nl80211_band band;
7243 const u8 *ht_mcs_mask;
7244 const u16 *vht_mcs_mask;
7252 if (ath10k_mac_vif_chan(vif, &def))
7255 band = def.chan->band;
7256 ht_mcs_mask = mask->control[band].ht_mcs;
7257 vht_mcs_mask = mask->control[band].vht_mcs;
7258 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7260 sgi = mask->control[band].gi;
7261 if (sgi == NL80211_TXRATE_FORCE_LGI)
7264 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7265 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7268 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7269 arvif->vdev_id, ret);
7272 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7274 rate = WMI_FIXED_RATE_NONE;
7277 rate = WMI_FIXED_RATE_NONE;
7278 nss = min(ar->num_rf_chains,
7279 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7280 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7282 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7285 mutex_lock(&ar->conf_mutex);
7287 arvif->bitrate_mask = *mask;
7288 ieee80211_iterate_stations_atomic(ar->hw,
7289 ath10k_mac_set_bitrate_mask_iter,
7292 mutex_unlock(&ar->conf_mutex);
7295 mutex_lock(&ar->conf_mutex);
7297 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7299 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7300 arvif->vdev_id, ret);
7305 mutex_unlock(&ar->conf_mutex);
7310 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7311 struct ieee80211_vif *vif,
7312 struct ieee80211_sta *sta,
7315 struct ath10k *ar = hw->priv;
7316 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7317 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7318 struct ath10k_peer *peer;
7321 spin_lock_bh(&ar->data_lock);
7323 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7325 spin_unlock_bh(&ar->data_lock);
7326 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7327 sta->addr, arvif->vdev_id);
7331 ath10k_dbg(ar, ATH10K_DBG_MAC,
7332 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7333 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7336 if (changed & IEEE80211_RC_BW_CHANGED) {
7337 bw = WMI_PEER_CHWIDTH_20MHZ;
7339 switch (sta->bandwidth) {
7340 case IEEE80211_STA_RX_BW_20:
7341 bw = WMI_PEER_CHWIDTH_20MHZ;
7343 case IEEE80211_STA_RX_BW_40:
7344 bw = WMI_PEER_CHWIDTH_40MHZ;
7346 case IEEE80211_STA_RX_BW_80:
7347 bw = WMI_PEER_CHWIDTH_80MHZ;
7349 case IEEE80211_STA_RX_BW_160:
7350 bw = WMI_PEER_CHWIDTH_160MHZ;
7353 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7354 sta->bandwidth, sta->addr);
7355 bw = WMI_PEER_CHWIDTH_20MHZ;
7362 if (changed & IEEE80211_RC_NSS_CHANGED)
7363 arsta->nss = sta->rx_nss;
7365 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7366 smps = WMI_PEER_SMPS_PS_NONE;
7368 switch (sta->smps_mode) {
7369 case IEEE80211_SMPS_AUTOMATIC:
7370 case IEEE80211_SMPS_OFF:
7371 smps = WMI_PEER_SMPS_PS_NONE;
7373 case IEEE80211_SMPS_STATIC:
7374 smps = WMI_PEER_SMPS_STATIC;
7376 case IEEE80211_SMPS_DYNAMIC:
7377 smps = WMI_PEER_SMPS_DYNAMIC;
7379 case IEEE80211_SMPS_NUM_MODES:
7380 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7381 sta->smps_mode, sta->addr);
7382 smps = WMI_PEER_SMPS_PS_NONE;
7389 arsta->changed |= changed;
7391 spin_unlock_bh(&ar->data_lock);
7393 ieee80211_queue_work(hw, &arsta->update_wk);
7396 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7397 struct ieee80211_vif *vif, s64 tsf_offset)
7399 struct ath10k *ar = hw->priv;
7400 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7401 u32 offset, vdev_param;
7404 if (tsf_offset < 0) {
7405 vdev_param = ar->wmi.vdev_param->dec_tsf;
7406 offset = -tsf_offset;
7408 vdev_param = ar->wmi.vdev_param->inc_tsf;
7409 offset = tsf_offset;
7412 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7413 vdev_param, offset);
7415 if (ret && ret != -EOPNOTSUPP)
7416 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7417 offset, vdev_param, ret);
7420 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7421 struct ieee80211_vif *vif,
7422 struct ieee80211_ampdu_params *params)
7424 struct ath10k *ar = hw->priv;
7425 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7426 struct ieee80211_sta *sta = params->sta;
7427 enum ieee80211_ampdu_mlme_action action = params->action;
7428 u16 tid = params->tid;
7430 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7431 arvif->vdev_id, sta->addr, tid, action);
7434 case IEEE80211_AMPDU_RX_START:
7435 case IEEE80211_AMPDU_RX_STOP:
7436 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7437 * creation/removal. Do we need to verify this?
7440 case IEEE80211_AMPDU_TX_START:
7441 case IEEE80211_AMPDU_TX_STOP_CONT:
7442 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7443 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7444 case IEEE80211_AMPDU_TX_OPERATIONAL:
7445 /* Firmware offloads Tx aggregation entirely so deny mac80211
7446 * Tx aggregation requests.
7455 ath10k_mac_update_rx_channel(struct ath10k *ar,
7456 struct ieee80211_chanctx_conf *ctx,
7457 struct ieee80211_vif_chanctx_switch *vifs,
7460 struct cfg80211_chan_def *def = NULL;
7462 /* Both locks are required because ar->rx_channel is modified. This
7463 * allows readers to hold either lock.
7465 lockdep_assert_held(&ar->conf_mutex);
7466 lockdep_assert_held(&ar->data_lock);
7468 WARN_ON(ctx && vifs);
7469 WARN_ON(vifs && !n_vifs);
7471 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7472 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7473 * ppdu on Rx may reduce performance on low-end systems. It should be
7474 * possible to make tables/hashmaps to speed the lookup up (be vary of
7475 * cpu data cache lines though regarding sizes) but to keep the initial
7476 * implementation simple and less intrusive fallback to the slow lookup
7477 * only for multi-channel cases. Single-channel cases will remain to
7478 * use the old channel derival and thus performance should not be
7482 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7483 ieee80211_iter_chan_contexts_atomic(ar->hw,
7484 ath10k_mac_get_any_chandef_iter,
7488 def = &vifs[0].new_ctx->def;
7490 ar->rx_channel = def->chan;
7491 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7492 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7493 /* During driver restart due to firmware assert, since mac80211
7494 * already has valid channel context for given radio, channel
7495 * context iteration return num_chanctx > 0. So fix rx_channel
7496 * when restart is in progress.
7498 ar->rx_channel = ctx->def.chan;
7500 ar->rx_channel = NULL;
7506 ath10k_mac_update_vif_chan(struct ath10k *ar,
7507 struct ieee80211_vif_chanctx_switch *vifs,
7510 struct ath10k_vif *arvif;
7514 lockdep_assert_held(&ar->conf_mutex);
7516 /* First stop monitor interface. Some FW versions crash if there's a
7517 * lone monitor interface.
7519 if (ar->monitor_started)
7520 ath10k_monitor_stop(ar);
7522 for (i = 0; i < n_vifs; i++) {
7523 arvif = (void *)vifs[i].vif->drv_priv;
7525 ath10k_dbg(ar, ATH10K_DBG_MAC,
7526 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7528 vifs[i].old_ctx->def.chan->center_freq,
7529 vifs[i].new_ctx->def.chan->center_freq,
7530 vifs[i].old_ctx->def.width,
7531 vifs[i].new_ctx->def.width);
7533 if (WARN_ON(!arvif->is_started))
7536 if (WARN_ON(!arvif->is_up))
7539 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7541 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7542 arvif->vdev_id, ret);
7547 /* All relevant vdevs are downed and associated channel resources
7548 * should be available for the channel switch now.
7551 spin_lock_bh(&ar->data_lock);
7552 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7553 spin_unlock_bh(&ar->data_lock);
7555 for (i = 0; i < n_vifs; i++) {
7556 arvif = (void *)vifs[i].vif->drv_priv;
7558 if (WARN_ON(!arvif->is_started))
7561 if (WARN_ON(!arvif->is_up))
7564 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7566 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7569 ret = ath10k_mac_setup_prb_tmpl(arvif);
7571 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7574 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7576 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7577 arvif->vdev_id, ret);
7581 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7584 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7585 arvif->vdev_id, ret);
7590 ath10k_monitor_recalc(ar);
7594 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7595 struct ieee80211_chanctx_conf *ctx)
7597 struct ath10k *ar = hw->priv;
7599 ath10k_dbg(ar, ATH10K_DBG_MAC,
7600 "mac chanctx add freq %hu width %d ptr %pK\n",
7601 ctx->def.chan->center_freq, ctx->def.width, ctx);
7603 mutex_lock(&ar->conf_mutex);
7605 spin_lock_bh(&ar->data_lock);
7606 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7607 spin_unlock_bh(&ar->data_lock);
7609 ath10k_recalc_radar_detection(ar);
7610 ath10k_monitor_recalc(ar);
7612 mutex_unlock(&ar->conf_mutex);
7618 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7619 struct ieee80211_chanctx_conf *ctx)
7621 struct ath10k *ar = hw->priv;
7623 ath10k_dbg(ar, ATH10K_DBG_MAC,
7624 "mac chanctx remove freq %hu width %d ptr %pK\n",
7625 ctx->def.chan->center_freq, ctx->def.width, ctx);
7627 mutex_lock(&ar->conf_mutex);
7629 spin_lock_bh(&ar->data_lock);
7630 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7631 spin_unlock_bh(&ar->data_lock);
7633 ath10k_recalc_radar_detection(ar);
7634 ath10k_monitor_recalc(ar);
7636 mutex_unlock(&ar->conf_mutex);
7639 struct ath10k_mac_change_chanctx_arg {
7640 struct ieee80211_chanctx_conf *ctx;
7641 struct ieee80211_vif_chanctx_switch *vifs;
7647 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7648 struct ieee80211_vif *vif)
7650 struct ath10k_mac_change_chanctx_arg *arg = data;
7652 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7659 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7660 struct ieee80211_vif *vif)
7662 struct ath10k_mac_change_chanctx_arg *arg = data;
7663 struct ieee80211_chanctx_conf *ctx;
7665 ctx = rcu_access_pointer(vif->chanctx_conf);
7666 if (ctx != arg->ctx)
7669 if (WARN_ON(arg->next_vif == arg->n_vifs))
7672 arg->vifs[arg->next_vif].vif = vif;
7673 arg->vifs[arg->next_vif].old_ctx = ctx;
7674 arg->vifs[arg->next_vif].new_ctx = ctx;
7679 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7680 struct ieee80211_chanctx_conf *ctx,
7683 struct ath10k *ar = hw->priv;
7684 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7686 mutex_lock(&ar->conf_mutex);
7688 ath10k_dbg(ar, ATH10K_DBG_MAC,
7689 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7690 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7692 /* This shouldn't really happen because channel switching should use
7693 * switch_vif_chanctx().
7695 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7698 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7699 ieee80211_iterate_active_interfaces_atomic(
7701 IEEE80211_IFACE_ITER_NORMAL,
7702 ath10k_mac_change_chanctx_cnt_iter,
7704 if (arg.n_vifs == 0)
7707 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7712 ieee80211_iterate_active_interfaces_atomic(
7714 IEEE80211_IFACE_ITER_NORMAL,
7715 ath10k_mac_change_chanctx_fill_iter,
7717 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7722 ath10k_recalc_radar_detection(ar);
7724 /* FIXME: How to configure Rx chains properly? */
7726 /* No other actions are actually necessary. Firmware maintains channel
7727 * definitions per vdev internally and there's no host-side channel
7728 * context abstraction to configure, e.g. channel width.
7732 mutex_unlock(&ar->conf_mutex);
7736 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7737 struct ieee80211_vif *vif,
7738 struct ieee80211_chanctx_conf *ctx)
7740 struct ath10k *ar = hw->priv;
7741 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7744 mutex_lock(&ar->conf_mutex);
7746 ath10k_dbg(ar, ATH10K_DBG_MAC,
7747 "mac chanctx assign ptr %pK vdev_id %i\n",
7748 ctx, arvif->vdev_id);
7750 if (WARN_ON(arvif->is_started)) {
7751 mutex_unlock(&ar->conf_mutex);
7755 ret = ath10k_vdev_start(arvif, &ctx->def);
7757 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7758 arvif->vdev_id, vif->addr,
7759 ctx->def.chan->center_freq, ret);
7763 arvif->is_started = true;
7765 ret = ath10k_mac_vif_setup_ps(arvif);
7767 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7768 arvif->vdev_id, ret);
7772 if (vif->type == NL80211_IFTYPE_MONITOR) {
7773 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7775 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7776 arvif->vdev_id, ret);
7780 arvif->is_up = true;
7783 if (ath10k_mac_can_set_cts_prot(arvif)) {
7784 ret = ath10k_mac_set_cts_prot(arvif);
7786 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7787 arvif->vdev_id, ret);
7790 if (ath10k_peer_stats_enabled(ar)) {
7791 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
7792 ret = ath10k_wmi_pdev_pktlog_enable(ar,
7795 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
7800 mutex_unlock(&ar->conf_mutex);
7804 ath10k_vdev_stop(arvif);
7805 arvif->is_started = false;
7806 ath10k_mac_vif_setup_ps(arvif);
7809 mutex_unlock(&ar->conf_mutex);
7814 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7815 struct ieee80211_vif *vif,
7816 struct ieee80211_chanctx_conf *ctx)
7818 struct ath10k *ar = hw->priv;
7819 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7822 mutex_lock(&ar->conf_mutex);
7824 ath10k_dbg(ar, ATH10K_DBG_MAC,
7825 "mac chanctx unassign ptr %pK vdev_id %i\n",
7826 ctx, arvif->vdev_id);
7828 WARN_ON(!arvif->is_started);
7830 if (vif->type == NL80211_IFTYPE_MONITOR) {
7831 WARN_ON(!arvif->is_up);
7833 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7835 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7836 arvif->vdev_id, ret);
7838 arvif->is_up = false;
7841 ret = ath10k_vdev_stop(arvif);
7843 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7844 arvif->vdev_id, ret);
7846 arvif->is_started = false;
7848 mutex_unlock(&ar->conf_mutex);
7852 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7853 struct ieee80211_vif_chanctx_switch *vifs,
7855 enum ieee80211_chanctx_switch_mode mode)
7857 struct ath10k *ar = hw->priv;
7859 mutex_lock(&ar->conf_mutex);
7861 ath10k_dbg(ar, ATH10K_DBG_MAC,
7862 "mac chanctx switch n_vifs %d mode %d\n",
7864 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7866 mutex_unlock(&ar->conf_mutex);
7870 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7871 struct ieee80211_vif *vif,
7872 struct ieee80211_sta *sta)
7875 struct ath10k_peer *peer;
7879 list_for_each_entry(peer, &ar->peers, list)
7880 if (peer->sta == sta)
7881 peer->removed = true;
7884 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
7885 struct ieee80211_vif *vif,
7886 struct ieee80211_sta *sta,
7887 struct station_info *sinfo)
7889 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7890 struct ath10k *ar = arsta->arvif->ar;
7892 if (!ath10k_peer_stats_enabled(ar))
7895 sinfo->rx_duration = arsta->rx_duration;
7896 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
7898 if (!arsta->txrate.legacy && !arsta->txrate.nss)
7901 if (arsta->txrate.legacy) {
7902 sinfo->txrate.legacy = arsta->txrate.legacy;
7904 sinfo->txrate.mcs = arsta->txrate.mcs;
7905 sinfo->txrate.nss = arsta->txrate.nss;
7906 sinfo->txrate.bw = arsta->txrate.bw;
7908 sinfo->txrate.flags = arsta->txrate.flags;
7909 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
7912 static const struct ieee80211_ops ath10k_ops = {
7913 .tx = ath10k_mac_op_tx,
7914 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7915 .start = ath10k_start,
7916 .stop = ath10k_stop,
7917 .config = ath10k_config,
7918 .add_interface = ath10k_add_interface,
7919 .remove_interface = ath10k_remove_interface,
7920 .configure_filter = ath10k_configure_filter,
7921 .bss_info_changed = ath10k_bss_info_changed,
7922 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7923 .hw_scan = ath10k_hw_scan,
7924 .cancel_hw_scan = ath10k_cancel_hw_scan,
7925 .set_key = ath10k_set_key,
7926 .set_default_unicast_key = ath10k_set_default_unicast_key,
7927 .sta_state = ath10k_sta_state,
7928 .conf_tx = ath10k_conf_tx,
7929 .remain_on_channel = ath10k_remain_on_channel,
7930 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7931 .set_rts_threshold = ath10k_set_rts_threshold,
7932 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7933 .flush = ath10k_flush,
7934 .tx_last_beacon = ath10k_tx_last_beacon,
7935 .set_antenna = ath10k_set_antenna,
7936 .get_antenna = ath10k_get_antenna,
7937 .reconfig_complete = ath10k_reconfig_complete,
7938 .get_survey = ath10k_get_survey,
7939 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7940 .sta_rc_update = ath10k_sta_rc_update,
7941 .offset_tsf = ath10k_offset_tsf,
7942 .ampdu_action = ath10k_ampdu_action,
7943 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7944 .get_et_stats = ath10k_debug_get_et_stats,
7945 .get_et_strings = ath10k_debug_get_et_strings,
7946 .add_chanctx = ath10k_mac_op_add_chanctx,
7947 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7948 .change_chanctx = ath10k_mac_op_change_chanctx,
7949 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7950 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7951 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7952 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7953 .sta_statistics = ath10k_sta_statistics,
7955 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7958 .suspend = ath10k_wow_op_suspend,
7959 .resume = ath10k_wow_op_resume,
7960 .set_wakeup = ath10k_wow_op_set_wakeup,
7962 #ifdef CONFIG_MAC80211_DEBUGFS
7963 .sta_add_debugfs = ath10k_sta_add_debugfs,
7967 #define CHAN2G(_channel, _freq, _flags) { \
7968 .band = NL80211_BAND_2GHZ, \
7969 .hw_value = (_channel), \
7970 .center_freq = (_freq), \
7971 .flags = (_flags), \
7972 .max_antenna_gain = 0, \
7976 #define CHAN5G(_channel, _freq, _flags) { \
7977 .band = NL80211_BAND_5GHZ, \
7978 .hw_value = (_channel), \
7979 .center_freq = (_freq), \
7980 .flags = (_flags), \
7981 .max_antenna_gain = 0, \
7985 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7995 CHAN2G(10, 2457, 0),
7996 CHAN2G(11, 2462, 0),
7997 CHAN2G(12, 2467, 0),
7998 CHAN2G(13, 2472, 0),
7999 CHAN2G(14, 2484, 0),
8002 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
8003 CHAN5G(36, 5180, 0),
8004 CHAN5G(40, 5200, 0),
8005 CHAN5G(44, 5220, 0),
8006 CHAN5G(48, 5240, 0),
8007 CHAN5G(52, 5260, 0),
8008 CHAN5G(56, 5280, 0),
8009 CHAN5G(60, 5300, 0),
8010 CHAN5G(64, 5320, 0),
8011 CHAN5G(100, 5500, 0),
8012 CHAN5G(104, 5520, 0),
8013 CHAN5G(108, 5540, 0),
8014 CHAN5G(112, 5560, 0),
8015 CHAN5G(116, 5580, 0),
8016 CHAN5G(120, 5600, 0),
8017 CHAN5G(124, 5620, 0),
8018 CHAN5G(128, 5640, 0),
8019 CHAN5G(132, 5660, 0),
8020 CHAN5G(136, 5680, 0),
8021 CHAN5G(140, 5700, 0),
8022 CHAN5G(144, 5720, 0),
8023 CHAN5G(149, 5745, 0),
8024 CHAN5G(153, 5765, 0),
8025 CHAN5G(157, 5785, 0),
8026 CHAN5G(161, 5805, 0),
8027 CHAN5G(165, 5825, 0),
8028 CHAN5G(169, 5845, 0),
8029 CHAN5G(173, 5865, 0),
8030 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
8031 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
8034 struct ath10k *ath10k_mac_create(size_t priv_size)
8036 struct ieee80211_hw *hw;
8037 struct ieee80211_ops *ops;
8040 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
8044 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
8057 void ath10k_mac_destroy(struct ath10k *ar)
8059 struct ieee80211_ops *ops = ar->ops;
8061 ieee80211_free_hw(ar->hw);
8065 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
8068 .types = BIT(NL80211_IFTYPE_STATION)
8069 | BIT(NL80211_IFTYPE_P2P_CLIENT)
8073 .types = BIT(NL80211_IFTYPE_P2P_GO)
8077 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
8081 .types = BIT(NL80211_IFTYPE_AP)
8082 #ifdef CONFIG_MAC80211_MESH
8083 | BIT(NL80211_IFTYPE_MESH_POINT)
8088 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
8091 .types = BIT(NL80211_IFTYPE_AP)
8092 #ifdef CONFIG_MAC80211_MESH
8093 | BIT(NL80211_IFTYPE_MESH_POINT)
8098 .types = BIT(NL80211_IFTYPE_STATION)
8102 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
8104 .limits = ath10k_if_limits,
8105 .n_limits = ARRAY_SIZE(ath10k_if_limits),
8106 .max_interfaces = 8,
8107 .num_different_channels = 1,
8108 .beacon_int_infra_match = true,
8112 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
8114 .limits = ath10k_10x_if_limits,
8115 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
8116 .max_interfaces = 8,
8117 .num_different_channels = 1,
8118 .beacon_int_infra_match = true,
8119 .beacon_int_min_gcd = 1,
8120 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8121 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8122 BIT(NL80211_CHAN_WIDTH_20) |
8123 BIT(NL80211_CHAN_WIDTH_40) |
8124 BIT(NL80211_CHAN_WIDTH_80),
8129 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
8132 .types = BIT(NL80211_IFTYPE_STATION),
8136 .types = BIT(NL80211_IFTYPE_AP) |
8137 #ifdef CONFIG_MAC80211_MESH
8138 BIT(NL80211_IFTYPE_MESH_POINT) |
8140 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8141 BIT(NL80211_IFTYPE_P2P_GO),
8145 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8149 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
8152 .types = BIT(NL80211_IFTYPE_STATION),
8156 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
8160 .types = BIT(NL80211_IFTYPE_AP) |
8161 #ifdef CONFIG_MAC80211_MESH
8162 BIT(NL80211_IFTYPE_MESH_POINT) |
8164 BIT(NL80211_IFTYPE_P2P_GO),
8168 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8172 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
8175 .types = BIT(NL80211_IFTYPE_STATION),
8179 .types = BIT(NL80211_IFTYPE_ADHOC),
8183 /* FIXME: This is not thouroughly tested. These combinations may over- or
8184 * underestimate hw/fw capabilities.
8186 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
8188 .limits = ath10k_tlv_if_limit,
8189 .num_different_channels = 1,
8190 .max_interfaces = 4,
8191 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8194 .limits = ath10k_tlv_if_limit_ibss,
8195 .num_different_channels = 1,
8196 .max_interfaces = 2,
8197 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8201 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
8203 .limits = ath10k_tlv_if_limit,
8204 .num_different_channels = 1,
8205 .max_interfaces = 4,
8206 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8209 .limits = ath10k_tlv_qcs_if_limit,
8210 .num_different_channels = 2,
8211 .max_interfaces = 4,
8212 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
8215 .limits = ath10k_tlv_if_limit_ibss,
8216 .num_different_channels = 1,
8217 .max_interfaces = 2,
8218 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8222 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8225 .types = BIT(NL80211_IFTYPE_STATION),
8229 .types = BIT(NL80211_IFTYPE_AP)
8230 #ifdef CONFIG_MAC80211_MESH
8231 | BIT(NL80211_IFTYPE_MESH_POINT)
8236 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8238 .limits = ath10k_10_4_if_limits,
8239 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8240 .max_interfaces = 16,
8241 .num_different_channels = 1,
8242 .beacon_int_infra_match = true,
8243 .beacon_int_min_gcd = 1,
8244 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8245 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8246 BIT(NL80211_CHAN_WIDTH_20) |
8247 BIT(NL80211_CHAN_WIDTH_40) |
8248 BIT(NL80211_CHAN_WIDTH_80),
8254 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = {
8256 .limits = ath10k_10_4_if_limits,
8257 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8258 .max_interfaces = 16,
8259 .num_different_channels = 1,
8260 .beacon_int_infra_match = true,
8261 .beacon_int_min_gcd = 100,
8262 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8263 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8264 BIT(NL80211_CHAN_WIDTH_20) |
8265 BIT(NL80211_CHAN_WIDTH_40) |
8266 BIT(NL80211_CHAN_WIDTH_80),
8271 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8272 struct ieee80211_vif *vif)
8274 struct ath10k_vif_iter *arvif_iter = data;
8275 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8277 if (arvif->vdev_id == arvif_iter->vdev_id)
8278 arvif_iter->arvif = arvif;
8281 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8283 struct ath10k_vif_iter arvif_iter;
8286 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8287 arvif_iter.vdev_id = vdev_id;
8289 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8290 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8292 ath10k_get_arvif_iter,
8294 if (!arvif_iter.arvif) {
8295 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8299 return arvif_iter.arvif;
8302 #define WRD_METHOD "WRDD"
8303 #define WRDD_WIFI (0x07)
8305 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8307 union acpi_object *mcc_pkg;
8308 union acpi_object *domain_type;
8309 union acpi_object *mcc_value;
8312 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8313 wrdd->package.count < 2 ||
8314 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8315 wrdd->package.elements[0].integer.value != 0) {
8316 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8320 for (i = 1; i < wrdd->package.count; ++i) {
8321 mcc_pkg = &wrdd->package.elements[i];
8323 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8325 if (mcc_pkg->package.count < 2)
8327 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8328 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8331 domain_type = &mcc_pkg->package.elements[0];
8332 if (domain_type->integer.value != WRDD_WIFI)
8335 mcc_value = &mcc_pkg->package.elements[1];
8336 return mcc_value->integer.value;
8341 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8343 acpi_handle root_handle;
8345 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8350 root_handle = ACPI_HANDLE(ar->dev);
8354 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8355 if (ACPI_FAILURE(status)) {
8356 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8357 "failed to get wrd method %d\n", status);
8361 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8362 if (ACPI_FAILURE(status)) {
8363 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8364 "failed to call wrdc %d\n", status);
8368 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8369 kfree(wrdd.pointer);
8373 alpha2[0] = (alpha2_code >> 8) & 0xff;
8374 alpha2[1] = (alpha2_code >> 0) & 0xff;
8377 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8378 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8380 *rd = ath_regd_find_country_by_name(alpha2);
8384 *rd |= COUNTRY_ERD_FLAG;
8388 static int ath10k_mac_init_rd(struct ath10k *ar)
8393 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8395 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8396 "fallback to eeprom programmed regulatory settings\n");
8397 rd = ar->hw_eeprom_rd;
8400 ar->ath_common.regulatory.current_rd = rd;
8404 int ath10k_mac_register(struct ath10k *ar)
8406 static const u32 cipher_suites[] = {
8407 WLAN_CIPHER_SUITE_WEP40,
8408 WLAN_CIPHER_SUITE_WEP104,
8409 WLAN_CIPHER_SUITE_TKIP,
8410 WLAN_CIPHER_SUITE_CCMP,
8412 /* Do not add hardware supported ciphers before this line.
8413 * Allow software encryption for all chips. Don't forget to
8414 * update n_cipher_suites below.
8416 WLAN_CIPHER_SUITE_AES_CMAC,
8417 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8418 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8419 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8421 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8422 * and CCMP-256 in hardware.
8424 WLAN_CIPHER_SUITE_GCMP,
8425 WLAN_CIPHER_SUITE_GCMP_256,
8426 WLAN_CIPHER_SUITE_CCMP_256,
8428 struct ieee80211_supported_band *band;
8432 if (!is_valid_ether_addr(ar->mac_addr)) {
8433 ath10k_warn(ar, "invalid MAC address; choosing random\n");
8434 eth_random_addr(ar->mac_addr);
8436 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8438 SET_IEEE80211_DEV(ar->hw, ar->dev);
8440 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8441 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8444 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8445 channels = kmemdup(ath10k_2ghz_channels,
8446 sizeof(ath10k_2ghz_channels),
8453 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8454 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8455 band->channels = channels;
8457 if (ar->hw_params.cck_rate_map_rev2) {
8458 band->n_bitrates = ath10k_g_rates_rev2_size;
8459 band->bitrates = ath10k_g_rates_rev2;
8461 band->n_bitrates = ath10k_g_rates_size;
8462 band->bitrates = ath10k_g_rates;
8465 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8468 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8469 channels = kmemdup(ath10k_5ghz_channels,
8470 sizeof(ath10k_5ghz_channels),
8477 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8478 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8479 band->channels = channels;
8480 band->n_bitrates = ath10k_a_rates_size;
8481 band->bitrates = ath10k_a_rates;
8482 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8485 wiphy_read_of_freq_limits(ar->hw->wiphy);
8486 ath10k_mac_setup_ht_vht_cap(ar);
8488 ar->hw->wiphy->interface_modes =
8489 BIT(NL80211_IFTYPE_STATION) |
8490 BIT(NL80211_IFTYPE_AP) |
8491 BIT(NL80211_IFTYPE_MESH_POINT);
8493 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8494 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8496 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8497 ar->hw->wiphy->interface_modes |=
8498 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8499 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8500 BIT(NL80211_IFTYPE_P2P_GO);
8502 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8504 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
8505 ar->running_fw->fw_file.fw_features)) {
8506 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8507 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8510 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8511 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8512 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8513 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8514 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8515 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8516 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8517 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8518 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8519 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8520 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8521 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8522 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8524 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8525 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8527 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8528 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8530 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8531 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8533 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8534 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8535 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8538 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8539 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8541 if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
8542 ar->hw->wiphy->max_sched_scan_reqs = 1;
8543 ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
8544 ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
8545 ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
8546 ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
8547 ar->hw->wiphy->max_sched_scan_plan_interval =
8548 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
8549 ar->hw->wiphy->max_sched_scan_plan_iterations =
8550 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
8553 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8554 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8555 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8557 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8559 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8560 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8562 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8563 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8564 * correct Probe Responses. This is more of a hack advert..
8566 ar->hw->wiphy->probe_resp_offload |=
8567 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8568 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8569 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8572 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8573 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8574 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8575 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
8576 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8579 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8580 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
8582 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8583 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8584 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8586 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8587 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8588 NL80211_FEATURE_AP_SCAN;
8590 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8592 ret = ath10k_wow_init(ar);
8594 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8598 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8599 wiphy_ext_feature_set(ar->hw->wiphy,
8600 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
8602 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) ||
8603 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map))
8604 wiphy_ext_feature_set(ar->hw->wiphy,
8605 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
8608 * on LL hardware queues are managed entirely by the FW
8609 * so we only advertise to mac we can do the queues thing
8611 ar->hw->queues = IEEE80211_MAX_QUEUES;
8613 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8614 * something that vdev_ids can't reach so that we don't stop the queue
8617 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8619 switch (ar->running_fw->fw_file.wmi_op_version) {
8620 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8621 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8622 ar->hw->wiphy->n_iface_combinations =
8623 ARRAY_SIZE(ath10k_if_comb);
8624 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8626 case ATH10K_FW_WMI_OP_VERSION_TLV:
8627 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8628 ar->hw->wiphy->iface_combinations =
8629 ath10k_tlv_qcs_if_comb;
8630 ar->hw->wiphy->n_iface_combinations =
8631 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8633 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8634 ar->hw->wiphy->n_iface_combinations =
8635 ARRAY_SIZE(ath10k_tlv_if_comb);
8637 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8639 case ATH10K_FW_WMI_OP_VERSION_10_1:
8640 case ATH10K_FW_WMI_OP_VERSION_10_2:
8641 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8642 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8643 ar->hw->wiphy->n_iface_combinations =
8644 ARRAY_SIZE(ath10k_10x_if_comb);
8646 case ATH10K_FW_WMI_OP_VERSION_10_4:
8647 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8648 ar->hw->wiphy->n_iface_combinations =
8649 ARRAY_SIZE(ath10k_10_4_if_comb);
8650 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT,
8652 ar->hw->wiphy->iface_combinations =
8653 ath10k_10_4_bcn_int_if_comb;
8654 ar->hw->wiphy->n_iface_combinations =
8655 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb);
8658 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8659 case ATH10K_FW_WMI_OP_VERSION_MAX:
8665 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8666 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8668 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8669 /* Init ath dfs pattern detector */
8670 ar->ath_common.debug_mask = ATH_DBG_DFS;
8671 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8674 if (!ar->dfs_detector)
8675 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8678 ret = ath10k_mac_init_rd(ar);
8680 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8681 goto err_dfs_detector_exit;
8684 /* Disable set_coverage_class for chipsets that do not support it. */
8685 if (!ar->hw_params.hw_ops->set_coverage_class)
8686 ar->ops->set_coverage_class = NULL;
8688 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8689 ath10k_reg_notifier);
8691 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8692 goto err_dfs_detector_exit;
8695 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
8696 ar->hw->wiphy->features |=
8697 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8700 ar->hw->wiphy->cipher_suites = cipher_suites;
8702 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
8703 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
8704 * from chip specific hw_param table.
8706 if (!ar->hw_params.n_cipher_suites ||
8707 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
8708 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
8709 ar->hw_params.n_cipher_suites);
8710 ar->hw_params.n_cipher_suites = 8;
8712 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
8714 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8716 ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER;
8718 ret = ieee80211_register_hw(ar->hw);
8720 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8721 goto err_dfs_detector_exit;
8724 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8725 ret = regulatory_hint(ar->hw->wiphy,
8726 ar->ath_common.regulatory.alpha2);
8728 goto err_unregister;
8734 ieee80211_unregister_hw(ar->hw);
8736 err_dfs_detector_exit:
8737 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8738 ar->dfs_detector->exit(ar->dfs_detector);
8741 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8742 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8744 SET_IEEE80211_DEV(ar->hw, NULL);
8748 void ath10k_mac_unregister(struct ath10k *ar)
8750 ieee80211_unregister_hw(ar->hw);
8752 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8753 ar->dfs_detector->exit(ar->dfs_detector);
8755 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8756 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8758 SET_IEEE80211_DEV(ar->hw, NULL);