2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
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 NL80211_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 NL80211_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_create(struct ath10k *ar,
671 struct ieee80211_vif *vif,
672 struct ieee80211_sta *sta,
675 enum wmi_peer_type peer_type)
677 struct ath10k_vif *arvif;
678 struct ath10k_peer *peer;
682 lockdep_assert_held(&ar->conf_mutex);
684 num_peers = ar->num_peers;
686 /* Each vdev consumes a peer entry as well */
687 list_for_each_entry(arvif, &ar->arvifs, list)
690 if (num_peers >= ar->max_num_peers)
693 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
695 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
700 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
702 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
707 spin_lock_bh(&ar->data_lock);
709 peer = ath10k_peer_find(ar, vdev_id, addr);
711 spin_unlock_bh(&ar->data_lock);
712 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
714 ath10k_wmi_peer_delete(ar, vdev_id, addr);
721 spin_unlock_bh(&ar->data_lock);
728 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
730 struct ath10k *ar = arvif->ar;
734 param = ar->wmi.pdev_param->sta_kickout_th;
735 ret = ath10k_wmi_pdev_set_param(ar, param,
736 ATH10K_KICKOUT_THRESHOLD);
738 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
739 arvif->vdev_id, ret);
743 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
744 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
745 ATH10K_KEEPALIVE_MIN_IDLE);
747 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
748 arvif->vdev_id, ret);
752 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
753 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
754 ATH10K_KEEPALIVE_MAX_IDLE);
756 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
757 arvif->vdev_id, ret);
761 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
762 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
763 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
765 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
766 arvif->vdev_id, ret);
773 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
775 struct ath10k *ar = arvif->ar;
778 vdev_param = ar->wmi.vdev_param->rts_threshold;
779 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
782 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
786 lockdep_assert_held(&ar->conf_mutex);
788 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
792 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
801 static void ath10k_peer_map_cleanup(struct ath10k *ar, struct ath10k_peer *peer)
805 lockdep_assert_held(&ar->conf_mutex);
807 for_each_set_bit(peer_id, peer->peer_ids,
808 ATH10K_MAX_NUM_PEER_IDS) {
809 ar->peer_map[peer_id] = NULL;
812 /* Double check that peer is properly un-referenced from
815 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
816 if (ar->peer_map[i] == peer) {
817 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
818 peer->addr, peer, i);
819 ar->peer_map[i] = NULL;
823 list_del(&peer->list);
828 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
830 struct ath10k_peer *peer, *tmp;
832 lockdep_assert_held(&ar->conf_mutex);
834 spin_lock_bh(&ar->data_lock);
835 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
836 if (peer->vdev_id != vdev_id)
839 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
840 peer->addr, vdev_id);
842 ath10k_peer_map_cleanup(ar, peer);
844 spin_unlock_bh(&ar->data_lock);
847 static void ath10k_peer_cleanup_all(struct ath10k *ar)
849 struct ath10k_peer *peer, *tmp;
852 lockdep_assert_held(&ar->conf_mutex);
854 spin_lock_bh(&ar->data_lock);
855 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
856 list_del(&peer->list);
860 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
861 ar->peer_map[i] = NULL;
863 spin_unlock_bh(&ar->data_lock);
866 ar->num_stations = 0;
869 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
870 struct ieee80211_sta *sta,
871 enum wmi_tdls_peer_state state)
874 struct wmi_tdls_peer_update_cmd_arg arg = {};
875 struct wmi_tdls_peer_capab_arg cap = {};
876 struct wmi_channel_arg chan_arg = {};
878 lockdep_assert_held(&ar->conf_mutex);
880 arg.vdev_id = vdev_id;
881 arg.peer_state = state;
882 ether_addr_copy(arg.addr, sta->addr);
884 cap.peer_max_sp = sta->max_sp;
885 cap.peer_uapsd_queues = sta->uapsd_queues;
887 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
888 !sta->tdls_initiator)
889 cap.is_peer_responder = 1;
891 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
893 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
894 arg.addr, vdev_id, ret);
901 /************************/
902 /* Interface management */
903 /************************/
905 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
907 struct ath10k *ar = arvif->ar;
909 lockdep_assert_held(&ar->data_lock);
914 if (!arvif->beacon_buf)
915 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
916 arvif->beacon->len, DMA_TO_DEVICE);
918 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
919 arvif->beacon_state != ATH10K_BEACON_SENT))
922 dev_kfree_skb_any(arvif->beacon);
924 arvif->beacon = NULL;
925 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
928 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
930 struct ath10k *ar = arvif->ar;
932 lockdep_assert_held(&ar->data_lock);
934 ath10k_mac_vif_beacon_free(arvif);
936 if (arvif->beacon_buf) {
937 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
938 arvif->beacon_buf, arvif->beacon_paddr);
939 arvif->beacon_buf = NULL;
943 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
945 unsigned long time_left;
947 lockdep_assert_held(&ar->conf_mutex);
949 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
952 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
953 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
957 return ar->last_wmi_vdev_start_status;
960 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
962 struct cfg80211_chan_def *chandef = NULL;
963 struct ieee80211_channel *channel = NULL;
964 struct wmi_vdev_start_request_arg arg = {};
967 lockdep_assert_held(&ar->conf_mutex);
969 ieee80211_iter_chan_contexts_atomic(ar->hw,
970 ath10k_mac_get_any_chandef_iter,
972 if (WARN_ON_ONCE(!chandef))
975 channel = chandef->chan;
977 arg.vdev_id = vdev_id;
978 arg.channel.freq = channel->center_freq;
979 arg.channel.band_center_freq1 = chandef->center_freq1;
981 /* TODO setup this dynamically, what in case we
982 don't have any vifs? */
983 arg.channel.mode = chan_to_phymode(chandef);
984 arg.channel.chan_radar =
985 !!(channel->flags & IEEE80211_CHAN_RADAR);
987 arg.channel.min_power = 0;
988 arg.channel.max_power = channel->max_power * 2;
989 arg.channel.max_reg_power = channel->max_reg_power * 2;
990 arg.channel.max_antenna_gain = channel->max_antenna_gain;
992 reinit_completion(&ar->vdev_setup_done);
994 ret = ath10k_wmi_vdev_start(ar, &arg);
996 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
1001 ret = ath10k_vdev_setup_sync(ar);
1003 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1008 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1010 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1015 ar->monitor_vdev_id = vdev_id;
1017 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1018 ar->monitor_vdev_id);
1022 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1024 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1025 ar->monitor_vdev_id, ret);
1030 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1034 lockdep_assert_held(&ar->conf_mutex);
1036 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1038 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1039 ar->monitor_vdev_id, ret);
1041 reinit_completion(&ar->vdev_setup_done);
1043 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1045 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1046 ar->monitor_vdev_id, ret);
1048 ret = ath10k_vdev_setup_sync(ar);
1050 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1051 ar->monitor_vdev_id, ret);
1053 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1054 ar->monitor_vdev_id);
1058 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1062 lockdep_assert_held(&ar->conf_mutex);
1064 if (ar->free_vdev_map == 0) {
1065 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1069 bit = __ffs64(ar->free_vdev_map);
1071 ar->monitor_vdev_id = bit;
1073 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1074 WMI_VDEV_TYPE_MONITOR,
1077 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1078 ar->monitor_vdev_id, ret);
1082 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1083 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1084 ar->monitor_vdev_id);
1089 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1093 lockdep_assert_held(&ar->conf_mutex);
1095 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1097 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1098 ar->monitor_vdev_id, ret);
1102 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1104 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1105 ar->monitor_vdev_id);
1109 static int ath10k_monitor_start(struct ath10k *ar)
1113 lockdep_assert_held(&ar->conf_mutex);
1115 ret = ath10k_monitor_vdev_create(ar);
1117 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1121 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1123 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1124 ath10k_monitor_vdev_delete(ar);
1128 ar->monitor_started = true;
1129 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1134 static int ath10k_monitor_stop(struct ath10k *ar)
1138 lockdep_assert_held(&ar->conf_mutex);
1140 ret = ath10k_monitor_vdev_stop(ar);
1142 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1146 ret = ath10k_monitor_vdev_delete(ar);
1148 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1152 ar->monitor_started = false;
1153 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1158 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1162 /* At least one chanctx is required to derive a channel to start
1165 num_ctx = ath10k_mac_num_chanctxs(ar);
1169 /* If there's already an existing special monitor interface then don't
1170 * bother creating another monitor vdev.
1172 if (ar->monitor_arvif)
1175 return ar->monitor ||
1176 ar->filter_flags & FIF_OTHER_BSS ||
1177 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1180 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1184 num_ctx = ath10k_mac_num_chanctxs(ar);
1186 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1187 * shouldn't allow this but make sure to prevent handling the following
1188 * case anyway since multi-channel DFS hasn't been tested at all.
1190 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1196 static int ath10k_monitor_recalc(struct ath10k *ar)
1202 lockdep_assert_held(&ar->conf_mutex);
1204 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1205 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1207 ath10k_dbg(ar, ATH10K_DBG_MAC,
1208 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1209 ar->monitor_started, needed, allowed);
1211 if (WARN_ON(needed && !allowed)) {
1212 if (ar->monitor_started) {
1213 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1215 ret = ath10k_monitor_stop(ar);
1217 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1225 if (needed == ar->monitor_started)
1229 return ath10k_monitor_start(ar);
1231 return ath10k_monitor_stop(ar);
1234 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1236 struct ath10k *ar = arvif->ar;
1238 lockdep_assert_held(&ar->conf_mutex);
1240 if (!arvif->is_started) {
1241 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1248 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1250 struct ath10k *ar = arvif->ar;
1253 lockdep_assert_held(&ar->conf_mutex);
1255 vdev_param = ar->wmi.vdev_param->protection_mode;
1257 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1258 arvif->vdev_id, arvif->use_cts_prot);
1260 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1261 arvif->use_cts_prot ? 1 : 0);
1264 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1266 struct ath10k *ar = arvif->ar;
1267 u32 vdev_param, rts_cts = 0;
1269 lockdep_assert_held(&ar->conf_mutex);
1271 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1273 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1275 if (arvif->num_legacy_stations > 0)
1276 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1277 WMI_RTSCTS_PROFILE);
1279 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1280 WMI_RTSCTS_PROFILE);
1282 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1286 static int ath10k_start_cac(struct ath10k *ar)
1290 lockdep_assert_held(&ar->conf_mutex);
1292 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1294 ret = ath10k_monitor_recalc(ar);
1296 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1297 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1301 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1302 ar->monitor_vdev_id);
1307 static int ath10k_stop_cac(struct ath10k *ar)
1309 lockdep_assert_held(&ar->conf_mutex);
1311 /* CAC is not running - do nothing */
1312 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1315 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1316 ath10k_monitor_stop(ar);
1318 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1323 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1324 struct ieee80211_chanctx_conf *conf,
1329 if (!*ret && conf->radar_enabled)
1333 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1335 bool has_radar = false;
1337 ieee80211_iter_chan_contexts_atomic(ar->hw,
1338 ath10k_mac_has_radar_iter,
1344 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1348 lockdep_assert_held(&ar->conf_mutex);
1350 ath10k_stop_cac(ar);
1352 if (!ath10k_mac_has_radar_enabled(ar))
1355 if (ar->num_started_vdevs > 0)
1358 ret = ath10k_start_cac(ar);
1361 * Not possible to start CAC on current channel so starting
1362 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1363 * by indicating that radar was detected.
1365 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1366 ieee80211_radar_detected(ar->hw);
1370 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1372 struct ath10k *ar = arvif->ar;
1375 lockdep_assert_held(&ar->conf_mutex);
1377 reinit_completion(&ar->vdev_setup_done);
1379 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1381 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1382 arvif->vdev_id, ret);
1386 ret = ath10k_vdev_setup_sync(ar);
1388 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1389 arvif->vdev_id, ret);
1393 WARN_ON(ar->num_started_vdevs == 0);
1395 if (ar->num_started_vdevs != 0) {
1396 ar->num_started_vdevs--;
1397 ath10k_recalc_radar_detection(ar);
1403 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1404 const struct cfg80211_chan_def *chandef,
1407 struct ath10k *ar = arvif->ar;
1408 struct wmi_vdev_start_request_arg arg = {};
1411 lockdep_assert_held(&ar->conf_mutex);
1413 reinit_completion(&ar->vdev_setup_done);
1415 arg.vdev_id = arvif->vdev_id;
1416 arg.dtim_period = arvif->dtim_period;
1417 arg.bcn_intval = arvif->beacon_interval;
1419 arg.channel.freq = chandef->chan->center_freq;
1420 arg.channel.band_center_freq1 = chandef->center_freq1;
1421 arg.channel.mode = chan_to_phymode(chandef);
1423 arg.channel.min_power = 0;
1424 arg.channel.max_power = chandef->chan->max_power * 2;
1425 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1426 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
1428 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1429 arg.ssid = arvif->u.ap.ssid;
1430 arg.ssid_len = arvif->u.ap.ssid_len;
1431 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1433 /* For now allow DFS for AP mode */
1434 arg.channel.chan_radar =
1435 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1436 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1437 arg.ssid = arvif->vif->bss_conf.ssid;
1438 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1441 ath10k_dbg(ar, ATH10K_DBG_MAC,
1442 "mac vdev %d start center_freq %d phymode %s\n",
1443 arg.vdev_id, arg.channel.freq,
1444 ath10k_wmi_phymode_str(arg.channel.mode));
1447 ret = ath10k_wmi_vdev_restart(ar, &arg);
1449 ret = ath10k_wmi_vdev_start(ar, &arg);
1452 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1457 ret = ath10k_vdev_setup_sync(ar);
1460 "failed to synchronize setup for vdev %i restart %d: %d\n",
1461 arg.vdev_id, restart, ret);
1465 ar->num_started_vdevs++;
1466 ath10k_recalc_radar_detection(ar);
1471 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1472 const struct cfg80211_chan_def *def)
1474 return ath10k_vdev_start_restart(arvif, def, false);
1477 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1478 const struct cfg80211_chan_def *def)
1480 return ath10k_vdev_start_restart(arvif, def, true);
1483 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1484 struct sk_buff *bcn)
1486 struct ath10k *ar = arvif->ar;
1487 struct ieee80211_mgmt *mgmt;
1491 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1494 mgmt = (void *)bcn->data;
1495 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1496 mgmt->u.beacon.variable,
1497 bcn->len - (mgmt->u.beacon.variable -
1502 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1504 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1505 arvif->vdev_id, ret);
1512 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1513 u8 oui_type, size_t ie_offset)
1520 if (WARN_ON(skb->len < ie_offset))
1523 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1524 skb->data + ie_offset,
1525 skb->len - ie_offset);
1530 end = skb->data + skb->len;
1533 if (WARN_ON(next > end))
1536 memmove(ie, next, end - next);
1537 skb_trim(skb, skb->len - len);
1542 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1544 struct ath10k *ar = arvif->ar;
1545 struct ieee80211_hw *hw = ar->hw;
1546 struct ieee80211_vif *vif = arvif->vif;
1547 struct ieee80211_mutable_offsets offs = {};
1548 struct sk_buff *bcn;
1551 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1554 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1555 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1558 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1560 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1564 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1566 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1571 /* P2P IE is inserted by firmware automatically (as configured above)
1572 * so remove it from the base beacon template to avoid duplicate P2P
1573 * IEs in beacon frames.
1575 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1576 offsetof(struct ieee80211_mgmt,
1577 u.beacon.variable));
1579 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1584 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1592 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1594 struct ath10k *ar = arvif->ar;
1595 struct ieee80211_hw *hw = ar->hw;
1596 struct ieee80211_vif *vif = arvif->vif;
1597 struct sk_buff *prb;
1600 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1603 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1606 /* For mesh, probe response and beacon share the same template */
1607 if (ieee80211_vif_is_mesh(vif))
1610 prb = ieee80211_proberesp_get(hw, vif);
1612 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1616 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1620 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1628 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1630 struct ath10k *ar = arvif->ar;
1631 struct cfg80211_chan_def def;
1634 /* When originally vdev is started during assign_vif_chanctx() some
1635 * information is missing, notably SSID. Firmware revisions with beacon
1636 * offloading require the SSID to be provided during vdev (re)start to
1637 * handle hidden SSID properly.
1639 * Vdev restart must be done after vdev has been both started and
1640 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1641 * deliver vdev restart response event causing timeouts during vdev
1642 * syncing in ath10k.
1644 * Note: The vdev down/up and template reinstallation could be skipped
1645 * since only wmi-tlv firmware are known to have beacon offload and
1646 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1647 * response delivery. It's probably more robust to keep it as is.
1649 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1652 if (WARN_ON(!arvif->is_started))
1655 if (WARN_ON(!arvif->is_up))
1658 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1661 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1663 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1664 arvif->vdev_id, ret);
1668 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1669 * firmware will crash upon vdev up.
1672 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1674 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1678 ret = ath10k_mac_setup_prb_tmpl(arvif);
1680 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1684 ret = ath10k_vdev_restart(arvif, &def);
1686 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1687 arvif->vdev_id, ret);
1691 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1694 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1695 arvif->vdev_id, ret);
1702 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1703 struct ieee80211_bss_conf *info)
1705 struct ath10k *ar = arvif->ar;
1708 lockdep_assert_held(&arvif->ar->conf_mutex);
1710 if (!info->enable_beacon) {
1711 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1713 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1714 arvif->vdev_id, ret);
1716 arvif->is_up = false;
1718 spin_lock_bh(&arvif->ar->data_lock);
1719 ath10k_mac_vif_beacon_free(arvif);
1720 spin_unlock_bh(&arvif->ar->data_lock);
1725 arvif->tx_seq_no = 0x1000;
1728 ether_addr_copy(arvif->bssid, info->bssid);
1730 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1733 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1734 arvif->vdev_id, ret);
1738 arvif->is_up = true;
1740 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1742 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1743 arvif->vdev_id, ret);
1747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1750 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1751 struct ieee80211_bss_conf *info,
1752 const u8 self_peer[ETH_ALEN])
1754 struct ath10k *ar = arvif->ar;
1758 lockdep_assert_held(&arvif->ar->conf_mutex);
1760 if (!info->ibss_joined) {
1761 if (is_zero_ether_addr(arvif->bssid))
1764 eth_zero_addr(arvif->bssid);
1769 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1770 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1771 ATH10K_DEFAULT_ATIM);
1773 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1774 arvif->vdev_id, ret);
1777 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1779 struct ath10k *ar = arvif->ar;
1784 lockdep_assert_held(&arvif->ar->conf_mutex);
1786 if (arvif->u.sta.uapsd)
1787 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1789 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1791 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1792 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1794 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1795 value, arvif->vdev_id, ret);
1802 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1804 struct ath10k *ar = arvif->ar;
1809 lockdep_assert_held(&arvif->ar->conf_mutex);
1811 if (arvif->u.sta.uapsd)
1812 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1814 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1816 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1817 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1820 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1821 value, arvif->vdev_id, ret);
1828 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1830 struct ath10k_vif *arvif;
1833 lockdep_assert_held(&ar->conf_mutex);
1835 list_for_each_entry(arvif, &ar->arvifs, list)
1836 if (arvif->is_started)
1842 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1844 struct ath10k *ar = arvif->ar;
1845 struct ieee80211_vif *vif = arvif->vif;
1846 struct ieee80211_conf *conf = &ar->hw->conf;
1847 enum wmi_sta_powersave_param param;
1848 enum wmi_sta_ps_mode psmode;
1853 lockdep_assert_held(&arvif->ar->conf_mutex);
1855 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1858 enable_ps = arvif->ps;
1860 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1861 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1862 ar->running_fw->fw_file.fw_features)) {
1863 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1868 if (!arvif->is_started) {
1869 /* mac80211 can update vif powersave state while disconnected.
1870 * Firmware doesn't behave nicely and consumes more power than
1871 * necessary if PS is disabled on a non-started vdev. Hence
1872 * force-enable PS for non-running vdevs.
1874 psmode = WMI_STA_PS_MODE_ENABLED;
1875 } else if (enable_ps) {
1876 psmode = WMI_STA_PS_MODE_ENABLED;
1877 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1879 ps_timeout = conf->dynamic_ps_timeout;
1880 if (ps_timeout == 0) {
1881 /* Firmware doesn't like 0 */
1882 ps_timeout = ieee80211_tu_to_usec(
1883 vif->bss_conf.beacon_int) / 1000;
1886 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1889 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1890 arvif->vdev_id, ret);
1894 psmode = WMI_STA_PS_MODE_DISABLED;
1897 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1898 arvif->vdev_id, psmode ? "enable" : "disable");
1900 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1902 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1903 psmode, arvif->vdev_id, ret);
1910 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1912 struct ath10k *ar = arvif->ar;
1913 struct wmi_sta_keepalive_arg arg = {};
1916 lockdep_assert_held(&arvif->ar->conf_mutex);
1918 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1921 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1924 /* Some firmware revisions have a bug and ignore the `enabled` field.
1925 * Instead use the interval to disable the keepalive.
1927 arg.vdev_id = arvif->vdev_id;
1929 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1930 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1932 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1934 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1935 arvif->vdev_id, ret);
1942 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1944 struct ath10k *ar = arvif->ar;
1945 struct ieee80211_vif *vif = arvif->vif;
1948 lockdep_assert_held(&arvif->ar->conf_mutex);
1950 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1953 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1956 if (!vif->csa_active)
1962 if (!ieee80211_csa_is_complete(vif)) {
1963 ieee80211_csa_update_counter(vif);
1965 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1967 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1970 ret = ath10k_mac_setup_prb_tmpl(arvif);
1972 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1975 ieee80211_csa_finish(vif);
1979 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1981 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1983 struct ath10k *ar = arvif->ar;
1985 mutex_lock(&ar->conf_mutex);
1986 ath10k_mac_vif_ap_csa_count_down(arvif);
1987 mutex_unlock(&ar->conf_mutex);
1990 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1991 struct ieee80211_vif *vif)
1993 struct sk_buff *skb = data;
1994 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1995 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1997 if (vif->type != NL80211_IFTYPE_STATION)
2000 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
2003 cancel_delayed_work(&arvif->connection_loss_work);
2006 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2008 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2009 IEEE80211_IFACE_ITER_NORMAL,
2010 ath10k_mac_handle_beacon_iter,
2014 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2015 struct ieee80211_vif *vif)
2017 u32 *vdev_id = data;
2018 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2019 struct ath10k *ar = arvif->ar;
2020 struct ieee80211_hw *hw = ar->hw;
2022 if (arvif->vdev_id != *vdev_id)
2028 ieee80211_beacon_loss(vif);
2030 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2031 * (done by mac80211) succeeds but beacons do not resume then it
2032 * doesn't make sense to continue operation. Queue connection loss work
2033 * which can be cancelled when beacon is received.
2035 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2036 ATH10K_CONNECTION_LOSS_HZ);
2039 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2041 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2042 IEEE80211_IFACE_ITER_NORMAL,
2043 ath10k_mac_handle_beacon_miss_iter,
2047 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2049 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2050 connection_loss_work.work);
2051 struct ieee80211_vif *vif = arvif->vif;
2056 ieee80211_connection_loss(vif);
2059 /**********************/
2060 /* Station management */
2061 /**********************/
2063 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2064 struct ieee80211_vif *vif)
2066 /* Some firmware revisions have unstable STA powersave when listen
2067 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2068 * generate NullFunc frames properly even if buffered frames have been
2069 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2070 * buffered frames. Often pinging the device from AP would simply fail.
2072 * As a workaround set it to 1.
2074 if (vif->type == NL80211_IFTYPE_STATION)
2077 return ar->hw->conf.listen_interval;
2080 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2081 struct ieee80211_vif *vif,
2082 struct ieee80211_sta *sta,
2083 struct wmi_peer_assoc_complete_arg *arg)
2085 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2088 lockdep_assert_held(&ar->conf_mutex);
2090 if (vif->type == NL80211_IFTYPE_STATION)
2091 aid = vif->bss_conf.aid;
2095 ether_addr_copy(arg->addr, sta->addr);
2096 arg->vdev_id = arvif->vdev_id;
2097 arg->peer_aid = aid;
2098 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2099 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2100 arg->peer_num_spatial_streams = 1;
2101 arg->peer_caps = vif->bss_conf.assoc_capability;
2104 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2105 struct ieee80211_vif *vif,
2106 struct ieee80211_sta *sta,
2107 struct wmi_peer_assoc_complete_arg *arg)
2109 struct ieee80211_bss_conf *info = &vif->bss_conf;
2110 struct cfg80211_chan_def def;
2111 struct cfg80211_bss *bss;
2112 const u8 *rsnie = NULL;
2113 const u8 *wpaie = NULL;
2115 lockdep_assert_held(&ar->conf_mutex);
2117 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2120 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2121 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2123 const struct cfg80211_bss_ies *ies;
2126 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2128 ies = rcu_dereference(bss->ies);
2130 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2131 WLAN_OUI_TYPE_MICROSOFT_WPA,
2135 cfg80211_put_bss(ar->hw->wiphy, bss);
2138 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2139 if (rsnie || wpaie) {
2140 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2141 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2145 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2146 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2150 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2151 ar->running_fw->fw_file.fw_features)) {
2152 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2156 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2157 struct ieee80211_vif *vif,
2158 struct ieee80211_sta *sta,
2159 struct wmi_peer_assoc_complete_arg *arg)
2161 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2162 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2163 struct cfg80211_chan_def def;
2164 const struct ieee80211_supported_band *sband;
2165 const struct ieee80211_rate *rates;
2166 enum nl80211_band band;
2171 lockdep_assert_held(&ar->conf_mutex);
2173 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2176 band = def.chan->band;
2177 sband = ar->hw->wiphy->bands[band];
2178 ratemask = sta->supp_rates[band];
2179 ratemask &= arvif->bitrate_mask.control[band].legacy;
2180 rates = sband->bitrates;
2182 rateset->num_rates = 0;
2184 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2185 if (!(ratemask & 1))
2188 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2189 rateset->rates[rateset->num_rates] = rate;
2190 rateset->num_rates++;
2195 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2199 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2200 if (ht_mcs_mask[nss])
2207 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2211 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2212 if (vht_mcs_mask[nss])
2218 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2219 struct ieee80211_vif *vif,
2220 struct ieee80211_sta *sta,
2221 struct wmi_peer_assoc_complete_arg *arg)
2223 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2224 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2225 struct cfg80211_chan_def def;
2226 enum nl80211_band band;
2227 const u8 *ht_mcs_mask;
2228 const u16 *vht_mcs_mask;
2233 lockdep_assert_held(&ar->conf_mutex);
2235 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2238 if (!ht_cap->ht_supported)
2241 band = def.chan->band;
2242 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2243 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2245 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2246 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2249 arg->peer_flags |= ar->wmi.peer_flags->ht;
2250 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2251 ht_cap->ampdu_factor)) - 1;
2253 arg->peer_mpdu_density =
2254 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2256 arg->peer_ht_caps = ht_cap->cap;
2257 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2259 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2260 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2262 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2263 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2264 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2267 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2268 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2269 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2271 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2272 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2275 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2276 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2277 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2280 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2281 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2282 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2283 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2284 arg->peer_rate_caps |= stbc;
2285 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2288 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2289 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2290 else if (ht_cap->mcs.rx_mask[1])
2291 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2293 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2294 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2295 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2296 max_nss = (i / 8) + 1;
2297 arg->peer_ht_rates.rates[n++] = i;
2301 * This is a workaround for HT-enabled STAs which break the spec
2302 * and have no HT capabilities RX mask (no HT RX MCS map).
2304 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2305 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2307 * Firmware asserts if such situation occurs.
2310 arg->peer_ht_rates.num_rates = 8;
2311 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2312 arg->peer_ht_rates.rates[i] = i;
2314 arg->peer_ht_rates.num_rates = n;
2315 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2318 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2320 arg->peer_ht_rates.num_rates,
2321 arg->peer_num_spatial_streams);
2324 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2325 struct ath10k_vif *arvif,
2326 struct ieee80211_sta *sta)
2332 lockdep_assert_held(&ar->conf_mutex);
2334 if (sta->wme && sta->uapsd_queues) {
2335 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2336 sta->uapsd_queues, sta->max_sp);
2338 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2339 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2340 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2341 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2342 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2343 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2344 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2345 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2346 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2347 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2348 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2349 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2351 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2352 max_sp = sta->max_sp;
2354 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2356 WMI_AP_PS_PEER_PARAM_UAPSD,
2359 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2360 arvif->vdev_id, ret);
2364 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2366 WMI_AP_PS_PEER_PARAM_MAX_SP,
2369 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2370 arvif->vdev_id, ret);
2374 /* TODO setup this based on STA listen interval and
2375 beacon interval. Currently we don't know
2376 sta->listen_interval - mac80211 patch required.
2377 Currently use 10 seconds */
2378 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2379 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2382 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2383 arvif->vdev_id, ret);
2392 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2393 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2400 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2401 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2405 idx_limit = fls(mcs_map) - 1;
2409 switch (idx_limit) {
2410 case 0: /* fall through */
2411 case 1: /* fall through */
2412 case 2: /* fall through */
2413 case 3: /* fall through */
2414 case 4: /* fall through */
2415 case 5: /* fall through */
2416 case 6: /* fall through */
2418 /* see ath10k_mac_can_set_bitrate_mask() */
2422 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2425 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2428 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2431 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2435 tx_mcs_set &= ~(0x3 << (nss * 2));
2436 tx_mcs_set |= mcs << (nss * 2);
2442 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2443 struct ieee80211_vif *vif,
2444 struct ieee80211_sta *sta,
2445 struct wmi_peer_assoc_complete_arg *arg)
2447 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2448 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2449 struct cfg80211_chan_def def;
2450 enum nl80211_band band;
2451 const u16 *vht_mcs_mask;
2454 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2457 if (!vht_cap->vht_supported)
2460 band = def.chan->band;
2461 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2463 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2466 arg->peer_flags |= ar->wmi.peer_flags->vht;
2468 if (def.chan->band == NL80211_BAND_2GHZ)
2469 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2471 arg->peer_vht_caps = vht_cap->cap;
2473 ampdu_factor = (vht_cap->cap &
2474 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2475 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2477 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2478 * zero in VHT IE. Using it would result in degraded throughput.
2479 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2480 * it if VHT max_mpdu is smaller. */
2481 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2482 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2483 ampdu_factor)) - 1);
2485 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2486 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2488 arg->peer_vht_rates.rx_max_rate =
2489 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2490 arg->peer_vht_rates.rx_mcs_set =
2491 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2492 arg->peer_vht_rates.tx_max_rate =
2493 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2494 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2495 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2497 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2498 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2501 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2502 struct ieee80211_vif *vif,
2503 struct ieee80211_sta *sta,
2504 struct wmi_peer_assoc_complete_arg *arg)
2506 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2508 switch (arvif->vdev_type) {
2509 case WMI_VDEV_TYPE_AP:
2511 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2513 if (sta->wme && sta->uapsd_queues) {
2514 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2515 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2518 case WMI_VDEV_TYPE_STA:
2520 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2522 case WMI_VDEV_TYPE_IBSS:
2524 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2530 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2531 sta->addr, !!(arg->peer_flags &
2532 arvif->ar->wmi.peer_flags->qos));
2535 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2537 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2538 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2541 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2542 struct ieee80211_vif *vif,
2543 struct ieee80211_sta *sta,
2544 struct wmi_peer_assoc_complete_arg *arg)
2546 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2547 struct cfg80211_chan_def def;
2548 enum nl80211_band band;
2549 const u8 *ht_mcs_mask;
2550 const u16 *vht_mcs_mask;
2551 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2553 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2556 band = def.chan->band;
2557 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2558 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2561 case NL80211_BAND_2GHZ:
2562 if (sta->vht_cap.vht_supported &&
2563 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2564 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2565 phymode = MODE_11AC_VHT40;
2567 phymode = MODE_11AC_VHT20;
2568 } else if (sta->ht_cap.ht_supported &&
2569 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2570 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2571 phymode = MODE_11NG_HT40;
2573 phymode = MODE_11NG_HT20;
2574 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2581 case NL80211_BAND_5GHZ:
2585 if (sta->vht_cap.vht_supported &&
2586 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2587 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2588 phymode = MODE_11AC_VHT80;
2589 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2590 phymode = MODE_11AC_VHT40;
2591 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2592 phymode = MODE_11AC_VHT20;
2593 } else if (sta->ht_cap.ht_supported &&
2594 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2595 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2596 phymode = MODE_11NA_HT40;
2598 phymode = MODE_11NA_HT20;
2608 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2609 sta->addr, ath10k_wmi_phymode_str(phymode));
2611 arg->peer_phymode = phymode;
2612 WARN_ON(phymode == MODE_UNKNOWN);
2615 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2616 struct ieee80211_vif *vif,
2617 struct ieee80211_sta *sta,
2618 struct wmi_peer_assoc_complete_arg *arg)
2620 lockdep_assert_held(&ar->conf_mutex);
2622 memset(arg, 0, sizeof(*arg));
2624 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2625 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2626 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2627 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2628 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2629 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2630 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2635 static const u32 ath10k_smps_map[] = {
2636 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2637 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2638 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2639 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2642 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2644 const struct ieee80211_sta_ht_cap *ht_cap)
2648 if (!ht_cap->ht_supported)
2651 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2652 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2654 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2657 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2658 WMI_PEER_SMPS_STATE,
2659 ath10k_smps_map[smps]);
2662 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2663 struct ieee80211_vif *vif,
2664 struct ieee80211_sta_vht_cap vht_cap)
2666 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2671 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2674 if (!(ar->vht_cap_info &
2675 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2676 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2677 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2678 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2681 param = ar->wmi.vdev_param->txbf;
2684 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2687 /* The following logic is correct. If a remote STA advertises support
2688 * for being a beamformer then we should enable us being a beamformee.
2691 if (ar->vht_cap_info &
2692 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2693 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2694 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2695 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2697 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2698 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2701 if (ar->vht_cap_info &
2702 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2703 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2704 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2705 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2707 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2708 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2711 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2712 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2714 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2715 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2717 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2719 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2727 /* can be called only in mac80211 callbacks due to `key_count` usage */
2728 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2729 struct ieee80211_vif *vif,
2730 struct ieee80211_bss_conf *bss_conf)
2732 struct ath10k *ar = hw->priv;
2733 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2734 struct ieee80211_sta_ht_cap ht_cap;
2735 struct ieee80211_sta_vht_cap vht_cap;
2736 struct wmi_peer_assoc_complete_arg peer_arg;
2737 struct ieee80211_sta *ap_sta;
2740 lockdep_assert_held(&ar->conf_mutex);
2742 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2743 arvif->vdev_id, arvif->bssid, arvif->aid);
2747 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2749 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2750 bss_conf->bssid, arvif->vdev_id);
2755 /* ap_sta must be accessed only within rcu section which must be left
2756 * before calling ath10k_setup_peer_smps() which might sleep. */
2757 ht_cap = ap_sta->ht_cap;
2758 vht_cap = ap_sta->vht_cap;
2760 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2762 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2763 bss_conf->bssid, arvif->vdev_id, ret);
2770 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2772 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2773 bss_conf->bssid, arvif->vdev_id, ret);
2777 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2779 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2780 arvif->vdev_id, ret);
2784 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2786 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2787 arvif->vdev_id, bss_conf->bssid, ret);
2791 ath10k_dbg(ar, ATH10K_DBG_MAC,
2792 "mac vdev %d up (associated) bssid %pM aid %d\n",
2793 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2795 WARN_ON(arvif->is_up);
2797 arvif->aid = bss_conf->aid;
2798 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2800 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2802 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2803 arvif->vdev_id, ret);
2807 arvif->is_up = true;
2809 /* Workaround: Some firmware revisions (tested with qca6174
2810 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2811 * poked with peer param command.
2813 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2814 WMI_PEER_DUMMY_VAR, 1);
2816 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2817 arvif->bssid, arvif->vdev_id, ret);
2822 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2823 struct ieee80211_vif *vif)
2825 struct ath10k *ar = hw->priv;
2826 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2827 struct ieee80211_sta_vht_cap vht_cap = {};
2830 lockdep_assert_held(&ar->conf_mutex);
2832 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2833 arvif->vdev_id, arvif->bssid);
2835 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2837 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2838 arvif->vdev_id, ret);
2840 arvif->def_wep_key_idx = -1;
2842 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2844 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2845 arvif->vdev_id, ret);
2849 arvif->is_up = false;
2851 cancel_delayed_work_sync(&arvif->connection_loss_work);
2854 static int ath10k_station_assoc(struct ath10k *ar,
2855 struct ieee80211_vif *vif,
2856 struct ieee80211_sta *sta,
2859 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2860 struct wmi_peer_assoc_complete_arg peer_arg;
2863 lockdep_assert_held(&ar->conf_mutex);
2865 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2867 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2868 sta->addr, arvif->vdev_id, ret);
2872 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2874 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2875 sta->addr, arvif->vdev_id, ret);
2879 /* Re-assoc is run only to update supported rates for given station. It
2880 * doesn't make much sense to reconfigure the peer completely.
2883 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2886 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2887 arvif->vdev_id, ret);
2891 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2893 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2894 sta->addr, arvif->vdev_id, ret);
2899 arvif->num_legacy_stations++;
2900 ret = ath10k_recalc_rtscts_prot(arvif);
2902 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2903 arvif->vdev_id, ret);
2908 /* Plumb cached keys only for static WEP */
2909 if (arvif->def_wep_key_idx != -1) {
2910 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2912 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2913 arvif->vdev_id, ret);
2922 static int ath10k_station_disassoc(struct ath10k *ar,
2923 struct ieee80211_vif *vif,
2924 struct ieee80211_sta *sta)
2926 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2929 lockdep_assert_held(&ar->conf_mutex);
2932 arvif->num_legacy_stations--;
2933 ret = ath10k_recalc_rtscts_prot(arvif);
2935 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2936 arvif->vdev_id, ret);
2941 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2943 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2944 arvif->vdev_id, ret);
2955 static int ath10k_update_channel_list(struct ath10k *ar)
2957 struct ieee80211_hw *hw = ar->hw;
2958 struct ieee80211_supported_band **bands;
2959 enum nl80211_band band;
2960 struct ieee80211_channel *channel;
2961 struct wmi_scan_chan_list_arg arg = {0};
2962 struct wmi_channel_arg *ch;
2968 lockdep_assert_held(&ar->conf_mutex);
2970 bands = hw->wiphy->bands;
2971 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2975 for (i = 0; i < bands[band]->n_channels; i++) {
2976 if (bands[band]->channels[i].flags &
2977 IEEE80211_CHAN_DISABLED)
2984 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2985 arg.channels = kzalloc(len, GFP_KERNEL);
2990 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2994 for (i = 0; i < bands[band]->n_channels; i++) {
2995 channel = &bands[band]->channels[i];
2997 if (channel->flags & IEEE80211_CHAN_DISABLED)
3000 ch->allow_ht = true;
3002 /* FIXME: when should we really allow VHT? */
3003 ch->allow_vht = true;
3006 !(channel->flags & IEEE80211_CHAN_NO_IR);
3009 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3012 !!(channel->flags & IEEE80211_CHAN_RADAR);
3014 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3015 ch->passive = passive;
3017 /* the firmware is ignoring the "radar" flag of the
3018 * channel and is scanning actively using Probe Requests
3019 * on "Radar detection"/DFS channels which are not
3020 * marked as "available"
3022 ch->passive |= ch->chan_radar;
3024 ch->freq = channel->center_freq;
3025 ch->band_center_freq1 = channel->center_freq;
3027 ch->max_power = channel->max_power * 2;
3028 ch->max_reg_power = channel->max_reg_power * 2;
3029 ch->max_antenna_gain = channel->max_antenna_gain;
3030 ch->reg_class_id = 0; /* FIXME */
3032 /* FIXME: why use only legacy modes, why not any
3033 * HT/VHT modes? Would that even make any
3035 if (channel->band == NL80211_BAND_2GHZ)
3036 ch->mode = MODE_11G;
3038 ch->mode = MODE_11A;
3040 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3043 ath10k_dbg(ar, ATH10K_DBG_WMI,
3044 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3045 ch - arg.channels, arg.n_channels,
3046 ch->freq, ch->max_power, ch->max_reg_power,
3047 ch->max_antenna_gain, ch->mode);
3053 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3054 kfree(arg.channels);
3059 static enum wmi_dfs_region
3060 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3062 switch (dfs_region) {
3063 case NL80211_DFS_UNSET:
3064 return WMI_UNINIT_DFS_DOMAIN;
3065 case NL80211_DFS_FCC:
3066 return WMI_FCC_DFS_DOMAIN;
3067 case NL80211_DFS_ETSI:
3068 return WMI_ETSI_DFS_DOMAIN;
3069 case NL80211_DFS_JP:
3070 return WMI_MKK4_DFS_DOMAIN;
3072 return WMI_UNINIT_DFS_DOMAIN;
3075 static void ath10k_regd_update(struct ath10k *ar)
3077 struct reg_dmn_pair_mapping *regpair;
3079 enum wmi_dfs_region wmi_dfs_reg;
3080 enum nl80211_dfs_regions nl_dfs_reg;
3082 lockdep_assert_held(&ar->conf_mutex);
3084 ret = ath10k_update_channel_list(ar);
3086 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3088 regpair = ar->ath_common.regulatory.regpair;
3090 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3091 nl_dfs_reg = ar->dfs_detector->region;
3092 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3094 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3097 /* Target allows setting up per-band regdomain but ath_common provides
3098 * a combined one only */
3099 ret = ath10k_wmi_pdev_set_regdomain(ar,
3100 regpair->reg_domain,
3101 regpair->reg_domain, /* 2ghz */
3102 regpair->reg_domain, /* 5ghz */
3103 regpair->reg_2ghz_ctl,
3104 regpair->reg_5ghz_ctl,
3107 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3110 static void ath10k_reg_notifier(struct wiphy *wiphy,
3111 struct regulatory_request *request)
3113 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3114 struct ath10k *ar = hw->priv;
3117 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3119 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3120 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3121 request->dfs_region);
3122 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3123 request->dfs_region);
3125 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3126 request->dfs_region);
3129 mutex_lock(&ar->conf_mutex);
3130 if (ar->state == ATH10K_STATE_ON)
3131 ath10k_regd_update(ar);
3132 mutex_unlock(&ar->conf_mutex);
3139 enum ath10k_mac_tx_path {
3141 ATH10K_MAC_TX_HTT_MGMT,
3142 ATH10K_MAC_TX_WMI_MGMT,
3143 ATH10K_MAC_TX_UNKNOWN,
3146 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3148 lockdep_assert_held(&ar->htt.tx_lock);
3150 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3151 ar->tx_paused |= BIT(reason);
3152 ieee80211_stop_queues(ar->hw);
3155 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3156 struct ieee80211_vif *vif)
3158 struct ath10k *ar = data;
3159 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3161 if (arvif->tx_paused)
3164 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3167 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3169 lockdep_assert_held(&ar->htt.tx_lock);
3171 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3172 ar->tx_paused &= ~BIT(reason);
3177 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3178 IEEE80211_IFACE_ITER_RESUME_ALL,
3179 ath10k_mac_tx_unlock_iter,
3182 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3185 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3187 struct ath10k *ar = arvif->ar;
3189 lockdep_assert_held(&ar->htt.tx_lock);
3191 WARN_ON(reason >= BITS_PER_LONG);
3192 arvif->tx_paused |= BIT(reason);
3193 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3196 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3198 struct ath10k *ar = arvif->ar;
3200 lockdep_assert_held(&ar->htt.tx_lock);
3202 WARN_ON(reason >= BITS_PER_LONG);
3203 arvif->tx_paused &= ~BIT(reason);
3208 if (arvif->tx_paused)
3211 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3214 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3215 enum wmi_tlv_tx_pause_id pause_id,
3216 enum wmi_tlv_tx_pause_action action)
3218 struct ath10k *ar = arvif->ar;
3220 lockdep_assert_held(&ar->htt.tx_lock);
3223 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3224 ath10k_mac_vif_tx_lock(arvif, pause_id);
3226 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3227 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3230 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3231 action, arvif->vdev_id);
3236 struct ath10k_mac_tx_pause {
3238 enum wmi_tlv_tx_pause_id pause_id;
3239 enum wmi_tlv_tx_pause_action action;
3242 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3243 struct ieee80211_vif *vif)
3245 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3246 struct ath10k_mac_tx_pause *arg = data;
3248 if (arvif->vdev_id != arg->vdev_id)
3251 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3254 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3255 enum wmi_tlv_tx_pause_id pause_id,
3256 enum wmi_tlv_tx_pause_action action)
3258 struct ath10k_mac_tx_pause arg = {
3260 .pause_id = pause_id,
3264 spin_lock_bh(&ar->htt.tx_lock);
3265 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3266 IEEE80211_IFACE_ITER_RESUME_ALL,
3267 ath10k_mac_handle_tx_pause_iter,
3269 spin_unlock_bh(&ar->htt.tx_lock);
3272 static enum ath10k_hw_txrx_mode
3273 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3274 struct ieee80211_vif *vif,
3275 struct ieee80211_sta *sta,
3276 struct sk_buff *skb)
3278 const struct ieee80211_hdr *hdr = (void *)skb->data;
3279 __le16 fc = hdr->frame_control;
3281 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3282 return ATH10K_HW_TXRX_RAW;
3284 if (ieee80211_is_mgmt(fc))
3285 return ATH10K_HW_TXRX_MGMT;
3289 * NullFunc frames are mostly used to ping if a client or AP are still
3290 * reachable and responsive. This implies tx status reports must be
3291 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3292 * come to a conclusion that the other end disappeared and tear down
3293 * BSS connection or it can never disconnect from BSS/client (which is
3296 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3297 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3298 * which seems to deliver correct tx reports for NullFunc frames. The
3299 * downside of using it is it ignores client powersave state so it can
3300 * end up disconnecting sleeping clients in AP mode. It should fix STA
3301 * mode though because AP don't sleep.
3303 if (ar->htt.target_version_major < 3 &&
3304 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3305 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3306 ar->running_fw->fw_file.fw_features))
3307 return ATH10K_HW_TXRX_MGMT;
3311 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3312 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3313 * to work with Ethernet txmode so use it.
3315 * FIXME: Check if raw mode works with TDLS.
3317 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3318 return ATH10K_HW_TXRX_ETHERNET;
3320 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3321 return ATH10K_HW_TXRX_RAW;
3323 return ATH10K_HW_TXRX_NATIVE_WIFI;
3326 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3327 struct sk_buff *skb)
3329 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3330 const struct ieee80211_hdr *hdr = (void *)skb->data;
3331 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3332 IEEE80211_TX_CTL_INJECTED;
3334 if (!ieee80211_has_protected(hdr->frame_control))
3337 if ((info->flags & mask) == mask)
3341 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3346 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3347 * Control in the header.
3349 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3351 struct ieee80211_hdr *hdr = (void *)skb->data;
3352 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3355 if (!ieee80211_is_data_qos(hdr->frame_control))
3358 qos_ctl = ieee80211_get_qos_ctl(hdr);
3359 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3360 skb->data, (void *)qos_ctl - (void *)skb->data);
3361 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3363 /* Some firmware revisions don't handle sending QoS NullFunc well.
3364 * These frames are mainly used for CQM purposes so it doesn't really
3365 * matter whether QoS NullFunc or NullFunc are sent.
3367 hdr = (void *)skb->data;
3368 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3369 cb->flags &= ~ATH10K_SKB_F_QOS;
3371 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3374 static void ath10k_tx_h_8023(struct sk_buff *skb)
3376 struct ieee80211_hdr *hdr;
3377 struct rfc1042_hdr *rfc1042;
3384 hdr = (void *)skb->data;
3385 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3386 rfc1042 = (void *)skb->data + hdrlen;
3388 ether_addr_copy(da, ieee80211_get_DA(hdr));
3389 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3390 type = rfc1042->snap_type;
3392 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3393 skb_push(skb, sizeof(*eth));
3395 eth = (void *)skb->data;
3396 ether_addr_copy(eth->h_dest, da);
3397 ether_addr_copy(eth->h_source, sa);
3398 eth->h_proto = type;
3401 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3402 struct ieee80211_vif *vif,
3403 struct sk_buff *skb)
3405 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3406 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3408 /* This is case only for P2P_GO */
3409 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3412 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3413 spin_lock_bh(&ar->data_lock);
3414 if (arvif->u.ap.noa_data)
3415 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3417 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3418 arvif->u.ap.noa_data,
3419 arvif->u.ap.noa_len);
3420 spin_unlock_bh(&ar->data_lock);
3424 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3425 struct ieee80211_vif *vif,
3426 struct ieee80211_txq *txq,
3427 struct sk_buff *skb)
3429 struct ieee80211_hdr *hdr = (void *)skb->data;
3430 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3433 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3434 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3436 if (ieee80211_is_mgmt(hdr->frame_control))
3437 cb->flags |= ATH10K_SKB_F_MGMT;
3439 if (ieee80211_is_data_qos(hdr->frame_control))
3440 cb->flags |= ATH10K_SKB_F_QOS;
3446 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3448 /* FIXME: Not really sure since when the behaviour changed. At some
3449 * point new firmware stopped requiring creation of peer entries for
3450 * offchannel tx (and actually creating them causes issues with wmi-htc
3451 * tx credit replenishment and reliability). Assuming it's at least 3.4
3452 * because that's when the `freq` was introduced to TX_FRM HTT command.
3454 return (ar->htt.target_version_major >= 3 &&
3455 ar->htt.target_version_minor >= 4 &&
3456 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3459 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3461 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3463 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3464 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3468 skb_queue_tail(q, skb);
3469 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3474 static enum ath10k_mac_tx_path
3475 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3476 struct sk_buff *skb,
3477 enum ath10k_hw_txrx_mode txmode)
3480 case ATH10K_HW_TXRX_RAW:
3481 case ATH10K_HW_TXRX_NATIVE_WIFI:
3482 case ATH10K_HW_TXRX_ETHERNET:
3483 return ATH10K_MAC_TX_HTT;
3484 case ATH10K_HW_TXRX_MGMT:
3485 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3486 ar->running_fw->fw_file.fw_features))
3487 return ATH10K_MAC_TX_WMI_MGMT;
3488 else if (ar->htt.target_version_major >= 3)
3489 return ATH10K_MAC_TX_HTT;
3491 return ATH10K_MAC_TX_HTT_MGMT;
3494 return ATH10K_MAC_TX_UNKNOWN;
3497 static int ath10k_mac_tx_submit(struct ath10k *ar,
3498 enum ath10k_hw_txrx_mode txmode,
3499 enum ath10k_mac_tx_path txpath,
3500 struct sk_buff *skb)
3502 struct ath10k_htt *htt = &ar->htt;
3506 case ATH10K_MAC_TX_HTT:
3507 ret = ath10k_htt_tx(htt, txmode, skb);
3509 case ATH10K_MAC_TX_HTT_MGMT:
3510 ret = ath10k_htt_mgmt_tx(htt, skb);
3512 case ATH10K_MAC_TX_WMI_MGMT:
3513 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3515 case ATH10K_MAC_TX_UNKNOWN:
3522 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3524 ieee80211_free_txskb(ar->hw, skb);
3530 /* This function consumes the sk_buff regardless of return value as far as
3531 * caller is concerned so no freeing is necessary afterwards.
3533 static int ath10k_mac_tx(struct ath10k *ar,
3534 struct ieee80211_vif *vif,
3535 struct ieee80211_sta *sta,
3536 enum ath10k_hw_txrx_mode txmode,
3537 enum ath10k_mac_tx_path txpath,
3538 struct sk_buff *skb)
3540 struct ieee80211_hw *hw = ar->hw;
3541 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3544 /* We should disable CCK RATE due to P2P */
3545 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3546 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3549 case ATH10K_HW_TXRX_MGMT:
3550 case ATH10K_HW_TXRX_NATIVE_WIFI:
3551 ath10k_tx_h_nwifi(hw, skb);
3552 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3553 ath10k_tx_h_seq_no(vif, skb);
3555 case ATH10K_HW_TXRX_ETHERNET:
3556 ath10k_tx_h_8023(skb);
3558 case ATH10K_HW_TXRX_RAW:
3559 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3561 ieee80211_free_txskb(hw, skb);
3566 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3567 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3568 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3571 skb_queue_tail(&ar->offchan_tx_queue, skb);
3572 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3577 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3579 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3586 void ath10k_offchan_tx_purge(struct ath10k *ar)
3588 struct sk_buff *skb;
3591 skb = skb_dequeue(&ar->offchan_tx_queue);
3595 ieee80211_free_txskb(ar->hw, skb);
3599 void ath10k_offchan_tx_work(struct work_struct *work)
3601 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3602 struct ath10k_peer *peer;
3603 struct ath10k_vif *arvif;
3604 enum ath10k_hw_txrx_mode txmode;
3605 enum ath10k_mac_tx_path txpath;
3606 struct ieee80211_hdr *hdr;
3607 struct ieee80211_vif *vif;
3608 struct ieee80211_sta *sta;
3609 struct sk_buff *skb;
3610 const u8 *peer_addr;
3613 unsigned long time_left;
3614 bool tmp_peer_created = false;
3616 /* FW requirement: We must create a peer before FW will send out
3617 * an offchannel frame. Otherwise the frame will be stuck and
3618 * never transmitted. We delete the peer upon tx completion.
3619 * It is unlikely that a peer for offchannel tx will already be
3620 * present. However it may be in some rare cases so account for that.
3621 * Otherwise we might remove a legitimate peer and break stuff. */
3624 skb = skb_dequeue(&ar->offchan_tx_queue);
3628 mutex_lock(&ar->conf_mutex);
3630 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3633 hdr = (struct ieee80211_hdr *)skb->data;
3634 peer_addr = ieee80211_get_DA(hdr);
3636 spin_lock_bh(&ar->data_lock);
3637 vdev_id = ar->scan.vdev_id;
3638 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3639 spin_unlock_bh(&ar->data_lock);
3642 /* FIXME: should this use ath10k_warn()? */
3643 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3644 peer_addr, vdev_id);
3647 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3649 WMI_PEER_TYPE_DEFAULT);
3651 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3652 peer_addr, vdev_id, ret);
3653 tmp_peer_created = (ret == 0);
3656 spin_lock_bh(&ar->data_lock);
3657 reinit_completion(&ar->offchan_tx_completed);
3658 ar->offchan_tx_skb = skb;
3659 spin_unlock_bh(&ar->data_lock);
3661 /* It's safe to access vif and sta - conf_mutex guarantees that
3662 * sta_state() and remove_interface() are locked exclusively
3663 * out wrt to this offchannel worker.
3665 arvif = ath10k_get_arvif(ar, vdev_id);
3668 sta = ieee80211_find_sta(vif, peer_addr);
3674 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3675 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3677 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3679 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3685 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3687 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3690 if (!peer && tmp_peer_created) {
3691 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3693 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3694 peer_addr, vdev_id, ret);
3697 mutex_unlock(&ar->conf_mutex);
3701 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3703 struct sk_buff *skb;
3706 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3710 ieee80211_free_txskb(ar->hw, skb);
3714 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3716 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3717 struct sk_buff *skb;
3721 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3725 ret = ath10k_wmi_mgmt_tx(ar, skb);
3727 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3729 ieee80211_free_txskb(ar->hw, skb);
3734 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3736 struct ath10k_txq *artxq;
3741 artxq = (void *)txq->drv_priv;
3742 INIT_LIST_HEAD(&artxq->list);
3745 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3747 struct ath10k_txq *artxq;
3748 struct ath10k_skb_cb *cb;
3749 struct sk_buff *msdu;
3755 artxq = (void *)txq->drv_priv;
3756 spin_lock_bh(&ar->txqs_lock);
3757 if (!list_empty(&artxq->list))
3758 list_del_init(&artxq->list);
3759 spin_unlock_bh(&ar->txqs_lock);
3761 spin_lock_bh(&ar->htt.tx_lock);
3762 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3763 cb = ATH10K_SKB_CB(msdu);
3767 spin_unlock_bh(&ar->htt.tx_lock);
3770 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3774 struct ath10k_peer *peer;
3776 lockdep_assert_held(&ar->data_lock);
3778 peer = ar->peer_map[peer_id];
3786 return peer->sta->txq[tid];
3788 return peer->vif->txq;
3793 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3794 struct ieee80211_txq *txq)
3796 struct ath10k *ar = hw->priv;
3797 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3799 /* No need to get locks */
3801 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3804 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3807 if (artxq->num_fw_queued < artxq->num_push_allowed)
3813 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3814 struct ieee80211_txq *txq)
3816 struct ath10k *ar = hw->priv;
3817 struct ath10k_htt *htt = &ar->htt;
3818 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3819 struct ieee80211_vif *vif = txq->vif;
3820 struct ieee80211_sta *sta = txq->sta;
3821 enum ath10k_hw_txrx_mode txmode;
3822 enum ath10k_mac_tx_path txpath;
3823 struct sk_buff *skb;
3824 struct ieee80211_hdr *hdr;
3826 bool is_mgmt, is_presp;
3829 spin_lock_bh(&ar->htt.tx_lock);
3830 ret = ath10k_htt_tx_inc_pending(htt);
3831 spin_unlock_bh(&ar->htt.tx_lock);
3836 skb = ieee80211_tx_dequeue(hw, txq);
3838 spin_lock_bh(&ar->htt.tx_lock);
3839 ath10k_htt_tx_dec_pending(htt);
3840 spin_unlock_bh(&ar->htt.tx_lock);
3845 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3848 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3849 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3850 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3853 hdr = (struct ieee80211_hdr *)skb->data;
3854 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3856 spin_lock_bh(&ar->htt.tx_lock);
3857 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3860 ath10k_htt_tx_dec_pending(htt);
3861 spin_unlock_bh(&ar->htt.tx_lock);
3864 spin_unlock_bh(&ar->htt.tx_lock);
3867 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3868 if (unlikely(ret)) {
3869 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3871 spin_lock_bh(&ar->htt.tx_lock);
3872 ath10k_htt_tx_dec_pending(htt);
3874 ath10k_htt_tx_mgmt_dec_pending(htt);
3875 spin_unlock_bh(&ar->htt.tx_lock);
3880 spin_lock_bh(&ar->htt.tx_lock);
3881 artxq->num_fw_queued++;
3882 spin_unlock_bh(&ar->htt.tx_lock);
3887 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3889 struct ieee80211_hw *hw = ar->hw;
3890 struct ieee80211_txq *txq;
3891 struct ath10k_txq *artxq;
3892 struct ath10k_txq *last;
3896 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3899 spin_lock_bh(&ar->txqs_lock);
3902 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3903 while (!list_empty(&ar->txqs)) {
3904 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3905 txq = container_of((void *)artxq, struct ieee80211_txq,
3908 /* Prevent aggressive sta/tid taking over tx queue */
3911 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3912 ret = ath10k_mac_tx_push_txq(hw, txq);
3917 list_del_init(&artxq->list);
3919 list_add_tail(&artxq->list, &ar->txqs);
3921 ath10k_htt_tx_txq_update(hw, txq);
3923 if (artxq == last || (ret < 0 && ret != -ENOENT))
3928 spin_unlock_bh(&ar->txqs_lock);
3935 void __ath10k_scan_finish(struct ath10k *ar)
3937 lockdep_assert_held(&ar->data_lock);
3939 switch (ar->scan.state) {
3940 case ATH10K_SCAN_IDLE:
3942 case ATH10K_SCAN_RUNNING:
3943 case ATH10K_SCAN_ABORTING:
3944 if (!ar->scan.is_roc) {
3945 struct cfg80211_scan_info info = {
3946 .aborted = (ar->scan.state ==
3947 ATH10K_SCAN_ABORTING),
3950 ieee80211_scan_completed(ar->hw, &info);
3951 } else if (ar->scan.roc_notify) {
3952 ieee80211_remain_on_channel_expired(ar->hw);
3955 case ATH10K_SCAN_STARTING:
3956 ar->scan.state = ATH10K_SCAN_IDLE;
3957 ar->scan_channel = NULL;
3958 ar->scan.roc_freq = 0;
3959 ath10k_offchan_tx_purge(ar);
3960 cancel_delayed_work(&ar->scan.timeout);
3961 complete(&ar->scan.completed);
3966 void ath10k_scan_finish(struct ath10k *ar)
3968 spin_lock_bh(&ar->data_lock);
3969 __ath10k_scan_finish(ar);
3970 spin_unlock_bh(&ar->data_lock);
3973 static int ath10k_scan_stop(struct ath10k *ar)
3975 struct wmi_stop_scan_arg arg = {
3976 .req_id = 1, /* FIXME */
3977 .req_type = WMI_SCAN_STOP_ONE,
3978 .u.scan_id = ATH10K_SCAN_ID,
3982 lockdep_assert_held(&ar->conf_mutex);
3984 ret = ath10k_wmi_stop_scan(ar, &arg);
3986 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3990 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
3992 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3994 } else if (ret > 0) {
3999 /* Scan state should be updated upon scan completion but in case
4000 * firmware fails to deliver the event (for whatever reason) it is
4001 * desired to clean up scan state anyway. Firmware may have just
4002 * dropped the scan completion event delivery due to transport pipe
4003 * being overflown with data and/or it can recover on its own before
4004 * next scan request is submitted.
4006 spin_lock_bh(&ar->data_lock);
4007 if (ar->scan.state != ATH10K_SCAN_IDLE)
4008 __ath10k_scan_finish(ar);
4009 spin_unlock_bh(&ar->data_lock);
4014 static void ath10k_scan_abort(struct ath10k *ar)
4018 lockdep_assert_held(&ar->conf_mutex);
4020 spin_lock_bh(&ar->data_lock);
4022 switch (ar->scan.state) {
4023 case ATH10K_SCAN_IDLE:
4024 /* This can happen if timeout worker kicked in and called
4025 * abortion while scan completion was being processed.
4028 case ATH10K_SCAN_STARTING:
4029 case ATH10K_SCAN_ABORTING:
4030 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4031 ath10k_scan_state_str(ar->scan.state),
4034 case ATH10K_SCAN_RUNNING:
4035 ar->scan.state = ATH10K_SCAN_ABORTING;
4036 spin_unlock_bh(&ar->data_lock);
4038 ret = ath10k_scan_stop(ar);
4040 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4042 spin_lock_bh(&ar->data_lock);
4046 spin_unlock_bh(&ar->data_lock);
4049 void ath10k_scan_timeout_work(struct work_struct *work)
4051 struct ath10k *ar = container_of(work, struct ath10k,
4054 mutex_lock(&ar->conf_mutex);
4055 ath10k_scan_abort(ar);
4056 mutex_unlock(&ar->conf_mutex);
4059 static int ath10k_start_scan(struct ath10k *ar,
4060 const struct wmi_start_scan_arg *arg)
4064 lockdep_assert_held(&ar->conf_mutex);
4066 ret = ath10k_wmi_start_scan(ar, arg);
4070 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4072 ret = ath10k_scan_stop(ar);
4074 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4079 /* If we failed to start the scan, return error code at
4080 * this point. This is probably due to some issue in the
4081 * firmware, but no need to wedge the driver due to that...
4083 spin_lock_bh(&ar->data_lock);
4084 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4085 spin_unlock_bh(&ar->data_lock);
4088 spin_unlock_bh(&ar->data_lock);
4093 /**********************/
4094 /* mac80211 callbacks */
4095 /**********************/
4097 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4098 struct ieee80211_tx_control *control,
4099 struct sk_buff *skb)
4101 struct ath10k *ar = hw->priv;
4102 struct ath10k_htt *htt = &ar->htt;
4103 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4104 struct ieee80211_vif *vif = info->control.vif;
4105 struct ieee80211_sta *sta = control->sta;
4106 struct ieee80211_txq *txq = NULL;
4107 struct ieee80211_hdr *hdr = (void *)skb->data;
4108 enum ath10k_hw_txrx_mode txmode;
4109 enum ath10k_mac_tx_path txpath;
4115 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4117 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4118 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4119 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4120 txpath == ATH10K_MAC_TX_HTT_MGMT);
4121 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4124 spin_lock_bh(&ar->htt.tx_lock);
4125 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4127 ret = ath10k_htt_tx_inc_pending(htt);
4129 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4131 spin_unlock_bh(&ar->htt.tx_lock);
4132 ieee80211_free_txskb(ar->hw, skb);
4136 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4138 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4140 ath10k_htt_tx_dec_pending(htt);
4141 spin_unlock_bh(&ar->htt.tx_lock);
4142 ieee80211_free_txskb(ar->hw, skb);
4145 spin_unlock_bh(&ar->htt.tx_lock);
4148 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
4150 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4152 spin_lock_bh(&ar->htt.tx_lock);
4153 ath10k_htt_tx_dec_pending(htt);
4155 ath10k_htt_tx_mgmt_dec_pending(htt);
4156 spin_unlock_bh(&ar->htt.tx_lock);
4162 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4163 struct ieee80211_txq *txq)
4165 struct ath10k *ar = hw->priv;
4166 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4167 struct ieee80211_txq *f_txq;
4168 struct ath10k_txq *f_artxq;
4172 spin_lock_bh(&ar->txqs_lock);
4173 if (list_empty(&artxq->list))
4174 list_add_tail(&artxq->list, &ar->txqs);
4176 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4177 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4178 list_del_init(&f_artxq->list);
4180 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4181 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4186 list_add_tail(&f_artxq->list, &ar->txqs);
4187 spin_unlock_bh(&ar->txqs_lock);
4189 ath10k_htt_tx_txq_update(hw, f_txq);
4190 ath10k_htt_tx_txq_update(hw, txq);
4193 /* Must not be called with conf_mutex held as workers can use that also. */
4194 void ath10k_drain_tx(struct ath10k *ar)
4196 /* make sure rcu-protected mac80211 tx path itself is drained */
4199 ath10k_offchan_tx_purge(ar);
4200 ath10k_mgmt_over_wmi_tx_purge(ar);
4202 cancel_work_sync(&ar->offchan_tx_work);
4203 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4206 void ath10k_halt(struct ath10k *ar)
4208 struct ath10k_vif *arvif;
4210 lockdep_assert_held(&ar->conf_mutex);
4212 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4213 ar->filter_flags = 0;
4214 ar->monitor = false;
4215 ar->monitor_arvif = NULL;
4217 if (ar->monitor_started)
4218 ath10k_monitor_stop(ar);
4220 ar->monitor_started = false;
4223 ath10k_scan_finish(ar);
4224 ath10k_peer_cleanup_all(ar);
4225 ath10k_core_stop(ar);
4226 ath10k_hif_power_down(ar);
4228 spin_lock_bh(&ar->data_lock);
4229 list_for_each_entry(arvif, &ar->arvifs, list)
4230 ath10k_mac_vif_beacon_cleanup(arvif);
4231 spin_unlock_bh(&ar->data_lock);
4234 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4236 struct ath10k *ar = hw->priv;
4238 mutex_lock(&ar->conf_mutex);
4240 *tx_ant = ar->cfg_tx_chainmask;
4241 *rx_ant = ar->cfg_rx_chainmask;
4243 mutex_unlock(&ar->conf_mutex);
4248 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4250 /* It is not clear that allowing gaps in chainmask
4251 * is helpful. Probably it will not do what user
4252 * is hoping for, so warn in that case.
4254 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4257 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4261 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4263 int nsts = ar->vht_cap_info;
4265 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4266 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4268 /* If firmware does not deliver to host number of space-time
4269 * streams supported, assume it support up to 4 BF STS and return
4270 * the value for VHT CAP: nsts-1)
4278 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4280 int sound_dim = ar->vht_cap_info;
4282 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4283 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4285 /* If the sounding dimension is not advertised by the firmware,
4286 * let's use a default value of 1
4294 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4296 struct ieee80211_sta_vht_cap vht_cap = {0};
4301 vht_cap.vht_supported = 1;
4302 vht_cap.cap = ar->vht_cap_info;
4304 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4305 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4306 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4307 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4308 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4313 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4314 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4315 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4316 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4317 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4323 for (i = 0; i < 8; i++) {
4324 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4325 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4327 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4330 if (ar->cfg_tx_chainmask <= 1)
4331 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4333 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4334 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4339 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4342 struct ieee80211_sta_ht_cap ht_cap = {0};
4344 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4347 ht_cap.ht_supported = 1;
4348 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4349 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4350 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4351 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4353 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4355 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4356 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4358 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4359 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4361 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4364 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4365 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4370 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4371 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4373 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4376 stbc = ar->ht_cap_info;
4377 stbc &= WMI_HT_CAP_RX_STBC;
4378 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4379 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4380 stbc &= IEEE80211_HT_CAP_RX_STBC;
4385 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4386 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4388 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4389 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4391 /* max AMSDU is implicitly taken from vht_cap_info */
4392 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4393 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4395 for (i = 0; i < ar->num_rf_chains; i++) {
4396 if (ar->cfg_rx_chainmask & BIT(i))
4397 ht_cap.mcs.rx_mask[i] = 0xFF;
4400 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4405 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4407 struct ieee80211_supported_band *band;
4408 struct ieee80211_sta_vht_cap vht_cap;
4409 struct ieee80211_sta_ht_cap ht_cap;
4411 ht_cap = ath10k_get_ht_cap(ar);
4412 vht_cap = ath10k_create_vht_cap(ar);
4414 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4415 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4416 band->ht_cap = ht_cap;
4418 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4419 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4420 band->ht_cap = ht_cap;
4421 band->vht_cap = vht_cap;
4425 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4429 lockdep_assert_held(&ar->conf_mutex);
4431 ath10k_check_chain_mask(ar, tx_ant, "tx");
4432 ath10k_check_chain_mask(ar, rx_ant, "rx");
4434 ar->cfg_tx_chainmask = tx_ant;
4435 ar->cfg_rx_chainmask = rx_ant;
4437 if ((ar->state != ATH10K_STATE_ON) &&
4438 (ar->state != ATH10K_STATE_RESTARTED))
4441 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4444 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4449 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4452 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4457 /* Reload HT/VHT capability */
4458 ath10k_mac_setup_ht_vht_cap(ar);
4463 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4465 struct ath10k *ar = hw->priv;
4468 mutex_lock(&ar->conf_mutex);
4469 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4470 mutex_unlock(&ar->conf_mutex);
4474 static int ath10k_start(struct ieee80211_hw *hw)
4476 struct ath10k *ar = hw->priv;
4481 * This makes sense only when restarting hw. It is harmless to call
4482 * unconditionally. This is necessary to make sure no HTT/WMI tx
4483 * commands will be submitted while restarting.
4485 ath10k_drain_tx(ar);
4487 mutex_lock(&ar->conf_mutex);
4489 switch (ar->state) {
4490 case ATH10K_STATE_OFF:
4491 ar->state = ATH10K_STATE_ON;
4493 case ATH10K_STATE_RESTARTING:
4494 ar->state = ATH10K_STATE_RESTARTED;
4496 case ATH10K_STATE_ON:
4497 case ATH10K_STATE_RESTARTED:
4498 case ATH10K_STATE_WEDGED:
4502 case ATH10K_STATE_UTF:
4507 ret = ath10k_hif_power_up(ar);
4509 ath10k_err(ar, "Could not init hif: %d\n", ret);
4513 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4514 &ar->normal_mode_fw);
4516 ath10k_err(ar, "Could not init core: %d\n", ret);
4517 goto err_power_down;
4520 param = ar->wmi.pdev_param->pmf_qos;
4521 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4523 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4527 param = ar->wmi.pdev_param->dynamic_bw;
4528 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4530 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4534 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4535 ret = ath10k_wmi_adaptive_qcs(ar, true);
4537 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4543 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4544 param = ar->wmi.pdev_param->burst_enable;
4545 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4547 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4552 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4555 * By default FW set ARP frames ac to voice (6). In that case ARP
4556 * exchange is not working properly for UAPSD enabled AP. ARP requests
4557 * which arrives with access category 0 are processed by network stack
4558 * and send back with access category 0, but FW changes access category
4559 * to 6. Set ARP frames access category to best effort (0) solves
4563 param = ar->wmi.pdev_param->arp_ac_override;
4564 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4566 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4571 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4572 ar->running_fw->fw_file.fw_features)) {
4573 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4574 WMI_CCA_DETECT_LEVEL_AUTO,
4575 WMI_CCA_DETECT_MARGIN_AUTO);
4577 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4583 param = ar->wmi.pdev_param->ani_enable;
4584 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4586 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4591 ar->ani_enabled = true;
4593 if (ath10k_peer_stats_enabled(ar)) {
4594 param = ar->wmi.pdev_param->peer_stats_update_period;
4595 ret = ath10k_wmi_pdev_set_param(ar, param,
4596 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4599 "failed to set peer stats period : %d\n",
4605 param = ar->wmi.pdev_param->enable_btcoex;
4606 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4607 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4608 ar->running_fw->fw_file.fw_features)) {
4609 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4612 "failed to set btcoex param: %d\n", ret);
4615 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4618 ar->num_started_vdevs = 0;
4619 ath10k_regd_update(ar);
4621 ath10k_spectral_start(ar);
4622 ath10k_thermal_set_throttling(ar);
4624 mutex_unlock(&ar->conf_mutex);
4628 ath10k_core_stop(ar);
4631 ath10k_hif_power_down(ar);
4634 ar->state = ATH10K_STATE_OFF;
4637 mutex_unlock(&ar->conf_mutex);
4641 static void ath10k_stop(struct ieee80211_hw *hw)
4643 struct ath10k *ar = hw->priv;
4645 ath10k_drain_tx(ar);
4647 mutex_lock(&ar->conf_mutex);
4648 if (ar->state != ATH10K_STATE_OFF) {
4650 ar->state = ATH10K_STATE_OFF;
4652 mutex_unlock(&ar->conf_mutex);
4654 cancel_delayed_work_sync(&ar->scan.timeout);
4655 cancel_work_sync(&ar->restart_work);
4658 static int ath10k_config_ps(struct ath10k *ar)
4660 struct ath10k_vif *arvif;
4663 lockdep_assert_held(&ar->conf_mutex);
4665 list_for_each_entry(arvif, &ar->arvifs, list) {
4666 ret = ath10k_mac_vif_setup_ps(arvif);
4668 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4676 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4681 lockdep_assert_held(&ar->conf_mutex);
4683 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4685 param = ar->wmi.pdev_param->txpower_limit2g;
4686 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4688 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4693 param = ar->wmi.pdev_param->txpower_limit5g;
4694 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4696 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4704 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4706 struct ath10k_vif *arvif;
4707 int ret, txpower = -1;
4709 lockdep_assert_held(&ar->conf_mutex);
4711 list_for_each_entry(arvif, &ar->arvifs, list) {
4712 if (arvif->txpower <= 0)
4716 txpower = arvif->txpower;
4718 txpower = min(txpower, arvif->txpower);
4724 ret = ath10k_mac_txpower_setup(ar, txpower);
4726 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4734 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4736 struct ath10k *ar = hw->priv;
4737 struct ieee80211_conf *conf = &hw->conf;
4740 mutex_lock(&ar->conf_mutex);
4742 if (changed & IEEE80211_CONF_CHANGE_PS)
4743 ath10k_config_ps(ar);
4745 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4746 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4747 ret = ath10k_monitor_recalc(ar);
4749 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4752 mutex_unlock(&ar->conf_mutex);
4756 static u32 get_nss_from_chainmask(u16 chain_mask)
4758 if ((chain_mask & 0xf) == 0xf)
4760 else if ((chain_mask & 0x7) == 0x7)
4762 else if ((chain_mask & 0x3) == 0x3)
4767 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4770 struct ath10k *ar = arvif->ar;
4774 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4777 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4778 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4779 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4780 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4782 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4783 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4784 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4785 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4790 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4791 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4793 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4794 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4795 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4797 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4798 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4800 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4801 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4802 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4804 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4805 ar->wmi.vdev_param->txbf, value);
4810 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4811 * because we will send mgmt frames without CCK. This requirement
4812 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4815 static int ath10k_add_interface(struct ieee80211_hw *hw,
4816 struct ieee80211_vif *vif)
4818 struct ath10k *ar = hw->priv;
4819 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4820 struct ath10k_peer *peer;
4821 enum wmi_sta_powersave_param param;
4828 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4830 mutex_lock(&ar->conf_mutex);
4832 memset(arvif, 0, sizeof(*arvif));
4833 ath10k_mac_txq_init(vif->txq);
4838 INIT_LIST_HEAD(&arvif->list);
4839 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4840 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4841 ath10k_mac_vif_sta_connection_loss_work);
4843 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4844 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4845 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4846 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4847 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4848 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4851 if (ar->num_peers >= ar->max_num_peers) {
4852 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4857 if (ar->free_vdev_map == 0) {
4858 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4862 bit = __ffs64(ar->free_vdev_map);
4864 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4865 bit, ar->free_vdev_map);
4867 arvif->vdev_id = bit;
4868 arvif->vdev_subtype =
4869 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4871 switch (vif->type) {
4872 case NL80211_IFTYPE_P2P_DEVICE:
4873 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4874 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4875 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4877 case NL80211_IFTYPE_UNSPECIFIED:
4878 case NL80211_IFTYPE_STATION:
4879 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4881 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4882 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4884 case NL80211_IFTYPE_ADHOC:
4885 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4887 case NL80211_IFTYPE_MESH_POINT:
4888 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4889 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4890 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4891 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4893 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4896 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4898 case NL80211_IFTYPE_AP:
4899 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4902 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4903 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4905 case NL80211_IFTYPE_MONITOR:
4906 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4913 /* Using vdev_id as queue number will make it very easy to do per-vif
4914 * tx queue locking. This shouldn't wrap due to interface combinations
4915 * but do a modulo for correctness sake and prevent using offchannel tx
4916 * queues for regular vif tx.
4918 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4919 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4920 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4922 /* Some firmware revisions don't wait for beacon tx completion before
4923 * sending another SWBA event. This could lead to hardware using old
4924 * (freed) beacon data in some cases, e.g. tx credit starvation
4925 * combined with missed TBTT. This is very very rare.
4927 * On non-IOMMU-enabled hosts this could be a possible security issue
4928 * because hw could beacon some random data on the air. On
4929 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4930 * device would crash.
4932 * Since there are no beacon tx completions (implicit nor explicit)
4933 * propagated to host the only workaround for this is to allocate a
4934 * DMA-coherent buffer for a lifetime of a vif and use it for all
4935 * beacon tx commands. Worst case for this approach is some beacons may
4936 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4938 if (vif->type == NL80211_IFTYPE_ADHOC ||
4939 vif->type == NL80211_IFTYPE_MESH_POINT ||
4940 vif->type == NL80211_IFTYPE_AP) {
4941 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4942 IEEE80211_MAX_FRAME_LEN,
4943 &arvif->beacon_paddr,
4945 if (!arvif->beacon_buf) {
4947 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4952 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4953 arvif->nohwcrypt = true;
4955 if (arvif->nohwcrypt &&
4956 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4958 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4962 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4963 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4964 arvif->beacon_buf ? "single-buf" : "per-skb");
4966 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4967 arvif->vdev_subtype, vif->addr);
4969 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4970 arvif->vdev_id, ret);
4974 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4975 spin_lock_bh(&ar->data_lock);
4976 list_add(&arvif->list, &ar->arvifs);
4977 spin_unlock_bh(&ar->data_lock);
4979 /* It makes no sense to have firmware do keepalives. mac80211 already
4980 * takes care of this with idle connection polling.
4982 ret = ath10k_mac_vif_disable_keepalive(arvif);
4984 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4985 arvif->vdev_id, ret);
4986 goto err_vdev_delete;
4989 arvif->def_wep_key_idx = -1;
4991 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4992 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4993 ATH10K_HW_TXRX_NATIVE_WIFI);
4994 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4995 if (ret && ret != -EOPNOTSUPP) {
4996 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4997 arvif->vdev_id, ret);
4998 goto err_vdev_delete;
5001 /* Configuring number of spatial stream for monitor interface is causing
5002 * target assert in qca9888 and qca6174.
5004 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
5005 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5007 vdev_param = ar->wmi.vdev_param->nss;
5008 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5011 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5012 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5014 goto err_vdev_delete;
5018 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5019 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5020 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5021 vif->addr, WMI_PEER_TYPE_DEFAULT);
5023 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5024 arvif->vdev_id, ret);
5025 goto err_vdev_delete;
5028 spin_lock_bh(&ar->data_lock);
5030 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5032 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5033 vif->addr, arvif->vdev_id);
5034 spin_unlock_bh(&ar->data_lock);
5036 goto err_peer_delete;
5039 arvif->peer_id = find_first_bit(peer->peer_ids,
5040 ATH10K_MAX_NUM_PEER_IDS);
5042 spin_unlock_bh(&ar->data_lock);
5044 arvif->peer_id = HTT_INVALID_PEERID;
5047 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5048 ret = ath10k_mac_set_kickout(arvif);
5050 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5051 arvif->vdev_id, ret);
5052 goto err_peer_delete;
5056 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5057 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5058 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5059 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5062 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5063 arvif->vdev_id, ret);
5064 goto err_peer_delete;
5067 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5069 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5070 arvif->vdev_id, ret);
5071 goto err_peer_delete;
5074 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5076 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5077 arvif->vdev_id, ret);
5078 goto err_peer_delete;
5082 ret = ath10k_mac_set_txbf_conf(arvif);
5084 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5085 arvif->vdev_id, ret);
5086 goto err_peer_delete;
5089 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5091 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5092 arvif->vdev_id, ret);
5093 goto err_peer_delete;
5096 arvif->txpower = vif->bss_conf.txpower;
5097 ret = ath10k_mac_txpower_recalc(ar);
5099 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5100 goto err_peer_delete;
5103 if (vif->type == NL80211_IFTYPE_MONITOR) {
5104 ar->monitor_arvif = arvif;
5105 ret = ath10k_monitor_recalc(ar);
5107 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5108 goto err_peer_delete;
5112 spin_lock_bh(&ar->htt.tx_lock);
5114 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5115 spin_unlock_bh(&ar->htt.tx_lock);
5117 mutex_unlock(&ar->conf_mutex);
5121 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5122 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5123 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5126 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5127 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5128 spin_lock_bh(&ar->data_lock);
5129 list_del(&arvif->list);
5130 spin_unlock_bh(&ar->data_lock);
5133 if (arvif->beacon_buf) {
5134 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5135 arvif->beacon_buf, arvif->beacon_paddr);
5136 arvif->beacon_buf = NULL;
5139 mutex_unlock(&ar->conf_mutex);
5144 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5148 for (i = 0; i < BITS_PER_LONG; i++)
5149 ath10k_mac_vif_tx_unlock(arvif, i);
5152 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5153 struct ieee80211_vif *vif)
5155 struct ath10k *ar = hw->priv;
5156 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5157 struct ath10k_peer *peer;
5161 cancel_work_sync(&arvif->ap_csa_work);
5162 cancel_delayed_work_sync(&arvif->connection_loss_work);
5164 mutex_lock(&ar->conf_mutex);
5166 spin_lock_bh(&ar->data_lock);
5167 ath10k_mac_vif_beacon_cleanup(arvif);
5168 spin_unlock_bh(&ar->data_lock);
5170 ret = ath10k_spectral_vif_stop(arvif);
5172 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5173 arvif->vdev_id, ret);
5175 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5176 spin_lock_bh(&ar->data_lock);
5177 list_del(&arvif->list);
5178 spin_unlock_bh(&ar->data_lock);
5180 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5181 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5182 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5185 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5186 arvif->vdev_id, ret);
5188 kfree(arvif->u.ap.noa_data);
5191 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5194 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5196 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5197 arvif->vdev_id, ret);
5199 /* Some firmware revisions don't notify host about self-peer removal
5200 * until after associated vdev is deleted.
5202 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5203 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5204 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5207 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5208 arvif->vdev_id, ret);
5210 spin_lock_bh(&ar->data_lock);
5212 spin_unlock_bh(&ar->data_lock);
5215 spin_lock_bh(&ar->data_lock);
5216 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5217 peer = ar->peer_map[i];
5221 if (peer->vif == vif) {
5222 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5223 vif->addr, arvif->vdev_id);
5227 spin_unlock_bh(&ar->data_lock);
5229 ath10k_peer_cleanup(ar, arvif->vdev_id);
5230 ath10k_mac_txq_unref(ar, vif->txq);
5232 if (vif->type == NL80211_IFTYPE_MONITOR) {
5233 ar->monitor_arvif = NULL;
5234 ret = ath10k_monitor_recalc(ar);
5236 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5239 spin_lock_bh(&ar->htt.tx_lock);
5240 ath10k_mac_vif_tx_unlock_all(arvif);
5241 spin_unlock_bh(&ar->htt.tx_lock);
5243 ath10k_mac_txq_unref(ar, vif->txq);
5245 mutex_unlock(&ar->conf_mutex);
5249 * FIXME: Has to be verified.
5251 #define SUPPORTED_FILTERS \
5256 FIF_BCN_PRBRESP_PROMISC | \
5260 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5261 unsigned int changed_flags,
5262 unsigned int *total_flags,
5265 struct ath10k *ar = hw->priv;
5268 mutex_lock(&ar->conf_mutex);
5270 changed_flags &= SUPPORTED_FILTERS;
5271 *total_flags &= SUPPORTED_FILTERS;
5272 ar->filter_flags = *total_flags;
5274 ret = ath10k_monitor_recalc(ar);
5276 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5278 mutex_unlock(&ar->conf_mutex);
5281 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5282 struct ieee80211_vif *vif,
5283 struct ieee80211_bss_conf *info,
5286 struct ath10k *ar = hw->priv;
5287 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5289 u32 vdev_param, pdev_param, slottime, preamble;
5291 mutex_lock(&ar->conf_mutex);
5293 if (changed & BSS_CHANGED_IBSS)
5294 ath10k_control_ibss(arvif, info, vif->addr);
5296 if (changed & BSS_CHANGED_BEACON_INT) {
5297 arvif->beacon_interval = info->beacon_int;
5298 vdev_param = ar->wmi.vdev_param->beacon_interval;
5299 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5300 arvif->beacon_interval);
5301 ath10k_dbg(ar, ATH10K_DBG_MAC,
5302 "mac vdev %d beacon_interval %d\n",
5303 arvif->vdev_id, arvif->beacon_interval);
5306 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5307 arvif->vdev_id, ret);
5310 if (changed & BSS_CHANGED_BEACON) {
5311 ath10k_dbg(ar, ATH10K_DBG_MAC,
5312 "vdev %d set beacon tx mode to staggered\n",
5315 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5316 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5317 WMI_BEACON_STAGGERED_MODE);
5319 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5320 arvif->vdev_id, ret);
5322 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5324 ath10k_warn(ar, "failed to update beacon template: %d\n",
5327 if (ieee80211_vif_is_mesh(vif)) {
5328 /* mesh doesn't use SSID but firmware needs it */
5329 strncpy(arvif->u.ap.ssid, "mesh",
5330 sizeof(arvif->u.ap.ssid));
5331 arvif->u.ap.ssid_len = 4;
5335 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5336 ret = ath10k_mac_setup_prb_tmpl(arvif);
5338 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5339 arvif->vdev_id, ret);
5342 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5343 arvif->dtim_period = info->dtim_period;
5345 ath10k_dbg(ar, ATH10K_DBG_MAC,
5346 "mac vdev %d dtim_period %d\n",
5347 arvif->vdev_id, arvif->dtim_period);
5349 vdev_param = ar->wmi.vdev_param->dtim_period;
5350 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5351 arvif->dtim_period);
5353 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5354 arvif->vdev_id, ret);
5357 if (changed & BSS_CHANGED_SSID &&
5358 vif->type == NL80211_IFTYPE_AP) {
5359 arvif->u.ap.ssid_len = info->ssid_len;
5361 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5362 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5365 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5366 ether_addr_copy(arvif->bssid, info->bssid);
5368 if (changed & BSS_CHANGED_BEACON_ENABLED)
5369 ath10k_control_beaconing(arvif, info);
5371 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5372 arvif->use_cts_prot = info->use_cts_prot;
5374 ret = ath10k_recalc_rtscts_prot(arvif);
5376 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5377 arvif->vdev_id, ret);
5379 if (ath10k_mac_can_set_cts_prot(arvif)) {
5380 ret = ath10k_mac_set_cts_prot(arvif);
5382 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5383 arvif->vdev_id, ret);
5387 if (changed & BSS_CHANGED_ERP_SLOT) {
5388 if (info->use_short_slot)
5389 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5392 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5394 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5395 arvif->vdev_id, slottime);
5397 vdev_param = ar->wmi.vdev_param->slot_time;
5398 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5401 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5402 arvif->vdev_id, ret);
5405 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5406 if (info->use_short_preamble)
5407 preamble = WMI_VDEV_PREAMBLE_SHORT;
5409 preamble = WMI_VDEV_PREAMBLE_LONG;
5411 ath10k_dbg(ar, ATH10K_DBG_MAC,
5412 "mac vdev %d preamble %dn",
5413 arvif->vdev_id, preamble);
5415 vdev_param = ar->wmi.vdev_param->preamble;
5416 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5419 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5420 arvif->vdev_id, ret);
5423 if (changed & BSS_CHANGED_ASSOC) {
5425 /* Workaround: Make sure monitor vdev is not running
5426 * when associating to prevent some firmware revisions
5427 * (e.g. 10.1 and 10.2) from crashing.
5429 if (ar->monitor_started)
5430 ath10k_monitor_stop(ar);
5431 ath10k_bss_assoc(hw, vif, info);
5432 ath10k_monitor_recalc(ar);
5434 ath10k_bss_disassoc(hw, vif);
5438 if (changed & BSS_CHANGED_TXPOWER) {
5439 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5440 arvif->vdev_id, info->txpower);
5442 arvif->txpower = info->txpower;
5443 ret = ath10k_mac_txpower_recalc(ar);
5445 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5448 if (changed & BSS_CHANGED_PS) {
5449 arvif->ps = vif->bss_conf.ps;
5451 ret = ath10k_config_ps(ar);
5453 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5454 arvif->vdev_id, ret);
5457 mutex_unlock(&ar->conf_mutex);
5460 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5461 struct ieee80211_vif *vif,
5462 struct ieee80211_scan_request *hw_req)
5464 struct ath10k *ar = hw->priv;
5465 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5466 struct cfg80211_scan_request *req = &hw_req->req;
5467 struct wmi_start_scan_arg arg;
5471 mutex_lock(&ar->conf_mutex);
5473 spin_lock_bh(&ar->data_lock);
5474 switch (ar->scan.state) {
5475 case ATH10K_SCAN_IDLE:
5476 reinit_completion(&ar->scan.started);
5477 reinit_completion(&ar->scan.completed);
5478 ar->scan.state = ATH10K_SCAN_STARTING;
5479 ar->scan.is_roc = false;
5480 ar->scan.vdev_id = arvif->vdev_id;
5483 case ATH10K_SCAN_STARTING:
5484 case ATH10K_SCAN_RUNNING:
5485 case ATH10K_SCAN_ABORTING:
5489 spin_unlock_bh(&ar->data_lock);
5494 memset(&arg, 0, sizeof(arg));
5495 ath10k_wmi_start_scan_init(ar, &arg);
5496 arg.vdev_id = arvif->vdev_id;
5497 arg.scan_id = ATH10K_SCAN_ID;
5500 arg.ie_len = req->ie_len;
5501 memcpy(arg.ie, req->ie, arg.ie_len);
5505 arg.n_ssids = req->n_ssids;
5506 for (i = 0; i < arg.n_ssids; i++) {
5507 arg.ssids[i].len = req->ssids[i].ssid_len;
5508 arg.ssids[i].ssid = req->ssids[i].ssid;
5511 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5514 if (req->n_channels) {
5515 arg.n_channels = req->n_channels;
5516 for (i = 0; i < arg.n_channels; i++)
5517 arg.channels[i] = req->channels[i]->center_freq;
5520 ret = ath10k_start_scan(ar, &arg);
5522 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5523 spin_lock_bh(&ar->data_lock);
5524 ar->scan.state = ATH10K_SCAN_IDLE;
5525 spin_unlock_bh(&ar->data_lock);
5528 /* Add a 200ms margin to account for event/command processing */
5529 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5530 msecs_to_jiffies(arg.max_scan_time +
5534 mutex_unlock(&ar->conf_mutex);
5538 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5539 struct ieee80211_vif *vif)
5541 struct ath10k *ar = hw->priv;
5543 mutex_lock(&ar->conf_mutex);
5544 ath10k_scan_abort(ar);
5545 mutex_unlock(&ar->conf_mutex);
5547 cancel_delayed_work_sync(&ar->scan.timeout);
5550 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5551 struct ath10k_vif *arvif,
5552 enum set_key_cmd cmd,
5553 struct ieee80211_key_conf *key)
5555 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5558 /* 10.1 firmware branch requires default key index to be set to group
5559 * key index after installing it. Otherwise FW/HW Txes corrupted
5560 * frames with multi-vif APs. This is not required for main firmware
5561 * branch (e.g. 636).
5563 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5565 * FIXME: It remains unknown if this is required for multi-vif STA
5566 * interfaces on 10.1.
5569 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5570 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5573 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5576 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5579 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5585 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5588 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5589 arvif->vdev_id, ret);
5592 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5593 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5594 struct ieee80211_key_conf *key)
5596 struct ath10k *ar = hw->priv;
5597 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5598 struct ath10k_peer *peer;
5599 const u8 *peer_addr;
5600 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5601 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5607 /* this one needs to be done in software */
5608 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5611 if (arvif->nohwcrypt)
5614 if (key->keyidx > WMI_MAX_KEY_INDEX)
5617 mutex_lock(&ar->conf_mutex);
5620 peer_addr = sta->addr;
5621 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5622 peer_addr = vif->bss_conf.bssid;
5624 peer_addr = vif->addr;
5626 key->hw_key_idx = key->keyidx;
5630 arvif->wep_keys[key->keyidx] = key;
5632 arvif->wep_keys[key->keyidx] = NULL;
5635 /* the peer should not disappear in mid-way (unless FW goes awry) since
5636 * we already hold conf_mutex. we just make sure its there now. */
5637 spin_lock_bh(&ar->data_lock);
5638 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5639 spin_unlock_bh(&ar->data_lock);
5642 if (cmd == SET_KEY) {
5643 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5648 /* if the peer doesn't exist there is no key to disable
5654 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5655 flags |= WMI_KEY_PAIRWISE;
5657 flags |= WMI_KEY_GROUP;
5660 if (cmd == DISABLE_KEY)
5661 ath10k_clear_vdev_key(arvif, key);
5663 /* When WEP keys are uploaded it's possible that there are
5664 * stations associated already (e.g. when merging) without any
5665 * keys. Static WEP needs an explicit per-peer key upload.
5667 if (vif->type == NL80211_IFTYPE_ADHOC &&
5669 ath10k_mac_vif_update_wep_key(arvif, key);
5671 /* 802.1x never sets the def_wep_key_idx so each set_key()
5672 * call changes default tx key.
5674 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5675 * after first set_key().
5677 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5678 flags |= WMI_KEY_TX_USAGE;
5681 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5684 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5685 arvif->vdev_id, peer_addr, ret);
5689 /* mac80211 sets static WEP keys as groupwise while firmware requires
5690 * them to be installed twice as both pairwise and groupwise.
5692 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5694 flags2 &= ~WMI_KEY_GROUP;
5695 flags2 |= WMI_KEY_PAIRWISE;
5697 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5700 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5701 arvif->vdev_id, peer_addr, ret);
5702 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5706 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5707 arvif->vdev_id, peer_addr, ret2);
5713 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5715 spin_lock_bh(&ar->data_lock);
5716 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5717 if (peer && cmd == SET_KEY)
5718 peer->keys[key->keyidx] = key;
5719 else if (peer && cmd == DISABLE_KEY)
5720 peer->keys[key->keyidx] = NULL;
5721 else if (peer == NULL)
5722 /* impossible unless FW goes crazy */
5723 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5724 spin_unlock_bh(&ar->data_lock);
5727 mutex_unlock(&ar->conf_mutex);
5731 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5732 struct ieee80211_vif *vif,
5735 struct ath10k *ar = hw->priv;
5736 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5739 mutex_lock(&arvif->ar->conf_mutex);
5741 if (arvif->ar->state != ATH10K_STATE_ON)
5744 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5745 arvif->vdev_id, keyidx);
5747 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5749 arvif->ar->wmi.vdev_param->def_keyid,
5753 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5759 arvif->def_wep_key_idx = keyidx;
5762 mutex_unlock(&arvif->ar->conf_mutex);
5765 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5768 struct ath10k_vif *arvif;
5769 struct ath10k_sta *arsta;
5770 struct ieee80211_sta *sta;
5771 struct cfg80211_chan_def def;
5772 enum nl80211_band band;
5773 const u8 *ht_mcs_mask;
5774 const u16 *vht_mcs_mask;
5775 u32 changed, bw, nss, smps;
5778 arsta = container_of(wk, struct ath10k_sta, update_wk);
5779 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5780 arvif = arsta->arvif;
5783 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5786 band = def.chan->band;
5787 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5788 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5790 spin_lock_bh(&ar->data_lock);
5792 changed = arsta->changed;
5799 spin_unlock_bh(&ar->data_lock);
5801 mutex_lock(&ar->conf_mutex);
5803 nss = max_t(u32, 1, nss);
5804 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5805 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5807 if (changed & IEEE80211_RC_BW_CHANGED) {
5808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5811 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5812 WMI_PEER_CHAN_WIDTH, bw);
5814 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5815 sta->addr, bw, err);
5818 if (changed & IEEE80211_RC_NSS_CHANGED) {
5819 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5822 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5825 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5826 sta->addr, nss, err);
5829 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5833 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5834 WMI_PEER_SMPS_STATE, smps);
5836 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5837 sta->addr, smps, err);
5840 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5841 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5844 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5846 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5850 mutex_unlock(&ar->conf_mutex);
5853 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5854 struct ieee80211_sta *sta)
5856 struct ath10k *ar = arvif->ar;
5858 lockdep_assert_held(&ar->conf_mutex);
5860 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5863 if (ar->num_stations >= ar->max_num_stations)
5871 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5872 struct ieee80211_sta *sta)
5874 struct ath10k *ar = arvif->ar;
5876 lockdep_assert_held(&ar->conf_mutex);
5878 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5884 struct ath10k_mac_tdls_iter_data {
5885 u32 num_tdls_stations;
5886 struct ieee80211_vif *curr_vif;
5889 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5890 struct ieee80211_sta *sta)
5892 struct ath10k_mac_tdls_iter_data *iter_data = data;
5893 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5894 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5896 if (sta->tdls && sta_vif == iter_data->curr_vif)
5897 iter_data->num_tdls_stations++;
5900 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5901 struct ieee80211_vif *vif)
5903 struct ath10k_mac_tdls_iter_data data = {};
5905 data.curr_vif = vif;
5907 ieee80211_iterate_stations_atomic(hw,
5908 ath10k_mac_tdls_vif_stations_count_iter,
5910 return data.num_tdls_stations;
5913 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5914 struct ieee80211_vif *vif)
5916 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5917 int *num_tdls_vifs = data;
5919 if (vif->type != NL80211_IFTYPE_STATION)
5922 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5926 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5928 int num_tdls_vifs = 0;
5930 ieee80211_iterate_active_interfaces_atomic(hw,
5931 IEEE80211_IFACE_ITER_NORMAL,
5932 ath10k_mac_tdls_vifs_count_iter,
5934 return num_tdls_vifs;
5937 static int ath10k_sta_state(struct ieee80211_hw *hw,
5938 struct ieee80211_vif *vif,
5939 struct ieee80211_sta *sta,
5940 enum ieee80211_sta_state old_state,
5941 enum ieee80211_sta_state new_state)
5943 struct ath10k *ar = hw->priv;
5944 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5945 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5946 struct ath10k_peer *peer;
5950 if (old_state == IEEE80211_STA_NOTEXIST &&
5951 new_state == IEEE80211_STA_NONE) {
5952 memset(arsta, 0, sizeof(*arsta));
5953 arsta->arvif = arvif;
5954 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5956 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5957 ath10k_mac_txq_init(sta->txq[i]);
5960 /* cancel must be done outside the mutex to avoid deadlock */
5961 if ((old_state == IEEE80211_STA_NONE &&
5962 new_state == IEEE80211_STA_NOTEXIST))
5963 cancel_work_sync(&arsta->update_wk);
5965 mutex_lock(&ar->conf_mutex);
5967 if (old_state == IEEE80211_STA_NOTEXIST &&
5968 new_state == IEEE80211_STA_NONE) {
5970 * New station addition.
5972 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5973 u32 num_tdls_stations;
5976 ath10k_dbg(ar, ATH10K_DBG_MAC,
5977 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5978 arvif->vdev_id, sta->addr,
5979 ar->num_stations + 1, ar->max_num_stations,
5980 ar->num_peers + 1, ar->max_num_peers);
5982 ret = ath10k_mac_inc_num_stations(arvif, sta);
5984 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5985 ar->max_num_stations);
5990 peer_type = WMI_PEER_TYPE_TDLS;
5992 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
5993 sta->addr, peer_type);
5995 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5996 sta->addr, arvif->vdev_id, ret);
5997 ath10k_mac_dec_num_stations(arvif, sta);
6001 spin_lock_bh(&ar->data_lock);
6003 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6005 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
6006 vif->addr, arvif->vdev_id);
6007 spin_unlock_bh(&ar->data_lock);
6008 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6009 ath10k_mac_dec_num_stations(arvif, sta);
6014 arsta->peer_id = find_first_bit(peer->peer_ids,
6015 ATH10K_MAX_NUM_PEER_IDS);
6017 spin_unlock_bh(&ar->data_lock);
6022 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6023 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6025 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
6026 num_tdls_stations == 0) {
6027 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6028 arvif->vdev_id, ar->max_num_tdls_vdevs);
6029 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6030 ath10k_mac_dec_num_stations(arvif, sta);
6035 if (num_tdls_stations == 0) {
6036 /* This is the first tdls peer in current vif */
6037 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
6039 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6042 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6043 arvif->vdev_id, ret);
6044 ath10k_peer_delete(ar, arvif->vdev_id,
6046 ath10k_mac_dec_num_stations(arvif, sta);
6051 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6052 WMI_TDLS_PEER_STATE_PEERING);
6055 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6056 sta->addr, arvif->vdev_id, ret);
6057 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6058 ath10k_mac_dec_num_stations(arvif, sta);
6060 if (num_tdls_stations != 0)
6062 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6065 } else if ((old_state == IEEE80211_STA_NONE &&
6066 new_state == IEEE80211_STA_NOTEXIST)) {
6068 * Existing station deletion.
6070 ath10k_dbg(ar, ATH10K_DBG_MAC,
6071 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6072 arvif->vdev_id, sta->addr, sta);
6075 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6077 WMI_TDLS_PEER_STATE_TEARDOWN);
6079 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6081 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6084 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6086 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6087 sta->addr, arvif->vdev_id, ret);
6089 ath10k_mac_dec_num_stations(arvif, sta);
6091 spin_lock_bh(&ar->data_lock);
6092 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6093 peer = ar->peer_map[i];
6097 if (peer->sta == sta) {
6098 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6099 sta->addr, peer, i, arvif->vdev_id);
6102 /* Clean up the peer object as well since we
6103 * must have failed to do this above.
6105 ath10k_peer_map_cleanup(ar, peer);
6108 spin_unlock_bh(&ar->data_lock);
6110 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6111 ath10k_mac_txq_unref(ar, sta->txq[i]);
6116 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6119 /* This was the last tdls peer in current vif */
6120 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6123 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6124 arvif->vdev_id, ret);
6126 } else if (old_state == IEEE80211_STA_AUTH &&
6127 new_state == IEEE80211_STA_ASSOC &&
6128 (vif->type == NL80211_IFTYPE_AP ||
6129 vif->type == NL80211_IFTYPE_MESH_POINT ||
6130 vif->type == NL80211_IFTYPE_ADHOC)) {
6134 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6137 ret = ath10k_station_assoc(ar, vif, sta, false);
6139 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6140 sta->addr, arvif->vdev_id, ret);
6141 } else if (old_state == IEEE80211_STA_ASSOC &&
6142 new_state == IEEE80211_STA_AUTHORIZED &&
6145 * Tdls station authorized.
6147 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6150 ret = ath10k_station_assoc(ar, vif, sta, false);
6152 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6153 sta->addr, arvif->vdev_id, ret);
6157 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6158 WMI_TDLS_PEER_STATE_CONNECTED);
6160 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6161 sta->addr, arvif->vdev_id, ret);
6162 } else if (old_state == IEEE80211_STA_ASSOC &&
6163 new_state == IEEE80211_STA_AUTH &&
6164 (vif->type == NL80211_IFTYPE_AP ||
6165 vif->type == NL80211_IFTYPE_MESH_POINT ||
6166 vif->type == NL80211_IFTYPE_ADHOC)) {
6170 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6173 ret = ath10k_station_disassoc(ar, vif, sta);
6175 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6176 sta->addr, arvif->vdev_id, ret);
6179 mutex_unlock(&ar->conf_mutex);
6183 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6184 u16 ac, bool enable)
6186 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6187 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6188 u32 prio = 0, acc = 0;
6192 lockdep_assert_held(&ar->conf_mutex);
6194 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6198 case IEEE80211_AC_VO:
6199 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6200 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6204 case IEEE80211_AC_VI:
6205 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6206 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6210 case IEEE80211_AC_BE:
6211 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6212 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6216 case IEEE80211_AC_BK:
6217 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6218 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6225 arvif->u.sta.uapsd |= value;
6227 arvif->u.sta.uapsd &= ~value;
6229 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6230 WMI_STA_PS_PARAM_UAPSD,
6231 arvif->u.sta.uapsd);
6233 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6237 if (arvif->u.sta.uapsd)
6238 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6240 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6242 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6243 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6246 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6248 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6250 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6251 arvif->vdev_id, ret);
6255 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6257 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6258 arvif->vdev_id, ret);
6262 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6263 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6264 /* Only userspace can make an educated decision when to send
6265 * trigger frame. The following effectively disables u-UAPSD
6266 * autotrigger in firmware (which is enabled by default
6267 * provided the autotrigger service is available).
6271 arg.user_priority = prio;
6272 arg.service_interval = 0;
6273 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6274 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6276 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6277 arvif->bssid, &arg, 1);
6279 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6289 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6290 struct ieee80211_vif *vif, u16 ac,
6291 const struct ieee80211_tx_queue_params *params)
6293 struct ath10k *ar = hw->priv;
6294 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6295 struct wmi_wmm_params_arg *p = NULL;
6298 mutex_lock(&ar->conf_mutex);
6301 case IEEE80211_AC_VO:
6302 p = &arvif->wmm_params.ac_vo;
6304 case IEEE80211_AC_VI:
6305 p = &arvif->wmm_params.ac_vi;
6307 case IEEE80211_AC_BE:
6308 p = &arvif->wmm_params.ac_be;
6310 case IEEE80211_AC_BK:
6311 p = &arvif->wmm_params.ac_bk;
6320 p->cwmin = params->cw_min;
6321 p->cwmax = params->cw_max;
6322 p->aifs = params->aifs;
6325 * The channel time duration programmed in the HW is in absolute
6326 * microseconds, while mac80211 gives the txop in units of
6329 p->txop = params->txop * 32;
6331 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6332 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6333 &arvif->wmm_params);
6335 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6336 arvif->vdev_id, ret);
6340 /* This won't work well with multi-interface cases but it's
6341 * better than nothing.
6343 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6345 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6350 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6352 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6355 mutex_unlock(&ar->conf_mutex);
6359 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6361 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6362 struct ieee80211_vif *vif,
6363 struct ieee80211_channel *chan,
6365 enum ieee80211_roc_type type)
6367 struct ath10k *ar = hw->priv;
6368 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6369 struct wmi_start_scan_arg arg;
6373 mutex_lock(&ar->conf_mutex);
6375 spin_lock_bh(&ar->data_lock);
6376 switch (ar->scan.state) {
6377 case ATH10K_SCAN_IDLE:
6378 reinit_completion(&ar->scan.started);
6379 reinit_completion(&ar->scan.completed);
6380 reinit_completion(&ar->scan.on_channel);
6381 ar->scan.state = ATH10K_SCAN_STARTING;
6382 ar->scan.is_roc = true;
6383 ar->scan.vdev_id = arvif->vdev_id;
6384 ar->scan.roc_freq = chan->center_freq;
6385 ar->scan.roc_notify = true;
6388 case ATH10K_SCAN_STARTING:
6389 case ATH10K_SCAN_RUNNING:
6390 case ATH10K_SCAN_ABORTING:
6394 spin_unlock_bh(&ar->data_lock);
6399 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6401 memset(&arg, 0, sizeof(arg));
6402 ath10k_wmi_start_scan_init(ar, &arg);
6403 arg.vdev_id = arvif->vdev_id;
6404 arg.scan_id = ATH10K_SCAN_ID;
6406 arg.channels[0] = chan->center_freq;
6407 arg.dwell_time_active = scan_time_msec;
6408 arg.dwell_time_passive = scan_time_msec;
6409 arg.max_scan_time = scan_time_msec;
6410 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6411 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6412 arg.burst_duration_ms = duration;
6414 ret = ath10k_start_scan(ar, &arg);
6416 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6417 spin_lock_bh(&ar->data_lock);
6418 ar->scan.state = ATH10K_SCAN_IDLE;
6419 spin_unlock_bh(&ar->data_lock);
6423 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6425 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6427 ret = ath10k_scan_stop(ar);
6429 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6435 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6436 msecs_to_jiffies(duration));
6440 mutex_unlock(&ar->conf_mutex);
6444 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6446 struct ath10k *ar = hw->priv;
6448 mutex_lock(&ar->conf_mutex);
6450 spin_lock_bh(&ar->data_lock);
6451 ar->scan.roc_notify = false;
6452 spin_unlock_bh(&ar->data_lock);
6454 ath10k_scan_abort(ar);
6456 mutex_unlock(&ar->conf_mutex);
6458 cancel_delayed_work_sync(&ar->scan.timeout);
6464 * Both RTS and Fragmentation threshold are interface-specific
6465 * in ath10k, but device-specific in mac80211.
6468 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6470 struct ath10k *ar = hw->priv;
6471 struct ath10k_vif *arvif;
6474 mutex_lock(&ar->conf_mutex);
6475 list_for_each_entry(arvif, &ar->arvifs, list) {
6476 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6477 arvif->vdev_id, value);
6479 ret = ath10k_mac_set_rts(arvif, value);
6481 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6482 arvif->vdev_id, ret);
6486 mutex_unlock(&ar->conf_mutex);
6491 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6493 /* Even though there's a WMI enum for fragmentation threshold no known
6494 * firmware actually implements it. Moreover it is not possible to rely
6495 * frame fragmentation to mac80211 because firmware clears the "more
6496 * fragments" bit in frame control making it impossible for remote
6497 * devices to reassemble frames.
6499 * Hence implement a dummy callback just to say fragmentation isn't
6500 * supported. This effectively prevents mac80211 from doing frame
6501 * fragmentation in software.
6506 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6507 u32 queues, bool drop)
6509 struct ath10k *ar = hw->priv;
6513 /* mac80211 doesn't care if we really xmit queued frames or not
6514 * we'll collect those frames either way if we stop/delete vdevs */
6518 mutex_lock(&ar->conf_mutex);
6520 if (ar->state == ATH10K_STATE_WEDGED)
6523 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6526 spin_lock_bh(&ar->htt.tx_lock);
6527 empty = (ar->htt.num_pending_tx == 0);
6528 spin_unlock_bh(&ar->htt.tx_lock);
6530 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6531 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6535 }), ATH10K_FLUSH_TIMEOUT_HZ);
6537 if (time_left == 0 || skip)
6538 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6539 skip, ar->state, time_left);
6542 mutex_unlock(&ar->conf_mutex);
6545 /* TODO: Implement this function properly
6546 * For now it is needed to reply to Probe Requests in IBSS mode.
6547 * Propably we need this information from FW.
6549 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6554 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6555 enum ieee80211_reconfig_type reconfig_type)
6557 struct ath10k *ar = hw->priv;
6559 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6562 mutex_lock(&ar->conf_mutex);
6564 /* If device failed to restart it will be in a different state, e.g.
6565 * ATH10K_STATE_WEDGED */
6566 if (ar->state == ATH10K_STATE_RESTARTED) {
6567 ath10k_info(ar, "device successfully recovered\n");
6568 ar->state = ATH10K_STATE_ON;
6569 ieee80211_wake_queues(ar->hw);
6572 mutex_unlock(&ar->conf_mutex);
6576 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6577 struct ieee80211_channel *channel)
6580 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6582 lockdep_assert_held(&ar->conf_mutex);
6584 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6585 (ar->rx_channel != channel))
6588 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6589 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6593 reinit_completion(&ar->bss_survey_done);
6595 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6597 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6601 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6603 ath10k_warn(ar, "bss channel survey timed out\n");
6608 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6609 struct survey_info *survey)
6611 struct ath10k *ar = hw->priv;
6612 struct ieee80211_supported_band *sband;
6613 struct survey_info *ar_survey = &ar->survey[idx];
6616 mutex_lock(&ar->conf_mutex);
6618 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6619 if (sband && idx >= sband->n_channels) {
6620 idx -= sband->n_channels;
6625 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6627 if (!sband || idx >= sband->n_channels) {
6632 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6634 spin_lock_bh(&ar->data_lock);
6635 memcpy(survey, ar_survey, sizeof(*survey));
6636 spin_unlock_bh(&ar->data_lock);
6638 survey->channel = &sband->channels[idx];
6640 if (ar->rx_channel == survey->channel)
6641 survey->filled |= SURVEY_INFO_IN_USE;
6644 mutex_unlock(&ar->conf_mutex);
6649 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6650 enum nl80211_band band,
6651 const struct cfg80211_bitrate_mask *mask)
6656 num_rates += hweight32(mask->control[band].legacy);
6658 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6659 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6661 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6662 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6664 return num_rates == 1;
6668 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6669 enum nl80211_band band,
6670 const struct cfg80211_bitrate_mask *mask,
6673 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6674 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6676 u8 vht_nss_mask = 0;
6679 if (mask->control[band].legacy)
6682 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6683 if (mask->control[band].ht_mcs[i] == 0)
6685 else if (mask->control[band].ht_mcs[i] ==
6686 sband->ht_cap.mcs.rx_mask[i])
6687 ht_nss_mask |= BIT(i);
6692 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6693 if (mask->control[band].vht_mcs[i] == 0)
6695 else if (mask->control[band].vht_mcs[i] ==
6696 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6697 vht_nss_mask |= BIT(i);
6702 if (ht_nss_mask != vht_nss_mask)
6705 if (ht_nss_mask == 0)
6708 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6711 *nss = fls(ht_nss_mask);
6717 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6718 enum nl80211_band band,
6719 const struct cfg80211_bitrate_mask *mask,
6722 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6729 if (hweight32(mask->control[band].legacy) == 1) {
6730 rate_idx = ffs(mask->control[band].legacy) - 1;
6732 hw_rate = sband->bitrates[rate_idx].hw_value;
6733 bitrate = sband->bitrates[rate_idx].bitrate;
6735 if (ath10k_mac_bitrate_is_cck(bitrate))
6736 preamble = WMI_RATE_PREAMBLE_CCK;
6738 preamble = WMI_RATE_PREAMBLE_OFDM;
6741 *rate = preamble << 6 |
6748 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6749 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6751 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6753 (ffs(mask->control[band].ht_mcs[i]) - 1);
6759 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6760 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6762 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6764 (ffs(mask->control[band].vht_mcs[i]) - 1);
6773 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6774 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6776 struct ath10k *ar = arvif->ar;
6780 lockdep_assert_held(&ar->conf_mutex);
6782 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6783 arvif->vdev_id, rate, nss, sgi);
6785 vdev_param = ar->wmi.vdev_param->fixed_rate;
6786 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6788 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6793 vdev_param = ar->wmi.vdev_param->nss;
6794 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6796 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6800 vdev_param = ar->wmi.vdev_param->sgi;
6801 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6803 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6807 vdev_param = ar->wmi.vdev_param->ldpc;
6808 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6810 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6818 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6819 enum nl80211_band band,
6820 const struct cfg80211_bitrate_mask *mask)
6825 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6826 * to express all VHT MCS rate masks. Effectively only the following
6827 * ranges can be used: none, 0-7, 0-8 and 0-9.
6829 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6830 vht_mcs = mask->control[band].vht_mcs[i];
6839 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6847 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6848 struct ieee80211_sta *sta)
6850 struct ath10k_vif *arvif = data;
6851 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6852 struct ath10k *ar = arvif->ar;
6854 if (arsta->arvif != arvif)
6857 spin_lock_bh(&ar->data_lock);
6858 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6859 spin_unlock_bh(&ar->data_lock);
6861 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6864 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6865 struct ieee80211_vif *vif,
6866 const struct cfg80211_bitrate_mask *mask)
6868 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6869 struct cfg80211_chan_def def;
6870 struct ath10k *ar = arvif->ar;
6871 enum nl80211_band band;
6872 const u8 *ht_mcs_mask;
6873 const u16 *vht_mcs_mask;
6881 if (ath10k_mac_vif_chan(vif, &def))
6884 band = def.chan->band;
6885 ht_mcs_mask = mask->control[band].ht_mcs;
6886 vht_mcs_mask = mask->control[band].vht_mcs;
6887 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6889 sgi = mask->control[band].gi;
6890 if (sgi == NL80211_TXRATE_FORCE_LGI)
6893 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6894 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6897 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6898 arvif->vdev_id, ret);
6901 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6903 rate = WMI_FIXED_RATE_NONE;
6906 rate = WMI_FIXED_RATE_NONE;
6907 nss = min(ar->num_rf_chains,
6908 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6909 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6911 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6914 mutex_lock(&ar->conf_mutex);
6916 arvif->bitrate_mask = *mask;
6917 ieee80211_iterate_stations_atomic(ar->hw,
6918 ath10k_mac_set_bitrate_mask_iter,
6921 mutex_unlock(&ar->conf_mutex);
6924 mutex_lock(&ar->conf_mutex);
6926 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6928 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6929 arvif->vdev_id, ret);
6934 mutex_unlock(&ar->conf_mutex);
6939 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6940 struct ieee80211_vif *vif,
6941 struct ieee80211_sta *sta,
6944 struct ath10k *ar = hw->priv;
6945 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6946 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6947 struct ath10k_peer *peer;
6950 spin_lock_bh(&ar->data_lock);
6952 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6954 spin_unlock_bh(&ar->data_lock);
6955 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
6956 sta->addr, arvif->vdev_id);
6960 ath10k_dbg(ar, ATH10K_DBG_MAC,
6961 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6962 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6965 if (changed & IEEE80211_RC_BW_CHANGED) {
6966 bw = WMI_PEER_CHWIDTH_20MHZ;
6968 switch (sta->bandwidth) {
6969 case IEEE80211_STA_RX_BW_20:
6970 bw = WMI_PEER_CHWIDTH_20MHZ;
6972 case IEEE80211_STA_RX_BW_40:
6973 bw = WMI_PEER_CHWIDTH_40MHZ;
6975 case IEEE80211_STA_RX_BW_80:
6976 bw = WMI_PEER_CHWIDTH_80MHZ;
6978 case IEEE80211_STA_RX_BW_160:
6979 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6980 sta->bandwidth, sta->addr);
6981 bw = WMI_PEER_CHWIDTH_20MHZ;
6988 if (changed & IEEE80211_RC_NSS_CHANGED)
6989 arsta->nss = sta->rx_nss;
6991 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6992 smps = WMI_PEER_SMPS_PS_NONE;
6994 switch (sta->smps_mode) {
6995 case IEEE80211_SMPS_AUTOMATIC:
6996 case IEEE80211_SMPS_OFF:
6997 smps = WMI_PEER_SMPS_PS_NONE;
6999 case IEEE80211_SMPS_STATIC:
7000 smps = WMI_PEER_SMPS_STATIC;
7002 case IEEE80211_SMPS_DYNAMIC:
7003 smps = WMI_PEER_SMPS_DYNAMIC;
7005 case IEEE80211_SMPS_NUM_MODES:
7006 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7007 sta->smps_mode, sta->addr);
7008 smps = WMI_PEER_SMPS_PS_NONE;
7015 arsta->changed |= changed;
7017 spin_unlock_bh(&ar->data_lock);
7019 ieee80211_queue_work(hw, &arsta->update_wk);
7022 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7025 * FIXME: Return 0 for time being. Need to figure out whether FW
7026 * has the API to fetch 64-bit local TSF
7032 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7035 struct ath10k *ar = hw->priv;
7036 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7037 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
7042 * Given tsf argument is entire TSF value, but firmware accepts
7043 * only TSF offset to current TSF.
7045 * get_tsf function is used to get offset value, however since
7046 * ath10k_get_tsf is not implemented properly, it will return 0 always.
7047 * Luckily all the caller functions to set_tsf, as of now, also rely on
7048 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
7049 * final tsf offset value to firmware will be arithmetically correct.
7051 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
7052 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7053 vdev_param, tsf_offset);
7054 if (ret && ret != -EOPNOTSUPP)
7055 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
7058 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7059 struct ieee80211_vif *vif,
7060 struct ieee80211_ampdu_params *params)
7062 struct ath10k *ar = hw->priv;
7063 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7064 struct ieee80211_sta *sta = params->sta;
7065 enum ieee80211_ampdu_mlme_action action = params->action;
7066 u16 tid = params->tid;
7068 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7069 arvif->vdev_id, sta->addr, tid, action);
7072 case IEEE80211_AMPDU_RX_START:
7073 case IEEE80211_AMPDU_RX_STOP:
7074 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7075 * creation/removal. Do we need to verify this?
7078 case IEEE80211_AMPDU_TX_START:
7079 case IEEE80211_AMPDU_TX_STOP_CONT:
7080 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7081 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7082 case IEEE80211_AMPDU_TX_OPERATIONAL:
7083 /* Firmware offloads Tx aggregation entirely so deny mac80211
7084 * Tx aggregation requests.
7093 ath10k_mac_update_rx_channel(struct ath10k *ar,
7094 struct ieee80211_chanctx_conf *ctx,
7095 struct ieee80211_vif_chanctx_switch *vifs,
7098 struct cfg80211_chan_def *def = NULL;
7100 /* Both locks are required because ar->rx_channel is modified. This
7101 * allows readers to hold either lock.
7103 lockdep_assert_held(&ar->conf_mutex);
7104 lockdep_assert_held(&ar->data_lock);
7106 WARN_ON(ctx && vifs);
7107 WARN_ON(vifs && !n_vifs);
7109 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7110 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7111 * ppdu on Rx may reduce performance on low-end systems. It should be
7112 * possible to make tables/hashmaps to speed the lookup up (be vary of
7113 * cpu data cache lines though regarding sizes) but to keep the initial
7114 * implementation simple and less intrusive fallback to the slow lookup
7115 * only for multi-channel cases. Single-channel cases will remain to
7116 * use the old channel derival and thus performance should not be
7120 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7121 ieee80211_iter_chan_contexts_atomic(ar->hw,
7122 ath10k_mac_get_any_chandef_iter,
7126 def = &vifs[0].new_ctx->def;
7128 ar->rx_channel = def->chan;
7129 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7130 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7131 /* During driver restart due to firmware assert, since mac80211
7132 * already has valid channel context for given radio, channel
7133 * context iteration return num_chanctx > 0. So fix rx_channel
7134 * when restart is in progress.
7136 ar->rx_channel = ctx->def.chan;
7138 ar->rx_channel = NULL;
7144 ath10k_mac_update_vif_chan(struct ath10k *ar,
7145 struct ieee80211_vif_chanctx_switch *vifs,
7148 struct ath10k_vif *arvif;
7152 lockdep_assert_held(&ar->conf_mutex);
7154 /* First stop monitor interface. Some FW versions crash if there's a
7155 * lone monitor interface.
7157 if (ar->monitor_started)
7158 ath10k_monitor_stop(ar);
7160 for (i = 0; i < n_vifs; i++) {
7161 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7163 ath10k_dbg(ar, ATH10K_DBG_MAC,
7164 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7166 vifs[i].old_ctx->def.chan->center_freq,
7167 vifs[i].new_ctx->def.chan->center_freq,
7168 vifs[i].old_ctx->def.width,
7169 vifs[i].new_ctx->def.width);
7171 if (WARN_ON(!arvif->is_started))
7174 if (WARN_ON(!arvif->is_up))
7177 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7179 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7180 arvif->vdev_id, ret);
7185 /* All relevant vdevs are downed and associated channel resources
7186 * should be available for the channel switch now.
7189 spin_lock_bh(&ar->data_lock);
7190 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7191 spin_unlock_bh(&ar->data_lock);
7193 for (i = 0; i < n_vifs; i++) {
7194 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7196 if (WARN_ON(!arvif->is_started))
7199 if (WARN_ON(!arvif->is_up))
7202 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7204 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7207 ret = ath10k_mac_setup_prb_tmpl(arvif);
7209 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7212 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7214 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7215 arvif->vdev_id, ret);
7219 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7222 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7223 arvif->vdev_id, ret);
7228 ath10k_monitor_recalc(ar);
7232 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7233 struct ieee80211_chanctx_conf *ctx)
7235 struct ath10k *ar = hw->priv;
7237 ath10k_dbg(ar, ATH10K_DBG_MAC,
7238 "mac chanctx add freq %hu width %d ptr %pK\n",
7239 ctx->def.chan->center_freq, ctx->def.width, ctx);
7241 mutex_lock(&ar->conf_mutex);
7243 spin_lock_bh(&ar->data_lock);
7244 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7245 spin_unlock_bh(&ar->data_lock);
7247 ath10k_recalc_radar_detection(ar);
7248 ath10k_monitor_recalc(ar);
7250 mutex_unlock(&ar->conf_mutex);
7256 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7257 struct ieee80211_chanctx_conf *ctx)
7259 struct ath10k *ar = hw->priv;
7261 ath10k_dbg(ar, ATH10K_DBG_MAC,
7262 "mac chanctx remove freq %hu width %d ptr %pK\n",
7263 ctx->def.chan->center_freq, ctx->def.width, ctx);
7265 mutex_lock(&ar->conf_mutex);
7267 spin_lock_bh(&ar->data_lock);
7268 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7269 spin_unlock_bh(&ar->data_lock);
7271 ath10k_recalc_radar_detection(ar);
7272 ath10k_monitor_recalc(ar);
7274 mutex_unlock(&ar->conf_mutex);
7277 struct ath10k_mac_change_chanctx_arg {
7278 struct ieee80211_chanctx_conf *ctx;
7279 struct ieee80211_vif_chanctx_switch *vifs;
7285 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7286 struct ieee80211_vif *vif)
7288 struct ath10k_mac_change_chanctx_arg *arg = data;
7290 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7297 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7298 struct ieee80211_vif *vif)
7300 struct ath10k_mac_change_chanctx_arg *arg = data;
7301 struct ieee80211_chanctx_conf *ctx;
7303 ctx = rcu_access_pointer(vif->chanctx_conf);
7304 if (ctx != arg->ctx)
7307 if (WARN_ON(arg->next_vif == arg->n_vifs))
7310 arg->vifs[arg->next_vif].vif = vif;
7311 arg->vifs[arg->next_vif].old_ctx = ctx;
7312 arg->vifs[arg->next_vif].new_ctx = ctx;
7317 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7318 struct ieee80211_chanctx_conf *ctx,
7321 struct ath10k *ar = hw->priv;
7322 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7324 mutex_lock(&ar->conf_mutex);
7326 ath10k_dbg(ar, ATH10K_DBG_MAC,
7327 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7328 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7330 /* This shouldn't really happen because channel switching should use
7331 * switch_vif_chanctx().
7333 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7336 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7337 ieee80211_iterate_active_interfaces_atomic(
7339 IEEE80211_IFACE_ITER_NORMAL,
7340 ath10k_mac_change_chanctx_cnt_iter,
7342 if (arg.n_vifs == 0)
7345 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7350 ieee80211_iterate_active_interfaces_atomic(
7352 IEEE80211_IFACE_ITER_NORMAL,
7353 ath10k_mac_change_chanctx_fill_iter,
7355 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7360 ath10k_recalc_radar_detection(ar);
7362 /* FIXME: How to configure Rx chains properly? */
7364 /* No other actions are actually necessary. Firmware maintains channel
7365 * definitions per vdev internally and there's no host-side channel
7366 * context abstraction to configure, e.g. channel width.
7370 mutex_unlock(&ar->conf_mutex);
7374 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7375 struct ieee80211_vif *vif,
7376 struct ieee80211_chanctx_conf *ctx)
7378 struct ath10k *ar = hw->priv;
7379 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7382 mutex_lock(&ar->conf_mutex);
7384 ath10k_dbg(ar, ATH10K_DBG_MAC,
7385 "mac chanctx assign ptr %pK vdev_id %i\n",
7386 ctx, arvif->vdev_id);
7388 if (WARN_ON(arvif->is_started)) {
7389 mutex_unlock(&ar->conf_mutex);
7393 ret = ath10k_vdev_start(arvif, &ctx->def);
7395 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7396 arvif->vdev_id, vif->addr,
7397 ctx->def.chan->center_freq, ret);
7401 arvif->is_started = true;
7403 ret = ath10k_mac_vif_setup_ps(arvif);
7405 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7406 arvif->vdev_id, ret);
7410 if (vif->type == NL80211_IFTYPE_MONITOR) {
7411 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7413 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7414 arvif->vdev_id, ret);
7418 arvif->is_up = true;
7421 if (ath10k_mac_can_set_cts_prot(arvif)) {
7422 ret = ath10k_mac_set_cts_prot(arvif);
7424 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7425 arvif->vdev_id, ret);
7428 mutex_unlock(&ar->conf_mutex);
7432 ath10k_vdev_stop(arvif);
7433 arvif->is_started = false;
7434 ath10k_mac_vif_setup_ps(arvif);
7437 mutex_unlock(&ar->conf_mutex);
7442 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7443 struct ieee80211_vif *vif,
7444 struct ieee80211_chanctx_conf *ctx)
7446 struct ath10k *ar = hw->priv;
7447 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7450 mutex_lock(&ar->conf_mutex);
7452 ath10k_dbg(ar, ATH10K_DBG_MAC,
7453 "mac chanctx unassign ptr %pK vdev_id %i\n",
7454 ctx, arvif->vdev_id);
7456 WARN_ON(!arvif->is_started);
7458 if (vif->type == NL80211_IFTYPE_MONITOR) {
7459 WARN_ON(!arvif->is_up);
7461 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7463 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7464 arvif->vdev_id, ret);
7466 arvif->is_up = false;
7469 ret = ath10k_vdev_stop(arvif);
7471 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7472 arvif->vdev_id, ret);
7474 arvif->is_started = false;
7476 mutex_unlock(&ar->conf_mutex);
7480 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7481 struct ieee80211_vif_chanctx_switch *vifs,
7483 enum ieee80211_chanctx_switch_mode mode)
7485 struct ath10k *ar = hw->priv;
7487 mutex_lock(&ar->conf_mutex);
7489 ath10k_dbg(ar, ATH10K_DBG_MAC,
7490 "mac chanctx switch n_vifs %d mode %d\n",
7492 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7494 mutex_unlock(&ar->conf_mutex);
7498 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7499 struct ieee80211_vif *vif,
7500 struct ieee80211_sta *sta)
7503 struct ath10k_peer *peer;
7507 list_for_each_entry(peer, &ar->peers, list)
7508 if (peer->sta == sta)
7509 peer->removed = true;
7512 static const struct ieee80211_ops ath10k_ops = {
7513 .tx = ath10k_mac_op_tx,
7514 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7515 .start = ath10k_start,
7516 .stop = ath10k_stop,
7517 .config = ath10k_config,
7518 .add_interface = ath10k_add_interface,
7519 .remove_interface = ath10k_remove_interface,
7520 .configure_filter = ath10k_configure_filter,
7521 .bss_info_changed = ath10k_bss_info_changed,
7522 .hw_scan = ath10k_hw_scan,
7523 .cancel_hw_scan = ath10k_cancel_hw_scan,
7524 .set_key = ath10k_set_key,
7525 .set_default_unicast_key = ath10k_set_default_unicast_key,
7526 .sta_state = ath10k_sta_state,
7527 .conf_tx = ath10k_conf_tx,
7528 .remain_on_channel = ath10k_remain_on_channel,
7529 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7530 .set_rts_threshold = ath10k_set_rts_threshold,
7531 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7532 .flush = ath10k_flush,
7533 .tx_last_beacon = ath10k_tx_last_beacon,
7534 .set_antenna = ath10k_set_antenna,
7535 .get_antenna = ath10k_get_antenna,
7536 .reconfig_complete = ath10k_reconfig_complete,
7537 .get_survey = ath10k_get_survey,
7538 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7539 .sta_rc_update = ath10k_sta_rc_update,
7540 .get_tsf = ath10k_get_tsf,
7541 .set_tsf = ath10k_set_tsf,
7542 .ampdu_action = ath10k_ampdu_action,
7543 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7544 .get_et_stats = ath10k_debug_get_et_stats,
7545 .get_et_strings = ath10k_debug_get_et_strings,
7546 .add_chanctx = ath10k_mac_op_add_chanctx,
7547 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7548 .change_chanctx = ath10k_mac_op_change_chanctx,
7549 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7550 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7551 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7552 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7554 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7557 .suspend = ath10k_wow_op_suspend,
7558 .resume = ath10k_wow_op_resume,
7560 #ifdef CONFIG_MAC80211_DEBUGFS
7561 .sta_add_debugfs = ath10k_sta_add_debugfs,
7562 .sta_statistics = ath10k_sta_statistics,
7566 #define CHAN2G(_channel, _freq, _flags) { \
7567 .band = NL80211_BAND_2GHZ, \
7568 .hw_value = (_channel), \
7569 .center_freq = (_freq), \
7570 .flags = (_flags), \
7571 .max_antenna_gain = 0, \
7575 #define CHAN5G(_channel, _freq, _flags) { \
7576 .band = NL80211_BAND_5GHZ, \
7577 .hw_value = (_channel), \
7578 .center_freq = (_freq), \
7579 .flags = (_flags), \
7580 .max_antenna_gain = 0, \
7584 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7594 CHAN2G(10, 2457, 0),
7595 CHAN2G(11, 2462, 0),
7596 CHAN2G(12, 2467, 0),
7597 CHAN2G(13, 2472, 0),
7598 CHAN2G(14, 2484, 0),
7601 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7602 CHAN5G(36, 5180, 0),
7603 CHAN5G(40, 5200, 0),
7604 CHAN5G(44, 5220, 0),
7605 CHAN5G(48, 5240, 0),
7606 CHAN5G(52, 5260, 0),
7607 CHAN5G(56, 5280, 0),
7608 CHAN5G(60, 5300, 0),
7609 CHAN5G(64, 5320, 0),
7610 CHAN5G(100, 5500, 0),
7611 CHAN5G(104, 5520, 0),
7612 CHAN5G(108, 5540, 0),
7613 CHAN5G(112, 5560, 0),
7614 CHAN5G(116, 5580, 0),
7615 CHAN5G(120, 5600, 0),
7616 CHAN5G(124, 5620, 0),
7617 CHAN5G(128, 5640, 0),
7618 CHAN5G(132, 5660, 0),
7619 CHAN5G(136, 5680, 0),
7620 CHAN5G(140, 5700, 0),
7621 CHAN5G(144, 5720, 0),
7622 CHAN5G(149, 5745, 0),
7623 CHAN5G(153, 5765, 0),
7624 CHAN5G(157, 5785, 0),
7625 CHAN5G(161, 5805, 0),
7626 CHAN5G(165, 5825, 0),
7629 struct ath10k *ath10k_mac_create(size_t priv_size)
7631 struct ieee80211_hw *hw;
7632 struct ieee80211_ops *ops;
7635 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7639 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7652 void ath10k_mac_destroy(struct ath10k *ar)
7654 struct ieee80211_ops *ops = ar->ops;
7656 ieee80211_free_hw(ar->hw);
7660 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7663 .types = BIT(NL80211_IFTYPE_STATION)
7664 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7668 .types = BIT(NL80211_IFTYPE_P2P_GO)
7672 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7676 .types = BIT(NL80211_IFTYPE_AP)
7677 #ifdef CONFIG_MAC80211_MESH
7678 | BIT(NL80211_IFTYPE_MESH_POINT)
7683 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7686 .types = BIT(NL80211_IFTYPE_AP)
7687 #ifdef CONFIG_MAC80211_MESH
7688 | BIT(NL80211_IFTYPE_MESH_POINT)
7693 .types = BIT(NL80211_IFTYPE_STATION)
7697 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7699 .limits = ath10k_if_limits,
7700 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7701 .max_interfaces = 8,
7702 .num_different_channels = 1,
7703 .beacon_int_infra_match = true,
7707 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7709 .limits = ath10k_10x_if_limits,
7710 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7711 .max_interfaces = 8,
7712 .num_different_channels = 1,
7713 .beacon_int_infra_match = true,
7714 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7715 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7716 BIT(NL80211_CHAN_WIDTH_20) |
7717 BIT(NL80211_CHAN_WIDTH_40) |
7718 BIT(NL80211_CHAN_WIDTH_80),
7723 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7726 .types = BIT(NL80211_IFTYPE_STATION),
7730 .types = BIT(NL80211_IFTYPE_AP) |
7731 #ifdef CONFIG_MAC80211_MESH
7732 BIT(NL80211_IFTYPE_MESH_POINT) |
7734 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7735 BIT(NL80211_IFTYPE_P2P_GO),
7739 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7743 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7746 .types = BIT(NL80211_IFTYPE_STATION),
7750 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7754 .types = BIT(NL80211_IFTYPE_AP) |
7755 #ifdef CONFIG_MAC80211_MESH
7756 BIT(NL80211_IFTYPE_MESH_POINT) |
7758 BIT(NL80211_IFTYPE_P2P_GO),
7762 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7766 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7769 .types = BIT(NL80211_IFTYPE_STATION),
7773 .types = BIT(NL80211_IFTYPE_ADHOC),
7777 /* FIXME: This is not thouroughly tested. These combinations may over- or
7778 * underestimate hw/fw capabilities.
7780 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7782 .limits = ath10k_tlv_if_limit,
7783 .num_different_channels = 1,
7784 .max_interfaces = 4,
7785 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7788 .limits = ath10k_tlv_if_limit_ibss,
7789 .num_different_channels = 1,
7790 .max_interfaces = 2,
7791 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7795 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7797 .limits = ath10k_tlv_if_limit,
7798 .num_different_channels = 1,
7799 .max_interfaces = 4,
7800 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7803 .limits = ath10k_tlv_qcs_if_limit,
7804 .num_different_channels = 2,
7805 .max_interfaces = 4,
7806 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7809 .limits = ath10k_tlv_if_limit_ibss,
7810 .num_different_channels = 1,
7811 .max_interfaces = 2,
7812 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7816 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7819 .types = BIT(NL80211_IFTYPE_STATION),
7823 .types = BIT(NL80211_IFTYPE_AP)
7824 #ifdef CONFIG_MAC80211_MESH
7825 | BIT(NL80211_IFTYPE_MESH_POINT)
7830 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7832 .limits = ath10k_10_4_if_limits,
7833 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7834 .max_interfaces = 16,
7835 .num_different_channels = 1,
7836 .beacon_int_infra_match = true,
7837 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7838 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7839 BIT(NL80211_CHAN_WIDTH_20) |
7840 BIT(NL80211_CHAN_WIDTH_40) |
7841 BIT(NL80211_CHAN_WIDTH_80),
7846 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7847 struct ieee80211_vif *vif)
7849 struct ath10k_vif_iter *arvif_iter = data;
7850 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7852 if (arvif->vdev_id == arvif_iter->vdev_id)
7853 arvif_iter->arvif = arvif;
7856 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7858 struct ath10k_vif_iter arvif_iter;
7861 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7862 arvif_iter.vdev_id = vdev_id;
7864 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7865 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7867 ath10k_get_arvif_iter,
7869 if (!arvif_iter.arvif) {
7870 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7874 return arvif_iter.arvif;
7877 int ath10k_mac_register(struct ath10k *ar)
7879 static const u32 cipher_suites[] = {
7880 WLAN_CIPHER_SUITE_WEP40,
7881 WLAN_CIPHER_SUITE_WEP104,
7882 WLAN_CIPHER_SUITE_TKIP,
7883 WLAN_CIPHER_SUITE_CCMP,
7884 WLAN_CIPHER_SUITE_AES_CMAC,
7886 struct ieee80211_supported_band *band;
7890 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
7892 SET_IEEE80211_DEV(ar->hw, ar->dev);
7894 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
7895 ARRAY_SIZE(ath10k_5ghz_channels)) !=
7898 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
7899 channels = kmemdup(ath10k_2ghz_channels,
7900 sizeof(ath10k_2ghz_channels),
7907 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
7908 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
7909 band->channels = channels;
7911 if (ar->hw_params.cck_rate_map_rev2) {
7912 band->n_bitrates = ath10k_g_rates_rev2_size;
7913 band->bitrates = ath10k_g_rates_rev2;
7915 band->n_bitrates = ath10k_g_rates_size;
7916 band->bitrates = ath10k_g_rates;
7919 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
7922 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
7923 channels = kmemdup(ath10k_5ghz_channels,
7924 sizeof(ath10k_5ghz_channels),
7931 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
7932 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
7933 band->channels = channels;
7934 band->n_bitrates = ath10k_a_rates_size;
7935 band->bitrates = ath10k_a_rates;
7936 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
7939 ath10k_mac_setup_ht_vht_cap(ar);
7941 ar->hw->wiphy->interface_modes =
7942 BIT(NL80211_IFTYPE_STATION) |
7943 BIT(NL80211_IFTYPE_AP) |
7944 BIT(NL80211_IFTYPE_MESH_POINT);
7946 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
7947 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
7949 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
7950 ar->hw->wiphy->interface_modes |=
7951 BIT(NL80211_IFTYPE_P2P_DEVICE) |
7952 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7953 BIT(NL80211_IFTYPE_P2P_GO);
7955 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
7956 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
7957 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
7958 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
7959 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
7960 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
7961 ieee80211_hw_set(ar->hw, AP_LINK_PS);
7962 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
7963 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
7964 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7965 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7966 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7967 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7968 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
7970 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7971 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7973 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
7974 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
7976 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
7977 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
7979 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
7980 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7981 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
7984 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7985 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7987 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
7988 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
7989 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
7991 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7993 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7994 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7996 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7997 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7998 * correct Probe Responses. This is more of a hack advert..
8000 ar->hw->wiphy->probe_resp_offload |=
8001 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
8002 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
8003 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8006 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
8007 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8009 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8010 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8011 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8013 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8014 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8015 NL80211_FEATURE_AP_SCAN;
8017 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8019 ret = ath10k_wow_init(ar);
8021 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8025 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8028 * on LL hardware queues are managed entirely by the FW
8029 * so we only advertise to mac we can do the queues thing
8031 ar->hw->queues = IEEE80211_MAX_QUEUES;
8033 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8034 * something that vdev_ids can't reach so that we don't stop the queue
8037 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8039 switch (ar->running_fw->fw_file.wmi_op_version) {
8040 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8041 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8042 ar->hw->wiphy->n_iface_combinations =
8043 ARRAY_SIZE(ath10k_if_comb);
8044 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8046 case ATH10K_FW_WMI_OP_VERSION_TLV:
8047 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8048 ar->hw->wiphy->iface_combinations =
8049 ath10k_tlv_qcs_if_comb;
8050 ar->hw->wiphy->n_iface_combinations =
8051 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8053 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8054 ar->hw->wiphy->n_iface_combinations =
8055 ARRAY_SIZE(ath10k_tlv_if_comb);
8057 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8059 case ATH10K_FW_WMI_OP_VERSION_10_1:
8060 case ATH10K_FW_WMI_OP_VERSION_10_2:
8061 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8062 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8063 ar->hw->wiphy->n_iface_combinations =
8064 ARRAY_SIZE(ath10k_10x_if_comb);
8066 case ATH10K_FW_WMI_OP_VERSION_10_4:
8067 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8068 ar->hw->wiphy->n_iface_combinations =
8069 ARRAY_SIZE(ath10k_10_4_if_comb);
8071 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8072 case ATH10K_FW_WMI_OP_VERSION_MAX:
8078 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8079 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8081 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8082 /* Init ath dfs pattern detector */
8083 ar->ath_common.debug_mask = ATH_DBG_DFS;
8084 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8087 if (!ar->dfs_detector)
8088 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8091 /* Current wake_tx_queue implementation imposes a significant
8092 * performance penalty in some setups. The tx scheduling code needs
8093 * more work anyway so disable the wake_tx_queue unless firmware
8094 * supports the pull-push mechanism.
8096 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8097 ar->running_fw->fw_file.fw_features))
8098 ar->ops->wake_tx_queue = NULL;
8100 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8101 ath10k_reg_notifier);
8103 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8104 goto err_dfs_detector_exit;
8107 ar->hw->wiphy->cipher_suites = cipher_suites;
8108 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8110 ret = ieee80211_register_hw(ar->hw);
8112 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8113 goto err_dfs_detector_exit;
8116 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8117 ret = regulatory_hint(ar->hw->wiphy,
8118 ar->ath_common.regulatory.alpha2);
8120 goto err_unregister;
8126 ieee80211_unregister_hw(ar->hw);
8128 err_dfs_detector_exit:
8129 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8130 ar->dfs_detector->exit(ar->dfs_detector);
8133 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8134 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8136 SET_IEEE80211_DEV(ar->hw, NULL);
8140 void ath10k_mac_unregister(struct ath10k *ar)
8142 ieee80211_unregister_hw(ar->hw);
8144 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8145 ar->dfs_detector->exit(ar->dfs_detector);
8147 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8148 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8150 SET_IEEE80211_DEV(ar->hw, NULL);