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>
34 static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
47 lockdep_assert_held(&arvif->ar->conf_mutex);
49 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
52 arg.key_flags = WMI_KEY_GROUP;
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
59 case WLAN_CIPHER_SUITE_TKIP:
60 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
85 static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
90 struct ath10k *ar = arvif->ar;
93 lockdep_assert_held(&ar->conf_mutex);
95 reinit_completion(&ar->install_key_done);
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
108 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
116 lockdep_assert_held(&ar->conf_mutex);
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
134 peer->keys[i] = arvif->wep_keys[i];
140 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
149 lockdep_assert_held(&ar->conf_mutex);
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
162 ret = ath10k_install_key(arvif, peer->keys[i],
164 if (ret && first_errno == 0)
168 ath10k_warn("failed to remove peer wep key %d: %d\n",
171 peer->keys[i] = NULL;
177 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
187 lockdep_assert_held(&ar->conf_mutex);
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
203 if (i < ARRAY_SIZE(peer->keys))
206 spin_unlock_bh(&ar->data_lock);
208 if (i == ARRAY_SIZE(peer->keys))
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
216 ath10k_warn("failed to remove key for %pM: %d\n",
224 /*********************/
225 /* General utilities */
226 /*********************/
228 static inline enum wmi_phy_mode
229 chan_to_phymode(const struct cfg80211_chan_def *chandef)
231 enum wmi_phy_mode phymode = MODE_UNKNOWN;
233 switch (chandef->chan->band) {
234 case IEEE80211_BAND_2GHZ:
235 switch (chandef->width) {
236 case NL80211_CHAN_WIDTH_20_NOHT:
239 case NL80211_CHAN_WIDTH_20:
240 phymode = MODE_11NG_HT20;
242 case NL80211_CHAN_WIDTH_40:
243 phymode = MODE_11NG_HT40;
245 case NL80211_CHAN_WIDTH_5:
246 case NL80211_CHAN_WIDTH_10:
247 case NL80211_CHAN_WIDTH_80:
248 case NL80211_CHAN_WIDTH_80P80:
249 case NL80211_CHAN_WIDTH_160:
250 phymode = MODE_UNKNOWN;
254 case IEEE80211_BAND_5GHZ:
255 switch (chandef->width) {
256 case NL80211_CHAN_WIDTH_20_NOHT:
259 case NL80211_CHAN_WIDTH_20:
260 phymode = MODE_11NA_HT20;
262 case NL80211_CHAN_WIDTH_40:
263 phymode = MODE_11NA_HT40;
265 case NL80211_CHAN_WIDTH_80:
266 phymode = MODE_11AC_VHT80;
268 case NL80211_CHAN_WIDTH_5:
269 case NL80211_CHAN_WIDTH_10:
270 case NL80211_CHAN_WIDTH_80P80:
271 case NL80211_CHAN_WIDTH_160:
272 phymode = MODE_UNKNOWN;
280 WARN_ON(phymode == MODE_UNKNOWN);
284 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
287 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
288 * 0 for no restriction
297 switch (mpdudensity) {
303 /* Our lower layer calculations limit our precision to
319 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
323 lockdep_assert_held(&ar->conf_mutex);
325 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
327 ath10k_warn("failed to create wmi peer %pM on vdev %i: %i\n",
332 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
334 ath10k_warn("failed to wait for created wmi peer %pM on vdev %i: %i\n",
338 spin_lock_bh(&ar->data_lock);
340 spin_unlock_bh(&ar->data_lock);
345 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
347 struct ath10k *ar = arvif->ar;
351 param = ar->wmi.pdev_param->sta_kickout_th;
352 ret = ath10k_wmi_pdev_set_param(ar, param,
353 ATH10K_KICKOUT_THRESHOLD);
355 ath10k_warn("failed to set kickout threshold on vdev %i: %d\n",
356 arvif->vdev_id, ret);
360 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
361 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
362 ATH10K_KEEPALIVE_MIN_IDLE);
364 ath10k_warn("failed to set keepalive minimum idle time on vdev %i: %d\n",
365 arvif->vdev_id, ret);
369 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
370 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
371 ATH10K_KEEPALIVE_MAX_IDLE);
373 ath10k_warn("failed to set keepalive maximum idle time on vdev %i: %d\n",
374 arvif->vdev_id, ret);
378 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
379 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
380 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
382 ath10k_warn("failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
383 arvif->vdev_id, ret);
390 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
392 struct ath10k *ar = arvif->ar;
395 if (value != 0xFFFFFFFF)
396 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
399 vdev_param = ar->wmi.vdev_param->rts_threshold;
400 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
403 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
405 struct ath10k *ar = arvif->ar;
408 if (value != 0xFFFFFFFF)
409 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
410 ATH10K_FRAGMT_THRESHOLD_MIN,
411 ATH10K_FRAGMT_THRESHOLD_MAX);
413 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
414 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
417 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
421 lockdep_assert_held(&ar->conf_mutex);
423 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
427 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
431 spin_lock_bh(&ar->data_lock);
433 spin_unlock_bh(&ar->data_lock);
438 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
440 struct ath10k_peer *peer, *tmp;
442 lockdep_assert_held(&ar->conf_mutex);
444 spin_lock_bh(&ar->data_lock);
445 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
446 if (peer->vdev_id != vdev_id)
449 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
450 peer->addr, vdev_id);
452 list_del(&peer->list);
456 spin_unlock_bh(&ar->data_lock);
459 static void ath10k_peer_cleanup_all(struct ath10k *ar)
461 struct ath10k_peer *peer, *tmp;
463 lockdep_assert_held(&ar->conf_mutex);
465 spin_lock_bh(&ar->data_lock);
466 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
467 list_del(&peer->list);
471 spin_unlock_bh(&ar->data_lock);
474 /************************/
475 /* Interface management */
476 /************************/
478 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
482 lockdep_assert_held(&ar->conf_mutex);
484 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
485 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
492 static bool ath10k_monitor_is_enabled(struct ath10k *ar)
494 lockdep_assert_held(&ar->conf_mutex);
496 ath10k_dbg(ATH10K_DBG_MAC,
497 "mac monitor refs: promisc %d monitor %d cac %d\n",
498 ar->promisc, ar->monitor,
499 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags));
501 return ar->promisc || ar->monitor ||
502 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
505 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
507 struct cfg80211_chan_def *chandef = &ar->chandef;
508 struct ieee80211_channel *channel = chandef->chan;
509 struct wmi_vdev_start_request_arg arg = {};
512 lockdep_assert_held(&ar->conf_mutex);
514 arg.vdev_id = vdev_id;
515 arg.channel.freq = channel->center_freq;
516 arg.channel.band_center_freq1 = chandef->center_freq1;
518 /* TODO setup this dynamically, what in case we
519 don't have any vifs? */
520 arg.channel.mode = chan_to_phymode(chandef);
521 arg.channel.chan_radar =
522 !!(channel->flags & IEEE80211_CHAN_RADAR);
524 arg.channel.min_power = 0;
525 arg.channel.max_power = channel->max_power * 2;
526 arg.channel.max_reg_power = channel->max_reg_power * 2;
527 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
529 ret = ath10k_wmi_vdev_start(ar, &arg);
531 ath10k_warn("failed to request monitor vdev %i start: %d\n",
536 ret = ath10k_vdev_setup_sync(ar);
538 ath10k_warn("failed to synchronize setup for monitor vdev %i: %d\n",
543 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
545 ath10k_warn("failed to put up monitor vdev %i: %d\n",
550 ar->monitor_vdev_id = vdev_id;
552 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
553 ar->monitor_vdev_id);
557 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
559 ath10k_warn("failed to stop monitor vdev %i after start failure: %d\n",
560 ar->monitor_vdev_id, ret);
565 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
569 lockdep_assert_held(&ar->conf_mutex);
571 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
573 ath10k_warn("failed to put down monitor vdev %i: %d\n",
574 ar->monitor_vdev_id, ret);
576 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
578 ath10k_warn("failed to to request monitor vdev %i stop: %d\n",
579 ar->monitor_vdev_id, ret);
581 ret = ath10k_vdev_setup_sync(ar);
583 ath10k_warn("failed to synchronise monitor vdev %i: %d\n",
584 ar->monitor_vdev_id, ret);
586 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
587 ar->monitor_vdev_id);
591 static int ath10k_monitor_vdev_create(struct ath10k *ar)
595 lockdep_assert_held(&ar->conf_mutex);
597 bit = ffs(ar->free_vdev_map);
599 ath10k_warn("failed to find free vdev id for monitor vdev\n");
603 ar->monitor_vdev_id = bit - 1;
604 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
606 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
607 WMI_VDEV_TYPE_MONITOR,
610 ath10k_warn("failed to request monitor vdev %i creation: %d\n",
611 ar->monitor_vdev_id, ret);
615 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
616 ar->monitor_vdev_id);
622 * Restore the ID to the global map.
624 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
628 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
632 lockdep_assert_held(&ar->conf_mutex);
634 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
636 ath10k_warn("failed to request wmi monitor vdev %i removal: %d\n",
637 ar->monitor_vdev_id, ret);
641 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
643 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
644 ar->monitor_vdev_id);
648 static int ath10k_monitor_start(struct ath10k *ar)
652 lockdep_assert_held(&ar->conf_mutex);
654 if (!ath10k_monitor_is_enabled(ar)) {
655 ath10k_warn("trying to start monitor with no references\n");
659 if (ar->monitor_started) {
660 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor already started\n");
664 ret = ath10k_monitor_vdev_create(ar);
666 ath10k_warn("failed to create monitor vdev: %d\n", ret);
670 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
672 ath10k_warn("failed to start monitor vdev: %d\n", ret);
673 ath10k_monitor_vdev_delete(ar);
677 ar->monitor_started = true;
678 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor started\n");
683 static void ath10k_monitor_stop(struct ath10k *ar)
687 lockdep_assert_held(&ar->conf_mutex);
689 if (ath10k_monitor_is_enabled(ar)) {
690 ath10k_dbg(ATH10K_DBG_MAC,
691 "mac monitor will be stopped later\n");
695 if (!ar->monitor_started) {
696 ath10k_dbg(ATH10K_DBG_MAC,
697 "mac monitor probably failed to start earlier\n");
701 ret = ath10k_monitor_vdev_stop(ar);
703 ath10k_warn("failed to stop monitor vdev: %d\n", ret);
705 ret = ath10k_monitor_vdev_delete(ar);
707 ath10k_warn("failed to delete monitor vdev: %d\n", ret);
709 ar->monitor_started = false;
710 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor stopped\n");
713 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
715 struct ath10k *ar = arvif->ar;
716 u32 vdev_param, rts_cts = 0;
718 lockdep_assert_held(&ar->conf_mutex);
720 vdev_param = ar->wmi.vdev_param->enable_rtscts;
722 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
723 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
725 if (arvif->num_legacy_stations > 0)
726 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
729 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
733 static int ath10k_start_cac(struct ath10k *ar)
737 lockdep_assert_held(&ar->conf_mutex);
739 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
741 ret = ath10k_monitor_start(ar);
743 ath10k_warn("failed to start monitor (cac): %d\n", ret);
744 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
748 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
749 ar->monitor_vdev_id);
754 static int ath10k_stop_cac(struct ath10k *ar)
756 lockdep_assert_held(&ar->conf_mutex);
758 /* CAC is not running - do nothing */
759 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
762 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
763 ath10k_monitor_stop(ar);
765 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
770 static void ath10k_recalc_radar_detection(struct ath10k *ar)
774 lockdep_assert_held(&ar->conf_mutex);
778 if (!ar->radar_enabled)
781 if (ar->num_started_vdevs > 0)
784 ret = ath10k_start_cac(ar);
787 * Not possible to start CAC on current channel so starting
788 * radiation is not allowed, make this channel DFS_UNAVAILABLE
789 * by indicating that radar was detected.
791 ath10k_warn("failed to start CAC: %d\n", ret);
792 ieee80211_radar_detected(ar->hw);
796 static int ath10k_vdev_start(struct ath10k_vif *arvif)
798 struct ath10k *ar = arvif->ar;
799 struct cfg80211_chan_def *chandef = &ar->chandef;
800 struct wmi_vdev_start_request_arg arg = {};
803 lockdep_assert_held(&ar->conf_mutex);
805 reinit_completion(&ar->vdev_setup_done);
807 arg.vdev_id = arvif->vdev_id;
808 arg.dtim_period = arvif->dtim_period;
809 arg.bcn_intval = arvif->beacon_interval;
811 arg.channel.freq = chandef->chan->center_freq;
812 arg.channel.band_center_freq1 = chandef->center_freq1;
813 arg.channel.mode = chan_to_phymode(chandef);
815 arg.channel.min_power = 0;
816 arg.channel.max_power = chandef->chan->max_power * 2;
817 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
818 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
820 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
821 arg.ssid = arvif->u.ap.ssid;
822 arg.ssid_len = arvif->u.ap.ssid_len;
823 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
825 /* For now allow DFS for AP mode */
826 arg.channel.chan_radar =
827 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
828 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
829 arg.ssid = arvif->vif->bss_conf.ssid;
830 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
833 ath10k_dbg(ATH10K_DBG_MAC,
834 "mac vdev %d start center_freq %d phymode %s\n",
835 arg.vdev_id, arg.channel.freq,
836 ath10k_wmi_phymode_str(arg.channel.mode));
838 ret = ath10k_wmi_vdev_start(ar, &arg);
840 ath10k_warn("failed to start WMI vdev %i: %d\n",
845 ret = ath10k_vdev_setup_sync(ar);
847 ath10k_warn("failed to synchronise setup for vdev %i: %d\n",
852 ar->num_started_vdevs++;
853 ath10k_recalc_radar_detection(ar);
858 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
860 struct ath10k *ar = arvif->ar;
863 lockdep_assert_held(&ar->conf_mutex);
865 reinit_completion(&ar->vdev_setup_done);
867 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
869 ath10k_warn("failed to stop WMI vdev %i: %d\n",
870 arvif->vdev_id, ret);
874 ret = ath10k_vdev_setup_sync(ar);
876 ath10k_warn("failed to syncronise setup for vdev %i: %d\n",
877 arvif->vdev_id, ret);
881 WARN_ON(ar->num_started_vdevs == 0);
883 if (ar->num_started_vdevs != 0) {
884 ar->num_started_vdevs--;
885 ath10k_recalc_radar_detection(ar);
891 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
892 struct ieee80211_bss_conf *info)
896 lockdep_assert_held(&arvif->ar->conf_mutex);
898 if (!info->enable_beacon) {
899 ath10k_vdev_stop(arvif);
901 arvif->is_started = false;
902 arvif->is_up = false;
904 spin_lock_bh(&arvif->ar->data_lock);
906 dma_unmap_single(arvif->ar->dev,
907 ATH10K_SKB_CB(arvif->beacon)->paddr,
908 arvif->beacon->len, DMA_TO_DEVICE);
909 dev_kfree_skb_any(arvif->beacon);
911 arvif->beacon = NULL;
912 arvif->beacon_sent = false;
914 spin_unlock_bh(&arvif->ar->data_lock);
919 arvif->tx_seq_no = 0x1000;
921 ret = ath10k_vdev_start(arvif);
926 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
928 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
931 ath10k_warn("failed to bring up vdev %d: %i\n",
932 arvif->vdev_id, ret);
933 ath10k_vdev_stop(arvif);
937 arvif->is_started = true;
940 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
943 static void ath10k_control_ibss(struct ath10k_vif *arvif,
944 struct ieee80211_bss_conf *info,
945 const u8 self_peer[ETH_ALEN])
950 lockdep_assert_held(&arvif->ar->conf_mutex);
952 if (!info->ibss_joined) {
953 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
955 ath10k_warn("failed to delete IBSS self peer %pM for vdev %d: %d\n",
956 self_peer, arvif->vdev_id, ret);
958 if (is_zero_ether_addr(arvif->bssid))
961 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
964 ath10k_warn("failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
965 arvif->bssid, arvif->vdev_id, ret);
969 memset(arvif->bssid, 0, ETH_ALEN);
974 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
976 ath10k_warn("failed to create IBSS self peer %pM for vdev %d: %d\n",
977 self_peer, arvif->vdev_id, ret);
981 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
982 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
983 ATH10K_DEFAULT_ATIM);
985 ath10k_warn("failed to set IBSS ATIM for vdev %d: %d\n",
986 arvif->vdev_id, ret);
990 * Review this when mac80211 gains per-interface powersave support.
992 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
994 struct ath10k *ar = arvif->ar;
995 struct ieee80211_conf *conf = &ar->hw->conf;
996 enum wmi_sta_powersave_param param;
997 enum wmi_sta_ps_mode psmode;
1000 lockdep_assert_held(&arvif->ar->conf_mutex);
1002 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1005 if (conf->flags & IEEE80211_CONF_PS) {
1006 psmode = WMI_STA_PS_MODE_ENABLED;
1007 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1009 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1010 conf->dynamic_ps_timeout);
1012 ath10k_warn("failed to set inactivity time for vdev %d: %i\n",
1013 arvif->vdev_id, ret);
1017 psmode = WMI_STA_PS_MODE_DISABLED;
1020 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1021 arvif->vdev_id, psmode ? "enable" : "disable");
1023 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1025 ath10k_warn("failed to set PS Mode %d for vdev %d: %d\n",
1026 psmode, arvif->vdev_id, ret);
1033 /**********************/
1034 /* Station management */
1035 /**********************/
1037 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1038 struct ath10k_vif *arvif,
1039 struct ieee80211_sta *sta,
1040 struct ieee80211_bss_conf *bss_conf,
1041 struct wmi_peer_assoc_complete_arg *arg)
1043 lockdep_assert_held(&ar->conf_mutex);
1045 memcpy(arg->addr, sta->addr, ETH_ALEN);
1046 arg->vdev_id = arvif->vdev_id;
1047 arg->peer_aid = sta->aid;
1048 arg->peer_flags |= WMI_PEER_AUTH;
1050 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
1052 * Seems FW have problems with Power Save in STA
1053 * mode when we setup this parameter to high (eg. 5).
1054 * Often we see that FW don't send NULL (with clean P flags)
1055 * frame even there is info about buffered frames in beacons.
1056 * Sometimes we have to wait more than 10 seconds before FW
1057 * will wakeup. Often sending one ping from AP to our device
1058 * just fail (more than 50%).
1060 * Seems setting this FW parameter to 1 couse FW
1061 * will check every beacon and will wakup immediately
1062 * after detection buffered data.
1064 arg->peer_listen_intval = 1;
1066 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1068 arg->peer_num_spatial_streams = 1;
1071 * The assoc capabilities are available only in managed mode.
1073 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1074 arg->peer_caps = bss_conf->assoc_capability;
1077 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1078 struct ath10k_vif *arvif,
1079 struct wmi_peer_assoc_complete_arg *arg)
1081 struct ieee80211_vif *vif = arvif->vif;
1082 struct ieee80211_bss_conf *info = &vif->bss_conf;
1083 struct cfg80211_bss *bss;
1084 const u8 *rsnie = NULL;
1085 const u8 *wpaie = NULL;
1087 lockdep_assert_held(&ar->conf_mutex);
1089 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1090 info->bssid, NULL, 0, 0, 0);
1092 const struct cfg80211_bss_ies *ies;
1095 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1097 ies = rcu_dereference(bss->ies);
1099 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1100 WLAN_OUI_TYPE_MICROSOFT_WPA,
1104 cfg80211_put_bss(ar->hw->wiphy, bss);
1107 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1108 if (rsnie || wpaie) {
1109 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1110 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1114 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1115 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1119 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1120 struct ieee80211_sta *sta,
1121 struct wmi_peer_assoc_complete_arg *arg)
1123 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1124 const struct ieee80211_supported_band *sband;
1125 const struct ieee80211_rate *rates;
1129 lockdep_assert_held(&ar->conf_mutex);
1131 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1132 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1133 rates = sband->bitrates;
1135 rateset->num_rates = 0;
1137 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1138 if (!(ratemask & 1))
1141 rateset->rates[rateset->num_rates] = rates->hw_value;
1142 rateset->num_rates++;
1146 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1147 struct ieee80211_sta *sta,
1148 struct wmi_peer_assoc_complete_arg *arg)
1150 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1153 lockdep_assert_held(&ar->conf_mutex);
1155 if (!ht_cap->ht_supported)
1158 arg->peer_flags |= WMI_PEER_HT;
1159 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1160 ht_cap->ampdu_factor)) - 1;
1162 arg->peer_mpdu_density =
1163 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1165 arg->peer_ht_caps = ht_cap->cap;
1166 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1168 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1169 arg->peer_flags |= WMI_PEER_LDPC;
1171 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1172 arg->peer_flags |= WMI_PEER_40MHZ;
1173 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1176 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1177 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1179 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1180 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1182 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1183 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1184 arg->peer_flags |= WMI_PEER_STBC;
1187 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1189 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1190 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1191 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1192 arg->peer_rate_caps |= stbc;
1193 arg->peer_flags |= WMI_PEER_STBC;
1196 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1197 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1198 else if (ht_cap->mcs.rx_mask[1])
1199 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1201 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1202 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1203 arg->peer_ht_rates.rates[n++] = i;
1206 * This is a workaround for HT-enabled STAs which break the spec
1207 * and have no HT capabilities RX mask (no HT RX MCS map).
1209 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1210 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1212 * Firmware asserts if such situation occurs.
1215 arg->peer_ht_rates.num_rates = 8;
1216 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1217 arg->peer_ht_rates.rates[i] = i;
1219 arg->peer_ht_rates.num_rates = n;
1220 arg->peer_num_spatial_streams = sta->rx_nss;
1223 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1225 arg->peer_ht_rates.num_rates,
1226 arg->peer_num_spatial_streams);
1229 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1230 struct ath10k_vif *arvif,
1231 struct ieee80211_sta *sta)
1237 lockdep_assert_held(&ar->conf_mutex);
1239 if (sta->wme && sta->uapsd_queues) {
1240 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1241 sta->uapsd_queues, sta->max_sp);
1243 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1244 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1245 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1246 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1247 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1248 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1249 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1250 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1251 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1252 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1253 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1254 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1257 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1258 max_sp = sta->max_sp;
1260 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1262 WMI_AP_PS_PEER_PARAM_UAPSD,
1265 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1266 arvif->vdev_id, ret);
1270 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1272 WMI_AP_PS_PEER_PARAM_MAX_SP,
1275 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1276 arvif->vdev_id, ret);
1280 /* TODO setup this based on STA listen interval and
1281 beacon interval. Currently we don't know
1282 sta->listen_interval - mac80211 patch required.
1283 Currently use 10 seconds */
1284 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1285 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1287 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1288 arvif->vdev_id, ret);
1296 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1297 struct ieee80211_sta *sta,
1298 struct wmi_peer_assoc_complete_arg *arg)
1300 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1303 if (!vht_cap->vht_supported)
1306 arg->peer_flags |= WMI_PEER_VHT;
1307 arg->peer_vht_caps = vht_cap->cap;
1310 ampdu_factor = (vht_cap->cap &
1311 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1312 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1314 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1315 * zero in VHT IE. Using it would result in degraded throughput.
1316 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1317 * it if VHT max_mpdu is smaller. */
1318 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1319 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1320 ampdu_factor)) - 1);
1322 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1323 arg->peer_flags |= WMI_PEER_80MHZ;
1325 arg->peer_vht_rates.rx_max_rate =
1326 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1327 arg->peer_vht_rates.rx_mcs_set =
1328 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1329 arg->peer_vht_rates.tx_max_rate =
1330 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1331 arg->peer_vht_rates.tx_mcs_set =
1332 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1334 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1335 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1338 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1339 struct ath10k_vif *arvif,
1340 struct ieee80211_sta *sta,
1341 struct ieee80211_bss_conf *bss_conf,
1342 struct wmi_peer_assoc_complete_arg *arg)
1344 switch (arvif->vdev_type) {
1345 case WMI_VDEV_TYPE_AP:
1347 arg->peer_flags |= WMI_PEER_QOS;
1349 if (sta->wme && sta->uapsd_queues) {
1350 arg->peer_flags |= WMI_PEER_APSD;
1351 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1354 case WMI_VDEV_TYPE_STA:
1356 arg->peer_flags |= WMI_PEER_QOS;
1363 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1364 struct ath10k_vif *arvif,
1365 struct ieee80211_sta *sta,
1366 struct wmi_peer_assoc_complete_arg *arg)
1368 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1370 switch (ar->hw->conf.chandef.chan->band) {
1371 case IEEE80211_BAND_2GHZ:
1372 if (sta->ht_cap.ht_supported) {
1373 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1374 phymode = MODE_11NG_HT40;
1376 phymode = MODE_11NG_HT20;
1382 case IEEE80211_BAND_5GHZ:
1386 if (sta->vht_cap.vht_supported) {
1387 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1388 phymode = MODE_11AC_VHT80;
1389 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1390 phymode = MODE_11AC_VHT40;
1391 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1392 phymode = MODE_11AC_VHT20;
1393 } else if (sta->ht_cap.ht_supported) {
1394 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1395 phymode = MODE_11NA_HT40;
1397 phymode = MODE_11NA_HT20;
1407 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1408 sta->addr, ath10k_wmi_phymode_str(phymode));
1410 arg->peer_phymode = phymode;
1411 WARN_ON(phymode == MODE_UNKNOWN);
1414 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1415 struct ath10k_vif *arvif,
1416 struct ieee80211_sta *sta,
1417 struct ieee80211_bss_conf *bss_conf,
1418 struct wmi_peer_assoc_complete_arg *arg)
1420 lockdep_assert_held(&ar->conf_mutex);
1422 memset(arg, 0, sizeof(*arg));
1424 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1425 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1426 ath10k_peer_assoc_h_rates(ar, sta, arg);
1427 ath10k_peer_assoc_h_ht(ar, sta, arg);
1428 ath10k_peer_assoc_h_vht(ar, sta, arg);
1429 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1430 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
1435 static const u32 ath10k_smps_map[] = {
1436 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1437 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1438 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1439 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1442 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1444 const struct ieee80211_sta_ht_cap *ht_cap)
1448 if (!ht_cap->ht_supported)
1451 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1452 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1454 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1457 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1458 WMI_PEER_SMPS_STATE,
1459 ath10k_smps_map[smps]);
1462 /* can be called only in mac80211 callbacks due to `key_count` usage */
1463 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1464 struct ieee80211_vif *vif,
1465 struct ieee80211_bss_conf *bss_conf)
1467 struct ath10k *ar = hw->priv;
1468 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1469 struct ieee80211_sta_ht_cap ht_cap;
1470 struct wmi_peer_assoc_complete_arg peer_arg;
1471 struct ieee80211_sta *ap_sta;
1474 lockdep_assert_held(&ar->conf_mutex);
1478 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1480 ath10k_warn("failed to find station entry for bss %pM vdev %i\n",
1481 bss_conf->bssid, arvif->vdev_id);
1486 /* ap_sta must be accessed only within rcu section which must be left
1487 * before calling ath10k_setup_peer_smps() which might sleep. */
1488 ht_cap = ap_sta->ht_cap;
1490 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1491 bss_conf, &peer_arg);
1493 ath10k_warn("failed to prepare peer assoc for %pM vdev %i: %d\n",
1494 bss_conf->bssid, arvif->vdev_id, ret);
1501 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1503 ath10k_warn("failed to run peer assoc for %pM vdev %i: %d\n",
1504 bss_conf->bssid, arvif->vdev_id, ret);
1508 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1510 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1511 arvif->vdev_id, ret);
1515 ath10k_dbg(ATH10K_DBG_MAC,
1516 "mac vdev %d up (associated) bssid %pM aid %d\n",
1517 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1519 arvif->aid = bss_conf->aid;
1520 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1522 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1524 ath10k_warn("failed to set vdev %d up: %d\n",
1525 arvif->vdev_id, ret);
1529 arvif->is_up = true;
1535 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1536 struct ieee80211_vif *vif)
1538 struct ath10k *ar = hw->priv;
1539 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1542 lockdep_assert_held(&ar->conf_mutex);
1545 * For some reason, calling VDEV-DOWN before VDEV-STOP
1546 * makes the FW to send frames via HTT after disassociation.
1547 * No idea why this happens, even though VDEV-DOWN is supposed
1548 * to be analogous to link down, so just stop the VDEV.
1550 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1553 /* FIXME: check return value */
1554 ret = ath10k_vdev_stop(arvif);
1557 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1558 * report beacons from previously associated network through HTT.
1559 * This in turn would spam mac80211 WARN_ON if we bring down all
1560 * interfaces as it expects there is no rx when no interface is
1563 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1565 /* FIXME: why don't we print error if wmi call fails? */
1566 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1568 arvif->def_wep_key_idx = 0;
1570 arvif->is_started = false;
1571 arvif->is_up = false;
1574 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1575 struct ieee80211_sta *sta, bool reassoc)
1577 struct wmi_peer_assoc_complete_arg peer_arg;
1580 lockdep_assert_held(&ar->conf_mutex);
1582 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1584 ath10k_warn("failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1585 sta->addr, arvif->vdev_id, ret);
1589 peer_arg.peer_reassoc = reassoc;
1590 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1592 ath10k_warn("failed to run peer assoc for STA %pM vdev %i: %d\n",
1593 sta->addr, arvif->vdev_id, ret);
1597 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr, &sta->ht_cap);
1599 ath10k_warn("failed to setup peer SMPS for vdev %d: %d\n",
1600 arvif->vdev_id, ret);
1605 arvif->num_legacy_stations++;
1606 ret = ath10k_recalc_rtscts_prot(arvif);
1608 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1609 arvif->vdev_id, ret);
1614 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1616 ath10k_warn("failed to install peer wep keys for vdev %i: %d\n",
1617 arvif->vdev_id, ret);
1621 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1623 ath10k_warn("failed to set qos params for STA %pM for vdev %i: %d\n",
1624 sta->addr, arvif->vdev_id, ret);
1631 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1632 struct ieee80211_sta *sta)
1636 lockdep_assert_held(&ar->conf_mutex);
1639 arvif->num_legacy_stations--;
1640 ret = ath10k_recalc_rtscts_prot(arvif);
1642 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
1643 arvif->vdev_id, ret);
1648 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1650 ath10k_warn("failed to clear all peer wep keys for vdev %i: %d\n",
1651 arvif->vdev_id, ret);
1662 static int ath10k_update_channel_list(struct ath10k *ar)
1664 struct ieee80211_hw *hw = ar->hw;
1665 struct ieee80211_supported_band **bands;
1666 enum ieee80211_band band;
1667 struct ieee80211_channel *channel;
1668 struct wmi_scan_chan_list_arg arg = {0};
1669 struct wmi_channel_arg *ch;
1675 lockdep_assert_held(&ar->conf_mutex);
1677 bands = hw->wiphy->bands;
1678 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1682 for (i = 0; i < bands[band]->n_channels; i++) {
1683 if (bands[band]->channels[i].flags &
1684 IEEE80211_CHAN_DISABLED)
1691 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1692 arg.channels = kzalloc(len, GFP_KERNEL);
1697 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1701 for (i = 0; i < bands[band]->n_channels; i++) {
1702 channel = &bands[band]->channels[i];
1704 if (channel->flags & IEEE80211_CHAN_DISABLED)
1707 ch->allow_ht = true;
1709 /* FIXME: when should we really allow VHT? */
1710 ch->allow_vht = true;
1713 !(channel->flags & IEEE80211_CHAN_NO_IR);
1716 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1719 !!(channel->flags & IEEE80211_CHAN_RADAR);
1721 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1722 ch->passive = passive;
1724 ch->freq = channel->center_freq;
1726 ch->max_power = channel->max_power * 2;
1727 ch->max_reg_power = channel->max_reg_power * 2;
1728 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1729 ch->reg_class_id = 0; /* FIXME */
1731 /* FIXME: why use only legacy modes, why not any
1732 * HT/VHT modes? Would that even make any
1734 if (channel->band == IEEE80211_BAND_2GHZ)
1735 ch->mode = MODE_11G;
1737 ch->mode = MODE_11A;
1739 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1742 ath10k_dbg(ATH10K_DBG_WMI,
1743 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1744 ch - arg.channels, arg.n_channels,
1745 ch->freq, ch->max_power, ch->max_reg_power,
1746 ch->max_antenna_gain, ch->mode);
1752 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1753 kfree(arg.channels);
1758 static enum wmi_dfs_region
1759 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1761 switch (dfs_region) {
1762 case NL80211_DFS_UNSET:
1763 return WMI_UNINIT_DFS_DOMAIN;
1764 case NL80211_DFS_FCC:
1765 return WMI_FCC_DFS_DOMAIN;
1766 case NL80211_DFS_ETSI:
1767 return WMI_ETSI_DFS_DOMAIN;
1768 case NL80211_DFS_JP:
1769 return WMI_MKK4_DFS_DOMAIN;
1771 return WMI_UNINIT_DFS_DOMAIN;
1774 static void ath10k_regd_update(struct ath10k *ar)
1776 struct reg_dmn_pair_mapping *regpair;
1778 enum wmi_dfs_region wmi_dfs_reg;
1779 enum nl80211_dfs_regions nl_dfs_reg;
1781 lockdep_assert_held(&ar->conf_mutex);
1783 ret = ath10k_update_channel_list(ar);
1785 ath10k_warn("failed to update channel list: %d\n", ret);
1787 regpair = ar->ath_common.regulatory.regpair;
1789 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1790 nl_dfs_reg = ar->dfs_detector->region;
1791 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1793 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1796 /* Target allows setting up per-band regdomain but ath_common provides
1797 * a combined one only */
1798 ret = ath10k_wmi_pdev_set_regdomain(ar,
1799 regpair->reg_domain,
1800 regpair->reg_domain, /* 2ghz */
1801 regpair->reg_domain, /* 5ghz */
1802 regpair->reg_2ghz_ctl,
1803 regpair->reg_5ghz_ctl,
1806 ath10k_warn("failed to set pdev regdomain: %d\n", ret);
1809 static void ath10k_reg_notifier(struct wiphy *wiphy,
1810 struct regulatory_request *request)
1812 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1813 struct ath10k *ar = hw->priv;
1816 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1818 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1819 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1820 request->dfs_region);
1821 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1822 request->dfs_region);
1824 ath10k_warn("DFS region 0x%X not supported, will trigger radar for every pulse\n",
1825 request->dfs_region);
1828 mutex_lock(&ar->conf_mutex);
1829 if (ar->state == ATH10K_STATE_ON)
1830 ath10k_regd_update(ar);
1831 mutex_unlock(&ar->conf_mutex);
1838 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1840 if (ieee80211_is_mgmt(hdr->frame_control))
1841 return HTT_DATA_TX_EXT_TID_MGMT;
1843 if (!ieee80211_is_data_qos(hdr->frame_control))
1844 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1846 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1847 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1849 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1852 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1853 struct ieee80211_tx_info *info)
1855 if (info->control.vif)
1856 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1858 if (ar->monitor_started)
1859 return ar->monitor_vdev_id;
1861 ath10k_warn("failed to resolve vdev id\n");
1866 * Frames sent to the FW have to be in "Native Wifi" format.
1867 * Strip the QoS field from the 802.11 header.
1869 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1870 struct ieee80211_tx_control *control,
1871 struct sk_buff *skb)
1873 struct ieee80211_hdr *hdr = (void *)skb->data;
1876 if (!ieee80211_is_data_qos(hdr->frame_control))
1879 qos_ctl = ieee80211_get_qos_ctl(hdr);
1880 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1881 skb->data, (void *)qos_ctl - (void *)skb->data);
1882 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1885 static void ath10k_tx_wep_key_work(struct work_struct *work)
1887 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1889 int ret, keyidx = arvif->def_wep_key_newidx;
1891 if (arvif->def_wep_key_idx == keyidx)
1894 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1895 arvif->vdev_id, keyidx);
1897 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1899 arvif->ar->wmi.vdev_param->def_keyid,
1902 ath10k_warn("failed to update wep key index for vdev %d: %d\n",
1908 arvif->def_wep_key_idx = keyidx;
1911 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1913 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1914 struct ieee80211_vif *vif = info->control.vif;
1915 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1916 struct ath10k *ar = arvif->ar;
1917 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1918 struct ieee80211_key_conf *key = info->control.hw_key;
1920 if (!ieee80211_has_protected(hdr->frame_control))
1926 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1927 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1930 if (key->keyidx == arvif->def_wep_key_idx)
1933 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1934 * queueing frames until key index is updated is not an option because
1935 * sk_buff may need more processing to be done, e.g. offchannel */
1936 arvif->def_wep_key_newidx = key->keyidx;
1937 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1940 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1942 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1943 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1944 struct ieee80211_vif *vif = info->control.vif;
1945 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1947 /* This is case only for P2P_GO */
1948 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1949 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1952 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1953 spin_lock_bh(&ar->data_lock);
1954 if (arvif->u.ap.noa_data)
1955 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1957 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1958 arvif->u.ap.noa_data,
1959 arvif->u.ap.noa_len);
1960 spin_unlock_bh(&ar->data_lock);
1964 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1966 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1969 if (ar->htt.target_version_major >= 3) {
1970 /* Since HTT 3.0 there is no separate mgmt tx command */
1971 ret = ath10k_htt_tx(&ar->htt, skb);
1975 if (ieee80211_is_mgmt(hdr->frame_control)) {
1976 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1978 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1979 ATH10K_MAX_NUM_MGMT_PENDING) {
1980 ath10k_warn("reached WMI management tranmist queue limit\n");
1985 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1986 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1988 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1990 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1992 ieee80211_is_nullfunc(hdr->frame_control)) {
1993 /* FW does not report tx status properly for NullFunc frames
1994 * unless they are sent through mgmt tx path. mac80211 sends
1995 * those frames when it detects link/beacon loss and depends
1996 * on the tx status to be correct. */
1997 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1999 ret = ath10k_htt_tx(&ar->htt, skb);
2004 ath10k_warn("failed to transmit packet, dropping: %d\n", ret);
2005 ieee80211_free_txskb(ar->hw, skb);
2009 void ath10k_offchan_tx_purge(struct ath10k *ar)
2011 struct sk_buff *skb;
2014 skb = skb_dequeue(&ar->offchan_tx_queue);
2018 ieee80211_free_txskb(ar->hw, skb);
2022 void ath10k_offchan_tx_work(struct work_struct *work)
2024 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2025 struct ath10k_peer *peer;
2026 struct ieee80211_hdr *hdr;
2027 struct sk_buff *skb;
2028 const u8 *peer_addr;
2032 /* FW requirement: We must create a peer before FW will send out
2033 * an offchannel frame. Otherwise the frame will be stuck and
2034 * never transmitted. We delete the peer upon tx completion.
2035 * It is unlikely that a peer for offchannel tx will already be
2036 * present. However it may be in some rare cases so account for that.
2037 * Otherwise we might remove a legitimate peer and break stuff. */
2040 skb = skb_dequeue(&ar->offchan_tx_queue);
2044 mutex_lock(&ar->conf_mutex);
2046 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2049 hdr = (struct ieee80211_hdr *)skb->data;
2050 peer_addr = ieee80211_get_DA(hdr);
2051 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2053 spin_lock_bh(&ar->data_lock);
2054 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2055 spin_unlock_bh(&ar->data_lock);
2058 /* FIXME: should this use ath10k_warn()? */
2059 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2060 peer_addr, vdev_id);
2063 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2065 ath10k_warn("failed to create peer %pM on vdev %d: %d\n",
2066 peer_addr, vdev_id, ret);
2069 spin_lock_bh(&ar->data_lock);
2070 reinit_completion(&ar->offchan_tx_completed);
2071 ar->offchan_tx_skb = skb;
2072 spin_unlock_bh(&ar->data_lock);
2074 ath10k_tx_htt(ar, skb);
2076 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2079 ath10k_warn("timed out waiting for offchannel skb %p\n",
2083 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2085 ath10k_warn("failed to delete peer %pM on vdev %d: %d\n",
2086 peer_addr, vdev_id, ret);
2089 mutex_unlock(&ar->conf_mutex);
2093 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2095 struct sk_buff *skb;
2098 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2102 ieee80211_free_txskb(ar->hw, skb);
2106 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2108 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2109 struct sk_buff *skb;
2113 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2117 ret = ath10k_wmi_mgmt_tx(ar, skb);
2119 ath10k_warn("failed to transmit management frame via WMI: %d\n",
2121 ieee80211_free_txskb(ar->hw, skb);
2131 * This gets called if we dont get a heart-beat during scan.
2132 * This may indicate the FW has hung and we need to abort the
2133 * scan manually to prevent cancel_hw_scan() from deadlocking
2135 void ath10k_reset_scan(unsigned long ptr)
2137 struct ath10k *ar = (struct ath10k *)ptr;
2139 spin_lock_bh(&ar->data_lock);
2140 if (!ar->scan.in_progress) {
2141 spin_unlock_bh(&ar->data_lock);
2145 ath10k_warn("scan timed out, firmware problem?\n");
2147 if (ar->scan.is_roc)
2148 ieee80211_remain_on_channel_expired(ar->hw);
2150 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2152 ar->scan.in_progress = false;
2153 complete_all(&ar->scan.completed);
2154 spin_unlock_bh(&ar->data_lock);
2157 static int ath10k_abort_scan(struct ath10k *ar)
2159 struct wmi_stop_scan_arg arg = {
2160 .req_id = 1, /* FIXME */
2161 .req_type = WMI_SCAN_STOP_ONE,
2162 .u.scan_id = ATH10K_SCAN_ID,
2166 lockdep_assert_held(&ar->conf_mutex);
2168 del_timer_sync(&ar->scan.timeout);
2170 spin_lock_bh(&ar->data_lock);
2171 if (!ar->scan.in_progress) {
2172 spin_unlock_bh(&ar->data_lock);
2176 ar->scan.aborting = true;
2177 spin_unlock_bh(&ar->data_lock);
2179 ret = ath10k_wmi_stop_scan(ar, &arg);
2181 ath10k_warn("failed to stop wmi scan: %d\n", ret);
2182 spin_lock_bh(&ar->data_lock);
2183 ar->scan.in_progress = false;
2184 ath10k_offchan_tx_purge(ar);
2185 spin_unlock_bh(&ar->data_lock);
2189 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2191 ath10k_warn("timed out while waiting for scan to stop\n");
2193 /* scan completion may be done right after we timeout here, so let's
2194 * check the in_progress and tell mac80211 scan is completed. if we
2195 * don't do that and FW fails to send us scan completion indication
2196 * then userspace won't be able to scan anymore */
2199 spin_lock_bh(&ar->data_lock);
2200 if (ar->scan.in_progress) {
2201 ath10k_warn("failed to stop scan, it's still in progress\n");
2202 ar->scan.in_progress = false;
2203 ath10k_offchan_tx_purge(ar);
2206 spin_unlock_bh(&ar->data_lock);
2211 static int ath10k_start_scan(struct ath10k *ar,
2212 const struct wmi_start_scan_arg *arg)
2216 lockdep_assert_held(&ar->conf_mutex);
2218 ret = ath10k_wmi_start_scan(ar, arg);
2222 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2224 ath10k_abort_scan(ar);
2228 /* the scan can complete earlier, before we even
2229 * start the timer. in that case the timer handler
2230 * checks ar->scan.in_progress and bails out if its
2231 * false. Add a 200ms margin to account event/command
2233 mod_timer(&ar->scan.timeout, jiffies +
2234 msecs_to_jiffies(arg->max_scan_time+200));
2238 /**********************/
2239 /* mac80211 callbacks */
2240 /**********************/
2242 static void ath10k_tx(struct ieee80211_hw *hw,
2243 struct ieee80211_tx_control *control,
2244 struct sk_buff *skb)
2246 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2247 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2248 struct ath10k *ar = hw->priv;
2251 /* We should disable CCK RATE due to P2P */
2252 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2253 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2255 /* we must calculate tid before we apply qos workaround
2256 * as we'd lose the qos control field */
2257 tid = ath10k_tx_h_get_tid(hdr);
2258 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
2260 /* it makes no sense to process injected frames like that */
2261 if (info->control.vif &&
2262 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2263 ath10k_tx_h_qos_workaround(hw, control, skb);
2264 ath10k_tx_h_update_wep_key(skb);
2265 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2266 ath10k_tx_h_seq_no(skb);
2269 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
2270 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2271 ATH10K_SKB_CB(skb)->htt.tid = tid;
2273 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2274 spin_lock_bh(&ar->data_lock);
2275 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2276 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2277 spin_unlock_bh(&ar->data_lock);
2279 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2281 skb_queue_tail(&ar->offchan_tx_queue, skb);
2282 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2286 ath10k_tx_htt(ar, skb);
2290 * Initialize various parameters with default vaules.
2292 void ath10k_halt(struct ath10k *ar)
2294 struct ath10k_vif *arvif;
2296 lockdep_assert_held(&ar->conf_mutex);
2298 if (ath10k_monitor_is_enabled(ar)) {
2299 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2300 ar->promisc = false;
2301 ar->monitor = false;
2302 ath10k_monitor_stop(ar);
2305 del_timer_sync(&ar->scan.timeout);
2306 ath10k_offchan_tx_purge(ar);
2307 ath10k_mgmt_over_wmi_tx_purge(ar);
2308 ath10k_peer_cleanup_all(ar);
2309 ath10k_core_stop(ar);
2310 ath10k_hif_power_down(ar);
2312 spin_lock_bh(&ar->data_lock);
2313 if (ar->scan.in_progress) {
2314 del_timer(&ar->scan.timeout);
2315 ar->scan.in_progress = false;
2316 ieee80211_scan_completed(ar->hw, true);
2319 list_for_each_entry(arvif, &ar->arvifs, list) {
2323 dma_unmap_single(arvif->ar->dev,
2324 ATH10K_SKB_CB(arvif->beacon)->paddr,
2325 arvif->beacon->len, DMA_TO_DEVICE);
2326 dev_kfree_skb_any(arvif->beacon);
2327 arvif->beacon = NULL;
2329 spin_unlock_bh(&ar->data_lock);
2332 static int ath10k_start(struct ieee80211_hw *hw)
2334 struct ath10k *ar = hw->priv;
2337 mutex_lock(&ar->conf_mutex);
2339 if (ar->state != ATH10K_STATE_OFF &&
2340 ar->state != ATH10K_STATE_RESTARTING) {
2345 ret = ath10k_hif_power_up(ar);
2347 ath10k_err("Could not init hif: %d\n", ret);
2348 ar->state = ATH10K_STATE_OFF;
2352 ret = ath10k_core_start(ar);
2354 ath10k_err("Could not init core: %d\n", ret);
2355 ath10k_hif_power_down(ar);
2356 ar->state = ATH10K_STATE_OFF;
2360 if (ar->state == ATH10K_STATE_OFF)
2361 ar->state = ATH10K_STATE_ON;
2362 else if (ar->state == ATH10K_STATE_RESTARTING)
2363 ar->state = ATH10K_STATE_RESTARTED;
2365 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2367 ath10k_warn("failed to enable PMF QOS: %d\n", ret);
2369 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2371 ath10k_warn("failed to enable dynamic BW: %d\n", ret);
2374 * By default FW set ARP frames ac to voice (6). In that case ARP
2375 * exchange is not working properly for UAPSD enabled AP. ARP requests
2376 * which arrives with access category 0 are processed by network stack
2377 * and send back with access category 0, but FW changes access category
2378 * to 6. Set ARP frames access category to best effort (0) solves
2382 ret = ath10k_wmi_pdev_set_param(ar,
2383 ar->wmi.pdev_param->arp_ac_override, 0);
2385 ath10k_warn("failed to set arp ac override parameter: %d\n",
2390 ar->num_started_vdevs = 0;
2391 ath10k_regd_update(ar);
2395 mutex_unlock(&ar->conf_mutex);
2399 static void ath10k_stop(struct ieee80211_hw *hw)
2401 struct ath10k *ar = hw->priv;
2403 mutex_lock(&ar->conf_mutex);
2404 if (ar->state == ATH10K_STATE_ON ||
2405 ar->state == ATH10K_STATE_RESTARTED ||
2406 ar->state == ATH10K_STATE_WEDGED)
2409 ar->state = ATH10K_STATE_OFF;
2410 mutex_unlock(&ar->conf_mutex);
2412 ath10k_mgmt_over_wmi_tx_purge(ar);
2414 cancel_work_sync(&ar->offchan_tx_work);
2415 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2416 cancel_work_sync(&ar->restart_work);
2419 static int ath10k_config_ps(struct ath10k *ar)
2421 struct ath10k_vif *arvif;
2424 lockdep_assert_held(&ar->conf_mutex);
2426 list_for_each_entry(arvif, &ar->arvifs, list) {
2427 ret = ath10k_mac_vif_setup_ps(arvif);
2429 ath10k_warn("failed to setup powersave: %d\n", ret);
2437 static const char *chandef_get_width(enum nl80211_chan_width width)
2440 case NL80211_CHAN_WIDTH_20_NOHT:
2442 case NL80211_CHAN_WIDTH_20:
2444 case NL80211_CHAN_WIDTH_40:
2446 case NL80211_CHAN_WIDTH_80:
2448 case NL80211_CHAN_WIDTH_80P80:
2450 case NL80211_CHAN_WIDTH_160:
2452 case NL80211_CHAN_WIDTH_5:
2454 case NL80211_CHAN_WIDTH_10:
2460 static void ath10k_config_chan(struct ath10k *ar)
2462 struct ath10k_vif *arvif;
2465 lockdep_assert_held(&ar->conf_mutex);
2467 ath10k_dbg(ATH10K_DBG_MAC,
2468 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2469 ar->chandef.chan->center_freq,
2470 ar->chandef.center_freq1,
2471 ar->chandef.center_freq2,
2472 chandef_get_width(ar->chandef.width));
2474 /* First stop monitor interface. Some FW versions crash if there's a
2475 * lone monitor interface. */
2476 if (ar->monitor_started)
2477 ath10k_monitor_vdev_stop(ar);
2479 list_for_each_entry(arvif, &ar->arvifs, list) {
2480 if (!arvif->is_started)
2483 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2486 ret = ath10k_vdev_stop(arvif);
2488 ath10k_warn("failed to stop vdev %d: %d\n",
2489 arvif->vdev_id, ret);
2494 /* all vdevs are now stopped - now attempt to restart them */
2496 list_for_each_entry(arvif, &ar->arvifs, list) {
2497 if (!arvif->is_started)
2500 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2503 ret = ath10k_vdev_start(arvif);
2505 ath10k_warn("failed to start vdev %d: %d\n",
2506 arvif->vdev_id, ret);
2513 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2516 ath10k_warn("failed to bring vdev up %d: %d\n",
2517 arvif->vdev_id, ret);
2522 if (ath10k_monitor_is_enabled(ar))
2523 ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
2526 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2528 struct ath10k *ar = hw->priv;
2529 struct ieee80211_conf *conf = &hw->conf;
2533 mutex_lock(&ar->conf_mutex);
2535 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2536 ath10k_dbg(ATH10K_DBG_MAC,
2537 "mac config channel %dMHz flags 0x%x radar %d\n",
2538 conf->chandef.chan->center_freq,
2539 conf->chandef.chan->flags,
2540 conf->radar_enabled);
2542 spin_lock_bh(&ar->data_lock);
2543 ar->rx_channel = conf->chandef.chan;
2544 spin_unlock_bh(&ar->data_lock);
2546 ar->radar_enabled = conf->radar_enabled;
2547 ath10k_recalc_radar_detection(ar);
2549 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2550 ar->chandef = conf->chandef;
2551 ath10k_config_chan(ar);
2555 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2556 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2557 hw->conf.power_level);
2559 param = ar->wmi.pdev_param->txpower_limit2g;
2560 ret = ath10k_wmi_pdev_set_param(ar, param,
2561 hw->conf.power_level * 2);
2563 ath10k_warn("failed to set 2g txpower %d: %d\n",
2564 hw->conf.power_level, ret);
2566 param = ar->wmi.pdev_param->txpower_limit5g;
2567 ret = ath10k_wmi_pdev_set_param(ar, param,
2568 hw->conf.power_level * 2);
2570 ath10k_warn("failed to set 5g txpower %d: %d\n",
2571 hw->conf.power_level, ret);
2574 if (changed & IEEE80211_CONF_CHANGE_PS)
2575 ath10k_config_ps(ar);
2577 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2578 if (conf->flags & IEEE80211_CONF_MONITOR && !ar->monitor) {
2580 ret = ath10k_monitor_start(ar);
2582 ath10k_warn("failed to start monitor (config): %d\n",
2584 ar->monitor = false;
2586 } else if (!(conf->flags & IEEE80211_CONF_MONITOR) &&
2588 ar->monitor = false;
2589 ath10k_monitor_stop(ar);
2593 mutex_unlock(&ar->conf_mutex);
2599 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2600 * because we will send mgmt frames without CCK. This requirement
2601 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2604 static int ath10k_add_interface(struct ieee80211_hw *hw,
2605 struct ieee80211_vif *vif)
2607 struct ath10k *ar = hw->priv;
2608 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2609 enum wmi_sta_powersave_param param;
2615 mutex_lock(&ar->conf_mutex);
2617 memset(arvif, 0, sizeof(*arvif));
2622 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2623 INIT_LIST_HEAD(&arvif->list);
2625 bit = ffs(ar->free_vdev_map);
2631 arvif->vdev_id = bit - 1;
2632 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2635 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2637 switch (vif->type) {
2638 case NL80211_IFTYPE_UNSPECIFIED:
2639 case NL80211_IFTYPE_STATION:
2640 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2642 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2644 case NL80211_IFTYPE_ADHOC:
2645 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2647 case NL80211_IFTYPE_AP:
2648 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2651 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2653 case NL80211_IFTYPE_MONITOR:
2654 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2661 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
2662 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2664 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2665 arvif->vdev_subtype, vif->addr);
2667 ath10k_warn("failed to create WMI vdev %i: %d\n",
2668 arvif->vdev_id, ret);
2672 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2673 list_add(&arvif->list, &ar->arvifs);
2675 vdev_param = ar->wmi.vdev_param->def_keyid;
2676 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2677 arvif->def_wep_key_idx);
2679 ath10k_warn("failed to set vdev %i default key id: %d\n",
2680 arvif->vdev_id, ret);
2681 goto err_vdev_delete;
2684 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2685 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2686 ATH10K_HW_TXRX_NATIVE_WIFI);
2687 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2688 if (ret && ret != -EOPNOTSUPP) {
2689 ath10k_warn("failed to set vdev %i TX encapsulation: %d\n",
2690 arvif->vdev_id, ret);
2691 goto err_vdev_delete;
2694 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2695 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2697 ath10k_warn("failed to create vdev %i peer for AP: %d\n",
2698 arvif->vdev_id, ret);
2699 goto err_vdev_delete;
2702 ret = ath10k_mac_set_kickout(arvif);
2704 ath10k_warn("failed to set vdev %i kickout parameters: %d\n",
2705 arvif->vdev_id, ret);
2706 goto err_peer_delete;
2710 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2711 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2712 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2713 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2716 ath10k_warn("failed to set vdev %i RX wake policy: %d\n",
2717 arvif->vdev_id, ret);
2718 goto err_peer_delete;
2721 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2722 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2723 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2726 ath10k_warn("failed to set vdev %i TX wake thresh: %d\n",
2727 arvif->vdev_id, ret);
2728 goto err_peer_delete;
2731 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2732 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2733 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2736 ath10k_warn("failed to set vdev %i PSPOLL count: %d\n",
2737 arvif->vdev_id, ret);
2738 goto err_peer_delete;
2742 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2744 ath10k_warn("failed to set rts threshold for vdev %d: %d\n",
2745 arvif->vdev_id, ret);
2746 goto err_peer_delete;
2749 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2751 ath10k_warn("failed to set frag threshold for vdev %d: %d\n",
2752 arvif->vdev_id, ret);
2753 goto err_peer_delete;
2756 mutex_unlock(&ar->conf_mutex);
2760 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2761 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2764 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2765 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2766 list_del(&arvif->list);
2769 mutex_unlock(&ar->conf_mutex);
2774 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2775 struct ieee80211_vif *vif)
2777 struct ath10k *ar = hw->priv;
2778 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2781 mutex_lock(&ar->conf_mutex);
2783 cancel_work_sync(&arvif->wep_key_work);
2785 spin_lock_bh(&ar->data_lock);
2786 if (arvif->beacon) {
2787 dma_unmap_single(arvif->ar->dev,
2788 ATH10K_SKB_CB(arvif->beacon)->paddr,
2789 arvif->beacon->len, DMA_TO_DEVICE);
2790 dev_kfree_skb_any(arvif->beacon);
2791 arvif->beacon = NULL;
2793 spin_unlock_bh(&ar->data_lock);
2795 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2796 list_del(&arvif->list);
2798 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2799 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2801 ath10k_warn("failed to remove peer for AP vdev %i: %d\n",
2802 arvif->vdev_id, ret);
2804 kfree(arvif->u.ap.noa_data);
2807 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
2810 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2812 ath10k_warn("failed to delete WMI vdev %i: %d\n",
2813 arvif->vdev_id, ret);
2815 ath10k_peer_cleanup(ar, arvif->vdev_id);
2817 mutex_unlock(&ar->conf_mutex);
2821 * FIXME: Has to be verified.
2823 #define SUPPORTED_FILTERS \
2824 (FIF_PROMISC_IN_BSS | \
2829 FIF_BCN_PRBRESP_PROMISC | \
2833 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2834 unsigned int changed_flags,
2835 unsigned int *total_flags,
2838 struct ath10k *ar = hw->priv;
2841 mutex_lock(&ar->conf_mutex);
2843 changed_flags &= SUPPORTED_FILTERS;
2844 *total_flags &= SUPPORTED_FILTERS;
2845 ar->filter_flags = *total_flags;
2847 if (ar->filter_flags & FIF_PROMISC_IN_BSS && !ar->promisc) {
2849 ret = ath10k_monitor_start(ar);
2851 ath10k_warn("failed to start monitor (promisc): %d\n",
2853 ar->promisc = false;
2855 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) && ar->promisc) {
2856 ar->promisc = false;
2857 ath10k_monitor_stop(ar);
2860 mutex_unlock(&ar->conf_mutex);
2863 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2864 struct ieee80211_vif *vif,
2865 struct ieee80211_bss_conf *info,
2868 struct ath10k *ar = hw->priv;
2869 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2871 u32 vdev_param, pdev_param;
2873 mutex_lock(&ar->conf_mutex);
2875 if (changed & BSS_CHANGED_IBSS)
2876 ath10k_control_ibss(arvif, info, vif->addr);
2878 if (changed & BSS_CHANGED_BEACON_INT) {
2879 arvif->beacon_interval = info->beacon_int;
2880 vdev_param = ar->wmi.vdev_param->beacon_interval;
2881 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2882 arvif->beacon_interval);
2883 ath10k_dbg(ATH10K_DBG_MAC,
2884 "mac vdev %d beacon_interval %d\n",
2885 arvif->vdev_id, arvif->beacon_interval);
2888 ath10k_warn("failed to set beacon interval for vdev %d: %i\n",
2889 arvif->vdev_id, ret);
2892 if (changed & BSS_CHANGED_BEACON) {
2893 ath10k_dbg(ATH10K_DBG_MAC,
2894 "vdev %d set beacon tx mode to staggered\n",
2897 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2898 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
2899 WMI_BEACON_STAGGERED_MODE);
2901 ath10k_warn("failed to set beacon mode for vdev %d: %i\n",
2902 arvif->vdev_id, ret);
2905 if (changed & BSS_CHANGED_BEACON_INFO) {
2906 arvif->dtim_period = info->dtim_period;
2908 ath10k_dbg(ATH10K_DBG_MAC,
2909 "mac vdev %d dtim_period %d\n",
2910 arvif->vdev_id, arvif->dtim_period);
2912 vdev_param = ar->wmi.vdev_param->dtim_period;
2913 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2914 arvif->dtim_period);
2916 ath10k_warn("failed to set dtim period for vdev %d: %i\n",
2917 arvif->vdev_id, ret);
2920 if (changed & BSS_CHANGED_SSID &&
2921 vif->type == NL80211_IFTYPE_AP) {
2922 arvif->u.ap.ssid_len = info->ssid_len;
2924 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2925 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2928 if (changed & BSS_CHANGED_BSSID) {
2929 if (!is_zero_ether_addr(info->bssid)) {
2930 ath10k_dbg(ATH10K_DBG_MAC,
2931 "mac vdev %d create peer %pM\n",
2932 arvif->vdev_id, info->bssid);
2934 ret = ath10k_peer_create(ar, arvif->vdev_id,
2937 ath10k_warn("failed to add peer %pM for vdev %d when changing bssid: %i\n",
2938 info->bssid, arvif->vdev_id, ret);
2940 if (vif->type == NL80211_IFTYPE_STATION) {
2942 * this is never erased as we it for crypto key
2943 * clearing; this is FW requirement
2945 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
2947 ath10k_dbg(ATH10K_DBG_MAC,
2948 "mac vdev %d start %pM\n",
2949 arvif->vdev_id, info->bssid);
2951 ret = ath10k_vdev_start(arvif);
2953 ath10k_warn("failed to start vdev %i: %d\n",
2954 arvif->vdev_id, ret);
2958 arvif->is_started = true;
2962 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2963 * so driver need to store it. It is needed when leaving
2964 * IBSS in order to remove BSSID peer.
2966 if (vif->type == NL80211_IFTYPE_ADHOC)
2967 memcpy(arvif->bssid, info->bssid,
2972 if (changed & BSS_CHANGED_BEACON_ENABLED)
2973 ath10k_control_beaconing(arvif, info);
2975 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2976 arvif->use_cts_prot = info->use_cts_prot;
2977 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2978 arvif->vdev_id, info->use_cts_prot);
2980 ret = ath10k_recalc_rtscts_prot(arvif);
2982 ath10k_warn("failed to recalculate rts/cts prot for vdev %d: %d\n",
2983 arvif->vdev_id, ret);
2986 if (changed & BSS_CHANGED_ERP_SLOT) {
2988 if (info->use_short_slot)
2989 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2992 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2994 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2995 arvif->vdev_id, slottime);
2997 vdev_param = ar->wmi.vdev_param->slot_time;
2998 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3001 ath10k_warn("failed to set erp slot for vdev %d: %i\n",
3002 arvif->vdev_id, ret);
3005 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3007 if (info->use_short_preamble)
3008 preamble = WMI_VDEV_PREAMBLE_SHORT;
3010 preamble = WMI_VDEV_PREAMBLE_LONG;
3012 ath10k_dbg(ATH10K_DBG_MAC,
3013 "mac vdev %d preamble %dn",
3014 arvif->vdev_id, preamble);
3016 vdev_param = ar->wmi.vdev_param->preamble;
3017 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3020 ath10k_warn("failed to set preamble for vdev %d: %i\n",
3021 arvif->vdev_id, ret);
3024 if (changed & BSS_CHANGED_ASSOC) {
3026 ath10k_bss_assoc(hw, vif, info);
3030 mutex_unlock(&ar->conf_mutex);
3033 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3034 struct ieee80211_vif *vif,
3035 struct cfg80211_scan_request *req)
3037 struct ath10k *ar = hw->priv;
3038 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3039 struct wmi_start_scan_arg arg;
3043 mutex_lock(&ar->conf_mutex);
3045 spin_lock_bh(&ar->data_lock);
3046 if (ar->scan.in_progress) {
3047 spin_unlock_bh(&ar->data_lock);
3052 reinit_completion(&ar->scan.started);
3053 reinit_completion(&ar->scan.completed);
3054 ar->scan.in_progress = true;
3055 ar->scan.aborting = false;
3056 ar->scan.is_roc = false;
3057 ar->scan.vdev_id = arvif->vdev_id;
3058 spin_unlock_bh(&ar->data_lock);
3060 memset(&arg, 0, sizeof(arg));
3061 ath10k_wmi_start_scan_init(ar, &arg);
3062 arg.vdev_id = arvif->vdev_id;
3063 arg.scan_id = ATH10K_SCAN_ID;
3066 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3069 arg.ie_len = req->ie_len;
3070 memcpy(arg.ie, req->ie, arg.ie_len);
3074 arg.n_ssids = req->n_ssids;
3075 for (i = 0; i < arg.n_ssids; i++) {
3076 arg.ssids[i].len = req->ssids[i].ssid_len;
3077 arg.ssids[i].ssid = req->ssids[i].ssid;
3080 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3083 if (req->n_channels) {
3084 arg.n_channels = req->n_channels;
3085 for (i = 0; i < arg.n_channels; i++)
3086 arg.channels[i] = req->channels[i]->center_freq;
3089 ret = ath10k_start_scan(ar, &arg);
3091 ath10k_warn("failed to start hw scan: %d\n", ret);
3092 spin_lock_bh(&ar->data_lock);
3093 ar->scan.in_progress = false;
3094 spin_unlock_bh(&ar->data_lock);
3098 mutex_unlock(&ar->conf_mutex);
3102 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3103 struct ieee80211_vif *vif)
3105 struct ath10k *ar = hw->priv;
3108 mutex_lock(&ar->conf_mutex);
3109 ret = ath10k_abort_scan(ar);
3111 ath10k_warn("failed to abort scan: %d\n", ret);
3112 ieee80211_scan_completed(hw, 1 /* aborted */);
3114 mutex_unlock(&ar->conf_mutex);
3117 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3118 struct ath10k_vif *arvif,
3119 enum set_key_cmd cmd,
3120 struct ieee80211_key_conf *key)
3122 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3125 /* 10.1 firmware branch requires default key index to be set to group
3126 * key index after installing it. Otherwise FW/HW Txes corrupted
3127 * frames with multi-vif APs. This is not required for main firmware
3128 * branch (e.g. 636).
3130 * FIXME: This has been tested only in AP. It remains unknown if this
3131 * is required for multi-vif STA interfaces on 10.1 */
3133 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3136 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3139 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3142 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3148 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3151 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3152 arvif->vdev_id, ret);
3155 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3156 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3157 struct ieee80211_key_conf *key)
3159 struct ath10k *ar = hw->priv;
3160 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3161 struct ath10k_peer *peer;
3162 const u8 *peer_addr;
3163 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3164 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3167 if (key->keyidx > WMI_MAX_KEY_INDEX)
3170 mutex_lock(&ar->conf_mutex);
3173 peer_addr = sta->addr;
3174 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3175 peer_addr = vif->bss_conf.bssid;
3177 peer_addr = vif->addr;
3179 key->hw_key_idx = key->keyidx;
3181 /* the peer should not disappear in mid-way (unless FW goes awry) since
3182 * we already hold conf_mutex. we just make sure its there now. */
3183 spin_lock_bh(&ar->data_lock);
3184 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3185 spin_unlock_bh(&ar->data_lock);
3188 if (cmd == SET_KEY) {
3189 ath10k_warn("failed to install key for non-existent peer %pM\n",
3194 /* if the peer doesn't exist there is no key to disable
3202 arvif->wep_keys[key->keyidx] = key;
3204 arvif->wep_keys[key->keyidx] = NULL;
3206 if (cmd == DISABLE_KEY)
3207 ath10k_clear_vdev_key(arvif, key);
3210 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3212 ath10k_warn("failed to install key for vdev %i peer %pM: %d\n",
3213 arvif->vdev_id, peer_addr, ret);
3217 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3219 spin_lock_bh(&ar->data_lock);
3220 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3221 if (peer && cmd == SET_KEY)
3222 peer->keys[key->keyidx] = key;
3223 else if (peer && cmd == DISABLE_KEY)
3224 peer->keys[key->keyidx] = NULL;
3225 else if (peer == NULL)
3226 /* impossible unless FW goes crazy */
3227 ath10k_warn("Peer %pM disappeared!\n", peer_addr);
3228 spin_unlock_bh(&ar->data_lock);
3231 mutex_unlock(&ar->conf_mutex);
3235 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3238 struct ath10k_vif *arvif;
3239 struct ath10k_sta *arsta;
3240 struct ieee80211_sta *sta;
3241 u32 changed, bw, nss, smps;
3244 arsta = container_of(wk, struct ath10k_sta, update_wk);
3245 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3246 arvif = arsta->arvif;
3249 spin_lock_bh(&ar->data_lock);
3251 changed = arsta->changed;
3258 spin_unlock_bh(&ar->data_lock);
3260 mutex_lock(&ar->conf_mutex);
3262 if (changed & IEEE80211_RC_BW_CHANGED) {
3263 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3266 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3267 WMI_PEER_CHAN_WIDTH, bw);
3269 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3270 sta->addr, bw, err);
3273 if (changed & IEEE80211_RC_NSS_CHANGED) {
3274 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3277 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3280 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3281 sta->addr, nss, err);
3284 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3285 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3288 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3289 WMI_PEER_SMPS_STATE, smps);
3291 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3292 sta->addr, smps, err);
3295 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3296 ath10k_dbg(ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3299 err = ath10k_station_assoc(ar, arvif, sta, true);
3301 ath10k_warn("failed to reassociate station: %pM\n",
3305 mutex_unlock(&ar->conf_mutex);
3308 static int ath10k_sta_state(struct ieee80211_hw *hw,
3309 struct ieee80211_vif *vif,
3310 struct ieee80211_sta *sta,
3311 enum ieee80211_sta_state old_state,
3312 enum ieee80211_sta_state new_state)
3314 struct ath10k *ar = hw->priv;
3315 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3316 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3320 if (old_state == IEEE80211_STA_NOTEXIST &&
3321 new_state == IEEE80211_STA_NONE) {
3322 memset(arsta, 0, sizeof(*arsta));
3323 arsta->arvif = arvif;
3324 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3327 /* cancel must be done outside the mutex to avoid deadlock */
3328 if ((old_state == IEEE80211_STA_NONE &&
3329 new_state == IEEE80211_STA_NOTEXIST))
3330 cancel_work_sync(&arsta->update_wk);
3332 mutex_lock(&ar->conf_mutex);
3334 if (old_state == IEEE80211_STA_NOTEXIST &&
3335 new_state == IEEE80211_STA_NONE &&
3336 vif->type != NL80211_IFTYPE_STATION) {
3338 * New station addition.
3340 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3341 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3343 max_num_peers = TARGET_NUM_PEERS;
3345 if (ar->num_peers >= max_num_peers) {
3346 ath10k_warn("number of peers exceeded: peers number %d (max peers %d)\n",
3347 ar->num_peers, max_num_peers);
3352 ath10k_dbg(ATH10K_DBG_MAC,
3353 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3354 arvif->vdev_id, sta->addr, ar->num_peers);
3356 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3358 ath10k_warn("failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3359 sta->addr, arvif->vdev_id, ret);
3360 } else if ((old_state == IEEE80211_STA_NONE &&
3361 new_state == IEEE80211_STA_NOTEXIST)) {
3363 * Existing station deletion.
3365 ath10k_dbg(ATH10K_DBG_MAC,
3366 "mac vdev %d peer delete %pM (sta gone)\n",
3367 arvif->vdev_id, sta->addr);
3368 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3370 ath10k_warn("failed to delete peer %pM for vdev %d: %i\n",
3371 sta->addr, arvif->vdev_id, ret);
3373 if (vif->type == NL80211_IFTYPE_STATION)
3374 ath10k_bss_disassoc(hw, vif);
3375 } else if (old_state == IEEE80211_STA_AUTH &&
3376 new_state == IEEE80211_STA_ASSOC &&
3377 (vif->type == NL80211_IFTYPE_AP ||
3378 vif->type == NL80211_IFTYPE_ADHOC)) {
3382 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3385 ret = ath10k_station_assoc(ar, arvif, sta, false);
3387 ath10k_warn("failed to associate station %pM for vdev %i: %i\n",
3388 sta->addr, arvif->vdev_id, ret);
3389 } else if (old_state == IEEE80211_STA_ASSOC &&
3390 new_state == IEEE80211_STA_AUTH &&
3391 (vif->type == NL80211_IFTYPE_AP ||
3392 vif->type == NL80211_IFTYPE_ADHOC)) {
3396 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3399 ret = ath10k_station_disassoc(ar, arvif, sta);
3401 ath10k_warn("failed to disassociate station: %pM vdev %i: %i\n",
3402 sta->addr, arvif->vdev_id, ret);
3405 mutex_unlock(&ar->conf_mutex);
3409 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3410 u16 ac, bool enable)
3412 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3416 lockdep_assert_held(&ar->conf_mutex);
3418 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3422 case IEEE80211_AC_VO:
3423 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3424 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3426 case IEEE80211_AC_VI:
3427 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3428 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3430 case IEEE80211_AC_BE:
3431 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3432 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3434 case IEEE80211_AC_BK:
3435 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3436 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3441 arvif->u.sta.uapsd |= value;
3443 arvif->u.sta.uapsd &= ~value;
3445 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3446 WMI_STA_PS_PARAM_UAPSD,
3447 arvif->u.sta.uapsd);
3449 ath10k_warn("failed to set uapsd params: %d\n", ret);
3453 if (arvif->u.sta.uapsd)
3454 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3456 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3458 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3459 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3462 ath10k_warn("failed to set rx wake param: %d\n", ret);
3468 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3469 struct ieee80211_vif *vif, u16 ac,
3470 const struct ieee80211_tx_queue_params *params)
3472 struct ath10k *ar = hw->priv;
3473 struct wmi_wmm_params_arg *p = NULL;
3476 mutex_lock(&ar->conf_mutex);
3479 case IEEE80211_AC_VO:
3480 p = &ar->wmm_params.ac_vo;
3482 case IEEE80211_AC_VI:
3483 p = &ar->wmm_params.ac_vi;
3485 case IEEE80211_AC_BE:
3486 p = &ar->wmm_params.ac_be;
3488 case IEEE80211_AC_BK:
3489 p = &ar->wmm_params.ac_bk;
3498 p->cwmin = params->cw_min;
3499 p->cwmax = params->cw_max;
3500 p->aifs = params->aifs;
3503 * The channel time duration programmed in the HW is in absolute
3504 * microseconds, while mac80211 gives the txop in units of
3507 p->txop = params->txop * 32;
3509 /* FIXME: FW accepts wmm params per hw, not per vif */
3510 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3512 ath10k_warn("failed to set wmm params: %d\n", ret);
3516 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3518 ath10k_warn("failed to set sta uapsd: %d\n", ret);
3521 mutex_unlock(&ar->conf_mutex);
3525 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3527 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3528 struct ieee80211_vif *vif,
3529 struct ieee80211_channel *chan,
3531 enum ieee80211_roc_type type)
3533 struct ath10k *ar = hw->priv;
3534 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3535 struct wmi_start_scan_arg arg;
3538 mutex_lock(&ar->conf_mutex);
3540 spin_lock_bh(&ar->data_lock);
3541 if (ar->scan.in_progress) {
3542 spin_unlock_bh(&ar->data_lock);
3547 reinit_completion(&ar->scan.started);
3548 reinit_completion(&ar->scan.completed);
3549 reinit_completion(&ar->scan.on_channel);
3550 ar->scan.in_progress = true;
3551 ar->scan.aborting = false;
3552 ar->scan.is_roc = true;
3553 ar->scan.vdev_id = arvif->vdev_id;
3554 ar->scan.roc_freq = chan->center_freq;
3555 spin_unlock_bh(&ar->data_lock);
3557 memset(&arg, 0, sizeof(arg));
3558 ath10k_wmi_start_scan_init(ar, &arg);
3559 arg.vdev_id = arvif->vdev_id;
3560 arg.scan_id = ATH10K_SCAN_ID;
3562 arg.channels[0] = chan->center_freq;
3563 arg.dwell_time_active = duration;
3564 arg.dwell_time_passive = duration;
3565 arg.max_scan_time = 2 * duration;
3566 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3567 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3569 ret = ath10k_start_scan(ar, &arg);
3571 ath10k_warn("failed to start roc scan: %d\n", ret);
3572 spin_lock_bh(&ar->data_lock);
3573 ar->scan.in_progress = false;
3574 spin_unlock_bh(&ar->data_lock);
3578 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3580 ath10k_warn("failed to switch to channel for roc scan\n");
3581 ath10k_abort_scan(ar);
3588 mutex_unlock(&ar->conf_mutex);
3592 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3594 struct ath10k *ar = hw->priv;
3596 mutex_lock(&ar->conf_mutex);
3597 ath10k_abort_scan(ar);
3598 mutex_unlock(&ar->conf_mutex);
3604 * Both RTS and Fragmentation threshold are interface-specific
3605 * in ath10k, but device-specific in mac80211.
3608 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3610 struct ath10k *ar = hw->priv;
3611 struct ath10k_vif *arvif;
3614 mutex_lock(&ar->conf_mutex);
3615 list_for_each_entry(arvif, &ar->arvifs, list) {
3616 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3617 arvif->vdev_id, value);
3619 ret = ath10k_mac_set_rts(arvif, value);
3621 ath10k_warn("failed to set rts threshold for vdev %d: %d\n",
3622 arvif->vdev_id, ret);
3626 mutex_unlock(&ar->conf_mutex);
3631 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3633 struct ath10k *ar = hw->priv;
3634 struct ath10k_vif *arvif;
3637 mutex_lock(&ar->conf_mutex);
3638 list_for_each_entry(arvif, &ar->arvifs, list) {
3639 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3640 arvif->vdev_id, value);
3642 ret = ath10k_mac_set_rts(arvif, value);
3644 ath10k_warn("failed to set fragmentation threshold for vdev %d: %d\n",
3645 arvif->vdev_id, ret);
3649 mutex_unlock(&ar->conf_mutex);
3654 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3655 u32 queues, bool drop)
3657 struct ath10k *ar = hw->priv;
3661 /* mac80211 doesn't care if we really xmit queued frames or not
3662 * we'll collect those frames either way if we stop/delete vdevs */
3666 mutex_lock(&ar->conf_mutex);
3668 if (ar->state == ATH10K_STATE_WEDGED)
3671 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3674 spin_lock_bh(&ar->htt.tx_lock);
3675 empty = (ar->htt.num_pending_tx == 0);
3676 spin_unlock_bh(&ar->htt.tx_lock);
3678 skip = (ar->state == ATH10K_STATE_WEDGED);
3681 }), ATH10K_FLUSH_TIMEOUT_HZ);
3683 if (ret <= 0 || skip)
3684 ath10k_warn("failed to flush transmit queue (skip %i ar-state %i): %i\n",
3685 skip, ar->state, ret);
3688 mutex_unlock(&ar->conf_mutex);
3691 /* TODO: Implement this function properly
3692 * For now it is needed to reply to Probe Requests in IBSS mode.
3693 * Propably we need this information from FW.
3695 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3701 static int ath10k_suspend(struct ieee80211_hw *hw,
3702 struct cfg80211_wowlan *wowlan)
3704 struct ath10k *ar = hw->priv;
3707 mutex_lock(&ar->conf_mutex);
3709 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
3711 if (ret == -ETIMEDOUT)
3717 ret = ath10k_hif_suspend(ar);
3719 ath10k_warn("failed to suspend hif: %d\n", ret);
3726 ret = ath10k_wmi_pdev_resume_target(ar);
3728 ath10k_warn("failed to resume target: %d\n", ret);
3732 mutex_unlock(&ar->conf_mutex);
3736 static int ath10k_resume(struct ieee80211_hw *hw)
3738 struct ath10k *ar = hw->priv;
3741 mutex_lock(&ar->conf_mutex);
3743 ret = ath10k_hif_resume(ar);
3745 ath10k_warn("failed to resume hif: %d\n", ret);
3750 ret = ath10k_wmi_pdev_resume_target(ar);
3752 ath10k_warn("failed to resume target: %d\n", ret);
3759 mutex_unlock(&ar->conf_mutex);
3764 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3766 struct ath10k *ar = hw->priv;
3768 mutex_lock(&ar->conf_mutex);
3770 /* If device failed to restart it will be in a different state, e.g.
3771 * ATH10K_STATE_WEDGED */
3772 if (ar->state == ATH10K_STATE_RESTARTED) {
3773 ath10k_info("device successfully recovered\n");
3774 ar->state = ATH10K_STATE_ON;
3777 mutex_unlock(&ar->conf_mutex);
3780 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3781 struct survey_info *survey)
3783 struct ath10k *ar = hw->priv;
3784 struct ieee80211_supported_band *sband;
3785 struct survey_info *ar_survey = &ar->survey[idx];
3788 mutex_lock(&ar->conf_mutex);
3790 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3791 if (sband && idx >= sband->n_channels) {
3792 idx -= sband->n_channels;
3797 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3799 if (!sband || idx >= sband->n_channels) {
3804 spin_lock_bh(&ar->data_lock);
3805 memcpy(survey, ar_survey, sizeof(*survey));
3806 spin_unlock_bh(&ar->data_lock);
3808 survey->channel = &sband->channels[idx];
3811 mutex_unlock(&ar->conf_mutex);
3815 /* Helper table for legacy fixed_rate/bitrate_mask */
3816 static const u8 cck_ofdm_rate[] = {
3833 /* Check if only one bit set */
3834 static int ath10k_check_single_mask(u32 mask)
3842 mask &= ~BIT(bit - 1);
3850 ath10k_default_bitrate_mask(struct ath10k *ar,
3851 enum ieee80211_band band,
3852 const struct cfg80211_bitrate_mask *mask)
3854 u32 legacy = 0x00ff;
3859 case IEEE80211_BAND_2GHZ:
3863 case IEEE80211_BAND_5GHZ:
3869 if (mask->control[band].legacy != legacy)
3872 for (i = 0; i < ar->num_rf_chains; i++)
3873 if (mask->control[band].ht_mcs[i] != ht)
3876 for (i = 0; i < ar->num_rf_chains; i++)
3877 if (mask->control[band].vht_mcs[i] != vht)
3884 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3885 enum ieee80211_band band,
3888 int ht_nss = 0, vht_nss = 0, i;
3891 if (ath10k_check_single_mask(mask->control[band].legacy))
3895 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3896 if (mask->control[band].ht_mcs[i] == 0xff)
3898 else if (mask->control[band].ht_mcs[i] == 0x00)
3907 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3908 if (mask->control[band].vht_mcs[i] == 0x03ff)
3910 else if (mask->control[band].vht_mcs[i] == 0x0000)
3918 if (ht_nss > 0 && vht_nss > 0)
3922 *fixed_nss = ht_nss;
3924 *fixed_nss = vht_nss;
3932 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3933 enum ieee80211_band band,
3934 enum wmi_rate_preamble *preamble)
3936 int legacy = 0, ht = 0, vht = 0, i;
3938 *preamble = WMI_RATE_PREAMBLE_OFDM;
3941 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3946 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3947 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3952 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3953 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3957 /* Currently we support only one fixed_rate */
3958 if ((legacy + ht + vht) != 1)
3962 *preamble = WMI_RATE_PREAMBLE_HT;
3964 *preamble = WMI_RATE_PREAMBLE_VHT;
3970 ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3971 enum ieee80211_band band,
3975 u8 rate = 0, pream = 0, nss = 0, i;
3976 enum wmi_rate_preamble preamble;
3978 /* Check if single rate correct */
3979 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3985 case WMI_RATE_PREAMBLE_CCK:
3986 case WMI_RATE_PREAMBLE_OFDM:
3987 i = ffs(mask->control[band].legacy) - 1;
3989 if (band == IEEE80211_BAND_2GHZ && i < 4)
3990 pream = WMI_RATE_PREAMBLE_CCK;
3992 if (band == IEEE80211_BAND_5GHZ)
3995 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3998 rate = cck_ofdm_rate[i];
4000 case WMI_RATE_PREAMBLE_HT:
4001 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4002 if (mask->control[band].ht_mcs[i])
4005 if (i == IEEE80211_HT_MCS_MASK_LEN)
4008 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4011 case WMI_RATE_PREAMBLE_VHT:
4012 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4013 if (mask->control[band].vht_mcs[i])
4016 if (i == NL80211_VHT_NSS_MAX)
4019 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4024 *fixed_nss = nss + 1;
4028 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4031 *fixed_rate = pream | nss | rate;
4036 static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
4037 enum ieee80211_band band,
4041 /* First check full NSS mask, if we can simply limit NSS */
4042 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4045 /* Next Check single rate is set */
4046 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
4049 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4054 struct ath10k *ar = arvif->ar;
4058 mutex_lock(&ar->conf_mutex);
4060 if (arvif->fixed_rate == fixed_rate &&
4061 arvif->fixed_nss == fixed_nss &&
4062 arvif->force_sgi == force_sgi)
4065 if (fixed_rate == WMI_FIXED_RATE_NONE)
4066 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4069 ath10k_dbg(ATH10K_DBG_MAC, "mac force sgi\n");
4071 vdev_param = ar->wmi.vdev_param->fixed_rate;
4072 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4073 vdev_param, fixed_rate);
4075 ath10k_warn("failed to set fixed rate param 0x%02x: %d\n",
4081 arvif->fixed_rate = fixed_rate;
4083 vdev_param = ar->wmi.vdev_param->nss;
4084 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4085 vdev_param, fixed_nss);
4088 ath10k_warn("failed to set fixed nss param %d: %d\n",
4094 arvif->fixed_nss = fixed_nss;
4096 vdev_param = ar->wmi.vdev_param->sgi;
4097 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4101 ath10k_warn("failed to set sgi param %d: %d\n",
4107 arvif->force_sgi = force_sgi;
4110 mutex_unlock(&ar->conf_mutex);
4114 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4115 struct ieee80211_vif *vif,
4116 const struct cfg80211_bitrate_mask *mask)
4118 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4119 struct ath10k *ar = arvif->ar;
4120 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4121 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4122 u8 fixed_nss = ar->num_rf_chains;
4125 force_sgi = mask->control[band].gi;
4126 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4129 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4130 if (!ath10k_get_fixed_rate_nss(mask, band,
4136 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4137 ath10k_warn("failed to force SGI usage for default rate settings\n");
4141 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4142 fixed_nss, force_sgi);
4145 static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
4146 struct ieee80211_vif *vif,
4147 struct cfg80211_chan_def *chandef)
4149 /* there's no need to do anything here. vif->csa_active is enough */
4153 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4154 struct ieee80211_vif *vif,
4155 struct ieee80211_sta *sta,
4158 struct ath10k *ar = hw->priv;
4159 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4162 spin_lock_bh(&ar->data_lock);
4164 ath10k_dbg(ATH10K_DBG_MAC,
4165 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4166 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4169 if (changed & IEEE80211_RC_BW_CHANGED) {
4170 bw = WMI_PEER_CHWIDTH_20MHZ;
4172 switch (sta->bandwidth) {
4173 case IEEE80211_STA_RX_BW_20:
4174 bw = WMI_PEER_CHWIDTH_20MHZ;
4176 case IEEE80211_STA_RX_BW_40:
4177 bw = WMI_PEER_CHWIDTH_40MHZ;
4179 case IEEE80211_STA_RX_BW_80:
4180 bw = WMI_PEER_CHWIDTH_80MHZ;
4182 case IEEE80211_STA_RX_BW_160:
4183 ath10k_warn("Invalid bandwith %d in rc update for %pM\n",
4184 sta->bandwidth, sta->addr);
4185 bw = WMI_PEER_CHWIDTH_20MHZ;
4192 if (changed & IEEE80211_RC_NSS_CHANGED)
4193 arsta->nss = sta->rx_nss;
4195 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4196 smps = WMI_PEER_SMPS_PS_NONE;
4198 switch (sta->smps_mode) {
4199 case IEEE80211_SMPS_AUTOMATIC:
4200 case IEEE80211_SMPS_OFF:
4201 smps = WMI_PEER_SMPS_PS_NONE;
4203 case IEEE80211_SMPS_STATIC:
4204 smps = WMI_PEER_SMPS_STATIC;
4206 case IEEE80211_SMPS_DYNAMIC:
4207 smps = WMI_PEER_SMPS_DYNAMIC;
4209 case IEEE80211_SMPS_NUM_MODES:
4210 ath10k_warn("Invalid smps %d in sta rc update for %pM\n",
4211 sta->smps_mode, sta->addr);
4212 smps = WMI_PEER_SMPS_PS_NONE;
4219 arsta->changed |= changed;
4221 spin_unlock_bh(&ar->data_lock);
4223 ieee80211_queue_work(hw, &arsta->update_wk);
4226 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4229 * FIXME: Return 0 for time being. Need to figure out whether FW
4230 * has the API to fetch 64-bit local TSF
4236 static const struct ieee80211_ops ath10k_ops = {
4238 .start = ath10k_start,
4239 .stop = ath10k_stop,
4240 .config = ath10k_config,
4241 .add_interface = ath10k_add_interface,
4242 .remove_interface = ath10k_remove_interface,
4243 .configure_filter = ath10k_configure_filter,
4244 .bss_info_changed = ath10k_bss_info_changed,
4245 .hw_scan = ath10k_hw_scan,
4246 .cancel_hw_scan = ath10k_cancel_hw_scan,
4247 .set_key = ath10k_set_key,
4248 .sta_state = ath10k_sta_state,
4249 .conf_tx = ath10k_conf_tx,
4250 .remain_on_channel = ath10k_remain_on_channel,
4251 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4252 .set_rts_threshold = ath10k_set_rts_threshold,
4253 .set_frag_threshold = ath10k_set_frag_threshold,
4254 .flush = ath10k_flush,
4255 .tx_last_beacon = ath10k_tx_last_beacon,
4256 .restart_complete = ath10k_restart_complete,
4257 .get_survey = ath10k_get_survey,
4258 .set_bitrate_mask = ath10k_set_bitrate_mask,
4259 .channel_switch_beacon = ath10k_channel_switch_beacon,
4260 .sta_rc_update = ath10k_sta_rc_update,
4261 .get_tsf = ath10k_get_tsf,
4263 .suspend = ath10k_suspend,
4264 .resume = ath10k_resume,
4268 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4269 .bitrate = (_rate), \
4270 .flags = (_flags), \
4271 .hw_value = (_rateid), \
4274 #define CHAN2G(_channel, _freq, _flags) { \
4275 .band = IEEE80211_BAND_2GHZ, \
4276 .hw_value = (_channel), \
4277 .center_freq = (_freq), \
4278 .flags = (_flags), \
4279 .max_antenna_gain = 0, \
4283 #define CHAN5G(_channel, _freq, _flags) { \
4284 .band = IEEE80211_BAND_5GHZ, \
4285 .hw_value = (_channel), \
4286 .center_freq = (_freq), \
4287 .flags = (_flags), \
4288 .max_antenna_gain = 0, \
4292 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4302 CHAN2G(10, 2457, 0),
4303 CHAN2G(11, 2462, 0),
4304 CHAN2G(12, 2467, 0),
4305 CHAN2G(13, 2472, 0),
4306 CHAN2G(14, 2484, 0),
4309 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4310 CHAN5G(36, 5180, 0),
4311 CHAN5G(40, 5200, 0),
4312 CHAN5G(44, 5220, 0),
4313 CHAN5G(48, 5240, 0),
4314 CHAN5G(52, 5260, 0),
4315 CHAN5G(56, 5280, 0),
4316 CHAN5G(60, 5300, 0),
4317 CHAN5G(64, 5320, 0),
4318 CHAN5G(100, 5500, 0),
4319 CHAN5G(104, 5520, 0),
4320 CHAN5G(108, 5540, 0),
4321 CHAN5G(112, 5560, 0),
4322 CHAN5G(116, 5580, 0),
4323 CHAN5G(120, 5600, 0),
4324 CHAN5G(124, 5620, 0),
4325 CHAN5G(128, 5640, 0),
4326 CHAN5G(132, 5660, 0),
4327 CHAN5G(136, 5680, 0),
4328 CHAN5G(140, 5700, 0),
4329 CHAN5G(149, 5745, 0),
4330 CHAN5G(153, 5765, 0),
4331 CHAN5G(157, 5785, 0),
4332 CHAN5G(161, 5805, 0),
4333 CHAN5G(165, 5825, 0),
4336 static struct ieee80211_rate ath10k_rates[] = {
4338 RATETAB_ENT(10, 0x82, 0),
4339 RATETAB_ENT(20, 0x84, 0),
4340 RATETAB_ENT(55, 0x8b, 0),
4341 RATETAB_ENT(110, 0x96, 0),
4343 RATETAB_ENT(60, 0x0c, 0),
4344 RATETAB_ENT(90, 0x12, 0),
4345 RATETAB_ENT(120, 0x18, 0),
4346 RATETAB_ENT(180, 0x24, 0),
4347 RATETAB_ENT(240, 0x30, 0),
4348 RATETAB_ENT(360, 0x48, 0),
4349 RATETAB_ENT(480, 0x60, 0),
4350 RATETAB_ENT(540, 0x6c, 0),
4353 #define ath10k_a_rates (ath10k_rates + 4)
4354 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4355 #define ath10k_g_rates (ath10k_rates + 0)
4356 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4358 struct ath10k *ath10k_mac_create(void)
4360 struct ieee80211_hw *hw;
4363 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4373 void ath10k_mac_destroy(struct ath10k *ar)
4375 ieee80211_free_hw(ar->hw);
4378 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4381 .types = BIT(NL80211_IFTYPE_STATION)
4382 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4386 .types = BIT(NL80211_IFTYPE_P2P_GO)
4390 .types = BIT(NL80211_IFTYPE_AP)
4394 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4397 .types = BIT(NL80211_IFTYPE_AP)
4401 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4403 .limits = ath10k_if_limits,
4404 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4405 .max_interfaces = 8,
4406 .num_different_channels = 1,
4407 .beacon_int_infra_match = true,
4411 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4413 .limits = ath10k_10x_if_limits,
4414 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4415 .max_interfaces = 8,
4416 .num_different_channels = 1,
4417 .beacon_int_infra_match = true,
4418 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4419 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4420 BIT(NL80211_CHAN_WIDTH_20) |
4421 BIT(NL80211_CHAN_WIDTH_40) |
4422 BIT(NL80211_CHAN_WIDTH_80),
4427 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4429 struct ieee80211_sta_vht_cap vht_cap = {0};
4433 vht_cap.vht_supported = 1;
4434 vht_cap.cap = ar->vht_cap_info;
4437 for (i = 0; i < 8; i++) {
4438 if (i < ar->num_rf_chains)
4439 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4441 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4444 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4445 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4450 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4453 struct ieee80211_sta_ht_cap ht_cap = {0};
4455 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4458 ht_cap.ht_supported = 1;
4459 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4460 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4461 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4462 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4463 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4465 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4466 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4468 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4469 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4471 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4474 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4475 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4480 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4481 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4483 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4486 stbc = ar->ht_cap_info;
4487 stbc &= WMI_HT_CAP_RX_STBC;
4488 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4489 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4490 stbc &= IEEE80211_HT_CAP_RX_STBC;
4495 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4496 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4498 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4499 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4501 /* max AMSDU is implicitly taken from vht_cap_info */
4502 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4503 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4505 for (i = 0; i < ar->num_rf_chains; i++)
4506 ht_cap.mcs.rx_mask[i] = 0xFF;
4508 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4514 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4515 struct ieee80211_vif *vif)
4517 struct ath10k_vif_iter *arvif_iter = data;
4518 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4520 if (arvif->vdev_id == arvif_iter->vdev_id)
4521 arvif_iter->arvif = arvif;
4524 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4526 struct ath10k_vif_iter arvif_iter;
4529 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4530 arvif_iter.vdev_id = vdev_id;
4532 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4533 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4535 ath10k_get_arvif_iter,
4537 if (!arvif_iter.arvif) {
4538 ath10k_warn("No VIF found for vdev %d\n", vdev_id);
4542 return arvif_iter.arvif;
4545 int ath10k_mac_register(struct ath10k *ar)
4547 struct ieee80211_supported_band *band;
4548 struct ieee80211_sta_vht_cap vht_cap;
4549 struct ieee80211_sta_ht_cap ht_cap;
4553 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4555 SET_IEEE80211_DEV(ar->hw, ar->dev);
4557 ht_cap = ath10k_get_ht_cap(ar);
4558 vht_cap = ath10k_create_vht_cap(ar);
4560 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4561 channels = kmemdup(ath10k_2ghz_channels,
4562 sizeof(ath10k_2ghz_channels),
4569 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4570 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4571 band->channels = channels;
4572 band->n_bitrates = ath10k_g_rates_size;
4573 band->bitrates = ath10k_g_rates;
4574 band->ht_cap = ht_cap;
4576 /* vht is not supported in 2.4 GHz */
4578 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4581 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4582 channels = kmemdup(ath10k_5ghz_channels,
4583 sizeof(ath10k_5ghz_channels),
4590 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4591 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4592 band->channels = channels;
4593 band->n_bitrates = ath10k_a_rates_size;
4594 band->bitrates = ath10k_a_rates;
4595 band->ht_cap = ht_cap;
4596 band->vht_cap = vht_cap;
4597 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4600 ar->hw->wiphy->interface_modes =
4601 BIT(NL80211_IFTYPE_STATION) |
4602 BIT(NL80211_IFTYPE_ADHOC) |
4603 BIT(NL80211_IFTYPE_AP);
4605 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4606 ar->hw->wiphy->interface_modes |=
4607 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4608 BIT(NL80211_IFTYPE_P2P_GO);
4610 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4611 IEEE80211_HW_SUPPORTS_PS |
4612 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4613 IEEE80211_HW_SUPPORTS_UAPSD |
4614 IEEE80211_HW_MFP_CAPABLE |
4615 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4616 IEEE80211_HW_HAS_RATE_CONTROL |
4617 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4618 IEEE80211_HW_AP_LINK_PS |
4619 IEEE80211_HW_SPECTRUM_MGMT;
4621 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4622 * bytes is used for padding/alignment if necessary. */
4623 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4625 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4626 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4628 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4629 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4630 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4633 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4634 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4636 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4637 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
4639 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4641 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4642 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4643 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4645 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4647 * on LL hardware queues are managed entirely by the FW
4648 * so we only advertise to mac we can do the queues thing
4652 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4653 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4654 ar->hw->wiphy->n_iface_combinations =
4655 ARRAY_SIZE(ath10k_10x_if_comb);
4657 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4658 ar->hw->wiphy->n_iface_combinations =
4659 ARRAY_SIZE(ath10k_if_comb);
4662 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4664 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4665 /* Init ath dfs pattern detector */
4666 ar->ath_common.debug_mask = ATH_DBG_DFS;
4667 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4670 if (!ar->dfs_detector)
4671 ath10k_warn("failed to initialise DFS pattern detector\n");
4674 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4675 ath10k_reg_notifier);
4677 ath10k_err("failed to initialise regulatory: %i\n", ret);
4681 ret = ieee80211_register_hw(ar->hw);
4683 ath10k_err("failed to register ieee80211: %d\n", ret);
4687 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4688 ret = regulatory_hint(ar->hw->wiphy,
4689 ar->ath_common.regulatory.alpha2);
4691 goto err_unregister;
4697 ieee80211_unregister_hw(ar->hw);
4699 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4700 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4705 void ath10k_mac_unregister(struct ath10k *ar)
4707 ieee80211_unregister_hw(ar->hw);
4709 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4710 ar->dfs_detector->exit(ar->dfs_detector);
4712 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4713 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4715 SET_IEEE80211_DEV(ar->hw, NULL);