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);
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 * 2;
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 int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1229 struct ath10k *ar = arvif->ar;
1230 u32 vdev_param, rts_cts = 0;
1232 lockdep_assert_held(&ar->conf_mutex);
1234 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1236 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1238 if (arvif->num_legacy_stations > 0)
1239 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1240 WMI_RTSCTS_PROFILE);
1242 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1243 WMI_RTSCTS_PROFILE);
1245 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1249 static int ath10k_start_cac(struct ath10k *ar)
1253 lockdep_assert_held(&ar->conf_mutex);
1255 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1257 ret = ath10k_monitor_recalc(ar);
1259 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1260 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1264 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1265 ar->monitor_vdev_id);
1270 static int ath10k_stop_cac(struct ath10k *ar)
1272 lockdep_assert_held(&ar->conf_mutex);
1274 /* CAC is not running - do nothing */
1275 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1278 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1279 ath10k_monitor_stop(ar);
1281 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1286 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1287 struct ieee80211_chanctx_conf *conf,
1292 if (!*ret && conf->radar_enabled)
1296 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1298 bool has_radar = false;
1300 ieee80211_iter_chan_contexts_atomic(ar->hw,
1301 ath10k_mac_has_radar_iter,
1307 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1311 lockdep_assert_held(&ar->conf_mutex);
1313 ath10k_stop_cac(ar);
1315 if (!ath10k_mac_has_radar_enabled(ar))
1318 if (ar->num_started_vdevs > 0)
1321 ret = ath10k_start_cac(ar);
1324 * Not possible to start CAC on current channel so starting
1325 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1326 * by indicating that radar was detected.
1328 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1329 ieee80211_radar_detected(ar->hw);
1333 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1335 struct ath10k *ar = arvif->ar;
1338 lockdep_assert_held(&ar->conf_mutex);
1340 reinit_completion(&ar->vdev_setup_done);
1342 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1344 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1345 arvif->vdev_id, ret);
1349 ret = ath10k_vdev_setup_sync(ar);
1351 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1352 arvif->vdev_id, ret);
1356 WARN_ON(ar->num_started_vdevs == 0);
1358 if (ar->num_started_vdevs != 0) {
1359 ar->num_started_vdevs--;
1360 ath10k_recalc_radar_detection(ar);
1366 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1367 const struct cfg80211_chan_def *chandef,
1370 struct ath10k *ar = arvif->ar;
1371 struct wmi_vdev_start_request_arg arg = {};
1374 lockdep_assert_held(&ar->conf_mutex);
1376 reinit_completion(&ar->vdev_setup_done);
1378 arg.vdev_id = arvif->vdev_id;
1379 arg.dtim_period = arvif->dtim_period;
1380 arg.bcn_intval = arvif->beacon_interval;
1382 arg.channel.freq = chandef->chan->center_freq;
1383 arg.channel.band_center_freq1 = chandef->center_freq1;
1384 arg.channel.mode = chan_to_phymode(chandef);
1386 arg.channel.min_power = 0;
1387 arg.channel.max_power = chandef->chan->max_power * 2;
1388 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1389 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1391 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1392 arg.ssid = arvif->u.ap.ssid;
1393 arg.ssid_len = arvif->u.ap.ssid_len;
1394 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1396 /* For now allow DFS for AP mode */
1397 arg.channel.chan_radar =
1398 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1399 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1400 arg.ssid = arvif->vif->bss_conf.ssid;
1401 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1404 ath10k_dbg(ar, ATH10K_DBG_MAC,
1405 "mac vdev %d start center_freq %d phymode %s\n",
1406 arg.vdev_id, arg.channel.freq,
1407 ath10k_wmi_phymode_str(arg.channel.mode));
1410 ret = ath10k_wmi_vdev_restart(ar, &arg);
1412 ret = ath10k_wmi_vdev_start(ar, &arg);
1415 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1420 ret = ath10k_vdev_setup_sync(ar);
1423 "failed to synchronize setup for vdev %i restart %d: %d\n",
1424 arg.vdev_id, restart, ret);
1428 ar->num_started_vdevs++;
1429 ath10k_recalc_radar_detection(ar);
1434 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1435 const struct cfg80211_chan_def *def)
1437 return ath10k_vdev_start_restart(arvif, def, false);
1440 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1441 const struct cfg80211_chan_def *def)
1443 return ath10k_vdev_start_restart(arvif, def, true);
1446 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1447 struct sk_buff *bcn)
1449 struct ath10k *ar = arvif->ar;
1450 struct ieee80211_mgmt *mgmt;
1454 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1457 mgmt = (void *)bcn->data;
1458 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1459 mgmt->u.beacon.variable,
1460 bcn->len - (mgmt->u.beacon.variable -
1465 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1467 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1468 arvif->vdev_id, ret);
1475 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1476 u8 oui_type, size_t ie_offset)
1483 if (WARN_ON(skb->len < ie_offset))
1486 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1487 skb->data + ie_offset,
1488 skb->len - ie_offset);
1493 end = skb->data + skb->len;
1496 if (WARN_ON(next > end))
1499 memmove(ie, next, end - next);
1500 skb_trim(skb, skb->len - len);
1505 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1507 struct ath10k *ar = arvif->ar;
1508 struct ieee80211_hw *hw = ar->hw;
1509 struct ieee80211_vif *vif = arvif->vif;
1510 struct ieee80211_mutable_offsets offs = {};
1511 struct sk_buff *bcn;
1514 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1517 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1518 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1521 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1523 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1527 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1529 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1534 /* P2P IE is inserted by firmware automatically (as configured above)
1535 * so remove it from the base beacon template to avoid duplicate P2P
1536 * IEs in beacon frames.
1538 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1539 offsetof(struct ieee80211_mgmt,
1540 u.beacon.variable));
1542 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1547 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1555 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1557 struct ath10k *ar = arvif->ar;
1558 struct ieee80211_hw *hw = ar->hw;
1559 struct ieee80211_vif *vif = arvif->vif;
1560 struct sk_buff *prb;
1563 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1566 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1569 prb = ieee80211_proberesp_get(hw, vif);
1571 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1575 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1579 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1587 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1589 struct ath10k *ar = arvif->ar;
1590 struct cfg80211_chan_def def;
1593 /* When originally vdev is started during assign_vif_chanctx() some
1594 * information is missing, notably SSID. Firmware revisions with beacon
1595 * offloading require the SSID to be provided during vdev (re)start to
1596 * handle hidden SSID properly.
1598 * Vdev restart must be done after vdev has been both started and
1599 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1600 * deliver vdev restart response event causing timeouts during vdev
1601 * syncing in ath10k.
1603 * Note: The vdev down/up and template reinstallation could be skipped
1604 * since only wmi-tlv firmware are known to have beacon offload and
1605 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1606 * response delivery. It's probably more robust to keep it as is.
1608 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1611 if (WARN_ON(!arvif->is_started))
1614 if (WARN_ON(!arvif->is_up))
1617 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1620 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1622 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1623 arvif->vdev_id, ret);
1627 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1628 * firmware will crash upon vdev up.
1631 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1633 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1637 ret = ath10k_mac_setup_prb_tmpl(arvif);
1639 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1643 ret = ath10k_vdev_restart(arvif, &def);
1645 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1646 arvif->vdev_id, ret);
1650 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1653 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1654 arvif->vdev_id, ret);
1661 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1662 struct ieee80211_bss_conf *info)
1664 struct ath10k *ar = arvif->ar;
1667 lockdep_assert_held(&arvif->ar->conf_mutex);
1669 if (!info->enable_beacon) {
1670 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1672 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1673 arvif->vdev_id, ret);
1675 arvif->is_up = false;
1677 spin_lock_bh(&arvif->ar->data_lock);
1678 ath10k_mac_vif_beacon_free(arvif);
1679 spin_unlock_bh(&arvif->ar->data_lock);
1684 arvif->tx_seq_no = 0x1000;
1687 ether_addr_copy(arvif->bssid, info->bssid);
1689 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1692 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1693 arvif->vdev_id, ret);
1697 arvif->is_up = true;
1699 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1701 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1702 arvif->vdev_id, ret);
1706 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1709 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1710 struct ieee80211_bss_conf *info,
1711 const u8 self_peer[ETH_ALEN])
1713 struct ath10k *ar = arvif->ar;
1717 lockdep_assert_held(&arvif->ar->conf_mutex);
1719 if (!info->ibss_joined) {
1720 if (is_zero_ether_addr(arvif->bssid))
1723 eth_zero_addr(arvif->bssid);
1728 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1729 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1730 ATH10K_DEFAULT_ATIM);
1732 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1733 arvif->vdev_id, ret);
1736 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1738 struct ath10k *ar = arvif->ar;
1743 lockdep_assert_held(&arvif->ar->conf_mutex);
1745 if (arvif->u.sta.uapsd)
1746 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1748 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1750 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1751 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1753 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1754 value, arvif->vdev_id, ret);
1761 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1763 struct ath10k *ar = arvif->ar;
1768 lockdep_assert_held(&arvif->ar->conf_mutex);
1770 if (arvif->u.sta.uapsd)
1771 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1773 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1775 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1776 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1779 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1780 value, arvif->vdev_id, ret);
1787 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1789 struct ath10k_vif *arvif;
1792 lockdep_assert_held(&ar->conf_mutex);
1794 list_for_each_entry(arvif, &ar->arvifs, list)
1795 if (arvif->is_started)
1801 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1803 struct ath10k *ar = arvif->ar;
1804 struct ieee80211_vif *vif = arvif->vif;
1805 struct ieee80211_conf *conf = &ar->hw->conf;
1806 enum wmi_sta_powersave_param param;
1807 enum wmi_sta_ps_mode psmode;
1812 lockdep_assert_held(&arvif->ar->conf_mutex);
1814 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1817 enable_ps = arvif->ps;
1819 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1820 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1821 ar->running_fw->fw_file.fw_features)) {
1822 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1827 if (!arvif->is_started) {
1828 /* mac80211 can update vif powersave state while disconnected.
1829 * Firmware doesn't behave nicely and consumes more power than
1830 * necessary if PS is disabled on a non-started vdev. Hence
1831 * force-enable PS for non-running vdevs.
1833 psmode = WMI_STA_PS_MODE_ENABLED;
1834 } else if (enable_ps) {
1835 psmode = WMI_STA_PS_MODE_ENABLED;
1836 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1838 ps_timeout = conf->dynamic_ps_timeout;
1839 if (ps_timeout == 0) {
1840 /* Firmware doesn't like 0 */
1841 ps_timeout = ieee80211_tu_to_usec(
1842 vif->bss_conf.beacon_int) / 1000;
1845 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1848 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1849 arvif->vdev_id, ret);
1853 psmode = WMI_STA_PS_MODE_DISABLED;
1856 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1857 arvif->vdev_id, psmode ? "enable" : "disable");
1859 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1861 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1862 psmode, arvif->vdev_id, ret);
1869 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1871 struct ath10k *ar = arvif->ar;
1872 struct wmi_sta_keepalive_arg arg = {};
1875 lockdep_assert_held(&arvif->ar->conf_mutex);
1877 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1880 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1883 /* Some firmware revisions have a bug and ignore the `enabled` field.
1884 * Instead use the interval to disable the keepalive.
1886 arg.vdev_id = arvif->vdev_id;
1888 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1889 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1891 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1893 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1894 arvif->vdev_id, ret);
1901 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1903 struct ath10k *ar = arvif->ar;
1904 struct ieee80211_vif *vif = arvif->vif;
1907 lockdep_assert_held(&arvif->ar->conf_mutex);
1909 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1912 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1915 if (!vif->csa_active)
1921 if (!ieee80211_csa_is_complete(vif)) {
1922 ieee80211_csa_update_counter(vif);
1924 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1926 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1929 ret = ath10k_mac_setup_prb_tmpl(arvif);
1931 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1934 ieee80211_csa_finish(vif);
1938 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1940 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1942 struct ath10k *ar = arvif->ar;
1944 mutex_lock(&ar->conf_mutex);
1945 ath10k_mac_vif_ap_csa_count_down(arvif);
1946 mutex_unlock(&ar->conf_mutex);
1949 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1950 struct ieee80211_vif *vif)
1952 struct sk_buff *skb = data;
1953 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1954 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1956 if (vif->type != NL80211_IFTYPE_STATION)
1959 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1962 cancel_delayed_work(&arvif->connection_loss_work);
1965 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1967 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1968 IEEE80211_IFACE_ITER_NORMAL,
1969 ath10k_mac_handle_beacon_iter,
1973 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1974 struct ieee80211_vif *vif)
1976 u32 *vdev_id = data;
1977 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1978 struct ath10k *ar = arvif->ar;
1979 struct ieee80211_hw *hw = ar->hw;
1981 if (arvif->vdev_id != *vdev_id)
1987 ieee80211_beacon_loss(vif);
1989 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1990 * (done by mac80211) succeeds but beacons do not resume then it
1991 * doesn't make sense to continue operation. Queue connection loss work
1992 * which can be cancelled when beacon is received.
1994 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1995 ATH10K_CONNECTION_LOSS_HZ);
1998 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
2000 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2001 IEEE80211_IFACE_ITER_NORMAL,
2002 ath10k_mac_handle_beacon_miss_iter,
2006 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
2008 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2009 connection_loss_work.work);
2010 struct ieee80211_vif *vif = arvif->vif;
2015 ieee80211_connection_loss(vif);
2018 /**********************/
2019 /* Station management */
2020 /**********************/
2022 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
2023 struct ieee80211_vif *vif)
2025 /* Some firmware revisions have unstable STA powersave when listen
2026 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
2027 * generate NullFunc frames properly even if buffered frames have been
2028 * indicated in Beacon TIM. Firmware would seldom wake up to pull
2029 * buffered frames. Often pinging the device from AP would simply fail.
2031 * As a workaround set it to 1.
2033 if (vif->type == NL80211_IFTYPE_STATION)
2036 return ar->hw->conf.listen_interval;
2039 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
2040 struct ieee80211_vif *vif,
2041 struct ieee80211_sta *sta,
2042 struct wmi_peer_assoc_complete_arg *arg)
2044 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2047 lockdep_assert_held(&ar->conf_mutex);
2049 if (vif->type == NL80211_IFTYPE_STATION)
2050 aid = vif->bss_conf.aid;
2054 ether_addr_copy(arg->addr, sta->addr);
2055 arg->vdev_id = arvif->vdev_id;
2056 arg->peer_aid = aid;
2057 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2058 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2059 arg->peer_num_spatial_streams = 1;
2060 arg->peer_caps = vif->bss_conf.assoc_capability;
2063 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2064 struct ieee80211_vif *vif,
2065 struct ieee80211_sta *sta,
2066 struct wmi_peer_assoc_complete_arg *arg)
2068 struct ieee80211_bss_conf *info = &vif->bss_conf;
2069 struct cfg80211_chan_def def;
2070 struct cfg80211_bss *bss;
2071 const u8 *rsnie = NULL;
2072 const u8 *wpaie = NULL;
2074 lockdep_assert_held(&ar->conf_mutex);
2076 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2079 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2080 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2082 const struct cfg80211_bss_ies *ies;
2085 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2087 ies = rcu_dereference(bss->ies);
2089 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2090 WLAN_OUI_TYPE_MICROSOFT_WPA,
2094 cfg80211_put_bss(ar->hw->wiphy, bss);
2097 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2098 if (rsnie || wpaie) {
2099 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2100 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2104 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2105 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2109 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2110 ar->running_fw->fw_file.fw_features)) {
2111 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2115 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2116 struct ieee80211_vif *vif,
2117 struct ieee80211_sta *sta,
2118 struct wmi_peer_assoc_complete_arg *arg)
2120 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2121 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2122 struct cfg80211_chan_def def;
2123 const struct ieee80211_supported_band *sband;
2124 const struct ieee80211_rate *rates;
2125 enum nl80211_band band;
2130 lockdep_assert_held(&ar->conf_mutex);
2132 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2135 band = def.chan->band;
2136 sband = ar->hw->wiphy->bands[band];
2137 ratemask = sta->supp_rates[band];
2138 ratemask &= arvif->bitrate_mask.control[band].legacy;
2139 rates = sband->bitrates;
2141 rateset->num_rates = 0;
2143 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2144 if (!(ratemask & 1))
2147 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2148 rateset->rates[rateset->num_rates] = rate;
2149 rateset->num_rates++;
2154 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2158 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2159 if (ht_mcs_mask[nss])
2166 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2170 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2171 if (vht_mcs_mask[nss])
2177 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2178 struct ieee80211_vif *vif,
2179 struct ieee80211_sta *sta,
2180 struct wmi_peer_assoc_complete_arg *arg)
2182 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2183 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2184 struct cfg80211_chan_def def;
2185 enum nl80211_band band;
2186 const u8 *ht_mcs_mask;
2187 const u16 *vht_mcs_mask;
2192 lockdep_assert_held(&ar->conf_mutex);
2194 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2197 if (!ht_cap->ht_supported)
2200 band = def.chan->band;
2201 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2202 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2204 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2205 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2208 arg->peer_flags |= ar->wmi.peer_flags->ht;
2209 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2210 ht_cap->ampdu_factor)) - 1;
2212 arg->peer_mpdu_density =
2213 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2215 arg->peer_ht_caps = ht_cap->cap;
2216 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2218 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2219 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2221 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2222 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2223 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2226 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2227 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2228 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2230 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2231 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2234 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2235 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2236 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2239 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2240 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2241 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2242 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2243 arg->peer_rate_caps |= stbc;
2244 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2247 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2248 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2249 else if (ht_cap->mcs.rx_mask[1])
2250 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2252 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2253 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2254 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2255 max_nss = (i / 8) + 1;
2256 arg->peer_ht_rates.rates[n++] = i;
2260 * This is a workaround for HT-enabled STAs which break the spec
2261 * and have no HT capabilities RX mask (no HT RX MCS map).
2263 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2264 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2266 * Firmware asserts if such situation occurs.
2269 arg->peer_ht_rates.num_rates = 8;
2270 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2271 arg->peer_ht_rates.rates[i] = i;
2273 arg->peer_ht_rates.num_rates = n;
2274 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2277 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2279 arg->peer_ht_rates.num_rates,
2280 arg->peer_num_spatial_streams);
2283 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2284 struct ath10k_vif *arvif,
2285 struct ieee80211_sta *sta)
2291 lockdep_assert_held(&ar->conf_mutex);
2293 if (sta->wme && sta->uapsd_queues) {
2294 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2295 sta->uapsd_queues, sta->max_sp);
2297 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2298 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2299 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2300 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2301 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2302 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2303 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2304 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2305 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2306 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2307 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2308 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2310 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2311 max_sp = sta->max_sp;
2313 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2315 WMI_AP_PS_PEER_PARAM_UAPSD,
2318 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2319 arvif->vdev_id, ret);
2323 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2325 WMI_AP_PS_PEER_PARAM_MAX_SP,
2328 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2329 arvif->vdev_id, ret);
2333 /* TODO setup this based on STA listen interval and
2334 beacon interval. Currently we don't know
2335 sta->listen_interval - mac80211 patch required.
2336 Currently use 10 seconds */
2337 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2338 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2341 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2342 arvif->vdev_id, ret);
2351 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2352 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2359 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2360 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2364 idx_limit = fls(mcs_map) - 1;
2368 switch (idx_limit) {
2369 case 0: /* fall through */
2370 case 1: /* fall through */
2371 case 2: /* fall through */
2372 case 3: /* fall through */
2373 case 4: /* fall through */
2374 case 5: /* fall through */
2375 case 6: /* fall through */
2377 /* see ath10k_mac_can_set_bitrate_mask() */
2381 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2384 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2387 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2390 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2394 tx_mcs_set &= ~(0x3 << (nss * 2));
2395 tx_mcs_set |= mcs << (nss * 2);
2401 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2402 struct ieee80211_vif *vif,
2403 struct ieee80211_sta *sta,
2404 struct wmi_peer_assoc_complete_arg *arg)
2406 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2407 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2408 struct cfg80211_chan_def def;
2409 enum nl80211_band band;
2410 const u16 *vht_mcs_mask;
2413 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2416 if (!vht_cap->vht_supported)
2419 band = def.chan->band;
2420 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2422 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2425 arg->peer_flags |= ar->wmi.peer_flags->vht;
2427 if (def.chan->band == NL80211_BAND_2GHZ)
2428 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2430 arg->peer_vht_caps = vht_cap->cap;
2432 ampdu_factor = (vht_cap->cap &
2433 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2434 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2436 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2437 * zero in VHT IE. Using it would result in degraded throughput.
2438 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2439 * it if VHT max_mpdu is smaller. */
2440 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2441 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2442 ampdu_factor)) - 1);
2444 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2445 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2447 arg->peer_vht_rates.rx_max_rate =
2448 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2449 arg->peer_vht_rates.rx_mcs_set =
2450 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2451 arg->peer_vht_rates.tx_max_rate =
2452 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2453 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2454 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2456 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2457 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2460 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2461 struct ieee80211_vif *vif,
2462 struct ieee80211_sta *sta,
2463 struct wmi_peer_assoc_complete_arg *arg)
2465 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2467 switch (arvif->vdev_type) {
2468 case WMI_VDEV_TYPE_AP:
2470 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2472 if (sta->wme && sta->uapsd_queues) {
2473 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2474 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2477 case WMI_VDEV_TYPE_STA:
2478 if (vif->bss_conf.qos)
2479 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2481 case WMI_VDEV_TYPE_IBSS:
2483 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2489 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2490 sta->addr, !!(arg->peer_flags &
2491 arvif->ar->wmi.peer_flags->qos));
2494 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2496 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2497 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2500 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2501 struct ieee80211_vif *vif,
2502 struct ieee80211_sta *sta,
2503 struct wmi_peer_assoc_complete_arg *arg)
2505 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2506 struct cfg80211_chan_def def;
2507 enum nl80211_band band;
2508 const u8 *ht_mcs_mask;
2509 const u16 *vht_mcs_mask;
2510 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2512 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2515 band = def.chan->band;
2516 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2517 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2520 case NL80211_BAND_2GHZ:
2521 if (sta->vht_cap.vht_supported &&
2522 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2523 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2524 phymode = MODE_11AC_VHT40;
2526 phymode = MODE_11AC_VHT20;
2527 } else if (sta->ht_cap.ht_supported &&
2528 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2529 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2530 phymode = MODE_11NG_HT40;
2532 phymode = MODE_11NG_HT20;
2533 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2540 case NL80211_BAND_5GHZ:
2544 if (sta->vht_cap.vht_supported &&
2545 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2546 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2547 phymode = MODE_11AC_VHT80;
2548 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2549 phymode = MODE_11AC_VHT40;
2550 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2551 phymode = MODE_11AC_VHT20;
2552 } else if (sta->ht_cap.ht_supported &&
2553 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2554 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2555 phymode = MODE_11NA_HT40;
2557 phymode = MODE_11NA_HT20;
2567 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2568 sta->addr, ath10k_wmi_phymode_str(phymode));
2570 arg->peer_phymode = phymode;
2571 WARN_ON(phymode == MODE_UNKNOWN);
2574 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2575 struct ieee80211_vif *vif,
2576 struct ieee80211_sta *sta,
2577 struct wmi_peer_assoc_complete_arg *arg)
2579 lockdep_assert_held(&ar->conf_mutex);
2581 memset(arg, 0, sizeof(*arg));
2583 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2584 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2585 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2586 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2587 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2588 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2589 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2594 static const u32 ath10k_smps_map[] = {
2595 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2596 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2597 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2598 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2601 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2603 const struct ieee80211_sta_ht_cap *ht_cap)
2607 if (!ht_cap->ht_supported)
2610 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2611 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2613 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2616 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2617 WMI_PEER_SMPS_STATE,
2618 ath10k_smps_map[smps]);
2621 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2622 struct ieee80211_vif *vif,
2623 struct ieee80211_sta_vht_cap vht_cap)
2625 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2630 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2633 if (!(ar->vht_cap_info &
2634 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2635 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2636 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2637 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2640 param = ar->wmi.vdev_param->txbf;
2643 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2646 /* The following logic is correct. If a remote STA advertises support
2647 * for being a beamformer then we should enable us being a beamformee.
2650 if (ar->vht_cap_info &
2651 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2652 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2653 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2654 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2656 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2657 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2660 if (ar->vht_cap_info &
2661 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2662 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2663 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2664 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2666 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2667 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2670 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2671 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2673 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2674 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2676 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2678 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2686 /* can be called only in mac80211 callbacks due to `key_count` usage */
2687 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2688 struct ieee80211_vif *vif,
2689 struct ieee80211_bss_conf *bss_conf)
2691 struct ath10k *ar = hw->priv;
2692 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2693 struct ieee80211_sta_ht_cap ht_cap;
2694 struct ieee80211_sta_vht_cap vht_cap;
2695 struct wmi_peer_assoc_complete_arg peer_arg;
2696 struct ieee80211_sta *ap_sta;
2699 lockdep_assert_held(&ar->conf_mutex);
2701 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2702 arvif->vdev_id, arvif->bssid, arvif->aid);
2706 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2708 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2709 bss_conf->bssid, arvif->vdev_id);
2714 /* ap_sta must be accessed only within rcu section which must be left
2715 * before calling ath10k_setup_peer_smps() which might sleep. */
2716 ht_cap = ap_sta->ht_cap;
2717 vht_cap = ap_sta->vht_cap;
2719 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2721 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2722 bss_conf->bssid, arvif->vdev_id, ret);
2729 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2731 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2732 bss_conf->bssid, arvif->vdev_id, ret);
2736 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2738 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2739 arvif->vdev_id, ret);
2743 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2745 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2746 arvif->vdev_id, bss_conf->bssid, ret);
2750 ath10k_dbg(ar, ATH10K_DBG_MAC,
2751 "mac vdev %d up (associated) bssid %pM aid %d\n",
2752 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2754 WARN_ON(arvif->is_up);
2756 arvif->aid = bss_conf->aid;
2757 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2759 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2761 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2762 arvif->vdev_id, ret);
2766 arvif->is_up = true;
2768 /* Workaround: Some firmware revisions (tested with qca6174
2769 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2770 * poked with peer param command.
2772 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2773 WMI_PEER_DUMMY_VAR, 1);
2775 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2776 arvif->bssid, arvif->vdev_id, ret);
2781 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2782 struct ieee80211_vif *vif)
2784 struct ath10k *ar = hw->priv;
2785 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2786 struct ieee80211_sta_vht_cap vht_cap = {};
2789 lockdep_assert_held(&ar->conf_mutex);
2791 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2792 arvif->vdev_id, arvif->bssid);
2794 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2796 ath10k_warn(ar, "failed to down vdev %i: %d\n",
2797 arvif->vdev_id, ret);
2799 arvif->def_wep_key_idx = -1;
2801 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2803 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2804 arvif->vdev_id, ret);
2808 arvif->is_up = false;
2810 cancel_delayed_work_sync(&arvif->connection_loss_work);
2813 static int ath10k_station_assoc(struct ath10k *ar,
2814 struct ieee80211_vif *vif,
2815 struct ieee80211_sta *sta,
2818 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2819 struct wmi_peer_assoc_complete_arg peer_arg;
2822 lockdep_assert_held(&ar->conf_mutex);
2824 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2826 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2827 sta->addr, arvif->vdev_id, ret);
2831 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2833 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2834 sta->addr, arvif->vdev_id, ret);
2838 /* Re-assoc is run only to update supported rates for given station. It
2839 * doesn't make much sense to reconfigure the peer completely.
2842 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2845 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2846 arvif->vdev_id, ret);
2850 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2852 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2853 sta->addr, arvif->vdev_id, ret);
2858 arvif->num_legacy_stations++;
2859 ret = ath10k_recalc_rtscts_prot(arvif);
2861 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2862 arvif->vdev_id, ret);
2867 /* Plumb cached keys only for static WEP */
2868 if (arvif->def_wep_key_idx != -1) {
2869 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2871 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2872 arvif->vdev_id, ret);
2881 static int ath10k_station_disassoc(struct ath10k *ar,
2882 struct ieee80211_vif *vif,
2883 struct ieee80211_sta *sta)
2885 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2888 lockdep_assert_held(&ar->conf_mutex);
2891 arvif->num_legacy_stations--;
2892 ret = ath10k_recalc_rtscts_prot(arvif);
2894 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2895 arvif->vdev_id, ret);
2900 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2902 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2903 arvif->vdev_id, ret);
2914 static int ath10k_update_channel_list(struct ath10k *ar)
2916 struct ieee80211_hw *hw = ar->hw;
2917 struct ieee80211_supported_band **bands;
2918 enum nl80211_band band;
2919 struct ieee80211_channel *channel;
2920 struct wmi_scan_chan_list_arg arg = {0};
2921 struct wmi_channel_arg *ch;
2927 lockdep_assert_held(&ar->conf_mutex);
2929 bands = hw->wiphy->bands;
2930 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2934 for (i = 0; i < bands[band]->n_channels; i++) {
2935 if (bands[band]->channels[i].flags &
2936 IEEE80211_CHAN_DISABLED)
2943 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2944 arg.channels = kzalloc(len, GFP_KERNEL);
2949 for (band = 0; band < NUM_NL80211_BANDS; band++) {
2953 for (i = 0; i < bands[band]->n_channels; i++) {
2954 channel = &bands[band]->channels[i];
2956 if (channel->flags & IEEE80211_CHAN_DISABLED)
2959 ch->allow_ht = true;
2961 /* FIXME: when should we really allow VHT? */
2962 ch->allow_vht = true;
2965 !(channel->flags & IEEE80211_CHAN_NO_IR);
2968 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2971 !!(channel->flags & IEEE80211_CHAN_RADAR);
2973 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2974 ch->passive = passive;
2976 ch->freq = channel->center_freq;
2977 ch->band_center_freq1 = channel->center_freq;
2979 ch->max_power = channel->max_power * 2;
2980 ch->max_reg_power = channel->max_reg_power * 2;
2981 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2982 ch->reg_class_id = 0; /* FIXME */
2984 /* FIXME: why use only legacy modes, why not any
2985 * HT/VHT modes? Would that even make any
2987 if (channel->band == NL80211_BAND_2GHZ)
2988 ch->mode = MODE_11G;
2990 ch->mode = MODE_11A;
2992 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2995 ath10k_dbg(ar, ATH10K_DBG_WMI,
2996 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2997 ch - arg.channels, arg.n_channels,
2998 ch->freq, ch->max_power, ch->max_reg_power,
2999 ch->max_antenna_gain, ch->mode);
3005 ret = ath10k_wmi_scan_chan_list(ar, &arg);
3006 kfree(arg.channels);
3011 static enum wmi_dfs_region
3012 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
3014 switch (dfs_region) {
3015 case NL80211_DFS_UNSET:
3016 return WMI_UNINIT_DFS_DOMAIN;
3017 case NL80211_DFS_FCC:
3018 return WMI_FCC_DFS_DOMAIN;
3019 case NL80211_DFS_ETSI:
3020 return WMI_ETSI_DFS_DOMAIN;
3021 case NL80211_DFS_JP:
3022 return WMI_MKK4_DFS_DOMAIN;
3024 return WMI_UNINIT_DFS_DOMAIN;
3027 static void ath10k_regd_update(struct ath10k *ar)
3029 struct reg_dmn_pair_mapping *regpair;
3031 enum wmi_dfs_region wmi_dfs_reg;
3032 enum nl80211_dfs_regions nl_dfs_reg;
3034 lockdep_assert_held(&ar->conf_mutex);
3036 ret = ath10k_update_channel_list(ar);
3038 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
3040 regpair = ar->ath_common.regulatory.regpair;
3042 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3043 nl_dfs_reg = ar->dfs_detector->region;
3044 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3046 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3049 /* Target allows setting up per-band regdomain but ath_common provides
3050 * a combined one only */
3051 ret = ath10k_wmi_pdev_set_regdomain(ar,
3052 regpair->reg_domain,
3053 regpair->reg_domain, /* 2ghz */
3054 regpair->reg_domain, /* 5ghz */
3055 regpair->reg_2ghz_ctl,
3056 regpair->reg_5ghz_ctl,
3059 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3062 static void ath10k_reg_notifier(struct wiphy *wiphy,
3063 struct regulatory_request *request)
3065 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3066 struct ath10k *ar = hw->priv;
3069 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3071 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3072 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3073 request->dfs_region);
3074 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3075 request->dfs_region);
3077 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3078 request->dfs_region);
3081 mutex_lock(&ar->conf_mutex);
3082 if (ar->state == ATH10K_STATE_ON)
3083 ath10k_regd_update(ar);
3084 mutex_unlock(&ar->conf_mutex);
3091 enum ath10k_mac_tx_path {
3093 ATH10K_MAC_TX_HTT_MGMT,
3094 ATH10K_MAC_TX_WMI_MGMT,
3095 ATH10K_MAC_TX_UNKNOWN,
3098 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3100 lockdep_assert_held(&ar->htt.tx_lock);
3102 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3103 ar->tx_paused |= BIT(reason);
3104 ieee80211_stop_queues(ar->hw);
3107 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3108 struct ieee80211_vif *vif)
3110 struct ath10k *ar = data;
3111 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3113 if (arvif->tx_paused)
3116 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3119 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3121 lockdep_assert_held(&ar->htt.tx_lock);
3123 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3124 ar->tx_paused &= ~BIT(reason);
3129 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3130 IEEE80211_IFACE_ITER_RESUME_ALL,
3131 ath10k_mac_tx_unlock_iter,
3134 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3137 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3139 struct ath10k *ar = arvif->ar;
3141 lockdep_assert_held(&ar->htt.tx_lock);
3143 WARN_ON(reason >= BITS_PER_LONG);
3144 arvif->tx_paused |= BIT(reason);
3145 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3148 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3150 struct ath10k *ar = arvif->ar;
3152 lockdep_assert_held(&ar->htt.tx_lock);
3154 WARN_ON(reason >= BITS_PER_LONG);
3155 arvif->tx_paused &= ~BIT(reason);
3160 if (arvif->tx_paused)
3163 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3166 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3167 enum wmi_tlv_tx_pause_id pause_id,
3168 enum wmi_tlv_tx_pause_action action)
3170 struct ath10k *ar = arvif->ar;
3172 lockdep_assert_held(&ar->htt.tx_lock);
3175 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3176 ath10k_mac_vif_tx_lock(arvif, pause_id);
3178 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3179 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3182 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3183 action, arvif->vdev_id);
3188 struct ath10k_mac_tx_pause {
3190 enum wmi_tlv_tx_pause_id pause_id;
3191 enum wmi_tlv_tx_pause_action action;
3194 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3195 struct ieee80211_vif *vif)
3197 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3198 struct ath10k_mac_tx_pause *arg = data;
3200 if (arvif->vdev_id != arg->vdev_id)
3203 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3206 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3207 enum wmi_tlv_tx_pause_id pause_id,
3208 enum wmi_tlv_tx_pause_action action)
3210 struct ath10k_mac_tx_pause arg = {
3212 .pause_id = pause_id,
3216 spin_lock_bh(&ar->htt.tx_lock);
3217 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3218 IEEE80211_IFACE_ITER_RESUME_ALL,
3219 ath10k_mac_handle_tx_pause_iter,
3221 spin_unlock_bh(&ar->htt.tx_lock);
3224 static enum ath10k_hw_txrx_mode
3225 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3226 struct ieee80211_vif *vif,
3227 struct ieee80211_sta *sta,
3228 struct sk_buff *skb)
3230 const struct ieee80211_hdr *hdr = (void *)skb->data;
3231 __le16 fc = hdr->frame_control;
3233 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3234 return ATH10K_HW_TXRX_RAW;
3236 if (ieee80211_is_mgmt(fc))
3237 return ATH10K_HW_TXRX_MGMT;
3241 * NullFunc frames are mostly used to ping if a client or AP are still
3242 * reachable and responsive. This implies tx status reports must be
3243 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3244 * come to a conclusion that the other end disappeared and tear down
3245 * BSS connection or it can never disconnect from BSS/client (which is
3248 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3249 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3250 * which seems to deliver correct tx reports for NullFunc frames. The
3251 * downside of using it is it ignores client powersave state so it can
3252 * end up disconnecting sleeping clients in AP mode. It should fix STA
3253 * mode though because AP don't sleep.
3255 if (ar->htt.target_version_major < 3 &&
3256 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3257 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3258 ar->running_fw->fw_file.fw_features))
3259 return ATH10K_HW_TXRX_MGMT;
3263 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3264 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3265 * to work with Ethernet txmode so use it.
3267 * FIXME: Check if raw mode works with TDLS.
3269 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3270 return ATH10K_HW_TXRX_ETHERNET;
3272 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3273 return ATH10K_HW_TXRX_RAW;
3275 return ATH10K_HW_TXRX_NATIVE_WIFI;
3278 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3279 struct sk_buff *skb)
3281 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3282 const struct ieee80211_hdr *hdr = (void *)skb->data;
3283 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3284 IEEE80211_TX_CTL_INJECTED;
3286 if (!ieee80211_has_protected(hdr->frame_control))
3289 if ((info->flags & mask) == mask)
3293 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3298 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3299 * Control in the header.
3301 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3303 struct ieee80211_hdr *hdr = (void *)skb->data;
3304 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3307 if (!ieee80211_is_data_qos(hdr->frame_control))
3310 qos_ctl = ieee80211_get_qos_ctl(hdr);
3311 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3312 skb->data, (void *)qos_ctl - (void *)skb->data);
3313 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3315 /* Some firmware revisions don't handle sending QoS NullFunc well.
3316 * These frames are mainly used for CQM purposes so it doesn't really
3317 * matter whether QoS NullFunc or NullFunc are sent.
3319 hdr = (void *)skb->data;
3320 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3321 cb->flags &= ~ATH10K_SKB_F_QOS;
3323 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3326 static void ath10k_tx_h_8023(struct sk_buff *skb)
3328 struct ieee80211_hdr *hdr;
3329 struct rfc1042_hdr *rfc1042;
3336 hdr = (void *)skb->data;
3337 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3338 rfc1042 = (void *)skb->data + hdrlen;
3340 ether_addr_copy(da, ieee80211_get_DA(hdr));
3341 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3342 type = rfc1042->snap_type;
3344 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3345 skb_push(skb, sizeof(*eth));
3347 eth = (void *)skb->data;
3348 ether_addr_copy(eth->h_dest, da);
3349 ether_addr_copy(eth->h_source, sa);
3350 eth->h_proto = type;
3353 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3354 struct ieee80211_vif *vif,
3355 struct sk_buff *skb)
3357 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3358 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3360 /* This is case only for P2P_GO */
3361 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3364 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3365 spin_lock_bh(&ar->data_lock);
3366 if (arvif->u.ap.noa_data)
3367 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3369 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3370 arvif->u.ap.noa_data,
3371 arvif->u.ap.noa_len);
3372 spin_unlock_bh(&ar->data_lock);
3376 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3377 struct ieee80211_vif *vif,
3378 struct ieee80211_txq *txq,
3379 struct sk_buff *skb)
3381 struct ieee80211_hdr *hdr = (void *)skb->data;
3382 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3385 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3386 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3388 if (ieee80211_is_mgmt(hdr->frame_control))
3389 cb->flags |= ATH10K_SKB_F_MGMT;
3391 if (ieee80211_is_data_qos(hdr->frame_control))
3392 cb->flags |= ATH10K_SKB_F_QOS;
3398 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3400 /* FIXME: Not really sure since when the behaviour changed. At some
3401 * point new firmware stopped requiring creation of peer entries for
3402 * offchannel tx (and actually creating them causes issues with wmi-htc
3403 * tx credit replenishment and reliability). Assuming it's at least 3.4
3404 * because that's when the `freq` was introduced to TX_FRM HTT command.
3406 return (ar->htt.target_version_major >= 3 &&
3407 ar->htt.target_version_minor >= 4 &&
3408 ar->running_fw->fw_file.htt_op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3411 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3413 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3416 spin_lock_bh(&ar->data_lock);
3418 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3419 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3424 __skb_queue_tail(q, skb);
3425 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3428 spin_unlock_bh(&ar->data_lock);
3433 static enum ath10k_mac_tx_path
3434 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3435 struct sk_buff *skb,
3436 enum ath10k_hw_txrx_mode txmode)
3439 case ATH10K_HW_TXRX_RAW:
3440 case ATH10K_HW_TXRX_NATIVE_WIFI:
3441 case ATH10K_HW_TXRX_ETHERNET:
3442 return ATH10K_MAC_TX_HTT;
3443 case ATH10K_HW_TXRX_MGMT:
3444 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3445 ar->running_fw->fw_file.fw_features))
3446 return ATH10K_MAC_TX_WMI_MGMT;
3447 else if (ar->htt.target_version_major >= 3)
3448 return ATH10K_MAC_TX_HTT;
3450 return ATH10K_MAC_TX_HTT_MGMT;
3453 return ATH10K_MAC_TX_UNKNOWN;
3456 static int ath10k_mac_tx_submit(struct ath10k *ar,
3457 enum ath10k_hw_txrx_mode txmode,
3458 enum ath10k_mac_tx_path txpath,
3459 struct sk_buff *skb)
3461 struct ath10k_htt *htt = &ar->htt;
3465 case ATH10K_MAC_TX_HTT:
3466 ret = ath10k_htt_tx(htt, txmode, skb);
3468 case ATH10K_MAC_TX_HTT_MGMT:
3469 ret = ath10k_htt_mgmt_tx(htt, skb);
3471 case ATH10K_MAC_TX_WMI_MGMT:
3472 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3474 case ATH10K_MAC_TX_UNKNOWN:
3481 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3483 ieee80211_free_txskb(ar->hw, skb);
3489 /* This function consumes the sk_buff regardless of return value as far as
3490 * caller is concerned so no freeing is necessary afterwards.
3492 static int ath10k_mac_tx(struct ath10k *ar,
3493 struct ieee80211_vif *vif,
3494 struct ieee80211_sta *sta,
3495 enum ath10k_hw_txrx_mode txmode,
3496 enum ath10k_mac_tx_path txpath,
3497 struct sk_buff *skb)
3499 struct ieee80211_hw *hw = ar->hw;
3500 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3503 /* We should disable CCK RATE due to P2P */
3504 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3505 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3508 case ATH10K_HW_TXRX_MGMT:
3509 case ATH10K_HW_TXRX_NATIVE_WIFI:
3510 ath10k_tx_h_nwifi(hw, skb);
3511 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3512 ath10k_tx_h_seq_no(vif, skb);
3514 case ATH10K_HW_TXRX_ETHERNET:
3515 ath10k_tx_h_8023(skb);
3517 case ATH10K_HW_TXRX_RAW:
3518 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3520 ieee80211_free_txskb(hw, skb);
3525 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3526 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3527 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %pK\n",
3530 skb_queue_tail(&ar->offchan_tx_queue, skb);
3531 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3536 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3538 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3545 void ath10k_offchan_tx_purge(struct ath10k *ar)
3547 struct sk_buff *skb;
3550 skb = skb_dequeue(&ar->offchan_tx_queue);
3554 ieee80211_free_txskb(ar->hw, skb);
3558 void ath10k_offchan_tx_work(struct work_struct *work)
3560 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3561 struct ath10k_peer *peer;
3562 struct ath10k_vif *arvif;
3563 enum ath10k_hw_txrx_mode txmode;
3564 enum ath10k_mac_tx_path txpath;
3565 struct ieee80211_hdr *hdr;
3566 struct ieee80211_vif *vif;
3567 struct ieee80211_sta *sta;
3568 struct sk_buff *skb;
3569 const u8 *peer_addr;
3572 unsigned long time_left;
3573 bool tmp_peer_created = false;
3575 /* FW requirement: We must create a peer before FW will send out
3576 * an offchannel frame. Otherwise the frame will be stuck and
3577 * never transmitted. We delete the peer upon tx completion.
3578 * It is unlikely that a peer for offchannel tx will already be
3579 * present. However it may be in some rare cases so account for that.
3580 * Otherwise we might remove a legitimate peer and break stuff. */
3583 skb = skb_dequeue(&ar->offchan_tx_queue);
3587 mutex_lock(&ar->conf_mutex);
3589 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %pK\n",
3592 hdr = (struct ieee80211_hdr *)skb->data;
3593 peer_addr = ieee80211_get_DA(hdr);
3595 spin_lock_bh(&ar->data_lock);
3596 vdev_id = ar->scan.vdev_id;
3597 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3598 spin_unlock_bh(&ar->data_lock);
3601 /* FIXME: should this use ath10k_warn()? */
3602 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3603 peer_addr, vdev_id);
3606 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3608 WMI_PEER_TYPE_DEFAULT);
3610 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3611 peer_addr, vdev_id, ret);
3612 tmp_peer_created = (ret == 0);
3615 spin_lock_bh(&ar->data_lock);
3616 reinit_completion(&ar->offchan_tx_completed);
3617 ar->offchan_tx_skb = skb;
3618 spin_unlock_bh(&ar->data_lock);
3620 /* It's safe to access vif and sta - conf_mutex guarantees that
3621 * sta_state() and remove_interface() are locked exclusively
3622 * out wrt to this offchannel worker.
3624 arvif = ath10k_get_arvif(ar, vdev_id);
3627 sta = ieee80211_find_sta(vif, peer_addr);
3633 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3634 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3636 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3638 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3644 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3646 ath10k_warn(ar, "timed out waiting for offchannel skb %pK\n",
3649 if (!peer && tmp_peer_created) {
3650 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3652 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3653 peer_addr, vdev_id, ret);
3656 mutex_unlock(&ar->conf_mutex);
3660 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3662 struct sk_buff *skb;
3665 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3669 ieee80211_free_txskb(ar->hw, skb);
3673 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3675 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3676 struct sk_buff *skb;
3680 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3684 ret = ath10k_wmi_mgmt_tx(ar, skb);
3686 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3688 ieee80211_free_txskb(ar->hw, skb);
3693 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3695 struct ath10k_txq *artxq;
3700 artxq = (void *)txq->drv_priv;
3701 INIT_LIST_HEAD(&artxq->list);
3704 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3706 struct ath10k_txq *artxq;
3707 struct ath10k_skb_cb *cb;
3708 struct sk_buff *msdu;
3714 artxq = (void *)txq->drv_priv;
3715 spin_lock_bh(&ar->txqs_lock);
3716 if (!list_empty(&artxq->list))
3717 list_del_init(&artxq->list);
3718 spin_unlock_bh(&ar->txqs_lock);
3720 spin_lock_bh(&ar->htt.tx_lock);
3721 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3722 cb = ATH10K_SKB_CB(msdu);
3726 spin_unlock_bh(&ar->htt.tx_lock);
3729 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3733 struct ath10k_peer *peer;
3735 lockdep_assert_held(&ar->data_lock);
3737 peer = ar->peer_map[peer_id];
3742 return peer->sta->txq[tid];
3744 return peer->vif->txq;
3749 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3750 struct ieee80211_txq *txq)
3752 struct ath10k *ar = hw->priv;
3753 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3755 /* No need to get locks */
3757 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3760 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3763 if (artxq->num_fw_queued < artxq->num_push_allowed)
3769 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3770 struct ieee80211_txq *txq)
3772 struct ath10k *ar = hw->priv;
3773 struct ath10k_htt *htt = &ar->htt;
3774 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3775 struct ieee80211_vif *vif = txq->vif;
3776 struct ieee80211_sta *sta = txq->sta;
3777 enum ath10k_hw_txrx_mode txmode;
3778 enum ath10k_mac_tx_path txpath;
3779 struct sk_buff *skb;
3780 struct ieee80211_hdr *hdr;
3782 bool is_mgmt, is_presp;
3785 spin_lock_bh(&ar->htt.tx_lock);
3786 ret = ath10k_htt_tx_inc_pending(htt);
3787 spin_unlock_bh(&ar->htt.tx_lock);
3792 skb = ieee80211_tx_dequeue(hw, txq);
3794 spin_lock_bh(&ar->htt.tx_lock);
3795 ath10k_htt_tx_dec_pending(htt);
3796 spin_unlock_bh(&ar->htt.tx_lock);
3801 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3804 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3805 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3806 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
3809 hdr = (struct ieee80211_hdr *)skb->data;
3810 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3812 spin_lock_bh(&ar->htt.tx_lock);
3813 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
3816 ath10k_htt_tx_dec_pending(htt);
3817 spin_unlock_bh(&ar->htt.tx_lock);
3820 spin_unlock_bh(&ar->htt.tx_lock);
3823 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3824 if (unlikely(ret)) {
3825 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3827 spin_lock_bh(&ar->htt.tx_lock);
3828 ath10k_htt_tx_dec_pending(htt);
3830 ath10k_htt_tx_mgmt_dec_pending(htt);
3831 spin_unlock_bh(&ar->htt.tx_lock);
3836 spin_lock_bh(&ar->htt.tx_lock);
3837 artxq->num_fw_queued++;
3838 spin_unlock_bh(&ar->htt.tx_lock);
3843 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3845 struct ieee80211_hw *hw = ar->hw;
3846 struct ieee80211_txq *txq;
3847 struct ath10k_txq *artxq;
3848 struct ath10k_txq *last;
3852 if (ar->htt.num_pending_tx >= (ar->htt.max_num_pending_tx / 2))
3855 spin_lock_bh(&ar->txqs_lock);
3858 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3859 while (!list_empty(&ar->txqs)) {
3860 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3861 txq = container_of((void *)artxq, struct ieee80211_txq,
3864 /* Prevent aggressive sta/tid taking over tx queue */
3867 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3868 ret = ath10k_mac_tx_push_txq(hw, txq);
3873 list_del_init(&artxq->list);
3875 list_add_tail(&artxq->list, &ar->txqs);
3877 ath10k_htt_tx_txq_update(hw, txq);
3879 if (artxq == last || (ret < 0 && ret != -ENOENT))
3884 spin_unlock_bh(&ar->txqs_lock);
3891 void __ath10k_scan_finish(struct ath10k *ar)
3893 lockdep_assert_held(&ar->data_lock);
3895 switch (ar->scan.state) {
3896 case ATH10K_SCAN_IDLE:
3898 case ATH10K_SCAN_RUNNING:
3899 case ATH10K_SCAN_ABORTING:
3900 if (!ar->scan.is_roc) {
3901 struct cfg80211_scan_info info = {
3902 .aborted = (ar->scan.state ==
3903 ATH10K_SCAN_ABORTING),
3906 ieee80211_scan_completed(ar->hw, &info);
3907 } else if (ar->scan.roc_notify) {
3908 ieee80211_remain_on_channel_expired(ar->hw);
3911 case ATH10K_SCAN_STARTING:
3912 ar->scan.state = ATH10K_SCAN_IDLE;
3913 ar->scan_channel = NULL;
3914 ar->scan.roc_freq = 0;
3915 ath10k_offchan_tx_purge(ar);
3916 cancel_delayed_work(&ar->scan.timeout);
3917 complete(&ar->scan.completed);
3922 void ath10k_scan_finish(struct ath10k *ar)
3924 spin_lock_bh(&ar->data_lock);
3925 __ath10k_scan_finish(ar);
3926 spin_unlock_bh(&ar->data_lock);
3929 static int ath10k_scan_stop(struct ath10k *ar)
3931 struct wmi_stop_scan_arg arg = {
3932 .req_id = 1, /* FIXME */
3933 .req_type = WMI_SCAN_STOP_ONE,
3934 .u.scan_id = ATH10K_SCAN_ID,
3938 lockdep_assert_held(&ar->conf_mutex);
3940 ret = ath10k_wmi_stop_scan(ar, &arg);
3942 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3946 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
3948 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3950 } else if (ret > 0) {
3955 /* Scan state should be updated upon scan completion but in case
3956 * firmware fails to deliver the event (for whatever reason) it is
3957 * desired to clean up scan state anyway. Firmware may have just
3958 * dropped the scan completion event delivery due to transport pipe
3959 * being overflown with data and/or it can recover on its own before
3960 * next scan request is submitted.
3962 spin_lock_bh(&ar->data_lock);
3963 if (ar->scan.state != ATH10K_SCAN_IDLE)
3964 __ath10k_scan_finish(ar);
3965 spin_unlock_bh(&ar->data_lock);
3970 static void ath10k_scan_abort(struct ath10k *ar)
3974 lockdep_assert_held(&ar->conf_mutex);
3976 spin_lock_bh(&ar->data_lock);
3978 switch (ar->scan.state) {
3979 case ATH10K_SCAN_IDLE:
3980 /* This can happen if timeout worker kicked in and called
3981 * abortion while scan completion was being processed.
3984 case ATH10K_SCAN_STARTING:
3985 case ATH10K_SCAN_ABORTING:
3986 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3987 ath10k_scan_state_str(ar->scan.state),
3990 case ATH10K_SCAN_RUNNING:
3991 ar->scan.state = ATH10K_SCAN_ABORTING;
3992 spin_unlock_bh(&ar->data_lock);
3994 ret = ath10k_scan_stop(ar);
3996 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3998 spin_lock_bh(&ar->data_lock);
4002 spin_unlock_bh(&ar->data_lock);
4005 void ath10k_scan_timeout_work(struct work_struct *work)
4007 struct ath10k *ar = container_of(work, struct ath10k,
4010 mutex_lock(&ar->conf_mutex);
4011 ath10k_scan_abort(ar);
4012 mutex_unlock(&ar->conf_mutex);
4015 static int ath10k_start_scan(struct ath10k *ar,
4016 const struct wmi_start_scan_arg *arg)
4020 lockdep_assert_held(&ar->conf_mutex);
4022 ret = ath10k_wmi_start_scan(ar, arg);
4026 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
4028 ret = ath10k_scan_stop(ar);
4030 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4035 /* If we failed to start the scan, return error code at
4036 * this point. This is probably due to some issue in the
4037 * firmware, but no need to wedge the driver due to that...
4039 spin_lock_bh(&ar->data_lock);
4040 if (ar->scan.state == ATH10K_SCAN_IDLE) {
4041 spin_unlock_bh(&ar->data_lock);
4044 spin_unlock_bh(&ar->data_lock);
4049 /**********************/
4050 /* mac80211 callbacks */
4051 /**********************/
4053 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
4054 struct ieee80211_tx_control *control,
4055 struct sk_buff *skb)
4057 struct ath10k *ar = hw->priv;
4058 struct ath10k_htt *htt = &ar->htt;
4059 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4060 struct ieee80211_vif *vif = info->control.vif;
4061 struct ieee80211_sta *sta = control->sta;
4062 struct ieee80211_txq *txq = NULL;
4063 struct ieee80211_hdr *hdr = (void *)skb->data;
4064 enum ath10k_hw_txrx_mode txmode;
4065 enum ath10k_mac_tx_path txpath;
4071 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
4073 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
4074 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4075 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4076 txpath == ATH10K_MAC_TX_HTT_MGMT);
4077 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4080 spin_lock_bh(&ar->htt.tx_lock);
4081 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4083 ret = ath10k_htt_tx_inc_pending(htt);
4085 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4087 spin_unlock_bh(&ar->htt.tx_lock);
4088 ieee80211_free_txskb(ar->hw, skb);
4092 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4094 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4096 ath10k_htt_tx_dec_pending(htt);
4097 spin_unlock_bh(&ar->htt.tx_lock);
4098 ieee80211_free_txskb(ar->hw, skb);
4101 spin_unlock_bh(&ar->htt.tx_lock);
4104 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
4106 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4108 spin_lock_bh(&ar->htt.tx_lock);
4109 ath10k_htt_tx_dec_pending(htt);
4111 ath10k_htt_tx_mgmt_dec_pending(htt);
4112 spin_unlock_bh(&ar->htt.tx_lock);
4118 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4119 struct ieee80211_txq *txq)
4121 struct ath10k *ar = hw->priv;
4122 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4123 struct ieee80211_txq *f_txq;
4124 struct ath10k_txq *f_artxq;
4128 spin_lock_bh(&ar->txqs_lock);
4129 if (list_empty(&artxq->list))
4130 list_add_tail(&artxq->list, &ar->txqs);
4132 f_artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
4133 f_txq = container_of((void *)f_artxq, struct ieee80211_txq, drv_priv);
4134 list_del_init(&f_artxq->list);
4136 while (ath10k_mac_tx_can_push(hw, f_txq) && max--) {
4137 ret = ath10k_mac_tx_push_txq(hw, f_txq);
4142 list_add_tail(&f_artxq->list, &ar->txqs);
4143 spin_unlock_bh(&ar->txqs_lock);
4145 ath10k_htt_tx_txq_update(hw, f_txq);
4146 ath10k_htt_tx_txq_update(hw, txq);
4149 /* Must not be called with conf_mutex held as workers can use that also. */
4150 void ath10k_drain_tx(struct ath10k *ar)
4152 /* make sure rcu-protected mac80211 tx path itself is drained */
4155 ath10k_offchan_tx_purge(ar);
4156 ath10k_mgmt_over_wmi_tx_purge(ar);
4158 cancel_work_sync(&ar->offchan_tx_work);
4159 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4162 void ath10k_halt(struct ath10k *ar)
4164 struct ath10k_vif *arvif;
4166 lockdep_assert_held(&ar->conf_mutex);
4168 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4169 ar->filter_flags = 0;
4170 ar->monitor = false;
4171 ar->monitor_arvif = NULL;
4173 if (ar->monitor_started)
4174 ath10k_monitor_stop(ar);
4176 ar->monitor_started = false;
4179 ath10k_scan_finish(ar);
4180 ath10k_peer_cleanup_all(ar);
4181 ath10k_core_stop(ar);
4182 ath10k_hif_power_down(ar);
4184 spin_lock_bh(&ar->data_lock);
4185 list_for_each_entry(arvif, &ar->arvifs, list)
4186 ath10k_mac_vif_beacon_cleanup(arvif);
4187 spin_unlock_bh(&ar->data_lock);
4190 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4192 struct ath10k *ar = hw->priv;
4194 mutex_lock(&ar->conf_mutex);
4196 *tx_ant = ar->cfg_tx_chainmask;
4197 *rx_ant = ar->cfg_rx_chainmask;
4199 mutex_unlock(&ar->conf_mutex);
4204 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4206 /* It is not clear that allowing gaps in chainmask
4207 * is helpful. Probably it will not do what user
4208 * is hoping for, so warn in that case.
4210 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4213 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4217 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4219 int nsts = ar->vht_cap_info;
4221 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4222 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4224 /* If firmware does not deliver to host number of space-time
4225 * streams supported, assume it support up to 4 BF STS and return
4226 * the value for VHT CAP: nsts-1)
4234 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4236 int sound_dim = ar->vht_cap_info;
4238 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4239 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4241 /* If the sounding dimension is not advertised by the firmware,
4242 * let's use a default value of 1
4250 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4252 struct ieee80211_sta_vht_cap vht_cap = {0};
4257 vht_cap.vht_supported = 1;
4258 vht_cap.cap = ar->vht_cap_info;
4260 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4261 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4262 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4263 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4264 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4269 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4270 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4271 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4272 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4273 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4279 for (i = 0; i < 8; i++) {
4280 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4281 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4283 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4286 if (ar->cfg_tx_chainmask <= 1)
4287 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
4289 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4290 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4295 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4298 struct ieee80211_sta_ht_cap ht_cap = {0};
4300 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4303 ht_cap.ht_supported = 1;
4304 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4305 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4306 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4307 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4309 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4311 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4312 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4314 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4315 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4317 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4320 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4321 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4326 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC && (ar->cfg_tx_chainmask > 1))
4327 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4329 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4332 stbc = ar->ht_cap_info;
4333 stbc &= WMI_HT_CAP_RX_STBC;
4334 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4335 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4336 stbc &= IEEE80211_HT_CAP_RX_STBC;
4341 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4342 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4344 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4345 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4347 /* max AMSDU is implicitly taken from vht_cap_info */
4348 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4349 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4351 for (i = 0; i < ar->num_rf_chains; i++) {
4352 if (ar->cfg_rx_chainmask & BIT(i))
4353 ht_cap.mcs.rx_mask[i] = 0xFF;
4356 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4361 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4363 struct ieee80211_supported_band *band;
4364 struct ieee80211_sta_vht_cap vht_cap;
4365 struct ieee80211_sta_ht_cap ht_cap;
4367 ht_cap = ath10k_get_ht_cap(ar);
4368 vht_cap = ath10k_create_vht_cap(ar);
4370 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4371 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4372 band->ht_cap = ht_cap;
4374 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4375 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4376 band->ht_cap = ht_cap;
4377 band->vht_cap = vht_cap;
4381 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4385 lockdep_assert_held(&ar->conf_mutex);
4387 ath10k_check_chain_mask(ar, tx_ant, "tx");
4388 ath10k_check_chain_mask(ar, rx_ant, "rx");
4390 ar->cfg_tx_chainmask = tx_ant;
4391 ar->cfg_rx_chainmask = rx_ant;
4393 if ((ar->state != ATH10K_STATE_ON) &&
4394 (ar->state != ATH10K_STATE_RESTARTED))
4397 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4400 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4405 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4408 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4413 /* Reload HT/VHT capability */
4414 ath10k_mac_setup_ht_vht_cap(ar);
4419 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4421 struct ath10k *ar = hw->priv;
4424 mutex_lock(&ar->conf_mutex);
4425 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4426 mutex_unlock(&ar->conf_mutex);
4430 static int ath10k_start(struct ieee80211_hw *hw)
4432 struct ath10k *ar = hw->priv;
4437 * This makes sense only when restarting hw. It is harmless to call
4438 * unconditionally. This is necessary to make sure no HTT/WMI tx
4439 * commands will be submitted while restarting.
4441 ath10k_drain_tx(ar);
4443 mutex_lock(&ar->conf_mutex);
4445 switch (ar->state) {
4446 case ATH10K_STATE_OFF:
4447 ar->state = ATH10K_STATE_ON;
4449 case ATH10K_STATE_RESTARTING:
4450 ar->state = ATH10K_STATE_RESTARTED;
4452 case ATH10K_STATE_ON:
4453 case ATH10K_STATE_RESTARTED:
4454 case ATH10K_STATE_WEDGED:
4458 case ATH10K_STATE_UTF:
4463 ret = ath10k_hif_power_up(ar);
4465 ath10k_err(ar, "Could not init hif: %d\n", ret);
4469 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4470 &ar->normal_mode_fw);
4472 ath10k_err(ar, "Could not init core: %d\n", ret);
4473 goto err_power_down;
4476 param = ar->wmi.pdev_param->pmf_qos;
4477 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4479 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4483 param = ar->wmi.pdev_param->dynamic_bw;
4484 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4486 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4490 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4491 ret = ath10k_wmi_adaptive_qcs(ar, true);
4493 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4499 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4500 param = ar->wmi.pdev_param->burst_enable;
4501 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4503 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4508 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4511 * By default FW set ARP frames ac to voice (6). In that case ARP
4512 * exchange is not working properly for UAPSD enabled AP. ARP requests
4513 * which arrives with access category 0 are processed by network stack
4514 * and send back with access category 0, but FW changes access category
4515 * to 6. Set ARP frames access category to best effort (0) solves
4519 param = ar->wmi.pdev_param->arp_ac_override;
4520 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4522 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4527 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4528 ar->running_fw->fw_file.fw_features)) {
4529 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4530 WMI_CCA_DETECT_LEVEL_AUTO,
4531 WMI_CCA_DETECT_MARGIN_AUTO);
4533 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4539 param = ar->wmi.pdev_param->ani_enable;
4540 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4542 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4547 ar->ani_enabled = true;
4549 if (ath10k_peer_stats_enabled(ar)) {
4550 param = ar->wmi.pdev_param->peer_stats_update_period;
4551 ret = ath10k_wmi_pdev_set_param(ar, param,
4552 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4555 "failed to set peer stats period : %d\n",
4561 param = ar->wmi.pdev_param->enable_btcoex;
4562 if (test_bit(WMI_SERVICE_COEX_GPIO, ar->wmi.svc_map) &&
4563 test_bit(ATH10K_FW_FEATURE_BTCOEX_PARAM,
4564 ar->running_fw->fw_file.fw_features)) {
4565 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4568 "failed to set btcoex param: %d\n", ret);
4571 clear_bit(ATH10K_FLAG_BTCOEX, &ar->dev_flags);
4574 ar->num_started_vdevs = 0;
4575 ath10k_regd_update(ar);
4577 ath10k_spectral_start(ar);
4578 ath10k_thermal_set_throttling(ar);
4580 mutex_unlock(&ar->conf_mutex);
4584 ath10k_core_stop(ar);
4587 ath10k_hif_power_down(ar);
4590 ar->state = ATH10K_STATE_OFF;
4593 mutex_unlock(&ar->conf_mutex);
4597 static void ath10k_stop(struct ieee80211_hw *hw)
4599 struct ath10k *ar = hw->priv;
4601 ath10k_drain_tx(ar);
4603 mutex_lock(&ar->conf_mutex);
4604 if (ar->state != ATH10K_STATE_OFF) {
4606 ar->state = ATH10K_STATE_OFF;
4608 mutex_unlock(&ar->conf_mutex);
4610 cancel_delayed_work_sync(&ar->scan.timeout);
4611 cancel_work_sync(&ar->restart_work);
4614 static int ath10k_config_ps(struct ath10k *ar)
4616 struct ath10k_vif *arvif;
4619 lockdep_assert_held(&ar->conf_mutex);
4621 list_for_each_entry(arvif, &ar->arvifs, list) {
4622 ret = ath10k_mac_vif_setup_ps(arvif);
4624 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4632 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4637 lockdep_assert_held(&ar->conf_mutex);
4639 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4641 param = ar->wmi.pdev_param->txpower_limit2g;
4642 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4644 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4649 param = ar->wmi.pdev_param->txpower_limit5g;
4650 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4652 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4660 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4662 struct ath10k_vif *arvif;
4663 int ret, txpower = -1;
4665 lockdep_assert_held(&ar->conf_mutex);
4667 list_for_each_entry(arvif, &ar->arvifs, list) {
4668 WARN_ON(arvif->txpower < 0);
4671 txpower = arvif->txpower;
4673 txpower = min(txpower, arvif->txpower);
4676 if (WARN_ON(txpower == -1))
4679 ret = ath10k_mac_txpower_setup(ar, txpower);
4681 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4689 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4691 struct ath10k *ar = hw->priv;
4692 struct ieee80211_conf *conf = &hw->conf;
4695 mutex_lock(&ar->conf_mutex);
4697 if (changed & IEEE80211_CONF_CHANGE_PS)
4698 ath10k_config_ps(ar);
4700 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4701 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4702 ret = ath10k_monitor_recalc(ar);
4704 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4707 mutex_unlock(&ar->conf_mutex);
4711 static u32 get_nss_from_chainmask(u16 chain_mask)
4713 if ((chain_mask & 0xf) == 0xf)
4715 else if ((chain_mask & 0x7) == 0x7)
4717 else if ((chain_mask & 0x3) == 0x3)
4722 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4725 struct ath10k *ar = arvif->ar;
4729 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4732 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4733 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4734 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4735 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4737 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4738 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4739 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4740 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4745 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4746 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4748 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4749 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4750 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4752 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4753 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4755 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4756 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4757 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4759 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4760 ar->wmi.vdev_param->txbf, value);
4765 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4766 * because we will send mgmt frames without CCK. This requirement
4767 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4770 static int ath10k_add_interface(struct ieee80211_hw *hw,
4771 struct ieee80211_vif *vif)
4773 struct ath10k *ar = hw->priv;
4774 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4775 struct ath10k_peer *peer;
4776 enum wmi_sta_powersave_param param;
4783 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4785 mutex_lock(&ar->conf_mutex);
4787 memset(arvif, 0, sizeof(*arvif));
4788 ath10k_mac_txq_init(vif->txq);
4793 INIT_LIST_HEAD(&arvif->list);
4794 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4795 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4796 ath10k_mac_vif_sta_connection_loss_work);
4798 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4799 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4800 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4801 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4802 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4803 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4806 if (ar->num_peers >= ar->max_num_peers) {
4807 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4812 if (ar->free_vdev_map == 0) {
4813 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4817 bit = __ffs64(ar->free_vdev_map);
4819 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4820 bit, ar->free_vdev_map);
4822 arvif->vdev_id = bit;
4823 arvif->vdev_subtype =
4824 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4826 switch (vif->type) {
4827 case NL80211_IFTYPE_P2P_DEVICE:
4828 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4829 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4830 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4832 case NL80211_IFTYPE_UNSPECIFIED:
4833 case NL80211_IFTYPE_STATION:
4834 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4836 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4837 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4839 case NL80211_IFTYPE_ADHOC:
4840 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4842 case NL80211_IFTYPE_MESH_POINT:
4843 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4844 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4845 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4846 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4848 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4851 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4853 case NL80211_IFTYPE_AP:
4854 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4857 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4858 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4860 case NL80211_IFTYPE_MONITOR:
4861 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4868 /* Using vdev_id as queue number will make it very easy to do per-vif
4869 * tx queue locking. This shouldn't wrap due to interface combinations
4870 * but do a modulo for correctness sake and prevent using offchannel tx
4871 * queues for regular vif tx.
4873 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4874 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4875 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4877 /* Some firmware revisions don't wait for beacon tx completion before
4878 * sending another SWBA event. This could lead to hardware using old
4879 * (freed) beacon data in some cases, e.g. tx credit starvation
4880 * combined with missed TBTT. This is very very rare.
4882 * On non-IOMMU-enabled hosts this could be a possible security issue
4883 * because hw could beacon some random data on the air. On
4884 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4885 * device would crash.
4887 * Since there are no beacon tx completions (implicit nor explicit)
4888 * propagated to host the only workaround for this is to allocate a
4889 * DMA-coherent buffer for a lifetime of a vif and use it for all
4890 * beacon tx commands. Worst case for this approach is some beacons may
4891 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4893 if (vif->type == NL80211_IFTYPE_ADHOC ||
4894 vif->type == NL80211_IFTYPE_MESH_POINT ||
4895 vif->type == NL80211_IFTYPE_AP) {
4896 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4897 IEEE80211_MAX_FRAME_LEN,
4898 &arvif->beacon_paddr,
4900 if (!arvif->beacon_buf) {
4902 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4907 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4908 arvif->nohwcrypt = true;
4910 if (arvif->nohwcrypt &&
4911 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4912 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4916 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4917 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4918 arvif->beacon_buf ? "single-buf" : "per-skb");
4920 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4921 arvif->vdev_subtype, vif->addr);
4923 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4924 arvif->vdev_id, ret);
4928 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4929 list_add(&arvif->list, &ar->arvifs);
4931 /* It makes no sense to have firmware do keepalives. mac80211 already
4932 * takes care of this with idle connection polling.
4934 ret = ath10k_mac_vif_disable_keepalive(arvif);
4936 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4937 arvif->vdev_id, ret);
4938 goto err_vdev_delete;
4941 arvif->def_wep_key_idx = -1;
4943 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4944 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4945 ATH10K_HW_TXRX_NATIVE_WIFI);
4946 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4947 if (ret && ret != -EOPNOTSUPP) {
4948 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4949 arvif->vdev_id, ret);
4950 goto err_vdev_delete;
4953 /* Configuring number of spatial stream for monitor interface is causing
4954 * target assert in qca9888 and qca6174.
4956 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
4957 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4959 vdev_param = ar->wmi.vdev_param->nss;
4960 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4963 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4964 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4966 goto err_vdev_delete;
4970 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4971 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4972 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
4973 vif->addr, WMI_PEER_TYPE_DEFAULT);
4975 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4976 arvif->vdev_id, ret);
4977 goto err_vdev_delete;
4980 spin_lock_bh(&ar->data_lock);
4982 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
4984 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
4985 vif->addr, arvif->vdev_id);
4986 spin_unlock_bh(&ar->data_lock);
4988 goto err_peer_delete;
4991 arvif->peer_id = find_first_bit(peer->peer_ids,
4992 ATH10K_MAX_NUM_PEER_IDS);
4994 spin_unlock_bh(&ar->data_lock);
4996 arvif->peer_id = HTT_INVALID_PEERID;
4999 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5000 ret = ath10k_mac_set_kickout(arvif);
5002 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
5003 arvif->vdev_id, ret);
5004 goto err_peer_delete;
5008 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
5009 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
5010 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5011 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5014 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
5015 arvif->vdev_id, ret);
5016 goto err_peer_delete;
5019 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5021 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5022 arvif->vdev_id, ret);
5023 goto err_peer_delete;
5026 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5028 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5029 arvif->vdev_id, ret);
5030 goto err_peer_delete;
5034 ret = ath10k_mac_set_txbf_conf(arvif);
5036 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
5037 arvif->vdev_id, ret);
5038 goto err_peer_delete;
5041 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
5043 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5044 arvif->vdev_id, ret);
5045 goto err_peer_delete;
5048 arvif->txpower = vif->bss_conf.txpower;
5049 ret = ath10k_mac_txpower_recalc(ar);
5051 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5052 goto err_peer_delete;
5055 if (vif->type == NL80211_IFTYPE_MONITOR) {
5056 ar->monitor_arvif = arvif;
5057 ret = ath10k_monitor_recalc(ar);
5059 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5060 goto err_peer_delete;
5064 spin_lock_bh(&ar->htt.tx_lock);
5066 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
5067 spin_unlock_bh(&ar->htt.tx_lock);
5069 mutex_unlock(&ar->conf_mutex);
5073 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5074 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
5075 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
5078 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5079 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5080 list_del(&arvif->list);
5083 if (arvif->beacon_buf) {
5084 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
5085 arvif->beacon_buf, arvif->beacon_paddr);
5086 arvif->beacon_buf = NULL;
5089 mutex_unlock(&ar->conf_mutex);
5094 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
5098 for (i = 0; i < BITS_PER_LONG; i++)
5099 ath10k_mac_vif_tx_unlock(arvif, i);
5102 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5103 struct ieee80211_vif *vif)
5105 struct ath10k *ar = hw->priv;
5106 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5107 struct ath10k_peer *peer;
5111 cancel_work_sync(&arvif->ap_csa_work);
5112 cancel_delayed_work_sync(&arvif->connection_loss_work);
5114 mutex_lock(&ar->conf_mutex);
5116 spin_lock_bh(&ar->data_lock);
5117 ath10k_mac_vif_beacon_cleanup(arvif);
5118 spin_unlock_bh(&ar->data_lock);
5120 ret = ath10k_spectral_vif_stop(arvif);
5122 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5123 arvif->vdev_id, ret);
5125 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5126 list_del(&arvif->list);
5128 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5129 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5130 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5133 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5134 arvif->vdev_id, ret);
5136 kfree(arvif->u.ap.noa_data);
5139 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5142 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5144 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5145 arvif->vdev_id, ret);
5147 /* Some firmware revisions don't notify host about self-peer removal
5148 * until after associated vdev is deleted.
5150 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5151 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5152 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5155 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5156 arvif->vdev_id, ret);
5158 spin_lock_bh(&ar->data_lock);
5160 spin_unlock_bh(&ar->data_lock);
5163 spin_lock_bh(&ar->data_lock);
5164 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5165 peer = ar->peer_map[i];
5169 if (peer->vif == vif) {
5170 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5171 vif->addr, arvif->vdev_id);
5175 spin_unlock_bh(&ar->data_lock);
5177 ath10k_peer_cleanup(ar, arvif->vdev_id);
5178 ath10k_mac_txq_unref(ar, vif->txq);
5180 if (vif->type == NL80211_IFTYPE_MONITOR) {
5181 ar->monitor_arvif = NULL;
5182 ret = ath10k_monitor_recalc(ar);
5184 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5187 spin_lock_bh(&ar->htt.tx_lock);
5188 ath10k_mac_vif_tx_unlock_all(arvif);
5189 spin_unlock_bh(&ar->htt.tx_lock);
5191 ath10k_mac_txq_unref(ar, vif->txq);
5193 mutex_unlock(&ar->conf_mutex);
5197 * FIXME: Has to be verified.
5199 #define SUPPORTED_FILTERS \
5204 FIF_BCN_PRBRESP_PROMISC | \
5208 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5209 unsigned int changed_flags,
5210 unsigned int *total_flags,
5213 struct ath10k *ar = hw->priv;
5216 mutex_lock(&ar->conf_mutex);
5218 changed_flags &= SUPPORTED_FILTERS;
5219 *total_flags &= SUPPORTED_FILTERS;
5220 ar->filter_flags = *total_flags;
5222 ret = ath10k_monitor_recalc(ar);
5224 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5226 mutex_unlock(&ar->conf_mutex);
5229 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5230 struct ieee80211_vif *vif,
5231 struct ieee80211_bss_conf *info,
5234 struct ath10k *ar = hw->priv;
5235 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5237 u32 vdev_param, pdev_param, slottime, preamble;
5239 mutex_lock(&ar->conf_mutex);
5241 if (changed & BSS_CHANGED_IBSS)
5242 ath10k_control_ibss(arvif, info, vif->addr);
5244 if (changed & BSS_CHANGED_BEACON_INT) {
5245 arvif->beacon_interval = info->beacon_int;
5246 vdev_param = ar->wmi.vdev_param->beacon_interval;
5247 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5248 arvif->beacon_interval);
5249 ath10k_dbg(ar, ATH10K_DBG_MAC,
5250 "mac vdev %d beacon_interval %d\n",
5251 arvif->vdev_id, arvif->beacon_interval);
5254 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5255 arvif->vdev_id, ret);
5258 if (changed & BSS_CHANGED_BEACON) {
5259 ath10k_dbg(ar, ATH10K_DBG_MAC,
5260 "vdev %d set beacon tx mode to staggered\n",
5263 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5264 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5265 WMI_BEACON_STAGGERED_MODE);
5267 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5268 arvif->vdev_id, ret);
5270 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5272 ath10k_warn(ar, "failed to update beacon template: %d\n",
5275 if (ieee80211_vif_is_mesh(vif)) {
5276 /* mesh doesn't use SSID but firmware needs it */
5277 strncpy(arvif->u.ap.ssid, "mesh",
5278 sizeof(arvif->u.ap.ssid));
5279 arvif->u.ap.ssid_len = 4;
5283 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5284 ret = ath10k_mac_setup_prb_tmpl(arvif);
5286 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5287 arvif->vdev_id, ret);
5290 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5291 arvif->dtim_period = info->dtim_period;
5293 ath10k_dbg(ar, ATH10K_DBG_MAC,
5294 "mac vdev %d dtim_period %d\n",
5295 arvif->vdev_id, arvif->dtim_period);
5297 vdev_param = ar->wmi.vdev_param->dtim_period;
5298 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5299 arvif->dtim_period);
5301 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5302 arvif->vdev_id, ret);
5305 if (changed & BSS_CHANGED_SSID &&
5306 vif->type == NL80211_IFTYPE_AP) {
5307 arvif->u.ap.ssid_len = info->ssid_len;
5309 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5310 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5313 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5314 ether_addr_copy(arvif->bssid, info->bssid);
5316 if (changed & BSS_CHANGED_BEACON_ENABLED)
5317 ath10k_control_beaconing(arvif, info);
5319 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5320 arvif->use_cts_prot = info->use_cts_prot;
5321 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
5322 arvif->vdev_id, info->use_cts_prot);
5324 ret = ath10k_recalc_rtscts_prot(arvif);
5326 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5327 arvif->vdev_id, ret);
5329 vdev_param = ar->wmi.vdev_param->protection_mode;
5330 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5331 info->use_cts_prot ? 1 : 0);
5333 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
5334 info->use_cts_prot, arvif->vdev_id, ret);
5337 if (changed & BSS_CHANGED_ERP_SLOT) {
5338 if (info->use_short_slot)
5339 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5342 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5344 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5345 arvif->vdev_id, slottime);
5347 vdev_param = ar->wmi.vdev_param->slot_time;
5348 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5351 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5352 arvif->vdev_id, ret);
5355 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5356 if (info->use_short_preamble)
5357 preamble = WMI_VDEV_PREAMBLE_SHORT;
5359 preamble = WMI_VDEV_PREAMBLE_LONG;
5361 ath10k_dbg(ar, ATH10K_DBG_MAC,
5362 "mac vdev %d preamble %dn",
5363 arvif->vdev_id, preamble);
5365 vdev_param = ar->wmi.vdev_param->preamble;
5366 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5369 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5370 arvif->vdev_id, ret);
5373 if (changed & BSS_CHANGED_ASSOC) {
5375 /* Workaround: Make sure monitor vdev is not running
5376 * when associating to prevent some firmware revisions
5377 * (e.g. 10.1 and 10.2) from crashing.
5379 if (ar->monitor_started)
5380 ath10k_monitor_stop(ar);
5381 ath10k_bss_assoc(hw, vif, info);
5382 ath10k_monitor_recalc(ar);
5384 ath10k_bss_disassoc(hw, vif);
5388 if (changed & BSS_CHANGED_TXPOWER) {
5389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5390 arvif->vdev_id, info->txpower);
5392 arvif->txpower = info->txpower;
5393 ret = ath10k_mac_txpower_recalc(ar);
5395 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5398 if (changed & BSS_CHANGED_PS) {
5399 arvif->ps = vif->bss_conf.ps;
5401 ret = ath10k_config_ps(ar);
5403 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5404 arvif->vdev_id, ret);
5407 mutex_unlock(&ar->conf_mutex);
5410 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5411 struct ieee80211_vif *vif,
5412 struct ieee80211_scan_request *hw_req)
5414 struct ath10k *ar = hw->priv;
5415 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5416 struct cfg80211_scan_request *req = &hw_req->req;
5417 struct wmi_start_scan_arg arg;
5421 mutex_lock(&ar->conf_mutex);
5423 spin_lock_bh(&ar->data_lock);
5424 switch (ar->scan.state) {
5425 case ATH10K_SCAN_IDLE:
5426 reinit_completion(&ar->scan.started);
5427 reinit_completion(&ar->scan.completed);
5428 ar->scan.state = ATH10K_SCAN_STARTING;
5429 ar->scan.is_roc = false;
5430 ar->scan.vdev_id = arvif->vdev_id;
5433 case ATH10K_SCAN_STARTING:
5434 case ATH10K_SCAN_RUNNING:
5435 case ATH10K_SCAN_ABORTING:
5439 spin_unlock_bh(&ar->data_lock);
5444 memset(&arg, 0, sizeof(arg));
5445 ath10k_wmi_start_scan_init(ar, &arg);
5446 arg.vdev_id = arvif->vdev_id;
5447 arg.scan_id = ATH10K_SCAN_ID;
5450 arg.ie_len = req->ie_len;
5451 memcpy(arg.ie, req->ie, arg.ie_len);
5455 arg.n_ssids = req->n_ssids;
5456 for (i = 0; i < arg.n_ssids; i++) {
5457 arg.ssids[i].len = req->ssids[i].ssid_len;
5458 arg.ssids[i].ssid = req->ssids[i].ssid;
5461 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5464 if (req->n_channels) {
5465 arg.n_channels = req->n_channels;
5466 for (i = 0; i < arg.n_channels; i++)
5467 arg.channels[i] = req->channels[i]->center_freq;
5470 ret = ath10k_start_scan(ar, &arg);
5472 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5473 spin_lock_bh(&ar->data_lock);
5474 ar->scan.state = ATH10K_SCAN_IDLE;
5475 spin_unlock_bh(&ar->data_lock);
5478 /* Add a 200ms margin to account for event/command processing */
5479 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5480 msecs_to_jiffies(arg.max_scan_time +
5484 mutex_unlock(&ar->conf_mutex);
5488 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5489 struct ieee80211_vif *vif)
5491 struct ath10k *ar = hw->priv;
5493 mutex_lock(&ar->conf_mutex);
5494 ath10k_scan_abort(ar);
5495 mutex_unlock(&ar->conf_mutex);
5497 cancel_delayed_work_sync(&ar->scan.timeout);
5500 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5501 struct ath10k_vif *arvif,
5502 enum set_key_cmd cmd,
5503 struct ieee80211_key_conf *key)
5505 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5508 /* 10.1 firmware branch requires default key index to be set to group
5509 * key index after installing it. Otherwise FW/HW Txes corrupted
5510 * frames with multi-vif APs. This is not required for main firmware
5511 * branch (e.g. 636).
5513 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5515 * FIXME: It remains unknown if this is required for multi-vif STA
5516 * interfaces on 10.1.
5519 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5520 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5523 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5526 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5529 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5535 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5538 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5539 arvif->vdev_id, ret);
5542 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5543 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5544 struct ieee80211_key_conf *key)
5546 struct ath10k *ar = hw->priv;
5547 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5548 struct ath10k_peer *peer;
5549 const u8 *peer_addr;
5550 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5551 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5557 /* this one needs to be done in software */
5558 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5561 if (arvif->nohwcrypt)
5564 if (key->keyidx > WMI_MAX_KEY_INDEX)
5567 mutex_lock(&ar->conf_mutex);
5570 peer_addr = sta->addr;
5571 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5572 peer_addr = vif->bss_conf.bssid;
5574 peer_addr = vif->addr;
5576 key->hw_key_idx = key->keyidx;
5580 arvif->wep_keys[key->keyidx] = key;
5582 arvif->wep_keys[key->keyidx] = NULL;
5585 /* the peer should not disappear in mid-way (unless FW goes awry) since
5586 * we already hold conf_mutex. we just make sure its there now. */
5587 spin_lock_bh(&ar->data_lock);
5588 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5589 spin_unlock_bh(&ar->data_lock);
5592 if (cmd == SET_KEY) {
5593 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5598 /* if the peer doesn't exist there is no key to disable
5604 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5605 flags |= WMI_KEY_PAIRWISE;
5607 flags |= WMI_KEY_GROUP;
5610 if (cmd == DISABLE_KEY)
5611 ath10k_clear_vdev_key(arvif, key);
5613 /* When WEP keys are uploaded it's possible that there are
5614 * stations associated already (e.g. when merging) without any
5615 * keys. Static WEP needs an explicit per-peer key upload.
5617 if (vif->type == NL80211_IFTYPE_ADHOC &&
5619 ath10k_mac_vif_update_wep_key(arvif, key);
5621 /* 802.1x never sets the def_wep_key_idx so each set_key()
5622 * call changes default tx key.
5624 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5625 * after first set_key().
5627 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5628 flags |= WMI_KEY_TX_USAGE;
5631 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5634 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5635 arvif->vdev_id, peer_addr, ret);
5639 /* mac80211 sets static WEP keys as groupwise while firmware requires
5640 * them to be installed twice as both pairwise and groupwise.
5642 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5644 flags2 &= ~WMI_KEY_GROUP;
5645 flags2 |= WMI_KEY_PAIRWISE;
5647 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5650 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5651 arvif->vdev_id, peer_addr, ret);
5652 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5656 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5657 arvif->vdev_id, peer_addr, ret2);
5663 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5665 spin_lock_bh(&ar->data_lock);
5666 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5667 if (peer && cmd == SET_KEY)
5668 peer->keys[key->keyidx] = key;
5669 else if (peer && cmd == DISABLE_KEY)
5670 peer->keys[key->keyidx] = NULL;
5671 else if (peer == NULL)
5672 /* impossible unless FW goes crazy */
5673 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5674 spin_unlock_bh(&ar->data_lock);
5677 mutex_unlock(&ar->conf_mutex);
5681 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5682 struct ieee80211_vif *vif,
5685 struct ath10k *ar = hw->priv;
5686 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5689 mutex_lock(&arvif->ar->conf_mutex);
5691 if (arvif->ar->state != ATH10K_STATE_ON)
5694 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5695 arvif->vdev_id, keyidx);
5697 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5699 arvif->ar->wmi.vdev_param->def_keyid,
5703 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5709 arvif->def_wep_key_idx = keyidx;
5712 mutex_unlock(&arvif->ar->conf_mutex);
5715 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5718 struct ath10k_vif *arvif;
5719 struct ath10k_sta *arsta;
5720 struct ieee80211_sta *sta;
5721 struct cfg80211_chan_def def;
5722 enum nl80211_band band;
5723 const u8 *ht_mcs_mask;
5724 const u16 *vht_mcs_mask;
5725 u32 changed, bw, nss, smps;
5728 arsta = container_of(wk, struct ath10k_sta, update_wk);
5729 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5730 arvif = arsta->arvif;
5733 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5736 band = def.chan->band;
5737 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5738 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5740 spin_lock_bh(&ar->data_lock);
5742 changed = arsta->changed;
5749 spin_unlock_bh(&ar->data_lock);
5751 mutex_lock(&ar->conf_mutex);
5753 nss = max_t(u32, 1, nss);
5754 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5755 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5757 if (changed & IEEE80211_RC_BW_CHANGED) {
5758 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5761 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5762 WMI_PEER_CHAN_WIDTH, bw);
5764 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5765 sta->addr, bw, err);
5768 if (changed & IEEE80211_RC_NSS_CHANGED) {
5769 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5772 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5775 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5776 sta->addr, nss, err);
5779 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5780 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5783 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5784 WMI_PEER_SMPS_STATE, smps);
5786 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5787 sta->addr, smps, err);
5790 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5791 changed & IEEE80211_RC_NSS_CHANGED) {
5792 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
5795 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5797 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5801 mutex_unlock(&ar->conf_mutex);
5804 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5805 struct ieee80211_sta *sta)
5807 struct ath10k *ar = arvif->ar;
5809 lockdep_assert_held(&ar->conf_mutex);
5811 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5814 if (ar->num_stations >= ar->max_num_stations)
5822 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5823 struct ieee80211_sta *sta)
5825 struct ath10k *ar = arvif->ar;
5827 lockdep_assert_held(&ar->conf_mutex);
5829 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5835 struct ath10k_mac_tdls_iter_data {
5836 u32 num_tdls_stations;
5837 struct ieee80211_vif *curr_vif;
5840 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5841 struct ieee80211_sta *sta)
5843 struct ath10k_mac_tdls_iter_data *iter_data = data;
5844 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5845 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5847 if (sta->tdls && sta_vif == iter_data->curr_vif)
5848 iter_data->num_tdls_stations++;
5851 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5852 struct ieee80211_vif *vif)
5854 struct ath10k_mac_tdls_iter_data data = {};
5856 data.curr_vif = vif;
5858 ieee80211_iterate_stations_atomic(hw,
5859 ath10k_mac_tdls_vif_stations_count_iter,
5861 return data.num_tdls_stations;
5864 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5865 struct ieee80211_vif *vif)
5867 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5868 int *num_tdls_vifs = data;
5870 if (vif->type != NL80211_IFTYPE_STATION)
5873 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5877 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5879 int num_tdls_vifs = 0;
5881 ieee80211_iterate_active_interfaces_atomic(hw,
5882 IEEE80211_IFACE_ITER_NORMAL,
5883 ath10k_mac_tdls_vifs_count_iter,
5885 return num_tdls_vifs;
5888 static int ath10k_sta_state(struct ieee80211_hw *hw,
5889 struct ieee80211_vif *vif,
5890 struct ieee80211_sta *sta,
5891 enum ieee80211_sta_state old_state,
5892 enum ieee80211_sta_state new_state)
5894 struct ath10k *ar = hw->priv;
5895 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5896 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5897 struct ath10k_peer *peer;
5901 if (old_state == IEEE80211_STA_NOTEXIST &&
5902 new_state == IEEE80211_STA_NONE) {
5903 memset(arsta, 0, sizeof(*arsta));
5904 arsta->arvif = arvif;
5905 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5907 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5908 ath10k_mac_txq_init(sta->txq[i]);
5911 /* cancel must be done outside the mutex to avoid deadlock */
5912 if ((old_state == IEEE80211_STA_NONE &&
5913 new_state == IEEE80211_STA_NOTEXIST))
5914 cancel_work_sync(&arsta->update_wk);
5916 mutex_lock(&ar->conf_mutex);
5918 if (old_state == IEEE80211_STA_NOTEXIST &&
5919 new_state == IEEE80211_STA_NONE) {
5921 * New station addition.
5923 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5924 u32 num_tdls_stations;
5927 ath10k_dbg(ar, ATH10K_DBG_MAC,
5928 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5929 arvif->vdev_id, sta->addr,
5930 ar->num_stations + 1, ar->max_num_stations,
5931 ar->num_peers + 1, ar->max_num_peers);
5933 ret = ath10k_mac_inc_num_stations(arvif, sta);
5935 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5936 ar->max_num_stations);
5941 peer_type = WMI_PEER_TYPE_TDLS;
5943 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
5944 sta->addr, peer_type);
5946 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5947 sta->addr, arvif->vdev_id, ret);
5948 ath10k_mac_dec_num_stations(arvif, sta);
5952 spin_lock_bh(&ar->data_lock);
5954 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
5956 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5957 vif->addr, arvif->vdev_id);
5958 spin_unlock_bh(&ar->data_lock);
5959 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5960 ath10k_mac_dec_num_stations(arvif, sta);
5965 arsta->peer_id = find_first_bit(peer->peer_ids,
5966 ATH10K_MAX_NUM_PEER_IDS);
5968 spin_unlock_bh(&ar->data_lock);
5973 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5974 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5976 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5977 num_tdls_stations == 0) {
5978 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5979 arvif->vdev_id, ar->max_num_tdls_vdevs);
5980 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5981 ath10k_mac_dec_num_stations(arvif, sta);
5986 if (num_tdls_stations == 0) {
5987 /* This is the first tdls peer in current vif */
5988 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5990 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5993 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5994 arvif->vdev_id, ret);
5995 ath10k_peer_delete(ar, arvif->vdev_id,
5997 ath10k_mac_dec_num_stations(arvif, sta);
6002 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6003 WMI_TDLS_PEER_STATE_PEERING);
6006 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
6007 sta->addr, arvif->vdev_id, ret);
6008 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6009 ath10k_mac_dec_num_stations(arvif, sta);
6011 if (num_tdls_stations != 0)
6013 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6016 } else if ((old_state == IEEE80211_STA_NONE &&
6017 new_state == IEEE80211_STA_NOTEXIST)) {
6019 * Existing station deletion.
6021 ath10k_dbg(ar, ATH10K_DBG_MAC,
6022 "mac vdev %d peer delete %pM sta %pK (sta gone)\n",
6023 arvif->vdev_id, sta->addr, sta);
6025 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
6027 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
6028 sta->addr, arvif->vdev_id, ret);
6030 ath10k_mac_dec_num_stations(arvif, sta);
6032 spin_lock_bh(&ar->data_lock);
6033 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
6034 peer = ar->peer_map[i];
6038 if (peer->sta == sta) {
6039 ath10k_warn(ar, "found sta peer %pM (ptr %pK id %d) entry on vdev %i after it was supposedly removed\n",
6040 sta->addr, peer, i, arvif->vdev_id);
6043 /* Clean up the peer object as well since we
6044 * must have failed to do this above.
6046 list_del(&peer->list);
6047 ar->peer_map[i] = NULL;
6052 spin_unlock_bh(&ar->data_lock);
6054 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
6055 ath10k_mac_txq_unref(ar, sta->txq[i]);
6060 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
6063 /* This was the last tdls peer in current vif */
6064 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
6067 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
6068 arvif->vdev_id, ret);
6070 } else if (old_state == IEEE80211_STA_AUTH &&
6071 new_state == IEEE80211_STA_ASSOC &&
6072 (vif->type == NL80211_IFTYPE_AP ||
6073 vif->type == NL80211_IFTYPE_MESH_POINT ||
6074 vif->type == NL80211_IFTYPE_ADHOC)) {
6078 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
6081 ret = ath10k_station_assoc(ar, vif, sta, false);
6083 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
6084 sta->addr, arvif->vdev_id, ret);
6085 } else if (old_state == IEEE80211_STA_ASSOC &&
6086 new_state == IEEE80211_STA_AUTHORIZED &&
6089 * Tdls station authorized.
6091 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
6094 ret = ath10k_station_assoc(ar, vif, sta, false);
6096 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
6097 sta->addr, arvif->vdev_id, ret);
6101 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
6102 WMI_TDLS_PEER_STATE_CONNECTED);
6104 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
6105 sta->addr, arvif->vdev_id, ret);
6106 } else if (old_state == IEEE80211_STA_ASSOC &&
6107 new_state == IEEE80211_STA_AUTH &&
6108 (vif->type == NL80211_IFTYPE_AP ||
6109 vif->type == NL80211_IFTYPE_MESH_POINT ||
6110 vif->type == NL80211_IFTYPE_ADHOC)) {
6114 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6117 ret = ath10k_station_disassoc(ar, vif, sta);
6119 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6120 sta->addr, arvif->vdev_id, ret);
6123 mutex_unlock(&ar->conf_mutex);
6127 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6128 u16 ac, bool enable)
6130 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6131 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6132 u32 prio = 0, acc = 0;
6136 lockdep_assert_held(&ar->conf_mutex);
6138 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6142 case IEEE80211_AC_VO:
6143 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6144 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6148 case IEEE80211_AC_VI:
6149 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6150 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6154 case IEEE80211_AC_BE:
6155 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6156 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6160 case IEEE80211_AC_BK:
6161 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6162 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6169 arvif->u.sta.uapsd |= value;
6171 arvif->u.sta.uapsd &= ~value;
6173 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6174 WMI_STA_PS_PARAM_UAPSD,
6175 arvif->u.sta.uapsd);
6177 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6181 if (arvif->u.sta.uapsd)
6182 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6184 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6186 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6187 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6190 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6192 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6194 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6195 arvif->vdev_id, ret);
6199 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6201 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6202 arvif->vdev_id, ret);
6206 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6207 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6208 /* Only userspace can make an educated decision when to send
6209 * trigger frame. The following effectively disables u-UAPSD
6210 * autotrigger in firmware (which is enabled by default
6211 * provided the autotrigger service is available).
6215 arg.user_priority = prio;
6216 arg.service_interval = 0;
6217 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6218 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6220 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6221 arvif->bssid, &arg, 1);
6223 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6233 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6234 struct ieee80211_vif *vif, u16 ac,
6235 const struct ieee80211_tx_queue_params *params)
6237 struct ath10k *ar = hw->priv;
6238 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6239 struct wmi_wmm_params_arg *p = NULL;
6242 mutex_lock(&ar->conf_mutex);
6245 case IEEE80211_AC_VO:
6246 p = &arvif->wmm_params.ac_vo;
6248 case IEEE80211_AC_VI:
6249 p = &arvif->wmm_params.ac_vi;
6251 case IEEE80211_AC_BE:
6252 p = &arvif->wmm_params.ac_be;
6254 case IEEE80211_AC_BK:
6255 p = &arvif->wmm_params.ac_bk;
6264 p->cwmin = params->cw_min;
6265 p->cwmax = params->cw_max;
6266 p->aifs = params->aifs;
6269 * The channel time duration programmed in the HW is in absolute
6270 * microseconds, while mac80211 gives the txop in units of
6273 p->txop = params->txop * 32;
6275 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6276 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6277 &arvif->wmm_params);
6279 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6280 arvif->vdev_id, ret);
6284 /* This won't work well with multi-interface cases but it's
6285 * better than nothing.
6287 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6289 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6294 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6296 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6299 mutex_unlock(&ar->conf_mutex);
6303 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6305 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6306 struct ieee80211_vif *vif,
6307 struct ieee80211_channel *chan,
6309 enum ieee80211_roc_type type)
6311 struct ath10k *ar = hw->priv;
6312 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6313 struct wmi_start_scan_arg arg;
6317 mutex_lock(&ar->conf_mutex);
6319 spin_lock_bh(&ar->data_lock);
6320 switch (ar->scan.state) {
6321 case ATH10K_SCAN_IDLE:
6322 reinit_completion(&ar->scan.started);
6323 reinit_completion(&ar->scan.completed);
6324 reinit_completion(&ar->scan.on_channel);
6325 ar->scan.state = ATH10K_SCAN_STARTING;
6326 ar->scan.is_roc = true;
6327 ar->scan.vdev_id = arvif->vdev_id;
6328 ar->scan.roc_freq = chan->center_freq;
6329 ar->scan.roc_notify = true;
6332 case ATH10K_SCAN_STARTING:
6333 case ATH10K_SCAN_RUNNING:
6334 case ATH10K_SCAN_ABORTING:
6338 spin_unlock_bh(&ar->data_lock);
6343 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6345 memset(&arg, 0, sizeof(arg));
6346 ath10k_wmi_start_scan_init(ar, &arg);
6347 arg.vdev_id = arvif->vdev_id;
6348 arg.scan_id = ATH10K_SCAN_ID;
6350 arg.channels[0] = chan->center_freq;
6351 arg.dwell_time_active = scan_time_msec;
6352 arg.dwell_time_passive = scan_time_msec;
6353 arg.max_scan_time = scan_time_msec;
6354 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6355 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6356 arg.burst_duration_ms = duration;
6358 ret = ath10k_start_scan(ar, &arg);
6360 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6361 spin_lock_bh(&ar->data_lock);
6362 ar->scan.state = ATH10K_SCAN_IDLE;
6363 spin_unlock_bh(&ar->data_lock);
6367 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6369 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6371 ret = ath10k_scan_stop(ar);
6373 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6379 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6380 msecs_to_jiffies(duration));
6384 mutex_unlock(&ar->conf_mutex);
6388 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6390 struct ath10k *ar = hw->priv;
6392 mutex_lock(&ar->conf_mutex);
6394 spin_lock_bh(&ar->data_lock);
6395 ar->scan.roc_notify = false;
6396 spin_unlock_bh(&ar->data_lock);
6398 ath10k_scan_abort(ar);
6400 mutex_unlock(&ar->conf_mutex);
6402 cancel_delayed_work_sync(&ar->scan.timeout);
6408 * Both RTS and Fragmentation threshold are interface-specific
6409 * in ath10k, but device-specific in mac80211.
6412 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6414 struct ath10k *ar = hw->priv;
6415 struct ath10k_vif *arvif;
6418 mutex_lock(&ar->conf_mutex);
6419 list_for_each_entry(arvif, &ar->arvifs, list) {
6420 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6421 arvif->vdev_id, value);
6423 ret = ath10k_mac_set_rts(arvif, value);
6425 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6426 arvif->vdev_id, ret);
6430 mutex_unlock(&ar->conf_mutex);
6435 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6437 /* Even though there's a WMI enum for fragmentation threshold no known
6438 * firmware actually implements it. Moreover it is not possible to rely
6439 * frame fragmentation to mac80211 because firmware clears the "more
6440 * fragments" bit in frame control making it impossible for remote
6441 * devices to reassemble frames.
6443 * Hence implement a dummy callback just to say fragmentation isn't
6444 * supported. This effectively prevents mac80211 from doing frame
6445 * fragmentation in software.
6450 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6451 u32 queues, bool drop)
6453 struct ath10k *ar = hw->priv;
6457 /* mac80211 doesn't care if we really xmit queued frames or not
6458 * we'll collect those frames either way if we stop/delete vdevs */
6462 mutex_lock(&ar->conf_mutex);
6464 if (ar->state == ATH10K_STATE_WEDGED)
6467 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6470 spin_lock_bh(&ar->htt.tx_lock);
6471 empty = (ar->htt.num_pending_tx == 0);
6472 spin_unlock_bh(&ar->htt.tx_lock);
6474 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6475 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6479 }), ATH10K_FLUSH_TIMEOUT_HZ);
6481 if (time_left == 0 || skip)
6482 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6483 skip, ar->state, time_left);
6486 mutex_unlock(&ar->conf_mutex);
6489 /* TODO: Implement this function properly
6490 * For now it is needed to reply to Probe Requests in IBSS mode.
6491 * Propably we need this information from FW.
6493 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6498 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6499 enum ieee80211_reconfig_type reconfig_type)
6501 struct ath10k *ar = hw->priv;
6503 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6506 mutex_lock(&ar->conf_mutex);
6508 /* If device failed to restart it will be in a different state, e.g.
6509 * ATH10K_STATE_WEDGED */
6510 if (ar->state == ATH10K_STATE_RESTARTED) {
6511 ath10k_info(ar, "device successfully recovered\n");
6512 ar->state = ATH10K_STATE_ON;
6513 ieee80211_wake_queues(ar->hw);
6516 mutex_unlock(&ar->conf_mutex);
6520 ath10k_mac_update_bss_chan_survey(struct ath10k *ar,
6521 struct ieee80211_channel *channel)
6524 enum wmi_bss_survey_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ_CLEAR;
6526 lockdep_assert_held(&ar->conf_mutex);
6528 if (!test_bit(WMI_SERVICE_BSS_CHANNEL_INFO_64, ar->wmi.svc_map) ||
6529 (ar->rx_channel != channel))
6532 if (ar->scan.state != ATH10K_SCAN_IDLE) {
6533 ath10k_dbg(ar, ATH10K_DBG_MAC, "ignoring bss chan info request while scanning..\n");
6537 reinit_completion(&ar->bss_survey_done);
6539 ret = ath10k_wmi_pdev_bss_chan_info_request(ar, type);
6541 ath10k_warn(ar, "failed to send pdev bss chan info request\n");
6545 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6547 ath10k_warn(ar, "bss channel survey timed out\n");
6552 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6553 struct survey_info *survey)
6555 struct ath10k *ar = hw->priv;
6556 struct ieee80211_supported_band *sband;
6557 struct survey_info *ar_survey = &ar->survey[idx];
6560 mutex_lock(&ar->conf_mutex);
6562 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6563 if (sband && idx >= sband->n_channels) {
6564 idx -= sband->n_channels;
6569 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6571 if (!sband || idx >= sband->n_channels) {
6576 ath10k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6578 spin_lock_bh(&ar->data_lock);
6579 memcpy(survey, ar_survey, sizeof(*survey));
6580 spin_unlock_bh(&ar->data_lock);
6582 survey->channel = &sband->channels[idx];
6584 if (ar->rx_channel == survey->channel)
6585 survey->filled |= SURVEY_INFO_IN_USE;
6588 mutex_unlock(&ar->conf_mutex);
6593 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6594 enum nl80211_band band,
6595 const struct cfg80211_bitrate_mask *mask)
6600 num_rates += hweight32(mask->control[band].legacy);
6602 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6603 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6605 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6606 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6608 return num_rates == 1;
6612 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6613 enum nl80211_band band,
6614 const struct cfg80211_bitrate_mask *mask,
6617 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6618 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6620 u8 vht_nss_mask = 0;
6623 if (mask->control[band].legacy)
6626 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6627 if (mask->control[band].ht_mcs[i] == 0)
6629 else if (mask->control[band].ht_mcs[i] ==
6630 sband->ht_cap.mcs.rx_mask[i])
6631 ht_nss_mask |= BIT(i);
6636 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6637 if (mask->control[band].vht_mcs[i] == 0)
6639 else if (mask->control[band].vht_mcs[i] ==
6640 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6641 vht_nss_mask |= BIT(i);
6646 if (ht_nss_mask != vht_nss_mask)
6649 if (ht_nss_mask == 0)
6652 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6655 *nss = fls(ht_nss_mask);
6661 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6662 enum nl80211_band band,
6663 const struct cfg80211_bitrate_mask *mask,
6666 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6673 if (hweight32(mask->control[band].legacy) == 1) {
6674 rate_idx = ffs(mask->control[band].legacy) - 1;
6676 hw_rate = sband->bitrates[rate_idx].hw_value;
6677 bitrate = sband->bitrates[rate_idx].bitrate;
6679 if (ath10k_mac_bitrate_is_cck(bitrate))
6680 preamble = WMI_RATE_PREAMBLE_CCK;
6682 preamble = WMI_RATE_PREAMBLE_OFDM;
6685 *rate = preamble << 6 |
6692 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6693 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6695 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6697 (ffs(mask->control[band].ht_mcs[i]) - 1);
6703 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6704 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6706 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6708 (ffs(mask->control[band].vht_mcs[i]) - 1);
6717 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6718 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6720 struct ath10k *ar = arvif->ar;
6724 lockdep_assert_held(&ar->conf_mutex);
6726 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6727 arvif->vdev_id, rate, nss, sgi);
6729 vdev_param = ar->wmi.vdev_param->fixed_rate;
6730 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6732 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6737 vdev_param = ar->wmi.vdev_param->nss;
6738 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6740 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6744 vdev_param = ar->wmi.vdev_param->sgi;
6745 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6747 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6751 vdev_param = ar->wmi.vdev_param->ldpc;
6752 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6754 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6762 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6763 enum nl80211_band band,
6764 const struct cfg80211_bitrate_mask *mask)
6769 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6770 * to express all VHT MCS rate masks. Effectively only the following
6771 * ranges can be used: none, 0-7, 0-8 and 0-9.
6773 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6774 vht_mcs = mask->control[band].vht_mcs[i];
6783 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6791 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6792 struct ieee80211_sta *sta)
6794 struct ath10k_vif *arvif = data;
6795 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6796 struct ath10k *ar = arvif->ar;
6798 if (arsta->arvif != arvif)
6801 spin_lock_bh(&ar->data_lock);
6802 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6803 spin_unlock_bh(&ar->data_lock);
6805 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6808 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6809 struct ieee80211_vif *vif,
6810 const struct cfg80211_bitrate_mask *mask)
6812 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6813 struct cfg80211_chan_def def;
6814 struct ath10k *ar = arvif->ar;
6815 enum nl80211_band band;
6816 const u8 *ht_mcs_mask;
6817 const u16 *vht_mcs_mask;
6825 if (ath10k_mac_vif_chan(vif, &def))
6828 band = def.chan->band;
6829 ht_mcs_mask = mask->control[band].ht_mcs;
6830 vht_mcs_mask = mask->control[band].vht_mcs;
6831 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6833 sgi = mask->control[band].gi;
6834 if (sgi == NL80211_TXRATE_FORCE_LGI)
6837 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6838 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6841 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6842 arvif->vdev_id, ret);
6845 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6847 rate = WMI_FIXED_RATE_NONE;
6850 rate = WMI_FIXED_RATE_NONE;
6851 nss = min(ar->num_rf_chains,
6852 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6853 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6855 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6858 mutex_lock(&ar->conf_mutex);
6860 arvif->bitrate_mask = *mask;
6861 ieee80211_iterate_stations_atomic(ar->hw,
6862 ath10k_mac_set_bitrate_mask_iter,
6865 mutex_unlock(&ar->conf_mutex);
6868 mutex_lock(&ar->conf_mutex);
6870 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6872 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6873 arvif->vdev_id, ret);
6878 mutex_unlock(&ar->conf_mutex);
6883 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6884 struct ieee80211_vif *vif,
6885 struct ieee80211_sta *sta,
6888 struct ath10k *ar = hw->priv;
6889 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6892 spin_lock_bh(&ar->data_lock);
6894 ath10k_dbg(ar, ATH10K_DBG_MAC,
6895 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6896 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6899 if (changed & IEEE80211_RC_BW_CHANGED) {
6900 bw = WMI_PEER_CHWIDTH_20MHZ;
6902 switch (sta->bandwidth) {
6903 case IEEE80211_STA_RX_BW_20:
6904 bw = WMI_PEER_CHWIDTH_20MHZ;
6906 case IEEE80211_STA_RX_BW_40:
6907 bw = WMI_PEER_CHWIDTH_40MHZ;
6909 case IEEE80211_STA_RX_BW_80:
6910 bw = WMI_PEER_CHWIDTH_80MHZ;
6912 case IEEE80211_STA_RX_BW_160:
6913 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6914 sta->bandwidth, sta->addr);
6915 bw = WMI_PEER_CHWIDTH_20MHZ;
6922 if (changed & IEEE80211_RC_NSS_CHANGED)
6923 arsta->nss = sta->rx_nss;
6925 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6926 smps = WMI_PEER_SMPS_PS_NONE;
6928 switch (sta->smps_mode) {
6929 case IEEE80211_SMPS_AUTOMATIC:
6930 case IEEE80211_SMPS_OFF:
6931 smps = WMI_PEER_SMPS_PS_NONE;
6933 case IEEE80211_SMPS_STATIC:
6934 smps = WMI_PEER_SMPS_STATIC;
6936 case IEEE80211_SMPS_DYNAMIC:
6937 smps = WMI_PEER_SMPS_DYNAMIC;
6939 case IEEE80211_SMPS_NUM_MODES:
6940 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6941 sta->smps_mode, sta->addr);
6942 smps = WMI_PEER_SMPS_PS_NONE;
6949 arsta->changed |= changed;
6951 spin_unlock_bh(&ar->data_lock);
6953 ieee80211_queue_work(hw, &arsta->update_wk);
6956 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6959 * FIXME: Return 0 for time being. Need to figure out whether FW
6960 * has the API to fetch 64-bit local TSF
6966 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6969 struct ath10k *ar = hw->priv;
6970 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6971 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
6976 * Given tsf argument is entire TSF value, but firmware accepts
6977 * only TSF offset to current TSF.
6979 * get_tsf function is used to get offset value, however since
6980 * ath10k_get_tsf is not implemented properly, it will return 0 always.
6981 * Luckily all the caller functions to set_tsf, as of now, also rely on
6982 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
6983 * final tsf offset value to firmware will be arithmetically correct.
6985 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
6986 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
6987 vdev_param, tsf_offset);
6988 if (ret && ret != -EOPNOTSUPP)
6989 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
6992 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6993 struct ieee80211_vif *vif,
6994 struct ieee80211_ampdu_params *params)
6996 struct ath10k *ar = hw->priv;
6997 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6998 struct ieee80211_sta *sta = params->sta;
6999 enum ieee80211_ampdu_mlme_action action = params->action;
7000 u16 tid = params->tid;
7002 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
7003 arvif->vdev_id, sta->addr, tid, action);
7006 case IEEE80211_AMPDU_RX_START:
7007 case IEEE80211_AMPDU_RX_STOP:
7008 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
7009 * creation/removal. Do we need to verify this?
7012 case IEEE80211_AMPDU_TX_START:
7013 case IEEE80211_AMPDU_TX_STOP_CONT:
7014 case IEEE80211_AMPDU_TX_STOP_FLUSH:
7015 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
7016 case IEEE80211_AMPDU_TX_OPERATIONAL:
7017 /* Firmware offloads Tx aggregation entirely so deny mac80211
7018 * Tx aggregation requests.
7027 ath10k_mac_update_rx_channel(struct ath10k *ar,
7028 struct ieee80211_chanctx_conf *ctx,
7029 struct ieee80211_vif_chanctx_switch *vifs,
7032 struct cfg80211_chan_def *def = NULL;
7034 /* Both locks are required because ar->rx_channel is modified. This
7035 * allows readers to hold either lock.
7037 lockdep_assert_held(&ar->conf_mutex);
7038 lockdep_assert_held(&ar->data_lock);
7040 WARN_ON(ctx && vifs);
7041 WARN_ON(vifs && n_vifs != 1);
7043 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
7044 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
7045 * ppdu on Rx may reduce performance on low-end systems. It should be
7046 * possible to make tables/hashmaps to speed the lookup up (be vary of
7047 * cpu data cache lines though regarding sizes) but to keep the initial
7048 * implementation simple and less intrusive fallback to the slow lookup
7049 * only for multi-channel cases. Single-channel cases will remain to
7050 * use the old channel derival and thus performance should not be
7054 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
7055 ieee80211_iter_chan_contexts_atomic(ar->hw,
7056 ath10k_mac_get_any_chandef_iter,
7060 def = &vifs[0].new_ctx->def;
7062 ar->rx_channel = def->chan;
7063 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
7064 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
7065 /* During driver restart due to firmware assert, since mac80211
7066 * already has valid channel context for given radio, channel
7067 * context iteration return num_chanctx > 0. So fix rx_channel
7068 * when restart is in progress.
7070 ar->rx_channel = ctx->def.chan;
7072 ar->rx_channel = NULL;
7078 ath10k_mac_update_vif_chan(struct ath10k *ar,
7079 struct ieee80211_vif_chanctx_switch *vifs,
7082 struct ath10k_vif *arvif;
7086 lockdep_assert_held(&ar->conf_mutex);
7088 /* First stop monitor interface. Some FW versions crash if there's a
7089 * lone monitor interface.
7091 if (ar->monitor_started)
7092 ath10k_monitor_stop(ar);
7094 for (i = 0; i < n_vifs; i++) {
7095 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7097 ath10k_dbg(ar, ATH10K_DBG_MAC,
7098 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
7100 vifs[i].old_ctx->def.chan->center_freq,
7101 vifs[i].new_ctx->def.chan->center_freq,
7102 vifs[i].old_ctx->def.width,
7103 vifs[i].new_ctx->def.width);
7105 if (WARN_ON(!arvif->is_started))
7108 if (WARN_ON(!arvif->is_up))
7111 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7113 ath10k_warn(ar, "failed to down vdev %d: %d\n",
7114 arvif->vdev_id, ret);
7119 /* All relevant vdevs are downed and associated channel resources
7120 * should be available for the channel switch now.
7123 spin_lock_bh(&ar->data_lock);
7124 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
7125 spin_unlock_bh(&ar->data_lock);
7127 for (i = 0; i < n_vifs; i++) {
7128 arvif = ath10k_vif_to_arvif(vifs[i].vif);
7130 if (WARN_ON(!arvif->is_started))
7133 if (WARN_ON(!arvif->is_up))
7136 ret = ath10k_mac_setup_bcn_tmpl(arvif);
7138 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
7141 ret = ath10k_mac_setup_prb_tmpl(arvif);
7143 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7146 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7148 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7149 arvif->vdev_id, ret);
7153 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7156 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7157 arvif->vdev_id, ret);
7162 ath10k_monitor_recalc(ar);
7166 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7167 struct ieee80211_chanctx_conf *ctx)
7169 struct ath10k *ar = hw->priv;
7171 ath10k_dbg(ar, ATH10K_DBG_MAC,
7172 "mac chanctx add freq %hu width %d ptr %pK\n",
7173 ctx->def.chan->center_freq, ctx->def.width, ctx);
7175 mutex_lock(&ar->conf_mutex);
7177 spin_lock_bh(&ar->data_lock);
7178 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7179 spin_unlock_bh(&ar->data_lock);
7181 ath10k_recalc_radar_detection(ar);
7182 ath10k_monitor_recalc(ar);
7184 mutex_unlock(&ar->conf_mutex);
7190 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7191 struct ieee80211_chanctx_conf *ctx)
7193 struct ath10k *ar = hw->priv;
7195 ath10k_dbg(ar, ATH10K_DBG_MAC,
7196 "mac chanctx remove freq %hu width %d ptr %pK\n",
7197 ctx->def.chan->center_freq, ctx->def.width, ctx);
7199 mutex_lock(&ar->conf_mutex);
7201 spin_lock_bh(&ar->data_lock);
7202 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7203 spin_unlock_bh(&ar->data_lock);
7205 ath10k_recalc_radar_detection(ar);
7206 ath10k_monitor_recalc(ar);
7208 mutex_unlock(&ar->conf_mutex);
7211 struct ath10k_mac_change_chanctx_arg {
7212 struct ieee80211_chanctx_conf *ctx;
7213 struct ieee80211_vif_chanctx_switch *vifs;
7219 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7220 struct ieee80211_vif *vif)
7222 struct ath10k_mac_change_chanctx_arg *arg = data;
7224 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7231 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7232 struct ieee80211_vif *vif)
7234 struct ath10k_mac_change_chanctx_arg *arg = data;
7235 struct ieee80211_chanctx_conf *ctx;
7237 ctx = rcu_access_pointer(vif->chanctx_conf);
7238 if (ctx != arg->ctx)
7241 if (WARN_ON(arg->next_vif == arg->n_vifs))
7244 arg->vifs[arg->next_vif].vif = vif;
7245 arg->vifs[arg->next_vif].old_ctx = ctx;
7246 arg->vifs[arg->next_vif].new_ctx = ctx;
7251 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7252 struct ieee80211_chanctx_conf *ctx,
7255 struct ath10k *ar = hw->priv;
7256 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7258 mutex_lock(&ar->conf_mutex);
7260 ath10k_dbg(ar, ATH10K_DBG_MAC,
7261 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
7262 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7264 /* This shouldn't really happen because channel switching should use
7265 * switch_vif_chanctx().
7267 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7270 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7271 ieee80211_iterate_active_interfaces_atomic(
7273 IEEE80211_IFACE_ITER_NORMAL,
7274 ath10k_mac_change_chanctx_cnt_iter,
7276 if (arg.n_vifs == 0)
7279 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7284 ieee80211_iterate_active_interfaces_atomic(
7286 IEEE80211_IFACE_ITER_NORMAL,
7287 ath10k_mac_change_chanctx_fill_iter,
7289 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7294 ath10k_recalc_radar_detection(ar);
7296 /* FIXME: How to configure Rx chains properly? */
7298 /* No other actions are actually necessary. Firmware maintains channel
7299 * definitions per vdev internally and there's no host-side channel
7300 * context abstraction to configure, e.g. channel width.
7304 mutex_unlock(&ar->conf_mutex);
7308 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7309 struct ieee80211_vif *vif,
7310 struct ieee80211_chanctx_conf *ctx)
7312 struct ath10k *ar = hw->priv;
7313 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7316 mutex_lock(&ar->conf_mutex);
7318 ath10k_dbg(ar, ATH10K_DBG_MAC,
7319 "mac chanctx assign ptr %pK vdev_id %i\n",
7320 ctx, arvif->vdev_id);
7322 if (WARN_ON(arvif->is_started)) {
7323 mutex_unlock(&ar->conf_mutex);
7327 ret = ath10k_vdev_start(arvif, &ctx->def);
7329 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7330 arvif->vdev_id, vif->addr,
7331 ctx->def.chan->center_freq, ret);
7335 arvif->is_started = true;
7337 ret = ath10k_mac_vif_setup_ps(arvif);
7339 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7340 arvif->vdev_id, ret);
7344 if (vif->type == NL80211_IFTYPE_MONITOR) {
7345 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7347 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7348 arvif->vdev_id, ret);
7352 arvif->is_up = true;
7355 mutex_unlock(&ar->conf_mutex);
7359 ath10k_vdev_stop(arvif);
7360 arvif->is_started = false;
7361 ath10k_mac_vif_setup_ps(arvif);
7364 mutex_unlock(&ar->conf_mutex);
7369 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7370 struct ieee80211_vif *vif,
7371 struct ieee80211_chanctx_conf *ctx)
7373 struct ath10k *ar = hw->priv;
7374 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7377 mutex_lock(&ar->conf_mutex);
7379 ath10k_dbg(ar, ATH10K_DBG_MAC,
7380 "mac chanctx unassign ptr %pK vdev_id %i\n",
7381 ctx, arvif->vdev_id);
7383 WARN_ON(!arvif->is_started);
7385 if (vif->type == NL80211_IFTYPE_MONITOR) {
7386 WARN_ON(!arvif->is_up);
7388 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7390 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7391 arvif->vdev_id, ret);
7393 arvif->is_up = false;
7396 ret = ath10k_vdev_stop(arvif);
7398 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7399 arvif->vdev_id, ret);
7401 arvif->is_started = false;
7403 mutex_unlock(&ar->conf_mutex);
7407 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7408 struct ieee80211_vif_chanctx_switch *vifs,
7410 enum ieee80211_chanctx_switch_mode mode)
7412 struct ath10k *ar = hw->priv;
7414 mutex_lock(&ar->conf_mutex);
7416 ath10k_dbg(ar, ATH10K_DBG_MAC,
7417 "mac chanctx switch n_vifs %d mode %d\n",
7419 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7421 mutex_unlock(&ar->conf_mutex);
7425 static const struct ieee80211_ops ath10k_ops = {
7426 .tx = ath10k_mac_op_tx,
7427 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7428 .start = ath10k_start,
7429 .stop = ath10k_stop,
7430 .config = ath10k_config,
7431 .add_interface = ath10k_add_interface,
7432 .remove_interface = ath10k_remove_interface,
7433 .configure_filter = ath10k_configure_filter,
7434 .bss_info_changed = ath10k_bss_info_changed,
7435 .hw_scan = ath10k_hw_scan,
7436 .cancel_hw_scan = ath10k_cancel_hw_scan,
7437 .set_key = ath10k_set_key,
7438 .set_default_unicast_key = ath10k_set_default_unicast_key,
7439 .sta_state = ath10k_sta_state,
7440 .conf_tx = ath10k_conf_tx,
7441 .remain_on_channel = ath10k_remain_on_channel,
7442 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7443 .set_rts_threshold = ath10k_set_rts_threshold,
7444 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7445 .flush = ath10k_flush,
7446 .tx_last_beacon = ath10k_tx_last_beacon,
7447 .set_antenna = ath10k_set_antenna,
7448 .get_antenna = ath10k_get_antenna,
7449 .reconfig_complete = ath10k_reconfig_complete,
7450 .get_survey = ath10k_get_survey,
7451 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7452 .sta_rc_update = ath10k_sta_rc_update,
7453 .get_tsf = ath10k_get_tsf,
7454 .set_tsf = ath10k_set_tsf,
7455 .ampdu_action = ath10k_ampdu_action,
7456 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7457 .get_et_stats = ath10k_debug_get_et_stats,
7458 .get_et_strings = ath10k_debug_get_et_strings,
7459 .add_chanctx = ath10k_mac_op_add_chanctx,
7460 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7461 .change_chanctx = ath10k_mac_op_change_chanctx,
7462 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7463 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7464 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7466 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7469 .suspend = ath10k_wow_op_suspend,
7470 .resume = ath10k_wow_op_resume,
7472 #ifdef CONFIG_MAC80211_DEBUGFS
7473 .sta_add_debugfs = ath10k_sta_add_debugfs,
7474 .sta_statistics = ath10k_sta_statistics,
7478 #define CHAN2G(_channel, _freq, _flags) { \
7479 .band = NL80211_BAND_2GHZ, \
7480 .hw_value = (_channel), \
7481 .center_freq = (_freq), \
7482 .flags = (_flags), \
7483 .max_antenna_gain = 0, \
7487 #define CHAN5G(_channel, _freq, _flags) { \
7488 .band = NL80211_BAND_5GHZ, \
7489 .hw_value = (_channel), \
7490 .center_freq = (_freq), \
7491 .flags = (_flags), \
7492 .max_antenna_gain = 0, \
7496 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7506 CHAN2G(10, 2457, 0),
7507 CHAN2G(11, 2462, 0),
7508 CHAN2G(12, 2467, 0),
7509 CHAN2G(13, 2472, 0),
7510 CHAN2G(14, 2484, 0),
7513 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7514 CHAN5G(36, 5180, 0),
7515 CHAN5G(40, 5200, 0),
7516 CHAN5G(44, 5220, 0),
7517 CHAN5G(48, 5240, 0),
7518 CHAN5G(52, 5260, 0),
7519 CHAN5G(56, 5280, 0),
7520 CHAN5G(60, 5300, 0),
7521 CHAN5G(64, 5320, 0),
7522 CHAN5G(100, 5500, 0),
7523 CHAN5G(104, 5520, 0),
7524 CHAN5G(108, 5540, 0),
7525 CHAN5G(112, 5560, 0),
7526 CHAN5G(116, 5580, 0),
7527 CHAN5G(120, 5600, 0),
7528 CHAN5G(124, 5620, 0),
7529 CHAN5G(128, 5640, 0),
7530 CHAN5G(132, 5660, 0),
7531 CHAN5G(136, 5680, 0),
7532 CHAN5G(140, 5700, 0),
7533 CHAN5G(144, 5720, 0),
7534 CHAN5G(149, 5745, 0),
7535 CHAN5G(153, 5765, 0),
7536 CHAN5G(157, 5785, 0),
7537 CHAN5G(161, 5805, 0),
7538 CHAN5G(165, 5825, 0),
7541 struct ath10k *ath10k_mac_create(size_t priv_size)
7543 struct ieee80211_hw *hw;
7544 struct ieee80211_ops *ops;
7547 ops = kmemdup(&ath10k_ops, sizeof(ath10k_ops), GFP_KERNEL);
7551 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, ops);
7564 void ath10k_mac_destroy(struct ath10k *ar)
7566 struct ieee80211_ops *ops = ar->ops;
7568 ieee80211_free_hw(ar->hw);
7572 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7575 .types = BIT(NL80211_IFTYPE_STATION)
7576 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7580 .types = BIT(NL80211_IFTYPE_P2P_GO)
7584 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7588 .types = BIT(NL80211_IFTYPE_AP)
7589 #ifdef CONFIG_MAC80211_MESH
7590 | BIT(NL80211_IFTYPE_MESH_POINT)
7595 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7598 .types = BIT(NL80211_IFTYPE_AP)
7599 #ifdef CONFIG_MAC80211_MESH
7600 | BIT(NL80211_IFTYPE_MESH_POINT)
7605 .types = BIT(NL80211_IFTYPE_STATION)
7609 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7611 .limits = ath10k_if_limits,
7612 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7613 .max_interfaces = 8,
7614 .num_different_channels = 1,
7615 .beacon_int_infra_match = true,
7619 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7621 .limits = ath10k_10x_if_limits,
7622 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7623 .max_interfaces = 8,
7624 .num_different_channels = 1,
7625 .beacon_int_infra_match = true,
7626 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7627 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7628 BIT(NL80211_CHAN_WIDTH_20) |
7629 BIT(NL80211_CHAN_WIDTH_40) |
7630 BIT(NL80211_CHAN_WIDTH_80),
7635 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7638 .types = BIT(NL80211_IFTYPE_STATION),
7642 .types = BIT(NL80211_IFTYPE_AP) |
7643 #ifdef CONFIG_MAC80211_MESH
7644 BIT(NL80211_IFTYPE_MESH_POINT) |
7646 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7647 BIT(NL80211_IFTYPE_P2P_GO),
7651 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7655 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7658 .types = BIT(NL80211_IFTYPE_STATION),
7662 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7666 .types = BIT(NL80211_IFTYPE_AP) |
7667 #ifdef CONFIG_MAC80211_MESH
7668 BIT(NL80211_IFTYPE_MESH_POINT) |
7670 BIT(NL80211_IFTYPE_P2P_GO),
7674 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7678 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7681 .types = BIT(NL80211_IFTYPE_STATION),
7685 .types = BIT(NL80211_IFTYPE_ADHOC),
7689 /* FIXME: This is not thouroughly tested. These combinations may over- or
7690 * underestimate hw/fw capabilities.
7692 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7694 .limits = ath10k_tlv_if_limit,
7695 .num_different_channels = 1,
7696 .max_interfaces = 4,
7697 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7700 .limits = ath10k_tlv_if_limit_ibss,
7701 .num_different_channels = 1,
7702 .max_interfaces = 2,
7703 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7707 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7709 .limits = ath10k_tlv_if_limit,
7710 .num_different_channels = 1,
7711 .max_interfaces = 4,
7712 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7715 .limits = ath10k_tlv_qcs_if_limit,
7716 .num_different_channels = 2,
7717 .max_interfaces = 4,
7718 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7721 .limits = ath10k_tlv_if_limit_ibss,
7722 .num_different_channels = 1,
7723 .max_interfaces = 2,
7724 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7728 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7731 .types = BIT(NL80211_IFTYPE_STATION),
7735 .types = BIT(NL80211_IFTYPE_AP)
7736 #ifdef CONFIG_MAC80211_MESH
7737 | BIT(NL80211_IFTYPE_MESH_POINT)
7742 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7744 .limits = ath10k_10_4_if_limits,
7745 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7746 .max_interfaces = 16,
7747 .num_different_channels = 1,
7748 .beacon_int_infra_match = true,
7749 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7750 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7751 BIT(NL80211_CHAN_WIDTH_20) |
7752 BIT(NL80211_CHAN_WIDTH_40) |
7753 BIT(NL80211_CHAN_WIDTH_80),
7758 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7759 struct ieee80211_vif *vif)
7761 struct ath10k_vif_iter *arvif_iter = data;
7762 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7764 if (arvif->vdev_id == arvif_iter->vdev_id)
7765 arvif_iter->arvif = arvif;
7768 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7770 struct ath10k_vif_iter arvif_iter;
7773 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7774 arvif_iter.vdev_id = vdev_id;
7776 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7777 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7779 ath10k_get_arvif_iter,
7781 if (!arvif_iter.arvif) {
7782 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7786 return arvif_iter.arvif;
7789 int ath10k_mac_register(struct ath10k *ar)
7791 static const u32 cipher_suites[] = {
7792 WLAN_CIPHER_SUITE_WEP40,
7793 WLAN_CIPHER_SUITE_WEP104,
7794 WLAN_CIPHER_SUITE_TKIP,
7795 WLAN_CIPHER_SUITE_CCMP,
7796 WLAN_CIPHER_SUITE_AES_CMAC,
7798 struct ieee80211_supported_band *band;
7802 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
7804 SET_IEEE80211_DEV(ar->hw, ar->dev);
7806 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
7807 ARRAY_SIZE(ath10k_5ghz_channels)) !=
7810 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
7811 channels = kmemdup(ath10k_2ghz_channels,
7812 sizeof(ath10k_2ghz_channels),
7819 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
7820 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
7821 band->channels = channels;
7823 if (ar->hw_params.cck_rate_map_rev2) {
7824 band->n_bitrates = ath10k_g_rates_rev2_size;
7825 band->bitrates = ath10k_g_rates_rev2;
7827 band->n_bitrates = ath10k_g_rates_size;
7828 band->bitrates = ath10k_g_rates;
7831 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
7834 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
7835 channels = kmemdup(ath10k_5ghz_channels,
7836 sizeof(ath10k_5ghz_channels),
7843 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
7844 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
7845 band->channels = channels;
7846 band->n_bitrates = ath10k_a_rates_size;
7847 band->bitrates = ath10k_a_rates;
7848 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
7851 ath10k_mac_setup_ht_vht_cap(ar);
7853 ar->hw->wiphy->interface_modes =
7854 BIT(NL80211_IFTYPE_STATION) |
7855 BIT(NL80211_IFTYPE_AP) |
7856 BIT(NL80211_IFTYPE_MESH_POINT);
7858 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
7859 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
7861 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
7862 ar->hw->wiphy->interface_modes |=
7863 BIT(NL80211_IFTYPE_P2P_DEVICE) |
7864 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7865 BIT(NL80211_IFTYPE_P2P_GO);
7867 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
7868 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
7869 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
7870 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
7871 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
7872 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
7873 ieee80211_hw_set(ar->hw, AP_LINK_PS);
7874 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
7875 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
7876 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7877 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7878 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7879 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7880 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
7882 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7883 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7885 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
7886 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
7888 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
7889 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
7891 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
7892 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7893 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
7896 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7897 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7899 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
7900 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
7901 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
7903 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7905 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7906 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7908 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7909 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7910 * correct Probe Responses. This is more of a hack advert..
7912 ar->hw->wiphy->probe_resp_offload |=
7913 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7914 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7915 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
7918 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
7919 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7921 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
7922 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
7923 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
7925 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
7926 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
7927 NL80211_FEATURE_AP_SCAN;
7929 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
7931 ret = ath10k_wow_init(ar);
7933 ath10k_warn(ar, "failed to init wow: %d\n", ret);
7937 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
7940 * on LL hardware queues are managed entirely by the FW
7941 * so we only advertise to mac we can do the queues thing
7943 ar->hw->queues = IEEE80211_MAX_QUEUES;
7945 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7946 * something that vdev_ids can't reach so that we don't stop the queue
7949 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
7951 switch (ar->running_fw->fw_file.wmi_op_version) {
7952 case ATH10K_FW_WMI_OP_VERSION_MAIN:
7953 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7954 ar->hw->wiphy->n_iface_combinations =
7955 ARRAY_SIZE(ath10k_if_comb);
7956 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7958 case ATH10K_FW_WMI_OP_VERSION_TLV:
7959 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7960 ar->hw->wiphy->iface_combinations =
7961 ath10k_tlv_qcs_if_comb;
7962 ar->hw->wiphy->n_iface_combinations =
7963 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7965 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7966 ar->hw->wiphy->n_iface_combinations =
7967 ARRAY_SIZE(ath10k_tlv_if_comb);
7969 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7971 case ATH10K_FW_WMI_OP_VERSION_10_1:
7972 case ATH10K_FW_WMI_OP_VERSION_10_2:
7973 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7974 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7975 ar->hw->wiphy->n_iface_combinations =
7976 ARRAY_SIZE(ath10k_10x_if_comb);
7978 case ATH10K_FW_WMI_OP_VERSION_10_4:
7979 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7980 ar->hw->wiphy->n_iface_combinations =
7981 ARRAY_SIZE(ath10k_10_4_if_comb);
7983 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7984 case ATH10K_FW_WMI_OP_VERSION_MAX:
7990 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7991 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7993 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED)) {
7994 /* Init ath dfs pattern detector */
7995 ar->ath_common.debug_mask = ATH_DBG_DFS;
7996 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7999 if (!ar->dfs_detector)
8000 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
8003 /* Current wake_tx_queue implementation imposes a significant
8004 * performance penalty in some setups. The tx scheduling code needs
8005 * more work anyway so disable the wake_tx_queue unless firmware
8006 * supports the pull-push mechanism.
8008 if (!test_bit(ATH10K_FW_FEATURE_PEER_FLOW_CONTROL,
8009 ar->running_fw->fw_file.fw_features))
8010 ar->ops->wake_tx_queue = NULL;
8012 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
8013 ath10k_reg_notifier);
8015 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
8016 goto err_dfs_detector_exit;
8019 ar->hw->wiphy->cipher_suites = cipher_suites;
8020 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8022 ret = ieee80211_register_hw(ar->hw);
8024 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
8025 goto err_dfs_detector_exit;
8028 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
8029 ret = regulatory_hint(ar->hw->wiphy,
8030 ar->ath_common.regulatory.alpha2);
8032 goto err_unregister;
8038 ieee80211_unregister_hw(ar->hw);
8040 err_dfs_detector_exit:
8041 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8042 ar->dfs_detector->exit(ar->dfs_detector);
8045 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8046 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8048 SET_IEEE80211_DEV(ar->hw, NULL);
8052 void ath10k_mac_unregister(struct ath10k *ar)
8054 ieee80211_unregister_hw(ar->hw);
8056 if (IS_ENABLED(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
8057 ar->dfs_detector->exit(ar->dfs_detector);
8059 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8060 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8062 SET_IEEE80211_DEV(ar->hw, NULL);