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 prb = ieee80211_proberesp_get(hw, vif);
1620 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1624 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1628 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1636 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1638 struct ath10k *ar = arvif->ar;
1639 struct cfg80211_chan_def def;
1642 /* When originally vdev is started during assign_vif_chanctx() some
1643 * information is missing, notably SSID. Firmware revisions with beacon
1644 * offloading require the SSID to be provided during vdev (re)start to
1645 * handle hidden SSID properly.
1647 * Vdev restart must be done after vdev has been both started and
1648 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1649 * deliver vdev restart response event causing timeouts during vdev
1650 * syncing in ath10k.
1652 * Note: The vdev down/up and template reinstallation could be skipped
1653 * since only wmi-tlv firmware are known to have beacon offload and
1654 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1655 * response delivery. It's probably more robust to keep it as is.
1657 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1660 if (WARN_ON(!arvif->is_started))
1663 if (WARN_ON(!arvif->is_up))
1666 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1669 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1671 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1672 arvif->vdev_id, ret);
1676 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1677 * firmware will crash upon vdev up.
1680 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1682 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1686 ret = ath10k_mac_setup_prb_tmpl(arvif);
1688 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1692 ret = ath10k_vdev_restart(arvif, &def);
1694 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1695 arvif->vdev_id, ret);
1699 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1702 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1703 arvif->vdev_id, ret);
1710 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1711 struct ieee80211_bss_conf *info)
1713 struct ath10k *ar = arvif->ar;
1716 lockdep_assert_held(&arvif->ar->conf_mutex);
1718 if (!info->enable_beacon) {
1719 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1721 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1722 arvif->vdev_id, ret);
1724 arvif->is_up = false;
1726 spin_lock_bh(&arvif->ar->data_lock);
1727 ath10k_mac_vif_beacon_free(arvif);
1728 spin_unlock_bh(&arvif->ar->data_lock);
1733 arvif->tx_seq_no = 0x1000;
1736 ether_addr_copy(arvif->bssid, info->bssid);
1738 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1741 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1742 arvif->vdev_id, ret);
1746 arvif->is_up = true;
1748 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1750 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1751 arvif->vdev_id, ret);
1755 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1758 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1759 struct ieee80211_bss_conf *info,
1760 const u8 self_peer[ETH_ALEN])
1762 struct ath10k *ar = arvif->ar;
1766 lockdep_assert_held(&arvif->ar->conf_mutex);
1768 if (!info->ibss_joined) {
1769 if (is_zero_ether_addr(arvif->bssid))
1772 eth_zero_addr(arvif->bssid);
1777 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1778 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1779 ATH10K_DEFAULT_ATIM);
1781 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1782 arvif->vdev_id, ret);
1785 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1787 struct ath10k *ar = arvif->ar;
1792 lockdep_assert_held(&arvif->ar->conf_mutex);
1794 if (arvif->u.sta.uapsd)
1795 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1797 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1799 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1800 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1802 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1803 value, arvif->vdev_id, ret);
1810 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1812 struct ath10k *ar = arvif->ar;
1817 lockdep_assert_held(&arvif->ar->conf_mutex);
1819 if (arvif->u.sta.uapsd)
1820 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1822 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1824 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1825 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1828 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1829 value, arvif->vdev_id, ret);
1836 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1838 struct ath10k_vif *arvif;
1841 lockdep_assert_held(&ar->conf_mutex);
1843 list_for_each_entry(arvif, &ar->arvifs, list)
1844 if (arvif->is_started)
1850 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1852 struct ath10k *ar = arvif->ar;
1853 struct ieee80211_vif *vif = arvif->vif;
1854 struct ieee80211_conf *conf = &ar->hw->conf;
1855 enum wmi_sta_powersave_param param;
1856 enum wmi_sta_ps_mode psmode;
1861 lockdep_assert_held(&arvif->ar->conf_mutex);
1863 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1866 enable_ps = arvif->ps;
1868 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1869 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1870 ar->running_fw->fw_file.fw_features)) {
1871 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1876 if (!arvif->is_started) {
1877 /* mac80211 can update vif powersave state while disconnected.
1878 * Firmware doesn't behave nicely and consumes more power than
1879 * necessary if PS is disabled on a non-started vdev. Hence
1880 * force-enable PS for non-running vdevs.
1882 psmode = WMI_STA_PS_MODE_ENABLED;
1883 } else if (enable_ps) {
1884 psmode = WMI_STA_PS_MODE_ENABLED;
1885 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1887 ps_timeout = conf->dynamic_ps_timeout;
1888 if (ps_timeout == 0) {
1889 /* Firmware doesn't like 0 */
1890 ps_timeout = ieee80211_tu_to_usec(
1891 vif->bss_conf.beacon_int) / 1000;
1894 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1897 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1898 arvif->vdev_id, ret);
1902 psmode = WMI_STA_PS_MODE_DISABLED;
1905 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1906 arvif->vdev_id, psmode ? "enable" : "disable");
1908 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1910 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1911 psmode, arvif->vdev_id, ret);
1918 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1920 struct ath10k *ar = arvif->ar;
1921 struct wmi_sta_keepalive_arg arg = {};
1924 lockdep_assert_held(&arvif->ar->conf_mutex);
1926 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1929 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1932 /* Some firmware revisions have a bug and ignore the `enabled` field.
1933 * Instead use the interval to disable the keepalive.
1935 arg.vdev_id = arvif->vdev_id;
1937 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1938 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1940 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1942 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1943 arvif->vdev_id, ret);
1950 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1952 struct ath10k *ar = arvif->ar;
1953 struct ieee80211_vif *vif = arvif->vif;
1956 lockdep_assert_held(&arvif->ar->conf_mutex);
1958 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1961 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1964 if (!vif->csa_active)
1970 if (!ieee80211_csa_is_complete(vif)) {
1971 ieee80211_csa_update_counter(vif);
1973 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1975 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1978 ret = ath10k_mac_setup_prb_tmpl(arvif);
1980 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1983 ieee80211_csa_finish(vif);
1987 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1989 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1991 struct ath10k *ar = arvif->ar;
1993 mutex_lock(&ar->conf_mutex);
1994 ath10k_mac_vif_ap_csa_count_down(arvif);
1995 mutex_unlock(&ar->conf_mutex);
1998 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1999 struct ieee80211_vif *vif)
2001 struct sk_buff *skb = data;
2002 struct ieee80211_mgmt *mgmt = (void *)skb->data;
2003 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2005 if (vif->type != NL80211_IFTYPE_STATION)
2008 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2011 cancel_delayed_work(&arvif->connection_loss_work);
2014 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2016 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2017 IEEE80211_IFACE_ITER_NORMAL,
2018 ath10k_mac_handle_beacon_iter,
2022 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2023 struct ieee80211_vif *vif)
2025 u32 *vdev_id = data;
2026 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2027 struct ath10k *ar = arvif->ar;
2028 struct ieee80211_hw *hw = ar->hw;
2030 if (arvif->vdev_id != *vdev_id)
2036 ieee80211_beacon_loss(vif);
2038 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2039 * (done by mac80211) succeeds but beacons do not resume then it
2040 * doesn't make sense to continue operation. Queue connection loss work
2041 * which can be cancelled when beacon is received.
2043 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2044 ATH10K_CONNECTION_LOSS_HZ);
2047 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2049 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2050 IEEE80211_IFACE_ITER_NORMAL,
2051 ath10k_mac_handle_beacon_miss_iter,
2055 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2057 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2058 connection_loss_work.work);
2059 struct ieee80211_vif *vif = arvif->vif;
2064 ieee80211_connection_loss(vif);
2067 /**********************/
2068 /* Station management */
2069 /**********************/
2071 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2072 struct ieee80211_vif *vif)
2074 /* Some firmware revisions have unstable STA powersave when listen
2075 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2076 * generate NullFunc frames properly even if buffered frames have been
2077 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2078 * buffered frames. Often pinging the device from AP would simply fail.
2080 * As a workaround set it to 1.
2082 if (vif->type == NL80211_IFTYPE_STATION)
2085 return ar->hw->conf.listen_interval;
2088 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2089 struct ieee80211_vif *vif,
2090 struct ieee80211_sta *sta,
2091 struct wmi_peer_assoc_complete_arg *arg)
2093 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2096 lockdep_assert_held(&ar->conf_mutex);
2098 if (vif->type == NL80211_IFTYPE_STATION)
2099 aid = vif->bss_conf.aid;
2103 ether_addr_copy(arg->addr, sta->addr);
2104 arg->vdev_id = arvif->vdev_id;
2105 arg->peer_aid = aid;
2106 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2107 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2108 arg->peer_num_spatial_streams = 1;
2109 arg->peer_caps = vif->bss_conf.assoc_capability;
2112 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2113 struct ieee80211_vif *vif,
2114 struct ieee80211_sta *sta,
2115 struct wmi_peer_assoc_complete_arg *arg)
2117 struct ieee80211_bss_conf *info = &vif->bss_conf;
2118 struct cfg80211_chan_def def;
2119 struct cfg80211_bss *bss;
2120 const u8 *rsnie = NULL;
2121 const u8 *wpaie = NULL;
2123 lockdep_assert_held(&ar->conf_mutex);
2125 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2128 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2129 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2131 const struct cfg80211_bss_ies *ies;
2134 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2136 ies = rcu_dereference(bss->ies);
2138 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2139 WLAN_OUI_TYPE_MICROSOFT_WPA,
2143 cfg80211_put_bss(ar->hw->wiphy, bss);
2146 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2147 if (rsnie || wpaie) {
2148 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2149 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2153 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2154 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2158 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2159 ar->running_fw->fw_file.fw_features)) {
2160 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2164 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2165 struct ieee80211_vif *vif,
2166 struct ieee80211_sta *sta,
2167 struct wmi_peer_assoc_complete_arg *arg)
2169 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2170 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2171 struct cfg80211_chan_def def;
2172 const struct ieee80211_supported_band *sband;
2173 const struct ieee80211_rate *rates;
2174 enum ieee80211_band band;
2179 lockdep_assert_held(&ar->conf_mutex);
2181 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2184 band = def.chan->band;
2185 sband = ar->hw->wiphy->bands[band];
2186 ratemask = sta->supp_rates[band];
2187 ratemask &= arvif->bitrate_mask.control[band].legacy;
2188 rates = sband->bitrates;
2190 rateset->num_rates = 0;
2192 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2193 if (!(ratemask & 1))
2196 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2197 rateset->rates[rateset->num_rates] = rate;
2198 rateset->num_rates++;
2203 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2207 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2208 if (ht_mcs_mask[nss])
2215 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2219 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2220 if (vht_mcs_mask[nss])
2226 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2227 struct ieee80211_vif *vif,
2228 struct ieee80211_sta *sta,
2229 struct wmi_peer_assoc_complete_arg *arg)
2231 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2232 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2233 struct cfg80211_chan_def def;
2234 enum ieee80211_band band;
2235 const u8 *ht_mcs_mask;
2236 const u16 *vht_mcs_mask;
2241 lockdep_assert_held(&ar->conf_mutex);
2243 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2246 if (!ht_cap->ht_supported)
2249 band = def.chan->band;
2250 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2251 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2253 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2254 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2257 arg->peer_flags |= ar->wmi.peer_flags->ht;
2258 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2259 ht_cap->ampdu_factor)) - 1;
2261 arg->peer_mpdu_density =
2262 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2264 arg->peer_ht_caps = ht_cap->cap;
2265 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2267 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2268 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2270 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2271 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2272 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2275 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2276 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2277 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2279 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2280 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2283 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2284 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2285 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2288 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2289 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2290 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2291 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2292 arg->peer_rate_caps |= stbc;
2293 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2296 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2297 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2298 else if (ht_cap->mcs.rx_mask[1])
2299 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2301 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2302 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2303 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2304 max_nss = (i / 8) + 1;
2305 arg->peer_ht_rates.rates[n++] = i;
2309 * This is a workaround for HT-enabled STAs which break the spec
2310 * and have no HT capabilities RX mask (no HT RX MCS map).
2312 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2313 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2315 * Firmware asserts if such situation occurs.
2318 arg->peer_ht_rates.num_rates = 8;
2319 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2320 arg->peer_ht_rates.rates[i] = i;
2322 arg->peer_ht_rates.num_rates = n;
2323 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2326 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2328 arg->peer_ht_rates.num_rates,
2329 arg->peer_num_spatial_streams);
2332 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2333 struct ath10k_vif *arvif,
2334 struct ieee80211_sta *sta)
2340 lockdep_assert_held(&ar->conf_mutex);
2342 if (sta->wme && sta->uapsd_queues) {
2343 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2344 sta->uapsd_queues, sta->max_sp);
2346 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2347 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2348 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2349 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2350 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2351 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2352 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2353 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2354 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2355 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2356 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2357 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2359 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2360 max_sp = sta->max_sp;
2362 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2364 WMI_AP_PS_PEER_PARAM_UAPSD,
2367 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2368 arvif->vdev_id, ret);
2372 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2374 WMI_AP_PS_PEER_PARAM_MAX_SP,
2377 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2378 arvif->vdev_id, ret);
2382 /* TODO setup this based on STA listen interval and
2383 beacon interval. Currently we don't know
2384 sta->listen_interval - mac80211 patch required.
2385 Currently use 10 seconds */
2386 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2387 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2390 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2391 arvif->vdev_id, ret);
2400 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2401 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2408 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2409 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2413 idx_limit = fls(mcs_map) - 1;
2417 switch (idx_limit) {
2418 case 0: /* fall through */
2419 case 1: /* fall through */
2420 case 2: /* fall through */
2421 case 3: /* fall through */
2422 case 4: /* fall through */
2423 case 5: /* fall through */
2424 case 6: /* fall through */
2426 /* see ath10k_mac_can_set_bitrate_mask() */
2430 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2433 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2436 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2439 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2443 tx_mcs_set &= ~(0x3 << (nss * 2));
2444 tx_mcs_set |= mcs << (nss * 2);
2450 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2451 struct ieee80211_vif *vif,
2452 struct ieee80211_sta *sta,
2453 struct wmi_peer_assoc_complete_arg *arg)
2455 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2456 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2457 struct cfg80211_chan_def def;
2458 enum ieee80211_band band;
2459 const u16 *vht_mcs_mask;
2462 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2465 if (!vht_cap->vht_supported)
2468 band = def.chan->band;
2469 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2471 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2474 arg->peer_flags |= ar->wmi.peer_flags->vht;
2476 if (def.chan->band == IEEE80211_BAND_2GHZ)
2477 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2479 arg->peer_vht_caps = vht_cap->cap;
2481 ampdu_factor = (vht_cap->cap &
2482 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2483 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2485 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2486 * zero in VHT IE. Using it would result in degraded throughput.
2487 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2488 * it if VHT max_mpdu is smaller. */
2489 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2490 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2491 ampdu_factor)) - 1);
2493 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2494 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2496 arg->peer_vht_rates.rx_max_rate =
2497 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2498 arg->peer_vht_rates.rx_mcs_set =
2499 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2500 arg->peer_vht_rates.tx_max_rate =
2501 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2502 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2503 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2505 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2506 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2509 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2510 struct ieee80211_vif *vif,
2511 struct ieee80211_sta *sta,
2512 struct wmi_peer_assoc_complete_arg *arg)
2514 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2516 switch (arvif->vdev_type) {
2517 case WMI_VDEV_TYPE_AP:
2519 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2521 if (sta->wme && sta->uapsd_queues) {
2522 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2523 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2526 case WMI_VDEV_TYPE_STA:
2527 if (vif->bss_conf.qos)
2528 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2530 case WMI_VDEV_TYPE_IBSS:
2532 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2538 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2539 sta->addr, !!(arg->peer_flags &
2540 arvif->ar->wmi.peer_flags->qos));
2543 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2545 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2546 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2549 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2550 struct ieee80211_vif *vif,
2551 struct ieee80211_sta *sta,
2552 struct wmi_peer_assoc_complete_arg *arg)
2554 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2555 struct cfg80211_chan_def def;
2556 enum ieee80211_band band;
2557 const u8 *ht_mcs_mask;
2558 const u16 *vht_mcs_mask;
2559 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2561 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2564 band = def.chan->band;
2565 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2566 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2569 case IEEE80211_BAND_2GHZ:
2570 if (sta->vht_cap.vht_supported &&
2571 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2572 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2573 phymode = MODE_11AC_VHT40;
2575 phymode = MODE_11AC_VHT20;
2576 } else if (sta->ht_cap.ht_supported &&
2577 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2578 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2579 phymode = MODE_11NG_HT40;
2581 phymode = MODE_11NG_HT20;
2582 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2589 case IEEE80211_BAND_5GHZ:
2593 if (sta->vht_cap.vht_supported &&
2594 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2595 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2596 phymode = MODE_11AC_VHT80;
2597 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2598 phymode = MODE_11AC_VHT40;
2599 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2600 phymode = MODE_11AC_VHT20;
2601 } else if (sta->ht_cap.ht_supported &&
2602 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2603 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2604 phymode = MODE_11NA_HT40;
2606 phymode = MODE_11NA_HT20;
2616 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2617 sta->addr, ath10k_wmi_phymode_str(phymode));
2619 arg->peer_phymode = phymode;
2620 WARN_ON(phymode == MODE_UNKNOWN);
2623 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2624 struct ieee80211_vif *vif,
2625 struct ieee80211_sta *sta,
2626 struct wmi_peer_assoc_complete_arg *arg)
2628 lockdep_assert_held(&ar->conf_mutex);
2630 memset(arg, 0, sizeof(*arg));
2632 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2633 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2634 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2635 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2636 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2637 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2638 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2643 static const u32 ath10k_smps_map[] = {
2644 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2645 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2646 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2647 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2650 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2652 const struct ieee80211_sta_ht_cap *ht_cap)
2656 if (!ht_cap->ht_supported)
2659 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2660 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2662 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2665 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2666 WMI_PEER_SMPS_STATE,
2667 ath10k_smps_map[smps]);
2670 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2671 struct ieee80211_vif *vif,
2672 struct ieee80211_sta_vht_cap vht_cap)
2674 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2679 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2682 if (!(ar->vht_cap_info &
2683 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2684 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2685 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2686 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2689 param = ar->wmi.vdev_param->txbf;
2692 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2695 /* The following logic is correct. If a remote STA advertises support
2696 * for being a beamformer then we should enable us being a beamformee.
2699 if (ar->vht_cap_info &
2700 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2701 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2702 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2703 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2705 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2706 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2709 if (ar->vht_cap_info &
2710 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2711 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2712 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2713 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2715 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2716 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2719 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2720 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2722 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2723 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2725 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2727 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2735 /* can be called only in mac80211 callbacks due to `key_count` usage */
2736 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2737 struct ieee80211_vif *vif,
2738 struct ieee80211_bss_conf *bss_conf)
2740 struct ath10k *ar = hw->priv;
2741 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2742 struct ieee80211_sta_ht_cap ht_cap;
2743 struct ieee80211_sta_vht_cap vht_cap;
2744 struct wmi_peer_assoc_complete_arg peer_arg;
2745 struct ieee80211_sta *ap_sta;
2748 lockdep_assert_held(&ar->conf_mutex);
2750 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2751 arvif->vdev_id, arvif->bssid, arvif->aid);
2755 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2757 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2758 bss_conf->bssid, arvif->vdev_id);
2763 /* ap_sta must be accessed only within rcu section which must be left
2764 * before calling ath10k_setup_peer_smps() which might sleep. */
2765 ht_cap = ap_sta->ht_cap;
2766 vht_cap = ap_sta->vht_cap;
2768 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2770 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2771 bss_conf->bssid, arvif->vdev_id, ret);
2778 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2780 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2781 bss_conf->bssid, arvif->vdev_id, ret);
2785 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2787 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2788 arvif->vdev_id, ret);
2792 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2794 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2795 arvif->vdev_id, bss_conf->bssid, ret);
2799 ath10k_dbg(ar, ATH10K_DBG_MAC,
2800 "mac vdev %d up (associated) bssid %pM aid %d\n",
2801 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2803 WARN_ON(arvif->is_up);
2805 arvif->aid = bss_conf->aid;
2806 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2808 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2810 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2811 arvif->vdev_id, ret);
2815 arvif->is_up = true;
2817 /* Workaround: Some firmware revisions (tested with qca6174
2818 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2819 * poked with peer param command.
2821 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2822 WMI_PEER_DUMMY_VAR, 1);
2824 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2825 arvif->bssid, arvif->vdev_id, ret);
2830 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2831 struct ieee80211_vif *vif)
2833 struct ath10k *ar = hw->priv;
2834 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2835 struct ieee80211_sta_vht_cap vht_cap = {};
2838 lockdep_assert_held(&ar->conf_mutex);
2840 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2841 arvif->vdev_id, arvif->bssid);
2843 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2845 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2846 arvif->vdev_id, ret);
2848 arvif->def_wep_key_idx = -1;
2850 if (!QCA_REV_WCN3990(ar)) {
2851 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2853 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2854 arvif->vdev_id, ret);
2859 arvif->is_up = false;
2861 cancel_delayed_work_sync(&arvif->connection_loss_work);
2864 static int ath10k_station_assoc(struct ath10k *ar,
2865 struct ieee80211_vif *vif,
2866 struct ieee80211_sta *sta,
2869 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2870 struct wmi_peer_assoc_complete_arg peer_arg;
2873 lockdep_assert_held(&ar->conf_mutex);
2875 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2877 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2878 sta->addr, arvif->vdev_id, ret);
2882 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2884 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2885 sta->addr, arvif->vdev_id, ret);
2889 /* Re-assoc is run only to update supported rates for given station. It
2890 * doesn't make much sense to reconfigure the peer completely.
2893 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2896 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2897 arvif->vdev_id, ret);
2901 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2903 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2904 sta->addr, arvif->vdev_id, ret);
2909 arvif->num_legacy_stations++;
2910 ret = ath10k_recalc_rtscts_prot(arvif);
2912 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2913 arvif->vdev_id, ret);
2918 /* Plumb cached keys only for static WEP */
2919 if (arvif->def_wep_key_idx != -1) {
2920 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2922 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2923 arvif->vdev_id, ret);
2932 static int ath10k_station_disassoc(struct ath10k *ar,
2933 struct ieee80211_vif *vif,
2934 struct ieee80211_sta *sta)
2936 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2939 lockdep_assert_held(&ar->conf_mutex);
2942 arvif->num_legacy_stations--;
2943 ret = ath10k_recalc_rtscts_prot(arvif);
2945 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2946 arvif->vdev_id, ret);
2951 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2953 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2954 arvif->vdev_id, ret);
2965 static int ath10k_update_channel_list(struct ath10k *ar)
2967 struct ieee80211_hw *hw = ar->hw;
2968 struct ieee80211_supported_band **bands;
2969 enum ieee80211_band band;
2970 struct ieee80211_channel *channel;
2971 struct wmi_scan_chan_list_arg arg = {0};
2972 struct wmi_channel_arg *ch;
2978 lockdep_assert_held(&ar->conf_mutex);
2980 bands = hw->wiphy->bands;
2981 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2985 for (i = 0; i < bands[band]->n_channels; i++) {
2986 if (bands[band]->channels[i].flags &
2987 IEEE80211_CHAN_DISABLED)
2994 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2995 arg.channels = kzalloc(len, GFP_KERNEL);
3000 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
3004 for (i = 0; i < bands[band]->n_channels; i++) {
3005 channel = &bands[band]->channels[i];
3007 if (channel->flags & IEEE80211_CHAN_DISABLED)
3010 ch->allow_ht = true;
3012 /* FIXME: when should we really allow VHT? */
3013 ch->allow_vht = true;
3016 !(channel->flags & IEEE80211_CHAN_NO_IR);
3019 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3022 !!(channel->flags & IEEE80211_CHAN_RADAR);
3024 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3025 ch->passive = passive;
3027 /* the firmware is ignoring the "radar" flag of the
3028 * channel and is scanning actively using Probe Requests
3029 * on "Radar detection"/DFS channels which are not
3030 * marked as "available"
3032 ch->passive |= ch->chan_radar;
3034 ch->freq = channel->center_freq;
3035 ch->band_center_freq1 = channel->center_freq;
3037 ch->max_power = channel->max_power * 2;
3038 ch->max_reg_power = channel->max_reg_power * 2;
3039 ch->max_antenna_gain = channel->max_antenna_gain * 2;
3040 ch->reg_class_id = 0; /* FIXME */
3042 /* FIXME: why use only legacy modes, why not any
3043 * HT/VHT modes? Would that even make any
3045 if (channel->band == IEEE80211_BAND_2GHZ)
3046 ch->mode = MODE_11G;
3048 ch->mode = MODE_11A;
3050 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3053 ath10k_dbg(ar, ATH10K_DBG_WMI,
3054 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3055 ch - arg.channels, arg.n_channels,
3056 ch->freq, ch->max_power, ch->max_reg_power,
3057 ch->max_antenna_gain, ch->mode);
3063 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3064 kfree(arg.channels);
3069 static enum wmi_dfs_region
3070 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3072 switch (dfs_region) {
3073 case NL80211_DFS_UNSET:
3074 return WMI_UNINIT_DFS_DOMAIN;
3075 case NL80211_DFS_FCC:
3076 return WMI_FCC_DFS_DOMAIN;
3077 case NL80211_DFS_ETSI:
3078 return WMI_ETSI_DFS_DOMAIN;
3079 case NL80211_DFS_JP:
3080 return WMI_MKK4_DFS_DOMAIN;
3082 return WMI_UNINIT_DFS_DOMAIN;
3085 static void ath10k_regd_update(struct ath10k *ar)
3087 struct reg_dmn_pair_mapping *regpair;
3089 enum wmi_dfs_region wmi_dfs_reg;
3090 enum nl80211_dfs_regions nl_dfs_reg;
3092 lockdep_assert_held(&ar->conf_mutex);
3094 ret = ath10k_update_channel_list(ar);
3096 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3098 regpair = ar->ath_common.regulatory.regpair;
3100 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3101 nl_dfs_reg = ar->dfs_detector->region;
3102 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3104 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3107 /* Target allows setting up per-band regdomain but ath_common provides
3108 * a combined one only */
3109 ret = ath10k_wmi_pdev_set_regdomain(ar,
3110 regpair->reg_domain,
3111 regpair->reg_domain, /* 2ghz */
3112 regpair->reg_domain, /* 5ghz */
3113 regpair->reg_2ghz_ctl,
3114 regpair->reg_5ghz_ctl,
3117 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3120 static void ath10k_reg_notifier(struct wiphy *wiphy,
3121 struct regulatory_request *request)
3123 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3124 struct ath10k *ar = hw->priv;
3127 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3129 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3130 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3131 request->dfs_region);
3132 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3133 request->dfs_region);
3135 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3136 request->dfs_region);
3139 mutex_lock(&ar->conf_mutex);
3140 if (ar->state == ATH10K_STATE_ON)
3141 ath10k_regd_update(ar);
3142 mutex_unlock(&ar->conf_mutex);
3149 enum ath10k_mac_tx_path {
3151 ATH10K_MAC_TX_HTT_MGMT,
3152 ATH10K_MAC_TX_WMI_MGMT,
3153 ATH10K_MAC_TX_UNKNOWN,
3156 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3158 lockdep_assert_held(&ar->htt.tx_lock);
3160 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3161 ar->tx_paused |= BIT(reason);
3162 ieee80211_stop_queues(ar->hw);
3165 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3166 struct ieee80211_vif *vif)
3168 struct ath10k *ar = data;
3169 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3171 if (arvif->tx_paused)
3174 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3177 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3179 lockdep_assert_held(&ar->htt.tx_lock);
3181 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3182 ar->tx_paused &= ~BIT(reason);
3187 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3188 IEEE80211_IFACE_ITER_RESUME_ALL,
3189 ath10k_mac_tx_unlock_iter,
3192 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3195 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3197 struct ath10k *ar = arvif->ar;
3199 lockdep_assert_held(&ar->htt.tx_lock);
3201 WARN_ON(reason >= BITS_PER_LONG);
3202 arvif->tx_paused |= BIT(reason);
3203 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3206 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3208 struct ath10k *ar = arvif->ar;
3210 lockdep_assert_held(&ar->htt.tx_lock);
3212 WARN_ON(reason >= BITS_PER_LONG);
3213 arvif->tx_paused &= ~BIT(reason);
3218 if (arvif->tx_paused)
3221 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3224 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3225 enum wmi_tlv_tx_pause_id pause_id,
3226 enum wmi_tlv_tx_pause_action action)
3228 struct ath10k *ar = arvif->ar;
3230 lockdep_assert_held(&ar->htt.tx_lock);
3233 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3234 ath10k_mac_vif_tx_lock(arvif, pause_id);
3236 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3237 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3240 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3241 action, arvif->vdev_id);
3246 struct ath10k_mac_tx_pause {
3248 enum wmi_tlv_tx_pause_id pause_id;
3249 enum wmi_tlv_tx_pause_action action;
3252 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3253 struct ieee80211_vif *vif)
3255 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3256 struct ath10k_mac_tx_pause *arg = data;
3258 if (arvif->vdev_id != arg->vdev_id)
3261 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3264 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3265 enum wmi_tlv_tx_pause_id pause_id,
3266 enum wmi_tlv_tx_pause_action action)
3268 struct ath10k_mac_tx_pause arg = {
3270 .pause_id = pause_id,
3274 spin_lock_bh(&ar->htt.tx_lock);
3275 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3276 IEEE80211_IFACE_ITER_RESUME_ALL,
3277 ath10k_mac_handle_tx_pause_iter,
3279 spin_unlock_bh(&ar->htt.tx_lock);
3282 static enum ath10k_hw_txrx_mode
3283 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3284 struct ieee80211_vif *vif,
3285 struct ieee80211_sta *sta,
3286 struct sk_buff *skb)
3288 const struct ieee80211_hdr *hdr = (void *)skb->data;
3289 __le16 fc = hdr->frame_control;
3291 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3292 return ATH10K_HW_TXRX_RAW;
3294 if (ieee80211_is_mgmt(fc))
3295 return ATH10K_HW_TXRX_MGMT;
3299 * NullFunc frames are mostly used to ping if a client or AP are still
3300 * reachable and responsive. This implies tx status reports must be
3301 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3302 * come to a conclusion that the other end disappeared and tear down
3303 * BSS connection or it can never disconnect from BSS/client (which is
3306 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3307 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3308 * which seems to deliver correct tx reports for NullFunc frames. The
3309 * downside of using it is it ignores client powersave state so it can
3310 * end up disconnecting sleeping clients in AP mode. It should fix STA
3311 * mode though because AP don't sleep.
3313 if (ar->htt.target_version_major < 3 &&
3314 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3315 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3316 ar->running_fw->fw_file.fw_features) &&
3317 !test_bit(ATH10K_FW_FEATURE_SKIP_NULL_FUNC_WAR,
3318 ar->running_fw->fw_file.fw_features))
3319 return ATH10K_HW_TXRX_MGMT;
3323 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3324 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3325 * to work with Ethernet txmode so use it.
3327 * FIXME: Check if raw mode works with TDLS.
3329 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3330 return ATH10K_HW_TXRX_ETHERNET;
3332 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3333 return ATH10K_HW_TXRX_RAW;
3335 return ATH10K_HW_TXRX_NATIVE_WIFI;
3338 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3339 struct sk_buff *skb)
3341 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3342 const struct ieee80211_hdr *hdr = (void *)skb->data;
3343 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3344 IEEE80211_TX_CTL_INJECTED;
3346 if (!ieee80211_has_protected(hdr->frame_control))
3349 if ((info->flags & mask) == mask)
3353 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3358 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3359 * Control in the header.
3361 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3363 struct ieee80211_hdr *hdr = (void *)skb->data;
3364 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3367 if (!ieee80211_is_data_qos(hdr->frame_control))
3370 qos_ctl = ieee80211_get_qos_ctl(hdr);
3371 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3372 skb->data, (void *)qos_ctl - (void *)skb->data);
3373 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3375 /* Some firmware revisions don't handle sending QoS NullFunc well.
3376 * These frames are mainly used for CQM purposes so it doesn't really
3377 * matter whether QoS NullFunc or NullFunc are sent.
3379 hdr = (void *)skb->data;
3380 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3381 cb->flags &= ~ATH10K_SKB_F_QOS;
3383 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3386 static void ath10k_tx_h_8023(struct sk_buff *skb)
3388 struct ieee80211_hdr *hdr;
3389 struct rfc1042_hdr *rfc1042;
3396 hdr = (void *)skb->data;
3397 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3398 rfc1042 = (void *)skb->data + hdrlen;
3400 ether_addr_copy(da, ieee80211_get_DA(hdr));
3401 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3402 type = rfc1042->snap_type;
3404 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3405 skb_push(skb, sizeof(*eth));
3407 eth = (void *)skb->data;
3408 ether_addr_copy(eth->h_dest, da);
3409 ether_addr_copy(eth->h_source, sa);
3410 eth->h_proto = type;
3413 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3414 struct ieee80211_vif *vif,
3415 struct sk_buff *skb)
3417 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3418 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3420 /* This is case only for P2P_GO */
3421 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3424 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3425 spin_lock_bh(&ar->data_lock);
3426 if (arvif->u.ap.noa_data)
3427 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3429 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3430 arvif->u.ap.noa_data,
3431 arvif->u.ap.noa_len);
3432 spin_unlock_bh(&ar->data_lock);
3436 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3437 struct ieee80211_vif *vif,
3438 struct ieee80211_txq *txq,
3439 struct sk_buff *skb)
3441 struct ieee80211_hdr *hdr = (void *)skb->data;
3442 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3445 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3446 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3448 if (ieee80211_is_mgmt(hdr->frame_control))
3449 cb->flags |= ATH10K_SKB_F_MGMT;
3451 if (ieee80211_is_data_qos(hdr->frame_control))
3452 cb->flags |= ATH10K_SKB_F_QOS;
3458 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3460 /* FIXME: Not really sure since when the behaviour changed. At some
3461 * point new firmware stopped requiring creation of peer entries for
3462 * offchannel tx (and actually creating them causes issues with wmi-htc
3463 * tx credit replenishment and reliability). Assuming it's at least 3.4
3464 * because that's when the `freq` was introduced to TX_FRM HTT command.
3466 return (ar->htt.target_version_major >= 3 &&
3467 ar->htt.target_version_minor >= 4 &&
3468 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3471 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3473 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3476 spin_lock_bh(&ar->data_lock);
3478 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3479 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3484 __skb_queue_tail(q, skb);
3485 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3488 spin_unlock_bh(&ar->data_lock);
3493 static enum ath10k_mac_tx_path
3494 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3495 struct sk_buff *skb,
3496 enum ath10k_hw_txrx_mode txmode)
3499 case ATH10K_HW_TXRX_RAW:
3500 case ATH10K_HW_TXRX_NATIVE_WIFI:
3501 case ATH10K_HW_TXRX_ETHERNET:
3502 return ATH10K_MAC_TX_HTT;
3503 case ATH10K_HW_TXRX_MGMT:
3504 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3505 ar->running_fw->fw_file.fw_features) ||
3506 test_bit(WMI_SERVICE_MGMT_TX_WMI,
3508 return ATH10K_MAC_TX_WMI_MGMT;
3509 else if (ar->htt.target_version_major >= 3)
3510 return ATH10K_MAC_TX_HTT;
3512 return ATH10K_MAC_TX_HTT_MGMT;
3515 return ATH10K_MAC_TX_UNKNOWN;
3518 static int ath10k_mac_tx_submit(struct ath10k *ar,
3519 enum ath10k_hw_txrx_mode txmode,
3520 enum ath10k_mac_tx_path txpath,
3521 struct sk_buff *skb)
3523 struct ath10k_htt *htt = &ar->htt;
3527 case ATH10K_MAC_TX_HTT:
3528 ret = ath10k_htt_tx(htt, txmode, skb);
3530 case ATH10K_MAC_TX_HTT_MGMT:
3531 ret = ath10k_htt_mgmt_tx(htt, skb);
3533 case ATH10K_MAC_TX_WMI_MGMT:
3534 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3536 case ATH10K_MAC_TX_UNKNOWN:
3543 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3545 ieee80211_free_txskb(ar->hw, skb);
3551 /* This function consumes the sk_buff regardless of return value as far as
3552 * caller is concerned so no freeing is necessary afterwards.
3554 static int ath10k_mac_tx(struct ath10k *ar,
3555 struct ieee80211_vif *vif,
3556 struct ieee80211_sta *sta,
3557 enum ath10k_hw_txrx_mode txmode,
3558 enum ath10k_mac_tx_path txpath,
3559 struct sk_buff *skb)
3561 struct ieee80211_hw *hw = ar->hw;
3562 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3566 /* We should disable CCK RATE due to P2P */
3567 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3568 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3571 case ATH10K_HW_TXRX_MGMT:
3572 case ATH10K_HW_TXRX_NATIVE_WIFI:
3573 ath10k_tx_h_nwifi(hw, skb);
3574 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3575 ath10k_tx_h_seq_no(vif, skb);
3577 case ATH10K_HW_TXRX_ETHERNET:
3578 ath10k_tx_h_8023(skb);
3580 case ATH10K_HW_TXRX_RAW:
3581 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3583 ieee80211_free_txskb(hw, skb);
3588 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3589 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3590 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3593 skb_queue_tail(&ar->offchan_tx_queue, skb);
3594 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3599 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3601 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3608 void ath10k_offchan_tx_purge(struct ath10k *ar)
3610 struct sk_buff *skb;
3613 skb = skb_dequeue(&ar->offchan_tx_queue);
3617 ieee80211_free_txskb(ar->hw, skb);
3621 void ath10k_offchan_tx_work(struct work_struct *work)
3623 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3624 struct ath10k_peer *peer;
3625 struct ath10k_vif *arvif;
3626 enum ath10k_hw_txrx_mode txmode;
3627 enum ath10k_mac_tx_path txpath;
3628 struct ieee80211_hdr *hdr;
3629 struct ieee80211_vif *vif;
3630 struct ieee80211_sta *sta;
3631 struct sk_buff *skb;
3632 const u8 *peer_addr;
3635 unsigned long time_left;
3636 bool tmp_peer_created = false;
3638 /* FW requirement: We must create a peer before FW will send out
3639 * an offchannel frame. Otherwise the frame will be stuck and
3640 * never transmitted. We delete the peer upon tx completion.
3641 * It is unlikely that a peer for offchannel tx will already be
3642 * present. However it may be in some rare cases so account for that.
3643 * Otherwise we might remove a legitimate peer and break stuff. */
3646 skb = skb_dequeue(&ar->offchan_tx_queue);
3650 mutex_lock(&ar->conf_mutex);
3652 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3655 hdr = (struct ieee80211_hdr *)skb->data;
3656 peer_addr = ieee80211_get_DA(hdr);
3658 spin_lock_bh(&ar->data_lock);
3659 vdev_id = ar->scan.vdev_id;
3660 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3661 spin_unlock_bh(&ar->data_lock);
3664 /* FIXME: should this use ath10k_warn()? */
3665 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3666 peer_addr, vdev_id);
3669 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3671 WMI_PEER_TYPE_DEFAULT);
3673 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3674 peer_addr, vdev_id, ret);
3675 tmp_peer_created = (ret == 0);
3678 spin_lock_bh(&ar->data_lock);
3679 reinit_completion(&ar->offchan_tx_completed);
3680 ar->offchan_tx_skb = skb;
3681 spin_unlock_bh(&ar->data_lock);
3683 /* It's safe to access vif and sta - conf_mutex guarantees that
3684 * sta_state() and remove_interface() are locked exclusively
3685 * out wrt to this offchannel worker.
3687 arvif = ath10k_get_arvif(ar, vdev_id);
3690 sta = ieee80211_find_sta(vif, peer_addr);
3696 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3697 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3699 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3701 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3707 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3709 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3712 if (!peer && tmp_peer_created) {
3713 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3715 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3716 peer_addr, vdev_id, ret);
3719 mutex_unlock(&ar->conf_mutex);
3723 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3725 struct sk_buff *skb;
3728 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3732 ieee80211_free_txskb(ar->hw, skb);
3736 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3738 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3739 struct sk_buff *skb;
3744 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3748 if (QCA_REV_WCN3990(ar)) {
3749 paddr = dma_map_single(ar->dev, skb->data,
3750 skb->len, DMA_TO_DEVICE);
3753 ret = ath10k_wmi_mgmt_tx_send(ar, skb, paddr);
3755 ath10k_warn(ar, "failed to transmit management frame by ref via WMI: %d\n",
3757 dma_unmap_single(ar->dev, paddr, skb->len,
3759 ieee80211_free_txskb(ar->hw, skb);
3762 ret = ath10k_wmi_mgmt_tx(ar, skb);
3764 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3766 ieee80211_free_txskb(ar->hw, skb);
3772 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3774 struct ath10k_txq *artxq;
3779 artxq = (void *)txq->drv_priv;
3780 INIT_LIST_HEAD(&artxq->list);
3783 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3785 struct ath10k_txq *artxq;
3786 struct ath10k_skb_cb *cb;
3787 struct sk_buff *msdu;
3793 artxq = (void *)txq->drv_priv;
3794 spin_lock_bh(&ar->txqs_lock);
3795 if (!list_empty(&artxq->list))
3796 list_del_init(&artxq->list);
3797 spin_unlock_bh(&ar->txqs_lock);
3799 spin_lock_bh(&ar->htt.tx_lock);
3800 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3801 cb = ATH10K_SKB_CB(msdu);
3805 spin_unlock_bh(&ar->htt.tx_lock);
3808 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3812 struct ath10k_peer *peer;
3814 lockdep_assert_held(&ar->data_lock);
3816 peer = ar->peer_map[peer_id];
3821 return peer->sta->txq[tid];
3823 return peer->vif->txq;
3828 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3829 struct ieee80211_txq *txq)
3831 struct ath10k *ar = hw->priv;
3832 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3834 /* No need to get locks */
3836 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3839 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3842 if (artxq->num_fw_queued < artxq->num_push_allowed)
3848 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3849 struct ieee80211_txq *txq)
3851 struct ath10k *ar = hw->priv;
3852 struct ath10k_htt *htt = &ar->htt;
3853 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3854 struct ieee80211_vif *vif = txq->vif;
3855 struct ieee80211_sta *sta = txq->sta;
3856 enum ath10k_hw_txrx_mode txmode;
3857 enum ath10k_mac_tx_path txpath;
3858 struct sk_buff *skb;
3859 struct ieee80211_hdr *hdr;
3861 bool is_mgmt, is_presp;
3864 spin_lock_bh(&ar->htt.tx_lock);
3865 ret = ath10k_htt_tx_inc_pending(htt);
3866 spin_unlock_bh(&ar->htt.tx_lock);
3871 skb = ieee80211_tx_dequeue(hw, txq);
3873 spin_lock_bh(&ar->htt.tx_lock);
3874 ath10k_htt_tx_dec_pending(htt);
3875 spin_unlock_bh(&ar->htt.tx_lock);
3880 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3883 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3884 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3885 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3888 hdr = (struct ieee80211_hdr *)skb->data;
3889 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3891 spin_lock_bh(&ar->htt.tx_lock);
3892 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3895 ath10k_htt_tx_dec_pending(htt);
3896 spin_unlock_bh(&ar->htt.tx_lock);
3899 spin_unlock_bh(&ar->htt.tx_lock);
3902 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3903 if (unlikely(ret)) {
3904 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3906 spin_lock_bh(&ar->htt.tx_lock);
3907 ath10k_htt_tx_dec_pending(htt);
3909 ath10k_htt_tx_mgmt_dec_pending(htt);
3910 spin_unlock_bh(&ar->htt.tx_lock);
3915 spin_lock_bh(&ar->htt.tx_lock);
3916 artxq->num_fw_queued++;
3917 spin_unlock_bh(&ar->htt.tx_lock);
3922 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3924 struct ieee80211_hw *hw = ar->hw;
3925 struct ieee80211_txq *txq;
3926 struct ath10k_txq *artxq;
3927 struct ath10k_txq *last;
3931 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3934 spin_lock_bh(&ar->txqs_lock);
3937 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3938 while (!list_empty(&ar->txqs)) {
3939 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3940 txq = container_of((void *)artxq, struct ieee80211_txq,
3943 /* Prevent aggressive sta/tid taking over tx queue */
3946 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3947 ret = ath10k_mac_tx_push_txq(hw, txq);
3952 list_del_init(&artxq->list);
3954 list_add_tail(&artxq->list, &ar->txqs);
3956 ath10k_htt_tx_txq_update(hw, txq);
3958 if (artxq == last || (ret < 0 && ret != -ENOENT))
3963 spin_unlock_bh(&ar->txqs_lock);
3970 void __ath10k_scan_finish(struct ath10k *ar)
3972 lockdep_assert_held(&ar->data_lock);
3974 switch (ar->scan.state) {
3975 case ATH10K_SCAN_IDLE:
3977 case ATH10K_SCAN_RUNNING:
3978 case ATH10K_SCAN_ABORTING:
3979 if (!ar->scan.is_roc)
3980 ieee80211_scan_completed(ar->hw,
3982 ATH10K_SCAN_ABORTING));
3983 else if (ar->scan.roc_notify)
3984 ieee80211_remain_on_channel_expired(ar->hw);
3986 case ATH10K_SCAN_STARTING:
3987 ar->scan.state = ATH10K_SCAN_IDLE;
3988 ar->scan_channel = NULL;
3989 ar->scan.roc_freq = 0;
3990 ath10k_offchan_tx_purge(ar);
3991 cancel_delayed_work(&ar->scan.timeout);
3992 complete(&ar->scan.completed);
3997 void ath10k_scan_finish(struct ath10k *ar)
3999 spin_lock_bh(&ar->data_lock);
4000 __ath10k_scan_finish(ar);
4001 spin_unlock_bh(&ar->data_lock);
4004 static int ath10k_scan_stop(struct ath10k *ar)
4006 struct wmi_stop_scan_arg arg = {
4007 .req_id = 1, /* FIXME */
4008 .req_type = WMI_SCAN_STOP_ONE,
4009 .u.scan_id = ATH10K_SCAN_ID,
4013 lockdep_assert_held(&ar->conf_mutex);
4015 ret = ath10k_wmi_stop_scan(ar, &arg);
4017 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
4021 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
4023 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
4025 } else if (ret > 0) {
4030 /* Scan state should be updated upon scan completion but in case
4031 * firmware fails to deliver the event (for whatever reason) it is
4032 * desired to clean up scan state anyway. Firmware may have just
4033 * dropped the scan completion event delivery due to transport pipe
4034 * being overflown with data and/or it can recover on its own before
4035 * next scan request is submitted.
4037 spin_lock_bh(&ar->data_lock);
4038 if (ar->scan.state != ATH10K_SCAN_IDLE)
4039 __ath10k_scan_finish(ar);
4040 spin_unlock_bh(&ar->data_lock);
4045 static void ath10k_scan_abort(struct ath10k *ar)
4049 lockdep_assert_held(&ar->conf_mutex);
4051 spin_lock_bh(&ar->data_lock);
4053 switch (ar->scan.state) {
4054 case ATH10K_SCAN_IDLE:
4055 /* This can happen if timeout worker kicked in and called
4056 * abortion while scan completion was being processed.
4059 case ATH10K_SCAN_STARTING:
4060 case ATH10K_SCAN_ABORTING:
4061 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4062 ath10k_scan_state_str(ar->scan.state),
4065 case ATH10K_SCAN_RUNNING:
4066 ar->scan.state = ATH10K_SCAN_ABORTING;
4067 spin_unlock_bh(&ar->data_lock);
4069 ret = ath10k_scan_stop(ar);
4071 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4073 spin_lock_bh(&ar->data_lock);
4077 spin_unlock_bh(&ar->data_lock);
4080 void ath10k_scan_timeout_work(struct work_struct *work)
4082 struct ath10k *ar = container_of(work, struct ath10k,
4085 mutex_lock(&ar->conf_mutex);
4086 ath10k_scan_abort(ar);
4087 mutex_unlock(&ar->conf_mutex);
4090 static int ath10k_start_scan(struct ath10k *ar,
4091 const struct wmi_start_scan_arg *arg)
4095 lockdep_assert_held(&ar->conf_mutex);
4097 ret = ath10k_wmi_start_scan(ar, arg);
4101 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4103 ret = ath10k_scan_stop(ar);
4105 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4110 /* If we failed to start the scan, return error code at
4111 * this point. This is probably due to some issue in the
4112 * firmware, but no need to wedge the driver due to that...
4114 spin_lock_bh(&ar->data_lock);
4115 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4116 spin_unlock_bh(&ar->data_lock);
4119 spin_unlock_bh(&ar->data_lock);
4124 /**********************/
4125 /* mac80211 callbacks */
4126 /**********************/
4128 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4129 struct ieee80211_tx_control *control,
4130 struct sk_buff *skb)
4132 struct ath10k *ar = hw->priv;
4133 struct ath10k_htt *htt = &ar->htt;
4134 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4135 struct ieee80211_vif *vif = info->control.vif;
4136 struct ieee80211_sta *sta = control->sta;
4137 struct ieee80211_txq *txq = NULL;
4138 struct ieee80211_hdr *hdr = (void *)skb->data;
4139 enum ath10k_hw_txrx_mode txmode;
4140 enum ath10k_mac_tx_path txpath;
4146 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4148 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4149 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4150 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4151 txpath == ATH10K_MAC_TX_HTT_MGMT);
4152 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4155 spin_lock_bh(&ar->htt.tx_lock);
4156 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4158 ret = ath10k_htt_tx_inc_pending(htt);
4160 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4162 spin_unlock_bh(&ar->htt.tx_lock);
4163 ieee80211_free_txskb(ar->hw, skb);
4167 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4169 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4171 ath10k_htt_tx_dec_pending(htt);
4172 spin_unlock_bh(&ar->htt.tx_lock);
4173 ieee80211_free_txskb(ar->hw, skb);
4176 spin_unlock_bh(&ar->htt.tx_lock);
4179 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
4181 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4183 spin_lock_bh(&ar->htt.tx_lock);
4184 ath10k_htt_tx_dec_pending(htt);
4186 ath10k_htt_tx_mgmt_dec_pending(htt);
4187 spin_unlock_bh(&ar->htt.tx_lock);
4193 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4194 struct ieee80211_txq *txq)
4196 struct ath10k *ar = hw->priv;
4197 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4198 struct ieee80211_txq *f_txq;
4199 struct ath10k_txq *f_artxq;
4203 spin_lock_bh(&ar->txqs_lock);
4204 if (list_empty(&artxq->list))
4205 list_add_tail(&artxq->list, &ar->txqs);
4207 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4208 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4209 list_del_init(&f_artxq->list);
4211 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4212 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4217 list_add_tail(&f_artxq->list, &ar->txqs);
4218 spin_unlock_bh(&ar->txqs_lock);
4220 ath10k_htt_tx_txq_update(hw, f_txq);
4221 ath10k_htt_tx_txq_update(hw, txq);
4224 /* Must not be called with conf_mutex held as workers can use that also. */
4225 void ath10k_drain_tx(struct ath10k *ar)
4227 /* make sure rcu-protected mac80211 tx path itself is drained */
4230 ath10k_offchan_tx_purge(ar);
4231 ath10k_mgmt_over_wmi_tx_purge(ar);
4233 cancel_work_sync(&ar->offchan_tx_work);
4234 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4237 void ath10k_halt(struct ath10k *ar)
4239 struct ath10k_vif *arvif;
4241 lockdep_assert_held(&ar->conf_mutex);
4243 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4244 ar->filter_flags = 0;
4245 ar->monitor = false;
4246 ar->monitor_arvif = NULL;
4248 if (ar->monitor_started)
4249 ath10k_monitor_stop(ar);
4251 ar->monitor_started = false;
4254 ath10k_scan_finish(ar);
4255 ath10k_peer_cleanup_all(ar);
4256 ath10k_core_stop(ar);
4257 ath10k_hif_power_down(ar);
4259 spin_lock_bh(&ar->data_lock);
4260 list_for_each_entry(arvif, &ar->arvifs, list)
4261 ath10k_mac_vif_beacon_cleanup(arvif);
4262 spin_unlock_bh(&ar->data_lock);
4265 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4267 struct ath10k *ar = hw->priv;
4269 mutex_lock(&ar->conf_mutex);
4271 *tx_ant = ar->cfg_tx_chainmask;
4272 *rx_ant = ar->cfg_rx_chainmask;
4274 mutex_unlock(&ar->conf_mutex);
4279 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4281 /* It is not clear that allowing gaps in chainmask
4282 * is helpful. Probably it will not do what user
4283 * is hoping for, so warn in that case.
4285 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4288 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4292 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4294 int nsts = ar->vht_cap_info;
4296 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4297 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4299 /* If firmware does not deliver to host number of space-time
4300 * streams supported, assume it support up to 4 BF STS and return
4301 * the value for VHT CAP: nsts-1)
4309 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4311 int sound_dim = ar->vht_cap_info;
4313 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4314 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4316 /* If the sounding dimension is not advertised by the firmware,
4317 * let's use a default value of 1
4325 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4327 struct ieee80211_sta_vht_cap vht_cap = {0};
4332 vht_cap.vht_supported = 1;
4333 vht_cap.cap = ar->vht_cap_info;
4335 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4336 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4337 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4338 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4339 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4344 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4345 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4346 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4347 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4348 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4354 for (i = 0; i < 8; i++) {
4355 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4356 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4358 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4361 if (ar->cfg_tx_chainmask <= 1)
4362 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4364 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4365 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4370 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4373 struct ieee80211_sta_ht_cap ht_cap = {0};
4375 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4378 ht_cap.ht_supported = 1;
4379 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4380 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4381 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4382 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4384 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4386 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4387 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4389 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4390 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4392 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4395 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4396 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4401 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4402 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4404 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4407 stbc = ar->ht_cap_info;
4408 stbc &= WMI_HT_CAP_RX_STBC;
4409 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4410 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4411 stbc &= IEEE80211_HT_CAP_RX_STBC;
4416 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4417 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4419 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4420 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4422 /* max AMSDU is implicitly taken from vht_cap_info */
4423 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4424 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4426 for (i = 0; i < ar->num_rf_chains; i++) {
4427 if (ar->cfg_rx_chainmask & BIT(i))
4428 ht_cap.mcs.rx_mask[i] = 0xFF;
4431 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4436 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4438 struct ieee80211_supported_band *band;
4439 struct ieee80211_sta_vht_cap vht_cap;
4440 struct ieee80211_sta_ht_cap ht_cap;
4442 ht_cap = ath10k_get_ht_cap(ar);
4443 vht_cap = ath10k_create_vht_cap(ar);
4445 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4446 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4447 band->ht_cap = ht_cap;
4449 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4450 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4451 band->ht_cap = ht_cap;
4452 band->vht_cap = vht_cap;
4456 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4460 lockdep_assert_held(&ar->conf_mutex);
4462 ath10k_check_chain_mask(ar, tx_ant, "tx");
4463 ath10k_check_chain_mask(ar, rx_ant, "rx");
4465 ar->cfg_tx_chainmask = tx_ant;
4466 ar->cfg_rx_chainmask = rx_ant;
4468 if ((ar->state != ATH10K_STATE_ON) &&
4469 (ar->state != ATH10K_STATE_RESTARTED))
4472 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4475 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4480 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4483 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4488 /* Reload HT/VHT capability */
4489 ath10k_mac_setup_ht_vht_cap(ar);
4494 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4496 struct ath10k *ar = hw->priv;
4499 mutex_lock(&ar->conf_mutex);
4500 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4501 mutex_unlock(&ar->conf_mutex);
4505 static int ath10k_start(struct ieee80211_hw *hw)
4507 struct ath10k *ar = hw->priv;
4512 * This makes sense only when restarting hw. It is harmless to call
4513 * unconditionally. This is necessary to make sure no HTT/WMI tx
4514 * commands will be submitted while restarting.
4516 ath10k_drain_tx(ar);
4518 mutex_lock(&ar->conf_mutex);
4520 switch (ar->state) {
4521 case ATH10K_STATE_OFF:
4522 ar->state = ATH10K_STATE_ON;
4524 case ATH10K_STATE_RESTARTING:
4525 if (!test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
4527 ar->state = ATH10K_STATE_RESTARTED;
4529 case ATH10K_STATE_ON:
4530 case ATH10K_STATE_RESTARTED:
4531 case ATH10K_STATE_WEDGED:
4535 case ATH10K_STATE_UTF:
4540 ret = ath10k_hif_power_up(ar);
4542 ath10k_err(ar, "Could not init hif: %d\n", ret);
4546 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4547 &ar->normal_mode_fw);
4549 ath10k_err(ar, "Could not init core: %d\n", ret);
4550 goto err_power_down;
4553 param = ar->wmi.pdev_param->pmf_qos;
4554 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4556 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4560 param = ar->wmi.pdev_param->dynamic_bw;
4561 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4563 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4567 param = ar->wmi.pdev_param->idle_ps_config;
4568 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4570 ath10k_warn(ar, "failed to enable idle_ps_config: %d\n", ret);
4574 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4575 ret = ath10k_wmi_adaptive_qcs(ar, true);
4577 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4583 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4584 param = ar->wmi.pdev_param->burst_enable;
4585 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4587 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4592 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4595 * By default FW set ARP frames ac to voice (6). In that case ARP
4596 * exchange is not working properly for UAPSD enabled AP. ARP requests
4597 * which arrives with access category 0 are processed by network stack
4598 * and send back with access category 0, but FW changes access category
4599 * to 6. Set ARP frames access category to best effort (0) solves
4603 param = ar->wmi.pdev_param->arp_ac_override;
4604 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4606 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4611 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4612 ar->running_fw->fw_file.fw_features)) {
4613 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4614 WMI_CCA_DETECT_LEVEL_AUTO,
4615 WMI_CCA_DETECT_MARGIN_AUTO);
4617 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4621 ar->sifs_burst_enabled = false;
4624 param = ar->wmi.pdev_param->ani_enable;
4625 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4627 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4632 ar->ani_enabled = true;
4634 if (ath10k_peer_stats_enabled(ar)) {
4635 param = ar->wmi.pdev_param->peer_stats_update_period;
4636 ret = ath10k_wmi_pdev_set_param(ar, param,
4637 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4640 "failed to set peer stats period : %d\n",
4646 param = ar->wmi.pdev_param->enable_btcoex;
4647 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4648 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4649 ar->running_fw->fw_file.fw_features)) {
4650 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4653 "failed to set btcoex param: %d\n", ret);
4656 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4659 ar->num_started_vdevs = 0;
4660 ath10k_regd_update(ar);
4662 ath10k_spectral_start(ar);
4663 ath10k_thermal_set_throttling(ar);
4665 mutex_unlock(&ar->conf_mutex);
4669 ath10k_core_stop(ar);
4672 ath10k_hif_power_down(ar);
4675 ar->state = ATH10K_STATE_OFF;
4678 mutex_unlock(&ar->conf_mutex);
4682 static void ath10k_stop(struct ieee80211_hw *hw)
4684 struct ath10k *ar = hw->priv;
4686 ath10k_drain_tx(ar);
4688 mutex_lock(&ar->conf_mutex);
4689 if (ar->state != ATH10K_STATE_OFF) {
4691 ar->state = ATH10K_STATE_OFF;
4693 mutex_unlock(&ar->conf_mutex);
4695 cancel_delayed_work_sync(&ar->scan.timeout);
4696 cancel_work_sync(&ar->restart_work);
4699 static int ath10k_config_ps(struct ath10k *ar)
4701 struct ath10k_vif *arvif;
4704 lockdep_assert_held(&ar->conf_mutex);
4706 list_for_each_entry(arvif, &ar->arvifs, list) {
4707 ret = ath10k_mac_vif_setup_ps(arvif);
4709 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4717 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4722 lockdep_assert_held(&ar->conf_mutex);
4724 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4726 param = ar->wmi.pdev_param->txpower_limit2g;
4727 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4729 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4734 param = ar->wmi.pdev_param->txpower_limit5g;
4735 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4737 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4745 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4747 struct ath10k_vif *arvif;
4748 int ret, txpower = -1;
4750 lockdep_assert_held(&ar->conf_mutex);
4752 list_for_each_entry(arvif, &ar->arvifs, list) {
4753 if (arvif->txpower <= 0)
4757 txpower = arvif->txpower;
4759 txpower = min(txpower, arvif->txpower);
4765 ret = ath10k_mac_txpower_setup(ar, txpower);
4767 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4775 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4777 struct ath10k *ar = hw->priv;
4778 struct ieee80211_conf *conf = &hw->conf;
4781 mutex_lock(&ar->conf_mutex);
4783 if (changed & IEEE80211_CONF_CHANGE_PS)
4784 ath10k_config_ps(ar);
4786 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4787 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4788 ret = ath10k_monitor_recalc(ar);
4790 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4793 mutex_unlock(&ar->conf_mutex);
4797 static u32 get_nss_from_chainmask(u16 chain_mask)
4799 if ((chain_mask & 0xf) == 0xf)
4801 else if ((chain_mask & 0x7) == 0x7)
4803 else if ((chain_mask & 0x3) == 0x3)
4808 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4811 struct ath10k *ar = arvif->ar;
4815 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4818 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4819 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4820 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4821 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4823 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4824 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4825 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4826 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4831 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4832 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4834 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4835 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4836 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4838 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4839 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4841 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4842 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4843 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4845 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4846 ar->wmi.vdev_param->txbf, value);
4851 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4852 * because we will send mgmt frames without CCK. This requirement
4853 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4856 static int ath10k_add_interface(struct ieee80211_hw *hw,
4857 struct ieee80211_vif *vif)
4859 struct ath10k *ar = hw->priv;
4860 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4861 struct ath10k_peer *peer;
4862 enum wmi_sta_powersave_param param;
4869 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4871 mutex_lock(&ar->conf_mutex);
4873 memset(arvif, 0, sizeof(*arvif));
4874 ath10k_mac_txq_init(vif->txq);
4879 INIT_LIST_HEAD(&arvif->list);
4880 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4881 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4882 ath10k_mac_vif_sta_connection_loss_work);
4884 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4885 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4886 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4887 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4888 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4889 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4892 if (ar->num_peers >= ar->max_num_peers) {
4893 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4898 if (ar->free_vdev_map == 0) {
4899 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4903 bit = __ffs64(ar->free_vdev_map);
4905 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4906 bit, ar->free_vdev_map);
4908 arvif->vdev_id = bit;
4909 arvif->vdev_subtype =
4910 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4912 switch (vif->type) {
4913 case NL80211_IFTYPE_P2P_DEVICE:
4914 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4915 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4916 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4918 case NL80211_IFTYPE_UNSPECIFIED:
4919 case NL80211_IFTYPE_STATION:
4920 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4922 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4923 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4925 case NL80211_IFTYPE_ADHOC:
4926 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4928 case NL80211_IFTYPE_MESH_POINT:
4929 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4930 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4931 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4932 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4934 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4937 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4939 case NL80211_IFTYPE_AP:
4940 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4943 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4944 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4946 case NL80211_IFTYPE_MONITOR:
4947 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4954 /* Using vdev_id as queue number will make it very easy to do per-vif
4955 * tx queue locking. This shouldn't wrap due to interface combinations
4956 * but do a modulo for correctness sake and prevent using offchannel tx
4957 * queues for regular vif tx.
4959 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4960 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4961 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4963 /* Some firmware revisions don't wait for beacon tx completion before
4964 * sending another SWBA event. This could lead to hardware using old
4965 * (freed) beacon data in some cases, e.g. tx credit starvation
4966 * combined with missed TBTT. This is very very rare.
4968 * On non-IOMMU-enabled hosts this could be a possible security issue
4969 * because hw could beacon some random data on the air. On
4970 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4971 * device would crash.
4973 * Since there are no beacon tx completions (implicit nor explicit)
4974 * propagated to host the only workaround for this is to allocate a
4975 * DMA-coherent buffer for a lifetime of a vif and use it for all
4976 * beacon tx commands. Worst case for this approach is some beacons may
4977 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4979 if (vif->type == NL80211_IFTYPE_ADHOC ||
4980 vif->type == NL80211_IFTYPE_MESH_POINT ||
4981 vif->type == NL80211_IFTYPE_AP) {
4982 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4983 IEEE80211_MAX_FRAME_LEN,
4984 &arvif->beacon_paddr,
4986 if (!arvif->beacon_buf) {
4988 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4993 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4994 arvif->nohwcrypt = true;
4996 if (arvif->nohwcrypt &&
4997 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4998 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
5002 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
5003 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
5004 arvif->beacon_buf ? "single-buf" : "per-skb");
5006 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
5007 arvif->vdev_subtype, vif->addr);
5009 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
5010 arvif->vdev_id, ret);
5014 if ((arvif->vdev_type == WMI_VDEV_TYPE_STA) && QCA_REV_WCN3990(ar)) {
5015 ret = ath10k_wmi_csa_offload(ar, arvif->vdev_id, true);
5017 ath10k_err(ar, "CSA offload failed for vdev %i: %d\n",
5018 arvif->vdev_id, ret);
5019 goto err_vdev_delete;
5023 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
5024 list_add(&arvif->list, &ar->arvifs);
5026 /* It makes no sense to have firmware do keepalives. mac80211 already
5027 * takes care of this with idle connection polling.
5029 ret = ath10k_mac_vif_disable_keepalive(arvif);
5031 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5032 arvif->vdev_id, ret);
5033 goto err_vdev_delete;
5036 arvif->def_wep_key_idx = -1;
5038 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5039 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5040 ATH10K_HW_TXRX_NATIVE_WIFI);
5041 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5042 if (ret && ret != -EOPNOTSUPP) {
5043 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5044 arvif->vdev_id, ret);
5045 goto err_vdev_delete;
5048 /* Configuring number of spatial stream for monitor interface is causing
5049 * target assert in qca9888 and qca6174.
5051 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5052 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5054 vdev_param = ar->wmi.vdev_param->nss;
5055 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5058 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5059 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5061 goto err_vdev_delete;
5065 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5066 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5067 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5068 vif->addr, WMI_PEER_TYPE_DEFAULT);
5070 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5071 arvif->vdev_id, ret);
5072 goto err_vdev_delete;
5075 spin_lock_bh(&ar->data_lock);
5077 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5079 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5080 vif->addr, arvif->vdev_id);
5081 spin_unlock_bh(&ar->data_lock);
5083 goto err_peer_delete;
5086 arvif->peer_id = find_first_bit(peer->peer_ids,
5087 ATH10K_MAX_NUM_PEER_IDS);
5089 spin_unlock_bh(&ar->data_lock);
5091 arvif->peer_id = HTT_INVALID_PEERID;
5094 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5095 ret = ath10k_mac_set_kickout(arvif);
5097 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5098 arvif->vdev_id, ret);
5099 goto err_peer_delete;
5103 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5104 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5105 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5106 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5109 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5110 arvif->vdev_id, ret);
5111 goto err_peer_delete;
5114 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5116 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5117 arvif->vdev_id, ret);
5118 goto err_peer_delete;
5121 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5123 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5124 arvif->vdev_id, ret);
5125 goto err_peer_delete;
5129 ret = ath10k_mac_set_txbf_conf(arvif);
5131 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5132 arvif->vdev_id, ret);
5133 goto err_peer_delete;
5136 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5138 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5139 arvif->vdev_id, ret);
5140 goto err_peer_delete;
5143 arvif->txpower = vif->bss_conf.txpower;
5144 ret = ath10k_mac_txpower_recalc(ar);
5146 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5147 goto err_peer_delete;
5150 if (vif->type == NL80211_IFTYPE_MONITOR) {
5151 ar->monitor_arvif = arvif;
5152 ret = ath10k_monitor_recalc(ar);
5154 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5155 goto err_peer_delete;
5159 spin_lock_bh(&ar->htt.tx_lock);
5161 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5162 spin_unlock_bh(&ar->htt.tx_lock);
5164 mutex_unlock(&ar->conf_mutex);
5168 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5169 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5170 ath10k_peer_delete(ar, arvif->vdev_id, vif->addr);
5173 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5174 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5175 list_del(&arvif->list);
5178 if (arvif->beacon_buf) {
5179 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5180 arvif->beacon_buf, arvif->beacon_paddr);
5181 arvif->beacon_buf = NULL;
5184 mutex_unlock(&ar->conf_mutex);
5189 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5193 for (i = 0; i < BITS_PER_LONG; i++)
5194 ath10k_mac_vif_tx_unlock(arvif, i);
5197 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5198 struct ieee80211_vif *vif)
5200 struct ath10k *ar = hw->priv;
5201 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5202 struct ath10k_peer *peer;
5203 unsigned long time_left;
5207 cancel_work_sync(&arvif->ap_csa_work);
5208 cancel_delayed_work_sync(&arvif->connection_loss_work);
5210 mutex_lock(&ar->conf_mutex);
5212 spin_lock_bh(&ar->data_lock);
5213 ath10k_mac_vif_beacon_cleanup(arvif);
5214 spin_unlock_bh(&ar->data_lock);
5216 ret = ath10k_spectral_vif_stop(arvif);
5218 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5219 arvif->vdev_id, ret);
5221 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5222 list_del(&arvif->list);
5224 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5225 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5226 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
5229 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5230 arvif->vdev_id, ret);
5232 kfree(arvif->u.ap.noa_data);
5235 if ((arvif->vdev_type == WMI_VDEV_TYPE_STA) && QCA_REV_WCN3990(ar))
5236 ath10k_wmi_csa_offload(ar, arvif->vdev_id, false);
5238 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5241 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5243 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5244 arvif->vdev_id, ret);
5246 if (QCA_REV_WCN3990(ar)) {
5247 time_left = wait_for_completion_timeout(
5248 &ar->vdev_delete_done,
5249 ATH10K_VDEV_DELETE_TIMEOUT_HZ);
5250 if (time_left == 0) {
5251 ath10k_warn(ar, "Timeout in receiving vdev delete resp\n");
5256 /* Some firmware revisions don't notify host about self-peer removal
5257 * until after associated vdev is deleted.
5259 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5260 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5261 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5264 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5265 arvif->vdev_id, ret);
5267 spin_lock_bh(&ar->data_lock);
5269 spin_unlock_bh(&ar->data_lock);
5272 spin_lock_bh(&ar->data_lock);
5273 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5274 peer = ar->peer_map[i];
5278 if (peer->vif == vif) {
5279 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5280 vif->addr, arvif->vdev_id);
5284 spin_unlock_bh(&ar->data_lock);
5286 ath10k_peer_cleanup(ar, arvif->vdev_id);
5287 ath10k_mac_txq_unref(ar, vif->txq);
5289 if (vif->type == NL80211_IFTYPE_MONITOR) {
5290 ar->monitor_arvif = NULL;
5291 ret = ath10k_monitor_recalc(ar);
5293 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5296 ret = ath10k_mac_txpower_recalc(ar);
5298 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5300 spin_lock_bh(&ar->htt.tx_lock);
5301 ath10k_mac_vif_tx_unlock_all(arvif);
5302 spin_unlock_bh(&ar->htt.tx_lock);
5304 ath10k_mac_txq_unref(ar, vif->txq);
5306 mutex_unlock(&ar->conf_mutex);
5309 static int ath10k_change_interface(struct ieee80211_hw *hw,
5310 struct ieee80211_vif *vif,
5311 enum nl80211_iftype new_type, bool p2p)
5313 struct ath10k *ar = hw->priv;
5316 ath10k_dbg(ar, ATH10K_DBG_MAC,
5317 "change_interface new: %d (%d), old: %d (%d)\n", new_type,
5318 p2p, vif->type, vif->p2p);
5320 if (new_type != vif->type || vif->p2p != p2p) {
5321 ath10k_remove_interface(hw, vif);
5322 vif->type = new_type;
5324 ret = ath10k_add_interface(hw, vif);
5330 * FIXME: Has to be verified.
5332 #define SUPPORTED_FILTERS \
5337 FIF_BCN_PRBRESP_PROMISC | \
5341 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5342 unsigned int changed_flags,
5343 unsigned int *total_flags,
5346 struct ath10k *ar = hw->priv;
5349 mutex_lock(&ar->conf_mutex);
5351 changed_flags &= SUPPORTED_FILTERS;
5352 *total_flags &= SUPPORTED_FILTERS;
5353 ar->filter_flags = *total_flags;
5355 ret = ath10k_monitor_recalc(ar);
5357 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5359 mutex_unlock(&ar->conf_mutex);
5362 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5363 struct ieee80211_vif *vif,
5364 struct ieee80211_bss_conf *info,
5367 struct ath10k *ar = hw->priv;
5368 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5370 u32 vdev_param, pdev_param, slottime, preamble;
5372 mutex_lock(&ar->conf_mutex);
5374 if (changed & BSS_CHANGED_IBSS)
5375 ath10k_control_ibss(arvif, info, vif->addr);
5377 if (changed & BSS_CHANGED_BEACON_INT) {
5378 arvif->beacon_interval = info->beacon_int;
5379 vdev_param = ar->wmi.vdev_param->beacon_interval;
5380 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5381 arvif->beacon_interval);
5382 ath10k_dbg(ar, ATH10K_DBG_MAC,
5383 "mac vdev %d beacon_interval %d\n",
5384 arvif->vdev_id, arvif->beacon_interval);
5387 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5388 arvif->vdev_id, ret);
5391 if (changed & BSS_CHANGED_BEACON) {
5392 ath10k_dbg(ar, ATH10K_DBG_MAC,
5393 "vdev %d set beacon tx mode to staggered\n",
5396 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5397 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5398 WMI_BEACON_STAGGERED_MODE);
5400 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5401 arvif->vdev_id, ret);
5403 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5405 ath10k_warn(ar, "failed to update beacon template: %d\n",
5408 if (ieee80211_vif_is_mesh(vif)) {
5409 /* mesh doesn't use SSID but firmware needs it */
5410 strncpy(arvif->u.ap.ssid, "mesh",
5411 sizeof(arvif->u.ap.ssid));
5412 arvif->u.ap.ssid_len = 4;
5416 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5417 ret = ath10k_mac_setup_prb_tmpl(arvif);
5419 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5420 arvif->vdev_id, ret);
5423 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5424 arvif->dtim_period = info->dtim_period;
5426 ath10k_dbg(ar, ATH10K_DBG_MAC,
5427 "mac vdev %d dtim_period %d\n",
5428 arvif->vdev_id, arvif->dtim_period);
5430 vdev_param = ar->wmi.vdev_param->dtim_period;
5431 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5432 arvif->dtim_period);
5434 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5435 arvif->vdev_id, ret);
5438 if (changed & BSS_CHANGED_SSID &&
5439 vif->type == NL80211_IFTYPE_AP) {
5440 arvif->u.ap.ssid_len = info->ssid_len;
5442 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5443 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5446 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5447 ether_addr_copy(arvif->bssid, info->bssid);
5449 if (changed & BSS_CHANGED_BEACON_ENABLED)
5450 ath10k_control_beaconing(arvif, info);
5452 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5453 arvif->use_cts_prot = info->use_cts_prot;
5455 ret = ath10k_recalc_rtscts_prot(arvif);
5457 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5458 arvif->vdev_id, ret);
5460 if (ath10k_mac_can_set_cts_prot(arvif)) {
5461 ret = ath10k_mac_set_cts_prot(arvif);
5463 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5464 arvif->vdev_id, ret);
5468 if (changed & BSS_CHANGED_ERP_SLOT) {
5469 if (info->use_short_slot)
5470 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5473 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5475 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5476 arvif->vdev_id, slottime);
5478 vdev_param = ar->wmi.vdev_param->slot_time;
5479 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5482 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5483 arvif->vdev_id, ret);
5486 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5487 if (info->use_short_preamble)
5488 preamble = WMI_VDEV_PREAMBLE_SHORT;
5490 preamble = WMI_VDEV_PREAMBLE_LONG;
5492 ath10k_dbg(ar, ATH10K_DBG_MAC,
5493 "mac vdev %d preamble %dn",
5494 arvif->vdev_id, preamble);
5496 vdev_param = ar->wmi.vdev_param->preamble;
5497 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5500 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5501 arvif->vdev_id, ret);
5504 if (changed & BSS_CHANGED_ASSOC) {
5506 /* Workaround: Make sure monitor vdev is not running
5507 * when associating to prevent some firmware revisions
5508 * (e.g. 10.1 and 10.2) from crashing.
5510 if (ar->monitor_started)
5511 ath10k_monitor_stop(ar);
5512 ath10k_bss_assoc(hw, vif, info);
5513 ath10k_monitor_recalc(ar);
5515 ath10k_bss_disassoc(hw, vif);
5519 if (changed & BSS_CHANGED_TXPOWER) {
5520 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5521 arvif->vdev_id, info->txpower);
5523 arvif->txpower = info->txpower;
5524 ret = ath10k_mac_txpower_recalc(ar);
5526 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5529 if (changed & BSS_CHANGED_PS) {
5530 arvif->ps = vif->bss_conf.ps;
5532 ret = ath10k_config_ps(ar);
5534 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5535 arvif->vdev_id, ret);
5538 mutex_unlock(&ar->conf_mutex);
5541 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5542 struct ieee80211_vif *vif,
5543 struct ieee80211_scan_request *hw_req)
5545 struct ath10k *ar = hw->priv;
5546 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5547 struct cfg80211_scan_request *req = &hw_req->req;
5548 struct wmi_start_scan_arg arg;
5550 int ret = 0, ie_skip_len = 0;
5553 mutex_lock(&ar->conf_mutex);
5555 spin_lock_bh(&ar->data_lock);
5556 switch (ar->scan.state) {
5557 case ATH10K_SCAN_IDLE:
5558 reinit_completion(&ar->scan.started);
5559 reinit_completion(&ar->scan.completed);
5560 ar->scan.state = ATH10K_SCAN_STARTING;
5561 ar->scan.is_roc = false;
5562 ar->scan.vdev_id = arvif->vdev_id;
5565 case ATH10K_SCAN_STARTING:
5566 case ATH10K_SCAN_RUNNING:
5567 case ATH10K_SCAN_ABORTING:
5571 spin_unlock_bh(&ar->data_lock);
5576 memset(&arg, 0, sizeof(arg));
5577 ath10k_wmi_start_scan_init(ar, &arg);
5578 arg.vdev_id = arvif->vdev_id;
5579 arg.scan_id = ATH10K_SCAN_ID;
5582 if (QCA_REV_WCN3990(ar)) {
5584 while (ptr[0] == WLAN_EID_SUPP_RATES ||
5585 ptr[0] == WLAN_EID_EXT_SUPP_RATES) {
5586 ie_skip_len = ptr[1] + 2;
5590 arg.ie_len = req->ie_len - ie_skip_len;
5591 memcpy(arg.ie, req->ie + ie_skip_len, arg.ie_len);
5595 arg.n_ssids = req->n_ssids;
5596 for (i = 0; i < arg.n_ssids; i++) {
5597 arg.ssids[i].len = req->ssids[i].ssid_len;
5598 arg.ssids[i].ssid = req->ssids[i].ssid;
5600 if (QCA_REV_WCN3990(ar)) {
5601 arg.scan_ctrl_flags &=
5602 ~(WMI_SCAN_ADD_BCAST_PROBE_REQ |
5603 WMI_SCAN_CHAN_STAT_EVENT);
5606 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5609 if (req->n_channels) {
5610 arg.n_channels = req->n_channels;
5611 for (i = 0; i < arg.n_channels; i++)
5612 arg.channels[i] = req->channels[i]->center_freq;
5615 ret = ath10k_start_scan(ar, &arg);
5617 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5618 spin_lock_bh(&ar->data_lock);
5619 ar->scan.state = ATH10K_SCAN_IDLE;
5620 spin_unlock_bh(&ar->data_lock);
5623 /* Add a 200ms margin to account for event/command processing */
5624 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5625 msecs_to_jiffies(arg.max_scan_time +
5629 mutex_unlock(&ar->conf_mutex);
5633 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5634 struct ieee80211_vif *vif)
5636 struct ath10k *ar = hw->priv;
5638 mutex_lock(&ar->conf_mutex);
5639 ath10k_scan_abort(ar);
5640 mutex_unlock(&ar->conf_mutex);
5642 cancel_delayed_work_sync(&ar->scan.timeout);
5645 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5646 struct ath10k_vif *arvif,
5647 enum set_key_cmd cmd,
5648 struct ieee80211_key_conf *key)
5650 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5653 /* 10.1 firmware branch requires default key index to be set to group
5654 * key index after installing it. Otherwise FW/HW Txes corrupted
5655 * frames with multi-vif APs. This is not required for main firmware
5656 * branch (e.g. 636).
5658 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5660 * FIXME: It remains unknown if this is required for multi-vif STA
5661 * interfaces on 10.1.
5664 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5665 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5668 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5671 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5674 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5680 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5683 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5684 arvif->vdev_id, ret);
5687 static void ath10k_set_rekey_data(struct ieee80211_hw *hw,
5688 struct ieee80211_vif *vif,
5689 struct cfg80211_gtk_rekey_data *data)
5691 struct ath10k *ar = hw->priv;
5692 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5694 mutex_lock(&ar->conf_mutex);
5695 memcpy(&arvif->gtk_rekey_data.kek, data->kek, NL80211_KEK_LEN);
5696 memcpy(&arvif->gtk_rekey_data.kck, data->kck, NL80211_KCK_LEN);
5697 arvif->gtk_rekey_data.replay_ctr =
5698 be64_to_cpup((__be64 *)data->replay_ctr);
5699 arvif->gtk_rekey_data.valid = true;
5700 mutex_unlock(&ar->conf_mutex);
5703 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5704 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5705 struct ieee80211_key_conf *key)
5707 struct ath10k *ar = hw->priv;
5708 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5709 struct ath10k_peer *peer;
5710 const u8 *peer_addr;
5711 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5712 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5718 /* this one needs to be done in software */
5719 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5722 if (arvif->nohwcrypt)
5725 if (key->keyidx > WMI_MAX_KEY_INDEX)
5728 mutex_lock(&ar->conf_mutex);
5731 peer_addr = sta->addr;
5732 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5733 peer_addr = vif->bss_conf.bssid;
5735 peer_addr = vif->addr;
5737 key->hw_key_idx = key->keyidx;
5741 arvif->wep_keys[key->keyidx] = key;
5743 arvif->wep_keys[key->keyidx] = NULL;
5746 /* the peer should not disappear in mid-way (unless FW goes awry) since
5747 * we already hold conf_mutex. we just make sure its there now. */
5748 spin_lock_bh(&ar->data_lock);
5749 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5750 spin_unlock_bh(&ar->data_lock);
5753 if (cmd == SET_KEY) {
5754 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5759 /* if the peer doesn't exist there is no key to disable
5765 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5766 flags |= WMI_KEY_PAIRWISE;
5768 flags |= WMI_KEY_GROUP;
5771 if (cmd == DISABLE_KEY)
5772 ath10k_clear_vdev_key(arvif, key);
5774 /* When WEP keys are uploaded it's possible that there are
5775 * stations associated already (e.g. when merging) without any
5776 * keys. Static WEP needs an explicit per-peer key upload.
5778 if (vif->type == NL80211_IFTYPE_ADHOC &&
5780 ath10k_mac_vif_update_wep_key(arvif, key);
5782 /* 802.1x never sets the def_wep_key_idx so each set_key()
5783 * call changes default tx key.
5785 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5786 * after first set_key().
5788 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5789 flags |= WMI_KEY_TX_USAGE;
5792 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5795 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5796 arvif->vdev_id, peer_addr, ret);
5800 /* mac80211 sets static WEP keys as groupwise while firmware requires
5801 * them to be installed twice as both pairwise and groupwise.
5803 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5805 flags2 &= ~WMI_KEY_GROUP;
5806 flags2 |= WMI_KEY_PAIRWISE;
5808 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5811 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5812 arvif->vdev_id, peer_addr, ret);
5813 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5817 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5818 arvif->vdev_id, peer_addr, ret2);
5824 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5826 spin_lock_bh(&ar->data_lock);
5827 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5828 if (peer && cmd == SET_KEY)
5829 peer->keys[key->keyidx] = key;
5830 else if (peer && cmd == DISABLE_KEY)
5831 peer->keys[key->keyidx] = NULL;
5832 else if (peer == NULL)
5833 /* impossible unless FW goes crazy */
5834 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5835 spin_unlock_bh(&ar->data_lock);
5838 mutex_unlock(&ar->conf_mutex);
5842 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5843 struct ieee80211_vif *vif,
5846 struct ath10k *ar = hw->priv;
5847 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5850 mutex_lock(&arvif->ar->conf_mutex);
5852 if (arvif->ar->state != ATH10K_STATE_ON)
5855 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5856 arvif->vdev_id, keyidx);
5858 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5860 arvif->ar->wmi.vdev_param->def_keyid,
5864 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5870 arvif->def_wep_key_idx = keyidx;
5873 mutex_unlock(&arvif->ar->conf_mutex);
5876 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5879 struct ath10k_vif *arvif;
5880 struct ath10k_sta *arsta;
5881 struct ieee80211_sta *sta;
5882 struct cfg80211_chan_def def;
5883 enum ieee80211_band band;
5884 const u8 *ht_mcs_mask;
5885 const u16 *vht_mcs_mask;
5886 u32 changed, bw, nss, smps;
5889 arsta = container_of(wk, struct ath10k_sta, update_wk);
5890 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5891 arvif = arsta->arvif;
5894 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5897 band = def.chan->band;
5898 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5899 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5901 spin_lock_bh(&ar->data_lock);
5903 changed = arsta->changed;
5910 spin_unlock_bh(&ar->data_lock);
5912 mutex_lock(&ar->conf_mutex);
5914 nss = max_t(u32, 1, nss);
5915 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5916 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5918 if (changed & IEEE80211_RC_BW_CHANGED) {
5919 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5922 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5923 WMI_PEER_CHAN_WIDTH, bw);
5925 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5926 sta->addr, bw, err);
5929 if (changed & IEEE80211_RC_NSS_CHANGED) {
5930 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5933 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5936 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5937 sta->addr, nss, err);
5940 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5941 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5944 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5945 WMI_PEER_SMPS_STATE, smps);
5947 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5948 sta->addr, smps, err);
5951 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5952 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5955 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5957 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5961 mutex_unlock(&ar->conf_mutex);
5964 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5965 struct ieee80211_sta *sta)
5967 struct ath10k *ar = arvif->ar;
5969 lockdep_assert_held(&ar->conf_mutex);
5971 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5974 if (ar->num_stations >= ar->max_num_stations)
5982 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5983 struct ieee80211_sta *sta)
5985 struct ath10k *ar = arvif->ar;
5987 lockdep_assert_held(&ar->conf_mutex);
5989 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5995 struct ath10k_mac_tdls_iter_data {
5996 u32 num_tdls_stations;
5997 struct ieee80211_vif *curr_vif;
6000 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
6001 struct ieee80211_sta *sta)
6003 struct ath10k_mac_tdls_iter_data *iter_data = data;
6004 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6005 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
6007 if (sta->tdls && sta_vif == iter_data->curr_vif)
6008 iter_data->num_tdls_stations++;
6011 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
6012 struct ieee80211_vif *vif)
6014 struct ath10k_mac_tdls_iter_data data = {};
6016 data.curr_vif = vif;
6018 ieee80211_iterate_stations_atomic(hw,
6019 ath10k_mac_tdls_vif_stations_count_iter,
6021 return data.num_tdls_stations;
6024 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
6025 struct ieee80211_vif *vif)
6027 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6028 int *num_tdls_vifs = data;
6030 if (vif->type != NL80211_IFTYPE_STATION)
6033 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
6037 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
6039 int num_tdls_vifs = 0;
6041 ieee80211_iterate_active_interfaces_atomic(hw,
6042 IEEE80211_IFACE_ITER_NORMAL,
6043 ath10k_mac_tdls_vifs_count_iter,
6045 return num_tdls_vifs;
6048 static int ath10k_sta_state(struct ieee80211_hw *hw,
6049 struct ieee80211_vif *vif,
6050 struct ieee80211_sta *sta,
6051 enum ieee80211_sta_state old_state,
6052 enum ieee80211_sta_state new_state)
6054 struct ath10k *ar = hw->priv;
6055 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6056 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6057 struct ath10k_peer *peer;
6061 if (old_state == IEEE80211_STA_NOTEXIST &&
6062 new_state == IEEE80211_STA_NONE) {
6063 memset(arsta, 0, sizeof(*arsta));
6064 arsta->arvif = arvif;
6065 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6067 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6068 ath10k_mac_txq_init(sta->txq[i]);
6071 /* cancel must be done outside the mutex to avoid deadlock */
6072 if ((old_state == IEEE80211_STA_NONE &&
6073 new_state == IEEE80211_STA_NOTEXIST))
6074 cancel_work_sync(&arsta->update_wk);
6076 if (vif->type == NL80211_IFTYPE_STATION && new_state > ar->sta_state)
6077 ar->sta_state = new_state;
6079 mutex_lock(&ar->conf_mutex);
6081 if (old_state == IEEE80211_STA_NOTEXIST &&
6082 new_state == IEEE80211_STA_NONE) {
6084 * New station addition.
6086 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6087 u32 num_tdls_stations;
6090 ath10k_dbg(ar, ATH10K_DBG_MAC,
6091 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6092 arvif->vdev_id, sta->addr,
6093 ar->num_stations + 1, ar->max_num_stations,
6094 ar->num_peers + 1, ar->max_num_peers);
6096 ret = ath10k_mac_inc_num_stations(arvif, sta);
6098 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6099 ar->max_num_stations);
6104 peer_type = WMI_PEER_TYPE_TDLS;
6106 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6107 sta->addr, peer_type);
6109 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6110 sta->addr, arvif->vdev_id, ret);
6111 ath10k_mac_dec_num_stations(arvif, sta);
6115 spin_lock_bh(&ar->data_lock);
6117 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6119 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6120 vif->addr, arvif->vdev_id);
6121 spin_unlock_bh(&ar->data_lock);
6122 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6123 ath10k_mac_dec_num_stations(arvif, sta);
6128 arsta->peer_id = find_first_bit(peer->peer_ids,
6129 ATH10K_MAX_NUM_PEER_IDS);
6131 spin_unlock_bh(&ar->data_lock);
6136 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6137 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6139 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
6140 num_tdls_stations == 0) {
6141 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6142 arvif->vdev_id, ar->max_num_tdls_vdevs);
6143 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6144 ath10k_mac_dec_num_stations(arvif, sta);
6149 if (num_tdls_stations == 0) {
6150 /* This is the first tdls peer in current vif */
6151 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
6153 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6156 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6157 arvif->vdev_id, ret);
6158 ath10k_peer_delete(ar, arvif->vdev_id,
6160 ath10k_mac_dec_num_stations(arvif, sta);
6165 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6166 WMI_TDLS_PEER_STATE_PEERING);
6169 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6170 sta->addr, arvif->vdev_id, ret);
6171 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6172 ath10k_mac_dec_num_stations(arvif, sta);
6174 if (num_tdls_stations != 0)
6176 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6179 } else if ((old_state == IEEE80211_STA_NONE &&
6180 new_state == IEEE80211_STA_NOTEXIST)) {
6182 * Existing station deletion.
6184 ath10k_dbg(ar, ATH10K_DBG_MAC,
6185 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6186 arvif->vdev_id, sta->addr, sta);
6189 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6191 WMI_TDLS_PEER_STATE_TEARDOWN);
6193 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6195 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6198 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6200 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6201 sta->addr, arvif->vdev_id, ret);
6203 ath10k_mac_dec_num_stations(arvif, sta);
6205 spin_lock_bh(&ar->data_lock);
6206 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6207 peer = ar->peer_map[i];
6211 if (peer->sta == sta) {
6212 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6213 sta->addr, peer, i, arvif->vdev_id);
6216 /* Clean up the peer object as well since we
6217 * must have failed to do this above.
6219 list_del(&peer->list);
6220 ar->peer_map[i] = NULL;
6225 spin_unlock_bh(&ar->data_lock);
6227 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6228 ath10k_mac_txq_unref(ar, sta->txq[i]);
6233 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6236 /* This was the last tdls peer in current vif */
6237 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6240 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6241 arvif->vdev_id, ret);
6243 } else if (old_state == IEEE80211_STA_AUTH &&
6244 new_state == IEEE80211_STA_ASSOC &&
6245 (vif->type == NL80211_IFTYPE_AP ||
6246 vif->type == NL80211_IFTYPE_MESH_POINT ||
6247 vif->type == NL80211_IFTYPE_ADHOC)) {
6251 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6254 ret = ath10k_station_assoc(ar, vif, sta, false);
6256 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6257 sta->addr, arvif->vdev_id, ret);
6258 } else if (old_state == IEEE80211_STA_ASSOC &&
6259 new_state == IEEE80211_STA_AUTHORIZED &&
6262 * Tdls station authorized.
6264 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6267 ret = ath10k_station_assoc(ar, vif, sta, false);
6269 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6270 sta->addr, arvif->vdev_id, ret);
6274 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6275 WMI_TDLS_PEER_STATE_CONNECTED);
6277 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6278 sta->addr, arvif->vdev_id, ret);
6279 } else if (old_state == IEEE80211_STA_ASSOC &&
6280 new_state == IEEE80211_STA_AUTH &&
6281 (vif->type == NL80211_IFTYPE_AP ||
6282 vif->type == NL80211_IFTYPE_MESH_POINT ||
6283 vif->type == NL80211_IFTYPE_ADHOC)) {
6287 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6290 ret = ath10k_station_disassoc(ar, vif, sta);
6292 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6293 sta->addr, arvif->vdev_id, ret);
6296 mutex_unlock(&ar->conf_mutex);
6300 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6301 u16 ac, bool enable)
6303 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6304 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6305 u32 prio = 0, acc = 0;
6309 lockdep_assert_held(&ar->conf_mutex);
6311 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6315 case IEEE80211_AC_VO:
6316 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6317 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6321 case IEEE80211_AC_VI:
6322 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6323 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6327 case IEEE80211_AC_BE:
6328 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6329 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6333 case IEEE80211_AC_BK:
6334 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6335 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6342 arvif->u.sta.uapsd |= value;
6344 arvif->u.sta.uapsd &= ~value;
6346 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6347 WMI_STA_PS_PARAM_UAPSD,
6348 arvif->u.sta.uapsd);
6350 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6354 if (arvif->u.sta.uapsd)
6355 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6357 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6359 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6360 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6363 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6365 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6367 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6368 arvif->vdev_id, ret);
6372 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6374 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6375 arvif->vdev_id, ret);
6379 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6380 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6381 /* Only userspace can make an educated decision when to send
6382 * trigger frame. The following effectively disables u-UAPSD
6383 * autotrigger in firmware (which is enabled by default
6384 * provided the autotrigger service is available).
6388 arg.user_priority = prio;
6389 arg.service_interval = 0;
6390 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6391 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6393 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6394 arvif->bssid, &arg, 1);
6396 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6406 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6407 struct ieee80211_vif *vif, u16 ac,
6408 const struct ieee80211_tx_queue_params *params)
6410 struct ath10k *ar = hw->priv;
6411 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6412 struct wmi_wmm_params_arg *p = NULL;
6415 mutex_lock(&ar->conf_mutex);
6418 case IEEE80211_AC_VO:
6419 p = &arvif->wmm_params.ac_vo;
6421 case IEEE80211_AC_VI:
6422 p = &arvif->wmm_params.ac_vi;
6424 case IEEE80211_AC_BE:
6425 p = &arvif->wmm_params.ac_be;
6427 case IEEE80211_AC_BK:
6428 p = &arvif->wmm_params.ac_bk;
6437 p->cwmin = params->cw_min;
6438 p->cwmax = params->cw_max;
6439 p->aifs = params->aifs;
6442 * The channel time duration programmed in the HW is in absolute
6443 * microseconds, while mac80211 gives the txop in units of
6446 p->txop = params->txop * 32;
6448 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6449 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6450 &arvif->wmm_params);
6452 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6453 arvif->vdev_id, ret);
6457 /* This won't work well with multi-interface cases but it's
6458 * better than nothing.
6460 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6462 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6467 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6469 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6472 mutex_unlock(&ar->conf_mutex);
6476 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6478 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6479 struct ieee80211_vif *vif,
6480 struct ieee80211_channel *chan,
6482 enum ieee80211_roc_type type)
6484 struct ath10k *ar = hw->priv;
6485 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6486 struct wmi_start_scan_arg arg;
6490 mutex_lock(&ar->conf_mutex);
6492 spin_lock_bh(&ar->data_lock);
6493 switch (ar->scan.state) {
6494 case ATH10K_SCAN_IDLE:
6495 reinit_completion(&ar->scan.started);
6496 reinit_completion(&ar->scan.completed);
6497 reinit_completion(&ar->scan.on_channel);
6498 ar->scan.state = ATH10K_SCAN_STARTING;
6499 ar->scan.is_roc = true;
6500 ar->scan.vdev_id = arvif->vdev_id;
6501 ar->scan.roc_freq = chan->center_freq;
6502 ar->scan.roc_notify = true;
6505 case ATH10K_SCAN_STARTING:
6506 case ATH10K_SCAN_RUNNING:
6507 case ATH10K_SCAN_ABORTING:
6511 spin_unlock_bh(&ar->data_lock);
6516 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6518 memset(&arg, 0, sizeof(arg));
6519 ath10k_wmi_start_scan_init(ar, &arg);
6520 arg.vdev_id = arvif->vdev_id;
6521 arg.scan_id = ATH10K_SCAN_ID;
6523 arg.channels[0] = chan->center_freq;
6524 arg.dwell_time_active = scan_time_msec;
6525 arg.dwell_time_passive = scan_time_msec;
6526 arg.max_scan_time = scan_time_msec;
6527 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6528 if (QCA_REV_WCN3990(ar)) {
6529 arg.scan_ctrl_flags &= ~(WMI_SCAN_FILTER_PROBE_REQ |
6530 WMI_SCAN_CHAN_STAT_EVENT |
6531 WMI_SCAN_ADD_BCAST_PROBE_REQ);
6533 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6535 arg.burst_duration_ms = duration;
6537 ret = ath10k_start_scan(ar, &arg);
6539 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6540 spin_lock_bh(&ar->data_lock);
6541 ar->scan.state = ATH10K_SCAN_IDLE;
6542 spin_unlock_bh(&ar->data_lock);
6546 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6548 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6550 ret = ath10k_scan_stop(ar);
6552 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6558 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6559 msecs_to_jiffies(duration));
6563 mutex_unlock(&ar->conf_mutex);
6567 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6569 struct ath10k *ar = hw->priv;
6571 mutex_lock(&ar->conf_mutex);
6573 spin_lock_bh(&ar->data_lock);
6574 ar->scan.roc_notify = false;
6575 spin_unlock_bh(&ar->data_lock);
6577 ath10k_scan_abort(ar);
6579 mutex_unlock(&ar->conf_mutex);
6581 cancel_delayed_work_sync(&ar->scan.timeout);
6587 * Both RTS and Fragmentation threshold are interface-specific
6588 * in ath10k, but device-specific in mac80211.
6591 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6593 struct ath10k *ar = hw->priv;
6594 struct ath10k_vif *arvif;
6597 mutex_lock(&ar->conf_mutex);
6598 list_for_each_entry(arvif, &ar->arvifs, list) {
6599 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6600 arvif->vdev_id, value);
6602 ret = ath10k_mac_set_rts(arvif, value);
6604 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6605 arvif->vdev_id, ret);
6609 mutex_unlock(&ar->conf_mutex);
6614 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6616 /* Even though there's a WMI enum for fragmentation threshold no known
6617 * firmware actually implements it. Moreover it is not possible to rely
6618 * frame fragmentation to mac80211 because firmware clears the "more
6619 * fragments" bit in frame control making it impossible for remote
6620 * devices to reassemble frames.
6622 * Hence implement a dummy callback just to say fragmentation isn't
6623 * supported. This effectively prevents mac80211 from doing frame
6624 * fragmentation in software.
6629 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6630 u32 queues, bool drop)
6632 struct ath10k *ar = hw->priv;
6636 /* mac80211 doesn't care if we really xmit queued frames or not
6637 * we'll collect those frames either way if we stop/delete vdevs */
6641 mutex_lock(&ar->conf_mutex);
6643 if (ar->state == ATH10K_STATE_WEDGED)
6646 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6649 spin_lock_bh(&ar->htt.tx_lock);
6650 empty = (ar->htt.num_pending_tx == 0);
6651 spin_unlock_bh(&ar->htt.tx_lock);
6653 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6654 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6658 }), ATH10K_FLUSH_TIMEOUT_HZ);
6660 if (time_left == 0 || skip)
6661 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6662 skip, ar->state, time_left);
6665 mutex_unlock(&ar->conf_mutex);
6668 /* TODO: Implement this function properly
6669 * For now it is needed to reply to Probe Requests in IBSS mode.
6670 * Propably we need this information from FW.
6672 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6677 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6678 enum ieee80211_reconfig_type reconfig_type)
6680 struct ath10k *ar = hw->priv;
6682 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6685 mutex_lock(&ar->conf_mutex);
6687 /* If device failed to restart it will be in a different state, e.g.
6688 * ATH10K_STATE_WEDGED */
6689 if (ar->state == ATH10K_STATE_RESTARTED) {
6690 ath10k_info(ar, "device successfully recovered\n");
6691 ar->state = ATH10K_STATE_ON;
6692 ieee80211_wake_queues(ar->hw);
6695 mutex_unlock(&ar->conf_mutex);
6699 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6700 struct ieee80211_channel *channel)
6703 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6705 lockdep_assert_held(&ar->conf_mutex);
6707 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6708 (ar->rx_channel != channel))
6711 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6712 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6716 reinit_completion(&ar->bss_survey_done);
6718 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6720 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6724 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6726 ath10k_warn(ar, "bss channel survey timed out\n");
6731 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6732 struct survey_info *survey)
6734 struct ath10k *ar = hw->priv;
6735 struct ieee80211_supported_band *sband;
6736 struct survey_info *ar_survey = &ar->survey[idx];
6739 mutex_lock(&ar->conf_mutex);
6741 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
6742 if (sband && idx >= sband->n_channels) {
6743 idx -= sband->n_channels;
6748 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
6750 if (!sband || idx >= sband->n_channels) {
6755 if (!QCA_REV_WCN3990(ar))
6756 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6758 spin_lock_bh(&ar->data_lock);
6759 memcpy(survey, ar_survey, sizeof(*survey));
6760 spin_unlock_bh(&ar->data_lock);
6762 survey->channel = &sband->channels[idx];
6764 if (ar->rx_channel == survey->channel)
6765 survey->filled |= SURVEY_INFO_IN_USE;
6768 mutex_unlock(&ar->conf_mutex);
6773 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6774 enum ieee80211_band band,
6775 const struct cfg80211_bitrate_mask *mask)
6780 num_rates += hweight32(mask->control[band].legacy);
6782 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6783 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6785 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6786 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6788 return num_rates == 1;
6792 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6793 enum ieee80211_band band,
6794 const struct cfg80211_bitrate_mask *mask,
6797 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6798 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6800 u8 vht_nss_mask = 0;
6803 if (mask->control[band].legacy)
6806 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6807 if (mask->control[band].ht_mcs[i] == 0)
6809 else if (mask->control[band].ht_mcs[i] ==
6810 sband->ht_cap.mcs.rx_mask[i])
6811 ht_nss_mask |= BIT(i);
6816 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6817 if (mask->control[band].vht_mcs[i] == 0)
6819 else if (mask->control[band].vht_mcs[i] ==
6820 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6821 vht_nss_mask |= BIT(i);
6826 if (ht_nss_mask != vht_nss_mask)
6829 if (ht_nss_mask == 0)
6832 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6835 *nss = fls(ht_nss_mask);
6841 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6842 enum ieee80211_band band,
6843 const struct cfg80211_bitrate_mask *mask,
6846 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6853 if (hweight32(mask->control[band].legacy) == 1) {
6854 rate_idx = ffs(mask->control[band].legacy) - 1;
6856 hw_rate = sband->bitrates[rate_idx].hw_value;
6857 bitrate = sband->bitrates[rate_idx].bitrate;
6859 if (ath10k_mac_bitrate_is_cck(bitrate))
6860 preamble = WMI_RATE_PREAMBLE_CCK;
6862 preamble = WMI_RATE_PREAMBLE_OFDM;
6865 *rate = preamble << 6 |
6872 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6873 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6875 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6877 (ffs(mask->control[band].ht_mcs[i]) - 1);
6883 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6884 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6886 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6888 (ffs(mask->control[band].vht_mcs[i]) - 1);
6897 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6898 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6900 struct ath10k *ar = arvif->ar;
6904 lockdep_assert_held(&ar->conf_mutex);
6906 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6907 arvif->vdev_id, rate, nss, sgi);
6909 vdev_param = ar->wmi.vdev_param->fixed_rate;
6910 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6912 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6917 vdev_param = ar->wmi.vdev_param->nss;
6918 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6920 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6924 vdev_param = ar->wmi.vdev_param->sgi;
6925 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6927 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6931 vdev_param = ar->wmi.vdev_param->ldpc;
6932 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6934 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6942 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6943 enum ieee80211_band band,
6944 const struct cfg80211_bitrate_mask *mask)
6949 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6950 * to express all VHT MCS rate masks. Effectively only the following
6951 * ranges can be used: none, 0-7, 0-8 and 0-9.
6953 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6954 vht_mcs = mask->control[band].vht_mcs[i];
6963 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6971 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6972 struct ieee80211_sta *sta)
6974 struct ath10k_vif *arvif = data;
6975 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6976 struct ath10k *ar = arvif->ar;
6978 if (arsta->arvif != arvif)
6981 spin_lock_bh(&ar->data_lock);
6982 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6983 spin_unlock_bh(&ar->data_lock);
6985 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6988 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6989 struct ieee80211_vif *vif,
6990 const struct cfg80211_bitrate_mask *mask)
6992 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6993 struct cfg80211_chan_def def;
6994 struct ath10k *ar = arvif->ar;
6995 enum ieee80211_band band;
6996 const u8 *ht_mcs_mask;
6997 const u16 *vht_mcs_mask;
7005 if (ath10k_mac_vif_chan(vif, &def))
7008 band = def.chan->band;
7009 ht_mcs_mask = mask->control[band].ht_mcs;
7010 vht_mcs_mask = mask->control[band].vht_mcs;
7011 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7013 sgi = mask->control[band].gi;
7014 if (sgi == NL80211_TXRATE_FORCE_LGI)
7017 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7018 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7021 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7022 arvif->vdev_id, ret);
7025 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7027 rate = WMI_FIXED_RATE_NONE;
7030 rate = WMI_FIXED_RATE_NONE;
7031 nss = min(ar->num_rf_chains,
7032 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7033 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7035 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7038 mutex_lock(&ar->conf_mutex);
7040 arvif->bitrate_mask = *mask;
7041 ieee80211_iterate_stations_atomic(ar->hw,
7042 ath10k_mac_set_bitrate_mask_iter,
7045 mutex_unlock(&ar->conf_mutex);
7048 mutex_lock(&ar->conf_mutex);
7050 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7052 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7053 arvif->vdev_id, ret);
7058 mutex_unlock(&ar->conf_mutex);
7063 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7064 struct ieee80211_vif *vif,
7065 struct ieee80211_sta *sta,
7068 struct ath10k *ar = hw->priv;
7069 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7070 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7071 struct ath10k_peer *peer;
7074 spin_lock_bh(&ar->data_lock);
7076 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7078 spin_unlock_bh(&ar->data_lock);
7079 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7080 sta->addr, arvif->vdev_id);
7084 ath10k_dbg(ar, ATH10K_DBG_MAC,
7085 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7086 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7089 if (changed & IEEE80211_RC_BW_CHANGED) {
7090 bw = WMI_PEER_CHWIDTH_20MHZ;
7092 switch (sta->bandwidth) {
7093 case IEEE80211_STA_RX_BW_20:
7094 bw = WMI_PEER_CHWIDTH_20MHZ;
7096 case IEEE80211_STA_RX_BW_40:
7097 bw = WMI_PEER_CHWIDTH_40MHZ;
7099 case IEEE80211_STA_RX_BW_80:
7100 bw = WMI_PEER_CHWIDTH_80MHZ;
7102 case IEEE80211_STA_RX_BW_160:
7103 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7104 sta->bandwidth, sta->addr);
7105 bw = WMI_PEER_CHWIDTH_20MHZ;
7112 if (changed & IEEE80211_RC_NSS_CHANGED)
7113 arsta->nss = sta->rx_nss;
7115 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7116 smps = WMI_PEER_SMPS_PS_NONE;
7118 switch (sta->smps_mode) {
7119 case IEEE80211_SMPS_AUTOMATIC:
7120 case IEEE80211_SMPS_OFF:
7121 smps = WMI_PEER_SMPS_PS_NONE;
7123 case IEEE80211_SMPS_STATIC:
7124 smps = WMI_PEER_SMPS_STATIC;
7126 case IEEE80211_SMPS_DYNAMIC:
7127 smps = WMI_PEER_SMPS_DYNAMIC;
7129 case IEEE80211_SMPS_NUM_MODES:
7130 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7131 sta->smps_mode, sta->addr);
7132 smps = WMI_PEER_SMPS_PS_NONE;
7139 arsta->changed |= changed;
7141 spin_unlock_bh(&ar->data_lock);
7143 ieee80211_queue_work(hw, &arsta->update_wk);
7146 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7149 * FIXME: Return 0 for time being. Need to figure out whether FW
7150 * has the API to fetch 64-bit local TSF
7156 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7159 struct ath10k *ar = hw->priv;
7160 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7161 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
7166 * Given tsf argument is entire TSF value, but firmware accepts
7167 * only TSF offset to current TSF.
7169 * get_tsf function is used to get offset value, however since
7170 * ath10k_get_tsf is not implemented properly, it will return 0 always.
7171 * Luckily all the caller functions to set_tsf, as of now, also rely on
7172 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
7173 * final tsf offset value to firmware will be arithmetically correct.
7175 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
7176 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7177 vdev_param, tsf_offset);
7178 if (ret && ret != -EOPNOTSUPP)
7179 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
7182 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7183 struct ieee80211_vif *vif,
7184 struct ieee80211_ampdu_params *params)
7186 struct ath10k *ar = hw->priv;
7187 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7188 struct ieee80211_sta *sta = params->sta;
7189 enum ieee80211_ampdu_mlme_action action = params->action;
7190 u16 tid = params->tid;
7192 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7193 arvif->vdev_id, sta->addr, tid, action);
7196 case IEEE80211_AMPDU_RX_START:
7197 case IEEE80211_AMPDU_RX_STOP:
7198 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7199 * creation/removal. Do we need to verify this?
7202 case IEEE80211_AMPDU_TX_START:
7203 case IEEE80211_AMPDU_TX_STOP_CONT:
7204 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7205 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7206 case IEEE80211_AMPDU_TX_OPERATIONAL:
7207 /* Firmware offloads Tx aggregation entirely so deny mac80211
7208 * Tx aggregation requests.
7217 ath10k_mac_update_rx_channel(struct ath10k *ar,
7218 struct ieee80211_chanctx_conf *ctx,
7219 struct ieee80211_vif_chanctx_switch *vifs,
7222 struct cfg80211_chan_def *def = NULL;
7224 /* Both locks are required because ar->rx_channel is modified. This
7225 * allows readers to hold either lock.
7227 lockdep_assert_held(&ar->conf_mutex);
7228 lockdep_assert_held(&ar->data_lock);
7230 WARN_ON(ctx && vifs);
7231 WARN_ON(vifs && !n_vifs);
7233 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7234 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7235 * ppdu on Rx may reduce performance on low-end systems. It should be
7236 * possible to make tables/hashmaps to speed the lookup up (be vary of
7237 * cpu data cache lines though regarding sizes) but to keep the initial
7238 * implementation simple and less intrusive fallback to the slow lookup
7239 * only for multi-channel cases. Single-channel cases will remain to
7240 * use the old channel derival and thus performance should not be
7244 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7245 ieee80211_iter_chan_contexts_atomic(ar->hw,
7246 ath10k_mac_get_any_chandef_iter,
7250 def = &vifs[0].new_ctx->def;
7252 ar->rx_channel = def->chan;
7253 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7254 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7255 /* During driver restart due to firmware assert, since mac80211
7256 * already has valid channel context for given radio, channel
7257 * context iteration return num_chanctx > 0. So fix rx_channel
7258 * when restart is in progress.
7260 ar->rx_channel = ctx->def.chan;
7262 ar->rx_channel = NULL;
7268 ath10k_mac_update_vif_chan(struct ath10k *ar,
7269 struct ieee80211_vif_chanctx_switch *vifs,
7272 struct ath10k_vif *arvif;
7276 lockdep_assert_held(&ar->conf_mutex);
7278 /* First stop monitor interface. Some FW versions crash if there's a
7279 * lone monitor interface.
7281 if (ar->monitor_started)
7282 ath10k_monitor_stop(ar);
7284 for (i = 0; i < n_vifs; i++) {
7285 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7287 ath10k_dbg(ar, ATH10K_DBG_MAC,
7288 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7290 vifs[i].old_ctx->def.chan->center_freq,
7291 vifs[i].new_ctx->def.chan->center_freq,
7292 vifs[i].old_ctx->def.width,
7293 vifs[i].new_ctx->def.width);
7295 if (WARN_ON(!arvif->is_started))
7298 if (WARN_ON(!arvif->is_up))
7300 if (QCA_REV_WCN3990(ar)) {
7301 /* In the case of wcn3990 WLAN module we send
7302 * vdev restart only, no need to send vdev down.
7305 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7308 "failed to restart vdev %d: %d\n",
7309 arvif->vdev_id, ret);
7313 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7315 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7316 arvif->vdev_id, ret);
7322 /* All relevant vdevs are downed and associated channel resources
7323 * should be available for the channel switch now.
7326 spin_lock_bh(&ar->data_lock);
7327 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7328 spin_unlock_bh(&ar->data_lock);
7330 for (i = 0; i < n_vifs; i++) {
7331 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7333 if (WARN_ON(!arvif->is_started))
7336 if (WARN_ON(!arvif->is_up))
7339 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7341 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7344 ret = ath10k_mac_setup_prb_tmpl(arvif);
7346 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7349 if (!QCA_REV_WCN3990(ar)) {
7350 /* In case of other than wcn3990 WLAN module we
7351 * send vdev down and vdev restart to the firmware.
7354 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7356 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7357 arvif->vdev_id, ret);
7362 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7365 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7366 arvif->vdev_id, ret);
7371 ath10k_monitor_recalc(ar);
7375 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7376 struct ieee80211_chanctx_conf *ctx)
7378 struct ath10k *ar = hw->priv;
7380 ath10k_dbg(ar, ATH10K_DBG_MAC,
7381 "mac chanctx add freq %hu width %d ptr %pK\n",
7382 ctx->def.chan->center_freq, ctx->def.width, ctx);
7384 mutex_lock(&ar->conf_mutex);
7386 spin_lock_bh(&ar->data_lock);
7387 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7388 spin_unlock_bh(&ar->data_lock);
7390 ath10k_recalc_radar_detection(ar);
7391 ath10k_monitor_recalc(ar);
7393 mutex_unlock(&ar->conf_mutex);
7399 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7400 struct ieee80211_chanctx_conf *ctx)
7402 struct ath10k *ar = hw->priv;
7404 ath10k_dbg(ar, ATH10K_DBG_MAC,
7405 "mac chanctx remove freq %hu width %d ptr %pK\n",
7406 ctx->def.chan->center_freq, ctx->def.width, ctx);
7408 mutex_lock(&ar->conf_mutex);
7410 spin_lock_bh(&ar->data_lock);
7411 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7412 spin_unlock_bh(&ar->data_lock);
7414 ath10k_recalc_radar_detection(ar);
7415 ath10k_monitor_recalc(ar);
7417 mutex_unlock(&ar->conf_mutex);
7420 struct ath10k_mac_change_chanctx_arg {
7421 struct ieee80211_chanctx_conf *ctx;
7422 struct ieee80211_vif_chanctx_switch *vifs;
7428 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7429 struct ieee80211_vif *vif)
7431 struct ath10k_mac_change_chanctx_arg *arg = data;
7433 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7440 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7441 struct ieee80211_vif *vif)
7443 struct ath10k_mac_change_chanctx_arg *arg = data;
7444 struct ieee80211_chanctx_conf *ctx;
7446 ctx = rcu_access_pointer(vif->chanctx_conf);
7447 if (ctx != arg->ctx)
7450 if (WARN_ON(arg->next_vif == arg->n_vifs))
7453 arg->vifs[arg->next_vif].vif = vif;
7454 arg->vifs[arg->next_vif].old_ctx = ctx;
7455 arg->vifs[arg->next_vif].new_ctx = ctx;
7460 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7461 struct ieee80211_chanctx_conf *ctx,
7464 struct ath10k *ar = hw->priv;
7465 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7467 mutex_lock(&ar->conf_mutex);
7469 ath10k_dbg(ar, ATH10K_DBG_MAC,
7470 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7471 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7473 /* This shouldn't really happen because channel switching should use
7474 * switch_vif_chanctx().
7476 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7479 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7480 ieee80211_iterate_active_interfaces_atomic(
7482 IEEE80211_IFACE_ITER_NORMAL,
7483 ath10k_mac_change_chanctx_cnt_iter,
7485 if (arg.n_vifs == 0)
7488 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7493 ieee80211_iterate_active_interfaces_atomic(
7495 IEEE80211_IFACE_ITER_NORMAL,
7496 ath10k_mac_change_chanctx_fill_iter,
7498 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7503 ath10k_recalc_radar_detection(ar);
7505 /* FIXME: How to configure Rx chains properly? */
7507 /* No other actions are actually necessary. Firmware maintains channel
7508 * definitions per vdev internally and there's no host-side channel
7509 * context abstraction to configure, e.g. channel width.
7513 mutex_unlock(&ar->conf_mutex);
7517 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7518 struct ieee80211_vif *vif,
7519 struct ieee80211_chanctx_conf *ctx)
7521 struct ath10k *ar = hw->priv;
7522 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7525 mutex_lock(&ar->conf_mutex);
7527 ath10k_dbg(ar, ATH10K_DBG_MAC,
7528 "mac chanctx assign ptr %pK vdev_id %i\n",
7529 ctx, arvif->vdev_id);
7531 if (WARN_ON(arvif->is_started)) {
7532 mutex_unlock(&ar->conf_mutex);
7536 ret = ath10k_vdev_start(arvif, &ctx->def);
7538 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7539 arvif->vdev_id, vif->addr,
7540 ctx->def.chan->center_freq, ret);
7544 arvif->is_started = true;
7546 ret = ath10k_mac_vif_setup_ps(arvif);
7548 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7549 arvif->vdev_id, ret);
7553 if (vif->type == NL80211_IFTYPE_MONITOR) {
7554 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7556 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7557 arvif->vdev_id, ret);
7561 arvif->is_up = true;
7564 if (ath10k_mac_can_set_cts_prot(arvif)) {
7565 ret = ath10k_mac_set_cts_prot(arvif);
7567 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7568 arvif->vdev_id, ret);
7571 mutex_unlock(&ar->conf_mutex);
7575 ath10k_vdev_stop(arvif);
7576 arvif->is_started = false;
7577 ath10k_mac_vif_setup_ps(arvif);
7580 mutex_unlock(&ar->conf_mutex);
7585 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7586 struct ieee80211_vif *vif,
7587 struct ieee80211_chanctx_conf *ctx)
7589 struct ath10k *ar = hw->priv;
7590 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7593 mutex_lock(&ar->conf_mutex);
7595 ath10k_dbg(ar, ATH10K_DBG_MAC,
7596 "mac chanctx unassign ptr %pK vdev_id %i\n",
7597 ctx, arvif->vdev_id);
7599 WARN_ON(!arvif->is_started);
7600 if (vif->type == NL80211_IFTYPE_MONITOR ||
7601 (vif->type == NL80211_IFTYPE_STATION &&
7602 ar->sta_state < IEEE80211_STA_ASSOC)) {
7603 WARN_ON(!arvif->is_up);
7605 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7607 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7608 arvif->vdev_id, ret);
7610 arvif->is_up = false;
7613 ret = ath10k_vdev_stop(arvif);
7615 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7616 arvif->vdev_id, ret);
7618 ar->sta_state = IEEE80211_STA_NOTEXIST;
7619 arvif->is_started = false;
7621 mutex_unlock(&ar->conf_mutex);
7625 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7626 struct ieee80211_vif_chanctx_switch *vifs,
7628 enum ieee80211_chanctx_switch_mode mode)
7630 struct ath10k *ar = hw->priv;
7632 mutex_lock(&ar->conf_mutex);
7634 ath10k_dbg(ar, ATH10K_DBG_MAC,
7635 "mac chanctx switch n_vifs %d mode %d\n",
7637 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7639 mutex_unlock(&ar->conf_mutex);
7643 static const struct ieee80211_ops ath10k_ops = {
7644 .tx = ath10k_mac_op_tx,
7645 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7646 .start = ath10k_start,
7647 .stop = ath10k_stop,
7648 .config = ath10k_config,
7649 .add_interface = ath10k_add_interface,
7650 .change_interface = ath10k_change_interface,
7651 .remove_interface = ath10k_remove_interface,
7652 .configure_filter = ath10k_configure_filter,
7653 .bss_info_changed = ath10k_bss_info_changed,
7654 .hw_scan = ath10k_hw_scan,
7655 .cancel_hw_scan = ath10k_cancel_hw_scan,
7656 .set_rekey_data = ath10k_set_rekey_data,
7657 .set_key = ath10k_set_key,
7658 .set_default_unicast_key = ath10k_set_default_unicast_key,
7659 .sta_state = ath10k_sta_state,
7660 .conf_tx = ath10k_conf_tx,
7661 .remain_on_channel = ath10k_remain_on_channel,
7662 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7663 .set_rts_threshold = ath10k_set_rts_threshold,
7664 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7665 .flush = ath10k_flush,
7666 .tx_last_beacon = ath10k_tx_last_beacon,
7667 .set_antenna = ath10k_set_antenna,
7668 .get_antenna = ath10k_get_antenna,
7669 .reconfig_complete = ath10k_reconfig_complete,
7670 .get_survey = ath10k_get_survey,
7671 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7672 .sta_rc_update = ath10k_sta_rc_update,
7673 .get_tsf = ath10k_get_tsf,
7674 .set_tsf = ath10k_set_tsf,
7675 .ampdu_action = ath10k_ampdu_action,
7676 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7677 .get_et_stats = ath10k_debug_get_et_stats,
7678 .get_et_strings = ath10k_debug_get_et_strings,
7679 .add_chanctx = ath10k_mac_op_add_chanctx,
7680 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7681 .change_chanctx = ath10k_mac_op_change_chanctx,
7682 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7683 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7684 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7686 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7689 .suspend = ath10k_wow_op_suspend,
7690 .resume = ath10k_wow_op_resume,
7691 .set_wakeup = ath10k_wow_op_set_wakeup,
7693 #ifdef CONFIG_MAC80211_DEBUGFS
7694 .sta_add_debugfs = ath10k_sta_add_debugfs,
7695 .sta_statistics = ath10k_sta_statistics,
7699 #define CHAN2G(_channel, _freq, _flags) { \
7700 .band = IEEE80211_BAND_2GHZ, \
7701 .hw_value = (_channel), \
7702 .center_freq = (_freq), \
7703 .flags = (_flags), \
7704 .max_antenna_gain = 0, \
7708 #define CHAN5G(_channel, _freq, _flags) { \
7709 .band = IEEE80211_BAND_5GHZ, \
7710 .hw_value = (_channel), \
7711 .center_freq = (_freq), \
7712 .flags = (_flags), \
7713 .max_antenna_gain = 0, \
7717 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7727 CHAN2G(10, 2457, 0),
7728 CHAN2G(11, 2462, 0),
7729 CHAN2G(12, 2467, 0),
7730 CHAN2G(13, 2472, 0),
7731 CHAN2G(14, 2484, 0),
7734 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7735 CHAN5G(36, 5180, 0),
7736 CHAN5G(40, 5200, 0),
7737 CHAN5G(44, 5220, 0),
7738 CHAN5G(48, 5240, 0),
7739 CHAN5G(52, 5260, 0),
7740 CHAN5G(56, 5280, 0),
7741 CHAN5G(60, 5300, 0),
7742 CHAN5G(64, 5320, 0),
7743 CHAN5G(100, 5500, 0),
7744 CHAN5G(104, 5520, 0),
7745 CHAN5G(108, 5540, 0),
7746 CHAN5G(112, 5560, 0),
7747 CHAN5G(116, 5580, 0),
7748 CHAN5G(120, 5600, 0),
7749 CHAN5G(124, 5620, 0),
7750 CHAN5G(128, 5640, 0),
7751 CHAN5G(132, 5660, 0),
7752 CHAN5G(136, 5680, 0),
7753 CHAN5G(140, 5700, 0),
7754 CHAN5G(144, 5720, 0),
7755 CHAN5G(149, 5745, 0),
7756 CHAN5G(153, 5765, 0),
7757 CHAN5G(157, 5785, 0),
7758 CHAN5G(161, 5805, 0),
7759 CHAN5G(165, 5825, 0),
7762 struct ath10k *ath10k_mac_create(size_t priv_size)
7764 struct ieee80211_hw *hw;
7765 struct ieee80211_ops *ops;
7768 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7772 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7785 void ath10k_mac_destroy(struct ath10k *ar)
7787 struct ieee80211_ops *ops = ar->ops;
7789 ieee80211_free_hw(ar->hw);
7793 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7796 .types = BIT(NL80211_IFTYPE_STATION)
7797 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7801 .types = BIT(NL80211_IFTYPE_P2P_GO)
7805 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7809 .types = BIT(NL80211_IFTYPE_AP)
7810 #ifdef CONFIG_MAC80211_MESH
7811 | BIT(NL80211_IFTYPE_MESH_POINT)
7816 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7819 .types = BIT(NL80211_IFTYPE_AP)
7820 #ifdef CONFIG_MAC80211_MESH
7821 | BIT(NL80211_IFTYPE_MESH_POINT)
7826 .types = BIT(NL80211_IFTYPE_STATION)
7830 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7832 .limits = ath10k_if_limits,
7833 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7834 .max_interfaces = 8,
7835 .num_different_channels = 1,
7836 .beacon_int_infra_match = true,
7840 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7842 .limits = ath10k_10x_if_limits,
7843 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7844 .max_interfaces = 8,
7845 .num_different_channels = 1,
7846 .beacon_int_infra_match = true,
7847 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7848 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7849 BIT(NL80211_CHAN_WIDTH_20) |
7850 BIT(NL80211_CHAN_WIDTH_40) |
7851 BIT(NL80211_CHAN_WIDTH_80),
7856 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7859 .types = BIT(NL80211_IFTYPE_STATION),
7863 .types = BIT(NL80211_IFTYPE_AP) |
7864 #ifdef CONFIG_MAC80211_MESH
7865 BIT(NL80211_IFTYPE_MESH_POINT) |
7867 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7868 BIT(NL80211_IFTYPE_P2P_GO),
7872 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7876 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7879 .types = BIT(NL80211_IFTYPE_STATION),
7883 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7887 .types = BIT(NL80211_IFTYPE_AP) |
7888 #ifdef CONFIG_MAC80211_MESH
7889 BIT(NL80211_IFTYPE_MESH_POINT) |
7891 BIT(NL80211_IFTYPE_P2P_GO),
7895 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7899 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7902 .types = BIT(NL80211_IFTYPE_STATION),
7906 .types = BIT(NL80211_IFTYPE_ADHOC),
7910 /* FIXME: This is not thouroughly tested. These combinations may over- or
7911 * underestimate hw/fw capabilities.
7913 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7915 .limits = ath10k_tlv_if_limit,
7916 .num_different_channels = 1,
7917 .max_interfaces = 4,
7918 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7921 .limits = ath10k_tlv_if_limit_ibss,
7922 .num_different_channels = 1,
7923 .max_interfaces = 2,
7924 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7928 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7930 .limits = ath10k_tlv_if_limit,
7931 .num_different_channels = 1,
7932 .max_interfaces = 4,
7933 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7936 .limits = ath10k_tlv_qcs_if_limit,
7937 .num_different_channels = 2,
7938 .max_interfaces = 4,
7939 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7942 .limits = ath10k_tlv_if_limit_ibss,
7943 .num_different_channels = 1,
7944 .max_interfaces = 2,
7945 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7949 static const struct ieee80211_iface_limit ath10k_wcn3990_if_limit[] = {
7952 .types = BIT(NL80211_IFTYPE_STATION),
7956 .types = BIT(NL80211_IFTYPE_AP) |
7957 #ifdef CONFIG_MAC80211_MESH
7958 BIT(NL80211_IFTYPE_MESH_POINT) |
7960 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7961 BIT(NL80211_IFTYPE_P2P_GO),
7965 static const struct ieee80211_iface_limit ath10k_wcn3990_qcs_if_limit[] = {
7968 .types = BIT(NL80211_IFTYPE_STATION),
7972 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7976 .types = BIT(NL80211_IFTYPE_AP) |
7977 #ifdef CONFIG_MAC80211_MESH
7978 BIT(NL80211_IFTYPE_MESH_POINT) |
7980 BIT(NL80211_IFTYPE_P2P_GO),
7984 static const struct ieee80211_iface_limit ath10k_wcn3990_if_limit_ibss[] = {
7987 .types = BIT(NL80211_IFTYPE_STATION),
7991 .types = BIT(NL80211_IFTYPE_ADHOC),
7995 static struct ieee80211_iface_combination ath10k_wcn3990_qcs_if_comb[] = {
7997 .limits = ath10k_wcn3990_if_limit,
7998 .num_different_channels = 1,
7999 .max_interfaces = 4,
8000 .n_limits = ARRAY_SIZE(ath10k_wcn3990_if_limit),
8001 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8002 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8003 BIT(NL80211_CHAN_WIDTH_20) |
8004 BIT(NL80211_CHAN_WIDTH_40) |
8005 BIT(NL80211_CHAN_WIDTH_80),
8009 .limits = ath10k_wcn3990_qcs_if_limit,
8010 .num_different_channels = 2,
8011 .max_interfaces = 4,
8012 .n_limits = ARRAY_SIZE(ath10k_wcn3990_qcs_if_limit),
8015 .limits = ath10k_wcn3990_if_limit_ibss,
8016 .num_different_channels = 1,
8017 .max_interfaces = 2,
8018 .n_limits = ARRAY_SIZE(ath10k_wcn3990_if_limit_ibss),
8019 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8020 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8021 BIT(NL80211_CHAN_WIDTH_20) |
8022 BIT(NL80211_CHAN_WIDTH_40) |
8023 BIT(NL80211_CHAN_WIDTH_80),
8028 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8031 .types = BIT(NL80211_IFTYPE_STATION),
8035 .types = BIT(NL80211_IFTYPE_AP)
8036 #ifdef CONFIG_MAC80211_MESH
8037 | BIT(NL80211_IFTYPE_MESH_POINT)
8042 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8044 .limits = ath10k_10_4_if_limits,
8045 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8046 .max_interfaces = 16,
8047 .num_different_channels = 1,
8048 .beacon_int_infra_match = true,
8049 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8050 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8051 BIT(NL80211_CHAN_WIDTH_20) |
8052 BIT(NL80211_CHAN_WIDTH_40) |
8053 BIT(NL80211_CHAN_WIDTH_80),
8058 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8059 struct ieee80211_vif *vif)
8061 struct ath10k_vif_iter *arvif_iter = data;
8062 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
8064 if (arvif->vdev_id == arvif_iter->vdev_id)
8065 arvif_iter->arvif = arvif;
8068 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8070 struct ath10k_vif_iter arvif_iter;
8073 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8074 arvif_iter.vdev_id = vdev_id;
8076 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8077 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8079 ath10k_get_arvif_iter,
8081 if (!arvif_iter.arvif) {
8082 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8086 return arvif_iter.arvif;
8089 int ath10k_mac_register(struct ath10k *ar)
8091 static const u32 cipher_suites[] = {
8092 WLAN_CIPHER_SUITE_WEP40,
8093 WLAN_CIPHER_SUITE_WEP104,
8094 WLAN_CIPHER_SUITE_TKIP,
8095 WLAN_CIPHER_SUITE_CCMP,
8096 WLAN_CIPHER_SUITE_AES_CMAC,
8098 struct ieee80211_supported_band *band;
8102 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8104 SET_IEEE80211_DEV(ar->hw, ar->dev);
8106 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8107 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8110 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8111 channels = kmemdup(ath10k_2ghz_channels,
8112 sizeof(ath10k_2ghz_channels),
8119 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
8120 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8121 band->channels = channels;
8123 if (ar->hw_params.cck_rate_map_rev2) {
8124 band->n_bitrates = ath10k_g_rates_rev2_size;
8125 band->bitrates = ath10k_g_rates_rev2;
8127 band->n_bitrates = ath10k_g_rates_size;
8128 band->bitrates = ath10k_g_rates;
8131 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
8134 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8135 channels = kmemdup(ath10k_5ghz_channels,
8136 sizeof(ath10k_5ghz_channels),
8143 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
8144 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8145 band->channels = channels;
8146 band->n_bitrates = ath10k_a_rates_size;
8147 band->bitrates = ath10k_a_rates;
8148 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
8151 ath10k_mac_setup_ht_vht_cap(ar);
8153 ar->hw->wiphy->interface_modes =
8154 BIT(NL80211_IFTYPE_STATION) |
8155 BIT(NL80211_IFTYPE_AP) |
8156 BIT(NL80211_IFTYPE_MESH_POINT);
8158 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8159 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8161 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8162 ar->hw->wiphy->interface_modes |=
8163 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8164 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8165 BIT(NL80211_IFTYPE_P2P_GO);
8167 if (QCA_REV_WCN3990(ar))
8168 ar->hw->wiphy->interface_modes &=
8169 ~BIT(NL80211_IFTYPE_P2P_DEVICE);
8171 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8172 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8173 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8174 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8175 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8176 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8177 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8178 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8179 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8180 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8181 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8182 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8183 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8184 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8186 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8187 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8189 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8190 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8192 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8193 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8195 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8196 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8197 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8200 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8201 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8203 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8204 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8205 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8207 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8209 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8210 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8212 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8213 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8214 * correct Probe Responses. This is more of a hack advert..
8216 ar->hw->wiphy->probe_resp_offload |=
8217 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8218 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8219 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8222 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
8223 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8225 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8226 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8227 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8229 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8230 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8231 NL80211_FEATURE_AP_SCAN;
8233 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8235 ret = ath10k_wow_init(ar);
8237 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8241 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8244 * on LL hardware queues are managed entirely by the FW
8245 * so we only advertise to mac we can do the queues thing
8247 ar->hw->queues = IEEE80211_MAX_QUEUES;
8249 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8250 * something that vdev_ids can't reach so that we don't stop the queue
8253 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8255 switch (ar->running_fw->fw_file.wmi_op_version) {
8256 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8257 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8258 ar->hw->wiphy->n_iface_combinations =
8259 ARRAY_SIZE(ath10k_if_comb);
8260 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8262 case ATH10K_FW_WMI_OP_VERSION_TLV:
8263 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8264 if (QCA_REV_WCN3990(ar)) {
8265 ar->hw->wiphy->iface_combinations =
8266 ath10k_wcn3990_qcs_if_comb;
8267 ar->hw->wiphy->n_iface_combinations =
8268 ARRAY_SIZE(ath10k_wcn3990_qcs_if_comb);
8271 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8272 ar->hw->wiphy->iface_combinations =
8273 ath10k_tlv_qcs_if_comb;
8274 ar->hw->wiphy->n_iface_combinations =
8275 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8277 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8278 ar->hw->wiphy->n_iface_combinations =
8279 ARRAY_SIZE(ath10k_tlv_if_comb);
8282 case ATH10K_FW_WMI_OP_VERSION_10_1:
8283 case ATH10K_FW_WMI_OP_VERSION_10_2:
8284 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8285 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8286 ar->hw->wiphy->n_iface_combinations =
8287 ARRAY_SIZE(ath10k_10x_if_comb);
8289 case ATH10K_FW_WMI_OP_VERSION_10_4:
8290 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8291 ar->hw->wiphy->n_iface_combinations =
8292 ARRAY_SIZE(ath10k_10_4_if_comb);
8294 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8295 case ATH10K_FW_WMI_OP_VERSION_MAX:
8301 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8302 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8304 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8305 /* Init ath dfs pattern detector */
8306 ar->ath_common.debug_mask = ATH_DBG_DFS;
8307 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8310 if (!ar->dfs_detector)
8311 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8314 /* Current wake_tx_queue implementation imposes a significant
8315 * performance penalty in some setups. The tx scheduling code needs
8316 * more work anyway so disable the wake_tx_queue unless firmware
8317 * supports the pull-push mechanism.
8319 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8320 ar->running_fw->fw_file.fw_features))
8321 ar->ops->wake_tx_queue = NULL;
8323 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8324 ath10k_reg_notifier);
8326 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8327 goto err_dfs_detector_exit;
8330 ar->hw->wiphy->cipher_suites = cipher_suites;
8331 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8333 ret = ieee80211_register_hw(ar->hw);
8335 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8336 goto err_dfs_detector_exit;
8339 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8340 ret = regulatory_hint(ar->hw->wiphy,
8341 ar->ath_common.regulatory.alpha2);
8343 goto err_unregister;
8349 ieee80211_unregister_hw(ar->hw);
8351 err_dfs_detector_exit:
8352 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8353 ar->dfs_detector->exit(ar->dfs_detector);
8356 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
8357 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
8359 SET_IEEE80211_DEV(ar->hw, NULL);
8363 void ath10k_mac_unregister(struct ath10k *ar)
8365 ath10k_wow_deinit(ar);
8366 ieee80211_unregister_hw(ar->hw);
8368 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8369 ar->dfs_detector->exit(ar->dfs_detector);
8371 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
8372 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
8374 SET_IEEE80211_DEV(ar->hw, NULL);