2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/cfg80211.h>
21 #include <net/mac80211.h>
22 #include <linux/etherdevice.h>
23 #include <linux/acpi.h>
41 static struct ieee80211_rate ath10k_rates[] = {
43 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
45 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
46 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
47 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
49 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
50 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
51 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
53 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
54 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
55 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
57 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
58 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
59 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
60 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
61 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
62 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
63 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
64 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
67 static struct ieee80211_rate ath10k_rates_rev2[] = {
69 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
71 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
72 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
73 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
75 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
76 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
77 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
79 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
80 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
81 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
83 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
84 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
85 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
86 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
87 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
88 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
89 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
90 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
93 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
95 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
96 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
97 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
98 #define ath10k_g_rates (ath10k_rates + 0)
99 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
101 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
102 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
104 static bool ath10k_mac_bitrate_is_cck(int bitrate)
117 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
119 return DIV_ROUND_UP(bitrate, 5) |
120 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
123 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
124 u8 hw_rate, bool cck)
126 const struct ieee80211_rate *rate;
129 for (i = 0; i < sband->n_bitrates; i++) {
130 rate = &sband->bitrates[i];
132 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
135 if (rate->hw_value == hw_rate)
137 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
138 rate->hw_value_short == hw_rate)
145 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
150 for (i = 0; i < sband->n_bitrates; i++)
151 if (sband->bitrates[i].bitrate == bitrate)
157 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
159 switch ((mcs_map >> (2 * nss)) & 0x3) {
160 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
161 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
162 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
168 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
172 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
173 if (ht_mcs_mask[nss])
180 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
184 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
185 if (vht_mcs_mask[nss])
191 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
193 enum wmi_host_platform_type platform_type;
196 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
197 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
199 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
201 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
203 if (ret && ret != -EOPNOTSUPP) {
204 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
215 static int ath10k_send_key(struct ath10k_vif *arvif,
216 struct ieee80211_key_conf *key,
217 enum set_key_cmd cmd,
218 const u8 *macaddr, u32 flags)
220 struct ath10k *ar = arvif->ar;
221 struct wmi_vdev_install_key_arg arg = {
222 .vdev_id = arvif->vdev_id,
223 .key_idx = key->keyidx,
224 .key_len = key->keylen,
225 .key_data = key->key,
230 lockdep_assert_held(&arvif->ar->conf_mutex);
232 switch (key->cipher) {
233 case WLAN_CIPHER_SUITE_CCMP:
234 arg.key_cipher = WMI_CIPHER_AES_CCM;
235 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
237 case WLAN_CIPHER_SUITE_TKIP:
238 arg.key_cipher = WMI_CIPHER_TKIP;
239 arg.key_txmic_len = 8;
240 arg.key_rxmic_len = 8;
242 case WLAN_CIPHER_SUITE_WEP40:
243 case WLAN_CIPHER_SUITE_WEP104:
244 arg.key_cipher = WMI_CIPHER_WEP;
246 case WLAN_CIPHER_SUITE_AES_CMAC:
250 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
254 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
255 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
257 if (cmd == DISABLE_KEY) {
258 arg.key_cipher = WMI_CIPHER_NONE;
262 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
265 static int ath10k_install_key(struct ath10k_vif *arvif,
266 struct ieee80211_key_conf *key,
267 enum set_key_cmd cmd,
268 const u8 *macaddr, u32 flags)
270 struct ath10k *ar = arvif->ar;
272 unsigned long time_left;
274 lockdep_assert_held(&ar->conf_mutex);
276 reinit_completion(&ar->install_key_done);
278 if (arvif->nohwcrypt)
281 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
285 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
292 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
295 struct ath10k *ar = arvif->ar;
296 struct ath10k_peer *peer;
301 lockdep_assert_held(&ar->conf_mutex);
303 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
304 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
305 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
308 spin_lock_bh(&ar->data_lock);
309 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
310 spin_unlock_bh(&ar->data_lock);
315 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
316 if (arvif->wep_keys[i] == NULL)
319 switch (arvif->vif->type) {
320 case NL80211_IFTYPE_AP:
321 flags = WMI_KEY_PAIRWISE;
323 if (arvif->def_wep_key_idx == i)
324 flags |= WMI_KEY_TX_USAGE;
326 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
327 SET_KEY, addr, flags);
331 case NL80211_IFTYPE_ADHOC:
332 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
338 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
339 SET_KEY, addr, WMI_KEY_GROUP);
348 spin_lock_bh(&ar->data_lock);
349 peer->keys[i] = arvif->wep_keys[i];
350 spin_unlock_bh(&ar->data_lock);
353 /* In some cases (notably with static WEP IBSS with multiple keys)
354 * multicast Tx becomes broken. Both pairwise and groupwise keys are
355 * installed already. Using WMI_KEY_TX_USAGE in different combinations
356 * didn't seem help. Using def_keyid vdev parameter seems to be
357 * effective so use that.
359 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
361 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
364 if (arvif->def_wep_key_idx == -1)
367 ret = ath10k_wmi_vdev_set_param(arvif->ar,
369 arvif->ar->wmi.vdev_param->def_keyid,
370 arvif->def_wep_key_idx);
372 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
373 arvif->vdev_id, ret);
380 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
383 struct ath10k *ar = arvif->ar;
384 struct ath10k_peer *peer;
390 lockdep_assert_held(&ar->conf_mutex);
392 spin_lock_bh(&ar->data_lock);
393 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
394 spin_unlock_bh(&ar->data_lock);
399 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
400 if (peer->keys[i] == NULL)
403 /* key flags are not required to delete the key */
404 ret = ath10k_install_key(arvif, peer->keys[i],
405 DISABLE_KEY, addr, flags);
406 if (ret < 0 && first_errno == 0)
410 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
413 spin_lock_bh(&ar->data_lock);
414 peer->keys[i] = NULL;
415 spin_unlock_bh(&ar->data_lock);
421 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
424 struct ath10k_peer *peer;
427 lockdep_assert_held(&ar->data_lock);
429 /* We don't know which vdev this peer belongs to,
430 * since WMI doesn't give us that information.
432 * FIXME: multi-bss needs to be handled.
434 peer = ath10k_peer_find(ar, 0, addr);
438 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
439 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
446 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
447 struct ieee80211_key_conf *key)
449 struct ath10k *ar = arvif->ar;
450 struct ath10k_peer *peer;
457 lockdep_assert_held(&ar->conf_mutex);
460 /* since ath10k_install_key we can't hold data_lock all the
461 * time, so we try to remove the keys incrementally
463 spin_lock_bh(&ar->data_lock);
465 list_for_each_entry(peer, &ar->peers, list) {
466 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
467 if (peer->keys[i] == key) {
468 ether_addr_copy(addr, peer->addr);
469 peer->keys[i] = NULL;
474 if (i < ARRAY_SIZE(peer->keys))
477 spin_unlock_bh(&ar->data_lock);
479 if (i == ARRAY_SIZE(peer->keys))
481 /* key flags are not required to delete the key */
482 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
483 if (ret < 0 && first_errno == 0)
487 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
494 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
495 struct ieee80211_key_conf *key)
497 struct ath10k *ar = arvif->ar;
498 struct ath10k_peer *peer;
501 lockdep_assert_held(&ar->conf_mutex);
503 list_for_each_entry(peer, &ar->peers, list) {
504 if (ether_addr_equal(peer->addr, arvif->vif->addr))
507 if (ether_addr_equal(peer->addr, arvif->bssid))
510 if (peer->keys[key->keyidx] == key)
513 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
514 arvif->vdev_id, key->keyidx);
516 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
518 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
519 arvif->vdev_id, peer->addr, ret);
527 /*********************/
528 /* General utilities */
529 /*********************/
531 static inline enum wmi_phy_mode
532 chan_to_phymode(const struct cfg80211_chan_def *chandef)
534 enum wmi_phy_mode phymode = MODE_UNKNOWN;
536 switch (chandef->chan->band) {
537 case NL80211_BAND_2GHZ:
538 switch (chandef->width) {
539 case NL80211_CHAN_WIDTH_20_NOHT:
540 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
545 case NL80211_CHAN_WIDTH_20:
546 phymode = MODE_11NG_HT20;
548 case NL80211_CHAN_WIDTH_40:
549 phymode = MODE_11NG_HT40;
551 case NL80211_CHAN_WIDTH_5:
552 case NL80211_CHAN_WIDTH_10:
553 case NL80211_CHAN_WIDTH_80:
554 case NL80211_CHAN_WIDTH_80P80:
555 case NL80211_CHAN_WIDTH_160:
556 phymode = MODE_UNKNOWN;
560 case NL80211_BAND_5GHZ:
561 switch (chandef->width) {
562 case NL80211_CHAN_WIDTH_20_NOHT:
565 case NL80211_CHAN_WIDTH_20:
566 phymode = MODE_11NA_HT20;
568 case NL80211_CHAN_WIDTH_40:
569 phymode = MODE_11NA_HT40;
571 case NL80211_CHAN_WIDTH_80:
572 phymode = MODE_11AC_VHT80;
574 case NL80211_CHAN_WIDTH_160:
575 phymode = MODE_11AC_VHT160;
577 case NL80211_CHAN_WIDTH_80P80:
578 phymode = MODE_11AC_VHT80_80;
580 case NL80211_CHAN_WIDTH_5:
581 case NL80211_CHAN_WIDTH_10:
582 phymode = MODE_UNKNOWN;
590 WARN_ON(phymode == MODE_UNKNOWN);
594 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
597 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
598 * 0 for no restriction
607 switch (mpdudensity) {
613 /* Our lower layer calculations limit our precision to
630 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
631 struct cfg80211_chan_def *def)
633 struct ieee80211_chanctx_conf *conf;
636 conf = rcu_dereference(vif->chanctx_conf);
648 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
649 struct ieee80211_chanctx_conf *conf,
657 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
661 ieee80211_iter_chan_contexts_atomic(ar->hw,
662 ath10k_mac_num_chanctxs_iter,
669 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
670 struct ieee80211_chanctx_conf *conf,
673 struct cfg80211_chan_def **def = data;
678 static int ath10k_peer_create(struct ath10k *ar,
679 struct ieee80211_vif *vif,
680 struct ieee80211_sta *sta,
683 enum wmi_peer_type peer_type)
685 struct ath10k_vif *arvif;
686 struct ath10k_peer *peer;
690 lockdep_assert_held(&ar->conf_mutex);
692 num_peers = ar->num_peers;
694 /* Each vdev consumes a peer entry as well */
695 list_for_each_entry(arvif, &ar->arvifs, list)
698 if (num_peers >= ar->max_num_peers)
701 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
703 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
708 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
710 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
715 spin_lock_bh(&ar->data_lock);
717 peer = ath10k_peer_find(ar, vdev_id, addr);
719 spin_unlock_bh(&ar->data_lock);
720 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
722 ath10k_wmi_peer_delete(ar, vdev_id, addr);
729 spin_unlock_bh(&ar->data_lock);
736 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
738 struct ath10k *ar = arvif->ar;
742 param = ar->wmi.pdev_param->sta_kickout_th;
743 ret = ath10k_wmi_pdev_set_param(ar, param,
744 ATH10K_KICKOUT_THRESHOLD);
746 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
747 arvif->vdev_id, ret);
751 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
752 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
753 ATH10K_KEEPALIVE_MIN_IDLE);
755 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
756 arvif->vdev_id, ret);
760 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
761 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
762 ATH10K_KEEPALIVE_MAX_IDLE);
764 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
765 arvif->vdev_id, ret);
769 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
770 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
771 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
773 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
774 arvif->vdev_id, ret);
781 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
783 struct ath10k *ar = arvif->ar;
786 vdev_param = ar->wmi.vdev_param->rts_threshold;
787 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
790 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
794 lockdep_assert_held(&ar->conf_mutex);
796 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
800 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
809 static void ath10k_peer_map_cleanup(struct ath10k *ar, struct ath10k_peer *peer)
813 lockdep_assert_held(&ar->conf_mutex);
815 for_each_set_bit(peer_id, peer->peer_ids,
816 ATH10K_MAX_NUM_PEER_IDS) {
817 ar->peer_map[peer_id] = NULL;
820 /* Double check that peer is properly un-referenced from
823 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
824 if (ar->peer_map[i] == peer) {
825 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
826 peer->addr, peer, i);
827 ar->peer_map[i] = NULL;
831 list_del(&peer->list);
836 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
838 struct ath10k_peer *peer, *tmp;
840 lockdep_assert_held(&ar->conf_mutex);
842 spin_lock_bh(&ar->data_lock);
843 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
844 if (peer->vdev_id != vdev_id)
847 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
848 peer->addr, vdev_id);
850 ath10k_peer_map_cleanup(ar, peer);
852 spin_unlock_bh(&ar->data_lock);
855 static void ath10k_peer_cleanup_all(struct ath10k *ar)
857 struct ath10k_peer *peer, *tmp;
860 lockdep_assert_held(&ar->conf_mutex);
862 spin_lock_bh(&ar->data_lock);
863 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
864 list_del(&peer->list);
868 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
869 ar->peer_map[i] = NULL;
871 spin_unlock_bh(&ar->data_lock);
874 ar->num_stations = 0;
877 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
878 struct ieee80211_sta *sta,
879 enum wmi_tdls_peer_state state)
882 struct wmi_tdls_peer_update_cmd_arg arg = {};
883 struct wmi_tdls_peer_capab_arg cap = {};
884 struct wmi_channel_arg chan_arg = {};
886 lockdep_assert_held(&ar->conf_mutex);
888 arg.vdev_id = vdev_id;
889 arg.peer_state = state;
890 ether_addr_copy(arg.addr, sta->addr);
892 cap.peer_max_sp = sta->max_sp;
893 cap.peer_uapsd_queues = sta->uapsd_queues;
895 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
896 !sta->tdls_initiator)
897 cap.is_peer_responder = 1;
899 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
901 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
902 arg.addr, vdev_id, ret);
909 /************************/
910 /* Interface management */
911 /************************/
913 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
915 struct ath10k *ar = arvif->ar;
917 lockdep_assert_held(&ar->data_lock);
922 if (!arvif->beacon_buf)
923 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
924 arvif->beacon->len, DMA_TO_DEVICE);
926 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
927 arvif->beacon_state != ATH10K_BEACON_SENT))
930 dev_kfree_skb_any(arvif->beacon);
932 arvif->beacon = NULL;
933 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
936 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
938 struct ath10k *ar = arvif->ar;
940 lockdep_assert_held(&ar->data_lock);
942 ath10k_mac_vif_beacon_free(arvif);
944 if (arvif->beacon_buf) {
945 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
946 arvif->beacon_buf, arvif->beacon_paddr);
947 arvif->beacon_buf = NULL;
951 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
953 unsigned long time_left;
955 lockdep_assert_held(&ar->conf_mutex);
957 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
960 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
961 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
965 return ar->last_wmi_vdev_start_status;
968 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
970 struct cfg80211_chan_def *chandef = NULL;
971 struct ieee80211_channel *channel = NULL;
972 struct wmi_vdev_start_request_arg arg = {};
975 lockdep_assert_held(&ar->conf_mutex);
977 ieee80211_iter_chan_contexts_atomic(ar->hw,
978 ath10k_mac_get_any_chandef_iter,
980 if (WARN_ON_ONCE(!chandef))
983 channel = chandef->chan;
985 arg.vdev_id = vdev_id;
986 arg.channel.freq = channel->center_freq;
987 arg.channel.band_center_freq1 = chandef->center_freq1;
988 arg.channel.band_center_freq2 = chandef->center_freq2;
990 /* TODO setup this dynamically, what in case we
991 * don't have any vifs?
993 arg.channel.mode = chan_to_phymode(chandef);
994 arg.channel.chan_radar =
995 !!(channel->flags & IEEE80211_CHAN_RADAR);
997 arg.channel.min_power = 0;
998 arg.channel.max_power = channel->max_power * 2;
999 arg.channel.max_reg_power = channel->max_reg_power * 2;
1000 arg.channel.max_antenna_gain = channel->max_antenna_gain;
1002 reinit_completion(&ar->vdev_setup_done);
1004 ret = ath10k_wmi_vdev_start(ar, &arg);
1006 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1011 ret = ath10k_vdev_setup_sync(ar);
1013 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1018 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1020 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1025 ar->monitor_vdev_id = vdev_id;
1027 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1028 ar->monitor_vdev_id);
1032 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1034 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1035 ar->monitor_vdev_id, ret);
1040 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1044 lockdep_assert_held(&ar->conf_mutex);
1046 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1048 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1049 ar->monitor_vdev_id, ret);
1051 reinit_completion(&ar->vdev_setup_done);
1053 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1055 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1056 ar->monitor_vdev_id, ret);
1058 ret = ath10k_vdev_setup_sync(ar);
1060 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1061 ar->monitor_vdev_id, ret);
1063 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1064 ar->monitor_vdev_id);
1068 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1072 lockdep_assert_held(&ar->conf_mutex);
1074 if (ar->free_vdev_map == 0) {
1075 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1079 bit = __ffs64(ar->free_vdev_map);
1081 ar->monitor_vdev_id = bit;
1083 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1084 WMI_VDEV_TYPE_MONITOR,
1087 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1088 ar->monitor_vdev_id, ret);
1092 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1093 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1094 ar->monitor_vdev_id);
1099 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1103 lockdep_assert_held(&ar->conf_mutex);
1105 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1107 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1108 ar->monitor_vdev_id, ret);
1112 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1114 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1115 ar->monitor_vdev_id);
1119 static int ath10k_monitor_start(struct ath10k *ar)
1123 lockdep_assert_held(&ar->conf_mutex);
1125 ret = ath10k_monitor_vdev_create(ar);
1127 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1131 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1133 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1134 ath10k_monitor_vdev_delete(ar);
1138 ar->monitor_started = true;
1139 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1144 static int ath10k_monitor_stop(struct ath10k *ar)
1148 lockdep_assert_held(&ar->conf_mutex);
1150 ret = ath10k_monitor_vdev_stop(ar);
1152 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1156 ret = ath10k_monitor_vdev_delete(ar);
1158 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1162 ar->monitor_started = false;
1163 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1168 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1172 /* At least one chanctx is required to derive a channel to start
1175 num_ctx = ath10k_mac_num_chanctxs(ar);
1179 /* If there's already an existing special monitor interface then don't
1180 * bother creating another monitor vdev.
1182 if (ar->monitor_arvif)
1185 return ar->monitor ||
1186 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1187 ar->running_fw->fw_file.fw_features) &&
1188 (ar->filter_flags & FIF_OTHER_BSS)) ||
1189 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1192 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1196 num_ctx = ath10k_mac_num_chanctxs(ar);
1198 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1199 * shouldn't allow this but make sure to prevent handling the following
1200 * case anyway since multi-channel DFS hasn't been tested at all.
1202 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1208 static int ath10k_monitor_recalc(struct ath10k *ar)
1214 lockdep_assert_held(&ar->conf_mutex);
1216 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1217 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1219 ath10k_dbg(ar, ATH10K_DBG_MAC,
1220 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1221 ar->monitor_started, needed, allowed);
1223 if (WARN_ON(needed && !allowed)) {
1224 if (ar->monitor_started) {
1225 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1227 ret = ath10k_monitor_stop(ar);
1229 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1237 if (needed == ar->monitor_started)
1241 return ath10k_monitor_start(ar);
1243 return ath10k_monitor_stop(ar);
1246 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1248 struct ath10k *ar = arvif->ar;
1250 lockdep_assert_held(&ar->conf_mutex);
1252 if (!arvif->is_started) {
1253 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1260 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1262 struct ath10k *ar = arvif->ar;
1265 lockdep_assert_held(&ar->conf_mutex);
1267 vdev_param = ar->wmi.vdev_param->protection_mode;
1269 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1270 arvif->vdev_id, arvif->use_cts_prot);
1272 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1273 arvif->use_cts_prot ? 1 : 0);
1276 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1278 struct ath10k *ar = arvif->ar;
1279 u32 vdev_param, rts_cts = 0;
1281 lockdep_assert_held(&ar->conf_mutex);
1283 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1285 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1287 if (arvif->num_legacy_stations > 0)
1288 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1289 WMI_RTSCTS_PROFILE);
1291 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1292 WMI_RTSCTS_PROFILE);
1294 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1295 arvif->vdev_id, rts_cts);
1297 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1301 static int ath10k_start_cac(struct ath10k *ar)
1305 lockdep_assert_held(&ar->conf_mutex);
1307 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1309 ret = ath10k_monitor_recalc(ar);
1311 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1312 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1317 ar->monitor_vdev_id);
1322 static int ath10k_stop_cac(struct ath10k *ar)
1324 lockdep_assert_held(&ar->conf_mutex);
1326 /* CAC is not running - do nothing */
1327 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1330 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1331 ath10k_monitor_stop(ar);
1333 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1338 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1339 struct ieee80211_chanctx_conf *conf,
1344 if (!*ret && conf->radar_enabled)
1348 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1350 bool has_radar = false;
1352 ieee80211_iter_chan_contexts_atomic(ar->hw,
1353 ath10k_mac_has_radar_iter,
1359 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1363 lockdep_assert_held(&ar->conf_mutex);
1365 ath10k_stop_cac(ar);
1367 if (!ath10k_mac_has_radar_enabled(ar))
1370 if (ar->num_started_vdevs > 0)
1373 ret = ath10k_start_cac(ar);
1376 * Not possible to start CAC on current channel so starting
1377 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1378 * by indicating that radar was detected.
1380 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1381 ieee80211_radar_detected(ar->hw);
1385 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1387 struct ath10k *ar = arvif->ar;
1390 lockdep_assert_held(&ar->conf_mutex);
1392 reinit_completion(&ar->vdev_setup_done);
1394 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1396 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1397 arvif->vdev_id, ret);
1401 ret = ath10k_vdev_setup_sync(ar);
1403 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1404 arvif->vdev_id, ret);
1408 WARN_ON(ar->num_started_vdevs == 0);
1410 if (ar->num_started_vdevs != 0) {
1411 ar->num_started_vdevs--;
1412 ath10k_recalc_radar_detection(ar);
1418 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1419 const struct cfg80211_chan_def *chandef,
1422 struct ath10k *ar = arvif->ar;
1423 struct wmi_vdev_start_request_arg arg = {};
1426 lockdep_assert_held(&ar->conf_mutex);
1428 reinit_completion(&ar->vdev_setup_done);
1430 arg.vdev_id = arvif->vdev_id;
1431 arg.dtim_period = arvif->dtim_period;
1432 arg.bcn_intval = arvif->beacon_interval;
1434 arg.channel.freq = chandef->chan->center_freq;
1435 arg.channel.band_center_freq1 = chandef->center_freq1;
1436 arg.channel.band_center_freq2 = chandef->center_freq2;
1437 arg.channel.mode = chan_to_phymode(chandef);
1439 arg.channel.min_power = 0;
1440 arg.channel.max_power = chandef->chan->max_power * 2;
1441 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1442 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
1444 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1445 arg.ssid = arvif->u.ap.ssid;
1446 arg.ssid_len = arvif->u.ap.ssid_len;
1447 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1449 /* For now allow DFS for AP mode */
1450 arg.channel.chan_radar =
1451 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1452 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1453 arg.ssid = arvif->vif->bss_conf.ssid;
1454 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1457 ath10k_dbg(ar, ATH10K_DBG_MAC,
1458 "mac vdev %d start center_freq %d phymode %s\n",
1459 arg.vdev_id, arg.channel.freq,
1460 ath10k_wmi_phymode_str(arg.channel.mode));
1463 ret = ath10k_wmi_vdev_restart(ar, &arg);
1465 ret = ath10k_wmi_vdev_start(ar, &arg);
1468 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1473 ret = ath10k_vdev_setup_sync(ar);
1476 "failed to synchronize setup for vdev %i restart %d: %d\n",
1477 arg.vdev_id, restart, ret);
1481 ar->num_started_vdevs++;
1482 ath10k_recalc_radar_detection(ar);
1487 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1488 const struct cfg80211_chan_def *def)
1490 return ath10k_vdev_start_restart(arvif, def, false);
1493 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1494 const struct cfg80211_chan_def *def)
1496 return ath10k_vdev_start_restart(arvif, def, true);
1499 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1500 struct sk_buff *bcn)
1502 struct ath10k *ar = arvif->ar;
1503 struct ieee80211_mgmt *mgmt;
1507 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1510 mgmt = (void *)bcn->data;
1511 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1512 mgmt->u.beacon.variable,
1513 bcn->len - (mgmt->u.beacon.variable -
1518 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1520 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1521 arvif->vdev_id, ret);
1528 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1529 u8 oui_type, size_t ie_offset)
1536 if (WARN_ON(skb->len < ie_offset))
1539 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1540 skb->data + ie_offset,
1541 skb->len - ie_offset);
1546 end = skb->data + skb->len;
1549 if (WARN_ON(next > end))
1552 memmove(ie, next, end - next);
1553 skb_trim(skb, skb->len - len);
1558 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1560 struct ath10k *ar = arvif->ar;
1561 struct ieee80211_hw *hw = ar->hw;
1562 struct ieee80211_vif *vif = arvif->vif;
1563 struct ieee80211_mutable_offsets offs = {};
1564 struct sk_buff *bcn;
1567 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1570 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1571 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1574 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1576 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1580 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1582 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1587 /* P2P IE is inserted by firmware automatically (as configured above)
1588 * so remove it from the base beacon template to avoid duplicate P2P
1589 * IEs in beacon frames.
1591 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1592 offsetof(struct ieee80211_mgmt,
1593 u.beacon.variable));
1595 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1600 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1608 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1610 struct ath10k *ar = arvif->ar;
1611 struct ieee80211_hw *hw = ar->hw;
1612 struct ieee80211_vif *vif = arvif->vif;
1613 struct sk_buff *prb;
1616 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1619 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1622 /* For mesh, probe response and beacon share the same template */
1623 if (ieee80211_vif_is_mesh(vif))
1626 prb = ieee80211_proberesp_get(hw, vif);
1628 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1632 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1636 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1644 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1646 struct ath10k *ar = arvif->ar;
1647 struct cfg80211_chan_def def;
1650 /* When originally vdev is started during assign_vif_chanctx() some
1651 * information is missing, notably SSID. Firmware revisions with beacon
1652 * offloading require the SSID to be provided during vdev (re)start to
1653 * handle hidden SSID properly.
1655 * Vdev restart must be done after vdev has been both started and
1656 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1657 * deliver vdev restart response event causing timeouts during vdev
1658 * syncing in ath10k.
1660 * Note: The vdev down/up and template reinstallation could be skipped
1661 * since only wmi-tlv firmware are known to have beacon offload and
1662 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1663 * response delivery. It's probably more robust to keep it as is.
1665 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1668 if (WARN_ON(!arvif->is_started))
1671 if (WARN_ON(!arvif->is_up))
1674 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1677 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1679 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1680 arvif->vdev_id, ret);
1684 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1685 * firmware will crash upon vdev up.
1688 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1690 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1694 ret = ath10k_mac_setup_prb_tmpl(arvif);
1696 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1700 ret = ath10k_vdev_restart(arvif, &def);
1702 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1703 arvif->vdev_id, ret);
1707 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1710 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1711 arvif->vdev_id, ret);
1718 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1719 struct ieee80211_bss_conf *info)
1721 struct ath10k *ar = arvif->ar;
1724 lockdep_assert_held(&arvif->ar->conf_mutex);
1726 if (!info->enable_beacon) {
1727 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1729 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1730 arvif->vdev_id, ret);
1732 arvif->is_up = false;
1734 spin_lock_bh(&arvif->ar->data_lock);
1735 ath10k_mac_vif_beacon_free(arvif);
1736 spin_unlock_bh(&arvif->ar->data_lock);
1741 arvif->tx_seq_no = 0x1000;
1744 ether_addr_copy(arvif->bssid, info->bssid);
1746 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1749 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1750 arvif->vdev_id, ret);
1754 arvif->is_up = true;
1756 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1758 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1759 arvif->vdev_id, ret);
1763 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1766 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1767 struct ieee80211_bss_conf *info,
1768 const u8 self_peer[ETH_ALEN])
1770 struct ath10k *ar = arvif->ar;
1774 lockdep_assert_held(&arvif->ar->conf_mutex);
1776 if (!info->ibss_joined) {
1777 if (is_zero_ether_addr(arvif->bssid))
1780 eth_zero_addr(arvif->bssid);
1785 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1786 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1787 ATH10K_DEFAULT_ATIM);
1789 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1790 arvif->vdev_id, ret);
1793 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1795 struct ath10k *ar = arvif->ar;
1800 lockdep_assert_held(&arvif->ar->conf_mutex);
1802 if (arvif->u.sta.uapsd)
1803 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1805 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1807 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1808 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1810 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1811 value, arvif->vdev_id, ret);
1818 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1820 struct ath10k *ar = arvif->ar;
1825 lockdep_assert_held(&arvif->ar->conf_mutex);
1827 if (arvif->u.sta.uapsd)
1828 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1830 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1832 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1833 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1836 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1837 value, arvif->vdev_id, ret);
1844 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1846 struct ath10k_vif *arvif;
1849 lockdep_assert_held(&ar->conf_mutex);
1851 list_for_each_entry(arvif, &ar->arvifs, list)
1852 if (arvif->is_started)
1858 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1860 struct ath10k *ar = arvif->ar;
1861 struct ieee80211_vif *vif = arvif->vif;
1862 struct ieee80211_conf *conf = &ar->hw->conf;
1863 enum wmi_sta_powersave_param param;
1864 enum wmi_sta_ps_mode psmode;
1869 lockdep_assert_held(&arvif->ar->conf_mutex);
1871 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1874 enable_ps = arvif->ps;
1876 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1877 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1878 ar->running_fw->fw_file.fw_features)) {
1879 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1884 if (!arvif->is_started) {
1885 /* mac80211 can update vif powersave state while disconnected.
1886 * Firmware doesn't behave nicely and consumes more power than
1887 * necessary if PS is disabled on a non-started vdev. Hence
1888 * force-enable PS for non-running vdevs.
1890 psmode = WMI_STA_PS_MODE_ENABLED;
1891 } else if (enable_ps) {
1892 psmode = WMI_STA_PS_MODE_ENABLED;
1893 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1895 ps_timeout = conf->dynamic_ps_timeout;
1896 if (ps_timeout == 0) {
1897 /* Firmware doesn't like 0 */
1898 ps_timeout = ieee80211_tu_to_usec(
1899 vif->bss_conf.beacon_int) / 1000;
1902 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1905 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1906 arvif->vdev_id, ret);
1910 psmode = WMI_STA_PS_MODE_DISABLED;
1913 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1914 arvif->vdev_id, psmode ? "enable" : "disable");
1916 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1918 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1919 psmode, arvif->vdev_id, ret);
1926 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1928 struct ath10k *ar = arvif->ar;
1929 struct wmi_sta_keepalive_arg arg = {};
1932 lockdep_assert_held(&arvif->ar->conf_mutex);
1934 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1937 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1940 /* Some firmware revisions have a bug and ignore the `enabled` field.
1941 * Instead use the interval to disable the keepalive.
1943 arg.vdev_id = arvif->vdev_id;
1945 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1946 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1948 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1950 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1951 arvif->vdev_id, ret);
1958 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1960 struct ath10k *ar = arvif->ar;
1961 struct ieee80211_vif *vif = arvif->vif;
1964 lockdep_assert_held(&arvif->ar->conf_mutex);
1966 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1969 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1972 if (!vif->csa_active)
1978 if (!ieee80211_csa_is_complete(vif)) {
1979 ieee80211_csa_update_counter(vif);
1981 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1983 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1986 ret = ath10k_mac_setup_prb_tmpl(arvif);
1988 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1991 ieee80211_csa_finish(vif);
1995 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1997 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1999 struct ath10k *ar = arvif->ar;
2001 mutex_lock(&ar->conf_mutex);
2002 ath10k_mac_vif_ap_csa_count_down(arvif);
2003 mutex_unlock(&ar->conf_mutex);
2006 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2007 struct ieee80211_vif *vif)
2009 struct sk_buff *skb = data;
2010 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2011 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2013 if (vif->type != NL80211_IFTYPE_STATION)
2016 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2019 cancel_delayed_work(&arvif->connection_loss_work);
2022 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2024 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2025 IEEE80211_IFACE_ITER_NORMAL,
2026 ath10k_mac_handle_beacon_iter,
2030 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2031 struct ieee80211_vif *vif)
2033 u32 *vdev_id = data;
2034 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2035 struct ath10k *ar = arvif->ar;
2036 struct ieee80211_hw *hw = ar->hw;
2038 if (arvif->vdev_id != *vdev_id)
2044 ieee80211_beacon_loss(vif);
2046 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2047 * (done by mac80211) succeeds but beacons do not resume then it
2048 * doesn't make sense to continue operation. Queue connection loss work
2049 * which can be cancelled when beacon is received.
2051 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2052 ATH10K_CONNECTION_LOSS_HZ);
2055 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2057 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2058 IEEE80211_IFACE_ITER_NORMAL,
2059 ath10k_mac_handle_beacon_miss_iter,
2063 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2065 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2066 connection_loss_work.work);
2067 struct ieee80211_vif *vif = arvif->vif;
2072 ieee80211_connection_loss(vif);
2075 /**********************/
2076 /* Station management */
2077 /**********************/
2079 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2080 struct ieee80211_vif *vif)
2082 /* Some firmware revisions have unstable STA powersave when listen
2083 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2084 * generate NullFunc frames properly even if buffered frames have been
2085 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2086 * buffered frames. Often pinging the device from AP would simply fail.
2088 * As a workaround set it to 1.
2090 if (vif->type == NL80211_IFTYPE_STATION)
2093 return ar->hw->conf.listen_interval;
2096 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2097 struct ieee80211_vif *vif,
2098 struct ieee80211_sta *sta,
2099 struct wmi_peer_assoc_complete_arg *arg)
2101 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2104 lockdep_assert_held(&ar->conf_mutex);
2106 if (vif->type == NL80211_IFTYPE_STATION)
2107 aid = vif->bss_conf.aid;
2111 ether_addr_copy(arg->addr, sta->addr);
2112 arg->vdev_id = arvif->vdev_id;
2113 arg->peer_aid = aid;
2114 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2115 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2116 arg->peer_num_spatial_streams = 1;
2117 arg->peer_caps = vif->bss_conf.assoc_capability;
2120 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2121 struct ieee80211_vif *vif,
2122 struct ieee80211_sta *sta,
2123 struct wmi_peer_assoc_complete_arg *arg)
2125 struct ieee80211_bss_conf *info = &vif->bss_conf;
2126 struct cfg80211_chan_def def;
2127 struct cfg80211_bss *bss;
2128 const u8 *rsnie = NULL;
2129 const u8 *wpaie = NULL;
2131 lockdep_assert_held(&ar->conf_mutex);
2133 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2136 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2137 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2139 const struct cfg80211_bss_ies *ies;
2142 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2144 ies = rcu_dereference(bss->ies);
2146 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2147 WLAN_OUI_TYPE_MICROSOFT_WPA,
2151 cfg80211_put_bss(ar->hw->wiphy, bss);
2154 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2155 if (rsnie || wpaie) {
2156 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2157 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2161 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2162 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2166 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2167 ar->running_fw->fw_file.fw_features)) {
2168 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2172 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2173 struct ieee80211_vif *vif,
2174 struct ieee80211_sta *sta,
2175 struct wmi_peer_assoc_complete_arg *arg)
2177 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2178 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2179 struct cfg80211_chan_def def;
2180 const struct ieee80211_supported_band *sband;
2181 const struct ieee80211_rate *rates;
2182 enum nl80211_band band;
2187 lockdep_assert_held(&ar->conf_mutex);
2189 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2192 band = def.chan->band;
2193 sband = ar->hw->wiphy->bands[band];
2194 ratemask = sta->supp_rates[band];
2195 ratemask &= arvif->bitrate_mask.control[band].legacy;
2196 rates = sband->bitrates;
2198 rateset->num_rates = 0;
2200 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2201 if (!(ratemask & 1))
2204 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2205 rateset->rates[rateset->num_rates] = rate;
2206 rateset->num_rates++;
2211 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2215 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2216 if (ht_mcs_mask[nss])
2223 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2227 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2228 if (vht_mcs_mask[nss])
2234 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2235 struct ieee80211_vif *vif,
2236 struct ieee80211_sta *sta,
2237 struct wmi_peer_assoc_complete_arg *arg)
2239 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2240 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2241 struct cfg80211_chan_def def;
2242 enum nl80211_band band;
2243 const u8 *ht_mcs_mask;
2244 const u16 *vht_mcs_mask;
2249 lockdep_assert_held(&ar->conf_mutex);
2251 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2254 if (!ht_cap->ht_supported)
2257 band = def.chan->band;
2258 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2259 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2261 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2262 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2265 arg->peer_flags |= ar->wmi.peer_flags->ht;
2266 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2267 ht_cap->ampdu_factor)) - 1;
2269 arg->peer_mpdu_density =
2270 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2272 arg->peer_ht_caps = ht_cap->cap;
2273 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2275 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2276 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2278 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2279 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2280 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2283 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2284 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2285 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2287 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2288 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2291 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2292 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2293 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2296 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2297 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2298 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2299 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2300 arg->peer_rate_caps |= stbc;
2301 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2304 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2305 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2306 else if (ht_cap->mcs.rx_mask[1])
2307 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2309 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2310 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2311 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2312 max_nss = (i / 8) + 1;
2313 arg->peer_ht_rates.rates[n++] = i;
2317 * This is a workaround for HT-enabled STAs which break the spec
2318 * and have no HT capabilities RX mask (no HT RX MCS map).
2320 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2321 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2323 * Firmware asserts if such situation occurs.
2326 arg->peer_ht_rates.num_rates = 8;
2327 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2328 arg->peer_ht_rates.rates[i] = i;
2330 arg->peer_ht_rates.num_rates = n;
2331 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2334 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2336 arg->peer_ht_rates.num_rates,
2337 arg->peer_num_spatial_streams);
2340 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2341 struct ath10k_vif *arvif,
2342 struct ieee80211_sta *sta)
2348 lockdep_assert_held(&ar->conf_mutex);
2350 if (sta->wme && sta->uapsd_queues) {
2351 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2352 sta->uapsd_queues, sta->max_sp);
2354 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2355 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2356 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2357 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2358 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2359 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2360 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2361 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2362 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2363 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2364 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2365 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2367 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2368 max_sp = sta->max_sp;
2370 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2372 WMI_AP_PS_PEER_PARAM_UAPSD,
2375 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2376 arvif->vdev_id, ret);
2380 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2382 WMI_AP_PS_PEER_PARAM_MAX_SP,
2385 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2386 arvif->vdev_id, ret);
2390 /* TODO setup this based on STA listen interval and
2391 * beacon interval. Currently we don't know
2392 * sta->listen_interval - mac80211 patch required.
2393 * Currently use 10 seconds
2395 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2396 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2399 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2400 arvif->vdev_id, ret);
2409 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2410 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2417 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2418 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2422 idx_limit = fls(mcs_map) - 1;
2426 switch (idx_limit) {
2427 case 0: /* fall through */
2428 case 1: /* fall through */
2429 case 2: /* fall through */
2430 case 3: /* fall through */
2431 case 4: /* fall through */
2432 case 5: /* fall through */
2433 case 6: /* fall through */
2435 /* see ath10k_mac_can_set_bitrate_mask() */
2439 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2442 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2445 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2448 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2452 tx_mcs_set &= ~(0x3 << (nss * 2));
2453 tx_mcs_set |= mcs << (nss * 2);
2459 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2460 struct ieee80211_vif *vif,
2461 struct ieee80211_sta *sta,
2462 struct wmi_peer_assoc_complete_arg *arg)
2464 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2465 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2466 struct cfg80211_chan_def def;
2467 enum nl80211_band band;
2468 const u16 *vht_mcs_mask;
2470 u8 max_nss, vht_mcs;
2473 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2476 if (!vht_cap->vht_supported)
2479 band = def.chan->band;
2480 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2482 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2485 arg->peer_flags |= ar->wmi.peer_flags->vht;
2487 if (def.chan->band == NL80211_BAND_2GHZ)
2488 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2490 arg->peer_vht_caps = vht_cap->cap;
2492 ampdu_factor = (vht_cap->cap &
2493 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2494 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2496 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2497 * zero in VHT IE. Using it would result in degraded throughput.
2498 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2499 * it if VHT max_mpdu is smaller.
2501 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2502 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2503 ampdu_factor)) - 1);
2505 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2506 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2508 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2509 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2511 /* Calculate peer NSS capability from VHT capabilities if STA
2514 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2515 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2518 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2522 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2523 arg->peer_vht_rates.rx_max_rate =
2524 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2525 arg->peer_vht_rates.rx_mcs_set =
2526 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2527 arg->peer_vht_rates.tx_max_rate =
2528 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2529 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2530 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2532 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2533 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2535 if (arg->peer_vht_rates.rx_max_rate &&
2536 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2537 switch (arg->peer_vht_rates.rx_max_rate) {
2539 /* Must be 2x2 at 160Mhz is all it can do. */
2540 arg->peer_bw_rxnss_override = 2;
2543 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2544 arg->peer_bw_rxnss_override = 1;
2550 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2551 struct ieee80211_vif *vif,
2552 struct ieee80211_sta *sta,
2553 struct wmi_peer_assoc_complete_arg *arg)
2555 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2557 switch (arvif->vdev_type) {
2558 case WMI_VDEV_TYPE_AP:
2560 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2562 if (sta->wme && sta->uapsd_queues) {
2563 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2564 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2567 case WMI_VDEV_TYPE_STA:
2569 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2571 case WMI_VDEV_TYPE_IBSS:
2573 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2579 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2580 sta->addr, !!(arg->peer_flags &
2581 arvif->ar->wmi.peer_flags->qos));
2584 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2586 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2587 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2590 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2591 struct ieee80211_sta *sta)
2593 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2594 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2595 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2596 return MODE_11AC_VHT160;
2597 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2598 return MODE_11AC_VHT80_80;
2600 /* not sure if this is a valid case? */
2601 return MODE_11AC_VHT160;
2605 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2606 return MODE_11AC_VHT80;
2608 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2609 return MODE_11AC_VHT40;
2611 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2612 return MODE_11AC_VHT20;
2614 return MODE_UNKNOWN;
2617 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2618 struct ieee80211_vif *vif,
2619 struct ieee80211_sta *sta,
2620 struct wmi_peer_assoc_complete_arg *arg)
2622 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2623 struct cfg80211_chan_def def;
2624 enum nl80211_band band;
2625 const u8 *ht_mcs_mask;
2626 const u16 *vht_mcs_mask;
2627 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2629 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2632 band = def.chan->band;
2633 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2634 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2637 case NL80211_BAND_2GHZ:
2638 if (sta->vht_cap.vht_supported &&
2639 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2640 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2641 phymode = MODE_11AC_VHT40;
2643 phymode = MODE_11AC_VHT20;
2644 } else if (sta->ht_cap.ht_supported &&
2645 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2646 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2647 phymode = MODE_11NG_HT40;
2649 phymode = MODE_11NG_HT20;
2650 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2657 case NL80211_BAND_5GHZ:
2661 if (sta->vht_cap.vht_supported &&
2662 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2663 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2664 } else if (sta->ht_cap.ht_supported &&
2665 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2666 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2667 phymode = MODE_11NA_HT40;
2669 phymode = MODE_11NA_HT20;
2679 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2680 sta->addr, ath10k_wmi_phymode_str(phymode));
2682 arg->peer_phymode = phymode;
2683 WARN_ON(phymode == MODE_UNKNOWN);
2686 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2687 struct ieee80211_vif *vif,
2688 struct ieee80211_sta *sta,
2689 struct wmi_peer_assoc_complete_arg *arg)
2691 lockdep_assert_held(&ar->conf_mutex);
2693 memset(arg, 0, sizeof(*arg));
2695 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2696 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2697 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2698 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2699 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2700 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2701 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2706 static const u32 ath10k_smps_map[] = {
2707 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2708 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2709 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2710 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2713 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2715 const struct ieee80211_sta_ht_cap *ht_cap)
2719 if (!ht_cap->ht_supported)
2722 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2723 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2725 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2728 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2729 WMI_PEER_SMPS_STATE,
2730 ath10k_smps_map[smps]);
2733 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2734 struct ieee80211_vif *vif,
2735 struct ieee80211_sta_vht_cap vht_cap)
2737 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2742 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2745 if (!(ar->vht_cap_info &
2746 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2747 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2748 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2749 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2752 param = ar->wmi.vdev_param->txbf;
2755 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2758 /* The following logic is correct. If a remote STA advertises support
2759 * for being a beamformer then we should enable us being a beamformee.
2762 if (ar->vht_cap_info &
2763 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2764 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2765 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2766 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2768 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2769 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2772 if (ar->vht_cap_info &
2773 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2774 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2775 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2776 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2778 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2779 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2782 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2783 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2785 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2786 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2788 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2790 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2798 /* can be called only in mac80211 callbacks due to `key_count` usage */
2799 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2800 struct ieee80211_vif *vif,
2801 struct ieee80211_bss_conf *bss_conf)
2803 struct ath10k *ar = hw->priv;
2804 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2805 struct ieee80211_sta_ht_cap ht_cap;
2806 struct ieee80211_sta_vht_cap vht_cap;
2807 struct wmi_peer_assoc_complete_arg peer_arg;
2808 struct ieee80211_sta *ap_sta;
2811 lockdep_assert_held(&ar->conf_mutex);
2813 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2814 arvif->vdev_id, arvif->bssid, arvif->aid);
2818 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2820 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2821 bss_conf->bssid, arvif->vdev_id);
2826 /* ap_sta must be accessed only within rcu section which must be left
2827 * before calling ath10k_setup_peer_smps() which might sleep.
2829 ht_cap = ap_sta->ht_cap;
2830 vht_cap = ap_sta->vht_cap;
2832 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2834 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2835 bss_conf->bssid, arvif->vdev_id, ret);
2842 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2844 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2845 bss_conf->bssid, arvif->vdev_id, ret);
2849 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2851 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2852 arvif->vdev_id, ret);
2856 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2858 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2859 arvif->vdev_id, bss_conf->bssid, ret);
2863 ath10k_dbg(ar, ATH10K_DBG_MAC,
2864 "mac vdev %d up (associated) bssid %pM aid %d\n",
2865 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2867 WARN_ON(arvif->is_up);
2869 arvif->aid = bss_conf->aid;
2870 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2872 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2874 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2875 arvif->vdev_id, ret);
2879 arvif->is_up = true;
2881 /* Workaround: Some firmware revisions (tested with qca6174
2882 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2883 * poked with peer param command.
2885 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2886 WMI_PEER_DUMMY_VAR, 1);
2888 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2889 arvif->bssid, arvif->vdev_id, ret);
2894 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2895 struct ieee80211_vif *vif)
2897 struct ath10k *ar = hw->priv;
2898 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2899 struct ieee80211_sta_vht_cap vht_cap = {};
2902 lockdep_assert_held(&ar->conf_mutex);
2904 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2905 arvif->vdev_id, arvif->bssid);
2907 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2909 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2910 arvif->vdev_id, ret);
2912 arvif->def_wep_key_idx = -1;
2914 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2916 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2917 arvif->vdev_id, ret);
2921 arvif->is_up = false;
2923 cancel_delayed_work_sync(&arvif->connection_loss_work);
2926 static int ath10k_station_assoc(struct ath10k *ar,
2927 struct ieee80211_vif *vif,
2928 struct ieee80211_sta *sta,
2931 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2932 struct wmi_peer_assoc_complete_arg peer_arg;
2935 lockdep_assert_held(&ar->conf_mutex);
2937 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2939 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2940 sta->addr, arvif->vdev_id, ret);
2944 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2946 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2947 sta->addr, arvif->vdev_id, ret);
2951 /* Re-assoc is run only to update supported rates for given station. It
2952 * doesn't make much sense to reconfigure the peer completely.
2955 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2958 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2959 arvif->vdev_id, ret);
2963 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2965 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2966 sta->addr, arvif->vdev_id, ret);
2971 arvif->num_legacy_stations++;
2972 ret = ath10k_recalc_rtscts_prot(arvif);
2974 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2975 arvif->vdev_id, ret);
2980 /* Plumb cached keys only for static WEP */
2981 if (arvif->def_wep_key_idx != -1) {
2982 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2984 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2985 arvif->vdev_id, ret);
2994 static int ath10k_station_disassoc(struct ath10k *ar,
2995 struct ieee80211_vif *vif,
2996 struct ieee80211_sta *sta)
2998 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3001 lockdep_assert_held(&ar->conf_mutex);
3004 arvif->num_legacy_stations--;
3005 ret = ath10k_recalc_rtscts_prot(arvif);
3007 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3008 arvif->vdev_id, ret);
3013 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3015 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3016 arvif->vdev_id, ret);
3027 static int ath10k_update_channel_list(struct ath10k *ar)
3029 struct ieee80211_hw *hw = ar->hw;
3030 struct ieee80211_supported_band **bands;
3031 enum nl80211_band band;
3032 struct ieee80211_channel *channel;
3033 struct wmi_scan_chan_list_arg arg = {0};
3034 struct wmi_channel_arg *ch;
3040 lockdep_assert_held(&ar->conf_mutex);
3042 bands = hw->wiphy->bands;
3043 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3047 for (i = 0; i < bands[band]->n_channels; i++) {
3048 if (bands[band]->channels[i].flags &
3049 IEEE80211_CHAN_DISABLED)
3056 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3057 arg.channels = kzalloc(len, GFP_KERNEL);
3062 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3066 for (i = 0; i < bands[band]->n_channels; i++) {
3067 channel = &bands[band]->channels[i];
3069 if (channel->flags & IEEE80211_CHAN_DISABLED)
3072 ch->allow_ht = true;
3074 /* FIXME: when should we really allow VHT? */
3075 ch->allow_vht = true;
3078 !(channel->flags & IEEE80211_CHAN_NO_IR);
3081 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3084 !!(channel->flags & IEEE80211_CHAN_RADAR);
3086 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3087 ch->passive = passive;
3089 /* the firmware is ignoring the "radar" flag of the
3090 * channel and is scanning actively using Probe Requests
3091 * on "Radar detection"/DFS channels which are not
3092 * marked as "available"
3094 ch->passive |= ch->chan_radar;
3096 ch->freq = channel->center_freq;
3097 ch->band_center_freq1 = channel->center_freq;
3099 ch->max_power = channel->max_power * 2;
3100 ch->max_reg_power = channel->max_reg_power * 2;
3101 ch->max_antenna_gain = channel->max_antenna_gain;
3102 ch->reg_class_id = 0; /* FIXME */
3104 /* FIXME: why use only legacy modes, why not any
3105 * HT/VHT modes? Would that even make any
3108 if (channel->band == NL80211_BAND_2GHZ)
3109 ch->mode = MODE_11G;
3111 ch->mode = MODE_11A;
3113 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3116 ath10k_dbg(ar, ATH10K_DBG_WMI,
3117 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3118 ch - arg.channels, arg.n_channels,
3119 ch->freq, ch->max_power, ch->max_reg_power,
3120 ch->max_antenna_gain, ch->mode);
3126 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3127 kfree(arg.channels);
3132 static enum wmi_dfs_region
3133 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3135 switch (dfs_region) {
3136 case NL80211_DFS_UNSET:
3137 return WMI_UNINIT_DFS_DOMAIN;
3138 case NL80211_DFS_FCC:
3139 return WMI_FCC_DFS_DOMAIN;
3140 case NL80211_DFS_ETSI:
3141 return WMI_ETSI_DFS_DOMAIN;
3142 case NL80211_DFS_JP:
3143 return WMI_MKK4_DFS_DOMAIN;
3145 return WMI_UNINIT_DFS_DOMAIN;
3148 static void ath10k_regd_update(struct ath10k *ar)
3150 struct reg_dmn_pair_mapping *regpair;
3152 enum wmi_dfs_region wmi_dfs_reg;
3153 enum nl80211_dfs_regions nl_dfs_reg;
3155 lockdep_assert_held(&ar->conf_mutex);
3157 ret = ath10k_update_channel_list(ar);
3159 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3161 regpair = ar->ath_common.regulatory.regpair;
3163 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3164 nl_dfs_reg = ar->dfs_detector->region;
3165 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3167 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3170 /* Target allows setting up per-band regdomain but ath_common provides
3171 * a combined one only
3173 ret = ath10k_wmi_pdev_set_regdomain(ar,
3174 regpair->reg_domain,
3175 regpair->reg_domain, /* 2ghz */
3176 regpair->reg_domain, /* 5ghz */
3177 regpair->reg_2ghz_ctl,
3178 regpair->reg_5ghz_ctl,
3181 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3184 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3185 struct ieee80211_supported_band *band)
3189 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3190 for (i = 0; i < band->n_channels; i++) {
3191 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3192 band->channels[i].center_freq > ar->high_5ghz_chan)
3193 band->channels[i].flags |=
3194 IEEE80211_CHAN_DISABLED;
3199 static void ath10k_reg_notifier(struct wiphy *wiphy,
3200 struct regulatory_request *request)
3202 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3203 struct ath10k *ar = hw->priv;
3206 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3208 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3209 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3210 request->dfs_region);
3211 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3212 request->dfs_region);
3214 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3215 request->dfs_region);
3218 mutex_lock(&ar->conf_mutex);
3219 if (ar->state == ATH10K_STATE_ON)
3220 ath10k_regd_update(ar);
3221 mutex_unlock(&ar->conf_mutex);
3223 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3224 ath10k_mac_update_channel_list(ar,
3225 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3232 enum ath10k_mac_tx_path {
3234 ATH10K_MAC_TX_HTT_MGMT,
3235 ATH10K_MAC_TX_WMI_MGMT,
3236 ATH10K_MAC_TX_UNKNOWN,
3239 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3241 lockdep_assert_held(&ar->htt.tx_lock);
3243 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3244 ar->tx_paused |= BIT(reason);
3245 ieee80211_stop_queues(ar->hw);
3248 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3249 struct ieee80211_vif *vif)
3251 struct ath10k *ar = data;
3252 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3254 if (arvif->tx_paused)
3257 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3260 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3262 lockdep_assert_held(&ar->htt.tx_lock);
3264 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3265 ar->tx_paused &= ~BIT(reason);
3270 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3271 IEEE80211_IFACE_ITER_RESUME_ALL,
3272 ath10k_mac_tx_unlock_iter,
3275 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3278 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3280 struct ath10k *ar = arvif->ar;
3282 lockdep_assert_held(&ar->htt.tx_lock);
3284 WARN_ON(reason >= BITS_PER_LONG);
3285 arvif->tx_paused |= BIT(reason);
3286 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3289 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3291 struct ath10k *ar = arvif->ar;
3293 lockdep_assert_held(&ar->htt.tx_lock);
3295 WARN_ON(reason >= BITS_PER_LONG);
3296 arvif->tx_paused &= ~BIT(reason);
3301 if (arvif->tx_paused)
3304 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3307 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3308 enum wmi_tlv_tx_pause_id pause_id,
3309 enum wmi_tlv_tx_pause_action action)
3311 struct ath10k *ar = arvif->ar;
3313 lockdep_assert_held(&ar->htt.tx_lock);
3316 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3317 ath10k_mac_vif_tx_lock(arvif, pause_id);
3319 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3320 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3323 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3324 "received unknown tx pause action %d on vdev %i, ignoring\n",
3325 action, arvif->vdev_id);
3330 struct ath10k_mac_tx_pause {
3332 enum wmi_tlv_tx_pause_id pause_id;
3333 enum wmi_tlv_tx_pause_action action;
3336 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3337 struct ieee80211_vif *vif)
3339 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3340 struct ath10k_mac_tx_pause *arg = data;
3342 if (arvif->vdev_id != arg->vdev_id)
3345 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3348 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3349 enum wmi_tlv_tx_pause_id pause_id,
3350 enum wmi_tlv_tx_pause_action action)
3352 struct ath10k_mac_tx_pause arg = {
3354 .pause_id = pause_id,
3358 spin_lock_bh(&ar->htt.tx_lock);
3359 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3360 IEEE80211_IFACE_ITER_RESUME_ALL,
3361 ath10k_mac_handle_tx_pause_iter,
3363 spin_unlock_bh(&ar->htt.tx_lock);
3366 static enum ath10k_hw_txrx_mode
3367 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3368 struct ieee80211_vif *vif,
3369 struct ieee80211_sta *sta,
3370 struct sk_buff *skb)
3372 const struct ieee80211_hdr *hdr = (void *)skb->data;
3373 __le16 fc = hdr->frame_control;
3375 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3376 return ATH10K_HW_TXRX_RAW;
3378 if (ieee80211_is_mgmt(fc))
3379 return ATH10K_HW_TXRX_MGMT;
3383 * NullFunc frames are mostly used to ping if a client or AP are still
3384 * reachable and responsive. This implies tx status reports must be
3385 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3386 * come to a conclusion that the other end disappeared and tear down
3387 * BSS connection or it can never disconnect from BSS/client (which is
3390 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3391 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3392 * which seems to deliver correct tx reports for NullFunc frames. The
3393 * downside of using it is it ignores client powersave state so it can
3394 * end up disconnecting sleeping clients in AP mode. It should fix STA
3395 * mode though because AP don't sleep.
3397 if (ar->htt.target_version_major < 3 &&
3398 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3399 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3400 ar->running_fw->fw_file.fw_features))
3401 return ATH10K_HW_TXRX_MGMT;
3405 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3406 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3407 * to work with Ethernet txmode so use it.
3409 * FIXME: Check if raw mode works with TDLS.
3411 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3412 return ATH10K_HW_TXRX_ETHERNET;
3414 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3415 return ATH10K_HW_TXRX_RAW;
3417 return ATH10K_HW_TXRX_NATIVE_WIFI;
3420 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3421 struct sk_buff *skb)
3423 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3424 const struct ieee80211_hdr *hdr = (void *)skb->data;
3425 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3426 IEEE80211_TX_CTL_INJECTED;
3428 if (!ieee80211_has_protected(hdr->frame_control))
3431 if ((info->flags & mask) == mask)
3435 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3440 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3441 * Control in the header.
3443 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3445 struct ieee80211_hdr *hdr = (void *)skb->data;
3446 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3449 if (!ieee80211_is_data_qos(hdr->frame_control))
3452 qos_ctl = ieee80211_get_qos_ctl(hdr);
3453 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3454 skb->data, (void *)qos_ctl - (void *)skb->data);
3455 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3457 /* Some firmware revisions don't handle sending QoS NullFunc well.
3458 * These frames are mainly used for CQM purposes so it doesn't really
3459 * matter whether QoS NullFunc or NullFunc are sent.
3461 hdr = (void *)skb->data;
3462 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3463 cb->flags &= ~ATH10K_SKB_F_QOS;
3465 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3468 static void ath10k_tx_h_8023(struct sk_buff *skb)
3470 struct ieee80211_hdr *hdr;
3471 struct rfc1042_hdr *rfc1042;
3478 hdr = (void *)skb->data;
3479 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3480 rfc1042 = (void *)skb->data + hdrlen;
3482 ether_addr_copy(da, ieee80211_get_DA(hdr));
3483 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3484 type = rfc1042->snap_type;
3486 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3487 skb_push(skb, sizeof(*eth));
3489 eth = (void *)skb->data;
3490 ether_addr_copy(eth->h_dest, da);
3491 ether_addr_copy(eth->h_source, sa);
3492 eth->h_proto = type;
3495 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3496 struct ieee80211_vif *vif,
3497 struct sk_buff *skb)
3499 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3500 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3502 /* This is case only for P2P_GO */
3503 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3506 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3507 spin_lock_bh(&ar->data_lock);
3508 if (arvif->u.ap.noa_data)
3509 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3511 skb_put_data(skb, arvif->u.ap.noa_data,
3512 arvif->u.ap.noa_len);
3513 spin_unlock_bh(&ar->data_lock);
3517 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3518 struct ieee80211_vif *vif,
3519 struct ieee80211_txq *txq,
3520 struct sk_buff *skb)
3522 struct ieee80211_hdr *hdr = (void *)skb->data;
3523 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3526 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3527 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3529 if (ieee80211_is_mgmt(hdr->frame_control))
3530 cb->flags |= ATH10K_SKB_F_MGMT;
3532 if (ieee80211_is_data_qos(hdr->frame_control))
3533 cb->flags |= ATH10K_SKB_F_QOS;
3539 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3541 /* FIXME: Not really sure since when the behaviour changed. At some
3542 * point new firmware stopped requiring creation of peer entries for
3543 * offchannel tx (and actually creating them causes issues with wmi-htc
3544 * tx credit replenishment and reliability). Assuming it's at least 3.4
3545 * because that's when the `freq` was introduced to TX_FRM HTT command.
3547 return (ar->htt.target_version_major >= 3 &&
3548 ar->htt.target_version_minor >= 4 &&
3549 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3552 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3554 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3556 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3557 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3561 skb_queue_tail(q, skb);
3562 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3567 static enum ath10k_mac_tx_path
3568 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3569 struct sk_buff *skb,
3570 enum ath10k_hw_txrx_mode txmode)
3573 case ATH10K_HW_TXRX_RAW:
3574 case ATH10K_HW_TXRX_NATIVE_WIFI:
3575 case ATH10K_HW_TXRX_ETHERNET:
3576 return ATH10K_MAC_TX_HTT;
3577 case ATH10K_HW_TXRX_MGMT:
3578 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3579 ar->running_fw->fw_file.fw_features))
3580 return ATH10K_MAC_TX_WMI_MGMT;
3581 else if (ar->htt.target_version_major >= 3)
3582 return ATH10K_MAC_TX_HTT;
3584 return ATH10K_MAC_TX_HTT_MGMT;
3587 return ATH10K_MAC_TX_UNKNOWN;
3590 static int ath10k_mac_tx_submit(struct ath10k *ar,
3591 enum ath10k_hw_txrx_mode txmode,
3592 enum ath10k_mac_tx_path txpath,
3593 struct sk_buff *skb)
3595 struct ath10k_htt *htt = &ar->htt;
3599 case ATH10K_MAC_TX_HTT:
3600 ret = ath10k_htt_tx(htt, txmode, skb);
3602 case ATH10K_MAC_TX_HTT_MGMT:
3603 ret = ath10k_htt_mgmt_tx(htt, skb);
3605 case ATH10K_MAC_TX_WMI_MGMT:
3606 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3608 case ATH10K_MAC_TX_UNKNOWN:
3615 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3617 ieee80211_free_txskb(ar->hw, skb);
3623 /* This function consumes the sk_buff regardless of return value as far as
3624 * caller is concerned so no freeing is necessary afterwards.
3626 static int ath10k_mac_tx(struct ath10k *ar,
3627 struct ieee80211_vif *vif,
3628 enum ath10k_hw_txrx_mode txmode,
3629 enum ath10k_mac_tx_path txpath,
3630 struct sk_buff *skb, bool noque_offchan)
3632 struct ieee80211_hw *hw = ar->hw;
3633 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3636 /* We should disable CCK RATE due to P2P */
3637 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3638 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3641 case ATH10K_HW_TXRX_MGMT:
3642 case ATH10K_HW_TXRX_NATIVE_WIFI:
3643 ath10k_tx_h_nwifi(hw, skb);
3644 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3645 ath10k_tx_h_seq_no(vif, skb);
3647 case ATH10K_HW_TXRX_ETHERNET:
3648 ath10k_tx_h_8023(skb);
3650 case ATH10K_HW_TXRX_RAW:
3651 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3653 ieee80211_free_txskb(hw, skb);
3658 if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3659 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3660 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n",
3663 skb_queue_tail(&ar->offchan_tx_queue, skb);
3664 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3669 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3671 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3678 void ath10k_offchan_tx_purge(struct ath10k *ar)
3680 struct sk_buff *skb;
3683 skb = skb_dequeue(&ar->offchan_tx_queue);
3687 ieee80211_free_txskb(ar->hw, skb);
3691 void ath10k_offchan_tx_work(struct work_struct *work)
3693 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3694 struct ath10k_peer *peer;
3695 struct ath10k_vif *arvif;
3696 enum ath10k_hw_txrx_mode txmode;
3697 enum ath10k_mac_tx_path txpath;
3698 struct ieee80211_hdr *hdr;
3699 struct ieee80211_vif *vif;
3700 struct ieee80211_sta *sta;
3701 struct sk_buff *skb;
3702 const u8 *peer_addr;
3705 unsigned long time_left;
3706 bool tmp_peer_created = false;
3708 /* FW requirement: We must create a peer before FW will send out
3709 * an offchannel frame. Otherwise the frame will be stuck and
3710 * never transmitted. We delete the peer upon tx completion.
3711 * It is unlikely that a peer for offchannel tx will already be
3712 * present. However it may be in some rare cases so account for that.
3713 * Otherwise we might remove a legitimate peer and break stuff.
3717 skb = skb_dequeue(&ar->offchan_tx_queue);
3721 mutex_lock(&ar->conf_mutex);
3723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n",
3726 hdr = (struct ieee80211_hdr *)skb->data;
3727 peer_addr = ieee80211_get_DA(hdr);
3729 spin_lock_bh(&ar->data_lock);
3730 vdev_id = ar->scan.vdev_id;
3731 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3732 spin_unlock_bh(&ar->data_lock);
3735 /* FIXME: should this use ath10k_warn()? */
3736 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3737 peer_addr, vdev_id);
3740 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3742 WMI_PEER_TYPE_DEFAULT);
3744 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3745 peer_addr, vdev_id, ret);
3746 tmp_peer_created = (ret == 0);
3749 spin_lock_bh(&ar->data_lock);
3750 reinit_completion(&ar->offchan_tx_completed);
3751 ar->offchan_tx_skb = skb;
3752 spin_unlock_bh(&ar->data_lock);
3754 /* It's safe to access vif and sta - conf_mutex guarantees that
3755 * sta_state() and remove_interface() are locked exclusively
3756 * out wrt to this offchannel worker.
3758 arvif = ath10k_get_arvif(ar, vdev_id);
3761 sta = ieee80211_find_sta(vif, peer_addr);
3767 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3768 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3770 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true);
3772 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3778 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3780 ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n",
3783 if (!peer && tmp_peer_created) {
3784 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3786 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3787 peer_addr, vdev_id, ret);
3790 mutex_unlock(&ar->conf_mutex);
3794 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3796 struct sk_buff *skb;
3799 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3803 ieee80211_free_txskb(ar->hw, skb);
3807 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3809 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3810 struct sk_buff *skb;
3814 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3818 ret = ath10k_wmi_mgmt_tx(ar, skb);
3820 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3822 ieee80211_free_txskb(ar->hw, skb);
3827 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3829 struct ath10k_txq *artxq;
3834 artxq = (void *)txq->drv_priv;
3835 INIT_LIST_HEAD(&artxq->list);
3838 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3840 struct ath10k_txq *artxq;
3841 struct ath10k_skb_cb *cb;
3842 struct sk_buff *msdu;
3848 artxq = (void *)txq->drv_priv;
3849 spin_lock_bh(&ar->txqs_lock);
3850 if (!list_empty(&artxq->list))
3851 list_del_init(&artxq->list);
3852 spin_unlock_bh(&ar->txqs_lock);
3854 spin_lock_bh(&ar->htt.tx_lock);
3855 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3856 cb = ATH10K_SKB_CB(msdu);
3860 spin_unlock_bh(&ar->htt.tx_lock);
3863 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3867 struct ath10k_peer *peer;
3869 lockdep_assert_held(&ar->data_lock);
3871 peer = ar->peer_map[peer_id];
3879 return peer->sta->txq[tid];
3881 return peer->vif->txq;
3886 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3887 struct ieee80211_txq *txq)
3889 struct ath10k *ar = hw->priv;
3890 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3892 /* No need to get locks */
3894 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3897 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3900 if (artxq->num_fw_queued < artxq->num_push_allowed)
3906 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3907 struct ieee80211_txq *txq)
3909 struct ath10k *ar = hw->priv;
3910 struct ath10k_htt *htt = &ar->htt;
3911 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3912 struct ieee80211_vif *vif = txq->vif;
3913 struct ieee80211_sta *sta = txq->sta;
3914 enum ath10k_hw_txrx_mode txmode;
3915 enum ath10k_mac_tx_path txpath;
3916 struct sk_buff *skb;
3917 struct ieee80211_hdr *hdr;
3919 bool is_mgmt, is_presp;
3922 spin_lock_bh(&ar->htt.tx_lock);
3923 ret = ath10k_htt_tx_inc_pending(htt);
3924 spin_unlock_bh(&ar->htt.tx_lock);
3929 skb = ieee80211_tx_dequeue(hw, txq);
3931 spin_lock_bh(&ar->htt.tx_lock);
3932 ath10k_htt_tx_dec_pending(htt);
3933 spin_unlock_bh(&ar->htt.tx_lock);
3938 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3941 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3942 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3943 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3946 hdr = (struct ieee80211_hdr *)skb->data;
3947 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3949 spin_lock_bh(&ar->htt.tx_lock);
3950 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3953 ath10k_htt_tx_dec_pending(htt);
3954 spin_unlock_bh(&ar->htt.tx_lock);
3957 spin_unlock_bh(&ar->htt.tx_lock);
3960 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
3961 if (unlikely(ret)) {
3962 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3964 spin_lock_bh(&ar->htt.tx_lock);
3965 ath10k_htt_tx_dec_pending(htt);
3967 ath10k_htt_tx_mgmt_dec_pending(htt);
3968 spin_unlock_bh(&ar->htt.tx_lock);
3973 spin_lock_bh(&ar->htt.tx_lock);
3974 artxq->num_fw_queued++;
3975 spin_unlock_bh(&ar->htt.tx_lock);
3980 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3982 struct ieee80211_hw *hw = ar->hw;
3983 struct ieee80211_txq *txq;
3984 struct ath10k_txq *artxq;
3985 struct ath10k_txq *last;
3989 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3992 spin_lock_bh(&ar->txqs_lock);
3995 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3996 while (!list_empty(&ar->txqs)) {
3997 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3998 txq = container_of((void *)artxq, struct ieee80211_txq,
4001 /* Prevent aggressive sta/tid taking over tx queue */
4004 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
4005 ret = ath10k_mac_tx_push_txq(hw, txq);
4010 list_del_init(&artxq->list);
4012 list_add_tail(&artxq->list, &ar->txqs);
4014 ath10k_htt_tx_txq_update(hw, txq);
4016 if (artxq == last || (ret < 0 && ret != -ENOENT))
4021 spin_unlock_bh(&ar->txqs_lock);
4023 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4029 void __ath10k_scan_finish(struct ath10k *ar)
4031 lockdep_assert_held(&ar->data_lock);
4033 switch (ar->scan.state) {
4034 case ATH10K_SCAN_IDLE:
4036 case ATH10K_SCAN_RUNNING:
4037 case ATH10K_SCAN_ABORTING:
4038 if (!ar->scan.is_roc) {
4039 struct cfg80211_scan_info info = {
4040 .aborted = (ar->scan.state ==
4041 ATH10K_SCAN_ABORTING),
4044 ieee80211_scan_completed(ar->hw, &info);
4045 } else if (ar->scan.roc_notify) {
4046 ieee80211_remain_on_channel_expired(ar->hw);
4049 case ATH10K_SCAN_STARTING:
4050 ar->scan.state = ATH10K_SCAN_IDLE;
4051 ar->scan_channel = NULL;
4052 ar->scan.roc_freq = 0;
4053 ath10k_offchan_tx_purge(ar);
4054 cancel_delayed_work(&ar->scan.timeout);
4055 complete(&ar->scan.completed);
4060 void ath10k_scan_finish(struct ath10k *ar)
4062 spin_lock_bh(&ar->data_lock);
4063 __ath10k_scan_finish(ar);
4064 spin_unlock_bh(&ar->data_lock);
4067 static int ath10k_scan_stop(struct ath10k *ar)
4069 struct wmi_stop_scan_arg arg = {
4070 .req_id = 1, /* FIXME */
4071 .req_type = WMI_SCAN_STOP_ONE,
4072 .u.scan_id = ATH10K_SCAN_ID,
4076 lockdep_assert_held(&ar->conf_mutex);
4078 ret = ath10k_wmi_stop_scan(ar, &arg);
4080 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4084 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4086 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4088 } else if (ret > 0) {
4093 /* Scan state should be updated upon scan completion but in case
4094 * firmware fails to deliver the event (for whatever reason) it is
4095 * desired to clean up scan state anyway. Firmware may have just
4096 * dropped the scan completion event delivery due to transport pipe
4097 * being overflown with data and/or it can recover on its own before
4098 * next scan request is submitted.
4100 spin_lock_bh(&ar->data_lock);
4101 if (ar->scan.state != ATH10K_SCAN_IDLE)
4102 __ath10k_scan_finish(ar);
4103 spin_unlock_bh(&ar->data_lock);
4108 static void ath10k_scan_abort(struct ath10k *ar)
4112 lockdep_assert_held(&ar->conf_mutex);
4114 spin_lock_bh(&ar->data_lock);
4116 switch (ar->scan.state) {
4117 case ATH10K_SCAN_IDLE:
4118 /* This can happen if timeout worker kicked in and called
4119 * abortion while scan completion was being processed.
4122 case ATH10K_SCAN_STARTING:
4123 case ATH10K_SCAN_ABORTING:
4124 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4125 ath10k_scan_state_str(ar->scan.state),
4128 case ATH10K_SCAN_RUNNING:
4129 ar->scan.state = ATH10K_SCAN_ABORTING;
4130 spin_unlock_bh(&ar->data_lock);
4132 ret = ath10k_scan_stop(ar);
4134 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4136 spin_lock_bh(&ar->data_lock);
4140 spin_unlock_bh(&ar->data_lock);
4143 void ath10k_scan_timeout_work(struct work_struct *work)
4145 struct ath10k *ar = container_of(work, struct ath10k,
4148 mutex_lock(&ar->conf_mutex);
4149 ath10k_scan_abort(ar);
4150 mutex_unlock(&ar->conf_mutex);
4153 static int ath10k_start_scan(struct ath10k *ar,
4154 const struct wmi_start_scan_arg *arg)
4158 lockdep_assert_held(&ar->conf_mutex);
4160 ret = ath10k_wmi_start_scan(ar, arg);
4164 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4166 ret = ath10k_scan_stop(ar);
4168 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4173 /* If we failed to start the scan, return error code at
4174 * this point. This is probably due to some issue in the
4175 * firmware, but no need to wedge the driver due to that...
4177 spin_lock_bh(&ar->data_lock);
4178 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4179 spin_unlock_bh(&ar->data_lock);
4182 spin_unlock_bh(&ar->data_lock);
4187 /**********************/
4188 /* mac80211 callbacks */
4189 /**********************/
4191 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4192 struct ieee80211_tx_control *control,
4193 struct sk_buff *skb)
4195 struct ath10k *ar = hw->priv;
4196 struct ath10k_htt *htt = &ar->htt;
4197 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4198 struct ieee80211_vif *vif = info->control.vif;
4199 struct ieee80211_sta *sta = control->sta;
4200 struct ieee80211_txq *txq = NULL;
4201 struct ieee80211_hdr *hdr = (void *)skb->data;
4202 enum ath10k_hw_txrx_mode txmode;
4203 enum ath10k_mac_tx_path txpath;
4209 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4211 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4212 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4213 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4214 txpath == ATH10K_MAC_TX_HTT_MGMT);
4215 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4218 spin_lock_bh(&ar->htt.tx_lock);
4219 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4221 ret = ath10k_htt_tx_inc_pending(htt);
4223 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4225 spin_unlock_bh(&ar->htt.tx_lock);
4226 ieee80211_free_txskb(ar->hw, skb);
4230 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4232 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4234 ath10k_htt_tx_dec_pending(htt);
4235 spin_unlock_bh(&ar->htt.tx_lock);
4236 ieee80211_free_txskb(ar->hw, skb);
4239 spin_unlock_bh(&ar->htt.tx_lock);
4242 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4244 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4246 spin_lock_bh(&ar->htt.tx_lock);
4247 ath10k_htt_tx_dec_pending(htt);
4249 ath10k_htt_tx_mgmt_dec_pending(htt);
4250 spin_unlock_bh(&ar->htt.tx_lock);
4256 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4257 struct ieee80211_txq *txq)
4259 struct ath10k *ar = hw->priv;
4260 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4261 struct ieee80211_txq *f_txq;
4262 struct ath10k_txq *f_artxq;
4266 spin_lock_bh(&ar->txqs_lock);
4267 if (list_empty(&artxq->list))
4268 list_add_tail(&artxq->list, &ar->txqs);
4270 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4271 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4272 list_del_init(&f_artxq->list);
4274 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4275 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4280 list_add_tail(&f_artxq->list, &ar->txqs);
4281 spin_unlock_bh(&ar->txqs_lock);
4283 ath10k_htt_tx_txq_update(hw, f_txq);
4284 ath10k_htt_tx_txq_update(hw, txq);
4287 /* Must not be called with conf_mutex held as workers can use that also. */
4288 void ath10k_drain_tx(struct ath10k *ar)
4290 /* make sure rcu-protected mac80211 tx path itself is drained */
4293 ath10k_offchan_tx_purge(ar);
4294 ath10k_mgmt_over_wmi_tx_purge(ar);
4296 cancel_work_sync(&ar->offchan_tx_work);
4297 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4300 void ath10k_halt(struct ath10k *ar)
4302 struct ath10k_vif *arvif;
4304 lockdep_assert_held(&ar->conf_mutex);
4306 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4307 ar->filter_flags = 0;
4308 ar->monitor = false;
4309 ar->monitor_arvif = NULL;
4311 if (ar->monitor_started)
4312 ath10k_monitor_stop(ar);
4314 ar->monitor_started = false;
4317 ath10k_scan_finish(ar);
4318 ath10k_peer_cleanup_all(ar);
4319 ath10k_core_stop(ar);
4320 ath10k_hif_power_down(ar);
4322 spin_lock_bh(&ar->data_lock);
4323 list_for_each_entry(arvif, &ar->arvifs, list)
4324 ath10k_mac_vif_beacon_cleanup(arvif);
4325 spin_unlock_bh(&ar->data_lock);
4328 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4330 struct ath10k *ar = hw->priv;
4332 mutex_lock(&ar->conf_mutex);
4334 *tx_ant = ar->cfg_tx_chainmask;
4335 *rx_ant = ar->cfg_rx_chainmask;
4337 mutex_unlock(&ar->conf_mutex);
4342 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4344 /* It is not clear that allowing gaps in chainmask
4345 * is helpful. Probably it will not do what user
4346 * is hoping for, so warn in that case.
4348 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4351 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4355 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4357 int nsts = ar->vht_cap_info;
4359 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4360 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4362 /* If firmware does not deliver to host number of space-time
4363 * streams supported, assume it support up to 4 BF STS and return
4364 * the value for VHT CAP: nsts-1)
4372 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4374 int sound_dim = ar->vht_cap_info;
4376 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4377 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4379 /* If the sounding dimension is not advertised by the firmware,
4380 * let's use a default value of 1
4388 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4390 struct ieee80211_sta_vht_cap vht_cap = {0};
4391 struct ath10k_hw_params *hw = &ar->hw_params;
4396 vht_cap.vht_supported = 1;
4397 vht_cap.cap = ar->vht_cap_info;
4399 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4400 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4401 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4402 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4403 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4408 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4409 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4410 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4411 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4412 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4417 /* Currently the firmware seems to be buggy, don't enable 80+80
4418 * mode until that's resolved.
4420 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4421 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4422 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4425 for (i = 0; i < 8; i++) {
4426 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4427 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4429 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4432 if (ar->cfg_tx_chainmask <= 1)
4433 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4435 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4436 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4438 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4439 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4440 * user-space a clue if that is the case.
4442 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4443 (hw->vht160_mcs_rx_highest != 0 ||
4444 hw->vht160_mcs_tx_highest != 0)) {
4445 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4446 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4452 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4455 struct ieee80211_sta_ht_cap ht_cap = {0};
4457 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4460 ht_cap.ht_supported = 1;
4461 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4462 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4463 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4464 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4466 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4468 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4469 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4471 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4472 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4474 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4477 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4478 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4483 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4484 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4486 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4489 stbc = ar->ht_cap_info;
4490 stbc &= WMI_HT_CAP_RX_STBC;
4491 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4492 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4493 stbc &= IEEE80211_HT_CAP_RX_STBC;
4498 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4499 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4501 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4502 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4504 /* max AMSDU is implicitly taken from vht_cap_info */
4505 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4506 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4508 for (i = 0; i < ar->num_rf_chains; i++) {
4509 if (ar->cfg_rx_chainmask & BIT(i))
4510 ht_cap.mcs.rx_mask[i] = 0xFF;
4513 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4518 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4520 struct ieee80211_supported_band *band;
4521 struct ieee80211_sta_vht_cap vht_cap;
4522 struct ieee80211_sta_ht_cap ht_cap;
4524 ht_cap = ath10k_get_ht_cap(ar);
4525 vht_cap = ath10k_create_vht_cap(ar);
4527 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4528 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4529 band->ht_cap = ht_cap;
4531 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4532 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4533 band->ht_cap = ht_cap;
4534 band->vht_cap = vht_cap;
4538 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4542 lockdep_assert_held(&ar->conf_mutex);
4544 ath10k_check_chain_mask(ar, tx_ant, "tx");
4545 ath10k_check_chain_mask(ar, rx_ant, "rx");
4547 ar->cfg_tx_chainmask = tx_ant;
4548 ar->cfg_rx_chainmask = rx_ant;
4550 if ((ar->state != ATH10K_STATE_ON) &&
4551 (ar->state != ATH10K_STATE_RESTARTED))
4554 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4557 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4562 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4565 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4570 /* Reload HT/VHT capability */
4571 ath10k_mac_setup_ht_vht_cap(ar);
4576 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4578 struct ath10k *ar = hw->priv;
4581 mutex_lock(&ar->conf_mutex);
4582 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4583 mutex_unlock(&ar->conf_mutex);
4587 static int ath10k_start(struct ieee80211_hw *hw)
4589 struct ath10k *ar = hw->priv;
4594 * This makes sense only when restarting hw. It is harmless to call
4595 * unconditionally. This is necessary to make sure no HTT/WMI tx
4596 * commands will be submitted while restarting.
4598 ath10k_drain_tx(ar);
4600 mutex_lock(&ar->conf_mutex);
4602 switch (ar->state) {
4603 case ATH10K_STATE_OFF:
4604 ar->state = ATH10K_STATE_ON;
4606 case ATH10K_STATE_RESTARTING:
4607 ar->state = ATH10K_STATE_RESTARTED;
4609 case ATH10K_STATE_ON:
4610 case ATH10K_STATE_RESTARTED:
4611 case ATH10K_STATE_WEDGED:
4615 case ATH10K_STATE_UTF:
4620 ret = ath10k_hif_power_up(ar);
4622 ath10k_err(ar, "Could not init hif: %d\n", ret);
4626 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4627 &ar->normal_mode_fw);
4629 ath10k_err(ar, "Could not init core: %d\n", ret);
4630 goto err_power_down;
4633 param = ar->wmi.pdev_param->pmf_qos;
4634 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4636 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4640 param = ar->wmi.pdev_param->dynamic_bw;
4641 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4643 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4647 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4648 ret = ath10k_wmi_adaptive_qcs(ar, true);
4650 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4656 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4657 param = ar->wmi.pdev_param->burst_enable;
4658 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4660 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4665 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4668 * By default FW set ARP frames ac to voice (6). In that case ARP
4669 * exchange is not working properly for UAPSD enabled AP. ARP requests
4670 * which arrives with access category 0 are processed by network stack
4671 * and send back with access category 0, but FW changes access category
4672 * to 6. Set ARP frames access category to best effort (0) solves
4676 param = ar->wmi.pdev_param->arp_ac_override;
4677 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4679 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4684 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4685 ar->running_fw->fw_file.fw_features)) {
4686 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4687 WMI_CCA_DETECT_LEVEL_AUTO,
4688 WMI_CCA_DETECT_MARGIN_AUTO);
4690 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4696 param = ar->wmi.pdev_param->ani_enable;
4697 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4699 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4704 ar->ani_enabled = true;
4706 if (ath10k_peer_stats_enabled(ar)) {
4707 param = ar->wmi.pdev_param->peer_stats_update_period;
4708 ret = ath10k_wmi_pdev_set_param(ar, param,
4709 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4712 "failed to set peer stats period : %d\n",
4718 param = ar->wmi.pdev_param->enable_btcoex;
4719 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4720 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4721 ar->running_fw->fw_file.fw_features)) {
4722 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4725 "failed to set btcoex param: %d\n", ret);
4728 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4731 ar->num_started_vdevs = 0;
4732 ath10k_regd_update(ar);
4734 ath10k_spectral_start(ar);
4735 ath10k_thermal_set_throttling(ar);
4737 mutex_unlock(&ar->conf_mutex);
4741 ath10k_core_stop(ar);
4744 ath10k_hif_power_down(ar);
4747 ar->state = ATH10K_STATE_OFF;
4750 mutex_unlock(&ar->conf_mutex);
4754 static void ath10k_stop(struct ieee80211_hw *hw)
4756 struct ath10k *ar = hw->priv;
4758 ath10k_drain_tx(ar);
4760 mutex_lock(&ar->conf_mutex);
4761 if (ar->state != ATH10K_STATE_OFF) {
4763 ar->state = ATH10K_STATE_OFF;
4765 mutex_unlock(&ar->conf_mutex);
4767 cancel_work_sync(&ar->set_coverage_class_work);
4768 cancel_delayed_work_sync(&ar->scan.timeout);
4769 cancel_work_sync(&ar->restart_work);
4772 static int ath10k_config_ps(struct ath10k *ar)
4774 struct ath10k_vif *arvif;
4777 lockdep_assert_held(&ar->conf_mutex);
4779 list_for_each_entry(arvif, &ar->arvifs, list) {
4780 ret = ath10k_mac_vif_setup_ps(arvif);
4782 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4790 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4795 lockdep_assert_held(&ar->conf_mutex);
4797 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4799 param = ar->wmi.pdev_param->txpower_limit2g;
4800 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4802 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4807 param = ar->wmi.pdev_param->txpower_limit5g;
4808 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4810 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4818 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4820 struct ath10k_vif *arvif;
4821 int ret, txpower = -1;
4823 lockdep_assert_held(&ar->conf_mutex);
4825 list_for_each_entry(arvif, &ar->arvifs, list) {
4826 if (arvif->txpower <= 0)
4830 txpower = arvif->txpower;
4832 txpower = min(txpower, arvif->txpower);
4838 ret = ath10k_mac_txpower_setup(ar, txpower);
4840 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4848 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4850 struct ath10k *ar = hw->priv;
4851 struct ieee80211_conf *conf = &hw->conf;
4854 mutex_lock(&ar->conf_mutex);
4856 if (changed & IEEE80211_CONF_CHANGE_PS)
4857 ath10k_config_ps(ar);
4859 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4860 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4861 ret = ath10k_monitor_recalc(ar);
4863 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4866 mutex_unlock(&ar->conf_mutex);
4870 static u32 get_nss_from_chainmask(u16 chain_mask)
4872 if ((chain_mask & 0xf) == 0xf)
4874 else if ((chain_mask & 0x7) == 0x7)
4876 else if ((chain_mask & 0x3) == 0x3)
4881 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4884 struct ath10k *ar = arvif->ar;
4888 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4891 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4892 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4893 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4894 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4896 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4897 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4898 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4899 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4904 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4905 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4907 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4908 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4909 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4911 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4912 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4914 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4915 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4916 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4918 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4919 ar->wmi.vdev_param->txbf, value);
4924 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4925 * because we will send mgmt frames without CCK. This requirement
4926 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4929 static int ath10k_add_interface(struct ieee80211_hw *hw,
4930 struct ieee80211_vif *vif)
4932 struct ath10k *ar = hw->priv;
4933 struct ath10k_vif *arvif = (void *)vif->drv_priv;
4934 struct ath10k_peer *peer;
4935 enum wmi_sta_powersave_param param;
4942 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4944 mutex_lock(&ar->conf_mutex);
4946 memset(arvif, 0, sizeof(*arvif));
4947 ath10k_mac_txq_init(vif->txq);
4952 INIT_LIST_HEAD(&arvif->list);
4953 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4954 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4955 ath10k_mac_vif_sta_connection_loss_work);
4957 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4958 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4959 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4960 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4961 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4962 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4965 if (ar->num_peers >= ar->max_num_peers) {
4966 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4971 if (ar->free_vdev_map == 0) {
4972 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4976 bit = __ffs64(ar->free_vdev_map);
4978 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4979 bit, ar->free_vdev_map);
4981 arvif->vdev_id = bit;
4982 arvif->vdev_subtype =
4983 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4985 switch (vif->type) {
4986 case NL80211_IFTYPE_P2P_DEVICE:
4987 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4988 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4989 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4991 case NL80211_IFTYPE_UNSPECIFIED:
4992 case NL80211_IFTYPE_STATION:
4993 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4995 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4996 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4998 case NL80211_IFTYPE_ADHOC:
4999 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
5001 case NL80211_IFTYPE_MESH_POINT:
5002 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
5003 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5004 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
5005 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5007 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5010 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5012 case NL80211_IFTYPE_AP:
5013 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5016 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5017 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5019 case NL80211_IFTYPE_MONITOR:
5020 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5027 /* Using vdev_id as queue number will make it very easy to do per-vif
5028 * tx queue locking. This shouldn't wrap due to interface combinations
5029 * but do a modulo for correctness sake and prevent using offchannel tx
5030 * queues for regular vif tx.
5032 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5033 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5034 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5036 /* Some firmware revisions don't wait for beacon tx completion before
5037 * sending another SWBA event. This could lead to hardware using old
5038 * (freed) beacon data in some cases, e.g. tx credit starvation
5039 * combined with missed TBTT. This is very very rare.
5041 * On non-IOMMU-enabled hosts this could be a possible security issue
5042 * because hw could beacon some random data on the air. On
5043 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5044 * device would crash.
5046 * Since there are no beacon tx completions (implicit nor explicit)
5047 * propagated to host the only workaround for this is to allocate a
5048 * DMA-coherent buffer for a lifetime of a vif and use it for all
5049 * beacon tx commands. Worst case for this approach is some beacons may
5050 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5052 if (vif->type == NL80211_IFTYPE_ADHOC ||
5053 vif->type == NL80211_IFTYPE_MESH_POINT ||
5054 vif->type == NL80211_IFTYPE_AP) {
5055 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
5056 IEEE80211_MAX_FRAME_LEN,
5057 &arvif->beacon_paddr,
5059 if (!arvif->beacon_buf) {
5061 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5066 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5067 arvif->nohwcrypt = true;
5069 if (arvif->nohwcrypt &&
5070 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5072 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5076 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5077 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5078 arvif->beacon_buf ? "single-buf" : "per-skb");
5080 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5081 arvif->vdev_subtype, vif->addr);
5083 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5084 arvif->vdev_id, ret);
5088 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5089 spin_lock_bh(&ar->data_lock);
5090 list_add(&arvif->list, &ar->arvifs);
5091 spin_unlock_bh(&ar->data_lock);
5093 /* It makes no sense to have firmware do keepalives. mac80211 already
5094 * takes care of this with idle connection polling.
5096 ret = ath10k_mac_vif_disable_keepalive(arvif);
5098 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5099 arvif->vdev_id, ret);
5100 goto err_vdev_delete;
5103 arvif->def_wep_key_idx = -1;
5105 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5106 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5107 ATH10K_HW_TXRX_NATIVE_WIFI);
5108 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5109 if (ret && ret != -EOPNOTSUPP) {
5110 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5111 arvif->vdev_id, ret);
5112 goto err_vdev_delete;
5115 /* Configuring number of spatial stream for monitor interface is causing
5116 * target assert in qca9888 and qca6174.
5118 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5119 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5121 vdev_param = ar->wmi.vdev_param->nss;
5122 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5125 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5126 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5128 goto err_vdev_delete;
5132 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5133 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5134 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5135 vif->addr, WMI_PEER_TYPE_DEFAULT);
5137 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5138 arvif->vdev_id, ret);
5139 goto err_vdev_delete;
5142 spin_lock_bh(&ar->data_lock);
5144 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5146 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5147 vif->addr, arvif->vdev_id);
5148 spin_unlock_bh(&ar->data_lock);
5150 goto err_peer_delete;
5153 arvif->peer_id = find_first_bit(peer->peer_ids,
5154 ATH10K_MAX_NUM_PEER_IDS);
5156 spin_unlock_bh(&ar->data_lock);
5158 arvif->peer_id = HTT_INVALID_PEERID;
5161 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5162 ret = ath10k_mac_set_kickout(arvif);
5164 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5165 arvif->vdev_id, ret);
5166 goto err_peer_delete;
5170 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5171 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5172 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5173 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5176 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5177 arvif->vdev_id, ret);
5178 goto err_peer_delete;
5181 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5183 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5184 arvif->vdev_id, ret);
5185 goto err_peer_delete;
5188 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5190 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5191 arvif->vdev_id, ret);
5192 goto err_peer_delete;
5196 ret = ath10k_mac_set_txbf_conf(arvif);
5198 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5199 arvif->vdev_id, ret);
5200 goto err_peer_delete;
5203 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5205 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5206 arvif->vdev_id, ret);
5207 goto err_peer_delete;
5210 arvif->txpower = vif->bss_conf.txpower;
5211 ret = ath10k_mac_txpower_recalc(ar);
5213 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5214 goto err_peer_delete;
5217 if (vif->type == NL80211_IFTYPE_MONITOR) {
5218 ar->monitor_arvif = arvif;
5219 ret = ath10k_monitor_recalc(ar);
5221 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5222 goto err_peer_delete;
5226 spin_lock_bh(&ar->htt.tx_lock);
5228 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5229 spin_unlock_bh(&ar->htt.tx_lock);
5231 mutex_unlock(&ar->conf_mutex);
5235 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5236 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5237 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5240 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5241 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5242 spin_lock_bh(&ar->data_lock);
5243 list_del(&arvif->list);
5244 spin_unlock_bh(&ar->data_lock);
5247 if (arvif->beacon_buf) {
5248 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5249 arvif->beacon_buf, arvif->beacon_paddr);
5250 arvif->beacon_buf = NULL;
5253 mutex_unlock(&ar->conf_mutex);
5258 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5262 for (i = 0; i < BITS_PER_LONG; i++)
5263 ath10k_mac_vif_tx_unlock(arvif, i);
5266 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5267 struct ieee80211_vif *vif)
5269 struct ath10k *ar = hw->priv;
5270 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5271 struct ath10k_peer *peer;
5275 cancel_work_sync(&arvif->ap_csa_work);
5276 cancel_delayed_work_sync(&arvif->connection_loss_work);
5278 mutex_lock(&ar->conf_mutex);
5280 spin_lock_bh(&ar->data_lock);
5281 ath10k_mac_vif_beacon_cleanup(arvif);
5282 spin_unlock_bh(&ar->data_lock);
5284 ret = ath10k_spectral_vif_stop(arvif);
5286 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5287 arvif->vdev_id, ret);
5289 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5290 spin_lock_bh(&ar->data_lock);
5291 list_del(&arvif->list);
5292 spin_unlock_bh(&ar->data_lock);
5294 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5295 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5296 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5299 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5300 arvif->vdev_id, ret);
5302 kfree(arvif->u.ap.noa_data);
5305 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5308 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5310 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5311 arvif->vdev_id, ret);
5313 /* Some firmware revisions don't notify host about self-peer removal
5314 * until after associated vdev is deleted.
5316 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5317 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5318 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5321 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5322 arvif->vdev_id, ret);
5324 spin_lock_bh(&ar->data_lock);
5326 spin_unlock_bh(&ar->data_lock);
5329 spin_lock_bh(&ar->data_lock);
5330 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5331 peer = ar->peer_map[i];
5335 if (peer->vif == vif) {
5336 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5337 vif->addr, arvif->vdev_id);
5341 spin_unlock_bh(&ar->data_lock);
5343 ath10k_peer_cleanup(ar, arvif->vdev_id);
5344 ath10k_mac_txq_unref(ar, vif->txq);
5346 if (vif->type == NL80211_IFTYPE_MONITOR) {
5347 ar->monitor_arvif = NULL;
5348 ret = ath10k_monitor_recalc(ar);
5350 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5353 ret = ath10k_mac_txpower_recalc(ar);
5355 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5357 spin_lock_bh(&ar->htt.tx_lock);
5358 ath10k_mac_vif_tx_unlock_all(arvif);
5359 spin_unlock_bh(&ar->htt.tx_lock);
5361 ath10k_mac_txq_unref(ar, vif->txq);
5363 mutex_unlock(&ar->conf_mutex);
5367 * FIXME: Has to be verified.
5369 #define SUPPORTED_FILTERS \
5374 FIF_BCN_PRBRESP_PROMISC | \
5378 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5379 unsigned int changed_flags,
5380 unsigned int *total_flags,
5383 struct ath10k *ar = hw->priv;
5386 mutex_lock(&ar->conf_mutex);
5388 changed_flags &= SUPPORTED_FILTERS;
5389 *total_flags &= SUPPORTED_FILTERS;
5390 ar->filter_flags = *total_flags;
5392 ret = ath10k_monitor_recalc(ar);
5394 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5396 mutex_unlock(&ar->conf_mutex);
5399 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5400 struct ieee80211_vif *vif,
5401 struct ieee80211_bss_conf *info,
5404 struct ath10k *ar = hw->priv;
5405 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5407 u32 vdev_param, pdev_param, slottime, preamble;
5409 mutex_lock(&ar->conf_mutex);
5411 if (changed & BSS_CHANGED_IBSS)
5412 ath10k_control_ibss(arvif, info, vif->addr);
5414 if (changed & BSS_CHANGED_BEACON_INT) {
5415 arvif->beacon_interval = info->beacon_int;
5416 vdev_param = ar->wmi.vdev_param->beacon_interval;
5417 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5418 arvif->beacon_interval);
5419 ath10k_dbg(ar, ATH10K_DBG_MAC,
5420 "mac vdev %d beacon_interval %d\n",
5421 arvif->vdev_id, arvif->beacon_interval);
5424 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5425 arvif->vdev_id, ret);
5428 if (changed & BSS_CHANGED_BEACON) {
5429 ath10k_dbg(ar, ATH10K_DBG_MAC,
5430 "vdev %d set beacon tx mode to staggered\n",
5433 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5434 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5435 WMI_BEACON_STAGGERED_MODE);
5437 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5438 arvif->vdev_id, ret);
5440 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5442 ath10k_warn(ar, "failed to update beacon template: %d\n",
5445 if (ieee80211_vif_is_mesh(vif)) {
5446 /* mesh doesn't use SSID but firmware needs it */
5447 strncpy(arvif->u.ap.ssid, "mesh",
5448 sizeof(arvif->u.ap.ssid));
5449 arvif->u.ap.ssid_len = 4;
5453 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5454 ret = ath10k_mac_setup_prb_tmpl(arvif);
5456 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5457 arvif->vdev_id, ret);
5460 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5461 arvif->dtim_period = info->dtim_period;
5463 ath10k_dbg(ar, ATH10K_DBG_MAC,
5464 "mac vdev %d dtim_period %d\n",
5465 arvif->vdev_id, arvif->dtim_period);
5467 vdev_param = ar->wmi.vdev_param->dtim_period;
5468 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5469 arvif->dtim_period);
5471 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5472 arvif->vdev_id, ret);
5475 if (changed & BSS_CHANGED_SSID &&
5476 vif->type == NL80211_IFTYPE_AP) {
5477 arvif->u.ap.ssid_len = info->ssid_len;
5479 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5480 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5483 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5484 ether_addr_copy(arvif->bssid, info->bssid);
5486 if (changed & BSS_CHANGED_BEACON_ENABLED)
5487 ath10k_control_beaconing(arvif, info);
5489 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5490 arvif->use_cts_prot = info->use_cts_prot;
5492 ret = ath10k_recalc_rtscts_prot(arvif);
5494 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5495 arvif->vdev_id, ret);
5497 if (ath10k_mac_can_set_cts_prot(arvif)) {
5498 ret = ath10k_mac_set_cts_prot(arvif);
5500 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5501 arvif->vdev_id, ret);
5505 if (changed & BSS_CHANGED_ERP_SLOT) {
5506 if (info->use_short_slot)
5507 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5510 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5512 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5513 arvif->vdev_id, slottime);
5515 vdev_param = ar->wmi.vdev_param->slot_time;
5516 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5519 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5520 arvif->vdev_id, ret);
5523 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5524 if (info->use_short_preamble)
5525 preamble = WMI_VDEV_PREAMBLE_SHORT;
5527 preamble = WMI_VDEV_PREAMBLE_LONG;
5529 ath10k_dbg(ar, ATH10K_DBG_MAC,
5530 "mac vdev %d preamble %dn",
5531 arvif->vdev_id, preamble);
5533 vdev_param = ar->wmi.vdev_param->preamble;
5534 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5537 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5538 arvif->vdev_id, ret);
5541 if (changed & BSS_CHANGED_ASSOC) {
5543 /* Workaround: Make sure monitor vdev is not running
5544 * when associating to prevent some firmware revisions
5545 * (e.g. 10.1 and 10.2) from crashing.
5547 if (ar->monitor_started)
5548 ath10k_monitor_stop(ar);
5549 ath10k_bss_assoc(hw, vif, info);
5550 ath10k_monitor_recalc(ar);
5552 ath10k_bss_disassoc(hw, vif);
5556 if (changed & BSS_CHANGED_TXPOWER) {
5557 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5558 arvif->vdev_id, info->txpower);
5560 arvif->txpower = info->txpower;
5561 ret = ath10k_mac_txpower_recalc(ar);
5563 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5566 if (changed & BSS_CHANGED_PS) {
5567 arvif->ps = vif->bss_conf.ps;
5569 ret = ath10k_config_ps(ar);
5571 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5572 arvif->vdev_id, ret);
5575 mutex_unlock(&ar->conf_mutex);
5578 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5580 struct ath10k *ar = hw->priv;
5582 /* This function should never be called if setting the coverage class
5583 * is not supported on this hardware.
5585 if (!ar->hw_params.hw_ops->set_coverage_class) {
5589 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5592 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5593 struct ieee80211_vif *vif,
5594 struct ieee80211_scan_request *hw_req)
5596 struct ath10k *ar = hw->priv;
5597 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5598 struct cfg80211_scan_request *req = &hw_req->req;
5599 struct wmi_start_scan_arg arg;
5603 mutex_lock(&ar->conf_mutex);
5605 spin_lock_bh(&ar->data_lock);
5606 switch (ar->scan.state) {
5607 case ATH10K_SCAN_IDLE:
5608 reinit_completion(&ar->scan.started);
5609 reinit_completion(&ar->scan.completed);
5610 ar->scan.state = ATH10K_SCAN_STARTING;
5611 ar->scan.is_roc = false;
5612 ar->scan.vdev_id = arvif->vdev_id;
5615 case ATH10K_SCAN_STARTING:
5616 case ATH10K_SCAN_RUNNING:
5617 case ATH10K_SCAN_ABORTING:
5621 spin_unlock_bh(&ar->data_lock);
5626 memset(&arg, 0, sizeof(arg));
5627 ath10k_wmi_start_scan_init(ar, &arg);
5628 arg.vdev_id = arvif->vdev_id;
5629 arg.scan_id = ATH10K_SCAN_ID;
5632 arg.ie_len = req->ie_len;
5633 memcpy(arg.ie, req->ie, arg.ie_len);
5637 arg.n_ssids = req->n_ssids;
5638 for (i = 0; i < arg.n_ssids; i++) {
5639 arg.ssids[i].len = req->ssids[i].ssid_len;
5640 arg.ssids[i].ssid = req->ssids[i].ssid;
5643 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5646 if (req->n_channels) {
5647 arg.n_channels = req->n_channels;
5648 for (i = 0; i < arg.n_channels; i++)
5649 arg.channels[i] = req->channels[i]->center_freq;
5652 ret = ath10k_start_scan(ar, &arg);
5654 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5655 spin_lock_bh(&ar->data_lock);
5656 ar->scan.state = ATH10K_SCAN_IDLE;
5657 spin_unlock_bh(&ar->data_lock);
5660 /* Add a 200ms margin to account for event/command processing */
5661 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5662 msecs_to_jiffies(arg.max_scan_time +
5666 mutex_unlock(&ar->conf_mutex);
5670 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5671 struct ieee80211_vif *vif)
5673 struct ath10k *ar = hw->priv;
5675 mutex_lock(&ar->conf_mutex);
5676 ath10k_scan_abort(ar);
5677 mutex_unlock(&ar->conf_mutex);
5679 cancel_delayed_work_sync(&ar->scan.timeout);
5682 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5683 struct ath10k_vif *arvif,
5684 enum set_key_cmd cmd,
5685 struct ieee80211_key_conf *key)
5687 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5690 /* 10.1 firmware branch requires default key index to be set to group
5691 * key index after installing it. Otherwise FW/HW Txes corrupted
5692 * frames with multi-vif APs. This is not required for main firmware
5693 * branch (e.g. 636).
5695 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5697 * FIXME: It remains unknown if this is required for multi-vif STA
5698 * interfaces on 10.1.
5701 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5702 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5705 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5708 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5711 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5717 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5720 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5721 arvif->vdev_id, ret);
5724 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5725 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5726 struct ieee80211_key_conf *key)
5728 struct ath10k *ar = hw->priv;
5729 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5730 struct ath10k_peer *peer;
5731 const u8 *peer_addr;
5732 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5733 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5739 /* this one needs to be done in software */
5740 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5743 if (arvif->nohwcrypt)
5746 if (key->keyidx > WMI_MAX_KEY_INDEX)
5749 mutex_lock(&ar->conf_mutex);
5752 peer_addr = sta->addr;
5753 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5754 peer_addr = vif->bss_conf.bssid;
5756 peer_addr = vif->addr;
5758 key->hw_key_idx = key->keyidx;
5762 arvif->wep_keys[key->keyidx] = key;
5764 arvif->wep_keys[key->keyidx] = NULL;
5767 /* the peer should not disappear in mid-way (unless FW goes awry) since
5768 * we already hold conf_mutex. we just make sure its there now.
5770 spin_lock_bh(&ar->data_lock);
5771 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5772 spin_unlock_bh(&ar->data_lock);
5775 if (cmd == SET_KEY) {
5776 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5781 /* if the peer doesn't exist there is no key to disable anymore */
5786 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5787 flags |= WMI_KEY_PAIRWISE;
5789 flags |= WMI_KEY_GROUP;
5792 if (cmd == DISABLE_KEY)
5793 ath10k_clear_vdev_key(arvif, key);
5795 /* When WEP keys are uploaded it's possible that there are
5796 * stations associated already (e.g. when merging) without any
5797 * keys. Static WEP needs an explicit per-peer key upload.
5799 if (vif->type == NL80211_IFTYPE_ADHOC &&
5801 ath10k_mac_vif_update_wep_key(arvif, key);
5803 /* 802.1x never sets the def_wep_key_idx so each set_key()
5804 * call changes default tx key.
5806 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5807 * after first set_key().
5809 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5810 flags |= WMI_KEY_TX_USAGE;
5813 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5816 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5817 arvif->vdev_id, peer_addr, ret);
5821 /* mac80211 sets static WEP keys as groupwise while firmware requires
5822 * them to be installed twice as both pairwise and groupwise.
5824 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5826 flags2 &= ~WMI_KEY_GROUP;
5827 flags2 |= WMI_KEY_PAIRWISE;
5829 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5832 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5833 arvif->vdev_id, peer_addr, ret);
5834 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5838 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5839 arvif->vdev_id, peer_addr, ret2);
5845 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5847 spin_lock_bh(&ar->data_lock);
5848 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5849 if (peer && cmd == SET_KEY)
5850 peer->keys[key->keyidx] = key;
5851 else if (peer && cmd == DISABLE_KEY)
5852 peer->keys[key->keyidx] = NULL;
5853 else if (peer == NULL)
5854 /* impossible unless FW goes crazy */
5855 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5856 spin_unlock_bh(&ar->data_lock);
5859 mutex_unlock(&ar->conf_mutex);
5863 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5864 struct ieee80211_vif *vif,
5867 struct ath10k *ar = hw->priv;
5868 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5871 mutex_lock(&arvif->ar->conf_mutex);
5873 if (arvif->ar->state != ATH10K_STATE_ON)
5876 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5877 arvif->vdev_id, keyidx);
5879 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5881 arvif->ar->wmi.vdev_param->def_keyid,
5885 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5891 arvif->def_wep_key_idx = keyidx;
5894 mutex_unlock(&arvif->ar->conf_mutex);
5897 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5900 struct ath10k_vif *arvif;
5901 struct ath10k_sta *arsta;
5902 struct ieee80211_sta *sta;
5903 struct cfg80211_chan_def def;
5904 enum nl80211_band band;
5905 const u8 *ht_mcs_mask;
5906 const u16 *vht_mcs_mask;
5907 u32 changed, bw, nss, smps;
5910 arsta = container_of(wk, struct ath10k_sta, update_wk);
5911 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5912 arvif = arsta->arvif;
5915 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5918 band = def.chan->band;
5919 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5920 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5922 spin_lock_bh(&ar->data_lock);
5924 changed = arsta->changed;
5931 spin_unlock_bh(&ar->data_lock);
5933 mutex_lock(&ar->conf_mutex);
5935 nss = max_t(u32, 1, nss);
5936 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5937 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5939 if (changed & IEEE80211_RC_BW_CHANGED) {
5940 enum wmi_phy_mode mode;
5942 mode = chan_to_phymode(&def);
5943 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
5944 sta->addr, bw, mode);
5946 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5947 WMI_PEER_PHYMODE, mode);
5949 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
5950 sta->addr, mode, err);
5954 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5955 WMI_PEER_CHAN_WIDTH, bw);
5957 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5958 sta->addr, bw, err);
5961 if (changed & IEEE80211_RC_NSS_CHANGED) {
5962 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5965 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5968 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5969 sta->addr, nss, err);
5972 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5976 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5977 WMI_PEER_SMPS_STATE, smps);
5979 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5980 sta->addr, smps, err);
5983 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5984 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5987 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5989 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5994 mutex_unlock(&ar->conf_mutex);
5997 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5998 struct ieee80211_sta *sta)
6000 struct ath10k *ar = arvif->ar;
6002 lockdep_assert_held(&ar->conf_mutex);
6004 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6007 if (ar->num_stations >= ar->max_num_stations)
6015 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6016 struct ieee80211_sta *sta)
6018 struct ath10k *ar = arvif->ar;
6020 lockdep_assert_held(&ar->conf_mutex);
6022 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6028 struct ath10k_mac_tdls_iter_data {
6029 u32 num_tdls_stations;
6030 struct ieee80211_vif *curr_vif;
6033 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
6034 struct ieee80211_sta *sta)
6036 struct ath10k_mac_tdls_iter_data *iter_data = data;
6037 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6038 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
6040 if (sta->tdls && sta_vif == iter_data->curr_vif)
6041 iter_data->num_tdls_stations++;
6044 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
6045 struct ieee80211_vif *vif)
6047 struct ath10k_mac_tdls_iter_data data = {};
6049 data.curr_vif = vif;
6051 ieee80211_iterate_stations_atomic(hw,
6052 ath10k_mac_tdls_vif_stations_count_iter,
6054 return data.num_tdls_stations;
6057 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
6058 struct ieee80211_vif *vif)
6060 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6061 int *num_tdls_vifs = data;
6063 if (vif->type != NL80211_IFTYPE_STATION)
6066 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
6070 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
6072 int num_tdls_vifs = 0;
6074 ieee80211_iterate_active_interfaces_atomic(hw,
6075 IEEE80211_IFACE_ITER_NORMAL,
6076 ath10k_mac_tdls_vifs_count_iter,
6078 return num_tdls_vifs;
6081 static int ath10k_sta_state(struct ieee80211_hw *hw,
6082 struct ieee80211_vif *vif,
6083 struct ieee80211_sta *sta,
6084 enum ieee80211_sta_state old_state,
6085 enum ieee80211_sta_state new_state)
6087 struct ath10k *ar = hw->priv;
6088 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6089 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6090 struct ath10k_peer *peer;
6094 if (old_state == IEEE80211_STA_NOTEXIST &&
6095 new_state == IEEE80211_STA_NONE) {
6096 memset(arsta, 0, sizeof(*arsta));
6097 arsta->arvif = arvif;
6098 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6100 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6101 ath10k_mac_txq_init(sta->txq[i]);
6104 /* cancel must be done outside the mutex to avoid deadlock */
6105 if ((old_state == IEEE80211_STA_NONE &&
6106 new_state == IEEE80211_STA_NOTEXIST))
6107 cancel_work_sync(&arsta->update_wk);
6109 mutex_lock(&ar->conf_mutex);
6111 if (old_state == IEEE80211_STA_NOTEXIST &&
6112 new_state == IEEE80211_STA_NONE) {
6114 * New station addition.
6116 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6117 u32 num_tdls_stations;
6120 ath10k_dbg(ar, ATH10K_DBG_MAC,
6121 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6122 arvif->vdev_id, sta->addr,
6123 ar->num_stations + 1, ar->max_num_stations,
6124 ar->num_peers + 1, ar->max_num_peers);
6126 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6127 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6130 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6131 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6133 ar->max_num_tdls_vdevs);
6137 peer_type = WMI_PEER_TYPE_TDLS;
6140 ret = ath10k_mac_inc_num_stations(arvif, sta);
6142 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6143 ar->max_num_stations);
6147 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6148 sta->addr, peer_type);
6150 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6151 sta->addr, arvif->vdev_id, ret);
6152 ath10k_mac_dec_num_stations(arvif, sta);
6156 spin_lock_bh(&ar->data_lock);
6158 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6160 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6161 vif->addr, arvif->vdev_id);
6162 spin_unlock_bh(&ar->data_lock);
6163 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6164 ath10k_mac_dec_num_stations(arvif, sta);
6169 arsta->peer_id = find_first_bit(peer->peer_ids,
6170 ATH10K_MAX_NUM_PEER_IDS);
6172 spin_unlock_bh(&ar->data_lock);
6177 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6178 WMI_TDLS_ENABLE_ACTIVE);
6180 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6181 arvif->vdev_id, ret);
6182 ath10k_peer_delete(ar, arvif->vdev_id,
6184 ath10k_mac_dec_num_stations(arvif, sta);
6188 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6189 WMI_TDLS_PEER_STATE_PEERING);
6192 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6193 sta->addr, arvif->vdev_id, ret);
6194 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6195 ath10k_mac_dec_num_stations(arvif, sta);
6197 if (num_tdls_stations != 0)
6199 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6202 } else if ((old_state == IEEE80211_STA_NONE &&
6203 new_state == IEEE80211_STA_NOTEXIST)) {
6205 * Existing station deletion.
6207 ath10k_dbg(ar, ATH10K_DBG_MAC,
6208 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6209 arvif->vdev_id, sta->addr, sta);
6212 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6214 WMI_TDLS_PEER_STATE_TEARDOWN);
6216 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6218 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6221 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6223 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6224 sta->addr, arvif->vdev_id, ret);
6226 ath10k_mac_dec_num_stations(arvif, sta);
6228 spin_lock_bh(&ar->data_lock);
6229 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6230 peer = ar->peer_map[i];
6234 if (peer->sta == sta) {
6235 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6236 sta->addr, peer, i, arvif->vdev_id);
6239 /* Clean up the peer object as well since we
6240 * must have failed to do this above.
6242 ath10k_peer_map_cleanup(ar, peer);
6245 spin_unlock_bh(&ar->data_lock);
6247 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6248 ath10k_mac_txq_unref(ar, sta->txq[i]);
6253 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6256 /* This was the last tdls peer in current vif */
6257 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6260 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6261 arvif->vdev_id, ret);
6263 } else if (old_state == IEEE80211_STA_AUTH &&
6264 new_state == IEEE80211_STA_ASSOC &&
6265 (vif->type == NL80211_IFTYPE_AP ||
6266 vif->type == NL80211_IFTYPE_MESH_POINT ||
6267 vif->type == NL80211_IFTYPE_ADHOC)) {
6271 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6274 ret = ath10k_station_assoc(ar, vif, sta, false);
6276 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6277 sta->addr, arvif->vdev_id, ret);
6278 } else if (old_state == IEEE80211_STA_ASSOC &&
6279 new_state == IEEE80211_STA_AUTHORIZED &&
6282 * Tdls station authorized.
6284 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6287 ret = ath10k_station_assoc(ar, vif, sta, false);
6289 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6290 sta->addr, arvif->vdev_id, ret);
6294 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6295 WMI_TDLS_PEER_STATE_CONNECTED);
6297 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6298 sta->addr, arvif->vdev_id, ret);
6299 } else if (old_state == IEEE80211_STA_ASSOC &&
6300 new_state == IEEE80211_STA_AUTH &&
6301 (vif->type == NL80211_IFTYPE_AP ||
6302 vif->type == NL80211_IFTYPE_MESH_POINT ||
6303 vif->type == NL80211_IFTYPE_ADHOC)) {
6307 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6310 ret = ath10k_station_disassoc(ar, vif, sta);
6312 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6313 sta->addr, arvif->vdev_id, ret);
6316 mutex_unlock(&ar->conf_mutex);
6320 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6321 u16 ac, bool enable)
6323 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6324 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6325 u32 prio = 0, acc = 0;
6329 lockdep_assert_held(&ar->conf_mutex);
6331 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6335 case IEEE80211_AC_VO:
6336 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6337 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6341 case IEEE80211_AC_VI:
6342 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6343 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6347 case IEEE80211_AC_BE:
6348 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6349 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6353 case IEEE80211_AC_BK:
6354 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6355 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6362 arvif->u.sta.uapsd |= value;
6364 arvif->u.sta.uapsd &= ~value;
6366 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6367 WMI_STA_PS_PARAM_UAPSD,
6368 arvif->u.sta.uapsd);
6370 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6374 if (arvif->u.sta.uapsd)
6375 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6377 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6379 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6380 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6383 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6385 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6387 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6388 arvif->vdev_id, ret);
6392 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6394 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6395 arvif->vdev_id, ret);
6399 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6400 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6401 /* Only userspace can make an educated decision when to send
6402 * trigger frame. The following effectively disables u-UAPSD
6403 * autotrigger in firmware (which is enabled by default
6404 * provided the autotrigger service is available).
6408 arg.user_priority = prio;
6409 arg.service_interval = 0;
6410 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6411 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6413 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6414 arvif->bssid, &arg, 1);
6416 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6426 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6427 struct ieee80211_vif *vif, u16 ac,
6428 const struct ieee80211_tx_queue_params *params)
6430 struct ath10k *ar = hw->priv;
6431 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6432 struct wmi_wmm_params_arg *p = NULL;
6435 mutex_lock(&ar->conf_mutex);
6438 case IEEE80211_AC_VO:
6439 p = &arvif->wmm_params.ac_vo;
6441 case IEEE80211_AC_VI:
6442 p = &arvif->wmm_params.ac_vi;
6444 case IEEE80211_AC_BE:
6445 p = &arvif->wmm_params.ac_be;
6447 case IEEE80211_AC_BK:
6448 p = &arvif->wmm_params.ac_bk;
6457 p->cwmin = params->cw_min;
6458 p->cwmax = params->cw_max;
6459 p->aifs = params->aifs;
6462 * The channel time duration programmed in the HW is in absolute
6463 * microseconds, while mac80211 gives the txop in units of
6466 p->txop = params->txop * 32;
6468 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6469 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6470 &arvif->wmm_params);
6472 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6473 arvif->vdev_id, ret);
6477 /* This won't work well with multi-interface cases but it's
6478 * better than nothing.
6480 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6482 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6487 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6489 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6492 mutex_unlock(&ar->conf_mutex);
6496 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6498 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6499 struct ieee80211_vif *vif,
6500 struct ieee80211_channel *chan,
6502 enum ieee80211_roc_type type)
6504 struct ath10k *ar = hw->priv;
6505 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6506 struct wmi_start_scan_arg arg;
6510 mutex_lock(&ar->conf_mutex);
6512 spin_lock_bh(&ar->data_lock);
6513 switch (ar->scan.state) {
6514 case ATH10K_SCAN_IDLE:
6515 reinit_completion(&ar->scan.started);
6516 reinit_completion(&ar->scan.completed);
6517 reinit_completion(&ar->scan.on_channel);
6518 ar->scan.state = ATH10K_SCAN_STARTING;
6519 ar->scan.is_roc = true;
6520 ar->scan.vdev_id = arvif->vdev_id;
6521 ar->scan.roc_freq = chan->center_freq;
6522 ar->scan.roc_notify = true;
6525 case ATH10K_SCAN_STARTING:
6526 case ATH10K_SCAN_RUNNING:
6527 case ATH10K_SCAN_ABORTING:
6531 spin_unlock_bh(&ar->data_lock);
6536 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6538 memset(&arg, 0, sizeof(arg));
6539 ath10k_wmi_start_scan_init(ar, &arg);
6540 arg.vdev_id = arvif->vdev_id;
6541 arg.scan_id = ATH10K_SCAN_ID;
6543 arg.channels[0] = chan->center_freq;
6544 arg.dwell_time_active = scan_time_msec;
6545 arg.dwell_time_passive = scan_time_msec;
6546 arg.max_scan_time = scan_time_msec;
6547 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6548 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6549 arg.burst_duration_ms = duration;
6551 ret = ath10k_start_scan(ar, &arg);
6553 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6554 spin_lock_bh(&ar->data_lock);
6555 ar->scan.state = ATH10K_SCAN_IDLE;
6556 spin_unlock_bh(&ar->data_lock);
6560 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6562 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6564 ret = ath10k_scan_stop(ar);
6566 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6572 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6573 msecs_to_jiffies(duration));
6577 mutex_unlock(&ar->conf_mutex);
6581 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6583 struct ath10k *ar = hw->priv;
6585 mutex_lock(&ar->conf_mutex);
6587 spin_lock_bh(&ar->data_lock);
6588 ar->scan.roc_notify = false;
6589 spin_unlock_bh(&ar->data_lock);
6591 ath10k_scan_abort(ar);
6593 mutex_unlock(&ar->conf_mutex);
6595 cancel_delayed_work_sync(&ar->scan.timeout);
6601 * Both RTS and Fragmentation threshold are interface-specific
6602 * in ath10k, but device-specific in mac80211.
6605 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6607 struct ath10k *ar = hw->priv;
6608 struct ath10k_vif *arvif;
6611 mutex_lock(&ar->conf_mutex);
6612 list_for_each_entry(arvif, &ar->arvifs, list) {
6613 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6614 arvif->vdev_id, value);
6616 ret = ath10k_mac_set_rts(arvif, value);
6618 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6619 arvif->vdev_id, ret);
6623 mutex_unlock(&ar->conf_mutex);
6628 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6630 /* Even though there's a WMI enum for fragmentation threshold no known
6631 * firmware actually implements it. Moreover it is not possible to rely
6632 * frame fragmentation to mac80211 because firmware clears the "more
6633 * fragments" bit in frame control making it impossible for remote
6634 * devices to reassemble frames.
6636 * Hence implement a dummy callback just to say fragmentation isn't
6637 * supported. This effectively prevents mac80211 from doing frame
6638 * fragmentation in software.
6643 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6644 u32 queues, bool drop)
6646 struct ath10k *ar = hw->priv;
6650 /* mac80211 doesn't care if we really xmit queued frames or not
6651 * we'll collect those frames either way if we stop/delete vdevs
6656 mutex_lock(&ar->conf_mutex);
6658 if (ar->state == ATH10K_STATE_WEDGED)
6661 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6664 spin_lock_bh(&ar->htt.tx_lock);
6665 empty = (ar->htt.num_pending_tx == 0);
6666 spin_unlock_bh(&ar->htt.tx_lock);
6668 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6669 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6673 }), ATH10K_FLUSH_TIMEOUT_HZ);
6675 if (time_left == 0 || skip)
6676 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6677 skip, ar->state, time_left);
6680 mutex_unlock(&ar->conf_mutex);
6683 /* TODO: Implement this function properly
6684 * For now it is needed to reply to Probe Requests in IBSS mode.
6685 * Propably we need this information from FW.
6687 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6692 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6693 enum ieee80211_reconfig_type reconfig_type)
6695 struct ath10k *ar = hw->priv;
6697 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6700 mutex_lock(&ar->conf_mutex);
6702 /* If device failed to restart it will be in a different state, e.g.
6703 * ATH10K_STATE_WEDGED
6705 if (ar->state == ATH10K_STATE_RESTARTED) {
6706 ath10k_info(ar, "device successfully recovered\n");
6707 ar->state = ATH10K_STATE_ON;
6708 ieee80211_wake_queues(ar->hw);
6711 mutex_unlock(&ar->conf_mutex);
6715 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6716 struct ieee80211_channel *channel)
6719 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6721 lockdep_assert_held(&ar->conf_mutex);
6723 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6724 (ar->rx_channel != channel))
6727 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6728 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6732 reinit_completion(&ar->bss_survey_done);
6734 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6736 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6740 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6742 ath10k_warn(ar, "bss channel survey timed out\n");
6747 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6748 struct survey_info *survey)
6750 struct ath10k *ar = hw->priv;
6751 struct ieee80211_supported_band *sband;
6752 struct survey_info *ar_survey = &ar->survey[idx];
6755 mutex_lock(&ar->conf_mutex);
6757 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6758 if (sband && idx >= sband->n_channels) {
6759 idx -= sband->n_channels;
6764 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6766 if (!sband || idx >= sband->n_channels) {
6771 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6773 spin_lock_bh(&ar->data_lock);
6774 memcpy(survey, ar_survey, sizeof(*survey));
6775 spin_unlock_bh(&ar->data_lock);
6777 survey->channel = &sband->channels[idx];
6779 if (ar->rx_channel == survey->channel)
6780 survey->filled |= SURVEY_INFO_IN_USE;
6783 mutex_unlock(&ar->conf_mutex);
6788 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6789 enum nl80211_band band,
6790 const struct cfg80211_bitrate_mask *mask)
6795 num_rates += hweight32(mask->control[band].legacy);
6797 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6798 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6800 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6801 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6803 return num_rates == 1;
6807 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6808 enum nl80211_band band,
6809 const struct cfg80211_bitrate_mask *mask,
6812 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6813 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6815 u8 vht_nss_mask = 0;
6818 if (mask->control[band].legacy)
6821 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6822 if (mask->control[band].ht_mcs[i] == 0)
6824 else if (mask->control[band].ht_mcs[i] ==
6825 sband->ht_cap.mcs.rx_mask[i])
6826 ht_nss_mask |= BIT(i);
6831 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6832 if (mask->control[band].vht_mcs[i] == 0)
6834 else if (mask->control[band].vht_mcs[i] ==
6835 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6836 vht_nss_mask |= BIT(i);
6841 if (ht_nss_mask != vht_nss_mask)
6844 if (ht_nss_mask == 0)
6847 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6850 *nss = fls(ht_nss_mask);
6856 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6857 enum nl80211_band band,
6858 const struct cfg80211_bitrate_mask *mask,
6861 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6868 if (hweight32(mask->control[band].legacy) == 1) {
6869 rate_idx = ffs(mask->control[band].legacy) - 1;
6871 hw_rate = sband->bitrates[rate_idx].hw_value;
6872 bitrate = sband->bitrates[rate_idx].bitrate;
6874 if (ath10k_mac_bitrate_is_cck(bitrate))
6875 preamble = WMI_RATE_PREAMBLE_CCK;
6877 preamble = WMI_RATE_PREAMBLE_OFDM;
6880 *rate = preamble << 6 |
6887 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6888 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6890 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6892 (ffs(mask->control[band].ht_mcs[i]) - 1);
6898 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6899 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6901 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6903 (ffs(mask->control[band].vht_mcs[i]) - 1);
6912 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6913 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6915 struct ath10k *ar = arvif->ar;
6919 lockdep_assert_held(&ar->conf_mutex);
6921 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6922 arvif->vdev_id, rate, nss, sgi);
6924 vdev_param = ar->wmi.vdev_param->fixed_rate;
6925 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6927 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6932 vdev_param = ar->wmi.vdev_param->nss;
6933 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6935 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6939 vdev_param = ar->wmi.vdev_param->sgi;
6940 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6942 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6946 vdev_param = ar->wmi.vdev_param->ldpc;
6947 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6949 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6957 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6958 enum nl80211_band band,
6959 const struct cfg80211_bitrate_mask *mask)
6964 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6965 * to express all VHT MCS rate masks. Effectively only the following
6966 * ranges can be used: none, 0-7, 0-8 and 0-9.
6968 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6969 vht_mcs = mask->control[band].vht_mcs[i];
6978 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6986 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6987 struct ieee80211_sta *sta)
6989 struct ath10k_vif *arvif = data;
6990 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6991 struct ath10k *ar = arvif->ar;
6993 if (arsta->arvif != arvif)
6996 spin_lock_bh(&ar->data_lock);
6997 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6998 spin_unlock_bh(&ar->data_lock);
7000 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7003 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7004 struct ieee80211_vif *vif,
7005 const struct cfg80211_bitrate_mask *mask)
7007 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7008 struct cfg80211_chan_def def;
7009 struct ath10k *ar = arvif->ar;
7010 enum nl80211_band band;
7011 const u8 *ht_mcs_mask;
7012 const u16 *vht_mcs_mask;
7020 if (ath10k_mac_vif_chan(vif, &def))
7023 band = def.chan->band;
7024 ht_mcs_mask = mask->control[band].ht_mcs;
7025 vht_mcs_mask = mask->control[band].vht_mcs;
7026 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7028 sgi = mask->control[band].gi;
7029 if (sgi == NL80211_TXRATE_FORCE_LGI)
7032 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7033 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7036 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7037 arvif->vdev_id, ret);
7040 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7042 rate = WMI_FIXED_RATE_NONE;
7045 rate = WMI_FIXED_RATE_NONE;
7046 nss = min(ar->num_rf_chains,
7047 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7048 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7050 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7053 mutex_lock(&ar->conf_mutex);
7055 arvif->bitrate_mask = *mask;
7056 ieee80211_iterate_stations_atomic(ar->hw,
7057 ath10k_mac_set_bitrate_mask_iter,
7060 mutex_unlock(&ar->conf_mutex);
7063 mutex_lock(&ar->conf_mutex);
7065 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7067 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7068 arvif->vdev_id, ret);
7073 mutex_unlock(&ar->conf_mutex);
7078 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7079 struct ieee80211_vif *vif,
7080 struct ieee80211_sta *sta,
7083 struct ath10k *ar = hw->priv;
7084 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7085 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7086 struct ath10k_peer *peer;
7089 spin_lock_bh(&ar->data_lock);
7091 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7093 spin_unlock_bh(&ar->data_lock);
7094 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7095 sta->addr, arvif->vdev_id);
7099 ath10k_dbg(ar, ATH10K_DBG_MAC,
7100 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7101 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7104 if (changed & IEEE80211_RC_BW_CHANGED) {
7105 bw = WMI_PEER_CHWIDTH_20MHZ;
7107 switch (sta->bandwidth) {
7108 case IEEE80211_STA_RX_BW_20:
7109 bw = WMI_PEER_CHWIDTH_20MHZ;
7111 case IEEE80211_STA_RX_BW_40:
7112 bw = WMI_PEER_CHWIDTH_40MHZ;
7114 case IEEE80211_STA_RX_BW_80:
7115 bw = WMI_PEER_CHWIDTH_80MHZ;
7117 case IEEE80211_STA_RX_BW_160:
7118 bw = WMI_PEER_CHWIDTH_160MHZ;
7121 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7122 sta->bandwidth, sta->addr);
7123 bw = WMI_PEER_CHWIDTH_20MHZ;
7130 if (changed & IEEE80211_RC_NSS_CHANGED)
7131 arsta->nss = sta->rx_nss;
7133 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7134 smps = WMI_PEER_SMPS_PS_NONE;
7136 switch (sta->smps_mode) {
7137 case IEEE80211_SMPS_AUTOMATIC:
7138 case IEEE80211_SMPS_OFF:
7139 smps = WMI_PEER_SMPS_PS_NONE;
7141 case IEEE80211_SMPS_STATIC:
7142 smps = WMI_PEER_SMPS_STATIC;
7144 case IEEE80211_SMPS_DYNAMIC:
7145 smps = WMI_PEER_SMPS_DYNAMIC;
7147 case IEEE80211_SMPS_NUM_MODES:
7148 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7149 sta->smps_mode, sta->addr);
7150 smps = WMI_PEER_SMPS_PS_NONE;
7157 arsta->changed |= changed;
7159 spin_unlock_bh(&ar->data_lock);
7161 ieee80211_queue_work(hw, &arsta->update_wk);
7164 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7165 struct ieee80211_vif *vif, s64 tsf_offset)
7167 struct ath10k *ar = hw->priv;
7168 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7169 u32 offset, vdev_param;
7172 if (tsf_offset < 0) {
7173 vdev_param = ar->wmi.vdev_param->dec_tsf;
7174 offset = -tsf_offset;
7176 vdev_param = ar->wmi.vdev_param->inc_tsf;
7177 offset = tsf_offset;
7180 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7181 vdev_param, offset);
7183 if (ret && ret != -EOPNOTSUPP)
7184 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7185 offset, vdev_param, ret);
7188 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7189 struct ieee80211_vif *vif,
7190 struct ieee80211_ampdu_params *params)
7192 struct ath10k *ar = hw->priv;
7193 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7194 struct ieee80211_sta *sta = params->sta;
7195 enum ieee80211_ampdu_mlme_action action = params->action;
7196 u16 tid = params->tid;
7198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7199 arvif->vdev_id, sta->addr, tid, action);
7202 case IEEE80211_AMPDU_RX_START:
7203 case IEEE80211_AMPDU_RX_STOP:
7204 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7205 * creation/removal. Do we need to verify this?
7208 case IEEE80211_AMPDU_TX_START:
7209 case IEEE80211_AMPDU_TX_STOP_CONT:
7210 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7211 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7212 case IEEE80211_AMPDU_TX_OPERATIONAL:
7213 /* Firmware offloads Tx aggregation entirely so deny mac80211
7214 * Tx aggregation requests.
7223 ath10k_mac_update_rx_channel(struct ath10k *ar,
7224 struct ieee80211_chanctx_conf *ctx,
7225 struct ieee80211_vif_chanctx_switch *vifs,
7228 struct cfg80211_chan_def *def = NULL;
7230 /* Both locks are required because ar->rx_channel is modified. This
7231 * allows readers to hold either lock.
7233 lockdep_assert_held(&ar->conf_mutex);
7234 lockdep_assert_held(&ar->data_lock);
7236 WARN_ON(ctx && vifs);
7237 WARN_ON(vifs && !n_vifs);
7239 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7240 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7241 * ppdu on Rx may reduce performance on low-end systems. It should be
7242 * possible to make tables/hashmaps to speed the lookup up (be vary of
7243 * cpu data cache lines though regarding sizes) but to keep the initial
7244 * implementation simple and less intrusive fallback to the slow lookup
7245 * only for multi-channel cases. Single-channel cases will remain to
7246 * use the old channel derival and thus performance should not be
7250 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7251 ieee80211_iter_chan_contexts_atomic(ar->hw,
7252 ath10k_mac_get_any_chandef_iter,
7256 def = &vifs[0].new_ctx->def;
7258 ar->rx_channel = def->chan;
7259 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7260 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7261 /* During driver restart due to firmware assert, since mac80211
7262 * already has valid channel context for given radio, channel
7263 * context iteration return num_chanctx > 0. So fix rx_channel
7264 * when restart is in progress.
7266 ar->rx_channel = ctx->def.chan;
7268 ar->rx_channel = NULL;
7274 ath10k_mac_update_vif_chan(struct ath10k *ar,
7275 struct ieee80211_vif_chanctx_switch *vifs,
7278 struct ath10k_vif *arvif;
7282 lockdep_assert_held(&ar->conf_mutex);
7284 /* First stop monitor interface. Some FW versions crash if there's a
7285 * lone monitor interface.
7287 if (ar->monitor_started)
7288 ath10k_monitor_stop(ar);
7290 for (i = 0; i < n_vifs; i++) {
7291 arvif = (void *)vifs[i].vif->drv_priv;
7293 ath10k_dbg(ar, ATH10K_DBG_MAC,
7294 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7296 vifs[i].old_ctx->def.chan->center_freq,
7297 vifs[i].new_ctx->def.chan->center_freq,
7298 vifs[i].old_ctx->def.width,
7299 vifs[i].new_ctx->def.width);
7301 if (WARN_ON(!arvif->is_started))
7304 if (WARN_ON(!arvif->is_up))
7307 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7309 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7310 arvif->vdev_id, ret);
7315 /* All relevant vdevs are downed and associated channel resources
7316 * should be available for the channel switch now.
7319 spin_lock_bh(&ar->data_lock);
7320 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7321 spin_unlock_bh(&ar->data_lock);
7323 for (i = 0; i < n_vifs; i++) {
7324 arvif = (void *)vifs[i].vif->drv_priv;
7326 if (WARN_ON(!arvif->is_started))
7329 if (WARN_ON(!arvif->is_up))
7332 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7334 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7337 ret = ath10k_mac_setup_prb_tmpl(arvif);
7339 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7342 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7344 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7345 arvif->vdev_id, ret);
7349 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7352 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7353 arvif->vdev_id, ret);
7358 ath10k_monitor_recalc(ar);
7362 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7363 struct ieee80211_chanctx_conf *ctx)
7365 struct ath10k *ar = hw->priv;
7367 ath10k_dbg(ar, ATH10K_DBG_MAC,
7368 "mac chanctx add freq %hu width %d ptr %pK\n",
7369 ctx->def.chan->center_freq, ctx->def.width, ctx);
7371 mutex_lock(&ar->conf_mutex);
7373 spin_lock_bh(&ar->data_lock);
7374 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7375 spin_unlock_bh(&ar->data_lock);
7377 ath10k_recalc_radar_detection(ar);
7378 ath10k_monitor_recalc(ar);
7380 mutex_unlock(&ar->conf_mutex);
7386 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7387 struct ieee80211_chanctx_conf *ctx)
7389 struct ath10k *ar = hw->priv;
7391 ath10k_dbg(ar, ATH10K_DBG_MAC,
7392 "mac chanctx remove freq %hu width %d ptr %pK\n",
7393 ctx->def.chan->center_freq, ctx->def.width, ctx);
7395 mutex_lock(&ar->conf_mutex);
7397 spin_lock_bh(&ar->data_lock);
7398 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7399 spin_unlock_bh(&ar->data_lock);
7401 ath10k_recalc_radar_detection(ar);
7402 ath10k_monitor_recalc(ar);
7404 mutex_unlock(&ar->conf_mutex);
7407 struct ath10k_mac_change_chanctx_arg {
7408 struct ieee80211_chanctx_conf *ctx;
7409 struct ieee80211_vif_chanctx_switch *vifs;
7415 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7416 struct ieee80211_vif *vif)
7418 struct ath10k_mac_change_chanctx_arg *arg = data;
7420 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7427 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7428 struct ieee80211_vif *vif)
7430 struct ath10k_mac_change_chanctx_arg *arg = data;
7431 struct ieee80211_chanctx_conf *ctx;
7433 ctx = rcu_access_pointer(vif->chanctx_conf);
7434 if (ctx != arg->ctx)
7437 if (WARN_ON(arg->next_vif == arg->n_vifs))
7440 arg->vifs[arg->next_vif].vif = vif;
7441 arg->vifs[arg->next_vif].old_ctx = ctx;
7442 arg->vifs[arg->next_vif].new_ctx = ctx;
7447 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7448 struct ieee80211_chanctx_conf *ctx,
7451 struct ath10k *ar = hw->priv;
7452 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7454 mutex_lock(&ar->conf_mutex);
7456 ath10k_dbg(ar, ATH10K_DBG_MAC,
7457 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7458 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7460 /* This shouldn't really happen because channel switching should use
7461 * switch_vif_chanctx().
7463 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7466 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7467 ieee80211_iterate_active_interfaces_atomic(
7469 IEEE80211_IFACE_ITER_NORMAL,
7470 ath10k_mac_change_chanctx_cnt_iter,
7472 if (arg.n_vifs == 0)
7475 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7480 ieee80211_iterate_active_interfaces_atomic(
7482 IEEE80211_IFACE_ITER_NORMAL,
7483 ath10k_mac_change_chanctx_fill_iter,
7485 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7490 ath10k_recalc_radar_detection(ar);
7492 /* FIXME: How to configure Rx chains properly? */
7494 /* No other actions are actually necessary. Firmware maintains channel
7495 * definitions per vdev internally and there's no host-side channel
7496 * context abstraction to configure, e.g. channel width.
7500 mutex_unlock(&ar->conf_mutex);
7504 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7505 struct ieee80211_vif *vif,
7506 struct ieee80211_chanctx_conf *ctx)
7508 struct ath10k *ar = hw->priv;
7509 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7512 mutex_lock(&ar->conf_mutex);
7514 ath10k_dbg(ar, ATH10K_DBG_MAC,
7515 "mac chanctx assign ptr %pK vdev_id %i\n",
7516 ctx, arvif->vdev_id);
7518 if (WARN_ON(arvif->is_started)) {
7519 mutex_unlock(&ar->conf_mutex);
7523 ret = ath10k_vdev_start(arvif, &ctx->def);
7525 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7526 arvif->vdev_id, vif->addr,
7527 ctx->def.chan->center_freq, ret);
7531 arvif->is_started = true;
7533 ret = ath10k_mac_vif_setup_ps(arvif);
7535 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7536 arvif->vdev_id, ret);
7540 if (vif->type == NL80211_IFTYPE_MONITOR) {
7541 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7543 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7544 arvif->vdev_id, ret);
7548 arvif->is_up = true;
7551 if (ath10k_mac_can_set_cts_prot(arvif)) {
7552 ret = ath10k_mac_set_cts_prot(arvif);
7554 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7555 arvif->vdev_id, ret);
7558 mutex_unlock(&ar->conf_mutex);
7562 ath10k_vdev_stop(arvif);
7563 arvif->is_started = false;
7564 ath10k_mac_vif_setup_ps(arvif);
7567 mutex_unlock(&ar->conf_mutex);
7572 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7573 struct ieee80211_vif *vif,
7574 struct ieee80211_chanctx_conf *ctx)
7576 struct ath10k *ar = hw->priv;
7577 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7580 mutex_lock(&ar->conf_mutex);
7582 ath10k_dbg(ar, ATH10K_DBG_MAC,
7583 "mac chanctx unassign ptr %pK vdev_id %i\n",
7584 ctx, arvif->vdev_id);
7586 WARN_ON(!arvif->is_started);
7588 if (vif->type == NL80211_IFTYPE_MONITOR) {
7589 WARN_ON(!arvif->is_up);
7591 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7593 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7594 arvif->vdev_id, ret);
7596 arvif->is_up = false;
7599 ret = ath10k_vdev_stop(arvif);
7601 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7602 arvif->vdev_id, ret);
7604 arvif->is_started = false;
7606 mutex_unlock(&ar->conf_mutex);
7610 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7611 struct ieee80211_vif_chanctx_switch *vifs,
7613 enum ieee80211_chanctx_switch_mode mode)
7615 struct ath10k *ar = hw->priv;
7617 mutex_lock(&ar->conf_mutex);
7619 ath10k_dbg(ar, ATH10K_DBG_MAC,
7620 "mac chanctx switch n_vifs %d mode %d\n",
7622 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7624 mutex_unlock(&ar->conf_mutex);
7628 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7629 struct ieee80211_vif *vif,
7630 struct ieee80211_sta *sta)
7633 struct ath10k_peer *peer;
7637 list_for_each_entry(peer, &ar->peers, list)
7638 if (peer->sta == sta)
7639 peer->removed = true;
7642 static const struct ieee80211_ops ath10k_ops = {
7643 .tx = ath10k_mac_op_tx,
7644 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7645 .start = ath10k_start,
7646 .stop = ath10k_stop,
7647 .config = ath10k_config,
7648 .add_interface = ath10k_add_interface,
7649 .remove_interface = ath10k_remove_interface,
7650 .configure_filter = ath10k_configure_filter,
7651 .bss_info_changed = ath10k_bss_info_changed,
7652 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7653 .hw_scan = ath10k_hw_scan,
7654 .cancel_hw_scan = ath10k_cancel_hw_scan,
7655 .set_key = ath10k_set_key,
7656 .set_default_unicast_key = ath10k_set_default_unicast_key,
7657 .sta_state = ath10k_sta_state,
7658 .conf_tx = ath10k_conf_tx,
7659 .remain_on_channel = ath10k_remain_on_channel,
7660 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7661 .set_rts_threshold = ath10k_set_rts_threshold,
7662 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7663 .flush = ath10k_flush,
7664 .tx_last_beacon = ath10k_tx_last_beacon,
7665 .set_antenna = ath10k_set_antenna,
7666 .get_antenna = ath10k_get_antenna,
7667 .reconfig_complete = ath10k_reconfig_complete,
7668 .get_survey = ath10k_get_survey,
7669 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7670 .sta_rc_update = ath10k_sta_rc_update,
7671 .offset_tsf = ath10k_offset_tsf,
7672 .ampdu_action = ath10k_ampdu_action,
7673 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7674 .get_et_stats = ath10k_debug_get_et_stats,
7675 .get_et_strings = ath10k_debug_get_et_strings,
7676 .add_chanctx = ath10k_mac_op_add_chanctx,
7677 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7678 .change_chanctx = ath10k_mac_op_change_chanctx,
7679 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7680 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7681 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7682 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7684 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7687 .suspend = ath10k_wow_op_suspend,
7688 .resume = ath10k_wow_op_resume,
7689 .set_wakeup = ath10k_wow_op_set_wakeup,
7691 #ifdef CONFIG_MAC80211_DEBUGFS
7692 .sta_add_debugfs = ath10k_sta_add_debugfs,
7693 .sta_statistics = ath10k_sta_statistics,
7697 #define CHAN2G(_channel, _freq, _flags) { \
7698 .band = NL80211_BAND_2GHZ, \
7699 .hw_value = (_channel), \
7700 .center_freq = (_freq), \
7701 .flags = (_flags), \
7702 .max_antenna_gain = 0, \
7706 #define CHAN5G(_channel, _freq, _flags) { \
7707 .band = NL80211_BAND_5GHZ, \
7708 .hw_value = (_channel), \
7709 .center_freq = (_freq), \
7710 .flags = (_flags), \
7711 .max_antenna_gain = 0, \
7715 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7725 CHAN2G(10, 2457, 0),
7726 CHAN2G(11, 2462, 0),
7727 CHAN2G(12, 2467, 0),
7728 CHAN2G(13, 2472, 0),
7729 CHAN2G(14, 2484, 0),
7732 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7733 CHAN5G(36, 5180, 0),
7734 CHAN5G(40, 5200, 0),
7735 CHAN5G(44, 5220, 0),
7736 CHAN5G(48, 5240, 0),
7737 CHAN5G(52, 5260, 0),
7738 CHAN5G(56, 5280, 0),
7739 CHAN5G(60, 5300, 0),
7740 CHAN5G(64, 5320, 0),
7741 CHAN5G(100, 5500, 0),
7742 CHAN5G(104, 5520, 0),
7743 CHAN5G(108, 5540, 0),
7744 CHAN5G(112, 5560, 0),
7745 CHAN5G(116, 5580, 0),
7746 CHAN5G(120, 5600, 0),
7747 CHAN5G(124, 5620, 0),
7748 CHAN5G(128, 5640, 0),
7749 CHAN5G(132, 5660, 0),
7750 CHAN5G(136, 5680, 0),
7751 CHAN5G(140, 5700, 0),
7752 CHAN5G(144, 5720, 0),
7753 CHAN5G(149, 5745, 0),
7754 CHAN5G(153, 5765, 0),
7755 CHAN5G(157, 5785, 0),
7756 CHAN5G(161, 5805, 0),
7757 CHAN5G(165, 5825, 0),
7758 CHAN5G(169, 5845, 0),
7761 struct ath10k *ath10k_mac_create(size_t priv_size)
7763 struct ieee80211_hw *hw;
7764 struct ieee80211_ops *ops;
7767 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7771 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7784 void ath10k_mac_destroy(struct ath10k *ar)
7786 struct ieee80211_ops *ops = ar->ops;
7788 ieee80211_free_hw(ar->hw);
7792 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7795 .types = BIT(NL80211_IFTYPE_STATION)
7796 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7800 .types = BIT(NL80211_IFTYPE_P2P_GO)
7804 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7808 .types = BIT(NL80211_IFTYPE_AP)
7809 #ifdef CONFIG_MAC80211_MESH
7810 | BIT(NL80211_IFTYPE_MESH_POINT)
7815 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7818 .types = BIT(NL80211_IFTYPE_AP)
7819 #ifdef CONFIG_MAC80211_MESH
7820 | BIT(NL80211_IFTYPE_MESH_POINT)
7825 .types = BIT(NL80211_IFTYPE_STATION)
7829 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7831 .limits = ath10k_if_limits,
7832 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7833 .max_interfaces = 8,
7834 .num_different_channels = 1,
7835 .beacon_int_infra_match = true,
7839 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7841 .limits = ath10k_10x_if_limits,
7842 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7843 .max_interfaces = 8,
7844 .num_different_channels = 1,
7845 .beacon_int_infra_match = true,
7846 .beacon_int_min_gcd = 1,
7847 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7848 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7849 BIT(NL80211_CHAN_WIDTH_20) |
7850 BIT(NL80211_CHAN_WIDTH_40) |
7851 BIT(NL80211_CHAN_WIDTH_80),
7856 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7859 .types = BIT(NL80211_IFTYPE_STATION),
7863 .types = BIT(NL80211_IFTYPE_AP) |
7864 #ifdef CONFIG_MAC80211_MESH
7865 BIT(NL80211_IFTYPE_MESH_POINT) |
7867 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7868 BIT(NL80211_IFTYPE_P2P_GO),
7872 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7876 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7879 .types = BIT(NL80211_IFTYPE_STATION),
7883 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7887 .types = BIT(NL80211_IFTYPE_AP) |
7888 #ifdef CONFIG_MAC80211_MESH
7889 BIT(NL80211_IFTYPE_MESH_POINT) |
7891 BIT(NL80211_IFTYPE_P2P_GO),
7895 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7899 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7902 .types = BIT(NL80211_IFTYPE_STATION),
7906 .types = BIT(NL80211_IFTYPE_ADHOC),
7910 /* FIXME: This is not thouroughly tested. These combinations may over- or
7911 * underestimate hw/fw capabilities.
7913 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7915 .limits = ath10k_tlv_if_limit,
7916 .num_different_channels = 1,
7917 .max_interfaces = 4,
7918 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7921 .limits = ath10k_tlv_if_limit_ibss,
7922 .num_different_channels = 1,
7923 .max_interfaces = 2,
7924 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7928 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7930 .limits = ath10k_tlv_if_limit,
7931 .num_different_channels = 1,
7932 .max_interfaces = 4,
7933 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7936 .limits = ath10k_tlv_qcs_if_limit,
7937 .num_different_channels = 2,
7938 .max_interfaces = 4,
7939 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7942 .limits = ath10k_tlv_if_limit_ibss,
7943 .num_different_channels = 1,
7944 .max_interfaces = 2,
7945 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7949 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7952 .types = BIT(NL80211_IFTYPE_STATION),
7956 .types = BIT(NL80211_IFTYPE_AP)
7957 #ifdef CONFIG_MAC80211_MESH
7958 | BIT(NL80211_IFTYPE_MESH_POINT)
7963 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7965 .limits = ath10k_10_4_if_limits,
7966 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7967 .max_interfaces = 16,
7968 .num_different_channels = 1,
7969 .beacon_int_infra_match = true,
7970 .beacon_int_min_gcd = 1,
7971 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7972 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7973 BIT(NL80211_CHAN_WIDTH_20) |
7974 BIT(NL80211_CHAN_WIDTH_40) |
7975 BIT(NL80211_CHAN_WIDTH_80),
7980 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7981 struct ieee80211_vif *vif)
7983 struct ath10k_vif_iter *arvif_iter = data;
7984 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7986 if (arvif->vdev_id == arvif_iter->vdev_id)
7987 arvif_iter->arvif = arvif;
7990 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7992 struct ath10k_vif_iter arvif_iter;
7995 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7996 arvif_iter.vdev_id = vdev_id;
7998 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7999 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8001 ath10k_get_arvif_iter,
8003 if (!arvif_iter.arvif) {
8004 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8008 return arvif_iter.arvif;
8011 #define WRD_METHOD "WRDD"
8012 #define WRDD_WIFI (0x07)
8014 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8016 union acpi_object *mcc_pkg;
8017 union acpi_object *domain_type;
8018 union acpi_object *mcc_value;
8021 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8022 wrdd->package.count < 2 ||
8023 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8024 wrdd->package.elements[0].integer.value != 0) {
8025 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8029 for (i = 1; i < wrdd->package.count; ++i) {
8030 mcc_pkg = &wrdd->package.elements[i];
8032 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8034 if (mcc_pkg->package.count < 2)
8036 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8037 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8040 domain_type = &mcc_pkg->package.elements[0];
8041 if (domain_type->integer.value != WRDD_WIFI)
8044 mcc_value = &mcc_pkg->package.elements[1];
8045 return mcc_value->integer.value;
8050 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8052 struct pci_dev __maybe_unused *pdev = to_pci_dev(ar->dev);
8053 acpi_handle root_handle;
8055 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8060 root_handle = ACPI_HANDLE(&pdev->dev);
8064 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8065 if (ACPI_FAILURE(status)) {
8066 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8067 "failed to get wrd method %d\n", status);
8071 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8072 if (ACPI_FAILURE(status)) {
8073 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8074 "failed to call wrdc %d\n", status);
8078 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8079 kfree(wrdd.pointer);
8083 alpha2[0] = (alpha2_code >> 8) & 0xff;
8084 alpha2[1] = (alpha2_code >> 0) & 0xff;
8087 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8088 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8090 *rd = ath_regd_find_country_by_name(alpha2);
8094 *rd |= COUNTRY_ERD_FLAG;
8098 static int ath10k_mac_init_rd(struct ath10k *ar)
8103 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8105 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8106 "fallback to eeprom programmed regulatory settings\n");
8107 rd = ar->hw_eeprom_rd;
8110 ar->ath_common.regulatory.current_rd = rd;
8114 int ath10k_mac_register(struct ath10k *ar)
8116 static const u32 cipher_suites[] = {
8117 WLAN_CIPHER_SUITE_WEP40,
8118 WLAN_CIPHER_SUITE_WEP104,
8119 WLAN_CIPHER_SUITE_TKIP,
8120 WLAN_CIPHER_SUITE_CCMP,
8121 WLAN_CIPHER_SUITE_AES_CMAC,
8123 struct ieee80211_supported_band *band;
8127 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8129 SET_IEEE80211_DEV(ar->hw, ar->dev);
8131 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8132 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8135 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8136 channels = kmemdup(ath10k_2ghz_channels,
8137 sizeof(ath10k_2ghz_channels),
8144 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8145 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8146 band->channels = channels;
8148 if (ar->hw_params.cck_rate_map_rev2) {
8149 band->n_bitrates = ath10k_g_rates_rev2_size;
8150 band->bitrates = ath10k_g_rates_rev2;
8152 band->n_bitrates = ath10k_g_rates_size;
8153 band->bitrates = ath10k_g_rates;
8156 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8159 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8160 channels = kmemdup(ath10k_5ghz_channels,
8161 sizeof(ath10k_5ghz_channels),
8168 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8169 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8170 band->channels = channels;
8171 band->n_bitrates = ath10k_a_rates_size;
8172 band->bitrates = ath10k_a_rates;
8173 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8176 wiphy_read_of_freq_limits(ar->hw->wiphy);
8177 ath10k_mac_setup_ht_vht_cap(ar);
8179 ar->hw->wiphy->interface_modes =
8180 BIT(NL80211_IFTYPE_STATION) |
8181 BIT(NL80211_IFTYPE_AP) |
8182 BIT(NL80211_IFTYPE_MESH_POINT);
8184 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8185 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8187 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8188 ar->hw->wiphy->interface_modes |=
8189 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8190 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8191 BIT(NL80211_IFTYPE_P2P_GO);
8193 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8194 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8195 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8196 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8197 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8198 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8199 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8200 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8201 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8202 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8203 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8204 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8205 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8206 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8207 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8208 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8210 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8211 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8213 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8214 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8216 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8217 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8219 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8220 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8221 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8224 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8225 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8227 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8228 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8229 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8231 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8233 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8234 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8236 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8237 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8238 * correct Probe Responses. This is more of a hack advert..
8240 ar->hw->wiphy->probe_resp_offload |=
8241 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8242 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8243 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8246 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8247 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8248 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8249 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8252 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8253 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8254 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8256 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8257 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8258 NL80211_FEATURE_AP_SCAN;
8260 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8262 ret = ath10k_wow_init(ar);
8264 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8268 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8271 * on LL hardware queues are managed entirely by the FW
8272 * so we only advertise to mac we can do the queues thing
8274 ar->hw->queues = IEEE80211_MAX_QUEUES;
8276 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8277 * something that vdev_ids can't reach so that we don't stop the queue
8280 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8282 switch (ar->running_fw->fw_file.wmi_op_version) {
8283 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8284 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8285 ar->hw->wiphy->n_iface_combinations =
8286 ARRAY_SIZE(ath10k_if_comb);
8287 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8289 case ATH10K_FW_WMI_OP_VERSION_TLV:
8290 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8291 ar->hw->wiphy->iface_combinations =
8292 ath10k_tlv_qcs_if_comb;
8293 ar->hw->wiphy->n_iface_combinations =
8294 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8296 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8297 ar->hw->wiphy->n_iface_combinations =
8298 ARRAY_SIZE(ath10k_tlv_if_comb);
8300 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8302 case ATH10K_FW_WMI_OP_VERSION_10_1:
8303 case ATH10K_FW_WMI_OP_VERSION_10_2:
8304 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8305 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8306 ar->hw->wiphy->n_iface_combinations =
8307 ARRAY_SIZE(ath10k_10x_if_comb);
8309 case ATH10K_FW_WMI_OP_VERSION_10_4:
8310 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8311 ar->hw->wiphy->n_iface_combinations =
8312 ARRAY_SIZE(ath10k_10_4_if_comb);
8314 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8315 case ATH10K_FW_WMI_OP_VERSION_MAX:
8321 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8322 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8324 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8325 /* Init ath dfs pattern detector */
8326 ar->ath_common.debug_mask = ATH_DBG_DFS;
8327 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8330 if (!ar->dfs_detector)
8331 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8334 /* Current wake_tx_queue implementation imposes a significant
8335 * performance penalty in some setups. The tx scheduling code needs
8336 * more work anyway so disable the wake_tx_queue unless firmware
8337 * supports the pull-push mechanism.
8339 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8340 ar->running_fw->fw_file.fw_features))
8341 ar->ops->wake_tx_queue = NULL;
8343 ret = ath10k_mac_init_rd(ar);
8345 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8346 goto err_dfs_detector_exit;
8349 /* Disable set_coverage_class for chipsets that do not support it. */
8350 if (!ar->hw_params.hw_ops->set_coverage_class)
8351 ar->ops->set_coverage_class = NULL;
8353 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8354 ath10k_reg_notifier);
8356 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8357 goto err_dfs_detector_exit;
8360 ar->hw->wiphy->cipher_suites = cipher_suites;
8361 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8363 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8365 ret = ieee80211_register_hw(ar->hw);
8367 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8368 goto err_dfs_detector_exit;
8371 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8372 ret = regulatory_hint(ar->hw->wiphy,
8373 ar->ath_common.regulatory.alpha2);
8375 goto err_unregister;
8381 ieee80211_unregister_hw(ar->hw);
8383 err_dfs_detector_exit:
8384 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8385 ar->dfs_detector->exit(ar->dfs_detector);
8388 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8389 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8391 SET_IEEE80211_DEV(ar->hw, NULL);
8395 void ath10k_mac_unregister(struct ath10k *ar)
8397 ieee80211_unregister_hw(ar->hw);
8399 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8400 ar->dfs_detector->exit(ar->dfs_detector);
8402 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8403 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8405 SET_IEEE80211_DEV(ar->hw, NULL);