2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
39 static struct ieee80211_rate ath10k_rates[] = {
41 .hw_value = ATH10K_HW_RATE_CCK_LP_1M },
43 .hw_value = ATH10K_HW_RATE_CCK_LP_2M,
44 .hw_value_short = ATH10K_HW_RATE_CCK_SP_2M,
45 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
47 .hw_value = ATH10K_HW_RATE_CCK_LP_5_5M,
48 .hw_value_short = ATH10K_HW_RATE_CCK_SP_5_5M,
49 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
51 .hw_value = ATH10K_HW_RATE_CCK_LP_11M,
52 .hw_value_short = ATH10K_HW_RATE_CCK_SP_11M,
53 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
55 { .bitrate = 60, .hw_value = ATH10K_HW_RATE_OFDM_6M },
56 { .bitrate = 90, .hw_value = ATH10K_HW_RATE_OFDM_9M },
57 { .bitrate = 120, .hw_value = ATH10K_HW_RATE_OFDM_12M },
58 { .bitrate = 180, .hw_value = ATH10K_HW_RATE_OFDM_18M },
59 { .bitrate = 240, .hw_value = ATH10K_HW_RATE_OFDM_24M },
60 { .bitrate = 360, .hw_value = ATH10K_HW_RATE_OFDM_36M },
61 { .bitrate = 480, .hw_value = ATH10K_HW_RATE_OFDM_48M },
62 { .bitrate = 540, .hw_value = ATH10K_HW_RATE_OFDM_54M },
65 #define ATH10K_MAC_FIRST_OFDM_RATE_IDX 4
67 #define ath10k_a_rates (ath10k_rates + ATH10K_MAC_FIRST_OFDM_RATE_IDX)
68 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - \
69 ATH10K_MAC_FIRST_OFDM_RATE_IDX)
70 #define ath10k_g_rates (ath10k_rates + 0)
71 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
73 static bool ath10k_mac_bitrate_is_cck(int bitrate)
86 static u8 ath10k_mac_bitrate_to_rate(int bitrate)
88 return DIV_ROUND_UP(bitrate, 5) |
89 (ath10k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
92 u8 ath10k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
95 const struct ieee80211_rate *rate;
98 for (i = 0; i < sband->n_bitrates; i++) {
99 rate = &sband->bitrates[i];
101 if (ath10k_mac_bitrate_is_cck(rate->bitrate) != cck)
104 if (rate->hw_value == hw_rate)
106 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
107 rate->hw_value_short == hw_rate)
114 u8 ath10k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
119 for (i = 0; i < sband->n_bitrates; i++)
120 if (sband->bitrates[i].bitrate == bitrate)
126 static int ath10k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
128 switch ((mcs_map >> (2 * nss)) & 0x3) {
129 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
130 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
131 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
137 ath10k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
141 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
142 if (ht_mcs_mask[nss])
149 ath10k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
153 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
154 if (vht_mcs_mask[nss])
164 static int ath10k_send_key(struct ath10k_vif *arvif,
165 struct ieee80211_key_conf *key,
166 enum set_key_cmd cmd,
167 const u8 *macaddr, u32 flags)
169 struct ath10k *ar = arvif->ar;
170 struct wmi_vdev_install_key_arg arg = {
171 .vdev_id = arvif->vdev_id,
172 .key_idx = key->keyidx,
173 .key_len = key->keylen,
174 .key_data = key->key,
179 lockdep_assert_held(&arvif->ar->conf_mutex);
181 switch (key->cipher) {
182 case WLAN_CIPHER_SUITE_CCMP:
183 arg.key_cipher = WMI_CIPHER_AES_CCM;
184 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
186 case WLAN_CIPHER_SUITE_TKIP:
187 arg.key_cipher = WMI_CIPHER_TKIP;
188 arg.key_txmic_len = 8;
189 arg.key_rxmic_len = 8;
191 case WLAN_CIPHER_SUITE_WEP40:
192 case WLAN_CIPHER_SUITE_WEP104:
193 arg.key_cipher = WMI_CIPHER_WEP;
195 case WLAN_CIPHER_SUITE_AES_CMAC:
199 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
203 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
204 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
206 if (cmd == DISABLE_KEY) {
207 arg.key_cipher = WMI_CIPHER_NONE;
211 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
214 static int ath10k_install_key(struct ath10k_vif *arvif,
215 struct ieee80211_key_conf *key,
216 enum set_key_cmd cmd,
217 const u8 *macaddr, u32 flags)
219 struct ath10k *ar = arvif->ar;
221 unsigned long time_left;
223 lockdep_assert_held(&ar->conf_mutex);
225 reinit_completion(&ar->install_key_done);
227 if (arvif->nohwcrypt)
230 ret = ath10k_send_key(arvif, key, cmd, macaddr, flags);
234 time_left = wait_for_completion_timeout(&ar->install_key_done, 3 * HZ);
241 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
244 struct ath10k *ar = arvif->ar;
245 struct ath10k_peer *peer;
250 lockdep_assert_held(&ar->conf_mutex);
252 if (WARN_ON(arvif->vif->type != NL80211_IFTYPE_AP &&
253 arvif->vif->type != NL80211_IFTYPE_ADHOC &&
254 arvif->vif->type != NL80211_IFTYPE_MESH_POINT))
257 spin_lock_bh(&ar->data_lock);
258 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
259 spin_unlock_bh(&ar->data_lock);
264 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
265 if (arvif->wep_keys[i] == NULL)
268 switch (arvif->vif->type) {
269 case NL80211_IFTYPE_AP:
270 flags = WMI_KEY_PAIRWISE;
272 if (arvif->def_wep_key_idx == i)
273 flags |= WMI_KEY_TX_USAGE;
275 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
276 SET_KEY, addr, flags);
280 case NL80211_IFTYPE_ADHOC:
281 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
287 ret = ath10k_install_key(arvif, arvif->wep_keys[i],
288 SET_KEY, addr, WMI_KEY_GROUP);
297 spin_lock_bh(&ar->data_lock);
298 peer->keys[i] = arvif->wep_keys[i];
299 spin_unlock_bh(&ar->data_lock);
302 /* In some cases (notably with static WEP IBSS with multiple keys)
303 * multicast Tx becomes broken. Both pairwise and groupwise keys are
304 * installed already. Using WMI_KEY_TX_USAGE in different combinations
305 * didn't seem help. Using def_keyid vdev parameter seems to be
306 * effective so use that.
308 * FIXME: Revisit. Perhaps this can be done in a less hacky way.
310 if (arvif->vif->type != NL80211_IFTYPE_ADHOC)
313 if (arvif->def_wep_key_idx == -1)
316 ret = ath10k_wmi_vdev_set_param(arvif->ar,
318 arvif->ar->wmi.vdev_param->def_keyid,
319 arvif->def_wep_key_idx);
321 ath10k_warn(ar, "failed to re-set def wpa key idxon vdev %i: %d\n",
322 arvif->vdev_id, ret);
329 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
332 struct ath10k *ar = arvif->ar;
333 struct ath10k_peer *peer;
339 lockdep_assert_held(&ar->conf_mutex);
341 spin_lock_bh(&ar->data_lock);
342 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
343 spin_unlock_bh(&ar->data_lock);
348 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
349 if (peer->keys[i] == NULL)
352 /* key flags are not required to delete the key */
353 ret = ath10k_install_key(arvif, peer->keys[i],
354 DISABLE_KEY, addr, flags);
355 if (ret < 0 && first_errno == 0)
359 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
362 spin_lock_bh(&ar->data_lock);
363 peer->keys[i] = NULL;
364 spin_unlock_bh(&ar->data_lock);
370 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
373 struct ath10k_peer *peer;
376 lockdep_assert_held(&ar->data_lock);
378 /* We don't know which vdev this peer belongs to,
379 * since WMI doesn't give us that information.
381 * FIXME: multi-bss needs to be handled.
383 peer = ath10k_peer_find(ar, 0, addr);
387 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
388 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
395 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
396 struct ieee80211_key_conf *key)
398 struct ath10k *ar = arvif->ar;
399 struct ath10k_peer *peer;
406 lockdep_assert_held(&ar->conf_mutex);
409 /* since ath10k_install_key we can't hold data_lock all the
410 * time, so we try to remove the keys incrementally */
411 spin_lock_bh(&ar->data_lock);
413 list_for_each_entry(peer, &ar->peers, list) {
414 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
415 if (peer->keys[i] == key) {
416 ether_addr_copy(addr, peer->addr);
417 peer->keys[i] = NULL;
422 if (i < ARRAY_SIZE(peer->keys))
425 spin_unlock_bh(&ar->data_lock);
427 if (i == ARRAY_SIZE(peer->keys))
429 /* key flags are not required to delete the key */
430 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, flags);
431 if (ret < 0 && first_errno == 0)
435 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
442 static int ath10k_mac_vif_update_wep_key(struct ath10k_vif *arvif,
443 struct ieee80211_key_conf *key)
445 struct ath10k *ar = arvif->ar;
446 struct ath10k_peer *peer;
449 lockdep_assert_held(&ar->conf_mutex);
451 list_for_each_entry(peer, &ar->peers, list) {
452 if (!memcmp(peer->addr, arvif->vif->addr, ETH_ALEN))
455 if (!memcmp(peer->addr, arvif->bssid, ETH_ALEN))
458 if (peer->keys[key->keyidx] == key)
461 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vif vdev %i update key %i needs update\n",
462 arvif->vdev_id, key->keyidx);
464 ret = ath10k_install_peer_wep_keys(arvif, peer->addr);
466 ath10k_warn(ar, "failed to update wep keys on vdev %i for peer %pM: %d\n",
467 arvif->vdev_id, peer->addr, ret);
475 /*********************/
476 /* General utilities */
477 /*********************/
479 static inline enum wmi_phy_mode
480 chan_to_phymode(const struct cfg80211_chan_def *chandef)
482 enum wmi_phy_mode phymode = MODE_UNKNOWN;
484 switch (chandef->chan->band) {
485 case IEEE80211_BAND_2GHZ:
486 switch (chandef->width) {
487 case NL80211_CHAN_WIDTH_20_NOHT:
488 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
493 case NL80211_CHAN_WIDTH_20:
494 phymode = MODE_11NG_HT20;
496 case NL80211_CHAN_WIDTH_40:
497 phymode = MODE_11NG_HT40;
499 case NL80211_CHAN_WIDTH_5:
500 case NL80211_CHAN_WIDTH_10:
501 case NL80211_CHAN_WIDTH_80:
502 case NL80211_CHAN_WIDTH_80P80:
503 case NL80211_CHAN_WIDTH_160:
504 phymode = MODE_UNKNOWN;
508 case IEEE80211_BAND_5GHZ:
509 switch (chandef->width) {
510 case NL80211_CHAN_WIDTH_20_NOHT:
513 case NL80211_CHAN_WIDTH_20:
514 phymode = MODE_11NA_HT20;
516 case NL80211_CHAN_WIDTH_40:
517 phymode = MODE_11NA_HT40;
519 case NL80211_CHAN_WIDTH_80:
520 phymode = MODE_11AC_VHT80;
522 case NL80211_CHAN_WIDTH_5:
523 case NL80211_CHAN_WIDTH_10:
524 case NL80211_CHAN_WIDTH_80P80:
525 case NL80211_CHAN_WIDTH_160:
526 phymode = MODE_UNKNOWN;
534 WARN_ON(phymode == MODE_UNKNOWN);
538 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
541 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
542 * 0 for no restriction
551 switch (mpdudensity) {
557 /* Our lower layer calculations limit our precision to
573 int ath10k_mac_vif_chan(struct ieee80211_vif *vif,
574 struct cfg80211_chan_def *def)
576 struct ieee80211_chanctx_conf *conf;
579 conf = rcu_dereference(vif->chanctx_conf);
591 static void ath10k_mac_num_chanctxs_iter(struct ieee80211_hw *hw,
592 struct ieee80211_chanctx_conf *conf,
600 static int ath10k_mac_num_chanctxs(struct ath10k *ar)
604 ieee80211_iter_chan_contexts_atomic(ar->hw,
605 ath10k_mac_num_chanctxs_iter,
612 ath10k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
613 struct ieee80211_chanctx_conf *conf,
616 struct cfg80211_chan_def **def = data;
621 static int ath10k_peer_create(struct ath10k *ar,
622 struct ieee80211_vif *vif,
623 struct ieee80211_sta *sta,
626 enum wmi_peer_type peer_type)
628 struct ath10k_vif *arvif;
629 struct ath10k_peer *peer;
633 lockdep_assert_held(&ar->conf_mutex);
635 num_peers = ar->num_peers;
637 /* Each vdev consumes a peer entry as well */
638 list_for_each_entry(arvif, &ar->arvifs, list)
641 if (num_peers >= ar->max_num_peers)
644 ret = ath10k_wmi_peer_create(ar, vdev_id, addr, peer_type);
646 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
651 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
653 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
658 spin_lock_bh(&ar->data_lock);
660 peer = ath10k_peer_find(ar, vdev_id, addr);
662 ath10k_warn(ar, "failed to find peer %pM on vdev %i after creation\n",
664 ath10k_wmi_peer_delete(ar, vdev_id, addr);
665 spin_unlock_bh(&ar->data_lock);
672 spin_unlock_bh(&ar->data_lock);
679 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
681 struct ath10k *ar = arvif->ar;
685 param = ar->wmi.pdev_param->sta_kickout_th;
686 ret = ath10k_wmi_pdev_set_param(ar, param,
687 ATH10K_KICKOUT_THRESHOLD);
689 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
690 arvif->vdev_id, ret);
694 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
695 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
696 ATH10K_KEEPALIVE_MIN_IDLE);
698 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
699 arvif->vdev_id, ret);
703 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
704 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
705 ATH10K_KEEPALIVE_MAX_IDLE);
707 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
708 arvif->vdev_id, ret);
712 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
713 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
714 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
716 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
717 arvif->vdev_id, ret);
724 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
726 struct ath10k *ar = arvif->ar;
729 vdev_param = ar->wmi.vdev_param->rts_threshold;
730 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
733 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
737 lockdep_assert_held(&ar->conf_mutex);
739 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
743 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
752 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
754 struct ath10k_peer *peer, *tmp;
757 lockdep_assert_held(&ar->conf_mutex);
759 spin_lock_bh(&ar->data_lock);
760 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
761 if (peer->vdev_id != vdev_id)
764 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
765 peer->addr, vdev_id);
767 for_each_set_bit(peer_id, peer->peer_ids,
768 ATH10K_MAX_NUM_PEER_IDS) {
769 ar->peer_map[peer_id] = NULL;
772 list_del(&peer->list);
776 spin_unlock_bh(&ar->data_lock);
779 static void ath10k_peer_cleanup_all(struct ath10k *ar)
781 struct ath10k_peer *peer, *tmp;
783 lockdep_assert_held(&ar->conf_mutex);
785 spin_lock_bh(&ar->data_lock);
786 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
787 list_del(&peer->list);
790 spin_unlock_bh(&ar->data_lock);
793 ar->num_stations = 0;
796 static int ath10k_mac_tdls_peer_update(struct ath10k *ar, u32 vdev_id,
797 struct ieee80211_sta *sta,
798 enum wmi_tdls_peer_state state)
801 struct wmi_tdls_peer_update_cmd_arg arg = {};
802 struct wmi_tdls_peer_capab_arg cap = {};
803 struct wmi_channel_arg chan_arg = {};
805 lockdep_assert_held(&ar->conf_mutex);
807 arg.vdev_id = vdev_id;
808 arg.peer_state = state;
809 ether_addr_copy(arg.addr, sta->addr);
811 cap.peer_max_sp = sta->max_sp;
812 cap.peer_uapsd_queues = sta->uapsd_queues;
814 if (state == WMI_TDLS_PEER_STATE_CONNECTED &&
815 !sta->tdls_initiator)
816 cap.is_peer_responder = 1;
818 ret = ath10k_wmi_tdls_peer_update(ar, &arg, &cap, &chan_arg);
820 ath10k_warn(ar, "failed to update tdls peer %pM on vdev %i: %i\n",
821 arg.addr, vdev_id, ret);
828 /************************/
829 /* Interface management */
830 /************************/
832 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
834 struct ath10k *ar = arvif->ar;
836 lockdep_assert_held(&ar->data_lock);
841 if (!arvif->beacon_buf)
842 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
843 arvif->beacon->len, DMA_TO_DEVICE);
845 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
846 arvif->beacon_state != ATH10K_BEACON_SENT))
849 dev_kfree_skb_any(arvif->beacon);
851 arvif->beacon = NULL;
852 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
855 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
857 struct ath10k *ar = arvif->ar;
859 lockdep_assert_held(&ar->data_lock);
861 ath10k_mac_vif_beacon_free(arvif);
863 if (arvif->beacon_buf) {
864 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
865 arvif->beacon_buf, arvif->beacon_paddr);
866 arvif->beacon_buf = NULL;
870 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
872 unsigned long time_left;
874 lockdep_assert_held(&ar->conf_mutex);
876 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
879 time_left = wait_for_completion_timeout(&ar->vdev_setup_done,
880 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
887 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
889 struct cfg80211_chan_def *chandef = NULL;
890 struct ieee80211_channel *channel = NULL;
891 struct wmi_vdev_start_request_arg arg = {};
894 lockdep_assert_held(&ar->conf_mutex);
896 ieee80211_iter_chan_contexts_atomic(ar->hw,
897 ath10k_mac_get_any_chandef_iter,
899 if (WARN_ON_ONCE(!chandef))
902 channel = chandef->chan;
904 arg.vdev_id = vdev_id;
905 arg.channel.freq = channel->center_freq;
906 arg.channel.band_center_freq1 = chandef->center_freq1;
908 /* TODO setup this dynamically, what in case we
909 don't have any vifs? */
910 arg.channel.mode = chan_to_phymode(chandef);
911 arg.channel.chan_radar =
912 !!(channel->flags & IEEE80211_CHAN_RADAR);
914 arg.channel.min_power = 0;
915 arg.channel.max_power = channel->max_power * 2;
916 arg.channel.max_reg_power = channel->max_reg_power * 2;
917 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
919 reinit_completion(&ar->vdev_setup_done);
921 ret = ath10k_wmi_vdev_start(ar, &arg);
923 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
928 ret = ath10k_vdev_setup_sync(ar);
930 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
935 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
937 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
942 ar->monitor_vdev_id = vdev_id;
944 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
945 ar->monitor_vdev_id);
949 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
951 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
952 ar->monitor_vdev_id, ret);
957 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
961 lockdep_assert_held(&ar->conf_mutex);
963 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
965 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
966 ar->monitor_vdev_id, ret);
968 reinit_completion(&ar->vdev_setup_done);
970 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
972 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
973 ar->monitor_vdev_id, ret);
975 ret = ath10k_vdev_setup_sync(ar);
977 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
978 ar->monitor_vdev_id, ret);
980 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
981 ar->monitor_vdev_id);
985 static int ath10k_monitor_vdev_create(struct ath10k *ar)
989 lockdep_assert_held(&ar->conf_mutex);
991 if (ar->free_vdev_map == 0) {
992 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
996 bit = __ffs64(ar->free_vdev_map);
998 ar->monitor_vdev_id = bit;
1000 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
1001 WMI_VDEV_TYPE_MONITOR,
1004 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
1005 ar->monitor_vdev_id, ret);
1009 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1010 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
1011 ar->monitor_vdev_id);
1016 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
1020 lockdep_assert_held(&ar->conf_mutex);
1022 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1024 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
1025 ar->monitor_vdev_id, ret);
1029 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
1031 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
1032 ar->monitor_vdev_id);
1036 static int ath10k_monitor_start(struct ath10k *ar)
1040 lockdep_assert_held(&ar->conf_mutex);
1042 ret = ath10k_monitor_vdev_create(ar);
1044 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
1048 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
1050 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
1051 ath10k_monitor_vdev_delete(ar);
1055 ar->monitor_started = true;
1056 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
1061 static int ath10k_monitor_stop(struct ath10k *ar)
1065 lockdep_assert_held(&ar->conf_mutex);
1067 ret = ath10k_monitor_vdev_stop(ar);
1069 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
1073 ret = ath10k_monitor_vdev_delete(ar);
1075 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
1079 ar->monitor_started = false;
1080 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
1085 static bool ath10k_mac_monitor_vdev_is_needed(struct ath10k *ar)
1089 /* At least one chanctx is required to derive a channel to start
1092 num_ctx = ath10k_mac_num_chanctxs(ar);
1096 /* If there's already an existing special monitor interface then don't
1097 * bother creating another monitor vdev.
1099 if (ar->monitor_arvif)
1102 return ar->monitor ||
1103 ar->filter_flags & FIF_OTHER_BSS ||
1104 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1107 static bool ath10k_mac_monitor_vdev_is_allowed(struct ath10k *ar)
1111 num_ctx = ath10k_mac_num_chanctxs(ar);
1113 /* FIXME: Current interface combinations and cfg80211/mac80211 code
1114 * shouldn't allow this but make sure to prevent handling the following
1115 * case anyway since multi-channel DFS hasn't been tested at all.
1117 if (test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags) && num_ctx > 1)
1123 static int ath10k_monitor_recalc(struct ath10k *ar)
1129 lockdep_assert_held(&ar->conf_mutex);
1131 needed = ath10k_mac_monitor_vdev_is_needed(ar);
1132 allowed = ath10k_mac_monitor_vdev_is_allowed(ar);
1134 ath10k_dbg(ar, ATH10K_DBG_MAC,
1135 "mac monitor recalc started? %d needed? %d allowed? %d\n",
1136 ar->monitor_started, needed, allowed);
1138 if (WARN_ON(needed && !allowed)) {
1139 if (ar->monitor_started) {
1140 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopping disallowed monitor\n");
1142 ret = ath10k_monitor_stop(ar);
1144 ath10k_warn(ar, "failed to stop disallowed monitor: %d\n",
1152 if (needed == ar->monitor_started)
1156 return ath10k_monitor_start(ar);
1158 return ath10k_monitor_stop(ar);
1161 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
1163 struct ath10k *ar = arvif->ar;
1164 u32 vdev_param, rts_cts = 0;
1166 lockdep_assert_held(&ar->conf_mutex);
1168 vdev_param = ar->wmi.vdev_param->enable_rtscts;
1170 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
1172 if (arvif->num_legacy_stations > 0)
1173 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
1174 WMI_RTSCTS_PROFILE);
1176 rts_cts |= SM(WMI_RTSCTS_FOR_SECOND_RATESERIES,
1177 WMI_RTSCTS_PROFILE);
1179 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
1183 static int ath10k_start_cac(struct ath10k *ar)
1187 lockdep_assert_held(&ar->conf_mutex);
1189 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1191 ret = ath10k_monitor_recalc(ar);
1193 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
1194 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
1199 ar->monitor_vdev_id);
1204 static int ath10k_stop_cac(struct ath10k *ar)
1206 lockdep_assert_held(&ar->conf_mutex);
1208 /* CAC is not running - do nothing */
1209 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
1212 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
1213 ath10k_monitor_stop(ar);
1215 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
1220 static void ath10k_mac_has_radar_iter(struct ieee80211_hw *hw,
1221 struct ieee80211_chanctx_conf *conf,
1226 if (!*ret && conf->radar_enabled)
1230 static bool ath10k_mac_has_radar_enabled(struct ath10k *ar)
1232 bool has_radar = false;
1234 ieee80211_iter_chan_contexts_atomic(ar->hw,
1235 ath10k_mac_has_radar_iter,
1241 static void ath10k_recalc_radar_detection(struct ath10k *ar)
1245 lockdep_assert_held(&ar->conf_mutex);
1247 ath10k_stop_cac(ar);
1249 if (!ath10k_mac_has_radar_enabled(ar))
1252 if (ar->num_started_vdevs > 0)
1255 ret = ath10k_start_cac(ar);
1258 * Not possible to start CAC on current channel so starting
1259 * radiation is not allowed, make this channel DFS_UNAVAILABLE
1260 * by indicating that radar was detected.
1262 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
1263 ieee80211_radar_detected(ar->hw);
1267 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
1269 struct ath10k *ar = arvif->ar;
1272 lockdep_assert_held(&ar->conf_mutex);
1274 reinit_completion(&ar->vdev_setup_done);
1276 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
1278 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
1279 arvif->vdev_id, ret);
1283 ret = ath10k_vdev_setup_sync(ar);
1285 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
1286 arvif->vdev_id, ret);
1290 WARN_ON(ar->num_started_vdevs == 0);
1292 if (ar->num_started_vdevs != 0) {
1293 ar->num_started_vdevs--;
1294 ath10k_recalc_radar_detection(ar);
1300 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif,
1301 const struct cfg80211_chan_def *chandef,
1304 struct ath10k *ar = arvif->ar;
1305 struct wmi_vdev_start_request_arg arg = {};
1308 lockdep_assert_held(&ar->conf_mutex);
1310 reinit_completion(&ar->vdev_setup_done);
1312 arg.vdev_id = arvif->vdev_id;
1313 arg.dtim_period = arvif->dtim_period;
1314 arg.bcn_intval = arvif->beacon_interval;
1316 arg.channel.freq = chandef->chan->center_freq;
1317 arg.channel.band_center_freq1 = chandef->center_freq1;
1318 arg.channel.mode = chan_to_phymode(chandef);
1320 arg.channel.min_power = 0;
1321 arg.channel.max_power = chandef->chan->max_power * 2;
1322 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
1323 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
1325 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1326 arg.ssid = arvif->u.ap.ssid;
1327 arg.ssid_len = arvif->u.ap.ssid_len;
1328 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
1330 /* For now allow DFS for AP mode */
1331 arg.channel.chan_radar =
1332 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
1333 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1334 arg.ssid = arvif->vif->bss_conf.ssid;
1335 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
1338 ath10k_dbg(ar, ATH10K_DBG_MAC,
1339 "mac vdev %d start center_freq %d phymode %s\n",
1340 arg.vdev_id, arg.channel.freq,
1341 ath10k_wmi_phymode_str(arg.channel.mode));
1344 ret = ath10k_wmi_vdev_restart(ar, &arg);
1346 ret = ath10k_wmi_vdev_start(ar, &arg);
1349 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
1354 ret = ath10k_vdev_setup_sync(ar);
1357 "failed to synchronize setup for vdev %i restart %d: %d\n",
1358 arg.vdev_id, restart, ret);
1362 ar->num_started_vdevs++;
1363 ath10k_recalc_radar_detection(ar);
1368 static int ath10k_vdev_start(struct ath10k_vif *arvif,
1369 const struct cfg80211_chan_def *def)
1371 return ath10k_vdev_start_restart(arvif, def, false);
1374 static int ath10k_vdev_restart(struct ath10k_vif *arvif,
1375 const struct cfg80211_chan_def *def)
1377 return ath10k_vdev_start_restart(arvif, def, true);
1380 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
1381 struct sk_buff *bcn)
1383 struct ath10k *ar = arvif->ar;
1384 struct ieee80211_mgmt *mgmt;
1388 if (arvif->vif->type != NL80211_IFTYPE_AP || !arvif->vif->p2p)
1391 mgmt = (void *)bcn->data;
1392 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1393 mgmt->u.beacon.variable,
1394 bcn->len - (mgmt->u.beacon.variable -
1399 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1401 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1402 arvif->vdev_id, ret);
1409 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1410 u8 oui_type, size_t ie_offset)
1417 if (WARN_ON(skb->len < ie_offset))
1420 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1421 skb->data + ie_offset,
1422 skb->len - ie_offset);
1427 end = skb->data + skb->len;
1430 if (WARN_ON(next > end))
1433 memmove(ie, next, end - next);
1434 skb_trim(skb, skb->len - len);
1439 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1441 struct ath10k *ar = arvif->ar;
1442 struct ieee80211_hw *hw = ar->hw;
1443 struct ieee80211_vif *vif = arvif->vif;
1444 struct ieee80211_mutable_offsets offs = {};
1445 struct sk_buff *bcn;
1448 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1451 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
1452 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
1455 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1457 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1461 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1463 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1468 /* P2P IE is inserted by firmware automatically (as configured above)
1469 * so remove it from the base beacon template to avoid duplicate P2P
1470 * IEs in beacon frames.
1472 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1473 offsetof(struct ieee80211_mgmt,
1474 u.beacon.variable));
1476 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1481 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1489 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1491 struct ath10k *ar = arvif->ar;
1492 struct ieee80211_hw *hw = ar->hw;
1493 struct ieee80211_vif *vif = arvif->vif;
1494 struct sk_buff *prb;
1497 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1500 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1503 prb = ieee80211_proberesp_get(hw, vif);
1505 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1509 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1513 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1521 static int ath10k_mac_vif_fix_hidden_ssid(struct ath10k_vif *arvif)
1523 struct ath10k *ar = arvif->ar;
1524 struct cfg80211_chan_def def;
1527 /* When originally vdev is started during assign_vif_chanctx() some
1528 * information is missing, notably SSID. Firmware revisions with beacon
1529 * offloading require the SSID to be provided during vdev (re)start to
1530 * handle hidden SSID properly.
1532 * Vdev restart must be done after vdev has been both started and
1533 * upped. Otherwise some firmware revisions (at least 10.2) fail to
1534 * deliver vdev restart response event causing timeouts during vdev
1535 * syncing in ath10k.
1537 * Note: The vdev down/up and template reinstallation could be skipped
1538 * since only wmi-tlv firmware are known to have beacon offload and
1539 * wmi-tlv doesn't seem to misbehave like 10.2 wrt vdev restart
1540 * response delivery. It's probably more robust to keep it as is.
1542 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1545 if (WARN_ON(!arvif->is_started))
1548 if (WARN_ON(!arvif->is_up))
1551 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
1554 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1556 ath10k_warn(ar, "failed to bring down ap vdev %i: %d\n",
1557 arvif->vdev_id, ret);
1561 /* Vdev down reset beacon & presp templates. Reinstall them. Otherwise
1562 * firmware will crash upon vdev up.
1565 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1567 ath10k_warn(ar, "failed to update beacon template: %d\n", ret);
1571 ret = ath10k_mac_setup_prb_tmpl(arvif);
1573 ath10k_warn(ar, "failed to update presp template: %d\n", ret);
1577 ret = ath10k_vdev_restart(arvif, &def);
1579 ath10k_warn(ar, "failed to restart ap vdev %i: %d\n",
1580 arvif->vdev_id, ret);
1584 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1587 ath10k_warn(ar, "failed to bring up ap vdev %i: %d\n",
1588 arvif->vdev_id, ret);
1595 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1596 struct ieee80211_bss_conf *info)
1598 struct ath10k *ar = arvif->ar;
1601 lockdep_assert_held(&arvif->ar->conf_mutex);
1603 if (!info->enable_beacon) {
1604 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1606 ath10k_warn(ar, "failed to down vdev_id %i: %d\n",
1607 arvif->vdev_id, ret);
1609 arvif->is_up = false;
1611 spin_lock_bh(&arvif->ar->data_lock);
1612 ath10k_mac_vif_beacon_free(arvif);
1613 spin_unlock_bh(&arvif->ar->data_lock);
1618 arvif->tx_seq_no = 0x1000;
1621 ether_addr_copy(arvif->bssid, info->bssid);
1623 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1626 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1627 arvif->vdev_id, ret);
1631 arvif->is_up = true;
1633 ret = ath10k_mac_vif_fix_hidden_ssid(arvif);
1635 ath10k_warn(ar, "failed to fix hidden ssid for vdev %i, expect trouble: %d\n",
1636 arvif->vdev_id, ret);
1640 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1643 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1644 struct ieee80211_bss_conf *info,
1645 const u8 self_peer[ETH_ALEN])
1647 struct ath10k *ar = arvif->ar;
1651 lockdep_assert_held(&arvif->ar->conf_mutex);
1653 if (!info->ibss_joined) {
1654 if (is_zero_ether_addr(arvif->bssid))
1657 eth_zero_addr(arvif->bssid);
1662 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1663 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1664 ATH10K_DEFAULT_ATIM);
1666 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1667 arvif->vdev_id, ret);
1670 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1672 struct ath10k *ar = arvif->ar;
1677 lockdep_assert_held(&arvif->ar->conf_mutex);
1679 if (arvif->u.sta.uapsd)
1680 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1682 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1684 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1685 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1687 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1688 value, arvif->vdev_id, ret);
1695 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1697 struct ath10k *ar = arvif->ar;
1702 lockdep_assert_held(&arvif->ar->conf_mutex);
1704 if (arvif->u.sta.uapsd)
1705 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1707 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1709 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1710 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1713 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1714 value, arvif->vdev_id, ret);
1721 static int ath10k_mac_num_vifs_started(struct ath10k *ar)
1723 struct ath10k_vif *arvif;
1726 lockdep_assert_held(&ar->conf_mutex);
1728 list_for_each_entry(arvif, &ar->arvifs, list)
1729 if (arvif->is_started)
1735 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1737 struct ath10k *ar = arvif->ar;
1738 struct ieee80211_vif *vif = arvif->vif;
1739 struct ieee80211_conf *conf = &ar->hw->conf;
1740 enum wmi_sta_powersave_param param;
1741 enum wmi_sta_ps_mode psmode;
1746 lockdep_assert_held(&arvif->ar->conf_mutex);
1748 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1751 enable_ps = arvif->ps;
1753 if (enable_ps && ath10k_mac_num_vifs_started(ar) > 1 &&
1754 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1756 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1761 if (!arvif->is_started) {
1762 /* mac80211 can update vif powersave state while disconnected.
1763 * Firmware doesn't behave nicely and consumes more power than
1764 * necessary if PS is disabled on a non-started vdev. Hence
1765 * force-enable PS for non-running vdevs.
1767 psmode = WMI_STA_PS_MODE_ENABLED;
1768 } else if (enable_ps) {
1769 psmode = WMI_STA_PS_MODE_ENABLED;
1770 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1772 ps_timeout = conf->dynamic_ps_timeout;
1773 if (ps_timeout == 0) {
1774 /* Firmware doesn't like 0 */
1775 ps_timeout = ieee80211_tu_to_usec(
1776 vif->bss_conf.beacon_int) / 1000;
1779 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1782 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1783 arvif->vdev_id, ret);
1787 psmode = WMI_STA_PS_MODE_DISABLED;
1790 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1791 arvif->vdev_id, psmode ? "enable" : "disable");
1793 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1795 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1796 psmode, arvif->vdev_id, ret);
1803 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1805 struct ath10k *ar = arvif->ar;
1806 struct wmi_sta_keepalive_arg arg = {};
1809 lockdep_assert_held(&arvif->ar->conf_mutex);
1811 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1814 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1817 /* Some firmware revisions have a bug and ignore the `enabled` field.
1818 * Instead use the interval to disable the keepalive.
1820 arg.vdev_id = arvif->vdev_id;
1822 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1823 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1825 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1827 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1828 arvif->vdev_id, ret);
1835 static void ath10k_mac_vif_ap_csa_count_down(struct ath10k_vif *arvif)
1837 struct ath10k *ar = arvif->ar;
1838 struct ieee80211_vif *vif = arvif->vif;
1841 lockdep_assert_held(&arvif->ar->conf_mutex);
1843 if (WARN_ON(!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)))
1846 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1849 if (!vif->csa_active)
1855 if (!ieee80211_csa_is_complete(vif)) {
1856 ieee80211_csa_update_counter(vif);
1858 ret = ath10k_mac_setup_bcn_tmpl(arvif);
1860 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
1863 ret = ath10k_mac_setup_prb_tmpl(arvif);
1865 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
1868 ieee80211_csa_finish(vif);
1872 static void ath10k_mac_vif_ap_csa_work(struct work_struct *work)
1874 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1876 struct ath10k *ar = arvif->ar;
1878 mutex_lock(&ar->conf_mutex);
1879 ath10k_mac_vif_ap_csa_count_down(arvif);
1880 mutex_unlock(&ar->conf_mutex);
1883 static void ath10k_mac_handle_beacon_iter(void *data, u8 *mac,
1884 struct ieee80211_vif *vif)
1886 struct sk_buff *skb = data;
1887 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1888 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1890 if (vif->type != NL80211_IFTYPE_STATION)
1893 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1896 cancel_delayed_work(&arvif->connection_loss_work);
1899 void ath10k_mac_handle_beacon(struct ath10k *ar, struct sk_buff *skb)
1901 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1902 IEEE80211_IFACE_ITER_NORMAL,
1903 ath10k_mac_handle_beacon_iter,
1907 static void ath10k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1908 struct ieee80211_vif *vif)
1910 u32 *vdev_id = data;
1911 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1912 struct ath10k *ar = arvif->ar;
1913 struct ieee80211_hw *hw = ar->hw;
1915 if (arvif->vdev_id != *vdev_id)
1921 ieee80211_beacon_loss(vif);
1923 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1924 * (done by mac80211) succeeds but beacons do not resume then it
1925 * doesn't make sense to continue operation. Queue connection loss work
1926 * which can be cancelled when beacon is received.
1928 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1929 ATH10K_CONNECTION_LOSS_HZ);
1932 void ath10k_mac_handle_beacon_miss(struct ath10k *ar, u32 vdev_id)
1934 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1935 IEEE80211_IFACE_ITER_NORMAL,
1936 ath10k_mac_handle_beacon_miss_iter,
1940 static void ath10k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1942 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1943 connection_loss_work.work);
1944 struct ieee80211_vif *vif = arvif->vif;
1949 ieee80211_connection_loss(vif);
1952 /**********************/
1953 /* Station management */
1954 /**********************/
1956 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1957 struct ieee80211_vif *vif)
1959 /* Some firmware revisions have unstable STA powersave when listen
1960 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1961 * generate NullFunc frames properly even if buffered frames have been
1962 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1963 * buffered frames. Often pinging the device from AP would simply fail.
1965 * As a workaround set it to 1.
1967 if (vif->type == NL80211_IFTYPE_STATION)
1970 return ar->hw->conf.listen_interval;
1973 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1974 struct ieee80211_vif *vif,
1975 struct ieee80211_sta *sta,
1976 struct wmi_peer_assoc_complete_arg *arg)
1978 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1981 lockdep_assert_held(&ar->conf_mutex);
1983 if (vif->type == NL80211_IFTYPE_STATION)
1984 aid = vif->bss_conf.aid;
1988 ether_addr_copy(arg->addr, sta->addr);
1989 arg->vdev_id = arvif->vdev_id;
1990 arg->peer_aid = aid;
1991 arg->peer_flags |= arvif->ar->wmi.peer_flags->auth;
1992 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1993 arg->peer_num_spatial_streams = 1;
1994 arg->peer_caps = vif->bss_conf.assoc_capability;
1997 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1998 struct ieee80211_vif *vif,
1999 struct ieee80211_sta *sta,
2000 struct wmi_peer_assoc_complete_arg *arg)
2002 struct ieee80211_bss_conf *info = &vif->bss_conf;
2003 struct cfg80211_chan_def def;
2004 struct cfg80211_bss *bss;
2005 const u8 *rsnie = NULL;
2006 const u8 *wpaie = NULL;
2008 lockdep_assert_held(&ar->conf_mutex);
2010 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2013 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
2014 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
2016 const struct cfg80211_bss_ies *ies;
2019 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
2021 ies = rcu_dereference(bss->ies);
2023 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
2024 WLAN_OUI_TYPE_MICROSOFT_WPA,
2028 cfg80211_put_bss(ar->hw->wiphy, bss);
2031 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
2032 if (rsnie || wpaie) {
2033 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
2034 arg->peer_flags |= ar->wmi.peer_flags->need_ptk_4_way;
2038 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
2039 arg->peer_flags |= ar->wmi.peer_flags->need_gtk_2_way;
2043 test_bit(ATH10K_FW_FEATURE_MFP_SUPPORT, ar->fw_features)) {
2044 arg->peer_flags |= ar->wmi.peer_flags->pmf;
2048 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
2049 struct ieee80211_vif *vif,
2050 struct ieee80211_sta *sta,
2051 struct wmi_peer_assoc_complete_arg *arg)
2053 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2054 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
2055 struct cfg80211_chan_def def;
2056 const struct ieee80211_supported_band *sband;
2057 const struct ieee80211_rate *rates;
2058 enum ieee80211_band band;
2063 lockdep_assert_held(&ar->conf_mutex);
2065 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2068 band = def.chan->band;
2069 sband = ar->hw->wiphy->bands[band];
2070 ratemask = sta->supp_rates[band];
2071 ratemask &= arvif->bitrate_mask.control[band].legacy;
2072 rates = sband->bitrates;
2074 rateset->num_rates = 0;
2076 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
2077 if (!(ratemask & 1))
2080 rate = ath10k_mac_bitrate_to_rate(rates->bitrate);
2081 rateset->rates[rateset->num_rates] = rate;
2082 rateset->num_rates++;
2087 ath10k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2091 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
2092 if (ht_mcs_mask[nss])
2099 ath10k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
2103 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
2104 if (vht_mcs_mask[nss])
2110 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
2111 struct ieee80211_vif *vif,
2112 struct ieee80211_sta *sta,
2113 struct wmi_peer_assoc_complete_arg *arg)
2115 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2116 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2117 struct cfg80211_chan_def def;
2118 enum ieee80211_band band;
2119 const u8 *ht_mcs_mask;
2120 const u16 *vht_mcs_mask;
2125 lockdep_assert_held(&ar->conf_mutex);
2127 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2130 if (!ht_cap->ht_supported)
2133 band = def.chan->band;
2134 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2135 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2137 if (ath10k_peer_assoc_h_ht_masked(ht_mcs_mask) &&
2138 ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2141 arg->peer_flags |= ar->wmi.peer_flags->ht;
2142 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2143 ht_cap->ampdu_factor)) - 1;
2145 arg->peer_mpdu_density =
2146 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
2148 arg->peer_ht_caps = ht_cap->cap;
2149 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
2151 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
2152 arg->peer_flags |= ar->wmi.peer_flags->ldbc;
2154 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
2155 arg->peer_flags |= ar->wmi.peer_flags->bw40;
2156 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
2159 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
2160 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
2161 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2163 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
2164 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
2167 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
2168 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
2169 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2172 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
2173 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
2174 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
2175 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
2176 arg->peer_rate_caps |= stbc;
2177 arg->peer_flags |= ar->wmi.peer_flags->stbc;
2180 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
2181 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
2182 else if (ht_cap->mcs.rx_mask[1])
2183 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
2185 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
2186 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
2187 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
2188 max_nss = (i / 8) + 1;
2189 arg->peer_ht_rates.rates[n++] = i;
2193 * This is a workaround for HT-enabled STAs which break the spec
2194 * and have no HT capabilities RX mask (no HT RX MCS map).
2196 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
2197 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
2199 * Firmware asserts if such situation occurs.
2202 arg->peer_ht_rates.num_rates = 8;
2203 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
2204 arg->peer_ht_rates.rates[i] = i;
2206 arg->peer_ht_rates.num_rates = n;
2207 arg->peer_num_spatial_streams = min(sta->rx_nss, max_nss);
2210 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
2212 arg->peer_ht_rates.num_rates,
2213 arg->peer_num_spatial_streams);
2216 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
2217 struct ath10k_vif *arvif,
2218 struct ieee80211_sta *sta)
2224 lockdep_assert_held(&ar->conf_mutex);
2226 if (sta->wme && sta->uapsd_queues) {
2227 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2228 sta->uapsd_queues, sta->max_sp);
2230 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2231 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2232 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2233 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2234 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2235 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2236 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2237 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2238 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2239 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2240 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2241 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2243 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2244 max_sp = sta->max_sp;
2246 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2248 WMI_AP_PS_PEER_PARAM_UAPSD,
2251 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
2252 arvif->vdev_id, ret);
2256 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
2258 WMI_AP_PS_PEER_PARAM_MAX_SP,
2261 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
2262 arvif->vdev_id, ret);
2266 /* TODO setup this based on STA listen interval and
2267 beacon interval. Currently we don't know
2268 sta->listen_interval - mac80211 patch required.
2269 Currently use 10 seconds */
2270 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
2271 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
2274 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
2275 arvif->vdev_id, ret);
2284 ath10k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
2285 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
2292 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
2293 mcs_map = ath10k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
2297 idx_limit = fls(mcs_map) - 1;
2301 switch (idx_limit) {
2302 case 0: /* fall through */
2303 case 1: /* fall through */
2304 case 2: /* fall through */
2305 case 3: /* fall through */
2306 case 4: /* fall through */
2307 case 5: /* fall through */
2308 case 6: /* fall through */
2310 /* see ath10k_mac_can_set_bitrate_mask() */
2314 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
2317 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
2320 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
2323 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
2327 tx_mcs_set &= ~(0x3 << (nss * 2));
2328 tx_mcs_set |= mcs << (nss * 2);
2334 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
2335 struct ieee80211_vif *vif,
2336 struct ieee80211_sta *sta,
2337 struct wmi_peer_assoc_complete_arg *arg)
2339 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
2340 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2341 struct cfg80211_chan_def def;
2342 enum ieee80211_band band;
2343 const u16 *vht_mcs_mask;
2346 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2349 if (!vht_cap->vht_supported)
2352 band = def.chan->band;
2353 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2355 if (ath10k_peer_assoc_h_vht_masked(vht_mcs_mask))
2358 arg->peer_flags |= ar->wmi.peer_flags->vht;
2360 if (def.chan->band == IEEE80211_BAND_2GHZ)
2361 arg->peer_flags |= ar->wmi.peer_flags->vht_2g;
2363 arg->peer_vht_caps = vht_cap->cap;
2365 ampdu_factor = (vht_cap->cap &
2366 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
2367 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
2369 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
2370 * zero in VHT IE. Using it would result in degraded throughput.
2371 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
2372 * it if VHT max_mpdu is smaller. */
2373 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
2374 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
2375 ampdu_factor)) - 1);
2377 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2378 arg->peer_flags |= ar->wmi.peer_flags->bw80;
2380 arg->peer_vht_rates.rx_max_rate =
2381 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
2382 arg->peer_vht_rates.rx_mcs_set =
2383 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
2384 arg->peer_vht_rates.tx_max_rate =
2385 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
2386 arg->peer_vht_rates.tx_mcs_set = ath10k_peer_assoc_h_vht_limit(
2387 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
2389 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
2390 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
2393 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
2394 struct ieee80211_vif *vif,
2395 struct ieee80211_sta *sta,
2396 struct wmi_peer_assoc_complete_arg *arg)
2398 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2400 switch (arvif->vdev_type) {
2401 case WMI_VDEV_TYPE_AP:
2403 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2405 if (sta->wme && sta->uapsd_queues) {
2406 arg->peer_flags |= arvif->ar->wmi.peer_flags->apsd;
2407 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
2410 case WMI_VDEV_TYPE_STA:
2411 if (vif->bss_conf.qos)
2412 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2414 case WMI_VDEV_TYPE_IBSS:
2416 arg->peer_flags |= arvif->ar->wmi.peer_flags->qos;
2422 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
2423 sta->addr, !!(arg->peer_flags &
2424 arvif->ar->wmi.peer_flags->qos));
2427 static bool ath10k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2429 return sta->supp_rates[IEEE80211_BAND_2GHZ] >>
2430 ATH10K_MAC_FIRST_OFDM_RATE_IDX;
2433 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
2434 struct ieee80211_vif *vif,
2435 struct ieee80211_sta *sta,
2436 struct wmi_peer_assoc_complete_arg *arg)
2438 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2439 struct cfg80211_chan_def def;
2440 enum ieee80211_band band;
2441 const u8 *ht_mcs_mask;
2442 const u16 *vht_mcs_mask;
2443 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2445 if (WARN_ON(ath10k_mac_vif_chan(vif, &def)))
2448 band = def.chan->band;
2449 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2450 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2453 case IEEE80211_BAND_2GHZ:
2454 if (sta->vht_cap.vht_supported &&
2455 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2456 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2457 phymode = MODE_11AC_VHT40;
2459 phymode = MODE_11AC_VHT20;
2460 } else if (sta->ht_cap.ht_supported &&
2461 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2462 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2463 phymode = MODE_11NG_HT40;
2465 phymode = MODE_11NG_HT20;
2466 } else if (ath10k_mac_sta_has_ofdm_only(sta)) {
2473 case IEEE80211_BAND_5GHZ:
2477 if (sta->vht_cap.vht_supported &&
2478 !ath10k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2479 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2480 phymode = MODE_11AC_VHT80;
2481 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2482 phymode = MODE_11AC_VHT40;
2483 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2484 phymode = MODE_11AC_VHT20;
2485 } else if (sta->ht_cap.ht_supported &&
2486 !ath10k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2487 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2488 phymode = MODE_11NA_HT40;
2490 phymode = MODE_11NA_HT20;
2500 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
2501 sta->addr, ath10k_wmi_phymode_str(phymode));
2503 arg->peer_phymode = phymode;
2504 WARN_ON(phymode == MODE_UNKNOWN);
2507 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
2508 struct ieee80211_vif *vif,
2509 struct ieee80211_sta *sta,
2510 struct wmi_peer_assoc_complete_arg *arg)
2512 lockdep_assert_held(&ar->conf_mutex);
2514 memset(arg, 0, sizeof(*arg));
2516 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
2517 ath10k_peer_assoc_h_crypto(ar, vif, sta, arg);
2518 ath10k_peer_assoc_h_rates(ar, vif, sta, arg);
2519 ath10k_peer_assoc_h_ht(ar, vif, sta, arg);
2520 ath10k_peer_assoc_h_vht(ar, vif, sta, arg);
2521 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
2522 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
2527 static const u32 ath10k_smps_map[] = {
2528 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
2529 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
2530 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
2531 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
2534 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
2536 const struct ieee80211_sta_ht_cap *ht_cap)
2540 if (!ht_cap->ht_supported)
2543 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2544 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2546 if (smps >= ARRAY_SIZE(ath10k_smps_map))
2549 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
2550 WMI_PEER_SMPS_STATE,
2551 ath10k_smps_map[smps]);
2554 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
2555 struct ieee80211_vif *vif,
2556 struct ieee80211_sta_vht_cap vht_cap)
2558 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2563 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_AFTER_ASSOC)
2566 if (!(ar->vht_cap_info &
2567 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2568 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
2569 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2570 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
2573 param = ar->wmi.vdev_param->txbf;
2576 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
2579 /* The following logic is correct. If a remote STA advertises support
2580 * for being a beamformer then we should enable us being a beamformee.
2583 if (ar->vht_cap_info &
2584 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
2585 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
2586 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
2587 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2589 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
2590 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
2593 if (ar->vht_cap_info &
2594 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
2595 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
2596 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
2597 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2599 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
2600 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
2603 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
2604 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
2606 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
2607 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
2609 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
2611 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
2619 /* can be called only in mac80211 callbacks due to `key_count` usage */
2620 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
2621 struct ieee80211_vif *vif,
2622 struct ieee80211_bss_conf *bss_conf)
2624 struct ath10k *ar = hw->priv;
2625 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2626 struct ieee80211_sta_ht_cap ht_cap;
2627 struct ieee80211_sta_vht_cap vht_cap;
2628 struct wmi_peer_assoc_complete_arg peer_arg;
2629 struct ieee80211_sta *ap_sta;
2632 lockdep_assert_held(&ar->conf_mutex);
2634 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2635 arvif->vdev_id, arvif->bssid, arvif->aid);
2639 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2641 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
2642 bss_conf->bssid, arvif->vdev_id);
2647 /* ap_sta must be accessed only within rcu section which must be left
2648 * before calling ath10k_setup_peer_smps() which might sleep. */
2649 ht_cap = ap_sta->ht_cap;
2650 vht_cap = ap_sta->vht_cap;
2652 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
2654 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
2655 bss_conf->bssid, arvif->vdev_id, ret);
2662 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2664 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
2665 bss_conf->bssid, arvif->vdev_id, ret);
2669 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
2671 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
2672 arvif->vdev_id, ret);
2676 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2678 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
2679 arvif->vdev_id, bss_conf->bssid, ret);
2683 ath10k_dbg(ar, ATH10K_DBG_MAC,
2684 "mac vdev %d up (associated) bssid %pM aid %d\n",
2685 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2687 WARN_ON(arvif->is_up);
2689 arvif->aid = bss_conf->aid;
2690 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2692 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2694 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
2695 arvif->vdev_id, ret);
2699 arvif->is_up = true;
2701 /* Workaround: Some firmware revisions (tested with qca6174
2702 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
2703 * poked with peer param command.
2705 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
2706 WMI_PEER_DUMMY_VAR, 1);
2708 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
2709 arvif->bssid, arvif->vdev_id, ret);
2714 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
2715 struct ieee80211_vif *vif)
2717 struct ath10k *ar = hw->priv;
2718 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2719 struct ieee80211_sta_vht_cap vht_cap = {};
2722 lockdep_assert_held(&ar->conf_mutex);
2724 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2725 arvif->vdev_id, arvif->bssid);
2727 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2729 ath10k_warn(ar, "faield to down vdev %i: %d\n",
2730 arvif->vdev_id, ret);
2732 arvif->def_wep_key_idx = -1;
2734 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
2736 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
2737 arvif->vdev_id, ret);
2741 arvif->is_up = false;
2743 cancel_delayed_work_sync(&arvif->connection_loss_work);
2746 static int ath10k_station_assoc(struct ath10k *ar,
2747 struct ieee80211_vif *vif,
2748 struct ieee80211_sta *sta,
2751 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2752 struct wmi_peer_assoc_complete_arg peer_arg;
2755 lockdep_assert_held(&ar->conf_mutex);
2757 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2759 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2760 sta->addr, arvif->vdev_id, ret);
2764 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2766 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2767 sta->addr, arvif->vdev_id, ret);
2771 /* Re-assoc is run only to update supported rates for given station. It
2772 * doesn't make much sense to reconfigure the peer completely.
2775 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2778 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2779 arvif->vdev_id, ret);
2783 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2785 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2786 sta->addr, arvif->vdev_id, ret);
2791 arvif->num_legacy_stations++;
2792 ret = ath10k_recalc_rtscts_prot(arvif);
2794 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2795 arvif->vdev_id, ret);
2800 /* Plumb cached keys only for static WEP */
2801 if (arvif->def_wep_key_idx != -1) {
2802 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2804 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2805 arvif->vdev_id, ret);
2814 static int ath10k_station_disassoc(struct ath10k *ar,
2815 struct ieee80211_vif *vif,
2816 struct ieee80211_sta *sta)
2818 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2821 lockdep_assert_held(&ar->conf_mutex);
2824 arvif->num_legacy_stations--;
2825 ret = ath10k_recalc_rtscts_prot(arvif);
2827 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2828 arvif->vdev_id, ret);
2833 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2835 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2836 arvif->vdev_id, ret);
2847 static int ath10k_update_channel_list(struct ath10k *ar)
2849 struct ieee80211_hw *hw = ar->hw;
2850 struct ieee80211_supported_band **bands;
2851 enum ieee80211_band band;
2852 struct ieee80211_channel *channel;
2853 struct wmi_scan_chan_list_arg arg = {0};
2854 struct wmi_channel_arg *ch;
2860 lockdep_assert_held(&ar->conf_mutex);
2862 bands = hw->wiphy->bands;
2863 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2867 for (i = 0; i < bands[band]->n_channels; i++) {
2868 if (bands[band]->channels[i].flags &
2869 IEEE80211_CHAN_DISABLED)
2876 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2877 arg.channels = kzalloc(len, GFP_KERNEL);
2882 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2886 for (i = 0; i < bands[band]->n_channels; i++) {
2887 channel = &bands[band]->channels[i];
2889 if (channel->flags & IEEE80211_CHAN_DISABLED)
2892 ch->allow_ht = true;
2894 /* FIXME: when should we really allow VHT? */
2895 ch->allow_vht = true;
2898 !(channel->flags & IEEE80211_CHAN_NO_IR);
2901 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2904 !!(channel->flags & IEEE80211_CHAN_RADAR);
2906 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2907 ch->passive = passive;
2909 ch->freq = channel->center_freq;
2910 ch->band_center_freq1 = channel->center_freq;
2912 ch->max_power = channel->max_power * 2;
2913 ch->max_reg_power = channel->max_reg_power * 2;
2914 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2915 ch->reg_class_id = 0; /* FIXME */
2917 /* FIXME: why use only legacy modes, why not any
2918 * HT/VHT modes? Would that even make any
2920 if (channel->band == IEEE80211_BAND_2GHZ)
2921 ch->mode = MODE_11G;
2923 ch->mode = MODE_11A;
2925 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2928 ath10k_dbg(ar, ATH10K_DBG_WMI,
2929 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2930 ch - arg.channels, arg.n_channels,
2931 ch->freq, ch->max_power, ch->max_reg_power,
2932 ch->max_antenna_gain, ch->mode);
2938 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2939 kfree(arg.channels);
2944 static enum wmi_dfs_region
2945 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2947 switch (dfs_region) {
2948 case NL80211_DFS_UNSET:
2949 return WMI_UNINIT_DFS_DOMAIN;
2950 case NL80211_DFS_FCC:
2951 return WMI_FCC_DFS_DOMAIN;
2952 case NL80211_DFS_ETSI:
2953 return WMI_ETSI_DFS_DOMAIN;
2954 case NL80211_DFS_JP:
2955 return WMI_MKK4_DFS_DOMAIN;
2957 return WMI_UNINIT_DFS_DOMAIN;
2960 static void ath10k_regd_update(struct ath10k *ar)
2962 struct reg_dmn_pair_mapping *regpair;
2964 enum wmi_dfs_region wmi_dfs_reg;
2965 enum nl80211_dfs_regions nl_dfs_reg;
2967 lockdep_assert_held(&ar->conf_mutex);
2969 ret = ath10k_update_channel_list(ar);
2971 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2973 regpair = ar->ath_common.regulatory.regpair;
2975 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2976 nl_dfs_reg = ar->dfs_detector->region;
2977 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2979 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2982 /* Target allows setting up per-band regdomain but ath_common provides
2983 * a combined one only */
2984 ret = ath10k_wmi_pdev_set_regdomain(ar,
2985 regpair->reg_domain,
2986 regpair->reg_domain, /* 2ghz */
2987 regpair->reg_domain, /* 5ghz */
2988 regpair->reg_2ghz_ctl,
2989 regpair->reg_5ghz_ctl,
2992 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
2995 static void ath10k_reg_notifier(struct wiphy *wiphy,
2996 struct regulatory_request *request)
2998 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2999 struct ath10k *ar = hw->priv;
3002 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
3004 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
3005 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
3006 request->dfs_region);
3007 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
3008 request->dfs_region);
3010 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
3011 request->dfs_region);
3014 mutex_lock(&ar->conf_mutex);
3015 if (ar->state == ATH10K_STATE_ON)
3016 ath10k_regd_update(ar);
3017 mutex_unlock(&ar->conf_mutex);
3024 enum ath10k_mac_tx_path {
3026 ATH10K_MAC_TX_HTT_MGMT,
3027 ATH10K_MAC_TX_WMI_MGMT,
3028 ATH10K_MAC_TX_UNKNOWN,
3031 void ath10k_mac_tx_lock(struct ath10k *ar, int reason)
3033 lockdep_assert_held(&ar->htt.tx_lock);
3035 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3036 ar->tx_paused |= BIT(reason);
3037 ieee80211_stop_queues(ar->hw);
3040 static void ath10k_mac_tx_unlock_iter(void *data, u8 *mac,
3041 struct ieee80211_vif *vif)
3043 struct ath10k *ar = data;
3044 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3046 if (arvif->tx_paused)
3049 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3052 void ath10k_mac_tx_unlock(struct ath10k *ar, int reason)
3054 lockdep_assert_held(&ar->htt.tx_lock);
3056 WARN_ON(reason >= ATH10K_TX_PAUSE_MAX);
3057 ar->tx_paused &= ~BIT(reason);
3062 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3063 IEEE80211_IFACE_ITER_RESUME_ALL,
3064 ath10k_mac_tx_unlock_iter,
3067 ieee80211_wake_queue(ar->hw, ar->hw->offchannel_tx_hw_queue);
3070 void ath10k_mac_vif_tx_lock(struct ath10k_vif *arvif, int reason)
3072 struct ath10k *ar = arvif->ar;
3074 lockdep_assert_held(&ar->htt.tx_lock);
3076 WARN_ON(reason >= BITS_PER_LONG);
3077 arvif->tx_paused |= BIT(reason);
3078 ieee80211_stop_queue(ar->hw, arvif->vdev_id);
3081 void ath10k_mac_vif_tx_unlock(struct ath10k_vif *arvif, int reason)
3083 struct ath10k *ar = arvif->ar;
3085 lockdep_assert_held(&ar->htt.tx_lock);
3087 WARN_ON(reason >= BITS_PER_LONG);
3088 arvif->tx_paused &= ~BIT(reason);
3093 if (arvif->tx_paused)
3096 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
3099 static void ath10k_mac_vif_handle_tx_pause(struct ath10k_vif *arvif,
3100 enum wmi_tlv_tx_pause_id pause_id,
3101 enum wmi_tlv_tx_pause_action action)
3103 struct ath10k *ar = arvif->ar;
3105 lockdep_assert_held(&ar->htt.tx_lock);
3108 case WMI_TLV_TX_PAUSE_ACTION_STOP:
3109 ath10k_mac_vif_tx_lock(arvif, pause_id);
3111 case WMI_TLV_TX_PAUSE_ACTION_WAKE:
3112 ath10k_mac_vif_tx_unlock(arvif, pause_id);
3115 ath10k_warn(ar, "received unknown tx pause action %d on vdev %i, ignoring\n",
3116 action, arvif->vdev_id);
3121 struct ath10k_mac_tx_pause {
3123 enum wmi_tlv_tx_pause_id pause_id;
3124 enum wmi_tlv_tx_pause_action action;
3127 static void ath10k_mac_handle_tx_pause_iter(void *data, u8 *mac,
3128 struct ieee80211_vif *vif)
3130 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3131 struct ath10k_mac_tx_pause *arg = data;
3133 if (arvif->vdev_id != arg->vdev_id)
3136 ath10k_mac_vif_handle_tx_pause(arvif, arg->pause_id, arg->action);
3139 void ath10k_mac_handle_tx_pause_vdev(struct ath10k *ar, u32 vdev_id,
3140 enum wmi_tlv_tx_pause_id pause_id,
3141 enum wmi_tlv_tx_pause_action action)
3143 struct ath10k_mac_tx_pause arg = {
3145 .pause_id = pause_id,
3149 spin_lock_bh(&ar->htt.tx_lock);
3150 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3151 IEEE80211_IFACE_ITER_RESUME_ALL,
3152 ath10k_mac_handle_tx_pause_iter,
3154 spin_unlock_bh(&ar->htt.tx_lock);
3157 static enum ath10k_hw_txrx_mode
3158 ath10k_mac_tx_h_get_txmode(struct ath10k *ar,
3159 struct ieee80211_vif *vif,
3160 struct ieee80211_sta *sta,
3161 struct sk_buff *skb)
3163 const struct ieee80211_hdr *hdr = (void *)skb->data;
3164 __le16 fc = hdr->frame_control;
3166 if (!vif || vif->type == NL80211_IFTYPE_MONITOR)
3167 return ATH10K_HW_TXRX_RAW;
3169 if (ieee80211_is_mgmt(fc))
3170 return ATH10K_HW_TXRX_MGMT;
3174 * NullFunc frames are mostly used to ping if a client or AP are still
3175 * reachable and responsive. This implies tx status reports must be
3176 * accurate - otherwise either mac80211 or userspace (e.g. hostapd) can
3177 * come to a conclusion that the other end disappeared and tear down
3178 * BSS connection or it can never disconnect from BSS/client (which is
3181 * Firmware with HTT older than 3.0 delivers incorrect tx status for
3182 * NullFunc frames to driver. However there's a HTT Mgmt Tx command
3183 * which seems to deliver correct tx reports for NullFunc frames. The
3184 * downside of using it is it ignores client powersave state so it can
3185 * end up disconnecting sleeping clients in AP mode. It should fix STA
3186 * mode though because AP don't sleep.
3188 if (ar->htt.target_version_major < 3 &&
3189 (ieee80211_is_nullfunc(fc) || ieee80211_is_qos_nullfunc(fc)) &&
3190 !test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX, ar->fw_features))
3191 return ATH10K_HW_TXRX_MGMT;
3195 * Some wmi-tlv firmwares for qca6174 have broken Tx key selection for
3196 * NativeWifi txmode - it selects AP key instead of peer key. It seems
3197 * to work with Ethernet txmode so use it.
3199 * FIXME: Check if raw mode works with TDLS.
3201 if (ieee80211_is_data_present(fc) && sta && sta->tdls)
3202 return ATH10K_HW_TXRX_ETHERNET;
3204 if (test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
3205 return ATH10K_HW_TXRX_RAW;
3207 return ATH10K_HW_TXRX_NATIVE_WIFI;
3210 static bool ath10k_tx_h_use_hwcrypto(struct ieee80211_vif *vif,
3211 struct sk_buff *skb)
3213 const struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3214 const struct ieee80211_hdr *hdr = (void *)skb->data;
3215 const u32 mask = IEEE80211_TX_INTFL_DONT_ENCRYPT |
3216 IEEE80211_TX_CTL_INJECTED;
3218 if (!ieee80211_has_protected(hdr->frame_control))
3221 if ((info->flags & mask) == mask)
3225 return !ath10k_vif_to_arvif(vif)->nohwcrypt;
3230 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
3231 * Control in the header.
3233 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
3235 struct ieee80211_hdr *hdr = (void *)skb->data;
3236 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3239 if (!ieee80211_is_data_qos(hdr->frame_control))
3242 qos_ctl = ieee80211_get_qos_ctl(hdr);
3243 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
3244 skb->data, (void *)qos_ctl - (void *)skb->data);
3245 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
3247 /* Some firmware revisions don't handle sending QoS NullFunc well.
3248 * These frames are mainly used for CQM purposes so it doesn't really
3249 * matter whether QoS NullFunc or NullFunc are sent.
3251 hdr = (void *)skb->data;
3252 if (ieee80211_is_qos_nullfunc(hdr->frame_control))
3253 cb->flags &= ~ATH10K_SKB_F_QOS;
3255 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
3258 static void ath10k_tx_h_8023(struct sk_buff *skb)
3260 struct ieee80211_hdr *hdr;
3261 struct rfc1042_hdr *rfc1042;
3268 hdr = (void *)skb->data;
3269 hdrlen = ieee80211_hdrlen(hdr->frame_control);
3270 rfc1042 = (void *)skb->data + hdrlen;
3272 ether_addr_copy(da, ieee80211_get_DA(hdr));
3273 ether_addr_copy(sa, ieee80211_get_SA(hdr));
3274 type = rfc1042->snap_type;
3276 skb_pull(skb, hdrlen + sizeof(*rfc1042));
3277 skb_push(skb, sizeof(*eth));
3279 eth = (void *)skb->data;
3280 ether_addr_copy(eth->h_dest, da);
3281 ether_addr_copy(eth->h_source, sa);
3282 eth->h_proto = type;
3285 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
3286 struct ieee80211_vif *vif,
3287 struct sk_buff *skb)
3289 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3290 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3292 /* This is case only for P2P_GO */
3293 if (vif->type != NL80211_IFTYPE_AP || !vif->p2p)
3296 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
3297 spin_lock_bh(&ar->data_lock);
3298 if (arvif->u.ap.noa_data)
3299 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
3301 memcpy(skb_put(skb, arvif->u.ap.noa_len),
3302 arvif->u.ap.noa_data,
3303 arvif->u.ap.noa_len);
3304 spin_unlock_bh(&ar->data_lock);
3308 static void ath10k_mac_tx_h_fill_cb(struct ath10k *ar,
3309 struct ieee80211_vif *vif,
3310 struct sk_buff *skb)
3312 struct ieee80211_hdr *hdr = (void *)skb->data;
3313 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
3316 if (!ath10k_tx_h_use_hwcrypto(vif, skb))
3317 cb->flags |= ATH10K_SKB_F_NO_HWCRYPT;
3319 if (ieee80211_is_mgmt(hdr->frame_control))
3320 cb->flags |= ATH10K_SKB_F_MGMT;
3322 if (ieee80211_is_data_qos(hdr->frame_control))
3323 cb->flags |= ATH10K_SKB_F_QOS;
3328 bool ath10k_mac_tx_frm_has_freq(struct ath10k *ar)
3330 /* FIXME: Not really sure since when the behaviour changed. At some
3331 * point new firmware stopped requiring creation of peer entries for
3332 * offchannel tx (and actually creating them causes issues with wmi-htc
3333 * tx credit replenishment and reliability). Assuming it's at least 3.4
3334 * because that's when the `freq` was introduced to TX_FRM HTT command.
3336 return (ar->htt.target_version_major >= 3 &&
3337 ar->htt.target_version_minor >= 4 &&
3338 ar->htt.op_version == ATH10K_FW_HTT_OP_VERSION_TLV);
3341 static int ath10k_mac_tx_wmi_mgmt(struct ath10k *ar, struct sk_buff *skb)
3343 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3346 spin_lock_bh(&ar->data_lock);
3348 if (skb_queue_len(q) == ATH10K_MAX_NUM_MGMT_PENDING) {
3349 ath10k_warn(ar, "wmi mgmt tx queue is full\n");
3354 __skb_queue_tail(q, skb);
3355 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
3358 spin_unlock_bh(&ar->data_lock);
3363 static enum ath10k_mac_tx_path
3364 ath10k_mac_tx_h_get_txpath(struct ath10k *ar,
3365 struct sk_buff *skb,
3366 enum ath10k_hw_txrx_mode txmode)
3369 case ATH10K_HW_TXRX_RAW:
3370 case ATH10K_HW_TXRX_NATIVE_WIFI:
3371 case ATH10K_HW_TXRX_ETHERNET:
3372 return ATH10K_MAC_TX_HTT;
3373 case ATH10K_HW_TXRX_MGMT:
3374 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
3376 return ATH10K_MAC_TX_WMI_MGMT;
3377 else if (ar->htt.target_version_major >= 3)
3378 return ATH10K_MAC_TX_HTT;
3380 return ATH10K_MAC_TX_HTT_MGMT;
3383 return ATH10K_MAC_TX_UNKNOWN;
3386 static int ath10k_mac_tx_submit(struct ath10k *ar,
3387 enum ath10k_hw_txrx_mode txmode,
3388 enum ath10k_mac_tx_path txpath,
3389 struct sk_buff *skb)
3391 struct ath10k_htt *htt = &ar->htt;
3395 case ATH10K_MAC_TX_HTT:
3396 ret = ath10k_htt_tx(htt, txmode, skb);
3398 case ATH10K_MAC_TX_HTT_MGMT:
3399 ret = ath10k_htt_mgmt_tx(htt, skb);
3401 case ATH10K_MAC_TX_WMI_MGMT:
3402 ret = ath10k_mac_tx_wmi_mgmt(ar, skb);
3404 case ATH10K_MAC_TX_UNKNOWN:
3411 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
3413 ieee80211_free_txskb(ar->hw, skb);
3419 /* This function consumes the sk_buff regardless of return value as far as
3420 * caller is concerned so no freeing is necessary afterwards.
3422 static int ath10k_mac_tx(struct ath10k *ar,
3423 struct ieee80211_vif *vif,
3424 struct ieee80211_sta *sta,
3425 enum ath10k_hw_txrx_mode txmode,
3426 enum ath10k_mac_tx_path txpath,
3427 struct sk_buff *skb)
3429 struct ieee80211_hw *hw = ar->hw;
3430 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3433 /* We should disable CCK RATE due to P2P */
3434 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
3435 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
3438 case ATH10K_HW_TXRX_MGMT:
3439 case ATH10K_HW_TXRX_NATIVE_WIFI:
3440 ath10k_tx_h_nwifi(hw, skb);
3441 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
3442 ath10k_tx_h_seq_no(vif, skb);
3444 case ATH10K_HW_TXRX_ETHERNET:
3445 ath10k_tx_h_8023(skb);
3447 case ATH10K_HW_TXRX_RAW:
3448 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
3450 ieee80211_free_txskb(hw, skb);
3455 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
3456 if (!ath10k_mac_tx_frm_has_freq(ar)) {
3457 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
3460 skb_queue_tail(&ar->offchan_tx_queue, skb);
3461 ieee80211_queue_work(hw, &ar->offchan_tx_work);
3466 ret = ath10k_mac_tx_submit(ar, txmode, txpath, skb);
3468 ath10k_warn(ar, "failed to submit frame: %d\n", ret);
3475 void ath10k_offchan_tx_purge(struct ath10k *ar)
3477 struct sk_buff *skb;
3480 skb = skb_dequeue(&ar->offchan_tx_queue);
3484 ieee80211_free_txskb(ar->hw, skb);
3488 void ath10k_offchan_tx_work(struct work_struct *work)
3490 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
3491 struct ath10k_peer *peer;
3492 struct ath10k_vif *arvif;
3493 enum ath10k_hw_txrx_mode txmode;
3494 enum ath10k_mac_tx_path txpath;
3495 struct ieee80211_hdr *hdr;
3496 struct ieee80211_vif *vif;
3497 struct ieee80211_sta *sta;
3498 struct sk_buff *skb;
3499 const u8 *peer_addr;
3502 unsigned long time_left;
3503 bool tmp_peer_created = false;
3505 /* FW requirement: We must create a peer before FW will send out
3506 * an offchannel frame. Otherwise the frame will be stuck and
3507 * never transmitted. We delete the peer upon tx completion.
3508 * It is unlikely that a peer for offchannel tx will already be
3509 * present. However it may be in some rare cases so account for that.
3510 * Otherwise we might remove a legitimate peer and break stuff. */
3513 skb = skb_dequeue(&ar->offchan_tx_queue);
3517 mutex_lock(&ar->conf_mutex);
3519 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
3522 hdr = (struct ieee80211_hdr *)skb->data;
3523 peer_addr = ieee80211_get_DA(hdr);
3525 spin_lock_bh(&ar->data_lock);
3526 vdev_id = ar->scan.vdev_id;
3527 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
3528 spin_unlock_bh(&ar->data_lock);
3531 /* FIXME: should this use ath10k_warn()? */
3532 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
3533 peer_addr, vdev_id);
3536 ret = ath10k_peer_create(ar, NULL, NULL, vdev_id,
3538 WMI_PEER_TYPE_DEFAULT);
3540 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
3541 peer_addr, vdev_id, ret);
3542 tmp_peer_created = (ret == 0);
3545 spin_lock_bh(&ar->data_lock);
3546 reinit_completion(&ar->offchan_tx_completed);
3547 ar->offchan_tx_skb = skb;
3548 spin_unlock_bh(&ar->data_lock);
3550 /* It's safe to access vif and sta - conf_mutex guarantees that
3551 * sta_state() and remove_interface() are locked exclusively
3552 * out wrt to this offchannel worker.
3554 arvif = ath10k_get_arvif(ar, vdev_id);
3557 sta = ieee80211_find_sta(vif, peer_addr);
3563 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3564 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3566 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3568 ath10k_warn(ar, "failed to transmit offchannel frame: %d\n",
3574 wait_for_completion_timeout(&ar->offchan_tx_completed, 3 * HZ);
3576 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
3579 if (!peer && tmp_peer_created) {
3580 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
3582 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
3583 peer_addr, vdev_id, ret);
3586 mutex_unlock(&ar->conf_mutex);
3590 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
3592 struct sk_buff *skb;
3595 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3599 ieee80211_free_txskb(ar->hw, skb);
3603 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
3605 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
3606 struct sk_buff *skb;
3610 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
3614 ret = ath10k_wmi_mgmt_tx(ar, skb);
3616 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
3618 ieee80211_free_txskb(ar->hw, skb);
3623 static void ath10k_mac_txq_init(struct ieee80211_txq *txq)
3625 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3630 INIT_LIST_HEAD(&artxq->list);
3633 static void ath10k_mac_txq_unref(struct ath10k *ar, struct ieee80211_txq *txq)
3635 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3640 spin_lock_bh(&ar->txqs_lock);
3641 if (!list_empty(&artxq->list))
3642 list_del_init(&artxq->list);
3643 spin_unlock_bh(&ar->txqs_lock);
3646 static bool ath10k_mac_tx_can_push(struct ieee80211_hw *hw,
3647 struct ieee80211_txq *txq)
3652 static int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw,
3653 struct ieee80211_txq *txq)
3655 const bool is_mgmt = false;
3656 const bool is_presp = false;
3657 struct ath10k *ar = hw->priv;
3658 struct ath10k_htt *htt = &ar->htt;
3659 struct ieee80211_vif *vif = txq->vif;
3660 struct ieee80211_sta *sta = txq->sta;
3661 enum ath10k_hw_txrx_mode txmode;
3662 enum ath10k_mac_tx_path txpath;
3663 struct sk_buff *skb;
3666 spin_lock_bh(&ar->htt.tx_lock);
3667 ret = ath10k_htt_tx_inc_pending(htt, is_mgmt, is_presp);
3668 spin_unlock_bh(&ar->htt.tx_lock);
3673 skb = ieee80211_tx_dequeue(hw, txq);
3675 spin_lock_bh(&ar->htt.tx_lock);
3676 ath10k_htt_tx_dec_pending(htt, is_mgmt);
3677 spin_unlock_bh(&ar->htt.tx_lock);
3682 ath10k_mac_tx_h_fill_cb(ar, vif, skb);
3684 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3685 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3687 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3688 if (unlikely(ret)) {
3689 ath10k_warn(ar, "failed to push frame: %d\n", ret);
3691 spin_lock_bh(&ar->htt.tx_lock);
3692 ath10k_htt_tx_dec_pending(htt, is_mgmt);
3693 spin_unlock_bh(&ar->htt.tx_lock);
3701 void ath10k_mac_tx_push_pending(struct ath10k *ar)
3703 struct ieee80211_hw *hw = ar->hw;
3704 struct ieee80211_txq *txq;
3705 struct ath10k_txq *artxq;
3706 struct ath10k_txq *last;
3710 spin_lock_bh(&ar->txqs_lock);
3713 last = list_last_entry(&ar->txqs, struct ath10k_txq, list);
3714 while (!list_empty(&ar->txqs)) {
3715 artxq = list_first_entry(&ar->txqs, struct ath10k_txq, list);
3716 txq = container_of((void *)artxq, struct ieee80211_txq,
3719 /* Prevent aggressive sta/tid taking over tx queue */
3722 ret = ath10k_mac_tx_push_txq(hw, txq);
3727 list_del_init(&artxq->list);
3728 ath10k_htt_tx_txq_update(hw, txq);
3730 if (artxq == last || (ret < 0 && ret != -ENOENT)) {
3732 list_add_tail(&artxq->list, &ar->txqs);
3738 spin_unlock_bh(&ar->txqs_lock);
3745 void __ath10k_scan_finish(struct ath10k *ar)
3747 lockdep_assert_held(&ar->data_lock);
3749 switch (ar->scan.state) {
3750 case ATH10K_SCAN_IDLE:
3752 case ATH10K_SCAN_RUNNING:
3753 case ATH10K_SCAN_ABORTING:
3754 if (!ar->scan.is_roc)
3755 ieee80211_scan_completed(ar->hw,
3757 ATH10K_SCAN_ABORTING));
3758 else if (ar->scan.roc_notify)
3759 ieee80211_remain_on_channel_expired(ar->hw);
3761 case ATH10K_SCAN_STARTING:
3762 ar->scan.state = ATH10K_SCAN_IDLE;
3763 ar->scan_channel = NULL;
3764 ar->scan.roc_freq = 0;
3765 ath10k_offchan_tx_purge(ar);
3766 cancel_delayed_work(&ar->scan.timeout);
3767 complete_all(&ar->scan.completed);
3772 void ath10k_scan_finish(struct ath10k *ar)
3774 spin_lock_bh(&ar->data_lock);
3775 __ath10k_scan_finish(ar);
3776 spin_unlock_bh(&ar->data_lock);
3779 static int ath10k_scan_stop(struct ath10k *ar)
3781 struct wmi_stop_scan_arg arg = {
3782 .req_id = 1, /* FIXME */
3783 .req_type = WMI_SCAN_STOP_ONE,
3784 .u.scan_id = ATH10K_SCAN_ID,
3788 lockdep_assert_held(&ar->conf_mutex);
3790 ret = ath10k_wmi_stop_scan(ar, &arg);
3792 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
3796 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
3798 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
3800 } else if (ret > 0) {
3805 /* Scan state should be updated upon scan completion but in case
3806 * firmware fails to deliver the event (for whatever reason) it is
3807 * desired to clean up scan state anyway. Firmware may have just
3808 * dropped the scan completion event delivery due to transport pipe
3809 * being overflown with data and/or it can recover on its own before
3810 * next scan request is submitted.
3812 spin_lock_bh(&ar->data_lock);
3813 if (ar->scan.state != ATH10K_SCAN_IDLE)
3814 __ath10k_scan_finish(ar);
3815 spin_unlock_bh(&ar->data_lock);
3820 static void ath10k_scan_abort(struct ath10k *ar)
3824 lockdep_assert_held(&ar->conf_mutex);
3826 spin_lock_bh(&ar->data_lock);
3828 switch (ar->scan.state) {
3829 case ATH10K_SCAN_IDLE:
3830 /* This can happen if timeout worker kicked in and called
3831 * abortion while scan completion was being processed.
3834 case ATH10K_SCAN_STARTING:
3835 case ATH10K_SCAN_ABORTING:
3836 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
3837 ath10k_scan_state_str(ar->scan.state),
3840 case ATH10K_SCAN_RUNNING:
3841 ar->scan.state = ATH10K_SCAN_ABORTING;
3842 spin_unlock_bh(&ar->data_lock);
3844 ret = ath10k_scan_stop(ar);
3846 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
3848 spin_lock_bh(&ar->data_lock);
3852 spin_unlock_bh(&ar->data_lock);
3855 void ath10k_scan_timeout_work(struct work_struct *work)
3857 struct ath10k *ar = container_of(work, struct ath10k,
3860 mutex_lock(&ar->conf_mutex);
3861 ath10k_scan_abort(ar);
3862 mutex_unlock(&ar->conf_mutex);
3865 static int ath10k_start_scan(struct ath10k *ar,
3866 const struct wmi_start_scan_arg *arg)
3870 lockdep_assert_held(&ar->conf_mutex);
3872 ret = ath10k_wmi_start_scan(ar, arg);
3876 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
3878 ret = ath10k_scan_stop(ar);
3880 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3885 /* If we failed to start the scan, return error code at
3886 * this point. This is probably due to some issue in the
3887 * firmware, but no need to wedge the driver due to that...
3889 spin_lock_bh(&ar->data_lock);
3890 if (ar->scan.state == ATH10K_SCAN_IDLE) {
3891 spin_unlock_bh(&ar->data_lock);
3894 spin_unlock_bh(&ar->data_lock);
3899 /**********************/
3900 /* mac80211 callbacks */
3901 /**********************/
3903 static void ath10k_mac_op_tx(struct ieee80211_hw *hw,
3904 struct ieee80211_tx_control *control,
3905 struct sk_buff *skb)
3907 struct ath10k *ar = hw->priv;
3908 struct ath10k_htt *htt = &ar->htt;
3909 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3910 struct ieee80211_vif *vif = info->control.vif;
3911 struct ieee80211_sta *sta = control->sta;
3912 struct ieee80211_hdr *hdr = (void *)skb->data;
3913 enum ath10k_hw_txrx_mode txmode;
3914 enum ath10k_mac_tx_path txpath;
3920 ath10k_mac_tx_h_fill_cb(ar, vif, skb);
3922 txmode = ath10k_mac_tx_h_get_txmode(ar, vif, sta, skb);
3923 txpath = ath10k_mac_tx_h_get_txpath(ar, skb, txmode);
3924 is_htt = (txpath == ATH10K_MAC_TX_HTT ||
3925 txpath == ATH10K_MAC_TX_HTT_MGMT);
3928 spin_lock_bh(&ar->htt.tx_lock);
3930 is_mgmt = ieee80211_is_mgmt(hdr->frame_control);
3931 is_presp = ieee80211_is_probe_resp(hdr->frame_control);
3933 ret = ath10k_htt_tx_inc_pending(htt, is_mgmt, is_presp);
3935 ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n",
3937 spin_unlock_bh(&ar->htt.tx_lock);
3938 ieee80211_free_txskb(ar->hw, skb);
3942 spin_unlock_bh(&ar->htt.tx_lock);
3945 ret = ath10k_mac_tx(ar, vif, sta, txmode, txpath, skb);
3947 ath10k_warn(ar, "failed to transmit frame: %d\n", ret);
3949 spin_lock_bh(&ar->htt.tx_lock);
3950 ath10k_htt_tx_dec_pending(htt, is_mgmt);
3951 spin_unlock_bh(&ar->htt.tx_lock);
3957 static void ath10k_mac_op_wake_tx_queue(struct ieee80211_hw *hw,
3958 struct ieee80211_txq *txq)
3960 struct ath10k *ar = hw->priv;
3961 struct ath10k_txq *artxq = (void *)txq->drv_priv;
3963 if (ath10k_mac_tx_can_push(hw, txq)) {
3964 spin_lock_bh(&ar->txqs_lock);
3965 if (list_empty(&artxq->list))
3966 list_add_tail(&artxq->list, &ar->txqs);
3967 spin_unlock_bh(&ar->txqs_lock);
3969 tasklet_schedule(&ar->htt.txrx_compl_task);
3972 ath10k_htt_tx_txq_update(hw, txq);
3975 /* Must not be called with conf_mutex held as workers can use that also. */
3976 void ath10k_drain_tx(struct ath10k *ar)
3978 /* make sure rcu-protected mac80211 tx path itself is drained */
3981 ath10k_offchan_tx_purge(ar);
3982 ath10k_mgmt_over_wmi_tx_purge(ar);
3984 cancel_work_sync(&ar->offchan_tx_work);
3985 cancel_work_sync(&ar->wmi_mgmt_tx_work);
3988 void ath10k_halt(struct ath10k *ar)
3990 struct ath10k_vif *arvif;
3992 lockdep_assert_held(&ar->conf_mutex);
3994 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
3995 ar->filter_flags = 0;
3996 ar->monitor = false;
3997 ar->monitor_arvif = NULL;
3999 if (ar->monitor_started)
4000 ath10k_monitor_stop(ar);
4002 ar->monitor_started = false;
4005 ath10k_scan_finish(ar);
4006 ath10k_peer_cleanup_all(ar);
4007 ath10k_core_stop(ar);
4008 ath10k_hif_power_down(ar);
4010 spin_lock_bh(&ar->data_lock);
4011 list_for_each_entry(arvif, &ar->arvifs, list)
4012 ath10k_mac_vif_beacon_cleanup(arvif);
4013 spin_unlock_bh(&ar->data_lock);
4016 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4018 struct ath10k *ar = hw->priv;
4020 mutex_lock(&ar->conf_mutex);
4022 *tx_ant = ar->cfg_tx_chainmask;
4023 *rx_ant = ar->cfg_rx_chainmask;
4025 mutex_unlock(&ar->conf_mutex);
4030 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
4032 /* It is not clear that allowing gaps in chainmask
4033 * is helpful. Probably it will not do what user
4034 * is hoping for, so warn in that case.
4036 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
4039 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
4043 static int ath10k_mac_get_vht_cap_bf_sts(struct ath10k *ar)
4045 int nsts = ar->vht_cap_info;
4047 nsts &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4048 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4050 /* If firmware does not deliver to host number of space-time
4051 * streams supported, assume it support up to 4 BF STS and return
4052 * the value for VHT CAP: nsts-1)
4060 static int ath10k_mac_get_vht_cap_bf_sound_dim(struct ath10k *ar)
4062 int sound_dim = ar->vht_cap_info;
4064 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4065 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4067 /* If the sounding dimension is not advertised by the firmware,
4068 * let's use a default value of 1
4076 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4078 struct ieee80211_sta_vht_cap vht_cap = {0};
4083 vht_cap.vht_supported = 1;
4084 vht_cap.cap = ar->vht_cap_info;
4086 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4087 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
4088 val = ath10k_mac_get_vht_cap_bf_sts(ar);
4089 val <<= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4090 val &= IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4095 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4096 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
4097 val = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4098 val <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4099 val &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4105 for (i = 0; i < 8; i++) {
4106 if ((i < ar->num_rf_chains) && (ar->cfg_tx_chainmask & BIT(i)))
4107 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
4109 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
4112 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4113 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4118 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4121 struct ieee80211_sta_ht_cap ht_cap = {0};
4123 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4126 ht_cap.ht_supported = 1;
4127 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4128 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4129 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4130 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4132 WLAN_HT_CAP_SM_PS_DISABLED << IEEE80211_HT_CAP_SM_PS_SHIFT;
4134 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4135 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4137 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4138 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4140 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4143 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4144 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4149 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4150 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4152 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4155 stbc = ar->ht_cap_info;
4156 stbc &= WMI_HT_CAP_RX_STBC;
4157 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4158 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4159 stbc &= IEEE80211_HT_CAP_RX_STBC;
4164 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4165 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4167 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4168 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4170 /* max AMSDU is implicitly taken from vht_cap_info */
4171 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4172 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4174 for (i = 0; i < ar->num_rf_chains; i++) {
4175 if (ar->cfg_rx_chainmask & BIT(i))
4176 ht_cap.mcs.rx_mask[i] = 0xFF;
4179 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4184 static void ath10k_mac_setup_ht_vht_cap(struct ath10k *ar)
4186 struct ieee80211_supported_band *band;
4187 struct ieee80211_sta_vht_cap vht_cap;
4188 struct ieee80211_sta_ht_cap ht_cap;
4190 ht_cap = ath10k_get_ht_cap(ar);
4191 vht_cap = ath10k_create_vht_cap(ar);
4193 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4194 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4195 band->ht_cap = ht_cap;
4197 /* Enable the VHT support at 2.4 GHz */
4198 band->vht_cap = vht_cap;
4200 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4201 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4202 band->ht_cap = ht_cap;
4203 band->vht_cap = vht_cap;
4207 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
4211 lockdep_assert_held(&ar->conf_mutex);
4213 ath10k_check_chain_mask(ar, tx_ant, "tx");
4214 ath10k_check_chain_mask(ar, rx_ant, "rx");
4216 ar->cfg_tx_chainmask = tx_ant;
4217 ar->cfg_rx_chainmask = rx_ant;
4219 if ((ar->state != ATH10K_STATE_ON) &&
4220 (ar->state != ATH10K_STATE_RESTARTED))
4223 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
4226 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
4231 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
4234 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
4239 /* Reload HT/VHT capability */
4240 ath10k_mac_setup_ht_vht_cap(ar);
4245 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4247 struct ath10k *ar = hw->priv;
4250 mutex_lock(&ar->conf_mutex);
4251 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
4252 mutex_unlock(&ar->conf_mutex);
4256 static int ath10k_start(struct ieee80211_hw *hw)
4258 struct ath10k *ar = hw->priv;
4263 * This makes sense only when restarting hw. It is harmless to call
4264 * uncoditionally. This is necessary to make sure no HTT/WMI tx
4265 * commands will be submitted while restarting.
4267 ath10k_drain_tx(ar);
4269 mutex_lock(&ar->conf_mutex);
4271 switch (ar->state) {
4272 case ATH10K_STATE_OFF:
4273 ar->state = ATH10K_STATE_ON;
4275 case ATH10K_STATE_RESTARTING:
4277 ar->state = ATH10K_STATE_RESTARTED;
4279 case ATH10K_STATE_ON:
4280 case ATH10K_STATE_RESTARTED:
4281 case ATH10K_STATE_WEDGED:
4285 case ATH10K_STATE_UTF:
4290 ret = ath10k_hif_power_up(ar);
4292 ath10k_err(ar, "Could not init hif: %d\n", ret);
4296 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
4298 ath10k_err(ar, "Could not init core: %d\n", ret);
4299 goto err_power_down;
4302 param = ar->wmi.pdev_param->pmf_qos;
4303 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4305 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
4309 param = ar->wmi.pdev_param->dynamic_bw;
4310 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4312 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
4316 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
4317 ret = ath10k_wmi_adaptive_qcs(ar, true);
4319 ath10k_warn(ar, "failed to enable adaptive qcs: %d\n",
4325 if (test_bit(WMI_SERVICE_BURST, ar->wmi.svc_map)) {
4326 param = ar->wmi.pdev_param->burst_enable;
4327 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4329 ath10k_warn(ar, "failed to disable burst: %d\n", ret);
4334 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4337 * By default FW set ARP frames ac to voice (6). In that case ARP
4338 * exchange is not working properly for UAPSD enabled AP. ARP requests
4339 * which arrives with access category 0 are processed by network stack
4340 * and send back with access category 0, but FW changes access category
4341 * to 6. Set ARP frames access category to best effort (0) solves
4345 param = ar->wmi.pdev_param->arp_ac_override;
4346 ret = ath10k_wmi_pdev_set_param(ar, param, 0);
4348 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
4353 if (test_bit(ATH10K_FW_FEATURE_SUPPORTS_ADAPTIVE_CCA,
4355 ret = ath10k_wmi_pdev_enable_adaptive_cca(ar, 1,
4356 WMI_CCA_DETECT_LEVEL_AUTO,
4357 WMI_CCA_DETECT_MARGIN_AUTO);
4359 ath10k_warn(ar, "failed to enable adaptive cca: %d\n",
4365 param = ar->wmi.pdev_param->ani_enable;
4366 ret = ath10k_wmi_pdev_set_param(ar, param, 1);
4368 ath10k_warn(ar, "failed to enable ani by default: %d\n",
4373 ar->ani_enabled = true;
4375 if (test_bit(WMI_SERVICE_PEER_STATS, ar->wmi.svc_map)) {
4376 param = ar->wmi.pdev_param->peer_stats_update_period;
4377 ret = ath10k_wmi_pdev_set_param(ar, param,
4378 PEER_DEFAULT_STATS_UPDATE_PERIOD);
4381 "failed to set peer stats period : %d\n",
4387 ar->num_started_vdevs = 0;
4388 ath10k_regd_update(ar);
4390 ath10k_spectral_start(ar);
4391 ath10k_thermal_set_throttling(ar);
4393 mutex_unlock(&ar->conf_mutex);
4397 ath10k_core_stop(ar);
4400 ath10k_hif_power_down(ar);
4403 ar->state = ATH10K_STATE_OFF;
4406 mutex_unlock(&ar->conf_mutex);
4410 static void ath10k_stop(struct ieee80211_hw *hw)
4412 struct ath10k *ar = hw->priv;
4414 ath10k_drain_tx(ar);
4416 mutex_lock(&ar->conf_mutex);
4417 if (ar->state != ATH10K_STATE_OFF) {
4419 ar->state = ATH10K_STATE_OFF;
4421 mutex_unlock(&ar->conf_mutex);
4423 cancel_delayed_work_sync(&ar->scan.timeout);
4424 cancel_work_sync(&ar->restart_work);
4427 static int ath10k_config_ps(struct ath10k *ar)
4429 struct ath10k_vif *arvif;
4432 lockdep_assert_held(&ar->conf_mutex);
4434 list_for_each_entry(arvif, &ar->arvifs, list) {
4435 ret = ath10k_mac_vif_setup_ps(arvif);
4437 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
4445 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
4450 lockdep_assert_held(&ar->conf_mutex);
4452 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
4454 param = ar->wmi.pdev_param->txpower_limit2g;
4455 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4457 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
4462 param = ar->wmi.pdev_param->txpower_limit5g;
4463 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
4465 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
4473 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
4475 struct ath10k_vif *arvif;
4476 int ret, txpower = -1;
4478 lockdep_assert_held(&ar->conf_mutex);
4480 list_for_each_entry(arvif, &ar->arvifs, list) {
4481 WARN_ON(arvif->txpower < 0);
4484 txpower = arvif->txpower;
4486 txpower = min(txpower, arvif->txpower);
4489 if (WARN_ON(txpower == -1))
4492 ret = ath10k_mac_txpower_setup(ar, txpower);
4494 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
4502 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
4504 struct ath10k *ar = hw->priv;
4505 struct ieee80211_conf *conf = &hw->conf;
4508 mutex_lock(&ar->conf_mutex);
4510 if (changed & IEEE80211_CONF_CHANGE_PS)
4511 ath10k_config_ps(ar);
4513 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
4514 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
4515 ret = ath10k_monitor_recalc(ar);
4517 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4520 mutex_unlock(&ar->conf_mutex);
4524 static u32 get_nss_from_chainmask(u16 chain_mask)
4526 if ((chain_mask & 0xf) == 0xf)
4528 else if ((chain_mask & 0x7) == 0x7)
4530 else if ((chain_mask & 0x3) == 0x3)
4535 static int ath10k_mac_set_txbf_conf(struct ath10k_vif *arvif)
4538 struct ath10k *ar = arvif->ar;
4542 if (ath10k_wmi_get_txbf_conf_scheme(ar) != WMI_TXBF_CONF_BEFORE_ASSOC)
4545 nsts = ath10k_mac_get_vht_cap_bf_sts(ar);
4546 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
4547 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE))
4548 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4550 sound_dim = ath10k_mac_get_vht_cap_bf_sound_dim(ar);
4551 if (ar->vht_cap_info & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
4552 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE))
4553 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4558 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
4559 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4561 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
4562 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFER |
4563 WMI_VDEV_PARAM_TXBF_SU_TX_BFER);
4565 if (ar->vht_cap_info & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
4566 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4568 if (ar->vht_cap_info & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
4569 value |= (WMI_VDEV_PARAM_TXBF_MU_TX_BFEE |
4570 WMI_VDEV_PARAM_TXBF_SU_TX_BFEE);
4572 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4573 ar->wmi.vdev_param->txbf, value);
4578 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
4579 * because we will send mgmt frames without CCK. This requirement
4580 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
4583 static int ath10k_add_interface(struct ieee80211_hw *hw,
4584 struct ieee80211_vif *vif)
4586 struct ath10k *ar = hw->priv;
4587 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4588 struct ath10k_peer *peer;
4589 enum wmi_sta_powersave_param param;
4596 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4598 mutex_lock(&ar->conf_mutex);
4600 memset(arvif, 0, sizeof(*arvif));
4601 ath10k_mac_txq_init(vif->txq);
4606 INIT_LIST_HEAD(&arvif->list);
4607 INIT_WORK(&arvif->ap_csa_work, ath10k_mac_vif_ap_csa_work);
4608 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4609 ath10k_mac_vif_sta_connection_loss_work);
4611 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4612 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4613 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4614 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4615 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4616 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4619 if (ar->num_peers >= ar->max_num_peers) {
4620 ath10k_warn(ar, "refusing vdev creation due to insufficient peer entry resources in firmware\n");
4625 if (ar->free_vdev_map == 0) {
4626 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
4630 bit = __ffs64(ar->free_vdev_map);
4632 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
4633 bit, ar->free_vdev_map);
4635 arvif->vdev_id = bit;
4636 arvif->vdev_subtype =
4637 ath10k_wmi_get_vdev_subtype(ar, WMI_VDEV_SUBTYPE_NONE);
4639 switch (vif->type) {
4640 case NL80211_IFTYPE_P2P_DEVICE:
4641 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4642 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4643 (ar, WMI_VDEV_SUBTYPE_P2P_DEVICE);
4645 case NL80211_IFTYPE_UNSPECIFIED:
4646 case NL80211_IFTYPE_STATION:
4647 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4649 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4650 (ar, WMI_VDEV_SUBTYPE_P2P_CLIENT);
4652 case NL80211_IFTYPE_ADHOC:
4653 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
4655 case NL80211_IFTYPE_MESH_POINT:
4656 if (test_bit(WMI_SERVICE_MESH_11S, ar->wmi.svc_map)) {
4657 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4658 (ar, WMI_VDEV_SUBTYPE_MESH_11S);
4659 } else if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4661 ath10k_warn(ar, "must load driver with rawmode=1 to add mesh interfaces\n");
4664 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4666 case NL80211_IFTYPE_AP:
4667 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4670 arvif->vdev_subtype = ath10k_wmi_get_vdev_subtype
4671 (ar, WMI_VDEV_SUBTYPE_P2P_GO);
4673 case NL80211_IFTYPE_MONITOR:
4674 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4681 /* Using vdev_id as queue number will make it very easy to do per-vif
4682 * tx queue locking. This shouldn't wrap due to interface combinations
4683 * but do a modulo for correctness sake and prevent using offchannel tx
4684 * queues for regular vif tx.
4686 vif->cab_queue = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4687 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4688 vif->hw_queue[i] = arvif->vdev_id % (IEEE80211_MAX_QUEUES - 1);
4690 /* Some firmware revisions don't wait for beacon tx completion before
4691 * sending another SWBA event. This could lead to hardware using old
4692 * (freed) beacon data in some cases, e.g. tx credit starvation
4693 * combined with missed TBTT. This is very very rare.
4695 * On non-IOMMU-enabled hosts this could be a possible security issue
4696 * because hw could beacon some random data on the air. On
4697 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
4698 * device would crash.
4700 * Since there are no beacon tx completions (implicit nor explicit)
4701 * propagated to host the only workaround for this is to allocate a
4702 * DMA-coherent buffer for a lifetime of a vif and use it for all
4703 * beacon tx commands. Worst case for this approach is some beacons may
4704 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
4706 if (vif->type == NL80211_IFTYPE_ADHOC ||
4707 vif->type == NL80211_IFTYPE_MESH_POINT ||
4708 vif->type == NL80211_IFTYPE_AP) {
4709 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
4710 IEEE80211_MAX_FRAME_LEN,
4711 &arvif->beacon_paddr,
4713 if (!arvif->beacon_buf) {
4715 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
4720 if (test_bit(ATH10K_FLAG_HW_CRYPTO_DISABLED, &ar->dev_flags))
4721 arvif->nohwcrypt = true;
4723 if (arvif->nohwcrypt &&
4724 !test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags)) {
4725 ath10k_warn(ar, "cryptmode module param needed for sw crypto\n");
4729 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
4730 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4731 arvif->beacon_buf ? "single-buf" : "per-skb");
4733 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
4734 arvif->vdev_subtype, vif->addr);
4736 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
4737 arvif->vdev_id, ret);
4741 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
4742 list_add(&arvif->list, &ar->arvifs);
4744 /* It makes no sense to have firmware do keepalives. mac80211 already
4745 * takes care of this with idle connection polling.
4747 ret = ath10k_mac_vif_disable_keepalive(arvif);
4749 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
4750 arvif->vdev_id, ret);
4751 goto err_vdev_delete;
4754 arvif->def_wep_key_idx = -1;
4756 vdev_param = ar->wmi.vdev_param->tx_encap_type;
4757 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4758 ATH10K_HW_TXRX_NATIVE_WIFI);
4759 /* 10.X firmware does not support this VDEV parameter. Do not warn */
4760 if (ret && ret != -EOPNOTSUPP) {
4761 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
4762 arvif->vdev_id, ret);
4763 goto err_vdev_delete;
4766 if (ar->cfg_tx_chainmask) {
4767 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4769 vdev_param = ar->wmi.vdev_param->nss;
4770 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4773 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
4774 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
4776 goto err_vdev_delete;
4780 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4781 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4782 ret = ath10k_peer_create(ar, vif, NULL, arvif->vdev_id,
4783 vif->addr, WMI_PEER_TYPE_DEFAULT);
4785 ath10k_warn(ar, "failed to create vdev %i peer for AP/IBSS: %d\n",
4786 arvif->vdev_id, ret);
4787 goto err_vdev_delete;
4790 spin_lock_bh(&ar->data_lock);
4792 peer = ath10k_peer_find(ar, arvif->vdev_id, vif->addr);
4794 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
4795 vif->addr, arvif->vdev_id);
4796 spin_unlock_bh(&ar->data_lock);
4798 goto err_peer_delete;
4801 arvif->peer_id = find_first_bit(peer->peer_ids,
4802 ATH10K_MAX_NUM_PEER_IDS);
4804 spin_unlock_bh(&ar->data_lock);
4806 arvif->peer_id = HTT_INVALID_PEERID;
4809 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4810 ret = ath10k_mac_set_kickout(arvif);
4812 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
4813 arvif->vdev_id, ret);
4814 goto err_peer_delete;
4818 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
4819 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4820 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4821 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4824 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
4825 arvif->vdev_id, ret);
4826 goto err_peer_delete;
4829 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4831 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4832 arvif->vdev_id, ret);
4833 goto err_peer_delete;
4836 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4838 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4839 arvif->vdev_id, ret);
4840 goto err_peer_delete;
4844 ret = ath10k_mac_set_txbf_conf(arvif);
4846 ath10k_warn(ar, "failed to set txbf for vdev %d: %d\n",
4847 arvif->vdev_id, ret);
4848 goto err_peer_delete;
4851 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
4853 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4854 arvif->vdev_id, ret);
4855 goto err_peer_delete;
4858 arvif->txpower = vif->bss_conf.txpower;
4859 ret = ath10k_mac_txpower_recalc(ar);
4861 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
4862 goto err_peer_delete;
4865 if (vif->type == NL80211_IFTYPE_MONITOR) {
4866 ar->monitor_arvif = arvif;
4867 ret = ath10k_monitor_recalc(ar);
4869 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4870 goto err_peer_delete;
4874 spin_lock_bh(&ar->htt.tx_lock);
4876 ieee80211_wake_queue(ar->hw, arvif->vdev_id);
4877 spin_unlock_bh(&ar->htt.tx_lock);
4879 mutex_unlock(&ar->conf_mutex);
4883 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4884 arvif->vdev_type == WMI_VDEV_TYPE_IBSS)
4885 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
4888 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4889 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4890 list_del(&arvif->list);
4893 if (arvif->beacon_buf) {
4894 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
4895 arvif->beacon_buf, arvif->beacon_paddr);
4896 arvif->beacon_buf = NULL;
4899 mutex_unlock(&ar->conf_mutex);
4904 static void ath10k_mac_vif_tx_unlock_all(struct ath10k_vif *arvif)
4908 for (i = 0; i < BITS_PER_LONG; i++)
4909 ath10k_mac_vif_tx_unlock(arvif, i);
4912 static void ath10k_remove_interface(struct ieee80211_hw *hw,
4913 struct ieee80211_vif *vif)
4915 struct ath10k *ar = hw->priv;
4916 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4917 struct ath10k_peer *peer;
4921 cancel_work_sync(&arvif->ap_csa_work);
4922 cancel_delayed_work_sync(&arvif->connection_loss_work);
4924 mutex_lock(&ar->conf_mutex);
4926 spin_lock_bh(&ar->data_lock);
4927 ath10k_mac_vif_beacon_cleanup(arvif);
4928 spin_unlock_bh(&ar->data_lock);
4930 ret = ath10k_spectral_vif_stop(arvif);
4932 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
4933 arvif->vdev_id, ret);
4935 ar->free_vdev_map |= 1LL << arvif->vdev_id;
4936 list_del(&arvif->list);
4938 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4939 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4940 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
4943 ath10k_warn(ar, "failed to submit AP/IBSS self-peer removal on vdev %i: %d\n",
4944 arvif->vdev_id, ret);
4946 kfree(arvif->u.ap.noa_data);
4949 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
4952 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
4954 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
4955 arvif->vdev_id, ret);
4957 /* Some firmware revisions don't notify host about self-peer removal
4958 * until after associated vdev is deleted.
4960 if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
4961 arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
4962 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
4965 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
4966 arvif->vdev_id, ret);
4968 spin_lock_bh(&ar->data_lock);
4970 spin_unlock_bh(&ar->data_lock);
4973 spin_lock_bh(&ar->data_lock);
4974 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
4975 peer = ar->peer_map[i];
4979 if (peer->vif == vif) {
4980 ath10k_warn(ar, "found vif peer %pM entry on vdev %i after it was supposedly removed\n",
4981 vif->addr, arvif->vdev_id);
4985 spin_unlock_bh(&ar->data_lock);
4987 ath10k_peer_cleanup(ar, arvif->vdev_id);
4989 if (vif->type == NL80211_IFTYPE_MONITOR) {
4990 ar->monitor_arvif = NULL;
4991 ret = ath10k_monitor_recalc(ar);
4993 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
4996 spin_lock_bh(&ar->htt.tx_lock);
4997 ath10k_mac_vif_tx_unlock_all(arvif);
4998 spin_unlock_bh(&ar->htt.tx_lock);
5000 ath10k_mac_txq_unref(ar, vif->txq);
5002 mutex_unlock(&ar->conf_mutex);
5006 * FIXME: Has to be verified.
5008 #define SUPPORTED_FILTERS \
5013 FIF_BCN_PRBRESP_PROMISC | \
5017 static void ath10k_configure_filter(struct ieee80211_hw *hw,
5018 unsigned int changed_flags,
5019 unsigned int *total_flags,
5022 struct ath10k *ar = hw->priv;
5025 mutex_lock(&ar->conf_mutex);
5027 changed_flags &= SUPPORTED_FILTERS;
5028 *total_flags &= SUPPORTED_FILTERS;
5029 ar->filter_flags = *total_flags;
5031 ret = ath10k_monitor_recalc(ar);
5033 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
5035 mutex_unlock(&ar->conf_mutex);
5038 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
5039 struct ieee80211_vif *vif,
5040 struct ieee80211_bss_conf *info,
5043 struct ath10k *ar = hw->priv;
5044 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5046 u32 vdev_param, pdev_param, slottime, preamble;
5048 mutex_lock(&ar->conf_mutex);
5050 if (changed & BSS_CHANGED_IBSS)
5051 ath10k_control_ibss(arvif, info, vif->addr);
5053 if (changed & BSS_CHANGED_BEACON_INT) {
5054 arvif->beacon_interval = info->beacon_int;
5055 vdev_param = ar->wmi.vdev_param->beacon_interval;
5056 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5057 arvif->beacon_interval);
5058 ath10k_dbg(ar, ATH10K_DBG_MAC,
5059 "mac vdev %d beacon_interval %d\n",
5060 arvif->vdev_id, arvif->beacon_interval);
5063 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
5064 arvif->vdev_id, ret);
5067 if (changed & BSS_CHANGED_BEACON) {
5068 ath10k_dbg(ar, ATH10K_DBG_MAC,
5069 "vdev %d set beacon tx mode to staggered\n",
5072 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
5073 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
5074 WMI_BEACON_STAGGERED_MODE);
5076 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
5077 arvif->vdev_id, ret);
5079 ret = ath10k_mac_setup_bcn_tmpl(arvif);
5081 ath10k_warn(ar, "failed to update beacon template: %d\n",
5084 if (ieee80211_vif_is_mesh(vif)) {
5085 /* mesh doesn't use SSID but firmware needs it */
5086 strncpy(arvif->u.ap.ssid, "mesh",
5087 sizeof(arvif->u.ap.ssid));
5088 arvif->u.ap.ssid_len = 4;
5092 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
5093 ret = ath10k_mac_setup_prb_tmpl(arvif);
5095 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
5096 arvif->vdev_id, ret);
5099 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
5100 arvif->dtim_period = info->dtim_period;
5102 ath10k_dbg(ar, ATH10K_DBG_MAC,
5103 "mac vdev %d dtim_period %d\n",
5104 arvif->vdev_id, arvif->dtim_period);
5106 vdev_param = ar->wmi.vdev_param->dtim_period;
5107 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5108 arvif->dtim_period);
5110 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
5111 arvif->vdev_id, ret);
5114 if (changed & BSS_CHANGED_SSID &&
5115 vif->type == NL80211_IFTYPE_AP) {
5116 arvif->u.ap.ssid_len = info->ssid_len;
5118 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
5119 arvif->u.ap.hidden_ssid = info->hidden_ssid;
5122 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
5123 ether_addr_copy(arvif->bssid, info->bssid);
5125 if (changed & BSS_CHANGED_BEACON_ENABLED)
5126 ath10k_control_beaconing(arvif, info);
5128 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
5129 arvif->use_cts_prot = info->use_cts_prot;
5130 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
5131 arvif->vdev_id, info->use_cts_prot);
5133 ret = ath10k_recalc_rtscts_prot(arvif);
5135 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
5136 arvif->vdev_id, ret);
5138 vdev_param = ar->wmi.vdev_param->protection_mode;
5139 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5140 info->use_cts_prot ? 1 : 0);
5142 ath10k_warn(ar, "failed to set protection mode %d on vdev %i: %d\n",
5143 info->use_cts_prot, arvif->vdev_id, ret);
5146 if (changed & BSS_CHANGED_ERP_SLOT) {
5147 if (info->use_short_slot)
5148 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
5151 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
5153 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
5154 arvif->vdev_id, slottime);
5156 vdev_param = ar->wmi.vdev_param->slot_time;
5157 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5160 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
5161 arvif->vdev_id, ret);
5164 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
5165 if (info->use_short_preamble)
5166 preamble = WMI_VDEV_PREAMBLE_SHORT;
5168 preamble = WMI_VDEV_PREAMBLE_LONG;
5170 ath10k_dbg(ar, ATH10K_DBG_MAC,
5171 "mac vdev %d preamble %dn",
5172 arvif->vdev_id, preamble);
5174 vdev_param = ar->wmi.vdev_param->preamble;
5175 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5178 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
5179 arvif->vdev_id, ret);
5182 if (changed & BSS_CHANGED_ASSOC) {
5184 /* Workaround: Make sure monitor vdev is not running
5185 * when associating to prevent some firmware revisions
5186 * (e.g. 10.1 and 10.2) from crashing.
5188 if (ar->monitor_started)
5189 ath10k_monitor_stop(ar);
5190 ath10k_bss_assoc(hw, vif, info);
5191 ath10k_monitor_recalc(ar);
5193 ath10k_bss_disassoc(hw, vif);
5197 if (changed & BSS_CHANGED_TXPOWER) {
5198 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
5199 arvif->vdev_id, info->txpower);
5201 arvif->txpower = info->txpower;
5202 ret = ath10k_mac_txpower_recalc(ar);
5204 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
5207 if (changed & BSS_CHANGED_PS) {
5208 arvif->ps = vif->bss_conf.ps;
5210 ret = ath10k_config_ps(ar);
5212 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
5213 arvif->vdev_id, ret);
5216 mutex_unlock(&ar->conf_mutex);
5219 static int ath10k_hw_scan(struct ieee80211_hw *hw,
5220 struct ieee80211_vif *vif,
5221 struct ieee80211_scan_request *hw_req)
5223 struct ath10k *ar = hw->priv;
5224 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5225 struct cfg80211_scan_request *req = &hw_req->req;
5226 struct wmi_start_scan_arg arg;
5230 mutex_lock(&ar->conf_mutex);
5232 spin_lock_bh(&ar->data_lock);
5233 switch (ar->scan.state) {
5234 case ATH10K_SCAN_IDLE:
5235 reinit_completion(&ar->scan.started);
5236 reinit_completion(&ar->scan.completed);
5237 ar->scan.state = ATH10K_SCAN_STARTING;
5238 ar->scan.is_roc = false;
5239 ar->scan.vdev_id = arvif->vdev_id;
5242 case ATH10K_SCAN_STARTING:
5243 case ATH10K_SCAN_RUNNING:
5244 case ATH10K_SCAN_ABORTING:
5248 spin_unlock_bh(&ar->data_lock);
5253 memset(&arg, 0, sizeof(arg));
5254 ath10k_wmi_start_scan_init(ar, &arg);
5255 arg.vdev_id = arvif->vdev_id;
5256 arg.scan_id = ATH10K_SCAN_ID;
5259 arg.ie_len = req->ie_len;
5260 memcpy(arg.ie, req->ie, arg.ie_len);
5264 arg.n_ssids = req->n_ssids;
5265 for (i = 0; i < arg.n_ssids; i++) {
5266 arg.ssids[i].len = req->ssids[i].ssid_len;
5267 arg.ssids[i].ssid = req->ssids[i].ssid;
5270 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
5273 if (req->n_channels) {
5274 arg.n_channels = req->n_channels;
5275 for (i = 0; i < arg.n_channels; i++)
5276 arg.channels[i] = req->channels[i]->center_freq;
5279 ret = ath10k_start_scan(ar, &arg);
5281 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
5282 spin_lock_bh(&ar->data_lock);
5283 ar->scan.state = ATH10K_SCAN_IDLE;
5284 spin_unlock_bh(&ar->data_lock);
5287 /* Add a 200ms margin to account for event/command processing */
5288 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
5289 msecs_to_jiffies(arg.max_scan_time +
5293 mutex_unlock(&ar->conf_mutex);
5297 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
5298 struct ieee80211_vif *vif)
5300 struct ath10k *ar = hw->priv;
5302 mutex_lock(&ar->conf_mutex);
5303 ath10k_scan_abort(ar);
5304 mutex_unlock(&ar->conf_mutex);
5306 cancel_delayed_work_sync(&ar->scan.timeout);
5309 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
5310 struct ath10k_vif *arvif,
5311 enum set_key_cmd cmd,
5312 struct ieee80211_key_conf *key)
5314 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
5317 /* 10.1 firmware branch requires default key index to be set to group
5318 * key index after installing it. Otherwise FW/HW Txes corrupted
5319 * frames with multi-vif APs. This is not required for main firmware
5320 * branch (e.g. 636).
5322 * This is also needed for 636 fw for IBSS-RSN to work more reliably.
5324 * FIXME: It remains unknown if this is required for multi-vif STA
5325 * interfaces on 10.1.
5328 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5329 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
5332 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
5335 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
5338 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5344 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
5347 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
5348 arvif->vdev_id, ret);
5351 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5352 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
5353 struct ieee80211_key_conf *key)
5355 struct ath10k *ar = hw->priv;
5356 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5357 struct ath10k_peer *peer;
5358 const u8 *peer_addr;
5359 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
5360 key->cipher == WLAN_CIPHER_SUITE_WEP104;
5366 /* this one needs to be done in software */
5367 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
5370 if (arvif->nohwcrypt)
5373 if (key->keyidx > WMI_MAX_KEY_INDEX)
5376 mutex_lock(&ar->conf_mutex);
5379 peer_addr = sta->addr;
5380 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
5381 peer_addr = vif->bss_conf.bssid;
5383 peer_addr = vif->addr;
5385 key->hw_key_idx = key->keyidx;
5389 arvif->wep_keys[key->keyidx] = key;
5391 arvif->wep_keys[key->keyidx] = NULL;
5394 /* the peer should not disappear in mid-way (unless FW goes awry) since
5395 * we already hold conf_mutex. we just make sure its there now. */
5396 spin_lock_bh(&ar->data_lock);
5397 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5398 spin_unlock_bh(&ar->data_lock);
5401 if (cmd == SET_KEY) {
5402 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
5407 /* if the peer doesn't exist there is no key to disable
5413 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
5414 flags |= WMI_KEY_PAIRWISE;
5416 flags |= WMI_KEY_GROUP;
5419 if (cmd == DISABLE_KEY)
5420 ath10k_clear_vdev_key(arvif, key);
5422 /* When WEP keys are uploaded it's possible that there are
5423 * stations associated already (e.g. when merging) without any
5424 * keys. Static WEP needs an explicit per-peer key upload.
5426 if (vif->type == NL80211_IFTYPE_ADHOC &&
5428 ath10k_mac_vif_update_wep_key(arvif, key);
5430 /* 802.1x never sets the def_wep_key_idx so each set_key()
5431 * call changes default tx key.
5433 * Static WEP sets def_wep_key_idx via .set_default_unicast_key
5434 * after first set_key().
5436 if (cmd == SET_KEY && arvif->def_wep_key_idx == -1)
5437 flags |= WMI_KEY_TX_USAGE;
5440 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags);
5443 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
5444 arvif->vdev_id, peer_addr, ret);
5448 /* mac80211 sets static WEP keys as groupwise while firmware requires
5449 * them to be installed twice as both pairwise and groupwise.
5451 if (is_wep && !sta && vif->type == NL80211_IFTYPE_STATION) {
5453 flags2 &= ~WMI_KEY_GROUP;
5454 flags2 |= WMI_KEY_PAIRWISE;
5456 ret = ath10k_install_key(arvif, key, cmd, peer_addr, flags2);
5459 ath10k_warn(ar, "failed to install (ucast) key for vdev %i peer %pM: %d\n",
5460 arvif->vdev_id, peer_addr, ret);
5461 ret2 = ath10k_install_key(arvif, key, DISABLE_KEY,
5465 ath10k_warn(ar, "failed to disable (mcast) key for vdev %i peer %pM: %d\n",
5466 arvif->vdev_id, peer_addr, ret2);
5472 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
5474 spin_lock_bh(&ar->data_lock);
5475 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
5476 if (peer && cmd == SET_KEY)
5477 peer->keys[key->keyidx] = key;
5478 else if (peer && cmd == DISABLE_KEY)
5479 peer->keys[key->keyidx] = NULL;
5480 else if (peer == NULL)
5481 /* impossible unless FW goes crazy */
5482 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
5483 spin_unlock_bh(&ar->data_lock);
5486 mutex_unlock(&ar->conf_mutex);
5490 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
5491 struct ieee80211_vif *vif,
5494 struct ath10k *ar = hw->priv;
5495 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5498 mutex_lock(&arvif->ar->conf_mutex);
5500 if (arvif->ar->state != ATH10K_STATE_ON)
5503 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
5504 arvif->vdev_id, keyidx);
5506 ret = ath10k_wmi_vdev_set_param(arvif->ar,
5508 arvif->ar->wmi.vdev_param->def_keyid,
5512 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
5518 arvif->def_wep_key_idx = keyidx;
5521 mutex_unlock(&arvif->ar->conf_mutex);
5524 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
5527 struct ath10k_vif *arvif;
5528 struct ath10k_sta *arsta;
5529 struct ieee80211_sta *sta;
5530 struct cfg80211_chan_def def;
5531 enum ieee80211_band band;
5532 const u8 *ht_mcs_mask;
5533 const u16 *vht_mcs_mask;
5534 u32 changed, bw, nss, smps;
5537 arsta = container_of(wk, struct ath10k_sta, update_wk);
5538 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
5539 arvif = arsta->arvif;
5542 if (WARN_ON(ath10k_mac_vif_chan(arvif->vif, &def)))
5545 band = def.chan->band;
5546 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
5547 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
5549 spin_lock_bh(&ar->data_lock);
5551 changed = arsta->changed;
5558 spin_unlock_bh(&ar->data_lock);
5560 mutex_lock(&ar->conf_mutex);
5562 nss = max_t(u32, 1, nss);
5563 nss = min(nss, max(ath10k_mac_max_ht_nss(ht_mcs_mask),
5564 ath10k_mac_max_vht_nss(vht_mcs_mask)));
5566 if (changed & IEEE80211_RC_BW_CHANGED) {
5567 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
5570 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5571 WMI_PEER_CHAN_WIDTH, bw);
5573 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
5574 sta->addr, bw, err);
5577 if (changed & IEEE80211_RC_NSS_CHANGED) {
5578 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
5581 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5584 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
5585 sta->addr, nss, err);
5588 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5589 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
5592 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
5593 WMI_PEER_SMPS_STATE, smps);
5595 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
5596 sta->addr, smps, err);
5599 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
5600 changed & IEEE80211_RC_NSS_CHANGED) {
5601 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
5604 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
5606 ath10k_warn(ar, "failed to reassociate station: %pM\n",
5610 mutex_unlock(&ar->conf_mutex);
5613 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif,
5614 struct ieee80211_sta *sta)
5616 struct ath10k *ar = arvif->ar;
5618 lockdep_assert_held(&ar->conf_mutex);
5620 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5623 if (ar->num_stations >= ar->max_num_stations)
5631 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif,
5632 struct ieee80211_sta *sta)
5634 struct ath10k *ar = arvif->ar;
5636 lockdep_assert_held(&ar->conf_mutex);
5638 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
5644 struct ath10k_mac_tdls_iter_data {
5645 u32 num_tdls_stations;
5646 struct ieee80211_vif *curr_vif;
5649 static void ath10k_mac_tdls_vif_stations_count_iter(void *data,
5650 struct ieee80211_sta *sta)
5652 struct ath10k_mac_tdls_iter_data *iter_data = data;
5653 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5654 struct ieee80211_vif *sta_vif = arsta->arvif->vif;
5656 if (sta->tdls && sta_vif == iter_data->curr_vif)
5657 iter_data->num_tdls_stations++;
5660 static int ath10k_mac_tdls_vif_stations_count(struct ieee80211_hw *hw,
5661 struct ieee80211_vif *vif)
5663 struct ath10k_mac_tdls_iter_data data = {};
5665 data.curr_vif = vif;
5667 ieee80211_iterate_stations_atomic(hw,
5668 ath10k_mac_tdls_vif_stations_count_iter,
5670 return data.num_tdls_stations;
5673 static void ath10k_mac_tdls_vifs_count_iter(void *data, u8 *mac,
5674 struct ieee80211_vif *vif)
5676 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5677 int *num_tdls_vifs = data;
5679 if (vif->type != NL80211_IFTYPE_STATION)
5682 if (ath10k_mac_tdls_vif_stations_count(arvif->ar->hw, vif) > 0)
5686 static int ath10k_mac_tdls_vifs_count(struct ieee80211_hw *hw)
5688 int num_tdls_vifs = 0;
5690 ieee80211_iterate_active_interfaces_atomic(hw,
5691 IEEE80211_IFACE_ITER_NORMAL,
5692 ath10k_mac_tdls_vifs_count_iter,
5694 return num_tdls_vifs;
5697 static int ath10k_sta_state(struct ieee80211_hw *hw,
5698 struct ieee80211_vif *vif,
5699 struct ieee80211_sta *sta,
5700 enum ieee80211_sta_state old_state,
5701 enum ieee80211_sta_state new_state)
5703 struct ath10k *ar = hw->priv;
5704 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5705 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
5706 struct ath10k_peer *peer;
5710 if (old_state == IEEE80211_STA_NOTEXIST &&
5711 new_state == IEEE80211_STA_NONE) {
5712 memset(arsta, 0, sizeof(*arsta));
5713 arsta->arvif = arvif;
5714 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
5716 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5717 ath10k_mac_txq_init(sta->txq[i]);
5720 /* cancel must be done outside the mutex to avoid deadlock */
5721 if ((old_state == IEEE80211_STA_NONE &&
5722 new_state == IEEE80211_STA_NOTEXIST))
5723 cancel_work_sync(&arsta->update_wk);
5725 mutex_lock(&ar->conf_mutex);
5727 if (old_state == IEEE80211_STA_NOTEXIST &&
5728 new_state == IEEE80211_STA_NONE) {
5730 * New station addition.
5732 enum wmi_peer_type peer_type = WMI_PEER_TYPE_DEFAULT;
5733 u32 num_tdls_stations;
5736 ath10k_dbg(ar, ATH10K_DBG_MAC,
5737 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
5738 arvif->vdev_id, sta->addr,
5739 ar->num_stations + 1, ar->max_num_stations,
5740 ar->num_peers + 1, ar->max_num_peers);
5742 ret = ath10k_mac_inc_num_stations(arvif, sta);
5744 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
5745 ar->max_num_stations);
5750 peer_type = WMI_PEER_TYPE_TDLS;
5752 ret = ath10k_peer_create(ar, vif, sta, arvif->vdev_id,
5753 sta->addr, peer_type);
5755 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
5756 sta->addr, arvif->vdev_id, ret);
5757 ath10k_mac_dec_num_stations(arvif, sta);
5761 spin_lock_bh(&ar->data_lock);
5763 peer = ath10k_peer_find(ar, arvif->vdev_id, sta->addr);
5765 ath10k_warn(ar, "failed to lookup peer %pM on vdev %i\n",
5766 vif->addr, arvif->vdev_id);
5767 spin_unlock_bh(&ar->data_lock);
5768 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5769 ath10k_mac_dec_num_stations(arvif, sta);
5774 arsta->peer_id = find_first_bit(peer->peer_ids,
5775 ATH10K_MAX_NUM_PEER_IDS);
5777 spin_unlock_bh(&ar->data_lock);
5782 num_tdls_stations = ath10k_mac_tdls_vif_stations_count(hw, vif);
5783 num_tdls_vifs = ath10k_mac_tdls_vifs_count(hw);
5785 if (num_tdls_vifs >= ar->max_num_tdls_vdevs &&
5786 num_tdls_stations == 0) {
5787 ath10k_warn(ar, "vdev %i exceeded maximum number of tdls vdevs %i\n",
5788 arvif->vdev_id, ar->max_num_tdls_vdevs);
5789 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5790 ath10k_mac_dec_num_stations(arvif, sta);
5795 if (num_tdls_stations == 0) {
5796 /* This is the first tdls peer in current vif */
5797 enum wmi_tdls_state state = WMI_TDLS_ENABLE_ACTIVE;
5799 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5802 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5803 arvif->vdev_id, ret);
5804 ath10k_peer_delete(ar, arvif->vdev_id,
5806 ath10k_mac_dec_num_stations(arvif, sta);
5811 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5812 WMI_TDLS_PEER_STATE_PEERING);
5815 "failed to update tdls peer %pM for vdev %d when adding a new sta: %i\n",
5816 sta->addr, arvif->vdev_id, ret);
5817 ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5818 ath10k_mac_dec_num_stations(arvif, sta);
5820 if (num_tdls_stations != 0)
5822 ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5825 } else if ((old_state == IEEE80211_STA_NONE &&
5826 new_state == IEEE80211_STA_NOTEXIST)) {
5828 * Existing station deletion.
5830 ath10k_dbg(ar, ATH10K_DBG_MAC,
5831 "mac vdev %d peer delete %pM (sta gone)\n",
5832 arvif->vdev_id, sta->addr);
5834 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
5836 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
5837 sta->addr, arvif->vdev_id, ret);
5839 ath10k_mac_dec_num_stations(arvif, sta);
5841 spin_lock_bh(&ar->data_lock);
5842 for (i = 0; i < ARRAY_SIZE(ar->peer_map); i++) {
5843 peer = ar->peer_map[i];
5847 if (peer->sta == sta) {
5848 ath10k_warn(ar, "found sta peer %pM entry on vdev %i after it was supposedly removed\n",
5849 sta->addr, arvif->vdev_id);
5853 spin_unlock_bh(&ar->data_lock);
5855 for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
5856 ath10k_mac_txq_unref(ar, sta->txq[i]);
5861 if (ath10k_mac_tdls_vif_stations_count(hw, vif))
5864 /* This was the last tdls peer in current vif */
5865 ret = ath10k_wmi_update_fw_tdls_state(ar, arvif->vdev_id,
5868 ath10k_warn(ar, "failed to update fw tdls state on vdev %i: %i\n",
5869 arvif->vdev_id, ret);
5871 } else if (old_state == IEEE80211_STA_AUTH &&
5872 new_state == IEEE80211_STA_ASSOC &&
5873 (vif->type == NL80211_IFTYPE_AP ||
5874 vif->type == NL80211_IFTYPE_MESH_POINT ||
5875 vif->type == NL80211_IFTYPE_ADHOC)) {
5879 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
5882 ret = ath10k_station_assoc(ar, vif, sta, false);
5884 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
5885 sta->addr, arvif->vdev_id, ret);
5886 } else if (old_state == IEEE80211_STA_ASSOC &&
5887 new_state == IEEE80211_STA_AUTHORIZED &&
5890 * Tdls station authorized.
5892 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac tdls sta %pM authorized\n",
5895 ret = ath10k_station_assoc(ar, vif, sta, false);
5897 ath10k_warn(ar, "failed to associate tdls station %pM for vdev %i: %i\n",
5898 sta->addr, arvif->vdev_id, ret);
5902 ret = ath10k_mac_tdls_peer_update(ar, arvif->vdev_id, sta,
5903 WMI_TDLS_PEER_STATE_CONNECTED);
5905 ath10k_warn(ar, "failed to update tdls peer %pM for vdev %i: %i\n",
5906 sta->addr, arvif->vdev_id, ret);
5907 } else if (old_state == IEEE80211_STA_ASSOC &&
5908 new_state == IEEE80211_STA_AUTH &&
5909 (vif->type == NL80211_IFTYPE_AP ||
5910 vif->type == NL80211_IFTYPE_MESH_POINT ||
5911 vif->type == NL80211_IFTYPE_ADHOC)) {
5915 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
5918 ret = ath10k_station_disassoc(ar, vif, sta);
5920 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
5921 sta->addr, arvif->vdev_id, ret);
5924 mutex_unlock(&ar->conf_mutex);
5928 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
5929 u16 ac, bool enable)
5931 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5932 struct wmi_sta_uapsd_auto_trig_arg arg = {};
5933 u32 prio = 0, acc = 0;
5937 lockdep_assert_held(&ar->conf_mutex);
5939 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
5943 case IEEE80211_AC_VO:
5944 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
5945 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
5949 case IEEE80211_AC_VI:
5950 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
5951 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
5955 case IEEE80211_AC_BE:
5956 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
5957 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
5961 case IEEE80211_AC_BK:
5962 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
5963 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
5970 arvif->u.sta.uapsd |= value;
5972 arvif->u.sta.uapsd &= ~value;
5974 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5975 WMI_STA_PS_PARAM_UAPSD,
5976 arvif->u.sta.uapsd);
5978 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
5982 if (arvif->u.sta.uapsd)
5983 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
5985 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
5987 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
5988 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
5991 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
5993 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
5995 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
5996 arvif->vdev_id, ret);
6000 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
6002 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
6003 arvif->vdev_id, ret);
6007 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
6008 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
6009 /* Only userspace can make an educated decision when to send
6010 * trigger frame. The following effectively disables u-UAPSD
6011 * autotrigger in firmware (which is enabled by default
6012 * provided the autotrigger service is available).
6016 arg.user_priority = prio;
6017 arg.service_interval = 0;
6018 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6019 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
6021 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
6022 arvif->bssid, &arg, 1);
6024 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
6034 static int ath10k_conf_tx(struct ieee80211_hw *hw,
6035 struct ieee80211_vif *vif, u16 ac,
6036 const struct ieee80211_tx_queue_params *params)
6038 struct ath10k *ar = hw->priv;
6039 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6040 struct wmi_wmm_params_arg *p = NULL;
6043 mutex_lock(&ar->conf_mutex);
6046 case IEEE80211_AC_VO:
6047 p = &arvif->wmm_params.ac_vo;
6049 case IEEE80211_AC_VI:
6050 p = &arvif->wmm_params.ac_vi;
6052 case IEEE80211_AC_BE:
6053 p = &arvif->wmm_params.ac_be;
6055 case IEEE80211_AC_BK:
6056 p = &arvif->wmm_params.ac_bk;
6065 p->cwmin = params->cw_min;
6066 p->cwmax = params->cw_max;
6067 p->aifs = params->aifs;
6070 * The channel time duration programmed in the HW is in absolute
6071 * microseconds, while mac80211 gives the txop in units of
6074 p->txop = params->txop * 32;
6076 if (ar->wmi.ops->gen_vdev_wmm_conf) {
6077 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
6078 &arvif->wmm_params);
6080 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
6081 arvif->vdev_id, ret);
6085 /* This won't work well with multi-interface cases but it's
6086 * better than nothing.
6088 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
6090 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
6095 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
6097 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
6100 mutex_unlock(&ar->conf_mutex);
6104 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
6106 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
6107 struct ieee80211_vif *vif,
6108 struct ieee80211_channel *chan,
6110 enum ieee80211_roc_type type)
6112 struct ath10k *ar = hw->priv;
6113 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6114 struct wmi_start_scan_arg arg;
6118 mutex_lock(&ar->conf_mutex);
6120 spin_lock_bh(&ar->data_lock);
6121 switch (ar->scan.state) {
6122 case ATH10K_SCAN_IDLE:
6123 reinit_completion(&ar->scan.started);
6124 reinit_completion(&ar->scan.completed);
6125 reinit_completion(&ar->scan.on_channel);
6126 ar->scan.state = ATH10K_SCAN_STARTING;
6127 ar->scan.is_roc = true;
6128 ar->scan.vdev_id = arvif->vdev_id;
6129 ar->scan.roc_freq = chan->center_freq;
6130 ar->scan.roc_notify = true;
6133 case ATH10K_SCAN_STARTING:
6134 case ATH10K_SCAN_RUNNING:
6135 case ATH10K_SCAN_ABORTING:
6139 spin_unlock_bh(&ar->data_lock);
6144 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
6146 memset(&arg, 0, sizeof(arg));
6147 ath10k_wmi_start_scan_init(ar, &arg);
6148 arg.vdev_id = arvif->vdev_id;
6149 arg.scan_id = ATH10K_SCAN_ID;
6151 arg.channels[0] = chan->center_freq;
6152 arg.dwell_time_active = scan_time_msec;
6153 arg.dwell_time_passive = scan_time_msec;
6154 arg.max_scan_time = scan_time_msec;
6155 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
6156 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
6157 arg.burst_duration_ms = duration;
6159 ret = ath10k_start_scan(ar, &arg);
6161 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
6162 spin_lock_bh(&ar->data_lock);
6163 ar->scan.state = ATH10K_SCAN_IDLE;
6164 spin_unlock_bh(&ar->data_lock);
6168 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
6170 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
6172 ret = ath10k_scan_stop(ar);
6174 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
6180 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
6181 msecs_to_jiffies(duration));
6185 mutex_unlock(&ar->conf_mutex);
6189 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
6191 struct ath10k *ar = hw->priv;
6193 mutex_lock(&ar->conf_mutex);
6195 spin_lock_bh(&ar->data_lock);
6196 ar->scan.roc_notify = false;
6197 spin_unlock_bh(&ar->data_lock);
6199 ath10k_scan_abort(ar);
6201 mutex_unlock(&ar->conf_mutex);
6203 cancel_delayed_work_sync(&ar->scan.timeout);
6209 * Both RTS and Fragmentation threshold are interface-specific
6210 * in ath10k, but device-specific in mac80211.
6213 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
6215 struct ath10k *ar = hw->priv;
6216 struct ath10k_vif *arvif;
6219 mutex_lock(&ar->conf_mutex);
6220 list_for_each_entry(arvif, &ar->arvifs, list) {
6221 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
6222 arvif->vdev_id, value);
6224 ret = ath10k_mac_set_rts(arvif, value);
6226 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
6227 arvif->vdev_id, ret);
6231 mutex_unlock(&ar->conf_mutex);
6236 static int ath10k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
6238 /* Even though there's a WMI enum for fragmentation threshold no known
6239 * firmware actually implements it. Moreover it is not possible to rely
6240 * frame fragmentation to mac80211 because firmware clears the "more
6241 * fragments" bit in frame control making it impossible for remote
6242 * devices to reassemble frames.
6244 * Hence implement a dummy callback just to say fragmentation isn't
6245 * supported. This effectively prevents mac80211 from doing frame
6246 * fragmentation in software.
6251 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6252 u32 queues, bool drop)
6254 struct ath10k *ar = hw->priv;
6258 /* mac80211 doesn't care if we really xmit queued frames or not
6259 * we'll collect those frames either way if we stop/delete vdevs */
6263 mutex_lock(&ar->conf_mutex);
6265 if (ar->state == ATH10K_STATE_WEDGED)
6268 time_left = wait_event_timeout(ar->htt.empty_tx_wq, ({
6271 spin_lock_bh(&ar->htt.tx_lock);
6272 empty = (ar->htt.num_pending_tx == 0);
6273 spin_unlock_bh(&ar->htt.tx_lock);
6275 skip = (ar->state == ATH10K_STATE_WEDGED) ||
6276 test_bit(ATH10K_FLAG_CRASH_FLUSH,
6280 }), ATH10K_FLUSH_TIMEOUT_HZ);
6282 if (time_left == 0 || skip)
6283 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %ld\n",
6284 skip, ar->state, time_left);
6287 mutex_unlock(&ar->conf_mutex);
6290 /* TODO: Implement this function properly
6291 * For now it is needed to reply to Probe Requests in IBSS mode.
6292 * Propably we need this information from FW.
6294 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
6299 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
6300 enum ieee80211_reconfig_type reconfig_type)
6302 struct ath10k *ar = hw->priv;
6304 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6307 mutex_lock(&ar->conf_mutex);
6309 /* If device failed to restart it will be in a different state, e.g.
6310 * ATH10K_STATE_WEDGED */
6311 if (ar->state == ATH10K_STATE_RESTARTED) {
6312 ath10k_info(ar, "device successfully recovered\n");
6313 ar->state = ATH10K_STATE_ON;
6314 ieee80211_wake_queues(ar->hw);
6317 mutex_unlock(&ar->conf_mutex);
6320 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
6321 struct survey_info *survey)
6323 struct ath10k *ar = hw->priv;
6324 struct ieee80211_supported_band *sband;
6325 struct survey_info *ar_survey = &ar->survey[idx];
6328 mutex_lock(&ar->conf_mutex);
6330 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
6331 if (sband && idx >= sband->n_channels) {
6332 idx -= sband->n_channels;
6337 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
6339 if (!sband || idx >= sband->n_channels) {
6344 spin_lock_bh(&ar->data_lock);
6345 memcpy(survey, ar_survey, sizeof(*survey));
6346 spin_unlock_bh(&ar->data_lock);
6348 survey->channel = &sband->channels[idx];
6350 if (ar->rx_channel == survey->channel)
6351 survey->filled |= SURVEY_INFO_IN_USE;
6354 mutex_unlock(&ar->conf_mutex);
6359 ath10k_mac_bitrate_mask_has_single_rate(struct ath10k *ar,
6360 enum ieee80211_band band,
6361 const struct cfg80211_bitrate_mask *mask)
6366 num_rates += hweight32(mask->control[band].legacy);
6368 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
6369 num_rates += hweight8(mask->control[band].ht_mcs[i]);
6371 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
6372 num_rates += hweight16(mask->control[band].vht_mcs[i]);
6374 return num_rates == 1;
6378 ath10k_mac_bitrate_mask_get_single_nss(struct ath10k *ar,
6379 enum ieee80211_band band,
6380 const struct cfg80211_bitrate_mask *mask,
6383 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6384 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
6386 u8 vht_nss_mask = 0;
6389 if (mask->control[band].legacy)
6392 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6393 if (mask->control[band].ht_mcs[i] == 0)
6395 else if (mask->control[band].ht_mcs[i] ==
6396 sband->ht_cap.mcs.rx_mask[i])
6397 ht_nss_mask |= BIT(i);
6402 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6403 if (mask->control[band].vht_mcs[i] == 0)
6405 else if (mask->control[band].vht_mcs[i] ==
6406 ath10k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
6407 vht_nss_mask |= BIT(i);
6412 if (ht_nss_mask != vht_nss_mask)
6415 if (ht_nss_mask == 0)
6418 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
6421 *nss = fls(ht_nss_mask);
6427 ath10k_mac_bitrate_mask_get_single_rate(struct ath10k *ar,
6428 enum ieee80211_band band,
6429 const struct cfg80211_bitrate_mask *mask,
6432 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
6439 if (hweight32(mask->control[band].legacy) == 1) {
6440 rate_idx = ffs(mask->control[band].legacy) - 1;
6442 hw_rate = sband->bitrates[rate_idx].hw_value;
6443 bitrate = sband->bitrates[rate_idx].bitrate;
6445 if (ath10k_mac_bitrate_is_cck(bitrate))
6446 preamble = WMI_RATE_PREAMBLE_CCK;
6448 preamble = WMI_RATE_PREAMBLE_OFDM;
6451 *rate = preamble << 6 |
6458 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
6459 if (hweight8(mask->control[band].ht_mcs[i]) == 1) {
6461 *rate = WMI_RATE_PREAMBLE_HT << 6 |
6463 (ffs(mask->control[band].ht_mcs[i]) - 1);
6469 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
6470 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
6472 *rate = WMI_RATE_PREAMBLE_VHT << 6 |
6474 (ffs(mask->control[band].vht_mcs[i]) - 1);
6483 static int ath10k_mac_set_fixed_rate_params(struct ath10k_vif *arvif,
6484 u8 rate, u8 nss, u8 sgi, u8 ldpc)
6486 struct ath10k *ar = arvif->ar;
6490 lockdep_assert_held(&ar->conf_mutex);
6492 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
6493 arvif->vdev_id, rate, nss, sgi);
6495 vdev_param = ar->wmi.vdev_param->fixed_rate;
6496 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, rate);
6498 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
6503 vdev_param = ar->wmi.vdev_param->nss;
6504 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, nss);
6506 ath10k_warn(ar, "failed to set nss param %d: %d\n", nss, ret);
6510 vdev_param = ar->wmi.vdev_param->sgi;
6511 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, sgi);
6513 ath10k_warn(ar, "failed to set sgi param %d: %d\n", sgi, ret);
6517 vdev_param = ar->wmi.vdev_param->ldpc;
6518 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, ldpc);
6520 ath10k_warn(ar, "failed to set ldpc param %d: %d\n", ldpc, ret);
6528 ath10k_mac_can_set_bitrate_mask(struct ath10k *ar,
6529 enum ieee80211_band band,
6530 const struct cfg80211_bitrate_mask *mask)
6535 /* Due to firmware limitation in WMI_PEER_ASSOC_CMDID it is impossible
6536 * to express all VHT MCS rate masks. Effectively only the following
6537 * ranges can be used: none, 0-7, 0-8 and 0-9.
6539 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
6540 vht_mcs = mask->control[band].vht_mcs[i];
6549 ath10k_warn(ar, "refusing bitrate mask with missing 0-7 VHT MCS rates\n");
6557 static void ath10k_mac_set_bitrate_mask_iter(void *data,
6558 struct ieee80211_sta *sta)
6560 struct ath10k_vif *arvif = data;
6561 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6562 struct ath10k *ar = arvif->ar;
6564 if (arsta->arvif != arvif)
6567 spin_lock_bh(&ar->data_lock);
6568 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
6569 spin_unlock_bh(&ar->data_lock);
6571 ieee80211_queue_work(ar->hw, &arsta->update_wk);
6574 static int ath10k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
6575 struct ieee80211_vif *vif,
6576 const struct cfg80211_bitrate_mask *mask)
6578 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6579 struct cfg80211_chan_def def;
6580 struct ath10k *ar = arvif->ar;
6581 enum ieee80211_band band;
6582 const u8 *ht_mcs_mask;
6583 const u16 *vht_mcs_mask;
6591 if (ath10k_mac_vif_chan(vif, &def))
6594 band = def.chan->band;
6595 ht_mcs_mask = mask->control[band].ht_mcs;
6596 vht_mcs_mask = mask->control[band].vht_mcs;
6597 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
6599 sgi = mask->control[band].gi;
6600 if (sgi == NL80211_TXRATE_FORCE_LGI)
6603 if (ath10k_mac_bitrate_mask_has_single_rate(ar, band, mask)) {
6604 ret = ath10k_mac_bitrate_mask_get_single_rate(ar, band, mask,
6607 ath10k_warn(ar, "failed to get single rate for vdev %i: %d\n",
6608 arvif->vdev_id, ret);
6611 } else if (ath10k_mac_bitrate_mask_get_single_nss(ar, band, mask,
6613 rate = WMI_FIXED_RATE_NONE;
6616 rate = WMI_FIXED_RATE_NONE;
6617 nss = min(ar->num_rf_chains,
6618 max(ath10k_mac_max_ht_nss(ht_mcs_mask),
6619 ath10k_mac_max_vht_nss(vht_mcs_mask)));
6621 if (!ath10k_mac_can_set_bitrate_mask(ar, band, mask))
6624 mutex_lock(&ar->conf_mutex);
6626 arvif->bitrate_mask = *mask;
6627 ieee80211_iterate_stations_atomic(ar->hw,
6628 ath10k_mac_set_bitrate_mask_iter,
6631 mutex_unlock(&ar->conf_mutex);
6634 mutex_lock(&ar->conf_mutex);
6636 ret = ath10k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6638 ath10k_warn(ar, "failed to set fixed rate params on vdev %i: %d\n",
6639 arvif->vdev_id, ret);
6644 mutex_unlock(&ar->conf_mutex);
6649 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
6650 struct ieee80211_vif *vif,
6651 struct ieee80211_sta *sta,
6654 struct ath10k *ar = hw->priv;
6655 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
6658 spin_lock_bh(&ar->data_lock);
6660 ath10k_dbg(ar, ATH10K_DBG_MAC,
6661 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
6662 sta->addr, changed, sta->bandwidth, sta->rx_nss,
6665 if (changed & IEEE80211_RC_BW_CHANGED) {
6666 bw = WMI_PEER_CHWIDTH_20MHZ;
6668 switch (sta->bandwidth) {
6669 case IEEE80211_STA_RX_BW_20:
6670 bw = WMI_PEER_CHWIDTH_20MHZ;
6672 case IEEE80211_STA_RX_BW_40:
6673 bw = WMI_PEER_CHWIDTH_40MHZ;
6675 case IEEE80211_STA_RX_BW_80:
6676 bw = WMI_PEER_CHWIDTH_80MHZ;
6678 case IEEE80211_STA_RX_BW_160:
6679 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
6680 sta->bandwidth, sta->addr);
6681 bw = WMI_PEER_CHWIDTH_20MHZ;
6688 if (changed & IEEE80211_RC_NSS_CHANGED)
6689 arsta->nss = sta->rx_nss;
6691 if (changed & IEEE80211_RC_SMPS_CHANGED) {
6692 smps = WMI_PEER_SMPS_PS_NONE;
6694 switch (sta->smps_mode) {
6695 case IEEE80211_SMPS_AUTOMATIC:
6696 case IEEE80211_SMPS_OFF:
6697 smps = WMI_PEER_SMPS_PS_NONE;
6699 case IEEE80211_SMPS_STATIC:
6700 smps = WMI_PEER_SMPS_STATIC;
6702 case IEEE80211_SMPS_DYNAMIC:
6703 smps = WMI_PEER_SMPS_DYNAMIC;
6705 case IEEE80211_SMPS_NUM_MODES:
6706 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
6707 sta->smps_mode, sta->addr);
6708 smps = WMI_PEER_SMPS_PS_NONE;
6715 arsta->changed |= changed;
6717 spin_unlock_bh(&ar->data_lock);
6719 ieee80211_queue_work(hw, &arsta->update_wk);
6722 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
6725 * FIXME: Return 0 for time being. Need to figure out whether FW
6726 * has the API to fetch 64-bit local TSF
6732 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
6733 struct ieee80211_vif *vif,
6734 struct ieee80211_ampdu_params *params)
6736 struct ath10k *ar = hw->priv;
6737 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
6738 struct ieee80211_sta *sta = params->sta;
6739 enum ieee80211_ampdu_mlme_action action = params->action;
6740 u16 tid = params->tid;
6742 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
6743 arvif->vdev_id, sta->addr, tid, action);
6746 case IEEE80211_AMPDU_RX_START:
6747 case IEEE80211_AMPDU_RX_STOP:
6748 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
6749 * creation/removal. Do we need to verify this?
6752 case IEEE80211_AMPDU_TX_START:
6753 case IEEE80211_AMPDU_TX_STOP_CONT:
6754 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6755 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6756 case IEEE80211_AMPDU_TX_OPERATIONAL:
6757 /* Firmware offloads Tx aggregation entirely so deny mac80211
6758 * Tx aggregation requests.
6767 ath10k_mac_update_rx_channel(struct ath10k *ar,
6768 struct ieee80211_chanctx_conf *ctx,
6769 struct ieee80211_vif_chanctx_switch *vifs,
6772 struct cfg80211_chan_def *def = NULL;
6774 /* Both locks are required because ar->rx_channel is modified. This
6775 * allows readers to hold either lock.
6777 lockdep_assert_held(&ar->conf_mutex);
6778 lockdep_assert_held(&ar->data_lock);
6780 WARN_ON(ctx && vifs);
6781 WARN_ON(vifs && n_vifs != 1);
6783 /* FIXME: Sort of an optimization and a workaround. Peers and vifs are
6784 * on a linked list now. Doing a lookup peer -> vif -> chanctx for each
6785 * ppdu on Rx may reduce performance on low-end systems. It should be
6786 * possible to make tables/hashmaps to speed the lookup up (be vary of
6787 * cpu data cache lines though regarding sizes) but to keep the initial
6788 * implementation simple and less intrusive fallback to the slow lookup
6789 * only for multi-channel cases. Single-channel cases will remain to
6790 * use the old channel derival and thus performance should not be
6794 if (!ctx && ath10k_mac_num_chanctxs(ar) == 1) {
6795 ieee80211_iter_chan_contexts_atomic(ar->hw,
6796 ath10k_mac_get_any_chandef_iter,
6800 def = &vifs[0].new_ctx->def;
6802 ar->rx_channel = def->chan;
6803 } else if (ctx && ath10k_mac_num_chanctxs(ar) == 0) {
6804 ar->rx_channel = ctx->def.chan;
6806 ar->rx_channel = NULL;
6812 ath10k_mac_update_vif_chan(struct ath10k *ar,
6813 struct ieee80211_vif_chanctx_switch *vifs,
6816 struct ath10k_vif *arvif;
6820 lockdep_assert_held(&ar->conf_mutex);
6822 /* First stop monitor interface. Some FW versions crash if there's a
6823 * lone monitor interface.
6825 if (ar->monitor_started)
6826 ath10k_monitor_stop(ar);
6828 for (i = 0; i < n_vifs; i++) {
6829 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6831 ath10k_dbg(ar, ATH10K_DBG_MAC,
6832 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
6834 vifs[i].old_ctx->def.chan->center_freq,
6835 vifs[i].new_ctx->def.chan->center_freq,
6836 vifs[i].old_ctx->def.width,
6837 vifs[i].new_ctx->def.width);
6839 if (WARN_ON(!arvif->is_started))
6842 if (WARN_ON(!arvif->is_up))
6845 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
6847 ath10k_warn(ar, "failed to down vdev %d: %d\n",
6848 arvif->vdev_id, ret);
6853 /* All relevant vdevs are downed and associated channel resources
6854 * should be available for the channel switch now.
6857 spin_lock_bh(&ar->data_lock);
6858 ath10k_mac_update_rx_channel(ar, NULL, vifs, n_vifs);
6859 spin_unlock_bh(&ar->data_lock);
6861 for (i = 0; i < n_vifs; i++) {
6862 arvif = ath10k_vif_to_arvif(vifs[i].vif);
6864 if (WARN_ON(!arvif->is_started))
6867 if (WARN_ON(!arvif->is_up))
6870 ret = ath10k_mac_setup_bcn_tmpl(arvif);
6872 ath10k_warn(ar, "failed to update bcn tmpl during csa: %d\n",
6875 ret = ath10k_mac_setup_prb_tmpl(arvif);
6877 ath10k_warn(ar, "failed to update prb tmpl during csa: %d\n",
6880 ret = ath10k_vdev_restart(arvif, &vifs[i].new_ctx->def);
6882 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
6883 arvif->vdev_id, ret);
6887 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6890 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
6891 arvif->vdev_id, ret);
6896 ath10k_monitor_recalc(ar);
6900 ath10k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6901 struct ieee80211_chanctx_conf *ctx)
6903 struct ath10k *ar = hw->priv;
6905 ath10k_dbg(ar, ATH10K_DBG_MAC,
6906 "mac chanctx add freq %hu width %d ptr %p\n",
6907 ctx->def.chan->center_freq, ctx->def.width, ctx);
6909 mutex_lock(&ar->conf_mutex);
6911 spin_lock_bh(&ar->data_lock);
6912 ath10k_mac_update_rx_channel(ar, ctx, NULL, 0);
6913 spin_unlock_bh(&ar->data_lock);
6915 ath10k_recalc_radar_detection(ar);
6916 ath10k_monitor_recalc(ar);
6918 mutex_unlock(&ar->conf_mutex);
6924 ath10k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6925 struct ieee80211_chanctx_conf *ctx)
6927 struct ath10k *ar = hw->priv;
6929 ath10k_dbg(ar, ATH10K_DBG_MAC,
6930 "mac chanctx remove freq %hu width %d ptr %p\n",
6931 ctx->def.chan->center_freq, ctx->def.width, ctx);
6933 mutex_lock(&ar->conf_mutex);
6935 spin_lock_bh(&ar->data_lock);
6936 ath10k_mac_update_rx_channel(ar, NULL, NULL, 0);
6937 spin_unlock_bh(&ar->data_lock);
6939 ath10k_recalc_radar_detection(ar);
6940 ath10k_monitor_recalc(ar);
6942 mutex_unlock(&ar->conf_mutex);
6945 struct ath10k_mac_change_chanctx_arg {
6946 struct ieee80211_chanctx_conf *ctx;
6947 struct ieee80211_vif_chanctx_switch *vifs;
6953 ath10k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
6954 struct ieee80211_vif *vif)
6956 struct ath10k_mac_change_chanctx_arg *arg = data;
6958 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
6965 ath10k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
6966 struct ieee80211_vif *vif)
6968 struct ath10k_mac_change_chanctx_arg *arg = data;
6969 struct ieee80211_chanctx_conf *ctx;
6971 ctx = rcu_access_pointer(vif->chanctx_conf);
6972 if (ctx != arg->ctx)
6975 if (WARN_ON(arg->next_vif == arg->n_vifs))
6978 arg->vifs[arg->next_vif].vif = vif;
6979 arg->vifs[arg->next_vif].old_ctx = ctx;
6980 arg->vifs[arg->next_vif].new_ctx = ctx;
6985 ath10k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6986 struct ieee80211_chanctx_conf *ctx,
6989 struct ath10k *ar = hw->priv;
6990 struct ath10k_mac_change_chanctx_arg arg = { .ctx = ctx };
6992 mutex_lock(&ar->conf_mutex);
6994 ath10k_dbg(ar, ATH10K_DBG_MAC,
6995 "mac chanctx change freq %hu width %d ptr %p changed %x\n",
6996 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
6998 /* This shouldn't really happen because channel switching should use
6999 * switch_vif_chanctx().
7001 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
7004 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH) {
7005 ieee80211_iterate_active_interfaces_atomic(
7007 IEEE80211_IFACE_ITER_NORMAL,
7008 ath10k_mac_change_chanctx_cnt_iter,
7010 if (arg.n_vifs == 0)
7013 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]),
7018 ieee80211_iterate_active_interfaces_atomic(
7020 IEEE80211_IFACE_ITER_NORMAL,
7021 ath10k_mac_change_chanctx_fill_iter,
7023 ath10k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
7028 ath10k_recalc_radar_detection(ar);
7030 /* FIXME: How to configure Rx chains properly? */
7032 /* No other actions are actually necessary. Firmware maintains channel
7033 * definitions per vdev internally and there's no host-side channel
7034 * context abstraction to configure, e.g. channel width.
7038 mutex_unlock(&ar->conf_mutex);
7042 ath10k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7043 struct ieee80211_vif *vif,
7044 struct ieee80211_chanctx_conf *ctx)
7046 struct ath10k *ar = hw->priv;
7047 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7050 mutex_lock(&ar->conf_mutex);
7052 ath10k_dbg(ar, ATH10K_DBG_MAC,
7053 "mac chanctx assign ptr %p vdev_id %i\n",
7054 ctx, arvif->vdev_id);
7056 if (WARN_ON(arvif->is_started)) {
7057 mutex_unlock(&ar->conf_mutex);
7061 ret = ath10k_vdev_start(arvif, &ctx->def);
7063 ath10k_warn(ar, "failed to start vdev %i addr %pM on freq %d: %d\n",
7064 arvif->vdev_id, vif->addr,
7065 ctx->def.chan->center_freq, ret);
7069 arvif->is_started = true;
7071 ret = ath10k_mac_vif_setup_ps(arvif);
7073 ath10k_warn(ar, "failed to update vdev %i ps: %d\n",
7074 arvif->vdev_id, ret);
7078 if (vif->type == NL80211_IFTYPE_MONITOR) {
7079 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, 0, vif->addr);
7081 ath10k_warn(ar, "failed to up monitor vdev %i: %d\n",
7082 arvif->vdev_id, ret);
7086 arvif->is_up = true;
7089 mutex_unlock(&ar->conf_mutex);
7093 ath10k_vdev_stop(arvif);
7094 arvif->is_started = false;
7095 ath10k_mac_vif_setup_ps(arvif);
7098 mutex_unlock(&ar->conf_mutex);
7103 ath10k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7104 struct ieee80211_vif *vif,
7105 struct ieee80211_chanctx_conf *ctx)
7107 struct ath10k *ar = hw->priv;
7108 struct ath10k_vif *arvif = (void *)vif->drv_priv;
7111 mutex_lock(&ar->conf_mutex);
7113 ath10k_dbg(ar, ATH10K_DBG_MAC,
7114 "mac chanctx unassign ptr %p vdev_id %i\n",
7115 ctx, arvif->vdev_id);
7117 WARN_ON(!arvif->is_started);
7119 if (vif->type == NL80211_IFTYPE_MONITOR) {
7120 WARN_ON(!arvif->is_up);
7122 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
7124 ath10k_warn(ar, "failed to down monitor vdev %i: %d\n",
7125 arvif->vdev_id, ret);
7127 arvif->is_up = false;
7130 ret = ath10k_vdev_stop(arvif);
7132 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
7133 arvif->vdev_id, ret);
7135 arvif->is_started = false;
7137 mutex_unlock(&ar->conf_mutex);
7141 ath10k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7142 struct ieee80211_vif_chanctx_switch *vifs,
7144 enum ieee80211_chanctx_switch_mode mode)
7146 struct ath10k *ar = hw->priv;
7148 mutex_lock(&ar->conf_mutex);
7150 ath10k_dbg(ar, ATH10K_DBG_MAC,
7151 "mac chanctx switch n_vifs %d mode %d\n",
7153 ath10k_mac_update_vif_chan(ar, vifs, n_vifs);
7155 mutex_unlock(&ar->conf_mutex);
7159 static const struct ieee80211_ops ath10k_ops = {
7160 .tx = ath10k_mac_op_tx,
7161 .wake_tx_queue = ath10k_mac_op_wake_tx_queue,
7162 .start = ath10k_start,
7163 .stop = ath10k_stop,
7164 .config = ath10k_config,
7165 .add_interface = ath10k_add_interface,
7166 .remove_interface = ath10k_remove_interface,
7167 .configure_filter = ath10k_configure_filter,
7168 .bss_info_changed = ath10k_bss_info_changed,
7169 .hw_scan = ath10k_hw_scan,
7170 .cancel_hw_scan = ath10k_cancel_hw_scan,
7171 .set_key = ath10k_set_key,
7172 .set_default_unicast_key = ath10k_set_default_unicast_key,
7173 .sta_state = ath10k_sta_state,
7174 .conf_tx = ath10k_conf_tx,
7175 .remain_on_channel = ath10k_remain_on_channel,
7176 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
7177 .set_rts_threshold = ath10k_set_rts_threshold,
7178 .set_frag_threshold = ath10k_mac_op_set_frag_threshold,
7179 .flush = ath10k_flush,
7180 .tx_last_beacon = ath10k_tx_last_beacon,
7181 .set_antenna = ath10k_set_antenna,
7182 .get_antenna = ath10k_get_antenna,
7183 .reconfig_complete = ath10k_reconfig_complete,
7184 .get_survey = ath10k_get_survey,
7185 .set_bitrate_mask = ath10k_mac_op_set_bitrate_mask,
7186 .sta_rc_update = ath10k_sta_rc_update,
7187 .get_tsf = ath10k_get_tsf,
7188 .ampdu_action = ath10k_ampdu_action,
7189 .get_et_sset_count = ath10k_debug_get_et_sset_count,
7190 .get_et_stats = ath10k_debug_get_et_stats,
7191 .get_et_strings = ath10k_debug_get_et_strings,
7192 .add_chanctx = ath10k_mac_op_add_chanctx,
7193 .remove_chanctx = ath10k_mac_op_remove_chanctx,
7194 .change_chanctx = ath10k_mac_op_change_chanctx,
7195 .assign_vif_chanctx = ath10k_mac_op_assign_vif_chanctx,
7196 .unassign_vif_chanctx = ath10k_mac_op_unassign_vif_chanctx,
7197 .switch_vif_chanctx = ath10k_mac_op_switch_vif_chanctx,
7199 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
7202 .suspend = ath10k_wow_op_suspend,
7203 .resume = ath10k_wow_op_resume,
7205 #ifdef CONFIG_MAC80211_DEBUGFS
7206 .sta_add_debugfs = ath10k_sta_add_debugfs,
7210 #define CHAN2G(_channel, _freq, _flags) { \
7211 .band = IEEE80211_BAND_2GHZ, \
7212 .hw_value = (_channel), \
7213 .center_freq = (_freq), \
7214 .flags = (_flags), \
7215 .max_antenna_gain = 0, \
7219 #define CHAN5G(_channel, _freq, _flags) { \
7220 .band = IEEE80211_BAND_5GHZ, \
7221 .hw_value = (_channel), \
7222 .center_freq = (_freq), \
7223 .flags = (_flags), \
7224 .max_antenna_gain = 0, \
7228 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
7238 CHAN2G(10, 2457, 0),
7239 CHAN2G(11, 2462, 0),
7240 CHAN2G(12, 2467, 0),
7241 CHAN2G(13, 2472, 0),
7242 CHAN2G(14, 2484, 0),
7245 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
7246 CHAN5G(36, 5180, 0),
7247 CHAN5G(40, 5200, 0),
7248 CHAN5G(44, 5220, 0),
7249 CHAN5G(48, 5240, 0),
7250 CHAN5G(52, 5260, 0),
7251 CHAN5G(56, 5280, 0),
7252 CHAN5G(60, 5300, 0),
7253 CHAN5G(64, 5320, 0),
7254 CHAN5G(100, 5500, 0),
7255 CHAN5G(104, 5520, 0),
7256 CHAN5G(108, 5540, 0),
7257 CHAN5G(112, 5560, 0),
7258 CHAN5G(116, 5580, 0),
7259 CHAN5G(120, 5600, 0),
7260 CHAN5G(124, 5620, 0),
7261 CHAN5G(128, 5640, 0),
7262 CHAN5G(132, 5660, 0),
7263 CHAN5G(136, 5680, 0),
7264 CHAN5G(140, 5700, 0),
7265 CHAN5G(144, 5720, 0),
7266 CHAN5G(149, 5745, 0),
7267 CHAN5G(153, 5765, 0),
7268 CHAN5G(157, 5785, 0),
7269 CHAN5G(161, 5805, 0),
7270 CHAN5G(165, 5825, 0),
7273 struct ath10k *ath10k_mac_create(size_t priv_size)
7275 struct ieee80211_hw *hw;
7278 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
7288 void ath10k_mac_destroy(struct ath10k *ar)
7290 ieee80211_free_hw(ar->hw);
7293 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
7296 .types = BIT(NL80211_IFTYPE_STATION)
7297 | BIT(NL80211_IFTYPE_P2P_CLIENT)
7301 .types = BIT(NL80211_IFTYPE_P2P_GO)
7305 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
7309 .types = BIT(NL80211_IFTYPE_AP)
7310 #ifdef CONFIG_MAC80211_MESH
7311 | BIT(NL80211_IFTYPE_MESH_POINT)
7316 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
7319 .types = BIT(NL80211_IFTYPE_AP)
7320 #ifdef CONFIG_MAC80211_MESH
7321 | BIT(NL80211_IFTYPE_MESH_POINT)
7326 .types = BIT(NL80211_IFTYPE_STATION)
7330 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
7332 .limits = ath10k_if_limits,
7333 .n_limits = ARRAY_SIZE(ath10k_if_limits),
7334 .max_interfaces = 8,
7335 .num_different_channels = 1,
7336 .beacon_int_infra_match = true,
7340 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
7342 .limits = ath10k_10x_if_limits,
7343 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
7344 .max_interfaces = 8,
7345 .num_different_channels = 1,
7346 .beacon_int_infra_match = true,
7347 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7348 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7349 BIT(NL80211_CHAN_WIDTH_20) |
7350 BIT(NL80211_CHAN_WIDTH_40) |
7351 BIT(NL80211_CHAN_WIDTH_80),
7356 static const struct ieee80211_iface_limit ath10k_tlv_if_limit[] = {
7359 .types = BIT(NL80211_IFTYPE_STATION),
7363 .types = BIT(NL80211_IFTYPE_AP) |
7364 #ifdef CONFIG_MAC80211_MESH
7365 BIT(NL80211_IFTYPE_MESH_POINT) |
7367 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7368 BIT(NL80211_IFTYPE_P2P_GO),
7372 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7376 static const struct ieee80211_iface_limit ath10k_tlv_qcs_if_limit[] = {
7379 .types = BIT(NL80211_IFTYPE_STATION),
7383 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
7387 .types = BIT(NL80211_IFTYPE_AP) |
7388 #ifdef CONFIG_MAC80211_MESH
7389 BIT(NL80211_IFTYPE_MESH_POINT) |
7391 BIT(NL80211_IFTYPE_P2P_GO),
7395 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
7399 static const struct ieee80211_iface_limit ath10k_tlv_if_limit_ibss[] = {
7402 .types = BIT(NL80211_IFTYPE_STATION),
7406 .types = BIT(NL80211_IFTYPE_ADHOC),
7410 /* FIXME: This is not thouroughly tested. These combinations may over- or
7411 * underestimate hw/fw capabilities.
7413 static struct ieee80211_iface_combination ath10k_tlv_if_comb[] = {
7415 .limits = ath10k_tlv_if_limit,
7416 .num_different_channels = 1,
7417 .max_interfaces = 4,
7418 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7421 .limits = ath10k_tlv_if_limit_ibss,
7422 .num_different_channels = 1,
7423 .max_interfaces = 2,
7424 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7428 static struct ieee80211_iface_combination ath10k_tlv_qcs_if_comb[] = {
7430 .limits = ath10k_tlv_if_limit,
7431 .num_different_channels = 1,
7432 .max_interfaces = 4,
7433 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit),
7436 .limits = ath10k_tlv_qcs_if_limit,
7437 .num_different_channels = 2,
7438 .max_interfaces = 4,
7439 .n_limits = ARRAY_SIZE(ath10k_tlv_qcs_if_limit),
7442 .limits = ath10k_tlv_if_limit_ibss,
7443 .num_different_channels = 1,
7444 .max_interfaces = 2,
7445 .n_limits = ARRAY_SIZE(ath10k_tlv_if_limit_ibss),
7449 static const struct ieee80211_iface_limit ath10k_10_4_if_limits[] = {
7452 .types = BIT(NL80211_IFTYPE_STATION),
7456 .types = BIT(NL80211_IFTYPE_AP)
7457 #ifdef CONFIG_MAC80211_MESH
7458 | BIT(NL80211_IFTYPE_MESH_POINT)
7463 static const struct ieee80211_iface_combination ath10k_10_4_if_comb[] = {
7465 .limits = ath10k_10_4_if_limits,
7466 .n_limits = ARRAY_SIZE(ath10k_10_4_if_limits),
7467 .max_interfaces = 16,
7468 .num_different_channels = 1,
7469 .beacon_int_infra_match = true,
7470 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
7471 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
7472 BIT(NL80211_CHAN_WIDTH_20) |
7473 BIT(NL80211_CHAN_WIDTH_40) |
7474 BIT(NL80211_CHAN_WIDTH_80),
7479 static void ath10k_get_arvif_iter(void *data, u8 *mac,
7480 struct ieee80211_vif *vif)
7482 struct ath10k_vif_iter *arvif_iter = data;
7483 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
7485 if (arvif->vdev_id == arvif_iter->vdev_id)
7486 arvif_iter->arvif = arvif;
7489 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
7491 struct ath10k_vif_iter arvif_iter;
7494 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
7495 arvif_iter.vdev_id = vdev_id;
7497 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
7498 ieee80211_iterate_active_interfaces_atomic(ar->hw,
7500 ath10k_get_arvif_iter,
7502 if (!arvif_iter.arvif) {
7503 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
7507 return arvif_iter.arvif;
7510 int ath10k_mac_register(struct ath10k *ar)
7512 static const u32 cipher_suites[] = {
7513 WLAN_CIPHER_SUITE_WEP40,
7514 WLAN_CIPHER_SUITE_WEP104,
7515 WLAN_CIPHER_SUITE_TKIP,
7516 WLAN_CIPHER_SUITE_CCMP,
7517 WLAN_CIPHER_SUITE_AES_CMAC,
7519 struct ieee80211_supported_band *band;
7523 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
7525 SET_IEEE80211_DEV(ar->hw, ar->dev);
7527 BUILD_BUG_ON((ARRAY_SIZE(ath10k_2ghz_channels) +
7528 ARRAY_SIZE(ath10k_5ghz_channels)) !=
7531 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
7532 channels = kmemdup(ath10k_2ghz_channels,
7533 sizeof(ath10k_2ghz_channels),
7540 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
7541 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
7542 band->channels = channels;
7543 band->n_bitrates = ath10k_g_rates_size;
7544 band->bitrates = ath10k_g_rates;
7546 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
7549 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
7550 channels = kmemdup(ath10k_5ghz_channels,
7551 sizeof(ath10k_5ghz_channels),
7558 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
7559 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
7560 band->channels = channels;
7561 band->n_bitrates = ath10k_a_rates_size;
7562 band->bitrates = ath10k_a_rates;
7563 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
7566 ath10k_mac_setup_ht_vht_cap(ar);
7568 ar->hw->wiphy->interface_modes =
7569 BIT(NL80211_IFTYPE_STATION) |
7570 BIT(NL80211_IFTYPE_AP) |
7571 BIT(NL80211_IFTYPE_MESH_POINT);
7573 ar->hw->wiphy->available_antennas_rx = ar->cfg_rx_chainmask;
7574 ar->hw->wiphy->available_antennas_tx = ar->cfg_tx_chainmask;
7576 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
7577 ar->hw->wiphy->interface_modes |=
7578 BIT(NL80211_IFTYPE_P2P_DEVICE) |
7579 BIT(NL80211_IFTYPE_P2P_CLIENT) |
7580 BIT(NL80211_IFTYPE_P2P_GO);
7582 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
7583 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
7584 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
7585 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
7586 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
7587 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
7588 ieee80211_hw_set(ar->hw, AP_LINK_PS);
7589 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
7590 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
7591 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
7592 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
7593 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
7594 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
7595 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
7597 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7598 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
7600 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
7601 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
7603 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
7604 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
7606 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
7607 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
7608 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
7611 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
7612 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
7614 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
7615 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
7616 ar->hw->txq_data_size = sizeof(struct ath10k_txq);
7618 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
7620 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
7621 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
7623 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
7624 * that userspace (e.g. wpa_supplicant/hostapd) can generate
7625 * correct Probe Responses. This is more of a hack advert..
7627 ar->hw->wiphy->probe_resp_offload |=
7628 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
7629 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
7630 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
7633 if (test_bit(WMI_SERVICE_TDLS, ar->wmi.svc_map))
7634 ar->hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7636 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
7637 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
7638 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
7640 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
7641 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
7643 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
7645 ret = ath10k_wow_init(ar);
7647 ath10k_warn(ar, "failed to init wow: %d\n", ret);
7651 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
7654 * on LL hardware queues are managed entirely by the FW
7655 * so we only advertise to mac we can do the queues thing
7657 ar->hw->queues = IEEE80211_MAX_QUEUES;
7659 /* vdev_ids are used as hw queue numbers. Make sure offchan tx queue is
7660 * something that vdev_ids can't reach so that we don't stop the queue
7663 ar->hw->offchannel_tx_hw_queue = IEEE80211_MAX_QUEUES - 1;
7665 switch (ar->wmi.op_version) {
7666 case ATH10K_FW_WMI_OP_VERSION_MAIN:
7667 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
7668 ar->hw->wiphy->n_iface_combinations =
7669 ARRAY_SIZE(ath10k_if_comb);
7670 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7672 case ATH10K_FW_WMI_OP_VERSION_TLV:
7673 if (test_bit(WMI_SERVICE_ADAPTIVE_OCS, ar->wmi.svc_map)) {
7674 ar->hw->wiphy->iface_combinations =
7675 ath10k_tlv_qcs_if_comb;
7676 ar->hw->wiphy->n_iface_combinations =
7677 ARRAY_SIZE(ath10k_tlv_qcs_if_comb);
7679 ar->hw->wiphy->iface_combinations = ath10k_tlv_if_comb;
7680 ar->hw->wiphy->n_iface_combinations =
7681 ARRAY_SIZE(ath10k_tlv_if_comb);
7683 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
7685 case ATH10K_FW_WMI_OP_VERSION_10_1:
7686 case ATH10K_FW_WMI_OP_VERSION_10_2:
7687 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
7688 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
7689 ar->hw->wiphy->n_iface_combinations =
7690 ARRAY_SIZE(ath10k_10x_if_comb);
7692 case ATH10K_FW_WMI_OP_VERSION_10_4:
7693 ar->hw->wiphy->iface_combinations = ath10k_10_4_if_comb;
7694 ar->hw->wiphy->n_iface_combinations =
7695 ARRAY_SIZE(ath10k_10_4_if_comb);
7697 case ATH10K_FW_WMI_OP_VERSION_UNSET:
7698 case ATH10K_FW_WMI_OP_VERSION_MAX:
7704 if (!test_bit(ATH10K_FLAG_RAW_MODE, &ar->dev_flags))
7705 ar->hw->netdev_features = NETIF_F_HW_CSUM;
7707 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
7708 /* Init ath dfs pattern detector */
7709 ar->ath_common.debug_mask = ATH_DBG_DFS;
7710 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
7713 if (!ar->dfs_detector)
7714 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
7717 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
7718 ath10k_reg_notifier);
7720 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
7721 goto err_dfs_detector_exit;
7724 ar->hw->wiphy->cipher_suites = cipher_suites;
7725 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
7727 ret = ieee80211_register_hw(ar->hw);
7729 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
7730 goto err_dfs_detector_exit;
7733 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
7734 ret = regulatory_hint(ar->hw->wiphy,
7735 ar->ath_common.regulatory.alpha2);
7737 goto err_unregister;
7743 ieee80211_unregister_hw(ar->hw);
7745 err_dfs_detector_exit:
7746 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7747 ar->dfs_detector->exit(ar->dfs_detector);
7750 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7751 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7753 SET_IEEE80211_DEV(ar->hw, NULL);
7757 void ath10k_mac_unregister(struct ath10k *ar)
7759 ieee80211_unregister_hw(ar->hw);
7761 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
7762 ar->dfs_detector->exit(ar->dfs_detector);
7764 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
7765 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
7767 SET_IEEE80211_DEV(ar->hw, NULL);