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;
203 if (cmd == DISABLE_KEY) {
204 arg.key_cipher = WMI_CIPHER_NONE;
208 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
211 static int ath10k_install_key(struct ath10k_vif *arvif,
212 struct ieee80211_key_conf *key,
213 enum set_key_cmd cmd,
214 const u8 *macaddr, u32 flags)
216 struct ath10k *ar = arvif->ar;
218 unsigned long time_left;
220 lockdep_assert_held(&ar->conf_mutex);
222 reinit_completion(&ar->install_key_done);
224 if (arvif->nohwcrypt)
227 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
231 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
238 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
241 struct ath10k *ar = arvif->ar;
242 struct ath10k_peer *peer;
247 lockdep_assert_held(&ar->conf_mutex);
249 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
250 arvif->vif->type != NL80211_IFTYPE_ADHOC))
253 spin_lock_bh(&ar->data_lock);
254 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
255 spin_unlock_bh(&ar->data_lock);
260 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
261 if (arvif->wep_keys[i] == NULL)
264 switch (arvif->vif->type) {
265 case NL80211_IFTYPE_AP:
266 flags = WMI_KEY_PAIRWISE;
268 if (arvif->def_wep_key_idx == i)
269 flags |= WMI_KEY_TX_USAGE;
271 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
272 SET_KEY, addr, flags);
276 case NL80211_IFTYPE_ADHOC:
277 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
283 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
284 SET_KEY, addr, WMI_KEY_GROUP);
293 spin_lock_bh(&ar->data_lock);
294 peer->keys[i] = arvif->wep_keys[i];
295 spin_unlock_bh(&ar->data_lock);
298 /* In some cases (notably with static WEP IBSS with multiple keys)
299 * multicast Tx becomes broken. Both pairwise and groupwise keys are
300 * installed already. Using WMI_KEY_TX_USAGE in different combinations
301 * didn't seem help. Using def_keyid vdev parameter seems to be
302 * effective so use that.
304 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
306 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
309 if (arvif->def_wep_key_idx == -1)
312 ret = ath10k_wmi_vdev_set_param(arvif->ar,
314 arvif->ar->wmi.vdev_param->def_keyid,
315 arvif->def_wep_key_idx);
317 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
318 arvif->vdev_id, ret);
325 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
328 struct ath10k *ar = arvif->ar;
329 struct ath10k_peer *peer;
335 lockdep_assert_held(&ar->conf_mutex);
337 spin_lock_bh(&ar->data_lock);
338 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
339 spin_unlock_bh(&ar->data_lock);
344 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
345 if (peer->keys[i] == NULL)
348 /* key flags are not required to delete the key */
349 ret = ath10k_install_key(arvif, peer->keys[i],
350 DISABLE_KEY, addr, flags);
351 if (ret < 0 && first_errno == 0)
355 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
358 spin_lock_bh(&ar->data_lock);
359 peer->keys[i] = NULL;
360 spin_unlock_bh(&ar->data_lock);
366 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
369 struct ath10k_peer *peer;
372 lockdep_assert_held(&ar->data_lock);
374 /* We don't know which vdev this peer belongs to,
375 * since WMI doesn't give us that information.
377 * FIXME: multi-bss needs to be handled.
379 peer = ath10k_peer_find(ar, 0, addr);
383 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
384 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
391 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
392 struct ieee80211_key_conf *key)
394 struct ath10k *ar = arvif->ar;
395 struct ath10k_peer *peer;
402 lockdep_assert_held(&ar->conf_mutex);
405 /* since ath10k_install_key we can't hold data_lock all the
406 * time, so we try to remove the keys incrementally */
407 spin_lock_bh(&ar->data_lock);
409 list_for_each_entry(peer, &ar->peers, list) {
410 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
411 if (peer->keys[i] == key) {
412 ether_addr_copy(addr, peer->addr);
413 peer->keys[i] = NULL;
418 if (i < ARRAY_SIZE(peer->keys))
421 spin_unlock_bh(&ar->data_lock);
423 if (i == ARRAY_SIZE(peer->keys))
425 /* key flags are not required to delete the key */
426 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
427 if (ret < 0 && first_errno == 0)
431 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
438 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
439 struct ieee80211_key_conf *key)
441 struct ath10k *ar = arvif->ar;
442 struct ath10k_peer *peer;
445 lockdep_assert_held(&ar->conf_mutex);
447 list_for_each_entry(peer, &ar->peers, list) {
448 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
451 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
454 if (peer->keys[key->keyidx] == key)
457 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
458 arvif->vdev_id, key->keyidx);
460 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
462 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
463 arvif->vdev_id, peer->addr, ret);
471 /*********************/
472 /* General utilities */
473 /*********************/
475 static inline enum wmi_phy_mode
476 chan_to_phymode(const struct cfg80211_chan_def *chandef)
478 enum wmi_phy_mode phymode = MODE_UNKNOWN;
480 switch (chandef->chan->band) {
481 case IEEE80211_BAND_2GHZ:
482 switch (chandef->width) {
483 case NL80211_CHAN_WIDTH_20_NOHT:
484 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
489 case NL80211_CHAN_WIDTH_20:
490 phymode = MODE_11NG_HT20;
492 case NL80211_CHAN_WIDTH_40:
493 phymode = MODE_11NG_HT40;
495 case NL80211_CHAN_WIDTH_5:
496 case NL80211_CHAN_WIDTH_10:
497 case NL80211_CHAN_WIDTH_80:
498 case NL80211_CHAN_WIDTH_80P80:
499 case NL80211_CHAN_WIDTH_160:
500 phymode = MODE_UNKNOWN;
504 case IEEE80211_BAND_5GHZ:
505 switch (chandef->width) {
506 case NL80211_CHAN_WIDTH_20_NOHT:
509 case NL80211_CHAN_WIDTH_20:
510 phymode = MODE_11NA_HT20;
512 case NL80211_CHAN_WIDTH_40:
513 phymode = MODE_11NA_HT40;
515 case NL80211_CHAN_WIDTH_80:
516 phymode = MODE_11AC_VHT80;
518 case NL80211_CHAN_WIDTH_5:
519 case NL80211_CHAN_WIDTH_10:
520 case NL80211_CHAN_WIDTH_80P80:
521 case NL80211_CHAN_WIDTH_160:
522 phymode = MODE_UNKNOWN;
530 WARN_ON(phymode == MODE_UNKNOWN);
534 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
537 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
538 * 0 for no restriction
547 switch (mpdudensity) {
553 /* Our lower layer calculations limit our precision to
569 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
570 struct cfg80211_chan_def *def)
572 struct ieee80211_chanctx_conf *conf;
575 conf = rcu_dereference(vif->chanctx_conf);
587 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
588 struct ieee80211_chanctx_conf *conf,
596 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
600 ieee80211_iter_chan_contexts_atomic(ar->hw,
601 ath10k_mac_num_chanctxs_iter,
608 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
609 struct ieee80211_chanctx_conf *conf,
612 struct cfg80211_chan_def **def = data;
617 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
618 enum wmi_peer_type peer_type)
620 struct ath10k_vif *arvif;
624 lockdep_assert_held(&ar->conf_mutex);
626 num_peers = ar->num_peers;
628 /* Each vdev consumes a peer entry as well */
629 list_for_each_entry(arvif, &ar->arvifs, list)
632 if (num_peers >= ar->max_num_peers)
635 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
637 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
642 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
644 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
654 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
656 struct ath10k *ar = arvif->ar;
660 param = ar->wmi.pdev_param->sta_kickout_th;
661 ret = ath10k_wmi_pdev_set_param(ar, param,
662 ATH10K_KICKOUT_THRESHOLD);
664 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
665 arvif->vdev_id, ret);
669 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
670 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
671 ATH10K_KEEPALIVE_MIN_IDLE);
673 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
674 arvif->vdev_id, ret);
678 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
679 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
680 ATH10K_KEEPALIVE_MAX_IDLE);
682 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
683 arvif->vdev_id, ret);
687 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
688 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
689 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
691 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
692 arvif->vdev_id, ret);
699 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
701 struct ath10k *ar = arvif->ar;
704 vdev_param = ar->wmi.vdev_param->rts_threshold;
705 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
708 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
712 lockdep_assert_held(&ar->conf_mutex);
714 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
718 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
727 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
729 struct ath10k_peer *peer, *tmp;
731 lockdep_assert_held(&ar->conf_mutex);
733 spin_lock_bh(&ar->data_lock);
734 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
735 if (peer->vdev_id != vdev_id)
738 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
739 peer->addr, vdev_id);
741 list_del(&peer->list);
745 spin_unlock_bh(&ar->data_lock);
748 static void ath10k_peer_cleanup_all(struct ath10k *ar)
750 struct ath10k_peer *peer, *tmp;
752 lockdep_assert_held(&ar->conf_mutex);
754 spin_lock_bh(&ar->data_lock);
755 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
756 list_del(&peer->list);
759 spin_unlock_bh(&ar->data_lock);
762 ar->num_stations = 0;
765 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
766 struct ieee80211_sta *sta,
767 enum wmi_tdls_peer_state state)
770 struct wmi_tdls_peer_update_cmd_arg arg = {};
771 struct wmi_tdls_peer_capab_arg cap = {};
772 struct wmi_channel_arg chan_arg = {};
774 lockdep_assert_held(&ar->conf_mutex);
776 arg.vdev_id = vdev_id;
777 arg.peer_state = state;
778 ether_addr_copy(arg.addr, sta->addr);
780 cap.peer_max_sp = sta->max_sp;
781 cap.peer_uapsd_queues = sta->uapsd_queues;
783 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
784 !sta->tdls_initiator)
785 cap.is_peer_responder = 1;
787 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
789 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
790 arg.addr, vdev_id, ret);
797 /************************/
798 /* Interface management */
799 /************************/
801 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
803 struct ath10k *ar = arvif->ar;
805 lockdep_assert_held(&ar->data_lock);
810 if (!arvif->beacon_buf)
811 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
812 arvif->beacon->len, DMA_TO_DEVICE);
814 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
815 arvif->beacon_state != ATH10K_BEACON_SENT))
818 dev_kfree_skb_any(arvif->beacon);
820 arvif->beacon = NULL;
821 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
824 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
826 struct ath10k *ar = arvif->ar;
828 lockdep_assert_held(&ar->data_lock);
830 ath10k_mac_vif_beacon_free(arvif);
832 if (arvif->beacon_buf) {
833 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
834 arvif->beacon_buf, arvif->beacon_paddr);
835 arvif->beacon_buf = NULL;
839 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
841 unsigned long time_left;
843 lockdep_assert_held(&ar->conf_mutex);
845 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
848 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
849 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
853 return ar->last_wmi_vdev_start_status;
856 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
858 struct cfg80211_chan_def *chandef = NULL;
859 struct ieee80211_channel *channel = NULL;
860 struct wmi_vdev_start_request_arg arg = {};
863 lockdep_assert_held(&ar->conf_mutex);
865 ieee80211_iter_chan_contexts_atomic(ar->hw,
866 ath10k_mac_get_any_chandef_iter,
868 if (WARN_ON_ONCE(!chandef))
871 channel = chandef->chan;
873 arg.vdev_id = vdev_id;
874 arg.channel.freq = channel->center_freq;
875 arg.channel.band_center_freq1 = chandef->center_freq1;
877 /* TODO setup this dynamically, what in case we
878 don't have any vifs? */
879 arg.channel.mode = chan_to_phymode(chandef);
880 arg.channel.chan_radar =
881 !!(channel->flags & IEEE80211_CHAN_RADAR);
883 arg.channel.min_power = 0;
884 arg.channel.max_power = channel->max_power * 2;
885 arg.channel.max_reg_power = channel->max_reg_power * 2;
886 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
888 reinit_completion(&ar->vdev_setup_done);
890 ret = ath10k_wmi_vdev_start(ar, &arg);
892 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
897 ret = ath10k_vdev_setup_sync(ar);
899 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
904 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
906 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
911 ar->monitor_vdev_id = vdev_id;
913 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
914 ar->monitor_vdev_id);
918 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
920 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
921 ar->monitor_vdev_id, ret);
926 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
930 lockdep_assert_held(&ar->conf_mutex);
932 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
934 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
935 ar->monitor_vdev_id, ret);
937 reinit_completion(&ar->vdev_setup_done);
939 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
941 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
942 ar->monitor_vdev_id, ret);
944 ret = ath10k_vdev_setup_sync(ar);
946 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
947 ar->monitor_vdev_id, ret);
949 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
950 ar->monitor_vdev_id);
954 static int ath10k_monitor_vdev_create(struct ath10k *ar)
958 lockdep_assert_held(&ar->conf_mutex);
960 if (ar->free_vdev_map == 0) {
961 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
965 bit = __ffs64(ar->free_vdev_map);
967 ar->monitor_vdev_id = bit;
969 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
970 WMI_VDEV_TYPE_MONITOR,
973 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
974 ar->monitor_vdev_id, ret);
978 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
979 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
980 ar->monitor_vdev_id);
985 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
989 lockdep_assert_held(&ar->conf_mutex);
991 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
993 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
994 ar->monitor_vdev_id, ret);
998 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1000 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1001 ar->monitor_vdev_id);
1005 static int ath10k_monitor_start(struct ath10k *ar)
1009 lockdep_assert_held(&ar->conf_mutex);
1011 ret = ath10k_monitor_vdev_create(ar);
1013 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1017 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1019 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1020 ath10k_monitor_vdev_delete(ar);
1024 ar->monitor_started = true;
1025 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1030 static int ath10k_monitor_stop(struct ath10k *ar)
1034 lockdep_assert_held(&ar->conf_mutex);
1036 ret = ath10k_monitor_vdev_stop(ar);
1038 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1042 ret = ath10k_monitor_vdev_delete(ar);
1044 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1048 ar->monitor_started = false;
1049 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1054 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1058 /* At least one chanctx is required to derive a channel to start
1061 num_ctx = ath10k_mac_num_chanctxs(ar);
1065 /* If there's already an existing special monitor interface then don't
1066 * bother creating another monitor vdev.
1068 if (ar->monitor_arvif)
1071 return ar->monitor ||
1072 ar->filter_flags & FIF_OTHER_BSS ||
1073 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1076 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1080 num_ctx = ath10k_mac_num_chanctxs(ar);
1082 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1083 * shouldn't allow this but make sure to prevent handling the following
1084 * case anyway since multi-channel DFS hasn't been tested at all.
1086 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1092 static int ath10k_monitor_recalc(struct ath10k *ar)
1098 lockdep_assert_held(&ar->conf_mutex);
1100 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1101 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1103 ath10k_dbg(ar, ATH10K_DBG_MAC,
1104 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1105 ar->monitor_started, needed, allowed);
1107 if (WARN_ON(needed && !allowed)) {
1108 if (ar->monitor_started) {
1109 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1111 ret = ath10k_monitor_stop(ar);
1113 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1121 if (needed == ar->monitor_started)
1125 return ath10k_monitor_start(ar);
1127 return ath10k_monitor_stop(ar);
1130 static bool ath10k_mac_can_set_cts_prot(struct ath10k_vif *arvif)
1132 struct ath10k *ar = arvif->ar;
1134 lockdep_assert_held(&ar->conf_mutex);
1136 if (!arvif->is_started) {
1137 ath10k_dbg(ar, ATH10K_DBG_MAC, "defer cts setup, vdev is not ready yet\n");
1144 static int ath10k_mac_set_cts_prot(struct ath10k_vif *arvif)
1146 struct ath10k *ar = arvif->ar;
1149 lockdep_assert_held(&ar->conf_mutex);
1151 vdev_param = ar->wmi.vdev_param->protection_mode;
1153 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_protection %d\n",
1154 arvif->vdev_id, arvif->use_cts_prot);
1156 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1157 arvif->use_cts_prot ? 1 : 0);
1160 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1162 struct ath10k *ar = arvif->ar;
1163 u32 vdev_param, rts_cts = 0;
1165 lockdep_assert_held(&ar->conf_mutex);
1167 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1169 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1171 if (arvif->num_legacy_stations > 0)
1172 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1173 WMI_RTSCTS_PROFILE);
1175 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1176 WMI_RTSCTS_PROFILE);
1178 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1182 static int ath10k_start_cac(struct ath10k *ar)
1186 lockdep_assert_held(&ar->conf_mutex);
1188 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1190 ret = ath10k_monitor_recalc(ar);
1192 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1193 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1197 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1198 ar->monitor_vdev_id);
1203 static int ath10k_stop_cac(struct ath10k *ar)
1205 lockdep_assert_held(&ar->conf_mutex);
1207 /* CAC is not running - do nothing */
1208 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1211 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1212 ath10k_monitor_stop(ar);
1214 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1219 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1220 struct ieee80211_chanctx_conf *conf,
1225 if (!*ret && conf->radar_enabled)
1229 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1231 bool has_radar = false;
1233 ieee80211_iter_chan_contexts_atomic(ar->hw,
1234 ath10k_mac_has_radar_iter,
1240 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1244 lockdep_assert_held(&ar->conf_mutex);
1246 ath10k_stop_cac(ar);
1248 if (!ath10k_mac_has_radar_enabled(ar))
1251 if (ar->num_started_vdevs > 0)
1254 ret = ath10k_start_cac(ar);
1257 * Not possible to start CAC on current channel so starting
1258 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1259 * by indicating that radar was detected.
1261 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1262 ieee80211_radar_detected(ar->hw);
1266 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1268 struct ath10k *ar = arvif->ar;
1271 lockdep_assert_held(&ar->conf_mutex);
1273 reinit_completion(&ar->vdev_setup_done);
1275 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1277 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1278 arvif->vdev_id, ret);
1282 ret = ath10k_vdev_setup_sync(ar);
1284 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1285 arvif->vdev_id, ret);
1289 WARN_ON(ar->num_started_vdevs == 0);
1291 if (ar->num_started_vdevs != 0) {
1292 ar->num_started_vdevs--;
1293 ath10k_recalc_radar_detection(ar);
1299 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1300 const struct cfg80211_chan_def *chandef,
1303 struct ath10k *ar = arvif->ar;
1304 struct wmi_vdev_start_request_arg arg = {};
1307 lockdep_assert_held(&ar->conf_mutex);
1309 reinit_completion(&ar->vdev_setup_done);
1311 arg.vdev_id = arvif->vdev_id;
1312 arg.dtim_period = arvif->dtim_period;
1313 arg.bcn_intval = arvif->beacon_interval;
1315 arg.channel.freq = chandef->chan->center_freq;
1316 arg.channel.band_center_freq1 = chandef->center_freq1;
1317 arg.channel.mode = chan_to_phymode(chandef);
1319 arg.channel.min_power = 0;
1320 arg.channel.max_power = chandef->chan->max_power * 2;
1321 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1322 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1324 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1325 arg.ssid = arvif->u.ap.ssid;
1326 arg.ssid_len = arvif->u.ap.ssid_len;
1327 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1329 /* For now allow DFS for AP mode */
1330 arg.channel.chan_radar =
1331 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1332 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1333 arg.ssid = arvif->vif->bss_conf.ssid;
1334 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1337 ath10k_dbg(ar, ATH10K_DBG_MAC,
1338 "mac vdev %d start center_freq %d phymode %s\n",
1339 arg.vdev_id, arg.channel.freq,
1340 ath10k_wmi_phymode_str(arg.channel.mode));
1343 ret = ath10k_wmi_vdev_restart(ar, &arg);
1345 ret = ath10k_wmi_vdev_start(ar, &arg);
1348 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1353 ret = ath10k_vdev_setup_sync(ar);
1356 "failed to synchronize setup for vdev %i restart %d: %d\n",
1357 arg.vdev_id, restart, ret);
1361 ar->num_started_vdevs++;
1362 ath10k_recalc_radar_detection(ar);
1367 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1368 const struct cfg80211_chan_def *def)
1370 return ath10k_vdev_start_restart(arvif, def, false);
1373 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1374 const struct cfg80211_chan_def *def)
1376 return ath10k_vdev_start_restart(arvif, def, true);
1379 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1380 struct sk_buff *bcn)
1382 struct ath10k *ar = arvif->ar;
1383 struct ieee80211_mgmt *mgmt;
1387 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1390 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1393 mgmt = (void *)bcn->data;
1394 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1395 mgmt->u.beacon.variable,
1396 bcn->len - (mgmt->u.beacon.variable -
1401 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1403 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1404 arvif->vdev_id, ret);
1411 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1412 u8 oui_type, size_t ie_offset)
1419 if (WARN_ON(skb->len < ie_offset))
1422 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1423 skb->data + ie_offset,
1424 skb->len - ie_offset);
1429 end = skb->data + skb->len;
1432 if (WARN_ON(next > end))
1435 memmove(ie, next, end - next);
1436 skb_trim(skb, skb->len - len);
1441 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1443 struct ath10k *ar = arvif->ar;
1444 struct ieee80211_hw *hw = ar->hw;
1445 struct ieee80211_vif *vif = arvif->vif;
1446 struct ieee80211_mutable_offsets offs = {};
1447 struct sk_buff *bcn;
1450 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1453 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1454 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1457 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1459 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1463 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1465 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1470 /* P2P IE is inserted by firmware automatically (as configured above)
1471 * so remove it from the base beacon template to avoid duplicate P2P
1472 * IEs in beacon frames.
1474 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1475 offsetof(struct ieee80211_mgmt,
1476 u.beacon.variable));
1478 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1483 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1491 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1493 struct ath10k *ar = arvif->ar;
1494 struct ieee80211_hw *hw = ar->hw;
1495 struct ieee80211_vif *vif = arvif->vif;
1496 struct sk_buff *prb;
1499 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1502 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1505 /* For mesh, probe response and beacon share the same template */
1506 if (ieee80211_vif_is_mesh(vif))
1509 prb = ieee80211_proberesp_get(hw, vif);
1511 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1515 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1519 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1527 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1529 struct ath10k *ar = arvif->ar;
1530 struct cfg80211_chan_def def;
1533 /* When originally vdev is started during assign_vif_chanctx() some
1534 * information is missing, notably SSID. Firmware revisions with beacon
1535 * offloading require the SSID to be provided during vdev (re)start to
1536 * handle hidden SSID properly.
1538 * Vdev restart must be done after vdev has been both started and
1539 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1540 * deliver vdev restart response event causing timeouts during vdev
1541 * syncing in ath10k.
1543 * Note: The vdev down/up and template reinstallation could be skipped
1544 * since only wmi-tlv firmware are known to have beacon offload and
1545 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1546 * response delivery. It's probably more robust to keep it as is.
1548 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1551 if (WARN_ON(!arvif->is_started))
1554 if (WARN_ON(!arvif->is_up))
1557 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1560 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1562 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1563 arvif->vdev_id, ret);
1567 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1568 * firmware will crash upon vdev up.
1571 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1573 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1577 ret = ath10k_mac_setup_prb_tmpl(arvif);
1579 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1583 ret = ath10k_vdev_restart(arvif, &def);
1585 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1586 arvif->vdev_id, ret);
1590 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1593 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1594 arvif->vdev_id, ret);
1601 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1602 struct ieee80211_bss_conf *info)
1604 struct ath10k *ar = arvif->ar;
1607 lockdep_assert_held(&arvif->ar->conf_mutex);
1609 if (!info->enable_beacon) {
1610 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1612 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1613 arvif->vdev_id, ret);
1615 arvif->is_up = false;
1617 spin_lock_bh(&arvif->ar->data_lock);
1618 ath10k_mac_vif_beacon_free(arvif);
1619 spin_unlock_bh(&arvif->ar->data_lock);
1624 arvif->tx_seq_no = 0x1000;
1627 ether_addr_copy(arvif->bssid, info->bssid);
1629 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1632 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1633 arvif->vdev_id, ret);
1637 arvif->is_up = true;
1639 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1641 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1642 arvif->vdev_id, ret);
1646 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1649 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1650 struct ieee80211_bss_conf *info,
1651 const u8 self_peer[ETH_ALEN])
1653 struct ath10k *ar = arvif->ar;
1657 lockdep_assert_held(&arvif->ar->conf_mutex);
1659 if (!info->ibss_joined) {
1660 if (is_zero_ether_addr(arvif->bssid))
1663 eth_zero_addr(arvif->bssid);
1668 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1669 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1670 ATH10K_DEFAULT_ATIM);
1672 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1673 arvif->vdev_id, ret);
1676 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1678 struct ath10k *ar = arvif->ar;
1683 lockdep_assert_held(&arvif->ar->conf_mutex);
1685 if (arvif->u.sta.uapsd)
1686 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1688 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1690 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1691 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1693 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1694 value, arvif->vdev_id, ret);
1701 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1703 struct ath10k *ar = arvif->ar;
1708 lockdep_assert_held(&arvif->ar->conf_mutex);
1710 if (arvif->u.sta.uapsd)
1711 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1713 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1715 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1716 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1719 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1720 value, arvif->vdev_id, ret);
1727 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1729 struct ath10k_vif *arvif;
1732 lockdep_assert_held(&ar->conf_mutex);
1734 list_for_each_entry(arvif, &ar->arvifs, list)
1735 if (arvif->is_started)
1741 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1743 struct ath10k *ar = arvif->ar;
1744 struct ieee80211_vif *vif = arvif->vif;
1745 struct ieee80211_conf *conf = &ar->hw->conf;
1746 enum wmi_sta_powersave_param param;
1747 enum wmi_sta_ps_mode psmode;
1752 lockdep_assert_held(&arvif->ar->conf_mutex);
1754 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1757 enable_ps = arvif->ps;
1759 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1760 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1762 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1767 if (!arvif->is_started) {
1768 /* mac80211 can update vif powersave state while disconnected.
1769 * Firmware doesn't behave nicely and consumes more power than
1770 * necessary if PS is disabled on a non-started vdev. Hence
1771 * force-enable PS for non-running vdevs.
1773 psmode = WMI_STA_PS_MODE_ENABLED;
1774 } else if (enable_ps) {
1775 psmode = WMI_STA_PS_MODE_ENABLED;
1776 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1778 ps_timeout = conf->dynamic_ps_timeout;
1779 if (ps_timeout == 0) {
1780 /* Firmware doesn't like 0 */
1781 ps_timeout = ieee80211_tu_to_usec(
1782 vif->bss_conf.beacon_int) / 1000;
1785 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1788 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1789 arvif->vdev_id, ret);
1793 psmode = WMI_STA_PS_MODE_DISABLED;
1796 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1797 arvif->vdev_id, psmode ? "enable" : "disable");
1799 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1801 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1802 psmode, arvif->vdev_id, ret);
1809 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1811 struct ath10k *ar = arvif->ar;
1812 struct wmi_sta_keepalive_arg arg = {};
1815 lockdep_assert_held(&arvif->ar->conf_mutex);
1817 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1820 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1823 /* Some firmware revisions have a bug and ignore the `enabled` field.
1824 * Instead use the interval to disable the keepalive.
1826 arg.vdev_id = arvif->vdev_id;
1828 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1829 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1831 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1833 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1834 arvif->vdev_id, ret);
1841 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1843 struct ath10k *ar = arvif->ar;
1844 struct ieee80211_vif *vif = arvif->vif;
1847 lockdep_assert_held(&arvif->ar->conf_mutex);
1849 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1852 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1855 if (!vif->csa_active)
1861 if (!ieee80211_csa_is_complete(vif)) {
1862 ieee80211_csa_update_counter(vif);
1864 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1866 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1869 ret = ath10k_mac_setup_prb_tmpl(arvif);
1871 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1874 ieee80211_csa_finish(vif);
1878 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1880 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1882 struct ath10k *ar = arvif->ar;
1884 mutex_lock(&ar->conf_mutex);
1885 ath10k_mac_vif_ap_csa_count_down(arvif);
1886 mutex_unlock(&ar->conf_mutex);
1889 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1890 struct ieee80211_vif *vif)
1892 struct sk_buff *skb = data;
1893 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1894 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1896 if (vif->type != NL80211_IFTYPE_STATION)
1899 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1902 cancel_delayed_work(&arvif->connection_loss_work);
1905 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1907 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1908 IEEE80211_IFACE_ITER_NORMAL,
1909 ath10k_mac_handle_beacon_iter,
1913 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1914 struct ieee80211_vif *vif)
1916 u32 *vdev_id = data;
1917 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1918 struct ath10k *ar = arvif->ar;
1919 struct ieee80211_hw *hw = ar->hw;
1921 if (arvif->vdev_id != *vdev_id)
1927 ieee80211_beacon_loss(vif);
1929 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1930 * (done by mac80211) succeeds but beacons do not resume then it
1931 * doesn't make sense to continue operation. Queue connection loss work
1932 * which can be cancelled when beacon is received.
1934 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1935 ATH10K_CONNECTION_LOSS_HZ);
1938 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1940 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1941 IEEE80211_IFACE_ITER_NORMAL,
1942 ath10k_mac_handle_beacon_miss_iter,
1946 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1948 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1949 connection_loss_work.work);
1950 struct ieee80211_vif *vif = arvif->vif;
1955 ieee80211_connection_loss(vif);
1958 /**********************/
1959 /* Station management */
1960 /**********************/
1962 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1963 struct ieee80211_vif *vif)
1965 /* Some firmware revisions have unstable STA powersave when listen
1966 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1967 * generate NullFunc frames properly even if buffered frames have been
1968 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1969 * buffered frames. Often pinging the device from AP would simply fail.
1971 * As a workaround set it to 1.
1973 if (vif->type == NL80211_IFTYPE_STATION)
1976 return ar->hw->conf.listen_interval;
1979 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1980 struct ieee80211_vif *vif,
1981 struct ieee80211_sta *sta,
1982 struct wmi_peer_assoc_complete_arg *arg)
1984 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1987 lockdep_assert_held(&ar->conf_mutex);
1989 if (vif->type == NL80211_IFTYPE_STATION)
1990 aid = vif->bss_conf.aid;
1994 ether_addr_copy(arg->addr, sta->addr);
1995 arg->vdev_id = arvif->vdev_id;
1996 arg->peer_aid = aid;
1997 arg->peer_flags |= WMI_PEER_AUTH;
1998 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1999 arg->peer_num_spatial_streams = 1;
2000 arg->peer_caps = vif->bss_conf.assoc_capability;
2003 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
2004 struct ieee80211_vif *vif,
2005 struct wmi_peer_assoc_complete_arg *arg)
2007 struct ieee80211_bss_conf *info = &vif->bss_conf;
2008 struct cfg80211_chan_def def;
2009 struct cfg80211_bss *bss;
2010 const u8 *rsnie = NULL;
2011 const u8 *wpaie = NULL;
2013 lockdep_assert_held(&ar->conf_mutex);
2015 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2018 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2019 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2021 const struct cfg80211_bss_ies *ies;
2024 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2026 ies = rcu_dereference(bss->ies);
2028 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2029 WLAN_OUI_TYPE_MICROSOFT_WPA,
2033 cfg80211_put_bss(ar->hw->wiphy, bss);
2036 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2037 if (rsnie || wpaie) {
2038 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2039 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
2043 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2044 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
2048 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2049 struct ieee80211_vif *vif,
2050 struct ieee80211_sta *sta,
2051 struct wmi_peer_assoc_complete_arg *arg)
2053 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2054 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2055 struct cfg80211_chan_def def;
2056 const struct ieee80211_supported_band *sband;
2057 const struct ieee80211_rate *rates;
2058 enum ieee80211_band band;
2063 lockdep_assert_held(&ar->conf_mutex);
2065 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2068 band = def.chan->band;
2069 sband = ar->hw->wiphy->bands[band];
2070 ratemask = sta->supp_rates[band];
2071 ratemask &= arvif->bitrate_mask.control[band].legacy;
2072 rates = sband->bitrates;
2074 rateset->num_rates = 0;
2076 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2077 if (!(ratemask & 1))
2080 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2081 rateset->rates[rateset->num_rates] = rate;
2082 rateset->num_rates++;
2087 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2091 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2092 if (ht_mcs_mask[nss])
2099 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2103 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2104 if (vht_mcs_mask[nss])
2110 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2111 struct ieee80211_vif *vif,
2112 struct ieee80211_sta *sta,
2113 struct wmi_peer_assoc_complete_arg *arg)
2115 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2116 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2117 struct cfg80211_chan_def def;
2118 enum ieee80211_band band;
2119 const u8 *ht_mcs_mask;
2120 const u16 *vht_mcs_mask;
2125 lockdep_assert_held(&ar->conf_mutex);
2127 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2130 if (!ht_cap->ht_supported)
2133 band = def.chan->band;
2134 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2135 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2137 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2138 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2141 arg->peer_flags |= WMI_PEER_HT;
2142 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2143 ht_cap->ampdu_factor)) - 1;
2145 arg->peer_mpdu_density =
2146 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2148 arg->peer_ht_caps = ht_cap->cap;
2149 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2151 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2152 arg->peer_flags |= WMI_PEER_LDPC;
2154 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2155 arg->peer_flags |= WMI_PEER_40MHZ;
2156 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2159 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2160 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2161 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2163 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2164 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2167 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2168 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2169 arg->peer_flags |= WMI_PEER_STBC;
2172 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2173 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2174 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2175 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2176 arg->peer_rate_caps |= stbc;
2177 arg->peer_flags |= WMI_PEER_STBC;
2180 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2181 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2182 else if (ht_cap->mcs.rx_mask[1])
2183 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2185 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2186 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2187 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2188 max_nss = (i / 8) + 1;
2189 arg->peer_ht_rates.rates[n++] = i;
2193 * This is a workaround for HT-enabled STAs which break the spec
2194 * and have no HT capabilities RX mask (no HT RX MCS map).
2196 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2197 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2199 * Firmware asserts if such situation occurs.
2202 arg->peer_ht_rates.num_rates = 8;
2203 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2204 arg->peer_ht_rates.rates[i] = i;
2206 arg->peer_ht_rates.num_rates = n;
2207 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2210 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2212 arg->peer_ht_rates.num_rates,
2213 arg->peer_num_spatial_streams);
2216 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2217 struct ath10k_vif *arvif,
2218 struct ieee80211_sta *sta)
2224 lockdep_assert_held(&ar->conf_mutex);
2226 if (sta->wme && sta->uapsd_queues) {
2227 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2228 sta->uapsd_queues, sta->max_sp);
2230 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2231 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2232 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2233 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2234 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2235 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2236 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2237 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2238 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2239 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2240 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2241 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2243 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2244 max_sp = sta->max_sp;
2246 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2248 WMI_AP_PS_PEER_PARAM_UAPSD,
2251 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2252 arvif->vdev_id, ret);
2256 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2258 WMI_AP_PS_PEER_PARAM_MAX_SP,
2261 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2262 arvif->vdev_id, ret);
2266 /* TODO setup this based on STA listen interval and
2267 beacon interval. Currently we don't know
2268 sta->listen_interval - mac80211 patch required.
2269 Currently use 10 seconds */
2270 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2271 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2274 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2275 arvif->vdev_id, ret);
2284 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2285 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2292 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2293 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2297 idx_limit = fls(mcs_map) - 1;
2301 switch (idx_limit) {
2302 case 0: /* fall through */
2303 case 1: /* fall through */
2304 case 2: /* fall through */
2305 case 3: /* fall through */
2306 case 4: /* fall through */
2307 case 5: /* fall through */
2308 case 6: /* fall through */
2310 /* see ath10k_mac_can_set_bitrate_mask() */
2314 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2317 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2320 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2323 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2327 tx_mcs_set &= ~(0x3 << (nss * 2));
2328 tx_mcs_set |= mcs << (nss * 2);
2334 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2335 struct ieee80211_vif *vif,
2336 struct ieee80211_sta *sta,
2337 struct wmi_peer_assoc_complete_arg *arg)
2339 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2340 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2341 struct cfg80211_chan_def def;
2342 enum ieee80211_band band;
2343 const u16 *vht_mcs_mask;
2346 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2349 if (!vht_cap->vht_supported)
2352 band = def.chan->band;
2353 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2355 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2358 arg->peer_flags |= WMI_PEER_VHT;
2360 if (def.chan->band == IEEE80211_BAND_2GHZ)
2361 arg->peer_flags |= WMI_PEER_VHT_2G;
2363 arg->peer_vht_caps = vht_cap->cap;
2365 ampdu_factor = (vht_cap->cap &
2366 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2367 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2369 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2370 * zero in VHT IE. Using it would result in degraded throughput.
2371 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2372 * it if VHT max_mpdu is smaller. */
2373 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2374 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2375 ampdu_factor)) - 1);
2377 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2378 arg->peer_flags |= WMI_PEER_80MHZ;
2380 arg->peer_vht_rates.rx_max_rate =
2381 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2382 arg->peer_vht_rates.rx_mcs_set =
2383 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2384 arg->peer_vht_rates.tx_max_rate =
2385 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2386 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2387 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2390 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2393 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2394 struct ieee80211_vif *vif,
2395 struct ieee80211_sta *sta,
2396 struct wmi_peer_assoc_complete_arg *arg)
2398 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2400 switch (arvif->vdev_type) {
2401 case WMI_VDEV_TYPE_AP:
2403 arg->peer_flags |= WMI_PEER_QOS;
2405 if (sta->wme && sta->uapsd_queues) {
2406 arg->peer_flags |= WMI_PEER_APSD;
2407 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2410 case WMI_VDEV_TYPE_STA:
2411 if (vif->bss_conf.qos)
2412 arg->peer_flags |= WMI_PEER_QOS;
2414 case WMI_VDEV_TYPE_IBSS:
2416 arg->peer_flags |= WMI_PEER_QOS;
2422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2423 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
2426 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2428 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2429 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2432 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2433 struct ieee80211_vif *vif,
2434 struct ieee80211_sta *sta,
2435 struct wmi_peer_assoc_complete_arg *arg)
2437 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2438 struct cfg80211_chan_def def;
2439 enum ieee80211_band band;
2440 const u8 *ht_mcs_mask;
2441 const u16 *vht_mcs_mask;
2442 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2444 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2447 band = def.chan->band;
2448 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2449 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2452 case IEEE80211_BAND_2GHZ:
2453 if (sta->vht_cap.vht_supported &&
2454 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2455 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2456 phymode = MODE_11AC_VHT40;
2458 phymode = MODE_11AC_VHT20;
2459 } else if (sta->ht_cap.ht_supported &&
2460 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2461 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2462 phymode = MODE_11NG_HT40;
2464 phymode = MODE_11NG_HT20;
2465 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2472 case IEEE80211_BAND_5GHZ:
2476 if (sta->vht_cap.vht_supported &&
2477 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2478 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2479 phymode = MODE_11AC_VHT80;
2480 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2481 phymode = MODE_11AC_VHT40;
2482 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2483 phymode = MODE_11AC_VHT20;
2484 } else if (sta->ht_cap.ht_supported &&
2485 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2486 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2487 phymode = MODE_11NA_HT40;
2489 phymode = MODE_11NA_HT20;
2499 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2500 sta->addr, ath10k_wmi_phymode_str(phymode));
2502 arg->peer_phymode = phymode;
2503 WARN_ON(phymode == MODE_UNKNOWN);
2506 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2507 struct ieee80211_vif *vif,
2508 struct ieee80211_sta *sta,
2509 struct wmi_peer_assoc_complete_arg *arg)
2511 lockdep_assert_held(&ar->conf_mutex);
2513 memset(arg, 0, sizeof(*arg));
2515 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2516 ath10k_peer_assoc_h_crypto(ar, vif, arg);
2517 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2518 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2519 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2520 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2521 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2526 static const u32 ath10k_smps_map[] = {
2527 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2528 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2529 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2530 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2533 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2535 const struct ieee80211_sta_ht_cap *ht_cap)
2539 if (!ht_cap->ht_supported)
2542 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2543 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2545 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2548 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2549 WMI_PEER_SMPS_STATE,
2550 ath10k_smps_map[smps]);
2553 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2554 struct ieee80211_vif *vif,
2555 struct ieee80211_sta_vht_cap vht_cap)
2557 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2562 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2565 if (!(ar->vht_cap_info &
2566 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2567 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2568 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2569 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2572 param = ar->wmi.vdev_param->txbf;
2575 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2578 /* The following logic is correct. If a remote STA advertises support
2579 * for being a beamformer then we should enable us being a beamformee.
2582 if (ar->vht_cap_info &
2583 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2584 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2585 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2586 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2588 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2589 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2592 if (ar->vht_cap_info &
2593 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2594 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2595 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2596 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2598 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2599 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2602 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2603 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2605 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2606 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2608 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2610 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2618 /* can be called only in mac80211 callbacks due to `key_count` usage */
2619 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2620 struct ieee80211_vif *vif,
2621 struct ieee80211_bss_conf *bss_conf)
2623 struct ath10k *ar = hw->priv;
2624 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2625 struct ieee80211_sta_ht_cap ht_cap;
2626 struct ieee80211_sta_vht_cap vht_cap;
2627 struct wmi_peer_assoc_complete_arg peer_arg;
2628 struct ieee80211_sta *ap_sta;
2631 lockdep_assert_held(&ar->conf_mutex);
2633 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2634 arvif->vdev_id, arvif->bssid, arvif->aid);
2638 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2640 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2641 bss_conf->bssid, arvif->vdev_id);
2646 /* ap_sta must be accessed only within rcu section which must be left
2647 * before calling ath10k_setup_peer_smps() which might sleep. */
2648 ht_cap = ap_sta->ht_cap;
2649 vht_cap = ap_sta->vht_cap;
2651 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2653 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2654 bss_conf->bssid, arvif->vdev_id, ret);
2661 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2663 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2664 bss_conf->bssid, arvif->vdev_id, ret);
2668 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2670 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2671 arvif->vdev_id, ret);
2675 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2677 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2678 arvif->vdev_id, bss_conf->bssid, ret);
2682 ath10k_dbg(ar, ATH10K_DBG_MAC,
2683 "mac vdev %d up (associated) bssid %pM aid %d\n",
2684 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2686 WARN_ON(arvif->is_up);
2688 arvif->aid = bss_conf->aid;
2689 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2691 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2693 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2694 arvif->vdev_id, ret);
2698 arvif->is_up = true;
2700 /* Workaround: Some firmware revisions (tested with qca6174
2701 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2702 * poked with peer param command.
2704 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2705 WMI_PEER_DUMMY_VAR, 1);
2707 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2708 arvif->bssid, arvif->vdev_id, ret);
2713 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2714 struct ieee80211_vif *vif)
2716 struct ath10k *ar = hw->priv;
2717 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2718 struct ieee80211_sta_vht_cap vht_cap = {};
2721 lockdep_assert_held(&ar->conf_mutex);
2723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2724 arvif->vdev_id, arvif->bssid);
2726 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2728 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2729 arvif->vdev_id, ret);
2731 arvif->def_wep_key_idx = -1;
2733 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2735 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2736 arvif->vdev_id, ret);
2740 arvif->is_up = false;
2742 cancel_delayed_work_sync(&arvif->connection_loss_work);
2745 static int ath10k_station_assoc(struct ath10k *ar,
2746 struct ieee80211_vif *vif,
2747 struct ieee80211_sta *sta,
2750 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2751 struct wmi_peer_assoc_complete_arg peer_arg;
2754 lockdep_assert_held(&ar->conf_mutex);
2756 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2758 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2759 sta->addr, arvif->vdev_id, ret);
2763 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2765 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2766 sta->addr, arvif->vdev_id, ret);
2770 /* Re-assoc is run only to update supported rates for given station. It
2771 * doesn't make much sense to reconfigure the peer completely.
2774 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2777 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2778 arvif->vdev_id, ret);
2782 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2784 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2785 sta->addr, arvif->vdev_id, ret);
2790 arvif->num_legacy_stations++;
2791 ret = ath10k_recalc_rtscts_prot(arvif);
2793 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2794 arvif->vdev_id, ret);
2799 /* Plumb cached keys only for static WEP */
2800 if (arvif->def_wep_key_idx != -1) {
2801 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2803 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2804 arvif->vdev_id, ret);
2813 static int ath10k_station_disassoc(struct ath10k *ar,
2814 struct ieee80211_vif *vif,
2815 struct ieee80211_sta *sta)
2817 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2820 lockdep_assert_held(&ar->conf_mutex);
2823 arvif->num_legacy_stations--;
2824 ret = ath10k_recalc_rtscts_prot(arvif);
2826 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2827 arvif->vdev_id, ret);
2832 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2834 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2835 arvif->vdev_id, ret);
2846 static int ath10k_update_channel_list(struct ath10k *ar)
2848 struct ieee80211_hw *hw = ar->hw;
2849 struct ieee80211_supported_band **bands;
2850 enum ieee80211_band band;
2851 struct ieee80211_channel *channel;
2852 struct wmi_scan_chan_list_arg arg = {0};
2853 struct wmi_channel_arg *ch;
2859 lockdep_assert_held(&ar->conf_mutex);
2861 bands = hw->wiphy->bands;
2862 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2866 for (i = 0; i < bands[band]->n_channels; i++) {
2867 if (bands[band]->channels[i].flags &
2868 IEEE80211_CHAN_DISABLED)
2875 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2876 arg.channels = kzalloc(len, GFP_KERNEL);
2881 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2885 for (i = 0; i < bands[band]->n_channels; i++) {
2886 channel = &bands[band]->channels[i];
2888 if (channel->flags & IEEE80211_CHAN_DISABLED)
2891 ch->allow_ht = true;
2893 /* FIXME: when should we really allow VHT? */
2894 ch->allow_vht = true;
2897 !(channel->flags & IEEE80211_CHAN_NO_IR);
2900 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2903 !!(channel->flags & IEEE80211_CHAN_RADAR);
2905 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2906 ch->passive = passive;
2908 /* the firmware is ignoring the "radar" flag of the
2909 * channel and is scanning actively using Probe Requests
2910 * on "Radar detection"/DFS channels which are not
2911 * marked as "available"
2913 ch->passive |= ch->chan_radar;
2915 ch->freq = channel->center_freq;
2916 ch->band_center_freq1 = channel->center_freq;
2918 ch->max_power = channel->max_power * 2;
2919 ch->max_reg_power = channel->max_reg_power * 2;
2920 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2921 ch->reg_class_id = 0; /* FIXME */
2923 /* FIXME: why use only legacy modes, why not any
2924 * HT/VHT modes? Would that even make any
2926 if (channel->band == IEEE80211_BAND_2GHZ)
2927 ch->mode = MODE_11G;
2929 ch->mode = MODE_11A;
2931 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2934 ath10k_dbg(ar, ATH10K_DBG_WMI,
2935 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2936 ch - arg.channels, arg.n_channels,
2937 ch->freq, ch->max_power, ch->max_reg_power,
2938 ch->max_antenna_gain, ch->mode);
2944 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2945 kfree(arg.channels);
2950 static enum wmi_dfs_region
2951 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2953 switch (dfs_region) {
2954 case NL80211_DFS_UNSET:
2955 return WMI_UNINIT_DFS_DOMAIN;
2956 case NL80211_DFS_FCC:
2957 return WMI_FCC_DFS_DOMAIN;
2958 case NL80211_DFS_ETSI:
2959 return WMI_ETSI_DFS_DOMAIN;
2960 case NL80211_DFS_JP:
2961 return WMI_MKK4_DFS_DOMAIN;
2963 return WMI_UNINIT_DFS_DOMAIN;
2966 static void ath10k_regd_update(struct ath10k *ar)
2968 struct reg_dmn_pair_mapping *regpair;
2970 enum wmi_dfs_region wmi_dfs_reg;
2971 enum nl80211_dfs_regions nl_dfs_reg;
2973 lockdep_assert_held(&ar->conf_mutex);
2975 ret = ath10k_update_channel_list(ar);
2977 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2979 regpair = ar->ath_common.regulatory.regpair;
2981 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2982 nl_dfs_reg = ar->dfs_detector->region;
2983 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2985 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2988 /* Target allows setting up per-band regdomain but ath_common provides
2989 * a combined one only */
2990 ret = ath10k_wmi_pdev_set_regdomain(ar,
2991 regpair->reg_domain,
2992 regpair->reg_domain, /* 2ghz */
2993 regpair->reg_domain, /* 5ghz */
2994 regpair->reg_2ghz_ctl,
2995 regpair->reg_5ghz_ctl,
2998 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
3001 static void ath10k_reg_notifier(struct wiphy *wiphy,
3002 struct regulatory_request *request)
3004 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
3005 struct ath10k *ar = hw->priv;
3008 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3010 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3011 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3012 request->dfs_region);
3013 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3014 request->dfs_region);
3016 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3017 request->dfs_region);
3020 mutex_lock(&ar->conf_mutex);
3021 if (ar->state == ATH10K_STATE_ON)
3022 ath10k_regd_update(ar);
3023 mutex_unlock(&ar->conf_mutex);
3030 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3032 lockdep_assert_held(&ar->htt.tx_lock);
3034 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3035 ar->tx_paused |= BIT(reason);
3036 ieee80211_stop_queues(ar->hw);
3039 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3040 struct ieee80211_vif *vif)
3042 struct ath10k *ar = data;
3043 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3045 if (arvif->tx_paused)
3048 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3051 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3053 lockdep_assert_held(&ar->htt.tx_lock);
3055 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3056 ar->tx_paused &= ~BIT(reason);
3061 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3062 IEEE80211_IFACE_ITER_RESUME_ALL,
3063 ath10k_mac_tx_unlock_iter,
3066 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3069 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3071 struct ath10k *ar = arvif->ar;
3073 lockdep_assert_held(&ar->htt.tx_lock);
3075 WARN_ON(reason >= BITS_PER_LONG);
3076 arvif->tx_paused |= BIT(reason);
3077 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3080 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3082 struct ath10k *ar = arvif->ar;
3084 lockdep_assert_held(&ar->htt.tx_lock);
3086 WARN_ON(reason >= BITS_PER_LONG);
3087 arvif->tx_paused &= ~BIT(reason);
3092 if (arvif->tx_paused)
3095 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3098 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3099 enum wmi_tlv_tx_pause_id pause_id,
3100 enum wmi_tlv_tx_pause_action action)
3102 struct ath10k *ar = arvif->ar;
3104 lockdep_assert_held(&ar->htt.tx_lock);
3107 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3108 ath10k_mac_vif_tx_lock(arvif, pause_id);
3110 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3111 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3114 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3115 action, arvif->vdev_id);
3120 struct ath10k_mac_tx_pause {
3122 enum wmi_tlv_tx_pause_id pause_id;
3123 enum wmi_tlv_tx_pause_action action;
3126 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3127 struct ieee80211_vif *vif)
3129 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3130 struct ath10k_mac_tx_pause *arg = data;
3132 if (arvif->vdev_id != arg->vdev_id)
3135 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3138 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3139 enum wmi_tlv_tx_pause_id pause_id,
3140 enum wmi_tlv_tx_pause_action action)
3142 struct ath10k_mac_tx_pause arg = {
3144 .pause_id = pause_id,
3148 spin_lock_bh(&ar->htt.tx_lock);
3149 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3150 IEEE80211_IFACE_ITER_RESUME_ALL,
3151 ath10k_mac_handle_tx_pause_iter,
3153 spin_unlock_bh(&ar->htt.tx_lock);
3156 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3158 if (ieee80211_is_mgmt(hdr->frame_control))
3159 return HTT_DATA_TX_EXT_TID_MGMT;
3161 if (!ieee80211_is_data_qos(hdr->frame_control))
3162 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3164 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3165 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3167 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3170 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
3173 return ath10k_vif_to_arvif(vif)->vdev_id;
3175 if (ar->monitor_started)
3176 return ar->monitor_vdev_id;
3178 ath10k_warn(ar, "failed to resolve vdev id\n");
3182 static enum ath10k_hw_txrx_mode
3183 ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
3184 struct ieee80211_sta *sta, struct sk_buff *skb)
3186 const struct ieee80211_hdr *hdr = (void *)skb->data;
3187 __le16 fc = hdr->frame_control;
3189 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3190 return ATH10K_HW_TXRX_RAW;
3192 if (ieee80211_is_mgmt(fc))
3193 return ATH10K_HW_TXRX_MGMT;
3197 * NullFunc frames are mostly used to ping if a client or AP are still
3198 * reachable and responsive. This implies tx status reports must be
3199 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3200 * come to a conclusion that the other end disappeared and tear down
3201 * BSS connection or it can never disconnect from BSS/client (which is
3204 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3205 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3206 * which seems to deliver correct tx reports for NullFunc frames. The
3207 * downside of using it is it ignores client powersave state so it can
3208 * end up disconnecting sleeping clients in AP mode. It should fix STA
3209 * mode though because AP don't sleep.
3211 if (ar->htt.target_version_major < 3 &&
3212 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3213 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3214 return ATH10K_HW_TXRX_MGMT;
3218 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3219 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3220 * to work with Ethernet txmode so use it.
3222 * FIXME: Check if raw mode works with TDLS.
3224 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3225 return ATH10K_HW_TXRX_ETHERNET;
3227 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3228 return ATH10K_HW_TXRX_RAW;
3230 return ATH10K_HW_TXRX_NATIVE_WIFI;
3233 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3234 struct sk_buff *skb) {
3235 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3236 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3237 IEEE80211_TX_CTL_INJECTED;
3238 if ((info->flags & mask) == mask)
3241 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3245 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3246 * Control in the header.
3248 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3250 struct ieee80211_hdr *hdr = (void *)skb->data;
3251 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3254 if (!ieee80211_is_data_qos(hdr->frame_control))
3257 qos_ctl = ieee80211_get_qos_ctl(hdr);
3258 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3259 skb->data, (void *)qos_ctl - (void *)skb->data);
3260 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3262 /* Some firmware revisions don't handle sending QoS NullFunc well.
3263 * These frames are mainly used for CQM purposes so it doesn't really
3264 * matter whether QoS NullFunc or NullFunc are sent.
3266 hdr = (void *)skb->data;
3267 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3268 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3270 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3273 static void ath10k_tx_h_8023(struct sk_buff *skb)
3275 struct ieee80211_hdr *hdr;
3276 struct rfc1042_hdr *rfc1042;
3283 hdr = (void *)skb->data;
3284 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3285 rfc1042 = (void *)skb->data + hdrlen;
3287 ether_addr_copy(da, ieee80211_get_DA(hdr));
3288 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3289 type = rfc1042->snap_type;
3291 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3292 skb_push(skb, sizeof(*eth));
3294 eth = (void *)skb->data;
3295 ether_addr_copy(eth->h_dest, da);
3296 ether_addr_copy(eth->h_source, sa);
3297 eth->h_proto = type;
3300 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3301 struct ieee80211_vif *vif,
3302 struct sk_buff *skb)
3304 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3305 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3307 /* This is case only for P2P_GO */
3308 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3309 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3312 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3313 spin_lock_bh(&ar->data_lock);
3314 if (arvif->u.ap.noa_data)
3315 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3317 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3318 arvif->u.ap.noa_data,
3319 arvif->u.ap.noa_len);
3320 spin_unlock_bh(&ar->data_lock);
3324 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3326 /* FIXME: Not really sure since when the behaviour changed. At some
3327 * point new firmware stopped requiring creation of peer entries for
3328 * offchannel tx (and actually creating them causes issues with wmi-htc
3329 * tx credit replenishment and reliability). Assuming it's at least 3.4
3330 * because that's when the `freq` was introduced to TX_FRM HTT command.
3332 return !(ar->htt.target_version_major >= 3 &&
3333 ar->htt.target_version_minor >= 4);
3336 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3338 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3340 if (skb_queue_len_lockless(q) >= ATH10K_MAX_NUM_MGMT_PENDING) {
3341 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3345 skb_queue_tail(q, skb);
3346 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3351 static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3353 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3354 struct ath10k_htt *htt = &ar->htt;
3357 switch (cb->txmode) {
3358 case ATH10K_HW_TXRX_RAW:
3359 case ATH10K_HW_TXRX_NATIVE_WIFI:
3360 case ATH10K_HW_TXRX_ETHERNET:
3361 ret = ath10k_htt_tx(htt, skb);
3363 case ATH10K_HW_TXRX_MGMT:
3364 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3366 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3367 else if (ar->htt.target_version_major >= 3)
3368 ret = ath10k_htt_tx(htt, skb);
3370 ret = ath10k_htt_mgmt_tx(htt, skb);
3375 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3377 ieee80211_free_txskb(ar->hw, skb);
3381 void ath10k_offchan_tx_purge(struct ath10k *ar)
3383 struct sk_buff *skb;
3386 skb = skb_dequeue(&ar->offchan_tx_queue);
3390 ieee80211_free_txskb(ar->hw, skb);
3394 void ath10k_offchan_tx_work(struct work_struct *work)
3396 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3397 struct ath10k_peer *peer;
3398 struct ieee80211_hdr *hdr;
3399 struct sk_buff *skb;
3400 const u8 *peer_addr;
3403 unsigned long time_left;
3404 bool tmp_peer_created = false;
3406 /* FW requirement: We must create a peer before FW will send out
3407 * an offchannel frame. Otherwise the frame will be stuck and
3408 * never transmitted. We delete the peer upon tx completion.
3409 * It is unlikely that a peer for offchannel tx will already be
3410 * present. However it may be in some rare cases so account for that.
3411 * Otherwise we might remove a legitimate peer and break stuff. */
3414 skb = skb_dequeue(&ar->offchan_tx_queue);
3418 mutex_lock(&ar->conf_mutex);
3420 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
3423 hdr = (struct ieee80211_hdr *)skb->data;
3424 peer_addr = ieee80211_get_DA(hdr);
3425 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
3427 spin_lock_bh(&ar->data_lock);
3428 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3429 spin_unlock_bh(&ar->data_lock);
3432 /* FIXME: should this use ath10k_warn()? */
3433 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3434 peer_addr, vdev_id);
3437 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3438 WMI_PEER_TYPE_DEFAULT);
3440 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3441 peer_addr, vdev_id, ret);
3442 tmp_peer_created = (ret == 0);
3445 spin_lock_bh(&ar->data_lock);
3446 reinit_completion(&ar->offchan_tx_completed);
3447 ar->offchan_tx_skb = skb;
3448 spin_unlock_bh(&ar->data_lock);
3450 ath10k_mac_tx(ar, skb);
3453 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3455 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
3458 if (!peer && tmp_peer_created) {
3459 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3461 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3462 peer_addr, vdev_id, ret);
3465 mutex_unlock(&ar->conf_mutex);
3469 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3471 struct sk_buff *skb;
3474 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3478 ieee80211_free_txskb(ar->hw, skb);
3482 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3484 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3485 struct sk_buff *skb;
3489 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3493 ret = ath10k_wmi_mgmt_tx(ar, skb);
3495 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3497 ieee80211_free_txskb(ar->hw, skb);
3506 void __ath10k_scan_finish(struct ath10k *ar)
3508 lockdep_assert_held(&ar->data_lock);
3510 switch (ar->scan.state) {
3511 case ATH10K_SCAN_IDLE:
3513 case ATH10K_SCAN_RUNNING:
3514 case ATH10K_SCAN_ABORTING:
3515 if (!ar->scan.is_roc)
3516 ieee80211_scan_completed(ar->hw,
3518 ATH10K_SCAN_ABORTING));
3519 else if (ar->scan.roc_notify)
3520 ieee80211_remain_on_channel_expired(ar->hw);
3522 case ATH10K_SCAN_STARTING:
3523 ar->scan.state = ATH10K_SCAN_IDLE;
3524 ar->scan_channel = NULL;
3525 ath10k_offchan_tx_purge(ar);
3526 cancel_delayed_work(&ar->scan.timeout);
3527 complete_all(&ar->scan.completed);
3532 void ath10k_scan_finish(struct ath10k *ar)
3534 spin_lock_bh(&ar->data_lock);
3535 __ath10k_scan_finish(ar);
3536 spin_unlock_bh(&ar->data_lock);
3539 static int ath10k_scan_stop(struct ath10k *ar)
3541 struct wmi_stop_scan_arg arg = {
3542 .req_id = 1, /* FIXME */
3543 .req_type = WMI_SCAN_STOP_ONE,
3544 .u.scan_id = ATH10K_SCAN_ID,
3548 lockdep_assert_held(&ar->conf_mutex);
3550 ret = ath10k_wmi_stop_scan(ar, &arg);
3552 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3556 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
3558 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3560 } else if (ret > 0) {
3565 /* Scan state should be updated upon scan completion but in case
3566 * firmware fails to deliver the event (for whatever reason) it is
3567 * desired to clean up scan state anyway. Firmware may have just
3568 * dropped the scan completion event delivery due to transport pipe
3569 * being overflown with data and/or it can recover on its own before
3570 * next scan request is submitted.
3572 spin_lock_bh(&ar->data_lock);
3573 if (ar->scan.state != ATH10K_SCAN_IDLE)
3574 __ath10k_scan_finish(ar);
3575 spin_unlock_bh(&ar->data_lock);
3580 static void ath10k_scan_abort(struct ath10k *ar)
3584 lockdep_assert_held(&ar->conf_mutex);
3586 spin_lock_bh(&ar->data_lock);
3588 switch (ar->scan.state) {
3589 case ATH10K_SCAN_IDLE:
3590 /* This can happen if timeout worker kicked in and called
3591 * abortion while scan completion was being processed.
3594 case ATH10K_SCAN_STARTING:
3595 case ATH10K_SCAN_ABORTING:
3596 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3597 ath10k_scan_state_str(ar->scan.state),
3600 case ATH10K_SCAN_RUNNING:
3601 ar->scan.state = ATH10K_SCAN_ABORTING;
3602 spin_unlock_bh(&ar->data_lock);
3604 ret = ath10k_scan_stop(ar);
3606 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3608 spin_lock_bh(&ar->data_lock);
3612 spin_unlock_bh(&ar->data_lock);
3615 void ath10k_scan_timeout_work(struct work_struct *work)
3617 struct ath10k *ar = container_of(work, struct ath10k,
3620 mutex_lock(&ar->conf_mutex);
3621 ath10k_scan_abort(ar);
3622 mutex_unlock(&ar->conf_mutex);
3625 static int ath10k_start_scan(struct ath10k *ar,
3626 const struct wmi_start_scan_arg *arg)
3630 lockdep_assert_held(&ar->conf_mutex);
3632 ret = ath10k_wmi_start_scan(ar, arg);
3636 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3638 ret = ath10k_scan_stop(ar);
3640 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3645 /* If we failed to start the scan, return error code at
3646 * this point. This is probably due to some issue in the
3647 * firmware, but no need to wedge the driver due to that...
3649 spin_lock_bh(&ar->data_lock);
3650 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3651 spin_unlock_bh(&ar->data_lock);
3654 spin_unlock_bh(&ar->data_lock);
3659 /**********************/
3660 /* mac80211 callbacks */
3661 /**********************/
3663 static void ath10k_tx(struct ieee80211_hw *hw,
3664 struct ieee80211_tx_control *control,
3665 struct sk_buff *skb)
3667 struct ath10k *ar = hw->priv;
3668 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3669 struct ieee80211_vif *vif = info->control.vif;
3670 struct ieee80211_sta *sta = control->sta;
3671 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3672 __le16 fc = hdr->frame_control;
3674 /* We should disable CCK RATE due to P2P */
3675 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3676 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3678 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
3679 ATH10K_SKB_CB(skb)->htt.freq = 0;
3680 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
3681 ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb);
3682 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
3683 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
3684 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
3686 switch (ATH10K_SKB_CB(skb)->txmode) {
3687 case ATH10K_HW_TXRX_MGMT:
3688 case ATH10K_HW_TXRX_NATIVE_WIFI:
3689 ath10k_tx_h_nwifi(hw, skb);
3690 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3691 ath10k_tx_h_seq_no(vif, skb);
3693 case ATH10K_HW_TXRX_ETHERNET:
3694 ath10k_tx_h_8023(skb);
3696 case ATH10K_HW_TXRX_RAW:
3697 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3699 ieee80211_free_txskb(hw, skb);
3704 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3705 spin_lock_bh(&ar->data_lock);
3706 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
3707 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
3708 spin_unlock_bh(&ar->data_lock);
3710 if (ath10k_mac_need_offchan_tx_work(ar)) {
3711 ATH10K_SKB_CB(skb)->htt.freq = 0;
3712 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
3714 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3717 skb_queue_tail(&ar->offchan_tx_queue, skb);
3718 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3723 ath10k_mac_tx(ar, skb);
3726 /* Must not be called with conf_mutex held as workers can use that also. */
3727 void ath10k_drain_tx(struct ath10k *ar)
3729 /* make sure rcu-protected mac80211 tx path itself is drained */
3732 ath10k_offchan_tx_purge(ar);
3733 ath10k_mgmt_over_wmi_tx_purge(ar);
3735 cancel_work_sync(&ar->offchan_tx_work);
3736 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3739 void ath10k_halt(struct ath10k *ar)
3741 struct ath10k_vif *arvif;
3743 lockdep_assert_held(&ar->conf_mutex);
3745 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3746 ar->filter_flags = 0;
3747 ar->monitor = false;
3748 ar->monitor_arvif = NULL;
3750 if (ar->monitor_started)
3751 ath10k_monitor_stop(ar);
3753 ar->monitor_started = false;
3756 ath10k_scan_finish(ar);
3757 ath10k_peer_cleanup_all(ar);
3758 ath10k_core_stop(ar);
3759 ath10k_hif_power_down(ar);
3761 spin_lock_bh(&ar->data_lock);
3762 list_for_each_entry(arvif, &ar->arvifs, list)
3763 ath10k_mac_vif_beacon_cleanup(arvif);
3764 spin_unlock_bh(&ar->data_lock);
3767 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3769 struct ath10k *ar = hw->priv;
3771 mutex_lock(&ar->conf_mutex);
3773 *tx_ant = ar->cfg_tx_chainmask;
3774 *rx_ant = ar->cfg_rx_chainmask;
3776 mutex_unlock(&ar->conf_mutex);
3781 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3783 /* It is not clear that allowing gaps in chainmask
3784 * is helpful. Probably it will not do what user
3785 * is hoping for, so warn in that case.
3787 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3790 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3794 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
3796 int nsts = ar->vht_cap_info;
3798 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
3799 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
3801 /* If firmware does not deliver to host number of space-time
3802 * streams supported, assume it support up to 4 BF STS and return
3803 * the value for VHT CAP: nsts-1)
3811 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
3813 int sound_dim = ar->vht_cap_info;
3815 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3816 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3818 /* If the sounding dimension is not advertised by the firmware,
3819 * let's use a default value of 1
3827 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3829 struct ieee80211_sta_vht_cap vht_cap = {0};
3834 vht_cap.vht_supported = 1;
3835 vht_cap.cap = ar->vht_cap_info;
3837 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
3838 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
3839 val = ath10k_mac_get_vht_cap_bf_sts(ar);
3840 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
3841 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
3846 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
3847 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
3848 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
3849 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3850 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3856 for (i = 0; i < 8; i++) {
3857 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
3858 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3860 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3863 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3864 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3869 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3872 struct ieee80211_sta_ht_cap ht_cap = {0};
3874 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3877 ht_cap.ht_supported = 1;
3878 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3879 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3880 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3881 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3882 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3884 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3885 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3887 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3888 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3890 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3893 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3894 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3899 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3900 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3902 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3905 stbc = ar->ht_cap_info;
3906 stbc &= WMI_HT_CAP_RX_STBC;
3907 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3908 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3909 stbc &= IEEE80211_HT_CAP_RX_STBC;
3914 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3915 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3917 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3918 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3920 /* max AMSDU is implicitly taken from vht_cap_info */
3921 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3922 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3924 for (i = 0; i < ar->num_rf_chains; i++) {
3925 if (ar->cfg_rx_chainmask & BIT(i))
3926 ht_cap.mcs.rx_mask[i] = 0xFF;
3929 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3934 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
3936 struct ieee80211_supported_band *band;
3937 struct ieee80211_sta_vht_cap vht_cap;
3938 struct ieee80211_sta_ht_cap ht_cap;
3940 ht_cap = ath10k_get_ht_cap(ar);
3941 vht_cap = ath10k_create_vht_cap(ar);
3943 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3944 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3945 band->ht_cap = ht_cap;
3947 /* Enable the VHT support at 2.4 GHz */
3948 band->vht_cap = vht_cap;
3950 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3951 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3952 band->ht_cap = ht_cap;
3953 band->vht_cap = vht_cap;
3957 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3961 lockdep_assert_held(&ar->conf_mutex);
3963 ath10k_check_chain_mask(ar, tx_ant, "tx");
3964 ath10k_check_chain_mask(ar, rx_ant, "rx");
3966 ar->cfg_tx_chainmask = tx_ant;
3967 ar->cfg_rx_chainmask = rx_ant;
3969 if ((ar->state != ATH10K_STATE_ON) &&
3970 (ar->state != ATH10K_STATE_RESTARTED))
3973 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3976 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
3981 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3984 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
3989 /* Reload HT/VHT capability */
3990 ath10k_mac_setup_ht_vht_cap(ar);
3995 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3997 struct ath10k *ar = hw->priv;
4000 mutex_lock(&ar->conf_mutex);
4001 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4002 mutex_unlock(&ar->conf_mutex);
4006 static int ath10k_start(struct ieee80211_hw *hw)
4008 struct ath10k *ar = hw->priv;
4013 * This makes sense only when restarting hw. It is harmless to call
4014 * uncoditionally. This is necessary to make sure no HTT/WMI tx
4015 * commands will be submitted while restarting.
4017 ath10k_drain_tx(ar);
4019 mutex_lock(&ar->conf_mutex);
4021 switch (ar->state) {
4022 case ATH10K_STATE_OFF:
4023 ar->state = ATH10K_STATE_ON;
4025 case ATH10K_STATE_RESTARTING:
4027 ar->state = ATH10K_STATE_RESTARTED;
4029 case ATH10K_STATE_ON:
4030 case ATH10K_STATE_RESTARTED:
4031 case ATH10K_STATE_WEDGED:
4035 case ATH10K_STATE_UTF:
4040 ret = ath10k_hif_power_up(ar);
4042 ath10k_err(ar, "Could not init hif: %d\n", ret);
4046 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
4048 ath10k_err(ar, "Could not init core: %d\n", ret);
4049 goto err_power_down;
4052 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
4054 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4058 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
4060 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4064 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4065 ret = ath10k_wmi_adaptive_qcs(ar, true);
4067 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4073 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4074 burst_enable = ar->wmi.pdev_param->burst_enable;
4075 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
4077 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4082 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4085 * By default FW set ARP frames ac to voice (6). In that case ARP
4086 * exchange is not working properly for UAPSD enabled AP. ARP requests
4087 * which arrives with access category 0 are processed by network stack
4088 * and send back with access category 0, but FW changes access category
4089 * to 6. Set ARP frames access category to best effort (0) solves
4093 ret = ath10k_wmi_pdev_set_param(ar,
4094 ar->wmi.pdev_param->arp_ac_override, 0);
4096 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4101 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4103 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4104 WMI_CCA_DETECT_LEVEL_AUTO,
4105 WMI_CCA_DETECT_MARGIN_AUTO);
4107 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4113 ret = ath10k_wmi_pdev_set_param(ar,
4114 ar->wmi.pdev_param->ani_enable, 1);
4116 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4121 ar->ani_enabled = true;
4123 ar->num_started_vdevs = 0;
4124 ath10k_regd_update(ar);
4126 ath10k_spectral_start(ar);
4127 ath10k_thermal_set_throttling(ar);
4129 mutex_unlock(&ar->conf_mutex);
4133 ath10k_core_stop(ar);
4136 ath10k_hif_power_down(ar);
4139 ar->state = ATH10K_STATE_OFF;
4142 mutex_unlock(&ar->conf_mutex);
4146 static void ath10k_stop(struct ieee80211_hw *hw)
4148 struct ath10k *ar = hw->priv;
4150 ath10k_drain_tx(ar);
4152 mutex_lock(&ar->conf_mutex);
4153 if (ar->state != ATH10K_STATE_OFF) {
4155 ar->state = ATH10K_STATE_OFF;
4157 mutex_unlock(&ar->conf_mutex);
4159 cancel_delayed_work_sync(&ar->scan.timeout);
4160 cancel_work_sync(&ar->restart_work);
4163 static int ath10k_config_ps(struct ath10k *ar)
4165 struct ath10k_vif *arvif;
4168 lockdep_assert_held(&ar->conf_mutex);
4170 list_for_each_entry(arvif, &ar->arvifs, list) {
4171 ret = ath10k_mac_vif_setup_ps(arvif);
4173 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4181 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4186 lockdep_assert_held(&ar->conf_mutex);
4188 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4190 param = ar->wmi.pdev_param->txpower_limit2g;
4191 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4193 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4198 param = ar->wmi.pdev_param->txpower_limit5g;
4199 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4201 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4209 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4211 struct ath10k_vif *arvif;
4212 int ret, txpower = -1;
4214 lockdep_assert_held(&ar->conf_mutex);
4216 list_for_each_entry(arvif, &ar->arvifs, list) {
4217 if (arvif->txpower <= 0)
4221 txpower = arvif->txpower;
4223 txpower = min(txpower, arvif->txpower);
4229 ret = ath10k_mac_txpower_setup(ar, txpower);
4231 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4239 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4241 struct ath10k *ar = hw->priv;
4242 struct ieee80211_conf *conf = &hw->conf;
4245 mutex_lock(&ar->conf_mutex);
4247 if (changed & IEEE80211_CONF_CHANGE_PS)
4248 ath10k_config_ps(ar);
4250 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4251 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4252 ret = ath10k_monitor_recalc(ar);
4254 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4257 mutex_unlock(&ar->conf_mutex);
4261 static u32 get_nss_from_chainmask(u16 chain_mask)
4263 if ((chain_mask & 0xf) == 0xf)
4265 else if ((chain_mask & 0x7) == 0x7)
4267 else if ((chain_mask & 0x3) == 0x3)
4272 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4275 struct ath10k *ar = arvif->ar;
4279 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4282 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4283 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4284 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4285 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4287 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4288 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4289 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4290 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4295 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4296 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4298 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4299 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4300 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4302 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4303 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4305 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4306 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4307 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4309 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4310 ar->wmi.vdev_param->txbf, value);
4315 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4316 * because we will send mgmt frames without CCK. This requirement
4317 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4320 static int ath10k_add_interface(struct ieee80211_hw *hw,
4321 struct ieee80211_vif *vif)
4323 struct ath10k *ar = hw->priv;
4324 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4325 enum wmi_sta_powersave_param param;
4332 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4334 mutex_lock(&ar->conf_mutex);
4336 memset(arvif, 0, sizeof(*arvif));
4341 INIT_LIST_HEAD(&arvif->list);
4342 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4343 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4344 ath10k_mac_vif_sta_connection_loss_work);
4346 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4347 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4348 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4349 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4350 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4351 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4354 if (ar->num_peers >= ar->max_num_peers) {
4355 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4360 if (ar->free_vdev_map == 0) {
4361 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4365 bit = __ffs64(ar->free_vdev_map);
4367 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4368 bit, ar->free_vdev_map);
4370 arvif->vdev_id = bit;
4371 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4373 switch (vif->type) {
4374 case NL80211_IFTYPE_P2P_DEVICE:
4375 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4376 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4378 case NL80211_IFTYPE_UNSPECIFIED:
4379 case NL80211_IFTYPE_STATION:
4380 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4382 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4384 case NL80211_IFTYPE_ADHOC:
4385 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4387 case NL80211_IFTYPE_MESH_POINT:
4388 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4390 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4393 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4395 case NL80211_IFTYPE_AP:
4396 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4399 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4401 case NL80211_IFTYPE_MONITOR:
4402 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4409 /* Using vdev_id as queue number will make it very easy to do per-vif
4410 * tx queue locking. This shouldn't wrap due to interface combinations
4411 * but do a modulo for correctness sake and prevent using offchannel tx
4412 * queues for regular vif tx.
4414 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4415 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4416 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4418 /* Some firmware revisions don't wait for beacon tx completion before
4419 * sending another SWBA event. This could lead to hardware using old
4420 * (freed) beacon data in some cases, e.g. tx credit starvation
4421 * combined with missed TBTT. This is very very rare.
4423 * On non-IOMMU-enabled hosts this could be a possible security issue
4424 * because hw could beacon some random data on the air. On
4425 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4426 * device would crash.
4428 * Since there are no beacon tx completions (implicit nor explicit)
4429 * propagated to host the only workaround for this is to allocate a
4430 * DMA-coherent buffer for a lifetime of a vif and use it for all
4431 * beacon tx commands. Worst case for this approach is some beacons may
4432 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4434 if (vif->type == NL80211_IFTYPE_ADHOC ||
4435 vif->type == NL80211_IFTYPE_MESH_POINT ||
4436 vif->type == NL80211_IFTYPE_AP) {
4437 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4438 IEEE80211_MAX_FRAME_LEN,
4439 &arvif->beacon_paddr,
4441 if (!arvif->beacon_buf) {
4443 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4448 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4449 arvif->nohwcrypt = true;
4451 if (arvif->nohwcrypt &&
4452 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4454 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4458 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4459 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4460 arvif->beacon_buf ? "single-buf" : "per-skb");
4462 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4463 arvif->vdev_subtype, vif->addr);
4465 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4466 arvif->vdev_id, ret);
4470 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4471 spin_lock_bh(&ar->data_lock);
4472 list_add(&arvif->list, &ar->arvifs);
4473 spin_unlock_bh(&ar->data_lock);
4475 /* It makes no sense to have firmware do keepalives. mac80211 already
4476 * takes care of this with idle connection polling.
4478 ret = ath10k_mac_vif_disable_keepalive(arvif);
4480 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4481 arvif->vdev_id, ret);
4482 goto err_vdev_delete;
4485 arvif->def_wep_key_idx = -1;
4487 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4488 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4489 ATH10K_HW_TXRX_NATIVE_WIFI);
4490 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4491 if (ret && ret != -EOPNOTSUPP) {
4492 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4493 arvif->vdev_id, ret);
4494 goto err_vdev_delete;
4497 /* Configuring number of spatial stream for monitor interface is causing
4498 * target assert in qca9888 and qca6174.
4500 if (ar->cfg_tx_chainmask && (vif->type != NL80211_IFTYPE_MONITOR)) {
4501 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4503 vdev_param = ar->wmi.vdev_param->nss;
4504 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4507 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4508 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4510 goto err_vdev_delete;
4514 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4515 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4516 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4517 WMI_PEER_TYPE_DEFAULT);
4519 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4520 arvif->vdev_id, ret);
4521 goto err_vdev_delete;
4525 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4526 ret = ath10k_mac_set_kickout(arvif);
4528 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
4529 arvif->vdev_id, ret);
4530 goto err_peer_delete;
4534 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4535 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4536 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4537 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4540 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
4541 arvif->vdev_id, ret);
4542 goto err_peer_delete;
4545 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4547 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4548 arvif->vdev_id, ret);
4549 goto err_peer_delete;
4552 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4554 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4555 arvif->vdev_id, ret);
4556 goto err_peer_delete;
4560 ret = ath10k_mac_set_txbf_conf(arvif);
4562 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
4563 arvif->vdev_id, ret);
4564 goto err_peer_delete;
4567 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
4569 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4570 arvif->vdev_id, ret);
4571 goto err_peer_delete;
4574 arvif->txpower = vif->bss_conf.txpower;
4575 ret = ath10k_mac_txpower_recalc(ar);
4577 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4578 goto err_peer_delete;
4581 if (vif->type == NL80211_IFTYPE_MONITOR) {
4582 ar->monitor_arvif = arvif;
4583 ret = ath10k_monitor_recalc(ar);
4585 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4586 goto err_peer_delete;
4590 spin_lock_bh(&ar->htt.tx_lock);
4592 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
4593 spin_unlock_bh(&ar->htt.tx_lock);
4595 mutex_unlock(&ar->conf_mutex);
4599 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4600 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
4601 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4604 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4605 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4606 spin_lock_bh(&ar->data_lock);
4607 list_del(&arvif->list);
4608 spin_unlock_bh(&ar->data_lock);
4611 if (arvif->beacon_buf) {
4612 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4613 arvif->beacon_buf, arvif->beacon_paddr);
4614 arvif->beacon_buf = NULL;
4617 mutex_unlock(&ar->conf_mutex);
4622 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4626 for (i = 0; i < BITS_PER_LONG; i++)
4627 ath10k_mac_vif_tx_unlock(arvif, i);
4630 static void ath10k_remove_interface(struct ieee80211_hw *hw,
4631 struct ieee80211_vif *vif)
4633 struct ath10k *ar = hw->priv;
4634 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4637 cancel_work_sync(&arvif->ap_csa_work);
4638 cancel_delayed_work_sync(&arvif->connection_loss_work);
4640 mutex_lock(&ar->conf_mutex);
4642 spin_lock_bh(&ar->data_lock);
4643 ath10k_mac_vif_beacon_cleanup(arvif);
4644 spin_unlock_bh(&ar->data_lock);
4646 ret = ath10k_spectral_vif_stop(arvif);
4648 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
4649 arvif->vdev_id, ret);
4651 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4652 spin_lock_bh(&ar->data_lock);
4653 list_del(&arvif->list);
4654 spin_unlock_bh(&ar->data_lock);
4656 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4657 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4658 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4661 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4662 arvif->vdev_id, ret);
4664 kfree(arvif->u.ap.noa_data);
4667 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
4670 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4672 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
4673 arvif->vdev_id, ret);
4675 /* Some firmware revisions don't notify host about self-peer removal
4676 * until after associated vdev is deleted.
4678 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4679 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4680 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4683 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4684 arvif->vdev_id, ret);
4686 spin_lock_bh(&ar->data_lock);
4688 spin_unlock_bh(&ar->data_lock);
4691 ath10k_peer_cleanup(ar, arvif->vdev_id);
4693 if (vif->type == NL80211_IFTYPE_MONITOR) {
4694 ar->monitor_arvif = NULL;
4695 ret = ath10k_monitor_recalc(ar);
4697 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4700 spin_lock_bh(&ar->htt.tx_lock);
4701 ath10k_mac_vif_tx_unlock_all(arvif);
4702 spin_unlock_bh(&ar->htt.tx_lock);
4704 mutex_unlock(&ar->conf_mutex);
4708 * FIXME: Has to be verified.
4710 #define SUPPORTED_FILTERS \
4715 FIF_BCN_PRBRESP_PROMISC | \
4719 static void ath10k_configure_filter(struct ieee80211_hw *hw,
4720 unsigned int changed_flags,
4721 unsigned int *total_flags,
4724 struct ath10k *ar = hw->priv;
4727 mutex_lock(&ar->conf_mutex);
4729 changed_flags &= SUPPORTED_FILTERS;
4730 *total_flags &= SUPPORTED_FILTERS;
4731 ar->filter_flags = *total_flags;
4733 ret = ath10k_monitor_recalc(ar);
4735 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
4737 mutex_unlock(&ar->conf_mutex);
4740 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4741 struct ieee80211_vif *vif,
4742 struct ieee80211_bss_conf *info,
4745 struct ath10k *ar = hw->priv;
4746 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4748 u32 vdev_param, pdev_param, slottime, preamble;
4750 mutex_lock(&ar->conf_mutex);
4752 if (changed & BSS_CHANGED_IBSS)
4753 ath10k_control_ibss(arvif, info, vif->addr);
4755 if (changed & BSS_CHANGED_BEACON_INT) {
4756 arvif->beacon_interval = info->beacon_int;
4757 vdev_param = ar->wmi.vdev_param->beacon_interval;
4758 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4759 arvif->beacon_interval);
4760 ath10k_dbg(ar, ATH10K_DBG_MAC,
4761 "mac vdev %d beacon_interval %d\n",
4762 arvif->vdev_id, arvif->beacon_interval);
4765 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
4766 arvif->vdev_id, ret);
4769 if (changed & BSS_CHANGED_BEACON) {
4770 ath10k_dbg(ar, ATH10K_DBG_MAC,
4771 "vdev %d set beacon tx mode to staggered\n",
4774 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4775 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
4776 WMI_BEACON_STAGGERED_MODE);
4778 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
4779 arvif->vdev_id, ret);
4781 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4783 ath10k_warn(ar, "failed to update beacon template: %d\n",
4786 if (ieee80211_vif_is_mesh(vif)) {
4787 /* mesh doesn't use SSID but firmware needs it */
4788 strncpy(arvif->u.ap.ssid, "mesh",
4789 sizeof(arvif->u.ap.ssid));
4790 arvif->u.ap.ssid_len = 4;
4794 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4795 ret = ath10k_mac_setup_prb_tmpl(arvif);
4797 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4798 arvif->vdev_id, ret);
4801 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
4802 arvif->dtim_period = info->dtim_period;
4804 ath10k_dbg(ar, ATH10K_DBG_MAC,
4805 "mac vdev %d dtim_period %d\n",
4806 arvif->vdev_id, arvif->dtim_period);
4808 vdev_param = ar->wmi.vdev_param->dtim_period;
4809 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4810 arvif->dtim_period);
4812 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
4813 arvif->vdev_id, ret);
4816 if (changed & BSS_CHANGED_SSID &&
4817 vif->type == NL80211_IFTYPE_AP) {
4818 arvif->u.ap.ssid_len = info->ssid_len;
4820 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4821 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4824 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4825 ether_addr_copy(arvif->bssid, info->bssid);
4827 if (changed & BSS_CHANGED_BEACON_ENABLED)
4828 ath10k_control_beaconing(arvif, info);
4830 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
4831 arvif->use_cts_prot = info->use_cts_prot;
4833 ret = ath10k_recalc_rtscts_prot(arvif);
4835 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4836 arvif->vdev_id, ret);
4838 if (ath10k_mac_can_set_cts_prot(arvif)) {
4839 ret = ath10k_mac_set_cts_prot(arvif);
4841 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
4842 arvif->vdev_id, ret);
4846 if (changed & BSS_CHANGED_ERP_SLOT) {
4847 if (info->use_short_slot)
4848 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4851 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4853 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
4854 arvif->vdev_id, slottime);
4856 vdev_param = ar->wmi.vdev_param->slot_time;
4857 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4860 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
4861 arvif->vdev_id, ret);
4864 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4865 if (info->use_short_preamble)
4866 preamble = WMI_VDEV_PREAMBLE_SHORT;
4868 preamble = WMI_VDEV_PREAMBLE_LONG;
4870 ath10k_dbg(ar, ATH10K_DBG_MAC,
4871 "mac vdev %d preamble %dn",
4872 arvif->vdev_id, preamble);
4874 vdev_param = ar->wmi.vdev_param->preamble;
4875 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4878 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
4879 arvif->vdev_id, ret);
4882 if (changed & BSS_CHANGED_ASSOC) {
4884 /* Workaround: Make sure monitor vdev is not running
4885 * when associating to prevent some firmware revisions
4886 * (e.g. 10.1 and 10.2) from crashing.
4888 if (ar->monitor_started)
4889 ath10k_monitor_stop(ar);
4890 ath10k_bss_assoc(hw, vif, info);
4891 ath10k_monitor_recalc(ar);
4893 ath10k_bss_disassoc(hw, vif);
4897 if (changed & BSS_CHANGED_TXPOWER) {
4898 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4899 arvif->vdev_id, info->txpower);
4901 arvif->txpower = info->txpower;
4902 ret = ath10k_mac_txpower_recalc(ar);
4904 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4907 if (changed & BSS_CHANGED_PS) {
4908 arvif->ps = vif->bss_conf.ps;
4910 ret = ath10k_config_ps(ar);
4912 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4913 arvif->vdev_id, ret);
4916 mutex_unlock(&ar->conf_mutex);
4919 static int ath10k_hw_scan(struct ieee80211_hw *hw,
4920 struct ieee80211_vif *vif,
4921 struct ieee80211_scan_request *hw_req)
4923 struct ath10k *ar = hw->priv;
4924 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4925 struct cfg80211_scan_request *req = &hw_req->req;
4926 struct wmi_start_scan_arg arg;
4930 mutex_lock(&ar->conf_mutex);
4932 spin_lock_bh(&ar->data_lock);
4933 switch (ar->scan.state) {
4934 case ATH10K_SCAN_IDLE:
4935 reinit_completion(&ar->scan.started);
4936 reinit_completion(&ar->scan.completed);
4937 ar->scan.state = ATH10K_SCAN_STARTING;
4938 ar->scan.is_roc = false;
4939 ar->scan.vdev_id = arvif->vdev_id;
4942 case ATH10K_SCAN_STARTING:
4943 case ATH10K_SCAN_RUNNING:
4944 case ATH10K_SCAN_ABORTING:
4948 spin_unlock_bh(&ar->data_lock);
4953 memset(&arg, 0, sizeof(arg));
4954 ath10k_wmi_start_scan_init(ar, &arg);
4955 arg.vdev_id = arvif->vdev_id;
4956 arg.scan_id = ATH10K_SCAN_ID;
4959 arg.ie_len = req->ie_len;
4960 memcpy(arg.ie, req->ie, arg.ie_len);
4964 arg.n_ssids = req->n_ssids;
4965 for (i = 0; i < arg.n_ssids; i++) {
4966 arg.ssids[i].len = req->ssids[i].ssid_len;
4967 arg.ssids[i].ssid = req->ssids[i].ssid;
4970 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4973 if (req->n_channels) {
4974 arg.n_channels = req->n_channels;
4975 for (i = 0; i < arg.n_channels; i++)
4976 arg.channels[i] = req->channels[i]->center_freq;
4979 ret = ath10k_start_scan(ar, &arg);
4981 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
4982 spin_lock_bh(&ar->data_lock);
4983 ar->scan.state = ATH10K_SCAN_IDLE;
4984 spin_unlock_bh(&ar->data_lock);
4987 /* Add a 200ms margin to account for event/command processing */
4988 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
4989 msecs_to_jiffies(arg.max_scan_time +
4993 mutex_unlock(&ar->conf_mutex);
4997 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4998 struct ieee80211_vif *vif)
5000 struct ath10k *ar = hw->priv;
5002 mutex_lock(&ar->conf_mutex);
5003 ath10k_scan_abort(ar);
5004 mutex_unlock(&ar->conf_mutex);
5006 cancel_delayed_work_sync(&ar->scan.timeout);
5009 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5010 struct ath10k_vif *arvif,
5011 enum set_key_cmd cmd,
5012 struct ieee80211_key_conf *key)
5014 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5017 /* 10.1 firmware branch requires default key index to be set to group
5018 * key index after installing it. Otherwise FW/HW Txes corrupted
5019 * frames with multi-vif APs. This is not required for main firmware
5020 * branch (e.g. 636).
5022 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5024 * FIXME: It remains unknown if this is required for multi-vif STA
5025 * interfaces on 10.1.
5028 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5029 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5032 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5035 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5038 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5044 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5047 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5048 arvif->vdev_id, ret);
5051 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5052 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5053 struct ieee80211_key_conf *key)
5055 struct ath10k *ar = hw->priv;
5056 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5057 struct ath10k_peer *peer;
5058 const u8 *peer_addr;
5059 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5060 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5066 /* this one needs to be done in software */
5067 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5070 if (arvif->nohwcrypt)
5073 if (key->keyidx > WMI_MAX_KEY_INDEX)
5076 mutex_lock(&ar->conf_mutex);
5079 peer_addr = sta->addr;
5080 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5081 peer_addr = vif->bss_conf.bssid;
5083 peer_addr = vif->addr;
5085 key->hw_key_idx = key->keyidx;
5089 arvif->wep_keys[key->keyidx] = key;
5091 arvif->wep_keys[key->keyidx] = NULL;
5094 /* the peer should not disappear in mid-way (unless FW goes awry) since
5095 * we already hold conf_mutex. we just make sure its there now. */
5096 spin_lock_bh(&ar->data_lock);
5097 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5098 spin_unlock_bh(&ar->data_lock);
5101 if (cmd == SET_KEY) {
5102 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5107 /* if the peer doesn't exist there is no key to disable
5113 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5114 flags |= WMI_KEY_PAIRWISE;
5116 flags |= WMI_KEY_GROUP;
5119 if (cmd == DISABLE_KEY)
5120 ath10k_clear_vdev_key(arvif, key);
5122 /* When WEP keys are uploaded it's possible that there are
5123 * stations associated already (e.g. when merging) without any
5124 * keys. Static WEP needs an explicit per-peer key upload.
5126 if (vif->type == NL80211_IFTYPE_ADHOC &&
5128 ath10k_mac_vif_update_wep_key(arvif, key);
5130 /* 802.1x never sets the def_wep_key_idx so each set_key()
5131 * call changes default tx key.
5133 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5134 * after first set_key().
5136 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5137 flags |= WMI_KEY_TX_USAGE;
5140 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5143 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5144 arvif->vdev_id, peer_addr, ret);
5148 /* mac80211 sets static WEP keys as groupwise while firmware requires
5149 * them to be installed twice as both pairwise and groupwise.
5151 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5153 flags2 &= ~WMI_KEY_GROUP;
5154 flags2 |= WMI_KEY_PAIRWISE;
5156 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5159 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5160 arvif->vdev_id, peer_addr, ret);
5161 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5165 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5166 arvif->vdev_id, peer_addr, ret2);
5172 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5174 spin_lock_bh(&ar->data_lock);
5175 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5176 if (peer && cmd == SET_KEY)
5177 peer->keys[key->keyidx] = key;
5178 else if (peer && cmd == DISABLE_KEY)
5179 peer->keys[key->keyidx] = NULL;
5180 else if (peer == NULL)
5181 /* impossible unless FW goes crazy */
5182 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5183 spin_unlock_bh(&ar->data_lock);
5186 mutex_unlock(&ar->conf_mutex);
5190 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5191 struct ieee80211_vif *vif,
5194 struct ath10k *ar = hw->priv;
5195 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5198 mutex_lock(&arvif->ar->conf_mutex);
5200 if (arvif->ar->state != ATH10K_STATE_ON)
5203 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5204 arvif->vdev_id, keyidx);
5206 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5208 arvif->ar->wmi.vdev_param->def_keyid,
5212 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5218 arvif->def_wep_key_idx = keyidx;
5221 mutex_unlock(&arvif->ar->conf_mutex);
5224 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5227 struct ath10k_vif *arvif;
5228 struct ath10k_sta *arsta;
5229 struct ieee80211_sta *sta;
5230 struct cfg80211_chan_def def;
5231 enum ieee80211_band band;
5232 const u8 *ht_mcs_mask;
5233 const u16 *vht_mcs_mask;
5234 u32 changed, bw, nss, smps;
5237 arsta = container_of(wk, struct ath10k_sta, update_wk);
5238 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5239 arvif = arsta->arvif;
5242 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5245 band = def.chan->band;
5246 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5247 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5249 spin_lock_bh(&ar->data_lock);
5251 changed = arsta->changed;
5258 spin_unlock_bh(&ar->data_lock);
5260 mutex_lock(&ar->conf_mutex);
5262 nss = max_t(u32, 1, nss);
5263 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5264 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5266 if (changed & IEEE80211_RC_BW_CHANGED) {
5267 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5270 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5271 WMI_PEER_CHAN_WIDTH, bw);
5273 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5274 sta->addr, bw, err);
5277 if (changed & IEEE80211_RC_NSS_CHANGED) {
5278 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5281 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5284 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5285 sta->addr, nss, err);
5288 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5289 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5292 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5293 WMI_PEER_SMPS_STATE, smps);
5295 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5296 sta->addr, smps, err);
5299 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
5300 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
5303 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5305 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5309 mutex_unlock(&ar->conf_mutex);
5312 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5313 struct ieee80211_sta *sta)
5315 struct ath10k *ar = arvif->ar;
5317 lockdep_assert_held(&ar->conf_mutex);
5319 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5322 if (ar->num_stations >= ar->max_num_stations)
5330 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5331 struct ieee80211_sta *sta)
5333 struct ath10k *ar = arvif->ar;
5335 lockdep_assert_held(&ar->conf_mutex);
5337 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5343 struct ath10k_mac_tdls_iter_data {
5344 u32 num_tdls_stations;
5345 struct ieee80211_vif *curr_vif;
5348 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5349 struct ieee80211_sta *sta)
5351 struct ath10k_mac_tdls_iter_data *iter_data = data;
5352 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5353 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5355 if (sta->tdls && sta_vif == iter_data->curr_vif)
5356 iter_data->num_tdls_stations++;
5359 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5360 struct ieee80211_vif *vif)
5362 struct ath10k_mac_tdls_iter_data data = {};
5364 data.curr_vif = vif;
5366 ieee80211_iterate_stations_atomic(hw,
5367 ath10k_mac_tdls_vif_stations_count_iter,
5369 return data.num_tdls_stations;
5372 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5373 struct ieee80211_vif *vif)
5375 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5376 int *num_tdls_vifs = data;
5378 if (vif->type != NL80211_IFTYPE_STATION)
5381 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5385 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5387 int num_tdls_vifs = 0;
5389 ieee80211_iterate_active_interfaces_atomic(hw,
5390 IEEE80211_IFACE_ITER_NORMAL,
5391 ath10k_mac_tdls_vifs_count_iter,
5393 return num_tdls_vifs;
5396 static int ath10k_sta_state(struct ieee80211_hw *hw,
5397 struct ieee80211_vif *vif,
5398 struct ieee80211_sta *sta,
5399 enum ieee80211_sta_state old_state,
5400 enum ieee80211_sta_state new_state)
5402 struct ath10k *ar = hw->priv;
5403 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5404 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5407 if (old_state == IEEE80211_STA_NOTEXIST &&
5408 new_state == IEEE80211_STA_NONE) {
5409 memset(arsta, 0, sizeof(*arsta));
5410 arsta->arvif = arvif;
5411 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5414 /* cancel must be done outside the mutex to avoid deadlock */
5415 if ((old_state == IEEE80211_STA_NONE &&
5416 new_state == IEEE80211_STA_NOTEXIST))
5417 cancel_work_sync(&arsta->update_wk);
5419 mutex_lock(&ar->conf_mutex);
5421 if (old_state == IEEE80211_STA_NOTEXIST &&
5422 new_state == IEEE80211_STA_NONE) {
5424 * New station addition.
5426 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5427 u32 num_tdls_stations;
5430 ath10k_dbg(ar, ATH10K_DBG_MAC,
5431 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5432 arvif->vdev_id, sta->addr,
5433 ar->num_stations + 1, ar->max_num_stations,
5434 ar->num_peers + 1, ar->max_num_peers);
5436 ret = ath10k_mac_inc_num_stations(arvif, sta);
5438 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5439 ar->max_num_stations);
5444 peer_type = WMI_PEER_TYPE_TDLS;
5446 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
5449 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5450 sta->addr, arvif->vdev_id, ret);
5451 ath10k_mac_dec_num_stations(arvif, sta);
5458 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5459 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5461 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5462 num_tdls_stations == 0) {
5463 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5464 arvif->vdev_id, ar->max_num_tdls_vdevs);
5465 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5466 ath10k_mac_dec_num_stations(arvif, sta);
5471 if (num_tdls_stations == 0) {
5472 /* This is the first tdls peer in current vif */
5473 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5475 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5478 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5479 arvif->vdev_id, ret);
5480 ath10k_peer_delete(ar, arvif->vdev_id,
5482 ath10k_mac_dec_num_stations(arvif, sta);
5487 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5488 WMI_TDLS_PEER_STATE_PEERING);
5491 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5492 sta->addr, arvif->vdev_id, ret);
5493 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5494 ath10k_mac_dec_num_stations(arvif, sta);
5496 if (num_tdls_stations != 0)
5498 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5501 } else if ((old_state == IEEE80211_STA_NONE &&
5502 new_state == IEEE80211_STA_NOTEXIST)) {
5504 * Existing station deletion.
5506 ath10k_dbg(ar, ATH10K_DBG_MAC,
5507 "mac vdev %d peer delete %pM (sta gone)\n",
5508 arvif->vdev_id, sta->addr);
5511 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id,
5513 WMI_TDLS_PEER_STATE_TEARDOWN);
5515 ath10k_warn(ar, "failed to update tdls peer state for %pM state %d: %i\n",
5517 WMI_TDLS_PEER_STATE_TEARDOWN, ret);
5520 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5522 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
5523 sta->addr, arvif->vdev_id, ret);
5525 ath10k_mac_dec_num_stations(arvif, sta);
5530 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5533 /* This was the last tdls peer in current vif */
5534 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5537 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5538 arvif->vdev_id, ret);
5540 } else if (old_state == IEEE80211_STA_AUTH &&
5541 new_state == IEEE80211_STA_ASSOC &&
5542 (vif->type == NL80211_IFTYPE_AP ||
5543 vif->type == NL80211_IFTYPE_MESH_POINT ||
5544 vif->type == NL80211_IFTYPE_ADHOC)) {
5548 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
5551 ret = ath10k_station_assoc(ar, vif, sta, false);
5553 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
5554 sta->addr, arvif->vdev_id, ret);
5555 } else if (old_state == IEEE80211_STA_ASSOC &&
5556 new_state == IEEE80211_STA_AUTHORIZED &&
5559 * Tdls station authorized.
5561 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5564 ret = ath10k_station_assoc(ar, vif, sta, false);
5566 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5567 sta->addr, arvif->vdev_id, ret);
5571 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5572 WMI_TDLS_PEER_STATE_CONNECTED);
5574 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5575 sta->addr, arvif->vdev_id, ret);
5576 } else if (old_state == IEEE80211_STA_ASSOC &&
5577 new_state == IEEE80211_STA_AUTH &&
5578 (vif->type == NL80211_IFTYPE_AP ||
5579 vif->type == NL80211_IFTYPE_MESH_POINT ||
5580 vif->type == NL80211_IFTYPE_ADHOC)) {
5584 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
5587 ret = ath10k_station_disassoc(ar, vif, sta);
5589 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
5590 sta->addr, arvif->vdev_id, ret);
5593 mutex_unlock(&ar->conf_mutex);
5597 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
5598 u16 ac, bool enable)
5600 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5601 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5602 u32 prio = 0, acc = 0;
5606 lockdep_assert_held(&ar->conf_mutex);
5608 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5612 case IEEE80211_AC_VO:
5613 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5614 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
5618 case IEEE80211_AC_VI:
5619 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5620 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
5624 case IEEE80211_AC_BE:
5625 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5626 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
5630 case IEEE80211_AC_BK:
5631 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5632 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
5639 arvif->u.sta.uapsd |= value;
5641 arvif->u.sta.uapsd &= ~value;
5643 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5644 WMI_STA_PS_PARAM_UAPSD,
5645 arvif->u.sta.uapsd);
5647 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
5651 if (arvif->u.sta.uapsd)
5652 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5654 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5656 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5657 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5660 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
5662 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5664 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5665 arvif->vdev_id, ret);
5669 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5671 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5672 arvif->vdev_id, ret);
5676 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5677 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5678 /* Only userspace can make an educated decision when to send
5679 * trigger frame. The following effectively disables u-UAPSD
5680 * autotrigger in firmware (which is enabled by default
5681 * provided the autotrigger service is available).
5685 arg.user_priority = prio;
5686 arg.service_interval = 0;
5687 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5688 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5690 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5691 arvif->bssid, &arg, 1);
5693 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5703 static int ath10k_conf_tx(struct ieee80211_hw *hw,
5704 struct ieee80211_vif *vif, u16 ac,
5705 const struct ieee80211_tx_queue_params *params)
5707 struct ath10k *ar = hw->priv;
5708 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5709 struct wmi_wmm_params_arg *p = NULL;
5712 mutex_lock(&ar->conf_mutex);
5715 case IEEE80211_AC_VO:
5716 p = &arvif->wmm_params.ac_vo;
5718 case IEEE80211_AC_VI:
5719 p = &arvif->wmm_params.ac_vi;
5721 case IEEE80211_AC_BE:
5722 p = &arvif->wmm_params.ac_be;
5724 case IEEE80211_AC_BK:
5725 p = &arvif->wmm_params.ac_bk;
5734 p->cwmin = params->cw_min;
5735 p->cwmax = params->cw_max;
5736 p->aifs = params->aifs;
5739 * The channel time duration programmed in the HW is in absolute
5740 * microseconds, while mac80211 gives the txop in units of
5743 p->txop = params->txop * 32;
5745 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5746 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5747 &arvif->wmm_params);
5749 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5750 arvif->vdev_id, ret);
5754 /* This won't work well with multi-interface cases but it's
5755 * better than nothing.
5757 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5759 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5764 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5766 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
5769 mutex_unlock(&ar->conf_mutex);
5773 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5775 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5776 struct ieee80211_vif *vif,
5777 struct ieee80211_channel *chan,
5779 enum ieee80211_roc_type type)
5781 struct ath10k *ar = hw->priv;
5782 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5783 struct wmi_start_scan_arg arg;
5787 mutex_lock(&ar->conf_mutex);
5789 spin_lock_bh(&ar->data_lock);
5790 switch (ar->scan.state) {
5791 case ATH10K_SCAN_IDLE:
5792 reinit_completion(&ar->scan.started);
5793 reinit_completion(&ar->scan.completed);
5794 reinit_completion(&ar->scan.on_channel);
5795 ar->scan.state = ATH10K_SCAN_STARTING;
5796 ar->scan.is_roc = true;
5797 ar->scan.vdev_id = arvif->vdev_id;
5798 ar->scan.roc_freq = chan->center_freq;
5799 ar->scan.roc_notify = true;
5802 case ATH10K_SCAN_STARTING:
5803 case ATH10K_SCAN_RUNNING:
5804 case ATH10K_SCAN_ABORTING:
5808 spin_unlock_bh(&ar->data_lock);
5813 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
5815 memset(&arg, 0, sizeof(arg));
5816 ath10k_wmi_start_scan_init(ar, &arg);
5817 arg.vdev_id = arvif->vdev_id;
5818 arg.scan_id = ATH10K_SCAN_ID;
5820 arg.channels[0] = chan->center_freq;
5821 arg.dwell_time_active = scan_time_msec;
5822 arg.dwell_time_passive = scan_time_msec;
5823 arg.max_scan_time = scan_time_msec;
5824 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5825 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5826 arg.burst_duration_ms = duration;
5828 ret = ath10k_start_scan(ar, &arg);
5830 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
5831 spin_lock_bh(&ar->data_lock);
5832 ar->scan.state = ATH10K_SCAN_IDLE;
5833 spin_unlock_bh(&ar->data_lock);
5837 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5839 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
5841 ret = ath10k_scan_stop(ar);
5843 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
5849 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5850 msecs_to_jiffies(duration));
5854 mutex_unlock(&ar->conf_mutex);
5858 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5860 struct ath10k *ar = hw->priv;
5862 mutex_lock(&ar->conf_mutex);
5864 spin_lock_bh(&ar->data_lock);
5865 ar->scan.roc_notify = false;
5866 spin_unlock_bh(&ar->data_lock);
5868 ath10k_scan_abort(ar);
5870 mutex_unlock(&ar->conf_mutex);
5872 cancel_delayed_work_sync(&ar->scan.timeout);
5878 * Both RTS and Fragmentation threshold are interface-specific
5879 * in ath10k, but device-specific in mac80211.
5882 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5884 struct ath10k *ar = hw->priv;
5885 struct ath10k_vif *arvif;
5888 mutex_lock(&ar->conf_mutex);
5889 list_for_each_entry(arvif, &ar->arvifs, list) {
5890 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
5891 arvif->vdev_id, value);
5893 ret = ath10k_mac_set_rts(arvif, value);
5895 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5896 arvif->vdev_id, ret);
5900 mutex_unlock(&ar->conf_mutex);
5905 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5907 /* Even though there's a WMI enum for fragmentation threshold no known
5908 * firmware actually implements it. Moreover it is not possible to rely
5909 * frame fragmentation to mac80211 because firmware clears the "more
5910 * fragments" bit in frame control making it impossible for remote
5911 * devices to reassemble frames.
5913 * Hence implement a dummy callback just to say fragmentation isn't
5914 * supported. This effectively prevents mac80211 from doing frame
5915 * fragmentation in software.
5920 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5921 u32 queues, bool drop)
5923 struct ath10k *ar = hw->priv;
5927 /* mac80211 doesn't care if we really xmit queued frames or not
5928 * we'll collect those frames either way if we stop/delete vdevs */
5932 mutex_lock(&ar->conf_mutex);
5934 if (ar->state == ATH10K_STATE_WEDGED)
5937 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
5940 spin_lock_bh(&ar->htt.tx_lock);
5941 empty = (ar->htt.num_pending_tx == 0);
5942 spin_unlock_bh(&ar->htt.tx_lock);
5944 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5945 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5949 }), ATH10K_FLUSH_TIMEOUT_HZ);
5951 if (time_left == 0 || skip)
5952 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5953 skip, ar->state, time_left);
5956 mutex_unlock(&ar->conf_mutex);
5959 /* TODO: Implement this function properly
5960 * For now it is needed to reply to Probe Requests in IBSS mode.
5961 * Propably we need this information from FW.
5963 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5968 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5969 enum ieee80211_reconfig_type reconfig_type)
5971 struct ath10k *ar = hw->priv;
5973 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5976 mutex_lock(&ar->conf_mutex);
5978 /* If device failed to restart it will be in a different state, e.g.
5979 * ATH10K_STATE_WEDGED */
5980 if (ar->state == ATH10K_STATE_RESTARTED) {
5981 ath10k_info(ar, "device successfully recovered\n");
5982 ar->state = ATH10K_STATE_ON;
5983 ieee80211_wake_queues(ar->hw);
5986 mutex_unlock(&ar->conf_mutex);
5989 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5990 struct survey_info *survey)
5992 struct ath10k *ar = hw->priv;
5993 struct ieee80211_supported_band *sband;
5994 struct survey_info *ar_survey = &ar->survey[idx];
5997 mutex_lock(&ar->conf_mutex);
5999 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
6000 if (sband && idx >= sband->n_channels) {
6001 idx -= sband->n_channels;
6006 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
6008 if (!sband || idx >= sband->n_channels) {
6013 spin_lock_bh(&ar->data_lock);
6014 memcpy(survey, ar_survey, sizeof(*survey));
6015 spin_unlock_bh(&ar->data_lock);
6017 survey->channel = &sband->channels[idx];
6019 if (ar->rx_channel == survey->channel)
6020 survey->filled |= SURVEY_INFO_IN_USE;
6023 mutex_unlock(&ar->conf_mutex);
6028 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6029 enum ieee80211_band band,
6030 const struct cfg80211_bitrate_mask *mask)
6035 num_rates += hweight32(mask->control[band].legacy);
6037 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6038 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6040 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6041 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6043 return num_rates == 1;
6047 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6048 enum ieee80211_band band,
6049 const struct cfg80211_bitrate_mask *mask,
6052 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6053 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6055 u8 vht_nss_mask = 0;
6058 if (mask->control[band].legacy)
6061 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6062 if (mask->control[band].ht_mcs[i] == 0)
6064 else if (mask->control[band].ht_mcs[i] ==
6065 sband->ht_cap.mcs.rx_mask[i])
6066 ht_nss_mask |= BIT(i);
6071 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6072 if (mask->control[band].vht_mcs[i] == 0)
6074 else if (mask->control[band].vht_mcs[i] ==
6075 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6076 vht_nss_mask |= BIT(i);
6081 if (ht_nss_mask != vht_nss_mask)
6084 if (ht_nss_mask == 0)
6087 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6090 *nss = fls(ht_nss_mask);
6096 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6097 enum ieee80211_band band,
6098 const struct cfg80211_bitrate_mask *mask,
6101 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6108 if (hweight32(mask->control[band].legacy) == 1) {
6109 rate_idx = ffs(mask->control[band].legacy) - 1;
6111 hw_rate = sband->bitrates[rate_idx].hw_value;
6112 bitrate = sband->bitrates[rate_idx].bitrate;
6114 if (ath10k_mac_bitrate_is_cck(bitrate))
6115 preamble = WMI_RATE_PREAMBLE_CCK;
6117 preamble = WMI_RATE_PREAMBLE_OFDM;
6120 *rate = preamble << 6 |
6127 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6128 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6130 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6132 (ffs(mask->control[band].ht_mcs[i]) - 1);
6138 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6139 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6141 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6143 (ffs(mask->control[band].vht_mcs[i]) - 1);
6152 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6153 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6155 struct ath10k *ar = arvif->ar;
6159 lockdep_assert_held(&ar->conf_mutex);
6161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6162 arvif->vdev_id, rate, nss, sgi);
6164 vdev_param = ar->wmi.vdev_param->fixed_rate;
6165 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6167 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6172 vdev_param = ar->wmi.vdev_param->nss;
6173 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6175 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6179 vdev_param = ar->wmi.vdev_param->sgi;
6180 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6182 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6186 vdev_param = ar->wmi.vdev_param->ldpc;
6187 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6189 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6197 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6198 enum ieee80211_band band,
6199 const struct cfg80211_bitrate_mask *mask)
6204 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6205 * to express all VHT MCS rate masks. Effectively only the following
6206 * ranges can be used: none, 0-7, 0-8 and 0-9.
6208 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6209 vht_mcs = mask->control[band].vht_mcs[i];
6218 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6226 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6227 struct ieee80211_sta *sta)
6229 struct ath10k_vif *arvif = data;
6230 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6231 struct ath10k *ar = arvif->ar;
6233 if (arsta->arvif != arvif)
6236 spin_lock_bh(&ar->data_lock);
6237 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6238 spin_unlock_bh(&ar->data_lock);
6240 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6243 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6244 struct ieee80211_vif *vif,
6245 const struct cfg80211_bitrate_mask *mask)
6247 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6248 struct cfg80211_chan_def def;
6249 struct ath10k *ar = arvif->ar;
6250 enum ieee80211_band band;
6251 const u8 *ht_mcs_mask;
6252 const u16 *vht_mcs_mask;
6260 if (ath10k_mac_vif_chan(vif, &def))
6263 band = def.chan->band;
6264 ht_mcs_mask = mask->control[band].ht_mcs;
6265 vht_mcs_mask = mask->control[band].vht_mcs;
6266 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6268 sgi = mask->control[band].gi;
6269 if (sgi == NL80211_TXRATE_FORCE_LGI)
6272 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6273 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6276 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6277 arvif->vdev_id, ret);
6280 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6282 rate = WMI_FIXED_RATE_NONE;
6285 rate = WMI_FIXED_RATE_NONE;
6286 nss = min(ar->num_rf_chains,
6287 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6288 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6290 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6293 mutex_lock(&ar->conf_mutex);
6295 arvif->bitrate_mask = *mask;
6296 ieee80211_iterate_stations_atomic(ar->hw,
6297 ath10k_mac_set_bitrate_mask_iter,
6300 mutex_unlock(&ar->conf_mutex);
6303 mutex_lock(&ar->conf_mutex);
6305 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6307 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6308 arvif->vdev_id, ret);
6313 mutex_unlock(&ar->conf_mutex);
6318 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6319 struct ieee80211_vif *vif,
6320 struct ieee80211_sta *sta,
6323 struct ath10k *ar = hw->priv;
6324 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6325 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6326 struct ath10k_peer *peer;
6329 spin_lock_bh(&ar->data_lock);
6331 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
6333 spin_unlock_bh(&ar->data_lock);
6334 ath10k_warn(ar, "mac sta rc update failed to find peer %pM on vdev %i\n",
6335 sta->addr, arvif->vdev_id);
6339 ath10k_dbg(ar, ATH10K_DBG_MAC,
6340 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6341 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6344 if (changed & IEEE80211_RC_BW_CHANGED) {
6345 bw = WMI_PEER_CHWIDTH_20MHZ;
6347 switch (sta->bandwidth) {
6348 case IEEE80211_STA_RX_BW_20:
6349 bw = WMI_PEER_CHWIDTH_20MHZ;
6351 case IEEE80211_STA_RX_BW_40:
6352 bw = WMI_PEER_CHWIDTH_40MHZ;
6354 case IEEE80211_STA_RX_BW_80:
6355 bw = WMI_PEER_CHWIDTH_80MHZ;
6357 case IEEE80211_STA_RX_BW_160:
6358 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6359 sta->bandwidth, sta->addr);
6360 bw = WMI_PEER_CHWIDTH_20MHZ;
6367 if (changed & IEEE80211_RC_NSS_CHANGED)
6368 arsta->nss = sta->rx_nss;
6370 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6371 smps = WMI_PEER_SMPS_PS_NONE;
6373 switch (sta->smps_mode) {
6374 case IEEE80211_SMPS_AUTOMATIC:
6375 case IEEE80211_SMPS_OFF:
6376 smps = WMI_PEER_SMPS_PS_NONE;
6378 case IEEE80211_SMPS_STATIC:
6379 smps = WMI_PEER_SMPS_STATIC;
6381 case IEEE80211_SMPS_DYNAMIC:
6382 smps = WMI_PEER_SMPS_DYNAMIC;
6384 case IEEE80211_SMPS_NUM_MODES:
6385 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6386 sta->smps_mode, sta->addr);
6387 smps = WMI_PEER_SMPS_PS_NONE;
6394 arsta->changed |= changed;
6396 spin_unlock_bh(&ar->data_lock);
6398 ieee80211_queue_work(hw, &arsta->update_wk);
6401 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6404 * FIXME: Return 0 for time being. Need to figure out whether FW
6405 * has the API to fetch 64-bit local TSF
6411 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6412 struct ieee80211_vif *vif,
6413 struct ieee80211_ampdu_params *params)
6415 struct ath10k *ar = hw->priv;
6416 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6417 struct ieee80211_sta *sta = params->sta;
6418 enum ieee80211_ampdu_mlme_action action = params->action;
6419 u16 tid = params->tid;
6421 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6422 arvif->vdev_id, sta->addr, tid, action);
6425 case IEEE80211_AMPDU_RX_START:
6426 case IEEE80211_AMPDU_RX_STOP:
6427 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6428 * creation/removal. Do we need to verify this?
6431 case IEEE80211_AMPDU_TX_START:
6432 case IEEE80211_AMPDU_TX_STOP_CONT:
6433 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6434 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6435 case IEEE80211_AMPDU_TX_OPERATIONAL:
6436 /* Firmware offloads Tx aggregation entirely so deny mac80211
6437 * Tx aggregation requests.
6446 ath10k_mac_update_rx_channel(struct ath10k *ar,
6447 struct ieee80211_chanctx_conf *ctx,
6448 struct ieee80211_vif_chanctx_switch *vifs,
6451 struct cfg80211_chan_def *def = NULL;
6453 /* Both locks are required because ar->rx_channel is modified. This
6454 * allows readers to hold either lock.
6456 lockdep_assert_held(&ar->conf_mutex);
6457 lockdep_assert_held(&ar->data_lock);
6459 WARN_ON(ctx && vifs);
6460 WARN_ON(vifs && !n_vifs);
6462 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6463 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6464 * ppdu on Rx may reduce performance on low-end systems. It should be
6465 * possible to make tables/hashmaps to speed the lookup up (be vary of
6466 * cpu data cache lines though regarding sizes) but to keep the initial
6467 * implementation simple and less intrusive fallback to the slow lookup
6468 * only for multi-channel cases. Single-channel cases will remain to
6469 * use the old channel derival and thus performance should not be
6473 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
6474 ieee80211_iter_chan_contexts_atomic(ar->hw,
6475 ath10k_mac_get_any_chandef_iter,
6479 def = &vifs[0].new_ctx->def;
6481 ar->rx_channel = def->chan;
6482 } else if ((ctx && ath10k_mac_num_chanctxs(ar) == 0) ||
6483 (ctx && (ar->state == ATH10K_STATE_RESTARTED))) {
6484 /* During driver restart due to firmware assert, since mac80211
6485 * already has valid channel context for given radio, channel
6486 * context iteration return num_chanctx > 0. So fix rx_channel
6487 * when restart is in progress.
6489 ar->rx_channel = ctx->def.chan;
6491 ar->rx_channel = NULL;
6497 ath10k_mac_update_vif_chan(struct ath10k *ar,
6498 struct ieee80211_vif_chanctx_switch *vifs,
6501 struct ath10k_vif *arvif;
6505 lockdep_assert_held(&ar->conf_mutex);
6507 /* First stop monitor interface. Some FW versions crash if there's a
6508 * lone monitor interface.
6510 if (ar->monitor_started)
6511 ath10k_monitor_stop(ar);
6513 for (i = 0; i < n_vifs; i++) {
6514 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6516 ath10k_dbg(ar, ATH10K_DBG_MAC,
6517 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6519 vifs[i].old_ctx->def.chan->center_freq,
6520 vifs[i].new_ctx->def.chan->center_freq,
6521 vifs[i].old_ctx->def.width,
6522 vifs[i].new_ctx->def.width);
6524 if (WARN_ON(!arvif->is_started))
6527 if (WARN_ON(!arvif->is_up))
6530 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6532 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6533 arvif->vdev_id, ret);
6538 /* All relevant vdevs are downed and associated channel resources
6539 * should be available for the channel switch now.
6542 spin_lock_bh(&ar->data_lock);
6543 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
6544 spin_unlock_bh(&ar->data_lock);
6546 for (i = 0; i < n_vifs; i++) {
6547 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6549 if (WARN_ON(!arvif->is_started))
6552 if (WARN_ON(!arvif->is_up))
6555 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6557 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6560 ret = ath10k_mac_setup_prb_tmpl(arvif);
6562 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6565 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6567 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6568 arvif->vdev_id, ret);
6572 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6575 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6576 arvif->vdev_id, ret);
6581 ath10k_monitor_recalc(ar);
6585 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6586 struct ieee80211_chanctx_conf *ctx)
6588 struct ath10k *ar = hw->priv;
6590 ath10k_dbg(ar, ATH10K_DBG_MAC,
6591 "mac chanctx add freq %hu width %d ptr %p\n",
6592 ctx->def.chan->center_freq, ctx->def.width, ctx);
6594 mutex_lock(&ar->conf_mutex);
6596 spin_lock_bh(&ar->data_lock);
6597 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
6598 spin_unlock_bh(&ar->data_lock);
6600 ath10k_recalc_radar_detection(ar);
6601 ath10k_monitor_recalc(ar);
6603 mutex_unlock(&ar->conf_mutex);
6609 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6610 struct ieee80211_chanctx_conf *ctx)
6612 struct ath10k *ar = hw->priv;
6614 ath10k_dbg(ar, ATH10K_DBG_MAC,
6615 "mac chanctx remove freq %hu width %d ptr %p\n",
6616 ctx->def.chan->center_freq, ctx->def.width, ctx);
6618 mutex_lock(&ar->conf_mutex);
6620 spin_lock_bh(&ar->data_lock);
6621 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
6622 spin_unlock_bh(&ar->data_lock);
6624 ath10k_recalc_radar_detection(ar);
6625 ath10k_monitor_recalc(ar);
6627 mutex_unlock(&ar->conf_mutex);
6630 struct ath10k_mac_change_chanctx_arg {
6631 struct ieee80211_chanctx_conf *ctx;
6632 struct ieee80211_vif_chanctx_switch *vifs;
6638 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
6639 struct ieee80211_vif *vif)
6641 struct ath10k_mac_change_chanctx_arg *arg = data;
6643 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
6650 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
6651 struct ieee80211_vif *vif)
6653 struct ath10k_mac_change_chanctx_arg *arg = data;
6654 struct ieee80211_chanctx_conf *ctx;
6656 ctx = rcu_access_pointer(vif->chanctx_conf);
6657 if (ctx != arg->ctx)
6660 if (WARN_ON(arg->next_vif == arg->n_vifs))
6663 arg->vifs[arg->next_vif].vif = vif;
6664 arg->vifs[arg->next_vif].old_ctx = ctx;
6665 arg->vifs[arg->next_vif].new_ctx = ctx;
6670 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6671 struct ieee80211_chanctx_conf *ctx,
6674 struct ath10k *ar = hw->priv;
6675 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
6677 mutex_lock(&ar->conf_mutex);
6679 ath10k_dbg(ar, ATH10K_DBG_MAC,
6680 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6681 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
6683 /* This shouldn't really happen because channel switching should use
6684 * switch_vif_chanctx().
6686 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6689 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
6690 ieee80211_iterate_active_interfaces_atomic(
6692 IEEE80211_IFACE_ITER_NORMAL,
6693 ath10k_mac_change_chanctx_cnt_iter,
6695 if (arg.n_vifs == 0)
6698 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
6703 ieee80211_iterate_active_interfaces_atomic(
6705 IEEE80211_IFACE_ITER_NORMAL,
6706 ath10k_mac_change_chanctx_fill_iter,
6708 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
6713 ath10k_recalc_radar_detection(ar);
6715 /* FIXME: How to configure Rx chains properly? */
6717 /* No other actions are actually necessary. Firmware maintains channel
6718 * definitions per vdev internally and there's no host-side channel
6719 * context abstraction to configure, e.g. channel width.
6723 mutex_unlock(&ar->conf_mutex);
6727 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6728 struct ieee80211_vif *vif,
6729 struct ieee80211_chanctx_conf *ctx)
6731 struct ath10k *ar = hw->priv;
6732 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6735 mutex_lock(&ar->conf_mutex);
6737 ath10k_dbg(ar, ATH10K_DBG_MAC,
6738 "mac chanctx assign ptr %p vdev_id %i\n",
6739 ctx, arvif->vdev_id);
6741 if (WARN_ON(arvif->is_started)) {
6742 mutex_unlock(&ar->conf_mutex);
6746 ret = ath10k_vdev_start(arvif, &ctx->def);
6748 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6749 arvif->vdev_id, vif->addr,
6750 ctx->def.chan->center_freq, ret);
6754 arvif->is_started = true;
6756 ret = ath10k_mac_vif_setup_ps(arvif);
6758 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6759 arvif->vdev_id, ret);
6763 if (vif->type == NL80211_IFTYPE_MONITOR) {
6764 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6766 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6767 arvif->vdev_id, ret);
6771 arvif->is_up = true;
6774 if (ath10k_mac_can_set_cts_prot(arvif)) {
6775 ret = ath10k_mac_set_cts_prot(arvif);
6777 ath10k_warn(ar, "failed to set cts protection for vdev %d: %d\n",
6778 arvif->vdev_id, ret);
6781 mutex_unlock(&ar->conf_mutex);
6785 ath10k_vdev_stop(arvif);
6786 arvif->is_started = false;
6787 ath10k_mac_vif_setup_ps(arvif);
6790 mutex_unlock(&ar->conf_mutex);
6795 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6796 struct ieee80211_vif *vif,
6797 struct ieee80211_chanctx_conf *ctx)
6799 struct ath10k *ar = hw->priv;
6800 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6803 mutex_lock(&ar->conf_mutex);
6805 ath10k_dbg(ar, ATH10K_DBG_MAC,
6806 "mac chanctx unassign ptr %p vdev_id %i\n",
6807 ctx, arvif->vdev_id);
6809 WARN_ON(!arvif->is_started);
6811 if (vif->type == NL80211_IFTYPE_MONITOR) {
6812 WARN_ON(!arvif->is_up);
6814 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6816 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6817 arvif->vdev_id, ret);
6819 arvif->is_up = false;
6822 ret = ath10k_vdev_stop(arvif);
6824 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6825 arvif->vdev_id, ret);
6827 arvif->is_started = false;
6829 mutex_unlock(&ar->conf_mutex);
6833 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6834 struct ieee80211_vif_chanctx_switch *vifs,
6836 enum ieee80211_chanctx_switch_mode mode)
6838 struct ath10k *ar = hw->priv;
6840 mutex_lock(&ar->conf_mutex);
6842 ath10k_dbg(ar, ATH10K_DBG_MAC,
6843 "mac chanctx switch n_vifs %d mode %d\n",
6845 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
6847 mutex_unlock(&ar->conf_mutex);
6851 static const struct ieee80211_ops ath10k_ops = {
6853 .start = ath10k_start,
6854 .stop = ath10k_stop,
6855 .config = ath10k_config,
6856 .add_interface = ath10k_add_interface,
6857 .remove_interface = ath10k_remove_interface,
6858 .configure_filter = ath10k_configure_filter,
6859 .bss_info_changed = ath10k_bss_info_changed,
6860 .hw_scan = ath10k_hw_scan,
6861 .cancel_hw_scan = ath10k_cancel_hw_scan,
6862 .set_key = ath10k_set_key,
6863 .set_default_unicast_key = ath10k_set_default_unicast_key,
6864 .sta_state = ath10k_sta_state,
6865 .conf_tx = ath10k_conf_tx,
6866 .remain_on_channel = ath10k_remain_on_channel,
6867 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6868 .set_rts_threshold = ath10k_set_rts_threshold,
6869 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
6870 .flush = ath10k_flush,
6871 .tx_last_beacon = ath10k_tx_last_beacon,
6872 .set_antenna = ath10k_set_antenna,
6873 .get_antenna = ath10k_get_antenna,
6874 .reconfig_complete = ath10k_reconfig_complete,
6875 .get_survey = ath10k_get_survey,
6876 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
6877 .sta_rc_update = ath10k_sta_rc_update,
6878 .get_tsf = ath10k_get_tsf,
6879 .ampdu_action = ath10k_ampdu_action,
6880 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6881 .get_et_stats = ath10k_debug_get_et_stats,
6882 .get_et_strings = ath10k_debug_get_et_strings,
6883 .add_chanctx = ath10k_mac_op_add_chanctx,
6884 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6885 .change_chanctx = ath10k_mac_op_change_chanctx,
6886 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6887 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6888 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
6890 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6893 .suspend = ath10k_wow_op_suspend,
6894 .resume = ath10k_wow_op_resume,
6896 #ifdef CONFIG_MAC80211_DEBUGFS
6897 .sta_add_debugfs = ath10k_sta_add_debugfs,
6901 #define CHAN2G(_channel, _freq, _flags) { \
6902 .band = IEEE80211_BAND_2GHZ, \
6903 .hw_value = (_channel), \
6904 .center_freq = (_freq), \
6905 .flags = (_flags), \
6906 .max_antenna_gain = 0, \
6910 #define CHAN5G(_channel, _freq, _flags) { \
6911 .band = IEEE80211_BAND_5GHZ, \
6912 .hw_value = (_channel), \
6913 .center_freq = (_freq), \
6914 .flags = (_flags), \
6915 .max_antenna_gain = 0, \
6919 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6929 CHAN2G(10, 2457, 0),
6930 CHAN2G(11, 2462, 0),
6931 CHAN2G(12, 2467, 0),
6932 CHAN2G(13, 2472, 0),
6933 CHAN2G(14, 2484, 0),
6936 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
6937 CHAN5G(36, 5180, 0),
6938 CHAN5G(40, 5200, 0),
6939 CHAN5G(44, 5220, 0),
6940 CHAN5G(48, 5240, 0),
6941 CHAN5G(52, 5260, 0),
6942 CHAN5G(56, 5280, 0),
6943 CHAN5G(60, 5300, 0),
6944 CHAN5G(64, 5320, 0),
6945 CHAN5G(100, 5500, 0),
6946 CHAN5G(104, 5520, 0),
6947 CHAN5G(108, 5540, 0),
6948 CHAN5G(112, 5560, 0),
6949 CHAN5G(116, 5580, 0),
6950 CHAN5G(120, 5600, 0),
6951 CHAN5G(124, 5620, 0),
6952 CHAN5G(128, 5640, 0),
6953 CHAN5G(132, 5660, 0),
6954 CHAN5G(136, 5680, 0),
6955 CHAN5G(140, 5700, 0),
6956 CHAN5G(144, 5720, 0),
6957 CHAN5G(149, 5745, 0),
6958 CHAN5G(153, 5765, 0),
6959 CHAN5G(157, 5785, 0),
6960 CHAN5G(161, 5805, 0),
6961 CHAN5G(165, 5825, 0),
6964 struct ath10k *ath10k_mac_create(size_t priv_size)
6966 struct ieee80211_hw *hw;
6969 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
6979 void ath10k_mac_destroy(struct ath10k *ar)
6981 ieee80211_free_hw(ar->hw);
6984 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6987 .types = BIT(NL80211_IFTYPE_STATION)
6988 | BIT(NL80211_IFTYPE_P2P_CLIENT)
6992 .types = BIT(NL80211_IFTYPE_P2P_GO)
6996 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7000 .types = BIT(NL80211_IFTYPE_AP)
7001 #ifdef CONFIG_MAC80211_MESH
7002 | BIT(NL80211_IFTYPE_MESH_POINT)
7007 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7010 .types = BIT(NL80211_IFTYPE_AP)
7011 #ifdef CONFIG_MAC80211_MESH
7012 | BIT(NL80211_IFTYPE_MESH_POINT)
7017 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7019 .limits = ath10k_if_limits,
7020 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7021 .max_interfaces = 8,
7022 .num_different_channels = 1,
7023 .beacon_int_infra_match = true,
7027 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7029 .limits = ath10k_10x_if_limits,
7030 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7031 .max_interfaces = 8,
7032 .num_different_channels = 1,
7033 .beacon_int_infra_match = true,
7034 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7035 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7036 BIT(NL80211_CHAN_WIDTH_20) |
7037 BIT(NL80211_CHAN_WIDTH_40) |
7038 BIT(NL80211_CHAN_WIDTH_80),
7043 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7046 .types = BIT(NL80211_IFTYPE_STATION),
7050 .types = BIT(NL80211_IFTYPE_AP) |
7051 #ifdef CONFIG_MAC80211_MESH
7052 BIT(NL80211_IFTYPE_MESH_POINT) |
7054 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7055 BIT(NL80211_IFTYPE_P2P_GO),
7059 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7063 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7066 .types = BIT(NL80211_IFTYPE_STATION),
7070 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7074 .types = BIT(NL80211_IFTYPE_AP) |
7075 #ifdef CONFIG_MAC80211_MESH
7076 BIT(NL80211_IFTYPE_MESH_POINT) |
7078 BIT(NL80211_IFTYPE_P2P_GO),
7082 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7086 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7089 .types = BIT(NL80211_IFTYPE_STATION),
7093 .types = BIT(NL80211_IFTYPE_ADHOC),
7097 /* FIXME: This is not thouroughly tested. These combinations may over- or
7098 * underestimate hw/fw capabilities.
7100 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7102 .limits = ath10k_tlv_if_limit,
7103 .num_different_channels = 1,
7104 .max_interfaces = 4,
7105 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7108 .limits = ath10k_tlv_if_limit_ibss,
7109 .num_different_channels = 1,
7110 .max_interfaces = 2,
7111 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7115 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7117 .limits = ath10k_tlv_if_limit,
7118 .num_different_channels = 1,
7119 .max_interfaces = 4,
7120 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7123 .limits = ath10k_tlv_qcs_if_limit,
7124 .num_different_channels = 2,
7125 .max_interfaces = 4,
7126 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7129 .limits = ath10k_tlv_if_limit_ibss,
7130 .num_different_channels = 1,
7131 .max_interfaces = 2,
7132 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7136 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7139 .types = BIT(NL80211_IFTYPE_STATION),
7143 .types = BIT(NL80211_IFTYPE_AP)
7144 #ifdef CONFIG_MAC80211_MESH
7145 | BIT(NL80211_IFTYPE_MESH_POINT)
7150 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7152 .limits = ath10k_10_4_if_limits,
7153 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7154 .max_interfaces = 16,
7155 .num_different_channels = 1,
7156 .beacon_int_infra_match = true,
7157 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7158 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7159 BIT(NL80211_CHAN_WIDTH_20) |
7160 BIT(NL80211_CHAN_WIDTH_40) |
7161 BIT(NL80211_CHAN_WIDTH_80),
7166 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7167 struct ieee80211_vif *vif)
7169 struct ath10k_vif_iter *arvif_iter = data;
7170 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7172 if (arvif->vdev_id == arvif_iter->vdev_id)
7173 arvif_iter->arvif = arvif;
7176 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7178 struct ath10k_vif_iter arvif_iter;
7181 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7182 arvif_iter.vdev_id = vdev_id;
7184 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7185 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7187 ath10k_get_arvif_iter,
7189 if (!arvif_iter.arvif) {
7190 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7194 return arvif_iter.arvif;
7197 int ath10k_mac_register(struct ath10k *ar)
7199 static const u32 cipher_suites[] = {
7200 WLAN_CIPHER_SUITE_WEP40,
7201 WLAN_CIPHER_SUITE_WEP104,
7202 WLAN_CIPHER_SUITE_TKIP,
7203 WLAN_CIPHER_SUITE_CCMP,
7204 WLAN_CIPHER_SUITE_AES_CMAC,
7206 struct ieee80211_supported_band *band;
7210 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
7212 SET_IEEE80211_DEV(ar->hw, ar->dev);
7214 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
7215 ARRAY_SIZE(ath10k_5ghz_channels)) !=
7218 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
7219 channels = kmemdup(ath10k_2ghz_channels,
7220 sizeof(ath10k_2ghz_channels),
7227 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
7228 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
7229 band->channels = channels;
7230 band->n_bitrates = ath10k_g_rates_size;
7231 band->bitrates = ath10k_g_rates;
7233 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
7236 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
7237 channels = kmemdup(ath10k_5ghz_channels,
7238 sizeof(ath10k_5ghz_channels),
7245 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
7246 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
7247 band->channels = channels;
7248 band->n_bitrates = ath10k_a_rates_size;
7249 band->bitrates = ath10k_a_rates;
7250 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
7253 ath10k_mac_setup_ht_vht_cap(ar);
7255 ar->hw->wiphy->interface_modes =
7256 BIT(NL80211_IFTYPE_STATION) |
7257 BIT(NL80211_IFTYPE_AP) |
7258 BIT(NL80211_IFTYPE_MESH_POINT);
7260 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
7261 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
7263 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
7264 ar->hw->wiphy->interface_modes |=
7265 BIT(NL80211_IFTYPE_P2P_DEVICE) |
7266 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7267 BIT(NL80211_IFTYPE_P2P_GO);
7269 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
7270 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
7271 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
7272 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
7273 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
7274 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
7275 ieee80211_hw_set(ar->hw, AP_LINK_PS);
7276 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
7277 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
7278 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7279 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7280 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7281 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7282 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
7284 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7285 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7287 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
7288 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
7290 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
7291 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
7293 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
7294 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7295 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
7298 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7299 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7301 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
7302 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
7304 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7306 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7307 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7309 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7310 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7311 * correct Probe Responses. This is more of a hack advert..
7313 ar->hw->wiphy->probe_resp_offload |=
7314 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7315 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7316 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
7319 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
7320 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7322 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
7323 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
7324 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
7326 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
7327 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
7329 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
7331 ret = ath10k_wow_init(ar);
7333 ath10k_warn(ar, "failed to init wow: %d\n", ret);
7337 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
7340 * on LL hardware queues are managed entirely by the FW
7341 * so we only advertise to mac we can do the queues thing
7343 ar->hw->queues = IEEE80211_MAX_QUEUES;
7345 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7346 * something that vdev_ids can't reach so that we don't stop the queue
7349 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
7351 switch (ar->wmi.op_version) {
7352 case ATH10K_FW_WMI_OP_VERSION_MAIN:
7353 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7354 ar->hw->wiphy->n_iface_combinations =
7355 ARRAY_SIZE(ath10k_if_comb);
7356 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7358 case ATH10K_FW_WMI_OP_VERSION_TLV:
7359 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7360 ar->hw->wiphy->iface_combinations =
7361 ath10k_tlv_qcs_if_comb;
7362 ar->hw->wiphy->n_iface_combinations =
7363 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7365 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7366 ar->hw->wiphy->n_iface_combinations =
7367 ARRAY_SIZE(ath10k_tlv_if_comb);
7369 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7371 case ATH10K_FW_WMI_OP_VERSION_10_1:
7372 case ATH10K_FW_WMI_OP_VERSION_10_2:
7373 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7374 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7375 ar->hw->wiphy->n_iface_combinations =
7376 ARRAY_SIZE(ath10k_10x_if_comb);
7378 case ATH10K_FW_WMI_OP_VERSION_10_4:
7379 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7380 ar->hw->wiphy->n_iface_combinations =
7381 ARRAY_SIZE(ath10k_10_4_if_comb);
7383 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7384 case ATH10K_FW_WMI_OP_VERSION_MAX:
7390 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7391 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7393 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7394 /* Init ath dfs pattern detector */
7395 ar->ath_common.debug_mask = ATH_DBG_DFS;
7396 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7399 if (!ar->dfs_detector)
7400 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
7403 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7404 ath10k_reg_notifier);
7406 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
7407 goto err_dfs_detector_exit;
7410 ar->hw->wiphy->cipher_suites = cipher_suites;
7411 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7413 ret = ieee80211_register_hw(ar->hw);
7415 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
7416 goto err_dfs_detector_exit;
7419 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7420 ret = regulatory_hint(ar->hw->wiphy,
7421 ar->ath_common.regulatory.alpha2);
7423 goto err_unregister;
7429 ieee80211_unregister_hw(ar->hw);
7431 err_dfs_detector_exit:
7432 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7433 ar->dfs_detector->exit(ar->dfs_detector);
7436 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7437 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7439 SET_IEEE80211_DEV(ar->hw, NULL);
7443 void ath10k_mac_unregister(struct ath10k *ar)
7445 ieee80211_unregister_hw(ar->hw);
7447 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7448 ar->dfs_detector->exit(ar->dfs_detector);
7450 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7451 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7453 SET_IEEE80211_DEV(ar->hw, NULL);