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>
35 static int ath10k_send_key(struct ath10k_vif *arvif,
36 struct ieee80211_key_conf *key,
40 struct ath10k *ar = arvif->ar;
41 struct wmi_vdev_install_key_arg arg = {
42 .vdev_id = arvif->vdev_id,
43 .key_idx = key->keyidx,
44 .key_len = key->keylen,
49 lockdep_assert_held(&arvif->ar->conf_mutex);
51 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
52 arg.key_flags = WMI_KEY_PAIRWISE;
54 arg.key_flags = WMI_KEY_GROUP;
56 switch (key->cipher) {
57 case WLAN_CIPHER_SUITE_CCMP:
58 arg.key_cipher = WMI_CIPHER_AES_CCM;
59 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
60 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
62 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
64 case WLAN_CIPHER_SUITE_TKIP:
65 arg.key_cipher = WMI_CIPHER_TKIP;
66 arg.key_txmic_len = 8;
67 arg.key_rxmic_len = 8;
69 case WLAN_CIPHER_SUITE_WEP40:
70 case WLAN_CIPHER_SUITE_WEP104:
71 arg.key_cipher = WMI_CIPHER_WEP;
72 /* AP/IBSS mode requires self-key to be groupwise
73 * Otherwise pairwise key must be set */
74 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
75 arg.key_flags = WMI_KEY_PAIRWISE;
78 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
82 if (cmd == DISABLE_KEY) {
83 arg.key_cipher = WMI_CIPHER_NONE;
87 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
90 static int ath10k_install_key(struct ath10k_vif *arvif,
91 struct ieee80211_key_conf *key,
95 struct ath10k *ar = arvif->ar;
98 lockdep_assert_held(&ar->conf_mutex);
100 reinit_completion(&ar->install_key_done);
102 ret = ath10k_send_key(arvif, key, cmd, macaddr);
106 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
113 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
116 struct ath10k *ar = arvif->ar;
117 struct ath10k_peer *peer;
121 lockdep_assert_held(&ar->conf_mutex);
123 spin_lock_bh(&ar->data_lock);
124 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
125 spin_unlock_bh(&ar->data_lock);
130 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
131 if (arvif->wep_keys[i] == NULL)
134 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
139 spin_lock_bh(&ar->data_lock);
140 peer->keys[i] = arvif->wep_keys[i];
141 spin_unlock_bh(&ar->data_lock);
147 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
150 struct ath10k *ar = arvif->ar;
151 struct ath10k_peer *peer;
156 lockdep_assert_held(&ar->conf_mutex);
158 spin_lock_bh(&ar->data_lock);
159 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
160 spin_unlock_bh(&ar->data_lock);
165 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
166 if (peer->keys[i] == NULL)
169 ret = ath10k_install_key(arvif, peer->keys[i],
171 if (ret && first_errno == 0)
175 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
178 spin_lock_bh(&ar->data_lock);
179 peer->keys[i] = NULL;
180 spin_unlock_bh(&ar->data_lock);
186 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
189 struct ath10k_peer *peer;
192 lockdep_assert_held(&ar->data_lock);
194 /* We don't know which vdev this peer belongs to,
195 * since WMI doesn't give us that information.
197 * FIXME: multi-bss needs to be handled.
199 peer = ath10k_peer_find(ar, 0, addr);
203 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
204 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
211 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
212 struct ieee80211_key_conf *key)
214 struct ath10k *ar = arvif->ar;
215 struct ath10k_peer *peer;
221 lockdep_assert_held(&ar->conf_mutex);
224 /* since ath10k_install_key we can't hold data_lock all the
225 * time, so we try to remove the keys incrementally */
226 spin_lock_bh(&ar->data_lock);
228 list_for_each_entry(peer, &ar->peers, list) {
229 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
230 if (peer->keys[i] == key) {
231 ether_addr_copy(addr, peer->addr);
232 peer->keys[i] = NULL;
237 if (i < ARRAY_SIZE(peer->keys))
240 spin_unlock_bh(&ar->data_lock);
242 if (i == ARRAY_SIZE(peer->keys))
245 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
246 if (ret && first_errno == 0)
250 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
257 /*********************/
258 /* General utilities */
259 /*********************/
261 static inline enum wmi_phy_mode
262 chan_to_phymode(const struct cfg80211_chan_def *chandef)
264 enum wmi_phy_mode phymode = MODE_UNKNOWN;
266 switch (chandef->chan->band) {
267 case IEEE80211_BAND_2GHZ:
268 switch (chandef->width) {
269 case NL80211_CHAN_WIDTH_20_NOHT:
272 case NL80211_CHAN_WIDTH_20:
273 phymode = MODE_11NG_HT20;
275 case NL80211_CHAN_WIDTH_40:
276 phymode = MODE_11NG_HT40;
278 case NL80211_CHAN_WIDTH_5:
279 case NL80211_CHAN_WIDTH_10:
280 case NL80211_CHAN_WIDTH_80:
281 case NL80211_CHAN_WIDTH_80P80:
282 case NL80211_CHAN_WIDTH_160:
283 phymode = MODE_UNKNOWN;
287 case IEEE80211_BAND_5GHZ:
288 switch (chandef->width) {
289 case NL80211_CHAN_WIDTH_20_NOHT:
292 case NL80211_CHAN_WIDTH_20:
293 phymode = MODE_11NA_HT20;
295 case NL80211_CHAN_WIDTH_40:
296 phymode = MODE_11NA_HT40;
298 case NL80211_CHAN_WIDTH_80:
299 phymode = MODE_11AC_VHT80;
301 case NL80211_CHAN_WIDTH_5:
302 case NL80211_CHAN_WIDTH_10:
303 case NL80211_CHAN_WIDTH_80P80:
304 case NL80211_CHAN_WIDTH_160:
305 phymode = MODE_UNKNOWN;
313 WARN_ON(phymode == MODE_UNKNOWN);
317 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
320 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
321 * 0 for no restriction
330 switch (mpdudensity) {
336 /* Our lower layer calculations limit our precision to
352 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
356 lockdep_assert_held(&ar->conf_mutex);
358 if (ar->num_peers >= ar->max_num_peers)
361 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
363 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
368 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
370 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
380 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
382 struct ath10k *ar = arvif->ar;
386 param = ar->wmi.pdev_param->sta_kickout_th;
387 ret = ath10k_wmi_pdev_set_param(ar, param,
388 ATH10K_KICKOUT_THRESHOLD);
390 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
391 arvif->vdev_id, ret);
395 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
396 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
397 ATH10K_KEEPALIVE_MIN_IDLE);
399 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
400 arvif->vdev_id, ret);
404 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
405 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
406 ATH10K_KEEPALIVE_MAX_IDLE);
408 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
409 arvif->vdev_id, ret);
413 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
414 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
415 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
417 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
418 arvif->vdev_id, ret);
425 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
427 struct ath10k *ar = arvif->ar;
430 vdev_param = ar->wmi.vdev_param->rts_threshold;
431 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
434 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
436 struct ath10k *ar = arvif->ar;
439 if (value != 0xFFFFFFFF)
440 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
441 ATH10K_FRAGMT_THRESHOLD_MIN,
442 ATH10K_FRAGMT_THRESHOLD_MAX);
444 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
445 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
448 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
452 lockdep_assert_held(&ar->conf_mutex);
454 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
458 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
467 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
469 struct ath10k_peer *peer, *tmp;
471 lockdep_assert_held(&ar->conf_mutex);
473 spin_lock_bh(&ar->data_lock);
474 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
475 if (peer->vdev_id != vdev_id)
478 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
479 peer->addr, vdev_id);
481 list_del(&peer->list);
485 spin_unlock_bh(&ar->data_lock);
488 static void ath10k_peer_cleanup_all(struct ath10k *ar)
490 struct ath10k_peer *peer, *tmp;
492 lockdep_assert_held(&ar->conf_mutex);
494 spin_lock_bh(&ar->data_lock);
495 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
496 list_del(&peer->list);
499 spin_unlock_bh(&ar->data_lock);
502 ar->num_stations = 0;
505 /************************/
506 /* Interface management */
507 /************************/
509 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
511 struct ath10k *ar = arvif->ar;
513 lockdep_assert_held(&ar->data_lock);
518 if (!arvif->beacon_buf)
519 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
520 arvif->beacon->len, DMA_TO_DEVICE);
522 dev_kfree_skb_any(arvif->beacon);
524 arvif->beacon = NULL;
525 arvif->beacon_sent = false;
528 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
530 struct ath10k *ar = arvif->ar;
532 lockdep_assert_held(&ar->data_lock);
534 ath10k_mac_vif_beacon_free(arvif);
536 if (arvif->beacon_buf) {
537 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
538 arvif->beacon_buf, arvif->beacon_paddr);
539 arvif->beacon_buf = NULL;
543 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
547 lockdep_assert_held(&ar->conf_mutex);
549 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
552 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
553 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
560 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
562 struct cfg80211_chan_def *chandef = &ar->chandef;
563 struct ieee80211_channel *channel = chandef->chan;
564 struct wmi_vdev_start_request_arg arg = {};
567 lockdep_assert_held(&ar->conf_mutex);
569 arg.vdev_id = vdev_id;
570 arg.channel.freq = channel->center_freq;
571 arg.channel.band_center_freq1 = chandef->center_freq1;
573 /* TODO setup this dynamically, what in case we
574 don't have any vifs? */
575 arg.channel.mode = chan_to_phymode(chandef);
576 arg.channel.chan_radar =
577 !!(channel->flags & IEEE80211_CHAN_RADAR);
579 arg.channel.min_power = 0;
580 arg.channel.max_power = channel->max_power * 2;
581 arg.channel.max_reg_power = channel->max_reg_power * 2;
582 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
584 reinit_completion(&ar->vdev_setup_done);
586 ret = ath10k_wmi_vdev_start(ar, &arg);
588 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
593 ret = ath10k_vdev_setup_sync(ar);
595 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
600 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
602 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
607 ar->monitor_vdev_id = vdev_id;
609 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
610 ar->monitor_vdev_id);
614 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
616 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
617 ar->monitor_vdev_id, ret);
622 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
626 lockdep_assert_held(&ar->conf_mutex);
628 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
630 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
631 ar->monitor_vdev_id, ret);
633 reinit_completion(&ar->vdev_setup_done);
635 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
637 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
638 ar->monitor_vdev_id, ret);
640 ret = ath10k_vdev_setup_sync(ar);
642 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
643 ar->monitor_vdev_id, ret);
645 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
646 ar->monitor_vdev_id);
650 static int ath10k_monitor_vdev_create(struct ath10k *ar)
654 lockdep_assert_held(&ar->conf_mutex);
656 if (ar->free_vdev_map == 0) {
657 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
661 bit = __ffs64(ar->free_vdev_map);
663 ar->monitor_vdev_id = bit;
665 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
666 WMI_VDEV_TYPE_MONITOR,
669 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
670 ar->monitor_vdev_id, ret);
674 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
675 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
676 ar->monitor_vdev_id);
681 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
685 lockdep_assert_held(&ar->conf_mutex);
687 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
689 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
690 ar->monitor_vdev_id, ret);
694 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
696 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
697 ar->monitor_vdev_id);
701 static int ath10k_monitor_start(struct ath10k *ar)
705 lockdep_assert_held(&ar->conf_mutex);
707 ret = ath10k_monitor_vdev_create(ar);
709 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
713 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
715 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
716 ath10k_monitor_vdev_delete(ar);
720 ar->monitor_started = true;
721 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
726 static int ath10k_monitor_stop(struct ath10k *ar)
730 lockdep_assert_held(&ar->conf_mutex);
732 ret = ath10k_monitor_vdev_stop(ar);
734 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
738 ret = ath10k_monitor_vdev_delete(ar);
740 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
744 ar->monitor_started = false;
745 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
750 static int ath10k_monitor_recalc(struct ath10k *ar)
754 lockdep_assert_held(&ar->conf_mutex);
756 should_start = ar->monitor ||
757 ar->filter_flags & FIF_PROMISC_IN_BSS ||
758 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
760 ath10k_dbg(ar, ATH10K_DBG_MAC,
761 "mac monitor recalc started? %d should? %d\n",
762 ar->monitor_started, should_start);
764 if (should_start == ar->monitor_started)
768 return ath10k_monitor_start(ar);
770 return ath10k_monitor_stop(ar);
773 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
775 struct ath10k *ar = arvif->ar;
776 u32 vdev_param, rts_cts = 0;
778 lockdep_assert_held(&ar->conf_mutex);
780 vdev_param = ar->wmi.vdev_param->enable_rtscts;
782 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
783 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
785 if (arvif->num_legacy_stations > 0)
786 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
789 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
793 static int ath10k_start_cac(struct ath10k *ar)
797 lockdep_assert_held(&ar->conf_mutex);
799 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
801 ret = ath10k_monitor_recalc(ar);
803 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
804 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
808 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
809 ar->monitor_vdev_id);
814 static int ath10k_stop_cac(struct ath10k *ar)
816 lockdep_assert_held(&ar->conf_mutex);
818 /* CAC is not running - do nothing */
819 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
822 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
823 ath10k_monitor_stop(ar);
825 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
830 static void ath10k_recalc_radar_detection(struct ath10k *ar)
834 lockdep_assert_held(&ar->conf_mutex);
838 if (!ar->radar_enabled)
841 if (ar->num_started_vdevs > 0)
844 ret = ath10k_start_cac(ar);
847 * Not possible to start CAC on current channel so starting
848 * radiation is not allowed, make this channel DFS_UNAVAILABLE
849 * by indicating that radar was detected.
851 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
852 ieee80211_radar_detected(ar->hw);
856 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
858 struct ath10k *ar = arvif->ar;
859 struct cfg80211_chan_def *chandef = &ar->chandef;
860 struct wmi_vdev_start_request_arg arg = {};
863 lockdep_assert_held(&ar->conf_mutex);
865 reinit_completion(&ar->vdev_setup_done);
867 arg.vdev_id = arvif->vdev_id;
868 arg.dtim_period = arvif->dtim_period;
869 arg.bcn_intval = arvif->beacon_interval;
871 arg.channel.freq = chandef->chan->center_freq;
872 arg.channel.band_center_freq1 = chandef->center_freq1;
873 arg.channel.mode = chan_to_phymode(chandef);
875 arg.channel.min_power = 0;
876 arg.channel.max_power = chandef->chan->max_power * 2;
877 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
878 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
880 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
881 arg.ssid = arvif->u.ap.ssid;
882 arg.ssid_len = arvif->u.ap.ssid_len;
883 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
885 /* For now allow DFS for AP mode */
886 arg.channel.chan_radar =
887 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
888 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
889 arg.ssid = arvif->vif->bss_conf.ssid;
890 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
893 ath10k_dbg(ar, ATH10K_DBG_MAC,
894 "mac vdev %d start center_freq %d phymode %s\n",
895 arg.vdev_id, arg.channel.freq,
896 ath10k_wmi_phymode_str(arg.channel.mode));
899 ret = ath10k_wmi_vdev_restart(ar, &arg);
901 ret = ath10k_wmi_vdev_start(ar, &arg);
904 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
909 ret = ath10k_vdev_setup_sync(ar);
911 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
916 ar->num_started_vdevs++;
917 ath10k_recalc_radar_detection(ar);
922 static int ath10k_vdev_start(struct ath10k_vif *arvif)
924 return ath10k_vdev_start_restart(arvif, false);
927 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
929 return ath10k_vdev_start_restart(arvif, true);
932 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
934 struct ath10k *ar = arvif->ar;
937 lockdep_assert_held(&ar->conf_mutex);
939 reinit_completion(&ar->vdev_setup_done);
941 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
943 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
944 arvif->vdev_id, ret);
948 ret = ath10k_vdev_setup_sync(ar);
950 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
951 arvif->vdev_id, ret);
955 WARN_ON(ar->num_started_vdevs == 0);
957 if (ar->num_started_vdevs != 0) {
958 ar->num_started_vdevs--;
959 ath10k_recalc_radar_detection(ar);
965 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
966 struct ieee80211_bss_conf *info)
968 struct ath10k *ar = arvif->ar;
971 lockdep_assert_held(&arvif->ar->conf_mutex);
973 if (!info->enable_beacon) {
974 ath10k_vdev_stop(arvif);
976 arvif->is_started = false;
977 arvif->is_up = false;
979 spin_lock_bh(&arvif->ar->data_lock);
980 ath10k_mac_vif_beacon_free(arvif);
981 spin_unlock_bh(&arvif->ar->data_lock);
986 arvif->tx_seq_no = 0x1000;
988 ret = ath10k_vdev_start(arvif);
993 ether_addr_copy(arvif->bssid, info->bssid);
995 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
998 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
999 arvif->vdev_id, ret);
1000 ath10k_vdev_stop(arvif);
1004 arvif->is_started = true;
1005 arvif->is_up = true;
1007 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1010 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1011 struct ieee80211_bss_conf *info,
1012 const u8 self_peer[ETH_ALEN])
1014 struct ath10k *ar = arvif->ar;
1018 lockdep_assert_held(&arvif->ar->conf_mutex);
1020 if (!info->ibss_joined) {
1021 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1023 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1024 self_peer, arvif->vdev_id, ret);
1026 if (is_zero_ether_addr(arvif->bssid))
1029 memset(arvif->bssid, 0, ETH_ALEN);
1034 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1036 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1037 self_peer, arvif->vdev_id, ret);
1041 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1042 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1043 ATH10K_DEFAULT_ATIM);
1045 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1046 arvif->vdev_id, ret);
1050 * Review this when mac80211 gains per-interface powersave support.
1052 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1054 struct ath10k *ar = arvif->ar;
1055 struct ieee80211_conf *conf = &ar->hw->conf;
1056 enum wmi_sta_powersave_param param;
1057 enum wmi_sta_ps_mode psmode;
1060 lockdep_assert_held(&arvif->ar->conf_mutex);
1062 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1065 if (conf->flags & IEEE80211_CONF_PS) {
1066 psmode = WMI_STA_PS_MODE_ENABLED;
1067 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1069 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1070 conf->dynamic_ps_timeout);
1072 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1073 arvif->vdev_id, ret);
1077 psmode = WMI_STA_PS_MODE_DISABLED;
1080 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1081 arvif->vdev_id, psmode ? "enable" : "disable");
1083 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1085 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1086 psmode, arvif->vdev_id, ret);
1093 /**********************/
1094 /* Station management */
1095 /**********************/
1097 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1098 struct ieee80211_vif *vif)
1100 /* Some firmware revisions have unstable STA powersave when listen
1101 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1102 * generate NullFunc frames properly even if buffered frames have been
1103 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1104 * buffered frames. Often pinging the device from AP would simply fail.
1106 * As a workaround set it to 1.
1108 if (vif->type == NL80211_IFTYPE_STATION)
1111 return ar->hw->conf.listen_interval;
1114 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1115 struct ieee80211_vif *vif,
1116 struct ieee80211_sta *sta,
1117 struct wmi_peer_assoc_complete_arg *arg)
1119 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1121 lockdep_assert_held(&ar->conf_mutex);
1123 ether_addr_copy(arg->addr, sta->addr);
1124 arg->vdev_id = arvif->vdev_id;
1125 arg->peer_aid = sta->aid;
1126 arg->peer_flags |= WMI_PEER_AUTH;
1127 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1128 arg->peer_num_spatial_streams = 1;
1129 arg->peer_caps = vif->bss_conf.assoc_capability;
1132 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1133 struct ieee80211_vif *vif,
1134 struct wmi_peer_assoc_complete_arg *arg)
1136 struct ieee80211_bss_conf *info = &vif->bss_conf;
1137 struct cfg80211_bss *bss;
1138 const u8 *rsnie = NULL;
1139 const u8 *wpaie = NULL;
1141 lockdep_assert_held(&ar->conf_mutex);
1143 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1144 info->bssid, NULL, 0, 0, 0);
1146 const struct cfg80211_bss_ies *ies;
1149 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1151 ies = rcu_dereference(bss->ies);
1153 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1154 WLAN_OUI_TYPE_MICROSOFT_WPA,
1158 cfg80211_put_bss(ar->hw->wiphy, bss);
1161 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1162 if (rsnie || wpaie) {
1163 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1164 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1168 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1169 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1173 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1174 struct ieee80211_sta *sta,
1175 struct wmi_peer_assoc_complete_arg *arg)
1177 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1178 const struct ieee80211_supported_band *sband;
1179 const struct ieee80211_rate *rates;
1183 lockdep_assert_held(&ar->conf_mutex);
1185 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1186 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1187 rates = sband->bitrates;
1189 rateset->num_rates = 0;
1191 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1192 if (!(ratemask & 1))
1195 rateset->rates[rateset->num_rates] = rates->hw_value;
1196 rateset->num_rates++;
1200 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1201 struct ieee80211_sta *sta,
1202 struct wmi_peer_assoc_complete_arg *arg)
1204 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1208 lockdep_assert_held(&ar->conf_mutex);
1210 if (!ht_cap->ht_supported)
1213 arg->peer_flags |= WMI_PEER_HT;
1214 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1215 ht_cap->ampdu_factor)) - 1;
1217 arg->peer_mpdu_density =
1218 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1220 arg->peer_ht_caps = ht_cap->cap;
1221 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1223 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1224 arg->peer_flags |= WMI_PEER_LDPC;
1226 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1227 arg->peer_flags |= WMI_PEER_40MHZ;
1228 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1231 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1232 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1234 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1235 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1237 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1238 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1239 arg->peer_flags |= WMI_PEER_STBC;
1242 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1243 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1244 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1245 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1246 arg->peer_rate_caps |= stbc;
1247 arg->peer_flags |= WMI_PEER_STBC;
1250 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1251 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1252 else if (ht_cap->mcs.rx_mask[1])
1253 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1255 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1256 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1257 arg->peer_ht_rates.rates[n++] = i;
1260 * This is a workaround for HT-enabled STAs which break the spec
1261 * and have no HT capabilities RX mask (no HT RX MCS map).
1263 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1264 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1266 * Firmware asserts if such situation occurs.
1269 arg->peer_ht_rates.num_rates = 8;
1270 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1271 arg->peer_ht_rates.rates[i] = i;
1273 arg->peer_ht_rates.num_rates = n;
1274 arg->peer_num_spatial_streams = sta->rx_nss;
1277 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1279 arg->peer_ht_rates.num_rates,
1280 arg->peer_num_spatial_streams);
1283 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1284 struct ath10k_vif *arvif,
1285 struct ieee80211_sta *sta)
1291 lockdep_assert_held(&ar->conf_mutex);
1293 if (sta->wme && sta->uapsd_queues) {
1294 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1295 sta->uapsd_queues, sta->max_sp);
1297 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1298 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1299 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1300 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1301 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1302 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1303 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1304 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1305 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1306 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1307 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1308 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1310 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1311 max_sp = sta->max_sp;
1313 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1315 WMI_AP_PS_PEER_PARAM_UAPSD,
1318 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1319 arvif->vdev_id, ret);
1323 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1325 WMI_AP_PS_PEER_PARAM_MAX_SP,
1328 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1329 arvif->vdev_id, ret);
1333 /* TODO setup this based on STA listen interval and
1334 beacon interval. Currently we don't know
1335 sta->listen_interval - mac80211 patch required.
1336 Currently use 10 seconds */
1337 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1338 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1341 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1342 arvif->vdev_id, ret);
1350 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1351 struct ieee80211_sta *sta,
1352 struct wmi_peer_assoc_complete_arg *arg)
1354 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1357 if (!vht_cap->vht_supported)
1360 arg->peer_flags |= WMI_PEER_VHT;
1361 arg->peer_vht_caps = vht_cap->cap;
1363 ampdu_factor = (vht_cap->cap &
1364 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1365 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1367 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1368 * zero in VHT IE. Using it would result in degraded throughput.
1369 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1370 * it if VHT max_mpdu is smaller. */
1371 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1372 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1373 ampdu_factor)) - 1);
1375 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1376 arg->peer_flags |= WMI_PEER_80MHZ;
1378 arg->peer_vht_rates.rx_max_rate =
1379 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1380 arg->peer_vht_rates.rx_mcs_set =
1381 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1382 arg->peer_vht_rates.tx_max_rate =
1383 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1384 arg->peer_vht_rates.tx_mcs_set =
1385 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1387 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1388 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1391 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1392 struct ieee80211_vif *vif,
1393 struct ieee80211_sta *sta,
1394 struct wmi_peer_assoc_complete_arg *arg)
1396 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1398 switch (arvif->vdev_type) {
1399 case WMI_VDEV_TYPE_AP:
1401 arg->peer_flags |= WMI_PEER_QOS;
1403 if (sta->wme && sta->uapsd_queues) {
1404 arg->peer_flags |= WMI_PEER_APSD;
1405 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1408 case WMI_VDEV_TYPE_STA:
1409 if (vif->bss_conf.qos)
1410 arg->peer_flags |= WMI_PEER_QOS;
1417 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1418 struct ieee80211_vif *vif,
1419 struct ieee80211_sta *sta,
1420 struct wmi_peer_assoc_complete_arg *arg)
1422 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1424 switch (ar->hw->conf.chandef.chan->band) {
1425 case IEEE80211_BAND_2GHZ:
1426 if (sta->ht_cap.ht_supported) {
1427 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1428 phymode = MODE_11NG_HT40;
1430 phymode = MODE_11NG_HT20;
1436 case IEEE80211_BAND_5GHZ:
1440 if (sta->vht_cap.vht_supported) {
1441 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1442 phymode = MODE_11AC_VHT80;
1443 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1444 phymode = MODE_11AC_VHT40;
1445 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1446 phymode = MODE_11AC_VHT20;
1447 } else if (sta->ht_cap.ht_supported) {
1448 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1449 phymode = MODE_11NA_HT40;
1451 phymode = MODE_11NA_HT20;
1461 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1462 sta->addr, ath10k_wmi_phymode_str(phymode));
1464 arg->peer_phymode = phymode;
1465 WARN_ON(phymode == MODE_UNKNOWN);
1468 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1469 struct ieee80211_vif *vif,
1470 struct ieee80211_sta *sta,
1471 struct wmi_peer_assoc_complete_arg *arg)
1473 lockdep_assert_held(&ar->conf_mutex);
1475 memset(arg, 0, sizeof(*arg));
1477 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1478 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1479 ath10k_peer_assoc_h_rates(ar, sta, arg);
1480 ath10k_peer_assoc_h_ht(ar, sta, arg);
1481 ath10k_peer_assoc_h_vht(ar, sta, arg);
1482 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1483 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1488 static const u32 ath10k_smps_map[] = {
1489 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1490 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1491 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1492 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1495 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1497 const struct ieee80211_sta_ht_cap *ht_cap)
1501 if (!ht_cap->ht_supported)
1504 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1505 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1507 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1510 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1511 WMI_PEER_SMPS_STATE,
1512 ath10k_smps_map[smps]);
1515 /* can be called only in mac80211 callbacks due to `key_count` usage */
1516 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1517 struct ieee80211_vif *vif,
1518 struct ieee80211_bss_conf *bss_conf)
1520 struct ath10k *ar = hw->priv;
1521 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1522 struct ieee80211_sta_ht_cap ht_cap;
1523 struct wmi_peer_assoc_complete_arg peer_arg;
1524 struct ieee80211_sta *ap_sta;
1527 lockdep_assert_held(&ar->conf_mutex);
1529 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1530 arvif->vdev_id, arvif->bssid, arvif->aid);
1534 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1536 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1537 bss_conf->bssid, arvif->vdev_id);
1542 /* ap_sta must be accessed only within rcu section which must be left
1543 * before calling ath10k_setup_peer_smps() which might sleep. */
1544 ht_cap = ap_sta->ht_cap;
1546 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1548 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1549 bss_conf->bssid, arvif->vdev_id, ret);
1556 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1558 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1559 bss_conf->bssid, arvif->vdev_id, ret);
1563 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1565 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1566 arvif->vdev_id, ret);
1570 ath10k_dbg(ar, ATH10K_DBG_MAC,
1571 "mac vdev %d up (associated) bssid %pM aid %d\n",
1572 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1574 WARN_ON(arvif->is_up);
1576 arvif->aid = bss_conf->aid;
1577 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1579 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1581 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1582 arvif->vdev_id, ret);
1586 arvif->is_up = true;
1589 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1590 struct ieee80211_vif *vif)
1592 struct ath10k *ar = hw->priv;
1593 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1596 lockdep_assert_held(&ar->conf_mutex);
1598 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1599 arvif->vdev_id, arvif->bssid);
1601 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1603 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1604 arvif->vdev_id, ret);
1606 arvif->def_wep_key_idx = 0;
1607 arvif->is_up = false;
1610 static int ath10k_station_assoc(struct ath10k *ar,
1611 struct ieee80211_vif *vif,
1612 struct ieee80211_sta *sta,
1615 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1616 struct wmi_peer_assoc_complete_arg peer_arg;
1619 lockdep_assert_held(&ar->conf_mutex);
1621 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
1623 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1624 sta->addr, arvif->vdev_id, ret);
1628 peer_arg.peer_reassoc = reassoc;
1629 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1631 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1632 sta->addr, arvif->vdev_id, ret);
1636 /* Re-assoc is run only to update supported rates for given station. It
1637 * doesn't make much sense to reconfigure the peer completely.
1640 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1643 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1644 arvif->vdev_id, ret);
1648 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1650 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1651 sta->addr, arvif->vdev_id, ret);
1656 arvif->num_legacy_stations++;
1657 ret = ath10k_recalc_rtscts_prot(arvif);
1659 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1660 arvif->vdev_id, ret);
1665 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1667 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1668 arvif->vdev_id, ret);
1676 static int ath10k_station_disassoc(struct ath10k *ar,
1677 struct ieee80211_vif *vif,
1678 struct ieee80211_sta *sta)
1680 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1683 lockdep_assert_held(&ar->conf_mutex);
1686 arvif->num_legacy_stations--;
1687 ret = ath10k_recalc_rtscts_prot(arvif);
1689 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1690 arvif->vdev_id, ret);
1695 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1697 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1698 arvif->vdev_id, ret);
1709 static int ath10k_update_channel_list(struct ath10k *ar)
1711 struct ieee80211_hw *hw = ar->hw;
1712 struct ieee80211_supported_band **bands;
1713 enum ieee80211_band band;
1714 struct ieee80211_channel *channel;
1715 struct wmi_scan_chan_list_arg arg = {0};
1716 struct wmi_channel_arg *ch;
1722 lockdep_assert_held(&ar->conf_mutex);
1724 bands = hw->wiphy->bands;
1725 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1729 for (i = 0; i < bands[band]->n_channels; i++) {
1730 if (bands[band]->channels[i].flags &
1731 IEEE80211_CHAN_DISABLED)
1738 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1739 arg.channels = kzalloc(len, GFP_KERNEL);
1744 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1748 for (i = 0; i < bands[band]->n_channels; i++) {
1749 channel = &bands[band]->channels[i];
1751 if (channel->flags & IEEE80211_CHAN_DISABLED)
1754 ch->allow_ht = true;
1756 /* FIXME: when should we really allow VHT? */
1757 ch->allow_vht = true;
1760 !(channel->flags & IEEE80211_CHAN_NO_IR);
1763 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1766 !!(channel->flags & IEEE80211_CHAN_RADAR);
1768 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1769 ch->passive = passive;
1771 ch->freq = channel->center_freq;
1772 ch->band_center_freq1 = channel->center_freq;
1774 ch->max_power = channel->max_power * 2;
1775 ch->max_reg_power = channel->max_reg_power * 2;
1776 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1777 ch->reg_class_id = 0; /* FIXME */
1779 /* FIXME: why use only legacy modes, why not any
1780 * HT/VHT modes? Would that even make any
1782 if (channel->band == IEEE80211_BAND_2GHZ)
1783 ch->mode = MODE_11G;
1785 ch->mode = MODE_11A;
1787 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1790 ath10k_dbg(ar, ATH10K_DBG_WMI,
1791 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1792 ch - arg.channels, arg.n_channels,
1793 ch->freq, ch->max_power, ch->max_reg_power,
1794 ch->max_antenna_gain, ch->mode);
1800 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1801 kfree(arg.channels);
1806 static enum wmi_dfs_region
1807 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1809 switch (dfs_region) {
1810 case NL80211_DFS_UNSET:
1811 return WMI_UNINIT_DFS_DOMAIN;
1812 case NL80211_DFS_FCC:
1813 return WMI_FCC_DFS_DOMAIN;
1814 case NL80211_DFS_ETSI:
1815 return WMI_ETSI_DFS_DOMAIN;
1816 case NL80211_DFS_JP:
1817 return WMI_MKK4_DFS_DOMAIN;
1819 return WMI_UNINIT_DFS_DOMAIN;
1822 static void ath10k_regd_update(struct ath10k *ar)
1824 struct reg_dmn_pair_mapping *regpair;
1826 enum wmi_dfs_region wmi_dfs_reg;
1827 enum nl80211_dfs_regions nl_dfs_reg;
1829 lockdep_assert_held(&ar->conf_mutex);
1831 ret = ath10k_update_channel_list(ar);
1833 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1835 regpair = ar->ath_common.regulatory.regpair;
1837 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1838 nl_dfs_reg = ar->dfs_detector->region;
1839 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1841 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1844 /* Target allows setting up per-band regdomain but ath_common provides
1845 * a combined one only */
1846 ret = ath10k_wmi_pdev_set_regdomain(ar,
1847 regpair->reg_domain,
1848 regpair->reg_domain, /* 2ghz */
1849 regpair->reg_domain, /* 5ghz */
1850 regpair->reg_2ghz_ctl,
1851 regpair->reg_5ghz_ctl,
1854 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1857 static void ath10k_reg_notifier(struct wiphy *wiphy,
1858 struct regulatory_request *request)
1860 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1861 struct ath10k *ar = hw->priv;
1864 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1866 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1867 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1868 request->dfs_region);
1869 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1870 request->dfs_region);
1872 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1873 request->dfs_region);
1876 mutex_lock(&ar->conf_mutex);
1877 if (ar->state == ATH10K_STATE_ON)
1878 ath10k_regd_update(ar);
1879 mutex_unlock(&ar->conf_mutex);
1886 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1888 if (ieee80211_is_mgmt(hdr->frame_control))
1889 return HTT_DATA_TX_EXT_TID_MGMT;
1891 if (!ieee80211_is_data_qos(hdr->frame_control))
1892 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1894 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1895 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1897 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1900 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
1903 return ath10k_vif_to_arvif(vif)->vdev_id;
1905 if (ar->monitor_started)
1906 return ar->monitor_vdev_id;
1908 ath10k_warn(ar, "failed to resolve vdev id\n");
1912 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1913 * Control in the header.
1915 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1917 struct ieee80211_hdr *hdr = (void *)skb->data;
1918 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1921 if (!ieee80211_is_data_qos(hdr->frame_control))
1924 qos_ctl = ieee80211_get_qos_ctl(hdr);
1925 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1926 skb->data, (void *)qos_ctl - (void *)skb->data);
1927 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1929 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1930 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1931 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1932 * it is safe to downgrade to NullFunc.
1934 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1935 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1936 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1940 static void ath10k_tx_wep_key_work(struct work_struct *work)
1942 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1944 struct ath10k *ar = arvif->ar;
1945 int ret, keyidx = arvif->def_wep_key_newidx;
1947 mutex_lock(&arvif->ar->conf_mutex);
1949 if (arvif->ar->state != ATH10K_STATE_ON)
1952 if (arvif->def_wep_key_idx == keyidx)
1955 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1956 arvif->vdev_id, keyidx);
1958 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1960 arvif->ar->wmi.vdev_param->def_keyid,
1963 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
1969 arvif->def_wep_key_idx = keyidx;
1972 mutex_unlock(&arvif->ar->conf_mutex);
1975 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1976 struct ieee80211_key_conf *key,
1977 struct sk_buff *skb)
1979 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1980 struct ath10k *ar = arvif->ar;
1981 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1983 if (!ieee80211_has_protected(hdr->frame_control))
1989 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1990 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1993 if (key->keyidx == arvif->def_wep_key_idx)
1996 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1997 * queueing frames until key index is updated is not an option because
1998 * sk_buff may need more processing to be done, e.g. offchannel */
1999 arvif->def_wep_key_newidx = key->keyidx;
2000 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
2003 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2004 struct ieee80211_vif *vif,
2005 struct sk_buff *skb)
2007 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2008 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2010 /* This is case only for P2P_GO */
2011 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2012 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2015 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2016 spin_lock_bh(&ar->data_lock);
2017 if (arvif->u.ap.noa_data)
2018 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2020 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2021 arvif->u.ap.noa_data,
2022 arvif->u.ap.noa_len);
2023 spin_unlock_bh(&ar->data_lock);
2027 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2029 /* FIXME: Not really sure since when the behaviour changed. At some
2030 * point new firmware stopped requiring creation of peer entries for
2031 * offchannel tx (and actually creating them causes issues with wmi-htc
2032 * tx credit replenishment and reliability). Assuming it's at least 3.4
2033 * because that's when the `freq` was introduced to TX_FRM HTT command.
2035 return !(ar->htt.target_version_major >= 3 &&
2036 ar->htt.target_version_minor >= 4);
2039 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2041 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2044 if (ar->htt.target_version_major >= 3) {
2045 /* Since HTT 3.0 there is no separate mgmt tx command */
2046 ret = ath10k_htt_tx(&ar->htt, skb);
2050 if (ieee80211_is_mgmt(hdr->frame_control)) {
2051 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2053 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2054 ATH10K_MAX_NUM_MGMT_PENDING) {
2055 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2060 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2061 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2063 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2065 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2067 ieee80211_is_nullfunc(hdr->frame_control)) {
2068 /* FW does not report tx status properly for NullFunc frames
2069 * unless they are sent through mgmt tx path. mac80211 sends
2070 * those frames when it detects link/beacon loss and depends
2071 * on the tx status to be correct. */
2072 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2074 ret = ath10k_htt_tx(&ar->htt, skb);
2079 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2081 ieee80211_free_txskb(ar->hw, skb);
2085 void ath10k_offchan_tx_purge(struct ath10k *ar)
2087 struct sk_buff *skb;
2090 skb = skb_dequeue(&ar->offchan_tx_queue);
2094 ieee80211_free_txskb(ar->hw, skb);
2098 void ath10k_offchan_tx_work(struct work_struct *work)
2100 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2101 struct ath10k_peer *peer;
2102 struct ieee80211_hdr *hdr;
2103 struct sk_buff *skb;
2104 const u8 *peer_addr;
2108 /* FW requirement: We must create a peer before FW will send out
2109 * an offchannel frame. Otherwise the frame will be stuck and
2110 * never transmitted. We delete the peer upon tx completion.
2111 * It is unlikely that a peer for offchannel tx will already be
2112 * present. However it may be in some rare cases so account for that.
2113 * Otherwise we might remove a legitimate peer and break stuff. */
2116 skb = skb_dequeue(&ar->offchan_tx_queue);
2120 mutex_lock(&ar->conf_mutex);
2122 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2125 hdr = (struct ieee80211_hdr *)skb->data;
2126 peer_addr = ieee80211_get_DA(hdr);
2127 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2129 spin_lock_bh(&ar->data_lock);
2130 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2131 spin_unlock_bh(&ar->data_lock);
2134 /* FIXME: should this use ath10k_warn()? */
2135 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2136 peer_addr, vdev_id);
2139 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2141 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2142 peer_addr, vdev_id, ret);
2145 spin_lock_bh(&ar->data_lock);
2146 reinit_completion(&ar->offchan_tx_completed);
2147 ar->offchan_tx_skb = skb;
2148 spin_unlock_bh(&ar->data_lock);
2150 ath10k_tx_htt(ar, skb);
2152 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2155 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2159 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2161 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2162 peer_addr, vdev_id, ret);
2165 mutex_unlock(&ar->conf_mutex);
2169 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2171 struct sk_buff *skb;
2174 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2178 ieee80211_free_txskb(ar->hw, skb);
2182 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2184 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2185 struct sk_buff *skb;
2189 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2193 ret = ath10k_wmi_mgmt_tx(ar, skb);
2195 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2197 ieee80211_free_txskb(ar->hw, skb);
2206 void __ath10k_scan_finish(struct ath10k *ar)
2208 lockdep_assert_held(&ar->data_lock);
2210 switch (ar->scan.state) {
2211 case ATH10K_SCAN_IDLE:
2213 case ATH10K_SCAN_RUNNING:
2214 if (ar->scan.is_roc)
2215 ieee80211_remain_on_channel_expired(ar->hw);
2216 case ATH10K_SCAN_ABORTING:
2217 if (!ar->scan.is_roc)
2218 ieee80211_scan_completed(ar->hw,
2220 ATH10K_SCAN_ABORTING));
2222 case ATH10K_SCAN_STARTING:
2223 ar->scan.state = ATH10K_SCAN_IDLE;
2224 ar->scan_channel = NULL;
2225 ath10k_offchan_tx_purge(ar);
2226 cancel_delayed_work(&ar->scan.timeout);
2227 complete_all(&ar->scan.completed);
2232 void ath10k_scan_finish(struct ath10k *ar)
2234 spin_lock_bh(&ar->data_lock);
2235 __ath10k_scan_finish(ar);
2236 spin_unlock_bh(&ar->data_lock);
2239 static int ath10k_scan_stop(struct ath10k *ar)
2241 struct wmi_stop_scan_arg arg = {
2242 .req_id = 1, /* FIXME */
2243 .req_type = WMI_SCAN_STOP_ONE,
2244 .u.scan_id = ATH10K_SCAN_ID,
2248 lockdep_assert_held(&ar->conf_mutex);
2250 ret = ath10k_wmi_stop_scan(ar, &arg);
2252 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2256 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2258 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2260 } else if (ret > 0) {
2265 /* Scan state should be updated upon scan completion but in case
2266 * firmware fails to deliver the event (for whatever reason) it is
2267 * desired to clean up scan state anyway. Firmware may have just
2268 * dropped the scan completion event delivery due to transport pipe
2269 * being overflown with data and/or it can recover on its own before
2270 * next scan request is submitted.
2272 spin_lock_bh(&ar->data_lock);
2273 if (ar->scan.state != ATH10K_SCAN_IDLE)
2274 __ath10k_scan_finish(ar);
2275 spin_unlock_bh(&ar->data_lock);
2280 static void ath10k_scan_abort(struct ath10k *ar)
2284 lockdep_assert_held(&ar->conf_mutex);
2286 spin_lock_bh(&ar->data_lock);
2288 switch (ar->scan.state) {
2289 case ATH10K_SCAN_IDLE:
2290 /* This can happen if timeout worker kicked in and called
2291 * abortion while scan completion was being processed.
2294 case ATH10K_SCAN_STARTING:
2295 case ATH10K_SCAN_ABORTING:
2296 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2297 ath10k_scan_state_str(ar->scan.state),
2300 case ATH10K_SCAN_RUNNING:
2301 ar->scan.state = ATH10K_SCAN_ABORTING;
2302 spin_unlock_bh(&ar->data_lock);
2304 ret = ath10k_scan_stop(ar);
2306 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2308 spin_lock_bh(&ar->data_lock);
2312 spin_unlock_bh(&ar->data_lock);
2315 void ath10k_scan_timeout_work(struct work_struct *work)
2317 struct ath10k *ar = container_of(work, struct ath10k,
2320 mutex_lock(&ar->conf_mutex);
2321 ath10k_scan_abort(ar);
2322 mutex_unlock(&ar->conf_mutex);
2325 static int ath10k_start_scan(struct ath10k *ar,
2326 const struct wmi_start_scan_arg *arg)
2330 lockdep_assert_held(&ar->conf_mutex);
2332 ret = ath10k_wmi_start_scan(ar, arg);
2336 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2338 ret = ath10k_scan_stop(ar);
2340 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2345 /* Add a 200ms margin to account for event/command processing */
2346 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2347 msecs_to_jiffies(arg->max_scan_time+200));
2351 /**********************/
2352 /* mac80211 callbacks */
2353 /**********************/
2355 static void ath10k_tx(struct ieee80211_hw *hw,
2356 struct ieee80211_tx_control *control,
2357 struct sk_buff *skb)
2359 struct ath10k *ar = hw->priv;
2360 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2361 struct ieee80211_vif *vif = info->control.vif;
2362 struct ieee80211_key_conf *key = info->control.hw_key;
2363 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2365 /* We should disable CCK RATE due to P2P */
2366 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2367 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2369 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2370 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2371 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2373 /* it makes no sense to process injected frames like that */
2374 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2375 ath10k_tx_h_nwifi(hw, skb);
2376 ath10k_tx_h_update_wep_key(vif, key, skb);
2377 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2378 ath10k_tx_h_seq_no(vif, skb);
2381 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2382 spin_lock_bh(&ar->data_lock);
2383 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
2384 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2385 spin_unlock_bh(&ar->data_lock);
2387 if (ath10k_mac_need_offchan_tx_work(ar)) {
2388 ATH10K_SKB_CB(skb)->htt.freq = 0;
2389 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2391 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2394 skb_queue_tail(&ar->offchan_tx_queue, skb);
2395 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2400 ath10k_tx_htt(ar, skb);
2403 /* Must not be called with conf_mutex held as workers can use that also. */
2404 void ath10k_drain_tx(struct ath10k *ar)
2406 /* make sure rcu-protected mac80211 tx path itself is drained */
2409 ath10k_offchan_tx_purge(ar);
2410 ath10k_mgmt_over_wmi_tx_purge(ar);
2412 cancel_work_sync(&ar->offchan_tx_work);
2413 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2416 void ath10k_halt(struct ath10k *ar)
2418 struct ath10k_vif *arvif;
2420 lockdep_assert_held(&ar->conf_mutex);
2422 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2423 ar->filter_flags = 0;
2424 ar->monitor = false;
2426 if (ar->monitor_started)
2427 ath10k_monitor_stop(ar);
2429 ar->monitor_started = false;
2431 ath10k_scan_finish(ar);
2432 ath10k_peer_cleanup_all(ar);
2433 ath10k_core_stop(ar);
2434 ath10k_hif_power_down(ar);
2436 spin_lock_bh(&ar->data_lock);
2437 list_for_each_entry(arvif, &ar->arvifs, list)
2438 ath10k_mac_vif_beacon_cleanup(arvif);
2439 spin_unlock_bh(&ar->data_lock);
2442 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2444 struct ath10k *ar = hw->priv;
2446 mutex_lock(&ar->conf_mutex);
2448 if (ar->cfg_tx_chainmask) {
2449 *tx_ant = ar->cfg_tx_chainmask;
2450 *rx_ant = ar->cfg_rx_chainmask;
2452 *tx_ant = ar->supp_tx_chainmask;
2453 *rx_ant = ar->supp_rx_chainmask;
2456 mutex_unlock(&ar->conf_mutex);
2461 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2463 /* It is not clear that allowing gaps in chainmask
2464 * is helpful. Probably it will not do what user
2465 * is hoping for, so warn in that case.
2467 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2470 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2474 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2478 lockdep_assert_held(&ar->conf_mutex);
2480 ath10k_check_chain_mask(ar, tx_ant, "tx");
2481 ath10k_check_chain_mask(ar, rx_ant, "rx");
2483 ar->cfg_tx_chainmask = tx_ant;
2484 ar->cfg_rx_chainmask = rx_ant;
2486 if ((ar->state != ATH10K_STATE_ON) &&
2487 (ar->state != ATH10K_STATE_RESTARTED))
2490 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2493 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2498 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2501 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2509 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2511 struct ath10k *ar = hw->priv;
2514 mutex_lock(&ar->conf_mutex);
2515 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2516 mutex_unlock(&ar->conf_mutex);
2520 static int ath10k_start(struct ieee80211_hw *hw)
2522 struct ath10k *ar = hw->priv;
2526 * This makes sense only when restarting hw. It is harmless to call
2527 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2528 * commands will be submitted while restarting.
2530 ath10k_drain_tx(ar);
2532 mutex_lock(&ar->conf_mutex);
2534 switch (ar->state) {
2535 case ATH10K_STATE_OFF:
2536 ar->state = ATH10K_STATE_ON;
2538 case ATH10K_STATE_RESTARTING:
2540 ar->state = ATH10K_STATE_RESTARTED;
2542 case ATH10K_STATE_ON:
2543 case ATH10K_STATE_RESTARTED:
2544 case ATH10K_STATE_WEDGED:
2548 case ATH10K_STATE_UTF:
2553 ret = ath10k_hif_power_up(ar);
2555 ath10k_err(ar, "Could not init hif: %d\n", ret);
2559 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2561 ath10k_err(ar, "Could not init core: %d\n", ret);
2562 goto err_power_down;
2565 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2567 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2571 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2573 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2577 if (ar->cfg_tx_chainmask)
2578 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2579 ar->cfg_rx_chainmask);
2582 * By default FW set ARP frames ac to voice (6). In that case ARP
2583 * exchange is not working properly for UAPSD enabled AP. ARP requests
2584 * which arrives with access category 0 are processed by network stack
2585 * and send back with access category 0, but FW changes access category
2586 * to 6. Set ARP frames access category to best effort (0) solves
2590 ret = ath10k_wmi_pdev_set_param(ar,
2591 ar->wmi.pdev_param->arp_ac_override, 0);
2593 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2598 ar->num_started_vdevs = 0;
2599 ath10k_regd_update(ar);
2601 ath10k_spectral_start(ar);
2603 mutex_unlock(&ar->conf_mutex);
2607 ath10k_core_stop(ar);
2610 ath10k_hif_power_down(ar);
2613 ar->state = ATH10K_STATE_OFF;
2616 mutex_unlock(&ar->conf_mutex);
2620 static void ath10k_stop(struct ieee80211_hw *hw)
2622 struct ath10k *ar = hw->priv;
2624 ath10k_drain_tx(ar);
2626 mutex_lock(&ar->conf_mutex);
2627 if (ar->state != ATH10K_STATE_OFF) {
2629 ar->state = ATH10K_STATE_OFF;
2631 mutex_unlock(&ar->conf_mutex);
2633 cancel_delayed_work_sync(&ar->scan.timeout);
2634 cancel_work_sync(&ar->restart_work);
2637 static int ath10k_config_ps(struct ath10k *ar)
2639 struct ath10k_vif *arvif;
2642 lockdep_assert_held(&ar->conf_mutex);
2644 list_for_each_entry(arvif, &ar->arvifs, list) {
2645 ret = ath10k_mac_vif_setup_ps(arvif);
2647 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2655 static const char *chandef_get_width(enum nl80211_chan_width width)
2658 case NL80211_CHAN_WIDTH_20_NOHT:
2660 case NL80211_CHAN_WIDTH_20:
2662 case NL80211_CHAN_WIDTH_40:
2664 case NL80211_CHAN_WIDTH_80:
2666 case NL80211_CHAN_WIDTH_80P80:
2668 case NL80211_CHAN_WIDTH_160:
2670 case NL80211_CHAN_WIDTH_5:
2672 case NL80211_CHAN_WIDTH_10:
2678 static void ath10k_config_chan(struct ath10k *ar)
2680 struct ath10k_vif *arvif;
2683 lockdep_assert_held(&ar->conf_mutex);
2685 ath10k_dbg(ar, ATH10K_DBG_MAC,
2686 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2687 ar->chandef.chan->center_freq,
2688 ar->chandef.center_freq1,
2689 ar->chandef.center_freq2,
2690 chandef_get_width(ar->chandef.width));
2692 /* First stop monitor interface. Some FW versions crash if there's a
2693 * lone monitor interface. */
2694 if (ar->monitor_started)
2695 ath10k_monitor_stop(ar);
2697 list_for_each_entry(arvif, &ar->arvifs, list) {
2698 if (!arvif->is_started)
2704 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2707 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2709 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2710 arvif->vdev_id, ret);
2715 /* all vdevs are downed now - attempt to restart and re-up them */
2717 list_for_each_entry(arvif, &ar->arvifs, list) {
2718 if (!arvif->is_started)
2721 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2724 ret = ath10k_vdev_restart(arvif);
2726 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2727 arvif->vdev_id, ret);
2734 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2737 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2738 arvif->vdev_id, ret);
2743 ath10k_monitor_recalc(ar);
2746 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
2751 lockdep_assert_held(&ar->conf_mutex);
2753 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
2755 param = ar->wmi.pdev_param->txpower_limit2g;
2756 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2758 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2763 param = ar->wmi.pdev_param->txpower_limit5g;
2764 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
2766 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2774 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
2776 struct ath10k_vif *arvif;
2777 int ret, txpower = -1;
2779 lockdep_assert_held(&ar->conf_mutex);
2781 list_for_each_entry(arvif, &ar->arvifs, list) {
2782 WARN_ON(arvif->txpower < 0);
2785 txpower = arvif->txpower;
2787 txpower = min(txpower, arvif->txpower);
2790 if (WARN_ON(txpower == -1))
2793 ret = ath10k_mac_txpower_setup(ar, txpower);
2795 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
2803 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2805 struct ath10k *ar = hw->priv;
2806 struct ieee80211_conf *conf = &hw->conf;
2809 mutex_lock(&ar->conf_mutex);
2811 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2812 ath10k_dbg(ar, ATH10K_DBG_MAC,
2813 "mac config channel %dMHz flags 0x%x radar %d\n",
2814 conf->chandef.chan->center_freq,
2815 conf->chandef.chan->flags,
2816 conf->radar_enabled);
2818 spin_lock_bh(&ar->data_lock);
2819 ar->rx_channel = conf->chandef.chan;
2820 spin_unlock_bh(&ar->data_lock);
2822 ar->radar_enabled = conf->radar_enabled;
2823 ath10k_recalc_radar_detection(ar);
2825 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2826 ar->chandef = conf->chandef;
2827 ath10k_config_chan(ar);
2831 if (changed & IEEE80211_CONF_CHANGE_PS)
2832 ath10k_config_ps(ar);
2834 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2835 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2836 ret = ath10k_monitor_recalc(ar);
2838 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2841 mutex_unlock(&ar->conf_mutex);
2845 static u32 get_nss_from_chainmask(u16 chain_mask)
2847 if ((chain_mask & 0x15) == 0x15)
2849 else if ((chain_mask & 0x7) == 0x7)
2851 else if ((chain_mask & 0x3) == 0x3)
2858 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2859 * because we will send mgmt frames without CCK. This requirement
2860 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2863 static int ath10k_add_interface(struct ieee80211_hw *hw,
2864 struct ieee80211_vif *vif)
2866 struct ath10k *ar = hw->priv;
2867 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2868 enum wmi_sta_powersave_param param;
2874 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2876 mutex_lock(&ar->conf_mutex);
2878 memset(arvif, 0, sizeof(*arvif));
2883 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2884 INIT_LIST_HEAD(&arvif->list);
2886 if (ar->free_vdev_map == 0) {
2887 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2891 bit = __ffs64(ar->free_vdev_map);
2893 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2894 bit, ar->free_vdev_map);
2896 arvif->vdev_id = bit;
2897 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2900 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2902 switch (vif->type) {
2903 case NL80211_IFTYPE_UNSPECIFIED:
2904 case NL80211_IFTYPE_STATION:
2905 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2907 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2909 case NL80211_IFTYPE_ADHOC:
2910 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2912 case NL80211_IFTYPE_AP:
2913 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2916 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2918 case NL80211_IFTYPE_MONITOR:
2919 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2926 /* Some firmware revisions don't wait for beacon tx completion before
2927 * sending another SWBA event. This could lead to hardware using old
2928 * (freed) beacon data in some cases, e.g. tx credit starvation
2929 * combined with missed TBTT. This is very very rare.
2931 * On non-IOMMU-enabled hosts this could be a possible security issue
2932 * because hw could beacon some random data on the air. On
2933 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2934 * device would crash.
2936 * Since there are no beacon tx completions (implicit nor explicit)
2937 * propagated to host the only workaround for this is to allocate a
2938 * DMA-coherent buffer for a lifetime of a vif and use it for all
2939 * beacon tx commands. Worst case for this approach is some beacons may
2940 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2942 if (vif->type == NL80211_IFTYPE_ADHOC ||
2943 vif->type == NL80211_IFTYPE_AP) {
2944 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2945 IEEE80211_MAX_FRAME_LEN,
2946 &arvif->beacon_paddr,
2948 if (!arvif->beacon_buf) {
2950 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2956 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2957 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2958 arvif->beacon_buf ? "single-buf" : "per-skb");
2960 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2961 arvif->vdev_subtype, vif->addr);
2963 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
2964 arvif->vdev_id, ret);
2968 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
2969 list_add(&arvif->list, &ar->arvifs);
2971 vdev_param = ar->wmi.vdev_param->def_keyid;
2972 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2973 arvif->def_wep_key_idx);
2975 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
2976 arvif->vdev_id, ret);
2977 goto err_vdev_delete;
2980 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2981 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2982 ATH10K_HW_TXRX_NATIVE_WIFI);
2983 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2984 if (ret && ret != -EOPNOTSUPP) {
2985 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
2986 arvif->vdev_id, ret);
2987 goto err_vdev_delete;
2990 if (ar->cfg_tx_chainmask) {
2991 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
2993 vdev_param = ar->wmi.vdev_param->nss;
2994 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2997 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
2998 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3000 goto err_vdev_delete;
3004 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3005 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3007 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
3008 arvif->vdev_id, ret);
3009 goto err_vdev_delete;
3012 ret = ath10k_mac_set_kickout(arvif);
3014 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
3015 arvif->vdev_id, ret);
3016 goto err_peer_delete;
3020 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3021 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3022 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3023 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3026 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
3027 arvif->vdev_id, ret);
3028 goto err_peer_delete;
3031 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
3032 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
3033 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3036 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
3037 arvif->vdev_id, ret);
3038 goto err_peer_delete;
3041 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
3042 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
3043 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3046 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
3047 arvif->vdev_id, ret);
3048 goto err_peer_delete;
3052 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
3054 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3055 arvif->vdev_id, ret);
3056 goto err_peer_delete;
3059 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
3061 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
3062 arvif->vdev_id, ret);
3063 goto err_peer_delete;
3066 arvif->txpower = vif->bss_conf.txpower;
3067 ret = ath10k_mac_txpower_recalc(ar);
3069 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3070 goto err_peer_delete;
3073 mutex_unlock(&ar->conf_mutex);
3077 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3078 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3081 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3082 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3083 list_del(&arvif->list);
3086 if (arvif->beacon_buf) {
3087 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3088 arvif->beacon_buf, arvif->beacon_paddr);
3089 arvif->beacon_buf = NULL;
3092 mutex_unlock(&ar->conf_mutex);
3097 static void ath10k_remove_interface(struct ieee80211_hw *hw,
3098 struct ieee80211_vif *vif)
3100 struct ath10k *ar = hw->priv;
3101 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3104 cancel_work_sync(&arvif->wep_key_work);
3106 mutex_lock(&ar->conf_mutex);
3108 spin_lock_bh(&ar->data_lock);
3109 ath10k_mac_vif_beacon_cleanup(arvif);
3110 spin_unlock_bh(&ar->data_lock);
3112 ret = ath10k_spectral_vif_stop(arvif);
3114 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
3115 arvif->vdev_id, ret);
3117 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3118 list_del(&arvif->list);
3120 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3121 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3123 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
3124 arvif->vdev_id, ret);
3126 kfree(arvif->u.ap.noa_data);
3129 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3132 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3134 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3135 arvif->vdev_id, ret);
3137 ath10k_peer_cleanup(ar, arvif->vdev_id);
3139 mutex_unlock(&ar->conf_mutex);
3143 * FIXME: Has to be verified.
3145 #define SUPPORTED_FILTERS \
3146 (FIF_PROMISC_IN_BSS | \
3151 FIF_BCN_PRBRESP_PROMISC | \
3155 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3156 unsigned int changed_flags,
3157 unsigned int *total_flags,
3160 struct ath10k *ar = hw->priv;
3163 mutex_lock(&ar->conf_mutex);
3165 changed_flags &= SUPPORTED_FILTERS;
3166 *total_flags &= SUPPORTED_FILTERS;
3167 ar->filter_flags = *total_flags;
3169 ret = ath10k_monitor_recalc(ar);
3171 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3173 mutex_unlock(&ar->conf_mutex);
3176 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3177 struct ieee80211_vif *vif,
3178 struct ieee80211_bss_conf *info,
3181 struct ath10k *ar = hw->priv;
3182 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3184 u32 vdev_param, pdev_param, slottime, preamble;
3186 mutex_lock(&ar->conf_mutex);
3188 if (changed & BSS_CHANGED_IBSS)
3189 ath10k_control_ibss(arvif, info, vif->addr);
3191 if (changed & BSS_CHANGED_BEACON_INT) {
3192 arvif->beacon_interval = info->beacon_int;
3193 vdev_param = ar->wmi.vdev_param->beacon_interval;
3194 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3195 arvif->beacon_interval);
3196 ath10k_dbg(ar, ATH10K_DBG_MAC,
3197 "mac vdev %d beacon_interval %d\n",
3198 arvif->vdev_id, arvif->beacon_interval);
3201 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3202 arvif->vdev_id, ret);
3205 if (changed & BSS_CHANGED_BEACON) {
3206 ath10k_dbg(ar, ATH10K_DBG_MAC,
3207 "vdev %d set beacon tx mode to staggered\n",
3210 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3211 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3212 WMI_BEACON_STAGGERED_MODE);
3214 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3215 arvif->vdev_id, ret);
3218 if (changed & BSS_CHANGED_BEACON_INFO) {
3219 arvif->dtim_period = info->dtim_period;
3221 ath10k_dbg(ar, ATH10K_DBG_MAC,
3222 "mac vdev %d dtim_period %d\n",
3223 arvif->vdev_id, arvif->dtim_period);
3225 vdev_param = ar->wmi.vdev_param->dtim_period;
3226 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3227 arvif->dtim_period);
3229 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3230 arvif->vdev_id, ret);
3233 if (changed & BSS_CHANGED_SSID &&
3234 vif->type == NL80211_IFTYPE_AP) {
3235 arvif->u.ap.ssid_len = info->ssid_len;
3237 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3238 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3241 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3242 ether_addr_copy(arvif->bssid, info->bssid);
3244 if (changed & BSS_CHANGED_BEACON_ENABLED)
3245 ath10k_control_beaconing(arvif, info);
3247 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3248 arvif->use_cts_prot = info->use_cts_prot;
3249 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3250 arvif->vdev_id, info->use_cts_prot);
3252 ret = ath10k_recalc_rtscts_prot(arvif);
3254 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3255 arvif->vdev_id, ret);
3258 if (changed & BSS_CHANGED_ERP_SLOT) {
3259 if (info->use_short_slot)
3260 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3263 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3265 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3266 arvif->vdev_id, slottime);
3268 vdev_param = ar->wmi.vdev_param->slot_time;
3269 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3272 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3273 arvif->vdev_id, ret);
3276 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3277 if (info->use_short_preamble)
3278 preamble = WMI_VDEV_PREAMBLE_SHORT;
3280 preamble = WMI_VDEV_PREAMBLE_LONG;
3282 ath10k_dbg(ar, ATH10K_DBG_MAC,
3283 "mac vdev %d preamble %dn",
3284 arvif->vdev_id, preamble);
3286 vdev_param = ar->wmi.vdev_param->preamble;
3287 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3290 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3291 arvif->vdev_id, ret);
3294 if (changed & BSS_CHANGED_ASSOC) {
3296 /* Workaround: Make sure monitor vdev is not running
3297 * when associating to prevent some firmware revisions
3298 * (e.g. 10.1 and 10.2) from crashing.
3300 if (ar->monitor_started)
3301 ath10k_monitor_stop(ar);
3302 ath10k_bss_assoc(hw, vif, info);
3303 ath10k_monitor_recalc(ar);
3305 ath10k_bss_disassoc(hw, vif);
3309 if (changed & BSS_CHANGED_TXPOWER) {
3310 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3311 arvif->vdev_id, info->txpower);
3313 arvif->txpower = info->txpower;
3314 ret = ath10k_mac_txpower_recalc(ar);
3316 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3319 mutex_unlock(&ar->conf_mutex);
3322 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3323 struct ieee80211_vif *vif,
3324 struct ieee80211_scan_request *hw_req)
3326 struct ath10k *ar = hw->priv;
3327 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3328 struct cfg80211_scan_request *req = &hw_req->req;
3329 struct wmi_start_scan_arg arg;
3333 mutex_lock(&ar->conf_mutex);
3335 spin_lock_bh(&ar->data_lock);
3336 switch (ar->scan.state) {
3337 case ATH10K_SCAN_IDLE:
3338 reinit_completion(&ar->scan.started);
3339 reinit_completion(&ar->scan.completed);
3340 ar->scan.state = ATH10K_SCAN_STARTING;
3341 ar->scan.is_roc = false;
3342 ar->scan.vdev_id = arvif->vdev_id;
3345 case ATH10K_SCAN_STARTING:
3346 case ATH10K_SCAN_RUNNING:
3347 case ATH10K_SCAN_ABORTING:
3351 spin_unlock_bh(&ar->data_lock);
3356 memset(&arg, 0, sizeof(arg));
3357 ath10k_wmi_start_scan_init(ar, &arg);
3358 arg.vdev_id = arvif->vdev_id;
3359 arg.scan_id = ATH10K_SCAN_ID;
3362 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3365 arg.ie_len = req->ie_len;
3366 memcpy(arg.ie, req->ie, arg.ie_len);
3370 arg.n_ssids = req->n_ssids;
3371 for (i = 0; i < arg.n_ssids; i++) {
3372 arg.ssids[i].len = req->ssids[i].ssid_len;
3373 arg.ssids[i].ssid = req->ssids[i].ssid;
3376 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3379 if (req->n_channels) {
3380 arg.n_channels = req->n_channels;
3381 for (i = 0; i < arg.n_channels; i++)
3382 arg.channels[i] = req->channels[i]->center_freq;
3385 ret = ath10k_start_scan(ar, &arg);
3387 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3388 spin_lock_bh(&ar->data_lock);
3389 ar->scan.state = ATH10K_SCAN_IDLE;
3390 spin_unlock_bh(&ar->data_lock);
3394 mutex_unlock(&ar->conf_mutex);
3398 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3399 struct ieee80211_vif *vif)
3401 struct ath10k *ar = hw->priv;
3403 mutex_lock(&ar->conf_mutex);
3404 ath10k_scan_abort(ar);
3405 mutex_unlock(&ar->conf_mutex);
3407 cancel_delayed_work_sync(&ar->scan.timeout);
3410 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3411 struct ath10k_vif *arvif,
3412 enum set_key_cmd cmd,
3413 struct ieee80211_key_conf *key)
3415 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3418 /* 10.1 firmware branch requires default key index to be set to group
3419 * key index after installing it. Otherwise FW/HW Txes corrupted
3420 * frames with multi-vif APs. This is not required for main firmware
3421 * branch (e.g. 636).
3423 * FIXME: This has been tested only in AP. It remains unknown if this
3424 * is required for multi-vif STA interfaces on 10.1 */
3426 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3429 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3432 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3435 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3441 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3444 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3445 arvif->vdev_id, ret);
3448 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3449 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3450 struct ieee80211_key_conf *key)
3452 struct ath10k *ar = hw->priv;
3453 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3454 struct ath10k_peer *peer;
3455 const u8 *peer_addr;
3456 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3457 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3460 if (key->keyidx > WMI_MAX_KEY_INDEX)
3463 mutex_lock(&ar->conf_mutex);
3466 peer_addr = sta->addr;
3467 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3468 peer_addr = vif->bss_conf.bssid;
3470 peer_addr = vif->addr;
3472 key->hw_key_idx = key->keyidx;
3474 /* the peer should not disappear in mid-way (unless FW goes awry) since
3475 * we already hold conf_mutex. we just make sure its there now. */
3476 spin_lock_bh(&ar->data_lock);
3477 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3478 spin_unlock_bh(&ar->data_lock);
3481 if (cmd == SET_KEY) {
3482 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3487 /* if the peer doesn't exist there is no key to disable
3495 arvif->wep_keys[key->keyidx] = key;
3497 arvif->wep_keys[key->keyidx] = NULL;
3499 if (cmd == DISABLE_KEY)
3500 ath10k_clear_vdev_key(arvif, key);
3503 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3505 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3506 arvif->vdev_id, peer_addr, ret);
3510 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3512 spin_lock_bh(&ar->data_lock);
3513 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3514 if (peer && cmd == SET_KEY)
3515 peer->keys[key->keyidx] = key;
3516 else if (peer && cmd == DISABLE_KEY)
3517 peer->keys[key->keyidx] = NULL;
3518 else if (peer == NULL)
3519 /* impossible unless FW goes crazy */
3520 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3521 spin_unlock_bh(&ar->data_lock);
3524 mutex_unlock(&ar->conf_mutex);
3528 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3531 struct ath10k_vif *arvif;
3532 struct ath10k_sta *arsta;
3533 struct ieee80211_sta *sta;
3534 u32 changed, bw, nss, smps;
3537 arsta = container_of(wk, struct ath10k_sta, update_wk);
3538 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3539 arvif = arsta->arvif;
3542 spin_lock_bh(&ar->data_lock);
3544 changed = arsta->changed;
3551 spin_unlock_bh(&ar->data_lock);
3553 mutex_lock(&ar->conf_mutex);
3555 if (changed & IEEE80211_RC_BW_CHANGED) {
3556 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3559 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3560 WMI_PEER_CHAN_WIDTH, bw);
3562 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3563 sta->addr, bw, err);
3566 if (changed & IEEE80211_RC_NSS_CHANGED) {
3567 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3570 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3573 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3574 sta->addr, nss, err);
3577 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3578 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3581 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3582 WMI_PEER_SMPS_STATE, smps);
3584 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3585 sta->addr, smps, err);
3588 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3589 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3592 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3594 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3598 mutex_unlock(&ar->conf_mutex);
3601 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
3603 struct ath10k *ar = arvif->ar;
3605 lockdep_assert_held(&ar->conf_mutex);
3607 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3608 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3611 if (ar->num_stations >= ar->max_num_stations)
3619 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
3621 struct ath10k *ar = arvif->ar;
3623 lockdep_assert_held(&ar->conf_mutex);
3625 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
3626 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
3632 static int ath10k_sta_state(struct ieee80211_hw *hw,
3633 struct ieee80211_vif *vif,
3634 struct ieee80211_sta *sta,
3635 enum ieee80211_sta_state old_state,
3636 enum ieee80211_sta_state new_state)
3638 struct ath10k *ar = hw->priv;
3639 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3640 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3643 if (old_state == IEEE80211_STA_NOTEXIST &&
3644 new_state == IEEE80211_STA_NONE) {
3645 memset(arsta, 0, sizeof(*arsta));
3646 arsta->arvif = arvif;
3647 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3650 /* cancel must be done outside the mutex to avoid deadlock */
3651 if ((old_state == IEEE80211_STA_NONE &&
3652 new_state == IEEE80211_STA_NOTEXIST))
3653 cancel_work_sync(&arsta->update_wk);
3655 mutex_lock(&ar->conf_mutex);
3657 if (old_state == IEEE80211_STA_NOTEXIST &&
3658 new_state == IEEE80211_STA_NONE) {
3660 * New station addition.
3662 ath10k_dbg(ar, ATH10K_DBG_MAC,
3663 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
3664 arvif->vdev_id, sta->addr,
3665 ar->num_stations + 1, ar->max_num_stations,
3666 ar->num_peers + 1, ar->max_num_peers);
3668 ret = ath10k_mac_inc_num_stations(arvif);
3670 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
3671 ar->max_num_stations);
3675 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3677 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3678 sta->addr, arvif->vdev_id, ret);
3679 ath10k_mac_dec_num_stations(arvif);
3683 if (vif->type == NL80211_IFTYPE_STATION) {
3684 WARN_ON(arvif->is_started);
3686 ret = ath10k_vdev_start(arvif);
3688 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3689 arvif->vdev_id, ret);
3690 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
3692 ath10k_mac_dec_num_stations(arvif);
3696 arvif->is_started = true;
3698 } else if ((old_state == IEEE80211_STA_NONE &&
3699 new_state == IEEE80211_STA_NOTEXIST)) {
3701 * Existing station deletion.
3703 ath10k_dbg(ar, ATH10K_DBG_MAC,
3704 "mac vdev %d peer delete %pM (sta gone)\n",
3705 arvif->vdev_id, sta->addr);
3707 if (vif->type == NL80211_IFTYPE_STATION) {
3708 WARN_ON(!arvif->is_started);
3710 ret = ath10k_vdev_stop(arvif);
3712 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
3713 arvif->vdev_id, ret);
3715 arvif->is_started = false;
3718 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3720 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3721 sta->addr, arvif->vdev_id, ret);
3723 ath10k_mac_dec_num_stations(arvif);
3724 } else if (old_state == IEEE80211_STA_AUTH &&
3725 new_state == IEEE80211_STA_ASSOC &&
3726 (vif->type == NL80211_IFTYPE_AP ||
3727 vif->type == NL80211_IFTYPE_ADHOC)) {
3731 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3734 ret = ath10k_station_assoc(ar, vif, sta, false);
3736 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3737 sta->addr, arvif->vdev_id, ret);
3738 } else if (old_state == IEEE80211_STA_ASSOC &&
3739 new_state == IEEE80211_STA_AUTH &&
3740 (vif->type == NL80211_IFTYPE_AP ||
3741 vif->type == NL80211_IFTYPE_ADHOC)) {
3745 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3748 ret = ath10k_station_disassoc(ar, vif, sta);
3750 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3751 sta->addr, arvif->vdev_id, ret);
3754 mutex_unlock(&ar->conf_mutex);
3758 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3759 u16 ac, bool enable)
3761 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3765 lockdep_assert_held(&ar->conf_mutex);
3767 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3771 case IEEE80211_AC_VO:
3772 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3773 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3775 case IEEE80211_AC_VI:
3776 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3777 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3779 case IEEE80211_AC_BE:
3780 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3781 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3783 case IEEE80211_AC_BK:
3784 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3785 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3790 arvif->u.sta.uapsd |= value;
3792 arvif->u.sta.uapsd &= ~value;
3794 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3795 WMI_STA_PS_PARAM_UAPSD,
3796 arvif->u.sta.uapsd);
3798 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3802 if (arvif->u.sta.uapsd)
3803 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3805 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3807 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3808 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3811 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3817 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3818 struct ieee80211_vif *vif, u16 ac,
3819 const struct ieee80211_tx_queue_params *params)
3821 struct ath10k *ar = hw->priv;
3822 struct wmi_wmm_params_arg *p = NULL;
3825 mutex_lock(&ar->conf_mutex);
3828 case IEEE80211_AC_VO:
3829 p = &ar->wmm_params.ac_vo;
3831 case IEEE80211_AC_VI:
3832 p = &ar->wmm_params.ac_vi;
3834 case IEEE80211_AC_BE:
3835 p = &ar->wmm_params.ac_be;
3837 case IEEE80211_AC_BK:
3838 p = &ar->wmm_params.ac_bk;
3847 p->cwmin = params->cw_min;
3848 p->cwmax = params->cw_max;
3849 p->aifs = params->aifs;
3852 * The channel time duration programmed in the HW is in absolute
3853 * microseconds, while mac80211 gives the txop in units of
3856 p->txop = params->txop * 32;
3858 /* FIXME: FW accepts wmm params per hw, not per vif */
3859 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3861 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3865 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3867 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3870 mutex_unlock(&ar->conf_mutex);
3874 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3876 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3877 struct ieee80211_vif *vif,
3878 struct ieee80211_channel *chan,
3880 enum ieee80211_roc_type type)
3882 struct ath10k *ar = hw->priv;
3883 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3884 struct wmi_start_scan_arg arg;
3887 mutex_lock(&ar->conf_mutex);
3889 spin_lock_bh(&ar->data_lock);
3890 switch (ar->scan.state) {
3891 case ATH10K_SCAN_IDLE:
3892 reinit_completion(&ar->scan.started);
3893 reinit_completion(&ar->scan.completed);
3894 reinit_completion(&ar->scan.on_channel);
3895 ar->scan.state = ATH10K_SCAN_STARTING;
3896 ar->scan.is_roc = true;
3897 ar->scan.vdev_id = arvif->vdev_id;
3898 ar->scan.roc_freq = chan->center_freq;
3901 case ATH10K_SCAN_STARTING:
3902 case ATH10K_SCAN_RUNNING:
3903 case ATH10K_SCAN_ABORTING:
3907 spin_unlock_bh(&ar->data_lock);
3912 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
3914 memset(&arg, 0, sizeof(arg));
3915 ath10k_wmi_start_scan_init(ar, &arg);
3916 arg.vdev_id = arvif->vdev_id;
3917 arg.scan_id = ATH10K_SCAN_ID;
3919 arg.channels[0] = chan->center_freq;
3920 arg.dwell_time_active = duration;
3921 arg.dwell_time_passive = duration;
3922 arg.max_scan_time = 2 * duration;
3923 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3924 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3926 ret = ath10k_start_scan(ar, &arg);
3928 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
3929 spin_lock_bh(&ar->data_lock);
3930 ar->scan.state = ATH10K_SCAN_IDLE;
3931 spin_unlock_bh(&ar->data_lock);
3935 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3937 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
3939 ret = ath10k_scan_stop(ar);
3941 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3949 mutex_unlock(&ar->conf_mutex);
3953 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3955 struct ath10k *ar = hw->priv;
3957 mutex_lock(&ar->conf_mutex);
3958 ath10k_scan_abort(ar);
3959 mutex_unlock(&ar->conf_mutex);
3961 cancel_delayed_work_sync(&ar->scan.timeout);
3967 * Both RTS and Fragmentation threshold are interface-specific
3968 * in ath10k, but device-specific in mac80211.
3971 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3973 struct ath10k *ar = hw->priv;
3974 struct ath10k_vif *arvif;
3977 mutex_lock(&ar->conf_mutex);
3978 list_for_each_entry(arvif, &ar->arvifs, list) {
3979 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3980 arvif->vdev_id, value);
3982 ret = ath10k_mac_set_rts(arvif, value);
3984 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3985 arvif->vdev_id, ret);
3989 mutex_unlock(&ar->conf_mutex);
3994 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3996 struct ath10k *ar = hw->priv;
3997 struct ath10k_vif *arvif;
4000 mutex_lock(&ar->conf_mutex);
4001 list_for_each_entry(arvif, &ar->arvifs, list) {
4002 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
4003 arvif->vdev_id, value);
4005 ret = ath10k_mac_set_frag(arvif, value);
4007 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
4008 arvif->vdev_id, ret);
4012 mutex_unlock(&ar->conf_mutex);
4017 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4018 u32 queues, bool drop)
4020 struct ath10k *ar = hw->priv;
4024 /* mac80211 doesn't care if we really xmit queued frames or not
4025 * we'll collect those frames either way if we stop/delete vdevs */
4029 mutex_lock(&ar->conf_mutex);
4031 if (ar->state == ATH10K_STATE_WEDGED)
4034 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
4037 spin_lock_bh(&ar->htt.tx_lock);
4038 empty = (ar->htt.num_pending_tx == 0);
4039 spin_unlock_bh(&ar->htt.tx_lock);
4041 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4042 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4046 }), ATH10K_FLUSH_TIMEOUT_HZ);
4048 if (ret <= 0 || skip)
4049 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4050 skip, ar->state, ret);
4053 mutex_unlock(&ar->conf_mutex);
4056 /* TODO: Implement this function properly
4057 * For now it is needed to reply to Probe Requests in IBSS mode.
4058 * Propably we need this information from FW.
4060 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4066 static int ath10k_suspend(struct ieee80211_hw *hw,
4067 struct cfg80211_wowlan *wowlan)
4069 struct ath10k *ar = hw->priv;
4072 mutex_lock(&ar->conf_mutex);
4074 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
4076 if (ret == -ETIMEDOUT)
4082 ret = ath10k_hif_suspend(ar);
4084 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
4091 ret = ath10k_wmi_pdev_resume_target(ar);
4093 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4097 mutex_unlock(&ar->conf_mutex);
4101 static int ath10k_resume(struct ieee80211_hw *hw)
4103 struct ath10k *ar = hw->priv;
4106 mutex_lock(&ar->conf_mutex);
4108 ret = ath10k_hif_resume(ar);
4110 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
4115 ret = ath10k_wmi_pdev_resume_target(ar);
4117 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4124 mutex_unlock(&ar->conf_mutex);
4129 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4130 enum ieee80211_reconfig_type reconfig_type)
4132 struct ath10k *ar = hw->priv;
4134 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4137 mutex_lock(&ar->conf_mutex);
4139 /* If device failed to restart it will be in a different state, e.g.
4140 * ATH10K_STATE_WEDGED */
4141 if (ar->state == ATH10K_STATE_RESTARTED) {
4142 ath10k_info(ar, "device successfully recovered\n");
4143 ar->state = ATH10K_STATE_ON;
4144 ieee80211_wake_queues(ar->hw);
4147 mutex_unlock(&ar->conf_mutex);
4150 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4151 struct survey_info *survey)
4153 struct ath10k *ar = hw->priv;
4154 struct ieee80211_supported_band *sband;
4155 struct survey_info *ar_survey = &ar->survey[idx];
4158 mutex_lock(&ar->conf_mutex);
4160 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4161 if (sband && idx >= sband->n_channels) {
4162 idx -= sband->n_channels;
4167 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4169 if (!sband || idx >= sband->n_channels) {
4174 spin_lock_bh(&ar->data_lock);
4175 memcpy(survey, ar_survey, sizeof(*survey));
4176 spin_unlock_bh(&ar->data_lock);
4178 survey->channel = &sband->channels[idx];
4180 if (ar->rx_channel == survey->channel)
4181 survey->filled |= SURVEY_INFO_IN_USE;
4184 mutex_unlock(&ar->conf_mutex);
4188 /* Helper table for legacy fixed_rate/bitrate_mask */
4189 static const u8 cck_ofdm_rate[] = {
4206 /* Check if only one bit set */
4207 static int ath10k_check_single_mask(u32 mask)
4215 mask &= ~BIT(bit - 1);
4223 ath10k_default_bitrate_mask(struct ath10k *ar,
4224 enum ieee80211_band band,
4225 const struct cfg80211_bitrate_mask *mask)
4227 u32 legacy = 0x00ff;
4230 u16 nrf = ar->num_rf_chains;
4232 if (ar->cfg_tx_chainmask)
4233 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4236 case IEEE80211_BAND_2GHZ:
4240 case IEEE80211_BAND_5GHZ:
4246 if (mask->control[band].legacy != legacy)
4249 for (i = 0; i < nrf; i++)
4250 if (mask->control[band].ht_mcs[i] != ht)
4253 for (i = 0; i < nrf; i++)
4254 if (mask->control[band].vht_mcs[i] != vht)
4261 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4262 enum ieee80211_band band,
4265 int ht_nss = 0, vht_nss = 0, i;
4268 if (ath10k_check_single_mask(mask->control[band].legacy))
4272 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4273 if (mask->control[band].ht_mcs[i] == 0xff)
4275 else if (mask->control[band].ht_mcs[i] == 0x00)
4284 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4285 if (mask->control[band].vht_mcs[i] == 0x03ff)
4287 else if (mask->control[band].vht_mcs[i] == 0x0000)
4295 if (ht_nss > 0 && vht_nss > 0)
4299 *fixed_nss = ht_nss;
4301 *fixed_nss = vht_nss;
4309 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4310 enum ieee80211_band band,
4311 enum wmi_rate_preamble *preamble)
4313 int legacy = 0, ht = 0, vht = 0, i;
4315 *preamble = WMI_RATE_PREAMBLE_OFDM;
4318 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4323 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4324 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4329 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4330 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4334 /* Currently we support only one fixed_rate */
4335 if ((legacy + ht + vht) != 1)
4339 *preamble = WMI_RATE_PREAMBLE_HT;
4341 *preamble = WMI_RATE_PREAMBLE_VHT;
4347 ath10k_bitrate_mask_rate(struct ath10k *ar,
4348 const struct cfg80211_bitrate_mask *mask,
4349 enum ieee80211_band band,
4353 u8 rate = 0, pream = 0, nss = 0, i;
4354 enum wmi_rate_preamble preamble;
4356 /* Check if single rate correct */
4357 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4363 case WMI_RATE_PREAMBLE_CCK:
4364 case WMI_RATE_PREAMBLE_OFDM:
4365 i = ffs(mask->control[band].legacy) - 1;
4367 if (band == IEEE80211_BAND_2GHZ && i < 4)
4368 pream = WMI_RATE_PREAMBLE_CCK;
4370 if (band == IEEE80211_BAND_5GHZ)
4373 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4376 rate = cck_ofdm_rate[i];
4378 case WMI_RATE_PREAMBLE_HT:
4379 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4380 if (mask->control[band].ht_mcs[i])
4383 if (i == IEEE80211_HT_MCS_MASK_LEN)
4386 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4389 case WMI_RATE_PREAMBLE_VHT:
4390 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4391 if (mask->control[band].vht_mcs[i])
4394 if (i == NL80211_VHT_NSS_MAX)
4397 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4402 *fixed_nss = nss + 1;
4406 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4409 *fixed_rate = pream | nss | rate;
4414 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4415 const struct cfg80211_bitrate_mask *mask,
4416 enum ieee80211_band band,
4420 /* First check full NSS mask, if we can simply limit NSS */
4421 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4424 /* Next Check single rate is set */
4425 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4428 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4433 struct ath10k *ar = arvif->ar;
4437 mutex_lock(&ar->conf_mutex);
4439 if (arvif->fixed_rate == fixed_rate &&
4440 arvif->fixed_nss == fixed_nss &&
4441 arvif->force_sgi == force_sgi)
4444 if (fixed_rate == WMI_FIXED_RATE_NONE)
4445 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4448 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4450 vdev_param = ar->wmi.vdev_param->fixed_rate;
4451 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4452 vdev_param, fixed_rate);
4454 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4460 arvif->fixed_rate = fixed_rate;
4462 vdev_param = ar->wmi.vdev_param->nss;
4463 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4464 vdev_param, fixed_nss);
4467 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4473 arvif->fixed_nss = fixed_nss;
4475 vdev_param = ar->wmi.vdev_param->sgi;
4476 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4480 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4486 arvif->force_sgi = force_sgi;
4489 mutex_unlock(&ar->conf_mutex);
4493 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4494 struct ieee80211_vif *vif,
4495 const struct cfg80211_bitrate_mask *mask)
4497 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4498 struct ath10k *ar = arvif->ar;
4499 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4500 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4501 u8 fixed_nss = ar->num_rf_chains;
4504 if (ar->cfg_tx_chainmask)
4505 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4507 force_sgi = mask->control[band].gi;
4508 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4511 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4512 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4518 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4519 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4523 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4524 fixed_nss, force_sgi);
4527 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4528 struct ieee80211_vif *vif,
4529 struct ieee80211_sta *sta,
4532 struct ath10k *ar = hw->priv;
4533 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4536 spin_lock_bh(&ar->data_lock);
4538 ath10k_dbg(ar, ATH10K_DBG_MAC,
4539 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4540 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4543 if (changed & IEEE80211_RC_BW_CHANGED) {
4544 bw = WMI_PEER_CHWIDTH_20MHZ;
4546 switch (sta->bandwidth) {
4547 case IEEE80211_STA_RX_BW_20:
4548 bw = WMI_PEER_CHWIDTH_20MHZ;
4550 case IEEE80211_STA_RX_BW_40:
4551 bw = WMI_PEER_CHWIDTH_40MHZ;
4553 case IEEE80211_STA_RX_BW_80:
4554 bw = WMI_PEER_CHWIDTH_80MHZ;
4556 case IEEE80211_STA_RX_BW_160:
4557 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4558 sta->bandwidth, sta->addr);
4559 bw = WMI_PEER_CHWIDTH_20MHZ;
4566 if (changed & IEEE80211_RC_NSS_CHANGED)
4567 arsta->nss = sta->rx_nss;
4569 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4570 smps = WMI_PEER_SMPS_PS_NONE;
4572 switch (sta->smps_mode) {
4573 case IEEE80211_SMPS_AUTOMATIC:
4574 case IEEE80211_SMPS_OFF:
4575 smps = WMI_PEER_SMPS_PS_NONE;
4577 case IEEE80211_SMPS_STATIC:
4578 smps = WMI_PEER_SMPS_STATIC;
4580 case IEEE80211_SMPS_DYNAMIC:
4581 smps = WMI_PEER_SMPS_DYNAMIC;
4583 case IEEE80211_SMPS_NUM_MODES:
4584 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4585 sta->smps_mode, sta->addr);
4586 smps = WMI_PEER_SMPS_PS_NONE;
4593 arsta->changed |= changed;
4595 spin_unlock_bh(&ar->data_lock);
4597 ieee80211_queue_work(hw, &arsta->update_wk);
4600 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4603 * FIXME: Return 0 for time being. Need to figure out whether FW
4604 * has the API to fetch 64-bit local TSF
4610 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4611 struct ieee80211_vif *vif,
4612 enum ieee80211_ampdu_mlme_action action,
4613 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4616 struct ath10k *ar = hw->priv;
4617 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4619 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4620 arvif->vdev_id, sta->addr, tid, action);
4623 case IEEE80211_AMPDU_RX_START:
4624 case IEEE80211_AMPDU_RX_STOP:
4625 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4626 * creation/removal. Do we need to verify this?
4629 case IEEE80211_AMPDU_TX_START:
4630 case IEEE80211_AMPDU_TX_STOP_CONT:
4631 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4632 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4633 case IEEE80211_AMPDU_TX_OPERATIONAL:
4634 /* Firmware offloads Tx aggregation entirely so deny mac80211
4635 * Tx aggregation requests.
4643 static const struct ieee80211_ops ath10k_ops = {
4645 .start = ath10k_start,
4646 .stop = ath10k_stop,
4647 .config = ath10k_config,
4648 .add_interface = ath10k_add_interface,
4649 .remove_interface = ath10k_remove_interface,
4650 .configure_filter = ath10k_configure_filter,
4651 .bss_info_changed = ath10k_bss_info_changed,
4652 .hw_scan = ath10k_hw_scan,
4653 .cancel_hw_scan = ath10k_cancel_hw_scan,
4654 .set_key = ath10k_set_key,
4655 .sta_state = ath10k_sta_state,
4656 .conf_tx = ath10k_conf_tx,
4657 .remain_on_channel = ath10k_remain_on_channel,
4658 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4659 .set_rts_threshold = ath10k_set_rts_threshold,
4660 .set_frag_threshold = ath10k_set_frag_threshold,
4661 .flush = ath10k_flush,
4662 .tx_last_beacon = ath10k_tx_last_beacon,
4663 .set_antenna = ath10k_set_antenna,
4664 .get_antenna = ath10k_get_antenna,
4665 .reconfig_complete = ath10k_reconfig_complete,
4666 .get_survey = ath10k_get_survey,
4667 .set_bitrate_mask = ath10k_set_bitrate_mask,
4668 .sta_rc_update = ath10k_sta_rc_update,
4669 .get_tsf = ath10k_get_tsf,
4670 .ampdu_action = ath10k_ampdu_action,
4671 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4672 .get_et_stats = ath10k_debug_get_et_stats,
4673 .get_et_strings = ath10k_debug_get_et_strings,
4675 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4678 .suspend = ath10k_suspend,
4679 .resume = ath10k_resume,
4683 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4684 .bitrate = (_rate), \
4685 .flags = (_flags), \
4686 .hw_value = (_rateid), \
4689 #define CHAN2G(_channel, _freq, _flags) { \
4690 .band = IEEE80211_BAND_2GHZ, \
4691 .hw_value = (_channel), \
4692 .center_freq = (_freq), \
4693 .flags = (_flags), \
4694 .max_antenna_gain = 0, \
4698 #define CHAN5G(_channel, _freq, _flags) { \
4699 .band = IEEE80211_BAND_5GHZ, \
4700 .hw_value = (_channel), \
4701 .center_freq = (_freq), \
4702 .flags = (_flags), \
4703 .max_antenna_gain = 0, \
4707 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4717 CHAN2G(10, 2457, 0),
4718 CHAN2G(11, 2462, 0),
4719 CHAN2G(12, 2467, 0),
4720 CHAN2G(13, 2472, 0),
4721 CHAN2G(14, 2484, 0),
4724 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4725 CHAN5G(36, 5180, 0),
4726 CHAN5G(40, 5200, 0),
4727 CHAN5G(44, 5220, 0),
4728 CHAN5G(48, 5240, 0),
4729 CHAN5G(52, 5260, 0),
4730 CHAN5G(56, 5280, 0),
4731 CHAN5G(60, 5300, 0),
4732 CHAN5G(64, 5320, 0),
4733 CHAN5G(100, 5500, 0),
4734 CHAN5G(104, 5520, 0),
4735 CHAN5G(108, 5540, 0),
4736 CHAN5G(112, 5560, 0),
4737 CHAN5G(116, 5580, 0),
4738 CHAN5G(120, 5600, 0),
4739 CHAN5G(124, 5620, 0),
4740 CHAN5G(128, 5640, 0),
4741 CHAN5G(132, 5660, 0),
4742 CHAN5G(136, 5680, 0),
4743 CHAN5G(140, 5700, 0),
4744 CHAN5G(149, 5745, 0),
4745 CHAN5G(153, 5765, 0),
4746 CHAN5G(157, 5785, 0),
4747 CHAN5G(161, 5805, 0),
4748 CHAN5G(165, 5825, 0),
4751 static struct ieee80211_rate ath10k_rates[] = {
4753 RATETAB_ENT(10, 0x82, 0),
4754 RATETAB_ENT(20, 0x84, 0),
4755 RATETAB_ENT(55, 0x8b, 0),
4756 RATETAB_ENT(110, 0x96, 0),
4758 RATETAB_ENT(60, 0x0c, 0),
4759 RATETAB_ENT(90, 0x12, 0),
4760 RATETAB_ENT(120, 0x18, 0),
4761 RATETAB_ENT(180, 0x24, 0),
4762 RATETAB_ENT(240, 0x30, 0),
4763 RATETAB_ENT(360, 0x48, 0),
4764 RATETAB_ENT(480, 0x60, 0),
4765 RATETAB_ENT(540, 0x6c, 0),
4768 #define ath10k_a_rates (ath10k_rates + 4)
4769 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4770 #define ath10k_g_rates (ath10k_rates + 0)
4771 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4773 struct ath10k *ath10k_mac_create(size_t priv_size)
4775 struct ieee80211_hw *hw;
4778 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4788 void ath10k_mac_destroy(struct ath10k *ar)
4790 ieee80211_free_hw(ar->hw);
4793 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4796 .types = BIT(NL80211_IFTYPE_STATION)
4797 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4801 .types = BIT(NL80211_IFTYPE_P2P_GO)
4805 .types = BIT(NL80211_IFTYPE_AP)
4809 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4812 .types = BIT(NL80211_IFTYPE_AP)
4816 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4818 .limits = ath10k_if_limits,
4819 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4820 .max_interfaces = 8,
4821 .num_different_channels = 1,
4822 .beacon_int_infra_match = true,
4826 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4828 .limits = ath10k_10x_if_limits,
4829 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4830 .max_interfaces = 8,
4831 .num_different_channels = 1,
4832 .beacon_int_infra_match = true,
4833 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4834 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4835 BIT(NL80211_CHAN_WIDTH_20) |
4836 BIT(NL80211_CHAN_WIDTH_40) |
4837 BIT(NL80211_CHAN_WIDTH_80),
4842 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4844 struct ieee80211_sta_vht_cap vht_cap = {0};
4848 vht_cap.vht_supported = 1;
4849 vht_cap.cap = ar->vht_cap_info;
4852 for (i = 0; i < 8; i++) {
4853 if (i < ar->num_rf_chains)
4854 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4856 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4859 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4860 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4865 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4868 struct ieee80211_sta_ht_cap ht_cap = {0};
4870 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4873 ht_cap.ht_supported = 1;
4874 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4875 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4876 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4877 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4878 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4880 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4881 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4883 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4884 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4886 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4889 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4890 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4895 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4896 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4898 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4901 stbc = ar->ht_cap_info;
4902 stbc &= WMI_HT_CAP_RX_STBC;
4903 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4904 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4905 stbc &= IEEE80211_HT_CAP_RX_STBC;
4910 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4911 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4913 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4914 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4916 /* max AMSDU is implicitly taken from vht_cap_info */
4917 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4918 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4920 for (i = 0; i < ar->num_rf_chains; i++)
4921 ht_cap.mcs.rx_mask[i] = 0xFF;
4923 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4928 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4929 struct ieee80211_vif *vif)
4931 struct ath10k_vif_iter *arvif_iter = data;
4932 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4934 if (arvif->vdev_id == arvif_iter->vdev_id)
4935 arvif_iter->arvif = arvif;
4938 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4940 struct ath10k_vif_iter arvif_iter;
4943 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4944 arvif_iter.vdev_id = vdev_id;
4946 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4947 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4949 ath10k_get_arvif_iter,
4951 if (!arvif_iter.arvif) {
4952 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
4956 return arvif_iter.arvif;
4959 int ath10k_mac_register(struct ath10k *ar)
4961 struct ieee80211_supported_band *band;
4962 struct ieee80211_sta_vht_cap vht_cap;
4963 struct ieee80211_sta_ht_cap ht_cap;
4967 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4969 SET_IEEE80211_DEV(ar->hw, ar->dev);
4971 ht_cap = ath10k_get_ht_cap(ar);
4972 vht_cap = ath10k_create_vht_cap(ar);
4974 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4975 channels = kmemdup(ath10k_2ghz_channels,
4976 sizeof(ath10k_2ghz_channels),
4983 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4984 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4985 band->channels = channels;
4986 band->n_bitrates = ath10k_g_rates_size;
4987 band->bitrates = ath10k_g_rates;
4988 band->ht_cap = ht_cap;
4990 /* vht is not supported in 2.4 GHz */
4992 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4995 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4996 channels = kmemdup(ath10k_5ghz_channels,
4997 sizeof(ath10k_5ghz_channels),
5004 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5005 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5006 band->channels = channels;
5007 band->n_bitrates = ath10k_a_rates_size;
5008 band->bitrates = ath10k_a_rates;
5009 band->ht_cap = ht_cap;
5010 band->vht_cap = vht_cap;
5011 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5014 ar->hw->wiphy->interface_modes =
5015 BIT(NL80211_IFTYPE_STATION) |
5016 BIT(NL80211_IFTYPE_AP);
5018 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5019 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5021 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5022 ar->hw->wiphy->interface_modes |=
5023 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5024 BIT(NL80211_IFTYPE_P2P_GO);
5026 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5027 IEEE80211_HW_SUPPORTS_PS |
5028 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5029 IEEE80211_HW_MFP_CAPABLE |
5030 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5031 IEEE80211_HW_HAS_RATE_CONTROL |
5032 IEEE80211_HW_AP_LINK_PS |
5033 IEEE80211_HW_SPECTRUM_MGMT;
5035 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5037 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5038 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
5040 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5041 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5042 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5045 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5046 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5048 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
5049 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5051 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5053 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
5054 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5055 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5057 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5058 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5061 * on LL hardware queues are managed entirely by the FW
5062 * so we only advertise to mac we can do the queues thing
5066 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
5067 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5068 ar->hw->wiphy->n_iface_combinations =
5069 ARRAY_SIZE(ath10k_10x_if_comb);
5071 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5072 ar->hw->wiphy->n_iface_combinations =
5073 ARRAY_SIZE(ath10k_if_comb);
5075 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
5078 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5080 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5081 /* Init ath dfs pattern detector */
5082 ar->ath_common.debug_mask = ATH_DBG_DFS;
5083 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5086 if (!ar->dfs_detector)
5087 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
5090 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5091 ath10k_reg_notifier);
5093 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
5097 ret = ieee80211_register_hw(ar->hw);
5099 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
5103 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5104 ret = regulatory_hint(ar->hw->wiphy,
5105 ar->ath_common.regulatory.alpha2);
5107 goto err_unregister;
5113 ieee80211_unregister_hw(ar->hw);
5115 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5116 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5121 void ath10k_mac_unregister(struct ath10k *ar)
5123 ieee80211_unregister_hw(ar->hw);
5125 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5126 ar->dfs_detector->exit(ar->dfs_detector);
5128 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5129 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5131 SET_IEEE80211_DEV(ar->hw, NULL);