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/mac80211.h>
21 #include <linux/etherdevice.h>
22 #include <linux/acpi.h>
40 static struct ieee80211_rate ath10k_rates[] = {
42 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
44 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
45 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
46 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
48 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
49 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
50 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
52 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
53 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
54 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
56 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
57 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
58 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
59 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
60 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
61 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
62 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
63 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
66 static struct ieee80211_rate ath10k_rates_rev2[] = {
68 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
70 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
71 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
72 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
74 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
75 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
76 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
78 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
79 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
80 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
82 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
83 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
84 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
85 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
86 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
87 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
88 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
89 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
92 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
94 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
95 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
96 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
97 #define ath10k_g_rates (ath10k_rates + 0)
98 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
100 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
101 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
103 static bool ath10k_mac_bitrate_is_cck(int bitrate)
116 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
118 return DIV_ROUND_UP(bitrate, 5) |
119 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
122 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
123 u8 hw_rate, bool cck)
125 const struct ieee80211_rate *rate;
128 for (i = 0; i < sband->n_bitrates; i++) {
129 rate = &sband->bitrates[i];
131 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
134 if (rate->hw_value == hw_rate)
136 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
137 rate->hw_value_short == hw_rate)
144 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
149 for (i = 0; i < sband->n_bitrates; i++)
150 if (sband->bitrates[i].bitrate == bitrate)
156 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
158 switch ((mcs_map >> (2 * nss)) & 0x3) {
159 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
160 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
161 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
167 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
171 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
172 if (ht_mcs_mask[nss])
179 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
183 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
184 if (vht_mcs_mask[nss])
190 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
192 enum wmi_host_platform_type platform_type;
195 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
196 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
198 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
200 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
202 if (ret && ret != -EOPNOTSUPP) {
203 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
214 static int ath10k_send_key(struct ath10k_vif *arvif,
215 struct ieee80211_key_conf *key,
216 enum set_key_cmd cmd,
217 const u8 *macaddr, u32 flags)
219 struct ath10k *ar = arvif->ar;
220 struct wmi_vdev_install_key_arg arg = {
221 .vdev_id = arvif->vdev_id,
222 .key_idx = key->keyidx,
223 .key_len = key->keylen,
224 .key_data = key->key,
229 lockdep_assert_held(&arvif->ar->conf_mutex);
231 switch (key->cipher) {
232 case WLAN_CIPHER_SUITE_CCMP:
233 arg.key_cipher = WMI_CIPHER_AES_CCM;
234 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
236 case WLAN_CIPHER_SUITE_TKIP:
237 arg.key_cipher = WMI_CIPHER_TKIP;
238 arg.key_txmic_len = 8;
239 arg.key_rxmic_len = 8;
241 case WLAN_CIPHER_SUITE_WEP40:
242 case WLAN_CIPHER_SUITE_WEP104:
243 arg.key_cipher = WMI_CIPHER_WEP;
245 case WLAN_CIPHER_SUITE_AES_CMAC:
249 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
253 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
254 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
256 if (cmd == DISABLE_KEY) {
257 arg.key_cipher = WMI_CIPHER_NONE;
261 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
264 static int ath10k_install_key(struct ath10k_vif *arvif,
265 struct ieee80211_key_conf *key,
266 enum set_key_cmd cmd,
267 const u8 *macaddr, u32 flags)
269 struct ath10k *ar = arvif->ar;
271 unsigned long time_left;
273 lockdep_assert_held(&ar->conf_mutex);
275 reinit_completion(&ar->install_key_done);
277 if (arvif->nohwcrypt)
280 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
284 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
291 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
294 struct ath10k *ar = arvif->ar;
295 struct ath10k_peer *peer;
300 lockdep_assert_held(&ar->conf_mutex);
302 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
303 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
304 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
307 spin_lock_bh(&ar->data_lock);
308 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
309 spin_unlock_bh(&ar->data_lock);
314 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
315 if (arvif->wep_keys[i] == NULL)
318 switch (arvif->vif->type) {
319 case NL80211_IFTYPE_AP:
320 flags = WMI_KEY_PAIRWISE;
322 if (arvif->def_wep_key_idx == i)
323 flags |= WMI_KEY_TX_USAGE;
325 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
326 SET_KEY, addr, flags);
330 case NL80211_IFTYPE_ADHOC:
331 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
337 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
338 SET_KEY, addr, WMI_KEY_GROUP);
347 spin_lock_bh(&ar->data_lock);
348 peer->keys[i] = arvif->wep_keys[i];
349 spin_unlock_bh(&ar->data_lock);
352 /* In some cases (notably with static WEP IBSS with multiple keys)
353 * multicast Tx becomes broken. Both pairwise and groupwise keys are
354 * installed already. Using WMI_KEY_TX_USAGE in different combinations
355 * didn't seem help. Using def_keyid vdev parameter seems to be
356 * effective so use that.
358 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
360 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
363 if (arvif->def_wep_key_idx == -1)
366 ret = ath10k_wmi_vdev_set_param(arvif->ar,
368 arvif->ar->wmi.vdev_param->def_keyid,
369 arvif->def_wep_key_idx);
371 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
372 arvif->vdev_id, ret);
379 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
382 struct ath10k *ar = arvif->ar;
383 struct ath10k_peer *peer;
389 lockdep_assert_held(&ar->conf_mutex);
391 spin_lock_bh(&ar->data_lock);
392 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
393 spin_unlock_bh(&ar->data_lock);
398 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
399 if (peer->keys[i] == NULL)
402 /* key flags are not required to delete the key */
403 ret = ath10k_install_key(arvif, peer->keys[i],
404 DISABLE_KEY, addr, flags);
405 if (ret < 0 && first_errno == 0)
409 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
412 spin_lock_bh(&ar->data_lock);
413 peer->keys[i] = NULL;
414 spin_unlock_bh(&ar->data_lock);
420 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
423 struct ath10k_peer *peer;
426 lockdep_assert_held(&ar->data_lock);
428 /* We don't know which vdev this peer belongs to,
429 * since WMI doesn't give us that information.
431 * FIXME: multi-bss needs to be handled.
433 peer = ath10k_peer_find(ar, 0, addr);
437 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
438 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
445 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
446 struct ieee80211_key_conf *key)
448 struct ath10k *ar = arvif->ar;
449 struct ath10k_peer *peer;
456 lockdep_assert_held(&ar->conf_mutex);
459 /* since ath10k_install_key we can't hold data_lock all the
460 * time, so we try to remove the keys incrementally */
461 spin_lock_bh(&ar->data_lock);
463 list_for_each_entry(peer, &ar->peers, list) {
464 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
465 if (peer->keys[i] == key) {
466 ether_addr_copy(addr, peer->addr);
467 peer->keys[i] = NULL;
472 if (i < ARRAY_SIZE(peer->keys))
475 spin_unlock_bh(&ar->data_lock);
477 if (i == ARRAY_SIZE(peer->keys))
479 /* key flags are not required to delete the key */
480 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
481 if (ret < 0 && first_errno == 0)
485 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
492 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
493 struct ieee80211_key_conf *key)
495 struct ath10k *ar = arvif->ar;
496 struct ath10k_peer *peer;
499 lockdep_assert_held(&ar->conf_mutex);
501 list_for_each_entry(peer, &ar->peers, list) {
502 if (ether_addr_equal(peer->addr, arvif->vif->addr))
505 if (ether_addr_equal(peer->addr, arvif->bssid))
508 if (peer->keys[key->keyidx] == key)
511 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
512 arvif->vdev_id, key->keyidx);
514 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
516 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
517 arvif->vdev_id, peer->addr, ret);
525 /*********************/
526 /* General utilities */
527 /*********************/
529 static inline enum wmi_phy_mode
530 chan_to_phymode(const struct cfg80211_chan_def *chandef)
532 enum wmi_phy_mode phymode = MODE_UNKNOWN;
534 switch (chandef->chan->band) {
535 case NL80211_BAND_2GHZ:
536 switch (chandef->width) {
537 case NL80211_CHAN_WIDTH_20_NOHT:
538 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
543 case NL80211_CHAN_WIDTH_20:
544 phymode = MODE_11NG_HT20;
546 case NL80211_CHAN_WIDTH_40:
547 phymode = MODE_11NG_HT40;
549 case NL80211_CHAN_WIDTH_5:
550 case NL80211_CHAN_WIDTH_10:
551 case NL80211_CHAN_WIDTH_80:
552 case NL80211_CHAN_WIDTH_80P80:
553 case NL80211_CHAN_WIDTH_160:
554 phymode = MODE_UNKNOWN;
558 case NL80211_BAND_5GHZ:
559 switch (chandef->width) {
560 case NL80211_CHAN_WIDTH_20_NOHT:
563 case NL80211_CHAN_WIDTH_20:
564 phymode = MODE_11NA_HT20;
566 case NL80211_CHAN_WIDTH_40:
567 phymode = MODE_11NA_HT40;
569 case NL80211_CHAN_WIDTH_80:
570 phymode = MODE_11AC_VHT80;
572 case NL80211_CHAN_WIDTH_160:
573 phymode = MODE_11AC_VHT160;
575 case NL80211_CHAN_WIDTH_80P80:
576 phymode = MODE_11AC_VHT80_80;
578 case NL80211_CHAN_WIDTH_5:
579 case NL80211_CHAN_WIDTH_10:
580 phymode = MODE_UNKNOWN;
588 WARN_ON(phymode == MODE_UNKNOWN);
592 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
595 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
596 * 0 for no restriction
605 switch (mpdudensity) {
611 /* Our lower layer calculations limit our precision to
627 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
628 struct cfg80211_chan_def *def)
630 struct ieee80211_chanctx_conf *conf;
633 conf = rcu_dereference(vif->chanctx_conf);
645 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
646 struct ieee80211_chanctx_conf *conf,
654 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
658 ieee80211_iter_chan_contexts_atomic(ar->hw,
659 ath10k_mac_num_chanctxs_iter,
666 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
667 struct ieee80211_chanctx_conf *conf,
670 struct cfg80211_chan_def **def = data;
675 static int ath10k_peer_create(struct ath10k *ar,
676 struct ieee80211_vif *vif,
677 struct ieee80211_sta *sta,
680 enum wmi_peer_type peer_type)
682 struct ath10k_vif *arvif;
683 struct ath10k_peer *peer;
687 lockdep_assert_held(&ar->conf_mutex);
689 num_peers = ar->num_peers;
691 /* Each vdev consumes a peer entry as well */
692 list_for_each_entry(arvif, &ar->arvifs, list)
695 if (num_peers >= ar->max_num_peers)
698 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
700 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
705 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
707 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
712 spin_lock_bh(&ar->data_lock);
714 peer = ath10k_peer_find(ar, vdev_id, addr);
716 spin_unlock_bh(&ar->data_lock);
717 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
719 ath10k_wmi_peer_delete(ar, vdev_id, addr);
726 spin_unlock_bh(&ar->data_lock);
733 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
735 struct ath10k *ar = arvif->ar;
739 param = ar->wmi.pdev_param->sta_kickout_th;
740 ret = ath10k_wmi_pdev_set_param(ar, param,
741 ATH10K_KICKOUT_THRESHOLD);
743 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
744 arvif->vdev_id, ret);
748 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
749 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
750 ATH10K_KEEPALIVE_MIN_IDLE);
752 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
753 arvif->vdev_id, ret);
757 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
758 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
759 ATH10K_KEEPALIVE_MAX_IDLE);
761 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
762 arvif->vdev_id, ret);
766 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
767 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
768 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
770 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
771 arvif->vdev_id, ret);
778 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
780 struct ath10k *ar = arvif->ar;
783 vdev_param = ar->wmi.vdev_param->rts_threshold;
784 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
787 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
791 lockdep_assert_held(&ar->conf_mutex);
793 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
797 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
806 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
808 struct ath10k_peer *peer, *tmp;
812 lockdep_assert_held(&ar->conf_mutex);
814 spin_lock_bh(&ar->data_lock);
815 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
816 if (peer->vdev_id != vdev_id)
819 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
820 peer->addr, vdev_id);
822 for_each_set_bit(peer_id, peer->peer_ids,
823 ATH10K_MAX_NUM_PEER_IDS) {
824 ar->peer_map[peer_id] = NULL;
827 /* Double check that peer is properly un-referenced from
830 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
831 if (ar->peer_map[i] == peer) {
832 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
833 peer->addr, peer, i);
834 ar->peer_map[i] = NULL;
838 list_del(&peer->list);
842 spin_unlock_bh(&ar->data_lock);
845 static void ath10k_peer_cleanup_all(struct ath10k *ar)
847 struct ath10k_peer *peer, *tmp;
850 lockdep_assert_held(&ar->conf_mutex);
852 spin_lock_bh(&ar->data_lock);
853 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
854 list_del(&peer->list);
858 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
859 ar->peer_map[i] = NULL;
861 spin_unlock_bh(&ar->data_lock);
864 ar->num_stations = 0;
867 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
868 struct ieee80211_sta *sta,
869 enum wmi_tdls_peer_state state)
872 struct wmi_tdls_peer_update_cmd_arg arg = {};
873 struct wmi_tdls_peer_capab_arg cap = {};
874 struct wmi_channel_arg chan_arg = {};
876 lockdep_assert_held(&ar->conf_mutex);
878 arg.vdev_id = vdev_id;
879 arg.peer_state = state;
880 ether_addr_copy(arg.addr, sta->addr);
882 cap.peer_max_sp = sta->max_sp;
883 cap.peer_uapsd_queues = sta->uapsd_queues;
885 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
886 !sta->tdls_initiator)
887 cap.is_peer_responder = 1;
889 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
891 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
892 arg.addr, vdev_id, ret);
899 /************************/
900 /* Interface management */
901 /************************/
903 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
905 struct ath10k *ar = arvif->ar;
907 lockdep_assert_held(&ar->data_lock);
912 if (!arvif->beacon_buf)
913 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
914 arvif->beacon->len, DMA_TO_DEVICE);
916 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
917 arvif->beacon_state != ATH10K_BEACON_SENT))
920 dev_kfree_skb_any(arvif->beacon);
922 arvif->beacon = NULL;
923 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
926 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
928 struct ath10k *ar = arvif->ar;
930 lockdep_assert_held(&ar->data_lock);
932 ath10k_mac_vif_beacon_free(arvif);
934 if (arvif->beacon_buf) {
935 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
936 arvif->beacon_buf, arvif->beacon_paddr);
937 arvif->beacon_buf = NULL;
941 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
943 unsigned long time_left;
945 lockdep_assert_held(&ar->conf_mutex);
947 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
950 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
951 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
958 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
960 struct cfg80211_chan_def *chandef = NULL;
961 struct ieee80211_channel *channel = NULL;
962 struct wmi_vdev_start_request_arg arg = {};
965 lockdep_assert_held(&ar->conf_mutex);
967 ieee80211_iter_chan_contexts_atomic(ar->hw,
968 ath10k_mac_get_any_chandef_iter,
970 if (WARN_ON_ONCE(!chandef))
973 channel = chandef->chan;
975 arg.vdev_id = vdev_id;
976 arg.channel.freq = channel->center_freq;
977 arg.channel.band_center_freq1 = chandef->center_freq1;
978 arg.channel.band_center_freq2 = chandef->center_freq2;
980 /* TODO setup this dynamically, what in case we
981 don't have any vifs? */
982 arg.channel.mode = chan_to_phymode(chandef);
983 arg.channel.chan_radar =
984 !!(channel->flags & IEEE80211_CHAN_RADAR);
986 arg.channel.min_power = 0;
987 arg.channel.max_power = channel->max_power * 2;
988 arg.channel.max_reg_power = channel->max_reg_power * 2;
989 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
991 reinit_completion(&ar->vdev_setup_done);
993 ret = ath10k_wmi_vdev_start(ar, &arg);
995 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1000 ret = ath10k_vdev_setup_sync(ar);
1002 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1007 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1009 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1014 ar->monitor_vdev_id = vdev_id;
1016 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1017 ar->monitor_vdev_id);
1021 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1023 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1024 ar->monitor_vdev_id, ret);
1029 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1033 lockdep_assert_held(&ar->conf_mutex);
1035 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1037 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1038 ar->monitor_vdev_id, ret);
1040 reinit_completion(&ar->vdev_setup_done);
1042 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1044 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1045 ar->monitor_vdev_id, ret);
1047 ret = ath10k_vdev_setup_sync(ar);
1049 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1050 ar->monitor_vdev_id, ret);
1052 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1053 ar->monitor_vdev_id);
1057 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1061 lockdep_assert_held(&ar->conf_mutex);
1063 if (ar->free_vdev_map == 0) {
1064 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1068 bit = __ffs64(ar->free_vdev_map);
1070 ar->monitor_vdev_id = bit;
1072 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1073 WMI_VDEV_TYPE_MONITOR,
1076 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1077 ar->monitor_vdev_id, ret);
1081 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1082 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1083 ar->monitor_vdev_id);
1088 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1092 lockdep_assert_held(&ar->conf_mutex);
1094 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1096 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1097 ar->monitor_vdev_id, ret);
1101 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1103 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1104 ar->monitor_vdev_id);
1108 static int ath10k_monitor_start(struct ath10k *ar)
1112 lockdep_assert_held(&ar->conf_mutex);
1114 ret = ath10k_monitor_vdev_create(ar);
1116 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1120 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1122 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1123 ath10k_monitor_vdev_delete(ar);
1127 ar->monitor_started = true;
1128 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1133 static int ath10k_monitor_stop(struct ath10k *ar)
1137 lockdep_assert_held(&ar->conf_mutex);
1139 ret = ath10k_monitor_vdev_stop(ar);
1141 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1145 ret = ath10k_monitor_vdev_delete(ar);
1147 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1151 ar->monitor_started = false;
1152 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1157 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1161 /* At least one chanctx is required to derive a channel to start
1164 num_ctx = ath10k_mac_num_chanctxs(ar);
1168 /* If there's already an existing special monitor interface then don't
1169 * bother creating another monitor vdev.
1171 if (ar->monitor_arvif)
1174 return ar->monitor ||
1175 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1176 ar->running_fw->fw_file.fw_features) &&
1177 (ar->filter_flags & FIF_OTHER_BSS)) ||
1178 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1181 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1185 num_ctx = ath10k_mac_num_chanctxs(ar);
1187 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1188 * shouldn't allow this but make sure to prevent handling the following
1189 * case anyway since multi-channel DFS hasn't been tested at all.
1191 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1197 static int ath10k_monitor_recalc(struct ath10k *ar)
1203 lockdep_assert_held(&ar->conf_mutex);
1205 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1206 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1208 ath10k_dbg(ar, ATH10K_DBG_MAC,
1209 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1210 ar->monitor_started, needed, allowed);
1212 if (WARN_ON(needed && !allowed)) {
1213 if (ar->monitor_started) {
1214 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1216 ret = ath10k_monitor_stop(ar);
1218 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1226 if (needed == ar->monitor_started)
1230 return ath10k_monitor_start(ar);
1232 return ath10k_monitor_stop(ar);
1235 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1237 struct ath10k *ar = arvif->ar;
1239 lockdep_assert_held(&ar->conf_mutex);
1241 if (!arvif->is_started) {
1242 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1249 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1251 struct ath10k *ar = arvif->ar;
1254 lockdep_assert_held(&ar->conf_mutex);
1256 vdev_param = ar->wmi.vdev_param->protection_mode;
1258 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1259 arvif->vdev_id, arvif->use_cts_prot);
1261 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1262 arvif->use_cts_prot ? 1 : 0);
1265 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1267 struct ath10k *ar = arvif->ar;
1268 u32 vdev_param, rts_cts = 0;
1270 lockdep_assert_held(&ar->conf_mutex);
1272 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1274 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1276 if (arvif->num_legacy_stations > 0)
1277 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1278 WMI_RTSCTS_PROFILE);
1280 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1281 WMI_RTSCTS_PROFILE);
1283 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1284 arvif->vdev_id, rts_cts);
1286 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1290 static int ath10k_start_cac(struct ath10k *ar)
1294 lockdep_assert_held(&ar->conf_mutex);
1296 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1298 ret = ath10k_monitor_recalc(ar);
1300 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1301 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1305 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1306 ar->monitor_vdev_id);
1311 static int ath10k_stop_cac(struct ath10k *ar)
1313 lockdep_assert_held(&ar->conf_mutex);
1315 /* CAC is not running - do nothing */
1316 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1319 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1320 ath10k_monitor_stop(ar);
1322 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1327 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1328 struct ieee80211_chanctx_conf *conf,
1333 if (!*ret && conf->radar_enabled)
1337 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1339 bool has_radar = false;
1341 ieee80211_iter_chan_contexts_atomic(ar->hw,
1342 ath10k_mac_has_radar_iter,
1348 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1352 lockdep_assert_held(&ar->conf_mutex);
1354 ath10k_stop_cac(ar);
1356 if (!ath10k_mac_has_radar_enabled(ar))
1359 if (ar->num_started_vdevs > 0)
1362 ret = ath10k_start_cac(ar);
1365 * Not possible to start CAC on current channel so starting
1366 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1367 * by indicating that radar was detected.
1369 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1370 ieee80211_radar_detected(ar->hw);
1374 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1376 struct ath10k *ar = arvif->ar;
1379 lockdep_assert_held(&ar->conf_mutex);
1381 reinit_completion(&ar->vdev_setup_done);
1383 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1385 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1386 arvif->vdev_id, ret);
1390 ret = ath10k_vdev_setup_sync(ar);
1392 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1393 arvif->vdev_id, ret);
1397 WARN_ON(ar->num_started_vdevs == 0);
1399 if (ar->num_started_vdevs != 0) {
1400 ar->num_started_vdevs--;
1401 ath10k_recalc_radar_detection(ar);
1407 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1408 const struct cfg80211_chan_def *chandef,
1411 struct ath10k *ar = arvif->ar;
1412 struct wmi_vdev_start_request_arg arg = {};
1415 lockdep_assert_held(&ar->conf_mutex);
1417 reinit_completion(&ar->vdev_setup_done);
1419 arg.vdev_id = arvif->vdev_id;
1420 arg.dtim_period = arvif->dtim_period;
1421 arg.bcn_intval = arvif->beacon_interval;
1423 arg.channel.freq = chandef->chan->center_freq;
1424 arg.channel.band_center_freq1 = chandef->center_freq1;
1425 arg.channel.band_center_freq2 = chandef->center_freq2;
1426 arg.channel.mode = chan_to_phymode(chandef);
1428 arg.channel.min_power = 0;
1429 arg.channel.max_power = chandef->chan->max_power * 2;
1430 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1431 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1433 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1434 arg.ssid = arvif->u.ap.ssid;
1435 arg.ssid_len = arvif->u.ap.ssid_len;
1436 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1438 /* For now allow DFS for AP mode */
1439 arg.channel.chan_radar =
1440 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1441 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1442 arg.ssid = arvif->vif->bss_conf.ssid;
1443 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1446 ath10k_dbg(ar, ATH10K_DBG_MAC,
1447 "mac vdev %d start center_freq %d phymode %s\n",
1448 arg.vdev_id, arg.channel.freq,
1449 ath10k_wmi_phymode_str(arg.channel.mode));
1452 ret = ath10k_wmi_vdev_restart(ar, &arg);
1454 ret = ath10k_wmi_vdev_start(ar, &arg);
1457 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1462 ret = ath10k_vdev_setup_sync(ar);
1465 "failed to synchronize setup for vdev %i restart %d: %d\n",
1466 arg.vdev_id, restart, ret);
1470 ar->num_started_vdevs++;
1471 ath10k_recalc_radar_detection(ar);
1476 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1477 const struct cfg80211_chan_def *def)
1479 return ath10k_vdev_start_restart(arvif, def, false);
1482 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1483 const struct cfg80211_chan_def *def)
1485 return ath10k_vdev_start_restart(arvif, def, true);
1488 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1489 struct sk_buff *bcn)
1491 struct ath10k *ar = arvif->ar;
1492 struct ieee80211_mgmt *mgmt;
1496 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1499 mgmt = (void *)bcn->data;
1500 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1501 mgmt->u.beacon.variable,
1502 bcn->len - (mgmt->u.beacon.variable -
1507 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1509 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1510 arvif->vdev_id, ret);
1517 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1518 u8 oui_type, size_t ie_offset)
1525 if (WARN_ON(skb->len < ie_offset))
1528 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1529 skb->data + ie_offset,
1530 skb->len - ie_offset);
1535 end = skb->data + skb->len;
1538 if (WARN_ON(next > end))
1541 memmove(ie, next, end - next);
1542 skb_trim(skb, skb->len - len);
1547 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1549 struct ath10k *ar = arvif->ar;
1550 struct ieee80211_hw *hw = ar->hw;
1551 struct ieee80211_vif *vif = arvif->vif;
1552 struct ieee80211_mutable_offsets offs = {};
1553 struct sk_buff *bcn;
1556 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1559 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1560 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1563 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1565 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1569 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1571 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1576 /* P2P IE is inserted by firmware automatically (as configured above)
1577 * so remove it from the base beacon template to avoid duplicate P2P
1578 * IEs in beacon frames.
1580 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1581 offsetof(struct ieee80211_mgmt,
1582 u.beacon.variable));
1584 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1589 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1597 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1599 struct ath10k *ar = arvif->ar;
1600 struct ieee80211_hw *hw = ar->hw;
1601 struct ieee80211_vif *vif = arvif->vif;
1602 struct sk_buff *prb;
1605 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1608 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1611 prb = ieee80211_proberesp_get(hw, vif);
1613 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1617 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1621 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1629 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1631 struct ath10k *ar = arvif->ar;
1632 struct cfg80211_chan_def def;
1635 /* When originally vdev is started during assign_vif_chanctx() some
1636 * information is missing, notably SSID. Firmware revisions with beacon
1637 * offloading require the SSID to be provided during vdev (re)start to
1638 * handle hidden SSID properly.
1640 * Vdev restart must be done after vdev has been both started and
1641 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1642 * deliver vdev restart response event causing timeouts during vdev
1643 * syncing in ath10k.
1645 * Note: The vdev down/up and template reinstallation could be skipped
1646 * since only wmi-tlv firmware are known to have beacon offload and
1647 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1648 * response delivery. It's probably more robust to keep it as is.
1650 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1653 if (WARN_ON(!arvif->is_started))
1656 if (WARN_ON(!arvif->is_up))
1659 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1662 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1664 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1665 arvif->vdev_id, ret);
1669 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1670 * firmware will crash upon vdev up.
1673 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1675 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1679 ret = ath10k_mac_setup_prb_tmpl(arvif);
1681 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1685 ret = ath10k_vdev_restart(arvif, &def);
1687 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1688 arvif->vdev_id, ret);
1692 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1695 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1696 arvif->vdev_id, ret);
1703 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1704 struct ieee80211_bss_conf *info)
1706 struct ath10k *ar = arvif->ar;
1709 lockdep_assert_held(&arvif->ar->conf_mutex);
1711 if (!info->enable_beacon) {
1712 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1714 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1715 arvif->vdev_id, ret);
1717 arvif->is_up = false;
1719 spin_lock_bh(&arvif->ar->data_lock);
1720 ath10k_mac_vif_beacon_free(arvif);
1721 spin_unlock_bh(&arvif->ar->data_lock);
1726 arvif->tx_seq_no = 0x1000;
1729 ether_addr_copy(arvif->bssid, info->bssid);
1731 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1734 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1735 arvif->vdev_id, ret);
1739 arvif->is_up = true;
1741 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1743 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1744 arvif->vdev_id, ret);
1748 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1751 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1752 struct ieee80211_bss_conf *info,
1753 const u8 self_peer[ETH_ALEN])
1755 struct ath10k *ar = arvif->ar;
1759 lockdep_assert_held(&arvif->ar->conf_mutex);
1761 if (!info->ibss_joined) {
1762 if (is_zero_ether_addr(arvif->bssid))
1765 eth_zero_addr(arvif->bssid);
1770 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1771 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1772 ATH10K_DEFAULT_ATIM);
1774 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1775 arvif->vdev_id, ret);
1778 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1780 struct ath10k *ar = arvif->ar;
1785 lockdep_assert_held(&arvif->ar->conf_mutex);
1787 if (arvif->u.sta.uapsd)
1788 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1790 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1792 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1793 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1795 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1796 value, arvif->vdev_id, ret);
1803 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1805 struct ath10k *ar = arvif->ar;
1810 lockdep_assert_held(&arvif->ar->conf_mutex);
1812 if (arvif->u.sta.uapsd)
1813 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1815 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1817 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1818 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1821 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1822 value, arvif->vdev_id, ret);
1829 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1831 struct ath10k_vif *arvif;
1834 lockdep_assert_held(&ar->conf_mutex);
1836 list_for_each_entry(arvif, &ar->arvifs, list)
1837 if (arvif->is_started)
1843 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1845 struct ath10k *ar = arvif->ar;
1846 struct ieee80211_vif *vif = arvif->vif;
1847 struct ieee80211_conf *conf = &ar->hw->conf;
1848 enum wmi_sta_powersave_param param;
1849 enum wmi_sta_ps_mode psmode;
1854 lockdep_assert_held(&arvif->ar->conf_mutex);
1856 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1859 enable_ps = arvif->ps;
1861 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1862 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1863 ar->running_fw->fw_file.fw_features)) {
1864 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1869 if (!arvif->is_started) {
1870 /* mac80211 can update vif powersave state while disconnected.
1871 * Firmware doesn't behave nicely and consumes more power than
1872 * necessary if PS is disabled on a non-started vdev. Hence
1873 * force-enable PS for non-running vdevs.
1875 psmode = WMI_STA_PS_MODE_ENABLED;
1876 } else if (enable_ps) {
1877 psmode = WMI_STA_PS_MODE_ENABLED;
1878 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1880 ps_timeout = conf->dynamic_ps_timeout;
1881 if (ps_timeout == 0) {
1882 /* Firmware doesn't like 0 */
1883 ps_timeout = ieee80211_tu_to_usec(
1884 vif->bss_conf.beacon_int) / 1000;
1887 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1890 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1891 arvif->vdev_id, ret);
1895 psmode = WMI_STA_PS_MODE_DISABLED;
1898 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1899 arvif->vdev_id, psmode ? "enable" : "disable");
1901 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1903 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1904 psmode, arvif->vdev_id, ret);
1911 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1913 struct ath10k *ar = arvif->ar;
1914 struct wmi_sta_keepalive_arg arg = {};
1917 lockdep_assert_held(&arvif->ar->conf_mutex);
1919 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1922 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1925 /* Some firmware revisions have a bug and ignore the `enabled` field.
1926 * Instead use the interval to disable the keepalive.
1928 arg.vdev_id = arvif->vdev_id;
1930 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1931 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1933 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1935 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1936 arvif->vdev_id, ret);
1943 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1945 struct ath10k *ar = arvif->ar;
1946 struct ieee80211_vif *vif = arvif->vif;
1949 lockdep_assert_held(&arvif->ar->conf_mutex);
1951 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1954 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1957 if (!vif->csa_active)
1963 if (!ieee80211_csa_is_complete(vif)) {
1964 ieee80211_csa_update_counter(vif);
1966 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1968 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1971 ret = ath10k_mac_setup_prb_tmpl(arvif);
1973 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1976 ieee80211_csa_finish(vif);
1980 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1982 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1984 struct ath10k *ar = arvif->ar;
1986 mutex_lock(&ar->conf_mutex);
1987 ath10k_mac_vif_ap_csa_count_down(arvif);
1988 mutex_unlock(&ar->conf_mutex);
1991 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1992 struct ieee80211_vif *vif)
1994 struct sk_buff *skb = data;
1995 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1996 struct ath10k_vif *arvif = (void *)vif->drv_priv;
1998 if (vif->type != NL80211_IFTYPE_STATION)
2001 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2004 cancel_delayed_work(&arvif->connection_loss_work);
2007 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2009 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2010 IEEE80211_IFACE_ITER_NORMAL,
2011 ath10k_mac_handle_beacon_iter,
2015 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2016 struct ieee80211_vif *vif)
2018 u32 *vdev_id = data;
2019 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2020 struct ath10k *ar = arvif->ar;
2021 struct ieee80211_hw *hw = ar->hw;
2023 if (arvif->vdev_id != *vdev_id)
2029 ieee80211_beacon_loss(vif);
2031 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2032 * (done by mac80211) succeeds but beacons do not resume then it
2033 * doesn't make sense to continue operation. Queue connection loss work
2034 * which can be cancelled when beacon is received.
2036 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2037 ATH10K_CONNECTION_LOSS_HZ);
2040 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2042 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2043 IEEE80211_IFACE_ITER_NORMAL,
2044 ath10k_mac_handle_beacon_miss_iter,
2048 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2050 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2051 connection_loss_work.work);
2052 struct ieee80211_vif *vif = arvif->vif;
2057 ieee80211_connection_loss(vif);
2060 /**********************/
2061 /* Station management */
2062 /**********************/
2064 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2065 struct ieee80211_vif *vif)
2067 /* Some firmware revisions have unstable STA powersave when listen
2068 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2069 * generate NullFunc frames properly even if buffered frames have been
2070 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2071 * buffered frames. Often pinging the device from AP would simply fail.
2073 * As a workaround set it to 1.
2075 if (vif->type == NL80211_IFTYPE_STATION)
2078 return ar->hw->conf.listen_interval;
2081 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2082 struct ieee80211_vif *vif,
2083 struct ieee80211_sta *sta,
2084 struct wmi_peer_assoc_complete_arg *arg)
2086 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2089 lockdep_assert_held(&ar->conf_mutex);
2091 if (vif->type == NL80211_IFTYPE_STATION)
2092 aid = vif->bss_conf.aid;
2096 ether_addr_copy(arg->addr, sta->addr);
2097 arg->vdev_id = arvif->vdev_id;
2098 arg->peer_aid = aid;
2099 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2100 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2101 arg->peer_num_spatial_streams = 1;
2102 arg->peer_caps = vif->bss_conf.assoc_capability;
2105 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2106 struct ieee80211_vif *vif,
2107 struct ieee80211_sta *sta,
2108 struct wmi_peer_assoc_complete_arg *arg)
2110 struct ieee80211_bss_conf *info = &vif->bss_conf;
2111 struct cfg80211_chan_def def;
2112 struct cfg80211_bss *bss;
2113 const u8 *rsnie = NULL;
2114 const u8 *wpaie = NULL;
2116 lockdep_assert_held(&ar->conf_mutex);
2118 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2121 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2122 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2124 const struct cfg80211_bss_ies *ies;
2127 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2129 ies = rcu_dereference(bss->ies);
2131 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2132 WLAN_OUI_TYPE_MICROSOFT_WPA,
2136 cfg80211_put_bss(ar->hw->wiphy, bss);
2139 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2140 if (rsnie || wpaie) {
2141 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2142 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2146 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2147 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2151 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2152 ar->running_fw->fw_file.fw_features)) {
2153 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2157 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2158 struct ieee80211_vif *vif,
2159 struct ieee80211_sta *sta,
2160 struct wmi_peer_assoc_complete_arg *arg)
2162 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2163 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2164 struct cfg80211_chan_def def;
2165 const struct ieee80211_supported_band *sband;
2166 const struct ieee80211_rate *rates;
2167 enum nl80211_band band;
2172 lockdep_assert_held(&ar->conf_mutex);
2174 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2177 band = def.chan->band;
2178 sband = ar->hw->wiphy->bands[band];
2179 ratemask = sta->supp_rates[band];
2180 ratemask &= arvif->bitrate_mask.control[band].legacy;
2181 rates = sband->bitrates;
2183 rateset->num_rates = 0;
2185 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2186 if (!(ratemask & 1))
2189 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2190 rateset->rates[rateset->num_rates] = rate;
2191 rateset->num_rates++;
2196 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2200 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2201 if (ht_mcs_mask[nss])
2208 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2212 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2213 if (vht_mcs_mask[nss])
2219 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2220 struct ieee80211_vif *vif,
2221 struct ieee80211_sta *sta,
2222 struct wmi_peer_assoc_complete_arg *arg)
2224 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2225 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2226 struct cfg80211_chan_def def;
2227 enum nl80211_band band;
2228 const u8 *ht_mcs_mask;
2229 const u16 *vht_mcs_mask;
2234 lockdep_assert_held(&ar->conf_mutex);
2236 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2239 if (!ht_cap->ht_supported)
2242 band = def.chan->band;
2243 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2244 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2246 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2247 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2250 arg->peer_flags |= ar->wmi.peer_flags->ht;
2251 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2252 ht_cap->ampdu_factor)) - 1;
2254 arg->peer_mpdu_density =
2255 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2257 arg->peer_ht_caps = ht_cap->cap;
2258 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2260 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2261 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2263 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2264 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2265 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2268 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2269 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2270 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2272 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2273 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2276 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2277 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2278 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2281 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2282 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2283 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2284 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2285 arg->peer_rate_caps |= stbc;
2286 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2289 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2290 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2291 else if (ht_cap->mcs.rx_mask[1])
2292 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2294 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2295 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2296 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2297 max_nss = (i / 8) + 1;
2298 arg->peer_ht_rates.rates[n++] = i;
2302 * This is a workaround for HT-enabled STAs which break the spec
2303 * and have no HT capabilities RX mask (no HT RX MCS map).
2305 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2306 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2308 * Firmware asserts if such situation occurs.
2311 arg->peer_ht_rates.num_rates = 8;
2312 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2313 arg->peer_ht_rates.rates[i] = i;
2315 arg->peer_ht_rates.num_rates = n;
2316 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2321 arg->peer_ht_rates.num_rates,
2322 arg->peer_num_spatial_streams);
2325 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2326 struct ath10k_vif *arvif,
2327 struct ieee80211_sta *sta)
2333 lockdep_assert_held(&ar->conf_mutex);
2335 if (sta->wme && sta->uapsd_queues) {
2336 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2337 sta->uapsd_queues, sta->max_sp);
2339 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2340 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2341 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2342 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2343 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2344 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2345 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2346 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2347 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2348 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2349 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2350 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2352 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2353 max_sp = sta->max_sp;
2355 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2357 WMI_AP_PS_PEER_PARAM_UAPSD,
2360 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2361 arvif->vdev_id, ret);
2365 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2367 WMI_AP_PS_PEER_PARAM_MAX_SP,
2370 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2371 arvif->vdev_id, ret);
2375 /* TODO setup this based on STA listen interval and
2376 beacon interval. Currently we don't know
2377 sta->listen_interval - mac80211 patch required.
2378 Currently use 10 seconds */
2379 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2380 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2383 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2384 arvif->vdev_id, ret);
2393 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2394 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2401 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2402 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2406 idx_limit = fls(mcs_map) - 1;
2410 switch (idx_limit) {
2411 case 0: /* fall through */
2412 case 1: /* fall through */
2413 case 2: /* fall through */
2414 case 3: /* fall through */
2415 case 4: /* fall through */
2416 case 5: /* fall through */
2417 case 6: /* fall through */
2419 /* see ath10k_mac_can_set_bitrate_mask() */
2423 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2426 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2429 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2432 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2436 tx_mcs_set &= ~(0x3 << (nss * 2));
2437 tx_mcs_set |= mcs << (nss * 2);
2443 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2444 struct ieee80211_vif *vif,
2445 struct ieee80211_sta *sta,
2446 struct wmi_peer_assoc_complete_arg *arg)
2448 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2449 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2450 struct cfg80211_chan_def def;
2451 enum nl80211_band band;
2452 const u16 *vht_mcs_mask;
2455 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2458 if (!vht_cap->vht_supported)
2461 band = def.chan->band;
2462 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2464 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2467 arg->peer_flags |= ar->wmi.peer_flags->vht;
2469 if (def.chan->band == NL80211_BAND_2GHZ)
2470 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2472 arg->peer_vht_caps = vht_cap->cap;
2474 ampdu_factor = (vht_cap->cap &
2475 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2476 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2478 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2479 * zero in VHT IE. Using it would result in degraded throughput.
2480 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2481 * it if VHT max_mpdu is smaller. */
2482 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2483 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2484 ampdu_factor)) - 1);
2486 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2487 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2489 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2490 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2492 arg->peer_vht_rates.rx_max_rate =
2493 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2494 arg->peer_vht_rates.rx_mcs_set =
2495 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2496 arg->peer_vht_rates.tx_max_rate =
2497 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2498 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2499 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2501 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2502 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2505 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2506 struct ieee80211_vif *vif,
2507 struct ieee80211_sta *sta,
2508 struct wmi_peer_assoc_complete_arg *arg)
2510 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2512 switch (arvif->vdev_type) {
2513 case WMI_VDEV_TYPE_AP:
2515 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2517 if (sta->wme && sta->uapsd_queues) {
2518 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2519 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2522 case WMI_VDEV_TYPE_STA:
2523 if (vif->bss_conf.qos)
2524 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2526 case WMI_VDEV_TYPE_IBSS:
2528 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2534 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2535 sta->addr, !!(arg->peer_flags &
2536 arvif->ar->wmi.peer_flags->qos));
2539 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2541 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2542 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2545 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2546 struct ieee80211_sta *sta)
2548 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2549 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2550 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2551 return MODE_11AC_VHT160;
2552 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2553 return MODE_11AC_VHT80_80;
2555 /* not sure if this is a valid case? */
2556 return MODE_11AC_VHT160;
2560 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2561 return MODE_11AC_VHT80;
2563 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2564 return MODE_11AC_VHT40;
2566 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2567 return MODE_11AC_VHT20;
2569 return MODE_UNKNOWN;
2572 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2573 struct ieee80211_vif *vif,
2574 struct ieee80211_sta *sta,
2575 struct wmi_peer_assoc_complete_arg *arg)
2577 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2578 struct cfg80211_chan_def def;
2579 enum nl80211_band band;
2580 const u8 *ht_mcs_mask;
2581 const u16 *vht_mcs_mask;
2582 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2584 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2587 band = def.chan->band;
2588 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2589 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2592 case NL80211_BAND_2GHZ:
2593 if (sta->vht_cap.vht_supported &&
2594 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2595 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2596 phymode = MODE_11AC_VHT40;
2598 phymode = MODE_11AC_VHT20;
2599 } else if (sta->ht_cap.ht_supported &&
2600 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2601 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2602 phymode = MODE_11NG_HT40;
2604 phymode = MODE_11NG_HT20;
2605 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2612 case NL80211_BAND_5GHZ:
2616 if (sta->vht_cap.vht_supported &&
2617 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2618 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2619 } else if (sta->ht_cap.ht_supported &&
2620 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2621 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2622 phymode = MODE_11NA_HT40;
2624 phymode = MODE_11NA_HT20;
2634 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2635 sta->addr, ath10k_wmi_phymode_str(phymode));
2637 arg->peer_phymode = phymode;
2638 WARN_ON(phymode == MODE_UNKNOWN);
2641 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2642 struct ieee80211_vif *vif,
2643 struct ieee80211_sta *sta,
2644 struct wmi_peer_assoc_complete_arg *arg)
2646 lockdep_assert_held(&ar->conf_mutex);
2648 memset(arg, 0, sizeof(*arg));
2650 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2651 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2652 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2653 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2654 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2655 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2656 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2661 static const u32 ath10k_smps_map[] = {
2662 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2663 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2664 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2665 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2668 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2670 const struct ieee80211_sta_ht_cap *ht_cap)
2674 if (!ht_cap->ht_supported)
2677 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2678 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2680 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2683 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2684 WMI_PEER_SMPS_STATE,
2685 ath10k_smps_map[smps]);
2688 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2689 struct ieee80211_vif *vif,
2690 struct ieee80211_sta_vht_cap vht_cap)
2692 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2697 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2700 if (!(ar->vht_cap_info &
2701 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2702 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2703 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2704 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2707 param = ar->wmi.vdev_param->txbf;
2710 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2713 /* The following logic is correct. If a remote STA advertises support
2714 * for being a beamformer then we should enable us being a beamformee.
2717 if (ar->vht_cap_info &
2718 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2719 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2720 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2721 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2723 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2724 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2727 if (ar->vht_cap_info &
2728 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2729 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2730 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2731 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2733 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2734 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2737 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2738 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2740 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2741 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2743 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2745 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2753 /* can be called only in mac80211 callbacks due to `key_count` usage */
2754 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2755 struct ieee80211_vif *vif,
2756 struct ieee80211_bss_conf *bss_conf)
2758 struct ath10k *ar = hw->priv;
2759 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2760 struct ieee80211_sta_ht_cap ht_cap;
2761 struct ieee80211_sta_vht_cap vht_cap;
2762 struct wmi_peer_assoc_complete_arg peer_arg;
2763 struct ieee80211_sta *ap_sta;
2766 lockdep_assert_held(&ar->conf_mutex);
2768 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2769 arvif->vdev_id, arvif->bssid, arvif->aid);
2773 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2775 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2776 bss_conf->bssid, arvif->vdev_id);
2781 /* ap_sta must be accessed only within rcu section which must be left
2782 * before calling ath10k_setup_peer_smps() which might sleep. */
2783 ht_cap = ap_sta->ht_cap;
2784 vht_cap = ap_sta->vht_cap;
2786 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2788 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2789 bss_conf->bssid, arvif->vdev_id, ret);
2796 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2798 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2799 bss_conf->bssid, arvif->vdev_id, ret);
2803 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2805 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2806 arvif->vdev_id, ret);
2810 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2812 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2813 arvif->vdev_id, bss_conf->bssid, ret);
2817 ath10k_dbg(ar, ATH10K_DBG_MAC,
2818 "mac vdev %d up (associated) bssid %pM aid %d\n",
2819 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2821 WARN_ON(arvif->is_up);
2823 arvif->aid = bss_conf->aid;
2824 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2826 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2828 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2829 arvif->vdev_id, ret);
2833 arvif->is_up = true;
2835 /* Workaround: Some firmware revisions (tested with qca6174
2836 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2837 * poked with peer param command.
2839 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2840 WMI_PEER_DUMMY_VAR, 1);
2842 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2843 arvif->bssid, arvif->vdev_id, ret);
2848 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2849 struct ieee80211_vif *vif)
2851 struct ath10k *ar = hw->priv;
2852 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2853 struct ieee80211_sta_vht_cap vht_cap = {};
2856 lockdep_assert_held(&ar->conf_mutex);
2858 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2859 arvif->vdev_id, arvif->bssid);
2861 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2863 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2864 arvif->vdev_id, ret);
2866 arvif->def_wep_key_idx = -1;
2868 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2870 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2871 arvif->vdev_id, ret);
2875 arvif->is_up = false;
2877 cancel_delayed_work_sync(&arvif->connection_loss_work);
2880 static int ath10k_station_assoc(struct ath10k *ar,
2881 struct ieee80211_vif *vif,
2882 struct ieee80211_sta *sta,
2885 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2886 struct wmi_peer_assoc_complete_arg peer_arg;
2889 lockdep_assert_held(&ar->conf_mutex);
2891 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2893 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2894 sta->addr, arvif->vdev_id, ret);
2898 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2900 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2901 sta->addr, arvif->vdev_id, ret);
2905 /* Re-assoc is run only to update supported rates for given station. It
2906 * doesn't make much sense to reconfigure the peer completely.
2909 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2912 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2913 arvif->vdev_id, ret);
2917 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2919 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2920 sta->addr, arvif->vdev_id, ret);
2925 arvif->num_legacy_stations++;
2926 ret = ath10k_recalc_rtscts_prot(arvif);
2928 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2929 arvif->vdev_id, ret);
2934 /* Plumb cached keys only for static WEP */
2935 if (arvif->def_wep_key_idx != -1) {
2936 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2938 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2939 arvif->vdev_id, ret);
2948 static int ath10k_station_disassoc(struct ath10k *ar,
2949 struct ieee80211_vif *vif,
2950 struct ieee80211_sta *sta)
2952 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2955 lockdep_assert_held(&ar->conf_mutex);
2958 arvif->num_legacy_stations--;
2959 ret = ath10k_recalc_rtscts_prot(arvif);
2961 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2962 arvif->vdev_id, ret);
2967 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2969 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2970 arvif->vdev_id, ret);
2981 static int ath10k_update_channel_list(struct ath10k *ar)
2983 struct ieee80211_hw *hw = ar->hw;
2984 struct ieee80211_supported_band **bands;
2985 enum nl80211_band band;
2986 struct ieee80211_channel *channel;
2987 struct wmi_scan_chan_list_arg arg = {0};
2988 struct wmi_channel_arg *ch;
2994 lockdep_assert_held(&ar->conf_mutex);
2996 bands = hw->wiphy->bands;
2997 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3001 for (i = 0; i < bands[band]->n_channels; i++) {
3002 if (bands[band]->channels[i].flags &
3003 IEEE80211_CHAN_DISABLED)
3010 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3011 arg.channels = kzalloc(len, GFP_KERNEL);
3016 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3020 for (i = 0; i < bands[band]->n_channels; i++) {
3021 channel = &bands[band]->channels[i];
3023 if (channel->flags & IEEE80211_CHAN_DISABLED)
3026 ch->allow_ht = true;
3028 /* FIXME: when should we really allow VHT? */
3029 ch->allow_vht = true;
3032 !(channel->flags & IEEE80211_CHAN_NO_IR);
3035 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3038 !!(channel->flags & IEEE80211_CHAN_RADAR);
3040 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3041 ch->passive = passive;
3043 ch->freq = channel->center_freq;
3044 ch->band_center_freq1 = channel->center_freq;
3046 ch->max_power = channel->max_power * 2;
3047 ch->max_reg_power = channel->max_reg_power * 2;
3048 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3049 ch->reg_class_id = 0; /* FIXME */
3051 /* FIXME: why use only legacy modes, why not any
3052 * HT/VHT modes? Would that even make any
3054 if (channel->band == NL80211_BAND_2GHZ)
3055 ch->mode = MODE_11G;
3057 ch->mode = MODE_11A;
3059 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3062 ath10k_dbg(ar, ATH10K_DBG_WMI,
3063 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3064 ch - arg.channels, arg.n_channels,
3065 ch->freq, ch->max_power, ch->max_reg_power,
3066 ch->max_antenna_gain, ch->mode);
3072 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3073 kfree(arg.channels);
3078 static enum wmi_dfs_region
3079 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3081 switch (dfs_region) {
3082 case NL80211_DFS_UNSET:
3083 return WMI_UNINIT_DFS_DOMAIN;
3084 case NL80211_DFS_FCC:
3085 return WMI_FCC_DFS_DOMAIN;
3086 case NL80211_DFS_ETSI:
3087 return WMI_ETSI_DFS_DOMAIN;
3088 case NL80211_DFS_JP:
3089 return WMI_MKK4_DFS_DOMAIN;
3091 return WMI_UNINIT_DFS_DOMAIN;
3094 static void ath10k_regd_update(struct ath10k *ar)
3096 struct reg_dmn_pair_mapping *regpair;
3098 enum wmi_dfs_region wmi_dfs_reg;
3099 enum nl80211_dfs_regions nl_dfs_reg;
3101 lockdep_assert_held(&ar->conf_mutex);
3103 ret = ath10k_update_channel_list(ar);
3105 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3107 regpair = ar->ath_common.regulatory.regpair;
3109 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3110 nl_dfs_reg = ar->dfs_detector->region;
3111 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3113 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3116 /* Target allows setting up per-band regdomain but ath_common provides
3117 * a combined one only */
3118 ret = ath10k_wmi_pdev_set_regdomain(ar,
3119 regpair->reg_domain,
3120 regpair->reg_domain, /* 2ghz */
3121 regpair->reg_domain, /* 5ghz */
3122 regpair->reg_2ghz_ctl,
3123 regpair->reg_5ghz_ctl,
3126 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3129 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3130 struct ieee80211_supported_band *band)
3134 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3135 for (i = 0; i < band->n_channels; i++) {
3136 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3137 band->channels[i].center_freq > ar->high_5ghz_chan)
3138 band->channels[i].flags |=
3139 IEEE80211_CHAN_DISABLED;
3144 static void ath10k_reg_notifier(struct wiphy *wiphy,
3145 struct regulatory_request *request)
3147 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3148 struct ath10k *ar = hw->priv;
3151 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3153 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3154 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3155 request->dfs_region);
3156 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3157 request->dfs_region);
3159 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3160 request->dfs_region);
3163 mutex_lock(&ar->conf_mutex);
3164 if (ar->state == ATH10K_STATE_ON)
3165 ath10k_regd_update(ar);
3166 mutex_unlock(&ar->conf_mutex);
3168 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3169 ath10k_mac_update_channel_list(ar,
3170 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3177 enum ath10k_mac_tx_path {
3179 ATH10K_MAC_TX_HTT_MGMT,
3180 ATH10K_MAC_TX_WMI_MGMT,
3181 ATH10K_MAC_TX_UNKNOWN,
3184 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3186 lockdep_assert_held(&ar->htt.tx_lock);
3188 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3189 ar->tx_paused |= BIT(reason);
3190 ieee80211_stop_queues(ar->hw);
3193 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3194 struct ieee80211_vif *vif)
3196 struct ath10k *ar = data;
3197 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3199 if (arvif->tx_paused)
3202 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3205 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3207 lockdep_assert_held(&ar->htt.tx_lock);
3209 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3210 ar->tx_paused &= ~BIT(reason);
3215 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3216 IEEE80211_IFACE_ITER_RESUME_ALL,
3217 ath10k_mac_tx_unlock_iter,
3220 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3223 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3225 struct ath10k *ar = arvif->ar;
3227 lockdep_assert_held(&ar->htt.tx_lock);
3229 WARN_ON(reason >= BITS_PER_LONG);
3230 arvif->tx_paused |= BIT(reason);
3231 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3234 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3236 struct ath10k *ar = arvif->ar;
3238 lockdep_assert_held(&ar->htt.tx_lock);
3240 WARN_ON(reason >= BITS_PER_LONG);
3241 arvif->tx_paused &= ~BIT(reason);
3246 if (arvif->tx_paused)
3249 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3252 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3253 enum wmi_tlv_tx_pause_id pause_id,
3254 enum wmi_tlv_tx_pause_action action)
3256 struct ath10k *ar = arvif->ar;
3258 lockdep_assert_held(&ar->htt.tx_lock);
3261 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3262 ath10k_mac_vif_tx_lock(arvif, pause_id);
3264 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3265 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3268 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3269 "received unknown tx pause action %d on vdev %i, ignoring\n",
3270 action, arvif->vdev_id);
3275 struct ath10k_mac_tx_pause {
3277 enum wmi_tlv_tx_pause_id pause_id;
3278 enum wmi_tlv_tx_pause_action action;
3281 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3282 struct ieee80211_vif *vif)
3284 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3285 struct ath10k_mac_tx_pause *arg = data;
3287 if (arvif->vdev_id != arg->vdev_id)
3290 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3293 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3294 enum wmi_tlv_tx_pause_id pause_id,
3295 enum wmi_tlv_tx_pause_action action)
3297 struct ath10k_mac_tx_pause arg = {
3299 .pause_id = pause_id,
3303 spin_lock_bh(&ar->htt.tx_lock);
3304 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3305 IEEE80211_IFACE_ITER_RESUME_ALL,
3306 ath10k_mac_handle_tx_pause_iter,
3308 spin_unlock_bh(&ar->htt.tx_lock);
3311 static enum ath10k_hw_txrx_mode
3312 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3313 struct ieee80211_vif *vif,
3314 struct ieee80211_sta *sta,
3315 struct sk_buff *skb)
3317 const struct ieee80211_hdr *hdr = (void *)skb->data;
3318 __le16 fc = hdr->frame_control;
3320 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3321 return ATH10K_HW_TXRX_RAW;
3323 if (ieee80211_is_mgmt(fc))
3324 return ATH10K_HW_TXRX_MGMT;
3328 * NullFunc frames are mostly used to ping if a client or AP are still
3329 * reachable and responsive. This implies tx status reports must be
3330 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3331 * come to a conclusion that the other end disappeared and tear down
3332 * BSS connection or it can never disconnect from BSS/client (which is
3335 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3336 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3337 * which seems to deliver correct tx reports for NullFunc frames. The
3338 * downside of using it is it ignores client powersave state so it can
3339 * end up disconnecting sleeping clients in AP mode. It should fix STA
3340 * mode though because AP don't sleep.
3342 if (ar->htt.target_version_major < 3 &&
3343 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3344 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3345 ar->running_fw->fw_file.fw_features))
3346 return ATH10K_HW_TXRX_MGMT;
3350 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3351 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3352 * to work with Ethernet txmode so use it.
3354 * FIXME: Check if raw mode works with TDLS.
3356 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3357 return ATH10K_HW_TXRX_ETHERNET;
3359 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3360 return ATH10K_HW_TXRX_RAW;
3362 return ATH10K_HW_TXRX_NATIVE_WIFI;
3365 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3366 struct sk_buff *skb)
3368 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3369 const struct ieee80211_hdr *hdr = (void *)skb->data;
3370 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3371 IEEE80211_TX_CTL_INJECTED;
3373 if (!ieee80211_has_protected(hdr->frame_control))
3376 if ((info->flags & mask) == mask)
3380 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3385 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3386 * Control in the header.
3388 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3390 struct ieee80211_hdr *hdr = (void *)skb->data;
3391 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3394 if (!ieee80211_is_data_qos(hdr->frame_control))
3397 qos_ctl = ieee80211_get_qos_ctl(hdr);
3398 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3399 skb->data, (void *)qos_ctl - (void *)skb->data);
3400 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3402 /* Some firmware revisions don't handle sending QoS NullFunc well.
3403 * These frames are mainly used for CQM purposes so it doesn't really
3404 * matter whether QoS NullFunc or NullFunc are sent.
3406 hdr = (void *)skb->data;
3407 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3408 cb->flags &= ~ATH10K_SKB_F_QOS;
3410 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3413 static void ath10k_tx_h_8023(struct sk_buff *skb)
3415 struct ieee80211_hdr *hdr;
3416 struct rfc1042_hdr *rfc1042;
3423 hdr = (void *)skb->data;
3424 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3425 rfc1042 = (void *)skb->data + hdrlen;
3427 ether_addr_copy(da, ieee80211_get_DA(hdr));
3428 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3429 type = rfc1042->snap_type;
3431 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3432 skb_push(skb, sizeof(*eth));
3434 eth = (void *)skb->data;
3435 ether_addr_copy(eth->h_dest, da);
3436 ether_addr_copy(eth->h_source, sa);
3437 eth->h_proto = type;
3440 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3441 struct ieee80211_vif *vif,
3442 struct sk_buff *skb)
3444 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3445 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3447 /* This is case only for P2P_GO */
3448 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3451 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3452 spin_lock_bh(&ar->data_lock);
3453 if (arvif->u.ap.noa_data)
3454 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3456 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3457 arvif->u.ap.noa_data,
3458 arvif->u.ap.noa_len);
3459 spin_unlock_bh(&ar->data_lock);
3463 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3464 struct ieee80211_vif *vif,
3465 struct ieee80211_txq *txq,
3466 struct sk_buff *skb)
3468 struct ieee80211_hdr *hdr = (void *)skb->data;
3469 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3472 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3473 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3475 if (ieee80211_is_mgmt(hdr->frame_control))
3476 cb->flags |= ATH10K_SKB_F_MGMT;
3478 if (ieee80211_is_data_qos(hdr->frame_control))
3479 cb->flags |= ATH10K_SKB_F_QOS;
3485 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3487 /* FIXME: Not really sure since when the behaviour changed. At some
3488 * point new firmware stopped requiring creation of peer entries for
3489 * offchannel tx (and actually creating them causes issues with wmi-htc
3490 * tx credit replenishment and reliability). Assuming it's at least 3.4
3491 * because that's when the `freq` was introduced to TX_FRM HTT command.
3493 return (ar->htt.target_version_major >= 3 &&
3494 ar->htt.target_version_minor >= 4 &&
3495 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3498 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3500 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3503 spin_lock_bh(&ar->data_lock);
3505 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3506 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3511 __skb_queue_tail(q, skb);
3512 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3515 spin_unlock_bh(&ar->data_lock);
3520 static enum ath10k_mac_tx_path
3521 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3522 struct sk_buff *skb,
3523 enum ath10k_hw_txrx_mode txmode)
3526 case ATH10K_HW_TXRX_RAW:
3527 case ATH10K_HW_TXRX_NATIVE_WIFI:
3528 case ATH10K_HW_TXRX_ETHERNET:
3529 return ATH10K_MAC_TX_HTT;
3530 case ATH10K_HW_TXRX_MGMT:
3531 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3532 ar->running_fw->fw_file.fw_features))
3533 return ATH10K_MAC_TX_WMI_MGMT;
3534 else if (ar->htt.target_version_major >= 3)
3535 return ATH10K_MAC_TX_HTT;
3537 return ATH10K_MAC_TX_HTT_MGMT;
3540 return ATH10K_MAC_TX_UNKNOWN;
3543 static int ath10k_mac_tx_submit(struct ath10k *ar,
3544 enum ath10k_hw_txrx_mode txmode,
3545 enum ath10k_mac_tx_path txpath,
3546 struct sk_buff *skb)
3548 struct ath10k_htt *htt = &ar->htt;
3552 case ATH10K_MAC_TX_HTT:
3553 ret = ath10k_htt_tx(htt, txmode, skb);
3555 case ATH10K_MAC_TX_HTT_MGMT:
3556 ret = ath10k_htt_mgmt_tx(htt, skb);
3558 case ATH10K_MAC_TX_WMI_MGMT:
3559 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3561 case ATH10K_MAC_TX_UNKNOWN:
3568 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3570 ieee80211_free_txskb(ar->hw, skb);
3576 /* This function consumes the sk_buff regardless of return value as far as
3577 * caller is concerned so no freeing is necessary afterwards.
3579 static int ath10k_mac_tx(struct ath10k *ar,
3580 struct ieee80211_vif *vif,
3581 enum ath10k_hw_txrx_mode txmode,
3582 enum ath10k_mac_tx_path txpath,
3583 struct sk_buff *skb)
3585 struct ieee80211_hw *hw = ar->hw;
3586 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3589 /* We should disable CCK RATE due to P2P */
3590 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3591 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3594 case ATH10K_HW_TXRX_MGMT:
3595 case ATH10K_HW_TXRX_NATIVE_WIFI:
3596 ath10k_tx_h_nwifi(hw, skb);
3597 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3598 ath10k_tx_h_seq_no(vif, skb);
3600 case ATH10K_HW_TXRX_ETHERNET:
3601 ath10k_tx_h_8023(skb);
3603 case ATH10K_HW_TXRX_RAW:
3604 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3606 ieee80211_free_txskb(hw, skb);
3611 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3612 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3613 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3616 skb_queue_tail(&ar->offchan_tx_queue, skb);
3617 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3622 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3624 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3631 void ath10k_offchan_tx_purge(struct ath10k *ar)
3633 struct sk_buff *skb;
3636 skb = skb_dequeue(&ar->offchan_tx_queue);
3640 ieee80211_free_txskb(ar->hw, skb);
3644 void ath10k_offchan_tx_work(struct work_struct *work)
3646 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3647 struct ath10k_peer *peer;
3648 struct ath10k_vif *arvif;
3649 enum ath10k_hw_txrx_mode txmode;
3650 enum ath10k_mac_tx_path txpath;
3651 struct ieee80211_hdr *hdr;
3652 struct ieee80211_vif *vif;
3653 struct ieee80211_sta *sta;
3654 struct sk_buff *skb;
3655 const u8 *peer_addr;
3658 unsigned long time_left;
3659 bool tmp_peer_created = false;
3661 /* FW requirement: We must create a peer before FW will send out
3662 * an offchannel frame. Otherwise the frame will be stuck and
3663 * never transmitted. We delete the peer upon tx completion.
3664 * It is unlikely that a peer for offchannel tx will already be
3665 * present. However it may be in some rare cases so account for that.
3666 * Otherwise we might remove a legitimate peer and break stuff. */
3669 skb = skb_dequeue(&ar->offchan_tx_queue);
3673 mutex_lock(&ar->conf_mutex);
3675 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3678 hdr = (struct ieee80211_hdr *)skb->data;
3679 peer_addr = ieee80211_get_DA(hdr);
3681 spin_lock_bh(&ar->data_lock);
3682 vdev_id = ar->scan.vdev_id;
3683 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3684 spin_unlock_bh(&ar->data_lock);
3687 /* FIXME: should this use ath10k_warn()? */
3688 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3689 peer_addr, vdev_id);
3692 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3694 WMI_PEER_TYPE_DEFAULT);
3696 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3697 peer_addr, vdev_id, ret);
3698 tmp_peer_created = (ret == 0);
3701 spin_lock_bh(&ar->data_lock);
3702 reinit_completion(&ar->offchan_tx_completed);
3703 ar->offchan_tx_skb = skb;
3704 spin_unlock_bh(&ar->data_lock);
3706 /* It's safe to access vif and sta - conf_mutex guarantees that
3707 * sta_state() and remove_interface() are locked exclusively
3708 * out wrt to this offchannel worker.
3710 arvif = ath10k_get_arvif(ar, vdev_id);
3713 sta = ieee80211_find_sta(vif, peer_addr);
3719 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3720 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3722 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
3724 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3730 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3732 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3735 if (!peer && tmp_peer_created) {
3736 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3738 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3739 peer_addr, vdev_id, ret);
3742 mutex_unlock(&ar->conf_mutex);
3746 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3748 struct sk_buff *skb;
3751 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3755 ieee80211_free_txskb(ar->hw, skb);
3759 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3761 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3762 struct sk_buff *skb;
3766 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3770 ret = ath10k_wmi_mgmt_tx(ar, skb);
3772 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3774 ieee80211_free_txskb(ar->hw, skb);
3779 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3781 struct ath10k_txq *artxq;
3786 artxq = (void *)txq->drv_priv;
3787 INIT_LIST_HEAD(&artxq->list);
3790 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3792 struct ath10k_txq *artxq;
3793 struct ath10k_skb_cb *cb;
3794 struct sk_buff *msdu;
3800 artxq = (void *)txq->drv_priv;
3801 spin_lock_bh(&ar->txqs_lock);
3802 if (!list_empty(&artxq->list))
3803 list_del_init(&artxq->list);
3804 spin_unlock_bh(&ar->txqs_lock);
3806 spin_lock_bh(&ar->htt.tx_lock);
3807 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3808 cb = ATH10K_SKB_CB(msdu);
3812 spin_unlock_bh(&ar->htt.tx_lock);
3815 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3819 struct ath10k_peer *peer;
3821 lockdep_assert_held(&ar->data_lock);
3823 peer = ar->peer_map[peer_id];
3831 return peer->sta->txq[tid];
3833 return peer->vif->txq;
3838 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3839 struct ieee80211_txq *txq)
3841 struct ath10k *ar = hw->priv;
3842 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3844 /* No need to get locks */
3846 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3849 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3852 if (artxq->num_fw_queued < artxq->num_push_allowed)
3858 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3859 struct ieee80211_txq *txq)
3861 struct ath10k *ar = hw->priv;
3862 struct ath10k_htt *htt = &ar->htt;
3863 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3864 struct ieee80211_vif *vif = txq->vif;
3865 struct ieee80211_sta *sta = txq->sta;
3866 enum ath10k_hw_txrx_mode txmode;
3867 enum ath10k_mac_tx_path txpath;
3868 struct sk_buff *skb;
3869 struct ieee80211_hdr *hdr;
3871 bool is_mgmt, is_presp;
3874 spin_lock_bh(&ar->htt.tx_lock);
3875 ret = ath10k_htt_tx_inc_pending(htt);
3876 spin_unlock_bh(&ar->htt.tx_lock);
3881 skb = ieee80211_tx_dequeue(hw, txq);
3883 spin_lock_bh(&ar->htt.tx_lock);
3884 ath10k_htt_tx_dec_pending(htt);
3885 spin_unlock_bh(&ar->htt.tx_lock);
3890 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3893 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3894 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3895 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3898 hdr = (struct ieee80211_hdr *)skb->data;
3899 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3901 spin_lock_bh(&ar->htt.tx_lock);
3902 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3905 ath10k_htt_tx_dec_pending(htt);
3906 spin_unlock_bh(&ar->htt.tx_lock);
3909 spin_unlock_bh(&ar->htt.tx_lock);
3912 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
3913 if (unlikely(ret)) {
3914 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3916 spin_lock_bh(&ar->htt.tx_lock);
3917 ath10k_htt_tx_dec_pending(htt);
3919 ath10k_htt_tx_mgmt_dec_pending(htt);
3920 spin_unlock_bh(&ar->htt.tx_lock);
3925 spin_lock_bh(&ar->htt.tx_lock);
3926 artxq->num_fw_queued++;
3927 spin_unlock_bh(&ar->htt.tx_lock);
3932 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3934 struct ieee80211_hw *hw = ar->hw;
3935 struct ieee80211_txq *txq;
3936 struct ath10k_txq *artxq;
3937 struct ath10k_txq *last;
3941 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3944 spin_lock_bh(&ar->txqs_lock);
3947 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3948 while (!list_empty(&ar->txqs)) {
3949 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3950 txq = container_of((void *)artxq, struct ieee80211_txq,
3953 /* Prevent aggressive sta/tid taking over tx queue */
3956 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3957 ret = ath10k_mac_tx_push_txq(hw, txq);
3962 list_del_init(&artxq->list);
3964 list_add_tail(&artxq->list, &ar->txqs);
3966 ath10k_htt_tx_txq_update(hw, txq);
3968 if (artxq == last || (ret < 0 && ret != -ENOENT))
3973 spin_unlock_bh(&ar->txqs_lock);
3980 void __ath10k_scan_finish(struct ath10k *ar)
3982 lockdep_assert_held(&ar->data_lock);
3984 switch (ar->scan.state) {
3985 case ATH10K_SCAN_IDLE:
3987 case ATH10K_SCAN_RUNNING:
3988 case ATH10K_SCAN_ABORTING:
3989 if (!ar->scan.is_roc) {
3990 struct cfg80211_scan_info info = {
3991 .aborted = (ar->scan.state ==
3992 ATH10K_SCAN_ABORTING),
3995 ieee80211_scan_completed(ar->hw, &info);
3996 } else if (ar->scan.roc_notify) {
3997 ieee80211_remain_on_channel_expired(ar->hw);
4000 case ATH10K_SCAN_STARTING:
4001 ar->scan.state = ATH10K_SCAN_IDLE;
4002 ar->scan_channel = NULL;
4003 ar->scan.roc_freq = 0;
4004 ath10k_offchan_tx_purge(ar);
4005 cancel_delayed_work(&ar->scan.timeout);
4006 complete(&ar->scan.completed);
4011 void ath10k_scan_finish(struct ath10k *ar)
4013 spin_lock_bh(&ar->data_lock);
4014 __ath10k_scan_finish(ar);
4015 spin_unlock_bh(&ar->data_lock);
4018 static int ath10k_scan_stop(struct ath10k *ar)
4020 struct wmi_stop_scan_arg arg = {
4021 .req_id = 1, /* FIXME */
4022 .req_type = WMI_SCAN_STOP_ONE,
4023 .u.scan_id = ATH10K_SCAN_ID,
4027 lockdep_assert_held(&ar->conf_mutex);
4029 ret = ath10k_wmi_stop_scan(ar, &arg);
4031 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4035 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4037 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4039 } else if (ret > 0) {
4044 /* Scan state should be updated upon scan completion but in case
4045 * firmware fails to deliver the event (for whatever reason) it is
4046 * desired to clean up scan state anyway. Firmware may have just
4047 * dropped the scan completion event delivery due to transport pipe
4048 * being overflown with data and/or it can recover on its own before
4049 * next scan request is submitted.
4051 spin_lock_bh(&ar->data_lock);
4052 if (ar->scan.state != ATH10K_SCAN_IDLE)
4053 __ath10k_scan_finish(ar);
4054 spin_unlock_bh(&ar->data_lock);
4059 static void ath10k_scan_abort(struct ath10k *ar)
4063 lockdep_assert_held(&ar->conf_mutex);
4065 spin_lock_bh(&ar->data_lock);
4067 switch (ar->scan.state) {
4068 case ATH10K_SCAN_IDLE:
4069 /* This can happen if timeout worker kicked in and called
4070 * abortion while scan completion was being processed.
4073 case ATH10K_SCAN_STARTING:
4074 case ATH10K_SCAN_ABORTING:
4075 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4076 ath10k_scan_state_str(ar->scan.state),
4079 case ATH10K_SCAN_RUNNING:
4080 ar->scan.state = ATH10K_SCAN_ABORTING;
4081 spin_unlock_bh(&ar->data_lock);
4083 ret = ath10k_scan_stop(ar);
4085 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4087 spin_lock_bh(&ar->data_lock);
4091 spin_unlock_bh(&ar->data_lock);
4094 void ath10k_scan_timeout_work(struct work_struct *work)
4096 struct ath10k *ar = container_of(work, struct ath10k,
4099 mutex_lock(&ar->conf_mutex);
4100 ath10k_scan_abort(ar);
4101 mutex_unlock(&ar->conf_mutex);
4104 static int ath10k_start_scan(struct ath10k *ar,
4105 const struct wmi_start_scan_arg *arg)
4109 lockdep_assert_held(&ar->conf_mutex);
4111 ret = ath10k_wmi_start_scan(ar, arg);
4115 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4117 ret = ath10k_scan_stop(ar);
4119 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4124 /* If we failed to start the scan, return error code at
4125 * this point. This is probably due to some issue in the
4126 * firmware, but no need to wedge the driver due to that...
4128 spin_lock_bh(&ar->data_lock);
4129 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4130 spin_unlock_bh(&ar->data_lock);
4133 spin_unlock_bh(&ar->data_lock);
4138 /**********************/
4139 /* mac80211 callbacks */
4140 /**********************/
4142 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4143 struct ieee80211_tx_control *control,
4144 struct sk_buff *skb)
4146 struct ath10k *ar = hw->priv;
4147 struct ath10k_htt *htt = &ar->htt;
4148 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4149 struct ieee80211_vif *vif = info->control.vif;
4150 struct ieee80211_sta *sta = control->sta;
4151 struct ieee80211_txq *txq = NULL;
4152 struct ieee80211_hdr *hdr = (void *)skb->data;
4153 enum ath10k_hw_txrx_mode txmode;
4154 enum ath10k_mac_tx_path txpath;
4160 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4162 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4163 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4164 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4165 txpath == ATH10K_MAC_TX_HTT_MGMT);
4166 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4169 spin_lock_bh(&ar->htt.tx_lock);
4170 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4172 ret = ath10k_htt_tx_inc_pending(htt);
4174 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4176 spin_unlock_bh(&ar->htt.tx_lock);
4177 ieee80211_free_txskb(ar->hw, skb);
4181 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4183 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4185 ath10k_htt_tx_dec_pending(htt);
4186 spin_unlock_bh(&ar->htt.tx_lock);
4187 ieee80211_free_txskb(ar->hw, skb);
4190 spin_unlock_bh(&ar->htt.tx_lock);
4193 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb);
4195 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4197 spin_lock_bh(&ar->htt.tx_lock);
4198 ath10k_htt_tx_dec_pending(htt);
4200 ath10k_htt_tx_mgmt_dec_pending(htt);
4201 spin_unlock_bh(&ar->htt.tx_lock);
4207 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4208 struct ieee80211_txq *txq)
4210 struct ath10k *ar = hw->priv;
4211 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4212 struct ieee80211_txq *f_txq;
4213 struct ath10k_txq *f_artxq;
4217 spin_lock_bh(&ar->txqs_lock);
4218 if (list_empty(&artxq->list))
4219 list_add_tail(&artxq->list, &ar->txqs);
4221 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4222 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4223 list_del_init(&f_artxq->list);
4225 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4226 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4231 list_add_tail(&f_artxq->list, &ar->txqs);
4232 spin_unlock_bh(&ar->txqs_lock);
4234 ath10k_htt_tx_txq_update(hw, f_txq);
4235 ath10k_htt_tx_txq_update(hw, txq);
4238 /* Must not be called with conf_mutex held as workers can use that also. */
4239 void ath10k_drain_tx(struct ath10k *ar)
4241 /* make sure rcu-protected mac80211 tx path itself is drained */
4244 ath10k_offchan_tx_purge(ar);
4245 ath10k_mgmt_over_wmi_tx_purge(ar);
4247 cancel_work_sync(&ar->offchan_tx_work);
4248 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4251 void ath10k_halt(struct ath10k *ar)
4253 struct ath10k_vif *arvif;
4255 lockdep_assert_held(&ar->conf_mutex);
4257 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4258 ar->filter_flags = 0;
4259 ar->monitor = false;
4260 ar->monitor_arvif = NULL;
4262 if (ar->monitor_started)
4263 ath10k_monitor_stop(ar);
4265 ar->monitor_started = false;
4268 ath10k_scan_finish(ar);
4269 ath10k_peer_cleanup_all(ar);
4270 ath10k_core_stop(ar);
4271 ath10k_hif_power_down(ar);
4273 spin_lock_bh(&ar->data_lock);
4274 list_for_each_entry(arvif, &ar->arvifs, list)
4275 ath10k_mac_vif_beacon_cleanup(arvif);
4276 spin_unlock_bh(&ar->data_lock);
4279 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4281 struct ath10k *ar = hw->priv;
4283 mutex_lock(&ar->conf_mutex);
4285 *tx_ant = ar->cfg_tx_chainmask;
4286 *rx_ant = ar->cfg_rx_chainmask;
4288 mutex_unlock(&ar->conf_mutex);
4293 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4295 /* It is not clear that allowing gaps in chainmask
4296 * is helpful. Probably it will not do what user
4297 * is hoping for, so warn in that case.
4299 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4302 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4306 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4308 int nsts = ar->vht_cap_info;
4310 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4311 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4313 /* If firmware does not deliver to host number of space-time
4314 * streams supported, assume it support up to 4 BF STS and return
4315 * the value for VHT CAP: nsts-1)
4323 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4325 int sound_dim = ar->vht_cap_info;
4327 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4328 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4330 /* If the sounding dimension is not advertised by the firmware,
4331 * let's use a default value of 1
4339 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4341 struct ieee80211_sta_vht_cap vht_cap = {0};
4346 vht_cap.vht_supported = 1;
4347 vht_cap.cap = ar->vht_cap_info;
4349 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4350 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4351 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4352 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4353 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4358 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4359 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4360 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4361 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4362 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4367 /* Currently the firmware seems to be buggy, don't enable 80+80
4368 * mode until that's resolved.
4370 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4371 !(ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))
4372 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4375 for (i = 0; i < 8; i++) {
4376 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4377 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4379 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4382 if (ar->cfg_tx_chainmask <= 1)
4383 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4385 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4386 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4391 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4394 struct ieee80211_sta_ht_cap ht_cap = {0};
4396 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4399 ht_cap.ht_supported = 1;
4400 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4401 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4402 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4403 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4405 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4407 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4408 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4410 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4411 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4413 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4416 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4417 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4422 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4423 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4425 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4428 stbc = ar->ht_cap_info;
4429 stbc &= WMI_HT_CAP_RX_STBC;
4430 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4431 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4432 stbc &= IEEE80211_HT_CAP_RX_STBC;
4437 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4438 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4440 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4441 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4443 /* max AMSDU is implicitly taken from vht_cap_info */
4444 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4445 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4447 for (i = 0; i < ar->num_rf_chains; i++) {
4448 if (ar->cfg_rx_chainmask & BIT(i))
4449 ht_cap.mcs.rx_mask[i] = 0xFF;
4452 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4457 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4459 struct ieee80211_supported_band *band;
4460 struct ieee80211_sta_vht_cap vht_cap;
4461 struct ieee80211_sta_ht_cap ht_cap;
4463 ht_cap = ath10k_get_ht_cap(ar);
4464 vht_cap = ath10k_create_vht_cap(ar);
4466 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4467 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4468 band->ht_cap = ht_cap;
4470 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4471 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4472 band->ht_cap = ht_cap;
4473 band->vht_cap = vht_cap;
4477 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4481 lockdep_assert_held(&ar->conf_mutex);
4483 ath10k_check_chain_mask(ar, tx_ant, "tx");
4484 ath10k_check_chain_mask(ar, rx_ant, "rx");
4486 ar->cfg_tx_chainmask = tx_ant;
4487 ar->cfg_rx_chainmask = rx_ant;
4489 if ((ar->state != ATH10K_STATE_ON) &&
4490 (ar->state != ATH10K_STATE_RESTARTED))
4493 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4496 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4501 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4504 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4509 /* Reload HT/VHT capability */
4510 ath10k_mac_setup_ht_vht_cap(ar);
4515 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4517 struct ath10k *ar = hw->priv;
4520 mutex_lock(&ar->conf_mutex);
4521 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4522 mutex_unlock(&ar->conf_mutex);
4526 static int ath10k_start(struct ieee80211_hw *hw)
4528 struct ath10k *ar = hw->priv;
4533 * This makes sense only when restarting hw. It is harmless to call
4534 * unconditionally. This is necessary to make sure no HTT/WMI tx
4535 * commands will be submitted while restarting.
4537 ath10k_drain_tx(ar);
4539 mutex_lock(&ar->conf_mutex);
4541 switch (ar->state) {
4542 case ATH10K_STATE_OFF:
4543 ar->state = ATH10K_STATE_ON;
4545 case ATH10K_STATE_RESTARTING:
4546 ar->state = ATH10K_STATE_RESTARTED;
4548 case ATH10K_STATE_ON:
4549 case ATH10K_STATE_RESTARTED:
4550 case ATH10K_STATE_WEDGED:
4554 case ATH10K_STATE_UTF:
4559 ret = ath10k_hif_power_up(ar);
4561 ath10k_err(ar, "Could not init hif: %d\n", ret);
4565 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4566 &ar->normal_mode_fw);
4568 ath10k_err(ar, "Could not init core: %d\n", ret);
4569 goto err_power_down;
4572 param = ar->wmi.pdev_param->pmf_qos;
4573 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4575 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4579 param = ar->wmi.pdev_param->dynamic_bw;
4580 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4582 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4586 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4587 ret = ath10k_wmi_adaptive_qcs(ar, true);
4589 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4595 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4596 param = ar->wmi.pdev_param->burst_enable;
4597 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4599 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4604 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4607 * By default FW set ARP frames ac to voice (6). In that case ARP
4608 * exchange is not working properly for UAPSD enabled AP. ARP requests
4609 * which arrives with access category 0 are processed by network stack
4610 * and send back with access category 0, but FW changes access category
4611 * to 6. Set ARP frames access category to best effort (0) solves
4615 param = ar->wmi.pdev_param->arp_ac_override;
4616 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4618 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4623 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4624 ar->running_fw->fw_file.fw_features)) {
4625 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4626 WMI_CCA_DETECT_LEVEL_AUTO,
4627 WMI_CCA_DETECT_MARGIN_AUTO);
4629 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4635 param = ar->wmi.pdev_param->ani_enable;
4636 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4638 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4643 ar->ani_enabled = true;
4645 if (ath10k_peer_stats_enabled(ar)) {
4646 param = ar->wmi.pdev_param->peer_stats_update_period;
4647 ret = ath10k_wmi_pdev_set_param(ar, param,
4648 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4651 "failed to set peer stats period : %d\n",
4657 param = ar->wmi.pdev_param->enable_btcoex;
4658 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4659 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4660 ar->running_fw->fw_file.fw_features)) {
4661 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4664 "failed to set btcoex param: %d\n", ret);
4667 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4670 ar->num_started_vdevs = 0;
4671 ath10k_regd_update(ar);
4673 ath10k_spectral_start(ar);
4674 ath10k_thermal_set_throttling(ar);
4676 mutex_unlock(&ar->conf_mutex);
4680 ath10k_core_stop(ar);
4683 ath10k_hif_power_down(ar);
4686 ar->state = ATH10K_STATE_OFF;
4689 mutex_unlock(&ar->conf_mutex);
4693 static void ath10k_stop(struct ieee80211_hw *hw)
4695 struct ath10k *ar = hw->priv;
4697 ath10k_drain_tx(ar);
4699 mutex_lock(&ar->conf_mutex);
4700 if (ar->state != ATH10K_STATE_OFF) {
4702 ar->state = ATH10K_STATE_OFF;
4704 mutex_unlock(&ar->conf_mutex);
4706 cancel_delayed_work_sync(&ar->scan.timeout);
4707 cancel_work_sync(&ar->restart_work);
4710 static int ath10k_config_ps(struct ath10k *ar)
4712 struct ath10k_vif *arvif;
4715 lockdep_assert_held(&ar->conf_mutex);
4717 list_for_each_entry(arvif, &ar->arvifs, list) {
4718 ret = ath10k_mac_vif_setup_ps(arvif);
4720 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4728 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4733 lockdep_assert_held(&ar->conf_mutex);
4735 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4737 param = ar->wmi.pdev_param->txpower_limit2g;
4738 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4740 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4745 param = ar->wmi.pdev_param->txpower_limit5g;
4746 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4748 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4756 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4758 struct ath10k_vif *arvif;
4759 int ret, txpower = -1;
4761 lockdep_assert_held(&ar->conf_mutex);
4763 list_for_each_entry(arvif, &ar->arvifs, list) {
4764 if (arvif->txpower <= 0)
4768 txpower = arvif->txpower;
4770 txpower = min(txpower, arvif->txpower);
4776 ret = ath10k_mac_txpower_setup(ar, txpower);
4778 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4786 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4788 struct ath10k *ar = hw->priv;
4789 struct ieee80211_conf *conf = &hw->conf;
4792 mutex_lock(&ar->conf_mutex);
4794 if (changed & IEEE80211_CONF_CHANGE_PS)
4795 ath10k_config_ps(ar);
4797 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4798 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4799 ret = ath10k_monitor_recalc(ar);
4801 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4804 mutex_unlock(&ar->conf_mutex);
4808 static u32 get_nss_from_chainmask(u16 chain_mask)
4810 if ((chain_mask & 0xf) == 0xf)
4812 else if ((chain_mask & 0x7) == 0x7)
4814 else if ((chain_mask & 0x3) == 0x3)
4819 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4822 struct ath10k *ar = arvif->ar;
4826 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4829 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4830 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4831 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4832 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4834 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4835 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4836 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4837 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4842 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4843 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4845 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4846 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4847 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4849 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4850 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4852 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4853 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4854 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4856 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4857 ar->wmi.vdev_param->txbf, value);
4862 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4863 * because we will send mgmt frames without CCK. This requirement
4864 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4867 static int ath10k_add_interface(struct ieee80211_hw *hw,
4868 struct ieee80211_vif *vif)
4870 struct ath10k *ar = hw->priv;
4871 struct ath10k_vif *arvif = (void *)vif->drv_priv;
4872 struct ath10k_peer *peer;
4873 enum wmi_sta_powersave_param param;
4880 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4882 mutex_lock(&ar->conf_mutex);
4884 memset(arvif, 0, sizeof(*arvif));
4885 ath10k_mac_txq_init(vif->txq);
4890 INIT_LIST_HEAD(&arvif->list);
4891 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4892 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4893 ath10k_mac_vif_sta_connection_loss_work);
4895 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4896 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4897 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4898 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4899 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4900 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4903 if (ar->num_peers >= ar->max_num_peers) {
4904 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4909 if (ar->free_vdev_map == 0) {
4910 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4914 bit = __ffs64(ar->free_vdev_map);
4916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4917 bit, ar->free_vdev_map);
4919 arvif->vdev_id = bit;
4920 arvif->vdev_subtype =
4921 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4923 switch (vif->type) {
4924 case NL80211_IFTYPE_P2P_DEVICE:
4925 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4926 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4927 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4929 case NL80211_IFTYPE_UNSPECIFIED:
4930 case NL80211_IFTYPE_STATION:
4931 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4933 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4934 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4936 case NL80211_IFTYPE_ADHOC:
4937 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4939 case NL80211_IFTYPE_MESH_POINT:
4940 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4941 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4942 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4943 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4945 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4948 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4950 case NL80211_IFTYPE_AP:
4951 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4954 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4955 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4957 case NL80211_IFTYPE_MONITOR:
4958 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4965 /* Using vdev_id as queue number will make it very easy to do per-vif
4966 * tx queue locking. This shouldn't wrap due to interface combinations
4967 * but do a modulo for correctness sake and prevent using offchannel tx
4968 * queues for regular vif tx.
4970 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4971 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4972 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4974 /* Some firmware revisions don't wait for beacon tx completion before
4975 * sending another SWBA event. This could lead to hardware using old
4976 * (freed) beacon data in some cases, e.g. tx credit starvation
4977 * combined with missed TBTT. This is very very rare.
4979 * On non-IOMMU-enabled hosts this could be a possible security issue
4980 * because hw could beacon some random data on the air. On
4981 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4982 * device would crash.
4984 * Since there are no beacon tx completions (implicit nor explicit)
4985 * propagated to host the only workaround for this is to allocate a
4986 * DMA-coherent buffer for a lifetime of a vif and use it for all
4987 * beacon tx commands. Worst case for this approach is some beacons may
4988 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4990 if (vif->type == NL80211_IFTYPE_ADHOC ||
4991 vif->type == NL80211_IFTYPE_MESH_POINT ||
4992 vif->type == NL80211_IFTYPE_AP) {
4993 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4994 IEEE80211_MAX_FRAME_LEN,
4995 &arvif->beacon_paddr,
4997 if (!arvif->beacon_buf) {
4999 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5004 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5005 arvif->nohwcrypt = true;
5007 if (arvif->nohwcrypt &&
5008 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5009 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5013 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5014 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5015 arvif->beacon_buf ? "single-buf" : "per-skb");
5017 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5018 arvif->vdev_subtype, vif->addr);
5020 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5021 arvif->vdev_id, ret);
5025 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5026 spin_lock_bh(&ar->data_lock);
5027 list_add(&arvif->list, &ar->arvifs);
5028 spin_unlock_bh(&ar->data_lock);
5030 /* It makes no sense to have firmware do keepalives. mac80211 already
5031 * takes care of this with idle connection polling.
5033 ret = ath10k_mac_vif_disable_keepalive(arvif);
5035 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5036 arvif->vdev_id, ret);
5037 goto err_vdev_delete;
5040 arvif->def_wep_key_idx = -1;
5042 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5043 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5044 ATH10K_HW_TXRX_NATIVE_WIFI);
5045 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5046 if (ret && ret != -EOPNOTSUPP) {
5047 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5048 arvif->vdev_id, ret);
5049 goto err_vdev_delete;
5052 /* Configuring number of spatial stream for monitor interface is causing
5053 * target assert in qca9888 and qca6174.
5055 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5056 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5058 vdev_param = ar->wmi.vdev_param->nss;
5059 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5062 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5063 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5065 goto err_vdev_delete;
5069 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5070 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5071 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5072 vif->addr, WMI_PEER_TYPE_DEFAULT);
5074 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5075 arvif->vdev_id, ret);
5076 goto err_vdev_delete;
5079 spin_lock_bh(&ar->data_lock);
5081 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5083 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5084 vif->addr, arvif->vdev_id);
5085 spin_unlock_bh(&ar->data_lock);
5087 goto err_peer_delete;
5090 arvif->peer_id = find_first_bit(peer->peer_ids,
5091 ATH10K_MAX_NUM_PEER_IDS);
5093 spin_unlock_bh(&ar->data_lock);
5095 arvif->peer_id = HTT_INVALID_PEERID;
5098 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5099 ret = ath10k_mac_set_kickout(arvif);
5101 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5102 arvif->vdev_id, ret);
5103 goto err_peer_delete;
5107 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5108 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5109 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5110 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5113 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5114 arvif->vdev_id, ret);
5115 goto err_peer_delete;
5118 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5120 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5121 arvif->vdev_id, ret);
5122 goto err_peer_delete;
5125 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5127 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5128 arvif->vdev_id, ret);
5129 goto err_peer_delete;
5133 ret = ath10k_mac_set_txbf_conf(arvif);
5135 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5136 arvif->vdev_id, ret);
5137 goto err_peer_delete;
5140 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5142 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5143 arvif->vdev_id, ret);
5144 goto err_peer_delete;
5147 arvif->txpower = vif->bss_conf.txpower;
5148 ret = ath10k_mac_txpower_recalc(ar);
5150 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5151 goto err_peer_delete;
5154 if (vif->type == NL80211_IFTYPE_MONITOR) {
5155 ar->monitor_arvif = arvif;
5156 ret = ath10k_monitor_recalc(ar);
5158 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5159 goto err_peer_delete;
5163 spin_lock_bh(&ar->htt.tx_lock);
5165 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5166 spin_unlock_bh(&ar->htt.tx_lock);
5168 mutex_unlock(&ar->conf_mutex);
5172 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5173 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5174 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5177 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5178 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5179 spin_lock_bh(&ar->data_lock);
5180 list_del(&arvif->list);
5181 spin_unlock_bh(&ar->data_lock);
5184 if (arvif->beacon_buf) {
5185 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5186 arvif->beacon_buf, arvif->beacon_paddr);
5187 arvif->beacon_buf = NULL;
5190 mutex_unlock(&ar->conf_mutex);
5195 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5199 for (i = 0; i < BITS_PER_LONG; i++)
5200 ath10k_mac_vif_tx_unlock(arvif, i);
5203 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5204 struct ieee80211_vif *vif)
5206 struct ath10k *ar = hw->priv;
5207 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5208 struct ath10k_peer *peer;
5212 cancel_work_sync(&arvif->ap_csa_work);
5213 cancel_delayed_work_sync(&arvif->connection_loss_work);
5215 mutex_lock(&ar->conf_mutex);
5217 spin_lock_bh(&ar->data_lock);
5218 ath10k_mac_vif_beacon_cleanup(arvif);
5219 spin_unlock_bh(&ar->data_lock);
5221 ret = ath10k_spectral_vif_stop(arvif);
5223 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5224 arvif->vdev_id, ret);
5226 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5227 spin_lock_bh(&ar->data_lock);
5228 list_del(&arvif->list);
5229 spin_unlock_bh(&ar->data_lock);
5231 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5232 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5233 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5236 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5237 arvif->vdev_id, ret);
5239 kfree(arvif->u.ap.noa_data);
5242 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5245 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5247 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5248 arvif->vdev_id, ret);
5250 /* Some firmware revisions don't notify host about self-peer removal
5251 * until after associated vdev is deleted.
5253 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5254 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5255 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5258 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5259 arvif->vdev_id, ret);
5261 spin_lock_bh(&ar->data_lock);
5263 spin_unlock_bh(&ar->data_lock);
5266 spin_lock_bh(&ar->data_lock);
5267 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5268 peer = ar->peer_map[i];
5272 if (peer->vif == vif) {
5273 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5274 vif->addr, arvif->vdev_id);
5278 spin_unlock_bh(&ar->data_lock);
5280 ath10k_peer_cleanup(ar, arvif->vdev_id);
5281 ath10k_mac_txq_unref(ar, vif->txq);
5283 if (vif->type == NL80211_IFTYPE_MONITOR) {
5284 ar->monitor_arvif = NULL;
5285 ret = ath10k_monitor_recalc(ar);
5287 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5290 ret = ath10k_mac_txpower_recalc(ar);
5292 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5294 spin_lock_bh(&ar->htt.tx_lock);
5295 ath10k_mac_vif_tx_unlock_all(arvif);
5296 spin_unlock_bh(&ar->htt.tx_lock);
5298 ath10k_mac_txq_unref(ar, vif->txq);
5300 mutex_unlock(&ar->conf_mutex);
5304 * FIXME: Has to be verified.
5306 #define SUPPORTED_FILTERS \
5311 FIF_BCN_PRBRESP_PROMISC | \
5315 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5316 unsigned int changed_flags,
5317 unsigned int *total_flags,
5320 struct ath10k *ar = hw->priv;
5323 mutex_lock(&ar->conf_mutex);
5325 changed_flags &= SUPPORTED_FILTERS;
5326 *total_flags &= SUPPORTED_FILTERS;
5327 ar->filter_flags = *total_flags;
5329 ret = ath10k_monitor_recalc(ar);
5331 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5333 mutex_unlock(&ar->conf_mutex);
5336 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5337 struct ieee80211_vif *vif,
5338 struct ieee80211_bss_conf *info,
5341 struct ath10k *ar = hw->priv;
5342 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5344 u32 vdev_param, pdev_param, slottime, preamble;
5346 mutex_lock(&ar->conf_mutex);
5348 if (changed & BSS_CHANGED_IBSS)
5349 ath10k_control_ibss(arvif, info, vif->addr);
5351 if (changed & BSS_CHANGED_BEACON_INT) {
5352 arvif->beacon_interval = info->beacon_int;
5353 vdev_param = ar->wmi.vdev_param->beacon_interval;
5354 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5355 arvif->beacon_interval);
5356 ath10k_dbg(ar, ATH10K_DBG_MAC,
5357 "mac vdev %d beacon_interval %d\n",
5358 arvif->vdev_id, arvif->beacon_interval);
5361 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5362 arvif->vdev_id, ret);
5365 if (changed & BSS_CHANGED_BEACON) {
5366 ath10k_dbg(ar, ATH10K_DBG_MAC,
5367 "vdev %d set beacon tx mode to staggered\n",
5370 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5371 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5372 WMI_BEACON_STAGGERED_MODE);
5374 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5375 arvif->vdev_id, ret);
5377 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5379 ath10k_warn(ar, "failed to update beacon template: %d\n",
5382 if (ieee80211_vif_is_mesh(vif)) {
5383 /* mesh doesn't use SSID but firmware needs it */
5384 strncpy(arvif->u.ap.ssid, "mesh",
5385 sizeof(arvif->u.ap.ssid));
5386 arvif->u.ap.ssid_len = 4;
5390 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5391 ret = ath10k_mac_setup_prb_tmpl(arvif);
5393 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5394 arvif->vdev_id, ret);
5397 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5398 arvif->dtim_period = info->dtim_period;
5400 ath10k_dbg(ar, ATH10K_DBG_MAC,
5401 "mac vdev %d dtim_period %d\n",
5402 arvif->vdev_id, arvif->dtim_period);
5404 vdev_param = ar->wmi.vdev_param->dtim_period;
5405 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5406 arvif->dtim_period);
5408 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5409 arvif->vdev_id, ret);
5412 if (changed & BSS_CHANGED_SSID &&
5413 vif->type == NL80211_IFTYPE_AP) {
5414 arvif->u.ap.ssid_len = info->ssid_len;
5416 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5417 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5420 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5421 ether_addr_copy(arvif->bssid, info->bssid);
5423 if (changed & BSS_CHANGED_BEACON_ENABLED)
5424 ath10k_control_beaconing(arvif, info);
5426 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5427 arvif->use_cts_prot = info->use_cts_prot;
5429 ret = ath10k_recalc_rtscts_prot(arvif);
5431 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5432 arvif->vdev_id, ret);
5434 if (ath10k_mac_can_set_cts_prot(arvif)) {
5435 ret = ath10k_mac_set_cts_prot(arvif);
5437 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5438 arvif->vdev_id, ret);
5442 if (changed & BSS_CHANGED_ERP_SLOT) {
5443 if (info->use_short_slot)
5444 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5447 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5449 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5450 arvif->vdev_id, slottime);
5452 vdev_param = ar->wmi.vdev_param->slot_time;
5453 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5456 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5457 arvif->vdev_id, ret);
5460 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5461 if (info->use_short_preamble)
5462 preamble = WMI_VDEV_PREAMBLE_SHORT;
5464 preamble = WMI_VDEV_PREAMBLE_LONG;
5466 ath10k_dbg(ar, ATH10K_DBG_MAC,
5467 "mac vdev %d preamble %dn",
5468 arvif->vdev_id, preamble);
5470 vdev_param = ar->wmi.vdev_param->preamble;
5471 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5474 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5475 arvif->vdev_id, ret);
5478 if (changed & BSS_CHANGED_ASSOC) {
5480 /* Workaround: Make sure monitor vdev is not running
5481 * when associating to prevent some firmware revisions
5482 * (e.g. 10.1 and 10.2) from crashing.
5484 if (ar->monitor_started)
5485 ath10k_monitor_stop(ar);
5486 ath10k_bss_assoc(hw, vif, info);
5487 ath10k_monitor_recalc(ar);
5489 ath10k_bss_disassoc(hw, vif);
5493 if (changed & BSS_CHANGED_TXPOWER) {
5494 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5495 arvif->vdev_id, info->txpower);
5497 arvif->txpower = info->txpower;
5498 ret = ath10k_mac_txpower_recalc(ar);
5500 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5503 if (changed & BSS_CHANGED_PS) {
5504 arvif->ps = vif->bss_conf.ps;
5506 ret = ath10k_config_ps(ar);
5508 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5509 arvif->vdev_id, ret);
5512 mutex_unlock(&ar->conf_mutex);
5515 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5517 struct ath10k *ar = hw->priv;
5519 /* This function should never be called if setting the coverage class
5520 * is not supported on this hardware.
5522 if (!ar->hw_params.hw_ops->set_coverage_class) {
5526 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5529 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5530 struct ieee80211_vif *vif,
5531 struct ieee80211_scan_request *hw_req)
5533 struct ath10k *ar = hw->priv;
5534 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5535 struct cfg80211_scan_request *req = &hw_req->req;
5536 struct wmi_start_scan_arg arg;
5540 mutex_lock(&ar->conf_mutex);
5542 spin_lock_bh(&ar->data_lock);
5543 switch (ar->scan.state) {
5544 case ATH10K_SCAN_IDLE:
5545 reinit_completion(&ar->scan.started);
5546 reinit_completion(&ar->scan.completed);
5547 ar->scan.state = ATH10K_SCAN_STARTING;
5548 ar->scan.is_roc = false;
5549 ar->scan.vdev_id = arvif->vdev_id;
5552 case ATH10K_SCAN_STARTING:
5553 case ATH10K_SCAN_RUNNING:
5554 case ATH10K_SCAN_ABORTING:
5558 spin_unlock_bh(&ar->data_lock);
5563 memset(&arg, 0, sizeof(arg));
5564 ath10k_wmi_start_scan_init(ar, &arg);
5565 arg.vdev_id = arvif->vdev_id;
5566 arg.scan_id = ATH10K_SCAN_ID;
5569 arg.ie_len = req->ie_len;
5570 memcpy(arg.ie, req->ie, arg.ie_len);
5574 arg.n_ssids = req->n_ssids;
5575 for (i = 0; i < arg.n_ssids; i++) {
5576 arg.ssids[i].len = req->ssids[i].ssid_len;
5577 arg.ssids[i].ssid = req->ssids[i].ssid;
5580 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5583 if (req->n_channels) {
5584 arg.n_channels = req->n_channels;
5585 for (i = 0; i < arg.n_channels; i++)
5586 arg.channels[i] = req->channels[i]->center_freq;
5589 ret = ath10k_start_scan(ar, &arg);
5591 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5592 spin_lock_bh(&ar->data_lock);
5593 ar->scan.state = ATH10K_SCAN_IDLE;
5594 spin_unlock_bh(&ar->data_lock);
5597 /* Add a 200ms margin to account for event/command processing */
5598 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5599 msecs_to_jiffies(arg.max_scan_time +
5603 mutex_unlock(&ar->conf_mutex);
5607 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5608 struct ieee80211_vif *vif)
5610 struct ath10k *ar = hw->priv;
5612 mutex_lock(&ar->conf_mutex);
5613 ath10k_scan_abort(ar);
5614 mutex_unlock(&ar->conf_mutex);
5616 cancel_delayed_work_sync(&ar->scan.timeout);
5619 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5620 struct ath10k_vif *arvif,
5621 enum set_key_cmd cmd,
5622 struct ieee80211_key_conf *key)
5624 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5627 /* 10.1 firmware branch requires default key index to be set to group
5628 * key index after installing it. Otherwise FW/HW Txes corrupted
5629 * frames with multi-vif APs. This is not required for main firmware
5630 * branch (e.g. 636).
5632 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5634 * FIXME: It remains unknown if this is required for multi-vif STA
5635 * interfaces on 10.1.
5638 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5639 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5642 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5645 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5648 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5654 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5657 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5658 arvif->vdev_id, ret);
5661 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5662 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5663 struct ieee80211_key_conf *key)
5665 struct ath10k *ar = hw->priv;
5666 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5667 struct ath10k_peer *peer;
5668 const u8 *peer_addr;
5669 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5670 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5676 /* this one needs to be done in software */
5677 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5680 if (arvif->nohwcrypt)
5683 if (key->keyidx > WMI_MAX_KEY_INDEX)
5686 mutex_lock(&ar->conf_mutex);
5689 peer_addr = sta->addr;
5690 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5691 peer_addr = vif->bss_conf.bssid;
5693 peer_addr = vif->addr;
5695 key->hw_key_idx = key->keyidx;
5699 arvif->wep_keys[key->keyidx] = key;
5701 arvif->wep_keys[key->keyidx] = NULL;
5704 /* the peer should not disappear in mid-way (unless FW goes awry) since
5705 * we already hold conf_mutex. we just make sure its there now. */
5706 spin_lock_bh(&ar->data_lock);
5707 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5708 spin_unlock_bh(&ar->data_lock);
5711 if (cmd == SET_KEY) {
5712 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5717 /* if the peer doesn't exist there is no key to disable
5723 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5724 flags |= WMI_KEY_PAIRWISE;
5726 flags |= WMI_KEY_GROUP;
5729 if (cmd == DISABLE_KEY)
5730 ath10k_clear_vdev_key(arvif, key);
5732 /* When WEP keys are uploaded it's possible that there are
5733 * stations associated already (e.g. when merging) without any
5734 * keys. Static WEP needs an explicit per-peer key upload.
5736 if (vif->type == NL80211_IFTYPE_ADHOC &&
5738 ath10k_mac_vif_update_wep_key(arvif, key);
5740 /* 802.1x never sets the def_wep_key_idx so each set_key()
5741 * call changes default tx key.
5743 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5744 * after first set_key().
5746 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5747 flags |= WMI_KEY_TX_USAGE;
5750 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5753 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5754 arvif->vdev_id, peer_addr, ret);
5758 /* mac80211 sets static WEP keys as groupwise while firmware requires
5759 * them to be installed twice as both pairwise and groupwise.
5761 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5763 flags2 &= ~WMI_KEY_GROUP;
5764 flags2 |= WMI_KEY_PAIRWISE;
5766 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5769 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5770 arvif->vdev_id, peer_addr, ret);
5771 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5775 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5776 arvif->vdev_id, peer_addr, ret2);
5782 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5784 spin_lock_bh(&ar->data_lock);
5785 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5786 if (peer && cmd == SET_KEY)
5787 peer->keys[key->keyidx] = key;
5788 else if (peer && cmd == DISABLE_KEY)
5789 peer->keys[key->keyidx] = NULL;
5790 else if (peer == NULL)
5791 /* impossible unless FW goes crazy */
5792 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5793 spin_unlock_bh(&ar->data_lock);
5796 mutex_unlock(&ar->conf_mutex);
5800 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5801 struct ieee80211_vif *vif,
5804 struct ath10k *ar = hw->priv;
5805 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5808 mutex_lock(&arvif->ar->conf_mutex);
5810 if (arvif->ar->state != ATH10K_STATE_ON)
5813 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5814 arvif->vdev_id, keyidx);
5816 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5818 arvif->ar->wmi.vdev_param->def_keyid,
5822 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5828 arvif->def_wep_key_idx = keyidx;
5831 mutex_unlock(&arvif->ar->conf_mutex);
5834 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5837 struct ath10k_vif *arvif;
5838 struct ath10k_sta *arsta;
5839 struct ieee80211_sta *sta;
5840 struct cfg80211_chan_def def;
5841 enum nl80211_band band;
5842 const u8 *ht_mcs_mask;
5843 const u16 *vht_mcs_mask;
5844 u32 changed, bw, nss, smps;
5847 arsta = container_of(wk, struct ath10k_sta, update_wk);
5848 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5849 arvif = arsta->arvif;
5852 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5855 band = def.chan->band;
5856 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5857 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5859 spin_lock_bh(&ar->data_lock);
5861 changed = arsta->changed;
5868 spin_unlock_bh(&ar->data_lock);
5870 mutex_lock(&ar->conf_mutex);
5872 nss = max_t(u32, 1, nss);
5873 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5874 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5876 if (changed & IEEE80211_RC_BW_CHANGED) {
5877 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5880 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5881 WMI_PEER_CHAN_WIDTH, bw);
5883 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5884 sta->addr, bw, err);
5887 if (changed & IEEE80211_RC_NSS_CHANGED) {
5888 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5891 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5894 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5895 sta->addr, nss, err);
5898 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5899 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5902 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5903 WMI_PEER_SMPS_STATE, smps);
5905 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5906 sta->addr, smps, err);
5909 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5910 changed & IEEE80211_RC_NSS_CHANGED) {
5911 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
5914 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5916 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5920 mutex_unlock(&ar->conf_mutex);
5923 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5924 struct ieee80211_sta *sta)
5926 struct ath10k *ar = arvif->ar;
5928 lockdep_assert_held(&ar->conf_mutex);
5930 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5933 if (ar->num_stations >= ar->max_num_stations)
5941 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5942 struct ieee80211_sta *sta)
5944 struct ath10k *ar = arvif->ar;
5946 lockdep_assert_held(&ar->conf_mutex);
5948 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5954 struct ath10k_mac_tdls_iter_data {
5955 u32 num_tdls_stations;
5956 struct ieee80211_vif *curr_vif;
5959 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5960 struct ieee80211_sta *sta)
5962 struct ath10k_mac_tdls_iter_data *iter_data = data;
5963 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5964 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5966 if (sta->tdls && sta_vif == iter_data->curr_vif)
5967 iter_data->num_tdls_stations++;
5970 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5971 struct ieee80211_vif *vif)
5973 struct ath10k_mac_tdls_iter_data data = {};
5975 data.curr_vif = vif;
5977 ieee80211_iterate_stations_atomic(hw,
5978 ath10k_mac_tdls_vif_stations_count_iter,
5980 return data.num_tdls_stations;
5983 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5984 struct ieee80211_vif *vif)
5986 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5987 int *num_tdls_vifs = data;
5989 if (vif->type != NL80211_IFTYPE_STATION)
5992 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5996 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5998 int num_tdls_vifs = 0;
6000 ieee80211_iterate_active_interfaces_atomic(hw,
6001 IEEE80211_IFACE_ITER_NORMAL,
6002 ath10k_mac_tdls_vifs_count_iter,
6004 return num_tdls_vifs;
6007 static int ath10k_sta_state(struct ieee80211_hw *hw,
6008 struct ieee80211_vif *vif,
6009 struct ieee80211_sta *sta,
6010 enum ieee80211_sta_state old_state,
6011 enum ieee80211_sta_state new_state)
6013 struct ath10k *ar = hw->priv;
6014 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6015 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6016 struct ath10k_peer *peer;
6020 if (old_state == IEEE80211_STA_NOTEXIST &&
6021 new_state == IEEE80211_STA_NONE) {
6022 memset(arsta, 0, sizeof(*arsta));
6023 arsta->arvif = arvif;
6024 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6026 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6027 ath10k_mac_txq_init(sta->txq[i]);
6030 /* cancel must be done outside the mutex to avoid deadlock */
6031 if ((old_state == IEEE80211_STA_NONE &&
6032 new_state == IEEE80211_STA_NOTEXIST))
6033 cancel_work_sync(&arsta->update_wk);
6035 mutex_lock(&ar->conf_mutex);
6037 if (old_state == IEEE80211_STA_NOTEXIST &&
6038 new_state == IEEE80211_STA_NONE) {
6040 * New station addition.
6042 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6043 u32 num_tdls_stations;
6046 ath10k_dbg(ar, ATH10K_DBG_MAC,
6047 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6048 arvif->vdev_id, sta->addr,
6049 ar->num_stations + 1, ar->max_num_stations,
6050 ar->num_peers + 1, ar->max_num_peers);
6052 ret = ath10k_mac_inc_num_stations(arvif, sta);
6054 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6055 ar->max_num_stations);
6060 peer_type = WMI_PEER_TYPE_TDLS;
6062 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6063 sta->addr, peer_type);
6065 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6066 sta->addr, arvif->vdev_id, ret);
6067 ath10k_mac_dec_num_stations(arvif, sta);
6071 spin_lock_bh(&ar->data_lock);
6073 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6075 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6076 vif->addr, arvif->vdev_id);
6077 spin_unlock_bh(&ar->data_lock);
6078 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6079 ath10k_mac_dec_num_stations(arvif, sta);
6084 arsta->peer_id = find_first_bit(peer->peer_ids,
6085 ATH10K_MAX_NUM_PEER_IDS);
6087 spin_unlock_bh(&ar->data_lock);
6092 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6093 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6095 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
6096 num_tdls_stations == 0) {
6097 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6098 arvif->vdev_id, ar->max_num_tdls_vdevs);
6099 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6100 ath10k_mac_dec_num_stations(arvif, sta);
6105 if (num_tdls_stations == 0) {
6106 /* This is the first tdls peer in current vif */
6107 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
6109 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6112 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6113 arvif->vdev_id, ret);
6114 ath10k_peer_delete(ar, arvif->vdev_id,
6116 ath10k_mac_dec_num_stations(arvif, sta);
6121 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6122 WMI_TDLS_PEER_STATE_PEERING);
6125 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6126 sta->addr, arvif->vdev_id, ret);
6127 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6128 ath10k_mac_dec_num_stations(arvif, sta);
6130 if (num_tdls_stations != 0)
6132 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6135 } else if ((old_state == IEEE80211_STA_NONE &&
6136 new_state == IEEE80211_STA_NOTEXIST)) {
6138 * Existing station deletion.
6140 ath10k_dbg(ar, ATH10K_DBG_MAC,
6141 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6142 arvif->vdev_id, sta->addr, sta);
6144 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6146 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6147 sta->addr, arvif->vdev_id, ret);
6149 ath10k_mac_dec_num_stations(arvif, sta);
6151 spin_lock_bh(&ar->data_lock);
6152 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6153 peer = ar->peer_map[i];
6157 if (peer->sta == sta) {
6158 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6159 sta->addr, peer, i, arvif->vdev_id);
6162 /* Clean up the peer object as well since we
6163 * must have failed to do this above.
6165 list_del(&peer->list);
6166 ar->peer_map[i] = NULL;
6171 spin_unlock_bh(&ar->data_lock);
6173 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6174 ath10k_mac_txq_unref(ar, sta->txq[i]);
6179 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6182 /* This was the last tdls peer in current vif */
6183 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6186 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6187 arvif->vdev_id, ret);
6189 } else if (old_state == IEEE80211_STA_AUTH &&
6190 new_state == IEEE80211_STA_ASSOC &&
6191 (vif->type == NL80211_IFTYPE_AP ||
6192 vif->type == NL80211_IFTYPE_MESH_POINT ||
6193 vif->type == NL80211_IFTYPE_ADHOC)) {
6197 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6200 ret = ath10k_station_assoc(ar, vif, sta, false);
6202 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6203 sta->addr, arvif->vdev_id, ret);
6204 } else if (old_state == IEEE80211_STA_ASSOC &&
6205 new_state == IEEE80211_STA_AUTHORIZED &&
6208 * Tdls station authorized.
6210 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6213 ret = ath10k_station_assoc(ar, vif, sta, false);
6215 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6216 sta->addr, arvif->vdev_id, ret);
6220 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6221 WMI_TDLS_PEER_STATE_CONNECTED);
6223 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6224 sta->addr, arvif->vdev_id, ret);
6225 } else if (old_state == IEEE80211_STA_ASSOC &&
6226 new_state == IEEE80211_STA_AUTH &&
6227 (vif->type == NL80211_IFTYPE_AP ||
6228 vif->type == NL80211_IFTYPE_MESH_POINT ||
6229 vif->type == NL80211_IFTYPE_ADHOC)) {
6233 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6236 ret = ath10k_station_disassoc(ar, vif, sta);
6238 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6239 sta->addr, arvif->vdev_id, ret);
6242 mutex_unlock(&ar->conf_mutex);
6246 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6247 u16 ac, bool enable)
6249 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6250 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6251 u32 prio = 0, acc = 0;
6255 lockdep_assert_held(&ar->conf_mutex);
6257 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6261 case IEEE80211_AC_VO:
6262 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6263 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6267 case IEEE80211_AC_VI:
6268 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6269 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6273 case IEEE80211_AC_BE:
6274 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6275 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6279 case IEEE80211_AC_BK:
6280 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6281 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6288 arvif->u.sta.uapsd |= value;
6290 arvif->u.sta.uapsd &= ~value;
6292 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6293 WMI_STA_PS_PARAM_UAPSD,
6294 arvif->u.sta.uapsd);
6296 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6300 if (arvif->u.sta.uapsd)
6301 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6303 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6305 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6306 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6309 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6311 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6313 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6314 arvif->vdev_id, ret);
6318 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6320 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6321 arvif->vdev_id, ret);
6325 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6326 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6327 /* Only userspace can make an educated decision when to send
6328 * trigger frame. The following effectively disables u-UAPSD
6329 * autotrigger in firmware (which is enabled by default
6330 * provided the autotrigger service is available).
6334 arg.user_priority = prio;
6335 arg.service_interval = 0;
6336 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6337 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6339 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6340 arvif->bssid, &arg, 1);
6342 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6352 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6353 struct ieee80211_vif *vif, u16 ac,
6354 const struct ieee80211_tx_queue_params *params)
6356 struct ath10k *ar = hw->priv;
6357 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6358 struct wmi_wmm_params_arg *p = NULL;
6361 mutex_lock(&ar->conf_mutex);
6364 case IEEE80211_AC_VO:
6365 p = &arvif->wmm_params.ac_vo;
6367 case IEEE80211_AC_VI:
6368 p = &arvif->wmm_params.ac_vi;
6370 case IEEE80211_AC_BE:
6371 p = &arvif->wmm_params.ac_be;
6373 case IEEE80211_AC_BK:
6374 p = &arvif->wmm_params.ac_bk;
6383 p->cwmin = params->cw_min;
6384 p->cwmax = params->cw_max;
6385 p->aifs = params->aifs;
6388 * The channel time duration programmed in the HW is in absolute
6389 * microseconds, while mac80211 gives the txop in units of
6392 p->txop = params->txop * 32;
6394 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6395 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6396 &arvif->wmm_params);
6398 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6399 arvif->vdev_id, ret);
6403 /* This won't work well with multi-interface cases but it's
6404 * better than nothing.
6406 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6408 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6413 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6415 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6418 mutex_unlock(&ar->conf_mutex);
6422 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6424 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6425 struct ieee80211_vif *vif,
6426 struct ieee80211_channel *chan,
6428 enum ieee80211_roc_type type)
6430 struct ath10k *ar = hw->priv;
6431 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6432 struct wmi_start_scan_arg arg;
6436 mutex_lock(&ar->conf_mutex);
6438 spin_lock_bh(&ar->data_lock);
6439 switch (ar->scan.state) {
6440 case ATH10K_SCAN_IDLE:
6441 reinit_completion(&ar->scan.started);
6442 reinit_completion(&ar->scan.completed);
6443 reinit_completion(&ar->scan.on_channel);
6444 ar->scan.state = ATH10K_SCAN_STARTING;
6445 ar->scan.is_roc = true;
6446 ar->scan.vdev_id = arvif->vdev_id;
6447 ar->scan.roc_freq = chan->center_freq;
6448 ar->scan.roc_notify = true;
6451 case ATH10K_SCAN_STARTING:
6452 case ATH10K_SCAN_RUNNING:
6453 case ATH10K_SCAN_ABORTING:
6457 spin_unlock_bh(&ar->data_lock);
6462 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6464 memset(&arg, 0, sizeof(arg));
6465 ath10k_wmi_start_scan_init(ar, &arg);
6466 arg.vdev_id = arvif->vdev_id;
6467 arg.scan_id = ATH10K_SCAN_ID;
6469 arg.channels[0] = chan->center_freq;
6470 arg.dwell_time_active = scan_time_msec;
6471 arg.dwell_time_passive = scan_time_msec;
6472 arg.max_scan_time = scan_time_msec;
6473 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6474 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6475 arg.burst_duration_ms = duration;
6477 ret = ath10k_start_scan(ar, &arg);
6479 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6480 spin_lock_bh(&ar->data_lock);
6481 ar->scan.state = ATH10K_SCAN_IDLE;
6482 spin_unlock_bh(&ar->data_lock);
6486 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6488 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6490 ret = ath10k_scan_stop(ar);
6492 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6498 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6499 msecs_to_jiffies(duration));
6503 mutex_unlock(&ar->conf_mutex);
6507 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6509 struct ath10k *ar = hw->priv;
6511 mutex_lock(&ar->conf_mutex);
6513 spin_lock_bh(&ar->data_lock);
6514 ar->scan.roc_notify = false;
6515 spin_unlock_bh(&ar->data_lock);
6517 ath10k_scan_abort(ar);
6519 mutex_unlock(&ar->conf_mutex);
6521 cancel_delayed_work_sync(&ar->scan.timeout);
6527 * Both RTS and Fragmentation threshold are interface-specific
6528 * in ath10k, but device-specific in mac80211.
6531 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6533 struct ath10k *ar = hw->priv;
6534 struct ath10k_vif *arvif;
6537 mutex_lock(&ar->conf_mutex);
6538 list_for_each_entry(arvif, &ar->arvifs, list) {
6539 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6540 arvif->vdev_id, value);
6542 ret = ath10k_mac_set_rts(arvif, value);
6544 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6545 arvif->vdev_id, ret);
6549 mutex_unlock(&ar->conf_mutex);
6554 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6556 /* Even though there's a WMI enum for fragmentation threshold no known
6557 * firmware actually implements it. Moreover it is not possible to rely
6558 * frame fragmentation to mac80211 because firmware clears the "more
6559 * fragments" bit in frame control making it impossible for remote
6560 * devices to reassemble frames.
6562 * Hence implement a dummy callback just to say fragmentation isn't
6563 * supported. This effectively prevents mac80211 from doing frame
6564 * fragmentation in software.
6569 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6570 u32 queues, bool drop)
6572 struct ath10k *ar = hw->priv;
6576 /* mac80211 doesn't care if we really xmit queued frames or not
6577 * we'll collect those frames either way if we stop/delete vdevs */
6581 mutex_lock(&ar->conf_mutex);
6583 if (ar->state == ATH10K_STATE_WEDGED)
6586 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6589 spin_lock_bh(&ar->htt.tx_lock);
6590 empty = (ar->htt.num_pending_tx == 0);
6591 spin_unlock_bh(&ar->htt.tx_lock);
6593 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6594 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6598 }), ATH10K_FLUSH_TIMEOUT_HZ);
6600 if (time_left == 0 || skip)
6601 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6602 skip, ar->state, time_left);
6605 mutex_unlock(&ar->conf_mutex);
6608 /* TODO: Implement this function properly
6609 * For now it is needed to reply to Probe Requests in IBSS mode.
6610 * Propably we need this information from FW.
6612 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6617 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6618 enum ieee80211_reconfig_type reconfig_type)
6620 struct ath10k *ar = hw->priv;
6622 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6625 mutex_lock(&ar->conf_mutex);
6627 /* If device failed to restart it will be in a different state, e.g.
6628 * ATH10K_STATE_WEDGED */
6629 if (ar->state == ATH10K_STATE_RESTARTED) {
6630 ath10k_info(ar, "device successfully recovered\n");
6631 ar->state = ATH10K_STATE_ON;
6632 ieee80211_wake_queues(ar->hw);
6635 mutex_unlock(&ar->conf_mutex);
6639 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6640 struct ieee80211_channel *channel)
6643 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6645 lockdep_assert_held(&ar->conf_mutex);
6647 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6648 (ar->rx_channel != channel))
6651 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6652 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6656 reinit_completion(&ar->bss_survey_done);
6658 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6660 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6664 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6666 ath10k_warn(ar, "bss channel survey timed out\n");
6671 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6672 struct survey_info *survey)
6674 struct ath10k *ar = hw->priv;
6675 struct ieee80211_supported_band *sband;
6676 struct survey_info *ar_survey = &ar->survey[idx];
6679 mutex_lock(&ar->conf_mutex);
6681 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6682 if (sband && idx >= sband->n_channels) {
6683 idx -= sband->n_channels;
6688 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6690 if (!sband || idx >= sband->n_channels) {
6695 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6697 spin_lock_bh(&ar->data_lock);
6698 memcpy(survey, ar_survey, sizeof(*survey));
6699 spin_unlock_bh(&ar->data_lock);
6701 survey->channel = &sband->channels[idx];
6703 if (ar->rx_channel == survey->channel)
6704 survey->filled |= SURVEY_INFO_IN_USE;
6707 mutex_unlock(&ar->conf_mutex);
6712 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6713 enum nl80211_band band,
6714 const struct cfg80211_bitrate_mask *mask)
6719 num_rates += hweight32(mask->control[band].legacy);
6721 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6722 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6724 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6725 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6727 return num_rates == 1;
6731 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6732 enum nl80211_band band,
6733 const struct cfg80211_bitrate_mask *mask,
6736 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6737 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6739 u8 vht_nss_mask = 0;
6742 if (mask->control[band].legacy)
6745 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6746 if (mask->control[band].ht_mcs[i] == 0)
6748 else if (mask->control[band].ht_mcs[i] ==
6749 sband->ht_cap.mcs.rx_mask[i])
6750 ht_nss_mask |= BIT(i);
6755 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6756 if (mask->control[band].vht_mcs[i] == 0)
6758 else if (mask->control[band].vht_mcs[i] ==
6759 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6760 vht_nss_mask |= BIT(i);
6765 if (ht_nss_mask != vht_nss_mask)
6768 if (ht_nss_mask == 0)
6771 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6774 *nss = fls(ht_nss_mask);
6780 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6781 enum nl80211_band band,
6782 const struct cfg80211_bitrate_mask *mask,
6785 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6792 if (hweight32(mask->control[band].legacy) == 1) {
6793 rate_idx = ffs(mask->control[band].legacy) - 1;
6795 hw_rate = sband->bitrates[rate_idx].hw_value;
6796 bitrate = sband->bitrates[rate_idx].bitrate;
6798 if (ath10k_mac_bitrate_is_cck(bitrate))
6799 preamble = WMI_RATE_PREAMBLE_CCK;
6801 preamble = WMI_RATE_PREAMBLE_OFDM;
6804 *rate = preamble << 6 |
6811 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6812 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6814 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6816 (ffs(mask->control[band].ht_mcs[i]) - 1);
6822 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6823 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6825 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6827 (ffs(mask->control[band].vht_mcs[i]) - 1);
6836 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6837 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6839 struct ath10k *ar = arvif->ar;
6843 lockdep_assert_held(&ar->conf_mutex);
6845 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6846 arvif->vdev_id, rate, nss, sgi);
6848 vdev_param = ar->wmi.vdev_param->fixed_rate;
6849 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6851 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6856 vdev_param = ar->wmi.vdev_param->nss;
6857 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6859 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6863 vdev_param = ar->wmi.vdev_param->sgi;
6864 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6866 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6870 vdev_param = ar->wmi.vdev_param->ldpc;
6871 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6873 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6881 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6882 enum nl80211_band band,
6883 const struct cfg80211_bitrate_mask *mask)
6888 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6889 * to express all VHT MCS rate masks. Effectively only the following
6890 * ranges can be used: none, 0-7, 0-8 and 0-9.
6892 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6893 vht_mcs = mask->control[band].vht_mcs[i];
6902 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6910 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6911 struct ieee80211_sta *sta)
6913 struct ath10k_vif *arvif = data;
6914 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6915 struct ath10k *ar = arvif->ar;
6917 if (arsta->arvif != arvif)
6920 spin_lock_bh(&ar->data_lock);
6921 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6922 spin_unlock_bh(&ar->data_lock);
6924 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6927 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6928 struct ieee80211_vif *vif,
6929 const struct cfg80211_bitrate_mask *mask)
6931 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6932 struct cfg80211_chan_def def;
6933 struct ath10k *ar = arvif->ar;
6934 enum nl80211_band band;
6935 const u8 *ht_mcs_mask;
6936 const u16 *vht_mcs_mask;
6944 if (ath10k_mac_vif_chan(vif, &def))
6947 band = def.chan->band;
6948 ht_mcs_mask = mask->control[band].ht_mcs;
6949 vht_mcs_mask = mask->control[band].vht_mcs;
6950 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6952 sgi = mask->control[band].gi;
6953 if (sgi == NL80211_TXRATE_FORCE_LGI)
6956 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6957 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6960 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6961 arvif->vdev_id, ret);
6964 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6966 rate = WMI_FIXED_RATE_NONE;
6969 rate = WMI_FIXED_RATE_NONE;
6970 nss = min(ar->num_rf_chains,
6971 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6972 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6974 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6977 mutex_lock(&ar->conf_mutex);
6979 arvif->bitrate_mask = *mask;
6980 ieee80211_iterate_stations_atomic(ar->hw,
6981 ath10k_mac_set_bitrate_mask_iter,
6984 mutex_unlock(&ar->conf_mutex);
6987 mutex_lock(&ar->conf_mutex);
6989 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6991 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6992 arvif->vdev_id, ret);
6997 mutex_unlock(&ar->conf_mutex);
7002 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7003 struct ieee80211_vif *vif,
7004 struct ieee80211_sta *sta,
7007 struct ath10k *ar = hw->priv;
7008 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7011 spin_lock_bh(&ar->data_lock);
7013 ath10k_dbg(ar, ATH10K_DBG_MAC,
7014 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7015 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7018 if (changed & IEEE80211_RC_BW_CHANGED) {
7019 bw = WMI_PEER_CHWIDTH_20MHZ;
7021 switch (sta->bandwidth) {
7022 case IEEE80211_STA_RX_BW_20:
7023 bw = WMI_PEER_CHWIDTH_20MHZ;
7025 case IEEE80211_STA_RX_BW_40:
7026 bw = WMI_PEER_CHWIDTH_40MHZ;
7028 case IEEE80211_STA_RX_BW_80:
7029 bw = WMI_PEER_CHWIDTH_80MHZ;
7031 case IEEE80211_STA_RX_BW_160:
7032 bw = WMI_PEER_CHWIDTH_160MHZ;
7035 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7036 sta->bandwidth, sta->addr);
7037 bw = WMI_PEER_CHWIDTH_20MHZ;
7044 if (changed & IEEE80211_RC_NSS_CHANGED)
7045 arsta->nss = sta->rx_nss;
7047 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7048 smps = WMI_PEER_SMPS_PS_NONE;
7050 switch (sta->smps_mode) {
7051 case IEEE80211_SMPS_AUTOMATIC:
7052 case IEEE80211_SMPS_OFF:
7053 smps = WMI_PEER_SMPS_PS_NONE;
7055 case IEEE80211_SMPS_STATIC:
7056 smps = WMI_PEER_SMPS_STATIC;
7058 case IEEE80211_SMPS_DYNAMIC:
7059 smps = WMI_PEER_SMPS_DYNAMIC;
7061 case IEEE80211_SMPS_NUM_MODES:
7062 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7063 sta->smps_mode, sta->addr);
7064 smps = WMI_PEER_SMPS_PS_NONE;
7071 arsta->changed |= changed;
7073 spin_unlock_bh(&ar->data_lock);
7075 ieee80211_queue_work(hw, &arsta->update_wk);
7078 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7079 struct ieee80211_vif *vif, s64 tsf_offset)
7081 struct ath10k *ar = hw->priv;
7082 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7083 u32 offset, vdev_param;
7086 if (tsf_offset < 0) {
7087 vdev_param = ar->wmi.vdev_param->dec_tsf;
7088 offset = -tsf_offset;
7090 vdev_param = ar->wmi.vdev_param->inc_tsf;
7091 offset = tsf_offset;
7094 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7095 vdev_param, offset);
7097 if (ret && ret != -EOPNOTSUPP)
7098 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7099 offset, vdev_param, ret);
7102 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7103 struct ieee80211_vif *vif,
7104 struct ieee80211_ampdu_params *params)
7106 struct ath10k *ar = hw->priv;
7107 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7108 struct ieee80211_sta *sta = params->sta;
7109 enum ieee80211_ampdu_mlme_action action = params->action;
7110 u16 tid = params->tid;
7112 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7113 arvif->vdev_id, sta->addr, tid, action);
7116 case IEEE80211_AMPDU_RX_START:
7117 case IEEE80211_AMPDU_RX_STOP:
7118 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7119 * creation/removal. Do we need to verify this?
7122 case IEEE80211_AMPDU_TX_START:
7123 case IEEE80211_AMPDU_TX_STOP_CONT:
7124 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7125 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7126 case IEEE80211_AMPDU_TX_OPERATIONAL:
7127 /* Firmware offloads Tx aggregation entirely so deny mac80211
7128 * Tx aggregation requests.
7137 ath10k_mac_update_rx_channel(struct ath10k *ar,
7138 struct ieee80211_chanctx_conf *ctx,
7139 struct ieee80211_vif_chanctx_switch *vifs,
7142 struct cfg80211_chan_def *def = NULL;
7144 /* Both locks are required because ar->rx_channel is modified. This
7145 * allows readers to hold either lock.
7147 lockdep_assert_held(&ar->conf_mutex);
7148 lockdep_assert_held(&ar->data_lock);
7150 WARN_ON(ctx && vifs);
7151 WARN_ON(vifs && !n_vifs);
7153 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7154 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7155 * ppdu on Rx may reduce performance on low-end systems. It should be
7156 * possible to make tables/hashmaps to speed the lookup up (be vary of
7157 * cpu data cache lines though regarding sizes) but to keep the initial
7158 * implementation simple and less intrusive fallback to the slow lookup
7159 * only for multi-channel cases. Single-channel cases will remain to
7160 * use the old channel derival and thus performance should not be
7164 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7165 ieee80211_iter_chan_contexts_atomic(ar->hw,
7166 ath10k_mac_get_any_chandef_iter,
7170 def = &vifs[0].new_ctx->def;
7172 ar->rx_channel = def->chan;
7173 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7174 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7175 /* During driver restart due to firmware assert, since mac80211
7176 * already has valid channel context for given radio, channel
7177 * context iteration return num_chanctx > 0. So fix rx_channel
7178 * when restart is in progress.
7180 ar->rx_channel = ctx->def.chan;
7182 ar->rx_channel = NULL;
7188 ath10k_mac_update_vif_chan(struct ath10k *ar,
7189 struct ieee80211_vif_chanctx_switch *vifs,
7192 struct ath10k_vif *arvif;
7196 lockdep_assert_held(&ar->conf_mutex);
7198 /* First stop monitor interface. Some FW versions crash if there's a
7199 * lone monitor interface.
7201 if (ar->monitor_started)
7202 ath10k_monitor_stop(ar);
7204 for (i = 0; i < n_vifs; i++) {
7205 arvif = (void *)vifs[i].vif->drv_priv;
7207 ath10k_dbg(ar, ATH10K_DBG_MAC,
7208 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7210 vifs[i].old_ctx->def.chan->center_freq,
7211 vifs[i].new_ctx->def.chan->center_freq,
7212 vifs[i].old_ctx->def.width,
7213 vifs[i].new_ctx->def.width);
7215 if (WARN_ON(!arvif->is_started))
7218 if (WARN_ON(!arvif->is_up))
7221 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7223 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7224 arvif->vdev_id, ret);
7229 /* All relevant vdevs are downed and associated channel resources
7230 * should be available for the channel switch now.
7233 spin_lock_bh(&ar->data_lock);
7234 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7235 spin_unlock_bh(&ar->data_lock);
7237 for (i = 0; i < n_vifs; i++) {
7238 arvif = (void *)vifs[i].vif->drv_priv;
7240 if (WARN_ON(!arvif->is_started))
7243 if (WARN_ON(!arvif->is_up))
7246 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7248 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7251 ret = ath10k_mac_setup_prb_tmpl(arvif);
7253 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7256 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7258 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7259 arvif->vdev_id, ret);
7263 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7266 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7267 arvif->vdev_id, ret);
7272 ath10k_monitor_recalc(ar);
7276 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7277 struct ieee80211_chanctx_conf *ctx)
7279 struct ath10k *ar = hw->priv;
7281 ath10k_dbg(ar, ATH10K_DBG_MAC,
7282 "mac chanctx add freq %hu width %d ptr %pK\n",
7283 ctx->def.chan->center_freq, ctx->def.width, ctx);
7285 mutex_lock(&ar->conf_mutex);
7287 spin_lock_bh(&ar->data_lock);
7288 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7289 spin_unlock_bh(&ar->data_lock);
7291 ath10k_recalc_radar_detection(ar);
7292 ath10k_monitor_recalc(ar);
7294 mutex_unlock(&ar->conf_mutex);
7300 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7301 struct ieee80211_chanctx_conf *ctx)
7303 struct ath10k *ar = hw->priv;
7305 ath10k_dbg(ar, ATH10K_DBG_MAC,
7306 "mac chanctx remove freq %hu width %d ptr %pK\n",
7307 ctx->def.chan->center_freq, ctx->def.width, ctx);
7309 mutex_lock(&ar->conf_mutex);
7311 spin_lock_bh(&ar->data_lock);
7312 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7313 spin_unlock_bh(&ar->data_lock);
7315 ath10k_recalc_radar_detection(ar);
7316 ath10k_monitor_recalc(ar);
7318 mutex_unlock(&ar->conf_mutex);
7321 struct ath10k_mac_change_chanctx_arg {
7322 struct ieee80211_chanctx_conf *ctx;
7323 struct ieee80211_vif_chanctx_switch *vifs;
7329 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7330 struct ieee80211_vif *vif)
7332 struct ath10k_mac_change_chanctx_arg *arg = data;
7334 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7341 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7342 struct ieee80211_vif *vif)
7344 struct ath10k_mac_change_chanctx_arg *arg = data;
7345 struct ieee80211_chanctx_conf *ctx;
7347 ctx = rcu_access_pointer(vif->chanctx_conf);
7348 if (ctx != arg->ctx)
7351 if (WARN_ON(arg->next_vif == arg->n_vifs))
7354 arg->vifs[arg->next_vif].vif = vif;
7355 arg->vifs[arg->next_vif].old_ctx = ctx;
7356 arg->vifs[arg->next_vif].new_ctx = ctx;
7361 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7362 struct ieee80211_chanctx_conf *ctx,
7365 struct ath10k *ar = hw->priv;
7366 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7368 mutex_lock(&ar->conf_mutex);
7370 ath10k_dbg(ar, ATH10K_DBG_MAC,
7371 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7372 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7374 /* This shouldn't really happen because channel switching should use
7375 * switch_vif_chanctx().
7377 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7380 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7381 ieee80211_iterate_active_interfaces_atomic(
7383 IEEE80211_IFACE_ITER_NORMAL,
7384 ath10k_mac_change_chanctx_cnt_iter,
7386 if (arg.n_vifs == 0)
7389 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7394 ieee80211_iterate_active_interfaces_atomic(
7396 IEEE80211_IFACE_ITER_NORMAL,
7397 ath10k_mac_change_chanctx_fill_iter,
7399 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7404 ath10k_recalc_radar_detection(ar);
7406 /* FIXME: How to configure Rx chains properly? */
7408 /* No other actions are actually necessary. Firmware maintains channel
7409 * definitions per vdev internally and there's no host-side channel
7410 * context abstraction to configure, e.g. channel width.
7414 mutex_unlock(&ar->conf_mutex);
7418 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7419 struct ieee80211_vif *vif,
7420 struct ieee80211_chanctx_conf *ctx)
7422 struct ath10k *ar = hw->priv;
7423 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7426 mutex_lock(&ar->conf_mutex);
7428 ath10k_dbg(ar, ATH10K_DBG_MAC,
7429 "mac chanctx assign ptr %pK vdev_id %i\n",
7430 ctx, arvif->vdev_id);
7432 if (WARN_ON(arvif->is_started)) {
7433 mutex_unlock(&ar->conf_mutex);
7437 ret = ath10k_vdev_start(arvif, &ctx->def);
7439 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7440 arvif->vdev_id, vif->addr,
7441 ctx->def.chan->center_freq, ret);
7445 arvif->is_started = true;
7447 ret = ath10k_mac_vif_setup_ps(arvif);
7449 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7450 arvif->vdev_id, ret);
7454 if (vif->type == NL80211_IFTYPE_MONITOR) {
7455 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7457 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7458 arvif->vdev_id, ret);
7462 arvif->is_up = true;
7465 if (ath10k_mac_can_set_cts_prot(arvif)) {
7466 ret = ath10k_mac_set_cts_prot(arvif);
7468 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7469 arvif->vdev_id, ret);
7472 mutex_unlock(&ar->conf_mutex);
7476 ath10k_vdev_stop(arvif);
7477 arvif->is_started = false;
7478 ath10k_mac_vif_setup_ps(arvif);
7481 mutex_unlock(&ar->conf_mutex);
7486 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7487 struct ieee80211_vif *vif,
7488 struct ieee80211_chanctx_conf *ctx)
7490 struct ath10k *ar = hw->priv;
7491 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7494 mutex_lock(&ar->conf_mutex);
7496 ath10k_dbg(ar, ATH10K_DBG_MAC,
7497 "mac chanctx unassign ptr %pK vdev_id %i\n",
7498 ctx, arvif->vdev_id);
7500 WARN_ON(!arvif->is_started);
7502 if (vif->type == NL80211_IFTYPE_MONITOR) {
7503 WARN_ON(!arvif->is_up);
7505 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7507 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7508 arvif->vdev_id, ret);
7510 arvif->is_up = false;
7513 ret = ath10k_vdev_stop(arvif);
7515 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7516 arvif->vdev_id, ret);
7518 arvif->is_started = false;
7520 mutex_unlock(&ar->conf_mutex);
7524 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7525 struct ieee80211_vif_chanctx_switch *vifs,
7527 enum ieee80211_chanctx_switch_mode mode)
7529 struct ath10k *ar = hw->priv;
7531 mutex_lock(&ar->conf_mutex);
7533 ath10k_dbg(ar, ATH10K_DBG_MAC,
7534 "mac chanctx switch n_vifs %d mode %d\n",
7536 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7538 mutex_unlock(&ar->conf_mutex);
7542 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7543 struct ieee80211_vif *vif,
7544 struct ieee80211_sta *sta)
7547 struct ath10k_peer *peer;
7551 list_for_each_entry(peer, &ar->peers, list)
7552 if (peer->sta == sta)
7553 peer->removed = true;
7556 static const struct ieee80211_ops ath10k_ops = {
7557 .tx = ath10k_mac_op_tx,
7558 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7559 .start = ath10k_start,
7560 .stop = ath10k_stop,
7561 .config = ath10k_config,
7562 .add_interface = ath10k_add_interface,
7563 .remove_interface = ath10k_remove_interface,
7564 .configure_filter = ath10k_configure_filter,
7565 .bss_info_changed = ath10k_bss_info_changed,
7566 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7567 .hw_scan = ath10k_hw_scan,
7568 .cancel_hw_scan = ath10k_cancel_hw_scan,
7569 .set_key = ath10k_set_key,
7570 .set_default_unicast_key = ath10k_set_default_unicast_key,
7571 .sta_state = ath10k_sta_state,
7572 .conf_tx = ath10k_conf_tx,
7573 .remain_on_channel = ath10k_remain_on_channel,
7574 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7575 .set_rts_threshold = ath10k_set_rts_threshold,
7576 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7577 .flush = ath10k_flush,
7578 .tx_last_beacon = ath10k_tx_last_beacon,
7579 .set_antenna = ath10k_set_antenna,
7580 .get_antenna = ath10k_get_antenna,
7581 .reconfig_complete = ath10k_reconfig_complete,
7582 .get_survey = ath10k_get_survey,
7583 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7584 .sta_rc_update = ath10k_sta_rc_update,
7585 .offset_tsf = ath10k_offset_tsf,
7586 .ampdu_action = ath10k_ampdu_action,
7587 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7588 .get_et_stats = ath10k_debug_get_et_stats,
7589 .get_et_strings = ath10k_debug_get_et_strings,
7590 .add_chanctx = ath10k_mac_op_add_chanctx,
7591 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7592 .change_chanctx = ath10k_mac_op_change_chanctx,
7593 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7594 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7595 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7596 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7598 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7601 .suspend = ath10k_wow_op_suspend,
7602 .resume = ath10k_wow_op_resume,
7604 #ifdef CONFIG_MAC80211_DEBUGFS
7605 .sta_add_debugfs = ath10k_sta_add_debugfs,
7606 .sta_statistics = ath10k_sta_statistics,
7610 #define CHAN2G(_channel, _freq, _flags) { \
7611 .band = NL80211_BAND_2GHZ, \
7612 .hw_value = (_channel), \
7613 .center_freq = (_freq), \
7614 .flags = (_flags), \
7615 .max_antenna_gain = 0, \
7619 #define CHAN5G(_channel, _freq, _flags) { \
7620 .band = NL80211_BAND_5GHZ, \
7621 .hw_value = (_channel), \
7622 .center_freq = (_freq), \
7623 .flags = (_flags), \
7624 .max_antenna_gain = 0, \
7628 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7638 CHAN2G(10, 2457, 0),
7639 CHAN2G(11, 2462, 0),
7640 CHAN2G(12, 2467, 0),
7641 CHAN2G(13, 2472, 0),
7642 CHAN2G(14, 2484, 0),
7645 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7646 CHAN5G(36, 5180, 0),
7647 CHAN5G(40, 5200, 0),
7648 CHAN5G(44, 5220, 0),
7649 CHAN5G(48, 5240, 0),
7650 CHAN5G(52, 5260, 0),
7651 CHAN5G(56, 5280, 0),
7652 CHAN5G(60, 5300, 0),
7653 CHAN5G(64, 5320, 0),
7654 CHAN5G(100, 5500, 0),
7655 CHAN5G(104, 5520, 0),
7656 CHAN5G(108, 5540, 0),
7657 CHAN5G(112, 5560, 0),
7658 CHAN5G(116, 5580, 0),
7659 CHAN5G(120, 5600, 0),
7660 CHAN5G(124, 5620, 0),
7661 CHAN5G(128, 5640, 0),
7662 CHAN5G(132, 5660, 0),
7663 CHAN5G(136, 5680, 0),
7664 CHAN5G(140, 5700, 0),
7665 CHAN5G(144, 5720, 0),
7666 CHAN5G(149, 5745, 0),
7667 CHAN5G(153, 5765, 0),
7668 CHAN5G(157, 5785, 0),
7669 CHAN5G(161, 5805, 0),
7670 CHAN5G(165, 5825, 0),
7671 CHAN5G(169, 5845, 0),
7674 struct ath10k *ath10k_mac_create(size_t priv_size)
7676 struct ieee80211_hw *hw;
7677 struct ieee80211_ops *ops;
7680 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7684 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7697 void ath10k_mac_destroy(struct ath10k *ar)
7699 struct ieee80211_ops *ops = ar->ops;
7701 ieee80211_free_hw(ar->hw);
7705 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7708 .types = BIT(NL80211_IFTYPE_STATION)
7709 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7713 .types = BIT(NL80211_IFTYPE_P2P_GO)
7717 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7721 .types = BIT(NL80211_IFTYPE_AP)
7722 #ifdef CONFIG_MAC80211_MESH
7723 | BIT(NL80211_IFTYPE_MESH_POINT)
7728 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7731 .types = BIT(NL80211_IFTYPE_AP)
7732 #ifdef CONFIG_MAC80211_MESH
7733 | BIT(NL80211_IFTYPE_MESH_POINT)
7738 .types = BIT(NL80211_IFTYPE_STATION)
7742 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7744 .limits = ath10k_if_limits,
7745 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7746 .max_interfaces = 8,
7747 .num_different_channels = 1,
7748 .beacon_int_infra_match = true,
7752 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7754 .limits = ath10k_10x_if_limits,
7755 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7756 .max_interfaces = 8,
7757 .num_different_channels = 1,
7758 .beacon_int_infra_match = true,
7759 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7760 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7761 BIT(NL80211_CHAN_WIDTH_20) |
7762 BIT(NL80211_CHAN_WIDTH_40) |
7763 BIT(NL80211_CHAN_WIDTH_80),
7768 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7771 .types = BIT(NL80211_IFTYPE_STATION),
7775 .types = BIT(NL80211_IFTYPE_AP) |
7776 #ifdef CONFIG_MAC80211_MESH
7777 BIT(NL80211_IFTYPE_MESH_POINT) |
7779 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7780 BIT(NL80211_IFTYPE_P2P_GO),
7784 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7788 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7791 .types = BIT(NL80211_IFTYPE_STATION),
7795 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7799 .types = BIT(NL80211_IFTYPE_AP) |
7800 #ifdef CONFIG_MAC80211_MESH
7801 BIT(NL80211_IFTYPE_MESH_POINT) |
7803 BIT(NL80211_IFTYPE_P2P_GO),
7807 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7811 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7814 .types = BIT(NL80211_IFTYPE_STATION),
7818 .types = BIT(NL80211_IFTYPE_ADHOC),
7822 /* FIXME: This is not thouroughly tested. These combinations may over- or
7823 * underestimate hw/fw capabilities.
7825 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7827 .limits = ath10k_tlv_if_limit,
7828 .num_different_channels = 1,
7829 .max_interfaces = 4,
7830 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7833 .limits = ath10k_tlv_if_limit_ibss,
7834 .num_different_channels = 1,
7835 .max_interfaces = 2,
7836 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7840 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7842 .limits = ath10k_tlv_if_limit,
7843 .num_different_channels = 1,
7844 .max_interfaces = 4,
7845 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7848 .limits = ath10k_tlv_qcs_if_limit,
7849 .num_different_channels = 2,
7850 .max_interfaces = 4,
7851 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7854 .limits = ath10k_tlv_if_limit_ibss,
7855 .num_different_channels = 1,
7856 .max_interfaces = 2,
7857 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7861 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7864 .types = BIT(NL80211_IFTYPE_STATION),
7868 .types = BIT(NL80211_IFTYPE_AP)
7869 #ifdef CONFIG_MAC80211_MESH
7870 | BIT(NL80211_IFTYPE_MESH_POINT)
7875 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7877 .limits = ath10k_10_4_if_limits,
7878 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7879 .max_interfaces = 16,
7880 .num_different_channels = 1,
7881 .beacon_int_infra_match = true,
7882 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7883 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7884 BIT(NL80211_CHAN_WIDTH_20) |
7885 BIT(NL80211_CHAN_WIDTH_40) |
7886 BIT(NL80211_CHAN_WIDTH_80),
7891 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7892 struct ieee80211_vif *vif)
7894 struct ath10k_vif_iter *arvif_iter = data;
7895 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7897 if (arvif->vdev_id == arvif_iter->vdev_id)
7898 arvif_iter->arvif = arvif;
7901 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7903 struct ath10k_vif_iter arvif_iter;
7906 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7907 arvif_iter.vdev_id = vdev_id;
7909 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7910 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7912 ath10k_get_arvif_iter,
7914 if (!arvif_iter.arvif) {
7915 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7919 return arvif_iter.arvif;
7922 #define WRD_METHOD "WRDD"
7923 #define WRDD_WIFI (0x07)
7925 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
7927 union acpi_object *mcc_pkg;
7928 union acpi_object *domain_type;
7929 union acpi_object *mcc_value;
7932 if (wrdd->type != ACPI_TYPE_PACKAGE ||
7933 wrdd->package.count < 2 ||
7934 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
7935 wrdd->package.elements[0].integer.value != 0) {
7936 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
7940 for (i = 1; i < wrdd->package.count; ++i) {
7941 mcc_pkg = &wrdd->package.elements[i];
7943 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
7945 if (mcc_pkg->package.count < 2)
7947 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
7948 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
7951 domain_type = &mcc_pkg->package.elements[0];
7952 if (domain_type->integer.value != WRDD_WIFI)
7955 mcc_value = &mcc_pkg->package.elements[1];
7956 return mcc_value->integer.value;
7961 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
7963 struct pci_dev __maybe_unused *pdev = to_pci_dev(ar->dev);
7964 acpi_handle root_handle;
7966 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
7971 root_handle = ACPI_HANDLE(&pdev->dev);
7975 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
7976 if (ACPI_FAILURE(status)) {
7977 ath10k_dbg(ar, ATH10K_DBG_BOOT,
7978 "failed to get wrd method %d\n", status);
7982 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
7983 if (ACPI_FAILURE(status)) {
7984 ath10k_dbg(ar, ATH10K_DBG_BOOT,
7985 "failed to call wrdc %d\n", status);
7989 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
7990 kfree(wrdd.pointer);
7994 alpha2[0] = (alpha2_code >> 8) & 0xff;
7995 alpha2[1] = (alpha2_code >> 0) & 0xff;
7998 ath10k_dbg(ar, ATH10K_DBG_BOOT,
7999 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8001 *rd = ath_regd_find_country_by_name(alpha2);
8005 *rd |= COUNTRY_ERD_FLAG;
8009 static int ath10k_mac_init_rd(struct ath10k *ar)
8014 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8016 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8017 "fallback to eeprom programmed regulatory settings\n");
8018 rd = ar->hw_eeprom_rd;
8021 ar->ath_common.regulatory.current_rd = rd;
8025 int ath10k_mac_register(struct ath10k *ar)
8027 static const u32 cipher_suites[] = {
8028 WLAN_CIPHER_SUITE_WEP40,
8029 WLAN_CIPHER_SUITE_WEP104,
8030 WLAN_CIPHER_SUITE_TKIP,
8031 WLAN_CIPHER_SUITE_CCMP,
8032 WLAN_CIPHER_SUITE_AES_CMAC,
8034 struct ieee80211_supported_band *band;
8038 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8040 SET_IEEE80211_DEV(ar->hw, ar->dev);
8042 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8043 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8046 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8047 channels = kmemdup(ath10k_2ghz_channels,
8048 sizeof(ath10k_2ghz_channels),
8055 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8056 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8057 band->channels = channels;
8059 if (ar->hw_params.cck_rate_map_rev2) {
8060 band->n_bitrates = ath10k_g_rates_rev2_size;
8061 band->bitrates = ath10k_g_rates_rev2;
8063 band->n_bitrates = ath10k_g_rates_size;
8064 band->bitrates = ath10k_g_rates;
8067 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8070 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8071 channels = kmemdup(ath10k_5ghz_channels,
8072 sizeof(ath10k_5ghz_channels),
8079 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8080 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8081 band->channels = channels;
8082 band->n_bitrates = ath10k_a_rates_size;
8083 band->bitrates = ath10k_a_rates;
8084 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8087 ath10k_mac_setup_ht_vht_cap(ar);
8089 ar->hw->wiphy->interface_modes =
8090 BIT(NL80211_IFTYPE_STATION) |
8091 BIT(NL80211_IFTYPE_AP) |
8092 BIT(NL80211_IFTYPE_MESH_POINT);
8094 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8095 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8097 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8098 ar->hw->wiphy->interface_modes |=
8099 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8100 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8101 BIT(NL80211_IFTYPE_P2P_GO);
8103 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8104 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8105 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8106 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8107 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8108 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8109 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8110 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8111 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8112 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8113 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8114 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8115 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8116 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8117 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8118 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8120 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8121 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8123 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8124 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8126 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8127 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8129 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8130 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8131 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8134 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8135 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8137 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8138 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8139 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8141 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8143 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8144 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8146 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8147 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8148 * correct Probe Responses. This is more of a hack advert..
8150 ar->hw->wiphy->probe_resp_offload |=
8151 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8152 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8153 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8156 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
8157 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8159 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8160 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8161 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8163 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8164 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8165 NL80211_FEATURE_AP_SCAN;
8167 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8169 ret = ath10k_wow_init(ar);
8171 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8175 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8178 * on LL hardware queues are managed entirely by the FW
8179 * so we only advertise to mac we can do the queues thing
8181 ar->hw->queues = IEEE80211_MAX_QUEUES;
8183 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8184 * something that vdev_ids can't reach so that we don't stop the queue
8187 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8189 switch (ar->running_fw->fw_file.wmi_op_version) {
8190 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8191 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8192 ar->hw->wiphy->n_iface_combinations =
8193 ARRAY_SIZE(ath10k_if_comb);
8194 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8196 case ATH10K_FW_WMI_OP_VERSION_TLV:
8197 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8198 ar->hw->wiphy->iface_combinations =
8199 ath10k_tlv_qcs_if_comb;
8200 ar->hw->wiphy->n_iface_combinations =
8201 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8203 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8204 ar->hw->wiphy->n_iface_combinations =
8205 ARRAY_SIZE(ath10k_tlv_if_comb);
8207 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8209 case ATH10K_FW_WMI_OP_VERSION_10_1:
8210 case ATH10K_FW_WMI_OP_VERSION_10_2:
8211 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8212 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8213 ar->hw->wiphy->n_iface_combinations =
8214 ARRAY_SIZE(ath10k_10x_if_comb);
8216 case ATH10K_FW_WMI_OP_VERSION_10_4:
8217 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8218 ar->hw->wiphy->n_iface_combinations =
8219 ARRAY_SIZE(ath10k_10_4_if_comb);
8221 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8222 case ATH10K_FW_WMI_OP_VERSION_MAX:
8228 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8229 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8231 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8232 /* Init ath dfs pattern detector */
8233 ar->ath_common.debug_mask = ATH_DBG_DFS;
8234 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8237 if (!ar->dfs_detector)
8238 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8241 /* Current wake_tx_queue implementation imposes a significant
8242 * performance penalty in some setups. The tx scheduling code needs
8243 * more work anyway so disable the wake_tx_queue unless firmware
8244 * supports the pull-push mechanism.
8246 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8247 ar->running_fw->fw_file.fw_features))
8248 ar->ops->wake_tx_queue = NULL;
8250 ret = ath10k_mac_init_rd(ar);
8252 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8253 goto err_dfs_detector_exit;
8256 /* Disable set_coverage_class for chipsets that do not support it. */
8257 if (!ar->hw_params.hw_ops->set_coverage_class)
8258 ar->ops->set_coverage_class = NULL;
8260 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8261 ath10k_reg_notifier);
8263 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8264 goto err_dfs_detector_exit;
8267 ar->hw->wiphy->cipher_suites = cipher_suites;
8268 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8270 ret = ieee80211_register_hw(ar->hw);
8272 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8273 goto err_dfs_detector_exit;
8276 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8277 ret = regulatory_hint(ar->hw->wiphy,
8278 ar->ath_common.regulatory.alpha2);
8280 goto err_unregister;
8286 ieee80211_unregister_hw(ar->hw);
8288 err_dfs_detector_exit:
8289 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8290 ar->dfs_detector->exit(ar->dfs_detector);
8293 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8294 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8296 SET_IEEE80211_DEV(ar->hw, NULL);
8300 void ath10k_mac_unregister(struct ath10k *ar)
8302 ieee80211_unregister_hw(ar->hw);
8304 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8305 ar->dfs_detector->exit(ar->dfs_detector);
8307 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8308 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8310 SET_IEEE80211_DEV(ar->hw, NULL);