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 mutex_lock(&ar->conf_mutex);
2953 memset(arvif, 0, sizeof(*arvif));
2958 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2959 INIT_LIST_HEAD(&arvif->list);
2961 if (ar->free_vdev_map == 0) {
2962 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2966 bit = __ffs64(ar->free_vdev_map);
2968 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2969 bit, ar->free_vdev_map);
2971 arvif->vdev_id = bit;
2972 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2974 switch (vif->type) {
2975 case NL80211_IFTYPE_P2P_DEVICE:
2976 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2977 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2979 case NL80211_IFTYPE_UNSPECIFIED:
2980 case NL80211_IFTYPE_STATION:
2981 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2983 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2985 case NL80211_IFTYPE_ADHOC:
2986 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2988 case NL80211_IFTYPE_AP:
2989 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2992 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2994 case NL80211_IFTYPE_MONITOR:
2995 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3002 /* Some firmware revisions don't wait for beacon tx completion before
3003 * sending another SWBA event. This could lead to hardware using old
3004 * (freed) beacon data in some cases, e.g. tx credit starvation
3005 * combined with missed TBTT. This is very very rare.
3007 * On non-IOMMU-enabled hosts this could be a possible security issue
3008 * because hw could beacon some random data on the air. On
3009 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3010 * device would crash.
3012 * Since there are no beacon tx completions (implicit nor explicit)
3013 * propagated to host the only workaround for this is to allocate a
3014 * DMA-coherent buffer for a lifetime of a vif and use it for all
3015 * beacon tx commands. Worst case for this approach is some beacons may
3016 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3018 if (vif->type == NL80211_IFTYPE_ADHOC ||
3019 vif->type == NL80211_IFTYPE_AP) {
3020 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3021 IEEE80211_MAX_FRAME_LEN,
3022 &arvif->beacon_paddr,
3024 if (!arvif->beacon_buf) {
3026 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3032 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3033 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3034 arvif->beacon_buf ? "single-buf" : "per-skb");
3036 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3037 arvif->vdev_subtype, vif->addr);
3039 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
3040 arvif->vdev_id, ret);
3044 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
3045 list_add(&arvif->list, &ar->arvifs);
3047 vdev_param = ar->wmi.vdev_param->def_keyid;
3048 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
3049 arvif->def_wep_key_idx);
3051 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
3052 arvif->vdev_id, ret);
3053 goto err_vdev_delete;
3056 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3057 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3058 ATH10K_HW_TXRX_NATIVE_WIFI);
3059 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3060 if (ret && ret != -EOPNOTSUPP) {
3061 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
3062 arvif->vdev_id, ret);
3063 goto err_vdev_delete;
3066 if (ar->cfg_tx_chainmask) {
3067 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3069 vdev_param = ar->wmi.vdev_param->nss;
3070 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3073 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3074 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3076 goto err_vdev_delete;
3080 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3081 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3083 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
3084 arvif->vdev_id, ret);
3085 goto err_vdev_delete;
3088 ret = ath10k_mac_set_kickout(arvif);
3090 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
3091 arvif->vdev_id, ret);
3092 goto err_peer_delete;
3096 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3097 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3098 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3099 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3102 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
3103 arvif->vdev_id, ret);
3104 goto err_peer_delete;
3107 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3109 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3110 arvif->vdev_id, ret);
3111 goto err_peer_delete;
3114 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3116 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3117 arvif->vdev_id, ret);
3118 goto err_peer_delete;
3122 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
3124 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3125 arvif->vdev_id, ret);
3126 goto err_peer_delete;
3129 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
3131 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
3132 arvif->vdev_id, ret);
3133 goto err_peer_delete;
3136 arvif->txpower = vif->bss_conf.txpower;
3137 ret = ath10k_mac_txpower_recalc(ar);
3139 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3140 goto err_peer_delete;
3143 mutex_unlock(&ar->conf_mutex);
3147 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3148 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3151 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3152 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3153 list_del(&arvif->list);
3156 if (arvif->beacon_buf) {
3157 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3158 arvif->beacon_buf, arvif->beacon_paddr);
3159 arvif->beacon_buf = NULL;
3162 mutex_unlock(&ar->conf_mutex);
3167 static void ath10k_remove_interface(struct ieee80211_hw *hw,
3168 struct ieee80211_vif *vif)
3170 struct ath10k *ar = hw->priv;
3171 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3174 cancel_work_sync(&arvif->wep_key_work);
3176 mutex_lock(&ar->conf_mutex);
3178 spin_lock_bh(&ar->data_lock);
3179 ath10k_mac_vif_beacon_cleanup(arvif);
3180 spin_unlock_bh(&ar->data_lock);
3182 ret = ath10k_spectral_vif_stop(arvif);
3184 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
3185 arvif->vdev_id, ret);
3187 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3188 list_del(&arvif->list);
3190 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3191 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3193 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
3194 arvif->vdev_id, ret);
3196 kfree(arvif->u.ap.noa_data);
3199 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3202 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3204 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3205 arvif->vdev_id, ret);
3207 ath10k_peer_cleanup(ar, arvif->vdev_id);
3209 mutex_unlock(&ar->conf_mutex);
3213 * FIXME: Has to be verified.
3215 #define SUPPORTED_FILTERS \
3216 (FIF_PROMISC_IN_BSS | \
3221 FIF_BCN_PRBRESP_PROMISC | \
3225 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3226 unsigned int changed_flags,
3227 unsigned int *total_flags,
3230 struct ath10k *ar = hw->priv;
3233 mutex_lock(&ar->conf_mutex);
3235 changed_flags &= SUPPORTED_FILTERS;
3236 *total_flags &= SUPPORTED_FILTERS;
3237 ar->filter_flags = *total_flags;
3239 ret = ath10k_monitor_recalc(ar);
3241 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3243 mutex_unlock(&ar->conf_mutex);
3246 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3247 struct ieee80211_vif *vif,
3248 struct ieee80211_bss_conf *info,
3251 struct ath10k *ar = hw->priv;
3252 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3254 u32 vdev_param, pdev_param, slottime, preamble;
3256 mutex_lock(&ar->conf_mutex);
3258 if (changed & BSS_CHANGED_IBSS)
3259 ath10k_control_ibss(arvif, info, vif->addr);
3261 if (changed & BSS_CHANGED_BEACON_INT) {
3262 arvif->beacon_interval = info->beacon_int;
3263 vdev_param = ar->wmi.vdev_param->beacon_interval;
3264 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3265 arvif->beacon_interval);
3266 ath10k_dbg(ar, ATH10K_DBG_MAC,
3267 "mac vdev %d beacon_interval %d\n",
3268 arvif->vdev_id, arvif->beacon_interval);
3271 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3272 arvif->vdev_id, ret);
3275 if (changed & BSS_CHANGED_BEACON) {
3276 ath10k_dbg(ar, ATH10K_DBG_MAC,
3277 "vdev %d set beacon tx mode to staggered\n",
3280 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3281 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3282 WMI_BEACON_STAGGERED_MODE);
3284 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3285 arvif->vdev_id, ret);
3288 if (changed & BSS_CHANGED_BEACON_INFO) {
3289 arvif->dtim_period = info->dtim_period;
3291 ath10k_dbg(ar, ATH10K_DBG_MAC,
3292 "mac vdev %d dtim_period %d\n",
3293 arvif->vdev_id, arvif->dtim_period);
3295 vdev_param = ar->wmi.vdev_param->dtim_period;
3296 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3297 arvif->dtim_period);
3299 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3300 arvif->vdev_id, ret);
3303 if (changed & BSS_CHANGED_SSID &&
3304 vif->type == NL80211_IFTYPE_AP) {
3305 arvif->u.ap.ssid_len = info->ssid_len;
3307 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3308 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3311 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3312 ether_addr_copy(arvif->bssid, info->bssid);
3314 if (changed & BSS_CHANGED_BEACON_ENABLED)
3315 ath10k_control_beaconing(arvif, info);
3317 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3318 arvif->use_cts_prot = info->use_cts_prot;
3319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3320 arvif->vdev_id, info->use_cts_prot);
3322 ret = ath10k_recalc_rtscts_prot(arvif);
3324 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3325 arvif->vdev_id, ret);
3328 if (changed & BSS_CHANGED_ERP_SLOT) {
3329 if (info->use_short_slot)
3330 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3333 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3335 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3336 arvif->vdev_id, slottime);
3338 vdev_param = ar->wmi.vdev_param->slot_time;
3339 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3342 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3343 arvif->vdev_id, ret);
3346 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3347 if (info->use_short_preamble)
3348 preamble = WMI_VDEV_PREAMBLE_SHORT;
3350 preamble = WMI_VDEV_PREAMBLE_LONG;
3352 ath10k_dbg(ar, ATH10K_DBG_MAC,
3353 "mac vdev %d preamble %dn",
3354 arvif->vdev_id, preamble);
3356 vdev_param = ar->wmi.vdev_param->preamble;
3357 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3360 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3361 arvif->vdev_id, ret);
3364 if (changed & BSS_CHANGED_ASSOC) {
3366 /* Workaround: Make sure monitor vdev is not running
3367 * when associating to prevent some firmware revisions
3368 * (e.g. 10.1 and 10.2) from crashing.
3370 if (ar->monitor_started)
3371 ath10k_monitor_stop(ar);
3372 ath10k_bss_assoc(hw, vif, info);
3373 ath10k_monitor_recalc(ar);
3375 ath10k_bss_disassoc(hw, vif);
3379 if (changed & BSS_CHANGED_TXPOWER) {
3380 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3381 arvif->vdev_id, info->txpower);
3383 arvif->txpower = info->txpower;
3384 ret = ath10k_mac_txpower_recalc(ar);
3386 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3389 if (changed & BSS_CHANGED_PS) {
3390 ret = ath10k_mac_vif_setup_ps(arvif);
3392 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3393 arvif->vdev_id, ret);
3396 mutex_unlock(&ar->conf_mutex);
3399 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3400 struct ieee80211_vif *vif,
3401 struct ieee80211_scan_request *hw_req)
3403 struct ath10k *ar = hw->priv;
3404 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3405 struct cfg80211_scan_request *req = &hw_req->req;
3406 struct wmi_start_scan_arg arg;
3410 mutex_lock(&ar->conf_mutex);
3412 spin_lock_bh(&ar->data_lock);
3413 switch (ar->scan.state) {
3414 case ATH10K_SCAN_IDLE:
3415 reinit_completion(&ar->scan.started);
3416 reinit_completion(&ar->scan.completed);
3417 ar->scan.state = ATH10K_SCAN_STARTING;
3418 ar->scan.is_roc = false;
3419 ar->scan.vdev_id = arvif->vdev_id;
3422 case ATH10K_SCAN_STARTING:
3423 case ATH10K_SCAN_RUNNING:
3424 case ATH10K_SCAN_ABORTING:
3428 spin_unlock_bh(&ar->data_lock);
3433 memset(&arg, 0, sizeof(arg));
3434 ath10k_wmi_start_scan_init(ar, &arg);
3435 arg.vdev_id = arvif->vdev_id;
3436 arg.scan_id = ATH10K_SCAN_ID;
3439 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3442 arg.ie_len = req->ie_len;
3443 memcpy(arg.ie, req->ie, arg.ie_len);
3447 arg.n_ssids = req->n_ssids;
3448 for (i = 0; i < arg.n_ssids; i++) {
3449 arg.ssids[i].len = req->ssids[i].ssid_len;
3450 arg.ssids[i].ssid = req->ssids[i].ssid;
3453 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3456 if (req->n_channels) {
3457 arg.n_channels = req->n_channels;
3458 for (i = 0; i < arg.n_channels; i++)
3459 arg.channels[i] = req->channels[i]->center_freq;
3462 ret = ath10k_start_scan(ar, &arg);
3464 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3465 spin_lock_bh(&ar->data_lock);
3466 ar->scan.state = ATH10K_SCAN_IDLE;
3467 spin_unlock_bh(&ar->data_lock);
3471 mutex_unlock(&ar->conf_mutex);
3475 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3476 struct ieee80211_vif *vif)
3478 struct ath10k *ar = hw->priv;
3480 mutex_lock(&ar->conf_mutex);
3481 ath10k_scan_abort(ar);
3482 mutex_unlock(&ar->conf_mutex);
3484 cancel_delayed_work_sync(&ar->scan.timeout);
3487 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3488 struct ath10k_vif *arvif,
3489 enum set_key_cmd cmd,
3490 struct ieee80211_key_conf *key)
3492 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3495 /* 10.1 firmware branch requires default key index to be set to group
3496 * key index after installing it. Otherwise FW/HW Txes corrupted
3497 * frames with multi-vif APs. This is not required for main firmware
3498 * branch (e.g. 636).
3500 * FIXME: This has been tested only in AP. It remains unknown if this
3501 * is required for multi-vif STA interfaces on 10.1 */
3503 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3506 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3509 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3512 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3518 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3521 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3522 arvif->vdev_id, ret);
3525 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3526 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3527 struct ieee80211_key_conf *key)
3529 struct ath10k *ar = hw->priv;
3530 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3531 struct ath10k_peer *peer;
3532 const u8 *peer_addr;
3533 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3534 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3537 if (key->keyidx > WMI_MAX_KEY_INDEX)
3540 mutex_lock(&ar->conf_mutex);
3543 peer_addr = sta->addr;
3544 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3545 peer_addr = vif->bss_conf.bssid;
3547 peer_addr = vif->addr;
3549 key->hw_key_idx = key->keyidx;
3551 /* the peer should not disappear in mid-way (unless FW goes awry) since
3552 * we already hold conf_mutex. we just make sure its there now. */
3553 spin_lock_bh(&ar->data_lock);
3554 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3555 spin_unlock_bh(&ar->data_lock);
3558 if (cmd == SET_KEY) {
3559 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3564 /* if the peer doesn't exist there is no key to disable
3572 arvif->wep_keys[key->keyidx] = key;
3574 arvif->wep_keys[key->keyidx] = NULL;
3576 if (cmd == DISABLE_KEY)
3577 ath10k_clear_vdev_key(arvif, key);
3580 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3582 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3583 arvif->vdev_id, peer_addr, ret);
3587 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3589 spin_lock_bh(&ar->data_lock);
3590 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3591 if (peer && cmd == SET_KEY)
3592 peer->keys[key->keyidx] = key;
3593 else if (peer && cmd == DISABLE_KEY)
3594 peer->keys[key->keyidx] = NULL;
3595 else if (peer == NULL)
3596 /* impossible unless FW goes crazy */
3597 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3598 spin_unlock_bh(&ar->data_lock);
3601 mutex_unlock(&ar->conf_mutex);
3605 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3608 struct ath10k_vif *arvif;
3609 struct ath10k_sta *arsta;
3610 struct ieee80211_sta *sta;
3611 u32 changed, bw, nss, smps;
3614 arsta = container_of(wk, struct ath10k_sta, update_wk);
3615 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3616 arvif = arsta->arvif;
3619 spin_lock_bh(&ar->data_lock);
3621 changed = arsta->changed;
3628 spin_unlock_bh(&ar->data_lock);
3630 mutex_lock(&ar->conf_mutex);
3632 if (changed & IEEE80211_RC_BW_CHANGED) {
3633 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3636 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3637 WMI_PEER_CHAN_WIDTH, bw);
3639 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3640 sta->addr, bw, err);
3643 if (changed & IEEE80211_RC_NSS_CHANGED) {
3644 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3647 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3650 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3651 sta->addr, nss, err);
3654 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3655 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3658 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3659 WMI_PEER_SMPS_STATE, smps);
3661 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3662 sta->addr, smps, err);
3665 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
3666 changed & IEEE80211_RC_NSS_CHANGED) {
3667 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
3670 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3672 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3676 mutex_unlock(&ar->conf_mutex);
3679 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3681 struct ath10k *ar = arvif->ar;
3683 lockdep_assert_held(&ar->conf_mutex);
3685 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3686 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3689 if (ar->num_stations >= ar->max_num_stations)
3697 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3699 struct ath10k *ar = arvif->ar;
3701 lockdep_assert_held(&ar->conf_mutex);
3703 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3704 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3710 static int ath10k_sta_state(struct ieee80211_hw *hw,
3711 struct ieee80211_vif *vif,
3712 struct ieee80211_sta *sta,
3713 enum ieee80211_sta_state old_state,
3714 enum ieee80211_sta_state new_state)
3716 struct ath10k *ar = hw->priv;
3717 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3718 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3721 if (old_state == IEEE80211_STA_NOTEXIST &&
3722 new_state == IEEE80211_STA_NONE) {
3723 memset(arsta, 0, sizeof(*arsta));
3724 arsta->arvif = arvif;
3725 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3728 /* cancel must be done outside the mutex to avoid deadlock */
3729 if ((old_state == IEEE80211_STA_NONE &&
3730 new_state == IEEE80211_STA_NOTEXIST))
3731 cancel_work_sync(&arsta->update_wk);
3733 mutex_lock(&ar->conf_mutex);
3735 if (old_state == IEEE80211_STA_NOTEXIST &&
3736 new_state == IEEE80211_STA_NONE) {
3738 * New station addition.
3740 ath10k_dbg(ar, ATH10K_DBG_MAC,
3741 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3742 arvif->vdev_id, sta->addr,
3743 ar->num_stations + 1, ar->max_num_stations,
3744 ar->num_peers + 1, ar->max_num_peers);
3746 ret = ath10k_mac_inc_num_stations(arvif);
3748 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3749 ar->max_num_stations);
3753 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3755 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3756 sta->addr, arvif->vdev_id, ret);
3757 ath10k_mac_dec_num_stations(arvif);
3761 if (vif->type == NL80211_IFTYPE_STATION) {
3762 WARN_ON(arvif->is_started);
3764 ret = ath10k_vdev_start(arvif);
3766 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3767 arvif->vdev_id, ret);
3768 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3770 ath10k_mac_dec_num_stations(arvif);
3774 arvif->is_started = true;
3776 } else if ((old_state == IEEE80211_STA_NONE &&
3777 new_state == IEEE80211_STA_NOTEXIST)) {
3779 * Existing station deletion.
3781 ath10k_dbg(ar, ATH10K_DBG_MAC,
3782 "mac vdev %d peer delete %pM (sta gone)\n",
3783 arvif->vdev_id, sta->addr);
3785 if (vif->type == NL80211_IFTYPE_STATION) {
3786 WARN_ON(!arvif->is_started);
3788 ret = ath10k_vdev_stop(arvif);
3790 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3791 arvif->vdev_id, ret);
3793 arvif->is_started = false;
3796 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3798 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3799 sta->addr, arvif->vdev_id, ret);
3801 ath10k_mac_dec_num_stations(arvif);
3802 } else if (old_state == IEEE80211_STA_AUTH &&
3803 new_state == IEEE80211_STA_ASSOC &&
3804 (vif->type == NL80211_IFTYPE_AP ||
3805 vif->type == NL80211_IFTYPE_ADHOC)) {
3809 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3812 ret = ath10k_station_assoc(ar, vif, sta, false);
3814 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3815 sta->addr, arvif->vdev_id, ret);
3816 } else if (old_state == IEEE80211_STA_ASSOC &&
3817 new_state == IEEE80211_STA_AUTH &&
3818 (vif->type == NL80211_IFTYPE_AP ||
3819 vif->type == NL80211_IFTYPE_ADHOC)) {
3823 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3826 ret = ath10k_station_disassoc(ar, vif, sta);
3828 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3829 sta->addr, arvif->vdev_id, ret);
3832 mutex_unlock(&ar->conf_mutex);
3836 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3837 u16 ac, bool enable)
3839 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3843 lockdep_assert_held(&ar->conf_mutex);
3845 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3849 case IEEE80211_AC_VO:
3850 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3851 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3853 case IEEE80211_AC_VI:
3854 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3855 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3857 case IEEE80211_AC_BE:
3858 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3859 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3861 case IEEE80211_AC_BK:
3862 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3863 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3868 arvif->u.sta.uapsd |= value;
3870 arvif->u.sta.uapsd &= ~value;
3872 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3873 WMI_STA_PS_PARAM_UAPSD,
3874 arvif->u.sta.uapsd);
3876 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3880 if (arvif->u.sta.uapsd)
3881 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3883 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3885 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3886 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3889 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3891 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3893 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3894 arvif->vdev_id, ret);
3898 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3900 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3901 arvif->vdev_id, ret);
3909 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3910 struct ieee80211_vif *vif, u16 ac,
3911 const struct ieee80211_tx_queue_params *params)
3913 struct ath10k *ar = hw->priv;
3914 struct wmi_wmm_params_arg *p = NULL;
3917 mutex_lock(&ar->conf_mutex);
3920 case IEEE80211_AC_VO:
3921 p = &ar->wmm_params.ac_vo;
3923 case IEEE80211_AC_VI:
3924 p = &ar->wmm_params.ac_vi;
3926 case IEEE80211_AC_BE:
3927 p = &ar->wmm_params.ac_be;
3929 case IEEE80211_AC_BK:
3930 p = &ar->wmm_params.ac_bk;
3939 p->cwmin = params->cw_min;
3940 p->cwmax = params->cw_max;
3941 p->aifs = params->aifs;
3944 * The channel time duration programmed in the HW is in absolute
3945 * microseconds, while mac80211 gives the txop in units of
3948 p->txop = params->txop * 32;
3950 /* FIXME: FW accepts wmm params per hw, not per vif */
3951 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3953 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3957 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3959 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3962 mutex_unlock(&ar->conf_mutex);
3966 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3968 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3969 struct ieee80211_vif *vif,
3970 struct ieee80211_channel *chan,
3972 enum ieee80211_roc_type type)
3974 struct ath10k *ar = hw->priv;
3975 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3976 struct wmi_start_scan_arg arg;
3979 mutex_lock(&ar->conf_mutex);
3981 spin_lock_bh(&ar->data_lock);
3982 switch (ar->scan.state) {
3983 case ATH10K_SCAN_IDLE:
3984 reinit_completion(&ar->scan.started);
3985 reinit_completion(&ar->scan.completed);
3986 reinit_completion(&ar->scan.on_channel);
3987 ar->scan.state = ATH10K_SCAN_STARTING;
3988 ar->scan.is_roc = true;
3989 ar->scan.vdev_id = arvif->vdev_id;
3990 ar->scan.roc_freq = chan->center_freq;
3993 case ATH10K_SCAN_STARTING:
3994 case ATH10K_SCAN_RUNNING:
3995 case ATH10K_SCAN_ABORTING:
3999 spin_unlock_bh(&ar->data_lock);
4004 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4006 memset(&arg, 0, sizeof(arg));
4007 ath10k_wmi_start_scan_init(ar, &arg);
4008 arg.vdev_id = arvif->vdev_id;
4009 arg.scan_id = ATH10K_SCAN_ID;
4011 arg.channels[0] = chan->center_freq;
4012 arg.dwell_time_active = duration;
4013 arg.dwell_time_passive = duration;
4014 arg.max_scan_time = 2 * duration;
4015 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4016 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4018 ret = ath10k_start_scan(ar, &arg);
4020 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
4021 spin_lock_bh(&ar->data_lock);
4022 ar->scan.state = ATH10K_SCAN_IDLE;
4023 spin_unlock_bh(&ar->data_lock);
4027 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4029 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
4031 ret = ath10k_scan_stop(ar);
4033 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4041 mutex_unlock(&ar->conf_mutex);
4045 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4047 struct ath10k *ar = hw->priv;
4049 mutex_lock(&ar->conf_mutex);
4050 ath10k_scan_abort(ar);
4051 mutex_unlock(&ar->conf_mutex);
4053 cancel_delayed_work_sync(&ar->scan.timeout);
4059 * Both RTS and Fragmentation threshold are interface-specific
4060 * in ath10k, but device-specific in mac80211.
4063 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4065 struct ath10k *ar = hw->priv;
4066 struct ath10k_vif *arvif;
4069 mutex_lock(&ar->conf_mutex);
4070 list_for_each_entry(arvif, &ar->arvifs, list) {
4071 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
4072 arvif->vdev_id, value);
4074 ret = ath10k_mac_set_rts(arvif, value);
4076 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4077 arvif->vdev_id, ret);
4081 mutex_unlock(&ar->conf_mutex);
4086 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4087 u32 queues, bool drop)
4089 struct ath10k *ar = hw->priv;
4093 /* mac80211 doesn't care if we really xmit queued frames or not
4094 * we'll collect those frames either way if we stop/delete vdevs */
4098 mutex_lock(&ar->conf_mutex);
4100 if (ar->state == ATH10K_STATE_WEDGED)
4103 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
4106 spin_lock_bh(&ar->htt.tx_lock);
4107 empty = (ar->htt.num_pending_tx == 0);
4108 spin_unlock_bh(&ar->htt.tx_lock);
4110 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4111 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4115 }), ATH10K_FLUSH_TIMEOUT_HZ);
4117 if (ret <= 0 || skip)
4118 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4119 skip, ar->state, ret);
4122 mutex_unlock(&ar->conf_mutex);
4125 /* TODO: Implement this function properly
4126 * For now it is needed to reply to Probe Requests in IBSS mode.
4127 * Propably we need this information from FW.
4129 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4135 static int ath10k_suspend(struct ieee80211_hw *hw,
4136 struct cfg80211_wowlan *wowlan)
4138 struct ath10k *ar = hw->priv;
4141 mutex_lock(&ar->conf_mutex);
4143 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
4145 if (ret == -ETIMEDOUT)
4151 ret = ath10k_hif_suspend(ar);
4153 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
4160 ret = ath10k_wmi_pdev_resume_target(ar);
4162 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4166 mutex_unlock(&ar->conf_mutex);
4170 static int ath10k_resume(struct ieee80211_hw *hw)
4172 struct ath10k *ar = hw->priv;
4175 mutex_lock(&ar->conf_mutex);
4177 ret = ath10k_hif_resume(ar);
4179 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
4184 ret = ath10k_wmi_pdev_resume_target(ar);
4186 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4193 mutex_unlock(&ar->conf_mutex);
4198 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4199 enum ieee80211_reconfig_type reconfig_type)
4201 struct ath10k *ar = hw->priv;
4203 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4206 mutex_lock(&ar->conf_mutex);
4208 /* If device failed to restart it will be in a different state, e.g.
4209 * ATH10K_STATE_WEDGED */
4210 if (ar->state == ATH10K_STATE_RESTARTED) {
4211 ath10k_info(ar, "device successfully recovered\n");
4212 ar->state = ATH10K_STATE_ON;
4213 ieee80211_wake_queues(ar->hw);
4216 mutex_unlock(&ar->conf_mutex);
4219 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4220 struct survey_info *survey)
4222 struct ath10k *ar = hw->priv;
4223 struct ieee80211_supported_band *sband;
4224 struct survey_info *ar_survey = &ar->survey[idx];
4227 mutex_lock(&ar->conf_mutex);
4229 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4230 if (sband && idx >= sband->n_channels) {
4231 idx -= sband->n_channels;
4236 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4238 if (!sband || idx >= sband->n_channels) {
4243 spin_lock_bh(&ar->data_lock);
4244 memcpy(survey, ar_survey, sizeof(*survey));
4245 spin_unlock_bh(&ar->data_lock);
4247 survey->channel = &sband->channels[idx];
4249 if (ar->rx_channel == survey->channel)
4250 survey->filled |= SURVEY_INFO_IN_USE;
4253 mutex_unlock(&ar->conf_mutex);
4257 /* Helper table for legacy fixed_rate/bitrate_mask */
4258 static const u8 cck_ofdm_rate[] = {
4275 /* Check if only one bit set */
4276 static int ath10k_check_single_mask(u32 mask)
4284 mask &= ~BIT(bit - 1);
4292 ath10k_default_bitrate_mask(struct ath10k *ar,
4293 enum ieee80211_band band,
4294 const struct cfg80211_bitrate_mask *mask)
4296 u32 legacy = 0x00ff;
4299 u16 nrf = ar->num_rf_chains;
4301 if (ar->cfg_tx_chainmask)
4302 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4305 case IEEE80211_BAND_2GHZ:
4309 case IEEE80211_BAND_5GHZ:
4315 if (mask->control[band].legacy != legacy)
4318 for (i = 0; i < nrf; i++)
4319 if (mask->control[band].ht_mcs[i] != ht)
4322 for (i = 0; i < nrf; i++)
4323 if (mask->control[band].vht_mcs[i] != vht)
4330 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4331 enum ieee80211_band band,
4334 int ht_nss = 0, vht_nss = 0, i;
4337 if (ath10k_check_single_mask(mask->control[band].legacy))
4341 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4342 if (mask->control[band].ht_mcs[i] == 0xff)
4344 else if (mask->control[band].ht_mcs[i] == 0x00)
4353 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4354 if (mask->control[band].vht_mcs[i] == 0x03ff)
4356 else if (mask->control[band].vht_mcs[i] == 0x0000)
4364 if (ht_nss > 0 && vht_nss > 0)
4368 *fixed_nss = ht_nss;
4370 *fixed_nss = vht_nss;
4378 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4379 enum ieee80211_band band,
4380 enum wmi_rate_preamble *preamble)
4382 int legacy = 0, ht = 0, vht = 0, i;
4384 *preamble = WMI_RATE_PREAMBLE_OFDM;
4387 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4392 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4393 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4398 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4399 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4403 /* Currently we support only one fixed_rate */
4404 if ((legacy + ht + vht) != 1)
4408 *preamble = WMI_RATE_PREAMBLE_HT;
4410 *preamble = WMI_RATE_PREAMBLE_VHT;
4416 ath10k_bitrate_mask_rate(struct ath10k *ar,
4417 const struct cfg80211_bitrate_mask *mask,
4418 enum ieee80211_band band,
4422 u8 rate = 0, pream = 0, nss = 0, i;
4423 enum wmi_rate_preamble preamble;
4425 /* Check if single rate correct */
4426 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4432 case WMI_RATE_PREAMBLE_CCK:
4433 case WMI_RATE_PREAMBLE_OFDM:
4434 i = ffs(mask->control[band].legacy) - 1;
4436 if (band == IEEE80211_BAND_2GHZ && i < 4)
4437 pream = WMI_RATE_PREAMBLE_CCK;
4439 if (band == IEEE80211_BAND_5GHZ)
4442 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4445 rate = cck_ofdm_rate[i];
4447 case WMI_RATE_PREAMBLE_HT:
4448 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4449 if (mask->control[band].ht_mcs[i])
4452 if (i == IEEE80211_HT_MCS_MASK_LEN)
4455 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4458 case WMI_RATE_PREAMBLE_VHT:
4459 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4460 if (mask->control[band].vht_mcs[i])
4463 if (i == NL80211_VHT_NSS_MAX)
4466 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4471 *fixed_nss = nss + 1;
4475 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4478 *fixed_rate = pream | nss | rate;
4483 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4484 const struct cfg80211_bitrate_mask *mask,
4485 enum ieee80211_band band,
4489 /* First check full NSS mask, if we can simply limit NSS */
4490 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4493 /* Next Check single rate is set */
4494 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4497 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4502 struct ath10k *ar = arvif->ar;
4506 mutex_lock(&ar->conf_mutex);
4508 if (arvif->fixed_rate == fixed_rate &&
4509 arvif->fixed_nss == fixed_nss &&
4510 arvif->force_sgi == force_sgi)
4513 if (fixed_rate == WMI_FIXED_RATE_NONE)
4514 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4517 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4519 vdev_param = ar->wmi.vdev_param->fixed_rate;
4520 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4521 vdev_param, fixed_rate);
4523 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4529 arvif->fixed_rate = fixed_rate;
4531 vdev_param = ar->wmi.vdev_param->nss;
4532 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4533 vdev_param, fixed_nss);
4536 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4542 arvif->fixed_nss = fixed_nss;
4544 vdev_param = ar->wmi.vdev_param->sgi;
4545 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4549 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4555 arvif->force_sgi = force_sgi;
4558 mutex_unlock(&ar->conf_mutex);
4562 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4563 struct ieee80211_vif *vif,
4564 const struct cfg80211_bitrate_mask *mask)
4566 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4567 struct ath10k *ar = arvif->ar;
4568 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4569 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4570 u8 fixed_nss = ar->num_rf_chains;
4573 if (ar->cfg_tx_chainmask)
4574 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4576 force_sgi = mask->control[band].gi;
4577 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4580 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4581 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4587 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4588 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4592 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4593 fixed_nss, force_sgi);
4596 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4597 struct ieee80211_vif *vif,
4598 struct ieee80211_sta *sta,
4601 struct ath10k *ar = hw->priv;
4602 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4605 spin_lock_bh(&ar->data_lock);
4607 ath10k_dbg(ar, ATH10K_DBG_MAC,
4608 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4609 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4612 if (changed & IEEE80211_RC_BW_CHANGED) {
4613 bw = WMI_PEER_CHWIDTH_20MHZ;
4615 switch (sta->bandwidth) {
4616 case IEEE80211_STA_RX_BW_20:
4617 bw = WMI_PEER_CHWIDTH_20MHZ;
4619 case IEEE80211_STA_RX_BW_40:
4620 bw = WMI_PEER_CHWIDTH_40MHZ;
4622 case IEEE80211_STA_RX_BW_80:
4623 bw = WMI_PEER_CHWIDTH_80MHZ;
4625 case IEEE80211_STA_RX_BW_160:
4626 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4627 sta->bandwidth, sta->addr);
4628 bw = WMI_PEER_CHWIDTH_20MHZ;
4635 if (changed & IEEE80211_RC_NSS_CHANGED)
4636 arsta->nss = sta->rx_nss;
4638 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4639 smps = WMI_PEER_SMPS_PS_NONE;
4641 switch (sta->smps_mode) {
4642 case IEEE80211_SMPS_AUTOMATIC:
4643 case IEEE80211_SMPS_OFF:
4644 smps = WMI_PEER_SMPS_PS_NONE;
4646 case IEEE80211_SMPS_STATIC:
4647 smps = WMI_PEER_SMPS_STATIC;
4649 case IEEE80211_SMPS_DYNAMIC:
4650 smps = WMI_PEER_SMPS_DYNAMIC;
4652 case IEEE80211_SMPS_NUM_MODES:
4653 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4654 sta->smps_mode, sta->addr);
4655 smps = WMI_PEER_SMPS_PS_NONE;
4662 arsta->changed |= changed;
4664 spin_unlock_bh(&ar->data_lock);
4666 ieee80211_queue_work(hw, &arsta->update_wk);
4669 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4672 * FIXME: Return 0 for time being. Need to figure out whether FW
4673 * has the API to fetch 64-bit local TSF
4679 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4680 struct ieee80211_vif *vif,
4681 enum ieee80211_ampdu_mlme_action action,
4682 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4685 struct ath10k *ar = hw->priv;
4686 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4688 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4689 arvif->vdev_id, sta->addr, tid, action);
4692 case IEEE80211_AMPDU_RX_START:
4693 case IEEE80211_AMPDU_RX_STOP:
4694 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4695 * creation/removal. Do we need to verify this?
4698 case IEEE80211_AMPDU_TX_START:
4699 case IEEE80211_AMPDU_TX_STOP_CONT:
4700 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4701 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4702 case IEEE80211_AMPDU_TX_OPERATIONAL:
4703 /* Firmware offloads Tx aggregation entirely so deny mac80211
4704 * Tx aggregation requests.
4712 static const struct ieee80211_ops ath10k_ops = {
4714 .start = ath10k_start,
4715 .stop = ath10k_stop,
4716 .config = ath10k_config,
4717 .add_interface = ath10k_add_interface,
4718 .remove_interface = ath10k_remove_interface,
4719 .configure_filter = ath10k_configure_filter,
4720 .bss_info_changed = ath10k_bss_info_changed,
4721 .hw_scan = ath10k_hw_scan,
4722 .cancel_hw_scan = ath10k_cancel_hw_scan,
4723 .set_key = ath10k_set_key,
4724 .sta_state = ath10k_sta_state,
4725 .conf_tx = ath10k_conf_tx,
4726 .remain_on_channel = ath10k_remain_on_channel,
4727 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4728 .set_rts_threshold = ath10k_set_rts_threshold,
4729 .flush = ath10k_flush,
4730 .tx_last_beacon = ath10k_tx_last_beacon,
4731 .set_antenna = ath10k_set_antenna,
4732 .get_antenna = ath10k_get_antenna,
4733 .reconfig_complete = ath10k_reconfig_complete,
4734 .get_survey = ath10k_get_survey,
4735 .set_bitrate_mask = ath10k_set_bitrate_mask,
4736 .sta_rc_update = ath10k_sta_rc_update,
4737 .get_tsf = ath10k_get_tsf,
4738 .ampdu_action = ath10k_ampdu_action,
4739 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4740 .get_et_stats = ath10k_debug_get_et_stats,
4741 .get_et_strings = ath10k_debug_get_et_strings,
4743 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4746 .suspend = ath10k_suspend,
4747 .resume = ath10k_resume,
4751 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4752 .bitrate = (_rate), \
4753 .flags = (_flags), \
4754 .hw_value = (_rateid), \
4757 #define CHAN2G(_channel, _freq, _flags) { \
4758 .band = IEEE80211_BAND_2GHZ, \
4759 .hw_value = (_channel), \
4760 .center_freq = (_freq), \
4761 .flags = (_flags), \
4762 .max_antenna_gain = 0, \
4766 #define CHAN5G(_channel, _freq, _flags) { \
4767 .band = IEEE80211_BAND_5GHZ, \
4768 .hw_value = (_channel), \
4769 .center_freq = (_freq), \
4770 .flags = (_flags), \
4771 .max_antenna_gain = 0, \
4775 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4785 CHAN2G(10, 2457, 0),
4786 CHAN2G(11, 2462, 0),
4787 CHAN2G(12, 2467, 0),
4788 CHAN2G(13, 2472, 0),
4789 CHAN2G(14, 2484, 0),
4792 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4793 CHAN5G(36, 5180, 0),
4794 CHAN5G(40, 5200, 0),
4795 CHAN5G(44, 5220, 0),
4796 CHAN5G(48, 5240, 0),
4797 CHAN5G(52, 5260, 0),
4798 CHAN5G(56, 5280, 0),
4799 CHAN5G(60, 5300, 0),
4800 CHAN5G(64, 5320, 0),
4801 CHAN5G(100, 5500, 0),
4802 CHAN5G(104, 5520, 0),
4803 CHAN5G(108, 5540, 0),
4804 CHAN5G(112, 5560, 0),
4805 CHAN5G(116, 5580, 0),
4806 CHAN5G(120, 5600, 0),
4807 CHAN5G(124, 5620, 0),
4808 CHAN5G(128, 5640, 0),
4809 CHAN5G(132, 5660, 0),
4810 CHAN5G(136, 5680, 0),
4811 CHAN5G(140, 5700, 0),
4812 CHAN5G(149, 5745, 0),
4813 CHAN5G(153, 5765, 0),
4814 CHAN5G(157, 5785, 0),
4815 CHAN5G(161, 5805, 0),
4816 CHAN5G(165, 5825, 0),
4819 /* Note: Be careful if you re-order these. There is code which depends on this
4822 static struct ieee80211_rate ath10k_rates[] = {
4824 RATETAB_ENT(10, 0x82, 0),
4825 RATETAB_ENT(20, 0x84, 0),
4826 RATETAB_ENT(55, 0x8b, 0),
4827 RATETAB_ENT(110, 0x96, 0),
4829 RATETAB_ENT(60, 0x0c, 0),
4830 RATETAB_ENT(90, 0x12, 0),
4831 RATETAB_ENT(120, 0x18, 0),
4832 RATETAB_ENT(180, 0x24, 0),
4833 RATETAB_ENT(240, 0x30, 0),
4834 RATETAB_ENT(360, 0x48, 0),
4835 RATETAB_ENT(480, 0x60, 0),
4836 RATETAB_ENT(540, 0x6c, 0),
4839 #define ath10k_a_rates (ath10k_rates + 4)
4840 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4841 #define ath10k_g_rates (ath10k_rates + 0)
4842 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4844 struct ath10k *ath10k_mac_create(size_t priv_size)
4846 struct ieee80211_hw *hw;
4849 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4859 void ath10k_mac_destroy(struct ath10k *ar)
4861 ieee80211_free_hw(ar->hw);
4864 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4867 .types = BIT(NL80211_IFTYPE_STATION)
4868 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4872 .types = BIT(NL80211_IFTYPE_P2P_GO)
4876 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
4880 .types = BIT(NL80211_IFTYPE_AP)
4884 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4887 .types = BIT(NL80211_IFTYPE_AP)
4891 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4893 .limits = ath10k_if_limits,
4894 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4895 .max_interfaces = 8,
4896 .num_different_channels = 1,
4897 .beacon_int_infra_match = true,
4901 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4903 .limits = ath10k_10x_if_limits,
4904 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4905 .max_interfaces = 8,
4906 .num_different_channels = 1,
4907 .beacon_int_infra_match = true,
4908 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4909 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4910 BIT(NL80211_CHAN_WIDTH_20) |
4911 BIT(NL80211_CHAN_WIDTH_40) |
4912 BIT(NL80211_CHAN_WIDTH_80),
4917 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4919 struct ieee80211_sta_vht_cap vht_cap = {0};
4923 vht_cap.vht_supported = 1;
4924 vht_cap.cap = ar->vht_cap_info;
4927 for (i = 0; i < 8; i++) {
4928 if (i < ar->num_rf_chains)
4929 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4931 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4934 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4935 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4940 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4943 struct ieee80211_sta_ht_cap ht_cap = {0};
4945 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4948 ht_cap.ht_supported = 1;
4949 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4950 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4951 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4952 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4953 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4955 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4956 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4958 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4959 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4961 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4964 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4965 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4970 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4971 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4973 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4976 stbc = ar->ht_cap_info;
4977 stbc &= WMI_HT_CAP_RX_STBC;
4978 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4979 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4980 stbc &= IEEE80211_HT_CAP_RX_STBC;
4985 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4986 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4988 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4989 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4991 /* max AMSDU is implicitly taken from vht_cap_info */
4992 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4993 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4995 for (i = 0; i < ar->num_rf_chains; i++)
4996 ht_cap.mcs.rx_mask[i] = 0xFF;
4998 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5003 static void ath10k_get_arvif_iter(void *data, u8 *mac,
5004 struct ieee80211_vif *vif)
5006 struct ath10k_vif_iter *arvif_iter = data;
5007 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5009 if (arvif->vdev_id == arvif_iter->vdev_id)
5010 arvif_iter->arvif = arvif;
5013 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5015 struct ath10k_vif_iter arvif_iter;
5018 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5019 arvif_iter.vdev_id = vdev_id;
5021 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5022 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5024 ath10k_get_arvif_iter,
5026 if (!arvif_iter.arvif) {
5027 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
5031 return arvif_iter.arvif;
5034 int ath10k_mac_register(struct ath10k *ar)
5036 struct ieee80211_supported_band *band;
5037 struct ieee80211_sta_vht_cap vht_cap;
5038 struct ieee80211_sta_ht_cap ht_cap;
5042 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5044 SET_IEEE80211_DEV(ar->hw, ar->dev);
5046 ht_cap = ath10k_get_ht_cap(ar);
5047 vht_cap = ath10k_create_vht_cap(ar);
5049 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5050 channels = kmemdup(ath10k_2ghz_channels,
5051 sizeof(ath10k_2ghz_channels),
5058 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5059 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5060 band->channels = channels;
5061 band->n_bitrates = ath10k_g_rates_size;
5062 band->bitrates = ath10k_g_rates;
5063 band->ht_cap = ht_cap;
5065 /* vht is not supported in 2.4 GHz */
5067 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5070 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5071 channels = kmemdup(ath10k_5ghz_channels,
5072 sizeof(ath10k_5ghz_channels),
5079 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5080 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5081 band->channels = channels;
5082 band->n_bitrates = ath10k_a_rates_size;
5083 band->bitrates = ath10k_a_rates;
5084 band->ht_cap = ht_cap;
5085 band->vht_cap = vht_cap;
5086 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5089 ar->hw->wiphy->interface_modes =
5090 BIT(NL80211_IFTYPE_STATION) |
5091 BIT(NL80211_IFTYPE_AP);
5093 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5094 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5096 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5097 ar->hw->wiphy->interface_modes |=
5098 BIT(NL80211_IFTYPE_P2P_DEVICE) |
5099 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5100 BIT(NL80211_IFTYPE_P2P_GO);
5102 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5103 IEEE80211_HW_SUPPORTS_PS |
5104 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5105 IEEE80211_HW_SUPPORTS_UAPSD |
5106 IEEE80211_HW_MFP_CAPABLE |
5107 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5108 IEEE80211_HW_HAS_RATE_CONTROL |
5109 IEEE80211_HW_AP_LINK_PS |
5110 IEEE80211_HW_SPECTRUM_MGMT;
5112 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5114 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5115 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
5117 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5118 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5119 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5122 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5123 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5125 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
5126 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5128 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5130 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
5131 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5132 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5134 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5135 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5138 * on LL hardware queues are managed entirely by the FW
5139 * so we only advertise to mac we can do the queues thing
5143 switch (ar->wmi.op_version) {
5144 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5145 case ATH10K_FW_WMI_OP_VERSION_TLV:
5146 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5147 ar->hw->wiphy->n_iface_combinations =
5148 ARRAY_SIZE(ath10k_if_comb);
5149 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
5151 case ATH10K_FW_WMI_OP_VERSION_10_1:
5152 case ATH10K_FW_WMI_OP_VERSION_10_2:
5153 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
5154 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5155 ar->hw->wiphy->n_iface_combinations =
5156 ARRAY_SIZE(ath10k_10x_if_comb);
5158 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5159 case ATH10K_FW_WMI_OP_VERSION_MAX:
5165 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5167 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5168 /* Init ath dfs pattern detector */
5169 ar->ath_common.debug_mask = ATH_DBG_DFS;
5170 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5173 if (!ar->dfs_detector)
5174 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
5177 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5178 ath10k_reg_notifier);
5180 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
5184 ret = ieee80211_register_hw(ar->hw);
5186 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
5190 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5191 ret = regulatory_hint(ar->hw->wiphy,
5192 ar->ath_common.regulatory.alpha2);
5194 goto err_unregister;
5200 ieee80211_unregister_hw(ar->hw);
5202 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5203 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5208 void ath10k_mac_unregister(struct ath10k *ar)
5210 ieee80211_unregister_hw(ar->hw);
5212 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5213 ar->dfs_detector->exit(ar->dfs_detector);
5215 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5216 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5218 SET_IEEE80211_DEV(ar->hw, NULL);