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 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
67 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
70 #define ath10k_g_rates (ath10k_rates + 0)
71 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
73 static bool ath10k_mac_bitrate_is_cck(int bitrate)
86 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
88 return DIV_ROUND_UP(bitrate, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
92 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
95 const struct ieee80211_rate *rate;
98 for (i = 0; i < sband->n_bitrates; i++) {
99 rate = &sband->bitrates[i];
101 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
104 if (rate->hw_value == hw_rate)
106 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
107 rate->hw_value_short == hw_rate)
114 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
119 for (i = 0; i < sband->n_bitrates; i++)
120 if (sband->bitrates[i].bitrate == bitrate)
126 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
128 switch ((mcs_map >> (2 * nss)) & 0x3) {
129 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
130 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
131 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
137 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
141 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
142 if (ht_mcs_mask[nss])
149 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
153 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
154 if (vht_mcs_mask[nss])
160 int ath10k_mac_ext_resource_config(struct ath10k *ar, u32 val)
162 enum wmi_host_platform_type platform_type;
165 if (test_bit(WMI_SERVICE_TX_MODE_DYNAMIC, ar->wmi.svc_map))
166 platform_type = WMI_HOST_PLATFORM_LOW_PERF;
168 platform_type = WMI_HOST_PLATFORM_HIGH_PERF;
170 ret = ath10k_wmi_ext_resource_config(ar, platform_type, val);
172 if (ret && ret != -EOPNOTSUPP) {
173 ath10k_warn(ar, "failed to configure ext resource: %d\n", ret);
184 static int ath10k_send_key(struct ath10k_vif *arvif,
185 struct ieee80211_key_conf *key,
186 enum set_key_cmd cmd,
187 const u8 *macaddr, u32 flags)
189 struct ath10k *ar = arvif->ar;
190 struct wmi_vdev_install_key_arg arg = {
191 .vdev_id = arvif->vdev_id,
192 .key_idx = key->keyidx,
193 .key_len = key->keylen,
194 .key_data = key->key,
199 lockdep_assert_held(&arvif->ar->conf_mutex);
201 switch (key->cipher) {
202 case WLAN_CIPHER_SUITE_CCMP:
203 arg.key_cipher = WMI_CIPHER_AES_CCM;
204 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
206 case WLAN_CIPHER_SUITE_TKIP:
207 arg.key_cipher = WMI_CIPHER_TKIP;
208 arg.key_txmic_len = 8;
209 arg.key_rxmic_len = 8;
211 case WLAN_CIPHER_SUITE_WEP40:
212 case WLAN_CIPHER_SUITE_WEP104:
213 arg.key_cipher = WMI_CIPHER_WEP;
215 case WLAN_CIPHER_SUITE_AES_CMAC:
219 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
223 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
224 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
226 if (cmd == DISABLE_KEY) {
227 arg.key_cipher = WMI_CIPHER_NONE;
231 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
234 static int ath10k_install_key(struct ath10k_vif *arvif,
235 struct ieee80211_key_conf *key,
236 enum set_key_cmd cmd,
237 const u8 *macaddr, u32 flags)
239 struct ath10k *ar = arvif->ar;
241 unsigned long time_left;
243 lockdep_assert_held(&ar->conf_mutex);
245 reinit_completion(&ar->install_key_done);
247 if (arvif->nohwcrypt)
250 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
254 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
261 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
264 struct ath10k *ar = arvif->ar;
265 struct ath10k_peer *peer;
270 lockdep_assert_held(&ar->conf_mutex);
272 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
273 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
274 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
277 spin_lock_bh(&ar->data_lock);
278 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
279 spin_unlock_bh(&ar->data_lock);
284 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
285 if (arvif->wep_keys[i] == NULL)
288 switch (arvif->vif->type) {
289 case NL80211_IFTYPE_AP:
290 flags = WMI_KEY_PAIRWISE;
292 if (arvif->def_wep_key_idx == i)
293 flags |= WMI_KEY_TX_USAGE;
295 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
296 SET_KEY, addr, flags);
300 case NL80211_IFTYPE_ADHOC:
301 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
307 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
308 SET_KEY, addr, WMI_KEY_GROUP);
317 spin_lock_bh(&ar->data_lock);
318 peer->keys[i] = arvif->wep_keys[i];
319 spin_unlock_bh(&ar->data_lock);
322 /* In some cases (notably with static WEP IBSS with multiple keys)
323 * multicast Tx becomes broken. Both pairwise and groupwise keys are
324 * installed already. Using WMI_KEY_TX_USAGE in different combinations
325 * didn't seem help. Using def_keyid vdev parameter seems to be
326 * effective so use that.
328 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
330 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
333 if (arvif->def_wep_key_idx == -1)
336 ret = ath10k_wmi_vdev_set_param(arvif->ar,
338 arvif->ar->wmi.vdev_param->def_keyid,
339 arvif->def_wep_key_idx);
341 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
342 arvif->vdev_id, ret);
349 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
352 struct ath10k *ar = arvif->ar;
353 struct ath10k_peer *peer;
359 lockdep_assert_held(&ar->conf_mutex);
361 spin_lock_bh(&ar->data_lock);
362 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
363 spin_unlock_bh(&ar->data_lock);
368 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
369 if (peer->keys[i] == NULL)
372 /* key flags are not required to delete the key */
373 ret = ath10k_install_key(arvif, peer->keys[i],
374 DISABLE_KEY, addr, flags);
375 if (ret < 0 && first_errno == 0)
379 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
382 spin_lock_bh(&ar->data_lock);
383 peer->keys[i] = NULL;
384 spin_unlock_bh(&ar->data_lock);
390 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
393 struct ath10k_peer *peer;
396 lockdep_assert_held(&ar->data_lock);
398 /* We don't know which vdev this peer belongs to,
399 * since WMI doesn't give us that information.
401 * FIXME: multi-bss needs to be handled.
403 peer = ath10k_peer_find(ar, 0, addr);
407 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
408 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
415 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
416 struct ieee80211_key_conf *key)
418 struct ath10k *ar = arvif->ar;
419 struct ath10k_peer *peer;
426 lockdep_assert_held(&ar->conf_mutex);
429 /* since ath10k_install_key we can't hold data_lock all the
430 * time, so we try to remove the keys incrementally */
431 spin_lock_bh(&ar->data_lock);
433 list_for_each_entry(peer, &ar->peers, list) {
434 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
435 if (peer->keys[i] == key) {
436 ether_addr_copy(addr, peer->addr);
437 peer->keys[i] = NULL;
442 if (i < ARRAY_SIZE(peer->keys))
445 spin_unlock_bh(&ar->data_lock);
447 if (i == ARRAY_SIZE(peer->keys))
449 /* key flags are not required to delete the key */
450 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
451 if (ret < 0 && first_errno == 0)
455 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
462 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
463 struct ieee80211_key_conf *key)
465 struct ath10k *ar = arvif->ar;
466 struct ath10k_peer *peer;
469 lockdep_assert_held(&ar->conf_mutex);
471 list_for_each_entry(peer, &ar->peers, list) {
472 if (ether_addr_equal(peer->addr, arvif->vif->addr))
475 if (ether_addr_equal(peer->addr, arvif->bssid))
478 if (peer->keys[key->keyidx] == key)
481 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
482 arvif->vdev_id, key->keyidx);
484 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
486 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
487 arvif->vdev_id, peer->addr, ret);
495 /*********************/
496 /* General utilities */
497 /*********************/
499 static inline enum wmi_phy_mode
500 chan_to_phymode(const struct cfg80211_chan_def *chandef)
502 enum wmi_phy_mode phymode = MODE_UNKNOWN;
504 switch (chandef->chan->band) {
505 case IEEE80211_BAND_2GHZ:
506 switch (chandef->width) {
507 case NL80211_CHAN_WIDTH_20_NOHT:
508 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
513 case NL80211_CHAN_WIDTH_20:
514 phymode = MODE_11NG_HT20;
516 case NL80211_CHAN_WIDTH_40:
517 phymode = MODE_11NG_HT40;
519 case NL80211_CHAN_WIDTH_5:
520 case NL80211_CHAN_WIDTH_10:
521 case NL80211_CHAN_WIDTH_80:
522 case NL80211_CHAN_WIDTH_80P80:
523 case NL80211_CHAN_WIDTH_160:
524 phymode = MODE_UNKNOWN;
528 case IEEE80211_BAND_5GHZ:
529 switch (chandef->width) {
530 case NL80211_CHAN_WIDTH_20_NOHT:
533 case NL80211_CHAN_WIDTH_20:
534 phymode = MODE_11NA_HT20;
536 case NL80211_CHAN_WIDTH_40:
537 phymode = MODE_11NA_HT40;
539 case NL80211_CHAN_WIDTH_80:
540 phymode = MODE_11AC_VHT80;
542 case NL80211_CHAN_WIDTH_5:
543 case NL80211_CHAN_WIDTH_10:
544 case NL80211_CHAN_WIDTH_80P80:
545 case NL80211_CHAN_WIDTH_160:
546 phymode = MODE_UNKNOWN;
554 WARN_ON(phymode == MODE_UNKNOWN);
558 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
561 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
562 * 0 for no restriction
571 switch (mpdudensity) {
577 /* Our lower layer calculations limit our precision to
593 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
594 struct cfg80211_chan_def *def)
596 struct ieee80211_chanctx_conf *conf;
599 conf = rcu_dereference(vif->chanctx_conf);
611 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
612 struct ieee80211_chanctx_conf *conf,
620 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
624 ieee80211_iter_chan_contexts_atomic(ar->hw,
625 ath10k_mac_num_chanctxs_iter,
632 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
633 struct ieee80211_chanctx_conf *conf,
636 struct cfg80211_chan_def **def = data;
641 static int ath10k_peer_create(struct ath10k *ar,
642 struct ieee80211_vif *vif,
643 struct ieee80211_sta *sta,
646 enum wmi_peer_type peer_type)
648 struct ath10k_vif *arvif;
649 struct ath10k_peer *peer;
653 lockdep_assert_held(&ar->conf_mutex);
655 num_peers = ar->num_peers;
657 /* Each vdev consumes a peer entry as well */
658 list_for_each_entry(arvif, &ar->arvifs, list)
661 if (num_peers >= ar->max_num_peers)
664 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
666 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
671 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
673 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
678 spin_lock_bh(&ar->data_lock);
680 peer = ath10k_peer_find(ar, vdev_id, addr);
682 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
684 ath10k_wmi_peer_delete(ar, vdev_id, addr);
685 spin_unlock_bh(&ar->data_lock);
692 spin_unlock_bh(&ar->data_lock);
699 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
701 struct ath10k *ar = arvif->ar;
705 param = ar->wmi.pdev_param->sta_kickout_th;
706 ret = ath10k_wmi_pdev_set_param(ar, param,
707 ATH10K_KICKOUT_THRESHOLD);
709 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
710 arvif->vdev_id, ret);
714 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
715 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
716 ATH10K_KEEPALIVE_MIN_IDLE);
718 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
719 arvif->vdev_id, ret);
723 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
724 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
725 ATH10K_KEEPALIVE_MAX_IDLE);
727 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
728 arvif->vdev_id, ret);
732 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
733 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
734 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
736 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
737 arvif->vdev_id, ret);
744 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
746 struct ath10k *ar = arvif->ar;
749 vdev_param = ar->wmi.vdev_param->rts_threshold;
750 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
753 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
757 lockdep_assert_held(&ar->conf_mutex);
759 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
763 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
772 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
774 struct ath10k_peer *peer, *tmp;
777 lockdep_assert_held(&ar->conf_mutex);
779 spin_lock_bh(&ar->data_lock);
780 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
781 if (peer->vdev_id != vdev_id)
784 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
785 peer->addr, vdev_id);
787 for_each_set_bit(peer_id, peer->peer_ids,
788 ATH10K_MAX_NUM_PEER_IDS) {
789 ar->peer_map[peer_id] = NULL;
792 list_del(&peer->list);
796 spin_unlock_bh(&ar->data_lock);
799 static void ath10k_peer_cleanup_all(struct ath10k *ar)
801 struct ath10k_peer *peer, *tmp;
803 lockdep_assert_held(&ar->conf_mutex);
805 spin_lock_bh(&ar->data_lock);
806 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
807 list_del(&peer->list);
810 spin_unlock_bh(&ar->data_lock);
813 ar->num_stations = 0;
816 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
817 struct ieee80211_sta *sta,
818 enum wmi_tdls_peer_state state)
821 struct wmi_tdls_peer_update_cmd_arg arg = {};
822 struct wmi_tdls_peer_capab_arg cap = {};
823 struct wmi_channel_arg chan_arg = {};
825 lockdep_assert_held(&ar->conf_mutex);
827 arg.vdev_id = vdev_id;
828 arg.peer_state = state;
829 ether_addr_copy(arg.addr, sta->addr);
831 cap.peer_max_sp = sta->max_sp;
832 cap.peer_uapsd_queues = sta->uapsd_queues;
834 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
835 !sta->tdls_initiator)
836 cap.is_peer_responder = 1;
838 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
840 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
841 arg.addr, vdev_id, ret);
848 /************************/
849 /* Interface management */
850 /************************/
852 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
854 struct ath10k *ar = arvif->ar;
856 lockdep_assert_held(&ar->data_lock);
861 if (!arvif->beacon_buf)
862 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
863 arvif->beacon->len, DMA_TO_DEVICE);
865 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
866 arvif->beacon_state != ATH10K_BEACON_SENT))
869 dev_kfree_skb_any(arvif->beacon);
871 arvif->beacon = NULL;
872 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
875 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
877 struct ath10k *ar = arvif->ar;
879 lockdep_assert_held(&ar->data_lock);
881 ath10k_mac_vif_beacon_free(arvif);
883 if (arvif->beacon_buf) {
884 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
885 arvif->beacon_buf, arvif->beacon_paddr);
886 arvif->beacon_buf = NULL;
890 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
892 unsigned long time_left;
894 lockdep_assert_held(&ar->conf_mutex);
896 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
899 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
900 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
907 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
909 struct cfg80211_chan_def *chandef = NULL;
910 struct ieee80211_channel *channel = NULL;
911 struct wmi_vdev_start_request_arg arg = {};
914 lockdep_assert_held(&ar->conf_mutex);
916 ieee80211_iter_chan_contexts_atomic(ar->hw,
917 ath10k_mac_get_any_chandef_iter,
919 if (WARN_ON_ONCE(!chandef))
922 channel = chandef->chan;
924 arg.vdev_id = vdev_id;
925 arg.channel.freq = channel->center_freq;
926 arg.channel.band_center_freq1 = chandef->center_freq1;
928 /* TODO setup this dynamically, what in case we
929 don't have any vifs? */
930 arg.channel.mode = chan_to_phymode(chandef);
931 arg.channel.chan_radar =
932 !!(channel->flags & IEEE80211_CHAN_RADAR);
934 arg.channel.min_power = 0;
935 arg.channel.max_power = channel->max_power * 2;
936 arg.channel.max_reg_power = channel->max_reg_power * 2;
937 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
939 reinit_completion(&ar->vdev_setup_done);
941 ret = ath10k_wmi_vdev_start(ar, &arg);
943 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
948 ret = ath10k_vdev_setup_sync(ar);
950 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
955 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
957 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
962 ar->monitor_vdev_id = vdev_id;
964 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
965 ar->monitor_vdev_id);
969 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
971 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
972 ar->monitor_vdev_id, ret);
977 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
981 lockdep_assert_held(&ar->conf_mutex);
983 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
985 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
986 ar->monitor_vdev_id, ret);
988 reinit_completion(&ar->vdev_setup_done);
990 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
992 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
993 ar->monitor_vdev_id, ret);
995 ret = ath10k_vdev_setup_sync(ar);
997 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
998 ar->monitor_vdev_id, ret);
1000 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
1001 ar->monitor_vdev_id);
1005 static int ath10k_monitor_vdev_create(struct ath10k *ar)
1009 lockdep_assert_held(&ar->conf_mutex);
1011 if (ar->free_vdev_map == 0) {
1012 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
1016 bit = __ffs64(ar->free_vdev_map);
1018 ar->monitor_vdev_id = bit;
1020 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1021 WMI_VDEV_TYPE_MONITOR,
1024 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1025 ar->monitor_vdev_id, ret);
1029 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1030 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1031 ar->monitor_vdev_id);
1036 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1040 lockdep_assert_held(&ar->conf_mutex);
1042 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1044 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1045 ar->monitor_vdev_id, ret);
1049 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1051 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1052 ar->monitor_vdev_id);
1056 static int ath10k_monitor_start(struct ath10k *ar)
1060 lockdep_assert_held(&ar->conf_mutex);
1062 ret = ath10k_monitor_vdev_create(ar);
1064 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1068 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1070 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1071 ath10k_monitor_vdev_delete(ar);
1075 ar->monitor_started = true;
1076 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1081 static int ath10k_monitor_stop(struct ath10k *ar)
1085 lockdep_assert_held(&ar->conf_mutex);
1087 ret = ath10k_monitor_vdev_stop(ar);
1089 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1093 ret = ath10k_monitor_vdev_delete(ar);
1095 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1099 ar->monitor_started = false;
1100 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1105 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1109 /* At least one chanctx is required to derive a channel to start
1112 num_ctx = ath10k_mac_num_chanctxs(ar);
1116 /* If there's already an existing special monitor interface then don't
1117 * bother creating another monitor vdev.
1119 if (ar->monitor_arvif)
1122 return ar->monitor ||
1123 ar->filter_flags & FIF_OTHER_BSS ||
1124 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1127 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1131 num_ctx = ath10k_mac_num_chanctxs(ar);
1133 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1134 * shouldn't allow this but make sure to prevent handling the following
1135 * case anyway since multi-channel DFS hasn't been tested at all.
1137 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1143 static int ath10k_monitor_recalc(struct ath10k *ar)
1149 lockdep_assert_held(&ar->conf_mutex);
1151 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1152 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1154 ath10k_dbg(ar, ATH10K_DBG_MAC,
1155 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1156 ar->monitor_started, needed, allowed);
1158 if (WARN_ON(needed && !allowed)) {
1159 if (ar->monitor_started) {
1160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1162 ret = ath10k_monitor_stop(ar);
1164 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1172 if (needed == ar->monitor_started)
1176 return ath10k_monitor_start(ar);
1178 return ath10k_monitor_stop(ar);
1181 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1183 struct ath10k *ar = arvif->ar;
1184 u32 vdev_param, rts_cts = 0;
1186 lockdep_assert_held(&ar->conf_mutex);
1188 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1190 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1192 if (arvif->num_legacy_stations > 0)
1193 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1194 WMI_RTSCTS_PROFILE);
1196 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1197 WMI_RTSCTS_PROFILE);
1199 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1203 static int ath10k_start_cac(struct ath10k *ar)
1207 lockdep_assert_held(&ar->conf_mutex);
1209 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1211 ret = ath10k_monitor_recalc(ar);
1213 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1214 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1218 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1219 ar->monitor_vdev_id);
1224 static int ath10k_stop_cac(struct ath10k *ar)
1226 lockdep_assert_held(&ar->conf_mutex);
1228 /* CAC is not running - do nothing */
1229 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1232 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1233 ath10k_monitor_stop(ar);
1235 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1240 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1241 struct ieee80211_chanctx_conf *conf,
1246 if (!*ret && conf->radar_enabled)
1250 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1252 bool has_radar = false;
1254 ieee80211_iter_chan_contexts_atomic(ar->hw,
1255 ath10k_mac_has_radar_iter,
1261 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1265 lockdep_assert_held(&ar->conf_mutex);
1267 ath10k_stop_cac(ar);
1269 if (!ath10k_mac_has_radar_enabled(ar))
1272 if (ar->num_started_vdevs > 0)
1275 ret = ath10k_start_cac(ar);
1278 * Not possible to start CAC on current channel so starting
1279 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1280 * by indicating that radar was detected.
1282 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1283 ieee80211_radar_detected(ar->hw);
1287 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1289 struct ath10k *ar = arvif->ar;
1292 lockdep_assert_held(&ar->conf_mutex);
1294 reinit_completion(&ar->vdev_setup_done);
1296 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1298 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1299 arvif->vdev_id, ret);
1303 ret = ath10k_vdev_setup_sync(ar);
1305 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1306 arvif->vdev_id, ret);
1310 WARN_ON(ar->num_started_vdevs == 0);
1312 if (ar->num_started_vdevs != 0) {
1313 ar->num_started_vdevs--;
1314 ath10k_recalc_radar_detection(ar);
1320 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1321 const struct cfg80211_chan_def *chandef,
1324 struct ath10k *ar = arvif->ar;
1325 struct wmi_vdev_start_request_arg arg = {};
1328 lockdep_assert_held(&ar->conf_mutex);
1330 reinit_completion(&ar->vdev_setup_done);
1332 arg.vdev_id = arvif->vdev_id;
1333 arg.dtim_period = arvif->dtim_period;
1334 arg.bcn_intval = arvif->beacon_interval;
1336 arg.channel.freq = chandef->chan->center_freq;
1337 arg.channel.band_center_freq1 = chandef->center_freq1;
1338 arg.channel.mode = chan_to_phymode(chandef);
1340 arg.channel.min_power = 0;
1341 arg.channel.max_power = chandef->chan->max_power * 2;
1342 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1343 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1345 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1346 arg.ssid = arvif->u.ap.ssid;
1347 arg.ssid_len = arvif->u.ap.ssid_len;
1348 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1350 /* For now allow DFS for AP mode */
1351 arg.channel.chan_radar =
1352 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1353 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1354 arg.ssid = arvif->vif->bss_conf.ssid;
1355 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1358 ath10k_dbg(ar, ATH10K_DBG_MAC,
1359 "mac vdev %d start center_freq %d phymode %s\n",
1360 arg.vdev_id, arg.channel.freq,
1361 ath10k_wmi_phymode_str(arg.channel.mode));
1364 ret = ath10k_wmi_vdev_restart(ar, &arg);
1366 ret = ath10k_wmi_vdev_start(ar, &arg);
1369 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1374 ret = ath10k_vdev_setup_sync(ar);
1377 "failed to synchronize setup for vdev %i restart %d: %d\n",
1378 arg.vdev_id, restart, ret);
1382 ar->num_started_vdevs++;
1383 ath10k_recalc_radar_detection(ar);
1388 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1389 const struct cfg80211_chan_def *def)
1391 return ath10k_vdev_start_restart(arvif, def, false);
1394 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1395 const struct cfg80211_chan_def *def)
1397 return ath10k_vdev_start_restart(arvif, def, true);
1400 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1401 struct sk_buff *bcn)
1403 struct ath10k *ar = arvif->ar;
1404 struct ieee80211_mgmt *mgmt;
1408 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1411 mgmt = (void *)bcn->data;
1412 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1413 mgmt->u.beacon.variable,
1414 bcn->len - (mgmt->u.beacon.variable -
1419 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1421 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1422 arvif->vdev_id, ret);
1429 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1430 u8 oui_type, size_t ie_offset)
1437 if (WARN_ON(skb->len < ie_offset))
1440 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1441 skb->data + ie_offset,
1442 skb->len - ie_offset);
1447 end = skb->data + skb->len;
1450 if (WARN_ON(next > end))
1453 memmove(ie, next, end - next);
1454 skb_trim(skb, skb->len - len);
1459 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1461 struct ath10k *ar = arvif->ar;
1462 struct ieee80211_hw *hw = ar->hw;
1463 struct ieee80211_vif *vif = arvif->vif;
1464 struct ieee80211_mutable_offsets offs = {};
1465 struct sk_buff *bcn;
1468 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1471 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1472 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1475 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1477 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1481 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1483 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1488 /* P2P IE is inserted by firmware automatically (as configured above)
1489 * so remove it from the base beacon template to avoid duplicate P2P
1490 * IEs in beacon frames.
1492 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1493 offsetof(struct ieee80211_mgmt,
1494 u.beacon.variable));
1496 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1501 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1509 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1511 struct ath10k *ar = arvif->ar;
1512 struct ieee80211_hw *hw = ar->hw;
1513 struct ieee80211_vif *vif = arvif->vif;
1514 struct sk_buff *prb;
1517 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1520 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1523 prb = ieee80211_proberesp_get(hw, vif);
1525 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1529 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1533 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1541 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1543 struct ath10k *ar = arvif->ar;
1544 struct cfg80211_chan_def def;
1547 /* When originally vdev is started during assign_vif_chanctx() some
1548 * information is missing, notably SSID. Firmware revisions with beacon
1549 * offloading require the SSID to be provided during vdev (re)start to
1550 * handle hidden SSID properly.
1552 * Vdev restart must be done after vdev has been both started and
1553 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1554 * deliver vdev restart response event causing timeouts during vdev
1555 * syncing in ath10k.
1557 * Note: The vdev down/up and template reinstallation could be skipped
1558 * since only wmi-tlv firmware are known to have beacon offload and
1559 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1560 * response delivery. It's probably more robust to keep it as is.
1562 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1565 if (WARN_ON(!arvif->is_started))
1568 if (WARN_ON(!arvif->is_up))
1571 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1574 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1576 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1577 arvif->vdev_id, ret);
1581 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1582 * firmware will crash upon vdev up.
1585 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1587 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1591 ret = ath10k_mac_setup_prb_tmpl(arvif);
1593 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1597 ret = ath10k_vdev_restart(arvif, &def);
1599 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1600 arvif->vdev_id, ret);
1604 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1607 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1608 arvif->vdev_id, ret);
1615 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1616 struct ieee80211_bss_conf *info)
1618 struct ath10k *ar = arvif->ar;
1621 lockdep_assert_held(&arvif->ar->conf_mutex);
1623 if (!info->enable_beacon) {
1624 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1626 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1627 arvif->vdev_id, ret);
1629 arvif->is_up = false;
1631 spin_lock_bh(&arvif->ar->data_lock);
1632 ath10k_mac_vif_beacon_free(arvif);
1633 spin_unlock_bh(&arvif->ar->data_lock);
1638 arvif->tx_seq_no = 0x1000;
1641 ether_addr_copy(arvif->bssid, info->bssid);
1643 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1646 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1647 arvif->vdev_id, ret);
1651 arvif->is_up = true;
1653 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1655 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1656 arvif->vdev_id, ret);
1660 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1663 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1664 struct ieee80211_bss_conf *info,
1665 const u8 self_peer[ETH_ALEN])
1667 struct ath10k *ar = arvif->ar;
1671 lockdep_assert_held(&arvif->ar->conf_mutex);
1673 if (!info->ibss_joined) {
1674 if (is_zero_ether_addr(arvif->bssid))
1677 eth_zero_addr(arvif->bssid);
1682 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1683 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1684 ATH10K_DEFAULT_ATIM);
1686 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1687 arvif->vdev_id, ret);
1690 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1692 struct ath10k *ar = arvif->ar;
1697 lockdep_assert_held(&arvif->ar->conf_mutex);
1699 if (arvif->u.sta.uapsd)
1700 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1702 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1704 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1705 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1707 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1708 value, arvif->vdev_id, ret);
1715 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1717 struct ath10k *ar = arvif->ar;
1722 lockdep_assert_held(&arvif->ar->conf_mutex);
1724 if (arvif->u.sta.uapsd)
1725 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1727 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1729 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1730 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1733 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1734 value, arvif->vdev_id, ret);
1741 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1743 struct ath10k_vif *arvif;
1746 lockdep_assert_held(&ar->conf_mutex);
1748 list_for_each_entry(arvif, &ar->arvifs, list)
1749 if (arvif->is_started)
1755 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1757 struct ath10k *ar = arvif->ar;
1758 struct ieee80211_vif *vif = arvif->vif;
1759 struct ieee80211_conf *conf = &ar->hw->conf;
1760 enum wmi_sta_powersave_param param;
1761 enum wmi_sta_ps_mode psmode;
1766 lockdep_assert_held(&arvif->ar->conf_mutex);
1768 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1771 enable_ps = arvif->ps;
1773 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1774 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1775 ar->running_fw->fw_file.fw_features)) {
1776 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1781 if (!arvif->is_started) {
1782 /* mac80211 can update vif powersave state while disconnected.
1783 * Firmware doesn't behave nicely and consumes more power than
1784 * necessary if PS is disabled on a non-started vdev. Hence
1785 * force-enable PS for non-running vdevs.
1787 psmode = WMI_STA_PS_MODE_ENABLED;
1788 } else if (enable_ps) {
1789 psmode = WMI_STA_PS_MODE_ENABLED;
1790 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1792 ps_timeout = conf->dynamic_ps_timeout;
1793 if (ps_timeout == 0) {
1794 /* Firmware doesn't like 0 */
1795 ps_timeout = ieee80211_tu_to_usec(
1796 vif->bss_conf.beacon_int) / 1000;
1799 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1802 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1803 arvif->vdev_id, ret);
1807 psmode = WMI_STA_PS_MODE_DISABLED;
1810 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1811 arvif->vdev_id, psmode ? "enable" : "disable");
1813 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1815 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1816 psmode, arvif->vdev_id, ret);
1823 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1825 struct ath10k *ar = arvif->ar;
1826 struct wmi_sta_keepalive_arg arg = {};
1829 lockdep_assert_held(&arvif->ar->conf_mutex);
1831 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1834 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1837 /* Some firmware revisions have a bug and ignore the `enabled` field.
1838 * Instead use the interval to disable the keepalive.
1840 arg.vdev_id = arvif->vdev_id;
1842 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1843 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1845 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1847 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1848 arvif->vdev_id, ret);
1855 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1857 struct ath10k *ar = arvif->ar;
1858 struct ieee80211_vif *vif = arvif->vif;
1861 lockdep_assert_held(&arvif->ar->conf_mutex);
1863 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1866 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1869 if (!vif->csa_active)
1875 if (!ieee80211_csa_is_complete(vif)) {
1876 ieee80211_csa_update_counter(vif);
1878 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1880 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1883 ret = ath10k_mac_setup_prb_tmpl(arvif);
1885 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1888 ieee80211_csa_finish(vif);
1892 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1894 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1896 struct ath10k *ar = arvif->ar;
1898 mutex_lock(&ar->conf_mutex);
1899 ath10k_mac_vif_ap_csa_count_down(arvif);
1900 mutex_unlock(&ar->conf_mutex);
1903 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1904 struct ieee80211_vif *vif)
1906 struct sk_buff *skb = data;
1907 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1908 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1910 if (vif->type != NL80211_IFTYPE_STATION)
1913 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1916 cancel_delayed_work(&arvif->connection_loss_work);
1919 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1921 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1922 IEEE80211_IFACE_ITER_NORMAL,
1923 ath10k_mac_handle_beacon_iter,
1927 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1928 struct ieee80211_vif *vif)
1930 u32 *vdev_id = data;
1931 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1932 struct ath10k *ar = arvif->ar;
1933 struct ieee80211_hw *hw = ar->hw;
1935 if (arvif->vdev_id != *vdev_id)
1941 ieee80211_beacon_loss(vif);
1943 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1944 * (done by mac80211) succeeds but beacons do not resume then it
1945 * doesn't make sense to continue operation. Queue connection loss work
1946 * which can be cancelled when beacon is received.
1948 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1949 ATH10K_CONNECTION_LOSS_HZ);
1952 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1954 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1955 IEEE80211_IFACE_ITER_NORMAL,
1956 ath10k_mac_handle_beacon_miss_iter,
1960 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1962 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1963 connection_loss_work.work);
1964 struct ieee80211_vif *vif = arvif->vif;
1969 ieee80211_connection_loss(vif);
1972 /**********************/
1973 /* Station management */
1974 /**********************/
1976 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1977 struct ieee80211_vif *vif)
1979 /* Some firmware revisions have unstable STA powersave when listen
1980 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1981 * generate NullFunc frames properly even if buffered frames have been
1982 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1983 * buffered frames. Often pinging the device from AP would simply fail.
1985 * As a workaround set it to 1.
1987 if (vif->type == NL80211_IFTYPE_STATION)
1990 return ar->hw->conf.listen_interval;
1993 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1994 struct ieee80211_vif *vif,
1995 struct ieee80211_sta *sta,
1996 struct wmi_peer_assoc_complete_arg *arg)
1998 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2001 lockdep_assert_held(&ar->conf_mutex);
2003 if (vif->type == NL80211_IFTYPE_STATION)
2004 aid = vif->bss_conf.aid;
2008 ether_addr_copy(arg->addr, sta->addr);
2009 arg->vdev_id = arvif->vdev_id;
2010 arg->peer_aid = aid;
2011 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
2012 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
2013 arg->peer_num_spatial_streams = 1;
2014 arg->peer_caps = vif->bss_conf.assoc_capability;
2017 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2018 struct ieee80211_vif *vif,
2019 struct ieee80211_sta *sta,
2020 struct wmi_peer_assoc_complete_arg *arg)
2022 struct ieee80211_bss_conf *info = &vif->bss_conf;
2023 struct cfg80211_chan_def def;
2024 struct cfg80211_bss *bss;
2025 const u8 *rsnie = NULL;
2026 const u8 *wpaie = NULL;
2028 lockdep_assert_held(&ar->conf_mutex);
2030 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2033 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2034 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2036 const struct cfg80211_bss_ies *ies;
2039 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2041 ies = rcu_dereference(bss->ies);
2043 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2044 WLAN_OUI_TYPE_MICROSOFT_WPA,
2048 cfg80211_put_bss(ar->hw->wiphy, bss);
2051 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2052 if (rsnie || wpaie) {
2053 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2054 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2058 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2059 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2063 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT,
2064 ar->running_fw->fw_file.fw_features)) {
2065 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2069 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2070 struct ieee80211_vif *vif,
2071 struct ieee80211_sta *sta,
2072 struct wmi_peer_assoc_complete_arg *arg)
2074 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2075 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2076 struct cfg80211_chan_def def;
2077 const struct ieee80211_supported_band *sband;
2078 const struct ieee80211_rate *rates;
2079 enum ieee80211_band band;
2084 lockdep_assert_held(&ar->conf_mutex);
2086 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2089 band = def.chan->band;
2090 sband = ar->hw->wiphy->bands[band];
2091 ratemask = sta->supp_rates[band];
2092 ratemask &= arvif->bitrate_mask.control[band].legacy;
2093 rates = sband->bitrates;
2095 rateset->num_rates = 0;
2097 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2098 if (!(ratemask & 1))
2101 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2102 rateset->rates[rateset->num_rates] = rate;
2103 rateset->num_rates++;
2108 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2112 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2113 if (ht_mcs_mask[nss])
2120 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2124 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2125 if (vht_mcs_mask[nss])
2131 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2132 struct ieee80211_vif *vif,
2133 struct ieee80211_sta *sta,
2134 struct wmi_peer_assoc_complete_arg *arg)
2136 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2137 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2138 struct cfg80211_chan_def def;
2139 enum ieee80211_band band;
2140 const u8 *ht_mcs_mask;
2141 const u16 *vht_mcs_mask;
2146 lockdep_assert_held(&ar->conf_mutex);
2148 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2151 if (!ht_cap->ht_supported)
2154 band = def.chan->band;
2155 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2156 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2158 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2159 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2162 arg->peer_flags |= ar->wmi.peer_flags->ht;
2163 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2164 ht_cap->ampdu_factor)) - 1;
2166 arg->peer_mpdu_density =
2167 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2169 arg->peer_ht_caps = ht_cap->cap;
2170 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2172 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2173 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2175 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2176 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2177 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2180 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2181 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2182 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2184 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2185 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2188 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2189 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2190 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2193 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2194 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2195 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2196 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2197 arg->peer_rate_caps |= stbc;
2198 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2201 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2202 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2203 else if (ht_cap->mcs.rx_mask[1])
2204 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2206 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2207 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2208 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2209 max_nss = (i / 8) + 1;
2210 arg->peer_ht_rates.rates[n++] = i;
2214 * This is a workaround for HT-enabled STAs which break the spec
2215 * and have no HT capabilities RX mask (no HT RX MCS map).
2217 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2218 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2220 * Firmware asserts if such situation occurs.
2223 arg->peer_ht_rates.num_rates = 8;
2224 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2225 arg->peer_ht_rates.rates[i] = i;
2227 arg->peer_ht_rates.num_rates = n;
2228 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2233 arg->peer_ht_rates.num_rates,
2234 arg->peer_num_spatial_streams);
2237 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2238 struct ath10k_vif *arvif,
2239 struct ieee80211_sta *sta)
2245 lockdep_assert_held(&ar->conf_mutex);
2247 if (sta->wme && sta->uapsd_queues) {
2248 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2249 sta->uapsd_queues, sta->max_sp);
2251 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2252 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2253 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2254 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2255 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2256 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2257 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2258 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2259 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2260 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2261 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2262 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2264 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2265 max_sp = sta->max_sp;
2267 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2269 WMI_AP_PS_PEER_PARAM_UAPSD,
2272 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2273 arvif->vdev_id, ret);
2277 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2279 WMI_AP_PS_PEER_PARAM_MAX_SP,
2282 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2283 arvif->vdev_id, ret);
2287 /* TODO setup this based on STA listen interval and
2288 beacon interval. Currently we don't know
2289 sta->listen_interval - mac80211 patch required.
2290 Currently use 10 seconds */
2291 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2292 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2295 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2296 arvif->vdev_id, ret);
2305 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2306 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2313 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2314 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2318 idx_limit = fls(mcs_map) - 1;
2322 switch (idx_limit) {
2323 case 0: /* fall through */
2324 case 1: /* fall through */
2325 case 2: /* fall through */
2326 case 3: /* fall through */
2327 case 4: /* fall through */
2328 case 5: /* fall through */
2329 case 6: /* fall through */
2331 /* see ath10k_mac_can_set_bitrate_mask() */
2335 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2338 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2341 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2344 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2348 tx_mcs_set &= ~(0x3 << (nss * 2));
2349 tx_mcs_set |= mcs << (nss * 2);
2355 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2356 struct ieee80211_vif *vif,
2357 struct ieee80211_sta *sta,
2358 struct wmi_peer_assoc_complete_arg *arg)
2360 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2361 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2362 struct cfg80211_chan_def def;
2363 enum ieee80211_band band;
2364 const u16 *vht_mcs_mask;
2367 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2370 if (!vht_cap->vht_supported)
2373 band = def.chan->band;
2374 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2376 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2379 arg->peer_flags |= ar->wmi.peer_flags->vht;
2381 if (def.chan->band == IEEE80211_BAND_2GHZ)
2382 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2384 arg->peer_vht_caps = vht_cap->cap;
2386 ampdu_factor = (vht_cap->cap &
2387 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2388 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2390 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2391 * zero in VHT IE. Using it would result in degraded throughput.
2392 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2393 * it if VHT max_mpdu is smaller. */
2394 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2395 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2396 ampdu_factor)) - 1);
2398 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2399 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2401 arg->peer_vht_rates.rx_max_rate =
2402 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2403 arg->peer_vht_rates.rx_mcs_set =
2404 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2405 arg->peer_vht_rates.tx_max_rate =
2406 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2407 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2408 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2410 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2411 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2414 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2415 struct ieee80211_vif *vif,
2416 struct ieee80211_sta *sta,
2417 struct wmi_peer_assoc_complete_arg *arg)
2419 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2421 switch (arvif->vdev_type) {
2422 case WMI_VDEV_TYPE_AP:
2424 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2426 if (sta->wme && sta->uapsd_queues) {
2427 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2428 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2431 case WMI_VDEV_TYPE_STA:
2432 if (vif->bss_conf.qos)
2433 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2435 case WMI_VDEV_TYPE_IBSS:
2437 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2443 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2444 sta->addr, !!(arg->peer_flags &
2445 arvif->ar->wmi.peer_flags->qos));
2448 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2450 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2451 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2454 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2455 struct ieee80211_vif *vif,
2456 struct ieee80211_sta *sta,
2457 struct wmi_peer_assoc_complete_arg *arg)
2459 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2460 struct cfg80211_chan_def def;
2461 enum ieee80211_band band;
2462 const u8 *ht_mcs_mask;
2463 const u16 *vht_mcs_mask;
2464 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2466 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2469 band = def.chan->band;
2470 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2471 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2474 case IEEE80211_BAND_2GHZ:
2475 if (sta->vht_cap.vht_supported &&
2476 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2477 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2478 phymode = MODE_11AC_VHT40;
2480 phymode = MODE_11AC_VHT20;
2481 } else if (sta->ht_cap.ht_supported &&
2482 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2483 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2484 phymode = MODE_11NG_HT40;
2486 phymode = MODE_11NG_HT20;
2487 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2494 case IEEE80211_BAND_5GHZ:
2498 if (sta->vht_cap.vht_supported &&
2499 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2500 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2501 phymode = MODE_11AC_VHT80;
2502 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2503 phymode = MODE_11AC_VHT40;
2504 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2505 phymode = MODE_11AC_VHT20;
2506 } else if (sta->ht_cap.ht_supported &&
2507 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2508 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2509 phymode = MODE_11NA_HT40;
2511 phymode = MODE_11NA_HT20;
2521 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2522 sta->addr, ath10k_wmi_phymode_str(phymode));
2524 arg->peer_phymode = phymode;
2525 WARN_ON(phymode == MODE_UNKNOWN);
2528 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2529 struct ieee80211_vif *vif,
2530 struct ieee80211_sta *sta,
2531 struct wmi_peer_assoc_complete_arg *arg)
2533 lockdep_assert_held(&ar->conf_mutex);
2535 memset(arg, 0, sizeof(*arg));
2537 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2538 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2539 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2540 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2541 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2542 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2543 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2548 static const u32 ath10k_smps_map[] = {
2549 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2550 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2551 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2552 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2555 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2557 const struct ieee80211_sta_ht_cap *ht_cap)
2561 if (!ht_cap->ht_supported)
2564 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2565 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2567 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2570 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2571 WMI_PEER_SMPS_STATE,
2572 ath10k_smps_map[smps]);
2575 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2576 struct ieee80211_vif *vif,
2577 struct ieee80211_sta_vht_cap vht_cap)
2579 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2584 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2587 if (!(ar->vht_cap_info &
2588 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2589 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2590 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2591 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2594 param = ar->wmi.vdev_param->txbf;
2597 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2600 /* The following logic is correct. If a remote STA advertises support
2601 * for being a beamformer then we should enable us being a beamformee.
2604 if (ar->vht_cap_info &
2605 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2606 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2607 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2608 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2610 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2611 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2614 if (ar->vht_cap_info &
2615 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2616 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2617 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2618 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2620 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2621 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2624 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2625 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2627 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2628 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2630 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2632 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2640 /* can be called only in mac80211 callbacks due to `key_count` usage */
2641 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2642 struct ieee80211_vif *vif,
2643 struct ieee80211_bss_conf *bss_conf)
2645 struct ath10k *ar = hw->priv;
2646 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2647 struct ieee80211_sta_ht_cap ht_cap;
2648 struct ieee80211_sta_vht_cap vht_cap;
2649 struct wmi_peer_assoc_complete_arg peer_arg;
2650 struct ieee80211_sta *ap_sta;
2653 lockdep_assert_held(&ar->conf_mutex);
2655 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2656 arvif->vdev_id, arvif->bssid, arvif->aid);
2660 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2662 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2663 bss_conf->bssid, arvif->vdev_id);
2668 /* ap_sta must be accessed only within rcu section which must be left
2669 * before calling ath10k_setup_peer_smps() which might sleep. */
2670 ht_cap = ap_sta->ht_cap;
2671 vht_cap = ap_sta->vht_cap;
2673 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2675 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2676 bss_conf->bssid, arvif->vdev_id, ret);
2683 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2685 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2686 bss_conf->bssid, arvif->vdev_id, ret);
2690 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2692 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2693 arvif->vdev_id, ret);
2697 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2699 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2700 arvif->vdev_id, bss_conf->bssid, ret);
2704 ath10k_dbg(ar, ATH10K_DBG_MAC,
2705 "mac vdev %d up (associated) bssid %pM aid %d\n",
2706 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2708 WARN_ON(arvif->is_up);
2710 arvif->aid = bss_conf->aid;
2711 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2713 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2715 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2716 arvif->vdev_id, ret);
2720 arvif->is_up = true;
2722 /* Workaround: Some firmware revisions (tested with qca6174
2723 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2724 * poked with peer param command.
2726 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2727 WMI_PEER_DUMMY_VAR, 1);
2729 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2730 arvif->bssid, arvif->vdev_id, ret);
2735 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2736 struct ieee80211_vif *vif)
2738 struct ath10k *ar = hw->priv;
2739 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2740 struct ieee80211_sta_vht_cap vht_cap = {};
2743 lockdep_assert_held(&ar->conf_mutex);
2745 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2746 arvif->vdev_id, arvif->bssid);
2748 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2750 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2751 arvif->vdev_id, ret);
2753 arvif->def_wep_key_idx = -1;
2755 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2757 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2758 arvif->vdev_id, ret);
2762 arvif->is_up = false;
2764 cancel_delayed_work_sync(&arvif->connection_loss_work);
2767 static int ath10k_station_assoc(struct ath10k *ar,
2768 struct ieee80211_vif *vif,
2769 struct ieee80211_sta *sta,
2772 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2773 struct wmi_peer_assoc_complete_arg peer_arg;
2776 lockdep_assert_held(&ar->conf_mutex);
2778 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2780 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2781 sta->addr, arvif->vdev_id, ret);
2785 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2787 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2788 sta->addr, arvif->vdev_id, ret);
2792 /* Re-assoc is run only to update supported rates for given station. It
2793 * doesn't make much sense to reconfigure the peer completely.
2796 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2799 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2800 arvif->vdev_id, ret);
2804 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2806 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2807 sta->addr, arvif->vdev_id, ret);
2812 arvif->num_legacy_stations++;
2813 ret = ath10k_recalc_rtscts_prot(arvif);
2815 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2816 arvif->vdev_id, ret);
2821 /* Plumb cached keys only for static WEP */
2822 if (arvif->def_wep_key_idx != -1) {
2823 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2825 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2826 arvif->vdev_id, ret);
2835 static int ath10k_station_disassoc(struct ath10k *ar,
2836 struct ieee80211_vif *vif,
2837 struct ieee80211_sta *sta)
2839 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2842 lockdep_assert_held(&ar->conf_mutex);
2845 arvif->num_legacy_stations--;
2846 ret = ath10k_recalc_rtscts_prot(arvif);
2848 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2849 arvif->vdev_id, ret);
2854 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2856 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2857 arvif->vdev_id, ret);
2868 static int ath10k_update_channel_list(struct ath10k *ar)
2870 struct ieee80211_hw *hw = ar->hw;
2871 struct ieee80211_supported_band **bands;
2872 enum ieee80211_band band;
2873 struct ieee80211_channel *channel;
2874 struct wmi_scan_chan_list_arg arg = {0};
2875 struct wmi_channel_arg *ch;
2881 lockdep_assert_held(&ar->conf_mutex);
2883 bands = hw->wiphy->bands;
2884 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2888 for (i = 0; i < bands[band]->n_channels; i++) {
2889 if (bands[band]->channels[i].flags &
2890 IEEE80211_CHAN_DISABLED)
2897 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2898 arg.channels = kzalloc(len, GFP_KERNEL);
2903 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2907 for (i = 0; i < bands[band]->n_channels; i++) {
2908 channel = &bands[band]->channels[i];
2910 if (channel->flags & IEEE80211_CHAN_DISABLED)
2913 ch->allow_ht = true;
2915 /* FIXME: when should we really allow VHT? */
2916 ch->allow_vht = true;
2919 !(channel->flags & IEEE80211_CHAN_NO_IR);
2922 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2925 !!(channel->flags & IEEE80211_CHAN_RADAR);
2927 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2928 ch->passive = passive;
2930 ch->freq = channel->center_freq;
2931 ch->band_center_freq1 = channel->center_freq;
2933 ch->max_power = channel->max_power * 2;
2934 ch->max_reg_power = channel->max_reg_power * 2;
2935 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2936 ch->reg_class_id = 0; /* FIXME */
2938 /* FIXME: why use only legacy modes, why not any
2939 * HT/VHT modes? Would that even make any
2941 if (channel->band == IEEE80211_BAND_2GHZ)
2942 ch->mode = MODE_11G;
2944 ch->mode = MODE_11A;
2946 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2949 ath10k_dbg(ar, ATH10K_DBG_WMI,
2950 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2951 ch - arg.channels, arg.n_channels,
2952 ch->freq, ch->max_power, ch->max_reg_power,
2953 ch->max_antenna_gain, ch->mode);
2959 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2960 kfree(arg.channels);
2965 static enum wmi_dfs_region
2966 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2968 switch (dfs_region) {
2969 case NL80211_DFS_UNSET:
2970 return WMI_UNINIT_DFS_DOMAIN;
2971 case NL80211_DFS_FCC:
2972 return WMI_FCC_DFS_DOMAIN;
2973 case NL80211_DFS_ETSI:
2974 return WMI_ETSI_DFS_DOMAIN;
2975 case NL80211_DFS_JP:
2976 return WMI_MKK4_DFS_DOMAIN;
2978 return WMI_UNINIT_DFS_DOMAIN;
2981 static void ath10k_regd_update(struct ath10k *ar)
2983 struct reg_dmn_pair_mapping *regpair;
2985 enum wmi_dfs_region wmi_dfs_reg;
2986 enum nl80211_dfs_regions nl_dfs_reg;
2988 lockdep_assert_held(&ar->conf_mutex);
2990 ret = ath10k_update_channel_list(ar);
2992 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2994 regpair = ar->ath_common.regulatory.regpair;
2996 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2997 nl_dfs_reg = ar->dfs_detector->region;
2998 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
3000 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
3003 /* Target allows setting up per-band regdomain but ath_common provides
3004 * a combined one only */
3005 ret = ath10k_wmi_pdev_set_regdomain(ar,
3006 regpair->reg_domain,
3007 regpair->reg_domain, /* 2ghz */
3008 regpair->reg_domain, /* 5ghz */
3009 regpair->reg_2ghz_ctl,
3010 regpair->reg_5ghz_ctl,
3013 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3016 static void ath10k_reg_notifier(struct wiphy *wiphy,
3017 struct regulatory_request *request)
3019 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3020 struct ath10k *ar = hw->priv;
3023 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3025 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3026 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3027 request->dfs_region);
3028 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3029 request->dfs_region);
3031 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3032 request->dfs_region);
3035 mutex_lock(&ar->conf_mutex);
3036 if (ar->state == ATH10K_STATE_ON)
3037 ath10k_regd_update(ar);
3038 mutex_unlock(&ar->conf_mutex);
3045 enum ath10k_mac_tx_path {
3047 ATH10K_MAC_TX_HTT_MGMT,
3048 ATH10K_MAC_TX_WMI_MGMT,
3049 ATH10K_MAC_TX_UNKNOWN,
3052 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3054 lockdep_assert_held(&ar->htt.tx_lock);
3056 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3057 ar->tx_paused |= BIT(reason);
3058 ieee80211_stop_queues(ar->hw);
3061 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3062 struct ieee80211_vif *vif)
3064 struct ath10k *ar = data;
3065 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3067 if (arvif->tx_paused)
3070 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3073 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3075 lockdep_assert_held(&ar->htt.tx_lock);
3077 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3078 ar->tx_paused &= ~BIT(reason);
3083 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3084 IEEE80211_IFACE_ITER_RESUME_ALL,
3085 ath10k_mac_tx_unlock_iter,
3088 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3091 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3093 struct ath10k *ar = arvif->ar;
3095 lockdep_assert_held(&ar->htt.tx_lock);
3097 WARN_ON(reason >= BITS_PER_LONG);
3098 arvif->tx_paused |= BIT(reason);
3099 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3102 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3104 struct ath10k *ar = arvif->ar;
3106 lockdep_assert_held(&ar->htt.tx_lock);
3108 WARN_ON(reason >= BITS_PER_LONG);
3109 arvif->tx_paused &= ~BIT(reason);
3114 if (arvif->tx_paused)
3117 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3120 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3121 enum wmi_tlv_tx_pause_id pause_id,
3122 enum wmi_tlv_tx_pause_action action)
3124 struct ath10k *ar = arvif->ar;
3126 lockdep_assert_held(&ar->htt.tx_lock);
3129 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3130 ath10k_mac_vif_tx_lock(arvif, pause_id);
3132 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3133 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3136 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3137 action, arvif->vdev_id);
3142 struct ath10k_mac_tx_pause {
3144 enum wmi_tlv_tx_pause_id pause_id;
3145 enum wmi_tlv_tx_pause_action action;
3148 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3149 struct ieee80211_vif *vif)
3151 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3152 struct ath10k_mac_tx_pause *arg = data;
3154 if (arvif->vdev_id != arg->vdev_id)
3157 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3160 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3161 enum wmi_tlv_tx_pause_id pause_id,
3162 enum wmi_tlv_tx_pause_action action)
3164 struct ath10k_mac_tx_pause arg = {
3166 .pause_id = pause_id,
3170 spin_lock_bh(&ar->htt.tx_lock);
3171 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3172 IEEE80211_IFACE_ITER_RESUME_ALL,
3173 ath10k_mac_handle_tx_pause_iter,
3175 spin_unlock_bh(&ar->htt.tx_lock);
3178 static enum ath10k_hw_txrx_mode
3179 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3180 struct ieee80211_vif *vif,
3181 struct ieee80211_sta *sta,
3182 struct sk_buff *skb)
3184 const struct ieee80211_hdr *hdr = (void *)skb->data;
3185 __le16 fc = hdr->frame_control;
3187 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3188 return ATH10K_HW_TXRX_RAW;
3190 if (ieee80211_is_mgmt(fc))
3191 return ATH10K_HW_TXRX_MGMT;
3195 * NullFunc frames are mostly used to ping if a client or AP are still
3196 * reachable and responsive. This implies tx status reports must be
3197 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3198 * come to a conclusion that the other end disappeared and tear down
3199 * BSS connection or it can never disconnect from BSS/client (which is
3202 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3203 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3204 * which seems to deliver correct tx reports for NullFunc frames. The
3205 * downside of using it is it ignores client powersave state so it can
3206 * end up disconnecting sleeping clients in AP mode. It should fix STA
3207 * mode though because AP don't sleep.
3209 if (ar->htt.target_version_major < 3 &&
3210 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3211 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3212 ar->running_fw->fw_file.fw_features))
3213 return ATH10K_HW_TXRX_MGMT;
3217 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3218 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3219 * to work with Ethernet txmode so use it.
3221 * FIXME: Check if raw mode works with TDLS.
3223 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3224 return ATH10K_HW_TXRX_ETHERNET;
3226 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3227 return ATH10K_HW_TXRX_RAW;
3229 return ATH10K_HW_TXRX_NATIVE_WIFI;
3232 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3233 struct sk_buff *skb)
3235 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3236 const struct ieee80211_hdr *hdr = (void *)skb->data;
3237 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3238 IEEE80211_TX_CTL_INJECTED;
3240 if (!ieee80211_has_protected(hdr->frame_control))
3243 if ((info->flags & mask) == mask)
3247 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3252 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3253 * Control in the header.
3255 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3257 struct ieee80211_hdr *hdr = (void *)skb->data;
3258 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3261 if (!ieee80211_is_data_qos(hdr->frame_control))
3264 qos_ctl = ieee80211_get_qos_ctl(hdr);
3265 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3266 skb->data, (void *)qos_ctl - (void *)skb->data);
3267 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3269 /* Some firmware revisions don't handle sending QoS NullFunc well.
3270 * These frames are mainly used for CQM purposes so it doesn't really
3271 * matter whether QoS NullFunc or NullFunc are sent.
3273 hdr = (void *)skb->data;
3274 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3275 cb->flags &= ~ATH10K_SKB_F_QOS;
3277 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3280 static void ath10k_tx_h_8023(struct sk_buff *skb)
3282 struct ieee80211_hdr *hdr;
3283 struct rfc1042_hdr *rfc1042;
3290 hdr = (void *)skb->data;
3291 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3292 rfc1042 = (void *)skb->data + hdrlen;
3294 ether_addr_copy(da, ieee80211_get_DA(hdr));
3295 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3296 type = rfc1042->snap_type;
3298 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3299 skb_push(skb, sizeof(*eth));
3301 eth = (void *)skb->data;
3302 ether_addr_copy(eth->h_dest, da);
3303 ether_addr_copy(eth->h_source, sa);
3304 eth->h_proto = type;
3307 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3308 struct ieee80211_vif *vif,
3309 struct sk_buff *skb)
3311 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3312 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3314 /* This is case only for P2P_GO */
3315 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3318 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3319 spin_lock_bh(&ar->data_lock);
3320 if (arvif->u.ap.noa_data)
3321 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3323 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3324 arvif->u.ap.noa_data,
3325 arvif->u.ap.noa_len);
3326 spin_unlock_bh(&ar->data_lock);
3330 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3331 struct ieee80211_vif *vif,
3332 struct ieee80211_txq *txq,
3333 struct sk_buff *skb)
3335 struct ieee80211_hdr *hdr = (void *)skb->data;
3336 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3339 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3340 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3342 if (ieee80211_is_mgmt(hdr->frame_control))
3343 cb->flags |= ATH10K_SKB_F_MGMT;
3345 if (ieee80211_is_data_qos(hdr->frame_control))
3346 cb->flags |= ATH10K_SKB_F_QOS;
3352 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3354 /* FIXME: Not really sure since when the behaviour changed. At some
3355 * point new firmware stopped requiring creation of peer entries for
3356 * offchannel tx (and actually creating them causes issues with wmi-htc
3357 * tx credit replenishment and reliability). Assuming it's at least 3.4
3358 * because that's when the `freq` was introduced to TX_FRM HTT command.
3360 return (ar->htt.target_version_major >= 3 &&
3361 ar->htt.target_version_minor >= 4 &&
3362 ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3365 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3367 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3370 spin_lock_bh(&ar->data_lock);
3372 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3373 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3378 __skb_queue_tail(q, skb);
3379 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3382 spin_unlock_bh(&ar->data_lock);
3387 static enum ath10k_mac_tx_path
3388 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3389 struct sk_buff *skb,
3390 enum ath10k_hw_txrx_mode txmode)
3393 case ATH10K_HW_TXRX_RAW:
3394 case ATH10K_HW_TXRX_NATIVE_WIFI:
3395 case ATH10K_HW_TXRX_ETHERNET:
3396 return ATH10K_MAC_TX_HTT;
3397 case ATH10K_HW_TXRX_MGMT:
3398 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3399 ar->running_fw->fw_file.fw_features))
3400 return ATH10K_MAC_TX_WMI_MGMT;
3401 else if (ar->htt.target_version_major >= 3)
3402 return ATH10K_MAC_TX_HTT;
3404 return ATH10K_MAC_TX_HTT_MGMT;
3407 return ATH10K_MAC_TX_UNKNOWN;
3410 static int ath10k_mac_tx_submit(struct ath10k *ar,
3411 enum ath10k_hw_txrx_mode txmode,
3412 enum ath10k_mac_tx_path txpath,
3413 struct sk_buff *skb)
3415 struct ath10k_htt *htt = &ar->htt;
3419 case ATH10K_MAC_TX_HTT:
3420 ret = ath10k_htt_tx(htt, txmode, skb);
3422 case ATH10K_MAC_TX_HTT_MGMT:
3423 ret = ath10k_htt_mgmt_tx(htt, skb);
3425 case ATH10K_MAC_TX_WMI_MGMT:
3426 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3428 case ATH10K_MAC_TX_UNKNOWN:
3435 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3437 ieee80211_free_txskb(ar->hw, skb);
3443 /* This function consumes the sk_buff regardless of return value as far as
3444 * caller is concerned so no freeing is necessary afterwards.
3446 static int ath10k_mac_tx(struct ath10k *ar,
3447 struct ieee80211_vif *vif,
3448 struct ieee80211_sta *sta,
3449 enum ath10k_hw_txrx_mode txmode,
3450 enum ath10k_mac_tx_path txpath,
3451 struct sk_buff *skb)
3453 struct ieee80211_hw *hw = ar->hw;
3454 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3457 /* We should disable CCK RATE due to P2P */
3458 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3459 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3462 case ATH10K_HW_TXRX_MGMT:
3463 case ATH10K_HW_TXRX_NATIVE_WIFI:
3464 ath10k_tx_h_nwifi(hw, skb);
3465 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3466 ath10k_tx_h_seq_no(vif, skb);
3468 case ATH10K_HW_TXRX_ETHERNET:
3469 ath10k_tx_h_8023(skb);
3471 case ATH10K_HW_TXRX_RAW:
3472 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3474 ieee80211_free_txskb(hw, skb);
3479 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3480 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3481 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3484 skb_queue_tail(&ar->offchan_tx_queue, skb);
3485 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3490 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3492 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3499 void ath10k_offchan_tx_purge(struct ath10k *ar)
3501 struct sk_buff *skb;
3504 skb = skb_dequeue(&ar->offchan_tx_queue);
3508 ieee80211_free_txskb(ar->hw, skb);
3512 void ath10k_offchan_tx_work(struct work_struct *work)
3514 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3515 struct ath10k_peer *peer;
3516 struct ath10k_vif *arvif;
3517 enum ath10k_hw_txrx_mode txmode;
3518 enum ath10k_mac_tx_path txpath;
3519 struct ieee80211_hdr *hdr;
3520 struct ieee80211_vif *vif;
3521 struct ieee80211_sta *sta;
3522 struct sk_buff *skb;
3523 const u8 *peer_addr;
3526 unsigned long time_left;
3527 bool tmp_peer_created = false;
3529 /* FW requirement: We must create a peer before FW will send out
3530 * an offchannel frame. Otherwise the frame will be stuck and
3531 * never transmitted. We delete the peer upon tx completion.
3532 * It is unlikely that a peer for offchannel tx will already be
3533 * present. However it may be in some rare cases so account for that.
3534 * Otherwise we might remove a legitimate peer and break stuff. */
3537 skb = skb_dequeue(&ar->offchan_tx_queue);
3541 mutex_lock(&ar->conf_mutex);
3543 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
3546 hdr = (struct ieee80211_hdr *)skb->data;
3547 peer_addr = ieee80211_get_DA(hdr);
3549 spin_lock_bh(&ar->data_lock);
3550 vdev_id = ar->scan.vdev_id;
3551 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3552 spin_unlock_bh(&ar->data_lock);
3555 /* FIXME: should this use ath10k_warn()? */
3556 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3557 peer_addr, vdev_id);
3560 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3562 WMI_PEER_TYPE_DEFAULT);
3564 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3565 peer_addr, vdev_id, ret);
3566 tmp_peer_created = (ret == 0);
3569 spin_lock_bh(&ar->data_lock);
3570 reinit_completion(&ar->offchan_tx_completed);
3571 ar->offchan_tx_skb = skb;
3572 spin_unlock_bh(&ar->data_lock);
3574 /* It's safe to access vif and sta - conf_mutex guarantees that
3575 * sta_state() and remove_interface() are locked exclusively
3576 * out wrt to this offchannel worker.
3578 arvif = ath10k_get_arvif(ar, vdev_id);
3581 sta = ieee80211_find_sta(vif, peer_addr);
3587 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3588 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3590 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3592 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3598 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3600 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
3603 if (!peer && tmp_peer_created) {
3604 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3606 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3607 peer_addr, vdev_id, ret);
3610 mutex_unlock(&ar->conf_mutex);
3614 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3616 struct sk_buff *skb;
3619 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3623 ieee80211_free_txskb(ar->hw, skb);
3627 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3629 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3630 struct sk_buff *skb;
3634 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3638 ret = ath10k_wmi_mgmt_tx(ar, skb);
3640 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3642 ieee80211_free_txskb(ar->hw, skb);
3647 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3649 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3654 INIT_LIST_HEAD(&artxq->list);
3657 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3659 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3660 struct ath10k_skb_cb *cb;
3661 struct sk_buff *msdu;
3667 spin_lock_bh(&ar->txqs_lock);
3668 if (!list_empty(&artxq->list))
3669 list_del_init(&artxq->list);
3670 spin_unlock_bh(&ar->txqs_lock);
3672 spin_lock_bh(&ar->htt.tx_lock);
3673 idr_for_each_entry(&ar->htt.pending_tx, msdu, msdu_id) {
3674 cb = ATH10K_SKB_CB(msdu);
3678 spin_unlock_bh(&ar->htt.tx_lock);
3681 struct ieee80211_txq *ath10k_mac_txq_lookup(struct ath10k *ar,
3685 struct ath10k_peer *peer;
3687 lockdep_assert_held(&ar->data_lock);
3689 peer = ar->peer_map[peer_id];
3694 return peer->sta->txq[tid];
3696 return peer->vif->txq;
3701 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3702 struct ieee80211_txq *txq)
3704 struct ath10k *ar = hw->priv;
3705 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3707 /* No need to get locks */
3709 if (ar->htt.tx_q_state.mode == HTT_TX_MODE_SWITCH_PUSH)
3712 if (ar->htt.num_pending_tx < ar->htt.tx_q_state.num_push_allowed)
3715 if (artxq->num_fw_queued < artxq->num_push_allowed)
3721 int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3722 struct ieee80211_txq *txq)
3724 struct ath10k *ar = hw->priv;
3725 struct ath10k_htt *htt = &ar->htt;
3726 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3727 struct ieee80211_vif *vif = txq->vif;
3728 struct ieee80211_sta *sta = txq->sta;
3729 enum ath10k_hw_txrx_mode txmode;
3730 enum ath10k_mac_tx_path txpath;
3731 struct sk_buff *skb;
3735 spin_lock_bh(&ar->htt.tx_lock);
3736 ret = ath10k_htt_tx_inc_pending(htt);
3737 spin_unlock_bh(&ar->htt.tx_lock);
3742 skb = ieee80211_tx_dequeue(hw, txq);
3744 spin_lock_bh(&ar->htt.tx_lock);
3745 ath10k_htt_tx_dec_pending(htt);
3746 spin_unlock_bh(&ar->htt.tx_lock);
3751 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3754 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3755 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3757 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3758 if (unlikely(ret)) {
3759 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3761 spin_lock_bh(&ar->htt.tx_lock);
3762 ath10k_htt_tx_dec_pending(htt);
3763 spin_unlock_bh(&ar->htt.tx_lock);
3768 spin_lock_bh(&ar->htt.tx_lock);
3769 artxq->num_fw_queued++;
3770 spin_unlock_bh(&ar->htt.tx_lock);
3775 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3777 struct ieee80211_hw *hw = ar->hw;
3778 struct ieee80211_txq *txq;
3779 struct ath10k_txq *artxq;
3780 struct ath10k_txq *last;
3784 spin_lock_bh(&ar->txqs_lock);
3787 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3788 while (!list_empty(&ar->txqs)) {
3789 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3790 txq = container_of((void *)artxq, struct ieee80211_txq,
3793 /* Prevent aggressive sta/tid taking over tx queue */
3796 while (ath10k_mac_tx_can_push(hw, txq) && max--) {
3797 ret = ath10k_mac_tx_push_txq(hw, txq);
3802 list_del_init(&artxq->list);
3804 list_add_tail(&artxq->list, &ar->txqs);
3806 ath10k_htt_tx_txq_update(hw, txq);
3808 if (artxq == last || (ret < 0 && ret != -ENOENT))
3813 spin_unlock_bh(&ar->txqs_lock);
3820 void __ath10k_scan_finish(struct ath10k *ar)
3822 lockdep_assert_held(&ar->data_lock);
3824 switch (ar->scan.state) {
3825 case ATH10K_SCAN_IDLE:
3827 case ATH10K_SCAN_RUNNING:
3828 case ATH10K_SCAN_ABORTING:
3829 if (!ar->scan.is_roc)
3830 ieee80211_scan_completed(ar->hw,
3832 ATH10K_SCAN_ABORTING));
3833 else if (ar->scan.roc_notify)
3834 ieee80211_remain_on_channel_expired(ar->hw);
3836 case ATH10K_SCAN_STARTING:
3837 ar->scan.state = ATH10K_SCAN_IDLE;
3838 ar->scan_channel = NULL;
3839 ar->scan.roc_freq = 0;
3840 ath10k_offchan_tx_purge(ar);
3841 cancel_delayed_work(&ar->scan.timeout);
3842 complete_all(&ar->scan.completed);
3847 void ath10k_scan_finish(struct ath10k *ar)
3849 spin_lock_bh(&ar->data_lock);
3850 __ath10k_scan_finish(ar);
3851 spin_unlock_bh(&ar->data_lock);
3854 static int ath10k_scan_stop(struct ath10k *ar)
3856 struct wmi_stop_scan_arg arg = {
3857 .req_id = 1, /* FIXME */
3858 .req_type = WMI_SCAN_STOP_ONE,
3859 .u.scan_id = ATH10K_SCAN_ID,
3863 lockdep_assert_held(&ar->conf_mutex);
3865 ret = ath10k_wmi_stop_scan(ar, &arg);
3867 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3871 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
3873 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3875 } else if (ret > 0) {
3880 /* Scan state should be updated upon scan completion but in case
3881 * firmware fails to deliver the event (for whatever reason) it is
3882 * desired to clean up scan state anyway. Firmware may have just
3883 * dropped the scan completion event delivery due to transport pipe
3884 * being overflown with data and/or it can recover on its own before
3885 * next scan request is submitted.
3887 spin_lock_bh(&ar->data_lock);
3888 if (ar->scan.state != ATH10K_SCAN_IDLE)
3889 __ath10k_scan_finish(ar);
3890 spin_unlock_bh(&ar->data_lock);
3895 static void ath10k_scan_abort(struct ath10k *ar)
3899 lockdep_assert_held(&ar->conf_mutex);
3901 spin_lock_bh(&ar->data_lock);
3903 switch (ar->scan.state) {
3904 case ATH10K_SCAN_IDLE:
3905 /* This can happen if timeout worker kicked in and called
3906 * abortion while scan completion was being processed.
3909 case ATH10K_SCAN_STARTING:
3910 case ATH10K_SCAN_ABORTING:
3911 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3912 ath10k_scan_state_str(ar->scan.state),
3915 case ATH10K_SCAN_RUNNING:
3916 ar->scan.state = ATH10K_SCAN_ABORTING;
3917 spin_unlock_bh(&ar->data_lock);
3919 ret = ath10k_scan_stop(ar);
3921 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3923 spin_lock_bh(&ar->data_lock);
3927 spin_unlock_bh(&ar->data_lock);
3930 void ath10k_scan_timeout_work(struct work_struct *work)
3932 struct ath10k *ar = container_of(work, struct ath10k,
3935 mutex_lock(&ar->conf_mutex);
3936 ath10k_scan_abort(ar);
3937 mutex_unlock(&ar->conf_mutex);
3940 static int ath10k_start_scan(struct ath10k *ar,
3941 const struct wmi_start_scan_arg *arg)
3945 lockdep_assert_held(&ar->conf_mutex);
3947 ret = ath10k_wmi_start_scan(ar, arg);
3951 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
3953 ret = ath10k_scan_stop(ar);
3955 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3960 /* If we failed to start the scan, return error code at
3961 * this point. This is probably due to some issue in the
3962 * firmware, but no need to wedge the driver due to that...
3964 spin_lock_bh(&ar->data_lock);
3965 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3966 spin_unlock_bh(&ar->data_lock);
3969 spin_unlock_bh(&ar->data_lock);
3974 /**********************/
3975 /* mac80211 callbacks */
3976 /**********************/
3978 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
3979 struct ieee80211_tx_control *control,
3980 struct sk_buff *skb)
3982 struct ath10k *ar = hw->priv;
3983 struct ath10k_htt *htt = &ar->htt;
3984 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3985 struct ieee80211_vif *vif = info->control.vif;
3986 struct ieee80211_sta *sta = control->sta;
3987 struct ieee80211_txq *txq = NULL;
3988 struct ieee80211_hdr *hdr = (void *)skb->data;
3989 enum ath10k_hw_txrx_mode txmode;
3990 enum ath10k_mac_tx_path txpath;
3996 ath10k_mac_tx_h_fill_cb(ar, vif, txq, skb);
3998 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3999 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
4000 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
4001 txpath == ATH10K_MAC_TX_HTT_MGMT);
4002 is_mgmt = (txpath == ATH10K_MAC_TX_HTT_MGMT);
4005 spin_lock_bh(&ar->htt.tx_lock);
4006 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
4008 ret = ath10k_htt_tx_inc_pending(htt);
4010 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
4012 spin_unlock_bh(&ar->htt.tx_lock);
4013 ieee80211_free_txskb(ar->hw, skb);
4017 ret = ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp);
4019 ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending count: %d, dropping\n",
4021 ath10k_htt_tx_dec_pending(htt);
4022 spin_unlock_bh(&ar->htt.tx_lock);
4023 ieee80211_free_txskb(ar->hw, skb);
4026 spin_unlock_bh(&ar->htt.tx_lock);
4029 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
4031 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
4033 spin_lock_bh(&ar->htt.tx_lock);
4034 ath10k_htt_tx_dec_pending(htt);
4036 ath10k_htt_tx_mgmt_dec_pending(htt);
4037 spin_unlock_bh(&ar->htt.tx_lock);
4043 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
4044 struct ieee80211_txq *txq)
4046 struct ath10k *ar = hw->priv;
4047 struct ath10k_txq *artxq = (void *)txq->drv_priv;
4049 spin_lock_bh(&ar->txqs_lock);
4050 if (list_empty(&artxq->list))
4051 list_add_tail(&artxq->list, &ar->txqs);
4052 spin_unlock_bh(&ar->txqs_lock);
4054 if (ath10k_mac_tx_can_push(hw, txq))
4055 tasklet_schedule(&ar->htt.txrx_compl_task);
4057 ath10k_htt_tx_txq_update(hw, txq);
4060 /* Must not be called with conf_mutex held as workers can use that also. */
4061 void ath10k_drain_tx(struct ath10k *ar)
4063 /* make sure rcu-protected mac80211 tx path itself is drained */
4066 ath10k_offchan_tx_purge(ar);
4067 ath10k_mgmt_over_wmi_tx_purge(ar);
4069 cancel_work_sync(&ar->offchan_tx_work);
4070 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4073 void ath10k_halt(struct ath10k *ar)
4075 struct ath10k_vif *arvif;
4077 lockdep_assert_held(&ar->conf_mutex);
4079 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
4080 ar->filter_flags = 0;
4081 ar->monitor = false;
4082 ar->monitor_arvif = NULL;
4084 if (ar->monitor_started)
4085 ath10k_monitor_stop(ar);
4087 ar->monitor_started = false;
4090 ath10k_scan_finish(ar);
4091 ath10k_peer_cleanup_all(ar);
4092 ath10k_core_stop(ar);
4093 ath10k_hif_power_down(ar);
4095 spin_lock_bh(&ar->data_lock);
4096 list_for_each_entry(arvif, &ar->arvifs, list)
4097 ath10k_mac_vif_beacon_cleanup(arvif);
4098 spin_unlock_bh(&ar->data_lock);
4101 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4103 struct ath10k *ar = hw->priv;
4105 mutex_lock(&ar->conf_mutex);
4107 *tx_ant = ar->cfg_tx_chainmask;
4108 *rx_ant = ar->cfg_rx_chainmask;
4110 mutex_unlock(&ar->conf_mutex);
4115 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4117 /* It is not clear that allowing gaps in chainmask
4118 * is helpful. Probably it will not do what user
4119 * is hoping for, so warn in that case.
4121 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4124 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4128 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4130 int nsts = ar->vht_cap_info;
4132 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4133 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4135 /* If firmware does not deliver to host number of space-time
4136 * streams supported, assume it support up to 4 BF STS and return
4137 * the value for VHT CAP: nsts-1)
4145 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4147 int sound_dim = ar->vht_cap_info;
4149 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4150 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4152 /* If the sounding dimension is not advertised by the firmware,
4153 * let's use a default value of 1
4161 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4163 struct ieee80211_sta_vht_cap vht_cap = {0};
4168 vht_cap.vht_supported = 1;
4169 vht_cap.cap = ar->vht_cap_info;
4171 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4172 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4173 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4174 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4175 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4180 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4181 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4182 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4183 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4184 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4190 for (i = 0; i < 8; i++) {
4191 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4192 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4194 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4197 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4198 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4203 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4206 struct ieee80211_sta_ht_cap ht_cap = {0};
4208 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4211 ht_cap.ht_supported = 1;
4212 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4213 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4214 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4215 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4217 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4219 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4220 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4222 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4223 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4225 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4228 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4229 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4234 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4235 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4237 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4240 stbc = ar->ht_cap_info;
4241 stbc &= WMI_HT_CAP_RX_STBC;
4242 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4243 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4244 stbc &= IEEE80211_HT_CAP_RX_STBC;
4249 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4250 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4252 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4253 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4255 /* max AMSDU is implicitly taken from vht_cap_info */
4256 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4257 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4259 for (i = 0; i < ar->num_rf_chains; i++) {
4260 if (ar->cfg_rx_chainmask & BIT(i))
4261 ht_cap.mcs.rx_mask[i] = 0xFF;
4264 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4269 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4271 struct ieee80211_supported_band *band;
4272 struct ieee80211_sta_vht_cap vht_cap;
4273 struct ieee80211_sta_ht_cap ht_cap;
4275 ht_cap = ath10k_get_ht_cap(ar);
4276 vht_cap = ath10k_create_vht_cap(ar);
4278 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4279 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4280 band->ht_cap = ht_cap;
4282 /* Enable the VHT support at 2.4 GHz */
4283 band->vht_cap = vht_cap;
4285 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4286 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4287 band->ht_cap = ht_cap;
4288 band->vht_cap = vht_cap;
4292 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4296 lockdep_assert_held(&ar->conf_mutex);
4298 ath10k_check_chain_mask(ar, tx_ant, "tx");
4299 ath10k_check_chain_mask(ar, rx_ant, "rx");
4301 ar->cfg_tx_chainmask = tx_ant;
4302 ar->cfg_rx_chainmask = rx_ant;
4304 if ((ar->state != ATH10K_STATE_ON) &&
4305 (ar->state != ATH10K_STATE_RESTARTED))
4308 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4311 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4316 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4319 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4324 /* Reload HT/VHT capability */
4325 ath10k_mac_setup_ht_vht_cap(ar);
4330 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4332 struct ath10k *ar = hw->priv;
4335 mutex_lock(&ar->conf_mutex);
4336 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4337 mutex_unlock(&ar->conf_mutex);
4341 static int ath10k_start(struct ieee80211_hw *hw)
4343 struct ath10k *ar = hw->priv;
4348 * This makes sense only when restarting hw. It is harmless to call
4349 * uncoditionally. This is necessary to make sure no HTT/WMI tx
4350 * commands will be submitted while restarting.
4352 ath10k_drain_tx(ar);
4354 mutex_lock(&ar->conf_mutex);
4356 switch (ar->state) {
4357 case ATH10K_STATE_OFF:
4358 ar->state = ATH10K_STATE_ON;
4360 case ATH10K_STATE_RESTARTING:
4362 ar->state = ATH10K_STATE_RESTARTED;
4364 case ATH10K_STATE_ON:
4365 case ATH10K_STATE_RESTARTED:
4366 case ATH10K_STATE_WEDGED:
4370 case ATH10K_STATE_UTF:
4375 ret = ath10k_hif_power_up(ar);
4377 ath10k_err(ar, "Could not init hif: %d\n", ret);
4381 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL,
4382 &ar->normal_mode_fw);
4384 ath10k_err(ar, "Could not init core: %d\n", ret);
4385 goto err_power_down;
4388 param = ar->wmi.pdev_param->pmf_qos;
4389 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4391 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4395 param = ar->wmi.pdev_param->dynamic_bw;
4396 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4398 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4402 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4403 ret = ath10k_wmi_adaptive_qcs(ar, true);
4405 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4411 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4412 param = ar->wmi.pdev_param->burst_enable;
4413 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4415 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4420 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4423 * By default FW set ARP frames ac to voice (6). In that case ARP
4424 * exchange is not working properly for UAPSD enabled AP. ARP requests
4425 * which arrives with access category 0 are processed by network stack
4426 * and send back with access category 0, but FW changes access category
4427 * to 6. Set ARP frames access category to best effort (0) solves
4431 param = ar->wmi.pdev_param->arp_ac_override;
4432 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4434 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4439 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4440 ar->running_fw->fw_file.fw_features)) {
4441 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4442 WMI_CCA_DETECT_LEVEL_AUTO,
4443 WMI_CCA_DETECT_MARGIN_AUTO);
4445 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4451 param = ar->wmi.pdev_param->ani_enable;
4452 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4454 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4459 ar->ani_enabled = true;
4461 if (ath10k_peer_stats_enabled(ar)) {
4462 param = ar->wmi.pdev_param->peer_stats_update_period;
4463 ret = ath10k_wmi_pdev_set_param(ar, param,
4464 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4467 "failed to set peer stats period : %d\n",
4473 ar->num_started_vdevs = 0;
4474 ath10k_regd_update(ar);
4476 ath10k_spectral_start(ar);
4477 ath10k_thermal_set_throttling(ar);
4479 mutex_unlock(&ar->conf_mutex);
4483 ath10k_core_stop(ar);
4486 ath10k_hif_power_down(ar);
4489 ar->state = ATH10K_STATE_OFF;
4492 mutex_unlock(&ar->conf_mutex);
4496 static void ath10k_stop(struct ieee80211_hw *hw)
4498 struct ath10k *ar = hw->priv;
4500 ath10k_drain_tx(ar);
4502 mutex_lock(&ar->conf_mutex);
4503 if (ar->state != ATH10K_STATE_OFF) {
4505 ar->state = ATH10K_STATE_OFF;
4507 mutex_unlock(&ar->conf_mutex);
4509 cancel_delayed_work_sync(&ar->scan.timeout);
4510 cancel_work_sync(&ar->restart_work);
4513 static int ath10k_config_ps(struct ath10k *ar)
4515 struct ath10k_vif *arvif;
4518 lockdep_assert_held(&ar->conf_mutex);
4520 list_for_each_entry(arvif, &ar->arvifs, list) {
4521 ret = ath10k_mac_vif_setup_ps(arvif);
4523 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4531 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4536 lockdep_assert_held(&ar->conf_mutex);
4538 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4540 param = ar->wmi.pdev_param->txpower_limit2g;
4541 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4543 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4548 param = ar->wmi.pdev_param->txpower_limit5g;
4549 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4551 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4559 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4561 struct ath10k_vif *arvif;
4562 int ret, txpower = -1;
4564 lockdep_assert_held(&ar->conf_mutex);
4566 list_for_each_entry(arvif, &ar->arvifs, list) {
4567 WARN_ON(arvif->txpower < 0);
4570 txpower = arvif->txpower;
4572 txpower = min(txpower, arvif->txpower);
4575 if (WARN_ON(txpower == -1))
4578 ret = ath10k_mac_txpower_setup(ar, txpower);
4580 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4588 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4590 struct ath10k *ar = hw->priv;
4591 struct ieee80211_conf *conf = &hw->conf;
4594 mutex_lock(&ar->conf_mutex);
4596 if (changed & IEEE80211_CONF_CHANGE_PS)
4597 ath10k_config_ps(ar);
4599 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4600 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4601 ret = ath10k_monitor_recalc(ar);
4603 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4606 mutex_unlock(&ar->conf_mutex);
4610 static u32 get_nss_from_chainmask(u16 chain_mask)
4612 if ((chain_mask & 0xf) == 0xf)
4614 else if ((chain_mask & 0x7) == 0x7)
4616 else if ((chain_mask & 0x3) == 0x3)
4621 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4624 struct ath10k *ar = arvif->ar;
4628 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4631 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4632 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4633 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4634 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4636 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4637 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4638 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4639 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4644 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4645 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4647 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4648 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4649 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4651 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4652 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4654 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4655 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4656 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4658 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4659 ar->wmi.vdev_param->txbf, value);
4664 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4665 * because we will send mgmt frames without CCK. This requirement
4666 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4669 static int ath10k_add_interface(struct ieee80211_hw *hw,
4670 struct ieee80211_vif *vif)
4672 struct ath10k *ar = hw->priv;
4673 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4674 struct ath10k_peer *peer;
4675 enum wmi_sta_powersave_param param;
4682 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4684 mutex_lock(&ar->conf_mutex);
4686 memset(arvif, 0, sizeof(*arvif));
4687 ath10k_mac_txq_init(vif->txq);
4692 INIT_LIST_HEAD(&arvif->list);
4693 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4694 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4695 ath10k_mac_vif_sta_connection_loss_work);
4697 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4698 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4699 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4700 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4701 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4702 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4705 if (ar->num_peers >= ar->max_num_peers) {
4706 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4711 if (ar->free_vdev_map == 0) {
4712 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4716 bit = __ffs64(ar->free_vdev_map);
4718 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4719 bit, ar->free_vdev_map);
4721 arvif->vdev_id = bit;
4722 arvif->vdev_subtype =
4723 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4725 switch (vif->type) {
4726 case NL80211_IFTYPE_P2P_DEVICE:
4727 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4728 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4729 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4731 case NL80211_IFTYPE_UNSPECIFIED:
4732 case NL80211_IFTYPE_STATION:
4733 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4735 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4736 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4738 case NL80211_IFTYPE_ADHOC:
4739 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4741 case NL80211_IFTYPE_MESH_POINT:
4742 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4743 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4744 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4745 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4747 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4750 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4752 case NL80211_IFTYPE_AP:
4753 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4756 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4757 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4759 case NL80211_IFTYPE_MONITOR:
4760 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4767 /* Using vdev_id as queue number will make it very easy to do per-vif
4768 * tx queue locking. This shouldn't wrap due to interface combinations
4769 * but do a modulo for correctness sake and prevent using offchannel tx
4770 * queues for regular vif tx.
4772 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4773 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4774 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4776 /* Some firmware revisions don't wait for beacon tx completion before
4777 * sending another SWBA event. This could lead to hardware using old
4778 * (freed) beacon data in some cases, e.g. tx credit starvation
4779 * combined with missed TBTT. This is very very rare.
4781 * On non-IOMMU-enabled hosts this could be a possible security issue
4782 * because hw could beacon some random data on the air. On
4783 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4784 * device would crash.
4786 * Since there are no beacon tx completions (implicit nor explicit)
4787 * propagated to host the only workaround for this is to allocate a
4788 * DMA-coherent buffer for a lifetime of a vif and use it for all
4789 * beacon tx commands. Worst case for this approach is some beacons may
4790 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4792 if (vif->type == NL80211_IFTYPE_ADHOC ||
4793 vif->type == NL80211_IFTYPE_MESH_POINT ||
4794 vif->type == NL80211_IFTYPE_AP) {
4795 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4796 IEEE80211_MAX_FRAME_LEN,
4797 &arvif->beacon_paddr,
4799 if (!arvif->beacon_buf) {
4801 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4806 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4807 arvif->nohwcrypt = true;
4809 if (arvif->nohwcrypt &&
4810 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4811 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4815 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4816 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4817 arvif->beacon_buf ? "single-buf" : "per-skb");
4819 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4820 arvif->vdev_subtype, vif->addr);
4822 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4823 arvif->vdev_id, ret);
4827 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4828 list_add(&arvif->list, &ar->arvifs);
4830 /* It makes no sense to have firmware do keepalives. mac80211 already
4831 * takes care of this with idle connection polling.
4833 ret = ath10k_mac_vif_disable_keepalive(arvif);
4835 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4836 arvif->vdev_id, ret);
4837 goto err_vdev_delete;
4840 arvif->def_wep_key_idx = -1;
4842 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4843 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4844 ATH10K_HW_TXRX_NATIVE_WIFI);
4845 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4846 if (ret && ret != -EOPNOTSUPP) {
4847 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4848 arvif->vdev_id, ret);
4849 goto err_vdev_delete;
4852 /* Configuring number of spatial stream for monitor interface is causing
4853 * target assert in qca9888 and qca6174.
4855 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
4856 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4858 vdev_param = ar->wmi.vdev_param->nss;
4859 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4862 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4863 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4865 goto err_vdev_delete;
4869 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4870 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4871 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
4872 vif->addr, WMI_PEER_TYPE_DEFAULT);
4874 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4875 arvif->vdev_id, ret);
4876 goto err_vdev_delete;
4879 spin_lock_bh(&ar->data_lock);
4881 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
4883 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
4884 vif->addr, arvif->vdev_id);
4885 spin_unlock_bh(&ar->data_lock);
4887 goto err_peer_delete;
4890 arvif->peer_id = find_first_bit(peer->peer_ids,
4891 ATH10K_MAX_NUM_PEER_IDS);
4893 spin_unlock_bh(&ar->data_lock);
4895 arvif->peer_id = HTT_INVALID_PEERID;
4898 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4899 ret = ath10k_mac_set_kickout(arvif);
4901 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
4902 arvif->vdev_id, ret);
4903 goto err_peer_delete;
4907 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4908 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4909 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4910 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4913 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
4914 arvif->vdev_id, ret);
4915 goto err_peer_delete;
4918 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4920 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4921 arvif->vdev_id, ret);
4922 goto err_peer_delete;
4925 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4927 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4928 arvif->vdev_id, ret);
4929 goto err_peer_delete;
4933 ret = ath10k_mac_set_txbf_conf(arvif);
4935 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
4936 arvif->vdev_id, ret);
4937 goto err_peer_delete;
4940 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
4942 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4943 arvif->vdev_id, ret);
4944 goto err_peer_delete;
4947 arvif->txpower = vif->bss_conf.txpower;
4948 ret = ath10k_mac_txpower_recalc(ar);
4950 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4951 goto err_peer_delete;
4954 if (vif->type == NL80211_IFTYPE_MONITOR) {
4955 ar->monitor_arvif = arvif;
4956 ret = ath10k_monitor_recalc(ar);
4958 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4959 goto err_peer_delete;
4963 spin_lock_bh(&ar->htt.tx_lock);
4965 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
4966 spin_unlock_bh(&ar->htt.tx_lock);
4968 mutex_unlock(&ar->conf_mutex);
4972 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4973 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
4974 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4977 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4978 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4979 list_del(&arvif->list);
4982 if (arvif->beacon_buf) {
4983 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4984 arvif->beacon_buf, arvif->beacon_paddr);
4985 arvif->beacon_buf = NULL;
4988 mutex_unlock(&ar->conf_mutex);
4993 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4997 for (i = 0; i < BITS_PER_LONG; i++)
4998 ath10k_mac_vif_tx_unlock(arvif, i);
5001 static void ath10k_remove_interface(struct ieee80211_hw *hw,
5002 struct ieee80211_vif *vif)
5004 struct ath10k *ar = hw->priv;
5005 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5006 struct ath10k_peer *peer;
5010 cancel_work_sync(&arvif->ap_csa_work);
5011 cancel_delayed_work_sync(&arvif->connection_loss_work);
5013 mutex_lock(&ar->conf_mutex);
5015 spin_lock_bh(&ar->data_lock);
5016 ath10k_mac_vif_beacon_cleanup(arvif);
5017 spin_unlock_bh(&ar->data_lock);
5019 ret = ath10k_spectral_vif_stop(arvif);
5021 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
5022 arvif->vdev_id, ret);
5024 ar->free_vdev_map |= 1LL << arvif->vdev_id;
5025 list_del(&arvif->list);
5027 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5028 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5029 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
5032 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
5033 arvif->vdev_id, ret);
5035 kfree(arvif->u.ap.noa_data);
5038 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
5041 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
5043 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
5044 arvif->vdev_id, ret);
5046 /* Some firmware revisions don't notify host about self-peer removal
5047 * until after associated vdev is deleted.
5049 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
5050 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
5051 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
5054 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
5055 arvif->vdev_id, ret);
5057 spin_lock_bh(&ar->data_lock);
5059 spin_unlock_bh(&ar->data_lock);
5062 spin_lock_bh(&ar->data_lock);
5063 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5064 peer = ar->peer_map[i];
5068 if (peer->vif == vif) {
5069 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
5070 vif->addr, arvif->vdev_id);
5074 spin_unlock_bh(&ar->data_lock);
5076 ath10k_peer_cleanup(ar, arvif->vdev_id);
5077 ath10k_mac_txq_unref(ar, vif->txq);
5079 if (vif->type == NL80211_IFTYPE_MONITOR) {
5080 ar->monitor_arvif = NULL;
5081 ret = ath10k_monitor_recalc(ar);
5083 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
5086 spin_lock_bh(&ar->htt.tx_lock);
5087 ath10k_mac_vif_tx_unlock_all(arvif);
5088 spin_unlock_bh(&ar->htt.tx_lock);
5090 ath10k_mac_txq_unref(ar, vif->txq);
5092 mutex_unlock(&ar->conf_mutex);
5096 * FIXME: Has to be verified.
5098 #define SUPPORTED_FILTERS \
5103 FIF_BCN_PRBRESP_PROMISC | \
5107 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5108 unsigned int changed_flags,
5109 unsigned int *total_flags,
5112 struct ath10k *ar = hw->priv;
5115 mutex_lock(&ar->conf_mutex);
5117 changed_flags &= SUPPORTED_FILTERS;
5118 *total_flags &= SUPPORTED_FILTERS;
5119 ar->filter_flags = *total_flags;
5121 ret = ath10k_monitor_recalc(ar);
5123 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
5125 mutex_unlock(&ar->conf_mutex);
5128 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5129 struct ieee80211_vif *vif,
5130 struct ieee80211_bss_conf *info,
5133 struct ath10k *ar = hw->priv;
5134 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5136 u32 vdev_param, pdev_param, slottime, preamble;
5138 mutex_lock(&ar->conf_mutex);
5140 if (changed & BSS_CHANGED_IBSS)
5141 ath10k_control_ibss(arvif, info, vif->addr);
5143 if (changed & BSS_CHANGED_BEACON_INT) {
5144 arvif->beacon_interval = info->beacon_int;
5145 vdev_param = ar->wmi.vdev_param->beacon_interval;
5146 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5147 arvif->beacon_interval);
5148 ath10k_dbg(ar, ATH10K_DBG_MAC,
5149 "mac vdev %d beacon_interval %d\n",
5150 arvif->vdev_id, arvif->beacon_interval);
5153 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5154 arvif->vdev_id, ret);
5157 if (changed & BSS_CHANGED_BEACON) {
5158 ath10k_dbg(ar, ATH10K_DBG_MAC,
5159 "vdev %d set beacon tx mode to staggered\n",
5162 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5163 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5164 WMI_BEACON_STAGGERED_MODE);
5166 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5167 arvif->vdev_id, ret);
5169 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5171 ath10k_warn(ar, "failed to update beacon template: %d\n",
5174 if (ieee80211_vif_is_mesh(vif)) {
5175 /* mesh doesn't use SSID but firmware needs it */
5176 strncpy(arvif->u.ap.ssid, "mesh",
5177 sizeof(arvif->u.ap.ssid));
5178 arvif->u.ap.ssid_len = 4;
5182 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5183 ret = ath10k_mac_setup_prb_tmpl(arvif);
5185 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5186 arvif->vdev_id, ret);
5189 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5190 arvif->dtim_period = info->dtim_period;
5192 ath10k_dbg(ar, ATH10K_DBG_MAC,
5193 "mac vdev %d dtim_period %d\n",
5194 arvif->vdev_id, arvif->dtim_period);
5196 vdev_param = ar->wmi.vdev_param->dtim_period;
5197 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5198 arvif->dtim_period);
5200 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5201 arvif->vdev_id, ret);
5204 if (changed & BSS_CHANGED_SSID &&
5205 vif->type == NL80211_IFTYPE_AP) {
5206 arvif->u.ap.ssid_len = info->ssid_len;
5208 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5209 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5212 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5213 ether_addr_copy(arvif->bssid, info->bssid);
5215 if (changed & BSS_CHANGED_BEACON_ENABLED)
5216 ath10k_control_beaconing(arvif, info);
5218 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5219 arvif->use_cts_prot = info->use_cts_prot;
5220 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
5221 arvif->vdev_id, info->use_cts_prot);
5223 ret = ath10k_recalc_rtscts_prot(arvif);
5225 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5226 arvif->vdev_id, ret);
5228 vdev_param = ar->wmi.vdev_param->protection_mode;
5229 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5230 info->use_cts_prot ? 1 : 0);
5232 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
5233 info->use_cts_prot, arvif->vdev_id, ret);
5236 if (changed & BSS_CHANGED_ERP_SLOT) {
5237 if (info->use_short_slot)
5238 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5241 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5243 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5244 arvif->vdev_id, slottime);
5246 vdev_param = ar->wmi.vdev_param->slot_time;
5247 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5250 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5251 arvif->vdev_id, ret);
5254 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5255 if (info->use_short_preamble)
5256 preamble = WMI_VDEV_PREAMBLE_SHORT;
5258 preamble = WMI_VDEV_PREAMBLE_LONG;
5260 ath10k_dbg(ar, ATH10K_DBG_MAC,
5261 "mac vdev %d preamble %dn",
5262 arvif->vdev_id, preamble);
5264 vdev_param = ar->wmi.vdev_param->preamble;
5265 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5268 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5269 arvif->vdev_id, ret);
5272 if (changed & BSS_CHANGED_ASSOC) {
5274 /* Workaround: Make sure monitor vdev is not running
5275 * when associating to prevent some firmware revisions
5276 * (e.g. 10.1 and 10.2) from crashing.
5278 if (ar->monitor_started)
5279 ath10k_monitor_stop(ar);
5280 ath10k_bss_assoc(hw, vif, info);
5281 ath10k_monitor_recalc(ar);
5283 ath10k_bss_disassoc(hw, vif);
5287 if (changed & BSS_CHANGED_TXPOWER) {
5288 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5289 arvif->vdev_id, info->txpower);
5291 arvif->txpower = info->txpower;
5292 ret = ath10k_mac_txpower_recalc(ar);
5294 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5297 if (changed & BSS_CHANGED_PS) {
5298 arvif->ps = vif->bss_conf.ps;
5300 ret = ath10k_config_ps(ar);
5302 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5303 arvif->vdev_id, ret);
5306 mutex_unlock(&ar->conf_mutex);
5309 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5310 struct ieee80211_vif *vif,
5311 struct ieee80211_scan_request *hw_req)
5313 struct ath10k *ar = hw->priv;
5314 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5315 struct cfg80211_scan_request *req = &hw_req->req;
5316 struct wmi_start_scan_arg arg;
5320 mutex_lock(&ar->conf_mutex);
5322 spin_lock_bh(&ar->data_lock);
5323 switch (ar->scan.state) {
5324 case ATH10K_SCAN_IDLE:
5325 reinit_completion(&ar->scan.started);
5326 reinit_completion(&ar->scan.completed);
5327 ar->scan.state = ATH10K_SCAN_STARTING;
5328 ar->scan.is_roc = false;
5329 ar->scan.vdev_id = arvif->vdev_id;
5332 case ATH10K_SCAN_STARTING:
5333 case ATH10K_SCAN_RUNNING:
5334 case ATH10K_SCAN_ABORTING:
5338 spin_unlock_bh(&ar->data_lock);
5343 memset(&arg, 0, sizeof(arg));
5344 ath10k_wmi_start_scan_init(ar, &arg);
5345 arg.vdev_id = arvif->vdev_id;
5346 arg.scan_id = ATH10K_SCAN_ID;
5349 arg.ie_len = req->ie_len;
5350 memcpy(arg.ie, req->ie, arg.ie_len);
5354 arg.n_ssids = req->n_ssids;
5355 for (i = 0; i < arg.n_ssids; i++) {
5356 arg.ssids[i].len = req->ssids[i].ssid_len;
5357 arg.ssids[i].ssid = req->ssids[i].ssid;
5360 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5363 if (req->n_channels) {
5364 arg.n_channels = req->n_channels;
5365 for (i = 0; i < arg.n_channels; i++)
5366 arg.channels[i] = req->channels[i]->center_freq;
5369 ret = ath10k_start_scan(ar, &arg);
5371 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5372 spin_lock_bh(&ar->data_lock);
5373 ar->scan.state = ATH10K_SCAN_IDLE;
5374 spin_unlock_bh(&ar->data_lock);
5377 /* Add a 200ms margin to account for event/command processing */
5378 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5379 msecs_to_jiffies(arg.max_scan_time +
5383 mutex_unlock(&ar->conf_mutex);
5387 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5388 struct ieee80211_vif *vif)
5390 struct ath10k *ar = hw->priv;
5392 mutex_lock(&ar->conf_mutex);
5393 ath10k_scan_abort(ar);
5394 mutex_unlock(&ar->conf_mutex);
5396 cancel_delayed_work_sync(&ar->scan.timeout);
5399 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5400 struct ath10k_vif *arvif,
5401 enum set_key_cmd cmd,
5402 struct ieee80211_key_conf *key)
5404 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5407 /* 10.1 firmware branch requires default key index to be set to group
5408 * key index after installing it. Otherwise FW/HW Txes corrupted
5409 * frames with multi-vif APs. This is not required for main firmware
5410 * branch (e.g. 636).
5412 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5414 * FIXME: It remains unknown if this is required for multi-vif STA
5415 * interfaces on 10.1.
5418 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5419 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5422 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5425 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5428 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5434 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5437 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5438 arvif->vdev_id, ret);
5441 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5442 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5443 struct ieee80211_key_conf *key)
5445 struct ath10k *ar = hw->priv;
5446 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5447 struct ath10k_peer *peer;
5448 const u8 *peer_addr;
5449 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5450 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5456 /* this one needs to be done in software */
5457 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5460 if (arvif->nohwcrypt)
5463 if (key->keyidx > WMI_MAX_KEY_INDEX)
5466 mutex_lock(&ar->conf_mutex);
5469 peer_addr = sta->addr;
5470 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5471 peer_addr = vif->bss_conf.bssid;
5473 peer_addr = vif->addr;
5475 key->hw_key_idx = key->keyidx;
5479 arvif->wep_keys[key->keyidx] = key;
5481 arvif->wep_keys[key->keyidx] = NULL;
5484 /* the peer should not disappear in mid-way (unless FW goes awry) since
5485 * we already hold conf_mutex. we just make sure its there now. */
5486 spin_lock_bh(&ar->data_lock);
5487 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5488 spin_unlock_bh(&ar->data_lock);
5491 if (cmd == SET_KEY) {
5492 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5497 /* if the peer doesn't exist there is no key to disable
5503 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5504 flags |= WMI_KEY_PAIRWISE;
5506 flags |= WMI_KEY_GROUP;
5509 if (cmd == DISABLE_KEY)
5510 ath10k_clear_vdev_key(arvif, key);
5512 /* When WEP keys are uploaded it's possible that there are
5513 * stations associated already (e.g. when merging) without any
5514 * keys. Static WEP needs an explicit per-peer key upload.
5516 if (vif->type == NL80211_IFTYPE_ADHOC &&
5518 ath10k_mac_vif_update_wep_key(arvif, key);
5520 /* 802.1x never sets the def_wep_key_idx so each set_key()
5521 * call changes default tx key.
5523 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5524 * after first set_key().
5526 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5527 flags |= WMI_KEY_TX_USAGE;
5530 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5533 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5534 arvif->vdev_id, peer_addr, ret);
5538 /* mac80211 sets static WEP keys as groupwise while firmware requires
5539 * them to be installed twice as both pairwise and groupwise.
5541 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5543 flags2 &= ~WMI_KEY_GROUP;
5544 flags2 |= WMI_KEY_PAIRWISE;
5546 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5549 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5550 arvif->vdev_id, peer_addr, ret);
5551 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5555 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5556 arvif->vdev_id, peer_addr, ret2);
5562 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5564 spin_lock_bh(&ar->data_lock);
5565 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5566 if (peer && cmd == SET_KEY)
5567 peer->keys[key->keyidx] = key;
5568 else if (peer && cmd == DISABLE_KEY)
5569 peer->keys[key->keyidx] = NULL;
5570 else if (peer == NULL)
5571 /* impossible unless FW goes crazy */
5572 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5573 spin_unlock_bh(&ar->data_lock);
5576 mutex_unlock(&ar->conf_mutex);
5580 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5581 struct ieee80211_vif *vif,
5584 struct ath10k *ar = hw->priv;
5585 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5588 mutex_lock(&arvif->ar->conf_mutex);
5590 if (arvif->ar->state != ATH10K_STATE_ON)
5593 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5594 arvif->vdev_id, keyidx);
5596 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5598 arvif->ar->wmi.vdev_param->def_keyid,
5602 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5608 arvif->def_wep_key_idx = keyidx;
5611 mutex_unlock(&arvif->ar->conf_mutex);
5614 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5617 struct ath10k_vif *arvif;
5618 struct ath10k_sta *arsta;
5619 struct ieee80211_sta *sta;
5620 struct cfg80211_chan_def def;
5621 enum ieee80211_band band;
5622 const u8 *ht_mcs_mask;
5623 const u16 *vht_mcs_mask;
5624 u32 changed, bw, nss, smps;
5627 arsta = container_of(wk, struct ath10k_sta, update_wk);
5628 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5629 arvif = arsta->arvif;
5632 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5635 band = def.chan->band;
5636 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5637 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5639 spin_lock_bh(&ar->data_lock);
5641 changed = arsta->changed;
5648 spin_unlock_bh(&ar->data_lock);
5650 mutex_lock(&ar->conf_mutex);
5652 nss = max_t(u32, 1, nss);
5653 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5654 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5656 if (changed & IEEE80211_RC_BW_CHANGED) {
5657 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5660 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5661 WMI_PEER_CHAN_WIDTH, bw);
5663 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5664 sta->addr, bw, err);
5667 if (changed & IEEE80211_RC_NSS_CHANGED) {
5668 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5671 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5674 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5675 sta->addr, nss, err);
5678 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5679 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5682 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5683 WMI_PEER_SMPS_STATE, smps);
5685 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5686 sta->addr, smps, err);
5689 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5690 changed & IEEE80211_RC_NSS_CHANGED) {
5691 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
5694 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5696 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5700 mutex_unlock(&ar->conf_mutex);
5703 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5704 struct ieee80211_sta *sta)
5706 struct ath10k *ar = arvif->ar;
5708 lockdep_assert_held(&ar->conf_mutex);
5710 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5713 if (ar->num_stations >= ar->max_num_stations)
5721 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5722 struct ieee80211_sta *sta)
5724 struct ath10k *ar = arvif->ar;
5726 lockdep_assert_held(&ar->conf_mutex);
5728 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5734 struct ath10k_mac_tdls_iter_data {
5735 u32 num_tdls_stations;
5736 struct ieee80211_vif *curr_vif;
5739 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5740 struct ieee80211_sta *sta)
5742 struct ath10k_mac_tdls_iter_data *iter_data = data;
5743 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5744 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5746 if (sta->tdls && sta_vif == iter_data->curr_vif)
5747 iter_data->num_tdls_stations++;
5750 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5751 struct ieee80211_vif *vif)
5753 struct ath10k_mac_tdls_iter_data data = {};
5755 data.curr_vif = vif;
5757 ieee80211_iterate_stations_atomic(hw,
5758 ath10k_mac_tdls_vif_stations_count_iter,
5760 return data.num_tdls_stations;
5763 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5764 struct ieee80211_vif *vif)
5766 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5767 int *num_tdls_vifs = data;
5769 if (vif->type != NL80211_IFTYPE_STATION)
5772 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5776 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5778 int num_tdls_vifs = 0;
5780 ieee80211_iterate_active_interfaces_atomic(hw,
5781 IEEE80211_IFACE_ITER_NORMAL,
5782 ath10k_mac_tdls_vifs_count_iter,
5784 return num_tdls_vifs;
5787 static int ath10k_sta_state(struct ieee80211_hw *hw,
5788 struct ieee80211_vif *vif,
5789 struct ieee80211_sta *sta,
5790 enum ieee80211_sta_state old_state,
5791 enum ieee80211_sta_state new_state)
5793 struct ath10k *ar = hw->priv;
5794 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5795 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5796 struct ath10k_peer *peer;
5800 if (old_state == IEEE80211_STA_NOTEXIST &&
5801 new_state == IEEE80211_STA_NONE) {
5802 memset(arsta, 0, sizeof(*arsta));
5803 arsta->arvif = arvif;
5804 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5806 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5807 ath10k_mac_txq_init(sta->txq[i]);
5810 /* cancel must be done outside the mutex to avoid deadlock */
5811 if ((old_state == IEEE80211_STA_NONE &&
5812 new_state == IEEE80211_STA_NOTEXIST))
5813 cancel_work_sync(&arsta->update_wk);
5815 mutex_lock(&ar->conf_mutex);
5817 if (old_state == IEEE80211_STA_NOTEXIST &&
5818 new_state == IEEE80211_STA_NONE) {
5820 * New station addition.
5822 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5823 u32 num_tdls_stations;
5826 ath10k_dbg(ar, ATH10K_DBG_MAC,
5827 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5828 arvif->vdev_id, sta->addr,
5829 ar->num_stations + 1, ar->max_num_stations,
5830 ar->num_peers + 1, ar->max_num_peers);
5832 ret = ath10k_mac_inc_num_stations(arvif, sta);
5834 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5835 ar->max_num_stations);
5840 peer_type = WMI_PEER_TYPE_TDLS;
5842 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
5843 sta->addr, peer_type);
5845 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5846 sta->addr, arvif->vdev_id, ret);
5847 ath10k_mac_dec_num_stations(arvif, sta);
5851 spin_lock_bh(&ar->data_lock);
5853 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
5855 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5856 vif->addr, arvif->vdev_id);
5857 spin_unlock_bh(&ar->data_lock);
5858 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5859 ath10k_mac_dec_num_stations(arvif, sta);
5864 arsta->peer_id = find_first_bit(peer->peer_ids,
5865 ATH10K_MAX_NUM_PEER_IDS);
5867 spin_unlock_bh(&ar->data_lock);
5872 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5873 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5875 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5876 num_tdls_stations == 0) {
5877 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5878 arvif->vdev_id, ar->max_num_tdls_vdevs);
5879 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5880 ath10k_mac_dec_num_stations(arvif, sta);
5885 if (num_tdls_stations == 0) {
5886 /* This is the first tdls peer in current vif */
5887 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5889 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5892 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5893 arvif->vdev_id, ret);
5894 ath10k_peer_delete(ar, arvif->vdev_id,
5896 ath10k_mac_dec_num_stations(arvif, sta);
5901 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5902 WMI_TDLS_PEER_STATE_PEERING);
5905 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5906 sta->addr, arvif->vdev_id, ret);
5907 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5908 ath10k_mac_dec_num_stations(arvif, sta);
5910 if (num_tdls_stations != 0)
5912 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5915 } else if ((old_state == IEEE80211_STA_NONE &&
5916 new_state == IEEE80211_STA_NOTEXIST)) {
5918 * Existing station deletion.
5920 ath10k_dbg(ar, ATH10K_DBG_MAC,
5921 "mac vdev %d peer delete %pM (sta gone)\n",
5922 arvif->vdev_id, sta->addr);
5924 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5926 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
5927 sta->addr, arvif->vdev_id, ret);
5929 ath10k_mac_dec_num_stations(arvif, sta);
5931 spin_lock_bh(&ar->data_lock);
5932 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5933 peer = ar->peer_map[i];
5937 if (peer->sta == sta) {
5938 ath10k_warn(ar, "found sta peer %pM entry on vdev %i after it was supposedly removed\n",
5939 sta->addr, arvif->vdev_id);
5943 spin_unlock_bh(&ar->data_lock);
5945 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5946 ath10k_mac_txq_unref(ar, sta->txq[i]);
5951 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5954 /* This was the last tdls peer in current vif */
5955 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5958 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5959 arvif->vdev_id, ret);
5961 } else if (old_state == IEEE80211_STA_AUTH &&
5962 new_state == IEEE80211_STA_ASSOC &&
5963 (vif->type == NL80211_IFTYPE_AP ||
5964 vif->type == NL80211_IFTYPE_MESH_POINT ||
5965 vif->type == NL80211_IFTYPE_ADHOC)) {
5969 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
5972 ret = ath10k_station_assoc(ar, vif, sta, false);
5974 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
5975 sta->addr, arvif->vdev_id, ret);
5976 } else if (old_state == IEEE80211_STA_ASSOC &&
5977 new_state == IEEE80211_STA_AUTHORIZED &&
5980 * Tdls station authorized.
5982 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5985 ret = ath10k_station_assoc(ar, vif, sta, false);
5987 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5988 sta->addr, arvif->vdev_id, ret);
5992 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5993 WMI_TDLS_PEER_STATE_CONNECTED);
5995 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5996 sta->addr, arvif->vdev_id, ret);
5997 } else if (old_state == IEEE80211_STA_ASSOC &&
5998 new_state == IEEE80211_STA_AUTH &&
5999 (vif->type == NL80211_IFTYPE_AP ||
6000 vif->type == NL80211_IFTYPE_MESH_POINT ||
6001 vif->type == NL80211_IFTYPE_ADHOC)) {
6005 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
6008 ret = ath10k_station_disassoc(ar, vif, sta);
6010 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
6011 sta->addr, arvif->vdev_id, ret);
6014 mutex_unlock(&ar->conf_mutex);
6018 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
6019 u16 ac, bool enable)
6021 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6022 struct wmi_sta_uapsd_auto_trig_arg arg = {};
6023 u32 prio = 0, acc = 0;
6027 lockdep_assert_held(&ar->conf_mutex);
6029 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
6033 case IEEE80211_AC_VO:
6034 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
6035 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
6039 case IEEE80211_AC_VI:
6040 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
6041 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
6045 case IEEE80211_AC_BE:
6046 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
6047 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
6051 case IEEE80211_AC_BK:
6052 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
6053 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
6060 arvif->u.sta.uapsd |= value;
6062 arvif->u.sta.uapsd &= ~value;
6064 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6065 WMI_STA_PS_PARAM_UAPSD,
6066 arvif->u.sta.uapsd);
6068 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
6072 if (arvif->u.sta.uapsd)
6073 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
6075 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6077 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6078 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
6081 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
6083 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
6085 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
6086 arvif->vdev_id, ret);
6090 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6092 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6093 arvif->vdev_id, ret);
6097 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6098 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6099 /* Only userspace can make an educated decision when to send
6100 * trigger frame. The following effectively disables u-UAPSD
6101 * autotrigger in firmware (which is enabled by default
6102 * provided the autotrigger service is available).
6106 arg.user_priority = prio;
6107 arg.service_interval = 0;
6108 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6109 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6111 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6112 arvif->bssid, &arg, 1);
6114 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6124 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6125 struct ieee80211_vif *vif, u16 ac,
6126 const struct ieee80211_tx_queue_params *params)
6128 struct ath10k *ar = hw->priv;
6129 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6130 struct wmi_wmm_params_arg *p = NULL;
6133 mutex_lock(&ar->conf_mutex);
6136 case IEEE80211_AC_VO:
6137 p = &arvif->wmm_params.ac_vo;
6139 case IEEE80211_AC_VI:
6140 p = &arvif->wmm_params.ac_vi;
6142 case IEEE80211_AC_BE:
6143 p = &arvif->wmm_params.ac_be;
6145 case IEEE80211_AC_BK:
6146 p = &arvif->wmm_params.ac_bk;
6155 p->cwmin = params->cw_min;
6156 p->cwmax = params->cw_max;
6157 p->aifs = params->aifs;
6160 * The channel time duration programmed in the HW is in absolute
6161 * microseconds, while mac80211 gives the txop in units of
6164 p->txop = params->txop * 32;
6166 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6167 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6168 &arvif->wmm_params);
6170 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6171 arvif->vdev_id, ret);
6175 /* This won't work well with multi-interface cases but it's
6176 * better than nothing.
6178 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6180 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6185 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6187 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6190 mutex_unlock(&ar->conf_mutex);
6194 #define ATH10K_ROC_TIMEOUT_HZ (2 * HZ)
6196 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6197 struct ieee80211_vif *vif,
6198 struct ieee80211_channel *chan,
6200 enum ieee80211_roc_type type)
6202 struct ath10k *ar = hw->priv;
6203 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6204 struct wmi_start_scan_arg arg;
6208 mutex_lock(&ar->conf_mutex);
6210 spin_lock_bh(&ar->data_lock);
6211 switch (ar->scan.state) {
6212 case ATH10K_SCAN_IDLE:
6213 reinit_completion(&ar->scan.started);
6214 reinit_completion(&ar->scan.completed);
6215 reinit_completion(&ar->scan.on_channel);
6216 ar->scan.state = ATH10K_SCAN_STARTING;
6217 ar->scan.is_roc = true;
6218 ar->scan.vdev_id = arvif->vdev_id;
6219 ar->scan.roc_freq = chan->center_freq;
6220 ar->scan.roc_notify = true;
6223 case ATH10K_SCAN_STARTING:
6224 case ATH10K_SCAN_RUNNING:
6225 case ATH10K_SCAN_ABORTING:
6229 spin_unlock_bh(&ar->data_lock);
6234 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6236 memset(&arg, 0, sizeof(arg));
6237 ath10k_wmi_start_scan_init(ar, &arg);
6238 arg.vdev_id = arvif->vdev_id;
6239 arg.scan_id = ATH10K_SCAN_ID;
6241 arg.channels[0] = chan->center_freq;
6242 arg.dwell_time_active = scan_time_msec;
6243 arg.dwell_time_passive = scan_time_msec;
6244 arg.max_scan_time = scan_time_msec;
6245 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6246 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6247 arg.burst_duration_ms = duration;
6249 ret = ath10k_start_scan(ar, &arg);
6251 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6252 spin_lock_bh(&ar->data_lock);
6253 ar->scan.state = ATH10K_SCAN_IDLE;
6254 spin_unlock_bh(&ar->data_lock);
6258 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
6260 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6262 ret = ath10k_scan_stop(ar);
6264 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6270 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6271 msecs_to_jiffies(duration));
6275 mutex_unlock(&ar->conf_mutex);
6279 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6281 struct ath10k *ar = hw->priv;
6283 mutex_lock(&ar->conf_mutex);
6285 spin_lock_bh(&ar->data_lock);
6286 ar->scan.roc_notify = false;
6287 spin_unlock_bh(&ar->data_lock);
6289 ath10k_scan_abort(ar);
6291 mutex_unlock(&ar->conf_mutex);
6293 cancel_delayed_work_sync(&ar->scan.timeout);
6299 * Both RTS and Fragmentation threshold are interface-specific
6300 * in ath10k, but device-specific in mac80211.
6303 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6305 struct ath10k *ar = hw->priv;
6306 struct ath10k_vif *arvif;
6309 mutex_lock(&ar->conf_mutex);
6310 list_for_each_entry(arvif, &ar->arvifs, list) {
6311 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6312 arvif->vdev_id, value);
6314 ret = ath10k_mac_set_rts(arvif, value);
6316 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6317 arvif->vdev_id, ret);
6321 mutex_unlock(&ar->conf_mutex);
6326 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6328 /* Even though there's a WMI enum for fragmentation threshold no known
6329 * firmware actually implements it. Moreover it is not possible to rely
6330 * frame fragmentation to mac80211 because firmware clears the "more
6331 * fragments" bit in frame control making it impossible for remote
6332 * devices to reassemble frames.
6334 * Hence implement a dummy callback just to say fragmentation isn't
6335 * supported. This effectively prevents mac80211 from doing frame
6336 * fragmentation in software.
6341 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6342 u32 queues, bool drop)
6344 struct ath10k *ar = hw->priv;
6348 /* mac80211 doesn't care if we really xmit queued frames or not
6349 * we'll collect those frames either way if we stop/delete vdevs */
6353 mutex_lock(&ar->conf_mutex);
6355 if (ar->state == ATH10K_STATE_WEDGED)
6358 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6361 spin_lock_bh(&ar->htt.tx_lock);
6362 empty = (ar->htt.num_pending_tx == 0);
6363 spin_unlock_bh(&ar->htt.tx_lock);
6365 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6366 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6370 }), ATH10K_FLUSH_TIMEOUT_HZ);
6372 if (time_left == 0 || skip)
6373 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6374 skip, ar->state, time_left);
6377 mutex_unlock(&ar->conf_mutex);
6380 /* TODO: Implement this function properly
6381 * For now it is needed to reply to Probe Requests in IBSS mode.
6382 * Propably we need this information from FW.
6384 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6389 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6390 enum ieee80211_reconfig_type reconfig_type)
6392 struct ath10k *ar = hw->priv;
6394 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6397 mutex_lock(&ar->conf_mutex);
6399 /* If device failed to restart it will be in a different state, e.g.
6400 * ATH10K_STATE_WEDGED */
6401 if (ar->state == ATH10K_STATE_RESTARTED) {
6402 ath10k_info(ar, "device successfully recovered\n");
6403 ar->state = ATH10K_STATE_ON;
6404 ieee80211_wake_queues(ar->hw);
6407 mutex_unlock(&ar->conf_mutex);
6410 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6411 struct survey_info *survey)
6413 struct ath10k *ar = hw->priv;
6414 struct ieee80211_supported_band *sband;
6415 struct survey_info *ar_survey = &ar->survey[idx];
6418 mutex_lock(&ar->conf_mutex);
6420 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
6421 if (sband && idx >= sband->n_channels) {
6422 idx -= sband->n_channels;
6427 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
6429 if (!sband || idx >= sband->n_channels) {
6434 spin_lock_bh(&ar->data_lock);
6435 memcpy(survey, ar_survey, sizeof(*survey));
6436 spin_unlock_bh(&ar->data_lock);
6438 survey->channel = &sband->channels[idx];
6440 if (ar->rx_channel == survey->channel)
6441 survey->filled |= SURVEY_INFO_IN_USE;
6444 mutex_unlock(&ar->conf_mutex);
6449 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6450 enum ieee80211_band band,
6451 const struct cfg80211_bitrate_mask *mask)
6456 num_rates += hweight32(mask->control[band].legacy);
6458 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6459 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6461 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6462 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6464 return num_rates == 1;
6468 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6469 enum ieee80211_band band,
6470 const struct cfg80211_bitrate_mask *mask,
6473 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6474 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6476 u8 vht_nss_mask = 0;
6479 if (mask->control[band].legacy)
6482 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6483 if (mask->control[band].ht_mcs[i] == 0)
6485 else if (mask->control[band].ht_mcs[i] ==
6486 sband->ht_cap.mcs.rx_mask[i])
6487 ht_nss_mask |= BIT(i);
6492 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6493 if (mask->control[band].vht_mcs[i] == 0)
6495 else if (mask->control[band].vht_mcs[i] ==
6496 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6497 vht_nss_mask |= BIT(i);
6502 if (ht_nss_mask != vht_nss_mask)
6505 if (ht_nss_mask == 0)
6508 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6511 *nss = fls(ht_nss_mask);
6517 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6518 enum ieee80211_band band,
6519 const struct cfg80211_bitrate_mask *mask,
6522 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6529 if (hweight32(mask->control[band].legacy) == 1) {
6530 rate_idx = ffs(mask->control[band].legacy) - 1;
6532 hw_rate = sband->bitrates[rate_idx].hw_value;
6533 bitrate = sband->bitrates[rate_idx].bitrate;
6535 if (ath10k_mac_bitrate_is_cck(bitrate))
6536 preamble = WMI_RATE_PREAMBLE_CCK;
6538 preamble = WMI_RATE_PREAMBLE_OFDM;
6541 *rate = preamble << 6 |
6548 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6549 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6551 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6553 (ffs(mask->control[band].ht_mcs[i]) - 1);
6559 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6560 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6562 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6564 (ffs(mask->control[band].vht_mcs[i]) - 1);
6573 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6574 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6576 struct ath10k *ar = arvif->ar;
6580 lockdep_assert_held(&ar->conf_mutex);
6582 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6583 arvif->vdev_id, rate, nss, sgi);
6585 vdev_param = ar->wmi.vdev_param->fixed_rate;
6586 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6588 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6593 vdev_param = ar->wmi.vdev_param->nss;
6594 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6596 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6600 vdev_param = ar->wmi.vdev_param->sgi;
6601 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6603 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6607 vdev_param = ar->wmi.vdev_param->ldpc;
6608 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6610 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6618 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6619 enum ieee80211_band band,
6620 const struct cfg80211_bitrate_mask *mask)
6625 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6626 * to express all VHT MCS rate masks. Effectively only the following
6627 * ranges can be used: none, 0-7, 0-8 and 0-9.
6629 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6630 vht_mcs = mask->control[band].vht_mcs[i];
6639 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6647 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6648 struct ieee80211_sta *sta)
6650 struct ath10k_vif *arvif = data;
6651 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6652 struct ath10k *ar = arvif->ar;
6654 if (arsta->arvif != arvif)
6657 spin_lock_bh(&ar->data_lock);
6658 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6659 spin_unlock_bh(&ar->data_lock);
6661 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6664 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6665 struct ieee80211_vif *vif,
6666 const struct cfg80211_bitrate_mask *mask)
6668 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6669 struct cfg80211_chan_def def;
6670 struct ath10k *ar = arvif->ar;
6671 enum ieee80211_band band;
6672 const u8 *ht_mcs_mask;
6673 const u16 *vht_mcs_mask;
6681 if (ath10k_mac_vif_chan(vif, &def))
6684 band = def.chan->band;
6685 ht_mcs_mask = mask->control[band].ht_mcs;
6686 vht_mcs_mask = mask->control[band].vht_mcs;
6687 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6689 sgi = mask->control[band].gi;
6690 if (sgi == NL80211_TXRATE_FORCE_LGI)
6693 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6694 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6697 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6698 arvif->vdev_id, ret);
6701 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6703 rate = WMI_FIXED_RATE_NONE;
6706 rate = WMI_FIXED_RATE_NONE;
6707 nss = min(ar->num_rf_chains,
6708 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6709 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6711 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6714 mutex_lock(&ar->conf_mutex);
6716 arvif->bitrate_mask = *mask;
6717 ieee80211_iterate_stations_atomic(ar->hw,
6718 ath10k_mac_set_bitrate_mask_iter,
6721 mutex_unlock(&ar->conf_mutex);
6724 mutex_lock(&ar->conf_mutex);
6726 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6728 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6729 arvif->vdev_id, ret);
6734 mutex_unlock(&ar->conf_mutex);
6739 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6740 struct ieee80211_vif *vif,
6741 struct ieee80211_sta *sta,
6744 struct ath10k *ar = hw->priv;
6745 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6748 spin_lock_bh(&ar->data_lock);
6750 ath10k_dbg(ar, ATH10K_DBG_MAC,
6751 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6752 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6755 if (changed & IEEE80211_RC_BW_CHANGED) {
6756 bw = WMI_PEER_CHWIDTH_20MHZ;
6758 switch (sta->bandwidth) {
6759 case IEEE80211_STA_RX_BW_20:
6760 bw = WMI_PEER_CHWIDTH_20MHZ;
6762 case IEEE80211_STA_RX_BW_40:
6763 bw = WMI_PEER_CHWIDTH_40MHZ;
6765 case IEEE80211_STA_RX_BW_80:
6766 bw = WMI_PEER_CHWIDTH_80MHZ;
6768 case IEEE80211_STA_RX_BW_160:
6769 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6770 sta->bandwidth, sta->addr);
6771 bw = WMI_PEER_CHWIDTH_20MHZ;
6778 if (changed & IEEE80211_RC_NSS_CHANGED)
6779 arsta->nss = sta->rx_nss;
6781 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6782 smps = WMI_PEER_SMPS_PS_NONE;
6784 switch (sta->smps_mode) {
6785 case IEEE80211_SMPS_AUTOMATIC:
6786 case IEEE80211_SMPS_OFF:
6787 smps = WMI_PEER_SMPS_PS_NONE;
6789 case IEEE80211_SMPS_STATIC:
6790 smps = WMI_PEER_SMPS_STATIC;
6792 case IEEE80211_SMPS_DYNAMIC:
6793 smps = WMI_PEER_SMPS_DYNAMIC;
6795 case IEEE80211_SMPS_NUM_MODES:
6796 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6797 sta->smps_mode, sta->addr);
6798 smps = WMI_PEER_SMPS_PS_NONE;
6805 arsta->changed |= changed;
6807 spin_unlock_bh(&ar->data_lock);
6809 ieee80211_queue_work(hw, &arsta->update_wk);
6812 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6815 * FIXME: Return 0 for time being. Need to figure out whether FW
6816 * has the API to fetch 64-bit local TSF
6822 static void ath10k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6825 struct ath10k *ar = hw->priv;
6826 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6827 u32 tsf_offset, vdev_param = ar->wmi.vdev_param->set_tsf;
6832 * Given tsf argument is entire TSF value, but firmware accepts
6833 * only TSF offset to current TSF.
6835 * get_tsf function is used to get offset value, however since
6836 * ath10k_get_tsf is not implemented properly, it will return 0 always.
6837 * Luckily all the caller functions to set_tsf, as of now, also rely on
6838 * get_tsf function to get entire tsf value such get_tsf() + tsf_delta,
6839 * final tsf offset value to firmware will be arithmetically correct.
6841 tsf_offset = tsf - ath10k_get_tsf(hw, vif);
6842 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
6843 vdev_param, tsf_offset);
6844 if (ret && ret != -EOPNOTSUPP)
6845 ath10k_warn(ar, "failed to set tsf offset: %d\n", ret);
6848 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6849 struct ieee80211_vif *vif,
6850 struct ieee80211_ampdu_params *params)
6852 struct ath10k *ar = hw->priv;
6853 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6854 struct ieee80211_sta *sta = params->sta;
6855 enum ieee80211_ampdu_mlme_action action = params->action;
6856 u16 tid = params->tid;
6858 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6859 arvif->vdev_id, sta->addr, tid, action);
6862 case IEEE80211_AMPDU_RX_START:
6863 case IEEE80211_AMPDU_RX_STOP:
6864 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6865 * creation/removal. Do we need to verify this?
6868 case IEEE80211_AMPDU_TX_START:
6869 case IEEE80211_AMPDU_TX_STOP_CONT:
6870 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6871 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6872 case IEEE80211_AMPDU_TX_OPERATIONAL:
6873 /* Firmware offloads Tx aggregation entirely so deny mac80211
6874 * Tx aggregation requests.
6883 ath10k_mac_update_rx_channel(struct ath10k *ar,
6884 struct ieee80211_chanctx_conf *ctx,
6885 struct ieee80211_vif_chanctx_switch *vifs,
6888 struct cfg80211_chan_def *def = NULL;
6890 /* Both locks are required because ar->rx_channel is modified. This
6891 * allows readers to hold either lock.
6893 lockdep_assert_held(&ar->conf_mutex);
6894 lockdep_assert_held(&ar->data_lock);
6896 WARN_ON(ctx && vifs);
6897 WARN_ON(vifs && n_vifs != 1);
6899 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6900 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6901 * ppdu on Rx may reduce performance on low-end systems. It should be
6902 * possible to make tables/hashmaps to speed the lookup up (be vary of
6903 * cpu data cache lines though regarding sizes) but to keep the initial
6904 * implementation simple and less intrusive fallback to the slow lookup
6905 * only for multi-channel cases. Single-channel cases will remain to
6906 * use the old channel derival and thus performance should not be
6910 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
6911 ieee80211_iter_chan_contexts_atomic(ar->hw,
6912 ath10k_mac_get_any_chandef_iter,
6916 def = &vifs[0].new_ctx->def;
6918 ar->rx_channel = def->chan;
6919 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
6920 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
6921 /* During driver restart due to firmware assert, since mac80211
6922 * already has valid channel context for given radio, channel
6923 * context iteration return num_chanctx > 0. So fix rx_channel
6924 * when restart is in progress.
6926 ar->rx_channel = ctx->def.chan;
6928 ar->rx_channel = NULL;
6934 ath10k_mac_update_vif_chan(struct ath10k *ar,
6935 struct ieee80211_vif_chanctx_switch *vifs,
6938 struct ath10k_vif *arvif;
6942 lockdep_assert_held(&ar->conf_mutex);
6944 /* First stop monitor interface. Some FW versions crash if there's a
6945 * lone monitor interface.
6947 if (ar->monitor_started)
6948 ath10k_monitor_stop(ar);
6950 for (i = 0; i < n_vifs; i++) {
6951 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6953 ath10k_dbg(ar, ATH10K_DBG_MAC,
6954 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6956 vifs[i].old_ctx->def.chan->center_freq,
6957 vifs[i].new_ctx->def.chan->center_freq,
6958 vifs[i].old_ctx->def.width,
6959 vifs[i].new_ctx->def.width);
6961 if (WARN_ON(!arvif->is_started))
6964 if (WARN_ON(!arvif->is_up))
6967 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6969 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6970 arvif->vdev_id, ret);
6975 /* All relevant vdevs are downed and associated channel resources
6976 * should be available for the channel switch now.
6979 spin_lock_bh(&ar->data_lock);
6980 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
6981 spin_unlock_bh(&ar->data_lock);
6983 for (i = 0; i < n_vifs; i++) {
6984 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6986 if (WARN_ON(!arvif->is_started))
6989 if (WARN_ON(!arvif->is_up))
6992 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6994 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6997 ret = ath10k_mac_setup_prb_tmpl(arvif);
6999 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
7002 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
7004 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
7005 arvif->vdev_id, ret);
7009 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
7012 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
7013 arvif->vdev_id, ret);
7018 ath10k_monitor_recalc(ar);
7022 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
7023 struct ieee80211_chanctx_conf *ctx)
7025 struct ath10k *ar = hw->priv;
7027 ath10k_dbg(ar, ATH10K_DBG_MAC,
7028 "mac chanctx add freq %hu width %d ptr %p\n",
7029 ctx->def.chan->center_freq, ctx->def.width, ctx);
7031 mutex_lock(&ar->conf_mutex);
7033 spin_lock_bh(&ar->data_lock);
7034 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
7035 spin_unlock_bh(&ar->data_lock);
7037 ath10k_recalc_radar_detection(ar);
7038 ath10k_monitor_recalc(ar);
7040 mutex_unlock(&ar->conf_mutex);
7046 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
7047 struct ieee80211_chanctx_conf *ctx)
7049 struct ath10k *ar = hw->priv;
7051 ath10k_dbg(ar, ATH10K_DBG_MAC,
7052 "mac chanctx remove freq %hu width %d ptr %p\n",
7053 ctx->def.chan->center_freq, ctx->def.width, ctx);
7055 mutex_lock(&ar->conf_mutex);
7057 spin_lock_bh(&ar->data_lock);
7058 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
7059 spin_unlock_bh(&ar->data_lock);
7061 ath10k_recalc_radar_detection(ar);
7062 ath10k_monitor_recalc(ar);
7064 mutex_unlock(&ar->conf_mutex);
7067 struct ath10k_mac_change_chanctx_arg {
7068 struct ieee80211_chanctx_conf *ctx;
7069 struct ieee80211_vif_chanctx_switch *vifs;
7075 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
7076 struct ieee80211_vif *vif)
7078 struct ath10k_mac_change_chanctx_arg *arg = data;
7080 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
7087 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
7088 struct ieee80211_vif *vif)
7090 struct ath10k_mac_change_chanctx_arg *arg = data;
7091 struct ieee80211_chanctx_conf *ctx;
7093 ctx = rcu_access_pointer(vif->chanctx_conf);
7094 if (ctx != arg->ctx)
7097 if (WARN_ON(arg->next_vif == arg->n_vifs))
7100 arg->vifs[arg->next_vif].vif = vif;
7101 arg->vifs[arg->next_vif].old_ctx = ctx;
7102 arg->vifs[arg->next_vif].new_ctx = ctx;
7107 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
7108 struct ieee80211_chanctx_conf *ctx,
7111 struct ath10k *ar = hw->priv;
7112 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
7114 mutex_lock(&ar->conf_mutex);
7116 ath10k_dbg(ar, ATH10K_DBG_MAC,
7117 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
7118 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
7120 /* This shouldn't really happen because channel switching should use
7121 * switch_vif_chanctx().
7123 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7126 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7127 ieee80211_iterate_active_interfaces_atomic(
7129 IEEE80211_IFACE_ITER_NORMAL,
7130 ath10k_mac_change_chanctx_cnt_iter,
7132 if (arg.n_vifs == 0)
7135 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7140 ieee80211_iterate_active_interfaces_atomic(
7142 IEEE80211_IFACE_ITER_NORMAL,
7143 ath10k_mac_change_chanctx_fill_iter,
7145 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7150 ath10k_recalc_radar_detection(ar);
7152 /* FIXME: How to configure Rx chains properly? */
7154 /* No other actions are actually necessary. Firmware maintains channel
7155 * definitions per vdev internally and there's no host-side channel
7156 * context abstraction to configure, e.g. channel width.
7160 mutex_unlock(&ar->conf_mutex);
7164 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7165 struct ieee80211_vif *vif,
7166 struct ieee80211_chanctx_conf *ctx)
7168 struct ath10k *ar = hw->priv;
7169 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7172 mutex_lock(&ar->conf_mutex);
7174 ath10k_dbg(ar, ATH10K_DBG_MAC,
7175 "mac chanctx assign ptr %p vdev_id %i\n",
7176 ctx, arvif->vdev_id);
7178 if (WARN_ON(arvif->is_started)) {
7179 mutex_unlock(&ar->conf_mutex);
7183 ret = ath10k_vdev_start(arvif, &ctx->def);
7185 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7186 arvif->vdev_id, vif->addr,
7187 ctx->def.chan->center_freq, ret);
7191 arvif->is_started = true;
7193 ret = ath10k_mac_vif_setup_ps(arvif);
7195 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7196 arvif->vdev_id, ret);
7200 if (vif->type == NL80211_IFTYPE_MONITOR) {
7201 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7203 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7204 arvif->vdev_id, ret);
7208 arvif->is_up = true;
7211 mutex_unlock(&ar->conf_mutex);
7215 ath10k_vdev_stop(arvif);
7216 arvif->is_started = false;
7217 ath10k_mac_vif_setup_ps(arvif);
7220 mutex_unlock(&ar->conf_mutex);
7225 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7226 struct ieee80211_vif *vif,
7227 struct ieee80211_chanctx_conf *ctx)
7229 struct ath10k *ar = hw->priv;
7230 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7233 mutex_lock(&ar->conf_mutex);
7235 ath10k_dbg(ar, ATH10K_DBG_MAC,
7236 "mac chanctx unassign ptr %p vdev_id %i\n",
7237 ctx, arvif->vdev_id);
7239 WARN_ON(!arvif->is_started);
7241 if (vif->type == NL80211_IFTYPE_MONITOR) {
7242 WARN_ON(!arvif->is_up);
7244 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7246 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7247 arvif->vdev_id, ret);
7249 arvif->is_up = false;
7252 ret = ath10k_vdev_stop(arvif);
7254 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7255 arvif->vdev_id, ret);
7257 arvif->is_started = false;
7259 mutex_unlock(&ar->conf_mutex);
7263 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7264 struct ieee80211_vif_chanctx_switch *vifs,
7266 enum ieee80211_chanctx_switch_mode mode)
7268 struct ath10k *ar = hw->priv;
7270 mutex_lock(&ar->conf_mutex);
7272 ath10k_dbg(ar, ATH10K_DBG_MAC,
7273 "mac chanctx switch n_vifs %d mode %d\n",
7275 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7277 mutex_unlock(&ar->conf_mutex);
7281 static const struct ieee80211_ops ath10k_ops = {
7282 .tx = ath10k_mac_op_tx,
7283 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7284 .start = ath10k_start,
7285 .stop = ath10k_stop,
7286 .config = ath10k_config,
7287 .add_interface = ath10k_add_interface,
7288 .remove_interface = ath10k_remove_interface,
7289 .configure_filter = ath10k_configure_filter,
7290 .bss_info_changed = ath10k_bss_info_changed,
7291 .hw_scan = ath10k_hw_scan,
7292 .cancel_hw_scan = ath10k_cancel_hw_scan,
7293 .set_key = ath10k_set_key,
7294 .set_default_unicast_key = ath10k_set_default_unicast_key,
7295 .sta_state = ath10k_sta_state,
7296 .conf_tx = ath10k_conf_tx,
7297 .remain_on_channel = ath10k_remain_on_channel,
7298 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7299 .set_rts_threshold = ath10k_set_rts_threshold,
7300 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7301 .flush = ath10k_flush,
7302 .tx_last_beacon = ath10k_tx_last_beacon,
7303 .set_antenna = ath10k_set_antenna,
7304 .get_antenna = ath10k_get_antenna,
7305 .reconfig_complete = ath10k_reconfig_complete,
7306 .get_survey = ath10k_get_survey,
7307 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7308 .sta_rc_update = ath10k_sta_rc_update,
7309 .get_tsf = ath10k_get_tsf,
7310 .set_tsf = ath10k_set_tsf,
7311 .ampdu_action = ath10k_ampdu_action,
7312 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7313 .get_et_stats = ath10k_debug_get_et_stats,
7314 .get_et_strings = ath10k_debug_get_et_strings,
7315 .add_chanctx = ath10k_mac_op_add_chanctx,
7316 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7317 .change_chanctx = ath10k_mac_op_change_chanctx,
7318 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7319 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7320 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7322 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7325 .suspend = ath10k_wow_op_suspend,
7326 .resume = ath10k_wow_op_resume,
7328 #ifdef CONFIG_MAC80211_DEBUGFS
7329 .sta_add_debugfs = ath10k_sta_add_debugfs,
7333 #define CHAN2G(_channel, _freq, _flags) { \
7334 .band = IEEE80211_BAND_2GHZ, \
7335 .hw_value = (_channel), \
7336 .center_freq = (_freq), \
7337 .flags = (_flags), \
7338 .max_antenna_gain = 0, \
7342 #define CHAN5G(_channel, _freq, _flags) { \
7343 .band = IEEE80211_BAND_5GHZ, \
7344 .hw_value = (_channel), \
7345 .center_freq = (_freq), \
7346 .flags = (_flags), \
7347 .max_antenna_gain = 0, \
7351 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7361 CHAN2G(10, 2457, 0),
7362 CHAN2G(11, 2462, 0),
7363 CHAN2G(12, 2467, 0),
7364 CHAN2G(13, 2472, 0),
7365 CHAN2G(14, 2484, 0),
7368 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7369 CHAN5G(36, 5180, 0),
7370 CHAN5G(40, 5200, 0),
7371 CHAN5G(44, 5220, 0),
7372 CHAN5G(48, 5240, 0),
7373 CHAN5G(52, 5260, 0),
7374 CHAN5G(56, 5280, 0),
7375 CHAN5G(60, 5300, 0),
7376 CHAN5G(64, 5320, 0),
7377 CHAN5G(100, 5500, 0),
7378 CHAN5G(104, 5520, 0),
7379 CHAN5G(108, 5540, 0),
7380 CHAN5G(112, 5560, 0),
7381 CHAN5G(116, 5580, 0),
7382 CHAN5G(120, 5600, 0),
7383 CHAN5G(124, 5620, 0),
7384 CHAN5G(128, 5640, 0),
7385 CHAN5G(132, 5660, 0),
7386 CHAN5G(136, 5680, 0),
7387 CHAN5G(140, 5700, 0),
7388 CHAN5G(144, 5720, 0),
7389 CHAN5G(149, 5745, 0),
7390 CHAN5G(153, 5765, 0),
7391 CHAN5G(157, 5785, 0),
7392 CHAN5G(161, 5805, 0),
7393 CHAN5G(165, 5825, 0),
7396 struct ath10k *ath10k_mac_create(size_t priv_size)
7398 struct ieee80211_hw *hw;
7401 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
7411 void ath10k_mac_destroy(struct ath10k *ar)
7413 ieee80211_free_hw(ar->hw);
7416 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7419 .types = BIT(NL80211_IFTYPE_STATION)
7420 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7424 .types = BIT(NL80211_IFTYPE_P2P_GO)
7428 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7432 .types = BIT(NL80211_IFTYPE_AP)
7433 #ifdef CONFIG_MAC80211_MESH
7434 | BIT(NL80211_IFTYPE_MESH_POINT)
7439 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7442 .types = BIT(NL80211_IFTYPE_AP)
7443 #ifdef CONFIG_MAC80211_MESH
7444 | BIT(NL80211_IFTYPE_MESH_POINT)
7449 .types = BIT(NL80211_IFTYPE_STATION)
7453 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7455 .limits = ath10k_if_limits,
7456 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7457 .max_interfaces = 8,
7458 .num_different_channels = 1,
7459 .beacon_int_infra_match = true,
7463 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7465 .limits = ath10k_10x_if_limits,
7466 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7467 .max_interfaces = 8,
7468 .num_different_channels = 1,
7469 .beacon_int_infra_match = true,
7470 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7471 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7472 BIT(NL80211_CHAN_WIDTH_20) |
7473 BIT(NL80211_CHAN_WIDTH_40) |
7474 BIT(NL80211_CHAN_WIDTH_80),
7479 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7482 .types = BIT(NL80211_IFTYPE_STATION),
7486 .types = BIT(NL80211_IFTYPE_AP) |
7487 #ifdef CONFIG_MAC80211_MESH
7488 BIT(NL80211_IFTYPE_MESH_POINT) |
7490 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7491 BIT(NL80211_IFTYPE_P2P_GO),
7495 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7499 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7502 .types = BIT(NL80211_IFTYPE_STATION),
7506 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7510 .types = BIT(NL80211_IFTYPE_AP) |
7511 #ifdef CONFIG_MAC80211_MESH
7512 BIT(NL80211_IFTYPE_MESH_POINT) |
7514 BIT(NL80211_IFTYPE_P2P_GO),
7518 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7522 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7525 .types = BIT(NL80211_IFTYPE_STATION),
7529 .types = BIT(NL80211_IFTYPE_ADHOC),
7533 /* FIXME: This is not thouroughly tested. These combinations may over- or
7534 * underestimate hw/fw capabilities.
7536 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7538 .limits = ath10k_tlv_if_limit,
7539 .num_different_channels = 1,
7540 .max_interfaces = 4,
7541 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7544 .limits = ath10k_tlv_if_limit_ibss,
7545 .num_different_channels = 1,
7546 .max_interfaces = 2,
7547 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7551 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7553 .limits = ath10k_tlv_if_limit,
7554 .num_different_channels = 1,
7555 .max_interfaces = 4,
7556 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7559 .limits = ath10k_tlv_qcs_if_limit,
7560 .num_different_channels = 2,
7561 .max_interfaces = 4,
7562 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7565 .limits = ath10k_tlv_if_limit_ibss,
7566 .num_different_channels = 1,
7567 .max_interfaces = 2,
7568 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7572 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7575 .types = BIT(NL80211_IFTYPE_STATION),
7579 .types = BIT(NL80211_IFTYPE_AP)
7580 #ifdef CONFIG_MAC80211_MESH
7581 | BIT(NL80211_IFTYPE_MESH_POINT)
7586 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7588 .limits = ath10k_10_4_if_limits,
7589 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7590 .max_interfaces = 16,
7591 .num_different_channels = 1,
7592 .beacon_int_infra_match = true,
7593 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7594 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7595 BIT(NL80211_CHAN_WIDTH_20) |
7596 BIT(NL80211_CHAN_WIDTH_40) |
7597 BIT(NL80211_CHAN_WIDTH_80),
7602 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7603 struct ieee80211_vif *vif)
7605 struct ath10k_vif_iter *arvif_iter = data;
7606 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7608 if (arvif->vdev_id == arvif_iter->vdev_id)
7609 arvif_iter->arvif = arvif;
7612 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7614 struct ath10k_vif_iter arvif_iter;
7617 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7618 arvif_iter.vdev_id = vdev_id;
7620 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7621 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7623 ath10k_get_arvif_iter,
7625 if (!arvif_iter.arvif) {
7626 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7630 return arvif_iter.arvif;
7633 int ath10k_mac_register(struct ath10k *ar)
7635 static const u32 cipher_suites[] = {
7636 WLAN_CIPHER_SUITE_WEP40,
7637 WLAN_CIPHER_SUITE_WEP104,
7638 WLAN_CIPHER_SUITE_TKIP,
7639 WLAN_CIPHER_SUITE_CCMP,
7640 WLAN_CIPHER_SUITE_AES_CMAC,
7642 struct ieee80211_supported_band *band;
7646 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
7648 SET_IEEE80211_DEV(ar->hw, ar->dev);
7650 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
7651 ARRAY_SIZE(ath10k_5ghz_channels)) !=
7654 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
7655 channels = kmemdup(ath10k_2ghz_channels,
7656 sizeof(ath10k_2ghz_channels),
7663 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
7664 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
7665 band->channels = channels;
7666 band->n_bitrates = ath10k_g_rates_size;
7667 band->bitrates = ath10k_g_rates;
7669 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
7672 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
7673 channels = kmemdup(ath10k_5ghz_channels,
7674 sizeof(ath10k_5ghz_channels),
7681 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
7682 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
7683 band->channels = channels;
7684 band->n_bitrates = ath10k_a_rates_size;
7685 band->bitrates = ath10k_a_rates;
7686 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
7689 ath10k_mac_setup_ht_vht_cap(ar);
7691 ar->hw->wiphy->interface_modes =
7692 BIT(NL80211_IFTYPE_STATION) |
7693 BIT(NL80211_IFTYPE_AP) |
7694 BIT(NL80211_IFTYPE_MESH_POINT);
7696 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
7697 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
7699 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->normal_mode_fw.fw_file.fw_features))
7700 ar->hw->wiphy->interface_modes |=
7701 BIT(NL80211_IFTYPE_P2P_DEVICE) |
7702 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7703 BIT(NL80211_IFTYPE_P2P_GO);
7705 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
7706 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
7707 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
7708 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
7709 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
7710 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
7711 ieee80211_hw_set(ar->hw, AP_LINK_PS);
7712 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
7713 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
7714 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7715 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7716 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7717 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7718 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
7720 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7721 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7723 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
7724 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
7726 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
7727 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
7729 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
7730 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7731 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
7734 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7735 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7737 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
7738 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
7739 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
7741 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7743 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7744 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7746 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7747 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7748 * correct Probe Responses. This is more of a hack advert..
7750 ar->hw->wiphy->probe_resp_offload |=
7751 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7752 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7753 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
7756 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
7757 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7759 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
7760 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
7761 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
7763 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
7764 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
7765 NL80211_FEATURE_AP_SCAN;
7767 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
7769 ret = ath10k_wow_init(ar);
7771 ath10k_warn(ar, "failed to init wow: %d\n", ret);
7775 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
7778 * on LL hardware queues are managed entirely by the FW
7779 * so we only advertise to mac we can do the queues thing
7781 ar->hw->queues = IEEE80211_MAX_QUEUES;
7783 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7784 * something that vdev_ids can't reach so that we don't stop the queue
7787 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
7789 switch (ar->wmi.op_version) {
7790 case ATH10K_FW_WMI_OP_VERSION_MAIN:
7791 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7792 ar->hw->wiphy->n_iface_combinations =
7793 ARRAY_SIZE(ath10k_if_comb);
7794 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7796 case ATH10K_FW_WMI_OP_VERSION_TLV:
7797 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7798 ar->hw->wiphy->iface_combinations =
7799 ath10k_tlv_qcs_if_comb;
7800 ar->hw->wiphy->n_iface_combinations =
7801 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7803 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7804 ar->hw->wiphy->n_iface_combinations =
7805 ARRAY_SIZE(ath10k_tlv_if_comb);
7807 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7809 case ATH10K_FW_WMI_OP_VERSION_10_1:
7810 case ATH10K_FW_WMI_OP_VERSION_10_2:
7811 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7812 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7813 ar->hw->wiphy->n_iface_combinations =
7814 ARRAY_SIZE(ath10k_10x_if_comb);
7816 case ATH10K_FW_WMI_OP_VERSION_10_4:
7817 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7818 ar->hw->wiphy->n_iface_combinations =
7819 ARRAY_SIZE(ath10k_10_4_if_comb);
7821 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7822 case ATH10K_FW_WMI_OP_VERSION_MAX:
7828 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7829 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7831 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7832 /* Init ath dfs pattern detector */
7833 ar->ath_common.debug_mask = ATH_DBG_DFS;
7834 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7837 if (!ar->dfs_detector)
7838 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
7841 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7842 ath10k_reg_notifier);
7844 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
7845 goto err_dfs_detector_exit;
7848 ar->hw->wiphy->cipher_suites = cipher_suites;
7849 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7851 ret = ieee80211_register_hw(ar->hw);
7853 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
7854 goto err_dfs_detector_exit;
7857 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7858 ret = regulatory_hint(ar->hw->wiphy,
7859 ar->ath_common.regulatory.alpha2);
7861 goto err_unregister;
7867 ieee80211_unregister_hw(ar->hw);
7869 err_dfs_detector_exit:
7870 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7871 ar->dfs_detector->exit(ar->dfs_detector);
7874 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7875 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7877 SET_IEEE80211_DEV(ar->hw, NULL);
7881 void ath10k_mac_unregister(struct ath10k *ar)
7883 ieee80211_unregister_hw(ar->hw);
7885 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7886 ar->dfs_detector->exit(ar->dfs_detector);
7888 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7889 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7891 SET_IEEE80211_DEV(ar->hw, NULL);