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 (rate->hw_value == hw_rate)
103 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
104 rate->hw_value_short == hw_rate)
111 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
116 for (i = 0; i < sband->n_bitrates; i++)
117 if (sband->bitrates[i].bitrate == bitrate)
123 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
125 switch ((mcs_map >> (2 * nss)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
134 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
138 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
139 if (ht_mcs_mask[nss])
146 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
150 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
151 if (vht_mcs_mask[nss])
161 static int ath10k_send_key(struct ath10k_vif *arvif,
162 struct ieee80211_key_conf *key,
163 enum set_key_cmd cmd,
164 const u8 *macaddr, u32 flags)
166 struct ath10k *ar = arvif->ar;
167 struct wmi_vdev_install_key_arg arg = {
168 .vdev_id = arvif->vdev_id,
169 .key_idx = key->keyidx,
170 .key_len = key->keylen,
171 .key_data = key->key,
176 lockdep_assert_held(&arvif->ar->conf_mutex);
178 switch (key->cipher) {
179 case WLAN_CIPHER_SUITE_CCMP:
180 arg.key_cipher = WMI_CIPHER_AES_CCM;
181 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
183 case WLAN_CIPHER_SUITE_TKIP:
184 arg.key_cipher = WMI_CIPHER_TKIP;
185 arg.key_txmic_len = 8;
186 arg.key_rxmic_len = 8;
188 case WLAN_CIPHER_SUITE_WEP40:
189 case WLAN_CIPHER_SUITE_WEP104:
190 arg.key_cipher = WMI_CIPHER_WEP;
192 case WLAN_CIPHER_SUITE_AES_CMAC:
196 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
200 if (cmd == DISABLE_KEY) {
201 arg.key_cipher = WMI_CIPHER_NONE;
205 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
208 static int ath10k_install_key(struct ath10k_vif *arvif,
209 struct ieee80211_key_conf *key,
210 enum set_key_cmd cmd,
211 const u8 *macaddr, u32 flags)
213 struct ath10k *ar = arvif->ar;
215 unsigned long time_left;
217 lockdep_assert_held(&ar->conf_mutex);
219 reinit_completion(&ar->install_key_done);
221 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
225 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
232 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
235 struct ath10k *ar = arvif->ar;
236 struct ath10k_peer *peer;
241 lockdep_assert_held(&ar->conf_mutex);
243 spin_lock_bh(&ar->data_lock);
244 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
245 spin_unlock_bh(&ar->data_lock);
250 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
251 if (arvif->wep_keys[i] == NULL)
255 flags |= WMI_KEY_PAIRWISE;
257 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
263 flags |= WMI_KEY_GROUP;
265 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
270 spin_lock_bh(&ar->data_lock);
271 peer->keys[i] = arvif->wep_keys[i];
272 spin_unlock_bh(&ar->data_lock);
275 /* In some cases (notably with static WEP IBSS with multiple keys)
276 * multicast Tx becomes broken. Both pairwise and groupwise keys are
277 * installed already. Using WMI_KEY_TX_USAGE in different combinations
278 * didn't seem help. Using def_keyid vdev parameter seems to be
279 * effective so use that.
281 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
283 if (arvif->def_wep_key_idx == -1)
286 ret = ath10k_wmi_vdev_set_param(arvif->ar,
288 arvif->ar->wmi.vdev_param->def_keyid,
289 arvif->def_wep_key_idx);
291 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
292 arvif->vdev_id, ret);
299 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
302 struct ath10k *ar = arvif->ar;
303 struct ath10k_peer *peer;
309 lockdep_assert_held(&ar->conf_mutex);
311 spin_lock_bh(&ar->data_lock);
312 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
313 spin_unlock_bh(&ar->data_lock);
318 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
319 if (peer->keys[i] == NULL)
322 /* key flags are not required to delete the key */
323 ret = ath10k_install_key(arvif, peer->keys[i],
324 DISABLE_KEY, addr, flags);
325 if (ret && first_errno == 0)
329 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
332 spin_lock_bh(&ar->data_lock);
333 peer->keys[i] = NULL;
334 spin_unlock_bh(&ar->data_lock);
340 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
343 struct ath10k_peer *peer;
346 lockdep_assert_held(&ar->data_lock);
348 /* We don't know which vdev this peer belongs to,
349 * since WMI doesn't give us that information.
351 * FIXME: multi-bss needs to be handled.
353 peer = ath10k_peer_find(ar, 0, addr);
357 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
358 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
365 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
366 struct ieee80211_key_conf *key)
368 struct ath10k *ar = arvif->ar;
369 struct ath10k_peer *peer;
376 lockdep_assert_held(&ar->conf_mutex);
379 /* since ath10k_install_key we can't hold data_lock all the
380 * time, so we try to remove the keys incrementally */
381 spin_lock_bh(&ar->data_lock);
383 list_for_each_entry(peer, &ar->peers, list) {
384 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
385 if (peer->keys[i] == key) {
386 ether_addr_copy(addr, peer->addr);
387 peer->keys[i] = NULL;
392 if (i < ARRAY_SIZE(peer->keys))
395 spin_unlock_bh(&ar->data_lock);
397 if (i == ARRAY_SIZE(peer->keys))
399 /* key flags are not required to delete the key */
400 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
401 if (ret && first_errno == 0)
405 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
412 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
413 struct ieee80211_key_conf *key)
415 struct ath10k *ar = arvif->ar;
416 struct ath10k_peer *peer;
419 lockdep_assert_held(&ar->conf_mutex);
421 list_for_each_entry(peer, &ar->peers, list) {
422 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
425 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
428 if (peer->keys[key->keyidx] == key)
431 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
432 arvif->vdev_id, key->keyidx);
434 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
436 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
437 arvif->vdev_id, peer->addr, ret);
445 /*********************/
446 /* General utilities */
447 /*********************/
449 static inline enum wmi_phy_mode
450 chan_to_phymode(const struct cfg80211_chan_def *chandef)
452 enum wmi_phy_mode phymode = MODE_UNKNOWN;
454 switch (chandef->chan->band) {
455 case IEEE80211_BAND_2GHZ:
456 switch (chandef->width) {
457 case NL80211_CHAN_WIDTH_20_NOHT:
458 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
463 case NL80211_CHAN_WIDTH_20:
464 phymode = MODE_11NG_HT20;
466 case NL80211_CHAN_WIDTH_40:
467 phymode = MODE_11NG_HT40;
469 case NL80211_CHAN_WIDTH_5:
470 case NL80211_CHAN_WIDTH_10:
471 case NL80211_CHAN_WIDTH_80:
472 case NL80211_CHAN_WIDTH_80P80:
473 case NL80211_CHAN_WIDTH_160:
474 phymode = MODE_UNKNOWN;
478 case IEEE80211_BAND_5GHZ:
479 switch (chandef->width) {
480 case NL80211_CHAN_WIDTH_20_NOHT:
483 case NL80211_CHAN_WIDTH_20:
484 phymode = MODE_11NA_HT20;
486 case NL80211_CHAN_WIDTH_40:
487 phymode = MODE_11NA_HT40;
489 case NL80211_CHAN_WIDTH_80:
490 phymode = MODE_11AC_VHT80;
492 case NL80211_CHAN_WIDTH_5:
493 case NL80211_CHAN_WIDTH_10:
494 case NL80211_CHAN_WIDTH_80P80:
495 case NL80211_CHAN_WIDTH_160:
496 phymode = MODE_UNKNOWN;
504 WARN_ON(phymode == MODE_UNKNOWN);
508 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
511 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
512 * 0 for no restriction
521 switch (mpdudensity) {
527 /* Our lower layer calculations limit our precision to
543 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
544 struct cfg80211_chan_def *def)
546 struct ieee80211_chanctx_conf *conf;
549 conf = rcu_dereference(vif->chanctx_conf);
561 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
562 struct ieee80211_chanctx_conf *conf,
570 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
574 ieee80211_iter_chan_contexts_atomic(ar->hw,
575 ath10k_mac_num_chanctxs_iter,
582 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
583 struct ieee80211_chanctx_conf *conf,
586 struct cfg80211_chan_def **def = data;
591 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
592 enum wmi_peer_type peer_type)
596 lockdep_assert_held(&ar->conf_mutex);
598 if (ar->num_peers >= ar->max_num_peers)
601 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
603 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
608 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
610 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
620 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
622 struct ath10k *ar = arvif->ar;
626 param = ar->wmi.pdev_param->sta_kickout_th;
627 ret = ath10k_wmi_pdev_set_param(ar, param,
628 ATH10K_KICKOUT_THRESHOLD);
630 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
631 arvif->vdev_id, ret);
635 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
636 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
637 ATH10K_KEEPALIVE_MIN_IDLE);
639 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
640 arvif->vdev_id, ret);
644 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
645 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
646 ATH10K_KEEPALIVE_MAX_IDLE);
648 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
649 arvif->vdev_id, ret);
653 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
654 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
655 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
657 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
658 arvif->vdev_id, ret);
665 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
667 struct ath10k *ar = arvif->ar;
670 vdev_param = ar->wmi.vdev_param->rts_threshold;
671 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
674 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
676 struct ath10k *ar = arvif->ar;
679 if (value != 0xFFFFFFFF)
680 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
681 ATH10K_FRAGMT_THRESHOLD_MIN,
682 ATH10K_FRAGMT_THRESHOLD_MAX);
684 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
685 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
688 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
692 lockdep_assert_held(&ar->conf_mutex);
694 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
698 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
707 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
709 struct ath10k_peer *peer, *tmp;
711 lockdep_assert_held(&ar->conf_mutex);
713 spin_lock_bh(&ar->data_lock);
714 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
715 if (peer->vdev_id != vdev_id)
718 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
719 peer->addr, vdev_id);
721 list_del(&peer->list);
725 spin_unlock_bh(&ar->data_lock);
728 static void ath10k_peer_cleanup_all(struct ath10k *ar)
730 struct ath10k_peer *peer, *tmp;
732 lockdep_assert_held(&ar->conf_mutex);
734 spin_lock_bh(&ar->data_lock);
735 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
736 list_del(&peer->list);
739 spin_unlock_bh(&ar->data_lock);
742 ar->num_stations = 0;
745 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
746 struct ieee80211_sta *sta,
747 enum wmi_tdls_peer_state state)
750 struct wmi_tdls_peer_update_cmd_arg arg = {};
751 struct wmi_tdls_peer_capab_arg cap = {};
752 struct wmi_channel_arg chan_arg = {};
754 lockdep_assert_held(&ar->conf_mutex);
756 arg.vdev_id = vdev_id;
757 arg.peer_state = state;
758 ether_addr_copy(arg.addr, sta->addr);
760 cap.peer_max_sp = sta->max_sp;
761 cap.peer_uapsd_queues = sta->uapsd_queues;
763 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
764 !sta->tdls_initiator)
765 cap.is_peer_responder = 1;
767 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
769 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
770 arg.addr, vdev_id, ret);
777 /************************/
778 /* Interface management */
779 /************************/
781 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
783 struct ath10k *ar = arvif->ar;
785 lockdep_assert_held(&ar->data_lock);
790 if (!arvif->beacon_buf)
791 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
792 arvif->beacon->len, DMA_TO_DEVICE);
794 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
795 arvif->beacon_state != ATH10K_BEACON_SENT))
798 dev_kfree_skb_any(arvif->beacon);
800 arvif->beacon = NULL;
801 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
804 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
806 struct ath10k *ar = arvif->ar;
808 lockdep_assert_held(&ar->data_lock);
810 ath10k_mac_vif_beacon_free(arvif);
812 if (arvif->beacon_buf) {
813 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
814 arvif->beacon_buf, arvif->beacon_paddr);
815 arvif->beacon_buf = NULL;
819 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
821 unsigned long time_left;
823 lockdep_assert_held(&ar->conf_mutex);
825 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
828 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
829 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
836 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
838 struct cfg80211_chan_def *chandef = NULL;
839 struct ieee80211_channel *channel = chandef->chan;
840 struct wmi_vdev_start_request_arg arg = {};
843 lockdep_assert_held(&ar->conf_mutex);
845 ieee80211_iter_chan_contexts_atomic(ar->hw,
846 ath10k_mac_get_any_chandef_iter,
848 if (WARN_ON_ONCE(!chandef))
851 channel = chandef->chan;
853 arg.vdev_id = vdev_id;
854 arg.channel.freq = channel->center_freq;
855 arg.channel.band_center_freq1 = chandef->center_freq1;
857 /* TODO setup this dynamically, what in case we
858 don't have any vifs? */
859 arg.channel.mode = chan_to_phymode(chandef);
860 arg.channel.chan_radar =
861 !!(channel->flags & IEEE80211_CHAN_RADAR);
863 arg.channel.min_power = 0;
864 arg.channel.max_power = channel->max_power * 2;
865 arg.channel.max_reg_power = channel->max_reg_power * 2;
866 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
868 reinit_completion(&ar->vdev_setup_done);
870 ret = ath10k_wmi_vdev_start(ar, &arg);
872 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
877 ret = ath10k_vdev_setup_sync(ar);
879 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
884 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
886 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
891 ar->monitor_vdev_id = vdev_id;
893 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
894 ar->monitor_vdev_id);
898 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
900 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
901 ar->monitor_vdev_id, ret);
906 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
910 lockdep_assert_held(&ar->conf_mutex);
912 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
914 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
915 ar->monitor_vdev_id, ret);
917 reinit_completion(&ar->vdev_setup_done);
919 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
921 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
922 ar->monitor_vdev_id, ret);
924 ret = ath10k_vdev_setup_sync(ar);
926 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
927 ar->monitor_vdev_id, ret);
929 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
930 ar->monitor_vdev_id);
934 static int ath10k_monitor_vdev_create(struct ath10k *ar)
938 lockdep_assert_held(&ar->conf_mutex);
940 if (ar->free_vdev_map == 0) {
941 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
945 bit = __ffs64(ar->free_vdev_map);
947 ar->monitor_vdev_id = bit;
949 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
950 WMI_VDEV_TYPE_MONITOR,
953 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
954 ar->monitor_vdev_id, ret);
958 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
959 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
960 ar->monitor_vdev_id);
965 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
969 lockdep_assert_held(&ar->conf_mutex);
971 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
973 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
974 ar->monitor_vdev_id, ret);
978 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
980 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
981 ar->monitor_vdev_id);
985 static int ath10k_monitor_start(struct ath10k *ar)
989 lockdep_assert_held(&ar->conf_mutex);
991 ret = ath10k_monitor_vdev_create(ar);
993 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
997 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
999 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1000 ath10k_monitor_vdev_delete(ar);
1004 ar->monitor_started = true;
1005 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1010 static int ath10k_monitor_stop(struct ath10k *ar)
1014 lockdep_assert_held(&ar->conf_mutex);
1016 ret = ath10k_monitor_vdev_stop(ar);
1018 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1022 ret = ath10k_monitor_vdev_delete(ar);
1024 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1028 ar->monitor_started = false;
1029 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1034 static bool ath10k_mac_should_disable_promisc(struct ath10k *ar)
1036 struct ath10k_vif *arvif;
1038 if (!(ar->filter_flags & FIF_PROMISC_IN_BSS))
1041 if (!ar->num_started_vdevs)
1044 list_for_each_entry(arvif, &ar->arvifs, list)
1045 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1048 ath10k_dbg(ar, ATH10K_DBG_MAC,
1049 "mac disabling promiscuous mode because vdev is started\n");
1053 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1057 /* At least one chanctx is required to derive a channel to start
1060 num_ctx = ath10k_mac_num_chanctxs(ar);
1064 /* If there's already an existing special monitor interface then don't
1065 * bother creating another monitor vdev.
1067 if (ar->monitor_arvif)
1070 return ar->monitor ||
1071 !ath10k_mac_should_disable_promisc(ar) ||
1072 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1075 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1079 num_ctx = ath10k_mac_num_chanctxs(ar);
1081 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1082 * shouldn't allow this but make sure to prevent handling the following
1083 * case anyway since multi-channel DFS hasn't been tested at all.
1085 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1091 static int ath10k_monitor_recalc(struct ath10k *ar)
1097 lockdep_assert_held(&ar->conf_mutex);
1099 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1100 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1102 ath10k_dbg(ar, ATH10K_DBG_MAC,
1103 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1104 ar->monitor_started, needed, allowed);
1106 if (WARN_ON(needed && !allowed)) {
1107 if (ar->monitor_started) {
1108 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1110 ret = ath10k_monitor_stop(ar);
1112 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1119 if (needed == ar->monitor_started)
1123 return ath10k_monitor_start(ar);
1125 return ath10k_monitor_stop(ar);
1128 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1130 struct ath10k *ar = arvif->ar;
1131 u32 vdev_param, rts_cts = 0;
1133 lockdep_assert_held(&ar->conf_mutex);
1135 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1137 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1139 if (arvif->num_legacy_stations > 0)
1140 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1141 WMI_RTSCTS_PROFILE);
1143 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1144 WMI_RTSCTS_PROFILE);
1146 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1150 static int ath10k_start_cac(struct ath10k *ar)
1154 lockdep_assert_held(&ar->conf_mutex);
1156 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1158 ret = ath10k_monitor_recalc(ar);
1160 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1161 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1165 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1166 ar->monitor_vdev_id);
1171 static int ath10k_stop_cac(struct ath10k *ar)
1173 lockdep_assert_held(&ar->conf_mutex);
1175 /* CAC is not running - do nothing */
1176 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1179 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1180 ath10k_monitor_stop(ar);
1182 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1187 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1188 struct ieee80211_chanctx_conf *conf,
1193 if (!*ret && conf->radar_enabled)
1197 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1199 bool has_radar = false;
1201 ieee80211_iter_chan_contexts_atomic(ar->hw,
1202 ath10k_mac_has_radar_iter,
1208 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1212 lockdep_assert_held(&ar->conf_mutex);
1214 ath10k_stop_cac(ar);
1216 if (!ath10k_mac_has_radar_enabled(ar))
1219 if (ar->num_started_vdevs > 0)
1222 ret = ath10k_start_cac(ar);
1225 * Not possible to start CAC on current channel so starting
1226 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1227 * by indicating that radar was detected.
1229 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1230 ieee80211_radar_detected(ar->hw);
1234 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1236 struct ath10k *ar = arvif->ar;
1239 lockdep_assert_held(&ar->conf_mutex);
1241 reinit_completion(&ar->vdev_setup_done);
1243 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1245 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1246 arvif->vdev_id, ret);
1250 ret = ath10k_vdev_setup_sync(ar);
1252 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1253 arvif->vdev_id, ret);
1257 WARN_ON(ar->num_started_vdevs == 0);
1259 if (ar->num_started_vdevs != 0) {
1260 ar->num_started_vdevs--;
1261 ath10k_recalc_radar_detection(ar);
1267 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1268 const struct cfg80211_chan_def *chandef,
1271 struct ath10k *ar = arvif->ar;
1272 struct wmi_vdev_start_request_arg arg = {};
1275 lockdep_assert_held(&ar->conf_mutex);
1277 reinit_completion(&ar->vdev_setup_done);
1279 arg.vdev_id = arvif->vdev_id;
1280 arg.dtim_period = arvif->dtim_period;
1281 arg.bcn_intval = arvif->beacon_interval;
1283 arg.channel.freq = chandef->chan->center_freq;
1284 arg.channel.band_center_freq1 = chandef->center_freq1;
1285 arg.channel.mode = chan_to_phymode(chandef);
1287 arg.channel.min_power = 0;
1288 arg.channel.max_power = chandef->chan->max_power * 2;
1289 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1290 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1292 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1293 arg.ssid = arvif->u.ap.ssid;
1294 arg.ssid_len = arvif->u.ap.ssid_len;
1295 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1297 /* For now allow DFS for AP mode */
1298 arg.channel.chan_radar =
1299 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1300 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1301 arg.ssid = arvif->vif->bss_conf.ssid;
1302 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1305 ath10k_dbg(ar, ATH10K_DBG_MAC,
1306 "mac vdev %d start center_freq %d phymode %s\n",
1307 arg.vdev_id, arg.channel.freq,
1308 ath10k_wmi_phymode_str(arg.channel.mode));
1311 ret = ath10k_wmi_vdev_restart(ar, &arg);
1313 ret = ath10k_wmi_vdev_start(ar, &arg);
1316 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1321 ret = ath10k_vdev_setup_sync(ar);
1324 "failed to synchronize setup for vdev %i restart %d: %d\n",
1325 arg.vdev_id, restart, ret);
1329 ar->num_started_vdevs++;
1330 ath10k_recalc_radar_detection(ar);
1332 ret = ath10k_monitor_recalc(ar);
1334 ath10k_warn(ar, "mac failed to recalc monitor for vdev %i restart %d: %d\n",
1335 arg.vdev_id, restart, ret);
1336 ret2 = ath10k_vdev_stop(arvif);
1338 ath10k_warn(ar, "mac failed to stop vdev %i restart %d: %d\n",
1339 arg.vdev_id, restart, ret2);
1345 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1346 const struct cfg80211_chan_def *def)
1348 return ath10k_vdev_start_restart(arvif, def, false);
1351 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1352 const struct cfg80211_chan_def *def)
1354 return ath10k_vdev_start_restart(arvif, def, true);
1357 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1358 struct sk_buff *bcn)
1360 struct ath10k *ar = arvif->ar;
1361 struct ieee80211_mgmt *mgmt;
1365 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1368 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1371 mgmt = (void *)bcn->data;
1372 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1373 mgmt->u.beacon.variable,
1374 bcn->len - (mgmt->u.beacon.variable -
1379 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1381 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1382 arvif->vdev_id, ret);
1389 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1390 u8 oui_type, size_t ie_offset)
1397 if (WARN_ON(skb->len < ie_offset))
1400 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1401 skb->data + ie_offset,
1402 skb->len - ie_offset);
1407 end = skb->data + skb->len;
1410 if (WARN_ON(next > end))
1413 memmove(ie, next, end - next);
1414 skb_trim(skb, skb->len - len);
1419 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1421 struct ath10k *ar = arvif->ar;
1422 struct ieee80211_hw *hw = ar->hw;
1423 struct ieee80211_vif *vif = arvif->vif;
1424 struct ieee80211_mutable_offsets offs = {};
1425 struct sk_buff *bcn;
1428 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1431 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1432 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1435 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1437 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1441 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1443 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1448 /* P2P IE is inserted by firmware automatically (as configured above)
1449 * so remove it from the base beacon template to avoid duplicate P2P
1450 * IEs in beacon frames.
1452 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1453 offsetof(struct ieee80211_mgmt,
1454 u.beacon.variable));
1456 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1461 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1469 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1471 struct ath10k *ar = arvif->ar;
1472 struct ieee80211_hw *hw = ar->hw;
1473 struct ieee80211_vif *vif = arvif->vif;
1474 struct sk_buff *prb;
1477 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1480 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1483 prb = ieee80211_proberesp_get(hw, vif);
1485 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1489 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1493 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1501 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1503 struct ath10k *ar = arvif->ar;
1504 struct cfg80211_chan_def def;
1507 /* When originally vdev is started during assign_vif_chanctx() some
1508 * information is missing, notably SSID. Firmware revisions with beacon
1509 * offloading require the SSID to be provided during vdev (re)start to
1510 * handle hidden SSID properly.
1512 * Vdev restart must be done after vdev has been both started and
1513 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1514 * deliver vdev restart response event causing timeouts during vdev
1515 * syncing in ath10k.
1517 * Note: The vdev down/up and template reinstallation could be skipped
1518 * since only wmi-tlv firmware are known to have beacon offload and
1519 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1520 * response delivery. It's probably more robust to keep it as is.
1522 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1525 if (WARN_ON(!arvif->is_started))
1528 if (WARN_ON(!arvif->is_up))
1531 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1534 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1536 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1537 arvif->vdev_id, ret);
1541 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1542 * firmware will crash upon vdev up.
1545 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1547 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1551 ret = ath10k_mac_setup_prb_tmpl(arvif);
1553 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1557 ret = ath10k_vdev_restart(arvif, &def);
1559 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1560 arvif->vdev_id, ret);
1564 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1567 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1568 arvif->vdev_id, ret);
1575 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1576 struct ieee80211_bss_conf *info)
1578 struct ath10k *ar = arvif->ar;
1581 lockdep_assert_held(&arvif->ar->conf_mutex);
1583 if (!info->enable_beacon) {
1584 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1586 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1587 arvif->vdev_id, ret);
1589 arvif->is_up = false;
1591 spin_lock_bh(&arvif->ar->data_lock);
1592 ath10k_mac_vif_beacon_free(arvif);
1593 spin_unlock_bh(&arvif->ar->data_lock);
1598 arvif->tx_seq_no = 0x1000;
1601 ether_addr_copy(arvif->bssid, info->bssid);
1603 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1606 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1607 arvif->vdev_id, ret);
1611 arvif->is_up = true;
1613 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1615 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1616 arvif->vdev_id, ret);
1620 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1623 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1624 struct ieee80211_bss_conf *info,
1625 const u8 self_peer[ETH_ALEN])
1627 struct ath10k *ar = arvif->ar;
1631 lockdep_assert_held(&arvif->ar->conf_mutex);
1633 if (!info->ibss_joined) {
1634 if (is_zero_ether_addr(arvif->bssid))
1637 eth_zero_addr(arvif->bssid);
1642 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1643 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1644 ATH10K_DEFAULT_ATIM);
1646 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1647 arvif->vdev_id, ret);
1650 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1652 struct ath10k *ar = arvif->ar;
1657 lockdep_assert_held(&arvif->ar->conf_mutex);
1659 if (arvif->u.sta.uapsd)
1660 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1662 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1664 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1665 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1667 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1668 value, arvif->vdev_id, ret);
1675 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1677 struct ath10k *ar = arvif->ar;
1682 lockdep_assert_held(&arvif->ar->conf_mutex);
1684 if (arvif->u.sta.uapsd)
1685 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1687 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1689 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1690 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1693 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1694 value, arvif->vdev_id, ret);
1701 static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1703 struct ath10k_vif *arvif;
1706 lockdep_assert_held(&ar->conf_mutex);
1708 list_for_each_entry(arvif, &ar->arvifs, list)
1715 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1717 struct ath10k *ar = arvif->ar;
1718 struct ieee80211_vif *vif = arvif->vif;
1719 struct ieee80211_conf *conf = &ar->hw->conf;
1720 enum wmi_sta_powersave_param param;
1721 enum wmi_sta_ps_mode psmode;
1726 lockdep_assert_held(&arvif->ar->conf_mutex);
1728 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1731 enable_ps = arvif->ps;
1733 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1734 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1736 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1742 psmode = WMI_STA_PS_MODE_ENABLED;
1743 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1745 ps_timeout = conf->dynamic_ps_timeout;
1746 if (ps_timeout == 0) {
1747 /* Firmware doesn't like 0 */
1748 ps_timeout = ieee80211_tu_to_usec(
1749 vif->bss_conf.beacon_int) / 1000;
1752 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1755 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1756 arvif->vdev_id, ret);
1760 psmode = WMI_STA_PS_MODE_DISABLED;
1763 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1764 arvif->vdev_id, psmode ? "enable" : "disable");
1766 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1768 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1769 psmode, arvif->vdev_id, ret);
1776 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1778 struct ath10k *ar = arvif->ar;
1779 struct wmi_sta_keepalive_arg arg = {};
1782 lockdep_assert_held(&arvif->ar->conf_mutex);
1784 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1787 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1790 /* Some firmware revisions have a bug and ignore the `enabled` field.
1791 * Instead use the interval to disable the keepalive.
1793 arg.vdev_id = arvif->vdev_id;
1795 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1796 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1798 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1800 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1801 arvif->vdev_id, ret);
1808 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1810 struct ath10k *ar = arvif->ar;
1811 struct ieee80211_vif *vif = arvif->vif;
1814 lockdep_assert_held(&arvif->ar->conf_mutex);
1816 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1819 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1822 if (!vif->csa_active)
1828 if (!ieee80211_csa_is_complete(vif)) {
1829 ieee80211_csa_update_counter(vif);
1831 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1833 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1836 ret = ath10k_mac_setup_prb_tmpl(arvif);
1838 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1841 ieee80211_csa_finish(vif);
1845 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1847 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1849 struct ath10k *ar = arvif->ar;
1851 mutex_lock(&ar->conf_mutex);
1852 ath10k_mac_vif_ap_csa_count_down(arvif);
1853 mutex_unlock(&ar->conf_mutex);
1856 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1857 struct ieee80211_vif *vif)
1859 struct sk_buff *skb = data;
1860 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1861 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1863 if (vif->type != NL80211_IFTYPE_STATION)
1866 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1869 cancel_delayed_work(&arvif->connection_loss_work);
1872 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1874 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1875 IEEE80211_IFACE_ITER_NORMAL,
1876 ath10k_mac_handle_beacon_iter,
1880 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1881 struct ieee80211_vif *vif)
1883 u32 *vdev_id = data;
1884 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1885 struct ath10k *ar = arvif->ar;
1886 struct ieee80211_hw *hw = ar->hw;
1888 if (arvif->vdev_id != *vdev_id)
1894 ieee80211_beacon_loss(vif);
1896 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1897 * (done by mac80211) succeeds but beacons do not resume then it
1898 * doesn't make sense to continue operation. Queue connection loss work
1899 * which can be cancelled when beacon is received.
1901 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1902 ATH10K_CONNECTION_LOSS_HZ);
1905 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1907 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1908 IEEE80211_IFACE_ITER_NORMAL,
1909 ath10k_mac_handle_beacon_miss_iter,
1913 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1915 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1916 connection_loss_work.work);
1917 struct ieee80211_vif *vif = arvif->vif;
1922 ieee80211_connection_loss(vif);
1925 /**********************/
1926 /* Station management */
1927 /**********************/
1929 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1930 struct ieee80211_vif *vif)
1932 /* Some firmware revisions have unstable STA powersave when listen
1933 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1934 * generate NullFunc frames properly even if buffered frames have been
1935 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1936 * buffered frames. Often pinging the device from AP would simply fail.
1938 * As a workaround set it to 1.
1940 if (vif->type == NL80211_IFTYPE_STATION)
1943 return ar->hw->conf.listen_interval;
1946 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1947 struct ieee80211_vif *vif,
1948 struct ieee80211_sta *sta,
1949 struct wmi_peer_assoc_complete_arg *arg)
1951 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1954 lockdep_assert_held(&ar->conf_mutex);
1956 if (vif->type == NL80211_IFTYPE_STATION)
1957 aid = vif->bss_conf.aid;
1961 ether_addr_copy(arg->addr, sta->addr);
1962 arg->vdev_id = arvif->vdev_id;
1963 arg->peer_aid = aid;
1964 arg->peer_flags |= WMI_PEER_AUTH;
1965 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1966 arg->peer_num_spatial_streams = 1;
1967 arg->peer_caps = vif->bss_conf.assoc_capability;
1970 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1971 struct ieee80211_vif *vif,
1972 struct wmi_peer_assoc_complete_arg *arg)
1974 struct ieee80211_bss_conf *info = &vif->bss_conf;
1975 struct cfg80211_chan_def def;
1976 struct cfg80211_bss *bss;
1977 const u8 *rsnie = NULL;
1978 const u8 *wpaie = NULL;
1980 lockdep_assert_held(&ar->conf_mutex);
1982 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1985 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1986 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
1988 const struct cfg80211_bss_ies *ies;
1991 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1993 ies = rcu_dereference(bss->ies);
1995 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1996 WLAN_OUI_TYPE_MICROSOFT_WPA,
2000 cfg80211_put_bss(ar->hw->wiphy, bss);
2003 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2004 if (rsnie || wpaie) {
2005 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2006 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
2010 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2011 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2015 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2016 struct ieee80211_vif *vif,
2017 struct ieee80211_sta *sta,
2018 struct wmi_peer_assoc_complete_arg *arg)
2020 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2021 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2022 struct cfg80211_chan_def def;
2023 const struct ieee80211_supported_band *sband;
2024 const struct ieee80211_rate *rates;
2025 enum ieee80211_band band;
2030 lockdep_assert_held(&ar->conf_mutex);
2032 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2035 band = def.chan->band;
2036 sband = ar->hw->wiphy->bands[band];
2037 ratemask = sta->supp_rates[band];
2038 ratemask &= arvif->bitrate_mask.control[band].legacy;
2039 rates = sband->bitrates;
2041 rateset->num_rates = 0;
2043 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2044 if (!(ratemask & 1))
2047 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2048 rateset->rates[rateset->num_rates] = rate;
2049 rateset->num_rates++;
2054 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2058 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2059 if (ht_mcs_mask[nss])
2066 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2070 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2071 if (vht_mcs_mask[nss])
2077 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2078 struct ieee80211_vif *vif,
2079 struct ieee80211_sta *sta,
2080 struct wmi_peer_assoc_complete_arg *arg)
2082 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2083 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2084 struct cfg80211_chan_def def;
2085 enum ieee80211_band band;
2086 const u8 *ht_mcs_mask;
2087 const u16 *vht_mcs_mask;
2091 lockdep_assert_held(&ar->conf_mutex);
2093 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2096 if (!ht_cap->ht_supported)
2099 band = def.chan->band;
2100 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2101 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2103 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2104 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2107 arg->peer_flags |= WMI_PEER_HT;
2108 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2109 ht_cap->ampdu_factor)) - 1;
2111 arg->peer_mpdu_density =
2112 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2114 arg->peer_ht_caps = ht_cap->cap;
2115 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2117 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2118 arg->peer_flags |= WMI_PEER_LDPC;
2120 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2121 arg->peer_flags |= WMI_PEER_40MHZ;
2122 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2125 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2126 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2127 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2129 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2130 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2133 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2134 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2135 arg->peer_flags |= WMI_PEER_STBC;
2138 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2139 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2140 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2141 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2142 arg->peer_rate_caps |= stbc;
2143 arg->peer_flags |= WMI_PEER_STBC;
2146 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2147 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2148 else if (ht_cap->mcs.rx_mask[1])
2149 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2151 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2152 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2153 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2154 max_nss = (i / 8) + 1;
2155 arg->peer_ht_rates.rates[n++] = i;
2159 * This is a workaround for HT-enabled STAs which break the spec
2160 * and have no HT capabilities RX mask (no HT RX MCS map).
2162 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2163 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2165 * Firmware asserts if such situation occurs.
2168 arg->peer_ht_rates.num_rates = 8;
2169 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2170 arg->peer_ht_rates.rates[i] = i;
2172 arg->peer_ht_rates.num_rates = n;
2173 arg->peer_num_spatial_streams = max_nss;
2176 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2178 arg->peer_ht_rates.num_rates,
2179 arg->peer_num_spatial_streams);
2182 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2183 struct ath10k_vif *arvif,
2184 struct ieee80211_sta *sta)
2190 lockdep_assert_held(&ar->conf_mutex);
2192 if (sta->wme && sta->uapsd_queues) {
2193 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2194 sta->uapsd_queues, sta->max_sp);
2196 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2197 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2198 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2199 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2200 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2201 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2202 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2203 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2204 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2205 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2206 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2207 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2209 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2210 max_sp = sta->max_sp;
2212 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2214 WMI_AP_PS_PEER_PARAM_UAPSD,
2217 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2218 arvif->vdev_id, ret);
2222 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2224 WMI_AP_PS_PEER_PARAM_MAX_SP,
2227 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2228 arvif->vdev_id, ret);
2232 /* TODO setup this based on STA listen interval and
2233 beacon interval. Currently we don't know
2234 sta->listen_interval - mac80211 patch required.
2235 Currently use 10 seconds */
2236 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2237 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2240 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2241 arvif->vdev_id, ret);
2250 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2251 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2258 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2259 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2263 idx_limit = fls(mcs_map) - 1;
2267 switch (idx_limit) {
2268 case 0: /* fall through */
2269 case 1: /* fall through */
2270 case 2: /* fall through */
2271 case 3: /* fall through */
2272 case 4: /* fall through */
2273 case 5: /* fall through */
2274 case 6: /* fall through */
2276 /* see ath10k_mac_can_set_bitrate_mask() */
2280 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2283 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2286 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2289 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2293 tx_mcs_set &= ~(0x3 << (nss * 2));
2294 tx_mcs_set |= mcs << (nss * 2);
2300 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2301 struct ieee80211_vif *vif,
2302 struct ieee80211_sta *sta,
2303 struct wmi_peer_assoc_complete_arg *arg)
2305 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2306 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2307 struct cfg80211_chan_def def;
2308 enum ieee80211_band band;
2309 const u16 *vht_mcs_mask;
2312 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2315 if (!vht_cap->vht_supported)
2318 band = def.chan->band;
2319 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2321 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2324 arg->peer_flags |= WMI_PEER_VHT;
2326 if (def.chan->band == IEEE80211_BAND_2GHZ)
2327 arg->peer_flags |= WMI_PEER_VHT_2G;
2329 arg->peer_vht_caps = vht_cap->cap;
2331 ampdu_factor = (vht_cap->cap &
2332 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2333 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2335 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2336 * zero in VHT IE. Using it would result in degraded throughput.
2337 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2338 * it if VHT max_mpdu is smaller. */
2339 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2340 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2341 ampdu_factor)) - 1);
2343 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2344 arg->peer_flags |= WMI_PEER_80MHZ;
2346 arg->peer_vht_rates.rx_max_rate =
2347 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2348 arg->peer_vht_rates.rx_mcs_set =
2349 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2350 arg->peer_vht_rates.tx_max_rate =
2351 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2352 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2353 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2355 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2356 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2359 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2360 struct ieee80211_vif *vif,
2361 struct ieee80211_sta *sta,
2362 struct wmi_peer_assoc_complete_arg *arg)
2364 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2366 switch (arvif->vdev_type) {
2367 case WMI_VDEV_TYPE_AP:
2369 arg->peer_flags |= WMI_PEER_QOS;
2371 if (sta->wme && sta->uapsd_queues) {
2372 arg->peer_flags |= WMI_PEER_APSD;
2373 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2376 case WMI_VDEV_TYPE_STA:
2377 if (vif->bss_conf.qos)
2378 arg->peer_flags |= WMI_PEER_QOS;
2380 case WMI_VDEV_TYPE_IBSS:
2382 arg->peer_flags |= WMI_PEER_QOS;
2388 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2389 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
2392 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2394 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2395 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2398 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2399 struct ieee80211_vif *vif,
2400 struct ieee80211_sta *sta,
2401 struct wmi_peer_assoc_complete_arg *arg)
2403 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2404 struct cfg80211_chan_def def;
2405 enum ieee80211_band band;
2406 const u8 *ht_mcs_mask;
2407 const u16 *vht_mcs_mask;
2408 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2410 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2413 band = def.chan->band;
2414 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2415 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2418 case IEEE80211_BAND_2GHZ:
2419 if (sta->vht_cap.vht_supported &&
2420 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2421 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2422 phymode = MODE_11AC_VHT40;
2424 phymode = MODE_11AC_VHT20;
2425 } else if (sta->ht_cap.ht_supported &&
2426 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2427 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2428 phymode = MODE_11NG_HT40;
2430 phymode = MODE_11NG_HT20;
2431 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2438 case IEEE80211_BAND_5GHZ:
2442 if (sta->vht_cap.vht_supported &&
2443 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2444 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2445 phymode = MODE_11AC_VHT80;
2446 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2447 phymode = MODE_11AC_VHT40;
2448 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2449 phymode = MODE_11AC_VHT20;
2450 } else if (sta->ht_cap.ht_supported &&
2451 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2452 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2453 phymode = MODE_11NA_HT40;
2455 phymode = MODE_11NA_HT20;
2465 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2466 sta->addr, ath10k_wmi_phymode_str(phymode));
2468 arg->peer_phymode = phymode;
2469 WARN_ON(phymode == MODE_UNKNOWN);
2472 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2473 struct ieee80211_vif *vif,
2474 struct ieee80211_sta *sta,
2475 struct wmi_peer_assoc_complete_arg *arg)
2477 lockdep_assert_held(&ar->conf_mutex);
2479 memset(arg, 0, sizeof(*arg));
2481 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2482 ath10k_peer_assoc_h_crypto(ar, vif, arg);
2483 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2484 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2485 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2486 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2487 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2492 static const u32 ath10k_smps_map[] = {
2493 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2494 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2495 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2496 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2499 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2501 const struct ieee80211_sta_ht_cap *ht_cap)
2505 if (!ht_cap->ht_supported)
2508 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2509 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2511 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2514 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2515 WMI_PEER_SMPS_STATE,
2516 ath10k_smps_map[smps]);
2519 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2520 struct ieee80211_vif *vif,
2521 struct ieee80211_sta_vht_cap vht_cap)
2523 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2528 if (!(ar->vht_cap_info &
2529 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2530 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2531 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2532 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2535 param = ar->wmi.vdev_param->txbf;
2538 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2541 /* The following logic is correct. If a remote STA advertises support
2542 * for being a beamformer then we should enable us being a beamformee.
2545 if (ar->vht_cap_info &
2546 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2547 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2548 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2549 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2551 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2552 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2555 if (ar->vht_cap_info &
2556 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2557 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2558 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2559 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2561 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2562 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2565 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2566 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2568 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2569 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2571 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2573 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2581 /* can be called only in mac80211 callbacks due to `key_count` usage */
2582 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2583 struct ieee80211_vif *vif,
2584 struct ieee80211_bss_conf *bss_conf)
2586 struct ath10k *ar = hw->priv;
2587 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2588 struct ieee80211_sta_ht_cap ht_cap;
2589 struct ieee80211_sta_vht_cap vht_cap;
2590 struct wmi_peer_assoc_complete_arg peer_arg;
2591 struct ieee80211_sta *ap_sta;
2594 lockdep_assert_held(&ar->conf_mutex);
2596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2597 arvif->vdev_id, arvif->bssid, arvif->aid);
2601 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2603 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2604 bss_conf->bssid, arvif->vdev_id);
2609 /* ap_sta must be accessed only within rcu section which must be left
2610 * before calling ath10k_setup_peer_smps() which might sleep. */
2611 ht_cap = ap_sta->ht_cap;
2612 vht_cap = ap_sta->vht_cap;
2614 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2616 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2617 bss_conf->bssid, arvif->vdev_id, ret);
2624 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2626 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2627 bss_conf->bssid, arvif->vdev_id, ret);
2631 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2633 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2634 arvif->vdev_id, ret);
2638 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2640 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2641 arvif->vdev_id, bss_conf->bssid, ret);
2645 ath10k_dbg(ar, ATH10K_DBG_MAC,
2646 "mac vdev %d up (associated) bssid %pM aid %d\n",
2647 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2649 WARN_ON(arvif->is_up);
2651 arvif->aid = bss_conf->aid;
2652 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2654 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2656 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2657 arvif->vdev_id, ret);
2661 arvif->is_up = true;
2663 /* Workaround: Some firmware revisions (tested with qca6174
2664 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2665 * poked with peer param command.
2667 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2668 WMI_PEER_DUMMY_VAR, 1);
2670 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2671 arvif->bssid, arvif->vdev_id, ret);
2676 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2677 struct ieee80211_vif *vif)
2679 struct ath10k *ar = hw->priv;
2680 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2681 struct ieee80211_sta_vht_cap vht_cap = {};
2684 lockdep_assert_held(&ar->conf_mutex);
2686 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2687 arvif->vdev_id, arvif->bssid);
2689 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2691 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2692 arvif->vdev_id, ret);
2694 arvif->def_wep_key_idx = -1;
2696 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2698 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2699 arvif->vdev_id, ret);
2703 arvif->is_up = false;
2705 cancel_delayed_work_sync(&arvif->connection_loss_work);
2708 static int ath10k_station_assoc(struct ath10k *ar,
2709 struct ieee80211_vif *vif,
2710 struct ieee80211_sta *sta,
2713 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2714 struct wmi_peer_assoc_complete_arg peer_arg;
2717 lockdep_assert_held(&ar->conf_mutex);
2719 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2721 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2722 sta->addr, arvif->vdev_id, ret);
2726 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2728 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2729 sta->addr, arvif->vdev_id, ret);
2733 /* Re-assoc is run only to update supported rates for given station. It
2734 * doesn't make much sense to reconfigure the peer completely.
2737 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2740 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2741 arvif->vdev_id, ret);
2745 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2747 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2748 sta->addr, arvif->vdev_id, ret);
2753 arvif->num_legacy_stations++;
2754 ret = ath10k_recalc_rtscts_prot(arvif);
2756 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2757 arvif->vdev_id, ret);
2762 /* Plumb cached keys only for static WEP */
2763 if (arvif->def_wep_key_idx != -1) {
2764 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2766 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2767 arvif->vdev_id, ret);
2776 static int ath10k_station_disassoc(struct ath10k *ar,
2777 struct ieee80211_vif *vif,
2778 struct ieee80211_sta *sta)
2780 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2783 lockdep_assert_held(&ar->conf_mutex);
2786 arvif->num_legacy_stations--;
2787 ret = ath10k_recalc_rtscts_prot(arvif);
2789 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2790 arvif->vdev_id, ret);
2795 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2797 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2798 arvif->vdev_id, ret);
2809 static int ath10k_update_channel_list(struct ath10k *ar)
2811 struct ieee80211_hw *hw = ar->hw;
2812 struct ieee80211_supported_band **bands;
2813 enum ieee80211_band band;
2814 struct ieee80211_channel *channel;
2815 struct wmi_scan_chan_list_arg arg = {0};
2816 struct wmi_channel_arg *ch;
2822 lockdep_assert_held(&ar->conf_mutex);
2824 bands = hw->wiphy->bands;
2825 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2829 for (i = 0; i < bands[band]->n_channels; i++) {
2830 if (bands[band]->channels[i].flags &
2831 IEEE80211_CHAN_DISABLED)
2838 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2839 arg.channels = kzalloc(len, GFP_KERNEL);
2844 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2848 for (i = 0; i < bands[band]->n_channels; i++) {
2849 channel = &bands[band]->channels[i];
2851 if (channel->flags & IEEE80211_CHAN_DISABLED)
2854 ch->allow_ht = true;
2856 /* FIXME: when should we really allow VHT? */
2857 ch->allow_vht = true;
2860 !(channel->flags & IEEE80211_CHAN_NO_IR);
2863 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2866 !!(channel->flags & IEEE80211_CHAN_RADAR);
2868 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2869 ch->passive = passive;
2871 ch->freq = channel->center_freq;
2872 ch->band_center_freq1 = channel->center_freq;
2874 ch->max_power = channel->max_power * 2;
2875 ch->max_reg_power = channel->max_reg_power * 2;
2876 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2877 ch->reg_class_id = 0; /* FIXME */
2879 /* FIXME: why use only legacy modes, why not any
2880 * HT/VHT modes? Would that even make any
2882 if (channel->band == IEEE80211_BAND_2GHZ)
2883 ch->mode = MODE_11G;
2885 ch->mode = MODE_11A;
2887 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2890 ath10k_dbg(ar, ATH10K_DBG_WMI,
2891 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2892 ch - arg.channels, arg.n_channels,
2893 ch->freq, ch->max_power, ch->max_reg_power,
2894 ch->max_antenna_gain, ch->mode);
2900 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2901 kfree(arg.channels);
2906 static enum wmi_dfs_region
2907 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2909 switch (dfs_region) {
2910 case NL80211_DFS_UNSET:
2911 return WMI_UNINIT_DFS_DOMAIN;
2912 case NL80211_DFS_FCC:
2913 return WMI_FCC_DFS_DOMAIN;
2914 case NL80211_DFS_ETSI:
2915 return WMI_ETSI_DFS_DOMAIN;
2916 case NL80211_DFS_JP:
2917 return WMI_MKK4_DFS_DOMAIN;
2919 return WMI_UNINIT_DFS_DOMAIN;
2922 static void ath10k_regd_update(struct ath10k *ar)
2924 struct reg_dmn_pair_mapping *regpair;
2926 enum wmi_dfs_region wmi_dfs_reg;
2927 enum nl80211_dfs_regions nl_dfs_reg;
2929 lockdep_assert_held(&ar->conf_mutex);
2931 ret = ath10k_update_channel_list(ar);
2933 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2935 regpair = ar->ath_common.regulatory.regpair;
2937 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2938 nl_dfs_reg = ar->dfs_detector->region;
2939 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2941 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2944 /* Target allows setting up per-band regdomain but ath_common provides
2945 * a combined one only */
2946 ret = ath10k_wmi_pdev_set_regdomain(ar,
2947 regpair->reg_domain,
2948 regpair->reg_domain, /* 2ghz */
2949 regpair->reg_domain, /* 5ghz */
2950 regpair->reg_2ghz_ctl,
2951 regpair->reg_5ghz_ctl,
2954 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
2957 static void ath10k_reg_notifier(struct wiphy *wiphy,
2958 struct regulatory_request *request)
2960 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2961 struct ath10k *ar = hw->priv;
2964 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2966 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2967 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
2968 request->dfs_region);
2969 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2970 request->dfs_region);
2972 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2973 request->dfs_region);
2976 mutex_lock(&ar->conf_mutex);
2977 if (ar->state == ATH10K_STATE_ON)
2978 ath10k_regd_update(ar);
2979 mutex_unlock(&ar->conf_mutex);
2986 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2988 lockdep_assert_held(&ar->htt.tx_lock);
2990 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2991 ar->tx_paused |= BIT(reason);
2992 ieee80211_stop_queues(ar->hw);
2995 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2996 struct ieee80211_vif *vif)
2998 struct ath10k *ar = data;
2999 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3001 if (arvif->tx_paused)
3004 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3007 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3009 lockdep_assert_held(&ar->htt.tx_lock);
3011 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3012 ar->tx_paused &= ~BIT(reason);
3017 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3018 IEEE80211_IFACE_ITER_RESUME_ALL,
3019 ath10k_mac_tx_unlock_iter,
3023 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3025 struct ath10k *ar = arvif->ar;
3027 lockdep_assert_held(&ar->htt.tx_lock);
3029 WARN_ON(reason >= BITS_PER_LONG);
3030 arvif->tx_paused |= BIT(reason);
3031 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3034 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3036 struct ath10k *ar = arvif->ar;
3038 lockdep_assert_held(&ar->htt.tx_lock);
3040 WARN_ON(reason >= BITS_PER_LONG);
3041 arvif->tx_paused &= ~BIT(reason);
3046 if (arvif->tx_paused)
3049 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3052 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3053 enum wmi_tlv_tx_pause_id pause_id,
3054 enum wmi_tlv_tx_pause_action action)
3056 struct ath10k *ar = arvif->ar;
3058 lockdep_assert_held(&ar->htt.tx_lock);
3061 case WMI_TLV_TX_PAUSE_ID_MCC:
3062 case WMI_TLV_TX_PAUSE_ID_P2P_CLI_NOA:
3063 case WMI_TLV_TX_PAUSE_ID_P2P_GO_PS:
3064 case WMI_TLV_TX_PAUSE_ID_AP_PS:
3065 case WMI_TLV_TX_PAUSE_ID_IBSS_PS:
3067 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3068 ath10k_mac_vif_tx_lock(arvif, pause_id);
3070 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3071 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3074 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3075 action, arvif->vdev_id);
3079 case WMI_TLV_TX_PAUSE_ID_AP_PEER_PS:
3080 case WMI_TLV_TX_PAUSE_ID_AP_PEER_UAPSD:
3081 case WMI_TLV_TX_PAUSE_ID_STA_ADD_BA:
3082 case WMI_TLV_TX_PAUSE_ID_HOST:
3084 /* FIXME: Some pause_ids aren't vdev specific. Instead they
3085 * target peer_id and tid. Implementing these could improve
3086 * traffic scheduling fairness across multiple connected
3087 * stations in AP/IBSS modes.
3089 ath10k_dbg(ar, ATH10K_DBG_MAC,
3090 "mac ignoring unsupported tx pause vdev %i id %d\n",
3091 arvif->vdev_id, pause_id);
3096 struct ath10k_mac_tx_pause {
3098 enum wmi_tlv_tx_pause_id pause_id;
3099 enum wmi_tlv_tx_pause_action action;
3102 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3103 struct ieee80211_vif *vif)
3105 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3106 struct ath10k_mac_tx_pause *arg = data;
3108 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3111 void ath10k_mac_handle_tx_pause(struct ath10k *ar, u32 vdev_id,
3112 enum wmi_tlv_tx_pause_id pause_id,
3113 enum wmi_tlv_tx_pause_action action)
3115 struct ath10k_mac_tx_pause arg = {
3117 .pause_id = pause_id,
3121 spin_lock_bh(&ar->htt.tx_lock);
3122 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3123 IEEE80211_IFACE_ITER_RESUME_ALL,
3124 ath10k_mac_handle_tx_pause_iter,
3126 spin_unlock_bh(&ar->htt.tx_lock);
3129 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3131 if (ieee80211_is_mgmt(hdr->frame_control))
3132 return HTT_DATA_TX_EXT_TID_MGMT;
3134 if (!ieee80211_is_data_qos(hdr->frame_control))
3135 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3137 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3138 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3140 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3143 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
3146 return ath10k_vif_to_arvif(vif)->vdev_id;
3148 if (ar->monitor_started)
3149 return ar->monitor_vdev_id;
3151 ath10k_warn(ar, "failed to resolve vdev id\n");
3155 static enum ath10k_hw_txrx_mode
3156 ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
3157 struct ieee80211_sta *sta, struct sk_buff *skb)
3159 const struct ieee80211_hdr *hdr = (void *)skb->data;
3160 __le16 fc = hdr->frame_control;
3162 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3163 return ATH10K_HW_TXRX_RAW;
3165 if (ieee80211_is_mgmt(fc))
3166 return ATH10K_HW_TXRX_MGMT;
3170 * NullFunc frames are mostly used to ping if a client or AP are still
3171 * reachable and responsive. This implies tx status reports must be
3172 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3173 * come to a conclusion that the other end disappeared and tear down
3174 * BSS connection or it can never disconnect from BSS/client (which is
3177 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3178 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3179 * which seems to deliver correct tx reports for NullFunc frames. The
3180 * downside of using it is it ignores client powersave state so it can
3181 * end up disconnecting sleeping clients in AP mode. It should fix STA
3182 * mode though because AP don't sleep.
3184 if (ar->htt.target_version_major < 3 &&
3185 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3186 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3187 return ATH10K_HW_TXRX_MGMT;
3191 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3192 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3193 * to work with Ethernet txmode so use it.
3195 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3196 return ATH10K_HW_TXRX_ETHERNET;
3198 return ATH10K_HW_TXRX_NATIVE_WIFI;
3201 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3202 * Control in the header.
3204 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3206 struct ieee80211_hdr *hdr = (void *)skb->data;
3207 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3210 if (!ieee80211_is_data_qos(hdr->frame_control))
3213 qos_ctl = ieee80211_get_qos_ctl(hdr);
3214 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3215 skb->data, (void *)qos_ctl - (void *)skb->data);
3216 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3218 /* Some firmware revisions don't handle sending QoS NullFunc well.
3219 * These frames are mainly used for CQM purposes so it doesn't really
3220 * matter whether QoS NullFunc or NullFunc are sent.
3222 hdr = (void *)skb->data;
3223 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3224 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3226 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3229 static void ath10k_tx_h_8023(struct sk_buff *skb)
3231 struct ieee80211_hdr *hdr;
3232 struct rfc1042_hdr *rfc1042;
3239 hdr = (void *)skb->data;
3240 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3241 rfc1042 = (void *)skb->data + hdrlen;
3243 ether_addr_copy(da, ieee80211_get_DA(hdr));
3244 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3245 type = rfc1042->snap_type;
3247 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3248 skb_push(skb, sizeof(*eth));
3250 eth = (void *)skb->data;
3251 ether_addr_copy(eth->h_dest, da);
3252 ether_addr_copy(eth->h_source, sa);
3253 eth->h_proto = type;
3256 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3257 struct ieee80211_vif *vif,
3258 struct sk_buff *skb)
3260 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3261 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3263 /* This is case only for P2P_GO */
3264 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3265 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3268 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3269 spin_lock_bh(&ar->data_lock);
3270 if (arvif->u.ap.noa_data)
3271 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3273 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3274 arvif->u.ap.noa_data,
3275 arvif->u.ap.noa_len);
3276 spin_unlock_bh(&ar->data_lock);
3280 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3282 /* FIXME: Not really sure since when the behaviour changed. At some
3283 * point new firmware stopped requiring creation of peer entries for
3284 * offchannel tx (and actually creating them causes issues with wmi-htc
3285 * tx credit replenishment and reliability). Assuming it's at least 3.4
3286 * because that's when the `freq` was introduced to TX_FRM HTT command.
3288 return !(ar->htt.target_version_major >= 3 &&
3289 ar->htt.target_version_minor >= 4);
3292 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3294 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3297 spin_lock_bh(&ar->data_lock);
3299 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3300 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3305 __skb_queue_tail(q, skb);
3306 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3309 spin_unlock_bh(&ar->data_lock);
3314 static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3316 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3317 struct ath10k_htt *htt = &ar->htt;
3320 switch (cb->txmode) {
3321 case ATH10K_HW_TXRX_RAW:
3322 case ATH10K_HW_TXRX_NATIVE_WIFI:
3323 case ATH10K_HW_TXRX_ETHERNET:
3324 ret = ath10k_htt_tx(htt, skb);
3326 case ATH10K_HW_TXRX_MGMT:
3327 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3329 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3330 else if (ar->htt.target_version_major >= 3)
3331 ret = ath10k_htt_tx(htt, skb);
3333 ret = ath10k_htt_mgmt_tx(htt, skb);
3338 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3340 ieee80211_free_txskb(ar->hw, skb);
3344 void ath10k_offchan_tx_purge(struct ath10k *ar)
3346 struct sk_buff *skb;
3349 skb = skb_dequeue(&ar->offchan_tx_queue);
3353 ieee80211_free_txskb(ar->hw, skb);
3357 void ath10k_offchan_tx_work(struct work_struct *work)
3359 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3360 struct ath10k_peer *peer;
3361 struct ieee80211_hdr *hdr;
3362 struct sk_buff *skb;
3363 const u8 *peer_addr;
3366 unsigned long time_left;
3368 /* FW requirement: We must create a peer before FW will send out
3369 * an offchannel frame. Otherwise the frame will be stuck and
3370 * never transmitted. We delete the peer upon tx completion.
3371 * It is unlikely that a peer for offchannel tx will already be
3372 * present. However it may be in some rare cases so account for that.
3373 * Otherwise we might remove a legitimate peer and break stuff. */
3376 skb = skb_dequeue(&ar->offchan_tx_queue);
3380 mutex_lock(&ar->conf_mutex);
3382 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
3385 hdr = (struct ieee80211_hdr *)skb->data;
3386 peer_addr = ieee80211_get_DA(hdr);
3387 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
3389 spin_lock_bh(&ar->data_lock);
3390 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3391 spin_unlock_bh(&ar->data_lock);
3394 /* FIXME: should this use ath10k_warn()? */
3395 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3396 peer_addr, vdev_id);
3399 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3400 WMI_PEER_TYPE_DEFAULT);
3402 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3403 peer_addr, vdev_id, ret);
3406 spin_lock_bh(&ar->data_lock);
3407 reinit_completion(&ar->offchan_tx_completed);
3408 ar->offchan_tx_skb = skb;
3409 spin_unlock_bh(&ar->data_lock);
3411 ath10k_mac_tx(ar, skb);
3414 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3416 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
3420 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3422 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3423 peer_addr, vdev_id, ret);
3426 mutex_unlock(&ar->conf_mutex);
3430 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3432 struct sk_buff *skb;
3435 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3439 ieee80211_free_txskb(ar->hw, skb);
3443 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3445 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3446 struct sk_buff *skb;
3450 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3454 ret = ath10k_wmi_mgmt_tx(ar, skb);
3456 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3458 ieee80211_free_txskb(ar->hw, skb);
3467 void __ath10k_scan_finish(struct ath10k *ar)
3469 lockdep_assert_held(&ar->data_lock);
3471 switch (ar->scan.state) {
3472 case ATH10K_SCAN_IDLE:
3474 case ATH10K_SCAN_RUNNING:
3475 if (ar->scan.is_roc)
3476 ieee80211_remain_on_channel_expired(ar->hw);
3478 case ATH10K_SCAN_ABORTING:
3479 if (!ar->scan.is_roc)
3480 ieee80211_scan_completed(ar->hw,
3482 ATH10K_SCAN_ABORTING));
3484 case ATH10K_SCAN_STARTING:
3485 ar->scan.state = ATH10K_SCAN_IDLE;
3486 ar->scan_channel = NULL;
3487 ath10k_offchan_tx_purge(ar);
3488 cancel_delayed_work(&ar->scan.timeout);
3489 complete_all(&ar->scan.completed);
3494 void ath10k_scan_finish(struct ath10k *ar)
3496 spin_lock_bh(&ar->data_lock);
3497 __ath10k_scan_finish(ar);
3498 spin_unlock_bh(&ar->data_lock);
3501 static int ath10k_scan_stop(struct ath10k *ar)
3503 struct wmi_stop_scan_arg arg = {
3504 .req_id = 1, /* FIXME */
3505 .req_type = WMI_SCAN_STOP_ONE,
3506 .u.scan_id = ATH10K_SCAN_ID,
3510 lockdep_assert_held(&ar->conf_mutex);
3512 ret = ath10k_wmi_stop_scan(ar, &arg);
3514 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3518 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
3520 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3522 } else if (ret > 0) {
3527 /* Scan state should be updated upon scan completion but in case
3528 * firmware fails to deliver the event (for whatever reason) it is
3529 * desired to clean up scan state anyway. Firmware may have just
3530 * dropped the scan completion event delivery due to transport pipe
3531 * being overflown with data and/or it can recover on its own before
3532 * next scan request is submitted.
3534 spin_lock_bh(&ar->data_lock);
3535 if (ar->scan.state != ATH10K_SCAN_IDLE)
3536 __ath10k_scan_finish(ar);
3537 spin_unlock_bh(&ar->data_lock);
3542 static void ath10k_scan_abort(struct ath10k *ar)
3546 lockdep_assert_held(&ar->conf_mutex);
3548 spin_lock_bh(&ar->data_lock);
3550 switch (ar->scan.state) {
3551 case ATH10K_SCAN_IDLE:
3552 /* This can happen if timeout worker kicked in and called
3553 * abortion while scan completion was being processed.
3556 case ATH10K_SCAN_STARTING:
3557 case ATH10K_SCAN_ABORTING:
3558 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3559 ath10k_scan_state_str(ar->scan.state),
3562 case ATH10K_SCAN_RUNNING:
3563 ar->scan.state = ATH10K_SCAN_ABORTING;
3564 spin_unlock_bh(&ar->data_lock);
3566 ret = ath10k_scan_stop(ar);
3568 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3570 spin_lock_bh(&ar->data_lock);
3574 spin_unlock_bh(&ar->data_lock);
3577 void ath10k_scan_timeout_work(struct work_struct *work)
3579 struct ath10k *ar = container_of(work, struct ath10k,
3582 mutex_lock(&ar->conf_mutex);
3583 ath10k_scan_abort(ar);
3584 mutex_unlock(&ar->conf_mutex);
3587 static int ath10k_start_scan(struct ath10k *ar,
3588 const struct wmi_start_scan_arg *arg)
3592 lockdep_assert_held(&ar->conf_mutex);
3594 ret = ath10k_wmi_start_scan(ar, arg);
3598 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3600 ret = ath10k_scan_stop(ar);
3602 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3607 /* If we failed to start the scan, return error code at
3608 * this point. This is probably due to some issue in the
3609 * firmware, but no need to wedge the driver due to that...
3611 spin_lock_bh(&ar->data_lock);
3612 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3613 spin_unlock_bh(&ar->data_lock);
3616 spin_unlock_bh(&ar->data_lock);
3618 /* Add a 200ms margin to account for event/command processing */
3619 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3620 msecs_to_jiffies(arg->max_scan_time+200));
3624 /**********************/
3625 /* mac80211 callbacks */
3626 /**********************/
3628 static void ath10k_tx(struct ieee80211_hw *hw,
3629 struct ieee80211_tx_control *control,
3630 struct sk_buff *skb)
3632 struct ath10k *ar = hw->priv;
3633 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3634 struct ieee80211_vif *vif = info->control.vif;
3635 struct ieee80211_sta *sta = control->sta;
3636 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3637 __le16 fc = hdr->frame_control;
3639 /* We should disable CCK RATE due to P2P */
3640 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3641 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3643 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
3644 ATH10K_SKB_CB(skb)->htt.freq = 0;
3645 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
3646 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
3647 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
3648 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
3650 switch (ATH10K_SKB_CB(skb)->txmode) {
3651 case ATH10K_HW_TXRX_MGMT:
3652 case ATH10K_HW_TXRX_NATIVE_WIFI:
3653 ath10k_tx_h_nwifi(hw, skb);
3654 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3655 ath10k_tx_h_seq_no(vif, skb);
3657 case ATH10K_HW_TXRX_ETHERNET:
3658 ath10k_tx_h_8023(skb);
3660 case ATH10K_HW_TXRX_RAW:
3661 /* FIXME: Packet injection isn't implemented. It should be
3662 * doable with firmware 10.2 on qca988x.
3665 ieee80211_free_txskb(hw, skb);
3669 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3670 spin_lock_bh(&ar->data_lock);
3671 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
3672 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
3673 spin_unlock_bh(&ar->data_lock);
3675 if (ath10k_mac_need_offchan_tx_work(ar)) {
3676 ATH10K_SKB_CB(skb)->htt.freq = 0;
3677 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
3679 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3682 skb_queue_tail(&ar->offchan_tx_queue, skb);
3683 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3688 ath10k_mac_tx(ar, skb);
3691 /* Must not be called with conf_mutex held as workers can use that also. */
3692 void ath10k_drain_tx(struct ath10k *ar)
3694 /* make sure rcu-protected mac80211 tx path itself is drained */
3697 ath10k_offchan_tx_purge(ar);
3698 ath10k_mgmt_over_wmi_tx_purge(ar);
3700 cancel_work_sync(&ar->offchan_tx_work);
3701 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3704 void ath10k_halt(struct ath10k *ar)
3706 struct ath10k_vif *arvif;
3708 lockdep_assert_held(&ar->conf_mutex);
3710 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3711 ar->filter_flags = 0;
3712 ar->monitor = false;
3713 ar->monitor_arvif = NULL;
3715 if (ar->monitor_started)
3716 ath10k_monitor_stop(ar);
3718 ar->monitor_started = false;
3721 ath10k_scan_finish(ar);
3722 ath10k_peer_cleanup_all(ar);
3723 ath10k_core_stop(ar);
3724 ath10k_hif_power_down(ar);
3726 spin_lock_bh(&ar->data_lock);
3727 list_for_each_entry(arvif, &ar->arvifs, list)
3728 ath10k_mac_vif_beacon_cleanup(arvif);
3729 spin_unlock_bh(&ar->data_lock);
3732 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3734 struct ath10k *ar = hw->priv;
3736 mutex_lock(&ar->conf_mutex);
3738 if (ar->cfg_tx_chainmask) {
3739 *tx_ant = ar->cfg_tx_chainmask;
3740 *rx_ant = ar->cfg_rx_chainmask;
3742 *tx_ant = ar->supp_tx_chainmask;
3743 *rx_ant = ar->supp_rx_chainmask;
3746 mutex_unlock(&ar->conf_mutex);
3751 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3753 /* It is not clear that allowing gaps in chainmask
3754 * is helpful. Probably it will not do what user
3755 * is hoping for, so warn in that case.
3757 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3760 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3764 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3768 lockdep_assert_held(&ar->conf_mutex);
3770 ath10k_check_chain_mask(ar, tx_ant, "tx");
3771 ath10k_check_chain_mask(ar, rx_ant, "rx");
3773 ar->cfg_tx_chainmask = tx_ant;
3774 ar->cfg_rx_chainmask = rx_ant;
3776 if ((ar->state != ATH10K_STATE_ON) &&
3777 (ar->state != ATH10K_STATE_RESTARTED))
3780 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3783 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
3788 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3791 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
3799 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3801 struct ath10k *ar = hw->priv;
3804 mutex_lock(&ar->conf_mutex);
3805 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3806 mutex_unlock(&ar->conf_mutex);
3810 static int ath10k_start(struct ieee80211_hw *hw)
3812 struct ath10k *ar = hw->priv;
3817 * This makes sense only when restarting hw. It is harmless to call
3818 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3819 * commands will be submitted while restarting.
3821 ath10k_drain_tx(ar);
3823 mutex_lock(&ar->conf_mutex);
3825 switch (ar->state) {
3826 case ATH10K_STATE_OFF:
3827 ar->state = ATH10K_STATE_ON;
3829 case ATH10K_STATE_RESTARTING:
3831 ar->state = ATH10K_STATE_RESTARTED;
3833 case ATH10K_STATE_ON:
3834 case ATH10K_STATE_RESTARTED:
3835 case ATH10K_STATE_WEDGED:
3839 case ATH10K_STATE_UTF:
3844 ret = ath10k_hif_power_up(ar);
3846 ath10k_err(ar, "Could not init hif: %d\n", ret);
3850 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
3852 ath10k_err(ar, "Could not init core: %d\n", ret);
3853 goto err_power_down;
3856 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
3858 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
3862 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
3864 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
3868 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3869 ret = ath10k_wmi_adaptive_qcs(ar, true);
3871 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3877 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3878 burst_enable = ar->wmi.pdev_param->burst_enable;
3879 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3881 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3886 if (ar->cfg_tx_chainmask)
3887 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3888 ar->cfg_rx_chainmask);
3891 * By default FW set ARP frames ac to voice (6). In that case ARP
3892 * exchange is not working properly for UAPSD enabled AP. ARP requests
3893 * which arrives with access category 0 are processed by network stack
3894 * and send back with access category 0, but FW changes access category
3895 * to 6. Set ARP frames access category to best effort (0) solves
3899 ret = ath10k_wmi_pdev_set_param(ar,
3900 ar->wmi.pdev_param->arp_ac_override, 0);
3902 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
3907 ret = ath10k_wmi_pdev_set_param(ar,
3908 ar->wmi.pdev_param->ani_enable, 1);
3910 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3915 ar->ani_enabled = true;
3917 ar->num_started_vdevs = 0;
3918 ath10k_regd_update(ar);
3920 ath10k_spectral_start(ar);
3921 ath10k_thermal_set_throttling(ar);
3923 mutex_unlock(&ar->conf_mutex);
3927 ath10k_core_stop(ar);
3930 ath10k_hif_power_down(ar);
3933 ar->state = ATH10K_STATE_OFF;
3936 mutex_unlock(&ar->conf_mutex);
3940 static void ath10k_stop(struct ieee80211_hw *hw)
3942 struct ath10k *ar = hw->priv;
3944 ath10k_drain_tx(ar);
3946 mutex_lock(&ar->conf_mutex);
3947 if (ar->state != ATH10K_STATE_OFF) {
3949 ar->state = ATH10K_STATE_OFF;
3951 mutex_unlock(&ar->conf_mutex);
3953 cancel_delayed_work_sync(&ar->scan.timeout);
3954 cancel_work_sync(&ar->restart_work);
3957 static int ath10k_config_ps(struct ath10k *ar)
3959 struct ath10k_vif *arvif;
3962 lockdep_assert_held(&ar->conf_mutex);
3964 list_for_each_entry(arvif, &ar->arvifs, list) {
3965 ret = ath10k_mac_vif_setup_ps(arvif);
3967 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
3975 static void ath10k_mac_chan_reconfigure(struct ath10k *ar)
3977 struct ath10k_vif *arvif;
3978 struct cfg80211_chan_def def;
3981 lockdep_assert_held(&ar->conf_mutex);
3983 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac chan reconfigure\n");
3985 /* First stop monitor interface. Some FW versions crash if there's a
3986 * lone monitor interface. */
3987 if (ar->monitor_started)
3988 ath10k_monitor_stop(ar);
3990 list_for_each_entry(arvif, &ar->arvifs, list) {
3991 if (!arvif->is_started)
3997 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
4000 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
4002 ath10k_warn(ar, "failed to down vdev %d: %d\n",
4003 arvif->vdev_id, ret);
4008 /* all vdevs are downed now - attempt to restart and re-up them */
4010 list_for_each_entry(arvif, &ar->arvifs, list) {
4011 if (!arvif->is_started)
4014 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
4017 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4019 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
4022 ret = ath10k_mac_setup_prb_tmpl(arvif);
4024 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
4027 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4030 ret = ath10k_vdev_restart(arvif, &def);
4032 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
4033 arvif->vdev_id, ret);
4040 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
4043 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
4044 arvif->vdev_id, ret);
4049 ath10k_monitor_recalc(ar);
4052 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4057 lockdep_assert_held(&ar->conf_mutex);
4059 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4061 param = ar->wmi.pdev_param->txpower_limit2g;
4062 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4064 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4069 param = ar->wmi.pdev_param->txpower_limit5g;
4070 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4072 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4080 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4082 struct ath10k_vif *arvif;
4083 int ret, txpower = -1;
4085 lockdep_assert_held(&ar->conf_mutex);
4087 list_for_each_entry(arvif, &ar->arvifs, list) {
4088 WARN_ON(arvif->txpower < 0);
4091 txpower = arvif->txpower;
4093 txpower = min(txpower, arvif->txpower);
4096 if (WARN_ON(txpower == -1))
4099 ret = ath10k_mac_txpower_setup(ar, txpower);
4101 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4109 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4111 struct ath10k *ar = hw->priv;
4112 struct ieee80211_conf *conf = &hw->conf;
4115 mutex_lock(&ar->conf_mutex);
4117 if (changed & IEEE80211_CONF_CHANGE_PS)
4118 ath10k_config_ps(ar);
4120 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4121 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4122 ret = ath10k_monitor_recalc(ar);
4124 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4127 mutex_unlock(&ar->conf_mutex);
4131 static u32 get_nss_from_chainmask(u16 chain_mask)
4133 if ((chain_mask & 0x15) == 0x15)
4135 else if ((chain_mask & 0x7) == 0x7)
4137 else if ((chain_mask & 0x3) == 0x3)
4144 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4145 * because we will send mgmt frames without CCK. This requirement
4146 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4149 static int ath10k_add_interface(struct ieee80211_hw *hw,
4150 struct ieee80211_vif *vif)
4152 struct ath10k *ar = hw->priv;
4153 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4154 enum wmi_sta_powersave_param param;
4161 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4163 mutex_lock(&ar->conf_mutex);
4165 memset(arvif, 0, sizeof(*arvif));
4170 INIT_LIST_HEAD(&arvif->list);
4171 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4172 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4173 ath10k_mac_vif_sta_connection_loss_work);
4175 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4176 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4177 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4178 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4179 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4180 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4183 if (ar->free_vdev_map == 0) {
4184 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4188 bit = __ffs64(ar->free_vdev_map);
4190 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4191 bit, ar->free_vdev_map);
4193 arvif->vdev_id = bit;
4194 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4196 switch (vif->type) {
4197 case NL80211_IFTYPE_P2P_DEVICE:
4198 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4199 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4201 case NL80211_IFTYPE_UNSPECIFIED:
4202 case NL80211_IFTYPE_STATION:
4203 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4205 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4207 case NL80211_IFTYPE_ADHOC:
4208 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4210 case NL80211_IFTYPE_AP:
4211 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4214 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4216 case NL80211_IFTYPE_MONITOR:
4217 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4224 /* Using vdev_id as queue number will make it very easy to do per-vif
4225 * tx queue locking. This shouldn't wrap due to interface combinations
4226 * but do a modulo for correctness sake and prevent using offchannel tx
4227 * queues for regular vif tx.
4229 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4230 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4231 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4233 /* Some firmware revisions don't wait for beacon tx completion before
4234 * sending another SWBA event. This could lead to hardware using old
4235 * (freed) beacon data in some cases, e.g. tx credit starvation
4236 * combined with missed TBTT. This is very very rare.
4238 * On non-IOMMU-enabled hosts this could be a possible security issue
4239 * because hw could beacon some random data on the air. On
4240 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4241 * device would crash.
4243 * Since there are no beacon tx completions (implicit nor explicit)
4244 * propagated to host the only workaround for this is to allocate a
4245 * DMA-coherent buffer for a lifetime of a vif and use it for all
4246 * beacon tx commands. Worst case for this approach is some beacons may
4247 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4249 if (vif->type == NL80211_IFTYPE_ADHOC ||
4250 vif->type == NL80211_IFTYPE_AP) {
4251 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4252 IEEE80211_MAX_FRAME_LEN,
4253 &arvif->beacon_paddr,
4255 if (!arvif->beacon_buf) {
4257 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4263 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4264 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4265 arvif->beacon_buf ? "single-buf" : "per-skb");
4267 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4268 arvif->vdev_subtype, vif->addr);
4270 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4271 arvif->vdev_id, ret);
4275 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4276 list_add(&arvif->list, &ar->arvifs);
4278 /* It makes no sense to have firmware do keepalives. mac80211 already
4279 * takes care of this with idle connection polling.
4281 ret = ath10k_mac_vif_disable_keepalive(arvif);
4283 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4284 arvif->vdev_id, ret);
4285 goto err_vdev_delete;
4288 arvif->def_wep_key_idx = -1;
4290 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4291 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4292 ATH10K_HW_TXRX_NATIVE_WIFI);
4293 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4294 if (ret && ret != -EOPNOTSUPP) {
4295 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4296 arvif->vdev_id, ret);
4297 goto err_vdev_delete;
4300 if (ar->cfg_tx_chainmask) {
4301 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4303 vdev_param = ar->wmi.vdev_param->nss;
4304 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4307 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4308 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4310 goto err_vdev_delete;
4314 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4315 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4316 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4317 WMI_PEER_TYPE_DEFAULT);
4319 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4320 arvif->vdev_id, ret);
4321 goto err_vdev_delete;
4325 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4326 ret = ath10k_mac_set_kickout(arvif);
4328 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
4329 arvif->vdev_id, ret);
4330 goto err_peer_delete;
4334 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4335 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4336 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4337 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4340 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
4341 arvif->vdev_id, ret);
4342 goto err_peer_delete;
4345 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4347 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4348 arvif->vdev_id, ret);
4349 goto err_peer_delete;
4352 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4354 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4355 arvif->vdev_id, ret);
4356 goto err_peer_delete;
4360 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
4362 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4363 arvif->vdev_id, ret);
4364 goto err_peer_delete;
4367 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
4369 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
4370 arvif->vdev_id, ret);
4371 goto err_peer_delete;
4374 arvif->txpower = vif->bss_conf.txpower;
4375 ret = ath10k_mac_txpower_recalc(ar);
4377 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4378 goto err_peer_delete;
4381 if (vif->type == NL80211_IFTYPE_MONITOR) {
4382 ar->monitor_arvif = arvif;
4383 ret = ath10k_monitor_recalc(ar);
4385 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4386 goto err_peer_delete;
4390 mutex_unlock(&ar->conf_mutex);
4394 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4395 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
4396 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4399 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4400 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4401 list_del(&arvif->list);
4404 if (arvif->beacon_buf) {
4405 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4406 arvif->beacon_buf, arvif->beacon_paddr);
4407 arvif->beacon_buf = NULL;
4410 mutex_unlock(&ar->conf_mutex);
4415 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4419 for (i = 0; i < BITS_PER_LONG; i++)
4420 ath10k_mac_vif_tx_unlock(arvif, i);
4423 static void ath10k_remove_interface(struct ieee80211_hw *hw,
4424 struct ieee80211_vif *vif)
4426 struct ath10k *ar = hw->priv;
4427 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4430 cancel_work_sync(&arvif->ap_csa_work);
4431 cancel_delayed_work_sync(&arvif->connection_loss_work);
4433 mutex_lock(&ar->conf_mutex);
4435 spin_lock_bh(&ar->data_lock);
4436 ath10k_mac_vif_beacon_cleanup(arvif);
4437 spin_unlock_bh(&ar->data_lock);
4439 ret = ath10k_spectral_vif_stop(arvif);
4441 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
4442 arvif->vdev_id, ret);
4444 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4445 list_del(&arvif->list);
4447 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4448 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4449 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4452 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4453 arvif->vdev_id, ret);
4455 kfree(arvif->u.ap.noa_data);
4458 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
4461 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4463 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
4464 arvif->vdev_id, ret);
4466 /* Some firmware revisions don't notify host about self-peer removal
4467 * until after associated vdev is deleted.
4469 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4470 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4471 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4474 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4475 arvif->vdev_id, ret);
4477 spin_lock_bh(&ar->data_lock);
4479 spin_unlock_bh(&ar->data_lock);
4482 ath10k_peer_cleanup(ar, arvif->vdev_id);
4484 if (vif->type == NL80211_IFTYPE_MONITOR) {
4485 ar->monitor_arvif = NULL;
4486 ret = ath10k_monitor_recalc(ar);
4488 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4491 spin_lock_bh(&ar->htt.tx_lock);
4492 ath10k_mac_vif_tx_unlock_all(arvif);
4493 spin_unlock_bh(&ar->htt.tx_lock);
4495 mutex_unlock(&ar->conf_mutex);
4499 * FIXME: Has to be verified.
4501 #define SUPPORTED_FILTERS \
4502 (FIF_PROMISC_IN_BSS | \
4507 FIF_BCN_PRBRESP_PROMISC | \
4511 static void ath10k_configure_filter(struct ieee80211_hw *hw,
4512 unsigned int changed_flags,
4513 unsigned int *total_flags,
4516 struct ath10k *ar = hw->priv;
4519 mutex_lock(&ar->conf_mutex);
4521 changed_flags &= SUPPORTED_FILTERS;
4522 *total_flags &= SUPPORTED_FILTERS;
4523 ar->filter_flags = *total_flags;
4525 ret = ath10k_monitor_recalc(ar);
4527 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
4529 mutex_unlock(&ar->conf_mutex);
4532 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4533 struct ieee80211_vif *vif,
4534 struct ieee80211_bss_conf *info,
4537 struct ath10k *ar = hw->priv;
4538 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4540 u32 vdev_param, pdev_param, slottime, preamble;
4542 mutex_lock(&ar->conf_mutex);
4544 if (changed & BSS_CHANGED_IBSS)
4545 ath10k_control_ibss(arvif, info, vif->addr);
4547 if (changed & BSS_CHANGED_BEACON_INT) {
4548 arvif->beacon_interval = info->beacon_int;
4549 vdev_param = ar->wmi.vdev_param->beacon_interval;
4550 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4551 arvif->beacon_interval);
4552 ath10k_dbg(ar, ATH10K_DBG_MAC,
4553 "mac vdev %d beacon_interval %d\n",
4554 arvif->vdev_id, arvif->beacon_interval);
4557 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
4558 arvif->vdev_id, ret);
4561 if (changed & BSS_CHANGED_BEACON) {
4562 ath10k_dbg(ar, ATH10K_DBG_MAC,
4563 "vdev %d set beacon tx mode to staggered\n",
4566 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4567 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
4568 WMI_BEACON_STAGGERED_MODE);
4570 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
4571 arvif->vdev_id, ret);
4573 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4575 ath10k_warn(ar, "failed to update beacon template: %d\n",
4579 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4580 ret = ath10k_mac_setup_prb_tmpl(arvif);
4582 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4583 arvif->vdev_id, ret);
4586 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
4587 arvif->dtim_period = info->dtim_period;
4589 ath10k_dbg(ar, ATH10K_DBG_MAC,
4590 "mac vdev %d dtim_period %d\n",
4591 arvif->vdev_id, arvif->dtim_period);
4593 vdev_param = ar->wmi.vdev_param->dtim_period;
4594 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4595 arvif->dtim_period);
4597 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
4598 arvif->vdev_id, ret);
4601 if (changed & BSS_CHANGED_SSID &&
4602 vif->type == NL80211_IFTYPE_AP) {
4603 arvif->u.ap.ssid_len = info->ssid_len;
4605 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4606 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4609 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4610 ether_addr_copy(arvif->bssid, info->bssid);
4612 if (changed & BSS_CHANGED_BEACON_ENABLED)
4613 ath10k_control_beaconing(arvif, info);
4615 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
4616 arvif->use_cts_prot = info->use_cts_prot;
4617 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
4618 arvif->vdev_id, info->use_cts_prot);
4620 ret = ath10k_recalc_rtscts_prot(arvif);
4622 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4623 arvif->vdev_id, ret);
4625 vdev_param = ar->wmi.vdev_param->protection_mode;
4626 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4627 info->use_cts_prot ? 1 : 0);
4629 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4630 info->use_cts_prot, arvif->vdev_id, ret);
4633 if (changed & BSS_CHANGED_ERP_SLOT) {
4634 if (info->use_short_slot)
4635 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4638 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4640 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
4641 arvif->vdev_id, slottime);
4643 vdev_param = ar->wmi.vdev_param->slot_time;
4644 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4647 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
4648 arvif->vdev_id, ret);
4651 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4652 if (info->use_short_preamble)
4653 preamble = WMI_VDEV_PREAMBLE_SHORT;
4655 preamble = WMI_VDEV_PREAMBLE_LONG;
4657 ath10k_dbg(ar, ATH10K_DBG_MAC,
4658 "mac vdev %d preamble %dn",
4659 arvif->vdev_id, preamble);
4661 vdev_param = ar->wmi.vdev_param->preamble;
4662 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4665 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
4666 arvif->vdev_id, ret);
4669 if (changed & BSS_CHANGED_ASSOC) {
4671 /* Workaround: Make sure monitor vdev is not running
4672 * when associating to prevent some firmware revisions
4673 * (e.g. 10.1 and 10.2) from crashing.
4675 if (ar->monitor_started)
4676 ath10k_monitor_stop(ar);
4677 ath10k_bss_assoc(hw, vif, info);
4678 ath10k_monitor_recalc(ar);
4680 ath10k_bss_disassoc(hw, vif);
4684 if (changed & BSS_CHANGED_TXPOWER) {
4685 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4686 arvif->vdev_id, info->txpower);
4688 arvif->txpower = info->txpower;
4689 ret = ath10k_mac_txpower_recalc(ar);
4691 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4694 if (changed & BSS_CHANGED_PS) {
4695 arvif->ps = vif->bss_conf.ps;
4697 ret = ath10k_config_ps(ar);
4699 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4700 arvif->vdev_id, ret);
4703 mutex_unlock(&ar->conf_mutex);
4706 static int ath10k_hw_scan(struct ieee80211_hw *hw,
4707 struct ieee80211_vif *vif,
4708 struct ieee80211_scan_request *hw_req)
4710 struct ath10k *ar = hw->priv;
4711 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4712 struct cfg80211_scan_request *req = &hw_req->req;
4713 struct wmi_start_scan_arg arg;
4717 mutex_lock(&ar->conf_mutex);
4719 spin_lock_bh(&ar->data_lock);
4720 switch (ar->scan.state) {
4721 case ATH10K_SCAN_IDLE:
4722 reinit_completion(&ar->scan.started);
4723 reinit_completion(&ar->scan.completed);
4724 ar->scan.state = ATH10K_SCAN_STARTING;
4725 ar->scan.is_roc = false;
4726 ar->scan.vdev_id = arvif->vdev_id;
4729 case ATH10K_SCAN_STARTING:
4730 case ATH10K_SCAN_RUNNING:
4731 case ATH10K_SCAN_ABORTING:
4735 spin_unlock_bh(&ar->data_lock);
4740 memset(&arg, 0, sizeof(arg));
4741 ath10k_wmi_start_scan_init(ar, &arg);
4742 arg.vdev_id = arvif->vdev_id;
4743 arg.scan_id = ATH10K_SCAN_ID;
4746 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
4749 arg.ie_len = req->ie_len;
4750 memcpy(arg.ie, req->ie, arg.ie_len);
4754 arg.n_ssids = req->n_ssids;
4755 for (i = 0; i < arg.n_ssids; i++) {
4756 arg.ssids[i].len = req->ssids[i].ssid_len;
4757 arg.ssids[i].ssid = req->ssids[i].ssid;
4760 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4763 if (req->n_channels) {
4764 arg.n_channels = req->n_channels;
4765 for (i = 0; i < arg.n_channels; i++)
4766 arg.channels[i] = req->channels[i]->center_freq;
4769 ret = ath10k_start_scan(ar, &arg);
4771 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
4772 spin_lock_bh(&ar->data_lock);
4773 ar->scan.state = ATH10K_SCAN_IDLE;
4774 spin_unlock_bh(&ar->data_lock);
4778 mutex_unlock(&ar->conf_mutex);
4782 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4783 struct ieee80211_vif *vif)
4785 struct ath10k *ar = hw->priv;
4787 mutex_lock(&ar->conf_mutex);
4788 ath10k_scan_abort(ar);
4789 mutex_unlock(&ar->conf_mutex);
4791 cancel_delayed_work_sync(&ar->scan.timeout);
4794 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4795 struct ath10k_vif *arvif,
4796 enum set_key_cmd cmd,
4797 struct ieee80211_key_conf *key)
4799 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4802 /* 10.1 firmware branch requires default key index to be set to group
4803 * key index after installing it. Otherwise FW/HW Txes corrupted
4804 * frames with multi-vif APs. This is not required for main firmware
4805 * branch (e.g. 636).
4807 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4809 * FIXME: It remains unknown if this is required for multi-vif STA
4810 * interfaces on 10.1.
4813 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4814 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4817 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4820 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4823 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4829 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4832 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
4833 arvif->vdev_id, ret);
4836 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4837 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4838 struct ieee80211_key_conf *key)
4840 struct ath10k *ar = hw->priv;
4841 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4842 struct ath10k_peer *peer;
4843 const u8 *peer_addr;
4844 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4845 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4851 /* this one needs to be done in software */
4852 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4855 if (key->keyidx > WMI_MAX_KEY_INDEX)
4858 mutex_lock(&ar->conf_mutex);
4861 peer_addr = sta->addr;
4862 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4863 peer_addr = vif->bss_conf.bssid;
4865 peer_addr = vif->addr;
4867 key->hw_key_idx = key->keyidx;
4871 arvif->wep_keys[key->keyidx] = key;
4873 arvif->wep_keys[key->keyidx] = NULL;
4876 /* the peer should not disappear in mid-way (unless FW goes awry) since
4877 * we already hold conf_mutex. we just make sure its there now. */
4878 spin_lock_bh(&ar->data_lock);
4879 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4880 spin_unlock_bh(&ar->data_lock);
4883 if (cmd == SET_KEY) {
4884 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
4889 /* if the peer doesn't exist there is no key to disable
4895 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4896 flags |= WMI_KEY_PAIRWISE;
4898 flags |= WMI_KEY_GROUP;
4901 if (cmd == DISABLE_KEY)
4902 ath10k_clear_vdev_key(arvif, key);
4904 /* When WEP keys are uploaded it's possible that there are
4905 * stations associated already (e.g. when merging) without any
4906 * keys. Static WEP needs an explicit per-peer key upload.
4908 if (vif->type == NL80211_IFTYPE_ADHOC &&
4910 ath10k_mac_vif_update_wep_key(arvif, key);
4912 /* 802.1x never sets the def_wep_key_idx so each set_key()
4913 * call changes default tx key.
4915 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4916 * after first set_key().
4918 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4919 flags |= WMI_KEY_TX_USAGE;
4922 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
4924 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
4925 arvif->vdev_id, peer_addr, ret);
4929 /* mac80211 sets static WEP keys as groupwise while firmware requires
4930 * them to be installed twice as both pairwise and groupwise.
4932 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4934 flags2 &= ~WMI_KEY_GROUP;
4935 flags2 |= WMI_KEY_PAIRWISE;
4937 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4939 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4940 arvif->vdev_id, peer_addr, ret);
4941 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4944 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4945 arvif->vdev_id, peer_addr, ret2);
4950 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4952 spin_lock_bh(&ar->data_lock);
4953 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4954 if (peer && cmd == SET_KEY)
4955 peer->keys[key->keyidx] = key;
4956 else if (peer && cmd == DISABLE_KEY)
4957 peer->keys[key->keyidx] = NULL;
4958 else if (peer == NULL)
4959 /* impossible unless FW goes crazy */
4960 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
4961 spin_unlock_bh(&ar->data_lock);
4964 mutex_unlock(&ar->conf_mutex);
4968 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4969 struct ieee80211_vif *vif,
4972 struct ath10k *ar = hw->priv;
4973 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4976 mutex_lock(&arvif->ar->conf_mutex);
4978 if (arvif->ar->state != ATH10K_STATE_ON)
4981 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4982 arvif->vdev_id, keyidx);
4984 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4986 arvif->ar->wmi.vdev_param->def_keyid,
4990 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4996 arvif->def_wep_key_idx = keyidx;
4999 mutex_unlock(&arvif->ar->conf_mutex);
5002 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5005 struct ath10k_vif *arvif;
5006 struct ath10k_sta *arsta;
5007 struct ieee80211_sta *sta;
5008 struct cfg80211_chan_def def;
5009 enum ieee80211_band band;
5010 const u8 *ht_mcs_mask;
5011 const u16 *vht_mcs_mask;
5012 u32 changed, bw, nss, smps;
5015 arsta = container_of(wk, struct ath10k_sta, update_wk);
5016 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5017 arvif = arsta->arvif;
5020 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5023 band = def.chan->band;
5024 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5025 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5027 spin_lock_bh(&ar->data_lock);
5029 changed = arsta->changed;
5036 spin_unlock_bh(&ar->data_lock);
5038 mutex_lock(&ar->conf_mutex);
5040 nss = max_t(u32, 1, nss);
5041 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5042 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5044 if (changed & IEEE80211_RC_BW_CHANGED) {
5045 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5048 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5049 WMI_PEER_CHAN_WIDTH, bw);
5051 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5052 sta->addr, bw, err);
5055 if (changed & IEEE80211_RC_NSS_CHANGED) {
5056 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5059 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5062 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5063 sta->addr, nss, err);
5066 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5067 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5070 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5071 WMI_PEER_SMPS_STATE, smps);
5073 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5074 sta->addr, smps, err);
5077 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5078 changed & IEEE80211_RC_NSS_CHANGED) {
5079 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
5082 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5084 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5088 mutex_unlock(&ar->conf_mutex);
5091 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5092 struct ieee80211_sta *sta)
5094 struct ath10k *ar = arvif->ar;
5096 lockdep_assert_held(&ar->conf_mutex);
5098 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5101 if (ar->num_stations >= ar->max_num_stations)
5109 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5110 struct ieee80211_sta *sta)
5112 struct ath10k *ar = arvif->ar;
5114 lockdep_assert_held(&ar->conf_mutex);
5116 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5122 struct ath10k_mac_tdls_iter_data {
5123 u32 num_tdls_stations;
5124 struct ieee80211_vif *curr_vif;
5127 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5128 struct ieee80211_sta *sta)
5130 struct ath10k_mac_tdls_iter_data *iter_data = data;
5131 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5132 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5134 if (sta->tdls && sta_vif == iter_data->curr_vif)
5135 iter_data->num_tdls_stations++;
5138 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5139 struct ieee80211_vif *vif)
5141 struct ath10k_mac_tdls_iter_data data = {};
5143 data.curr_vif = vif;
5145 ieee80211_iterate_stations_atomic(hw,
5146 ath10k_mac_tdls_vif_stations_count_iter,
5148 return data.num_tdls_stations;
5151 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5152 struct ieee80211_vif *vif)
5154 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5155 int *num_tdls_vifs = data;
5157 if (vif->type != NL80211_IFTYPE_STATION)
5160 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5164 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5166 int num_tdls_vifs = 0;
5168 ieee80211_iterate_active_interfaces_atomic(hw,
5169 IEEE80211_IFACE_ITER_NORMAL,
5170 ath10k_mac_tdls_vifs_count_iter,
5172 return num_tdls_vifs;
5175 static int ath10k_sta_state(struct ieee80211_hw *hw,
5176 struct ieee80211_vif *vif,
5177 struct ieee80211_sta *sta,
5178 enum ieee80211_sta_state old_state,
5179 enum ieee80211_sta_state new_state)
5181 struct ath10k *ar = hw->priv;
5182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5183 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5186 if (old_state == IEEE80211_STA_NOTEXIST &&
5187 new_state == IEEE80211_STA_NONE) {
5188 memset(arsta, 0, sizeof(*arsta));
5189 arsta->arvif = arvif;
5190 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5193 /* cancel must be done outside the mutex to avoid deadlock */
5194 if ((old_state == IEEE80211_STA_NONE &&
5195 new_state == IEEE80211_STA_NOTEXIST))
5196 cancel_work_sync(&arsta->update_wk);
5198 mutex_lock(&ar->conf_mutex);
5200 if (old_state == IEEE80211_STA_NOTEXIST &&
5201 new_state == IEEE80211_STA_NONE) {
5203 * New station addition.
5205 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5206 u32 num_tdls_stations;
5209 ath10k_dbg(ar, ATH10K_DBG_MAC,
5210 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5211 arvif->vdev_id, sta->addr,
5212 ar->num_stations + 1, ar->max_num_stations,
5213 ar->num_peers + 1, ar->max_num_peers);
5215 ret = ath10k_mac_inc_num_stations(arvif, sta);
5217 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5218 ar->max_num_stations);
5223 peer_type = WMI_PEER_TYPE_TDLS;
5225 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
5228 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5229 sta->addr, arvif->vdev_id, ret);
5230 ath10k_mac_dec_num_stations(arvif, sta);
5237 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5238 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5240 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5241 num_tdls_stations == 0) {
5242 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5243 arvif->vdev_id, ar->max_num_tdls_vdevs);
5244 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5245 ath10k_mac_dec_num_stations(arvif, sta);
5250 if (num_tdls_stations == 0) {
5251 /* This is the first tdls peer in current vif */
5252 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5254 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5257 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5258 arvif->vdev_id, ret);
5259 ath10k_peer_delete(ar, arvif->vdev_id,
5261 ath10k_mac_dec_num_stations(arvif, sta);
5266 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5267 WMI_TDLS_PEER_STATE_PEERING);
5270 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5271 sta->addr, arvif->vdev_id, ret);
5272 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5273 ath10k_mac_dec_num_stations(arvif, sta);
5275 if (num_tdls_stations != 0)
5277 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5280 } else if ((old_state == IEEE80211_STA_NONE &&
5281 new_state == IEEE80211_STA_NOTEXIST)) {
5283 * Existing station deletion.
5285 ath10k_dbg(ar, ATH10K_DBG_MAC,
5286 "mac vdev %d peer delete %pM (sta gone)\n",
5287 arvif->vdev_id, sta->addr);
5289 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5291 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
5292 sta->addr, arvif->vdev_id, ret);
5294 ath10k_mac_dec_num_stations(arvif, sta);
5299 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5302 /* This was the last tdls peer in current vif */
5303 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5306 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5307 arvif->vdev_id, ret);
5309 } else if (old_state == IEEE80211_STA_AUTH &&
5310 new_state == IEEE80211_STA_ASSOC &&
5311 (vif->type == NL80211_IFTYPE_AP ||
5312 vif->type == NL80211_IFTYPE_ADHOC)) {
5316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
5319 ret = ath10k_station_assoc(ar, vif, sta, false);
5321 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
5322 sta->addr, arvif->vdev_id, ret);
5323 } else if (old_state == IEEE80211_STA_ASSOC &&
5324 new_state == IEEE80211_STA_AUTHORIZED &&
5327 * Tdls station authorized.
5329 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5332 ret = ath10k_station_assoc(ar, vif, sta, false);
5334 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5335 sta->addr, arvif->vdev_id, ret);
5339 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5340 WMI_TDLS_PEER_STATE_CONNECTED);
5342 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5343 sta->addr, arvif->vdev_id, ret);
5344 } else if (old_state == IEEE80211_STA_ASSOC &&
5345 new_state == IEEE80211_STA_AUTH &&
5346 (vif->type == NL80211_IFTYPE_AP ||
5347 vif->type == NL80211_IFTYPE_ADHOC)) {
5351 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
5354 ret = ath10k_station_disassoc(ar, vif, sta);
5356 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
5357 sta->addr, arvif->vdev_id, ret);
5360 mutex_unlock(&ar->conf_mutex);
5364 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
5365 u16 ac, bool enable)
5367 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5368 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5369 u32 prio = 0, acc = 0;
5373 lockdep_assert_held(&ar->conf_mutex);
5375 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5379 case IEEE80211_AC_VO:
5380 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5381 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
5385 case IEEE80211_AC_VI:
5386 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5387 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
5391 case IEEE80211_AC_BE:
5392 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5393 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
5397 case IEEE80211_AC_BK:
5398 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5399 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
5406 arvif->u.sta.uapsd |= value;
5408 arvif->u.sta.uapsd &= ~value;
5410 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5411 WMI_STA_PS_PARAM_UAPSD,
5412 arvif->u.sta.uapsd);
5414 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
5418 if (arvif->u.sta.uapsd)
5419 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5421 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5423 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5424 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5427 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
5429 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5431 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5432 arvif->vdev_id, ret);
5436 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5438 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5439 arvif->vdev_id, ret);
5443 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5444 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5445 /* Only userspace can make an educated decision when to send
5446 * trigger frame. The following effectively disables u-UAPSD
5447 * autotrigger in firmware (which is enabled by default
5448 * provided the autotrigger service is available).
5452 arg.user_priority = prio;
5453 arg.service_interval = 0;
5454 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5455 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5457 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5458 arvif->bssid, &arg, 1);
5460 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5470 static int ath10k_conf_tx(struct ieee80211_hw *hw,
5471 struct ieee80211_vif *vif, u16 ac,
5472 const struct ieee80211_tx_queue_params *params)
5474 struct ath10k *ar = hw->priv;
5475 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5476 struct wmi_wmm_params_arg *p = NULL;
5479 mutex_lock(&ar->conf_mutex);
5482 case IEEE80211_AC_VO:
5483 p = &arvif->wmm_params.ac_vo;
5485 case IEEE80211_AC_VI:
5486 p = &arvif->wmm_params.ac_vi;
5488 case IEEE80211_AC_BE:
5489 p = &arvif->wmm_params.ac_be;
5491 case IEEE80211_AC_BK:
5492 p = &arvif->wmm_params.ac_bk;
5501 p->cwmin = params->cw_min;
5502 p->cwmax = params->cw_max;
5503 p->aifs = params->aifs;
5506 * The channel time duration programmed in the HW is in absolute
5507 * microseconds, while mac80211 gives the txop in units of
5510 p->txop = params->txop * 32;
5512 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5513 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5514 &arvif->wmm_params);
5516 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5517 arvif->vdev_id, ret);
5521 /* This won't work well with multi-interface cases but it's
5522 * better than nothing.
5524 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5526 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5531 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5533 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
5536 mutex_unlock(&ar->conf_mutex);
5540 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5542 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5543 struct ieee80211_vif *vif,
5544 struct ieee80211_channel *chan,
5546 enum ieee80211_roc_type type)
5548 struct ath10k *ar = hw->priv;
5549 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5550 struct wmi_start_scan_arg arg;
5554 mutex_lock(&ar->conf_mutex);
5556 spin_lock_bh(&ar->data_lock);
5557 switch (ar->scan.state) {
5558 case ATH10K_SCAN_IDLE:
5559 reinit_completion(&ar->scan.started);
5560 reinit_completion(&ar->scan.completed);
5561 reinit_completion(&ar->scan.on_channel);
5562 ar->scan.state = ATH10K_SCAN_STARTING;
5563 ar->scan.is_roc = true;
5564 ar->scan.vdev_id = arvif->vdev_id;
5565 ar->scan.roc_freq = chan->center_freq;
5568 case ATH10K_SCAN_STARTING:
5569 case ATH10K_SCAN_RUNNING:
5570 case ATH10K_SCAN_ABORTING:
5574 spin_unlock_bh(&ar->data_lock);
5579 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
5581 memset(&arg, 0, sizeof(arg));
5582 ath10k_wmi_start_scan_init(ar, &arg);
5583 arg.vdev_id = arvif->vdev_id;
5584 arg.scan_id = ATH10K_SCAN_ID;
5586 arg.channels[0] = chan->center_freq;
5587 arg.dwell_time_active = scan_time_msec;
5588 arg.dwell_time_passive = scan_time_msec;
5589 arg.max_scan_time = scan_time_msec;
5590 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5591 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5592 arg.burst_duration_ms = duration;
5594 ret = ath10k_start_scan(ar, &arg);
5596 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
5597 spin_lock_bh(&ar->data_lock);
5598 ar->scan.state = ATH10K_SCAN_IDLE;
5599 spin_unlock_bh(&ar->data_lock);
5603 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5605 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
5607 ret = ath10k_scan_stop(ar);
5609 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
5615 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5616 msecs_to_jiffies(duration));
5620 mutex_unlock(&ar->conf_mutex);
5624 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5626 struct ath10k *ar = hw->priv;
5628 mutex_lock(&ar->conf_mutex);
5629 ath10k_scan_abort(ar);
5630 mutex_unlock(&ar->conf_mutex);
5632 cancel_delayed_work_sync(&ar->scan.timeout);
5638 * Both RTS and Fragmentation threshold are interface-specific
5639 * in ath10k, but device-specific in mac80211.
5642 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5644 struct ath10k *ar = hw->priv;
5645 struct ath10k_vif *arvif;
5648 mutex_lock(&ar->conf_mutex);
5649 list_for_each_entry(arvif, &ar->arvifs, list) {
5650 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
5651 arvif->vdev_id, value);
5653 ret = ath10k_mac_set_rts(arvif, value);
5655 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5656 arvif->vdev_id, ret);
5660 mutex_unlock(&ar->conf_mutex);
5665 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5666 u32 queues, bool drop)
5668 struct ath10k *ar = hw->priv;
5672 /* mac80211 doesn't care if we really xmit queued frames or not
5673 * we'll collect those frames either way if we stop/delete vdevs */
5677 mutex_lock(&ar->conf_mutex);
5679 if (ar->state == ATH10K_STATE_WEDGED)
5682 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
5685 spin_lock_bh(&ar->htt.tx_lock);
5686 empty = (ar->htt.num_pending_tx == 0);
5687 spin_unlock_bh(&ar->htt.tx_lock);
5689 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5690 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5694 }), ATH10K_FLUSH_TIMEOUT_HZ);
5696 if (ret <= 0 || skip)
5697 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
5698 skip, ar->state, ret);
5701 mutex_unlock(&ar->conf_mutex);
5704 /* TODO: Implement this function properly
5705 * For now it is needed to reply to Probe Requests in IBSS mode.
5706 * Propably we need this information from FW.
5708 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5713 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5714 enum ieee80211_reconfig_type reconfig_type)
5716 struct ath10k *ar = hw->priv;
5718 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5721 mutex_lock(&ar->conf_mutex);
5723 /* If device failed to restart it will be in a different state, e.g.
5724 * ATH10K_STATE_WEDGED */
5725 if (ar->state == ATH10K_STATE_RESTARTED) {
5726 ath10k_info(ar, "device successfully recovered\n");
5727 ar->state = ATH10K_STATE_ON;
5728 ieee80211_wake_queues(ar->hw);
5731 mutex_unlock(&ar->conf_mutex);
5734 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5735 struct survey_info *survey)
5737 struct ath10k *ar = hw->priv;
5738 struct ieee80211_supported_band *sband;
5739 struct survey_info *ar_survey = &ar->survey[idx];
5742 mutex_lock(&ar->conf_mutex);
5744 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5745 if (sband && idx >= sband->n_channels) {
5746 idx -= sband->n_channels;
5751 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5753 if (!sband || idx >= sband->n_channels) {
5758 spin_lock_bh(&ar->data_lock);
5759 memcpy(survey, ar_survey, sizeof(*survey));
5760 spin_unlock_bh(&ar->data_lock);
5762 survey->channel = &sband->channels[idx];
5764 if (ar->rx_channel == survey->channel)
5765 survey->filled |= SURVEY_INFO_IN_USE;
5768 mutex_unlock(&ar->conf_mutex);
5773 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5774 enum ieee80211_band band,
5775 const struct cfg80211_bitrate_mask *mask)
5780 num_rates += hweight32(mask->control[band].legacy);
5782 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5783 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5785 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5786 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5788 return num_rates == 1;
5792 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5793 enum ieee80211_band band,
5794 const struct cfg80211_bitrate_mask *mask,
5797 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5798 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5800 u8 vht_nss_mask = 0;
5803 if (mask->control[band].legacy)
5806 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5807 if (mask->control[band].ht_mcs[i] == 0)
5809 else if (mask->control[band].ht_mcs[i] ==
5810 sband->ht_cap.mcs.rx_mask[i])
5811 ht_nss_mask |= BIT(i);
5816 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5817 if (mask->control[band].vht_mcs[i] == 0)
5819 else if (mask->control[band].vht_mcs[i] ==
5820 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5821 vht_nss_mask |= BIT(i);
5826 if (ht_nss_mask != vht_nss_mask)
5829 if (ht_nss_mask == 0)
5832 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5835 *nss = fls(ht_nss_mask);
5841 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5842 enum ieee80211_band band,
5843 const struct cfg80211_bitrate_mask *mask,
5846 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5853 if (hweight32(mask->control[band].legacy) == 1) {
5854 rate_idx = ffs(mask->control[band].legacy) - 1;
5856 hw_rate = sband->bitrates[rate_idx].hw_value;
5857 bitrate = sband->bitrates[rate_idx].bitrate;
5859 if (ath10k_mac_bitrate_is_cck(bitrate))
5860 preamble = WMI_RATE_PREAMBLE_CCK;
5862 preamble = WMI_RATE_PREAMBLE_OFDM;
5865 *rate = preamble << 6 |
5872 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5873 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5875 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5877 (ffs(mask->control[band].ht_mcs[i]) - 1);
5883 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5884 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5886 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5888 (ffs(mask->control[band].vht_mcs[i]) - 1);
5897 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5898 u8 rate, u8 nss, u8 sgi)
5900 struct ath10k *ar = arvif->ar;
5904 lockdep_assert_held(&ar->conf_mutex);
5906 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5907 arvif->vdev_id, rate, nss, sgi);
5909 vdev_param = ar->wmi.vdev_param->fixed_rate;
5910 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
5912 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
5917 vdev_param = ar->wmi.vdev_param->nss;
5918 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
5920 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5924 vdev_param = ar->wmi.vdev_param->sgi;
5925 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
5927 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5935 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5936 enum ieee80211_band band,
5937 const struct cfg80211_bitrate_mask *mask)
5942 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5943 * to express all VHT MCS rate masks. Effectively only the following
5944 * ranges can be used: none, 0-7, 0-8 and 0-9.
5946 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5947 vht_mcs = mask->control[band].vht_mcs[i];
5956 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5964 static void ath10k_mac_set_bitrate_mask_iter(void *data,
5965 struct ieee80211_sta *sta)
5967 struct ath10k_vif *arvif = data;
5968 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5969 struct ath10k *ar = arvif->ar;
5971 if (arsta->arvif != arvif)
5974 spin_lock_bh(&ar->data_lock);
5975 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5976 spin_unlock_bh(&ar->data_lock);
5978 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5981 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5982 struct ieee80211_vif *vif,
5983 const struct cfg80211_bitrate_mask *mask)
5985 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5986 struct cfg80211_chan_def def;
5987 struct ath10k *ar = arvif->ar;
5988 enum ieee80211_band band;
5989 const u8 *ht_mcs_mask;
5990 const u16 *vht_mcs_mask;
5997 if (ath10k_mac_vif_chan(vif, &def))
6000 band = def.chan->band;
6001 ht_mcs_mask = mask->control[band].ht_mcs;
6002 vht_mcs_mask = mask->control[band].vht_mcs;
6004 sgi = mask->control[band].gi;
6005 if (sgi == NL80211_TXRATE_FORCE_LGI)
6008 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6009 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6012 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6013 arvif->vdev_id, ret);
6016 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6018 rate = WMI_FIXED_RATE_NONE;
6021 rate = WMI_FIXED_RATE_NONE;
6022 nss = min(ar->num_rf_chains,
6023 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6024 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6026 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6029 mutex_lock(&ar->conf_mutex);
6031 arvif->bitrate_mask = *mask;
6032 ieee80211_iterate_stations_atomic(ar->hw,
6033 ath10k_mac_set_bitrate_mask_iter,
6036 mutex_unlock(&ar->conf_mutex);
6039 mutex_lock(&ar->conf_mutex);
6041 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
6043 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6044 arvif->vdev_id, ret);
6049 mutex_unlock(&ar->conf_mutex);
6054 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6055 struct ieee80211_vif *vif,
6056 struct ieee80211_sta *sta,
6059 struct ath10k *ar = hw->priv;
6060 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6063 spin_lock_bh(&ar->data_lock);
6065 ath10k_dbg(ar, ATH10K_DBG_MAC,
6066 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6067 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6070 if (changed & IEEE80211_RC_BW_CHANGED) {
6071 bw = WMI_PEER_CHWIDTH_20MHZ;
6073 switch (sta->bandwidth) {
6074 case IEEE80211_STA_RX_BW_20:
6075 bw = WMI_PEER_CHWIDTH_20MHZ;
6077 case IEEE80211_STA_RX_BW_40:
6078 bw = WMI_PEER_CHWIDTH_40MHZ;
6080 case IEEE80211_STA_RX_BW_80:
6081 bw = WMI_PEER_CHWIDTH_80MHZ;
6083 case IEEE80211_STA_RX_BW_160:
6084 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6085 sta->bandwidth, sta->addr);
6086 bw = WMI_PEER_CHWIDTH_20MHZ;
6093 if (changed & IEEE80211_RC_NSS_CHANGED)
6094 arsta->nss = sta->rx_nss;
6096 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6097 smps = WMI_PEER_SMPS_PS_NONE;
6099 switch (sta->smps_mode) {
6100 case IEEE80211_SMPS_AUTOMATIC:
6101 case IEEE80211_SMPS_OFF:
6102 smps = WMI_PEER_SMPS_PS_NONE;
6104 case IEEE80211_SMPS_STATIC:
6105 smps = WMI_PEER_SMPS_STATIC;
6107 case IEEE80211_SMPS_DYNAMIC:
6108 smps = WMI_PEER_SMPS_DYNAMIC;
6110 case IEEE80211_SMPS_NUM_MODES:
6111 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6112 sta->smps_mode, sta->addr);
6113 smps = WMI_PEER_SMPS_PS_NONE;
6120 arsta->changed |= changed;
6122 spin_unlock_bh(&ar->data_lock);
6124 ieee80211_queue_work(hw, &arsta->update_wk);
6127 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6130 * FIXME: Return 0 for time being. Need to figure out whether FW
6131 * has the API to fetch 64-bit local TSF
6137 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6138 struct ieee80211_vif *vif,
6139 enum ieee80211_ampdu_mlme_action action,
6140 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6143 struct ath10k *ar = hw->priv;
6144 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6147 arvif->vdev_id, sta->addr, tid, action);
6150 case IEEE80211_AMPDU_RX_START:
6151 case IEEE80211_AMPDU_RX_STOP:
6152 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6153 * creation/removal. Do we need to verify this?
6156 case IEEE80211_AMPDU_TX_START:
6157 case IEEE80211_AMPDU_TX_STOP_CONT:
6158 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6159 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6160 case IEEE80211_AMPDU_TX_OPERATIONAL:
6161 /* Firmware offloads Tx aggregation entirely so deny mac80211
6162 * Tx aggregation requests.
6171 ath10k_mac_update_rx_channel(struct ath10k *ar)
6173 struct cfg80211_chan_def *def = NULL;
6175 /* Both locks are required because ar->rx_channel is modified. This
6176 * allows readers to hold either lock.
6178 lockdep_assert_held(&ar->conf_mutex);
6179 lockdep_assert_held(&ar->data_lock);
6181 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6182 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6183 * ppdu on Rx may reduce performance on low-end systems. It should be
6184 * possible to make tables/hashmaps to speed the lookup up (be vary of
6185 * cpu data cache lines though regarding sizes) but to keep the initial
6186 * implementation simple and less intrusive fallback to the slow lookup
6187 * only for multi-channel cases. Single-channel cases will remain to
6188 * use the old channel derival and thus performance should not be
6192 if (ath10k_mac_num_chanctxs(ar) == 1) {
6193 ieee80211_iter_chan_contexts_atomic(ar->hw,
6194 ath10k_mac_get_any_chandef_iter,
6196 ar->rx_channel = def->chan;
6198 ar->rx_channel = NULL;
6204 ath10k_mac_chan_ctx_init(struct ath10k *ar,
6205 struct ath10k_chanctx *arctx,
6206 struct ieee80211_chanctx_conf *conf)
6208 lockdep_assert_held(&ar->conf_mutex);
6209 lockdep_assert_held(&ar->data_lock);
6211 memset(arctx, 0, sizeof(*arctx));
6213 arctx->conf = *conf;
6217 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6218 struct ieee80211_chanctx_conf *ctx)
6220 struct ath10k *ar = hw->priv;
6221 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6223 ath10k_dbg(ar, ATH10K_DBG_MAC,
6224 "mac chanctx add freq %hu width %d ptr %p\n",
6225 ctx->def.chan->center_freq, ctx->def.width, ctx);
6227 mutex_lock(&ar->conf_mutex);
6229 spin_lock_bh(&ar->data_lock);
6230 ath10k_mac_chan_ctx_init(ar, arctx, ctx);
6231 ath10k_mac_update_rx_channel(ar);
6232 spin_unlock_bh(&ar->data_lock);
6234 ath10k_recalc_radar_detection(ar);
6235 ath10k_monitor_recalc(ar);
6237 mutex_unlock(&ar->conf_mutex);
6243 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6244 struct ieee80211_chanctx_conf *ctx)
6246 struct ath10k *ar = hw->priv;
6248 ath10k_dbg(ar, ATH10K_DBG_MAC,
6249 "mac chanctx remove freq %hu width %d ptr %p\n",
6250 ctx->def.chan->center_freq, ctx->def.width, ctx);
6252 mutex_lock(&ar->conf_mutex);
6254 spin_lock_bh(&ar->data_lock);
6255 ath10k_mac_update_rx_channel(ar);
6256 spin_unlock_bh(&ar->data_lock);
6258 ath10k_recalc_radar_detection(ar);
6259 ath10k_monitor_recalc(ar);
6261 mutex_unlock(&ar->conf_mutex);
6265 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6266 struct ieee80211_chanctx_conf *ctx,
6269 struct ath10k *ar = hw->priv;
6270 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6272 mutex_lock(&ar->conf_mutex);
6274 ath10k_dbg(ar, ATH10K_DBG_MAC,
6275 "mac chanctx change freq %hu->%hu width %d->%d ptr %p changed %x\n",
6276 arctx->conf.def.chan->center_freq,
6277 ctx->def.chan->center_freq,
6278 arctx->conf.def.width, ctx->def.width,
6281 /* This shouldn't really happen because channel switching should use
6282 * switch_vif_chanctx().
6284 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6287 spin_lock_bh(&ar->data_lock);
6289 spin_unlock_bh(&ar->data_lock);
6291 ath10k_recalc_radar_detection(ar);
6293 /* FIXME: How to configure Rx chains properly? */
6295 /* No other actions are actually necessary. Firmware maintains channel
6296 * definitions per vdev internally and there's no host-side channel
6297 * context abstraction to configure, e.g. channel width.
6301 mutex_unlock(&ar->conf_mutex);
6305 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6306 struct ieee80211_vif *vif,
6307 struct ieee80211_chanctx_conf *ctx)
6309 struct ath10k *ar = hw->priv;
6310 struct ath10k_chanctx *arctx = (void *)ctx->drv_priv;
6311 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6314 mutex_lock(&ar->conf_mutex);
6316 ath10k_dbg(ar, ATH10K_DBG_MAC,
6317 "mac chanctx assign ptr %p vdev_id %i\n",
6318 ctx, arvif->vdev_id);
6320 if (WARN_ON(arvif->is_started)) {
6321 mutex_unlock(&ar->conf_mutex);
6325 ret = ath10k_vdev_start(arvif, &arctx->conf.def);
6327 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6328 arvif->vdev_id, vif->addr,
6329 arctx->conf.def.chan->center_freq, ret);
6333 arvif->is_started = true;
6335 if (vif->type == NL80211_IFTYPE_MONITOR) {
6336 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6338 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6339 arvif->vdev_id, ret);
6343 arvif->is_up = true;
6346 mutex_unlock(&ar->conf_mutex);
6350 ath10k_vdev_stop(arvif);
6351 arvif->is_started = false;
6354 mutex_unlock(&ar->conf_mutex);
6359 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6360 struct ieee80211_vif *vif,
6361 struct ieee80211_chanctx_conf *ctx)
6363 struct ath10k *ar = hw->priv;
6364 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6367 mutex_lock(&ar->conf_mutex);
6369 ath10k_dbg(ar, ATH10K_DBG_MAC,
6370 "mac chanctx unassign ptr %p vdev_id %i\n",
6371 ctx, arvif->vdev_id);
6373 WARN_ON(!arvif->is_started);
6375 if (vif->type == NL80211_IFTYPE_MONITOR) {
6376 WARN_ON(!arvif->is_up);
6378 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6380 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6381 arvif->vdev_id, ret);
6383 arvif->is_up = false;
6386 ret = ath10k_vdev_stop(arvif);
6388 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6389 arvif->vdev_id, ret);
6391 arvif->is_started = false;
6393 mutex_unlock(&ar->conf_mutex);
6397 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6398 struct ieee80211_vif_chanctx_switch *vifs,
6400 enum ieee80211_chanctx_switch_mode mode)
6402 struct ath10k *ar = hw->priv;
6403 struct ath10k_vif *arvif;
6404 struct ath10k_chanctx *arctx_new, *arctx_old;
6407 mutex_lock(&ar->conf_mutex);
6409 ath10k_dbg(ar, ATH10K_DBG_MAC,
6410 "mac chanctx switch n_vifs %d mode %d\n",
6413 spin_lock_bh(&ar->data_lock);
6414 for (i = 0; i < n_vifs; i++) {
6415 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6416 arctx_new = (void *)vifs[i].new_ctx->drv_priv;
6417 arctx_old = (void *)vifs[i].old_ctx->drv_priv;
6419 ath10k_dbg(ar, ATH10K_DBG_MAC,
6420 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d ptr %p->%p\n",
6422 vifs[i].old_ctx->def.chan->center_freq,
6423 vifs[i].new_ctx->def.chan->center_freq,
6424 vifs[i].old_ctx->def.width,
6425 vifs[i].new_ctx->def.width,
6426 arctx_old, arctx_new);
6428 if (mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
6429 ath10k_mac_chan_ctx_init(ar, arctx_new,
6433 arctx_new->conf = *vifs[i].new_ctx;
6435 /* FIXME: ath10k_mac_chan_reconfigure() uses current, i.e. not
6436 * yet updated chanctx_conf pointer.
6438 arctx_old->conf = *vifs[i].new_ctx;
6440 ath10k_mac_update_rx_channel(ar);
6441 spin_unlock_bh(&ar->data_lock);
6443 /* FIXME: Reconfigure only affected vifs */
6444 ath10k_mac_chan_reconfigure(ar);
6446 mutex_unlock(&ar->conf_mutex);
6450 static const struct ieee80211_ops ath10k_ops = {
6452 .start = ath10k_start,
6453 .stop = ath10k_stop,
6454 .config = ath10k_config,
6455 .add_interface = ath10k_add_interface,
6456 .remove_interface = ath10k_remove_interface,
6457 .configure_filter = ath10k_configure_filter,
6458 .bss_info_changed = ath10k_bss_info_changed,
6459 .hw_scan = ath10k_hw_scan,
6460 .cancel_hw_scan = ath10k_cancel_hw_scan,
6461 .set_key = ath10k_set_key,
6462 .set_default_unicast_key = ath10k_set_default_unicast_key,
6463 .sta_state = ath10k_sta_state,
6464 .conf_tx = ath10k_conf_tx,
6465 .remain_on_channel = ath10k_remain_on_channel,
6466 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6467 .set_rts_threshold = ath10k_set_rts_threshold,
6468 .flush = ath10k_flush,
6469 .tx_last_beacon = ath10k_tx_last_beacon,
6470 .set_antenna = ath10k_set_antenna,
6471 .get_antenna = ath10k_get_antenna,
6472 .reconfig_complete = ath10k_reconfig_complete,
6473 .get_survey = ath10k_get_survey,
6474 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
6475 .sta_rc_update = ath10k_sta_rc_update,
6476 .get_tsf = ath10k_get_tsf,
6477 .ampdu_action = ath10k_ampdu_action,
6478 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6479 .get_et_stats = ath10k_debug_get_et_stats,
6480 .get_et_strings = ath10k_debug_get_et_strings,
6481 .add_chanctx = ath10k_mac_op_add_chanctx,
6482 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6483 .change_chanctx = ath10k_mac_op_change_chanctx,
6484 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6485 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6486 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
6488 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6491 .suspend = ath10k_wow_op_suspend,
6492 .resume = ath10k_wow_op_resume,
6494 #ifdef CONFIG_MAC80211_DEBUGFS
6495 .sta_add_debugfs = ath10k_sta_add_debugfs,
6499 #define CHAN2G(_channel, _freq, _flags) { \
6500 .band = IEEE80211_BAND_2GHZ, \
6501 .hw_value = (_channel), \
6502 .center_freq = (_freq), \
6503 .flags = (_flags), \
6504 .max_antenna_gain = 0, \
6508 #define CHAN5G(_channel, _freq, _flags) { \
6509 .band = IEEE80211_BAND_5GHZ, \
6510 .hw_value = (_channel), \
6511 .center_freq = (_freq), \
6512 .flags = (_flags), \
6513 .max_antenna_gain = 0, \
6517 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6527 CHAN2G(10, 2457, 0),
6528 CHAN2G(11, 2462, 0),
6529 CHAN2G(12, 2467, 0),
6530 CHAN2G(13, 2472, 0),
6531 CHAN2G(14, 2484, 0),
6534 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
6535 CHAN5G(36, 5180, 0),
6536 CHAN5G(40, 5200, 0),
6537 CHAN5G(44, 5220, 0),
6538 CHAN5G(48, 5240, 0),
6539 CHAN5G(52, 5260, 0),
6540 CHAN5G(56, 5280, 0),
6541 CHAN5G(60, 5300, 0),
6542 CHAN5G(64, 5320, 0),
6543 CHAN5G(100, 5500, 0),
6544 CHAN5G(104, 5520, 0),
6545 CHAN5G(108, 5540, 0),
6546 CHAN5G(112, 5560, 0),
6547 CHAN5G(116, 5580, 0),
6548 CHAN5G(120, 5600, 0),
6549 CHAN5G(124, 5620, 0),
6550 CHAN5G(128, 5640, 0),
6551 CHAN5G(132, 5660, 0),
6552 CHAN5G(136, 5680, 0),
6553 CHAN5G(140, 5700, 0),
6554 CHAN5G(144, 5720, 0),
6555 CHAN5G(149, 5745, 0),
6556 CHAN5G(153, 5765, 0),
6557 CHAN5G(157, 5785, 0),
6558 CHAN5G(161, 5805, 0),
6559 CHAN5G(165, 5825, 0),
6562 struct ath10k *ath10k_mac_create(size_t priv_size)
6564 struct ieee80211_hw *hw;
6567 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
6577 void ath10k_mac_destroy(struct ath10k *ar)
6579 ieee80211_free_hw(ar->hw);
6582 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6585 .types = BIT(NL80211_IFTYPE_STATION)
6586 | BIT(NL80211_IFTYPE_P2P_CLIENT)
6590 .types = BIT(NL80211_IFTYPE_P2P_GO)
6594 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6598 .types = BIT(NL80211_IFTYPE_AP)
6602 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
6605 .types = BIT(NL80211_IFTYPE_AP)
6609 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6611 .limits = ath10k_if_limits,
6612 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6613 .max_interfaces = 8,
6614 .num_different_channels = 1,
6615 .beacon_int_infra_match = true,
6619 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
6621 .limits = ath10k_10x_if_limits,
6622 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
6623 .max_interfaces = 8,
6624 .num_different_channels = 1,
6625 .beacon_int_infra_match = true,
6626 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6627 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6628 BIT(NL80211_CHAN_WIDTH_20) |
6629 BIT(NL80211_CHAN_WIDTH_40) |
6630 BIT(NL80211_CHAN_WIDTH_80),
6635 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6638 .types = BIT(NL80211_IFTYPE_STATION) |
6639 BIT(NL80211_IFTYPE_AP) |
6640 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6641 BIT(NL80211_IFTYPE_P2P_GO),
6645 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6649 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6652 .types = BIT(NL80211_IFTYPE_STATION),
6656 .types = BIT(NL80211_IFTYPE_ADHOC),
6660 /* FIXME: This is not thouroughly tested. These combinations may over- or
6661 * underestimate hw/fw capabilities.
6663 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6665 .limits = ath10k_tlv_if_limit,
6666 .num_different_channels = 1,
6667 .max_interfaces = 3,
6668 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6671 .limits = ath10k_tlv_if_limit_ibss,
6672 .num_different_channels = 1,
6673 .max_interfaces = 2,
6674 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6678 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6680 .limits = ath10k_tlv_if_limit,
6681 .num_different_channels = 2,
6682 .max_interfaces = 3,
6683 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6686 .limits = ath10k_tlv_if_limit_ibss,
6687 .num_different_channels = 1,
6688 .max_interfaces = 2,
6689 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6693 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6695 struct ieee80211_sta_vht_cap vht_cap = {0};
6700 vht_cap.vht_supported = 1;
6701 vht_cap.cap = ar->vht_cap_info;
6703 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6704 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6705 val = ar->num_rf_chains - 1;
6706 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6707 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6712 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6713 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6714 val = ar->num_rf_chains - 1;
6715 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6716 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6722 for (i = 0; i < 8; i++) {
6723 if (i < ar->num_rf_chains)
6724 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6726 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6729 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6730 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6735 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6738 struct ieee80211_sta_ht_cap ht_cap = {0};
6740 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6743 ht_cap.ht_supported = 1;
6744 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6745 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6746 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6747 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6748 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6750 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6751 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6753 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6754 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6756 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6759 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6760 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6765 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6766 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6768 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6771 stbc = ar->ht_cap_info;
6772 stbc &= WMI_HT_CAP_RX_STBC;
6773 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6774 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6775 stbc &= IEEE80211_HT_CAP_RX_STBC;
6780 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6781 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6783 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6784 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6786 /* max AMSDU is implicitly taken from vht_cap_info */
6787 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6788 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6790 for (i = 0; i < ar->num_rf_chains; i++)
6791 ht_cap.mcs.rx_mask[i] = 0xFF;
6793 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6798 static void ath10k_get_arvif_iter(void *data, u8 *mac,
6799 struct ieee80211_vif *vif)
6801 struct ath10k_vif_iter *arvif_iter = data;
6802 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6804 if (arvif->vdev_id == arvif_iter->vdev_id)
6805 arvif_iter->arvif = arvif;
6808 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6810 struct ath10k_vif_iter arvif_iter;
6813 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6814 arvif_iter.vdev_id = vdev_id;
6816 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6817 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6819 ath10k_get_arvif_iter,
6821 if (!arvif_iter.arvif) {
6822 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
6826 return arvif_iter.arvif;
6829 int ath10k_mac_register(struct ath10k *ar)
6831 static const u32 cipher_suites[] = {
6832 WLAN_CIPHER_SUITE_WEP40,
6833 WLAN_CIPHER_SUITE_WEP104,
6834 WLAN_CIPHER_SUITE_TKIP,
6835 WLAN_CIPHER_SUITE_CCMP,
6836 WLAN_CIPHER_SUITE_AES_CMAC,
6838 struct ieee80211_supported_band *band;
6839 struct ieee80211_sta_vht_cap vht_cap;
6840 struct ieee80211_sta_ht_cap ht_cap;
6844 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6846 SET_IEEE80211_DEV(ar->hw, ar->dev);
6848 ht_cap = ath10k_get_ht_cap(ar);
6849 vht_cap = ath10k_create_vht_cap(ar);
6851 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6852 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6855 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6856 channels = kmemdup(ath10k_2ghz_channels,
6857 sizeof(ath10k_2ghz_channels),
6864 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6865 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6866 band->channels = channels;
6867 band->n_bitrates = ath10k_g_rates_size;
6868 band->bitrates = ath10k_g_rates;
6869 band->ht_cap = ht_cap;
6871 /* Enable the VHT support at 2.4 GHz */
6872 band->vht_cap = vht_cap;
6874 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6877 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6878 channels = kmemdup(ath10k_5ghz_channels,
6879 sizeof(ath10k_5ghz_channels),
6886 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6887 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6888 band->channels = channels;
6889 band->n_bitrates = ath10k_a_rates_size;
6890 band->bitrates = ath10k_a_rates;
6891 band->ht_cap = ht_cap;
6892 band->vht_cap = vht_cap;
6893 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6896 ar->hw->wiphy->interface_modes =
6897 BIT(NL80211_IFTYPE_STATION) |
6898 BIT(NL80211_IFTYPE_AP);
6900 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6901 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6903 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6904 ar->hw->wiphy->interface_modes |=
6905 BIT(NL80211_IFTYPE_P2P_DEVICE) |
6906 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6907 BIT(NL80211_IFTYPE_P2P_GO);
6909 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
6910 IEEE80211_HW_SUPPORTS_PS |
6911 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
6912 IEEE80211_HW_MFP_CAPABLE |
6913 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
6914 IEEE80211_HW_HAS_RATE_CONTROL |
6915 IEEE80211_HW_AP_LINK_PS |
6916 IEEE80211_HW_SPECTRUM_MGMT |
6917 IEEE80211_HW_SW_CRYPTO_CONTROL |
6918 IEEE80211_HW_CONNECTION_MONITOR |
6919 IEEE80211_HW_SUPPORTS_PER_STA_GTK |
6920 IEEE80211_HW_WANT_MONITOR_VIF |
6921 IEEE80211_HW_CHANCTX_STA_CSA |
6922 IEEE80211_HW_QUEUE_CONTROL;
6924 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6925 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
6927 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
6928 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
6930 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6931 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
6932 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
6935 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6936 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6938 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
6939 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
6940 ar->hw->chanctx_data_size = sizeof(struct ath10k_chanctx);
6942 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6944 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6945 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6947 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6948 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6949 * correct Probe Responses. This is more of a hack advert..
6951 ar->hw->wiphy->probe_resp_offload |=
6952 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6953 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6954 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6957 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6958 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6960 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6961 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
6962 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6964 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
6965 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6967 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6969 ret = ath10k_wow_init(ar);
6971 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6976 * on LL hardware queues are managed entirely by the FW
6977 * so we only advertise to mac we can do the queues thing
6979 ar->hw->queues = IEEE80211_MAX_QUEUES;
6981 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6982 * something that vdev_ids can't reach so that we don't stop the queue
6985 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
6987 switch (ar->wmi.op_version) {
6988 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6989 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6990 ar->hw->wiphy->n_iface_combinations =
6991 ARRAY_SIZE(ath10k_if_comb);
6992 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6994 case ATH10K_FW_WMI_OP_VERSION_TLV:
6995 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6996 ar->hw->wiphy->iface_combinations =
6997 ath10k_tlv_qcs_if_comb;
6998 ar->hw->wiphy->n_iface_combinations =
6999 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7001 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7002 ar->hw->wiphy->n_iface_combinations =
7003 ARRAY_SIZE(ath10k_tlv_if_comb);
7005 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7007 case ATH10K_FW_WMI_OP_VERSION_10_1:
7008 case ATH10K_FW_WMI_OP_VERSION_10_2:
7009 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7010 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7011 ar->hw->wiphy->n_iface_combinations =
7012 ARRAY_SIZE(ath10k_10x_if_comb);
7014 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7015 case ATH10K_FW_WMI_OP_VERSION_MAX:
7021 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7023 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7024 /* Init ath dfs pattern detector */
7025 ar->ath_common.debug_mask = ATH_DBG_DFS;
7026 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7029 if (!ar->dfs_detector)
7030 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
7033 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7034 ath10k_reg_notifier);
7036 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
7040 ar->hw->wiphy->cipher_suites = cipher_suites;
7041 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7043 ret = ieee80211_register_hw(ar->hw);
7045 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
7049 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7050 ret = regulatory_hint(ar->hw->wiphy,
7051 ar->ath_common.regulatory.alpha2);
7053 goto err_unregister;
7059 ieee80211_unregister_hw(ar->hw);
7061 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7062 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7067 void ath10k_mac_unregister(struct ath10k *ar)
7069 ieee80211_unregister_hw(ar->hw);
7071 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7072 ar->dfs_detector->exit(ar->dfs_detector);
7074 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7075 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7077 SET_IEEE80211_DEV(ar->hw, NULL);