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>
31 static struct ieee80211_rate ath10k_rates[] = {
33 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
35 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
36 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
37 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
39 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
40 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
41 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
43 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
47 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
48 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
49 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
50 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
51 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
52 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
53 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
54 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
57 static struct ieee80211_rate ath10k_rates_rev2[] = {
59 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
61 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
62 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
63 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
65 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
66 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
67 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
69 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
70 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
71 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
73 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
74 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
75 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
76 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
77 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
78 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
79 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
80 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
83 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
85 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
86 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
87 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
88 #define ath10k_g_rates (ath10k_rates + 0)
89 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
91 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
92 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
94 #define ath10k_wmi_legacy_rates ath10k_rates
96 static bool ath10k_mac_bitrate_is_cck(int bitrate)
109 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
111 return DIV_ROUND_UP(bitrate, 5) |
112 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
115 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
116 u8 hw_rate, bool cck)
118 const struct ieee80211_rate *rate;
121 for (i = 0; i < sband->n_bitrates; i++) {
122 rate = &sband->bitrates[i];
124 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
127 if (rate->hw_value == hw_rate)
129 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
130 rate->hw_value_short == hw_rate)
137 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
142 for (i = 0; i < sband->n_bitrates; i++)
143 if (sband->bitrates[i].bitrate == bitrate)
149 static int ath10k_mac_get_rate_hw_value(int bitrate)
152 u8 hw_value_prefix = 0;
154 if (ath10k_mac_bitrate_is_cck(bitrate))
155 hw_value_prefix = WMI_RATE_PREAMBLE_CCK << 6;
157 for (i = 0; i < ARRAY_SIZE(ath10k_rates); i++) {
158 if (ath10k_rates[i].bitrate == bitrate)
159 return hw_value_prefix | ath10k_rates[i].hw_value;
165 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
167 switch ((mcs_map >> (2 * nss)) & 0x3) {
168 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
169 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
170 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
176 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
180 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
181 if (ht_mcs_mask[nss])
188 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
192 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
193 if (vht_mcs_mask[nss])
199 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
201 enum wmi_host_platform_type platform_type;
204 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
205 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
207 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
209 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
211 if (ret && ret != -EOPNOTSUPP) {
212 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
223 static int ath10k_send_key(struct ath10k_vif *arvif,
224 struct ieee80211_key_conf *key,
225 enum set_key_cmd cmd,
226 const u8 *macaddr, u32 flags)
228 struct ath10k *ar = arvif->ar;
229 struct wmi_vdev_install_key_arg arg = {
230 .vdev_id = arvif->vdev_id,
231 .key_idx = key->keyidx,
232 .key_len = key->keylen,
233 .key_data = key->key,
238 lockdep_assert_held(&arvif->ar->conf_mutex);
240 switch (key->cipher) {
241 case WLAN_CIPHER_SUITE_CCMP:
242 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
243 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
245 case WLAN_CIPHER_SUITE_TKIP:
246 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_TKIP];
247 arg.key_txmic_len = 8;
248 arg.key_rxmic_len = 8;
250 case WLAN_CIPHER_SUITE_WEP40:
251 case WLAN_CIPHER_SUITE_WEP104:
252 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_WEP];
254 case WLAN_CIPHER_SUITE_CCMP_256:
255 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_CCM];
257 case WLAN_CIPHER_SUITE_GCMP:
258 case WLAN_CIPHER_SUITE_GCMP_256:
259 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_AES_GCM];
261 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
262 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
263 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
264 case WLAN_CIPHER_SUITE_AES_CMAC:
268 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
272 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
273 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
275 if (cmd == DISABLE_KEY) {
276 arg.key_cipher = ar->wmi_key_cipher[WMI_CIPHER_NONE];
280 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
283 static int ath10k_install_key(struct ath10k_vif *arvif,
284 struct ieee80211_key_conf *key,
285 enum set_key_cmd cmd,
286 const u8 *macaddr, u32 flags)
288 struct ath10k *ar = arvif->ar;
290 unsigned long time_left;
292 lockdep_assert_held(&ar->conf_mutex);
294 reinit_completion(&ar->install_key_done);
296 if (arvif->nohwcrypt)
299 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
303 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
310 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
313 struct ath10k *ar = arvif->ar;
314 struct ath10k_peer *peer;
319 lockdep_assert_held(&ar->conf_mutex);
321 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
322 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
323 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
326 spin_lock_bh(&ar->data_lock);
327 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
328 spin_unlock_bh(&ar->data_lock);
333 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
334 if (arvif->wep_keys[i] == NULL)
337 switch (arvif->vif->type) {
338 case NL80211_IFTYPE_AP:
339 flags = WMI_KEY_PAIRWISE;
341 if (arvif->def_wep_key_idx == i)
342 flags |= WMI_KEY_TX_USAGE;
344 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
345 SET_KEY, addr, flags);
349 case NL80211_IFTYPE_ADHOC:
350 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
356 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
357 SET_KEY, addr, WMI_KEY_GROUP);
366 spin_lock_bh(&ar->data_lock);
367 peer->keys[i] = arvif->wep_keys[i];
368 spin_unlock_bh(&ar->data_lock);
371 /* In some cases (notably with static WEP IBSS with multiple keys)
372 * multicast Tx becomes broken. Both pairwise and groupwise keys are
373 * installed already. Using WMI_KEY_TX_USAGE in different combinations
374 * didn't seem help. Using def_keyid vdev parameter seems to be
375 * effective so use that.
377 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
379 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
382 if (arvif->def_wep_key_idx == -1)
385 ret = ath10k_wmi_vdev_set_param(arvif->ar,
387 arvif->ar->wmi.vdev_param->def_keyid,
388 arvif->def_wep_key_idx);
390 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
391 arvif->vdev_id, ret);
398 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
401 struct ath10k *ar = arvif->ar;
402 struct ath10k_peer *peer;
408 lockdep_assert_held(&ar->conf_mutex);
410 spin_lock_bh(&ar->data_lock);
411 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
412 spin_unlock_bh(&ar->data_lock);
417 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
418 if (peer->keys[i] == NULL)
421 /* key flags are not required to delete the key */
422 ret = ath10k_install_key(arvif, peer->keys[i],
423 DISABLE_KEY, addr, flags);
424 if (ret < 0 && first_errno == 0)
428 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
431 spin_lock_bh(&ar->data_lock);
432 peer->keys[i] = NULL;
433 spin_unlock_bh(&ar->data_lock);
439 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
442 struct ath10k_peer *peer;
445 lockdep_assert_held(&ar->data_lock);
447 /* We don't know which vdev this peer belongs to,
448 * since WMI doesn't give us that information.
450 * FIXME: multi-bss needs to be handled.
452 peer = ath10k_peer_find(ar, 0, addr);
456 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
457 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
464 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
465 struct ieee80211_key_conf *key)
467 struct ath10k *ar = arvif->ar;
468 struct ath10k_peer *peer;
475 lockdep_assert_held(&ar->conf_mutex);
478 /* since ath10k_install_key we can't hold data_lock all the
479 * time, so we try to remove the keys incrementally
481 spin_lock_bh(&ar->data_lock);
483 list_for_each_entry(peer, &ar->peers, list) {
484 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
485 if (peer->keys[i] == key) {
486 ether_addr_copy(addr, peer->addr);
487 peer->keys[i] = NULL;
492 if (i < ARRAY_SIZE(peer->keys))
495 spin_unlock_bh(&ar->data_lock);
497 if (i == ARRAY_SIZE(peer->keys))
499 /* key flags are not required to delete the key */
500 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
501 if (ret < 0 && first_errno == 0)
505 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
512 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
513 struct ieee80211_key_conf *key)
515 struct ath10k *ar = arvif->ar;
516 struct ath10k_peer *peer;
519 lockdep_assert_held(&ar->conf_mutex);
521 list_for_each_entry(peer, &ar->peers, list) {
522 if (ether_addr_equal(peer->addr, arvif->vif->addr))
525 if (ether_addr_equal(peer->addr, arvif->bssid))
528 if (peer->keys[key->keyidx] == key)
531 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
532 arvif->vdev_id, key->keyidx);
534 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
536 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
537 arvif->vdev_id, peer->addr, ret);
545 /*********************/
546 /* General utilities */
547 /*********************/
549 static inline enum wmi_phy_mode
550 chan_to_phymode(const struct cfg80211_chan_def *chandef)
552 enum wmi_phy_mode phymode = MODE_UNKNOWN;
554 switch (chandef->chan->band) {
555 case NL80211_BAND_2GHZ:
556 switch (chandef->width) {
557 case NL80211_CHAN_WIDTH_20_NOHT:
558 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
563 case NL80211_CHAN_WIDTH_20:
564 phymode = MODE_11NG_HT20;
566 case NL80211_CHAN_WIDTH_40:
567 phymode = MODE_11NG_HT40;
569 case NL80211_CHAN_WIDTH_5:
570 case NL80211_CHAN_WIDTH_10:
571 case NL80211_CHAN_WIDTH_80:
572 case NL80211_CHAN_WIDTH_80P80:
573 case NL80211_CHAN_WIDTH_160:
574 phymode = MODE_UNKNOWN;
578 case NL80211_BAND_5GHZ:
579 switch (chandef->width) {
580 case NL80211_CHAN_WIDTH_20_NOHT:
583 case NL80211_CHAN_WIDTH_20:
584 phymode = MODE_11NA_HT20;
586 case NL80211_CHAN_WIDTH_40:
587 phymode = MODE_11NA_HT40;
589 case NL80211_CHAN_WIDTH_80:
590 phymode = MODE_11AC_VHT80;
592 case NL80211_CHAN_WIDTH_160:
593 phymode = MODE_11AC_VHT160;
595 case NL80211_CHAN_WIDTH_80P80:
596 phymode = MODE_11AC_VHT80_80;
598 case NL80211_CHAN_WIDTH_5:
599 case NL80211_CHAN_WIDTH_10:
600 phymode = MODE_UNKNOWN;
608 WARN_ON(phymode == MODE_UNKNOWN);
612 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
615 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
616 * 0 for no restriction
625 switch (mpdudensity) {
631 /* Our lower layer calculations limit our precision to
648 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
649 struct cfg80211_chan_def *def)
651 struct ieee80211_chanctx_conf *conf;
654 conf = rcu_dereference(vif->chanctx_conf);
666 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
667 struct ieee80211_chanctx_conf *conf,
675 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
679 ieee80211_iter_chan_contexts_atomic(ar->hw,
680 ath10k_mac_num_chanctxs_iter,
687 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
688 struct ieee80211_chanctx_conf *conf,
691 struct cfg80211_chan_def **def = data;
696 static int ath10k_peer_create(struct ath10k *ar,
697 struct ieee80211_vif *vif,
698 struct ieee80211_sta *sta,
701 enum wmi_peer_type peer_type)
703 struct ath10k_vif *arvif;
704 struct ath10k_peer *peer;
708 lockdep_assert_held(&ar->conf_mutex);
710 num_peers = ar->num_peers;
712 /* Each vdev consumes a peer entry as well */
713 list_for_each_entry(arvif, &ar->arvifs, list)
716 if (num_peers >= ar->max_num_peers)
719 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
721 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
726 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
728 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
733 spin_lock_bh(&ar->data_lock);
735 peer = ath10k_peer_find(ar, vdev_id, addr);
737 spin_unlock_bh(&ar->data_lock);
738 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
740 ath10k_wmi_peer_delete(ar, vdev_id, addr);
747 spin_unlock_bh(&ar->data_lock);
754 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
756 struct ath10k *ar = arvif->ar;
760 param = ar->wmi.pdev_param->sta_kickout_th;
761 ret = ath10k_wmi_pdev_set_param(ar, param,
762 ATH10K_KICKOUT_THRESHOLD);
764 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
765 arvif->vdev_id, ret);
769 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
770 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
771 ATH10K_KEEPALIVE_MIN_IDLE);
773 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
774 arvif->vdev_id, ret);
778 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
779 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
780 ATH10K_KEEPALIVE_MAX_IDLE);
782 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
783 arvif->vdev_id, ret);
787 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
788 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
789 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
791 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
792 arvif->vdev_id, ret);
799 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
801 struct ath10k *ar = arvif->ar;
804 vdev_param = ar->wmi.vdev_param->rts_threshold;
805 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
808 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
812 lockdep_assert_held(&ar->conf_mutex);
814 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
818 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
827 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
829 struct ath10k_peer *peer, *tmp;
833 lockdep_assert_held(&ar->conf_mutex);
835 spin_lock_bh(&ar->data_lock);
836 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
837 if (peer->vdev_id != vdev_id)
840 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
841 peer->addr, vdev_id);
843 for_each_set_bit(peer_id, peer->peer_ids,
844 ATH10K_MAX_NUM_PEER_IDS) {
845 ar->peer_map[peer_id] = NULL;
848 /* Double check that peer is properly un-referenced from
851 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
852 if (ar->peer_map[i] == peer) {
853 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
854 peer->addr, peer, i);
855 ar->peer_map[i] = NULL;
859 list_del(&peer->list);
863 spin_unlock_bh(&ar->data_lock);
866 static void ath10k_peer_cleanup_all(struct ath10k *ar)
868 struct ath10k_peer *peer, *tmp;
871 lockdep_assert_held(&ar->conf_mutex);
873 spin_lock_bh(&ar->data_lock);
874 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
875 list_del(&peer->list);
879 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
880 ar->peer_map[i] = NULL;
882 spin_unlock_bh(&ar->data_lock);
885 ar->num_stations = 0;
888 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
889 struct ieee80211_sta *sta,
890 enum wmi_tdls_peer_state state)
893 struct wmi_tdls_peer_update_cmd_arg arg = {};
894 struct wmi_tdls_peer_capab_arg cap = {};
895 struct wmi_channel_arg chan_arg = {};
897 lockdep_assert_held(&ar->conf_mutex);
899 arg.vdev_id = vdev_id;
900 arg.peer_state = state;
901 ether_addr_copy(arg.addr, sta->addr);
903 cap.peer_max_sp = sta->max_sp;
904 cap.peer_uapsd_queues = sta->uapsd_queues;
906 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
907 !sta->tdls_initiator)
908 cap.is_peer_responder = 1;
910 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
912 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
913 arg.addr, vdev_id, ret);
920 /************************/
921 /* Interface management */
922 /************************/
924 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
926 struct ath10k *ar = arvif->ar;
928 lockdep_assert_held(&ar->data_lock);
933 if (!arvif->beacon_buf)
934 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
935 arvif->beacon->len, DMA_TO_DEVICE);
937 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
938 arvif->beacon_state != ATH10K_BEACON_SENT))
941 dev_kfree_skb_any(arvif->beacon);
943 arvif->beacon = NULL;
944 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
947 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
949 struct ath10k *ar = arvif->ar;
951 lockdep_assert_held(&ar->data_lock);
953 ath10k_mac_vif_beacon_free(arvif);
955 if (arvif->beacon_buf) {
956 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
957 arvif->beacon_buf, arvif->beacon_paddr);
958 arvif->beacon_buf = NULL;
962 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
964 unsigned long time_left;
966 lockdep_assert_held(&ar->conf_mutex);
968 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
971 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
972 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
976 return ar->last_wmi_vdev_start_status;
979 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
981 struct cfg80211_chan_def *chandef = NULL;
982 struct ieee80211_channel *channel = NULL;
983 struct wmi_vdev_start_request_arg arg = {};
986 lockdep_assert_held(&ar->conf_mutex);
988 ieee80211_iter_chan_contexts_atomic(ar->hw,
989 ath10k_mac_get_any_chandef_iter,
991 if (WARN_ON_ONCE(!chandef))
994 channel = chandef->chan;
996 arg.vdev_id = vdev_id;
997 arg.channel.freq = channel->center_freq;
998 arg.channel.band_center_freq1 = chandef->center_freq1;
999 arg.channel.band_center_freq2 = chandef->center_freq2;
1001 /* TODO setup this dynamically, what in case we
1002 * don't have any vifs?
1004 arg.channel.mode = chan_to_phymode(chandef);
1005 arg.channel.chan_radar =
1006 !!(channel->flags & IEEE80211_CHAN_RADAR);
1008 arg.channel.min_power = 0;
1009 arg.channel.max_power = channel->max_power * 2;
1010 arg.channel.max_reg_power = channel->max_reg_power * 2;
1011 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
1013 reinit_completion(&ar->vdev_setup_done);
1015 ret = ath10k_wmi_vdev_start(ar, &arg);
1017 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1022 ret = ath10k_vdev_setup_sync(ar);
1024 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1029 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1031 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1036 ar->monitor_vdev_id = vdev_id;
1038 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1039 ar->monitor_vdev_id);
1043 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1045 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1046 ar->monitor_vdev_id, ret);
1051 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1055 lockdep_assert_held(&ar->conf_mutex);
1057 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1059 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1060 ar->monitor_vdev_id, ret);
1062 reinit_completion(&ar->vdev_setup_done);
1064 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1066 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1067 ar->monitor_vdev_id, ret);
1069 ret = ath10k_vdev_setup_sync(ar);
1071 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1072 ar->monitor_vdev_id, ret);
1074 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1075 ar->monitor_vdev_id);
1079 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1083 lockdep_assert_held(&ar->conf_mutex);
1085 if (ar->free_vdev_map == 0) {
1086 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1090 bit = __ffs64(ar->free_vdev_map);
1092 ar->monitor_vdev_id = bit;
1094 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1095 WMI_VDEV_TYPE_MONITOR,
1098 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1099 ar->monitor_vdev_id, ret);
1103 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1104 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1105 ar->monitor_vdev_id);
1110 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1114 lockdep_assert_held(&ar->conf_mutex);
1116 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1118 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1119 ar->monitor_vdev_id, ret);
1123 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1125 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1126 ar->monitor_vdev_id);
1130 static int ath10k_monitor_start(struct ath10k *ar)
1134 lockdep_assert_held(&ar->conf_mutex);
1136 ret = ath10k_monitor_vdev_create(ar);
1138 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1142 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1144 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1145 ath10k_monitor_vdev_delete(ar);
1149 ar->monitor_started = true;
1150 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1155 static int ath10k_monitor_stop(struct ath10k *ar)
1159 lockdep_assert_held(&ar->conf_mutex);
1161 ret = ath10k_monitor_vdev_stop(ar);
1163 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1167 ret = ath10k_monitor_vdev_delete(ar);
1169 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1173 ar->monitor_started = false;
1174 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1179 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1183 /* At least one chanctx is required to derive a channel to start
1186 num_ctx = ath10k_mac_num_chanctxs(ar);
1190 /* If there's already an existing special monitor interface then don't
1191 * bother creating another monitor vdev.
1193 if (ar->monitor_arvif)
1196 return ar->monitor ||
1197 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1198 ar->running_fw->fw_file.fw_features) &&
1199 (ar->filter_flags & FIF_OTHER_BSS)) ||
1200 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1203 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1207 num_ctx = ath10k_mac_num_chanctxs(ar);
1209 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1210 * shouldn't allow this but make sure to prevent handling the following
1211 * case anyway since multi-channel DFS hasn't been tested at all.
1213 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1219 static int ath10k_monitor_recalc(struct ath10k *ar)
1225 lockdep_assert_held(&ar->conf_mutex);
1227 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1228 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1230 ath10k_dbg(ar, ATH10K_DBG_MAC,
1231 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1232 ar->monitor_started, needed, allowed);
1234 if (WARN_ON(needed && !allowed)) {
1235 if (ar->monitor_started) {
1236 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1238 ret = ath10k_monitor_stop(ar);
1240 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1248 if (needed == ar->monitor_started)
1252 return ath10k_monitor_start(ar);
1254 return ath10k_monitor_stop(ar);
1257 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1259 struct ath10k *ar = arvif->ar;
1261 lockdep_assert_held(&ar->conf_mutex);
1263 if (!arvif->is_started) {
1264 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1271 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1273 struct ath10k *ar = arvif->ar;
1276 lockdep_assert_held(&ar->conf_mutex);
1278 vdev_param = ar->wmi.vdev_param->protection_mode;
1280 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1281 arvif->vdev_id, arvif->use_cts_prot);
1283 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1284 arvif->use_cts_prot ? 1 : 0);
1287 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1289 struct ath10k *ar = arvif->ar;
1290 u32 vdev_param, rts_cts = 0;
1292 lockdep_assert_held(&ar->conf_mutex);
1294 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1296 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1298 if (arvif->num_legacy_stations > 0)
1299 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1300 WMI_RTSCTS_PROFILE);
1302 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1303 WMI_RTSCTS_PROFILE);
1305 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1306 arvif->vdev_id, rts_cts);
1308 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1312 static int ath10k_start_cac(struct ath10k *ar)
1316 lockdep_assert_held(&ar->conf_mutex);
1318 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1320 ret = ath10k_monitor_recalc(ar);
1322 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1323 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1327 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1328 ar->monitor_vdev_id);
1333 static int ath10k_stop_cac(struct ath10k *ar)
1335 lockdep_assert_held(&ar->conf_mutex);
1337 /* CAC is not running - do nothing */
1338 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1341 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1342 ath10k_monitor_stop(ar);
1344 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1349 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1350 struct ieee80211_chanctx_conf *conf,
1355 if (!*ret && conf->radar_enabled)
1359 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1361 bool has_radar = false;
1363 ieee80211_iter_chan_contexts_atomic(ar->hw,
1364 ath10k_mac_has_radar_iter,
1370 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1374 lockdep_assert_held(&ar->conf_mutex);
1376 ath10k_stop_cac(ar);
1378 if (!ath10k_mac_has_radar_enabled(ar))
1381 if (ar->num_started_vdevs > 0)
1384 ret = ath10k_start_cac(ar);
1387 * Not possible to start CAC on current channel so starting
1388 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1389 * by indicating that radar was detected.
1391 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1392 ieee80211_radar_detected(ar->hw);
1396 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1398 struct ath10k *ar = arvif->ar;
1401 lockdep_assert_held(&ar->conf_mutex);
1403 reinit_completion(&ar->vdev_setup_done);
1405 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1407 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1408 arvif->vdev_id, ret);
1412 ret = ath10k_vdev_setup_sync(ar);
1414 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1415 arvif->vdev_id, ret);
1419 WARN_ON(ar->num_started_vdevs == 0);
1421 if (ar->num_started_vdevs != 0) {
1422 ar->num_started_vdevs--;
1423 ath10k_recalc_radar_detection(ar);
1429 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1430 const struct cfg80211_chan_def *chandef,
1433 struct ath10k *ar = arvif->ar;
1434 struct wmi_vdev_start_request_arg arg = {};
1437 lockdep_assert_held(&ar->conf_mutex);
1439 reinit_completion(&ar->vdev_setup_done);
1441 arg.vdev_id = arvif->vdev_id;
1442 arg.dtim_period = arvif->dtim_period;
1443 arg.bcn_intval = arvif->beacon_interval;
1445 arg.channel.freq = chandef->chan->center_freq;
1446 arg.channel.band_center_freq1 = chandef->center_freq1;
1447 arg.channel.band_center_freq2 = chandef->center_freq2;
1448 arg.channel.mode = chan_to_phymode(chandef);
1450 arg.channel.min_power = 0;
1451 arg.channel.max_power = chandef->chan->max_power * 2;
1452 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1453 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1455 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1456 arg.ssid = arvif->u.ap.ssid;
1457 arg.ssid_len = arvif->u.ap.ssid_len;
1458 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1460 /* For now allow DFS for AP mode */
1461 arg.channel.chan_radar =
1462 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1463 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1464 arg.ssid = arvif->vif->bss_conf.ssid;
1465 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1468 ath10k_dbg(ar, ATH10K_DBG_MAC,
1469 "mac vdev %d start center_freq %d phymode %s\n",
1470 arg.vdev_id, arg.channel.freq,
1471 ath10k_wmi_phymode_str(arg.channel.mode));
1474 ret = ath10k_wmi_vdev_restart(ar, &arg);
1476 ret = ath10k_wmi_vdev_start(ar, &arg);
1479 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1484 ret = ath10k_vdev_setup_sync(ar);
1487 "failed to synchronize setup for vdev %i restart %d: %d\n",
1488 arg.vdev_id, restart, ret);
1492 ar->num_started_vdevs++;
1493 ath10k_recalc_radar_detection(ar);
1498 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1499 const struct cfg80211_chan_def *def)
1501 return ath10k_vdev_start_restart(arvif, def, false);
1504 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1505 const struct cfg80211_chan_def *def)
1507 return ath10k_vdev_start_restart(arvif, def, true);
1510 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1511 struct sk_buff *bcn)
1513 struct ath10k *ar = arvif->ar;
1514 struct ieee80211_mgmt *mgmt;
1518 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1521 mgmt = (void *)bcn->data;
1522 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1523 mgmt->u.beacon.variable,
1524 bcn->len - (mgmt->u.beacon.variable -
1529 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1531 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1532 arvif->vdev_id, ret);
1539 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1540 u8 oui_type, size_t ie_offset)
1547 if (WARN_ON(skb->len < ie_offset))
1550 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1551 skb->data + ie_offset,
1552 skb->len - ie_offset);
1557 end = skb->data + skb->len;
1560 if (WARN_ON(next > end))
1563 memmove(ie, next, end - next);
1564 skb_trim(skb, skb->len - len);
1569 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1571 struct ath10k *ar = arvif->ar;
1572 struct ieee80211_hw *hw = ar->hw;
1573 struct ieee80211_vif *vif = arvif->vif;
1574 struct ieee80211_mutable_offsets offs = {};
1575 struct sk_buff *bcn;
1578 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1581 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1582 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1585 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1587 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1591 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1593 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1598 /* P2P IE is inserted by firmware automatically (as configured above)
1599 * so remove it from the base beacon template to avoid duplicate P2P
1600 * IEs in beacon frames.
1602 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1603 offsetof(struct ieee80211_mgmt,
1604 u.beacon.variable));
1606 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1611 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1619 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1621 struct ath10k *ar = arvif->ar;
1622 struct ieee80211_hw *hw = ar->hw;
1623 struct ieee80211_vif *vif = arvif->vif;
1624 struct sk_buff *prb;
1627 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1630 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1633 prb = ieee80211_proberesp_get(hw, vif);
1635 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1639 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1643 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1651 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1653 struct ath10k *ar = arvif->ar;
1654 struct cfg80211_chan_def def;
1657 /* When originally vdev is started during assign_vif_chanctx() some
1658 * information is missing, notably SSID. Firmware revisions with beacon
1659 * offloading require the SSID to be provided during vdev (re)start to
1660 * handle hidden SSID properly.
1662 * Vdev restart must be done after vdev has been both started and
1663 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1664 * deliver vdev restart response event causing timeouts during vdev
1665 * syncing in ath10k.
1667 * Note: The vdev down/up and template reinstallation could be skipped
1668 * since only wmi-tlv firmware are known to have beacon offload and
1669 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1670 * response delivery. It's probably more robust to keep it as is.
1672 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1675 if (WARN_ON(!arvif->is_started))
1678 if (WARN_ON(!arvif->is_up))
1681 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1684 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1686 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1687 arvif->vdev_id, ret);
1691 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1692 * firmware will crash upon vdev up.
1695 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1697 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1701 ret = ath10k_mac_setup_prb_tmpl(arvif);
1703 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1707 ret = ath10k_vdev_restart(arvif, &def);
1709 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1710 arvif->vdev_id, ret);
1714 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1717 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1718 arvif->vdev_id, ret);
1725 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1726 struct ieee80211_bss_conf *info)
1728 struct ath10k *ar = arvif->ar;
1731 lockdep_assert_held(&arvif->ar->conf_mutex);
1733 if (!info->enable_beacon) {
1734 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1736 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1737 arvif->vdev_id, ret);
1739 arvif->is_up = false;
1741 spin_lock_bh(&arvif->ar->data_lock);
1742 ath10k_mac_vif_beacon_free(arvif);
1743 spin_unlock_bh(&arvif->ar->data_lock);
1748 arvif->tx_seq_no = 0x1000;
1751 ether_addr_copy(arvif->bssid, info->bssid);
1753 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1756 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1757 arvif->vdev_id, ret);
1761 arvif->is_up = true;
1763 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1765 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1766 arvif->vdev_id, ret);
1770 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1773 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1774 struct ieee80211_bss_conf *info,
1775 const u8 self_peer[ETH_ALEN])
1777 struct ath10k *ar = arvif->ar;
1781 lockdep_assert_held(&arvif->ar->conf_mutex);
1783 if (!info->ibss_joined) {
1784 if (is_zero_ether_addr(arvif->bssid))
1787 eth_zero_addr(arvif->bssid);
1792 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1793 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1794 ATH10K_DEFAULT_ATIM);
1796 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1797 arvif->vdev_id, ret);
1800 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1802 struct ath10k *ar = arvif->ar;
1807 lockdep_assert_held(&arvif->ar->conf_mutex);
1809 if (arvif->u.sta.uapsd)
1810 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1812 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1814 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1815 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1817 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1818 value, arvif->vdev_id, ret);
1825 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1827 struct ath10k *ar = arvif->ar;
1832 lockdep_assert_held(&arvif->ar->conf_mutex);
1834 if (arvif->u.sta.uapsd)
1835 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1837 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1839 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1840 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1843 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1844 value, arvif->vdev_id, ret);
1851 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1853 struct ath10k_vif *arvif;
1856 lockdep_assert_held(&ar->conf_mutex);
1858 list_for_each_entry(arvif, &ar->arvifs, list)
1859 if (arvif->is_started)
1865 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1867 struct ath10k *ar = arvif->ar;
1868 struct ieee80211_vif *vif = arvif->vif;
1869 struct ieee80211_conf *conf = &ar->hw->conf;
1870 enum wmi_sta_powersave_param param;
1871 enum wmi_sta_ps_mode psmode;
1876 lockdep_assert_held(&arvif->ar->conf_mutex);
1878 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1881 enable_ps = arvif->ps;
1883 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1884 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1885 ar->running_fw->fw_file.fw_features)) {
1886 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1891 if (!arvif->is_started) {
1892 /* mac80211 can update vif powersave state while disconnected.
1893 * Firmware doesn't behave nicely and consumes more power than
1894 * necessary if PS is disabled on a non-started vdev. Hence
1895 * force-enable PS for non-running vdevs.
1897 psmode = WMI_STA_PS_MODE_ENABLED;
1898 } else if (enable_ps) {
1899 psmode = WMI_STA_PS_MODE_ENABLED;
1900 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1902 ps_timeout = conf->dynamic_ps_timeout;
1903 if (ps_timeout == 0) {
1904 /* Firmware doesn't like 0 */
1905 ps_timeout = ieee80211_tu_to_usec(
1906 vif->bss_conf.beacon_int) / 1000;
1909 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1912 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1913 arvif->vdev_id, ret);
1917 psmode = WMI_STA_PS_MODE_DISABLED;
1920 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1921 arvif->vdev_id, psmode ? "enable" : "disable");
1923 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1925 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1926 psmode, arvif->vdev_id, ret);
1933 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1935 struct ath10k *ar = arvif->ar;
1936 struct wmi_sta_keepalive_arg arg = {};
1939 lockdep_assert_held(&arvif->ar->conf_mutex);
1941 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1944 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1947 /* Some firmware revisions have a bug and ignore the `enabled` field.
1948 * Instead use the interval to disable the keepalive.
1950 arg.vdev_id = arvif->vdev_id;
1952 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1953 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1955 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1957 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1958 arvif->vdev_id, ret);
1965 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1967 struct ath10k *ar = arvif->ar;
1968 struct ieee80211_vif *vif = arvif->vif;
1971 lockdep_assert_held(&arvif->ar->conf_mutex);
1973 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1976 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1979 if (!vif->csa_active)
1985 if (!ieee80211_csa_is_complete(vif)) {
1986 ieee80211_csa_update_counter(vif);
1988 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1990 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1993 ret = ath10k_mac_setup_prb_tmpl(arvif);
1995 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1998 ieee80211_csa_finish(vif);
2002 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2004 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2006 struct ath10k *ar = arvif->ar;
2008 mutex_lock(&ar->conf_mutex);
2009 ath10k_mac_vif_ap_csa_count_down(arvif);
2010 mutex_unlock(&ar->conf_mutex);
2013 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2014 struct ieee80211_vif *vif)
2016 struct sk_buff *skb = data;
2017 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2018 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2020 if (vif->type != NL80211_IFTYPE_STATION)
2023 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2026 cancel_delayed_work(&arvif->connection_loss_work);
2029 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2031 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2032 IEEE80211_IFACE_ITER_NORMAL,
2033 ath10k_mac_handle_beacon_iter,
2037 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2038 struct ieee80211_vif *vif)
2040 u32 *vdev_id = data;
2041 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2042 struct ath10k *ar = arvif->ar;
2043 struct ieee80211_hw *hw = ar->hw;
2045 if (arvif->vdev_id != *vdev_id)
2051 ieee80211_beacon_loss(vif);
2053 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2054 * (done by mac80211) succeeds but beacons do not resume then it
2055 * doesn't make sense to continue operation. Queue connection loss work
2056 * which can be cancelled when beacon is received.
2058 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2059 ATH10K_CONNECTION_LOSS_HZ);
2062 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2064 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2065 IEEE80211_IFACE_ITER_NORMAL,
2066 ath10k_mac_handle_beacon_miss_iter,
2070 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2072 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2073 connection_loss_work.work);
2074 struct ieee80211_vif *vif = arvif->vif;
2079 ieee80211_connection_loss(vif);
2082 /**********************/
2083 /* Station management */
2084 /**********************/
2086 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2087 struct ieee80211_vif *vif)
2089 /* Some firmware revisions have unstable STA powersave when listen
2090 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2091 * generate NullFunc frames properly even if buffered frames have been
2092 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2093 * buffered frames. Often pinging the device from AP would simply fail.
2095 * As a workaround set it to 1.
2097 if (vif->type == NL80211_IFTYPE_STATION)
2100 return ar->hw->conf.listen_interval;
2103 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2104 struct ieee80211_vif *vif,
2105 struct ieee80211_sta *sta,
2106 struct wmi_peer_assoc_complete_arg *arg)
2108 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2111 lockdep_assert_held(&ar->conf_mutex);
2113 if (vif->type == NL80211_IFTYPE_STATION)
2114 aid = vif->bss_conf.aid;
2118 ether_addr_copy(arg->addr, sta->addr);
2119 arg->vdev_id = arvif->vdev_id;
2120 arg->peer_aid = aid;
2121 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2122 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2123 arg->peer_num_spatial_streams = 1;
2124 arg->peer_caps = vif->bss_conf.assoc_capability;
2127 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2128 struct ieee80211_vif *vif,
2129 struct ieee80211_sta *sta,
2130 struct wmi_peer_assoc_complete_arg *arg)
2132 struct ieee80211_bss_conf *info = &vif->bss_conf;
2133 struct cfg80211_chan_def def;
2134 struct cfg80211_bss *bss;
2135 const u8 *rsnie = NULL;
2136 const u8 *wpaie = NULL;
2138 lockdep_assert_held(&ar->conf_mutex);
2140 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2143 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2144 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2146 const struct cfg80211_bss_ies *ies;
2149 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2151 ies = rcu_dereference(bss->ies);
2153 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2154 WLAN_OUI_TYPE_MICROSOFT_WPA,
2158 cfg80211_put_bss(ar->hw->wiphy, bss);
2161 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2162 if (rsnie || wpaie) {
2163 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2164 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2168 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2169 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2173 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2174 ar->running_fw->fw_file.fw_features)) {
2175 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2179 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2180 struct ieee80211_vif *vif,
2181 struct ieee80211_sta *sta,
2182 struct wmi_peer_assoc_complete_arg *arg)
2184 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2185 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2186 struct cfg80211_chan_def def;
2187 const struct ieee80211_supported_band *sband;
2188 const struct ieee80211_rate *rates;
2189 enum nl80211_band band;
2194 lockdep_assert_held(&ar->conf_mutex);
2196 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2199 band = def.chan->band;
2200 sband = ar->hw->wiphy->bands[band];
2201 ratemask = sta->supp_rates[band];
2202 ratemask &= arvif->bitrate_mask.control[band].legacy;
2203 rates = sband->bitrates;
2205 rateset->num_rates = 0;
2207 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2208 if (!(ratemask & 1))
2211 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2212 rateset->rates[rateset->num_rates] = rate;
2213 rateset->num_rates++;
2218 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2222 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2223 if (ht_mcs_mask[nss])
2230 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2234 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2235 if (vht_mcs_mask[nss])
2241 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2242 struct ieee80211_vif *vif,
2243 struct ieee80211_sta *sta,
2244 struct wmi_peer_assoc_complete_arg *arg)
2246 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2247 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2248 struct cfg80211_chan_def def;
2249 enum nl80211_band band;
2250 const u8 *ht_mcs_mask;
2251 const u16 *vht_mcs_mask;
2256 lockdep_assert_held(&ar->conf_mutex);
2258 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2261 if (!ht_cap->ht_supported)
2264 band = def.chan->band;
2265 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2266 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2268 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2269 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2272 arg->peer_flags |= ar->wmi.peer_flags->ht;
2273 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2274 ht_cap->ampdu_factor)) - 1;
2276 arg->peer_mpdu_density =
2277 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2279 arg->peer_ht_caps = ht_cap->cap;
2280 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2282 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2283 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2285 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2286 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2287 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2290 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2291 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2292 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2294 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2295 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2298 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2299 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2300 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2303 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2304 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2305 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2306 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2307 arg->peer_rate_caps |= stbc;
2308 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2311 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2312 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2313 else if (ht_cap->mcs.rx_mask[1])
2314 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2316 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2317 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2318 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2319 max_nss = (i / 8) + 1;
2320 arg->peer_ht_rates.rates[n++] = i;
2324 * This is a workaround for HT-enabled STAs which break the spec
2325 * and have no HT capabilities RX mask (no HT RX MCS map).
2327 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2328 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2330 * Firmware asserts if such situation occurs.
2333 arg->peer_ht_rates.num_rates = 8;
2334 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2335 arg->peer_ht_rates.rates[i] = i;
2337 arg->peer_ht_rates.num_rates = n;
2338 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2341 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2343 arg->peer_ht_rates.num_rates,
2344 arg->peer_num_spatial_streams);
2347 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2348 struct ath10k_vif *arvif,
2349 struct ieee80211_sta *sta)
2355 lockdep_assert_held(&ar->conf_mutex);
2357 if (sta->wme && sta->uapsd_queues) {
2358 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2359 sta->uapsd_queues, sta->max_sp);
2361 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2362 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2363 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2364 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2365 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2366 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2367 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2368 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2369 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2370 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2371 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2372 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2374 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2375 max_sp = sta->max_sp;
2377 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2379 WMI_AP_PS_PEER_PARAM_UAPSD,
2382 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2383 arvif->vdev_id, ret);
2387 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2389 WMI_AP_PS_PEER_PARAM_MAX_SP,
2392 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2393 arvif->vdev_id, ret);
2397 /* TODO setup this based on STA listen interval and
2398 * beacon interval. Currently we don't know
2399 * sta->listen_interval - mac80211 patch required.
2400 * Currently use 10 seconds
2402 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2403 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2406 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2407 arvif->vdev_id, ret);
2416 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2417 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2424 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2425 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2429 idx_limit = fls(mcs_map) - 1;
2433 switch (idx_limit) {
2434 case 0: /* fall through */
2435 case 1: /* fall through */
2436 case 2: /* fall through */
2437 case 3: /* fall through */
2438 case 4: /* fall through */
2439 case 5: /* fall through */
2440 case 6: /* fall through */
2442 /* see ath10k_mac_can_set_bitrate_mask() */
2446 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2449 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2452 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2455 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2459 tx_mcs_set &= ~(0x3 << (nss * 2));
2460 tx_mcs_set |= mcs << (nss * 2);
2466 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2467 struct ieee80211_vif *vif,
2468 struct ieee80211_sta *sta,
2469 struct wmi_peer_assoc_complete_arg *arg)
2471 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2472 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2473 struct cfg80211_chan_def def;
2474 enum nl80211_band band;
2475 const u16 *vht_mcs_mask;
2477 u8 max_nss, vht_mcs;
2480 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2483 if (!vht_cap->vht_supported)
2486 band = def.chan->band;
2487 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2489 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2492 arg->peer_flags |= ar->wmi.peer_flags->vht;
2494 if (def.chan->band == NL80211_BAND_2GHZ)
2495 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2497 arg->peer_vht_caps = vht_cap->cap;
2499 ampdu_factor = (vht_cap->cap &
2500 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2501 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2503 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2504 * zero in VHT IE. Using it would result in degraded throughput.
2505 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2506 * it if VHT max_mpdu is smaller.
2508 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2509 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2510 ampdu_factor)) - 1);
2512 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2513 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2515 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2516 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2518 /* Calculate peer NSS capability from VHT capabilities if STA
2521 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2522 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2525 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2529 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2530 arg->peer_vht_rates.rx_max_rate =
2531 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2532 arg->peer_vht_rates.rx_mcs_set =
2533 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2534 arg->peer_vht_rates.tx_max_rate =
2535 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2536 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2537 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2539 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2540 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2542 if (arg->peer_vht_rates.rx_max_rate &&
2543 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2544 switch (arg->peer_vht_rates.rx_max_rate) {
2546 /* Must be 2x2 at 160Mhz is all it can do. */
2547 arg->peer_bw_rxnss_override = 2;
2550 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2551 arg->peer_bw_rxnss_override = 1;
2557 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2558 struct ieee80211_vif *vif,
2559 struct ieee80211_sta *sta,
2560 struct wmi_peer_assoc_complete_arg *arg)
2562 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2564 switch (arvif->vdev_type) {
2565 case WMI_VDEV_TYPE_AP:
2567 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2569 if (sta->wme && sta->uapsd_queues) {
2570 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2571 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2574 case WMI_VDEV_TYPE_STA:
2576 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2578 case WMI_VDEV_TYPE_IBSS:
2580 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2586 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2587 sta->addr, !!(arg->peer_flags &
2588 arvif->ar->wmi.peer_flags->qos));
2591 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2593 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2594 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2597 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2598 struct ieee80211_sta *sta)
2600 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2601 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2602 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2603 return MODE_11AC_VHT160;
2604 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2605 return MODE_11AC_VHT80_80;
2607 /* not sure if this is a valid case? */
2608 return MODE_11AC_VHT160;
2612 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2613 return MODE_11AC_VHT80;
2615 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2616 return MODE_11AC_VHT40;
2618 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2619 return MODE_11AC_VHT20;
2621 return MODE_UNKNOWN;
2624 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2625 struct ieee80211_vif *vif,
2626 struct ieee80211_sta *sta,
2627 struct wmi_peer_assoc_complete_arg *arg)
2629 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2630 struct cfg80211_chan_def def;
2631 enum nl80211_band band;
2632 const u8 *ht_mcs_mask;
2633 const u16 *vht_mcs_mask;
2634 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2636 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2639 band = def.chan->band;
2640 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2641 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2644 case NL80211_BAND_2GHZ:
2645 if (sta->vht_cap.vht_supported &&
2646 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2647 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2648 phymode = MODE_11AC_VHT40;
2650 phymode = MODE_11AC_VHT20;
2651 } else if (sta->ht_cap.ht_supported &&
2652 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2653 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2654 phymode = MODE_11NG_HT40;
2656 phymode = MODE_11NG_HT20;
2657 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2664 case NL80211_BAND_5GHZ:
2668 if (sta->vht_cap.vht_supported &&
2669 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2670 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2671 } else if (sta->ht_cap.ht_supported &&
2672 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2673 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2674 phymode = MODE_11NA_HT40;
2676 phymode = MODE_11NA_HT20;
2686 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2687 sta->addr, ath10k_wmi_phymode_str(phymode));
2689 arg->peer_phymode = phymode;
2690 WARN_ON(phymode == MODE_UNKNOWN);
2693 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2694 struct ieee80211_vif *vif,
2695 struct ieee80211_sta *sta,
2696 struct wmi_peer_assoc_complete_arg *arg)
2698 lockdep_assert_held(&ar->conf_mutex);
2700 memset(arg, 0, sizeof(*arg));
2702 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2703 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2704 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2705 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2706 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2707 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2708 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2713 static const u32 ath10k_smps_map[] = {
2714 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2715 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2716 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2717 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2720 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2722 const struct ieee80211_sta_ht_cap *ht_cap)
2726 if (!ht_cap->ht_supported)
2729 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2730 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2732 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2735 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2736 WMI_PEER_SMPS_STATE,
2737 ath10k_smps_map[smps]);
2740 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2741 struct ieee80211_vif *vif,
2742 struct ieee80211_sta_vht_cap vht_cap)
2744 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2749 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2752 if (!(ar->vht_cap_info &
2753 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2754 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2755 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2756 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2759 param = ar->wmi.vdev_param->txbf;
2762 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2765 /* The following logic is correct. If a remote STA advertises support
2766 * for being a beamformer then we should enable us being a beamformee.
2769 if (ar->vht_cap_info &
2770 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2771 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2772 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2773 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2775 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2776 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2779 if (ar->vht_cap_info &
2780 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2781 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2782 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2783 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2785 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2786 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2789 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2790 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2792 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2793 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2795 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2797 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2805 /* can be called only in mac80211 callbacks due to `key_count` usage */
2806 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2807 struct ieee80211_vif *vif,
2808 struct ieee80211_bss_conf *bss_conf)
2810 struct ath10k *ar = hw->priv;
2811 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2812 struct ieee80211_sta_ht_cap ht_cap;
2813 struct ieee80211_sta_vht_cap vht_cap;
2814 struct wmi_peer_assoc_complete_arg peer_arg;
2815 struct ieee80211_sta *ap_sta;
2818 lockdep_assert_held(&ar->conf_mutex);
2820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2821 arvif->vdev_id, arvif->bssid, arvif->aid);
2825 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2827 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2828 bss_conf->bssid, arvif->vdev_id);
2833 /* ap_sta must be accessed only within rcu section which must be left
2834 * before calling ath10k_setup_peer_smps() which might sleep.
2836 ht_cap = ap_sta->ht_cap;
2837 vht_cap = ap_sta->vht_cap;
2839 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2841 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2842 bss_conf->bssid, arvif->vdev_id, ret);
2849 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2851 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2852 bss_conf->bssid, arvif->vdev_id, ret);
2856 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2858 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2859 arvif->vdev_id, ret);
2863 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2865 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2866 arvif->vdev_id, bss_conf->bssid, ret);
2870 ath10k_dbg(ar, ATH10K_DBG_MAC,
2871 "mac vdev %d up (associated) bssid %pM aid %d\n",
2872 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2874 WARN_ON(arvif->is_up);
2876 arvif->aid = bss_conf->aid;
2877 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2879 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2881 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2882 arvif->vdev_id, ret);
2886 arvif->is_up = true;
2888 /* Workaround: Some firmware revisions (tested with qca6174
2889 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2890 * poked with peer param command.
2892 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2893 WMI_PEER_DUMMY_VAR, 1);
2895 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2896 arvif->bssid, arvif->vdev_id, ret);
2901 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2902 struct ieee80211_vif *vif)
2904 struct ath10k *ar = hw->priv;
2905 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2906 struct ieee80211_sta_vht_cap vht_cap = {};
2909 lockdep_assert_held(&ar->conf_mutex);
2911 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2912 arvif->vdev_id, arvif->bssid);
2914 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2916 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2917 arvif->vdev_id, ret);
2919 arvif->def_wep_key_idx = -1;
2921 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2923 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2924 arvif->vdev_id, ret);
2928 arvif->is_up = false;
2930 cancel_delayed_work_sync(&arvif->connection_loss_work);
2933 static int ath10k_station_assoc(struct ath10k *ar,
2934 struct ieee80211_vif *vif,
2935 struct ieee80211_sta *sta,
2938 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2939 struct wmi_peer_assoc_complete_arg peer_arg;
2942 lockdep_assert_held(&ar->conf_mutex);
2944 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2946 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2947 sta->addr, arvif->vdev_id, ret);
2951 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2953 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2954 sta->addr, arvif->vdev_id, ret);
2958 /* Re-assoc is run only to update supported rates for given station. It
2959 * doesn't make much sense to reconfigure the peer completely.
2962 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2965 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2966 arvif->vdev_id, ret);
2970 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2972 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2973 sta->addr, arvif->vdev_id, ret);
2978 arvif->num_legacy_stations++;
2979 ret = ath10k_recalc_rtscts_prot(arvif);
2981 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2982 arvif->vdev_id, ret);
2987 /* Plumb cached keys only for static WEP */
2988 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
2989 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2991 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2992 arvif->vdev_id, ret);
3001 static int ath10k_station_disassoc(struct ath10k *ar,
3002 struct ieee80211_vif *vif,
3003 struct ieee80211_sta *sta)
3005 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3008 lockdep_assert_held(&ar->conf_mutex);
3011 arvif->num_legacy_stations--;
3012 ret = ath10k_recalc_rtscts_prot(arvif);
3014 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3015 arvif->vdev_id, ret);
3020 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3022 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3023 arvif->vdev_id, ret);
3034 static int ath10k_update_channel_list(struct ath10k *ar)
3036 struct ieee80211_hw *hw = ar->hw;
3037 struct ieee80211_supported_band **bands;
3038 enum nl80211_band band;
3039 struct ieee80211_channel *channel;
3040 struct wmi_scan_chan_list_arg arg = {0};
3041 struct wmi_channel_arg *ch;
3047 lockdep_assert_held(&ar->conf_mutex);
3049 bands = hw->wiphy->bands;
3050 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3054 for (i = 0; i < bands[band]->n_channels; i++) {
3055 if (bands[band]->channels[i].flags &
3056 IEEE80211_CHAN_DISABLED)
3063 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3064 arg.channels = kzalloc(len, GFP_KERNEL);
3069 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3073 for (i = 0; i < bands[band]->n_channels; i++) {
3074 channel = &bands[band]->channels[i];
3076 if (channel->flags & IEEE80211_CHAN_DISABLED)
3079 ch->allow_ht = true;
3081 /* FIXME: when should we really allow VHT? */
3082 ch->allow_vht = true;
3085 !(channel->flags & IEEE80211_CHAN_NO_IR);
3088 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3091 !!(channel->flags & IEEE80211_CHAN_RADAR);
3093 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3094 ch->passive = passive;
3096 /* the firmware is ignoring the "radar" flag of the
3097 * channel and is scanning actively using Probe Requests
3098 * on "Radar detection"/DFS channels which are not
3099 * marked as "available"
3101 ch->passive |= ch->chan_radar;
3103 ch->freq = channel->center_freq;
3104 ch->band_center_freq1 = channel->center_freq;
3106 ch->max_power = channel->max_power * 2;
3107 ch->max_reg_power = channel->max_reg_power * 2;
3108 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3109 ch->reg_class_id = 0; /* FIXME */
3111 /* FIXME: why use only legacy modes, why not any
3112 * HT/VHT modes? Would that even make any
3115 if (channel->band == NL80211_BAND_2GHZ)
3116 ch->mode = MODE_11G;
3118 ch->mode = MODE_11A;
3120 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3123 ath10k_dbg(ar, ATH10K_DBG_WMI,
3124 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3125 ch - arg.channels, arg.n_channels,
3126 ch->freq, ch->max_power, ch->max_reg_power,
3127 ch->max_antenna_gain, ch->mode);
3133 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3134 kfree(arg.channels);
3139 static enum wmi_dfs_region
3140 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3142 switch (dfs_region) {
3143 case NL80211_DFS_UNSET:
3144 return WMI_UNINIT_DFS_DOMAIN;
3145 case NL80211_DFS_FCC:
3146 return WMI_FCC_DFS_DOMAIN;
3147 case NL80211_DFS_ETSI:
3148 return WMI_ETSI_DFS_DOMAIN;
3149 case NL80211_DFS_JP:
3150 return WMI_MKK4_DFS_DOMAIN;
3152 return WMI_UNINIT_DFS_DOMAIN;
3155 static void ath10k_regd_update(struct ath10k *ar)
3157 struct reg_dmn_pair_mapping *regpair;
3159 enum wmi_dfs_region wmi_dfs_reg;
3160 enum nl80211_dfs_regions nl_dfs_reg;
3162 lockdep_assert_held(&ar->conf_mutex);
3164 ret = ath10k_update_channel_list(ar);
3166 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3168 regpair = ar->ath_common.regulatory.regpair;
3170 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3171 nl_dfs_reg = ar->dfs_detector->region;
3172 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3174 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3177 /* Target allows setting up per-band regdomain but ath_common provides
3178 * a combined one only
3180 ret = ath10k_wmi_pdev_set_regdomain(ar,
3181 regpair->reg_domain,
3182 regpair->reg_domain, /* 2ghz */
3183 regpair->reg_domain, /* 5ghz */
3184 regpair->reg_2ghz_ctl,
3185 regpair->reg_5ghz_ctl,
3188 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3191 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3192 struct ieee80211_supported_band *band)
3196 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3197 for (i = 0; i < band->n_channels; i++) {
3198 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3199 band->channels[i].center_freq > ar->high_5ghz_chan)
3200 band->channels[i].flags |=
3201 IEEE80211_CHAN_DISABLED;
3206 static void ath10k_reg_notifier(struct wiphy *wiphy,
3207 struct regulatory_request *request)
3209 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3210 struct ath10k *ar = hw->priv;
3213 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3215 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3216 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3217 request->dfs_region);
3218 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3219 request->dfs_region);
3221 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3222 request->dfs_region);
3225 mutex_lock(&ar->conf_mutex);
3226 if (ar->state == ATH10K_STATE_ON)
3227 ath10k_regd_update(ar);
3228 mutex_unlock(&ar->conf_mutex);
3230 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3231 ath10k_mac_update_channel_list(ar,
3232 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3235 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3237 spin_lock_bh(&ar->data_lock);
3238 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3239 spin_unlock_bh(&ar->data_lock);
3241 cancel_work_sync(&ar->radar_confirmation_work);
3248 enum ath10k_mac_tx_path {
3250 ATH10K_MAC_TX_HTT_MGMT,
3251 ATH10K_MAC_TX_WMI_MGMT,
3252 ATH10K_MAC_TX_UNKNOWN,
3255 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3257 lockdep_assert_held(&ar->htt.tx_lock);
3259 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3260 ar->tx_paused |= BIT(reason);
3261 ieee80211_stop_queues(ar->hw);
3264 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3265 struct ieee80211_vif *vif)
3267 struct ath10k *ar = data;
3268 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3270 if (arvif->tx_paused)
3273 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3276 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3278 lockdep_assert_held(&ar->htt.tx_lock);
3280 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3281 ar->tx_paused &= ~BIT(reason);
3286 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3287 IEEE80211_IFACE_ITER_RESUME_ALL,
3288 ath10k_mac_tx_unlock_iter,
3291 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3294 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3296 struct ath10k *ar = arvif->ar;
3298 lockdep_assert_held(&ar->htt.tx_lock);
3300 WARN_ON(reason >= BITS_PER_LONG);
3301 arvif->tx_paused |= BIT(reason);
3302 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3305 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3307 struct ath10k *ar = arvif->ar;
3309 lockdep_assert_held(&ar->htt.tx_lock);
3311 WARN_ON(reason >= BITS_PER_LONG);
3312 arvif->tx_paused &= ~BIT(reason);
3317 if (arvif->tx_paused)
3320 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3323 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3324 enum wmi_tlv_tx_pause_id pause_id,
3325 enum wmi_tlv_tx_pause_action action)
3327 struct ath10k *ar = arvif->ar;
3329 lockdep_assert_held(&ar->htt.tx_lock);
3332 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3333 ath10k_mac_vif_tx_lock(arvif, pause_id);
3335 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3336 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3339 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3340 "received unknown tx pause action %d on vdev %i, ignoring\n",
3341 action, arvif->vdev_id);
3346 struct ath10k_mac_tx_pause {
3348 enum wmi_tlv_tx_pause_id pause_id;
3349 enum wmi_tlv_tx_pause_action action;
3352 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3353 struct ieee80211_vif *vif)
3355 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3356 struct ath10k_mac_tx_pause *arg = data;
3358 if (arvif->vdev_id != arg->vdev_id)
3361 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3364 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3365 enum wmi_tlv_tx_pause_id pause_id,
3366 enum wmi_tlv_tx_pause_action action)
3368 struct ath10k_mac_tx_pause arg = {
3370 .pause_id = pause_id,
3374 spin_lock_bh(&ar->htt.tx_lock);
3375 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3376 IEEE80211_IFACE_ITER_RESUME_ALL,
3377 ath10k_mac_handle_tx_pause_iter,
3379 spin_unlock_bh(&ar->htt.tx_lock);
3382 static enum ath10k_hw_txrx_mode
3383 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3384 struct ieee80211_vif *vif,
3385 struct ieee80211_sta *sta,
3386 struct sk_buff *skb)
3388 const struct ieee80211_hdr *hdr = (void *)skb->data;
3389 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
3390 __le16 fc = hdr->frame_control;
3392 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3393 return ATH10K_HW_TXRX_RAW;
3395 if (ieee80211_is_mgmt(fc))
3396 return ATH10K_HW_TXRX_MGMT;
3400 * NullFunc frames are mostly used to ping if a client or AP are still
3401 * reachable and responsive. This implies tx status reports must be
3402 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3403 * come to a conclusion that the other end disappeared and tear down
3404 * BSS connection or it can never disconnect from BSS/client (which is
3407 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3408 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3409 * which seems to deliver correct tx reports for NullFunc frames. The
3410 * downside of using it is it ignores client powersave state so it can
3411 * end up disconnecting sleeping clients in AP mode. It should fix STA
3412 * mode though because AP don't sleep.
3414 if (ar->htt.target_version_major < 3 &&
3415 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3416 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3417 ar->running_fw->fw_file.fw_features))
3418 return ATH10K_HW_TXRX_MGMT;
3422 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3423 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3424 * to work with Ethernet txmode so use it.
3426 * FIXME: Check if raw mode works with TDLS.
3428 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3429 return ATH10K_HW_TXRX_ETHERNET;
3431 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) ||
3432 skb_cb->flags & ATH10K_SKB_F_RAW_TX)
3433 return ATH10K_HW_TXRX_RAW;
3435 return ATH10K_HW_TXRX_NATIVE_WIFI;
3438 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3439 struct sk_buff *skb)
3441 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3442 const struct ieee80211_hdr *hdr = (void *)skb->data;
3443 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3444 IEEE80211_TX_CTL_INJECTED;
3446 if (!ieee80211_has_protected(hdr->frame_control))
3449 if ((info->flags & mask) == mask)
3453 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3458 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3459 * Control in the header.
3461 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3463 struct ieee80211_hdr *hdr = (void *)skb->data;
3464 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3467 if (!ieee80211_is_data_qos(hdr->frame_control))
3470 qos_ctl = ieee80211_get_qos_ctl(hdr);
3471 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3472 skb->data, (void *)qos_ctl - (void *)skb->data);
3473 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3475 /* Some firmware revisions don't handle sending QoS NullFunc well.
3476 * These frames are mainly used for CQM purposes so it doesn't really
3477 * matter whether QoS NullFunc or NullFunc are sent.
3479 hdr = (void *)skb->data;
3480 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3481 cb->flags &= ~ATH10K_SKB_F_QOS;
3483 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3486 static void ath10k_tx_h_8023(struct sk_buff *skb)
3488 struct ieee80211_hdr *hdr;
3489 struct rfc1042_hdr *rfc1042;
3496 hdr = (void *)skb->data;
3497 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3498 rfc1042 = (void *)skb->data + hdrlen;
3500 ether_addr_copy(da, ieee80211_get_DA(hdr));
3501 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3502 type = rfc1042->snap_type;
3504 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3505 skb_push(skb, sizeof(*eth));
3507 eth = (void *)skb->data;
3508 ether_addr_copy(eth->h_dest, da);
3509 ether_addr_copy(eth->h_source, sa);
3510 eth->h_proto = type;
3513 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3514 struct ieee80211_vif *vif,
3515 struct sk_buff *skb)
3517 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3518 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3520 /* This is case only for P2P_GO */
3521 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3524 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3525 spin_lock_bh(&ar->data_lock);
3526 if (arvif->u.ap.noa_data)
3527 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3529 skb_put_data(skb, arvif->u.ap.noa_data,
3530 arvif->u.ap.noa_len);
3531 spin_unlock_bh(&ar->data_lock);
3535 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3536 struct ieee80211_vif *vif,
3537 struct ieee80211_txq *txq,
3538 struct sk_buff *skb, u16 airtime)
3540 struct ieee80211_hdr *hdr = (void *)skb->data;
3541 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3542 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3543 bool is_data = ieee80211_is_data(hdr->frame_control) ||
3544 ieee80211_is_data_qos(hdr->frame_control);
3547 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3548 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3550 if (ieee80211_is_mgmt(hdr->frame_control))
3551 cb->flags |= ATH10K_SKB_F_MGMT;
3553 if (ieee80211_is_data_qos(hdr->frame_control))
3554 cb->flags |= ATH10K_SKB_F_QOS;
3556 /* Data frames encrypted in software will be posted to firmware
3557 * with tx encap mode set to RAW. Ex: Multicast traffic generated
3558 * for a specific VLAN group will always be encrypted in software.
3560 if (is_data && ieee80211_has_protected(hdr->frame_control) &&
3561 !info->control.hw_key) {
3562 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3563 cb->flags |= ATH10K_SKB_F_RAW_TX;
3568 cb->airtime_est = airtime;
3571 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3573 /* FIXME: Not really sure since when the behaviour changed. At some
3574 * point new firmware stopped requiring creation of peer entries for
3575 * offchannel tx (and actually creating them causes issues with wmi-htc
3576 * tx credit replenishment and reliability). Assuming it's at least 3.4
3577 * because that's when the `freq` was introduced to TX_FRM HTT command.
3579 return (ar->htt.target_version_major >= 3 &&
3580 ar->htt.target_version_minor >= 4 &&
3581 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3584 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3586 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3589 spin_lock_bh(&ar->data_lock);
3591 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3592 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3597 __skb_queue_tail(q, skb);
3598 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3601 spin_unlock_bh(&ar->data_lock);
3606 static enum ath10k_mac_tx_path
3607 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3608 struct sk_buff *skb,
3609 enum ath10k_hw_txrx_mode txmode)
3612 case ATH10K_HW_TXRX_RAW:
3613 case ATH10K_HW_TXRX_NATIVE_WIFI:
3614 case ATH10K_HW_TXRX_ETHERNET:
3615 return ATH10K_MAC_TX_HTT;
3616 case ATH10K_HW_TXRX_MGMT:
3617 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3618 ar->running_fw->fw_file.fw_features) ||
3619 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3621 return ATH10K_MAC_TX_WMI_MGMT;
3622 else if (ar->htt.target_version_major >= 3)
3623 return ATH10K_MAC_TX_HTT;
3625 return ATH10K_MAC_TX_HTT_MGMT;
3628 return ATH10K_MAC_TX_UNKNOWN;
3631 static int ath10k_mac_tx_submit(struct ath10k *ar,
3632 enum ath10k_hw_txrx_mode txmode,
3633 enum ath10k_mac_tx_path txpath,
3634 struct sk_buff *skb)
3636 struct ath10k_htt *htt = &ar->htt;
3640 case ATH10K_MAC_TX_HTT:
3641 ret = ath10k_htt_tx(htt, txmode, skb);
3643 case ATH10K_MAC_TX_HTT_MGMT:
3644 ret = ath10k_htt_mgmt_tx(htt, skb);
3646 case ATH10K_MAC_TX_WMI_MGMT:
3647 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3649 case ATH10K_MAC_TX_UNKNOWN:
3656 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3658 ieee80211_free_txskb(ar->hw, skb);
3664 /* This function consumes the sk_buff regardless of return value as far as
3665 * caller is concerned so no freeing is necessary afterwards.
3667 static int ath10k_mac_tx(struct ath10k *ar,
3668 struct ieee80211_vif *vif,
3669 enum ath10k_hw_txrx_mode txmode,
3670 enum ath10k_mac_tx_path txpath,
3671 struct sk_buff *skb)
3673 struct ieee80211_hw *hw = ar->hw;
3674 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3675 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
3678 /* We should disable CCK RATE due to P2P */
3679 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3680 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3683 case ATH10K_HW_TXRX_MGMT:
3684 case ATH10K_HW_TXRX_NATIVE_WIFI:
3685 ath10k_tx_h_nwifi(hw, skb);
3686 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3687 ath10k_tx_h_seq_no(vif, skb);
3689 case ATH10K_HW_TXRX_ETHERNET:
3690 ath10k_tx_h_8023(skb);
3692 case ATH10K_HW_TXRX_RAW:
3693 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) &&
3694 !(skb_cb->flags & ATH10K_SKB_F_RAW_TX)) {
3696 ieee80211_free_txskb(hw, skb);
3701 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3702 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3703 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3706 skb_queue_tail(&ar->offchan_tx_queue, skb);
3707 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3712 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3714 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3721 void ath10k_offchan_tx_purge(struct ath10k *ar)
3723 struct sk_buff *skb;
3726 skb = skb_dequeue(&ar->offchan_tx_queue);
3730 ieee80211_free_txskb(ar->hw, skb);
3734 void ath10k_offchan_tx_work(struct work_struct *work)
3736 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3737 struct ath10k_peer *peer;
3738 struct ath10k_vif *arvif;
3739 enum ath10k_hw_txrx_mode txmode;
3740 enum ath10k_mac_tx_path txpath;
3741 struct ieee80211_hdr *hdr;
3742 struct ieee80211_vif *vif;
3743 struct ieee80211_sta *sta;
3744 struct sk_buff *skb;
3745 const u8 *peer_addr;
3748 unsigned long time_left;
3749 bool tmp_peer_created = false;
3751 /* FW requirement: We must create a peer before FW will send out
3752 * an offchannel frame. Otherwise the frame will be stuck and
3753 * never transmitted. We delete the peer upon tx completion.
3754 * It is unlikely that a peer for offchannel tx will already be
3755 * present. However it may be in some rare cases so account for that.
3756 * Otherwise we might remove a legitimate peer and break stuff.
3760 skb = skb_dequeue(&ar->offchan_tx_queue);
3764 mutex_lock(&ar->conf_mutex);
3766 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3769 hdr = (struct ieee80211_hdr *)skb->data;
3770 peer_addr = ieee80211_get_DA(hdr);
3772 spin_lock_bh(&ar->data_lock);
3773 vdev_id = ar->scan.vdev_id;
3774 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3775 spin_unlock_bh(&ar->data_lock);
3778 /* FIXME: should this use ath10k_warn()? */
3779 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3780 peer_addr, vdev_id);
3783 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3785 WMI_PEER_TYPE_DEFAULT);
3787 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3788 peer_addr, vdev_id, ret);
3789 tmp_peer_created = (ret == 0);
3792 spin_lock_bh(&ar->data_lock);
3793 reinit_completion(&ar->offchan_tx_completed);
3794 ar->offchan_tx_skb = skb;
3795 spin_unlock_bh(&ar->data_lock);
3797 /* It's safe to access vif and sta - conf_mutex guarantees that
3798 * sta_state() and remove_interface() are locked exclusively
3799 * out wrt to this offchannel worker.
3801 arvif = ath10k_get_arvif(ar, vdev_id);
3804 sta = ieee80211_find_sta(vif, peer_addr);
3810 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3811 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3813 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
3815 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3821 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3823 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3826 if (!peer && tmp_peer_created) {
3827 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3829 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3830 peer_addr, vdev_id, ret);
3833 mutex_unlock(&ar->conf_mutex);
3837 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3839 struct sk_buff *skb;
3842 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3846 ieee80211_free_txskb(ar->hw, skb);
3850 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3852 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3853 struct sk_buff *skb;
3858 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3862 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
3863 ar->running_fw->fw_file.fw_features)) {
3864 paddr = dma_map_single(ar->dev, skb->data,
3865 skb->len, DMA_TO_DEVICE);
3868 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3870 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3872 dma_unmap_single(ar->dev, paddr, skb->len,
3874 ieee80211_free_txskb(ar->hw, skb);
3877 ret = ath10k_wmi_mgmt_tx(ar, skb);
3879 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3881 ieee80211_free_txskb(ar->hw, skb);
3887 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3889 struct ath10k_txq *artxq;
3894 artxq = (void *)txq->drv_priv;
3895 INIT_LIST_HEAD(&artxq->list);
3898 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3900 struct ath10k_skb_cb *cb;
3901 struct sk_buff *msdu;
3907 spin_lock_bh(&ar->htt.tx_lock);
3908 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3909 cb = ATH10K_SKB_CB(msdu);
3913 spin_unlock_bh(&ar->htt.tx_lock);
3916 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3920 struct ath10k_peer *peer;
3922 lockdep_assert_held(&ar->data_lock);
3924 peer = ar->peer_map[peer_id];
3932 return peer->sta->txq[tid];
3934 return peer->vif->txq;
3939 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3940 struct ieee80211_txq *txq)
3942 struct ath10k *ar = hw->priv;
3943 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3945 /* No need to get locks */
3946 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3949 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3952 if (artxq->num_fw_queued < artxq->num_push_allowed)
3958 /* Return estimated airtime in microsecond, which is calculated using last
3959 * reported TX rate. This is just a rough estimation because host driver has no
3960 * knowledge of the actual transmit rate, retries or aggregation. If actual
3961 * airtime can be reported by firmware, then delta between estimated and actual
3962 * airtime can be adjusted from deficit.
3964 #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
3965 #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
3966 static u16 ath10k_mac_update_airtime(struct ath10k *ar,
3967 struct ieee80211_txq *txq,
3968 struct sk_buff *skb)
3970 struct ath10k_sta *arsta;
3974 if (!txq || !txq->sta)
3977 if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
3980 spin_lock_bh(&ar->data_lock);
3981 arsta = (struct ath10k_sta *)txq->sta->drv_priv;
3983 pktlen = skb->len + 38; /* Assume MAC header 30, SNAP 8 for most case */
3984 if (arsta->last_tx_bitrate) {
3985 /* airtime in us, last_tx_bitrate in 100kbps */
3986 airtime = (pktlen * 8 * (1000 / 100))
3987 / arsta->last_tx_bitrate;
3988 /* overhead for media access time and IFS */
3989 airtime += IEEE80211_ATF_OVERHEAD_IFS;
3991 /* This is mostly for throttle excessive BC/MC frames, and the
3992 * airtime/rate doesn't need be exact. Airtime of BC/MC frames
3993 * in 2G get some discount, which helps prevent very low rate
3994 * frames from being blocked for too long.
3996 airtime = (pktlen * 8 * (1000 / 100)) / 60; /* 6M */
3997 airtime += IEEE80211_ATF_OVERHEAD;
3999 spin_unlock_bh(&ar->data_lock);
4004 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
4005 struct ieee80211_txq *txq)
4007 struct ath10k *ar = hw->priv;
4008 struct ath10k_htt *htt = &ar->htt;
4009 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4010 struct ieee80211_vif *vif = txq->vif;
4011 struct ieee80211_sta *sta = txq->sta;
4012 enum ath10k_hw_txrx_mode txmode;
4013 enum ath10k_mac_tx_path txpath;
4014 struct sk_buff *skb;
4015 struct ieee80211_hdr *hdr;
4017 bool is_mgmt, is_presp;
4021 spin_lock_bh(&ar->htt.tx_lock);
4022 ret = ath10k_htt_tx_inc_pending(htt);
4023 spin_unlock_bh(&ar->htt.tx_lock);
4028 skb = ieee80211_tx_dequeue(hw, txq);
4030 spin_lock_bh(&ar->htt.tx_lock);
4031 ath10k_htt_tx_dec_pending(htt);
4032 spin_unlock_bh(&ar->htt.tx_lock);
4037 airtime = ath10k_mac_update_airtime(ar, txq, skb);
4038 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb, airtime);
4041 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4042 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4043 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4046 hdr = (struct ieee80211_hdr *)skb->data;
4047 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4049 spin_lock_bh(&ar->htt.tx_lock);
4050 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4053 ath10k_htt_tx_dec_pending(htt);
4054 spin_unlock_bh(&ar->htt.tx_lock);
4057 spin_unlock_bh(&ar->htt.tx_lock);
4060 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4061 if (unlikely(ret)) {
4062 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4064 spin_lock_bh(&ar->htt.tx_lock);
4065 ath10k_htt_tx_dec_pending(htt);
4067 ath10k_htt_tx_mgmt_dec_pending(htt);
4068 spin_unlock_bh(&ar->htt.tx_lock);
4073 spin_lock_bh(&ar->htt.tx_lock);
4074 artxq->num_fw_queued++;
4075 spin_unlock_bh(&ar->htt.tx_lock);
4080 static int ath10k_mac_schedule_txq(struct ieee80211_hw *hw, u32 ac)
4082 struct ieee80211_txq *txq;
4085 ieee80211_txq_schedule_start(hw, ac);
4086 while ((txq = ieee80211_next_txq(hw, ac))) {
4087 while (ath10k_mac_tx_can_push(hw, txq)) {
4088 ret = ath10k_mac_tx_push_txq(hw, txq);
4092 ieee80211_return_txq(hw, txq, false);
4093 ath10k_htt_tx_txq_update(hw, txq);
4097 ieee80211_txq_schedule_end(hw, ac);
4102 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4104 struct ieee80211_hw *hw = ar->hw;
4107 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4110 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4114 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4115 if (ath10k_mac_schedule_txq(hw, ac) == -EBUSY)
4120 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4126 void __ath10k_scan_finish(struct ath10k *ar)
4128 lockdep_assert_held(&ar->data_lock);
4130 switch (ar->scan.state) {
4131 case ATH10K_SCAN_IDLE:
4133 case ATH10K_SCAN_RUNNING:
4134 case ATH10K_SCAN_ABORTING:
4135 if (!ar->scan.is_roc) {
4136 struct cfg80211_scan_info info = {
4137 .aborted = (ar->scan.state ==
4138 ATH10K_SCAN_ABORTING),
4141 ieee80211_scan_completed(ar->hw, &info);
4142 } else if (ar->scan.roc_notify) {
4143 ieee80211_remain_on_channel_expired(ar->hw);
4146 case ATH10K_SCAN_STARTING:
4147 ar->scan.state = ATH10K_SCAN_IDLE;
4148 ar->scan_channel = NULL;
4149 ar->scan.roc_freq = 0;
4150 ath10k_offchan_tx_purge(ar);
4151 cancel_delayed_work(&ar->scan.timeout);
4152 complete(&ar->scan.completed);
4157 void ath10k_scan_finish(struct ath10k *ar)
4159 spin_lock_bh(&ar->data_lock);
4160 __ath10k_scan_finish(ar);
4161 spin_unlock_bh(&ar->data_lock);
4164 static int ath10k_scan_stop(struct ath10k *ar)
4166 struct wmi_stop_scan_arg arg = {
4167 .req_id = 1, /* FIXME */
4168 .req_type = WMI_SCAN_STOP_ONE,
4169 .u.scan_id = ATH10K_SCAN_ID,
4173 lockdep_assert_held(&ar->conf_mutex);
4175 ret = ath10k_wmi_stop_scan(ar, &arg);
4177 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4181 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4183 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4185 } else if (ret > 0) {
4190 /* Scan state should be updated upon scan completion but in case
4191 * firmware fails to deliver the event (for whatever reason) it is
4192 * desired to clean up scan state anyway. Firmware may have just
4193 * dropped the scan completion event delivery due to transport pipe
4194 * being overflown with data and/or it can recover on its own before
4195 * next scan request is submitted.
4197 spin_lock_bh(&ar->data_lock);
4198 if (ar->scan.state != ATH10K_SCAN_IDLE)
4199 __ath10k_scan_finish(ar);
4200 spin_unlock_bh(&ar->data_lock);
4205 static void ath10k_scan_abort(struct ath10k *ar)
4209 lockdep_assert_held(&ar->conf_mutex);
4211 spin_lock_bh(&ar->data_lock);
4213 switch (ar->scan.state) {
4214 case ATH10K_SCAN_IDLE:
4215 /* This can happen if timeout worker kicked in and called
4216 * abortion while scan completion was being processed.
4219 case ATH10K_SCAN_STARTING:
4220 case ATH10K_SCAN_ABORTING:
4221 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4222 ath10k_scan_state_str(ar->scan.state),
4225 case ATH10K_SCAN_RUNNING:
4226 ar->scan.state = ATH10K_SCAN_ABORTING;
4227 spin_unlock_bh(&ar->data_lock);
4229 ret = ath10k_scan_stop(ar);
4231 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4233 spin_lock_bh(&ar->data_lock);
4237 spin_unlock_bh(&ar->data_lock);
4240 void ath10k_scan_timeout_work(struct work_struct *work)
4242 struct ath10k *ar = container_of(work, struct ath10k,
4245 mutex_lock(&ar->conf_mutex);
4246 ath10k_scan_abort(ar);
4247 mutex_unlock(&ar->conf_mutex);
4250 static int ath10k_start_scan(struct ath10k *ar,
4251 const struct wmi_start_scan_arg *arg)
4255 lockdep_assert_held(&ar->conf_mutex);
4257 ret = ath10k_wmi_start_scan(ar, arg);
4261 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4263 ret = ath10k_scan_stop(ar);
4265 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4270 /* If we failed to start the scan, return error code at
4271 * this point. This is probably due to some issue in the
4272 * firmware, but no need to wedge the driver due to that...
4274 spin_lock_bh(&ar->data_lock);
4275 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4276 spin_unlock_bh(&ar->data_lock);
4279 spin_unlock_bh(&ar->data_lock);
4284 /**********************/
4285 /* mac80211 callbacks */
4286 /**********************/
4288 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4289 struct ieee80211_tx_control *control,
4290 struct sk_buff *skb)
4292 struct ath10k *ar = hw->priv;
4293 struct ath10k_htt *htt = &ar->htt;
4294 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4295 struct ieee80211_vif *vif = info->control.vif;
4296 struct ieee80211_sta *sta = control->sta;
4297 struct ieee80211_txq *txq = NULL;
4298 struct ieee80211_hdr *hdr = (void *)skb->data;
4299 enum ath10k_hw_txrx_mode txmode;
4300 enum ath10k_mac_tx_path txpath;
4307 airtime = ath10k_mac_update_airtime(ar, txq, skb);
4308 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb, airtime);
4310 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4311 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4312 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4313 txpath == ATH10K_MAC_TX_HTT_MGMT);
4314 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4317 spin_lock_bh(&ar->htt.tx_lock);
4318 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4320 ret = ath10k_htt_tx_inc_pending(htt);
4322 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4324 spin_unlock_bh(&ar->htt.tx_lock);
4325 ieee80211_free_txskb(ar->hw, skb);
4329 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4331 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4333 ath10k_htt_tx_dec_pending(htt);
4334 spin_unlock_bh(&ar->htt.tx_lock);
4335 ieee80211_free_txskb(ar->hw, skb);
4338 spin_unlock_bh(&ar->htt.tx_lock);
4341 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4343 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4345 spin_lock_bh(&ar->htt.tx_lock);
4346 ath10k_htt_tx_dec_pending(htt);
4348 ath10k_htt_tx_mgmt_dec_pending(htt);
4349 spin_unlock_bh(&ar->htt.tx_lock);
4355 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4356 struct ieee80211_txq *txq)
4358 struct ath10k *ar = hw->priv;
4362 ath10k_htt_tx_txq_update(hw, txq);
4363 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4367 ieee80211_txq_schedule_start(hw, ac);
4368 txq = ieee80211_next_txq(hw, ac);
4372 while (ath10k_mac_tx_can_push(hw, txq)) {
4373 ret = ath10k_mac_tx_push_txq(hw, txq);
4377 ieee80211_return_txq(hw, txq, false);
4378 ath10k_htt_tx_txq_update(hw, txq);
4380 ieee80211_txq_schedule_end(hw, ac);
4383 /* Must not be called with conf_mutex held as workers can use that also. */
4384 void ath10k_drain_tx(struct ath10k *ar)
4386 /* make sure rcu-protected mac80211 tx path itself is drained */
4389 ath10k_offchan_tx_purge(ar);
4390 ath10k_mgmt_over_wmi_tx_purge(ar);
4392 cancel_work_sync(&ar->offchan_tx_work);
4393 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4396 void ath10k_halt(struct ath10k *ar)
4398 struct ath10k_vif *arvif;
4400 lockdep_assert_held(&ar->conf_mutex);
4402 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4403 ar->filter_flags = 0;
4404 ar->monitor = false;
4405 ar->monitor_arvif = NULL;
4407 if (ar->monitor_started)
4408 ath10k_monitor_stop(ar);
4410 ar->monitor_started = false;
4413 ath10k_scan_finish(ar);
4414 ath10k_peer_cleanup_all(ar);
4415 ath10k_stop_radar_confirmation(ar);
4416 ath10k_core_stop(ar);
4417 ath10k_hif_power_down(ar);
4419 spin_lock_bh(&ar->data_lock);
4420 list_for_each_entry(arvif, &ar->arvifs, list)
4421 ath10k_mac_vif_beacon_cleanup(arvif);
4422 spin_unlock_bh(&ar->data_lock);
4425 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4427 struct ath10k *ar = hw->priv;
4429 mutex_lock(&ar->conf_mutex);
4431 *tx_ant = ar->cfg_tx_chainmask;
4432 *rx_ant = ar->cfg_rx_chainmask;
4434 mutex_unlock(&ar->conf_mutex);
4439 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4441 /* It is not clear that allowing gaps in chainmask
4442 * is helpful. Probably it will not do what user
4443 * is hoping for, so warn in that case.
4445 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4448 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4452 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4454 int nsts = ar->vht_cap_info;
4456 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4457 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4459 /* If firmware does not deliver to host number of space-time
4460 * streams supported, assume it support up to 4 BF STS and return
4461 * the value for VHT CAP: nsts-1)
4469 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4471 int sound_dim = ar->vht_cap_info;
4473 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4474 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4476 /* If the sounding dimension is not advertised by the firmware,
4477 * let's use a default value of 1
4485 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4487 struct ieee80211_sta_vht_cap vht_cap = {0};
4488 struct ath10k_hw_params *hw = &ar->hw_params;
4493 vht_cap.vht_supported = 1;
4494 vht_cap.cap = ar->vht_cap_info;
4496 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4497 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4498 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4499 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4500 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4505 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4506 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4507 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4508 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4509 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4514 /* Currently the firmware seems to be buggy, don't enable 80+80
4515 * mode until that's resolved.
4517 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4518 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4519 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4522 for (i = 0; i < 8; i++) {
4523 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4524 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4526 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4529 if (ar->cfg_tx_chainmask <= 1)
4530 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4532 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4533 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4535 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4536 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4537 * user-space a clue if that is the case.
4539 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4540 (hw->vht160_mcs_rx_highest != 0 ||
4541 hw->vht160_mcs_tx_highest != 0)) {
4542 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4543 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4549 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4552 struct ieee80211_sta_ht_cap ht_cap = {0};
4554 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4557 ht_cap.ht_supported = 1;
4558 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4559 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4560 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4561 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4563 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4565 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4566 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4568 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4569 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4571 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4574 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4575 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4580 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4581 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4583 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4586 stbc = ar->ht_cap_info;
4587 stbc &= WMI_HT_CAP_RX_STBC;
4588 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4589 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4590 stbc &= IEEE80211_HT_CAP_RX_STBC;
4595 if (ar->ht_cap_info & WMI_HT_CAP_LDPC || (ar->ht_cap_info &
4596 WMI_HT_CAP_RX_LDPC && (ar->ht_cap_info & WMI_HT_CAP_TX_LDPC)))
4597 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4599 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4600 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4602 /* max AMSDU is implicitly taken from vht_cap_info */
4603 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4604 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4606 for (i = 0; i < ar->num_rf_chains; i++) {
4607 if (ar->cfg_rx_chainmask & BIT(i))
4608 ht_cap.mcs.rx_mask[i] = 0xFF;
4611 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4616 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4618 struct ieee80211_supported_band *band;
4619 struct ieee80211_sta_vht_cap vht_cap;
4620 struct ieee80211_sta_ht_cap ht_cap;
4622 ht_cap = ath10k_get_ht_cap(ar);
4623 vht_cap = ath10k_create_vht_cap(ar);
4625 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4626 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4627 band->ht_cap = ht_cap;
4629 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4630 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4631 band->ht_cap = ht_cap;
4632 band->vht_cap = vht_cap;
4636 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4640 lockdep_assert_held(&ar->conf_mutex);
4642 ath10k_check_chain_mask(ar, tx_ant, "tx");
4643 ath10k_check_chain_mask(ar, rx_ant, "rx");
4645 ar->cfg_tx_chainmask = tx_ant;
4646 ar->cfg_rx_chainmask = rx_ant;
4648 if ((ar->state != ATH10K_STATE_ON) &&
4649 (ar->state != ATH10K_STATE_RESTARTED))
4652 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4655 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4660 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4663 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4668 /* Reload HT/VHT capability */
4669 ath10k_mac_setup_ht_vht_cap(ar);
4674 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4676 struct ath10k *ar = hw->priv;
4679 mutex_lock(&ar->conf_mutex);
4680 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4681 mutex_unlock(&ar->conf_mutex);
4685 static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar,
4686 struct wmi_bb_timing_cfg_arg *bb_timing)
4688 struct device_node *node;
4689 const char *fem_name;
4692 node = ar->dev->of_node;
4696 ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name);
4701 * If external Front End module used in hardware, then default base band timing
4702 * parameter cannot be used since they were fine tuned for reference hardware,
4703 * so choosing different value suitable for that external FEM.
4705 if (!strcmp("microsemi-lx5586", fem_name)) {
4706 bb_timing->bb_tx_timing = 0x00;
4707 bb_timing->bb_xpa_timing = 0x0101;
4712 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
4713 bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing);
4717 static int ath10k_start(struct ieee80211_hw *hw)
4719 struct ath10k *ar = hw->priv;
4722 struct wmi_bb_timing_cfg_arg bb_timing = {0};
4725 * This makes sense only when restarting hw. It is harmless to call
4726 * unconditionally. This is necessary to make sure no HTT/WMI tx
4727 * commands will be submitted while restarting.
4729 ath10k_drain_tx(ar);
4731 mutex_lock(&ar->conf_mutex);
4733 switch (ar->state) {
4734 case ATH10K_STATE_OFF:
4735 ar->state = ATH10K_STATE_ON;
4737 case ATH10K_STATE_RESTARTING:
4738 ar->state = ATH10K_STATE_RESTARTED;
4740 case ATH10K_STATE_ON:
4741 case ATH10K_STATE_RESTARTED:
4742 case ATH10K_STATE_WEDGED:
4746 case ATH10K_STATE_UTF:
4751 ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
4753 ath10k_err(ar, "Could not init hif: %d\n", ret);
4757 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4758 &ar->normal_mode_fw);
4760 ath10k_err(ar, "Could not init core: %d\n", ret);
4761 goto err_power_down;
4764 param = ar->wmi.pdev_param->pmf_qos;
4765 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4767 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4771 param = ar->wmi.pdev_param->dynamic_bw;
4772 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4774 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4778 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
4779 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
4781 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
4786 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4787 ret = ath10k_wmi_adaptive_qcs(ar, true);
4789 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4795 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4796 param = ar->wmi.pdev_param->burst_enable;
4797 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4799 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4804 param = ar->wmi.pdev_param->idle_ps_config;
4805 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4806 if (ret && ret != -EOPNOTSUPP) {
4807 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4811 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4814 * By default FW set ARP frames ac to voice (6). In that case ARP
4815 * exchange is not working properly for UAPSD enabled AP. ARP requests
4816 * which arrives with access category 0 are processed by network stack
4817 * and send back with access category 0, but FW changes access category
4818 * to 6. Set ARP frames access category to best effort (0) solves
4822 param = ar->wmi.pdev_param->arp_ac_override;
4823 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4825 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4830 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4831 ar->running_fw->fw_file.fw_features)) {
4832 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4833 WMI_CCA_DETECT_LEVEL_AUTO,
4834 WMI_CCA_DETECT_MARGIN_AUTO);
4836 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4842 param = ar->wmi.pdev_param->ani_enable;
4843 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4845 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4850 ar->ani_enabled = true;
4852 if (ath10k_peer_stats_enabled(ar)) {
4853 param = ar->wmi.pdev_param->peer_stats_update_period;
4854 ret = ath10k_wmi_pdev_set_param(ar, param,
4855 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4858 "failed to set peer stats period : %d\n",
4864 param = ar->wmi.pdev_param->enable_btcoex;
4865 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4866 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4867 ar->running_fw->fw_file.fw_features)) {
4868 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4871 "failed to set btcoex param: %d\n", ret);
4874 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4877 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) {
4878 ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing);
4880 ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing);
4883 "failed to set bb timings: %d\n",
4890 ar->num_started_vdevs = 0;
4891 ath10k_regd_update(ar);
4893 ath10k_spectral_start(ar);
4894 ath10k_thermal_set_throttling(ar);
4896 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
4898 mutex_unlock(&ar->conf_mutex);
4902 ath10k_core_stop(ar);
4905 ath10k_hif_power_down(ar);
4908 ar->state = ATH10K_STATE_OFF;
4911 mutex_unlock(&ar->conf_mutex);
4915 static void ath10k_stop(struct ieee80211_hw *hw)
4917 struct ath10k *ar = hw->priv;
4919 ath10k_drain_tx(ar);
4921 mutex_lock(&ar->conf_mutex);
4922 if (ar->state != ATH10K_STATE_OFF) {
4924 ar->state = ATH10K_STATE_OFF;
4926 mutex_unlock(&ar->conf_mutex);
4928 cancel_work_sync(&ar->set_coverage_class_work);
4929 cancel_delayed_work_sync(&ar->scan.timeout);
4930 cancel_work_sync(&ar->restart_work);
4933 static int ath10k_config_ps(struct ath10k *ar)
4935 struct ath10k_vif *arvif;
4938 lockdep_assert_held(&ar->conf_mutex);
4940 list_for_each_entry(arvif, &ar->arvifs, list) {
4941 ret = ath10k_mac_vif_setup_ps(arvif);
4943 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4951 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4956 lockdep_assert_held(&ar->conf_mutex);
4958 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4960 param = ar->wmi.pdev_param->txpower_limit2g;
4961 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4963 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4968 param = ar->wmi.pdev_param->txpower_limit5g;
4969 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4971 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4979 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4981 struct ath10k_vif *arvif;
4982 int ret, txpower = -1;
4984 lockdep_assert_held(&ar->conf_mutex);
4986 list_for_each_entry(arvif, &ar->arvifs, list) {
4987 if (arvif->txpower <= 0)
4991 txpower = arvif->txpower;
4993 txpower = min(txpower, arvif->txpower);
4999 ret = ath10k_mac_txpower_setup(ar, txpower);
5001 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
5009 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
5011 struct ath10k *ar = hw->priv;
5012 struct ieee80211_conf *conf = &hw->conf;
5015 mutex_lock(&ar->conf_mutex);
5017 if (changed & IEEE80211_CONF_CHANGE_PS)
5018 ath10k_config_ps(ar);
5020 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
5021 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
5022 ret = ath10k_monitor_recalc(ar);
5024 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5027 mutex_unlock(&ar->conf_mutex);
5031 static u32 get_nss_from_chainmask(u16 chain_mask)
5033 if ((chain_mask & 0xf) == 0xf)
5035 else if ((chain_mask & 0x7) == 0x7)
5037 else if ((chain_mask & 0x3) == 0x3)
5042 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
5045 struct ath10k *ar = arvif->ar;
5049 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
5052 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
5053 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5054 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
5055 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
5057 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
5058 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5059 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
5060 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
5065 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
5066 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
5068 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
5069 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
5070 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
5072 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
5073 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
5075 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
5076 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
5077 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
5079 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5080 ar->wmi.vdev_param->txbf, value);
5085 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5086 * because we will send mgmt frames without CCK. This requirement
5087 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5090 static int ath10k_add_interface(struct ieee80211_hw *hw,
5091 struct ieee80211_vif *vif)
5093 struct ath10k *ar = hw->priv;
5094 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5095 struct ath10k_peer *peer;
5096 enum wmi_sta_powersave_param param;
5103 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5105 mutex_lock(&ar->conf_mutex);
5107 memset(arvif, 0, sizeof(*arvif));
5108 ath10k_mac_txq_init(vif->txq);
5113 INIT_LIST_HEAD(&arvif->list);
5114 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5115 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5116 ath10k_mac_vif_sta_connection_loss_work);
5118 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5119 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5120 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5121 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5122 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5123 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5126 if (ar->num_peers >= ar->max_num_peers) {
5127 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5132 if (ar->free_vdev_map == 0) {
5133 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5137 bit = __ffs64(ar->free_vdev_map);
5139 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5140 bit, ar->free_vdev_map);
5142 arvif->vdev_id = bit;
5143 arvif->vdev_subtype =
5144 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5146 switch (vif->type) {
5147 case NL80211_IFTYPE_P2P_DEVICE:
5148 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5149 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5150 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5152 case NL80211_IFTYPE_UNSPECIFIED:
5153 case NL80211_IFTYPE_STATION:
5154 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5156 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5157 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5159 case NL80211_IFTYPE_ADHOC:
5160 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5162 case NL80211_IFTYPE_MESH_POINT:
5163 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5164 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5165 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5166 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5168 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5171 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5173 case NL80211_IFTYPE_AP:
5174 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5177 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5178 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5180 case NL80211_IFTYPE_MONITOR:
5181 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5188 /* Using vdev_id as queue number will make it very easy to do per-vif
5189 * tx queue locking. This shouldn't wrap due to interface combinations
5190 * but do a modulo for correctness sake and prevent using offchannel tx
5191 * queues for regular vif tx.
5193 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5194 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5195 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5197 /* Some firmware revisions don't wait for beacon tx completion before
5198 * sending another SWBA event. This could lead to hardware using old
5199 * (freed) beacon data in some cases, e.g. tx credit starvation
5200 * combined with missed TBTT. This is very very rare.
5202 * On non-IOMMU-enabled hosts this could be a possible security issue
5203 * because hw could beacon some random data on the air. On
5204 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5205 * device would crash.
5207 * Since there are no beacon tx completions (implicit nor explicit)
5208 * propagated to host the only workaround for this is to allocate a
5209 * DMA-coherent buffer for a lifetime of a vif and use it for all
5210 * beacon tx commands. Worst case for this approach is some beacons may
5211 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5213 if (vif->type == NL80211_IFTYPE_ADHOC ||
5214 vif->type == NL80211_IFTYPE_MESH_POINT ||
5215 vif->type == NL80211_IFTYPE_AP) {
5216 arvif->beacon_buf = dma_alloc_coherent(ar->dev,
5217 IEEE80211_MAX_FRAME_LEN,
5218 &arvif->beacon_paddr,
5220 if (!arvif->beacon_buf) {
5222 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5227 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5228 arvif->nohwcrypt = true;
5230 if (arvif->nohwcrypt &&
5231 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5232 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5236 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5237 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5238 arvif->beacon_buf ? "single-buf" : "per-skb");
5240 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5241 arvif->vdev_subtype, vif->addr);
5243 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5244 arvif->vdev_id, ret);
5248 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT,
5250 vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn;
5251 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5252 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN);
5253 if (ret && ret != -EOPNOTSUPP) {
5254 ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n",
5255 arvif->vdev_id, ret);
5259 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5260 spin_lock_bh(&ar->data_lock);
5261 list_add(&arvif->list, &ar->arvifs);
5262 spin_unlock_bh(&ar->data_lock);
5264 /* It makes no sense to have firmware do keepalives. mac80211 already
5265 * takes care of this with idle connection polling.
5267 ret = ath10k_mac_vif_disable_keepalive(arvif);
5269 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5270 arvif->vdev_id, ret);
5271 goto err_vdev_delete;
5274 arvif->def_wep_key_idx = -1;
5276 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5277 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5278 ATH10K_HW_TXRX_NATIVE_WIFI);
5279 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5280 if (ret && ret != -EOPNOTSUPP) {
5281 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5282 arvif->vdev_id, ret);
5283 goto err_vdev_delete;
5286 /* Configuring number of spatial stream for monitor interface is causing
5287 * target assert in qca9888 and qca6174.
5289 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5290 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5292 vdev_param = ar->wmi.vdev_param->nss;
5293 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5296 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5297 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5299 goto err_vdev_delete;
5303 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5304 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5305 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5306 vif->addr, WMI_PEER_TYPE_DEFAULT);
5308 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5309 arvif->vdev_id, ret);
5310 goto err_vdev_delete;
5313 spin_lock_bh(&ar->data_lock);
5315 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5317 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5318 vif->addr, arvif->vdev_id);
5319 spin_unlock_bh(&ar->data_lock);
5321 goto err_peer_delete;
5324 arvif->peer_id = find_first_bit(peer->peer_ids,
5325 ATH10K_MAX_NUM_PEER_IDS);
5327 spin_unlock_bh(&ar->data_lock);
5329 arvif->peer_id = HTT_INVALID_PEERID;
5332 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5333 ret = ath10k_mac_set_kickout(arvif);
5335 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5336 arvif->vdev_id, ret);
5337 goto err_peer_delete;
5341 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5342 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5343 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5344 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5347 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5348 arvif->vdev_id, ret);
5349 goto err_peer_delete;
5352 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5354 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5355 arvif->vdev_id, ret);
5356 goto err_peer_delete;
5359 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5361 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5362 arvif->vdev_id, ret);
5363 goto err_peer_delete;
5367 ret = ath10k_mac_set_txbf_conf(arvif);
5369 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5370 arvif->vdev_id, ret);
5371 goto err_peer_delete;
5374 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5376 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5377 arvif->vdev_id, ret);
5378 goto err_peer_delete;
5381 arvif->txpower = vif->bss_conf.txpower;
5382 ret = ath10k_mac_txpower_recalc(ar);
5384 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5385 goto err_peer_delete;
5388 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
5389 vdev_param = ar->wmi.vdev_param->rtt_responder_role;
5390 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5391 arvif->ftm_responder);
5393 /* It is harmless to not set FTM role. Do not warn */
5394 if (ret && ret != -EOPNOTSUPP)
5395 ath10k_warn(ar, "failed to set vdev %i FTM Responder: %d\n",
5396 arvif->vdev_id, ret);
5399 if (vif->type == NL80211_IFTYPE_MONITOR) {
5400 ar->monitor_arvif = arvif;
5401 ret = ath10k_monitor_recalc(ar);
5403 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5404 goto err_peer_delete;
5408 spin_lock_bh(&ar->htt.tx_lock);
5410 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5411 spin_unlock_bh(&ar->htt.tx_lock);
5413 mutex_unlock(&ar->conf_mutex);
5417 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5418 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5419 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5422 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5423 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5424 spin_lock_bh(&ar->data_lock);
5425 list_del(&arvif->list);
5426 spin_unlock_bh(&ar->data_lock);
5429 if (arvif->beacon_buf) {
5430 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5431 arvif->beacon_buf, arvif->beacon_paddr);
5432 arvif->beacon_buf = NULL;
5435 mutex_unlock(&ar->conf_mutex);
5440 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5444 for (i = 0; i < BITS_PER_LONG; i++)
5445 ath10k_mac_vif_tx_unlock(arvif, i);
5448 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5449 struct ieee80211_vif *vif)
5451 struct ath10k *ar = hw->priv;
5452 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5453 struct ath10k_peer *peer;
5457 cancel_work_sync(&arvif->ap_csa_work);
5458 cancel_delayed_work_sync(&arvif->connection_loss_work);
5460 mutex_lock(&ar->conf_mutex);
5462 spin_lock_bh(&ar->data_lock);
5463 ath10k_mac_vif_beacon_cleanup(arvif);
5464 spin_unlock_bh(&ar->data_lock);
5466 ret = ath10k_spectral_vif_stop(arvif);
5468 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5469 arvif->vdev_id, ret);
5471 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5472 spin_lock_bh(&ar->data_lock);
5473 list_del(&arvif->list);
5474 spin_unlock_bh(&ar->data_lock);
5476 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5477 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5478 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5481 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5482 arvif->vdev_id, ret);
5484 kfree(arvif->u.ap.noa_data);
5487 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5490 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5492 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5493 arvif->vdev_id, ret);
5495 /* Some firmware revisions don't notify host about self-peer removal
5496 * until after associated vdev is deleted.
5498 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5499 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5500 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5503 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5504 arvif->vdev_id, ret);
5506 spin_lock_bh(&ar->data_lock);
5508 spin_unlock_bh(&ar->data_lock);
5511 spin_lock_bh(&ar->data_lock);
5512 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5513 peer = ar->peer_map[i];
5517 if (peer->vif == vif) {
5518 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5519 vif->addr, arvif->vdev_id);
5523 spin_unlock_bh(&ar->data_lock);
5525 ath10k_peer_cleanup(ar, arvif->vdev_id);
5526 ath10k_mac_txq_unref(ar, vif->txq);
5528 if (vif->type == NL80211_IFTYPE_MONITOR) {
5529 ar->monitor_arvif = NULL;
5530 ret = ath10k_monitor_recalc(ar);
5532 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5535 ret = ath10k_mac_txpower_recalc(ar);
5537 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5539 spin_lock_bh(&ar->htt.tx_lock);
5540 ath10k_mac_vif_tx_unlock_all(arvif);
5541 spin_unlock_bh(&ar->htt.tx_lock);
5543 ath10k_mac_txq_unref(ar, vif->txq);
5545 mutex_unlock(&ar->conf_mutex);
5549 * FIXME: Has to be verified.
5551 #define SUPPORTED_FILTERS \
5556 FIF_BCN_PRBRESP_PROMISC | \
5560 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5561 unsigned int changed_flags,
5562 unsigned int *total_flags,
5565 struct ath10k *ar = hw->priv;
5568 mutex_lock(&ar->conf_mutex);
5570 changed_flags &= SUPPORTED_FILTERS;
5571 *total_flags &= SUPPORTED_FILTERS;
5572 ar->filter_flags = *total_flags;
5574 ret = ath10k_monitor_recalc(ar);
5576 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5578 mutex_unlock(&ar->conf_mutex);
5581 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5582 struct ieee80211_vif *vif,
5583 struct ieee80211_bss_conf *info,
5586 struct ath10k *ar = hw->priv;
5587 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5588 struct cfg80211_chan_def def;
5589 u32 vdev_param, pdev_param, slottime, preamble;
5590 u16 bitrate, hw_value;
5591 u8 rate, basic_rate_idx;
5592 int rateidx, ret = 0, hw_rate_code;
5593 enum nl80211_band band;
5594 const struct ieee80211_supported_band *sband;
5596 mutex_lock(&ar->conf_mutex);
5598 if (changed & BSS_CHANGED_IBSS)
5599 ath10k_control_ibss(arvif, info, vif->addr);
5601 if (changed & BSS_CHANGED_BEACON_INT) {
5602 arvif->beacon_interval = info->beacon_int;
5603 vdev_param = ar->wmi.vdev_param->beacon_interval;
5604 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5605 arvif->beacon_interval);
5606 ath10k_dbg(ar, ATH10K_DBG_MAC,
5607 "mac vdev %d beacon_interval %d\n",
5608 arvif->vdev_id, arvif->beacon_interval);
5611 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5612 arvif->vdev_id, ret);
5615 if (changed & BSS_CHANGED_BEACON) {
5616 ath10k_dbg(ar, ATH10K_DBG_MAC,
5617 "vdev %d set beacon tx mode to staggered\n",
5620 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5621 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5622 WMI_BEACON_STAGGERED_MODE);
5624 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5625 arvif->vdev_id, ret);
5627 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5629 ath10k_warn(ar, "failed to update beacon template: %d\n",
5632 if (ieee80211_vif_is_mesh(vif)) {
5633 /* mesh doesn't use SSID but firmware needs it */
5634 strncpy(arvif->u.ap.ssid, "mesh",
5635 sizeof(arvif->u.ap.ssid));
5636 arvif->u.ap.ssid_len = 4;
5640 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5641 ret = ath10k_mac_setup_prb_tmpl(arvif);
5643 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5644 arvif->vdev_id, ret);
5647 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5648 arvif->dtim_period = info->dtim_period;
5650 ath10k_dbg(ar, ATH10K_DBG_MAC,
5651 "mac vdev %d dtim_period %d\n",
5652 arvif->vdev_id, arvif->dtim_period);
5654 vdev_param = ar->wmi.vdev_param->dtim_period;
5655 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5656 arvif->dtim_period);
5658 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5659 arvif->vdev_id, ret);
5662 if (changed & BSS_CHANGED_SSID &&
5663 vif->type == NL80211_IFTYPE_AP) {
5664 arvif->u.ap.ssid_len = info->ssid_len;
5666 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5667 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5670 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5671 ether_addr_copy(arvif->bssid, info->bssid);
5673 if (changed & BSS_CHANGED_FTM_RESPONDER &&
5674 arvif->ftm_responder != info->ftm_responder &&
5675 test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
5676 arvif->ftm_responder = info->ftm_responder;
5678 vdev_param = ar->wmi.vdev_param->rtt_responder_role;
5679 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5680 arvif->ftm_responder);
5682 ath10k_dbg(ar, ATH10K_DBG_MAC,
5683 "mac vdev %d ftm_responder %d:ret %d\n",
5684 arvif->vdev_id, arvif->ftm_responder, ret);
5687 if (changed & BSS_CHANGED_BEACON_ENABLED)
5688 ath10k_control_beaconing(arvif, info);
5690 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5691 arvif->use_cts_prot = info->use_cts_prot;
5693 ret = ath10k_recalc_rtscts_prot(arvif);
5695 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5696 arvif->vdev_id, ret);
5698 if (ath10k_mac_can_set_cts_prot(arvif)) {
5699 ret = ath10k_mac_set_cts_prot(arvif);
5701 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5702 arvif->vdev_id, ret);
5706 if (changed & BSS_CHANGED_ERP_SLOT) {
5707 if (info->use_short_slot)
5708 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5711 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5713 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5714 arvif->vdev_id, slottime);
5716 vdev_param = ar->wmi.vdev_param->slot_time;
5717 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5720 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5721 arvif->vdev_id, ret);
5724 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5725 if (info->use_short_preamble)
5726 preamble = WMI_VDEV_PREAMBLE_SHORT;
5728 preamble = WMI_VDEV_PREAMBLE_LONG;
5730 ath10k_dbg(ar, ATH10K_DBG_MAC,
5731 "mac vdev %d preamble %dn",
5732 arvif->vdev_id, preamble);
5734 vdev_param = ar->wmi.vdev_param->preamble;
5735 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5738 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5739 arvif->vdev_id, ret);
5742 if (changed & BSS_CHANGED_ASSOC) {
5744 /* Workaround: Make sure monitor vdev is not running
5745 * when associating to prevent some firmware revisions
5746 * (e.g. 10.1 and 10.2) from crashing.
5748 if (ar->monitor_started)
5749 ath10k_monitor_stop(ar);
5750 ath10k_bss_assoc(hw, vif, info);
5751 ath10k_monitor_recalc(ar);
5753 ath10k_bss_disassoc(hw, vif);
5757 if (changed & BSS_CHANGED_TXPOWER) {
5758 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5759 arvif->vdev_id, info->txpower);
5761 arvif->txpower = info->txpower;
5762 ret = ath10k_mac_txpower_recalc(ar);
5764 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5767 if (changed & BSS_CHANGED_PS) {
5768 arvif->ps = vif->bss_conf.ps;
5770 ret = ath10k_config_ps(ar);
5772 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5773 arvif->vdev_id, ret);
5776 if (changed & BSS_CHANGED_MCAST_RATE &&
5777 !ath10k_mac_vif_chan(arvif->vif, &def)) {
5778 band = def.chan->band;
5779 rateidx = vif->bss_conf.mcast_rate[band] - 1;
5781 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5782 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5784 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
5785 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
5786 if (ath10k_mac_bitrate_is_cck(bitrate))
5787 preamble = WMI_RATE_PREAMBLE_CCK;
5789 preamble = WMI_RATE_PREAMBLE_OFDM;
5791 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
5793 ath10k_dbg(ar, ATH10K_DBG_MAC,
5794 "mac vdev %d mcast_rate %x\n",
5795 arvif->vdev_id, rate);
5797 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5798 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5802 "failed to set mcast rate on vdev %i: %d\n",
5803 arvif->vdev_id, ret);
5805 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5806 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5810 "failed to set bcast rate on vdev %i: %d\n",
5811 arvif->vdev_id, ret);
5814 if (changed & BSS_CHANGED_BASIC_RATES) {
5815 if (ath10k_mac_vif_chan(vif, &def)) {
5816 mutex_unlock(&ar->conf_mutex);
5820 sband = ar->hw->wiphy->bands[def.chan->band];
5821 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
5822 bitrate = sband->bitrates[basic_rate_idx].bitrate;
5824 hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
5825 if (hw_rate_code < 0) {
5826 ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
5827 mutex_unlock(&ar->conf_mutex);
5831 vdev_param = ar->wmi.vdev_param->mgmt_rate;
5832 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5835 ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
5838 mutex_unlock(&ar->conf_mutex);
5841 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5843 struct ath10k *ar = hw->priv;
5845 /* This function should never be called if setting the coverage class
5846 * is not supported on this hardware.
5848 if (!ar->hw_params.hw_ops->set_coverage_class) {
5852 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5855 struct ath10k_mac_tdls_iter_data {
5856 u32 num_tdls_stations;
5857 struct ieee80211_vif *curr_vif;
5860 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5861 struct ieee80211_sta *sta)
5863 struct ath10k_mac_tdls_iter_data *iter_data = data;
5864 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5865 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5867 if (sta->tdls && sta_vif == iter_data->curr_vif)
5868 iter_data->num_tdls_stations++;
5871 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5872 struct ieee80211_vif *vif)
5874 struct ath10k_mac_tdls_iter_data data = {};
5876 data.curr_vif = vif;
5878 ieee80211_iterate_stations_atomic(hw,
5879 ath10k_mac_tdls_vif_stations_count_iter,
5881 return data.num_tdls_stations;
5884 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5885 struct ieee80211_vif *vif,
5886 struct ieee80211_scan_request *hw_req)
5888 struct ath10k *ar = hw->priv;
5889 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5890 struct cfg80211_scan_request *req = &hw_req->req;
5891 struct wmi_start_scan_arg arg;
5896 mutex_lock(&ar->conf_mutex);
5898 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
5903 spin_lock_bh(&ar->data_lock);
5904 switch (ar->scan.state) {
5905 case ATH10K_SCAN_IDLE:
5906 reinit_completion(&ar->scan.started);
5907 reinit_completion(&ar->scan.completed);
5908 ar->scan.state = ATH10K_SCAN_STARTING;
5909 ar->scan.is_roc = false;
5910 ar->scan.vdev_id = arvif->vdev_id;
5913 case ATH10K_SCAN_STARTING:
5914 case ATH10K_SCAN_RUNNING:
5915 case ATH10K_SCAN_ABORTING:
5919 spin_unlock_bh(&ar->data_lock);
5924 memset(&arg, 0, sizeof(arg));
5925 ath10k_wmi_start_scan_init(ar, &arg);
5926 arg.vdev_id = arvif->vdev_id;
5927 arg.scan_id = ATH10K_SCAN_ID;
5930 arg.ie_len = req->ie_len;
5931 memcpy(arg.ie, req->ie, arg.ie_len);
5935 arg.n_ssids = req->n_ssids;
5936 for (i = 0; i < arg.n_ssids; i++) {
5937 arg.ssids[i].len = req->ssids[i].ssid_len;
5938 arg.ssids[i].ssid = req->ssids[i].ssid;
5941 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5944 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5945 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
5946 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
5947 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
5950 if (req->n_channels) {
5951 arg.n_channels = req->n_channels;
5952 for (i = 0; i < arg.n_channels; i++)
5953 arg.channels[i] = req->channels[i]->center_freq;
5956 /* if duration is set, default dwell times will be overwritten */
5957 if (req->duration) {
5958 arg.dwell_time_active = req->duration;
5959 arg.dwell_time_passive = req->duration;
5960 arg.burst_duration_ms = req->duration;
5962 scan_timeout = min_t(u32, arg.max_rest_time *
5963 (arg.n_channels - 1) + (req->duration +
5964 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
5965 arg.n_channels, arg.max_scan_time + 200);
5968 /* Add a 200ms margin to account for event/command processing */
5969 scan_timeout = arg.max_scan_time + 200;
5972 ret = ath10k_start_scan(ar, &arg);
5974 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5975 spin_lock_bh(&ar->data_lock);
5976 ar->scan.state = ATH10K_SCAN_IDLE;
5977 spin_unlock_bh(&ar->data_lock);
5980 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5981 msecs_to_jiffies(scan_timeout));
5984 mutex_unlock(&ar->conf_mutex);
5988 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5989 struct ieee80211_vif *vif)
5991 struct ath10k *ar = hw->priv;
5993 mutex_lock(&ar->conf_mutex);
5994 ath10k_scan_abort(ar);
5995 mutex_unlock(&ar->conf_mutex);
5997 cancel_delayed_work_sync(&ar->scan.timeout);
6000 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
6001 struct ath10k_vif *arvif,
6002 enum set_key_cmd cmd,
6003 struct ieee80211_key_conf *key)
6005 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
6008 /* 10.1 firmware branch requires default key index to be set to group
6009 * key index after installing it. Otherwise FW/HW Txes corrupted
6010 * frames with multi-vif APs. This is not required for main firmware
6011 * branch (e.g. 636).
6013 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6015 * FIXME: It remains unknown if this is required for multi-vif STA
6016 * interfaces on 10.1.
6019 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
6020 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
6023 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
6026 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
6029 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6035 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6038 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
6039 arvif->vdev_id, ret);
6042 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6043 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
6044 struct ieee80211_key_conf *key)
6046 struct ath10k *ar = hw->priv;
6047 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6048 struct ath10k_peer *peer;
6049 const u8 *peer_addr;
6050 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
6051 key->cipher == WLAN_CIPHER_SUITE_WEP104;
6057 /* this one needs to be done in software */
6058 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
6059 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
6060 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
6061 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
6064 if (arvif->nohwcrypt)
6067 if (key->keyidx > WMI_MAX_KEY_INDEX)
6070 mutex_lock(&ar->conf_mutex);
6073 peer_addr = sta->addr;
6074 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6075 peer_addr = vif->bss_conf.bssid;
6077 peer_addr = vif->addr;
6079 key->hw_key_idx = key->keyidx;
6083 arvif->wep_keys[key->keyidx] = key;
6085 arvif->wep_keys[key->keyidx] = NULL;
6088 /* the peer should not disappear in mid-way (unless FW goes awry) since
6089 * we already hold conf_mutex. we just make sure its there now.
6091 spin_lock_bh(&ar->data_lock);
6092 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6093 spin_unlock_bh(&ar->data_lock);
6096 if (cmd == SET_KEY) {
6097 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
6102 /* if the peer doesn't exist there is no key to disable anymore */
6107 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6108 flags |= WMI_KEY_PAIRWISE;
6110 flags |= WMI_KEY_GROUP;
6113 if (cmd == DISABLE_KEY)
6114 ath10k_clear_vdev_key(arvif, key);
6116 /* When WEP keys are uploaded it's possible that there are
6117 * stations associated already (e.g. when merging) without any
6118 * keys. Static WEP needs an explicit per-peer key upload.
6120 if (vif->type == NL80211_IFTYPE_ADHOC &&
6122 ath10k_mac_vif_update_wep_key(arvif, key);
6124 /* 802.1x never sets the def_wep_key_idx so each set_key()
6125 * call changes default tx key.
6127 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6128 * after first set_key().
6130 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
6131 flags |= WMI_KEY_TX_USAGE;
6134 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
6137 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
6138 arvif->vdev_id, peer_addr, ret);
6142 /* mac80211 sets static WEP keys as groupwise while firmware requires
6143 * them to be installed twice as both pairwise and groupwise.
6145 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6147 flags2 &= ~WMI_KEY_GROUP;
6148 flags2 |= WMI_KEY_PAIRWISE;
6150 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6153 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6154 arvif->vdev_id, peer_addr, ret);
6155 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6159 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6160 arvif->vdev_id, peer_addr, ret2);
6166 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6168 spin_lock_bh(&ar->data_lock);
6169 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6170 if (peer && cmd == SET_KEY)
6171 peer->keys[key->keyidx] = key;
6172 else if (peer && cmd == DISABLE_KEY)
6173 peer->keys[key->keyidx] = NULL;
6174 else if (peer == NULL)
6175 /* impossible unless FW goes crazy */
6176 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6177 spin_unlock_bh(&ar->data_lock);
6179 if (sta && sta->tdls)
6180 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6181 WMI_PEER_AUTHORIZE, 1);
6184 mutex_unlock(&ar->conf_mutex);
6188 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6189 struct ieee80211_vif *vif,
6192 struct ath10k *ar = hw->priv;
6193 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6196 mutex_lock(&arvif->ar->conf_mutex);
6198 if (arvif->ar->state != ATH10K_STATE_ON)
6201 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6202 arvif->vdev_id, keyidx);
6204 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6206 arvif->ar->wmi.vdev_param->def_keyid,
6210 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6216 arvif->def_wep_key_idx = keyidx;
6219 mutex_unlock(&arvif->ar->conf_mutex);
6222 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6225 struct ath10k_vif *arvif;
6226 struct ath10k_sta *arsta;
6227 struct ieee80211_sta *sta;
6228 struct cfg80211_chan_def def;
6229 enum nl80211_band band;
6230 const u8 *ht_mcs_mask;
6231 const u16 *vht_mcs_mask;
6232 u32 changed, bw, nss, smps;
6235 arsta = container_of(wk, struct ath10k_sta, update_wk);
6236 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6237 arvif = arsta->arvif;
6240 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6243 band = def.chan->band;
6244 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6245 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6247 spin_lock_bh(&ar->data_lock);
6249 changed = arsta->changed;
6256 spin_unlock_bh(&ar->data_lock);
6258 mutex_lock(&ar->conf_mutex);
6260 nss = max_t(u32, 1, nss);
6261 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6262 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6264 if (changed & IEEE80211_RC_BW_CHANGED) {
6265 enum wmi_phy_mode mode;
6267 mode = chan_to_phymode(&def);
6268 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
6269 sta->addr, bw, mode);
6271 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6272 WMI_PEER_PHYMODE, mode);
6274 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6275 sta->addr, mode, err);
6279 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6280 WMI_PEER_CHAN_WIDTH, bw);
6282 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6283 sta->addr, bw, err);
6286 if (changed & IEEE80211_RC_NSS_CHANGED) {
6287 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
6290 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6293 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6294 sta->addr, nss, err);
6297 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6298 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
6301 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6302 WMI_PEER_SMPS_STATE, smps);
6304 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6305 sta->addr, smps, err);
6308 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6309 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
6312 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6314 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6319 mutex_unlock(&ar->conf_mutex);
6322 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6323 struct ieee80211_sta *sta)
6325 struct ath10k *ar = arvif->ar;
6327 lockdep_assert_held(&ar->conf_mutex);
6329 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6332 if (ar->num_stations >= ar->max_num_stations)
6340 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6341 struct ieee80211_sta *sta)
6343 struct ath10k *ar = arvif->ar;
6345 lockdep_assert_held(&ar->conf_mutex);
6347 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6353 static int ath10k_sta_state(struct ieee80211_hw *hw,
6354 struct ieee80211_vif *vif,
6355 struct ieee80211_sta *sta,
6356 enum ieee80211_sta_state old_state,
6357 enum ieee80211_sta_state new_state)
6359 struct ath10k *ar = hw->priv;
6360 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6361 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6362 struct ath10k_peer *peer;
6366 if (old_state == IEEE80211_STA_NOTEXIST &&
6367 new_state == IEEE80211_STA_NONE) {
6368 memset(arsta, 0, sizeof(*arsta));
6369 arsta->arvif = arvif;
6370 arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
6371 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6373 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6374 ath10k_mac_txq_init(sta->txq[i]);
6377 /* cancel must be done outside the mutex to avoid deadlock */
6378 if ((old_state == IEEE80211_STA_NONE &&
6379 new_state == IEEE80211_STA_NOTEXIST))
6380 cancel_work_sync(&arsta->update_wk);
6382 mutex_lock(&ar->conf_mutex);
6384 if (old_state == IEEE80211_STA_NOTEXIST &&
6385 new_state == IEEE80211_STA_NONE) {
6387 * New station addition.
6389 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6390 u32 num_tdls_stations;
6392 ath10k_dbg(ar, ATH10K_DBG_MAC,
6393 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6394 arvif->vdev_id, sta->addr,
6395 ar->num_stations + 1, ar->max_num_stations,
6396 ar->num_peers + 1, ar->max_num_peers);
6398 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6401 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6402 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6404 ar->max_num_tdls_vdevs);
6408 peer_type = WMI_PEER_TYPE_TDLS;
6411 ret = ath10k_mac_inc_num_stations(arvif, sta);
6413 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6414 ar->max_num_stations);
6418 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6419 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats),
6421 if (!arsta->tx_stats) {
6427 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6428 sta->addr, peer_type);
6430 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6431 sta->addr, arvif->vdev_id, ret);
6432 ath10k_mac_dec_num_stations(arvif, sta);
6433 kfree(arsta->tx_stats);
6437 spin_lock_bh(&ar->data_lock);
6439 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6441 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6442 vif->addr, arvif->vdev_id);
6443 spin_unlock_bh(&ar->data_lock);
6444 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6445 ath10k_mac_dec_num_stations(arvif, sta);
6446 kfree(arsta->tx_stats);
6451 arsta->peer_id = find_first_bit(peer->peer_ids,
6452 ATH10K_MAX_NUM_PEER_IDS);
6454 spin_unlock_bh(&ar->data_lock);
6459 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6460 WMI_TDLS_ENABLE_ACTIVE);
6462 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6463 arvif->vdev_id, ret);
6464 ath10k_peer_delete(ar, arvif->vdev_id,
6466 ath10k_mac_dec_num_stations(arvif, sta);
6467 kfree(arsta->tx_stats);
6471 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6472 WMI_TDLS_PEER_STATE_PEERING);
6475 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6476 sta->addr, arvif->vdev_id, ret);
6477 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6478 ath10k_mac_dec_num_stations(arvif, sta);
6479 kfree(arsta->tx_stats);
6481 if (num_tdls_stations != 0)
6483 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6486 } else if ((old_state == IEEE80211_STA_NONE &&
6487 new_state == IEEE80211_STA_NOTEXIST)) {
6489 * Existing station deletion.
6491 ath10k_dbg(ar, ATH10K_DBG_MAC,
6492 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6493 arvif->vdev_id, sta->addr, sta);
6496 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6498 WMI_TDLS_PEER_STATE_TEARDOWN);
6500 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6502 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6505 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6507 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6508 sta->addr, arvif->vdev_id, ret);
6510 ath10k_mac_dec_num_stations(arvif, sta);
6512 spin_lock_bh(&ar->data_lock);
6513 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6514 peer = ar->peer_map[i];
6518 if (peer->sta == sta) {
6519 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6520 sta->addr, peer, i, arvif->vdev_id);
6523 /* Clean up the peer object as well since we
6524 * must have failed to do this above.
6526 list_del(&peer->list);
6527 ar->peer_map[i] = NULL;
6532 spin_unlock_bh(&ar->data_lock);
6534 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6535 kfree(arsta->tx_stats);
6536 arsta->tx_stats = NULL;
6539 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6540 ath10k_mac_txq_unref(ar, sta->txq[i]);
6545 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6548 /* This was the last tdls peer in current vif */
6549 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6552 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6553 arvif->vdev_id, ret);
6555 } else if (old_state == IEEE80211_STA_AUTH &&
6556 new_state == IEEE80211_STA_ASSOC &&
6557 (vif->type == NL80211_IFTYPE_AP ||
6558 vif->type == NL80211_IFTYPE_MESH_POINT ||
6559 vif->type == NL80211_IFTYPE_ADHOC)) {
6563 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6566 ret = ath10k_station_assoc(ar, vif, sta, false);
6568 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6569 sta->addr, arvif->vdev_id, ret);
6570 } else if (old_state == IEEE80211_STA_ASSOC &&
6571 new_state == IEEE80211_STA_AUTHORIZED &&
6574 * Tdls station authorized.
6576 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6579 ret = ath10k_station_assoc(ar, vif, sta, false);
6581 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6582 sta->addr, arvif->vdev_id, ret);
6586 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6587 WMI_TDLS_PEER_STATE_CONNECTED);
6589 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6590 sta->addr, arvif->vdev_id, ret);
6591 } else if (old_state == IEEE80211_STA_ASSOC &&
6592 new_state == IEEE80211_STA_AUTH &&
6593 (vif->type == NL80211_IFTYPE_AP ||
6594 vif->type == NL80211_IFTYPE_MESH_POINT ||
6595 vif->type == NL80211_IFTYPE_ADHOC)) {
6599 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6602 ret = ath10k_station_disassoc(ar, vif, sta);
6604 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6605 sta->addr, arvif->vdev_id, ret);
6608 mutex_unlock(&ar->conf_mutex);
6612 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6613 u16 ac, bool enable)
6615 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6616 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6617 u32 prio = 0, acc = 0;
6621 lockdep_assert_held(&ar->conf_mutex);
6623 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6627 case IEEE80211_AC_VO:
6628 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6629 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6633 case IEEE80211_AC_VI:
6634 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6635 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6639 case IEEE80211_AC_BE:
6640 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6641 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6645 case IEEE80211_AC_BK:
6646 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6647 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6654 arvif->u.sta.uapsd |= value;
6656 arvif->u.sta.uapsd &= ~value;
6658 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6659 WMI_STA_PS_PARAM_UAPSD,
6660 arvif->u.sta.uapsd);
6662 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6666 if (arvif->u.sta.uapsd)
6667 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6669 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6671 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6672 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6675 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6677 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6679 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6680 arvif->vdev_id, ret);
6684 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6686 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6687 arvif->vdev_id, ret);
6691 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6692 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6693 /* Only userspace can make an educated decision when to send
6694 * trigger frame. The following effectively disables u-UAPSD
6695 * autotrigger in firmware (which is enabled by default
6696 * provided the autotrigger service is available).
6700 arg.user_priority = prio;
6701 arg.service_interval = 0;
6702 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6703 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6705 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6706 arvif->bssid, &arg, 1);
6708 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6718 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6719 struct ieee80211_vif *vif, u16 ac,
6720 const struct ieee80211_tx_queue_params *params)
6722 struct ath10k *ar = hw->priv;
6723 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6724 struct wmi_wmm_params_arg *p = NULL;
6727 mutex_lock(&ar->conf_mutex);
6730 case IEEE80211_AC_VO:
6731 p = &arvif->wmm_params.ac_vo;
6733 case IEEE80211_AC_VI:
6734 p = &arvif->wmm_params.ac_vi;
6736 case IEEE80211_AC_BE:
6737 p = &arvif->wmm_params.ac_be;
6739 case IEEE80211_AC_BK:
6740 p = &arvif->wmm_params.ac_bk;
6749 p->cwmin = params->cw_min;
6750 p->cwmax = params->cw_max;
6751 p->aifs = params->aifs;
6754 * The channel time duration programmed in the HW is in absolute
6755 * microseconds, while mac80211 gives the txop in units of
6758 p->txop = params->txop * 32;
6760 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6761 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6762 &arvif->wmm_params);
6764 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6765 arvif->vdev_id, ret);
6769 /* This won't work well with multi-interface cases but it's
6770 * better than nothing.
6772 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6774 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6779 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6781 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6784 mutex_unlock(&ar->conf_mutex);
6788 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6790 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6791 struct ieee80211_vif *vif,
6792 struct ieee80211_channel *chan,
6794 enum ieee80211_roc_type type)
6796 struct ath10k *ar = hw->priv;
6797 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6798 struct wmi_start_scan_arg arg;
6802 mutex_lock(&ar->conf_mutex);
6804 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6809 spin_lock_bh(&ar->data_lock);
6810 switch (ar->scan.state) {
6811 case ATH10K_SCAN_IDLE:
6812 reinit_completion(&ar->scan.started);
6813 reinit_completion(&ar->scan.completed);
6814 reinit_completion(&ar->scan.on_channel);
6815 ar->scan.state = ATH10K_SCAN_STARTING;
6816 ar->scan.is_roc = true;
6817 ar->scan.vdev_id = arvif->vdev_id;
6818 ar->scan.roc_freq = chan->center_freq;
6819 ar->scan.roc_notify = true;
6822 case ATH10K_SCAN_STARTING:
6823 case ATH10K_SCAN_RUNNING:
6824 case ATH10K_SCAN_ABORTING:
6828 spin_unlock_bh(&ar->data_lock);
6833 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6835 memset(&arg, 0, sizeof(arg));
6836 ath10k_wmi_start_scan_init(ar, &arg);
6837 arg.vdev_id = arvif->vdev_id;
6838 arg.scan_id = ATH10K_SCAN_ID;
6840 arg.channels[0] = chan->center_freq;
6841 arg.dwell_time_active = scan_time_msec;
6842 arg.dwell_time_passive = scan_time_msec;
6843 arg.max_scan_time = scan_time_msec;
6844 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6845 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6846 arg.burst_duration_ms = duration;
6848 ret = ath10k_start_scan(ar, &arg);
6850 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6851 spin_lock_bh(&ar->data_lock);
6852 ar->scan.state = ATH10K_SCAN_IDLE;
6853 spin_unlock_bh(&ar->data_lock);
6857 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6859 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6861 ret = ath10k_scan_stop(ar);
6863 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6869 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6870 msecs_to_jiffies(duration));
6874 mutex_unlock(&ar->conf_mutex);
6878 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6880 struct ath10k *ar = hw->priv;
6882 mutex_lock(&ar->conf_mutex);
6884 spin_lock_bh(&ar->data_lock);
6885 ar->scan.roc_notify = false;
6886 spin_unlock_bh(&ar->data_lock);
6888 ath10k_scan_abort(ar);
6890 mutex_unlock(&ar->conf_mutex);
6892 cancel_delayed_work_sync(&ar->scan.timeout);
6898 * Both RTS and Fragmentation threshold are interface-specific
6899 * in ath10k, but device-specific in mac80211.
6902 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6904 struct ath10k *ar = hw->priv;
6905 struct ath10k_vif *arvif;
6908 mutex_lock(&ar->conf_mutex);
6909 list_for_each_entry(arvif, &ar->arvifs, list) {
6910 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6911 arvif->vdev_id, value);
6913 ret = ath10k_mac_set_rts(arvif, value);
6915 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6916 arvif->vdev_id, ret);
6920 mutex_unlock(&ar->conf_mutex);
6925 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6927 /* Even though there's a WMI enum for fragmentation threshold no known
6928 * firmware actually implements it. Moreover it is not possible to rely
6929 * frame fragmentation to mac80211 because firmware clears the "more
6930 * fragments" bit in frame control making it impossible for remote
6931 * devices to reassemble frames.
6933 * Hence implement a dummy callback just to say fragmentation isn't
6934 * supported. This effectively prevents mac80211 from doing frame
6935 * fragmentation in software.
6940 void ath10k_mac_wait_tx_complete(struct ath10k *ar)
6945 /* mac80211 doesn't care if we really xmit queued frames or not
6946 * we'll collect those frames either way if we stop/delete vdevs
6949 if (ar->state == ATH10K_STATE_WEDGED)
6952 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6955 spin_lock_bh(&ar->htt.tx_lock);
6956 empty = (ar->htt.num_pending_tx == 0);
6957 spin_unlock_bh(&ar->htt.tx_lock);
6959 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6960 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6964 }), ATH10K_FLUSH_TIMEOUT_HZ);
6966 if (time_left == 0 || skip)
6967 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6968 skip, ar->state, time_left);
6971 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6972 u32 queues, bool drop)
6974 struct ath10k *ar = hw->priv;
6975 struct ath10k_vif *arvif;
6979 if (vif && vif->type == NL80211_IFTYPE_STATION) {
6980 bitmap = ~(1 << WMI_MGMT_TID);
6981 list_for_each_entry(arvif, &ar->arvifs, list) {
6982 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6983 ath10k_wmi_peer_flush(ar, arvif->vdev_id,
6984 arvif->bssid, bitmap);
6990 mutex_lock(&ar->conf_mutex);
6991 ath10k_mac_wait_tx_complete(ar);
6992 mutex_unlock(&ar->conf_mutex);
6995 /* TODO: Implement this function properly
6996 * For now it is needed to reply to Probe Requests in IBSS mode.
6997 * Propably we need this information from FW.
6999 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
7004 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
7005 enum ieee80211_reconfig_type reconfig_type)
7007 struct ath10k *ar = hw->priv;
7009 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
7012 mutex_lock(&ar->conf_mutex);
7014 /* If device failed to restart it will be in a different state, e.g.
7015 * ATH10K_STATE_WEDGED
7017 if (ar->state == ATH10K_STATE_RESTARTED) {
7018 ath10k_info(ar, "device successfully recovered\n");
7019 ar->state = ATH10K_STATE_ON;
7020 ieee80211_wake_queues(ar->hw);
7023 mutex_unlock(&ar->conf_mutex);
7027 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
7028 struct ieee80211_channel *channel)
7031 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
7033 lockdep_assert_held(&ar->conf_mutex);
7035 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
7036 (ar->rx_channel != channel))
7039 if (ar->scan.state != ATH10K_SCAN_IDLE) {
7040 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
7044 reinit_completion(&ar->bss_survey_done);
7046 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
7048 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
7052 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
7054 ath10k_warn(ar, "bss channel survey timed out\n");
7059 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
7060 struct survey_info *survey)
7062 struct ath10k *ar = hw->priv;
7063 struct ieee80211_supported_band *sband;
7064 struct survey_info *ar_survey = &ar->survey[idx];
7067 mutex_lock(&ar->conf_mutex);
7069 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
7070 if (sband && idx >= sband->n_channels) {
7071 idx -= sband->n_channels;
7076 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
7078 if (!sband || idx >= sband->n_channels) {
7083 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
7085 spin_lock_bh(&ar->data_lock);
7086 memcpy(survey, ar_survey, sizeof(*survey));
7087 spin_unlock_bh(&ar->data_lock);
7089 survey->channel = &sband->channels[idx];
7091 if (ar->rx_channel == survey->channel)
7092 survey->filled |= SURVEY_INFO_IN_USE;
7095 mutex_unlock(&ar->conf_mutex);
7100 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
7101 enum nl80211_band band,
7102 const struct cfg80211_bitrate_mask *mask)
7107 num_rates += hweight32(mask->control[band].legacy);
7109 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
7110 num_rates += hweight8(mask->control[band].ht_mcs[i]);
7112 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
7113 num_rates += hweight16(mask->control[band].vht_mcs[i]);
7115 return num_rates == 1;
7119 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
7120 enum nl80211_band band,
7121 const struct cfg80211_bitrate_mask *mask,
7124 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
7125 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7127 u8 vht_nss_mask = 0;
7130 if (mask->control[band].legacy)
7133 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7134 if (mask->control[band].ht_mcs[i] == 0)
7136 else if (mask->control[band].ht_mcs[i] ==
7137 sband->ht_cap.mcs.rx_mask[i])
7138 ht_nss_mask |= BIT(i);
7143 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7144 if (mask->control[band].vht_mcs[i] == 0)
7146 else if (mask->control[band].vht_mcs[i] ==
7147 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
7148 vht_nss_mask |= BIT(i);
7153 if (ht_nss_mask != vht_nss_mask)
7156 if (ht_nss_mask == 0)
7159 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
7162 *nss = fls(ht_nss_mask);
7168 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
7169 enum nl80211_band band,
7170 const struct cfg80211_bitrate_mask *mask,
7179 if (hweight32(mask->control[band].legacy) == 1) {
7180 rate_idx = ffs(mask->control[band].legacy) - 1;
7182 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
7183 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
7185 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
7186 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
7188 if (ath10k_mac_bitrate_is_cck(bitrate))
7189 preamble = WMI_RATE_PREAMBLE_CCK;
7191 preamble = WMI_RATE_PREAMBLE_OFDM;
7194 *rate = preamble << 6 |
7201 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7202 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
7204 *rate = WMI_RATE_PREAMBLE_HT << 6 |
7206 (ffs(mask->control[band].ht_mcs[i]) - 1);
7212 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7213 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
7215 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
7217 (ffs(mask->control[band].vht_mcs[i]) - 1);
7226 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
7227 u8 rate, u8 nss, u8 sgi, u8 ldpc)
7229 struct ath10k *ar = arvif->ar;
7233 lockdep_assert_held(&ar->conf_mutex);
7235 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7236 arvif->vdev_id, rate, nss, sgi);
7238 vdev_param = ar->wmi.vdev_param->fixed_rate;
7239 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
7241 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
7246 vdev_param = ar->wmi.vdev_param->nss;
7247 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
7249 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
7253 vdev_param = ar->wmi.vdev_param->sgi;
7254 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
7256 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
7260 vdev_param = ar->wmi.vdev_param->ldpc;
7261 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
7263 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
7271 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
7272 enum nl80211_band band,
7273 const struct cfg80211_bitrate_mask *mask)
7278 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7279 * to express all VHT MCS rate masks. Effectively only the following
7280 * ranges can be used: none, 0-7, 0-8 and 0-9.
7282 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7283 vht_mcs = mask->control[band].vht_mcs[i];
7292 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7300 static void ath10k_mac_set_bitrate_mask_iter(void *data,
7301 struct ieee80211_sta *sta)
7303 struct ath10k_vif *arvif = data;
7304 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7305 struct ath10k *ar = arvif->ar;
7307 if (arsta->arvif != arvif)
7310 spin_lock_bh(&ar->data_lock);
7311 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7312 spin_unlock_bh(&ar->data_lock);
7314 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7317 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7318 struct ieee80211_vif *vif,
7319 const struct cfg80211_bitrate_mask *mask)
7321 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7322 struct cfg80211_chan_def def;
7323 struct ath10k *ar = arvif->ar;
7324 enum nl80211_band band;
7325 const u8 *ht_mcs_mask;
7326 const u16 *vht_mcs_mask;
7334 if (ath10k_mac_vif_chan(vif, &def))
7337 band = def.chan->band;
7338 ht_mcs_mask = mask->control[band].ht_mcs;
7339 vht_mcs_mask = mask->control[band].vht_mcs;
7340 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7342 sgi = mask->control[band].gi;
7343 if (sgi == NL80211_TXRATE_FORCE_LGI)
7346 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7347 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7350 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7351 arvif->vdev_id, ret);
7354 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7356 rate = WMI_FIXED_RATE_NONE;
7359 rate = WMI_FIXED_RATE_NONE;
7360 nss = min(ar->num_rf_chains,
7361 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7362 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7364 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7367 mutex_lock(&ar->conf_mutex);
7369 arvif->bitrate_mask = *mask;
7370 ieee80211_iterate_stations_atomic(ar->hw,
7371 ath10k_mac_set_bitrate_mask_iter,
7374 mutex_unlock(&ar->conf_mutex);
7377 mutex_lock(&ar->conf_mutex);
7379 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7381 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7382 arvif->vdev_id, ret);
7387 mutex_unlock(&ar->conf_mutex);
7392 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7393 struct ieee80211_vif *vif,
7394 struct ieee80211_sta *sta,
7397 struct ath10k *ar = hw->priv;
7398 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7399 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7400 struct ath10k_peer *peer;
7403 spin_lock_bh(&ar->data_lock);
7405 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7407 spin_unlock_bh(&ar->data_lock);
7408 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7409 sta->addr, arvif->vdev_id);
7413 ath10k_dbg(ar, ATH10K_DBG_MAC,
7414 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7415 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7418 if (changed & IEEE80211_RC_BW_CHANGED) {
7419 bw = WMI_PEER_CHWIDTH_20MHZ;
7421 switch (sta->bandwidth) {
7422 case IEEE80211_STA_RX_BW_20:
7423 bw = WMI_PEER_CHWIDTH_20MHZ;
7425 case IEEE80211_STA_RX_BW_40:
7426 bw = WMI_PEER_CHWIDTH_40MHZ;
7428 case IEEE80211_STA_RX_BW_80:
7429 bw = WMI_PEER_CHWIDTH_80MHZ;
7431 case IEEE80211_STA_RX_BW_160:
7432 bw = WMI_PEER_CHWIDTH_160MHZ;
7435 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7436 sta->bandwidth, sta->addr);
7437 bw = WMI_PEER_CHWIDTH_20MHZ;
7444 if (changed & IEEE80211_RC_NSS_CHANGED)
7445 arsta->nss = sta->rx_nss;
7447 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7448 smps = WMI_PEER_SMPS_PS_NONE;
7450 switch (sta->smps_mode) {
7451 case IEEE80211_SMPS_AUTOMATIC:
7452 case IEEE80211_SMPS_OFF:
7453 smps = WMI_PEER_SMPS_PS_NONE;
7455 case IEEE80211_SMPS_STATIC:
7456 smps = WMI_PEER_SMPS_STATIC;
7458 case IEEE80211_SMPS_DYNAMIC:
7459 smps = WMI_PEER_SMPS_DYNAMIC;
7461 case IEEE80211_SMPS_NUM_MODES:
7462 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7463 sta->smps_mode, sta->addr);
7464 smps = WMI_PEER_SMPS_PS_NONE;
7471 arsta->changed |= changed;
7473 spin_unlock_bh(&ar->data_lock);
7475 ieee80211_queue_work(hw, &arsta->update_wk);
7478 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7479 struct ieee80211_vif *vif, s64 tsf_offset)
7481 struct ath10k *ar = hw->priv;
7482 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7483 u32 offset, vdev_param;
7486 if (tsf_offset < 0) {
7487 vdev_param = ar->wmi.vdev_param->dec_tsf;
7488 offset = -tsf_offset;
7490 vdev_param = ar->wmi.vdev_param->inc_tsf;
7491 offset = tsf_offset;
7494 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7495 vdev_param, offset);
7497 if (ret && ret != -EOPNOTSUPP)
7498 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7499 offset, vdev_param, ret);
7502 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7503 struct ieee80211_vif *vif,
7504 struct ieee80211_ampdu_params *params)
7506 struct ath10k *ar = hw->priv;
7507 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7508 struct ieee80211_sta *sta = params->sta;
7509 enum ieee80211_ampdu_mlme_action action = params->action;
7510 u16 tid = params->tid;
7512 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7513 arvif->vdev_id, sta->addr, tid, action);
7516 case IEEE80211_AMPDU_RX_START:
7517 case IEEE80211_AMPDU_RX_STOP:
7518 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7519 * creation/removal. Do we need to verify this?
7522 case IEEE80211_AMPDU_TX_START:
7523 case IEEE80211_AMPDU_TX_STOP_CONT:
7524 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7525 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7526 case IEEE80211_AMPDU_TX_OPERATIONAL:
7527 /* Firmware offloads Tx aggregation entirely so deny mac80211
7528 * Tx aggregation requests.
7537 ath10k_mac_update_rx_channel(struct ath10k *ar,
7538 struct ieee80211_chanctx_conf *ctx,
7539 struct ieee80211_vif_chanctx_switch *vifs,
7542 struct cfg80211_chan_def *def = NULL;
7544 /* Both locks are required because ar->rx_channel is modified. This
7545 * allows readers to hold either lock.
7547 lockdep_assert_held(&ar->conf_mutex);
7548 lockdep_assert_held(&ar->data_lock);
7550 WARN_ON(ctx && vifs);
7551 WARN_ON(vifs && !n_vifs);
7553 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7554 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7555 * ppdu on Rx may reduce performance on low-end systems. It should be
7556 * possible to make tables/hashmaps to speed the lookup up (be vary of
7557 * cpu data cache lines though regarding sizes) but to keep the initial
7558 * implementation simple and less intrusive fallback to the slow lookup
7559 * only for multi-channel cases. Single-channel cases will remain to
7560 * use the old channel derival and thus performance should not be
7564 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7565 ieee80211_iter_chan_contexts_atomic(ar->hw,
7566 ath10k_mac_get_any_chandef_iter,
7570 def = &vifs[0].new_ctx->def;
7572 ar->rx_channel = def->chan;
7573 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7574 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7575 /* During driver restart due to firmware assert, since mac80211
7576 * already has valid channel context for given radio, channel
7577 * context iteration return num_chanctx > 0. So fix rx_channel
7578 * when restart is in progress.
7580 ar->rx_channel = ctx->def.chan;
7582 ar->rx_channel = NULL;
7588 ath10k_mac_update_vif_chan(struct ath10k *ar,
7589 struct ieee80211_vif_chanctx_switch *vifs,
7592 struct ath10k_vif *arvif;
7596 lockdep_assert_held(&ar->conf_mutex);
7598 /* First stop monitor interface. Some FW versions crash if there's a
7599 * lone monitor interface.
7601 if (ar->monitor_started)
7602 ath10k_monitor_stop(ar);
7604 for (i = 0; i < n_vifs; i++) {
7605 arvif = (void *)vifs[i].vif->drv_priv;
7607 ath10k_dbg(ar, ATH10K_DBG_MAC,
7608 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7610 vifs[i].old_ctx->def.chan->center_freq,
7611 vifs[i].new_ctx->def.chan->center_freq,
7612 vifs[i].old_ctx->def.width,
7613 vifs[i].new_ctx->def.width);
7615 if (WARN_ON(!arvif->is_started))
7618 if (WARN_ON(!arvif->is_up))
7621 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7623 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7624 arvif->vdev_id, ret);
7629 /* All relevant vdevs are downed and associated channel resources
7630 * should be available for the channel switch now.
7633 spin_lock_bh(&ar->data_lock);
7634 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7635 spin_unlock_bh(&ar->data_lock);
7637 for (i = 0; i < n_vifs; i++) {
7638 arvif = (void *)vifs[i].vif->drv_priv;
7640 if (WARN_ON(!arvif->is_started))
7643 if (WARN_ON(!arvif->is_up))
7646 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7648 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7651 ret = ath10k_mac_setup_prb_tmpl(arvif);
7653 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7656 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7658 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7659 arvif->vdev_id, ret);
7663 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7666 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7667 arvif->vdev_id, ret);
7672 ath10k_monitor_recalc(ar);
7676 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7677 struct ieee80211_chanctx_conf *ctx)
7679 struct ath10k *ar = hw->priv;
7681 ath10k_dbg(ar, ATH10K_DBG_MAC,
7682 "mac chanctx add freq %hu width %d ptr %pK\n",
7683 ctx->def.chan->center_freq, ctx->def.width, ctx);
7685 mutex_lock(&ar->conf_mutex);
7687 spin_lock_bh(&ar->data_lock);
7688 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7689 spin_unlock_bh(&ar->data_lock);
7691 ath10k_recalc_radar_detection(ar);
7692 ath10k_monitor_recalc(ar);
7694 mutex_unlock(&ar->conf_mutex);
7700 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7701 struct ieee80211_chanctx_conf *ctx)
7703 struct ath10k *ar = hw->priv;
7705 ath10k_dbg(ar, ATH10K_DBG_MAC,
7706 "mac chanctx remove freq %hu width %d ptr %pK\n",
7707 ctx->def.chan->center_freq, ctx->def.width, ctx);
7709 mutex_lock(&ar->conf_mutex);
7711 spin_lock_bh(&ar->data_lock);
7712 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7713 spin_unlock_bh(&ar->data_lock);
7715 ath10k_recalc_radar_detection(ar);
7716 ath10k_monitor_recalc(ar);
7718 mutex_unlock(&ar->conf_mutex);
7721 struct ath10k_mac_change_chanctx_arg {
7722 struct ieee80211_chanctx_conf *ctx;
7723 struct ieee80211_vif_chanctx_switch *vifs;
7729 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7730 struct ieee80211_vif *vif)
7732 struct ath10k_mac_change_chanctx_arg *arg = data;
7734 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7741 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7742 struct ieee80211_vif *vif)
7744 struct ath10k_mac_change_chanctx_arg *arg = data;
7745 struct ieee80211_chanctx_conf *ctx;
7747 ctx = rcu_access_pointer(vif->chanctx_conf);
7748 if (ctx != arg->ctx)
7751 if (WARN_ON(arg->next_vif == arg->n_vifs))
7754 arg->vifs[arg->next_vif].vif = vif;
7755 arg->vifs[arg->next_vif].old_ctx = ctx;
7756 arg->vifs[arg->next_vif].new_ctx = ctx;
7761 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7762 struct ieee80211_chanctx_conf *ctx,
7765 struct ath10k *ar = hw->priv;
7766 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7768 mutex_lock(&ar->conf_mutex);
7770 ath10k_dbg(ar, ATH10K_DBG_MAC,
7771 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7772 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7774 /* This shouldn't really happen because channel switching should use
7775 * switch_vif_chanctx().
7777 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7780 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7781 ieee80211_iterate_active_interfaces_atomic(
7783 IEEE80211_IFACE_ITER_NORMAL,
7784 ath10k_mac_change_chanctx_cnt_iter,
7786 if (arg.n_vifs == 0)
7789 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7794 ieee80211_iterate_active_interfaces_atomic(
7796 IEEE80211_IFACE_ITER_NORMAL,
7797 ath10k_mac_change_chanctx_fill_iter,
7799 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7804 ath10k_recalc_radar_detection(ar);
7806 /* FIXME: How to configure Rx chains properly? */
7808 /* No other actions are actually necessary. Firmware maintains channel
7809 * definitions per vdev internally and there's no host-side channel
7810 * context abstraction to configure, e.g. channel width.
7814 mutex_unlock(&ar->conf_mutex);
7818 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7819 struct ieee80211_vif *vif,
7820 struct ieee80211_chanctx_conf *ctx)
7822 struct ath10k *ar = hw->priv;
7823 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7826 mutex_lock(&ar->conf_mutex);
7828 ath10k_dbg(ar, ATH10K_DBG_MAC,
7829 "mac chanctx assign ptr %pK vdev_id %i\n",
7830 ctx, arvif->vdev_id);
7832 if (WARN_ON(arvif->is_started)) {
7833 mutex_unlock(&ar->conf_mutex);
7837 ret = ath10k_vdev_start(arvif, &ctx->def);
7839 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7840 arvif->vdev_id, vif->addr,
7841 ctx->def.chan->center_freq, ret);
7845 arvif->is_started = true;
7847 ret = ath10k_mac_vif_setup_ps(arvif);
7849 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7850 arvif->vdev_id, ret);
7854 if (vif->type == NL80211_IFTYPE_MONITOR) {
7855 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7857 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7858 arvif->vdev_id, ret);
7862 arvif->is_up = true;
7865 if (ath10k_mac_can_set_cts_prot(arvif)) {
7866 ret = ath10k_mac_set_cts_prot(arvif);
7868 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7869 arvif->vdev_id, ret);
7872 if (ath10k_peer_stats_enabled(ar)) {
7873 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
7874 ret = ath10k_wmi_pdev_pktlog_enable(ar,
7877 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
7882 mutex_unlock(&ar->conf_mutex);
7886 ath10k_vdev_stop(arvif);
7887 arvif->is_started = false;
7888 ath10k_mac_vif_setup_ps(arvif);
7891 mutex_unlock(&ar->conf_mutex);
7896 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7897 struct ieee80211_vif *vif,
7898 struct ieee80211_chanctx_conf *ctx)
7900 struct ath10k *ar = hw->priv;
7901 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7904 mutex_lock(&ar->conf_mutex);
7906 ath10k_dbg(ar, ATH10K_DBG_MAC,
7907 "mac chanctx unassign ptr %pK vdev_id %i\n",
7908 ctx, arvif->vdev_id);
7910 WARN_ON(!arvif->is_started);
7912 if (vif->type == NL80211_IFTYPE_MONITOR) {
7913 WARN_ON(!arvif->is_up);
7915 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7917 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7918 arvif->vdev_id, ret);
7920 arvif->is_up = false;
7923 ret = ath10k_vdev_stop(arvif);
7925 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7926 arvif->vdev_id, ret);
7928 arvif->is_started = false;
7930 mutex_unlock(&ar->conf_mutex);
7934 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7935 struct ieee80211_vif_chanctx_switch *vifs,
7937 enum ieee80211_chanctx_switch_mode mode)
7939 struct ath10k *ar = hw->priv;
7941 mutex_lock(&ar->conf_mutex);
7943 ath10k_dbg(ar, ATH10K_DBG_MAC,
7944 "mac chanctx switch n_vifs %d mode %d\n",
7946 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7948 mutex_unlock(&ar->conf_mutex);
7952 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7953 struct ieee80211_vif *vif,
7954 struct ieee80211_sta *sta)
7957 struct ath10k_peer *peer;
7961 list_for_each_entry(peer, &ar->peers, list)
7962 if (peer->sta == sta)
7963 peer->removed = true;
7966 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
7967 struct ieee80211_vif *vif,
7968 struct ieee80211_sta *sta,
7969 struct station_info *sinfo)
7971 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7972 struct ath10k *ar = arsta->arvif->ar;
7974 if (!ath10k_peer_stats_enabled(ar))
7977 sinfo->rx_duration = arsta->rx_duration;
7978 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
7980 if (!arsta->txrate.legacy && !arsta->txrate.nss)
7983 if (arsta->txrate.legacy) {
7984 sinfo->txrate.legacy = arsta->txrate.legacy;
7986 sinfo->txrate.mcs = arsta->txrate.mcs;
7987 sinfo->txrate.nss = arsta->txrate.nss;
7988 sinfo->txrate.bw = arsta->txrate.bw;
7990 sinfo->txrate.flags = arsta->txrate.flags;
7991 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
7994 static const struct ieee80211_ops ath10k_ops = {
7995 .tx = ath10k_mac_op_tx,
7996 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7997 .start = ath10k_start,
7998 .stop = ath10k_stop,
7999 .config = ath10k_config,
8000 .add_interface = ath10k_add_interface,
8001 .remove_interface = ath10k_remove_interface,
8002 .configure_filter = ath10k_configure_filter,
8003 .bss_info_changed = ath10k_bss_info_changed,
8004 .set_coverage_class = ath10k_mac_op_set_coverage_class,
8005 .hw_scan = ath10k_hw_scan,
8006 .cancel_hw_scan = ath10k_cancel_hw_scan,
8007 .set_key = ath10k_set_key,
8008 .set_default_unicast_key = ath10k_set_default_unicast_key,
8009 .sta_state = ath10k_sta_state,
8010 .conf_tx = ath10k_conf_tx,
8011 .remain_on_channel = ath10k_remain_on_channel,
8012 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
8013 .set_rts_threshold = ath10k_set_rts_threshold,
8014 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
8015 .flush = ath10k_flush,
8016 .tx_last_beacon = ath10k_tx_last_beacon,
8017 .set_antenna = ath10k_set_antenna,
8018 .get_antenna = ath10k_get_antenna,
8019 .reconfig_complete = ath10k_reconfig_complete,
8020 .get_survey = ath10k_get_survey,
8021 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
8022 .sta_rc_update = ath10k_sta_rc_update,
8023 .offset_tsf = ath10k_offset_tsf,
8024 .ampdu_action = ath10k_ampdu_action,
8025 .get_et_sset_count = ath10k_debug_get_et_sset_count,
8026 .get_et_stats = ath10k_debug_get_et_stats,
8027 .get_et_strings = ath10k_debug_get_et_strings,
8028 .add_chanctx = ath10k_mac_op_add_chanctx,
8029 .remove_chanctx = ath10k_mac_op_remove_chanctx,
8030 .change_chanctx = ath10k_mac_op_change_chanctx,
8031 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
8032 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
8033 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
8034 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
8035 .sta_statistics = ath10k_sta_statistics,
8037 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
8040 .suspend = ath10k_wow_op_suspend,
8041 .resume = ath10k_wow_op_resume,
8042 .set_wakeup = ath10k_wow_op_set_wakeup,
8044 #ifdef CONFIG_MAC80211_DEBUGFS
8045 .sta_add_debugfs = ath10k_sta_add_debugfs,
8049 #define CHAN2G(_channel, _freq, _flags) { \
8050 .band = NL80211_BAND_2GHZ, \
8051 .hw_value = (_channel), \
8052 .center_freq = (_freq), \
8053 .flags = (_flags), \
8054 .max_antenna_gain = 0, \
8058 #define CHAN5G(_channel, _freq, _flags) { \
8059 .band = NL80211_BAND_5GHZ, \
8060 .hw_value = (_channel), \
8061 .center_freq = (_freq), \
8062 .flags = (_flags), \
8063 .max_antenna_gain = 0, \
8067 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
8077 CHAN2G(10, 2457, 0),
8078 CHAN2G(11, 2462, 0),
8079 CHAN2G(12, 2467, 0),
8080 CHAN2G(13, 2472, 0),
8081 CHAN2G(14, 2484, 0),
8084 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
8085 CHAN5G(36, 5180, 0),
8086 CHAN5G(40, 5200, 0),
8087 CHAN5G(44, 5220, 0),
8088 CHAN5G(48, 5240, 0),
8089 CHAN5G(52, 5260, 0),
8090 CHAN5G(56, 5280, 0),
8091 CHAN5G(60, 5300, 0),
8092 CHAN5G(64, 5320, 0),
8093 CHAN5G(100, 5500, 0),
8094 CHAN5G(104, 5520, 0),
8095 CHAN5G(108, 5540, 0),
8096 CHAN5G(112, 5560, 0),
8097 CHAN5G(116, 5580, 0),
8098 CHAN5G(120, 5600, 0),
8099 CHAN5G(124, 5620, 0),
8100 CHAN5G(128, 5640, 0),
8101 CHAN5G(132, 5660, 0),
8102 CHAN5G(136, 5680, 0),
8103 CHAN5G(140, 5700, 0),
8104 CHAN5G(144, 5720, 0),
8105 CHAN5G(149, 5745, 0),
8106 CHAN5G(153, 5765, 0),
8107 CHAN5G(157, 5785, 0),
8108 CHAN5G(161, 5805, 0),
8109 CHAN5G(165, 5825, 0),
8110 CHAN5G(169, 5845, 0),
8111 CHAN5G(173, 5865, 0),
8112 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
8113 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
8116 struct ath10k *ath10k_mac_create(size_t priv_size)
8118 struct ieee80211_hw *hw;
8119 struct ieee80211_ops *ops;
8122 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
8126 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
8139 void ath10k_mac_destroy(struct ath10k *ar)
8141 struct ieee80211_ops *ops = ar->ops;
8143 ieee80211_free_hw(ar->hw);
8147 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
8150 .types = BIT(NL80211_IFTYPE_STATION)
8151 | BIT(NL80211_IFTYPE_P2P_CLIENT)
8155 .types = BIT(NL80211_IFTYPE_P2P_GO)
8159 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
8163 .types = BIT(NL80211_IFTYPE_AP)
8164 #ifdef CONFIG_MAC80211_MESH
8165 | BIT(NL80211_IFTYPE_MESH_POINT)
8170 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
8173 .types = BIT(NL80211_IFTYPE_AP)
8174 #ifdef CONFIG_MAC80211_MESH
8175 | BIT(NL80211_IFTYPE_MESH_POINT)
8180 .types = BIT(NL80211_IFTYPE_STATION)
8184 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
8186 .limits = ath10k_if_limits,
8187 .n_limits = ARRAY_SIZE(ath10k_if_limits),
8188 .max_interfaces = 8,
8189 .num_different_channels = 1,
8190 .beacon_int_infra_match = true,
8194 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
8196 .limits = ath10k_10x_if_limits,
8197 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
8198 .max_interfaces = 8,
8199 .num_different_channels = 1,
8200 .beacon_int_infra_match = true,
8201 .beacon_int_min_gcd = 1,
8202 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8203 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8204 BIT(NL80211_CHAN_WIDTH_20) |
8205 BIT(NL80211_CHAN_WIDTH_40) |
8206 BIT(NL80211_CHAN_WIDTH_80),
8211 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
8214 .types = BIT(NL80211_IFTYPE_STATION),
8218 .types = BIT(NL80211_IFTYPE_AP) |
8219 #ifdef CONFIG_MAC80211_MESH
8220 BIT(NL80211_IFTYPE_MESH_POINT) |
8222 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8223 BIT(NL80211_IFTYPE_P2P_GO),
8227 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8231 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
8234 .types = BIT(NL80211_IFTYPE_STATION),
8238 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
8242 .types = BIT(NL80211_IFTYPE_AP) |
8243 #ifdef CONFIG_MAC80211_MESH
8244 BIT(NL80211_IFTYPE_MESH_POINT) |
8246 BIT(NL80211_IFTYPE_P2P_GO),
8250 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8254 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
8257 .types = BIT(NL80211_IFTYPE_STATION),
8261 .types = BIT(NL80211_IFTYPE_ADHOC),
8265 /* FIXME: This is not thouroughly tested. These combinations may over- or
8266 * underestimate hw/fw capabilities.
8268 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
8270 .limits = ath10k_tlv_if_limit,
8271 .num_different_channels = 1,
8272 .max_interfaces = 4,
8273 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8276 .limits = ath10k_tlv_if_limit_ibss,
8277 .num_different_channels = 1,
8278 .max_interfaces = 2,
8279 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8283 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
8285 .limits = ath10k_tlv_if_limit,
8286 .num_different_channels = 1,
8287 .max_interfaces = 4,
8288 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8291 .limits = ath10k_tlv_qcs_if_limit,
8292 .num_different_channels = 2,
8293 .max_interfaces = 4,
8294 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
8297 .limits = ath10k_tlv_if_limit_ibss,
8298 .num_different_channels = 1,
8299 .max_interfaces = 2,
8300 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8304 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8307 .types = BIT(NL80211_IFTYPE_STATION),
8311 .types = BIT(NL80211_IFTYPE_AP)
8312 #ifdef CONFIG_MAC80211_MESH
8313 | BIT(NL80211_IFTYPE_MESH_POINT)
8318 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8320 .limits = ath10k_10_4_if_limits,
8321 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8322 .max_interfaces = 16,
8323 .num_different_channels = 1,
8324 .beacon_int_infra_match = true,
8325 .beacon_int_min_gcd = 1,
8326 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8327 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8328 BIT(NL80211_CHAN_WIDTH_20) |
8329 BIT(NL80211_CHAN_WIDTH_40) |
8330 BIT(NL80211_CHAN_WIDTH_80),
8336 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = {
8338 .limits = ath10k_10_4_if_limits,
8339 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8340 .max_interfaces = 16,
8341 .num_different_channels = 1,
8342 .beacon_int_infra_match = true,
8343 .beacon_int_min_gcd = 100,
8344 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8345 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8346 BIT(NL80211_CHAN_WIDTH_20) |
8347 BIT(NL80211_CHAN_WIDTH_40) |
8348 BIT(NL80211_CHAN_WIDTH_80),
8353 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8354 struct ieee80211_vif *vif)
8356 struct ath10k_vif_iter *arvif_iter = data;
8357 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8359 if (arvif->vdev_id == arvif_iter->vdev_id)
8360 arvif_iter->arvif = arvif;
8363 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8365 struct ath10k_vif_iter arvif_iter;
8368 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8369 arvif_iter.vdev_id = vdev_id;
8371 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8372 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8374 ath10k_get_arvif_iter,
8376 if (!arvif_iter.arvif) {
8377 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8381 return arvif_iter.arvif;
8384 #define WRD_METHOD "WRDD"
8385 #define WRDD_WIFI (0x07)
8387 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8389 union acpi_object *mcc_pkg;
8390 union acpi_object *domain_type;
8391 union acpi_object *mcc_value;
8394 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8395 wrdd->package.count < 2 ||
8396 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8397 wrdd->package.elements[0].integer.value != 0) {
8398 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8402 for (i = 1; i < wrdd->package.count; ++i) {
8403 mcc_pkg = &wrdd->package.elements[i];
8405 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8407 if (mcc_pkg->package.count < 2)
8409 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8410 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8413 domain_type = &mcc_pkg->package.elements[0];
8414 if (domain_type->integer.value != WRDD_WIFI)
8417 mcc_value = &mcc_pkg->package.elements[1];
8418 return mcc_value->integer.value;
8423 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8425 acpi_handle root_handle;
8427 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8432 root_handle = ACPI_HANDLE(ar->dev);
8436 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8437 if (ACPI_FAILURE(status)) {
8438 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8439 "failed to get wrd method %d\n", status);
8443 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8444 if (ACPI_FAILURE(status)) {
8445 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8446 "failed to call wrdc %d\n", status);
8450 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8451 kfree(wrdd.pointer);
8455 alpha2[0] = (alpha2_code >> 8) & 0xff;
8456 alpha2[1] = (alpha2_code >> 0) & 0xff;
8459 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8460 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8462 *rd = ath_regd_find_country_by_name(alpha2);
8466 *rd |= COUNTRY_ERD_FLAG;
8470 static int ath10k_mac_init_rd(struct ath10k *ar)
8475 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8477 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8478 "fallback to eeprom programmed regulatory settings\n");
8479 rd = ar->hw_eeprom_rd;
8482 ar->ath_common.regulatory.current_rd = rd;
8486 int ath10k_mac_register(struct ath10k *ar)
8488 static const u32 cipher_suites[] = {
8489 WLAN_CIPHER_SUITE_WEP40,
8490 WLAN_CIPHER_SUITE_WEP104,
8491 WLAN_CIPHER_SUITE_TKIP,
8492 WLAN_CIPHER_SUITE_CCMP,
8494 /* Do not add hardware supported ciphers before this line.
8495 * Allow software encryption for all chips. Don't forget to
8496 * update n_cipher_suites below.
8498 WLAN_CIPHER_SUITE_AES_CMAC,
8499 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8500 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8501 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8503 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8504 * and CCMP-256 in hardware.
8506 WLAN_CIPHER_SUITE_GCMP,
8507 WLAN_CIPHER_SUITE_GCMP_256,
8508 WLAN_CIPHER_SUITE_CCMP_256,
8510 struct ieee80211_supported_band *band;
8514 if (!is_valid_ether_addr(ar->mac_addr)) {
8515 ath10k_warn(ar, "invalid MAC address; choosing random\n");
8516 eth_random_addr(ar->mac_addr);
8518 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8520 SET_IEEE80211_DEV(ar->hw, ar->dev);
8522 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8523 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8526 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8527 channels = kmemdup(ath10k_2ghz_channels,
8528 sizeof(ath10k_2ghz_channels),
8535 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8536 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8537 band->channels = channels;
8539 if (ar->hw_params.cck_rate_map_rev2) {
8540 band->n_bitrates = ath10k_g_rates_rev2_size;
8541 band->bitrates = ath10k_g_rates_rev2;
8543 band->n_bitrates = ath10k_g_rates_size;
8544 band->bitrates = ath10k_g_rates;
8547 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8550 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8551 channels = kmemdup(ath10k_5ghz_channels,
8552 sizeof(ath10k_5ghz_channels),
8559 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8560 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8561 band->channels = channels;
8562 band->n_bitrates = ath10k_a_rates_size;
8563 band->bitrates = ath10k_a_rates;
8564 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8567 wiphy_read_of_freq_limits(ar->hw->wiphy);
8568 ath10k_mac_setup_ht_vht_cap(ar);
8570 ar->hw->wiphy->interface_modes =
8571 BIT(NL80211_IFTYPE_STATION) |
8572 BIT(NL80211_IFTYPE_AP) |
8573 BIT(NL80211_IFTYPE_MESH_POINT);
8575 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8576 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8578 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8579 ar->hw->wiphy->interface_modes |=
8580 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8581 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8582 BIT(NL80211_IFTYPE_P2P_GO);
8584 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8586 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
8587 ar->running_fw->fw_file.fw_features)) {
8588 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8589 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8592 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8593 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8594 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8595 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8596 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8597 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8598 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8599 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8600 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8601 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8602 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8603 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8604 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8606 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8607 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8609 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8610 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8612 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8613 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8615 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8616 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8617 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8620 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8621 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8623 if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
8624 ar->hw->wiphy->max_sched_scan_reqs = 1;
8625 ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
8626 ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
8627 ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
8628 ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
8629 ar->hw->wiphy->max_sched_scan_plan_interval =
8630 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
8631 ar->hw->wiphy->max_sched_scan_plan_iterations =
8632 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
8635 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8636 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8637 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8639 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8641 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8642 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8644 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8645 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8646 * correct Probe Responses. This is more of a hack advert..
8648 ar->hw->wiphy->probe_resp_offload |=
8649 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8650 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8651 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8654 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8655 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8656 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8657 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
8658 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8661 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8662 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
8664 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8665 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8666 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8668 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8669 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8670 NL80211_FEATURE_AP_SCAN;
8672 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8674 ret = ath10k_wow_init(ar);
8676 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8680 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8681 wiphy_ext_feature_set(ar->hw->wiphy,
8682 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
8684 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) ||
8685 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map))
8686 wiphy_ext_feature_set(ar->hw->wiphy,
8687 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
8689 if (ath10k_peer_stats_enabled(ar) ||
8690 test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
8691 wiphy_ext_feature_set(ar->hw->wiphy,
8692 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
8694 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map))
8695 wiphy_ext_feature_set(ar->hw->wiphy,
8696 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
8699 * on LL hardware queues are managed entirely by the FW
8700 * so we only advertise to mac we can do the queues thing
8702 ar->hw->queues = IEEE80211_MAX_QUEUES;
8704 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8705 * something that vdev_ids can't reach so that we don't stop the queue
8708 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8710 switch (ar->running_fw->fw_file.wmi_op_version) {
8711 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8712 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8713 ar->hw->wiphy->n_iface_combinations =
8714 ARRAY_SIZE(ath10k_if_comb);
8715 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8717 case ATH10K_FW_WMI_OP_VERSION_TLV:
8718 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8719 ar->hw->wiphy->iface_combinations =
8720 ath10k_tlv_qcs_if_comb;
8721 ar->hw->wiphy->n_iface_combinations =
8722 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8724 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8725 ar->hw->wiphy->n_iface_combinations =
8726 ARRAY_SIZE(ath10k_tlv_if_comb);
8728 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8730 case ATH10K_FW_WMI_OP_VERSION_10_1:
8731 case ATH10K_FW_WMI_OP_VERSION_10_2:
8732 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8733 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8734 ar->hw->wiphy->n_iface_combinations =
8735 ARRAY_SIZE(ath10k_10x_if_comb);
8737 case ATH10K_FW_WMI_OP_VERSION_10_4:
8738 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8739 ar->hw->wiphy->n_iface_combinations =
8740 ARRAY_SIZE(ath10k_10_4_if_comb);
8741 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT,
8743 ar->hw->wiphy->iface_combinations =
8744 ath10k_10_4_bcn_int_if_comb;
8745 ar->hw->wiphy->n_iface_combinations =
8746 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb);
8749 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8750 case ATH10K_FW_WMI_OP_VERSION_MAX:
8756 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8757 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8759 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8760 /* Init ath dfs pattern detector */
8761 ar->ath_common.debug_mask = ATH_DBG_DFS;
8762 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8765 if (!ar->dfs_detector)
8766 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8769 ret = ath10k_mac_init_rd(ar);
8771 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8772 goto err_dfs_detector_exit;
8775 /* Disable set_coverage_class for chipsets that do not support it. */
8776 if (!ar->hw_params.hw_ops->set_coverage_class)
8777 ar->ops->set_coverage_class = NULL;
8779 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8780 ath10k_reg_notifier);
8782 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8783 goto err_dfs_detector_exit;
8786 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
8787 ar->hw->wiphy->features |=
8788 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8791 ar->hw->wiphy->cipher_suites = cipher_suites;
8793 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
8794 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
8795 * from chip specific hw_param table.
8797 if (!ar->hw_params.n_cipher_suites ||
8798 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
8799 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
8800 ar->hw_params.n_cipher_suites);
8801 ar->hw_params.n_cipher_suites = 8;
8803 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
8805 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8807 ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER;
8809 ret = ieee80211_register_hw(ar->hw);
8811 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8812 goto err_dfs_detector_exit;
8815 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT, ar->wmi.svc_map)) {
8816 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
8817 ar->hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
8820 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8821 ret = regulatory_hint(ar->hw->wiphy,
8822 ar->ath_common.regulatory.alpha2);
8824 goto err_unregister;
8830 ieee80211_unregister_hw(ar->hw);
8832 err_dfs_detector_exit:
8833 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8834 ar->dfs_detector->exit(ar->dfs_detector);
8837 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8838 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8840 SET_IEEE80211_DEV(ar->hw, NULL);
8844 void ath10k_mac_unregister(struct ath10k *ar)
8846 ieee80211_unregister_hw(ar->hw);
8848 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8849 ar->dfs_detector->exit(ar->dfs_detector);
8851 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8852 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8854 SET_IEEE80211_DEV(ar->hw, NULL);