2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
39 static struct ieee80211_rate ath10k_rates[] = {
41 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
43 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
47 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
48 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
49 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
51 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
52 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
53 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
55 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
56 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
57 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
58 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
59 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
60 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
61 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
62 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
65 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
67 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
70 #define ath10k_g_rates (ath10k_rates + 0)
71 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
73 static bool ath10k_mac_bitrate_is_cck(int bitrate)
86 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
88 return DIV_ROUND_UP(bitrate, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
92 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
95 const struct ieee80211_rate *rate;
98 for (i = 0; i < sband->n_bitrates; i++) {
99 rate = &sband->bitrates[i];
101 if (rate->hw_value == hw_rate)
103 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
104 rate->hw_value_short == hw_rate)
111 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
116 for (i = 0; i < sband->n_bitrates; i++)
117 if (sband->bitrates[i].bitrate == bitrate)
123 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
125 switch ((mcs_map >> (2 * nss)) & 0x3) {
126 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
127 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
128 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
134 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
138 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
139 if (ht_mcs_mask[nss])
146 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
150 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
151 if (vht_mcs_mask[nss])
161 static int ath10k_send_key(struct ath10k_vif *arvif,
162 struct ieee80211_key_conf *key,
163 enum set_key_cmd cmd,
164 const u8 *macaddr, u32 flags)
166 struct ath10k *ar = arvif->ar;
167 struct wmi_vdev_install_key_arg arg = {
168 .vdev_id = arvif->vdev_id,
169 .key_idx = key->keyidx,
170 .key_len = key->keylen,
171 .key_data = key->key,
176 lockdep_assert_held(&arvif->ar->conf_mutex);
178 switch (key->cipher) {
179 case WLAN_CIPHER_SUITE_CCMP:
180 arg.key_cipher = WMI_CIPHER_AES_CCM;
181 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
183 case WLAN_CIPHER_SUITE_TKIP:
184 arg.key_cipher = WMI_CIPHER_TKIP;
185 arg.key_txmic_len = 8;
186 arg.key_rxmic_len = 8;
188 case WLAN_CIPHER_SUITE_WEP40:
189 case WLAN_CIPHER_SUITE_WEP104:
190 arg.key_cipher = WMI_CIPHER_WEP;
192 case WLAN_CIPHER_SUITE_AES_CMAC:
196 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
200 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
201 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
204 if (cmd == DISABLE_KEY) {
205 arg.key_cipher = WMI_CIPHER_NONE;
209 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
212 static int ath10k_install_key(struct ath10k_vif *arvif,
213 struct ieee80211_key_conf *key,
214 enum set_key_cmd cmd,
215 const u8 *macaddr, u32 flags)
217 struct ath10k *ar = arvif->ar;
219 unsigned long time_left;
221 lockdep_assert_held(&ar->conf_mutex);
223 reinit_completion(&ar->install_key_done);
225 if (arvif->nohwcrypt)
228 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
232 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
239 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
242 struct ath10k *ar = arvif->ar;
243 struct ath10k_peer *peer;
248 lockdep_assert_held(&ar->conf_mutex);
250 spin_lock_bh(&ar->data_lock);
251 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
252 spin_unlock_bh(&ar->data_lock);
257 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
258 if (arvif->wep_keys[i] == NULL)
262 flags |= WMI_KEY_PAIRWISE;
264 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
270 flags |= WMI_KEY_GROUP;
272 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
277 spin_lock_bh(&ar->data_lock);
278 peer->keys[i] = arvif->wep_keys[i];
279 spin_unlock_bh(&ar->data_lock);
282 /* In some cases (notably with static WEP IBSS with multiple keys)
283 * multicast Tx becomes broken. Both pairwise and groupwise keys are
284 * installed already. Using WMI_KEY_TX_USAGE in different combinations
285 * didn't seem help. Using def_keyid vdev parameter seems to be
286 * effective so use that.
288 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
290 if (arvif->def_wep_key_idx == -1)
293 ret = ath10k_wmi_vdev_set_param(arvif->ar,
295 arvif->ar->wmi.vdev_param->def_keyid,
296 arvif->def_wep_key_idx);
298 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
299 arvif->vdev_id, ret);
306 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
309 struct ath10k *ar = arvif->ar;
310 struct ath10k_peer *peer;
316 lockdep_assert_held(&ar->conf_mutex);
318 spin_lock_bh(&ar->data_lock);
319 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
320 spin_unlock_bh(&ar->data_lock);
325 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
326 if (peer->keys[i] == NULL)
329 /* key flags are not required to delete the key */
330 ret = ath10k_install_key(arvif, peer->keys[i],
331 DISABLE_KEY, addr, flags);
332 if (ret < 0 && first_errno == 0)
336 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
339 spin_lock_bh(&ar->data_lock);
340 peer->keys[i] = NULL;
341 spin_unlock_bh(&ar->data_lock);
347 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
350 struct ath10k_peer *peer;
353 lockdep_assert_held(&ar->data_lock);
355 /* We don't know which vdev this peer belongs to,
356 * since WMI doesn't give us that information.
358 * FIXME: multi-bss needs to be handled.
360 peer = ath10k_peer_find(ar, 0, addr);
364 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
365 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
372 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
373 struct ieee80211_key_conf *key)
375 struct ath10k *ar = arvif->ar;
376 struct ath10k_peer *peer;
383 lockdep_assert_held(&ar->conf_mutex);
386 /* since ath10k_install_key we can't hold data_lock all the
387 * time, so we try to remove the keys incrementally */
388 spin_lock_bh(&ar->data_lock);
390 list_for_each_entry(peer, &ar->peers, list) {
391 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
392 if (peer->keys[i] == key) {
393 ether_addr_copy(addr, peer->addr);
394 peer->keys[i] = NULL;
399 if (i < ARRAY_SIZE(peer->keys))
402 spin_unlock_bh(&ar->data_lock);
404 if (i == ARRAY_SIZE(peer->keys))
406 /* key flags are not required to delete the key */
407 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
408 if (ret < 0 && first_errno == 0)
412 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
419 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
420 struct ieee80211_key_conf *key)
422 struct ath10k *ar = arvif->ar;
423 struct ath10k_peer *peer;
426 lockdep_assert_held(&ar->conf_mutex);
428 list_for_each_entry(peer, &ar->peers, list) {
429 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
432 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
435 if (peer->keys[key->keyidx] == key)
438 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
439 arvif->vdev_id, key->keyidx);
441 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
443 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
444 arvif->vdev_id, peer->addr, ret);
452 /*********************/
453 /* General utilities */
454 /*********************/
456 static inline enum wmi_phy_mode
457 chan_to_phymode(const struct cfg80211_chan_def *chandef)
459 enum wmi_phy_mode phymode = MODE_UNKNOWN;
461 switch (chandef->chan->band) {
462 case IEEE80211_BAND_2GHZ:
463 switch (chandef->width) {
464 case NL80211_CHAN_WIDTH_20_NOHT:
465 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
470 case NL80211_CHAN_WIDTH_20:
471 phymode = MODE_11NG_HT20;
473 case NL80211_CHAN_WIDTH_40:
474 phymode = MODE_11NG_HT40;
476 case NL80211_CHAN_WIDTH_5:
477 case NL80211_CHAN_WIDTH_10:
478 case NL80211_CHAN_WIDTH_80:
479 case NL80211_CHAN_WIDTH_80P80:
480 case NL80211_CHAN_WIDTH_160:
481 phymode = MODE_UNKNOWN;
485 case IEEE80211_BAND_5GHZ:
486 switch (chandef->width) {
487 case NL80211_CHAN_WIDTH_20_NOHT:
490 case NL80211_CHAN_WIDTH_20:
491 phymode = MODE_11NA_HT20;
493 case NL80211_CHAN_WIDTH_40:
494 phymode = MODE_11NA_HT40;
496 case NL80211_CHAN_WIDTH_80:
497 phymode = MODE_11AC_VHT80;
499 case NL80211_CHAN_WIDTH_5:
500 case NL80211_CHAN_WIDTH_10:
501 case NL80211_CHAN_WIDTH_80P80:
502 case NL80211_CHAN_WIDTH_160:
503 phymode = MODE_UNKNOWN;
511 WARN_ON(phymode == MODE_UNKNOWN);
515 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
518 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
519 * 0 for no restriction
528 switch (mpdudensity) {
534 /* Our lower layer calculations limit our precision to
550 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
551 struct cfg80211_chan_def *def)
553 struct ieee80211_chanctx_conf *conf;
556 conf = rcu_dereference(vif->chanctx_conf);
568 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
569 struct ieee80211_chanctx_conf *conf,
577 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
581 ieee80211_iter_chan_contexts_atomic(ar->hw,
582 ath10k_mac_num_chanctxs_iter,
589 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
590 struct ieee80211_chanctx_conf *conf,
593 struct cfg80211_chan_def **def = data;
598 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr,
599 enum wmi_peer_type peer_type)
603 lockdep_assert_held(&ar->conf_mutex);
605 if (ar->num_peers >= ar->max_num_peers)
608 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
610 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
615 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
617 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
627 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
629 struct ath10k *ar = arvif->ar;
633 param = ar->wmi.pdev_param->sta_kickout_th;
634 ret = ath10k_wmi_pdev_set_param(ar, param,
635 ATH10K_KICKOUT_THRESHOLD);
637 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
638 arvif->vdev_id, ret);
642 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
643 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
644 ATH10K_KEEPALIVE_MIN_IDLE);
646 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
647 arvif->vdev_id, ret);
651 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
652 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
653 ATH10K_KEEPALIVE_MAX_IDLE);
655 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
656 arvif->vdev_id, ret);
660 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
661 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
662 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
664 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
665 arvif->vdev_id, ret);
672 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
674 struct ath10k *ar = arvif->ar;
677 vdev_param = ar->wmi.vdev_param->rts_threshold;
678 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
681 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
685 lockdep_assert_held(&ar->conf_mutex);
687 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
691 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
700 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
702 struct ath10k_peer *peer, *tmp;
704 lockdep_assert_held(&ar->conf_mutex);
706 spin_lock_bh(&ar->data_lock);
707 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
708 if (peer->vdev_id != vdev_id)
711 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
712 peer->addr, vdev_id);
714 list_del(&peer->list);
718 spin_unlock_bh(&ar->data_lock);
721 static void ath10k_peer_cleanup_all(struct ath10k *ar)
723 struct ath10k_peer *peer, *tmp;
725 lockdep_assert_held(&ar->conf_mutex);
727 spin_lock_bh(&ar->data_lock);
728 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
729 list_del(&peer->list);
732 spin_unlock_bh(&ar->data_lock);
735 ar->num_stations = 0;
738 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
739 struct ieee80211_sta *sta,
740 enum wmi_tdls_peer_state state)
743 struct wmi_tdls_peer_update_cmd_arg arg = {};
744 struct wmi_tdls_peer_capab_arg cap = {};
745 struct wmi_channel_arg chan_arg = {};
747 lockdep_assert_held(&ar->conf_mutex);
749 arg.vdev_id = vdev_id;
750 arg.peer_state = state;
751 ether_addr_copy(arg.addr, sta->addr);
753 cap.peer_max_sp = sta->max_sp;
754 cap.peer_uapsd_queues = sta->uapsd_queues;
756 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
757 !sta->tdls_initiator)
758 cap.is_peer_responder = 1;
760 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
762 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
763 arg.addr, vdev_id, ret);
770 /************************/
771 /* Interface management */
772 /************************/
774 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
776 struct ath10k *ar = arvif->ar;
778 lockdep_assert_held(&ar->data_lock);
783 if (!arvif->beacon_buf)
784 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
785 arvif->beacon->len, DMA_TO_DEVICE);
787 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
788 arvif->beacon_state != ATH10K_BEACON_SENT))
791 dev_kfree_skb_any(arvif->beacon);
793 arvif->beacon = NULL;
794 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
797 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
799 struct ath10k *ar = arvif->ar;
801 lockdep_assert_held(&ar->data_lock);
803 ath10k_mac_vif_beacon_free(arvif);
805 if (arvif->beacon_buf) {
806 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
807 arvif->beacon_buf, arvif->beacon_paddr);
808 arvif->beacon_buf = NULL;
812 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
814 unsigned long time_left;
816 lockdep_assert_held(&ar->conf_mutex);
818 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
821 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
822 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
829 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
831 struct cfg80211_chan_def *chandef = NULL;
832 struct ieee80211_channel *channel = NULL;
833 struct wmi_vdev_start_request_arg arg = {};
836 lockdep_assert_held(&ar->conf_mutex);
838 ieee80211_iter_chan_contexts_atomic(ar->hw,
839 ath10k_mac_get_any_chandef_iter,
841 if (WARN_ON_ONCE(!chandef))
844 channel = chandef->chan;
846 arg.vdev_id = vdev_id;
847 arg.channel.freq = channel->center_freq;
848 arg.channel.band_center_freq1 = chandef->center_freq1;
850 /* TODO setup this dynamically, what in case we
851 don't have any vifs? */
852 arg.channel.mode = chan_to_phymode(chandef);
853 arg.channel.chan_radar =
854 !!(channel->flags & IEEE80211_CHAN_RADAR);
856 arg.channel.min_power = 0;
857 arg.channel.max_power = channel->max_power * 2;
858 arg.channel.max_reg_power = channel->max_reg_power * 2;
859 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
861 reinit_completion(&ar->vdev_setup_done);
863 ret = ath10k_wmi_vdev_start(ar, &arg);
865 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
870 ret = ath10k_vdev_setup_sync(ar);
872 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
877 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
879 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
884 ar->monitor_vdev_id = vdev_id;
886 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
887 ar->monitor_vdev_id);
891 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
893 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
894 ar->monitor_vdev_id, ret);
899 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
903 lockdep_assert_held(&ar->conf_mutex);
905 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
907 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
908 ar->monitor_vdev_id, ret);
910 reinit_completion(&ar->vdev_setup_done);
912 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
914 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
915 ar->monitor_vdev_id, ret);
917 ret = ath10k_vdev_setup_sync(ar);
919 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
920 ar->monitor_vdev_id, ret);
922 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
923 ar->monitor_vdev_id);
927 static int ath10k_monitor_vdev_create(struct ath10k *ar)
931 lockdep_assert_held(&ar->conf_mutex);
933 if (ar->free_vdev_map == 0) {
934 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
938 bit = __ffs64(ar->free_vdev_map);
940 ar->monitor_vdev_id = bit;
942 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
943 WMI_VDEV_TYPE_MONITOR,
946 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
947 ar->monitor_vdev_id, ret);
951 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
952 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
953 ar->monitor_vdev_id);
958 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
962 lockdep_assert_held(&ar->conf_mutex);
964 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
966 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
967 ar->monitor_vdev_id, ret);
971 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
974 ar->monitor_vdev_id);
978 static int ath10k_monitor_start(struct ath10k *ar)
982 lockdep_assert_held(&ar->conf_mutex);
984 ret = ath10k_monitor_vdev_create(ar);
986 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
990 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
992 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
993 ath10k_monitor_vdev_delete(ar);
997 ar->monitor_started = true;
998 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1003 static int ath10k_monitor_stop(struct ath10k *ar)
1007 lockdep_assert_held(&ar->conf_mutex);
1009 ret = ath10k_monitor_vdev_stop(ar);
1011 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1015 ret = ath10k_monitor_vdev_delete(ar);
1017 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1021 ar->monitor_started = false;
1022 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1027 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1031 /* At least one chanctx is required to derive a channel to start
1034 num_ctx = ath10k_mac_num_chanctxs(ar);
1038 /* If there's already an existing special monitor interface then don't
1039 * bother creating another monitor vdev.
1041 if (ar->monitor_arvif)
1044 return ar->monitor ||
1045 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1048 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1052 num_ctx = ath10k_mac_num_chanctxs(ar);
1054 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1055 * shouldn't allow this but make sure to prevent handling the following
1056 * case anyway since multi-channel DFS hasn't been tested at all.
1058 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1064 static int ath10k_monitor_recalc(struct ath10k *ar)
1070 lockdep_assert_held(&ar->conf_mutex);
1072 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1073 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1075 ath10k_dbg(ar, ATH10K_DBG_MAC,
1076 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1077 ar->monitor_started, needed, allowed);
1079 if (WARN_ON(needed && !allowed)) {
1080 if (ar->monitor_started) {
1081 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1083 ret = ath10k_monitor_stop(ar);
1085 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n", ret);
1092 if (needed == ar->monitor_started)
1096 return ath10k_monitor_start(ar);
1098 return ath10k_monitor_stop(ar);
1101 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1103 struct ath10k *ar = arvif->ar;
1104 u32 vdev_param, rts_cts = 0;
1106 lockdep_assert_held(&ar->conf_mutex);
1108 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1110 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1112 if (arvif->num_legacy_stations > 0)
1113 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1114 WMI_RTSCTS_PROFILE);
1116 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1117 WMI_RTSCTS_PROFILE);
1119 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1123 static int ath10k_start_cac(struct ath10k *ar)
1127 lockdep_assert_held(&ar->conf_mutex);
1129 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1131 ret = ath10k_monitor_recalc(ar);
1133 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1134 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1138 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1139 ar->monitor_vdev_id);
1144 static int ath10k_stop_cac(struct ath10k *ar)
1146 lockdep_assert_held(&ar->conf_mutex);
1148 /* CAC is not running - do nothing */
1149 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1152 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1153 ath10k_monitor_stop(ar);
1155 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1160 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1161 struct ieee80211_chanctx_conf *conf,
1166 if (!*ret && conf->radar_enabled)
1170 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1172 bool has_radar = false;
1174 ieee80211_iter_chan_contexts_atomic(ar->hw,
1175 ath10k_mac_has_radar_iter,
1181 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1185 lockdep_assert_held(&ar->conf_mutex);
1187 ath10k_stop_cac(ar);
1189 if (!ath10k_mac_has_radar_enabled(ar))
1192 if (ar->num_started_vdevs > 0)
1195 ret = ath10k_start_cac(ar);
1198 * Not possible to start CAC on current channel so starting
1199 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1200 * by indicating that radar was detected.
1202 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1203 ieee80211_radar_detected(ar->hw);
1207 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1209 struct ath10k *ar = arvif->ar;
1212 lockdep_assert_held(&ar->conf_mutex);
1214 reinit_completion(&ar->vdev_setup_done);
1216 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1218 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1219 arvif->vdev_id, ret);
1223 ret = ath10k_vdev_setup_sync(ar);
1225 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1226 arvif->vdev_id, ret);
1230 WARN_ON(ar->num_started_vdevs == 0);
1232 if (ar->num_started_vdevs != 0) {
1233 ar->num_started_vdevs--;
1234 ath10k_recalc_radar_detection(ar);
1240 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1241 const struct cfg80211_chan_def *chandef,
1244 struct ath10k *ar = arvif->ar;
1245 struct wmi_vdev_start_request_arg arg = {};
1248 lockdep_assert_held(&ar->conf_mutex);
1250 reinit_completion(&ar->vdev_setup_done);
1252 arg.vdev_id = arvif->vdev_id;
1253 arg.dtim_period = arvif->dtim_period;
1254 arg.bcn_intval = arvif->beacon_interval;
1256 arg.channel.freq = chandef->chan->center_freq;
1257 arg.channel.band_center_freq1 = chandef->center_freq1;
1258 arg.channel.mode = chan_to_phymode(chandef);
1260 arg.channel.min_power = 0;
1261 arg.channel.max_power = chandef->chan->max_power * 2;
1262 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1263 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1265 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1266 arg.ssid = arvif->u.ap.ssid;
1267 arg.ssid_len = arvif->u.ap.ssid_len;
1268 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1270 /* For now allow DFS for AP mode */
1271 arg.channel.chan_radar =
1272 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1273 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1274 arg.ssid = arvif->vif->bss_conf.ssid;
1275 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1278 ath10k_dbg(ar, ATH10K_DBG_MAC,
1279 "mac vdev %d start center_freq %d phymode %s\n",
1280 arg.vdev_id, arg.channel.freq,
1281 ath10k_wmi_phymode_str(arg.channel.mode));
1284 ret = ath10k_wmi_vdev_restart(ar, &arg);
1286 ret = ath10k_wmi_vdev_start(ar, &arg);
1289 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1294 ret = ath10k_vdev_setup_sync(ar);
1297 "failed to synchronize setup for vdev %i restart %d: %d\n",
1298 arg.vdev_id, restart, ret);
1302 ar->num_started_vdevs++;
1303 ath10k_recalc_radar_detection(ar);
1308 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1309 const struct cfg80211_chan_def *def)
1311 return ath10k_vdev_start_restart(arvif, def, false);
1314 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1315 const struct cfg80211_chan_def *def)
1317 return ath10k_vdev_start_restart(arvif, def, true);
1320 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1321 struct sk_buff *bcn)
1323 struct ath10k *ar = arvif->ar;
1324 struct ieee80211_mgmt *mgmt;
1328 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1331 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1334 mgmt = (void *)bcn->data;
1335 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1336 mgmt->u.beacon.variable,
1337 bcn->len - (mgmt->u.beacon.variable -
1342 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1344 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1345 arvif->vdev_id, ret);
1352 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1353 u8 oui_type, size_t ie_offset)
1360 if (WARN_ON(skb->len < ie_offset))
1363 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1364 skb->data + ie_offset,
1365 skb->len - ie_offset);
1370 end = skb->data + skb->len;
1373 if (WARN_ON(next > end))
1376 memmove(ie, next, end - next);
1377 skb_trim(skb, skb->len - len);
1382 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1384 struct ath10k *ar = arvif->ar;
1385 struct ieee80211_hw *hw = ar->hw;
1386 struct ieee80211_vif *vif = arvif->vif;
1387 struct ieee80211_mutable_offsets offs = {};
1388 struct sk_buff *bcn;
1391 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1394 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1395 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1398 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1400 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1404 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1406 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1411 /* P2P IE is inserted by firmware automatically (as configured above)
1412 * so remove it from the base beacon template to avoid duplicate P2P
1413 * IEs in beacon frames.
1415 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1416 offsetof(struct ieee80211_mgmt,
1417 u.beacon.variable));
1419 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1424 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1432 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1434 struct ath10k *ar = arvif->ar;
1435 struct ieee80211_hw *hw = ar->hw;
1436 struct ieee80211_vif *vif = arvif->vif;
1437 struct sk_buff *prb;
1440 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1443 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1446 prb = ieee80211_proberesp_get(hw, vif);
1448 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1452 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1456 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1464 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1466 struct ath10k *ar = arvif->ar;
1467 struct cfg80211_chan_def def;
1470 /* When originally vdev is started during assign_vif_chanctx() some
1471 * information is missing, notably SSID. Firmware revisions with beacon
1472 * offloading require the SSID to be provided during vdev (re)start to
1473 * handle hidden SSID properly.
1475 * Vdev restart must be done after vdev has been both started and
1476 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1477 * deliver vdev restart response event causing timeouts during vdev
1478 * syncing in ath10k.
1480 * Note: The vdev down/up and template reinstallation could be skipped
1481 * since only wmi-tlv firmware are known to have beacon offload and
1482 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1483 * response delivery. It's probably more robust to keep it as is.
1485 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1488 if (WARN_ON(!arvif->is_started))
1491 if (WARN_ON(!arvif->is_up))
1494 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1497 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1499 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1500 arvif->vdev_id, ret);
1504 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1505 * firmware will crash upon vdev up.
1508 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1510 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1514 ret = ath10k_mac_setup_prb_tmpl(arvif);
1516 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1520 ret = ath10k_vdev_restart(arvif, &def);
1522 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1523 arvif->vdev_id, ret);
1527 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1530 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1531 arvif->vdev_id, ret);
1538 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1539 struct ieee80211_bss_conf *info)
1541 struct ath10k *ar = arvif->ar;
1544 lockdep_assert_held(&arvif->ar->conf_mutex);
1546 if (!info->enable_beacon) {
1547 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1549 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1550 arvif->vdev_id, ret);
1552 arvif->is_up = false;
1554 spin_lock_bh(&arvif->ar->data_lock);
1555 ath10k_mac_vif_beacon_free(arvif);
1556 spin_unlock_bh(&arvif->ar->data_lock);
1561 arvif->tx_seq_no = 0x1000;
1564 ether_addr_copy(arvif->bssid, info->bssid);
1566 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1569 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1570 arvif->vdev_id, ret);
1574 arvif->is_up = true;
1576 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1578 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1579 arvif->vdev_id, ret);
1583 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1586 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1587 struct ieee80211_bss_conf *info,
1588 const u8 self_peer[ETH_ALEN])
1590 struct ath10k *ar = arvif->ar;
1594 lockdep_assert_held(&arvif->ar->conf_mutex);
1596 if (!info->ibss_joined) {
1597 if (is_zero_ether_addr(arvif->bssid))
1600 eth_zero_addr(arvif->bssid);
1605 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1606 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1607 ATH10K_DEFAULT_ATIM);
1609 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1610 arvif->vdev_id, ret);
1613 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1615 struct ath10k *ar = arvif->ar;
1620 lockdep_assert_held(&arvif->ar->conf_mutex);
1622 if (arvif->u.sta.uapsd)
1623 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1625 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1627 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1628 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1630 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1631 value, arvif->vdev_id, ret);
1638 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1640 struct ath10k *ar = arvif->ar;
1645 lockdep_assert_held(&arvif->ar->conf_mutex);
1647 if (arvif->u.sta.uapsd)
1648 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1650 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1652 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1653 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1656 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1657 value, arvif->vdev_id, ret);
1664 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1666 struct ath10k_vif *arvif;
1669 lockdep_assert_held(&ar->conf_mutex);
1671 list_for_each_entry(arvif, &ar->arvifs, list)
1672 if (arvif->is_started)
1678 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1680 struct ath10k *ar = arvif->ar;
1681 struct ieee80211_vif *vif = arvif->vif;
1682 struct ieee80211_conf *conf = &ar->hw->conf;
1683 enum wmi_sta_powersave_param param;
1684 enum wmi_sta_ps_mode psmode;
1689 lockdep_assert_held(&arvif->ar->conf_mutex);
1691 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1694 enable_ps = arvif->ps;
1696 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1697 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1699 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1704 if (!arvif->is_started) {
1705 /* mac80211 can update vif powersave state while disconnected.
1706 * Firmware doesn't behave nicely and consumes more power than
1707 * necessary if PS is disabled on a non-started vdev. Hence
1708 * force-enable PS for non-running vdevs.
1710 psmode = WMI_STA_PS_MODE_ENABLED;
1711 } else if (enable_ps) {
1712 psmode = WMI_STA_PS_MODE_ENABLED;
1713 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1715 ps_timeout = conf->dynamic_ps_timeout;
1716 if (ps_timeout == 0) {
1717 /* Firmware doesn't like 0 */
1718 ps_timeout = ieee80211_tu_to_usec(
1719 vif->bss_conf.beacon_int) / 1000;
1722 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1725 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1726 arvif->vdev_id, ret);
1730 psmode = WMI_STA_PS_MODE_DISABLED;
1733 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1734 arvif->vdev_id, psmode ? "enable" : "disable");
1736 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1738 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1739 psmode, arvif->vdev_id, ret);
1746 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1748 struct ath10k *ar = arvif->ar;
1749 struct wmi_sta_keepalive_arg arg = {};
1752 lockdep_assert_held(&arvif->ar->conf_mutex);
1754 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1757 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1760 /* Some firmware revisions have a bug and ignore the `enabled` field.
1761 * Instead use the interval to disable the keepalive.
1763 arg.vdev_id = arvif->vdev_id;
1765 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1766 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1768 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1770 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1771 arvif->vdev_id, ret);
1778 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1780 struct ath10k *ar = arvif->ar;
1781 struct ieee80211_vif *vif = arvif->vif;
1784 lockdep_assert_held(&arvif->ar->conf_mutex);
1786 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1789 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1792 if (!vif->csa_active)
1798 if (!ieee80211_csa_is_complete(vif)) {
1799 ieee80211_csa_update_counter(vif);
1801 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1803 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1806 ret = ath10k_mac_setup_prb_tmpl(arvif);
1808 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1811 ieee80211_csa_finish(vif);
1815 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1817 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1819 struct ath10k *ar = arvif->ar;
1821 mutex_lock(&ar->conf_mutex);
1822 ath10k_mac_vif_ap_csa_count_down(arvif);
1823 mutex_unlock(&ar->conf_mutex);
1826 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1827 struct ieee80211_vif *vif)
1829 struct sk_buff *skb = data;
1830 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1831 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1833 if (vif->type != NL80211_IFTYPE_STATION)
1836 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1839 cancel_delayed_work(&arvif->connection_loss_work);
1842 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1844 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1845 IEEE80211_IFACE_ITER_NORMAL,
1846 ath10k_mac_handle_beacon_iter,
1850 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1851 struct ieee80211_vif *vif)
1853 u32 *vdev_id = data;
1854 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1855 struct ath10k *ar = arvif->ar;
1856 struct ieee80211_hw *hw = ar->hw;
1858 if (arvif->vdev_id != *vdev_id)
1864 ieee80211_beacon_loss(vif);
1866 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1867 * (done by mac80211) succeeds but beacons do not resume then it
1868 * doesn't make sense to continue operation. Queue connection loss work
1869 * which can be cancelled when beacon is received.
1871 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1872 ATH10K_CONNECTION_LOSS_HZ);
1875 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1877 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1878 IEEE80211_IFACE_ITER_NORMAL,
1879 ath10k_mac_handle_beacon_miss_iter,
1883 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1885 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1886 connection_loss_work.work);
1887 struct ieee80211_vif *vif = arvif->vif;
1892 ieee80211_connection_loss(vif);
1895 /**********************/
1896 /* Station management */
1897 /**********************/
1899 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1900 struct ieee80211_vif *vif)
1902 /* Some firmware revisions have unstable STA powersave when listen
1903 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1904 * generate NullFunc frames properly even if buffered frames have been
1905 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1906 * buffered frames. Often pinging the device from AP would simply fail.
1908 * As a workaround set it to 1.
1910 if (vif->type == NL80211_IFTYPE_STATION)
1913 return ar->hw->conf.listen_interval;
1916 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1917 struct ieee80211_vif *vif,
1918 struct ieee80211_sta *sta,
1919 struct wmi_peer_assoc_complete_arg *arg)
1921 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1924 lockdep_assert_held(&ar->conf_mutex);
1926 if (vif->type == NL80211_IFTYPE_STATION)
1927 aid = vif->bss_conf.aid;
1931 ether_addr_copy(arg->addr, sta->addr);
1932 arg->vdev_id = arvif->vdev_id;
1933 arg->peer_aid = aid;
1934 arg->peer_flags |= WMI_PEER_AUTH;
1935 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1936 arg->peer_num_spatial_streams = 1;
1937 arg->peer_caps = vif->bss_conf.assoc_capability;
1940 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1941 struct ieee80211_vif *vif,
1942 struct wmi_peer_assoc_complete_arg *arg)
1944 struct ieee80211_bss_conf *info = &vif->bss_conf;
1945 struct cfg80211_chan_def def;
1946 struct cfg80211_bss *bss;
1947 const u8 *rsnie = NULL;
1948 const u8 *wpaie = NULL;
1950 lockdep_assert_held(&ar->conf_mutex);
1952 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
1955 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1956 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
1958 const struct cfg80211_bss_ies *ies;
1961 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1963 ies = rcu_dereference(bss->ies);
1965 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1966 WLAN_OUI_TYPE_MICROSOFT_WPA,
1970 cfg80211_put_bss(ar->hw->wiphy, bss);
1973 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1974 if (rsnie || wpaie) {
1975 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1976 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1980 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1981 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1985 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1986 struct ieee80211_vif *vif,
1987 struct ieee80211_sta *sta,
1988 struct wmi_peer_assoc_complete_arg *arg)
1990 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1991 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1992 struct cfg80211_chan_def def;
1993 const struct ieee80211_supported_band *sband;
1994 const struct ieee80211_rate *rates;
1995 enum ieee80211_band band;
2000 lockdep_assert_held(&ar->conf_mutex);
2002 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2005 band = def.chan->band;
2006 sband = ar->hw->wiphy->bands[band];
2007 ratemask = sta->supp_rates[band];
2008 ratemask &= arvif->bitrate_mask.control[band].legacy;
2009 rates = sband->bitrates;
2011 rateset->num_rates = 0;
2013 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2014 if (!(ratemask & 1))
2017 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2018 rateset->rates[rateset->num_rates] = rate;
2019 rateset->num_rates++;
2024 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2028 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2029 if (ht_mcs_mask[nss])
2036 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2040 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2041 if (vht_mcs_mask[nss])
2047 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2048 struct ieee80211_vif *vif,
2049 struct ieee80211_sta *sta,
2050 struct wmi_peer_assoc_complete_arg *arg)
2052 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2053 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2054 struct cfg80211_chan_def def;
2055 enum ieee80211_band band;
2056 const u8 *ht_mcs_mask;
2057 const u16 *vht_mcs_mask;
2061 lockdep_assert_held(&ar->conf_mutex);
2063 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2066 if (!ht_cap->ht_supported)
2069 band = def.chan->band;
2070 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2071 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2073 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2074 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2077 arg->peer_flags |= WMI_PEER_HT;
2078 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2079 ht_cap->ampdu_factor)) - 1;
2081 arg->peer_mpdu_density =
2082 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2084 arg->peer_ht_caps = ht_cap->cap;
2085 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2087 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2088 arg->peer_flags |= WMI_PEER_LDPC;
2090 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2091 arg->peer_flags |= WMI_PEER_40MHZ;
2092 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2095 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2096 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2097 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2099 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2100 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2103 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2104 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2105 arg->peer_flags |= WMI_PEER_STBC;
2108 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2109 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2110 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2111 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2112 arg->peer_rate_caps |= stbc;
2113 arg->peer_flags |= WMI_PEER_STBC;
2116 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2117 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2118 else if (ht_cap->mcs.rx_mask[1])
2119 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2121 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2122 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2123 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2124 max_nss = (i / 8) + 1;
2125 arg->peer_ht_rates.rates[n++] = i;
2129 * This is a workaround for HT-enabled STAs which break the spec
2130 * and have no HT capabilities RX mask (no HT RX MCS map).
2132 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2133 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2135 * Firmware asserts if such situation occurs.
2138 arg->peer_ht_rates.num_rates = 8;
2139 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2140 arg->peer_ht_rates.rates[i] = i;
2142 arg->peer_ht_rates.num_rates = n;
2143 arg->peer_num_spatial_streams = max_nss;
2146 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2148 arg->peer_ht_rates.num_rates,
2149 arg->peer_num_spatial_streams);
2152 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2153 struct ath10k_vif *arvif,
2154 struct ieee80211_sta *sta)
2160 lockdep_assert_held(&ar->conf_mutex);
2162 if (sta->wme && sta->uapsd_queues) {
2163 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2164 sta->uapsd_queues, sta->max_sp);
2166 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2167 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2168 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2169 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2170 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2171 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2172 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2173 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2174 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2175 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2176 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2177 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2179 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2180 max_sp = sta->max_sp;
2182 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2184 WMI_AP_PS_PEER_PARAM_UAPSD,
2187 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2188 arvif->vdev_id, ret);
2192 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2194 WMI_AP_PS_PEER_PARAM_MAX_SP,
2197 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2198 arvif->vdev_id, ret);
2202 /* TODO setup this based on STA listen interval and
2203 beacon interval. Currently we don't know
2204 sta->listen_interval - mac80211 patch required.
2205 Currently use 10 seconds */
2206 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2207 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2210 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2211 arvif->vdev_id, ret);
2220 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2221 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2228 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2229 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2233 idx_limit = fls(mcs_map) - 1;
2237 switch (idx_limit) {
2238 case 0: /* fall through */
2239 case 1: /* fall through */
2240 case 2: /* fall through */
2241 case 3: /* fall through */
2242 case 4: /* fall through */
2243 case 5: /* fall through */
2244 case 6: /* fall through */
2246 /* see ath10k_mac_can_set_bitrate_mask() */
2250 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2253 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2256 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2259 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2263 tx_mcs_set &= ~(0x3 << (nss * 2));
2264 tx_mcs_set |= mcs << (nss * 2);
2270 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2271 struct ieee80211_vif *vif,
2272 struct ieee80211_sta *sta,
2273 struct wmi_peer_assoc_complete_arg *arg)
2275 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2276 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2277 struct cfg80211_chan_def def;
2278 enum ieee80211_band band;
2279 const u16 *vht_mcs_mask;
2282 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2285 if (!vht_cap->vht_supported)
2288 band = def.chan->band;
2289 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2291 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2294 arg->peer_flags |= WMI_PEER_VHT;
2296 if (def.chan->band == IEEE80211_BAND_2GHZ)
2297 arg->peer_flags |= WMI_PEER_VHT_2G;
2299 arg->peer_vht_caps = vht_cap->cap;
2301 ampdu_factor = (vht_cap->cap &
2302 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2303 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2305 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2306 * zero in VHT IE. Using it would result in degraded throughput.
2307 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2308 * it if VHT max_mpdu is smaller. */
2309 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2310 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2311 ampdu_factor)) - 1);
2313 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2314 arg->peer_flags |= WMI_PEER_80MHZ;
2316 arg->peer_vht_rates.rx_max_rate =
2317 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2318 arg->peer_vht_rates.rx_mcs_set =
2319 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2320 arg->peer_vht_rates.tx_max_rate =
2321 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2322 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2323 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2325 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2326 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2329 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2330 struct ieee80211_vif *vif,
2331 struct ieee80211_sta *sta,
2332 struct wmi_peer_assoc_complete_arg *arg)
2334 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2336 switch (arvif->vdev_type) {
2337 case WMI_VDEV_TYPE_AP:
2339 arg->peer_flags |= WMI_PEER_QOS;
2341 if (sta->wme && sta->uapsd_queues) {
2342 arg->peer_flags |= WMI_PEER_APSD;
2343 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2346 case WMI_VDEV_TYPE_STA:
2347 if (vif->bss_conf.qos)
2348 arg->peer_flags |= WMI_PEER_QOS;
2350 case WMI_VDEV_TYPE_IBSS:
2352 arg->peer_flags |= WMI_PEER_QOS;
2358 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2359 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
2362 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2364 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2365 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2368 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2369 struct ieee80211_vif *vif,
2370 struct ieee80211_sta *sta,
2371 struct wmi_peer_assoc_complete_arg *arg)
2373 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2374 struct cfg80211_chan_def def;
2375 enum ieee80211_band band;
2376 const u8 *ht_mcs_mask;
2377 const u16 *vht_mcs_mask;
2378 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2380 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2383 band = def.chan->band;
2384 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2385 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2388 case IEEE80211_BAND_2GHZ:
2389 if (sta->vht_cap.vht_supported &&
2390 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2391 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2392 phymode = MODE_11AC_VHT40;
2394 phymode = MODE_11AC_VHT20;
2395 } else if (sta->ht_cap.ht_supported &&
2396 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2397 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2398 phymode = MODE_11NG_HT40;
2400 phymode = MODE_11NG_HT20;
2401 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2408 case IEEE80211_BAND_5GHZ:
2412 if (sta->vht_cap.vht_supported &&
2413 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2414 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2415 phymode = MODE_11AC_VHT80;
2416 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2417 phymode = MODE_11AC_VHT40;
2418 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2419 phymode = MODE_11AC_VHT20;
2420 } else if (sta->ht_cap.ht_supported &&
2421 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2422 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2423 phymode = MODE_11NA_HT40;
2425 phymode = MODE_11NA_HT20;
2435 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2436 sta->addr, ath10k_wmi_phymode_str(phymode));
2438 arg->peer_phymode = phymode;
2439 WARN_ON(phymode == MODE_UNKNOWN);
2442 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2443 struct ieee80211_vif *vif,
2444 struct ieee80211_sta *sta,
2445 struct wmi_peer_assoc_complete_arg *arg)
2447 lockdep_assert_held(&ar->conf_mutex);
2449 memset(arg, 0, sizeof(*arg));
2451 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2452 ath10k_peer_assoc_h_crypto(ar, vif, arg);
2453 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2454 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2455 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2456 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2457 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2462 static const u32 ath10k_smps_map[] = {
2463 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2464 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2465 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2466 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2469 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2471 const struct ieee80211_sta_ht_cap *ht_cap)
2475 if (!ht_cap->ht_supported)
2478 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2479 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2481 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2484 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2485 WMI_PEER_SMPS_STATE,
2486 ath10k_smps_map[smps]);
2489 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2490 struct ieee80211_vif *vif,
2491 struct ieee80211_sta_vht_cap vht_cap)
2493 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2498 if (!(ar->vht_cap_info &
2499 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2500 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2501 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2502 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2505 param = ar->wmi.vdev_param->txbf;
2508 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2511 /* The following logic is correct. If a remote STA advertises support
2512 * for being a beamformer then we should enable us being a beamformee.
2515 if (ar->vht_cap_info &
2516 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2517 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2518 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2519 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2521 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2522 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2525 if (ar->vht_cap_info &
2526 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2527 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2528 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2529 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2531 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2532 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2535 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2536 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2538 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2539 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2541 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2543 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2551 /* can be called only in mac80211 callbacks due to `key_count` usage */
2552 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2553 struct ieee80211_vif *vif,
2554 struct ieee80211_bss_conf *bss_conf)
2556 struct ath10k *ar = hw->priv;
2557 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2558 struct ieee80211_sta_ht_cap ht_cap;
2559 struct ieee80211_sta_vht_cap vht_cap;
2560 struct wmi_peer_assoc_complete_arg peer_arg;
2561 struct ieee80211_sta *ap_sta;
2564 lockdep_assert_held(&ar->conf_mutex);
2566 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2567 arvif->vdev_id, arvif->bssid, arvif->aid);
2571 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2573 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2574 bss_conf->bssid, arvif->vdev_id);
2579 /* ap_sta must be accessed only within rcu section which must be left
2580 * before calling ath10k_setup_peer_smps() which might sleep. */
2581 ht_cap = ap_sta->ht_cap;
2582 vht_cap = ap_sta->vht_cap;
2584 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2586 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2587 bss_conf->bssid, arvif->vdev_id, ret);
2594 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2596 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2597 bss_conf->bssid, arvif->vdev_id, ret);
2601 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2603 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2604 arvif->vdev_id, ret);
2608 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2610 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2611 arvif->vdev_id, bss_conf->bssid, ret);
2615 ath10k_dbg(ar, ATH10K_DBG_MAC,
2616 "mac vdev %d up (associated) bssid %pM aid %d\n",
2617 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2619 WARN_ON(arvif->is_up);
2621 arvif->aid = bss_conf->aid;
2622 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2624 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2626 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2627 arvif->vdev_id, ret);
2631 arvif->is_up = true;
2633 /* Workaround: Some firmware revisions (tested with qca6174
2634 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2635 * poked with peer param command.
2637 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2638 WMI_PEER_DUMMY_VAR, 1);
2640 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2641 arvif->bssid, arvif->vdev_id, ret);
2646 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2647 struct ieee80211_vif *vif)
2649 struct ath10k *ar = hw->priv;
2650 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2651 struct ieee80211_sta_vht_cap vht_cap = {};
2654 lockdep_assert_held(&ar->conf_mutex);
2656 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2657 arvif->vdev_id, arvif->bssid);
2659 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2661 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2662 arvif->vdev_id, ret);
2664 arvif->def_wep_key_idx = -1;
2666 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2668 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2669 arvif->vdev_id, ret);
2673 arvif->is_up = false;
2675 cancel_delayed_work_sync(&arvif->connection_loss_work);
2678 static int ath10k_station_assoc(struct ath10k *ar,
2679 struct ieee80211_vif *vif,
2680 struct ieee80211_sta *sta,
2683 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2684 struct wmi_peer_assoc_complete_arg peer_arg;
2687 lockdep_assert_held(&ar->conf_mutex);
2689 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2691 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2692 sta->addr, arvif->vdev_id, ret);
2696 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2698 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2699 sta->addr, arvif->vdev_id, ret);
2703 /* Re-assoc is run only to update supported rates for given station. It
2704 * doesn't make much sense to reconfigure the peer completely.
2707 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2710 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2711 arvif->vdev_id, ret);
2715 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2717 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2718 sta->addr, arvif->vdev_id, ret);
2723 arvif->num_legacy_stations++;
2724 ret = ath10k_recalc_rtscts_prot(arvif);
2726 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2727 arvif->vdev_id, ret);
2732 /* Plumb cached keys only for static WEP */
2733 if (arvif->def_wep_key_idx != -1) {
2734 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2736 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2737 arvif->vdev_id, ret);
2746 static int ath10k_station_disassoc(struct ath10k *ar,
2747 struct ieee80211_vif *vif,
2748 struct ieee80211_sta *sta)
2750 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2753 lockdep_assert_held(&ar->conf_mutex);
2756 arvif->num_legacy_stations--;
2757 ret = ath10k_recalc_rtscts_prot(arvif);
2759 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2760 arvif->vdev_id, ret);
2765 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2767 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2768 arvif->vdev_id, ret);
2779 static int ath10k_update_channel_list(struct ath10k *ar)
2781 struct ieee80211_hw *hw = ar->hw;
2782 struct ieee80211_supported_band **bands;
2783 enum ieee80211_band band;
2784 struct ieee80211_channel *channel;
2785 struct wmi_scan_chan_list_arg arg = {0};
2786 struct wmi_channel_arg *ch;
2792 lockdep_assert_held(&ar->conf_mutex);
2794 bands = hw->wiphy->bands;
2795 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2799 for (i = 0; i < bands[band]->n_channels; i++) {
2800 if (bands[band]->channels[i].flags &
2801 IEEE80211_CHAN_DISABLED)
2808 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2809 arg.channels = kzalloc(len, GFP_KERNEL);
2814 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2818 for (i = 0; i < bands[band]->n_channels; i++) {
2819 channel = &bands[band]->channels[i];
2821 if (channel->flags & IEEE80211_CHAN_DISABLED)
2824 ch->allow_ht = true;
2826 /* FIXME: when should we really allow VHT? */
2827 ch->allow_vht = true;
2830 !(channel->flags & IEEE80211_CHAN_NO_IR);
2833 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2836 !!(channel->flags & IEEE80211_CHAN_RADAR);
2838 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2839 ch->passive = passive;
2841 ch->freq = channel->center_freq;
2842 ch->band_center_freq1 = channel->center_freq;
2844 ch->max_power = channel->max_power * 2;
2845 ch->max_reg_power = channel->max_reg_power * 2;
2846 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2847 ch->reg_class_id = 0; /* FIXME */
2849 /* FIXME: why use only legacy modes, why not any
2850 * HT/VHT modes? Would that even make any
2852 if (channel->band == IEEE80211_BAND_2GHZ)
2853 ch->mode = MODE_11G;
2855 ch->mode = MODE_11A;
2857 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2860 ath10k_dbg(ar, ATH10K_DBG_WMI,
2861 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2862 ch - arg.channels, arg.n_channels,
2863 ch->freq, ch->max_power, ch->max_reg_power,
2864 ch->max_antenna_gain, ch->mode);
2870 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2871 kfree(arg.channels);
2876 static enum wmi_dfs_region
2877 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2879 switch (dfs_region) {
2880 case NL80211_DFS_UNSET:
2881 return WMI_UNINIT_DFS_DOMAIN;
2882 case NL80211_DFS_FCC:
2883 return WMI_FCC_DFS_DOMAIN;
2884 case NL80211_DFS_ETSI:
2885 return WMI_ETSI_DFS_DOMAIN;
2886 case NL80211_DFS_JP:
2887 return WMI_MKK4_DFS_DOMAIN;
2889 return WMI_UNINIT_DFS_DOMAIN;
2892 static void ath10k_regd_update(struct ath10k *ar)
2894 struct reg_dmn_pair_mapping *regpair;
2896 enum wmi_dfs_region wmi_dfs_reg;
2897 enum nl80211_dfs_regions nl_dfs_reg;
2899 lockdep_assert_held(&ar->conf_mutex);
2901 ret = ath10k_update_channel_list(ar);
2903 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2905 regpair = ar->ath_common.regulatory.regpair;
2907 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2908 nl_dfs_reg = ar->dfs_detector->region;
2909 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2911 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2914 /* Target allows setting up per-band regdomain but ath_common provides
2915 * a combined one only */
2916 ret = ath10k_wmi_pdev_set_regdomain(ar,
2917 regpair->reg_domain,
2918 regpair->reg_domain, /* 2ghz */
2919 regpair->reg_domain, /* 5ghz */
2920 regpair->reg_2ghz_ctl,
2921 regpair->reg_5ghz_ctl,
2924 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
2927 static void ath10k_reg_notifier(struct wiphy *wiphy,
2928 struct regulatory_request *request)
2930 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2931 struct ath10k *ar = hw->priv;
2934 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2936 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2937 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
2938 request->dfs_region);
2939 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2940 request->dfs_region);
2942 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2943 request->dfs_region);
2946 mutex_lock(&ar->conf_mutex);
2947 if (ar->state == ATH10K_STATE_ON)
2948 ath10k_regd_update(ar);
2949 mutex_unlock(&ar->conf_mutex);
2956 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
2958 lockdep_assert_held(&ar->htt.tx_lock);
2960 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2961 ar->tx_paused |= BIT(reason);
2962 ieee80211_stop_queues(ar->hw);
2965 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
2966 struct ieee80211_vif *vif)
2968 struct ath10k *ar = data;
2969 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2971 if (arvif->tx_paused)
2974 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
2977 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
2979 lockdep_assert_held(&ar->htt.tx_lock);
2981 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
2982 ar->tx_paused &= ~BIT(reason);
2987 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2988 IEEE80211_IFACE_ITER_RESUME_ALL,
2989 ath10k_mac_tx_unlock_iter,
2993 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
2995 struct ath10k *ar = arvif->ar;
2997 lockdep_assert_held(&ar->htt.tx_lock);
2999 WARN_ON(reason >= BITS_PER_LONG);
3000 arvif->tx_paused |= BIT(reason);
3001 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3004 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3006 struct ath10k *ar = arvif->ar;
3008 lockdep_assert_held(&ar->htt.tx_lock);
3010 WARN_ON(reason >= BITS_PER_LONG);
3011 arvif->tx_paused &= ~BIT(reason);
3016 if (arvif->tx_paused)
3019 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3022 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3023 enum wmi_tlv_tx_pause_id pause_id,
3024 enum wmi_tlv_tx_pause_action action)
3026 struct ath10k *ar = arvif->ar;
3028 lockdep_assert_held(&ar->htt.tx_lock);
3031 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3032 ath10k_mac_vif_tx_lock(arvif, pause_id);
3034 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3035 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3038 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3039 action, arvif->vdev_id);
3044 struct ath10k_mac_tx_pause {
3046 enum wmi_tlv_tx_pause_id pause_id;
3047 enum wmi_tlv_tx_pause_action action;
3050 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3051 struct ieee80211_vif *vif)
3053 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3054 struct ath10k_mac_tx_pause *arg = data;
3056 if (arvif->vdev_id != arg->vdev_id)
3059 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3062 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3063 enum wmi_tlv_tx_pause_id pause_id,
3064 enum wmi_tlv_tx_pause_action action)
3066 struct ath10k_mac_tx_pause arg = {
3068 .pause_id = pause_id,
3072 spin_lock_bh(&ar->htt.tx_lock);
3073 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3074 IEEE80211_IFACE_ITER_RESUME_ALL,
3075 ath10k_mac_handle_tx_pause_iter,
3077 spin_unlock_bh(&ar->htt.tx_lock);
3080 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
3082 if (ieee80211_is_mgmt(hdr->frame_control))
3083 return HTT_DATA_TX_EXT_TID_MGMT;
3085 if (!ieee80211_is_data_qos(hdr->frame_control))
3086 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3088 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
3089 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3091 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
3094 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
3097 return ath10k_vif_to_arvif(vif)->vdev_id;
3099 if (ar->monitor_started)
3100 return ar->monitor_vdev_id;
3102 ath10k_warn(ar, "failed to resolve vdev id\n");
3106 static enum ath10k_hw_txrx_mode
3107 ath10k_tx_h_get_txmode(struct ath10k *ar, struct ieee80211_vif *vif,
3108 struct ieee80211_sta *sta, struct sk_buff *skb)
3110 const struct ieee80211_hdr *hdr = (void *)skb->data;
3111 __le16 fc = hdr->frame_control;
3113 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3114 return ATH10K_HW_TXRX_RAW;
3116 if (ieee80211_is_mgmt(fc))
3117 return ATH10K_HW_TXRX_MGMT;
3121 * NullFunc frames are mostly used to ping if a client or AP are still
3122 * reachable and responsive. This implies tx status reports must be
3123 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3124 * come to a conclusion that the other end disappeared and tear down
3125 * BSS connection or it can never disconnect from BSS/client (which is
3128 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3129 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3130 * which seems to deliver correct tx reports for NullFunc frames. The
3131 * downside of using it is it ignores client powersave state so it can
3132 * end up disconnecting sleeping clients in AP mode. It should fix STA
3133 * mode though because AP don't sleep.
3135 if (ar->htt.target_version_major < 3 &&
3136 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3137 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3138 return ATH10K_HW_TXRX_MGMT;
3142 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3143 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3144 * to work with Ethernet txmode so use it.
3146 * FIXME: Check if raw mode works with TDLS.
3148 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3149 return ATH10K_HW_TXRX_ETHERNET;
3151 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3152 return ATH10K_HW_TXRX_RAW;
3154 return ATH10K_HW_TXRX_NATIVE_WIFI;
3157 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3158 struct sk_buff *skb) {
3159 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3160 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3161 IEEE80211_TX_CTL_INJECTED;
3162 if ((info->flags & mask) == mask)
3165 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3169 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3170 * Control in the header.
3172 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3174 struct ieee80211_hdr *hdr = (void *)skb->data;
3175 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3178 if (!ieee80211_is_data_qos(hdr->frame_control))
3181 qos_ctl = ieee80211_get_qos_ctl(hdr);
3182 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3183 skb->data, (void *)qos_ctl - (void *)skb->data);
3184 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3186 /* Some firmware revisions don't handle sending QoS NullFunc well.
3187 * These frames are mainly used for CQM purposes so it doesn't really
3188 * matter whether QoS NullFunc or NullFunc are sent.
3190 hdr = (void *)skb->data;
3191 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3192 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
3194 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3197 static void ath10k_tx_h_8023(struct sk_buff *skb)
3199 struct ieee80211_hdr *hdr;
3200 struct rfc1042_hdr *rfc1042;
3207 hdr = (void *)skb->data;
3208 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3209 rfc1042 = (void *)skb->data + hdrlen;
3211 ether_addr_copy(da, ieee80211_get_DA(hdr));
3212 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3213 type = rfc1042->snap_type;
3215 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3216 skb_push(skb, sizeof(*eth));
3218 eth = (void *)skb->data;
3219 ether_addr_copy(eth->h_dest, da);
3220 ether_addr_copy(eth->h_source, sa);
3221 eth->h_proto = type;
3224 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3225 struct ieee80211_vif *vif,
3226 struct sk_buff *skb)
3228 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3229 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3231 /* This is case only for P2P_GO */
3232 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
3233 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
3236 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3237 spin_lock_bh(&ar->data_lock);
3238 if (arvif->u.ap.noa_data)
3239 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3241 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3242 arvif->u.ap.noa_data,
3243 arvif->u.ap.noa_len);
3244 spin_unlock_bh(&ar->data_lock);
3248 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
3250 /* FIXME: Not really sure since when the behaviour changed. At some
3251 * point new firmware stopped requiring creation of peer entries for
3252 * offchannel tx (and actually creating them causes issues with wmi-htc
3253 * tx credit replenishment and reliability). Assuming it's at least 3.4
3254 * because that's when the `freq` was introduced to TX_FRM HTT command.
3256 return !(ar->htt.target_version_major >= 3 &&
3257 ar->htt.target_version_minor >= 4);
3260 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3262 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3265 spin_lock_bh(&ar->data_lock);
3267 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3268 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3273 __skb_queue_tail(q, skb);
3274 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3277 spin_unlock_bh(&ar->data_lock);
3282 static void ath10k_mac_tx(struct ath10k *ar, struct sk_buff *skb)
3284 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3285 struct ath10k_htt *htt = &ar->htt;
3288 switch (cb->txmode) {
3289 case ATH10K_HW_TXRX_RAW:
3290 case ATH10K_HW_TXRX_NATIVE_WIFI:
3291 case ATH10K_HW_TXRX_ETHERNET:
3292 ret = ath10k_htt_tx(htt, skb);
3294 case ATH10K_HW_TXRX_MGMT:
3295 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3297 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3298 else if (ar->htt.target_version_major >= 3)
3299 ret = ath10k_htt_tx(htt, skb);
3301 ret = ath10k_htt_mgmt_tx(htt, skb);
3306 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3308 ieee80211_free_txskb(ar->hw, skb);
3312 void ath10k_offchan_tx_purge(struct ath10k *ar)
3314 struct sk_buff *skb;
3317 skb = skb_dequeue(&ar->offchan_tx_queue);
3321 ieee80211_free_txskb(ar->hw, skb);
3325 void ath10k_offchan_tx_work(struct work_struct *work)
3327 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3328 struct ath10k_peer *peer;
3329 struct ieee80211_hdr *hdr;
3330 struct sk_buff *skb;
3331 const u8 *peer_addr;
3334 unsigned long time_left;
3336 /* FW requirement: We must create a peer before FW will send out
3337 * an offchannel frame. Otherwise the frame will be stuck and
3338 * never transmitted. We delete the peer upon tx completion.
3339 * It is unlikely that a peer for offchannel tx will already be
3340 * present. However it may be in some rare cases so account for that.
3341 * Otherwise we might remove a legitimate peer and break stuff. */
3344 skb = skb_dequeue(&ar->offchan_tx_queue);
3348 mutex_lock(&ar->conf_mutex);
3350 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
3353 hdr = (struct ieee80211_hdr *)skb->data;
3354 peer_addr = ieee80211_get_DA(hdr);
3355 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
3357 spin_lock_bh(&ar->data_lock);
3358 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3359 spin_unlock_bh(&ar->data_lock);
3362 /* FIXME: should this use ath10k_warn()? */
3363 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3364 peer_addr, vdev_id);
3367 ret = ath10k_peer_create(ar, vdev_id, peer_addr,
3368 WMI_PEER_TYPE_DEFAULT);
3370 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3371 peer_addr, vdev_id, ret);
3374 spin_lock_bh(&ar->data_lock);
3375 reinit_completion(&ar->offchan_tx_completed);
3376 ar->offchan_tx_skb = skb;
3377 spin_unlock_bh(&ar->data_lock);
3379 ath10k_mac_tx(ar, skb);
3382 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3384 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
3388 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3390 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3391 peer_addr, vdev_id, ret);
3394 mutex_unlock(&ar->conf_mutex);
3398 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3400 struct sk_buff *skb;
3403 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3407 ieee80211_free_txskb(ar->hw, skb);
3411 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3413 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3414 struct sk_buff *skb;
3418 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3422 ret = ath10k_wmi_mgmt_tx(ar, skb);
3424 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3426 ieee80211_free_txskb(ar->hw, skb);
3435 void __ath10k_scan_finish(struct ath10k *ar)
3437 lockdep_assert_held(&ar->data_lock);
3439 switch (ar->scan.state) {
3440 case ATH10K_SCAN_IDLE:
3442 case ATH10K_SCAN_RUNNING:
3443 case ATH10K_SCAN_ABORTING:
3444 if (!ar->scan.is_roc)
3445 ieee80211_scan_completed(ar->hw,
3447 ATH10K_SCAN_ABORTING));
3448 else if (ar->scan.roc_notify)
3449 ieee80211_remain_on_channel_expired(ar->hw);
3451 case ATH10K_SCAN_STARTING:
3452 ar->scan.state = ATH10K_SCAN_IDLE;
3453 ar->scan_channel = NULL;
3454 ath10k_offchan_tx_purge(ar);
3455 cancel_delayed_work(&ar->scan.timeout);
3456 complete_all(&ar->scan.completed);
3461 void ath10k_scan_finish(struct ath10k *ar)
3463 spin_lock_bh(&ar->data_lock);
3464 __ath10k_scan_finish(ar);
3465 spin_unlock_bh(&ar->data_lock);
3468 static int ath10k_scan_stop(struct ath10k *ar)
3470 struct wmi_stop_scan_arg arg = {
3471 .req_id = 1, /* FIXME */
3472 .req_type = WMI_SCAN_STOP_ONE,
3473 .u.scan_id = ATH10K_SCAN_ID,
3477 lockdep_assert_held(&ar->conf_mutex);
3479 ret = ath10k_wmi_stop_scan(ar, &arg);
3481 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3485 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
3487 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3489 } else if (ret > 0) {
3494 /* Scan state should be updated upon scan completion but in case
3495 * firmware fails to deliver the event (for whatever reason) it is
3496 * desired to clean up scan state anyway. Firmware may have just
3497 * dropped the scan completion event delivery due to transport pipe
3498 * being overflown with data and/or it can recover on its own before
3499 * next scan request is submitted.
3501 spin_lock_bh(&ar->data_lock);
3502 if (ar->scan.state != ATH10K_SCAN_IDLE)
3503 __ath10k_scan_finish(ar);
3504 spin_unlock_bh(&ar->data_lock);
3509 static void ath10k_scan_abort(struct ath10k *ar)
3513 lockdep_assert_held(&ar->conf_mutex);
3515 spin_lock_bh(&ar->data_lock);
3517 switch (ar->scan.state) {
3518 case ATH10K_SCAN_IDLE:
3519 /* This can happen if timeout worker kicked in and called
3520 * abortion while scan completion was being processed.
3523 case ATH10K_SCAN_STARTING:
3524 case ATH10K_SCAN_ABORTING:
3525 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3526 ath10k_scan_state_str(ar->scan.state),
3529 case ATH10K_SCAN_RUNNING:
3530 ar->scan.state = ATH10K_SCAN_ABORTING;
3531 spin_unlock_bh(&ar->data_lock);
3533 ret = ath10k_scan_stop(ar);
3535 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3537 spin_lock_bh(&ar->data_lock);
3541 spin_unlock_bh(&ar->data_lock);
3544 void ath10k_scan_timeout_work(struct work_struct *work)
3546 struct ath10k *ar = container_of(work, struct ath10k,
3549 mutex_lock(&ar->conf_mutex);
3550 ath10k_scan_abort(ar);
3551 mutex_unlock(&ar->conf_mutex);
3554 static int ath10k_start_scan(struct ath10k *ar,
3555 const struct wmi_start_scan_arg *arg)
3559 lockdep_assert_held(&ar->conf_mutex);
3561 ret = ath10k_wmi_start_scan(ar, arg);
3565 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3567 ret = ath10k_scan_stop(ar);
3569 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3574 /* If we failed to start the scan, return error code at
3575 * this point. This is probably due to some issue in the
3576 * firmware, but no need to wedge the driver due to that...
3578 spin_lock_bh(&ar->data_lock);
3579 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3580 spin_unlock_bh(&ar->data_lock);
3583 spin_unlock_bh(&ar->data_lock);
3585 /* Add a 200ms margin to account for event/command processing */
3586 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3587 msecs_to_jiffies(arg->max_scan_time+200));
3591 /**********************/
3592 /* mac80211 callbacks */
3593 /**********************/
3595 static void ath10k_tx(struct ieee80211_hw *hw,
3596 struct ieee80211_tx_control *control,
3597 struct sk_buff *skb)
3599 struct ath10k *ar = hw->priv;
3600 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3601 struct ieee80211_vif *vif = info->control.vif;
3602 struct ieee80211_sta *sta = control->sta;
3603 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3604 __le16 fc = hdr->frame_control;
3606 /* We should disable CCK RATE due to P2P */
3607 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3608 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3610 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
3611 ATH10K_SKB_CB(skb)->htt.freq = 0;
3612 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
3613 ATH10K_SKB_CB(skb)->htt.nohwcrypt = !ath10k_tx_h_use_hwcrypto(vif, skb);
3614 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
3615 ATH10K_SKB_CB(skb)->txmode = ath10k_tx_h_get_txmode(ar, vif, sta, skb);
3616 ATH10K_SKB_CB(skb)->is_protected = ieee80211_has_protected(fc);
3618 switch (ATH10K_SKB_CB(skb)->txmode) {
3619 case ATH10K_HW_TXRX_MGMT:
3620 case ATH10K_HW_TXRX_NATIVE_WIFI:
3621 ath10k_tx_h_nwifi(hw, skb);
3622 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3623 ath10k_tx_h_seq_no(vif, skb);
3625 case ATH10K_HW_TXRX_ETHERNET:
3626 ath10k_tx_h_8023(skb);
3628 case ATH10K_HW_TXRX_RAW:
3629 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3631 ieee80211_free_txskb(hw, skb);
3636 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3637 spin_lock_bh(&ar->data_lock);
3638 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
3639 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
3640 spin_unlock_bh(&ar->data_lock);
3642 if (ath10k_mac_need_offchan_tx_work(ar)) {
3643 ATH10K_SKB_CB(skb)->htt.freq = 0;
3644 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
3646 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3649 skb_queue_tail(&ar->offchan_tx_queue, skb);
3650 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3655 ath10k_mac_tx(ar, skb);
3658 /* Must not be called with conf_mutex held as workers can use that also. */
3659 void ath10k_drain_tx(struct ath10k *ar)
3661 /* make sure rcu-protected mac80211 tx path itself is drained */
3664 ath10k_offchan_tx_purge(ar);
3665 ath10k_mgmt_over_wmi_tx_purge(ar);
3667 cancel_work_sync(&ar->offchan_tx_work);
3668 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3671 void ath10k_halt(struct ath10k *ar)
3673 struct ath10k_vif *arvif;
3675 lockdep_assert_held(&ar->conf_mutex);
3677 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3678 ar->filter_flags = 0;
3679 ar->monitor = false;
3680 ar->monitor_arvif = NULL;
3682 if (ar->monitor_started)
3683 ath10k_monitor_stop(ar);
3685 ar->monitor_started = false;
3688 ath10k_scan_finish(ar);
3689 ath10k_peer_cleanup_all(ar);
3690 ath10k_core_stop(ar);
3691 ath10k_hif_power_down(ar);
3693 spin_lock_bh(&ar->data_lock);
3694 list_for_each_entry(arvif, &ar->arvifs, list)
3695 ath10k_mac_vif_beacon_cleanup(arvif);
3696 spin_unlock_bh(&ar->data_lock);
3699 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
3701 struct ath10k *ar = hw->priv;
3703 mutex_lock(&ar->conf_mutex);
3705 if (ar->cfg_tx_chainmask) {
3706 *tx_ant = ar->cfg_tx_chainmask;
3707 *rx_ant = ar->cfg_rx_chainmask;
3709 *tx_ant = ar->supp_tx_chainmask;
3710 *rx_ant = ar->supp_rx_chainmask;
3713 mutex_unlock(&ar->conf_mutex);
3718 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
3720 /* It is not clear that allowing gaps in chainmask
3721 * is helpful. Probably it will not do what user
3722 * is hoping for, so warn in that case.
3724 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
3727 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
3731 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
3735 lockdep_assert_held(&ar->conf_mutex);
3737 ath10k_check_chain_mask(ar, tx_ant, "tx");
3738 ath10k_check_chain_mask(ar, rx_ant, "rx");
3740 ar->cfg_tx_chainmask = tx_ant;
3741 ar->cfg_rx_chainmask = rx_ant;
3743 if ((ar->state != ATH10K_STATE_ON) &&
3744 (ar->state != ATH10K_STATE_RESTARTED))
3747 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
3750 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
3755 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
3758 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
3766 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
3768 struct ath10k *ar = hw->priv;
3771 mutex_lock(&ar->conf_mutex);
3772 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
3773 mutex_unlock(&ar->conf_mutex);
3777 static int ath10k_start(struct ieee80211_hw *hw)
3779 struct ath10k *ar = hw->priv;
3784 * This makes sense only when restarting hw. It is harmless to call
3785 * uncoditionally. This is necessary to make sure no HTT/WMI tx
3786 * commands will be submitted while restarting.
3788 ath10k_drain_tx(ar);
3790 mutex_lock(&ar->conf_mutex);
3792 switch (ar->state) {
3793 case ATH10K_STATE_OFF:
3794 ar->state = ATH10K_STATE_ON;
3796 case ATH10K_STATE_RESTARTING:
3798 ar->state = ATH10K_STATE_RESTARTED;
3800 case ATH10K_STATE_ON:
3801 case ATH10K_STATE_RESTARTED:
3802 case ATH10K_STATE_WEDGED:
3806 case ATH10K_STATE_UTF:
3811 ret = ath10k_hif_power_up(ar);
3813 ath10k_err(ar, "Could not init hif: %d\n", ret);
3817 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
3819 ath10k_err(ar, "Could not init core: %d\n", ret);
3820 goto err_power_down;
3823 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
3825 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
3829 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
3831 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
3835 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
3836 ret = ath10k_wmi_adaptive_qcs(ar, true);
3838 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
3844 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
3845 burst_enable = ar->wmi.pdev_param->burst_enable;
3846 ret = ath10k_wmi_pdev_set_param(ar, burst_enable, 0);
3848 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
3853 if (ar->cfg_tx_chainmask)
3854 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
3855 ar->cfg_rx_chainmask);
3858 * By default FW set ARP frames ac to voice (6). In that case ARP
3859 * exchange is not working properly for UAPSD enabled AP. ARP requests
3860 * which arrives with access category 0 are processed by network stack
3861 * and send back with access category 0, but FW changes access category
3862 * to 6. Set ARP frames access category to best effort (0) solves
3866 ret = ath10k_wmi_pdev_set_param(ar,
3867 ar->wmi.pdev_param->arp_ac_override, 0);
3869 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
3874 ret = ath10k_wmi_pdev_set_param(ar,
3875 ar->wmi.pdev_param->ani_enable, 1);
3877 ath10k_warn(ar, "failed to enable ani by default: %d\n",
3882 ar->ani_enabled = true;
3884 ar->num_started_vdevs = 0;
3885 ath10k_regd_update(ar);
3887 ath10k_spectral_start(ar);
3888 ath10k_thermal_set_throttling(ar);
3890 mutex_unlock(&ar->conf_mutex);
3894 ath10k_core_stop(ar);
3897 ath10k_hif_power_down(ar);
3900 ar->state = ATH10K_STATE_OFF;
3903 mutex_unlock(&ar->conf_mutex);
3907 static void ath10k_stop(struct ieee80211_hw *hw)
3909 struct ath10k *ar = hw->priv;
3911 ath10k_drain_tx(ar);
3913 mutex_lock(&ar->conf_mutex);
3914 if (ar->state != ATH10K_STATE_OFF) {
3916 ar->state = ATH10K_STATE_OFF;
3918 mutex_unlock(&ar->conf_mutex);
3920 cancel_delayed_work_sync(&ar->scan.timeout);
3921 cancel_work_sync(&ar->restart_work);
3924 static int ath10k_config_ps(struct ath10k *ar)
3926 struct ath10k_vif *arvif;
3929 lockdep_assert_held(&ar->conf_mutex);
3931 list_for_each_entry(arvif, &ar->arvifs, list) {
3932 ret = ath10k_mac_vif_setup_ps(arvif);
3934 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
3942 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3947 lockdep_assert_held(&ar->conf_mutex);
3949 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3951 param = ar->wmi.pdev_param->txpower_limit2g;
3952 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3954 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3959 param = ar->wmi.pdev_param->txpower_limit5g;
3960 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3962 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3970 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3972 struct ath10k_vif *arvif;
3973 int ret, txpower = -1;
3975 lockdep_assert_held(&ar->conf_mutex);
3977 list_for_each_entry(arvif, &ar->arvifs, list) {
3978 WARN_ON(arvif->txpower < 0);
3981 txpower = arvif->txpower;
3983 txpower = min(txpower, arvif->txpower);
3986 if (WARN_ON(txpower == -1))
3989 ret = ath10k_mac_txpower_setup(ar, txpower);
3991 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3999 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4001 struct ath10k *ar = hw->priv;
4002 struct ieee80211_conf *conf = &hw->conf;
4005 mutex_lock(&ar->conf_mutex);
4007 if (changed & IEEE80211_CONF_CHANGE_PS)
4008 ath10k_config_ps(ar);
4010 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4011 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4012 ret = ath10k_monitor_recalc(ar);
4014 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4017 mutex_unlock(&ar->conf_mutex);
4021 static u32 get_nss_from_chainmask(u16 chain_mask)
4023 if ((chain_mask & 0x15) == 0x15)
4025 else if ((chain_mask & 0x7) == 0x7)
4027 else if ((chain_mask & 0x3) == 0x3)
4034 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4035 * because we will send mgmt frames without CCK. This requirement
4036 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4039 static int ath10k_add_interface(struct ieee80211_hw *hw,
4040 struct ieee80211_vif *vif)
4042 struct ath10k *ar = hw->priv;
4043 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4044 enum wmi_sta_powersave_param param;
4051 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4053 mutex_lock(&ar->conf_mutex);
4055 memset(arvif, 0, sizeof(*arvif));
4060 INIT_LIST_HEAD(&arvif->list);
4061 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4062 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4063 ath10k_mac_vif_sta_connection_loss_work);
4065 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4066 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4067 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4068 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4069 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4070 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4073 if (ar->free_vdev_map == 0) {
4074 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4078 bit = __ffs64(ar->free_vdev_map);
4080 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4081 bit, ar->free_vdev_map);
4083 arvif->vdev_id = bit;
4084 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4086 switch (vif->type) {
4087 case NL80211_IFTYPE_P2P_DEVICE:
4088 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4089 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
4091 case NL80211_IFTYPE_UNSPECIFIED:
4092 case NL80211_IFTYPE_STATION:
4093 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4095 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
4097 case NL80211_IFTYPE_ADHOC:
4098 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4100 case NL80211_IFTYPE_AP:
4101 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4104 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
4106 case NL80211_IFTYPE_MONITOR:
4107 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4114 /* Using vdev_id as queue number will make it very easy to do per-vif
4115 * tx queue locking. This shouldn't wrap due to interface combinations
4116 * but do a modulo for correctness sake and prevent using offchannel tx
4117 * queues for regular vif tx.
4119 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4120 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4121 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4123 /* Some firmware revisions don't wait for beacon tx completion before
4124 * sending another SWBA event. This could lead to hardware using old
4125 * (freed) beacon data in some cases, e.g. tx credit starvation
4126 * combined with missed TBTT. This is very very rare.
4128 * On non-IOMMU-enabled hosts this could be a possible security issue
4129 * because hw could beacon some random data on the air. On
4130 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4131 * device would crash.
4133 * Since there are no beacon tx completions (implicit nor explicit)
4134 * propagated to host the only workaround for this is to allocate a
4135 * DMA-coherent buffer for a lifetime of a vif and use it for all
4136 * beacon tx commands. Worst case for this approach is some beacons may
4137 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4139 if (vif->type == NL80211_IFTYPE_ADHOC ||
4140 vif->type == NL80211_IFTYPE_AP) {
4141 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4142 IEEE80211_MAX_FRAME_LEN,
4143 &arvif->beacon_paddr,
4145 if (!arvif->beacon_buf) {
4147 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4152 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4153 arvif->nohwcrypt = true;
4155 if (arvif->nohwcrypt &&
4156 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4157 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4161 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4162 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4163 arvif->beacon_buf ? "single-buf" : "per-skb");
4165 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4166 arvif->vdev_subtype, vif->addr);
4168 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4169 arvif->vdev_id, ret);
4173 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4174 list_add(&arvif->list, &ar->arvifs);
4176 /* It makes no sense to have firmware do keepalives. mac80211 already
4177 * takes care of this with idle connection polling.
4179 ret = ath10k_mac_vif_disable_keepalive(arvif);
4181 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4182 arvif->vdev_id, ret);
4183 goto err_vdev_delete;
4186 arvif->def_wep_key_idx = -1;
4188 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4189 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4190 ATH10K_HW_TXRX_NATIVE_WIFI);
4191 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4192 if (ret && ret != -EOPNOTSUPP) {
4193 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4194 arvif->vdev_id, ret);
4195 goto err_vdev_delete;
4198 if (ar->cfg_tx_chainmask) {
4199 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4201 vdev_param = ar->wmi.vdev_param->nss;
4202 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4205 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4206 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4208 goto err_vdev_delete;
4212 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4213 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4214 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr,
4215 WMI_PEER_TYPE_DEFAULT);
4217 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4218 arvif->vdev_id, ret);
4219 goto err_vdev_delete;
4223 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4224 ret = ath10k_mac_set_kickout(arvif);
4226 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
4227 arvif->vdev_id, ret);
4228 goto err_peer_delete;
4232 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4233 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4234 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4235 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4238 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
4239 arvif->vdev_id, ret);
4240 goto err_peer_delete;
4243 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4245 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4246 arvif->vdev_id, ret);
4247 goto err_peer_delete;
4250 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4252 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4253 arvif->vdev_id, ret);
4254 goto err_peer_delete;
4258 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
4260 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4261 arvif->vdev_id, ret);
4262 goto err_peer_delete;
4265 arvif->txpower = vif->bss_conf.txpower;
4266 ret = ath10k_mac_txpower_recalc(ar);
4268 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4269 goto err_peer_delete;
4272 if (vif->type == NL80211_IFTYPE_MONITOR) {
4273 ar->monitor_arvif = arvif;
4274 ret = ath10k_monitor_recalc(ar);
4276 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4277 goto err_peer_delete;
4281 mutex_unlock(&ar->conf_mutex);
4285 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4286 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
4287 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4290 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4291 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4292 list_del(&arvif->list);
4295 if (arvif->beacon_buf) {
4296 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4297 arvif->beacon_buf, arvif->beacon_paddr);
4298 arvif->beacon_buf = NULL;
4301 mutex_unlock(&ar->conf_mutex);
4306 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4310 for (i = 0; i < BITS_PER_LONG; i++)
4311 ath10k_mac_vif_tx_unlock(arvif, i);
4314 static void ath10k_remove_interface(struct ieee80211_hw *hw,
4315 struct ieee80211_vif *vif)
4317 struct ath10k *ar = hw->priv;
4318 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4321 cancel_work_sync(&arvif->ap_csa_work);
4322 cancel_delayed_work_sync(&arvif->connection_loss_work);
4324 mutex_lock(&ar->conf_mutex);
4326 spin_lock_bh(&ar->data_lock);
4327 ath10k_mac_vif_beacon_cleanup(arvif);
4328 spin_unlock_bh(&ar->data_lock);
4330 ret = ath10k_spectral_vif_stop(arvif);
4332 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
4333 arvif->vdev_id, ret);
4335 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4336 list_del(&arvif->list);
4338 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4339 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4340 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4343 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4344 arvif->vdev_id, ret);
4346 kfree(arvif->u.ap.noa_data);
4349 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
4352 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4354 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
4355 arvif->vdev_id, ret);
4357 /* Some firmware revisions don't notify host about self-peer removal
4358 * until after associated vdev is deleted.
4360 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4361 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4362 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4365 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4366 arvif->vdev_id, ret);
4368 spin_lock_bh(&ar->data_lock);
4370 spin_unlock_bh(&ar->data_lock);
4373 ath10k_peer_cleanup(ar, arvif->vdev_id);
4375 if (vif->type == NL80211_IFTYPE_MONITOR) {
4376 ar->monitor_arvif = NULL;
4377 ret = ath10k_monitor_recalc(ar);
4379 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4382 spin_lock_bh(&ar->htt.tx_lock);
4383 ath10k_mac_vif_tx_unlock_all(arvif);
4384 spin_unlock_bh(&ar->htt.tx_lock);
4386 mutex_unlock(&ar->conf_mutex);
4390 * FIXME: Has to be verified.
4392 #define SUPPORTED_FILTERS \
4397 FIF_BCN_PRBRESP_PROMISC | \
4401 static void ath10k_configure_filter(struct ieee80211_hw *hw,
4402 unsigned int changed_flags,
4403 unsigned int *total_flags,
4406 struct ath10k *ar = hw->priv;
4409 mutex_lock(&ar->conf_mutex);
4411 changed_flags &= SUPPORTED_FILTERS;
4412 *total_flags &= SUPPORTED_FILTERS;
4413 ar->filter_flags = *total_flags;
4415 ret = ath10k_monitor_recalc(ar);
4417 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
4419 mutex_unlock(&ar->conf_mutex);
4422 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
4423 struct ieee80211_vif *vif,
4424 struct ieee80211_bss_conf *info,
4427 struct ath10k *ar = hw->priv;
4428 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4430 u32 vdev_param, pdev_param, slottime, preamble;
4432 mutex_lock(&ar->conf_mutex);
4434 if (changed & BSS_CHANGED_IBSS)
4435 ath10k_control_ibss(arvif, info, vif->addr);
4437 if (changed & BSS_CHANGED_BEACON_INT) {
4438 arvif->beacon_interval = info->beacon_int;
4439 vdev_param = ar->wmi.vdev_param->beacon_interval;
4440 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4441 arvif->beacon_interval);
4442 ath10k_dbg(ar, ATH10K_DBG_MAC,
4443 "mac vdev %d beacon_interval %d\n",
4444 arvif->vdev_id, arvif->beacon_interval);
4447 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
4448 arvif->vdev_id, ret);
4451 if (changed & BSS_CHANGED_BEACON) {
4452 ath10k_dbg(ar, ATH10K_DBG_MAC,
4453 "vdev %d set beacon tx mode to staggered\n",
4456 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
4457 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
4458 WMI_BEACON_STAGGERED_MODE);
4460 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
4461 arvif->vdev_id, ret);
4463 ret = ath10k_mac_setup_bcn_tmpl(arvif);
4465 ath10k_warn(ar, "failed to update beacon template: %d\n",
4469 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
4470 ret = ath10k_mac_setup_prb_tmpl(arvif);
4472 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
4473 arvif->vdev_id, ret);
4476 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
4477 arvif->dtim_period = info->dtim_period;
4479 ath10k_dbg(ar, ATH10K_DBG_MAC,
4480 "mac vdev %d dtim_period %d\n",
4481 arvif->vdev_id, arvif->dtim_period);
4483 vdev_param = ar->wmi.vdev_param->dtim_period;
4484 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4485 arvif->dtim_period);
4487 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
4488 arvif->vdev_id, ret);
4491 if (changed & BSS_CHANGED_SSID &&
4492 vif->type == NL80211_IFTYPE_AP) {
4493 arvif->u.ap.ssid_len = info->ssid_len;
4495 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
4496 arvif->u.ap.hidden_ssid = info->hidden_ssid;
4499 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
4500 ether_addr_copy(arvif->bssid, info->bssid);
4502 if (changed & BSS_CHANGED_BEACON_ENABLED)
4503 ath10k_control_beaconing(arvif, info);
4505 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
4506 arvif->use_cts_prot = info->use_cts_prot;
4507 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
4508 arvif->vdev_id, info->use_cts_prot);
4510 ret = ath10k_recalc_rtscts_prot(arvif);
4512 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
4513 arvif->vdev_id, ret);
4515 vdev_param = ar->wmi.vdev_param->protection_mode;
4516 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4517 info->use_cts_prot ? 1 : 0);
4519 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
4520 info->use_cts_prot, arvif->vdev_id, ret);
4523 if (changed & BSS_CHANGED_ERP_SLOT) {
4524 if (info->use_short_slot)
4525 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
4528 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
4530 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
4531 arvif->vdev_id, slottime);
4533 vdev_param = ar->wmi.vdev_param->slot_time;
4534 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4537 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
4538 arvif->vdev_id, ret);
4541 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
4542 if (info->use_short_preamble)
4543 preamble = WMI_VDEV_PREAMBLE_SHORT;
4545 preamble = WMI_VDEV_PREAMBLE_LONG;
4547 ath10k_dbg(ar, ATH10K_DBG_MAC,
4548 "mac vdev %d preamble %dn",
4549 arvif->vdev_id, preamble);
4551 vdev_param = ar->wmi.vdev_param->preamble;
4552 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4555 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
4556 arvif->vdev_id, ret);
4559 if (changed & BSS_CHANGED_ASSOC) {
4561 /* Workaround: Make sure monitor vdev is not running
4562 * when associating to prevent some firmware revisions
4563 * (e.g. 10.1 and 10.2) from crashing.
4565 if (ar->monitor_started)
4566 ath10k_monitor_stop(ar);
4567 ath10k_bss_assoc(hw, vif, info);
4568 ath10k_monitor_recalc(ar);
4570 ath10k_bss_disassoc(hw, vif);
4574 if (changed & BSS_CHANGED_TXPOWER) {
4575 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
4576 arvif->vdev_id, info->txpower);
4578 arvif->txpower = info->txpower;
4579 ret = ath10k_mac_txpower_recalc(ar);
4581 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4584 if (changed & BSS_CHANGED_PS) {
4585 arvif->ps = vif->bss_conf.ps;
4587 ret = ath10k_config_ps(ar);
4589 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
4590 arvif->vdev_id, ret);
4593 mutex_unlock(&ar->conf_mutex);
4596 static int ath10k_hw_scan(struct ieee80211_hw *hw,
4597 struct ieee80211_vif *vif,
4598 struct ieee80211_scan_request *hw_req)
4600 struct ath10k *ar = hw->priv;
4601 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4602 struct cfg80211_scan_request *req = &hw_req->req;
4603 struct wmi_start_scan_arg arg;
4607 mutex_lock(&ar->conf_mutex);
4609 spin_lock_bh(&ar->data_lock);
4610 switch (ar->scan.state) {
4611 case ATH10K_SCAN_IDLE:
4612 reinit_completion(&ar->scan.started);
4613 reinit_completion(&ar->scan.completed);
4614 ar->scan.state = ATH10K_SCAN_STARTING;
4615 ar->scan.is_roc = false;
4616 ar->scan.vdev_id = arvif->vdev_id;
4619 case ATH10K_SCAN_STARTING:
4620 case ATH10K_SCAN_RUNNING:
4621 case ATH10K_SCAN_ABORTING:
4625 spin_unlock_bh(&ar->data_lock);
4630 memset(&arg, 0, sizeof(arg));
4631 ath10k_wmi_start_scan_init(ar, &arg);
4632 arg.vdev_id = arvif->vdev_id;
4633 arg.scan_id = ATH10K_SCAN_ID;
4636 arg.ie_len = req->ie_len;
4637 memcpy(arg.ie, req->ie, arg.ie_len);
4641 arg.n_ssids = req->n_ssids;
4642 for (i = 0; i < arg.n_ssids; i++) {
4643 arg.ssids[i].len = req->ssids[i].ssid_len;
4644 arg.ssids[i].ssid = req->ssids[i].ssid;
4647 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4650 if (req->n_channels) {
4651 arg.n_channels = req->n_channels;
4652 for (i = 0; i < arg.n_channels; i++)
4653 arg.channels[i] = req->channels[i]->center_freq;
4656 ret = ath10k_start_scan(ar, &arg);
4658 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
4659 spin_lock_bh(&ar->data_lock);
4660 ar->scan.state = ATH10K_SCAN_IDLE;
4661 spin_unlock_bh(&ar->data_lock);
4665 mutex_unlock(&ar->conf_mutex);
4669 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
4670 struct ieee80211_vif *vif)
4672 struct ath10k *ar = hw->priv;
4674 mutex_lock(&ar->conf_mutex);
4675 ath10k_scan_abort(ar);
4676 mutex_unlock(&ar->conf_mutex);
4678 cancel_delayed_work_sync(&ar->scan.timeout);
4681 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
4682 struct ath10k_vif *arvif,
4683 enum set_key_cmd cmd,
4684 struct ieee80211_key_conf *key)
4686 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
4689 /* 10.1 firmware branch requires default key index to be set to group
4690 * key index after installing it. Otherwise FW/HW Txes corrupted
4691 * frames with multi-vif APs. This is not required for main firmware
4692 * branch (e.g. 636).
4694 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
4696 * FIXME: It remains unknown if this is required for multi-vif STA
4697 * interfaces on 10.1.
4700 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4701 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4704 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
4707 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
4710 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4716 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4719 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
4720 arvif->vdev_id, ret);
4723 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4724 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4725 struct ieee80211_key_conf *key)
4727 struct ath10k *ar = hw->priv;
4728 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4729 struct ath10k_peer *peer;
4730 const u8 *peer_addr;
4731 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
4732 key->cipher == WLAN_CIPHER_SUITE_WEP104;
4738 /* this one needs to be done in software */
4739 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
4742 if (arvif->nohwcrypt)
4745 if (key->keyidx > WMI_MAX_KEY_INDEX)
4748 mutex_lock(&ar->conf_mutex);
4751 peer_addr = sta->addr;
4752 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
4753 peer_addr = vif->bss_conf.bssid;
4755 peer_addr = vif->addr;
4757 key->hw_key_idx = key->keyidx;
4761 arvif->wep_keys[key->keyidx] = key;
4763 arvif->wep_keys[key->keyidx] = NULL;
4766 /* the peer should not disappear in mid-way (unless FW goes awry) since
4767 * we already hold conf_mutex. we just make sure its there now. */
4768 spin_lock_bh(&ar->data_lock);
4769 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4770 spin_unlock_bh(&ar->data_lock);
4773 if (cmd == SET_KEY) {
4774 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
4779 /* if the peer doesn't exist there is no key to disable
4785 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4786 flags |= WMI_KEY_PAIRWISE;
4788 flags |= WMI_KEY_GROUP;
4791 if (cmd == DISABLE_KEY)
4792 ath10k_clear_vdev_key(arvif, key);
4794 /* When WEP keys are uploaded it's possible that there are
4795 * stations associated already (e.g. when merging) without any
4796 * keys. Static WEP needs an explicit per-peer key upload.
4798 if (vif->type == NL80211_IFTYPE_ADHOC &&
4800 ath10k_mac_vif_update_wep_key(arvif, key);
4802 /* 802.1x never sets the def_wep_key_idx so each set_key()
4803 * call changes default tx key.
4805 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
4806 * after first set_key().
4808 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
4809 flags |= WMI_KEY_TX_USAGE;
4812 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
4815 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
4816 arvif->vdev_id, peer_addr, ret);
4820 /* mac80211 sets static WEP keys as groupwise while firmware requires
4821 * them to be installed twice as both pairwise and groupwise.
4823 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
4825 flags2 &= ~WMI_KEY_GROUP;
4826 flags2 |= WMI_KEY_PAIRWISE;
4828 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
4831 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
4832 arvif->vdev_id, peer_addr, ret);
4833 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
4837 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
4838 arvif->vdev_id, peer_addr, ret2);
4844 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
4846 spin_lock_bh(&ar->data_lock);
4847 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
4848 if (peer && cmd == SET_KEY)
4849 peer->keys[key->keyidx] = key;
4850 else if (peer && cmd == DISABLE_KEY)
4851 peer->keys[key->keyidx] = NULL;
4852 else if (peer == NULL)
4853 /* impossible unless FW goes crazy */
4854 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
4855 spin_unlock_bh(&ar->data_lock);
4858 mutex_unlock(&ar->conf_mutex);
4862 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
4863 struct ieee80211_vif *vif,
4866 struct ath10k *ar = hw->priv;
4867 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4870 mutex_lock(&arvif->ar->conf_mutex);
4872 if (arvif->ar->state != ATH10K_STATE_ON)
4875 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
4876 arvif->vdev_id, keyidx);
4878 ret = ath10k_wmi_vdev_set_param(arvif->ar,
4880 arvif->ar->wmi.vdev_param->def_keyid,
4884 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
4890 arvif->def_wep_key_idx = keyidx;
4893 mutex_unlock(&arvif->ar->conf_mutex);
4896 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
4899 struct ath10k_vif *arvif;
4900 struct ath10k_sta *arsta;
4901 struct ieee80211_sta *sta;
4902 struct cfg80211_chan_def def;
4903 enum ieee80211_band band;
4904 const u8 *ht_mcs_mask;
4905 const u16 *vht_mcs_mask;
4906 u32 changed, bw, nss, smps;
4909 arsta = container_of(wk, struct ath10k_sta, update_wk);
4910 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4911 arvif = arsta->arvif;
4914 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
4917 band = def.chan->band;
4918 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4919 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4921 spin_lock_bh(&ar->data_lock);
4923 changed = arsta->changed;
4930 spin_unlock_bh(&ar->data_lock);
4932 mutex_lock(&ar->conf_mutex);
4934 nss = max_t(u32, 1, nss);
4935 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
4936 ath10k_mac_max_vht_nss(vht_mcs_mask)));
4938 if (changed & IEEE80211_RC_BW_CHANGED) {
4939 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
4942 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4943 WMI_PEER_CHAN_WIDTH, bw);
4945 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
4946 sta->addr, bw, err);
4949 if (changed & IEEE80211_RC_NSS_CHANGED) {
4950 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
4953 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4956 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
4957 sta->addr, nss, err);
4960 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4961 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
4964 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
4965 WMI_PEER_SMPS_STATE, smps);
4967 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
4968 sta->addr, smps, err);
4971 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4972 changed & IEEE80211_RC_NSS_CHANGED) {
4973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
4976 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
4978 ath10k_warn(ar, "failed to reassociate station: %pM\n",
4982 mutex_unlock(&ar->conf_mutex);
4985 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
4986 struct ieee80211_sta *sta)
4988 struct ath10k *ar = arvif->ar;
4990 lockdep_assert_held(&ar->conf_mutex);
4992 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
4995 if (ar->num_stations >= ar->max_num_stations)
5003 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5004 struct ieee80211_sta *sta)
5006 struct ath10k *ar = arvif->ar;
5008 lockdep_assert_held(&ar->conf_mutex);
5010 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5016 struct ath10k_mac_tdls_iter_data {
5017 u32 num_tdls_stations;
5018 struct ieee80211_vif *curr_vif;
5021 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5022 struct ieee80211_sta *sta)
5024 struct ath10k_mac_tdls_iter_data *iter_data = data;
5025 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5026 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5028 if (sta->tdls && sta_vif == iter_data->curr_vif)
5029 iter_data->num_tdls_stations++;
5032 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5033 struct ieee80211_vif *vif)
5035 struct ath10k_mac_tdls_iter_data data = {};
5037 data.curr_vif = vif;
5039 ieee80211_iterate_stations_atomic(hw,
5040 ath10k_mac_tdls_vif_stations_count_iter,
5042 return data.num_tdls_stations;
5045 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5046 struct ieee80211_vif *vif)
5048 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5049 int *num_tdls_vifs = data;
5051 if (vif->type != NL80211_IFTYPE_STATION)
5054 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5058 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5060 int num_tdls_vifs = 0;
5062 ieee80211_iterate_active_interfaces_atomic(hw,
5063 IEEE80211_IFACE_ITER_NORMAL,
5064 ath10k_mac_tdls_vifs_count_iter,
5066 return num_tdls_vifs;
5069 static int ath10k_sta_state(struct ieee80211_hw *hw,
5070 struct ieee80211_vif *vif,
5071 struct ieee80211_sta *sta,
5072 enum ieee80211_sta_state old_state,
5073 enum ieee80211_sta_state new_state)
5075 struct ath10k *ar = hw->priv;
5076 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5077 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5080 if (old_state == IEEE80211_STA_NOTEXIST &&
5081 new_state == IEEE80211_STA_NONE) {
5082 memset(arsta, 0, sizeof(*arsta));
5083 arsta->arvif = arvif;
5084 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5087 /* cancel must be done outside the mutex to avoid deadlock */
5088 if ((old_state == IEEE80211_STA_NONE &&
5089 new_state == IEEE80211_STA_NOTEXIST))
5090 cancel_work_sync(&arsta->update_wk);
5092 mutex_lock(&ar->conf_mutex);
5094 if (old_state == IEEE80211_STA_NOTEXIST &&
5095 new_state == IEEE80211_STA_NONE) {
5097 * New station addition.
5099 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5100 u32 num_tdls_stations;
5103 ath10k_dbg(ar, ATH10K_DBG_MAC,
5104 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5105 arvif->vdev_id, sta->addr,
5106 ar->num_stations + 1, ar->max_num_stations,
5107 ar->num_peers + 1, ar->max_num_peers);
5109 ret = ath10k_mac_inc_num_stations(arvif, sta);
5111 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5112 ar->max_num_stations);
5117 peer_type = WMI_PEER_TYPE_TDLS;
5119 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr,
5122 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5123 sta->addr, arvif->vdev_id, ret);
5124 ath10k_mac_dec_num_stations(arvif, sta);
5131 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5132 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5134 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5135 num_tdls_stations == 0) {
5136 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5137 arvif->vdev_id, ar->max_num_tdls_vdevs);
5138 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5139 ath10k_mac_dec_num_stations(arvif, sta);
5144 if (num_tdls_stations == 0) {
5145 /* This is the first tdls peer in current vif */
5146 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5148 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5151 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5152 arvif->vdev_id, ret);
5153 ath10k_peer_delete(ar, arvif->vdev_id,
5155 ath10k_mac_dec_num_stations(arvif, sta);
5160 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5161 WMI_TDLS_PEER_STATE_PEERING);
5164 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5165 sta->addr, arvif->vdev_id, ret);
5166 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5167 ath10k_mac_dec_num_stations(arvif, sta);
5169 if (num_tdls_stations != 0)
5171 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5174 } else if ((old_state == IEEE80211_STA_NONE &&
5175 new_state == IEEE80211_STA_NOTEXIST)) {
5177 * Existing station deletion.
5179 ath10k_dbg(ar, ATH10K_DBG_MAC,
5180 "mac vdev %d peer delete %pM (sta gone)\n",
5181 arvif->vdev_id, sta->addr);
5183 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5185 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
5186 sta->addr, arvif->vdev_id, ret);
5188 ath10k_mac_dec_num_stations(arvif, sta);
5193 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5196 /* This was the last tdls peer in current vif */
5197 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5200 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5201 arvif->vdev_id, ret);
5203 } else if (old_state == IEEE80211_STA_AUTH &&
5204 new_state == IEEE80211_STA_ASSOC &&
5205 (vif->type == NL80211_IFTYPE_AP ||
5206 vif->type == NL80211_IFTYPE_ADHOC)) {
5210 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
5213 ret = ath10k_station_assoc(ar, vif, sta, false);
5215 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
5216 sta->addr, arvif->vdev_id, ret);
5217 } else if (old_state == IEEE80211_STA_ASSOC &&
5218 new_state == IEEE80211_STA_AUTHORIZED &&
5221 * Tdls station authorized.
5223 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5226 ret = ath10k_station_assoc(ar, vif, sta, false);
5228 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5229 sta->addr, arvif->vdev_id, ret);
5233 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5234 WMI_TDLS_PEER_STATE_CONNECTED);
5236 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5237 sta->addr, arvif->vdev_id, ret);
5238 } else if (old_state == IEEE80211_STA_ASSOC &&
5239 new_state == IEEE80211_STA_AUTH &&
5240 (vif->type == NL80211_IFTYPE_AP ||
5241 vif->type == NL80211_IFTYPE_ADHOC)) {
5245 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
5248 ret = ath10k_station_disassoc(ar, vif, sta);
5250 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
5251 sta->addr, arvif->vdev_id, ret);
5254 mutex_unlock(&ar->conf_mutex);
5258 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
5259 u16 ac, bool enable)
5261 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5262 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5263 u32 prio = 0, acc = 0;
5267 lockdep_assert_held(&ar->conf_mutex);
5269 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5273 case IEEE80211_AC_VO:
5274 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5275 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
5279 case IEEE80211_AC_VI:
5280 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5281 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
5285 case IEEE80211_AC_BE:
5286 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5287 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
5291 case IEEE80211_AC_BK:
5292 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5293 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
5300 arvif->u.sta.uapsd |= value;
5302 arvif->u.sta.uapsd &= ~value;
5304 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5305 WMI_STA_PS_PARAM_UAPSD,
5306 arvif->u.sta.uapsd);
5308 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
5312 if (arvif->u.sta.uapsd)
5313 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5315 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5317 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5318 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5321 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
5323 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5325 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5326 arvif->vdev_id, ret);
5330 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
5332 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
5333 arvif->vdev_id, ret);
5337 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
5338 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
5339 /* Only userspace can make an educated decision when to send
5340 * trigger frame. The following effectively disables u-UAPSD
5341 * autotrigger in firmware (which is enabled by default
5342 * provided the autotrigger service is available).
5346 arg.user_priority = prio;
5347 arg.service_interval = 0;
5348 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5349 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
5351 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
5352 arvif->bssid, &arg, 1);
5354 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
5364 static int ath10k_conf_tx(struct ieee80211_hw *hw,
5365 struct ieee80211_vif *vif, u16 ac,
5366 const struct ieee80211_tx_queue_params *params)
5368 struct ath10k *ar = hw->priv;
5369 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5370 struct wmi_wmm_params_arg *p = NULL;
5373 mutex_lock(&ar->conf_mutex);
5376 case IEEE80211_AC_VO:
5377 p = &arvif->wmm_params.ac_vo;
5379 case IEEE80211_AC_VI:
5380 p = &arvif->wmm_params.ac_vi;
5382 case IEEE80211_AC_BE:
5383 p = &arvif->wmm_params.ac_be;
5385 case IEEE80211_AC_BK:
5386 p = &arvif->wmm_params.ac_bk;
5395 p->cwmin = params->cw_min;
5396 p->cwmax = params->cw_max;
5397 p->aifs = params->aifs;
5400 * The channel time duration programmed in the HW is in absolute
5401 * microseconds, while mac80211 gives the txop in units of
5404 p->txop = params->txop * 32;
5406 if (ar->wmi.ops->gen_vdev_wmm_conf) {
5407 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
5408 &arvif->wmm_params);
5410 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
5411 arvif->vdev_id, ret);
5415 /* This won't work well with multi-interface cases but it's
5416 * better than nothing.
5418 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
5420 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
5425 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
5427 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
5430 mutex_unlock(&ar->conf_mutex);
5434 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
5436 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
5437 struct ieee80211_vif *vif,
5438 struct ieee80211_channel *chan,
5440 enum ieee80211_roc_type type)
5442 struct ath10k *ar = hw->priv;
5443 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5444 struct wmi_start_scan_arg arg;
5448 mutex_lock(&ar->conf_mutex);
5450 spin_lock_bh(&ar->data_lock);
5451 switch (ar->scan.state) {
5452 case ATH10K_SCAN_IDLE:
5453 reinit_completion(&ar->scan.started);
5454 reinit_completion(&ar->scan.completed);
5455 reinit_completion(&ar->scan.on_channel);
5456 ar->scan.state = ATH10K_SCAN_STARTING;
5457 ar->scan.is_roc = true;
5458 ar->scan.vdev_id = arvif->vdev_id;
5459 ar->scan.roc_freq = chan->center_freq;
5460 ar->scan.roc_notify = true;
5463 case ATH10K_SCAN_STARTING:
5464 case ATH10K_SCAN_RUNNING:
5465 case ATH10K_SCAN_ABORTING:
5469 spin_unlock_bh(&ar->data_lock);
5474 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
5476 memset(&arg, 0, sizeof(arg));
5477 ath10k_wmi_start_scan_init(ar, &arg);
5478 arg.vdev_id = arvif->vdev_id;
5479 arg.scan_id = ATH10K_SCAN_ID;
5481 arg.channels[0] = chan->center_freq;
5482 arg.dwell_time_active = scan_time_msec;
5483 arg.dwell_time_passive = scan_time_msec;
5484 arg.max_scan_time = scan_time_msec;
5485 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5486 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
5487 arg.burst_duration_ms = duration;
5489 ret = ath10k_start_scan(ar, &arg);
5491 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
5492 spin_lock_bh(&ar->data_lock);
5493 ar->scan.state = ATH10K_SCAN_IDLE;
5494 spin_unlock_bh(&ar->data_lock);
5498 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
5500 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
5502 ret = ath10k_scan_stop(ar);
5504 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
5510 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5511 msecs_to_jiffies(duration));
5515 mutex_unlock(&ar->conf_mutex);
5519 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
5521 struct ath10k *ar = hw->priv;
5523 mutex_lock(&ar->conf_mutex);
5525 spin_lock_bh(&ar->data_lock);
5526 ar->scan.roc_notify = false;
5527 spin_unlock_bh(&ar->data_lock);
5529 ath10k_scan_abort(ar);
5531 mutex_unlock(&ar->conf_mutex);
5533 cancel_delayed_work_sync(&ar->scan.timeout);
5539 * Both RTS and Fragmentation threshold are interface-specific
5540 * in ath10k, but device-specific in mac80211.
5543 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5545 struct ath10k *ar = hw->priv;
5546 struct ath10k_vif *arvif;
5549 mutex_lock(&ar->conf_mutex);
5550 list_for_each_entry(arvif, &ar->arvifs, list) {
5551 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
5552 arvif->vdev_id, value);
5554 ret = ath10k_mac_set_rts(arvif, value);
5556 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
5557 arvif->vdev_id, ret);
5561 mutex_unlock(&ar->conf_mutex);
5566 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5567 u32 queues, bool drop)
5569 struct ath10k *ar = hw->priv;
5573 /* mac80211 doesn't care if we really xmit queued frames or not
5574 * we'll collect those frames either way if we stop/delete vdevs */
5578 mutex_lock(&ar->conf_mutex);
5580 if (ar->state == ATH10K_STATE_WEDGED)
5583 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
5586 spin_lock_bh(&ar->htt.tx_lock);
5587 empty = (ar->htt.num_pending_tx == 0);
5588 spin_unlock_bh(&ar->htt.tx_lock);
5590 skip = (ar->state == ATH10K_STATE_WEDGED) ||
5591 test_bit(ATH10K_FLAG_CRASH_FLUSH,
5595 }), ATH10K_FLUSH_TIMEOUT_HZ);
5597 if (time_left == 0 || skip)
5598 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
5599 skip, ar->state, time_left);
5602 mutex_unlock(&ar->conf_mutex);
5605 /* TODO: Implement this function properly
5606 * For now it is needed to reply to Probe Requests in IBSS mode.
5607 * Propably we need this information from FW.
5609 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
5614 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
5615 enum ieee80211_reconfig_type reconfig_type)
5617 struct ath10k *ar = hw->priv;
5619 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5622 mutex_lock(&ar->conf_mutex);
5624 /* If device failed to restart it will be in a different state, e.g.
5625 * ATH10K_STATE_WEDGED */
5626 if (ar->state == ATH10K_STATE_RESTARTED) {
5627 ath10k_info(ar, "device successfully recovered\n");
5628 ar->state = ATH10K_STATE_ON;
5629 ieee80211_wake_queues(ar->hw);
5632 mutex_unlock(&ar->conf_mutex);
5635 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
5636 struct survey_info *survey)
5638 struct ath10k *ar = hw->priv;
5639 struct ieee80211_supported_band *sband;
5640 struct survey_info *ar_survey = &ar->survey[idx];
5643 mutex_lock(&ar->conf_mutex);
5645 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
5646 if (sband && idx >= sband->n_channels) {
5647 idx -= sband->n_channels;
5652 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
5654 if (!sband || idx >= sband->n_channels) {
5659 spin_lock_bh(&ar->data_lock);
5660 memcpy(survey, ar_survey, sizeof(*survey));
5661 spin_unlock_bh(&ar->data_lock);
5663 survey->channel = &sband->channels[idx];
5665 if (ar->rx_channel == survey->channel)
5666 survey->filled |= SURVEY_INFO_IN_USE;
5669 mutex_unlock(&ar->conf_mutex);
5674 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
5675 enum ieee80211_band band,
5676 const struct cfg80211_bitrate_mask *mask)
5681 num_rates += hweight32(mask->control[band].legacy);
5683 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5684 num_rates += hweight8(mask->control[band].ht_mcs[i]);
5686 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
5687 num_rates += hweight16(mask->control[band].vht_mcs[i]);
5689 return num_rates == 1;
5693 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
5694 enum ieee80211_band band,
5695 const struct cfg80211_bitrate_mask *mask,
5698 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5699 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5701 u8 vht_nss_mask = 0;
5704 if (mask->control[band].legacy)
5707 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5708 if (mask->control[band].ht_mcs[i] == 0)
5710 else if (mask->control[band].ht_mcs[i] ==
5711 sband->ht_cap.mcs.rx_mask[i])
5712 ht_nss_mask |= BIT(i);
5717 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5718 if (mask->control[band].vht_mcs[i] == 0)
5720 else if (mask->control[band].vht_mcs[i] ==
5721 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5722 vht_nss_mask |= BIT(i);
5727 if (ht_nss_mask != vht_nss_mask)
5730 if (ht_nss_mask == 0)
5733 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5736 *nss = fls(ht_nss_mask);
5742 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
5743 enum ieee80211_band band,
5744 const struct cfg80211_bitrate_mask *mask,
5747 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5754 if (hweight32(mask->control[band].legacy) == 1) {
5755 rate_idx = ffs(mask->control[band].legacy) - 1;
5757 hw_rate = sband->bitrates[rate_idx].hw_value;
5758 bitrate = sband->bitrates[rate_idx].bitrate;
5760 if (ath10k_mac_bitrate_is_cck(bitrate))
5761 preamble = WMI_RATE_PREAMBLE_CCK;
5763 preamble = WMI_RATE_PREAMBLE_OFDM;
5766 *rate = preamble << 6 |
5773 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5774 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
5776 *rate = WMI_RATE_PREAMBLE_HT << 6 |
5778 (ffs(mask->control[band].ht_mcs[i]) - 1);
5784 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5785 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
5787 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
5789 (ffs(mask->control[band].vht_mcs[i]) - 1);
5798 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
5799 u8 rate, u8 nss, u8 sgi)
5801 struct ath10k *ar = arvif->ar;
5805 lockdep_assert_held(&ar->conf_mutex);
5807 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5808 arvif->vdev_id, rate, nss, sgi);
5810 vdev_param = ar->wmi.vdev_param->fixed_rate;
5811 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
5813 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
5818 vdev_param = ar->wmi.vdev_param->nss;
5819 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
5821 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
5825 vdev_param = ar->wmi.vdev_param->sgi;
5826 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
5828 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
5836 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
5837 enum ieee80211_band band,
5838 const struct cfg80211_bitrate_mask *mask)
5843 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
5844 * to express all VHT MCS rate masks. Effectively only the following
5845 * ranges can be used: none, 0-7, 0-8 and 0-9.
5847 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5848 vht_mcs = mask->control[band].vht_mcs[i];
5857 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
5865 static void ath10k_mac_set_bitrate_mask_iter(void *data,
5866 struct ieee80211_sta *sta)
5868 struct ath10k_vif *arvif = data;
5869 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5870 struct ath10k *ar = arvif->ar;
5872 if (arsta->arvif != arvif)
5875 spin_lock_bh(&ar->data_lock);
5876 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5877 spin_unlock_bh(&ar->data_lock);
5879 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5882 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5883 struct ieee80211_vif *vif,
5884 const struct cfg80211_bitrate_mask *mask)
5886 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5887 struct cfg80211_chan_def def;
5888 struct ath10k *ar = arvif->ar;
5889 enum ieee80211_band band;
5890 const u8 *ht_mcs_mask;
5891 const u16 *vht_mcs_mask;
5898 if (ath10k_mac_vif_chan(vif, &def))
5901 band = def.chan->band;
5902 ht_mcs_mask = mask->control[band].ht_mcs;
5903 vht_mcs_mask = mask->control[band].vht_mcs;
5905 sgi = mask->control[band].gi;
5906 if (sgi == NL80211_TXRATE_FORCE_LGI)
5909 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
5910 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
5913 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
5914 arvif->vdev_id, ret);
5917 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5919 rate = WMI_FIXED_RATE_NONE;
5922 rate = WMI_FIXED_RATE_NONE;
5923 nss = min(ar->num_rf_chains,
5924 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5925 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5927 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
5930 mutex_lock(&ar->conf_mutex);
5932 arvif->bitrate_mask = *mask;
5933 ieee80211_iterate_stations_atomic(ar->hw,
5934 ath10k_mac_set_bitrate_mask_iter,
5937 mutex_unlock(&ar->conf_mutex);
5940 mutex_lock(&ar->conf_mutex);
5942 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi);
5944 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
5945 arvif->vdev_id, ret);
5950 mutex_unlock(&ar->conf_mutex);
5955 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
5956 struct ieee80211_vif *vif,
5957 struct ieee80211_sta *sta,
5960 struct ath10k *ar = hw->priv;
5961 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5964 spin_lock_bh(&ar->data_lock);
5966 ath10k_dbg(ar, ATH10K_DBG_MAC,
5967 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
5968 sta->addr, changed, sta->bandwidth, sta->rx_nss,
5971 if (changed & IEEE80211_RC_BW_CHANGED) {
5972 bw = WMI_PEER_CHWIDTH_20MHZ;
5974 switch (sta->bandwidth) {
5975 case IEEE80211_STA_RX_BW_20:
5976 bw = WMI_PEER_CHWIDTH_20MHZ;
5978 case IEEE80211_STA_RX_BW_40:
5979 bw = WMI_PEER_CHWIDTH_40MHZ;
5981 case IEEE80211_STA_RX_BW_80:
5982 bw = WMI_PEER_CHWIDTH_80MHZ;
5984 case IEEE80211_STA_RX_BW_160:
5985 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
5986 sta->bandwidth, sta->addr);
5987 bw = WMI_PEER_CHWIDTH_20MHZ;
5994 if (changed & IEEE80211_RC_NSS_CHANGED)
5995 arsta->nss = sta->rx_nss;
5997 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5998 smps = WMI_PEER_SMPS_PS_NONE;
6000 switch (sta->smps_mode) {
6001 case IEEE80211_SMPS_AUTOMATIC:
6002 case IEEE80211_SMPS_OFF:
6003 smps = WMI_PEER_SMPS_PS_NONE;
6005 case IEEE80211_SMPS_STATIC:
6006 smps = WMI_PEER_SMPS_STATIC;
6008 case IEEE80211_SMPS_DYNAMIC:
6009 smps = WMI_PEER_SMPS_DYNAMIC;
6011 case IEEE80211_SMPS_NUM_MODES:
6012 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6013 sta->smps_mode, sta->addr);
6014 smps = WMI_PEER_SMPS_PS_NONE;
6021 arsta->changed |= changed;
6023 spin_unlock_bh(&ar->data_lock);
6025 ieee80211_queue_work(hw, &arsta->update_wk);
6028 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6031 * FIXME: Return 0 for time being. Need to figure out whether FW
6032 * has the API to fetch 64-bit local TSF
6038 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6039 struct ieee80211_vif *vif,
6040 enum ieee80211_ampdu_mlme_action action,
6041 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
6044 struct ath10k *ar = hw->priv;
6045 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6047 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6048 arvif->vdev_id, sta->addr, tid, action);
6051 case IEEE80211_AMPDU_RX_START:
6052 case IEEE80211_AMPDU_RX_STOP:
6053 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6054 * creation/removal. Do we need to verify this?
6057 case IEEE80211_AMPDU_TX_START:
6058 case IEEE80211_AMPDU_TX_STOP_CONT:
6059 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6060 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6061 case IEEE80211_AMPDU_TX_OPERATIONAL:
6062 /* Firmware offloads Tx aggregation entirely so deny mac80211
6063 * Tx aggregation requests.
6072 ath10k_mac_update_rx_channel(struct ath10k *ar,
6073 struct ieee80211_chanctx_conf *ctx,
6074 struct ieee80211_vif_chanctx_switch *vifs,
6077 struct cfg80211_chan_def *def = NULL;
6079 /* Both locks are required because ar->rx_channel is modified. This
6080 * allows readers to hold either lock.
6082 lockdep_assert_held(&ar->conf_mutex);
6083 lockdep_assert_held(&ar->data_lock);
6085 WARN_ON(ctx && vifs);
6086 WARN_ON(vifs && n_vifs != 1);
6088 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6089 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6090 * ppdu on Rx may reduce performance on low-end systems. It should be
6091 * possible to make tables/hashmaps to speed the lookup up (be vary of
6092 * cpu data cache lines though regarding sizes) but to keep the initial
6093 * implementation simple and less intrusive fallback to the slow lookup
6094 * only for multi-channel cases. Single-channel cases will remain to
6095 * use the old channel derival and thus performance should not be
6099 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
6100 ieee80211_iter_chan_contexts_atomic(ar->hw,
6101 ath10k_mac_get_any_chandef_iter,
6105 def = &vifs[0].new_ctx->def;
6107 ar->rx_channel = def->chan;
6108 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6109 ar->rx_channel = ctx->def.chan;
6111 ar->rx_channel = NULL;
6117 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6118 struct ieee80211_chanctx_conf *ctx)
6120 struct ath10k *ar = hw->priv;
6122 ath10k_dbg(ar, ATH10K_DBG_MAC,
6123 "mac chanctx add freq %hu width %d ptr %p\n",
6124 ctx->def.chan->center_freq, ctx->def.width, ctx);
6126 mutex_lock(&ar->conf_mutex);
6128 spin_lock_bh(&ar->data_lock);
6129 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
6130 spin_unlock_bh(&ar->data_lock);
6132 ath10k_recalc_radar_detection(ar);
6133 ath10k_monitor_recalc(ar);
6135 mutex_unlock(&ar->conf_mutex);
6141 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6142 struct ieee80211_chanctx_conf *ctx)
6144 struct ath10k *ar = hw->priv;
6146 ath10k_dbg(ar, ATH10K_DBG_MAC,
6147 "mac chanctx remove freq %hu width %d ptr %p\n",
6148 ctx->def.chan->center_freq, ctx->def.width, ctx);
6150 mutex_lock(&ar->conf_mutex);
6152 spin_lock_bh(&ar->data_lock);
6153 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
6154 spin_unlock_bh(&ar->data_lock);
6156 ath10k_recalc_radar_detection(ar);
6157 ath10k_monitor_recalc(ar);
6159 mutex_unlock(&ar->conf_mutex);
6163 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6164 struct ieee80211_chanctx_conf *ctx,
6167 struct ath10k *ar = hw->priv;
6169 mutex_lock(&ar->conf_mutex);
6171 ath10k_dbg(ar, ATH10K_DBG_MAC,
6172 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6173 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
6175 /* This shouldn't really happen because channel switching should use
6176 * switch_vif_chanctx().
6178 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6181 ath10k_recalc_radar_detection(ar);
6183 /* FIXME: How to configure Rx chains properly? */
6185 /* No other actions are actually necessary. Firmware maintains channel
6186 * definitions per vdev internally and there's no host-side channel
6187 * context abstraction to configure, e.g. channel width.
6191 mutex_unlock(&ar->conf_mutex);
6195 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
6196 struct ieee80211_vif *vif,
6197 struct ieee80211_chanctx_conf *ctx)
6199 struct ath10k *ar = hw->priv;
6200 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6203 mutex_lock(&ar->conf_mutex);
6205 ath10k_dbg(ar, ATH10K_DBG_MAC,
6206 "mac chanctx assign ptr %p vdev_id %i\n",
6207 ctx, arvif->vdev_id);
6209 if (WARN_ON(arvif->is_started)) {
6210 mutex_unlock(&ar->conf_mutex);
6214 ret = ath10k_vdev_start(arvif, &ctx->def);
6216 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
6217 arvif->vdev_id, vif->addr,
6218 ctx->def.chan->center_freq, ret);
6222 arvif->is_started = true;
6224 ret = ath10k_mac_vif_setup_ps(arvif);
6226 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
6227 arvif->vdev_id, ret);
6231 if (vif->type == NL80211_IFTYPE_MONITOR) {
6232 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
6234 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
6235 arvif->vdev_id, ret);
6239 arvif->is_up = true;
6242 mutex_unlock(&ar->conf_mutex);
6246 ath10k_vdev_stop(arvif);
6247 arvif->is_started = false;
6248 ath10k_mac_vif_setup_ps(arvif);
6251 mutex_unlock(&ar->conf_mutex);
6256 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
6257 struct ieee80211_vif *vif,
6258 struct ieee80211_chanctx_conf *ctx)
6260 struct ath10k *ar = hw->priv;
6261 struct ath10k_vif *arvif = (void *)vif->drv_priv;
6264 mutex_lock(&ar->conf_mutex);
6266 ath10k_dbg(ar, ATH10K_DBG_MAC,
6267 "mac chanctx unassign ptr %p vdev_id %i\n",
6268 ctx, arvif->vdev_id);
6270 WARN_ON(!arvif->is_started);
6272 if (vif->type == NL80211_IFTYPE_MONITOR) {
6273 WARN_ON(!arvif->is_up);
6275 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6277 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
6278 arvif->vdev_id, ret);
6280 arvif->is_up = false;
6283 ret = ath10k_vdev_stop(arvif);
6285 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
6286 arvif->vdev_id, ret);
6288 arvif->is_started = false;
6290 mutex_unlock(&ar->conf_mutex);
6294 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
6295 struct ieee80211_vif_chanctx_switch *vifs,
6297 enum ieee80211_chanctx_switch_mode mode)
6299 struct ath10k *ar = hw->priv;
6300 struct ath10k_vif *arvif;
6304 mutex_lock(&ar->conf_mutex);
6306 ath10k_dbg(ar, ATH10K_DBG_MAC,
6307 "mac chanctx switch n_vifs %d mode %d\n",
6310 /* First stop monitor interface. Some FW versions crash if there's a
6311 * lone monitor interface.
6313 if (ar->monitor_started)
6314 ath10k_monitor_stop(ar);
6316 for (i = 0; i < n_vifs; i++) {
6317 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6319 ath10k_dbg(ar, ATH10K_DBG_MAC,
6320 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6322 vifs[i].old_ctx->def.chan->center_freq,
6323 vifs[i].new_ctx->def.chan->center_freq,
6324 vifs[i].old_ctx->def.width,
6325 vifs[i].new_ctx->def.width);
6327 if (WARN_ON(!arvif->is_started))
6330 if (WARN_ON(!arvif->is_up))
6333 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6335 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6336 arvif->vdev_id, ret);
6341 /* All relevant vdevs are downed and associated channel resources
6342 * should be available for the channel switch now.
6345 spin_lock_bh(&ar->data_lock);
6346 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
6347 spin_unlock_bh(&ar->data_lock);
6349 for (i = 0; i < n_vifs; i++) {
6350 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6352 if (WARN_ON(!arvif->is_started))
6355 if (WARN_ON(!arvif->is_up))
6358 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6360 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6363 ret = ath10k_mac_setup_prb_tmpl(arvif);
6365 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6368 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6370 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6371 arvif->vdev_id, ret);
6375 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6378 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6379 arvif->vdev_id, ret);
6384 ath10k_monitor_recalc(ar);
6386 mutex_unlock(&ar->conf_mutex);
6390 static const struct ieee80211_ops ath10k_ops = {
6392 .start = ath10k_start,
6393 .stop = ath10k_stop,
6394 .config = ath10k_config,
6395 .add_interface = ath10k_add_interface,
6396 .remove_interface = ath10k_remove_interface,
6397 .configure_filter = ath10k_configure_filter,
6398 .bss_info_changed = ath10k_bss_info_changed,
6399 .hw_scan = ath10k_hw_scan,
6400 .cancel_hw_scan = ath10k_cancel_hw_scan,
6401 .set_key = ath10k_set_key,
6402 .set_default_unicast_key = ath10k_set_default_unicast_key,
6403 .sta_state = ath10k_sta_state,
6404 .conf_tx = ath10k_conf_tx,
6405 .remain_on_channel = ath10k_remain_on_channel,
6406 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
6407 .set_rts_threshold = ath10k_set_rts_threshold,
6408 .flush = ath10k_flush,
6409 .tx_last_beacon = ath10k_tx_last_beacon,
6410 .set_antenna = ath10k_set_antenna,
6411 .get_antenna = ath10k_get_antenna,
6412 .reconfig_complete = ath10k_reconfig_complete,
6413 .get_survey = ath10k_get_survey,
6414 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
6415 .sta_rc_update = ath10k_sta_rc_update,
6416 .get_tsf = ath10k_get_tsf,
6417 .ampdu_action = ath10k_ampdu_action,
6418 .get_et_sset_count = ath10k_debug_get_et_sset_count,
6419 .get_et_stats = ath10k_debug_get_et_stats,
6420 .get_et_strings = ath10k_debug_get_et_strings,
6421 .add_chanctx = ath10k_mac_op_add_chanctx,
6422 .remove_chanctx = ath10k_mac_op_remove_chanctx,
6423 .change_chanctx = ath10k_mac_op_change_chanctx,
6424 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
6425 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
6426 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
6428 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
6431 .suspend = ath10k_wow_op_suspend,
6432 .resume = ath10k_wow_op_resume,
6434 #ifdef CONFIG_MAC80211_DEBUGFS
6435 .sta_add_debugfs = ath10k_sta_add_debugfs,
6439 #define CHAN2G(_channel, _freq, _flags) { \
6440 .band = IEEE80211_BAND_2GHZ, \
6441 .hw_value = (_channel), \
6442 .center_freq = (_freq), \
6443 .flags = (_flags), \
6444 .max_antenna_gain = 0, \
6448 #define CHAN5G(_channel, _freq, _flags) { \
6449 .band = IEEE80211_BAND_5GHZ, \
6450 .hw_value = (_channel), \
6451 .center_freq = (_freq), \
6452 .flags = (_flags), \
6453 .max_antenna_gain = 0, \
6457 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
6467 CHAN2G(10, 2457, 0),
6468 CHAN2G(11, 2462, 0),
6469 CHAN2G(12, 2467, 0),
6470 CHAN2G(13, 2472, 0),
6471 CHAN2G(14, 2484, 0),
6474 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
6475 CHAN5G(36, 5180, 0),
6476 CHAN5G(40, 5200, 0),
6477 CHAN5G(44, 5220, 0),
6478 CHAN5G(48, 5240, 0),
6479 CHAN5G(52, 5260, 0),
6480 CHAN5G(56, 5280, 0),
6481 CHAN5G(60, 5300, 0),
6482 CHAN5G(64, 5320, 0),
6483 CHAN5G(100, 5500, 0),
6484 CHAN5G(104, 5520, 0),
6485 CHAN5G(108, 5540, 0),
6486 CHAN5G(112, 5560, 0),
6487 CHAN5G(116, 5580, 0),
6488 CHAN5G(120, 5600, 0),
6489 CHAN5G(124, 5620, 0),
6490 CHAN5G(128, 5640, 0),
6491 CHAN5G(132, 5660, 0),
6492 CHAN5G(136, 5680, 0),
6493 CHAN5G(140, 5700, 0),
6494 CHAN5G(144, 5720, 0),
6495 CHAN5G(149, 5745, 0),
6496 CHAN5G(153, 5765, 0),
6497 CHAN5G(157, 5785, 0),
6498 CHAN5G(161, 5805, 0),
6499 CHAN5G(165, 5825, 0),
6502 struct ath10k *ath10k_mac_create(size_t priv_size)
6504 struct ieee80211_hw *hw;
6507 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
6517 void ath10k_mac_destroy(struct ath10k *ar)
6519 ieee80211_free_hw(ar->hw);
6522 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
6525 .types = BIT(NL80211_IFTYPE_STATION)
6526 | BIT(NL80211_IFTYPE_P2P_CLIENT)
6530 .types = BIT(NL80211_IFTYPE_P2P_GO)
6534 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
6538 .types = BIT(NL80211_IFTYPE_AP)
6542 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
6545 .types = BIT(NL80211_IFTYPE_AP)
6549 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
6551 .limits = ath10k_if_limits,
6552 .n_limits = ARRAY_SIZE(ath10k_if_limits),
6553 .max_interfaces = 8,
6554 .num_different_channels = 1,
6555 .beacon_int_infra_match = true,
6559 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
6561 .limits = ath10k_10x_if_limits,
6562 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
6563 .max_interfaces = 8,
6564 .num_different_channels = 1,
6565 .beacon_int_infra_match = true,
6566 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6567 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6568 BIT(NL80211_CHAN_WIDTH_20) |
6569 BIT(NL80211_CHAN_WIDTH_40) |
6570 BIT(NL80211_CHAN_WIDTH_80),
6575 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
6578 .types = BIT(NL80211_IFTYPE_STATION),
6582 .types = BIT(NL80211_IFTYPE_AP) |
6583 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6584 BIT(NL80211_IFTYPE_P2P_GO),
6588 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6592 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
6595 .types = BIT(NL80211_IFTYPE_STATION),
6599 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
6603 .types = BIT(NL80211_IFTYPE_AP) |
6604 BIT(NL80211_IFTYPE_P2P_GO),
6608 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
6612 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
6615 .types = BIT(NL80211_IFTYPE_STATION),
6619 .types = BIT(NL80211_IFTYPE_ADHOC),
6623 /* FIXME: This is not thouroughly tested. These combinations may over- or
6624 * underestimate hw/fw capabilities.
6626 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
6628 .limits = ath10k_tlv_if_limit,
6629 .num_different_channels = 1,
6630 .max_interfaces = 4,
6631 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6634 .limits = ath10k_tlv_if_limit_ibss,
6635 .num_different_channels = 1,
6636 .max_interfaces = 2,
6637 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6641 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
6643 .limits = ath10k_tlv_if_limit,
6644 .num_different_channels = 1,
6645 .max_interfaces = 4,
6646 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
6649 .limits = ath10k_tlv_qcs_if_limit,
6650 .num_different_channels = 2,
6651 .max_interfaces = 4,
6652 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
6655 .limits = ath10k_tlv_if_limit_ibss,
6656 .num_different_channels = 1,
6657 .max_interfaces = 2,
6658 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
6662 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
6665 .types = BIT(NL80211_IFTYPE_STATION),
6669 .types = BIT(NL80211_IFTYPE_AP)
6673 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
6675 .limits = ath10k_10_4_if_limits,
6676 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
6677 .max_interfaces = 16,
6678 .num_different_channels = 1,
6679 .beacon_int_infra_match = true,
6680 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
6681 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6682 BIT(NL80211_CHAN_WIDTH_20) |
6683 BIT(NL80211_CHAN_WIDTH_40) |
6684 BIT(NL80211_CHAN_WIDTH_80),
6689 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
6691 struct ieee80211_sta_vht_cap vht_cap = {0};
6696 vht_cap.vht_supported = 1;
6697 vht_cap.cap = ar->vht_cap_info;
6699 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
6700 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
6701 val = ar->num_rf_chains - 1;
6702 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
6703 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
6708 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
6709 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
6710 val = ar->num_rf_chains - 1;
6711 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
6712 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
6718 for (i = 0; i < 8; i++) {
6719 if (i < ar->num_rf_chains)
6720 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
6722 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
6725 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
6726 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
6731 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
6734 struct ieee80211_sta_ht_cap ht_cap = {0};
6736 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
6739 ht_cap.ht_supported = 1;
6740 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
6741 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
6742 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
6743 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
6744 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
6746 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
6747 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
6749 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
6750 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
6752 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
6755 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
6756 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
6761 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
6762 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
6764 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
6767 stbc = ar->ht_cap_info;
6768 stbc &= WMI_HT_CAP_RX_STBC;
6769 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
6770 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
6771 stbc &= IEEE80211_HT_CAP_RX_STBC;
6776 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
6777 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
6779 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
6780 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
6782 /* max AMSDU is implicitly taken from vht_cap_info */
6783 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
6784 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
6786 for (i = 0; i < ar->num_rf_chains; i++)
6787 ht_cap.mcs.rx_mask[i] = 0xFF;
6789 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
6794 static void ath10k_get_arvif_iter(void *data, u8 *mac,
6795 struct ieee80211_vif *vif)
6797 struct ath10k_vif_iter *arvif_iter = data;
6798 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6800 if (arvif->vdev_id == arvif_iter->vdev_id)
6801 arvif_iter->arvif = arvif;
6804 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
6806 struct ath10k_vif_iter arvif_iter;
6809 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
6810 arvif_iter.vdev_id = vdev_id;
6812 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
6813 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6815 ath10k_get_arvif_iter,
6817 if (!arvif_iter.arvif) {
6818 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
6822 return arvif_iter.arvif;
6825 int ath10k_mac_register(struct ath10k *ar)
6827 static const u32 cipher_suites[] = {
6828 WLAN_CIPHER_SUITE_WEP40,
6829 WLAN_CIPHER_SUITE_WEP104,
6830 WLAN_CIPHER_SUITE_TKIP,
6831 WLAN_CIPHER_SUITE_CCMP,
6832 WLAN_CIPHER_SUITE_AES_CMAC,
6834 struct ieee80211_supported_band *band;
6835 struct ieee80211_sta_vht_cap vht_cap;
6836 struct ieee80211_sta_ht_cap ht_cap;
6840 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6842 SET_IEEE80211_DEV(ar->hw, ar->dev);
6844 ht_cap = ath10k_get_ht_cap(ar);
6845 vht_cap = ath10k_create_vht_cap(ar);
6847 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
6848 ARRAY_SIZE(ath10k_5ghz_channels)) !=
6851 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
6852 channels = kmemdup(ath10k_2ghz_channels,
6853 sizeof(ath10k_2ghz_channels),
6860 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
6861 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
6862 band->channels = channels;
6863 band->n_bitrates = ath10k_g_rates_size;
6864 band->bitrates = ath10k_g_rates;
6865 band->ht_cap = ht_cap;
6867 /* Enable the VHT support at 2.4 GHz */
6868 band->vht_cap = vht_cap;
6870 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
6873 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
6874 channels = kmemdup(ath10k_5ghz_channels,
6875 sizeof(ath10k_5ghz_channels),
6882 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
6883 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
6884 band->channels = channels;
6885 band->n_bitrates = ath10k_a_rates_size;
6886 band->bitrates = ath10k_a_rates;
6887 band->ht_cap = ht_cap;
6888 band->vht_cap = vht_cap;
6889 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
6892 ar->hw->wiphy->interface_modes =
6893 BIT(NL80211_IFTYPE_STATION) |
6894 BIT(NL80211_IFTYPE_AP);
6896 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
6897 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
6899 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
6900 ar->hw->wiphy->interface_modes |=
6901 BIT(NL80211_IFTYPE_P2P_DEVICE) |
6902 BIT(NL80211_IFTYPE_P2P_CLIENT) |
6903 BIT(NL80211_IFTYPE_P2P_GO);
6905 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6906 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6907 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6908 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6909 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6910 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6911 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6912 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
6913 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6914 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6915 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6916 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6917 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6918 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
6920 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
6921 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
6923 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6924 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
6926 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
6927 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
6929 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
6930 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6931 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
6934 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6935 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6937 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
6938 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
6940 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
6942 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
6943 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
6945 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
6946 * that userspace (e.g. wpa_supplicant/hostapd) can generate
6947 * correct Probe Responses. This is more of a hack advert..
6949 ar->hw->wiphy->probe_resp_offload |=
6950 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
6951 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
6952 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
6955 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
6956 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
6958 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6959 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
6960 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6962 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
6963 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
6965 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6967 ret = ath10k_wow_init(ar);
6969 ath10k_warn(ar, "failed to init wow: %d\n", ret);
6973 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
6976 * on LL hardware queues are managed entirely by the FW
6977 * so we only advertise to mac we can do the queues thing
6979 ar->hw->queues = IEEE80211_MAX_QUEUES;
6981 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
6982 * something that vdev_ids can't reach so that we don't stop the queue
6985 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
6987 switch (ar->wmi.op_version) {
6988 case ATH10K_FW_WMI_OP_VERSION_MAIN:
6989 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
6990 ar->hw->wiphy->n_iface_combinations =
6991 ARRAY_SIZE(ath10k_if_comb);
6992 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
6994 case ATH10K_FW_WMI_OP_VERSION_TLV:
6995 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
6996 ar->hw->wiphy->iface_combinations =
6997 ath10k_tlv_qcs_if_comb;
6998 ar->hw->wiphy->n_iface_combinations =
6999 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7001 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7002 ar->hw->wiphy->n_iface_combinations =
7003 ARRAY_SIZE(ath10k_tlv_if_comb);
7005 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7007 case ATH10K_FW_WMI_OP_VERSION_10_1:
7008 case ATH10K_FW_WMI_OP_VERSION_10_2:
7009 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7010 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7011 ar->hw->wiphy->n_iface_combinations =
7012 ARRAY_SIZE(ath10k_10x_if_comb);
7014 case ATH10K_FW_WMI_OP_VERSION_10_4:
7015 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7016 ar->hw->wiphy->n_iface_combinations =
7017 ARRAY_SIZE(ath10k_10_4_if_comb);
7019 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7020 case ATH10K_FW_WMI_OP_VERSION_MAX:
7026 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7027 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7029 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7030 /* Init ath dfs pattern detector */
7031 ar->ath_common.debug_mask = ATH_DBG_DFS;
7032 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7035 if (!ar->dfs_detector)
7036 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
7039 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7040 ath10k_reg_notifier);
7042 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
7046 ar->hw->wiphy->cipher_suites = cipher_suites;
7047 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7049 ret = ieee80211_register_hw(ar->hw);
7051 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
7055 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7056 ret = regulatory_hint(ar->hw->wiphy,
7057 ar->ath_common.regulatory.alpha2);
7059 goto err_unregister;
7065 ieee80211_unregister_hw(ar->hw);
7067 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7068 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7073 void ath10k_mac_unregister(struct ath10k *ar)
7075 ieee80211_unregister_hw(ar->hw);
7077 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7078 ar->dfs_detector->exit(ar->dfs_detector);
7080 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7081 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7083 SET_IEEE80211_DEV(ar->hw, NULL);