1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2005-2011 Atheros Communications Inc.
4 * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
5 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
10 #include <net/cfg80211.h>
11 #include <net/mac80211.h>
12 #include <linux/etherdevice.h>
13 #include <linux/acpi.h>
15 #include <linux/bitfield.h>
32 static struct ieee80211_rate ath10k_rates[] = {
34 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
36 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
37 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
38 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
40 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
41 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
42 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
44 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
45 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
46 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
48 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
49 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
50 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
51 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
52 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
53 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
54 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
55 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
58 static struct ieee80211_rate ath10k_rates_rev2[] = {
60 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
62 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
63 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
64 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
66 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
67 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
68 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
70 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
71 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
72 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
74 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
75 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
76 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
77 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
78 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
79 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
80 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
81 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
84 static const struct cfg80211_sar_freq_ranges ath10k_sar_freq_ranges[] = {
85 {.start_freq = 2402, .end_freq = 2494 },
86 {.start_freq = 5170, .end_freq = 5875 },
89 static const struct cfg80211_sar_capa ath10k_sar_capa = {
90 .type = NL80211_SAR_TYPE_POWER,
91 .num_freq_ranges = (ARRAY_SIZE(ath10k_sar_freq_ranges)),
92 .freq_ranges = &ath10k_sar_freq_ranges[0],
95 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
97 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
98 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
99 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
100 #define ath10k_g_rates (ath10k_rates + 0)
101 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
103 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
104 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
106 #define ath10k_wmi_legacy_rates ath10k_rates
108 static bool ath10k_mac_bitrate_is_cck(int bitrate)
121 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
123 return DIV_ROUND_UP(bitrate, 5) |
124 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
127 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
128 u8 hw_rate, bool cck)
130 const struct ieee80211_rate *rate;
133 for (i = 0; i < sband->n_bitrates; i++) {
134 rate = &sband->bitrates[i];
136 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
139 if (rate->hw_value == hw_rate)
141 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
142 rate->hw_value_short == hw_rate)
149 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
154 for (i = 0; i < sband->n_bitrates; i++)
155 if (sband->bitrates[i].bitrate == bitrate)
161 static int ath10k_mac_get_rate_hw_value(int bitrate)
164 u8 hw_value_prefix = 0;
166 if (ath10k_mac_bitrate_is_cck(bitrate))
167 hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
169 for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
170 if (ath10k_rates[i].bitrate == bitrate)
171 return hw_value_prefix | ath10k_rates[i].hw_value;
177 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
179 switch ((mcs_map >> (2 * nss)) & 0x3) {
180 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
181 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
182 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
188 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
192 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
193 if (ht_mcs_mask[nss])
200 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
204 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
205 if (vht_mcs_mask[nss])
211 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
213 enum wmi_host_platform_type platform_type;
216 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
217 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
219 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
221 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
223 if (ret && ret != -EOPNOTSUPP) {
224 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
235 static int ath10k_send_key(struct ath10k_vif *arvif,
236 struct ieee80211_key_conf *key,
237 enum set_key_cmd cmd,
238 const u8 *macaddr, u32 flags)
240 struct ath10k *ar = arvif->ar;
241 struct wmi_vdev_install_key_arg arg = {
242 .vdev_id = arvif->vdev_id,
243 .key_idx = key->keyidx,
244 .key_len = key->keylen,
245 .key_data = key->key,
250 lockdep_assert_held(&arvif->ar->conf_mutex);
252 switch (key->cipher) {
253 case WLAN_CIPHER_SUITE_CCMP:
254 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
255 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
257 case WLAN_CIPHER_SUITE_TKIP:
258 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_TKIP];
259 arg.key_txmic_len = 8;
260 arg.key_rxmic_len = 8;
262 case WLAN_CIPHER_SUITE_WEP40:
263 case WLAN_CIPHER_SUITE_WEP104:
264 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_WEP];
266 case WLAN_CIPHER_SUITE_CCMP_256:
267 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
269 case WLAN_CIPHER_SUITE_GCMP:
270 case WLAN_CIPHER_SUITE_GCMP_256:
271 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_GCM];
272 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
274 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
275 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
276 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
277 case WLAN_CIPHER_SUITE_AES_CMAC:
281 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
285 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
286 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
288 if (cmd == DISABLE_KEY) {
289 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_NONE];
293 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
296 static int ath10k_install_key(struct ath10k_vif *arvif,
297 struct ieee80211_key_conf *key,
298 enum set_key_cmd cmd,
299 const u8 *macaddr, u32 flags)
301 struct ath10k *ar = arvif->ar;
303 unsigned long time_left;
305 lockdep_assert_held(&ar->conf_mutex);
307 reinit_completion(&ar->install_key_done);
309 if (arvif->nohwcrypt)
312 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
316 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
323 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
326 struct ath10k *ar = arvif->ar;
327 struct ath10k_peer *peer;
332 lockdep_assert_held(&ar->conf_mutex);
334 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
335 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
336 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
339 spin_lock_bh(&ar->data_lock);
340 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
341 spin_unlock_bh(&ar->data_lock);
346 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
347 if (arvif->wep_keys[i] == NULL)
350 switch (arvif->vif->type) {
351 case NL80211_IFTYPE_AP:
352 flags = WMI_KEY_PAIRWISE;
354 if (arvif->def_wep_key_idx == i)
355 flags |= WMI_KEY_TX_USAGE;
357 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
358 SET_KEY, addr, flags);
362 case NL80211_IFTYPE_ADHOC:
363 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
369 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
370 SET_KEY, addr, WMI_KEY_GROUP);
379 spin_lock_bh(&ar->data_lock);
380 peer->keys[i] = arvif->wep_keys[i];
381 spin_unlock_bh(&ar->data_lock);
384 /* In some cases (notably with static WEP IBSS with multiple keys)
385 * multicast Tx becomes broken. Both pairwise and groupwise keys are
386 * installed already. Using WMI_KEY_TX_USAGE in different combinations
387 * didn't seem help. Using def_keyid vdev parameter seems to be
388 * effective so use that.
390 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
392 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
395 if (arvif->def_wep_key_idx == -1)
398 ret = ath10k_wmi_vdev_set_param(arvif->ar,
400 arvif->ar->wmi.vdev_param->def_keyid,
401 arvif->def_wep_key_idx);
403 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
404 arvif->vdev_id, ret);
411 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
414 struct ath10k *ar = arvif->ar;
415 struct ath10k_peer *peer;
421 lockdep_assert_held(&ar->conf_mutex);
423 spin_lock_bh(&ar->data_lock);
424 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
425 spin_unlock_bh(&ar->data_lock);
430 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
431 if (peer->keys[i] == NULL)
434 /* key flags are not required to delete the key */
435 ret = ath10k_install_key(arvif, peer->keys[i],
436 DISABLE_KEY, addr, flags);
437 if (ret < 0 && first_errno == 0)
441 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
444 spin_lock_bh(&ar->data_lock);
445 peer->keys[i] = NULL;
446 spin_unlock_bh(&ar->data_lock);
452 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
455 struct ath10k_peer *peer;
458 lockdep_assert_held(&ar->data_lock);
460 /* We don't know which vdev this peer belongs to,
461 * since WMI doesn't give us that information.
463 * FIXME: multi-bss needs to be handled.
465 peer = ath10k_peer_find(ar, 0, addr);
469 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
470 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
477 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
478 struct ieee80211_key_conf *key)
480 struct ath10k *ar = arvif->ar;
481 struct ath10k_peer *peer;
488 lockdep_assert_held(&ar->conf_mutex);
491 /* since ath10k_install_key we can't hold data_lock all the
492 * time, so we try to remove the keys incrementally
494 spin_lock_bh(&ar->data_lock);
496 list_for_each_entry(peer, &ar->peers, list) {
497 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
498 if (peer->keys[i] == key) {
499 ether_addr_copy(addr, peer->addr);
500 peer->keys[i] = NULL;
505 if (i < ARRAY_SIZE(peer->keys))
508 spin_unlock_bh(&ar->data_lock);
510 if (i == ARRAY_SIZE(peer->keys))
512 /* key flags are not required to delete the key */
513 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
514 if (ret < 0 && first_errno == 0)
518 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
525 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
526 struct ieee80211_key_conf *key)
528 struct ath10k *ar = arvif->ar;
529 struct ath10k_peer *peer;
532 lockdep_assert_held(&ar->conf_mutex);
534 list_for_each_entry(peer, &ar->peers, list) {
535 if (ether_addr_equal(peer->addr, arvif->vif->addr))
538 if (ether_addr_equal(peer->addr, arvif->bssid))
541 if (peer->keys[key->keyidx] == key)
544 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
545 arvif->vdev_id, key->keyidx);
547 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
549 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
550 arvif->vdev_id, peer->addr, ret);
558 /*********************/
559 /* General utilities */
560 /*********************/
562 static inline enum wmi_phy_mode
563 chan_to_phymode(const struct cfg80211_chan_def *chandef)
565 enum wmi_phy_mode phymode = MODE_UNKNOWN;
567 switch (chandef->chan->band) {
568 case NL80211_BAND_2GHZ:
569 switch (chandef->width) {
570 case NL80211_CHAN_WIDTH_20_NOHT:
571 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
576 case NL80211_CHAN_WIDTH_20:
577 phymode = MODE_11NG_HT20;
579 case NL80211_CHAN_WIDTH_40:
580 phymode = MODE_11NG_HT40;
583 phymode = MODE_UNKNOWN;
587 case NL80211_BAND_5GHZ:
588 switch (chandef->width) {
589 case NL80211_CHAN_WIDTH_20_NOHT:
592 case NL80211_CHAN_WIDTH_20:
593 phymode = MODE_11NA_HT20;
595 case NL80211_CHAN_WIDTH_40:
596 phymode = MODE_11NA_HT40;
598 case NL80211_CHAN_WIDTH_80:
599 phymode = MODE_11AC_VHT80;
601 case NL80211_CHAN_WIDTH_160:
602 phymode = MODE_11AC_VHT160;
604 case NL80211_CHAN_WIDTH_80P80:
605 phymode = MODE_11AC_VHT80_80;
608 phymode = MODE_UNKNOWN;
616 WARN_ON(phymode == MODE_UNKNOWN);
620 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
623 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
624 * 0 for no restriction
633 switch (mpdudensity) {
639 /* Our lower layer calculations limit our precision to
656 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
657 struct cfg80211_chan_def *def)
659 struct ieee80211_chanctx_conf *conf;
662 conf = rcu_dereference(vif->chanctx_conf);
674 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
675 struct ieee80211_chanctx_conf *conf,
683 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
687 ieee80211_iter_chan_contexts_atomic(ar->hw,
688 ath10k_mac_num_chanctxs_iter,
695 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
696 struct ieee80211_chanctx_conf *conf,
699 struct cfg80211_chan_def **def = data;
704 static void ath10k_wait_for_peer_delete_done(struct ath10k *ar, u32 vdev_id,
707 unsigned long time_left;
710 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) {
711 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
713 ath10k_warn(ar, "failed wait for peer deleted");
717 time_left = wait_for_completion_timeout(&ar->peer_delete_done,
720 ath10k_warn(ar, "Timeout in receiving peer delete response\n");
724 static int ath10k_peer_create(struct ath10k *ar,
725 struct ieee80211_vif *vif,
726 struct ieee80211_sta *sta,
729 enum wmi_peer_type peer_type)
731 struct ath10k_vif *arvif;
732 struct ath10k_peer *peer;
736 lockdep_assert_held(&ar->conf_mutex);
738 num_peers = ar->num_peers;
740 /* Each vdev consumes a peer entry as well */
741 list_for_each_entry(arvif, &ar->arvifs, list)
744 if (num_peers >= ar->max_num_peers)
747 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
749 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
754 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
756 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
761 spin_lock_bh(&ar->data_lock);
763 peer = ath10k_peer_find(ar, vdev_id, addr);
765 spin_unlock_bh(&ar->data_lock);
766 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
768 ath10k_wait_for_peer_delete_done(ar, vdev_id, addr);
775 spin_unlock_bh(&ar->data_lock);
782 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
784 struct ath10k *ar = arvif->ar;
788 param = ar->wmi.pdev_param->sta_kickout_th;
789 ret = ath10k_wmi_pdev_set_param(ar, param,
790 ATH10K_KICKOUT_THRESHOLD);
792 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
793 arvif->vdev_id, ret);
797 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
798 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
799 ATH10K_KEEPALIVE_MIN_IDLE);
801 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
802 arvif->vdev_id, ret);
806 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
807 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
808 ATH10K_KEEPALIVE_MAX_IDLE);
810 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
811 arvif->vdev_id, ret);
815 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
816 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
817 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
819 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
820 arvif->vdev_id, ret);
827 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
829 struct ath10k *ar = arvif->ar;
832 vdev_param = ar->wmi.vdev_param->rts_threshold;
833 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
836 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
840 lockdep_assert_held(&ar->conf_mutex);
842 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
846 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
850 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) {
851 unsigned long time_left;
853 time_left = wait_for_completion_timeout
854 (&ar->peer_delete_done, 5 * HZ);
857 ath10k_warn(ar, "Timeout in receiving peer delete response\n");
867 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
869 struct ath10k_peer *peer, *tmp;
873 lockdep_assert_held(&ar->conf_mutex);
875 spin_lock_bh(&ar->data_lock);
876 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
877 if (peer->vdev_id != vdev_id)
880 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
881 peer->addr, vdev_id);
883 for_each_set_bit(peer_id, peer->peer_ids,
884 ATH10K_MAX_NUM_PEER_IDS) {
885 ar->peer_map[peer_id] = NULL;
888 /* Double check that peer is properly un-referenced from
891 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
892 if (ar->peer_map[i] == peer) {
893 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
894 peer->addr, peer, i);
895 ar->peer_map[i] = NULL;
899 list_del(&peer->list);
903 spin_unlock_bh(&ar->data_lock);
906 static void ath10k_peer_cleanup_all(struct ath10k *ar)
908 struct ath10k_peer *peer, *tmp;
911 lockdep_assert_held(&ar->conf_mutex);
913 spin_lock_bh(&ar->data_lock);
914 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
915 list_del(&peer->list);
919 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
920 ar->peer_map[i] = NULL;
922 spin_unlock_bh(&ar->data_lock);
925 ar->num_stations = 0;
928 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
929 struct ieee80211_sta *sta,
930 enum wmi_tdls_peer_state state)
933 struct wmi_tdls_peer_update_cmd_arg arg = {};
934 struct wmi_tdls_peer_capab_arg cap = {};
935 struct wmi_channel_arg chan_arg = {};
937 lockdep_assert_held(&ar->conf_mutex);
939 arg.vdev_id = vdev_id;
940 arg.peer_state = state;
941 ether_addr_copy(arg.addr, sta->addr);
943 cap.peer_max_sp = sta->max_sp;
944 cap.peer_uapsd_queues = sta->uapsd_queues;
946 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
947 !sta->tdls_initiator)
948 cap.is_peer_responder = 1;
950 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
952 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
953 arg.addr, vdev_id, ret);
960 /************************/
961 /* Interface management */
962 /************************/
964 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
966 struct ath10k *ar = arvif->ar;
968 lockdep_assert_held(&ar->data_lock);
973 if (!arvif->beacon_buf)
974 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
975 arvif->beacon->len, DMA_TO_DEVICE);
977 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
978 arvif->beacon_state != ATH10K_BEACON_SENT))
981 dev_kfree_skb_any(arvif->beacon);
983 arvif->beacon = NULL;
984 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
987 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
989 struct ath10k *ar = arvif->ar;
991 lockdep_assert_held(&ar->data_lock);
993 ath10k_mac_vif_beacon_free(arvif);
995 if (arvif->beacon_buf) {
996 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
997 arvif->beacon_buf, arvif->beacon_paddr);
998 arvif->beacon_buf = NULL;
1002 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
1004 unsigned long time_left;
1006 lockdep_assert_held(&ar->conf_mutex);
1008 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
1011 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
1012 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
1016 return ar->last_wmi_vdev_start_status;
1019 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
1021 struct cfg80211_chan_def *chandef = NULL;
1022 struct ieee80211_channel *channel = NULL;
1023 struct wmi_vdev_start_request_arg arg = {};
1026 lockdep_assert_held(&ar->conf_mutex);
1028 ieee80211_iter_chan_contexts_atomic(ar->hw,
1029 ath10k_mac_get_any_chandef_iter,
1031 if (WARN_ON_ONCE(!chandef))
1034 channel = chandef->chan;
1036 arg.vdev_id = vdev_id;
1037 arg.channel.freq = channel->center_freq;
1038 arg.channel.band_center_freq1 = chandef->center_freq1;
1039 arg.channel.band_center_freq2 = chandef->center_freq2;
1041 /* TODO setup this dynamically, what in case we
1042 * don't have any vifs?
1044 arg.channel.mode = chan_to_phymode(chandef);
1045 arg.channel.chan_radar =
1046 !!(channel->flags & IEEE80211_CHAN_RADAR);
1048 arg.channel.min_power = 0;
1049 arg.channel.max_power = channel->max_power * 2;
1050 arg.channel.max_reg_power = channel->max_reg_power * 2;
1051 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
1053 reinit_completion(&ar->vdev_setup_done);
1054 reinit_completion(&ar->vdev_delete_done);
1056 ret = ath10k_wmi_vdev_start(ar, &arg);
1058 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1063 ret = ath10k_vdev_setup_sync(ar);
1065 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1070 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1072 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1077 ar->monitor_vdev_id = vdev_id;
1079 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1080 ar->monitor_vdev_id);
1084 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1086 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1087 ar->monitor_vdev_id, ret);
1092 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1096 lockdep_assert_held(&ar->conf_mutex);
1098 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1100 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1101 ar->monitor_vdev_id, ret);
1103 reinit_completion(&ar->vdev_setup_done);
1104 reinit_completion(&ar->vdev_delete_done);
1106 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1108 ath10k_warn(ar, "failed to request monitor vdev %i stop: %d\n",
1109 ar->monitor_vdev_id, ret);
1111 ret = ath10k_vdev_setup_sync(ar);
1113 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1114 ar->monitor_vdev_id, ret);
1116 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1117 ar->monitor_vdev_id);
1121 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1125 lockdep_assert_held(&ar->conf_mutex);
1127 if (ar->free_vdev_map == 0) {
1128 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1132 bit = __ffs64(ar->free_vdev_map);
1134 ar->monitor_vdev_id = bit;
1136 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1137 WMI_VDEV_TYPE_MONITOR,
1140 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1141 ar->monitor_vdev_id, ret);
1145 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1147 ar->monitor_vdev_id);
1152 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1156 lockdep_assert_held(&ar->conf_mutex);
1158 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1160 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1161 ar->monitor_vdev_id, ret);
1165 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1167 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1168 ar->monitor_vdev_id);
1172 static int ath10k_monitor_start(struct ath10k *ar)
1176 lockdep_assert_held(&ar->conf_mutex);
1178 ret = ath10k_monitor_vdev_create(ar);
1180 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1184 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1186 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1187 ath10k_monitor_vdev_delete(ar);
1191 ar->monitor_started = true;
1192 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1197 static int ath10k_monitor_stop(struct ath10k *ar)
1201 lockdep_assert_held(&ar->conf_mutex);
1203 ret = ath10k_monitor_vdev_stop(ar);
1205 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1209 ret = ath10k_monitor_vdev_delete(ar);
1211 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1215 ar->monitor_started = false;
1216 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1221 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1225 /* At least one chanctx is required to derive a channel to start
1228 num_ctx = ath10k_mac_num_chanctxs(ar);
1232 /* If there's already an existing special monitor interface then don't
1233 * bother creating another monitor vdev.
1235 if (ar->monitor_arvif)
1238 return ar->monitor ||
1239 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1240 ar->running_fw->fw_file.fw_features) &&
1241 (ar->filter_flags & FIF_OTHER_BSS)) ||
1242 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1245 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1249 num_ctx = ath10k_mac_num_chanctxs(ar);
1251 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1252 * shouldn't allow this but make sure to prevent handling the following
1253 * case anyway since multi-channel DFS hasn't been tested at all.
1255 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1261 static int ath10k_monitor_recalc(struct ath10k *ar)
1267 lockdep_assert_held(&ar->conf_mutex);
1269 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1270 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1272 ath10k_dbg(ar, ATH10K_DBG_MAC,
1273 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1274 ar->monitor_started, needed, allowed);
1276 if (WARN_ON(needed && !allowed)) {
1277 if (ar->monitor_started) {
1278 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1280 ret = ath10k_monitor_stop(ar);
1282 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1290 if (needed == ar->monitor_started)
1294 return ath10k_monitor_start(ar);
1296 return ath10k_monitor_stop(ar);
1299 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1301 struct ath10k *ar = arvif->ar;
1303 lockdep_assert_held(&ar->conf_mutex);
1305 if (!arvif->is_started) {
1306 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1313 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1315 struct ath10k *ar = arvif->ar;
1318 lockdep_assert_held(&ar->conf_mutex);
1320 vdev_param = ar->wmi.vdev_param->protection_mode;
1322 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1323 arvif->vdev_id, arvif->use_cts_prot);
1325 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1326 arvif->use_cts_prot ? 1 : 0);
1329 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1331 struct ath10k *ar = arvif->ar;
1332 u32 vdev_param, rts_cts = 0;
1334 lockdep_assert_held(&ar->conf_mutex);
1336 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1338 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1340 if (arvif->num_legacy_stations > 0)
1341 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1342 WMI_RTSCTS_PROFILE);
1344 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1345 WMI_RTSCTS_PROFILE);
1347 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1348 arvif->vdev_id, rts_cts);
1350 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1354 static int ath10k_start_cac(struct ath10k *ar)
1358 lockdep_assert_held(&ar->conf_mutex);
1360 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1362 ret = ath10k_monitor_recalc(ar);
1364 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1365 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1369 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1370 ar->monitor_vdev_id);
1375 static int ath10k_stop_cac(struct ath10k *ar)
1377 lockdep_assert_held(&ar->conf_mutex);
1379 /* CAC is not running - do nothing */
1380 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1383 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1384 ath10k_monitor_stop(ar);
1386 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1391 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1392 struct ieee80211_chanctx_conf *conf,
1397 if (!*ret && conf->radar_enabled)
1401 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1403 bool has_radar = false;
1405 ieee80211_iter_chan_contexts_atomic(ar->hw,
1406 ath10k_mac_has_radar_iter,
1412 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1416 lockdep_assert_held(&ar->conf_mutex);
1418 ath10k_stop_cac(ar);
1420 if (!ath10k_mac_has_radar_enabled(ar))
1423 if (ar->num_started_vdevs > 0)
1426 ret = ath10k_start_cac(ar);
1429 * Not possible to start CAC on current channel so starting
1430 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1431 * by indicating that radar was detected.
1433 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1434 ieee80211_radar_detected(ar->hw);
1438 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1440 struct ath10k *ar = arvif->ar;
1443 lockdep_assert_held(&ar->conf_mutex);
1445 reinit_completion(&ar->vdev_setup_done);
1446 reinit_completion(&ar->vdev_delete_done);
1448 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1450 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1451 arvif->vdev_id, ret);
1455 ret = ath10k_vdev_setup_sync(ar);
1457 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1458 arvif->vdev_id, ret);
1462 WARN_ON(ar->num_started_vdevs == 0);
1464 if (ar->num_started_vdevs != 0) {
1465 ar->num_started_vdevs--;
1466 ath10k_recalc_radar_detection(ar);
1472 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1473 const struct cfg80211_chan_def *chandef,
1476 struct ath10k *ar = arvif->ar;
1477 struct wmi_vdev_start_request_arg arg = {};
1480 lockdep_assert_held(&ar->conf_mutex);
1482 reinit_completion(&ar->vdev_setup_done);
1483 reinit_completion(&ar->vdev_delete_done);
1485 arg.vdev_id = arvif->vdev_id;
1486 arg.dtim_period = arvif->dtim_period;
1487 arg.bcn_intval = arvif->beacon_interval;
1489 arg.channel.freq = chandef->chan->center_freq;
1490 arg.channel.band_center_freq1 = chandef->center_freq1;
1491 arg.channel.band_center_freq2 = chandef->center_freq2;
1492 arg.channel.mode = chan_to_phymode(chandef);
1494 arg.channel.min_power = 0;
1495 arg.channel.max_power = chandef->chan->max_power * 2;
1496 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1497 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1499 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1500 arg.ssid = arvif->u.ap.ssid;
1501 arg.ssid_len = arvif->u.ap.ssid_len;
1502 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1504 /* For now allow DFS for AP mode */
1505 arg.channel.chan_radar =
1506 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1507 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1508 arg.ssid = arvif->vif->bss_conf.ssid;
1509 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1512 ath10k_dbg(ar, ATH10K_DBG_MAC,
1513 "mac vdev %d start center_freq %d phymode %s\n",
1514 arg.vdev_id, arg.channel.freq,
1515 ath10k_wmi_phymode_str(arg.channel.mode));
1518 ret = ath10k_wmi_vdev_restart(ar, &arg);
1520 ret = ath10k_wmi_vdev_start(ar, &arg);
1523 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1528 ret = ath10k_vdev_setup_sync(ar);
1531 "failed to synchronize setup for vdev %i restart %d: %d\n",
1532 arg.vdev_id, restart, ret);
1536 ar->num_started_vdevs++;
1537 ath10k_recalc_radar_detection(ar);
1542 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1543 const struct cfg80211_chan_def *def)
1545 return ath10k_vdev_start_restart(arvif, def, false);
1548 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1549 const struct cfg80211_chan_def *def)
1551 return ath10k_vdev_start_restart(arvif, def, true);
1554 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1555 struct sk_buff *bcn)
1557 struct ath10k *ar = arvif->ar;
1558 struct ieee80211_mgmt *mgmt;
1562 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1565 mgmt = (void *)bcn->data;
1566 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1567 mgmt->u.beacon.variable,
1568 bcn->len - (mgmt->u.beacon.variable -
1573 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1575 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1576 arvif->vdev_id, ret);
1583 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1584 u8 oui_type, size_t ie_offset)
1591 if (WARN_ON(skb->len < ie_offset))
1594 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1595 skb->data + ie_offset,
1596 skb->len - ie_offset);
1601 end = skb->data + skb->len;
1604 if (WARN_ON(next > end))
1607 memmove(ie, next, end - next);
1608 skb_trim(skb, skb->len - len);
1613 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1615 struct ath10k *ar = arvif->ar;
1616 struct ieee80211_hw *hw = ar->hw;
1617 struct ieee80211_vif *vif = arvif->vif;
1618 struct ieee80211_mutable_offsets offs = {};
1619 struct sk_buff *bcn;
1622 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1625 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1626 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1629 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1631 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1635 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1637 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1642 /* P2P IE is inserted by firmware automatically (as configured above)
1643 * so remove it from the base beacon template to avoid duplicate P2P
1644 * IEs in beacon frames.
1646 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1647 offsetof(struct ieee80211_mgmt,
1648 u.beacon.variable));
1650 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1655 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1663 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1665 struct ath10k *ar = arvif->ar;
1666 struct ieee80211_hw *hw = ar->hw;
1667 struct ieee80211_vif *vif = arvif->vif;
1668 struct sk_buff *prb;
1671 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1674 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1677 /* For mesh, probe response and beacon share the same template */
1678 if (ieee80211_vif_is_mesh(vif))
1681 prb = ieee80211_proberesp_get(hw, vif);
1683 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1687 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1691 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1699 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1701 struct ath10k *ar = arvif->ar;
1702 struct cfg80211_chan_def def;
1705 /* When originally vdev is started during assign_vif_chanctx() some
1706 * information is missing, notably SSID. Firmware revisions with beacon
1707 * offloading require the SSID to be provided during vdev (re)start to
1708 * handle hidden SSID properly.
1710 * Vdev restart must be done after vdev has been both started and
1711 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1712 * deliver vdev restart response event causing timeouts during vdev
1713 * syncing in ath10k.
1715 * Note: The vdev down/up and template reinstallation could be skipped
1716 * since only wmi-tlv firmware are known to have beacon offload and
1717 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1718 * response delivery. It's probably more robust to keep it as is.
1720 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1723 if (WARN_ON(!arvif->is_started))
1726 if (WARN_ON(!arvif->is_up))
1729 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1732 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1734 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1735 arvif->vdev_id, ret);
1739 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1740 * firmware will crash upon vdev up.
1743 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1745 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1749 ret = ath10k_mac_setup_prb_tmpl(arvif);
1751 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1755 ret = ath10k_vdev_restart(arvif, &def);
1757 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1758 arvif->vdev_id, ret);
1762 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1765 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1766 arvif->vdev_id, ret);
1773 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1774 struct ieee80211_bss_conf *info)
1776 struct ath10k *ar = arvif->ar;
1779 lockdep_assert_held(&arvif->ar->conf_mutex);
1781 if (!info->enable_beacon) {
1782 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1784 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1785 arvif->vdev_id, ret);
1787 arvif->is_up = false;
1789 spin_lock_bh(&arvif->ar->data_lock);
1790 ath10k_mac_vif_beacon_free(arvif);
1791 spin_unlock_bh(&arvif->ar->data_lock);
1796 arvif->tx_seq_no = 0x1000;
1799 ether_addr_copy(arvif->bssid, info->bssid);
1801 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1804 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1805 arvif->vdev_id, ret);
1809 arvif->is_up = true;
1811 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1813 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1814 arvif->vdev_id, ret);
1818 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1821 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1822 struct ieee80211_bss_conf *info,
1823 const u8 self_peer[ETH_ALEN])
1825 struct ath10k *ar = arvif->ar;
1829 lockdep_assert_held(&arvif->ar->conf_mutex);
1831 if (!info->ibss_joined) {
1832 if (is_zero_ether_addr(arvif->bssid))
1835 eth_zero_addr(arvif->bssid);
1840 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1841 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1842 ATH10K_DEFAULT_ATIM);
1844 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1845 arvif->vdev_id, ret);
1848 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1850 struct ath10k *ar = arvif->ar;
1855 lockdep_assert_held(&arvif->ar->conf_mutex);
1857 if (arvif->u.sta.uapsd)
1858 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1860 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1862 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1863 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1865 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1866 value, arvif->vdev_id, ret);
1873 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1875 struct ath10k *ar = arvif->ar;
1880 lockdep_assert_held(&arvif->ar->conf_mutex);
1882 if (arvif->u.sta.uapsd)
1883 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1885 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1887 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1888 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1891 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1892 value, arvif->vdev_id, ret);
1899 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1901 struct ath10k_vif *arvif;
1904 lockdep_assert_held(&ar->conf_mutex);
1906 list_for_each_entry(arvif, &ar->arvifs, list)
1907 if (arvif->is_started)
1913 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1915 struct ath10k *ar = arvif->ar;
1916 struct ieee80211_vif *vif = arvif->vif;
1917 struct ieee80211_conf *conf = &ar->hw->conf;
1918 enum wmi_sta_powersave_param param;
1919 enum wmi_sta_ps_mode psmode;
1924 lockdep_assert_held(&arvif->ar->conf_mutex);
1926 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1929 enable_ps = arvif->ps;
1931 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1932 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1933 ar->running_fw->fw_file.fw_features)) {
1934 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1939 if (!arvif->is_started) {
1940 /* mac80211 can update vif powersave state while disconnected.
1941 * Firmware doesn't behave nicely and consumes more power than
1942 * necessary if PS is disabled on a non-started vdev. Hence
1943 * force-enable PS for non-running vdevs.
1945 psmode = WMI_STA_PS_MODE_ENABLED;
1946 } else if (enable_ps) {
1947 psmode = WMI_STA_PS_MODE_ENABLED;
1948 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1950 ps_timeout = conf->dynamic_ps_timeout;
1951 if (ps_timeout == 0) {
1952 /* Firmware doesn't like 0 */
1953 ps_timeout = ieee80211_tu_to_usec(
1954 vif->bss_conf.beacon_int) / 1000;
1957 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1960 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1961 arvif->vdev_id, ret);
1965 psmode = WMI_STA_PS_MODE_DISABLED;
1968 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1969 arvif->vdev_id, psmode ? "enable" : "disable");
1971 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1973 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1974 psmode, arvif->vdev_id, ret);
1981 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1983 struct ath10k *ar = arvif->ar;
1984 struct wmi_sta_keepalive_arg arg = {};
1987 lockdep_assert_held(&arvif->ar->conf_mutex);
1989 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1992 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1995 /* Some firmware revisions have a bug and ignore the `enabled` field.
1996 * Instead use the interval to disable the keepalive.
1998 arg.vdev_id = arvif->vdev_id;
2000 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
2001 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
2003 ret = ath10k_wmi_sta_keepalive(ar, &arg);
2005 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
2006 arvif->vdev_id, ret);
2013 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
2015 struct ath10k *ar = arvif->ar;
2016 struct ieee80211_vif *vif = arvif->vif;
2019 lockdep_assert_held(&arvif->ar->conf_mutex);
2021 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
2024 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2027 if (!vif->csa_active)
2033 if (!ieee80211_beacon_cntdwn_is_complete(vif)) {
2034 ieee80211_beacon_update_cntdwn(vif);
2036 ret = ath10k_mac_setup_bcn_tmpl(arvif);
2038 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
2041 ret = ath10k_mac_setup_prb_tmpl(arvif);
2043 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
2046 ieee80211_csa_finish(vif);
2050 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2052 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2054 struct ath10k *ar = arvif->ar;
2056 mutex_lock(&ar->conf_mutex);
2057 ath10k_mac_vif_ap_csa_count_down(arvif);
2058 mutex_unlock(&ar->conf_mutex);
2061 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2062 struct ieee80211_vif *vif)
2064 struct sk_buff *skb = data;
2065 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2066 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2068 if (vif->type != NL80211_IFTYPE_STATION)
2071 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2074 cancel_delayed_work(&arvif->connection_loss_work);
2077 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2079 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2080 ATH10K_ITER_NORMAL_FLAGS,
2081 ath10k_mac_handle_beacon_iter,
2085 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2086 struct ieee80211_vif *vif)
2088 u32 *vdev_id = data;
2089 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2090 struct ath10k *ar = arvif->ar;
2091 struct ieee80211_hw *hw = ar->hw;
2093 if (arvif->vdev_id != *vdev_id)
2099 ieee80211_beacon_loss(vif);
2101 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2102 * (done by mac80211) succeeds but beacons do not resume then it
2103 * doesn't make sense to continue operation. Queue connection loss work
2104 * which can be cancelled when beacon is received.
2106 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2107 ATH10K_CONNECTION_LOSS_HZ);
2110 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2112 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2113 ATH10K_ITER_NORMAL_FLAGS,
2114 ath10k_mac_handle_beacon_miss_iter,
2118 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2120 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2121 connection_loss_work.work);
2122 struct ieee80211_vif *vif = arvif->vif;
2127 ieee80211_connection_loss(vif);
2130 /**********************/
2131 /* Station management */
2132 /**********************/
2134 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2135 struct ieee80211_vif *vif)
2137 /* Some firmware revisions have unstable STA powersave when listen
2138 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2139 * generate NullFunc frames properly even if buffered frames have been
2140 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2141 * buffered frames. Often pinging the device from AP would simply fail.
2143 * As a workaround set it to 1.
2145 if (vif->type == NL80211_IFTYPE_STATION)
2148 return ar->hw->conf.listen_interval;
2151 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2152 struct ieee80211_vif *vif,
2153 struct ieee80211_sta *sta,
2154 struct wmi_peer_assoc_complete_arg *arg)
2156 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2159 lockdep_assert_held(&ar->conf_mutex);
2161 if (vif->type == NL80211_IFTYPE_STATION)
2162 aid = vif->bss_conf.aid;
2166 ether_addr_copy(arg->addr, sta->addr);
2167 arg->vdev_id = arvif->vdev_id;
2168 arg->peer_aid = aid;
2169 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2170 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2171 arg->peer_num_spatial_streams = 1;
2172 arg->peer_caps = vif->bss_conf.assoc_capability;
2175 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2176 struct ieee80211_vif *vif,
2177 struct ieee80211_sta *sta,
2178 struct wmi_peer_assoc_complete_arg *arg)
2180 struct ieee80211_bss_conf *info = &vif->bss_conf;
2181 struct cfg80211_chan_def def;
2182 struct cfg80211_bss *bss;
2183 const u8 *rsnie = NULL;
2184 const u8 *wpaie = NULL;
2186 lockdep_assert_held(&ar->conf_mutex);
2188 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2191 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid,
2192 info->ssid_len ? info->ssid : NULL, info->ssid_len,
2193 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2195 const struct cfg80211_bss_ies *ies;
2198 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2200 ies = rcu_dereference(bss->ies);
2202 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2203 WLAN_OUI_TYPE_MICROSOFT_WPA,
2207 cfg80211_put_bss(ar->hw->wiphy, bss);
2210 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2211 if (rsnie || wpaie) {
2212 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2213 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2217 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2218 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2222 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2223 ar->running_fw->fw_file.fw_features)) {
2224 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2228 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2229 struct ieee80211_vif *vif,
2230 struct ieee80211_sta *sta,
2231 struct wmi_peer_assoc_complete_arg *arg)
2233 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2234 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2235 struct cfg80211_chan_def def;
2236 const struct ieee80211_supported_band *sband;
2237 const struct ieee80211_rate *rates;
2238 enum nl80211_band band;
2243 lockdep_assert_held(&ar->conf_mutex);
2245 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2248 band = def.chan->band;
2249 sband = ar->hw->wiphy->bands[band];
2250 ratemask = sta->supp_rates[band];
2251 ratemask &= arvif->bitrate_mask.control[band].legacy;
2252 rates = sband->bitrates;
2254 rateset->num_rates = 0;
2256 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2257 if (!(ratemask & 1))
2260 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2261 rateset->rates[rateset->num_rates] = rate;
2262 rateset->num_rates++;
2267 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2271 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2272 if (ht_mcs_mask[nss])
2279 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2283 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2284 if (vht_mcs_mask[nss])
2290 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2291 struct ieee80211_vif *vif,
2292 struct ieee80211_sta *sta,
2293 struct wmi_peer_assoc_complete_arg *arg)
2295 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2296 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2297 struct cfg80211_chan_def def;
2298 enum nl80211_band band;
2299 const u8 *ht_mcs_mask;
2300 const u16 *vht_mcs_mask;
2305 lockdep_assert_held(&ar->conf_mutex);
2307 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2310 if (!ht_cap->ht_supported)
2313 band = def.chan->band;
2314 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2315 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2317 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2318 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2321 arg->peer_flags |= ar->wmi.peer_flags->ht;
2322 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2323 ht_cap->ampdu_factor)) - 1;
2325 arg->peer_mpdu_density =
2326 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2328 arg->peer_ht_caps = ht_cap->cap;
2329 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2331 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2332 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2334 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2335 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2336 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2339 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2340 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2341 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2343 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2344 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2347 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2348 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2349 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2352 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2353 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2354 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2355 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2356 arg->peer_rate_caps |= stbc;
2357 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2360 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2361 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2362 else if (ht_cap->mcs.rx_mask[1])
2363 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2365 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2366 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2367 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2368 max_nss = (i / 8) + 1;
2369 arg->peer_ht_rates.rates[n++] = i;
2373 * This is a workaround for HT-enabled STAs which break the spec
2374 * and have no HT capabilities RX mask (no HT RX MCS map).
2376 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2377 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2379 * Firmware asserts if such situation occurs.
2382 arg->peer_ht_rates.num_rates = 8;
2383 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2384 arg->peer_ht_rates.rates[i] = i;
2386 arg->peer_ht_rates.num_rates = n;
2387 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2390 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2392 arg->peer_ht_rates.num_rates,
2393 arg->peer_num_spatial_streams);
2396 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2397 struct ath10k_vif *arvif,
2398 struct ieee80211_sta *sta)
2404 lockdep_assert_held(&ar->conf_mutex);
2406 if (sta->wme && sta->uapsd_queues) {
2407 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2408 sta->uapsd_queues, sta->max_sp);
2410 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2411 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2412 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2413 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2414 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2415 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2416 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2417 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2418 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2419 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2420 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2421 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2423 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2424 max_sp = sta->max_sp;
2426 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2428 WMI_AP_PS_PEER_PARAM_UAPSD,
2431 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2432 arvif->vdev_id, ret);
2436 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2438 WMI_AP_PS_PEER_PARAM_MAX_SP,
2441 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2442 arvif->vdev_id, ret);
2446 /* TODO setup this based on STA listen interval and
2447 * beacon interval. Currently we don't know
2448 * sta->listen_interval - mac80211 patch required.
2449 * Currently use 10 seconds
2451 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2452 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2455 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2456 arvif->vdev_id, ret);
2465 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2466 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2473 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2474 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2478 idx_limit = fls(mcs_map) - 1;
2482 switch (idx_limit) {
2491 /* see ath10k_mac_can_set_bitrate_mask() */
2495 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2498 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2501 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2504 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2508 tx_mcs_set &= ~(0x3 << (nss * 2));
2509 tx_mcs_set |= mcs << (nss * 2);
2515 static u32 get_160mhz_nss_from_maxrate(int rate)
2527 nss = 3; /* not support MCS9 from spec*/
2539 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2540 struct ieee80211_vif *vif,
2541 struct ieee80211_sta *sta,
2542 struct wmi_peer_assoc_complete_arg *arg)
2544 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2545 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2546 struct ath10k_hw_params *hw = &ar->hw_params;
2547 struct cfg80211_chan_def def;
2548 enum nl80211_band band;
2549 const u16 *vht_mcs_mask;
2551 u8 max_nss, vht_mcs;
2554 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2557 if (!vht_cap->vht_supported)
2560 band = def.chan->band;
2561 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2563 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2566 arg->peer_flags |= ar->wmi.peer_flags->vht;
2568 if (def.chan->band == NL80211_BAND_2GHZ)
2569 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2571 arg->peer_vht_caps = vht_cap->cap;
2573 ampdu_factor = (vht_cap->cap &
2574 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2575 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2577 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2578 * zero in VHT IE. Using it would result in degraded throughput.
2579 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2580 * it if VHT max_mpdu is smaller.
2582 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2583 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2584 ampdu_factor)) - 1);
2586 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2587 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2589 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2590 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2592 /* Calculate peer NSS capability from VHT capabilities if STA
2595 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2596 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2599 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2603 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2604 arg->peer_vht_rates.rx_max_rate =
2605 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2606 arg->peer_vht_rates.rx_mcs_set =
2607 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2608 arg->peer_vht_rates.tx_max_rate =
2609 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2610 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2611 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2613 /* Configure bandwidth-NSS mapping to FW
2614 * for the chip's tx chains setting on 160Mhz bw
2616 if (arg->peer_phymode == MODE_11AC_VHT160 ||
2617 arg->peer_phymode == MODE_11AC_VHT80_80) {
2621 max_rate = arg->peer_vht_rates.rx_max_rate;
2622 rx_nss = get_160mhz_nss_from_maxrate(max_rate);
2625 rx_nss = arg->peer_num_spatial_streams;
2627 rx_nss = min(arg->peer_num_spatial_streams, rx_nss);
2629 max_rate = hw->vht160_mcs_tx_highest;
2630 rx_nss = min(rx_nss, get_160mhz_nss_from_maxrate(max_rate));
2632 arg->peer_bw_rxnss_override =
2633 FIELD_PREP(WMI_PEER_NSS_MAP_ENABLE, 1) |
2634 FIELD_PREP(WMI_PEER_NSS_160MHZ_MASK, (rx_nss - 1));
2636 if (arg->peer_phymode == MODE_11AC_VHT80_80) {
2637 arg->peer_bw_rxnss_override |=
2638 FIELD_PREP(WMI_PEER_NSS_80_80MHZ_MASK, (rx_nss - 1));
2641 ath10k_dbg(ar, ATH10K_DBG_MAC,
2642 "mac vht peer %pM max_mpdu %d flags 0x%x peer_rx_nss_override 0x%x\n",
2643 sta->addr, arg->peer_max_mpdu,
2644 arg->peer_flags, arg->peer_bw_rxnss_override);
2647 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2648 struct ieee80211_vif *vif,
2649 struct ieee80211_sta *sta,
2650 struct wmi_peer_assoc_complete_arg *arg)
2652 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2654 switch (arvif->vdev_type) {
2655 case WMI_VDEV_TYPE_AP:
2657 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2659 if (sta->wme && sta->uapsd_queues) {
2660 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2661 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2664 case WMI_VDEV_TYPE_STA:
2666 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2668 case WMI_VDEV_TYPE_IBSS:
2670 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2676 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2677 sta->addr, !!(arg->peer_flags &
2678 arvif->ar->wmi.peer_flags->qos));
2681 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2683 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2684 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2687 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2688 struct ieee80211_sta *sta)
2690 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2691 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2692 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2693 return MODE_11AC_VHT160;
2694 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2695 return MODE_11AC_VHT80_80;
2697 /* not sure if this is a valid case? */
2698 return MODE_11AC_VHT160;
2702 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2703 return MODE_11AC_VHT80;
2705 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2706 return MODE_11AC_VHT40;
2708 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2709 return MODE_11AC_VHT20;
2711 return MODE_UNKNOWN;
2714 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2715 struct ieee80211_vif *vif,
2716 struct ieee80211_sta *sta,
2717 struct wmi_peer_assoc_complete_arg *arg)
2719 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2720 struct cfg80211_chan_def def;
2721 enum nl80211_band band;
2722 const u8 *ht_mcs_mask;
2723 const u16 *vht_mcs_mask;
2724 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2726 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2729 band = def.chan->band;
2730 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2731 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2734 case NL80211_BAND_2GHZ:
2735 if (sta->vht_cap.vht_supported &&
2736 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2737 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2738 phymode = MODE_11AC_VHT40;
2740 phymode = MODE_11AC_VHT20;
2741 } else if (sta->ht_cap.ht_supported &&
2742 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2743 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2744 phymode = MODE_11NG_HT40;
2746 phymode = MODE_11NG_HT20;
2747 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2754 case NL80211_BAND_5GHZ:
2758 if (sta->vht_cap.vht_supported &&
2759 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2760 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2761 } else if (sta->ht_cap.ht_supported &&
2762 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2763 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2764 phymode = MODE_11NA_HT40;
2766 phymode = MODE_11NA_HT20;
2776 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2777 sta->addr, ath10k_wmi_phymode_str(phymode));
2779 arg->peer_phymode = phymode;
2780 WARN_ON(phymode == MODE_UNKNOWN);
2783 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2784 struct ieee80211_vif *vif,
2785 struct ieee80211_sta *sta,
2786 struct wmi_peer_assoc_complete_arg *arg)
2788 lockdep_assert_held(&ar->conf_mutex);
2790 memset(arg, 0, sizeof(*arg));
2792 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2793 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2794 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2795 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2796 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2797 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2798 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2803 static const u32 ath10k_smps_map[] = {
2804 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2805 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2806 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2807 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2810 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2812 const struct ieee80211_sta_ht_cap *ht_cap)
2816 if (!ht_cap->ht_supported)
2819 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2820 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2822 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2825 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2826 ar->wmi.peer_param->smps_state,
2827 ath10k_smps_map[smps]);
2830 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2831 struct ieee80211_vif *vif,
2832 struct ieee80211_sta_vht_cap vht_cap)
2834 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2839 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2842 if (!(ar->vht_cap_info &
2843 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2844 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2845 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2846 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2849 param = ar->wmi.vdev_param->txbf;
2852 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2855 /* The following logic is correct. If a remote STA advertises support
2856 * for being a beamformer then we should enable us being a beamformee.
2859 if (ar->vht_cap_info &
2860 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2861 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2862 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2863 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2865 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2866 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2869 if (ar->vht_cap_info &
2870 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2871 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2872 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2873 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2875 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2876 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2879 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2880 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2882 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2883 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2885 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2887 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2895 static bool ath10k_mac_is_connected(struct ath10k *ar)
2897 struct ath10k_vif *arvif;
2899 list_for_each_entry(arvif, &ar->arvifs, list) {
2900 if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_STA)
2907 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2911 int tx_power_2g, tx_power_5g;
2914 lockdep_assert_held(&ar->conf_mutex);
2916 /* ath10k internally uses unit of 0.5 dBm so multiply by 2 */
2917 tx_power_2g = txpower * 2;
2918 tx_power_5g = txpower * 2;
2920 connected = ath10k_mac_is_connected(ar);
2922 if (connected && ar->tx_power_2g_limit)
2923 if (tx_power_2g > ar->tx_power_2g_limit)
2924 tx_power_2g = ar->tx_power_2g_limit;
2926 if (connected && ar->tx_power_5g_limit)
2927 if (tx_power_5g > ar->tx_power_5g_limit)
2928 tx_power_5g = ar->tx_power_5g_limit;
2930 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower 2g: %d, 5g: %d\n",
2931 tx_power_2g, tx_power_5g);
2933 param = ar->wmi.pdev_param->txpower_limit2g;
2934 ret = ath10k_wmi_pdev_set_param(ar, param, tx_power_2g);
2936 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2941 param = ar->wmi.pdev_param->txpower_limit5g;
2942 ret = ath10k_wmi_pdev_set_param(ar, param, tx_power_5g);
2944 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2952 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2954 struct ath10k_vif *arvif;
2955 int ret, txpower = -1;
2957 lockdep_assert_held(&ar->conf_mutex);
2959 list_for_each_entry(arvif, &ar->arvifs, list) {
2960 /* txpower not initialized yet? */
2961 if (arvif->txpower == INT_MIN)
2965 txpower = arvif->txpower;
2967 txpower = min(txpower, arvif->txpower);
2973 ret = ath10k_mac_txpower_setup(ar, txpower);
2975 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2983 static int ath10k_mac_set_sar_power(struct ath10k *ar)
2985 if (!ar->hw_params.dynamic_sar_support)
2988 if (!ath10k_mac_is_connected(ar))
2991 /* if connected, then arvif->txpower must be valid */
2992 return ath10k_mac_txpower_recalc(ar);
2995 static int ath10k_mac_set_sar_specs(struct ieee80211_hw *hw,
2996 const struct cfg80211_sar_specs *sar)
2998 const struct cfg80211_sar_sub_specs *sub_specs;
2999 struct ath10k *ar = hw->priv;
3003 mutex_lock(&ar->conf_mutex);
3005 if (!ar->hw_params.dynamic_sar_support) {
3010 if (!sar || sar->type != NL80211_SAR_TYPE_POWER ||
3011 sar->num_sub_specs == 0) {
3016 sub_specs = sar->sub_specs;
3018 /* 0dbm is not a practical value for ath10k, so use 0
3019 * as no SAR limitation on it.
3021 ar->tx_power_2g_limit = 0;
3022 ar->tx_power_5g_limit = 0;
3024 /* note the power is in 0.25dbm unit, while ath10k uses
3027 for (i = 0; i < sar->num_sub_specs; i++) {
3028 if (sub_specs->freq_range_index == 0)
3029 ar->tx_power_2g_limit = sub_specs->power / 2;
3030 else if (sub_specs->freq_range_index == 1)
3031 ar->tx_power_5g_limit = sub_specs->power / 2;
3036 ret = ath10k_mac_set_sar_power(ar);
3038 ath10k_warn(ar, "failed to set sar power: %d", ret);
3043 mutex_unlock(&ar->conf_mutex);
3047 /* can be called only in mac80211 callbacks due to `key_count` usage */
3048 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
3049 struct ieee80211_vif *vif,
3050 struct ieee80211_bss_conf *bss_conf)
3052 struct ath10k *ar = hw->priv;
3053 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3054 struct ieee80211_sta_ht_cap ht_cap;
3055 struct ieee80211_sta_vht_cap vht_cap;
3056 struct wmi_peer_assoc_complete_arg peer_arg;
3057 struct ieee80211_sta *ap_sta;
3060 lockdep_assert_held(&ar->conf_mutex);
3062 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
3063 arvif->vdev_id, arvif->bssid, arvif->aid);
3067 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
3069 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
3070 bss_conf->bssid, arvif->vdev_id);
3075 /* ap_sta must be accessed only within rcu section which must be left
3076 * before calling ath10k_setup_peer_smps() which might sleep.
3078 ht_cap = ap_sta->ht_cap;
3079 vht_cap = ap_sta->vht_cap;
3081 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
3083 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
3084 bss_conf->bssid, arvif->vdev_id, ret);
3091 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
3093 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
3094 bss_conf->bssid, arvif->vdev_id, ret);
3098 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
3100 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
3101 arvif->vdev_id, ret);
3105 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
3107 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
3108 arvif->vdev_id, bss_conf->bssid, ret);
3112 ath10k_dbg(ar, ATH10K_DBG_MAC,
3113 "mac vdev %d up (associated) bssid %pM aid %d\n",
3114 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
3116 WARN_ON(arvif->is_up);
3118 arvif->aid = bss_conf->aid;
3119 ether_addr_copy(arvif->bssid, bss_conf->bssid);
3121 ret = ath10k_wmi_pdev_set_param(ar,
3122 ar->wmi.pdev_param->peer_stats_info_enable, 1);
3124 ath10k_warn(ar, "failed to enable peer stats info: %d\n", ret);
3126 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
3128 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
3129 arvif->vdev_id, ret);
3133 arvif->is_up = true;
3135 ath10k_mac_set_sar_power(ar);
3137 /* Workaround: Some firmware revisions (tested with qca6174
3138 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
3139 * poked with peer param command.
3141 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
3142 ar->wmi.peer_param->dummy_var, 1);
3144 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
3145 arvif->bssid, arvif->vdev_id, ret);
3150 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
3151 struct ieee80211_vif *vif)
3153 struct ath10k *ar = hw->priv;
3154 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3155 struct ieee80211_sta_vht_cap vht_cap = {};
3158 lockdep_assert_held(&ar->conf_mutex);
3160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
3161 arvif->vdev_id, arvif->bssid);
3163 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
3165 ath10k_warn(ar, "failed to down vdev %i: %d\n",
3166 arvif->vdev_id, ret);
3168 arvif->def_wep_key_idx = -1;
3170 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
3172 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
3173 arvif->vdev_id, ret);
3177 arvif->is_up = false;
3179 ath10k_mac_txpower_recalc(ar);
3181 cancel_delayed_work_sync(&arvif->connection_loss_work);
3184 static int ath10k_new_peer_tid_config(struct ath10k *ar,
3185 struct ieee80211_sta *sta,
3186 struct ath10k_vif *arvif)
3188 struct wmi_per_peer_per_tid_cfg_arg arg = {};
3189 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3193 for (i = 0; i < ATH10K_TID_MAX; i++) {
3194 config_apply = false;
3195 if (arvif->retry_long[i] || arvif->ampdu[i] ||
3196 arvif->rate_ctrl[i] || arvif->rtscts[i]) {
3197 config_apply = true;
3199 arg.vdev_id = arvif->vdev_id;
3200 arg.retry_count = arvif->retry_long[i];
3201 arg.aggr_control = arvif->ampdu[i];
3202 arg.rate_ctrl = arvif->rate_ctrl[i];
3203 arg.rcode_flags = arvif->rate_code[i];
3205 if (arvif->rtscts[i])
3206 arg.ext_tid_cfg_bitmap =
3207 WMI_EXT_TID_RTS_CTS_CONFIG;
3209 arg.ext_tid_cfg_bitmap = 0;
3211 arg.rtscts_ctrl = arvif->rtscts[i];
3214 if (arvif->noack[i]) {
3215 arg.ack_policy = arvif->noack[i];
3216 arg.rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE;
3217 arg.aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_DISABLE;
3218 config_apply = true;
3221 /* Assign default value(-1) to newly connected station.
3222 * This is to identify station specific tid configuration not
3223 * configured for the station.
3225 arsta->retry_long[i] = -1;
3226 arsta->noack[i] = -1;
3227 arsta->ampdu[i] = -1;
3232 ether_addr_copy(arg.peer_macaddr.addr, sta->addr);
3234 ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, &arg);
3236 ath10k_warn(ar, "failed to set per tid retry/aggr config for sta %pM: %d\n",
3241 memset(&arg, 0, sizeof(arg));
3247 static int ath10k_station_assoc(struct ath10k *ar,
3248 struct ieee80211_vif *vif,
3249 struct ieee80211_sta *sta,
3252 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3253 struct wmi_peer_assoc_complete_arg peer_arg;
3256 lockdep_assert_held(&ar->conf_mutex);
3258 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
3260 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
3261 sta->addr, arvif->vdev_id, ret);
3265 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
3267 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
3268 sta->addr, arvif->vdev_id, ret);
3272 /* Re-assoc is run only to update supported rates for given station. It
3273 * doesn't make much sense to reconfigure the peer completely.
3276 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
3279 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
3280 arvif->vdev_id, ret);
3284 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
3286 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
3287 sta->addr, arvif->vdev_id, ret);
3292 arvif->num_legacy_stations++;
3293 ret = ath10k_recalc_rtscts_prot(arvif);
3295 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3296 arvif->vdev_id, ret);
3301 /* Plumb cached keys only for static WEP */
3302 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
3303 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
3305 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
3306 arvif->vdev_id, ret);
3312 if (!test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT, ar->wmi.svc_map))
3315 return ath10k_new_peer_tid_config(ar, sta, arvif);
3318 static int ath10k_station_disassoc(struct ath10k *ar,
3319 struct ieee80211_vif *vif,
3320 struct ieee80211_sta *sta)
3322 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3325 lockdep_assert_held(&ar->conf_mutex);
3328 arvif->num_legacy_stations--;
3329 ret = ath10k_recalc_rtscts_prot(arvif);
3331 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3332 arvif->vdev_id, ret);
3337 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3339 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3340 arvif->vdev_id, ret);
3351 static int ath10k_update_channel_list(struct ath10k *ar)
3353 struct ieee80211_hw *hw = ar->hw;
3354 struct ieee80211_supported_band **bands;
3355 enum nl80211_band band;
3356 struct ieee80211_channel *channel;
3357 struct wmi_scan_chan_list_arg arg = {0};
3358 struct wmi_channel_arg *ch;
3364 lockdep_assert_held(&ar->conf_mutex);
3366 bands = hw->wiphy->bands;
3367 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3371 for (i = 0; i < bands[band]->n_channels; i++) {
3372 if (bands[band]->channels[i].flags &
3373 IEEE80211_CHAN_DISABLED)
3380 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3381 arg.channels = kzalloc(len, GFP_KERNEL);
3386 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3390 for (i = 0; i < bands[band]->n_channels; i++) {
3391 channel = &bands[band]->channels[i];
3393 if (channel->flags & IEEE80211_CHAN_DISABLED)
3396 ch->allow_ht = true;
3398 /* FIXME: when should we really allow VHT? */
3399 ch->allow_vht = true;
3402 !(channel->flags & IEEE80211_CHAN_NO_IR);
3405 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3408 !!(channel->flags & IEEE80211_CHAN_RADAR);
3410 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3411 ch->passive = passive;
3413 /* the firmware is ignoring the "radar" flag of the
3414 * channel and is scanning actively using Probe Requests
3415 * on "Radar detection"/DFS channels which are not
3416 * marked as "available"
3418 ch->passive |= ch->chan_radar;
3420 ch->freq = channel->center_freq;
3421 ch->band_center_freq1 = channel->center_freq;
3423 ch->max_power = channel->max_power * 2;
3424 ch->max_reg_power = channel->max_reg_power * 2;
3425 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3426 ch->reg_class_id = 0; /* FIXME */
3428 /* FIXME: why use only legacy modes, why not any
3429 * HT/VHT modes? Would that even make any
3432 if (channel->band == NL80211_BAND_2GHZ)
3433 ch->mode = MODE_11G;
3435 ch->mode = MODE_11A;
3437 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3440 ath10k_dbg(ar, ATH10K_DBG_WMI,
3441 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3442 ch - arg.channels, arg.n_channels,
3443 ch->freq, ch->max_power, ch->max_reg_power,
3444 ch->max_antenna_gain, ch->mode);
3450 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3451 kfree(arg.channels);
3456 static enum wmi_dfs_region
3457 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3459 switch (dfs_region) {
3460 case NL80211_DFS_UNSET:
3461 return WMI_UNINIT_DFS_DOMAIN;
3462 case NL80211_DFS_FCC:
3463 return WMI_FCC_DFS_DOMAIN;
3464 case NL80211_DFS_ETSI:
3465 return WMI_ETSI_DFS_DOMAIN;
3466 case NL80211_DFS_JP:
3467 return WMI_MKK4_DFS_DOMAIN;
3469 return WMI_UNINIT_DFS_DOMAIN;
3472 static void ath10k_regd_update(struct ath10k *ar)
3474 struct reg_dmn_pair_mapping *regpair;
3476 enum wmi_dfs_region wmi_dfs_reg;
3477 enum nl80211_dfs_regions nl_dfs_reg;
3479 lockdep_assert_held(&ar->conf_mutex);
3481 ret = ath10k_update_channel_list(ar);
3483 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3485 regpair = ar->ath_common.regulatory.regpair;
3487 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3488 nl_dfs_reg = ar->dfs_detector->region;
3489 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3491 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3494 /* Target allows setting up per-band regdomain but ath_common provides
3495 * a combined one only
3497 ret = ath10k_wmi_pdev_set_regdomain(ar,
3498 regpair->reg_domain,
3499 regpair->reg_domain, /* 2ghz */
3500 regpair->reg_domain, /* 5ghz */
3501 regpair->reg_2ghz_ctl,
3502 regpair->reg_5ghz_ctl,
3505 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3508 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3509 struct ieee80211_supported_band *band)
3513 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3514 for (i = 0; i < band->n_channels; i++) {
3515 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3516 band->channels[i].center_freq > ar->high_5ghz_chan)
3517 band->channels[i].flags |=
3518 IEEE80211_CHAN_DISABLED;
3523 static void ath10k_reg_notifier(struct wiphy *wiphy,
3524 struct regulatory_request *request)
3526 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3527 struct ath10k *ar = hw->priv;
3530 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3532 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3533 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3534 request->dfs_region);
3535 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3536 request->dfs_region);
3538 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3539 request->dfs_region);
3542 mutex_lock(&ar->conf_mutex);
3543 if (ar->state == ATH10K_STATE_ON)
3544 ath10k_regd_update(ar);
3545 mutex_unlock(&ar->conf_mutex);
3547 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3548 ath10k_mac_update_channel_list(ar,
3549 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3552 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3554 spin_lock_bh(&ar->data_lock);
3555 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3556 spin_unlock_bh(&ar->data_lock);
3558 cancel_work_sync(&ar->radar_confirmation_work);
3565 enum ath10k_mac_tx_path {
3567 ATH10K_MAC_TX_HTT_MGMT,
3568 ATH10K_MAC_TX_WMI_MGMT,
3569 ATH10K_MAC_TX_UNKNOWN,
3572 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3574 lockdep_assert_held(&ar->htt.tx_lock);
3576 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3577 ar->tx_paused |= BIT(reason);
3578 ieee80211_stop_queues(ar->hw);
3581 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3582 struct ieee80211_vif *vif)
3584 struct ath10k *ar = data;
3585 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3587 if (arvif->tx_paused)
3590 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3593 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3595 lockdep_assert_held(&ar->htt.tx_lock);
3597 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3598 ar->tx_paused &= ~BIT(reason);
3603 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3604 ATH10K_ITER_RESUME_FLAGS,
3605 ath10k_mac_tx_unlock_iter,
3608 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3611 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3613 struct ath10k *ar = arvif->ar;
3615 lockdep_assert_held(&ar->htt.tx_lock);
3617 WARN_ON(reason >= BITS_PER_LONG);
3618 arvif->tx_paused |= BIT(reason);
3619 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3622 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3624 struct ath10k *ar = arvif->ar;
3626 lockdep_assert_held(&ar->htt.tx_lock);
3628 WARN_ON(reason >= BITS_PER_LONG);
3629 arvif->tx_paused &= ~BIT(reason);
3634 if (arvif->tx_paused)
3637 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3640 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3641 enum wmi_tlv_tx_pause_id pause_id,
3642 enum wmi_tlv_tx_pause_action action)
3644 struct ath10k *ar = arvif->ar;
3646 lockdep_assert_held(&ar->htt.tx_lock);
3649 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3650 ath10k_mac_vif_tx_lock(arvif, pause_id);
3652 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3653 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3656 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3657 "received unknown tx pause action %d on vdev %i, ignoring\n",
3658 action, arvif->vdev_id);
3663 struct ath10k_mac_tx_pause {
3665 enum wmi_tlv_tx_pause_id pause_id;
3666 enum wmi_tlv_tx_pause_action action;
3669 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3670 struct ieee80211_vif *vif)
3672 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3673 struct ath10k_mac_tx_pause *arg = data;
3675 if (arvif->vdev_id != arg->vdev_id)
3678 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3681 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3682 enum wmi_tlv_tx_pause_id pause_id,
3683 enum wmi_tlv_tx_pause_action action)
3685 struct ath10k_mac_tx_pause arg = {
3687 .pause_id = pause_id,
3691 spin_lock_bh(&ar->htt.tx_lock);
3692 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3693 ATH10K_ITER_RESUME_FLAGS,
3694 ath10k_mac_handle_tx_pause_iter,
3696 spin_unlock_bh(&ar->htt.tx_lock);
3699 static enum ath10k_hw_txrx_mode
3700 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3701 struct ieee80211_vif *vif,
3702 struct ieee80211_sta *sta,
3703 struct sk_buff *skb)
3705 const struct ieee80211_hdr *hdr = (void *)skb->data;
3706 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
3707 __le16 fc = hdr->frame_control;
3709 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3710 return ATH10K_HW_TXRX_RAW;
3712 if (ieee80211_is_mgmt(fc))
3713 return ATH10K_HW_TXRX_MGMT;
3717 * NullFunc frames are mostly used to ping if a client or AP are still
3718 * reachable and responsive. This implies tx status reports must be
3719 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3720 * come to a conclusion that the other end disappeared and tear down
3721 * BSS connection or it can never disconnect from BSS/client (which is
3724 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3725 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3726 * which seems to deliver correct tx reports for NullFunc frames. The
3727 * downside of using it is it ignores client powersave state so it can
3728 * end up disconnecting sleeping clients in AP mode. It should fix STA
3729 * mode though because AP don't sleep.
3731 if (ar->htt.target_version_major < 3 &&
3732 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3733 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3734 ar->running_fw->fw_file.fw_features))
3735 return ATH10K_HW_TXRX_MGMT;
3739 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3740 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3741 * to work with Ethernet txmode so use it.
3743 * FIXME: Check if raw mode works with TDLS.
3745 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3746 return ATH10K_HW_TXRX_ETHERNET;
3748 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) ||
3749 skb_cb->flags & ATH10K_SKB_F_RAW_TX)
3750 return ATH10K_HW_TXRX_RAW;
3752 return ATH10K_HW_TXRX_NATIVE_WIFI;
3755 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3756 struct sk_buff *skb)
3758 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3759 const struct ieee80211_hdr *hdr = (void *)skb->data;
3760 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3761 IEEE80211_TX_CTL_INJECTED;
3763 if (!ieee80211_has_protected(hdr->frame_control))
3766 if ((info->flags & mask) == mask)
3770 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3775 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3776 * Control in the header.
3778 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3780 struct ieee80211_hdr *hdr = (void *)skb->data;
3781 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3784 if (!ieee80211_is_data_qos(hdr->frame_control))
3787 qos_ctl = ieee80211_get_qos_ctl(hdr);
3788 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3789 skb->data, (void *)qos_ctl - (void *)skb->data);
3790 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3792 /* Some firmware revisions don't handle sending QoS NullFunc well.
3793 * These frames are mainly used for CQM purposes so it doesn't really
3794 * matter whether QoS NullFunc or NullFunc are sent.
3796 hdr = (void *)skb->data;
3797 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3798 cb->flags &= ~ATH10K_SKB_F_QOS;
3800 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3803 static void ath10k_tx_h_8023(struct sk_buff *skb)
3805 struct ieee80211_hdr *hdr;
3806 struct rfc1042_hdr *rfc1042;
3813 hdr = (void *)skb->data;
3814 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3815 rfc1042 = (void *)skb->data + hdrlen;
3817 ether_addr_copy(da, ieee80211_get_DA(hdr));
3818 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3819 type = rfc1042->snap_type;
3821 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3822 skb_push(skb, sizeof(*eth));
3824 eth = (void *)skb->data;
3825 ether_addr_copy(eth->h_dest, da);
3826 ether_addr_copy(eth->h_source, sa);
3827 eth->h_proto = type;
3830 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3831 struct ieee80211_vif *vif,
3832 struct sk_buff *skb)
3834 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3835 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3837 /* This is case only for P2P_GO */
3838 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3841 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3842 spin_lock_bh(&ar->data_lock);
3843 if (arvif->u.ap.noa_data)
3844 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3846 skb_put_data(skb, arvif->u.ap.noa_data,
3847 arvif->u.ap.noa_len);
3848 spin_unlock_bh(&ar->data_lock);
3852 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3853 struct ieee80211_vif *vif,
3854 struct ieee80211_txq *txq,
3855 struct ieee80211_sta *sta,
3856 struct sk_buff *skb, u16 airtime)
3858 struct ieee80211_hdr *hdr = (void *)skb->data;
3859 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3860 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3861 bool is_data = ieee80211_is_data(hdr->frame_control) ||
3862 ieee80211_is_data_qos(hdr->frame_control);
3863 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3864 struct ath10k_sta *arsta;
3869 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3870 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3872 if (ieee80211_is_mgmt(hdr->frame_control))
3873 cb->flags |= ATH10K_SKB_F_MGMT;
3875 if (ieee80211_is_data_qos(hdr->frame_control)) {
3876 cb->flags |= ATH10K_SKB_F_QOS;
3877 qos_ctl = ieee80211_get_qos_ctl(hdr);
3878 tid = (*qos_ctl) & IEEE80211_QOS_CTL_TID_MASK;
3880 if (arvif->noack[tid] == WMI_PEER_TID_CONFIG_NOACK)
3884 arsta = (struct ath10k_sta *)sta->drv_priv;
3886 if (arsta->noack[tid] == WMI_PEER_TID_CONFIG_NOACK)
3889 if (arsta->noack[tid] == WMI_PEER_TID_CONFIG_ACK)
3894 cb->flags |= ATH10K_SKB_F_NOACK_TID;
3897 /* Data frames encrypted in software will be posted to firmware
3898 * with tx encap mode set to RAW. Ex: Multicast traffic generated
3899 * for a specific VLAN group will always be encrypted in software.
3901 if (is_data && ieee80211_has_protected(hdr->frame_control) &&
3902 !info->control.hw_key) {
3903 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3904 cb->flags |= ATH10K_SKB_F_RAW_TX;
3909 cb->airtime_est = airtime;
3911 arsta = (struct ath10k_sta *)sta->drv_priv;
3912 spin_lock_bh(&ar->data_lock);
3913 cb->ucast_cipher = arsta->ucast_cipher;
3914 spin_unlock_bh(&ar->data_lock);
3918 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3920 /* FIXME: Not really sure since when the behaviour changed. At some
3921 * point new firmware stopped requiring creation of peer entries for
3922 * offchannel tx (and actually creating them causes issues with wmi-htc
3923 * tx credit replenishment and reliability). Assuming it's at least 3.4
3924 * because that's when the `freq` was introduced to TX_FRM HTT command.
3926 return (ar->htt.target_version_major >= 3 &&
3927 ar->htt.target_version_minor >= 4 &&
3928 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3931 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3933 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3935 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3936 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3940 skb_queue_tail(q, skb);
3941 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3946 static enum ath10k_mac_tx_path
3947 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3948 struct sk_buff *skb,
3949 enum ath10k_hw_txrx_mode txmode)
3952 case ATH10K_HW_TXRX_RAW:
3953 case ATH10K_HW_TXRX_NATIVE_WIFI:
3954 case ATH10K_HW_TXRX_ETHERNET:
3955 return ATH10K_MAC_TX_HTT;
3956 case ATH10K_HW_TXRX_MGMT:
3957 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3958 ar->running_fw->fw_file.fw_features) ||
3959 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3961 return ATH10K_MAC_TX_WMI_MGMT;
3962 else if (ar->htt.target_version_major >= 3)
3963 return ATH10K_MAC_TX_HTT;
3965 return ATH10K_MAC_TX_HTT_MGMT;
3968 return ATH10K_MAC_TX_UNKNOWN;
3971 static int ath10k_mac_tx_submit(struct ath10k *ar,
3972 enum ath10k_hw_txrx_mode txmode,
3973 enum ath10k_mac_tx_path txpath,
3974 struct sk_buff *skb)
3976 struct ath10k_htt *htt = &ar->htt;
3980 case ATH10K_MAC_TX_HTT:
3981 ret = ath10k_htt_tx(htt, txmode, skb);
3983 case ATH10K_MAC_TX_HTT_MGMT:
3984 ret = ath10k_htt_mgmt_tx(htt, skb);
3986 case ATH10K_MAC_TX_WMI_MGMT:
3987 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3989 case ATH10K_MAC_TX_UNKNOWN:
3996 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3998 ieee80211_free_txskb(ar->hw, skb);
4004 /* This function consumes the sk_buff regardless of return value as far as
4005 * caller is concerned so no freeing is necessary afterwards.
4007 static int ath10k_mac_tx(struct ath10k *ar,
4008 struct ieee80211_vif *vif,
4009 enum ath10k_hw_txrx_mode txmode,
4010 enum ath10k_mac_tx_path txpath,
4011 struct sk_buff *skb, bool noque_offchan)
4013 struct ieee80211_hw *hw = ar->hw;
4014 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4015 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
4018 /* We should disable CCK RATE due to P2P */
4019 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
4020 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
4023 case ATH10K_HW_TXRX_MGMT:
4024 case ATH10K_HW_TXRX_NATIVE_WIFI:
4025 ath10k_tx_h_nwifi(hw, skb);
4026 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
4027 ath10k_tx_h_seq_no(vif, skb);
4029 case ATH10K_HW_TXRX_ETHERNET:
4030 ath10k_tx_h_8023(skb);
4032 case ATH10K_HW_TXRX_RAW:
4033 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) &&
4034 !(skb_cb->flags & ATH10K_SKB_F_RAW_TX)) {
4036 ieee80211_free_txskb(hw, skb);
4041 if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
4042 if (!ath10k_mac_tx_frm_has_freq(ar)) {
4043 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n",
4046 skb_queue_tail(&ar->offchan_tx_queue, skb);
4047 ieee80211_queue_work(hw, &ar->offchan_tx_work);
4052 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
4054 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
4061 void ath10k_offchan_tx_purge(struct ath10k *ar)
4063 struct sk_buff *skb;
4066 skb = skb_dequeue(&ar->offchan_tx_queue);
4070 ieee80211_free_txskb(ar->hw, skb);
4074 void ath10k_offchan_tx_work(struct work_struct *work)
4076 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
4077 struct ath10k_peer *peer;
4078 struct ath10k_vif *arvif;
4079 enum ath10k_hw_txrx_mode txmode;
4080 enum ath10k_mac_tx_path txpath;
4081 struct ieee80211_hdr *hdr;
4082 struct ieee80211_vif *vif;
4083 struct ieee80211_sta *sta;
4084 struct sk_buff *skb;
4085 const u8 *peer_addr;
4088 unsigned long time_left;
4089 bool tmp_peer_created = false;
4091 /* FW requirement: We must create a peer before FW will send out
4092 * an offchannel frame. Otherwise the frame will be stuck and
4093 * never transmitted. We delete the peer upon tx completion.
4094 * It is unlikely that a peer for offchannel tx will already be
4095 * present. However it may be in some rare cases so account for that.
4096 * Otherwise we might remove a legitimate peer and break stuff.
4100 skb = skb_dequeue(&ar->offchan_tx_queue);
4104 mutex_lock(&ar->conf_mutex);
4106 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n",
4109 hdr = (struct ieee80211_hdr *)skb->data;
4110 peer_addr = ieee80211_get_DA(hdr);
4112 spin_lock_bh(&ar->data_lock);
4113 vdev_id = ar->scan.vdev_id;
4114 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
4115 spin_unlock_bh(&ar->data_lock);
4118 ath10k_warn(ar, "peer %pM on vdev %d already present\n",
4119 peer_addr, vdev_id);
4122 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
4124 WMI_PEER_TYPE_DEFAULT);
4126 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
4127 peer_addr, vdev_id, ret);
4128 tmp_peer_created = (ret == 0);
4131 spin_lock_bh(&ar->data_lock);
4132 reinit_completion(&ar->offchan_tx_completed);
4133 ar->offchan_tx_skb = skb;
4134 spin_unlock_bh(&ar->data_lock);
4136 /* It's safe to access vif and sta - conf_mutex guarantees that
4137 * sta_state() and remove_interface() are locked exclusively
4138 * out wrt to this offchannel worker.
4140 arvif = ath10k_get_arvif(ar, vdev_id);
4143 sta = ieee80211_find_sta(vif, peer_addr);
4149 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4150 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4152 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true);
4154 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
4160 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
4162 ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n",
4165 if (!peer && tmp_peer_created) {
4166 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
4168 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
4169 peer_addr, vdev_id, ret);
4172 mutex_unlock(&ar->conf_mutex);
4176 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
4178 struct sk_buff *skb;
4181 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
4185 ieee80211_free_txskb(ar->hw, skb);
4189 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
4191 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
4192 struct sk_buff *skb;
4197 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
4201 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
4202 ar->running_fw->fw_file.fw_features)) {
4203 paddr = dma_map_single(ar->dev, skb->data,
4204 skb->len, DMA_TO_DEVICE);
4205 if (dma_mapping_error(ar->dev, paddr)) {
4206 ieee80211_free_txskb(ar->hw, skb);
4209 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
4211 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
4213 /* remove this msdu from idr tracking */
4214 ath10k_wmi_cleanup_mgmt_tx_send(ar, skb);
4216 dma_unmap_single(ar->dev, paddr, skb->len,
4218 ieee80211_free_txskb(ar->hw, skb);
4221 ret = ath10k_wmi_mgmt_tx(ar, skb);
4223 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
4225 ieee80211_free_txskb(ar->hw, skb);
4231 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
4233 struct ath10k_txq *artxq;
4238 artxq = (void *)txq->drv_priv;
4239 INIT_LIST_HEAD(&artxq->list);
4242 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
4244 struct ath10k_skb_cb *cb;
4245 struct sk_buff *msdu;
4251 spin_lock_bh(&ar->htt.tx_lock);
4252 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
4253 cb = ATH10K_SKB_CB(msdu);
4257 spin_unlock_bh(&ar->htt.tx_lock);
4260 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
4264 struct ath10k_peer *peer;
4266 lockdep_assert_held(&ar->data_lock);
4268 peer = ar->peer_map[peer_id];
4276 return peer->sta->txq[tid];
4278 return peer->vif->txq;
4283 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
4284 struct ieee80211_txq *txq)
4286 struct ath10k *ar = hw->priv;
4287 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4289 /* No need to get locks */
4290 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
4293 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
4296 if (artxq->num_fw_queued < artxq->num_push_allowed)
4302 /* Return estimated airtime in microsecond, which is calculated using last
4303 * reported TX rate. This is just a rough estimation because host driver has no
4304 * knowledge of the actual transmit rate, retries or aggregation. If actual
4305 * airtime can be reported by firmware, then delta between estimated and actual
4306 * airtime can be adjusted from deficit.
4308 #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
4309 #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
4310 static u16 ath10k_mac_update_airtime(struct ath10k *ar,
4311 struct ieee80211_txq *txq,
4312 struct sk_buff *skb)
4314 struct ath10k_sta *arsta;
4318 if (!txq || !txq->sta)
4321 if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
4324 spin_lock_bh(&ar->data_lock);
4325 arsta = (struct ath10k_sta *)txq->sta->drv_priv;
4327 pktlen = skb->len + 38; /* Assume MAC header 30, SNAP 8 for most case */
4328 if (arsta->last_tx_bitrate) {
4329 /* airtime in us, last_tx_bitrate in 100kbps */
4330 airtime = (pktlen * 8 * (1000 / 100))
4331 / arsta->last_tx_bitrate;
4332 /* overhead for media access time and IFS */
4333 airtime += IEEE80211_ATF_OVERHEAD_IFS;
4335 /* This is mostly for throttle excessive BC/MC frames, and the
4336 * airtime/rate doesn't need be exact. Airtime of BC/MC frames
4337 * in 2G get some discount, which helps prevent very low rate
4338 * frames from being blocked for too long.
4340 airtime = (pktlen * 8 * (1000 / 100)) / 60; /* 6M */
4341 airtime += IEEE80211_ATF_OVERHEAD;
4343 spin_unlock_bh(&ar->data_lock);
4348 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
4349 struct ieee80211_txq *txq)
4351 struct ath10k *ar = hw->priv;
4352 struct ath10k_htt *htt = &ar->htt;
4353 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4354 struct ieee80211_vif *vif = txq->vif;
4355 struct ieee80211_sta *sta = txq->sta;
4356 enum ath10k_hw_txrx_mode txmode;
4357 enum ath10k_mac_tx_path txpath;
4358 struct sk_buff *skb;
4359 struct ieee80211_hdr *hdr;
4361 bool is_mgmt, is_presp;
4365 spin_lock_bh(&ar->htt.tx_lock);
4366 ret = ath10k_htt_tx_inc_pending(htt);
4367 spin_unlock_bh(&ar->htt.tx_lock);
4372 skb = ieee80211_tx_dequeue_ni(hw, txq);
4374 spin_lock_bh(&ar->htt.tx_lock);
4375 ath10k_htt_tx_dec_pending(htt);
4376 spin_unlock_bh(&ar->htt.tx_lock);
4381 airtime = ath10k_mac_update_airtime(ar, txq, skb);
4382 ath10k_mac_tx_h_fill_cb(ar, vif, txq, sta, skb, airtime);
4385 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4386 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4387 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4390 hdr = (struct ieee80211_hdr *)skb->data;
4391 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4393 spin_lock_bh(&ar->htt.tx_lock);
4394 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4397 ath10k_htt_tx_dec_pending(htt);
4398 spin_unlock_bh(&ar->htt.tx_lock);
4401 spin_unlock_bh(&ar->htt.tx_lock);
4404 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4405 if (unlikely(ret)) {
4406 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4408 spin_lock_bh(&ar->htt.tx_lock);
4409 ath10k_htt_tx_dec_pending(htt);
4411 ath10k_htt_tx_mgmt_dec_pending(htt);
4412 spin_unlock_bh(&ar->htt.tx_lock);
4417 spin_lock_bh(&ar->htt.tx_lock);
4418 artxq->num_fw_queued++;
4419 spin_unlock_bh(&ar->htt.tx_lock);
4424 static int ath10k_mac_schedule_txq(struct ieee80211_hw *hw, u32 ac)
4426 struct ieee80211_txq *txq;
4429 ieee80211_txq_schedule_start(hw, ac);
4430 while ((txq = ieee80211_next_txq(hw, ac))) {
4431 while (ath10k_mac_tx_can_push(hw, txq)) {
4432 ret = ath10k_mac_tx_push_txq(hw, txq);
4436 ieee80211_return_txq(hw, txq, false);
4437 ath10k_htt_tx_txq_update(hw, txq);
4441 ieee80211_txq_schedule_end(hw, ac);
4446 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4448 struct ieee80211_hw *hw = ar->hw;
4451 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4454 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4458 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4459 if (ath10k_mac_schedule_txq(hw, ac) == -EBUSY)
4464 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4470 void __ath10k_scan_finish(struct ath10k *ar)
4472 lockdep_assert_held(&ar->data_lock);
4474 switch (ar->scan.state) {
4475 case ATH10K_SCAN_IDLE:
4477 case ATH10K_SCAN_RUNNING:
4478 case ATH10K_SCAN_ABORTING:
4479 if (!ar->scan.is_roc) {
4480 struct cfg80211_scan_info info = {
4481 .aborted = (ar->scan.state ==
4482 ATH10K_SCAN_ABORTING),
4485 ieee80211_scan_completed(ar->hw, &info);
4486 } else if (ar->scan.roc_notify) {
4487 ieee80211_remain_on_channel_expired(ar->hw);
4490 case ATH10K_SCAN_STARTING:
4491 ar->scan.state = ATH10K_SCAN_IDLE;
4492 ar->scan_channel = NULL;
4493 ar->scan.roc_freq = 0;
4494 ath10k_offchan_tx_purge(ar);
4495 cancel_delayed_work(&ar->scan.timeout);
4496 complete(&ar->scan.completed);
4501 void ath10k_scan_finish(struct ath10k *ar)
4503 spin_lock_bh(&ar->data_lock);
4504 __ath10k_scan_finish(ar);
4505 spin_unlock_bh(&ar->data_lock);
4508 static int ath10k_scan_stop(struct ath10k *ar)
4510 struct wmi_stop_scan_arg arg = {
4511 .req_id = 1, /* FIXME */
4512 .req_type = WMI_SCAN_STOP_ONE,
4513 .u.scan_id = ATH10K_SCAN_ID,
4517 lockdep_assert_held(&ar->conf_mutex);
4519 ret = ath10k_wmi_stop_scan(ar, &arg);
4521 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4525 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4527 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4529 } else if (ret > 0) {
4534 /* Scan state should be updated upon scan completion but in case
4535 * firmware fails to deliver the event (for whatever reason) it is
4536 * desired to clean up scan state anyway. Firmware may have just
4537 * dropped the scan completion event delivery due to transport pipe
4538 * being overflown with data and/or it can recover on its own before
4539 * next scan request is submitted.
4541 spin_lock_bh(&ar->data_lock);
4542 if (ar->scan.state != ATH10K_SCAN_IDLE)
4543 __ath10k_scan_finish(ar);
4544 spin_unlock_bh(&ar->data_lock);
4549 static void ath10k_scan_abort(struct ath10k *ar)
4553 lockdep_assert_held(&ar->conf_mutex);
4555 spin_lock_bh(&ar->data_lock);
4557 switch (ar->scan.state) {
4558 case ATH10K_SCAN_IDLE:
4559 /* This can happen if timeout worker kicked in and called
4560 * abortion while scan completion was being processed.
4563 case ATH10K_SCAN_STARTING:
4564 case ATH10K_SCAN_ABORTING:
4565 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4566 ath10k_scan_state_str(ar->scan.state),
4569 case ATH10K_SCAN_RUNNING:
4570 ar->scan.state = ATH10K_SCAN_ABORTING;
4571 spin_unlock_bh(&ar->data_lock);
4573 ret = ath10k_scan_stop(ar);
4575 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4577 spin_lock_bh(&ar->data_lock);
4581 spin_unlock_bh(&ar->data_lock);
4584 void ath10k_scan_timeout_work(struct work_struct *work)
4586 struct ath10k *ar = container_of(work, struct ath10k,
4589 mutex_lock(&ar->conf_mutex);
4590 ath10k_scan_abort(ar);
4591 mutex_unlock(&ar->conf_mutex);
4594 static int ath10k_start_scan(struct ath10k *ar,
4595 const struct wmi_start_scan_arg *arg)
4599 lockdep_assert_held(&ar->conf_mutex);
4601 ret = ath10k_wmi_start_scan(ar, arg);
4605 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4607 ret = ath10k_scan_stop(ar);
4609 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4614 /* If we failed to start the scan, return error code at
4615 * this point. This is probably due to some issue in the
4616 * firmware, but no need to wedge the driver due to that...
4618 spin_lock_bh(&ar->data_lock);
4619 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4620 spin_unlock_bh(&ar->data_lock);
4623 spin_unlock_bh(&ar->data_lock);
4628 /**********************/
4629 /* mac80211 callbacks */
4630 /**********************/
4632 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4633 struct ieee80211_tx_control *control,
4634 struct sk_buff *skb)
4636 struct ath10k *ar = hw->priv;
4637 struct ath10k_htt *htt = &ar->htt;
4638 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4639 struct ieee80211_vif *vif = info->control.vif;
4640 struct ieee80211_sta *sta = control->sta;
4641 struct ieee80211_txq *txq = NULL;
4642 struct ieee80211_hdr *hdr = (void *)skb->data;
4643 enum ath10k_hw_txrx_mode txmode;
4644 enum ath10k_mac_tx_path txpath;
4651 airtime = ath10k_mac_update_airtime(ar, txq, skb);
4652 ath10k_mac_tx_h_fill_cb(ar, vif, txq, sta, skb, airtime);
4654 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4655 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4656 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4657 txpath == ATH10K_MAC_TX_HTT_MGMT);
4658 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4661 spin_lock_bh(&ar->htt.tx_lock);
4662 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4664 ret = ath10k_htt_tx_inc_pending(htt);
4666 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4668 spin_unlock_bh(&ar->htt.tx_lock);
4669 ieee80211_free_txskb(ar->hw, skb);
4673 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4675 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4677 ath10k_htt_tx_dec_pending(htt);
4678 spin_unlock_bh(&ar->htt.tx_lock);
4679 ieee80211_free_txskb(ar->hw, skb);
4682 spin_unlock_bh(&ar->htt.tx_lock);
4685 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4687 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4689 spin_lock_bh(&ar->htt.tx_lock);
4690 ath10k_htt_tx_dec_pending(htt);
4692 ath10k_htt_tx_mgmt_dec_pending(htt);
4693 spin_unlock_bh(&ar->htt.tx_lock);
4699 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4700 struct ieee80211_txq *txq)
4702 struct ath10k *ar = hw->priv;
4706 ath10k_htt_tx_txq_update(hw, txq);
4707 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4711 ieee80211_txq_schedule_start(hw, ac);
4712 txq = ieee80211_next_txq(hw, ac);
4716 while (ath10k_mac_tx_can_push(hw, txq)) {
4717 ret = ath10k_mac_tx_push_txq(hw, txq);
4721 ieee80211_return_txq(hw, txq, false);
4722 ath10k_htt_tx_txq_update(hw, txq);
4724 ieee80211_txq_schedule_end(hw, ac);
4727 /* Must not be called with conf_mutex held as workers can use that also. */
4728 void ath10k_drain_tx(struct ath10k *ar)
4730 lockdep_assert_not_held(&ar->conf_mutex);
4732 /* make sure rcu-protected mac80211 tx path itself is drained */
4735 ath10k_offchan_tx_purge(ar);
4736 ath10k_mgmt_over_wmi_tx_purge(ar);
4738 cancel_work_sync(&ar->offchan_tx_work);
4739 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4742 void ath10k_halt(struct ath10k *ar)
4744 struct ath10k_vif *arvif;
4746 lockdep_assert_held(&ar->conf_mutex);
4748 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4749 ar->filter_flags = 0;
4750 ar->monitor = false;
4751 ar->monitor_arvif = NULL;
4753 if (ar->monitor_started)
4754 ath10k_monitor_stop(ar);
4756 ar->monitor_started = false;
4759 ath10k_scan_finish(ar);
4760 ath10k_peer_cleanup_all(ar);
4761 ath10k_stop_radar_confirmation(ar);
4762 ath10k_core_stop(ar);
4763 ath10k_hif_power_down(ar);
4765 spin_lock_bh(&ar->data_lock);
4766 list_for_each_entry(arvif, &ar->arvifs, list)
4767 ath10k_mac_vif_beacon_cleanup(arvif);
4768 spin_unlock_bh(&ar->data_lock);
4771 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4773 struct ath10k *ar = hw->priv;
4775 mutex_lock(&ar->conf_mutex);
4777 *tx_ant = ar->cfg_tx_chainmask;
4778 *rx_ant = ar->cfg_rx_chainmask;
4780 mutex_unlock(&ar->conf_mutex);
4785 static bool ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4787 /* It is not clear that allowing gaps in chainmask
4788 * is helpful. Probably it will not do what user
4789 * is hoping for, so warn in that case.
4791 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4794 ath10k_warn(ar, "mac %s antenna chainmask is invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4799 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4801 int nsts = ar->vht_cap_info;
4803 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4804 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4806 /* If firmware does not deliver to host number of space-time
4807 * streams supported, assume it support up to 4 BF STS and return
4808 * the value for VHT CAP: nsts-1)
4816 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4818 int sound_dim = ar->vht_cap_info;
4820 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4821 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4823 /* If the sounding dimension is not advertised by the firmware,
4824 * let's use a default value of 1
4832 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4834 struct ieee80211_sta_vht_cap vht_cap = {0};
4835 struct ath10k_hw_params *hw = &ar->hw_params;
4840 vht_cap.vht_supported = 1;
4841 vht_cap.cap = ar->vht_cap_info;
4843 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4844 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4845 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4846 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4847 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4852 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4853 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4854 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4855 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4856 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4862 for (i = 0; i < 8; i++) {
4863 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4864 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4866 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4869 if (ar->cfg_tx_chainmask <= 1)
4870 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4872 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4873 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4875 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4876 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4877 * user-space a clue if that is the case.
4879 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4880 (hw->vht160_mcs_rx_highest != 0 ||
4881 hw->vht160_mcs_tx_highest != 0)) {
4882 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4883 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4889 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4892 struct ieee80211_sta_ht_cap ht_cap = {0};
4894 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4897 ht_cap.ht_supported = 1;
4898 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4899 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4900 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4901 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4903 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4905 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4906 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4908 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4909 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4911 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4914 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4915 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4920 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4921 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4923 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4926 stbc = ar->ht_cap_info;
4927 stbc &= WMI_HT_CAP_RX_STBC;
4928 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4929 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4930 stbc &= IEEE80211_HT_CAP_RX_STBC;
4935 if (ar->ht_cap_info & WMI_HT_CAP_LDPC || (ar->ht_cap_info &
4936 WMI_HT_CAP_RX_LDPC && (ar->ht_cap_info & WMI_HT_CAP_TX_LDPC)))
4937 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4939 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4940 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4942 /* max AMSDU is implicitly taken from vht_cap_info */
4943 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4944 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4946 for (i = 0; i < ar->num_rf_chains; i++) {
4947 if (ar->cfg_rx_chainmask & BIT(i))
4948 ht_cap.mcs.rx_mask[i] = 0xFF;
4951 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4956 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4958 struct ieee80211_supported_band *band;
4959 struct ieee80211_sta_vht_cap vht_cap;
4960 struct ieee80211_sta_ht_cap ht_cap;
4962 ht_cap = ath10k_get_ht_cap(ar);
4963 vht_cap = ath10k_create_vht_cap(ar);
4965 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4966 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4967 band->ht_cap = ht_cap;
4969 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4970 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4971 band->ht_cap = ht_cap;
4972 band->vht_cap = vht_cap;
4976 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4979 bool is_valid_tx_chain_mask, is_valid_rx_chain_mask;
4981 lockdep_assert_held(&ar->conf_mutex);
4983 is_valid_tx_chain_mask = ath10k_check_chain_mask(ar, tx_ant, "tx");
4984 is_valid_rx_chain_mask = ath10k_check_chain_mask(ar, rx_ant, "rx");
4986 if (!is_valid_tx_chain_mask || !is_valid_rx_chain_mask)
4989 ar->cfg_tx_chainmask = tx_ant;
4990 ar->cfg_rx_chainmask = rx_ant;
4992 if ((ar->state != ATH10K_STATE_ON) &&
4993 (ar->state != ATH10K_STATE_RESTARTED))
4996 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4999 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
5004 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
5007 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
5012 /* Reload HT/VHT capability */
5013 ath10k_mac_setup_ht_vht_cap(ar);
5018 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
5020 struct ath10k *ar = hw->priv;
5023 mutex_lock(&ar->conf_mutex);
5024 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
5025 mutex_unlock(&ar->conf_mutex);
5029 static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar,
5030 struct wmi_bb_timing_cfg_arg *bb_timing)
5032 struct device_node *node;
5033 const char *fem_name;
5036 node = ar->dev->of_node;
5040 ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name);
5045 * If external Front End module used in hardware, then default base band timing
5046 * parameter cannot be used since they were fine tuned for reference hardware,
5047 * so choosing different value suitable for that external FEM.
5049 if (!strcmp("microsemi-lx5586", fem_name)) {
5050 bb_timing->bb_tx_timing = 0x00;
5051 bb_timing->bb_xpa_timing = 0x0101;
5056 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
5057 bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing);
5061 static int ath10k_mac_rfkill_config(struct ath10k *ar)
5066 if (ar->hw_values->rfkill_pin == 0) {
5067 ath10k_warn(ar, "ath10k does not support hardware rfkill with this device\n");
5071 ath10k_dbg(ar, ATH10K_DBG_MAC,
5072 "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
5073 ar->hw_values->rfkill_pin, ar->hw_values->rfkill_cfg,
5074 ar->hw_values->rfkill_on_level);
5076 param = FIELD_PREP(WMI_TLV_RFKILL_CFG_RADIO_LEVEL,
5077 ar->hw_values->rfkill_on_level) |
5078 FIELD_PREP(WMI_TLV_RFKILL_CFG_GPIO_PIN_NUM,
5079 ar->hw_values->rfkill_pin) |
5080 FIELD_PREP(WMI_TLV_RFKILL_CFG_PIN_AS_GPIO,
5081 ar->hw_values->rfkill_cfg);
5083 ret = ath10k_wmi_pdev_set_param(ar,
5084 ar->wmi.pdev_param->rfkill_config,
5088 "failed to set rfkill config 0x%x: %d\n",
5095 int ath10k_mac_rfkill_enable_radio(struct ath10k *ar, bool enable)
5097 enum wmi_tlv_rfkill_enable_radio param;
5101 param = WMI_TLV_RFKILL_ENABLE_RADIO_ON;
5103 param = WMI_TLV_RFKILL_ENABLE_RADIO_OFF;
5105 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac rfkill enable %d", param);
5107 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rfkill_enable,
5110 ath10k_warn(ar, "failed to set rfkill enable param %d: %d\n",
5118 static int ath10k_start(struct ieee80211_hw *hw)
5120 struct ath10k *ar = hw->priv;
5123 struct wmi_bb_timing_cfg_arg bb_timing = {0};
5126 * This makes sense only when restarting hw. It is harmless to call
5127 * unconditionally. This is necessary to make sure no HTT/WMI tx
5128 * commands will be submitted while restarting.
5130 ath10k_drain_tx(ar);
5132 mutex_lock(&ar->conf_mutex);
5134 switch (ar->state) {
5135 case ATH10K_STATE_OFF:
5136 ar->state = ATH10K_STATE_ON;
5138 case ATH10K_STATE_RESTARTING:
5139 ar->state = ATH10K_STATE_RESTARTED;
5141 case ATH10K_STATE_ON:
5142 case ATH10K_STATE_RESTARTED:
5143 case ATH10K_STATE_WEDGED:
5147 case ATH10K_STATE_UTF:
5152 spin_lock_bh(&ar->data_lock);
5154 if (ar->hw_rfkill_on) {
5155 ar->hw_rfkill_on = false;
5156 spin_unlock_bh(&ar->data_lock);
5160 spin_unlock_bh(&ar->data_lock);
5162 ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
5164 ath10k_err(ar, "Could not init hif: %d\n", ret);
5168 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
5169 &ar->normal_mode_fw);
5171 ath10k_err(ar, "Could not init core: %d\n", ret);
5172 goto err_power_down;
5175 if (ar->sys_cap_info & WMI_TLV_SYS_CAP_INFO_RFKILL) {
5176 ret = ath10k_mac_rfkill_config(ar);
5177 if (ret && ret != -EOPNOTSUPP) {
5178 ath10k_warn(ar, "failed to configure rfkill: %d", ret);
5183 param = ar->wmi.pdev_param->pmf_qos;
5184 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
5186 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
5190 param = ar->wmi.pdev_param->dynamic_bw;
5191 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
5193 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
5197 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
5198 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
5200 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
5205 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
5206 ret = ath10k_wmi_adaptive_qcs(ar, true);
5208 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
5214 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
5215 param = ar->wmi.pdev_param->burst_enable;
5216 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
5218 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
5223 param = ar->wmi.pdev_param->idle_ps_config;
5224 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
5225 if (ret && ret != -EOPNOTSUPP) {
5226 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
5230 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
5233 * By default FW set ARP frames ac to voice (6). In that case ARP
5234 * exchange is not working properly for UAPSD enabled AP. ARP requests
5235 * which arrives with access category 0 are processed by network stack
5236 * and send back with access category 0, but FW changes access category
5237 * to 6. Set ARP frames access category to best effort (0) solves
5241 param = ar->wmi.pdev_param->arp_ac_override;
5242 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
5244 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
5249 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
5250 ar->running_fw->fw_file.fw_features)) {
5251 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
5252 WMI_CCA_DETECT_LEVEL_AUTO,
5253 WMI_CCA_DETECT_MARGIN_AUTO);
5255 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
5261 param = ar->wmi.pdev_param->ani_enable;
5262 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
5264 ath10k_warn(ar, "failed to enable ani by default: %d\n",
5269 ar->ani_enabled = true;
5271 if (ath10k_peer_stats_enabled(ar)) {
5272 param = ar->wmi.pdev_param->peer_stats_update_period;
5273 ret = ath10k_wmi_pdev_set_param(ar, param,
5274 PEER_DEFAULT_STATS_UPDATE_PERIOD);
5277 "failed to set peer stats period : %d\n",
5283 param = ar->wmi.pdev_param->enable_btcoex;
5284 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
5285 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
5286 ar->running_fw->fw_file.fw_features) &&
5288 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
5291 "failed to set btcoex param: %d\n", ret);
5294 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
5297 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) {
5298 ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing);
5300 ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing);
5303 "failed to set bb timings: %d\n",
5310 ar->num_started_vdevs = 0;
5311 ath10k_regd_update(ar);
5313 ath10k_spectral_start(ar);
5314 ath10k_thermal_set_throttling(ar);
5316 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
5318 mutex_unlock(&ar->conf_mutex);
5322 ath10k_core_stop(ar);
5325 ath10k_hif_power_down(ar);
5328 ar->state = ATH10K_STATE_OFF;
5331 mutex_unlock(&ar->conf_mutex);
5335 static void ath10k_stop(struct ieee80211_hw *hw)
5337 struct ath10k *ar = hw->priv;
5339 ath10k_drain_tx(ar);
5341 mutex_lock(&ar->conf_mutex);
5342 if (ar->state != ATH10K_STATE_OFF) {
5343 if (!ar->hw_rfkill_on)
5345 ar->state = ATH10K_STATE_OFF;
5347 mutex_unlock(&ar->conf_mutex);
5349 cancel_work_sync(&ar->set_coverage_class_work);
5350 cancel_delayed_work_sync(&ar->scan.timeout);
5351 cancel_work_sync(&ar->restart_work);
5354 static int ath10k_config_ps(struct ath10k *ar)
5356 struct ath10k_vif *arvif;
5359 lockdep_assert_held(&ar->conf_mutex);
5361 list_for_each_entry(arvif, &ar->arvifs, list) {
5362 ret = ath10k_mac_vif_setup_ps(arvif);
5364 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
5372 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
5374 struct ath10k *ar = hw->priv;
5375 struct ieee80211_conf *conf = &hw->conf;
5378 mutex_lock(&ar->conf_mutex);
5380 if (changed & IEEE80211_CONF_CHANGE_PS)
5381 ath10k_config_ps(ar);
5383 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
5384 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
5385 ret = ath10k_monitor_recalc(ar);
5387 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5390 mutex_unlock(&ar->conf_mutex);
5394 static u32 get_nss_from_chainmask(u16 chain_mask)
5396 if ((chain_mask & 0xf) == 0xf)
5398 else if ((chain_mask & 0x7) == 0x7)
5400 else if ((chain_mask & 0x3) == 0x3)
5405 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
5408 struct ath10k *ar = arvif->ar;
5412 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
5415 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
5416 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5417 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
5418 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
5420 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
5421 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5422 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
5423 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
5428 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
5429 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
5431 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
5432 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
5433 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
5435 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
5436 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
5438 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
5439 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
5440 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
5442 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5443 ar->wmi.vdev_param->txbf, value);
5448 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5449 * because we will send mgmt frames without CCK. This requirement
5450 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5453 static int ath10k_add_interface(struct ieee80211_hw *hw,
5454 struct ieee80211_vif *vif)
5456 struct ath10k *ar = hw->priv;
5457 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5458 struct ath10k_peer *peer;
5459 enum wmi_sta_powersave_param param;
5466 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5468 mutex_lock(&ar->conf_mutex);
5470 memset(arvif, 0, sizeof(*arvif));
5471 ath10k_mac_txq_init(vif->txq);
5476 INIT_LIST_HEAD(&arvif->list);
5477 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5478 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5479 ath10k_mac_vif_sta_connection_loss_work);
5481 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5482 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5483 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5484 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5485 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5486 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5489 if (ar->num_peers >= ar->max_num_peers) {
5490 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5495 if (ar->free_vdev_map == 0) {
5496 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5500 bit = __ffs64(ar->free_vdev_map);
5502 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5503 bit, ar->free_vdev_map);
5505 arvif->vdev_id = bit;
5506 arvif->vdev_subtype =
5507 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5509 switch (vif->type) {
5510 case NL80211_IFTYPE_P2P_DEVICE:
5511 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5512 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5513 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5515 case NL80211_IFTYPE_UNSPECIFIED:
5516 case NL80211_IFTYPE_STATION:
5517 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5519 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5520 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5522 case NL80211_IFTYPE_ADHOC:
5523 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5525 case NL80211_IFTYPE_MESH_POINT:
5526 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5527 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5528 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5529 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5531 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5534 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5536 case NL80211_IFTYPE_AP:
5537 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5540 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5541 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5543 case NL80211_IFTYPE_MONITOR:
5544 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5551 /* Using vdev_id as queue number will make it very easy to do per-vif
5552 * tx queue locking. This shouldn't wrap due to interface combinations
5553 * but do a modulo for correctness sake and prevent using offchannel tx
5554 * queues for regular vif tx.
5556 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5557 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5558 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5560 /* Some firmware revisions don't wait for beacon tx completion before
5561 * sending another SWBA event. This could lead to hardware using old
5562 * (freed) beacon data in some cases, e.g. tx credit starvation
5563 * combined with missed TBTT. This is very rare.
5565 * On non-IOMMU-enabled hosts this could be a possible security issue
5566 * because hw could beacon some random data on the air. On
5567 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5568 * device would crash.
5570 * Since there are no beacon tx completions (implicit nor explicit)
5571 * propagated to host the only workaround for this is to allocate a
5572 * DMA-coherent buffer for a lifetime of a vif and use it for all
5573 * beacon tx commands. Worst case for this approach is some beacons may
5574 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5576 if (vif->type == NL80211_IFTYPE_ADHOC ||
5577 vif->type == NL80211_IFTYPE_MESH_POINT ||
5578 vif->type == NL80211_IFTYPE_AP) {
5579 arvif->beacon_buf = dma_alloc_coherent(ar->dev,
5580 IEEE80211_MAX_FRAME_LEN,
5581 &arvif->beacon_paddr,
5583 if (!arvif->beacon_buf) {
5585 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5590 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5591 arvif->nohwcrypt = true;
5593 if (arvif->nohwcrypt &&
5594 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5596 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5600 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5601 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5602 arvif->beacon_buf ? "single-buf" : "per-skb");
5604 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5605 arvif->vdev_subtype, vif->addr);
5607 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5608 arvif->vdev_id, ret);
5612 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT,
5614 vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn;
5615 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5616 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN);
5617 if (ret && ret != -EOPNOTSUPP) {
5618 ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n",
5619 arvif->vdev_id, ret);
5623 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5624 spin_lock_bh(&ar->data_lock);
5625 list_add(&arvif->list, &ar->arvifs);
5626 spin_unlock_bh(&ar->data_lock);
5628 /* It makes no sense to have firmware do keepalives. mac80211 already
5629 * takes care of this with idle connection polling.
5631 ret = ath10k_mac_vif_disable_keepalive(arvif);
5633 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5634 arvif->vdev_id, ret);
5635 goto err_vdev_delete;
5638 arvif->def_wep_key_idx = -1;
5640 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5641 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5642 ATH10K_HW_TXRX_NATIVE_WIFI);
5643 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5644 if (ret && ret != -EOPNOTSUPP) {
5645 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5646 arvif->vdev_id, ret);
5647 goto err_vdev_delete;
5650 /* Configuring number of spatial stream for monitor interface is causing
5651 * target assert in qca9888 and qca6174.
5653 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5654 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5656 vdev_param = ar->wmi.vdev_param->nss;
5657 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5660 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5661 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5663 goto err_vdev_delete;
5667 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5668 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5669 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5670 vif->addr, WMI_PEER_TYPE_DEFAULT);
5672 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5673 arvif->vdev_id, ret);
5674 goto err_vdev_delete;
5677 spin_lock_bh(&ar->data_lock);
5679 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5681 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5682 vif->addr, arvif->vdev_id);
5683 spin_unlock_bh(&ar->data_lock);
5685 goto err_peer_delete;
5688 arvif->peer_id = find_first_bit(peer->peer_ids,
5689 ATH10K_MAX_NUM_PEER_IDS);
5691 spin_unlock_bh(&ar->data_lock);
5693 arvif->peer_id = HTT_INVALID_PEERID;
5696 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5697 ret = ath10k_mac_set_kickout(arvif);
5699 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5700 arvif->vdev_id, ret);
5701 goto err_peer_delete;
5705 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5706 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5707 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5708 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5711 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5712 arvif->vdev_id, ret);
5713 goto err_peer_delete;
5716 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5718 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5719 arvif->vdev_id, ret);
5720 goto err_peer_delete;
5723 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5725 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5726 arvif->vdev_id, ret);
5727 goto err_peer_delete;
5731 ret = ath10k_mac_set_txbf_conf(arvif);
5733 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5734 arvif->vdev_id, ret);
5735 goto err_peer_delete;
5738 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5740 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5741 arvif->vdev_id, ret);
5742 goto err_peer_delete;
5745 arvif->txpower = vif->bss_conf.txpower;
5746 ret = ath10k_mac_txpower_recalc(ar);
5748 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5749 goto err_peer_delete;
5752 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
5753 vdev_param = ar->wmi.vdev_param->rtt_responder_role;
5754 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5755 arvif->ftm_responder);
5757 /* It is harmless to not set FTM role. Do not warn */
5758 if (ret && ret != -EOPNOTSUPP)
5759 ath10k_warn(ar, "failed to set vdev %i FTM Responder: %d\n",
5760 arvif->vdev_id, ret);
5763 if (vif->type == NL80211_IFTYPE_MONITOR) {
5764 ar->monitor_arvif = arvif;
5765 ret = ath10k_monitor_recalc(ar);
5767 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5768 goto err_peer_delete;
5772 spin_lock_bh(&ar->htt.tx_lock);
5774 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5775 spin_unlock_bh(&ar->htt.tx_lock);
5777 mutex_unlock(&ar->conf_mutex);
5781 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5782 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5783 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5784 ath10k_wait_for_peer_delete_done(ar, arvif->vdev_id,
5789 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5790 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5791 spin_lock_bh(&ar->data_lock);
5792 list_del(&arvif->list);
5793 spin_unlock_bh(&ar->data_lock);
5796 if (arvif->beacon_buf) {
5797 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5798 arvif->beacon_buf, arvif->beacon_paddr);
5799 arvif->beacon_buf = NULL;
5802 mutex_unlock(&ar->conf_mutex);
5807 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5811 for (i = 0; i < BITS_PER_LONG; i++)
5812 ath10k_mac_vif_tx_unlock(arvif, i);
5815 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5816 struct ieee80211_vif *vif)
5818 struct ath10k *ar = hw->priv;
5819 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5820 struct ath10k_peer *peer;
5821 unsigned long time_left;
5825 cancel_work_sync(&arvif->ap_csa_work);
5826 cancel_delayed_work_sync(&arvif->connection_loss_work);
5828 mutex_lock(&ar->conf_mutex);
5830 ret = ath10k_spectral_vif_stop(arvif);
5832 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5833 arvif->vdev_id, ret);
5835 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5836 spin_lock_bh(&ar->data_lock);
5837 list_del(&arvif->list);
5838 spin_unlock_bh(&ar->data_lock);
5840 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5841 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5842 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5845 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5846 arvif->vdev_id, ret);
5848 ath10k_wait_for_peer_delete_done(ar, arvif->vdev_id,
5850 kfree(arvif->u.ap.noa_data);
5853 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5856 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5858 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5859 arvif->vdev_id, ret);
5861 if (test_bit(WMI_SERVICE_SYNC_DELETE_CMDS, ar->wmi.svc_map)) {
5862 time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
5863 ATH10K_VDEV_DELETE_TIMEOUT_HZ);
5864 if (time_left == 0) {
5865 ath10k_warn(ar, "Timeout in receiving vdev delete response\n");
5870 /* Some firmware revisions don't notify host about self-peer removal
5871 * until after associated vdev is deleted.
5873 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5874 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5875 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5878 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5879 arvif->vdev_id, ret);
5881 spin_lock_bh(&ar->data_lock);
5883 spin_unlock_bh(&ar->data_lock);
5886 spin_lock_bh(&ar->data_lock);
5887 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5888 peer = ar->peer_map[i];
5892 if (peer->vif == vif) {
5893 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5894 vif->addr, arvif->vdev_id);
5899 /* Clean this up late, less opportunity for firmware to access
5900 * DMA memory we have deleted.
5902 ath10k_mac_vif_beacon_cleanup(arvif);
5903 spin_unlock_bh(&ar->data_lock);
5905 ath10k_peer_cleanup(ar, arvif->vdev_id);
5906 ath10k_mac_txq_unref(ar, vif->txq);
5908 if (vif->type == NL80211_IFTYPE_MONITOR) {
5909 ar->monitor_arvif = NULL;
5910 ret = ath10k_monitor_recalc(ar);
5912 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5915 ret = ath10k_mac_txpower_recalc(ar);
5917 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5919 spin_lock_bh(&ar->htt.tx_lock);
5920 ath10k_mac_vif_tx_unlock_all(arvif);
5921 spin_unlock_bh(&ar->htt.tx_lock);
5923 ath10k_mac_txq_unref(ar, vif->txq);
5926 mutex_unlock(&ar->conf_mutex);
5930 * FIXME: Has to be verified.
5932 #define SUPPORTED_FILTERS \
5937 FIF_BCN_PRBRESP_PROMISC | \
5941 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5942 unsigned int changed_flags,
5943 unsigned int *total_flags,
5946 struct ath10k *ar = hw->priv;
5949 mutex_lock(&ar->conf_mutex);
5951 changed_flags &= SUPPORTED_FILTERS;
5952 *total_flags &= SUPPORTED_FILTERS;
5953 ar->filter_flags = *total_flags;
5955 ret = ath10k_monitor_recalc(ar);
5957 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5959 mutex_unlock(&ar->conf_mutex);
5962 static void ath10k_recalculate_mgmt_rate(struct ath10k *ar,
5963 struct ieee80211_vif *vif,
5964 struct cfg80211_chan_def *def)
5966 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5967 const struct ieee80211_supported_band *sband;
5974 lockdep_assert_held(&ar->conf_mutex);
5976 sband = ar->hw->wiphy->bands[def->chan->band];
5977 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
5978 bitrate = sband->bitrates[basic_rate_idx].bitrate;
5980 hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
5981 if (hw_rate_code < 0) {
5982 ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
5986 vdev_param = ar->wmi.vdev_param->mgmt_rate;
5987 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5990 ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
5993 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5994 struct ieee80211_vif *vif,
5995 struct ieee80211_bss_conf *info,
5998 struct ath10k *ar = hw->priv;
5999 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6000 struct cfg80211_chan_def def;
6001 u32 vdev_param, pdev_param, slottime, preamble;
6002 u16 bitrate, hw_value;
6004 int ret = 0, mcast_rate;
6005 enum nl80211_band band;
6007 mutex_lock(&ar->conf_mutex);
6009 if (changed & BSS_CHANGED_IBSS)
6010 ath10k_control_ibss(arvif, info, vif->addr);
6012 if (changed & BSS_CHANGED_BEACON_INT) {
6013 arvif->beacon_interval = info->beacon_int;
6014 vdev_param = ar->wmi.vdev_param->beacon_interval;
6015 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6016 arvif->beacon_interval);
6017 ath10k_dbg(ar, ATH10K_DBG_MAC,
6018 "mac vdev %d beacon_interval %d\n",
6019 arvif->vdev_id, arvif->beacon_interval);
6022 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
6023 arvif->vdev_id, ret);
6026 if (changed & BSS_CHANGED_BEACON) {
6027 ath10k_dbg(ar, ATH10K_DBG_MAC,
6028 "vdev %d set beacon tx mode to staggered\n",
6031 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
6032 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
6033 WMI_BEACON_STAGGERED_MODE);
6035 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
6036 arvif->vdev_id, ret);
6038 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6040 ath10k_warn(ar, "failed to update beacon template: %d\n",
6043 if (ieee80211_vif_is_mesh(vif)) {
6044 /* mesh doesn't use SSID but firmware needs it */
6045 strncpy(arvif->u.ap.ssid, "mesh",
6046 sizeof(arvif->u.ap.ssid));
6047 arvif->u.ap.ssid_len = 4;
6051 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
6052 ret = ath10k_mac_setup_prb_tmpl(arvif);
6054 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
6055 arvif->vdev_id, ret);
6058 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
6059 arvif->dtim_period = info->dtim_period;
6061 ath10k_dbg(ar, ATH10K_DBG_MAC,
6062 "mac vdev %d dtim_period %d\n",
6063 arvif->vdev_id, arvif->dtim_period);
6065 vdev_param = ar->wmi.vdev_param->dtim_period;
6066 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6067 arvif->dtim_period);
6069 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
6070 arvif->vdev_id, ret);
6073 if (changed & BSS_CHANGED_SSID &&
6074 vif->type == NL80211_IFTYPE_AP) {
6075 arvif->u.ap.ssid_len = info->ssid_len;
6077 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
6078 arvif->u.ap.hidden_ssid = info->hidden_ssid;
6081 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
6082 ether_addr_copy(arvif->bssid, info->bssid);
6084 if (changed & BSS_CHANGED_FTM_RESPONDER &&
6085 arvif->ftm_responder != info->ftm_responder &&
6086 test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
6087 arvif->ftm_responder = info->ftm_responder;
6089 vdev_param = ar->wmi.vdev_param->rtt_responder_role;
6090 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6091 arvif->ftm_responder);
6093 ath10k_dbg(ar, ATH10K_DBG_MAC,
6094 "mac vdev %d ftm_responder %d:ret %d\n",
6095 arvif->vdev_id, arvif->ftm_responder, ret);
6098 if (changed & BSS_CHANGED_BEACON_ENABLED)
6099 ath10k_control_beaconing(arvif, info);
6101 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
6102 arvif->use_cts_prot = info->use_cts_prot;
6104 ret = ath10k_recalc_rtscts_prot(arvif);
6106 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
6107 arvif->vdev_id, ret);
6109 if (ath10k_mac_can_set_cts_prot(arvif)) {
6110 ret = ath10k_mac_set_cts_prot(arvif);
6112 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
6113 arvif->vdev_id, ret);
6117 if (changed & BSS_CHANGED_ERP_SLOT) {
6118 if (info->use_short_slot)
6119 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
6122 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
6124 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
6125 arvif->vdev_id, slottime);
6127 vdev_param = ar->wmi.vdev_param->slot_time;
6128 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6131 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
6132 arvif->vdev_id, ret);
6135 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
6136 if (info->use_short_preamble)
6137 preamble = WMI_VDEV_PREAMBLE_SHORT;
6139 preamble = WMI_VDEV_PREAMBLE_LONG;
6141 ath10k_dbg(ar, ATH10K_DBG_MAC,
6142 "mac vdev %d preamble %dn",
6143 arvif->vdev_id, preamble);
6145 vdev_param = ar->wmi.vdev_param->preamble;
6146 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6149 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
6150 arvif->vdev_id, ret);
6153 if (changed & BSS_CHANGED_ASSOC) {
6155 /* Workaround: Make sure monitor vdev is not running
6156 * when associating to prevent some firmware revisions
6157 * (e.g. 10.1 and 10.2) from crashing.
6159 if (ar->monitor_started)
6160 ath10k_monitor_stop(ar);
6161 ath10k_bss_assoc(hw, vif, info);
6162 ath10k_monitor_recalc(ar);
6164 ath10k_bss_disassoc(hw, vif);
6168 if (changed & BSS_CHANGED_TXPOWER) {
6169 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
6170 arvif->vdev_id, info->txpower);
6172 arvif->txpower = info->txpower;
6173 ret = ath10k_mac_txpower_recalc(ar);
6175 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
6178 if (changed & BSS_CHANGED_PS) {
6179 arvif->ps = vif->bss_conf.ps;
6181 ret = ath10k_config_ps(ar);
6183 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
6184 arvif->vdev_id, ret);
6187 if (changed & BSS_CHANGED_MCAST_RATE &&
6188 !ath10k_mac_vif_chan(arvif->vif, &def)) {
6189 band = def.chan->band;
6190 mcast_rate = vif->bss_conf.mcast_rate[band];
6192 rateidx = mcast_rate - 1;
6194 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
6196 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
6197 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
6199 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
6200 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
6201 if (ath10k_mac_bitrate_is_cck(bitrate))
6202 preamble = WMI_RATE_PREAMBLE_CCK;
6204 preamble = WMI_RATE_PREAMBLE_OFDM;
6206 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
6208 ath10k_dbg(ar, ATH10K_DBG_MAC,
6209 "mac vdev %d mcast_rate %x\n",
6210 arvif->vdev_id, rate);
6212 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
6213 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
6217 "failed to set mcast rate on vdev %i: %d\n",
6218 arvif->vdev_id, ret);
6220 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
6221 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
6225 "failed to set bcast rate on vdev %i: %d\n",
6226 arvif->vdev_id, ret);
6229 if (changed & BSS_CHANGED_BASIC_RATES &&
6230 !ath10k_mac_vif_chan(arvif->vif, &def))
6231 ath10k_recalculate_mgmt_rate(ar, vif, &def);
6233 mutex_unlock(&ar->conf_mutex);
6236 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
6238 struct ath10k *ar = hw->priv;
6240 /* This function should never be called if setting the coverage class
6241 * is not supported on this hardware.
6243 if (!ar->hw_params.hw_ops->set_coverage_class) {
6247 ar->hw_params.hw_ops->set_coverage_class(ar, value);
6250 struct ath10k_mac_tdls_iter_data {
6251 u32 num_tdls_stations;
6252 struct ieee80211_vif *curr_vif;
6255 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
6256 struct ieee80211_sta *sta)
6258 struct ath10k_mac_tdls_iter_data *iter_data = data;
6259 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6260 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
6262 if (sta->tdls && sta_vif == iter_data->curr_vif)
6263 iter_data->num_tdls_stations++;
6266 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
6267 struct ieee80211_vif *vif)
6269 struct ath10k_mac_tdls_iter_data data = {};
6271 data.curr_vif = vif;
6273 ieee80211_iterate_stations_atomic(hw,
6274 ath10k_mac_tdls_vif_stations_count_iter,
6276 return data.num_tdls_stations;
6279 static int ath10k_hw_scan(struct ieee80211_hw *hw,
6280 struct ieee80211_vif *vif,
6281 struct ieee80211_scan_request *hw_req)
6283 struct ath10k *ar = hw->priv;
6284 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6285 struct cfg80211_scan_request *req = &hw_req->req;
6286 struct wmi_start_scan_arg arg;
6291 mutex_lock(&ar->conf_mutex);
6293 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6298 spin_lock_bh(&ar->data_lock);
6299 switch (ar->scan.state) {
6300 case ATH10K_SCAN_IDLE:
6301 reinit_completion(&ar->scan.started);
6302 reinit_completion(&ar->scan.completed);
6303 ar->scan.state = ATH10K_SCAN_STARTING;
6304 ar->scan.is_roc = false;
6305 ar->scan.vdev_id = arvif->vdev_id;
6308 case ATH10K_SCAN_STARTING:
6309 case ATH10K_SCAN_RUNNING:
6310 case ATH10K_SCAN_ABORTING:
6314 spin_unlock_bh(&ar->data_lock);
6319 memset(&arg, 0, sizeof(arg));
6320 ath10k_wmi_start_scan_init(ar, &arg);
6321 arg.vdev_id = arvif->vdev_id;
6322 arg.scan_id = ATH10K_SCAN_ID;
6325 arg.ie_len = req->ie_len;
6326 memcpy(arg.ie, req->ie, arg.ie_len);
6330 arg.n_ssids = req->n_ssids;
6331 for (i = 0; i < arg.n_ssids; i++) {
6332 arg.ssids[i].len = req->ssids[i].ssid_len;
6333 arg.ssids[i].ssid = req->ssids[i].ssid;
6336 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6339 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6340 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
6341 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
6342 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
6345 if (req->n_channels) {
6346 arg.n_channels = req->n_channels;
6347 for (i = 0; i < arg.n_channels; i++)
6348 arg.channels[i] = req->channels[i]->center_freq;
6351 /* if duration is set, default dwell times will be overwritten */
6352 if (req->duration) {
6353 arg.dwell_time_active = req->duration;
6354 arg.dwell_time_passive = req->duration;
6355 arg.burst_duration_ms = req->duration;
6357 scan_timeout = min_t(u32, arg.max_rest_time *
6358 (arg.n_channels - 1) + (req->duration +
6359 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
6360 arg.n_channels, arg.max_scan_time + 200);
6363 /* Add a 200ms margin to account for event/command processing */
6364 scan_timeout = arg.max_scan_time + 200;
6367 ret = ath10k_start_scan(ar, &arg);
6369 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
6370 spin_lock_bh(&ar->data_lock);
6371 ar->scan.state = ATH10K_SCAN_IDLE;
6372 spin_unlock_bh(&ar->data_lock);
6375 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6376 msecs_to_jiffies(scan_timeout));
6379 mutex_unlock(&ar->conf_mutex);
6383 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
6384 struct ieee80211_vif *vif)
6386 struct ath10k *ar = hw->priv;
6388 mutex_lock(&ar->conf_mutex);
6389 ath10k_scan_abort(ar);
6390 mutex_unlock(&ar->conf_mutex);
6392 cancel_delayed_work_sync(&ar->scan.timeout);
6395 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
6396 struct ath10k_vif *arvif,
6397 enum set_key_cmd cmd,
6398 struct ieee80211_key_conf *key)
6400 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
6403 /* 10.1 firmware branch requires default key index to be set to group
6404 * key index after installing it. Otherwise FW/HW Txes corrupted
6405 * frames with multi-vif APs. This is not required for main firmware
6406 * branch (e.g. 636).
6408 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6410 * FIXME: It remains unknown if this is required for multi-vif STA
6411 * interfaces on 10.1.
6414 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
6415 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
6418 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
6421 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
6424 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6430 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6433 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
6434 arvif->vdev_id, ret);
6437 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6438 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
6439 struct ieee80211_key_conf *key)
6441 struct ath10k *ar = hw->priv;
6442 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6443 struct ath10k_sta *arsta;
6444 struct ath10k_peer *peer;
6445 const u8 *peer_addr;
6446 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
6447 key->cipher == WLAN_CIPHER_SUITE_WEP104;
6453 /* this one needs to be done in software */
6454 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
6455 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
6456 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
6457 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
6460 if (arvif->nohwcrypt)
6463 if (key->keyidx > WMI_MAX_KEY_INDEX)
6466 mutex_lock(&ar->conf_mutex);
6469 arsta = (struct ath10k_sta *)sta->drv_priv;
6470 peer_addr = sta->addr;
6471 spin_lock_bh(&ar->data_lock);
6472 arsta->ucast_cipher = key->cipher;
6473 spin_unlock_bh(&ar->data_lock);
6474 } else if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
6475 peer_addr = vif->bss_conf.bssid;
6477 peer_addr = vif->addr;
6480 key->hw_key_idx = key->keyidx;
6484 arvif->wep_keys[key->keyidx] = key;
6486 arvif->wep_keys[key->keyidx] = NULL;
6489 /* the peer should not disappear in mid-way (unless FW goes awry) since
6490 * we already hold conf_mutex. we just make sure its there now.
6492 spin_lock_bh(&ar->data_lock);
6493 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6494 spin_unlock_bh(&ar->data_lock);
6497 if (cmd == SET_KEY) {
6498 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
6503 /* if the peer doesn't exist there is no key to disable anymore */
6508 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6509 flags |= WMI_KEY_PAIRWISE;
6511 flags |= WMI_KEY_GROUP;
6514 if (cmd == DISABLE_KEY)
6515 ath10k_clear_vdev_key(arvif, key);
6517 /* When WEP keys are uploaded it's possible that there are
6518 * stations associated already (e.g. when merging) without any
6519 * keys. Static WEP needs an explicit per-peer key upload.
6521 if (vif->type == NL80211_IFTYPE_ADHOC &&
6523 ath10k_mac_vif_update_wep_key(arvif, key);
6525 /* 802.1x never sets the def_wep_key_idx so each set_key()
6526 * call changes default tx key.
6528 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6529 * after first set_key().
6531 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
6532 flags |= WMI_KEY_TX_USAGE;
6535 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
6538 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
6539 arvif->vdev_id, peer_addr, ret);
6543 /* mac80211 sets static WEP keys as groupwise while firmware requires
6544 * them to be installed twice as both pairwise and groupwise.
6546 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6548 flags2 &= ~WMI_KEY_GROUP;
6549 flags2 |= WMI_KEY_PAIRWISE;
6551 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6554 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6555 arvif->vdev_id, peer_addr, ret);
6556 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6560 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6561 arvif->vdev_id, peer_addr, ret2);
6567 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6569 spin_lock_bh(&ar->data_lock);
6570 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6571 if (peer && cmd == SET_KEY)
6572 peer->keys[key->keyidx] = key;
6573 else if (peer && cmd == DISABLE_KEY)
6574 peer->keys[key->keyidx] = NULL;
6575 else if (peer == NULL)
6576 /* impossible unless FW goes crazy */
6577 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6578 spin_unlock_bh(&ar->data_lock);
6580 if (sta && sta->tdls)
6581 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6582 ar->wmi.peer_param->authorize, 1);
6583 else if (sta && cmd == SET_KEY && (key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
6584 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, peer_addr,
6585 ar->wmi.peer_param->authorize, 1);
6588 mutex_unlock(&ar->conf_mutex);
6592 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6593 struct ieee80211_vif *vif,
6596 struct ath10k *ar = hw->priv;
6597 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6600 mutex_lock(&arvif->ar->conf_mutex);
6602 if (arvif->ar->state != ATH10K_STATE_ON)
6605 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6606 arvif->vdev_id, keyidx);
6608 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6610 arvif->ar->wmi.vdev_param->def_keyid,
6614 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6620 arvif->def_wep_key_idx = keyidx;
6623 mutex_unlock(&arvif->ar->conf_mutex);
6626 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6629 struct ath10k_vif *arvif;
6630 struct ath10k_sta *arsta;
6631 struct ieee80211_sta *sta;
6632 struct cfg80211_chan_def def;
6633 enum nl80211_band band;
6634 const u8 *ht_mcs_mask;
6635 const u16 *vht_mcs_mask;
6636 u32 changed, bw, nss, smps;
6639 arsta = container_of(wk, struct ath10k_sta, update_wk);
6640 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6641 arvif = arsta->arvif;
6644 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6647 band = def.chan->band;
6648 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6649 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6651 spin_lock_bh(&ar->data_lock);
6653 changed = arsta->changed;
6660 spin_unlock_bh(&ar->data_lock);
6662 mutex_lock(&ar->conf_mutex);
6664 nss = max_t(u32, 1, nss);
6665 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6666 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6668 if (changed & IEEE80211_RC_BW_CHANGED) {
6669 enum wmi_phy_mode mode;
6671 mode = chan_to_phymode(&def);
6672 ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM peer bw %d phymode %d\n",
6673 sta->addr, bw, mode);
6675 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6676 ar->wmi.peer_param->phymode, mode);
6678 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6679 sta->addr, mode, err);
6683 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6684 ar->wmi.peer_param->chan_width, bw);
6686 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6687 sta->addr, bw, err);
6690 if (changed & IEEE80211_RC_NSS_CHANGED) {
6691 ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM nss %d\n",
6694 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6695 ar->wmi.peer_param->nss, nss);
6697 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6698 sta->addr, nss, err);
6701 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6702 ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM smps %d\n",
6705 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6706 ar->wmi.peer_param->smps_state, smps);
6708 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6709 sta->addr, smps, err);
6712 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6713 ath10k_dbg(ar, ATH10K_DBG_STA, "mac update sta %pM supp rates\n",
6716 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6718 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6723 mutex_unlock(&ar->conf_mutex);
6726 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6727 struct ieee80211_sta *sta)
6729 struct ath10k *ar = arvif->ar;
6731 lockdep_assert_held(&ar->conf_mutex);
6733 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6736 if (ar->num_stations >= ar->max_num_stations)
6744 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6745 struct ieee80211_sta *sta)
6747 struct ath10k *ar = arvif->ar;
6749 lockdep_assert_held(&ar->conf_mutex);
6751 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6757 static int ath10k_sta_set_txpwr(struct ieee80211_hw *hw,
6758 struct ieee80211_vif *vif,
6759 struct ieee80211_sta *sta)
6761 struct ath10k *ar = hw->priv;
6762 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6766 if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
6769 txpwr = sta->txpwr.power;
6774 if (txpwr > ATH10K_TX_POWER_MAX_VAL || txpwr < ATH10K_TX_POWER_MIN_VAL)
6777 mutex_lock(&ar->conf_mutex);
6779 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6780 ar->wmi.peer_param->use_fixed_power, txpwr);
6782 ath10k_warn(ar, "failed to set tx power for station ret: %d\n",
6788 mutex_unlock(&ar->conf_mutex);
6792 struct ath10k_mac_iter_tid_conf_data {
6793 struct ieee80211_vif *curr_vif;
6799 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6800 enum nl80211_band band,
6801 const struct cfg80211_bitrate_mask *mask,
6807 num_rates += hweight32(mask->control[band].legacy);
6809 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6810 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6813 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6814 tmp = hweight16(mask->control[band].vht_mcs[i]);
6816 *vht_num_rates += tmp;
6819 return num_rates == 1;
6823 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6824 enum nl80211_band band,
6825 const struct cfg80211_bitrate_mask *mask,
6826 u8 *rate, u8 *nss, bool vht_only)
6837 if (hweight32(mask->control[band].legacy) == 1) {
6838 rate_idx = ffs(mask->control[band].legacy) - 1;
6840 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
6841 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
6843 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
6844 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
6846 if (ath10k_mac_bitrate_is_cck(bitrate))
6847 preamble = WMI_RATE_PREAMBLE_CCK;
6849 preamble = WMI_RATE_PREAMBLE_OFDM;
6852 *rate = preamble << 6 |
6859 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6860 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6862 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6864 (ffs(mask->control[band].ht_mcs[i]) - 1);
6871 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6872 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6874 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6876 (ffs(mask->control[band].vht_mcs[i]) - 1);
6885 static int ath10k_mac_validate_rate_mask(struct ath10k *ar,
6886 struct ieee80211_sta *sta,
6887 u32 rate_ctrl_flag, u8 nss)
6889 if (nss > sta->rx_nss) {
6890 ath10k_warn(ar, "Invalid nss field, configured %u limit %u\n",
6895 if (ATH10K_HW_PREAMBLE(rate_ctrl_flag) == WMI_RATE_PREAMBLE_VHT) {
6896 if (!sta->vht_cap.vht_supported) {
6897 ath10k_warn(ar, "Invalid VHT rate for sta %pM\n",
6901 } else if (ATH10K_HW_PREAMBLE(rate_ctrl_flag) == WMI_RATE_PREAMBLE_HT) {
6902 if (!sta->ht_cap.ht_supported || sta->vht_cap.vht_supported) {
6903 ath10k_warn(ar, "Invalid HT rate for sta %pM\n",
6908 if (sta->ht_cap.ht_supported || sta->vht_cap.vht_supported)
6916 ath10k_mac_tid_bitrate_config(struct ath10k *ar,
6917 struct ieee80211_vif *vif,
6918 struct ieee80211_sta *sta,
6919 u32 *rate_ctrl_flag, u8 *rate_ctrl,
6920 enum nl80211_tx_rate_setting txrate_type,
6921 const struct cfg80211_bitrate_mask *mask)
6923 struct cfg80211_chan_def def;
6924 enum nl80211_band band;
6926 int vht_num_rates, ret;
6928 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
6931 if (txrate_type == NL80211_TX_RATE_AUTOMATIC) {
6932 *rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_AUTO;
6933 *rate_ctrl_flag = 0;
6937 band = def.chan->band;
6939 if (!ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask,
6944 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6945 &rate, &nss, false);
6947 ath10k_warn(ar, "failed to get single rate: %d\n",
6952 *rate_ctrl_flag = rate;
6954 if (sta && ath10k_mac_validate_rate_mask(ar, sta, *rate_ctrl_flag, nss))
6957 if (txrate_type == NL80211_TX_RATE_FIXED)
6958 *rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_FIXED_RATE;
6959 else if (txrate_type == NL80211_TX_RATE_LIMITED &&
6960 (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT,
6962 *rate_ctrl = WMI_PEER_TID_CONFIG_RATE_UPPER_CAP;
6969 static int ath10k_mac_set_tid_config(struct ath10k *ar, struct ieee80211_sta *sta,
6970 struct ieee80211_vif *vif, u32 changed,
6971 struct wmi_per_peer_per_tid_cfg_arg *arg)
6973 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6974 struct ath10k_sta *arsta;
6981 arsta = (struct ath10k_sta *)sta->drv_priv;
6983 if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
6984 if ((arsta->retry_long[arg->tid] > 0 ||
6985 arsta->rate_code[arg->tid] > 0 ||
6986 arsta->ampdu[arg->tid] ==
6987 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE) &&
6988 arg->ack_policy == WMI_PEER_TID_CONFIG_NOACK) {
6989 changed &= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK);
6990 arg->ack_policy = 0;
6991 arg->aggr_control = 0;
6993 arg->rcode_flags = 0;
6997 if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
6998 if (arsta->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK ||
6999 arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK) {
7000 arg->aggr_control = 0;
7001 changed &= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
7005 if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
7006 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
7007 if (arsta->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK ||
7008 arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK) {
7010 arg->rcode_flags = 0;
7014 ether_addr_copy(arg->peer_macaddr.addr, sta->addr);
7016 ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, arg);
7020 /* Store the configured parameters in success case */
7021 if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
7022 arsta->noack[arg->tid] = arg->ack_policy;
7023 arg->ack_policy = 0;
7024 arg->aggr_control = 0;
7026 arg->rcode_flags = 0;
7029 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG)) {
7030 arsta->retry_long[arg->tid] = arg->retry_count;
7031 arg->retry_count = 0;
7034 if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
7035 arsta->ampdu[arg->tid] = arg->aggr_control;
7036 arg->aggr_control = 0;
7039 if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
7040 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
7041 arsta->rate_ctrl[arg->tid] = arg->rate_ctrl;
7043 arg->rcode_flags = 0;
7046 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
7047 arsta->rtscts[arg->tid] = arg->rtscts_ctrl;
7048 arg->ext_tid_cfg_bitmap = 0;
7051 if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
7052 if ((arvif->retry_long[arg->tid] ||
7053 arvif->rate_code[arg->tid] ||
7054 arvif->ampdu[arg->tid] ==
7055 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE) &&
7056 arg->ack_policy == WMI_PEER_TID_CONFIG_NOACK) {
7057 changed &= ~BIT(NL80211_TID_CONFIG_ATTR_NOACK);
7059 arvif->noack[arg->tid] = arg->ack_policy;
7060 arvif->ampdu[arg->tid] = arg->aggr_control;
7061 arvif->rate_ctrl[arg->tid] = arg->rate_ctrl;
7065 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG)) {
7066 if (arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK)
7067 changed &= ~BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
7069 arvif->retry_long[arg->tid] = arg->retry_count;
7072 if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
7073 if (arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK)
7074 changed &= ~BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
7076 arvif->ampdu[arg->tid] = arg->aggr_control;
7079 if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
7080 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
7081 if (arvif->noack[arg->tid] == WMI_PEER_TID_CONFIG_NOACK) {
7082 changed &= ~(BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
7083 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE));
7085 arvif->rate_ctrl[arg->tid] = arg->rate_ctrl;
7086 arvif->rate_code[arg->tid] = arg->rcode_flags;
7090 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
7091 arvif->rtscts[arg->tid] = arg->rtscts_ctrl;
7092 arg->ext_tid_cfg_bitmap = 0;
7096 arvif->tid_conf_changed[arg->tid] |= changed;
7103 ath10k_mac_parse_tid_config(struct ath10k *ar,
7104 struct ieee80211_sta *sta,
7105 struct ieee80211_vif *vif,
7106 struct cfg80211_tid_cfg *tid_conf,
7107 struct wmi_per_peer_per_tid_cfg_arg *arg)
7109 u32 changed = tid_conf->mask;
7115 while (i < ATH10K_TID_MAX) {
7116 if (!(tid_conf->tids & BIT(i))) {
7123 if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
7124 if (tid_conf->noack == NL80211_TID_CONFIG_ENABLE) {
7125 arg->ack_policy = WMI_PEER_TID_CONFIG_NOACK;
7127 WMI_TID_CONFIG_RATE_CONTROL_DEFAULT_LOWEST_RATE;
7129 WMI_TID_CONFIG_AGGR_CONTROL_DISABLE;
7132 WMI_PEER_TID_CONFIG_ACK;
7134 WMI_TID_CONFIG_RATE_CONTROL_AUTO;
7136 WMI_TID_CONFIG_AGGR_CONTROL_ENABLE;
7140 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG))
7141 arg->retry_count = tid_conf->retry_long;
7143 if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
7144 if (tid_conf->noack == NL80211_TID_CONFIG_ENABLE)
7145 arg->aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_ENABLE;
7147 arg->aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_DISABLE;
7150 if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
7151 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
7152 ret = ath10k_mac_tid_bitrate_config(ar, vif, sta,
7155 tid_conf->txrate_type,
7156 &tid_conf->txrate_mask);
7158 ath10k_warn(ar, "failed to configure bitrate mask %d\n",
7160 arg->rcode_flags = 0;
7165 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
7166 if (tid_conf->rtscts)
7167 arg->rtscts_ctrl = tid_conf->rtscts;
7169 arg->ext_tid_cfg_bitmap = WMI_EXT_TID_RTS_CTS_CONFIG;
7172 ret = ath10k_mac_set_tid_config(ar, sta, vif, changed, arg);
7181 static int ath10k_mac_reset_tid_config(struct ath10k *ar,
7182 struct ieee80211_sta *sta,
7183 struct ath10k_vif *arvif,
7186 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7187 struct wmi_per_peer_per_tid_cfg_arg arg;
7190 arg.vdev_id = arvif->vdev_id;
7191 while (i < ATH10K_TID_MAX) {
7192 if (!(tids & BIT(i))) {
7198 arg.ack_policy = WMI_PEER_TID_CONFIG_ACK;
7199 arg.retry_count = ATH10K_MAX_RETRY_COUNT;
7200 arg.rate_ctrl = WMI_TID_CONFIG_RATE_CONTROL_AUTO;
7201 arg.aggr_control = WMI_TID_CONFIG_AGGR_CONTROL_ENABLE;
7202 arg.rtscts_ctrl = WMI_TID_CONFIG_RTSCTS_CONTROL_ENABLE;
7203 arg.ext_tid_cfg_bitmap = WMI_EXT_TID_RTS_CTS_CONFIG;
7205 ether_addr_copy(arg.peer_macaddr.addr, sta->addr);
7207 ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, &arg);
7211 if (!arvif->tids_rst) {
7212 arsta->retry_long[i] = -1;
7213 arsta->noack[i] = -1;
7214 arsta->ampdu[i] = -1;
7215 arsta->rate_code[i] = -1;
7216 arsta->rate_ctrl[i] = 0;
7217 arsta->rtscts[i] = -1;
7219 arvif->retry_long[i] = 0;
7220 arvif->noack[i] = 0;
7221 arvif->ampdu[i] = 0;
7222 arvif->rate_code[i] = 0;
7223 arvif->rate_ctrl[i] = 0;
7224 arvif->rtscts[i] = 0;
7233 static void ath10k_sta_tid_cfg_wk(struct work_struct *wk)
7235 struct wmi_per_peer_per_tid_cfg_arg arg = {};
7236 struct ieee80211_sta *sta;
7237 struct ath10k_sta *arsta;
7238 struct ath10k_vif *arvif;
7245 arsta = container_of(wk, struct ath10k_sta, tid_config_wk);
7246 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
7247 arvif = arsta->arvif;
7250 mutex_lock(&ar->conf_mutex);
7252 if (arvif->tids_rst) {
7253 ret = ath10k_mac_reset_tid_config(ar, sta, arvif,
7258 ether_addr_copy(arg.peer_macaddr.addr, sta->addr);
7260 for (i = 0; i < ATH10K_TID_MAX; i++) {
7261 config_apply = false;
7262 changed = arvif->tid_conf_changed[i];
7264 if (changed & BIT(NL80211_TID_CONFIG_ATTR_NOACK)) {
7265 if (arsta->noack[i] != -1) {
7268 config_apply = true;
7269 arg.ack_policy = arvif->noack[i];
7270 arg.aggr_control = arvif->ampdu[i];
7271 arg.rate_ctrl = arvif->rate_ctrl[i];
7275 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG)) {
7276 if (arsta->retry_long[i] != -1 ||
7277 arsta->noack[i] == WMI_PEER_TID_CONFIG_NOACK ||
7278 arvif->noack[i] == WMI_PEER_TID_CONFIG_NOACK) {
7279 arg.retry_count = 0;
7281 arg.retry_count = arvif->retry_long[i];
7282 config_apply = true;
7286 if (changed & BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL)) {
7287 if (arsta->ampdu[i] != -1 ||
7288 arsta->noack[i] == WMI_PEER_TID_CONFIG_NOACK ||
7289 arvif->noack[i] == WMI_PEER_TID_CONFIG_NOACK) {
7290 arg.aggr_control = 0;
7292 arg.aggr_control = arvif->ampdu[i];
7293 config_apply = true;
7297 if (changed & (BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
7298 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE))) {
7299 nss = ATH10K_HW_NSS(arvif->rate_code[i]);
7300 ret = ath10k_mac_validate_rate_mask(ar, sta,
7301 arvif->rate_code[i],
7304 arvif->rate_ctrl[i] > WMI_TID_CONFIG_RATE_CONTROL_AUTO) {
7306 arg.rcode_flags = 0;
7309 if (arsta->rate_ctrl[i] >
7310 WMI_TID_CONFIG_RATE_CONTROL_AUTO ||
7311 arsta->noack[i] == WMI_PEER_TID_CONFIG_NOACK ||
7312 arvif->noack[i] == WMI_PEER_TID_CONFIG_NOACK) {
7314 arg.rcode_flags = 0;
7316 arg.rate_ctrl = arvif->rate_ctrl[i];
7317 arg.rcode_flags = arvif->rate_code[i];
7318 config_apply = true;
7322 if (changed & BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL)) {
7323 if (arsta->rtscts[i]) {
7324 arg.rtscts_ctrl = 0;
7325 arg.ext_tid_cfg_bitmap = 0;
7327 arg.rtscts_ctrl = arvif->rtscts[i] - 1;
7328 arg.ext_tid_cfg_bitmap =
7329 WMI_EXT_TID_RTS_CTS_CONFIG;
7330 config_apply = true;
7337 ret = ath10k_wmi_set_per_peer_per_tid_cfg(ar, &arg);
7339 ath10k_warn(ar, "failed to set per tid config for sta %pM: %d\n",
7344 arg.retry_count = 0;
7345 arg.aggr_control = 0;
7347 arg.rcode_flags = 0;
7351 mutex_unlock(&ar->conf_mutex);
7354 static void ath10k_mac_vif_stations_tid_conf(void *data,
7355 struct ieee80211_sta *sta)
7357 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7358 struct ath10k_mac_iter_tid_conf_data *iter_data = data;
7359 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
7361 if (sta_vif != iter_data->curr_vif || !sta->wme)
7364 ieee80211_queue_work(iter_data->ar->hw, &arsta->tid_config_wk);
7367 static int ath10k_sta_state(struct ieee80211_hw *hw,
7368 struct ieee80211_vif *vif,
7369 struct ieee80211_sta *sta,
7370 enum ieee80211_sta_state old_state,
7371 enum ieee80211_sta_state new_state)
7373 struct ath10k *ar = hw->priv;
7374 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7375 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7376 struct ath10k_peer *peer;
7380 if (old_state == IEEE80211_STA_NOTEXIST &&
7381 new_state == IEEE80211_STA_NONE) {
7382 memset(arsta, 0, sizeof(*arsta));
7383 arsta->arvif = arvif;
7384 arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
7385 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
7386 INIT_WORK(&arsta->tid_config_wk, ath10k_sta_tid_cfg_wk);
7388 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
7389 ath10k_mac_txq_init(sta->txq[i]);
7392 /* cancel must be done outside the mutex to avoid deadlock */
7393 if ((old_state == IEEE80211_STA_NONE &&
7394 new_state == IEEE80211_STA_NOTEXIST)) {
7395 cancel_work_sync(&arsta->update_wk);
7396 cancel_work_sync(&arsta->tid_config_wk);
7399 mutex_lock(&ar->conf_mutex);
7401 if (old_state == IEEE80211_STA_NOTEXIST &&
7402 new_state == IEEE80211_STA_NONE) {
7404 * New station addition.
7406 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
7407 u32 num_tdls_stations;
7409 ath10k_dbg(ar, ATH10K_DBG_STA,
7410 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
7411 arvif->vdev_id, sta->addr,
7412 ar->num_stations + 1, ar->max_num_stations,
7413 ar->num_peers + 1, ar->max_num_peers);
7415 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
7418 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
7419 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
7421 ar->max_num_tdls_vdevs);
7425 peer_type = WMI_PEER_TYPE_TDLS;
7428 ret = ath10k_mac_inc_num_stations(arvif, sta);
7430 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
7431 ar->max_num_stations);
7435 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
7436 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats),
7438 if (!arsta->tx_stats) {
7439 ath10k_mac_dec_num_stations(arvif, sta);
7445 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
7446 sta->addr, peer_type);
7448 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
7449 sta->addr, arvif->vdev_id, ret);
7450 ath10k_mac_dec_num_stations(arvif, sta);
7451 kfree(arsta->tx_stats);
7455 spin_lock_bh(&ar->data_lock);
7457 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7459 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
7460 vif->addr, arvif->vdev_id);
7461 spin_unlock_bh(&ar->data_lock);
7462 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
7463 ath10k_mac_dec_num_stations(arvif, sta);
7464 kfree(arsta->tx_stats);
7469 arsta->peer_id = find_first_bit(peer->peer_ids,
7470 ATH10K_MAX_NUM_PEER_IDS);
7472 spin_unlock_bh(&ar->data_lock);
7477 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
7478 WMI_TDLS_ENABLE_ACTIVE);
7480 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
7481 arvif->vdev_id, ret);
7482 ath10k_peer_delete(ar, arvif->vdev_id,
7484 ath10k_mac_dec_num_stations(arvif, sta);
7485 kfree(arsta->tx_stats);
7489 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
7490 WMI_TDLS_PEER_STATE_PEERING);
7493 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
7494 sta->addr, arvif->vdev_id, ret);
7495 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
7496 ath10k_mac_dec_num_stations(arvif, sta);
7497 kfree(arsta->tx_stats);
7499 if (num_tdls_stations != 0)
7501 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
7504 } else if ((old_state == IEEE80211_STA_NONE &&
7505 new_state == IEEE80211_STA_NOTEXIST)) {
7507 * Existing station deletion.
7509 ath10k_dbg(ar, ATH10K_DBG_STA,
7510 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
7511 arvif->vdev_id, sta->addr, sta);
7514 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
7516 WMI_TDLS_PEER_STATE_TEARDOWN);
7518 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
7520 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
7523 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
7525 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
7526 sta->addr, arvif->vdev_id, ret);
7528 ath10k_mac_dec_num_stations(arvif, sta);
7530 spin_lock_bh(&ar->data_lock);
7531 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
7532 peer = ar->peer_map[i];
7536 if (peer->sta == sta) {
7537 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
7538 sta->addr, peer, i, arvif->vdev_id);
7541 /* Clean up the peer object as well since we
7542 * must have failed to do this above.
7544 list_del(&peer->list);
7545 ar->peer_map[i] = NULL;
7550 spin_unlock_bh(&ar->data_lock);
7552 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
7553 kfree(arsta->tx_stats);
7554 arsta->tx_stats = NULL;
7557 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
7558 ath10k_mac_txq_unref(ar, sta->txq[i]);
7563 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
7566 /* This was the last tdls peer in current vif */
7567 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
7570 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
7571 arvif->vdev_id, ret);
7573 } else if (old_state == IEEE80211_STA_AUTH &&
7574 new_state == IEEE80211_STA_ASSOC &&
7575 (vif->type == NL80211_IFTYPE_AP ||
7576 vif->type == NL80211_IFTYPE_MESH_POINT ||
7577 vif->type == NL80211_IFTYPE_ADHOC)) {
7581 ath10k_dbg(ar, ATH10K_DBG_STA, "mac sta %pM associated\n",
7584 ret = ath10k_station_assoc(ar, vif, sta, false);
7586 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
7587 sta->addr, arvif->vdev_id, ret);
7588 } else if (old_state == IEEE80211_STA_ASSOC &&
7589 new_state == IEEE80211_STA_AUTHORIZED &&
7592 * Tdls station authorized.
7594 ath10k_dbg(ar, ATH10K_DBG_STA, "mac tdls sta %pM authorized\n",
7597 ret = ath10k_station_assoc(ar, vif, sta, false);
7599 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
7600 sta->addr, arvif->vdev_id, ret);
7604 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
7605 WMI_TDLS_PEER_STATE_CONNECTED);
7607 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
7608 sta->addr, arvif->vdev_id, ret);
7609 } else if (old_state == IEEE80211_STA_ASSOC &&
7610 new_state == IEEE80211_STA_AUTH &&
7611 (vif->type == NL80211_IFTYPE_AP ||
7612 vif->type == NL80211_IFTYPE_MESH_POINT ||
7613 vif->type == NL80211_IFTYPE_ADHOC)) {
7617 ath10k_dbg(ar, ATH10K_DBG_STA, "mac sta %pM disassociated\n",
7620 ret = ath10k_station_disassoc(ar, vif, sta);
7622 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
7623 sta->addr, arvif->vdev_id, ret);
7626 mutex_unlock(&ar->conf_mutex);
7630 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
7631 u16 ac, bool enable)
7633 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7634 struct wmi_sta_uapsd_auto_trig_arg arg = {};
7635 u32 prio = 0, acc = 0;
7639 lockdep_assert_held(&ar->conf_mutex);
7641 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
7645 case IEEE80211_AC_VO:
7646 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
7647 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
7651 case IEEE80211_AC_VI:
7652 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
7653 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
7657 case IEEE80211_AC_BE:
7658 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
7659 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
7663 case IEEE80211_AC_BK:
7664 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
7665 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
7672 arvif->u.sta.uapsd |= value;
7674 arvif->u.sta.uapsd &= ~value;
7676 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
7677 WMI_STA_PS_PARAM_UAPSD,
7678 arvif->u.sta.uapsd);
7680 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
7684 if (arvif->u.sta.uapsd)
7685 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
7687 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
7689 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
7690 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
7693 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
7695 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
7697 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
7698 arvif->vdev_id, ret);
7702 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
7704 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
7705 arvif->vdev_id, ret);
7709 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
7710 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
7711 /* Only userspace can make an educated decision when to send
7712 * trigger frame. The following effectively disables u-UAPSD
7713 * autotrigger in firmware (which is enabled by default
7714 * provided the autotrigger service is available).
7718 arg.user_priority = prio;
7719 arg.service_interval = 0;
7720 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
7721 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
7723 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
7724 arvif->bssid, &arg, 1);
7726 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
7736 static int ath10k_conf_tx(struct ieee80211_hw *hw,
7737 struct ieee80211_vif *vif, u16 ac,
7738 const struct ieee80211_tx_queue_params *params)
7740 struct ath10k *ar = hw->priv;
7741 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7742 struct wmi_wmm_params_arg *p = NULL;
7745 mutex_lock(&ar->conf_mutex);
7748 case IEEE80211_AC_VO:
7749 p = &arvif->wmm_params.ac_vo;
7751 case IEEE80211_AC_VI:
7752 p = &arvif->wmm_params.ac_vi;
7754 case IEEE80211_AC_BE:
7755 p = &arvif->wmm_params.ac_be;
7757 case IEEE80211_AC_BK:
7758 p = &arvif->wmm_params.ac_bk;
7767 p->cwmin = params->cw_min;
7768 p->cwmax = params->cw_max;
7769 p->aifs = params->aifs;
7772 * The channel time duration programmed in the HW is in absolute
7773 * microseconds, while mac80211 gives the txop in units of
7776 p->txop = params->txop * 32;
7778 if (ar->wmi.ops->gen_vdev_wmm_conf) {
7779 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
7780 &arvif->wmm_params);
7782 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
7783 arvif->vdev_id, ret);
7787 /* This won't work well with multi-interface cases but it's
7788 * better than nothing.
7790 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
7792 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
7797 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
7799 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
7802 mutex_unlock(&ar->conf_mutex);
7806 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
7807 struct ieee80211_vif *vif,
7808 struct ieee80211_channel *chan,
7810 enum ieee80211_roc_type type)
7812 struct ath10k *ar = hw->priv;
7813 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7814 struct wmi_start_scan_arg arg;
7818 mutex_lock(&ar->conf_mutex);
7820 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
7825 spin_lock_bh(&ar->data_lock);
7826 switch (ar->scan.state) {
7827 case ATH10K_SCAN_IDLE:
7828 reinit_completion(&ar->scan.started);
7829 reinit_completion(&ar->scan.completed);
7830 reinit_completion(&ar->scan.on_channel);
7831 ar->scan.state = ATH10K_SCAN_STARTING;
7832 ar->scan.is_roc = true;
7833 ar->scan.vdev_id = arvif->vdev_id;
7834 ar->scan.roc_freq = chan->center_freq;
7835 ar->scan.roc_notify = true;
7838 case ATH10K_SCAN_STARTING:
7839 case ATH10K_SCAN_RUNNING:
7840 case ATH10K_SCAN_ABORTING:
7844 spin_unlock_bh(&ar->data_lock);
7849 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
7851 memset(&arg, 0, sizeof(arg));
7852 ath10k_wmi_start_scan_init(ar, &arg);
7853 arg.vdev_id = arvif->vdev_id;
7854 arg.scan_id = ATH10K_SCAN_ID;
7856 arg.channels[0] = chan->center_freq;
7857 arg.dwell_time_active = scan_time_msec;
7858 arg.dwell_time_passive = scan_time_msec;
7859 arg.max_scan_time = scan_time_msec;
7860 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
7861 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
7862 arg.burst_duration_ms = duration;
7864 ret = ath10k_start_scan(ar, &arg);
7866 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
7867 spin_lock_bh(&ar->data_lock);
7868 ar->scan.state = ATH10K_SCAN_IDLE;
7869 spin_unlock_bh(&ar->data_lock);
7873 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
7875 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
7877 ret = ath10k_scan_stop(ar);
7879 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
7885 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
7886 msecs_to_jiffies(duration));
7890 mutex_unlock(&ar->conf_mutex);
7894 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw,
7895 struct ieee80211_vif *vif)
7897 struct ath10k *ar = hw->priv;
7899 mutex_lock(&ar->conf_mutex);
7901 spin_lock_bh(&ar->data_lock);
7902 ar->scan.roc_notify = false;
7903 spin_unlock_bh(&ar->data_lock);
7905 ath10k_scan_abort(ar);
7907 mutex_unlock(&ar->conf_mutex);
7909 cancel_delayed_work_sync(&ar->scan.timeout);
7915 * Both RTS and Fragmentation threshold are interface-specific
7916 * in ath10k, but device-specific in mac80211.
7919 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
7921 struct ath10k *ar = hw->priv;
7922 struct ath10k_vif *arvif;
7925 mutex_lock(&ar->conf_mutex);
7926 list_for_each_entry(arvif, &ar->arvifs, list) {
7927 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
7928 arvif->vdev_id, value);
7930 ret = ath10k_mac_set_rts(arvif, value);
7932 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
7933 arvif->vdev_id, ret);
7937 mutex_unlock(&ar->conf_mutex);
7942 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
7944 /* Even though there's a WMI enum for fragmentation threshold no known
7945 * firmware actually implements it. Moreover it is not possible to rely
7946 * frame fragmentation to mac80211 because firmware clears the "more
7947 * fragments" bit in frame control making it impossible for remote
7948 * devices to reassemble frames.
7950 * Hence implement a dummy callback just to say fragmentation isn't
7951 * supported. This effectively prevents mac80211 from doing frame
7952 * fragmentation in software.
7957 void ath10k_mac_wait_tx_complete(struct ath10k *ar)
7962 /* mac80211 doesn't care if we really xmit queued frames or not
7963 * we'll collect those frames either way if we stop/delete vdevs
7966 if (ar->state == ATH10K_STATE_WEDGED)
7969 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
7972 spin_lock_bh(&ar->htt.tx_lock);
7973 empty = (ar->htt.num_pending_tx == 0);
7974 spin_unlock_bh(&ar->htt.tx_lock);
7976 skip = (ar->state == ATH10K_STATE_WEDGED) ||
7977 test_bit(ATH10K_FLAG_CRASH_FLUSH,
7981 }), ATH10K_FLUSH_TIMEOUT_HZ);
7983 if (time_left == 0 || skip)
7984 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
7985 skip, ar->state, time_left);
7988 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7989 u32 queues, bool drop)
7991 struct ath10k *ar = hw->priv;
7992 struct ath10k_vif *arvif;
7996 if (vif && vif->type == NL80211_IFTYPE_STATION) {
7997 bitmap = ~(1 << WMI_MGMT_TID);
7998 list_for_each_entry(arvif, &ar->arvifs, list) {
7999 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
8000 ath10k_wmi_peer_flush(ar, arvif->vdev_id,
8001 arvif->bssid, bitmap);
8003 ath10k_htt_flush_tx(&ar->htt);
8008 mutex_lock(&ar->conf_mutex);
8009 ath10k_mac_wait_tx_complete(ar);
8010 mutex_unlock(&ar->conf_mutex);
8013 /* TODO: Implement this function properly
8014 * For now it is needed to reply to Probe Requests in IBSS mode.
8015 * Propably we need this information from FW.
8017 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
8022 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
8023 enum ieee80211_reconfig_type reconfig_type)
8025 struct ath10k *ar = hw->priv;
8027 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
8030 mutex_lock(&ar->conf_mutex);
8032 /* If device failed to restart it will be in a different state, e.g.
8033 * ATH10K_STATE_WEDGED
8035 if (ar->state == ATH10K_STATE_RESTARTED) {
8036 ath10k_info(ar, "device successfully recovered\n");
8037 ar->state = ATH10K_STATE_ON;
8038 ieee80211_wake_queues(ar->hw);
8039 clear_bit(ATH10K_FLAG_RESTARTING, &ar->dev_flags);
8042 mutex_unlock(&ar->conf_mutex);
8046 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
8047 struct ieee80211_channel *channel)
8050 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
8052 lockdep_assert_held(&ar->conf_mutex);
8054 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
8055 (ar->rx_channel != channel))
8058 if (ar->scan.state != ATH10K_SCAN_IDLE) {
8059 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
8063 reinit_completion(&ar->bss_survey_done);
8065 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
8067 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
8071 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
8073 ath10k_warn(ar, "bss channel survey timed out\n");
8078 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
8079 struct survey_info *survey)
8081 struct ath10k *ar = hw->priv;
8082 struct ieee80211_supported_band *sband;
8083 struct survey_info *ar_survey = &ar->survey[idx];
8086 mutex_lock(&ar->conf_mutex);
8088 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
8089 if (sband && idx >= sband->n_channels) {
8090 idx -= sband->n_channels;
8095 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
8097 if (!sband || idx >= sband->n_channels) {
8102 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
8104 spin_lock_bh(&ar->data_lock);
8105 memcpy(survey, ar_survey, sizeof(*survey));
8106 spin_unlock_bh(&ar->data_lock);
8108 survey->channel = &sband->channels[idx];
8110 if (ar->rx_channel == survey->channel)
8111 survey->filled |= SURVEY_INFO_IN_USE;
8114 mutex_unlock(&ar->conf_mutex);
8119 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
8120 enum nl80211_band band,
8121 const struct cfg80211_bitrate_mask *mask,
8124 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
8125 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8127 u8 vht_nss_mask = 0;
8130 if (mask->control[band].legacy)
8133 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
8134 if (mask->control[band].ht_mcs[i] == 0)
8136 else if (mask->control[band].ht_mcs[i] ==
8137 sband->ht_cap.mcs.rx_mask[i])
8138 ht_nss_mask |= BIT(i);
8143 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
8144 if (mask->control[band].vht_mcs[i] == 0)
8146 else if (mask->control[band].vht_mcs[i] ==
8147 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
8148 vht_nss_mask |= BIT(i);
8153 if (ht_nss_mask != vht_nss_mask)
8156 if (ht_nss_mask == 0)
8159 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
8162 *nss = fls(ht_nss_mask);
8167 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
8168 u8 rate, u8 nss, u8 sgi, u8 ldpc)
8170 struct ath10k *ar = arvif->ar;
8174 lockdep_assert_held(&ar->conf_mutex);
8176 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n",
8177 arvif->vdev_id, rate, nss, sgi);
8179 vdev_param = ar->wmi.vdev_param->fixed_rate;
8180 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
8182 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
8187 vdev_param = ar->wmi.vdev_param->nss;
8188 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
8190 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
8194 vdev_param = ar->wmi.vdev_param->sgi;
8195 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
8197 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
8201 vdev_param = ar->wmi.vdev_param->ldpc;
8202 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
8204 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
8212 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
8213 enum nl80211_band band,
8214 const struct cfg80211_bitrate_mask *mask,
8220 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
8221 * to express all VHT MCS rate masks. Effectively only the following
8222 * ranges can be used: none, 0-7, 0-8 and 0-9.
8224 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8225 vht_mcs = mask->control[band].vht_mcs[i];
8235 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
8243 static bool ath10k_mac_set_vht_bitrate_mask_fixup(struct ath10k *ar,
8244 struct ath10k_vif *arvif,
8245 struct ieee80211_sta *sta)
8248 u8 rate = arvif->vht_pfr;
8250 /* skip non vht and multiple rate peers */
8251 if (!sta->vht_cap.vht_supported || arvif->vht_num_rates != 1)
8254 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
8255 WMI_PEER_PARAM_FIXED_RATE, rate);
8257 ath10k_warn(ar, "failed to enable STA %pM peer fixed rate: %d\n",
8263 static void ath10k_mac_set_bitrate_mask_iter(void *data,
8264 struct ieee80211_sta *sta)
8266 struct ath10k_vif *arvif = data;
8267 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
8268 struct ath10k *ar = arvif->ar;
8270 if (arsta->arvif != arvif)
8273 if (ath10k_mac_set_vht_bitrate_mask_fixup(ar, arvif, sta))
8276 spin_lock_bh(&ar->data_lock);
8277 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
8278 spin_unlock_bh(&ar->data_lock);
8280 ieee80211_queue_work(ar->hw, &arsta->update_wk);
8283 static void ath10k_mac_clr_bitrate_mask_iter(void *data,
8284 struct ieee80211_sta *sta)
8286 struct ath10k_vif *arvif = data;
8287 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
8288 struct ath10k *ar = arvif->ar;
8291 /* clear vht peers only */
8292 if (arsta->arvif != arvif || !sta->vht_cap.vht_supported)
8295 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
8296 WMI_PEER_PARAM_FIXED_RATE,
8297 WMI_FIXED_RATE_NONE);
8299 ath10k_warn(ar, "failed to clear STA %pM peer fixed rate: %d\n",
8303 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
8304 struct ieee80211_vif *vif,
8305 const struct cfg80211_bitrate_mask *mask)
8307 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8308 struct cfg80211_chan_def def;
8309 struct ath10k *ar = arvif->ar;
8310 enum nl80211_band band;
8311 const u8 *ht_mcs_mask;
8312 const u16 *vht_mcs_mask;
8319 int vht_num_rates, allow_pfr;
8321 bool update_bitrate_mask = true;
8323 if (ath10k_mac_vif_chan(vif, &def))
8326 band = def.chan->band;
8327 ht_mcs_mask = mask->control[band].ht_mcs;
8328 vht_mcs_mask = mask->control[band].vht_mcs;
8329 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
8331 sgi = mask->control[band].gi;
8332 if (sgi == NL80211_TXRATE_FORCE_LGI)
8335 allow_pfr = test_bit(ATH10K_FW_FEATURE_PEER_FIXED_RATE,
8336 ar->normal_mode_fw.fw_file.fw_features);
8338 mutex_lock(&ar->conf_mutex);
8339 ieee80211_iterate_stations_atomic(ar->hw,
8340 ath10k_mac_clr_bitrate_mask_iter,
8342 mutex_unlock(&ar->conf_mutex);
8345 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask,
8347 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
8351 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
8352 arvif->vdev_id, ret);
8355 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
8357 rate = WMI_FIXED_RATE_NONE;
8360 rate = WMI_FIXED_RATE_NONE;
8361 nss = min(ar->num_rf_chains,
8362 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
8363 ath10k_mac_max_vht_nss(vht_mcs_mask)));
8365 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask,
8369 if (!allow_pfr || vht_num_rates != 1)
8372 /* Reach here, firmware supports peer fixed rate and has
8373 * single vht rate, and don't update vif birate_mask, as
8374 * the rate only for specific peer.
8376 ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
8380 update_bitrate_mask = false;
8385 mutex_lock(&ar->conf_mutex);
8387 if (update_bitrate_mask)
8388 arvif->bitrate_mask = *mask;
8389 arvif->vht_num_rates = vht_num_rates;
8390 arvif->vht_pfr = vht_pfr;
8391 ieee80211_iterate_stations_atomic(ar->hw,
8392 ath10k_mac_set_bitrate_mask_iter,
8395 mutex_unlock(&ar->conf_mutex);
8398 mutex_lock(&ar->conf_mutex);
8400 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
8402 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
8403 arvif->vdev_id, ret);
8408 mutex_unlock(&ar->conf_mutex);
8413 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
8414 struct ieee80211_vif *vif,
8415 struct ieee80211_sta *sta,
8418 struct ath10k *ar = hw->priv;
8419 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
8420 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8421 struct ath10k_peer *peer;
8424 spin_lock_bh(&ar->data_lock);
8426 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
8428 spin_unlock_bh(&ar->data_lock);
8429 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
8430 sta->addr, arvif->vdev_id);
8434 ath10k_dbg(ar, ATH10K_DBG_STA,
8435 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
8436 sta->addr, changed, sta->bandwidth, sta->rx_nss,
8439 if (changed & IEEE80211_RC_BW_CHANGED) {
8440 bw = WMI_PEER_CHWIDTH_20MHZ;
8442 switch (sta->bandwidth) {
8443 case IEEE80211_STA_RX_BW_20:
8444 bw = WMI_PEER_CHWIDTH_20MHZ;
8446 case IEEE80211_STA_RX_BW_40:
8447 bw = WMI_PEER_CHWIDTH_40MHZ;
8449 case IEEE80211_STA_RX_BW_80:
8450 bw = WMI_PEER_CHWIDTH_80MHZ;
8452 case IEEE80211_STA_RX_BW_160:
8453 bw = WMI_PEER_CHWIDTH_160MHZ;
8456 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
8457 sta->bandwidth, sta->addr);
8458 bw = WMI_PEER_CHWIDTH_20MHZ;
8465 if (changed & IEEE80211_RC_NSS_CHANGED)
8466 arsta->nss = sta->rx_nss;
8468 if (changed & IEEE80211_RC_SMPS_CHANGED) {
8469 smps = WMI_PEER_SMPS_PS_NONE;
8471 switch (sta->smps_mode) {
8472 case IEEE80211_SMPS_AUTOMATIC:
8473 case IEEE80211_SMPS_OFF:
8474 smps = WMI_PEER_SMPS_PS_NONE;
8476 case IEEE80211_SMPS_STATIC:
8477 smps = WMI_PEER_SMPS_STATIC;
8479 case IEEE80211_SMPS_DYNAMIC:
8480 smps = WMI_PEER_SMPS_DYNAMIC;
8482 case IEEE80211_SMPS_NUM_MODES:
8483 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
8484 sta->smps_mode, sta->addr);
8485 smps = WMI_PEER_SMPS_PS_NONE;
8492 arsta->changed |= changed;
8494 spin_unlock_bh(&ar->data_lock);
8496 ieee80211_queue_work(hw, &arsta->update_wk);
8499 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
8500 struct ieee80211_vif *vif, s64 tsf_offset)
8502 struct ath10k *ar = hw->priv;
8503 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8504 u32 offset, vdev_param;
8507 if (tsf_offset < 0) {
8508 vdev_param = ar->wmi.vdev_param->dec_tsf;
8509 offset = -tsf_offset;
8511 vdev_param = ar->wmi.vdev_param->inc_tsf;
8512 offset = tsf_offset;
8515 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
8516 vdev_param, offset);
8518 if (ret && ret != -EOPNOTSUPP)
8519 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
8520 offset, vdev_param, ret);
8523 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
8524 struct ieee80211_vif *vif,
8525 struct ieee80211_ampdu_params *params)
8527 struct ath10k *ar = hw->priv;
8528 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8529 struct ieee80211_sta *sta = params->sta;
8530 enum ieee80211_ampdu_mlme_action action = params->action;
8531 u16 tid = params->tid;
8533 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %u action %d\n",
8534 arvif->vdev_id, sta->addr, tid, action);
8537 case IEEE80211_AMPDU_RX_START:
8538 case IEEE80211_AMPDU_RX_STOP:
8539 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
8540 * creation/removal. Do we need to verify this?
8543 case IEEE80211_AMPDU_TX_START:
8544 case IEEE80211_AMPDU_TX_STOP_CONT:
8545 case IEEE80211_AMPDU_TX_STOP_FLUSH:
8546 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
8547 case IEEE80211_AMPDU_TX_OPERATIONAL:
8548 /* Firmware offloads Tx aggregation entirely so deny mac80211
8549 * Tx aggregation requests.
8558 ath10k_mac_update_rx_channel(struct ath10k *ar,
8559 struct ieee80211_chanctx_conf *ctx,
8560 struct ieee80211_vif_chanctx_switch *vifs,
8563 struct cfg80211_chan_def *def = NULL;
8565 /* Both locks are required because ar->rx_channel is modified. This
8566 * allows readers to hold either lock.
8568 lockdep_assert_held(&ar->conf_mutex);
8569 lockdep_assert_held(&ar->data_lock);
8571 WARN_ON(ctx && vifs);
8572 WARN_ON(vifs && !n_vifs);
8574 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
8575 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
8576 * ppdu on Rx may reduce performance on low-end systems. It should be
8577 * possible to make tables/hashmaps to speed the lookup up (be vary of
8578 * cpu data cache lines though regarding sizes) but to keep the initial
8579 * implementation simple and less intrusive fallback to the slow lookup
8580 * only for multi-channel cases. Single-channel cases will remain to
8581 * use the old channel derival and thus performance should not be
8585 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
8586 ieee80211_iter_chan_contexts_atomic(ar->hw,
8587 ath10k_mac_get_any_chandef_iter,
8591 def = &vifs[0].new_ctx->def;
8593 ar->rx_channel = def->chan;
8594 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
8595 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
8596 /* During driver restart due to firmware assert, since mac80211
8597 * already has valid channel context for given radio, channel
8598 * context iteration return num_chanctx > 0. So fix rx_channel
8599 * when restart is in progress.
8601 ar->rx_channel = ctx->def.chan;
8603 ar->rx_channel = NULL;
8609 ath10k_mac_update_vif_chan(struct ath10k *ar,
8610 struct ieee80211_vif_chanctx_switch *vifs,
8613 struct ath10k_vif *arvif;
8617 lockdep_assert_held(&ar->conf_mutex);
8619 /* First stop monitor interface. Some FW versions crash if there's a
8620 * lone monitor interface.
8622 if (ar->monitor_started)
8623 ath10k_monitor_stop(ar);
8625 for (i = 0; i < n_vifs; i++) {
8626 arvif = (void *)vifs[i].vif->drv_priv;
8628 ath10k_dbg(ar, ATH10K_DBG_MAC,
8629 "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n",
8631 vifs[i].old_ctx->def.chan->center_freq,
8632 vifs[i].new_ctx->def.chan->center_freq,
8633 vifs[i].old_ctx->def.width,
8634 vifs[i].new_ctx->def.width);
8636 if (WARN_ON(!arvif->is_started))
8639 if (WARN_ON(!arvif->is_up))
8642 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
8644 ath10k_warn(ar, "failed to down vdev %d: %d\n",
8645 arvif->vdev_id, ret);
8650 /* All relevant vdevs are downed and associated channel resources
8651 * should be available for the channel switch now.
8654 spin_lock_bh(&ar->data_lock);
8655 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
8656 spin_unlock_bh(&ar->data_lock);
8658 for (i = 0; i < n_vifs; i++) {
8659 arvif = (void *)vifs[i].vif->drv_priv;
8661 if (WARN_ON(!arvif->is_started))
8664 if (WARN_ON(!arvif->is_up))
8667 ret = ath10k_mac_setup_bcn_tmpl(arvif);
8669 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
8672 ret = ath10k_mac_setup_prb_tmpl(arvif);
8674 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
8677 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
8679 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
8680 arvif->vdev_id, ret);
8684 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
8687 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
8688 arvif->vdev_id, ret);
8693 ath10k_monitor_recalc(ar);
8697 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
8698 struct ieee80211_chanctx_conf *ctx)
8700 struct ath10k *ar = hw->priv;
8702 ath10k_dbg(ar, ATH10K_DBG_MAC,
8703 "mac chanctx add freq %u width %d ptr %pK\n",
8704 ctx->def.chan->center_freq, ctx->def.width, ctx);
8706 mutex_lock(&ar->conf_mutex);
8708 spin_lock_bh(&ar->data_lock);
8709 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
8710 spin_unlock_bh(&ar->data_lock);
8712 ath10k_recalc_radar_detection(ar);
8713 ath10k_monitor_recalc(ar);
8715 mutex_unlock(&ar->conf_mutex);
8721 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
8722 struct ieee80211_chanctx_conf *ctx)
8724 struct ath10k *ar = hw->priv;
8726 ath10k_dbg(ar, ATH10K_DBG_MAC,
8727 "mac chanctx remove freq %u width %d ptr %pK\n",
8728 ctx->def.chan->center_freq, ctx->def.width, ctx);
8730 mutex_lock(&ar->conf_mutex);
8732 spin_lock_bh(&ar->data_lock);
8733 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
8734 spin_unlock_bh(&ar->data_lock);
8736 ath10k_recalc_radar_detection(ar);
8737 ath10k_monitor_recalc(ar);
8739 mutex_unlock(&ar->conf_mutex);
8742 struct ath10k_mac_change_chanctx_arg {
8743 struct ieee80211_chanctx_conf *ctx;
8744 struct ieee80211_vif_chanctx_switch *vifs;
8750 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
8751 struct ieee80211_vif *vif)
8753 struct ath10k_mac_change_chanctx_arg *arg = data;
8755 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
8762 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
8763 struct ieee80211_vif *vif)
8765 struct ath10k_mac_change_chanctx_arg *arg = data;
8766 struct ieee80211_chanctx_conf *ctx;
8768 ctx = rcu_access_pointer(vif->chanctx_conf);
8769 if (ctx != arg->ctx)
8772 if (WARN_ON(arg->next_vif == arg->n_vifs))
8775 arg->vifs[arg->next_vif].vif = vif;
8776 arg->vifs[arg->next_vif].old_ctx = ctx;
8777 arg->vifs[arg->next_vif].new_ctx = ctx;
8782 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
8783 struct ieee80211_chanctx_conf *ctx,
8786 struct ath10k *ar = hw->priv;
8787 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
8789 mutex_lock(&ar->conf_mutex);
8791 ath10k_dbg(ar, ATH10K_DBG_MAC,
8792 "mac chanctx change freq %u width %d ptr %pK changed %x\n",
8793 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
8795 /* This shouldn't really happen because channel switching should use
8796 * switch_vif_chanctx().
8798 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
8801 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
8802 ieee80211_iterate_active_interfaces_atomic(
8804 ATH10K_ITER_NORMAL_FLAGS,
8805 ath10k_mac_change_chanctx_cnt_iter,
8807 if (arg.n_vifs == 0)
8810 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
8815 ieee80211_iterate_active_interfaces_atomic(
8817 ATH10K_ITER_NORMAL_FLAGS,
8818 ath10k_mac_change_chanctx_fill_iter,
8820 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
8825 ath10k_recalc_radar_detection(ar);
8827 /* FIXME: How to configure Rx chains properly? */
8829 /* No other actions are actually necessary. Firmware maintains channel
8830 * definitions per vdev internally and there's no host-side channel
8831 * context abstraction to configure, e.g. channel width.
8835 mutex_unlock(&ar->conf_mutex);
8839 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
8840 struct ieee80211_vif *vif,
8841 struct ieee80211_chanctx_conf *ctx)
8843 struct ath10k *ar = hw->priv;
8844 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8847 mutex_lock(&ar->conf_mutex);
8849 ath10k_dbg(ar, ATH10K_DBG_MAC,
8850 "mac chanctx assign ptr %pK vdev_id %i\n",
8851 ctx, arvif->vdev_id);
8853 if (WARN_ON(arvif->is_started)) {
8854 mutex_unlock(&ar->conf_mutex);
8858 ret = ath10k_vdev_start(arvif, &ctx->def);
8860 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
8861 arvif->vdev_id, vif->addr,
8862 ctx->def.chan->center_freq, ret);
8866 arvif->is_started = true;
8868 ret = ath10k_mac_vif_setup_ps(arvif);
8870 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
8871 arvif->vdev_id, ret);
8875 if (vif->type == NL80211_IFTYPE_MONITOR) {
8876 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
8878 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
8879 arvif->vdev_id, ret);
8883 arvif->is_up = true;
8886 if (ath10k_mac_can_set_cts_prot(arvif)) {
8887 ret = ath10k_mac_set_cts_prot(arvif);
8889 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
8890 arvif->vdev_id, ret);
8893 if (ath10k_peer_stats_enabled(ar) &&
8894 ar->hw_params.tx_stats_over_pktlog) {
8895 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
8896 ret = ath10k_wmi_pdev_pktlog_enable(ar,
8899 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
8904 mutex_unlock(&ar->conf_mutex);
8908 ath10k_vdev_stop(arvif);
8909 arvif->is_started = false;
8910 ath10k_mac_vif_setup_ps(arvif);
8913 mutex_unlock(&ar->conf_mutex);
8918 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
8919 struct ieee80211_vif *vif,
8920 struct ieee80211_chanctx_conf *ctx)
8922 struct ath10k *ar = hw->priv;
8923 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8926 mutex_lock(&ar->conf_mutex);
8928 ath10k_dbg(ar, ATH10K_DBG_MAC,
8929 "mac chanctx unassign ptr %pK vdev_id %i\n",
8930 ctx, arvif->vdev_id);
8932 WARN_ON(!arvif->is_started);
8934 if (vif->type == NL80211_IFTYPE_MONITOR) {
8935 WARN_ON(!arvif->is_up);
8937 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
8939 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
8940 arvif->vdev_id, ret);
8942 arvif->is_up = false;
8945 ret = ath10k_vdev_stop(arvif);
8947 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
8948 arvif->vdev_id, ret);
8950 arvif->is_started = false;
8952 mutex_unlock(&ar->conf_mutex);
8956 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
8957 struct ieee80211_vif_chanctx_switch *vifs,
8959 enum ieee80211_chanctx_switch_mode mode)
8961 struct ath10k *ar = hw->priv;
8963 mutex_lock(&ar->conf_mutex);
8965 ath10k_dbg(ar, ATH10K_DBG_MAC,
8966 "mac chanctx switch n_vifs %d mode %d\n",
8968 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
8970 mutex_unlock(&ar->conf_mutex);
8974 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
8975 struct ieee80211_vif *vif,
8976 struct ieee80211_sta *sta)
8979 struct ath10k_peer *peer;
8983 list_for_each_entry(peer, &ar->peers, list)
8984 if (peer->sta == sta)
8985 peer->removed = true;
8988 /* HT MCS parameters with Nss = 1 */
8989 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss1[] = {
8990 /* MCS L20 L40 S20 S40 */
8991 {0, { 65, 135, 72, 150} },
8992 {1, { 130, 270, 144, 300} },
8993 {2, { 195, 405, 217, 450} },
8994 {3, { 260, 540, 289, 600} },
8995 {4, { 390, 810, 433, 900} },
8996 {5, { 520, 1080, 578, 1200} },
8997 {6, { 585, 1215, 650, 1350} },
8998 {7, { 650, 1350, 722, 1500} }
9001 /* HT MCS parameters with Nss = 2 */
9002 static const struct ath10k_index_ht_data_rate_type supported_ht_mcs_rate_nss2[] = {
9003 /* MCS L20 L40 S20 S40 */
9004 {0, {130, 270, 144, 300} },
9005 {1, {260, 540, 289, 600} },
9006 {2, {390, 810, 433, 900} },
9007 {3, {520, 1080, 578, 1200} },
9008 {4, {780, 1620, 867, 1800} },
9009 {5, {1040, 2160, 1156, 2400} },
9010 {6, {1170, 2430, 1300, 2700} },
9011 {7, {1300, 2700, 1444, 3000} }
9014 /* MCS parameters with Nss = 1 */
9015 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss1[] = {
9016 /* MCS L80 S80 L40 S40 L20 S20 */
9017 {0, {293, 325}, {135, 150}, {65, 72} },
9018 {1, {585, 650}, {270, 300}, {130, 144} },
9019 {2, {878, 975}, {405, 450}, {195, 217} },
9020 {3, {1170, 1300}, {540, 600}, {260, 289} },
9021 {4, {1755, 1950}, {810, 900}, {390, 433} },
9022 {5, {2340, 2600}, {1080, 1200}, {520, 578} },
9023 {6, {2633, 2925}, {1215, 1350}, {585, 650} },
9024 {7, {2925, 3250}, {1350, 1500}, {650, 722} },
9025 {8, {3510, 3900}, {1620, 1800}, {780, 867} },
9026 {9, {3900, 4333}, {1800, 2000}, {780, 867} }
9029 /*MCS parameters with Nss = 2 */
9030 static const struct ath10k_index_vht_data_rate_type supported_vht_mcs_rate_nss2[] = {
9031 /* MCS L80 S80 L40 S40 L20 S20 */
9032 {0, {585, 650}, {270, 300}, {130, 144} },
9033 {1, {1170, 1300}, {540, 600}, {260, 289} },
9034 {2, {1755, 1950}, {810, 900}, {390, 433} },
9035 {3, {2340, 2600}, {1080, 1200}, {520, 578} },
9036 {4, {3510, 3900}, {1620, 1800}, {780, 867} },
9037 {5, {4680, 5200}, {2160, 2400}, {1040, 1156} },
9038 {6, {5265, 5850}, {2430, 2700}, {1170, 1300} },
9039 {7, {5850, 6500}, {2700, 3000}, {1300, 1444} },
9040 {8, {7020, 7800}, {3240, 3600}, {1560, 1733} },
9041 {9, {7800, 8667}, {3600, 4000}, {1560, 1733} }
9044 static void ath10k_mac_get_rate_flags_ht(struct ath10k *ar, u32 rate, u8 nss, u8 mcs,
9047 struct ath10k_index_ht_data_rate_type *mcs_rate;
9049 size_t len_nss1 = ARRAY_SIZE(supported_ht_mcs_rate_nss1);
9050 size_t len_nss2 = ARRAY_SIZE(supported_ht_mcs_rate_nss2);
9052 if (mcs >= (len_nss1 + len_nss2)) {
9053 ath10k_warn(ar, "not supported mcs %d in current rate table", mcs);
9057 mcs_rate = (struct ath10k_index_ht_data_rate_type *)
9058 ((nss == 1) ? &supported_ht_mcs_rate_nss1 :
9059 &supported_ht_mcs_rate_nss2);
9061 if (mcs >= len_nss1)
9062 index = mcs - len_nss1;
9066 if (rate == mcs_rate[index].supported_rate[0]) {
9067 *bw = RATE_INFO_BW_20;
9068 } else if (rate == mcs_rate[index].supported_rate[1]) {
9069 *bw |= RATE_INFO_BW_40;
9070 } else if (rate == mcs_rate[index].supported_rate[2]) {
9071 *bw |= RATE_INFO_BW_20;
9072 *flags |= RATE_INFO_FLAGS_SHORT_GI;
9073 } else if (rate == mcs_rate[index].supported_rate[3]) {
9074 *bw |= RATE_INFO_BW_40;
9075 *flags |= RATE_INFO_FLAGS_SHORT_GI;
9077 ath10k_warn(ar, "invalid ht params rate %d 100kbps nss %d mcs %d",
9082 static void ath10k_mac_get_rate_flags_vht(struct ath10k *ar, u32 rate, u8 nss, u8 mcs,
9085 struct ath10k_index_vht_data_rate_type *mcs_rate;
9087 mcs_rate = (struct ath10k_index_vht_data_rate_type *)
9088 ((nss == 1) ? &supported_vht_mcs_rate_nss1 :
9089 &supported_vht_mcs_rate_nss2);
9091 if (rate == mcs_rate[mcs].supported_VHT80_rate[0]) {
9092 *bw = RATE_INFO_BW_80;
9093 } else if (rate == mcs_rate[mcs].supported_VHT80_rate[1]) {
9094 *bw = RATE_INFO_BW_80;
9095 *flags |= RATE_INFO_FLAGS_SHORT_GI;
9096 } else if (rate == mcs_rate[mcs].supported_VHT40_rate[0]) {
9097 *bw = RATE_INFO_BW_40;
9098 } else if (rate == mcs_rate[mcs].supported_VHT40_rate[1]) {
9099 *bw = RATE_INFO_BW_40;
9100 *flags |= RATE_INFO_FLAGS_SHORT_GI;
9101 } else if (rate == mcs_rate[mcs].supported_VHT20_rate[0]) {
9102 *bw = RATE_INFO_BW_20;
9103 } else if (rate == mcs_rate[mcs].supported_VHT20_rate[1]) {
9104 *bw = RATE_INFO_BW_20;
9105 *flags |= RATE_INFO_FLAGS_SHORT_GI;
9107 ath10k_warn(ar, "invalid vht params rate %d 100kbps nss %d mcs %d",
9112 static void ath10k_mac_get_rate_flags(struct ath10k *ar, u32 rate,
9113 enum ath10k_phy_mode mode, u8 nss, u8 mcs,
9116 if (mode == ATH10K_PHY_MODE_HT) {
9117 *flags = RATE_INFO_FLAGS_MCS;
9118 ath10k_mac_get_rate_flags_ht(ar, rate, nss, mcs, flags, bw);
9119 } else if (mode == ATH10K_PHY_MODE_VHT) {
9120 *flags = RATE_INFO_FLAGS_VHT_MCS;
9121 ath10k_mac_get_rate_flags_vht(ar, rate, nss, mcs, flags, bw);
9125 static void ath10k_mac_parse_bitrate(struct ath10k *ar, u32 rate_code,
9126 u32 bitrate_kbps, struct rate_info *rate)
9128 enum ath10k_phy_mode mode = ATH10K_PHY_MODE_LEGACY;
9129 enum wmi_rate_preamble preamble = WMI_TLV_GET_HW_RC_PREAM_V1(rate_code);
9130 u8 nss = WMI_TLV_GET_HW_RC_NSS_V1(rate_code) + 1;
9131 u8 mcs = WMI_TLV_GET_HW_RC_RATE_V1(rate_code);
9132 u8 flags = 0, bw = 0;
9134 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac parse rate code 0x%x bitrate %d kbps\n",
9135 rate_code, bitrate_kbps);
9137 if (preamble == WMI_RATE_PREAMBLE_HT)
9138 mode = ATH10K_PHY_MODE_HT;
9139 else if (preamble == WMI_RATE_PREAMBLE_VHT)
9140 mode = ATH10K_PHY_MODE_VHT;
9142 ath10k_mac_get_rate_flags(ar, bitrate_kbps / 100, mode, nss, mcs, &flags, &bw);
9144 ath10k_dbg(ar, ATH10K_DBG_MAC,
9145 "mac parse bitrate preamble %d mode %d nss %d mcs %d flags %x bw %d\n",
9146 preamble, mode, nss, mcs, flags, bw);
9148 rate->flags = flags;
9150 rate->legacy = bitrate_kbps / 100;
9155 static void ath10k_mac_sta_get_peer_stats_info(struct ath10k *ar,
9156 struct ieee80211_sta *sta,
9157 struct station_info *sinfo)
9159 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
9160 struct ath10k_peer *peer;
9161 unsigned long time_left;
9164 if (!(ar->hw_params.supports_peer_stats_info &&
9165 arsta->arvif->vdev_type == WMI_VDEV_TYPE_STA))
9168 spin_lock_bh(&ar->data_lock);
9169 peer = ath10k_peer_find(ar, arsta->arvif->vdev_id, sta->addr);
9170 spin_unlock_bh(&ar->data_lock);
9174 reinit_completion(&ar->peer_stats_info_complete);
9176 ret = ath10k_wmi_request_peer_stats_info(ar,
9177 arsta->arvif->vdev_id,
9178 WMI_REQUEST_ONE_PEER_STATS_INFO,
9179 arsta->arvif->bssid,
9181 if (ret && ret != -EOPNOTSUPP) {
9182 ath10k_warn(ar, "could not request peer stats info: %d\n", ret);
9186 time_left = wait_for_completion_timeout(&ar->peer_stats_info_complete, 3 * HZ);
9187 if (time_left == 0) {
9188 ath10k_warn(ar, "timed out waiting peer stats info\n");
9192 if (arsta->rx_rate_code != 0 && arsta->rx_bitrate_kbps != 0) {
9193 ath10k_mac_parse_bitrate(ar, arsta->rx_rate_code,
9194 arsta->rx_bitrate_kbps,
9197 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
9198 arsta->rx_rate_code = 0;
9199 arsta->rx_bitrate_kbps = 0;
9202 if (arsta->tx_rate_code != 0 && arsta->tx_bitrate_kbps != 0) {
9203 ath10k_mac_parse_bitrate(ar, arsta->tx_rate_code,
9204 arsta->tx_bitrate_kbps,
9207 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
9208 arsta->tx_rate_code = 0;
9209 arsta->tx_bitrate_kbps = 0;
9213 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
9214 struct ieee80211_vif *vif,
9215 struct ieee80211_sta *sta,
9216 struct station_info *sinfo)
9218 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
9219 struct ath10k *ar = arsta->arvif->ar;
9221 if (!ath10k_peer_stats_enabled(ar))
9224 mutex_lock(&ar->conf_mutex);
9225 ath10k_debug_fw_stats_request(ar);
9226 mutex_unlock(&ar->conf_mutex);
9228 sinfo->rx_duration = arsta->rx_duration;
9229 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
9231 if (arsta->txrate.legacy || arsta->txrate.nss) {
9232 if (arsta->txrate.legacy) {
9233 sinfo->txrate.legacy = arsta->txrate.legacy;
9235 sinfo->txrate.mcs = arsta->txrate.mcs;
9236 sinfo->txrate.nss = arsta->txrate.nss;
9237 sinfo->txrate.bw = arsta->txrate.bw;
9239 sinfo->txrate.flags = arsta->txrate.flags;
9240 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
9243 if (ar->htt.disable_tx_comp) {
9244 sinfo->tx_failed = arsta->tx_failed;
9245 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
9248 sinfo->tx_retries = arsta->tx_retries;
9249 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
9251 ath10k_mac_sta_get_peer_stats_info(ar, sta, sinfo);
9254 static int ath10k_mac_op_set_tid_config(struct ieee80211_hw *hw,
9255 struct ieee80211_vif *vif,
9256 struct ieee80211_sta *sta,
9257 struct cfg80211_tid_config *tid_config)
9259 struct ath10k *ar = hw->priv;
9260 struct ath10k_vif *arvif = (void *)vif->drv_priv;
9261 struct ath10k_mac_iter_tid_conf_data data = {};
9262 struct wmi_per_peer_per_tid_cfg_arg arg = {};
9265 mutex_lock(&ar->conf_mutex);
9266 arg.vdev_id = arvif->vdev_id;
9268 arvif->tids_rst = 0;
9269 memset(arvif->tid_conf_changed, 0, sizeof(arvif->tid_conf_changed));
9271 for (i = 0; i < tid_config->n_tid_conf; i++) {
9272 ret = ath10k_mac_parse_tid_config(ar, sta, vif,
9273 &tid_config->tid_conf[i],
9284 arvif->tids_rst = 0;
9285 data.curr_vif = vif;
9288 ieee80211_iterate_stations_atomic(hw, ath10k_mac_vif_stations_tid_conf,
9292 mutex_unlock(&ar->conf_mutex);
9296 static int ath10k_mac_op_reset_tid_config(struct ieee80211_hw *hw,
9297 struct ieee80211_vif *vif,
9298 struct ieee80211_sta *sta,
9301 struct ath10k_vif *arvif = (void *)vif->drv_priv;
9302 struct ath10k_mac_iter_tid_conf_data data = {};
9303 struct ath10k *ar = hw->priv;
9306 mutex_lock(&ar->conf_mutex);
9309 arvif->tids_rst = 0;
9310 ret = ath10k_mac_reset_tid_config(ar, sta, arvif, tids);
9314 arvif->tids_rst = tids;
9315 data.curr_vif = vif;
9317 ieee80211_iterate_stations_atomic(hw, ath10k_mac_vif_stations_tid_conf,
9321 mutex_unlock(&ar->conf_mutex);
9325 static const struct ieee80211_ops ath10k_ops = {
9326 .tx = ath10k_mac_op_tx,
9327 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
9328 .start = ath10k_start,
9329 .stop = ath10k_stop,
9330 .config = ath10k_config,
9331 .add_interface = ath10k_add_interface,
9332 .remove_interface = ath10k_remove_interface,
9333 .configure_filter = ath10k_configure_filter,
9334 .bss_info_changed = ath10k_bss_info_changed,
9335 .set_coverage_class = ath10k_mac_op_set_coverage_class,
9336 .hw_scan = ath10k_hw_scan,
9337 .cancel_hw_scan = ath10k_cancel_hw_scan,
9338 .set_key = ath10k_set_key,
9339 .set_default_unicast_key = ath10k_set_default_unicast_key,
9340 .sta_state = ath10k_sta_state,
9341 .sta_set_txpwr = ath10k_sta_set_txpwr,
9342 .conf_tx = ath10k_conf_tx,
9343 .remain_on_channel = ath10k_remain_on_channel,
9344 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
9345 .set_rts_threshold = ath10k_set_rts_threshold,
9346 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
9347 .flush = ath10k_flush,
9348 .tx_last_beacon = ath10k_tx_last_beacon,
9349 .set_antenna = ath10k_set_antenna,
9350 .get_antenna = ath10k_get_antenna,
9351 .reconfig_complete = ath10k_reconfig_complete,
9352 .get_survey = ath10k_get_survey,
9353 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
9354 .sta_rc_update = ath10k_sta_rc_update,
9355 .offset_tsf = ath10k_offset_tsf,
9356 .ampdu_action = ath10k_ampdu_action,
9357 .get_et_sset_count = ath10k_debug_get_et_sset_count,
9358 .get_et_stats = ath10k_debug_get_et_stats,
9359 .get_et_strings = ath10k_debug_get_et_strings,
9360 .add_chanctx = ath10k_mac_op_add_chanctx,
9361 .remove_chanctx = ath10k_mac_op_remove_chanctx,
9362 .change_chanctx = ath10k_mac_op_change_chanctx,
9363 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
9364 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
9365 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
9366 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
9367 .sta_statistics = ath10k_sta_statistics,
9368 .set_tid_config = ath10k_mac_op_set_tid_config,
9369 .reset_tid_config = ath10k_mac_op_reset_tid_config,
9371 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
9374 .suspend = ath10k_wow_op_suspend,
9375 .resume = ath10k_wow_op_resume,
9376 .set_wakeup = ath10k_wow_op_set_wakeup,
9378 #ifdef CONFIG_MAC80211_DEBUGFS
9379 .sta_add_debugfs = ath10k_sta_add_debugfs,
9381 .set_sar_specs = ath10k_mac_set_sar_specs,
9384 #define CHAN2G(_channel, _freq, _flags) { \
9385 .band = NL80211_BAND_2GHZ, \
9386 .hw_value = (_channel), \
9387 .center_freq = (_freq), \
9388 .flags = (_flags), \
9389 .max_antenna_gain = 0, \
9393 #define CHAN5G(_channel, _freq, _flags) { \
9394 .band = NL80211_BAND_5GHZ, \
9395 .hw_value = (_channel), \
9396 .center_freq = (_freq), \
9397 .flags = (_flags), \
9398 .max_antenna_gain = 0, \
9402 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
9412 CHAN2G(10, 2457, 0),
9413 CHAN2G(11, 2462, 0),
9414 CHAN2G(12, 2467, 0),
9415 CHAN2G(13, 2472, 0),
9416 CHAN2G(14, 2484, 0),
9419 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
9420 CHAN5G(36, 5180, 0),
9421 CHAN5G(40, 5200, 0),
9422 CHAN5G(44, 5220, 0),
9423 CHAN5G(48, 5240, 0),
9424 CHAN5G(52, 5260, 0),
9425 CHAN5G(56, 5280, 0),
9426 CHAN5G(60, 5300, 0),
9427 CHAN5G(64, 5320, 0),
9428 CHAN5G(100, 5500, 0),
9429 CHAN5G(104, 5520, 0),
9430 CHAN5G(108, 5540, 0),
9431 CHAN5G(112, 5560, 0),
9432 CHAN5G(116, 5580, 0),
9433 CHAN5G(120, 5600, 0),
9434 CHAN5G(124, 5620, 0),
9435 CHAN5G(128, 5640, 0),
9436 CHAN5G(132, 5660, 0),
9437 CHAN5G(136, 5680, 0),
9438 CHAN5G(140, 5700, 0),
9439 CHAN5G(144, 5720, 0),
9440 CHAN5G(149, 5745, 0),
9441 CHAN5G(153, 5765, 0),
9442 CHAN5G(157, 5785, 0),
9443 CHAN5G(161, 5805, 0),
9444 CHAN5G(165, 5825, 0),
9445 CHAN5G(169, 5845, 0),
9446 CHAN5G(173, 5865, 0),
9447 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
9448 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
9451 struct ath10k *ath10k_mac_create(size_t priv_size)
9453 struct ieee80211_hw *hw;
9454 struct ieee80211_ops *ops;
9457 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
9461 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
9474 void ath10k_mac_destroy(struct ath10k *ar)
9476 struct ieee80211_ops *ops = ar->ops;
9478 ieee80211_free_hw(ar->hw);
9482 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
9485 .types = BIT(NL80211_IFTYPE_STATION)
9486 | BIT(NL80211_IFTYPE_P2P_CLIENT)
9490 .types = BIT(NL80211_IFTYPE_P2P_GO)
9494 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
9498 .types = BIT(NL80211_IFTYPE_AP)
9499 #ifdef CONFIG_MAC80211_MESH
9500 | BIT(NL80211_IFTYPE_MESH_POINT)
9505 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
9508 .types = BIT(NL80211_IFTYPE_AP)
9509 #ifdef CONFIG_MAC80211_MESH
9510 | BIT(NL80211_IFTYPE_MESH_POINT)
9515 .types = BIT(NL80211_IFTYPE_STATION)
9519 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
9521 .limits = ath10k_if_limits,
9522 .n_limits = ARRAY_SIZE(ath10k_if_limits),
9523 .max_interfaces = 8,
9524 .num_different_channels = 1,
9525 .beacon_int_infra_match = true,
9529 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
9531 .limits = ath10k_10x_if_limits,
9532 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
9533 .max_interfaces = 8,
9534 .num_different_channels = 1,
9535 .beacon_int_infra_match = true,
9536 .beacon_int_min_gcd = 1,
9537 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9538 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
9539 BIT(NL80211_CHAN_WIDTH_20) |
9540 BIT(NL80211_CHAN_WIDTH_40) |
9541 BIT(NL80211_CHAN_WIDTH_80),
9546 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
9549 .types = BIT(NL80211_IFTYPE_STATION),
9553 .types = BIT(NL80211_IFTYPE_AP) |
9554 #ifdef CONFIG_MAC80211_MESH
9555 BIT(NL80211_IFTYPE_MESH_POINT) |
9557 BIT(NL80211_IFTYPE_P2P_CLIENT) |
9558 BIT(NL80211_IFTYPE_P2P_GO),
9562 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
9566 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
9569 .types = BIT(NL80211_IFTYPE_STATION),
9573 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
9577 .types = BIT(NL80211_IFTYPE_AP) |
9578 #ifdef CONFIG_MAC80211_MESH
9579 BIT(NL80211_IFTYPE_MESH_POINT) |
9581 BIT(NL80211_IFTYPE_P2P_GO),
9585 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
9589 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
9592 .types = BIT(NL80211_IFTYPE_STATION),
9596 .types = BIT(NL80211_IFTYPE_ADHOC),
9600 /* FIXME: This is not thouroughly tested. These combinations may over- or
9601 * underestimate hw/fw capabilities.
9603 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
9605 .limits = ath10k_tlv_if_limit,
9606 .num_different_channels = 1,
9607 .max_interfaces = 4,
9608 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
9611 .limits = ath10k_tlv_if_limit_ibss,
9612 .num_different_channels = 1,
9613 .max_interfaces = 2,
9614 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
9618 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
9620 .limits = ath10k_tlv_if_limit,
9621 .num_different_channels = 1,
9622 .max_interfaces = 4,
9623 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
9626 .limits = ath10k_tlv_qcs_if_limit,
9627 .num_different_channels = 2,
9628 .max_interfaces = 4,
9629 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
9632 .limits = ath10k_tlv_if_limit_ibss,
9633 .num_different_channels = 1,
9634 .max_interfaces = 2,
9635 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
9639 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
9642 .types = BIT(NL80211_IFTYPE_STATION),
9646 .types = BIT(NL80211_IFTYPE_AP)
9647 #ifdef CONFIG_MAC80211_MESH
9648 | BIT(NL80211_IFTYPE_MESH_POINT)
9653 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
9655 .limits = ath10k_10_4_if_limits,
9656 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
9657 .max_interfaces = 16,
9658 .num_different_channels = 1,
9659 .beacon_int_infra_match = true,
9660 .beacon_int_min_gcd = 1,
9661 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9662 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
9663 BIT(NL80211_CHAN_WIDTH_20) |
9664 BIT(NL80211_CHAN_WIDTH_40) |
9665 BIT(NL80211_CHAN_WIDTH_80) |
9666 BIT(NL80211_CHAN_WIDTH_80P80) |
9667 BIT(NL80211_CHAN_WIDTH_160),
9673 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = {
9675 .limits = ath10k_10_4_if_limits,
9676 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
9677 .max_interfaces = 16,
9678 .num_different_channels = 1,
9679 .beacon_int_infra_match = true,
9680 .beacon_int_min_gcd = 100,
9681 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
9682 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
9683 BIT(NL80211_CHAN_WIDTH_20) |
9684 BIT(NL80211_CHAN_WIDTH_40) |
9685 BIT(NL80211_CHAN_WIDTH_80) |
9686 BIT(NL80211_CHAN_WIDTH_80P80) |
9687 BIT(NL80211_CHAN_WIDTH_160),
9692 static void ath10k_get_arvif_iter(void *data, u8 *mac,
9693 struct ieee80211_vif *vif)
9695 struct ath10k_vif_iter *arvif_iter = data;
9696 struct ath10k_vif *arvif = (void *)vif->drv_priv;
9698 if (arvif->vdev_id == arvif_iter->vdev_id)
9699 arvif_iter->arvif = arvif;
9702 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
9704 struct ath10k_vif_iter arvif_iter;
9706 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
9707 arvif_iter.vdev_id = vdev_id;
9709 ieee80211_iterate_active_interfaces_atomic(ar->hw,
9710 ATH10K_ITER_RESUME_FLAGS,
9711 ath10k_get_arvif_iter,
9713 if (!arvif_iter.arvif) {
9714 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
9718 return arvif_iter.arvif;
9721 #define WRD_METHOD "WRDD"
9722 #define WRDD_WIFI (0x07)
9724 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
9726 union acpi_object *mcc_pkg;
9727 union acpi_object *domain_type;
9728 union acpi_object *mcc_value;
9731 if (wrdd->type != ACPI_TYPE_PACKAGE ||
9732 wrdd->package.count < 2 ||
9733 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
9734 wrdd->package.elements[0].integer.value != 0) {
9735 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
9739 for (i = 1; i < wrdd->package.count; ++i) {
9740 mcc_pkg = &wrdd->package.elements[i];
9742 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
9744 if (mcc_pkg->package.count < 2)
9746 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
9747 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
9750 domain_type = &mcc_pkg->package.elements[0];
9751 if (domain_type->integer.value != WRDD_WIFI)
9754 mcc_value = &mcc_pkg->package.elements[1];
9755 return mcc_value->integer.value;
9760 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
9762 acpi_handle root_handle;
9764 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
9769 root_handle = ACPI_HANDLE(ar->dev);
9773 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
9774 if (ACPI_FAILURE(status)) {
9775 ath10k_dbg(ar, ATH10K_DBG_BOOT,
9776 "failed to get wrd method %d\n", status);
9780 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
9781 if (ACPI_FAILURE(status)) {
9782 ath10k_dbg(ar, ATH10K_DBG_BOOT,
9783 "failed to call wrdc %d\n", status);
9787 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
9788 kfree(wrdd.pointer);
9792 alpha2[0] = (alpha2_code >> 8) & 0xff;
9793 alpha2[1] = (alpha2_code >> 0) & 0xff;
9796 ath10k_dbg(ar, ATH10K_DBG_BOOT,
9797 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
9799 *rd = ath_regd_find_country_by_name(alpha2);
9803 *rd |= COUNTRY_ERD_FLAG;
9807 static int ath10k_mac_init_rd(struct ath10k *ar)
9812 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
9814 ath10k_dbg(ar, ATH10K_DBG_BOOT,
9815 "fallback to eeprom programmed regulatory settings\n");
9816 rd = ar->hw_eeprom_rd;
9819 ar->ath_common.regulatory.current_rd = rd;
9823 int ath10k_mac_register(struct ath10k *ar)
9825 static const u32 cipher_suites[] = {
9826 WLAN_CIPHER_SUITE_WEP40,
9827 WLAN_CIPHER_SUITE_WEP104,
9828 WLAN_CIPHER_SUITE_TKIP,
9829 WLAN_CIPHER_SUITE_CCMP,
9831 /* Do not add hardware supported ciphers before this line.
9832 * Allow software encryption for all chips. Don't forget to
9833 * update n_cipher_suites below.
9835 WLAN_CIPHER_SUITE_AES_CMAC,
9836 WLAN_CIPHER_SUITE_BIP_CMAC_256,
9837 WLAN_CIPHER_SUITE_BIP_GMAC_128,
9838 WLAN_CIPHER_SUITE_BIP_GMAC_256,
9840 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
9841 * and CCMP-256 in hardware.
9843 WLAN_CIPHER_SUITE_GCMP,
9844 WLAN_CIPHER_SUITE_GCMP_256,
9845 WLAN_CIPHER_SUITE_CCMP_256,
9847 struct ieee80211_supported_band *band;
9851 if (!is_valid_ether_addr(ar->mac_addr)) {
9852 ath10k_warn(ar, "invalid MAC address; choosing random\n");
9853 eth_random_addr(ar->mac_addr);
9855 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
9857 SET_IEEE80211_DEV(ar->hw, ar->dev);
9859 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
9860 ARRAY_SIZE(ath10k_5ghz_channels)) !=
9863 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
9864 channels = kmemdup(ath10k_2ghz_channels,
9865 sizeof(ath10k_2ghz_channels),
9872 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
9873 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
9874 band->channels = channels;
9876 if (ar->hw_params.cck_rate_map_rev2) {
9877 band->n_bitrates = ath10k_g_rates_rev2_size;
9878 band->bitrates = ath10k_g_rates_rev2;
9880 band->n_bitrates = ath10k_g_rates_size;
9881 band->bitrates = ath10k_g_rates;
9884 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
9887 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
9888 channels = kmemdup(ath10k_5ghz_channels,
9889 sizeof(ath10k_5ghz_channels),
9896 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
9897 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
9898 band->channels = channels;
9899 band->n_bitrates = ath10k_a_rates_size;
9900 band->bitrates = ath10k_a_rates;
9901 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
9904 wiphy_read_of_freq_limits(ar->hw->wiphy);
9905 ath10k_mac_setup_ht_vht_cap(ar);
9907 ar->hw->wiphy->interface_modes =
9908 BIT(NL80211_IFTYPE_STATION) |
9909 BIT(NL80211_IFTYPE_AP) |
9910 BIT(NL80211_IFTYPE_MESH_POINT);
9912 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
9913 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
9915 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
9916 ar->hw->wiphy->interface_modes |=
9917 BIT(NL80211_IFTYPE_P2P_DEVICE) |
9918 BIT(NL80211_IFTYPE_P2P_CLIENT) |
9919 BIT(NL80211_IFTYPE_P2P_GO);
9921 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
9923 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
9924 ar->running_fw->fw_file.fw_features)) {
9925 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
9926 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
9929 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
9930 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
9931 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
9932 ieee80211_hw_set(ar->hw, AP_LINK_PS);
9933 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
9934 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
9935 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
9936 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
9937 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
9938 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
9939 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
9940 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
9941 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
9943 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
9944 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
9946 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
9947 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
9949 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
9950 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
9952 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
9953 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
9954 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
9957 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
9958 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
9960 if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
9961 ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
9962 ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
9963 ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
9964 ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
9965 ar->hw->wiphy->max_sched_scan_plan_interval =
9966 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
9967 ar->hw->wiphy->max_sched_scan_plan_iterations =
9968 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
9969 ar->hw->wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
9972 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
9973 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
9974 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
9976 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
9978 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
9979 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
9981 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
9982 * that userspace (e.g. wpa_supplicant/hostapd) can generate
9983 * correct Probe Responses. This is more of a hack advert..
9985 ar->hw->wiphy->probe_resp_offload |=
9986 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
9987 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
9988 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
9991 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
9992 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
9993 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
9994 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
9995 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
9998 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
9999 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
10001 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
10002 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
10003 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
10005 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
10006 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
10007 NL80211_FEATURE_AP_SCAN;
10009 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
10011 ret = ath10k_wow_init(ar);
10013 ath10k_warn(ar, "failed to init wow: %d\n", ret);
10017 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
10018 wiphy_ext_feature_set(ar->hw->wiphy,
10019 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
10020 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_AQL);
10022 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) ||
10023 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map))
10024 wiphy_ext_feature_set(ar->hw->wiphy,
10025 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
10027 if (ath10k_peer_stats_enabled(ar) ||
10028 test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
10029 wiphy_ext_feature_set(ar->hw->wiphy,
10030 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
10032 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map))
10033 wiphy_ext_feature_set(ar->hw->wiphy,
10034 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
10036 if (test_bit(WMI_SERVICE_TX_PWR_PER_PEER, ar->wmi.svc_map))
10037 wiphy_ext_feature_set(ar->hw->wiphy,
10038 NL80211_EXT_FEATURE_STA_TX_PWR);
10040 if (test_bit(WMI_SERVICE_PEER_TID_CONFIGS_SUPPORT, ar->wmi.svc_map)) {
10041 ar->hw->wiphy->tid_config_support.vif |=
10042 BIT(NL80211_TID_CONFIG_ATTR_NOACK) |
10043 BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT) |
10044 BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG) |
10045 BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL) |
10046 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE) |
10047 BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
10049 if (test_bit(WMI_SERVICE_EXT_PEER_TID_CONFIGS_SUPPORT,
10050 ar->wmi.svc_map)) {
10051 ar->hw->wiphy->tid_config_support.vif |=
10052 BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
10055 ar->hw->wiphy->tid_config_support.peer =
10056 ar->hw->wiphy->tid_config_support.vif;
10057 ar->hw->wiphy->max_data_retry_count = ATH10K_MAX_RETRY_COUNT;
10059 ar->ops->set_tid_config = NULL;
10062 * on LL hardware queues are managed entirely by the FW
10063 * so we only advertise to mac we can do the queues thing
10065 ar->hw->queues = IEEE80211_MAX_QUEUES;
10067 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
10068 * something that vdev_ids can't reach so that we don't stop the queue
10071 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
10073 switch (ar->running_fw->fw_file.wmi_op_version) {
10074 case ATH10K_FW_WMI_OP_VERSION_MAIN:
10075 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
10076 ar->hw->wiphy->n_iface_combinations =
10077 ARRAY_SIZE(ath10k_if_comb);
10078 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
10080 case ATH10K_FW_WMI_OP_VERSION_TLV:
10081 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
10082 ar->hw->wiphy->iface_combinations =
10083 ath10k_tlv_qcs_if_comb;
10084 ar->hw->wiphy->n_iface_combinations =
10085 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
10087 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
10088 ar->hw->wiphy->n_iface_combinations =
10089 ARRAY_SIZE(ath10k_tlv_if_comb);
10091 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
10093 case ATH10K_FW_WMI_OP_VERSION_10_1:
10094 case ATH10K_FW_WMI_OP_VERSION_10_2:
10095 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
10096 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
10097 ar->hw->wiphy->n_iface_combinations =
10098 ARRAY_SIZE(ath10k_10x_if_comb);
10100 case ATH10K_FW_WMI_OP_VERSION_10_4:
10101 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
10102 ar->hw->wiphy->n_iface_combinations =
10103 ARRAY_SIZE(ath10k_10_4_if_comb);
10104 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT,
10105 ar->wmi.svc_map)) {
10106 ar->hw->wiphy->iface_combinations =
10107 ath10k_10_4_bcn_int_if_comb;
10108 ar->hw->wiphy->n_iface_combinations =
10109 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb);
10112 case ATH10K_FW_WMI_OP_VERSION_UNSET:
10113 case ATH10K_FW_WMI_OP_VERSION_MAX:
10119 if (ar->hw_params.dynamic_sar_support)
10120 ar->hw->wiphy->sar_capa = &ath10k_sar_capa;
10122 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
10123 ar->hw->netdev_features = NETIF_F_HW_CSUM;
10125 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
10126 /* Init ath dfs pattern detector */
10127 ar->ath_common.debug_mask = ATH_DBG_DFS;
10128 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
10129 NL80211_DFS_UNSET);
10131 if (!ar->dfs_detector)
10132 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
10135 ret = ath10k_mac_init_rd(ar);
10137 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
10138 goto err_dfs_detector_exit;
10141 /* Disable set_coverage_class for chipsets that do not support it. */
10142 if (!ar->hw_params.hw_ops->set_coverage_class)
10143 ar->ops->set_coverage_class = NULL;
10145 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
10146 ath10k_reg_notifier);
10148 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
10149 goto err_dfs_detector_exit;
10152 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
10153 ar->hw->wiphy->features |=
10154 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
10157 ar->hw->wiphy->cipher_suites = cipher_suites;
10159 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
10160 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
10161 * from chip specific hw_param table.
10163 if (!ar->hw_params.n_cipher_suites ||
10164 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
10165 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
10166 ar->hw_params.n_cipher_suites);
10167 ar->hw_params.n_cipher_suites = 8;
10169 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
10171 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
10173 ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER;
10175 ret = ieee80211_register_hw(ar->hw);
10177 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
10178 goto err_dfs_detector_exit;
10181 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT, ar->wmi.svc_map)) {
10182 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
10183 ar->hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
10186 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
10187 ret = regulatory_hint(ar->hw->wiphy,
10188 ar->ath_common.regulatory.alpha2);
10190 goto err_unregister;
10196 ieee80211_unregister_hw(ar->hw);
10198 err_dfs_detector_exit:
10199 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
10200 ar->dfs_detector->exit(ar->dfs_detector);
10203 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
10204 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
10206 SET_IEEE80211_DEV(ar->hw, NULL);
10210 void ath10k_mac_unregister(struct ath10k *ar)
10212 ieee80211_unregister_hw(ar->hw);
10214 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
10215 ar->dfs_detector->exit(ar->dfs_detector);
10217 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
10218 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
10220 SET_IEEE80211_DEV(ar->hw, NULL);