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 /* For mesh, probe response and beacon share the same template */
1634 if (ieee80211_vif_is_mesh(vif))
1637 prb = ieee80211_proberesp_get(hw, vif);
1639 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1643 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1647 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1655 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1657 struct ath10k *ar = arvif->ar;
1658 struct cfg80211_chan_def def;
1661 /* When originally vdev is started during assign_vif_chanctx() some
1662 * information is missing, notably SSID. Firmware revisions with beacon
1663 * offloading require the SSID to be provided during vdev (re)start to
1664 * handle hidden SSID properly.
1666 * Vdev restart must be done after vdev has been both started and
1667 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1668 * deliver vdev restart response event causing timeouts during vdev
1669 * syncing in ath10k.
1671 * Note: The vdev down/up and template reinstallation could be skipped
1672 * since only wmi-tlv firmware are known to have beacon offload and
1673 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1674 * response delivery. It's probably more robust to keep it as is.
1676 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1679 if (WARN_ON(!arvif->is_started))
1682 if (WARN_ON(!arvif->is_up))
1685 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1688 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1690 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1691 arvif->vdev_id, ret);
1695 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1696 * firmware will crash upon vdev up.
1699 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1701 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1705 ret = ath10k_mac_setup_prb_tmpl(arvif);
1707 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1711 ret = ath10k_vdev_restart(arvif, &def);
1713 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1714 arvif->vdev_id, ret);
1718 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1721 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1722 arvif->vdev_id, ret);
1729 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1730 struct ieee80211_bss_conf *info)
1732 struct ath10k *ar = arvif->ar;
1735 lockdep_assert_held(&arvif->ar->conf_mutex);
1737 if (!info->enable_beacon) {
1738 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1740 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1741 arvif->vdev_id, ret);
1743 arvif->is_up = false;
1745 spin_lock_bh(&arvif->ar->data_lock);
1746 ath10k_mac_vif_beacon_free(arvif);
1747 spin_unlock_bh(&arvif->ar->data_lock);
1752 arvif->tx_seq_no = 0x1000;
1755 ether_addr_copy(arvif->bssid, info->bssid);
1757 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1760 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1761 arvif->vdev_id, ret);
1765 arvif->is_up = true;
1767 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1769 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1770 arvif->vdev_id, ret);
1774 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1777 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1778 struct ieee80211_bss_conf *info,
1779 const u8 self_peer[ETH_ALEN])
1781 struct ath10k *ar = arvif->ar;
1785 lockdep_assert_held(&arvif->ar->conf_mutex);
1787 if (!info->ibss_joined) {
1788 if (is_zero_ether_addr(arvif->bssid))
1791 eth_zero_addr(arvif->bssid);
1796 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1797 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1798 ATH10K_DEFAULT_ATIM);
1800 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1801 arvif->vdev_id, ret);
1804 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1806 struct ath10k *ar = arvif->ar;
1811 lockdep_assert_held(&arvif->ar->conf_mutex);
1813 if (arvif->u.sta.uapsd)
1814 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1816 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1818 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1819 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1821 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1822 value, arvif->vdev_id, ret);
1829 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1831 struct ath10k *ar = arvif->ar;
1836 lockdep_assert_held(&arvif->ar->conf_mutex);
1838 if (arvif->u.sta.uapsd)
1839 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1841 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1843 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1844 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1847 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1848 value, arvif->vdev_id, ret);
1855 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1857 struct ath10k_vif *arvif;
1860 lockdep_assert_held(&ar->conf_mutex);
1862 list_for_each_entry(arvif, &ar->arvifs, list)
1863 if (arvif->is_started)
1869 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1871 struct ath10k *ar = arvif->ar;
1872 struct ieee80211_vif *vif = arvif->vif;
1873 struct ieee80211_conf *conf = &ar->hw->conf;
1874 enum wmi_sta_powersave_param param;
1875 enum wmi_sta_ps_mode psmode;
1880 lockdep_assert_held(&arvif->ar->conf_mutex);
1882 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1885 enable_ps = arvif->ps;
1887 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1888 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1889 ar->running_fw->fw_file.fw_features)) {
1890 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1895 if (!arvif->is_started) {
1896 /* mac80211 can update vif powersave state while disconnected.
1897 * Firmware doesn't behave nicely and consumes more power than
1898 * necessary if PS is disabled on a non-started vdev. Hence
1899 * force-enable PS for non-running vdevs.
1901 psmode = WMI_STA_PS_MODE_ENABLED;
1902 } else if (enable_ps) {
1903 psmode = WMI_STA_PS_MODE_ENABLED;
1904 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1906 ps_timeout = conf->dynamic_ps_timeout;
1907 if (ps_timeout == 0) {
1908 /* Firmware doesn't like 0 */
1909 ps_timeout = ieee80211_tu_to_usec(
1910 vif->bss_conf.beacon_int) / 1000;
1913 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1916 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1917 arvif->vdev_id, ret);
1921 psmode = WMI_STA_PS_MODE_DISABLED;
1924 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1925 arvif->vdev_id, psmode ? "enable" : "disable");
1927 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1929 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1930 psmode, arvif->vdev_id, ret);
1937 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1939 struct ath10k *ar = arvif->ar;
1940 struct wmi_sta_keepalive_arg arg = {};
1943 lockdep_assert_held(&arvif->ar->conf_mutex);
1945 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1948 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1951 /* Some firmware revisions have a bug and ignore the `enabled` field.
1952 * Instead use the interval to disable the keepalive.
1954 arg.vdev_id = arvif->vdev_id;
1956 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1957 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1959 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1961 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1962 arvif->vdev_id, ret);
1969 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1971 struct ath10k *ar = arvif->ar;
1972 struct ieee80211_vif *vif = arvif->vif;
1975 lockdep_assert_held(&arvif->ar->conf_mutex);
1977 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1980 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1983 if (!vif->csa_active)
1989 if (!ieee80211_csa_is_complete(vif)) {
1990 ieee80211_csa_update_counter(vif);
1992 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1994 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1997 ret = ath10k_mac_setup_prb_tmpl(arvif);
1999 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
2002 ieee80211_csa_finish(vif);
2006 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
2008 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2010 struct ath10k *ar = arvif->ar;
2012 mutex_lock(&ar->conf_mutex);
2013 ath10k_mac_vif_ap_csa_count_down(arvif);
2014 mutex_unlock(&ar->conf_mutex);
2017 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2018 struct ieee80211_vif *vif)
2020 struct sk_buff *skb = data;
2021 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2022 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2024 if (vif->type != NL80211_IFTYPE_STATION)
2027 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2030 cancel_delayed_work(&arvif->connection_loss_work);
2033 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2035 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2036 IEEE80211_IFACE_ITER_NORMAL,
2037 ath10k_mac_handle_beacon_iter,
2041 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2042 struct ieee80211_vif *vif)
2044 u32 *vdev_id = data;
2045 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2046 struct ath10k *ar = arvif->ar;
2047 struct ieee80211_hw *hw = ar->hw;
2049 if (arvif->vdev_id != *vdev_id)
2055 ieee80211_beacon_loss(vif);
2057 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2058 * (done by mac80211) succeeds but beacons do not resume then it
2059 * doesn't make sense to continue operation. Queue connection loss work
2060 * which can be cancelled when beacon is received.
2062 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2063 ATH10K_CONNECTION_LOSS_HZ);
2066 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2068 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2069 IEEE80211_IFACE_ITER_NORMAL,
2070 ath10k_mac_handle_beacon_miss_iter,
2074 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2076 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2077 connection_loss_work.work);
2078 struct ieee80211_vif *vif = arvif->vif;
2083 ieee80211_connection_loss(vif);
2086 /**********************/
2087 /* Station management */
2088 /**********************/
2090 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2091 struct ieee80211_vif *vif)
2093 /* Some firmware revisions have unstable STA powersave when listen
2094 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2095 * generate NullFunc frames properly even if buffered frames have been
2096 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2097 * buffered frames. Often pinging the device from AP would simply fail.
2099 * As a workaround set it to 1.
2101 if (vif->type == NL80211_IFTYPE_STATION)
2104 return ar->hw->conf.listen_interval;
2107 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2108 struct ieee80211_vif *vif,
2109 struct ieee80211_sta *sta,
2110 struct wmi_peer_assoc_complete_arg *arg)
2112 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2115 lockdep_assert_held(&ar->conf_mutex);
2117 if (vif->type == NL80211_IFTYPE_STATION)
2118 aid = vif->bss_conf.aid;
2122 ether_addr_copy(arg->addr, sta->addr);
2123 arg->vdev_id = arvif->vdev_id;
2124 arg->peer_aid = aid;
2125 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2126 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2127 arg->peer_num_spatial_streams = 1;
2128 arg->peer_caps = vif->bss_conf.assoc_capability;
2131 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2132 struct ieee80211_vif *vif,
2133 struct ieee80211_sta *sta,
2134 struct wmi_peer_assoc_complete_arg *arg)
2136 struct ieee80211_bss_conf *info = &vif->bss_conf;
2137 struct cfg80211_chan_def def;
2138 struct cfg80211_bss *bss;
2139 const u8 *rsnie = NULL;
2140 const u8 *wpaie = NULL;
2142 lockdep_assert_held(&ar->conf_mutex);
2144 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2147 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2148 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2150 const struct cfg80211_bss_ies *ies;
2153 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2155 ies = rcu_dereference(bss->ies);
2157 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2158 WLAN_OUI_TYPE_MICROSOFT_WPA,
2162 cfg80211_put_bss(ar->hw->wiphy, bss);
2165 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2166 if (rsnie || wpaie) {
2167 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2168 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2172 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2173 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2177 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2178 ar->running_fw->fw_file.fw_features)) {
2179 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2183 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2184 struct ieee80211_vif *vif,
2185 struct ieee80211_sta *sta,
2186 struct wmi_peer_assoc_complete_arg *arg)
2188 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2189 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2190 struct cfg80211_chan_def def;
2191 const struct ieee80211_supported_band *sband;
2192 const struct ieee80211_rate *rates;
2193 enum nl80211_band band;
2198 lockdep_assert_held(&ar->conf_mutex);
2200 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2203 band = def.chan->band;
2204 sband = ar->hw->wiphy->bands[band];
2205 ratemask = sta->supp_rates[band];
2206 ratemask &= arvif->bitrate_mask.control[band].legacy;
2207 rates = sband->bitrates;
2209 rateset->num_rates = 0;
2211 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2212 if (!(ratemask & 1))
2215 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2216 rateset->rates[rateset->num_rates] = rate;
2217 rateset->num_rates++;
2222 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2226 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2227 if (ht_mcs_mask[nss])
2234 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2238 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2239 if (vht_mcs_mask[nss])
2245 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2246 struct ieee80211_vif *vif,
2247 struct ieee80211_sta *sta,
2248 struct wmi_peer_assoc_complete_arg *arg)
2250 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2251 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2252 struct cfg80211_chan_def def;
2253 enum nl80211_band band;
2254 const u8 *ht_mcs_mask;
2255 const u16 *vht_mcs_mask;
2260 lockdep_assert_held(&ar->conf_mutex);
2262 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2265 if (!ht_cap->ht_supported)
2268 band = def.chan->band;
2269 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2270 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2272 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2273 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2276 arg->peer_flags |= ar->wmi.peer_flags->ht;
2277 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2278 ht_cap->ampdu_factor)) - 1;
2280 arg->peer_mpdu_density =
2281 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2283 arg->peer_ht_caps = ht_cap->cap;
2284 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2286 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2287 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2289 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2290 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2291 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2294 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2295 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2296 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2298 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2299 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2302 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2303 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2304 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2307 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2308 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2309 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2310 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2311 arg->peer_rate_caps |= stbc;
2312 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2315 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2316 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2317 else if (ht_cap->mcs.rx_mask[1])
2318 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2320 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2321 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2322 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2323 max_nss = (i / 8) + 1;
2324 arg->peer_ht_rates.rates[n++] = i;
2328 * This is a workaround for HT-enabled STAs which break the spec
2329 * and have no HT capabilities RX mask (no HT RX MCS map).
2331 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2332 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2334 * Firmware asserts if such situation occurs.
2337 arg->peer_ht_rates.num_rates = 8;
2338 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2339 arg->peer_ht_rates.rates[i] = i;
2341 arg->peer_ht_rates.num_rates = n;
2342 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2345 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2347 arg->peer_ht_rates.num_rates,
2348 arg->peer_num_spatial_streams);
2351 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2352 struct ath10k_vif *arvif,
2353 struct ieee80211_sta *sta)
2359 lockdep_assert_held(&ar->conf_mutex);
2361 if (sta->wme && sta->uapsd_queues) {
2362 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2363 sta->uapsd_queues, sta->max_sp);
2365 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2366 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2367 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2368 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2369 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2370 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2371 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2372 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2373 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2374 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2375 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2376 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2378 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2379 max_sp = sta->max_sp;
2381 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2383 WMI_AP_PS_PEER_PARAM_UAPSD,
2386 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2387 arvif->vdev_id, ret);
2391 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2393 WMI_AP_PS_PEER_PARAM_MAX_SP,
2396 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2397 arvif->vdev_id, ret);
2401 /* TODO setup this based on STA listen interval and
2402 * beacon interval. Currently we don't know
2403 * sta->listen_interval - mac80211 patch required.
2404 * Currently use 10 seconds
2406 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2407 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2410 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2411 arvif->vdev_id, ret);
2420 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2421 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2428 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2429 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2433 idx_limit = fls(mcs_map) - 1;
2437 switch (idx_limit) {
2438 case 0: /* fall through */
2439 case 1: /* fall through */
2440 case 2: /* fall through */
2441 case 3: /* fall through */
2442 case 4: /* fall through */
2443 case 5: /* fall through */
2444 case 6: /* fall through */
2446 /* see ath10k_mac_can_set_bitrate_mask() */
2450 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2453 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2456 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2459 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2463 tx_mcs_set &= ~(0x3 << (nss * 2));
2464 tx_mcs_set |= mcs << (nss * 2);
2470 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2471 struct ieee80211_vif *vif,
2472 struct ieee80211_sta *sta,
2473 struct wmi_peer_assoc_complete_arg *arg)
2475 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2476 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2477 struct cfg80211_chan_def def;
2478 enum nl80211_band band;
2479 const u16 *vht_mcs_mask;
2481 u8 max_nss, vht_mcs;
2484 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2487 if (!vht_cap->vht_supported)
2490 band = def.chan->band;
2491 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2493 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2496 arg->peer_flags |= ar->wmi.peer_flags->vht;
2498 if (def.chan->band == NL80211_BAND_2GHZ)
2499 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2501 arg->peer_vht_caps = vht_cap->cap;
2503 ampdu_factor = (vht_cap->cap &
2504 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2505 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2507 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2508 * zero in VHT IE. Using it would result in degraded throughput.
2509 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2510 * it if VHT max_mpdu is smaller.
2512 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2513 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2514 ampdu_factor)) - 1);
2516 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2517 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2519 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2520 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2522 /* Calculate peer NSS capability from VHT capabilities if STA
2525 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2526 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2529 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2533 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2534 arg->peer_vht_rates.rx_max_rate =
2535 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2536 arg->peer_vht_rates.rx_mcs_set =
2537 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2538 arg->peer_vht_rates.tx_max_rate =
2539 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2540 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2541 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2543 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2544 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2546 if (arg->peer_vht_rates.rx_max_rate &&
2547 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2548 switch (arg->peer_vht_rates.rx_max_rate) {
2550 /* Must be 2x2 at 160Mhz is all it can do. */
2551 arg->peer_bw_rxnss_override = 2;
2554 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2555 arg->peer_bw_rxnss_override = 1;
2561 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2562 struct ieee80211_vif *vif,
2563 struct ieee80211_sta *sta,
2564 struct wmi_peer_assoc_complete_arg *arg)
2566 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2568 switch (arvif->vdev_type) {
2569 case WMI_VDEV_TYPE_AP:
2571 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2573 if (sta->wme && sta->uapsd_queues) {
2574 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2575 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2578 case WMI_VDEV_TYPE_STA:
2580 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2582 case WMI_VDEV_TYPE_IBSS:
2584 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2590 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2591 sta->addr, !!(arg->peer_flags &
2592 arvif->ar->wmi.peer_flags->qos));
2595 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2597 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2598 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2601 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2602 struct ieee80211_sta *sta)
2604 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2605 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2606 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2607 return MODE_11AC_VHT160;
2608 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2609 return MODE_11AC_VHT80_80;
2611 /* not sure if this is a valid case? */
2612 return MODE_11AC_VHT160;
2616 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2617 return MODE_11AC_VHT80;
2619 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2620 return MODE_11AC_VHT40;
2622 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2623 return MODE_11AC_VHT20;
2625 return MODE_UNKNOWN;
2628 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2629 struct ieee80211_vif *vif,
2630 struct ieee80211_sta *sta,
2631 struct wmi_peer_assoc_complete_arg *arg)
2633 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2634 struct cfg80211_chan_def def;
2635 enum nl80211_band band;
2636 const u8 *ht_mcs_mask;
2637 const u16 *vht_mcs_mask;
2638 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2640 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2643 band = def.chan->band;
2644 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2645 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2648 case NL80211_BAND_2GHZ:
2649 if (sta->vht_cap.vht_supported &&
2650 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2651 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2652 phymode = MODE_11AC_VHT40;
2654 phymode = MODE_11AC_VHT20;
2655 } else if (sta->ht_cap.ht_supported &&
2656 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2657 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2658 phymode = MODE_11NG_HT40;
2660 phymode = MODE_11NG_HT20;
2661 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2668 case NL80211_BAND_5GHZ:
2672 if (sta->vht_cap.vht_supported &&
2673 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2674 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2675 } else if (sta->ht_cap.ht_supported &&
2676 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2677 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2678 phymode = MODE_11NA_HT40;
2680 phymode = MODE_11NA_HT20;
2690 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2691 sta->addr, ath10k_wmi_phymode_str(phymode));
2693 arg->peer_phymode = phymode;
2694 WARN_ON(phymode == MODE_UNKNOWN);
2697 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2698 struct ieee80211_vif *vif,
2699 struct ieee80211_sta *sta,
2700 struct wmi_peer_assoc_complete_arg *arg)
2702 lockdep_assert_held(&ar->conf_mutex);
2704 memset(arg, 0, sizeof(*arg));
2706 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2707 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2708 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2709 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2710 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2711 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2712 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2717 static const u32 ath10k_smps_map[] = {
2718 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2719 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2720 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2721 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2724 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2726 const struct ieee80211_sta_ht_cap *ht_cap)
2730 if (!ht_cap->ht_supported)
2733 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2734 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2736 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2739 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2740 WMI_PEER_SMPS_STATE,
2741 ath10k_smps_map[smps]);
2744 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2745 struct ieee80211_vif *vif,
2746 struct ieee80211_sta_vht_cap vht_cap)
2748 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2753 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2756 if (!(ar->vht_cap_info &
2757 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2758 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2759 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2760 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2763 param = ar->wmi.vdev_param->txbf;
2766 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2769 /* The following logic is correct. If a remote STA advertises support
2770 * for being a beamformer then we should enable us being a beamformee.
2773 if (ar->vht_cap_info &
2774 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2775 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2776 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2777 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2779 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2780 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2783 if (ar->vht_cap_info &
2784 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2785 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2786 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2787 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2789 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2790 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2793 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2794 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2796 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2797 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2799 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2801 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2809 /* can be called only in mac80211 callbacks due to `key_count` usage */
2810 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2811 struct ieee80211_vif *vif,
2812 struct ieee80211_bss_conf *bss_conf)
2814 struct ath10k *ar = hw->priv;
2815 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2816 struct ieee80211_sta_ht_cap ht_cap;
2817 struct ieee80211_sta_vht_cap vht_cap;
2818 struct wmi_peer_assoc_complete_arg peer_arg;
2819 struct ieee80211_sta *ap_sta;
2822 lockdep_assert_held(&ar->conf_mutex);
2824 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2825 arvif->vdev_id, arvif->bssid, arvif->aid);
2829 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2831 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2832 bss_conf->bssid, arvif->vdev_id);
2837 /* ap_sta must be accessed only within rcu section which must be left
2838 * before calling ath10k_setup_peer_smps() which might sleep.
2840 ht_cap = ap_sta->ht_cap;
2841 vht_cap = ap_sta->vht_cap;
2843 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2845 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2846 bss_conf->bssid, arvif->vdev_id, ret);
2853 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2855 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2856 bss_conf->bssid, arvif->vdev_id, ret);
2860 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2862 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2863 arvif->vdev_id, ret);
2867 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2869 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2870 arvif->vdev_id, bss_conf->bssid, ret);
2874 ath10k_dbg(ar, ATH10K_DBG_MAC,
2875 "mac vdev %d up (associated) bssid %pM aid %d\n",
2876 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2878 WARN_ON(arvif->is_up);
2880 arvif->aid = bss_conf->aid;
2881 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2883 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2885 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2886 arvif->vdev_id, ret);
2890 arvif->is_up = true;
2892 /* Workaround: Some firmware revisions (tested with qca6174
2893 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2894 * poked with peer param command.
2896 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2897 WMI_PEER_DUMMY_VAR, 1);
2899 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2900 arvif->bssid, arvif->vdev_id, ret);
2905 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2906 struct ieee80211_vif *vif)
2908 struct ath10k *ar = hw->priv;
2909 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2910 struct ieee80211_sta_vht_cap vht_cap = {};
2913 lockdep_assert_held(&ar->conf_mutex);
2915 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2916 arvif->vdev_id, arvif->bssid);
2918 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2920 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2921 arvif->vdev_id, ret);
2923 arvif->def_wep_key_idx = -1;
2925 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2927 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2928 arvif->vdev_id, ret);
2932 arvif->is_up = false;
2934 cancel_delayed_work_sync(&arvif->connection_loss_work);
2937 static int ath10k_station_assoc(struct ath10k *ar,
2938 struct ieee80211_vif *vif,
2939 struct ieee80211_sta *sta,
2942 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2943 struct wmi_peer_assoc_complete_arg peer_arg;
2946 lockdep_assert_held(&ar->conf_mutex);
2948 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2950 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2951 sta->addr, arvif->vdev_id, ret);
2955 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2957 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2958 sta->addr, arvif->vdev_id, ret);
2962 /* Re-assoc is run only to update supported rates for given station. It
2963 * doesn't make much sense to reconfigure the peer completely.
2966 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2969 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2970 arvif->vdev_id, ret);
2974 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2976 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2977 sta->addr, arvif->vdev_id, ret);
2982 arvif->num_legacy_stations++;
2983 ret = ath10k_recalc_rtscts_prot(arvif);
2985 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2986 arvif->vdev_id, ret);
2991 /* Plumb cached keys only for static WEP */
2992 if ((arvif->def_wep_key_idx != -1) && (!sta->tdls)) {
2993 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2995 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2996 arvif->vdev_id, ret);
3005 static int ath10k_station_disassoc(struct ath10k *ar,
3006 struct ieee80211_vif *vif,
3007 struct ieee80211_sta *sta)
3009 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3012 lockdep_assert_held(&ar->conf_mutex);
3015 arvif->num_legacy_stations--;
3016 ret = ath10k_recalc_rtscts_prot(arvif);
3018 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3019 arvif->vdev_id, ret);
3024 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3026 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3027 arvif->vdev_id, ret);
3038 static int ath10k_update_channel_list(struct ath10k *ar)
3040 struct ieee80211_hw *hw = ar->hw;
3041 struct ieee80211_supported_band **bands;
3042 enum nl80211_band band;
3043 struct ieee80211_channel *channel;
3044 struct wmi_scan_chan_list_arg arg = {0};
3045 struct wmi_channel_arg *ch;
3051 lockdep_assert_held(&ar->conf_mutex);
3053 bands = hw->wiphy->bands;
3054 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3058 for (i = 0; i < bands[band]->n_channels; i++) {
3059 if (bands[band]->channels[i].flags &
3060 IEEE80211_CHAN_DISABLED)
3067 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3068 arg.channels = kzalloc(len, GFP_KERNEL);
3073 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3077 for (i = 0; i < bands[band]->n_channels; i++) {
3078 channel = &bands[band]->channels[i];
3080 if (channel->flags & IEEE80211_CHAN_DISABLED)
3083 ch->allow_ht = true;
3085 /* FIXME: when should we really allow VHT? */
3086 ch->allow_vht = true;
3089 !(channel->flags & IEEE80211_CHAN_NO_IR);
3092 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3095 !!(channel->flags & IEEE80211_CHAN_RADAR);
3097 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3098 ch->passive = passive;
3100 /* the firmware is ignoring the "radar" flag of the
3101 * channel and is scanning actively using Probe Requests
3102 * on "Radar detection"/DFS channels which are not
3103 * marked as "available"
3105 ch->passive |= ch->chan_radar;
3107 ch->freq = channel->center_freq;
3108 ch->band_center_freq1 = channel->center_freq;
3110 ch->max_power = channel->max_power * 2;
3111 ch->max_reg_power = channel->max_reg_power * 2;
3112 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3113 ch->reg_class_id = 0; /* FIXME */
3115 /* FIXME: why use only legacy modes, why not any
3116 * HT/VHT modes? Would that even make any
3119 if (channel->band == NL80211_BAND_2GHZ)
3120 ch->mode = MODE_11G;
3122 ch->mode = MODE_11A;
3124 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3127 ath10k_dbg(ar, ATH10K_DBG_WMI,
3128 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3129 ch - arg.channels, arg.n_channels,
3130 ch->freq, ch->max_power, ch->max_reg_power,
3131 ch->max_antenna_gain, ch->mode);
3137 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3138 kfree(arg.channels);
3143 static enum wmi_dfs_region
3144 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3146 switch (dfs_region) {
3147 case NL80211_DFS_UNSET:
3148 return WMI_UNINIT_DFS_DOMAIN;
3149 case NL80211_DFS_FCC:
3150 return WMI_FCC_DFS_DOMAIN;
3151 case NL80211_DFS_ETSI:
3152 return WMI_ETSI_DFS_DOMAIN;
3153 case NL80211_DFS_JP:
3154 return WMI_MKK4_DFS_DOMAIN;
3156 return WMI_UNINIT_DFS_DOMAIN;
3159 static void ath10k_regd_update(struct ath10k *ar)
3161 struct reg_dmn_pair_mapping *regpair;
3163 enum wmi_dfs_region wmi_dfs_reg;
3164 enum nl80211_dfs_regions nl_dfs_reg;
3166 lockdep_assert_held(&ar->conf_mutex);
3168 ret = ath10k_update_channel_list(ar);
3170 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3172 regpair = ar->ath_common.regulatory.regpair;
3174 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3175 nl_dfs_reg = ar->dfs_detector->region;
3176 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3178 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3181 /* Target allows setting up per-band regdomain but ath_common provides
3182 * a combined one only
3184 ret = ath10k_wmi_pdev_set_regdomain(ar,
3185 regpair->reg_domain,
3186 regpair->reg_domain, /* 2ghz */
3187 regpair->reg_domain, /* 5ghz */
3188 regpair->reg_2ghz_ctl,
3189 regpair->reg_5ghz_ctl,
3192 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3195 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3196 struct ieee80211_supported_band *band)
3200 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3201 for (i = 0; i < band->n_channels; i++) {
3202 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3203 band->channels[i].center_freq > ar->high_5ghz_chan)
3204 band->channels[i].flags |=
3205 IEEE80211_CHAN_DISABLED;
3210 static void ath10k_reg_notifier(struct wiphy *wiphy,
3211 struct regulatory_request *request)
3213 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3214 struct ath10k *ar = hw->priv;
3217 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3219 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3220 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3221 request->dfs_region);
3222 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3223 request->dfs_region);
3225 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3226 request->dfs_region);
3229 mutex_lock(&ar->conf_mutex);
3230 if (ar->state == ATH10K_STATE_ON)
3231 ath10k_regd_update(ar);
3232 mutex_unlock(&ar->conf_mutex);
3234 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3235 ath10k_mac_update_channel_list(ar,
3236 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3239 static void ath10k_stop_radar_confirmation(struct ath10k *ar)
3241 spin_lock_bh(&ar->data_lock);
3242 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_STOPPED;
3243 spin_unlock_bh(&ar->data_lock);
3245 cancel_work_sync(&ar->radar_confirmation_work);
3252 enum ath10k_mac_tx_path {
3254 ATH10K_MAC_TX_HTT_MGMT,
3255 ATH10K_MAC_TX_WMI_MGMT,
3256 ATH10K_MAC_TX_UNKNOWN,
3259 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3261 lockdep_assert_held(&ar->htt.tx_lock);
3263 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3264 ar->tx_paused |= BIT(reason);
3265 ieee80211_stop_queues(ar->hw);
3268 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3269 struct ieee80211_vif *vif)
3271 struct ath10k *ar = data;
3272 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3274 if (arvif->tx_paused)
3277 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3280 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3282 lockdep_assert_held(&ar->htt.tx_lock);
3284 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3285 ar->tx_paused &= ~BIT(reason);
3290 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3291 IEEE80211_IFACE_ITER_RESUME_ALL,
3292 ath10k_mac_tx_unlock_iter,
3295 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3298 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3300 struct ath10k *ar = arvif->ar;
3302 lockdep_assert_held(&ar->htt.tx_lock);
3304 WARN_ON(reason >= BITS_PER_LONG);
3305 arvif->tx_paused |= BIT(reason);
3306 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3309 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3311 struct ath10k *ar = arvif->ar;
3313 lockdep_assert_held(&ar->htt.tx_lock);
3315 WARN_ON(reason >= BITS_PER_LONG);
3316 arvif->tx_paused &= ~BIT(reason);
3321 if (arvif->tx_paused)
3324 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3327 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3328 enum wmi_tlv_tx_pause_id pause_id,
3329 enum wmi_tlv_tx_pause_action action)
3331 struct ath10k *ar = arvif->ar;
3333 lockdep_assert_held(&ar->htt.tx_lock);
3336 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3337 ath10k_mac_vif_tx_lock(arvif, pause_id);
3339 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3340 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3343 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3344 "received unknown tx pause action %d on vdev %i, ignoring\n",
3345 action, arvif->vdev_id);
3350 struct ath10k_mac_tx_pause {
3352 enum wmi_tlv_tx_pause_id pause_id;
3353 enum wmi_tlv_tx_pause_action action;
3356 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3357 struct ieee80211_vif *vif)
3359 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3360 struct ath10k_mac_tx_pause *arg = data;
3362 if (arvif->vdev_id != arg->vdev_id)
3365 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3368 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3369 enum wmi_tlv_tx_pause_id pause_id,
3370 enum wmi_tlv_tx_pause_action action)
3372 struct ath10k_mac_tx_pause arg = {
3374 .pause_id = pause_id,
3378 spin_lock_bh(&ar->htt.tx_lock);
3379 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3380 IEEE80211_IFACE_ITER_RESUME_ALL,
3381 ath10k_mac_handle_tx_pause_iter,
3383 spin_unlock_bh(&ar->htt.tx_lock);
3386 static enum ath10k_hw_txrx_mode
3387 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3388 struct ieee80211_vif *vif,
3389 struct ieee80211_sta *sta,
3390 struct sk_buff *skb)
3392 const struct ieee80211_hdr *hdr = (void *)skb->data;
3393 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
3394 __le16 fc = hdr->frame_control;
3396 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3397 return ATH10K_HW_TXRX_RAW;
3399 if (ieee80211_is_mgmt(fc))
3400 return ATH10K_HW_TXRX_MGMT;
3404 * NullFunc frames are mostly used to ping if a client or AP are still
3405 * reachable and responsive. This implies tx status reports must be
3406 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3407 * come to a conclusion that the other end disappeared and tear down
3408 * BSS connection or it can never disconnect from BSS/client (which is
3411 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3412 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3413 * which seems to deliver correct tx reports for NullFunc frames. The
3414 * downside of using it is it ignores client powersave state so it can
3415 * end up disconnecting sleeping clients in AP mode. It should fix STA
3416 * mode though because AP don't sleep.
3418 if (ar->htt.target_version_major < 3 &&
3419 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3420 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3421 ar->running_fw->fw_file.fw_features))
3422 return ATH10K_HW_TXRX_MGMT;
3426 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3427 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3428 * to work with Ethernet txmode so use it.
3430 * FIXME: Check if raw mode works with TDLS.
3432 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3433 return ATH10K_HW_TXRX_ETHERNET;
3435 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) ||
3436 skb_cb->flags & ATH10K_SKB_F_RAW_TX)
3437 return ATH10K_HW_TXRX_RAW;
3439 return ATH10K_HW_TXRX_NATIVE_WIFI;
3442 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3443 struct sk_buff *skb)
3445 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3446 const struct ieee80211_hdr *hdr = (void *)skb->data;
3447 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3448 IEEE80211_TX_CTL_INJECTED;
3450 if (!ieee80211_has_protected(hdr->frame_control))
3453 if ((info->flags & mask) == mask)
3457 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3462 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3463 * Control in the header.
3465 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3467 struct ieee80211_hdr *hdr = (void *)skb->data;
3468 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3471 if (!ieee80211_is_data_qos(hdr->frame_control))
3474 qos_ctl = ieee80211_get_qos_ctl(hdr);
3475 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3476 skb->data, (void *)qos_ctl - (void *)skb->data);
3477 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3479 /* Some firmware revisions don't handle sending QoS NullFunc well.
3480 * These frames are mainly used for CQM purposes so it doesn't really
3481 * matter whether QoS NullFunc or NullFunc are sent.
3483 hdr = (void *)skb->data;
3484 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3485 cb->flags &= ~ATH10K_SKB_F_QOS;
3487 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3490 static void ath10k_tx_h_8023(struct sk_buff *skb)
3492 struct ieee80211_hdr *hdr;
3493 struct rfc1042_hdr *rfc1042;
3500 hdr = (void *)skb->data;
3501 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3502 rfc1042 = (void *)skb->data + hdrlen;
3504 ether_addr_copy(da, ieee80211_get_DA(hdr));
3505 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3506 type = rfc1042->snap_type;
3508 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3509 skb_push(skb, sizeof(*eth));
3511 eth = (void *)skb->data;
3512 ether_addr_copy(eth->h_dest, da);
3513 ether_addr_copy(eth->h_source, sa);
3514 eth->h_proto = type;
3517 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3518 struct ieee80211_vif *vif,
3519 struct sk_buff *skb)
3521 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3522 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3524 /* This is case only for P2P_GO */
3525 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3528 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3529 spin_lock_bh(&ar->data_lock);
3530 if (arvif->u.ap.noa_data)
3531 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3533 skb_put_data(skb, arvif->u.ap.noa_data,
3534 arvif->u.ap.noa_len);
3535 spin_unlock_bh(&ar->data_lock);
3539 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3540 struct ieee80211_vif *vif,
3541 struct ieee80211_txq *txq,
3542 struct sk_buff *skb, u16 airtime)
3544 struct ieee80211_hdr *hdr = (void *)skb->data;
3545 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3546 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3547 bool is_data = ieee80211_is_data(hdr->frame_control) ||
3548 ieee80211_is_data_qos(hdr->frame_control);
3551 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3552 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3554 if (ieee80211_is_mgmt(hdr->frame_control))
3555 cb->flags |= ATH10K_SKB_F_MGMT;
3557 if (ieee80211_is_data_qos(hdr->frame_control))
3558 cb->flags |= ATH10K_SKB_F_QOS;
3560 /* Data frames encrypted in software will be posted to firmware
3561 * with tx encap mode set to RAW. Ex: Multicast traffic generated
3562 * for a specific VLAN group will always be encrypted in software.
3564 if (is_data && ieee80211_has_protected(hdr->frame_control) &&
3565 !info->control.hw_key) {
3566 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3567 cb->flags |= ATH10K_SKB_F_RAW_TX;
3572 cb->airtime_est = airtime;
3575 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3577 /* FIXME: Not really sure since when the behaviour changed. At some
3578 * point new firmware stopped requiring creation of peer entries for
3579 * offchannel tx (and actually creating them causes issues with wmi-htc
3580 * tx credit replenishment and reliability). Assuming it's at least 3.4
3581 * because that's when the `freq` was introduced to TX_FRM HTT command.
3583 return (ar->htt.target_version_major >= 3 &&
3584 ar->htt.target_version_minor >= 4 &&
3585 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3588 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3590 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3593 spin_lock_bh(&ar->data_lock);
3595 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3596 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3601 __skb_queue_tail(q, skb);
3602 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3605 spin_unlock_bh(&ar->data_lock);
3610 static enum ath10k_mac_tx_path
3611 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3612 struct sk_buff *skb,
3613 enum ath10k_hw_txrx_mode txmode)
3616 case ATH10K_HW_TXRX_RAW:
3617 case ATH10K_HW_TXRX_NATIVE_WIFI:
3618 case ATH10K_HW_TXRX_ETHERNET:
3619 return ATH10K_MAC_TX_HTT;
3620 case ATH10K_HW_TXRX_MGMT:
3621 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3622 ar->running_fw->fw_file.fw_features) ||
3623 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3625 return ATH10K_MAC_TX_WMI_MGMT;
3626 else if (ar->htt.target_version_major >= 3)
3627 return ATH10K_MAC_TX_HTT;
3629 return ATH10K_MAC_TX_HTT_MGMT;
3632 return ATH10K_MAC_TX_UNKNOWN;
3635 static int ath10k_mac_tx_submit(struct ath10k *ar,
3636 enum ath10k_hw_txrx_mode txmode,
3637 enum ath10k_mac_tx_path txpath,
3638 struct sk_buff *skb)
3640 struct ath10k_htt *htt = &ar->htt;
3644 case ATH10K_MAC_TX_HTT:
3645 ret = ath10k_htt_tx(htt, txmode, skb);
3647 case ATH10K_MAC_TX_HTT_MGMT:
3648 ret = ath10k_htt_mgmt_tx(htt, skb);
3650 case ATH10K_MAC_TX_WMI_MGMT:
3651 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3653 case ATH10K_MAC_TX_UNKNOWN:
3660 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3662 ieee80211_free_txskb(ar->hw, skb);
3668 /* This function consumes the sk_buff regardless of return value as far as
3669 * caller is concerned so no freeing is necessary afterwards.
3671 static int ath10k_mac_tx(struct ath10k *ar,
3672 struct ieee80211_vif *vif,
3673 enum ath10k_hw_txrx_mode txmode,
3674 enum ath10k_mac_tx_path txpath,
3675 struct sk_buff *skb)
3677 struct ieee80211_hw *hw = ar->hw;
3678 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3679 const struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
3682 /* We should disable CCK RATE due to P2P */
3683 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3684 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3687 case ATH10K_HW_TXRX_MGMT:
3688 case ATH10K_HW_TXRX_NATIVE_WIFI:
3689 ath10k_tx_h_nwifi(hw, skb);
3690 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3691 ath10k_tx_h_seq_no(vif, skb);
3693 case ATH10K_HW_TXRX_ETHERNET:
3694 ath10k_tx_h_8023(skb);
3696 case ATH10K_HW_TXRX_RAW:
3697 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags) &&
3698 !(skb_cb->flags & ATH10K_SKB_F_RAW_TX)) {
3700 ieee80211_free_txskb(hw, skb);
3705 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3706 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3707 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3710 skb_queue_tail(&ar->offchan_tx_queue, skb);
3711 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3716 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3718 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3725 void ath10k_offchan_tx_purge(struct ath10k *ar)
3727 struct sk_buff *skb;
3730 skb = skb_dequeue(&ar->offchan_tx_queue);
3734 ieee80211_free_txskb(ar->hw, skb);
3738 void ath10k_offchan_tx_work(struct work_struct *work)
3740 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3741 struct ath10k_peer *peer;
3742 struct ath10k_vif *arvif;
3743 enum ath10k_hw_txrx_mode txmode;
3744 enum ath10k_mac_tx_path txpath;
3745 struct ieee80211_hdr *hdr;
3746 struct ieee80211_vif *vif;
3747 struct ieee80211_sta *sta;
3748 struct sk_buff *skb;
3749 const u8 *peer_addr;
3752 unsigned long time_left;
3753 bool tmp_peer_created = false;
3755 /* FW requirement: We must create a peer before FW will send out
3756 * an offchannel frame. Otherwise the frame will be stuck and
3757 * never transmitted. We delete the peer upon tx completion.
3758 * It is unlikely that a peer for offchannel tx will already be
3759 * present. However it may be in some rare cases so account for that.
3760 * Otherwise we might remove a legitimate peer and break stuff.
3764 skb = skb_dequeue(&ar->offchan_tx_queue);
3768 mutex_lock(&ar->conf_mutex);
3770 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3773 hdr = (struct ieee80211_hdr *)skb->data;
3774 peer_addr = ieee80211_get_DA(hdr);
3776 spin_lock_bh(&ar->data_lock);
3777 vdev_id = ar->scan.vdev_id;
3778 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3779 spin_unlock_bh(&ar->data_lock);
3782 /* FIXME: should this use ath10k_warn()? */
3783 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3784 peer_addr, vdev_id);
3787 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3789 WMI_PEER_TYPE_DEFAULT);
3791 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3792 peer_addr, vdev_id, ret);
3793 tmp_peer_created = (ret == 0);
3796 spin_lock_bh(&ar->data_lock);
3797 reinit_completion(&ar->offchan_tx_completed);
3798 ar->offchan_tx_skb = skb;
3799 spin_unlock_bh(&ar->data_lock);
3801 /* It's safe to access vif and sta - conf_mutex guarantees that
3802 * sta_state() and remove_interface() are locked exclusively
3803 * out wrt to this offchannel worker.
3805 arvif = ath10k_get_arvif(ar, vdev_id);
3808 sta = ieee80211_find_sta(vif, peer_addr);
3814 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3815 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3817 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
3819 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3825 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3827 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3830 if (!peer && tmp_peer_created) {
3831 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3833 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3834 peer_addr, vdev_id, ret);
3837 mutex_unlock(&ar->conf_mutex);
3841 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3843 struct sk_buff *skb;
3846 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3850 ieee80211_free_txskb(ar->hw, skb);
3854 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3856 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3857 struct sk_buff *skb;
3862 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3866 if (test_bit(ATH10K_FW_FEATURE_MGMT_TX_BY_REF,
3867 ar->running_fw->fw_file.fw_features)) {
3868 paddr = dma_map_single(ar->dev, skb->data,
3869 skb->len, DMA_TO_DEVICE);
3872 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3874 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3876 dma_unmap_single(ar->dev, paddr, skb->len,
3878 ieee80211_free_txskb(ar->hw, skb);
3881 ret = ath10k_wmi_mgmt_tx(ar, skb);
3883 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3885 ieee80211_free_txskb(ar->hw, skb);
3891 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3893 struct ath10k_txq *artxq;
3898 artxq = (void *)txq->drv_priv;
3899 INIT_LIST_HEAD(&artxq->list);
3902 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3904 struct ath10k_skb_cb *cb;
3905 struct sk_buff *msdu;
3911 spin_lock_bh(&ar->htt.tx_lock);
3912 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3913 cb = ATH10K_SKB_CB(msdu);
3917 spin_unlock_bh(&ar->htt.tx_lock);
3920 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3924 struct ath10k_peer *peer;
3926 lockdep_assert_held(&ar->data_lock);
3928 peer = ar->peer_map[peer_id];
3936 return peer->sta->txq[tid];
3938 return peer->vif->txq;
3943 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3944 struct ieee80211_txq *txq)
3946 struct ath10k *ar = hw->priv;
3947 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3949 /* No need to get locks */
3950 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3953 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3956 if (artxq->num_fw_queued < artxq->num_push_allowed)
3962 /* Return estimated airtime in microsecond, which is calculated using last
3963 * reported TX rate. This is just a rough estimation because host driver has no
3964 * knowledge of the actual transmit rate, retries or aggregation. If actual
3965 * airtime can be reported by firmware, then delta between estimated and actual
3966 * airtime can be adjusted from deficit.
3968 #define IEEE80211_ATF_OVERHEAD 100 /* IFS + some slot time */
3969 #define IEEE80211_ATF_OVERHEAD_IFS 16 /* IFS only */
3970 static u16 ath10k_mac_update_airtime(struct ath10k *ar,
3971 struct ieee80211_txq *txq,
3972 struct sk_buff *skb)
3974 struct ath10k_sta *arsta;
3978 if (!txq || !txq->sta)
3981 if (test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
3984 spin_lock_bh(&ar->data_lock);
3985 arsta = (struct ath10k_sta *)txq->sta->drv_priv;
3987 pktlen = skb->len + 38; /* Assume MAC header 30, SNAP 8 for most case */
3988 if (arsta->last_tx_bitrate) {
3989 /* airtime in us, last_tx_bitrate in 100kbps */
3990 airtime = (pktlen * 8 * (1000 / 100))
3991 / arsta->last_tx_bitrate;
3992 /* overhead for media access time and IFS */
3993 airtime += IEEE80211_ATF_OVERHEAD_IFS;
3995 /* This is mostly for throttle excessive BC/MC frames, and the
3996 * airtime/rate doesn't need be exact. Airtime of BC/MC frames
3997 * in 2G get some discount, which helps prevent very low rate
3998 * frames from being blocked for too long.
4000 airtime = (pktlen * 8 * (1000 / 100)) / 60; /* 6M */
4001 airtime += IEEE80211_ATF_OVERHEAD;
4003 spin_unlock_bh(&ar->data_lock);
4008 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
4009 struct ieee80211_txq *txq)
4011 struct ath10k *ar = hw->priv;
4012 struct ath10k_htt *htt = &ar->htt;
4013 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4014 struct ieee80211_vif *vif = txq->vif;
4015 struct ieee80211_sta *sta = txq->sta;
4016 enum ath10k_hw_txrx_mode txmode;
4017 enum ath10k_mac_tx_path txpath;
4018 struct sk_buff *skb;
4019 struct ieee80211_hdr *hdr;
4021 bool is_mgmt, is_presp;
4025 spin_lock_bh(&ar->htt.tx_lock);
4026 ret = ath10k_htt_tx_inc_pending(htt);
4027 spin_unlock_bh(&ar->htt.tx_lock);
4032 skb = ieee80211_tx_dequeue(hw, txq);
4034 spin_lock_bh(&ar->htt.tx_lock);
4035 ath10k_htt_tx_dec_pending(htt);
4036 spin_unlock_bh(&ar->htt.tx_lock);
4041 airtime = ath10k_mac_update_airtime(ar, txq, skb);
4042 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb, airtime);
4045 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4046 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4047 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4050 hdr = (struct ieee80211_hdr *)skb->data;
4051 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4053 spin_lock_bh(&ar->htt.tx_lock);
4054 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4057 ath10k_htt_tx_dec_pending(htt);
4058 spin_unlock_bh(&ar->htt.tx_lock);
4061 spin_unlock_bh(&ar->htt.tx_lock);
4064 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4065 if (unlikely(ret)) {
4066 ath10k_warn(ar, "failed to push frame: %d\n", ret);
4068 spin_lock_bh(&ar->htt.tx_lock);
4069 ath10k_htt_tx_dec_pending(htt);
4071 ath10k_htt_tx_mgmt_dec_pending(htt);
4072 spin_unlock_bh(&ar->htt.tx_lock);
4077 spin_lock_bh(&ar->htt.tx_lock);
4078 artxq->num_fw_queued++;
4079 spin_unlock_bh(&ar->htt.tx_lock);
4084 static int ath10k_mac_schedule_txq(struct ieee80211_hw *hw, u32 ac)
4086 struct ieee80211_txq *txq;
4089 ieee80211_txq_schedule_start(hw, ac);
4090 while ((txq = ieee80211_next_txq(hw, ac))) {
4091 while (ath10k_mac_tx_can_push(hw, txq)) {
4092 ret = ath10k_mac_tx_push_txq(hw, txq);
4096 ieee80211_return_txq(hw, txq, false);
4097 ath10k_htt_tx_txq_update(hw, txq);
4101 ieee80211_txq_schedule_end(hw, ac);
4106 void ath10k_mac_tx_push_pending(struct ath10k *ar)
4108 struct ieee80211_hw *hw = ar->hw;
4111 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4114 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
4118 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4119 if (ath10k_mac_schedule_txq(hw, ac) == -EBUSY)
4124 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4130 void __ath10k_scan_finish(struct ath10k *ar)
4132 lockdep_assert_held(&ar->data_lock);
4134 switch (ar->scan.state) {
4135 case ATH10K_SCAN_IDLE:
4137 case ATH10K_SCAN_RUNNING:
4138 case ATH10K_SCAN_ABORTING:
4139 if (!ar->scan.is_roc) {
4140 struct cfg80211_scan_info info = {
4141 .aborted = (ar->scan.state ==
4142 ATH10K_SCAN_ABORTING),
4145 ieee80211_scan_completed(ar->hw, &info);
4146 } else if (ar->scan.roc_notify) {
4147 ieee80211_remain_on_channel_expired(ar->hw);
4150 case ATH10K_SCAN_STARTING:
4151 ar->scan.state = ATH10K_SCAN_IDLE;
4152 ar->scan_channel = NULL;
4153 ar->scan.roc_freq = 0;
4154 ath10k_offchan_tx_purge(ar);
4155 cancel_delayed_work(&ar->scan.timeout);
4156 complete(&ar->scan.completed);
4161 void ath10k_scan_finish(struct ath10k *ar)
4163 spin_lock_bh(&ar->data_lock);
4164 __ath10k_scan_finish(ar);
4165 spin_unlock_bh(&ar->data_lock);
4168 static int ath10k_scan_stop(struct ath10k *ar)
4170 struct wmi_stop_scan_arg arg = {
4171 .req_id = 1, /* FIXME */
4172 .req_type = WMI_SCAN_STOP_ONE,
4173 .u.scan_id = ATH10K_SCAN_ID,
4177 lockdep_assert_held(&ar->conf_mutex);
4179 ret = ath10k_wmi_stop_scan(ar, &arg);
4181 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4185 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4187 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4189 } else if (ret > 0) {
4194 /* Scan state should be updated upon scan completion but in case
4195 * firmware fails to deliver the event (for whatever reason) it is
4196 * desired to clean up scan state anyway. Firmware may have just
4197 * dropped the scan completion event delivery due to transport pipe
4198 * being overflown with data and/or it can recover on its own before
4199 * next scan request is submitted.
4201 spin_lock_bh(&ar->data_lock);
4202 if (ar->scan.state != ATH10K_SCAN_IDLE)
4203 __ath10k_scan_finish(ar);
4204 spin_unlock_bh(&ar->data_lock);
4209 static void ath10k_scan_abort(struct ath10k *ar)
4213 lockdep_assert_held(&ar->conf_mutex);
4215 spin_lock_bh(&ar->data_lock);
4217 switch (ar->scan.state) {
4218 case ATH10K_SCAN_IDLE:
4219 /* This can happen if timeout worker kicked in and called
4220 * abortion while scan completion was being processed.
4223 case ATH10K_SCAN_STARTING:
4224 case ATH10K_SCAN_ABORTING:
4225 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4226 ath10k_scan_state_str(ar->scan.state),
4229 case ATH10K_SCAN_RUNNING:
4230 ar->scan.state = ATH10K_SCAN_ABORTING;
4231 spin_unlock_bh(&ar->data_lock);
4233 ret = ath10k_scan_stop(ar);
4235 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4237 spin_lock_bh(&ar->data_lock);
4241 spin_unlock_bh(&ar->data_lock);
4244 void ath10k_scan_timeout_work(struct work_struct *work)
4246 struct ath10k *ar = container_of(work, struct ath10k,
4249 mutex_lock(&ar->conf_mutex);
4250 ath10k_scan_abort(ar);
4251 mutex_unlock(&ar->conf_mutex);
4254 static int ath10k_start_scan(struct ath10k *ar,
4255 const struct wmi_start_scan_arg *arg)
4259 lockdep_assert_held(&ar->conf_mutex);
4261 ret = ath10k_wmi_start_scan(ar, arg);
4265 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4267 ret = ath10k_scan_stop(ar);
4269 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4274 /* If we failed to start the scan, return error code at
4275 * this point. This is probably due to some issue in the
4276 * firmware, but no need to wedge the driver due to that...
4278 spin_lock_bh(&ar->data_lock);
4279 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4280 spin_unlock_bh(&ar->data_lock);
4283 spin_unlock_bh(&ar->data_lock);
4288 /**********************/
4289 /* mac80211 callbacks */
4290 /**********************/
4292 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4293 struct ieee80211_tx_control *control,
4294 struct sk_buff *skb)
4296 struct ath10k *ar = hw->priv;
4297 struct ath10k_htt *htt = &ar->htt;
4298 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4299 struct ieee80211_vif *vif = info->control.vif;
4300 struct ieee80211_sta *sta = control->sta;
4301 struct ieee80211_txq *txq = NULL;
4302 struct ieee80211_hdr *hdr = (void *)skb->data;
4303 enum ath10k_hw_txrx_mode txmode;
4304 enum ath10k_mac_tx_path txpath;
4311 airtime = ath10k_mac_update_airtime(ar, txq, skb);
4312 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb, airtime);
4314 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4315 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4316 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4317 txpath == ATH10K_MAC_TX_HTT_MGMT);
4318 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4321 spin_lock_bh(&ar->htt.tx_lock);
4322 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4324 ret = ath10k_htt_tx_inc_pending(htt);
4326 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4328 spin_unlock_bh(&ar->htt.tx_lock);
4329 ieee80211_free_txskb(ar->hw, skb);
4333 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4335 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4337 ath10k_htt_tx_dec_pending(htt);
4338 spin_unlock_bh(&ar->htt.tx_lock);
4339 ieee80211_free_txskb(ar->hw, skb);
4342 spin_unlock_bh(&ar->htt.tx_lock);
4345 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4347 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4349 spin_lock_bh(&ar->htt.tx_lock);
4350 ath10k_htt_tx_dec_pending(htt);
4352 ath10k_htt_tx_mgmt_dec_pending(htt);
4353 spin_unlock_bh(&ar->htt.tx_lock);
4359 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4360 struct ieee80211_txq *txq)
4362 struct ath10k *ar = hw->priv;
4366 ath10k_htt_tx_txq_update(hw, txq);
4367 if (ar->htt.tx_q_state.mode != HTT_TX_MODE_SWITCH_PUSH)
4371 ieee80211_txq_schedule_start(hw, ac);
4372 txq = ieee80211_next_txq(hw, ac);
4376 while (ath10k_mac_tx_can_push(hw, txq)) {
4377 ret = ath10k_mac_tx_push_txq(hw, txq);
4381 ieee80211_return_txq(hw, txq, false);
4382 ath10k_htt_tx_txq_update(hw, txq);
4384 ieee80211_txq_schedule_end(hw, ac);
4387 /* Must not be called with conf_mutex held as workers can use that also. */
4388 void ath10k_drain_tx(struct ath10k *ar)
4390 /* make sure rcu-protected mac80211 tx path itself is drained */
4393 ath10k_offchan_tx_purge(ar);
4394 ath10k_mgmt_over_wmi_tx_purge(ar);
4396 cancel_work_sync(&ar->offchan_tx_work);
4397 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4400 void ath10k_halt(struct ath10k *ar)
4402 struct ath10k_vif *arvif;
4404 lockdep_assert_held(&ar->conf_mutex);
4406 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4407 ar->filter_flags = 0;
4408 ar->monitor = false;
4409 ar->monitor_arvif = NULL;
4411 if (ar->monitor_started)
4412 ath10k_monitor_stop(ar);
4414 ar->monitor_started = false;
4417 ath10k_scan_finish(ar);
4418 ath10k_peer_cleanup_all(ar);
4419 ath10k_stop_radar_confirmation(ar);
4420 ath10k_core_stop(ar);
4421 ath10k_hif_power_down(ar);
4423 spin_lock_bh(&ar->data_lock);
4424 list_for_each_entry(arvif, &ar->arvifs, list)
4425 ath10k_mac_vif_beacon_cleanup(arvif);
4426 spin_unlock_bh(&ar->data_lock);
4429 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4431 struct ath10k *ar = hw->priv;
4433 mutex_lock(&ar->conf_mutex);
4435 *tx_ant = ar->cfg_tx_chainmask;
4436 *rx_ant = ar->cfg_rx_chainmask;
4438 mutex_unlock(&ar->conf_mutex);
4443 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4445 /* It is not clear that allowing gaps in chainmask
4446 * is helpful. Probably it will not do what user
4447 * is hoping for, so warn in that case.
4449 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4452 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4456 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4458 int nsts = ar->vht_cap_info;
4460 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4461 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4463 /* If firmware does not deliver to host number of space-time
4464 * streams supported, assume it support up to 4 BF STS and return
4465 * the value for VHT CAP: nsts-1)
4473 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4475 int sound_dim = ar->vht_cap_info;
4477 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4478 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4480 /* If the sounding dimension is not advertised by the firmware,
4481 * let's use a default value of 1
4489 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4491 struct ieee80211_sta_vht_cap vht_cap = {0};
4492 struct ath10k_hw_params *hw = &ar->hw_params;
4497 vht_cap.vht_supported = 1;
4498 vht_cap.cap = ar->vht_cap_info;
4500 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4501 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4502 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4503 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4504 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4509 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4510 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4511 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4512 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4513 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4518 /* Currently the firmware seems to be buggy, don't enable 80+80
4519 * mode until that's resolved.
4521 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4522 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4523 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4526 for (i = 0; i < 8; i++) {
4527 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4528 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4530 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4533 if (ar->cfg_tx_chainmask <= 1)
4534 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4536 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4537 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4539 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4540 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4541 * user-space a clue if that is the case.
4543 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4544 (hw->vht160_mcs_rx_highest != 0 ||
4545 hw->vht160_mcs_tx_highest != 0)) {
4546 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4547 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4553 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4556 struct ieee80211_sta_ht_cap ht_cap = {0};
4558 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4561 ht_cap.ht_supported = 1;
4562 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4563 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4564 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4565 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4567 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4569 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4570 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4572 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4573 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4575 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4578 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4579 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4584 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4585 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4587 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4590 stbc = ar->ht_cap_info;
4591 stbc &= WMI_HT_CAP_RX_STBC;
4592 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4593 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4594 stbc &= IEEE80211_HT_CAP_RX_STBC;
4599 if (ar->ht_cap_info & WMI_HT_CAP_LDPC || (ar->ht_cap_info &
4600 WMI_HT_CAP_RX_LDPC && (ar->ht_cap_info & WMI_HT_CAP_TX_LDPC)))
4601 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4603 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4604 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4606 /* max AMSDU is implicitly taken from vht_cap_info */
4607 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4608 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4610 for (i = 0; i < ar->num_rf_chains; i++) {
4611 if (ar->cfg_rx_chainmask & BIT(i))
4612 ht_cap.mcs.rx_mask[i] = 0xFF;
4615 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4620 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4622 struct ieee80211_supported_band *band;
4623 struct ieee80211_sta_vht_cap vht_cap;
4624 struct ieee80211_sta_ht_cap ht_cap;
4626 ht_cap = ath10k_get_ht_cap(ar);
4627 vht_cap = ath10k_create_vht_cap(ar);
4629 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4630 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4631 band->ht_cap = ht_cap;
4633 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4634 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4635 band->ht_cap = ht_cap;
4636 band->vht_cap = vht_cap;
4640 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4644 lockdep_assert_held(&ar->conf_mutex);
4646 ath10k_check_chain_mask(ar, tx_ant, "tx");
4647 ath10k_check_chain_mask(ar, rx_ant, "rx");
4649 ar->cfg_tx_chainmask = tx_ant;
4650 ar->cfg_rx_chainmask = rx_ant;
4652 if ((ar->state != ATH10K_STATE_ON) &&
4653 (ar->state != ATH10K_STATE_RESTARTED))
4656 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4659 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4664 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4667 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4672 /* Reload HT/VHT capability */
4673 ath10k_mac_setup_ht_vht_cap(ar);
4678 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4680 struct ath10k *ar = hw->priv;
4683 mutex_lock(&ar->conf_mutex);
4684 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4685 mutex_unlock(&ar->conf_mutex);
4689 static int __ath10k_fetch_bb_timing_dt(struct ath10k *ar,
4690 struct wmi_bb_timing_cfg_arg *bb_timing)
4692 struct device_node *node;
4693 const char *fem_name;
4696 node = ar->dev->of_node;
4700 ret = of_property_read_string_index(node, "ext-fem-name", 0, &fem_name);
4705 * If external Front End module used in hardware, then default base band timing
4706 * parameter cannot be used since they were fine tuned for reference hardware,
4707 * so choosing different value suitable for that external FEM.
4709 if (!strcmp("microsemi-lx5586", fem_name)) {
4710 bb_timing->bb_tx_timing = 0x00;
4711 bb_timing->bb_xpa_timing = 0x0101;
4716 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot bb_tx_timing 0x%x bb_xpa_timing 0x%x\n",
4717 bb_timing->bb_tx_timing, bb_timing->bb_xpa_timing);
4721 static int ath10k_start(struct ieee80211_hw *hw)
4723 struct ath10k *ar = hw->priv;
4726 struct wmi_bb_timing_cfg_arg bb_timing = {0};
4729 * This makes sense only when restarting hw. It is harmless to call
4730 * unconditionally. This is necessary to make sure no HTT/WMI tx
4731 * commands will be submitted while restarting.
4733 ath10k_drain_tx(ar);
4735 mutex_lock(&ar->conf_mutex);
4737 switch (ar->state) {
4738 case ATH10K_STATE_OFF:
4739 ar->state = ATH10K_STATE_ON;
4741 case ATH10K_STATE_RESTARTING:
4742 ar->state = ATH10K_STATE_RESTARTED;
4744 case ATH10K_STATE_ON:
4745 case ATH10K_STATE_RESTARTED:
4746 case ATH10K_STATE_WEDGED:
4750 case ATH10K_STATE_UTF:
4755 ret = ath10k_hif_power_up(ar, ATH10K_FIRMWARE_MODE_NORMAL);
4757 ath10k_err(ar, "Could not init hif: %d\n", ret);
4761 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4762 &ar->normal_mode_fw);
4764 ath10k_err(ar, "Could not init core: %d\n", ret);
4765 goto err_power_down;
4768 param = ar->wmi.pdev_param->pmf_qos;
4769 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4771 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4775 param = ar->wmi.pdev_param->dynamic_bw;
4776 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4778 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4782 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
4783 ret = ath10k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
4785 ath10k_err(ar, "failed to set prob req oui: %i\n", ret);
4790 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4791 ret = ath10k_wmi_adaptive_qcs(ar, true);
4793 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4799 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4800 param = ar->wmi.pdev_param->burst_enable;
4801 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4803 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4808 param = ar->wmi.pdev_param->idle_ps_config;
4809 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4810 if (ret && ret != -EOPNOTSUPP) {
4811 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4815 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4818 * By default FW set ARP frames ac to voice (6). In that case ARP
4819 * exchange is not working properly for UAPSD enabled AP. ARP requests
4820 * which arrives with access category 0 are processed by network stack
4821 * and send back with access category 0, but FW changes access category
4822 * to 6. Set ARP frames access category to best effort (0) solves
4826 param = ar->wmi.pdev_param->arp_ac_override;
4827 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4829 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4834 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4835 ar->running_fw->fw_file.fw_features)) {
4836 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4837 WMI_CCA_DETECT_LEVEL_AUTO,
4838 WMI_CCA_DETECT_MARGIN_AUTO);
4840 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4846 param = ar->wmi.pdev_param->ani_enable;
4847 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4849 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4854 ar->ani_enabled = true;
4856 if (ath10k_peer_stats_enabled(ar)) {
4857 param = ar->wmi.pdev_param->peer_stats_update_period;
4858 ret = ath10k_wmi_pdev_set_param(ar, param,
4859 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4862 "failed to set peer stats period : %d\n",
4868 param = ar->wmi.pdev_param->enable_btcoex;
4869 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4870 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4871 ar->running_fw->fw_file.fw_features)) {
4872 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4875 "failed to set btcoex param: %d\n", ret);
4878 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4881 if (test_bit(WMI_SERVICE_BB_TIMING_CONFIG_SUPPORT, ar->wmi.svc_map)) {
4882 ret = __ath10k_fetch_bb_timing_dt(ar, &bb_timing);
4884 ret = ath10k_wmi_pdev_bb_timing(ar, &bb_timing);
4887 "failed to set bb timings: %d\n",
4894 ar->num_started_vdevs = 0;
4895 ath10k_regd_update(ar);
4897 ath10k_spectral_start(ar);
4898 ath10k_thermal_set_throttling(ar);
4900 ar->radar_conf_state = ATH10K_RADAR_CONFIRMATION_IDLE;
4902 mutex_unlock(&ar->conf_mutex);
4906 ath10k_core_stop(ar);
4909 ath10k_hif_power_down(ar);
4912 ar->state = ATH10K_STATE_OFF;
4915 mutex_unlock(&ar->conf_mutex);
4919 static void ath10k_stop(struct ieee80211_hw *hw)
4921 struct ath10k *ar = hw->priv;
4923 ath10k_drain_tx(ar);
4925 mutex_lock(&ar->conf_mutex);
4926 if (ar->state != ATH10K_STATE_OFF) {
4928 ar->state = ATH10K_STATE_OFF;
4930 mutex_unlock(&ar->conf_mutex);
4932 cancel_work_sync(&ar->set_coverage_class_work);
4933 cancel_delayed_work_sync(&ar->scan.timeout);
4934 cancel_work_sync(&ar->restart_work);
4937 static int ath10k_config_ps(struct ath10k *ar)
4939 struct ath10k_vif *arvif;
4942 lockdep_assert_held(&ar->conf_mutex);
4944 list_for_each_entry(arvif, &ar->arvifs, list) {
4945 ret = ath10k_mac_vif_setup_ps(arvif);
4947 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4955 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4960 lockdep_assert_held(&ar->conf_mutex);
4962 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4964 param = ar->wmi.pdev_param->txpower_limit2g;
4965 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4967 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4972 param = ar->wmi.pdev_param->txpower_limit5g;
4973 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4975 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4983 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4985 struct ath10k_vif *arvif;
4986 int ret, txpower = -1;
4988 lockdep_assert_held(&ar->conf_mutex);
4990 list_for_each_entry(arvif, &ar->arvifs, list) {
4991 if (arvif->txpower <= 0)
4995 txpower = arvif->txpower;
4997 txpower = min(txpower, arvif->txpower);
5003 ret = ath10k_mac_txpower_setup(ar, txpower);
5005 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
5013 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
5015 struct ath10k *ar = hw->priv;
5016 struct ieee80211_conf *conf = &hw->conf;
5019 mutex_lock(&ar->conf_mutex);
5021 if (changed & IEEE80211_CONF_CHANGE_PS)
5022 ath10k_config_ps(ar);
5024 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
5025 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
5026 ret = ath10k_monitor_recalc(ar);
5028 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5031 mutex_unlock(&ar->conf_mutex);
5035 static u32 get_nss_from_chainmask(u16 chain_mask)
5037 if ((chain_mask & 0xf) == 0xf)
5039 else if ((chain_mask & 0x7) == 0x7)
5041 else if ((chain_mask & 0x3) == 0x3)
5046 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
5049 struct ath10k *ar = arvif->ar;
5053 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
5056 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
5057 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
5058 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
5059 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
5061 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
5062 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
5063 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
5064 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
5069 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
5070 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
5072 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
5073 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
5074 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
5076 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
5077 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
5079 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
5080 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
5081 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
5083 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5084 ar->wmi.vdev_param->txbf, value);
5089 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
5090 * because we will send mgmt frames without CCK. This requirement
5091 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
5094 static int ath10k_add_interface(struct ieee80211_hw *hw,
5095 struct ieee80211_vif *vif)
5097 struct ath10k *ar = hw->priv;
5098 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5099 struct ath10k_peer *peer;
5100 enum wmi_sta_powersave_param param;
5107 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
5109 mutex_lock(&ar->conf_mutex);
5111 memset(arvif, 0, sizeof(*arvif));
5112 ath10k_mac_txq_init(vif->txq);
5117 INIT_LIST_HEAD(&arvif->list);
5118 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
5119 INIT_DELAYED_WORK(&arvif->connection_loss_work,
5120 ath10k_mac_vif_sta_connection_loss_work);
5122 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
5123 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
5124 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
5125 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
5126 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
5127 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
5130 if (ar->num_peers >= ar->max_num_peers) {
5131 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
5136 if (ar->free_vdev_map == 0) {
5137 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
5141 bit = __ffs64(ar->free_vdev_map);
5143 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
5144 bit, ar->free_vdev_map);
5146 arvif->vdev_id = bit;
5147 arvif->vdev_subtype =
5148 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
5150 switch (vif->type) {
5151 case NL80211_IFTYPE_P2P_DEVICE:
5152 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5153 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5154 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
5156 case NL80211_IFTYPE_UNSPECIFIED:
5157 case NL80211_IFTYPE_STATION:
5158 arvif->vdev_type = WMI_VDEV_TYPE_STA;
5160 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5161 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
5163 case NL80211_IFTYPE_ADHOC:
5164 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5166 case NL80211_IFTYPE_MESH_POINT:
5167 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5168 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5169 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5170 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5172 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5175 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5177 case NL80211_IFTYPE_AP:
5178 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5181 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5182 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5184 case NL80211_IFTYPE_MONITOR:
5185 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5192 /* Using vdev_id as queue number will make it very easy to do per-vif
5193 * tx queue locking. This shouldn't wrap due to interface combinations
5194 * but do a modulo for correctness sake and prevent using offchannel tx
5195 * queues for regular vif tx.
5197 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5198 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5199 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5201 /* Some firmware revisions don't wait for beacon tx completion before
5202 * sending another SWBA event. This could lead to hardware using old
5203 * (freed) beacon data in some cases, e.g. tx credit starvation
5204 * combined with missed TBTT. This is very very rare.
5206 * On non-IOMMU-enabled hosts this could be a possible security issue
5207 * because hw could beacon some random data on the air. On
5208 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5209 * device would crash.
5211 * Since there are no beacon tx completions (implicit nor explicit)
5212 * propagated to host the only workaround for this is to allocate a
5213 * DMA-coherent buffer for a lifetime of a vif and use it for all
5214 * beacon tx commands. Worst case for this approach is some beacons may
5215 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5217 if (vif->type == NL80211_IFTYPE_ADHOC ||
5218 vif->type == NL80211_IFTYPE_MESH_POINT ||
5219 vif->type == NL80211_IFTYPE_AP) {
5220 arvif->beacon_buf = dma_alloc_coherent(ar->dev,
5221 IEEE80211_MAX_FRAME_LEN,
5222 &arvif->beacon_paddr,
5224 if (!arvif->beacon_buf) {
5226 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5231 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5232 arvif->nohwcrypt = true;
5234 if (arvif->nohwcrypt &&
5235 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5236 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5240 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5241 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5242 arvif->beacon_buf ? "single-buf" : "per-skb");
5244 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5245 arvif->vdev_subtype, vif->addr);
5247 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5248 arvif->vdev_id, ret);
5252 if (test_bit(WMI_SERVICE_VDEV_DISABLE_4_ADDR_SRC_LRN_SUPPORT,
5254 vdev_param = ar->wmi.vdev_param->disable_4addr_src_lrn;
5255 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5256 WMI_VDEV_DISABLE_4_ADDR_SRC_LRN);
5257 if (ret && ret != -EOPNOTSUPP) {
5258 ath10k_warn(ar, "failed to disable 4addr src lrn vdev %i: %d\n",
5259 arvif->vdev_id, ret);
5263 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5264 spin_lock_bh(&ar->data_lock);
5265 list_add(&arvif->list, &ar->arvifs);
5266 spin_unlock_bh(&ar->data_lock);
5268 /* It makes no sense to have firmware do keepalives. mac80211 already
5269 * takes care of this with idle connection polling.
5271 ret = ath10k_mac_vif_disable_keepalive(arvif);
5273 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5274 arvif->vdev_id, ret);
5275 goto err_vdev_delete;
5278 arvif->def_wep_key_idx = -1;
5280 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5281 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5282 ATH10K_HW_TXRX_NATIVE_WIFI);
5283 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5284 if (ret && ret != -EOPNOTSUPP) {
5285 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5286 arvif->vdev_id, ret);
5287 goto err_vdev_delete;
5290 /* Configuring number of spatial stream for monitor interface is causing
5291 * target assert in qca9888 and qca6174.
5293 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5294 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5296 vdev_param = ar->wmi.vdev_param->nss;
5297 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5300 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5301 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5303 goto err_vdev_delete;
5307 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5308 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5309 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5310 vif->addr, WMI_PEER_TYPE_DEFAULT);
5312 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5313 arvif->vdev_id, ret);
5314 goto err_vdev_delete;
5317 spin_lock_bh(&ar->data_lock);
5319 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5321 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5322 vif->addr, arvif->vdev_id);
5323 spin_unlock_bh(&ar->data_lock);
5325 goto err_peer_delete;
5328 arvif->peer_id = find_first_bit(peer->peer_ids,
5329 ATH10K_MAX_NUM_PEER_IDS);
5331 spin_unlock_bh(&ar->data_lock);
5333 arvif->peer_id = HTT_INVALID_PEERID;
5336 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5337 ret = ath10k_mac_set_kickout(arvif);
5339 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5340 arvif->vdev_id, ret);
5341 goto err_peer_delete;
5345 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5346 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5347 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5348 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5351 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5352 arvif->vdev_id, ret);
5353 goto err_peer_delete;
5356 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5358 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5359 arvif->vdev_id, ret);
5360 goto err_peer_delete;
5363 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5365 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5366 arvif->vdev_id, ret);
5367 goto err_peer_delete;
5371 ret = ath10k_mac_set_txbf_conf(arvif);
5373 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5374 arvif->vdev_id, ret);
5375 goto err_peer_delete;
5378 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5380 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5381 arvif->vdev_id, ret);
5382 goto err_peer_delete;
5385 arvif->txpower = vif->bss_conf.txpower;
5386 ret = ath10k_mac_txpower_recalc(ar);
5388 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5389 goto err_peer_delete;
5392 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
5393 vdev_param = ar->wmi.vdev_param->rtt_responder_role;
5394 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5395 arvif->ftm_responder);
5397 /* It is harmless to not set FTM role. Do not warn */
5398 if (ret && ret != -EOPNOTSUPP)
5399 ath10k_warn(ar, "failed to set vdev %i FTM Responder: %d\n",
5400 arvif->vdev_id, ret);
5403 if (vif->type == NL80211_IFTYPE_MONITOR) {
5404 ar->monitor_arvif = arvif;
5405 ret = ath10k_monitor_recalc(ar);
5407 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5408 goto err_peer_delete;
5412 spin_lock_bh(&ar->htt.tx_lock);
5414 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5415 spin_unlock_bh(&ar->htt.tx_lock);
5417 mutex_unlock(&ar->conf_mutex);
5421 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5422 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5423 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5426 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5427 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5428 spin_lock_bh(&ar->data_lock);
5429 list_del(&arvif->list);
5430 spin_unlock_bh(&ar->data_lock);
5433 if (arvif->beacon_buf) {
5434 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5435 arvif->beacon_buf, arvif->beacon_paddr);
5436 arvif->beacon_buf = NULL;
5439 mutex_unlock(&ar->conf_mutex);
5444 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5448 for (i = 0; i < BITS_PER_LONG; i++)
5449 ath10k_mac_vif_tx_unlock(arvif, i);
5452 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5453 struct ieee80211_vif *vif)
5455 struct ath10k *ar = hw->priv;
5456 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5457 struct ath10k_peer *peer;
5461 cancel_work_sync(&arvif->ap_csa_work);
5462 cancel_delayed_work_sync(&arvif->connection_loss_work);
5464 mutex_lock(&ar->conf_mutex);
5466 spin_lock_bh(&ar->data_lock);
5467 ath10k_mac_vif_beacon_cleanup(arvif);
5468 spin_unlock_bh(&ar->data_lock);
5470 ret = ath10k_spectral_vif_stop(arvif);
5472 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5473 arvif->vdev_id, ret);
5475 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5476 spin_lock_bh(&ar->data_lock);
5477 list_del(&arvif->list);
5478 spin_unlock_bh(&ar->data_lock);
5480 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5481 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5482 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5485 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5486 arvif->vdev_id, ret);
5488 kfree(arvif->u.ap.noa_data);
5491 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5494 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5496 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5497 arvif->vdev_id, ret);
5499 /* Some firmware revisions don't notify host about self-peer removal
5500 * until after associated vdev is deleted.
5502 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5503 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5504 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5507 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5508 arvif->vdev_id, ret);
5510 spin_lock_bh(&ar->data_lock);
5512 spin_unlock_bh(&ar->data_lock);
5515 spin_lock_bh(&ar->data_lock);
5516 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5517 peer = ar->peer_map[i];
5521 if (peer->vif == vif) {
5522 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5523 vif->addr, arvif->vdev_id);
5527 spin_unlock_bh(&ar->data_lock);
5529 ath10k_peer_cleanup(ar, arvif->vdev_id);
5530 ath10k_mac_txq_unref(ar, vif->txq);
5532 if (vif->type == NL80211_IFTYPE_MONITOR) {
5533 ar->monitor_arvif = NULL;
5534 ret = ath10k_monitor_recalc(ar);
5536 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5539 ret = ath10k_mac_txpower_recalc(ar);
5541 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5543 spin_lock_bh(&ar->htt.tx_lock);
5544 ath10k_mac_vif_tx_unlock_all(arvif);
5545 spin_unlock_bh(&ar->htt.tx_lock);
5547 ath10k_mac_txq_unref(ar, vif->txq);
5549 mutex_unlock(&ar->conf_mutex);
5553 * FIXME: Has to be verified.
5555 #define SUPPORTED_FILTERS \
5560 FIF_BCN_PRBRESP_PROMISC | \
5564 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5565 unsigned int changed_flags,
5566 unsigned int *total_flags,
5569 struct ath10k *ar = hw->priv;
5572 mutex_lock(&ar->conf_mutex);
5574 changed_flags &= SUPPORTED_FILTERS;
5575 *total_flags &= SUPPORTED_FILTERS;
5576 ar->filter_flags = *total_flags;
5578 ret = ath10k_monitor_recalc(ar);
5580 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5582 mutex_unlock(&ar->conf_mutex);
5585 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5586 struct ieee80211_vif *vif,
5587 struct ieee80211_bss_conf *info,
5590 struct ath10k *ar = hw->priv;
5591 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5592 struct cfg80211_chan_def def;
5593 u32 vdev_param, pdev_param, slottime, preamble;
5594 u16 bitrate, hw_value;
5595 u8 rate, basic_rate_idx, rateidx;
5596 int ret = 0, hw_rate_code, mcast_rate;
5597 enum nl80211_band band;
5598 const struct ieee80211_supported_band *sband;
5600 mutex_lock(&ar->conf_mutex);
5602 if (changed & BSS_CHANGED_IBSS)
5603 ath10k_control_ibss(arvif, info, vif->addr);
5605 if (changed & BSS_CHANGED_BEACON_INT) {
5606 arvif->beacon_interval = info->beacon_int;
5607 vdev_param = ar->wmi.vdev_param->beacon_interval;
5608 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5609 arvif->beacon_interval);
5610 ath10k_dbg(ar, ATH10K_DBG_MAC,
5611 "mac vdev %d beacon_interval %d\n",
5612 arvif->vdev_id, arvif->beacon_interval);
5615 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5616 arvif->vdev_id, ret);
5619 if (changed & BSS_CHANGED_BEACON) {
5620 ath10k_dbg(ar, ATH10K_DBG_MAC,
5621 "vdev %d set beacon tx mode to staggered\n",
5624 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5625 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5626 WMI_BEACON_STAGGERED_MODE);
5628 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5629 arvif->vdev_id, ret);
5631 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5633 ath10k_warn(ar, "failed to update beacon template: %d\n",
5636 if (ieee80211_vif_is_mesh(vif)) {
5637 /* mesh doesn't use SSID but firmware needs it */
5638 strncpy(arvif->u.ap.ssid, "mesh",
5639 sizeof(arvif->u.ap.ssid));
5640 arvif->u.ap.ssid_len = 4;
5644 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5645 ret = ath10k_mac_setup_prb_tmpl(arvif);
5647 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5648 arvif->vdev_id, ret);
5651 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5652 arvif->dtim_period = info->dtim_period;
5654 ath10k_dbg(ar, ATH10K_DBG_MAC,
5655 "mac vdev %d dtim_period %d\n",
5656 arvif->vdev_id, arvif->dtim_period);
5658 vdev_param = ar->wmi.vdev_param->dtim_period;
5659 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5660 arvif->dtim_period);
5662 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5663 arvif->vdev_id, ret);
5666 if (changed & BSS_CHANGED_SSID &&
5667 vif->type == NL80211_IFTYPE_AP) {
5668 arvif->u.ap.ssid_len = info->ssid_len;
5670 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5671 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5674 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5675 ether_addr_copy(arvif->bssid, info->bssid);
5677 if (changed & BSS_CHANGED_FTM_RESPONDER &&
5678 arvif->ftm_responder != info->ftm_responder &&
5679 test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map)) {
5680 arvif->ftm_responder = info->ftm_responder;
5682 vdev_param = ar->wmi.vdev_param->rtt_responder_role;
5683 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5684 arvif->ftm_responder);
5686 ath10k_dbg(ar, ATH10K_DBG_MAC,
5687 "mac vdev %d ftm_responder %d:ret %d\n",
5688 arvif->vdev_id, arvif->ftm_responder, ret);
5691 if (changed & BSS_CHANGED_BEACON_ENABLED)
5692 ath10k_control_beaconing(arvif, info);
5694 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5695 arvif->use_cts_prot = info->use_cts_prot;
5697 ret = ath10k_recalc_rtscts_prot(arvif);
5699 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5700 arvif->vdev_id, ret);
5702 if (ath10k_mac_can_set_cts_prot(arvif)) {
5703 ret = ath10k_mac_set_cts_prot(arvif);
5705 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5706 arvif->vdev_id, ret);
5710 if (changed & BSS_CHANGED_ERP_SLOT) {
5711 if (info->use_short_slot)
5712 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5715 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5717 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5718 arvif->vdev_id, slottime);
5720 vdev_param = ar->wmi.vdev_param->slot_time;
5721 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5724 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5725 arvif->vdev_id, ret);
5728 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5729 if (info->use_short_preamble)
5730 preamble = WMI_VDEV_PREAMBLE_SHORT;
5732 preamble = WMI_VDEV_PREAMBLE_LONG;
5734 ath10k_dbg(ar, ATH10K_DBG_MAC,
5735 "mac vdev %d preamble %dn",
5736 arvif->vdev_id, preamble);
5738 vdev_param = ar->wmi.vdev_param->preamble;
5739 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5742 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5743 arvif->vdev_id, ret);
5746 if (changed & BSS_CHANGED_ASSOC) {
5748 /* Workaround: Make sure monitor vdev is not running
5749 * when associating to prevent some firmware revisions
5750 * (e.g. 10.1 and 10.2) from crashing.
5752 if (ar->monitor_started)
5753 ath10k_monitor_stop(ar);
5754 ath10k_bss_assoc(hw, vif, info);
5755 ath10k_monitor_recalc(ar);
5757 ath10k_bss_disassoc(hw, vif);
5761 if (changed & BSS_CHANGED_TXPOWER) {
5762 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5763 arvif->vdev_id, info->txpower);
5765 arvif->txpower = info->txpower;
5766 ret = ath10k_mac_txpower_recalc(ar);
5768 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5771 if (changed & BSS_CHANGED_PS) {
5772 arvif->ps = vif->bss_conf.ps;
5774 ret = ath10k_config_ps(ar);
5776 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5777 arvif->vdev_id, ret);
5780 if (changed & BSS_CHANGED_MCAST_RATE &&
5781 !ath10k_mac_vif_chan(arvif->vif, &def)) {
5782 band = def.chan->band;
5783 mcast_rate = vif->bss_conf.mcast_rate[band];
5785 rateidx = mcast_rate - 1;
5787 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
5789 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
5790 rateidx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
5792 bitrate = ath10k_wmi_legacy_rates[rateidx].bitrate;
5793 hw_value = ath10k_wmi_legacy_rates[rateidx].hw_value;
5794 if (ath10k_mac_bitrate_is_cck(bitrate))
5795 preamble = WMI_RATE_PREAMBLE_CCK;
5797 preamble = WMI_RATE_PREAMBLE_OFDM;
5799 rate = ATH10K_HW_RATECODE(hw_value, 0, preamble);
5801 ath10k_dbg(ar, ATH10K_DBG_MAC,
5802 "mac vdev %d mcast_rate %x\n",
5803 arvif->vdev_id, rate);
5805 vdev_param = ar->wmi.vdev_param->mcast_data_rate;
5806 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5810 "failed to set mcast rate on vdev %i: %d\n",
5811 arvif->vdev_id, ret);
5813 vdev_param = ar->wmi.vdev_param->bcast_data_rate;
5814 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
5818 "failed to set bcast rate on vdev %i: %d\n",
5819 arvif->vdev_id, ret);
5822 if (changed & BSS_CHANGED_BASIC_RATES) {
5823 if (ath10k_mac_vif_chan(vif, &def)) {
5824 mutex_unlock(&ar->conf_mutex);
5828 sband = ar->hw->wiphy->bands[def.chan->band];
5829 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
5830 bitrate = sband->bitrates[basic_rate_idx].bitrate;
5832 hw_rate_code = ath10k_mac_get_rate_hw_value(bitrate);
5833 if (hw_rate_code < 0) {
5834 ath10k_warn(ar, "bitrate not supported %d\n", bitrate);
5835 mutex_unlock(&ar->conf_mutex);
5839 vdev_param = ar->wmi.vdev_param->mgmt_rate;
5840 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5843 ath10k_warn(ar, "failed to set mgmt tx rate %d\n", ret);
5846 mutex_unlock(&ar->conf_mutex);
5849 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5851 struct ath10k *ar = hw->priv;
5853 /* This function should never be called if setting the coverage class
5854 * is not supported on this hardware.
5856 if (!ar->hw_params.hw_ops->set_coverage_class) {
5860 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5863 struct ath10k_mac_tdls_iter_data {
5864 u32 num_tdls_stations;
5865 struct ieee80211_vif *curr_vif;
5868 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5869 struct ieee80211_sta *sta)
5871 struct ath10k_mac_tdls_iter_data *iter_data = data;
5872 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5873 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5875 if (sta->tdls && sta_vif == iter_data->curr_vif)
5876 iter_data->num_tdls_stations++;
5879 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5880 struct ieee80211_vif *vif)
5882 struct ath10k_mac_tdls_iter_data data = {};
5884 data.curr_vif = vif;
5886 ieee80211_iterate_stations_atomic(hw,
5887 ath10k_mac_tdls_vif_stations_count_iter,
5889 return data.num_tdls_stations;
5892 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5893 struct ieee80211_vif *vif,
5894 struct ieee80211_scan_request *hw_req)
5896 struct ath10k *ar = hw->priv;
5897 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5898 struct cfg80211_scan_request *req = &hw_req->req;
5899 struct wmi_start_scan_arg arg;
5904 mutex_lock(&ar->conf_mutex);
5906 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
5911 spin_lock_bh(&ar->data_lock);
5912 switch (ar->scan.state) {
5913 case ATH10K_SCAN_IDLE:
5914 reinit_completion(&ar->scan.started);
5915 reinit_completion(&ar->scan.completed);
5916 ar->scan.state = ATH10K_SCAN_STARTING;
5917 ar->scan.is_roc = false;
5918 ar->scan.vdev_id = arvif->vdev_id;
5921 case ATH10K_SCAN_STARTING:
5922 case ATH10K_SCAN_RUNNING:
5923 case ATH10K_SCAN_ABORTING:
5927 spin_unlock_bh(&ar->data_lock);
5932 memset(&arg, 0, sizeof(arg));
5933 ath10k_wmi_start_scan_init(ar, &arg);
5934 arg.vdev_id = arvif->vdev_id;
5935 arg.scan_id = ATH10K_SCAN_ID;
5938 arg.ie_len = req->ie_len;
5939 memcpy(arg.ie, req->ie, arg.ie_len);
5943 arg.n_ssids = req->n_ssids;
5944 for (i = 0; i < arg.n_ssids; i++) {
5945 arg.ssids[i].len = req->ssids[i].ssid_len;
5946 arg.ssids[i].ssid = req->ssids[i].ssid;
5949 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5952 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5953 arg.scan_ctrl_flags |= WMI_SCAN_ADD_SPOOFED_MAC_IN_PROBE_REQ;
5954 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
5955 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
5958 if (req->n_channels) {
5959 arg.n_channels = req->n_channels;
5960 for (i = 0; i < arg.n_channels; i++)
5961 arg.channels[i] = req->channels[i]->center_freq;
5964 /* if duration is set, default dwell times will be overwritten */
5965 if (req->duration) {
5966 arg.dwell_time_active = req->duration;
5967 arg.dwell_time_passive = req->duration;
5968 arg.burst_duration_ms = req->duration;
5970 scan_timeout = min_t(u32, arg.max_rest_time *
5971 (arg.n_channels - 1) + (req->duration +
5972 ATH10K_SCAN_CHANNEL_SWITCH_WMI_EVT_OVERHEAD) *
5973 arg.n_channels, arg.max_scan_time + 200);
5976 /* Add a 200ms margin to account for event/command processing */
5977 scan_timeout = arg.max_scan_time + 200;
5980 ret = ath10k_start_scan(ar, &arg);
5982 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5983 spin_lock_bh(&ar->data_lock);
5984 ar->scan.state = ATH10K_SCAN_IDLE;
5985 spin_unlock_bh(&ar->data_lock);
5988 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5989 msecs_to_jiffies(scan_timeout));
5992 mutex_unlock(&ar->conf_mutex);
5996 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5997 struct ieee80211_vif *vif)
5999 struct ath10k *ar = hw->priv;
6001 mutex_lock(&ar->conf_mutex);
6002 ath10k_scan_abort(ar);
6003 mutex_unlock(&ar->conf_mutex);
6005 cancel_delayed_work_sync(&ar->scan.timeout);
6008 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
6009 struct ath10k_vif *arvif,
6010 enum set_key_cmd cmd,
6011 struct ieee80211_key_conf *key)
6013 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
6016 /* 10.1 firmware branch requires default key index to be set to group
6017 * key index after installing it. Otherwise FW/HW Txes corrupted
6018 * frames with multi-vif APs. This is not required for main firmware
6019 * branch (e.g. 636).
6021 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
6023 * FIXME: It remains unknown if this is required for multi-vif STA
6024 * interfaces on 10.1.
6027 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
6028 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
6031 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
6034 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
6037 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6043 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
6046 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
6047 arvif->vdev_id, ret);
6050 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6051 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
6052 struct ieee80211_key_conf *key)
6054 struct ath10k *ar = hw->priv;
6055 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6056 struct ath10k_peer *peer;
6057 const u8 *peer_addr;
6058 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
6059 key->cipher == WLAN_CIPHER_SUITE_WEP104;
6065 /* this one needs to be done in software */
6066 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
6067 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
6068 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
6069 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
6072 if (arvif->nohwcrypt)
6075 if (key->keyidx > WMI_MAX_KEY_INDEX)
6078 mutex_lock(&ar->conf_mutex);
6081 peer_addr = sta->addr;
6082 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6083 peer_addr = vif->bss_conf.bssid;
6085 peer_addr = vif->addr;
6087 key->hw_key_idx = key->keyidx;
6091 arvif->wep_keys[key->keyidx] = key;
6093 arvif->wep_keys[key->keyidx] = NULL;
6096 /* the peer should not disappear in mid-way (unless FW goes awry) since
6097 * we already hold conf_mutex. we just make sure its there now.
6099 spin_lock_bh(&ar->data_lock);
6100 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6101 spin_unlock_bh(&ar->data_lock);
6104 if (cmd == SET_KEY) {
6105 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
6110 /* if the peer doesn't exist there is no key to disable anymore */
6115 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
6116 flags |= WMI_KEY_PAIRWISE;
6118 flags |= WMI_KEY_GROUP;
6121 if (cmd == DISABLE_KEY)
6122 ath10k_clear_vdev_key(arvif, key);
6124 /* When WEP keys are uploaded it's possible that there are
6125 * stations associated already (e.g. when merging) without any
6126 * keys. Static WEP needs an explicit per-peer key upload.
6128 if (vif->type == NL80211_IFTYPE_ADHOC &&
6130 ath10k_mac_vif_update_wep_key(arvif, key);
6132 /* 802.1x never sets the def_wep_key_idx so each set_key()
6133 * call changes default tx key.
6135 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
6136 * after first set_key().
6138 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
6139 flags |= WMI_KEY_TX_USAGE;
6142 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
6145 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
6146 arvif->vdev_id, peer_addr, ret);
6150 /* mac80211 sets static WEP keys as groupwise while firmware requires
6151 * them to be installed twice as both pairwise and groupwise.
6153 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
6155 flags2 &= ~WMI_KEY_GROUP;
6156 flags2 |= WMI_KEY_PAIRWISE;
6158 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
6161 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
6162 arvif->vdev_id, peer_addr, ret);
6163 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
6167 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
6168 arvif->vdev_id, peer_addr, ret2);
6174 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
6176 spin_lock_bh(&ar->data_lock);
6177 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
6178 if (peer && cmd == SET_KEY)
6179 peer->keys[key->keyidx] = key;
6180 else if (peer && cmd == DISABLE_KEY)
6181 peer->keys[key->keyidx] = NULL;
6182 else if (peer == NULL)
6183 /* impossible unless FW goes crazy */
6184 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
6185 spin_unlock_bh(&ar->data_lock);
6187 if (sta && sta->tdls)
6188 ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6189 WMI_PEER_AUTHORIZE, 1);
6192 mutex_unlock(&ar->conf_mutex);
6196 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
6197 struct ieee80211_vif *vif,
6200 struct ath10k *ar = hw->priv;
6201 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6204 mutex_lock(&arvif->ar->conf_mutex);
6206 if (arvif->ar->state != ATH10K_STATE_ON)
6209 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
6210 arvif->vdev_id, keyidx);
6212 ret = ath10k_wmi_vdev_set_param(arvif->ar,
6214 arvif->ar->wmi.vdev_param->def_keyid,
6218 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
6224 arvif->def_wep_key_idx = keyidx;
6227 mutex_unlock(&arvif->ar->conf_mutex);
6230 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
6233 struct ath10k_vif *arvif;
6234 struct ath10k_sta *arsta;
6235 struct ieee80211_sta *sta;
6236 struct cfg80211_chan_def def;
6237 enum nl80211_band band;
6238 const u8 *ht_mcs_mask;
6239 const u16 *vht_mcs_mask;
6240 u32 changed, bw, nss, smps;
6243 arsta = container_of(wk, struct ath10k_sta, update_wk);
6244 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
6245 arvif = arsta->arvif;
6248 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
6251 band = def.chan->band;
6252 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
6253 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
6255 spin_lock_bh(&ar->data_lock);
6257 changed = arsta->changed;
6264 spin_unlock_bh(&ar->data_lock);
6266 mutex_lock(&ar->conf_mutex);
6268 nss = max_t(u32, 1, nss);
6269 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6270 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6272 if (changed & IEEE80211_RC_BW_CHANGED) {
6273 enum wmi_phy_mode mode;
6275 mode = chan_to_phymode(&def);
6276 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
6277 sta->addr, bw, mode);
6279 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6280 WMI_PEER_PHYMODE, mode);
6282 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
6283 sta->addr, mode, err);
6287 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6288 WMI_PEER_CHAN_WIDTH, bw);
6290 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
6291 sta->addr, bw, err);
6294 if (changed & IEEE80211_RC_NSS_CHANGED) {
6295 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
6298 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6301 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
6302 sta->addr, nss, err);
6305 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6306 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
6309 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
6310 WMI_PEER_SMPS_STATE, smps);
6312 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
6313 sta->addr, smps, err);
6316 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
6317 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
6320 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
6322 ath10k_warn(ar, "failed to reassociate station: %pM\n",
6327 mutex_unlock(&ar->conf_mutex);
6330 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
6331 struct ieee80211_sta *sta)
6333 struct ath10k *ar = arvif->ar;
6335 lockdep_assert_held(&ar->conf_mutex);
6337 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6340 if (ar->num_stations >= ar->max_num_stations)
6348 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6349 struct ieee80211_sta *sta)
6351 struct ath10k *ar = arvif->ar;
6353 lockdep_assert_held(&ar->conf_mutex);
6355 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6361 static int ath10k_sta_state(struct ieee80211_hw *hw,
6362 struct ieee80211_vif *vif,
6363 struct ieee80211_sta *sta,
6364 enum ieee80211_sta_state old_state,
6365 enum ieee80211_sta_state new_state)
6367 struct ath10k *ar = hw->priv;
6368 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6369 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6370 struct ath10k_peer *peer;
6374 if (old_state == IEEE80211_STA_NOTEXIST &&
6375 new_state == IEEE80211_STA_NONE) {
6376 memset(arsta, 0, sizeof(*arsta));
6377 arsta->arvif = arvif;
6378 arsta->peer_ps_state = WMI_PEER_PS_STATE_DISABLED;
6379 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6381 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6382 ath10k_mac_txq_init(sta->txq[i]);
6385 /* cancel must be done outside the mutex to avoid deadlock */
6386 if ((old_state == IEEE80211_STA_NONE &&
6387 new_state == IEEE80211_STA_NOTEXIST))
6388 cancel_work_sync(&arsta->update_wk);
6390 mutex_lock(&ar->conf_mutex);
6392 if (old_state == IEEE80211_STA_NOTEXIST &&
6393 new_state == IEEE80211_STA_NONE) {
6395 * New station addition.
6397 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6398 u32 num_tdls_stations;
6400 ath10k_dbg(ar, ATH10K_DBG_MAC,
6401 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6402 arvif->vdev_id, sta->addr,
6403 ar->num_stations + 1, ar->max_num_stations,
6404 ar->num_peers + 1, ar->max_num_peers);
6406 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6409 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6410 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6412 ar->max_num_tdls_vdevs);
6416 peer_type = WMI_PEER_TYPE_TDLS;
6419 ret = ath10k_mac_inc_num_stations(arvif, sta);
6421 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6422 ar->max_num_stations);
6426 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6427 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats),
6429 if (!arsta->tx_stats) {
6435 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6436 sta->addr, peer_type);
6438 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6439 sta->addr, arvif->vdev_id, ret);
6440 ath10k_mac_dec_num_stations(arvif, sta);
6441 kfree(arsta->tx_stats);
6445 spin_lock_bh(&ar->data_lock);
6447 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6449 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6450 vif->addr, arvif->vdev_id);
6451 spin_unlock_bh(&ar->data_lock);
6452 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6453 ath10k_mac_dec_num_stations(arvif, sta);
6454 kfree(arsta->tx_stats);
6459 arsta->peer_id = find_first_bit(peer->peer_ids,
6460 ATH10K_MAX_NUM_PEER_IDS);
6462 spin_unlock_bh(&ar->data_lock);
6467 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6468 WMI_TDLS_ENABLE_ACTIVE);
6470 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6471 arvif->vdev_id, ret);
6472 ath10k_peer_delete(ar, arvif->vdev_id,
6474 ath10k_mac_dec_num_stations(arvif, sta);
6475 kfree(arsta->tx_stats);
6479 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6480 WMI_TDLS_PEER_STATE_PEERING);
6483 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6484 sta->addr, arvif->vdev_id, ret);
6485 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6486 ath10k_mac_dec_num_stations(arvif, sta);
6487 kfree(arsta->tx_stats);
6489 if (num_tdls_stations != 0)
6491 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6494 } else if ((old_state == IEEE80211_STA_NONE &&
6495 new_state == IEEE80211_STA_NOTEXIST)) {
6497 * Existing station deletion.
6499 ath10k_dbg(ar, ATH10K_DBG_MAC,
6500 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6501 arvif->vdev_id, sta->addr, sta);
6504 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6506 WMI_TDLS_PEER_STATE_TEARDOWN);
6508 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6510 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6513 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6515 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6516 sta->addr, arvif->vdev_id, ret);
6518 ath10k_mac_dec_num_stations(arvif, sta);
6520 spin_lock_bh(&ar->data_lock);
6521 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6522 peer = ar->peer_map[i];
6526 if (peer->sta == sta) {
6527 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6528 sta->addr, peer, i, arvif->vdev_id);
6531 /* Clean up the peer object as well since we
6532 * must have failed to do this above.
6534 list_del(&peer->list);
6535 ar->peer_map[i] = NULL;
6540 spin_unlock_bh(&ar->data_lock);
6542 if (ath10k_debug_is_extd_tx_stats_enabled(ar)) {
6543 kfree(arsta->tx_stats);
6544 arsta->tx_stats = NULL;
6547 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6548 ath10k_mac_txq_unref(ar, sta->txq[i]);
6553 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6556 /* This was the last tdls peer in current vif */
6557 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6560 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6561 arvif->vdev_id, ret);
6563 } else if (old_state == IEEE80211_STA_AUTH &&
6564 new_state == IEEE80211_STA_ASSOC &&
6565 (vif->type == NL80211_IFTYPE_AP ||
6566 vif->type == NL80211_IFTYPE_MESH_POINT ||
6567 vif->type == NL80211_IFTYPE_ADHOC)) {
6571 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6574 ret = ath10k_station_assoc(ar, vif, sta, false);
6576 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6577 sta->addr, arvif->vdev_id, ret);
6578 } else if (old_state == IEEE80211_STA_ASSOC &&
6579 new_state == IEEE80211_STA_AUTHORIZED &&
6582 * Tdls station authorized.
6584 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6587 ret = ath10k_station_assoc(ar, vif, sta, false);
6589 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6590 sta->addr, arvif->vdev_id, ret);
6594 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6595 WMI_TDLS_PEER_STATE_CONNECTED);
6597 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6598 sta->addr, arvif->vdev_id, ret);
6599 } else if (old_state == IEEE80211_STA_ASSOC &&
6600 new_state == IEEE80211_STA_AUTH &&
6601 (vif->type == NL80211_IFTYPE_AP ||
6602 vif->type == NL80211_IFTYPE_MESH_POINT ||
6603 vif->type == NL80211_IFTYPE_ADHOC)) {
6607 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6610 ret = ath10k_station_disassoc(ar, vif, sta);
6612 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6613 sta->addr, arvif->vdev_id, ret);
6616 mutex_unlock(&ar->conf_mutex);
6620 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6621 u16 ac, bool enable)
6623 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6624 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6625 u32 prio = 0, acc = 0;
6629 lockdep_assert_held(&ar->conf_mutex);
6631 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6635 case IEEE80211_AC_VO:
6636 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6637 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6641 case IEEE80211_AC_VI:
6642 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6643 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6647 case IEEE80211_AC_BE:
6648 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6649 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6653 case IEEE80211_AC_BK:
6654 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6655 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6662 arvif->u.sta.uapsd |= value;
6664 arvif->u.sta.uapsd &= ~value;
6666 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6667 WMI_STA_PS_PARAM_UAPSD,
6668 arvif->u.sta.uapsd);
6670 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6674 if (arvif->u.sta.uapsd)
6675 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6677 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6679 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6680 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6683 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6685 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6687 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6688 arvif->vdev_id, ret);
6692 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6694 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6695 arvif->vdev_id, ret);
6699 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6700 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6701 /* Only userspace can make an educated decision when to send
6702 * trigger frame. The following effectively disables u-UAPSD
6703 * autotrigger in firmware (which is enabled by default
6704 * provided the autotrigger service is available).
6708 arg.user_priority = prio;
6709 arg.service_interval = 0;
6710 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6711 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6713 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6714 arvif->bssid, &arg, 1);
6716 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6726 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6727 struct ieee80211_vif *vif, u16 ac,
6728 const struct ieee80211_tx_queue_params *params)
6730 struct ath10k *ar = hw->priv;
6731 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6732 struct wmi_wmm_params_arg *p = NULL;
6735 mutex_lock(&ar->conf_mutex);
6738 case IEEE80211_AC_VO:
6739 p = &arvif->wmm_params.ac_vo;
6741 case IEEE80211_AC_VI:
6742 p = &arvif->wmm_params.ac_vi;
6744 case IEEE80211_AC_BE:
6745 p = &arvif->wmm_params.ac_be;
6747 case IEEE80211_AC_BK:
6748 p = &arvif->wmm_params.ac_bk;
6757 p->cwmin = params->cw_min;
6758 p->cwmax = params->cw_max;
6759 p->aifs = params->aifs;
6762 * The channel time duration programmed in the HW is in absolute
6763 * microseconds, while mac80211 gives the txop in units of
6766 p->txop = params->txop * 32;
6768 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6769 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6770 &arvif->wmm_params);
6772 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6773 arvif->vdev_id, ret);
6777 /* This won't work well with multi-interface cases but it's
6778 * better than nothing.
6780 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6782 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6787 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6789 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6792 mutex_unlock(&ar->conf_mutex);
6796 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6798 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6799 struct ieee80211_vif *vif,
6800 struct ieee80211_channel *chan,
6802 enum ieee80211_roc_type type)
6804 struct ath10k *ar = hw->priv;
6805 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6806 struct wmi_start_scan_arg arg;
6810 mutex_lock(&ar->conf_mutex);
6812 if (ath10k_mac_tdls_vif_stations_count(hw, vif) > 0) {
6817 spin_lock_bh(&ar->data_lock);
6818 switch (ar->scan.state) {
6819 case ATH10K_SCAN_IDLE:
6820 reinit_completion(&ar->scan.started);
6821 reinit_completion(&ar->scan.completed);
6822 reinit_completion(&ar->scan.on_channel);
6823 ar->scan.state = ATH10K_SCAN_STARTING;
6824 ar->scan.is_roc = true;
6825 ar->scan.vdev_id = arvif->vdev_id;
6826 ar->scan.roc_freq = chan->center_freq;
6827 ar->scan.roc_notify = true;
6830 case ATH10K_SCAN_STARTING:
6831 case ATH10K_SCAN_RUNNING:
6832 case ATH10K_SCAN_ABORTING:
6836 spin_unlock_bh(&ar->data_lock);
6841 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6843 memset(&arg, 0, sizeof(arg));
6844 ath10k_wmi_start_scan_init(ar, &arg);
6845 arg.vdev_id = arvif->vdev_id;
6846 arg.scan_id = ATH10K_SCAN_ID;
6848 arg.channels[0] = chan->center_freq;
6849 arg.dwell_time_active = scan_time_msec;
6850 arg.dwell_time_passive = scan_time_msec;
6851 arg.max_scan_time = scan_time_msec;
6852 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6853 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6854 arg.burst_duration_ms = duration;
6856 ret = ath10k_start_scan(ar, &arg);
6858 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6859 spin_lock_bh(&ar->data_lock);
6860 ar->scan.state = ATH10K_SCAN_IDLE;
6861 spin_unlock_bh(&ar->data_lock);
6865 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6867 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6869 ret = ath10k_scan_stop(ar);
6871 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6877 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6878 msecs_to_jiffies(duration));
6882 mutex_unlock(&ar->conf_mutex);
6886 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6888 struct ath10k *ar = hw->priv;
6890 mutex_lock(&ar->conf_mutex);
6892 spin_lock_bh(&ar->data_lock);
6893 ar->scan.roc_notify = false;
6894 spin_unlock_bh(&ar->data_lock);
6896 ath10k_scan_abort(ar);
6898 mutex_unlock(&ar->conf_mutex);
6900 cancel_delayed_work_sync(&ar->scan.timeout);
6906 * Both RTS and Fragmentation threshold are interface-specific
6907 * in ath10k, but device-specific in mac80211.
6910 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6912 struct ath10k *ar = hw->priv;
6913 struct ath10k_vif *arvif;
6916 mutex_lock(&ar->conf_mutex);
6917 list_for_each_entry(arvif, &ar->arvifs, list) {
6918 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6919 arvif->vdev_id, value);
6921 ret = ath10k_mac_set_rts(arvif, value);
6923 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6924 arvif->vdev_id, ret);
6928 mutex_unlock(&ar->conf_mutex);
6933 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6935 /* Even though there's a WMI enum for fragmentation threshold no known
6936 * firmware actually implements it. Moreover it is not possible to rely
6937 * frame fragmentation to mac80211 because firmware clears the "more
6938 * fragments" bit in frame control making it impossible for remote
6939 * devices to reassemble frames.
6941 * Hence implement a dummy callback just to say fragmentation isn't
6942 * supported. This effectively prevents mac80211 from doing frame
6943 * fragmentation in software.
6948 void ath10k_mac_wait_tx_complete(struct ath10k *ar)
6953 /* mac80211 doesn't care if we really xmit queued frames or not
6954 * we'll collect those frames either way if we stop/delete vdevs
6957 if (ar->state == ATH10K_STATE_WEDGED)
6960 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6963 spin_lock_bh(&ar->htt.tx_lock);
6964 empty = (ar->htt.num_pending_tx == 0);
6965 spin_unlock_bh(&ar->htt.tx_lock);
6967 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6968 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6972 }), ATH10K_FLUSH_TIMEOUT_HZ);
6974 if (time_left == 0 || skip)
6975 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6976 skip, ar->state, time_left);
6979 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6980 u32 queues, bool drop)
6982 struct ath10k *ar = hw->priv;
6983 struct ath10k_vif *arvif;
6987 if (vif && vif->type == NL80211_IFTYPE_STATION) {
6988 bitmap = ~(1 << WMI_MGMT_TID);
6989 list_for_each_entry(arvif, &ar->arvifs, list) {
6990 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6991 ath10k_wmi_peer_flush(ar, arvif->vdev_id,
6992 arvif->bssid, bitmap);
6998 mutex_lock(&ar->conf_mutex);
6999 ath10k_mac_wait_tx_complete(ar);
7000 mutex_unlock(&ar->conf_mutex);
7003 /* TODO: Implement this function properly
7004 * For now it is needed to reply to Probe Requests in IBSS mode.
7005 * Propably we need this information from FW.
7007 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
7012 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
7013 enum ieee80211_reconfig_type reconfig_type)
7015 struct ath10k *ar = hw->priv;
7017 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
7020 mutex_lock(&ar->conf_mutex);
7022 /* If device failed to restart it will be in a different state, e.g.
7023 * ATH10K_STATE_WEDGED
7025 if (ar->state == ATH10K_STATE_RESTARTED) {
7026 ath10k_info(ar, "device successfully recovered\n");
7027 ar->state = ATH10K_STATE_ON;
7028 ieee80211_wake_queues(ar->hw);
7031 mutex_unlock(&ar->conf_mutex);
7035 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
7036 struct ieee80211_channel *channel)
7039 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
7041 lockdep_assert_held(&ar->conf_mutex);
7043 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
7044 (ar->rx_channel != channel))
7047 if (ar->scan.state != ATH10K_SCAN_IDLE) {
7048 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
7052 reinit_completion(&ar->bss_survey_done);
7054 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
7056 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
7060 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
7062 ath10k_warn(ar, "bss channel survey timed out\n");
7067 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
7068 struct survey_info *survey)
7070 struct ath10k *ar = hw->priv;
7071 struct ieee80211_supported_band *sband;
7072 struct survey_info *ar_survey = &ar->survey[idx];
7075 mutex_lock(&ar->conf_mutex);
7077 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
7078 if (sband && idx >= sband->n_channels) {
7079 idx -= sband->n_channels;
7084 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
7086 if (!sband || idx >= sband->n_channels) {
7091 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
7093 spin_lock_bh(&ar->data_lock);
7094 memcpy(survey, ar_survey, sizeof(*survey));
7095 spin_unlock_bh(&ar->data_lock);
7097 survey->channel = &sband->channels[idx];
7099 if (ar->rx_channel == survey->channel)
7100 survey->filled |= SURVEY_INFO_IN_USE;
7103 mutex_unlock(&ar->conf_mutex);
7108 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
7109 enum nl80211_band band,
7110 const struct cfg80211_bitrate_mask *mask)
7115 num_rates += hweight32(mask->control[band].legacy);
7117 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
7118 num_rates += hweight8(mask->control[band].ht_mcs[i]);
7120 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
7121 num_rates += hweight16(mask->control[band].vht_mcs[i]);
7123 return num_rates == 1;
7127 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
7128 enum nl80211_band band,
7129 const struct cfg80211_bitrate_mask *mask,
7132 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
7133 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7135 u8 vht_nss_mask = 0;
7138 if (mask->control[band].legacy)
7141 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7142 if (mask->control[band].ht_mcs[i] == 0)
7144 else if (mask->control[band].ht_mcs[i] ==
7145 sband->ht_cap.mcs.rx_mask[i])
7146 ht_nss_mask |= BIT(i);
7151 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7152 if (mask->control[band].vht_mcs[i] == 0)
7154 else if (mask->control[band].vht_mcs[i] ==
7155 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
7156 vht_nss_mask |= BIT(i);
7161 if (ht_nss_mask != vht_nss_mask)
7164 if (ht_nss_mask == 0)
7167 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
7170 *nss = fls(ht_nss_mask);
7176 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
7177 enum nl80211_band band,
7178 const struct cfg80211_bitrate_mask *mask,
7187 if (hweight32(mask->control[band].legacy) == 1) {
7188 rate_idx = ffs(mask->control[band].legacy) - 1;
7190 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
7191 rate_idx += ATH10K_MAC_FIRST_OFDM_RATE_IDX;
7193 hw_rate = ath10k_wmi_legacy_rates[rate_idx].hw_value;
7194 bitrate = ath10k_wmi_legacy_rates[rate_idx].bitrate;
7196 if (ath10k_mac_bitrate_is_cck(bitrate))
7197 preamble = WMI_RATE_PREAMBLE_CCK;
7199 preamble = WMI_RATE_PREAMBLE_OFDM;
7202 *rate = preamble << 6 |
7209 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7210 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
7212 *rate = WMI_RATE_PREAMBLE_HT << 6 |
7214 (ffs(mask->control[band].ht_mcs[i]) - 1);
7220 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7221 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
7223 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
7225 (ffs(mask->control[band].vht_mcs[i]) - 1);
7234 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
7235 u8 rate, u8 nss, u8 sgi, u8 ldpc)
7237 struct ath10k *ar = arvif->ar;
7241 lockdep_assert_held(&ar->conf_mutex);
7243 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
7244 arvif->vdev_id, rate, nss, sgi);
7246 vdev_param = ar->wmi.vdev_param->fixed_rate;
7247 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
7249 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
7254 vdev_param = ar->wmi.vdev_param->nss;
7255 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
7257 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
7261 vdev_param = ar->wmi.vdev_param->sgi;
7262 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
7264 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
7268 vdev_param = ar->wmi.vdev_param->ldpc;
7269 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
7271 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
7279 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
7280 enum nl80211_band band,
7281 const struct cfg80211_bitrate_mask *mask)
7286 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
7287 * to express all VHT MCS rate masks. Effectively only the following
7288 * ranges can be used: none, 0-7, 0-8 and 0-9.
7290 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7291 vht_mcs = mask->control[band].vht_mcs[i];
7300 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
7308 static void ath10k_mac_set_bitrate_mask_iter(void *data,
7309 struct ieee80211_sta *sta)
7311 struct ath10k_vif *arvif = data;
7312 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7313 struct ath10k *ar = arvif->ar;
7315 if (arsta->arvif != arvif)
7318 spin_lock_bh(&ar->data_lock);
7319 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7320 spin_unlock_bh(&ar->data_lock);
7322 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7325 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7326 struct ieee80211_vif *vif,
7327 const struct cfg80211_bitrate_mask *mask)
7329 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7330 struct cfg80211_chan_def def;
7331 struct ath10k *ar = arvif->ar;
7332 enum nl80211_band band;
7333 const u8 *ht_mcs_mask;
7334 const u16 *vht_mcs_mask;
7342 if (ath10k_mac_vif_chan(vif, &def))
7345 band = def.chan->band;
7346 ht_mcs_mask = mask->control[band].ht_mcs;
7347 vht_mcs_mask = mask->control[band].vht_mcs;
7348 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7350 sgi = mask->control[band].gi;
7351 if (sgi == NL80211_TXRATE_FORCE_LGI)
7354 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7355 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7358 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7359 arvif->vdev_id, ret);
7362 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7364 rate = WMI_FIXED_RATE_NONE;
7367 rate = WMI_FIXED_RATE_NONE;
7368 nss = min(ar->num_rf_chains,
7369 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7370 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7372 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7375 mutex_lock(&ar->conf_mutex);
7377 arvif->bitrate_mask = *mask;
7378 ieee80211_iterate_stations_atomic(ar->hw,
7379 ath10k_mac_set_bitrate_mask_iter,
7382 mutex_unlock(&ar->conf_mutex);
7385 mutex_lock(&ar->conf_mutex);
7387 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7389 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7390 arvif->vdev_id, ret);
7395 mutex_unlock(&ar->conf_mutex);
7400 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7401 struct ieee80211_vif *vif,
7402 struct ieee80211_sta *sta,
7405 struct ath10k *ar = hw->priv;
7406 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7407 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7408 struct ath10k_peer *peer;
7411 spin_lock_bh(&ar->data_lock);
7413 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7415 spin_unlock_bh(&ar->data_lock);
7416 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7417 sta->addr, arvif->vdev_id);
7421 ath10k_dbg(ar, ATH10K_DBG_MAC,
7422 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7423 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7426 if (changed & IEEE80211_RC_BW_CHANGED) {
7427 bw = WMI_PEER_CHWIDTH_20MHZ;
7429 switch (sta->bandwidth) {
7430 case IEEE80211_STA_RX_BW_20:
7431 bw = WMI_PEER_CHWIDTH_20MHZ;
7433 case IEEE80211_STA_RX_BW_40:
7434 bw = WMI_PEER_CHWIDTH_40MHZ;
7436 case IEEE80211_STA_RX_BW_80:
7437 bw = WMI_PEER_CHWIDTH_80MHZ;
7439 case IEEE80211_STA_RX_BW_160:
7440 bw = WMI_PEER_CHWIDTH_160MHZ;
7443 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7444 sta->bandwidth, sta->addr);
7445 bw = WMI_PEER_CHWIDTH_20MHZ;
7452 if (changed & IEEE80211_RC_NSS_CHANGED)
7453 arsta->nss = sta->rx_nss;
7455 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7456 smps = WMI_PEER_SMPS_PS_NONE;
7458 switch (sta->smps_mode) {
7459 case IEEE80211_SMPS_AUTOMATIC:
7460 case IEEE80211_SMPS_OFF:
7461 smps = WMI_PEER_SMPS_PS_NONE;
7463 case IEEE80211_SMPS_STATIC:
7464 smps = WMI_PEER_SMPS_STATIC;
7466 case IEEE80211_SMPS_DYNAMIC:
7467 smps = WMI_PEER_SMPS_DYNAMIC;
7469 case IEEE80211_SMPS_NUM_MODES:
7470 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7471 sta->smps_mode, sta->addr);
7472 smps = WMI_PEER_SMPS_PS_NONE;
7479 arsta->changed |= changed;
7481 spin_unlock_bh(&ar->data_lock);
7483 ieee80211_queue_work(hw, &arsta->update_wk);
7486 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7487 struct ieee80211_vif *vif, s64 tsf_offset)
7489 struct ath10k *ar = hw->priv;
7490 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7491 u32 offset, vdev_param;
7494 if (tsf_offset < 0) {
7495 vdev_param = ar->wmi.vdev_param->dec_tsf;
7496 offset = -tsf_offset;
7498 vdev_param = ar->wmi.vdev_param->inc_tsf;
7499 offset = tsf_offset;
7502 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7503 vdev_param, offset);
7505 if (ret && ret != -EOPNOTSUPP)
7506 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7507 offset, vdev_param, ret);
7510 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7511 struct ieee80211_vif *vif,
7512 struct ieee80211_ampdu_params *params)
7514 struct ath10k *ar = hw->priv;
7515 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7516 struct ieee80211_sta *sta = params->sta;
7517 enum ieee80211_ampdu_mlme_action action = params->action;
7518 u16 tid = params->tid;
7520 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7521 arvif->vdev_id, sta->addr, tid, action);
7524 case IEEE80211_AMPDU_RX_START:
7525 case IEEE80211_AMPDU_RX_STOP:
7526 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7527 * creation/removal. Do we need to verify this?
7530 case IEEE80211_AMPDU_TX_START:
7531 case IEEE80211_AMPDU_TX_STOP_CONT:
7532 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7533 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7534 case IEEE80211_AMPDU_TX_OPERATIONAL:
7535 /* Firmware offloads Tx aggregation entirely so deny mac80211
7536 * Tx aggregation requests.
7545 ath10k_mac_update_rx_channel(struct ath10k *ar,
7546 struct ieee80211_chanctx_conf *ctx,
7547 struct ieee80211_vif_chanctx_switch *vifs,
7550 struct cfg80211_chan_def *def = NULL;
7552 /* Both locks are required because ar->rx_channel is modified. This
7553 * allows readers to hold either lock.
7555 lockdep_assert_held(&ar->conf_mutex);
7556 lockdep_assert_held(&ar->data_lock);
7558 WARN_ON(ctx && vifs);
7559 WARN_ON(vifs && !n_vifs);
7561 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7562 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7563 * ppdu on Rx may reduce performance on low-end systems. It should be
7564 * possible to make tables/hashmaps to speed the lookup up (be vary of
7565 * cpu data cache lines though regarding sizes) but to keep the initial
7566 * implementation simple and less intrusive fallback to the slow lookup
7567 * only for multi-channel cases. Single-channel cases will remain to
7568 * use the old channel derival and thus performance should not be
7572 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7573 ieee80211_iter_chan_contexts_atomic(ar->hw,
7574 ath10k_mac_get_any_chandef_iter,
7578 def = &vifs[0].new_ctx->def;
7580 ar->rx_channel = def->chan;
7581 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7582 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7583 /* During driver restart due to firmware assert, since mac80211
7584 * already has valid channel context for given radio, channel
7585 * context iteration return num_chanctx > 0. So fix rx_channel
7586 * when restart is in progress.
7588 ar->rx_channel = ctx->def.chan;
7590 ar->rx_channel = NULL;
7596 ath10k_mac_update_vif_chan(struct ath10k *ar,
7597 struct ieee80211_vif_chanctx_switch *vifs,
7600 struct ath10k_vif *arvif;
7604 lockdep_assert_held(&ar->conf_mutex);
7606 /* First stop monitor interface. Some FW versions crash if there's a
7607 * lone monitor interface.
7609 if (ar->monitor_started)
7610 ath10k_monitor_stop(ar);
7612 for (i = 0; i < n_vifs; i++) {
7613 arvif = (void *)vifs[i].vif->drv_priv;
7615 ath10k_dbg(ar, ATH10K_DBG_MAC,
7616 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7618 vifs[i].old_ctx->def.chan->center_freq,
7619 vifs[i].new_ctx->def.chan->center_freq,
7620 vifs[i].old_ctx->def.width,
7621 vifs[i].new_ctx->def.width);
7623 if (WARN_ON(!arvif->is_started))
7626 if (WARN_ON(!arvif->is_up))
7629 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7631 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7632 arvif->vdev_id, ret);
7637 /* All relevant vdevs are downed and associated channel resources
7638 * should be available for the channel switch now.
7641 spin_lock_bh(&ar->data_lock);
7642 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7643 spin_unlock_bh(&ar->data_lock);
7645 for (i = 0; i < n_vifs; i++) {
7646 arvif = (void *)vifs[i].vif->drv_priv;
7648 if (WARN_ON(!arvif->is_started))
7651 if (WARN_ON(!arvif->is_up))
7654 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7656 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7659 ret = ath10k_mac_setup_prb_tmpl(arvif);
7661 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7664 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7666 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7667 arvif->vdev_id, ret);
7671 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7674 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7675 arvif->vdev_id, ret);
7680 ath10k_monitor_recalc(ar);
7684 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7685 struct ieee80211_chanctx_conf *ctx)
7687 struct ath10k *ar = hw->priv;
7689 ath10k_dbg(ar, ATH10K_DBG_MAC,
7690 "mac chanctx add freq %hu width %d ptr %pK\n",
7691 ctx->def.chan->center_freq, ctx->def.width, ctx);
7693 mutex_lock(&ar->conf_mutex);
7695 spin_lock_bh(&ar->data_lock);
7696 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7697 spin_unlock_bh(&ar->data_lock);
7699 ath10k_recalc_radar_detection(ar);
7700 ath10k_monitor_recalc(ar);
7702 mutex_unlock(&ar->conf_mutex);
7708 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7709 struct ieee80211_chanctx_conf *ctx)
7711 struct ath10k *ar = hw->priv;
7713 ath10k_dbg(ar, ATH10K_DBG_MAC,
7714 "mac chanctx remove freq %hu width %d ptr %pK\n",
7715 ctx->def.chan->center_freq, ctx->def.width, ctx);
7717 mutex_lock(&ar->conf_mutex);
7719 spin_lock_bh(&ar->data_lock);
7720 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7721 spin_unlock_bh(&ar->data_lock);
7723 ath10k_recalc_radar_detection(ar);
7724 ath10k_monitor_recalc(ar);
7726 mutex_unlock(&ar->conf_mutex);
7729 struct ath10k_mac_change_chanctx_arg {
7730 struct ieee80211_chanctx_conf *ctx;
7731 struct ieee80211_vif_chanctx_switch *vifs;
7737 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7738 struct ieee80211_vif *vif)
7740 struct ath10k_mac_change_chanctx_arg *arg = data;
7742 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7749 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7750 struct ieee80211_vif *vif)
7752 struct ath10k_mac_change_chanctx_arg *arg = data;
7753 struct ieee80211_chanctx_conf *ctx;
7755 ctx = rcu_access_pointer(vif->chanctx_conf);
7756 if (ctx != arg->ctx)
7759 if (WARN_ON(arg->next_vif == arg->n_vifs))
7762 arg->vifs[arg->next_vif].vif = vif;
7763 arg->vifs[arg->next_vif].old_ctx = ctx;
7764 arg->vifs[arg->next_vif].new_ctx = ctx;
7769 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7770 struct ieee80211_chanctx_conf *ctx,
7773 struct ath10k *ar = hw->priv;
7774 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7776 mutex_lock(&ar->conf_mutex);
7778 ath10k_dbg(ar, ATH10K_DBG_MAC,
7779 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7780 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7782 /* This shouldn't really happen because channel switching should use
7783 * switch_vif_chanctx().
7785 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7788 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7789 ieee80211_iterate_active_interfaces_atomic(
7791 IEEE80211_IFACE_ITER_NORMAL,
7792 ath10k_mac_change_chanctx_cnt_iter,
7794 if (arg.n_vifs == 0)
7797 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7802 ieee80211_iterate_active_interfaces_atomic(
7804 IEEE80211_IFACE_ITER_NORMAL,
7805 ath10k_mac_change_chanctx_fill_iter,
7807 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7812 ath10k_recalc_radar_detection(ar);
7814 /* FIXME: How to configure Rx chains properly? */
7816 /* No other actions are actually necessary. Firmware maintains channel
7817 * definitions per vdev internally and there's no host-side channel
7818 * context abstraction to configure, e.g. channel width.
7822 mutex_unlock(&ar->conf_mutex);
7826 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7827 struct ieee80211_vif *vif,
7828 struct ieee80211_chanctx_conf *ctx)
7830 struct ath10k *ar = hw->priv;
7831 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7834 mutex_lock(&ar->conf_mutex);
7836 ath10k_dbg(ar, ATH10K_DBG_MAC,
7837 "mac chanctx assign ptr %pK vdev_id %i\n",
7838 ctx, arvif->vdev_id);
7840 if (WARN_ON(arvif->is_started)) {
7841 mutex_unlock(&ar->conf_mutex);
7845 ret = ath10k_vdev_start(arvif, &ctx->def);
7847 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7848 arvif->vdev_id, vif->addr,
7849 ctx->def.chan->center_freq, ret);
7853 arvif->is_started = true;
7855 ret = ath10k_mac_vif_setup_ps(arvif);
7857 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7858 arvif->vdev_id, ret);
7862 if (vif->type == NL80211_IFTYPE_MONITOR) {
7863 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7865 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7866 arvif->vdev_id, ret);
7870 arvif->is_up = true;
7873 if (ath10k_mac_can_set_cts_prot(arvif)) {
7874 ret = ath10k_mac_set_cts_prot(arvif);
7876 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7877 arvif->vdev_id, ret);
7880 if (ath10k_peer_stats_enabled(ar)) {
7881 ar->pktlog_filter |= ATH10K_PKTLOG_PEER_STATS;
7882 ret = ath10k_wmi_pdev_pktlog_enable(ar,
7885 ath10k_warn(ar, "failed to enable pktlog %d\n", ret);
7890 mutex_unlock(&ar->conf_mutex);
7894 ath10k_vdev_stop(arvif);
7895 arvif->is_started = false;
7896 ath10k_mac_vif_setup_ps(arvif);
7899 mutex_unlock(&ar->conf_mutex);
7904 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7905 struct ieee80211_vif *vif,
7906 struct ieee80211_chanctx_conf *ctx)
7908 struct ath10k *ar = hw->priv;
7909 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7912 mutex_lock(&ar->conf_mutex);
7914 ath10k_dbg(ar, ATH10K_DBG_MAC,
7915 "mac chanctx unassign ptr %pK vdev_id %i\n",
7916 ctx, arvif->vdev_id);
7918 WARN_ON(!arvif->is_started);
7920 if (vif->type == NL80211_IFTYPE_MONITOR) {
7921 WARN_ON(!arvif->is_up);
7923 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7925 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7926 arvif->vdev_id, ret);
7928 arvif->is_up = false;
7931 ret = ath10k_vdev_stop(arvif);
7933 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7934 arvif->vdev_id, ret);
7936 arvif->is_started = false;
7938 mutex_unlock(&ar->conf_mutex);
7942 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7943 struct ieee80211_vif_chanctx_switch *vifs,
7945 enum ieee80211_chanctx_switch_mode mode)
7947 struct ath10k *ar = hw->priv;
7949 mutex_lock(&ar->conf_mutex);
7951 ath10k_dbg(ar, ATH10K_DBG_MAC,
7952 "mac chanctx switch n_vifs %d mode %d\n",
7954 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7956 mutex_unlock(&ar->conf_mutex);
7960 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7961 struct ieee80211_vif *vif,
7962 struct ieee80211_sta *sta)
7965 struct ath10k_peer *peer;
7969 list_for_each_entry(peer, &ar->peers, list)
7970 if (peer->sta == sta)
7971 peer->removed = true;
7974 static void ath10k_sta_statistics(struct ieee80211_hw *hw,
7975 struct ieee80211_vif *vif,
7976 struct ieee80211_sta *sta,
7977 struct station_info *sinfo)
7979 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7980 struct ath10k *ar = arsta->arvif->ar;
7982 if (!ath10k_peer_stats_enabled(ar))
7985 sinfo->rx_duration = arsta->rx_duration;
7986 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
7988 if (!arsta->txrate.legacy && !arsta->txrate.nss)
7991 if (arsta->txrate.legacy) {
7992 sinfo->txrate.legacy = arsta->txrate.legacy;
7994 sinfo->txrate.mcs = arsta->txrate.mcs;
7995 sinfo->txrate.nss = arsta->txrate.nss;
7996 sinfo->txrate.bw = arsta->txrate.bw;
7998 sinfo->txrate.flags = arsta->txrate.flags;
7999 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
8002 static const struct ieee80211_ops ath10k_ops = {
8003 .tx = ath10k_mac_op_tx,
8004 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
8005 .start = ath10k_start,
8006 .stop = ath10k_stop,
8007 .config = ath10k_config,
8008 .add_interface = ath10k_add_interface,
8009 .remove_interface = ath10k_remove_interface,
8010 .configure_filter = ath10k_configure_filter,
8011 .bss_info_changed = ath10k_bss_info_changed,
8012 .set_coverage_class = ath10k_mac_op_set_coverage_class,
8013 .hw_scan = ath10k_hw_scan,
8014 .cancel_hw_scan = ath10k_cancel_hw_scan,
8015 .set_key = ath10k_set_key,
8016 .set_default_unicast_key = ath10k_set_default_unicast_key,
8017 .sta_state = ath10k_sta_state,
8018 .conf_tx = ath10k_conf_tx,
8019 .remain_on_channel = ath10k_remain_on_channel,
8020 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
8021 .set_rts_threshold = ath10k_set_rts_threshold,
8022 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
8023 .flush = ath10k_flush,
8024 .tx_last_beacon = ath10k_tx_last_beacon,
8025 .set_antenna = ath10k_set_antenna,
8026 .get_antenna = ath10k_get_antenna,
8027 .reconfig_complete = ath10k_reconfig_complete,
8028 .get_survey = ath10k_get_survey,
8029 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
8030 .sta_rc_update = ath10k_sta_rc_update,
8031 .offset_tsf = ath10k_offset_tsf,
8032 .ampdu_action = ath10k_ampdu_action,
8033 .get_et_sset_count = ath10k_debug_get_et_sset_count,
8034 .get_et_stats = ath10k_debug_get_et_stats,
8035 .get_et_strings = ath10k_debug_get_et_strings,
8036 .add_chanctx = ath10k_mac_op_add_chanctx,
8037 .remove_chanctx = ath10k_mac_op_remove_chanctx,
8038 .change_chanctx = ath10k_mac_op_change_chanctx,
8039 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
8040 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
8041 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
8042 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
8043 .sta_statistics = ath10k_sta_statistics,
8045 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
8048 .suspend = ath10k_wow_op_suspend,
8049 .resume = ath10k_wow_op_resume,
8050 .set_wakeup = ath10k_wow_op_set_wakeup,
8052 #ifdef CONFIG_MAC80211_DEBUGFS
8053 .sta_add_debugfs = ath10k_sta_add_debugfs,
8057 #define CHAN2G(_channel, _freq, _flags) { \
8058 .band = NL80211_BAND_2GHZ, \
8059 .hw_value = (_channel), \
8060 .center_freq = (_freq), \
8061 .flags = (_flags), \
8062 .max_antenna_gain = 0, \
8066 #define CHAN5G(_channel, _freq, _flags) { \
8067 .band = NL80211_BAND_5GHZ, \
8068 .hw_value = (_channel), \
8069 .center_freq = (_freq), \
8070 .flags = (_flags), \
8071 .max_antenna_gain = 0, \
8075 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
8085 CHAN2G(10, 2457, 0),
8086 CHAN2G(11, 2462, 0),
8087 CHAN2G(12, 2467, 0),
8088 CHAN2G(13, 2472, 0),
8089 CHAN2G(14, 2484, 0),
8092 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
8093 CHAN5G(36, 5180, 0),
8094 CHAN5G(40, 5200, 0),
8095 CHAN5G(44, 5220, 0),
8096 CHAN5G(48, 5240, 0),
8097 CHAN5G(52, 5260, 0),
8098 CHAN5G(56, 5280, 0),
8099 CHAN5G(60, 5300, 0),
8100 CHAN5G(64, 5320, 0),
8101 CHAN5G(100, 5500, 0),
8102 CHAN5G(104, 5520, 0),
8103 CHAN5G(108, 5540, 0),
8104 CHAN5G(112, 5560, 0),
8105 CHAN5G(116, 5580, 0),
8106 CHAN5G(120, 5600, 0),
8107 CHAN5G(124, 5620, 0),
8108 CHAN5G(128, 5640, 0),
8109 CHAN5G(132, 5660, 0),
8110 CHAN5G(136, 5680, 0),
8111 CHAN5G(140, 5700, 0),
8112 CHAN5G(144, 5720, 0),
8113 CHAN5G(149, 5745, 0),
8114 CHAN5G(153, 5765, 0),
8115 CHAN5G(157, 5785, 0),
8116 CHAN5G(161, 5805, 0),
8117 CHAN5G(165, 5825, 0),
8118 CHAN5G(169, 5845, 0),
8119 CHAN5G(173, 5865, 0),
8120 /* If you add more, you may need to change ATH10K_MAX_5G_CHAN */
8121 /* And you will definitely need to change ATH10K_NUM_CHANS in core.h */
8124 struct ath10k *ath10k_mac_create(size_t priv_size)
8126 struct ieee80211_hw *hw;
8127 struct ieee80211_ops *ops;
8130 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
8134 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
8147 void ath10k_mac_destroy(struct ath10k *ar)
8149 struct ieee80211_ops *ops = ar->ops;
8151 ieee80211_free_hw(ar->hw);
8155 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
8158 .types = BIT(NL80211_IFTYPE_STATION)
8159 | BIT(NL80211_IFTYPE_P2P_CLIENT)
8163 .types = BIT(NL80211_IFTYPE_P2P_GO)
8167 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
8171 .types = BIT(NL80211_IFTYPE_AP)
8172 #ifdef CONFIG_MAC80211_MESH
8173 | BIT(NL80211_IFTYPE_MESH_POINT)
8178 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
8181 .types = BIT(NL80211_IFTYPE_AP)
8182 #ifdef CONFIG_MAC80211_MESH
8183 | BIT(NL80211_IFTYPE_MESH_POINT)
8188 .types = BIT(NL80211_IFTYPE_STATION)
8192 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
8194 .limits = ath10k_if_limits,
8195 .n_limits = ARRAY_SIZE(ath10k_if_limits),
8196 .max_interfaces = 8,
8197 .num_different_channels = 1,
8198 .beacon_int_infra_match = true,
8202 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
8204 .limits = ath10k_10x_if_limits,
8205 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
8206 .max_interfaces = 8,
8207 .num_different_channels = 1,
8208 .beacon_int_infra_match = true,
8209 .beacon_int_min_gcd = 1,
8210 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8211 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8212 BIT(NL80211_CHAN_WIDTH_20) |
8213 BIT(NL80211_CHAN_WIDTH_40) |
8214 BIT(NL80211_CHAN_WIDTH_80),
8219 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
8222 .types = BIT(NL80211_IFTYPE_STATION),
8226 .types = BIT(NL80211_IFTYPE_AP) |
8227 #ifdef CONFIG_MAC80211_MESH
8228 BIT(NL80211_IFTYPE_MESH_POINT) |
8230 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8231 BIT(NL80211_IFTYPE_P2P_GO),
8235 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8239 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
8242 .types = BIT(NL80211_IFTYPE_STATION),
8246 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
8250 .types = BIT(NL80211_IFTYPE_AP) |
8251 #ifdef CONFIG_MAC80211_MESH
8252 BIT(NL80211_IFTYPE_MESH_POINT) |
8254 BIT(NL80211_IFTYPE_P2P_GO),
8258 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
8262 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
8265 .types = BIT(NL80211_IFTYPE_STATION),
8269 .types = BIT(NL80211_IFTYPE_ADHOC),
8273 /* FIXME: This is not thouroughly tested. These combinations may over- or
8274 * underestimate hw/fw capabilities.
8276 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
8278 .limits = ath10k_tlv_if_limit,
8279 .num_different_channels = 1,
8280 .max_interfaces = 4,
8281 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8284 .limits = ath10k_tlv_if_limit_ibss,
8285 .num_different_channels = 1,
8286 .max_interfaces = 2,
8287 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8291 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
8293 .limits = ath10k_tlv_if_limit,
8294 .num_different_channels = 1,
8295 .max_interfaces = 4,
8296 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
8299 .limits = ath10k_tlv_qcs_if_limit,
8300 .num_different_channels = 2,
8301 .max_interfaces = 4,
8302 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
8305 .limits = ath10k_tlv_if_limit_ibss,
8306 .num_different_channels = 1,
8307 .max_interfaces = 2,
8308 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
8312 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8315 .types = BIT(NL80211_IFTYPE_STATION),
8319 .types = BIT(NL80211_IFTYPE_AP)
8320 #ifdef CONFIG_MAC80211_MESH
8321 | BIT(NL80211_IFTYPE_MESH_POINT)
8326 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8328 .limits = ath10k_10_4_if_limits,
8329 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8330 .max_interfaces = 16,
8331 .num_different_channels = 1,
8332 .beacon_int_infra_match = true,
8333 .beacon_int_min_gcd = 1,
8334 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8335 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8336 BIT(NL80211_CHAN_WIDTH_20) |
8337 BIT(NL80211_CHAN_WIDTH_40) |
8338 BIT(NL80211_CHAN_WIDTH_80),
8344 ieee80211_iface_combination ath10k_10_4_bcn_int_if_comb[] = {
8346 .limits = ath10k_10_4_if_limits,
8347 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8348 .max_interfaces = 16,
8349 .num_different_channels = 1,
8350 .beacon_int_infra_match = true,
8351 .beacon_int_min_gcd = 100,
8352 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8353 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8354 BIT(NL80211_CHAN_WIDTH_20) |
8355 BIT(NL80211_CHAN_WIDTH_40) |
8356 BIT(NL80211_CHAN_WIDTH_80),
8361 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8362 struct ieee80211_vif *vif)
8364 struct ath10k_vif_iter *arvif_iter = data;
8365 struct ath10k_vif *arvif = (void *)vif->drv_priv;
8367 if (arvif->vdev_id == arvif_iter->vdev_id)
8368 arvif_iter->arvif = arvif;
8371 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8373 struct ath10k_vif_iter arvif_iter;
8376 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8377 arvif_iter.vdev_id = vdev_id;
8379 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8380 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8382 ath10k_get_arvif_iter,
8384 if (!arvif_iter.arvif) {
8385 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8389 return arvif_iter.arvif;
8392 #define WRD_METHOD "WRDD"
8393 #define WRDD_WIFI (0x07)
8395 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8397 union acpi_object *mcc_pkg;
8398 union acpi_object *domain_type;
8399 union acpi_object *mcc_value;
8402 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8403 wrdd->package.count < 2 ||
8404 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8405 wrdd->package.elements[0].integer.value != 0) {
8406 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8410 for (i = 1; i < wrdd->package.count; ++i) {
8411 mcc_pkg = &wrdd->package.elements[i];
8413 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8415 if (mcc_pkg->package.count < 2)
8417 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8418 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8421 domain_type = &mcc_pkg->package.elements[0];
8422 if (domain_type->integer.value != WRDD_WIFI)
8425 mcc_value = &mcc_pkg->package.elements[1];
8426 return mcc_value->integer.value;
8431 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8433 acpi_handle root_handle;
8435 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8440 root_handle = ACPI_HANDLE(ar->dev);
8444 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8445 if (ACPI_FAILURE(status)) {
8446 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8447 "failed to get wrd method %d\n", status);
8451 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8452 if (ACPI_FAILURE(status)) {
8453 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8454 "failed to call wrdc %d\n", status);
8458 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8459 kfree(wrdd.pointer);
8463 alpha2[0] = (alpha2_code >> 8) & 0xff;
8464 alpha2[1] = (alpha2_code >> 0) & 0xff;
8467 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8468 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8470 *rd = ath_regd_find_country_by_name(alpha2);
8474 *rd |= COUNTRY_ERD_FLAG;
8478 static int ath10k_mac_init_rd(struct ath10k *ar)
8483 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8485 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8486 "fallback to eeprom programmed regulatory settings\n");
8487 rd = ar->hw_eeprom_rd;
8490 ar->ath_common.regulatory.current_rd = rd;
8494 int ath10k_mac_register(struct ath10k *ar)
8496 static const u32 cipher_suites[] = {
8497 WLAN_CIPHER_SUITE_WEP40,
8498 WLAN_CIPHER_SUITE_WEP104,
8499 WLAN_CIPHER_SUITE_TKIP,
8500 WLAN_CIPHER_SUITE_CCMP,
8502 /* Do not add hardware supported ciphers before this line.
8503 * Allow software encryption for all chips. Don't forget to
8504 * update n_cipher_suites below.
8506 WLAN_CIPHER_SUITE_AES_CMAC,
8507 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8508 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8509 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8511 /* Only QCA99x0 and QCA4019 varients support GCMP-128, GCMP-256
8512 * and CCMP-256 in hardware.
8514 WLAN_CIPHER_SUITE_GCMP,
8515 WLAN_CIPHER_SUITE_GCMP_256,
8516 WLAN_CIPHER_SUITE_CCMP_256,
8518 struct ieee80211_supported_band *band;
8522 if (!is_valid_ether_addr(ar->mac_addr)) {
8523 ath10k_warn(ar, "invalid MAC address; choosing random\n");
8524 eth_random_addr(ar->mac_addr);
8526 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8528 SET_IEEE80211_DEV(ar->hw, ar->dev);
8530 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8531 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8534 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8535 channels = kmemdup(ath10k_2ghz_channels,
8536 sizeof(ath10k_2ghz_channels),
8543 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8544 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8545 band->channels = channels;
8547 if (ar->hw_params.cck_rate_map_rev2) {
8548 band->n_bitrates = ath10k_g_rates_rev2_size;
8549 band->bitrates = ath10k_g_rates_rev2;
8551 band->n_bitrates = ath10k_g_rates_size;
8552 band->bitrates = ath10k_g_rates;
8555 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8558 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8559 channels = kmemdup(ath10k_5ghz_channels,
8560 sizeof(ath10k_5ghz_channels),
8567 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8568 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8569 band->channels = channels;
8570 band->n_bitrates = ath10k_a_rates_size;
8571 band->bitrates = ath10k_a_rates;
8572 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8575 wiphy_read_of_freq_limits(ar->hw->wiphy);
8576 ath10k_mac_setup_ht_vht_cap(ar);
8578 ar->hw->wiphy->interface_modes =
8579 BIT(NL80211_IFTYPE_STATION) |
8580 BIT(NL80211_IFTYPE_AP) |
8581 BIT(NL80211_IFTYPE_MESH_POINT);
8583 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8584 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8586 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8587 ar->hw->wiphy->interface_modes |=
8588 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8589 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8590 BIT(NL80211_IFTYPE_P2P_GO);
8592 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8594 if (!test_bit(ATH10K_FW_FEATURE_NO_PS,
8595 ar->running_fw->fw_file.fw_features)) {
8596 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8597 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8600 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8601 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8602 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8603 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8604 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8605 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8606 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8607 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8608 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8609 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8610 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8611 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8612 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8614 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8615 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8617 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8618 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8620 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8621 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8623 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8624 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8625 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8628 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8629 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8631 if (test_bit(WMI_SERVICE_NLO, ar->wmi.svc_map)) {
8632 ar->hw->wiphy->max_sched_scan_reqs = 1;
8633 ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
8634 ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
8635 ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
8636 ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
8637 ar->hw->wiphy->max_sched_scan_plan_interval =
8638 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
8639 ar->hw->wiphy->max_sched_scan_plan_iterations =
8640 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
8643 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8644 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8645 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8647 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8649 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8650 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8652 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8653 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8654 * correct Probe Responses. This is more of a hack advert..
8656 ar->hw->wiphy->probe_resp_offload |=
8657 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8658 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8659 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8662 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8663 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8664 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8665 if (test_bit(WMI_SERVICE_TDLS_WIDER_BANDWIDTH, ar->wmi.svc_map))
8666 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8669 if (test_bit(WMI_SERVICE_TDLS_UAPSD_BUFFER_STA, ar->wmi.svc_map))
8670 ieee80211_hw_set(ar->hw, SUPPORTS_TDLS_BUFFER_STA);
8672 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8673 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8674 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8676 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8677 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8678 NL80211_FEATURE_AP_SCAN;
8680 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8682 ret = ath10k_wow_init(ar);
8684 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8688 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8689 wiphy_ext_feature_set(ar->hw->wiphy,
8690 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
8692 if (test_bit(WMI_SERVICE_TX_DATA_ACK_RSSI, ar->wmi.svc_map) ||
8693 test_bit(WMI_SERVICE_HTT_MGMT_TX_COMP_VALID_FLAGS, ar->wmi.svc_map))
8694 wiphy_ext_feature_set(ar->hw->wiphy,
8695 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT);
8697 if (ath10k_peer_stats_enabled(ar) ||
8698 test_bit(WMI_SERVICE_REPORT_AIRTIME, ar->wmi.svc_map))
8699 wiphy_ext_feature_set(ar->hw->wiphy,
8700 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
8702 if (test_bit(WMI_SERVICE_RTT_RESPONDER_ROLE, ar->wmi.svc_map))
8703 wiphy_ext_feature_set(ar->hw->wiphy,
8704 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
8707 * on LL hardware queues are managed entirely by the FW
8708 * so we only advertise to mac we can do the queues thing
8710 ar->hw->queues = IEEE80211_MAX_QUEUES;
8712 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8713 * something that vdev_ids can't reach so that we don't stop the queue
8716 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8718 switch (ar->running_fw->fw_file.wmi_op_version) {
8719 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8720 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8721 ar->hw->wiphy->n_iface_combinations =
8722 ARRAY_SIZE(ath10k_if_comb);
8723 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8725 case ATH10K_FW_WMI_OP_VERSION_TLV:
8726 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8727 ar->hw->wiphy->iface_combinations =
8728 ath10k_tlv_qcs_if_comb;
8729 ar->hw->wiphy->n_iface_combinations =
8730 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8732 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8733 ar->hw->wiphy->n_iface_combinations =
8734 ARRAY_SIZE(ath10k_tlv_if_comb);
8736 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8738 case ATH10K_FW_WMI_OP_VERSION_10_1:
8739 case ATH10K_FW_WMI_OP_VERSION_10_2:
8740 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8741 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8742 ar->hw->wiphy->n_iface_combinations =
8743 ARRAY_SIZE(ath10k_10x_if_comb);
8745 case ATH10K_FW_WMI_OP_VERSION_10_4:
8746 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8747 ar->hw->wiphy->n_iface_combinations =
8748 ARRAY_SIZE(ath10k_10_4_if_comb);
8749 if (test_bit(WMI_SERVICE_VDEV_DIFFERENT_BEACON_INTERVAL_SUPPORT,
8751 ar->hw->wiphy->iface_combinations =
8752 ath10k_10_4_bcn_int_if_comb;
8753 ar->hw->wiphy->n_iface_combinations =
8754 ARRAY_SIZE(ath10k_10_4_bcn_int_if_comb);
8757 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8758 case ATH10K_FW_WMI_OP_VERSION_MAX:
8764 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8765 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8767 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8768 /* Init ath dfs pattern detector */
8769 ar->ath_common.debug_mask = ATH_DBG_DFS;
8770 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8773 if (!ar->dfs_detector)
8774 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8777 ret = ath10k_mac_init_rd(ar);
8779 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8780 goto err_dfs_detector_exit;
8783 /* Disable set_coverage_class for chipsets that do not support it. */
8784 if (!ar->hw_params.hw_ops->set_coverage_class)
8785 ar->ops->set_coverage_class = NULL;
8787 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8788 ath10k_reg_notifier);
8790 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8791 goto err_dfs_detector_exit;
8794 if (test_bit(WMI_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi.svc_map)) {
8795 ar->hw->wiphy->features |=
8796 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8799 ar->hw->wiphy->cipher_suites = cipher_suites;
8801 /* QCA988x and QCA6174 family chips do not support CCMP-256, GCMP-128
8802 * and GCMP-256 ciphers in hardware. Fetch number of ciphers supported
8803 * from chip specific hw_param table.
8805 if (!ar->hw_params.n_cipher_suites ||
8806 ar->hw_params.n_cipher_suites > ARRAY_SIZE(cipher_suites)) {
8807 ath10k_err(ar, "invalid hw_params.n_cipher_suites %d\n",
8808 ar->hw_params.n_cipher_suites);
8809 ar->hw_params.n_cipher_suites = 8;
8811 ar->hw->wiphy->n_cipher_suites = ar->hw_params.n_cipher_suites;
8813 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8815 ar->hw->weight_multiplier = ATH10K_AIRTIME_WEIGHT_MULTIPLIER;
8817 ret = ieee80211_register_hw(ar->hw);
8819 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8820 goto err_dfs_detector_exit;
8823 if (test_bit(WMI_SERVICE_PER_PACKET_SW_ENCRYPT, ar->wmi.svc_map)) {
8824 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
8825 ar->hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
8828 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8829 ret = regulatory_hint(ar->hw->wiphy,
8830 ar->ath_common.regulatory.alpha2);
8832 goto err_unregister;
8838 ieee80211_unregister_hw(ar->hw);
8840 err_dfs_detector_exit:
8841 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8842 ar->dfs_detector->exit(ar->dfs_detector);
8845 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8846 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8848 SET_IEEE80211_DEV(ar->hw, NULL);
8852 void ath10k_mac_unregister(struct ath10k *ar)
8854 ieee80211_unregister_hw(ar->hw);
8856 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8857 ar->dfs_detector->exit(ar->dfs_detector);
8859 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8860 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8862 SET_IEEE80211_DEV(ar->hw, NULL);