2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013, 2017 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
39 static struct ieee80211_rate ath10k_rates[] = {
41 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
43 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
47 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
48 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
49 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
51 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
52 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
53 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
55 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
56 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
57 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
58 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
59 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
60 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
61 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
62 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
65 static struct ieee80211_rate ath10k_rates_rev2[] = {
67 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_1M },
69 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_2M,
70 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_2M,
71 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
73 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_5_5M,
74 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_5_5M,
75 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
77 .hw_value = ATH10K_HW_RATE_REV2_CCK_LP_11M,
78 .hw_value_short = ATH10K_HW_RATE_REV2_CCK_SP_11M,
79 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
81 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
82 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
83 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
84 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
85 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
86 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
87 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
88 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
91 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
93 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
94 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
95 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
96 #define ath10k_g_rates (ath10k_rates + 0)
97 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
99 #define ath10k_g_rates_rev2 (ath10k_rates_rev2 + 0)
100 #define ath10k_g_rates_rev2_size (ARRAY_SIZE(ath10k_rates_rev2))
102 static bool ath10k_mac_bitrate_is_cck(int bitrate)
115 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
117 return DIV_ROUND_UP(bitrate, 5) |
118 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
121 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
122 u8 hw_rate, bool cck)
124 const struct ieee80211_rate *rate;
127 for (i = 0; i < sband->n_bitrates; i++) {
128 rate = &sband->bitrates[i];
130 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
133 if (rate->hw_value == hw_rate)
135 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
136 rate->hw_value_short == hw_rate)
143 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
148 for (i = 0; i < sband->n_bitrates; i++)
149 if (sband->bitrates[i].bitrate == bitrate)
155 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
157 switch ((mcs_map >> (2 * nss)) & 0x3) {
158 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
159 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
160 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
166 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
170 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
171 if (ht_mcs_mask[nss])
178 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
182 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
183 if (vht_mcs_mask[nss])
189 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
191 enum wmi_host_platform_type platform_type;
194 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
195 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
197 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
199 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
201 if (ret && ret != -EOPNOTSUPP) {
202 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
213 static int ath10k_send_key(struct ath10k_vif *arvif,
214 struct ieee80211_key_conf *key,
215 enum set_key_cmd cmd,
216 const u8 *macaddr, u32 flags)
218 struct ath10k *ar = arvif->ar;
219 struct wmi_vdev_install_key_arg arg = {
220 .vdev_id = arvif->vdev_id,
221 .key_idx = key->keyidx,
222 .key_len = key->keylen,
223 .key_data = key->key,
228 lockdep_assert_held(&arvif->ar->conf_mutex);
230 switch (key->cipher) {
231 case WLAN_CIPHER_SUITE_CCMP:
232 arg.key_cipher = WMI_CIPHER_AES_CCM;
233 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
235 case WLAN_CIPHER_SUITE_TKIP:
236 arg.key_cipher = WMI_CIPHER_TKIP;
237 arg.key_txmic_len = 8;
238 arg.key_rxmic_len = 8;
240 case WLAN_CIPHER_SUITE_WEP40:
241 case WLAN_CIPHER_SUITE_WEP104:
242 arg.key_cipher = WMI_CIPHER_WEP;
244 case WLAN_CIPHER_SUITE_AES_CMAC:
248 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
252 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
253 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
255 if (cmd == DISABLE_KEY) {
256 arg.key_cipher = WMI_CIPHER_NONE;
260 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
263 static int ath10k_install_key(struct ath10k_vif *arvif,
264 struct ieee80211_key_conf *key,
265 enum set_key_cmd cmd,
266 const u8 *macaddr, u32 flags)
268 struct ath10k *ar = arvif->ar;
270 unsigned long time_left;
272 lockdep_assert_held(&ar->conf_mutex);
274 reinit_completion(&ar->install_key_done);
276 if (arvif->nohwcrypt)
279 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
283 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
290 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
293 struct ath10k *ar = arvif->ar;
294 struct ath10k_peer *peer;
299 lockdep_assert_held(&ar->conf_mutex);
301 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
302 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
303 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
306 spin_lock_bh(&ar->data_lock);
307 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
308 spin_unlock_bh(&ar->data_lock);
313 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
314 if (arvif->wep_keys[i] == NULL)
317 switch (arvif->vif->type) {
318 case NL80211_IFTYPE_AP:
319 flags = WMI_KEY_PAIRWISE;
321 if (arvif->def_wep_key_idx == i)
322 flags |= WMI_KEY_TX_USAGE;
324 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
325 SET_KEY, addr, flags);
329 case NL80211_IFTYPE_ADHOC:
330 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
336 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
337 SET_KEY, addr, WMI_KEY_GROUP);
346 spin_lock_bh(&ar->data_lock);
347 peer->keys[i] = arvif->wep_keys[i];
348 spin_unlock_bh(&ar->data_lock);
351 /* In some cases (notably with static WEP IBSS with multiple keys)
352 * multicast Tx becomes broken. Both pairwise and groupwise keys are
353 * installed already. Using WMI_KEY_TX_USAGE in different combinations
354 * didn't seem help. Using def_keyid vdev parameter seems to be
355 * effective so use that.
357 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
359 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
362 if (arvif->def_wep_key_idx == -1)
365 ret = ath10k_wmi_vdev_set_param(arvif->ar,
367 arvif->ar->wmi.vdev_param->def_keyid,
368 arvif->def_wep_key_idx);
370 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
371 arvif->vdev_id, ret);
378 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
381 struct ath10k *ar = arvif->ar;
382 struct ath10k_peer *peer;
388 lockdep_assert_held(&ar->conf_mutex);
390 spin_lock_bh(&ar->data_lock);
391 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
392 spin_unlock_bh(&ar->data_lock);
397 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
398 if (peer->keys[i] == NULL)
401 /* key flags are not required to delete the key */
402 ret = ath10k_install_key(arvif, peer->keys[i],
403 DISABLE_KEY, addr, flags);
404 if (ret < 0 && first_errno == 0)
408 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
411 spin_lock_bh(&ar->data_lock);
412 peer->keys[i] = NULL;
413 spin_unlock_bh(&ar->data_lock);
419 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
422 struct ath10k_peer *peer;
425 lockdep_assert_held(&ar->data_lock);
427 /* We don't know which vdev this peer belongs to,
428 * since WMI doesn't give us that information.
430 * FIXME: multi-bss needs to be handled.
432 peer = ath10k_peer_find(ar, 0, addr);
436 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
437 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
444 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
445 struct ieee80211_key_conf *key)
447 struct ath10k *ar = arvif->ar;
448 struct ath10k_peer *peer;
455 lockdep_assert_held(&ar->conf_mutex);
458 /* since ath10k_install_key we can't hold data_lock all the
459 * time, so we try to remove the keys incrementally */
460 spin_lock_bh(&ar->data_lock);
462 list_for_each_entry(peer, &ar->peers, list) {
463 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
464 if (peer->keys[i] == key) {
465 ether_addr_copy(addr, peer->addr);
466 peer->keys[i] = NULL;
471 if (i < ARRAY_SIZE(peer->keys))
474 spin_unlock_bh(&ar->data_lock);
476 if (i == ARRAY_SIZE(peer->keys))
478 /* key flags are not required to delete the key */
479 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
480 if (ret < 0 && first_errno == 0)
484 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
491 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
492 struct ieee80211_key_conf *key)
494 struct ath10k *ar = arvif->ar;
495 struct ath10k_peer *peer;
498 lockdep_assert_held(&ar->conf_mutex);
500 list_for_each_entry(peer, &ar->peers, list) {
501 if (ether_addr_equal(peer->addr, arvif->vif->addr))
504 if (ether_addr_equal(peer->addr, arvif->bssid))
507 if (peer->keys[key->keyidx] == key)
510 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
511 arvif->vdev_id, key->keyidx);
513 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
515 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
516 arvif->vdev_id, peer->addr, ret);
524 /*********************/
525 /* General utilities */
526 /*********************/
528 static inline enum wmi_phy_mode
529 chan_to_phymode(const struct cfg80211_chan_def *chandef)
531 enum wmi_phy_mode phymode = MODE_UNKNOWN;
533 switch (chandef->chan->band) {
534 case IEEE80211_BAND_2GHZ:
535 switch (chandef->width) {
536 case NL80211_CHAN_WIDTH_20_NOHT:
537 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
542 case NL80211_CHAN_WIDTH_20:
543 phymode = MODE_11NG_HT20;
545 case NL80211_CHAN_WIDTH_40:
546 phymode = MODE_11NG_HT40;
548 case NL80211_CHAN_WIDTH_5:
549 case NL80211_CHAN_WIDTH_10:
550 case NL80211_CHAN_WIDTH_80:
551 case NL80211_CHAN_WIDTH_80P80:
552 case NL80211_CHAN_WIDTH_160:
553 phymode = MODE_UNKNOWN;
557 case IEEE80211_BAND_5GHZ:
558 switch (chandef->width) {
559 case NL80211_CHAN_WIDTH_20_NOHT:
562 case NL80211_CHAN_WIDTH_20:
563 phymode = MODE_11NA_HT20;
565 case NL80211_CHAN_WIDTH_40:
566 phymode = MODE_11NA_HT40;
568 case NL80211_CHAN_WIDTH_80:
569 phymode = MODE_11AC_VHT80;
571 case NL80211_CHAN_WIDTH_5:
572 case NL80211_CHAN_WIDTH_10:
573 case NL80211_CHAN_WIDTH_80P80:
574 case NL80211_CHAN_WIDTH_160:
575 phymode = MODE_UNKNOWN;
583 WARN_ON(phymode == MODE_UNKNOWN);
587 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
590 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
591 * 0 for no restriction
600 switch (mpdudensity) {
606 /* Our lower layer calculations limit our precision to
622 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
623 struct cfg80211_chan_def *def)
625 struct ieee80211_chanctx_conf *conf;
628 conf = rcu_dereference(vif->chanctx_conf);
640 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
641 struct ieee80211_chanctx_conf *conf,
649 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
653 ieee80211_iter_chan_contexts_atomic(ar->hw,
654 ath10k_mac_num_chanctxs_iter,
661 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
662 struct ieee80211_chanctx_conf *conf,
665 struct cfg80211_chan_def **def = data;
670 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
673 unsigned long time_left;
675 lockdep_assert_held(&ar->conf_mutex);
677 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
681 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
685 if (QCA_REV_WCN3990(ar)) {
686 time_left = wait_for_completion_timeout(&ar->peer_delete_done,
689 if (time_left == 0) {
690 ath10k_warn(ar, "Timeout in receiving peer delete response\n");
700 static int ath10k_peer_create(struct ath10k *ar,
701 struct ieee80211_vif *vif,
702 struct ieee80211_sta *sta,
705 enum wmi_peer_type peer_type)
707 struct ath10k_vif *arvif;
708 struct ath10k_peer *peer;
712 lockdep_assert_held(&ar->conf_mutex);
714 num_peers = ar->num_peers;
716 /* Each vdev consumes a peer entry as well */
717 list_for_each_entry(arvif, &ar->arvifs, list)
720 if (num_peers >= ar->max_num_peers)
723 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
725 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
730 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
732 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
737 spin_lock_bh(&ar->data_lock);
739 peer = ath10k_peer_find(ar, vdev_id, addr);
741 spin_unlock_bh(&ar->data_lock);
742 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
744 ath10k_peer_delete(ar, vdev_id, addr);
751 spin_unlock_bh(&ar->data_lock);
758 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
760 struct ath10k *ar = arvif->ar;
764 param = ar->wmi.pdev_param->sta_kickout_th;
765 ret = ath10k_wmi_pdev_set_param(ar, param,
766 ATH10K_KICKOUT_THRESHOLD);
768 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
769 arvif->vdev_id, ret);
773 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
774 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
775 ATH10K_KEEPALIVE_MIN_IDLE);
777 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
778 arvif->vdev_id, ret);
782 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
783 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
784 ATH10K_KEEPALIVE_MAX_IDLE);
786 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
787 arvif->vdev_id, ret);
791 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
792 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
793 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
795 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
796 arvif->vdev_id, ret);
803 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
805 struct ath10k *ar = arvif->ar;
808 vdev_param = ar->wmi.vdev_param->rts_threshold;
809 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
812 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
814 struct ath10k_peer *peer, *tmp;
818 lockdep_assert_held(&ar->conf_mutex);
820 spin_lock_bh(&ar->data_lock);
821 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
822 if (peer->vdev_id != vdev_id)
825 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
826 peer->addr, vdev_id);
828 for_each_set_bit(peer_id, peer->peer_ids,
829 ATH10K_MAX_NUM_PEER_IDS) {
830 ar->peer_map[peer_id] = NULL;
833 /* Double check that peer is properly un-referenced from
836 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
837 if (ar->peer_map[i] == peer) {
838 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
839 peer->addr, peer, i);
840 ar->peer_map[i] = NULL;
844 list_del(&peer->list);
848 spin_unlock_bh(&ar->data_lock);
851 static void ath10k_peer_cleanup_all(struct ath10k *ar)
853 struct ath10k_peer *peer, *tmp;
856 lockdep_assert_held(&ar->conf_mutex);
858 spin_lock_bh(&ar->data_lock);
859 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
860 list_del(&peer->list);
864 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
865 ar->peer_map[i] = NULL;
867 spin_unlock_bh(&ar->data_lock);
870 ar->num_stations = 0;
873 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
874 struct ieee80211_sta *sta,
875 enum wmi_tdls_peer_state state)
878 struct wmi_tdls_peer_update_cmd_arg arg = {};
879 struct wmi_tdls_peer_capab_arg cap = {};
880 struct wmi_channel_arg chan_arg = {};
882 lockdep_assert_held(&ar->conf_mutex);
884 arg.vdev_id = vdev_id;
885 arg.peer_state = state;
886 ether_addr_copy(arg.addr, sta->addr);
888 cap.peer_max_sp = sta->max_sp;
889 cap.peer_uapsd_queues = sta->uapsd_queues;
891 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
892 !sta->tdls_initiator)
893 cap.is_peer_responder = 1;
895 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
897 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
898 arg.addr, vdev_id, ret);
905 /************************/
906 /* Interface management */
907 /************************/
909 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
911 struct ath10k *ar = arvif->ar;
913 lockdep_assert_held(&ar->data_lock);
918 if (!arvif->beacon_buf)
919 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
920 arvif->beacon->len, DMA_TO_DEVICE);
922 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
923 arvif->beacon_state != ATH10K_BEACON_SENT))
926 dev_kfree_skb_any(arvif->beacon);
928 arvif->beacon = NULL;
929 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
932 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
934 struct ath10k *ar = arvif->ar;
936 lockdep_assert_held(&ar->data_lock);
938 ath10k_mac_vif_beacon_free(arvif);
940 if (arvif->beacon_buf) {
941 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
942 arvif->beacon_buf, arvif->beacon_paddr);
943 arvif->beacon_buf = NULL;
947 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
949 unsigned long time_left;
951 lockdep_assert_held(&ar->conf_mutex);
953 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
956 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
957 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
964 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
966 struct cfg80211_chan_def *chandef = NULL;
967 struct ieee80211_channel *channel = NULL;
968 struct wmi_vdev_start_request_arg arg = {};
971 lockdep_assert_held(&ar->conf_mutex);
973 ieee80211_iter_chan_contexts_atomic(ar->hw,
974 ath10k_mac_get_any_chandef_iter,
976 if (WARN_ON_ONCE(!chandef))
979 channel = chandef->chan;
981 arg.vdev_id = vdev_id;
982 arg.channel.freq = channel->center_freq;
983 arg.channel.band_center_freq1 = chandef->center_freq1;
985 /* TODO setup this dynamically, what in case we
986 don't have any vifs? */
987 arg.channel.mode = chan_to_phymode(chandef);
988 arg.channel.chan_radar =
989 !!(channel->flags & IEEE80211_CHAN_RADAR);
991 arg.channel.min_power = 0;
992 arg.channel.max_power = channel->max_power * 2;
993 arg.channel.max_reg_power = channel->max_reg_power * 2;
994 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
996 reinit_completion(&ar->vdev_setup_done);
997 reinit_completion(&ar->vdev_delete_done);
999 ret = ath10k_wmi_vdev_start(ar, &arg);
1001 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1006 ret = ath10k_vdev_setup_sync(ar);
1008 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1013 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1015 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1020 ar->monitor_vdev_id = vdev_id;
1022 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1023 ar->monitor_vdev_id);
1027 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1029 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1030 ar->monitor_vdev_id, ret);
1035 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1039 lockdep_assert_held(&ar->conf_mutex);
1041 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1043 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1044 ar->monitor_vdev_id, ret);
1046 reinit_completion(&ar->vdev_setup_done);
1047 reinit_completion(&ar->vdev_delete_done);
1049 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1051 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1052 ar->monitor_vdev_id, ret);
1054 ret = ath10k_vdev_setup_sync(ar);
1056 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1057 ar->monitor_vdev_id, ret);
1059 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1060 ar->monitor_vdev_id);
1064 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1068 lockdep_assert_held(&ar->conf_mutex);
1070 if (ar->free_vdev_map == 0) {
1071 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1075 bit = __ffs64(ar->free_vdev_map);
1077 ar->monitor_vdev_id = bit;
1079 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1080 WMI_VDEV_TYPE_MONITOR,
1083 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1084 ar->monitor_vdev_id, ret);
1088 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1089 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1090 ar->monitor_vdev_id);
1095 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1099 lockdep_assert_held(&ar->conf_mutex);
1101 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1103 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1104 ar->monitor_vdev_id, ret);
1108 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1110 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1111 ar->monitor_vdev_id);
1115 static int ath10k_monitor_start(struct ath10k *ar)
1119 lockdep_assert_held(&ar->conf_mutex);
1121 ret = ath10k_monitor_vdev_create(ar);
1123 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1127 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1129 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1130 ath10k_monitor_vdev_delete(ar);
1134 ar->monitor_started = true;
1135 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1140 static int ath10k_monitor_stop(struct ath10k *ar)
1144 lockdep_assert_held(&ar->conf_mutex);
1146 ret = ath10k_monitor_vdev_stop(ar);
1148 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1152 ret = ath10k_monitor_vdev_delete(ar);
1154 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1158 ar->monitor_started = false;
1159 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1164 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1168 /* At least one chanctx is required to derive a channel to start
1171 num_ctx = ath10k_mac_num_chanctxs(ar);
1175 /* If there's already an existing special monitor interface then don't
1176 * bother creating another monitor vdev.
1178 if (ar->monitor_arvif)
1181 return ar->monitor ||
1182 ar->filter_flags & FIF_OTHER_BSS ||
1183 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1186 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1190 num_ctx = ath10k_mac_num_chanctxs(ar);
1192 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1193 * shouldn't allow this but make sure to prevent handling the following
1194 * case anyway since multi-channel DFS hasn't been tested at all.
1196 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1202 static int ath10k_monitor_recalc(struct ath10k *ar)
1208 lockdep_assert_held(&ar->conf_mutex);
1210 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1211 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1213 ath10k_dbg(ar, ATH10K_DBG_MAC,
1214 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1215 ar->monitor_started, needed, allowed);
1217 if (WARN_ON(needed && !allowed)) {
1218 if (ar->monitor_started) {
1219 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1221 ret = ath10k_monitor_stop(ar);
1223 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1231 if (needed == ar->monitor_started)
1235 return ath10k_monitor_start(ar);
1237 return ath10k_monitor_stop(ar);
1240 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1242 struct ath10k *ar = arvif->ar;
1244 lockdep_assert_held(&ar->conf_mutex);
1246 if (!arvif->is_started) {
1247 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1254 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1256 struct ath10k *ar = arvif->ar;
1259 lockdep_assert_held(&ar->conf_mutex);
1261 vdev_param = ar->wmi.vdev_param->protection_mode;
1263 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1264 arvif->vdev_id, arvif->use_cts_prot);
1266 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1267 arvif->use_cts_prot ? 1 : 0);
1270 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1272 struct ath10k *ar = arvif->ar;
1273 u32 vdev_param, rts_cts = 0;
1275 lockdep_assert_held(&ar->conf_mutex);
1277 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1279 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1281 if (arvif->num_legacy_stations > 0)
1282 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1283 WMI_RTSCTS_PROFILE);
1285 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1286 WMI_RTSCTS_PROFILE);
1288 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1292 static int ath10k_start_cac(struct ath10k *ar)
1296 lockdep_assert_held(&ar->conf_mutex);
1298 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1300 ret = ath10k_monitor_recalc(ar);
1302 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1303 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1307 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1308 ar->monitor_vdev_id);
1313 static int ath10k_stop_cac(struct ath10k *ar)
1315 lockdep_assert_held(&ar->conf_mutex);
1317 /* CAC is not running - do nothing */
1318 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1321 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1322 ath10k_monitor_stop(ar);
1324 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1329 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1330 struct ieee80211_chanctx_conf *conf,
1335 if (!*ret && conf->radar_enabled)
1339 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1341 bool has_radar = false;
1343 ieee80211_iter_chan_contexts_atomic(ar->hw,
1344 ath10k_mac_has_radar_iter,
1350 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1354 lockdep_assert_held(&ar->conf_mutex);
1356 ath10k_stop_cac(ar);
1358 if (!ath10k_mac_has_radar_enabled(ar))
1361 if (ar->num_started_vdevs > 0)
1364 ret = ath10k_start_cac(ar);
1367 * Not possible to start CAC on current channel so starting
1368 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1369 * by indicating that radar was detected.
1371 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1372 ieee80211_radar_detected(ar->hw);
1376 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1378 struct ath10k *ar = arvif->ar;
1381 lockdep_assert_held(&ar->conf_mutex);
1383 reinit_completion(&ar->vdev_setup_done);
1384 reinit_completion(&ar->vdev_delete_done);
1386 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1388 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1389 arvif->vdev_id, ret);
1393 ret = ath10k_vdev_setup_sync(ar);
1395 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1396 arvif->vdev_id, ret);
1400 WARN_ON(ar->num_started_vdevs == 0);
1402 if (ar->num_started_vdevs != 0) {
1403 ar->num_started_vdevs--;
1404 ath10k_recalc_radar_detection(ar);
1410 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1411 const struct cfg80211_chan_def *chandef,
1414 struct ath10k *ar = arvif->ar;
1415 struct wmi_vdev_start_request_arg arg = {};
1418 lockdep_assert_held(&ar->conf_mutex);
1420 /* Clear arp and ns offload cache */
1421 memset(&arvif->arp_offload, 0, sizeof(arvif->arp_offload));
1422 memset(&arvif->ns_offload, 0, sizeof(arvif->ns_offload));
1424 reinit_completion(&ar->vdev_setup_done);
1425 reinit_completion(&ar->vdev_delete_done);
1427 arg.vdev_id = arvif->vdev_id;
1428 arg.dtim_period = arvif->dtim_period;
1429 arg.bcn_intval = arvif->beacon_interval;
1431 arg.channel.freq = chandef->chan->center_freq;
1432 arg.channel.band_center_freq1 = chandef->center_freq1;
1433 arg.channel.mode = chan_to_phymode(chandef);
1435 arg.channel.min_power = 0;
1436 arg.channel.max_power = chandef->chan->max_power * 2;
1437 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1438 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1440 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1441 arg.ssid = arvif->u.ap.ssid;
1442 arg.ssid_len = arvif->u.ap.ssid_len;
1443 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1445 /* For now allow DFS for AP mode */
1446 arg.channel.chan_radar =
1447 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1448 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1449 arg.ssid = arvif->vif->bss_conf.ssid;
1450 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1453 ath10k_dbg(ar, ATH10K_DBG_MAC,
1454 "mac vdev %d start center_freq %d phymode %s\n",
1455 arg.vdev_id, arg.channel.freq,
1456 ath10k_wmi_phymode_str(arg.channel.mode));
1459 ret = ath10k_wmi_vdev_restart(ar, &arg);
1461 ret = ath10k_wmi_vdev_start(ar, &arg);
1464 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1469 ret = ath10k_vdev_setup_sync(ar);
1472 "failed to synchronize setup for vdev %i restart %d: %d\n",
1473 arg.vdev_id, restart, ret);
1477 ar->num_started_vdevs++;
1478 ath10k_recalc_radar_detection(ar);
1483 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1484 const struct cfg80211_chan_def *def)
1486 return ath10k_vdev_start_restart(arvif, def, false);
1489 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1490 const struct cfg80211_chan_def *def)
1492 return ath10k_vdev_start_restart(arvif, def, true);
1495 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1496 struct sk_buff *bcn)
1498 struct ath10k *ar = arvif->ar;
1499 struct ieee80211_mgmt *mgmt;
1503 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1506 mgmt = (void *)bcn->data;
1507 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1508 mgmt->u.beacon.variable,
1509 bcn->len - (mgmt->u.beacon.variable -
1514 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1516 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1517 arvif->vdev_id, ret);
1524 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1525 u8 oui_type, size_t ie_offset)
1532 if (WARN_ON(skb->len < ie_offset))
1535 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1536 skb->data + ie_offset,
1537 skb->len - ie_offset);
1542 end = skb->data + skb->len;
1545 if (WARN_ON(next > end))
1548 memmove(ie, next, end - next);
1549 skb_trim(skb, skb->len - len);
1554 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1556 struct ath10k *ar = arvif->ar;
1557 struct ieee80211_hw *hw = ar->hw;
1558 struct ieee80211_vif *vif = arvif->vif;
1559 struct ieee80211_mutable_offsets offs = {};
1560 struct sk_buff *bcn;
1563 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1566 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1567 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1570 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1572 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1576 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1578 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1583 /* P2P IE is inserted by firmware automatically (as configured above)
1584 * so remove it from the base beacon template to avoid duplicate P2P
1585 * IEs in beacon frames.
1587 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1588 offsetof(struct ieee80211_mgmt,
1589 u.beacon.variable));
1591 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1596 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1604 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1606 struct ath10k *ar = arvif->ar;
1607 struct ieee80211_hw *hw = ar->hw;
1608 struct ieee80211_vif *vif = arvif->vif;
1609 struct sk_buff *prb;
1612 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1615 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1618 /* For mesh, probe response and beacon share the same template */
1619 if (ieee80211_vif_is_mesh(vif))
1622 prb = ieee80211_proberesp_get(hw, vif);
1624 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1628 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1632 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1640 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1642 struct ath10k *ar = arvif->ar;
1643 struct cfg80211_chan_def def;
1646 /* When originally vdev is started during assign_vif_chanctx() some
1647 * information is missing, notably SSID. Firmware revisions with beacon
1648 * offloading require the SSID to be provided during vdev (re)start to
1649 * handle hidden SSID properly.
1651 * Vdev restart must be done after vdev has been both started and
1652 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1653 * deliver vdev restart response event causing timeouts during vdev
1654 * syncing in ath10k.
1656 * Note: The vdev down/up and template reinstallation could be skipped
1657 * since only wmi-tlv firmware are known to have beacon offload and
1658 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1659 * response delivery. It's probably more robust to keep it as is.
1661 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1664 if (WARN_ON(!arvif->is_started))
1667 if (WARN_ON(!arvif->is_up))
1670 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1673 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1675 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1676 arvif->vdev_id, ret);
1680 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1681 * firmware will crash upon vdev up.
1684 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1686 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1690 ret = ath10k_mac_setup_prb_tmpl(arvif);
1692 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1696 ret = ath10k_vdev_restart(arvif, &def);
1698 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1699 arvif->vdev_id, ret);
1703 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1706 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1707 arvif->vdev_id, ret);
1714 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1715 struct ieee80211_bss_conf *info)
1717 struct ath10k *ar = arvif->ar;
1720 lockdep_assert_held(&arvif->ar->conf_mutex);
1722 if (!info->enable_beacon) {
1723 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1725 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1726 arvif->vdev_id, ret);
1728 arvif->is_up = false;
1730 spin_lock_bh(&arvif->ar->data_lock);
1731 ath10k_mac_vif_beacon_free(arvif);
1732 spin_unlock_bh(&arvif->ar->data_lock);
1737 arvif->tx_seq_no = 0x1000;
1740 ether_addr_copy(arvif->bssid, info->bssid);
1742 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1745 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1746 arvif->vdev_id, ret);
1750 arvif->is_up = true;
1752 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1754 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1755 arvif->vdev_id, ret);
1759 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1762 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1763 struct ieee80211_bss_conf *info,
1764 const u8 self_peer[ETH_ALEN])
1766 struct ath10k *ar = arvif->ar;
1770 lockdep_assert_held(&arvif->ar->conf_mutex);
1772 if (!info->ibss_joined) {
1773 if (is_zero_ether_addr(arvif->bssid))
1776 eth_zero_addr(arvif->bssid);
1781 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1782 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1783 ATH10K_DEFAULT_ATIM);
1785 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1786 arvif->vdev_id, ret);
1789 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1791 struct ath10k *ar = arvif->ar;
1796 lockdep_assert_held(&arvif->ar->conf_mutex);
1798 if (arvif->u.sta.uapsd)
1799 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1801 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1803 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1804 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1806 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1807 value, arvif->vdev_id, ret);
1814 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1816 struct ath10k *ar = arvif->ar;
1821 lockdep_assert_held(&arvif->ar->conf_mutex);
1823 if (arvif->u.sta.uapsd)
1824 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1826 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1828 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1829 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1832 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1833 value, arvif->vdev_id, ret);
1840 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1842 struct ath10k_vif *arvif;
1845 lockdep_assert_held(&ar->conf_mutex);
1847 list_for_each_entry(arvif, &ar->arvifs, list)
1848 if (arvif->is_started)
1854 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1856 struct ath10k *ar = arvif->ar;
1857 struct ieee80211_vif *vif = arvif->vif;
1858 struct ieee80211_conf *conf = &ar->hw->conf;
1859 enum wmi_sta_powersave_param param;
1860 enum wmi_sta_ps_mode psmode;
1865 lockdep_assert_held(&arvif->ar->conf_mutex);
1867 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1870 enable_ps = arvif->ps;
1872 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1873 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1874 ar->running_fw->fw_file.fw_features)) {
1875 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1880 if (!arvif->is_started) {
1881 /* mac80211 can update vif powersave state while disconnected.
1882 * Firmware doesn't behave nicely and consumes more power than
1883 * necessary if PS is disabled on a non-started vdev. Hence
1884 * force-enable PS for non-running vdevs.
1886 psmode = WMI_STA_PS_MODE_ENABLED;
1887 } else if (enable_ps) {
1888 psmode = WMI_STA_PS_MODE_ENABLED;
1889 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1891 ps_timeout = conf->dynamic_ps_timeout;
1892 if (ps_timeout == 0) {
1893 /* Firmware doesn't like 0 */
1894 ps_timeout = ieee80211_tu_to_usec(
1895 vif->bss_conf.beacon_int) / 1000;
1898 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1901 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1902 arvif->vdev_id, ret);
1906 psmode = WMI_STA_PS_MODE_DISABLED;
1909 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1910 arvif->vdev_id, psmode ? "enable" : "disable");
1912 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1914 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1915 psmode, arvif->vdev_id, ret);
1922 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1924 struct ath10k *ar = arvif->ar;
1925 struct wmi_sta_keepalive_arg arg = {};
1928 lockdep_assert_held(&arvif->ar->conf_mutex);
1930 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1933 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1936 /* Some firmware revisions have a bug and ignore the `enabled` field.
1937 * Instead use the interval to disable the keepalive.
1939 arg.vdev_id = arvif->vdev_id;
1941 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1942 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1944 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1946 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1947 arvif->vdev_id, ret);
1954 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1956 struct ath10k *ar = arvif->ar;
1957 struct ieee80211_vif *vif = arvif->vif;
1960 lockdep_assert_held(&arvif->ar->conf_mutex);
1962 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1965 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1968 if (!vif->csa_active)
1974 if (!ieee80211_csa_is_complete(vif)) {
1975 ieee80211_csa_update_counter(vif);
1977 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1979 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1982 ret = ath10k_mac_setup_prb_tmpl(arvif);
1984 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1987 ieee80211_csa_finish(vif);
1991 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1993 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1995 struct ath10k *ar = arvif->ar;
1997 mutex_lock(&ar->conf_mutex);
1998 ath10k_mac_vif_ap_csa_count_down(arvif);
1999 mutex_unlock(&ar->conf_mutex);
2002 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
2003 struct ieee80211_vif *vif)
2005 struct sk_buff *skb = data;
2006 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2007 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2009 if (vif->type != NL80211_IFTYPE_STATION)
2012 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2015 cancel_delayed_work(&arvif->connection_loss_work);
2018 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2020 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2021 IEEE80211_IFACE_ITER_NORMAL,
2022 ath10k_mac_handle_beacon_iter,
2026 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2027 struct ieee80211_vif *vif)
2029 u32 *vdev_id = data;
2030 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2031 struct ath10k *ar = arvif->ar;
2032 struct ieee80211_hw *hw = ar->hw;
2034 if (arvif->vdev_id != *vdev_id)
2040 ieee80211_beacon_loss(vif);
2042 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2043 * (done by mac80211) succeeds but beacons do not resume then it
2044 * doesn't make sense to continue operation. Queue connection loss work
2045 * which can be cancelled when beacon is received.
2047 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2048 ATH10K_CONNECTION_LOSS_HZ);
2051 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2053 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2054 IEEE80211_IFACE_ITER_NORMAL,
2055 ath10k_mac_handle_beacon_miss_iter,
2059 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2061 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2062 connection_loss_work.work);
2063 struct ieee80211_vif *vif = arvif->vif;
2068 ieee80211_connection_loss(vif);
2071 /**********************/
2072 /* Station management */
2073 /**********************/
2075 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2076 struct ieee80211_vif *vif)
2078 /* Some firmware revisions have unstable STA powersave when listen
2079 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2080 * generate NullFunc frames properly even if buffered frames have been
2081 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2082 * buffered frames. Often pinging the device from AP would simply fail.
2084 * As a workaround set it to 1.
2086 if (vif->type == NL80211_IFTYPE_STATION)
2089 return ar->hw->conf.listen_interval;
2092 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2093 struct ieee80211_vif *vif,
2094 struct ieee80211_sta *sta,
2095 struct wmi_peer_assoc_complete_arg *arg)
2097 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2100 lockdep_assert_held(&ar->conf_mutex);
2102 if (vif->type == NL80211_IFTYPE_STATION)
2103 aid = vif->bss_conf.aid;
2107 ether_addr_copy(arg->addr, sta->addr);
2108 arg->vdev_id = arvif->vdev_id;
2109 arg->peer_aid = aid;
2110 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2111 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2112 arg->peer_num_spatial_streams = 1;
2113 arg->peer_caps = vif->bss_conf.assoc_capability;
2116 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2117 struct ieee80211_vif *vif,
2118 struct ieee80211_sta *sta,
2119 struct wmi_peer_assoc_complete_arg *arg)
2121 struct ieee80211_bss_conf *info = &vif->bss_conf;
2122 struct cfg80211_chan_def def;
2123 struct cfg80211_bss *bss;
2124 const u8 *rsnie = NULL;
2125 const u8 *wpaie = NULL;
2127 lockdep_assert_held(&ar->conf_mutex);
2129 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2132 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2133 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2135 const struct cfg80211_bss_ies *ies;
2138 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2140 ies = rcu_dereference(bss->ies);
2142 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2143 WLAN_OUI_TYPE_MICROSOFT_WPA,
2147 cfg80211_put_bss(ar->hw->wiphy, bss);
2150 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2151 if (rsnie || wpaie) {
2152 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2153 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2157 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2158 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2162 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2163 ar->running_fw->fw_file.fw_features)) {
2164 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2168 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2169 struct ieee80211_vif *vif,
2170 struct ieee80211_sta *sta,
2171 struct wmi_peer_assoc_complete_arg *arg)
2173 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2174 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2175 struct cfg80211_chan_def def;
2176 const struct ieee80211_supported_band *sband;
2177 const struct ieee80211_rate *rates;
2178 enum ieee80211_band band;
2183 lockdep_assert_held(&ar->conf_mutex);
2185 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2188 band = def.chan->band;
2189 sband = ar->hw->wiphy->bands[band];
2190 ratemask = sta->supp_rates[band];
2191 ratemask &= arvif->bitrate_mask.control[band].legacy;
2192 rates = sband->bitrates;
2194 rateset->num_rates = 0;
2196 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2197 if (!(ratemask & 1))
2200 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2201 rateset->rates[rateset->num_rates] = rate;
2202 rateset->num_rates++;
2207 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2211 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2212 if (ht_mcs_mask[nss])
2219 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2223 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2224 if (vht_mcs_mask[nss])
2230 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2231 struct ieee80211_vif *vif,
2232 struct ieee80211_sta *sta,
2233 struct wmi_peer_assoc_complete_arg *arg)
2235 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2236 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2237 struct cfg80211_chan_def def;
2238 enum ieee80211_band band;
2239 const u8 *ht_mcs_mask;
2240 const u16 *vht_mcs_mask;
2245 lockdep_assert_held(&ar->conf_mutex);
2247 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2250 if (!ht_cap->ht_supported)
2253 band = def.chan->band;
2254 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2255 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2257 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2258 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2261 arg->peer_flags |= ar->wmi.peer_flags->ht;
2262 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2263 ht_cap->ampdu_factor)) - 1;
2265 arg->peer_mpdu_density =
2266 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2268 arg->peer_ht_caps = ht_cap->cap;
2269 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2271 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2272 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2274 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2275 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2276 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2279 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2280 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2281 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2283 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2284 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2287 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2288 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2289 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2292 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2293 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2294 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2295 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2296 arg->peer_rate_caps |= stbc;
2297 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2300 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2301 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2302 else if (ht_cap->mcs.rx_mask[1])
2303 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2305 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2306 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2307 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2308 max_nss = (i / 8) + 1;
2309 arg->peer_ht_rates.rates[n++] = i;
2313 * This is a workaround for HT-enabled STAs which break the spec
2314 * and have no HT capabilities RX mask (no HT RX MCS map).
2316 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2317 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2319 * Firmware asserts if such situation occurs.
2322 arg->peer_ht_rates.num_rates = 8;
2323 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2324 arg->peer_ht_rates.rates[i] = i;
2326 arg->peer_ht_rates.num_rates = n;
2327 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2330 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2332 arg->peer_ht_rates.num_rates,
2333 arg->peer_num_spatial_streams);
2336 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2337 struct ath10k_vif *arvif,
2338 struct ieee80211_sta *sta)
2344 lockdep_assert_held(&ar->conf_mutex);
2346 if (sta->wme && sta->uapsd_queues) {
2347 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2348 sta->uapsd_queues, sta->max_sp);
2350 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2351 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2352 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2353 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2354 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2355 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2356 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2357 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2358 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2359 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2360 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2361 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2363 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2364 max_sp = sta->max_sp;
2366 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2368 WMI_AP_PS_PEER_PARAM_UAPSD,
2371 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2372 arvif->vdev_id, ret);
2376 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2378 WMI_AP_PS_PEER_PARAM_MAX_SP,
2381 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2382 arvif->vdev_id, ret);
2386 /* TODO setup this based on STA listen interval and
2387 beacon interval. Currently we don't know
2388 sta->listen_interval - mac80211 patch required.
2389 Currently use 10 seconds */
2390 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2391 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2394 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2395 arvif->vdev_id, ret);
2404 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2405 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2412 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2413 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2417 idx_limit = fls(mcs_map) - 1;
2421 switch (idx_limit) {
2422 case 0: /* fall through */
2423 case 1: /* fall through */
2424 case 2: /* fall through */
2425 case 3: /* fall through */
2426 case 4: /* fall through */
2427 case 5: /* fall through */
2428 case 6: /* fall through */
2430 /* see ath10k_mac_can_set_bitrate_mask() */
2434 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2437 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2440 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2443 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2447 tx_mcs_set &= ~(0x3 << (nss * 2));
2448 tx_mcs_set |= mcs << (nss * 2);
2454 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2455 struct ieee80211_vif *vif,
2456 struct ieee80211_sta *sta,
2457 struct wmi_peer_assoc_complete_arg *arg)
2459 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2460 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2461 struct cfg80211_chan_def def;
2462 enum ieee80211_band band;
2463 const u16 *vht_mcs_mask;
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 == IEEE80211_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. */
2493 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2494 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2495 ampdu_factor)) - 1);
2497 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2498 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2500 arg->peer_vht_rates.rx_max_rate =
2501 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2502 arg->peer_vht_rates.rx_mcs_set =
2503 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2504 arg->peer_vht_rates.tx_max_rate =
2505 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2506 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2507 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2509 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2510 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2513 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2514 struct ieee80211_vif *vif,
2515 struct ieee80211_sta *sta,
2516 struct wmi_peer_assoc_complete_arg *arg)
2518 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2520 switch (arvif->vdev_type) {
2521 case WMI_VDEV_TYPE_AP:
2523 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2525 if (sta->wme && sta->uapsd_queues) {
2526 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2527 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2530 case WMI_VDEV_TYPE_STA:
2531 if (vif->bss_conf.qos)
2532 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2534 case WMI_VDEV_TYPE_IBSS:
2536 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2542 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2543 sta->addr, !!(arg->peer_flags &
2544 arvif->ar->wmi.peer_flags->qos));
2547 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2549 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2550 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2553 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2554 struct ieee80211_vif *vif,
2555 struct ieee80211_sta *sta,
2556 struct wmi_peer_assoc_complete_arg *arg)
2558 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2559 struct cfg80211_chan_def def;
2560 enum ieee80211_band band;
2561 const u8 *ht_mcs_mask;
2562 const u16 *vht_mcs_mask;
2563 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2565 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2568 band = def.chan->band;
2569 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2570 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2573 case IEEE80211_BAND_2GHZ:
2574 if (sta->vht_cap.vht_supported &&
2575 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2576 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2577 phymode = MODE_11AC_VHT40;
2579 phymode = MODE_11AC_VHT20;
2580 } else if (sta->ht_cap.ht_supported &&
2581 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2582 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2583 phymode = MODE_11NG_HT40;
2585 phymode = MODE_11NG_HT20;
2586 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2593 case IEEE80211_BAND_5GHZ:
2597 if (sta->vht_cap.vht_supported &&
2598 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2599 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2600 phymode = MODE_11AC_VHT80;
2601 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2602 phymode = MODE_11AC_VHT40;
2603 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2604 phymode = MODE_11AC_VHT20;
2605 } else if (sta->ht_cap.ht_supported &&
2606 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2607 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2608 phymode = MODE_11NA_HT40;
2610 phymode = MODE_11NA_HT20;
2620 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2621 sta->addr, ath10k_wmi_phymode_str(phymode));
2623 arg->peer_phymode = phymode;
2624 WARN_ON(phymode == MODE_UNKNOWN);
2627 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2628 struct ieee80211_vif *vif,
2629 struct ieee80211_sta *sta,
2630 struct wmi_peer_assoc_complete_arg *arg)
2632 lockdep_assert_held(&ar->conf_mutex);
2634 memset(arg, 0, sizeof(*arg));
2636 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2637 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2638 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2639 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2640 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2641 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2642 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2647 static const u32 ath10k_smps_map[] = {
2648 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2649 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2650 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2651 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2654 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2656 const struct ieee80211_sta_ht_cap *ht_cap)
2660 if (!ht_cap->ht_supported)
2663 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2664 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2666 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2669 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2670 WMI_PEER_SMPS_STATE,
2671 ath10k_smps_map[smps]);
2674 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2675 struct ieee80211_vif *vif,
2676 struct ieee80211_sta_vht_cap vht_cap)
2678 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2683 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2686 if (!(ar->vht_cap_info &
2687 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2688 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2689 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2690 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2693 param = ar->wmi.vdev_param->txbf;
2696 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2699 /* The following logic is correct. If a remote STA advertises support
2700 * for being a beamformer then we should enable us being a beamformee.
2703 if (ar->vht_cap_info &
2704 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2705 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2706 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2707 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2709 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2710 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2713 if (ar->vht_cap_info &
2714 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2715 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2716 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2717 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2719 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2720 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2723 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2724 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2726 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2727 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2729 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2731 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2739 /* can be called only in mac80211 callbacks due to `key_count` usage */
2740 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2741 struct ieee80211_vif *vif,
2742 struct ieee80211_bss_conf *bss_conf)
2744 struct ath10k *ar = hw->priv;
2745 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2746 struct ieee80211_sta_ht_cap ht_cap;
2747 struct ieee80211_sta_vht_cap vht_cap;
2748 struct wmi_peer_assoc_complete_arg peer_arg;
2749 struct ieee80211_sta *ap_sta;
2752 lockdep_assert_held(&ar->conf_mutex);
2754 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2755 arvif->vdev_id, arvif->bssid, arvif->aid);
2759 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2761 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2762 bss_conf->bssid, arvif->vdev_id);
2767 /* ap_sta must be accessed only within rcu section which must be left
2768 * before calling ath10k_setup_peer_smps() which might sleep. */
2769 ht_cap = ap_sta->ht_cap;
2770 vht_cap = ap_sta->vht_cap;
2772 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2774 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2775 bss_conf->bssid, arvif->vdev_id, ret);
2782 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2784 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2785 bss_conf->bssid, arvif->vdev_id, ret);
2789 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2791 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2792 arvif->vdev_id, ret);
2796 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2798 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2799 arvif->vdev_id, bss_conf->bssid, ret);
2803 ath10k_dbg(ar, ATH10K_DBG_MAC,
2804 "mac vdev %d up (associated) bssid %pM aid %d\n",
2805 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2807 WARN_ON(arvif->is_up);
2809 arvif->aid = bss_conf->aid;
2810 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2812 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2814 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2815 arvif->vdev_id, ret);
2819 arvif->is_up = true;
2821 /* Workaround: Some firmware revisions (tested with qca6174
2822 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2823 * poked with peer param command.
2825 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2826 WMI_PEER_DUMMY_VAR, 1);
2828 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2829 arvif->bssid, arvif->vdev_id, ret);
2834 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2835 struct ieee80211_vif *vif)
2837 struct ath10k *ar = hw->priv;
2838 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2839 struct ieee80211_sta_vht_cap vht_cap = {};
2842 lockdep_assert_held(&ar->conf_mutex);
2844 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2845 arvif->vdev_id, arvif->bssid);
2847 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2849 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2850 arvif->vdev_id, ret);
2852 arvif->def_wep_key_idx = -1;
2854 if (!QCA_REV_WCN3990(ar)) {
2855 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2857 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2858 arvif->vdev_id, ret);
2863 arvif->is_up = false;
2865 cancel_delayed_work_sync(&arvif->connection_loss_work);
2868 static int ath10k_station_assoc(struct ath10k *ar,
2869 struct ieee80211_vif *vif,
2870 struct ieee80211_sta *sta,
2873 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2874 struct wmi_peer_assoc_complete_arg peer_arg;
2877 lockdep_assert_held(&ar->conf_mutex);
2879 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2881 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2882 sta->addr, arvif->vdev_id, ret);
2886 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2888 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2889 sta->addr, arvif->vdev_id, ret);
2893 /* Re-assoc is run only to update supported rates for given station. It
2894 * doesn't make much sense to reconfigure the peer completely.
2897 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2900 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2901 arvif->vdev_id, ret);
2905 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2907 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2908 sta->addr, arvif->vdev_id, ret);
2913 arvif->num_legacy_stations++;
2914 ret = ath10k_recalc_rtscts_prot(arvif);
2916 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2917 arvif->vdev_id, ret);
2922 /* Plumb cached keys only for static WEP */
2923 if (arvif->def_wep_key_idx != -1) {
2924 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2926 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2927 arvif->vdev_id, ret);
2936 static int ath10k_station_disassoc(struct ath10k *ar,
2937 struct ieee80211_vif *vif,
2938 struct ieee80211_sta *sta)
2940 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2943 lockdep_assert_held(&ar->conf_mutex);
2946 arvif->num_legacy_stations--;
2947 ret = ath10k_recalc_rtscts_prot(arvif);
2949 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2950 arvif->vdev_id, ret);
2955 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2957 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2958 arvif->vdev_id, ret);
2969 static int ath10k_update_channel_list(struct ath10k *ar)
2971 struct ieee80211_hw *hw = ar->hw;
2972 struct ieee80211_supported_band **bands;
2973 enum ieee80211_band band;
2974 struct ieee80211_channel *channel;
2975 struct wmi_scan_chan_list_arg arg = {0};
2976 struct wmi_channel_arg *ch;
2982 lockdep_assert_held(&ar->conf_mutex);
2984 bands = hw->wiphy->bands;
2985 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2989 for (i = 0; i < bands[band]->n_channels; i++) {
2990 if (bands[band]->channels[i].flags &
2991 IEEE80211_CHAN_DISABLED)
2998 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2999 arg.channels = kzalloc(len, GFP_KERNEL);
3004 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3008 for (i = 0; i < bands[band]->n_channels; i++) {
3009 channel = &bands[band]->channels[i];
3011 if (channel->flags & IEEE80211_CHAN_DISABLED)
3014 ch->allow_ht = true;
3016 /* FIXME: when should we really allow VHT? */
3017 ch->allow_vht = true;
3020 !(channel->flags & IEEE80211_CHAN_NO_IR);
3023 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3026 !!(channel->flags & IEEE80211_CHAN_RADAR);
3028 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3029 ch->passive = passive;
3031 /* the firmware is ignoring the "radar" flag of the
3032 * channel and is scanning actively using Probe Requests
3033 * on "Radar detection"/DFS channels which are not
3034 * marked as "available"
3036 ch->passive |= ch->chan_radar;
3038 ch->freq = channel->center_freq;
3039 ch->band_center_freq1 = channel->center_freq;
3041 ch->max_power = channel->max_power * 2;
3042 ch->max_reg_power = channel->max_reg_power * 2;
3043 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3044 ch->reg_class_id = 0; /* FIXME */
3046 /* FIXME: why use only legacy modes, why not any
3047 * HT/VHT modes? Would that even make any
3049 if (channel->band == IEEE80211_BAND_2GHZ)
3050 ch->mode = MODE_11G;
3052 ch->mode = MODE_11A;
3054 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3057 ath10k_dbg(ar, ATH10K_DBG_WMI,
3058 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3059 ch - arg.channels, arg.n_channels,
3060 ch->freq, ch->max_power, ch->max_reg_power,
3061 ch->max_antenna_gain, ch->mode);
3067 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3068 kfree(arg.channels);
3073 static enum wmi_dfs_region
3074 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3076 switch (dfs_region) {
3077 case NL80211_DFS_UNSET:
3078 return WMI_UNINIT_DFS_DOMAIN;
3079 case NL80211_DFS_FCC:
3080 return WMI_FCC_DFS_DOMAIN;
3081 case NL80211_DFS_ETSI:
3082 return WMI_ETSI_DFS_DOMAIN;
3083 case NL80211_DFS_JP:
3084 return WMI_MKK4_DFS_DOMAIN;
3086 return WMI_UNINIT_DFS_DOMAIN;
3089 static void ath10k_regd_update(struct ath10k *ar)
3091 struct reg_dmn_pair_mapping *regpair;
3093 enum wmi_dfs_region wmi_dfs_reg;
3094 enum nl80211_dfs_regions nl_dfs_reg;
3096 lockdep_assert_held(&ar->conf_mutex);
3098 ret = ath10k_update_channel_list(ar);
3100 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3102 regpair = ar->ath_common.regulatory.regpair;
3104 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3105 nl_dfs_reg = ar->dfs_detector->region;
3106 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3108 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3111 /* Target allows setting up per-band regdomain but ath_common provides
3112 * a combined one only */
3113 ret = ath10k_wmi_pdev_set_regdomain(ar,
3114 regpair->reg_domain,
3115 regpair->reg_domain, /* 2ghz */
3116 regpair->reg_domain, /* 5ghz */
3117 regpair->reg_2ghz_ctl,
3118 regpair->reg_5ghz_ctl,
3121 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3124 static void ath10k_reg_notifier(struct wiphy *wiphy,
3125 struct regulatory_request *request)
3127 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3128 struct ath10k *ar = hw->priv;
3131 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3133 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3134 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3135 request->dfs_region);
3136 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3137 request->dfs_region);
3139 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3140 request->dfs_region);
3143 mutex_lock(&ar->conf_mutex);
3144 if (ar->state == ATH10K_STATE_ON)
3145 ath10k_regd_update(ar);
3146 mutex_unlock(&ar->conf_mutex);
3153 enum ath10k_mac_tx_path {
3155 ATH10K_MAC_TX_HTT_MGMT,
3156 ATH10K_MAC_TX_WMI_MGMT,
3157 ATH10K_MAC_TX_UNKNOWN,
3160 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3162 lockdep_assert_held(&ar->htt.tx_lock);
3164 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3165 ar->tx_paused |= BIT(reason);
3166 ieee80211_stop_queues(ar->hw);
3169 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3170 struct ieee80211_vif *vif)
3172 struct ath10k *ar = data;
3173 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3175 if (arvif->tx_paused)
3178 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3181 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3183 lockdep_assert_held(&ar->htt.tx_lock);
3185 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3186 ar->tx_paused &= ~BIT(reason);
3191 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3192 IEEE80211_IFACE_ITER_RESUME_ALL,
3193 ath10k_mac_tx_unlock_iter,
3196 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3199 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3201 struct ath10k *ar = arvif->ar;
3203 lockdep_assert_held(&ar->htt.tx_lock);
3205 WARN_ON(reason >= BITS_PER_LONG);
3206 arvif->tx_paused |= BIT(reason);
3207 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3210 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3212 struct ath10k *ar = arvif->ar;
3214 lockdep_assert_held(&ar->htt.tx_lock);
3216 WARN_ON(reason >= BITS_PER_LONG);
3217 arvif->tx_paused &= ~BIT(reason);
3222 if (arvif->tx_paused)
3225 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3228 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3229 enum wmi_tlv_tx_pause_id pause_id,
3230 enum wmi_tlv_tx_pause_action action)
3232 struct ath10k *ar = arvif->ar;
3234 lockdep_assert_held(&ar->htt.tx_lock);
3237 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3238 ath10k_mac_vif_tx_lock(arvif, pause_id);
3240 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3241 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3244 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3245 action, arvif->vdev_id);
3250 struct ath10k_mac_tx_pause {
3252 enum wmi_tlv_tx_pause_id pause_id;
3253 enum wmi_tlv_tx_pause_action action;
3256 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3257 struct ieee80211_vif *vif)
3259 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3260 struct ath10k_mac_tx_pause *arg = data;
3262 if (arvif->vdev_id != arg->vdev_id)
3265 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3268 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3269 enum wmi_tlv_tx_pause_id pause_id,
3270 enum wmi_tlv_tx_pause_action action)
3272 struct ath10k_mac_tx_pause arg = {
3274 .pause_id = pause_id,
3278 spin_lock_bh(&ar->htt.tx_lock);
3279 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3280 IEEE80211_IFACE_ITER_RESUME_ALL,
3281 ath10k_mac_handle_tx_pause_iter,
3283 spin_unlock_bh(&ar->htt.tx_lock);
3286 static enum ath10k_hw_txrx_mode
3287 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3288 struct ieee80211_vif *vif,
3289 struct ieee80211_sta *sta,
3290 struct sk_buff *skb)
3292 const struct ieee80211_hdr *hdr = (void *)skb->data;
3293 __le16 fc = hdr->frame_control;
3295 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3296 return ATH10K_HW_TXRX_RAW;
3298 if (ieee80211_is_mgmt(fc))
3299 return ATH10K_HW_TXRX_MGMT;
3303 * NullFunc frames are mostly used to ping if a client or AP are still
3304 * reachable and responsive. This implies tx status reports must be
3305 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3306 * come to a conclusion that the other end disappeared and tear down
3307 * BSS connection or it can never disconnect from BSS/client (which is
3310 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3311 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3312 * which seems to deliver correct tx reports for NullFunc frames. The
3313 * downside of using it is it ignores client powersave state so it can
3314 * end up disconnecting sleeping clients in AP mode. It should fix STA
3315 * mode though because AP don't sleep.
3317 if (ar->htt.target_version_major < 3 &&
3318 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3319 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3320 ar->running_fw->fw_file.fw_features) &&
3321 !test_bit(ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR,
3322 ar->running_fw->fw_file.fw_features))
3323 return ATH10K_HW_TXRX_MGMT;
3327 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3328 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3329 * to work with Ethernet txmode so use it.
3331 * FIXME: Check if raw mode works with TDLS.
3333 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3334 return ATH10K_HW_TXRX_ETHERNET;
3336 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3337 return ATH10K_HW_TXRX_RAW;
3339 return ATH10K_HW_TXRX_NATIVE_WIFI;
3342 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3343 struct sk_buff *skb)
3345 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3346 const struct ieee80211_hdr *hdr = (void *)skb->data;
3347 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3348 IEEE80211_TX_CTL_INJECTED;
3350 if (!ieee80211_has_protected(hdr->frame_control))
3353 if ((info->flags & mask) == mask)
3357 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3362 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3363 * Control in the header.
3365 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3367 struct ieee80211_hdr *hdr = (void *)skb->data;
3368 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3371 if (!ieee80211_is_data_qos(hdr->frame_control))
3374 qos_ctl = ieee80211_get_qos_ctl(hdr);
3375 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3376 skb->data, (void *)qos_ctl - (void *)skb->data);
3377 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3379 /* Some firmware revisions don't handle sending QoS NullFunc well.
3380 * These frames are mainly used for CQM purposes so it doesn't really
3381 * matter whether QoS NullFunc or NullFunc are sent.
3383 hdr = (void *)skb->data;
3384 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3385 cb->flags &= ~ATH10K_SKB_F_QOS;
3387 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3390 static void ath10k_tx_h_8023(struct sk_buff *skb)
3392 struct ieee80211_hdr *hdr;
3393 struct rfc1042_hdr *rfc1042;
3400 hdr = (void *)skb->data;
3401 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3402 rfc1042 = (void *)skb->data + hdrlen;
3404 ether_addr_copy(da, ieee80211_get_DA(hdr));
3405 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3406 type = rfc1042->snap_type;
3408 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3409 skb_push(skb, sizeof(*eth));
3411 eth = (void *)skb->data;
3412 ether_addr_copy(eth->h_dest, da);
3413 ether_addr_copy(eth->h_source, sa);
3414 eth->h_proto = type;
3417 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3418 struct ieee80211_vif *vif,
3419 struct sk_buff *skb)
3421 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3422 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3424 /* This is case only for P2P_GO */
3425 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3428 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3429 spin_lock_bh(&ar->data_lock);
3430 if (arvif->u.ap.noa_data)
3431 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3433 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3434 arvif->u.ap.noa_data,
3435 arvif->u.ap.noa_len);
3436 spin_unlock_bh(&ar->data_lock);
3440 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3441 struct ieee80211_vif *vif,
3442 struct ieee80211_txq *txq,
3443 struct sk_buff *skb)
3445 struct ieee80211_hdr *hdr = (void *)skb->data;
3446 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3449 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3450 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3452 if (ieee80211_is_mgmt(hdr->frame_control))
3453 cb->flags |= ATH10K_SKB_F_MGMT;
3455 if (ieee80211_is_data_qos(hdr->frame_control))
3456 cb->flags |= ATH10K_SKB_F_QOS;
3462 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3464 /* FIXME: Not really sure since when the behaviour changed. At some
3465 * point new firmware stopped requiring creation of peer entries for
3466 * offchannel tx (and actually creating them causes issues with wmi-htc
3467 * tx credit replenishment and reliability). Assuming it's at least 3.4
3468 * because that's when the `freq` was introduced to TX_FRM HTT command.
3470 return (ar->htt.target_version_major >= 3 &&
3471 ar->htt.target_version_minor >= 4 &&
3472 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3475 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3477 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3480 spin_lock_bh(&ar->data_lock);
3482 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3483 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3488 __skb_queue_tail(q, skb);
3489 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3492 spin_unlock_bh(&ar->data_lock);
3497 static enum ath10k_mac_tx_path
3498 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3499 struct sk_buff *skb,
3500 enum ath10k_hw_txrx_mode txmode)
3503 case ATH10K_HW_TXRX_RAW:
3504 case ATH10K_HW_TXRX_NATIVE_WIFI:
3505 case ATH10K_HW_TXRX_ETHERNET:
3506 return ATH10K_MAC_TX_HTT;
3507 case ATH10K_HW_TXRX_MGMT:
3508 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3509 ar->running_fw->fw_file.fw_features) ||
3510 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3512 return ATH10K_MAC_TX_WMI_MGMT;
3513 else if (ar->htt.target_version_major >= 3)
3514 return ATH10K_MAC_TX_HTT;
3516 return ATH10K_MAC_TX_HTT_MGMT;
3519 return ATH10K_MAC_TX_UNKNOWN;
3522 static int ath10k_mac_tx_submit(struct ath10k *ar,
3523 enum ath10k_hw_txrx_mode txmode,
3524 enum ath10k_mac_tx_path txpath,
3525 struct sk_buff *skb)
3527 struct ath10k_htt *htt = &ar->htt;
3531 case ATH10K_MAC_TX_HTT:
3532 ret = ath10k_htt_tx(htt, txmode, skb);
3534 case ATH10K_MAC_TX_HTT_MGMT:
3535 ret = ath10k_htt_mgmt_tx(htt, skb);
3537 case ATH10K_MAC_TX_WMI_MGMT:
3538 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3540 case ATH10K_MAC_TX_UNKNOWN:
3547 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3549 ieee80211_free_txskb(ar->hw, skb);
3555 /* This function consumes the sk_buff regardless of return value as far as
3556 * caller is concerned so no freeing is necessary afterwards.
3558 static int ath10k_mac_tx(struct ath10k *ar,
3559 struct ieee80211_vif *vif,
3560 struct ieee80211_sta *sta,
3561 enum ath10k_hw_txrx_mode txmode,
3562 enum ath10k_mac_tx_path txpath,
3563 struct sk_buff *skb)
3565 struct ieee80211_hw *hw = ar->hw;
3566 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3570 /* We should disable CCK RATE due to P2P */
3571 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3572 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3575 case ATH10K_HW_TXRX_MGMT:
3576 case ATH10K_HW_TXRX_NATIVE_WIFI:
3577 ath10k_tx_h_nwifi(hw, skb);
3578 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3579 ath10k_tx_h_seq_no(vif, skb);
3581 case ATH10K_HW_TXRX_ETHERNET:
3582 ath10k_tx_h_8023(skb);
3584 case ATH10K_HW_TXRX_RAW:
3585 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3587 ieee80211_free_txskb(hw, skb);
3592 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3593 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3594 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3597 skb_queue_tail(&ar->offchan_tx_queue, skb);
3598 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3603 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3605 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3612 void ath10k_offchan_tx_purge(struct ath10k *ar)
3614 struct sk_buff *skb;
3617 skb = skb_dequeue(&ar->offchan_tx_queue);
3621 ieee80211_free_txskb(ar->hw, skb);
3625 void ath10k_offchan_tx_work(struct work_struct *work)
3627 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3628 struct ath10k_peer *peer;
3629 struct ath10k_vif *arvif;
3630 enum ath10k_hw_txrx_mode txmode;
3631 enum ath10k_mac_tx_path txpath;
3632 struct ieee80211_hdr *hdr;
3633 struct ieee80211_vif *vif;
3634 struct ieee80211_sta *sta;
3635 struct sk_buff *skb;
3636 const u8 *peer_addr;
3639 unsigned long time_left;
3640 bool tmp_peer_created = false;
3642 /* FW requirement: We must create a peer before FW will send out
3643 * an offchannel frame. Otherwise the frame will be stuck and
3644 * never transmitted. We delete the peer upon tx completion.
3645 * It is unlikely that a peer for offchannel tx will already be
3646 * present. However it may be in some rare cases so account for that.
3647 * Otherwise we might remove a legitimate peer and break stuff. */
3650 skb = skb_dequeue(&ar->offchan_tx_queue);
3654 mutex_lock(&ar->conf_mutex);
3656 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3659 hdr = (struct ieee80211_hdr *)skb->data;
3660 peer_addr = ieee80211_get_DA(hdr);
3662 spin_lock_bh(&ar->data_lock);
3663 vdev_id = ar->scan.vdev_id;
3664 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3665 spin_unlock_bh(&ar->data_lock);
3668 /* FIXME: should this use ath10k_warn()? */
3669 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3670 peer_addr, vdev_id);
3673 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3675 WMI_PEER_TYPE_DEFAULT);
3677 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3678 peer_addr, vdev_id, ret);
3679 tmp_peer_created = (ret == 0);
3682 spin_lock_bh(&ar->data_lock);
3683 reinit_completion(&ar->offchan_tx_completed);
3684 ar->offchan_tx_skb = skb;
3685 spin_unlock_bh(&ar->data_lock);
3687 /* It's safe to access vif and sta - conf_mutex guarantees that
3688 * sta_state() and remove_interface() are locked exclusively
3689 * out wrt to this offchannel worker.
3691 arvif = ath10k_get_arvif(ar, vdev_id);
3694 sta = ieee80211_find_sta(vif, peer_addr);
3700 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3701 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3703 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3705 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3711 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3713 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3716 if (!peer && tmp_peer_created) {
3717 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3719 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3720 peer_addr, vdev_id, ret);
3723 mutex_unlock(&ar->conf_mutex);
3727 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3729 struct sk_buff *skb;
3732 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3736 ieee80211_free_txskb(ar->hw, skb);
3740 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3742 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3743 struct sk_buff *skb;
3748 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3752 if (QCA_REV_WCN3990(ar)) {
3753 paddr = dma_map_single(ar->dev, skb->data,
3754 skb->len, DMA_TO_DEVICE);
3757 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3759 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3761 dma_unmap_single(ar->dev, paddr, skb->len,
3763 ieee80211_free_txskb(ar->hw, skb);
3766 ret = ath10k_wmi_mgmt_tx(ar, skb);
3768 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3770 ieee80211_free_txskb(ar->hw, skb);
3776 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3778 struct ath10k_txq *artxq;
3783 artxq = (void *)txq->drv_priv;
3784 INIT_LIST_HEAD(&artxq->list);
3787 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3789 struct ath10k_txq *artxq;
3790 struct ath10k_skb_cb *cb;
3791 struct sk_buff *msdu;
3797 artxq = (void *)txq->drv_priv;
3798 spin_lock_bh(&ar->txqs_lock);
3799 if (!list_empty(&artxq->list))
3800 list_del_init(&artxq->list);
3801 spin_unlock_bh(&ar->txqs_lock);
3803 spin_lock_bh(&ar->htt.tx_lock);
3804 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3805 cb = ATH10K_SKB_CB(msdu);
3809 spin_unlock_bh(&ar->htt.tx_lock);
3812 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3816 struct ath10k_peer *peer;
3818 lockdep_assert_held(&ar->data_lock);
3820 peer = ar->peer_map[peer_id];
3825 return peer->sta->txq[tid];
3827 return peer->vif->txq;
3832 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3833 struct ieee80211_txq *txq)
3835 struct ath10k *ar = hw->priv;
3836 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3838 /* No need to get locks */
3840 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3843 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3846 if (artxq->num_fw_queued < artxq->num_push_allowed)
3852 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3853 struct ieee80211_txq *txq)
3855 struct ath10k *ar = hw->priv;
3856 struct ath10k_htt *htt = &ar->htt;
3857 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3858 struct ieee80211_vif *vif = txq->vif;
3859 struct ieee80211_sta *sta = txq->sta;
3860 enum ath10k_hw_txrx_mode txmode;
3861 enum ath10k_mac_tx_path txpath;
3862 struct sk_buff *skb;
3863 struct ieee80211_hdr *hdr;
3865 bool is_mgmt, is_presp;
3868 spin_lock_bh(&ar->htt.tx_lock);
3869 ret = ath10k_htt_tx_inc_pending(htt);
3870 spin_unlock_bh(&ar->htt.tx_lock);
3875 skb = ieee80211_tx_dequeue(hw, txq);
3877 spin_lock_bh(&ar->htt.tx_lock);
3878 ath10k_htt_tx_dec_pending(htt);
3879 spin_unlock_bh(&ar->htt.tx_lock);
3884 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3887 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3888 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3889 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3892 hdr = (struct ieee80211_hdr *)skb->data;
3893 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3895 spin_lock_bh(&ar->htt.tx_lock);
3896 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3899 ath10k_htt_tx_dec_pending(htt);
3900 spin_unlock_bh(&ar->htt.tx_lock);
3903 spin_unlock_bh(&ar->htt.tx_lock);
3906 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3907 if (unlikely(ret)) {
3908 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3910 spin_lock_bh(&ar->htt.tx_lock);
3911 ath10k_htt_tx_dec_pending(htt);
3913 ath10k_htt_tx_mgmt_dec_pending(htt);
3914 spin_unlock_bh(&ar->htt.tx_lock);
3919 spin_lock_bh(&ar->htt.tx_lock);
3920 artxq->num_fw_queued++;
3921 spin_unlock_bh(&ar->htt.tx_lock);
3926 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3928 struct ieee80211_hw *hw = ar->hw;
3929 struct ieee80211_txq *txq;
3930 struct ath10k_txq *artxq;
3931 struct ath10k_txq *last;
3935 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3938 spin_lock_bh(&ar->txqs_lock);
3941 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3942 while (!list_empty(&ar->txqs)) {
3943 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3944 txq = container_of((void *)artxq, struct ieee80211_txq,
3947 /* Prevent aggressive sta/tid taking over tx queue */
3950 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3951 ret = ath10k_mac_tx_push_txq(hw, txq);
3956 list_del_init(&artxq->list);
3958 list_add_tail(&artxq->list, &ar->txqs);
3960 ath10k_htt_tx_txq_update(hw, txq);
3962 if (artxq == last || (ret < 0 && ret != -ENOENT))
3967 spin_unlock_bh(&ar->txqs_lock);
3974 void __ath10k_scan_finish(struct ath10k *ar)
3976 lockdep_assert_held(&ar->data_lock);
3978 switch (ar->scan.state) {
3979 case ATH10K_SCAN_IDLE:
3981 case ATH10K_SCAN_RUNNING:
3982 case ATH10K_SCAN_ABORTING:
3983 if (!ar->scan.is_roc)
3984 ieee80211_scan_completed(ar->hw,
3986 ATH10K_SCAN_ABORTING));
3987 else if (ar->scan.roc_notify)
3988 ieee80211_remain_on_channel_expired(ar->hw);
3990 case ATH10K_SCAN_STARTING:
3991 ar->scan.state = ATH10K_SCAN_IDLE;
3992 ar->scan_channel = NULL;
3993 ar->scan.roc_freq = 0;
3994 ath10k_offchan_tx_purge(ar);
3995 cancel_delayed_work(&ar->scan.timeout);
3996 complete(&ar->scan.completed);
4001 void ath10k_scan_finish(struct ath10k *ar)
4003 spin_lock_bh(&ar->data_lock);
4004 __ath10k_scan_finish(ar);
4005 spin_unlock_bh(&ar->data_lock);
4008 static int ath10k_scan_stop(struct ath10k *ar)
4010 struct wmi_stop_scan_arg arg = {
4011 .req_id = 1, /* FIXME */
4012 .req_type = WMI_SCAN_STOP_ONE,
4013 .u.scan_id = ATH10K_SCAN_ID,
4017 lockdep_assert_held(&ar->conf_mutex);
4019 ret = ath10k_wmi_stop_scan(ar, &arg);
4021 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4025 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4027 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4029 } else if (ret > 0) {
4034 /* Scan state should be updated upon scan completion but in case
4035 * firmware fails to deliver the event (for whatever reason) it is
4036 * desired to clean up scan state anyway. Firmware may have just
4037 * dropped the scan completion event delivery due to transport pipe
4038 * being overflown with data and/or it can recover on its own before
4039 * next scan request is submitted.
4041 spin_lock_bh(&ar->data_lock);
4042 if (ar->scan.state != ATH10K_SCAN_IDLE)
4043 __ath10k_scan_finish(ar);
4044 spin_unlock_bh(&ar->data_lock);
4049 static void ath10k_scan_abort(struct ath10k *ar)
4053 lockdep_assert_held(&ar->conf_mutex);
4055 spin_lock_bh(&ar->data_lock);
4057 switch (ar->scan.state) {
4058 case ATH10K_SCAN_IDLE:
4059 /* This can happen if timeout worker kicked in and called
4060 * abortion while scan completion was being processed.
4063 case ATH10K_SCAN_STARTING:
4064 case ATH10K_SCAN_ABORTING:
4065 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4066 ath10k_scan_state_str(ar->scan.state),
4069 case ATH10K_SCAN_RUNNING:
4070 ar->scan.state = ATH10K_SCAN_ABORTING;
4071 spin_unlock_bh(&ar->data_lock);
4073 ret = ath10k_scan_stop(ar);
4075 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4077 spin_lock_bh(&ar->data_lock);
4081 spin_unlock_bh(&ar->data_lock);
4084 void ath10k_scan_timeout_work(struct work_struct *work)
4086 struct ath10k *ar = container_of(work, struct ath10k,
4089 mutex_lock(&ar->conf_mutex);
4090 ath10k_scan_abort(ar);
4091 mutex_unlock(&ar->conf_mutex);
4094 static int ath10k_start_scan(struct ath10k *ar,
4095 const struct wmi_start_scan_arg *arg)
4099 lockdep_assert_held(&ar->conf_mutex);
4101 ret = ath10k_wmi_start_scan(ar, arg);
4105 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4107 ret = ath10k_scan_stop(ar);
4109 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4114 /* If we failed to start the scan, return error code at
4115 * this point. This is probably due to some issue in the
4116 * firmware, but no need to wedge the driver due to that...
4118 spin_lock_bh(&ar->data_lock);
4119 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4120 spin_unlock_bh(&ar->data_lock);
4123 spin_unlock_bh(&ar->data_lock);
4128 /**********************/
4129 /* mac80211 callbacks */
4130 /**********************/
4132 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4133 struct ieee80211_tx_control *control,
4134 struct sk_buff *skb)
4136 struct ath10k *ar = hw->priv;
4137 struct ath10k_htt *htt = &ar->htt;
4138 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4139 struct ieee80211_vif *vif = info->control.vif;
4140 struct ieee80211_sta *sta = control->sta;
4141 struct ieee80211_txq *txq = NULL;
4142 struct ieee80211_hdr *hdr = (void *)skb->data;
4143 enum ath10k_hw_txrx_mode txmode;
4144 enum ath10k_mac_tx_path txpath;
4150 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4152 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4153 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4154 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4155 txpath == ATH10K_MAC_TX_HTT_MGMT);
4156 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4159 spin_lock_bh(&ar->htt.tx_lock);
4160 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4162 ret = ath10k_htt_tx_inc_pending(htt);
4164 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4166 spin_unlock_bh(&ar->htt.tx_lock);
4167 ieee80211_free_txskb(ar->hw, skb);
4171 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4173 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4175 ath10k_htt_tx_dec_pending(htt);
4176 spin_unlock_bh(&ar->htt.tx_lock);
4177 ieee80211_free_txskb(ar->hw, skb);
4180 spin_unlock_bh(&ar->htt.tx_lock);
4183 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
4185 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4187 spin_lock_bh(&ar->htt.tx_lock);
4188 ath10k_htt_tx_dec_pending(htt);
4190 ath10k_htt_tx_mgmt_dec_pending(htt);
4191 spin_unlock_bh(&ar->htt.tx_lock);
4197 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4198 struct ieee80211_txq *txq)
4200 struct ath10k *ar = hw->priv;
4201 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4202 struct ieee80211_txq *f_txq;
4203 struct ath10k_txq *f_artxq;
4207 spin_lock_bh(&ar->txqs_lock);
4208 if (list_empty(&artxq->list))
4209 list_add_tail(&artxq->list, &ar->txqs);
4211 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4212 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4213 list_del_init(&f_artxq->list);
4215 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4216 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4221 list_add_tail(&f_artxq->list, &ar->txqs);
4222 spin_unlock_bh(&ar->txqs_lock);
4224 ath10k_htt_tx_txq_update(hw, f_txq);
4225 ath10k_htt_tx_txq_update(hw, txq);
4228 /* Must not be called with conf_mutex held as workers can use that also. */
4229 void ath10k_drain_tx(struct ath10k *ar)
4231 /* make sure rcu-protected mac80211 tx path itself is drained */
4234 ath10k_offchan_tx_purge(ar);
4235 ath10k_mgmt_over_wmi_tx_purge(ar);
4237 cancel_work_sync(&ar->offchan_tx_work);
4238 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4241 void ath10k_halt(struct ath10k *ar)
4243 struct ath10k_vif *arvif;
4245 lockdep_assert_held(&ar->conf_mutex);
4247 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4248 ar->filter_flags = 0;
4249 ar->monitor = false;
4250 ar->monitor_arvif = NULL;
4252 if (ar->monitor_started)
4253 ath10k_monitor_stop(ar);
4255 ar->monitor_started = false;
4258 ath10k_scan_finish(ar);
4259 ath10k_peer_cleanup_all(ar);
4260 ath10k_core_stop(ar);
4261 ath10k_hif_power_down(ar);
4263 spin_lock_bh(&ar->data_lock);
4264 list_for_each_entry(arvif, &ar->arvifs, list)
4265 ath10k_mac_vif_beacon_cleanup(arvif);
4266 spin_unlock_bh(&ar->data_lock);
4269 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4271 struct ath10k *ar = hw->priv;
4273 mutex_lock(&ar->conf_mutex);
4275 *tx_ant = ar->cfg_tx_chainmask;
4276 *rx_ant = ar->cfg_rx_chainmask;
4278 mutex_unlock(&ar->conf_mutex);
4283 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4285 /* It is not clear that allowing gaps in chainmask
4286 * is helpful. Probably it will not do what user
4287 * is hoping for, so warn in that case.
4289 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4292 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4296 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4298 int nsts = ar->vht_cap_info;
4300 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4301 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4303 /* If firmware does not deliver to host number of space-time
4304 * streams supported, assume it support up to 4 BF STS and return
4305 * the value for VHT CAP: nsts-1)
4313 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4315 int sound_dim = ar->vht_cap_info;
4317 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4318 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4320 /* If the sounding dimension is not advertised by the firmware,
4321 * let's use a default value of 1
4329 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4331 struct ieee80211_sta_vht_cap vht_cap = {0};
4336 vht_cap.vht_supported = 1;
4337 vht_cap.cap = ar->vht_cap_info;
4339 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4340 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4341 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4342 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4343 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4348 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4349 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4350 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4351 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4352 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4358 for (i = 0; i < 8; i++) {
4359 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4360 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4362 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4365 if (ar->cfg_tx_chainmask <= 1)
4366 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4368 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4369 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4374 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4377 struct ieee80211_sta_ht_cap ht_cap = {0};
4379 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4382 ht_cap.ht_supported = 1;
4383 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4384 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4385 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4386 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4388 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4390 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4391 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4393 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4394 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4396 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4399 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4400 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4405 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4406 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4408 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4411 stbc = ar->ht_cap_info;
4412 stbc &= WMI_HT_CAP_RX_STBC;
4413 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4414 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4415 stbc &= IEEE80211_HT_CAP_RX_STBC;
4420 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4421 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4423 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4424 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4426 /* max AMSDU is implicitly taken from vht_cap_info */
4427 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4428 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4430 for (i = 0; i < ar->num_rf_chains; i++) {
4431 if (ar->cfg_rx_chainmask & BIT(i))
4432 ht_cap.mcs.rx_mask[i] = 0xFF;
4435 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4440 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4442 struct ieee80211_supported_band *band;
4443 struct ieee80211_sta_vht_cap vht_cap;
4444 struct ieee80211_sta_ht_cap ht_cap;
4446 ht_cap = ath10k_get_ht_cap(ar);
4447 vht_cap = ath10k_create_vht_cap(ar);
4449 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4450 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4451 band->ht_cap = ht_cap;
4453 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4454 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4455 band->ht_cap = ht_cap;
4456 band->vht_cap = vht_cap;
4460 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4464 lockdep_assert_held(&ar->conf_mutex);
4466 ath10k_check_chain_mask(ar, tx_ant, "tx");
4467 ath10k_check_chain_mask(ar, rx_ant, "rx");
4469 ar->cfg_tx_chainmask = tx_ant;
4470 ar->cfg_rx_chainmask = rx_ant;
4472 if ((ar->state != ATH10K_STATE_ON) &&
4473 (ar->state != ATH10K_STATE_RESTARTED))
4476 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4479 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4484 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4487 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4492 /* Reload HT/VHT capability */
4493 ath10k_mac_setup_ht_vht_cap(ar);
4498 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4500 struct ath10k *ar = hw->priv;
4503 mutex_lock(&ar->conf_mutex);
4504 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4505 mutex_unlock(&ar->conf_mutex);
4509 static int ath10k_start(struct ieee80211_hw *hw)
4511 struct ath10k *ar = hw->priv;
4516 * This makes sense only when restarting hw. It is harmless to call
4517 * unconditionally. This is necessary to make sure no HTT/WMI tx
4518 * commands will be submitted while restarting.
4520 ath10k_drain_tx(ar);
4522 mutex_lock(&ar->conf_mutex);
4524 switch (ar->state) {
4525 case ATH10K_STATE_OFF:
4526 ar->state = ATH10K_STATE_ON;
4528 case ATH10K_STATE_RESTARTING:
4529 if (!test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
4531 ar->state = ATH10K_STATE_RESTARTED;
4533 case ATH10K_STATE_ON:
4534 case ATH10K_STATE_RESTARTED:
4535 case ATH10K_STATE_WEDGED:
4539 case ATH10K_STATE_UTF:
4544 ret = ath10k_hif_power_up(ar);
4546 ath10k_err(ar, "Could not init hif: %d\n", ret);
4550 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4551 &ar->normal_mode_fw);
4553 ath10k_err(ar, "Could not init core: %d\n", ret);
4554 goto err_power_down;
4557 param = ar->wmi.pdev_param->pmf_qos;
4558 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4560 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4564 param = ar->wmi.pdev_param->dynamic_bw;
4565 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4567 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4571 param = ar->wmi.pdev_param->idle_ps_config;
4572 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4574 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4578 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4579 ret = ath10k_wmi_adaptive_qcs(ar, true);
4581 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4587 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4588 param = ar->wmi.pdev_param->burst_enable;
4589 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4591 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4596 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4599 * By default FW set ARP frames ac to voice (6). In that case ARP
4600 * exchange is not working properly for UAPSD enabled AP. ARP requests
4601 * which arrives with access category 0 are processed by network stack
4602 * and send back with access category 0, but FW changes access category
4603 * to 6. Set ARP frames access category to best effort (0) solves
4607 param = ar->wmi.pdev_param->arp_ac_override;
4608 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4610 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4615 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4616 ar->running_fw->fw_file.fw_features)) {
4617 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4618 WMI_CCA_DETECT_LEVEL_AUTO,
4619 WMI_CCA_DETECT_MARGIN_AUTO);
4621 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4625 ar->sifs_burst_enabled = false;
4628 param = ar->wmi.pdev_param->ani_enable;
4629 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4631 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4636 ar->ani_enabled = true;
4638 if (ath10k_peer_stats_enabled(ar)) {
4639 param = ar->wmi.pdev_param->peer_stats_update_period;
4640 ret = ath10k_wmi_pdev_set_param(ar, param,
4641 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4644 "failed to set peer stats period : %d\n",
4650 param = ar->wmi.pdev_param->enable_btcoex;
4651 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4652 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4653 ar->running_fw->fw_file.fw_features)) {
4654 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4657 "failed to set btcoex param: %d\n", ret);
4660 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4663 ar->num_started_vdevs = 0;
4664 ath10k_regd_update(ar);
4666 ath10k_spectral_start(ar);
4667 ath10k_thermal_set_throttling(ar);
4669 mutex_unlock(&ar->conf_mutex);
4673 ath10k_core_stop(ar);
4676 ath10k_hif_power_down(ar);
4679 ar->state = ATH10K_STATE_OFF;
4682 mutex_unlock(&ar->conf_mutex);
4686 static void ath10k_stop(struct ieee80211_hw *hw)
4688 struct ath10k *ar = hw->priv;
4690 ath10k_drain_tx(ar);
4692 mutex_lock(&ar->conf_mutex);
4693 if (ar->state != ATH10K_STATE_OFF) {
4695 ar->state = ATH10K_STATE_OFF;
4697 mutex_unlock(&ar->conf_mutex);
4699 cancel_delayed_work_sync(&ar->scan.timeout);
4700 cancel_work_sync(&ar->restart_work);
4703 static int ath10k_config_ps(struct ath10k *ar)
4705 struct ath10k_vif *arvif;
4708 lockdep_assert_held(&ar->conf_mutex);
4710 list_for_each_entry(arvif, &ar->arvifs, list) {
4711 ret = ath10k_mac_vif_setup_ps(arvif);
4713 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4721 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4726 lockdep_assert_held(&ar->conf_mutex);
4728 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4730 param = ar->wmi.pdev_param->txpower_limit2g;
4731 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4733 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4738 param = ar->wmi.pdev_param->txpower_limit5g;
4739 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4741 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4749 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4751 struct ath10k_vif *arvif;
4752 int ret, txpower = -1;
4754 lockdep_assert_held(&ar->conf_mutex);
4756 list_for_each_entry(arvif, &ar->arvifs, list) {
4757 if (arvif->txpower <= 0)
4761 txpower = arvif->txpower;
4763 txpower = min(txpower, arvif->txpower);
4769 ret = ath10k_mac_txpower_setup(ar, txpower);
4771 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4779 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4781 struct ath10k *ar = hw->priv;
4782 struct ieee80211_conf *conf = &hw->conf;
4785 mutex_lock(&ar->conf_mutex);
4787 if (changed & IEEE80211_CONF_CHANGE_PS)
4788 ath10k_config_ps(ar);
4790 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4791 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4792 ret = ath10k_monitor_recalc(ar);
4794 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4797 mutex_unlock(&ar->conf_mutex);
4801 static u32 get_nss_from_chainmask(u16 chain_mask)
4803 if ((chain_mask & 0xf) == 0xf)
4805 else if ((chain_mask & 0x7) == 0x7)
4807 else if ((chain_mask & 0x3) == 0x3)
4812 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4815 struct ath10k *ar = arvif->ar;
4819 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4822 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4823 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4824 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4825 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4827 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4828 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4829 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4830 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4835 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4836 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4838 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4839 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4840 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4842 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4843 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4845 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4846 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4847 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4849 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4850 ar->wmi.vdev_param->txbf, value);
4855 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4856 * because we will send mgmt frames without CCK. This requirement
4857 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4860 static int ath10k_add_interface(struct ieee80211_hw *hw,
4861 struct ieee80211_vif *vif)
4863 struct ath10k *ar = hw->priv;
4864 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4865 struct ath10k_peer *peer;
4866 enum wmi_sta_powersave_param param;
4873 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4875 mutex_lock(&ar->conf_mutex);
4877 memset(arvif, 0, sizeof(*arvif));
4878 ath10k_mac_txq_init(vif->txq);
4883 INIT_LIST_HEAD(&arvif->list);
4884 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4885 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4886 ath10k_mac_vif_sta_connection_loss_work);
4888 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4889 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4890 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4891 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4892 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4893 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4896 if (ar->num_peers >= ar->max_num_peers) {
4897 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4902 if (ar->free_vdev_map == 0) {
4903 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4907 bit = __ffs64(ar->free_vdev_map);
4909 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4910 bit, ar->free_vdev_map);
4912 arvif->vdev_id = bit;
4913 arvif->vdev_subtype =
4914 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4916 switch (vif->type) {
4917 case NL80211_IFTYPE_P2P_DEVICE:
4918 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4919 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4920 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4922 case NL80211_IFTYPE_UNSPECIFIED:
4923 case NL80211_IFTYPE_STATION:
4924 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4926 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4927 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4929 case NL80211_IFTYPE_ADHOC:
4930 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4932 case NL80211_IFTYPE_MESH_POINT:
4933 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4934 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4935 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4936 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4938 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4941 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4943 case NL80211_IFTYPE_AP:
4944 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4947 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4948 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4950 case NL80211_IFTYPE_MONITOR:
4951 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4958 /* Using vdev_id as queue number will make it very easy to do per-vif
4959 * tx queue locking. This shouldn't wrap due to interface combinations
4960 * but do a modulo for correctness sake and prevent using offchannel tx
4961 * queues for regular vif tx.
4963 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4964 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4965 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4967 /* Some firmware revisions don't wait for beacon tx completion before
4968 * sending another SWBA event. This could lead to hardware using old
4969 * (freed) beacon data in some cases, e.g. tx credit starvation
4970 * combined with missed TBTT. This is very very rare.
4972 * On non-IOMMU-enabled hosts this could be a possible security issue
4973 * because hw could beacon some random data on the air. On
4974 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4975 * device would crash.
4977 * Since there are no beacon tx completions (implicit nor explicit)
4978 * propagated to host the only workaround for this is to allocate a
4979 * DMA-coherent buffer for a lifetime of a vif and use it for all
4980 * beacon tx commands. Worst case for this approach is some beacons may
4981 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4983 if (vif->type == NL80211_IFTYPE_ADHOC ||
4984 vif->type == NL80211_IFTYPE_MESH_POINT ||
4985 vif->type == NL80211_IFTYPE_AP) {
4986 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4987 IEEE80211_MAX_FRAME_LEN,
4988 &arvif->beacon_paddr,
4990 if (!arvif->beacon_buf) {
4992 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4997 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4998 arvif->nohwcrypt = true;
5000 if (arvif->nohwcrypt &&
5001 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
5002 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5006 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5007 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5008 arvif->beacon_buf ? "single-buf" : "per-skb");
5010 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5011 arvif->vdev_subtype, vif->addr);
5013 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5014 arvif->vdev_id, ret);
5018 if ((arvif->vdev_type == WMI_VDEV_TYPE_STA) && QCA_REV_WCN3990(ar)) {
5019 ret = ath10k_wmi_csa_offload(ar, arvif->vdev_id, true);
5021 ath10k_err(ar, "CSA offload failed for vdev %i: %d\n",
5022 arvif->vdev_id, ret);
5023 goto err_vdev_delete;
5027 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5028 spin_lock_bh(&ar->data_lock);
5029 list_add(&arvif->list, &ar->arvifs);
5030 spin_unlock_bh(&ar->data_lock);
5032 /* It makes no sense to have firmware do keepalives. mac80211 already
5033 * takes care of this with idle connection polling.
5035 ret = ath10k_mac_vif_disable_keepalive(arvif);
5037 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5038 arvif->vdev_id, ret);
5039 goto err_vdev_delete;
5042 arvif->def_wep_key_idx = -1;
5044 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5045 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5046 ATH10K_HW_TXRX_NATIVE_WIFI);
5047 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5048 if (ret && ret != -EOPNOTSUPP) {
5049 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5050 arvif->vdev_id, ret);
5051 goto err_vdev_delete;
5054 /* Configuring number of spatial stream for monitor interface is causing
5055 * target assert in qca9888 and qca6174.
5057 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5058 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5060 vdev_param = ar->wmi.vdev_param->nss;
5061 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5064 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5065 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5067 goto err_vdev_delete;
5071 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5072 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5073 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5074 vif->addr, WMI_PEER_TYPE_DEFAULT);
5076 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5077 arvif->vdev_id, ret);
5078 goto err_vdev_delete;
5081 spin_lock_bh(&ar->data_lock);
5083 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5085 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5086 vif->addr, arvif->vdev_id);
5087 spin_unlock_bh(&ar->data_lock);
5089 goto err_peer_delete;
5092 arvif->peer_id = find_first_bit(peer->peer_ids,
5093 ATH10K_MAX_NUM_PEER_IDS);
5095 spin_unlock_bh(&ar->data_lock);
5097 arvif->peer_id = HTT_INVALID_PEERID;
5100 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5101 ret = ath10k_mac_set_kickout(arvif);
5103 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5104 arvif->vdev_id, ret);
5105 goto err_peer_delete;
5109 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5110 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5111 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5112 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5115 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5116 arvif->vdev_id, ret);
5117 goto err_peer_delete;
5120 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5122 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5123 arvif->vdev_id, ret);
5124 goto err_peer_delete;
5127 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5129 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5130 arvif->vdev_id, ret);
5131 goto err_peer_delete;
5135 ret = ath10k_mac_set_txbf_conf(arvif);
5137 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5138 arvif->vdev_id, ret);
5139 goto err_peer_delete;
5142 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5144 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5145 arvif->vdev_id, ret);
5146 goto err_peer_delete;
5149 arvif->txpower = vif->bss_conf.txpower;
5150 ret = ath10k_mac_txpower_recalc(ar);
5152 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5153 goto err_peer_delete;
5156 if (vif->type == NL80211_IFTYPE_MONITOR) {
5157 ar->monitor_arvif = arvif;
5158 ret = ath10k_monitor_recalc(ar);
5160 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5161 goto err_peer_delete;
5165 spin_lock_bh(&ar->htt.tx_lock);
5167 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5168 spin_unlock_bh(&ar->htt.tx_lock);
5170 mutex_unlock(&ar->conf_mutex);
5174 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5175 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5176 ath10k_peer_delete(ar, arvif->vdev_id, vif->addr);
5179 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5180 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5181 spin_lock_bh(&ar->data_lock);
5182 list_del(&arvif->list);
5183 spin_unlock_bh(&ar->data_lock);
5186 if (arvif->beacon_buf) {
5187 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5188 arvif->beacon_buf, arvif->beacon_paddr);
5189 arvif->beacon_buf = NULL;
5192 mutex_unlock(&ar->conf_mutex);
5197 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5201 for (i = 0; i < BITS_PER_LONG; i++)
5202 ath10k_mac_vif_tx_unlock(arvif, i);
5205 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5206 struct ieee80211_vif *vif)
5208 struct ath10k *ar = hw->priv;
5209 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5210 struct ath10k_peer *peer;
5211 unsigned long time_left;
5215 cancel_work_sync(&arvif->ap_csa_work);
5216 cancel_delayed_work_sync(&arvif->connection_loss_work);
5218 mutex_lock(&ar->conf_mutex);
5220 spin_lock_bh(&ar->data_lock);
5221 ath10k_mac_vif_beacon_cleanup(arvif);
5222 spin_unlock_bh(&ar->data_lock);
5224 ret = ath10k_spectral_vif_stop(arvif);
5226 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5227 arvif->vdev_id, ret);
5229 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5230 spin_lock_bh(&ar->data_lock);
5231 list_del(&arvif->list);
5232 spin_unlock_bh(&ar->data_lock);
5234 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5235 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5236 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
5239 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5240 arvif->vdev_id, ret);
5242 kfree(arvif->u.ap.noa_data);
5245 if ((arvif->vdev_type == WMI_VDEV_TYPE_STA) && QCA_REV_WCN3990(ar))
5246 ath10k_wmi_csa_offload(ar, arvif->vdev_id, false);
5248 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5251 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5253 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5254 arvif->vdev_id, ret);
5256 if (QCA_REV_WCN3990(ar)) {
5257 time_left = wait_for_completion_timeout(
5258 &ar->vdev_delete_done,
5259 ATH10K_VDEV_DELETE_TIMEOUT_HZ);
5260 if (time_left == 0) {
5261 ath10k_warn(ar, "Timeout in receiving vdev delete resp\n");
5266 /* Some firmware revisions don't notify host about self-peer removal
5267 * until after associated vdev is deleted.
5269 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5270 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5271 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5274 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5275 arvif->vdev_id, ret);
5277 spin_lock_bh(&ar->data_lock);
5279 spin_unlock_bh(&ar->data_lock);
5282 spin_lock_bh(&ar->data_lock);
5283 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5284 peer = ar->peer_map[i];
5288 if (peer->vif == vif) {
5289 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5290 vif->addr, arvif->vdev_id);
5294 spin_unlock_bh(&ar->data_lock);
5296 ath10k_peer_cleanup(ar, arvif->vdev_id);
5297 ath10k_mac_txq_unref(ar, vif->txq);
5299 if (vif->type == NL80211_IFTYPE_MONITOR) {
5300 ar->monitor_arvif = NULL;
5301 ret = ath10k_monitor_recalc(ar);
5303 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5306 ret = ath10k_mac_txpower_recalc(ar);
5308 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5310 spin_lock_bh(&ar->htt.tx_lock);
5311 ath10k_mac_vif_tx_unlock_all(arvif);
5312 spin_unlock_bh(&ar->htt.tx_lock);
5314 ath10k_mac_txq_unref(ar, vif->txq);
5316 mutex_unlock(&ar->conf_mutex);
5319 static int ath10k_change_interface(struct ieee80211_hw *hw,
5320 struct ieee80211_vif *vif,
5321 enum nl80211_iftype new_type, bool p2p)
5323 struct ath10k *ar = hw->priv;
5326 ath10k_dbg(ar, ATH10K_DBG_MAC,
5327 "change_interface new: %d (%d), old: %d (%d)\n", new_type,
5328 p2p, vif->type, vif->p2p);
5330 if (new_type != vif->type || vif->p2p != p2p) {
5331 ath10k_remove_interface(hw, vif);
5332 vif->type = new_type;
5334 ret = ath10k_add_interface(hw, vif);
5340 * FIXME: Has to be verified.
5342 #define SUPPORTED_FILTERS \
5347 FIF_BCN_PRBRESP_PROMISC | \
5351 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5352 unsigned int changed_flags,
5353 unsigned int *total_flags,
5356 struct ath10k *ar = hw->priv;
5359 mutex_lock(&ar->conf_mutex);
5361 changed_flags &= SUPPORTED_FILTERS;
5362 *total_flags &= SUPPORTED_FILTERS;
5363 ar->filter_flags = *total_flags;
5365 ret = ath10k_monitor_recalc(ar);
5367 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5369 mutex_unlock(&ar->conf_mutex);
5372 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5373 struct ieee80211_vif *vif,
5374 struct ieee80211_bss_conf *info,
5377 struct ath10k *ar = hw->priv;
5378 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5380 u32 vdev_param, pdev_param, slottime, preamble;
5382 mutex_lock(&ar->conf_mutex);
5384 if (changed & BSS_CHANGED_IBSS)
5385 ath10k_control_ibss(arvif, info, vif->addr);
5387 if (changed & BSS_CHANGED_BEACON_INT) {
5388 arvif->beacon_interval = info->beacon_int;
5389 vdev_param = ar->wmi.vdev_param->beacon_interval;
5390 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5391 arvif->beacon_interval);
5392 ath10k_dbg(ar, ATH10K_DBG_MAC,
5393 "mac vdev %d beacon_interval %d\n",
5394 arvif->vdev_id, arvif->beacon_interval);
5397 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5398 arvif->vdev_id, ret);
5401 if (changed & BSS_CHANGED_BEACON) {
5402 ath10k_dbg(ar, ATH10K_DBG_MAC,
5403 "vdev %d set beacon tx mode to staggered\n",
5406 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5407 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5408 WMI_BEACON_STAGGERED_MODE);
5410 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5411 arvif->vdev_id, ret);
5413 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5415 ath10k_warn(ar, "failed to update beacon template: %d\n",
5418 if (ieee80211_vif_is_mesh(vif)) {
5419 /* mesh doesn't use SSID but firmware needs it */
5420 strncpy(arvif->u.ap.ssid, "mesh",
5421 sizeof(arvif->u.ap.ssid));
5422 arvif->u.ap.ssid_len = 4;
5426 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5427 ret = ath10k_mac_setup_prb_tmpl(arvif);
5429 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5430 arvif->vdev_id, ret);
5433 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5434 arvif->dtim_period = info->dtim_period;
5436 ath10k_dbg(ar, ATH10K_DBG_MAC,
5437 "mac vdev %d dtim_period %d\n",
5438 arvif->vdev_id, arvif->dtim_period);
5440 vdev_param = ar->wmi.vdev_param->dtim_period;
5441 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5442 arvif->dtim_period);
5444 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5445 arvif->vdev_id, ret);
5448 if (changed & BSS_CHANGED_SSID &&
5449 vif->type == NL80211_IFTYPE_AP) {
5450 arvif->u.ap.ssid_len = info->ssid_len;
5452 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5453 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5456 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5457 ether_addr_copy(arvif->bssid, info->bssid);
5459 if (changed & BSS_CHANGED_BEACON_ENABLED)
5460 ath10k_control_beaconing(arvif, info);
5462 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5463 arvif->use_cts_prot = info->use_cts_prot;
5465 ret = ath10k_recalc_rtscts_prot(arvif);
5467 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5468 arvif->vdev_id, ret);
5470 if (ath10k_mac_can_set_cts_prot(arvif)) {
5471 ret = ath10k_mac_set_cts_prot(arvif);
5473 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5474 arvif->vdev_id, ret);
5478 if (changed & BSS_CHANGED_ERP_SLOT) {
5479 if (info->use_short_slot)
5480 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5483 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5485 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5486 arvif->vdev_id, slottime);
5488 vdev_param = ar->wmi.vdev_param->slot_time;
5489 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5492 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5493 arvif->vdev_id, ret);
5496 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5497 if (info->use_short_preamble)
5498 preamble = WMI_VDEV_PREAMBLE_SHORT;
5500 preamble = WMI_VDEV_PREAMBLE_LONG;
5502 ath10k_dbg(ar, ATH10K_DBG_MAC,
5503 "mac vdev %d preamble %dn",
5504 arvif->vdev_id, preamble);
5506 vdev_param = ar->wmi.vdev_param->preamble;
5507 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5510 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5511 arvif->vdev_id, ret);
5514 if (changed & BSS_CHANGED_ASSOC) {
5516 /* Workaround: Make sure monitor vdev is not running
5517 * when associating to prevent some firmware revisions
5518 * (e.g. 10.1 and 10.2) from crashing.
5520 if (ar->monitor_started)
5521 ath10k_monitor_stop(ar);
5522 ath10k_bss_assoc(hw, vif, info);
5523 ath10k_monitor_recalc(ar);
5525 ath10k_bss_disassoc(hw, vif);
5529 if (changed & BSS_CHANGED_TXPOWER) {
5530 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5531 arvif->vdev_id, info->txpower);
5533 arvif->txpower = info->txpower;
5534 ret = ath10k_mac_txpower_recalc(ar);
5536 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5539 if (changed & BSS_CHANGED_PS) {
5540 arvif->ps = vif->bss_conf.ps;
5542 ret = ath10k_config_ps(ar);
5544 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5545 arvif->vdev_id, ret);
5548 mutex_unlock(&ar->conf_mutex);
5551 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5552 struct ieee80211_vif *vif,
5553 struct ieee80211_scan_request *hw_req)
5555 struct ath10k *ar = hw->priv;
5556 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5557 struct cfg80211_scan_request *req = &hw_req->req;
5558 struct wmi_start_scan_arg arg;
5560 int ret = 0, ie_skip_len = 0;
5563 mutex_lock(&ar->conf_mutex);
5565 spin_lock_bh(&ar->data_lock);
5566 switch (ar->scan.state) {
5567 case ATH10K_SCAN_IDLE:
5568 reinit_completion(&ar->scan.started);
5569 reinit_completion(&ar->scan.completed);
5570 ar->scan.state = ATH10K_SCAN_STARTING;
5571 ar->scan.is_roc = false;
5572 ar->scan.vdev_id = arvif->vdev_id;
5575 case ATH10K_SCAN_STARTING:
5576 case ATH10K_SCAN_RUNNING:
5577 case ATH10K_SCAN_ABORTING:
5581 spin_unlock_bh(&ar->data_lock);
5586 memset(&arg, 0, sizeof(arg));
5587 ath10k_wmi_start_scan_init(ar, &arg);
5588 arg.vdev_id = arvif->vdev_id;
5589 arg.scan_id = ATH10K_SCAN_ID;
5592 if (QCA_REV_WCN3990(ar)) {
5594 while (ptr[0] == WLAN_EID_SUPP_RATES ||
5595 ptr[0] == WLAN_EID_EXT_SUPP_RATES) {
5596 ie_skip_len = ptr[1] + 2;
5600 arg.ie_len = req->ie_len - ie_skip_len;
5601 memcpy(arg.ie, req->ie + ie_skip_len, arg.ie_len);
5605 arg.n_ssids = req->n_ssids;
5606 for (i = 0; i < arg.n_ssids; i++) {
5607 arg.ssids[i].len = req->ssids[i].ssid_len;
5608 arg.ssids[i].ssid = req->ssids[i].ssid;
5610 if (QCA_REV_WCN3990(ar)) {
5611 arg.scan_ctrl_flags &=
5612 ~(WMI_SCAN_ADD_BCAST_PROBE_REQ |
5613 WMI_SCAN_CHAN_STAT_EVENT);
5616 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5619 if (req->n_channels) {
5620 arg.n_channels = req->n_channels;
5621 for (i = 0; i < arg.n_channels; i++)
5622 arg.channels[i] = req->channels[i]->center_freq;
5625 ret = ath10k_start_scan(ar, &arg);
5627 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5628 spin_lock_bh(&ar->data_lock);
5629 ar->scan.state = ATH10K_SCAN_IDLE;
5630 spin_unlock_bh(&ar->data_lock);
5633 /* Add a 200ms margin to account for event/command processing */
5634 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5635 msecs_to_jiffies(arg.max_scan_time +
5639 mutex_unlock(&ar->conf_mutex);
5643 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5644 struct ieee80211_vif *vif)
5646 struct ath10k *ar = hw->priv;
5648 mutex_lock(&ar->conf_mutex);
5649 ath10k_scan_abort(ar);
5650 mutex_unlock(&ar->conf_mutex);
5652 cancel_delayed_work_sync(&ar->scan.timeout);
5655 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5656 struct ath10k_vif *arvif,
5657 enum set_key_cmd cmd,
5658 struct ieee80211_key_conf *key)
5660 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5663 /* 10.1 firmware branch requires default key index to be set to group
5664 * key index after installing it. Otherwise FW/HW Txes corrupted
5665 * frames with multi-vif APs. This is not required for main firmware
5666 * branch (e.g. 636).
5668 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5670 * FIXME: It remains unknown if this is required for multi-vif STA
5671 * interfaces on 10.1.
5674 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5675 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5678 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5681 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5684 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5690 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5693 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5694 arvif->vdev_id, ret);
5697 static void ath10k_set_rekey_data(struct ieee80211_hw *hw,
5698 struct ieee80211_vif *vif,
5699 struct cfg80211_gtk_rekey_data *data)
5701 struct ath10k *ar = hw->priv;
5702 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5704 mutex_lock(&ar->conf_mutex);
5705 memcpy(&arvif->gtk_rekey_data.kek, data->kek, NL80211_KEK_LEN);
5706 memcpy(&arvif->gtk_rekey_data.kck, data->kck, NL80211_KCK_LEN);
5707 arvif->gtk_rekey_data.replay_ctr =
5708 be64_to_cpup((__be64 *)data->replay_ctr);
5709 arvif->gtk_rekey_data.valid = true;
5710 mutex_unlock(&ar->conf_mutex);
5713 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5714 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5715 struct ieee80211_key_conf *key)
5717 struct ath10k *ar = hw->priv;
5718 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5719 struct ath10k_peer *peer;
5720 const u8 *peer_addr;
5721 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5722 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5728 /* this one needs to be done in software */
5729 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5732 if (arvif->nohwcrypt)
5735 if (key->keyidx > WMI_MAX_KEY_INDEX)
5738 mutex_lock(&ar->conf_mutex);
5741 peer_addr = sta->addr;
5742 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5743 peer_addr = vif->bss_conf.bssid;
5745 peer_addr = vif->addr;
5747 key->hw_key_idx = key->keyidx;
5751 arvif->wep_keys[key->keyidx] = key;
5753 arvif->wep_keys[key->keyidx] = NULL;
5756 /* the peer should not disappear in mid-way (unless FW goes awry) since
5757 * we already hold conf_mutex. we just make sure its there now. */
5758 spin_lock_bh(&ar->data_lock);
5759 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5760 spin_unlock_bh(&ar->data_lock);
5763 if (cmd == SET_KEY) {
5764 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5769 /* if the peer doesn't exist there is no key to disable
5775 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5776 flags |= WMI_KEY_PAIRWISE;
5778 flags |= WMI_KEY_GROUP;
5781 if (cmd == DISABLE_KEY)
5782 ath10k_clear_vdev_key(arvif, key);
5784 /* When WEP keys are uploaded it's possible that there are
5785 * stations associated already (e.g. when merging) without any
5786 * keys. Static WEP needs an explicit per-peer key upload.
5788 if (vif->type == NL80211_IFTYPE_ADHOC &&
5790 ath10k_mac_vif_update_wep_key(arvif, key);
5792 /* 802.1x never sets the def_wep_key_idx so each set_key()
5793 * call changes default tx key.
5795 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5796 * after first set_key().
5798 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5799 flags |= WMI_KEY_TX_USAGE;
5802 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5805 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5806 arvif->vdev_id, peer_addr, ret);
5810 /* mac80211 sets static WEP keys as groupwise while firmware requires
5811 * them to be installed twice as both pairwise and groupwise.
5813 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5815 flags2 &= ~WMI_KEY_GROUP;
5816 flags2 |= WMI_KEY_PAIRWISE;
5818 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5821 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5822 arvif->vdev_id, peer_addr, ret);
5823 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5827 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5828 arvif->vdev_id, peer_addr, ret2);
5834 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5836 spin_lock_bh(&ar->data_lock);
5837 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5838 if (peer && cmd == SET_KEY)
5839 peer->keys[key->keyidx] = key;
5840 else if (peer && cmd == DISABLE_KEY)
5841 peer->keys[key->keyidx] = NULL;
5842 else if (peer == NULL)
5843 /* impossible unless FW goes crazy */
5844 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5845 spin_unlock_bh(&ar->data_lock);
5848 mutex_unlock(&ar->conf_mutex);
5852 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5853 struct ieee80211_vif *vif,
5856 struct ath10k *ar = hw->priv;
5857 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5860 mutex_lock(&arvif->ar->conf_mutex);
5862 if (arvif->ar->state != ATH10K_STATE_ON)
5865 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5866 arvif->vdev_id, keyidx);
5868 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5870 arvif->ar->wmi.vdev_param->def_keyid,
5874 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5880 arvif->def_wep_key_idx = keyidx;
5883 mutex_unlock(&arvif->ar->conf_mutex);
5886 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5889 struct ath10k_vif *arvif;
5890 struct ath10k_sta *arsta;
5891 struct ieee80211_sta *sta;
5892 struct cfg80211_chan_def def;
5893 enum ieee80211_band band;
5894 const u8 *ht_mcs_mask;
5895 const u16 *vht_mcs_mask;
5896 u32 changed, bw, nss, smps;
5899 arsta = container_of(wk, struct ath10k_sta, update_wk);
5900 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5901 arvif = arsta->arvif;
5904 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5907 band = def.chan->band;
5908 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5909 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5911 spin_lock_bh(&ar->data_lock);
5913 changed = arsta->changed;
5920 spin_unlock_bh(&ar->data_lock);
5922 mutex_lock(&ar->conf_mutex);
5924 nss = max_t(u32, 1, nss);
5925 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5926 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5928 if (changed & IEEE80211_RC_BW_CHANGED) {
5929 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5932 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5933 WMI_PEER_CHAN_WIDTH, bw);
5935 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5936 sta->addr, bw, err);
5939 if (changed & IEEE80211_RC_NSS_CHANGED) {
5940 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5943 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5946 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5947 sta->addr, nss, err);
5950 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5951 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5954 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5955 WMI_PEER_SMPS_STATE, smps);
5957 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5958 sta->addr, smps, err);
5961 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5962 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5965 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5967 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5971 mutex_unlock(&ar->conf_mutex);
5974 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5975 struct ieee80211_sta *sta)
5977 struct ath10k *ar = arvif->ar;
5979 lockdep_assert_held(&ar->conf_mutex);
5981 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5984 if (ar->num_stations >= ar->max_num_stations)
5992 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5993 struct ieee80211_sta *sta)
5995 struct ath10k *ar = arvif->ar;
5997 lockdep_assert_held(&ar->conf_mutex);
5999 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6005 struct ath10k_mac_tdls_iter_data {
6006 u32 num_tdls_stations;
6007 struct ieee80211_vif *curr_vif;
6010 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
6011 struct ieee80211_sta *sta)
6013 struct ath10k_mac_tdls_iter_data *iter_data = data;
6014 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6015 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
6017 if (sta->tdls && sta_vif == iter_data->curr_vif)
6018 iter_data->num_tdls_stations++;
6021 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
6022 struct ieee80211_vif *vif)
6024 struct ath10k_mac_tdls_iter_data data = {};
6026 data.curr_vif = vif;
6028 ieee80211_iterate_stations_atomic(hw,
6029 ath10k_mac_tdls_vif_stations_count_iter,
6031 return data.num_tdls_stations;
6034 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
6035 struct ieee80211_vif *vif)
6037 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6038 int *num_tdls_vifs = data;
6040 if (vif->type != NL80211_IFTYPE_STATION)
6043 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
6047 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
6049 int num_tdls_vifs = 0;
6051 ieee80211_iterate_active_interfaces_atomic(hw,
6052 IEEE80211_IFACE_ITER_NORMAL,
6053 ath10k_mac_tdls_vifs_count_iter,
6055 return num_tdls_vifs;
6058 static int ath10k_sta_state(struct ieee80211_hw *hw,
6059 struct ieee80211_vif *vif,
6060 struct ieee80211_sta *sta,
6061 enum ieee80211_sta_state old_state,
6062 enum ieee80211_sta_state new_state)
6064 struct ath10k *ar = hw->priv;
6065 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6066 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6067 struct ath10k_peer *peer;
6071 if (old_state == IEEE80211_STA_NOTEXIST &&
6072 new_state == IEEE80211_STA_NONE) {
6073 memset(arsta, 0, sizeof(*arsta));
6074 arsta->arvif = arvif;
6075 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6077 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6078 ath10k_mac_txq_init(sta->txq[i]);
6081 /* cancel must be done outside the mutex to avoid deadlock */
6082 if ((old_state == IEEE80211_STA_NONE &&
6083 new_state == IEEE80211_STA_NOTEXIST))
6084 cancel_work_sync(&arsta->update_wk);
6086 if (vif->type == NL80211_IFTYPE_STATION && new_state > ar->sta_state)
6087 ar->sta_state = new_state;
6089 mutex_lock(&ar->conf_mutex);
6091 if (old_state == IEEE80211_STA_NOTEXIST &&
6092 new_state == IEEE80211_STA_NONE) {
6094 * New station addition.
6096 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6097 u32 num_tdls_stations;
6100 ath10k_dbg(ar, ATH10K_DBG_MAC,
6101 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6102 arvif->vdev_id, sta->addr,
6103 ar->num_stations + 1, ar->max_num_stations,
6104 ar->num_peers + 1, ar->max_num_peers);
6106 ret = ath10k_mac_inc_num_stations(arvif, sta);
6108 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6109 ar->max_num_stations);
6114 peer_type = WMI_PEER_TYPE_TDLS;
6116 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6117 sta->addr, peer_type);
6119 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6120 sta->addr, arvif->vdev_id, ret);
6121 ath10k_mac_dec_num_stations(arvif, sta);
6125 spin_lock_bh(&ar->data_lock);
6127 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6129 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6130 vif->addr, arvif->vdev_id);
6131 spin_unlock_bh(&ar->data_lock);
6132 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6133 ath10k_mac_dec_num_stations(arvif, sta);
6138 arsta->peer_id = find_first_bit(peer->peer_ids,
6139 ATH10K_MAX_NUM_PEER_IDS);
6141 spin_unlock_bh(&ar->data_lock);
6146 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6147 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6149 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
6150 num_tdls_stations == 0) {
6151 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6152 arvif->vdev_id, ar->max_num_tdls_vdevs);
6153 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6154 ath10k_mac_dec_num_stations(arvif, sta);
6159 if (num_tdls_stations == 0) {
6160 /* This is the first tdls peer in current vif */
6161 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
6163 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6166 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6167 arvif->vdev_id, ret);
6168 ath10k_peer_delete(ar, arvif->vdev_id,
6170 ath10k_mac_dec_num_stations(arvif, sta);
6175 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6176 WMI_TDLS_PEER_STATE_PEERING);
6179 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6180 sta->addr, arvif->vdev_id, ret);
6181 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6182 ath10k_mac_dec_num_stations(arvif, sta);
6184 if (num_tdls_stations != 0)
6186 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6189 } else if ((old_state == IEEE80211_STA_NONE &&
6190 new_state == IEEE80211_STA_NOTEXIST)) {
6192 * Existing station deletion.
6194 ath10k_dbg(ar, ATH10K_DBG_MAC,
6195 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6196 arvif->vdev_id, sta->addr, sta);
6199 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6201 WMI_TDLS_PEER_STATE_TEARDOWN);
6203 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6205 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6208 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6210 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6211 sta->addr, arvif->vdev_id, ret);
6213 ath10k_mac_dec_num_stations(arvif, sta);
6215 spin_lock_bh(&ar->data_lock);
6216 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6217 peer = ar->peer_map[i];
6221 if (peer->sta == sta) {
6222 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6223 sta->addr, peer, i, arvif->vdev_id);
6226 /* Clean up the peer object as well since we
6227 * must have failed to do this above.
6229 list_del(&peer->list);
6230 ar->peer_map[i] = NULL;
6235 spin_unlock_bh(&ar->data_lock);
6237 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6238 ath10k_mac_txq_unref(ar, sta->txq[i]);
6243 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6246 /* This was the last tdls peer in current vif */
6247 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6250 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6251 arvif->vdev_id, ret);
6253 } else if (old_state == IEEE80211_STA_AUTH &&
6254 new_state == IEEE80211_STA_ASSOC &&
6255 (vif->type == NL80211_IFTYPE_AP ||
6256 vif->type == NL80211_IFTYPE_MESH_POINT ||
6257 vif->type == NL80211_IFTYPE_ADHOC)) {
6261 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6264 ret = ath10k_station_assoc(ar, vif, sta, false);
6266 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6267 sta->addr, arvif->vdev_id, ret);
6268 } else if (old_state == IEEE80211_STA_ASSOC &&
6269 new_state == IEEE80211_STA_AUTHORIZED &&
6272 * Tdls station authorized.
6274 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6277 ret = ath10k_station_assoc(ar, vif, sta, false);
6279 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6280 sta->addr, arvif->vdev_id, ret);
6284 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6285 WMI_TDLS_PEER_STATE_CONNECTED);
6287 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6288 sta->addr, arvif->vdev_id, ret);
6289 } else if (old_state == IEEE80211_STA_ASSOC &&
6290 new_state == IEEE80211_STA_AUTH &&
6291 (vif->type == NL80211_IFTYPE_AP ||
6292 vif->type == NL80211_IFTYPE_MESH_POINT ||
6293 vif->type == NL80211_IFTYPE_ADHOC)) {
6297 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6300 ret = ath10k_station_disassoc(ar, vif, sta);
6302 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6303 sta->addr, arvif->vdev_id, ret);
6306 mutex_unlock(&ar->conf_mutex);
6310 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6311 u16 ac, bool enable)
6313 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6314 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6315 u32 prio = 0, acc = 0;
6319 lockdep_assert_held(&ar->conf_mutex);
6321 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6325 case IEEE80211_AC_VO:
6326 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6327 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6331 case IEEE80211_AC_VI:
6332 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6333 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6337 case IEEE80211_AC_BE:
6338 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6339 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6343 case IEEE80211_AC_BK:
6344 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6345 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6352 arvif->u.sta.uapsd |= value;
6354 arvif->u.sta.uapsd &= ~value;
6356 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6357 WMI_STA_PS_PARAM_UAPSD,
6358 arvif->u.sta.uapsd);
6360 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6364 if (arvif->u.sta.uapsd)
6365 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6367 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6369 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6370 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6373 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6375 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6377 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6378 arvif->vdev_id, ret);
6382 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6384 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6385 arvif->vdev_id, ret);
6389 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6390 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6391 /* Only userspace can make an educated decision when to send
6392 * trigger frame. The following effectively disables u-UAPSD
6393 * autotrigger in firmware (which is enabled by default
6394 * provided the autotrigger service is available).
6398 arg.user_priority = prio;
6399 arg.service_interval = 0;
6400 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6401 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6403 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6404 arvif->bssid, &arg, 1);
6406 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6416 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6417 struct ieee80211_vif *vif, u16 ac,
6418 const struct ieee80211_tx_queue_params *params)
6420 struct ath10k *ar = hw->priv;
6421 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6422 struct wmi_wmm_params_arg *p = NULL;
6425 mutex_lock(&ar->conf_mutex);
6428 case IEEE80211_AC_VO:
6429 p = &arvif->wmm_params.ac_vo;
6431 case IEEE80211_AC_VI:
6432 p = &arvif->wmm_params.ac_vi;
6434 case IEEE80211_AC_BE:
6435 p = &arvif->wmm_params.ac_be;
6437 case IEEE80211_AC_BK:
6438 p = &arvif->wmm_params.ac_bk;
6447 p->cwmin = params->cw_min;
6448 p->cwmax = params->cw_max;
6449 p->aifs = params->aifs;
6452 * The channel time duration programmed in the HW is in absolute
6453 * microseconds, while mac80211 gives the txop in units of
6456 p->txop = params->txop * 32;
6458 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6459 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6460 &arvif->wmm_params);
6462 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6463 arvif->vdev_id, ret);
6467 /* This won't work well with multi-interface cases but it's
6468 * better than nothing.
6470 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6472 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6477 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6479 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6482 mutex_unlock(&ar->conf_mutex);
6486 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6488 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6489 struct ieee80211_vif *vif,
6490 struct ieee80211_channel *chan,
6492 enum ieee80211_roc_type type)
6494 struct ath10k *ar = hw->priv;
6495 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6496 struct wmi_start_scan_arg arg;
6500 mutex_lock(&ar->conf_mutex);
6502 spin_lock_bh(&ar->data_lock);
6503 switch (ar->scan.state) {
6504 case ATH10K_SCAN_IDLE:
6505 reinit_completion(&ar->scan.started);
6506 reinit_completion(&ar->scan.completed);
6507 reinit_completion(&ar->scan.on_channel);
6508 ar->scan.state = ATH10K_SCAN_STARTING;
6509 ar->scan.is_roc = true;
6510 ar->scan.vdev_id = arvif->vdev_id;
6511 ar->scan.roc_freq = chan->center_freq;
6512 ar->scan.roc_notify = true;
6515 case ATH10K_SCAN_STARTING:
6516 case ATH10K_SCAN_RUNNING:
6517 case ATH10K_SCAN_ABORTING:
6521 spin_unlock_bh(&ar->data_lock);
6526 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6528 memset(&arg, 0, sizeof(arg));
6529 ath10k_wmi_start_scan_init(ar, &arg);
6530 arg.vdev_id = arvif->vdev_id;
6531 arg.scan_id = ATH10K_SCAN_ID;
6533 arg.channels[0] = chan->center_freq;
6534 arg.dwell_time_active = scan_time_msec;
6535 arg.dwell_time_passive = scan_time_msec;
6536 arg.max_scan_time = scan_time_msec;
6537 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6538 if (QCA_REV_WCN3990(ar)) {
6539 arg.scan_ctrl_flags &= ~(WMI_SCAN_FILTER_PROBE_REQ |
6540 WMI_SCAN_CHAN_STAT_EVENT |
6541 WMI_SCAN_ADD_BCAST_PROBE_REQ);
6543 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 */
6651 mutex_lock(&ar->conf_mutex);
6653 if (ar->state == ATH10K_STATE_WEDGED)
6656 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6659 spin_lock_bh(&ar->htt.tx_lock);
6660 empty = (ar->htt.num_pending_tx == 0);
6661 spin_unlock_bh(&ar->htt.tx_lock);
6663 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6664 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6668 }), ATH10K_FLUSH_TIMEOUT_HZ);
6670 if (time_left == 0 || skip)
6671 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6672 skip, ar->state, time_left);
6675 mutex_unlock(&ar->conf_mutex);
6678 /* TODO: Implement this function properly
6679 * For now it is needed to reply to Probe Requests in IBSS mode.
6680 * Propably we need this information from FW.
6682 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6687 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6688 enum ieee80211_reconfig_type reconfig_type)
6690 struct ath10k *ar = hw->priv;
6692 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6695 mutex_lock(&ar->conf_mutex);
6697 /* If device failed to restart it will be in a different state, e.g.
6698 * ATH10K_STATE_WEDGED */
6699 if (ar->state == ATH10K_STATE_RESTARTED) {
6700 ath10k_info(ar, "device successfully recovered\n");
6701 ar->state = ATH10K_STATE_ON;
6702 ieee80211_wake_queues(ar->hw);
6705 mutex_unlock(&ar->conf_mutex);
6709 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6710 struct ieee80211_channel *channel)
6713 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6715 lockdep_assert_held(&ar->conf_mutex);
6717 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6718 (ar->rx_channel != channel))
6721 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6722 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6726 reinit_completion(&ar->bss_survey_done);
6728 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6730 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6734 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6736 ath10k_warn(ar, "bss channel survey timed out\n");
6741 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6742 struct survey_info *survey)
6744 struct ath10k *ar = hw->priv;
6745 struct ieee80211_supported_band *sband;
6746 struct survey_info *ar_survey = &ar->survey[idx];
6749 mutex_lock(&ar->conf_mutex);
6751 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
6752 if (sband && idx >= sband->n_channels) {
6753 idx -= sband->n_channels;
6758 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
6760 if (!sband || idx >= sband->n_channels) {
6765 if (!QCA_REV_WCN3990(ar))
6766 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6768 spin_lock_bh(&ar->data_lock);
6769 memcpy(survey, ar_survey, sizeof(*survey));
6770 spin_unlock_bh(&ar->data_lock);
6772 survey->channel = &sband->channels[idx];
6774 if (ar->rx_channel == survey->channel)
6775 survey->filled |= SURVEY_INFO_IN_USE;
6778 mutex_unlock(&ar->conf_mutex);
6783 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6784 enum ieee80211_band band,
6785 const struct cfg80211_bitrate_mask *mask)
6790 num_rates += hweight32(mask->control[band].legacy);
6792 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6793 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6795 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6796 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6798 return num_rates == 1;
6802 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6803 enum ieee80211_band band,
6804 const struct cfg80211_bitrate_mask *mask,
6807 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6808 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6810 u8 vht_nss_mask = 0;
6813 if (mask->control[band].legacy)
6816 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6817 if (mask->control[band].ht_mcs[i] == 0)
6819 else if (mask->control[band].ht_mcs[i] ==
6820 sband->ht_cap.mcs.rx_mask[i])
6821 ht_nss_mask |= BIT(i);
6826 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6827 if (mask->control[band].vht_mcs[i] == 0)
6829 else if (mask->control[band].vht_mcs[i] ==
6830 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6831 vht_nss_mask |= BIT(i);
6836 if (ht_nss_mask != vht_nss_mask)
6839 if (ht_nss_mask == 0)
6842 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6845 *nss = fls(ht_nss_mask);
6851 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6852 enum ieee80211_band band,
6853 const struct cfg80211_bitrate_mask *mask,
6856 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6863 if (hweight32(mask->control[band].legacy) == 1) {
6864 rate_idx = ffs(mask->control[band].legacy) - 1;
6866 hw_rate = sband->bitrates[rate_idx].hw_value;
6867 bitrate = sband->bitrates[rate_idx].bitrate;
6869 if (ath10k_mac_bitrate_is_cck(bitrate))
6870 preamble = WMI_RATE_PREAMBLE_CCK;
6872 preamble = WMI_RATE_PREAMBLE_OFDM;
6875 *rate = preamble << 6 |
6882 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6883 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6885 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6887 (ffs(mask->control[band].ht_mcs[i]) - 1);
6893 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6894 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6896 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6898 (ffs(mask->control[band].vht_mcs[i]) - 1);
6907 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6908 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6910 struct ath10k *ar = arvif->ar;
6914 lockdep_assert_held(&ar->conf_mutex);
6916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6917 arvif->vdev_id, rate, nss, sgi);
6919 vdev_param = ar->wmi.vdev_param->fixed_rate;
6920 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6922 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6927 vdev_param = ar->wmi.vdev_param->nss;
6928 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6930 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6934 vdev_param = ar->wmi.vdev_param->sgi;
6935 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6937 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6941 vdev_param = ar->wmi.vdev_param->ldpc;
6942 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6944 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6952 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6953 enum ieee80211_band band,
6954 const struct cfg80211_bitrate_mask *mask)
6959 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6960 * to express all VHT MCS rate masks. Effectively only the following
6961 * ranges can be used: none, 0-7, 0-8 and 0-9.
6963 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6964 vht_mcs = mask->control[band].vht_mcs[i];
6973 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6981 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6982 struct ieee80211_sta *sta)
6984 struct ath10k_vif *arvif = data;
6985 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6986 struct ath10k *ar = arvif->ar;
6988 if (arsta->arvif != arvif)
6991 spin_lock_bh(&ar->data_lock);
6992 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6993 spin_unlock_bh(&ar->data_lock);
6995 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6998 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6999 struct ieee80211_vif *vif,
7000 const struct cfg80211_bitrate_mask *mask)
7002 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7003 struct cfg80211_chan_def def;
7004 struct ath10k *ar = arvif->ar;
7005 enum ieee80211_band band;
7006 const u8 *ht_mcs_mask;
7007 const u16 *vht_mcs_mask;
7015 if (ath10k_mac_vif_chan(vif, &def))
7018 band = def.chan->band;
7019 ht_mcs_mask = mask->control[band].ht_mcs;
7020 vht_mcs_mask = mask->control[band].vht_mcs;
7021 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7023 sgi = mask->control[band].gi;
7024 if (sgi == NL80211_TXRATE_FORCE_LGI)
7027 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7028 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7031 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7032 arvif->vdev_id, ret);
7035 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7037 rate = WMI_FIXED_RATE_NONE;
7040 rate = WMI_FIXED_RATE_NONE;
7041 nss = min(ar->num_rf_chains,
7042 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7043 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7045 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7048 mutex_lock(&ar->conf_mutex);
7050 arvif->bitrate_mask = *mask;
7051 ieee80211_iterate_stations_atomic(ar->hw,
7052 ath10k_mac_set_bitrate_mask_iter,
7055 mutex_unlock(&ar->conf_mutex);
7058 mutex_lock(&ar->conf_mutex);
7060 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7062 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7063 arvif->vdev_id, ret);
7068 mutex_unlock(&ar->conf_mutex);
7073 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7074 struct ieee80211_vif *vif,
7075 struct ieee80211_sta *sta,
7078 struct ath10k *ar = hw->priv;
7079 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7080 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7081 struct ath10k_peer *peer;
7084 spin_lock_bh(&ar->data_lock);
7086 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7088 spin_unlock_bh(&ar->data_lock);
7089 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7090 sta->addr, arvif->vdev_id);
7094 ath10k_dbg(ar, ATH10K_DBG_MAC,
7095 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7096 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7099 if (changed & IEEE80211_RC_BW_CHANGED) {
7100 bw = WMI_PEER_CHWIDTH_20MHZ;
7102 switch (sta->bandwidth) {
7103 case IEEE80211_STA_RX_BW_20:
7104 bw = WMI_PEER_CHWIDTH_20MHZ;
7106 case IEEE80211_STA_RX_BW_40:
7107 bw = WMI_PEER_CHWIDTH_40MHZ;
7109 case IEEE80211_STA_RX_BW_80:
7110 bw = WMI_PEER_CHWIDTH_80MHZ;
7112 case IEEE80211_STA_RX_BW_160:
7113 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7114 sta->bandwidth, sta->addr);
7115 bw = WMI_PEER_CHWIDTH_20MHZ;
7122 if (changed & IEEE80211_RC_NSS_CHANGED)
7123 arsta->nss = sta->rx_nss;
7125 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7126 smps = WMI_PEER_SMPS_PS_NONE;
7128 switch (sta->smps_mode) {
7129 case IEEE80211_SMPS_AUTOMATIC:
7130 case IEEE80211_SMPS_OFF:
7131 smps = WMI_PEER_SMPS_PS_NONE;
7133 case IEEE80211_SMPS_STATIC:
7134 smps = WMI_PEER_SMPS_STATIC;
7136 case IEEE80211_SMPS_DYNAMIC:
7137 smps = WMI_PEER_SMPS_DYNAMIC;
7139 case IEEE80211_SMPS_NUM_MODES:
7140 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7141 sta->smps_mode, sta->addr);
7142 smps = WMI_PEER_SMPS_PS_NONE;
7149 arsta->changed |= changed;
7151 spin_unlock_bh(&ar->data_lock);
7153 ieee80211_queue_work(hw, &arsta->update_wk);
7156 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7159 * FIXME: Return 0 for time being. Need to figure out whether FW
7160 * has the API to fetch 64-bit local TSF
7166 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7169 struct ath10k *ar = hw->priv;
7170 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7171 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
7176 * Given tsf argument is entire TSF value, but firmware accepts
7177 * only TSF offset to current TSF.
7179 * get_tsf function is used to get offset value, however since
7180 * ath10k_get_tsf is not implemented properly, it will return 0 always.
7181 * Luckily all the caller functions to set_tsf, as of now, also rely on
7182 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
7183 * final tsf offset value to firmware will be arithmetically correct.
7185 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
7186 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7187 vdev_param, tsf_offset);
7188 if (ret && ret != -EOPNOTSUPP)
7189 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
7192 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7193 struct ieee80211_vif *vif,
7194 struct ieee80211_ampdu_params *params)
7196 struct ath10k *ar = hw->priv;
7197 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7198 struct ieee80211_sta *sta = params->sta;
7199 enum ieee80211_ampdu_mlme_action action = params->action;
7200 u16 tid = params->tid;
7202 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7203 arvif->vdev_id, sta->addr, tid, action);
7206 case IEEE80211_AMPDU_RX_START:
7207 case IEEE80211_AMPDU_RX_STOP:
7208 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7209 * creation/removal. Do we need to verify this?
7212 case IEEE80211_AMPDU_TX_START:
7213 case IEEE80211_AMPDU_TX_STOP_CONT:
7214 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7215 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7216 case IEEE80211_AMPDU_TX_OPERATIONAL:
7217 /* Firmware offloads Tx aggregation entirely so deny mac80211
7218 * Tx aggregation requests.
7227 ath10k_mac_update_rx_channel(struct ath10k *ar,
7228 struct ieee80211_chanctx_conf *ctx,
7229 struct ieee80211_vif_chanctx_switch *vifs,
7232 struct cfg80211_chan_def *def = NULL;
7234 /* Both locks are required because ar->rx_channel is modified. This
7235 * allows readers to hold either lock.
7237 lockdep_assert_held(&ar->conf_mutex);
7238 lockdep_assert_held(&ar->data_lock);
7240 WARN_ON(ctx && vifs);
7241 WARN_ON(vifs && !n_vifs);
7243 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7244 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7245 * ppdu on Rx may reduce performance on low-end systems. It should be
7246 * possible to make tables/hashmaps to speed the lookup up (be vary of
7247 * cpu data cache lines though regarding sizes) but to keep the initial
7248 * implementation simple and less intrusive fallback to the slow lookup
7249 * only for multi-channel cases. Single-channel cases will remain to
7250 * use the old channel derival and thus performance should not be
7254 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7255 ieee80211_iter_chan_contexts_atomic(ar->hw,
7256 ath10k_mac_get_any_chandef_iter,
7260 def = &vifs[0].new_ctx->def;
7262 ar->rx_channel = def->chan;
7263 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7264 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7265 /* During driver restart due to firmware assert, since mac80211
7266 * already has valid channel context for given radio, channel
7267 * context iteration return num_chanctx > 0. So fix rx_channel
7268 * when restart is in progress.
7270 ar->rx_channel = ctx->def.chan;
7272 ar->rx_channel = NULL;
7278 ath10k_mac_update_vif_chan(struct ath10k *ar,
7279 struct ieee80211_vif_chanctx_switch *vifs,
7282 struct ath10k_vif *arvif;
7286 lockdep_assert_held(&ar->conf_mutex);
7288 /* First stop monitor interface. Some FW versions crash if there's a
7289 * lone monitor interface.
7291 if (ar->monitor_started)
7292 ath10k_monitor_stop(ar);
7294 for (i = 0; i < n_vifs; i++) {
7295 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7297 ath10k_dbg(ar, ATH10K_DBG_MAC,
7298 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7300 vifs[i].old_ctx->def.chan->center_freq,
7301 vifs[i].new_ctx->def.chan->center_freq,
7302 vifs[i].old_ctx->def.width,
7303 vifs[i].new_ctx->def.width);
7305 if (WARN_ON(!arvif->is_started))
7308 if (WARN_ON(!arvif->is_up))
7310 if (QCA_REV_WCN3990(ar)) {
7311 /* In the case of wcn3990 WLAN module we send
7312 * vdev restart only, no need to send vdev down.
7315 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7318 "failed to restart vdev %d: %d\n",
7319 arvif->vdev_id, ret);
7323 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7325 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7326 arvif->vdev_id, ret);
7332 /* All relevant vdevs are downed and associated channel resources
7333 * should be available for the channel switch now.
7336 spin_lock_bh(&ar->data_lock);
7337 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7338 spin_unlock_bh(&ar->data_lock);
7340 for (i = 0; i < n_vifs; i++) {
7341 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7343 if (WARN_ON(!arvif->is_started))
7346 if (WARN_ON(!arvif->is_up))
7349 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7351 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7354 ret = ath10k_mac_setup_prb_tmpl(arvif);
7356 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7359 if (!QCA_REV_WCN3990(ar)) {
7360 /* In case of other than wcn3990 WLAN module we
7361 * send vdev down and vdev restart to the firmware.
7364 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7366 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7367 arvif->vdev_id, ret);
7372 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7375 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7376 arvif->vdev_id, ret);
7381 ath10k_monitor_recalc(ar);
7385 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7386 struct ieee80211_chanctx_conf *ctx)
7388 struct ath10k *ar = hw->priv;
7390 ath10k_dbg(ar, ATH10K_DBG_MAC,
7391 "mac chanctx add freq %hu width %d ptr %pK\n",
7392 ctx->def.chan->center_freq, ctx->def.width, ctx);
7394 mutex_lock(&ar->conf_mutex);
7396 spin_lock_bh(&ar->data_lock);
7397 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7398 spin_unlock_bh(&ar->data_lock);
7400 ath10k_recalc_radar_detection(ar);
7401 ath10k_monitor_recalc(ar);
7403 mutex_unlock(&ar->conf_mutex);
7409 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7410 struct ieee80211_chanctx_conf *ctx)
7412 struct ath10k *ar = hw->priv;
7414 ath10k_dbg(ar, ATH10K_DBG_MAC,
7415 "mac chanctx remove freq %hu width %d ptr %pK\n",
7416 ctx->def.chan->center_freq, ctx->def.width, ctx);
7418 mutex_lock(&ar->conf_mutex);
7420 spin_lock_bh(&ar->data_lock);
7421 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7422 spin_unlock_bh(&ar->data_lock);
7424 ath10k_recalc_radar_detection(ar);
7425 ath10k_monitor_recalc(ar);
7427 mutex_unlock(&ar->conf_mutex);
7430 struct ath10k_mac_change_chanctx_arg {
7431 struct ieee80211_chanctx_conf *ctx;
7432 struct ieee80211_vif_chanctx_switch *vifs;
7438 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7439 struct ieee80211_vif *vif)
7441 struct ath10k_mac_change_chanctx_arg *arg = data;
7443 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7450 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7451 struct ieee80211_vif *vif)
7453 struct ath10k_mac_change_chanctx_arg *arg = data;
7454 struct ieee80211_chanctx_conf *ctx;
7456 ctx = rcu_access_pointer(vif->chanctx_conf);
7457 if (ctx != arg->ctx)
7460 if (WARN_ON(arg->next_vif == arg->n_vifs))
7463 arg->vifs[arg->next_vif].vif = vif;
7464 arg->vifs[arg->next_vif].old_ctx = ctx;
7465 arg->vifs[arg->next_vif].new_ctx = ctx;
7470 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7471 struct ieee80211_chanctx_conf *ctx,
7474 struct ath10k *ar = hw->priv;
7475 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7477 mutex_lock(&ar->conf_mutex);
7479 ath10k_dbg(ar, ATH10K_DBG_MAC,
7480 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7481 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7483 /* This shouldn't really happen because channel switching should use
7484 * switch_vif_chanctx().
7486 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7489 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7490 ieee80211_iterate_active_interfaces_atomic(
7492 IEEE80211_IFACE_ITER_NORMAL,
7493 ath10k_mac_change_chanctx_cnt_iter,
7495 if (arg.n_vifs == 0)
7498 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7503 ieee80211_iterate_active_interfaces_atomic(
7505 IEEE80211_IFACE_ITER_NORMAL,
7506 ath10k_mac_change_chanctx_fill_iter,
7508 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7513 ath10k_recalc_radar_detection(ar);
7515 /* FIXME: How to configure Rx chains properly? */
7517 /* No other actions are actually necessary. Firmware maintains channel
7518 * definitions per vdev internally and there's no host-side channel
7519 * context abstraction to configure, e.g. channel width.
7523 mutex_unlock(&ar->conf_mutex);
7527 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7528 struct ieee80211_vif *vif,
7529 struct ieee80211_chanctx_conf *ctx)
7531 struct ath10k *ar = hw->priv;
7532 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7535 mutex_lock(&ar->conf_mutex);
7537 ath10k_dbg(ar, ATH10K_DBG_MAC,
7538 "mac chanctx assign ptr %pK vdev_id %i\n",
7539 ctx, arvif->vdev_id);
7541 if (WARN_ON(arvif->is_started)) {
7542 mutex_unlock(&ar->conf_mutex);
7546 ret = ath10k_vdev_start(arvif, &ctx->def);
7548 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7549 arvif->vdev_id, vif->addr,
7550 ctx->def.chan->center_freq, ret);
7554 arvif->is_started = true;
7556 ret = ath10k_mac_vif_setup_ps(arvif);
7558 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7559 arvif->vdev_id, ret);
7563 if (vif->type == NL80211_IFTYPE_MONITOR) {
7564 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7566 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7567 arvif->vdev_id, ret);
7571 arvif->is_up = true;
7574 if (ath10k_mac_can_set_cts_prot(arvif)) {
7575 ret = ath10k_mac_set_cts_prot(arvif);
7577 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7578 arvif->vdev_id, ret);
7581 mutex_unlock(&ar->conf_mutex);
7585 ath10k_vdev_stop(arvif);
7586 arvif->is_started = false;
7587 ath10k_mac_vif_setup_ps(arvif);
7590 mutex_unlock(&ar->conf_mutex);
7595 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7596 struct ieee80211_vif *vif,
7597 struct ieee80211_chanctx_conf *ctx)
7599 struct ath10k *ar = hw->priv;
7600 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7603 mutex_lock(&ar->conf_mutex);
7605 ath10k_dbg(ar, ATH10K_DBG_MAC,
7606 "mac chanctx unassign ptr %pK vdev_id %i\n",
7607 ctx, arvif->vdev_id);
7609 WARN_ON(!arvif->is_started);
7610 if (vif->type == NL80211_IFTYPE_MONITOR ||
7611 (vif->type == NL80211_IFTYPE_STATION &&
7612 ar->sta_state < IEEE80211_STA_ASSOC)) {
7613 WARN_ON(!arvif->is_up);
7615 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7617 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7618 arvif->vdev_id, ret);
7620 arvif->is_up = false;
7623 ret = ath10k_vdev_stop(arvif);
7625 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7626 arvif->vdev_id, ret);
7628 ar->sta_state = IEEE80211_STA_NOTEXIST;
7629 arvif->is_started = false;
7631 mutex_unlock(&ar->conf_mutex);
7635 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7636 struct ieee80211_vif_chanctx_switch *vifs,
7638 enum ieee80211_chanctx_switch_mode mode)
7640 struct ath10k *ar = hw->priv;
7642 mutex_lock(&ar->conf_mutex);
7644 ath10k_dbg(ar, ATH10K_DBG_MAC,
7645 "mac chanctx switch n_vifs %d mode %d\n",
7647 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7649 mutex_unlock(&ar->conf_mutex);
7653 static const struct ieee80211_ops ath10k_ops = {
7654 .tx = ath10k_mac_op_tx,
7655 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7656 .start = ath10k_start,
7657 .stop = ath10k_stop,
7658 .config = ath10k_config,
7659 .add_interface = ath10k_add_interface,
7660 .change_interface = ath10k_change_interface,
7661 .remove_interface = ath10k_remove_interface,
7662 .configure_filter = ath10k_configure_filter,
7663 .bss_info_changed = ath10k_bss_info_changed,
7664 .hw_scan = ath10k_hw_scan,
7665 .cancel_hw_scan = ath10k_cancel_hw_scan,
7666 .set_rekey_data = ath10k_set_rekey_data,
7667 .set_key = ath10k_set_key,
7668 .set_default_unicast_key = ath10k_set_default_unicast_key,
7669 .sta_state = ath10k_sta_state,
7670 .conf_tx = ath10k_conf_tx,
7671 .remain_on_channel = ath10k_remain_on_channel,
7672 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7673 .set_rts_threshold = ath10k_set_rts_threshold,
7674 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7675 .flush = ath10k_flush,
7676 .tx_last_beacon = ath10k_tx_last_beacon,
7677 .set_antenna = ath10k_set_antenna,
7678 .get_antenna = ath10k_get_antenna,
7679 .reconfig_complete = ath10k_reconfig_complete,
7680 .get_survey = ath10k_get_survey,
7681 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7682 .sta_rc_update = ath10k_sta_rc_update,
7683 .get_tsf = ath10k_get_tsf,
7684 .set_tsf = ath10k_set_tsf,
7685 .ampdu_action = ath10k_ampdu_action,
7686 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7687 .get_et_stats = ath10k_debug_get_et_stats,
7688 .get_et_strings = ath10k_debug_get_et_strings,
7689 .add_chanctx = ath10k_mac_op_add_chanctx,
7690 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7691 .change_chanctx = ath10k_mac_op_change_chanctx,
7692 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7693 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7694 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7696 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7699 .suspend = ath10k_wow_op_suspend,
7700 .resume = ath10k_wow_op_resume,
7701 .set_wakeup = ath10k_wow_op_set_wakeup,
7703 #ifdef CONFIG_MAC80211_DEBUGFS
7704 .sta_add_debugfs = ath10k_sta_add_debugfs,
7705 .sta_statistics = ath10k_sta_statistics,
7709 #define CHAN2G(_channel, _freq, _flags) { \
7710 .band = IEEE80211_BAND_2GHZ, \
7711 .hw_value = (_channel), \
7712 .center_freq = (_freq), \
7713 .flags = (_flags), \
7714 .max_antenna_gain = 0, \
7718 #define CHAN5G(_channel, _freq, _flags) { \
7719 .band = IEEE80211_BAND_5GHZ, \
7720 .hw_value = (_channel), \
7721 .center_freq = (_freq), \
7722 .flags = (_flags), \
7723 .max_antenna_gain = 0, \
7727 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7737 CHAN2G(10, 2457, 0),
7738 CHAN2G(11, 2462, 0),
7739 CHAN2G(12, 2467, 0),
7740 CHAN2G(13, 2472, 0),
7741 CHAN2G(14, 2484, 0),
7744 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7745 CHAN5G(36, 5180, 0),
7746 CHAN5G(40, 5200, 0),
7747 CHAN5G(44, 5220, 0),
7748 CHAN5G(48, 5240, 0),
7749 CHAN5G(52, 5260, 0),
7750 CHAN5G(56, 5280, 0),
7751 CHAN5G(60, 5300, 0),
7752 CHAN5G(64, 5320, 0),
7753 CHAN5G(100, 5500, 0),
7754 CHAN5G(104, 5520, 0),
7755 CHAN5G(108, 5540, 0),
7756 CHAN5G(112, 5560, 0),
7757 CHAN5G(116, 5580, 0),
7758 CHAN5G(120, 5600, 0),
7759 CHAN5G(124, 5620, 0),
7760 CHAN5G(128, 5640, 0),
7761 CHAN5G(132, 5660, 0),
7762 CHAN5G(136, 5680, 0),
7763 CHAN5G(140, 5700, 0),
7764 CHAN5G(144, 5720, 0),
7765 CHAN5G(149, 5745, 0),
7766 CHAN5G(153, 5765, 0),
7767 CHAN5G(157, 5785, 0),
7768 CHAN5G(161, 5805, 0),
7769 CHAN5G(165, 5825, 0),
7772 struct ath10k *ath10k_mac_create(size_t priv_size)
7774 struct ieee80211_hw *hw;
7775 struct ieee80211_ops *ops;
7778 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7782 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7795 void ath10k_mac_destroy(struct ath10k *ar)
7797 struct ieee80211_ops *ops = ar->ops;
7799 ieee80211_free_hw(ar->hw);
7803 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7806 .types = BIT(NL80211_IFTYPE_STATION)
7807 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7811 .types = BIT(NL80211_IFTYPE_P2P_GO)
7815 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7819 .types = BIT(NL80211_IFTYPE_AP)
7820 #ifdef CONFIG_MAC80211_MESH
7821 | BIT(NL80211_IFTYPE_MESH_POINT)
7826 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7829 .types = BIT(NL80211_IFTYPE_AP)
7830 #ifdef CONFIG_MAC80211_MESH
7831 | BIT(NL80211_IFTYPE_MESH_POINT)
7836 .types = BIT(NL80211_IFTYPE_STATION)
7840 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7842 .limits = ath10k_if_limits,
7843 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7844 .max_interfaces = 8,
7845 .num_different_channels = 1,
7846 .beacon_int_infra_match = true,
7850 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7852 .limits = ath10k_10x_if_limits,
7853 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7854 .max_interfaces = 8,
7855 .num_different_channels = 1,
7856 .beacon_int_infra_match = true,
7857 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7858 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7859 BIT(NL80211_CHAN_WIDTH_20) |
7860 BIT(NL80211_CHAN_WIDTH_40) |
7861 BIT(NL80211_CHAN_WIDTH_80),
7866 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7869 .types = BIT(NL80211_IFTYPE_STATION),
7873 .types = BIT(NL80211_IFTYPE_AP) |
7874 #ifdef CONFIG_MAC80211_MESH
7875 BIT(NL80211_IFTYPE_MESH_POINT) |
7877 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7878 BIT(NL80211_IFTYPE_P2P_GO),
7882 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7886 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7889 .types = BIT(NL80211_IFTYPE_STATION),
7893 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7897 .types = BIT(NL80211_IFTYPE_AP) |
7898 #ifdef CONFIG_MAC80211_MESH
7899 BIT(NL80211_IFTYPE_MESH_POINT) |
7901 BIT(NL80211_IFTYPE_P2P_GO),
7905 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7909 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7912 .types = BIT(NL80211_IFTYPE_STATION),
7916 .types = BIT(NL80211_IFTYPE_ADHOC),
7920 /* FIXME: This is not thouroughly tested. These combinations may over- or
7921 * underestimate hw/fw capabilities.
7923 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7925 .limits = ath10k_tlv_if_limit,
7926 .num_different_channels = 1,
7927 .max_interfaces = 4,
7928 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7931 .limits = ath10k_tlv_if_limit_ibss,
7932 .num_different_channels = 1,
7933 .max_interfaces = 2,
7934 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7938 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7940 .limits = ath10k_tlv_if_limit,
7941 .num_different_channels = 1,
7942 .max_interfaces = 4,
7943 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7946 .limits = ath10k_tlv_qcs_if_limit,
7947 .num_different_channels = 2,
7948 .max_interfaces = 4,
7949 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7952 .limits = ath10k_tlv_if_limit_ibss,
7953 .num_different_channels = 1,
7954 .max_interfaces = 2,
7955 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7959 static const struct ieee80211_iface_limit ath10k_wcn3990_if_limit[] = {
7962 .types = BIT(NL80211_IFTYPE_STATION),
7966 .types = BIT(NL80211_IFTYPE_AP) |
7967 #ifdef CONFIG_MAC80211_MESH
7968 BIT(NL80211_IFTYPE_MESH_POINT) |
7970 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7971 BIT(NL80211_IFTYPE_P2P_GO),
7975 static const struct ieee80211_iface_limit ath10k_wcn3990_qcs_if_limit[] = {
7978 .types = BIT(NL80211_IFTYPE_STATION),
7982 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7986 .types = BIT(NL80211_IFTYPE_AP) |
7987 #ifdef CONFIG_MAC80211_MESH
7988 BIT(NL80211_IFTYPE_MESH_POINT) |
7990 BIT(NL80211_IFTYPE_P2P_GO),
7994 static const struct ieee80211_iface_limit ath10k_wcn3990_if_limit_ibss[] = {
7997 .types = BIT(NL80211_IFTYPE_STATION),
8001 .types = BIT(NL80211_IFTYPE_ADHOC),
8005 static struct ieee80211_iface_combination ath10k_wcn3990_qcs_if_comb[] = {
8007 .limits = ath10k_wcn3990_if_limit,
8008 .num_different_channels = 1,
8009 .max_interfaces = 4,
8010 .n_limits = ARRAY_SIZE(ath10k_wcn3990_if_limit),
8011 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8012 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8013 BIT(NL80211_CHAN_WIDTH_20) |
8014 BIT(NL80211_CHAN_WIDTH_40) |
8015 BIT(NL80211_CHAN_WIDTH_80),
8019 .limits = ath10k_wcn3990_qcs_if_limit,
8020 .num_different_channels = 2,
8021 .max_interfaces = 4,
8022 .n_limits = ARRAY_SIZE(ath10k_wcn3990_qcs_if_limit),
8025 .limits = ath10k_wcn3990_if_limit_ibss,
8026 .num_different_channels = 1,
8027 .max_interfaces = 2,
8028 .n_limits = ARRAY_SIZE(ath10k_wcn3990_if_limit_ibss),
8029 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8030 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8031 BIT(NL80211_CHAN_WIDTH_20) |
8032 BIT(NL80211_CHAN_WIDTH_40) |
8033 BIT(NL80211_CHAN_WIDTH_80),
8038 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8041 .types = BIT(NL80211_IFTYPE_STATION),
8045 .types = BIT(NL80211_IFTYPE_AP)
8046 #ifdef CONFIG_MAC80211_MESH
8047 | BIT(NL80211_IFTYPE_MESH_POINT)
8052 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8054 .limits = ath10k_10_4_if_limits,
8055 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8056 .max_interfaces = 16,
8057 .num_different_channels = 1,
8058 .beacon_int_infra_match = true,
8059 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8060 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8061 BIT(NL80211_CHAN_WIDTH_20) |
8062 BIT(NL80211_CHAN_WIDTH_40) |
8063 BIT(NL80211_CHAN_WIDTH_80),
8068 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8069 struct ieee80211_vif *vif)
8071 struct ath10k_vif_iter *arvif_iter = data;
8072 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
8074 if (arvif->vdev_id == arvif_iter->vdev_id)
8075 arvif_iter->arvif = arvif;
8078 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8080 struct ath10k_vif_iter arvif_iter;
8083 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8084 arvif_iter.vdev_id = vdev_id;
8086 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8087 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8089 ath10k_get_arvif_iter,
8091 if (!arvif_iter.arvif) {
8092 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8096 return arvif_iter.arvif;
8099 int ath10k_mac_register(struct ath10k *ar)
8101 static const u32 cipher_suites[] = {
8102 WLAN_CIPHER_SUITE_WEP40,
8103 WLAN_CIPHER_SUITE_WEP104,
8104 WLAN_CIPHER_SUITE_TKIP,
8105 WLAN_CIPHER_SUITE_CCMP,
8106 WLAN_CIPHER_SUITE_AES_CMAC,
8108 struct ieee80211_supported_band *band;
8112 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8114 SET_IEEE80211_DEV(ar->hw, ar->dev);
8116 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8117 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8120 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8121 channels = kmemdup(ath10k_2ghz_channels,
8122 sizeof(ath10k_2ghz_channels),
8129 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
8130 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8131 band->channels = channels;
8133 if (ar->hw_params.cck_rate_map_rev2) {
8134 band->n_bitrates = ath10k_g_rates_rev2_size;
8135 band->bitrates = ath10k_g_rates_rev2;
8137 band->n_bitrates = ath10k_g_rates_size;
8138 band->bitrates = ath10k_g_rates;
8141 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
8144 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8145 channels = kmemdup(ath10k_5ghz_channels,
8146 sizeof(ath10k_5ghz_channels),
8153 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
8154 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8155 band->channels = channels;
8156 band->n_bitrates = ath10k_a_rates_size;
8157 band->bitrates = ath10k_a_rates;
8158 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
8161 ath10k_mac_setup_ht_vht_cap(ar);
8163 ar->hw->wiphy->interface_modes =
8164 BIT(NL80211_IFTYPE_STATION) |
8165 BIT(NL80211_IFTYPE_AP) |
8166 BIT(NL80211_IFTYPE_MESH_POINT);
8168 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8169 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8171 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8172 ar->hw->wiphy->interface_modes |=
8173 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8174 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8175 BIT(NL80211_IFTYPE_P2P_GO);
8177 if (QCA_REV_WCN3990(ar))
8178 ar->hw->wiphy->interface_modes &=
8179 ~BIT(NL80211_IFTYPE_P2P_DEVICE);
8181 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8182 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8183 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8184 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8185 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8186 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8187 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8188 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8189 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8190 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8191 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8192 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8193 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8194 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8196 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8197 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8199 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8200 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8202 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8203 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8205 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8206 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8207 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8210 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8211 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8213 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8214 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8215 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8217 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8219 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8220 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8222 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8223 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8224 * correct Probe Responses. This is more of a hack advert..
8226 ar->hw->wiphy->probe_resp_offload |=
8227 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8228 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8229 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8232 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
8233 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8235 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8236 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8237 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8239 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8240 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8241 NL80211_FEATURE_AP_SCAN;
8243 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8245 ret = ath10k_wow_init(ar);
8247 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8251 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8254 * on LL hardware queues are managed entirely by the FW
8255 * so we only advertise to mac we can do the queues thing
8257 ar->hw->queues = IEEE80211_MAX_QUEUES;
8259 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8260 * something that vdev_ids can't reach so that we don't stop the queue
8263 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8265 switch (ar->running_fw->fw_file.wmi_op_version) {
8266 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8267 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8268 ar->hw->wiphy->n_iface_combinations =
8269 ARRAY_SIZE(ath10k_if_comb);
8270 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8272 case ATH10K_FW_WMI_OP_VERSION_TLV:
8273 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8274 if (QCA_REV_WCN3990(ar)) {
8275 ar->hw->wiphy->iface_combinations =
8276 ath10k_wcn3990_qcs_if_comb;
8277 ar->hw->wiphy->n_iface_combinations =
8278 ARRAY_SIZE(ath10k_wcn3990_qcs_if_comb);
8281 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8282 ar->hw->wiphy->iface_combinations =
8283 ath10k_tlv_qcs_if_comb;
8284 ar->hw->wiphy->n_iface_combinations =
8285 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8287 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8288 ar->hw->wiphy->n_iface_combinations =
8289 ARRAY_SIZE(ath10k_tlv_if_comb);
8292 case ATH10K_FW_WMI_OP_VERSION_10_1:
8293 case ATH10K_FW_WMI_OP_VERSION_10_2:
8294 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8295 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8296 ar->hw->wiphy->n_iface_combinations =
8297 ARRAY_SIZE(ath10k_10x_if_comb);
8299 case ATH10K_FW_WMI_OP_VERSION_10_4:
8300 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8301 ar->hw->wiphy->n_iface_combinations =
8302 ARRAY_SIZE(ath10k_10_4_if_comb);
8304 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8305 case ATH10K_FW_WMI_OP_VERSION_MAX:
8311 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8312 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8314 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8315 /* Init ath dfs pattern detector */
8316 ar->ath_common.debug_mask = ATH_DBG_DFS;
8317 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8320 if (!ar->dfs_detector)
8321 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8324 /* Current wake_tx_queue implementation imposes a significant
8325 * performance penalty in some setups. The tx scheduling code needs
8326 * more work anyway so disable the wake_tx_queue unless firmware
8327 * supports the pull-push mechanism.
8329 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8330 ar->running_fw->fw_file.fw_features))
8331 ar->ops->wake_tx_queue = NULL;
8333 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8334 ath10k_reg_notifier);
8336 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8337 goto err_dfs_detector_exit;
8340 ar->hw->wiphy->cipher_suites = cipher_suites;
8341 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8343 ret = ieee80211_register_hw(ar->hw);
8345 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8346 goto err_dfs_detector_exit;
8349 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8350 ret = regulatory_hint(ar->hw->wiphy,
8351 ar->ath_common.regulatory.alpha2);
8353 goto err_unregister;
8359 ieee80211_unregister_hw(ar->hw);
8361 err_dfs_detector_exit:
8362 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8363 ar->dfs_detector->exit(ar->dfs_detector);
8366 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
8367 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
8369 SET_IEEE80211_DEV(ar->hw, NULL);
8373 void ath10k_mac_unregister(struct ath10k *ar)
8375 ath10k_wow_deinit(ar);
8376 ieee80211_unregister_hw(ar->hw);
8378 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8379 ar->dfs_detector->exit(ar->dfs_detector);
8381 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
8382 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
8384 SET_IEEE80211_DEV(ar->hw, NULL);