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>
37 static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
42 struct ath10k *ar = arvif->ar;
43 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
51 lockdep_assert_held(&arvif->ar->conf_mutex);
53 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
56 arg.key_flags = WMI_KEY_GROUP;
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
61 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
62 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
64 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
66 case WLAN_CIPHER_SUITE_TKIP:
67 arg.key_cipher = WMI_CIPHER_TKIP;
68 arg.key_txmic_len = 8;
69 arg.key_rxmic_len = 8;
71 case WLAN_CIPHER_SUITE_WEP40:
72 case WLAN_CIPHER_SUITE_WEP104:
73 arg.key_cipher = WMI_CIPHER_WEP;
74 /* AP/IBSS mode requires self-key to be groupwise
75 * Otherwise pairwise key must be set */
76 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
77 arg.key_flags = WMI_KEY_PAIRWISE;
80 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
84 if (cmd == DISABLE_KEY) {
85 arg.key_cipher = WMI_CIPHER_NONE;
89 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
92 static int ath10k_install_key(struct ath10k_vif *arvif,
93 struct ieee80211_key_conf *key,
97 struct ath10k *ar = arvif->ar;
100 lockdep_assert_held(&ar->conf_mutex);
102 reinit_completion(&ar->install_key_done);
104 ret = ath10k_send_key(arvif, key, cmd, macaddr);
108 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
115 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
118 struct ath10k *ar = arvif->ar;
119 struct ath10k_peer *peer;
123 lockdep_assert_held(&ar->conf_mutex);
125 spin_lock_bh(&ar->data_lock);
126 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
127 spin_unlock_bh(&ar->data_lock);
132 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
133 if (arvif->wep_keys[i] == NULL)
136 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
141 spin_lock_bh(&ar->data_lock);
142 peer->keys[i] = arvif->wep_keys[i];
143 spin_unlock_bh(&ar->data_lock);
149 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
152 struct ath10k *ar = arvif->ar;
153 struct ath10k_peer *peer;
158 lockdep_assert_held(&ar->conf_mutex);
160 spin_lock_bh(&ar->data_lock);
161 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
162 spin_unlock_bh(&ar->data_lock);
167 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
168 if (peer->keys[i] == NULL)
171 ret = ath10k_install_key(arvif, peer->keys[i],
173 if (ret && first_errno == 0)
177 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
180 spin_lock_bh(&ar->data_lock);
181 peer->keys[i] = NULL;
182 spin_unlock_bh(&ar->data_lock);
188 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
191 struct ath10k_peer *peer;
194 lockdep_assert_held(&ar->data_lock);
196 /* We don't know which vdev this peer belongs to,
197 * since WMI doesn't give us that information.
199 * FIXME: multi-bss needs to be handled.
201 peer = ath10k_peer_find(ar, 0, addr);
205 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
206 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
213 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
214 struct ieee80211_key_conf *key)
216 struct ath10k *ar = arvif->ar;
217 struct ath10k_peer *peer;
223 lockdep_assert_held(&ar->conf_mutex);
226 /* since ath10k_install_key we can't hold data_lock all the
227 * time, so we try to remove the keys incrementally */
228 spin_lock_bh(&ar->data_lock);
230 list_for_each_entry(peer, &ar->peers, list) {
231 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
232 if (peer->keys[i] == key) {
233 ether_addr_copy(addr, peer->addr);
234 peer->keys[i] = NULL;
239 if (i < ARRAY_SIZE(peer->keys))
242 spin_unlock_bh(&ar->data_lock);
244 if (i == ARRAY_SIZE(peer->keys))
247 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
248 if (ret && first_errno == 0)
252 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
259 /*********************/
260 /* General utilities */
261 /*********************/
263 static inline enum wmi_phy_mode
264 chan_to_phymode(const struct cfg80211_chan_def *chandef)
266 enum wmi_phy_mode phymode = MODE_UNKNOWN;
268 switch (chandef->chan->band) {
269 case IEEE80211_BAND_2GHZ:
270 switch (chandef->width) {
271 case NL80211_CHAN_WIDTH_20_NOHT:
274 case NL80211_CHAN_WIDTH_20:
275 phymode = MODE_11NG_HT20;
277 case NL80211_CHAN_WIDTH_40:
278 phymode = MODE_11NG_HT40;
280 case NL80211_CHAN_WIDTH_5:
281 case NL80211_CHAN_WIDTH_10:
282 case NL80211_CHAN_WIDTH_80:
283 case NL80211_CHAN_WIDTH_80P80:
284 case NL80211_CHAN_WIDTH_160:
285 phymode = MODE_UNKNOWN;
289 case IEEE80211_BAND_5GHZ:
290 switch (chandef->width) {
291 case NL80211_CHAN_WIDTH_20_NOHT:
294 case NL80211_CHAN_WIDTH_20:
295 phymode = MODE_11NA_HT20;
297 case NL80211_CHAN_WIDTH_40:
298 phymode = MODE_11NA_HT40;
300 case NL80211_CHAN_WIDTH_80:
301 phymode = MODE_11AC_VHT80;
303 case NL80211_CHAN_WIDTH_5:
304 case NL80211_CHAN_WIDTH_10:
305 case NL80211_CHAN_WIDTH_80P80:
306 case NL80211_CHAN_WIDTH_160:
307 phymode = MODE_UNKNOWN;
315 WARN_ON(phymode == MODE_UNKNOWN);
319 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
322 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
323 * 0 for no restriction
332 switch (mpdudensity) {
338 /* Our lower layer calculations limit our precision to
354 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
358 lockdep_assert_held(&ar->conf_mutex);
360 if (ar->num_peers >= ar->max_num_peers)
363 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
365 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
370 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
372 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
382 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
384 struct ath10k *ar = arvif->ar;
388 param = ar->wmi.pdev_param->sta_kickout_th;
389 ret = ath10k_wmi_pdev_set_param(ar, param,
390 ATH10K_KICKOUT_THRESHOLD);
392 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
393 arvif->vdev_id, ret);
397 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
398 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
399 ATH10K_KEEPALIVE_MIN_IDLE);
401 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
402 arvif->vdev_id, ret);
406 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
407 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
408 ATH10K_KEEPALIVE_MAX_IDLE);
410 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
411 arvif->vdev_id, ret);
415 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
416 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
417 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
419 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
420 arvif->vdev_id, ret);
427 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
429 struct ath10k *ar = arvif->ar;
432 vdev_param = ar->wmi.vdev_param->rts_threshold;
433 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
436 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
438 struct ath10k *ar = arvif->ar;
441 if (value != 0xFFFFFFFF)
442 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
443 ATH10K_FRAGMT_THRESHOLD_MIN,
444 ATH10K_FRAGMT_THRESHOLD_MAX);
446 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
447 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
450 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
454 lockdep_assert_held(&ar->conf_mutex);
456 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
460 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
469 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
471 struct ath10k_peer *peer, *tmp;
473 lockdep_assert_held(&ar->conf_mutex);
475 spin_lock_bh(&ar->data_lock);
476 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
477 if (peer->vdev_id != vdev_id)
480 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
481 peer->addr, vdev_id);
483 list_del(&peer->list);
487 spin_unlock_bh(&ar->data_lock);
490 static void ath10k_peer_cleanup_all(struct ath10k *ar)
492 struct ath10k_peer *peer, *tmp;
494 lockdep_assert_held(&ar->conf_mutex);
496 spin_lock_bh(&ar->data_lock);
497 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
498 list_del(&peer->list);
501 spin_unlock_bh(&ar->data_lock);
504 ar->num_stations = 0;
507 /************************/
508 /* Interface management */
509 /************************/
511 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
513 struct ath10k *ar = arvif->ar;
515 lockdep_assert_held(&ar->data_lock);
520 if (!arvif->beacon_buf)
521 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
522 arvif->beacon->len, DMA_TO_DEVICE);
524 dev_kfree_skb_any(arvif->beacon);
526 arvif->beacon = NULL;
527 arvif->beacon_sent = false;
530 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
532 struct ath10k *ar = arvif->ar;
534 lockdep_assert_held(&ar->data_lock);
536 ath10k_mac_vif_beacon_free(arvif);
538 if (arvif->beacon_buf) {
539 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
540 arvif->beacon_buf, arvif->beacon_paddr);
541 arvif->beacon_buf = NULL;
545 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
549 lockdep_assert_held(&ar->conf_mutex);
551 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
554 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
555 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
562 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
564 struct cfg80211_chan_def *chandef = &ar->chandef;
565 struct ieee80211_channel *channel = chandef->chan;
566 struct wmi_vdev_start_request_arg arg = {};
569 lockdep_assert_held(&ar->conf_mutex);
571 arg.vdev_id = vdev_id;
572 arg.channel.freq = channel->center_freq;
573 arg.channel.band_center_freq1 = chandef->center_freq1;
575 /* TODO setup this dynamically, what in case we
576 don't have any vifs? */
577 arg.channel.mode = chan_to_phymode(chandef);
578 arg.channel.chan_radar =
579 !!(channel->flags & IEEE80211_CHAN_RADAR);
581 arg.channel.min_power = 0;
582 arg.channel.max_power = channel->max_power * 2;
583 arg.channel.max_reg_power = channel->max_reg_power * 2;
584 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
586 reinit_completion(&ar->vdev_setup_done);
588 ret = ath10k_wmi_vdev_start(ar, &arg);
590 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
595 ret = ath10k_vdev_setup_sync(ar);
597 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
602 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
604 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
609 ar->monitor_vdev_id = vdev_id;
611 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
612 ar->monitor_vdev_id);
616 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
618 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
619 ar->monitor_vdev_id, ret);
624 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
628 lockdep_assert_held(&ar->conf_mutex);
630 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
632 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
633 ar->monitor_vdev_id, ret);
635 reinit_completion(&ar->vdev_setup_done);
637 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
639 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
640 ar->monitor_vdev_id, ret);
642 ret = ath10k_vdev_setup_sync(ar);
644 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
645 ar->monitor_vdev_id, ret);
647 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
648 ar->monitor_vdev_id);
652 static int ath10k_monitor_vdev_create(struct ath10k *ar)
656 lockdep_assert_held(&ar->conf_mutex);
658 if (ar->free_vdev_map == 0) {
659 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
663 bit = __ffs64(ar->free_vdev_map);
665 ar->monitor_vdev_id = bit;
667 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
668 WMI_VDEV_TYPE_MONITOR,
671 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
672 ar->monitor_vdev_id, ret);
676 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
677 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
678 ar->monitor_vdev_id);
683 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
687 lockdep_assert_held(&ar->conf_mutex);
689 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
691 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
692 ar->monitor_vdev_id, ret);
696 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
698 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
699 ar->monitor_vdev_id);
703 static int ath10k_monitor_start(struct ath10k *ar)
707 lockdep_assert_held(&ar->conf_mutex);
709 ret = ath10k_monitor_vdev_create(ar);
711 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
715 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
717 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
718 ath10k_monitor_vdev_delete(ar);
722 ar->monitor_started = true;
723 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
728 static int ath10k_monitor_stop(struct ath10k *ar)
732 lockdep_assert_held(&ar->conf_mutex);
734 ret = ath10k_monitor_vdev_stop(ar);
736 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
740 ret = ath10k_monitor_vdev_delete(ar);
742 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
746 ar->monitor_started = false;
747 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
752 static int ath10k_monitor_recalc(struct ath10k *ar)
756 lockdep_assert_held(&ar->conf_mutex);
758 should_start = ar->monitor ||
759 ar->filter_flags & FIF_PROMISC_IN_BSS ||
760 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
762 ath10k_dbg(ar, ATH10K_DBG_MAC,
763 "mac monitor recalc started? %d should? %d\n",
764 ar->monitor_started, should_start);
766 if (should_start == ar->monitor_started)
770 return ath10k_monitor_start(ar);
772 return ath10k_monitor_stop(ar);
775 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
777 struct ath10k *ar = arvif->ar;
778 u32 vdev_param, rts_cts = 0;
780 lockdep_assert_held(&ar->conf_mutex);
782 vdev_param = ar->wmi.vdev_param->enable_rtscts;
784 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
785 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
787 if (arvif->num_legacy_stations > 0)
788 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
791 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
795 static int ath10k_start_cac(struct ath10k *ar)
799 lockdep_assert_held(&ar->conf_mutex);
801 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
803 ret = ath10k_monitor_recalc(ar);
805 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
806 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
810 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
811 ar->monitor_vdev_id);
816 static int ath10k_stop_cac(struct ath10k *ar)
818 lockdep_assert_held(&ar->conf_mutex);
820 /* CAC is not running - do nothing */
821 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
824 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
825 ath10k_monitor_stop(ar);
827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
832 static void ath10k_recalc_radar_detection(struct ath10k *ar)
836 lockdep_assert_held(&ar->conf_mutex);
840 if (!ar->radar_enabled)
843 if (ar->num_started_vdevs > 0)
846 ret = ath10k_start_cac(ar);
849 * Not possible to start CAC on current channel so starting
850 * radiation is not allowed, make this channel DFS_UNAVAILABLE
851 * by indicating that radar was detected.
853 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
854 ieee80211_radar_detected(ar->hw);
858 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
860 struct ath10k *ar = arvif->ar;
861 struct cfg80211_chan_def *chandef = &ar->chandef;
862 struct wmi_vdev_start_request_arg arg = {};
865 lockdep_assert_held(&ar->conf_mutex);
867 reinit_completion(&ar->vdev_setup_done);
869 arg.vdev_id = arvif->vdev_id;
870 arg.dtim_period = arvif->dtim_period;
871 arg.bcn_intval = arvif->beacon_interval;
873 arg.channel.freq = chandef->chan->center_freq;
874 arg.channel.band_center_freq1 = chandef->center_freq1;
875 arg.channel.mode = chan_to_phymode(chandef);
877 arg.channel.min_power = 0;
878 arg.channel.max_power = chandef->chan->max_power * 2;
879 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
880 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
882 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
883 arg.ssid = arvif->u.ap.ssid;
884 arg.ssid_len = arvif->u.ap.ssid_len;
885 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
887 /* For now allow DFS for AP mode */
888 arg.channel.chan_radar =
889 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
890 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
891 arg.ssid = arvif->vif->bss_conf.ssid;
892 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
895 ath10k_dbg(ar, ATH10K_DBG_MAC,
896 "mac vdev %d start center_freq %d phymode %s\n",
897 arg.vdev_id, arg.channel.freq,
898 ath10k_wmi_phymode_str(arg.channel.mode));
901 ret = ath10k_wmi_vdev_restart(ar, &arg);
903 ret = ath10k_wmi_vdev_start(ar, &arg);
906 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
911 ret = ath10k_vdev_setup_sync(ar);
913 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
918 ar->num_started_vdevs++;
919 ath10k_recalc_radar_detection(ar);
924 static int ath10k_vdev_start(struct ath10k_vif *arvif)
926 return ath10k_vdev_start_restart(arvif, false);
929 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
931 return ath10k_vdev_start_restart(arvif, true);
934 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
936 struct ath10k *ar = arvif->ar;
939 lockdep_assert_held(&ar->conf_mutex);
941 reinit_completion(&ar->vdev_setup_done);
943 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
945 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
946 arvif->vdev_id, ret);
950 ret = ath10k_vdev_setup_sync(ar);
952 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
953 arvif->vdev_id, ret);
957 WARN_ON(ar->num_started_vdevs == 0);
959 if (ar->num_started_vdevs != 0) {
960 ar->num_started_vdevs--;
961 ath10k_recalc_radar_detection(ar);
967 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
968 struct ieee80211_bss_conf *info)
970 struct ath10k *ar = arvif->ar;
973 lockdep_assert_held(&arvif->ar->conf_mutex);
975 if (!info->enable_beacon) {
976 ath10k_vdev_stop(arvif);
978 arvif->is_started = false;
979 arvif->is_up = false;
981 spin_lock_bh(&arvif->ar->data_lock);
982 ath10k_mac_vif_beacon_free(arvif);
983 spin_unlock_bh(&arvif->ar->data_lock);
988 arvif->tx_seq_no = 0x1000;
990 ret = ath10k_vdev_start(arvif);
995 ether_addr_copy(arvif->bssid, info->bssid);
997 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1000 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1001 arvif->vdev_id, ret);
1002 ath10k_vdev_stop(arvif);
1006 arvif->is_started = true;
1007 arvif->is_up = true;
1009 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1012 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1013 struct ieee80211_bss_conf *info,
1014 const u8 self_peer[ETH_ALEN])
1016 struct ath10k *ar = arvif->ar;
1020 lockdep_assert_held(&arvif->ar->conf_mutex);
1022 if (!info->ibss_joined) {
1023 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1025 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1026 self_peer, arvif->vdev_id, ret);
1028 if (is_zero_ether_addr(arvif->bssid))
1031 memset(arvif->bssid, 0, ETH_ALEN);
1036 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1038 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1039 self_peer, arvif->vdev_id, ret);
1043 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1044 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1045 ATH10K_DEFAULT_ATIM);
1047 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1048 arvif->vdev_id, ret);
1051 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1053 struct ath10k *ar = arvif->ar;
1058 lockdep_assert_held(&arvif->ar->conf_mutex);
1060 if (arvif->u.sta.uapsd)
1061 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1063 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1065 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1066 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1068 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1069 value, arvif->vdev_id, ret);
1076 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1078 struct ath10k *ar = arvif->ar;
1083 lockdep_assert_held(&arvif->ar->conf_mutex);
1085 if (arvif->u.sta.uapsd)
1086 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1088 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1090 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1091 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1094 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1095 value, arvif->vdev_id, ret);
1102 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1104 struct ath10k *ar = arvif->ar;
1105 struct ieee80211_vif *vif = arvif->vif;
1106 struct ieee80211_conf *conf = &ar->hw->conf;
1107 enum wmi_sta_powersave_param param;
1108 enum wmi_sta_ps_mode psmode;
1112 lockdep_assert_held(&arvif->ar->conf_mutex);
1114 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1117 if (vif->bss_conf.ps) {
1118 psmode = WMI_STA_PS_MODE_ENABLED;
1119 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1121 ps_timeout = conf->dynamic_ps_timeout;
1122 if (ps_timeout == 0) {
1123 /* Firmware doesn't like 0 */
1124 ps_timeout = ieee80211_tu_to_usec(
1125 vif->bss_conf.beacon_int) / 1000;
1128 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1131 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1132 arvif->vdev_id, ret);
1136 psmode = WMI_STA_PS_MODE_DISABLED;
1139 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1140 arvif->vdev_id, psmode ? "enable" : "disable");
1142 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1144 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1145 psmode, arvif->vdev_id, ret);
1152 /**********************/
1153 /* Station management */
1154 /**********************/
1156 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1157 struct ieee80211_vif *vif)
1159 /* Some firmware revisions have unstable STA powersave when listen
1160 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1161 * generate NullFunc frames properly even if buffered frames have been
1162 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1163 * buffered frames. Often pinging the device from AP would simply fail.
1165 * As a workaround set it to 1.
1167 if (vif->type == NL80211_IFTYPE_STATION)
1170 return ar->hw->conf.listen_interval;
1173 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1174 struct ieee80211_vif *vif,
1175 struct ieee80211_sta *sta,
1176 struct wmi_peer_assoc_complete_arg *arg)
1178 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1180 lockdep_assert_held(&ar->conf_mutex);
1182 ether_addr_copy(arg->addr, sta->addr);
1183 arg->vdev_id = arvif->vdev_id;
1184 arg->peer_aid = sta->aid;
1185 arg->peer_flags |= WMI_PEER_AUTH;
1186 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1187 arg->peer_num_spatial_streams = 1;
1188 arg->peer_caps = vif->bss_conf.assoc_capability;
1191 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1192 struct ieee80211_vif *vif,
1193 struct wmi_peer_assoc_complete_arg *arg)
1195 struct ieee80211_bss_conf *info = &vif->bss_conf;
1196 struct cfg80211_bss *bss;
1197 const u8 *rsnie = NULL;
1198 const u8 *wpaie = NULL;
1200 lockdep_assert_held(&ar->conf_mutex);
1202 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1203 info->bssid, NULL, 0, 0, 0);
1205 const struct cfg80211_bss_ies *ies;
1208 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1210 ies = rcu_dereference(bss->ies);
1212 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1213 WLAN_OUI_TYPE_MICROSOFT_WPA,
1217 cfg80211_put_bss(ar->hw->wiphy, bss);
1220 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1221 if (rsnie || wpaie) {
1222 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1223 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1227 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1228 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1232 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1233 struct ieee80211_sta *sta,
1234 struct wmi_peer_assoc_complete_arg *arg)
1236 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1237 const struct ieee80211_supported_band *sband;
1238 const struct ieee80211_rate *rates;
1242 lockdep_assert_held(&ar->conf_mutex);
1244 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1245 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1246 rates = sband->bitrates;
1248 rateset->num_rates = 0;
1250 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1251 if (!(ratemask & 1))
1254 rateset->rates[rateset->num_rates] = rates->hw_value;
1255 rateset->num_rates++;
1259 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1260 struct ieee80211_sta *sta,
1261 struct wmi_peer_assoc_complete_arg *arg)
1263 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1267 lockdep_assert_held(&ar->conf_mutex);
1269 if (!ht_cap->ht_supported)
1272 arg->peer_flags |= WMI_PEER_HT;
1273 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1274 ht_cap->ampdu_factor)) - 1;
1276 arg->peer_mpdu_density =
1277 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1279 arg->peer_ht_caps = ht_cap->cap;
1280 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1282 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1283 arg->peer_flags |= WMI_PEER_LDPC;
1285 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1286 arg->peer_flags |= WMI_PEER_40MHZ;
1287 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1290 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1291 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1293 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1294 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1296 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1297 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1298 arg->peer_flags |= WMI_PEER_STBC;
1301 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1302 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1303 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1304 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1305 arg->peer_rate_caps |= stbc;
1306 arg->peer_flags |= WMI_PEER_STBC;
1309 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1310 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1311 else if (ht_cap->mcs.rx_mask[1])
1312 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1314 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1315 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1316 arg->peer_ht_rates.rates[n++] = i;
1319 * This is a workaround for HT-enabled STAs which break the spec
1320 * and have no HT capabilities RX mask (no HT RX MCS map).
1322 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1323 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1325 * Firmware asserts if such situation occurs.
1328 arg->peer_ht_rates.num_rates = 8;
1329 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1330 arg->peer_ht_rates.rates[i] = i;
1332 arg->peer_ht_rates.num_rates = n;
1333 arg->peer_num_spatial_streams = sta->rx_nss;
1336 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1338 arg->peer_ht_rates.num_rates,
1339 arg->peer_num_spatial_streams);
1342 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1343 struct ath10k_vif *arvif,
1344 struct ieee80211_sta *sta)
1350 lockdep_assert_held(&ar->conf_mutex);
1352 if (sta->wme && sta->uapsd_queues) {
1353 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1354 sta->uapsd_queues, sta->max_sp);
1356 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1357 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1358 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1359 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1360 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1361 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1362 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1363 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1364 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1365 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1366 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1367 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1369 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1370 max_sp = sta->max_sp;
1372 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1374 WMI_AP_PS_PEER_PARAM_UAPSD,
1377 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1378 arvif->vdev_id, ret);
1382 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1384 WMI_AP_PS_PEER_PARAM_MAX_SP,
1387 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1388 arvif->vdev_id, ret);
1392 /* TODO setup this based on STA listen interval and
1393 beacon interval. Currently we don't know
1394 sta->listen_interval - mac80211 patch required.
1395 Currently use 10 seconds */
1396 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1397 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1400 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1401 arvif->vdev_id, ret);
1409 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1410 struct ieee80211_sta *sta,
1411 struct wmi_peer_assoc_complete_arg *arg)
1413 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1416 if (!vht_cap->vht_supported)
1419 arg->peer_flags |= WMI_PEER_VHT;
1420 arg->peer_vht_caps = vht_cap->cap;
1422 ampdu_factor = (vht_cap->cap &
1423 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1424 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1426 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1427 * zero in VHT IE. Using it would result in degraded throughput.
1428 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1429 * it if VHT max_mpdu is smaller. */
1430 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1431 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1432 ampdu_factor)) - 1);
1434 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1435 arg->peer_flags |= WMI_PEER_80MHZ;
1437 arg->peer_vht_rates.rx_max_rate =
1438 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1439 arg->peer_vht_rates.rx_mcs_set =
1440 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1441 arg->peer_vht_rates.tx_max_rate =
1442 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1443 arg->peer_vht_rates.tx_mcs_set =
1444 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1446 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1447 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1450 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1451 struct ieee80211_vif *vif,
1452 struct ieee80211_sta *sta,
1453 struct wmi_peer_assoc_complete_arg *arg)
1455 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1457 switch (arvif->vdev_type) {
1458 case WMI_VDEV_TYPE_AP:
1460 arg->peer_flags |= WMI_PEER_QOS;
1462 if (sta->wme && sta->uapsd_queues) {
1463 arg->peer_flags |= WMI_PEER_APSD;
1464 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1467 case WMI_VDEV_TYPE_STA:
1468 if (vif->bss_conf.qos)
1469 arg->peer_flags |= WMI_PEER_QOS;
1471 case WMI_VDEV_TYPE_IBSS:
1473 arg->peer_flags |= WMI_PEER_QOS;
1479 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1480 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
1483 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1485 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1486 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1489 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1490 struct ieee80211_vif *vif,
1491 struct ieee80211_sta *sta,
1492 struct wmi_peer_assoc_complete_arg *arg)
1494 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1496 switch (ar->hw->conf.chandef.chan->band) {
1497 case IEEE80211_BAND_2GHZ:
1498 if (sta->ht_cap.ht_supported) {
1499 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1500 phymode = MODE_11NG_HT40;
1502 phymode = MODE_11NG_HT20;
1503 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
1510 case IEEE80211_BAND_5GHZ:
1514 if (sta->vht_cap.vht_supported) {
1515 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1516 phymode = MODE_11AC_VHT80;
1517 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1518 phymode = MODE_11AC_VHT40;
1519 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1520 phymode = MODE_11AC_VHT20;
1521 } else if (sta->ht_cap.ht_supported) {
1522 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1523 phymode = MODE_11NA_HT40;
1525 phymode = MODE_11NA_HT20;
1535 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1536 sta->addr, ath10k_wmi_phymode_str(phymode));
1538 arg->peer_phymode = phymode;
1539 WARN_ON(phymode == MODE_UNKNOWN);
1542 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1543 struct ieee80211_vif *vif,
1544 struct ieee80211_sta *sta,
1545 struct wmi_peer_assoc_complete_arg *arg)
1547 lockdep_assert_held(&ar->conf_mutex);
1549 memset(arg, 0, sizeof(*arg));
1551 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1552 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1553 ath10k_peer_assoc_h_rates(ar, sta, arg);
1554 ath10k_peer_assoc_h_ht(ar, sta, arg);
1555 ath10k_peer_assoc_h_vht(ar, sta, arg);
1556 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1557 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1562 static const u32 ath10k_smps_map[] = {
1563 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1564 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1565 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1566 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1569 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1571 const struct ieee80211_sta_ht_cap *ht_cap)
1575 if (!ht_cap->ht_supported)
1578 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1579 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1581 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1584 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1585 WMI_PEER_SMPS_STATE,
1586 ath10k_smps_map[smps]);
1589 /* can be called only in mac80211 callbacks due to `key_count` usage */
1590 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1591 struct ieee80211_vif *vif,
1592 struct ieee80211_bss_conf *bss_conf)
1594 struct ath10k *ar = hw->priv;
1595 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1596 struct ieee80211_sta_ht_cap ht_cap;
1597 struct wmi_peer_assoc_complete_arg peer_arg;
1598 struct ieee80211_sta *ap_sta;
1601 lockdep_assert_held(&ar->conf_mutex);
1603 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1604 arvif->vdev_id, arvif->bssid, arvif->aid);
1608 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1610 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1611 bss_conf->bssid, arvif->vdev_id);
1616 /* ap_sta must be accessed only within rcu section which must be left
1617 * before calling ath10k_setup_peer_smps() which might sleep. */
1618 ht_cap = ap_sta->ht_cap;
1620 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1622 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1623 bss_conf->bssid, arvif->vdev_id, ret);
1630 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1632 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1633 bss_conf->bssid, arvif->vdev_id, ret);
1637 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1639 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1640 arvif->vdev_id, ret);
1644 ath10k_dbg(ar, ATH10K_DBG_MAC,
1645 "mac vdev %d up (associated) bssid %pM aid %d\n",
1646 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1648 WARN_ON(arvif->is_up);
1650 arvif->aid = bss_conf->aid;
1651 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1653 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1655 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1656 arvif->vdev_id, ret);
1660 arvif->is_up = true;
1663 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1664 struct ieee80211_vif *vif)
1666 struct ath10k *ar = hw->priv;
1667 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1670 lockdep_assert_held(&ar->conf_mutex);
1672 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1673 arvif->vdev_id, arvif->bssid);
1675 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1677 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1678 arvif->vdev_id, ret);
1680 arvif->def_wep_key_idx = 0;
1681 arvif->is_up = false;
1684 static int ath10k_station_assoc(struct ath10k *ar,
1685 struct ieee80211_vif *vif,
1686 struct ieee80211_sta *sta,
1689 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1690 struct wmi_peer_assoc_complete_arg peer_arg;
1693 lockdep_assert_held(&ar->conf_mutex);
1695 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
1697 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1698 sta->addr, arvif->vdev_id, ret);
1702 peer_arg.peer_reassoc = reassoc;
1703 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1705 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1706 sta->addr, arvif->vdev_id, ret);
1710 /* Re-assoc is run only to update supported rates for given station. It
1711 * doesn't make much sense to reconfigure the peer completely.
1714 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1717 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1718 arvif->vdev_id, ret);
1722 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1724 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1725 sta->addr, arvif->vdev_id, ret);
1730 arvif->num_legacy_stations++;
1731 ret = ath10k_recalc_rtscts_prot(arvif);
1733 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1734 arvif->vdev_id, ret);
1739 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1741 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1742 arvif->vdev_id, ret);
1750 static int ath10k_station_disassoc(struct ath10k *ar,
1751 struct ieee80211_vif *vif,
1752 struct ieee80211_sta *sta)
1754 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1757 lockdep_assert_held(&ar->conf_mutex);
1760 arvif->num_legacy_stations--;
1761 ret = ath10k_recalc_rtscts_prot(arvif);
1763 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1764 arvif->vdev_id, ret);
1769 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1771 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1772 arvif->vdev_id, ret);
1783 static int ath10k_update_channel_list(struct ath10k *ar)
1785 struct ieee80211_hw *hw = ar->hw;
1786 struct ieee80211_supported_band **bands;
1787 enum ieee80211_band band;
1788 struct ieee80211_channel *channel;
1789 struct wmi_scan_chan_list_arg arg = {0};
1790 struct wmi_channel_arg *ch;
1796 lockdep_assert_held(&ar->conf_mutex);
1798 bands = hw->wiphy->bands;
1799 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1803 for (i = 0; i < bands[band]->n_channels; i++) {
1804 if (bands[band]->channels[i].flags &
1805 IEEE80211_CHAN_DISABLED)
1812 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1813 arg.channels = kzalloc(len, GFP_KERNEL);
1818 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1822 for (i = 0; i < bands[band]->n_channels; i++) {
1823 channel = &bands[band]->channels[i];
1825 if (channel->flags & IEEE80211_CHAN_DISABLED)
1828 ch->allow_ht = true;
1830 /* FIXME: when should we really allow VHT? */
1831 ch->allow_vht = true;
1834 !(channel->flags & IEEE80211_CHAN_NO_IR);
1837 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1840 !!(channel->flags & IEEE80211_CHAN_RADAR);
1842 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1843 ch->passive = passive;
1845 ch->freq = channel->center_freq;
1846 ch->band_center_freq1 = channel->center_freq;
1848 ch->max_power = channel->max_power * 2;
1849 ch->max_reg_power = channel->max_reg_power * 2;
1850 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1851 ch->reg_class_id = 0; /* FIXME */
1853 /* FIXME: why use only legacy modes, why not any
1854 * HT/VHT modes? Would that even make any
1856 if (channel->band == IEEE80211_BAND_2GHZ)
1857 ch->mode = MODE_11G;
1859 ch->mode = MODE_11A;
1861 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1864 ath10k_dbg(ar, ATH10K_DBG_WMI,
1865 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1866 ch - arg.channels, arg.n_channels,
1867 ch->freq, ch->max_power, ch->max_reg_power,
1868 ch->max_antenna_gain, ch->mode);
1874 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1875 kfree(arg.channels);
1880 static enum wmi_dfs_region
1881 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1883 switch (dfs_region) {
1884 case NL80211_DFS_UNSET:
1885 return WMI_UNINIT_DFS_DOMAIN;
1886 case NL80211_DFS_FCC:
1887 return WMI_FCC_DFS_DOMAIN;
1888 case NL80211_DFS_ETSI:
1889 return WMI_ETSI_DFS_DOMAIN;
1890 case NL80211_DFS_JP:
1891 return WMI_MKK4_DFS_DOMAIN;
1893 return WMI_UNINIT_DFS_DOMAIN;
1896 static void ath10k_regd_update(struct ath10k *ar)
1898 struct reg_dmn_pair_mapping *regpair;
1900 enum wmi_dfs_region wmi_dfs_reg;
1901 enum nl80211_dfs_regions nl_dfs_reg;
1903 lockdep_assert_held(&ar->conf_mutex);
1905 ret = ath10k_update_channel_list(ar);
1907 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1909 regpair = ar->ath_common.regulatory.regpair;
1911 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1912 nl_dfs_reg = ar->dfs_detector->region;
1913 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1915 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1918 /* Target allows setting up per-band regdomain but ath_common provides
1919 * a combined one only */
1920 ret = ath10k_wmi_pdev_set_regdomain(ar,
1921 regpair->reg_domain,
1922 regpair->reg_domain, /* 2ghz */
1923 regpair->reg_domain, /* 5ghz */
1924 regpair->reg_2ghz_ctl,
1925 regpair->reg_5ghz_ctl,
1928 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1931 static void ath10k_reg_notifier(struct wiphy *wiphy,
1932 struct regulatory_request *request)
1934 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1935 struct ath10k *ar = hw->priv;
1938 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1940 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1941 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1942 request->dfs_region);
1943 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1944 request->dfs_region);
1946 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1947 request->dfs_region);
1950 mutex_lock(&ar->conf_mutex);
1951 if (ar->state == ATH10K_STATE_ON)
1952 ath10k_regd_update(ar);
1953 mutex_unlock(&ar->conf_mutex);
1960 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1962 if (ieee80211_is_mgmt(hdr->frame_control))
1963 return HTT_DATA_TX_EXT_TID_MGMT;
1965 if (!ieee80211_is_data_qos(hdr->frame_control))
1966 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1968 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1969 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1971 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1974 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
1977 return ath10k_vif_to_arvif(vif)->vdev_id;
1979 if (ar->monitor_started)
1980 return ar->monitor_vdev_id;
1982 ath10k_warn(ar, "failed to resolve vdev id\n");
1986 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1987 * Control in the header.
1989 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1991 struct ieee80211_hdr *hdr = (void *)skb->data;
1992 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1995 if (!ieee80211_is_data_qos(hdr->frame_control))
1998 qos_ctl = ieee80211_get_qos_ctl(hdr);
1999 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2000 skb->data, (void *)qos_ctl - (void *)skb->data);
2001 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
2003 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2004 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2005 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2006 * it is safe to downgrade to NullFunc.
2008 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2009 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2010 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2014 static void ath10k_tx_wep_key_work(struct work_struct *work)
2016 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2018 struct ath10k *ar = arvif->ar;
2019 int ret, keyidx = arvif->def_wep_key_newidx;
2021 mutex_lock(&arvif->ar->conf_mutex);
2023 if (arvif->ar->state != ATH10K_STATE_ON)
2026 if (arvif->def_wep_key_idx == keyidx)
2029 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
2030 arvif->vdev_id, keyidx);
2032 ret = ath10k_wmi_vdev_set_param(arvif->ar,
2034 arvif->ar->wmi.vdev_param->def_keyid,
2037 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
2043 arvif->def_wep_key_idx = keyidx;
2046 mutex_unlock(&arvif->ar->conf_mutex);
2049 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
2050 struct ieee80211_key_conf *key,
2051 struct sk_buff *skb)
2053 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2054 struct ath10k *ar = arvif->ar;
2055 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2057 if (!ieee80211_has_protected(hdr->frame_control))
2063 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
2064 key->cipher != WLAN_CIPHER_SUITE_WEP104)
2067 if (key->keyidx == arvif->def_wep_key_idx)
2070 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
2071 * queueing frames until key index is updated is not an option because
2072 * sk_buff may need more processing to be done, e.g. offchannel */
2073 arvif->def_wep_key_newidx = key->keyidx;
2074 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
2077 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2078 struct ieee80211_vif *vif,
2079 struct sk_buff *skb)
2081 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2082 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2084 /* This is case only for P2P_GO */
2085 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2086 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2089 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2090 spin_lock_bh(&ar->data_lock);
2091 if (arvif->u.ap.noa_data)
2092 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2094 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2095 arvif->u.ap.noa_data,
2096 arvif->u.ap.noa_len);
2097 spin_unlock_bh(&ar->data_lock);
2101 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2103 /* FIXME: Not really sure since when the behaviour changed. At some
2104 * point new firmware stopped requiring creation of peer entries for
2105 * offchannel tx (and actually creating them causes issues with wmi-htc
2106 * tx credit replenishment and reliability). Assuming it's at least 3.4
2107 * because that's when the `freq` was introduced to TX_FRM HTT command.
2109 return !(ar->htt.target_version_major >= 3 &&
2110 ar->htt.target_version_minor >= 4);
2113 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2115 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2118 if (ar->htt.target_version_major >= 3) {
2119 /* Since HTT 3.0 there is no separate mgmt tx command */
2120 ret = ath10k_htt_tx(&ar->htt, skb);
2124 if (ieee80211_is_mgmt(hdr->frame_control)) {
2125 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2127 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2128 ATH10K_MAX_NUM_MGMT_PENDING) {
2129 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2134 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2135 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2137 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2139 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2141 ieee80211_is_nullfunc(hdr->frame_control)) {
2142 /* FW does not report tx status properly for NullFunc frames
2143 * unless they are sent through mgmt tx path. mac80211 sends
2144 * those frames when it detects link/beacon loss and depends
2145 * on the tx status to be correct. */
2146 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2148 ret = ath10k_htt_tx(&ar->htt, skb);
2153 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2155 ieee80211_free_txskb(ar->hw, skb);
2159 void ath10k_offchan_tx_purge(struct ath10k *ar)
2161 struct sk_buff *skb;
2164 skb = skb_dequeue(&ar->offchan_tx_queue);
2168 ieee80211_free_txskb(ar->hw, skb);
2172 void ath10k_offchan_tx_work(struct work_struct *work)
2174 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2175 struct ath10k_peer *peer;
2176 struct ieee80211_hdr *hdr;
2177 struct sk_buff *skb;
2178 const u8 *peer_addr;
2182 /* FW requirement: We must create a peer before FW will send out
2183 * an offchannel frame. Otherwise the frame will be stuck and
2184 * never transmitted. We delete the peer upon tx completion.
2185 * It is unlikely that a peer for offchannel tx will already be
2186 * present. However it may be in some rare cases so account for that.
2187 * Otherwise we might remove a legitimate peer and break stuff. */
2190 skb = skb_dequeue(&ar->offchan_tx_queue);
2194 mutex_lock(&ar->conf_mutex);
2196 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2199 hdr = (struct ieee80211_hdr *)skb->data;
2200 peer_addr = ieee80211_get_DA(hdr);
2201 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2203 spin_lock_bh(&ar->data_lock);
2204 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2205 spin_unlock_bh(&ar->data_lock);
2208 /* FIXME: should this use ath10k_warn()? */
2209 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2210 peer_addr, vdev_id);
2213 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2215 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2216 peer_addr, vdev_id, ret);
2219 spin_lock_bh(&ar->data_lock);
2220 reinit_completion(&ar->offchan_tx_completed);
2221 ar->offchan_tx_skb = skb;
2222 spin_unlock_bh(&ar->data_lock);
2224 ath10k_tx_htt(ar, skb);
2226 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2229 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2233 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2235 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2236 peer_addr, vdev_id, ret);
2239 mutex_unlock(&ar->conf_mutex);
2243 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2245 struct sk_buff *skb;
2248 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2252 ieee80211_free_txskb(ar->hw, skb);
2256 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2258 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2259 struct sk_buff *skb;
2263 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2267 ret = ath10k_wmi_mgmt_tx(ar, skb);
2269 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2271 ieee80211_free_txskb(ar->hw, skb);
2280 void __ath10k_scan_finish(struct ath10k *ar)
2282 lockdep_assert_held(&ar->data_lock);
2284 switch (ar->scan.state) {
2285 case ATH10K_SCAN_IDLE:
2287 case ATH10K_SCAN_RUNNING:
2288 if (ar->scan.is_roc)
2289 ieee80211_remain_on_channel_expired(ar->hw);
2290 case ATH10K_SCAN_ABORTING:
2291 if (!ar->scan.is_roc)
2292 ieee80211_scan_completed(ar->hw,
2294 ATH10K_SCAN_ABORTING));
2296 case ATH10K_SCAN_STARTING:
2297 ar->scan.state = ATH10K_SCAN_IDLE;
2298 ar->scan_channel = NULL;
2299 ath10k_offchan_tx_purge(ar);
2300 cancel_delayed_work(&ar->scan.timeout);
2301 complete_all(&ar->scan.completed);
2306 void ath10k_scan_finish(struct ath10k *ar)
2308 spin_lock_bh(&ar->data_lock);
2309 __ath10k_scan_finish(ar);
2310 spin_unlock_bh(&ar->data_lock);
2313 static int ath10k_scan_stop(struct ath10k *ar)
2315 struct wmi_stop_scan_arg arg = {
2316 .req_id = 1, /* FIXME */
2317 .req_type = WMI_SCAN_STOP_ONE,
2318 .u.scan_id = ATH10K_SCAN_ID,
2322 lockdep_assert_held(&ar->conf_mutex);
2324 ret = ath10k_wmi_stop_scan(ar, &arg);
2326 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2330 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2332 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2334 } else if (ret > 0) {
2339 /* Scan state should be updated upon scan completion but in case
2340 * firmware fails to deliver the event (for whatever reason) it is
2341 * desired to clean up scan state anyway. Firmware may have just
2342 * dropped the scan completion event delivery due to transport pipe
2343 * being overflown with data and/or it can recover on its own before
2344 * next scan request is submitted.
2346 spin_lock_bh(&ar->data_lock);
2347 if (ar->scan.state != ATH10K_SCAN_IDLE)
2348 __ath10k_scan_finish(ar);
2349 spin_unlock_bh(&ar->data_lock);
2354 static void ath10k_scan_abort(struct ath10k *ar)
2358 lockdep_assert_held(&ar->conf_mutex);
2360 spin_lock_bh(&ar->data_lock);
2362 switch (ar->scan.state) {
2363 case ATH10K_SCAN_IDLE:
2364 /* This can happen if timeout worker kicked in and called
2365 * abortion while scan completion was being processed.
2368 case ATH10K_SCAN_STARTING:
2369 case ATH10K_SCAN_ABORTING:
2370 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2371 ath10k_scan_state_str(ar->scan.state),
2374 case ATH10K_SCAN_RUNNING:
2375 ar->scan.state = ATH10K_SCAN_ABORTING;
2376 spin_unlock_bh(&ar->data_lock);
2378 ret = ath10k_scan_stop(ar);
2380 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2382 spin_lock_bh(&ar->data_lock);
2386 spin_unlock_bh(&ar->data_lock);
2389 void ath10k_scan_timeout_work(struct work_struct *work)
2391 struct ath10k *ar = container_of(work, struct ath10k,
2394 mutex_lock(&ar->conf_mutex);
2395 ath10k_scan_abort(ar);
2396 mutex_unlock(&ar->conf_mutex);
2399 static int ath10k_start_scan(struct ath10k *ar,
2400 const struct wmi_start_scan_arg *arg)
2404 lockdep_assert_held(&ar->conf_mutex);
2406 ret = ath10k_wmi_start_scan(ar, arg);
2410 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2412 ret = ath10k_scan_stop(ar);
2414 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2419 /* Add a 200ms margin to account for event/command processing */
2420 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2421 msecs_to_jiffies(arg->max_scan_time+200));
2425 /**********************/
2426 /* mac80211 callbacks */
2427 /**********************/
2429 static void ath10k_tx(struct ieee80211_hw *hw,
2430 struct ieee80211_tx_control *control,
2431 struct sk_buff *skb)
2433 struct ath10k *ar = hw->priv;
2434 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2435 struct ieee80211_vif *vif = info->control.vif;
2436 struct ieee80211_key_conf *key = info->control.hw_key;
2437 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2439 /* We should disable CCK RATE due to P2P */
2440 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2441 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2443 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2444 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2445 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2447 /* it makes no sense to process injected frames like that */
2448 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2449 ath10k_tx_h_nwifi(hw, skb);
2450 ath10k_tx_h_update_wep_key(vif, key, skb);
2451 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2452 ath10k_tx_h_seq_no(vif, skb);
2455 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2456 spin_lock_bh(&ar->data_lock);
2457 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
2458 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2459 spin_unlock_bh(&ar->data_lock);
2461 if (ath10k_mac_need_offchan_tx_work(ar)) {
2462 ATH10K_SKB_CB(skb)->htt.freq = 0;
2463 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2465 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2468 skb_queue_tail(&ar->offchan_tx_queue, skb);
2469 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2474 ath10k_tx_htt(ar, skb);
2477 /* Must not be called with conf_mutex held as workers can use that also. */
2478 void ath10k_drain_tx(struct ath10k *ar)
2480 /* make sure rcu-protected mac80211 tx path itself is drained */
2483 ath10k_offchan_tx_purge(ar);
2484 ath10k_mgmt_over_wmi_tx_purge(ar);
2486 cancel_work_sync(&ar->offchan_tx_work);
2487 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2490 void ath10k_halt(struct ath10k *ar)
2492 struct ath10k_vif *arvif;
2494 lockdep_assert_held(&ar->conf_mutex);
2496 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2497 ar->filter_flags = 0;
2498 ar->monitor = false;
2500 if (ar->monitor_started)
2501 ath10k_monitor_stop(ar);
2503 ar->monitor_started = false;
2505 ath10k_scan_finish(ar);
2506 ath10k_peer_cleanup_all(ar);
2507 ath10k_core_stop(ar);
2508 ath10k_hif_power_down(ar);
2510 spin_lock_bh(&ar->data_lock);
2511 list_for_each_entry(arvif, &ar->arvifs, list)
2512 ath10k_mac_vif_beacon_cleanup(arvif);
2513 spin_unlock_bh(&ar->data_lock);
2516 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2518 struct ath10k *ar = hw->priv;
2520 mutex_lock(&ar->conf_mutex);
2522 if (ar->cfg_tx_chainmask) {
2523 *tx_ant = ar->cfg_tx_chainmask;
2524 *rx_ant = ar->cfg_rx_chainmask;
2526 *tx_ant = ar->supp_tx_chainmask;
2527 *rx_ant = ar->supp_rx_chainmask;
2530 mutex_unlock(&ar->conf_mutex);
2535 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2537 /* It is not clear that allowing gaps in chainmask
2538 * is helpful. Probably it will not do what user
2539 * is hoping for, so warn in that case.
2541 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2544 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2548 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2552 lockdep_assert_held(&ar->conf_mutex);
2554 ath10k_check_chain_mask(ar, tx_ant, "tx");
2555 ath10k_check_chain_mask(ar, rx_ant, "rx");
2557 ar->cfg_tx_chainmask = tx_ant;
2558 ar->cfg_rx_chainmask = rx_ant;
2560 if ((ar->state != ATH10K_STATE_ON) &&
2561 (ar->state != ATH10K_STATE_RESTARTED))
2564 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2567 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2572 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2575 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2583 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2585 struct ath10k *ar = hw->priv;
2588 mutex_lock(&ar->conf_mutex);
2589 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2590 mutex_unlock(&ar->conf_mutex);
2594 static int ath10k_start(struct ieee80211_hw *hw)
2596 struct ath10k *ar = hw->priv;
2600 * This makes sense only when restarting hw. It is harmless to call
2601 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2602 * commands will be submitted while restarting.
2604 ath10k_drain_tx(ar);
2606 mutex_lock(&ar->conf_mutex);
2608 switch (ar->state) {
2609 case ATH10K_STATE_OFF:
2610 ar->state = ATH10K_STATE_ON;
2612 case ATH10K_STATE_RESTARTING:
2614 ar->state = ATH10K_STATE_RESTARTED;
2616 case ATH10K_STATE_ON:
2617 case ATH10K_STATE_RESTARTED:
2618 case ATH10K_STATE_WEDGED:
2622 case ATH10K_STATE_UTF:
2627 ret = ath10k_hif_power_up(ar);
2629 ath10k_err(ar, "Could not init hif: %d\n", ret);
2633 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2635 ath10k_err(ar, "Could not init core: %d\n", ret);
2636 goto err_power_down;
2639 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2641 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2645 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2647 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2651 if (ar->cfg_tx_chainmask)
2652 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2653 ar->cfg_rx_chainmask);
2656 * By default FW set ARP frames ac to voice (6). In that case ARP
2657 * exchange is not working properly for UAPSD enabled AP. ARP requests
2658 * which arrives with access category 0 are processed by network stack
2659 * and send back with access category 0, but FW changes access category
2660 * to 6. Set ARP frames access category to best effort (0) solves
2664 ret = ath10k_wmi_pdev_set_param(ar,
2665 ar->wmi.pdev_param->arp_ac_override, 0);
2667 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2672 ar->num_started_vdevs = 0;
2673 ath10k_regd_update(ar);
2675 ath10k_spectral_start(ar);
2677 mutex_unlock(&ar->conf_mutex);
2681 ath10k_core_stop(ar);
2684 ath10k_hif_power_down(ar);
2687 ar->state = ATH10K_STATE_OFF;
2690 mutex_unlock(&ar->conf_mutex);
2694 static void ath10k_stop(struct ieee80211_hw *hw)
2696 struct ath10k *ar = hw->priv;
2698 ath10k_drain_tx(ar);
2700 mutex_lock(&ar->conf_mutex);
2701 if (ar->state != ATH10K_STATE_OFF) {
2703 ar->state = ATH10K_STATE_OFF;
2705 mutex_unlock(&ar->conf_mutex);
2707 cancel_delayed_work_sync(&ar->scan.timeout);
2708 cancel_work_sync(&ar->restart_work);
2711 static int ath10k_config_ps(struct ath10k *ar)
2713 struct ath10k_vif *arvif;
2716 lockdep_assert_held(&ar->conf_mutex);
2718 list_for_each_entry(arvif, &ar->arvifs, list) {
2719 ret = ath10k_mac_vif_setup_ps(arvif);
2721 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2729 static const char *chandef_get_width(enum nl80211_chan_width width)
2732 case NL80211_CHAN_WIDTH_20_NOHT:
2734 case NL80211_CHAN_WIDTH_20:
2736 case NL80211_CHAN_WIDTH_40:
2738 case NL80211_CHAN_WIDTH_80:
2740 case NL80211_CHAN_WIDTH_80P80:
2742 case NL80211_CHAN_WIDTH_160:
2744 case NL80211_CHAN_WIDTH_5:
2746 case NL80211_CHAN_WIDTH_10:
2752 static void ath10k_config_chan(struct ath10k *ar)
2754 struct ath10k_vif *arvif;
2757 lockdep_assert_held(&ar->conf_mutex);
2759 ath10k_dbg(ar, ATH10K_DBG_MAC,
2760 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2761 ar->chandef.chan->center_freq,
2762 ar->chandef.center_freq1,
2763 ar->chandef.center_freq2,
2764 chandef_get_width(ar->chandef.width));
2766 /* First stop monitor interface. Some FW versions crash if there's a
2767 * lone monitor interface. */
2768 if (ar->monitor_started)
2769 ath10k_monitor_stop(ar);
2771 list_for_each_entry(arvif, &ar->arvifs, list) {
2772 if (!arvif->is_started)
2778 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2781 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2783 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2784 arvif->vdev_id, ret);
2789 /* all vdevs are downed now - attempt to restart and re-up them */
2791 list_for_each_entry(arvif, &ar->arvifs, list) {
2792 if (!arvif->is_started)
2795 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2798 ret = ath10k_vdev_restart(arvif);
2800 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2801 arvif->vdev_id, ret);
2808 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2811 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2812 arvif->vdev_id, ret);
2817 ath10k_monitor_recalc(ar);
2820 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2825 lockdep_assert_held(&ar->conf_mutex);
2827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2829 param = ar->wmi.pdev_param->txpower_limit2g;
2830 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2832 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2837 param = ar->wmi.pdev_param->txpower_limit5g;
2838 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2840 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2848 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2850 struct ath10k_vif *arvif;
2851 int ret, txpower = -1;
2853 lockdep_assert_held(&ar->conf_mutex);
2855 list_for_each_entry(arvif, &ar->arvifs, list) {
2856 WARN_ON(arvif->txpower < 0);
2859 txpower = arvif->txpower;
2861 txpower = min(txpower, arvif->txpower);
2864 if (WARN_ON(txpower == -1))
2867 ret = ath10k_mac_txpower_setup(ar, txpower);
2869 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2877 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2879 struct ath10k *ar = hw->priv;
2880 struct ieee80211_conf *conf = &hw->conf;
2883 mutex_lock(&ar->conf_mutex);
2885 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2886 ath10k_dbg(ar, ATH10K_DBG_MAC,
2887 "mac config channel %dMHz flags 0x%x radar %d\n",
2888 conf->chandef.chan->center_freq,
2889 conf->chandef.chan->flags,
2890 conf->radar_enabled);
2892 spin_lock_bh(&ar->data_lock);
2893 ar->rx_channel = conf->chandef.chan;
2894 spin_unlock_bh(&ar->data_lock);
2896 ar->radar_enabled = conf->radar_enabled;
2897 ath10k_recalc_radar_detection(ar);
2899 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2900 ar->chandef = conf->chandef;
2901 ath10k_config_chan(ar);
2905 if (changed & IEEE80211_CONF_CHANGE_PS)
2906 ath10k_config_ps(ar);
2908 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2909 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2910 ret = ath10k_monitor_recalc(ar);
2912 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2915 mutex_unlock(&ar->conf_mutex);
2919 static u32 get_nss_from_chainmask(u16 chain_mask)
2921 if ((chain_mask & 0x15) == 0x15)
2923 else if ((chain_mask & 0x7) == 0x7)
2925 else if ((chain_mask & 0x3) == 0x3)
2932 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2933 * because we will send mgmt frames without CCK. This requirement
2934 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2937 static int ath10k_add_interface(struct ieee80211_hw *hw,
2938 struct ieee80211_vif *vif)
2940 struct ath10k *ar = hw->priv;
2941 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2942 enum wmi_sta_powersave_param param;
2948 mutex_lock(&ar->conf_mutex);
2950 memset(arvif, 0, sizeof(*arvif));
2955 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2956 INIT_LIST_HEAD(&arvif->list);
2958 if (ar->free_vdev_map == 0) {
2959 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2963 bit = __ffs64(ar->free_vdev_map);
2965 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2966 bit, ar->free_vdev_map);
2968 arvif->vdev_id = bit;
2969 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2971 switch (vif->type) {
2972 case NL80211_IFTYPE_P2P_DEVICE:
2973 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2974 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2976 case NL80211_IFTYPE_UNSPECIFIED:
2977 case NL80211_IFTYPE_STATION:
2978 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2980 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2982 case NL80211_IFTYPE_ADHOC:
2983 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2985 case NL80211_IFTYPE_AP:
2986 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2989 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2991 case NL80211_IFTYPE_MONITOR:
2992 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2999 /* Some firmware revisions don't wait for beacon tx completion before
3000 * sending another SWBA event. This could lead to hardware using old
3001 * (freed) beacon data in some cases, e.g. tx credit starvation
3002 * combined with missed TBTT. This is very very rare.
3004 * On non-IOMMU-enabled hosts this could be a possible security issue
3005 * because hw could beacon some random data on the air. On
3006 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3007 * device would crash.
3009 * Since there are no beacon tx completions (implicit nor explicit)
3010 * propagated to host the only workaround for this is to allocate a
3011 * DMA-coherent buffer for a lifetime of a vif and use it for all
3012 * beacon tx commands. Worst case for this approach is some beacons may
3013 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3015 if (vif->type == NL80211_IFTYPE_ADHOC ||
3016 vif->type == NL80211_IFTYPE_AP) {
3017 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3018 IEEE80211_MAX_FRAME_LEN,
3019 &arvif->beacon_paddr,
3021 if (!arvif->beacon_buf) {
3023 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3029 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3030 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3031 arvif->beacon_buf ? "single-buf" : "per-skb");
3033 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3034 arvif->vdev_subtype, vif->addr);
3036 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
3037 arvif->vdev_id, ret);
3041 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
3042 list_add(&arvif->list, &ar->arvifs);
3044 vdev_param = ar->wmi.vdev_param->def_keyid;
3045 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
3046 arvif->def_wep_key_idx);
3048 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
3049 arvif->vdev_id, ret);
3050 goto err_vdev_delete;
3053 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3054 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3055 ATH10K_HW_TXRX_NATIVE_WIFI);
3056 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3057 if (ret && ret != -EOPNOTSUPP) {
3058 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
3059 arvif->vdev_id, ret);
3060 goto err_vdev_delete;
3063 if (ar->cfg_tx_chainmask) {
3064 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3066 vdev_param = ar->wmi.vdev_param->nss;
3067 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3070 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3071 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3073 goto err_vdev_delete;
3077 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3078 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3080 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
3081 arvif->vdev_id, ret);
3082 goto err_vdev_delete;
3085 ret = ath10k_mac_set_kickout(arvif);
3087 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
3088 arvif->vdev_id, ret);
3089 goto err_peer_delete;
3093 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3094 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3095 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3096 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3099 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
3100 arvif->vdev_id, ret);
3101 goto err_peer_delete;
3104 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3106 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3107 arvif->vdev_id, ret);
3108 goto err_peer_delete;
3111 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3113 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3114 arvif->vdev_id, ret);
3115 goto err_peer_delete;
3119 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
3121 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3122 arvif->vdev_id, ret);
3123 goto err_peer_delete;
3126 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
3128 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
3129 arvif->vdev_id, ret);
3130 goto err_peer_delete;
3133 arvif->txpower = vif->bss_conf.txpower;
3134 ret = ath10k_mac_txpower_recalc(ar);
3136 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3137 goto err_peer_delete;
3140 mutex_unlock(&ar->conf_mutex);
3144 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3145 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3148 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3149 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3150 list_del(&arvif->list);
3153 if (arvif->beacon_buf) {
3154 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3155 arvif->beacon_buf, arvif->beacon_paddr);
3156 arvif->beacon_buf = NULL;
3159 mutex_unlock(&ar->conf_mutex);
3164 static void ath10k_remove_interface(struct ieee80211_hw *hw,
3165 struct ieee80211_vif *vif)
3167 struct ath10k *ar = hw->priv;
3168 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3171 cancel_work_sync(&arvif->wep_key_work);
3173 mutex_lock(&ar->conf_mutex);
3175 spin_lock_bh(&ar->data_lock);
3176 ath10k_mac_vif_beacon_cleanup(arvif);
3177 spin_unlock_bh(&ar->data_lock);
3179 ret = ath10k_spectral_vif_stop(arvif);
3181 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
3182 arvif->vdev_id, ret);
3184 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3185 list_del(&arvif->list);
3187 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3188 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3190 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
3191 arvif->vdev_id, ret);
3193 kfree(arvif->u.ap.noa_data);
3196 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3199 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3201 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3202 arvif->vdev_id, ret);
3204 ath10k_peer_cleanup(ar, arvif->vdev_id);
3206 mutex_unlock(&ar->conf_mutex);
3210 * FIXME: Has to be verified.
3212 #define SUPPORTED_FILTERS \
3213 (FIF_PROMISC_IN_BSS | \
3218 FIF_BCN_PRBRESP_PROMISC | \
3222 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3223 unsigned int changed_flags,
3224 unsigned int *total_flags,
3227 struct ath10k *ar = hw->priv;
3230 mutex_lock(&ar->conf_mutex);
3232 changed_flags &= SUPPORTED_FILTERS;
3233 *total_flags &= SUPPORTED_FILTERS;
3234 ar->filter_flags = *total_flags;
3236 ret = ath10k_monitor_recalc(ar);
3238 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3240 mutex_unlock(&ar->conf_mutex);
3243 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3244 struct ieee80211_vif *vif,
3245 struct ieee80211_bss_conf *info,
3248 struct ath10k *ar = hw->priv;
3249 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3251 u32 vdev_param, pdev_param, slottime, preamble;
3253 mutex_lock(&ar->conf_mutex);
3255 if (changed & BSS_CHANGED_IBSS)
3256 ath10k_control_ibss(arvif, info, vif->addr);
3258 if (changed & BSS_CHANGED_BEACON_INT) {
3259 arvif->beacon_interval = info->beacon_int;
3260 vdev_param = ar->wmi.vdev_param->beacon_interval;
3261 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3262 arvif->beacon_interval);
3263 ath10k_dbg(ar, ATH10K_DBG_MAC,
3264 "mac vdev %d beacon_interval %d\n",
3265 arvif->vdev_id, arvif->beacon_interval);
3268 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3269 arvif->vdev_id, ret);
3272 if (changed & BSS_CHANGED_BEACON) {
3273 ath10k_dbg(ar, ATH10K_DBG_MAC,
3274 "vdev %d set beacon tx mode to staggered\n",
3277 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3278 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3279 WMI_BEACON_STAGGERED_MODE);
3281 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3282 arvif->vdev_id, ret);
3285 if (changed & BSS_CHANGED_BEACON_INFO) {
3286 arvif->dtim_period = info->dtim_period;
3288 ath10k_dbg(ar, ATH10K_DBG_MAC,
3289 "mac vdev %d dtim_period %d\n",
3290 arvif->vdev_id, arvif->dtim_period);
3292 vdev_param = ar->wmi.vdev_param->dtim_period;
3293 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3294 arvif->dtim_period);
3296 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3297 arvif->vdev_id, ret);
3300 if (changed & BSS_CHANGED_SSID &&
3301 vif->type == NL80211_IFTYPE_AP) {
3302 arvif->u.ap.ssid_len = info->ssid_len;
3304 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3305 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3308 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3309 ether_addr_copy(arvif->bssid, info->bssid);
3311 if (changed & BSS_CHANGED_BEACON_ENABLED)
3312 ath10k_control_beaconing(arvif, info);
3314 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3315 arvif->use_cts_prot = info->use_cts_prot;
3316 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3317 arvif->vdev_id, info->use_cts_prot);
3319 ret = ath10k_recalc_rtscts_prot(arvif);
3321 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3322 arvif->vdev_id, ret);
3325 if (changed & BSS_CHANGED_ERP_SLOT) {
3326 if (info->use_short_slot)
3327 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3330 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3332 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3333 arvif->vdev_id, slottime);
3335 vdev_param = ar->wmi.vdev_param->slot_time;
3336 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3339 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3340 arvif->vdev_id, ret);
3343 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3344 if (info->use_short_preamble)
3345 preamble = WMI_VDEV_PREAMBLE_SHORT;
3347 preamble = WMI_VDEV_PREAMBLE_LONG;
3349 ath10k_dbg(ar, ATH10K_DBG_MAC,
3350 "mac vdev %d preamble %dn",
3351 arvif->vdev_id, preamble);
3353 vdev_param = ar->wmi.vdev_param->preamble;
3354 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3357 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3358 arvif->vdev_id, ret);
3361 if (changed & BSS_CHANGED_ASSOC) {
3363 /* Workaround: Make sure monitor vdev is not running
3364 * when associating to prevent some firmware revisions
3365 * (e.g. 10.1 and 10.2) from crashing.
3367 if (ar->monitor_started)
3368 ath10k_monitor_stop(ar);
3369 ath10k_bss_assoc(hw, vif, info);
3370 ath10k_monitor_recalc(ar);
3372 ath10k_bss_disassoc(hw, vif);
3376 if (changed & BSS_CHANGED_TXPOWER) {
3377 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3378 arvif->vdev_id, info->txpower);
3380 arvif->txpower = info->txpower;
3381 ret = ath10k_mac_txpower_recalc(ar);
3383 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3386 if (changed & BSS_CHANGED_PS) {
3387 ret = ath10k_mac_vif_setup_ps(arvif);
3389 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3390 arvif->vdev_id, ret);
3393 mutex_unlock(&ar->conf_mutex);
3396 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3397 struct ieee80211_vif *vif,
3398 struct ieee80211_scan_request *hw_req)
3400 struct ath10k *ar = hw->priv;
3401 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3402 struct cfg80211_scan_request *req = &hw_req->req;
3403 struct wmi_start_scan_arg arg;
3407 mutex_lock(&ar->conf_mutex);
3409 spin_lock_bh(&ar->data_lock);
3410 switch (ar->scan.state) {
3411 case ATH10K_SCAN_IDLE:
3412 reinit_completion(&ar->scan.started);
3413 reinit_completion(&ar->scan.completed);
3414 ar->scan.state = ATH10K_SCAN_STARTING;
3415 ar->scan.is_roc = false;
3416 ar->scan.vdev_id = arvif->vdev_id;
3419 case ATH10K_SCAN_STARTING:
3420 case ATH10K_SCAN_RUNNING:
3421 case ATH10K_SCAN_ABORTING:
3425 spin_unlock_bh(&ar->data_lock);
3430 memset(&arg, 0, sizeof(arg));
3431 ath10k_wmi_start_scan_init(ar, &arg);
3432 arg.vdev_id = arvif->vdev_id;
3433 arg.scan_id = ATH10K_SCAN_ID;
3436 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3439 arg.ie_len = req->ie_len;
3440 memcpy(arg.ie, req->ie, arg.ie_len);
3444 arg.n_ssids = req->n_ssids;
3445 for (i = 0; i < arg.n_ssids; i++) {
3446 arg.ssids[i].len = req->ssids[i].ssid_len;
3447 arg.ssids[i].ssid = req->ssids[i].ssid;
3450 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3453 if (req->n_channels) {
3454 arg.n_channels = req->n_channels;
3455 for (i = 0; i < arg.n_channels; i++)
3456 arg.channels[i] = req->channels[i]->center_freq;
3459 ret = ath10k_start_scan(ar, &arg);
3461 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3462 spin_lock_bh(&ar->data_lock);
3463 ar->scan.state = ATH10K_SCAN_IDLE;
3464 spin_unlock_bh(&ar->data_lock);
3468 mutex_unlock(&ar->conf_mutex);
3472 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3473 struct ieee80211_vif *vif)
3475 struct ath10k *ar = hw->priv;
3477 mutex_lock(&ar->conf_mutex);
3478 ath10k_scan_abort(ar);
3479 mutex_unlock(&ar->conf_mutex);
3481 cancel_delayed_work_sync(&ar->scan.timeout);
3484 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3485 struct ath10k_vif *arvif,
3486 enum set_key_cmd cmd,
3487 struct ieee80211_key_conf *key)
3489 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3492 /* 10.1 firmware branch requires default key index to be set to group
3493 * key index after installing it. Otherwise FW/HW Txes corrupted
3494 * frames with multi-vif APs. This is not required for main firmware
3495 * branch (e.g. 636).
3497 * FIXME: This has been tested only in AP. It remains unknown if this
3498 * is required for multi-vif STA interfaces on 10.1 */
3500 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3503 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3506 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3509 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3515 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3518 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3519 arvif->vdev_id, ret);
3522 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3523 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3524 struct ieee80211_key_conf *key)
3526 struct ath10k *ar = hw->priv;
3527 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3528 struct ath10k_peer *peer;
3529 const u8 *peer_addr;
3530 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3531 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3534 if (key->keyidx > WMI_MAX_KEY_INDEX)
3537 mutex_lock(&ar->conf_mutex);
3540 peer_addr = sta->addr;
3541 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3542 peer_addr = vif->bss_conf.bssid;
3544 peer_addr = vif->addr;
3546 key->hw_key_idx = key->keyidx;
3548 /* the peer should not disappear in mid-way (unless FW goes awry) since
3549 * we already hold conf_mutex. we just make sure its there now. */
3550 spin_lock_bh(&ar->data_lock);
3551 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3552 spin_unlock_bh(&ar->data_lock);
3555 if (cmd == SET_KEY) {
3556 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3561 /* if the peer doesn't exist there is no key to disable
3569 arvif->wep_keys[key->keyidx] = key;
3571 arvif->wep_keys[key->keyidx] = NULL;
3573 if (cmd == DISABLE_KEY)
3574 ath10k_clear_vdev_key(arvif, key);
3577 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3579 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3580 arvif->vdev_id, peer_addr, ret);
3584 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3586 spin_lock_bh(&ar->data_lock);
3587 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3588 if (peer && cmd == SET_KEY)
3589 peer->keys[key->keyidx] = key;
3590 else if (peer && cmd == DISABLE_KEY)
3591 peer->keys[key->keyidx] = NULL;
3592 else if (peer == NULL)
3593 /* impossible unless FW goes crazy */
3594 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3595 spin_unlock_bh(&ar->data_lock);
3598 mutex_unlock(&ar->conf_mutex);
3602 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3605 struct ath10k_vif *arvif;
3606 struct ath10k_sta *arsta;
3607 struct ieee80211_sta *sta;
3608 u32 changed, bw, nss, smps;
3611 arsta = container_of(wk, struct ath10k_sta, update_wk);
3612 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3613 arvif = arsta->arvif;
3616 spin_lock_bh(&ar->data_lock);
3618 changed = arsta->changed;
3625 spin_unlock_bh(&ar->data_lock);
3627 mutex_lock(&ar->conf_mutex);
3629 if (changed & IEEE80211_RC_BW_CHANGED) {
3630 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3633 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3634 WMI_PEER_CHAN_WIDTH, bw);
3636 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3637 sta->addr, bw, err);
3640 if (changed & IEEE80211_RC_NSS_CHANGED) {
3641 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3644 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3647 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3648 sta->addr, nss, err);
3651 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3652 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3655 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3656 WMI_PEER_SMPS_STATE, smps);
3658 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3659 sta->addr, smps, err);
3662 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3663 changed & IEEE80211_RC_NSS_CHANGED) {
3664 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
3667 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3669 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3673 mutex_unlock(&ar->conf_mutex);
3676 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3678 struct ath10k *ar = arvif->ar;
3680 lockdep_assert_held(&ar->conf_mutex);
3682 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3683 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3686 if (ar->num_stations >= ar->max_num_stations)
3694 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3696 struct ath10k *ar = arvif->ar;
3698 lockdep_assert_held(&ar->conf_mutex);
3700 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3701 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3707 static int ath10k_sta_state(struct ieee80211_hw *hw,
3708 struct ieee80211_vif *vif,
3709 struct ieee80211_sta *sta,
3710 enum ieee80211_sta_state old_state,
3711 enum ieee80211_sta_state new_state)
3713 struct ath10k *ar = hw->priv;
3714 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3715 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3718 if (old_state == IEEE80211_STA_NOTEXIST &&
3719 new_state == IEEE80211_STA_NONE) {
3720 memset(arsta, 0, sizeof(*arsta));
3721 arsta->arvif = arvif;
3722 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3725 /* cancel must be done outside the mutex to avoid deadlock */
3726 if ((old_state == IEEE80211_STA_NONE &&
3727 new_state == IEEE80211_STA_NOTEXIST))
3728 cancel_work_sync(&arsta->update_wk);
3730 mutex_lock(&ar->conf_mutex);
3732 if (old_state == IEEE80211_STA_NOTEXIST &&
3733 new_state == IEEE80211_STA_NONE) {
3735 * New station addition.
3737 ath10k_dbg(ar, ATH10K_DBG_MAC,
3738 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3739 arvif->vdev_id, sta->addr,
3740 ar->num_stations + 1, ar->max_num_stations,
3741 ar->num_peers + 1, ar->max_num_peers);
3743 ret = ath10k_mac_inc_num_stations(arvif);
3745 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3746 ar->max_num_stations);
3750 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3752 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3753 sta->addr, arvif->vdev_id, ret);
3754 ath10k_mac_dec_num_stations(arvif);
3758 if (vif->type == NL80211_IFTYPE_STATION) {
3759 WARN_ON(arvif->is_started);
3761 ret = ath10k_vdev_start(arvif);
3763 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3764 arvif->vdev_id, ret);
3765 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3767 ath10k_mac_dec_num_stations(arvif);
3771 arvif->is_started = true;
3773 } else if ((old_state == IEEE80211_STA_NONE &&
3774 new_state == IEEE80211_STA_NOTEXIST)) {
3776 * Existing station deletion.
3778 ath10k_dbg(ar, ATH10K_DBG_MAC,
3779 "mac vdev %d peer delete %pM (sta gone)\n",
3780 arvif->vdev_id, sta->addr);
3782 if (vif->type == NL80211_IFTYPE_STATION) {
3783 WARN_ON(!arvif->is_started);
3785 ret = ath10k_vdev_stop(arvif);
3787 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3788 arvif->vdev_id, ret);
3790 arvif->is_started = false;
3793 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3795 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3796 sta->addr, arvif->vdev_id, ret);
3798 ath10k_mac_dec_num_stations(arvif);
3799 } else if (old_state == IEEE80211_STA_AUTH &&
3800 new_state == IEEE80211_STA_ASSOC &&
3801 (vif->type == NL80211_IFTYPE_AP ||
3802 vif->type == NL80211_IFTYPE_ADHOC)) {
3806 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3809 ret = ath10k_station_assoc(ar, vif, sta, false);
3811 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3812 sta->addr, arvif->vdev_id, ret);
3813 } else if (old_state == IEEE80211_STA_ASSOC &&
3814 new_state == IEEE80211_STA_AUTH &&
3815 (vif->type == NL80211_IFTYPE_AP ||
3816 vif->type == NL80211_IFTYPE_ADHOC)) {
3820 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3823 ret = ath10k_station_disassoc(ar, vif, sta);
3825 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3826 sta->addr, arvif->vdev_id, ret);
3829 mutex_unlock(&ar->conf_mutex);
3833 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3834 u16 ac, bool enable)
3836 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3840 lockdep_assert_held(&ar->conf_mutex);
3842 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3846 case IEEE80211_AC_VO:
3847 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3848 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3850 case IEEE80211_AC_VI:
3851 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3852 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3854 case IEEE80211_AC_BE:
3855 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3856 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3858 case IEEE80211_AC_BK:
3859 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3860 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3865 arvif->u.sta.uapsd |= value;
3867 arvif->u.sta.uapsd &= ~value;
3869 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3870 WMI_STA_PS_PARAM_UAPSD,
3871 arvif->u.sta.uapsd);
3873 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3877 if (arvif->u.sta.uapsd)
3878 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3880 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3882 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3883 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3886 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3888 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3890 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3891 arvif->vdev_id, ret);
3895 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3897 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3898 arvif->vdev_id, ret);
3906 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3907 struct ieee80211_vif *vif, u16 ac,
3908 const struct ieee80211_tx_queue_params *params)
3910 struct ath10k *ar = hw->priv;
3911 struct wmi_wmm_params_arg *p = NULL;
3914 mutex_lock(&ar->conf_mutex);
3917 case IEEE80211_AC_VO:
3918 p = &ar->wmm_params.ac_vo;
3920 case IEEE80211_AC_VI:
3921 p = &ar->wmm_params.ac_vi;
3923 case IEEE80211_AC_BE:
3924 p = &ar->wmm_params.ac_be;
3926 case IEEE80211_AC_BK:
3927 p = &ar->wmm_params.ac_bk;
3936 p->cwmin = params->cw_min;
3937 p->cwmax = params->cw_max;
3938 p->aifs = params->aifs;
3941 * The channel time duration programmed in the HW is in absolute
3942 * microseconds, while mac80211 gives the txop in units of
3945 p->txop = params->txop * 32;
3947 /* FIXME: FW accepts wmm params per hw, not per vif */
3948 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3950 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3954 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3956 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3959 mutex_unlock(&ar->conf_mutex);
3963 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3965 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3966 struct ieee80211_vif *vif,
3967 struct ieee80211_channel *chan,
3969 enum ieee80211_roc_type type)
3971 struct ath10k *ar = hw->priv;
3972 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3973 struct wmi_start_scan_arg arg;
3976 mutex_lock(&ar->conf_mutex);
3978 spin_lock_bh(&ar->data_lock);
3979 switch (ar->scan.state) {
3980 case ATH10K_SCAN_IDLE:
3981 reinit_completion(&ar->scan.started);
3982 reinit_completion(&ar->scan.completed);
3983 reinit_completion(&ar->scan.on_channel);
3984 ar->scan.state = ATH10K_SCAN_STARTING;
3985 ar->scan.is_roc = true;
3986 ar->scan.vdev_id = arvif->vdev_id;
3987 ar->scan.roc_freq = chan->center_freq;
3990 case ATH10K_SCAN_STARTING:
3991 case ATH10K_SCAN_RUNNING:
3992 case ATH10K_SCAN_ABORTING:
3996 spin_unlock_bh(&ar->data_lock);
4001 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4003 memset(&arg, 0, sizeof(arg));
4004 ath10k_wmi_start_scan_init(ar, &arg);
4005 arg.vdev_id = arvif->vdev_id;
4006 arg.scan_id = ATH10K_SCAN_ID;
4008 arg.channels[0] = chan->center_freq;
4009 arg.dwell_time_active = duration;
4010 arg.dwell_time_passive = duration;
4011 arg.max_scan_time = 2 * duration;
4012 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4013 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4015 ret = ath10k_start_scan(ar, &arg);
4017 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
4018 spin_lock_bh(&ar->data_lock);
4019 ar->scan.state = ATH10K_SCAN_IDLE;
4020 spin_unlock_bh(&ar->data_lock);
4024 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4026 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
4028 ret = ath10k_scan_stop(ar);
4030 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4038 mutex_unlock(&ar->conf_mutex);
4042 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4044 struct ath10k *ar = hw->priv;
4046 mutex_lock(&ar->conf_mutex);
4047 ath10k_scan_abort(ar);
4048 mutex_unlock(&ar->conf_mutex);
4050 cancel_delayed_work_sync(&ar->scan.timeout);
4056 * Both RTS and Fragmentation threshold are interface-specific
4057 * in ath10k, but device-specific in mac80211.
4060 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4062 struct ath10k *ar = hw->priv;
4063 struct ath10k_vif *arvif;
4066 mutex_lock(&ar->conf_mutex);
4067 list_for_each_entry(arvif, &ar->arvifs, list) {
4068 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
4069 arvif->vdev_id, value);
4071 ret = ath10k_mac_set_rts(arvif, value);
4073 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4074 arvif->vdev_id, ret);
4078 mutex_unlock(&ar->conf_mutex);
4083 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4084 u32 queues, bool drop)
4086 struct ath10k *ar = hw->priv;
4090 /* mac80211 doesn't care if we really xmit queued frames or not
4091 * we'll collect those frames either way if we stop/delete vdevs */
4095 mutex_lock(&ar->conf_mutex);
4097 if (ar->state == ATH10K_STATE_WEDGED)
4100 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
4103 spin_lock_bh(&ar->htt.tx_lock);
4104 empty = (ar->htt.num_pending_tx == 0);
4105 spin_unlock_bh(&ar->htt.tx_lock);
4107 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4108 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4112 }), ATH10K_FLUSH_TIMEOUT_HZ);
4114 if (ret <= 0 || skip)
4115 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4116 skip, ar->state, ret);
4119 mutex_unlock(&ar->conf_mutex);
4122 /* TODO: Implement this function properly
4123 * For now it is needed to reply to Probe Requests in IBSS mode.
4124 * Propably we need this information from FW.
4126 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4132 static int ath10k_suspend(struct ieee80211_hw *hw,
4133 struct cfg80211_wowlan *wowlan)
4135 struct ath10k *ar = hw->priv;
4138 mutex_lock(&ar->conf_mutex);
4140 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
4142 if (ret == -ETIMEDOUT)
4148 ret = ath10k_hif_suspend(ar);
4150 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
4157 ret = ath10k_wmi_pdev_resume_target(ar);
4159 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4163 mutex_unlock(&ar->conf_mutex);
4167 static int ath10k_resume(struct ieee80211_hw *hw)
4169 struct ath10k *ar = hw->priv;
4172 mutex_lock(&ar->conf_mutex);
4174 ret = ath10k_hif_resume(ar);
4176 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
4181 ret = ath10k_wmi_pdev_resume_target(ar);
4183 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4190 mutex_unlock(&ar->conf_mutex);
4195 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4196 enum ieee80211_reconfig_type reconfig_type)
4198 struct ath10k *ar = hw->priv;
4200 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4203 mutex_lock(&ar->conf_mutex);
4205 /* If device failed to restart it will be in a different state, e.g.
4206 * ATH10K_STATE_WEDGED */
4207 if (ar->state == ATH10K_STATE_RESTARTED) {
4208 ath10k_info(ar, "device successfully recovered\n");
4209 ar->state = ATH10K_STATE_ON;
4210 ieee80211_wake_queues(ar->hw);
4213 mutex_unlock(&ar->conf_mutex);
4216 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4217 struct survey_info *survey)
4219 struct ath10k *ar = hw->priv;
4220 struct ieee80211_supported_band *sband;
4221 struct survey_info *ar_survey = &ar->survey[idx];
4224 mutex_lock(&ar->conf_mutex);
4226 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4227 if (sband && idx >= sband->n_channels) {
4228 idx -= sband->n_channels;
4233 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4235 if (!sband || idx >= sband->n_channels) {
4240 spin_lock_bh(&ar->data_lock);
4241 memcpy(survey, ar_survey, sizeof(*survey));
4242 spin_unlock_bh(&ar->data_lock);
4244 survey->channel = &sband->channels[idx];
4246 if (ar->rx_channel == survey->channel)
4247 survey->filled |= SURVEY_INFO_IN_USE;
4250 mutex_unlock(&ar->conf_mutex);
4254 /* Helper table for legacy fixed_rate/bitrate_mask */
4255 static const u8 cck_ofdm_rate[] = {
4272 /* Check if only one bit set */
4273 static int ath10k_check_single_mask(u32 mask)
4281 mask &= ~BIT(bit - 1);
4289 ath10k_default_bitrate_mask(struct ath10k *ar,
4290 enum ieee80211_band band,
4291 const struct cfg80211_bitrate_mask *mask)
4293 u32 legacy = 0x00ff;
4296 u16 nrf = ar->num_rf_chains;
4298 if (ar->cfg_tx_chainmask)
4299 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4302 case IEEE80211_BAND_2GHZ:
4306 case IEEE80211_BAND_5GHZ:
4312 if (mask->control[band].legacy != legacy)
4315 for (i = 0; i < nrf; i++)
4316 if (mask->control[band].ht_mcs[i] != ht)
4319 for (i = 0; i < nrf; i++)
4320 if (mask->control[band].vht_mcs[i] != vht)
4327 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4328 enum ieee80211_band band,
4331 int ht_nss = 0, vht_nss = 0, i;
4334 if (ath10k_check_single_mask(mask->control[band].legacy))
4338 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4339 if (mask->control[band].ht_mcs[i] == 0xff)
4341 else if (mask->control[band].ht_mcs[i] == 0x00)
4350 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4351 if (mask->control[band].vht_mcs[i] == 0x03ff)
4353 else if (mask->control[band].vht_mcs[i] == 0x0000)
4361 if (ht_nss > 0 && vht_nss > 0)
4365 *fixed_nss = ht_nss;
4367 *fixed_nss = vht_nss;
4375 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4376 enum ieee80211_band band,
4377 enum wmi_rate_preamble *preamble)
4379 int legacy = 0, ht = 0, vht = 0, i;
4381 *preamble = WMI_RATE_PREAMBLE_OFDM;
4384 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4389 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4390 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4395 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4396 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4400 /* Currently we support only one fixed_rate */
4401 if ((legacy + ht + vht) != 1)
4405 *preamble = WMI_RATE_PREAMBLE_HT;
4407 *preamble = WMI_RATE_PREAMBLE_VHT;
4413 ath10k_bitrate_mask_rate(struct ath10k *ar,
4414 const struct cfg80211_bitrate_mask *mask,
4415 enum ieee80211_band band,
4419 u8 rate = 0, pream = 0, nss = 0, i;
4420 enum wmi_rate_preamble preamble;
4422 /* Check if single rate correct */
4423 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4429 case WMI_RATE_PREAMBLE_CCK:
4430 case WMI_RATE_PREAMBLE_OFDM:
4431 i = ffs(mask->control[band].legacy) - 1;
4433 if (band == IEEE80211_BAND_2GHZ && i < 4)
4434 pream = WMI_RATE_PREAMBLE_CCK;
4436 if (band == IEEE80211_BAND_5GHZ)
4439 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4442 rate = cck_ofdm_rate[i];
4444 case WMI_RATE_PREAMBLE_HT:
4445 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4446 if (mask->control[band].ht_mcs[i])
4449 if (i == IEEE80211_HT_MCS_MASK_LEN)
4452 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4455 case WMI_RATE_PREAMBLE_VHT:
4456 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4457 if (mask->control[band].vht_mcs[i])
4460 if (i == NL80211_VHT_NSS_MAX)
4463 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4468 *fixed_nss = nss + 1;
4472 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4475 *fixed_rate = pream | nss | rate;
4480 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4481 const struct cfg80211_bitrate_mask *mask,
4482 enum ieee80211_band band,
4486 /* First check full NSS mask, if we can simply limit NSS */
4487 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4490 /* Next Check single rate is set */
4491 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4494 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4499 struct ath10k *ar = arvif->ar;
4503 mutex_lock(&ar->conf_mutex);
4505 if (arvif->fixed_rate == fixed_rate &&
4506 arvif->fixed_nss == fixed_nss &&
4507 arvif->force_sgi == force_sgi)
4510 if (fixed_rate == WMI_FIXED_RATE_NONE)
4511 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4514 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4516 vdev_param = ar->wmi.vdev_param->fixed_rate;
4517 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4518 vdev_param, fixed_rate);
4520 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4526 arvif->fixed_rate = fixed_rate;
4528 vdev_param = ar->wmi.vdev_param->nss;
4529 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4530 vdev_param, fixed_nss);
4533 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4539 arvif->fixed_nss = fixed_nss;
4541 vdev_param = ar->wmi.vdev_param->sgi;
4542 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4546 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4552 arvif->force_sgi = force_sgi;
4555 mutex_unlock(&ar->conf_mutex);
4559 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4560 struct ieee80211_vif *vif,
4561 const struct cfg80211_bitrate_mask *mask)
4563 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4564 struct ath10k *ar = arvif->ar;
4565 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4566 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4567 u8 fixed_nss = ar->num_rf_chains;
4570 if (ar->cfg_tx_chainmask)
4571 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4573 force_sgi = mask->control[band].gi;
4574 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4577 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4578 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4584 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4585 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4589 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4590 fixed_nss, force_sgi);
4593 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4594 struct ieee80211_vif *vif,
4595 struct ieee80211_sta *sta,
4598 struct ath10k *ar = hw->priv;
4599 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4602 spin_lock_bh(&ar->data_lock);
4604 ath10k_dbg(ar, ATH10K_DBG_MAC,
4605 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4606 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4609 if (changed & IEEE80211_RC_BW_CHANGED) {
4610 bw = WMI_PEER_CHWIDTH_20MHZ;
4612 switch (sta->bandwidth) {
4613 case IEEE80211_STA_RX_BW_20:
4614 bw = WMI_PEER_CHWIDTH_20MHZ;
4616 case IEEE80211_STA_RX_BW_40:
4617 bw = WMI_PEER_CHWIDTH_40MHZ;
4619 case IEEE80211_STA_RX_BW_80:
4620 bw = WMI_PEER_CHWIDTH_80MHZ;
4622 case IEEE80211_STA_RX_BW_160:
4623 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4624 sta->bandwidth, sta->addr);
4625 bw = WMI_PEER_CHWIDTH_20MHZ;
4632 if (changed & IEEE80211_RC_NSS_CHANGED)
4633 arsta->nss = sta->rx_nss;
4635 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4636 smps = WMI_PEER_SMPS_PS_NONE;
4638 switch (sta->smps_mode) {
4639 case IEEE80211_SMPS_AUTOMATIC:
4640 case IEEE80211_SMPS_OFF:
4641 smps = WMI_PEER_SMPS_PS_NONE;
4643 case IEEE80211_SMPS_STATIC:
4644 smps = WMI_PEER_SMPS_STATIC;
4646 case IEEE80211_SMPS_DYNAMIC:
4647 smps = WMI_PEER_SMPS_DYNAMIC;
4649 case IEEE80211_SMPS_NUM_MODES:
4650 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4651 sta->smps_mode, sta->addr);
4652 smps = WMI_PEER_SMPS_PS_NONE;
4659 arsta->changed |= changed;
4661 spin_unlock_bh(&ar->data_lock);
4663 ieee80211_queue_work(hw, &arsta->update_wk);
4666 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4669 * FIXME: Return 0 for time being. Need to figure out whether FW
4670 * has the API to fetch 64-bit local TSF
4676 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4677 struct ieee80211_vif *vif,
4678 enum ieee80211_ampdu_mlme_action action,
4679 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4682 struct ath10k *ar = hw->priv;
4683 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4685 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4686 arvif->vdev_id, sta->addr, tid, action);
4689 case IEEE80211_AMPDU_RX_START:
4690 case IEEE80211_AMPDU_RX_STOP:
4691 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4692 * creation/removal. Do we need to verify this?
4695 case IEEE80211_AMPDU_TX_START:
4696 case IEEE80211_AMPDU_TX_STOP_CONT:
4697 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4698 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4699 case IEEE80211_AMPDU_TX_OPERATIONAL:
4700 /* Firmware offloads Tx aggregation entirely so deny mac80211
4701 * Tx aggregation requests.
4709 static const struct ieee80211_ops ath10k_ops = {
4711 .start = ath10k_start,
4712 .stop = ath10k_stop,
4713 .config = ath10k_config,
4714 .add_interface = ath10k_add_interface,
4715 .remove_interface = ath10k_remove_interface,
4716 .configure_filter = ath10k_configure_filter,
4717 .bss_info_changed = ath10k_bss_info_changed,
4718 .hw_scan = ath10k_hw_scan,
4719 .cancel_hw_scan = ath10k_cancel_hw_scan,
4720 .set_key = ath10k_set_key,
4721 .sta_state = ath10k_sta_state,
4722 .conf_tx = ath10k_conf_tx,
4723 .remain_on_channel = ath10k_remain_on_channel,
4724 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4725 .set_rts_threshold = ath10k_set_rts_threshold,
4726 .flush = ath10k_flush,
4727 .tx_last_beacon = ath10k_tx_last_beacon,
4728 .set_antenna = ath10k_set_antenna,
4729 .get_antenna = ath10k_get_antenna,
4730 .reconfig_complete = ath10k_reconfig_complete,
4731 .get_survey = ath10k_get_survey,
4732 .set_bitrate_mask = ath10k_set_bitrate_mask,
4733 .sta_rc_update = ath10k_sta_rc_update,
4734 .get_tsf = ath10k_get_tsf,
4735 .ampdu_action = ath10k_ampdu_action,
4736 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4737 .get_et_stats = ath10k_debug_get_et_stats,
4738 .get_et_strings = ath10k_debug_get_et_strings,
4740 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4743 .suspend = ath10k_suspend,
4744 .resume = ath10k_resume,
4748 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4749 .bitrate = (_rate), \
4750 .flags = (_flags), \
4751 .hw_value = (_rateid), \
4754 #define CHAN2G(_channel, _freq, _flags) { \
4755 .band = IEEE80211_BAND_2GHZ, \
4756 .hw_value = (_channel), \
4757 .center_freq = (_freq), \
4758 .flags = (_flags), \
4759 .max_antenna_gain = 0, \
4763 #define CHAN5G(_channel, _freq, _flags) { \
4764 .band = IEEE80211_BAND_5GHZ, \
4765 .hw_value = (_channel), \
4766 .center_freq = (_freq), \
4767 .flags = (_flags), \
4768 .max_antenna_gain = 0, \
4772 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4782 CHAN2G(10, 2457, 0),
4783 CHAN2G(11, 2462, 0),
4784 CHAN2G(12, 2467, 0),
4785 CHAN2G(13, 2472, 0),
4786 CHAN2G(14, 2484, 0),
4789 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4790 CHAN5G(36, 5180, 0),
4791 CHAN5G(40, 5200, 0),
4792 CHAN5G(44, 5220, 0),
4793 CHAN5G(48, 5240, 0),
4794 CHAN5G(52, 5260, 0),
4795 CHAN5G(56, 5280, 0),
4796 CHAN5G(60, 5300, 0),
4797 CHAN5G(64, 5320, 0),
4798 CHAN5G(100, 5500, 0),
4799 CHAN5G(104, 5520, 0),
4800 CHAN5G(108, 5540, 0),
4801 CHAN5G(112, 5560, 0),
4802 CHAN5G(116, 5580, 0),
4803 CHAN5G(120, 5600, 0),
4804 CHAN5G(124, 5620, 0),
4805 CHAN5G(128, 5640, 0),
4806 CHAN5G(132, 5660, 0),
4807 CHAN5G(136, 5680, 0),
4808 CHAN5G(140, 5700, 0),
4809 CHAN5G(149, 5745, 0),
4810 CHAN5G(153, 5765, 0),
4811 CHAN5G(157, 5785, 0),
4812 CHAN5G(161, 5805, 0),
4813 CHAN5G(165, 5825, 0),
4816 /* Note: Be careful if you re-order these. There is code which depends on this
4819 static struct ieee80211_rate ath10k_rates[] = {
4821 RATETAB_ENT(10, 0x82, 0),
4822 RATETAB_ENT(20, 0x84, 0),
4823 RATETAB_ENT(55, 0x8b, 0),
4824 RATETAB_ENT(110, 0x96, 0),
4826 RATETAB_ENT(60, 0x0c, 0),
4827 RATETAB_ENT(90, 0x12, 0),
4828 RATETAB_ENT(120, 0x18, 0),
4829 RATETAB_ENT(180, 0x24, 0),
4830 RATETAB_ENT(240, 0x30, 0),
4831 RATETAB_ENT(360, 0x48, 0),
4832 RATETAB_ENT(480, 0x60, 0),
4833 RATETAB_ENT(540, 0x6c, 0),
4836 #define ath10k_a_rates (ath10k_rates + 4)
4837 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4838 #define ath10k_g_rates (ath10k_rates + 0)
4839 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4841 struct ath10k *ath10k_mac_create(size_t priv_size)
4843 struct ieee80211_hw *hw;
4846 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4856 void ath10k_mac_destroy(struct ath10k *ar)
4858 ieee80211_free_hw(ar->hw);
4861 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4864 .types = BIT(NL80211_IFTYPE_STATION)
4865 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4869 .types = BIT(NL80211_IFTYPE_P2P_GO)
4873 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
4877 .types = BIT(NL80211_IFTYPE_AP)
4881 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4884 .types = BIT(NL80211_IFTYPE_AP)
4888 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4890 .limits = ath10k_if_limits,
4891 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4892 .max_interfaces = 8,
4893 .num_different_channels = 1,
4894 .beacon_int_infra_match = true,
4898 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4900 .limits = ath10k_10x_if_limits,
4901 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4902 .max_interfaces = 8,
4903 .num_different_channels = 1,
4904 .beacon_int_infra_match = true,
4905 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4906 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4907 BIT(NL80211_CHAN_WIDTH_20) |
4908 BIT(NL80211_CHAN_WIDTH_40) |
4909 BIT(NL80211_CHAN_WIDTH_80),
4914 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4916 struct ieee80211_sta_vht_cap vht_cap = {0};
4920 vht_cap.vht_supported = 1;
4921 vht_cap.cap = ar->vht_cap_info;
4924 for (i = 0; i < 8; i++) {
4925 if (i < ar->num_rf_chains)
4926 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4928 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4931 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4932 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4937 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4940 struct ieee80211_sta_ht_cap ht_cap = {0};
4942 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4945 ht_cap.ht_supported = 1;
4946 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4947 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4948 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4949 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4950 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4952 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4953 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4955 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4956 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4958 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4961 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4962 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4967 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4968 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4970 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4973 stbc = ar->ht_cap_info;
4974 stbc &= WMI_HT_CAP_RX_STBC;
4975 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4976 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4977 stbc &= IEEE80211_HT_CAP_RX_STBC;
4982 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4983 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4985 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4986 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4988 /* max AMSDU is implicitly taken from vht_cap_info */
4989 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4990 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4992 for (i = 0; i < ar->num_rf_chains; i++)
4993 ht_cap.mcs.rx_mask[i] = 0xFF;
4995 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5000 static void ath10k_get_arvif_iter(void *data, u8 *mac,
5001 struct ieee80211_vif *vif)
5003 struct ath10k_vif_iter *arvif_iter = data;
5004 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5006 if (arvif->vdev_id == arvif_iter->vdev_id)
5007 arvif_iter->arvif = arvif;
5010 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5012 struct ath10k_vif_iter arvif_iter;
5015 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5016 arvif_iter.vdev_id = vdev_id;
5018 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5019 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5021 ath10k_get_arvif_iter,
5023 if (!arvif_iter.arvif) {
5024 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
5028 return arvif_iter.arvif;
5031 int ath10k_mac_register(struct ath10k *ar)
5033 struct ieee80211_supported_band *band;
5034 struct ieee80211_sta_vht_cap vht_cap;
5035 struct ieee80211_sta_ht_cap ht_cap;
5039 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5041 SET_IEEE80211_DEV(ar->hw, ar->dev);
5043 ht_cap = ath10k_get_ht_cap(ar);
5044 vht_cap = ath10k_create_vht_cap(ar);
5046 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5047 channels = kmemdup(ath10k_2ghz_channels,
5048 sizeof(ath10k_2ghz_channels),
5055 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5056 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5057 band->channels = channels;
5058 band->n_bitrates = ath10k_g_rates_size;
5059 band->bitrates = ath10k_g_rates;
5060 band->ht_cap = ht_cap;
5062 /* vht is not supported in 2.4 GHz */
5064 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5067 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5068 channels = kmemdup(ath10k_5ghz_channels,
5069 sizeof(ath10k_5ghz_channels),
5076 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5077 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5078 band->channels = channels;
5079 band->n_bitrates = ath10k_a_rates_size;
5080 band->bitrates = ath10k_a_rates;
5081 band->ht_cap = ht_cap;
5082 band->vht_cap = vht_cap;
5083 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5086 ar->hw->wiphy->interface_modes =
5087 BIT(NL80211_IFTYPE_STATION) |
5088 BIT(NL80211_IFTYPE_AP);
5090 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5091 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5093 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5094 ar->hw->wiphy->interface_modes |=
5095 BIT(NL80211_IFTYPE_P2P_DEVICE) |
5096 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5097 BIT(NL80211_IFTYPE_P2P_GO);
5099 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5100 IEEE80211_HW_SUPPORTS_PS |
5101 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5102 IEEE80211_HW_SUPPORTS_UAPSD |
5103 IEEE80211_HW_MFP_CAPABLE |
5104 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5105 IEEE80211_HW_HAS_RATE_CONTROL |
5106 IEEE80211_HW_AP_LINK_PS |
5107 IEEE80211_HW_SPECTRUM_MGMT;
5109 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5111 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5112 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
5114 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5115 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5116 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5119 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5120 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5122 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
5123 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5125 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5127 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
5128 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5129 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5131 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5132 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5135 * on LL hardware queues are managed entirely by the FW
5136 * so we only advertise to mac we can do the queues thing
5140 switch (ar->wmi.op_version) {
5141 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5142 case ATH10K_FW_WMI_OP_VERSION_TLV:
5143 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5144 ar->hw->wiphy->n_iface_combinations =
5145 ARRAY_SIZE(ath10k_if_comb);
5146 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
5148 case ATH10K_FW_WMI_OP_VERSION_10_1:
5149 case ATH10K_FW_WMI_OP_VERSION_10_2:
5150 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
5151 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5152 ar->hw->wiphy->n_iface_combinations =
5153 ARRAY_SIZE(ath10k_10x_if_comb);
5155 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5156 case ATH10K_FW_WMI_OP_VERSION_MAX:
5162 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5164 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5165 /* Init ath dfs pattern detector */
5166 ar->ath_common.debug_mask = ATH_DBG_DFS;
5167 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5170 if (!ar->dfs_detector)
5171 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
5174 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5175 ath10k_reg_notifier);
5177 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
5181 ret = ieee80211_register_hw(ar->hw);
5183 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
5187 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5188 ret = regulatory_hint(ar->hw->wiphy,
5189 ar->ath_common.regulatory.alpha2);
5191 goto err_unregister;
5197 ieee80211_unregister_hw(ar->hw);
5199 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5200 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5205 void ath10k_mac_unregister(struct ath10k *ar)
5207 ieee80211_unregister_hw(ar->hw);
5209 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5210 ar->dfs_detector->exit(ar->dfs_detector);
5212 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5213 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5215 SET_IEEE80211_DEV(ar->hw, NULL);