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_cleanup(struct ath10k *ar, u32 vdev_id)
803 struct ath10k_peer *peer, *tmp;
807 lockdep_assert_held(&ar->conf_mutex);
809 spin_lock_bh(&ar->data_lock);
810 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
811 if (peer->vdev_id != vdev_id)
814 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
815 peer->addr, vdev_id);
817 for_each_set_bit(peer_id, peer->peer_ids,
818 ATH10K_MAX_NUM_PEER_IDS) {
819 ar->peer_map[peer_id] = NULL;
822 /* Double check that peer is properly un-referenced from
825 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
826 if (ar->peer_map[i] == peer) {
827 ath10k_warn(ar, "removing stale peer_map entry for %pM (ptr %pK idx %d)\n",
828 peer->addr, peer, i);
829 ar->peer_map[i] = NULL;
833 list_del(&peer->list);
837 spin_unlock_bh(&ar->data_lock);
840 static void ath10k_peer_cleanup_all(struct ath10k *ar)
842 struct ath10k_peer *peer, *tmp;
845 lockdep_assert_held(&ar->conf_mutex);
847 spin_lock_bh(&ar->data_lock);
848 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
849 list_del(&peer->list);
853 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++)
854 ar->peer_map[i] = NULL;
856 spin_unlock_bh(&ar->data_lock);
859 ar->num_stations = 0;
862 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
863 struct ieee80211_sta *sta,
864 enum wmi_tdls_peer_state state)
867 struct wmi_tdls_peer_update_cmd_arg arg = {};
868 struct wmi_tdls_peer_capab_arg cap = {};
869 struct wmi_channel_arg chan_arg = {};
871 lockdep_assert_held(&ar->conf_mutex);
873 arg.vdev_id = vdev_id;
874 arg.peer_state = state;
875 ether_addr_copy(arg.addr, sta->addr);
877 cap.peer_max_sp = sta->max_sp;
878 cap.peer_uapsd_queues = sta->uapsd_queues;
880 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
881 !sta->tdls_initiator)
882 cap.is_peer_responder = 1;
884 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
886 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
887 arg.addr, vdev_id, ret);
894 /************************/
895 /* Interface management */
896 /************************/
898 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
900 struct ath10k *ar = arvif->ar;
902 lockdep_assert_held(&ar->data_lock);
907 if (!arvif->beacon_buf)
908 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
909 arvif->beacon->len, DMA_TO_DEVICE);
911 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
912 arvif->beacon_state != ATH10K_BEACON_SENT))
915 dev_kfree_skb_any(arvif->beacon);
917 arvif->beacon = NULL;
918 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
921 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
923 struct ath10k *ar = arvif->ar;
925 lockdep_assert_held(&ar->data_lock);
927 ath10k_mac_vif_beacon_free(arvif);
929 if (arvif->beacon_buf) {
930 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
931 arvif->beacon_buf, arvif->beacon_paddr);
932 arvif->beacon_buf = NULL;
936 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
938 unsigned long time_left;
940 lockdep_assert_held(&ar->conf_mutex);
942 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
945 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
946 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
950 return ar->last_wmi_vdev_start_status;
953 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
955 struct cfg80211_chan_def *chandef = NULL;
956 struct ieee80211_channel *channel = NULL;
957 struct wmi_vdev_start_request_arg arg = {};
960 lockdep_assert_held(&ar->conf_mutex);
962 ieee80211_iter_chan_contexts_atomic(ar->hw,
963 ath10k_mac_get_any_chandef_iter,
965 if (WARN_ON_ONCE(!chandef))
968 channel = chandef->chan;
970 arg.vdev_id = vdev_id;
971 arg.channel.freq = channel->center_freq;
972 arg.channel.band_center_freq1 = chandef->center_freq1;
974 /* TODO setup this dynamically, what in case we
975 don't have any vifs? */
976 arg.channel.mode = chan_to_phymode(chandef);
977 arg.channel.chan_radar =
978 !!(channel->flags & IEEE80211_CHAN_RADAR);
980 arg.channel.min_power = 0;
981 arg.channel.max_power = channel->max_power * 2;
982 arg.channel.max_reg_power = channel->max_reg_power * 2;
983 arg.channel.max_antenna_gain = channel->max_antenna_gain;
985 reinit_completion(&ar->vdev_setup_done);
987 ret = ath10k_wmi_vdev_start(ar, &arg);
989 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
994 ret = ath10k_vdev_setup_sync(ar);
996 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
1001 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
1003 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
1008 ar->monitor_vdev_id = vdev_id;
1010 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
1011 ar->monitor_vdev_id);
1015 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1017 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
1018 ar->monitor_vdev_id, ret);
1023 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
1027 lockdep_assert_held(&ar->conf_mutex);
1029 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1031 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
1032 ar->monitor_vdev_id, ret);
1034 reinit_completion(&ar->vdev_setup_done);
1036 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1038 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
1039 ar->monitor_vdev_id, ret);
1041 ret = ath10k_vdev_setup_sync(ar);
1043 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
1044 ar->monitor_vdev_id, ret);
1046 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1047 ar->monitor_vdev_id);
1051 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1055 lockdep_assert_held(&ar->conf_mutex);
1057 if (ar->free_vdev_map == 0) {
1058 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1062 bit = __ffs64(ar->free_vdev_map);
1064 ar->monitor_vdev_id = bit;
1066 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1067 WMI_VDEV_TYPE_MONITOR,
1070 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1071 ar->monitor_vdev_id, ret);
1075 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1076 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1077 ar->monitor_vdev_id);
1082 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1086 lockdep_assert_held(&ar->conf_mutex);
1088 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1090 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1091 ar->monitor_vdev_id, ret);
1095 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1097 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1098 ar->monitor_vdev_id);
1102 static int ath10k_monitor_start(struct ath10k *ar)
1106 lockdep_assert_held(&ar->conf_mutex);
1108 ret = ath10k_monitor_vdev_create(ar);
1110 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1114 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1116 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1117 ath10k_monitor_vdev_delete(ar);
1121 ar->monitor_started = true;
1122 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1127 static int ath10k_monitor_stop(struct ath10k *ar)
1131 lockdep_assert_held(&ar->conf_mutex);
1133 ret = ath10k_monitor_vdev_stop(ar);
1135 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1139 ret = ath10k_monitor_vdev_delete(ar);
1141 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1145 ar->monitor_started = false;
1146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1151 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1155 /* At least one chanctx is required to derive a channel to start
1158 num_ctx = ath10k_mac_num_chanctxs(ar);
1162 /* If there's already an existing special monitor interface then don't
1163 * bother creating another monitor vdev.
1165 if (ar->monitor_arvif)
1168 return ar->monitor ||
1169 ar->filter_flags & FIF_OTHER_BSS ||
1170 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1173 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1177 num_ctx = ath10k_mac_num_chanctxs(ar);
1179 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1180 * shouldn't allow this but make sure to prevent handling the following
1181 * case anyway since multi-channel DFS hasn't been tested at all.
1183 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1189 static int ath10k_monitor_recalc(struct ath10k *ar)
1195 lockdep_assert_held(&ar->conf_mutex);
1197 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1198 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1200 ath10k_dbg(ar, ATH10K_DBG_MAC,
1201 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1202 ar->monitor_started, needed, allowed);
1204 if (WARN_ON(needed && !allowed)) {
1205 if (ar->monitor_started) {
1206 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1208 ret = ath10k_monitor_stop(ar);
1210 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1218 if (needed == ar->monitor_started)
1222 return ath10k_monitor_start(ar);
1224 return ath10k_monitor_stop(ar);
1227 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1229 struct ath10k *ar = arvif->ar;
1231 lockdep_assert_held(&ar->conf_mutex);
1233 if (!arvif->is_started) {
1234 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1241 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1243 struct ath10k *ar = arvif->ar;
1246 lockdep_assert_held(&ar->conf_mutex);
1248 vdev_param = ar->wmi.vdev_param->protection_mode;
1250 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1251 arvif->vdev_id, arvif->use_cts_prot);
1253 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1254 arvif->use_cts_prot ? 1 : 0);
1257 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1259 struct ath10k *ar = arvif->ar;
1260 u32 vdev_param, rts_cts = 0;
1262 lockdep_assert_held(&ar->conf_mutex);
1264 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1266 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1268 if (arvif->num_legacy_stations > 0)
1269 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1270 WMI_RTSCTS_PROFILE);
1272 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1273 WMI_RTSCTS_PROFILE);
1275 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1279 static int ath10k_start_cac(struct ath10k *ar)
1283 lockdep_assert_held(&ar->conf_mutex);
1285 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1287 ret = ath10k_monitor_recalc(ar);
1289 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1290 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1294 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1295 ar->monitor_vdev_id);
1300 static int ath10k_stop_cac(struct ath10k *ar)
1302 lockdep_assert_held(&ar->conf_mutex);
1304 /* CAC is not running - do nothing */
1305 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1308 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1309 ath10k_monitor_stop(ar);
1311 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1316 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1317 struct ieee80211_chanctx_conf *conf,
1322 if (!*ret && conf->radar_enabled)
1326 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1328 bool has_radar = false;
1330 ieee80211_iter_chan_contexts_atomic(ar->hw,
1331 ath10k_mac_has_radar_iter,
1337 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1341 lockdep_assert_held(&ar->conf_mutex);
1343 ath10k_stop_cac(ar);
1345 if (!ath10k_mac_has_radar_enabled(ar))
1348 if (ar->num_started_vdevs > 0)
1351 ret = ath10k_start_cac(ar);
1354 * Not possible to start CAC on current channel so starting
1355 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1356 * by indicating that radar was detected.
1358 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1359 ieee80211_radar_detected(ar->hw);
1363 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1365 struct ath10k *ar = arvif->ar;
1368 lockdep_assert_held(&ar->conf_mutex);
1370 reinit_completion(&ar->vdev_setup_done);
1372 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1374 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1375 arvif->vdev_id, ret);
1379 ret = ath10k_vdev_setup_sync(ar);
1381 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1382 arvif->vdev_id, ret);
1386 WARN_ON(ar->num_started_vdevs == 0);
1388 if (ar->num_started_vdevs != 0) {
1389 ar->num_started_vdevs--;
1390 ath10k_recalc_radar_detection(ar);
1396 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1397 const struct cfg80211_chan_def *chandef,
1400 struct ath10k *ar = arvif->ar;
1401 struct wmi_vdev_start_request_arg arg = {};
1404 lockdep_assert_held(&ar->conf_mutex);
1406 reinit_completion(&ar->vdev_setup_done);
1408 arg.vdev_id = arvif->vdev_id;
1409 arg.dtim_period = arvif->dtim_period;
1410 arg.bcn_intval = arvif->beacon_interval;
1412 arg.channel.freq = chandef->chan->center_freq;
1413 arg.channel.band_center_freq1 = chandef->center_freq1;
1414 arg.channel.mode = chan_to_phymode(chandef);
1416 arg.channel.min_power = 0;
1417 arg.channel.max_power = chandef->chan->max_power * 2;
1418 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1419 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
1421 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1422 arg.ssid = arvif->u.ap.ssid;
1423 arg.ssid_len = arvif->u.ap.ssid_len;
1424 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1426 /* For now allow DFS for AP mode */
1427 arg.channel.chan_radar =
1428 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1429 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1430 arg.ssid = arvif->vif->bss_conf.ssid;
1431 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1434 ath10k_dbg(ar, ATH10K_DBG_MAC,
1435 "mac vdev %d start center_freq %d phymode %s\n",
1436 arg.vdev_id, arg.channel.freq,
1437 ath10k_wmi_phymode_str(arg.channel.mode));
1440 ret = ath10k_wmi_vdev_restart(ar, &arg);
1442 ret = ath10k_wmi_vdev_start(ar, &arg);
1445 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1450 ret = ath10k_vdev_setup_sync(ar);
1453 "failed to synchronize setup for vdev %i restart %d: %d\n",
1454 arg.vdev_id, restart, ret);
1458 ar->num_started_vdevs++;
1459 ath10k_recalc_radar_detection(ar);
1464 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1465 const struct cfg80211_chan_def *def)
1467 return ath10k_vdev_start_restart(arvif, def, false);
1470 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1471 const struct cfg80211_chan_def *def)
1473 return ath10k_vdev_start_restart(arvif, def, true);
1476 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1477 struct sk_buff *bcn)
1479 struct ath10k *ar = arvif->ar;
1480 struct ieee80211_mgmt *mgmt;
1484 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1487 mgmt = (void *)bcn->data;
1488 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1489 mgmt->u.beacon.variable,
1490 bcn->len - (mgmt->u.beacon.variable -
1495 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1497 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1498 arvif->vdev_id, ret);
1505 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1506 u8 oui_type, size_t ie_offset)
1513 if (WARN_ON(skb->len < ie_offset))
1516 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1517 skb->data + ie_offset,
1518 skb->len - ie_offset);
1523 end = skb->data + skb->len;
1526 if (WARN_ON(next > end))
1529 memmove(ie, next, end - next);
1530 skb_trim(skb, skb->len - len);
1535 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1537 struct ath10k *ar = arvif->ar;
1538 struct ieee80211_hw *hw = ar->hw;
1539 struct ieee80211_vif *vif = arvif->vif;
1540 struct ieee80211_mutable_offsets offs = {};
1541 struct sk_buff *bcn;
1544 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1547 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1548 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1551 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1553 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1557 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1559 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1564 /* P2P IE is inserted by firmware automatically (as configured above)
1565 * so remove it from the base beacon template to avoid duplicate P2P
1566 * IEs in beacon frames.
1568 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1569 offsetof(struct ieee80211_mgmt,
1570 u.beacon.variable));
1572 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1577 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1585 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1587 struct ath10k *ar = arvif->ar;
1588 struct ieee80211_hw *hw = ar->hw;
1589 struct ieee80211_vif *vif = arvif->vif;
1590 struct sk_buff *prb;
1593 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1596 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1599 /* For mesh, probe response and beacon share the same template */
1600 if (ieee80211_vif_is_mesh(vif))
1603 prb = ieee80211_proberesp_get(hw, vif);
1605 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1609 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1613 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1621 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1623 struct ath10k *ar = arvif->ar;
1624 struct cfg80211_chan_def def;
1627 /* When originally vdev is started during assign_vif_chanctx() some
1628 * information is missing, notably SSID. Firmware revisions with beacon
1629 * offloading require the SSID to be provided during vdev (re)start to
1630 * handle hidden SSID properly.
1632 * Vdev restart must be done after vdev has been both started and
1633 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1634 * deliver vdev restart response event causing timeouts during vdev
1635 * syncing in ath10k.
1637 * Note: The vdev down/up and template reinstallation could be skipped
1638 * since only wmi-tlv firmware are known to have beacon offload and
1639 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1640 * response delivery. It's probably more robust to keep it as is.
1642 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1645 if (WARN_ON(!arvif->is_started))
1648 if (WARN_ON(!arvif->is_up))
1651 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1654 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1656 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1657 arvif->vdev_id, ret);
1661 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1662 * firmware will crash upon vdev up.
1665 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1667 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1671 ret = ath10k_mac_setup_prb_tmpl(arvif);
1673 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1677 ret = ath10k_vdev_restart(arvif, &def);
1679 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1680 arvif->vdev_id, ret);
1684 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1687 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1688 arvif->vdev_id, ret);
1695 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1696 struct ieee80211_bss_conf *info)
1698 struct ath10k *ar = arvif->ar;
1701 lockdep_assert_held(&arvif->ar->conf_mutex);
1703 if (!info->enable_beacon) {
1704 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1706 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1707 arvif->vdev_id, ret);
1709 arvif->is_up = false;
1711 spin_lock_bh(&arvif->ar->data_lock);
1712 ath10k_mac_vif_beacon_free(arvif);
1713 spin_unlock_bh(&arvif->ar->data_lock);
1718 arvif->tx_seq_no = 0x1000;
1721 ether_addr_copy(arvif->bssid, info->bssid);
1723 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1726 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1727 arvif->vdev_id, ret);
1731 arvif->is_up = true;
1733 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1735 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1736 arvif->vdev_id, ret);
1740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1743 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1744 struct ieee80211_bss_conf *info,
1745 const u8 self_peer[ETH_ALEN])
1747 struct ath10k *ar = arvif->ar;
1751 lockdep_assert_held(&arvif->ar->conf_mutex);
1753 if (!info->ibss_joined) {
1754 if (is_zero_ether_addr(arvif->bssid))
1757 eth_zero_addr(arvif->bssid);
1762 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1763 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1764 ATH10K_DEFAULT_ATIM);
1766 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1767 arvif->vdev_id, ret);
1770 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1772 struct ath10k *ar = arvif->ar;
1777 lockdep_assert_held(&arvif->ar->conf_mutex);
1779 if (arvif->u.sta.uapsd)
1780 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1782 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1784 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1785 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1787 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1788 value, arvif->vdev_id, ret);
1795 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1797 struct ath10k *ar = arvif->ar;
1802 lockdep_assert_held(&arvif->ar->conf_mutex);
1804 if (arvif->u.sta.uapsd)
1805 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1807 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1809 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1810 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1813 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1814 value, arvif->vdev_id, ret);
1821 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1823 struct ath10k_vif *arvif;
1826 lockdep_assert_held(&ar->conf_mutex);
1828 list_for_each_entry(arvif, &ar->arvifs, list)
1829 if (arvif->is_started)
1835 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1837 struct ath10k *ar = arvif->ar;
1838 struct ieee80211_vif *vif = arvif->vif;
1839 struct ieee80211_conf *conf = &ar->hw->conf;
1840 enum wmi_sta_powersave_param param;
1841 enum wmi_sta_ps_mode psmode;
1846 lockdep_assert_held(&arvif->ar->conf_mutex);
1848 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1851 enable_ps = arvif->ps;
1853 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1854 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1855 ar->running_fw->fw_file.fw_features)) {
1856 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1861 if (!arvif->is_started) {
1862 /* mac80211 can update vif powersave state while disconnected.
1863 * Firmware doesn't behave nicely and consumes more power than
1864 * necessary if PS is disabled on a non-started vdev. Hence
1865 * force-enable PS for non-running vdevs.
1867 psmode = WMI_STA_PS_MODE_ENABLED;
1868 } else if (enable_ps) {
1869 psmode = WMI_STA_PS_MODE_ENABLED;
1870 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1872 ps_timeout = conf->dynamic_ps_timeout;
1873 if (ps_timeout == 0) {
1874 /* Firmware doesn't like 0 */
1875 ps_timeout = ieee80211_tu_to_usec(
1876 vif->bss_conf.beacon_int) / 1000;
1879 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1882 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1883 arvif->vdev_id, ret);
1887 psmode = WMI_STA_PS_MODE_DISABLED;
1890 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1891 arvif->vdev_id, psmode ? "enable" : "disable");
1893 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1895 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1896 psmode, arvif->vdev_id, ret);
1903 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1905 struct ath10k *ar = arvif->ar;
1906 struct wmi_sta_keepalive_arg arg = {};
1909 lockdep_assert_held(&arvif->ar->conf_mutex);
1911 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1914 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1917 /* Some firmware revisions have a bug and ignore the `enabled` field.
1918 * Instead use the interval to disable the keepalive.
1920 arg.vdev_id = arvif->vdev_id;
1922 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1923 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1925 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1927 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1928 arvif->vdev_id, ret);
1935 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1937 struct ath10k *ar = arvif->ar;
1938 struct ieee80211_vif *vif = arvif->vif;
1941 lockdep_assert_held(&arvif->ar->conf_mutex);
1943 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1946 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1949 if (!vif->csa_active)
1955 if (!ieee80211_csa_is_complete(vif)) {
1956 ieee80211_csa_update_counter(vif);
1958 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1960 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1963 ret = ath10k_mac_setup_prb_tmpl(arvif);
1965 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1968 ieee80211_csa_finish(vif);
1972 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1974 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1976 struct ath10k *ar = arvif->ar;
1978 mutex_lock(&ar->conf_mutex);
1979 ath10k_mac_vif_ap_csa_count_down(arvif);
1980 mutex_unlock(&ar->conf_mutex);
1983 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1984 struct ieee80211_vif *vif)
1986 struct sk_buff *skb = data;
1987 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1988 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1990 if (vif->type != NL80211_IFTYPE_STATION)
1993 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1996 cancel_delayed_work(&arvif->connection_loss_work);
1999 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
2001 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2002 IEEE80211_IFACE_ITER_NORMAL,
2003 ath10k_mac_handle_beacon_iter,
2007 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
2008 struct ieee80211_vif *vif)
2010 u32 *vdev_id = data;
2011 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2012 struct ath10k *ar = arvif->ar;
2013 struct ieee80211_hw *hw = ar->hw;
2015 if (arvif->vdev_id != *vdev_id)
2021 ieee80211_beacon_loss(vif);
2023 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
2024 * (done by mac80211) succeeds but beacons do not resume then it
2025 * doesn't make sense to continue operation. Queue connection loss work
2026 * which can be cancelled when beacon is received.
2028 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
2029 ATH10K_CONNECTION_LOSS_HZ);
2032 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2034 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2035 IEEE80211_IFACE_ITER_NORMAL,
2036 ath10k_mac_handle_beacon_miss_iter,
2040 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2042 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2043 connection_loss_work.work);
2044 struct ieee80211_vif *vif = arvif->vif;
2049 ieee80211_connection_loss(vif);
2052 /**********************/
2053 /* Station management */
2054 /**********************/
2056 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2057 struct ieee80211_vif *vif)
2059 /* Some firmware revisions have unstable STA powersave when listen
2060 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2061 * generate NullFunc frames properly even if buffered frames have been
2062 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2063 * buffered frames. Often pinging the device from AP would simply fail.
2065 * As a workaround set it to 1.
2067 if (vif->type == NL80211_IFTYPE_STATION)
2070 return ar->hw->conf.listen_interval;
2073 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2074 struct ieee80211_vif *vif,
2075 struct ieee80211_sta *sta,
2076 struct wmi_peer_assoc_complete_arg *arg)
2078 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2081 lockdep_assert_held(&ar->conf_mutex);
2083 if (vif->type == NL80211_IFTYPE_STATION)
2084 aid = vif->bss_conf.aid;
2088 ether_addr_copy(arg->addr, sta->addr);
2089 arg->vdev_id = arvif->vdev_id;
2090 arg->peer_aid = aid;
2091 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2092 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2093 arg->peer_num_spatial_streams = 1;
2094 arg->peer_caps = vif->bss_conf.assoc_capability;
2097 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2098 struct ieee80211_vif *vif,
2099 struct ieee80211_sta *sta,
2100 struct wmi_peer_assoc_complete_arg *arg)
2102 struct ieee80211_bss_conf *info = &vif->bss_conf;
2103 struct cfg80211_chan_def def;
2104 struct cfg80211_bss *bss;
2105 const u8 *rsnie = NULL;
2106 const u8 *wpaie = NULL;
2108 lockdep_assert_held(&ar->conf_mutex);
2110 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2113 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2114 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2116 const struct cfg80211_bss_ies *ies;
2119 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2121 ies = rcu_dereference(bss->ies);
2123 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2124 WLAN_OUI_TYPE_MICROSOFT_WPA,
2128 cfg80211_put_bss(ar->hw->wiphy, bss);
2131 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2132 if (rsnie || wpaie) {
2133 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2134 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2138 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2139 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2143 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2144 ar->running_fw->fw_file.fw_features)) {
2145 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2149 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2150 struct ieee80211_vif *vif,
2151 struct ieee80211_sta *sta,
2152 struct wmi_peer_assoc_complete_arg *arg)
2154 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2155 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2156 struct cfg80211_chan_def def;
2157 const struct ieee80211_supported_band *sband;
2158 const struct ieee80211_rate *rates;
2159 enum nl80211_band band;
2164 lockdep_assert_held(&ar->conf_mutex);
2166 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2169 band = def.chan->band;
2170 sband = ar->hw->wiphy->bands[band];
2171 ratemask = sta->supp_rates[band];
2172 ratemask &= arvif->bitrate_mask.control[band].legacy;
2173 rates = sband->bitrates;
2175 rateset->num_rates = 0;
2177 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2178 if (!(ratemask & 1))
2181 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2182 rateset->rates[rateset->num_rates] = rate;
2183 rateset->num_rates++;
2188 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2192 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2193 if (ht_mcs_mask[nss])
2200 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2204 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2205 if (vht_mcs_mask[nss])
2211 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2212 struct ieee80211_vif *vif,
2213 struct ieee80211_sta *sta,
2214 struct wmi_peer_assoc_complete_arg *arg)
2216 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2217 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2218 struct cfg80211_chan_def def;
2219 enum nl80211_band band;
2220 const u8 *ht_mcs_mask;
2221 const u16 *vht_mcs_mask;
2226 lockdep_assert_held(&ar->conf_mutex);
2228 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2231 if (!ht_cap->ht_supported)
2234 band = def.chan->band;
2235 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2236 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2238 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2239 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2242 arg->peer_flags |= ar->wmi.peer_flags->ht;
2243 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2244 ht_cap->ampdu_factor)) - 1;
2246 arg->peer_mpdu_density =
2247 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2249 arg->peer_ht_caps = ht_cap->cap;
2250 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2252 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2253 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2255 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2256 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2257 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2260 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2261 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2262 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2264 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2265 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2268 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2269 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2270 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2273 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2274 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2275 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2276 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2277 arg->peer_rate_caps |= stbc;
2278 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2281 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2282 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2283 else if (ht_cap->mcs.rx_mask[1])
2284 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2286 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2287 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2288 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2289 max_nss = (i / 8) + 1;
2290 arg->peer_ht_rates.rates[n++] = i;
2294 * This is a workaround for HT-enabled STAs which break the spec
2295 * and have no HT capabilities RX mask (no HT RX MCS map).
2297 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2298 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2300 * Firmware asserts if such situation occurs.
2303 arg->peer_ht_rates.num_rates = 8;
2304 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2305 arg->peer_ht_rates.rates[i] = i;
2307 arg->peer_ht_rates.num_rates = n;
2308 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2311 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2313 arg->peer_ht_rates.num_rates,
2314 arg->peer_num_spatial_streams);
2317 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2318 struct ath10k_vif *arvif,
2319 struct ieee80211_sta *sta)
2325 lockdep_assert_held(&ar->conf_mutex);
2327 if (sta->wme && sta->uapsd_queues) {
2328 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2329 sta->uapsd_queues, sta->max_sp);
2331 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2332 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2333 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2334 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2335 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2336 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2337 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2338 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2339 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2340 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2341 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2342 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2344 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2345 max_sp = sta->max_sp;
2347 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2349 WMI_AP_PS_PEER_PARAM_UAPSD,
2352 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2353 arvif->vdev_id, ret);
2357 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2359 WMI_AP_PS_PEER_PARAM_MAX_SP,
2362 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2363 arvif->vdev_id, ret);
2367 /* TODO setup this based on STA listen interval and
2368 beacon interval. Currently we don't know
2369 sta->listen_interval - mac80211 patch required.
2370 Currently use 10 seconds */
2371 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2372 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2375 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2376 arvif->vdev_id, ret);
2385 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2386 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2393 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2394 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2398 idx_limit = fls(mcs_map) - 1;
2402 switch (idx_limit) {
2403 case 0: /* fall through */
2404 case 1: /* fall through */
2405 case 2: /* fall through */
2406 case 3: /* fall through */
2407 case 4: /* fall through */
2408 case 5: /* fall through */
2409 case 6: /* fall through */
2411 /* see ath10k_mac_can_set_bitrate_mask() */
2415 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2418 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2421 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2424 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2428 tx_mcs_set &= ~(0x3 << (nss * 2));
2429 tx_mcs_set |= mcs << (nss * 2);
2435 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2436 struct ieee80211_vif *vif,
2437 struct ieee80211_sta *sta,
2438 struct wmi_peer_assoc_complete_arg *arg)
2440 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2441 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2442 struct cfg80211_chan_def def;
2443 enum nl80211_band band;
2444 const u16 *vht_mcs_mask;
2447 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2450 if (!vht_cap->vht_supported)
2453 band = def.chan->band;
2454 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2456 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2459 arg->peer_flags |= ar->wmi.peer_flags->vht;
2461 if (def.chan->band == NL80211_BAND_2GHZ)
2462 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2464 arg->peer_vht_caps = vht_cap->cap;
2466 ampdu_factor = (vht_cap->cap &
2467 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2468 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2470 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2471 * zero in VHT IE. Using it would result in degraded throughput.
2472 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2473 * it if VHT max_mpdu is smaller. */
2474 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2475 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2476 ampdu_factor)) - 1);
2478 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2479 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2481 arg->peer_vht_rates.rx_max_rate =
2482 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2483 arg->peer_vht_rates.rx_mcs_set =
2484 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2485 arg->peer_vht_rates.tx_max_rate =
2486 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2487 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2488 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2490 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2491 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2494 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2495 struct ieee80211_vif *vif,
2496 struct ieee80211_sta *sta,
2497 struct wmi_peer_assoc_complete_arg *arg)
2499 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2501 switch (arvif->vdev_type) {
2502 case WMI_VDEV_TYPE_AP:
2504 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2506 if (sta->wme && sta->uapsd_queues) {
2507 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2508 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2511 case WMI_VDEV_TYPE_STA:
2513 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2515 case WMI_VDEV_TYPE_IBSS:
2517 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2523 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2524 sta->addr, !!(arg->peer_flags &
2525 arvif->ar->wmi.peer_flags->qos));
2528 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2530 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2531 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2534 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2535 struct ieee80211_vif *vif,
2536 struct ieee80211_sta *sta,
2537 struct wmi_peer_assoc_complete_arg *arg)
2539 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2540 struct cfg80211_chan_def def;
2541 enum nl80211_band band;
2542 const u8 *ht_mcs_mask;
2543 const u16 *vht_mcs_mask;
2544 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2546 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2549 band = def.chan->band;
2550 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2551 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2554 case NL80211_BAND_2GHZ:
2555 if (sta->vht_cap.vht_supported &&
2556 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2557 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2558 phymode = MODE_11AC_VHT40;
2560 phymode = MODE_11AC_VHT20;
2561 } else if (sta->ht_cap.ht_supported &&
2562 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2563 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2564 phymode = MODE_11NG_HT40;
2566 phymode = MODE_11NG_HT20;
2567 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2574 case NL80211_BAND_5GHZ:
2578 if (sta->vht_cap.vht_supported &&
2579 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2580 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2581 phymode = MODE_11AC_VHT80;
2582 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2583 phymode = MODE_11AC_VHT40;
2584 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2585 phymode = MODE_11AC_VHT20;
2586 } else if (sta->ht_cap.ht_supported &&
2587 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2588 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2589 phymode = MODE_11NA_HT40;
2591 phymode = MODE_11NA_HT20;
2601 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2602 sta->addr, ath10k_wmi_phymode_str(phymode));
2604 arg->peer_phymode = phymode;
2605 WARN_ON(phymode == MODE_UNKNOWN);
2608 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2609 struct ieee80211_vif *vif,
2610 struct ieee80211_sta *sta,
2611 struct wmi_peer_assoc_complete_arg *arg)
2613 lockdep_assert_held(&ar->conf_mutex);
2615 memset(arg, 0, sizeof(*arg));
2617 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2618 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2619 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2620 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2621 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2622 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2623 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2628 static const u32 ath10k_smps_map[] = {
2629 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2630 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2631 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2632 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2635 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2637 const struct ieee80211_sta_ht_cap *ht_cap)
2641 if (!ht_cap->ht_supported)
2644 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2645 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2647 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2650 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2651 WMI_PEER_SMPS_STATE,
2652 ath10k_smps_map[smps]);
2655 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2656 struct ieee80211_vif *vif,
2657 struct ieee80211_sta_vht_cap vht_cap)
2659 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2664 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2667 if (!(ar->vht_cap_info &
2668 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2669 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2670 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2671 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2674 param = ar->wmi.vdev_param->txbf;
2677 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2680 /* The following logic is correct. If a remote STA advertises support
2681 * for being a beamformer then we should enable us being a beamformee.
2684 if (ar->vht_cap_info &
2685 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2686 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2687 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2688 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2690 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2691 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2694 if (ar->vht_cap_info &
2695 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2696 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2697 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2698 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2700 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2701 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2704 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2705 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2707 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2708 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2710 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2712 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2720 /* can be called only in mac80211 callbacks due to `key_count` usage */
2721 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2722 struct ieee80211_vif *vif,
2723 struct ieee80211_bss_conf *bss_conf)
2725 struct ath10k *ar = hw->priv;
2726 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2727 struct ieee80211_sta_ht_cap ht_cap;
2728 struct ieee80211_sta_vht_cap vht_cap;
2729 struct wmi_peer_assoc_complete_arg peer_arg;
2730 struct ieee80211_sta *ap_sta;
2733 lockdep_assert_held(&ar->conf_mutex);
2735 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2736 arvif->vdev_id, arvif->bssid, arvif->aid);
2740 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2742 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2743 bss_conf->bssid, arvif->vdev_id);
2748 /* ap_sta must be accessed only within rcu section which must be left
2749 * before calling ath10k_setup_peer_smps() which might sleep. */
2750 ht_cap = ap_sta->ht_cap;
2751 vht_cap = ap_sta->vht_cap;
2753 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2755 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2756 bss_conf->bssid, arvif->vdev_id, ret);
2763 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2765 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2766 bss_conf->bssid, arvif->vdev_id, ret);
2770 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2772 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2773 arvif->vdev_id, ret);
2777 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2779 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2780 arvif->vdev_id, bss_conf->bssid, ret);
2784 ath10k_dbg(ar, ATH10K_DBG_MAC,
2785 "mac vdev %d up (associated) bssid %pM aid %d\n",
2786 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2788 WARN_ON(arvif->is_up);
2790 arvif->aid = bss_conf->aid;
2791 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2793 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2795 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2796 arvif->vdev_id, ret);
2800 arvif->is_up = true;
2802 /* Workaround: Some firmware revisions (tested with qca6174
2803 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2804 * poked with peer param command.
2806 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2807 WMI_PEER_DUMMY_VAR, 1);
2809 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2810 arvif->bssid, arvif->vdev_id, ret);
2815 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2816 struct ieee80211_vif *vif)
2818 struct ath10k *ar = hw->priv;
2819 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2820 struct ieee80211_sta_vht_cap vht_cap = {};
2823 lockdep_assert_held(&ar->conf_mutex);
2825 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2826 arvif->vdev_id, arvif->bssid);
2828 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2830 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2831 arvif->vdev_id, ret);
2833 arvif->def_wep_key_idx = -1;
2835 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2837 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2838 arvif->vdev_id, ret);
2842 arvif->is_up = false;
2844 cancel_delayed_work_sync(&arvif->connection_loss_work);
2847 static int ath10k_station_assoc(struct ath10k *ar,
2848 struct ieee80211_vif *vif,
2849 struct ieee80211_sta *sta,
2852 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2853 struct wmi_peer_assoc_complete_arg peer_arg;
2856 lockdep_assert_held(&ar->conf_mutex);
2858 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2860 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2861 sta->addr, arvif->vdev_id, ret);
2865 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2867 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2868 sta->addr, arvif->vdev_id, ret);
2872 /* Re-assoc is run only to update supported rates for given station. It
2873 * doesn't make much sense to reconfigure the peer completely.
2876 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2879 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2880 arvif->vdev_id, ret);
2884 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2886 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2887 sta->addr, arvif->vdev_id, ret);
2892 arvif->num_legacy_stations++;
2893 ret = ath10k_recalc_rtscts_prot(arvif);
2895 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2896 arvif->vdev_id, ret);
2901 /* Plumb cached keys only for static WEP */
2902 if (arvif->def_wep_key_idx != -1) {
2903 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2905 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2906 arvif->vdev_id, ret);
2915 static int ath10k_station_disassoc(struct ath10k *ar,
2916 struct ieee80211_vif *vif,
2917 struct ieee80211_sta *sta)
2919 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2922 lockdep_assert_held(&ar->conf_mutex);
2925 arvif->num_legacy_stations--;
2926 ret = ath10k_recalc_rtscts_prot(arvif);
2928 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2929 arvif->vdev_id, ret);
2934 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2936 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2937 arvif->vdev_id, ret);
2948 static int ath10k_update_channel_list(struct ath10k *ar)
2950 struct ieee80211_hw *hw = ar->hw;
2951 struct ieee80211_supported_band **bands;
2952 enum nl80211_band band;
2953 struct ieee80211_channel *channel;
2954 struct wmi_scan_chan_list_arg arg = {0};
2955 struct wmi_channel_arg *ch;
2961 lockdep_assert_held(&ar->conf_mutex);
2963 bands = hw->wiphy->bands;
2964 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2968 for (i = 0; i < bands[band]->n_channels; i++) {
2969 if (bands[band]->channels[i].flags &
2970 IEEE80211_CHAN_DISABLED)
2977 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2978 arg.channels = kzalloc(len, GFP_KERNEL);
2983 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2987 for (i = 0; i < bands[band]->n_channels; i++) {
2988 channel = &bands[band]->channels[i];
2990 if (channel->flags & IEEE80211_CHAN_DISABLED)
2993 ch->allow_ht = true;
2995 /* FIXME: when should we really allow VHT? */
2996 ch->allow_vht = true;
2999 !(channel->flags & IEEE80211_CHAN_NO_IR);
3002 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
3005 !!(channel->flags & IEEE80211_CHAN_RADAR);
3007 passive = channel->flags & IEEE80211_CHAN_NO_IR;
3008 ch->passive = passive;
3010 /* the firmware is ignoring the "radar" flag of the
3011 * channel and is scanning actively using Probe Requests
3012 * on "Radar detection"/DFS channels which are not
3013 * marked as "available"
3015 ch->passive |= ch->chan_radar;
3017 ch->freq = channel->center_freq;
3018 ch->band_center_freq1 = channel->center_freq;
3020 ch->max_power = channel->max_power * 2;
3021 ch->max_reg_power = channel->max_reg_power * 2;
3022 ch->max_antenna_gain = channel->max_antenna_gain;
3023 ch->reg_class_id = 0; /* FIXME */
3025 /* FIXME: why use only legacy modes, why not any
3026 * HT/VHT modes? Would that even make any
3028 if (channel->band == NL80211_BAND_2GHZ)
3029 ch->mode = MODE_11G;
3031 ch->mode = MODE_11A;
3033 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
3036 ath10k_dbg(ar, ATH10K_DBG_WMI,
3037 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
3038 ch - arg.channels, arg.n_channels,
3039 ch->freq, ch->max_power, ch->max_reg_power,
3040 ch->max_antenna_gain, ch->mode);
3046 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3047 kfree(arg.channels);
3052 static enum wmi_dfs_region
3053 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3055 switch (dfs_region) {
3056 case NL80211_DFS_UNSET:
3057 return WMI_UNINIT_DFS_DOMAIN;
3058 case NL80211_DFS_FCC:
3059 return WMI_FCC_DFS_DOMAIN;
3060 case NL80211_DFS_ETSI:
3061 return WMI_ETSI_DFS_DOMAIN;
3062 case NL80211_DFS_JP:
3063 return WMI_MKK4_DFS_DOMAIN;
3065 return WMI_UNINIT_DFS_DOMAIN;
3068 static void ath10k_regd_update(struct ath10k *ar)
3070 struct reg_dmn_pair_mapping *regpair;
3072 enum wmi_dfs_region wmi_dfs_reg;
3073 enum nl80211_dfs_regions nl_dfs_reg;
3075 lockdep_assert_held(&ar->conf_mutex);
3077 ret = ath10k_update_channel_list(ar);
3079 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3081 regpair = ar->ath_common.regulatory.regpair;
3083 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3084 nl_dfs_reg = ar->dfs_detector->region;
3085 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3087 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3090 /* Target allows setting up per-band regdomain but ath_common provides
3091 * a combined one only */
3092 ret = ath10k_wmi_pdev_set_regdomain(ar,
3093 regpair->reg_domain,
3094 regpair->reg_domain, /* 2ghz */
3095 regpair->reg_domain, /* 5ghz */
3096 regpair->reg_2ghz_ctl,
3097 regpair->reg_5ghz_ctl,
3100 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3103 static void ath10k_reg_notifier(struct wiphy *wiphy,
3104 struct regulatory_request *request)
3106 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3107 struct ath10k *ar = hw->priv;
3110 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3112 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3113 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3114 request->dfs_region);
3115 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3116 request->dfs_region);
3118 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3119 request->dfs_region);
3122 mutex_lock(&ar->conf_mutex);
3123 if (ar->state == ATH10K_STATE_ON)
3124 ath10k_regd_update(ar);
3125 mutex_unlock(&ar->conf_mutex);
3132 enum ath10k_mac_tx_path {
3134 ATH10K_MAC_TX_HTT_MGMT,
3135 ATH10K_MAC_TX_WMI_MGMT,
3136 ATH10K_MAC_TX_UNKNOWN,
3139 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3141 lockdep_assert_held(&ar->htt.tx_lock);
3143 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3144 ar->tx_paused |= BIT(reason);
3145 ieee80211_stop_queues(ar->hw);
3148 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3149 struct ieee80211_vif *vif)
3151 struct ath10k *ar = data;
3152 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3154 if (arvif->tx_paused)
3157 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3160 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3162 lockdep_assert_held(&ar->htt.tx_lock);
3164 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3165 ar->tx_paused &= ~BIT(reason);
3170 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3171 IEEE80211_IFACE_ITER_RESUME_ALL,
3172 ath10k_mac_tx_unlock_iter,
3175 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3178 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3180 struct ath10k *ar = arvif->ar;
3182 lockdep_assert_held(&ar->htt.tx_lock);
3184 WARN_ON(reason >= BITS_PER_LONG);
3185 arvif->tx_paused |= BIT(reason);
3186 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3189 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3191 struct ath10k *ar = arvif->ar;
3193 lockdep_assert_held(&ar->htt.tx_lock);
3195 WARN_ON(reason >= BITS_PER_LONG);
3196 arvif->tx_paused &= ~BIT(reason);
3201 if (arvif->tx_paused)
3204 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3207 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3208 enum wmi_tlv_tx_pause_id pause_id,
3209 enum wmi_tlv_tx_pause_action action)
3211 struct ath10k *ar = arvif->ar;
3213 lockdep_assert_held(&ar->htt.tx_lock);
3216 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3217 ath10k_mac_vif_tx_lock(arvif, pause_id);
3219 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3220 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3223 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3224 action, arvif->vdev_id);
3229 struct ath10k_mac_tx_pause {
3231 enum wmi_tlv_tx_pause_id pause_id;
3232 enum wmi_tlv_tx_pause_action action;
3235 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3236 struct ieee80211_vif *vif)
3238 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3239 struct ath10k_mac_tx_pause *arg = data;
3241 if (arvif->vdev_id != arg->vdev_id)
3244 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3247 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3248 enum wmi_tlv_tx_pause_id pause_id,
3249 enum wmi_tlv_tx_pause_action action)
3251 struct ath10k_mac_tx_pause arg = {
3253 .pause_id = pause_id,
3257 spin_lock_bh(&ar->htt.tx_lock);
3258 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3259 IEEE80211_IFACE_ITER_RESUME_ALL,
3260 ath10k_mac_handle_tx_pause_iter,
3262 spin_unlock_bh(&ar->htt.tx_lock);
3265 static enum ath10k_hw_txrx_mode
3266 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3267 struct ieee80211_vif *vif,
3268 struct ieee80211_sta *sta,
3269 struct sk_buff *skb)
3271 const struct ieee80211_hdr *hdr = (void *)skb->data;
3272 __le16 fc = hdr->frame_control;
3274 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3275 return ATH10K_HW_TXRX_RAW;
3277 if (ieee80211_is_mgmt(fc))
3278 return ATH10K_HW_TXRX_MGMT;
3282 * NullFunc frames are mostly used to ping if a client or AP are still
3283 * reachable and responsive. This implies tx status reports must be
3284 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3285 * come to a conclusion that the other end disappeared and tear down
3286 * BSS connection or it can never disconnect from BSS/client (which is
3289 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3290 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3291 * which seems to deliver correct tx reports for NullFunc frames. The
3292 * downside of using it is it ignores client powersave state so it can
3293 * end up disconnecting sleeping clients in AP mode. It should fix STA
3294 * mode though because AP don't sleep.
3296 if (ar->htt.target_version_major < 3 &&
3297 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3298 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3299 ar->running_fw->fw_file.fw_features))
3300 return ATH10K_HW_TXRX_MGMT;
3304 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3305 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3306 * to work with Ethernet txmode so use it.
3308 * FIXME: Check if raw mode works with TDLS.
3310 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3311 return ATH10K_HW_TXRX_ETHERNET;
3313 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3314 return ATH10K_HW_TXRX_RAW;
3316 return ATH10K_HW_TXRX_NATIVE_WIFI;
3319 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3320 struct sk_buff *skb)
3322 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3323 const struct ieee80211_hdr *hdr = (void *)skb->data;
3324 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3325 IEEE80211_TX_CTL_INJECTED;
3327 if (!ieee80211_has_protected(hdr->frame_control))
3330 if ((info->flags & mask) == mask)
3334 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3339 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3340 * Control in the header.
3342 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3344 struct ieee80211_hdr *hdr = (void *)skb->data;
3345 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3348 if (!ieee80211_is_data_qos(hdr->frame_control))
3351 qos_ctl = ieee80211_get_qos_ctl(hdr);
3352 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3353 skb->data, (void *)qos_ctl - (void *)skb->data);
3354 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3356 /* Some firmware revisions don't handle sending QoS NullFunc well.
3357 * These frames are mainly used for CQM purposes so it doesn't really
3358 * matter whether QoS NullFunc or NullFunc are sent.
3360 hdr = (void *)skb->data;
3361 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3362 cb->flags &= ~ATH10K_SKB_F_QOS;
3364 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3367 static void ath10k_tx_h_8023(struct sk_buff *skb)
3369 struct ieee80211_hdr *hdr;
3370 struct rfc1042_hdr *rfc1042;
3377 hdr = (void *)skb->data;
3378 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3379 rfc1042 = (void *)skb->data + hdrlen;
3381 ether_addr_copy(da, ieee80211_get_DA(hdr));
3382 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3383 type = rfc1042->snap_type;
3385 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3386 skb_push(skb, sizeof(*eth));
3388 eth = (void *)skb->data;
3389 ether_addr_copy(eth->h_dest, da);
3390 ether_addr_copy(eth->h_source, sa);
3391 eth->h_proto = type;
3394 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3395 struct ieee80211_vif *vif,
3396 struct sk_buff *skb)
3398 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3399 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3401 /* This is case only for P2P_GO */
3402 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3405 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3406 spin_lock_bh(&ar->data_lock);
3407 if (arvif->u.ap.noa_data)
3408 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3410 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3411 arvif->u.ap.noa_data,
3412 arvif->u.ap.noa_len);
3413 spin_unlock_bh(&ar->data_lock);
3417 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3418 struct ieee80211_vif *vif,
3419 struct ieee80211_txq *txq,
3420 struct sk_buff *skb)
3422 struct ieee80211_hdr *hdr = (void *)skb->data;
3423 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3426 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3427 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3429 if (ieee80211_is_mgmt(hdr->frame_control))
3430 cb->flags |= ATH10K_SKB_F_MGMT;
3432 if (ieee80211_is_data_qos(hdr->frame_control))
3433 cb->flags |= ATH10K_SKB_F_QOS;
3439 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3441 /* FIXME: Not really sure since when the behaviour changed. At some
3442 * point new firmware stopped requiring creation of peer entries for
3443 * offchannel tx (and actually creating them causes issues with wmi-htc
3444 * tx credit replenishment and reliability). Assuming it's at least 3.4
3445 * because that's when the `freq` was introduced to TX_FRM HTT command.
3447 return (ar->htt.target_version_major >= 3 &&
3448 ar->htt.target_version_minor >= 4 &&
3449 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3452 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3454 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3456 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3457 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3461 skb_queue_tail(q, skb);
3462 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3467 static enum ath10k_mac_tx_path
3468 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3469 struct sk_buff *skb,
3470 enum ath10k_hw_txrx_mode txmode)
3473 case ATH10K_HW_TXRX_RAW:
3474 case ATH10K_HW_TXRX_NATIVE_WIFI:
3475 case ATH10K_HW_TXRX_ETHERNET:
3476 return ATH10K_MAC_TX_HTT;
3477 case ATH10K_HW_TXRX_MGMT:
3478 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3479 ar->running_fw->fw_file.fw_features))
3480 return ATH10K_MAC_TX_WMI_MGMT;
3481 else if (ar->htt.target_version_major >= 3)
3482 return ATH10K_MAC_TX_HTT;
3484 return ATH10K_MAC_TX_HTT_MGMT;
3487 return ATH10K_MAC_TX_UNKNOWN;
3490 static int ath10k_mac_tx_submit(struct ath10k *ar,
3491 enum ath10k_hw_txrx_mode txmode,
3492 enum ath10k_mac_tx_path txpath,
3493 struct sk_buff *skb)
3495 struct ath10k_htt *htt = &ar->htt;
3499 case ATH10K_MAC_TX_HTT:
3500 ret = ath10k_htt_tx(htt, txmode, skb);
3502 case ATH10K_MAC_TX_HTT_MGMT:
3503 ret = ath10k_htt_mgmt_tx(htt, skb);
3505 case ATH10K_MAC_TX_WMI_MGMT:
3506 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3508 case ATH10K_MAC_TX_UNKNOWN:
3515 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3517 ieee80211_free_txskb(ar->hw, skb);
3523 /* This function consumes the sk_buff regardless of return value as far as
3524 * caller is concerned so no freeing is necessary afterwards.
3526 static int ath10k_mac_tx(struct ath10k *ar,
3527 struct ieee80211_vif *vif,
3528 struct ieee80211_sta *sta,
3529 enum ath10k_hw_txrx_mode txmode,
3530 enum ath10k_mac_tx_path txpath,
3531 struct sk_buff *skb)
3533 struct ieee80211_hw *hw = ar->hw;
3534 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3537 /* We should disable CCK RATE due to P2P */
3538 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3539 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3542 case ATH10K_HW_TXRX_MGMT:
3543 case ATH10K_HW_TXRX_NATIVE_WIFI:
3544 ath10k_tx_h_nwifi(hw, skb);
3545 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3546 ath10k_tx_h_seq_no(vif, skb);
3548 case ATH10K_HW_TXRX_ETHERNET:
3549 ath10k_tx_h_8023(skb);
3551 case ATH10K_HW_TXRX_RAW:
3552 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3554 ieee80211_free_txskb(hw, skb);
3559 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3560 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3561 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3564 skb_queue_tail(&ar->offchan_tx_queue, skb);
3565 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3570 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3572 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3579 void ath10k_offchan_tx_purge(struct ath10k *ar)
3581 struct sk_buff *skb;
3584 skb = skb_dequeue(&ar->offchan_tx_queue);
3588 ieee80211_free_txskb(ar->hw, skb);
3592 void ath10k_offchan_tx_work(struct work_struct *work)
3594 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3595 struct ath10k_peer *peer;
3596 struct ath10k_vif *arvif;
3597 enum ath10k_hw_txrx_mode txmode;
3598 enum ath10k_mac_tx_path txpath;
3599 struct ieee80211_hdr *hdr;
3600 struct ieee80211_vif *vif;
3601 struct ieee80211_sta *sta;
3602 struct sk_buff *skb;
3603 const u8 *peer_addr;
3606 unsigned long time_left;
3607 bool tmp_peer_created = false;
3609 /* FW requirement: We must create a peer before FW will send out
3610 * an offchannel frame. Otherwise the frame will be stuck and
3611 * never transmitted. We delete the peer upon tx completion.
3612 * It is unlikely that a peer for offchannel tx will already be
3613 * present. However it may be in some rare cases so account for that.
3614 * Otherwise we might remove a legitimate peer and break stuff. */
3617 skb = skb_dequeue(&ar->offchan_tx_queue);
3621 mutex_lock(&ar->conf_mutex);
3623 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3626 hdr = (struct ieee80211_hdr *)skb->data;
3627 peer_addr = ieee80211_get_DA(hdr);
3629 spin_lock_bh(&ar->data_lock);
3630 vdev_id = ar->scan.vdev_id;
3631 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3632 spin_unlock_bh(&ar->data_lock);
3635 /* FIXME: should this use ath10k_warn()? */
3636 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3637 peer_addr, vdev_id);
3640 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3642 WMI_PEER_TYPE_DEFAULT);
3644 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3645 peer_addr, vdev_id, ret);
3646 tmp_peer_created = (ret == 0);
3649 spin_lock_bh(&ar->data_lock);
3650 reinit_completion(&ar->offchan_tx_completed);
3651 ar->offchan_tx_skb = skb;
3652 spin_unlock_bh(&ar->data_lock);
3654 /* It's safe to access vif and sta - conf_mutex guarantees that
3655 * sta_state() and remove_interface() are locked exclusively
3656 * out wrt to this offchannel worker.
3658 arvif = ath10k_get_arvif(ar, vdev_id);
3661 sta = ieee80211_find_sta(vif, peer_addr);
3667 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3668 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3670 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3672 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3678 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3680 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3683 if (!peer && tmp_peer_created) {
3684 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3686 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3687 peer_addr, vdev_id, ret);
3690 mutex_unlock(&ar->conf_mutex);
3694 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3696 struct sk_buff *skb;
3699 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3703 ieee80211_free_txskb(ar->hw, skb);
3707 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3709 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3710 struct sk_buff *skb;
3714 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3718 ret = ath10k_wmi_mgmt_tx(ar, skb);
3720 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3722 ieee80211_free_txskb(ar->hw, skb);
3727 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3729 struct ath10k_txq *artxq;
3734 artxq = (void *)txq->drv_priv;
3735 INIT_LIST_HEAD(&artxq->list);
3738 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3740 struct ath10k_txq *artxq;
3741 struct ath10k_skb_cb *cb;
3742 struct sk_buff *msdu;
3748 artxq = (void *)txq->drv_priv;
3749 spin_lock_bh(&ar->txqs_lock);
3750 if (!list_empty(&artxq->list))
3751 list_del_init(&artxq->list);
3752 spin_unlock_bh(&ar->txqs_lock);
3754 spin_lock_bh(&ar->htt.tx_lock);
3755 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3756 cb = ATH10K_SKB_CB(msdu);
3760 spin_unlock_bh(&ar->htt.tx_lock);
3763 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3767 struct ath10k_peer *peer;
3769 lockdep_assert_held(&ar->data_lock);
3771 peer = ar->peer_map[peer_id];
3779 return peer->sta->txq[tid];
3781 return peer->vif->txq;
3786 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3787 struct ieee80211_txq *txq)
3789 struct ath10k *ar = hw->priv;
3790 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3792 /* No need to get locks */
3794 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3797 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3800 if (artxq->num_fw_queued < artxq->num_push_allowed)
3806 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3807 struct ieee80211_txq *txq)
3809 struct ath10k *ar = hw->priv;
3810 struct ath10k_htt *htt = &ar->htt;
3811 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3812 struct ieee80211_vif *vif = txq->vif;
3813 struct ieee80211_sta *sta = txq->sta;
3814 enum ath10k_hw_txrx_mode txmode;
3815 enum ath10k_mac_tx_path txpath;
3816 struct sk_buff *skb;
3817 struct ieee80211_hdr *hdr;
3819 bool is_mgmt, is_presp;
3822 spin_lock_bh(&ar->htt.tx_lock);
3823 ret = ath10k_htt_tx_inc_pending(htt);
3824 spin_unlock_bh(&ar->htt.tx_lock);
3829 skb = ieee80211_tx_dequeue(hw, txq);
3831 spin_lock_bh(&ar->htt.tx_lock);
3832 ath10k_htt_tx_dec_pending(htt);
3833 spin_unlock_bh(&ar->htt.tx_lock);
3838 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3841 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3842 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3843 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3846 hdr = (struct ieee80211_hdr *)skb->data;
3847 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3849 spin_lock_bh(&ar->htt.tx_lock);
3850 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3853 ath10k_htt_tx_dec_pending(htt);
3854 spin_unlock_bh(&ar->htt.tx_lock);
3857 spin_unlock_bh(&ar->htt.tx_lock);
3860 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3861 if (unlikely(ret)) {
3862 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3864 spin_lock_bh(&ar->htt.tx_lock);
3865 ath10k_htt_tx_dec_pending(htt);
3867 ath10k_htt_tx_mgmt_dec_pending(htt);
3868 spin_unlock_bh(&ar->htt.tx_lock);
3873 spin_lock_bh(&ar->htt.tx_lock);
3874 artxq->num_fw_queued++;
3875 spin_unlock_bh(&ar->htt.tx_lock);
3880 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3882 struct ieee80211_hw *hw = ar->hw;
3883 struct ieee80211_txq *txq;
3884 struct ath10k_txq *artxq;
3885 struct ath10k_txq *last;
3889 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3892 spin_lock_bh(&ar->txqs_lock);
3895 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3896 while (!list_empty(&ar->txqs)) {
3897 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3898 txq = container_of((void *)artxq, struct ieee80211_txq,
3901 /* Prevent aggressive sta/tid taking over tx queue */
3904 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3905 ret = ath10k_mac_tx_push_txq(hw, txq);
3910 list_del_init(&artxq->list);
3912 list_add_tail(&artxq->list, &ar->txqs);
3914 ath10k_htt_tx_txq_update(hw, txq);
3916 if (artxq == last || (ret < 0 && ret != -ENOENT))
3921 spin_unlock_bh(&ar->txqs_lock);
3928 void __ath10k_scan_finish(struct ath10k *ar)
3930 lockdep_assert_held(&ar->data_lock);
3932 switch (ar->scan.state) {
3933 case ATH10K_SCAN_IDLE:
3935 case ATH10K_SCAN_RUNNING:
3936 case ATH10K_SCAN_ABORTING:
3937 if (!ar->scan.is_roc) {
3938 struct cfg80211_scan_info info = {
3939 .aborted = (ar->scan.state ==
3940 ATH10K_SCAN_ABORTING),
3943 ieee80211_scan_completed(ar->hw, &info);
3944 } else if (ar->scan.roc_notify) {
3945 ieee80211_remain_on_channel_expired(ar->hw);
3948 case ATH10K_SCAN_STARTING:
3949 ar->scan.state = ATH10K_SCAN_IDLE;
3950 ar->scan_channel = NULL;
3951 ar->scan.roc_freq = 0;
3952 ath10k_offchan_tx_purge(ar);
3953 cancel_delayed_work(&ar->scan.timeout);
3954 complete(&ar->scan.completed);
3959 void ath10k_scan_finish(struct ath10k *ar)
3961 spin_lock_bh(&ar->data_lock);
3962 __ath10k_scan_finish(ar);
3963 spin_unlock_bh(&ar->data_lock);
3966 static int ath10k_scan_stop(struct ath10k *ar)
3968 struct wmi_stop_scan_arg arg = {
3969 .req_id = 1, /* FIXME */
3970 .req_type = WMI_SCAN_STOP_ONE,
3971 .u.scan_id = ATH10K_SCAN_ID,
3975 lockdep_assert_held(&ar->conf_mutex);
3977 ret = ath10k_wmi_stop_scan(ar, &arg);
3979 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3983 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
3985 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3987 } else if (ret > 0) {
3992 /* Scan state should be updated upon scan completion but in case
3993 * firmware fails to deliver the event (for whatever reason) it is
3994 * desired to clean up scan state anyway. Firmware may have just
3995 * dropped the scan completion event delivery due to transport pipe
3996 * being overflown with data and/or it can recover on its own before
3997 * next scan request is submitted.
3999 spin_lock_bh(&ar->data_lock);
4000 if (ar->scan.state != ATH10K_SCAN_IDLE)
4001 __ath10k_scan_finish(ar);
4002 spin_unlock_bh(&ar->data_lock);
4007 static void ath10k_scan_abort(struct ath10k *ar)
4011 lockdep_assert_held(&ar->conf_mutex);
4013 spin_lock_bh(&ar->data_lock);
4015 switch (ar->scan.state) {
4016 case ATH10K_SCAN_IDLE:
4017 /* This can happen if timeout worker kicked in and called
4018 * abortion while scan completion was being processed.
4021 case ATH10K_SCAN_STARTING:
4022 case ATH10K_SCAN_ABORTING:
4023 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
4024 ath10k_scan_state_str(ar->scan.state),
4027 case ATH10K_SCAN_RUNNING:
4028 ar->scan.state = ATH10K_SCAN_ABORTING;
4029 spin_unlock_bh(&ar->data_lock);
4031 ret = ath10k_scan_stop(ar);
4033 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
4035 spin_lock_bh(&ar->data_lock);
4039 spin_unlock_bh(&ar->data_lock);
4042 void ath10k_scan_timeout_work(struct work_struct *work)
4044 struct ath10k *ar = container_of(work, struct ath10k,
4047 mutex_lock(&ar->conf_mutex);
4048 ath10k_scan_abort(ar);
4049 mutex_unlock(&ar->conf_mutex);
4052 static int ath10k_start_scan(struct ath10k *ar,
4053 const struct wmi_start_scan_arg *arg)
4057 lockdep_assert_held(&ar->conf_mutex);
4059 ret = ath10k_wmi_start_scan(ar, arg);
4063 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4065 ret = ath10k_scan_stop(ar);
4067 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4072 /* If we failed to start the scan, return error code at
4073 * this point. This is probably due to some issue in the
4074 * firmware, but no need to wedge the driver due to that...
4076 spin_lock_bh(&ar->data_lock);
4077 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4078 spin_unlock_bh(&ar->data_lock);
4081 spin_unlock_bh(&ar->data_lock);
4086 /**********************/
4087 /* mac80211 callbacks */
4088 /**********************/
4090 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4091 struct ieee80211_tx_control *control,
4092 struct sk_buff *skb)
4094 struct ath10k *ar = hw->priv;
4095 struct ath10k_htt *htt = &ar->htt;
4096 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4097 struct ieee80211_vif *vif = info->control.vif;
4098 struct ieee80211_sta *sta = control->sta;
4099 struct ieee80211_txq *txq = NULL;
4100 struct ieee80211_hdr *hdr = (void *)skb->data;
4101 enum ath10k_hw_txrx_mode txmode;
4102 enum ath10k_mac_tx_path txpath;
4108 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4110 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4111 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4112 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4113 txpath == ATH10K_MAC_TX_HTT_MGMT);
4114 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4117 spin_lock_bh(&ar->htt.tx_lock);
4118 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4120 ret = ath10k_htt_tx_inc_pending(htt);
4122 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4124 spin_unlock_bh(&ar->htt.tx_lock);
4125 ieee80211_free_txskb(ar->hw, skb);
4129 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4131 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4133 ath10k_htt_tx_dec_pending(htt);
4134 spin_unlock_bh(&ar->htt.tx_lock);
4135 ieee80211_free_txskb(ar->hw, skb);
4138 spin_unlock_bh(&ar->htt.tx_lock);
4141 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
4143 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4145 spin_lock_bh(&ar->htt.tx_lock);
4146 ath10k_htt_tx_dec_pending(htt);
4148 ath10k_htt_tx_mgmt_dec_pending(htt);
4149 spin_unlock_bh(&ar->htt.tx_lock);
4155 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4156 struct ieee80211_txq *txq)
4158 struct ath10k *ar = hw->priv;
4159 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4160 struct ieee80211_txq *f_txq;
4161 struct ath10k_txq *f_artxq;
4165 spin_lock_bh(&ar->txqs_lock);
4166 if (list_empty(&artxq->list))
4167 list_add_tail(&artxq->list, &ar->txqs);
4169 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4170 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4171 list_del_init(&f_artxq->list);
4173 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4174 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4179 list_add_tail(&f_artxq->list, &ar->txqs);
4180 spin_unlock_bh(&ar->txqs_lock);
4182 ath10k_htt_tx_txq_update(hw, f_txq);
4183 ath10k_htt_tx_txq_update(hw, txq);
4186 /* Must not be called with conf_mutex held as workers can use that also. */
4187 void ath10k_drain_tx(struct ath10k *ar)
4189 /* make sure rcu-protected mac80211 tx path itself is drained */
4192 ath10k_offchan_tx_purge(ar);
4193 ath10k_mgmt_over_wmi_tx_purge(ar);
4195 cancel_work_sync(&ar->offchan_tx_work);
4196 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4199 void ath10k_halt(struct ath10k *ar)
4201 struct ath10k_vif *arvif;
4203 lockdep_assert_held(&ar->conf_mutex);
4205 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4206 ar->filter_flags = 0;
4207 ar->monitor = false;
4208 ar->monitor_arvif = NULL;
4210 if (ar->monitor_started)
4211 ath10k_monitor_stop(ar);
4213 ar->monitor_started = false;
4216 ath10k_scan_finish(ar);
4217 ath10k_peer_cleanup_all(ar);
4218 ath10k_core_stop(ar);
4219 ath10k_hif_power_down(ar);
4221 spin_lock_bh(&ar->data_lock);
4222 list_for_each_entry(arvif, &ar->arvifs, list)
4223 ath10k_mac_vif_beacon_cleanup(arvif);
4224 spin_unlock_bh(&ar->data_lock);
4227 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4229 struct ath10k *ar = hw->priv;
4231 mutex_lock(&ar->conf_mutex);
4233 *tx_ant = ar->cfg_tx_chainmask;
4234 *rx_ant = ar->cfg_rx_chainmask;
4236 mutex_unlock(&ar->conf_mutex);
4241 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4243 /* It is not clear that allowing gaps in chainmask
4244 * is helpful. Probably it will not do what user
4245 * is hoping for, so warn in that case.
4247 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4250 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4254 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4256 int nsts = ar->vht_cap_info;
4258 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4259 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4261 /* If firmware does not deliver to host number of space-time
4262 * streams supported, assume it support up to 4 BF STS and return
4263 * the value for VHT CAP: nsts-1)
4271 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4273 int sound_dim = ar->vht_cap_info;
4275 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4276 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4278 /* If the sounding dimension is not advertised by the firmware,
4279 * let's use a default value of 1
4287 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4289 struct ieee80211_sta_vht_cap vht_cap = {0};
4294 vht_cap.vht_supported = 1;
4295 vht_cap.cap = ar->vht_cap_info;
4297 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4298 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4299 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4300 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4301 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4306 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4307 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4308 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4309 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4310 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4316 for (i = 0; i < 8; i++) {
4317 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4318 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4320 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4323 if (ar->cfg_tx_chainmask <= 1)
4324 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4326 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4327 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4332 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4335 struct ieee80211_sta_ht_cap ht_cap = {0};
4337 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4340 ht_cap.ht_supported = 1;
4341 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4342 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4343 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4344 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4346 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4348 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4349 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4351 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4352 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4354 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4357 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4358 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4363 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4364 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4366 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4369 stbc = ar->ht_cap_info;
4370 stbc &= WMI_HT_CAP_RX_STBC;
4371 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4372 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4373 stbc &= IEEE80211_HT_CAP_RX_STBC;
4378 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4379 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4381 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4382 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4384 /* max AMSDU is implicitly taken from vht_cap_info */
4385 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4386 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4388 for (i = 0; i < ar->num_rf_chains; i++) {
4389 if (ar->cfg_rx_chainmask & BIT(i))
4390 ht_cap.mcs.rx_mask[i] = 0xFF;
4393 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4398 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4400 struct ieee80211_supported_band *band;
4401 struct ieee80211_sta_vht_cap vht_cap;
4402 struct ieee80211_sta_ht_cap ht_cap;
4404 ht_cap = ath10k_get_ht_cap(ar);
4405 vht_cap = ath10k_create_vht_cap(ar);
4407 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4408 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4409 band->ht_cap = ht_cap;
4411 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4412 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4413 band->ht_cap = ht_cap;
4414 band->vht_cap = vht_cap;
4418 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4422 lockdep_assert_held(&ar->conf_mutex);
4424 ath10k_check_chain_mask(ar, tx_ant, "tx");
4425 ath10k_check_chain_mask(ar, rx_ant, "rx");
4427 ar->cfg_tx_chainmask = tx_ant;
4428 ar->cfg_rx_chainmask = rx_ant;
4430 if ((ar->state != ATH10K_STATE_ON) &&
4431 (ar->state != ATH10K_STATE_RESTARTED))
4434 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4437 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4442 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4445 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4450 /* Reload HT/VHT capability */
4451 ath10k_mac_setup_ht_vht_cap(ar);
4456 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4458 struct ath10k *ar = hw->priv;
4461 mutex_lock(&ar->conf_mutex);
4462 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4463 mutex_unlock(&ar->conf_mutex);
4467 static int ath10k_start(struct ieee80211_hw *hw)
4469 struct ath10k *ar = hw->priv;
4474 * This makes sense only when restarting hw. It is harmless to call
4475 * unconditionally. This is necessary to make sure no HTT/WMI tx
4476 * commands will be submitted while restarting.
4478 ath10k_drain_tx(ar);
4480 mutex_lock(&ar->conf_mutex);
4482 switch (ar->state) {
4483 case ATH10K_STATE_OFF:
4484 ar->state = ATH10K_STATE_ON;
4486 case ATH10K_STATE_RESTARTING:
4487 ar->state = ATH10K_STATE_RESTARTED;
4489 case ATH10K_STATE_ON:
4490 case ATH10K_STATE_RESTARTED:
4491 case ATH10K_STATE_WEDGED:
4495 case ATH10K_STATE_UTF:
4500 ret = ath10k_hif_power_up(ar);
4502 ath10k_err(ar, "Could not init hif: %d\n", ret);
4506 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4507 &ar->normal_mode_fw);
4509 ath10k_err(ar, "Could not init core: %d\n", ret);
4510 goto err_power_down;
4513 param = ar->wmi.pdev_param->pmf_qos;
4514 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4516 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4520 param = ar->wmi.pdev_param->dynamic_bw;
4521 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4523 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4527 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4528 ret = ath10k_wmi_adaptive_qcs(ar, true);
4530 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4536 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4537 param = ar->wmi.pdev_param->burst_enable;
4538 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4540 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4545 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4548 * By default FW set ARP frames ac to voice (6). In that case ARP
4549 * exchange is not working properly for UAPSD enabled AP. ARP requests
4550 * which arrives with access category 0 are processed by network stack
4551 * and send back with access category 0, but FW changes access category
4552 * to 6. Set ARP frames access category to best effort (0) solves
4556 param = ar->wmi.pdev_param->arp_ac_override;
4557 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4559 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4564 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4565 ar->running_fw->fw_file.fw_features)) {
4566 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4567 WMI_CCA_DETECT_LEVEL_AUTO,
4568 WMI_CCA_DETECT_MARGIN_AUTO);
4570 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4576 param = ar->wmi.pdev_param->ani_enable;
4577 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4579 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4584 ar->ani_enabled = true;
4586 if (ath10k_peer_stats_enabled(ar)) {
4587 param = ar->wmi.pdev_param->peer_stats_update_period;
4588 ret = ath10k_wmi_pdev_set_param(ar, param,
4589 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4592 "failed to set peer stats period : %d\n",
4598 param = ar->wmi.pdev_param->enable_btcoex;
4599 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4600 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4601 ar->running_fw->fw_file.fw_features)) {
4602 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4605 "failed to set btcoex param: %d\n", ret);
4608 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4611 ar->num_started_vdevs = 0;
4612 ath10k_regd_update(ar);
4614 ath10k_spectral_start(ar);
4615 ath10k_thermal_set_throttling(ar);
4617 mutex_unlock(&ar->conf_mutex);
4621 ath10k_core_stop(ar);
4624 ath10k_hif_power_down(ar);
4627 ar->state = ATH10K_STATE_OFF;
4630 mutex_unlock(&ar->conf_mutex);
4634 static void ath10k_stop(struct ieee80211_hw *hw)
4636 struct ath10k *ar = hw->priv;
4638 ath10k_drain_tx(ar);
4640 mutex_lock(&ar->conf_mutex);
4641 if (ar->state != ATH10K_STATE_OFF) {
4643 ar->state = ATH10K_STATE_OFF;
4645 mutex_unlock(&ar->conf_mutex);
4647 cancel_delayed_work_sync(&ar->scan.timeout);
4648 cancel_work_sync(&ar->restart_work);
4651 static int ath10k_config_ps(struct ath10k *ar)
4653 struct ath10k_vif *arvif;
4656 lockdep_assert_held(&ar->conf_mutex);
4658 list_for_each_entry(arvif, &ar->arvifs, list) {
4659 ret = ath10k_mac_vif_setup_ps(arvif);
4661 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4669 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4674 lockdep_assert_held(&ar->conf_mutex);
4676 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4678 param = ar->wmi.pdev_param->txpower_limit2g;
4679 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4681 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4686 param = ar->wmi.pdev_param->txpower_limit5g;
4687 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4689 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4697 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4699 struct ath10k_vif *arvif;
4700 int ret, txpower = -1;
4702 lockdep_assert_held(&ar->conf_mutex);
4704 list_for_each_entry(arvif, &ar->arvifs, list) {
4705 if (arvif->txpower <= 0)
4709 txpower = arvif->txpower;
4711 txpower = min(txpower, arvif->txpower);
4717 ret = ath10k_mac_txpower_setup(ar, txpower);
4719 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4727 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4729 struct ath10k *ar = hw->priv;
4730 struct ieee80211_conf *conf = &hw->conf;
4733 mutex_lock(&ar->conf_mutex);
4735 if (changed & IEEE80211_CONF_CHANGE_PS)
4736 ath10k_config_ps(ar);
4738 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4739 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4740 ret = ath10k_monitor_recalc(ar);
4742 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4745 mutex_unlock(&ar->conf_mutex);
4749 static u32 get_nss_from_chainmask(u16 chain_mask)
4751 if ((chain_mask & 0xf) == 0xf)
4753 else if ((chain_mask & 0x7) == 0x7)
4755 else if ((chain_mask & 0x3) == 0x3)
4760 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4763 struct ath10k *ar = arvif->ar;
4767 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4770 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4771 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4772 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4773 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4775 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4776 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4777 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4778 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4783 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4784 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4786 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4787 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4788 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4790 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4791 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4793 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4794 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4795 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4797 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4798 ar->wmi.vdev_param->txbf, value);
4803 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4804 * because we will send mgmt frames without CCK. This requirement
4805 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4808 static int ath10k_add_interface(struct ieee80211_hw *hw,
4809 struct ieee80211_vif *vif)
4811 struct ath10k *ar = hw->priv;
4812 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4813 struct ath10k_peer *peer;
4814 enum wmi_sta_powersave_param param;
4821 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4823 mutex_lock(&ar->conf_mutex);
4825 memset(arvif, 0, sizeof(*arvif));
4826 ath10k_mac_txq_init(vif->txq);
4831 INIT_LIST_HEAD(&arvif->list);
4832 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4833 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4834 ath10k_mac_vif_sta_connection_loss_work);
4836 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4837 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4838 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4839 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4840 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4841 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4844 if (ar->num_peers >= ar->max_num_peers) {
4845 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4850 if (ar->free_vdev_map == 0) {
4851 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4855 bit = __ffs64(ar->free_vdev_map);
4857 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4858 bit, ar->free_vdev_map);
4860 arvif->vdev_id = bit;
4861 arvif->vdev_subtype =
4862 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4864 switch (vif->type) {
4865 case NL80211_IFTYPE_P2P_DEVICE:
4866 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4867 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4868 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4870 case NL80211_IFTYPE_UNSPECIFIED:
4871 case NL80211_IFTYPE_STATION:
4872 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4874 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4875 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4877 case NL80211_IFTYPE_ADHOC:
4878 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4880 case NL80211_IFTYPE_MESH_POINT:
4881 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4882 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4883 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4884 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4886 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4889 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4891 case NL80211_IFTYPE_AP:
4892 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4895 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4896 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4898 case NL80211_IFTYPE_MONITOR:
4899 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4906 /* Using vdev_id as queue number will make it very easy to do per-vif
4907 * tx queue locking. This shouldn't wrap due to interface combinations
4908 * but do a modulo for correctness sake and prevent using offchannel tx
4909 * queues for regular vif tx.
4911 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4912 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4913 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4915 /* Some firmware revisions don't wait for beacon tx completion before
4916 * sending another SWBA event. This could lead to hardware using old
4917 * (freed) beacon data in some cases, e.g. tx credit starvation
4918 * combined with missed TBTT. This is very very rare.
4920 * On non-IOMMU-enabled hosts this could be a possible security issue
4921 * because hw could beacon some random data on the air. On
4922 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4923 * device would crash.
4925 * Since there are no beacon tx completions (implicit nor explicit)
4926 * propagated to host the only workaround for this is to allocate a
4927 * DMA-coherent buffer for a lifetime of a vif and use it for all
4928 * beacon tx commands. Worst case for this approach is some beacons may
4929 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4931 if (vif->type == NL80211_IFTYPE_ADHOC ||
4932 vif->type == NL80211_IFTYPE_MESH_POINT ||
4933 vif->type == NL80211_IFTYPE_AP) {
4934 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4935 IEEE80211_MAX_FRAME_LEN,
4936 &arvif->beacon_paddr,
4938 if (!arvif->beacon_buf) {
4940 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4945 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4946 arvif->nohwcrypt = true;
4948 if (arvif->nohwcrypt &&
4949 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4951 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4955 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4956 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4957 arvif->beacon_buf ? "single-buf" : "per-skb");
4959 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4960 arvif->vdev_subtype, vif->addr);
4962 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4963 arvif->vdev_id, ret);
4967 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4968 spin_lock_bh(&ar->data_lock);
4969 list_add(&arvif->list, &ar->arvifs);
4970 spin_unlock_bh(&ar->data_lock);
4972 /* It makes no sense to have firmware do keepalives. mac80211 already
4973 * takes care of this with idle connection polling.
4975 ret = ath10k_mac_vif_disable_keepalive(arvif);
4977 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4978 arvif->vdev_id, ret);
4979 goto err_vdev_delete;
4982 arvif->def_wep_key_idx = -1;
4984 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4985 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4986 ATH10K_HW_TXRX_NATIVE_WIFI);
4987 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4988 if (ret && ret != -EOPNOTSUPP) {
4989 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4990 arvif->vdev_id, ret);
4991 goto err_vdev_delete;
4994 /* Configuring number of spatial stream for monitor interface is causing
4995 * target assert in qca9888 and qca6174.
4997 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
4998 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
5000 vdev_param = ar->wmi.vdev_param->nss;
5001 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5004 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
5005 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
5007 goto err_vdev_delete;
5011 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5012 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5013 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
5014 vif->addr, WMI_PEER_TYPE_DEFAULT);
5016 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
5017 arvif->vdev_id, ret);
5018 goto err_vdev_delete;
5021 spin_lock_bh(&ar->data_lock);
5023 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
5025 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5026 vif->addr, arvif->vdev_id);
5027 spin_unlock_bh(&ar->data_lock);
5029 goto err_peer_delete;
5032 arvif->peer_id = find_first_bit(peer->peer_ids,
5033 ATH10K_MAX_NUM_PEER_IDS);
5035 spin_unlock_bh(&ar->data_lock);
5037 arvif->peer_id = HTT_INVALID_PEERID;
5040 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5041 ret = ath10k_mac_set_kickout(arvif);
5043 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5044 arvif->vdev_id, ret);
5045 goto err_peer_delete;
5049 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5050 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5051 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5052 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5055 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5056 arvif->vdev_id, ret);
5057 goto err_peer_delete;
5060 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5062 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5063 arvif->vdev_id, ret);
5064 goto err_peer_delete;
5067 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5069 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5070 arvif->vdev_id, ret);
5071 goto err_peer_delete;
5075 ret = ath10k_mac_set_txbf_conf(arvif);
5077 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5078 arvif->vdev_id, ret);
5079 goto err_peer_delete;
5082 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5084 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5085 arvif->vdev_id, ret);
5086 goto err_peer_delete;
5089 arvif->txpower = vif->bss_conf.txpower;
5090 ret = ath10k_mac_txpower_recalc(ar);
5092 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5093 goto err_peer_delete;
5096 if (vif->type == NL80211_IFTYPE_MONITOR) {
5097 ar->monitor_arvif = arvif;
5098 ret = ath10k_monitor_recalc(ar);
5100 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5101 goto err_peer_delete;
5105 spin_lock_bh(&ar->htt.tx_lock);
5107 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5108 spin_unlock_bh(&ar->htt.tx_lock);
5110 mutex_unlock(&ar->conf_mutex);
5114 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5115 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5116 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5119 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5120 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5121 spin_lock_bh(&ar->data_lock);
5122 list_del(&arvif->list);
5123 spin_unlock_bh(&ar->data_lock);
5126 if (arvif->beacon_buf) {
5127 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5128 arvif->beacon_buf, arvif->beacon_paddr);
5129 arvif->beacon_buf = NULL;
5132 mutex_unlock(&ar->conf_mutex);
5137 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5141 for (i = 0; i < BITS_PER_LONG; i++)
5142 ath10k_mac_vif_tx_unlock(arvif, i);
5145 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5146 struct ieee80211_vif *vif)
5148 struct ath10k *ar = hw->priv;
5149 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5150 struct ath10k_peer *peer;
5154 cancel_work_sync(&arvif->ap_csa_work);
5155 cancel_delayed_work_sync(&arvif->connection_loss_work);
5157 mutex_lock(&ar->conf_mutex);
5159 spin_lock_bh(&ar->data_lock);
5160 ath10k_mac_vif_beacon_cleanup(arvif);
5161 spin_unlock_bh(&ar->data_lock);
5163 ret = ath10k_spectral_vif_stop(arvif);
5165 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5166 arvif->vdev_id, ret);
5168 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5169 spin_lock_bh(&ar->data_lock);
5170 list_del(&arvif->list);
5171 spin_unlock_bh(&ar->data_lock);
5173 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5174 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5175 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5178 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5179 arvif->vdev_id, ret);
5181 kfree(arvif->u.ap.noa_data);
5184 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5187 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5189 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5190 arvif->vdev_id, ret);
5192 /* Some firmware revisions don't notify host about self-peer removal
5193 * until after associated vdev is deleted.
5195 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5196 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5197 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5200 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5201 arvif->vdev_id, ret);
5203 spin_lock_bh(&ar->data_lock);
5205 spin_unlock_bh(&ar->data_lock);
5208 spin_lock_bh(&ar->data_lock);
5209 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5210 peer = ar->peer_map[i];
5214 if (peer->vif == vif) {
5215 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5216 vif->addr, arvif->vdev_id);
5220 spin_unlock_bh(&ar->data_lock);
5222 ath10k_peer_cleanup(ar, arvif->vdev_id);
5223 ath10k_mac_txq_unref(ar, vif->txq);
5225 if (vif->type == NL80211_IFTYPE_MONITOR) {
5226 ar->monitor_arvif = NULL;
5227 ret = ath10k_monitor_recalc(ar);
5229 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5232 spin_lock_bh(&ar->htt.tx_lock);
5233 ath10k_mac_vif_tx_unlock_all(arvif);
5234 spin_unlock_bh(&ar->htt.tx_lock);
5236 ath10k_mac_txq_unref(ar, vif->txq);
5238 mutex_unlock(&ar->conf_mutex);
5242 * FIXME: Has to be verified.
5244 #define SUPPORTED_FILTERS \
5249 FIF_BCN_PRBRESP_PROMISC | \
5253 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5254 unsigned int changed_flags,
5255 unsigned int *total_flags,
5258 struct ath10k *ar = hw->priv;
5261 mutex_lock(&ar->conf_mutex);
5263 changed_flags &= SUPPORTED_FILTERS;
5264 *total_flags &= SUPPORTED_FILTERS;
5265 ar->filter_flags = *total_flags;
5267 ret = ath10k_monitor_recalc(ar);
5269 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5271 mutex_unlock(&ar->conf_mutex);
5274 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5275 struct ieee80211_vif *vif,
5276 struct ieee80211_bss_conf *info,
5279 struct ath10k *ar = hw->priv;
5280 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5282 u32 vdev_param, pdev_param, slottime, preamble;
5284 mutex_lock(&ar->conf_mutex);
5286 if (changed & BSS_CHANGED_IBSS)
5287 ath10k_control_ibss(arvif, info, vif->addr);
5289 if (changed & BSS_CHANGED_BEACON_INT) {
5290 arvif->beacon_interval = info->beacon_int;
5291 vdev_param = ar->wmi.vdev_param->beacon_interval;
5292 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5293 arvif->beacon_interval);
5294 ath10k_dbg(ar, ATH10K_DBG_MAC,
5295 "mac vdev %d beacon_interval %d\n",
5296 arvif->vdev_id, arvif->beacon_interval);
5299 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5300 arvif->vdev_id, ret);
5303 if (changed & BSS_CHANGED_BEACON) {
5304 ath10k_dbg(ar, ATH10K_DBG_MAC,
5305 "vdev %d set beacon tx mode to staggered\n",
5308 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5309 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5310 WMI_BEACON_STAGGERED_MODE);
5312 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5313 arvif->vdev_id, ret);
5315 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5317 ath10k_warn(ar, "failed to update beacon template: %d\n",
5320 if (ieee80211_vif_is_mesh(vif)) {
5321 /* mesh doesn't use SSID but firmware needs it */
5322 strncpy(arvif->u.ap.ssid, "mesh",
5323 sizeof(arvif->u.ap.ssid));
5324 arvif->u.ap.ssid_len = 4;
5328 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5329 ret = ath10k_mac_setup_prb_tmpl(arvif);
5331 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5332 arvif->vdev_id, ret);
5335 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5336 arvif->dtim_period = info->dtim_period;
5338 ath10k_dbg(ar, ATH10K_DBG_MAC,
5339 "mac vdev %d dtim_period %d\n",
5340 arvif->vdev_id, arvif->dtim_period);
5342 vdev_param = ar->wmi.vdev_param->dtim_period;
5343 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5344 arvif->dtim_period);
5346 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5347 arvif->vdev_id, ret);
5350 if (changed & BSS_CHANGED_SSID &&
5351 vif->type == NL80211_IFTYPE_AP) {
5352 arvif->u.ap.ssid_len = info->ssid_len;
5354 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5355 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5358 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5359 ether_addr_copy(arvif->bssid, info->bssid);
5361 if (changed & BSS_CHANGED_BEACON_ENABLED)
5362 ath10k_control_beaconing(arvif, info);
5364 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5365 arvif->use_cts_prot = info->use_cts_prot;
5367 ret = ath10k_recalc_rtscts_prot(arvif);
5369 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5370 arvif->vdev_id, ret);
5372 if (ath10k_mac_can_set_cts_prot(arvif)) {
5373 ret = ath10k_mac_set_cts_prot(arvif);
5375 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
5376 arvif->vdev_id, ret);
5380 if (changed & BSS_CHANGED_ERP_SLOT) {
5381 if (info->use_short_slot)
5382 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5385 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5387 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5388 arvif->vdev_id, slottime);
5390 vdev_param = ar->wmi.vdev_param->slot_time;
5391 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5394 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5395 arvif->vdev_id, ret);
5398 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5399 if (info->use_short_preamble)
5400 preamble = WMI_VDEV_PREAMBLE_SHORT;
5402 preamble = WMI_VDEV_PREAMBLE_LONG;
5404 ath10k_dbg(ar, ATH10K_DBG_MAC,
5405 "mac vdev %d preamble %dn",
5406 arvif->vdev_id, preamble);
5408 vdev_param = ar->wmi.vdev_param->preamble;
5409 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5412 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5413 arvif->vdev_id, ret);
5416 if (changed & BSS_CHANGED_ASSOC) {
5418 /* Workaround: Make sure monitor vdev is not running
5419 * when associating to prevent some firmware revisions
5420 * (e.g. 10.1 and 10.2) from crashing.
5422 if (ar->monitor_started)
5423 ath10k_monitor_stop(ar);
5424 ath10k_bss_assoc(hw, vif, info);
5425 ath10k_monitor_recalc(ar);
5427 ath10k_bss_disassoc(hw, vif);
5431 if (changed & BSS_CHANGED_TXPOWER) {
5432 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5433 arvif->vdev_id, info->txpower);
5435 arvif->txpower = info->txpower;
5436 ret = ath10k_mac_txpower_recalc(ar);
5438 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5441 if (changed & BSS_CHANGED_PS) {
5442 arvif->ps = vif->bss_conf.ps;
5444 ret = ath10k_config_ps(ar);
5446 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5447 arvif->vdev_id, ret);
5450 mutex_unlock(&ar->conf_mutex);
5453 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5454 struct ieee80211_vif *vif,
5455 struct ieee80211_scan_request *hw_req)
5457 struct ath10k *ar = hw->priv;
5458 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5459 struct cfg80211_scan_request *req = &hw_req->req;
5460 struct wmi_start_scan_arg arg;
5464 mutex_lock(&ar->conf_mutex);
5466 spin_lock_bh(&ar->data_lock);
5467 switch (ar->scan.state) {
5468 case ATH10K_SCAN_IDLE:
5469 reinit_completion(&ar->scan.started);
5470 reinit_completion(&ar->scan.completed);
5471 ar->scan.state = ATH10K_SCAN_STARTING;
5472 ar->scan.is_roc = false;
5473 ar->scan.vdev_id = arvif->vdev_id;
5476 case ATH10K_SCAN_STARTING:
5477 case ATH10K_SCAN_RUNNING:
5478 case ATH10K_SCAN_ABORTING:
5482 spin_unlock_bh(&ar->data_lock);
5487 memset(&arg, 0, sizeof(arg));
5488 ath10k_wmi_start_scan_init(ar, &arg);
5489 arg.vdev_id = arvif->vdev_id;
5490 arg.scan_id = ATH10K_SCAN_ID;
5493 arg.ie_len = req->ie_len;
5494 memcpy(arg.ie, req->ie, arg.ie_len);
5498 arg.n_ssids = req->n_ssids;
5499 for (i = 0; i < arg.n_ssids; i++) {
5500 arg.ssids[i].len = req->ssids[i].ssid_len;
5501 arg.ssids[i].ssid = req->ssids[i].ssid;
5504 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5507 if (req->n_channels) {
5508 arg.n_channels = req->n_channels;
5509 for (i = 0; i < arg.n_channels; i++)
5510 arg.channels[i] = req->channels[i]->center_freq;
5513 ret = ath10k_start_scan(ar, &arg);
5515 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5516 spin_lock_bh(&ar->data_lock);
5517 ar->scan.state = ATH10K_SCAN_IDLE;
5518 spin_unlock_bh(&ar->data_lock);
5521 /* Add a 200ms margin to account for event/command processing */
5522 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5523 msecs_to_jiffies(arg.max_scan_time +
5527 mutex_unlock(&ar->conf_mutex);
5531 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5532 struct ieee80211_vif *vif)
5534 struct ath10k *ar = hw->priv;
5536 mutex_lock(&ar->conf_mutex);
5537 ath10k_scan_abort(ar);
5538 mutex_unlock(&ar->conf_mutex);
5540 cancel_delayed_work_sync(&ar->scan.timeout);
5543 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5544 struct ath10k_vif *arvif,
5545 enum set_key_cmd cmd,
5546 struct ieee80211_key_conf *key)
5548 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5551 /* 10.1 firmware branch requires default key index to be set to group
5552 * key index after installing it. Otherwise FW/HW Txes corrupted
5553 * frames with multi-vif APs. This is not required for main firmware
5554 * branch (e.g. 636).
5556 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5558 * FIXME: It remains unknown if this is required for multi-vif STA
5559 * interfaces on 10.1.
5562 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5563 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5566 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5569 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5572 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5578 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5581 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5582 arvif->vdev_id, ret);
5585 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5586 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5587 struct ieee80211_key_conf *key)
5589 struct ath10k *ar = hw->priv;
5590 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5591 struct ath10k_peer *peer;
5592 const u8 *peer_addr;
5593 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5594 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5600 /* this one needs to be done in software */
5601 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5604 if (arvif->nohwcrypt)
5607 if (key->keyidx > WMI_MAX_KEY_INDEX)
5610 mutex_lock(&ar->conf_mutex);
5613 peer_addr = sta->addr;
5614 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5615 peer_addr = vif->bss_conf.bssid;
5617 peer_addr = vif->addr;
5619 key->hw_key_idx = key->keyidx;
5623 arvif->wep_keys[key->keyidx] = key;
5625 arvif->wep_keys[key->keyidx] = NULL;
5628 /* the peer should not disappear in mid-way (unless FW goes awry) since
5629 * we already hold conf_mutex. we just make sure its there now. */
5630 spin_lock_bh(&ar->data_lock);
5631 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5632 spin_unlock_bh(&ar->data_lock);
5635 if (cmd == SET_KEY) {
5636 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5641 /* if the peer doesn't exist there is no key to disable
5647 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5648 flags |= WMI_KEY_PAIRWISE;
5650 flags |= WMI_KEY_GROUP;
5653 if (cmd == DISABLE_KEY)
5654 ath10k_clear_vdev_key(arvif, key);
5656 /* When WEP keys are uploaded it's possible that there are
5657 * stations associated already (e.g. when merging) without any
5658 * keys. Static WEP needs an explicit per-peer key upload.
5660 if (vif->type == NL80211_IFTYPE_ADHOC &&
5662 ath10k_mac_vif_update_wep_key(arvif, key);
5664 /* 802.1x never sets the def_wep_key_idx so each set_key()
5665 * call changes default tx key.
5667 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5668 * after first set_key().
5670 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5671 flags |= WMI_KEY_TX_USAGE;
5674 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5677 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5678 arvif->vdev_id, peer_addr, ret);
5682 /* mac80211 sets static WEP keys as groupwise while firmware requires
5683 * them to be installed twice as both pairwise and groupwise.
5685 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5687 flags2 &= ~WMI_KEY_GROUP;
5688 flags2 |= WMI_KEY_PAIRWISE;
5690 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5693 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5694 arvif->vdev_id, peer_addr, ret);
5695 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5699 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5700 arvif->vdev_id, peer_addr, ret2);
5706 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5708 spin_lock_bh(&ar->data_lock);
5709 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5710 if (peer && cmd == SET_KEY)
5711 peer->keys[key->keyidx] = key;
5712 else if (peer && cmd == DISABLE_KEY)
5713 peer->keys[key->keyidx] = NULL;
5714 else if (peer == NULL)
5715 /* impossible unless FW goes crazy */
5716 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5717 spin_unlock_bh(&ar->data_lock);
5720 mutex_unlock(&ar->conf_mutex);
5724 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5725 struct ieee80211_vif *vif,
5728 struct ath10k *ar = hw->priv;
5729 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5732 mutex_lock(&arvif->ar->conf_mutex);
5734 if (arvif->ar->state != ATH10K_STATE_ON)
5737 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5738 arvif->vdev_id, keyidx);
5740 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5742 arvif->ar->wmi.vdev_param->def_keyid,
5746 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5752 arvif->def_wep_key_idx = keyidx;
5755 mutex_unlock(&arvif->ar->conf_mutex);
5758 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5761 struct ath10k_vif *arvif;
5762 struct ath10k_sta *arsta;
5763 struct ieee80211_sta *sta;
5764 struct cfg80211_chan_def def;
5765 enum nl80211_band band;
5766 const u8 *ht_mcs_mask;
5767 const u16 *vht_mcs_mask;
5768 u32 changed, bw, nss, smps;
5771 arsta = container_of(wk, struct ath10k_sta, update_wk);
5772 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5773 arvif = arsta->arvif;
5776 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5779 band = def.chan->band;
5780 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5781 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5783 spin_lock_bh(&ar->data_lock);
5785 changed = arsta->changed;
5792 spin_unlock_bh(&ar->data_lock);
5794 mutex_lock(&ar->conf_mutex);
5796 nss = max_t(u32, 1, nss);
5797 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5798 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5800 if (changed & IEEE80211_RC_BW_CHANGED) {
5801 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5804 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5805 WMI_PEER_CHAN_WIDTH, bw);
5807 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5808 sta->addr, bw, err);
5811 if (changed & IEEE80211_RC_NSS_CHANGED) {
5812 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5815 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5818 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5819 sta->addr, nss, err);
5822 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5826 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5827 WMI_PEER_SMPS_STATE, smps);
5829 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5830 sta->addr, smps, err);
5833 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5834 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5837 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5839 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5843 mutex_unlock(&ar->conf_mutex);
5846 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5847 struct ieee80211_sta *sta)
5849 struct ath10k *ar = arvif->ar;
5851 lockdep_assert_held(&ar->conf_mutex);
5853 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5856 if (ar->num_stations >= ar->max_num_stations)
5864 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5865 struct ieee80211_sta *sta)
5867 struct ath10k *ar = arvif->ar;
5869 lockdep_assert_held(&ar->conf_mutex);
5871 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5877 struct ath10k_mac_tdls_iter_data {
5878 u32 num_tdls_stations;
5879 struct ieee80211_vif *curr_vif;
5882 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5883 struct ieee80211_sta *sta)
5885 struct ath10k_mac_tdls_iter_data *iter_data = data;
5886 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5887 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5889 if (sta->tdls && sta_vif == iter_data->curr_vif)
5890 iter_data->num_tdls_stations++;
5893 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5894 struct ieee80211_vif *vif)
5896 struct ath10k_mac_tdls_iter_data data = {};
5898 data.curr_vif = vif;
5900 ieee80211_iterate_stations_atomic(hw,
5901 ath10k_mac_tdls_vif_stations_count_iter,
5903 return data.num_tdls_stations;
5906 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5907 struct ieee80211_vif *vif)
5909 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5910 int *num_tdls_vifs = data;
5912 if (vif->type != NL80211_IFTYPE_STATION)
5915 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5919 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5921 int num_tdls_vifs = 0;
5923 ieee80211_iterate_active_interfaces_atomic(hw,
5924 IEEE80211_IFACE_ITER_NORMAL,
5925 ath10k_mac_tdls_vifs_count_iter,
5927 return num_tdls_vifs;
5930 static int ath10k_sta_state(struct ieee80211_hw *hw,
5931 struct ieee80211_vif *vif,
5932 struct ieee80211_sta *sta,
5933 enum ieee80211_sta_state old_state,
5934 enum ieee80211_sta_state new_state)
5936 struct ath10k *ar = hw->priv;
5937 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5938 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5939 struct ath10k_peer *peer;
5943 if (old_state == IEEE80211_STA_NOTEXIST &&
5944 new_state == IEEE80211_STA_NONE) {
5945 memset(arsta, 0, sizeof(*arsta));
5946 arsta->arvif = arvif;
5947 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5949 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5950 ath10k_mac_txq_init(sta->txq[i]);
5953 /* cancel must be done outside the mutex to avoid deadlock */
5954 if ((old_state == IEEE80211_STA_NONE &&
5955 new_state == IEEE80211_STA_NOTEXIST))
5956 cancel_work_sync(&arsta->update_wk);
5958 mutex_lock(&ar->conf_mutex);
5960 if (old_state == IEEE80211_STA_NOTEXIST &&
5961 new_state == IEEE80211_STA_NONE) {
5963 * New station addition.
5965 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5966 u32 num_tdls_stations;
5969 ath10k_dbg(ar, ATH10K_DBG_MAC,
5970 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5971 arvif->vdev_id, sta->addr,
5972 ar->num_stations + 1, ar->max_num_stations,
5973 ar->num_peers + 1, ar->max_num_peers);
5975 ret = ath10k_mac_inc_num_stations(arvif, sta);
5977 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5978 ar->max_num_stations);
5983 peer_type = WMI_PEER_TYPE_TDLS;
5985 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
5986 sta->addr, peer_type);
5988 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5989 sta->addr, arvif->vdev_id, ret);
5990 ath10k_mac_dec_num_stations(arvif, sta);
5994 spin_lock_bh(&ar->data_lock);
5996 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
5998 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5999 vif->addr, arvif->vdev_id);
6000 spin_unlock_bh(&ar->data_lock);
6001 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6002 ath10k_mac_dec_num_stations(arvif, sta);
6007 arsta->peer_id = find_first_bit(peer->peer_ids,
6008 ATH10K_MAX_NUM_PEER_IDS);
6010 spin_unlock_bh(&ar->data_lock);
6015 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
6016 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
6018 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
6019 num_tdls_stations == 0) {
6020 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
6021 arvif->vdev_id, ar->max_num_tdls_vdevs);
6022 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6023 ath10k_mac_dec_num_stations(arvif, sta);
6028 if (num_tdls_stations == 0) {
6029 /* This is the first tdls peer in current vif */
6030 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
6032 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6035 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6036 arvif->vdev_id, ret);
6037 ath10k_peer_delete(ar, arvif->vdev_id,
6039 ath10k_mac_dec_num_stations(arvif, sta);
6044 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6045 WMI_TDLS_PEER_STATE_PEERING);
6048 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6049 sta->addr, arvif->vdev_id, ret);
6050 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6051 ath10k_mac_dec_num_stations(arvif, sta);
6053 if (num_tdls_stations != 0)
6055 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6058 } else if ((old_state == IEEE80211_STA_NONE &&
6059 new_state == IEEE80211_STA_NOTEXIST)) {
6061 * Existing station deletion.
6063 ath10k_dbg(ar, ATH10K_DBG_MAC,
6064 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6065 arvif->vdev_id, sta->addr, sta);
6068 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
6070 WMI_TDLS_PEER_STATE_TEARDOWN);
6072 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
6074 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
6077 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6079 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6080 sta->addr, arvif->vdev_id, ret);
6082 ath10k_mac_dec_num_stations(arvif, sta);
6084 spin_lock_bh(&ar->data_lock);
6085 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6086 peer = ar->peer_map[i];
6090 if (peer->sta == sta) {
6091 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6092 sta->addr, peer, i, arvif->vdev_id);
6095 /* Clean up the peer object as well since we
6096 * must have failed to do this above.
6098 list_del(&peer->list);
6099 ar->peer_map[i] = NULL;
6104 spin_unlock_bh(&ar->data_lock);
6106 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6107 ath10k_mac_txq_unref(ar, sta->txq[i]);
6112 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6115 /* This was the last tdls peer in current vif */
6116 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6119 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6120 arvif->vdev_id, ret);
6122 } else if (old_state == IEEE80211_STA_AUTH &&
6123 new_state == IEEE80211_STA_ASSOC &&
6124 (vif->type == NL80211_IFTYPE_AP ||
6125 vif->type == NL80211_IFTYPE_MESH_POINT ||
6126 vif->type == NL80211_IFTYPE_ADHOC)) {
6130 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6133 ret = ath10k_station_assoc(ar, vif, sta, false);
6135 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6136 sta->addr, arvif->vdev_id, ret);
6137 } else if (old_state == IEEE80211_STA_ASSOC &&
6138 new_state == IEEE80211_STA_AUTHORIZED &&
6141 * Tdls station authorized.
6143 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6146 ret = ath10k_station_assoc(ar, vif, sta, false);
6148 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6149 sta->addr, arvif->vdev_id, ret);
6153 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6154 WMI_TDLS_PEER_STATE_CONNECTED);
6156 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6157 sta->addr, arvif->vdev_id, ret);
6158 } else if (old_state == IEEE80211_STA_ASSOC &&
6159 new_state == IEEE80211_STA_AUTH &&
6160 (vif->type == NL80211_IFTYPE_AP ||
6161 vif->type == NL80211_IFTYPE_MESH_POINT ||
6162 vif->type == NL80211_IFTYPE_ADHOC)) {
6166 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6169 ret = ath10k_station_disassoc(ar, vif, sta);
6171 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6172 sta->addr, arvif->vdev_id, ret);
6175 mutex_unlock(&ar->conf_mutex);
6179 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6180 u16 ac, bool enable)
6182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6183 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6184 u32 prio = 0, acc = 0;
6188 lockdep_assert_held(&ar->conf_mutex);
6190 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6194 case IEEE80211_AC_VO:
6195 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6196 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6200 case IEEE80211_AC_VI:
6201 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6202 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6206 case IEEE80211_AC_BE:
6207 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6208 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6212 case IEEE80211_AC_BK:
6213 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6214 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6221 arvif->u.sta.uapsd |= value;
6223 arvif->u.sta.uapsd &= ~value;
6225 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6226 WMI_STA_PS_PARAM_UAPSD,
6227 arvif->u.sta.uapsd);
6229 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6233 if (arvif->u.sta.uapsd)
6234 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6236 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6238 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6239 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6242 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6244 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6246 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6247 arvif->vdev_id, ret);
6251 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6253 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6254 arvif->vdev_id, ret);
6258 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6259 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6260 /* Only userspace can make an educated decision when to send
6261 * trigger frame. The following effectively disables u-UAPSD
6262 * autotrigger in firmware (which is enabled by default
6263 * provided the autotrigger service is available).
6267 arg.user_priority = prio;
6268 arg.service_interval = 0;
6269 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6270 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6272 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6273 arvif->bssid, &arg, 1);
6275 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6285 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6286 struct ieee80211_vif *vif, u16 ac,
6287 const struct ieee80211_tx_queue_params *params)
6289 struct ath10k *ar = hw->priv;
6290 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6291 struct wmi_wmm_params_arg *p = NULL;
6294 mutex_lock(&ar->conf_mutex);
6297 case IEEE80211_AC_VO:
6298 p = &arvif->wmm_params.ac_vo;
6300 case IEEE80211_AC_VI:
6301 p = &arvif->wmm_params.ac_vi;
6303 case IEEE80211_AC_BE:
6304 p = &arvif->wmm_params.ac_be;
6306 case IEEE80211_AC_BK:
6307 p = &arvif->wmm_params.ac_bk;
6316 p->cwmin = params->cw_min;
6317 p->cwmax = params->cw_max;
6318 p->aifs = params->aifs;
6321 * The channel time duration programmed in the HW is in absolute
6322 * microseconds, while mac80211 gives the txop in units of
6325 p->txop = params->txop * 32;
6327 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6328 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6329 &arvif->wmm_params);
6331 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6332 arvif->vdev_id, ret);
6336 /* This won't work well with multi-interface cases but it's
6337 * better than nothing.
6339 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6341 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6346 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6348 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6351 mutex_unlock(&ar->conf_mutex);
6355 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6357 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6358 struct ieee80211_vif *vif,
6359 struct ieee80211_channel *chan,
6361 enum ieee80211_roc_type type)
6363 struct ath10k *ar = hw->priv;
6364 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6365 struct wmi_start_scan_arg arg;
6369 mutex_lock(&ar->conf_mutex);
6371 spin_lock_bh(&ar->data_lock);
6372 switch (ar->scan.state) {
6373 case ATH10K_SCAN_IDLE:
6374 reinit_completion(&ar->scan.started);
6375 reinit_completion(&ar->scan.completed);
6376 reinit_completion(&ar->scan.on_channel);
6377 ar->scan.state = ATH10K_SCAN_STARTING;
6378 ar->scan.is_roc = true;
6379 ar->scan.vdev_id = arvif->vdev_id;
6380 ar->scan.roc_freq = chan->center_freq;
6381 ar->scan.roc_notify = true;
6384 case ATH10K_SCAN_STARTING:
6385 case ATH10K_SCAN_RUNNING:
6386 case ATH10K_SCAN_ABORTING:
6390 spin_unlock_bh(&ar->data_lock);
6395 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6397 memset(&arg, 0, sizeof(arg));
6398 ath10k_wmi_start_scan_init(ar, &arg);
6399 arg.vdev_id = arvif->vdev_id;
6400 arg.scan_id = ATH10K_SCAN_ID;
6402 arg.channels[0] = chan->center_freq;
6403 arg.dwell_time_active = scan_time_msec;
6404 arg.dwell_time_passive = scan_time_msec;
6405 arg.max_scan_time = scan_time_msec;
6406 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6407 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6408 arg.burst_duration_ms = duration;
6410 ret = ath10k_start_scan(ar, &arg);
6412 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6413 spin_lock_bh(&ar->data_lock);
6414 ar->scan.state = ATH10K_SCAN_IDLE;
6415 spin_unlock_bh(&ar->data_lock);
6419 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6421 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6423 ret = ath10k_scan_stop(ar);
6425 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6431 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6432 msecs_to_jiffies(duration));
6436 mutex_unlock(&ar->conf_mutex);
6440 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6442 struct ath10k *ar = hw->priv;
6444 mutex_lock(&ar->conf_mutex);
6446 spin_lock_bh(&ar->data_lock);
6447 ar->scan.roc_notify = false;
6448 spin_unlock_bh(&ar->data_lock);
6450 ath10k_scan_abort(ar);
6452 mutex_unlock(&ar->conf_mutex);
6454 cancel_delayed_work_sync(&ar->scan.timeout);
6460 * Both RTS and Fragmentation threshold are interface-specific
6461 * in ath10k, but device-specific in mac80211.
6464 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6466 struct ath10k *ar = hw->priv;
6467 struct ath10k_vif *arvif;
6470 mutex_lock(&ar->conf_mutex);
6471 list_for_each_entry(arvif, &ar->arvifs, list) {
6472 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6473 arvif->vdev_id, value);
6475 ret = ath10k_mac_set_rts(arvif, value);
6477 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6478 arvif->vdev_id, ret);
6482 mutex_unlock(&ar->conf_mutex);
6487 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6489 /* Even though there's a WMI enum for fragmentation threshold no known
6490 * firmware actually implements it. Moreover it is not possible to rely
6491 * frame fragmentation to mac80211 because firmware clears the "more
6492 * fragments" bit in frame control making it impossible for remote
6493 * devices to reassemble frames.
6495 * Hence implement a dummy callback just to say fragmentation isn't
6496 * supported. This effectively prevents mac80211 from doing frame
6497 * fragmentation in software.
6502 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6503 u32 queues, bool drop)
6505 struct ath10k *ar = hw->priv;
6509 /* mac80211 doesn't care if we really xmit queued frames or not
6510 * we'll collect those frames either way if we stop/delete vdevs */
6514 mutex_lock(&ar->conf_mutex);
6516 if (ar->state == ATH10K_STATE_WEDGED)
6519 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6522 spin_lock_bh(&ar->htt.tx_lock);
6523 empty = (ar->htt.num_pending_tx == 0);
6524 spin_unlock_bh(&ar->htt.tx_lock);
6526 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6527 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6531 }), ATH10K_FLUSH_TIMEOUT_HZ);
6533 if (time_left == 0 || skip)
6534 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6535 skip, ar->state, time_left);
6538 mutex_unlock(&ar->conf_mutex);
6541 /* TODO: Implement this function properly
6542 * For now it is needed to reply to Probe Requests in IBSS mode.
6543 * Propably we need this information from FW.
6545 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6550 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6551 enum ieee80211_reconfig_type reconfig_type)
6553 struct ath10k *ar = hw->priv;
6555 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6558 mutex_lock(&ar->conf_mutex);
6560 /* If device failed to restart it will be in a different state, e.g.
6561 * ATH10K_STATE_WEDGED */
6562 if (ar->state == ATH10K_STATE_RESTARTED) {
6563 ath10k_info(ar, "device successfully recovered\n");
6564 ar->state = ATH10K_STATE_ON;
6565 ieee80211_wake_queues(ar->hw);
6568 mutex_unlock(&ar->conf_mutex);
6572 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6573 struct ieee80211_channel *channel)
6576 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6578 lockdep_assert_held(&ar->conf_mutex);
6580 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6581 (ar->rx_channel != channel))
6584 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6585 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6589 reinit_completion(&ar->bss_survey_done);
6591 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6593 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6597 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6599 ath10k_warn(ar, "bss channel survey timed out\n");
6604 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6605 struct survey_info *survey)
6607 struct ath10k *ar = hw->priv;
6608 struct ieee80211_supported_band *sband;
6609 struct survey_info *ar_survey = &ar->survey[idx];
6612 mutex_lock(&ar->conf_mutex);
6614 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6615 if (sband && idx >= sband->n_channels) {
6616 idx -= sband->n_channels;
6621 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6623 if (!sband || idx >= sband->n_channels) {
6628 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6630 spin_lock_bh(&ar->data_lock);
6631 memcpy(survey, ar_survey, sizeof(*survey));
6632 spin_unlock_bh(&ar->data_lock);
6634 survey->channel = &sband->channels[idx];
6636 if (ar->rx_channel == survey->channel)
6637 survey->filled |= SURVEY_INFO_IN_USE;
6640 mutex_unlock(&ar->conf_mutex);
6645 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6646 enum nl80211_band band,
6647 const struct cfg80211_bitrate_mask *mask)
6652 num_rates += hweight32(mask->control[band].legacy);
6654 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6655 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6657 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6658 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6660 return num_rates == 1;
6664 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6665 enum nl80211_band band,
6666 const struct cfg80211_bitrate_mask *mask,
6669 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6670 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6672 u8 vht_nss_mask = 0;
6675 if (mask->control[band].legacy)
6678 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6679 if (mask->control[band].ht_mcs[i] == 0)
6681 else if (mask->control[band].ht_mcs[i] ==
6682 sband->ht_cap.mcs.rx_mask[i])
6683 ht_nss_mask |= BIT(i);
6688 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6689 if (mask->control[band].vht_mcs[i] == 0)
6691 else if (mask->control[band].vht_mcs[i] ==
6692 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6693 vht_nss_mask |= BIT(i);
6698 if (ht_nss_mask != vht_nss_mask)
6701 if (ht_nss_mask == 0)
6704 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6707 *nss = fls(ht_nss_mask);
6713 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6714 enum nl80211_band band,
6715 const struct cfg80211_bitrate_mask *mask,
6718 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6725 if (hweight32(mask->control[band].legacy) == 1) {
6726 rate_idx = ffs(mask->control[band].legacy) - 1;
6728 hw_rate = sband->bitrates[rate_idx].hw_value;
6729 bitrate = sband->bitrates[rate_idx].bitrate;
6731 if (ath10k_mac_bitrate_is_cck(bitrate))
6732 preamble = WMI_RATE_PREAMBLE_CCK;
6734 preamble = WMI_RATE_PREAMBLE_OFDM;
6737 *rate = preamble << 6 |
6744 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6745 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6747 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6749 (ffs(mask->control[band].ht_mcs[i]) - 1);
6755 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6756 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6758 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6760 (ffs(mask->control[band].vht_mcs[i]) - 1);
6769 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6770 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6772 struct ath10k *ar = arvif->ar;
6776 lockdep_assert_held(&ar->conf_mutex);
6778 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6779 arvif->vdev_id, rate, nss, sgi);
6781 vdev_param = ar->wmi.vdev_param->fixed_rate;
6782 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6784 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6789 vdev_param = ar->wmi.vdev_param->nss;
6790 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6792 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6796 vdev_param = ar->wmi.vdev_param->sgi;
6797 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6799 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6803 vdev_param = ar->wmi.vdev_param->ldpc;
6804 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6806 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6814 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6815 enum nl80211_band band,
6816 const struct cfg80211_bitrate_mask *mask)
6821 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6822 * to express all VHT MCS rate masks. Effectively only the following
6823 * ranges can be used: none, 0-7, 0-8 and 0-9.
6825 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6826 vht_mcs = mask->control[band].vht_mcs[i];
6835 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6843 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6844 struct ieee80211_sta *sta)
6846 struct ath10k_vif *arvif = data;
6847 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6848 struct ath10k *ar = arvif->ar;
6850 if (arsta->arvif != arvif)
6853 spin_lock_bh(&ar->data_lock);
6854 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6855 spin_unlock_bh(&ar->data_lock);
6857 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6860 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6861 struct ieee80211_vif *vif,
6862 const struct cfg80211_bitrate_mask *mask)
6864 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6865 struct cfg80211_chan_def def;
6866 struct ath10k *ar = arvif->ar;
6867 enum nl80211_band band;
6868 const u8 *ht_mcs_mask;
6869 const u16 *vht_mcs_mask;
6877 if (ath10k_mac_vif_chan(vif, &def))
6880 band = def.chan->band;
6881 ht_mcs_mask = mask->control[band].ht_mcs;
6882 vht_mcs_mask = mask->control[band].vht_mcs;
6883 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6885 sgi = mask->control[band].gi;
6886 if (sgi == NL80211_TXRATE_FORCE_LGI)
6889 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6890 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6893 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6894 arvif->vdev_id, ret);
6897 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6899 rate = WMI_FIXED_RATE_NONE;
6902 rate = WMI_FIXED_RATE_NONE;
6903 nss = min(ar->num_rf_chains,
6904 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6905 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6907 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6910 mutex_lock(&ar->conf_mutex);
6912 arvif->bitrate_mask = *mask;
6913 ieee80211_iterate_stations_atomic(ar->hw,
6914 ath10k_mac_set_bitrate_mask_iter,
6917 mutex_unlock(&ar->conf_mutex);
6920 mutex_lock(&ar->conf_mutex);
6922 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6924 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6925 arvif->vdev_id, ret);
6930 mutex_unlock(&ar->conf_mutex);
6935 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6936 struct ieee80211_vif *vif,
6937 struct ieee80211_sta *sta,
6940 struct ath10k *ar = hw->priv;
6941 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6942 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6943 struct ath10k_peer *peer;
6946 spin_lock_bh(&ar->data_lock);
6948 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6950 spin_unlock_bh(&ar->data_lock);
6951 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
6952 sta->addr, arvif->vdev_id);
6956 ath10k_dbg(ar, ATH10K_DBG_MAC,
6957 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6958 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6961 if (changed & IEEE80211_RC_BW_CHANGED) {
6962 bw = WMI_PEER_CHWIDTH_20MHZ;
6964 switch (sta->bandwidth) {
6965 case IEEE80211_STA_RX_BW_20:
6966 bw = WMI_PEER_CHWIDTH_20MHZ;
6968 case IEEE80211_STA_RX_BW_40:
6969 bw = WMI_PEER_CHWIDTH_40MHZ;
6971 case IEEE80211_STA_RX_BW_80:
6972 bw = WMI_PEER_CHWIDTH_80MHZ;
6974 case IEEE80211_STA_RX_BW_160:
6975 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6976 sta->bandwidth, sta->addr);
6977 bw = WMI_PEER_CHWIDTH_20MHZ;
6984 if (changed & IEEE80211_RC_NSS_CHANGED)
6985 arsta->nss = sta->rx_nss;
6987 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6988 smps = WMI_PEER_SMPS_PS_NONE;
6990 switch (sta->smps_mode) {
6991 case IEEE80211_SMPS_AUTOMATIC:
6992 case IEEE80211_SMPS_OFF:
6993 smps = WMI_PEER_SMPS_PS_NONE;
6995 case IEEE80211_SMPS_STATIC:
6996 smps = WMI_PEER_SMPS_STATIC;
6998 case IEEE80211_SMPS_DYNAMIC:
6999 smps = WMI_PEER_SMPS_DYNAMIC;
7001 case IEEE80211_SMPS_NUM_MODES:
7002 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
7003 sta->smps_mode, sta->addr);
7004 smps = WMI_PEER_SMPS_PS_NONE;
7011 arsta->changed |= changed;
7013 spin_unlock_bh(&ar->data_lock);
7015 ieee80211_queue_work(hw, &arsta->update_wk);
7018 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
7021 * FIXME: Return 0 for time being. Need to figure out whether FW
7022 * has the API to fetch 64-bit local TSF
7028 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7031 struct ath10k *ar = hw->priv;
7032 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7033 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
7038 * Given tsf argument is entire TSF value, but firmware accepts
7039 * only TSF offset to current TSF.
7041 * get_tsf function is used to get offset value, however since
7042 * ath10k_get_tsf is not implemented properly, it will return 0 always.
7043 * Luckily all the caller functions to set_tsf, as of now, also rely on
7044 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
7045 * final tsf offset value to firmware will be arithmetically correct.
7047 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
7048 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
7049 vdev_param, tsf_offset);
7050 if (ret && ret != -EOPNOTSUPP)
7051 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
7054 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
7055 struct ieee80211_vif *vif,
7056 struct ieee80211_ampdu_params *params)
7058 struct ath10k *ar = hw->priv;
7059 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7060 struct ieee80211_sta *sta = params->sta;
7061 enum ieee80211_ampdu_mlme_action action = params->action;
7062 u16 tid = params->tid;
7064 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7065 arvif->vdev_id, sta->addr, tid, action);
7068 case IEEE80211_AMPDU_RX_START:
7069 case IEEE80211_AMPDU_RX_STOP:
7070 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7071 * creation/removal. Do we need to verify this?
7074 case IEEE80211_AMPDU_TX_START:
7075 case IEEE80211_AMPDU_TX_STOP_CONT:
7076 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7077 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7078 case IEEE80211_AMPDU_TX_OPERATIONAL:
7079 /* Firmware offloads Tx aggregation entirely so deny mac80211
7080 * Tx aggregation requests.
7089 ath10k_mac_update_rx_channel(struct ath10k *ar,
7090 struct ieee80211_chanctx_conf *ctx,
7091 struct ieee80211_vif_chanctx_switch *vifs,
7094 struct cfg80211_chan_def *def = NULL;
7096 /* Both locks are required because ar->rx_channel is modified. This
7097 * allows readers to hold either lock.
7099 lockdep_assert_held(&ar->conf_mutex);
7100 lockdep_assert_held(&ar->data_lock);
7102 WARN_ON(ctx && vifs);
7103 WARN_ON(vifs && !n_vifs);
7105 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7106 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7107 * ppdu on Rx may reduce performance on low-end systems. It should be
7108 * possible to make tables/hashmaps to speed the lookup up (be vary of
7109 * cpu data cache lines though regarding sizes) but to keep the initial
7110 * implementation simple and less intrusive fallback to the slow lookup
7111 * only for multi-channel cases. Single-channel cases will remain to
7112 * use the old channel derival and thus performance should not be
7116 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7117 ieee80211_iter_chan_contexts_atomic(ar->hw,
7118 ath10k_mac_get_any_chandef_iter,
7122 def = &vifs[0].new_ctx->def;
7124 ar->rx_channel = def->chan;
7125 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7126 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7127 /* During driver restart due to firmware assert, since mac80211
7128 * already has valid channel context for given radio, channel
7129 * context iteration return num_chanctx > 0. So fix rx_channel
7130 * when restart is in progress.
7132 ar->rx_channel = ctx->def.chan;
7134 ar->rx_channel = NULL;
7140 ath10k_mac_update_vif_chan(struct ath10k *ar,
7141 struct ieee80211_vif_chanctx_switch *vifs,
7144 struct ath10k_vif *arvif;
7148 lockdep_assert_held(&ar->conf_mutex);
7150 /* First stop monitor interface. Some FW versions crash if there's a
7151 * lone monitor interface.
7153 if (ar->monitor_started)
7154 ath10k_monitor_stop(ar);
7156 for (i = 0; i < n_vifs; i++) {
7157 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7159 ath10k_dbg(ar, ATH10K_DBG_MAC,
7160 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7162 vifs[i].old_ctx->def.chan->center_freq,
7163 vifs[i].new_ctx->def.chan->center_freq,
7164 vifs[i].old_ctx->def.width,
7165 vifs[i].new_ctx->def.width);
7167 if (WARN_ON(!arvif->is_started))
7170 if (WARN_ON(!arvif->is_up))
7173 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7175 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7176 arvif->vdev_id, ret);
7181 /* All relevant vdevs are downed and associated channel resources
7182 * should be available for the channel switch now.
7185 spin_lock_bh(&ar->data_lock);
7186 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7187 spin_unlock_bh(&ar->data_lock);
7189 for (i = 0; i < n_vifs; i++) {
7190 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7192 if (WARN_ON(!arvif->is_started))
7195 if (WARN_ON(!arvif->is_up))
7198 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7200 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7203 ret = ath10k_mac_setup_prb_tmpl(arvif);
7205 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7208 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7210 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7211 arvif->vdev_id, ret);
7215 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7218 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7219 arvif->vdev_id, ret);
7224 ath10k_monitor_recalc(ar);
7228 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7229 struct ieee80211_chanctx_conf *ctx)
7231 struct ath10k *ar = hw->priv;
7233 ath10k_dbg(ar, ATH10K_DBG_MAC,
7234 "mac chanctx add freq %hu width %d ptr %pK\n",
7235 ctx->def.chan->center_freq, ctx->def.width, ctx);
7237 mutex_lock(&ar->conf_mutex);
7239 spin_lock_bh(&ar->data_lock);
7240 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7241 spin_unlock_bh(&ar->data_lock);
7243 ath10k_recalc_radar_detection(ar);
7244 ath10k_monitor_recalc(ar);
7246 mutex_unlock(&ar->conf_mutex);
7252 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7253 struct ieee80211_chanctx_conf *ctx)
7255 struct ath10k *ar = hw->priv;
7257 ath10k_dbg(ar, ATH10K_DBG_MAC,
7258 "mac chanctx remove freq %hu width %d ptr %pK\n",
7259 ctx->def.chan->center_freq, ctx->def.width, ctx);
7261 mutex_lock(&ar->conf_mutex);
7263 spin_lock_bh(&ar->data_lock);
7264 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7265 spin_unlock_bh(&ar->data_lock);
7267 ath10k_recalc_radar_detection(ar);
7268 ath10k_monitor_recalc(ar);
7270 mutex_unlock(&ar->conf_mutex);
7273 struct ath10k_mac_change_chanctx_arg {
7274 struct ieee80211_chanctx_conf *ctx;
7275 struct ieee80211_vif_chanctx_switch *vifs;
7281 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7282 struct ieee80211_vif *vif)
7284 struct ath10k_mac_change_chanctx_arg *arg = data;
7286 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7293 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7294 struct ieee80211_vif *vif)
7296 struct ath10k_mac_change_chanctx_arg *arg = data;
7297 struct ieee80211_chanctx_conf *ctx;
7299 ctx = rcu_access_pointer(vif->chanctx_conf);
7300 if (ctx != arg->ctx)
7303 if (WARN_ON(arg->next_vif == arg->n_vifs))
7306 arg->vifs[arg->next_vif].vif = vif;
7307 arg->vifs[arg->next_vif].old_ctx = ctx;
7308 arg->vifs[arg->next_vif].new_ctx = ctx;
7313 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7314 struct ieee80211_chanctx_conf *ctx,
7317 struct ath10k *ar = hw->priv;
7318 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7320 mutex_lock(&ar->conf_mutex);
7322 ath10k_dbg(ar, ATH10K_DBG_MAC,
7323 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7324 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7326 /* This shouldn't really happen because channel switching should use
7327 * switch_vif_chanctx().
7329 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7332 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7333 ieee80211_iterate_active_interfaces_atomic(
7335 IEEE80211_IFACE_ITER_NORMAL,
7336 ath10k_mac_change_chanctx_cnt_iter,
7338 if (arg.n_vifs == 0)
7341 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7346 ieee80211_iterate_active_interfaces_atomic(
7348 IEEE80211_IFACE_ITER_NORMAL,
7349 ath10k_mac_change_chanctx_fill_iter,
7351 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7356 ath10k_recalc_radar_detection(ar);
7358 /* FIXME: How to configure Rx chains properly? */
7360 /* No other actions are actually necessary. Firmware maintains channel
7361 * definitions per vdev internally and there's no host-side channel
7362 * context abstraction to configure, e.g. channel width.
7366 mutex_unlock(&ar->conf_mutex);
7370 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7371 struct ieee80211_vif *vif,
7372 struct ieee80211_chanctx_conf *ctx)
7374 struct ath10k *ar = hw->priv;
7375 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7378 mutex_lock(&ar->conf_mutex);
7380 ath10k_dbg(ar, ATH10K_DBG_MAC,
7381 "mac chanctx assign ptr %pK vdev_id %i\n",
7382 ctx, arvif->vdev_id);
7384 if (WARN_ON(arvif->is_started)) {
7385 mutex_unlock(&ar->conf_mutex);
7389 ret = ath10k_vdev_start(arvif, &ctx->def);
7391 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7392 arvif->vdev_id, vif->addr,
7393 ctx->def.chan->center_freq, ret);
7397 arvif->is_started = true;
7399 ret = ath10k_mac_vif_setup_ps(arvif);
7401 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7402 arvif->vdev_id, ret);
7406 if (vif->type == NL80211_IFTYPE_MONITOR) {
7407 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7409 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7410 arvif->vdev_id, ret);
7414 arvif->is_up = true;
7417 if (ath10k_mac_can_set_cts_prot(arvif)) {
7418 ret = ath10k_mac_set_cts_prot(arvif);
7420 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
7421 arvif->vdev_id, ret);
7424 mutex_unlock(&ar->conf_mutex);
7428 ath10k_vdev_stop(arvif);
7429 arvif->is_started = false;
7430 ath10k_mac_vif_setup_ps(arvif);
7433 mutex_unlock(&ar->conf_mutex);
7438 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7439 struct ieee80211_vif *vif,
7440 struct ieee80211_chanctx_conf *ctx)
7442 struct ath10k *ar = hw->priv;
7443 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7446 mutex_lock(&ar->conf_mutex);
7448 ath10k_dbg(ar, ATH10K_DBG_MAC,
7449 "mac chanctx unassign ptr %pK vdev_id %i\n",
7450 ctx, arvif->vdev_id);
7452 WARN_ON(!arvif->is_started);
7454 if (vif->type == NL80211_IFTYPE_MONITOR) {
7455 WARN_ON(!arvif->is_up);
7457 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7459 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7460 arvif->vdev_id, ret);
7462 arvif->is_up = false;
7465 ret = ath10k_vdev_stop(arvif);
7467 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7468 arvif->vdev_id, ret);
7470 arvif->is_started = false;
7472 mutex_unlock(&ar->conf_mutex);
7476 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7477 struct ieee80211_vif_chanctx_switch *vifs,
7479 enum ieee80211_chanctx_switch_mode mode)
7481 struct ath10k *ar = hw->priv;
7483 mutex_lock(&ar->conf_mutex);
7485 ath10k_dbg(ar, ATH10K_DBG_MAC,
7486 "mac chanctx switch n_vifs %d mode %d\n",
7488 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7490 mutex_unlock(&ar->conf_mutex);
7494 static void ath10k_mac_op_sta_pre_rcu_remove(struct ieee80211_hw *hw,
7495 struct ieee80211_vif *vif,
7496 struct ieee80211_sta *sta)
7499 struct ath10k_peer *peer;
7503 list_for_each_entry(peer, &ar->peers, list)
7504 if (peer->sta == sta)
7505 peer->removed = true;
7508 static const struct ieee80211_ops ath10k_ops = {
7509 .tx = ath10k_mac_op_tx,
7510 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7511 .start = ath10k_start,
7512 .stop = ath10k_stop,
7513 .config = ath10k_config,
7514 .add_interface = ath10k_add_interface,
7515 .remove_interface = ath10k_remove_interface,
7516 .configure_filter = ath10k_configure_filter,
7517 .bss_info_changed = ath10k_bss_info_changed,
7518 .hw_scan = ath10k_hw_scan,
7519 .cancel_hw_scan = ath10k_cancel_hw_scan,
7520 .set_key = ath10k_set_key,
7521 .set_default_unicast_key = ath10k_set_default_unicast_key,
7522 .sta_state = ath10k_sta_state,
7523 .conf_tx = ath10k_conf_tx,
7524 .remain_on_channel = ath10k_remain_on_channel,
7525 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7526 .set_rts_threshold = ath10k_set_rts_threshold,
7527 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7528 .flush = ath10k_flush,
7529 .tx_last_beacon = ath10k_tx_last_beacon,
7530 .set_antenna = ath10k_set_antenna,
7531 .get_antenna = ath10k_get_antenna,
7532 .reconfig_complete = ath10k_reconfig_complete,
7533 .get_survey = ath10k_get_survey,
7534 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7535 .sta_rc_update = ath10k_sta_rc_update,
7536 .get_tsf = ath10k_get_tsf,
7537 .set_tsf = ath10k_set_tsf,
7538 .ampdu_action = ath10k_ampdu_action,
7539 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7540 .get_et_stats = ath10k_debug_get_et_stats,
7541 .get_et_strings = ath10k_debug_get_et_strings,
7542 .add_chanctx = ath10k_mac_op_add_chanctx,
7543 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7544 .change_chanctx = ath10k_mac_op_change_chanctx,
7545 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7546 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7547 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7548 .sta_pre_rcu_remove = ath10k_mac_op_sta_pre_rcu_remove,
7550 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7553 .suspend = ath10k_wow_op_suspend,
7554 .resume = ath10k_wow_op_resume,
7556 #ifdef CONFIG_MAC80211_DEBUGFS
7557 .sta_add_debugfs = ath10k_sta_add_debugfs,
7558 .sta_statistics = ath10k_sta_statistics,
7562 #define CHAN2G(_channel, _freq, _flags) { \
7563 .band = NL80211_BAND_2GHZ, \
7564 .hw_value = (_channel), \
7565 .center_freq = (_freq), \
7566 .flags = (_flags), \
7567 .max_antenna_gain = 0, \
7571 #define CHAN5G(_channel, _freq, _flags) { \
7572 .band = NL80211_BAND_5GHZ, \
7573 .hw_value = (_channel), \
7574 .center_freq = (_freq), \
7575 .flags = (_flags), \
7576 .max_antenna_gain = 0, \
7580 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7590 CHAN2G(10, 2457, 0),
7591 CHAN2G(11, 2462, 0),
7592 CHAN2G(12, 2467, 0),
7593 CHAN2G(13, 2472, 0),
7594 CHAN2G(14, 2484, 0),
7597 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7598 CHAN5G(36, 5180, 0),
7599 CHAN5G(40, 5200, 0),
7600 CHAN5G(44, 5220, 0),
7601 CHAN5G(48, 5240, 0),
7602 CHAN5G(52, 5260, 0),
7603 CHAN5G(56, 5280, 0),
7604 CHAN5G(60, 5300, 0),
7605 CHAN5G(64, 5320, 0),
7606 CHAN5G(100, 5500, 0),
7607 CHAN5G(104, 5520, 0),
7608 CHAN5G(108, 5540, 0),
7609 CHAN5G(112, 5560, 0),
7610 CHAN5G(116, 5580, 0),
7611 CHAN5G(120, 5600, 0),
7612 CHAN5G(124, 5620, 0),
7613 CHAN5G(128, 5640, 0),
7614 CHAN5G(132, 5660, 0),
7615 CHAN5G(136, 5680, 0),
7616 CHAN5G(140, 5700, 0),
7617 CHAN5G(144, 5720, 0),
7618 CHAN5G(149, 5745, 0),
7619 CHAN5G(153, 5765, 0),
7620 CHAN5G(157, 5785, 0),
7621 CHAN5G(161, 5805, 0),
7622 CHAN5G(165, 5825, 0),
7625 struct ath10k *ath10k_mac_create(size_t priv_size)
7627 struct ieee80211_hw *hw;
7628 struct ieee80211_ops *ops;
7631 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7635 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7648 void ath10k_mac_destroy(struct ath10k *ar)
7650 struct ieee80211_ops *ops = ar->ops;
7652 ieee80211_free_hw(ar->hw);
7656 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7659 .types = BIT(NL80211_IFTYPE_STATION)
7660 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7664 .types = BIT(NL80211_IFTYPE_P2P_GO)
7668 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7672 .types = BIT(NL80211_IFTYPE_AP)
7673 #ifdef CONFIG_MAC80211_MESH
7674 | BIT(NL80211_IFTYPE_MESH_POINT)
7679 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7682 .types = BIT(NL80211_IFTYPE_AP)
7683 #ifdef CONFIG_MAC80211_MESH
7684 | BIT(NL80211_IFTYPE_MESH_POINT)
7689 .types = BIT(NL80211_IFTYPE_STATION)
7693 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7695 .limits = ath10k_if_limits,
7696 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7697 .max_interfaces = 8,
7698 .num_different_channels = 1,
7699 .beacon_int_infra_match = true,
7703 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7705 .limits = ath10k_10x_if_limits,
7706 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7707 .max_interfaces = 8,
7708 .num_different_channels = 1,
7709 .beacon_int_infra_match = true,
7710 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7711 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7712 BIT(NL80211_CHAN_WIDTH_20) |
7713 BIT(NL80211_CHAN_WIDTH_40) |
7714 BIT(NL80211_CHAN_WIDTH_80),
7719 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7722 .types = BIT(NL80211_IFTYPE_STATION),
7726 .types = BIT(NL80211_IFTYPE_AP) |
7727 #ifdef CONFIG_MAC80211_MESH
7728 BIT(NL80211_IFTYPE_MESH_POINT) |
7730 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7731 BIT(NL80211_IFTYPE_P2P_GO),
7735 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7739 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7742 .types = BIT(NL80211_IFTYPE_STATION),
7746 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7750 .types = BIT(NL80211_IFTYPE_AP) |
7751 #ifdef CONFIG_MAC80211_MESH
7752 BIT(NL80211_IFTYPE_MESH_POINT) |
7754 BIT(NL80211_IFTYPE_P2P_GO),
7758 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7762 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7765 .types = BIT(NL80211_IFTYPE_STATION),
7769 .types = BIT(NL80211_IFTYPE_ADHOC),
7773 /* FIXME: This is not thouroughly tested. These combinations may over- or
7774 * underestimate hw/fw capabilities.
7776 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7778 .limits = ath10k_tlv_if_limit,
7779 .num_different_channels = 1,
7780 .max_interfaces = 4,
7781 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7784 .limits = ath10k_tlv_if_limit_ibss,
7785 .num_different_channels = 1,
7786 .max_interfaces = 2,
7787 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7791 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7793 .limits = ath10k_tlv_if_limit,
7794 .num_different_channels = 1,
7795 .max_interfaces = 4,
7796 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7799 .limits = ath10k_tlv_qcs_if_limit,
7800 .num_different_channels = 2,
7801 .max_interfaces = 4,
7802 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7805 .limits = ath10k_tlv_if_limit_ibss,
7806 .num_different_channels = 1,
7807 .max_interfaces = 2,
7808 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7812 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7815 .types = BIT(NL80211_IFTYPE_STATION),
7819 .types = BIT(NL80211_IFTYPE_AP)
7820 #ifdef CONFIG_MAC80211_MESH
7821 | BIT(NL80211_IFTYPE_MESH_POINT)
7826 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7828 .limits = ath10k_10_4_if_limits,
7829 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7830 .max_interfaces = 16,
7831 .num_different_channels = 1,
7832 .beacon_int_infra_match = true,
7833 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7834 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7835 BIT(NL80211_CHAN_WIDTH_20) |
7836 BIT(NL80211_CHAN_WIDTH_40) |
7837 BIT(NL80211_CHAN_WIDTH_80),
7842 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7843 struct ieee80211_vif *vif)
7845 struct ath10k_vif_iter *arvif_iter = data;
7846 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7848 if (arvif->vdev_id == arvif_iter->vdev_id)
7849 arvif_iter->arvif = arvif;
7852 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7854 struct ath10k_vif_iter arvif_iter;
7857 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7858 arvif_iter.vdev_id = vdev_id;
7860 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7861 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7863 ath10k_get_arvif_iter,
7865 if (!arvif_iter.arvif) {
7866 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7870 return arvif_iter.arvif;
7873 int ath10k_mac_register(struct ath10k *ar)
7875 static const u32 cipher_suites[] = {
7876 WLAN_CIPHER_SUITE_WEP40,
7877 WLAN_CIPHER_SUITE_WEP104,
7878 WLAN_CIPHER_SUITE_TKIP,
7879 WLAN_CIPHER_SUITE_CCMP,
7880 WLAN_CIPHER_SUITE_AES_CMAC,
7882 struct ieee80211_supported_band *band;
7886 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
7888 SET_IEEE80211_DEV(ar->hw, ar->dev);
7890 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
7891 ARRAY_SIZE(ath10k_5ghz_channels)) !=
7894 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
7895 channels = kmemdup(ath10k_2ghz_channels,
7896 sizeof(ath10k_2ghz_channels),
7903 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
7904 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
7905 band->channels = channels;
7907 if (ar->hw_params.cck_rate_map_rev2) {
7908 band->n_bitrates = ath10k_g_rates_rev2_size;
7909 band->bitrates = ath10k_g_rates_rev2;
7911 band->n_bitrates = ath10k_g_rates_size;
7912 band->bitrates = ath10k_g_rates;
7915 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
7918 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
7919 channels = kmemdup(ath10k_5ghz_channels,
7920 sizeof(ath10k_5ghz_channels),
7927 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
7928 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
7929 band->channels = channels;
7930 band->n_bitrates = ath10k_a_rates_size;
7931 band->bitrates = ath10k_a_rates;
7932 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
7935 ath10k_mac_setup_ht_vht_cap(ar);
7937 ar->hw->wiphy->interface_modes =
7938 BIT(NL80211_IFTYPE_STATION) |
7939 BIT(NL80211_IFTYPE_AP) |
7940 BIT(NL80211_IFTYPE_MESH_POINT);
7942 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
7943 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
7945 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
7946 ar->hw->wiphy->interface_modes |=
7947 BIT(NL80211_IFTYPE_P2P_DEVICE) |
7948 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7949 BIT(NL80211_IFTYPE_P2P_GO);
7951 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
7952 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
7953 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
7954 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
7955 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
7956 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
7957 ieee80211_hw_set(ar->hw, AP_LINK_PS);
7958 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
7959 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
7960 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7961 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7962 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7963 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7964 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
7966 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7967 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7969 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
7970 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
7972 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
7973 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
7975 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
7976 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7977 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
7980 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7981 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7983 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
7984 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
7985 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
7987 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7989 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7990 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7992 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7993 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7994 * correct Probe Responses. This is more of a hack advert..
7996 ar->hw->wiphy->probe_resp_offload |=
7997 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7998 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7999 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
8002 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
8003 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
8005 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8006 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8007 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8009 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8010 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8011 NL80211_FEATURE_AP_SCAN;
8013 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8015 ret = ath10k_wow_init(ar);
8017 ath10k_warn(ar, "failed to init wow: %d\n", ret);
8021 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
8024 * on LL hardware queues are managed entirely by the FW
8025 * so we only advertise to mac we can do the queues thing
8027 ar->hw->queues = IEEE80211_MAX_QUEUES;
8029 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
8030 * something that vdev_ids can't reach so that we don't stop the queue
8033 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
8035 switch (ar->running_fw->fw_file.wmi_op_version) {
8036 case ATH10K_FW_WMI_OP_VERSION_MAIN:
8037 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
8038 ar->hw->wiphy->n_iface_combinations =
8039 ARRAY_SIZE(ath10k_if_comb);
8040 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8042 case ATH10K_FW_WMI_OP_VERSION_TLV:
8043 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
8044 ar->hw->wiphy->iface_combinations =
8045 ath10k_tlv_qcs_if_comb;
8046 ar->hw->wiphy->n_iface_combinations =
8047 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
8049 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
8050 ar->hw->wiphy->n_iface_combinations =
8051 ARRAY_SIZE(ath10k_tlv_if_comb);
8053 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
8055 case ATH10K_FW_WMI_OP_VERSION_10_1:
8056 case ATH10K_FW_WMI_OP_VERSION_10_2:
8057 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
8058 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
8059 ar->hw->wiphy->n_iface_combinations =
8060 ARRAY_SIZE(ath10k_10x_if_comb);
8062 case ATH10K_FW_WMI_OP_VERSION_10_4:
8063 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
8064 ar->hw->wiphy->n_iface_combinations =
8065 ARRAY_SIZE(ath10k_10_4_if_comb);
8067 case ATH10K_FW_WMI_OP_VERSION_UNSET:
8068 case ATH10K_FW_WMI_OP_VERSION_MAX:
8074 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
8075 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8077 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
8078 /* Init ath dfs pattern detector */
8079 ar->ath_common.debug_mask = ATH_DBG_DFS;
8080 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
8083 if (!ar->dfs_detector)
8084 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8087 /* Current wake_tx_queue implementation imposes a significant
8088 * performance penalty in some setups. The tx scheduling code needs
8089 * more work anyway so disable the wake_tx_queue unless firmware
8090 * supports the pull-push mechanism.
8092 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8093 ar->running_fw->fw_file.fw_features))
8094 ar->ops->wake_tx_queue = NULL;
8096 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8097 ath10k_reg_notifier);
8099 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8100 goto err_dfs_detector_exit;
8103 ar->hw->wiphy->cipher_suites = cipher_suites;
8104 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8106 ret = ieee80211_register_hw(ar->hw);
8108 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8109 goto err_dfs_detector_exit;
8112 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8113 ret = regulatory_hint(ar->hw->wiphy,
8114 ar->ath_common.regulatory.alpha2);
8116 goto err_unregister;
8122 ieee80211_unregister_hw(ar->hw);
8124 err_dfs_detector_exit:
8125 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8126 ar->dfs_detector->exit(ar->dfs_detector);
8129 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8130 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8132 SET_IEEE80211_DEV(ar->hw, NULL);
8136 void ath10k_mac_unregister(struct ath10k *ar)
8138 ieee80211_unregister_hw(ar->hw);
8140 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8141 ar->dfs_detector->exit(ar->dfs_detector);
8143 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8144 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8146 SET_IEEE80211_DEV(ar->hw, NULL);