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;
79 case WLAN_CIPHER_SUITE_AES_CMAC:
80 /* this one needs to be done in software */
83 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
87 if (cmd == DISABLE_KEY) {
88 arg.key_cipher = WMI_CIPHER_NONE;
92 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
95 static int ath10k_install_key(struct ath10k_vif *arvif,
96 struct ieee80211_key_conf *key,
100 struct ath10k *ar = arvif->ar;
103 lockdep_assert_held(&ar->conf_mutex);
105 reinit_completion(&ar->install_key_done);
107 ret = ath10k_send_key(arvif, key, cmd, macaddr);
111 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
118 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
121 struct ath10k *ar = arvif->ar;
122 struct ath10k_peer *peer;
126 lockdep_assert_held(&ar->conf_mutex);
128 spin_lock_bh(&ar->data_lock);
129 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
130 spin_unlock_bh(&ar->data_lock);
135 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
136 if (arvif->wep_keys[i] == NULL)
139 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
144 spin_lock_bh(&ar->data_lock);
145 peer->keys[i] = arvif->wep_keys[i];
146 spin_unlock_bh(&ar->data_lock);
152 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
155 struct ath10k *ar = arvif->ar;
156 struct ath10k_peer *peer;
161 lockdep_assert_held(&ar->conf_mutex);
163 spin_lock_bh(&ar->data_lock);
164 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
165 spin_unlock_bh(&ar->data_lock);
170 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
171 if (peer->keys[i] == NULL)
174 ret = ath10k_install_key(arvif, peer->keys[i],
176 if (ret && first_errno == 0)
180 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
183 spin_lock_bh(&ar->data_lock);
184 peer->keys[i] = NULL;
185 spin_unlock_bh(&ar->data_lock);
191 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
194 struct ath10k_peer *peer;
197 lockdep_assert_held(&ar->data_lock);
199 /* We don't know which vdev this peer belongs to,
200 * since WMI doesn't give us that information.
202 * FIXME: multi-bss needs to be handled.
204 peer = ath10k_peer_find(ar, 0, addr);
208 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
209 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
216 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
217 struct ieee80211_key_conf *key)
219 struct ath10k *ar = arvif->ar;
220 struct ath10k_peer *peer;
226 lockdep_assert_held(&ar->conf_mutex);
229 /* since ath10k_install_key we can't hold data_lock all the
230 * time, so we try to remove the keys incrementally */
231 spin_lock_bh(&ar->data_lock);
233 list_for_each_entry(peer, &ar->peers, list) {
234 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
235 if (peer->keys[i] == key) {
236 ether_addr_copy(addr, peer->addr);
237 peer->keys[i] = NULL;
242 if (i < ARRAY_SIZE(peer->keys))
245 spin_unlock_bh(&ar->data_lock);
247 if (i == ARRAY_SIZE(peer->keys))
250 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
251 if (ret && first_errno == 0)
255 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
262 /*********************/
263 /* General utilities */
264 /*********************/
266 static inline enum wmi_phy_mode
267 chan_to_phymode(const struct cfg80211_chan_def *chandef)
269 enum wmi_phy_mode phymode = MODE_UNKNOWN;
271 switch (chandef->chan->band) {
272 case IEEE80211_BAND_2GHZ:
273 switch (chandef->width) {
274 case NL80211_CHAN_WIDTH_20_NOHT:
275 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
280 case NL80211_CHAN_WIDTH_20:
281 phymode = MODE_11NG_HT20;
283 case NL80211_CHAN_WIDTH_40:
284 phymode = MODE_11NG_HT40;
286 case NL80211_CHAN_WIDTH_5:
287 case NL80211_CHAN_WIDTH_10:
288 case NL80211_CHAN_WIDTH_80:
289 case NL80211_CHAN_WIDTH_80P80:
290 case NL80211_CHAN_WIDTH_160:
291 phymode = MODE_UNKNOWN;
295 case IEEE80211_BAND_5GHZ:
296 switch (chandef->width) {
297 case NL80211_CHAN_WIDTH_20_NOHT:
300 case NL80211_CHAN_WIDTH_20:
301 phymode = MODE_11NA_HT20;
303 case NL80211_CHAN_WIDTH_40:
304 phymode = MODE_11NA_HT40;
306 case NL80211_CHAN_WIDTH_80:
307 phymode = MODE_11AC_VHT80;
309 case NL80211_CHAN_WIDTH_5:
310 case NL80211_CHAN_WIDTH_10:
311 case NL80211_CHAN_WIDTH_80P80:
312 case NL80211_CHAN_WIDTH_160:
313 phymode = MODE_UNKNOWN;
321 WARN_ON(phymode == MODE_UNKNOWN);
325 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
328 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
329 * 0 for no restriction
338 switch (mpdudensity) {
344 /* Our lower layer calculations limit our precision to
360 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
364 lockdep_assert_held(&ar->conf_mutex);
366 if (ar->num_peers >= ar->max_num_peers)
369 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
371 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
376 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
378 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
388 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
390 struct ath10k *ar = arvif->ar;
394 param = ar->wmi.pdev_param->sta_kickout_th;
395 ret = ath10k_wmi_pdev_set_param(ar, param,
396 ATH10K_KICKOUT_THRESHOLD);
398 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
399 arvif->vdev_id, ret);
403 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
404 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
405 ATH10K_KEEPALIVE_MIN_IDLE);
407 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
408 arvif->vdev_id, ret);
412 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
413 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
414 ATH10K_KEEPALIVE_MAX_IDLE);
416 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
417 arvif->vdev_id, ret);
421 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
422 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
423 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
425 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
426 arvif->vdev_id, ret);
433 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
435 struct ath10k *ar = arvif->ar;
438 vdev_param = ar->wmi.vdev_param->rts_threshold;
439 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
442 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
444 struct ath10k *ar = arvif->ar;
447 if (value != 0xFFFFFFFF)
448 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
449 ATH10K_FRAGMT_THRESHOLD_MIN,
450 ATH10K_FRAGMT_THRESHOLD_MAX);
452 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
453 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
456 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
460 lockdep_assert_held(&ar->conf_mutex);
462 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
466 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
475 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
477 struct ath10k_peer *peer, *tmp;
479 lockdep_assert_held(&ar->conf_mutex);
481 spin_lock_bh(&ar->data_lock);
482 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
483 if (peer->vdev_id != vdev_id)
486 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
487 peer->addr, vdev_id);
489 list_del(&peer->list);
493 spin_unlock_bh(&ar->data_lock);
496 static void ath10k_peer_cleanup_all(struct ath10k *ar)
498 struct ath10k_peer *peer, *tmp;
500 lockdep_assert_held(&ar->conf_mutex);
502 spin_lock_bh(&ar->data_lock);
503 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
504 list_del(&peer->list);
507 spin_unlock_bh(&ar->data_lock);
510 ar->num_stations = 0;
513 /************************/
514 /* Interface management */
515 /************************/
517 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
519 struct ath10k *ar = arvif->ar;
521 lockdep_assert_held(&ar->data_lock);
526 if (!arvif->beacon_buf)
527 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
528 arvif->beacon->len, DMA_TO_DEVICE);
530 dev_kfree_skb_any(arvif->beacon);
532 arvif->beacon = NULL;
533 arvif->beacon_sent = false;
536 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
538 struct ath10k *ar = arvif->ar;
540 lockdep_assert_held(&ar->data_lock);
542 ath10k_mac_vif_beacon_free(arvif);
544 if (arvif->beacon_buf) {
545 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
546 arvif->beacon_buf, arvif->beacon_paddr);
547 arvif->beacon_buf = NULL;
551 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
555 lockdep_assert_held(&ar->conf_mutex);
557 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
560 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
561 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
568 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
570 struct cfg80211_chan_def *chandef = &ar->chandef;
571 struct ieee80211_channel *channel = chandef->chan;
572 struct wmi_vdev_start_request_arg arg = {};
575 lockdep_assert_held(&ar->conf_mutex);
577 arg.vdev_id = vdev_id;
578 arg.channel.freq = channel->center_freq;
579 arg.channel.band_center_freq1 = chandef->center_freq1;
581 /* TODO setup this dynamically, what in case we
582 don't have any vifs? */
583 arg.channel.mode = chan_to_phymode(chandef);
584 arg.channel.chan_radar =
585 !!(channel->flags & IEEE80211_CHAN_RADAR);
587 arg.channel.min_power = 0;
588 arg.channel.max_power = channel->max_power * 2;
589 arg.channel.max_reg_power = channel->max_reg_power * 2;
590 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
592 reinit_completion(&ar->vdev_setup_done);
594 ret = ath10k_wmi_vdev_start(ar, &arg);
596 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
601 ret = ath10k_vdev_setup_sync(ar);
603 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
608 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
610 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
615 ar->monitor_vdev_id = vdev_id;
617 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
618 ar->monitor_vdev_id);
622 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
624 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
625 ar->monitor_vdev_id, ret);
630 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
634 lockdep_assert_held(&ar->conf_mutex);
636 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
638 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
639 ar->monitor_vdev_id, ret);
641 reinit_completion(&ar->vdev_setup_done);
643 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
645 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
646 ar->monitor_vdev_id, ret);
648 ret = ath10k_vdev_setup_sync(ar);
650 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
651 ar->monitor_vdev_id, ret);
653 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
654 ar->monitor_vdev_id);
658 static int ath10k_monitor_vdev_create(struct ath10k *ar)
662 lockdep_assert_held(&ar->conf_mutex);
664 if (ar->free_vdev_map == 0) {
665 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
669 bit = __ffs64(ar->free_vdev_map);
671 ar->monitor_vdev_id = bit;
673 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
674 WMI_VDEV_TYPE_MONITOR,
677 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
678 ar->monitor_vdev_id, ret);
682 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
683 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
684 ar->monitor_vdev_id);
689 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
693 lockdep_assert_held(&ar->conf_mutex);
695 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
697 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
698 ar->monitor_vdev_id, ret);
702 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
704 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
705 ar->monitor_vdev_id);
709 static int ath10k_monitor_start(struct ath10k *ar)
713 lockdep_assert_held(&ar->conf_mutex);
715 ret = ath10k_monitor_vdev_create(ar);
717 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
721 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
723 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
724 ath10k_monitor_vdev_delete(ar);
728 ar->monitor_started = true;
729 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
734 static int ath10k_monitor_stop(struct ath10k *ar)
738 lockdep_assert_held(&ar->conf_mutex);
740 ret = ath10k_monitor_vdev_stop(ar);
742 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
746 ret = ath10k_monitor_vdev_delete(ar);
748 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
752 ar->monitor_started = false;
753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
758 static int ath10k_monitor_recalc(struct ath10k *ar)
762 lockdep_assert_held(&ar->conf_mutex);
764 should_start = ar->monitor ||
765 ar->filter_flags & FIF_PROMISC_IN_BSS ||
766 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
768 ath10k_dbg(ar, ATH10K_DBG_MAC,
769 "mac monitor recalc started? %d should? %d\n",
770 ar->monitor_started, should_start);
772 if (should_start == ar->monitor_started)
776 return ath10k_monitor_start(ar);
778 return ath10k_monitor_stop(ar);
781 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
783 struct ath10k *ar = arvif->ar;
784 u32 vdev_param, rts_cts = 0;
786 lockdep_assert_held(&ar->conf_mutex);
788 vdev_param = ar->wmi.vdev_param->enable_rtscts;
790 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
791 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
793 if (arvif->num_legacy_stations > 0)
794 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
797 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
801 static int ath10k_start_cac(struct ath10k *ar)
805 lockdep_assert_held(&ar->conf_mutex);
807 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
809 ret = ath10k_monitor_recalc(ar);
811 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
812 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
816 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
817 ar->monitor_vdev_id);
822 static int ath10k_stop_cac(struct ath10k *ar)
824 lockdep_assert_held(&ar->conf_mutex);
826 /* CAC is not running - do nothing */
827 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
830 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
831 ath10k_monitor_stop(ar);
833 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
838 static void ath10k_recalc_radar_detection(struct ath10k *ar)
842 lockdep_assert_held(&ar->conf_mutex);
846 if (!ar->radar_enabled)
849 if (ar->num_started_vdevs > 0)
852 ret = ath10k_start_cac(ar);
855 * Not possible to start CAC on current channel so starting
856 * radiation is not allowed, make this channel DFS_UNAVAILABLE
857 * by indicating that radar was detected.
859 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
860 ieee80211_radar_detected(ar->hw);
864 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
866 struct ath10k *ar = arvif->ar;
867 struct cfg80211_chan_def *chandef = &ar->chandef;
868 struct wmi_vdev_start_request_arg arg = {};
871 lockdep_assert_held(&ar->conf_mutex);
873 reinit_completion(&ar->vdev_setup_done);
875 arg.vdev_id = arvif->vdev_id;
876 arg.dtim_period = arvif->dtim_period;
877 arg.bcn_intval = arvif->beacon_interval;
879 arg.channel.freq = chandef->chan->center_freq;
880 arg.channel.band_center_freq1 = chandef->center_freq1;
881 arg.channel.mode = chan_to_phymode(chandef);
883 arg.channel.min_power = 0;
884 arg.channel.max_power = chandef->chan->max_power * 2;
885 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
886 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
888 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
889 arg.ssid = arvif->u.ap.ssid;
890 arg.ssid_len = arvif->u.ap.ssid_len;
891 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
893 /* For now allow DFS for AP mode */
894 arg.channel.chan_radar =
895 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
896 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
897 arg.ssid = arvif->vif->bss_conf.ssid;
898 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
901 ath10k_dbg(ar, ATH10K_DBG_MAC,
902 "mac vdev %d start center_freq %d phymode %s\n",
903 arg.vdev_id, arg.channel.freq,
904 ath10k_wmi_phymode_str(arg.channel.mode));
907 ret = ath10k_wmi_vdev_restart(ar, &arg);
909 ret = ath10k_wmi_vdev_start(ar, &arg);
912 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
917 ret = ath10k_vdev_setup_sync(ar);
919 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
924 ar->num_started_vdevs++;
925 ath10k_recalc_radar_detection(ar);
930 static int ath10k_vdev_start(struct ath10k_vif *arvif)
932 return ath10k_vdev_start_restart(arvif, false);
935 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
937 return ath10k_vdev_start_restart(arvif, true);
940 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
942 struct ath10k *ar = arvif->ar;
945 lockdep_assert_held(&ar->conf_mutex);
947 reinit_completion(&ar->vdev_setup_done);
949 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
951 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
952 arvif->vdev_id, ret);
956 ret = ath10k_vdev_setup_sync(ar);
958 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
959 arvif->vdev_id, ret);
963 WARN_ON(ar->num_started_vdevs == 0);
965 if (ar->num_started_vdevs != 0) {
966 ar->num_started_vdevs--;
967 ath10k_recalc_radar_detection(ar);
973 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
974 struct ieee80211_bss_conf *info)
976 struct ath10k *ar = arvif->ar;
979 lockdep_assert_held(&arvif->ar->conf_mutex);
981 if (!info->enable_beacon) {
982 ath10k_vdev_stop(arvif);
984 arvif->is_started = false;
985 arvif->is_up = false;
987 spin_lock_bh(&arvif->ar->data_lock);
988 ath10k_mac_vif_beacon_free(arvif);
989 spin_unlock_bh(&arvif->ar->data_lock);
994 arvif->tx_seq_no = 0x1000;
996 ret = ath10k_vdev_start(arvif);
1001 ether_addr_copy(arvif->bssid, info->bssid);
1003 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1006 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1007 arvif->vdev_id, ret);
1008 ath10k_vdev_stop(arvif);
1012 arvif->is_started = true;
1013 arvif->is_up = true;
1015 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1018 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1019 struct ieee80211_bss_conf *info,
1020 const u8 self_peer[ETH_ALEN])
1022 struct ath10k *ar = arvif->ar;
1026 lockdep_assert_held(&arvif->ar->conf_mutex);
1028 if (!info->ibss_joined) {
1029 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1031 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1032 self_peer, arvif->vdev_id, ret);
1034 if (is_zero_ether_addr(arvif->bssid))
1037 memset(arvif->bssid, 0, ETH_ALEN);
1042 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1044 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1045 self_peer, arvif->vdev_id, ret);
1049 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1050 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1051 ATH10K_DEFAULT_ATIM);
1053 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1054 arvif->vdev_id, ret);
1057 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1059 struct ath10k *ar = arvif->ar;
1064 lockdep_assert_held(&arvif->ar->conf_mutex);
1066 if (arvif->u.sta.uapsd)
1067 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1069 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1071 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1072 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1074 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1075 value, arvif->vdev_id, ret);
1082 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1084 struct ath10k *ar = arvif->ar;
1089 lockdep_assert_held(&arvif->ar->conf_mutex);
1091 if (arvif->u.sta.uapsd)
1092 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1094 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1096 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1097 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1100 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1101 value, arvif->vdev_id, ret);
1108 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1110 struct ath10k *ar = arvif->ar;
1111 struct ieee80211_vif *vif = arvif->vif;
1112 struct ieee80211_conf *conf = &ar->hw->conf;
1113 enum wmi_sta_powersave_param param;
1114 enum wmi_sta_ps_mode psmode;
1118 lockdep_assert_held(&arvif->ar->conf_mutex);
1120 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1123 if (vif->bss_conf.ps) {
1124 psmode = WMI_STA_PS_MODE_ENABLED;
1125 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1127 ps_timeout = conf->dynamic_ps_timeout;
1128 if (ps_timeout == 0) {
1129 /* Firmware doesn't like 0 */
1130 ps_timeout = ieee80211_tu_to_usec(
1131 vif->bss_conf.beacon_int) / 1000;
1134 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1137 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1138 arvif->vdev_id, ret);
1142 psmode = WMI_STA_PS_MODE_DISABLED;
1145 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1146 arvif->vdev_id, psmode ? "enable" : "disable");
1148 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1150 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1151 psmode, arvif->vdev_id, ret);
1158 /**********************/
1159 /* Station management */
1160 /**********************/
1162 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1163 struct ieee80211_vif *vif)
1165 /* Some firmware revisions have unstable STA powersave when listen
1166 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1167 * generate NullFunc frames properly even if buffered frames have been
1168 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1169 * buffered frames. Often pinging the device from AP would simply fail.
1171 * As a workaround set it to 1.
1173 if (vif->type == NL80211_IFTYPE_STATION)
1176 return ar->hw->conf.listen_interval;
1179 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1180 struct ieee80211_vif *vif,
1181 struct ieee80211_sta *sta,
1182 struct wmi_peer_assoc_complete_arg *arg)
1184 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1186 lockdep_assert_held(&ar->conf_mutex);
1188 ether_addr_copy(arg->addr, sta->addr);
1189 arg->vdev_id = arvif->vdev_id;
1190 arg->peer_aid = sta->aid;
1191 arg->peer_flags |= WMI_PEER_AUTH;
1192 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1193 arg->peer_num_spatial_streams = 1;
1194 arg->peer_caps = vif->bss_conf.assoc_capability;
1197 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1198 struct ieee80211_vif *vif,
1199 struct wmi_peer_assoc_complete_arg *arg)
1201 struct ieee80211_bss_conf *info = &vif->bss_conf;
1202 struct cfg80211_bss *bss;
1203 const u8 *rsnie = NULL;
1204 const u8 *wpaie = NULL;
1206 lockdep_assert_held(&ar->conf_mutex);
1208 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1209 info->bssid, NULL, 0, 0, 0);
1211 const struct cfg80211_bss_ies *ies;
1214 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1216 ies = rcu_dereference(bss->ies);
1218 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1219 WLAN_OUI_TYPE_MICROSOFT_WPA,
1223 cfg80211_put_bss(ar->hw->wiphy, bss);
1226 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1227 if (rsnie || wpaie) {
1228 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1229 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1233 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1234 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1238 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1239 struct ieee80211_sta *sta,
1240 struct wmi_peer_assoc_complete_arg *arg)
1242 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1243 const struct ieee80211_supported_band *sband;
1244 const struct ieee80211_rate *rates;
1248 lockdep_assert_held(&ar->conf_mutex);
1250 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1251 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1252 rates = sband->bitrates;
1254 rateset->num_rates = 0;
1256 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1257 if (!(ratemask & 1))
1260 rateset->rates[rateset->num_rates] = rates->hw_value;
1261 rateset->num_rates++;
1265 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1266 struct ieee80211_sta *sta,
1267 struct wmi_peer_assoc_complete_arg *arg)
1269 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1273 lockdep_assert_held(&ar->conf_mutex);
1275 if (!ht_cap->ht_supported)
1278 arg->peer_flags |= WMI_PEER_HT;
1279 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1280 ht_cap->ampdu_factor)) - 1;
1282 arg->peer_mpdu_density =
1283 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1285 arg->peer_ht_caps = ht_cap->cap;
1286 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1288 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1289 arg->peer_flags |= WMI_PEER_LDPC;
1291 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1292 arg->peer_flags |= WMI_PEER_40MHZ;
1293 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1296 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1297 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1299 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1300 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1302 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1303 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1304 arg->peer_flags |= WMI_PEER_STBC;
1307 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1308 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1309 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1310 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1311 arg->peer_rate_caps |= stbc;
1312 arg->peer_flags |= WMI_PEER_STBC;
1315 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1316 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1317 else if (ht_cap->mcs.rx_mask[1])
1318 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1320 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1321 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1322 arg->peer_ht_rates.rates[n++] = i;
1325 * This is a workaround for HT-enabled STAs which break the spec
1326 * and have no HT capabilities RX mask (no HT RX MCS map).
1328 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1329 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1331 * Firmware asserts if such situation occurs.
1334 arg->peer_ht_rates.num_rates = 8;
1335 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1336 arg->peer_ht_rates.rates[i] = i;
1338 arg->peer_ht_rates.num_rates = n;
1339 arg->peer_num_spatial_streams = sta->rx_nss;
1342 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1344 arg->peer_ht_rates.num_rates,
1345 arg->peer_num_spatial_streams);
1348 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1349 struct ath10k_vif *arvif,
1350 struct ieee80211_sta *sta)
1356 lockdep_assert_held(&ar->conf_mutex);
1358 if (sta->wme && sta->uapsd_queues) {
1359 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1360 sta->uapsd_queues, sta->max_sp);
1362 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1363 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1364 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1365 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1366 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1367 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1368 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1369 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1370 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1371 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1372 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1373 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1375 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1376 max_sp = sta->max_sp;
1378 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1380 WMI_AP_PS_PEER_PARAM_UAPSD,
1383 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1384 arvif->vdev_id, ret);
1388 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1390 WMI_AP_PS_PEER_PARAM_MAX_SP,
1393 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1394 arvif->vdev_id, ret);
1398 /* TODO setup this based on STA listen interval and
1399 beacon interval. Currently we don't know
1400 sta->listen_interval - mac80211 patch required.
1401 Currently use 10 seconds */
1402 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1403 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1406 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1407 arvif->vdev_id, ret);
1415 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1416 struct ieee80211_sta *sta,
1417 struct wmi_peer_assoc_complete_arg *arg)
1419 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1422 if (!vht_cap->vht_supported)
1425 arg->peer_flags |= WMI_PEER_VHT;
1426 arg->peer_vht_caps = vht_cap->cap;
1428 ampdu_factor = (vht_cap->cap &
1429 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1430 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1432 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1433 * zero in VHT IE. Using it would result in degraded throughput.
1434 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1435 * it if VHT max_mpdu is smaller. */
1436 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1437 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1438 ampdu_factor)) - 1);
1440 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1441 arg->peer_flags |= WMI_PEER_80MHZ;
1443 arg->peer_vht_rates.rx_max_rate =
1444 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1445 arg->peer_vht_rates.rx_mcs_set =
1446 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1447 arg->peer_vht_rates.tx_max_rate =
1448 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1449 arg->peer_vht_rates.tx_mcs_set =
1450 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1452 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1453 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1456 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1457 struct ieee80211_vif *vif,
1458 struct ieee80211_sta *sta,
1459 struct wmi_peer_assoc_complete_arg *arg)
1461 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1463 switch (arvif->vdev_type) {
1464 case WMI_VDEV_TYPE_AP:
1466 arg->peer_flags |= WMI_PEER_QOS;
1468 if (sta->wme && sta->uapsd_queues) {
1469 arg->peer_flags |= WMI_PEER_APSD;
1470 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1473 case WMI_VDEV_TYPE_STA:
1474 if (vif->bss_conf.qos)
1475 arg->peer_flags |= WMI_PEER_QOS;
1477 case WMI_VDEV_TYPE_IBSS:
1479 arg->peer_flags |= WMI_PEER_QOS;
1485 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1486 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
1489 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1491 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1492 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1495 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1496 struct ieee80211_vif *vif,
1497 struct ieee80211_sta *sta,
1498 struct wmi_peer_assoc_complete_arg *arg)
1500 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1502 switch (ar->hw->conf.chandef.chan->band) {
1503 case IEEE80211_BAND_2GHZ:
1504 if (sta->ht_cap.ht_supported) {
1505 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1506 phymode = MODE_11NG_HT40;
1508 phymode = MODE_11NG_HT20;
1509 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
1516 case IEEE80211_BAND_5GHZ:
1520 if (sta->vht_cap.vht_supported) {
1521 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1522 phymode = MODE_11AC_VHT80;
1523 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1524 phymode = MODE_11AC_VHT40;
1525 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1526 phymode = MODE_11AC_VHT20;
1527 } else if (sta->ht_cap.ht_supported) {
1528 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1529 phymode = MODE_11NA_HT40;
1531 phymode = MODE_11NA_HT20;
1541 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1542 sta->addr, ath10k_wmi_phymode_str(phymode));
1544 arg->peer_phymode = phymode;
1545 WARN_ON(phymode == MODE_UNKNOWN);
1548 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1549 struct ieee80211_vif *vif,
1550 struct ieee80211_sta *sta,
1551 struct wmi_peer_assoc_complete_arg *arg)
1553 lockdep_assert_held(&ar->conf_mutex);
1555 memset(arg, 0, sizeof(*arg));
1557 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1558 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1559 ath10k_peer_assoc_h_rates(ar, sta, arg);
1560 ath10k_peer_assoc_h_ht(ar, sta, arg);
1561 ath10k_peer_assoc_h_vht(ar, sta, arg);
1562 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1563 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1568 static const u32 ath10k_smps_map[] = {
1569 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1570 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1571 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1572 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1575 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1577 const struct ieee80211_sta_ht_cap *ht_cap)
1581 if (!ht_cap->ht_supported)
1584 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1585 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1587 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1590 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1591 WMI_PEER_SMPS_STATE,
1592 ath10k_smps_map[smps]);
1595 /* can be called only in mac80211 callbacks due to `key_count` usage */
1596 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1597 struct ieee80211_vif *vif,
1598 struct ieee80211_bss_conf *bss_conf)
1600 struct ath10k *ar = hw->priv;
1601 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1602 struct ieee80211_sta_ht_cap ht_cap;
1603 struct wmi_peer_assoc_complete_arg peer_arg;
1604 struct ieee80211_sta *ap_sta;
1607 lockdep_assert_held(&ar->conf_mutex);
1609 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1610 arvif->vdev_id, arvif->bssid, arvif->aid);
1614 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1616 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1617 bss_conf->bssid, arvif->vdev_id);
1622 /* ap_sta must be accessed only within rcu section which must be left
1623 * before calling ath10k_setup_peer_smps() which might sleep. */
1624 ht_cap = ap_sta->ht_cap;
1626 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1628 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1629 bss_conf->bssid, arvif->vdev_id, ret);
1636 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1638 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1639 bss_conf->bssid, arvif->vdev_id, ret);
1643 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1645 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1646 arvif->vdev_id, ret);
1650 ath10k_dbg(ar, ATH10K_DBG_MAC,
1651 "mac vdev %d up (associated) bssid %pM aid %d\n",
1652 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1654 WARN_ON(arvif->is_up);
1656 arvif->aid = bss_conf->aid;
1657 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1659 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1661 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1662 arvif->vdev_id, ret);
1666 arvif->is_up = true;
1669 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1670 struct ieee80211_vif *vif)
1672 struct ath10k *ar = hw->priv;
1673 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1676 lockdep_assert_held(&ar->conf_mutex);
1678 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1679 arvif->vdev_id, arvif->bssid);
1681 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1683 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1684 arvif->vdev_id, ret);
1686 arvif->def_wep_key_idx = 0;
1687 arvif->is_up = false;
1690 static int ath10k_station_assoc(struct ath10k *ar,
1691 struct ieee80211_vif *vif,
1692 struct ieee80211_sta *sta,
1695 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1696 struct wmi_peer_assoc_complete_arg peer_arg;
1699 lockdep_assert_held(&ar->conf_mutex);
1701 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
1703 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1704 sta->addr, arvif->vdev_id, ret);
1708 peer_arg.peer_reassoc = reassoc;
1709 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1711 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1712 sta->addr, arvif->vdev_id, ret);
1716 /* Re-assoc is run only to update supported rates for given station. It
1717 * doesn't make much sense to reconfigure the peer completely.
1720 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1723 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1724 arvif->vdev_id, ret);
1728 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1730 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1731 sta->addr, arvif->vdev_id, ret);
1736 arvif->num_legacy_stations++;
1737 ret = ath10k_recalc_rtscts_prot(arvif);
1739 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1740 arvif->vdev_id, ret);
1745 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1747 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1748 arvif->vdev_id, ret);
1756 static int ath10k_station_disassoc(struct ath10k *ar,
1757 struct ieee80211_vif *vif,
1758 struct ieee80211_sta *sta)
1760 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1763 lockdep_assert_held(&ar->conf_mutex);
1766 arvif->num_legacy_stations--;
1767 ret = ath10k_recalc_rtscts_prot(arvif);
1769 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1770 arvif->vdev_id, ret);
1775 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1777 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1778 arvif->vdev_id, ret);
1789 static int ath10k_update_channel_list(struct ath10k *ar)
1791 struct ieee80211_hw *hw = ar->hw;
1792 struct ieee80211_supported_band **bands;
1793 enum ieee80211_band band;
1794 struct ieee80211_channel *channel;
1795 struct wmi_scan_chan_list_arg arg = {0};
1796 struct wmi_channel_arg *ch;
1802 lockdep_assert_held(&ar->conf_mutex);
1804 bands = hw->wiphy->bands;
1805 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1809 for (i = 0; i < bands[band]->n_channels; i++) {
1810 if (bands[band]->channels[i].flags &
1811 IEEE80211_CHAN_DISABLED)
1818 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1819 arg.channels = kzalloc(len, GFP_KERNEL);
1824 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1828 for (i = 0; i < bands[band]->n_channels; i++) {
1829 channel = &bands[band]->channels[i];
1831 if (channel->flags & IEEE80211_CHAN_DISABLED)
1834 ch->allow_ht = true;
1836 /* FIXME: when should we really allow VHT? */
1837 ch->allow_vht = true;
1840 !(channel->flags & IEEE80211_CHAN_NO_IR);
1843 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1846 !!(channel->flags & IEEE80211_CHAN_RADAR);
1848 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1849 ch->passive = passive;
1851 ch->freq = channel->center_freq;
1852 ch->band_center_freq1 = channel->center_freq;
1854 ch->max_power = channel->max_power * 2;
1855 ch->max_reg_power = channel->max_reg_power * 2;
1856 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1857 ch->reg_class_id = 0; /* FIXME */
1859 /* FIXME: why use only legacy modes, why not any
1860 * HT/VHT modes? Would that even make any
1862 if (channel->band == IEEE80211_BAND_2GHZ)
1863 ch->mode = MODE_11G;
1865 ch->mode = MODE_11A;
1867 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1870 ath10k_dbg(ar, ATH10K_DBG_WMI,
1871 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1872 ch - arg.channels, arg.n_channels,
1873 ch->freq, ch->max_power, ch->max_reg_power,
1874 ch->max_antenna_gain, ch->mode);
1880 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1881 kfree(arg.channels);
1886 static enum wmi_dfs_region
1887 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1889 switch (dfs_region) {
1890 case NL80211_DFS_UNSET:
1891 return WMI_UNINIT_DFS_DOMAIN;
1892 case NL80211_DFS_FCC:
1893 return WMI_FCC_DFS_DOMAIN;
1894 case NL80211_DFS_ETSI:
1895 return WMI_ETSI_DFS_DOMAIN;
1896 case NL80211_DFS_JP:
1897 return WMI_MKK4_DFS_DOMAIN;
1899 return WMI_UNINIT_DFS_DOMAIN;
1902 static void ath10k_regd_update(struct ath10k *ar)
1904 struct reg_dmn_pair_mapping *regpair;
1906 enum wmi_dfs_region wmi_dfs_reg;
1907 enum nl80211_dfs_regions nl_dfs_reg;
1909 lockdep_assert_held(&ar->conf_mutex);
1911 ret = ath10k_update_channel_list(ar);
1913 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1915 regpair = ar->ath_common.regulatory.regpair;
1917 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1918 nl_dfs_reg = ar->dfs_detector->region;
1919 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1921 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1924 /* Target allows setting up per-band regdomain but ath_common provides
1925 * a combined one only */
1926 ret = ath10k_wmi_pdev_set_regdomain(ar,
1927 regpair->reg_domain,
1928 regpair->reg_domain, /* 2ghz */
1929 regpair->reg_domain, /* 5ghz */
1930 regpair->reg_2ghz_ctl,
1931 regpair->reg_5ghz_ctl,
1934 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1937 static void ath10k_reg_notifier(struct wiphy *wiphy,
1938 struct regulatory_request *request)
1940 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1941 struct ath10k *ar = hw->priv;
1944 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1946 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1947 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1948 request->dfs_region);
1949 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1950 request->dfs_region);
1952 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1953 request->dfs_region);
1956 mutex_lock(&ar->conf_mutex);
1957 if (ar->state == ATH10K_STATE_ON)
1958 ath10k_regd_update(ar);
1959 mutex_unlock(&ar->conf_mutex);
1966 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1968 if (ieee80211_is_mgmt(hdr->frame_control))
1969 return HTT_DATA_TX_EXT_TID_MGMT;
1971 if (!ieee80211_is_data_qos(hdr->frame_control))
1972 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1974 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1975 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1977 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1980 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
1983 return ath10k_vif_to_arvif(vif)->vdev_id;
1985 if (ar->monitor_started)
1986 return ar->monitor_vdev_id;
1988 ath10k_warn(ar, "failed to resolve vdev id\n");
1992 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1993 * Control in the header.
1995 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1997 struct ieee80211_hdr *hdr = (void *)skb->data;
1998 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2001 if (!ieee80211_is_data_qos(hdr->frame_control))
2004 qos_ctl = ieee80211_get_qos_ctl(hdr);
2005 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2006 skb->data, (void *)qos_ctl - (void *)skb->data);
2007 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
2009 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2010 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2011 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2012 * it is safe to downgrade to NullFunc.
2014 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2015 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2016 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2020 static void ath10k_tx_wep_key_work(struct work_struct *work)
2022 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2024 struct ath10k *ar = arvif->ar;
2025 int ret, keyidx = arvif->def_wep_key_newidx;
2027 mutex_lock(&arvif->ar->conf_mutex);
2029 if (arvif->ar->state != ATH10K_STATE_ON)
2032 if (arvif->def_wep_key_idx == keyidx)
2035 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
2036 arvif->vdev_id, keyidx);
2038 ret = ath10k_wmi_vdev_set_param(arvif->ar,
2040 arvif->ar->wmi.vdev_param->def_keyid,
2043 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
2049 arvif->def_wep_key_idx = keyidx;
2052 mutex_unlock(&arvif->ar->conf_mutex);
2055 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
2056 struct ieee80211_key_conf *key,
2057 struct sk_buff *skb)
2059 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2060 struct ath10k *ar = arvif->ar;
2061 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2063 if (!ieee80211_has_protected(hdr->frame_control))
2069 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
2070 key->cipher != WLAN_CIPHER_SUITE_WEP104)
2073 if (key->keyidx == arvif->def_wep_key_idx)
2076 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
2077 * queueing frames until key index is updated is not an option because
2078 * sk_buff may need more processing to be done, e.g. offchannel */
2079 arvif->def_wep_key_newidx = key->keyidx;
2080 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
2083 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2084 struct ieee80211_vif *vif,
2085 struct sk_buff *skb)
2087 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2088 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2090 /* This is case only for P2P_GO */
2091 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2092 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2095 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2096 spin_lock_bh(&ar->data_lock);
2097 if (arvif->u.ap.noa_data)
2098 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2100 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2101 arvif->u.ap.noa_data,
2102 arvif->u.ap.noa_len);
2103 spin_unlock_bh(&ar->data_lock);
2107 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2109 /* FIXME: Not really sure since when the behaviour changed. At some
2110 * point new firmware stopped requiring creation of peer entries for
2111 * offchannel tx (and actually creating them causes issues with wmi-htc
2112 * tx credit replenishment and reliability). Assuming it's at least 3.4
2113 * because that's when the `freq` was introduced to TX_FRM HTT command.
2115 return !(ar->htt.target_version_major >= 3 &&
2116 ar->htt.target_version_minor >= 4);
2119 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2121 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2124 if (ar->htt.target_version_major >= 3) {
2125 /* Since HTT 3.0 there is no separate mgmt tx command */
2126 ret = ath10k_htt_tx(&ar->htt, skb);
2130 if (ieee80211_is_mgmt(hdr->frame_control)) {
2131 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2133 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2134 ATH10K_MAX_NUM_MGMT_PENDING) {
2135 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2140 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2141 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2143 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2145 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2147 ieee80211_is_nullfunc(hdr->frame_control)) {
2148 /* FW does not report tx status properly for NullFunc frames
2149 * unless they are sent through mgmt tx path. mac80211 sends
2150 * those frames when it detects link/beacon loss and depends
2151 * on the tx status to be correct. */
2152 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2154 ret = ath10k_htt_tx(&ar->htt, skb);
2159 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2161 ieee80211_free_txskb(ar->hw, skb);
2165 void ath10k_offchan_tx_purge(struct ath10k *ar)
2167 struct sk_buff *skb;
2170 skb = skb_dequeue(&ar->offchan_tx_queue);
2174 ieee80211_free_txskb(ar->hw, skb);
2178 void ath10k_offchan_tx_work(struct work_struct *work)
2180 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2181 struct ath10k_peer *peer;
2182 struct ieee80211_hdr *hdr;
2183 struct sk_buff *skb;
2184 const u8 *peer_addr;
2188 /* FW requirement: We must create a peer before FW will send out
2189 * an offchannel frame. Otherwise the frame will be stuck and
2190 * never transmitted. We delete the peer upon tx completion.
2191 * It is unlikely that a peer for offchannel tx will already be
2192 * present. However it may be in some rare cases so account for that.
2193 * Otherwise we might remove a legitimate peer and break stuff. */
2196 skb = skb_dequeue(&ar->offchan_tx_queue);
2200 mutex_lock(&ar->conf_mutex);
2202 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2205 hdr = (struct ieee80211_hdr *)skb->data;
2206 peer_addr = ieee80211_get_DA(hdr);
2207 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2209 spin_lock_bh(&ar->data_lock);
2210 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2211 spin_unlock_bh(&ar->data_lock);
2214 /* FIXME: should this use ath10k_warn()? */
2215 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2216 peer_addr, vdev_id);
2219 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2221 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2222 peer_addr, vdev_id, ret);
2225 spin_lock_bh(&ar->data_lock);
2226 reinit_completion(&ar->offchan_tx_completed);
2227 ar->offchan_tx_skb = skb;
2228 spin_unlock_bh(&ar->data_lock);
2230 ath10k_tx_htt(ar, skb);
2232 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2235 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2239 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2241 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2242 peer_addr, vdev_id, ret);
2245 mutex_unlock(&ar->conf_mutex);
2249 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2251 struct sk_buff *skb;
2254 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2258 ieee80211_free_txskb(ar->hw, skb);
2262 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2264 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2265 struct sk_buff *skb;
2269 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2273 ret = ath10k_wmi_mgmt_tx(ar, skb);
2275 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2277 ieee80211_free_txskb(ar->hw, skb);
2286 void __ath10k_scan_finish(struct ath10k *ar)
2288 lockdep_assert_held(&ar->data_lock);
2290 switch (ar->scan.state) {
2291 case ATH10K_SCAN_IDLE:
2293 case ATH10K_SCAN_RUNNING:
2294 if (ar->scan.is_roc)
2295 ieee80211_remain_on_channel_expired(ar->hw);
2296 case ATH10K_SCAN_ABORTING:
2297 if (!ar->scan.is_roc)
2298 ieee80211_scan_completed(ar->hw,
2300 ATH10K_SCAN_ABORTING));
2302 case ATH10K_SCAN_STARTING:
2303 ar->scan.state = ATH10K_SCAN_IDLE;
2304 ar->scan_channel = NULL;
2305 ath10k_offchan_tx_purge(ar);
2306 cancel_delayed_work(&ar->scan.timeout);
2307 complete_all(&ar->scan.completed);
2312 void ath10k_scan_finish(struct ath10k *ar)
2314 spin_lock_bh(&ar->data_lock);
2315 __ath10k_scan_finish(ar);
2316 spin_unlock_bh(&ar->data_lock);
2319 static int ath10k_scan_stop(struct ath10k *ar)
2321 struct wmi_stop_scan_arg arg = {
2322 .req_id = 1, /* FIXME */
2323 .req_type = WMI_SCAN_STOP_ONE,
2324 .u.scan_id = ATH10K_SCAN_ID,
2328 lockdep_assert_held(&ar->conf_mutex);
2330 ret = ath10k_wmi_stop_scan(ar, &arg);
2332 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2336 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2338 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2340 } else if (ret > 0) {
2345 /* Scan state should be updated upon scan completion but in case
2346 * firmware fails to deliver the event (for whatever reason) it is
2347 * desired to clean up scan state anyway. Firmware may have just
2348 * dropped the scan completion event delivery due to transport pipe
2349 * being overflown with data and/or it can recover on its own before
2350 * next scan request is submitted.
2352 spin_lock_bh(&ar->data_lock);
2353 if (ar->scan.state != ATH10K_SCAN_IDLE)
2354 __ath10k_scan_finish(ar);
2355 spin_unlock_bh(&ar->data_lock);
2360 static void ath10k_scan_abort(struct ath10k *ar)
2364 lockdep_assert_held(&ar->conf_mutex);
2366 spin_lock_bh(&ar->data_lock);
2368 switch (ar->scan.state) {
2369 case ATH10K_SCAN_IDLE:
2370 /* This can happen if timeout worker kicked in and called
2371 * abortion while scan completion was being processed.
2374 case ATH10K_SCAN_STARTING:
2375 case ATH10K_SCAN_ABORTING:
2376 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2377 ath10k_scan_state_str(ar->scan.state),
2380 case ATH10K_SCAN_RUNNING:
2381 ar->scan.state = ATH10K_SCAN_ABORTING;
2382 spin_unlock_bh(&ar->data_lock);
2384 ret = ath10k_scan_stop(ar);
2386 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2388 spin_lock_bh(&ar->data_lock);
2392 spin_unlock_bh(&ar->data_lock);
2395 void ath10k_scan_timeout_work(struct work_struct *work)
2397 struct ath10k *ar = container_of(work, struct ath10k,
2400 mutex_lock(&ar->conf_mutex);
2401 ath10k_scan_abort(ar);
2402 mutex_unlock(&ar->conf_mutex);
2405 static int ath10k_start_scan(struct ath10k *ar,
2406 const struct wmi_start_scan_arg *arg)
2410 lockdep_assert_held(&ar->conf_mutex);
2412 ret = ath10k_wmi_start_scan(ar, arg);
2416 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2418 ret = ath10k_scan_stop(ar);
2420 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2425 /* Add a 200ms margin to account for event/command processing */
2426 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2427 msecs_to_jiffies(arg->max_scan_time+200));
2431 /**********************/
2432 /* mac80211 callbacks */
2433 /**********************/
2435 static void ath10k_tx(struct ieee80211_hw *hw,
2436 struct ieee80211_tx_control *control,
2437 struct sk_buff *skb)
2439 struct ath10k *ar = hw->priv;
2440 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2441 struct ieee80211_vif *vif = info->control.vif;
2442 struct ieee80211_key_conf *key = info->control.hw_key;
2443 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2445 /* We should disable CCK RATE due to P2P */
2446 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2447 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2449 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2450 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2451 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2453 /* it makes no sense to process injected frames like that */
2454 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2455 ath10k_tx_h_nwifi(hw, skb);
2456 ath10k_tx_h_update_wep_key(vif, key, skb);
2457 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2458 ath10k_tx_h_seq_no(vif, skb);
2461 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2462 spin_lock_bh(&ar->data_lock);
2463 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
2464 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2465 spin_unlock_bh(&ar->data_lock);
2467 if (ath10k_mac_need_offchan_tx_work(ar)) {
2468 ATH10K_SKB_CB(skb)->htt.freq = 0;
2469 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2471 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2474 skb_queue_tail(&ar->offchan_tx_queue, skb);
2475 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2480 ath10k_tx_htt(ar, skb);
2483 /* Must not be called with conf_mutex held as workers can use that also. */
2484 void ath10k_drain_tx(struct ath10k *ar)
2486 /* make sure rcu-protected mac80211 tx path itself is drained */
2489 ath10k_offchan_tx_purge(ar);
2490 ath10k_mgmt_over_wmi_tx_purge(ar);
2492 cancel_work_sync(&ar->offchan_tx_work);
2493 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2496 void ath10k_halt(struct ath10k *ar)
2498 struct ath10k_vif *arvif;
2500 lockdep_assert_held(&ar->conf_mutex);
2502 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2503 ar->filter_flags = 0;
2504 ar->monitor = false;
2506 if (ar->monitor_started)
2507 ath10k_monitor_stop(ar);
2509 ar->monitor_started = false;
2511 ath10k_scan_finish(ar);
2512 ath10k_peer_cleanup_all(ar);
2513 ath10k_core_stop(ar);
2514 ath10k_hif_power_down(ar);
2516 spin_lock_bh(&ar->data_lock);
2517 list_for_each_entry(arvif, &ar->arvifs, list)
2518 ath10k_mac_vif_beacon_cleanup(arvif);
2519 spin_unlock_bh(&ar->data_lock);
2522 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2524 struct ath10k *ar = hw->priv;
2526 mutex_lock(&ar->conf_mutex);
2528 if (ar->cfg_tx_chainmask) {
2529 *tx_ant = ar->cfg_tx_chainmask;
2530 *rx_ant = ar->cfg_rx_chainmask;
2532 *tx_ant = ar->supp_tx_chainmask;
2533 *rx_ant = ar->supp_rx_chainmask;
2536 mutex_unlock(&ar->conf_mutex);
2541 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2543 /* It is not clear that allowing gaps in chainmask
2544 * is helpful. Probably it will not do what user
2545 * is hoping for, so warn in that case.
2547 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2550 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2554 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2558 lockdep_assert_held(&ar->conf_mutex);
2560 ath10k_check_chain_mask(ar, tx_ant, "tx");
2561 ath10k_check_chain_mask(ar, rx_ant, "rx");
2563 ar->cfg_tx_chainmask = tx_ant;
2564 ar->cfg_rx_chainmask = rx_ant;
2566 if ((ar->state != ATH10K_STATE_ON) &&
2567 (ar->state != ATH10K_STATE_RESTARTED))
2570 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2573 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2578 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2581 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2589 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2591 struct ath10k *ar = hw->priv;
2594 mutex_lock(&ar->conf_mutex);
2595 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2596 mutex_unlock(&ar->conf_mutex);
2600 static int ath10k_start(struct ieee80211_hw *hw)
2602 struct ath10k *ar = hw->priv;
2606 * This makes sense only when restarting hw. It is harmless to call
2607 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2608 * commands will be submitted while restarting.
2610 ath10k_drain_tx(ar);
2612 mutex_lock(&ar->conf_mutex);
2614 switch (ar->state) {
2615 case ATH10K_STATE_OFF:
2616 ar->state = ATH10K_STATE_ON;
2618 case ATH10K_STATE_RESTARTING:
2620 ar->state = ATH10K_STATE_RESTARTED;
2622 case ATH10K_STATE_ON:
2623 case ATH10K_STATE_RESTARTED:
2624 case ATH10K_STATE_WEDGED:
2628 case ATH10K_STATE_UTF:
2633 ret = ath10k_hif_power_up(ar);
2635 ath10k_err(ar, "Could not init hif: %d\n", ret);
2639 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2641 ath10k_err(ar, "Could not init core: %d\n", ret);
2642 goto err_power_down;
2645 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2647 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2651 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2653 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2657 if (ar->cfg_tx_chainmask)
2658 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2659 ar->cfg_rx_chainmask);
2662 * By default FW set ARP frames ac to voice (6). In that case ARP
2663 * exchange is not working properly for UAPSD enabled AP. ARP requests
2664 * which arrives with access category 0 are processed by network stack
2665 * and send back with access category 0, but FW changes access category
2666 * to 6. Set ARP frames access category to best effort (0) solves
2670 ret = ath10k_wmi_pdev_set_param(ar,
2671 ar->wmi.pdev_param->arp_ac_override, 0);
2673 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2678 ar->num_started_vdevs = 0;
2679 ath10k_regd_update(ar);
2681 ath10k_spectral_start(ar);
2683 mutex_unlock(&ar->conf_mutex);
2687 ath10k_core_stop(ar);
2690 ath10k_hif_power_down(ar);
2693 ar->state = ATH10K_STATE_OFF;
2696 mutex_unlock(&ar->conf_mutex);
2700 static void ath10k_stop(struct ieee80211_hw *hw)
2702 struct ath10k *ar = hw->priv;
2704 ath10k_drain_tx(ar);
2706 mutex_lock(&ar->conf_mutex);
2707 if (ar->state != ATH10K_STATE_OFF) {
2709 ar->state = ATH10K_STATE_OFF;
2711 mutex_unlock(&ar->conf_mutex);
2713 cancel_delayed_work_sync(&ar->scan.timeout);
2714 cancel_work_sync(&ar->restart_work);
2717 static int ath10k_config_ps(struct ath10k *ar)
2719 struct ath10k_vif *arvif;
2722 lockdep_assert_held(&ar->conf_mutex);
2724 list_for_each_entry(arvif, &ar->arvifs, list) {
2725 ret = ath10k_mac_vif_setup_ps(arvif);
2727 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2735 static const char *chandef_get_width(enum nl80211_chan_width width)
2738 case NL80211_CHAN_WIDTH_20_NOHT:
2740 case NL80211_CHAN_WIDTH_20:
2742 case NL80211_CHAN_WIDTH_40:
2744 case NL80211_CHAN_WIDTH_80:
2746 case NL80211_CHAN_WIDTH_80P80:
2748 case NL80211_CHAN_WIDTH_160:
2750 case NL80211_CHAN_WIDTH_5:
2752 case NL80211_CHAN_WIDTH_10:
2758 static void ath10k_config_chan(struct ath10k *ar)
2760 struct ath10k_vif *arvif;
2763 lockdep_assert_held(&ar->conf_mutex);
2765 ath10k_dbg(ar, ATH10K_DBG_MAC,
2766 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2767 ar->chandef.chan->center_freq,
2768 ar->chandef.center_freq1,
2769 ar->chandef.center_freq2,
2770 chandef_get_width(ar->chandef.width));
2772 /* First stop monitor interface. Some FW versions crash if there's a
2773 * lone monitor interface. */
2774 if (ar->monitor_started)
2775 ath10k_monitor_stop(ar);
2777 list_for_each_entry(arvif, &ar->arvifs, list) {
2778 if (!arvif->is_started)
2784 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2787 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2789 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2790 arvif->vdev_id, ret);
2795 /* all vdevs are downed now - attempt to restart and re-up them */
2797 list_for_each_entry(arvif, &ar->arvifs, list) {
2798 if (!arvif->is_started)
2801 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2804 ret = ath10k_vdev_restart(arvif);
2806 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2807 arvif->vdev_id, ret);
2814 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2817 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2818 arvif->vdev_id, ret);
2823 ath10k_monitor_recalc(ar);
2826 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2831 lockdep_assert_held(&ar->conf_mutex);
2833 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2835 param = ar->wmi.pdev_param->txpower_limit2g;
2836 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2838 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2843 param = ar->wmi.pdev_param->txpower_limit5g;
2844 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2846 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2854 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2856 struct ath10k_vif *arvif;
2857 int ret, txpower = -1;
2859 lockdep_assert_held(&ar->conf_mutex);
2861 list_for_each_entry(arvif, &ar->arvifs, list) {
2862 WARN_ON(arvif->txpower < 0);
2865 txpower = arvif->txpower;
2867 txpower = min(txpower, arvif->txpower);
2870 if (WARN_ON(txpower == -1))
2873 ret = ath10k_mac_txpower_setup(ar, txpower);
2875 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2883 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2885 struct ath10k *ar = hw->priv;
2886 struct ieee80211_conf *conf = &hw->conf;
2889 mutex_lock(&ar->conf_mutex);
2891 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2892 ath10k_dbg(ar, ATH10K_DBG_MAC,
2893 "mac config channel %dMHz flags 0x%x radar %d\n",
2894 conf->chandef.chan->center_freq,
2895 conf->chandef.chan->flags,
2896 conf->radar_enabled);
2898 spin_lock_bh(&ar->data_lock);
2899 ar->rx_channel = conf->chandef.chan;
2900 spin_unlock_bh(&ar->data_lock);
2902 ar->radar_enabled = conf->radar_enabled;
2903 ath10k_recalc_radar_detection(ar);
2905 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2906 ar->chandef = conf->chandef;
2907 ath10k_config_chan(ar);
2911 if (changed & IEEE80211_CONF_CHANGE_PS)
2912 ath10k_config_ps(ar);
2914 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2915 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2916 ret = ath10k_monitor_recalc(ar);
2918 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2921 mutex_unlock(&ar->conf_mutex);
2925 static u32 get_nss_from_chainmask(u16 chain_mask)
2927 if ((chain_mask & 0x15) == 0x15)
2929 else if ((chain_mask & 0x7) == 0x7)
2931 else if ((chain_mask & 0x3) == 0x3)
2938 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2939 * because we will send mgmt frames without CCK. This requirement
2940 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2943 static int ath10k_add_interface(struct ieee80211_hw *hw,
2944 struct ieee80211_vif *vif)
2946 struct ath10k *ar = hw->priv;
2947 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2948 enum wmi_sta_powersave_param param;
2954 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2956 mutex_lock(&ar->conf_mutex);
2958 memset(arvif, 0, sizeof(*arvif));
2963 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2964 INIT_LIST_HEAD(&arvif->list);
2966 if (ar->free_vdev_map == 0) {
2967 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2971 bit = __ffs64(ar->free_vdev_map);
2973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2974 bit, ar->free_vdev_map);
2976 arvif->vdev_id = bit;
2977 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2979 switch (vif->type) {
2980 case NL80211_IFTYPE_P2P_DEVICE:
2981 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2982 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2984 case NL80211_IFTYPE_UNSPECIFIED:
2985 case NL80211_IFTYPE_STATION:
2986 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2988 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2990 case NL80211_IFTYPE_ADHOC:
2991 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2993 case NL80211_IFTYPE_AP:
2994 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2997 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2999 case NL80211_IFTYPE_MONITOR:
3000 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3007 /* Some firmware revisions don't wait for beacon tx completion before
3008 * sending another SWBA event. This could lead to hardware using old
3009 * (freed) beacon data in some cases, e.g. tx credit starvation
3010 * combined with missed TBTT. This is very very rare.
3012 * On non-IOMMU-enabled hosts this could be a possible security issue
3013 * because hw could beacon some random data on the air. On
3014 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3015 * device would crash.
3017 * Since there are no beacon tx completions (implicit nor explicit)
3018 * propagated to host the only workaround for this is to allocate a
3019 * DMA-coherent buffer for a lifetime of a vif and use it for all
3020 * beacon tx commands. Worst case for this approach is some beacons may
3021 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3023 if (vif->type == NL80211_IFTYPE_ADHOC ||
3024 vif->type == NL80211_IFTYPE_AP) {
3025 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3026 IEEE80211_MAX_FRAME_LEN,
3027 &arvif->beacon_paddr,
3029 if (!arvif->beacon_buf) {
3031 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3037 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3038 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3039 arvif->beacon_buf ? "single-buf" : "per-skb");
3041 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3042 arvif->vdev_subtype, vif->addr);
3044 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
3045 arvif->vdev_id, ret);
3049 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
3050 list_add(&arvif->list, &ar->arvifs);
3052 vdev_param = ar->wmi.vdev_param->def_keyid;
3053 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
3054 arvif->def_wep_key_idx);
3056 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
3057 arvif->vdev_id, ret);
3058 goto err_vdev_delete;
3061 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3062 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3063 ATH10K_HW_TXRX_NATIVE_WIFI);
3064 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3065 if (ret && ret != -EOPNOTSUPP) {
3066 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
3067 arvif->vdev_id, ret);
3068 goto err_vdev_delete;
3071 if (ar->cfg_tx_chainmask) {
3072 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3074 vdev_param = ar->wmi.vdev_param->nss;
3075 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3078 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3079 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3081 goto err_vdev_delete;
3085 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3086 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3088 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
3089 arvif->vdev_id, ret);
3090 goto err_vdev_delete;
3093 ret = ath10k_mac_set_kickout(arvif);
3095 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
3096 arvif->vdev_id, ret);
3097 goto err_peer_delete;
3101 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3102 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3103 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3104 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3107 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
3108 arvif->vdev_id, ret);
3109 goto err_peer_delete;
3112 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3114 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3115 arvif->vdev_id, ret);
3116 goto err_peer_delete;
3119 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3121 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3122 arvif->vdev_id, ret);
3123 goto err_peer_delete;
3127 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
3129 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3130 arvif->vdev_id, ret);
3131 goto err_peer_delete;
3134 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
3136 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
3137 arvif->vdev_id, ret);
3138 goto err_peer_delete;
3141 arvif->txpower = vif->bss_conf.txpower;
3142 ret = ath10k_mac_txpower_recalc(ar);
3144 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3145 goto err_peer_delete;
3148 mutex_unlock(&ar->conf_mutex);
3152 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3153 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3156 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3157 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3158 list_del(&arvif->list);
3161 if (arvif->beacon_buf) {
3162 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3163 arvif->beacon_buf, arvif->beacon_paddr);
3164 arvif->beacon_buf = NULL;
3167 mutex_unlock(&ar->conf_mutex);
3172 static void ath10k_remove_interface(struct ieee80211_hw *hw,
3173 struct ieee80211_vif *vif)
3175 struct ath10k *ar = hw->priv;
3176 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3179 cancel_work_sync(&arvif->wep_key_work);
3181 mutex_lock(&ar->conf_mutex);
3183 spin_lock_bh(&ar->data_lock);
3184 ath10k_mac_vif_beacon_cleanup(arvif);
3185 spin_unlock_bh(&ar->data_lock);
3187 ret = ath10k_spectral_vif_stop(arvif);
3189 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
3190 arvif->vdev_id, ret);
3192 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3193 list_del(&arvif->list);
3195 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3196 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3198 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
3199 arvif->vdev_id, ret);
3201 kfree(arvif->u.ap.noa_data);
3204 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3207 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3209 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3210 arvif->vdev_id, ret);
3212 ath10k_peer_cleanup(ar, arvif->vdev_id);
3214 mutex_unlock(&ar->conf_mutex);
3218 * FIXME: Has to be verified.
3220 #define SUPPORTED_FILTERS \
3221 (FIF_PROMISC_IN_BSS | \
3226 FIF_BCN_PRBRESP_PROMISC | \
3230 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3231 unsigned int changed_flags,
3232 unsigned int *total_flags,
3235 struct ath10k *ar = hw->priv;
3238 mutex_lock(&ar->conf_mutex);
3240 changed_flags &= SUPPORTED_FILTERS;
3241 *total_flags &= SUPPORTED_FILTERS;
3242 ar->filter_flags = *total_flags;
3244 ret = ath10k_monitor_recalc(ar);
3246 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3248 mutex_unlock(&ar->conf_mutex);
3251 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3252 struct ieee80211_vif *vif,
3253 struct ieee80211_bss_conf *info,
3256 struct ath10k *ar = hw->priv;
3257 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3259 u32 vdev_param, pdev_param, slottime, preamble;
3261 mutex_lock(&ar->conf_mutex);
3263 if (changed & BSS_CHANGED_IBSS)
3264 ath10k_control_ibss(arvif, info, vif->addr);
3266 if (changed & BSS_CHANGED_BEACON_INT) {
3267 arvif->beacon_interval = info->beacon_int;
3268 vdev_param = ar->wmi.vdev_param->beacon_interval;
3269 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3270 arvif->beacon_interval);
3271 ath10k_dbg(ar, ATH10K_DBG_MAC,
3272 "mac vdev %d beacon_interval %d\n",
3273 arvif->vdev_id, arvif->beacon_interval);
3276 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3277 arvif->vdev_id, ret);
3280 if (changed & BSS_CHANGED_BEACON) {
3281 ath10k_dbg(ar, ATH10K_DBG_MAC,
3282 "vdev %d set beacon tx mode to staggered\n",
3285 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3286 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3287 WMI_BEACON_STAGGERED_MODE);
3289 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3290 arvif->vdev_id, ret);
3293 if (changed & BSS_CHANGED_BEACON_INFO) {
3294 arvif->dtim_period = info->dtim_period;
3296 ath10k_dbg(ar, ATH10K_DBG_MAC,
3297 "mac vdev %d dtim_period %d\n",
3298 arvif->vdev_id, arvif->dtim_period);
3300 vdev_param = ar->wmi.vdev_param->dtim_period;
3301 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3302 arvif->dtim_period);
3304 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3305 arvif->vdev_id, ret);
3308 if (changed & BSS_CHANGED_SSID &&
3309 vif->type == NL80211_IFTYPE_AP) {
3310 arvif->u.ap.ssid_len = info->ssid_len;
3312 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3313 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3316 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3317 ether_addr_copy(arvif->bssid, info->bssid);
3319 if (changed & BSS_CHANGED_BEACON_ENABLED)
3320 ath10k_control_beaconing(arvif, info);
3322 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3323 arvif->use_cts_prot = info->use_cts_prot;
3324 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3325 arvif->vdev_id, info->use_cts_prot);
3327 ret = ath10k_recalc_rtscts_prot(arvif);
3329 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3330 arvif->vdev_id, ret);
3333 if (changed & BSS_CHANGED_ERP_SLOT) {
3334 if (info->use_short_slot)
3335 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3338 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3340 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3341 arvif->vdev_id, slottime);
3343 vdev_param = ar->wmi.vdev_param->slot_time;
3344 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3347 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3348 arvif->vdev_id, ret);
3351 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3352 if (info->use_short_preamble)
3353 preamble = WMI_VDEV_PREAMBLE_SHORT;
3355 preamble = WMI_VDEV_PREAMBLE_LONG;
3357 ath10k_dbg(ar, ATH10K_DBG_MAC,
3358 "mac vdev %d preamble %dn",
3359 arvif->vdev_id, preamble);
3361 vdev_param = ar->wmi.vdev_param->preamble;
3362 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3365 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3366 arvif->vdev_id, ret);
3369 if (changed & BSS_CHANGED_ASSOC) {
3371 /* Workaround: Make sure monitor vdev is not running
3372 * when associating to prevent some firmware revisions
3373 * (e.g. 10.1 and 10.2) from crashing.
3375 if (ar->monitor_started)
3376 ath10k_monitor_stop(ar);
3377 ath10k_bss_assoc(hw, vif, info);
3378 ath10k_monitor_recalc(ar);
3380 ath10k_bss_disassoc(hw, vif);
3384 if (changed & BSS_CHANGED_TXPOWER) {
3385 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3386 arvif->vdev_id, info->txpower);
3388 arvif->txpower = info->txpower;
3389 ret = ath10k_mac_txpower_recalc(ar);
3391 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3394 if (changed & BSS_CHANGED_PS) {
3395 ret = ath10k_mac_vif_setup_ps(arvif);
3397 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3398 arvif->vdev_id, ret);
3401 mutex_unlock(&ar->conf_mutex);
3404 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3405 struct ieee80211_vif *vif,
3406 struct ieee80211_scan_request *hw_req)
3408 struct ath10k *ar = hw->priv;
3409 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3410 struct cfg80211_scan_request *req = &hw_req->req;
3411 struct wmi_start_scan_arg arg;
3415 mutex_lock(&ar->conf_mutex);
3417 spin_lock_bh(&ar->data_lock);
3418 switch (ar->scan.state) {
3419 case ATH10K_SCAN_IDLE:
3420 reinit_completion(&ar->scan.started);
3421 reinit_completion(&ar->scan.completed);
3422 ar->scan.state = ATH10K_SCAN_STARTING;
3423 ar->scan.is_roc = false;
3424 ar->scan.vdev_id = arvif->vdev_id;
3427 case ATH10K_SCAN_STARTING:
3428 case ATH10K_SCAN_RUNNING:
3429 case ATH10K_SCAN_ABORTING:
3433 spin_unlock_bh(&ar->data_lock);
3438 memset(&arg, 0, sizeof(arg));
3439 ath10k_wmi_start_scan_init(ar, &arg);
3440 arg.vdev_id = arvif->vdev_id;
3441 arg.scan_id = ATH10K_SCAN_ID;
3444 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3447 arg.ie_len = req->ie_len;
3448 memcpy(arg.ie, req->ie, arg.ie_len);
3452 arg.n_ssids = req->n_ssids;
3453 for (i = 0; i < arg.n_ssids; i++) {
3454 arg.ssids[i].len = req->ssids[i].ssid_len;
3455 arg.ssids[i].ssid = req->ssids[i].ssid;
3458 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3461 if (req->n_channels) {
3462 arg.n_channels = req->n_channels;
3463 for (i = 0; i < arg.n_channels; i++)
3464 arg.channels[i] = req->channels[i]->center_freq;
3467 ret = ath10k_start_scan(ar, &arg);
3469 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3470 spin_lock_bh(&ar->data_lock);
3471 ar->scan.state = ATH10K_SCAN_IDLE;
3472 spin_unlock_bh(&ar->data_lock);
3476 mutex_unlock(&ar->conf_mutex);
3480 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3481 struct ieee80211_vif *vif)
3483 struct ath10k *ar = hw->priv;
3485 mutex_lock(&ar->conf_mutex);
3486 ath10k_scan_abort(ar);
3487 mutex_unlock(&ar->conf_mutex);
3489 cancel_delayed_work_sync(&ar->scan.timeout);
3492 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3493 struct ath10k_vif *arvif,
3494 enum set_key_cmd cmd,
3495 struct ieee80211_key_conf *key)
3497 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3500 /* 10.1 firmware branch requires default key index to be set to group
3501 * key index after installing it. Otherwise FW/HW Txes corrupted
3502 * frames with multi-vif APs. This is not required for main firmware
3503 * branch (e.g. 636).
3505 * FIXME: This has been tested only in AP. It remains unknown if this
3506 * is required for multi-vif STA interfaces on 10.1 */
3508 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3511 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3514 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3517 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3523 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3526 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3527 arvif->vdev_id, ret);
3530 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3531 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3532 struct ieee80211_key_conf *key)
3534 struct ath10k *ar = hw->priv;
3535 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3536 struct ath10k_peer *peer;
3537 const u8 *peer_addr;
3538 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3539 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3542 if (key->keyidx > WMI_MAX_KEY_INDEX)
3545 mutex_lock(&ar->conf_mutex);
3548 peer_addr = sta->addr;
3549 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3550 peer_addr = vif->bss_conf.bssid;
3552 peer_addr = vif->addr;
3554 key->hw_key_idx = key->keyidx;
3556 /* the peer should not disappear in mid-way (unless FW goes awry) since
3557 * we already hold conf_mutex. we just make sure its there now. */
3558 spin_lock_bh(&ar->data_lock);
3559 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3560 spin_unlock_bh(&ar->data_lock);
3563 if (cmd == SET_KEY) {
3564 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3569 /* if the peer doesn't exist there is no key to disable
3577 arvif->wep_keys[key->keyidx] = key;
3579 arvif->wep_keys[key->keyidx] = NULL;
3581 if (cmd == DISABLE_KEY)
3582 ath10k_clear_vdev_key(arvif, key);
3585 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3587 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3588 arvif->vdev_id, peer_addr, ret);
3592 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3594 spin_lock_bh(&ar->data_lock);
3595 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3596 if (peer && cmd == SET_KEY)
3597 peer->keys[key->keyidx] = key;
3598 else if (peer && cmd == DISABLE_KEY)
3599 peer->keys[key->keyidx] = NULL;
3600 else if (peer == NULL)
3601 /* impossible unless FW goes crazy */
3602 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3603 spin_unlock_bh(&ar->data_lock);
3606 mutex_unlock(&ar->conf_mutex);
3610 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3613 struct ath10k_vif *arvif;
3614 struct ath10k_sta *arsta;
3615 struct ieee80211_sta *sta;
3616 u32 changed, bw, nss, smps;
3619 arsta = container_of(wk, struct ath10k_sta, update_wk);
3620 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3621 arvif = arsta->arvif;
3624 spin_lock_bh(&ar->data_lock);
3626 changed = arsta->changed;
3633 spin_unlock_bh(&ar->data_lock);
3635 mutex_lock(&ar->conf_mutex);
3637 if (changed & IEEE80211_RC_BW_CHANGED) {
3638 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3641 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3642 WMI_PEER_CHAN_WIDTH, bw);
3644 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3645 sta->addr, bw, err);
3648 if (changed & IEEE80211_RC_NSS_CHANGED) {
3649 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3652 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3655 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3656 sta->addr, nss, err);
3659 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3660 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3663 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3664 WMI_PEER_SMPS_STATE, smps);
3666 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3667 sta->addr, smps, err);
3670 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3671 changed & IEEE80211_RC_NSS_CHANGED) {
3672 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
3675 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3677 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3681 mutex_unlock(&ar->conf_mutex);
3684 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3686 struct ath10k *ar = arvif->ar;
3688 lockdep_assert_held(&ar->conf_mutex);
3690 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3691 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3694 if (ar->num_stations >= ar->max_num_stations)
3702 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3704 struct ath10k *ar = arvif->ar;
3706 lockdep_assert_held(&ar->conf_mutex);
3708 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3709 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3715 static int ath10k_sta_state(struct ieee80211_hw *hw,
3716 struct ieee80211_vif *vif,
3717 struct ieee80211_sta *sta,
3718 enum ieee80211_sta_state old_state,
3719 enum ieee80211_sta_state new_state)
3721 struct ath10k *ar = hw->priv;
3722 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3723 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3726 if (old_state == IEEE80211_STA_NOTEXIST &&
3727 new_state == IEEE80211_STA_NONE) {
3728 memset(arsta, 0, sizeof(*arsta));
3729 arsta->arvif = arvif;
3730 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3733 /* cancel must be done outside the mutex to avoid deadlock */
3734 if ((old_state == IEEE80211_STA_NONE &&
3735 new_state == IEEE80211_STA_NOTEXIST))
3736 cancel_work_sync(&arsta->update_wk);
3738 mutex_lock(&ar->conf_mutex);
3740 if (old_state == IEEE80211_STA_NOTEXIST &&
3741 new_state == IEEE80211_STA_NONE) {
3743 * New station addition.
3745 ath10k_dbg(ar, ATH10K_DBG_MAC,
3746 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3747 arvif->vdev_id, sta->addr,
3748 ar->num_stations + 1, ar->max_num_stations,
3749 ar->num_peers + 1, ar->max_num_peers);
3751 ret = ath10k_mac_inc_num_stations(arvif);
3753 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3754 ar->max_num_stations);
3758 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3760 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3761 sta->addr, arvif->vdev_id, ret);
3762 ath10k_mac_dec_num_stations(arvif);
3766 if (vif->type == NL80211_IFTYPE_STATION) {
3767 WARN_ON(arvif->is_started);
3769 ret = ath10k_vdev_start(arvif);
3771 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3772 arvif->vdev_id, ret);
3773 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3775 ath10k_mac_dec_num_stations(arvif);
3779 arvif->is_started = true;
3781 } else if ((old_state == IEEE80211_STA_NONE &&
3782 new_state == IEEE80211_STA_NOTEXIST)) {
3784 * Existing station deletion.
3786 ath10k_dbg(ar, ATH10K_DBG_MAC,
3787 "mac vdev %d peer delete %pM (sta gone)\n",
3788 arvif->vdev_id, sta->addr);
3790 if (vif->type == NL80211_IFTYPE_STATION) {
3791 WARN_ON(!arvif->is_started);
3793 ret = ath10k_vdev_stop(arvif);
3795 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3796 arvif->vdev_id, ret);
3798 arvif->is_started = false;
3801 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3803 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3804 sta->addr, arvif->vdev_id, ret);
3806 ath10k_mac_dec_num_stations(arvif);
3807 } else if (old_state == IEEE80211_STA_AUTH &&
3808 new_state == IEEE80211_STA_ASSOC &&
3809 (vif->type == NL80211_IFTYPE_AP ||
3810 vif->type == NL80211_IFTYPE_ADHOC)) {
3814 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3817 ret = ath10k_station_assoc(ar, vif, sta, false);
3819 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3820 sta->addr, arvif->vdev_id, ret);
3821 } else if (old_state == IEEE80211_STA_ASSOC &&
3822 new_state == IEEE80211_STA_AUTH &&
3823 (vif->type == NL80211_IFTYPE_AP ||
3824 vif->type == NL80211_IFTYPE_ADHOC)) {
3828 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3831 ret = ath10k_station_disassoc(ar, vif, sta);
3833 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3834 sta->addr, arvif->vdev_id, ret);
3837 mutex_unlock(&ar->conf_mutex);
3841 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3842 u16 ac, bool enable)
3844 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3848 lockdep_assert_held(&ar->conf_mutex);
3850 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3854 case IEEE80211_AC_VO:
3855 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3856 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3858 case IEEE80211_AC_VI:
3859 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3860 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3862 case IEEE80211_AC_BE:
3863 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3864 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3866 case IEEE80211_AC_BK:
3867 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3868 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3873 arvif->u.sta.uapsd |= value;
3875 arvif->u.sta.uapsd &= ~value;
3877 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3878 WMI_STA_PS_PARAM_UAPSD,
3879 arvif->u.sta.uapsd);
3881 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3885 if (arvif->u.sta.uapsd)
3886 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3888 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3890 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3891 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3894 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3896 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3898 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3899 arvif->vdev_id, ret);
3903 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3905 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3906 arvif->vdev_id, ret);
3914 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3915 struct ieee80211_vif *vif, u16 ac,
3916 const struct ieee80211_tx_queue_params *params)
3918 struct ath10k *ar = hw->priv;
3919 struct wmi_wmm_params_arg *p = NULL;
3922 mutex_lock(&ar->conf_mutex);
3925 case IEEE80211_AC_VO:
3926 p = &ar->wmm_params.ac_vo;
3928 case IEEE80211_AC_VI:
3929 p = &ar->wmm_params.ac_vi;
3931 case IEEE80211_AC_BE:
3932 p = &ar->wmm_params.ac_be;
3934 case IEEE80211_AC_BK:
3935 p = &ar->wmm_params.ac_bk;
3944 p->cwmin = params->cw_min;
3945 p->cwmax = params->cw_max;
3946 p->aifs = params->aifs;
3949 * The channel time duration programmed in the HW is in absolute
3950 * microseconds, while mac80211 gives the txop in units of
3953 p->txop = params->txop * 32;
3955 /* FIXME: FW accepts wmm params per hw, not per vif */
3956 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3958 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3962 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3964 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3967 mutex_unlock(&ar->conf_mutex);
3971 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3973 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3974 struct ieee80211_vif *vif,
3975 struct ieee80211_channel *chan,
3977 enum ieee80211_roc_type type)
3979 struct ath10k *ar = hw->priv;
3980 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3981 struct wmi_start_scan_arg arg;
3984 mutex_lock(&ar->conf_mutex);
3986 spin_lock_bh(&ar->data_lock);
3987 switch (ar->scan.state) {
3988 case ATH10K_SCAN_IDLE:
3989 reinit_completion(&ar->scan.started);
3990 reinit_completion(&ar->scan.completed);
3991 reinit_completion(&ar->scan.on_channel);
3992 ar->scan.state = ATH10K_SCAN_STARTING;
3993 ar->scan.is_roc = true;
3994 ar->scan.vdev_id = arvif->vdev_id;
3995 ar->scan.roc_freq = chan->center_freq;
3998 case ATH10K_SCAN_STARTING:
3999 case ATH10K_SCAN_RUNNING:
4000 case ATH10K_SCAN_ABORTING:
4004 spin_unlock_bh(&ar->data_lock);
4009 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4011 memset(&arg, 0, sizeof(arg));
4012 ath10k_wmi_start_scan_init(ar, &arg);
4013 arg.vdev_id = arvif->vdev_id;
4014 arg.scan_id = ATH10K_SCAN_ID;
4016 arg.channels[0] = chan->center_freq;
4017 arg.dwell_time_active = duration;
4018 arg.dwell_time_passive = duration;
4019 arg.max_scan_time = 2 * duration;
4020 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4021 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4023 ret = ath10k_start_scan(ar, &arg);
4025 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
4026 spin_lock_bh(&ar->data_lock);
4027 ar->scan.state = ATH10K_SCAN_IDLE;
4028 spin_unlock_bh(&ar->data_lock);
4032 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4034 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
4036 ret = ath10k_scan_stop(ar);
4038 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4046 mutex_unlock(&ar->conf_mutex);
4050 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4052 struct ath10k *ar = hw->priv;
4054 mutex_lock(&ar->conf_mutex);
4055 ath10k_scan_abort(ar);
4056 mutex_unlock(&ar->conf_mutex);
4058 cancel_delayed_work_sync(&ar->scan.timeout);
4064 * Both RTS and Fragmentation threshold are interface-specific
4065 * in ath10k, but device-specific in mac80211.
4068 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4070 struct ath10k *ar = hw->priv;
4071 struct ath10k_vif *arvif;
4074 mutex_lock(&ar->conf_mutex);
4075 list_for_each_entry(arvif, &ar->arvifs, list) {
4076 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
4077 arvif->vdev_id, value);
4079 ret = ath10k_mac_set_rts(arvif, value);
4081 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4082 arvif->vdev_id, ret);
4086 mutex_unlock(&ar->conf_mutex);
4091 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4092 u32 queues, bool drop)
4094 struct ath10k *ar = hw->priv;
4098 /* mac80211 doesn't care if we really xmit queued frames or not
4099 * we'll collect those frames either way if we stop/delete vdevs */
4103 mutex_lock(&ar->conf_mutex);
4105 if (ar->state == ATH10K_STATE_WEDGED)
4108 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
4111 spin_lock_bh(&ar->htt.tx_lock);
4112 empty = (ar->htt.num_pending_tx == 0);
4113 spin_unlock_bh(&ar->htt.tx_lock);
4115 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4116 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4120 }), ATH10K_FLUSH_TIMEOUT_HZ);
4122 if (ret <= 0 || skip)
4123 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4124 skip, ar->state, ret);
4127 mutex_unlock(&ar->conf_mutex);
4130 /* TODO: Implement this function properly
4131 * For now it is needed to reply to Probe Requests in IBSS mode.
4132 * Propably we need this information from FW.
4134 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4140 static int ath10k_suspend(struct ieee80211_hw *hw,
4141 struct cfg80211_wowlan *wowlan)
4143 struct ath10k *ar = hw->priv;
4146 mutex_lock(&ar->conf_mutex);
4148 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
4150 if (ret == -ETIMEDOUT)
4156 ret = ath10k_hif_suspend(ar);
4158 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
4165 ret = ath10k_wmi_pdev_resume_target(ar);
4167 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4171 mutex_unlock(&ar->conf_mutex);
4175 static int ath10k_resume(struct ieee80211_hw *hw)
4177 struct ath10k *ar = hw->priv;
4180 mutex_lock(&ar->conf_mutex);
4182 ret = ath10k_hif_resume(ar);
4184 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
4189 ret = ath10k_wmi_pdev_resume_target(ar);
4191 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4198 mutex_unlock(&ar->conf_mutex);
4203 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4204 enum ieee80211_reconfig_type reconfig_type)
4206 struct ath10k *ar = hw->priv;
4208 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4211 mutex_lock(&ar->conf_mutex);
4213 /* If device failed to restart it will be in a different state, e.g.
4214 * ATH10K_STATE_WEDGED */
4215 if (ar->state == ATH10K_STATE_RESTARTED) {
4216 ath10k_info(ar, "device successfully recovered\n");
4217 ar->state = ATH10K_STATE_ON;
4218 ieee80211_wake_queues(ar->hw);
4221 mutex_unlock(&ar->conf_mutex);
4224 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4225 struct survey_info *survey)
4227 struct ath10k *ar = hw->priv;
4228 struct ieee80211_supported_band *sband;
4229 struct survey_info *ar_survey = &ar->survey[idx];
4232 mutex_lock(&ar->conf_mutex);
4234 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4235 if (sband && idx >= sband->n_channels) {
4236 idx -= sband->n_channels;
4241 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4243 if (!sband || idx >= sband->n_channels) {
4248 spin_lock_bh(&ar->data_lock);
4249 memcpy(survey, ar_survey, sizeof(*survey));
4250 spin_unlock_bh(&ar->data_lock);
4252 survey->channel = &sband->channels[idx];
4254 if (ar->rx_channel == survey->channel)
4255 survey->filled |= SURVEY_INFO_IN_USE;
4258 mutex_unlock(&ar->conf_mutex);
4262 /* Helper table for legacy fixed_rate/bitrate_mask */
4263 static const u8 cck_ofdm_rate[] = {
4280 /* Check if only one bit set */
4281 static int ath10k_check_single_mask(u32 mask)
4289 mask &= ~BIT(bit - 1);
4297 ath10k_default_bitrate_mask(struct ath10k *ar,
4298 enum ieee80211_band band,
4299 const struct cfg80211_bitrate_mask *mask)
4301 u32 legacy = 0x00ff;
4304 u16 nrf = ar->num_rf_chains;
4306 if (ar->cfg_tx_chainmask)
4307 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4310 case IEEE80211_BAND_2GHZ:
4314 case IEEE80211_BAND_5GHZ:
4320 if (mask->control[band].legacy != legacy)
4323 for (i = 0; i < nrf; i++)
4324 if (mask->control[band].ht_mcs[i] != ht)
4327 for (i = 0; i < nrf; i++)
4328 if (mask->control[band].vht_mcs[i] != vht)
4335 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4336 enum ieee80211_band band,
4339 int ht_nss = 0, vht_nss = 0, i;
4342 if (ath10k_check_single_mask(mask->control[band].legacy))
4346 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4347 if (mask->control[band].ht_mcs[i] == 0xff)
4349 else if (mask->control[band].ht_mcs[i] == 0x00)
4358 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4359 if (mask->control[band].vht_mcs[i] == 0x03ff)
4361 else if (mask->control[band].vht_mcs[i] == 0x0000)
4369 if (ht_nss > 0 && vht_nss > 0)
4373 *fixed_nss = ht_nss;
4375 *fixed_nss = vht_nss;
4383 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4384 enum ieee80211_band band,
4385 enum wmi_rate_preamble *preamble)
4387 int legacy = 0, ht = 0, vht = 0, i;
4389 *preamble = WMI_RATE_PREAMBLE_OFDM;
4392 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4397 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4398 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4403 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4404 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4408 /* Currently we support only one fixed_rate */
4409 if ((legacy + ht + vht) != 1)
4413 *preamble = WMI_RATE_PREAMBLE_HT;
4415 *preamble = WMI_RATE_PREAMBLE_VHT;
4421 ath10k_bitrate_mask_rate(struct ath10k *ar,
4422 const struct cfg80211_bitrate_mask *mask,
4423 enum ieee80211_band band,
4427 u8 rate = 0, pream = 0, nss = 0, i;
4428 enum wmi_rate_preamble preamble;
4430 /* Check if single rate correct */
4431 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4437 case WMI_RATE_PREAMBLE_CCK:
4438 case WMI_RATE_PREAMBLE_OFDM:
4439 i = ffs(mask->control[band].legacy) - 1;
4441 if (band == IEEE80211_BAND_2GHZ && i < 4)
4442 pream = WMI_RATE_PREAMBLE_CCK;
4444 if (band == IEEE80211_BAND_5GHZ)
4447 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4450 rate = cck_ofdm_rate[i];
4452 case WMI_RATE_PREAMBLE_HT:
4453 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4454 if (mask->control[band].ht_mcs[i])
4457 if (i == IEEE80211_HT_MCS_MASK_LEN)
4460 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4463 case WMI_RATE_PREAMBLE_VHT:
4464 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4465 if (mask->control[band].vht_mcs[i])
4468 if (i == NL80211_VHT_NSS_MAX)
4471 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4476 *fixed_nss = nss + 1;
4480 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4483 *fixed_rate = pream | nss | rate;
4488 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4489 const struct cfg80211_bitrate_mask *mask,
4490 enum ieee80211_band band,
4494 /* First check full NSS mask, if we can simply limit NSS */
4495 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4498 /* Next Check single rate is set */
4499 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4502 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4507 struct ath10k *ar = arvif->ar;
4511 mutex_lock(&ar->conf_mutex);
4513 if (arvif->fixed_rate == fixed_rate &&
4514 arvif->fixed_nss == fixed_nss &&
4515 arvif->force_sgi == force_sgi)
4518 if (fixed_rate == WMI_FIXED_RATE_NONE)
4519 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4522 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4524 vdev_param = ar->wmi.vdev_param->fixed_rate;
4525 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4526 vdev_param, fixed_rate);
4528 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4534 arvif->fixed_rate = fixed_rate;
4536 vdev_param = ar->wmi.vdev_param->nss;
4537 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4538 vdev_param, fixed_nss);
4541 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4547 arvif->fixed_nss = fixed_nss;
4549 vdev_param = ar->wmi.vdev_param->sgi;
4550 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4554 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4560 arvif->force_sgi = force_sgi;
4563 mutex_unlock(&ar->conf_mutex);
4567 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4568 struct ieee80211_vif *vif,
4569 const struct cfg80211_bitrate_mask *mask)
4571 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4572 struct ath10k *ar = arvif->ar;
4573 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4574 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4575 u8 fixed_nss = ar->num_rf_chains;
4578 if (ar->cfg_tx_chainmask)
4579 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4581 force_sgi = mask->control[band].gi;
4582 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4585 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4586 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4592 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4593 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4597 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4598 fixed_nss, force_sgi);
4601 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4602 struct ieee80211_vif *vif,
4603 struct ieee80211_sta *sta,
4606 struct ath10k *ar = hw->priv;
4607 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4610 spin_lock_bh(&ar->data_lock);
4612 ath10k_dbg(ar, ATH10K_DBG_MAC,
4613 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4614 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4617 if (changed & IEEE80211_RC_BW_CHANGED) {
4618 bw = WMI_PEER_CHWIDTH_20MHZ;
4620 switch (sta->bandwidth) {
4621 case IEEE80211_STA_RX_BW_20:
4622 bw = WMI_PEER_CHWIDTH_20MHZ;
4624 case IEEE80211_STA_RX_BW_40:
4625 bw = WMI_PEER_CHWIDTH_40MHZ;
4627 case IEEE80211_STA_RX_BW_80:
4628 bw = WMI_PEER_CHWIDTH_80MHZ;
4630 case IEEE80211_STA_RX_BW_160:
4631 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4632 sta->bandwidth, sta->addr);
4633 bw = WMI_PEER_CHWIDTH_20MHZ;
4640 if (changed & IEEE80211_RC_NSS_CHANGED)
4641 arsta->nss = sta->rx_nss;
4643 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4644 smps = WMI_PEER_SMPS_PS_NONE;
4646 switch (sta->smps_mode) {
4647 case IEEE80211_SMPS_AUTOMATIC:
4648 case IEEE80211_SMPS_OFF:
4649 smps = WMI_PEER_SMPS_PS_NONE;
4651 case IEEE80211_SMPS_STATIC:
4652 smps = WMI_PEER_SMPS_STATIC;
4654 case IEEE80211_SMPS_DYNAMIC:
4655 smps = WMI_PEER_SMPS_DYNAMIC;
4657 case IEEE80211_SMPS_NUM_MODES:
4658 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4659 sta->smps_mode, sta->addr);
4660 smps = WMI_PEER_SMPS_PS_NONE;
4667 arsta->changed |= changed;
4669 spin_unlock_bh(&ar->data_lock);
4671 ieee80211_queue_work(hw, &arsta->update_wk);
4674 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4677 * FIXME: Return 0 for time being. Need to figure out whether FW
4678 * has the API to fetch 64-bit local TSF
4684 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4685 struct ieee80211_vif *vif,
4686 enum ieee80211_ampdu_mlme_action action,
4687 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4690 struct ath10k *ar = hw->priv;
4691 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4693 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4694 arvif->vdev_id, sta->addr, tid, action);
4697 case IEEE80211_AMPDU_RX_START:
4698 case IEEE80211_AMPDU_RX_STOP:
4699 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4700 * creation/removal. Do we need to verify this?
4703 case IEEE80211_AMPDU_TX_START:
4704 case IEEE80211_AMPDU_TX_STOP_CONT:
4705 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4706 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4707 case IEEE80211_AMPDU_TX_OPERATIONAL:
4708 /* Firmware offloads Tx aggregation entirely so deny mac80211
4709 * Tx aggregation requests.
4717 static const struct ieee80211_ops ath10k_ops = {
4719 .start = ath10k_start,
4720 .stop = ath10k_stop,
4721 .config = ath10k_config,
4722 .add_interface = ath10k_add_interface,
4723 .remove_interface = ath10k_remove_interface,
4724 .configure_filter = ath10k_configure_filter,
4725 .bss_info_changed = ath10k_bss_info_changed,
4726 .hw_scan = ath10k_hw_scan,
4727 .cancel_hw_scan = ath10k_cancel_hw_scan,
4728 .set_key = ath10k_set_key,
4729 .sta_state = ath10k_sta_state,
4730 .conf_tx = ath10k_conf_tx,
4731 .remain_on_channel = ath10k_remain_on_channel,
4732 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4733 .set_rts_threshold = ath10k_set_rts_threshold,
4734 .flush = ath10k_flush,
4735 .tx_last_beacon = ath10k_tx_last_beacon,
4736 .set_antenna = ath10k_set_antenna,
4737 .get_antenna = ath10k_get_antenna,
4738 .reconfig_complete = ath10k_reconfig_complete,
4739 .get_survey = ath10k_get_survey,
4740 .set_bitrate_mask = ath10k_set_bitrate_mask,
4741 .sta_rc_update = ath10k_sta_rc_update,
4742 .get_tsf = ath10k_get_tsf,
4743 .ampdu_action = ath10k_ampdu_action,
4744 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4745 .get_et_stats = ath10k_debug_get_et_stats,
4746 .get_et_strings = ath10k_debug_get_et_strings,
4748 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4751 .suspend = ath10k_suspend,
4752 .resume = ath10k_resume,
4756 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4757 .bitrate = (_rate), \
4758 .flags = (_flags), \
4759 .hw_value = (_rateid), \
4762 #define CHAN2G(_channel, _freq, _flags) { \
4763 .band = IEEE80211_BAND_2GHZ, \
4764 .hw_value = (_channel), \
4765 .center_freq = (_freq), \
4766 .flags = (_flags), \
4767 .max_antenna_gain = 0, \
4771 #define CHAN5G(_channel, _freq, _flags) { \
4772 .band = IEEE80211_BAND_5GHZ, \
4773 .hw_value = (_channel), \
4774 .center_freq = (_freq), \
4775 .flags = (_flags), \
4776 .max_antenna_gain = 0, \
4780 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4790 CHAN2G(10, 2457, 0),
4791 CHAN2G(11, 2462, 0),
4792 CHAN2G(12, 2467, 0),
4793 CHAN2G(13, 2472, 0),
4794 CHAN2G(14, 2484, 0),
4797 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4798 CHAN5G(36, 5180, 0),
4799 CHAN5G(40, 5200, 0),
4800 CHAN5G(44, 5220, 0),
4801 CHAN5G(48, 5240, 0),
4802 CHAN5G(52, 5260, 0),
4803 CHAN5G(56, 5280, 0),
4804 CHAN5G(60, 5300, 0),
4805 CHAN5G(64, 5320, 0),
4806 CHAN5G(100, 5500, 0),
4807 CHAN5G(104, 5520, 0),
4808 CHAN5G(108, 5540, 0),
4809 CHAN5G(112, 5560, 0),
4810 CHAN5G(116, 5580, 0),
4811 CHAN5G(120, 5600, 0),
4812 CHAN5G(124, 5620, 0),
4813 CHAN5G(128, 5640, 0),
4814 CHAN5G(132, 5660, 0),
4815 CHAN5G(136, 5680, 0),
4816 CHAN5G(140, 5700, 0),
4817 CHAN5G(149, 5745, 0),
4818 CHAN5G(153, 5765, 0),
4819 CHAN5G(157, 5785, 0),
4820 CHAN5G(161, 5805, 0),
4821 CHAN5G(165, 5825, 0),
4824 /* Note: Be careful if you re-order these. There is code which depends on this
4827 static struct ieee80211_rate ath10k_rates[] = {
4829 RATETAB_ENT(10, 0x82, 0),
4830 RATETAB_ENT(20, 0x84, 0),
4831 RATETAB_ENT(55, 0x8b, 0),
4832 RATETAB_ENT(110, 0x96, 0),
4834 RATETAB_ENT(60, 0x0c, 0),
4835 RATETAB_ENT(90, 0x12, 0),
4836 RATETAB_ENT(120, 0x18, 0),
4837 RATETAB_ENT(180, 0x24, 0),
4838 RATETAB_ENT(240, 0x30, 0),
4839 RATETAB_ENT(360, 0x48, 0),
4840 RATETAB_ENT(480, 0x60, 0),
4841 RATETAB_ENT(540, 0x6c, 0),
4844 #define ath10k_a_rates (ath10k_rates + 4)
4845 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4846 #define ath10k_g_rates (ath10k_rates + 0)
4847 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4849 struct ath10k *ath10k_mac_create(size_t priv_size)
4851 struct ieee80211_hw *hw;
4854 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4864 void ath10k_mac_destroy(struct ath10k *ar)
4866 ieee80211_free_hw(ar->hw);
4869 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4872 .types = BIT(NL80211_IFTYPE_STATION)
4873 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4877 .types = BIT(NL80211_IFTYPE_P2P_GO)
4881 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
4885 .types = BIT(NL80211_IFTYPE_AP)
4889 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4892 .types = BIT(NL80211_IFTYPE_AP)
4896 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4898 .limits = ath10k_if_limits,
4899 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4900 .max_interfaces = 8,
4901 .num_different_channels = 1,
4902 .beacon_int_infra_match = true,
4906 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4908 .limits = ath10k_10x_if_limits,
4909 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4910 .max_interfaces = 8,
4911 .num_different_channels = 1,
4912 .beacon_int_infra_match = true,
4913 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4914 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4915 BIT(NL80211_CHAN_WIDTH_20) |
4916 BIT(NL80211_CHAN_WIDTH_40) |
4917 BIT(NL80211_CHAN_WIDTH_80),
4922 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4924 struct ieee80211_sta_vht_cap vht_cap = {0};
4928 vht_cap.vht_supported = 1;
4929 vht_cap.cap = ar->vht_cap_info;
4932 for (i = 0; i < 8; i++) {
4933 if (i < ar->num_rf_chains)
4934 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4936 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4939 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4940 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4945 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4948 struct ieee80211_sta_ht_cap ht_cap = {0};
4950 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4953 ht_cap.ht_supported = 1;
4954 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4955 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4956 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4957 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4958 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4960 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4961 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4963 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4964 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4966 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4969 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4970 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4975 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4976 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4978 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4981 stbc = ar->ht_cap_info;
4982 stbc &= WMI_HT_CAP_RX_STBC;
4983 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4984 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4985 stbc &= IEEE80211_HT_CAP_RX_STBC;
4990 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4991 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4993 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4994 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4996 /* max AMSDU is implicitly taken from vht_cap_info */
4997 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4998 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5000 for (i = 0; i < ar->num_rf_chains; i++)
5001 ht_cap.mcs.rx_mask[i] = 0xFF;
5003 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5008 static void ath10k_get_arvif_iter(void *data, u8 *mac,
5009 struct ieee80211_vif *vif)
5011 struct ath10k_vif_iter *arvif_iter = data;
5012 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5014 if (arvif->vdev_id == arvif_iter->vdev_id)
5015 arvif_iter->arvif = arvif;
5018 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5020 struct ath10k_vif_iter arvif_iter;
5023 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5024 arvif_iter.vdev_id = vdev_id;
5026 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5027 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5029 ath10k_get_arvif_iter,
5031 if (!arvif_iter.arvif) {
5032 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
5036 return arvif_iter.arvif;
5039 int ath10k_mac_register(struct ath10k *ar)
5041 static const u32 cipher_suites[] = {
5042 WLAN_CIPHER_SUITE_WEP40,
5043 WLAN_CIPHER_SUITE_WEP104,
5044 WLAN_CIPHER_SUITE_TKIP,
5045 WLAN_CIPHER_SUITE_CCMP,
5046 WLAN_CIPHER_SUITE_AES_CMAC,
5048 struct ieee80211_supported_band *band;
5049 struct ieee80211_sta_vht_cap vht_cap;
5050 struct ieee80211_sta_ht_cap ht_cap;
5054 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5056 SET_IEEE80211_DEV(ar->hw, ar->dev);
5058 ht_cap = ath10k_get_ht_cap(ar);
5059 vht_cap = ath10k_create_vht_cap(ar);
5061 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5062 channels = kmemdup(ath10k_2ghz_channels,
5063 sizeof(ath10k_2ghz_channels),
5070 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5071 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5072 band->channels = channels;
5073 band->n_bitrates = ath10k_g_rates_size;
5074 band->bitrates = ath10k_g_rates;
5075 band->ht_cap = ht_cap;
5077 /* vht is not supported in 2.4 GHz */
5079 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5082 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5083 channels = kmemdup(ath10k_5ghz_channels,
5084 sizeof(ath10k_5ghz_channels),
5091 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5092 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5093 band->channels = channels;
5094 band->n_bitrates = ath10k_a_rates_size;
5095 band->bitrates = ath10k_a_rates;
5096 band->ht_cap = ht_cap;
5097 band->vht_cap = vht_cap;
5098 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5101 ar->hw->wiphy->interface_modes =
5102 BIT(NL80211_IFTYPE_STATION) |
5103 BIT(NL80211_IFTYPE_AP);
5105 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5106 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5108 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5109 ar->hw->wiphy->interface_modes |=
5110 BIT(NL80211_IFTYPE_P2P_DEVICE) |
5111 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5112 BIT(NL80211_IFTYPE_P2P_GO);
5114 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5115 IEEE80211_HW_SUPPORTS_PS |
5116 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5117 IEEE80211_HW_MFP_CAPABLE |
5118 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5119 IEEE80211_HW_HAS_RATE_CONTROL |
5120 IEEE80211_HW_AP_LINK_PS |
5121 IEEE80211_HW_SPECTRUM_MGMT |
5122 IEEE80211_HW_SW_CRYPTO_CONTROL;
5124 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5126 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5127 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
5129 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5130 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5131 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5134 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5135 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5137 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
5138 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5140 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5142 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
5143 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5144 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5146 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5147 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5150 * on LL hardware queues are managed entirely by the FW
5151 * so we only advertise to mac we can do the queues thing
5155 switch (ar->wmi.op_version) {
5156 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5157 case ATH10K_FW_WMI_OP_VERSION_TLV:
5158 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5159 ar->hw->wiphy->n_iface_combinations =
5160 ARRAY_SIZE(ath10k_if_comb);
5161 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
5163 case ATH10K_FW_WMI_OP_VERSION_10_1:
5164 case ATH10K_FW_WMI_OP_VERSION_10_2:
5165 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
5166 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5167 ar->hw->wiphy->n_iface_combinations =
5168 ARRAY_SIZE(ath10k_10x_if_comb);
5170 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5171 case ATH10K_FW_WMI_OP_VERSION_MAX:
5177 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5179 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5180 /* Init ath dfs pattern detector */
5181 ar->ath_common.debug_mask = ATH_DBG_DFS;
5182 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5185 if (!ar->dfs_detector)
5186 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
5189 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5190 ath10k_reg_notifier);
5192 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
5196 ar->hw->wiphy->cipher_suites = cipher_suites;
5197 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5199 ret = ieee80211_register_hw(ar->hw);
5201 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
5205 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5206 ret = regulatory_hint(ar->hw->wiphy,
5207 ar->ath_common.regulatory.alpha2);
5209 goto err_unregister;
5215 ieee80211_unregister_hw(ar->hw);
5217 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5218 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5223 void ath10k_mac_unregister(struct ath10k *ar)
5225 ieee80211_unregister_hw(ar->hw);
5227 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5228 ar->dfs_detector->exit(ar->dfs_detector);
5230 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5231 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5233 SET_IEEE80211_DEV(ar->hw, NULL);