2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/cfg80211.h>
21 #include <net/mac80211.h>
22 #include <linux/etherdevice.h>
23 #include <linux/acpi.h>
41 static struct ieee80211_rate ath10k_rates[] = {
43 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
45 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
46 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
47 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
49 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
50 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
51 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
53 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
54 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
55 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
57 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
58 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
59 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
60 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
61 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
62 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
63 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
64 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
67 static struct ieee80211_rate ath10k_rates_rev2[] = {
69 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
71 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
72 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
73 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
75 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
76 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
77 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
79 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
80 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
81 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
83 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
84 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
85 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
86 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
87 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
88 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
89 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
90 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
93 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
95 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
96 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
97 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
98 #define ath10k_g_rates (ath10k_rates + 0)
99 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
101 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
102 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
104 static bool ath10k_mac_bitrate_is_cck(int bitrate)
117 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
119 return DIV_ROUND_UP(bitrate, 5) |
120 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
123 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
124 u8 hw_rate, bool cck)
126 const struct ieee80211_rate *rate;
129 for (i = 0; i < sband->n_bitrates; i++) {
130 rate = &sband->bitrates[i];
132 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
135 if (rate->hw_value == hw_rate)
137 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
138 rate->hw_value_short == hw_rate)
145 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
150 for (i = 0; i < sband->n_bitrates; i++)
151 if (sband->bitrates[i].bitrate == bitrate)
157 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
159 switch ((mcs_map >> (2 * nss)) & 0x3) {
160 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
161 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
162 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
168 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
172 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
173 if (ht_mcs_mask[nss])
180 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
184 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
185 if (vht_mcs_mask[nss])
191 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
193 enum wmi_host_platform_type platform_type;
196 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
197 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
199 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
201 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
203 if (ret && ret != -EOPNOTSUPP) {
204 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
215 static int ath10k_send_key(struct ath10k_vif *arvif,
216 struct ieee80211_key_conf *key,
217 enum set_key_cmd cmd,
218 const u8 *macaddr, u32 flags)
220 struct ath10k *ar = arvif->ar;
221 struct wmi_vdev_install_key_arg arg = {
222 .vdev_id = arvif->vdev_id,
223 .key_idx = key->keyidx,
224 .key_len = key->keylen,
225 .key_data = key->key,
230 lockdep_assert_held(&arvif->ar->conf_mutex);
232 switch (key->cipher) {
233 case WLAN_CIPHER_SUITE_CCMP:
234 arg.key_cipher = WMI_CIPHER_AES_CCM;
235 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
237 case WLAN_CIPHER_SUITE_TKIP:
238 arg.key_cipher = WMI_CIPHER_TKIP;
239 arg.key_txmic_len = 8;
240 arg.key_rxmic_len = 8;
242 case WLAN_CIPHER_SUITE_WEP40:
243 case WLAN_CIPHER_SUITE_WEP104:
244 arg.key_cipher = WMI_CIPHER_WEP;
246 case WLAN_CIPHER_SUITE_AES_CMAC:
250 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
254 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
255 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
257 if (cmd == DISABLE_KEY) {
258 arg.key_cipher = WMI_CIPHER_NONE;
262 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
265 static int ath10k_install_key(struct ath10k_vif *arvif,
266 struct ieee80211_key_conf *key,
267 enum set_key_cmd cmd,
268 const u8 *macaddr, u32 flags)
270 struct ath10k *ar = arvif->ar;
272 unsigned long time_left;
274 lockdep_assert_held(&ar->conf_mutex);
276 reinit_completion(&ar->install_key_done);
278 if (arvif->nohwcrypt)
281 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
285 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
292 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
295 struct ath10k *ar = arvif->ar;
296 struct ath10k_peer *peer;
301 lockdep_assert_held(&ar->conf_mutex);
303 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
304 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
305 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
308 spin_lock_bh(&ar->data_lock);
309 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
310 spin_unlock_bh(&ar->data_lock);
315 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
316 if (arvif->wep_keys[i] == NULL)
319 switch (arvif->vif->type) {
320 case NL80211_IFTYPE_AP:
321 flags = WMI_KEY_PAIRWISE;
323 if (arvif->def_wep_key_idx == i)
324 flags |= WMI_KEY_TX_USAGE;
326 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
327 SET_KEY, addr, flags);
331 case NL80211_IFTYPE_ADHOC:
332 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
338 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
339 SET_KEY, addr, WMI_KEY_GROUP);
348 spin_lock_bh(&ar->data_lock);
349 peer->keys[i] = arvif->wep_keys[i];
350 spin_unlock_bh(&ar->data_lock);
353 /* In some cases (notably with static WEP IBSS with multiple keys)
354 * multicast Tx becomes broken. Both pairwise and groupwise keys are
355 * installed already. Using WMI_KEY_TX_USAGE in different combinations
356 * didn't seem help. Using def_keyid vdev parameter seems to be
357 * effective so use that.
359 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
361 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
364 if (arvif->def_wep_key_idx == -1)
367 ret = ath10k_wmi_vdev_set_param(arvif->ar,
369 arvif->ar->wmi.vdev_param->def_keyid,
370 arvif->def_wep_key_idx);
372 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
373 arvif->vdev_id, ret);
380 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
383 struct ath10k *ar = arvif->ar;
384 struct ath10k_peer *peer;
390 lockdep_assert_held(&ar->conf_mutex);
392 spin_lock_bh(&ar->data_lock);
393 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
394 spin_unlock_bh(&ar->data_lock);
399 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
400 if (peer->keys[i] == NULL)
403 /* key flags are not required to delete the key */
404 ret = ath10k_install_key(arvif, peer->keys[i],
405 DISABLE_KEY, addr, flags);
406 if (ret < 0 && first_errno == 0)
410 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
413 spin_lock_bh(&ar->data_lock);
414 peer->keys[i] = NULL;
415 spin_unlock_bh(&ar->data_lock);
421 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
424 struct ath10k_peer *peer;
427 lockdep_assert_held(&ar->data_lock);
429 /* We don't know which vdev this peer belongs to,
430 * since WMI doesn't give us that information.
432 * FIXME: multi-bss needs to be handled.
434 peer = ath10k_peer_find(ar, 0, addr);
438 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
439 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
446 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
447 struct ieee80211_key_conf *key)
449 struct ath10k *ar = arvif->ar;
450 struct ath10k_peer *peer;
457 lockdep_assert_held(&ar->conf_mutex);
460 /* since ath10k_install_key we can't hold data_lock all the
461 * time, so we try to remove the keys incrementally
463 spin_lock_bh(&ar->data_lock);
465 list_for_each_entry(peer, &ar->peers, list) {
466 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
467 if (peer->keys[i] == key) {
468 ether_addr_copy(addr, peer->addr);
469 peer->keys[i] = NULL;
474 if (i < ARRAY_SIZE(peer->keys))
477 spin_unlock_bh(&ar->data_lock);
479 if (i == ARRAY_SIZE(peer->keys))
481 /* key flags are not required to delete the key */
482 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
483 if (ret < 0 && first_errno == 0)
487 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
494 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
495 struct ieee80211_key_conf *key)
497 struct ath10k *ar = arvif->ar;
498 struct ath10k_peer *peer;
501 lockdep_assert_held(&ar->conf_mutex);
503 list_for_each_entry(peer, &ar->peers, list) {
504 if (ether_addr_equal(peer->addr, arvif->vif->addr))
507 if (ether_addr_equal(peer->addr, arvif->bssid))
510 if (peer->keys[key->keyidx] == key)
513 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
514 arvif->vdev_id, key->keyidx);
516 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
518 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
519 arvif->vdev_id, peer->addr, ret);
527 /*********************/
528 /* General utilities */
529 /*********************/
531 static inline enum wmi_phy_mode
532 chan_to_phymode(const struct cfg80211_chan_def *chandef)
534 enum wmi_phy_mode phymode = MODE_UNKNOWN;
536 switch (chandef->chan->band) {
537 case NL80211_BAND_2GHZ:
538 switch (chandef->width) {
539 case NL80211_CHAN_WIDTH_20_NOHT:
540 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
545 case NL80211_CHAN_WIDTH_20:
546 phymode = MODE_11NG_HT20;
548 case NL80211_CHAN_WIDTH_40:
549 phymode = MODE_11NG_HT40;
551 case NL80211_CHAN_WIDTH_5:
552 case NL80211_CHAN_WIDTH_10:
553 case NL80211_CHAN_WIDTH_80:
554 case NL80211_CHAN_WIDTH_80P80:
555 case NL80211_CHAN_WIDTH_160:
556 phymode = MODE_UNKNOWN;
560 case NL80211_BAND_5GHZ:
561 switch (chandef->width) {
562 case NL80211_CHAN_WIDTH_20_NOHT:
565 case NL80211_CHAN_WIDTH_20:
566 phymode = MODE_11NA_HT20;
568 case NL80211_CHAN_WIDTH_40:
569 phymode = MODE_11NA_HT40;
571 case NL80211_CHAN_WIDTH_80:
572 phymode = MODE_11AC_VHT80;
574 case NL80211_CHAN_WIDTH_160:
575 phymode = MODE_11AC_VHT160;
577 case NL80211_CHAN_WIDTH_80P80:
578 phymode = MODE_11AC_VHT80_80;
580 case NL80211_CHAN_WIDTH_5:
581 case NL80211_CHAN_WIDTH_10:
582 phymode = MODE_UNKNOWN;
590 WARN_ON(phymode == MODE_UNKNOWN);
594 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
597 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
598 * 0 for no restriction
607 switch (mpdudensity) {
613 /* Our lower layer calculations limit our precision to
630 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
631 struct cfg80211_chan_def *def)
633 struct ieee80211_chanctx_conf *conf;
636 conf = rcu_dereference(vif->chanctx_conf);
648 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
649 struct ieee80211_chanctx_conf *conf,
657 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
661 ieee80211_iter_chan_contexts_atomic(ar->hw,
662 ath10k_mac_num_chanctxs_iter,
669 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
670 struct ieee80211_chanctx_conf *conf,
673 struct cfg80211_chan_def **def = data;
678 static int ath10k_peer_create(struct ath10k *ar,
679 struct ieee80211_vif *vif,
680 struct ieee80211_sta *sta,
683 enum wmi_peer_type peer_type)
685 struct ath10k_vif *arvif;
686 struct ath10k_peer *peer;
690 lockdep_assert_held(&ar->conf_mutex);
692 num_peers = ar->num_peers;
694 /* Each vdev consumes a peer entry as well */
695 list_for_each_entry(arvif, &ar->arvifs, list)
698 if (num_peers >= ar->max_num_peers)
701 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
703 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
708 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
710 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
715 spin_lock_bh(&ar->data_lock);
717 peer = ath10k_peer_find(ar, vdev_id, addr);
719 spin_unlock_bh(&ar->data_lock);
720 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
722 ath10k_wmi_peer_delete(ar, vdev_id, addr);
729 spin_unlock_bh(&ar->data_lock);
736 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
738 struct ath10k *ar = arvif->ar;
742 param = ar->wmi.pdev_param->sta_kickout_th;
743 ret = ath10k_wmi_pdev_set_param(ar, param,
744 ATH10K_KICKOUT_THRESHOLD);
746 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
747 arvif->vdev_id, ret);
751 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
752 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
753 ATH10K_KEEPALIVE_MIN_IDLE);
755 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
756 arvif->vdev_id, ret);
760 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
761 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
762 ATH10K_KEEPALIVE_MAX_IDLE);
764 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
765 arvif->vdev_id, ret);
769 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
770 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
771 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
773 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
774 arvif->vdev_id, ret);
781 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
783 struct ath10k *ar = arvif->ar;
786 vdev_param = ar->wmi.vdev_param->rts_threshold;
787 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
790 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
794 lockdep_assert_held(&ar->conf_mutex);
796 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
800 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
809 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
811 struct ath10k_peer *peer, *tmp;
815 lockdep_assert_held(&ar->conf_mutex);
817 spin_lock_bh(&ar->data_lock);
818 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
819 if (peer->vdev_id != vdev_id)
822 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
823 peer->addr, vdev_id);
825 for_each_set_bit(peer_id, peer->peer_ids,
826 ATH10K_MAX_NUM_PEER_IDS) {
827 ar->peer_map[peer_id] = NULL;
830 /* Double check that peer is properly un-referenced from
833 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
834 if (ar->peer_map[i] == peer) {
835 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
836 peer->addr, peer, i);
837 ar->peer_map[i] = NULL;
841 list_del(&peer->list);
845 spin_unlock_bh(&ar->data_lock);
848 static void ath10k_peer_cleanup_all(struct ath10k *ar)
850 struct ath10k_peer *peer, *tmp;
853 lockdep_assert_held(&ar->conf_mutex);
855 spin_lock_bh(&ar->data_lock);
856 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
857 list_del(&peer->list);
861 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
862 ar->peer_map[i] = NULL;
864 spin_unlock_bh(&ar->data_lock);
867 ar->num_stations = 0;
870 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
871 struct ieee80211_sta *sta,
872 enum wmi_tdls_peer_state state)
875 struct wmi_tdls_peer_update_cmd_arg arg = {};
876 struct wmi_tdls_peer_capab_arg cap = {};
877 struct wmi_channel_arg chan_arg = {};
879 lockdep_assert_held(&ar->conf_mutex);
881 arg.vdev_id = vdev_id;
882 arg.peer_state = state;
883 ether_addr_copy(arg.addr, sta->addr);
885 cap.peer_max_sp = sta->max_sp;
886 cap.peer_uapsd_queues = sta->uapsd_queues;
888 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
889 !sta->tdls_initiator)
890 cap.is_peer_responder = 1;
892 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
894 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
895 arg.addr, vdev_id, ret);
902 /************************/
903 /* Interface management */
904 /************************/
906 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
908 struct ath10k *ar = arvif->ar;
910 lockdep_assert_held(&ar->data_lock);
915 if (!arvif->beacon_buf)
916 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
917 arvif->beacon->len, DMA_TO_DEVICE);
919 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
920 arvif->beacon_state != ATH10K_BEACON_SENT))
923 dev_kfree_skb_any(arvif->beacon);
925 arvif->beacon = NULL;
926 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
929 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
931 struct ath10k *ar = arvif->ar;
933 lockdep_assert_held(&ar->data_lock);
935 ath10k_mac_vif_beacon_free(arvif);
937 if (arvif->beacon_buf) {
938 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
939 arvif->beacon_buf, arvif->beacon_paddr);
940 arvif->beacon_buf = NULL;
944 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
946 unsigned long time_left;
948 lockdep_assert_held(&ar->conf_mutex);
950 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
953 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
954 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
958 return ar->last_wmi_vdev_start_status;
961 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
963 struct cfg80211_chan_def *chandef = NULL;
964 struct ieee80211_channel *channel = NULL;
965 struct wmi_vdev_start_request_arg arg = {};
968 lockdep_assert_held(&ar->conf_mutex);
970 ieee80211_iter_chan_contexts_atomic(ar->hw,
971 ath10k_mac_get_any_chandef_iter,
973 if (WARN_ON_ONCE(!chandef))
976 channel = chandef->chan;
978 arg.vdev_id = vdev_id;
979 arg.channel.freq = channel->center_freq;
980 arg.channel.band_center_freq1 = chandef->center_freq1;
981 arg.channel.band_center_freq2 = chandef->center_freq2;
983 /* TODO setup this dynamically, what in case we
984 * don't have any vifs?
986 arg.channel.mode = chan_to_phymode(chandef);
987 arg.channel.chan_radar =
988 !!(channel->flags & IEEE80211_CHAN_RADAR);
990 arg.channel.min_power = 0;
991 arg.channel.max_power = channel->max_power * 2;
992 arg.channel.max_reg_power = channel->max_reg_power * 2;
993 arg.channel.max_antenna_gain = channel->max_antenna_gain;
995 reinit_completion(&ar->vdev_setup_done);
997 ret = ath10k_wmi_vdev_start(ar, &arg);
999 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1004 ret = ath10k_vdev_setup_sync(ar);
1006 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1011 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1013 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1018 ar->monitor_vdev_id = vdev_id;
1020 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1021 ar->monitor_vdev_id);
1025 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1027 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1028 ar->monitor_vdev_id, ret);
1033 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1037 lockdep_assert_held(&ar->conf_mutex);
1039 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1041 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1042 ar->monitor_vdev_id, ret);
1044 reinit_completion(&ar->vdev_setup_done);
1046 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1048 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1049 ar->monitor_vdev_id, ret);
1051 ret = ath10k_vdev_setup_sync(ar);
1053 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1054 ar->monitor_vdev_id, ret);
1056 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1057 ar->monitor_vdev_id);
1061 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1065 lockdep_assert_held(&ar->conf_mutex);
1067 if (ar->free_vdev_map == 0) {
1068 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1072 bit = __ffs64(ar->free_vdev_map);
1074 ar->monitor_vdev_id = bit;
1076 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1077 WMI_VDEV_TYPE_MONITOR,
1080 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1081 ar->monitor_vdev_id, ret);
1085 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1086 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1087 ar->monitor_vdev_id);
1092 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1096 lockdep_assert_held(&ar->conf_mutex);
1098 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1100 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1101 ar->monitor_vdev_id, ret);
1105 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1107 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1108 ar->monitor_vdev_id);
1112 static int ath10k_monitor_start(struct ath10k *ar)
1116 lockdep_assert_held(&ar->conf_mutex);
1118 ret = ath10k_monitor_vdev_create(ar);
1120 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1124 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1126 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1127 ath10k_monitor_vdev_delete(ar);
1131 ar->monitor_started = true;
1132 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1137 static int ath10k_monitor_stop(struct ath10k *ar)
1141 lockdep_assert_held(&ar->conf_mutex);
1143 ret = ath10k_monitor_vdev_stop(ar);
1145 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1149 ret = ath10k_monitor_vdev_delete(ar);
1151 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1155 ar->monitor_started = false;
1156 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1161 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1165 /* At least one chanctx is required to derive a channel to start
1168 num_ctx = ath10k_mac_num_chanctxs(ar);
1172 /* If there's already an existing special monitor interface then don't
1173 * bother creating another monitor vdev.
1175 if (ar->monitor_arvif)
1178 return ar->monitor ||
1179 (!test_bit(ATH10K_FW_FEATURE_ALLOWS_MESH_BCAST,
1180 ar->running_fw->fw_file.fw_features) &&
1181 (ar->filter_flags & FIF_OTHER_BSS)) ||
1182 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1185 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1189 num_ctx = ath10k_mac_num_chanctxs(ar);
1191 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1192 * shouldn't allow this but make sure to prevent handling the following
1193 * case anyway since multi-channel DFS hasn't been tested at all.
1195 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1201 static int ath10k_monitor_recalc(struct ath10k *ar)
1207 lockdep_assert_held(&ar->conf_mutex);
1209 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1210 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1212 ath10k_dbg(ar, ATH10K_DBG_MAC,
1213 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1214 ar->monitor_started, needed, allowed);
1216 if (WARN_ON(needed && !allowed)) {
1217 if (ar->monitor_started) {
1218 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1220 ret = ath10k_monitor_stop(ar);
1222 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1230 if (needed == ar->monitor_started)
1234 return ath10k_monitor_start(ar);
1236 return ath10k_monitor_stop(ar);
1239 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1241 struct ath10k *ar = arvif->ar;
1243 lockdep_assert_held(&ar->conf_mutex);
1245 if (!arvif->is_started) {
1246 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1253 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1255 struct ath10k *ar = arvif->ar;
1258 lockdep_assert_held(&ar->conf_mutex);
1260 vdev_param = ar->wmi.vdev_param->protection_mode;
1262 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1263 arvif->vdev_id, arvif->use_cts_prot);
1265 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1266 arvif->use_cts_prot ? 1 : 0);
1269 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1271 struct ath10k *ar = arvif->ar;
1272 u32 vdev_param, rts_cts = 0;
1274 lockdep_assert_held(&ar->conf_mutex);
1276 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1278 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1280 if (arvif->num_legacy_stations > 0)
1281 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1282 WMI_RTSCTS_PROFILE);
1284 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1285 WMI_RTSCTS_PROFILE);
1287 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
1288 arvif->vdev_id, rts_cts);
1290 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1294 static int ath10k_start_cac(struct ath10k *ar)
1298 lockdep_assert_held(&ar->conf_mutex);
1300 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1302 ret = ath10k_monitor_recalc(ar);
1304 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1305 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1309 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1310 ar->monitor_vdev_id);
1315 static int ath10k_stop_cac(struct ath10k *ar)
1317 lockdep_assert_held(&ar->conf_mutex);
1319 /* CAC is not running - do nothing */
1320 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1323 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1324 ath10k_monitor_stop(ar);
1326 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1331 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1332 struct ieee80211_chanctx_conf *conf,
1337 if (!*ret && conf->radar_enabled)
1341 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1343 bool has_radar = false;
1345 ieee80211_iter_chan_contexts_atomic(ar->hw,
1346 ath10k_mac_has_radar_iter,
1352 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1356 lockdep_assert_held(&ar->conf_mutex);
1358 ath10k_stop_cac(ar);
1360 if (!ath10k_mac_has_radar_enabled(ar))
1363 if (ar->num_started_vdevs > 0)
1366 ret = ath10k_start_cac(ar);
1369 * Not possible to start CAC on current channel so starting
1370 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1371 * by indicating that radar was detected.
1373 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1374 ieee80211_radar_detected(ar->hw);
1378 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1380 struct ath10k *ar = arvif->ar;
1383 lockdep_assert_held(&ar->conf_mutex);
1385 reinit_completion(&ar->vdev_setup_done);
1387 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1389 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1390 arvif->vdev_id, ret);
1394 ret = ath10k_vdev_setup_sync(ar);
1396 ath10k_warn(ar, "failed to synchronize setup for vdev %i: %d\n",
1397 arvif->vdev_id, ret);
1401 WARN_ON(ar->num_started_vdevs == 0);
1403 if (ar->num_started_vdevs != 0) {
1404 ar->num_started_vdevs--;
1405 ath10k_recalc_radar_detection(ar);
1411 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1412 const struct cfg80211_chan_def *chandef,
1415 struct ath10k *ar = arvif->ar;
1416 struct wmi_vdev_start_request_arg arg = {};
1419 lockdep_assert_held(&ar->conf_mutex);
1421 reinit_completion(&ar->vdev_setup_done);
1423 arg.vdev_id = arvif->vdev_id;
1424 arg.dtim_period = arvif->dtim_period;
1425 arg.bcn_intval = arvif->beacon_interval;
1427 arg.channel.freq = chandef->chan->center_freq;
1428 arg.channel.band_center_freq1 = chandef->center_freq1;
1429 arg.channel.band_center_freq2 = chandef->center_freq2;
1430 arg.channel.mode = chan_to_phymode(chandef);
1432 arg.channel.min_power = 0;
1433 arg.channel.max_power = chandef->chan->max_power * 2;
1434 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1435 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
1437 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1438 arg.ssid = arvif->u.ap.ssid;
1439 arg.ssid_len = arvif->u.ap.ssid_len;
1440 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1442 /* For now allow DFS for AP mode */
1443 arg.channel.chan_radar =
1444 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1445 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1446 arg.ssid = arvif->vif->bss_conf.ssid;
1447 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1450 ath10k_dbg(ar, ATH10K_DBG_MAC,
1451 "mac vdev %d start center_freq %d phymode %s\n",
1452 arg.vdev_id, arg.channel.freq,
1453 ath10k_wmi_phymode_str(arg.channel.mode));
1456 ret = ath10k_wmi_vdev_restart(ar, &arg);
1458 ret = ath10k_wmi_vdev_start(ar, &arg);
1461 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1466 ret = ath10k_vdev_setup_sync(ar);
1469 "failed to synchronize setup for vdev %i restart %d: %d\n",
1470 arg.vdev_id, restart, ret);
1474 ar->num_started_vdevs++;
1475 ath10k_recalc_radar_detection(ar);
1480 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1481 const struct cfg80211_chan_def *def)
1483 return ath10k_vdev_start_restart(arvif, def, false);
1486 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1487 const struct cfg80211_chan_def *def)
1489 return ath10k_vdev_start_restart(arvif, def, true);
1492 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1493 struct sk_buff *bcn)
1495 struct ath10k *ar = arvif->ar;
1496 struct ieee80211_mgmt *mgmt;
1500 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1503 mgmt = (void *)bcn->data;
1504 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1505 mgmt->u.beacon.variable,
1506 bcn->len - (mgmt->u.beacon.variable -
1511 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1513 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1514 arvif->vdev_id, ret);
1521 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1522 u8 oui_type, size_t ie_offset)
1529 if (WARN_ON(skb->len < ie_offset))
1532 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1533 skb->data + ie_offset,
1534 skb->len - ie_offset);
1539 end = skb->data + skb->len;
1542 if (WARN_ON(next > end))
1545 memmove(ie, next, end - next);
1546 skb_trim(skb, skb->len - len);
1551 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1553 struct ath10k *ar = arvif->ar;
1554 struct ieee80211_hw *hw = ar->hw;
1555 struct ieee80211_vif *vif = arvif->vif;
1556 struct ieee80211_mutable_offsets offs = {};
1557 struct sk_buff *bcn;
1560 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1563 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1564 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1567 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1569 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1573 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1575 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1580 /* P2P IE is inserted by firmware automatically (as configured above)
1581 * so remove it from the base beacon template to avoid duplicate P2P
1582 * IEs in beacon frames.
1584 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1585 offsetof(struct ieee80211_mgmt,
1586 u.beacon.variable));
1588 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1593 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1601 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1603 struct ath10k *ar = arvif->ar;
1604 struct ieee80211_hw *hw = ar->hw;
1605 struct ieee80211_vif *vif = arvif->vif;
1606 struct sk_buff *prb;
1609 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1612 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1615 /* For mesh, probe response and beacon share the same template */
1616 if (ieee80211_vif_is_mesh(vif))
1619 prb = ieee80211_proberesp_get(hw, vif);
1621 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1625 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1629 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1637 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1639 struct ath10k *ar = arvif->ar;
1640 struct cfg80211_chan_def def;
1643 /* When originally vdev is started during assign_vif_chanctx() some
1644 * information is missing, notably SSID. Firmware revisions with beacon
1645 * offloading require the SSID to be provided during vdev (re)start to
1646 * handle hidden SSID properly.
1648 * Vdev restart must be done after vdev has been both started and
1649 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1650 * deliver vdev restart response event causing timeouts during vdev
1651 * syncing in ath10k.
1653 * Note: The vdev down/up and template reinstallation could be skipped
1654 * since only wmi-tlv firmware are known to have beacon offload and
1655 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1656 * response delivery. It's probably more robust to keep it as is.
1658 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1661 if (WARN_ON(!arvif->is_started))
1664 if (WARN_ON(!arvif->is_up))
1667 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1670 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1672 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1673 arvif->vdev_id, ret);
1677 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1678 * firmware will crash upon vdev up.
1681 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1683 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1687 ret = ath10k_mac_setup_prb_tmpl(arvif);
1689 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1693 ret = ath10k_vdev_restart(arvif, &def);
1695 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1696 arvif->vdev_id, ret);
1700 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1703 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1704 arvif->vdev_id, ret);
1711 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1712 struct ieee80211_bss_conf *info)
1714 struct ath10k *ar = arvif->ar;
1717 lockdep_assert_held(&arvif->ar->conf_mutex);
1719 if (!info->enable_beacon) {
1720 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1722 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1723 arvif->vdev_id, ret);
1725 arvif->is_up = false;
1727 spin_lock_bh(&arvif->ar->data_lock);
1728 ath10k_mac_vif_beacon_free(arvif);
1729 spin_unlock_bh(&arvif->ar->data_lock);
1734 arvif->tx_seq_no = 0x1000;
1737 ether_addr_copy(arvif->bssid, info->bssid);
1739 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1742 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1743 arvif->vdev_id, ret);
1747 arvif->is_up = true;
1749 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1751 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1752 arvif->vdev_id, ret);
1756 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1759 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1760 struct ieee80211_bss_conf *info,
1761 const u8 self_peer[ETH_ALEN])
1763 struct ath10k *ar = arvif->ar;
1767 lockdep_assert_held(&arvif->ar->conf_mutex);
1769 if (!info->ibss_joined) {
1770 if (is_zero_ether_addr(arvif->bssid))
1773 eth_zero_addr(arvif->bssid);
1778 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1779 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1780 ATH10K_DEFAULT_ATIM);
1782 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1783 arvif->vdev_id, ret);
1786 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1788 struct ath10k *ar = arvif->ar;
1793 lockdep_assert_held(&arvif->ar->conf_mutex);
1795 if (arvif->u.sta.uapsd)
1796 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1798 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1800 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1801 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1803 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1804 value, arvif->vdev_id, ret);
1811 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1813 struct ath10k *ar = arvif->ar;
1818 lockdep_assert_held(&arvif->ar->conf_mutex);
1820 if (arvif->u.sta.uapsd)
1821 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1823 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1825 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1826 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1829 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1830 value, arvif->vdev_id, ret);
1837 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1839 struct ath10k_vif *arvif;
1842 lockdep_assert_held(&ar->conf_mutex);
1844 list_for_each_entry(arvif, &ar->arvifs, list)
1845 if (arvif->is_started)
1851 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1853 struct ath10k *ar = arvif->ar;
1854 struct ieee80211_vif *vif = arvif->vif;
1855 struct ieee80211_conf *conf = &ar->hw->conf;
1856 enum wmi_sta_powersave_param param;
1857 enum wmi_sta_ps_mode psmode;
1862 lockdep_assert_held(&arvif->ar->conf_mutex);
1864 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1867 enable_ps = arvif->ps;
1869 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1870 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1871 ar->running_fw->fw_file.fw_features)) {
1872 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1877 if (!arvif->is_started) {
1878 /* mac80211 can update vif powersave state while disconnected.
1879 * Firmware doesn't behave nicely and consumes more power than
1880 * necessary if PS is disabled on a non-started vdev. Hence
1881 * force-enable PS for non-running vdevs.
1883 psmode = WMI_STA_PS_MODE_ENABLED;
1884 } else if (enable_ps) {
1885 psmode = WMI_STA_PS_MODE_ENABLED;
1886 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1888 ps_timeout = conf->dynamic_ps_timeout;
1889 if (ps_timeout == 0) {
1890 /* Firmware doesn't like 0 */
1891 ps_timeout = ieee80211_tu_to_usec(
1892 vif->bss_conf.beacon_int) / 1000;
1895 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1898 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1899 arvif->vdev_id, ret);
1903 psmode = WMI_STA_PS_MODE_DISABLED;
1906 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1907 arvif->vdev_id, psmode ? "enable" : "disable");
1909 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1911 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1912 psmode, arvif->vdev_id, ret);
1919 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1921 struct ath10k *ar = arvif->ar;
1922 struct wmi_sta_keepalive_arg arg = {};
1925 lockdep_assert_held(&arvif->ar->conf_mutex);
1927 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1930 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1933 /* Some firmware revisions have a bug and ignore the `enabled` field.
1934 * Instead use the interval to disable the keepalive.
1936 arg.vdev_id = arvif->vdev_id;
1938 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1939 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1941 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1943 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1944 arvif->vdev_id, ret);
1951 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1953 struct ath10k *ar = arvif->ar;
1954 struct ieee80211_vif *vif = arvif->vif;
1957 lockdep_assert_held(&arvif->ar->conf_mutex);
1959 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1962 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1965 if (!vif->csa_active)
1971 if (!ieee80211_csa_is_complete(vif)) {
1972 ieee80211_csa_update_counter(vif);
1974 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1976 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1979 ret = ath10k_mac_setup_prb_tmpl(arvif);
1981 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1984 ieee80211_csa_finish(vif);
1988 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1990 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1992 struct ath10k *ar = arvif->ar;
1994 mutex_lock(&ar->conf_mutex);
1995 ath10k_mac_vif_ap_csa_count_down(arvif);
1996 mutex_unlock(&ar->conf_mutex);
1999 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2000 struct ieee80211_vif *vif)
2002 struct sk_buff *skb = data;
2003 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2004 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2006 if (vif->type != NL80211_IFTYPE_STATION)
2009 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2012 cancel_delayed_work(&arvif->connection_loss_work);
2015 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2017 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2018 IEEE80211_IFACE_ITER_NORMAL,
2019 ath10k_mac_handle_beacon_iter,
2023 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2024 struct ieee80211_vif *vif)
2026 u32 *vdev_id = data;
2027 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2028 struct ath10k *ar = arvif->ar;
2029 struct ieee80211_hw *hw = ar->hw;
2031 if (arvif->vdev_id != *vdev_id)
2037 ieee80211_beacon_loss(vif);
2039 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2040 * (done by mac80211) succeeds but beacons do not resume then it
2041 * doesn't make sense to continue operation. Queue connection loss work
2042 * which can be cancelled when beacon is received.
2044 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2045 ATH10K_CONNECTION_LOSS_HZ);
2048 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2050 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2051 IEEE80211_IFACE_ITER_NORMAL,
2052 ath10k_mac_handle_beacon_miss_iter,
2056 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2058 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2059 connection_loss_work.work);
2060 struct ieee80211_vif *vif = arvif->vif;
2065 ieee80211_connection_loss(vif);
2068 /**********************/
2069 /* Station management */
2070 /**********************/
2072 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2073 struct ieee80211_vif *vif)
2075 /* Some firmware revisions have unstable STA powersave when listen
2076 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2077 * generate NullFunc frames properly even if buffered frames have been
2078 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2079 * buffered frames. Often pinging the device from AP would simply fail.
2081 * As a workaround set it to 1.
2083 if (vif->type == NL80211_IFTYPE_STATION)
2086 return ar->hw->conf.listen_interval;
2089 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2090 struct ieee80211_vif *vif,
2091 struct ieee80211_sta *sta,
2092 struct wmi_peer_assoc_complete_arg *arg)
2094 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2097 lockdep_assert_held(&ar->conf_mutex);
2099 if (vif->type == NL80211_IFTYPE_STATION)
2100 aid = vif->bss_conf.aid;
2104 ether_addr_copy(arg->addr, sta->addr);
2105 arg->vdev_id = arvif->vdev_id;
2106 arg->peer_aid = aid;
2107 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2108 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2109 arg->peer_num_spatial_streams = 1;
2110 arg->peer_caps = vif->bss_conf.assoc_capability;
2113 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2114 struct ieee80211_vif *vif,
2115 struct ieee80211_sta *sta,
2116 struct wmi_peer_assoc_complete_arg *arg)
2118 struct ieee80211_bss_conf *info = &vif->bss_conf;
2119 struct cfg80211_chan_def def;
2120 struct cfg80211_bss *bss;
2121 const u8 *rsnie = NULL;
2122 const u8 *wpaie = NULL;
2124 lockdep_assert_held(&ar->conf_mutex);
2126 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2129 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2130 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2132 const struct cfg80211_bss_ies *ies;
2135 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2137 ies = rcu_dereference(bss->ies);
2139 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2140 WLAN_OUI_TYPE_MICROSOFT_WPA,
2144 cfg80211_put_bss(ar->hw->wiphy, bss);
2147 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2148 if (rsnie || wpaie) {
2149 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2150 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2154 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2155 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2159 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2160 ar->running_fw->fw_file.fw_features)) {
2161 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2165 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2166 struct ieee80211_vif *vif,
2167 struct ieee80211_sta *sta,
2168 struct wmi_peer_assoc_complete_arg *arg)
2170 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2171 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2172 struct cfg80211_chan_def def;
2173 const struct ieee80211_supported_band *sband;
2174 const struct ieee80211_rate *rates;
2175 enum nl80211_band band;
2180 lockdep_assert_held(&ar->conf_mutex);
2182 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2185 band = def.chan->band;
2186 sband = ar->hw->wiphy->bands[band];
2187 ratemask = sta->supp_rates[band];
2188 ratemask &= arvif->bitrate_mask.control[band].legacy;
2189 rates = sband->bitrates;
2191 rateset->num_rates = 0;
2193 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2194 if (!(ratemask & 1))
2197 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2198 rateset->rates[rateset->num_rates] = rate;
2199 rateset->num_rates++;
2204 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2208 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2209 if (ht_mcs_mask[nss])
2216 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2220 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2221 if (vht_mcs_mask[nss])
2227 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2228 struct ieee80211_vif *vif,
2229 struct ieee80211_sta *sta,
2230 struct wmi_peer_assoc_complete_arg *arg)
2232 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2233 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2234 struct cfg80211_chan_def def;
2235 enum nl80211_band band;
2236 const u8 *ht_mcs_mask;
2237 const u16 *vht_mcs_mask;
2242 lockdep_assert_held(&ar->conf_mutex);
2244 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2247 if (!ht_cap->ht_supported)
2250 band = def.chan->band;
2251 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2252 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2254 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2255 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2258 arg->peer_flags |= ar->wmi.peer_flags->ht;
2259 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2260 ht_cap->ampdu_factor)) - 1;
2262 arg->peer_mpdu_density =
2263 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2265 arg->peer_ht_caps = ht_cap->cap;
2266 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2268 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2269 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2271 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2272 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2273 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2276 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2277 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2278 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2280 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2281 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2284 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2285 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2286 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2289 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2290 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2291 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2292 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2293 arg->peer_rate_caps |= stbc;
2294 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2297 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2298 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2299 else if (ht_cap->mcs.rx_mask[1])
2300 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2302 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2303 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2304 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2305 max_nss = (i / 8) + 1;
2306 arg->peer_ht_rates.rates[n++] = i;
2310 * This is a workaround for HT-enabled STAs which break the spec
2311 * and have no HT capabilities RX mask (no HT RX MCS map).
2313 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2314 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2316 * Firmware asserts if such situation occurs.
2319 arg->peer_ht_rates.num_rates = 8;
2320 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2321 arg->peer_ht_rates.rates[i] = i;
2323 arg->peer_ht_rates.num_rates = n;
2324 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2327 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2329 arg->peer_ht_rates.num_rates,
2330 arg->peer_num_spatial_streams);
2333 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2334 struct ath10k_vif *arvif,
2335 struct ieee80211_sta *sta)
2341 lockdep_assert_held(&ar->conf_mutex);
2343 if (sta->wme && sta->uapsd_queues) {
2344 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2345 sta->uapsd_queues, sta->max_sp);
2347 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2348 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2349 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2350 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2351 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2352 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2353 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2354 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2355 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2356 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2357 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2358 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2360 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2361 max_sp = sta->max_sp;
2363 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2365 WMI_AP_PS_PEER_PARAM_UAPSD,
2368 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2369 arvif->vdev_id, ret);
2373 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2375 WMI_AP_PS_PEER_PARAM_MAX_SP,
2378 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2379 arvif->vdev_id, ret);
2383 /* TODO setup this based on STA listen interval and
2384 * beacon interval. Currently we don't know
2385 * sta->listen_interval - mac80211 patch required.
2386 * Currently use 10 seconds
2388 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2389 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2392 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2393 arvif->vdev_id, ret);
2402 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2403 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2410 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2411 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2415 idx_limit = fls(mcs_map) - 1;
2419 switch (idx_limit) {
2420 case 0: /* fall through */
2421 case 1: /* fall through */
2422 case 2: /* fall through */
2423 case 3: /* fall through */
2424 case 4: /* fall through */
2425 case 5: /* fall through */
2426 case 6: /* fall through */
2428 /* see ath10k_mac_can_set_bitrate_mask() */
2432 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2435 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2438 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2441 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2445 tx_mcs_set &= ~(0x3 << (nss * 2));
2446 tx_mcs_set |= mcs << (nss * 2);
2452 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2453 struct ieee80211_vif *vif,
2454 struct ieee80211_sta *sta,
2455 struct wmi_peer_assoc_complete_arg *arg)
2457 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2458 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2459 struct cfg80211_chan_def def;
2460 enum nl80211_band band;
2461 const u16 *vht_mcs_mask;
2463 u8 max_nss, vht_mcs;
2466 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2469 if (!vht_cap->vht_supported)
2472 band = def.chan->band;
2473 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2475 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2478 arg->peer_flags |= ar->wmi.peer_flags->vht;
2480 if (def.chan->band == NL80211_BAND_2GHZ)
2481 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2483 arg->peer_vht_caps = vht_cap->cap;
2485 ampdu_factor = (vht_cap->cap &
2486 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2487 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2489 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2490 * zero in VHT IE. Using it would result in degraded throughput.
2491 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2492 * it if VHT max_mpdu is smaller.
2494 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2495 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2496 ampdu_factor)) - 1);
2498 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2499 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2501 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2502 arg->peer_flags |= ar->wmi.peer_flags->bw160;
2504 /* Calculate peer NSS capability from VHT capabilities if STA
2507 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
2508 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
2511 if ((vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) &&
2515 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2516 arg->peer_vht_rates.rx_max_rate =
2517 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2518 arg->peer_vht_rates.rx_mcs_set =
2519 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2520 arg->peer_vht_rates.tx_max_rate =
2521 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2522 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2523 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2525 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2526 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2528 if (arg->peer_vht_rates.rx_max_rate &&
2529 (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK)) {
2530 switch (arg->peer_vht_rates.rx_max_rate) {
2532 /* Must be 2x2 at 160Mhz is all it can do. */
2533 arg->peer_bw_rxnss_override = 2;
2536 /* Can only do 1x1 at 160Mhz (Long Guard Interval) */
2537 arg->peer_bw_rxnss_override = 1;
2543 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2544 struct ieee80211_vif *vif,
2545 struct ieee80211_sta *sta,
2546 struct wmi_peer_assoc_complete_arg *arg)
2548 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2550 switch (arvif->vdev_type) {
2551 case WMI_VDEV_TYPE_AP:
2553 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2555 if (sta->wme && sta->uapsd_queues) {
2556 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2557 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2560 case WMI_VDEV_TYPE_STA:
2562 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2564 case WMI_VDEV_TYPE_IBSS:
2566 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2572 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2573 sta->addr, !!(arg->peer_flags &
2574 arvif->ar->wmi.peer_flags->qos));
2577 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2579 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2580 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2583 static enum wmi_phy_mode ath10k_mac_get_phymode_vht(struct ath10k *ar,
2584 struct ieee80211_sta *sta)
2586 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2587 switch (sta->vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2588 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2589 return MODE_11AC_VHT160;
2590 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2591 return MODE_11AC_VHT80_80;
2593 /* not sure if this is a valid case? */
2594 return MODE_11AC_VHT160;
2598 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2599 return MODE_11AC_VHT80;
2601 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2602 return MODE_11AC_VHT40;
2604 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2605 return MODE_11AC_VHT20;
2607 return MODE_UNKNOWN;
2610 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2611 struct ieee80211_vif *vif,
2612 struct ieee80211_sta *sta,
2613 struct wmi_peer_assoc_complete_arg *arg)
2615 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2616 struct cfg80211_chan_def def;
2617 enum nl80211_band band;
2618 const u8 *ht_mcs_mask;
2619 const u16 *vht_mcs_mask;
2620 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2622 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2625 band = def.chan->band;
2626 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2627 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2630 case NL80211_BAND_2GHZ:
2631 if (sta->vht_cap.vht_supported &&
2632 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2633 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2634 phymode = MODE_11AC_VHT40;
2636 phymode = MODE_11AC_VHT20;
2637 } else if (sta->ht_cap.ht_supported &&
2638 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2639 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2640 phymode = MODE_11NG_HT40;
2642 phymode = MODE_11NG_HT20;
2643 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2650 case NL80211_BAND_5GHZ:
2654 if (sta->vht_cap.vht_supported &&
2655 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2656 phymode = ath10k_mac_get_phymode_vht(ar, sta);
2657 } else if (sta->ht_cap.ht_supported &&
2658 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2659 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2660 phymode = MODE_11NA_HT40;
2662 phymode = MODE_11NA_HT20;
2672 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2673 sta->addr, ath10k_wmi_phymode_str(phymode));
2675 arg->peer_phymode = phymode;
2676 WARN_ON(phymode == MODE_UNKNOWN);
2679 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2680 struct ieee80211_vif *vif,
2681 struct ieee80211_sta *sta,
2682 struct wmi_peer_assoc_complete_arg *arg)
2684 lockdep_assert_held(&ar->conf_mutex);
2686 memset(arg, 0, sizeof(*arg));
2688 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2689 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2690 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2691 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2692 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2693 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2694 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2699 static const u32 ath10k_smps_map[] = {
2700 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2701 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2702 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2703 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2706 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2708 const struct ieee80211_sta_ht_cap *ht_cap)
2712 if (!ht_cap->ht_supported)
2715 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2716 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2718 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2721 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2722 WMI_PEER_SMPS_STATE,
2723 ath10k_smps_map[smps]);
2726 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2727 struct ieee80211_vif *vif,
2728 struct ieee80211_sta_vht_cap vht_cap)
2730 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2735 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2738 if (!(ar->vht_cap_info &
2739 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2740 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2741 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2742 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2745 param = ar->wmi.vdev_param->txbf;
2748 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2751 /* The following logic is correct. If a remote STA advertises support
2752 * for being a beamformer then we should enable us being a beamformee.
2755 if (ar->vht_cap_info &
2756 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2757 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2758 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2759 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2761 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2762 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2765 if (ar->vht_cap_info &
2766 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2767 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2768 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2769 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2771 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2772 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2775 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2776 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2778 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2779 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2781 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2783 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2791 /* can be called only in mac80211 callbacks due to `key_count` usage */
2792 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2793 struct ieee80211_vif *vif,
2794 struct ieee80211_bss_conf *bss_conf)
2796 struct ath10k *ar = hw->priv;
2797 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2798 struct ieee80211_sta_ht_cap ht_cap;
2799 struct ieee80211_sta_vht_cap vht_cap;
2800 struct wmi_peer_assoc_complete_arg peer_arg;
2801 struct ieee80211_sta *ap_sta;
2804 lockdep_assert_held(&ar->conf_mutex);
2806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2807 arvif->vdev_id, arvif->bssid, arvif->aid);
2811 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2813 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2814 bss_conf->bssid, arvif->vdev_id);
2819 /* ap_sta must be accessed only within rcu section which must be left
2820 * before calling ath10k_setup_peer_smps() which might sleep.
2822 ht_cap = ap_sta->ht_cap;
2823 vht_cap = ap_sta->vht_cap;
2825 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2827 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2828 bss_conf->bssid, arvif->vdev_id, ret);
2835 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2837 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2838 bss_conf->bssid, arvif->vdev_id, ret);
2842 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2844 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2845 arvif->vdev_id, ret);
2849 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2851 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2852 arvif->vdev_id, bss_conf->bssid, ret);
2856 ath10k_dbg(ar, ATH10K_DBG_MAC,
2857 "mac vdev %d up (associated) bssid %pM aid %d\n",
2858 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2860 WARN_ON(arvif->is_up);
2862 arvif->aid = bss_conf->aid;
2863 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2865 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2867 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2868 arvif->vdev_id, ret);
2872 arvif->is_up = true;
2874 /* Workaround: Some firmware revisions (tested with qca6174
2875 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2876 * poked with peer param command.
2878 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2879 WMI_PEER_DUMMY_VAR, 1);
2881 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2882 arvif->bssid, arvif->vdev_id, ret);
2887 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2888 struct ieee80211_vif *vif)
2890 struct ath10k *ar = hw->priv;
2891 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2892 struct ieee80211_sta_vht_cap vht_cap = {};
2895 lockdep_assert_held(&ar->conf_mutex);
2897 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2898 arvif->vdev_id, arvif->bssid);
2900 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2902 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2903 arvif->vdev_id, ret);
2905 arvif->def_wep_key_idx = -1;
2907 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2909 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2910 arvif->vdev_id, ret);
2914 arvif->is_up = false;
2916 cancel_delayed_work_sync(&arvif->connection_loss_work);
2919 static int ath10k_station_assoc(struct ath10k *ar,
2920 struct ieee80211_vif *vif,
2921 struct ieee80211_sta *sta,
2924 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2925 struct wmi_peer_assoc_complete_arg peer_arg;
2928 lockdep_assert_held(&ar->conf_mutex);
2930 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2932 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2933 sta->addr, arvif->vdev_id, ret);
2937 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2939 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2940 sta->addr, arvif->vdev_id, ret);
2944 /* Re-assoc is run only to update supported rates for given station. It
2945 * doesn't make much sense to reconfigure the peer completely.
2948 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2951 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2952 arvif->vdev_id, ret);
2956 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2958 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2959 sta->addr, arvif->vdev_id, ret);
2964 arvif->num_legacy_stations++;
2965 ret = ath10k_recalc_rtscts_prot(arvif);
2967 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2968 arvif->vdev_id, ret);
2973 /* Plumb cached keys only for static WEP */
2974 if (arvif->def_wep_key_idx != -1) {
2975 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2977 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2978 arvif->vdev_id, ret);
2987 static int ath10k_station_disassoc(struct ath10k *ar,
2988 struct ieee80211_vif *vif,
2989 struct ieee80211_sta *sta)
2991 struct ath10k_vif *arvif = (void *)vif->drv_priv;
2994 lockdep_assert_held(&ar->conf_mutex);
2997 arvif->num_legacy_stations--;
2998 ret = ath10k_recalc_rtscts_prot(arvif);
3000 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3001 arvif->vdev_id, ret);
3006 ret = ath10k_clear_peer_keys(arvif, sta->addr);
3008 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
3009 arvif->vdev_id, ret);
3020 static int ath10k_update_channel_list(struct ath10k *ar)
3022 struct ieee80211_hw *hw = ar->hw;
3023 struct ieee80211_supported_band **bands;
3024 enum nl80211_band band;
3025 struct ieee80211_channel *channel;
3026 struct wmi_scan_chan_list_arg arg = {0};
3027 struct wmi_channel_arg *ch;
3033 lockdep_assert_held(&ar->conf_mutex);
3035 bands = hw->wiphy->bands;
3036 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3040 for (i = 0; i < bands[band]->n_channels; i++) {
3041 if (bands[band]->channels[i].flags &
3042 IEEE80211_CHAN_DISABLED)
3049 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
3050 arg.channels = kzalloc(len, GFP_KERNEL);
3055 for (band = 0; band < NUM_NL80211_BANDS; band++) {
3059 for (i = 0; i < bands[band]->n_channels; i++) {
3060 channel = &bands[band]->channels[i];
3062 if (channel->flags & IEEE80211_CHAN_DISABLED)
3065 ch->allow_ht = true;
3067 /* FIXME: when should we really allow VHT? */
3068 ch->allow_vht = true;
3071 !(channel->flags & IEEE80211_CHAN_NO_IR);
3074 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3077 !!(channel->flags & IEEE80211_CHAN_RADAR);
3079 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3080 ch->passive = passive;
3082 /* the firmware is ignoring the "radar" flag of the
3083 * channel and is scanning actively using Probe Requests
3084 * on "Radar detection"/DFS channels which are not
3085 * marked as "available"
3087 ch->passive |= ch->chan_radar;
3089 ch->freq = channel->center_freq;
3090 ch->band_center_freq1 = channel->center_freq;
3092 ch->max_power = channel->max_power * 2;
3093 ch->max_reg_power = channel->max_reg_power * 2;
3094 ch->max_antenna_gain = channel->max_antenna_gain;
3095 ch->reg_class_id = 0; /* FIXME */
3097 /* FIXME: why use only legacy modes, why not any
3098 * HT/VHT modes? Would that even make any
3101 if (channel->band == NL80211_BAND_2GHZ)
3102 ch->mode = MODE_11G;
3104 ch->mode = MODE_11A;
3106 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3109 ath10k_dbg(ar, ATH10K_DBG_WMI,
3110 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3111 ch - arg.channels, arg.n_channels,
3112 ch->freq, ch->max_power, ch->max_reg_power,
3113 ch->max_antenna_gain, ch->mode);
3119 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3120 kfree(arg.channels);
3125 static enum wmi_dfs_region
3126 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3128 switch (dfs_region) {
3129 case NL80211_DFS_UNSET:
3130 return WMI_UNINIT_DFS_DOMAIN;
3131 case NL80211_DFS_FCC:
3132 return WMI_FCC_DFS_DOMAIN;
3133 case NL80211_DFS_ETSI:
3134 return WMI_ETSI_DFS_DOMAIN;
3135 case NL80211_DFS_JP:
3136 return WMI_MKK4_DFS_DOMAIN;
3138 return WMI_UNINIT_DFS_DOMAIN;
3141 static void ath10k_regd_update(struct ath10k *ar)
3143 struct reg_dmn_pair_mapping *regpair;
3145 enum wmi_dfs_region wmi_dfs_reg;
3146 enum nl80211_dfs_regions nl_dfs_reg;
3148 lockdep_assert_held(&ar->conf_mutex);
3150 ret = ath10k_update_channel_list(ar);
3152 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3154 regpair = ar->ath_common.regulatory.regpair;
3156 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3157 nl_dfs_reg = ar->dfs_detector->region;
3158 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3160 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3163 /* Target allows setting up per-band regdomain but ath_common provides
3164 * a combined one only
3166 ret = ath10k_wmi_pdev_set_regdomain(ar,
3167 regpair->reg_domain,
3168 regpair->reg_domain, /* 2ghz */
3169 regpair->reg_domain, /* 5ghz */
3170 regpair->reg_2ghz_ctl,
3171 regpair->reg_5ghz_ctl,
3174 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3177 static void ath10k_mac_update_channel_list(struct ath10k *ar,
3178 struct ieee80211_supported_band *band)
3182 if (ar->low_5ghz_chan && ar->high_5ghz_chan) {
3183 for (i = 0; i < band->n_channels; i++) {
3184 if (band->channels[i].center_freq < ar->low_5ghz_chan ||
3185 band->channels[i].center_freq > ar->high_5ghz_chan)
3186 band->channels[i].flags |=
3187 IEEE80211_CHAN_DISABLED;
3192 static void ath10k_reg_notifier(struct wiphy *wiphy,
3193 struct regulatory_request *request)
3195 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3196 struct ath10k *ar = hw->priv;
3199 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3201 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3202 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3203 request->dfs_region);
3204 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3205 request->dfs_region);
3207 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3208 request->dfs_region);
3211 mutex_lock(&ar->conf_mutex);
3212 if (ar->state == ATH10K_STATE_ON)
3213 ath10k_regd_update(ar);
3214 mutex_unlock(&ar->conf_mutex);
3216 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY)
3217 ath10k_mac_update_channel_list(ar,
3218 ar->hw->wiphy->bands[NL80211_BAND_5GHZ]);
3225 enum ath10k_mac_tx_path {
3227 ATH10K_MAC_TX_HTT_MGMT,
3228 ATH10K_MAC_TX_WMI_MGMT,
3229 ATH10K_MAC_TX_UNKNOWN,
3232 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3234 lockdep_assert_held(&ar->htt.tx_lock);
3236 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3237 ar->tx_paused |= BIT(reason);
3238 ieee80211_stop_queues(ar->hw);
3241 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3242 struct ieee80211_vif *vif)
3244 struct ath10k *ar = data;
3245 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3247 if (arvif->tx_paused)
3250 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3253 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3255 lockdep_assert_held(&ar->htt.tx_lock);
3257 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3258 ar->tx_paused &= ~BIT(reason);
3263 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3264 IEEE80211_IFACE_ITER_RESUME_ALL,
3265 ath10k_mac_tx_unlock_iter,
3268 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3271 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3273 struct ath10k *ar = arvif->ar;
3275 lockdep_assert_held(&ar->htt.tx_lock);
3277 WARN_ON(reason >= BITS_PER_LONG);
3278 arvif->tx_paused |= BIT(reason);
3279 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3282 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3284 struct ath10k *ar = arvif->ar;
3286 lockdep_assert_held(&ar->htt.tx_lock);
3288 WARN_ON(reason >= BITS_PER_LONG);
3289 arvif->tx_paused &= ~BIT(reason);
3294 if (arvif->tx_paused)
3297 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3300 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3301 enum wmi_tlv_tx_pause_id pause_id,
3302 enum wmi_tlv_tx_pause_action action)
3304 struct ath10k *ar = arvif->ar;
3306 lockdep_assert_held(&ar->htt.tx_lock);
3309 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3310 ath10k_mac_vif_tx_lock(arvif, pause_id);
3312 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3313 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3316 ath10k_dbg(ar, ATH10K_DBG_BOOT,
3317 "received unknown tx pause action %d on vdev %i, ignoring\n",
3318 action, arvif->vdev_id);
3323 struct ath10k_mac_tx_pause {
3325 enum wmi_tlv_tx_pause_id pause_id;
3326 enum wmi_tlv_tx_pause_action action;
3329 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3330 struct ieee80211_vif *vif)
3332 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3333 struct ath10k_mac_tx_pause *arg = data;
3335 if (arvif->vdev_id != arg->vdev_id)
3338 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3341 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3342 enum wmi_tlv_tx_pause_id pause_id,
3343 enum wmi_tlv_tx_pause_action action)
3345 struct ath10k_mac_tx_pause arg = {
3347 .pause_id = pause_id,
3351 spin_lock_bh(&ar->htt.tx_lock);
3352 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3353 IEEE80211_IFACE_ITER_RESUME_ALL,
3354 ath10k_mac_handle_tx_pause_iter,
3356 spin_unlock_bh(&ar->htt.tx_lock);
3359 static enum ath10k_hw_txrx_mode
3360 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3361 struct ieee80211_vif *vif,
3362 struct ieee80211_sta *sta,
3363 struct sk_buff *skb)
3365 const struct ieee80211_hdr *hdr = (void *)skb->data;
3366 __le16 fc = hdr->frame_control;
3368 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3369 return ATH10K_HW_TXRX_RAW;
3371 if (ieee80211_is_mgmt(fc))
3372 return ATH10K_HW_TXRX_MGMT;
3376 * NullFunc frames are mostly used to ping if a client or AP are still
3377 * reachable and responsive. This implies tx status reports must be
3378 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3379 * come to a conclusion that the other end disappeared and tear down
3380 * BSS connection or it can never disconnect from BSS/client (which is
3383 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3384 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3385 * which seems to deliver correct tx reports for NullFunc frames. The
3386 * downside of using it is it ignores client powersave state so it can
3387 * end up disconnecting sleeping clients in AP mode. It should fix STA
3388 * mode though because AP don't sleep.
3390 if (ar->htt.target_version_major < 3 &&
3391 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3392 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3393 ar->running_fw->fw_file.fw_features))
3394 return ATH10K_HW_TXRX_MGMT;
3398 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3399 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3400 * to work with Ethernet txmode so use it.
3402 * FIXME: Check if raw mode works with TDLS.
3404 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3405 return ATH10K_HW_TXRX_ETHERNET;
3407 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3408 return ATH10K_HW_TXRX_RAW;
3410 return ATH10K_HW_TXRX_NATIVE_WIFI;
3413 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3414 struct sk_buff *skb)
3416 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3417 const struct ieee80211_hdr *hdr = (void *)skb->data;
3418 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3419 IEEE80211_TX_CTL_INJECTED;
3421 if (!ieee80211_has_protected(hdr->frame_control))
3424 if ((info->flags & mask) == mask)
3428 return !((struct ath10k_vif *)vif->drv_priv)->nohwcrypt;
3433 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3434 * Control in the header.
3436 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3438 struct ieee80211_hdr *hdr = (void *)skb->data;
3439 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3442 if (!ieee80211_is_data_qos(hdr->frame_control))
3445 qos_ctl = ieee80211_get_qos_ctl(hdr);
3446 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3447 skb->data, (void *)qos_ctl - (void *)skb->data);
3448 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3450 /* Some firmware revisions don't handle sending QoS NullFunc well.
3451 * These frames are mainly used for CQM purposes so it doesn't really
3452 * matter whether QoS NullFunc or NullFunc are sent.
3454 hdr = (void *)skb->data;
3455 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3456 cb->flags &= ~ATH10K_SKB_F_QOS;
3458 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3461 static void ath10k_tx_h_8023(struct sk_buff *skb)
3463 struct ieee80211_hdr *hdr;
3464 struct rfc1042_hdr *rfc1042;
3471 hdr = (void *)skb->data;
3472 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3473 rfc1042 = (void *)skb->data + hdrlen;
3475 ether_addr_copy(da, ieee80211_get_DA(hdr));
3476 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3477 type = rfc1042->snap_type;
3479 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3480 skb_push(skb, sizeof(*eth));
3482 eth = (void *)skb->data;
3483 ether_addr_copy(eth->h_dest, da);
3484 ether_addr_copy(eth->h_source, sa);
3485 eth->h_proto = type;
3488 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3489 struct ieee80211_vif *vif,
3490 struct sk_buff *skb)
3492 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3493 struct ath10k_vif *arvif = (void *)vif->drv_priv;
3495 /* This is case only for P2P_GO */
3496 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3499 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3500 spin_lock_bh(&ar->data_lock);
3501 if (arvif->u.ap.noa_data)
3502 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3504 skb_put_data(skb, arvif->u.ap.noa_data,
3505 arvif->u.ap.noa_len);
3506 spin_unlock_bh(&ar->data_lock);
3510 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3511 struct ieee80211_vif *vif,
3512 struct ieee80211_txq *txq,
3513 struct sk_buff *skb)
3515 struct ieee80211_hdr *hdr = (void *)skb->data;
3516 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3519 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3520 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3522 if (ieee80211_is_mgmt(hdr->frame_control))
3523 cb->flags |= ATH10K_SKB_F_MGMT;
3525 if (ieee80211_is_data_qos(hdr->frame_control))
3526 cb->flags |= ATH10K_SKB_F_QOS;
3532 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3534 /* FIXME: Not really sure since when the behaviour changed. At some
3535 * point new firmware stopped requiring creation of peer entries for
3536 * offchannel tx (and actually creating them causes issues with wmi-htc
3537 * tx credit replenishment and reliability). Assuming it's at least 3.4
3538 * because that's when the `freq` was introduced to TX_FRM HTT command.
3540 return (ar->htt.target_version_major >= 3 &&
3541 ar->htt.target_version_minor >= 4 &&
3542 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3545 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3547 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3549 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3550 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3554 skb_queue_tail(q, skb);
3555 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3560 static enum ath10k_mac_tx_path
3561 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3562 struct sk_buff *skb,
3563 enum ath10k_hw_txrx_mode txmode)
3566 case ATH10K_HW_TXRX_RAW:
3567 case ATH10K_HW_TXRX_NATIVE_WIFI:
3568 case ATH10K_HW_TXRX_ETHERNET:
3569 return ATH10K_MAC_TX_HTT;
3570 case ATH10K_HW_TXRX_MGMT:
3571 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3572 ar->running_fw->fw_file.fw_features))
3573 return ATH10K_MAC_TX_WMI_MGMT;
3574 else if (ar->htt.target_version_major >= 3)
3575 return ATH10K_MAC_TX_HTT;
3577 return ATH10K_MAC_TX_HTT_MGMT;
3580 return ATH10K_MAC_TX_UNKNOWN;
3583 static int ath10k_mac_tx_submit(struct ath10k *ar,
3584 enum ath10k_hw_txrx_mode txmode,
3585 enum ath10k_mac_tx_path txpath,
3586 struct sk_buff *skb)
3588 struct ath10k_htt *htt = &ar->htt;
3592 case ATH10K_MAC_TX_HTT:
3593 ret = ath10k_htt_tx(htt, txmode, skb);
3595 case ATH10K_MAC_TX_HTT_MGMT:
3596 ret = ath10k_htt_mgmt_tx(htt, skb);
3598 case ATH10K_MAC_TX_WMI_MGMT:
3599 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3601 case ATH10K_MAC_TX_UNKNOWN:
3608 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3610 ieee80211_free_txskb(ar->hw, skb);
3616 /* This function consumes the sk_buff regardless of return value as far as
3617 * caller is concerned so no freeing is necessary afterwards.
3619 static int ath10k_mac_tx(struct ath10k *ar,
3620 struct ieee80211_vif *vif,
3621 enum ath10k_hw_txrx_mode txmode,
3622 enum ath10k_mac_tx_path txpath,
3623 struct sk_buff *skb, bool noque_offchan)
3625 struct ieee80211_hw *hw = ar->hw;
3626 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3629 /* We should disable CCK RATE due to P2P */
3630 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3631 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3634 case ATH10K_HW_TXRX_MGMT:
3635 case ATH10K_HW_TXRX_NATIVE_WIFI:
3636 ath10k_tx_h_nwifi(hw, skb);
3637 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3638 ath10k_tx_h_seq_no(vif, skb);
3640 case ATH10K_HW_TXRX_ETHERNET:
3641 ath10k_tx_h_8023(skb);
3643 case ATH10K_HW_TXRX_RAW:
3644 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3646 ieee80211_free_txskb(hw, skb);
3651 if (!noque_offchan && info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3652 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3653 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac queued offchannel skb %pK len %d\n",
3656 skb_queue_tail(&ar->offchan_tx_queue, skb);
3657 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3662 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3664 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3671 void ath10k_offchan_tx_purge(struct ath10k *ar)
3673 struct sk_buff *skb;
3676 skb = skb_dequeue(&ar->offchan_tx_queue);
3680 ieee80211_free_txskb(ar->hw, skb);
3684 void ath10k_offchan_tx_work(struct work_struct *work)
3686 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3687 struct ath10k_peer *peer;
3688 struct ath10k_vif *arvif;
3689 enum ath10k_hw_txrx_mode txmode;
3690 enum ath10k_mac_tx_path txpath;
3691 struct ieee80211_hdr *hdr;
3692 struct ieee80211_vif *vif;
3693 struct ieee80211_sta *sta;
3694 struct sk_buff *skb;
3695 const u8 *peer_addr;
3698 unsigned long time_left;
3699 bool tmp_peer_created = false;
3701 /* FW requirement: We must create a peer before FW will send out
3702 * an offchannel frame. Otherwise the frame will be stuck and
3703 * never transmitted. We delete the peer upon tx completion.
3704 * It is unlikely that a peer for offchannel tx will already be
3705 * present. However it may be in some rare cases so account for that.
3706 * Otherwise we might remove a legitimate peer and break stuff.
3710 skb = skb_dequeue(&ar->offchan_tx_queue);
3714 mutex_lock(&ar->conf_mutex);
3716 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK len %d\n",
3719 hdr = (struct ieee80211_hdr *)skb->data;
3720 peer_addr = ieee80211_get_DA(hdr);
3722 spin_lock_bh(&ar->data_lock);
3723 vdev_id = ar->scan.vdev_id;
3724 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3725 spin_unlock_bh(&ar->data_lock);
3728 /* FIXME: should this use ath10k_warn()? */
3729 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3730 peer_addr, vdev_id);
3733 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3735 WMI_PEER_TYPE_DEFAULT);
3737 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3738 peer_addr, vdev_id, ret);
3739 tmp_peer_created = (ret == 0);
3742 spin_lock_bh(&ar->data_lock);
3743 reinit_completion(&ar->offchan_tx_completed);
3744 ar->offchan_tx_skb = skb;
3745 spin_unlock_bh(&ar->data_lock);
3747 /* It's safe to access vif and sta - conf_mutex guarantees that
3748 * sta_state() and remove_interface() are locked exclusively
3749 * out wrt to this offchannel worker.
3751 arvif = ath10k_get_arvif(ar, vdev_id);
3754 sta = ieee80211_find_sta(vif, peer_addr);
3760 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3761 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3763 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, true);
3765 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3771 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3773 ath10k_warn(ar, "timed out waiting for offchannel skb %pK, len: %d\n",
3776 if (!peer && tmp_peer_created) {
3777 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3779 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3780 peer_addr, vdev_id, ret);
3783 mutex_unlock(&ar->conf_mutex);
3787 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3789 struct sk_buff *skb;
3792 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3796 ieee80211_free_txskb(ar->hw, skb);
3800 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3802 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3803 struct sk_buff *skb;
3807 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3811 ret = ath10k_wmi_mgmt_tx(ar, skb);
3813 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3815 ieee80211_free_txskb(ar->hw, skb);
3820 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3822 struct ath10k_txq *artxq;
3827 artxq = (void *)txq->drv_priv;
3828 INIT_LIST_HEAD(&artxq->list);
3831 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3833 struct ath10k_txq *artxq;
3834 struct ath10k_skb_cb *cb;
3835 struct sk_buff *msdu;
3841 artxq = (void *)txq->drv_priv;
3842 spin_lock_bh(&ar->txqs_lock);
3843 if (!list_empty(&artxq->list))
3844 list_del_init(&artxq->list);
3845 spin_unlock_bh(&ar->txqs_lock);
3847 spin_lock_bh(&ar->htt.tx_lock);
3848 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3849 cb = ATH10K_SKB_CB(msdu);
3853 spin_unlock_bh(&ar->htt.tx_lock);
3856 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3860 struct ath10k_peer *peer;
3862 lockdep_assert_held(&ar->data_lock);
3864 peer = ar->peer_map[peer_id];
3872 return peer->sta->txq[tid];
3874 return peer->vif->txq;
3879 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3880 struct ieee80211_txq *txq)
3882 struct ath10k *ar = hw->priv;
3883 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3885 /* No need to get locks */
3887 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3890 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3893 if (artxq->num_fw_queued < artxq->num_push_allowed)
3899 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3900 struct ieee80211_txq *txq)
3902 struct ath10k *ar = hw->priv;
3903 struct ath10k_htt *htt = &ar->htt;
3904 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3905 struct ieee80211_vif *vif = txq->vif;
3906 struct ieee80211_sta *sta = txq->sta;
3907 enum ath10k_hw_txrx_mode txmode;
3908 enum ath10k_mac_tx_path txpath;
3909 struct sk_buff *skb;
3910 struct ieee80211_hdr *hdr;
3912 bool is_mgmt, is_presp;
3915 spin_lock_bh(&ar->htt.tx_lock);
3916 ret = ath10k_htt_tx_inc_pending(htt);
3917 spin_unlock_bh(&ar->htt.tx_lock);
3922 skb = ieee80211_tx_dequeue(hw, txq);
3924 spin_lock_bh(&ar->htt.tx_lock);
3925 ath10k_htt_tx_dec_pending(htt);
3926 spin_unlock_bh(&ar->htt.tx_lock);
3931 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3934 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3935 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3936 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3939 hdr = (struct ieee80211_hdr *)skb->data;
3940 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3942 spin_lock_bh(&ar->htt.tx_lock);
3943 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3946 ath10k_htt_tx_dec_pending(htt);
3947 spin_unlock_bh(&ar->htt.tx_lock);
3950 spin_unlock_bh(&ar->htt.tx_lock);
3953 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
3954 if (unlikely(ret)) {
3955 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3957 spin_lock_bh(&ar->htt.tx_lock);
3958 ath10k_htt_tx_dec_pending(htt);
3960 ath10k_htt_tx_mgmt_dec_pending(htt);
3961 spin_unlock_bh(&ar->htt.tx_lock);
3966 spin_lock_bh(&ar->htt.tx_lock);
3967 artxq->num_fw_queued++;
3968 spin_unlock_bh(&ar->htt.tx_lock);
3973 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3975 struct ieee80211_hw *hw = ar->hw;
3976 struct ieee80211_txq *txq;
3977 struct ath10k_txq *artxq;
3978 struct ath10k_txq *last;
3982 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3985 spin_lock_bh(&ar->txqs_lock);
3988 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3989 while (!list_empty(&ar->txqs)) {
3990 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3991 txq = container_of((void *)artxq, struct ieee80211_txq,
3994 /* Prevent aggressive sta/tid taking over tx queue */
3997 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3998 ret = ath10k_mac_tx_push_txq(hw, txq);
4003 list_del_init(&artxq->list);
4005 list_add_tail(&artxq->list, &ar->txqs);
4007 ath10k_htt_tx_txq_update(hw, txq);
4009 if (artxq == last || (ret < 0 && ret != -ENOENT))
4014 spin_unlock_bh(&ar->txqs_lock);
4016 EXPORT_SYMBOL(ath10k_mac_tx_push_pending);
4022 void __ath10k_scan_finish(struct ath10k *ar)
4024 lockdep_assert_held(&ar->data_lock);
4026 switch (ar->scan.state) {
4027 case ATH10K_SCAN_IDLE:
4029 case ATH10K_SCAN_RUNNING:
4030 case ATH10K_SCAN_ABORTING:
4031 if (!ar->scan.is_roc) {
4032 struct cfg80211_scan_info info = {
4033 .aborted = (ar->scan.state ==
4034 ATH10K_SCAN_ABORTING),
4037 ieee80211_scan_completed(ar->hw, &info);
4038 } else if (ar->scan.roc_notify) {
4039 ieee80211_remain_on_channel_expired(ar->hw);
4042 case ATH10K_SCAN_STARTING:
4043 ar->scan.state = ATH10K_SCAN_IDLE;
4044 ar->scan_channel = NULL;
4045 ar->scan.roc_freq = 0;
4046 ath10k_offchan_tx_purge(ar);
4047 cancel_delayed_work(&ar->scan.timeout);
4048 complete(&ar->scan.completed);
4053 void ath10k_scan_finish(struct ath10k *ar)
4055 spin_lock_bh(&ar->data_lock);
4056 __ath10k_scan_finish(ar);
4057 spin_unlock_bh(&ar->data_lock);
4060 static int ath10k_scan_stop(struct ath10k *ar)
4062 struct wmi_stop_scan_arg arg = {
4063 .req_id = 1, /* FIXME */
4064 .req_type = WMI_SCAN_STOP_ONE,
4065 .u.scan_id = ATH10K_SCAN_ID,
4069 lockdep_assert_held(&ar->conf_mutex);
4071 ret = ath10k_wmi_stop_scan(ar, &arg);
4073 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4077 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4079 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4081 } else if (ret > 0) {
4086 /* Scan state should be updated upon scan completion but in case
4087 * firmware fails to deliver the event (for whatever reason) it is
4088 * desired to clean up scan state anyway. Firmware may have just
4089 * dropped the scan completion event delivery due to transport pipe
4090 * being overflown with data and/or it can recover on its own before
4091 * next scan request is submitted.
4093 spin_lock_bh(&ar->data_lock);
4094 if (ar->scan.state != ATH10K_SCAN_IDLE)
4095 __ath10k_scan_finish(ar);
4096 spin_unlock_bh(&ar->data_lock);
4101 static void ath10k_scan_abort(struct ath10k *ar)
4105 lockdep_assert_held(&ar->conf_mutex);
4107 spin_lock_bh(&ar->data_lock);
4109 switch (ar->scan.state) {
4110 case ATH10K_SCAN_IDLE:
4111 /* This can happen if timeout worker kicked in and called
4112 * abortion while scan completion was being processed.
4115 case ATH10K_SCAN_STARTING:
4116 case ATH10K_SCAN_ABORTING:
4117 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4118 ath10k_scan_state_str(ar->scan.state),
4121 case ATH10K_SCAN_RUNNING:
4122 ar->scan.state = ATH10K_SCAN_ABORTING;
4123 spin_unlock_bh(&ar->data_lock);
4125 ret = ath10k_scan_stop(ar);
4127 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4129 spin_lock_bh(&ar->data_lock);
4133 spin_unlock_bh(&ar->data_lock);
4136 void ath10k_scan_timeout_work(struct work_struct *work)
4138 struct ath10k *ar = container_of(work, struct ath10k,
4141 mutex_lock(&ar->conf_mutex);
4142 ath10k_scan_abort(ar);
4143 mutex_unlock(&ar->conf_mutex);
4146 static int ath10k_start_scan(struct ath10k *ar,
4147 const struct wmi_start_scan_arg *arg)
4151 lockdep_assert_held(&ar->conf_mutex);
4153 ret = ath10k_wmi_start_scan(ar, arg);
4157 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4159 ret = ath10k_scan_stop(ar);
4161 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4166 /* If we failed to start the scan, return error code at
4167 * this point. This is probably due to some issue in the
4168 * firmware, but no need to wedge the driver due to that...
4170 spin_lock_bh(&ar->data_lock);
4171 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4172 spin_unlock_bh(&ar->data_lock);
4175 spin_unlock_bh(&ar->data_lock);
4180 /**********************/
4181 /* mac80211 callbacks */
4182 /**********************/
4184 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4185 struct ieee80211_tx_control *control,
4186 struct sk_buff *skb)
4188 struct ath10k *ar = hw->priv;
4189 struct ath10k_htt *htt = &ar->htt;
4190 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4191 struct ieee80211_vif *vif = info->control.vif;
4192 struct ieee80211_sta *sta = control->sta;
4193 struct ieee80211_txq *txq = NULL;
4194 struct ieee80211_hdr *hdr = (void *)skb->data;
4195 enum ath10k_hw_txrx_mode txmode;
4196 enum ath10k_mac_tx_path txpath;
4202 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4204 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4205 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4206 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4207 txpath == ATH10K_MAC_TX_HTT_MGMT);
4208 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4211 spin_lock_bh(&ar->htt.tx_lock);
4212 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4214 ret = ath10k_htt_tx_inc_pending(htt);
4216 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4218 spin_unlock_bh(&ar->htt.tx_lock);
4219 ieee80211_free_txskb(ar->hw, skb);
4223 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4225 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4227 ath10k_htt_tx_dec_pending(htt);
4228 spin_unlock_bh(&ar->htt.tx_lock);
4229 ieee80211_free_txskb(ar->hw, skb);
4232 spin_unlock_bh(&ar->htt.tx_lock);
4235 ret = ath10k_mac_tx(ar, vif, txmode, txpath, skb, false);
4237 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4239 spin_lock_bh(&ar->htt.tx_lock);
4240 ath10k_htt_tx_dec_pending(htt);
4242 ath10k_htt_tx_mgmt_dec_pending(htt);
4243 spin_unlock_bh(&ar->htt.tx_lock);
4249 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4250 struct ieee80211_txq *txq)
4252 struct ath10k *ar = hw->priv;
4253 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4254 struct ieee80211_txq *f_txq;
4255 struct ath10k_txq *f_artxq;
4259 spin_lock_bh(&ar->txqs_lock);
4260 if (list_empty(&artxq->list))
4261 list_add_tail(&artxq->list, &ar->txqs);
4263 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4264 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4265 list_del_init(&f_artxq->list);
4267 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4268 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4273 list_add_tail(&f_artxq->list, &ar->txqs);
4274 spin_unlock_bh(&ar->txqs_lock);
4276 ath10k_htt_tx_txq_update(hw, f_txq);
4277 ath10k_htt_tx_txq_update(hw, txq);
4280 /* Must not be called with conf_mutex held as workers can use that also. */
4281 void ath10k_drain_tx(struct ath10k *ar)
4283 /* make sure rcu-protected mac80211 tx path itself is drained */
4286 ath10k_offchan_tx_purge(ar);
4287 ath10k_mgmt_over_wmi_tx_purge(ar);
4289 cancel_work_sync(&ar->offchan_tx_work);
4290 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4293 void ath10k_halt(struct ath10k *ar)
4295 struct ath10k_vif *arvif;
4297 lockdep_assert_held(&ar->conf_mutex);
4299 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4300 ar->filter_flags = 0;
4301 ar->monitor = false;
4302 ar->monitor_arvif = NULL;
4304 if (ar->monitor_started)
4305 ath10k_monitor_stop(ar);
4307 ar->monitor_started = false;
4310 ath10k_scan_finish(ar);
4311 ath10k_peer_cleanup_all(ar);
4312 ath10k_core_stop(ar);
4313 ath10k_hif_power_down(ar);
4315 spin_lock_bh(&ar->data_lock);
4316 list_for_each_entry(arvif, &ar->arvifs, list)
4317 ath10k_mac_vif_beacon_cleanup(arvif);
4318 spin_unlock_bh(&ar->data_lock);
4321 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4323 struct ath10k *ar = hw->priv;
4325 mutex_lock(&ar->conf_mutex);
4327 *tx_ant = ar->cfg_tx_chainmask;
4328 *rx_ant = ar->cfg_rx_chainmask;
4330 mutex_unlock(&ar->conf_mutex);
4335 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4337 /* It is not clear that allowing gaps in chainmask
4338 * is helpful. Probably it will not do what user
4339 * is hoping for, so warn in that case.
4341 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4344 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4348 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4350 int nsts = ar->vht_cap_info;
4352 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4353 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4355 /* If firmware does not deliver to host number of space-time
4356 * streams supported, assume it support up to 4 BF STS and return
4357 * the value for VHT CAP: nsts-1)
4365 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4367 int sound_dim = ar->vht_cap_info;
4369 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4370 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4372 /* If the sounding dimension is not advertised by the firmware,
4373 * let's use a default value of 1
4381 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4383 struct ieee80211_sta_vht_cap vht_cap = {0};
4384 struct ath10k_hw_params *hw = &ar->hw_params;
4389 vht_cap.vht_supported = 1;
4390 vht_cap.cap = ar->vht_cap_info;
4392 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4393 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4394 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4395 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4396 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4401 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4402 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4403 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4404 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4405 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4410 /* Currently the firmware seems to be buggy, don't enable 80+80
4411 * mode until that's resolved.
4413 if ((ar->vht_cap_info & IEEE80211_VHT_CAP_SHORT_GI_160) &&
4414 (ar->vht_cap_info & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) == 0)
4415 vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
4418 for (i = 0; i < 8; i++) {
4419 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4420 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4422 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4425 if (ar->cfg_tx_chainmask <= 1)
4426 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4428 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4429 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4431 /* If we are supporting 160Mhz or 80+80, then the NIC may be able to do
4432 * a restricted NSS for 160 or 80+80 vs what it can do for 80Mhz. Give
4433 * user-space a clue if that is the case.
4435 if ((vht_cap.cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) &&
4436 (hw->vht160_mcs_rx_highest != 0 ||
4437 hw->vht160_mcs_tx_highest != 0)) {
4438 vht_cap.vht_mcs.rx_highest = cpu_to_le16(hw->vht160_mcs_rx_highest);
4439 vht_cap.vht_mcs.tx_highest = cpu_to_le16(hw->vht160_mcs_tx_highest);
4445 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4448 struct ieee80211_sta_ht_cap ht_cap = {0};
4450 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4453 ht_cap.ht_supported = 1;
4454 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4455 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4456 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4457 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4459 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4461 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4462 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4464 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4465 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4467 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4470 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4471 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4476 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4477 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4479 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4482 stbc = ar->ht_cap_info;
4483 stbc &= WMI_HT_CAP_RX_STBC;
4484 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4485 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4486 stbc &= IEEE80211_HT_CAP_RX_STBC;
4491 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4492 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4494 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4495 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4497 /* max AMSDU is implicitly taken from vht_cap_info */
4498 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4499 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4501 for (i = 0; i < ar->num_rf_chains; i++) {
4502 if (ar->cfg_rx_chainmask & BIT(i))
4503 ht_cap.mcs.rx_mask[i] = 0xFF;
4506 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4511 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4513 struct ieee80211_supported_band *band;
4514 struct ieee80211_sta_vht_cap vht_cap;
4515 struct ieee80211_sta_ht_cap ht_cap;
4517 ht_cap = ath10k_get_ht_cap(ar);
4518 vht_cap = ath10k_create_vht_cap(ar);
4520 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4521 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4522 band->ht_cap = ht_cap;
4524 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4525 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4526 band->ht_cap = ht_cap;
4527 band->vht_cap = vht_cap;
4531 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4535 lockdep_assert_held(&ar->conf_mutex);
4537 ath10k_check_chain_mask(ar, tx_ant, "tx");
4538 ath10k_check_chain_mask(ar, rx_ant, "rx");
4540 ar->cfg_tx_chainmask = tx_ant;
4541 ar->cfg_rx_chainmask = rx_ant;
4543 if ((ar->state != ATH10K_STATE_ON) &&
4544 (ar->state != ATH10K_STATE_RESTARTED))
4547 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4550 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4555 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4558 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4563 /* Reload HT/VHT capability */
4564 ath10k_mac_setup_ht_vht_cap(ar);
4569 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4571 struct ath10k *ar = hw->priv;
4574 mutex_lock(&ar->conf_mutex);
4575 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4576 mutex_unlock(&ar->conf_mutex);
4580 static int ath10k_start(struct ieee80211_hw *hw)
4582 struct ath10k *ar = hw->priv;
4587 * This makes sense only when restarting hw. It is harmless to call
4588 * unconditionally. This is necessary to make sure no HTT/WMI tx
4589 * commands will be submitted while restarting.
4591 ath10k_drain_tx(ar);
4593 mutex_lock(&ar->conf_mutex);
4595 switch (ar->state) {
4596 case ATH10K_STATE_OFF:
4597 ar->state = ATH10K_STATE_ON;
4599 case ATH10K_STATE_RESTARTING:
4600 ar->state = ATH10K_STATE_RESTARTED;
4602 case ATH10K_STATE_ON:
4603 case ATH10K_STATE_RESTARTED:
4604 case ATH10K_STATE_WEDGED:
4608 case ATH10K_STATE_UTF:
4613 ret = ath10k_hif_power_up(ar);
4615 ath10k_err(ar, "Could not init hif: %d\n", ret);
4619 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4620 &ar->normal_mode_fw);
4622 ath10k_err(ar, "Could not init core: %d\n", ret);
4623 goto err_power_down;
4626 param = ar->wmi.pdev_param->pmf_qos;
4627 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4629 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4633 param = ar->wmi.pdev_param->dynamic_bw;
4634 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4636 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4640 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4641 ret = ath10k_wmi_adaptive_qcs(ar, true);
4643 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4649 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4650 param = ar->wmi.pdev_param->burst_enable;
4651 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4653 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4658 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4661 * By default FW set ARP frames ac to voice (6). In that case ARP
4662 * exchange is not working properly for UAPSD enabled AP. ARP requests
4663 * which arrives with access category 0 are processed by network stack
4664 * and send back with access category 0, but FW changes access category
4665 * to 6. Set ARP frames access category to best effort (0) solves
4669 param = ar->wmi.pdev_param->arp_ac_override;
4670 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4672 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4677 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4678 ar->running_fw->fw_file.fw_features)) {
4679 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4680 WMI_CCA_DETECT_LEVEL_AUTO,
4681 WMI_CCA_DETECT_MARGIN_AUTO);
4683 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4689 param = ar->wmi.pdev_param->ani_enable;
4690 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4692 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4697 ar->ani_enabled = true;
4699 if (ath10k_peer_stats_enabled(ar)) {
4700 param = ar->wmi.pdev_param->peer_stats_update_period;
4701 ret = ath10k_wmi_pdev_set_param(ar, param,
4702 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4705 "failed to set peer stats period : %d\n",
4711 param = ar->wmi.pdev_param->enable_btcoex;
4712 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4713 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4714 ar->running_fw->fw_file.fw_features)) {
4715 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4718 "failed to set btcoex param: %d\n", ret);
4721 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4724 ar->num_started_vdevs = 0;
4725 ath10k_regd_update(ar);
4727 ath10k_spectral_start(ar);
4728 ath10k_thermal_set_throttling(ar);
4730 mutex_unlock(&ar->conf_mutex);
4734 ath10k_core_stop(ar);
4737 ath10k_hif_power_down(ar);
4740 ar->state = ATH10K_STATE_OFF;
4743 mutex_unlock(&ar->conf_mutex);
4747 static void ath10k_stop(struct ieee80211_hw *hw)
4749 struct ath10k *ar = hw->priv;
4751 ath10k_drain_tx(ar);
4753 mutex_lock(&ar->conf_mutex);
4754 if (ar->state != ATH10K_STATE_OFF) {
4756 ar->state = ATH10K_STATE_OFF;
4758 mutex_unlock(&ar->conf_mutex);
4760 cancel_work_sync(&ar->set_coverage_class_work);
4761 cancel_delayed_work_sync(&ar->scan.timeout);
4762 cancel_work_sync(&ar->restart_work);
4765 static int ath10k_config_ps(struct ath10k *ar)
4767 struct ath10k_vif *arvif;
4770 lockdep_assert_held(&ar->conf_mutex);
4772 list_for_each_entry(arvif, &ar->arvifs, list) {
4773 ret = ath10k_mac_vif_setup_ps(arvif);
4775 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4783 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4788 lockdep_assert_held(&ar->conf_mutex);
4790 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4792 param = ar->wmi.pdev_param->txpower_limit2g;
4793 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4795 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4800 param = ar->wmi.pdev_param->txpower_limit5g;
4801 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4803 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4811 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4813 struct ath10k_vif *arvif;
4814 int ret, txpower = -1;
4816 lockdep_assert_held(&ar->conf_mutex);
4818 list_for_each_entry(arvif, &ar->arvifs, list) {
4819 if (arvif->txpower <= 0)
4823 txpower = arvif->txpower;
4825 txpower = min(txpower, arvif->txpower);
4831 ret = ath10k_mac_txpower_setup(ar, txpower);
4833 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4841 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4843 struct ath10k *ar = hw->priv;
4844 struct ieee80211_conf *conf = &hw->conf;
4847 mutex_lock(&ar->conf_mutex);
4849 if (changed & IEEE80211_CONF_CHANGE_PS)
4850 ath10k_config_ps(ar);
4852 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4853 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4854 ret = ath10k_monitor_recalc(ar);
4856 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4859 mutex_unlock(&ar->conf_mutex);
4863 static u32 get_nss_from_chainmask(u16 chain_mask)
4865 if ((chain_mask & 0xf) == 0xf)
4867 else if ((chain_mask & 0x7) == 0x7)
4869 else if ((chain_mask & 0x3) == 0x3)
4874 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4877 struct ath10k *ar = arvif->ar;
4881 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4884 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4885 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4886 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4887 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4889 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4890 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4891 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4892 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4897 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4898 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4900 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4901 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4902 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4904 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4905 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4907 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4908 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4909 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4911 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4912 ar->wmi.vdev_param->txbf, value);
4917 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4918 * because we will send mgmt frames without CCK. This requirement
4919 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4922 static int ath10k_add_interface(struct ieee80211_hw *hw,
4923 struct ieee80211_vif *vif)
4925 struct ath10k *ar = hw->priv;
4926 struct ath10k_vif *arvif = (void *)vif->drv_priv;
4927 struct ath10k_peer *peer;
4928 enum wmi_sta_powersave_param param;
4935 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4937 mutex_lock(&ar->conf_mutex);
4939 memset(arvif, 0, sizeof(*arvif));
4940 ath10k_mac_txq_init(vif->txq);
4945 INIT_LIST_HEAD(&arvif->list);
4946 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4947 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4948 ath10k_mac_vif_sta_connection_loss_work);
4950 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4951 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4952 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4953 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4954 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4955 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4958 if (ar->num_peers >= ar->max_num_peers) {
4959 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4964 if (ar->free_vdev_map == 0) {
4965 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4969 bit = __ffs64(ar->free_vdev_map);
4971 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4972 bit, ar->free_vdev_map);
4974 arvif->vdev_id = bit;
4975 arvif->vdev_subtype =
4976 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4978 switch (vif->type) {
4979 case NL80211_IFTYPE_P2P_DEVICE:
4980 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4981 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4982 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4984 case NL80211_IFTYPE_UNSPECIFIED:
4985 case NL80211_IFTYPE_STATION:
4986 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4988 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4989 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4991 case NL80211_IFTYPE_ADHOC:
4992 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4994 case NL80211_IFTYPE_MESH_POINT:
4995 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4996 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4997 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4998 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5000 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
5003 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5005 case NL80211_IFTYPE_AP:
5006 arvif->vdev_type = WMI_VDEV_TYPE_AP;
5009 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
5010 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
5012 case NL80211_IFTYPE_MONITOR:
5013 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
5020 /* Using vdev_id as queue number will make it very easy to do per-vif
5021 * tx queue locking. This shouldn't wrap due to interface combinations
5022 * but do a modulo for correctness sake and prevent using offchannel tx
5023 * queues for regular vif tx.
5025 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5026 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
5027 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
5029 /* Some firmware revisions don't wait for beacon tx completion before
5030 * sending another SWBA event. This could lead to hardware using old
5031 * (freed) beacon data in some cases, e.g. tx credit starvation
5032 * combined with missed TBTT. This is very very rare.
5034 * On non-IOMMU-enabled hosts this could be a possible security issue
5035 * because hw could beacon some random data on the air. On
5036 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
5037 * device would crash.
5039 * Since there are no beacon tx completions (implicit nor explicit)
5040 * propagated to host the only workaround for this is to allocate a
5041 * DMA-coherent buffer for a lifetime of a vif and use it for all
5042 * beacon tx commands. Worst case for this approach is some beacons may
5043 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
5045 if (vif->type == NL80211_IFTYPE_ADHOC ||
5046 vif->type == NL80211_IFTYPE_MESH_POINT ||
5047 vif->type == NL80211_IFTYPE_AP) {
5048 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
5049 IEEE80211_MAX_FRAME_LEN,
5050 &arvif->beacon_paddr,
5052 if (!arvif->beacon_buf) {
5054 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
5059 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
5060 arvif->nohwcrypt = true;
5062 if (arvif->nohwcrypt &&
5063 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5065 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5069 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5070 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5071 arvif->beacon_buf ? "single-buf" : "per-skb");
5073 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5074 arvif->vdev_subtype, vif->addr);
5076 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5077 arvif->vdev_id, ret);
5081 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5082 spin_lock_bh(&ar->data_lock);
5083 list_add(&arvif->list, &ar->arvifs);
5084 spin_unlock_bh(&ar->data_lock);
5086 /* It makes no sense to have firmware do keepalives. mac80211 already
5087 * takes care of this with idle connection polling.
5089 ret = ath10k_mac_vif_disable_keepalive(arvif);
5091 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5092 arvif->vdev_id, ret);
5093 goto err_vdev_delete;
5096 arvif->def_wep_key_idx = -1;
5098 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5099 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5100 ATH10K_HW_TXRX_NATIVE_WIFI);
5101 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5102 if (ret && ret != -EOPNOTSUPP) {
5103 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5104 arvif->vdev_id, ret);
5105 goto err_vdev_delete;
5108 /* Configuring number of spatial stream for monitor interface is causing
5109 * target assert in qca9888 and qca6174.
5111 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5112 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5114 vdev_param = ar->wmi.vdev_param->nss;
5115 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5118 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5119 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5121 goto err_vdev_delete;
5125 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5126 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5127 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5128 vif->addr, WMI_PEER_TYPE_DEFAULT);
5130 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5131 arvif->vdev_id, ret);
5132 goto err_vdev_delete;
5135 spin_lock_bh(&ar->data_lock);
5137 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5139 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5140 vif->addr, arvif->vdev_id);
5141 spin_unlock_bh(&ar->data_lock);
5143 goto err_peer_delete;
5146 arvif->peer_id = find_first_bit(peer->peer_ids,
5147 ATH10K_MAX_NUM_PEER_IDS);
5149 spin_unlock_bh(&ar->data_lock);
5151 arvif->peer_id = HTT_INVALID_PEERID;
5154 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5155 ret = ath10k_mac_set_kickout(arvif);
5157 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5158 arvif->vdev_id, ret);
5159 goto err_peer_delete;
5163 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5164 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5165 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5166 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5169 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5170 arvif->vdev_id, ret);
5171 goto err_peer_delete;
5174 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5176 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5177 arvif->vdev_id, ret);
5178 goto err_peer_delete;
5181 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5183 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5184 arvif->vdev_id, ret);
5185 goto err_peer_delete;
5189 ret = ath10k_mac_set_txbf_conf(arvif);
5191 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5192 arvif->vdev_id, ret);
5193 goto err_peer_delete;
5196 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5198 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5199 arvif->vdev_id, ret);
5200 goto err_peer_delete;
5203 arvif->txpower = vif->bss_conf.txpower;
5204 ret = ath10k_mac_txpower_recalc(ar);
5206 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5207 goto err_peer_delete;
5210 if (vif->type == NL80211_IFTYPE_MONITOR) {
5211 ar->monitor_arvif = arvif;
5212 ret = ath10k_monitor_recalc(ar);
5214 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5215 goto err_peer_delete;
5219 spin_lock_bh(&ar->htt.tx_lock);
5221 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5222 spin_unlock_bh(&ar->htt.tx_lock);
5224 mutex_unlock(&ar->conf_mutex);
5228 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5229 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5230 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5233 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5234 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5235 spin_lock_bh(&ar->data_lock);
5236 list_del(&arvif->list);
5237 spin_unlock_bh(&ar->data_lock);
5240 if (arvif->beacon_buf) {
5241 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5242 arvif->beacon_buf, arvif->beacon_paddr);
5243 arvif->beacon_buf = NULL;
5246 mutex_unlock(&ar->conf_mutex);
5251 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5255 for (i = 0; i < BITS_PER_LONG; i++)
5256 ath10k_mac_vif_tx_unlock(arvif, i);
5259 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5260 struct ieee80211_vif *vif)
5262 struct ath10k *ar = hw->priv;
5263 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5264 struct ath10k_peer *peer;
5268 cancel_work_sync(&arvif->ap_csa_work);
5269 cancel_delayed_work_sync(&arvif->connection_loss_work);
5271 mutex_lock(&ar->conf_mutex);
5273 spin_lock_bh(&ar->data_lock);
5274 ath10k_mac_vif_beacon_cleanup(arvif);
5275 spin_unlock_bh(&ar->data_lock);
5277 ret = ath10k_spectral_vif_stop(arvif);
5279 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5280 arvif->vdev_id, ret);
5282 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5283 spin_lock_bh(&ar->data_lock);
5284 list_del(&arvif->list);
5285 spin_unlock_bh(&ar->data_lock);
5287 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5288 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5289 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5292 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5293 arvif->vdev_id, ret);
5295 kfree(arvif->u.ap.noa_data);
5298 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5301 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5303 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5304 arvif->vdev_id, ret);
5306 /* Some firmware revisions don't notify host about self-peer removal
5307 * until after associated vdev is deleted.
5309 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5310 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5311 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5314 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5315 arvif->vdev_id, ret);
5317 spin_lock_bh(&ar->data_lock);
5319 spin_unlock_bh(&ar->data_lock);
5322 spin_lock_bh(&ar->data_lock);
5323 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5324 peer = ar->peer_map[i];
5328 if (peer->vif == vif) {
5329 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5330 vif->addr, arvif->vdev_id);
5334 spin_unlock_bh(&ar->data_lock);
5336 ath10k_peer_cleanup(ar, arvif->vdev_id);
5337 ath10k_mac_txq_unref(ar, vif->txq);
5339 if (vif->type == NL80211_IFTYPE_MONITOR) {
5340 ar->monitor_arvif = NULL;
5341 ret = ath10k_monitor_recalc(ar);
5343 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5346 ret = ath10k_mac_txpower_recalc(ar);
5348 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5350 spin_lock_bh(&ar->htt.tx_lock);
5351 ath10k_mac_vif_tx_unlock_all(arvif);
5352 spin_unlock_bh(&ar->htt.tx_lock);
5354 ath10k_mac_txq_unref(ar, vif->txq);
5356 mutex_unlock(&ar->conf_mutex);
5360 * FIXME: Has to be verified.
5362 #define SUPPORTED_FILTERS \
5367 FIF_BCN_PRBRESP_PROMISC | \
5371 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5372 unsigned int changed_flags,
5373 unsigned int *total_flags,
5376 struct ath10k *ar = hw->priv;
5379 mutex_lock(&ar->conf_mutex);
5381 changed_flags &= SUPPORTED_FILTERS;
5382 *total_flags &= SUPPORTED_FILTERS;
5383 ar->filter_flags = *total_flags;
5385 ret = ath10k_monitor_recalc(ar);
5387 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5389 mutex_unlock(&ar->conf_mutex);
5392 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5393 struct ieee80211_vif *vif,
5394 struct ieee80211_bss_conf *info,
5397 struct ath10k *ar = hw->priv;
5398 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5400 u32 vdev_param, pdev_param, slottime, preamble;
5402 mutex_lock(&ar->conf_mutex);
5404 if (changed & BSS_CHANGED_IBSS)
5405 ath10k_control_ibss(arvif, info, vif->addr);
5407 if (changed & BSS_CHANGED_BEACON_INT) {
5408 arvif->beacon_interval = info->beacon_int;
5409 vdev_param = ar->wmi.vdev_param->beacon_interval;
5410 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5411 arvif->beacon_interval);
5412 ath10k_dbg(ar, ATH10K_DBG_MAC,
5413 "mac vdev %d beacon_interval %d\n",
5414 arvif->vdev_id, arvif->beacon_interval);
5417 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5418 arvif->vdev_id, ret);
5421 if (changed & BSS_CHANGED_BEACON) {
5422 ath10k_dbg(ar, ATH10K_DBG_MAC,
5423 "vdev %d set beacon tx mode to staggered\n",
5426 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5427 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5428 WMI_BEACON_STAGGERED_MODE);
5430 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5431 arvif->vdev_id, ret);
5433 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5435 ath10k_warn(ar, "failed to update beacon template: %d\n",
5438 if (ieee80211_vif_is_mesh(vif)) {
5439 /* mesh doesn't use SSID but firmware needs it */
5440 strncpy(arvif->u.ap.ssid, "mesh",
5441 sizeof(arvif->u.ap.ssid));
5442 arvif->u.ap.ssid_len = 4;
5446 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5447 ret = ath10k_mac_setup_prb_tmpl(arvif);
5449 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5450 arvif->vdev_id, ret);
5453 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5454 arvif->dtim_period = info->dtim_period;
5456 ath10k_dbg(ar, ATH10K_DBG_MAC,
5457 "mac vdev %d dtim_period %d\n",
5458 arvif->vdev_id, arvif->dtim_period);
5460 vdev_param = ar->wmi.vdev_param->dtim_period;
5461 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5462 arvif->dtim_period);
5464 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5465 arvif->vdev_id, ret);
5468 if (changed & BSS_CHANGED_SSID &&
5469 vif->type == NL80211_IFTYPE_AP) {
5470 arvif->u.ap.ssid_len = info->ssid_len;
5472 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5473 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5476 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5477 ether_addr_copy(arvif->bssid, info->bssid);
5479 if (changed & BSS_CHANGED_BEACON_ENABLED)
5480 ath10k_control_beaconing(arvif, info);
5482 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5483 arvif->use_cts_prot = info->use_cts_prot;
5485 ret = ath10k_recalc_rtscts_prot(arvif);
5487 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5488 arvif->vdev_id, ret);
5490 if (ath10k_mac_can_set_cts_prot(arvif)) {
5491 ret = ath10k_mac_set_cts_prot(arvif);
5493 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5494 arvif->vdev_id, ret);
5498 if (changed & BSS_CHANGED_ERP_SLOT) {
5499 if (info->use_short_slot)
5500 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5503 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5505 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5506 arvif->vdev_id, slottime);
5508 vdev_param = ar->wmi.vdev_param->slot_time;
5509 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5512 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5513 arvif->vdev_id, ret);
5516 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5517 if (info->use_short_preamble)
5518 preamble = WMI_VDEV_PREAMBLE_SHORT;
5520 preamble = WMI_VDEV_PREAMBLE_LONG;
5522 ath10k_dbg(ar, ATH10K_DBG_MAC,
5523 "mac vdev %d preamble %dn",
5524 arvif->vdev_id, preamble);
5526 vdev_param = ar->wmi.vdev_param->preamble;
5527 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5530 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5531 arvif->vdev_id, ret);
5534 if (changed & BSS_CHANGED_ASSOC) {
5536 /* Workaround: Make sure monitor vdev is not running
5537 * when associating to prevent some firmware revisions
5538 * (e.g. 10.1 and 10.2) from crashing.
5540 if (ar->monitor_started)
5541 ath10k_monitor_stop(ar);
5542 ath10k_bss_assoc(hw, vif, info);
5543 ath10k_monitor_recalc(ar);
5545 ath10k_bss_disassoc(hw, vif);
5549 if (changed & BSS_CHANGED_TXPOWER) {
5550 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5551 arvif->vdev_id, info->txpower);
5553 arvif->txpower = info->txpower;
5554 ret = ath10k_mac_txpower_recalc(ar);
5556 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5559 if (changed & BSS_CHANGED_PS) {
5560 arvif->ps = vif->bss_conf.ps;
5562 ret = ath10k_config_ps(ar);
5564 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5565 arvif->vdev_id, ret);
5568 mutex_unlock(&ar->conf_mutex);
5571 static void ath10k_mac_op_set_coverage_class(struct ieee80211_hw *hw, s16 value)
5573 struct ath10k *ar = hw->priv;
5575 /* This function should never be called if setting the coverage class
5576 * is not supported on this hardware.
5578 if (!ar->hw_params.hw_ops->set_coverage_class) {
5582 ar->hw_params.hw_ops->set_coverage_class(ar, value);
5585 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5586 struct ieee80211_vif *vif,
5587 struct ieee80211_scan_request *hw_req)
5589 struct ath10k *ar = hw->priv;
5590 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5591 struct cfg80211_scan_request *req = &hw_req->req;
5592 struct wmi_start_scan_arg arg;
5596 mutex_lock(&ar->conf_mutex);
5598 spin_lock_bh(&ar->data_lock);
5599 switch (ar->scan.state) {
5600 case ATH10K_SCAN_IDLE:
5601 reinit_completion(&ar->scan.started);
5602 reinit_completion(&ar->scan.completed);
5603 ar->scan.state = ATH10K_SCAN_STARTING;
5604 ar->scan.is_roc = false;
5605 ar->scan.vdev_id = arvif->vdev_id;
5608 case ATH10K_SCAN_STARTING:
5609 case ATH10K_SCAN_RUNNING:
5610 case ATH10K_SCAN_ABORTING:
5614 spin_unlock_bh(&ar->data_lock);
5619 memset(&arg, 0, sizeof(arg));
5620 ath10k_wmi_start_scan_init(ar, &arg);
5621 arg.vdev_id = arvif->vdev_id;
5622 arg.scan_id = ATH10K_SCAN_ID;
5625 arg.ie_len = req->ie_len;
5626 memcpy(arg.ie, req->ie, arg.ie_len);
5630 arg.n_ssids = req->n_ssids;
5631 for (i = 0; i < arg.n_ssids; i++) {
5632 arg.ssids[i].len = req->ssids[i].ssid_len;
5633 arg.ssids[i].ssid = req->ssids[i].ssid;
5636 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5639 if (req->n_channels) {
5640 arg.n_channels = req->n_channels;
5641 for (i = 0; i < arg.n_channels; i++)
5642 arg.channels[i] = req->channels[i]->center_freq;
5645 ret = ath10k_start_scan(ar, &arg);
5647 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5648 spin_lock_bh(&ar->data_lock);
5649 ar->scan.state = ATH10K_SCAN_IDLE;
5650 spin_unlock_bh(&ar->data_lock);
5653 /* Add a 200ms margin to account for event/command processing */
5654 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5655 msecs_to_jiffies(arg.max_scan_time +
5659 mutex_unlock(&ar->conf_mutex);
5663 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5664 struct ieee80211_vif *vif)
5666 struct ath10k *ar = hw->priv;
5668 mutex_lock(&ar->conf_mutex);
5669 ath10k_scan_abort(ar);
5670 mutex_unlock(&ar->conf_mutex);
5672 cancel_delayed_work_sync(&ar->scan.timeout);
5675 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5676 struct ath10k_vif *arvif,
5677 enum set_key_cmd cmd,
5678 struct ieee80211_key_conf *key)
5680 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5683 /* 10.1 firmware branch requires default key index to be set to group
5684 * key index after installing it. Otherwise FW/HW Txes corrupted
5685 * frames with multi-vif APs. This is not required for main firmware
5686 * branch (e.g. 636).
5688 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5690 * FIXME: It remains unknown if this is required for multi-vif STA
5691 * interfaces on 10.1.
5694 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5695 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5698 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5701 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5704 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5710 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5713 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5714 arvif->vdev_id, ret);
5717 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5718 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5719 struct ieee80211_key_conf *key)
5721 struct ath10k *ar = hw->priv;
5722 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5723 struct ath10k_peer *peer;
5724 const u8 *peer_addr;
5725 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5726 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5732 /* this one needs to be done in software */
5733 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5736 if (arvif->nohwcrypt)
5739 if (key->keyidx > WMI_MAX_KEY_INDEX)
5742 mutex_lock(&ar->conf_mutex);
5745 peer_addr = sta->addr;
5746 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5747 peer_addr = vif->bss_conf.bssid;
5749 peer_addr = vif->addr;
5751 key->hw_key_idx = key->keyidx;
5755 arvif->wep_keys[key->keyidx] = key;
5757 arvif->wep_keys[key->keyidx] = NULL;
5760 /* the peer should not disappear in mid-way (unless FW goes awry) since
5761 * we already hold conf_mutex. we just make sure its there now.
5763 spin_lock_bh(&ar->data_lock);
5764 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5765 spin_unlock_bh(&ar->data_lock);
5768 if (cmd == SET_KEY) {
5769 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5774 /* if the peer doesn't exist there is no key to disable anymore */
5779 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5780 flags |= WMI_KEY_PAIRWISE;
5782 flags |= WMI_KEY_GROUP;
5785 if (cmd == DISABLE_KEY)
5786 ath10k_clear_vdev_key(arvif, key);
5788 /* When WEP keys are uploaded it's possible that there are
5789 * stations associated already (e.g. when merging) without any
5790 * keys. Static WEP needs an explicit per-peer key upload.
5792 if (vif->type == NL80211_IFTYPE_ADHOC &&
5794 ath10k_mac_vif_update_wep_key(arvif, key);
5796 /* 802.1x never sets the def_wep_key_idx so each set_key()
5797 * call changes default tx key.
5799 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5800 * after first set_key().
5802 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5803 flags |= WMI_KEY_TX_USAGE;
5806 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5809 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5810 arvif->vdev_id, peer_addr, ret);
5814 /* mac80211 sets static WEP keys as groupwise while firmware requires
5815 * them to be installed twice as both pairwise and groupwise.
5817 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5819 flags2 &= ~WMI_KEY_GROUP;
5820 flags2 |= WMI_KEY_PAIRWISE;
5822 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5825 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5826 arvif->vdev_id, peer_addr, ret);
5827 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5831 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5832 arvif->vdev_id, peer_addr, ret2);
5838 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5840 spin_lock_bh(&ar->data_lock);
5841 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5842 if (peer && cmd == SET_KEY)
5843 peer->keys[key->keyidx] = key;
5844 else if (peer && cmd == DISABLE_KEY)
5845 peer->keys[key->keyidx] = NULL;
5846 else if (peer == NULL)
5847 /* impossible unless FW goes crazy */
5848 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5849 spin_unlock_bh(&ar->data_lock);
5852 mutex_unlock(&ar->conf_mutex);
5856 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5857 struct ieee80211_vif *vif,
5860 struct ath10k *ar = hw->priv;
5861 struct ath10k_vif *arvif = (void *)vif->drv_priv;
5864 mutex_lock(&arvif->ar->conf_mutex);
5866 if (arvif->ar->state != ATH10K_STATE_ON)
5869 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5870 arvif->vdev_id, keyidx);
5872 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5874 arvif->ar->wmi.vdev_param->def_keyid,
5878 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5884 arvif->def_wep_key_idx = keyidx;
5887 mutex_unlock(&arvif->ar->conf_mutex);
5890 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5893 struct ath10k_vif *arvif;
5894 struct ath10k_sta *arsta;
5895 struct ieee80211_sta *sta;
5896 struct cfg80211_chan_def def;
5897 enum nl80211_band band;
5898 const u8 *ht_mcs_mask;
5899 const u16 *vht_mcs_mask;
5900 u32 changed, bw, nss, smps;
5903 arsta = container_of(wk, struct ath10k_sta, update_wk);
5904 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5905 arvif = arsta->arvif;
5908 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5911 band = def.chan->band;
5912 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5913 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5915 spin_lock_bh(&ar->data_lock);
5917 changed = arsta->changed;
5924 spin_unlock_bh(&ar->data_lock);
5926 mutex_lock(&ar->conf_mutex);
5928 nss = max_t(u32, 1, nss);
5929 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5930 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5932 if (changed & IEEE80211_RC_BW_CHANGED) {
5933 enum wmi_phy_mode mode;
5935 mode = chan_to_phymode(&def);
5936 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
5937 sta->addr, bw, mode);
5939 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5940 WMI_PEER_PHYMODE, mode);
5942 ath10k_warn(ar, "failed to update STA %pM peer phymode %d: %d\n",
5943 sta->addr, mode, err);
5947 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5948 WMI_PEER_CHAN_WIDTH, bw);
5950 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5951 sta->addr, bw, err);
5954 if (changed & IEEE80211_RC_NSS_CHANGED) {
5955 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5958 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5961 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5962 sta->addr, nss, err);
5965 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5966 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5969 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5970 WMI_PEER_SMPS_STATE, smps);
5972 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5973 sta->addr, smps, err);
5976 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5977 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5980 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5982 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5987 mutex_unlock(&ar->conf_mutex);
5990 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5991 struct ieee80211_sta *sta)
5993 struct ath10k *ar = arvif->ar;
5995 lockdep_assert_held(&ar->conf_mutex);
5997 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6000 if (ar->num_stations >= ar->max_num_stations)
6008 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
6009 struct ieee80211_sta *sta)
6011 struct ath10k *ar = arvif->ar;
6013 lockdep_assert_held(&ar->conf_mutex);
6015 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6021 struct ath10k_mac_tdls_iter_data {
6022 u32 num_tdls_stations;
6023 struct ieee80211_vif *curr_vif;
6026 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
6027 struct ieee80211_sta *sta)
6029 struct ath10k_mac_tdls_iter_data *iter_data = data;
6030 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6031 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
6033 if (sta->tdls && sta_vif == iter_data->curr_vif)
6034 iter_data->num_tdls_stations++;
6037 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
6038 struct ieee80211_vif *vif)
6040 struct ath10k_mac_tdls_iter_data data = {};
6042 data.curr_vif = vif;
6044 ieee80211_iterate_stations_atomic(hw,
6045 ath10k_mac_tdls_vif_stations_count_iter,
6047 return data.num_tdls_stations;
6050 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
6051 struct ieee80211_vif *vif)
6053 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6054 int *num_tdls_vifs = data;
6056 if (vif->type != NL80211_IFTYPE_STATION)
6059 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
6063 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
6065 int num_tdls_vifs = 0;
6067 ieee80211_iterate_active_interfaces_atomic(hw,
6068 IEEE80211_IFACE_ITER_NORMAL,
6069 ath10k_mac_tdls_vifs_count_iter,
6071 return num_tdls_vifs;
6074 static int ath10k_sta_state(struct ieee80211_hw *hw,
6075 struct ieee80211_vif *vif,
6076 struct ieee80211_sta *sta,
6077 enum ieee80211_sta_state old_state,
6078 enum ieee80211_sta_state new_state)
6080 struct ath10k *ar = hw->priv;
6081 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6082 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6083 struct ath10k_peer *peer;
6087 if (old_state == IEEE80211_STA_NOTEXIST &&
6088 new_state == IEEE80211_STA_NONE) {
6089 memset(arsta, 0, sizeof(*arsta));
6090 arsta->arvif = arvif;
6091 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6093 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6094 ath10k_mac_txq_init(sta->txq[i]);
6097 /* cancel must be done outside the mutex to avoid deadlock */
6098 if ((old_state == IEEE80211_STA_NONE &&
6099 new_state == IEEE80211_STA_NOTEXIST))
6100 cancel_work_sync(&arsta->update_wk);
6102 mutex_lock(&ar->conf_mutex);
6104 if (old_state == IEEE80211_STA_NOTEXIST &&
6105 new_state == IEEE80211_STA_NONE) {
6107 * New station addition.
6109 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6110 u32 num_tdls_stations;
6113 ath10k_dbg(ar, ATH10K_DBG_MAC,
6114 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6115 arvif->vdev_id, sta->addr,
6116 ar->num_stations + 1, ar->max_num_stations,
6117 ar->num_peers + 1, ar->max_num_peers);
6119 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6120 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6123 if (num_tdls_stations >= ar->max_num_tdls_vdevs) {
6124 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6126 ar->max_num_tdls_vdevs);
6130 peer_type = WMI_PEER_TYPE_TDLS;
6133 ret = ath10k_mac_inc_num_stations(arvif, sta);
6135 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6136 ar->max_num_stations);
6140 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6141 sta->addr, peer_type);
6143 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6144 sta->addr, arvif->vdev_id, ret);
6145 ath10k_mac_dec_num_stations(arvif, sta);
6149 spin_lock_bh(&ar->data_lock);
6151 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6153 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6154 vif->addr, arvif->vdev_id);
6155 spin_unlock_bh(&ar->data_lock);
6156 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6157 ath10k_mac_dec_num_stations(arvif, sta);
6162 arsta->peer_id = find_first_bit(peer->peer_ids,
6163 ATH10K_MAX_NUM_PEER_IDS);
6165 spin_unlock_bh(&ar->data_lock);
6170 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6171 WMI_TDLS_ENABLE_ACTIVE);
6173 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6174 arvif->vdev_id, ret);
6175 ath10k_peer_delete(ar, arvif->vdev_id,
6177 ath10k_mac_dec_num_stations(arvif, sta);
6181 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6182 WMI_TDLS_PEER_STATE_PEERING);
6185 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6186 sta->addr, arvif->vdev_id, ret);
6187 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6188 ath10k_mac_dec_num_stations(arvif, sta);
6190 if (num_tdls_stations != 0)
6192 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6195 } else if ((old_state == IEEE80211_STA_NONE &&
6196 new_state == IEEE80211_STA_NOTEXIST)) {
6198 * Existing station deletion.
6200 ath10k_dbg(ar, ATH10K_DBG_MAC,
6201 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6202 arvif->vdev_id, sta->addr, sta);
6205 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6207 WMI_TDLS_PEER_STATE_TEARDOWN);
6209 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6211 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6214 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6216 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6217 sta->addr, arvif->vdev_id, ret);
6219 ath10k_mac_dec_num_stations(arvif, sta);
6221 spin_lock_bh(&ar->data_lock);
6222 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6223 peer = ar->peer_map[i];
6227 if (peer->sta == sta) {
6228 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6229 sta->addr, peer, i, arvif->vdev_id);
6232 /* Clean up the peer object as well since we
6233 * must have failed to do this above.
6235 list_del(&peer->list);
6236 ar->peer_map[i] = NULL;
6241 spin_unlock_bh(&ar->data_lock);
6243 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6244 ath10k_mac_txq_unref(ar, sta->txq[i]);
6249 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6252 /* This was the last tdls peer in current vif */
6253 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6256 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6257 arvif->vdev_id, ret);
6259 } else if (old_state == IEEE80211_STA_AUTH &&
6260 new_state == IEEE80211_STA_ASSOC &&
6261 (vif->type == NL80211_IFTYPE_AP ||
6262 vif->type == NL80211_IFTYPE_MESH_POINT ||
6263 vif->type == NL80211_IFTYPE_ADHOC)) {
6267 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6270 ret = ath10k_station_assoc(ar, vif, sta, false);
6272 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6273 sta->addr, arvif->vdev_id, ret);
6274 } else if (old_state == IEEE80211_STA_ASSOC &&
6275 new_state == IEEE80211_STA_AUTHORIZED &&
6278 * Tdls station authorized.
6280 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6283 ret = ath10k_station_assoc(ar, vif, sta, false);
6285 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6286 sta->addr, arvif->vdev_id, ret);
6290 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6291 WMI_TDLS_PEER_STATE_CONNECTED);
6293 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6294 sta->addr, arvif->vdev_id, ret);
6295 } else if (old_state == IEEE80211_STA_ASSOC &&
6296 new_state == IEEE80211_STA_AUTH &&
6297 (vif->type == NL80211_IFTYPE_AP ||
6298 vif->type == NL80211_IFTYPE_MESH_POINT ||
6299 vif->type == NL80211_IFTYPE_ADHOC)) {
6303 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6306 ret = ath10k_station_disassoc(ar, vif, sta);
6308 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6309 sta->addr, arvif->vdev_id, ret);
6312 mutex_unlock(&ar->conf_mutex);
6316 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6317 u16 ac, bool enable)
6319 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6320 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6321 u32 prio = 0, acc = 0;
6325 lockdep_assert_held(&ar->conf_mutex);
6327 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6331 case IEEE80211_AC_VO:
6332 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6333 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6337 case IEEE80211_AC_VI:
6338 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6339 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6343 case IEEE80211_AC_BE:
6344 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6345 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6349 case IEEE80211_AC_BK:
6350 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6351 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6358 arvif->u.sta.uapsd |= value;
6360 arvif->u.sta.uapsd &= ~value;
6362 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6363 WMI_STA_PS_PARAM_UAPSD,
6364 arvif->u.sta.uapsd);
6366 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6370 if (arvif->u.sta.uapsd)
6371 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6373 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6375 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6376 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6379 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6381 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6383 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6384 arvif->vdev_id, ret);
6388 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6390 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6391 arvif->vdev_id, ret);
6395 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6396 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6397 /* Only userspace can make an educated decision when to send
6398 * trigger frame. The following effectively disables u-UAPSD
6399 * autotrigger in firmware (which is enabled by default
6400 * provided the autotrigger service is available).
6404 arg.user_priority = prio;
6405 arg.service_interval = 0;
6406 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6407 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6409 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6410 arvif->bssid, &arg, 1);
6412 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6422 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6423 struct ieee80211_vif *vif, u16 ac,
6424 const struct ieee80211_tx_queue_params *params)
6426 struct ath10k *ar = hw->priv;
6427 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6428 struct wmi_wmm_params_arg *p = NULL;
6431 mutex_lock(&ar->conf_mutex);
6434 case IEEE80211_AC_VO:
6435 p = &arvif->wmm_params.ac_vo;
6437 case IEEE80211_AC_VI:
6438 p = &arvif->wmm_params.ac_vi;
6440 case IEEE80211_AC_BE:
6441 p = &arvif->wmm_params.ac_be;
6443 case IEEE80211_AC_BK:
6444 p = &arvif->wmm_params.ac_bk;
6453 p->cwmin = params->cw_min;
6454 p->cwmax = params->cw_max;
6455 p->aifs = params->aifs;
6458 * The channel time duration programmed in the HW is in absolute
6459 * microseconds, while mac80211 gives the txop in units of
6462 p->txop = params->txop * 32;
6464 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6465 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6466 &arvif->wmm_params);
6468 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6469 arvif->vdev_id, ret);
6473 /* This won't work well with multi-interface cases but it's
6474 * better than nothing.
6476 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6478 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6483 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6485 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6488 mutex_unlock(&ar->conf_mutex);
6492 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6494 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6495 struct ieee80211_vif *vif,
6496 struct ieee80211_channel *chan,
6498 enum ieee80211_roc_type type)
6500 struct ath10k *ar = hw->priv;
6501 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6502 struct wmi_start_scan_arg arg;
6506 mutex_lock(&ar->conf_mutex);
6508 spin_lock_bh(&ar->data_lock);
6509 switch (ar->scan.state) {
6510 case ATH10K_SCAN_IDLE:
6511 reinit_completion(&ar->scan.started);
6512 reinit_completion(&ar->scan.completed);
6513 reinit_completion(&ar->scan.on_channel);
6514 ar->scan.state = ATH10K_SCAN_STARTING;
6515 ar->scan.is_roc = true;
6516 ar->scan.vdev_id = arvif->vdev_id;
6517 ar->scan.roc_freq = chan->center_freq;
6518 ar->scan.roc_notify = true;
6521 case ATH10K_SCAN_STARTING:
6522 case ATH10K_SCAN_RUNNING:
6523 case ATH10K_SCAN_ABORTING:
6527 spin_unlock_bh(&ar->data_lock);
6532 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6534 memset(&arg, 0, sizeof(arg));
6535 ath10k_wmi_start_scan_init(ar, &arg);
6536 arg.vdev_id = arvif->vdev_id;
6537 arg.scan_id = ATH10K_SCAN_ID;
6539 arg.channels[0] = chan->center_freq;
6540 arg.dwell_time_active = scan_time_msec;
6541 arg.dwell_time_passive = scan_time_msec;
6542 arg.max_scan_time = scan_time_msec;
6543 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6544 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6545 arg.burst_duration_ms = duration;
6547 ret = ath10k_start_scan(ar, &arg);
6549 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6550 spin_lock_bh(&ar->data_lock);
6551 ar->scan.state = ATH10K_SCAN_IDLE;
6552 spin_unlock_bh(&ar->data_lock);
6556 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6558 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6560 ret = ath10k_scan_stop(ar);
6562 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6568 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6569 msecs_to_jiffies(duration));
6573 mutex_unlock(&ar->conf_mutex);
6577 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6579 struct ath10k *ar = hw->priv;
6581 mutex_lock(&ar->conf_mutex);
6583 spin_lock_bh(&ar->data_lock);
6584 ar->scan.roc_notify = false;
6585 spin_unlock_bh(&ar->data_lock);
6587 ath10k_scan_abort(ar);
6589 mutex_unlock(&ar->conf_mutex);
6591 cancel_delayed_work_sync(&ar->scan.timeout);
6597 * Both RTS and Fragmentation threshold are interface-specific
6598 * in ath10k, but device-specific in mac80211.
6601 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6603 struct ath10k *ar = hw->priv;
6604 struct ath10k_vif *arvif;
6607 mutex_lock(&ar->conf_mutex);
6608 list_for_each_entry(arvif, &ar->arvifs, list) {
6609 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6610 arvif->vdev_id, value);
6612 ret = ath10k_mac_set_rts(arvif, value);
6614 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6615 arvif->vdev_id, ret);
6619 mutex_unlock(&ar->conf_mutex);
6624 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6626 /* Even though there's a WMI enum for fragmentation threshold no known
6627 * firmware actually implements it. Moreover it is not possible to rely
6628 * frame fragmentation to mac80211 because firmware clears the "more
6629 * fragments" bit in frame control making it impossible for remote
6630 * devices to reassemble frames.
6632 * Hence implement a dummy callback just to say fragmentation isn't
6633 * supported. This effectively prevents mac80211 from doing frame
6634 * fragmentation in software.
6639 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6640 u32 queues, bool drop)
6642 struct ath10k *ar = hw->priv;
6646 /* mac80211 doesn't care if we really xmit queued frames or not
6647 * we'll collect those frames either way if we stop/delete vdevs
6652 mutex_lock(&ar->conf_mutex);
6654 if (ar->state == ATH10K_STATE_WEDGED)
6657 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6660 spin_lock_bh(&ar->htt.tx_lock);
6661 empty = (ar->htt.num_pending_tx == 0);
6662 spin_unlock_bh(&ar->htt.tx_lock);
6664 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6665 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6669 }), ATH10K_FLUSH_TIMEOUT_HZ);
6671 if (time_left == 0 || skip)
6672 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6673 skip, ar->state, time_left);
6676 mutex_unlock(&ar->conf_mutex);
6679 /* TODO: Implement this function properly
6680 * For now it is needed to reply to Probe Requests in IBSS mode.
6681 * Propably we need this information from FW.
6683 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6688 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6689 enum ieee80211_reconfig_type reconfig_type)
6691 struct ath10k *ar = hw->priv;
6693 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6696 mutex_lock(&ar->conf_mutex);
6698 /* If device failed to restart it will be in a different state, e.g.
6699 * ATH10K_STATE_WEDGED
6701 if (ar->state == ATH10K_STATE_RESTARTED) {
6702 ath10k_info(ar, "device successfully recovered\n");
6703 ar->state = ATH10K_STATE_ON;
6704 ieee80211_wake_queues(ar->hw);
6707 mutex_unlock(&ar->conf_mutex);
6711 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6712 struct ieee80211_channel *channel)
6715 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6717 lockdep_assert_held(&ar->conf_mutex);
6719 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6720 (ar->rx_channel != channel))
6723 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6724 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6728 reinit_completion(&ar->bss_survey_done);
6730 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6732 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6736 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6738 ath10k_warn(ar, "bss channel survey timed out\n");
6743 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6744 struct survey_info *survey)
6746 struct ath10k *ar = hw->priv;
6747 struct ieee80211_supported_band *sband;
6748 struct survey_info *ar_survey = &ar->survey[idx];
6751 mutex_lock(&ar->conf_mutex);
6753 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6754 if (sband && idx >= sband->n_channels) {
6755 idx -= sband->n_channels;
6760 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6762 if (!sband || idx >= sband->n_channels) {
6767 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6769 spin_lock_bh(&ar->data_lock);
6770 memcpy(survey, ar_survey, sizeof(*survey));
6771 spin_unlock_bh(&ar->data_lock);
6773 survey->channel = &sband->channels[idx];
6775 if (ar->rx_channel == survey->channel)
6776 survey->filled |= SURVEY_INFO_IN_USE;
6779 mutex_unlock(&ar->conf_mutex);
6784 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6785 enum nl80211_band band,
6786 const struct cfg80211_bitrate_mask *mask)
6791 num_rates += hweight32(mask->control[band].legacy);
6793 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6794 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6796 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6797 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6799 return num_rates == 1;
6803 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6804 enum nl80211_band band,
6805 const struct cfg80211_bitrate_mask *mask,
6808 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6809 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6811 u8 vht_nss_mask = 0;
6814 if (mask->control[band].legacy)
6817 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6818 if (mask->control[band].ht_mcs[i] == 0)
6820 else if (mask->control[band].ht_mcs[i] ==
6821 sband->ht_cap.mcs.rx_mask[i])
6822 ht_nss_mask |= BIT(i);
6827 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6828 if (mask->control[band].vht_mcs[i] == 0)
6830 else if (mask->control[band].vht_mcs[i] ==
6831 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6832 vht_nss_mask |= BIT(i);
6837 if (ht_nss_mask != vht_nss_mask)
6840 if (ht_nss_mask == 0)
6843 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6846 *nss = fls(ht_nss_mask);
6852 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6853 enum nl80211_band band,
6854 const struct cfg80211_bitrate_mask *mask,
6857 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6864 if (hweight32(mask->control[band].legacy) == 1) {
6865 rate_idx = ffs(mask->control[band].legacy) - 1;
6867 hw_rate = sband->bitrates[rate_idx].hw_value;
6868 bitrate = sband->bitrates[rate_idx].bitrate;
6870 if (ath10k_mac_bitrate_is_cck(bitrate))
6871 preamble = WMI_RATE_PREAMBLE_CCK;
6873 preamble = WMI_RATE_PREAMBLE_OFDM;
6876 *rate = preamble << 6 |
6883 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6884 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6886 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6888 (ffs(mask->control[band].ht_mcs[i]) - 1);
6894 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6895 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6897 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6899 (ffs(mask->control[band].vht_mcs[i]) - 1);
6908 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6909 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6911 struct ath10k *ar = arvif->ar;
6915 lockdep_assert_held(&ar->conf_mutex);
6917 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6918 arvif->vdev_id, rate, nss, sgi);
6920 vdev_param = ar->wmi.vdev_param->fixed_rate;
6921 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6923 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6928 vdev_param = ar->wmi.vdev_param->nss;
6929 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6931 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6935 vdev_param = ar->wmi.vdev_param->sgi;
6936 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6938 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6942 vdev_param = ar->wmi.vdev_param->ldpc;
6943 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6945 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6953 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6954 enum nl80211_band band,
6955 const struct cfg80211_bitrate_mask *mask)
6960 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6961 * to express all VHT MCS rate masks. Effectively only the following
6962 * ranges can be used: none, 0-7, 0-8 and 0-9.
6964 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6965 vht_mcs = mask->control[band].vht_mcs[i];
6974 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6982 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6983 struct ieee80211_sta *sta)
6985 struct ath10k_vif *arvif = data;
6986 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6987 struct ath10k *ar = arvif->ar;
6989 if (arsta->arvif != arvif)
6992 spin_lock_bh(&ar->data_lock);
6993 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6994 spin_unlock_bh(&ar->data_lock);
6996 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6999 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7000 struct ieee80211_vif *vif,
7001 const struct cfg80211_bitrate_mask *mask)
7003 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7004 struct cfg80211_chan_def def;
7005 struct ath10k *ar = arvif->ar;
7006 enum nl80211_band band;
7007 const u8 *ht_mcs_mask;
7008 const u16 *vht_mcs_mask;
7016 if (ath10k_mac_vif_chan(vif, &def))
7019 band = def.chan->band;
7020 ht_mcs_mask = mask->control[band].ht_mcs;
7021 vht_mcs_mask = mask->control[band].vht_mcs;
7022 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7024 sgi = mask->control[band].gi;
7025 if (sgi == NL80211_TXRATE_FORCE_LGI)
7028 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7029 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7032 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7033 arvif->vdev_id, ret);
7036 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7038 rate = WMI_FIXED_RATE_NONE;
7041 rate = WMI_FIXED_RATE_NONE;
7042 nss = min(ar->num_rf_chains,
7043 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7044 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7046 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7049 mutex_lock(&ar->conf_mutex);
7051 arvif->bitrate_mask = *mask;
7052 ieee80211_iterate_stations_atomic(ar->hw,
7053 ath10k_mac_set_bitrate_mask_iter,
7056 mutex_unlock(&ar->conf_mutex);
7059 mutex_lock(&ar->conf_mutex);
7061 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7063 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7064 arvif->vdev_id, ret);
7069 mutex_unlock(&ar->conf_mutex);
7074 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7075 struct ieee80211_vif *vif,
7076 struct ieee80211_sta *sta,
7079 struct ath10k *ar = hw->priv;
7080 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7081 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7082 struct ath10k_peer *peer;
7085 spin_lock_bh(&ar->data_lock);
7087 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7089 spin_unlock_bh(&ar->data_lock);
7090 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7091 sta->addr, arvif->vdev_id);
7095 ath10k_dbg(ar, ATH10K_DBG_MAC,
7096 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7097 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7100 if (changed & IEEE80211_RC_BW_CHANGED) {
7101 bw = WMI_PEER_CHWIDTH_20MHZ;
7103 switch (sta->bandwidth) {
7104 case IEEE80211_STA_RX_BW_20:
7105 bw = WMI_PEER_CHWIDTH_20MHZ;
7107 case IEEE80211_STA_RX_BW_40:
7108 bw = WMI_PEER_CHWIDTH_40MHZ;
7110 case IEEE80211_STA_RX_BW_80:
7111 bw = WMI_PEER_CHWIDTH_80MHZ;
7113 case IEEE80211_STA_RX_BW_160:
7114 bw = WMI_PEER_CHWIDTH_160MHZ;
7117 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7118 sta->bandwidth, sta->addr);
7119 bw = WMI_PEER_CHWIDTH_20MHZ;
7126 if (changed & IEEE80211_RC_NSS_CHANGED)
7127 arsta->nss = sta->rx_nss;
7129 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7130 smps = WMI_PEER_SMPS_PS_NONE;
7132 switch (sta->smps_mode) {
7133 case IEEE80211_SMPS_AUTOMATIC:
7134 case IEEE80211_SMPS_OFF:
7135 smps = WMI_PEER_SMPS_PS_NONE;
7137 case IEEE80211_SMPS_STATIC:
7138 smps = WMI_PEER_SMPS_STATIC;
7140 case IEEE80211_SMPS_DYNAMIC:
7141 smps = WMI_PEER_SMPS_DYNAMIC;
7143 case IEEE80211_SMPS_NUM_MODES:
7144 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7145 sta->smps_mode, sta->addr);
7146 smps = WMI_PEER_SMPS_PS_NONE;
7153 arsta->changed |= changed;
7155 spin_unlock_bh(&ar->data_lock);
7157 ieee80211_queue_work(hw, &arsta->update_wk);
7160 static void ath10k_offset_tsf(struct ieee80211_hw *hw,
7161 struct ieee80211_vif *vif, s64 tsf_offset)
7163 struct ath10k *ar = hw->priv;
7164 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7165 u32 offset, vdev_param;
7168 if (tsf_offset < 0) {
7169 vdev_param = ar->wmi.vdev_param->dec_tsf;
7170 offset = -tsf_offset;
7172 vdev_param = ar->wmi.vdev_param->inc_tsf;
7173 offset = tsf_offset;
7176 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7177 vdev_param, offset);
7179 if (ret && ret != -EOPNOTSUPP)
7180 ath10k_warn(ar, "failed to set tsf offset %d cmd %d: %d\n",
7181 offset, vdev_param, ret);
7184 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7185 struct ieee80211_vif *vif,
7186 struct ieee80211_ampdu_params *params)
7188 struct ath10k *ar = hw->priv;
7189 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7190 struct ieee80211_sta *sta = params->sta;
7191 enum ieee80211_ampdu_mlme_action action = params->action;
7192 u16 tid = params->tid;
7194 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7195 arvif->vdev_id, sta->addr, tid, action);
7198 case IEEE80211_AMPDU_RX_START:
7199 case IEEE80211_AMPDU_RX_STOP:
7200 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7201 * creation/removal. Do we need to verify this?
7204 case IEEE80211_AMPDU_TX_START:
7205 case IEEE80211_AMPDU_TX_STOP_CONT:
7206 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7207 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7208 case IEEE80211_AMPDU_TX_OPERATIONAL:
7209 /* Firmware offloads Tx aggregation entirely so deny mac80211
7210 * Tx aggregation requests.
7219 ath10k_mac_update_rx_channel(struct ath10k *ar,
7220 struct ieee80211_chanctx_conf *ctx,
7221 struct ieee80211_vif_chanctx_switch *vifs,
7224 struct cfg80211_chan_def *def = NULL;
7226 /* Both locks are required because ar->rx_channel is modified. This
7227 * allows readers to hold either lock.
7229 lockdep_assert_held(&ar->conf_mutex);
7230 lockdep_assert_held(&ar->data_lock);
7232 WARN_ON(ctx && vifs);
7233 WARN_ON(vifs && !n_vifs);
7235 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7236 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7237 * ppdu on Rx may reduce performance on low-end systems. It should be
7238 * possible to make tables/hashmaps to speed the lookup up (be vary of
7239 * cpu data cache lines though regarding sizes) but to keep the initial
7240 * implementation simple and less intrusive fallback to the slow lookup
7241 * only for multi-channel cases. Single-channel cases will remain to
7242 * use the old channel derival and thus performance should not be
7246 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7247 ieee80211_iter_chan_contexts_atomic(ar->hw,
7248 ath10k_mac_get_any_chandef_iter,
7252 def = &vifs[0].new_ctx->def;
7254 ar->rx_channel = def->chan;
7255 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7256 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7257 /* During driver restart due to firmware assert, since mac80211
7258 * already has valid channel context for given radio, channel
7259 * context iteration return num_chanctx > 0. So fix rx_channel
7260 * when restart is in progress.
7262 ar->rx_channel = ctx->def.chan;
7264 ar->rx_channel = NULL;
7270 ath10k_mac_update_vif_chan(struct ath10k *ar,
7271 struct ieee80211_vif_chanctx_switch *vifs,
7274 struct ath10k_vif *arvif;
7278 lockdep_assert_held(&ar->conf_mutex);
7280 /* First stop monitor interface. Some FW versions crash if there's a
7281 * lone monitor interface.
7283 if (ar->monitor_started)
7284 ath10k_monitor_stop(ar);
7286 for (i = 0; i < n_vifs; i++) {
7287 arvif = (void *)vifs[i].vif->drv_priv;
7289 ath10k_dbg(ar, ATH10K_DBG_MAC,
7290 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7292 vifs[i].old_ctx->def.chan->center_freq,
7293 vifs[i].new_ctx->def.chan->center_freq,
7294 vifs[i].old_ctx->def.width,
7295 vifs[i].new_ctx->def.width);
7297 if (WARN_ON(!arvif->is_started))
7300 if (WARN_ON(!arvif->is_up))
7303 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7305 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7306 arvif->vdev_id, ret);
7311 /* All relevant vdevs are downed and associated channel resources
7312 * should be available for the channel switch now.
7315 spin_lock_bh(&ar->data_lock);
7316 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7317 spin_unlock_bh(&ar->data_lock);
7319 for (i = 0; i < n_vifs; i++) {
7320 arvif = (void *)vifs[i].vif->drv_priv;
7322 if (WARN_ON(!arvif->is_started))
7325 if (WARN_ON(!arvif->is_up))
7328 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7330 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7333 ret = ath10k_mac_setup_prb_tmpl(arvif);
7335 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7338 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7340 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7341 arvif->vdev_id, ret);
7345 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7348 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7349 arvif->vdev_id, ret);
7354 ath10k_monitor_recalc(ar);
7358 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7359 struct ieee80211_chanctx_conf *ctx)
7361 struct ath10k *ar = hw->priv;
7363 ath10k_dbg(ar, ATH10K_DBG_MAC,
7364 "mac chanctx add freq %hu width %d ptr %pK\n",
7365 ctx->def.chan->center_freq, ctx->def.width, ctx);
7367 mutex_lock(&ar->conf_mutex);
7369 spin_lock_bh(&ar->data_lock);
7370 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7371 spin_unlock_bh(&ar->data_lock);
7373 ath10k_recalc_radar_detection(ar);
7374 ath10k_monitor_recalc(ar);
7376 mutex_unlock(&ar->conf_mutex);
7382 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7383 struct ieee80211_chanctx_conf *ctx)
7385 struct ath10k *ar = hw->priv;
7387 ath10k_dbg(ar, ATH10K_DBG_MAC,
7388 "mac chanctx remove freq %hu width %d ptr %pK\n",
7389 ctx->def.chan->center_freq, ctx->def.width, ctx);
7391 mutex_lock(&ar->conf_mutex);
7393 spin_lock_bh(&ar->data_lock);
7394 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7395 spin_unlock_bh(&ar->data_lock);
7397 ath10k_recalc_radar_detection(ar);
7398 ath10k_monitor_recalc(ar);
7400 mutex_unlock(&ar->conf_mutex);
7403 struct ath10k_mac_change_chanctx_arg {
7404 struct ieee80211_chanctx_conf *ctx;
7405 struct ieee80211_vif_chanctx_switch *vifs;
7411 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7412 struct ieee80211_vif *vif)
7414 struct ath10k_mac_change_chanctx_arg *arg = data;
7416 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7423 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7424 struct ieee80211_vif *vif)
7426 struct ath10k_mac_change_chanctx_arg *arg = data;
7427 struct ieee80211_chanctx_conf *ctx;
7429 ctx = rcu_access_pointer(vif->chanctx_conf);
7430 if (ctx != arg->ctx)
7433 if (WARN_ON(arg->next_vif == arg->n_vifs))
7436 arg->vifs[arg->next_vif].vif = vif;
7437 arg->vifs[arg->next_vif].old_ctx = ctx;
7438 arg->vifs[arg->next_vif].new_ctx = ctx;
7443 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7444 struct ieee80211_chanctx_conf *ctx,
7447 struct ath10k *ar = hw->priv;
7448 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7450 mutex_lock(&ar->conf_mutex);
7452 ath10k_dbg(ar, ATH10K_DBG_MAC,
7453 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7454 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7456 /* This shouldn't really happen because channel switching should use
7457 * switch_vif_chanctx().
7459 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7462 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7463 ieee80211_iterate_active_interfaces_atomic(
7465 IEEE80211_IFACE_ITER_NORMAL,
7466 ath10k_mac_change_chanctx_cnt_iter,
7468 if (arg.n_vifs == 0)
7471 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7476 ieee80211_iterate_active_interfaces_atomic(
7478 IEEE80211_IFACE_ITER_NORMAL,
7479 ath10k_mac_change_chanctx_fill_iter,
7481 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7486 ath10k_recalc_radar_detection(ar);
7488 /* FIXME: How to configure Rx chains properly? */
7490 /* No other actions are actually necessary. Firmware maintains channel
7491 * definitions per vdev internally and there's no host-side channel
7492 * context abstraction to configure, e.g. channel width.
7496 mutex_unlock(&ar->conf_mutex);
7500 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7501 struct ieee80211_vif *vif,
7502 struct ieee80211_chanctx_conf *ctx)
7504 struct ath10k *ar = hw->priv;
7505 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7508 mutex_lock(&ar->conf_mutex);
7510 ath10k_dbg(ar, ATH10K_DBG_MAC,
7511 "mac chanctx assign ptr %pK vdev_id %i\n",
7512 ctx, arvif->vdev_id);
7514 if (WARN_ON(arvif->is_started)) {
7515 mutex_unlock(&ar->conf_mutex);
7519 ret = ath10k_vdev_start(arvif, &ctx->def);
7521 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7522 arvif->vdev_id, vif->addr,
7523 ctx->def.chan->center_freq, ret);
7527 arvif->is_started = true;
7529 ret = ath10k_mac_vif_setup_ps(arvif);
7531 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7532 arvif->vdev_id, ret);
7536 if (vif->type == NL80211_IFTYPE_MONITOR) {
7537 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7539 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7540 arvif->vdev_id, ret);
7544 arvif->is_up = true;
7547 if (ath10k_mac_can_set_cts_prot(arvif)) {
7548 ret = ath10k_mac_set_cts_prot(arvif);
7550 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7551 arvif->vdev_id, ret);
7554 mutex_unlock(&ar->conf_mutex);
7558 ath10k_vdev_stop(arvif);
7559 arvif->is_started = false;
7560 ath10k_mac_vif_setup_ps(arvif);
7563 mutex_unlock(&ar->conf_mutex);
7568 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7569 struct ieee80211_vif *vif,
7570 struct ieee80211_chanctx_conf *ctx)
7572 struct ath10k *ar = hw->priv;
7573 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7576 mutex_lock(&ar->conf_mutex);
7578 ath10k_dbg(ar, ATH10K_DBG_MAC,
7579 "mac chanctx unassign ptr %pK vdev_id %i\n",
7580 ctx, arvif->vdev_id);
7582 WARN_ON(!arvif->is_started);
7584 if (vif->type == NL80211_IFTYPE_MONITOR) {
7585 WARN_ON(!arvif->is_up);
7587 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7589 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7590 arvif->vdev_id, ret);
7592 arvif->is_up = false;
7595 ret = ath10k_vdev_stop(arvif);
7597 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7598 arvif->vdev_id, ret);
7600 arvif->is_started = false;
7602 mutex_unlock(&ar->conf_mutex);
7606 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7607 struct ieee80211_vif_chanctx_switch *vifs,
7609 enum ieee80211_chanctx_switch_mode mode)
7611 struct ath10k *ar = hw->priv;
7613 mutex_lock(&ar->conf_mutex);
7615 ath10k_dbg(ar, ATH10K_DBG_MAC,
7616 "mac chanctx switch n_vifs %d mode %d\n",
7618 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7620 mutex_unlock(&ar->conf_mutex);
7624 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7625 struct ieee80211_vif *vif,
7626 struct ieee80211_sta *sta)
7629 struct ath10k_peer *peer;
7633 list_for_each_entry(peer, &ar->peers, list)
7634 if (peer->sta == sta)
7635 peer->removed = true;
7638 static const struct ieee80211_ops ath10k_ops = {
7639 .tx = ath10k_mac_op_tx,
7640 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7641 .start = ath10k_start,
7642 .stop = ath10k_stop,
7643 .config = ath10k_config,
7644 .add_interface = ath10k_add_interface,
7645 .remove_interface = ath10k_remove_interface,
7646 .configure_filter = ath10k_configure_filter,
7647 .bss_info_changed = ath10k_bss_info_changed,
7648 .set_coverage_class = ath10k_mac_op_set_coverage_class,
7649 .hw_scan = ath10k_hw_scan,
7650 .cancel_hw_scan = ath10k_cancel_hw_scan,
7651 .set_key = ath10k_set_key,
7652 .set_default_unicast_key = ath10k_set_default_unicast_key,
7653 .sta_state = ath10k_sta_state,
7654 .conf_tx = ath10k_conf_tx,
7655 .remain_on_channel = ath10k_remain_on_channel,
7656 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7657 .set_rts_threshold = ath10k_set_rts_threshold,
7658 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7659 .flush = ath10k_flush,
7660 .tx_last_beacon = ath10k_tx_last_beacon,
7661 .set_antenna = ath10k_set_antenna,
7662 .get_antenna = ath10k_get_antenna,
7663 .reconfig_complete = ath10k_reconfig_complete,
7664 .get_survey = ath10k_get_survey,
7665 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7666 .sta_rc_update = ath10k_sta_rc_update,
7667 .offset_tsf = ath10k_offset_tsf,
7668 .ampdu_action = ath10k_ampdu_action,
7669 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7670 .get_et_stats = ath10k_debug_get_et_stats,
7671 .get_et_strings = ath10k_debug_get_et_strings,
7672 .add_chanctx = ath10k_mac_op_add_chanctx,
7673 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7674 .change_chanctx = ath10k_mac_op_change_chanctx,
7675 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7676 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7677 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7678 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7680 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7683 .suspend = ath10k_wow_op_suspend,
7684 .resume = ath10k_wow_op_resume,
7685 .set_wakeup = ath10k_wow_op_set_wakeup,
7687 #ifdef CONFIG_MAC80211_DEBUGFS
7688 .sta_add_debugfs = ath10k_sta_add_debugfs,
7689 .sta_statistics = ath10k_sta_statistics,
7693 #define CHAN2G(_channel, _freq, _flags) { \
7694 .band = NL80211_BAND_2GHZ, \
7695 .hw_value = (_channel), \
7696 .center_freq = (_freq), \
7697 .flags = (_flags), \
7698 .max_antenna_gain = 0, \
7702 #define CHAN5G(_channel, _freq, _flags) { \
7703 .band = NL80211_BAND_5GHZ, \
7704 .hw_value = (_channel), \
7705 .center_freq = (_freq), \
7706 .flags = (_flags), \
7707 .max_antenna_gain = 0, \
7711 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7721 CHAN2G(10, 2457, 0),
7722 CHAN2G(11, 2462, 0),
7723 CHAN2G(12, 2467, 0),
7724 CHAN2G(13, 2472, 0),
7725 CHAN2G(14, 2484, 0),
7728 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7729 CHAN5G(36, 5180, 0),
7730 CHAN5G(40, 5200, 0),
7731 CHAN5G(44, 5220, 0),
7732 CHAN5G(48, 5240, 0),
7733 CHAN5G(52, 5260, 0),
7734 CHAN5G(56, 5280, 0),
7735 CHAN5G(60, 5300, 0),
7736 CHAN5G(64, 5320, 0),
7737 CHAN5G(100, 5500, 0),
7738 CHAN5G(104, 5520, 0),
7739 CHAN5G(108, 5540, 0),
7740 CHAN5G(112, 5560, 0),
7741 CHAN5G(116, 5580, 0),
7742 CHAN5G(120, 5600, 0),
7743 CHAN5G(124, 5620, 0),
7744 CHAN5G(128, 5640, 0),
7745 CHAN5G(132, 5660, 0),
7746 CHAN5G(136, 5680, 0),
7747 CHAN5G(140, 5700, 0),
7748 CHAN5G(144, 5720, 0),
7749 CHAN5G(149, 5745, 0),
7750 CHAN5G(153, 5765, 0),
7751 CHAN5G(157, 5785, 0),
7752 CHAN5G(161, 5805, 0),
7753 CHAN5G(165, 5825, 0),
7754 CHAN5G(169, 5845, 0),
7757 struct ath10k *ath10k_mac_create(size_t priv_size)
7759 struct ieee80211_hw *hw;
7760 struct ieee80211_ops *ops;
7763 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7767 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7780 void ath10k_mac_destroy(struct ath10k *ar)
7782 struct ieee80211_ops *ops = ar->ops;
7784 ieee80211_free_hw(ar->hw);
7788 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7791 .types = BIT(NL80211_IFTYPE_STATION)
7792 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7796 .types = BIT(NL80211_IFTYPE_P2P_GO)
7800 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7804 .types = BIT(NL80211_IFTYPE_AP)
7805 #ifdef CONFIG_MAC80211_MESH
7806 | BIT(NL80211_IFTYPE_MESH_POINT)
7811 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7814 .types = BIT(NL80211_IFTYPE_AP)
7815 #ifdef CONFIG_MAC80211_MESH
7816 | BIT(NL80211_IFTYPE_MESH_POINT)
7821 .types = BIT(NL80211_IFTYPE_STATION)
7825 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7827 .limits = ath10k_if_limits,
7828 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7829 .max_interfaces = 8,
7830 .num_different_channels = 1,
7831 .beacon_int_infra_match = true,
7835 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7837 .limits = ath10k_10x_if_limits,
7838 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7839 .max_interfaces = 8,
7840 .num_different_channels = 1,
7841 .beacon_int_infra_match = true,
7842 .beacon_int_min_gcd = 1,
7843 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7844 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7845 BIT(NL80211_CHAN_WIDTH_20) |
7846 BIT(NL80211_CHAN_WIDTH_40) |
7847 BIT(NL80211_CHAN_WIDTH_80),
7852 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7855 .types = BIT(NL80211_IFTYPE_STATION),
7859 .types = BIT(NL80211_IFTYPE_AP) |
7860 #ifdef CONFIG_MAC80211_MESH
7861 BIT(NL80211_IFTYPE_MESH_POINT) |
7863 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7864 BIT(NL80211_IFTYPE_P2P_GO),
7868 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7872 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7875 .types = BIT(NL80211_IFTYPE_STATION),
7879 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7883 .types = BIT(NL80211_IFTYPE_AP) |
7884 #ifdef CONFIG_MAC80211_MESH
7885 BIT(NL80211_IFTYPE_MESH_POINT) |
7887 BIT(NL80211_IFTYPE_P2P_GO),
7891 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7895 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7898 .types = BIT(NL80211_IFTYPE_STATION),
7902 .types = BIT(NL80211_IFTYPE_ADHOC),
7906 /* FIXME: This is not thouroughly tested. These combinations may over- or
7907 * underestimate hw/fw capabilities.
7909 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7911 .limits = ath10k_tlv_if_limit,
7912 .num_different_channels = 1,
7913 .max_interfaces = 4,
7914 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7917 .limits = ath10k_tlv_if_limit_ibss,
7918 .num_different_channels = 1,
7919 .max_interfaces = 2,
7920 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7924 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7926 .limits = ath10k_tlv_if_limit,
7927 .num_different_channels = 1,
7928 .max_interfaces = 4,
7929 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7932 .limits = ath10k_tlv_qcs_if_limit,
7933 .num_different_channels = 2,
7934 .max_interfaces = 4,
7935 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7938 .limits = ath10k_tlv_if_limit_ibss,
7939 .num_different_channels = 1,
7940 .max_interfaces = 2,
7941 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7945 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7948 .types = BIT(NL80211_IFTYPE_STATION),
7952 .types = BIT(NL80211_IFTYPE_AP)
7953 #ifdef CONFIG_MAC80211_MESH
7954 | BIT(NL80211_IFTYPE_MESH_POINT)
7959 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7961 .limits = ath10k_10_4_if_limits,
7962 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7963 .max_interfaces = 16,
7964 .num_different_channels = 1,
7965 .beacon_int_infra_match = true,
7966 .beacon_int_min_gcd = 1,
7967 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7968 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7969 BIT(NL80211_CHAN_WIDTH_20) |
7970 BIT(NL80211_CHAN_WIDTH_40) |
7971 BIT(NL80211_CHAN_WIDTH_80),
7976 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7977 struct ieee80211_vif *vif)
7979 struct ath10k_vif_iter *arvif_iter = data;
7980 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7982 if (arvif->vdev_id == arvif_iter->vdev_id)
7983 arvif_iter->arvif = arvif;
7986 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7988 struct ath10k_vif_iter arvif_iter;
7991 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7992 arvif_iter.vdev_id = vdev_id;
7994 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7995 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7997 ath10k_get_arvif_iter,
7999 if (!arvif_iter.arvif) {
8000 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8004 return arvif_iter.arvif;
8007 #define WRD_METHOD "WRDD"
8008 #define WRDD_WIFI (0x07)
8010 static u32 ath10k_mac_wrdd_get_mcc(struct ath10k *ar, union acpi_object *wrdd)
8012 union acpi_object *mcc_pkg;
8013 union acpi_object *domain_type;
8014 union acpi_object *mcc_value;
8017 if (wrdd->type != ACPI_TYPE_PACKAGE ||
8018 wrdd->package.count < 2 ||
8019 wrdd->package.elements[0].type != ACPI_TYPE_INTEGER ||
8020 wrdd->package.elements[0].integer.value != 0) {
8021 ath10k_warn(ar, "ignoring malformed/unsupported wrdd structure\n");
8025 for (i = 1; i < wrdd->package.count; ++i) {
8026 mcc_pkg = &wrdd->package.elements[i];
8028 if (mcc_pkg->type != ACPI_TYPE_PACKAGE)
8030 if (mcc_pkg->package.count < 2)
8032 if (mcc_pkg->package.elements[0].type != ACPI_TYPE_INTEGER ||
8033 mcc_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
8036 domain_type = &mcc_pkg->package.elements[0];
8037 if (domain_type->integer.value != WRDD_WIFI)
8040 mcc_value = &mcc_pkg->package.elements[1];
8041 return mcc_value->integer.value;
8046 static int ath10k_mac_get_wrdd_regulatory(struct ath10k *ar, u16 *rd)
8048 struct pci_dev __maybe_unused *pdev = to_pci_dev(ar->dev);
8049 acpi_handle root_handle;
8051 struct acpi_buffer wrdd = {ACPI_ALLOCATE_BUFFER, NULL};
8056 root_handle = ACPI_HANDLE(&pdev->dev);
8060 status = acpi_get_handle(root_handle, (acpi_string)WRD_METHOD, &handle);
8061 if (ACPI_FAILURE(status)) {
8062 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8063 "failed to get wrd method %d\n", status);
8067 status = acpi_evaluate_object(handle, NULL, NULL, &wrdd);
8068 if (ACPI_FAILURE(status)) {
8069 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8070 "failed to call wrdc %d\n", status);
8074 alpha2_code = ath10k_mac_wrdd_get_mcc(ar, wrdd.pointer);
8075 kfree(wrdd.pointer);
8079 alpha2[0] = (alpha2_code >> 8) & 0xff;
8080 alpha2[1] = (alpha2_code >> 0) & 0xff;
8083 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8084 "regulatory hint from WRDD (alpha2-code): %s\n", alpha2);
8086 *rd = ath_regd_find_country_by_name(alpha2);
8090 *rd |= COUNTRY_ERD_FLAG;
8094 static int ath10k_mac_init_rd(struct ath10k *ar)
8099 ret = ath10k_mac_get_wrdd_regulatory(ar, &rd);
8101 ath10k_dbg(ar, ATH10K_DBG_BOOT,
8102 "fallback to eeprom programmed regulatory settings\n");
8103 rd = ar->hw_eeprom_rd;
8106 ar->ath_common.regulatory.current_rd = rd;
8110 int ath10k_mac_register(struct ath10k *ar)
8112 static const u32 cipher_suites[] = {
8113 WLAN_CIPHER_SUITE_WEP40,
8114 WLAN_CIPHER_SUITE_WEP104,
8115 WLAN_CIPHER_SUITE_TKIP,
8116 WLAN_CIPHER_SUITE_CCMP,
8117 WLAN_CIPHER_SUITE_AES_CMAC,
8119 struct ieee80211_supported_band *band;
8123 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8125 SET_IEEE80211_DEV(ar->hw, ar->dev);
8127 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8128 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8131 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8132 channels = kmemdup(ath10k_2ghz_channels,
8133 sizeof(ath10k_2ghz_channels),
8140 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8141 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8142 band->channels = channels;
8144 if (ar->hw_params.cck_rate_map_rev2) {
8145 band->n_bitrates = ath10k_g_rates_rev2_size;
8146 band->bitrates = ath10k_g_rates_rev2;
8148 band->n_bitrates = ath10k_g_rates_size;
8149 band->bitrates = ath10k_g_rates;
8152 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8155 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8156 channels = kmemdup(ath10k_5ghz_channels,
8157 sizeof(ath10k_5ghz_channels),
8164 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8165 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8166 band->channels = channels;
8167 band->n_bitrates = ath10k_a_rates_size;
8168 band->bitrates = ath10k_a_rates;
8169 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8172 wiphy_read_of_freq_limits(ar->hw->wiphy);
8173 ath10k_mac_setup_ht_vht_cap(ar);
8175 ar->hw->wiphy->interface_modes =
8176 BIT(NL80211_IFTYPE_STATION) |
8177 BIT(NL80211_IFTYPE_AP) |
8178 BIT(NL80211_IFTYPE_MESH_POINT);
8180 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8181 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8183 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8184 ar->hw->wiphy->interface_modes |=
8185 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8186 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8187 BIT(NL80211_IFTYPE_P2P_GO);
8189 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8190 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8191 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8192 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8193 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8194 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8195 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8196 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8197 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8198 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8199 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8200 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8201 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8202 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8203 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8204 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8206 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8207 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8209 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8210 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8212 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8213 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8215 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8216 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8217 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8220 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8221 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8223 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8224 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8225 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8227 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8229 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8230 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8232 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8233 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8234 * correct Probe Responses. This is more of a hack advert..
8236 ar->hw->wiphy->probe_resp_offload |=
8237 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8238 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8239 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8242 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map) ||
8243 test_bit(WMI_SERVICE_TDLS_EXPLICIT_MODE_ONLY, ar->wmi.svc_map)) {
8244 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8245 ieee80211_hw_set(ar->hw, TDLS_WIDER_BW);
8248 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8249 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8250 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8252 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8253 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8254 NL80211_FEATURE_AP_SCAN;
8256 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8258 ret = ath10k_wow_init(ar);
8260 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8264 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8267 * on LL hardware queues are managed entirely by the FW
8268 * so we only advertise to mac we can do the queues thing
8270 ar->hw->queues = IEEE80211_MAX_QUEUES;
8272 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8273 * something that vdev_ids can't reach so that we don't stop the queue
8276 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8278 switch (ar->running_fw->fw_file.wmi_op_version) {
8279 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8280 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8281 ar->hw->wiphy->n_iface_combinations =
8282 ARRAY_SIZE(ath10k_if_comb);
8283 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8285 case ATH10K_FW_WMI_OP_VERSION_TLV:
8286 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8287 ar->hw->wiphy->iface_combinations =
8288 ath10k_tlv_qcs_if_comb;
8289 ar->hw->wiphy->n_iface_combinations =
8290 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8292 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8293 ar->hw->wiphy->n_iface_combinations =
8294 ARRAY_SIZE(ath10k_tlv_if_comb);
8296 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8298 case ATH10K_FW_WMI_OP_VERSION_10_1:
8299 case ATH10K_FW_WMI_OP_VERSION_10_2:
8300 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8301 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8302 ar->hw->wiphy->n_iface_combinations =
8303 ARRAY_SIZE(ath10k_10x_if_comb);
8305 case ATH10K_FW_WMI_OP_VERSION_10_4:
8306 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8307 ar->hw->wiphy->n_iface_combinations =
8308 ARRAY_SIZE(ath10k_10_4_if_comb);
8310 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8311 case ATH10K_FW_WMI_OP_VERSION_MAX:
8317 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8318 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8320 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8321 /* Init ath dfs pattern detector */
8322 ar->ath_common.debug_mask = ATH_DBG_DFS;
8323 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8326 if (!ar->dfs_detector)
8327 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8330 /* Current wake_tx_queue implementation imposes a significant
8331 * performance penalty in some setups. The tx scheduling code needs
8332 * more work anyway so disable the wake_tx_queue unless firmware
8333 * supports the pull-push mechanism.
8335 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8336 ar->running_fw->fw_file.fw_features))
8337 ar->ops->wake_tx_queue = NULL;
8339 ret = ath10k_mac_init_rd(ar);
8341 ath10k_err(ar, "failed to derive regdom: %d\n", ret);
8342 goto err_dfs_detector_exit;
8345 /* Disable set_coverage_class for chipsets that do not support it. */
8346 if (!ar->hw_params.hw_ops->set_coverage_class)
8347 ar->ops->set_coverage_class = NULL;
8349 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8350 ath10k_reg_notifier);
8352 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8353 goto err_dfs_detector_exit;
8356 ar->hw->wiphy->cipher_suites = cipher_suites;
8357 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8359 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8361 ret = ieee80211_register_hw(ar->hw);
8363 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8364 goto err_dfs_detector_exit;
8367 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8368 ret = regulatory_hint(ar->hw->wiphy,
8369 ar->ath_common.regulatory.alpha2);
8371 goto err_unregister;
8377 ieee80211_unregister_hw(ar->hw);
8379 err_dfs_detector_exit:
8380 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8381 ar->dfs_detector->exit(ar->dfs_detector);
8384 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8385 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8387 SET_IEEE80211_DEV(ar->hw, NULL);
8391 void ath10k_mac_unregister(struct ath10k *ar)
8393 ieee80211_unregister_hw(ar->hw);
8395 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8396 ar->dfs_detector->exit(ar->dfs_detector);
8398 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8399 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8401 SET_IEEE80211_DEV(ar->hw, NULL);