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 (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
201 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
204 if (cmd == DISABLE_KEY) {
205 arg.key_cipher = WMI_CIPHER_NONE;
209 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
212 static int ath10k_install_key(struct ath10k_vif *arvif,
213 struct ieee80211_key_conf *key,
214 enum set_key_cmd cmd,
215 const u8 *macaddr, u32 flags)
217 struct ath10k *ar = arvif->ar;
219 unsigned long time_left;
221 lockdep_assert_held(&ar->conf_mutex);
223 reinit_completion(&ar->install_key_done);
225 if (arvif->nohwcrypt)
228 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
232 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
239 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
242 struct ath10k *ar = arvif->ar;
243 struct ath10k_peer *peer;
248 lockdep_assert_held(&ar->conf_mutex);
250 spin_lock_bh(&ar->data_lock);
251 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
252 spin_unlock_bh(&ar->data_lock);
257 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
258 if (arvif->wep_keys[i] == NULL)
262 flags |= WMI_KEY_PAIRWISE;
264 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
270 flags |= WMI_KEY_GROUP;
272 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
277 spin_lock_bh(&ar->data_lock);
278 peer->keys[i] = arvif->wep_keys[i];
279 spin_unlock_bh(&ar->data_lock);
282 /* In some cases (notably with static WEP IBSS with multiple keys)
283 * multicast Tx becomes broken. Both pairwise and groupwise keys are
284 * installed already. Using WMI_KEY_TX_USAGE in different combinations
285 * didn't seem help. Using def_keyid vdev parameter seems to be
286 * effective so use that.
288 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
290 if (arvif->def_wep_key_idx == -1)
293 ret = ath10k_wmi_vdev_set_param(arvif->ar,
295 arvif->ar->wmi.vdev_param->def_keyid,
296 arvif->def_wep_key_idx);
298 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
299 arvif->vdev_id, ret);
306 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
309 struct ath10k *ar = arvif->ar;
310 struct ath10k_peer *peer;
316 lockdep_assert_held(&ar->conf_mutex);
318 spin_lock_bh(&ar->data_lock);
319 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
320 spin_unlock_bh(&ar->data_lock);
325 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
326 if (peer->keys[i] == NULL)
329 /* key flags are not required to delete the key */
330 ret = ath10k_install_key(arvif, peer->keys[i],
331 DISABLE_KEY, addr, flags);
332 if (ret < 0 && first_errno == 0)
336 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
339 spin_lock_bh(&ar->data_lock);
340 peer->keys[i] = NULL;
341 spin_unlock_bh(&ar->data_lock);
347 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
350 struct ath10k_peer *peer;
353 lockdep_assert_held(&ar->data_lock);
355 /* We don't know which vdev this peer belongs to,
356 * since WMI doesn't give us that information.
358 * FIXME: multi-bss needs to be handled.
360 peer = ath10k_peer_find(ar, 0, addr);
364 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
365 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
372 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
373 struct ieee80211_key_conf *key)
375 struct ath10k *ar = arvif->ar;
376 struct ath10k_peer *peer;
383 lockdep_assert_held(&ar->conf_mutex);
386 /* since ath10k_install_key we can't hold data_lock all the
387 * time, so we try to remove the keys incrementally */
388 spin_lock_bh(&ar->data_lock);
390 list_for_each_entry(peer, &ar->peers, list) {
391 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
392 if (peer->keys[i] == key) {
393 ether_addr_copy(addr, peer->addr);
394 peer->keys[i] = NULL;
399 if (i < ARRAY_SIZE(peer->keys))
402 spin_unlock_bh(&ar->data_lock);
404 if (i == ARRAY_SIZE(peer->keys))
406 /* key flags are not required to delete the key */
407 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
408 if (ret < 0 && first_errno == 0)
412 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
419 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
420 struct ieee80211_key_conf *key)
422 struct ath10k *ar = arvif->ar;
423 struct ath10k_peer *peer;
426 lockdep_assert_held(&ar->conf_mutex);
428 list_for_each_entry(peer, &ar->peers, list) {
429 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
432 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
435 if (peer->keys[key->keyidx] == key)
438 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
439 arvif->vdev_id, key->keyidx);
441 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
443 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
444 arvif->vdev_id, peer->addr, ret);
452 /*********************/
453 /* General utilities */
454 /*********************/
456 static inline enum wmi_phy_mode
457 chan_to_phymode(const struct cfg80211_chan_def *chandef)
459 enum wmi_phy_mode phymode = MODE_UNKNOWN;
461 switch (chandef->chan->band) {
462 case IEEE80211_BAND_2GHZ:
463 switch (chandef->width) {
464 case NL80211_CHAN_WIDTH_20_NOHT:
465 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
470 case NL80211_CHAN_WIDTH_20:
471 phymode = MODE_11NG_HT20;
473 case NL80211_CHAN_WIDTH_40:
474 phymode = MODE_11NG_HT40;
476 case NL80211_CHAN_WIDTH_5:
477 case NL80211_CHAN_WIDTH_10:
478 case NL80211_CHAN_WIDTH_80:
479 case NL80211_CHAN_WIDTH_80P80:
480 case NL80211_CHAN_WIDTH_160:
481 phymode = MODE_UNKNOWN;
485 case IEEE80211_BAND_5GHZ:
486 switch (chandef->width) {
487 case NL80211_CHAN_WIDTH_20_NOHT:
490 case NL80211_CHAN_WIDTH_20:
491 phymode = MODE_11NA_HT20;
493 case NL80211_CHAN_WIDTH_40:
494 phymode = MODE_11NA_HT40;
496 case NL80211_CHAN_WIDTH_80:
497 phymode = MODE_11AC_VHT80;
499 case NL80211_CHAN_WIDTH_5:
500 case NL80211_CHAN_WIDTH_10:
501 case NL80211_CHAN_WIDTH_80P80:
502 case NL80211_CHAN_WIDTH_160:
503 phymode = MODE_UNKNOWN;
511 WARN_ON(phymode == MODE_UNKNOWN);
515 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
518 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
519 * 0 for no restriction
528 switch (mpdudensity) {
534 /* Our lower layer calculations limit our precision to
550 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
551 struct cfg80211_chan_def *def)
553 struct ieee80211_chanctx_conf *conf;
556 conf = rcu_dereference(vif->chanctx_conf);
568 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
569 struct ieee80211_chanctx_conf *conf,
577 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
581 ieee80211_iter_chan_contexts_atomic(ar->hw,
582 ath10k_mac_num_chanctxs_iter,
589 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
590 struct ieee80211_chanctx_conf *conf,
593 struct cfg80211_chan_def **def = data;
598 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
599 enum wmi_peer_type peer_type)
603 lockdep_assert_held(&ar->conf_mutex);
605 if (ar->num_peers >= ar->max_num_peers)
608 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
610 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
615 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
617 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
627 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
629 struct ath10k *ar = arvif->ar;
633 param = ar->wmi.pdev_param->sta_kickout_th;
634 ret = ath10k_wmi_pdev_set_param(ar, param,
635 ATH10K_KICKOUT_THRESHOLD);
637 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
638 arvif->vdev_id, ret);
642 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
643 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
644 ATH10K_KEEPALIVE_MIN_IDLE);
646 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
647 arvif->vdev_id, ret);
651 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
652 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
653 ATH10K_KEEPALIVE_MAX_IDLE);
655 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
656 arvif->vdev_id, ret);
660 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
661 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
662 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
664 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
665 arvif->vdev_id, ret);
672 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
674 struct ath10k *ar = arvif->ar;
677 vdev_param = ar->wmi.vdev_param->rts_threshold;
678 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
681 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
683 struct ath10k *ar = arvif->ar;
686 if (value != 0xFFFFFFFF)
687 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
688 ATH10K_FRAGMT_THRESHOLD_MIN,
689 ATH10K_FRAGMT_THRESHOLD_MAX);
691 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
692 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
695 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
699 lockdep_assert_held(&ar->conf_mutex);
701 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
705 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
714 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
716 struct ath10k_peer *peer, *tmp;
718 lockdep_assert_held(&ar->conf_mutex);
720 spin_lock_bh(&ar->data_lock);
721 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
722 if (peer->vdev_id != vdev_id)
725 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
726 peer->addr, vdev_id);
728 list_del(&peer->list);
732 spin_unlock_bh(&ar->data_lock);
735 static void ath10k_peer_cleanup_all(struct ath10k *ar)
737 struct ath10k_peer *peer, *tmp;
739 lockdep_assert_held(&ar->conf_mutex);
741 spin_lock_bh(&ar->data_lock);
742 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
743 list_del(&peer->list);
746 spin_unlock_bh(&ar->data_lock);
749 ar->num_stations = 0;
752 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
753 struct ieee80211_sta *sta,
754 enum wmi_tdls_peer_state state)
757 struct wmi_tdls_peer_update_cmd_arg arg = {};
758 struct wmi_tdls_peer_capab_arg cap = {};
759 struct wmi_channel_arg chan_arg = {};
761 lockdep_assert_held(&ar->conf_mutex);
763 arg.vdev_id = vdev_id;
764 arg.peer_state = state;
765 ether_addr_copy(arg.addr, sta->addr);
767 cap.peer_max_sp = sta->max_sp;
768 cap.peer_uapsd_queues = sta->uapsd_queues;
770 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
771 !sta->tdls_initiator)
772 cap.is_peer_responder = 1;
774 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
776 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
777 arg.addr, vdev_id, ret);
784 /************************/
785 /* Interface management */
786 /************************/
788 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
790 struct ath10k *ar = arvif->ar;
792 lockdep_assert_held(&ar->data_lock);
797 if (!arvif->beacon_buf)
798 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
799 arvif->beacon->len, DMA_TO_DEVICE);
801 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
802 arvif->beacon_state != ATH10K_BEACON_SENT))
805 dev_kfree_skb_any(arvif->beacon);
807 arvif->beacon = NULL;
808 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
811 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
813 struct ath10k *ar = arvif->ar;
815 lockdep_assert_held(&ar->data_lock);
817 ath10k_mac_vif_beacon_free(arvif);
819 if (arvif->beacon_buf) {
820 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
821 arvif->beacon_buf, arvif->beacon_paddr);
822 arvif->beacon_buf = NULL;
826 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
828 unsigned long time_left;
830 lockdep_assert_held(&ar->conf_mutex);
832 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
835 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
836 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
843 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
845 struct cfg80211_chan_def *chandef = NULL;
846 struct ieee80211_channel *channel = NULL;
847 struct wmi_vdev_start_request_arg arg = {};
850 lockdep_assert_held(&ar->conf_mutex);
852 ieee80211_iter_chan_contexts_atomic(ar->hw,
853 ath10k_mac_get_any_chandef_iter,
855 if (WARN_ON_ONCE(!chandef))
858 channel = chandef->chan;
860 arg.vdev_id = vdev_id;
861 arg.channel.freq = channel->center_freq;
862 arg.channel.band_center_freq1 = chandef->center_freq1;
864 /* TODO setup this dynamically, what in case we
865 don't have any vifs? */
866 arg.channel.mode = chan_to_phymode(chandef);
867 arg.channel.chan_radar =
868 !!(channel->flags & IEEE80211_CHAN_RADAR);
870 arg.channel.min_power = 0;
871 arg.channel.max_power = channel->max_power * 2;
872 arg.channel.max_reg_power = channel->max_reg_power * 2;
873 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
875 reinit_completion(&ar->vdev_setup_done);
877 ret = ath10k_wmi_vdev_start(ar, &arg);
879 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
884 ret = ath10k_vdev_setup_sync(ar);
886 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
891 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
893 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
898 ar->monitor_vdev_id = vdev_id;
900 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
901 ar->monitor_vdev_id);
905 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
907 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
908 ar->monitor_vdev_id, ret);
913 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
917 lockdep_assert_held(&ar->conf_mutex);
919 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
921 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
922 ar->monitor_vdev_id, ret);
924 reinit_completion(&ar->vdev_setup_done);
926 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
928 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
929 ar->monitor_vdev_id, ret);
931 ret = ath10k_vdev_setup_sync(ar);
933 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
934 ar->monitor_vdev_id, ret);
936 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
937 ar->monitor_vdev_id);
941 static int ath10k_monitor_vdev_create(struct ath10k *ar)
945 lockdep_assert_held(&ar->conf_mutex);
947 if (ar->free_vdev_map == 0) {
948 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
952 bit = __ffs64(ar->free_vdev_map);
954 ar->monitor_vdev_id = bit;
956 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
957 WMI_VDEV_TYPE_MONITOR,
960 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
961 ar->monitor_vdev_id, ret);
965 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
966 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
967 ar->monitor_vdev_id);
972 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
976 lockdep_assert_held(&ar->conf_mutex);
978 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
980 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
981 ar->monitor_vdev_id, ret);
985 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
987 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
988 ar->monitor_vdev_id);
992 static int ath10k_monitor_start(struct ath10k *ar)
996 lockdep_assert_held(&ar->conf_mutex);
998 ret = ath10k_monitor_vdev_create(ar);
1000 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1004 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1006 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1007 ath10k_monitor_vdev_delete(ar);
1011 ar->monitor_started = true;
1012 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1017 static int ath10k_monitor_stop(struct ath10k *ar)
1021 lockdep_assert_held(&ar->conf_mutex);
1023 ret = ath10k_monitor_vdev_stop(ar);
1025 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1029 ret = ath10k_monitor_vdev_delete(ar);
1031 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1035 ar->monitor_started = false;
1036 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1041 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1045 /* At least one chanctx is required to derive a channel to start
1048 num_ctx = ath10k_mac_num_chanctxs(ar);
1052 /* If there's already an existing special monitor interface then don't
1053 * bother creating another monitor vdev.
1055 if (ar->monitor_arvif)
1058 return ar->monitor ||
1059 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1062 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1066 num_ctx = ath10k_mac_num_chanctxs(ar);
1068 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1069 * shouldn't allow this but make sure to prevent handling the following
1070 * case anyway since multi-channel DFS hasn't been tested at all.
1072 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1078 static int ath10k_monitor_recalc(struct ath10k *ar)
1084 lockdep_assert_held(&ar->conf_mutex);
1086 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1087 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1089 ath10k_dbg(ar, ATH10K_DBG_MAC,
1090 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1091 ar->monitor_started, needed, allowed);
1093 if (WARN_ON(needed && !allowed)) {
1094 if (ar->monitor_started) {
1095 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1097 ret = ath10k_monitor_stop(ar);
1099 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1106 if (needed == ar->monitor_started)
1110 return ath10k_monitor_start(ar);
1112 return ath10k_monitor_stop(ar);
1115 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1117 struct ath10k *ar = arvif->ar;
1118 u32 vdev_param, rts_cts = 0;
1120 lockdep_assert_held(&ar->conf_mutex);
1122 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1124 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1126 if (arvif->num_legacy_stations > 0)
1127 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1128 WMI_RTSCTS_PROFILE);
1130 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1131 WMI_RTSCTS_PROFILE);
1133 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1137 static int ath10k_start_cac(struct ath10k *ar)
1141 lockdep_assert_held(&ar->conf_mutex);
1143 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1145 ret = ath10k_monitor_recalc(ar);
1147 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1148 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1152 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1153 ar->monitor_vdev_id);
1158 static int ath10k_stop_cac(struct ath10k *ar)
1160 lockdep_assert_held(&ar->conf_mutex);
1162 /* CAC is not running - do nothing */
1163 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1166 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1167 ath10k_monitor_stop(ar);
1169 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1174 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1175 struct ieee80211_chanctx_conf *conf,
1180 if (!*ret && conf->radar_enabled)
1184 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1186 bool has_radar = false;
1188 ieee80211_iter_chan_contexts_atomic(ar->hw,
1189 ath10k_mac_has_radar_iter,
1195 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1199 lockdep_assert_held(&ar->conf_mutex);
1201 ath10k_stop_cac(ar);
1203 if (!ath10k_mac_has_radar_enabled(ar))
1206 if (ar->num_started_vdevs > 0)
1209 ret = ath10k_start_cac(ar);
1212 * Not possible to start CAC on current channel so starting
1213 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1214 * by indicating that radar was detected.
1216 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1217 ieee80211_radar_detected(ar->hw);
1221 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1223 struct ath10k *ar = arvif->ar;
1226 lockdep_assert_held(&ar->conf_mutex);
1228 reinit_completion(&ar->vdev_setup_done);
1230 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1232 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1233 arvif->vdev_id, ret);
1237 ret = ath10k_vdev_setup_sync(ar);
1239 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1240 arvif->vdev_id, ret);
1244 WARN_ON(ar->num_started_vdevs == 0);
1246 if (ar->num_started_vdevs != 0) {
1247 ar->num_started_vdevs--;
1248 ath10k_recalc_radar_detection(ar);
1254 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1255 const struct cfg80211_chan_def *chandef,
1258 struct ath10k *ar = arvif->ar;
1259 struct wmi_vdev_start_request_arg arg = {};
1262 lockdep_assert_held(&ar->conf_mutex);
1264 reinit_completion(&ar->vdev_setup_done);
1266 arg.vdev_id = arvif->vdev_id;
1267 arg.dtim_period = arvif->dtim_period;
1268 arg.bcn_intval = arvif->beacon_interval;
1270 arg.channel.freq = chandef->chan->center_freq;
1271 arg.channel.band_center_freq1 = chandef->center_freq1;
1272 arg.channel.mode = chan_to_phymode(chandef);
1274 arg.channel.min_power = 0;
1275 arg.channel.max_power = chandef->chan->max_power * 2;
1276 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1277 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1279 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1280 arg.ssid = arvif->u.ap.ssid;
1281 arg.ssid_len = arvif->u.ap.ssid_len;
1282 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1284 /* For now allow DFS for AP mode */
1285 arg.channel.chan_radar =
1286 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1287 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1288 arg.ssid = arvif->vif->bss_conf.ssid;
1289 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1292 ath10k_dbg(ar, ATH10K_DBG_MAC,
1293 "mac vdev %d start center_freq %d phymode %s\n",
1294 arg.vdev_id, arg.channel.freq,
1295 ath10k_wmi_phymode_str(arg.channel.mode));
1298 ret = ath10k_wmi_vdev_restart(ar, &arg);
1300 ret = ath10k_wmi_vdev_start(ar, &arg);
1303 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1308 ret = ath10k_vdev_setup_sync(ar);
1311 "failed to synchronize setup for vdev %i restart %d: %d\n",
1312 arg.vdev_id, restart, ret);
1316 ar->num_started_vdevs++;
1317 ath10k_recalc_radar_detection(ar);
1322 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1323 const struct cfg80211_chan_def *def)
1325 return ath10k_vdev_start_restart(arvif, def, false);
1328 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1329 const struct cfg80211_chan_def *def)
1331 return ath10k_vdev_start_restart(arvif, def, true);
1334 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1335 struct sk_buff *bcn)
1337 struct ath10k *ar = arvif->ar;
1338 struct ieee80211_mgmt *mgmt;
1342 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1345 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1348 mgmt = (void *)bcn->data;
1349 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1350 mgmt->u.beacon.variable,
1351 bcn->len - (mgmt->u.beacon.variable -
1356 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1358 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1359 arvif->vdev_id, ret);
1366 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1367 u8 oui_type, size_t ie_offset)
1374 if (WARN_ON(skb->len < ie_offset))
1377 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1378 skb->data + ie_offset,
1379 skb->len - ie_offset);
1384 end = skb->data + skb->len;
1387 if (WARN_ON(next > end))
1390 memmove(ie, next, end - next);
1391 skb_trim(skb, skb->len - len);
1396 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1398 struct ath10k *ar = arvif->ar;
1399 struct ieee80211_hw *hw = ar->hw;
1400 struct ieee80211_vif *vif = arvif->vif;
1401 struct ieee80211_mutable_offsets offs = {};
1402 struct sk_buff *bcn;
1405 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1408 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1409 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1412 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1414 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1418 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1420 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1425 /* P2P IE is inserted by firmware automatically (as configured above)
1426 * so remove it from the base beacon template to avoid duplicate P2P
1427 * IEs in beacon frames.
1429 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1430 offsetof(struct ieee80211_mgmt,
1431 u.beacon.variable));
1433 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1438 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1446 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1448 struct ath10k *ar = arvif->ar;
1449 struct ieee80211_hw *hw = ar->hw;
1450 struct ieee80211_vif *vif = arvif->vif;
1451 struct sk_buff *prb;
1454 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1457 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1460 prb = ieee80211_proberesp_get(hw, vif);
1462 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1466 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1470 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1478 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1480 struct ath10k *ar = arvif->ar;
1481 struct cfg80211_chan_def def;
1484 /* When originally vdev is started during assign_vif_chanctx() some
1485 * information is missing, notably SSID. Firmware revisions with beacon
1486 * offloading require the SSID to be provided during vdev (re)start to
1487 * handle hidden SSID properly.
1489 * Vdev restart must be done after vdev has been both started and
1490 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1491 * deliver vdev restart response event causing timeouts during vdev
1492 * syncing in ath10k.
1494 * Note: The vdev down/up and template reinstallation could be skipped
1495 * since only wmi-tlv firmware are known to have beacon offload and
1496 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1497 * response delivery. It's probably more robust to keep it as is.
1499 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1502 if (WARN_ON(!arvif->is_started))
1505 if (WARN_ON(!arvif->is_up))
1508 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1511 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1513 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1514 arvif->vdev_id, ret);
1518 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1519 * firmware will crash upon vdev up.
1522 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1524 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1528 ret = ath10k_mac_setup_prb_tmpl(arvif);
1530 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1534 ret = ath10k_vdev_restart(arvif, &def);
1536 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1537 arvif->vdev_id, ret);
1541 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1544 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1545 arvif->vdev_id, ret);
1552 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1553 struct ieee80211_bss_conf *info)
1555 struct ath10k *ar = arvif->ar;
1558 lockdep_assert_held(&arvif->ar->conf_mutex);
1560 if (!info->enable_beacon) {
1561 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1563 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1564 arvif->vdev_id, ret);
1566 arvif->is_up = false;
1568 spin_lock_bh(&arvif->ar->data_lock);
1569 ath10k_mac_vif_beacon_free(arvif);
1570 spin_unlock_bh(&arvif->ar->data_lock);
1575 arvif->tx_seq_no = 0x1000;
1578 ether_addr_copy(arvif->bssid, info->bssid);
1580 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1583 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1584 arvif->vdev_id, ret);
1588 arvif->is_up = true;
1590 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1592 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1593 arvif->vdev_id, ret);
1597 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1600 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1601 struct ieee80211_bss_conf *info,
1602 const u8 self_peer[ETH_ALEN])
1604 struct ath10k *ar = arvif->ar;
1608 lockdep_assert_held(&arvif->ar->conf_mutex);
1610 if (!info->ibss_joined) {
1611 if (is_zero_ether_addr(arvif->bssid))
1614 eth_zero_addr(arvif->bssid);
1619 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1620 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1621 ATH10K_DEFAULT_ATIM);
1623 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1624 arvif->vdev_id, ret);
1627 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1629 struct ath10k *ar = arvif->ar;
1634 lockdep_assert_held(&arvif->ar->conf_mutex);
1636 if (arvif->u.sta.uapsd)
1637 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1639 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1641 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1642 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1644 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1645 value, arvif->vdev_id, ret);
1652 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1654 struct ath10k *ar = arvif->ar;
1659 lockdep_assert_held(&arvif->ar->conf_mutex);
1661 if (arvif->u.sta.uapsd)
1662 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1664 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1666 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1667 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1670 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1671 value, arvif->vdev_id, ret);
1678 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1680 struct ath10k_vif *arvif;
1683 lockdep_assert_held(&ar->conf_mutex);
1685 list_for_each_entry(arvif, &ar->arvifs, list)
1686 if (arvif->is_started)
1692 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1694 struct ath10k *ar = arvif->ar;
1695 struct ieee80211_vif *vif = arvif->vif;
1696 struct ieee80211_conf *conf = &ar->hw->conf;
1697 enum wmi_sta_powersave_param param;
1698 enum wmi_sta_ps_mode psmode;
1703 lockdep_assert_held(&arvif->ar->conf_mutex);
1705 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1708 enable_ps = arvif->ps;
1710 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1711 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1713 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1718 if (!arvif->is_started) {
1719 /* mac80211 can update vif powersave state while disconnected.
1720 * Firmware doesn't behave nicely and consumes more power than
1721 * necessary if PS is disabled on a non-started vdev. Hence
1722 * force-enable PS for non-running vdevs.
1724 psmode = WMI_STA_PS_MODE_ENABLED;
1725 } else if (enable_ps) {
1726 psmode = WMI_STA_PS_MODE_ENABLED;
1727 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1729 ps_timeout = conf->dynamic_ps_timeout;
1730 if (ps_timeout == 0) {
1731 /* Firmware doesn't like 0 */
1732 ps_timeout = ieee80211_tu_to_usec(
1733 vif->bss_conf.beacon_int) / 1000;
1736 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1739 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1740 arvif->vdev_id, ret);
1744 psmode = WMI_STA_PS_MODE_DISABLED;
1747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1748 arvif->vdev_id, psmode ? "enable" : "disable");
1750 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1752 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1753 psmode, arvif->vdev_id, ret);
1760 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1762 struct ath10k *ar = arvif->ar;
1763 struct wmi_sta_keepalive_arg arg = {};
1766 lockdep_assert_held(&arvif->ar->conf_mutex);
1768 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1771 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1774 /* Some firmware revisions have a bug and ignore the `enabled` field.
1775 * Instead use the interval to disable the keepalive.
1777 arg.vdev_id = arvif->vdev_id;
1779 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1780 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1782 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1784 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1785 arvif->vdev_id, ret);
1792 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1794 struct ath10k *ar = arvif->ar;
1795 struct ieee80211_vif *vif = arvif->vif;
1798 lockdep_assert_held(&arvif->ar->conf_mutex);
1800 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1803 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1806 if (!vif->csa_active)
1812 if (!ieee80211_csa_is_complete(vif)) {
1813 ieee80211_csa_update_counter(vif);
1815 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1817 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1820 ret = ath10k_mac_setup_prb_tmpl(arvif);
1822 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1825 ieee80211_csa_finish(vif);
1829 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1831 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1833 struct ath10k *ar = arvif->ar;
1835 mutex_lock(&ar->conf_mutex);
1836 ath10k_mac_vif_ap_csa_count_down(arvif);
1837 mutex_unlock(&ar->conf_mutex);
1840 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1841 struct ieee80211_vif *vif)
1843 struct sk_buff *skb = data;
1844 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1845 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1847 if (vif->type != NL80211_IFTYPE_STATION)
1850 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1853 cancel_delayed_work(&arvif->connection_loss_work);
1856 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1858 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1859 IEEE80211_IFACE_ITER_NORMAL,
1860 ath10k_mac_handle_beacon_iter,
1864 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1865 struct ieee80211_vif *vif)
1867 u32 *vdev_id = data;
1868 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1869 struct ath10k *ar = arvif->ar;
1870 struct ieee80211_hw *hw = ar->hw;
1872 if (arvif->vdev_id != *vdev_id)
1878 ieee80211_beacon_loss(vif);
1880 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1881 * (done by mac80211) succeeds but beacons do not resume then it
1882 * doesn't make sense to continue operation. Queue connection loss work
1883 * which can be cancelled when beacon is received.
1885 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1886 ATH10K_CONNECTION_LOSS_HZ);
1889 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1891 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1892 IEEE80211_IFACE_ITER_NORMAL,
1893 ath10k_mac_handle_beacon_miss_iter,
1897 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1899 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1900 connection_loss_work.work);
1901 struct ieee80211_vif *vif = arvif->vif;
1906 ieee80211_connection_loss(vif);
1909 /**********************/
1910 /* Station management */
1911 /**********************/
1913 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1914 struct ieee80211_vif *vif)
1916 /* Some firmware revisions have unstable STA powersave when listen
1917 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1918 * generate NullFunc frames properly even if buffered frames have been
1919 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1920 * buffered frames. Often pinging the device from AP would simply fail.
1922 * As a workaround set it to 1.
1924 if (vif->type == NL80211_IFTYPE_STATION)
1927 return ar->hw->conf.listen_interval;
1930 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1931 struct ieee80211_vif *vif,
1932 struct ieee80211_sta *sta,
1933 struct wmi_peer_assoc_complete_arg *arg)
1935 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1938 lockdep_assert_held(&ar->conf_mutex);
1940 if (vif->type == NL80211_IFTYPE_STATION)
1941 aid = vif->bss_conf.aid;
1945 ether_addr_copy(arg->addr, sta->addr);
1946 arg->vdev_id = arvif->vdev_id;
1947 arg->peer_aid = aid;
1948 arg->peer_flags |= WMI_PEER_AUTH;
1949 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1950 arg->peer_num_spatial_streams = 1;
1951 arg->peer_caps = vif->bss_conf.assoc_capability;
1954 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1955 struct ieee80211_vif *vif,
1956 struct wmi_peer_assoc_complete_arg *arg)
1958 struct ieee80211_bss_conf *info = &vif->bss_conf;
1959 struct cfg80211_chan_def def;
1960 struct cfg80211_bss *bss;
1961 const u8 *rsnie = NULL;
1962 const u8 *wpaie = NULL;
1964 lockdep_assert_held(&ar->conf_mutex);
1966 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1969 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1970 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
1972 const struct cfg80211_bss_ies *ies;
1975 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1977 ies = rcu_dereference(bss->ies);
1979 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1980 WLAN_OUI_TYPE_MICROSOFT_WPA,
1984 cfg80211_put_bss(ar->hw->wiphy, bss);
1987 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1988 if (rsnie || wpaie) {
1989 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1990 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1994 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1995 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1999 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2000 struct ieee80211_vif *vif,
2001 struct ieee80211_sta *sta,
2002 struct wmi_peer_assoc_complete_arg *arg)
2004 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2005 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2006 struct cfg80211_chan_def def;
2007 const struct ieee80211_supported_band *sband;
2008 const struct ieee80211_rate *rates;
2009 enum ieee80211_band band;
2014 lockdep_assert_held(&ar->conf_mutex);
2016 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2019 band = def.chan->band;
2020 sband = ar->hw->wiphy->bands[band];
2021 ratemask = sta->supp_rates[band];
2022 ratemask &= arvif->bitrate_mask.control[band].legacy;
2023 rates = sband->bitrates;
2025 rateset->num_rates = 0;
2027 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2028 if (!(ratemask & 1))
2031 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2032 rateset->rates[rateset->num_rates] = rate;
2033 rateset->num_rates++;
2038 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2042 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2043 if (ht_mcs_mask[nss])
2050 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2054 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2055 if (vht_mcs_mask[nss])
2061 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2062 struct ieee80211_vif *vif,
2063 struct ieee80211_sta *sta,
2064 struct wmi_peer_assoc_complete_arg *arg)
2066 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2068 struct cfg80211_chan_def def;
2069 enum ieee80211_band band;
2070 const u8 *ht_mcs_mask;
2071 const u16 *vht_mcs_mask;
2075 lockdep_assert_held(&ar->conf_mutex);
2077 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2080 if (!ht_cap->ht_supported)
2083 band = def.chan->band;
2084 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2085 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2087 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2088 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2091 arg->peer_flags |= WMI_PEER_HT;
2092 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2093 ht_cap->ampdu_factor)) - 1;
2095 arg->peer_mpdu_density =
2096 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2098 arg->peer_ht_caps = ht_cap->cap;
2099 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2101 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2102 arg->peer_flags |= WMI_PEER_LDPC;
2104 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2105 arg->peer_flags |= WMI_PEER_40MHZ;
2106 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2109 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2110 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2111 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2113 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2114 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2117 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2118 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2119 arg->peer_flags |= WMI_PEER_STBC;
2122 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2123 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2124 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2125 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2126 arg->peer_rate_caps |= stbc;
2127 arg->peer_flags |= WMI_PEER_STBC;
2130 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2131 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2132 else if (ht_cap->mcs.rx_mask[1])
2133 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2135 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2136 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2137 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2138 max_nss = (i / 8) + 1;
2139 arg->peer_ht_rates.rates[n++] = i;
2143 * This is a workaround for HT-enabled STAs which break the spec
2144 * and have no HT capabilities RX mask (no HT RX MCS map).
2146 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2147 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2149 * Firmware asserts if such situation occurs.
2152 arg->peer_ht_rates.num_rates = 8;
2153 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2154 arg->peer_ht_rates.rates[i] = i;
2156 arg->peer_ht_rates.num_rates = n;
2157 arg->peer_num_spatial_streams = max_nss;
2160 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2162 arg->peer_ht_rates.num_rates,
2163 arg->peer_num_spatial_streams);
2166 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2167 struct ath10k_vif *arvif,
2168 struct ieee80211_sta *sta)
2174 lockdep_assert_held(&ar->conf_mutex);
2176 if (sta->wme && sta->uapsd_queues) {
2177 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2178 sta->uapsd_queues, sta->max_sp);
2180 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2181 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2182 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2183 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2184 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2185 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2186 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2187 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2188 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2189 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2190 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2191 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2193 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2194 max_sp = sta->max_sp;
2196 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2198 WMI_AP_PS_PEER_PARAM_UAPSD,
2201 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2202 arvif->vdev_id, ret);
2206 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2208 WMI_AP_PS_PEER_PARAM_MAX_SP,
2211 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2212 arvif->vdev_id, ret);
2216 /* TODO setup this based on STA listen interval and
2217 beacon interval. Currently we don't know
2218 sta->listen_interval - mac80211 patch required.
2219 Currently use 10 seconds */
2220 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2221 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2224 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2225 arvif->vdev_id, ret);
2234 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2235 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2242 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2243 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2247 idx_limit = fls(mcs_map) - 1;
2251 switch (idx_limit) {
2252 case 0: /* fall through */
2253 case 1: /* fall through */
2254 case 2: /* fall through */
2255 case 3: /* fall through */
2256 case 4: /* fall through */
2257 case 5: /* fall through */
2258 case 6: /* fall through */
2260 /* see ath10k_mac_can_set_bitrate_mask() */
2264 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2267 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2270 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2273 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2277 tx_mcs_set &= ~(0x3 << (nss * 2));
2278 tx_mcs_set |= mcs << (nss * 2);
2284 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2285 struct ieee80211_vif *vif,
2286 struct ieee80211_sta *sta,
2287 struct wmi_peer_assoc_complete_arg *arg)
2289 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2290 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2291 struct cfg80211_chan_def def;
2292 enum ieee80211_band band;
2293 const u16 *vht_mcs_mask;
2296 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2299 if (!vht_cap->vht_supported)
2302 band = def.chan->band;
2303 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2305 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2308 arg->peer_flags |= WMI_PEER_VHT;
2310 if (def.chan->band == IEEE80211_BAND_2GHZ)
2311 arg->peer_flags |= WMI_PEER_VHT_2G;
2313 arg->peer_vht_caps = vht_cap->cap;
2315 ampdu_factor = (vht_cap->cap &
2316 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2317 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2319 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2320 * zero in VHT IE. Using it would result in degraded throughput.
2321 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2322 * it if VHT max_mpdu is smaller. */
2323 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2324 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2325 ampdu_factor)) - 1);
2327 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2328 arg->peer_flags |= WMI_PEER_80MHZ;
2330 arg->peer_vht_rates.rx_max_rate =
2331 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2332 arg->peer_vht_rates.rx_mcs_set =
2333 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2334 arg->peer_vht_rates.tx_max_rate =
2335 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2336 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2337 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2339 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2340 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2343 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2344 struct ieee80211_vif *vif,
2345 struct ieee80211_sta *sta,
2346 struct wmi_peer_assoc_complete_arg *arg)
2348 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2350 switch (arvif->vdev_type) {
2351 case WMI_VDEV_TYPE_AP:
2353 arg->peer_flags |= WMI_PEER_QOS;
2355 if (sta->wme && sta->uapsd_queues) {
2356 arg->peer_flags |= WMI_PEER_APSD;
2357 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2360 case WMI_VDEV_TYPE_STA:
2361 if (vif->bss_conf.qos)
2362 arg->peer_flags |= WMI_PEER_QOS;
2364 case WMI_VDEV_TYPE_IBSS:
2366 arg->peer_flags |= WMI_PEER_QOS;
2372 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2373 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
2376 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2378 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2379 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2382 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2383 struct ieee80211_vif *vif,
2384 struct ieee80211_sta *sta,
2385 struct wmi_peer_assoc_complete_arg *arg)
2387 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2388 struct cfg80211_chan_def def;
2389 enum ieee80211_band band;
2390 const u8 *ht_mcs_mask;
2391 const u16 *vht_mcs_mask;
2392 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2394 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2397 band = def.chan->band;
2398 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2399 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2402 case IEEE80211_BAND_2GHZ:
2403 if (sta->vht_cap.vht_supported &&
2404 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2405 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2406 phymode = MODE_11AC_VHT40;
2408 phymode = MODE_11AC_VHT20;
2409 } else if (sta->ht_cap.ht_supported &&
2410 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2411 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2412 phymode = MODE_11NG_HT40;
2414 phymode = MODE_11NG_HT20;
2415 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2422 case IEEE80211_BAND_5GHZ:
2426 if (sta->vht_cap.vht_supported &&
2427 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2428 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2429 phymode = MODE_11AC_VHT80;
2430 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2431 phymode = MODE_11AC_VHT40;
2432 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2433 phymode = MODE_11AC_VHT20;
2434 } else if (sta->ht_cap.ht_supported &&
2435 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2436 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2437 phymode = MODE_11NA_HT40;
2439 phymode = MODE_11NA_HT20;
2449 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2450 sta->addr, ath10k_wmi_phymode_str(phymode));
2452 arg->peer_phymode = phymode;
2453 WARN_ON(phymode == MODE_UNKNOWN);
2456 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2457 struct ieee80211_vif *vif,
2458 struct ieee80211_sta *sta,
2459 struct wmi_peer_assoc_complete_arg *arg)
2461 lockdep_assert_held(&ar->conf_mutex);
2463 memset(arg, 0, sizeof(*arg));
2465 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2466 ath10k_peer_assoc_h_crypto(ar, vif, arg);
2467 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2468 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2469 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2470 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2471 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2476 static const u32 ath10k_smps_map[] = {
2477 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2478 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2479 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2480 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2483 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2485 const struct ieee80211_sta_ht_cap *ht_cap)
2489 if (!ht_cap->ht_supported)
2492 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2493 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2495 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2498 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2499 WMI_PEER_SMPS_STATE,
2500 ath10k_smps_map[smps]);
2503 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2504 struct ieee80211_vif *vif,
2505 struct ieee80211_sta_vht_cap vht_cap)
2507 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2512 if (!(ar->vht_cap_info &
2513 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2514 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2515 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2516 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2519 param = ar->wmi.vdev_param->txbf;
2522 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2525 /* The following logic is correct. If a remote STA advertises support
2526 * for being a beamformer then we should enable us being a beamformee.
2529 if (ar->vht_cap_info &
2530 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2531 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2532 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2533 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2535 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2536 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2539 if (ar->vht_cap_info &
2540 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2541 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2542 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2543 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2545 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2546 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2549 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2550 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2552 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2553 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2555 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2557 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2565 /* can be called only in mac80211 callbacks due to `key_count` usage */
2566 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2567 struct ieee80211_vif *vif,
2568 struct ieee80211_bss_conf *bss_conf)
2570 struct ath10k *ar = hw->priv;
2571 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2572 struct ieee80211_sta_ht_cap ht_cap;
2573 struct ieee80211_sta_vht_cap vht_cap;
2574 struct wmi_peer_assoc_complete_arg peer_arg;
2575 struct ieee80211_sta *ap_sta;
2578 lockdep_assert_held(&ar->conf_mutex);
2580 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2581 arvif->vdev_id, arvif->bssid, arvif->aid);
2585 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2587 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2588 bss_conf->bssid, arvif->vdev_id);
2593 /* ap_sta must be accessed only within rcu section which must be left
2594 * before calling ath10k_setup_peer_smps() which might sleep. */
2595 ht_cap = ap_sta->ht_cap;
2596 vht_cap = ap_sta->vht_cap;
2598 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2600 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2601 bss_conf->bssid, arvif->vdev_id, ret);
2608 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2610 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2611 bss_conf->bssid, arvif->vdev_id, ret);
2615 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2617 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2618 arvif->vdev_id, ret);
2622 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2624 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2625 arvif->vdev_id, bss_conf->bssid, ret);
2629 ath10k_dbg(ar, ATH10K_DBG_MAC,
2630 "mac vdev %d up (associated) bssid %pM aid %d\n",
2631 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2633 WARN_ON(arvif->is_up);
2635 arvif->aid = bss_conf->aid;
2636 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2638 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2640 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2641 arvif->vdev_id, ret);
2645 arvif->is_up = true;
2647 /* Workaround: Some firmware revisions (tested with qca6174
2648 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2649 * poked with peer param command.
2651 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2652 WMI_PEER_DUMMY_VAR, 1);
2654 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2655 arvif->bssid, arvif->vdev_id, ret);
2660 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2661 struct ieee80211_vif *vif)
2663 struct ath10k *ar = hw->priv;
2664 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2665 struct ieee80211_sta_vht_cap vht_cap = {};
2668 lockdep_assert_held(&ar->conf_mutex);
2670 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2671 arvif->vdev_id, arvif->bssid);
2673 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2675 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2676 arvif->vdev_id, ret);
2678 arvif->def_wep_key_idx = -1;
2680 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2682 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2683 arvif->vdev_id, ret);
2687 arvif->is_up = false;
2689 cancel_delayed_work_sync(&arvif->connection_loss_work);
2692 static int ath10k_station_assoc(struct ath10k *ar,
2693 struct ieee80211_vif *vif,
2694 struct ieee80211_sta *sta,
2697 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2698 struct wmi_peer_assoc_complete_arg peer_arg;
2701 lockdep_assert_held(&ar->conf_mutex);
2703 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2705 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2706 sta->addr, arvif->vdev_id, ret);
2710 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2712 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2713 sta->addr, arvif->vdev_id, ret);
2717 /* Re-assoc is run only to update supported rates for given station. It
2718 * doesn't make much sense to reconfigure the peer completely.
2721 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2724 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2725 arvif->vdev_id, ret);
2729 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2731 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2732 sta->addr, arvif->vdev_id, ret);
2737 arvif->num_legacy_stations++;
2738 ret = ath10k_recalc_rtscts_prot(arvif);
2740 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2741 arvif->vdev_id, ret);
2746 /* Plumb cached keys only for static WEP */
2747 if (arvif->def_wep_key_idx != -1) {
2748 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2750 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2751 arvif->vdev_id, ret);
2760 static int ath10k_station_disassoc(struct ath10k *ar,
2761 struct ieee80211_vif *vif,
2762 struct ieee80211_sta *sta)
2764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2767 lockdep_assert_held(&ar->conf_mutex);
2770 arvif->num_legacy_stations--;
2771 ret = ath10k_recalc_rtscts_prot(arvif);
2773 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2774 arvif->vdev_id, ret);
2779 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2781 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2782 arvif->vdev_id, ret);
2793 static int ath10k_update_channel_list(struct ath10k *ar)
2795 struct ieee80211_hw *hw = ar->hw;
2796 struct ieee80211_supported_band **bands;
2797 enum ieee80211_band band;
2798 struct ieee80211_channel *channel;
2799 struct wmi_scan_chan_list_arg arg = {0};
2800 struct wmi_channel_arg *ch;
2806 lockdep_assert_held(&ar->conf_mutex);
2808 bands = hw->wiphy->bands;
2809 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2813 for (i = 0; i < bands[band]->n_channels; i++) {
2814 if (bands[band]->channels[i].flags &
2815 IEEE80211_CHAN_DISABLED)
2822 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2823 arg.channels = kzalloc(len, GFP_KERNEL);
2828 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2832 for (i = 0; i < bands[band]->n_channels; i++) {
2833 channel = &bands[band]->channels[i];
2835 if (channel->flags & IEEE80211_CHAN_DISABLED)
2838 ch->allow_ht = true;
2840 /* FIXME: when should we really allow VHT? */
2841 ch->allow_vht = true;
2844 !(channel->flags & IEEE80211_CHAN_NO_IR);
2847 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2850 !!(channel->flags & IEEE80211_CHAN_RADAR);
2852 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2853 ch->passive = passive;
2855 ch->freq = channel->center_freq;
2856 ch->band_center_freq1 = channel->center_freq;
2858 ch->max_power = channel->max_power * 2;
2859 ch->max_reg_power = channel->max_reg_power * 2;
2860 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2861 ch->reg_class_id = 0; /* FIXME */
2863 /* FIXME: why use only legacy modes, why not any
2864 * HT/VHT modes? Would that even make any
2866 if (channel->band == IEEE80211_BAND_2GHZ)
2867 ch->mode = MODE_11G;
2869 ch->mode = MODE_11A;
2871 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2874 ath10k_dbg(ar, ATH10K_DBG_WMI,
2875 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2876 ch - arg.channels, arg.n_channels,
2877 ch->freq, ch->max_power, ch->max_reg_power,
2878 ch->max_antenna_gain, ch->mode);
2884 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2885 kfree(arg.channels);
2890 static enum wmi_dfs_region
2891 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2893 switch (dfs_region) {
2894 case NL80211_DFS_UNSET:
2895 return WMI_UNINIT_DFS_DOMAIN;
2896 case NL80211_DFS_FCC:
2897 return WMI_FCC_DFS_DOMAIN;
2898 case NL80211_DFS_ETSI:
2899 return WMI_ETSI_DFS_DOMAIN;
2900 case NL80211_DFS_JP:
2901 return WMI_MKK4_DFS_DOMAIN;
2903 return WMI_UNINIT_DFS_DOMAIN;
2906 static void ath10k_regd_update(struct ath10k *ar)
2908 struct reg_dmn_pair_mapping *regpair;
2910 enum wmi_dfs_region wmi_dfs_reg;
2911 enum nl80211_dfs_regions nl_dfs_reg;
2913 lockdep_assert_held(&ar->conf_mutex);
2915 ret = ath10k_update_channel_list(ar);
2917 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2919 regpair = ar->ath_common.regulatory.regpair;
2921 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2922 nl_dfs_reg = ar->dfs_detector->region;
2923 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2925 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2928 /* Target allows setting up per-band regdomain but ath_common provides
2929 * a combined one only */
2930 ret = ath10k_wmi_pdev_set_regdomain(ar,
2931 regpair->reg_domain,
2932 regpair->reg_domain, /* 2ghz */
2933 regpair->reg_domain, /* 5ghz */
2934 regpair->reg_2ghz_ctl,
2935 regpair->reg_5ghz_ctl,
2938 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
2941 static void ath10k_reg_notifier(struct wiphy *wiphy,
2942 struct regulatory_request *request)
2944 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2945 struct ath10k *ar = hw->priv;
2948 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2950 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2951 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
2952 request->dfs_region);
2953 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2954 request->dfs_region);
2956 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2957 request->dfs_region);
2960 mutex_lock(&ar->conf_mutex);
2961 if (ar->state == ATH10K_STATE_ON)
2962 ath10k_regd_update(ar);
2963 mutex_unlock(&ar->conf_mutex);
2970 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2972 lockdep_assert_held(&ar->htt.tx_lock);
2974 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2975 ar->tx_paused |= BIT(reason);
2976 ieee80211_stop_queues(ar->hw);
2979 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2980 struct ieee80211_vif *vif)
2982 struct ath10k *ar = data;
2983 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2985 if (arvif->tx_paused)
2988 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2991 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2993 lockdep_assert_held(&ar->htt.tx_lock);
2995 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2996 ar->tx_paused &= ~BIT(reason);
3001 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3002 IEEE80211_IFACE_ITER_RESUME_ALL,
3003 ath10k_mac_tx_unlock_iter,
3007 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3009 struct ath10k *ar = arvif->ar;
3011 lockdep_assert_held(&ar->htt.tx_lock);
3013 WARN_ON(reason >= BITS_PER_LONG);
3014 arvif->tx_paused |= BIT(reason);
3015 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3018 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3020 struct ath10k *ar = arvif->ar;
3022 lockdep_assert_held(&ar->htt.tx_lock);
3024 WARN_ON(reason >= BITS_PER_LONG);
3025 arvif->tx_paused &= ~BIT(reason);
3030 if (arvif->tx_paused)
3033 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3036 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3037 enum wmi_tlv_tx_pause_id pause_id,
3038 enum wmi_tlv_tx_pause_action action)
3040 struct ath10k *ar = arvif->ar;
3042 lockdep_assert_held(&ar->htt.tx_lock);
3045 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3046 ath10k_mac_vif_tx_lock(arvif, pause_id);
3048 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3049 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3052 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3053 action, arvif->vdev_id);
3058 struct ath10k_mac_tx_pause {
3060 enum wmi_tlv_tx_pause_id pause_id;
3061 enum wmi_tlv_tx_pause_action action;
3064 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3065 struct ieee80211_vif *vif)
3067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3068 struct ath10k_mac_tx_pause *arg = data;
3070 if (arvif->vdev_id != arg->vdev_id)
3073 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3076 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3077 enum wmi_tlv_tx_pause_id pause_id,
3078 enum wmi_tlv_tx_pause_action action)
3080 struct ath10k_mac_tx_pause arg = {
3082 .pause_id = pause_id,
3086 spin_lock_bh(&ar->htt.tx_lock);
3087 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3088 IEEE80211_IFACE_ITER_RESUME_ALL,
3089 ath10k_mac_handle_tx_pause_iter,
3091 spin_unlock_bh(&ar->htt.tx_lock);
3094 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3096 if (ieee80211_is_mgmt(hdr->frame_control))
3097 return HTT_DATA_TX_EXT_TID_MGMT;
3099 if (!ieee80211_is_data_qos(hdr->frame_control))
3100 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3102 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3103 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3105 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3108 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
3111 return ath10k_vif_to_arvif(vif)->vdev_id;
3113 if (ar->monitor_started)
3114 return ar->monitor_vdev_id;
3116 ath10k_warn(ar, "failed to resolve vdev id\n");
3120 static enum ath10k_hw_txrx_mode
3121 ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
3122 struct ieee80211_sta *sta, struct sk_buff *skb)
3124 const struct ieee80211_hdr *hdr = (void *)skb->data;
3125 __le16 fc = hdr->frame_control;
3127 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3128 return ATH10K_HW_TXRX_RAW;
3130 if (ieee80211_is_mgmt(fc))
3131 return ATH10K_HW_TXRX_MGMT;
3135 * NullFunc frames are mostly used to ping if a client or AP are still
3136 * reachable and responsive. This implies tx status reports must be
3137 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3138 * come to a conclusion that the other end disappeared and tear down
3139 * BSS connection or it can never disconnect from BSS/client (which is
3142 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3143 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3144 * which seems to deliver correct tx reports for NullFunc frames. The
3145 * downside of using it is it ignores client powersave state so it can
3146 * end up disconnecting sleeping clients in AP mode. It should fix STA
3147 * mode though because AP don't sleep.
3149 if (ar->htt.target_version_major < 3 &&
3150 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3151 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3152 return ATH10K_HW_TXRX_MGMT;
3156 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3157 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3158 * to work with Ethernet txmode so use it.
3160 * FIXME: Check if raw mode works with TDLS.
3162 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3163 return ATH10K_HW_TXRX_ETHERNET;
3165 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3166 return ATH10K_HW_TXRX_RAW;
3168 return ATH10K_HW_TXRX_NATIVE_WIFI;
3171 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3172 struct sk_buff *skb) {
3173 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3174 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3175 IEEE80211_TX_CTL_INJECTED;
3176 if ((info->flags & mask) == mask)
3179 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3183 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3184 * Control in the header.
3186 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3188 struct ieee80211_hdr *hdr = (void *)skb->data;
3189 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3192 if (!ieee80211_is_data_qos(hdr->frame_control))
3195 qos_ctl = ieee80211_get_qos_ctl(hdr);
3196 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3197 skb->data, (void *)qos_ctl - (void *)skb->data);
3198 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3200 /* Some firmware revisions don't handle sending QoS NullFunc well.
3201 * These frames are mainly used for CQM purposes so it doesn't really
3202 * matter whether QoS NullFunc or NullFunc are sent.
3204 hdr = (void *)skb->data;
3205 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3206 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3208 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3211 static void ath10k_tx_h_8023(struct sk_buff *skb)
3213 struct ieee80211_hdr *hdr;
3214 struct rfc1042_hdr *rfc1042;
3221 hdr = (void *)skb->data;
3222 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3223 rfc1042 = (void *)skb->data + hdrlen;
3225 ether_addr_copy(da, ieee80211_get_DA(hdr));
3226 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3227 type = rfc1042->snap_type;
3229 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3230 skb_push(skb, sizeof(*eth));
3232 eth = (void *)skb->data;
3233 ether_addr_copy(eth->h_dest, da);
3234 ether_addr_copy(eth->h_source, sa);
3235 eth->h_proto = type;
3238 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3239 struct ieee80211_vif *vif,
3240 struct sk_buff *skb)
3242 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3243 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3245 /* This is case only for P2P_GO */
3246 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3247 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3250 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3251 spin_lock_bh(&ar->data_lock);
3252 if (arvif->u.ap.noa_data)
3253 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3255 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3256 arvif->u.ap.noa_data,
3257 arvif->u.ap.noa_len);
3258 spin_unlock_bh(&ar->data_lock);
3262 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3264 /* FIXME: Not really sure since when the behaviour changed. At some
3265 * point new firmware stopped requiring creation of peer entries for
3266 * offchannel tx (and actually creating them causes issues with wmi-htc
3267 * tx credit replenishment and reliability). Assuming it's at least 3.4
3268 * because that's when the `freq` was introduced to TX_FRM HTT command.
3270 return !(ar->htt.target_version_major >= 3 &&
3271 ar->htt.target_version_minor >= 4);
3274 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3276 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3279 spin_lock_bh(&ar->data_lock);
3281 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3282 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3287 __skb_queue_tail(q, skb);
3288 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3291 spin_unlock_bh(&ar->data_lock);
3296 static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3298 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3299 struct ath10k_htt *htt = &ar->htt;
3302 switch (cb->txmode) {
3303 case ATH10K_HW_TXRX_RAW:
3304 case ATH10K_HW_TXRX_NATIVE_WIFI:
3305 case ATH10K_HW_TXRX_ETHERNET:
3306 ret = ath10k_htt_tx(htt, skb);
3308 case ATH10K_HW_TXRX_MGMT:
3309 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3311 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3312 else if (ar->htt.target_version_major >= 3)
3313 ret = ath10k_htt_tx(htt, skb);
3315 ret = ath10k_htt_mgmt_tx(htt, skb);
3320 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3322 ieee80211_free_txskb(ar->hw, skb);
3326 void ath10k_offchan_tx_purge(struct ath10k *ar)
3328 struct sk_buff *skb;
3331 skb = skb_dequeue(&ar->offchan_tx_queue);
3335 ieee80211_free_txskb(ar->hw, skb);
3339 void ath10k_offchan_tx_work(struct work_struct *work)
3341 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3342 struct ath10k_peer *peer;
3343 struct ieee80211_hdr *hdr;
3344 struct sk_buff *skb;
3345 const u8 *peer_addr;
3348 unsigned long time_left;
3350 /* FW requirement: We must create a peer before FW will send out
3351 * an offchannel frame. Otherwise the frame will be stuck and
3352 * never transmitted. We delete the peer upon tx completion.
3353 * It is unlikely that a peer for offchannel tx will already be
3354 * present. However it may be in some rare cases so account for that.
3355 * Otherwise we might remove a legitimate peer and break stuff. */
3358 skb = skb_dequeue(&ar->offchan_tx_queue);
3362 mutex_lock(&ar->conf_mutex);
3364 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
3367 hdr = (struct ieee80211_hdr *)skb->data;
3368 peer_addr = ieee80211_get_DA(hdr);
3369 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
3371 spin_lock_bh(&ar->data_lock);
3372 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3373 spin_unlock_bh(&ar->data_lock);
3376 /* FIXME: should this use ath10k_warn()? */
3377 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3378 peer_addr, vdev_id);
3381 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3382 WMI_PEER_TYPE_DEFAULT);
3384 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3385 peer_addr, vdev_id, ret);
3388 spin_lock_bh(&ar->data_lock);
3389 reinit_completion(&ar->offchan_tx_completed);
3390 ar->offchan_tx_skb = skb;
3391 spin_unlock_bh(&ar->data_lock);
3393 ath10k_mac_tx(ar, skb);
3396 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3398 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
3402 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3404 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3405 peer_addr, vdev_id, ret);
3408 mutex_unlock(&ar->conf_mutex);
3412 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3414 struct sk_buff *skb;
3417 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3421 ieee80211_free_txskb(ar->hw, skb);
3425 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3427 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3428 struct sk_buff *skb;
3432 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3436 ret = ath10k_wmi_mgmt_tx(ar, skb);
3438 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3440 ieee80211_free_txskb(ar->hw, skb);
3449 void __ath10k_scan_finish(struct ath10k *ar)
3451 lockdep_assert_held(&ar->data_lock);
3453 switch (ar->scan.state) {
3454 case ATH10K_SCAN_IDLE:
3456 case ATH10K_SCAN_RUNNING:
3457 case ATH10K_SCAN_ABORTING:
3458 if (!ar->scan.is_roc)
3459 ieee80211_scan_completed(ar->hw,
3461 ATH10K_SCAN_ABORTING));
3462 else if (ar->scan.roc_notify)
3463 ieee80211_remain_on_channel_expired(ar->hw);
3465 case ATH10K_SCAN_STARTING:
3466 ar->scan.state = ATH10K_SCAN_IDLE;
3467 ar->scan_channel = NULL;
3468 ath10k_offchan_tx_purge(ar);
3469 cancel_delayed_work(&ar->scan.timeout);
3470 complete_all(&ar->scan.completed);
3475 void ath10k_scan_finish(struct ath10k *ar)
3477 spin_lock_bh(&ar->data_lock);
3478 __ath10k_scan_finish(ar);
3479 spin_unlock_bh(&ar->data_lock);
3482 static int ath10k_scan_stop(struct ath10k *ar)
3484 struct wmi_stop_scan_arg arg = {
3485 .req_id = 1, /* FIXME */
3486 .req_type = WMI_SCAN_STOP_ONE,
3487 .u.scan_id = ATH10K_SCAN_ID,
3491 lockdep_assert_held(&ar->conf_mutex);
3493 ret = ath10k_wmi_stop_scan(ar, &arg);
3495 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3499 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
3501 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3503 } else if (ret > 0) {
3508 /* Scan state should be updated upon scan completion but in case
3509 * firmware fails to deliver the event (for whatever reason) it is
3510 * desired to clean up scan state anyway. Firmware may have just
3511 * dropped the scan completion event delivery due to transport pipe
3512 * being overflown with data and/or it can recover on its own before
3513 * next scan request is submitted.
3515 spin_lock_bh(&ar->data_lock);
3516 if (ar->scan.state != ATH10K_SCAN_IDLE)
3517 __ath10k_scan_finish(ar);
3518 spin_unlock_bh(&ar->data_lock);
3523 static void ath10k_scan_abort(struct ath10k *ar)
3527 lockdep_assert_held(&ar->conf_mutex);
3529 spin_lock_bh(&ar->data_lock);
3531 switch (ar->scan.state) {
3532 case ATH10K_SCAN_IDLE:
3533 /* This can happen if timeout worker kicked in and called
3534 * abortion while scan completion was being processed.
3537 case ATH10K_SCAN_STARTING:
3538 case ATH10K_SCAN_ABORTING:
3539 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3540 ath10k_scan_state_str(ar->scan.state),
3543 case ATH10K_SCAN_RUNNING:
3544 ar->scan.state = ATH10K_SCAN_ABORTING;
3545 spin_unlock_bh(&ar->data_lock);
3547 ret = ath10k_scan_stop(ar);
3549 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3551 spin_lock_bh(&ar->data_lock);
3555 spin_unlock_bh(&ar->data_lock);
3558 void ath10k_scan_timeout_work(struct work_struct *work)
3560 struct ath10k *ar = container_of(work, struct ath10k,
3563 mutex_lock(&ar->conf_mutex);
3564 ath10k_scan_abort(ar);
3565 mutex_unlock(&ar->conf_mutex);
3568 static int ath10k_start_scan(struct ath10k *ar,
3569 const struct wmi_start_scan_arg *arg)
3573 lockdep_assert_held(&ar->conf_mutex);
3575 ret = ath10k_wmi_start_scan(ar, arg);
3579 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3581 ret = ath10k_scan_stop(ar);
3583 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3588 /* If we failed to start the scan, return error code at
3589 * this point. This is probably due to some issue in the
3590 * firmware, but no need to wedge the driver due to that...
3592 spin_lock_bh(&ar->data_lock);
3593 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3594 spin_unlock_bh(&ar->data_lock);
3597 spin_unlock_bh(&ar->data_lock);
3599 /* Add a 200ms margin to account for event/command processing */
3600 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3601 msecs_to_jiffies(arg->max_scan_time+200));
3605 /**********************/
3606 /* mac80211 callbacks */
3607 /**********************/
3609 static void ath10k_tx(struct ieee80211_hw *hw,
3610 struct ieee80211_tx_control *control,
3611 struct sk_buff *skb)
3613 struct ath10k *ar = hw->priv;
3614 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3615 struct ieee80211_vif *vif = info->control.vif;
3616 struct ieee80211_sta *sta = control->sta;
3617 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3618 __le16 fc = hdr->frame_control;
3620 /* We should disable CCK RATE due to P2P */
3621 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3622 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3624 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
3625 ATH10K_SKB_CB(skb)->htt.freq = 0;
3626 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
3627 ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb);
3628 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
3629 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
3630 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
3632 switch (ATH10K_SKB_CB(skb)->txmode) {
3633 case ATH10K_HW_TXRX_MGMT:
3634 case ATH10K_HW_TXRX_NATIVE_WIFI:
3635 ath10k_tx_h_nwifi(hw, skb);
3636 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3637 ath10k_tx_h_seq_no(vif, skb);
3639 case ATH10K_HW_TXRX_ETHERNET:
3640 ath10k_tx_h_8023(skb);
3642 case ATH10K_HW_TXRX_RAW:
3643 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3645 ieee80211_free_txskb(hw, skb);
3650 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3651 spin_lock_bh(&ar->data_lock);
3652 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
3653 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
3654 spin_unlock_bh(&ar->data_lock);
3656 if (ath10k_mac_need_offchan_tx_work(ar)) {
3657 ATH10K_SKB_CB(skb)->htt.freq = 0;
3658 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
3660 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3663 skb_queue_tail(&ar->offchan_tx_queue, skb);
3664 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3669 ath10k_mac_tx(ar, skb);
3672 /* Must not be called with conf_mutex held as workers can use that also. */
3673 void ath10k_drain_tx(struct ath10k *ar)
3675 /* make sure rcu-protected mac80211 tx path itself is drained */
3678 ath10k_offchan_tx_purge(ar);
3679 ath10k_mgmt_over_wmi_tx_purge(ar);
3681 cancel_work_sync(&ar->offchan_tx_work);
3682 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3685 void ath10k_halt(struct ath10k *ar)
3687 struct ath10k_vif *arvif;
3689 lockdep_assert_held(&ar->conf_mutex);
3691 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3692 ar->filter_flags = 0;
3693 ar->monitor = false;
3694 ar->monitor_arvif = NULL;
3696 if (ar->monitor_started)
3697 ath10k_monitor_stop(ar);
3699 ar->monitor_started = false;
3702 ath10k_scan_finish(ar);
3703 ath10k_peer_cleanup_all(ar);
3704 ath10k_core_stop(ar);
3705 ath10k_hif_power_down(ar);
3707 spin_lock_bh(&ar->data_lock);
3708 list_for_each_entry(arvif, &ar->arvifs, list)
3709 ath10k_mac_vif_beacon_cleanup(arvif);
3710 spin_unlock_bh(&ar->data_lock);
3713 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3715 struct ath10k *ar = hw->priv;
3717 mutex_lock(&ar->conf_mutex);
3719 if (ar->cfg_tx_chainmask) {
3720 *tx_ant = ar->cfg_tx_chainmask;
3721 *rx_ant = ar->cfg_rx_chainmask;
3723 *tx_ant = ar->supp_tx_chainmask;
3724 *rx_ant = ar->supp_rx_chainmask;
3727 mutex_unlock(&ar->conf_mutex);
3732 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3734 /* It is not clear that allowing gaps in chainmask
3735 * is helpful. Probably it will not do what user
3736 * is hoping for, so warn in that case.
3738 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3741 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3745 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3749 lockdep_assert_held(&ar->conf_mutex);
3751 ath10k_check_chain_mask(ar, tx_ant, "tx");
3752 ath10k_check_chain_mask(ar, rx_ant, "rx");
3754 ar->cfg_tx_chainmask = tx_ant;
3755 ar->cfg_rx_chainmask = rx_ant;
3757 if ((ar->state != ATH10K_STATE_ON) &&
3758 (ar->state != ATH10K_STATE_RESTARTED))
3761 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3764 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
3769 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3772 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
3780 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3782 struct ath10k *ar = hw->priv;
3785 mutex_lock(&ar->conf_mutex);
3786 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3787 mutex_unlock(&ar->conf_mutex);
3791 static int ath10k_start(struct ieee80211_hw *hw)
3793 struct ath10k *ar = hw->priv;
3798 * This makes sense only when restarting hw. It is harmless to call
3799 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3800 * commands will be submitted while restarting.
3802 ath10k_drain_tx(ar);
3804 mutex_lock(&ar->conf_mutex);
3806 switch (ar->state) {
3807 case ATH10K_STATE_OFF:
3808 ar->state = ATH10K_STATE_ON;
3810 case ATH10K_STATE_RESTARTING:
3812 ar->state = ATH10K_STATE_RESTARTED;
3814 case ATH10K_STATE_ON:
3815 case ATH10K_STATE_RESTARTED:
3816 case ATH10K_STATE_WEDGED:
3820 case ATH10K_STATE_UTF:
3825 ret = ath10k_hif_power_up(ar);
3827 ath10k_err(ar, "Could not init hif: %d\n", ret);
3831 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
3833 ath10k_err(ar, "Could not init core: %d\n", ret);
3834 goto err_power_down;
3837 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
3839 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
3843 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
3845 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
3849 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3850 ret = ath10k_wmi_adaptive_qcs(ar, true);
3852 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3858 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3859 burst_enable = ar->wmi.pdev_param->burst_enable;
3860 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3862 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3867 if (ar->cfg_tx_chainmask)
3868 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3869 ar->cfg_rx_chainmask);
3872 * By default FW set ARP frames ac to voice (6). In that case ARP
3873 * exchange is not working properly for UAPSD enabled AP. ARP requests
3874 * which arrives with access category 0 are processed by network stack
3875 * and send back with access category 0, but FW changes access category
3876 * to 6. Set ARP frames access category to best effort (0) solves
3880 ret = ath10k_wmi_pdev_set_param(ar,
3881 ar->wmi.pdev_param->arp_ac_override, 0);
3883 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
3888 ret = ath10k_wmi_pdev_set_param(ar,
3889 ar->wmi.pdev_param->ani_enable, 1);
3891 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3896 ar->ani_enabled = true;
3898 ar->num_started_vdevs = 0;
3899 ath10k_regd_update(ar);
3901 ath10k_spectral_start(ar);
3902 ath10k_thermal_set_throttling(ar);
3904 mutex_unlock(&ar->conf_mutex);
3908 ath10k_core_stop(ar);
3911 ath10k_hif_power_down(ar);
3914 ar->state = ATH10K_STATE_OFF;
3917 mutex_unlock(&ar->conf_mutex);
3921 static void ath10k_stop(struct ieee80211_hw *hw)
3923 struct ath10k *ar = hw->priv;
3925 ath10k_drain_tx(ar);
3927 mutex_lock(&ar->conf_mutex);
3928 if (ar->state != ATH10K_STATE_OFF) {
3930 ar->state = ATH10K_STATE_OFF;
3932 mutex_unlock(&ar->conf_mutex);
3934 cancel_delayed_work_sync(&ar->scan.timeout);
3935 cancel_work_sync(&ar->restart_work);
3938 static int ath10k_config_ps(struct ath10k *ar)
3940 struct ath10k_vif *arvif;
3943 lockdep_assert_held(&ar->conf_mutex);
3945 list_for_each_entry(arvif, &ar->arvifs, list) {
3946 ret = ath10k_mac_vif_setup_ps(arvif);
3948 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
3956 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3961 lockdep_assert_held(&ar->conf_mutex);
3963 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3965 param = ar->wmi.pdev_param->txpower_limit2g;
3966 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3968 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3973 param = ar->wmi.pdev_param->txpower_limit5g;
3974 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3976 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3984 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3986 struct ath10k_vif *arvif;
3987 int ret, txpower = -1;
3989 lockdep_assert_held(&ar->conf_mutex);
3991 list_for_each_entry(arvif, &ar->arvifs, list) {
3992 WARN_ON(arvif->txpower < 0);
3995 txpower = arvif->txpower;
3997 txpower = min(txpower, arvif->txpower);
4000 if (WARN_ON(txpower == -1))
4003 ret = ath10k_mac_txpower_setup(ar, txpower);
4005 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4013 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4015 struct ath10k *ar = hw->priv;
4016 struct ieee80211_conf *conf = &hw->conf;
4019 mutex_lock(&ar->conf_mutex);
4021 if (changed & IEEE80211_CONF_CHANGE_PS)
4022 ath10k_config_ps(ar);
4024 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4025 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4026 ret = ath10k_monitor_recalc(ar);
4028 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4031 mutex_unlock(&ar->conf_mutex);
4035 static u32 get_nss_from_chainmask(u16 chain_mask)
4037 if ((chain_mask & 0x15) == 0x15)
4039 else if ((chain_mask & 0x7) == 0x7)
4041 else if ((chain_mask & 0x3) == 0x3)
4048 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4049 * because we will send mgmt frames without CCK. This requirement
4050 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4053 static int ath10k_add_interface(struct ieee80211_hw *hw,
4054 struct ieee80211_vif *vif)
4056 struct ath10k *ar = hw->priv;
4057 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4058 enum wmi_sta_powersave_param param;
4065 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4067 mutex_lock(&ar->conf_mutex);
4069 memset(arvif, 0, sizeof(*arvif));
4074 INIT_LIST_HEAD(&arvif->list);
4075 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4076 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4077 ath10k_mac_vif_sta_connection_loss_work);
4079 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4080 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4081 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4082 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4083 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4084 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4087 if (ar->free_vdev_map == 0) {
4088 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4092 bit = __ffs64(ar->free_vdev_map);
4094 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4095 bit, ar->free_vdev_map);
4097 arvif->vdev_id = bit;
4098 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4100 switch (vif->type) {
4101 case NL80211_IFTYPE_P2P_DEVICE:
4102 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4103 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4105 case NL80211_IFTYPE_UNSPECIFIED:
4106 case NL80211_IFTYPE_STATION:
4107 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4109 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4111 case NL80211_IFTYPE_ADHOC:
4112 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4114 case NL80211_IFTYPE_AP:
4115 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4118 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4120 case NL80211_IFTYPE_MONITOR:
4121 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4128 /* Using vdev_id as queue number will make it very easy to do per-vif
4129 * tx queue locking. This shouldn't wrap due to interface combinations
4130 * but do a modulo for correctness sake and prevent using offchannel tx
4131 * queues for regular vif tx.
4133 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4134 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4135 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4137 /* Some firmware revisions don't wait for beacon tx completion before
4138 * sending another SWBA event. This could lead to hardware using old
4139 * (freed) beacon data in some cases, e.g. tx credit starvation
4140 * combined with missed TBTT. This is very very rare.
4142 * On non-IOMMU-enabled hosts this could be a possible security issue
4143 * because hw could beacon some random data on the air. On
4144 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4145 * device would crash.
4147 * Since there are no beacon tx completions (implicit nor explicit)
4148 * propagated to host the only workaround for this is to allocate a
4149 * DMA-coherent buffer for a lifetime of a vif and use it for all
4150 * beacon tx commands. Worst case for this approach is some beacons may
4151 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4153 if (vif->type == NL80211_IFTYPE_ADHOC ||
4154 vif->type == NL80211_IFTYPE_AP) {
4155 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4156 IEEE80211_MAX_FRAME_LEN,
4157 &arvif->beacon_paddr,
4159 if (!arvif->beacon_buf) {
4161 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4166 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4167 arvif->nohwcrypt = true;
4169 if (arvif->nohwcrypt &&
4170 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4171 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4175 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4176 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4177 arvif->beacon_buf ? "single-buf" : "per-skb");
4179 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4180 arvif->vdev_subtype, vif->addr);
4182 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4183 arvif->vdev_id, ret);
4187 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4188 list_add(&arvif->list, &ar->arvifs);
4190 /* It makes no sense to have firmware do keepalives. mac80211 already
4191 * takes care of this with idle connection polling.
4193 ret = ath10k_mac_vif_disable_keepalive(arvif);
4195 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4196 arvif->vdev_id, ret);
4197 goto err_vdev_delete;
4200 arvif->def_wep_key_idx = -1;
4202 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4203 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4204 ATH10K_HW_TXRX_NATIVE_WIFI);
4205 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4206 if (ret && ret != -EOPNOTSUPP) {
4207 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4208 arvif->vdev_id, ret);
4209 goto err_vdev_delete;
4212 if (ar->cfg_tx_chainmask) {
4213 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4215 vdev_param = ar->wmi.vdev_param->nss;
4216 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4219 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4220 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4222 goto err_vdev_delete;
4226 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4227 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4228 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4229 WMI_PEER_TYPE_DEFAULT);
4231 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4232 arvif->vdev_id, ret);
4233 goto err_vdev_delete;
4237 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4238 ret = ath10k_mac_set_kickout(arvif);
4240 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
4241 arvif->vdev_id, ret);
4242 goto err_peer_delete;
4246 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4247 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4248 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4249 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4252 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
4253 arvif->vdev_id, ret);
4254 goto err_peer_delete;
4257 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4259 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4260 arvif->vdev_id, ret);
4261 goto err_peer_delete;
4264 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4266 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4267 arvif->vdev_id, ret);
4268 goto err_peer_delete;
4272 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
4274 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4275 arvif->vdev_id, ret);
4276 goto err_peer_delete;
4279 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
4281 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
4282 arvif->vdev_id, ret);
4283 goto err_peer_delete;
4286 arvif->txpower = vif->bss_conf.txpower;
4287 ret = ath10k_mac_txpower_recalc(ar);
4289 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4290 goto err_peer_delete;
4293 if (vif->type == NL80211_IFTYPE_MONITOR) {
4294 ar->monitor_arvif = arvif;
4295 ret = ath10k_monitor_recalc(ar);
4297 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4298 goto err_peer_delete;
4302 mutex_unlock(&ar->conf_mutex);
4306 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4307 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
4308 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4311 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4312 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4313 list_del(&arvif->list);
4316 if (arvif->beacon_buf) {
4317 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4318 arvif->beacon_buf, arvif->beacon_paddr);
4319 arvif->beacon_buf = NULL;
4322 mutex_unlock(&ar->conf_mutex);
4327 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4331 for (i = 0; i < BITS_PER_LONG; i++)
4332 ath10k_mac_vif_tx_unlock(arvif, i);
4335 static void ath10k_remove_interface(struct ieee80211_hw *hw,
4336 struct ieee80211_vif *vif)
4338 struct ath10k *ar = hw->priv;
4339 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4342 cancel_work_sync(&arvif->ap_csa_work);
4343 cancel_delayed_work_sync(&arvif->connection_loss_work);
4345 mutex_lock(&ar->conf_mutex);
4347 spin_lock_bh(&ar->data_lock);
4348 ath10k_mac_vif_beacon_cleanup(arvif);
4349 spin_unlock_bh(&ar->data_lock);
4351 ret = ath10k_spectral_vif_stop(arvif);
4353 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
4354 arvif->vdev_id, ret);
4356 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4357 list_del(&arvif->list);
4359 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4360 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4361 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4364 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4365 arvif->vdev_id, ret);
4367 kfree(arvif->u.ap.noa_data);
4370 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
4373 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4375 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
4376 arvif->vdev_id, ret);
4378 /* Some firmware revisions don't notify host about self-peer removal
4379 * until after associated vdev is deleted.
4381 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4382 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4383 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4386 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4387 arvif->vdev_id, ret);
4389 spin_lock_bh(&ar->data_lock);
4391 spin_unlock_bh(&ar->data_lock);
4394 ath10k_peer_cleanup(ar, arvif->vdev_id);
4396 if (vif->type == NL80211_IFTYPE_MONITOR) {
4397 ar->monitor_arvif = NULL;
4398 ret = ath10k_monitor_recalc(ar);
4400 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4403 spin_lock_bh(&ar->htt.tx_lock);
4404 ath10k_mac_vif_tx_unlock_all(arvif);
4405 spin_unlock_bh(&ar->htt.tx_lock);
4407 mutex_unlock(&ar->conf_mutex);
4411 * FIXME: Has to be verified.
4413 #define SUPPORTED_FILTERS \
4418 FIF_BCN_PRBRESP_PROMISC | \
4422 static void ath10k_configure_filter(struct ieee80211_hw *hw,
4423 unsigned int changed_flags,
4424 unsigned int *total_flags,
4427 struct ath10k *ar = hw->priv;
4430 mutex_lock(&ar->conf_mutex);
4432 changed_flags &= SUPPORTED_FILTERS;
4433 *total_flags &= SUPPORTED_FILTERS;
4434 ar->filter_flags = *total_flags;
4436 ret = ath10k_monitor_recalc(ar);
4438 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
4440 mutex_unlock(&ar->conf_mutex);
4443 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4444 struct ieee80211_vif *vif,
4445 struct ieee80211_bss_conf *info,
4448 struct ath10k *ar = hw->priv;
4449 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4451 u32 vdev_param, pdev_param, slottime, preamble;
4453 mutex_lock(&ar->conf_mutex);
4455 if (changed & BSS_CHANGED_IBSS)
4456 ath10k_control_ibss(arvif, info, vif->addr);
4458 if (changed & BSS_CHANGED_BEACON_INT) {
4459 arvif->beacon_interval = info->beacon_int;
4460 vdev_param = ar->wmi.vdev_param->beacon_interval;
4461 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4462 arvif->beacon_interval);
4463 ath10k_dbg(ar, ATH10K_DBG_MAC,
4464 "mac vdev %d beacon_interval %d\n",
4465 arvif->vdev_id, arvif->beacon_interval);
4468 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
4469 arvif->vdev_id, ret);
4472 if (changed & BSS_CHANGED_BEACON) {
4473 ath10k_dbg(ar, ATH10K_DBG_MAC,
4474 "vdev %d set beacon tx mode to staggered\n",
4477 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4478 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
4479 WMI_BEACON_STAGGERED_MODE);
4481 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
4482 arvif->vdev_id, ret);
4484 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4486 ath10k_warn(ar, "failed to update beacon template: %d\n",
4490 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4491 ret = ath10k_mac_setup_prb_tmpl(arvif);
4493 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4494 arvif->vdev_id, ret);
4497 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
4498 arvif->dtim_period = info->dtim_period;
4500 ath10k_dbg(ar, ATH10K_DBG_MAC,
4501 "mac vdev %d dtim_period %d\n",
4502 arvif->vdev_id, arvif->dtim_period);
4504 vdev_param = ar->wmi.vdev_param->dtim_period;
4505 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4506 arvif->dtim_period);
4508 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
4509 arvif->vdev_id, ret);
4512 if (changed & BSS_CHANGED_SSID &&
4513 vif->type == NL80211_IFTYPE_AP) {
4514 arvif->u.ap.ssid_len = info->ssid_len;
4516 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4517 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4520 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4521 ether_addr_copy(arvif->bssid, info->bssid);
4523 if (changed & BSS_CHANGED_BEACON_ENABLED)
4524 ath10k_control_beaconing(arvif, info);
4526 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
4527 arvif->use_cts_prot = info->use_cts_prot;
4528 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
4529 arvif->vdev_id, info->use_cts_prot);
4531 ret = ath10k_recalc_rtscts_prot(arvif);
4533 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4534 arvif->vdev_id, ret);
4536 vdev_param = ar->wmi.vdev_param->protection_mode;
4537 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4538 info->use_cts_prot ? 1 : 0);
4540 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4541 info->use_cts_prot, arvif->vdev_id, ret);
4544 if (changed & BSS_CHANGED_ERP_SLOT) {
4545 if (info->use_short_slot)
4546 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4549 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4551 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
4552 arvif->vdev_id, slottime);
4554 vdev_param = ar->wmi.vdev_param->slot_time;
4555 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4558 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
4559 arvif->vdev_id, ret);
4562 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4563 if (info->use_short_preamble)
4564 preamble = WMI_VDEV_PREAMBLE_SHORT;
4566 preamble = WMI_VDEV_PREAMBLE_LONG;
4568 ath10k_dbg(ar, ATH10K_DBG_MAC,
4569 "mac vdev %d preamble %dn",
4570 arvif->vdev_id, preamble);
4572 vdev_param = ar->wmi.vdev_param->preamble;
4573 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4576 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
4577 arvif->vdev_id, ret);
4580 if (changed & BSS_CHANGED_ASSOC) {
4582 /* Workaround: Make sure monitor vdev is not running
4583 * when associating to prevent some firmware revisions
4584 * (e.g. 10.1 and 10.2) from crashing.
4586 if (ar->monitor_started)
4587 ath10k_monitor_stop(ar);
4588 ath10k_bss_assoc(hw, vif, info);
4589 ath10k_monitor_recalc(ar);
4591 ath10k_bss_disassoc(hw, vif);
4595 if (changed & BSS_CHANGED_TXPOWER) {
4596 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4597 arvif->vdev_id, info->txpower);
4599 arvif->txpower = info->txpower;
4600 ret = ath10k_mac_txpower_recalc(ar);
4602 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4605 if (changed & BSS_CHANGED_PS) {
4606 arvif->ps = vif->bss_conf.ps;
4608 ret = ath10k_config_ps(ar);
4610 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4611 arvif->vdev_id, ret);
4614 mutex_unlock(&ar->conf_mutex);
4617 static int ath10k_hw_scan(struct ieee80211_hw *hw,
4618 struct ieee80211_vif *vif,
4619 struct ieee80211_scan_request *hw_req)
4621 struct ath10k *ar = hw->priv;
4622 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4623 struct cfg80211_scan_request *req = &hw_req->req;
4624 struct wmi_start_scan_arg arg;
4628 mutex_lock(&ar->conf_mutex);
4630 spin_lock_bh(&ar->data_lock);
4631 switch (ar->scan.state) {
4632 case ATH10K_SCAN_IDLE:
4633 reinit_completion(&ar->scan.started);
4634 reinit_completion(&ar->scan.completed);
4635 ar->scan.state = ATH10K_SCAN_STARTING;
4636 ar->scan.is_roc = false;
4637 ar->scan.vdev_id = arvif->vdev_id;
4640 case ATH10K_SCAN_STARTING:
4641 case ATH10K_SCAN_RUNNING:
4642 case ATH10K_SCAN_ABORTING:
4646 spin_unlock_bh(&ar->data_lock);
4651 memset(&arg, 0, sizeof(arg));
4652 ath10k_wmi_start_scan_init(ar, &arg);
4653 arg.vdev_id = arvif->vdev_id;
4654 arg.scan_id = ATH10K_SCAN_ID;
4657 arg.ie_len = req->ie_len;
4658 memcpy(arg.ie, req->ie, arg.ie_len);
4662 arg.n_ssids = req->n_ssids;
4663 for (i = 0; i < arg.n_ssids; i++) {
4664 arg.ssids[i].len = req->ssids[i].ssid_len;
4665 arg.ssids[i].ssid = req->ssids[i].ssid;
4668 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4671 if (req->n_channels) {
4672 arg.n_channels = req->n_channels;
4673 for (i = 0; i < arg.n_channels; i++)
4674 arg.channels[i] = req->channels[i]->center_freq;
4677 ret = ath10k_start_scan(ar, &arg);
4679 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
4680 spin_lock_bh(&ar->data_lock);
4681 ar->scan.state = ATH10K_SCAN_IDLE;
4682 spin_unlock_bh(&ar->data_lock);
4686 mutex_unlock(&ar->conf_mutex);
4690 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4691 struct ieee80211_vif *vif)
4693 struct ath10k *ar = hw->priv;
4695 mutex_lock(&ar->conf_mutex);
4696 ath10k_scan_abort(ar);
4697 mutex_unlock(&ar->conf_mutex);
4699 cancel_delayed_work_sync(&ar->scan.timeout);
4702 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4703 struct ath10k_vif *arvif,
4704 enum set_key_cmd cmd,
4705 struct ieee80211_key_conf *key)
4707 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4710 /* 10.1 firmware branch requires default key index to be set to group
4711 * key index after installing it. Otherwise FW/HW Txes corrupted
4712 * frames with multi-vif APs. This is not required for main firmware
4713 * branch (e.g. 636).
4715 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4717 * FIXME: It remains unknown if this is required for multi-vif STA
4718 * interfaces on 10.1.
4721 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4722 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4725 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4728 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4731 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4737 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4740 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
4741 arvif->vdev_id, ret);
4744 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4745 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4746 struct ieee80211_key_conf *key)
4748 struct ath10k *ar = hw->priv;
4749 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4750 struct ath10k_peer *peer;
4751 const u8 *peer_addr;
4752 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4753 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4759 /* this one needs to be done in software */
4760 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4763 if (arvif->nohwcrypt)
4766 if (key->keyidx > WMI_MAX_KEY_INDEX)
4769 mutex_lock(&ar->conf_mutex);
4772 peer_addr = sta->addr;
4773 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4774 peer_addr = vif->bss_conf.bssid;
4776 peer_addr = vif->addr;
4778 key->hw_key_idx = key->keyidx;
4782 arvif->wep_keys[key->keyidx] = key;
4784 arvif->wep_keys[key->keyidx] = NULL;
4787 /* the peer should not disappear in mid-way (unless FW goes awry) since
4788 * we already hold conf_mutex. we just make sure its there now. */
4789 spin_lock_bh(&ar->data_lock);
4790 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4791 spin_unlock_bh(&ar->data_lock);
4794 if (cmd == SET_KEY) {
4795 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
4800 /* if the peer doesn't exist there is no key to disable
4806 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4807 flags |= WMI_KEY_PAIRWISE;
4809 flags |= WMI_KEY_GROUP;
4812 if (cmd == DISABLE_KEY)
4813 ath10k_clear_vdev_key(arvif, key);
4815 /* When WEP keys are uploaded it's possible that there are
4816 * stations associated already (e.g. when merging) without any
4817 * keys. Static WEP needs an explicit per-peer key upload.
4819 if (vif->type == NL80211_IFTYPE_ADHOC &&
4821 ath10k_mac_vif_update_wep_key(arvif, key);
4823 /* 802.1x never sets the def_wep_key_idx so each set_key()
4824 * call changes default tx key.
4826 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4827 * after first set_key().
4829 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4830 flags |= WMI_KEY_TX_USAGE;
4833 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
4836 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
4837 arvif->vdev_id, peer_addr, ret);
4841 /* mac80211 sets static WEP keys as groupwise while firmware requires
4842 * them to be installed twice as both pairwise and groupwise.
4844 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4846 flags2 &= ~WMI_KEY_GROUP;
4847 flags2 |= WMI_KEY_PAIRWISE;
4849 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4852 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4853 arvif->vdev_id, peer_addr, ret);
4854 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4858 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4859 arvif->vdev_id, peer_addr, ret2);
4865 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4867 spin_lock_bh(&ar->data_lock);
4868 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4869 if (peer && cmd == SET_KEY)
4870 peer->keys[key->keyidx] = key;
4871 else if (peer && cmd == DISABLE_KEY)
4872 peer->keys[key->keyidx] = NULL;
4873 else if (peer == NULL)
4874 /* impossible unless FW goes crazy */
4875 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
4876 spin_unlock_bh(&ar->data_lock);
4879 mutex_unlock(&ar->conf_mutex);
4883 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4884 struct ieee80211_vif *vif,
4887 struct ath10k *ar = hw->priv;
4888 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4891 mutex_lock(&arvif->ar->conf_mutex);
4893 if (arvif->ar->state != ATH10K_STATE_ON)
4896 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4897 arvif->vdev_id, keyidx);
4899 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4901 arvif->ar->wmi.vdev_param->def_keyid,
4905 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4911 arvif->def_wep_key_idx = keyidx;
4914 mutex_unlock(&arvif->ar->conf_mutex);
4917 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4920 struct ath10k_vif *arvif;
4921 struct ath10k_sta *arsta;
4922 struct ieee80211_sta *sta;
4923 struct cfg80211_chan_def def;
4924 enum ieee80211_band band;
4925 const u8 *ht_mcs_mask;
4926 const u16 *vht_mcs_mask;
4927 u32 changed, bw, nss, smps;
4930 arsta = container_of(wk, struct ath10k_sta, update_wk);
4931 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4932 arvif = arsta->arvif;
4935 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4938 band = def.chan->band;
4939 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4940 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4942 spin_lock_bh(&ar->data_lock);
4944 changed = arsta->changed;
4951 spin_unlock_bh(&ar->data_lock);
4953 mutex_lock(&ar->conf_mutex);
4955 nss = max_t(u32, 1, nss);
4956 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
4957 ath10k_mac_max_vht_nss(vht_mcs_mask)));
4959 if (changed & IEEE80211_RC_BW_CHANGED) {
4960 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
4963 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4964 WMI_PEER_CHAN_WIDTH, bw);
4966 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
4967 sta->addr, bw, err);
4970 if (changed & IEEE80211_RC_NSS_CHANGED) {
4971 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
4974 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4977 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
4978 sta->addr, nss, err);
4981 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4982 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
4985 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4986 WMI_PEER_SMPS_STATE, smps);
4988 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
4989 sta->addr, smps, err);
4992 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4993 changed & IEEE80211_RC_NSS_CHANGED) {
4994 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
4997 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
4999 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5003 mutex_unlock(&ar->conf_mutex);
5006 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5007 struct ieee80211_sta *sta)
5009 struct ath10k *ar = arvif->ar;
5011 lockdep_assert_held(&ar->conf_mutex);
5013 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5016 if (ar->num_stations >= ar->max_num_stations)
5024 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5025 struct ieee80211_sta *sta)
5027 struct ath10k *ar = arvif->ar;
5029 lockdep_assert_held(&ar->conf_mutex);
5031 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5037 struct ath10k_mac_tdls_iter_data {
5038 u32 num_tdls_stations;
5039 struct ieee80211_vif *curr_vif;
5042 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5043 struct ieee80211_sta *sta)
5045 struct ath10k_mac_tdls_iter_data *iter_data = data;
5046 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5047 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5049 if (sta->tdls && sta_vif == iter_data->curr_vif)
5050 iter_data->num_tdls_stations++;
5053 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5054 struct ieee80211_vif *vif)
5056 struct ath10k_mac_tdls_iter_data data = {};
5058 data.curr_vif = vif;
5060 ieee80211_iterate_stations_atomic(hw,
5061 ath10k_mac_tdls_vif_stations_count_iter,
5063 return data.num_tdls_stations;
5066 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5067 struct ieee80211_vif *vif)
5069 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5070 int *num_tdls_vifs = data;
5072 if (vif->type != NL80211_IFTYPE_STATION)
5075 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5079 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5081 int num_tdls_vifs = 0;
5083 ieee80211_iterate_active_interfaces_atomic(hw,
5084 IEEE80211_IFACE_ITER_NORMAL,
5085 ath10k_mac_tdls_vifs_count_iter,
5087 return num_tdls_vifs;
5090 static int ath10k_sta_state(struct ieee80211_hw *hw,
5091 struct ieee80211_vif *vif,
5092 struct ieee80211_sta *sta,
5093 enum ieee80211_sta_state old_state,
5094 enum ieee80211_sta_state new_state)
5096 struct ath10k *ar = hw->priv;
5097 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5098 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5101 if (old_state == IEEE80211_STA_NOTEXIST &&
5102 new_state == IEEE80211_STA_NONE) {
5103 memset(arsta, 0, sizeof(*arsta));
5104 arsta->arvif = arvif;
5105 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5108 /* cancel must be done outside the mutex to avoid deadlock */
5109 if ((old_state == IEEE80211_STA_NONE &&
5110 new_state == IEEE80211_STA_NOTEXIST))
5111 cancel_work_sync(&arsta->update_wk);
5113 mutex_lock(&ar->conf_mutex);
5115 if (old_state == IEEE80211_STA_NOTEXIST &&
5116 new_state == IEEE80211_STA_NONE) {
5118 * New station addition.
5120 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5121 u32 num_tdls_stations;
5124 ath10k_dbg(ar, ATH10K_DBG_MAC,
5125 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5126 arvif->vdev_id, sta->addr,
5127 ar->num_stations + 1, ar->max_num_stations,
5128 ar->num_peers + 1, ar->max_num_peers);
5130 ret = ath10k_mac_inc_num_stations(arvif, sta);
5132 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5133 ar->max_num_stations);
5138 peer_type = WMI_PEER_TYPE_TDLS;
5140 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
5143 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5144 sta->addr, arvif->vdev_id, ret);
5145 ath10k_mac_dec_num_stations(arvif, sta);
5152 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5153 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5155 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5156 num_tdls_stations == 0) {
5157 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5158 arvif->vdev_id, ar->max_num_tdls_vdevs);
5159 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5160 ath10k_mac_dec_num_stations(arvif, sta);
5165 if (num_tdls_stations == 0) {
5166 /* This is the first tdls peer in current vif */
5167 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5169 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5172 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5173 arvif->vdev_id, ret);
5174 ath10k_peer_delete(ar, arvif->vdev_id,
5176 ath10k_mac_dec_num_stations(arvif, sta);
5181 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5182 WMI_TDLS_PEER_STATE_PEERING);
5185 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5186 sta->addr, arvif->vdev_id, ret);
5187 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5188 ath10k_mac_dec_num_stations(arvif, sta);
5190 if (num_tdls_stations != 0)
5192 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5195 } else if ((old_state == IEEE80211_STA_NONE &&
5196 new_state == IEEE80211_STA_NOTEXIST)) {
5198 * Existing station deletion.
5200 ath10k_dbg(ar, ATH10K_DBG_MAC,
5201 "mac vdev %d peer delete %pM (sta gone)\n",
5202 arvif->vdev_id, sta->addr);
5204 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5206 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
5207 sta->addr, arvif->vdev_id, ret);
5209 ath10k_mac_dec_num_stations(arvif, sta);
5214 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5217 /* This was the last tdls peer in current vif */
5218 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5221 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5222 arvif->vdev_id, ret);
5224 } else if (old_state == IEEE80211_STA_AUTH &&
5225 new_state == IEEE80211_STA_ASSOC &&
5226 (vif->type == NL80211_IFTYPE_AP ||
5227 vif->type == NL80211_IFTYPE_ADHOC)) {
5231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
5234 ret = ath10k_station_assoc(ar, vif, sta, false);
5236 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
5237 sta->addr, arvif->vdev_id, ret);
5238 } else if (old_state == IEEE80211_STA_ASSOC &&
5239 new_state == IEEE80211_STA_AUTHORIZED &&
5242 * Tdls station authorized.
5244 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5247 ret = ath10k_station_assoc(ar, vif, sta, false);
5249 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5250 sta->addr, arvif->vdev_id, ret);
5254 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5255 WMI_TDLS_PEER_STATE_CONNECTED);
5257 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5258 sta->addr, arvif->vdev_id, ret);
5259 } else if (old_state == IEEE80211_STA_ASSOC &&
5260 new_state == IEEE80211_STA_AUTH &&
5261 (vif->type == NL80211_IFTYPE_AP ||
5262 vif->type == NL80211_IFTYPE_ADHOC)) {
5266 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
5269 ret = ath10k_station_disassoc(ar, vif, sta);
5271 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
5272 sta->addr, arvif->vdev_id, ret);
5275 mutex_unlock(&ar->conf_mutex);
5279 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
5280 u16 ac, bool enable)
5282 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5283 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5284 u32 prio = 0, acc = 0;
5288 lockdep_assert_held(&ar->conf_mutex);
5290 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5294 case IEEE80211_AC_VO:
5295 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5296 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
5300 case IEEE80211_AC_VI:
5301 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5302 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
5306 case IEEE80211_AC_BE:
5307 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5308 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
5312 case IEEE80211_AC_BK:
5313 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5314 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
5321 arvif->u.sta.uapsd |= value;
5323 arvif->u.sta.uapsd &= ~value;
5325 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5326 WMI_STA_PS_PARAM_UAPSD,
5327 arvif->u.sta.uapsd);
5329 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
5333 if (arvif->u.sta.uapsd)
5334 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5336 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5338 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5339 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5342 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
5344 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5346 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5347 arvif->vdev_id, ret);
5351 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5353 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5354 arvif->vdev_id, ret);
5358 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5359 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5360 /* Only userspace can make an educated decision when to send
5361 * trigger frame. The following effectively disables u-UAPSD
5362 * autotrigger in firmware (which is enabled by default
5363 * provided the autotrigger service is available).
5367 arg.user_priority = prio;
5368 arg.service_interval = 0;
5369 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5370 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5372 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5373 arvif->bssid, &arg, 1);
5375 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5385 static int ath10k_conf_tx(struct ieee80211_hw *hw,
5386 struct ieee80211_vif *vif, u16 ac,
5387 const struct ieee80211_tx_queue_params *params)
5389 struct ath10k *ar = hw->priv;
5390 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5391 struct wmi_wmm_params_arg *p = NULL;
5394 mutex_lock(&ar->conf_mutex);
5397 case IEEE80211_AC_VO:
5398 p = &arvif->wmm_params.ac_vo;
5400 case IEEE80211_AC_VI:
5401 p = &arvif->wmm_params.ac_vi;
5403 case IEEE80211_AC_BE:
5404 p = &arvif->wmm_params.ac_be;
5406 case IEEE80211_AC_BK:
5407 p = &arvif->wmm_params.ac_bk;
5416 p->cwmin = params->cw_min;
5417 p->cwmax = params->cw_max;
5418 p->aifs = params->aifs;
5421 * The channel time duration programmed in the HW is in absolute
5422 * microseconds, while mac80211 gives the txop in units of
5425 p->txop = params->txop * 32;
5427 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5428 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5429 &arvif->wmm_params);
5431 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5432 arvif->vdev_id, ret);
5436 /* This won't work well with multi-interface cases but it's
5437 * better than nothing.
5439 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5441 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5446 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5448 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
5451 mutex_unlock(&ar->conf_mutex);
5455 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5457 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5458 struct ieee80211_vif *vif,
5459 struct ieee80211_channel *chan,
5461 enum ieee80211_roc_type type)
5463 struct ath10k *ar = hw->priv;
5464 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5465 struct wmi_start_scan_arg arg;
5469 mutex_lock(&ar->conf_mutex);
5471 spin_lock_bh(&ar->data_lock);
5472 switch (ar->scan.state) {
5473 case ATH10K_SCAN_IDLE:
5474 reinit_completion(&ar->scan.started);
5475 reinit_completion(&ar->scan.completed);
5476 reinit_completion(&ar->scan.on_channel);
5477 ar->scan.state = ATH10K_SCAN_STARTING;
5478 ar->scan.is_roc = true;
5479 ar->scan.vdev_id = arvif->vdev_id;
5480 ar->scan.roc_freq = chan->center_freq;
5481 ar->scan.roc_notify = true;
5484 case ATH10K_SCAN_STARTING:
5485 case ATH10K_SCAN_RUNNING:
5486 case ATH10K_SCAN_ABORTING:
5490 spin_unlock_bh(&ar->data_lock);
5495 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
5497 memset(&arg, 0, sizeof(arg));
5498 ath10k_wmi_start_scan_init(ar, &arg);
5499 arg.vdev_id = arvif->vdev_id;
5500 arg.scan_id = ATH10K_SCAN_ID;
5502 arg.channels[0] = chan->center_freq;
5503 arg.dwell_time_active = scan_time_msec;
5504 arg.dwell_time_passive = scan_time_msec;
5505 arg.max_scan_time = scan_time_msec;
5506 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5507 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5508 arg.burst_duration_ms = duration;
5510 ret = ath10k_start_scan(ar, &arg);
5512 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
5513 spin_lock_bh(&ar->data_lock);
5514 ar->scan.state = ATH10K_SCAN_IDLE;
5515 spin_unlock_bh(&ar->data_lock);
5519 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5521 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
5523 ret = ath10k_scan_stop(ar);
5525 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
5531 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5532 msecs_to_jiffies(duration));
5536 mutex_unlock(&ar->conf_mutex);
5540 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5542 struct ath10k *ar = hw->priv;
5544 mutex_lock(&ar->conf_mutex);
5546 spin_lock_bh(&ar->data_lock);
5547 ar->scan.roc_notify = false;
5548 spin_unlock_bh(&ar->data_lock);
5550 ath10k_scan_abort(ar);
5552 mutex_unlock(&ar->conf_mutex);
5554 cancel_delayed_work_sync(&ar->scan.timeout);
5560 * Both RTS and Fragmentation threshold are interface-specific
5561 * in ath10k, but device-specific in mac80211.
5564 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5566 struct ath10k *ar = hw->priv;
5567 struct ath10k_vif *arvif;
5570 mutex_lock(&ar->conf_mutex);
5571 list_for_each_entry(arvif, &ar->arvifs, list) {
5572 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
5573 arvif->vdev_id, value);
5575 ret = ath10k_mac_set_rts(arvif, value);
5577 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5578 arvif->vdev_id, ret);
5582 mutex_unlock(&ar->conf_mutex);
5587 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5588 u32 queues, bool drop)
5590 struct ath10k *ar = hw->priv;
5594 /* mac80211 doesn't care if we really xmit queued frames or not
5595 * we'll collect those frames either way if we stop/delete vdevs */
5599 mutex_lock(&ar->conf_mutex);
5601 if (ar->state == ATH10K_STATE_WEDGED)
5604 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
5607 spin_lock_bh(&ar->htt.tx_lock);
5608 empty = (ar->htt.num_pending_tx == 0);
5609 spin_unlock_bh(&ar->htt.tx_lock);
5611 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5612 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5616 }), ATH10K_FLUSH_TIMEOUT_HZ);
5618 if (time_left == 0 || skip)
5619 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5620 skip, ar->state, time_left);
5623 mutex_unlock(&ar->conf_mutex);
5626 /* TODO: Implement this function properly
5627 * For now it is needed to reply to Probe Requests in IBSS mode.
5628 * Propably we need this information from FW.
5630 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5635 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5636 enum ieee80211_reconfig_type reconfig_type)
5638 struct ath10k *ar = hw->priv;
5640 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5643 mutex_lock(&ar->conf_mutex);
5645 /* If device failed to restart it will be in a different state, e.g.
5646 * ATH10K_STATE_WEDGED */
5647 if (ar->state == ATH10K_STATE_RESTARTED) {
5648 ath10k_info(ar, "device successfully recovered\n");
5649 ar->state = ATH10K_STATE_ON;
5650 ieee80211_wake_queues(ar->hw);
5653 mutex_unlock(&ar->conf_mutex);
5656 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5657 struct survey_info *survey)
5659 struct ath10k *ar = hw->priv;
5660 struct ieee80211_supported_band *sband;
5661 struct survey_info *ar_survey = &ar->survey[idx];
5664 mutex_lock(&ar->conf_mutex);
5666 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5667 if (sband && idx >= sband->n_channels) {
5668 idx -= sband->n_channels;
5673 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5675 if (!sband || idx >= sband->n_channels) {
5680 spin_lock_bh(&ar->data_lock);
5681 memcpy(survey, ar_survey, sizeof(*survey));
5682 spin_unlock_bh(&ar->data_lock);
5684 survey->channel = &sband->channels[idx];
5686 if (ar->rx_channel == survey->channel)
5687 survey->filled |= SURVEY_INFO_IN_USE;
5690 mutex_unlock(&ar->conf_mutex);
5695 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5696 enum ieee80211_band band,
5697 const struct cfg80211_bitrate_mask *mask)
5702 num_rates += hweight32(mask->control[band].legacy);
5704 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5705 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5707 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5708 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5710 return num_rates == 1;
5714 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5715 enum ieee80211_band band,
5716 const struct cfg80211_bitrate_mask *mask,
5719 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5720 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5722 u8 vht_nss_mask = 0;
5725 if (mask->control[band].legacy)
5728 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5729 if (mask->control[band].ht_mcs[i] == 0)
5731 else if (mask->control[band].ht_mcs[i] ==
5732 sband->ht_cap.mcs.rx_mask[i])
5733 ht_nss_mask |= BIT(i);
5738 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5739 if (mask->control[band].vht_mcs[i] == 0)
5741 else if (mask->control[band].vht_mcs[i] ==
5742 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5743 vht_nss_mask |= BIT(i);
5748 if (ht_nss_mask != vht_nss_mask)
5751 if (ht_nss_mask == 0)
5754 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5757 *nss = fls(ht_nss_mask);
5763 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5764 enum ieee80211_band band,
5765 const struct cfg80211_bitrate_mask *mask,
5768 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5775 if (hweight32(mask->control[band].legacy) == 1) {
5776 rate_idx = ffs(mask->control[band].legacy) - 1;
5778 hw_rate = sband->bitrates[rate_idx].hw_value;
5779 bitrate = sband->bitrates[rate_idx].bitrate;
5781 if (ath10k_mac_bitrate_is_cck(bitrate))
5782 preamble = WMI_RATE_PREAMBLE_CCK;
5784 preamble = WMI_RATE_PREAMBLE_OFDM;
5787 *rate = preamble << 6 |
5794 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5795 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5797 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5799 (ffs(mask->control[band].ht_mcs[i]) - 1);
5805 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5806 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5808 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5810 (ffs(mask->control[band].vht_mcs[i]) - 1);
5819 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5820 u8 rate, u8 nss, u8 sgi)
5822 struct ath10k *ar = arvif->ar;
5826 lockdep_assert_held(&ar->conf_mutex);
5828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5829 arvif->vdev_id, rate, nss, sgi);
5831 vdev_param = ar->wmi.vdev_param->fixed_rate;
5832 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
5834 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
5839 vdev_param = ar->wmi.vdev_param->nss;
5840 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
5842 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5846 vdev_param = ar->wmi.vdev_param->sgi;
5847 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
5849 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5857 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5858 enum ieee80211_band band,
5859 const struct cfg80211_bitrate_mask *mask)
5864 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5865 * to express all VHT MCS rate masks. Effectively only the following
5866 * ranges can be used: none, 0-7, 0-8 and 0-9.
5868 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5869 vht_mcs = mask->control[band].vht_mcs[i];
5878 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5886 static void ath10k_mac_set_bitrate_mask_iter(void *data,
5887 struct ieee80211_sta *sta)
5889 struct ath10k_vif *arvif = data;
5890 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5891 struct ath10k *ar = arvif->ar;
5893 if (arsta->arvif != arvif)
5896 spin_lock_bh(&ar->data_lock);
5897 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5898 spin_unlock_bh(&ar->data_lock);
5900 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5903 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5904 struct ieee80211_vif *vif,
5905 const struct cfg80211_bitrate_mask *mask)
5907 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5908 struct cfg80211_chan_def def;
5909 struct ath10k *ar = arvif->ar;
5910 enum ieee80211_band band;
5911 const u8 *ht_mcs_mask;
5912 const u16 *vht_mcs_mask;
5919 if (ath10k_mac_vif_chan(vif, &def))
5922 band = def.chan->band;
5923 ht_mcs_mask = mask->control[band].ht_mcs;
5924 vht_mcs_mask = mask->control[band].vht_mcs;
5926 sgi = mask->control[band].gi;
5927 if (sgi == NL80211_TXRATE_FORCE_LGI)
5930 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5931 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5934 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5935 arvif->vdev_id, ret);
5938 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5940 rate = WMI_FIXED_RATE_NONE;
5943 rate = WMI_FIXED_RATE_NONE;
5944 nss = min(ar->num_rf_chains,
5945 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5946 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5948 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
5951 mutex_lock(&ar->conf_mutex);
5953 arvif->bitrate_mask = *mask;
5954 ieee80211_iterate_stations_atomic(ar->hw,
5955 ath10k_mac_set_bitrate_mask_iter,
5958 mutex_unlock(&ar->conf_mutex);
5961 mutex_lock(&ar->conf_mutex);
5963 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
5965 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5966 arvif->vdev_id, ret);
5971 mutex_unlock(&ar->conf_mutex);
5976 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5977 struct ieee80211_vif *vif,
5978 struct ieee80211_sta *sta,
5981 struct ath10k *ar = hw->priv;
5982 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5985 spin_lock_bh(&ar->data_lock);
5987 ath10k_dbg(ar, ATH10K_DBG_MAC,
5988 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5989 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5992 if (changed & IEEE80211_RC_BW_CHANGED) {
5993 bw = WMI_PEER_CHWIDTH_20MHZ;
5995 switch (sta->bandwidth) {
5996 case IEEE80211_STA_RX_BW_20:
5997 bw = WMI_PEER_CHWIDTH_20MHZ;
5999 case IEEE80211_STA_RX_BW_40:
6000 bw = WMI_PEER_CHWIDTH_40MHZ;
6002 case IEEE80211_STA_RX_BW_80:
6003 bw = WMI_PEER_CHWIDTH_80MHZ;
6005 case IEEE80211_STA_RX_BW_160:
6006 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6007 sta->bandwidth, sta->addr);
6008 bw = WMI_PEER_CHWIDTH_20MHZ;
6015 if (changed & IEEE80211_RC_NSS_CHANGED)
6016 arsta->nss = sta->rx_nss;
6018 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6019 smps = WMI_PEER_SMPS_PS_NONE;
6021 switch (sta->smps_mode) {
6022 case IEEE80211_SMPS_AUTOMATIC:
6023 case IEEE80211_SMPS_OFF:
6024 smps = WMI_PEER_SMPS_PS_NONE;
6026 case IEEE80211_SMPS_STATIC:
6027 smps = WMI_PEER_SMPS_STATIC;
6029 case IEEE80211_SMPS_DYNAMIC:
6030 smps = WMI_PEER_SMPS_DYNAMIC;
6032 case IEEE80211_SMPS_NUM_MODES:
6033 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6034 sta->smps_mode, sta->addr);
6035 smps = WMI_PEER_SMPS_PS_NONE;
6042 arsta->changed |= changed;
6044 spin_unlock_bh(&ar->data_lock);
6046 ieee80211_queue_work(hw, &arsta->update_wk);
6049 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6052 * FIXME: Return 0 for time being. Need to figure out whether FW
6053 * has the API to fetch 64-bit local TSF
6059 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6060 struct ieee80211_vif *vif,
6061 enum ieee80211_ampdu_mlme_action action,
6062 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6065 struct ath10k *ar = hw->priv;
6066 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6068 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6069 arvif->vdev_id, sta->addr, tid, action);
6072 case IEEE80211_AMPDU_RX_START:
6073 case IEEE80211_AMPDU_RX_STOP:
6074 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6075 * creation/removal. Do we need to verify this?
6078 case IEEE80211_AMPDU_TX_START:
6079 case IEEE80211_AMPDU_TX_STOP_CONT:
6080 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6081 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6082 case IEEE80211_AMPDU_TX_OPERATIONAL:
6083 /* Firmware offloads Tx aggregation entirely so deny mac80211
6084 * Tx aggregation requests.
6093 ath10k_mac_update_rx_channel(struct ath10k *ar,
6094 struct ieee80211_chanctx_conf *ctx,
6095 struct ieee80211_vif_chanctx_switch *vifs,
6098 struct cfg80211_chan_def *def = NULL;
6100 /* Both locks are required because ar->rx_channel is modified. This
6101 * allows readers to hold either lock.
6103 lockdep_assert_held(&ar->conf_mutex);
6104 lockdep_assert_held(&ar->data_lock);
6106 WARN_ON(ctx && vifs);
6107 WARN_ON(vifs && n_vifs != 1);
6109 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6110 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6111 * ppdu on Rx may reduce performance on low-end systems. It should be
6112 * possible to make tables/hashmaps to speed the lookup up (be vary of
6113 * cpu data cache lines though regarding sizes) but to keep the initial
6114 * implementation simple and less intrusive fallback to the slow lookup
6115 * only for multi-channel cases. Single-channel cases will remain to
6116 * use the old channel derival and thus performance should not be
6120 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
6121 ieee80211_iter_chan_contexts_atomic(ar->hw,
6122 ath10k_mac_get_any_chandef_iter,
6126 def = &vifs[0].new_ctx->def;
6128 ar->rx_channel = def->chan;
6129 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6130 ar->rx_channel = ctx->def.chan;
6132 ar->rx_channel = NULL;
6138 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6139 struct ieee80211_chanctx_conf *ctx)
6141 struct ath10k *ar = hw->priv;
6143 ath10k_dbg(ar, ATH10K_DBG_MAC,
6144 "mac chanctx add freq %hu width %d ptr %p\n",
6145 ctx->def.chan->center_freq, ctx->def.width, ctx);
6147 mutex_lock(&ar->conf_mutex);
6149 spin_lock_bh(&ar->data_lock);
6150 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
6151 spin_unlock_bh(&ar->data_lock);
6153 ath10k_recalc_radar_detection(ar);
6154 ath10k_monitor_recalc(ar);
6156 mutex_unlock(&ar->conf_mutex);
6162 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6163 struct ieee80211_chanctx_conf *ctx)
6165 struct ath10k *ar = hw->priv;
6167 ath10k_dbg(ar, ATH10K_DBG_MAC,
6168 "mac chanctx remove freq %hu width %d ptr %p\n",
6169 ctx->def.chan->center_freq, ctx->def.width, ctx);
6171 mutex_lock(&ar->conf_mutex);
6173 spin_lock_bh(&ar->data_lock);
6174 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
6175 spin_unlock_bh(&ar->data_lock);
6177 ath10k_recalc_radar_detection(ar);
6178 ath10k_monitor_recalc(ar);
6180 mutex_unlock(&ar->conf_mutex);
6184 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6185 struct ieee80211_chanctx_conf *ctx,
6188 struct ath10k *ar = hw->priv;
6190 mutex_lock(&ar->conf_mutex);
6192 ath10k_dbg(ar, ATH10K_DBG_MAC,
6193 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6194 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
6196 /* This shouldn't really happen because channel switching should use
6197 * switch_vif_chanctx().
6199 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6202 ath10k_recalc_radar_detection(ar);
6204 /* FIXME: How to configure Rx chains properly? */
6206 /* No other actions are actually necessary. Firmware maintains channel
6207 * definitions per vdev internally and there's no host-side channel
6208 * context abstraction to configure, e.g. channel width.
6212 mutex_unlock(&ar->conf_mutex);
6216 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6217 struct ieee80211_vif *vif,
6218 struct ieee80211_chanctx_conf *ctx)
6220 struct ath10k *ar = hw->priv;
6221 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6224 mutex_lock(&ar->conf_mutex);
6226 ath10k_dbg(ar, ATH10K_DBG_MAC,
6227 "mac chanctx assign ptr %p vdev_id %i\n",
6228 ctx, arvif->vdev_id);
6230 if (WARN_ON(arvif->is_started)) {
6231 mutex_unlock(&ar->conf_mutex);
6235 ret = ath10k_vdev_start(arvif, &ctx->def);
6237 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6238 arvif->vdev_id, vif->addr,
6239 ctx->def.chan->center_freq, ret);
6243 arvif->is_started = true;
6245 ret = ath10k_mac_vif_setup_ps(arvif);
6247 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6248 arvif->vdev_id, ret);
6252 if (vif->type == NL80211_IFTYPE_MONITOR) {
6253 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6255 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6256 arvif->vdev_id, ret);
6260 arvif->is_up = true;
6263 mutex_unlock(&ar->conf_mutex);
6267 ath10k_vdev_stop(arvif);
6268 arvif->is_started = false;
6269 ath10k_mac_vif_setup_ps(arvif);
6272 mutex_unlock(&ar->conf_mutex);
6277 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6278 struct ieee80211_vif *vif,
6279 struct ieee80211_chanctx_conf *ctx)
6281 struct ath10k *ar = hw->priv;
6282 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6285 mutex_lock(&ar->conf_mutex);
6287 ath10k_dbg(ar, ATH10K_DBG_MAC,
6288 "mac chanctx unassign ptr %p vdev_id %i\n",
6289 ctx, arvif->vdev_id);
6291 WARN_ON(!arvif->is_started);
6293 if (vif->type == NL80211_IFTYPE_MONITOR) {
6294 WARN_ON(!arvif->is_up);
6296 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6298 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6299 arvif->vdev_id, ret);
6301 arvif->is_up = false;
6304 ret = ath10k_vdev_stop(arvif);
6306 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6307 arvif->vdev_id, ret);
6309 arvif->is_started = false;
6311 mutex_unlock(&ar->conf_mutex);
6315 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6316 struct ieee80211_vif_chanctx_switch *vifs,
6318 enum ieee80211_chanctx_switch_mode mode)
6320 struct ath10k *ar = hw->priv;
6321 struct ath10k_vif *arvif;
6325 mutex_lock(&ar->conf_mutex);
6327 ath10k_dbg(ar, ATH10K_DBG_MAC,
6328 "mac chanctx switch n_vifs %d mode %d\n",
6331 /* First stop monitor interface. Some FW versions crash if there's a
6332 * lone monitor interface.
6334 if (ar->monitor_started)
6335 ath10k_monitor_stop(ar);
6337 for (i = 0; i < n_vifs; i++) {
6338 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6340 ath10k_dbg(ar, ATH10K_DBG_MAC,
6341 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6343 vifs[i].old_ctx->def.chan->center_freq,
6344 vifs[i].new_ctx->def.chan->center_freq,
6345 vifs[i].old_ctx->def.width,
6346 vifs[i].new_ctx->def.width);
6348 if (WARN_ON(!arvif->is_started))
6351 if (WARN_ON(!arvif->is_up))
6354 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6356 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6357 arvif->vdev_id, ret);
6362 /* All relevant vdevs are downed and associated channel resources
6363 * should be available for the channel switch now.
6366 spin_lock_bh(&ar->data_lock);
6367 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
6368 spin_unlock_bh(&ar->data_lock);
6370 for (i = 0; i < n_vifs; i++) {
6371 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6373 if (WARN_ON(!arvif->is_started))
6376 if (WARN_ON(!arvif->is_up))
6379 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6381 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6384 ret = ath10k_mac_setup_prb_tmpl(arvif);
6386 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6389 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6391 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6392 arvif->vdev_id, ret);
6396 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6399 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6400 arvif->vdev_id, ret);
6405 ath10k_monitor_recalc(ar);
6407 mutex_unlock(&ar->conf_mutex);
6411 static const struct ieee80211_ops ath10k_ops = {
6413 .start = ath10k_start,
6414 .stop = ath10k_stop,
6415 .config = ath10k_config,
6416 .add_interface = ath10k_add_interface,
6417 .remove_interface = ath10k_remove_interface,
6418 .configure_filter = ath10k_configure_filter,
6419 .bss_info_changed = ath10k_bss_info_changed,
6420 .hw_scan = ath10k_hw_scan,
6421 .cancel_hw_scan = ath10k_cancel_hw_scan,
6422 .set_key = ath10k_set_key,
6423 .set_default_unicast_key = ath10k_set_default_unicast_key,
6424 .sta_state = ath10k_sta_state,
6425 .conf_tx = ath10k_conf_tx,
6426 .remain_on_channel = ath10k_remain_on_channel,
6427 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6428 .set_rts_threshold = ath10k_set_rts_threshold,
6429 .flush = ath10k_flush,
6430 .tx_last_beacon = ath10k_tx_last_beacon,
6431 .set_antenna = ath10k_set_antenna,
6432 .get_antenna = ath10k_get_antenna,
6433 .reconfig_complete = ath10k_reconfig_complete,
6434 .get_survey = ath10k_get_survey,
6435 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
6436 .sta_rc_update = ath10k_sta_rc_update,
6437 .get_tsf = ath10k_get_tsf,
6438 .ampdu_action = ath10k_ampdu_action,
6439 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6440 .get_et_stats = ath10k_debug_get_et_stats,
6441 .get_et_strings = ath10k_debug_get_et_strings,
6442 .add_chanctx = ath10k_mac_op_add_chanctx,
6443 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6444 .change_chanctx = ath10k_mac_op_change_chanctx,
6445 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6446 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6447 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
6449 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6452 .suspend = ath10k_wow_op_suspend,
6453 .resume = ath10k_wow_op_resume,
6455 #ifdef CONFIG_MAC80211_DEBUGFS
6456 .sta_add_debugfs = ath10k_sta_add_debugfs,
6460 #define CHAN2G(_channel, _freq, _flags) { \
6461 .band = IEEE80211_BAND_2GHZ, \
6462 .hw_value = (_channel), \
6463 .center_freq = (_freq), \
6464 .flags = (_flags), \
6465 .max_antenna_gain = 0, \
6469 #define CHAN5G(_channel, _freq, _flags) { \
6470 .band = IEEE80211_BAND_5GHZ, \
6471 .hw_value = (_channel), \
6472 .center_freq = (_freq), \
6473 .flags = (_flags), \
6474 .max_antenna_gain = 0, \
6478 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6488 CHAN2G(10, 2457, 0),
6489 CHAN2G(11, 2462, 0),
6490 CHAN2G(12, 2467, 0),
6491 CHAN2G(13, 2472, 0),
6492 CHAN2G(14, 2484, 0),
6495 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
6496 CHAN5G(36, 5180, 0),
6497 CHAN5G(40, 5200, 0),
6498 CHAN5G(44, 5220, 0),
6499 CHAN5G(48, 5240, 0),
6500 CHAN5G(52, 5260, 0),
6501 CHAN5G(56, 5280, 0),
6502 CHAN5G(60, 5300, 0),
6503 CHAN5G(64, 5320, 0),
6504 CHAN5G(100, 5500, 0),
6505 CHAN5G(104, 5520, 0),
6506 CHAN5G(108, 5540, 0),
6507 CHAN5G(112, 5560, 0),
6508 CHAN5G(116, 5580, 0),
6509 CHAN5G(120, 5600, 0),
6510 CHAN5G(124, 5620, 0),
6511 CHAN5G(128, 5640, 0),
6512 CHAN5G(132, 5660, 0),
6513 CHAN5G(136, 5680, 0),
6514 CHAN5G(140, 5700, 0),
6515 CHAN5G(144, 5720, 0),
6516 CHAN5G(149, 5745, 0),
6517 CHAN5G(153, 5765, 0),
6518 CHAN5G(157, 5785, 0),
6519 CHAN5G(161, 5805, 0),
6520 CHAN5G(165, 5825, 0),
6523 struct ath10k *ath10k_mac_create(size_t priv_size)
6525 struct ieee80211_hw *hw;
6528 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
6538 void ath10k_mac_destroy(struct ath10k *ar)
6540 ieee80211_free_hw(ar->hw);
6543 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6546 .types = BIT(NL80211_IFTYPE_STATION)
6547 | BIT(NL80211_IFTYPE_P2P_CLIENT)
6551 .types = BIT(NL80211_IFTYPE_P2P_GO)
6555 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6559 .types = BIT(NL80211_IFTYPE_AP)
6563 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
6566 .types = BIT(NL80211_IFTYPE_AP)
6570 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6572 .limits = ath10k_if_limits,
6573 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6574 .max_interfaces = 8,
6575 .num_different_channels = 1,
6576 .beacon_int_infra_match = true,
6580 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
6582 .limits = ath10k_10x_if_limits,
6583 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
6584 .max_interfaces = 8,
6585 .num_different_channels = 1,
6586 .beacon_int_infra_match = true,
6587 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6588 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6589 BIT(NL80211_CHAN_WIDTH_20) |
6590 BIT(NL80211_CHAN_WIDTH_40) |
6591 BIT(NL80211_CHAN_WIDTH_80),
6596 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6599 .types = BIT(NL80211_IFTYPE_STATION),
6603 .types = BIT(NL80211_IFTYPE_AP) |
6604 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6605 BIT(NL80211_IFTYPE_P2P_GO),
6609 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6613 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
6616 .types = BIT(NL80211_IFTYPE_STATION),
6620 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
6624 .types = BIT(NL80211_IFTYPE_AP) |
6625 BIT(NL80211_IFTYPE_P2P_GO),
6629 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6633 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6636 .types = BIT(NL80211_IFTYPE_STATION),
6640 .types = BIT(NL80211_IFTYPE_ADHOC),
6644 /* FIXME: This is not thouroughly tested. These combinations may over- or
6645 * underestimate hw/fw capabilities.
6647 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6649 .limits = ath10k_tlv_if_limit,
6650 .num_different_channels = 1,
6651 .max_interfaces = 4,
6652 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6655 .limits = ath10k_tlv_if_limit_ibss,
6656 .num_different_channels = 1,
6657 .max_interfaces = 2,
6658 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6662 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6664 .limits = ath10k_tlv_if_limit,
6665 .num_different_channels = 1,
6666 .max_interfaces = 4,
6667 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6670 .limits = ath10k_tlv_qcs_if_limit,
6671 .num_different_channels = 2,
6672 .max_interfaces = 4,
6673 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
6676 .limits = ath10k_tlv_if_limit_ibss,
6677 .num_different_channels = 1,
6678 .max_interfaces = 2,
6679 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6683 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
6686 .types = BIT(NL80211_IFTYPE_STATION),
6690 .types = BIT(NL80211_IFTYPE_AP)
6694 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
6696 .limits = ath10k_10_4_if_limits,
6697 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
6698 .max_interfaces = 16,
6699 .num_different_channels = 1,
6700 .beacon_int_infra_match = true,
6701 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6702 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6703 BIT(NL80211_CHAN_WIDTH_20) |
6704 BIT(NL80211_CHAN_WIDTH_40) |
6705 BIT(NL80211_CHAN_WIDTH_80),
6710 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6712 struct ieee80211_sta_vht_cap vht_cap = {0};
6717 vht_cap.vht_supported = 1;
6718 vht_cap.cap = ar->vht_cap_info;
6720 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6721 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6722 val = ar->num_rf_chains - 1;
6723 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6724 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6729 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6730 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6731 val = ar->num_rf_chains - 1;
6732 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6733 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6739 for (i = 0; i < 8; i++) {
6740 if (i < ar->num_rf_chains)
6741 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6743 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6746 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6747 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6752 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6755 struct ieee80211_sta_ht_cap ht_cap = {0};
6757 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6760 ht_cap.ht_supported = 1;
6761 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6762 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6763 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6764 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6765 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6767 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6768 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6770 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6771 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6773 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6776 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6777 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6782 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6783 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6785 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6788 stbc = ar->ht_cap_info;
6789 stbc &= WMI_HT_CAP_RX_STBC;
6790 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6791 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6792 stbc &= IEEE80211_HT_CAP_RX_STBC;
6797 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6798 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6800 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6801 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6803 /* max AMSDU is implicitly taken from vht_cap_info */
6804 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6805 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6807 for (i = 0; i < ar->num_rf_chains; i++)
6808 ht_cap.mcs.rx_mask[i] = 0xFF;
6810 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6815 static void ath10k_get_arvif_iter(void *data, u8 *mac,
6816 struct ieee80211_vif *vif)
6818 struct ath10k_vif_iter *arvif_iter = data;
6819 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6821 if (arvif->vdev_id == arvif_iter->vdev_id)
6822 arvif_iter->arvif = arvif;
6825 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6827 struct ath10k_vif_iter arvif_iter;
6830 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6831 arvif_iter.vdev_id = vdev_id;
6833 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6834 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6836 ath10k_get_arvif_iter,
6838 if (!arvif_iter.arvif) {
6839 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
6843 return arvif_iter.arvif;
6846 int ath10k_mac_register(struct ath10k *ar)
6848 static const u32 cipher_suites[] = {
6849 WLAN_CIPHER_SUITE_WEP40,
6850 WLAN_CIPHER_SUITE_WEP104,
6851 WLAN_CIPHER_SUITE_TKIP,
6852 WLAN_CIPHER_SUITE_CCMP,
6853 WLAN_CIPHER_SUITE_AES_CMAC,
6855 struct ieee80211_supported_band *band;
6856 struct ieee80211_sta_vht_cap vht_cap;
6857 struct ieee80211_sta_ht_cap ht_cap;
6861 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6863 SET_IEEE80211_DEV(ar->hw, ar->dev);
6865 ht_cap = ath10k_get_ht_cap(ar);
6866 vht_cap = ath10k_create_vht_cap(ar);
6868 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6869 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6872 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6873 channels = kmemdup(ath10k_2ghz_channels,
6874 sizeof(ath10k_2ghz_channels),
6881 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6882 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6883 band->channels = channels;
6884 band->n_bitrates = ath10k_g_rates_size;
6885 band->bitrates = ath10k_g_rates;
6886 band->ht_cap = ht_cap;
6888 /* Enable the VHT support at 2.4 GHz */
6889 band->vht_cap = vht_cap;
6891 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6894 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6895 channels = kmemdup(ath10k_5ghz_channels,
6896 sizeof(ath10k_5ghz_channels),
6903 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6904 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6905 band->channels = channels;
6906 band->n_bitrates = ath10k_a_rates_size;
6907 band->bitrates = ath10k_a_rates;
6908 band->ht_cap = ht_cap;
6909 band->vht_cap = vht_cap;
6910 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6913 ar->hw->wiphy->interface_modes =
6914 BIT(NL80211_IFTYPE_STATION) |
6915 BIT(NL80211_IFTYPE_AP);
6917 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6918 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6920 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6921 ar->hw->wiphy->interface_modes |=
6922 BIT(NL80211_IFTYPE_P2P_DEVICE) |
6923 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6924 BIT(NL80211_IFTYPE_P2P_GO);
6926 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6927 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6928 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6929 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6930 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6931 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6932 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6933 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
6934 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6935 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6936 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6937 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6938 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6939 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
6941 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
6942 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
6944 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6945 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
6947 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
6948 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
6950 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6951 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6952 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
6955 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6956 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6958 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
6959 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
6961 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6963 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6964 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6966 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6967 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6968 * correct Probe Responses. This is more of a hack advert..
6970 ar->hw->wiphy->probe_resp_offload |=
6971 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6972 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6973 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6976 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6977 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6979 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6980 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
6981 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6983 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
6984 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6986 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6988 ret = ath10k_wow_init(ar);
6990 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6994 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
6997 * on LL hardware queues are managed entirely by the FW
6998 * so we only advertise to mac we can do the queues thing
7000 ar->hw->queues = IEEE80211_MAX_QUEUES;
7002 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7003 * something that vdev_ids can't reach so that we don't stop the queue
7006 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
7008 switch (ar->wmi.op_version) {
7009 case ATH10K_FW_WMI_OP_VERSION_MAIN:
7010 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7011 ar->hw->wiphy->n_iface_combinations =
7012 ARRAY_SIZE(ath10k_if_comb);
7013 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7015 case ATH10K_FW_WMI_OP_VERSION_TLV:
7016 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7017 ar->hw->wiphy->iface_combinations =
7018 ath10k_tlv_qcs_if_comb;
7019 ar->hw->wiphy->n_iface_combinations =
7020 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7022 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7023 ar->hw->wiphy->n_iface_combinations =
7024 ARRAY_SIZE(ath10k_tlv_if_comb);
7026 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7028 case ATH10K_FW_WMI_OP_VERSION_10_1:
7029 case ATH10K_FW_WMI_OP_VERSION_10_2:
7030 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7031 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7032 ar->hw->wiphy->n_iface_combinations =
7033 ARRAY_SIZE(ath10k_10x_if_comb);
7035 case ATH10K_FW_WMI_OP_VERSION_10_4:
7036 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7037 ar->hw->wiphy->n_iface_combinations =
7038 ARRAY_SIZE(ath10k_10_4_if_comb);
7040 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7041 case ATH10K_FW_WMI_OP_VERSION_MAX:
7047 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7048 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7050 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7051 /* Init ath dfs pattern detector */
7052 ar->ath_common.debug_mask = ATH_DBG_DFS;
7053 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7056 if (!ar->dfs_detector)
7057 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
7060 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7061 ath10k_reg_notifier);
7063 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
7067 ar->hw->wiphy->cipher_suites = cipher_suites;
7068 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7070 ret = ieee80211_register_hw(ar->hw);
7072 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
7076 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7077 ret = regulatory_hint(ar->hw->wiphy,
7078 ar->ath_common.regulatory.alpha2);
7080 goto err_unregister;
7086 ieee80211_unregister_hw(ar->hw);
7088 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7089 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7094 void ath10k_mac_unregister(struct ath10k *ar)
7096 ieee80211_unregister_hw(ar->hw);
7098 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7099 ar->dfs_detector->exit(ar->dfs_detector);
7101 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7102 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7104 SET_IEEE80211_DEV(ar->hw, NULL);