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 spin_lock_bh(&ar->data_lock);
5025 list_add(&arvif->list, &ar->arvifs);
5026 spin_unlock_bh(&ar->data_lock);
5028 /* It makes no sense to have firmware do keepalives. mac80211 already
5029 * takes care of this with idle connection polling.
5031 ret = ath10k_mac_vif_disable_keepalive(arvif);
5033 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
5034 arvif->vdev_id, ret);
5035 goto err_vdev_delete;
5038 arvif->def_wep_key_idx = -1;
5040 vdev_param = ar->wmi.vdev_param->tx_encap_type;
5041 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5042 ATH10K_HW_TXRX_NATIVE_WIFI);
5043 /* 10.X firmware does not support this VDEV parameter. Do not warn */
5044 if (ret && ret != -EOPNOTSUPP) {
5045 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
5046 arvif->vdev_id, ret);
5047 goto err_vdev_delete;
5050 /* Configuring number of spatial stream for monitor interface is causing
5051 * target assert in qca9888 and qca6174.
5053 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5054 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5056 vdev_param = ar->wmi.vdev_param->nss;
5057 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5060 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5061 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5063 goto err_vdev_delete;
5067 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5068 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5069 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5070 vif->addr, WMI_PEER_TYPE_DEFAULT);
5072 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5073 arvif->vdev_id, ret);
5074 goto err_vdev_delete;
5077 spin_lock_bh(&ar->data_lock);
5079 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5081 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5082 vif->addr, arvif->vdev_id);
5083 spin_unlock_bh(&ar->data_lock);
5085 goto err_peer_delete;
5088 arvif->peer_id = find_first_bit(peer->peer_ids,
5089 ATH10K_MAX_NUM_PEER_IDS);
5091 spin_unlock_bh(&ar->data_lock);
5093 arvif->peer_id = HTT_INVALID_PEERID;
5096 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5097 ret = ath10k_mac_set_kickout(arvif);
5099 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5100 arvif->vdev_id, ret);
5101 goto err_peer_delete;
5105 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5106 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5107 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5108 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5111 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5112 arvif->vdev_id, ret);
5113 goto err_peer_delete;
5116 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5118 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5119 arvif->vdev_id, ret);
5120 goto err_peer_delete;
5123 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5125 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5126 arvif->vdev_id, ret);
5127 goto err_peer_delete;
5131 ret = ath10k_mac_set_txbf_conf(arvif);
5133 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5134 arvif->vdev_id, ret);
5135 goto err_peer_delete;
5138 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5140 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5141 arvif->vdev_id, ret);
5142 goto err_peer_delete;
5145 arvif->txpower = vif->bss_conf.txpower;
5146 ret = ath10k_mac_txpower_recalc(ar);
5148 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5149 goto err_peer_delete;
5152 if (vif->type == NL80211_IFTYPE_MONITOR) {
5153 ar->monitor_arvif = arvif;
5154 ret = ath10k_monitor_recalc(ar);
5156 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5157 goto err_peer_delete;
5161 spin_lock_bh(&ar->htt.tx_lock);
5163 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5164 spin_unlock_bh(&ar->htt.tx_lock);
5166 mutex_unlock(&ar->conf_mutex);
5170 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5171 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5172 ath10k_peer_delete(ar, arvif->vdev_id, vif->addr);
5175 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5176 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5177 spin_lock_bh(&ar->data_lock);
5178 list_del(&arvif->list);
5179 spin_unlock_bh(&ar->data_lock);
5182 if (arvif->beacon_buf) {
5183 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5184 arvif->beacon_buf, arvif->beacon_paddr);
5185 arvif->beacon_buf = NULL;
5188 mutex_unlock(&ar->conf_mutex);
5193 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5197 for (i = 0; i < BITS_PER_LONG; i++)
5198 ath10k_mac_vif_tx_unlock(arvif, i);
5201 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5202 struct ieee80211_vif *vif)
5204 struct ath10k *ar = hw->priv;
5205 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5206 struct ath10k_peer *peer;
5207 unsigned long time_left;
5211 cancel_work_sync(&arvif->ap_csa_work);
5212 cancel_delayed_work_sync(&arvif->connection_loss_work);
5214 mutex_lock(&ar->conf_mutex);
5216 spin_lock_bh(&ar->data_lock);
5217 ath10k_mac_vif_beacon_cleanup(arvif);
5218 spin_unlock_bh(&ar->data_lock);
5220 ret = ath10k_spectral_vif_stop(arvif);
5222 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5223 arvif->vdev_id, ret);
5225 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5226 spin_lock_bh(&ar->data_lock);
5227 list_del(&arvif->list);
5228 spin_unlock_bh(&ar->data_lock);
5230 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5231 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5232 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
5235 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5236 arvif->vdev_id, ret);
5238 kfree(arvif->u.ap.noa_data);
5241 if ((arvif->vdev_type == WMI_VDEV_TYPE_STA) && QCA_REV_WCN3990(ar))
5242 ath10k_wmi_csa_offload(ar, arvif->vdev_id, false);
5244 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5247 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5249 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5250 arvif->vdev_id, ret);
5252 if (QCA_REV_WCN3990(ar)) {
5253 time_left = wait_for_completion_timeout(
5254 &ar->vdev_delete_done,
5255 ATH10K_VDEV_DELETE_TIMEOUT_HZ);
5256 if (time_left == 0) {
5257 ath10k_warn(ar, "Timeout in receiving vdev delete resp\n");
5262 /* Some firmware revisions don't notify host about self-peer removal
5263 * until after associated vdev is deleted.
5265 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5266 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5267 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5270 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5271 arvif->vdev_id, ret);
5273 spin_lock_bh(&ar->data_lock);
5275 spin_unlock_bh(&ar->data_lock);
5278 spin_lock_bh(&ar->data_lock);
5279 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5280 peer = ar->peer_map[i];
5284 if (peer->vif == vif) {
5285 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5286 vif->addr, arvif->vdev_id);
5290 spin_unlock_bh(&ar->data_lock);
5292 ath10k_peer_cleanup(ar, arvif->vdev_id);
5293 ath10k_mac_txq_unref(ar, vif->txq);
5295 if (vif->type == NL80211_IFTYPE_MONITOR) {
5296 ar->monitor_arvif = NULL;
5297 ret = ath10k_monitor_recalc(ar);
5299 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5302 ret = ath10k_mac_txpower_recalc(ar);
5304 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5306 spin_lock_bh(&ar->htt.tx_lock);
5307 ath10k_mac_vif_tx_unlock_all(arvif);
5308 spin_unlock_bh(&ar->htt.tx_lock);
5310 ath10k_mac_txq_unref(ar, vif->txq);
5312 mutex_unlock(&ar->conf_mutex);
5315 static int ath10k_change_interface(struct ieee80211_hw *hw,
5316 struct ieee80211_vif *vif,
5317 enum nl80211_iftype new_type, bool p2p)
5319 struct ath10k *ar = hw->priv;
5322 ath10k_dbg(ar, ATH10K_DBG_MAC,
5323 "change_interface new: %d (%d), old: %d (%d)\n", new_type,
5324 p2p, vif->type, vif->p2p);
5326 if (new_type != vif->type || vif->p2p != p2p) {
5327 ath10k_remove_interface(hw, vif);
5328 vif->type = new_type;
5330 ret = ath10k_add_interface(hw, vif);
5336 * FIXME: Has to be verified.
5338 #define SUPPORTED_FILTERS \
5343 FIF_BCN_PRBRESP_PROMISC | \
5347 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5348 unsigned int changed_flags,
5349 unsigned int *total_flags,
5352 struct ath10k *ar = hw->priv;
5355 mutex_lock(&ar->conf_mutex);
5357 changed_flags &= SUPPORTED_FILTERS;
5358 *total_flags &= SUPPORTED_FILTERS;
5359 ar->filter_flags = *total_flags;
5361 ret = ath10k_monitor_recalc(ar);
5363 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5365 mutex_unlock(&ar->conf_mutex);
5368 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5369 struct ieee80211_vif *vif,
5370 struct ieee80211_bss_conf *info,
5373 struct ath10k *ar = hw->priv;
5374 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5376 u32 vdev_param, pdev_param, slottime, preamble;
5378 mutex_lock(&ar->conf_mutex);
5380 if (changed & BSS_CHANGED_IBSS)
5381 ath10k_control_ibss(arvif, info, vif->addr);
5383 if (changed & BSS_CHANGED_BEACON_INT) {
5384 arvif->beacon_interval = info->beacon_int;
5385 vdev_param = ar->wmi.vdev_param->beacon_interval;
5386 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5387 arvif->beacon_interval);
5388 ath10k_dbg(ar, ATH10K_DBG_MAC,
5389 "mac vdev %d beacon_interval %d\n",
5390 arvif->vdev_id, arvif->beacon_interval);
5393 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5394 arvif->vdev_id, ret);
5397 if (changed & BSS_CHANGED_BEACON) {
5398 ath10k_dbg(ar, ATH10K_DBG_MAC,
5399 "vdev %d set beacon tx mode to staggered\n",
5402 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5403 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5404 WMI_BEACON_STAGGERED_MODE);
5406 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5407 arvif->vdev_id, ret);
5409 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5411 ath10k_warn(ar, "failed to update beacon template: %d\n",
5414 if (ieee80211_vif_is_mesh(vif)) {
5415 /* mesh doesn't use SSID but firmware needs it */
5416 strncpy(arvif->u.ap.ssid, "mesh",
5417 sizeof(arvif->u.ap.ssid));
5418 arvif->u.ap.ssid_len = 4;
5422 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5423 ret = ath10k_mac_setup_prb_tmpl(arvif);
5425 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5426 arvif->vdev_id, ret);
5429 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5430 arvif->dtim_period = info->dtim_period;
5432 ath10k_dbg(ar, ATH10K_DBG_MAC,
5433 "mac vdev %d dtim_period %d\n",
5434 arvif->vdev_id, arvif->dtim_period);
5436 vdev_param = ar->wmi.vdev_param->dtim_period;
5437 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5438 arvif->dtim_period);
5440 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5441 arvif->vdev_id, ret);
5444 if (changed & BSS_CHANGED_SSID &&
5445 vif->type == NL80211_IFTYPE_AP) {
5446 arvif->u.ap.ssid_len = info->ssid_len;
5448 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5449 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5452 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5453 ether_addr_copy(arvif->bssid, info->bssid);
5455 if (changed & BSS_CHANGED_BEACON_ENABLED)
5456 ath10k_control_beaconing(arvif, info);
5458 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5459 arvif->use_cts_prot = info->use_cts_prot;
5461 ret = ath10k_recalc_rtscts_prot(arvif);
5463 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5464 arvif->vdev_id, ret);
5466 if (ath10k_mac_can_set_cts_prot(arvif)) {
5467 ret = ath10k_mac_set_cts_prot(arvif);
5469 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5470 arvif->vdev_id, ret);
5474 if (changed & BSS_CHANGED_ERP_SLOT) {
5475 if (info->use_short_slot)
5476 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5479 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5481 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5482 arvif->vdev_id, slottime);
5484 vdev_param = ar->wmi.vdev_param->slot_time;
5485 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5488 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5489 arvif->vdev_id, ret);
5492 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5493 if (info->use_short_preamble)
5494 preamble = WMI_VDEV_PREAMBLE_SHORT;
5496 preamble = WMI_VDEV_PREAMBLE_LONG;
5498 ath10k_dbg(ar, ATH10K_DBG_MAC,
5499 "mac vdev %d preamble %dn",
5500 arvif->vdev_id, preamble);
5502 vdev_param = ar->wmi.vdev_param->preamble;
5503 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5506 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5507 arvif->vdev_id, ret);
5510 if (changed & BSS_CHANGED_ASSOC) {
5512 /* Workaround: Make sure monitor vdev is not running
5513 * when associating to prevent some firmware revisions
5514 * (e.g. 10.1 and 10.2) from crashing.
5516 if (ar->monitor_started)
5517 ath10k_monitor_stop(ar);
5518 ath10k_bss_assoc(hw, vif, info);
5519 ath10k_monitor_recalc(ar);
5521 ath10k_bss_disassoc(hw, vif);
5525 if (changed & BSS_CHANGED_TXPOWER) {
5526 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5527 arvif->vdev_id, info->txpower);
5529 arvif->txpower = info->txpower;
5530 ret = ath10k_mac_txpower_recalc(ar);
5532 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5535 if (changed & BSS_CHANGED_PS) {
5536 arvif->ps = vif->bss_conf.ps;
5538 ret = ath10k_config_ps(ar);
5540 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5541 arvif->vdev_id, ret);
5544 mutex_unlock(&ar->conf_mutex);
5547 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5548 struct ieee80211_vif *vif,
5549 struct ieee80211_scan_request *hw_req)
5551 struct ath10k *ar = hw->priv;
5552 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5553 struct cfg80211_scan_request *req = &hw_req->req;
5554 struct wmi_start_scan_arg arg;
5556 int ret = 0, ie_skip_len = 0;
5559 mutex_lock(&ar->conf_mutex);
5561 spin_lock_bh(&ar->data_lock);
5562 switch (ar->scan.state) {
5563 case ATH10K_SCAN_IDLE:
5564 reinit_completion(&ar->scan.started);
5565 reinit_completion(&ar->scan.completed);
5566 ar->scan.state = ATH10K_SCAN_STARTING;
5567 ar->scan.is_roc = false;
5568 ar->scan.vdev_id = arvif->vdev_id;
5571 case ATH10K_SCAN_STARTING:
5572 case ATH10K_SCAN_RUNNING:
5573 case ATH10K_SCAN_ABORTING:
5577 spin_unlock_bh(&ar->data_lock);
5582 memset(&arg, 0, sizeof(arg));
5583 ath10k_wmi_start_scan_init(ar, &arg);
5584 arg.vdev_id = arvif->vdev_id;
5585 arg.scan_id = ATH10K_SCAN_ID;
5588 if (QCA_REV_WCN3990(ar)) {
5590 while (ptr[0] == WLAN_EID_SUPP_RATES ||
5591 ptr[0] == WLAN_EID_EXT_SUPP_RATES) {
5592 ie_skip_len = ptr[1] + 2;
5596 arg.ie_len = req->ie_len - ie_skip_len;
5597 memcpy(arg.ie, req->ie + ie_skip_len, arg.ie_len);
5601 arg.n_ssids = req->n_ssids;
5602 for (i = 0; i < arg.n_ssids; i++) {
5603 arg.ssids[i].len = req->ssids[i].ssid_len;
5604 arg.ssids[i].ssid = req->ssids[i].ssid;
5606 if (QCA_REV_WCN3990(ar)) {
5607 arg.scan_ctrl_flags &=
5608 ~(WMI_SCAN_ADD_BCAST_PROBE_REQ |
5609 WMI_SCAN_CHAN_STAT_EVENT);
5612 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5615 if (req->n_channels) {
5616 arg.n_channels = req->n_channels;
5617 for (i = 0; i < arg.n_channels; i++)
5618 arg.channels[i] = req->channels[i]->center_freq;
5621 ret = ath10k_start_scan(ar, &arg);
5623 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5624 spin_lock_bh(&ar->data_lock);
5625 ar->scan.state = ATH10K_SCAN_IDLE;
5626 spin_unlock_bh(&ar->data_lock);
5629 /* Add a 200ms margin to account for event/command processing */
5630 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5631 msecs_to_jiffies(arg.max_scan_time +
5635 mutex_unlock(&ar->conf_mutex);
5639 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5640 struct ieee80211_vif *vif)
5642 struct ath10k *ar = hw->priv;
5644 mutex_lock(&ar->conf_mutex);
5645 ath10k_scan_abort(ar);
5646 mutex_unlock(&ar->conf_mutex);
5648 cancel_delayed_work_sync(&ar->scan.timeout);
5651 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5652 struct ath10k_vif *arvif,
5653 enum set_key_cmd cmd,
5654 struct ieee80211_key_conf *key)
5656 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5659 /* 10.1 firmware branch requires default key index to be set to group
5660 * key index after installing it. Otherwise FW/HW Txes corrupted
5661 * frames with multi-vif APs. This is not required for main firmware
5662 * branch (e.g. 636).
5664 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5666 * FIXME: It remains unknown if this is required for multi-vif STA
5667 * interfaces on 10.1.
5670 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5671 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5674 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5677 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5680 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5686 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5689 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5690 arvif->vdev_id, ret);
5693 static void ath10k_set_rekey_data(struct ieee80211_hw *hw,
5694 struct ieee80211_vif *vif,
5695 struct cfg80211_gtk_rekey_data *data)
5697 struct ath10k *ar = hw->priv;
5698 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5700 mutex_lock(&ar->conf_mutex);
5701 memcpy(&arvif->gtk_rekey_data.kek, data->kek, NL80211_KEK_LEN);
5702 memcpy(&arvif->gtk_rekey_data.kck, data->kck, NL80211_KCK_LEN);
5703 arvif->gtk_rekey_data.replay_ctr =
5704 be64_to_cpup((__be64 *)data->replay_ctr);
5705 arvif->gtk_rekey_data.valid = true;
5706 mutex_unlock(&ar->conf_mutex);
5709 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5710 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5711 struct ieee80211_key_conf *key)
5713 struct ath10k *ar = hw->priv;
5714 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5715 struct ath10k_peer *peer;
5716 const u8 *peer_addr;
5717 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5718 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5724 /* this one needs to be done in software */
5725 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5728 if (arvif->nohwcrypt)
5731 if (key->keyidx > WMI_MAX_KEY_INDEX)
5734 mutex_lock(&ar->conf_mutex);
5737 peer_addr = sta->addr;
5738 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5739 peer_addr = vif->bss_conf.bssid;
5741 peer_addr = vif->addr;
5743 key->hw_key_idx = key->keyidx;
5747 arvif->wep_keys[key->keyidx] = key;
5749 arvif->wep_keys[key->keyidx] = NULL;
5752 /* the peer should not disappear in mid-way (unless FW goes awry) since
5753 * we already hold conf_mutex. we just make sure its there now. */
5754 spin_lock_bh(&ar->data_lock);
5755 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5756 spin_unlock_bh(&ar->data_lock);
5759 if (cmd == SET_KEY) {
5760 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5765 /* if the peer doesn't exist there is no key to disable
5771 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5772 flags |= WMI_KEY_PAIRWISE;
5774 flags |= WMI_KEY_GROUP;
5777 if (cmd == DISABLE_KEY)
5778 ath10k_clear_vdev_key(arvif, key);
5780 /* When WEP keys are uploaded it's possible that there are
5781 * stations associated already (e.g. when merging) without any
5782 * keys. Static WEP needs an explicit per-peer key upload.
5784 if (vif->type == NL80211_IFTYPE_ADHOC &&
5786 ath10k_mac_vif_update_wep_key(arvif, key);
5788 /* 802.1x never sets the def_wep_key_idx so each set_key()
5789 * call changes default tx key.
5791 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5792 * after first set_key().
5794 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5795 flags |= WMI_KEY_TX_USAGE;
5798 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5801 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5802 arvif->vdev_id, peer_addr, ret);
5806 /* mac80211 sets static WEP keys as groupwise while firmware requires
5807 * them to be installed twice as both pairwise and groupwise.
5809 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5811 flags2 &= ~WMI_KEY_GROUP;
5812 flags2 |= WMI_KEY_PAIRWISE;
5814 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5817 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5818 arvif->vdev_id, peer_addr, ret);
5819 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5823 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5824 arvif->vdev_id, peer_addr, ret2);
5830 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5832 spin_lock_bh(&ar->data_lock);
5833 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5834 if (peer && cmd == SET_KEY)
5835 peer->keys[key->keyidx] = key;
5836 else if (peer && cmd == DISABLE_KEY)
5837 peer->keys[key->keyidx] = NULL;
5838 else if (peer == NULL)
5839 /* impossible unless FW goes crazy */
5840 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5841 spin_unlock_bh(&ar->data_lock);
5844 mutex_unlock(&ar->conf_mutex);
5848 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5849 struct ieee80211_vif *vif,
5852 struct ath10k *ar = hw->priv;
5853 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5856 mutex_lock(&arvif->ar->conf_mutex);
5858 if (arvif->ar->state != ATH10K_STATE_ON)
5861 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5862 arvif->vdev_id, keyidx);
5864 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5866 arvif->ar->wmi.vdev_param->def_keyid,
5870 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5876 arvif->def_wep_key_idx = keyidx;
5879 mutex_unlock(&arvif->ar->conf_mutex);
5882 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5885 struct ath10k_vif *arvif;
5886 struct ath10k_sta *arsta;
5887 struct ieee80211_sta *sta;
5888 struct cfg80211_chan_def def;
5889 enum ieee80211_band band;
5890 const u8 *ht_mcs_mask;
5891 const u16 *vht_mcs_mask;
5892 u32 changed, bw, nss, smps;
5895 arsta = container_of(wk, struct ath10k_sta, update_wk);
5896 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5897 arvif = arsta->arvif;
5900 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5903 band = def.chan->band;
5904 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5905 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5907 spin_lock_bh(&ar->data_lock);
5909 changed = arsta->changed;
5916 spin_unlock_bh(&ar->data_lock);
5918 mutex_lock(&ar->conf_mutex);
5920 nss = max_t(u32, 1, nss);
5921 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5922 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5924 if (changed & IEEE80211_RC_BW_CHANGED) {
5925 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5928 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5929 WMI_PEER_CHAN_WIDTH, bw);
5931 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5932 sta->addr, bw, err);
5935 if (changed & IEEE80211_RC_NSS_CHANGED) {
5936 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5939 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5942 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5943 sta->addr, nss, err);
5946 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5947 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5950 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5951 WMI_PEER_SMPS_STATE, smps);
5953 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5954 sta->addr, smps, err);
5957 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5958 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5961 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5963 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5967 mutex_unlock(&ar->conf_mutex);
5970 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5971 struct ieee80211_sta *sta)
5973 struct ath10k *ar = arvif->ar;
5975 lockdep_assert_held(&ar->conf_mutex);
5977 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5980 if (ar->num_stations >= ar->max_num_stations)
5988 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5989 struct ieee80211_sta *sta)
5991 struct ath10k *ar = arvif->ar;
5993 lockdep_assert_held(&ar->conf_mutex);
5995 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
6001 struct ath10k_mac_tdls_iter_data {
6002 u32 num_tdls_stations;
6003 struct ieee80211_vif *curr_vif;
6006 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
6007 struct ieee80211_sta *sta)
6009 struct ath10k_mac_tdls_iter_data *iter_data = data;
6010 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6011 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
6013 if (sta->tdls && sta_vif == iter_data->curr_vif)
6014 iter_data->num_tdls_stations++;
6017 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
6018 struct ieee80211_vif *vif)
6020 struct ath10k_mac_tdls_iter_data data = {};
6022 data.curr_vif = vif;
6024 ieee80211_iterate_stations_atomic(hw,
6025 ath10k_mac_tdls_vif_stations_count_iter,
6027 return data.num_tdls_stations;
6030 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
6031 struct ieee80211_vif *vif)
6033 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6034 int *num_tdls_vifs = data;
6036 if (vif->type != NL80211_IFTYPE_STATION)
6039 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
6043 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
6045 int num_tdls_vifs = 0;
6047 ieee80211_iterate_active_interfaces_atomic(hw,
6048 IEEE80211_IFACE_ITER_NORMAL,
6049 ath10k_mac_tdls_vifs_count_iter,
6051 return num_tdls_vifs;
6054 static int ath10k_sta_state(struct ieee80211_hw *hw,
6055 struct ieee80211_vif *vif,
6056 struct ieee80211_sta *sta,
6057 enum ieee80211_sta_state old_state,
6058 enum ieee80211_sta_state new_state)
6060 struct ath10k *ar = hw->priv;
6061 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6062 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6063 struct ath10k_peer *peer;
6067 if (old_state == IEEE80211_STA_NOTEXIST &&
6068 new_state == IEEE80211_STA_NONE) {
6069 memset(arsta, 0, sizeof(*arsta));
6070 arsta->arvif = arvif;
6071 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
6073 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6074 ath10k_mac_txq_init(sta->txq[i]);
6077 /* cancel must be done outside the mutex to avoid deadlock */
6078 if ((old_state == IEEE80211_STA_NONE &&
6079 new_state == IEEE80211_STA_NOTEXIST))
6080 cancel_work_sync(&arsta->update_wk);
6082 if (vif->type == NL80211_IFTYPE_STATION && new_state > ar->sta_state)
6083 ar->sta_state = new_state;
6085 mutex_lock(&ar->conf_mutex);
6087 if (old_state == IEEE80211_STA_NOTEXIST &&
6088 new_state == IEEE80211_STA_NONE) {
6090 * New station addition.
6092 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
6093 u32 num_tdls_stations;
6096 ath10k_dbg(ar, ATH10K_DBG_MAC,
6097 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
6098 arvif->vdev_id, sta->addr,
6099 ar->num_stations + 1, ar->max_num_stations,
6100 ar->num_peers + 1, ar->max_num_peers);
6102 ret = ath10k_mac_inc_num_stations(arvif, sta);
6104 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
6105 ar->max_num_stations);
6110 peer_type = WMI_PEER_TYPE_TDLS;
6112 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
6113 sta->addr, peer_type);
6115 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
6116 sta->addr, arvif->vdev_id, ret);
6117 ath10k_mac_dec_num_stations(arvif, sta);
6121 spin_lock_bh(&ar->data_lock);
6123 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6125 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6126 vif->addr, arvif->vdev_id);
6127 spin_unlock_bh(&ar->data_lock);
6128 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6129 ath10k_mac_dec_num_stations(arvif, sta);
6134 arsta->peer_id = find_first_bit(peer->peer_ids,
6135 ATH10K_MAX_NUM_PEER_IDS);
6137 spin_unlock_bh(&ar->data_lock);
6142 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6143 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6145 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
6146 num_tdls_stations == 0) {
6147 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6148 arvif->vdev_id, ar->max_num_tdls_vdevs);
6149 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6150 ath10k_mac_dec_num_stations(arvif, sta);
6155 if (num_tdls_stations == 0) {
6156 /* This is the first tdls peer in current vif */
6157 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
6159 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6162 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6163 arvif->vdev_id, ret);
6164 ath10k_peer_delete(ar, arvif->vdev_id,
6166 ath10k_mac_dec_num_stations(arvif, sta);
6171 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6172 WMI_TDLS_PEER_STATE_PEERING);
6175 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6176 sta->addr, arvif->vdev_id, ret);
6177 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6178 ath10k_mac_dec_num_stations(arvif, sta);
6180 if (num_tdls_stations != 0)
6182 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6185 } else if ((old_state == IEEE80211_STA_NONE &&
6186 new_state == IEEE80211_STA_NOTEXIST)) {
6188 * Existing station deletion.
6190 ath10k_dbg(ar, ATH10K_DBG_MAC,
6191 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6192 arvif->vdev_id, sta->addr, sta);
6195 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6197 WMI_TDLS_PEER_STATE_TEARDOWN);
6199 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6201 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6204 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6206 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6207 sta->addr, arvif->vdev_id, ret);
6209 ath10k_mac_dec_num_stations(arvif, sta);
6211 spin_lock_bh(&ar->data_lock);
6212 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6213 peer = ar->peer_map[i];
6217 if (peer->sta == sta) {
6218 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6219 sta->addr, peer, i, arvif->vdev_id);
6222 /* Clean up the peer object as well since we
6223 * must have failed to do this above.
6225 list_del(&peer->list);
6226 ar->peer_map[i] = NULL;
6231 spin_unlock_bh(&ar->data_lock);
6233 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6234 ath10k_mac_txq_unref(ar, sta->txq[i]);
6239 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6242 /* This was the last tdls peer in current vif */
6243 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6246 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6247 arvif->vdev_id, ret);
6249 } else if (old_state == IEEE80211_STA_AUTH &&
6250 new_state == IEEE80211_STA_ASSOC &&
6251 (vif->type == NL80211_IFTYPE_AP ||
6252 vif->type == NL80211_IFTYPE_MESH_POINT ||
6253 vif->type == NL80211_IFTYPE_ADHOC)) {
6257 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6260 ret = ath10k_station_assoc(ar, vif, sta, false);
6262 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6263 sta->addr, arvif->vdev_id, ret);
6264 } else if (old_state == IEEE80211_STA_ASSOC &&
6265 new_state == IEEE80211_STA_AUTHORIZED &&
6268 * Tdls station authorized.
6270 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6273 ret = ath10k_station_assoc(ar, vif, sta, false);
6275 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6276 sta->addr, arvif->vdev_id, ret);
6280 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6281 WMI_TDLS_PEER_STATE_CONNECTED);
6283 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6284 sta->addr, arvif->vdev_id, ret);
6285 } else if (old_state == IEEE80211_STA_ASSOC &&
6286 new_state == IEEE80211_STA_AUTH &&
6287 (vif->type == NL80211_IFTYPE_AP ||
6288 vif->type == NL80211_IFTYPE_MESH_POINT ||
6289 vif->type == NL80211_IFTYPE_ADHOC)) {
6293 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6296 ret = ath10k_station_disassoc(ar, vif, sta);
6298 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6299 sta->addr, arvif->vdev_id, ret);
6302 mutex_unlock(&ar->conf_mutex);
6306 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6307 u16 ac, bool enable)
6309 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6310 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6311 u32 prio = 0, acc = 0;
6315 lockdep_assert_held(&ar->conf_mutex);
6317 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6321 case IEEE80211_AC_VO:
6322 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6323 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6327 case IEEE80211_AC_VI:
6328 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6329 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6333 case IEEE80211_AC_BE:
6334 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6335 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6339 case IEEE80211_AC_BK:
6340 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6341 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6348 arvif->u.sta.uapsd |= value;
6350 arvif->u.sta.uapsd &= ~value;
6352 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6353 WMI_STA_PS_PARAM_UAPSD,
6354 arvif->u.sta.uapsd);
6356 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6360 if (arvif->u.sta.uapsd)
6361 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6363 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6365 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6366 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6369 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6371 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6373 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6374 arvif->vdev_id, ret);
6378 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6380 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6381 arvif->vdev_id, ret);
6385 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6386 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6387 /* Only userspace can make an educated decision when to send
6388 * trigger frame. The following effectively disables u-UAPSD
6389 * autotrigger in firmware (which is enabled by default
6390 * provided the autotrigger service is available).
6394 arg.user_priority = prio;
6395 arg.service_interval = 0;
6396 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6397 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6399 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6400 arvif->bssid, &arg, 1);
6402 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6412 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6413 struct ieee80211_vif *vif, u16 ac,
6414 const struct ieee80211_tx_queue_params *params)
6416 struct ath10k *ar = hw->priv;
6417 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6418 struct wmi_wmm_params_arg *p = NULL;
6421 mutex_lock(&ar->conf_mutex);
6424 case IEEE80211_AC_VO:
6425 p = &arvif->wmm_params.ac_vo;
6427 case IEEE80211_AC_VI:
6428 p = &arvif->wmm_params.ac_vi;
6430 case IEEE80211_AC_BE:
6431 p = &arvif->wmm_params.ac_be;
6433 case IEEE80211_AC_BK:
6434 p = &arvif->wmm_params.ac_bk;
6443 p->cwmin = params->cw_min;
6444 p->cwmax = params->cw_max;
6445 p->aifs = params->aifs;
6448 * The channel time duration programmed in the HW is in absolute
6449 * microseconds, while mac80211 gives the txop in units of
6452 p->txop = params->txop * 32;
6454 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6455 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6456 &arvif->wmm_params);
6458 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6459 arvif->vdev_id, ret);
6463 /* This won't work well with multi-interface cases but it's
6464 * better than nothing.
6466 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6468 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6473 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6475 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6478 mutex_unlock(&ar->conf_mutex);
6482 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6484 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6485 struct ieee80211_vif *vif,
6486 struct ieee80211_channel *chan,
6488 enum ieee80211_roc_type type)
6490 struct ath10k *ar = hw->priv;
6491 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6492 struct wmi_start_scan_arg arg;
6496 mutex_lock(&ar->conf_mutex);
6498 spin_lock_bh(&ar->data_lock);
6499 switch (ar->scan.state) {
6500 case ATH10K_SCAN_IDLE:
6501 reinit_completion(&ar->scan.started);
6502 reinit_completion(&ar->scan.completed);
6503 reinit_completion(&ar->scan.on_channel);
6504 ar->scan.state = ATH10K_SCAN_STARTING;
6505 ar->scan.is_roc = true;
6506 ar->scan.vdev_id = arvif->vdev_id;
6507 ar->scan.roc_freq = chan->center_freq;
6508 ar->scan.roc_notify = true;
6511 case ATH10K_SCAN_STARTING:
6512 case ATH10K_SCAN_RUNNING:
6513 case ATH10K_SCAN_ABORTING:
6517 spin_unlock_bh(&ar->data_lock);
6522 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6524 memset(&arg, 0, sizeof(arg));
6525 ath10k_wmi_start_scan_init(ar, &arg);
6526 arg.vdev_id = arvif->vdev_id;
6527 arg.scan_id = ATH10K_SCAN_ID;
6529 arg.channels[0] = chan->center_freq;
6530 arg.dwell_time_active = scan_time_msec;
6531 arg.dwell_time_passive = scan_time_msec;
6532 arg.max_scan_time = scan_time_msec;
6533 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6534 if (QCA_REV_WCN3990(ar)) {
6535 arg.scan_ctrl_flags &= ~(WMI_SCAN_FILTER_PROBE_REQ |
6536 WMI_SCAN_CHAN_STAT_EVENT |
6537 WMI_SCAN_ADD_BCAST_PROBE_REQ);
6539 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6541 arg.burst_duration_ms = duration;
6543 ret = ath10k_start_scan(ar, &arg);
6545 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6546 spin_lock_bh(&ar->data_lock);
6547 ar->scan.state = ATH10K_SCAN_IDLE;
6548 spin_unlock_bh(&ar->data_lock);
6552 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6554 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6556 ret = ath10k_scan_stop(ar);
6558 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6564 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6565 msecs_to_jiffies(duration));
6569 mutex_unlock(&ar->conf_mutex);
6573 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6575 struct ath10k *ar = hw->priv;
6577 mutex_lock(&ar->conf_mutex);
6579 spin_lock_bh(&ar->data_lock);
6580 ar->scan.roc_notify = false;
6581 spin_unlock_bh(&ar->data_lock);
6583 ath10k_scan_abort(ar);
6585 mutex_unlock(&ar->conf_mutex);
6587 cancel_delayed_work_sync(&ar->scan.timeout);
6593 * Both RTS and Fragmentation threshold are interface-specific
6594 * in ath10k, but device-specific in mac80211.
6597 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6599 struct ath10k *ar = hw->priv;
6600 struct ath10k_vif *arvif;
6603 mutex_lock(&ar->conf_mutex);
6604 list_for_each_entry(arvif, &ar->arvifs, list) {
6605 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6606 arvif->vdev_id, value);
6608 ret = ath10k_mac_set_rts(arvif, value);
6610 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6611 arvif->vdev_id, ret);
6615 mutex_unlock(&ar->conf_mutex);
6620 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6622 /* Even though there's a WMI enum for fragmentation threshold no known
6623 * firmware actually implements it. Moreover it is not possible to rely
6624 * frame fragmentation to mac80211 because firmware clears the "more
6625 * fragments" bit in frame control making it impossible for remote
6626 * devices to reassemble frames.
6628 * Hence implement a dummy callback just to say fragmentation isn't
6629 * supported. This effectively prevents mac80211 from doing frame
6630 * fragmentation in software.
6635 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6636 u32 queues, bool drop)
6638 struct ath10k *ar = hw->priv;
6642 /* mac80211 doesn't care if we really xmit queued frames or not
6643 * we'll collect those frames either way if we stop/delete vdevs */
6647 mutex_lock(&ar->conf_mutex);
6649 if (ar->state == ATH10K_STATE_WEDGED)
6652 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6655 spin_lock_bh(&ar->htt.tx_lock);
6656 empty = (ar->htt.num_pending_tx == 0);
6657 spin_unlock_bh(&ar->htt.tx_lock);
6659 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6660 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6664 }), ATH10K_FLUSH_TIMEOUT_HZ);
6666 if (time_left == 0 || skip)
6667 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6668 skip, ar->state, time_left);
6671 mutex_unlock(&ar->conf_mutex);
6674 /* TODO: Implement this function properly
6675 * For now it is needed to reply to Probe Requests in IBSS mode.
6676 * Propably we need this information from FW.
6678 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6683 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6684 enum ieee80211_reconfig_type reconfig_type)
6686 struct ath10k *ar = hw->priv;
6688 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6691 mutex_lock(&ar->conf_mutex);
6693 /* If device failed to restart it will be in a different state, e.g.
6694 * ATH10K_STATE_WEDGED */
6695 if (ar->state == ATH10K_STATE_RESTARTED) {
6696 ath10k_info(ar, "device successfully recovered\n");
6697 ar->state = ATH10K_STATE_ON;
6698 ieee80211_wake_queues(ar->hw);
6701 mutex_unlock(&ar->conf_mutex);
6705 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6706 struct ieee80211_channel *channel)
6709 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6711 lockdep_assert_held(&ar->conf_mutex);
6713 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6714 (ar->rx_channel != channel))
6717 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6718 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6722 reinit_completion(&ar->bss_survey_done);
6724 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6726 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6730 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6732 ath10k_warn(ar, "bss channel survey timed out\n");
6737 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6738 struct survey_info *survey)
6740 struct ath10k *ar = hw->priv;
6741 struct ieee80211_supported_band *sband;
6742 struct survey_info *ar_survey = &ar->survey[idx];
6745 mutex_lock(&ar->conf_mutex);
6747 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
6748 if (sband && idx >= sband->n_channels) {
6749 idx -= sband->n_channels;
6754 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
6756 if (!sband || idx >= sband->n_channels) {
6761 if (!QCA_REV_WCN3990(ar))
6762 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6764 spin_lock_bh(&ar->data_lock);
6765 memcpy(survey, ar_survey, sizeof(*survey));
6766 spin_unlock_bh(&ar->data_lock);
6768 survey->channel = &sband->channels[idx];
6770 if (ar->rx_channel == survey->channel)
6771 survey->filled |= SURVEY_INFO_IN_USE;
6774 mutex_unlock(&ar->conf_mutex);
6779 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6780 enum ieee80211_band band,
6781 const struct cfg80211_bitrate_mask *mask)
6786 num_rates += hweight32(mask->control[band].legacy);
6788 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6789 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6791 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6792 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6794 return num_rates == 1;
6798 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6799 enum ieee80211_band band,
6800 const struct cfg80211_bitrate_mask *mask,
6803 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6804 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6806 u8 vht_nss_mask = 0;
6809 if (mask->control[band].legacy)
6812 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6813 if (mask->control[band].ht_mcs[i] == 0)
6815 else if (mask->control[band].ht_mcs[i] ==
6816 sband->ht_cap.mcs.rx_mask[i])
6817 ht_nss_mask |= BIT(i);
6822 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6823 if (mask->control[band].vht_mcs[i] == 0)
6825 else if (mask->control[band].vht_mcs[i] ==
6826 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6827 vht_nss_mask |= BIT(i);
6832 if (ht_nss_mask != vht_nss_mask)
6835 if (ht_nss_mask == 0)
6838 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6841 *nss = fls(ht_nss_mask);
6847 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6848 enum ieee80211_band band,
6849 const struct cfg80211_bitrate_mask *mask,
6852 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6859 if (hweight32(mask->control[band].legacy) == 1) {
6860 rate_idx = ffs(mask->control[band].legacy) - 1;
6862 hw_rate = sband->bitrates[rate_idx].hw_value;
6863 bitrate = sband->bitrates[rate_idx].bitrate;
6865 if (ath10k_mac_bitrate_is_cck(bitrate))
6866 preamble = WMI_RATE_PREAMBLE_CCK;
6868 preamble = WMI_RATE_PREAMBLE_OFDM;
6871 *rate = preamble << 6 |
6878 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6879 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6881 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6883 (ffs(mask->control[band].ht_mcs[i]) - 1);
6889 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6890 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6892 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6894 (ffs(mask->control[band].vht_mcs[i]) - 1);
6903 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6904 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6906 struct ath10k *ar = arvif->ar;
6910 lockdep_assert_held(&ar->conf_mutex);
6912 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6913 arvif->vdev_id, rate, nss, sgi);
6915 vdev_param = ar->wmi.vdev_param->fixed_rate;
6916 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6918 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6923 vdev_param = ar->wmi.vdev_param->nss;
6924 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6926 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6930 vdev_param = ar->wmi.vdev_param->sgi;
6931 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6933 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6937 vdev_param = ar->wmi.vdev_param->ldpc;
6938 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6940 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6948 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6949 enum ieee80211_band band,
6950 const struct cfg80211_bitrate_mask *mask)
6955 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6956 * to express all VHT MCS rate masks. Effectively only the following
6957 * ranges can be used: none, 0-7, 0-8 and 0-9.
6959 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6960 vht_mcs = mask->control[band].vht_mcs[i];
6969 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6977 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6978 struct ieee80211_sta *sta)
6980 struct ath10k_vif *arvif = data;
6981 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6982 struct ath10k *ar = arvif->ar;
6984 if (arsta->arvif != arvif)
6987 spin_lock_bh(&ar->data_lock);
6988 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6989 spin_unlock_bh(&ar->data_lock);
6991 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6994 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6995 struct ieee80211_vif *vif,
6996 const struct cfg80211_bitrate_mask *mask)
6998 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6999 struct cfg80211_chan_def def;
7000 struct ath10k *ar = arvif->ar;
7001 enum ieee80211_band band;
7002 const u8 *ht_mcs_mask;
7003 const u16 *vht_mcs_mask;
7011 if (ath10k_mac_vif_chan(vif, &def))
7014 band = def.chan->band;
7015 ht_mcs_mask = mask->control[band].ht_mcs;
7016 vht_mcs_mask = mask->control[band].vht_mcs;
7017 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7019 sgi = mask->control[band].gi;
7020 if (sgi == NL80211_TXRATE_FORCE_LGI)
7023 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
7024 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
7027 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
7028 arvif->vdev_id, ret);
7031 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7033 rate = WMI_FIXED_RATE_NONE;
7036 rate = WMI_FIXED_RATE_NONE;
7037 nss = min(ar->num_rf_chains,
7038 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
7039 ath10k_mac_max_vht_nss(vht_mcs_mask)));
7041 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
7044 mutex_lock(&ar->conf_mutex);
7046 arvif->bitrate_mask = *mask;
7047 ieee80211_iterate_stations_atomic(ar->hw,
7048 ath10k_mac_set_bitrate_mask_iter,
7051 mutex_unlock(&ar->conf_mutex);
7054 mutex_lock(&ar->conf_mutex);
7056 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
7058 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
7059 arvif->vdev_id, ret);
7064 mutex_unlock(&ar->conf_mutex);
7069 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
7070 struct ieee80211_vif *vif,
7071 struct ieee80211_sta *sta,
7074 struct ath10k *ar = hw->priv;
7075 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
7076 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7077 struct ath10k_peer *peer;
7080 spin_lock_bh(&ar->data_lock);
7082 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
7084 spin_unlock_bh(&ar->data_lock);
7085 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
7086 sta->addr, arvif->vdev_id);
7090 ath10k_dbg(ar, ATH10K_DBG_MAC,
7091 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
7092 sta->addr, changed, sta->bandwidth, sta->rx_nss,
7095 if (changed & IEEE80211_RC_BW_CHANGED) {
7096 bw = WMI_PEER_CHWIDTH_20MHZ;
7098 switch (sta->bandwidth) {
7099 case IEEE80211_STA_RX_BW_20:
7100 bw = WMI_PEER_CHWIDTH_20MHZ;
7102 case IEEE80211_STA_RX_BW_40:
7103 bw = WMI_PEER_CHWIDTH_40MHZ;
7105 case IEEE80211_STA_RX_BW_80:
7106 bw = WMI_PEER_CHWIDTH_80MHZ;
7108 case IEEE80211_STA_RX_BW_160:
7109 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
7110 sta->bandwidth, sta->addr);
7111 bw = WMI_PEER_CHWIDTH_20MHZ;
7118 if (changed & IEEE80211_RC_NSS_CHANGED)
7119 arsta->nss = sta->rx_nss;
7121 if (changed & IEEE80211_RC_SMPS_CHANGED) {
7122 smps = WMI_PEER_SMPS_PS_NONE;
7124 switch (sta->smps_mode) {
7125 case IEEE80211_SMPS_AUTOMATIC:
7126 case IEEE80211_SMPS_OFF:
7127 smps = WMI_PEER_SMPS_PS_NONE;
7129 case IEEE80211_SMPS_STATIC:
7130 smps = WMI_PEER_SMPS_STATIC;
7132 case IEEE80211_SMPS_DYNAMIC:
7133 smps = WMI_PEER_SMPS_DYNAMIC;
7135 case IEEE80211_SMPS_NUM_MODES:
7136 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7137 sta->smps_mode, sta->addr);
7138 smps = WMI_PEER_SMPS_PS_NONE;
7145 arsta->changed |= changed;
7147 spin_unlock_bh(&ar->data_lock);
7149 ieee80211_queue_work(hw, &arsta->update_wk);
7152 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7155 * FIXME: Return 0 for time being. Need to figure out whether FW
7156 * has the API to fetch 64-bit local TSF
7162 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7165 struct ath10k *ar = hw->priv;
7166 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7167 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
7172 * Given tsf argument is entire TSF value, but firmware accepts
7173 * only TSF offset to current TSF.
7175 * get_tsf function is used to get offset value, however since
7176 * ath10k_get_tsf is not implemented properly, it will return 0 always.
7177 * Luckily all the caller functions to set_tsf, as of now, also rely on
7178 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
7179 * final tsf offset value to firmware will be arithmetically correct.
7181 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
7182 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7183 vdev_param, tsf_offset);
7184 if (ret && ret != -EOPNOTSUPP)
7185 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
7188 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7189 struct ieee80211_vif *vif,
7190 struct ieee80211_ampdu_params *params)
7192 struct ath10k *ar = hw->priv;
7193 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7194 struct ieee80211_sta *sta = params->sta;
7195 enum ieee80211_ampdu_mlme_action action = params->action;
7196 u16 tid = params->tid;
7198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7199 arvif->vdev_id, sta->addr, tid, action);
7202 case IEEE80211_AMPDU_RX_START:
7203 case IEEE80211_AMPDU_RX_STOP:
7204 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7205 * creation/removal. Do we need to verify this?
7208 case IEEE80211_AMPDU_TX_START:
7209 case IEEE80211_AMPDU_TX_STOP_CONT:
7210 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7211 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7212 case IEEE80211_AMPDU_TX_OPERATIONAL:
7213 /* Firmware offloads Tx aggregation entirely so deny mac80211
7214 * Tx aggregation requests.
7223 ath10k_mac_update_rx_channel(struct ath10k *ar,
7224 struct ieee80211_chanctx_conf *ctx,
7225 struct ieee80211_vif_chanctx_switch *vifs,
7228 struct cfg80211_chan_def *def = NULL;
7230 /* Both locks are required because ar->rx_channel is modified. This
7231 * allows readers to hold either lock.
7233 lockdep_assert_held(&ar->conf_mutex);
7234 lockdep_assert_held(&ar->data_lock);
7236 WARN_ON(ctx && vifs);
7237 WARN_ON(vifs && !n_vifs);
7239 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7240 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7241 * ppdu on Rx may reduce performance on low-end systems. It should be
7242 * possible to make tables/hashmaps to speed the lookup up (be vary of
7243 * cpu data cache lines though regarding sizes) but to keep the initial
7244 * implementation simple and less intrusive fallback to the slow lookup
7245 * only for multi-channel cases. Single-channel cases will remain to
7246 * use the old channel derival and thus performance should not be
7250 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7251 ieee80211_iter_chan_contexts_atomic(ar->hw,
7252 ath10k_mac_get_any_chandef_iter,
7256 def = &vifs[0].new_ctx->def;
7258 ar->rx_channel = def->chan;
7259 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7260 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7261 /* During driver restart due to firmware assert, since mac80211
7262 * already has valid channel context for given radio, channel
7263 * context iteration return num_chanctx > 0. So fix rx_channel
7264 * when restart is in progress.
7266 ar->rx_channel = ctx->def.chan;
7268 ar->rx_channel = NULL;
7274 ath10k_mac_update_vif_chan(struct ath10k *ar,
7275 struct ieee80211_vif_chanctx_switch *vifs,
7278 struct ath10k_vif *arvif;
7282 lockdep_assert_held(&ar->conf_mutex);
7284 /* First stop monitor interface. Some FW versions crash if there's a
7285 * lone monitor interface.
7287 if (ar->monitor_started)
7288 ath10k_monitor_stop(ar);
7290 for (i = 0; i < n_vifs; i++) {
7291 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7293 ath10k_dbg(ar, ATH10K_DBG_MAC,
7294 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7296 vifs[i].old_ctx->def.chan->center_freq,
7297 vifs[i].new_ctx->def.chan->center_freq,
7298 vifs[i].old_ctx->def.width,
7299 vifs[i].new_ctx->def.width);
7301 if (WARN_ON(!arvif->is_started))
7304 if (WARN_ON(!arvif->is_up))
7306 if (QCA_REV_WCN3990(ar)) {
7307 /* In the case of wcn3990 WLAN module we send
7308 * vdev restart only, no need to send vdev down.
7311 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7314 "failed to restart vdev %d: %d\n",
7315 arvif->vdev_id, ret);
7319 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7321 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7322 arvif->vdev_id, ret);
7328 /* All relevant vdevs are downed and associated channel resources
7329 * should be available for the channel switch now.
7332 spin_lock_bh(&ar->data_lock);
7333 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7334 spin_unlock_bh(&ar->data_lock);
7336 for (i = 0; i < n_vifs; i++) {
7337 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7339 if (WARN_ON(!arvif->is_started))
7342 if (WARN_ON(!arvif->is_up))
7345 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7347 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7350 ret = ath10k_mac_setup_prb_tmpl(arvif);
7352 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7355 if (!QCA_REV_WCN3990(ar)) {
7356 /* In case of other than wcn3990 WLAN module we
7357 * send vdev down and vdev restart to the firmware.
7360 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7362 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7363 arvif->vdev_id, ret);
7368 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7371 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7372 arvif->vdev_id, ret);
7377 ath10k_monitor_recalc(ar);
7381 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7382 struct ieee80211_chanctx_conf *ctx)
7384 struct ath10k *ar = hw->priv;
7386 ath10k_dbg(ar, ATH10K_DBG_MAC,
7387 "mac chanctx add freq %hu width %d ptr %pK\n",
7388 ctx->def.chan->center_freq, ctx->def.width, ctx);
7390 mutex_lock(&ar->conf_mutex);
7392 spin_lock_bh(&ar->data_lock);
7393 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7394 spin_unlock_bh(&ar->data_lock);
7396 ath10k_recalc_radar_detection(ar);
7397 ath10k_monitor_recalc(ar);
7399 mutex_unlock(&ar->conf_mutex);
7405 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7406 struct ieee80211_chanctx_conf *ctx)
7408 struct ath10k *ar = hw->priv;
7410 ath10k_dbg(ar, ATH10K_DBG_MAC,
7411 "mac chanctx remove freq %hu width %d ptr %pK\n",
7412 ctx->def.chan->center_freq, ctx->def.width, ctx);
7414 mutex_lock(&ar->conf_mutex);
7416 spin_lock_bh(&ar->data_lock);
7417 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7418 spin_unlock_bh(&ar->data_lock);
7420 ath10k_recalc_radar_detection(ar);
7421 ath10k_monitor_recalc(ar);
7423 mutex_unlock(&ar->conf_mutex);
7426 struct ath10k_mac_change_chanctx_arg {
7427 struct ieee80211_chanctx_conf *ctx;
7428 struct ieee80211_vif_chanctx_switch *vifs;
7434 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7435 struct ieee80211_vif *vif)
7437 struct ath10k_mac_change_chanctx_arg *arg = data;
7439 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7446 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7447 struct ieee80211_vif *vif)
7449 struct ath10k_mac_change_chanctx_arg *arg = data;
7450 struct ieee80211_chanctx_conf *ctx;
7452 ctx = rcu_access_pointer(vif->chanctx_conf);
7453 if (ctx != arg->ctx)
7456 if (WARN_ON(arg->next_vif == arg->n_vifs))
7459 arg->vifs[arg->next_vif].vif = vif;
7460 arg->vifs[arg->next_vif].old_ctx = ctx;
7461 arg->vifs[arg->next_vif].new_ctx = ctx;
7466 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7467 struct ieee80211_chanctx_conf *ctx,
7470 struct ath10k *ar = hw->priv;
7471 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7473 mutex_lock(&ar->conf_mutex);
7475 ath10k_dbg(ar, ATH10K_DBG_MAC,
7476 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7477 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7479 /* This shouldn't really happen because channel switching should use
7480 * switch_vif_chanctx().
7482 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7485 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7486 ieee80211_iterate_active_interfaces_atomic(
7488 IEEE80211_IFACE_ITER_NORMAL,
7489 ath10k_mac_change_chanctx_cnt_iter,
7491 if (arg.n_vifs == 0)
7494 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7499 ieee80211_iterate_active_interfaces_atomic(
7501 IEEE80211_IFACE_ITER_NORMAL,
7502 ath10k_mac_change_chanctx_fill_iter,
7504 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7509 ath10k_recalc_radar_detection(ar);
7511 /* FIXME: How to configure Rx chains properly? */
7513 /* No other actions are actually necessary. Firmware maintains channel
7514 * definitions per vdev internally and there's no host-side channel
7515 * context abstraction to configure, e.g. channel width.
7519 mutex_unlock(&ar->conf_mutex);
7523 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7524 struct ieee80211_vif *vif,
7525 struct ieee80211_chanctx_conf *ctx)
7527 struct ath10k *ar = hw->priv;
7528 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7531 mutex_lock(&ar->conf_mutex);
7533 ath10k_dbg(ar, ATH10K_DBG_MAC,
7534 "mac chanctx assign ptr %pK vdev_id %i\n",
7535 ctx, arvif->vdev_id);
7537 if (WARN_ON(arvif->is_started)) {
7538 mutex_unlock(&ar->conf_mutex);
7542 ret = ath10k_vdev_start(arvif, &ctx->def);
7544 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7545 arvif->vdev_id, vif->addr,
7546 ctx->def.chan->center_freq, ret);
7550 arvif->is_started = true;
7552 ret = ath10k_mac_vif_setup_ps(arvif);
7554 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7555 arvif->vdev_id, ret);
7559 if (vif->type == NL80211_IFTYPE_MONITOR) {
7560 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7562 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7563 arvif->vdev_id, ret);
7567 arvif->is_up = true;
7570 if (ath10k_mac_can_set_cts_prot(arvif)) {
7571 ret = ath10k_mac_set_cts_prot(arvif);
7573 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7574 arvif->vdev_id, ret);
7577 mutex_unlock(&ar->conf_mutex);
7581 ath10k_vdev_stop(arvif);
7582 arvif->is_started = false;
7583 ath10k_mac_vif_setup_ps(arvif);
7586 mutex_unlock(&ar->conf_mutex);
7591 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7592 struct ieee80211_vif *vif,
7593 struct ieee80211_chanctx_conf *ctx)
7595 struct ath10k *ar = hw->priv;
7596 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7599 mutex_lock(&ar->conf_mutex);
7601 ath10k_dbg(ar, ATH10K_DBG_MAC,
7602 "mac chanctx unassign ptr %pK vdev_id %i\n",
7603 ctx, arvif->vdev_id);
7605 WARN_ON(!arvif->is_started);
7606 if (vif->type == NL80211_IFTYPE_MONITOR ||
7607 (vif->type == NL80211_IFTYPE_STATION &&
7608 ar->sta_state < IEEE80211_STA_ASSOC)) {
7609 WARN_ON(!arvif->is_up);
7611 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7613 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7614 arvif->vdev_id, ret);
7616 arvif->is_up = false;
7619 ret = ath10k_vdev_stop(arvif);
7621 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7622 arvif->vdev_id, ret);
7624 ar->sta_state = IEEE80211_STA_NOTEXIST;
7625 arvif->is_started = false;
7627 mutex_unlock(&ar->conf_mutex);
7631 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7632 struct ieee80211_vif_chanctx_switch *vifs,
7634 enum ieee80211_chanctx_switch_mode mode)
7636 struct ath10k *ar = hw->priv;
7638 mutex_lock(&ar->conf_mutex);
7640 ath10k_dbg(ar, ATH10K_DBG_MAC,
7641 "mac chanctx switch n_vifs %d mode %d\n",
7643 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7645 mutex_unlock(&ar->conf_mutex);
7649 static const struct ieee80211_ops ath10k_ops = {
7650 .tx = ath10k_mac_op_tx,
7651 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7652 .start = ath10k_start,
7653 .stop = ath10k_stop,
7654 .config = ath10k_config,
7655 .add_interface = ath10k_add_interface,
7656 .change_interface = ath10k_change_interface,
7657 .remove_interface = ath10k_remove_interface,
7658 .configure_filter = ath10k_configure_filter,
7659 .bss_info_changed = ath10k_bss_info_changed,
7660 .hw_scan = ath10k_hw_scan,
7661 .cancel_hw_scan = ath10k_cancel_hw_scan,
7662 .set_rekey_data = ath10k_set_rekey_data,
7663 .set_key = ath10k_set_key,
7664 .set_default_unicast_key = ath10k_set_default_unicast_key,
7665 .sta_state = ath10k_sta_state,
7666 .conf_tx = ath10k_conf_tx,
7667 .remain_on_channel = ath10k_remain_on_channel,
7668 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7669 .set_rts_threshold = ath10k_set_rts_threshold,
7670 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7671 .flush = ath10k_flush,
7672 .tx_last_beacon = ath10k_tx_last_beacon,
7673 .set_antenna = ath10k_set_antenna,
7674 .get_antenna = ath10k_get_antenna,
7675 .reconfig_complete = ath10k_reconfig_complete,
7676 .get_survey = ath10k_get_survey,
7677 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7678 .sta_rc_update = ath10k_sta_rc_update,
7679 .get_tsf = ath10k_get_tsf,
7680 .set_tsf = ath10k_set_tsf,
7681 .ampdu_action = ath10k_ampdu_action,
7682 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7683 .get_et_stats = ath10k_debug_get_et_stats,
7684 .get_et_strings = ath10k_debug_get_et_strings,
7685 .add_chanctx = ath10k_mac_op_add_chanctx,
7686 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7687 .change_chanctx = ath10k_mac_op_change_chanctx,
7688 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7689 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7690 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7692 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7695 .suspend = ath10k_wow_op_suspend,
7696 .resume = ath10k_wow_op_resume,
7697 .set_wakeup = ath10k_wow_op_set_wakeup,
7699 #ifdef CONFIG_MAC80211_DEBUGFS
7700 .sta_add_debugfs = ath10k_sta_add_debugfs,
7701 .sta_statistics = ath10k_sta_statistics,
7705 #define CHAN2G(_channel, _freq, _flags) { \
7706 .band = IEEE80211_BAND_2GHZ, \
7707 .hw_value = (_channel), \
7708 .center_freq = (_freq), \
7709 .flags = (_flags), \
7710 .max_antenna_gain = 0, \
7714 #define CHAN5G(_channel, _freq, _flags) { \
7715 .band = IEEE80211_BAND_5GHZ, \
7716 .hw_value = (_channel), \
7717 .center_freq = (_freq), \
7718 .flags = (_flags), \
7719 .max_antenna_gain = 0, \
7723 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7733 CHAN2G(10, 2457, 0),
7734 CHAN2G(11, 2462, 0),
7735 CHAN2G(12, 2467, 0),
7736 CHAN2G(13, 2472, 0),
7737 CHAN2G(14, 2484, 0),
7740 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7741 CHAN5G(36, 5180, 0),
7742 CHAN5G(40, 5200, 0),
7743 CHAN5G(44, 5220, 0),
7744 CHAN5G(48, 5240, 0),
7745 CHAN5G(52, 5260, 0),
7746 CHAN5G(56, 5280, 0),
7747 CHAN5G(60, 5300, 0),
7748 CHAN5G(64, 5320, 0),
7749 CHAN5G(100, 5500, 0),
7750 CHAN5G(104, 5520, 0),
7751 CHAN5G(108, 5540, 0),
7752 CHAN5G(112, 5560, 0),
7753 CHAN5G(116, 5580, 0),
7754 CHAN5G(120, 5600, 0),
7755 CHAN5G(124, 5620, 0),
7756 CHAN5G(128, 5640, 0),
7757 CHAN5G(132, 5660, 0),
7758 CHAN5G(136, 5680, 0),
7759 CHAN5G(140, 5700, 0),
7760 CHAN5G(144, 5720, 0),
7761 CHAN5G(149, 5745, 0),
7762 CHAN5G(153, 5765, 0),
7763 CHAN5G(157, 5785, 0),
7764 CHAN5G(161, 5805, 0),
7765 CHAN5G(165, 5825, 0),
7768 struct ath10k *ath10k_mac_create(size_t priv_size)
7770 struct ieee80211_hw *hw;
7771 struct ieee80211_ops *ops;
7774 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7778 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7791 void ath10k_mac_destroy(struct ath10k *ar)
7793 struct ieee80211_ops *ops = ar->ops;
7795 ieee80211_free_hw(ar->hw);
7799 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7802 .types = BIT(NL80211_IFTYPE_STATION)
7803 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7807 .types = BIT(NL80211_IFTYPE_P2P_GO)
7811 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7815 .types = BIT(NL80211_IFTYPE_AP)
7816 #ifdef CONFIG_MAC80211_MESH
7817 | BIT(NL80211_IFTYPE_MESH_POINT)
7822 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7825 .types = BIT(NL80211_IFTYPE_AP)
7826 #ifdef CONFIG_MAC80211_MESH
7827 | BIT(NL80211_IFTYPE_MESH_POINT)
7832 .types = BIT(NL80211_IFTYPE_STATION)
7836 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7838 .limits = ath10k_if_limits,
7839 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7840 .max_interfaces = 8,
7841 .num_different_channels = 1,
7842 .beacon_int_infra_match = true,
7846 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7848 .limits = ath10k_10x_if_limits,
7849 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7850 .max_interfaces = 8,
7851 .num_different_channels = 1,
7852 .beacon_int_infra_match = true,
7853 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7854 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7855 BIT(NL80211_CHAN_WIDTH_20) |
7856 BIT(NL80211_CHAN_WIDTH_40) |
7857 BIT(NL80211_CHAN_WIDTH_80),
7862 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7865 .types = BIT(NL80211_IFTYPE_STATION),
7869 .types = BIT(NL80211_IFTYPE_AP) |
7870 #ifdef CONFIG_MAC80211_MESH
7871 BIT(NL80211_IFTYPE_MESH_POINT) |
7873 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7874 BIT(NL80211_IFTYPE_P2P_GO),
7878 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7882 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7885 .types = BIT(NL80211_IFTYPE_STATION),
7889 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7893 .types = BIT(NL80211_IFTYPE_AP) |
7894 #ifdef CONFIG_MAC80211_MESH
7895 BIT(NL80211_IFTYPE_MESH_POINT) |
7897 BIT(NL80211_IFTYPE_P2P_GO),
7901 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7905 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7908 .types = BIT(NL80211_IFTYPE_STATION),
7912 .types = BIT(NL80211_IFTYPE_ADHOC),
7916 /* FIXME: This is not thouroughly tested. These combinations may over- or
7917 * underestimate hw/fw capabilities.
7919 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7921 .limits = ath10k_tlv_if_limit,
7922 .num_different_channels = 1,
7923 .max_interfaces = 4,
7924 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7927 .limits = ath10k_tlv_if_limit_ibss,
7928 .num_different_channels = 1,
7929 .max_interfaces = 2,
7930 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7934 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7936 .limits = ath10k_tlv_if_limit,
7937 .num_different_channels = 1,
7938 .max_interfaces = 4,
7939 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7942 .limits = ath10k_tlv_qcs_if_limit,
7943 .num_different_channels = 2,
7944 .max_interfaces = 4,
7945 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7948 .limits = ath10k_tlv_if_limit_ibss,
7949 .num_different_channels = 1,
7950 .max_interfaces = 2,
7951 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7955 static const struct ieee80211_iface_limit ath10k_wcn3990_if_limit[] = {
7958 .types = BIT(NL80211_IFTYPE_STATION),
7962 .types = BIT(NL80211_IFTYPE_AP) |
7963 #ifdef CONFIG_MAC80211_MESH
7964 BIT(NL80211_IFTYPE_MESH_POINT) |
7966 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7967 BIT(NL80211_IFTYPE_P2P_GO),
7971 static const struct ieee80211_iface_limit ath10k_wcn3990_qcs_if_limit[] = {
7974 .types = BIT(NL80211_IFTYPE_STATION),
7978 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7982 .types = BIT(NL80211_IFTYPE_AP) |
7983 #ifdef CONFIG_MAC80211_MESH
7984 BIT(NL80211_IFTYPE_MESH_POINT) |
7986 BIT(NL80211_IFTYPE_P2P_GO),
7990 static const struct ieee80211_iface_limit ath10k_wcn3990_if_limit_ibss[] = {
7993 .types = BIT(NL80211_IFTYPE_STATION),
7997 .types = BIT(NL80211_IFTYPE_ADHOC),
8001 static struct ieee80211_iface_combination ath10k_wcn3990_qcs_if_comb[] = {
8003 .limits = ath10k_wcn3990_if_limit,
8004 .num_different_channels = 1,
8005 .max_interfaces = 4,
8006 .n_limits = ARRAY_SIZE(ath10k_wcn3990_if_limit),
8007 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8008 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8009 BIT(NL80211_CHAN_WIDTH_20) |
8010 BIT(NL80211_CHAN_WIDTH_40) |
8011 BIT(NL80211_CHAN_WIDTH_80),
8015 .limits = ath10k_wcn3990_qcs_if_limit,
8016 .num_different_channels = 2,
8017 .max_interfaces = 4,
8018 .n_limits = ARRAY_SIZE(ath10k_wcn3990_qcs_if_limit),
8021 .limits = ath10k_wcn3990_if_limit_ibss,
8022 .num_different_channels = 1,
8023 .max_interfaces = 2,
8024 .n_limits = ARRAY_SIZE(ath10k_wcn3990_if_limit_ibss),
8025 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8026 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8027 BIT(NL80211_CHAN_WIDTH_20) |
8028 BIT(NL80211_CHAN_WIDTH_40) |
8029 BIT(NL80211_CHAN_WIDTH_80),
8034 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
8037 .types = BIT(NL80211_IFTYPE_STATION),
8041 .types = BIT(NL80211_IFTYPE_AP)
8042 #ifdef CONFIG_MAC80211_MESH
8043 | BIT(NL80211_IFTYPE_MESH_POINT)
8048 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
8050 .limits = ath10k_10_4_if_limits,
8051 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
8052 .max_interfaces = 16,
8053 .num_different_channels = 1,
8054 .beacon_int_infra_match = true,
8055 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
8056 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8057 BIT(NL80211_CHAN_WIDTH_20) |
8058 BIT(NL80211_CHAN_WIDTH_40) |
8059 BIT(NL80211_CHAN_WIDTH_80),
8064 static void ath10k_get_arvif_iter(void *data, u8 *mac,
8065 struct ieee80211_vif *vif)
8067 struct ath10k_vif_iter *arvif_iter = data;
8068 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
8070 if (arvif->vdev_id == arvif_iter->vdev_id)
8071 arvif_iter->arvif = arvif;
8074 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
8076 struct ath10k_vif_iter arvif_iter;
8079 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
8080 arvif_iter.vdev_id = vdev_id;
8082 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
8083 ieee80211_iterate_active_interfaces_atomic(ar->hw,
8085 ath10k_get_arvif_iter,
8087 if (!arvif_iter.arvif) {
8088 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
8092 return arvif_iter.arvif;
8095 int ath10k_mac_register(struct ath10k *ar)
8097 static const u32 cipher_suites[] = {
8098 WLAN_CIPHER_SUITE_WEP40,
8099 WLAN_CIPHER_SUITE_WEP104,
8100 WLAN_CIPHER_SUITE_TKIP,
8101 WLAN_CIPHER_SUITE_CCMP,
8102 WLAN_CIPHER_SUITE_AES_CMAC,
8104 struct ieee80211_supported_band *band;
8108 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8110 SET_IEEE80211_DEV(ar->hw, ar->dev);
8112 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
8113 ARRAY_SIZE(ath10k_5ghz_channels)) !=
8116 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
8117 channels = kmemdup(ath10k_2ghz_channels,
8118 sizeof(ath10k_2ghz_channels),
8125 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
8126 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
8127 band->channels = channels;
8129 if (ar->hw_params.cck_rate_map_rev2) {
8130 band->n_bitrates = ath10k_g_rates_rev2_size;
8131 band->bitrates = ath10k_g_rates_rev2;
8133 band->n_bitrates = ath10k_g_rates_size;
8134 band->bitrates = ath10k_g_rates;
8137 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
8140 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
8141 channels = kmemdup(ath10k_5ghz_channels,
8142 sizeof(ath10k_5ghz_channels),
8149 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
8150 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
8151 band->channels = channels;
8152 band->n_bitrates = ath10k_a_rates_size;
8153 band->bitrates = ath10k_a_rates;
8154 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
8157 ath10k_mac_setup_ht_vht_cap(ar);
8159 ar->hw->wiphy->interface_modes =
8160 BIT(NL80211_IFTYPE_STATION) |
8161 BIT(NL80211_IFTYPE_AP) |
8162 BIT(NL80211_IFTYPE_MESH_POINT);
8164 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
8165 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
8167 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
8168 ar->hw->wiphy->interface_modes |=
8169 BIT(NL80211_IFTYPE_P2P_DEVICE) |
8170 BIT(NL80211_IFTYPE_P2P_CLIENT) |
8171 BIT(NL80211_IFTYPE_P2P_GO);
8173 if (QCA_REV_WCN3990(ar))
8174 ar->hw->wiphy->interface_modes &=
8175 ~BIT(NL80211_IFTYPE_P2P_DEVICE);
8177 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8178 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8179 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8180 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8181 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8182 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8183 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8184 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8185 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8186 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8187 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8188 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8189 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8190 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8192 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8193 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8195 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8196 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8198 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
8199 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8201 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
8202 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8203 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8206 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8207 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8209 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
8210 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
8211 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
8213 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
8215 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
8216 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
8218 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
8219 * that userspace (e.g. wpa_supplicant/hostapd) can generate
8220 * correct Probe Responses. This is more of a hack advert..
8222 ar->hw->wiphy->probe_resp_offload |=
8223 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8224 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8225 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8228 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
8229 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8231 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8232 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8233 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8235 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8236 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8237 NL80211_FEATURE_AP_SCAN;
8239 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8241 ret = ath10k_wow_init(ar);
8243 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8247 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8250 * on LL hardware queues are managed entirely by the FW
8251 * so we only advertise to mac we can do the queues thing
8253 ar->hw->queues = IEEE80211_MAX_QUEUES;
8255 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8256 * something that vdev_ids can't reach so that we don't stop the queue
8259 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8261 switch (ar->running_fw->fw_file.wmi_op_version) {
8262 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8263 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8264 ar->hw->wiphy->n_iface_combinations =
8265 ARRAY_SIZE(ath10k_if_comb);
8266 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8268 case ATH10K_FW_WMI_OP_VERSION_TLV:
8269 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8270 if (QCA_REV_WCN3990(ar)) {
8271 ar->hw->wiphy->iface_combinations =
8272 ath10k_wcn3990_qcs_if_comb;
8273 ar->hw->wiphy->n_iface_combinations =
8274 ARRAY_SIZE(ath10k_wcn3990_qcs_if_comb);
8277 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8278 ar->hw->wiphy->iface_combinations =
8279 ath10k_tlv_qcs_if_comb;
8280 ar->hw->wiphy->n_iface_combinations =
8281 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8283 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8284 ar->hw->wiphy->n_iface_combinations =
8285 ARRAY_SIZE(ath10k_tlv_if_comb);
8288 case ATH10K_FW_WMI_OP_VERSION_10_1:
8289 case ATH10K_FW_WMI_OP_VERSION_10_2:
8290 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8291 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8292 ar->hw->wiphy->n_iface_combinations =
8293 ARRAY_SIZE(ath10k_10x_if_comb);
8295 case ATH10K_FW_WMI_OP_VERSION_10_4:
8296 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8297 ar->hw->wiphy->n_iface_combinations =
8298 ARRAY_SIZE(ath10k_10_4_if_comb);
8300 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8301 case ATH10K_FW_WMI_OP_VERSION_MAX:
8307 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8308 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8310 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8311 /* Init ath dfs pattern detector */
8312 ar->ath_common.debug_mask = ATH_DBG_DFS;
8313 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8316 if (!ar->dfs_detector)
8317 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8320 /* Current wake_tx_queue implementation imposes a significant
8321 * performance penalty in some setups. The tx scheduling code needs
8322 * more work anyway so disable the wake_tx_queue unless firmware
8323 * supports the pull-push mechanism.
8325 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8326 ar->running_fw->fw_file.fw_features))
8327 ar->ops->wake_tx_queue = NULL;
8329 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8330 ath10k_reg_notifier);
8332 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8333 goto err_dfs_detector_exit;
8336 ar->hw->wiphy->cipher_suites = cipher_suites;
8337 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8339 ret = ieee80211_register_hw(ar->hw);
8341 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8342 goto err_dfs_detector_exit;
8345 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8346 ret = regulatory_hint(ar->hw->wiphy,
8347 ar->ath_common.regulatory.alpha2);
8349 goto err_unregister;
8355 ieee80211_unregister_hw(ar->hw);
8357 err_dfs_detector_exit:
8358 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8359 ar->dfs_detector->exit(ar->dfs_detector);
8362 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
8363 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
8365 SET_IEEE80211_DEV(ar->hw, NULL);
8369 void ath10k_mac_unregister(struct ath10k *ar)
8371 ath10k_wow_deinit(ar);
8372 ieee80211_unregister_hw(ar->hw);
8374 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8375 ar->dfs_detector->exit(ar->dfs_detector);
8377 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
8378 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
8380 SET_IEEE80211_DEV(ar->hw, NULL);