2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
37 static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
42 struct ath10k *ar = arvif->ar;
43 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
51 lockdep_assert_held(&arvif->ar->conf_mutex);
53 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
56 arg.key_flags = WMI_KEY_GROUP;
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
61 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
62 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
64 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
66 case WLAN_CIPHER_SUITE_TKIP:
67 arg.key_cipher = WMI_CIPHER_TKIP;
68 arg.key_txmic_len = 8;
69 arg.key_rxmic_len = 8;
71 case WLAN_CIPHER_SUITE_WEP40:
72 case WLAN_CIPHER_SUITE_WEP104:
73 arg.key_cipher = WMI_CIPHER_WEP;
74 /* AP/IBSS mode requires self-key to be groupwise
75 * Otherwise pairwise key must be set */
76 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
77 arg.key_flags = WMI_KEY_PAIRWISE;
80 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
84 if (cmd == DISABLE_KEY) {
85 arg.key_cipher = WMI_CIPHER_NONE;
89 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
92 static int ath10k_install_key(struct ath10k_vif *arvif,
93 struct ieee80211_key_conf *key,
97 struct ath10k *ar = arvif->ar;
100 lockdep_assert_held(&ar->conf_mutex);
102 reinit_completion(&ar->install_key_done);
104 ret = ath10k_send_key(arvif, key, cmd, macaddr);
108 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
115 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
118 struct ath10k *ar = arvif->ar;
119 struct ath10k_peer *peer;
123 lockdep_assert_held(&ar->conf_mutex);
125 spin_lock_bh(&ar->data_lock);
126 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
127 spin_unlock_bh(&ar->data_lock);
132 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
133 if (arvif->wep_keys[i] == NULL)
136 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
141 spin_lock_bh(&ar->data_lock);
142 peer->keys[i] = arvif->wep_keys[i];
143 spin_unlock_bh(&ar->data_lock);
149 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
152 struct ath10k *ar = arvif->ar;
153 struct ath10k_peer *peer;
158 lockdep_assert_held(&ar->conf_mutex);
160 spin_lock_bh(&ar->data_lock);
161 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
162 spin_unlock_bh(&ar->data_lock);
167 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
168 if (peer->keys[i] == NULL)
171 ret = ath10k_install_key(arvif, peer->keys[i],
173 if (ret && first_errno == 0)
177 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
180 spin_lock_bh(&ar->data_lock);
181 peer->keys[i] = NULL;
182 spin_unlock_bh(&ar->data_lock);
188 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
191 struct ath10k_peer *peer;
194 lockdep_assert_held(&ar->data_lock);
196 /* We don't know which vdev this peer belongs to,
197 * since WMI doesn't give us that information.
199 * FIXME: multi-bss needs to be handled.
201 peer = ath10k_peer_find(ar, 0, addr);
205 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
206 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
213 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
214 struct ieee80211_key_conf *key)
216 struct ath10k *ar = arvif->ar;
217 struct ath10k_peer *peer;
223 lockdep_assert_held(&ar->conf_mutex);
226 /* since ath10k_install_key we can't hold data_lock all the
227 * time, so we try to remove the keys incrementally */
228 spin_lock_bh(&ar->data_lock);
230 list_for_each_entry(peer, &ar->peers, list) {
231 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
232 if (peer->keys[i] == key) {
233 ether_addr_copy(addr, peer->addr);
234 peer->keys[i] = NULL;
239 if (i < ARRAY_SIZE(peer->keys))
242 spin_unlock_bh(&ar->data_lock);
244 if (i == ARRAY_SIZE(peer->keys))
247 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
248 if (ret && first_errno == 0)
252 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
259 /*********************/
260 /* General utilities */
261 /*********************/
263 static inline enum wmi_phy_mode
264 chan_to_phymode(const struct cfg80211_chan_def *chandef)
266 enum wmi_phy_mode phymode = MODE_UNKNOWN;
268 switch (chandef->chan->band) {
269 case IEEE80211_BAND_2GHZ:
270 switch (chandef->width) {
271 case NL80211_CHAN_WIDTH_20_NOHT:
272 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
277 case NL80211_CHAN_WIDTH_20:
278 phymode = MODE_11NG_HT20;
280 case NL80211_CHAN_WIDTH_40:
281 phymode = MODE_11NG_HT40;
283 case NL80211_CHAN_WIDTH_5:
284 case NL80211_CHAN_WIDTH_10:
285 case NL80211_CHAN_WIDTH_80:
286 case NL80211_CHAN_WIDTH_80P80:
287 case NL80211_CHAN_WIDTH_160:
288 phymode = MODE_UNKNOWN;
292 case IEEE80211_BAND_5GHZ:
293 switch (chandef->width) {
294 case NL80211_CHAN_WIDTH_20_NOHT:
297 case NL80211_CHAN_WIDTH_20:
298 phymode = MODE_11NA_HT20;
300 case NL80211_CHAN_WIDTH_40:
301 phymode = MODE_11NA_HT40;
303 case NL80211_CHAN_WIDTH_80:
304 phymode = MODE_11AC_VHT80;
306 case NL80211_CHAN_WIDTH_5:
307 case NL80211_CHAN_WIDTH_10:
308 case NL80211_CHAN_WIDTH_80P80:
309 case NL80211_CHAN_WIDTH_160:
310 phymode = MODE_UNKNOWN;
318 WARN_ON(phymode == MODE_UNKNOWN);
322 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
325 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
326 * 0 for no restriction
335 switch (mpdudensity) {
341 /* Our lower layer calculations limit our precision to
357 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
361 lockdep_assert_held(&ar->conf_mutex);
363 if (ar->num_peers >= ar->max_num_peers)
366 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
368 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
373 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
375 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
385 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
387 struct ath10k *ar = arvif->ar;
391 param = ar->wmi.pdev_param->sta_kickout_th;
392 ret = ath10k_wmi_pdev_set_param(ar, param,
393 ATH10K_KICKOUT_THRESHOLD);
395 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
396 arvif->vdev_id, ret);
400 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
401 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
402 ATH10K_KEEPALIVE_MIN_IDLE);
404 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
405 arvif->vdev_id, ret);
409 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
410 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
411 ATH10K_KEEPALIVE_MAX_IDLE);
413 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
414 arvif->vdev_id, ret);
418 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
419 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
420 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
422 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
423 arvif->vdev_id, ret);
430 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
432 struct ath10k *ar = arvif->ar;
435 vdev_param = ar->wmi.vdev_param->rts_threshold;
436 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
439 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
441 struct ath10k *ar = arvif->ar;
444 if (value != 0xFFFFFFFF)
445 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
446 ATH10K_FRAGMT_THRESHOLD_MIN,
447 ATH10K_FRAGMT_THRESHOLD_MAX);
449 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
450 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
453 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
457 lockdep_assert_held(&ar->conf_mutex);
459 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
463 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
472 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
474 struct ath10k_peer *peer, *tmp;
476 lockdep_assert_held(&ar->conf_mutex);
478 spin_lock_bh(&ar->data_lock);
479 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
480 if (peer->vdev_id != vdev_id)
483 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
484 peer->addr, vdev_id);
486 list_del(&peer->list);
490 spin_unlock_bh(&ar->data_lock);
493 static void ath10k_peer_cleanup_all(struct ath10k *ar)
495 struct ath10k_peer *peer, *tmp;
497 lockdep_assert_held(&ar->conf_mutex);
499 spin_lock_bh(&ar->data_lock);
500 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
501 list_del(&peer->list);
504 spin_unlock_bh(&ar->data_lock);
507 ar->num_stations = 0;
510 /************************/
511 /* Interface management */
512 /************************/
514 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
516 struct ath10k *ar = arvif->ar;
518 lockdep_assert_held(&ar->data_lock);
523 if (!arvif->beacon_buf)
524 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
525 arvif->beacon->len, DMA_TO_DEVICE);
527 dev_kfree_skb_any(arvif->beacon);
529 arvif->beacon = NULL;
530 arvif->beacon_sent = false;
533 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
535 struct ath10k *ar = arvif->ar;
537 lockdep_assert_held(&ar->data_lock);
539 ath10k_mac_vif_beacon_free(arvif);
541 if (arvif->beacon_buf) {
542 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
543 arvif->beacon_buf, arvif->beacon_paddr);
544 arvif->beacon_buf = NULL;
548 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
552 lockdep_assert_held(&ar->conf_mutex);
554 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
557 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
558 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
565 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
567 struct cfg80211_chan_def *chandef = &ar->chandef;
568 struct ieee80211_channel *channel = chandef->chan;
569 struct wmi_vdev_start_request_arg arg = {};
572 lockdep_assert_held(&ar->conf_mutex);
574 arg.vdev_id = vdev_id;
575 arg.channel.freq = channel->center_freq;
576 arg.channel.band_center_freq1 = chandef->center_freq1;
578 /* TODO setup this dynamically, what in case we
579 don't have any vifs? */
580 arg.channel.mode = chan_to_phymode(chandef);
581 arg.channel.chan_radar =
582 !!(channel->flags & IEEE80211_CHAN_RADAR);
584 arg.channel.min_power = 0;
585 arg.channel.max_power = channel->max_power * 2;
586 arg.channel.max_reg_power = channel->max_reg_power * 2;
587 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
589 reinit_completion(&ar->vdev_setup_done);
591 ret = ath10k_wmi_vdev_start(ar, &arg);
593 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
598 ret = ath10k_vdev_setup_sync(ar);
600 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
605 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
607 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
612 ar->monitor_vdev_id = vdev_id;
614 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
615 ar->monitor_vdev_id);
619 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
621 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
622 ar->monitor_vdev_id, ret);
627 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
631 lockdep_assert_held(&ar->conf_mutex);
633 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
635 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
636 ar->monitor_vdev_id, ret);
638 reinit_completion(&ar->vdev_setup_done);
640 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
642 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
643 ar->monitor_vdev_id, ret);
645 ret = ath10k_vdev_setup_sync(ar);
647 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
648 ar->monitor_vdev_id, ret);
650 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
651 ar->monitor_vdev_id);
655 static int ath10k_monitor_vdev_create(struct ath10k *ar)
659 lockdep_assert_held(&ar->conf_mutex);
661 if (ar->free_vdev_map == 0) {
662 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
666 bit = __ffs64(ar->free_vdev_map);
668 ar->monitor_vdev_id = bit;
670 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
671 WMI_VDEV_TYPE_MONITOR,
674 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
675 ar->monitor_vdev_id, ret);
679 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
680 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
681 ar->monitor_vdev_id);
686 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
690 lockdep_assert_held(&ar->conf_mutex);
692 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
694 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
695 ar->monitor_vdev_id, ret);
699 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
701 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
702 ar->monitor_vdev_id);
706 static int ath10k_monitor_start(struct ath10k *ar)
710 lockdep_assert_held(&ar->conf_mutex);
712 ret = ath10k_monitor_vdev_create(ar);
714 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
718 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
720 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
721 ath10k_monitor_vdev_delete(ar);
725 ar->monitor_started = true;
726 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
731 static int ath10k_monitor_stop(struct ath10k *ar)
735 lockdep_assert_held(&ar->conf_mutex);
737 ret = ath10k_monitor_vdev_stop(ar);
739 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
743 ret = ath10k_monitor_vdev_delete(ar);
745 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
749 ar->monitor_started = false;
750 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
755 static int ath10k_monitor_recalc(struct ath10k *ar)
759 lockdep_assert_held(&ar->conf_mutex);
761 should_start = ar->monitor ||
762 ar->filter_flags & FIF_PROMISC_IN_BSS ||
763 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
765 ath10k_dbg(ar, ATH10K_DBG_MAC,
766 "mac monitor recalc started? %d should? %d\n",
767 ar->monitor_started, should_start);
769 if (should_start == ar->monitor_started)
773 return ath10k_monitor_start(ar);
775 return ath10k_monitor_stop(ar);
778 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
780 struct ath10k *ar = arvif->ar;
781 u32 vdev_param, rts_cts = 0;
783 lockdep_assert_held(&ar->conf_mutex);
785 vdev_param = ar->wmi.vdev_param->enable_rtscts;
787 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
788 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
790 if (arvif->num_legacy_stations > 0)
791 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
794 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
798 static int ath10k_start_cac(struct ath10k *ar)
802 lockdep_assert_held(&ar->conf_mutex);
804 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
806 ret = ath10k_monitor_recalc(ar);
808 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
809 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
813 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
814 ar->monitor_vdev_id);
819 static int ath10k_stop_cac(struct ath10k *ar)
821 lockdep_assert_held(&ar->conf_mutex);
823 /* CAC is not running - do nothing */
824 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
827 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
828 ath10k_monitor_stop(ar);
830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
835 static void ath10k_recalc_radar_detection(struct ath10k *ar)
839 lockdep_assert_held(&ar->conf_mutex);
843 if (!ar->radar_enabled)
846 if (ar->num_started_vdevs > 0)
849 ret = ath10k_start_cac(ar);
852 * Not possible to start CAC on current channel so starting
853 * radiation is not allowed, make this channel DFS_UNAVAILABLE
854 * by indicating that radar was detected.
856 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
857 ieee80211_radar_detected(ar->hw);
861 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
863 struct ath10k *ar = arvif->ar;
864 struct cfg80211_chan_def *chandef = &ar->chandef;
865 struct wmi_vdev_start_request_arg arg = {};
868 lockdep_assert_held(&ar->conf_mutex);
870 reinit_completion(&ar->vdev_setup_done);
872 arg.vdev_id = arvif->vdev_id;
873 arg.dtim_period = arvif->dtim_period;
874 arg.bcn_intval = arvif->beacon_interval;
876 arg.channel.freq = chandef->chan->center_freq;
877 arg.channel.band_center_freq1 = chandef->center_freq1;
878 arg.channel.mode = chan_to_phymode(chandef);
880 arg.channel.min_power = 0;
881 arg.channel.max_power = chandef->chan->max_power * 2;
882 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
883 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
885 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
886 arg.ssid = arvif->u.ap.ssid;
887 arg.ssid_len = arvif->u.ap.ssid_len;
888 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
890 /* For now allow DFS for AP mode */
891 arg.channel.chan_radar =
892 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
893 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
894 arg.ssid = arvif->vif->bss_conf.ssid;
895 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
898 ath10k_dbg(ar, ATH10K_DBG_MAC,
899 "mac vdev %d start center_freq %d phymode %s\n",
900 arg.vdev_id, arg.channel.freq,
901 ath10k_wmi_phymode_str(arg.channel.mode));
904 ret = ath10k_wmi_vdev_restart(ar, &arg);
906 ret = ath10k_wmi_vdev_start(ar, &arg);
909 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
914 ret = ath10k_vdev_setup_sync(ar);
916 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
921 ar->num_started_vdevs++;
922 ath10k_recalc_radar_detection(ar);
927 static int ath10k_vdev_start(struct ath10k_vif *arvif)
929 return ath10k_vdev_start_restart(arvif, false);
932 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
934 return ath10k_vdev_start_restart(arvif, true);
937 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
939 struct ath10k *ar = arvif->ar;
942 lockdep_assert_held(&ar->conf_mutex);
944 reinit_completion(&ar->vdev_setup_done);
946 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
948 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
949 arvif->vdev_id, ret);
953 ret = ath10k_vdev_setup_sync(ar);
955 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
956 arvif->vdev_id, ret);
960 WARN_ON(ar->num_started_vdevs == 0);
962 if (ar->num_started_vdevs != 0) {
963 ar->num_started_vdevs--;
964 ath10k_recalc_radar_detection(ar);
970 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
971 struct ieee80211_bss_conf *info)
973 struct ath10k *ar = arvif->ar;
976 lockdep_assert_held(&arvif->ar->conf_mutex);
978 if (!info->enable_beacon) {
979 ath10k_vdev_stop(arvif);
981 arvif->is_started = false;
982 arvif->is_up = false;
984 spin_lock_bh(&arvif->ar->data_lock);
985 ath10k_mac_vif_beacon_free(arvif);
986 spin_unlock_bh(&arvif->ar->data_lock);
991 arvif->tx_seq_no = 0x1000;
993 ret = ath10k_vdev_start(arvif);
998 ether_addr_copy(arvif->bssid, info->bssid);
1000 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1003 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1004 arvif->vdev_id, ret);
1005 ath10k_vdev_stop(arvif);
1009 arvif->is_started = true;
1010 arvif->is_up = true;
1012 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1015 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1016 struct ieee80211_bss_conf *info,
1017 const u8 self_peer[ETH_ALEN])
1019 struct ath10k *ar = arvif->ar;
1023 lockdep_assert_held(&arvif->ar->conf_mutex);
1025 if (!info->ibss_joined) {
1026 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1028 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1029 self_peer, arvif->vdev_id, ret);
1031 if (is_zero_ether_addr(arvif->bssid))
1034 memset(arvif->bssid, 0, ETH_ALEN);
1039 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1041 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1042 self_peer, arvif->vdev_id, ret);
1046 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1047 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1048 ATH10K_DEFAULT_ATIM);
1050 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1051 arvif->vdev_id, ret);
1054 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1056 struct ath10k *ar = arvif->ar;
1061 lockdep_assert_held(&arvif->ar->conf_mutex);
1063 if (arvif->u.sta.uapsd)
1064 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1066 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1068 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1069 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1071 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1072 value, arvif->vdev_id, ret);
1079 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1081 struct ath10k *ar = arvif->ar;
1086 lockdep_assert_held(&arvif->ar->conf_mutex);
1088 if (arvif->u.sta.uapsd)
1089 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1091 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1093 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1094 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1097 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1098 value, arvif->vdev_id, ret);
1105 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1107 struct ath10k *ar = arvif->ar;
1108 struct ieee80211_vif *vif = arvif->vif;
1109 struct ieee80211_conf *conf = &ar->hw->conf;
1110 enum wmi_sta_powersave_param param;
1111 enum wmi_sta_ps_mode psmode;
1115 lockdep_assert_held(&arvif->ar->conf_mutex);
1117 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1120 if (vif->bss_conf.ps) {
1121 psmode = WMI_STA_PS_MODE_ENABLED;
1122 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1124 ps_timeout = conf->dynamic_ps_timeout;
1125 if (ps_timeout == 0) {
1126 /* Firmware doesn't like 0 */
1127 ps_timeout = ieee80211_tu_to_usec(
1128 vif->bss_conf.beacon_int) / 1000;
1131 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1134 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1135 arvif->vdev_id, ret);
1139 psmode = WMI_STA_PS_MODE_DISABLED;
1142 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1143 arvif->vdev_id, psmode ? "enable" : "disable");
1145 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1147 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1148 psmode, arvif->vdev_id, ret);
1155 /**********************/
1156 /* Station management */
1157 /**********************/
1159 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1160 struct ieee80211_vif *vif)
1162 /* Some firmware revisions have unstable STA powersave when listen
1163 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1164 * generate NullFunc frames properly even if buffered frames have been
1165 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1166 * buffered frames. Often pinging the device from AP would simply fail.
1168 * As a workaround set it to 1.
1170 if (vif->type == NL80211_IFTYPE_STATION)
1173 return ar->hw->conf.listen_interval;
1176 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1177 struct ieee80211_vif *vif,
1178 struct ieee80211_sta *sta,
1179 struct wmi_peer_assoc_complete_arg *arg)
1181 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1183 lockdep_assert_held(&ar->conf_mutex);
1185 ether_addr_copy(arg->addr, sta->addr);
1186 arg->vdev_id = arvif->vdev_id;
1187 arg->peer_aid = sta->aid;
1188 arg->peer_flags |= WMI_PEER_AUTH;
1189 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1190 arg->peer_num_spatial_streams = 1;
1191 arg->peer_caps = vif->bss_conf.assoc_capability;
1194 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1195 struct ieee80211_vif *vif,
1196 struct wmi_peer_assoc_complete_arg *arg)
1198 struct ieee80211_bss_conf *info = &vif->bss_conf;
1199 struct cfg80211_bss *bss;
1200 const u8 *rsnie = NULL;
1201 const u8 *wpaie = NULL;
1203 lockdep_assert_held(&ar->conf_mutex);
1205 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1206 info->bssid, NULL, 0, 0, 0);
1208 const struct cfg80211_bss_ies *ies;
1211 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1213 ies = rcu_dereference(bss->ies);
1215 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1216 WLAN_OUI_TYPE_MICROSOFT_WPA,
1220 cfg80211_put_bss(ar->hw->wiphy, bss);
1223 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1224 if (rsnie || wpaie) {
1225 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1226 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1230 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1231 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1235 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1236 struct ieee80211_sta *sta,
1237 struct wmi_peer_assoc_complete_arg *arg)
1239 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1240 const struct ieee80211_supported_band *sband;
1241 const struct ieee80211_rate *rates;
1245 lockdep_assert_held(&ar->conf_mutex);
1247 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1248 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1249 rates = sband->bitrates;
1251 rateset->num_rates = 0;
1253 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1254 if (!(ratemask & 1))
1257 rateset->rates[rateset->num_rates] = rates->hw_value;
1258 rateset->num_rates++;
1262 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1263 struct ieee80211_sta *sta,
1264 struct wmi_peer_assoc_complete_arg *arg)
1266 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1270 lockdep_assert_held(&ar->conf_mutex);
1272 if (!ht_cap->ht_supported)
1275 arg->peer_flags |= WMI_PEER_HT;
1276 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1277 ht_cap->ampdu_factor)) - 1;
1279 arg->peer_mpdu_density =
1280 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1282 arg->peer_ht_caps = ht_cap->cap;
1283 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1285 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1286 arg->peer_flags |= WMI_PEER_LDPC;
1288 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1289 arg->peer_flags |= WMI_PEER_40MHZ;
1290 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1293 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1294 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1296 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1297 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1299 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1300 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1301 arg->peer_flags |= WMI_PEER_STBC;
1304 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1305 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1306 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1307 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1308 arg->peer_rate_caps |= stbc;
1309 arg->peer_flags |= WMI_PEER_STBC;
1312 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1313 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1314 else if (ht_cap->mcs.rx_mask[1])
1315 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1317 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1318 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1319 arg->peer_ht_rates.rates[n++] = i;
1322 * This is a workaround for HT-enabled STAs which break the spec
1323 * and have no HT capabilities RX mask (no HT RX MCS map).
1325 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1326 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1328 * Firmware asserts if such situation occurs.
1331 arg->peer_ht_rates.num_rates = 8;
1332 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1333 arg->peer_ht_rates.rates[i] = i;
1335 arg->peer_ht_rates.num_rates = n;
1336 arg->peer_num_spatial_streams = sta->rx_nss;
1339 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1341 arg->peer_ht_rates.num_rates,
1342 arg->peer_num_spatial_streams);
1345 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1346 struct ath10k_vif *arvif,
1347 struct ieee80211_sta *sta)
1353 lockdep_assert_held(&ar->conf_mutex);
1355 if (sta->wme && sta->uapsd_queues) {
1356 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1357 sta->uapsd_queues, sta->max_sp);
1359 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1360 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1361 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1362 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1363 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1364 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1365 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1366 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1367 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1368 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1369 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1370 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1372 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1373 max_sp = sta->max_sp;
1375 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1377 WMI_AP_PS_PEER_PARAM_UAPSD,
1380 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1381 arvif->vdev_id, ret);
1385 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1387 WMI_AP_PS_PEER_PARAM_MAX_SP,
1390 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1391 arvif->vdev_id, ret);
1395 /* TODO setup this based on STA listen interval and
1396 beacon interval. Currently we don't know
1397 sta->listen_interval - mac80211 patch required.
1398 Currently use 10 seconds */
1399 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1400 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1403 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1404 arvif->vdev_id, ret);
1412 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1413 struct ieee80211_sta *sta,
1414 struct wmi_peer_assoc_complete_arg *arg)
1416 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1419 if (!vht_cap->vht_supported)
1422 arg->peer_flags |= WMI_PEER_VHT;
1423 arg->peer_vht_caps = vht_cap->cap;
1425 ampdu_factor = (vht_cap->cap &
1426 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1427 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1429 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1430 * zero in VHT IE. Using it would result in degraded throughput.
1431 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1432 * it if VHT max_mpdu is smaller. */
1433 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1434 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1435 ampdu_factor)) - 1);
1437 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1438 arg->peer_flags |= WMI_PEER_80MHZ;
1440 arg->peer_vht_rates.rx_max_rate =
1441 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1442 arg->peer_vht_rates.rx_mcs_set =
1443 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1444 arg->peer_vht_rates.tx_max_rate =
1445 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1446 arg->peer_vht_rates.tx_mcs_set =
1447 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1449 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1450 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1453 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1454 struct ieee80211_vif *vif,
1455 struct ieee80211_sta *sta,
1456 struct wmi_peer_assoc_complete_arg *arg)
1458 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1460 switch (arvif->vdev_type) {
1461 case WMI_VDEV_TYPE_AP:
1463 arg->peer_flags |= WMI_PEER_QOS;
1465 if (sta->wme && sta->uapsd_queues) {
1466 arg->peer_flags |= WMI_PEER_APSD;
1467 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1470 case WMI_VDEV_TYPE_STA:
1471 if (vif->bss_conf.qos)
1472 arg->peer_flags |= WMI_PEER_QOS;
1474 case WMI_VDEV_TYPE_IBSS:
1476 arg->peer_flags |= WMI_PEER_QOS;
1482 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1483 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
1486 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1488 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1489 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1492 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1493 struct ieee80211_vif *vif,
1494 struct ieee80211_sta *sta,
1495 struct wmi_peer_assoc_complete_arg *arg)
1497 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1499 switch (ar->hw->conf.chandef.chan->band) {
1500 case IEEE80211_BAND_2GHZ:
1501 if (sta->ht_cap.ht_supported) {
1502 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1503 phymode = MODE_11NG_HT40;
1505 phymode = MODE_11NG_HT20;
1506 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
1513 case IEEE80211_BAND_5GHZ:
1517 if (sta->vht_cap.vht_supported) {
1518 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1519 phymode = MODE_11AC_VHT80;
1520 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1521 phymode = MODE_11AC_VHT40;
1522 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1523 phymode = MODE_11AC_VHT20;
1524 } else if (sta->ht_cap.ht_supported) {
1525 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1526 phymode = MODE_11NA_HT40;
1528 phymode = MODE_11NA_HT20;
1538 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1539 sta->addr, ath10k_wmi_phymode_str(phymode));
1541 arg->peer_phymode = phymode;
1542 WARN_ON(phymode == MODE_UNKNOWN);
1545 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1546 struct ieee80211_vif *vif,
1547 struct ieee80211_sta *sta,
1548 struct wmi_peer_assoc_complete_arg *arg)
1550 lockdep_assert_held(&ar->conf_mutex);
1552 memset(arg, 0, sizeof(*arg));
1554 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1555 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1556 ath10k_peer_assoc_h_rates(ar, sta, arg);
1557 ath10k_peer_assoc_h_ht(ar, sta, arg);
1558 ath10k_peer_assoc_h_vht(ar, sta, arg);
1559 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1560 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1565 static const u32 ath10k_smps_map[] = {
1566 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1567 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1568 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1569 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1572 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1574 const struct ieee80211_sta_ht_cap *ht_cap)
1578 if (!ht_cap->ht_supported)
1581 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1582 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1584 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1587 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1588 WMI_PEER_SMPS_STATE,
1589 ath10k_smps_map[smps]);
1592 /* can be called only in mac80211 callbacks due to `key_count` usage */
1593 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1594 struct ieee80211_vif *vif,
1595 struct ieee80211_bss_conf *bss_conf)
1597 struct ath10k *ar = hw->priv;
1598 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1599 struct ieee80211_sta_ht_cap ht_cap;
1600 struct wmi_peer_assoc_complete_arg peer_arg;
1601 struct ieee80211_sta *ap_sta;
1604 lockdep_assert_held(&ar->conf_mutex);
1606 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1607 arvif->vdev_id, arvif->bssid, arvif->aid);
1611 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1613 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1614 bss_conf->bssid, arvif->vdev_id);
1619 /* ap_sta must be accessed only within rcu section which must be left
1620 * before calling ath10k_setup_peer_smps() which might sleep. */
1621 ht_cap = ap_sta->ht_cap;
1623 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1625 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1626 bss_conf->bssid, arvif->vdev_id, ret);
1633 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1635 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1636 bss_conf->bssid, arvif->vdev_id, ret);
1640 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1642 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1643 arvif->vdev_id, ret);
1647 ath10k_dbg(ar, ATH10K_DBG_MAC,
1648 "mac vdev %d up (associated) bssid %pM aid %d\n",
1649 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1651 WARN_ON(arvif->is_up);
1653 arvif->aid = bss_conf->aid;
1654 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1656 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1658 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1659 arvif->vdev_id, ret);
1663 arvif->is_up = true;
1666 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1667 struct ieee80211_vif *vif)
1669 struct ath10k *ar = hw->priv;
1670 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1673 lockdep_assert_held(&ar->conf_mutex);
1675 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1676 arvif->vdev_id, arvif->bssid);
1678 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1680 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1681 arvif->vdev_id, ret);
1683 arvif->def_wep_key_idx = 0;
1684 arvif->is_up = false;
1687 static int ath10k_station_assoc(struct ath10k *ar,
1688 struct ieee80211_vif *vif,
1689 struct ieee80211_sta *sta,
1692 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1693 struct wmi_peer_assoc_complete_arg peer_arg;
1696 lockdep_assert_held(&ar->conf_mutex);
1698 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
1700 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1701 sta->addr, arvif->vdev_id, ret);
1705 peer_arg.peer_reassoc = reassoc;
1706 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1708 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1709 sta->addr, arvif->vdev_id, ret);
1713 /* Re-assoc is run only to update supported rates for given station. It
1714 * doesn't make much sense to reconfigure the peer completely.
1717 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1720 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1721 arvif->vdev_id, ret);
1725 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1727 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1728 sta->addr, arvif->vdev_id, ret);
1733 arvif->num_legacy_stations++;
1734 ret = ath10k_recalc_rtscts_prot(arvif);
1736 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1737 arvif->vdev_id, ret);
1742 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1744 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1745 arvif->vdev_id, ret);
1753 static int ath10k_station_disassoc(struct ath10k *ar,
1754 struct ieee80211_vif *vif,
1755 struct ieee80211_sta *sta)
1757 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1760 lockdep_assert_held(&ar->conf_mutex);
1763 arvif->num_legacy_stations--;
1764 ret = ath10k_recalc_rtscts_prot(arvif);
1766 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1767 arvif->vdev_id, ret);
1772 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1774 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1775 arvif->vdev_id, ret);
1786 static int ath10k_update_channel_list(struct ath10k *ar)
1788 struct ieee80211_hw *hw = ar->hw;
1789 struct ieee80211_supported_band **bands;
1790 enum ieee80211_band band;
1791 struct ieee80211_channel *channel;
1792 struct wmi_scan_chan_list_arg arg = {0};
1793 struct wmi_channel_arg *ch;
1799 lockdep_assert_held(&ar->conf_mutex);
1801 bands = hw->wiphy->bands;
1802 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1806 for (i = 0; i < bands[band]->n_channels; i++) {
1807 if (bands[band]->channels[i].flags &
1808 IEEE80211_CHAN_DISABLED)
1815 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1816 arg.channels = kzalloc(len, GFP_KERNEL);
1821 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1825 for (i = 0; i < bands[band]->n_channels; i++) {
1826 channel = &bands[band]->channels[i];
1828 if (channel->flags & IEEE80211_CHAN_DISABLED)
1831 ch->allow_ht = true;
1833 /* FIXME: when should we really allow VHT? */
1834 ch->allow_vht = true;
1837 !(channel->flags & IEEE80211_CHAN_NO_IR);
1840 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1843 !!(channel->flags & IEEE80211_CHAN_RADAR);
1845 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1846 ch->passive = passive;
1848 ch->freq = channel->center_freq;
1849 ch->band_center_freq1 = channel->center_freq;
1851 ch->max_power = channel->max_power * 2;
1852 ch->max_reg_power = channel->max_reg_power * 2;
1853 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1854 ch->reg_class_id = 0; /* FIXME */
1856 /* FIXME: why use only legacy modes, why not any
1857 * HT/VHT modes? Would that even make any
1859 if (channel->band == IEEE80211_BAND_2GHZ)
1860 ch->mode = MODE_11G;
1862 ch->mode = MODE_11A;
1864 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1867 ath10k_dbg(ar, ATH10K_DBG_WMI,
1868 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1869 ch - arg.channels, arg.n_channels,
1870 ch->freq, ch->max_power, ch->max_reg_power,
1871 ch->max_antenna_gain, ch->mode);
1877 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1878 kfree(arg.channels);
1883 static enum wmi_dfs_region
1884 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1886 switch (dfs_region) {
1887 case NL80211_DFS_UNSET:
1888 return WMI_UNINIT_DFS_DOMAIN;
1889 case NL80211_DFS_FCC:
1890 return WMI_FCC_DFS_DOMAIN;
1891 case NL80211_DFS_ETSI:
1892 return WMI_ETSI_DFS_DOMAIN;
1893 case NL80211_DFS_JP:
1894 return WMI_MKK4_DFS_DOMAIN;
1896 return WMI_UNINIT_DFS_DOMAIN;
1899 static void ath10k_regd_update(struct ath10k *ar)
1901 struct reg_dmn_pair_mapping *regpair;
1903 enum wmi_dfs_region wmi_dfs_reg;
1904 enum nl80211_dfs_regions nl_dfs_reg;
1906 lockdep_assert_held(&ar->conf_mutex);
1908 ret = ath10k_update_channel_list(ar);
1910 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1912 regpair = ar->ath_common.regulatory.regpair;
1914 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1915 nl_dfs_reg = ar->dfs_detector->region;
1916 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1918 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1921 /* Target allows setting up per-band regdomain but ath_common provides
1922 * a combined one only */
1923 ret = ath10k_wmi_pdev_set_regdomain(ar,
1924 regpair->reg_domain,
1925 regpair->reg_domain, /* 2ghz */
1926 regpair->reg_domain, /* 5ghz */
1927 regpair->reg_2ghz_ctl,
1928 regpair->reg_5ghz_ctl,
1931 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1934 static void ath10k_reg_notifier(struct wiphy *wiphy,
1935 struct regulatory_request *request)
1937 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1938 struct ath10k *ar = hw->priv;
1941 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1943 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1944 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1945 request->dfs_region);
1946 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1947 request->dfs_region);
1949 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1950 request->dfs_region);
1953 mutex_lock(&ar->conf_mutex);
1954 if (ar->state == ATH10K_STATE_ON)
1955 ath10k_regd_update(ar);
1956 mutex_unlock(&ar->conf_mutex);
1963 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1965 if (ieee80211_is_mgmt(hdr->frame_control))
1966 return HTT_DATA_TX_EXT_TID_MGMT;
1968 if (!ieee80211_is_data_qos(hdr->frame_control))
1969 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1971 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1972 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1974 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1977 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
1980 return ath10k_vif_to_arvif(vif)->vdev_id;
1982 if (ar->monitor_started)
1983 return ar->monitor_vdev_id;
1985 ath10k_warn(ar, "failed to resolve vdev id\n");
1989 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1990 * Control in the header.
1992 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1994 struct ieee80211_hdr *hdr = (void *)skb->data;
1995 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1998 if (!ieee80211_is_data_qos(hdr->frame_control))
2001 qos_ctl = ieee80211_get_qos_ctl(hdr);
2002 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2003 skb->data, (void *)qos_ctl - (void *)skb->data);
2004 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
2006 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2007 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2008 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2009 * it is safe to downgrade to NullFunc.
2011 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2012 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2013 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2017 static void ath10k_tx_wep_key_work(struct work_struct *work)
2019 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
2021 struct ath10k *ar = arvif->ar;
2022 int ret, keyidx = arvif->def_wep_key_newidx;
2024 mutex_lock(&arvif->ar->conf_mutex);
2026 if (arvif->ar->state != ATH10K_STATE_ON)
2029 if (arvif->def_wep_key_idx == keyidx)
2032 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
2033 arvif->vdev_id, keyidx);
2035 ret = ath10k_wmi_vdev_set_param(arvif->ar,
2037 arvif->ar->wmi.vdev_param->def_keyid,
2040 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
2046 arvif->def_wep_key_idx = keyidx;
2049 mutex_unlock(&arvif->ar->conf_mutex);
2052 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
2053 struct ieee80211_key_conf *key,
2054 struct sk_buff *skb)
2056 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2057 struct ath10k *ar = arvif->ar;
2058 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2060 if (!ieee80211_has_protected(hdr->frame_control))
2066 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
2067 key->cipher != WLAN_CIPHER_SUITE_WEP104)
2070 if (key->keyidx == arvif->def_wep_key_idx)
2073 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
2074 * queueing frames until key index is updated is not an option because
2075 * sk_buff may need more processing to be done, e.g. offchannel */
2076 arvif->def_wep_key_newidx = key->keyidx;
2077 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
2080 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2081 struct ieee80211_vif *vif,
2082 struct sk_buff *skb)
2084 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2085 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2087 /* This is case only for P2P_GO */
2088 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2089 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2092 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2093 spin_lock_bh(&ar->data_lock);
2094 if (arvif->u.ap.noa_data)
2095 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2097 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2098 arvif->u.ap.noa_data,
2099 arvif->u.ap.noa_len);
2100 spin_unlock_bh(&ar->data_lock);
2104 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2106 /* FIXME: Not really sure since when the behaviour changed. At some
2107 * point new firmware stopped requiring creation of peer entries for
2108 * offchannel tx (and actually creating them causes issues with wmi-htc
2109 * tx credit replenishment and reliability). Assuming it's at least 3.4
2110 * because that's when the `freq` was introduced to TX_FRM HTT command.
2112 return !(ar->htt.target_version_major >= 3 &&
2113 ar->htt.target_version_minor >= 4);
2116 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2118 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2121 if (ar->htt.target_version_major >= 3) {
2122 /* Since HTT 3.0 there is no separate mgmt tx command */
2123 ret = ath10k_htt_tx(&ar->htt, skb);
2127 if (ieee80211_is_mgmt(hdr->frame_control)) {
2128 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2130 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2131 ATH10K_MAX_NUM_MGMT_PENDING) {
2132 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2137 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2138 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2140 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2142 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2144 ieee80211_is_nullfunc(hdr->frame_control)) {
2145 /* FW does not report tx status properly for NullFunc frames
2146 * unless they are sent through mgmt tx path. mac80211 sends
2147 * those frames when it detects link/beacon loss and depends
2148 * on the tx status to be correct. */
2149 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2151 ret = ath10k_htt_tx(&ar->htt, skb);
2156 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2158 ieee80211_free_txskb(ar->hw, skb);
2162 void ath10k_offchan_tx_purge(struct ath10k *ar)
2164 struct sk_buff *skb;
2167 skb = skb_dequeue(&ar->offchan_tx_queue);
2171 ieee80211_free_txskb(ar->hw, skb);
2175 void ath10k_offchan_tx_work(struct work_struct *work)
2177 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2178 struct ath10k_peer *peer;
2179 struct ieee80211_hdr *hdr;
2180 struct sk_buff *skb;
2181 const u8 *peer_addr;
2185 /* FW requirement: We must create a peer before FW will send out
2186 * an offchannel frame. Otherwise the frame will be stuck and
2187 * never transmitted. We delete the peer upon tx completion.
2188 * It is unlikely that a peer for offchannel tx will already be
2189 * present. However it may be in some rare cases so account for that.
2190 * Otherwise we might remove a legitimate peer and break stuff. */
2193 skb = skb_dequeue(&ar->offchan_tx_queue);
2197 mutex_lock(&ar->conf_mutex);
2199 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2202 hdr = (struct ieee80211_hdr *)skb->data;
2203 peer_addr = ieee80211_get_DA(hdr);
2204 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2206 spin_lock_bh(&ar->data_lock);
2207 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2208 spin_unlock_bh(&ar->data_lock);
2211 /* FIXME: should this use ath10k_warn()? */
2212 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2213 peer_addr, vdev_id);
2216 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2218 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2219 peer_addr, vdev_id, ret);
2222 spin_lock_bh(&ar->data_lock);
2223 reinit_completion(&ar->offchan_tx_completed);
2224 ar->offchan_tx_skb = skb;
2225 spin_unlock_bh(&ar->data_lock);
2227 ath10k_tx_htt(ar, skb);
2229 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2232 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2236 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2238 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2239 peer_addr, vdev_id, ret);
2242 mutex_unlock(&ar->conf_mutex);
2246 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2248 struct sk_buff *skb;
2251 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2255 ieee80211_free_txskb(ar->hw, skb);
2259 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2261 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2262 struct sk_buff *skb;
2266 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2270 ret = ath10k_wmi_mgmt_tx(ar, skb);
2272 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2274 ieee80211_free_txskb(ar->hw, skb);
2283 void __ath10k_scan_finish(struct ath10k *ar)
2285 lockdep_assert_held(&ar->data_lock);
2287 switch (ar->scan.state) {
2288 case ATH10K_SCAN_IDLE:
2290 case ATH10K_SCAN_RUNNING:
2291 if (ar->scan.is_roc)
2292 ieee80211_remain_on_channel_expired(ar->hw);
2293 case ATH10K_SCAN_ABORTING:
2294 if (!ar->scan.is_roc)
2295 ieee80211_scan_completed(ar->hw,
2297 ATH10K_SCAN_ABORTING));
2299 case ATH10K_SCAN_STARTING:
2300 ar->scan.state = ATH10K_SCAN_IDLE;
2301 ar->scan_channel = NULL;
2302 ath10k_offchan_tx_purge(ar);
2303 cancel_delayed_work(&ar->scan.timeout);
2304 complete_all(&ar->scan.completed);
2309 void ath10k_scan_finish(struct ath10k *ar)
2311 spin_lock_bh(&ar->data_lock);
2312 __ath10k_scan_finish(ar);
2313 spin_unlock_bh(&ar->data_lock);
2316 static int ath10k_scan_stop(struct ath10k *ar)
2318 struct wmi_stop_scan_arg arg = {
2319 .req_id = 1, /* FIXME */
2320 .req_type = WMI_SCAN_STOP_ONE,
2321 .u.scan_id = ATH10K_SCAN_ID,
2325 lockdep_assert_held(&ar->conf_mutex);
2327 ret = ath10k_wmi_stop_scan(ar, &arg);
2329 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2333 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2335 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2337 } else if (ret > 0) {
2342 /* Scan state should be updated upon scan completion but in case
2343 * firmware fails to deliver the event (for whatever reason) it is
2344 * desired to clean up scan state anyway. Firmware may have just
2345 * dropped the scan completion event delivery due to transport pipe
2346 * being overflown with data and/or it can recover on its own before
2347 * next scan request is submitted.
2349 spin_lock_bh(&ar->data_lock);
2350 if (ar->scan.state != ATH10K_SCAN_IDLE)
2351 __ath10k_scan_finish(ar);
2352 spin_unlock_bh(&ar->data_lock);
2357 static void ath10k_scan_abort(struct ath10k *ar)
2361 lockdep_assert_held(&ar->conf_mutex);
2363 spin_lock_bh(&ar->data_lock);
2365 switch (ar->scan.state) {
2366 case ATH10K_SCAN_IDLE:
2367 /* This can happen if timeout worker kicked in and called
2368 * abortion while scan completion was being processed.
2371 case ATH10K_SCAN_STARTING:
2372 case ATH10K_SCAN_ABORTING:
2373 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2374 ath10k_scan_state_str(ar->scan.state),
2377 case ATH10K_SCAN_RUNNING:
2378 ar->scan.state = ATH10K_SCAN_ABORTING;
2379 spin_unlock_bh(&ar->data_lock);
2381 ret = ath10k_scan_stop(ar);
2383 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2385 spin_lock_bh(&ar->data_lock);
2389 spin_unlock_bh(&ar->data_lock);
2392 void ath10k_scan_timeout_work(struct work_struct *work)
2394 struct ath10k *ar = container_of(work, struct ath10k,
2397 mutex_lock(&ar->conf_mutex);
2398 ath10k_scan_abort(ar);
2399 mutex_unlock(&ar->conf_mutex);
2402 static int ath10k_start_scan(struct ath10k *ar,
2403 const struct wmi_start_scan_arg *arg)
2407 lockdep_assert_held(&ar->conf_mutex);
2409 ret = ath10k_wmi_start_scan(ar, arg);
2413 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2415 ret = ath10k_scan_stop(ar);
2417 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2422 /* Add a 200ms margin to account for event/command processing */
2423 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2424 msecs_to_jiffies(arg->max_scan_time+200));
2428 /**********************/
2429 /* mac80211 callbacks */
2430 /**********************/
2432 static void ath10k_tx(struct ieee80211_hw *hw,
2433 struct ieee80211_tx_control *control,
2434 struct sk_buff *skb)
2436 struct ath10k *ar = hw->priv;
2437 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2438 struct ieee80211_vif *vif = info->control.vif;
2439 struct ieee80211_key_conf *key = info->control.hw_key;
2440 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2442 /* We should disable CCK RATE due to P2P */
2443 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2444 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2446 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2447 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2448 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2450 /* it makes no sense to process injected frames like that */
2451 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2452 ath10k_tx_h_nwifi(hw, skb);
2453 ath10k_tx_h_update_wep_key(vif, key, skb);
2454 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2455 ath10k_tx_h_seq_no(vif, skb);
2458 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2459 spin_lock_bh(&ar->data_lock);
2460 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
2461 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2462 spin_unlock_bh(&ar->data_lock);
2464 if (ath10k_mac_need_offchan_tx_work(ar)) {
2465 ATH10K_SKB_CB(skb)->htt.freq = 0;
2466 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2468 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2471 skb_queue_tail(&ar->offchan_tx_queue, skb);
2472 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2477 ath10k_tx_htt(ar, skb);
2480 /* Must not be called with conf_mutex held as workers can use that also. */
2481 void ath10k_drain_tx(struct ath10k *ar)
2483 /* make sure rcu-protected mac80211 tx path itself is drained */
2486 ath10k_offchan_tx_purge(ar);
2487 ath10k_mgmt_over_wmi_tx_purge(ar);
2489 cancel_work_sync(&ar->offchan_tx_work);
2490 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2493 void ath10k_halt(struct ath10k *ar)
2495 struct ath10k_vif *arvif;
2497 lockdep_assert_held(&ar->conf_mutex);
2499 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2500 ar->filter_flags = 0;
2501 ar->monitor = false;
2503 if (ar->monitor_started)
2504 ath10k_monitor_stop(ar);
2506 ar->monitor_started = false;
2508 ath10k_scan_finish(ar);
2509 ath10k_peer_cleanup_all(ar);
2510 ath10k_core_stop(ar);
2511 ath10k_hif_power_down(ar);
2513 spin_lock_bh(&ar->data_lock);
2514 list_for_each_entry(arvif, &ar->arvifs, list)
2515 ath10k_mac_vif_beacon_cleanup(arvif);
2516 spin_unlock_bh(&ar->data_lock);
2519 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2521 struct ath10k *ar = hw->priv;
2523 mutex_lock(&ar->conf_mutex);
2525 if (ar->cfg_tx_chainmask) {
2526 *tx_ant = ar->cfg_tx_chainmask;
2527 *rx_ant = ar->cfg_rx_chainmask;
2529 *tx_ant = ar->supp_tx_chainmask;
2530 *rx_ant = ar->supp_rx_chainmask;
2533 mutex_unlock(&ar->conf_mutex);
2538 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2540 /* It is not clear that allowing gaps in chainmask
2541 * is helpful. Probably it will not do what user
2542 * is hoping for, so warn in that case.
2544 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2547 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2551 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2555 lockdep_assert_held(&ar->conf_mutex);
2557 ath10k_check_chain_mask(ar, tx_ant, "tx");
2558 ath10k_check_chain_mask(ar, rx_ant, "rx");
2560 ar->cfg_tx_chainmask = tx_ant;
2561 ar->cfg_rx_chainmask = rx_ant;
2563 if ((ar->state != ATH10K_STATE_ON) &&
2564 (ar->state != ATH10K_STATE_RESTARTED))
2567 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2570 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2575 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2578 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2586 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2588 struct ath10k *ar = hw->priv;
2591 mutex_lock(&ar->conf_mutex);
2592 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2593 mutex_unlock(&ar->conf_mutex);
2597 static int ath10k_start(struct ieee80211_hw *hw)
2599 struct ath10k *ar = hw->priv;
2603 * This makes sense only when restarting hw. It is harmless to call
2604 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2605 * commands will be submitted while restarting.
2607 ath10k_drain_tx(ar);
2609 mutex_lock(&ar->conf_mutex);
2611 switch (ar->state) {
2612 case ATH10K_STATE_OFF:
2613 ar->state = ATH10K_STATE_ON;
2615 case ATH10K_STATE_RESTARTING:
2617 ar->state = ATH10K_STATE_RESTARTED;
2619 case ATH10K_STATE_ON:
2620 case ATH10K_STATE_RESTARTED:
2621 case ATH10K_STATE_WEDGED:
2625 case ATH10K_STATE_UTF:
2630 ret = ath10k_hif_power_up(ar);
2632 ath10k_err(ar, "Could not init hif: %d\n", ret);
2636 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2638 ath10k_err(ar, "Could not init core: %d\n", ret);
2639 goto err_power_down;
2642 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2644 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2648 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2650 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2654 if (ar->cfg_tx_chainmask)
2655 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2656 ar->cfg_rx_chainmask);
2659 * By default FW set ARP frames ac to voice (6). In that case ARP
2660 * exchange is not working properly for UAPSD enabled AP. ARP requests
2661 * which arrives with access category 0 are processed by network stack
2662 * and send back with access category 0, but FW changes access category
2663 * to 6. Set ARP frames access category to best effort (0) solves
2667 ret = ath10k_wmi_pdev_set_param(ar,
2668 ar->wmi.pdev_param->arp_ac_override, 0);
2670 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2675 ar->num_started_vdevs = 0;
2676 ath10k_regd_update(ar);
2678 ath10k_spectral_start(ar);
2680 mutex_unlock(&ar->conf_mutex);
2684 ath10k_core_stop(ar);
2687 ath10k_hif_power_down(ar);
2690 ar->state = ATH10K_STATE_OFF;
2693 mutex_unlock(&ar->conf_mutex);
2697 static void ath10k_stop(struct ieee80211_hw *hw)
2699 struct ath10k *ar = hw->priv;
2701 ath10k_drain_tx(ar);
2703 mutex_lock(&ar->conf_mutex);
2704 if (ar->state != ATH10K_STATE_OFF) {
2706 ar->state = ATH10K_STATE_OFF;
2708 mutex_unlock(&ar->conf_mutex);
2710 cancel_delayed_work_sync(&ar->scan.timeout);
2711 cancel_work_sync(&ar->restart_work);
2714 static int ath10k_config_ps(struct ath10k *ar)
2716 struct ath10k_vif *arvif;
2719 lockdep_assert_held(&ar->conf_mutex);
2721 list_for_each_entry(arvif, &ar->arvifs, list) {
2722 ret = ath10k_mac_vif_setup_ps(arvif);
2724 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2732 static const char *chandef_get_width(enum nl80211_chan_width width)
2735 case NL80211_CHAN_WIDTH_20_NOHT:
2737 case NL80211_CHAN_WIDTH_20:
2739 case NL80211_CHAN_WIDTH_40:
2741 case NL80211_CHAN_WIDTH_80:
2743 case NL80211_CHAN_WIDTH_80P80:
2745 case NL80211_CHAN_WIDTH_160:
2747 case NL80211_CHAN_WIDTH_5:
2749 case NL80211_CHAN_WIDTH_10:
2755 static void ath10k_config_chan(struct ath10k *ar)
2757 struct ath10k_vif *arvif;
2760 lockdep_assert_held(&ar->conf_mutex);
2762 ath10k_dbg(ar, ATH10K_DBG_MAC,
2763 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2764 ar->chandef.chan->center_freq,
2765 ar->chandef.center_freq1,
2766 ar->chandef.center_freq2,
2767 chandef_get_width(ar->chandef.width));
2769 /* First stop monitor interface. Some FW versions crash if there's a
2770 * lone monitor interface. */
2771 if (ar->monitor_started)
2772 ath10k_monitor_stop(ar);
2774 list_for_each_entry(arvif, &ar->arvifs, list) {
2775 if (!arvif->is_started)
2781 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2784 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2786 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2787 arvif->vdev_id, ret);
2792 /* all vdevs are downed now - attempt to restart and re-up them */
2794 list_for_each_entry(arvif, &ar->arvifs, list) {
2795 if (!arvif->is_started)
2798 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2801 ret = ath10k_vdev_restart(arvif);
2803 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2804 arvif->vdev_id, ret);
2811 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2814 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2815 arvif->vdev_id, ret);
2820 ath10k_monitor_recalc(ar);
2823 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2828 lockdep_assert_held(&ar->conf_mutex);
2830 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2832 param = ar->wmi.pdev_param->txpower_limit2g;
2833 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2835 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2840 param = ar->wmi.pdev_param->txpower_limit5g;
2841 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2843 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2851 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2853 struct ath10k_vif *arvif;
2854 int ret, txpower = -1;
2856 lockdep_assert_held(&ar->conf_mutex);
2858 list_for_each_entry(arvif, &ar->arvifs, list) {
2859 WARN_ON(arvif->txpower < 0);
2862 txpower = arvif->txpower;
2864 txpower = min(txpower, arvif->txpower);
2867 if (WARN_ON(txpower == -1))
2870 ret = ath10k_mac_txpower_setup(ar, txpower);
2872 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2880 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2882 struct ath10k *ar = hw->priv;
2883 struct ieee80211_conf *conf = &hw->conf;
2886 mutex_lock(&ar->conf_mutex);
2888 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2889 ath10k_dbg(ar, ATH10K_DBG_MAC,
2890 "mac config channel %dMHz flags 0x%x radar %d\n",
2891 conf->chandef.chan->center_freq,
2892 conf->chandef.chan->flags,
2893 conf->radar_enabled);
2895 spin_lock_bh(&ar->data_lock);
2896 ar->rx_channel = conf->chandef.chan;
2897 spin_unlock_bh(&ar->data_lock);
2899 ar->radar_enabled = conf->radar_enabled;
2900 ath10k_recalc_radar_detection(ar);
2902 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2903 ar->chandef = conf->chandef;
2904 ath10k_config_chan(ar);
2908 if (changed & IEEE80211_CONF_CHANGE_PS)
2909 ath10k_config_ps(ar);
2911 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2912 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2913 ret = ath10k_monitor_recalc(ar);
2915 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2918 mutex_unlock(&ar->conf_mutex);
2922 static u32 get_nss_from_chainmask(u16 chain_mask)
2924 if ((chain_mask & 0x15) == 0x15)
2926 else if ((chain_mask & 0x7) == 0x7)
2928 else if ((chain_mask & 0x3) == 0x3)
2935 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2936 * because we will send mgmt frames without CCK. This requirement
2937 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2940 static int ath10k_add_interface(struct ieee80211_hw *hw,
2941 struct ieee80211_vif *vif)
2943 struct ath10k *ar = hw->priv;
2944 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2945 enum wmi_sta_powersave_param param;
2951 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2953 mutex_lock(&ar->conf_mutex);
2955 memset(arvif, 0, sizeof(*arvif));
2960 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2961 INIT_LIST_HEAD(&arvif->list);
2963 if (ar->free_vdev_map == 0) {
2964 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2968 bit = __ffs64(ar->free_vdev_map);
2970 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2971 bit, ar->free_vdev_map);
2973 arvif->vdev_id = bit;
2974 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2976 switch (vif->type) {
2977 case NL80211_IFTYPE_P2P_DEVICE:
2978 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2979 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2981 case NL80211_IFTYPE_UNSPECIFIED:
2982 case NL80211_IFTYPE_STATION:
2983 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2985 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2987 case NL80211_IFTYPE_ADHOC:
2988 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2990 case NL80211_IFTYPE_AP:
2991 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2994 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2996 case NL80211_IFTYPE_MONITOR:
2997 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3004 /* Some firmware revisions don't wait for beacon tx completion before
3005 * sending another SWBA event. This could lead to hardware using old
3006 * (freed) beacon data in some cases, e.g. tx credit starvation
3007 * combined with missed TBTT. This is very very rare.
3009 * On non-IOMMU-enabled hosts this could be a possible security issue
3010 * because hw could beacon some random data on the air. On
3011 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3012 * device would crash.
3014 * Since there are no beacon tx completions (implicit nor explicit)
3015 * propagated to host the only workaround for this is to allocate a
3016 * DMA-coherent buffer for a lifetime of a vif and use it for all
3017 * beacon tx commands. Worst case for this approach is some beacons may
3018 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3020 if (vif->type == NL80211_IFTYPE_ADHOC ||
3021 vif->type == NL80211_IFTYPE_AP) {
3022 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3023 IEEE80211_MAX_FRAME_LEN,
3024 &arvif->beacon_paddr,
3026 if (!arvif->beacon_buf) {
3028 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3034 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3035 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3036 arvif->beacon_buf ? "single-buf" : "per-skb");
3038 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3039 arvif->vdev_subtype, vif->addr);
3041 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
3042 arvif->vdev_id, ret);
3046 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
3047 list_add(&arvif->list, &ar->arvifs);
3049 vdev_param = ar->wmi.vdev_param->def_keyid;
3050 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
3051 arvif->def_wep_key_idx);
3053 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
3054 arvif->vdev_id, ret);
3055 goto err_vdev_delete;
3058 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3059 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3060 ATH10K_HW_TXRX_NATIVE_WIFI);
3061 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3062 if (ret && ret != -EOPNOTSUPP) {
3063 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
3064 arvif->vdev_id, ret);
3065 goto err_vdev_delete;
3068 if (ar->cfg_tx_chainmask) {
3069 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3071 vdev_param = ar->wmi.vdev_param->nss;
3072 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3075 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3076 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3078 goto err_vdev_delete;
3082 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3083 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3085 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
3086 arvif->vdev_id, ret);
3087 goto err_vdev_delete;
3090 ret = ath10k_mac_set_kickout(arvif);
3092 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
3093 arvif->vdev_id, ret);
3094 goto err_peer_delete;
3098 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3099 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3100 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3101 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3104 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
3105 arvif->vdev_id, ret);
3106 goto err_peer_delete;
3109 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3111 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3112 arvif->vdev_id, ret);
3113 goto err_peer_delete;
3116 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3118 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3119 arvif->vdev_id, ret);
3120 goto err_peer_delete;
3124 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
3126 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3127 arvif->vdev_id, ret);
3128 goto err_peer_delete;
3131 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
3133 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
3134 arvif->vdev_id, ret);
3135 goto err_peer_delete;
3138 arvif->txpower = vif->bss_conf.txpower;
3139 ret = ath10k_mac_txpower_recalc(ar);
3141 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3142 goto err_peer_delete;
3145 mutex_unlock(&ar->conf_mutex);
3149 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3150 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3153 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3154 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3155 list_del(&arvif->list);
3158 if (arvif->beacon_buf) {
3159 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3160 arvif->beacon_buf, arvif->beacon_paddr);
3161 arvif->beacon_buf = NULL;
3164 mutex_unlock(&ar->conf_mutex);
3169 static void ath10k_remove_interface(struct ieee80211_hw *hw,
3170 struct ieee80211_vif *vif)
3172 struct ath10k *ar = hw->priv;
3173 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3176 cancel_work_sync(&arvif->wep_key_work);
3178 mutex_lock(&ar->conf_mutex);
3180 spin_lock_bh(&ar->data_lock);
3181 ath10k_mac_vif_beacon_cleanup(arvif);
3182 spin_unlock_bh(&ar->data_lock);
3184 ret = ath10k_spectral_vif_stop(arvif);
3186 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
3187 arvif->vdev_id, ret);
3189 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3190 list_del(&arvif->list);
3192 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3193 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3195 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
3196 arvif->vdev_id, ret);
3198 kfree(arvif->u.ap.noa_data);
3201 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3204 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3206 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3207 arvif->vdev_id, ret);
3209 ath10k_peer_cleanup(ar, arvif->vdev_id);
3211 mutex_unlock(&ar->conf_mutex);
3215 * FIXME: Has to be verified.
3217 #define SUPPORTED_FILTERS \
3218 (FIF_PROMISC_IN_BSS | \
3223 FIF_BCN_PRBRESP_PROMISC | \
3227 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3228 unsigned int changed_flags,
3229 unsigned int *total_flags,
3232 struct ath10k *ar = hw->priv;
3235 mutex_lock(&ar->conf_mutex);
3237 changed_flags &= SUPPORTED_FILTERS;
3238 *total_flags &= SUPPORTED_FILTERS;
3239 ar->filter_flags = *total_flags;
3241 ret = ath10k_monitor_recalc(ar);
3243 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3245 mutex_unlock(&ar->conf_mutex);
3248 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3249 struct ieee80211_vif *vif,
3250 struct ieee80211_bss_conf *info,
3253 struct ath10k *ar = hw->priv;
3254 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3256 u32 vdev_param, pdev_param, slottime, preamble;
3258 mutex_lock(&ar->conf_mutex);
3260 if (changed & BSS_CHANGED_IBSS)
3261 ath10k_control_ibss(arvif, info, vif->addr);
3263 if (changed & BSS_CHANGED_BEACON_INT) {
3264 arvif->beacon_interval = info->beacon_int;
3265 vdev_param = ar->wmi.vdev_param->beacon_interval;
3266 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3267 arvif->beacon_interval);
3268 ath10k_dbg(ar, ATH10K_DBG_MAC,
3269 "mac vdev %d beacon_interval %d\n",
3270 arvif->vdev_id, arvif->beacon_interval);
3273 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3274 arvif->vdev_id, ret);
3277 if (changed & BSS_CHANGED_BEACON) {
3278 ath10k_dbg(ar, ATH10K_DBG_MAC,
3279 "vdev %d set beacon tx mode to staggered\n",
3282 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3283 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3284 WMI_BEACON_STAGGERED_MODE);
3286 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3287 arvif->vdev_id, ret);
3290 if (changed & BSS_CHANGED_BEACON_INFO) {
3291 arvif->dtim_period = info->dtim_period;
3293 ath10k_dbg(ar, ATH10K_DBG_MAC,
3294 "mac vdev %d dtim_period %d\n",
3295 arvif->vdev_id, arvif->dtim_period);
3297 vdev_param = ar->wmi.vdev_param->dtim_period;
3298 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3299 arvif->dtim_period);
3301 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3302 arvif->vdev_id, ret);
3305 if (changed & BSS_CHANGED_SSID &&
3306 vif->type == NL80211_IFTYPE_AP) {
3307 arvif->u.ap.ssid_len = info->ssid_len;
3309 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3310 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3313 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3314 ether_addr_copy(arvif->bssid, info->bssid);
3316 if (changed & BSS_CHANGED_BEACON_ENABLED)
3317 ath10k_control_beaconing(arvif, info);
3319 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3320 arvif->use_cts_prot = info->use_cts_prot;
3321 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3322 arvif->vdev_id, info->use_cts_prot);
3324 ret = ath10k_recalc_rtscts_prot(arvif);
3326 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3327 arvif->vdev_id, ret);
3330 if (changed & BSS_CHANGED_ERP_SLOT) {
3331 if (info->use_short_slot)
3332 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3335 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3337 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3338 arvif->vdev_id, slottime);
3340 vdev_param = ar->wmi.vdev_param->slot_time;
3341 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3344 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3345 arvif->vdev_id, ret);
3348 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3349 if (info->use_short_preamble)
3350 preamble = WMI_VDEV_PREAMBLE_SHORT;
3352 preamble = WMI_VDEV_PREAMBLE_LONG;
3354 ath10k_dbg(ar, ATH10K_DBG_MAC,
3355 "mac vdev %d preamble %dn",
3356 arvif->vdev_id, preamble);
3358 vdev_param = ar->wmi.vdev_param->preamble;
3359 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3362 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3363 arvif->vdev_id, ret);
3366 if (changed & BSS_CHANGED_ASSOC) {
3368 /* Workaround: Make sure monitor vdev is not running
3369 * when associating to prevent some firmware revisions
3370 * (e.g. 10.1 and 10.2) from crashing.
3372 if (ar->monitor_started)
3373 ath10k_monitor_stop(ar);
3374 ath10k_bss_assoc(hw, vif, info);
3375 ath10k_monitor_recalc(ar);
3377 ath10k_bss_disassoc(hw, vif);
3381 if (changed & BSS_CHANGED_TXPOWER) {
3382 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3383 arvif->vdev_id, info->txpower);
3385 arvif->txpower = info->txpower;
3386 ret = ath10k_mac_txpower_recalc(ar);
3388 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3391 if (changed & BSS_CHANGED_PS) {
3392 ret = ath10k_mac_vif_setup_ps(arvif);
3394 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3395 arvif->vdev_id, ret);
3398 mutex_unlock(&ar->conf_mutex);
3401 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3402 struct ieee80211_vif *vif,
3403 struct ieee80211_scan_request *hw_req)
3405 struct ath10k *ar = hw->priv;
3406 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3407 struct cfg80211_scan_request *req = &hw_req->req;
3408 struct wmi_start_scan_arg arg;
3412 mutex_lock(&ar->conf_mutex);
3414 spin_lock_bh(&ar->data_lock);
3415 switch (ar->scan.state) {
3416 case ATH10K_SCAN_IDLE:
3417 reinit_completion(&ar->scan.started);
3418 reinit_completion(&ar->scan.completed);
3419 ar->scan.state = ATH10K_SCAN_STARTING;
3420 ar->scan.is_roc = false;
3421 ar->scan.vdev_id = arvif->vdev_id;
3424 case ATH10K_SCAN_STARTING:
3425 case ATH10K_SCAN_RUNNING:
3426 case ATH10K_SCAN_ABORTING:
3430 spin_unlock_bh(&ar->data_lock);
3435 memset(&arg, 0, sizeof(arg));
3436 ath10k_wmi_start_scan_init(ar, &arg);
3437 arg.vdev_id = arvif->vdev_id;
3438 arg.scan_id = ATH10K_SCAN_ID;
3441 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3444 arg.ie_len = req->ie_len;
3445 memcpy(arg.ie, req->ie, arg.ie_len);
3449 arg.n_ssids = req->n_ssids;
3450 for (i = 0; i < arg.n_ssids; i++) {
3451 arg.ssids[i].len = req->ssids[i].ssid_len;
3452 arg.ssids[i].ssid = req->ssids[i].ssid;
3455 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3458 if (req->n_channels) {
3459 arg.n_channels = req->n_channels;
3460 for (i = 0; i < arg.n_channels; i++)
3461 arg.channels[i] = req->channels[i]->center_freq;
3464 ret = ath10k_start_scan(ar, &arg);
3466 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3467 spin_lock_bh(&ar->data_lock);
3468 ar->scan.state = ATH10K_SCAN_IDLE;
3469 spin_unlock_bh(&ar->data_lock);
3473 mutex_unlock(&ar->conf_mutex);
3477 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3478 struct ieee80211_vif *vif)
3480 struct ath10k *ar = hw->priv;
3482 mutex_lock(&ar->conf_mutex);
3483 ath10k_scan_abort(ar);
3484 mutex_unlock(&ar->conf_mutex);
3486 cancel_delayed_work_sync(&ar->scan.timeout);
3489 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3490 struct ath10k_vif *arvif,
3491 enum set_key_cmd cmd,
3492 struct ieee80211_key_conf *key)
3494 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3497 /* 10.1 firmware branch requires default key index to be set to group
3498 * key index after installing it. Otherwise FW/HW Txes corrupted
3499 * frames with multi-vif APs. This is not required for main firmware
3500 * branch (e.g. 636).
3502 * FIXME: This has been tested only in AP. It remains unknown if this
3503 * is required for multi-vif STA interfaces on 10.1 */
3505 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3508 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3511 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3514 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3520 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3523 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3524 arvif->vdev_id, ret);
3527 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3528 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3529 struct ieee80211_key_conf *key)
3531 struct ath10k *ar = hw->priv;
3532 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3533 struct ath10k_peer *peer;
3534 const u8 *peer_addr;
3535 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3536 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3539 if (key->keyidx > WMI_MAX_KEY_INDEX)
3542 mutex_lock(&ar->conf_mutex);
3545 peer_addr = sta->addr;
3546 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3547 peer_addr = vif->bss_conf.bssid;
3549 peer_addr = vif->addr;
3551 key->hw_key_idx = key->keyidx;
3553 /* the peer should not disappear in mid-way (unless FW goes awry) since
3554 * we already hold conf_mutex. we just make sure its there now. */
3555 spin_lock_bh(&ar->data_lock);
3556 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3557 spin_unlock_bh(&ar->data_lock);
3560 if (cmd == SET_KEY) {
3561 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3566 /* if the peer doesn't exist there is no key to disable
3574 arvif->wep_keys[key->keyidx] = key;
3576 arvif->wep_keys[key->keyidx] = NULL;
3578 if (cmd == DISABLE_KEY)
3579 ath10k_clear_vdev_key(arvif, key);
3582 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3584 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3585 arvif->vdev_id, peer_addr, ret);
3589 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3591 spin_lock_bh(&ar->data_lock);
3592 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3593 if (peer && cmd == SET_KEY)
3594 peer->keys[key->keyidx] = key;
3595 else if (peer && cmd == DISABLE_KEY)
3596 peer->keys[key->keyidx] = NULL;
3597 else if (peer == NULL)
3598 /* impossible unless FW goes crazy */
3599 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3600 spin_unlock_bh(&ar->data_lock);
3603 mutex_unlock(&ar->conf_mutex);
3607 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3610 struct ath10k_vif *arvif;
3611 struct ath10k_sta *arsta;
3612 struct ieee80211_sta *sta;
3613 u32 changed, bw, nss, smps;
3616 arsta = container_of(wk, struct ath10k_sta, update_wk);
3617 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3618 arvif = arsta->arvif;
3621 spin_lock_bh(&ar->data_lock);
3623 changed = arsta->changed;
3630 spin_unlock_bh(&ar->data_lock);
3632 mutex_lock(&ar->conf_mutex);
3634 if (changed & IEEE80211_RC_BW_CHANGED) {
3635 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3638 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3639 WMI_PEER_CHAN_WIDTH, bw);
3641 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3642 sta->addr, bw, err);
3645 if (changed & IEEE80211_RC_NSS_CHANGED) {
3646 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3649 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3652 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3653 sta->addr, nss, err);
3656 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3657 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3660 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3661 WMI_PEER_SMPS_STATE, smps);
3663 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3664 sta->addr, smps, err);
3667 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3668 changed & IEEE80211_RC_NSS_CHANGED) {
3669 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
3672 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3674 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3678 mutex_unlock(&ar->conf_mutex);
3681 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3683 struct ath10k *ar = arvif->ar;
3685 lockdep_assert_held(&ar->conf_mutex);
3687 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3688 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3691 if (ar->num_stations >= ar->max_num_stations)
3699 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3701 struct ath10k *ar = arvif->ar;
3703 lockdep_assert_held(&ar->conf_mutex);
3705 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3706 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3712 static int ath10k_sta_state(struct ieee80211_hw *hw,
3713 struct ieee80211_vif *vif,
3714 struct ieee80211_sta *sta,
3715 enum ieee80211_sta_state old_state,
3716 enum ieee80211_sta_state new_state)
3718 struct ath10k *ar = hw->priv;
3719 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3720 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3723 if (old_state == IEEE80211_STA_NOTEXIST &&
3724 new_state == IEEE80211_STA_NONE) {
3725 memset(arsta, 0, sizeof(*arsta));
3726 arsta->arvif = arvif;
3727 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3730 /* cancel must be done outside the mutex to avoid deadlock */
3731 if ((old_state == IEEE80211_STA_NONE &&
3732 new_state == IEEE80211_STA_NOTEXIST))
3733 cancel_work_sync(&arsta->update_wk);
3735 mutex_lock(&ar->conf_mutex);
3737 if (old_state == IEEE80211_STA_NOTEXIST &&
3738 new_state == IEEE80211_STA_NONE) {
3740 * New station addition.
3742 ath10k_dbg(ar, ATH10K_DBG_MAC,
3743 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3744 arvif->vdev_id, sta->addr,
3745 ar->num_stations + 1, ar->max_num_stations,
3746 ar->num_peers + 1, ar->max_num_peers);
3748 ret = ath10k_mac_inc_num_stations(arvif);
3750 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3751 ar->max_num_stations);
3755 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3757 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3758 sta->addr, arvif->vdev_id, ret);
3759 ath10k_mac_dec_num_stations(arvif);
3763 if (vif->type == NL80211_IFTYPE_STATION) {
3764 WARN_ON(arvif->is_started);
3766 ret = ath10k_vdev_start(arvif);
3768 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3769 arvif->vdev_id, ret);
3770 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3772 ath10k_mac_dec_num_stations(arvif);
3776 arvif->is_started = true;
3778 } else if ((old_state == IEEE80211_STA_NONE &&
3779 new_state == IEEE80211_STA_NOTEXIST)) {
3781 * Existing station deletion.
3783 ath10k_dbg(ar, ATH10K_DBG_MAC,
3784 "mac vdev %d peer delete %pM (sta gone)\n",
3785 arvif->vdev_id, sta->addr);
3787 if (vif->type == NL80211_IFTYPE_STATION) {
3788 WARN_ON(!arvif->is_started);
3790 ret = ath10k_vdev_stop(arvif);
3792 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3793 arvif->vdev_id, ret);
3795 arvif->is_started = false;
3798 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3800 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3801 sta->addr, arvif->vdev_id, ret);
3803 ath10k_mac_dec_num_stations(arvif);
3804 } else if (old_state == IEEE80211_STA_AUTH &&
3805 new_state == IEEE80211_STA_ASSOC &&
3806 (vif->type == NL80211_IFTYPE_AP ||
3807 vif->type == NL80211_IFTYPE_ADHOC)) {
3811 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3814 ret = ath10k_station_assoc(ar, vif, sta, false);
3816 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3817 sta->addr, arvif->vdev_id, ret);
3818 } else if (old_state == IEEE80211_STA_ASSOC &&
3819 new_state == IEEE80211_STA_AUTH &&
3820 (vif->type == NL80211_IFTYPE_AP ||
3821 vif->type == NL80211_IFTYPE_ADHOC)) {
3825 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3828 ret = ath10k_station_disassoc(ar, vif, sta);
3830 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3831 sta->addr, arvif->vdev_id, ret);
3834 mutex_unlock(&ar->conf_mutex);
3838 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3839 u16 ac, bool enable)
3841 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3845 lockdep_assert_held(&ar->conf_mutex);
3847 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3851 case IEEE80211_AC_VO:
3852 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3853 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3855 case IEEE80211_AC_VI:
3856 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3857 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3859 case IEEE80211_AC_BE:
3860 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3861 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3863 case IEEE80211_AC_BK:
3864 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3865 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3870 arvif->u.sta.uapsd |= value;
3872 arvif->u.sta.uapsd &= ~value;
3874 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3875 WMI_STA_PS_PARAM_UAPSD,
3876 arvif->u.sta.uapsd);
3878 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3882 if (arvif->u.sta.uapsd)
3883 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3885 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3887 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3888 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3891 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3893 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3895 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3896 arvif->vdev_id, ret);
3900 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3902 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3903 arvif->vdev_id, ret);
3911 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3912 struct ieee80211_vif *vif, u16 ac,
3913 const struct ieee80211_tx_queue_params *params)
3915 struct ath10k *ar = hw->priv;
3916 struct wmi_wmm_params_arg *p = NULL;
3919 mutex_lock(&ar->conf_mutex);
3922 case IEEE80211_AC_VO:
3923 p = &ar->wmm_params.ac_vo;
3925 case IEEE80211_AC_VI:
3926 p = &ar->wmm_params.ac_vi;
3928 case IEEE80211_AC_BE:
3929 p = &ar->wmm_params.ac_be;
3931 case IEEE80211_AC_BK:
3932 p = &ar->wmm_params.ac_bk;
3941 p->cwmin = params->cw_min;
3942 p->cwmax = params->cw_max;
3943 p->aifs = params->aifs;
3946 * The channel time duration programmed in the HW is in absolute
3947 * microseconds, while mac80211 gives the txop in units of
3950 p->txop = params->txop * 32;
3952 /* FIXME: FW accepts wmm params per hw, not per vif */
3953 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3955 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3959 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3961 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3964 mutex_unlock(&ar->conf_mutex);
3968 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3970 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3971 struct ieee80211_vif *vif,
3972 struct ieee80211_channel *chan,
3974 enum ieee80211_roc_type type)
3976 struct ath10k *ar = hw->priv;
3977 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3978 struct wmi_start_scan_arg arg;
3981 mutex_lock(&ar->conf_mutex);
3983 spin_lock_bh(&ar->data_lock);
3984 switch (ar->scan.state) {
3985 case ATH10K_SCAN_IDLE:
3986 reinit_completion(&ar->scan.started);
3987 reinit_completion(&ar->scan.completed);
3988 reinit_completion(&ar->scan.on_channel);
3989 ar->scan.state = ATH10K_SCAN_STARTING;
3990 ar->scan.is_roc = true;
3991 ar->scan.vdev_id = arvif->vdev_id;
3992 ar->scan.roc_freq = chan->center_freq;
3995 case ATH10K_SCAN_STARTING:
3996 case ATH10K_SCAN_RUNNING:
3997 case ATH10K_SCAN_ABORTING:
4001 spin_unlock_bh(&ar->data_lock);
4006 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4008 memset(&arg, 0, sizeof(arg));
4009 ath10k_wmi_start_scan_init(ar, &arg);
4010 arg.vdev_id = arvif->vdev_id;
4011 arg.scan_id = ATH10K_SCAN_ID;
4013 arg.channels[0] = chan->center_freq;
4014 arg.dwell_time_active = duration;
4015 arg.dwell_time_passive = duration;
4016 arg.max_scan_time = 2 * duration;
4017 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4018 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4020 ret = ath10k_start_scan(ar, &arg);
4022 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
4023 spin_lock_bh(&ar->data_lock);
4024 ar->scan.state = ATH10K_SCAN_IDLE;
4025 spin_unlock_bh(&ar->data_lock);
4029 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4031 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
4033 ret = ath10k_scan_stop(ar);
4035 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4043 mutex_unlock(&ar->conf_mutex);
4047 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4049 struct ath10k *ar = hw->priv;
4051 mutex_lock(&ar->conf_mutex);
4052 ath10k_scan_abort(ar);
4053 mutex_unlock(&ar->conf_mutex);
4055 cancel_delayed_work_sync(&ar->scan.timeout);
4061 * Both RTS and Fragmentation threshold are interface-specific
4062 * in ath10k, but device-specific in mac80211.
4065 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4067 struct ath10k *ar = hw->priv;
4068 struct ath10k_vif *arvif;
4071 mutex_lock(&ar->conf_mutex);
4072 list_for_each_entry(arvif, &ar->arvifs, list) {
4073 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
4074 arvif->vdev_id, value);
4076 ret = ath10k_mac_set_rts(arvif, value);
4078 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4079 arvif->vdev_id, ret);
4083 mutex_unlock(&ar->conf_mutex);
4088 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4089 u32 queues, bool drop)
4091 struct ath10k *ar = hw->priv;
4095 /* mac80211 doesn't care if we really xmit queued frames or not
4096 * we'll collect those frames either way if we stop/delete vdevs */
4100 mutex_lock(&ar->conf_mutex);
4102 if (ar->state == ATH10K_STATE_WEDGED)
4105 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
4108 spin_lock_bh(&ar->htt.tx_lock);
4109 empty = (ar->htt.num_pending_tx == 0);
4110 spin_unlock_bh(&ar->htt.tx_lock);
4112 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4113 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4117 }), ATH10K_FLUSH_TIMEOUT_HZ);
4119 if (ret <= 0 || skip)
4120 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4121 skip, ar->state, ret);
4124 mutex_unlock(&ar->conf_mutex);
4127 /* TODO: Implement this function properly
4128 * For now it is needed to reply to Probe Requests in IBSS mode.
4129 * Propably we need this information from FW.
4131 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4137 static int ath10k_suspend(struct ieee80211_hw *hw,
4138 struct cfg80211_wowlan *wowlan)
4140 struct ath10k *ar = hw->priv;
4143 mutex_lock(&ar->conf_mutex);
4145 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
4147 if (ret == -ETIMEDOUT)
4153 ret = ath10k_hif_suspend(ar);
4155 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
4162 ret = ath10k_wmi_pdev_resume_target(ar);
4164 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4168 mutex_unlock(&ar->conf_mutex);
4172 static int ath10k_resume(struct ieee80211_hw *hw)
4174 struct ath10k *ar = hw->priv;
4177 mutex_lock(&ar->conf_mutex);
4179 ret = ath10k_hif_resume(ar);
4181 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
4186 ret = ath10k_wmi_pdev_resume_target(ar);
4188 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4195 mutex_unlock(&ar->conf_mutex);
4200 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4201 enum ieee80211_reconfig_type reconfig_type)
4203 struct ath10k *ar = hw->priv;
4205 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4208 mutex_lock(&ar->conf_mutex);
4210 /* If device failed to restart it will be in a different state, e.g.
4211 * ATH10K_STATE_WEDGED */
4212 if (ar->state == ATH10K_STATE_RESTARTED) {
4213 ath10k_info(ar, "device successfully recovered\n");
4214 ar->state = ATH10K_STATE_ON;
4215 ieee80211_wake_queues(ar->hw);
4218 mutex_unlock(&ar->conf_mutex);
4221 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4222 struct survey_info *survey)
4224 struct ath10k *ar = hw->priv;
4225 struct ieee80211_supported_band *sband;
4226 struct survey_info *ar_survey = &ar->survey[idx];
4229 mutex_lock(&ar->conf_mutex);
4231 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4232 if (sband && idx >= sband->n_channels) {
4233 idx -= sband->n_channels;
4238 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4240 if (!sband || idx >= sband->n_channels) {
4245 spin_lock_bh(&ar->data_lock);
4246 memcpy(survey, ar_survey, sizeof(*survey));
4247 spin_unlock_bh(&ar->data_lock);
4249 survey->channel = &sband->channels[idx];
4251 if (ar->rx_channel == survey->channel)
4252 survey->filled |= SURVEY_INFO_IN_USE;
4255 mutex_unlock(&ar->conf_mutex);
4259 /* Helper table for legacy fixed_rate/bitrate_mask */
4260 static const u8 cck_ofdm_rate[] = {
4277 /* Check if only one bit set */
4278 static int ath10k_check_single_mask(u32 mask)
4286 mask &= ~BIT(bit - 1);
4294 ath10k_default_bitrate_mask(struct ath10k *ar,
4295 enum ieee80211_band band,
4296 const struct cfg80211_bitrate_mask *mask)
4298 u32 legacy = 0x00ff;
4301 u16 nrf = ar->num_rf_chains;
4303 if (ar->cfg_tx_chainmask)
4304 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4307 case IEEE80211_BAND_2GHZ:
4311 case IEEE80211_BAND_5GHZ:
4317 if (mask->control[band].legacy != legacy)
4320 for (i = 0; i < nrf; i++)
4321 if (mask->control[band].ht_mcs[i] != ht)
4324 for (i = 0; i < nrf; i++)
4325 if (mask->control[band].vht_mcs[i] != vht)
4332 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4333 enum ieee80211_band band,
4336 int ht_nss = 0, vht_nss = 0, i;
4339 if (ath10k_check_single_mask(mask->control[band].legacy))
4343 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4344 if (mask->control[band].ht_mcs[i] == 0xff)
4346 else if (mask->control[band].ht_mcs[i] == 0x00)
4355 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4356 if (mask->control[band].vht_mcs[i] == 0x03ff)
4358 else if (mask->control[band].vht_mcs[i] == 0x0000)
4366 if (ht_nss > 0 && vht_nss > 0)
4370 *fixed_nss = ht_nss;
4372 *fixed_nss = vht_nss;
4380 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4381 enum ieee80211_band band,
4382 enum wmi_rate_preamble *preamble)
4384 int legacy = 0, ht = 0, vht = 0, i;
4386 *preamble = WMI_RATE_PREAMBLE_OFDM;
4389 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4394 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4395 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4400 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4401 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4405 /* Currently we support only one fixed_rate */
4406 if ((legacy + ht + vht) != 1)
4410 *preamble = WMI_RATE_PREAMBLE_HT;
4412 *preamble = WMI_RATE_PREAMBLE_VHT;
4418 ath10k_bitrate_mask_rate(struct ath10k *ar,
4419 const struct cfg80211_bitrate_mask *mask,
4420 enum ieee80211_band band,
4424 u8 rate = 0, pream = 0, nss = 0, i;
4425 enum wmi_rate_preamble preamble;
4427 /* Check if single rate correct */
4428 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4434 case WMI_RATE_PREAMBLE_CCK:
4435 case WMI_RATE_PREAMBLE_OFDM:
4436 i = ffs(mask->control[band].legacy) - 1;
4438 if (band == IEEE80211_BAND_2GHZ && i < 4)
4439 pream = WMI_RATE_PREAMBLE_CCK;
4441 if (band == IEEE80211_BAND_5GHZ)
4444 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4447 rate = cck_ofdm_rate[i];
4449 case WMI_RATE_PREAMBLE_HT:
4450 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4451 if (mask->control[band].ht_mcs[i])
4454 if (i == IEEE80211_HT_MCS_MASK_LEN)
4457 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4460 case WMI_RATE_PREAMBLE_VHT:
4461 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4462 if (mask->control[band].vht_mcs[i])
4465 if (i == NL80211_VHT_NSS_MAX)
4468 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4473 *fixed_nss = nss + 1;
4477 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4480 *fixed_rate = pream | nss | rate;
4485 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4486 const struct cfg80211_bitrate_mask *mask,
4487 enum ieee80211_band band,
4491 /* First check full NSS mask, if we can simply limit NSS */
4492 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4495 /* Next Check single rate is set */
4496 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4499 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4504 struct ath10k *ar = arvif->ar;
4508 mutex_lock(&ar->conf_mutex);
4510 if (arvif->fixed_rate == fixed_rate &&
4511 arvif->fixed_nss == fixed_nss &&
4512 arvif->force_sgi == force_sgi)
4515 if (fixed_rate == WMI_FIXED_RATE_NONE)
4516 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4519 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4521 vdev_param = ar->wmi.vdev_param->fixed_rate;
4522 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4523 vdev_param, fixed_rate);
4525 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4531 arvif->fixed_rate = fixed_rate;
4533 vdev_param = ar->wmi.vdev_param->nss;
4534 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4535 vdev_param, fixed_nss);
4538 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4544 arvif->fixed_nss = fixed_nss;
4546 vdev_param = ar->wmi.vdev_param->sgi;
4547 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4551 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4557 arvif->force_sgi = force_sgi;
4560 mutex_unlock(&ar->conf_mutex);
4564 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4565 struct ieee80211_vif *vif,
4566 const struct cfg80211_bitrate_mask *mask)
4568 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4569 struct ath10k *ar = arvif->ar;
4570 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4571 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4572 u8 fixed_nss = ar->num_rf_chains;
4575 if (ar->cfg_tx_chainmask)
4576 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4578 force_sgi = mask->control[band].gi;
4579 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4582 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4583 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4589 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4590 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4594 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4595 fixed_nss, force_sgi);
4598 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4599 struct ieee80211_vif *vif,
4600 struct ieee80211_sta *sta,
4603 struct ath10k *ar = hw->priv;
4604 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4607 spin_lock_bh(&ar->data_lock);
4609 ath10k_dbg(ar, ATH10K_DBG_MAC,
4610 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4611 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4614 if (changed & IEEE80211_RC_BW_CHANGED) {
4615 bw = WMI_PEER_CHWIDTH_20MHZ;
4617 switch (sta->bandwidth) {
4618 case IEEE80211_STA_RX_BW_20:
4619 bw = WMI_PEER_CHWIDTH_20MHZ;
4621 case IEEE80211_STA_RX_BW_40:
4622 bw = WMI_PEER_CHWIDTH_40MHZ;
4624 case IEEE80211_STA_RX_BW_80:
4625 bw = WMI_PEER_CHWIDTH_80MHZ;
4627 case IEEE80211_STA_RX_BW_160:
4628 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4629 sta->bandwidth, sta->addr);
4630 bw = WMI_PEER_CHWIDTH_20MHZ;
4637 if (changed & IEEE80211_RC_NSS_CHANGED)
4638 arsta->nss = sta->rx_nss;
4640 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4641 smps = WMI_PEER_SMPS_PS_NONE;
4643 switch (sta->smps_mode) {
4644 case IEEE80211_SMPS_AUTOMATIC:
4645 case IEEE80211_SMPS_OFF:
4646 smps = WMI_PEER_SMPS_PS_NONE;
4648 case IEEE80211_SMPS_STATIC:
4649 smps = WMI_PEER_SMPS_STATIC;
4651 case IEEE80211_SMPS_DYNAMIC:
4652 smps = WMI_PEER_SMPS_DYNAMIC;
4654 case IEEE80211_SMPS_NUM_MODES:
4655 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4656 sta->smps_mode, sta->addr);
4657 smps = WMI_PEER_SMPS_PS_NONE;
4664 arsta->changed |= changed;
4666 spin_unlock_bh(&ar->data_lock);
4668 ieee80211_queue_work(hw, &arsta->update_wk);
4671 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4674 * FIXME: Return 0 for time being. Need to figure out whether FW
4675 * has the API to fetch 64-bit local TSF
4681 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4682 struct ieee80211_vif *vif,
4683 enum ieee80211_ampdu_mlme_action action,
4684 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4687 struct ath10k *ar = hw->priv;
4688 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4690 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4691 arvif->vdev_id, sta->addr, tid, action);
4694 case IEEE80211_AMPDU_RX_START:
4695 case IEEE80211_AMPDU_RX_STOP:
4696 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4697 * creation/removal. Do we need to verify this?
4700 case IEEE80211_AMPDU_TX_START:
4701 case IEEE80211_AMPDU_TX_STOP_CONT:
4702 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4703 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4704 case IEEE80211_AMPDU_TX_OPERATIONAL:
4705 /* Firmware offloads Tx aggregation entirely so deny mac80211
4706 * Tx aggregation requests.
4714 static const struct ieee80211_ops ath10k_ops = {
4716 .start = ath10k_start,
4717 .stop = ath10k_stop,
4718 .config = ath10k_config,
4719 .add_interface = ath10k_add_interface,
4720 .remove_interface = ath10k_remove_interface,
4721 .configure_filter = ath10k_configure_filter,
4722 .bss_info_changed = ath10k_bss_info_changed,
4723 .hw_scan = ath10k_hw_scan,
4724 .cancel_hw_scan = ath10k_cancel_hw_scan,
4725 .set_key = ath10k_set_key,
4726 .sta_state = ath10k_sta_state,
4727 .conf_tx = ath10k_conf_tx,
4728 .remain_on_channel = ath10k_remain_on_channel,
4729 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4730 .set_rts_threshold = ath10k_set_rts_threshold,
4731 .flush = ath10k_flush,
4732 .tx_last_beacon = ath10k_tx_last_beacon,
4733 .set_antenna = ath10k_set_antenna,
4734 .get_antenna = ath10k_get_antenna,
4735 .reconfig_complete = ath10k_reconfig_complete,
4736 .get_survey = ath10k_get_survey,
4737 .set_bitrate_mask = ath10k_set_bitrate_mask,
4738 .sta_rc_update = ath10k_sta_rc_update,
4739 .get_tsf = ath10k_get_tsf,
4740 .ampdu_action = ath10k_ampdu_action,
4741 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4742 .get_et_stats = ath10k_debug_get_et_stats,
4743 .get_et_strings = ath10k_debug_get_et_strings,
4745 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4748 .suspend = ath10k_suspend,
4749 .resume = ath10k_resume,
4753 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4754 .bitrate = (_rate), \
4755 .flags = (_flags), \
4756 .hw_value = (_rateid), \
4759 #define CHAN2G(_channel, _freq, _flags) { \
4760 .band = IEEE80211_BAND_2GHZ, \
4761 .hw_value = (_channel), \
4762 .center_freq = (_freq), \
4763 .flags = (_flags), \
4764 .max_antenna_gain = 0, \
4768 #define CHAN5G(_channel, _freq, _flags) { \
4769 .band = IEEE80211_BAND_5GHZ, \
4770 .hw_value = (_channel), \
4771 .center_freq = (_freq), \
4772 .flags = (_flags), \
4773 .max_antenna_gain = 0, \
4777 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4787 CHAN2G(10, 2457, 0),
4788 CHAN2G(11, 2462, 0),
4789 CHAN2G(12, 2467, 0),
4790 CHAN2G(13, 2472, 0),
4791 CHAN2G(14, 2484, 0),
4794 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4795 CHAN5G(36, 5180, 0),
4796 CHAN5G(40, 5200, 0),
4797 CHAN5G(44, 5220, 0),
4798 CHAN5G(48, 5240, 0),
4799 CHAN5G(52, 5260, 0),
4800 CHAN5G(56, 5280, 0),
4801 CHAN5G(60, 5300, 0),
4802 CHAN5G(64, 5320, 0),
4803 CHAN5G(100, 5500, 0),
4804 CHAN5G(104, 5520, 0),
4805 CHAN5G(108, 5540, 0),
4806 CHAN5G(112, 5560, 0),
4807 CHAN5G(116, 5580, 0),
4808 CHAN5G(120, 5600, 0),
4809 CHAN5G(124, 5620, 0),
4810 CHAN5G(128, 5640, 0),
4811 CHAN5G(132, 5660, 0),
4812 CHAN5G(136, 5680, 0),
4813 CHAN5G(140, 5700, 0),
4814 CHAN5G(149, 5745, 0),
4815 CHAN5G(153, 5765, 0),
4816 CHAN5G(157, 5785, 0),
4817 CHAN5G(161, 5805, 0),
4818 CHAN5G(165, 5825, 0),
4821 /* Note: Be careful if you re-order these. There is code which depends on this
4824 static struct ieee80211_rate ath10k_rates[] = {
4826 RATETAB_ENT(10, 0x82, 0),
4827 RATETAB_ENT(20, 0x84, 0),
4828 RATETAB_ENT(55, 0x8b, 0),
4829 RATETAB_ENT(110, 0x96, 0),
4831 RATETAB_ENT(60, 0x0c, 0),
4832 RATETAB_ENT(90, 0x12, 0),
4833 RATETAB_ENT(120, 0x18, 0),
4834 RATETAB_ENT(180, 0x24, 0),
4835 RATETAB_ENT(240, 0x30, 0),
4836 RATETAB_ENT(360, 0x48, 0),
4837 RATETAB_ENT(480, 0x60, 0),
4838 RATETAB_ENT(540, 0x6c, 0),
4841 #define ath10k_a_rates (ath10k_rates + 4)
4842 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4843 #define ath10k_g_rates (ath10k_rates + 0)
4844 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4846 struct ath10k *ath10k_mac_create(size_t priv_size)
4848 struct ieee80211_hw *hw;
4851 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4861 void ath10k_mac_destroy(struct ath10k *ar)
4863 ieee80211_free_hw(ar->hw);
4866 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4869 .types = BIT(NL80211_IFTYPE_STATION)
4870 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4874 .types = BIT(NL80211_IFTYPE_P2P_GO)
4878 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
4882 .types = BIT(NL80211_IFTYPE_AP)
4886 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4889 .types = BIT(NL80211_IFTYPE_AP)
4893 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4895 .limits = ath10k_if_limits,
4896 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4897 .max_interfaces = 8,
4898 .num_different_channels = 1,
4899 .beacon_int_infra_match = true,
4903 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4905 .limits = ath10k_10x_if_limits,
4906 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4907 .max_interfaces = 8,
4908 .num_different_channels = 1,
4909 .beacon_int_infra_match = true,
4910 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4911 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4912 BIT(NL80211_CHAN_WIDTH_20) |
4913 BIT(NL80211_CHAN_WIDTH_40) |
4914 BIT(NL80211_CHAN_WIDTH_80),
4919 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4921 struct ieee80211_sta_vht_cap vht_cap = {0};
4925 vht_cap.vht_supported = 1;
4926 vht_cap.cap = ar->vht_cap_info;
4929 for (i = 0; i < 8; i++) {
4930 if (i < ar->num_rf_chains)
4931 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4933 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4936 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4937 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4942 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4945 struct ieee80211_sta_ht_cap ht_cap = {0};
4947 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4950 ht_cap.ht_supported = 1;
4951 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4952 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4953 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4954 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4955 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4957 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4958 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4960 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4961 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4963 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4966 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4967 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4972 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4973 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4975 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4978 stbc = ar->ht_cap_info;
4979 stbc &= WMI_HT_CAP_RX_STBC;
4980 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4981 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4982 stbc &= IEEE80211_HT_CAP_RX_STBC;
4987 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4988 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4990 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4991 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4993 /* max AMSDU is implicitly taken from vht_cap_info */
4994 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4995 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4997 for (i = 0; i < ar->num_rf_chains; i++)
4998 ht_cap.mcs.rx_mask[i] = 0xFF;
5000 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5005 static void ath10k_get_arvif_iter(void *data, u8 *mac,
5006 struct ieee80211_vif *vif)
5008 struct ath10k_vif_iter *arvif_iter = data;
5009 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5011 if (arvif->vdev_id == arvif_iter->vdev_id)
5012 arvif_iter->arvif = arvif;
5015 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5017 struct ath10k_vif_iter arvif_iter;
5020 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5021 arvif_iter.vdev_id = vdev_id;
5023 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5024 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5026 ath10k_get_arvif_iter,
5028 if (!arvif_iter.arvif) {
5029 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
5033 return arvif_iter.arvif;
5036 int ath10k_mac_register(struct ath10k *ar)
5038 struct ieee80211_supported_band *band;
5039 struct ieee80211_sta_vht_cap vht_cap;
5040 struct ieee80211_sta_ht_cap ht_cap;
5044 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5046 SET_IEEE80211_DEV(ar->hw, ar->dev);
5048 ht_cap = ath10k_get_ht_cap(ar);
5049 vht_cap = ath10k_create_vht_cap(ar);
5051 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5052 channels = kmemdup(ath10k_2ghz_channels,
5053 sizeof(ath10k_2ghz_channels),
5060 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5061 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5062 band->channels = channels;
5063 band->n_bitrates = ath10k_g_rates_size;
5064 band->bitrates = ath10k_g_rates;
5065 band->ht_cap = ht_cap;
5067 /* vht is not supported in 2.4 GHz */
5069 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5072 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5073 channels = kmemdup(ath10k_5ghz_channels,
5074 sizeof(ath10k_5ghz_channels),
5081 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5082 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5083 band->channels = channels;
5084 band->n_bitrates = ath10k_a_rates_size;
5085 band->bitrates = ath10k_a_rates;
5086 band->ht_cap = ht_cap;
5087 band->vht_cap = vht_cap;
5088 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5091 ar->hw->wiphy->interface_modes =
5092 BIT(NL80211_IFTYPE_STATION) |
5093 BIT(NL80211_IFTYPE_AP);
5095 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5096 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5098 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5099 ar->hw->wiphy->interface_modes |=
5100 BIT(NL80211_IFTYPE_P2P_DEVICE) |
5101 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5102 BIT(NL80211_IFTYPE_P2P_GO);
5104 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5105 IEEE80211_HW_SUPPORTS_PS |
5106 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5107 IEEE80211_HW_MFP_CAPABLE |
5108 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5109 IEEE80211_HW_HAS_RATE_CONTROL |
5110 IEEE80211_HW_AP_LINK_PS |
5111 IEEE80211_HW_SPECTRUM_MGMT;
5113 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5115 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5116 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
5118 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5119 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5120 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5123 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5124 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5126 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
5127 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5129 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5131 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
5132 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5133 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5135 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5136 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5139 * on LL hardware queues are managed entirely by the FW
5140 * so we only advertise to mac we can do the queues thing
5144 switch (ar->wmi.op_version) {
5145 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5146 case ATH10K_FW_WMI_OP_VERSION_TLV:
5147 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5148 ar->hw->wiphy->n_iface_combinations =
5149 ARRAY_SIZE(ath10k_if_comb);
5150 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
5152 case ATH10K_FW_WMI_OP_VERSION_10_1:
5153 case ATH10K_FW_WMI_OP_VERSION_10_2:
5154 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
5155 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5156 ar->hw->wiphy->n_iface_combinations =
5157 ARRAY_SIZE(ath10k_10x_if_comb);
5159 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5160 case ATH10K_FW_WMI_OP_VERSION_MAX:
5166 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5168 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5169 /* Init ath dfs pattern detector */
5170 ar->ath_common.debug_mask = ATH_DBG_DFS;
5171 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5174 if (!ar->dfs_detector)
5175 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
5178 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5179 ath10k_reg_notifier);
5181 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
5185 ret = ieee80211_register_hw(ar->hw);
5187 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
5191 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5192 ret = regulatory_hint(ar->hw->wiphy,
5193 ar->ath_common.regulatory.alpha2);
5195 goto err_unregister;
5201 ieee80211_unregister_hw(ar->hw);
5203 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5204 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5209 void ath10k_mac_unregister(struct ath10k *ar)
5211 ieee80211_unregister_hw(ar->hw);
5213 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5214 ar->dfs_detector->exit(ar->dfs_detector);
5216 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5217 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5219 SET_IEEE80211_DEV(ar->hw, NULL);