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 INIT_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("could not 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("could not remove key for %pM\n", addr);
223 /*********************/
224 /* General utilities */
225 /*********************/
227 static inline enum wmi_phy_mode
228 chan_to_phymode(const struct cfg80211_chan_def *chandef)
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
279 WARN_ON(phymode == MODE_UNKNOWN);
283 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
296 switch (mpdudensity) {
302 /* Our lower layer calculations limit our precision to
318 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
322 lockdep_assert_held(&ar->conf_mutex);
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
326 ath10k_warn("Failed to create wmi peer: %i\n", ret);
330 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
332 ath10k_warn("Failed to wait for created wmi peer: %i\n", ret);
339 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
341 struct ath10k *ar = arvif->ar;
344 if (value != 0xFFFFFFFF)
345 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
348 vdev_param = ar->wmi.vdev_param->rts_threshold;
349 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
352 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
354 struct ath10k *ar = arvif->ar;
357 if (value != 0xFFFFFFFF)
358 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
359 ATH10K_FRAGMT_THRESHOLD_MIN,
360 ATH10K_FRAGMT_THRESHOLD_MAX);
362 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
363 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
366 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
370 lockdep_assert_held(&ar->conf_mutex);
372 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
376 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
383 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
385 struct ath10k_peer *peer, *tmp;
387 lockdep_assert_held(&ar->conf_mutex);
389 spin_lock_bh(&ar->data_lock);
390 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
391 if (peer->vdev_id != vdev_id)
394 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
395 peer->addr, vdev_id);
397 list_del(&peer->list);
400 spin_unlock_bh(&ar->data_lock);
403 static void ath10k_peer_cleanup_all(struct ath10k *ar)
405 struct ath10k_peer *peer, *tmp;
407 lockdep_assert_held(&ar->conf_mutex);
409 spin_lock_bh(&ar->data_lock);
410 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
411 list_del(&peer->list);
414 spin_unlock_bh(&ar->data_lock);
417 /************************/
418 /* Interface management */
419 /************************/
421 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
425 lockdep_assert_held(&ar->conf_mutex);
427 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
428 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
435 static int ath10k_vdev_start(struct ath10k_vif *arvif)
437 struct ath10k *ar = arvif->ar;
438 struct ieee80211_conf *conf = &ar->hw->conf;
439 struct ieee80211_channel *channel = conf->chandef.chan;
440 struct wmi_vdev_start_request_arg arg = {};
443 lockdep_assert_held(&ar->conf_mutex);
445 INIT_COMPLETION(ar->vdev_setup_done);
447 arg.vdev_id = arvif->vdev_id;
448 arg.dtim_period = arvif->dtim_period;
449 arg.bcn_intval = arvif->beacon_interval;
451 arg.channel.freq = channel->center_freq;
453 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
455 arg.channel.mode = chan_to_phymode(&conf->chandef);
457 arg.channel.min_power = 0;
458 arg.channel.max_power = channel->max_power * 2;
459 arg.channel.max_reg_power = channel->max_reg_power * 2;
460 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
462 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
463 arg.ssid = arvif->u.ap.ssid;
464 arg.ssid_len = arvif->u.ap.ssid_len;
465 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
467 /* For now allow DFS for AP mode */
468 arg.channel.chan_radar =
469 !!(channel->flags & IEEE80211_CHAN_RADAR);
470 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
471 arg.ssid = arvif->vif->bss_conf.ssid;
472 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
475 ath10k_dbg(ATH10K_DBG_MAC,
476 "mac vdev %d start center_freq %d phymode %s\n",
477 arg.vdev_id, arg.channel.freq,
478 ath10k_wmi_phymode_str(arg.channel.mode));
480 ret = ath10k_wmi_vdev_start(ar, &arg);
482 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
486 ret = ath10k_vdev_setup_sync(ar);
488 ath10k_warn("vdev setup failed %d\n", ret);
495 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
497 struct ath10k *ar = arvif->ar;
500 lockdep_assert_held(&ar->conf_mutex);
502 INIT_COMPLETION(ar->vdev_setup_done);
504 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
506 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
510 ret = ath10k_vdev_setup_sync(ar);
512 ath10k_warn("vdev setup failed %d\n", ret);
519 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
521 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
522 struct wmi_vdev_start_request_arg arg = {};
525 lockdep_assert_held(&ar->conf_mutex);
527 if (!ar->monitor_present) {
528 ath10k_warn("mac montor stop -- monitor is not present\n");
532 arg.vdev_id = vdev_id;
533 arg.channel.freq = channel->center_freq;
534 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
536 /* TODO setup this dynamically, what in case we
537 don't have any vifs? */
538 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
539 arg.channel.chan_radar =
540 !!(channel->flags & IEEE80211_CHAN_RADAR);
542 arg.channel.min_power = 0;
543 arg.channel.max_power = channel->max_power * 2;
544 arg.channel.max_reg_power = channel->max_reg_power * 2;
545 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
547 ret = ath10k_wmi_vdev_start(ar, &arg);
549 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
553 ret = ath10k_vdev_setup_sync(ar);
555 ath10k_warn("Monitor vdev setup failed %d\n", ret);
559 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
561 ath10k_warn("Monitor vdev up failed: %d\n", ret);
565 ar->monitor_vdev_id = vdev_id;
566 ar->monitor_enabled = true;
571 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
573 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
578 static int ath10k_monitor_stop(struct ath10k *ar)
582 lockdep_assert_held(&ar->conf_mutex);
584 if (!ar->monitor_present) {
585 ath10k_warn("mac montor stop -- monitor is not present\n");
589 if (!ar->monitor_enabled) {
590 ath10k_warn("mac montor stop -- monitor is not enabled\n");
594 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
596 ath10k_warn("Monitor vdev down failed: %d\n", ret);
598 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
600 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
602 ret = ath10k_vdev_setup_sync(ar);
604 ath10k_warn("Monitor_down sync failed: %d\n", ret);
606 ar->monitor_enabled = false;
610 static int ath10k_monitor_create(struct ath10k *ar)
614 lockdep_assert_held(&ar->conf_mutex);
616 if (ar->monitor_present) {
617 ath10k_warn("Monitor mode already enabled\n");
621 bit = ffs(ar->free_vdev_map);
623 ath10k_warn("No free VDEV slots\n");
627 ar->monitor_vdev_id = bit - 1;
628 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
630 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
631 WMI_VDEV_TYPE_MONITOR,
634 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
638 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
639 ar->monitor_vdev_id);
641 ar->monitor_present = true;
646 * Restore the ID to the global map.
648 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
652 static int ath10k_monitor_destroy(struct ath10k *ar)
656 lockdep_assert_held(&ar->conf_mutex);
658 if (!ar->monitor_present)
661 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
663 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
667 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
668 ar->monitor_present = false;
670 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
671 ar->monitor_vdev_id);
675 static int ath10k_start_cac(struct ath10k *ar)
679 lockdep_assert_held(&ar->conf_mutex);
681 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
683 ret = ath10k_monitor_create(ar);
685 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
689 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
691 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
692 ath10k_monitor_destroy(ar);
696 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
697 ar->monitor_vdev_id);
702 static int ath10k_stop_cac(struct ath10k *ar)
704 lockdep_assert_held(&ar->conf_mutex);
706 /* CAC is not running - do nothing */
707 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
710 ath10k_monitor_stop(ar);
711 ath10k_monitor_destroy(ar);
712 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
714 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
719 static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
722 case NL80211_DFS_USABLE:
724 case NL80211_DFS_UNAVAILABLE:
725 return "UNAVAILABLE";
726 case NL80211_DFS_AVAILABLE:
734 static void ath10k_config_radar_detection(struct ath10k *ar)
736 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
737 bool radar = ar->hw->conf.radar_enabled;
738 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
739 enum nl80211_dfs_state dfs_state = chan->dfs_state;
742 lockdep_assert_held(&ar->conf_mutex);
744 ath10k_dbg(ATH10K_DBG_MAC,
745 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
746 chan->center_freq, radar, chan_radar,
747 ath10k_dfs_state(dfs_state));
750 * It's safe to call it even if CAC is not started.
751 * This call here guarantees changing channel, etc. will stop CAC.
761 if (dfs_state != NL80211_DFS_USABLE)
764 ret = ath10k_start_cac(ar);
767 * Not possible to start CAC on current channel so starting
768 * radiation is not allowed, make this channel DFS_UNAVAILABLE
769 * by indicating that radar was detected.
771 ath10k_warn("failed to start CAC (%d)\n", ret);
772 ieee80211_radar_detected(ar->hw);
776 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
777 struct ieee80211_bss_conf *info)
781 lockdep_assert_held(&arvif->ar->conf_mutex);
783 if (!info->enable_beacon) {
784 ath10k_vdev_stop(arvif);
788 arvif->tx_seq_no = 0x1000;
790 ret = ath10k_vdev_start(arvif);
794 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
796 ath10k_warn("Failed to bring up VDEV: %d\n",
800 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
803 static void ath10k_control_ibss(struct ath10k_vif *arvif,
804 struct ieee80211_bss_conf *info,
805 const u8 self_peer[ETH_ALEN])
810 lockdep_assert_held(&arvif->ar->conf_mutex);
812 if (!info->ibss_joined) {
813 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
815 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
816 self_peer, arvif->vdev_id, ret);
818 if (is_zero_ether_addr(arvif->u.ibss.bssid))
821 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
822 arvif->u.ibss.bssid);
824 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
825 arvif->u.ibss.bssid, arvif->vdev_id, ret);
829 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
834 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
836 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
837 self_peer, arvif->vdev_id, ret);
841 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
842 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
843 ATH10K_DEFAULT_ATIM);
845 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
846 arvif->vdev_id, ret);
850 * Review this when mac80211 gains per-interface powersave support.
852 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
854 struct ath10k *ar = arvif->ar;
855 struct ieee80211_conf *conf = &ar->hw->conf;
856 enum wmi_sta_powersave_param param;
857 enum wmi_sta_ps_mode psmode;
860 lockdep_assert_held(&arvif->ar->conf_mutex);
862 if (arvif->vif->type != NL80211_IFTYPE_STATION)
865 if (conf->flags & IEEE80211_CONF_PS) {
866 psmode = WMI_STA_PS_MODE_ENABLED;
867 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
869 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
870 conf->dynamic_ps_timeout);
872 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
877 psmode = WMI_STA_PS_MODE_DISABLED;
880 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
881 arvif->vdev_id, psmode ? "enable" : "disable");
883 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
885 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
886 psmode, arvif->vdev_id);
893 /**********************/
894 /* Station management */
895 /**********************/
897 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
898 struct ath10k_vif *arvif,
899 struct ieee80211_sta *sta,
900 struct ieee80211_bss_conf *bss_conf,
901 struct wmi_peer_assoc_complete_arg *arg)
903 lockdep_assert_held(&ar->conf_mutex);
905 memcpy(arg->addr, sta->addr, ETH_ALEN);
906 arg->vdev_id = arvif->vdev_id;
907 arg->peer_aid = sta->aid;
908 arg->peer_flags |= WMI_PEER_AUTH;
910 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
912 * Seems FW have problems with Power Save in STA
913 * mode when we setup this parameter to high (eg. 5).
914 * Often we see that FW don't send NULL (with clean P flags)
915 * frame even there is info about buffered frames in beacons.
916 * Sometimes we have to wait more than 10 seconds before FW
917 * will wakeup. Often sending one ping from AP to our device
918 * just fail (more than 50%).
920 * Seems setting this FW parameter to 1 couse FW
921 * will check every beacon and will wakup immediately
922 * after detection buffered data.
924 arg->peer_listen_intval = 1;
926 arg->peer_listen_intval = ar->hw->conf.listen_interval;
928 arg->peer_num_spatial_streams = 1;
931 * The assoc capabilities are available only in managed mode.
933 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
934 arg->peer_caps = bss_conf->assoc_capability;
937 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
938 struct ath10k_vif *arvif,
939 struct wmi_peer_assoc_complete_arg *arg)
941 struct ieee80211_vif *vif = arvif->vif;
942 struct ieee80211_bss_conf *info = &vif->bss_conf;
943 struct cfg80211_bss *bss;
944 const u8 *rsnie = NULL;
945 const u8 *wpaie = NULL;
947 lockdep_assert_held(&ar->conf_mutex);
949 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
950 info->bssid, NULL, 0, 0, 0);
952 const struct cfg80211_bss_ies *ies;
955 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
957 ies = rcu_dereference(bss->ies);
959 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
960 WLAN_OUI_TYPE_MICROSOFT_WPA,
964 cfg80211_put_bss(ar->hw->wiphy, bss);
967 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
968 if (rsnie || wpaie) {
969 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
970 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
974 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
975 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
979 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
980 struct ieee80211_sta *sta,
981 struct wmi_peer_assoc_complete_arg *arg)
983 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
984 const struct ieee80211_supported_band *sband;
985 const struct ieee80211_rate *rates;
989 lockdep_assert_held(&ar->conf_mutex);
991 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
992 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
993 rates = sband->bitrates;
995 rateset->num_rates = 0;
997 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1001 rateset->rates[rateset->num_rates] = rates->hw_value;
1002 rateset->num_rates++;
1006 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1007 struct ieee80211_sta *sta,
1008 struct wmi_peer_assoc_complete_arg *arg)
1010 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1014 lockdep_assert_held(&ar->conf_mutex);
1016 if (!ht_cap->ht_supported)
1019 arg->peer_flags |= WMI_PEER_HT;
1020 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1021 ht_cap->ampdu_factor)) - 1;
1023 arg->peer_mpdu_density =
1024 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1026 arg->peer_ht_caps = ht_cap->cap;
1027 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1029 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1030 arg->peer_flags |= WMI_PEER_LDPC;
1032 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1033 arg->peer_flags |= WMI_PEER_40MHZ;
1034 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1037 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1038 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1040 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1041 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1043 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1044 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1045 arg->peer_flags |= WMI_PEER_STBC;
1048 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1050 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1051 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1052 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1053 arg->peer_rate_caps |= stbc;
1054 arg->peer_flags |= WMI_PEER_STBC;
1057 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1058 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1060 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
1061 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1062 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1063 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
1064 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1065 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
1068 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1069 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1070 else if (ht_cap->mcs.rx_mask[1])
1071 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1073 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1074 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1075 arg->peer_ht_rates.rates[n++] = i;
1077 arg->peer_ht_rates.num_rates = n;
1078 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
1080 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1082 arg->peer_ht_rates.num_rates,
1083 arg->peer_num_spatial_streams);
1086 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
1087 struct ath10k_vif *arvif,
1088 struct ieee80211_sta *sta,
1089 struct ieee80211_bss_conf *bss_conf,
1090 struct wmi_peer_assoc_complete_arg *arg)
1095 lockdep_assert_held(&ar->conf_mutex);
1098 arg->peer_flags |= WMI_PEER_QOS;
1100 if (sta->wme && sta->uapsd_queues) {
1101 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1102 sta->uapsd_queues, sta->max_sp);
1104 arg->peer_flags |= WMI_PEER_APSD;
1105 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1107 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1108 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1109 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1110 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1111 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1112 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1113 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1114 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1115 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1116 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1117 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1118 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1121 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1122 max_sp = sta->max_sp;
1124 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1126 WMI_AP_PS_PEER_PARAM_UAPSD,
1129 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1131 WMI_AP_PS_PEER_PARAM_MAX_SP,
1134 /* TODO setup this based on STA listen interval and
1135 beacon interval. Currently we don't know
1136 sta->listen_interval - mac80211 patch required.
1137 Currently use 10 seconds */
1138 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1140 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1145 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1146 struct ath10k_vif *arvif,
1147 struct ieee80211_sta *sta,
1148 struct ieee80211_bss_conf *bss_conf,
1149 struct wmi_peer_assoc_complete_arg *arg)
1152 arg->peer_flags |= WMI_PEER_QOS;
1155 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1156 struct ieee80211_sta *sta,
1157 struct wmi_peer_assoc_complete_arg *arg)
1159 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1162 if (!vht_cap->vht_supported)
1165 arg->peer_flags |= WMI_PEER_VHT;
1166 arg->peer_vht_caps = vht_cap->cap;
1169 ampdu_factor = (vht_cap->cap &
1170 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1171 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1173 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1174 * zero in VHT IE. Using it would result in degraded throughput.
1175 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1176 * it if VHT max_mpdu is smaller. */
1177 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1178 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1179 ampdu_factor)) - 1);
1181 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1182 arg->peer_flags |= WMI_PEER_80MHZ;
1184 arg->peer_vht_rates.rx_max_rate =
1185 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1186 arg->peer_vht_rates.rx_mcs_set =
1187 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1188 arg->peer_vht_rates.tx_max_rate =
1189 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1190 arg->peer_vht_rates.tx_mcs_set =
1191 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1193 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1194 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1197 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1198 struct ath10k_vif *arvif,
1199 struct ieee80211_sta *sta,
1200 struct ieee80211_bss_conf *bss_conf,
1201 struct wmi_peer_assoc_complete_arg *arg)
1203 switch (arvif->vdev_type) {
1204 case WMI_VDEV_TYPE_AP:
1205 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1207 case WMI_VDEV_TYPE_STA:
1208 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1215 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1216 struct ath10k_vif *arvif,
1217 struct ieee80211_sta *sta,
1218 struct wmi_peer_assoc_complete_arg *arg)
1220 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1222 switch (ar->hw->conf.chandef.chan->band) {
1223 case IEEE80211_BAND_2GHZ:
1224 if (sta->ht_cap.ht_supported) {
1225 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1226 phymode = MODE_11NG_HT40;
1228 phymode = MODE_11NG_HT20;
1234 case IEEE80211_BAND_5GHZ:
1238 if (sta->vht_cap.vht_supported) {
1239 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1240 phymode = MODE_11AC_VHT80;
1241 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1242 phymode = MODE_11AC_VHT40;
1243 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1244 phymode = MODE_11AC_VHT20;
1245 } else if (sta->ht_cap.ht_supported) {
1246 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1247 phymode = MODE_11NA_HT40;
1249 phymode = MODE_11NA_HT20;
1259 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1260 sta->addr, ath10k_wmi_phymode_str(phymode));
1262 arg->peer_phymode = phymode;
1263 WARN_ON(phymode == MODE_UNKNOWN);
1266 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1267 struct ath10k_vif *arvif,
1268 struct ieee80211_sta *sta,
1269 struct ieee80211_bss_conf *bss_conf,
1270 struct wmi_peer_assoc_complete_arg *arg)
1272 lockdep_assert_held(&ar->conf_mutex);
1274 memset(arg, 0, sizeof(*arg));
1276 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1277 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1278 ath10k_peer_assoc_h_rates(ar, sta, arg);
1279 ath10k_peer_assoc_h_ht(ar, sta, arg);
1280 ath10k_peer_assoc_h_vht(ar, sta, arg);
1281 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1282 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
1287 /* can be called only in mac80211 callbacks due to `key_count` usage */
1288 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1289 struct ieee80211_vif *vif,
1290 struct ieee80211_bss_conf *bss_conf)
1292 struct ath10k *ar = hw->priv;
1293 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1294 struct wmi_peer_assoc_complete_arg peer_arg;
1295 struct ieee80211_sta *ap_sta;
1298 lockdep_assert_held(&ar->conf_mutex);
1302 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1304 ath10k_warn("Failed to find station entry for %pM\n",
1310 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1311 bss_conf, &peer_arg);
1313 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1314 bss_conf->bssid, ret);
1321 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1323 ath10k_warn("Peer assoc failed for %pM\n: %d",
1324 bss_conf->bssid, ret);
1328 ath10k_dbg(ATH10K_DBG_MAC,
1329 "mac vdev %d up (associated) bssid %pM aid %d\n",
1330 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1332 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1335 ath10k_warn("VDEV: %d up failed: ret %d\n",
1336 arvif->vdev_id, ret);
1342 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1343 struct ieee80211_vif *vif)
1345 struct ath10k *ar = hw->priv;
1346 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1349 lockdep_assert_held(&ar->conf_mutex);
1352 * For some reason, calling VDEV-DOWN before VDEV-STOP
1353 * makes the FW to send frames via HTT after disassociation.
1354 * No idea why this happens, even though VDEV-DOWN is supposed
1355 * to be analogous to link down, so just stop the VDEV.
1357 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1360 /* FIXME: check return value */
1361 ret = ath10k_vdev_stop(arvif);
1364 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1365 * report beacons from previously associated network through HTT.
1366 * This in turn would spam mac80211 WARN_ON if we bring down all
1367 * interfaces as it expects there is no rx when no interface is
1370 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1372 /* FIXME: why don't we print error if wmi call fails? */
1373 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1375 arvif->def_wep_key_idx = 0;
1378 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1379 struct ieee80211_sta *sta)
1381 struct wmi_peer_assoc_complete_arg peer_arg;
1384 lockdep_assert_held(&ar->conf_mutex);
1386 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1388 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1393 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1395 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1400 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1402 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1409 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1410 struct ieee80211_sta *sta)
1414 lockdep_assert_held(&ar->conf_mutex);
1416 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1418 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1429 static int ath10k_update_channel_list(struct ath10k *ar)
1431 struct ieee80211_hw *hw = ar->hw;
1432 struct ieee80211_supported_band **bands;
1433 enum ieee80211_band band;
1434 struct ieee80211_channel *channel;
1435 struct wmi_scan_chan_list_arg arg = {0};
1436 struct wmi_channel_arg *ch;
1442 lockdep_assert_held(&ar->conf_mutex);
1444 bands = hw->wiphy->bands;
1445 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1449 for (i = 0; i < bands[band]->n_channels; i++) {
1450 if (bands[band]->channels[i].flags &
1451 IEEE80211_CHAN_DISABLED)
1458 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1459 arg.channels = kzalloc(len, GFP_KERNEL);
1464 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1468 for (i = 0; i < bands[band]->n_channels; i++) {
1469 channel = &bands[band]->channels[i];
1471 if (channel->flags & IEEE80211_CHAN_DISABLED)
1474 ch->allow_ht = true;
1476 /* FIXME: when should we really allow VHT? */
1477 ch->allow_vht = true;
1480 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1483 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1486 !!(channel->flags & IEEE80211_CHAN_RADAR);
1488 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1489 ch->passive = passive;
1491 ch->freq = channel->center_freq;
1493 ch->max_power = channel->max_power * 2;
1494 ch->max_reg_power = channel->max_reg_power * 2;
1495 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1496 ch->reg_class_id = 0; /* FIXME */
1498 /* FIXME: why use only legacy modes, why not any
1499 * HT/VHT modes? Would that even make any
1501 if (channel->band == IEEE80211_BAND_2GHZ)
1502 ch->mode = MODE_11G;
1504 ch->mode = MODE_11A;
1506 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1509 ath10k_dbg(ATH10K_DBG_WMI,
1510 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1511 ch - arg.channels, arg.n_channels,
1512 ch->freq, ch->max_power, ch->max_reg_power,
1513 ch->max_antenna_gain, ch->mode);
1519 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1520 kfree(arg.channels);
1525 static void ath10k_regd_update(struct ath10k *ar)
1527 struct reg_dmn_pair_mapping *regpair;
1530 lockdep_assert_held(&ar->conf_mutex);
1532 ret = ath10k_update_channel_list(ar);
1534 ath10k_warn("could not update channel list (%d)\n", ret);
1536 regpair = ar->ath_common.regulatory.regpair;
1538 /* Target allows setting up per-band regdomain but ath_common provides
1539 * a combined one only */
1540 ret = ath10k_wmi_pdev_set_regdomain(ar,
1541 regpair->regDmnEnum,
1542 regpair->regDmnEnum, /* 2ghz */
1543 regpair->regDmnEnum, /* 5ghz */
1544 regpair->reg_2ghz_ctl,
1545 regpair->reg_5ghz_ctl);
1547 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1550 static void ath10k_reg_notifier(struct wiphy *wiphy,
1551 struct regulatory_request *request)
1553 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1554 struct ath10k *ar = hw->priv;
1557 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1559 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1560 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1561 request->dfs_region);
1562 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1563 request->dfs_region);
1565 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1566 request->dfs_region);
1569 mutex_lock(&ar->conf_mutex);
1570 if (ar->state == ATH10K_STATE_ON)
1571 ath10k_regd_update(ar);
1572 mutex_unlock(&ar->conf_mutex);
1579 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1581 if (ieee80211_is_mgmt(hdr->frame_control))
1582 return HTT_DATA_TX_EXT_TID_MGMT;
1584 if (!ieee80211_is_data_qos(hdr->frame_control))
1585 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1587 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1588 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1590 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1593 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1594 struct ieee80211_tx_info *info)
1596 if (info->control.vif)
1597 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1599 if (ar->monitor_enabled)
1600 return ar->monitor_vdev_id;
1602 ath10k_warn("could not resolve vdev id\n");
1607 * Frames sent to the FW have to be in "Native Wifi" format.
1608 * Strip the QoS field from the 802.11 header.
1610 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1611 struct ieee80211_tx_control *control,
1612 struct sk_buff *skb)
1614 struct ieee80211_hdr *hdr = (void *)skb->data;
1617 if (!ieee80211_is_data_qos(hdr->frame_control))
1620 qos_ctl = ieee80211_get_qos_ctl(hdr);
1621 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1622 skb->data, (void *)qos_ctl - (void *)skb->data);
1623 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1626 static void ath10k_tx_wep_key_work(struct work_struct *work)
1628 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1630 int ret, keyidx = arvif->def_wep_key_newidx;
1632 if (arvif->def_wep_key_idx == keyidx)
1635 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1636 arvif->vdev_id, keyidx);
1638 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1640 arvif->ar->wmi.vdev_param->def_keyid,
1643 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1647 arvif->def_wep_key_idx = keyidx;
1650 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1652 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1653 struct ieee80211_vif *vif = info->control.vif;
1654 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1655 struct ath10k *ar = arvif->ar;
1656 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1657 struct ieee80211_key_conf *key = info->control.hw_key;
1659 if (!ieee80211_has_protected(hdr->frame_control))
1665 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1666 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1669 if (key->keyidx == arvif->def_wep_key_idx)
1672 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1673 * queueing frames until key index is updated is not an option because
1674 * sk_buff may need more processing to be done, e.g. offchannel */
1675 arvif->def_wep_key_newidx = key->keyidx;
1676 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1679 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1681 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1682 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1683 struct ieee80211_vif *vif = info->control.vif;
1684 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1686 /* This is case only for P2P_GO */
1687 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1688 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1691 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1692 spin_lock_bh(&ar->data_lock);
1693 if (arvif->u.ap.noa_data)
1694 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1696 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1697 arvif->u.ap.noa_data,
1698 arvif->u.ap.noa_len);
1699 spin_unlock_bh(&ar->data_lock);
1703 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1705 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1708 if (ar->htt.target_version_major >= 3) {
1709 /* Since HTT 3.0 there is no separate mgmt tx command */
1710 ret = ath10k_htt_tx(&ar->htt, skb);
1714 if (ieee80211_is_mgmt(hdr->frame_control)) {
1715 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1717 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1718 ATH10K_MAX_NUM_MGMT_PENDING) {
1719 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1724 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1725 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1727 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1729 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1731 ieee80211_is_nullfunc(hdr->frame_control)) {
1732 /* FW does not report tx status properly for NullFunc frames
1733 * unless they are sent through mgmt tx path. mac80211 sends
1734 * those frames when it detects link/beacon loss and depends
1735 * on the tx status to be correct. */
1736 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1738 ret = ath10k_htt_tx(&ar->htt, skb);
1743 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1744 ieee80211_free_txskb(ar->hw, skb);
1748 void ath10k_offchan_tx_purge(struct ath10k *ar)
1750 struct sk_buff *skb;
1753 skb = skb_dequeue(&ar->offchan_tx_queue);
1757 ieee80211_free_txskb(ar->hw, skb);
1761 void ath10k_offchan_tx_work(struct work_struct *work)
1763 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1764 struct ath10k_peer *peer;
1765 struct ieee80211_hdr *hdr;
1766 struct sk_buff *skb;
1767 const u8 *peer_addr;
1771 /* FW requirement: We must create a peer before FW will send out
1772 * an offchannel frame. Otherwise the frame will be stuck and
1773 * never transmitted. We delete the peer upon tx completion.
1774 * It is unlikely that a peer for offchannel tx will already be
1775 * present. However it may be in some rare cases so account for that.
1776 * Otherwise we might remove a legitimate peer and break stuff. */
1779 skb = skb_dequeue(&ar->offchan_tx_queue);
1783 mutex_lock(&ar->conf_mutex);
1785 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
1788 hdr = (struct ieee80211_hdr *)skb->data;
1789 peer_addr = ieee80211_get_DA(hdr);
1790 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
1792 spin_lock_bh(&ar->data_lock);
1793 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1794 spin_unlock_bh(&ar->data_lock);
1797 /* FIXME: should this use ath10k_warn()? */
1798 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1799 peer_addr, vdev_id);
1802 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1804 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1805 peer_addr, vdev_id, ret);
1808 spin_lock_bh(&ar->data_lock);
1809 INIT_COMPLETION(ar->offchan_tx_completed);
1810 ar->offchan_tx_skb = skb;
1811 spin_unlock_bh(&ar->data_lock);
1813 ath10k_tx_htt(ar, skb);
1815 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1818 ath10k_warn("timed out waiting for offchannel skb %p\n",
1822 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1824 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1825 peer_addr, vdev_id, ret);
1828 mutex_unlock(&ar->conf_mutex);
1832 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1834 struct sk_buff *skb;
1837 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1841 ieee80211_free_txskb(ar->hw, skb);
1845 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1847 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1848 struct sk_buff *skb;
1852 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1856 ret = ath10k_wmi_mgmt_tx(ar, skb);
1858 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
1859 ieee80211_free_txskb(ar->hw, skb);
1869 * This gets called if we dont get a heart-beat during scan.
1870 * This may indicate the FW has hung and we need to abort the
1871 * scan manually to prevent cancel_hw_scan() from deadlocking
1873 void ath10k_reset_scan(unsigned long ptr)
1875 struct ath10k *ar = (struct ath10k *)ptr;
1877 spin_lock_bh(&ar->data_lock);
1878 if (!ar->scan.in_progress) {
1879 spin_unlock_bh(&ar->data_lock);
1883 ath10k_warn("scan timeout. resetting. fw issue?\n");
1885 if (ar->scan.is_roc)
1886 ieee80211_remain_on_channel_expired(ar->hw);
1888 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1890 ar->scan.in_progress = false;
1891 complete_all(&ar->scan.completed);
1892 spin_unlock_bh(&ar->data_lock);
1895 static int ath10k_abort_scan(struct ath10k *ar)
1897 struct wmi_stop_scan_arg arg = {
1898 .req_id = 1, /* FIXME */
1899 .req_type = WMI_SCAN_STOP_ONE,
1900 .u.scan_id = ATH10K_SCAN_ID,
1904 lockdep_assert_held(&ar->conf_mutex);
1906 del_timer_sync(&ar->scan.timeout);
1908 spin_lock_bh(&ar->data_lock);
1909 if (!ar->scan.in_progress) {
1910 spin_unlock_bh(&ar->data_lock);
1914 ar->scan.aborting = true;
1915 spin_unlock_bh(&ar->data_lock);
1917 ret = ath10k_wmi_stop_scan(ar, &arg);
1919 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1920 spin_lock_bh(&ar->data_lock);
1921 ar->scan.in_progress = false;
1922 ath10k_offchan_tx_purge(ar);
1923 spin_unlock_bh(&ar->data_lock);
1927 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1929 ath10k_warn("timed out while waiting for scan to stop\n");
1931 /* scan completion may be done right after we timeout here, so let's
1932 * check the in_progress and tell mac80211 scan is completed. if we
1933 * don't do that and FW fails to send us scan completion indication
1934 * then userspace won't be able to scan anymore */
1937 spin_lock_bh(&ar->data_lock);
1938 if (ar->scan.in_progress) {
1939 ath10k_warn("could not stop scan. its still in progress\n");
1940 ar->scan.in_progress = false;
1941 ath10k_offchan_tx_purge(ar);
1944 spin_unlock_bh(&ar->data_lock);
1949 static int ath10k_start_scan(struct ath10k *ar,
1950 const struct wmi_start_scan_arg *arg)
1954 lockdep_assert_held(&ar->conf_mutex);
1956 ret = ath10k_wmi_start_scan(ar, arg);
1960 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1962 ath10k_abort_scan(ar);
1966 /* the scan can complete earlier, before we even
1967 * start the timer. in that case the timer handler
1968 * checks ar->scan.in_progress and bails out if its
1969 * false. Add a 200ms margin to account event/command
1971 mod_timer(&ar->scan.timeout, jiffies +
1972 msecs_to_jiffies(arg->max_scan_time+200));
1976 /**********************/
1977 /* mac80211 callbacks */
1978 /**********************/
1980 static void ath10k_tx(struct ieee80211_hw *hw,
1981 struct ieee80211_tx_control *control,
1982 struct sk_buff *skb)
1984 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1985 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1986 struct ath10k *ar = hw->priv;
1989 /* We should disable CCK RATE due to P2P */
1990 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1991 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1993 /* we must calculate tid before we apply qos workaround
1994 * as we'd lose the qos control field */
1995 tid = ath10k_tx_h_get_tid(hdr);
1996 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
1998 /* it makes no sense to process injected frames like that */
1999 if (info->control.vif &&
2000 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2001 ath10k_tx_h_qos_workaround(hw, control, skb);
2002 ath10k_tx_h_update_wep_key(skb);
2003 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2004 ath10k_tx_h_seq_no(skb);
2007 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
2008 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2009 ATH10K_SKB_CB(skb)->htt.tid = tid;
2011 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2012 spin_lock_bh(&ar->data_lock);
2013 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2014 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2015 spin_unlock_bh(&ar->data_lock);
2017 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2019 skb_queue_tail(&ar->offchan_tx_queue, skb);
2020 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2024 ath10k_tx_htt(ar, skb);
2028 * Initialize various parameters with default vaules.
2030 void ath10k_halt(struct ath10k *ar)
2032 lockdep_assert_held(&ar->conf_mutex);
2034 ath10k_stop_cac(ar);
2035 del_timer_sync(&ar->scan.timeout);
2036 ath10k_offchan_tx_purge(ar);
2037 ath10k_mgmt_over_wmi_tx_purge(ar);
2038 ath10k_peer_cleanup_all(ar);
2039 ath10k_core_stop(ar);
2040 ath10k_hif_power_down(ar);
2042 spin_lock_bh(&ar->data_lock);
2043 if (ar->scan.in_progress) {
2044 del_timer(&ar->scan.timeout);
2045 ar->scan.in_progress = false;
2046 ieee80211_scan_completed(ar->hw, true);
2048 spin_unlock_bh(&ar->data_lock);
2051 static int ath10k_start(struct ieee80211_hw *hw)
2053 struct ath10k *ar = hw->priv;
2056 mutex_lock(&ar->conf_mutex);
2058 if (ar->state != ATH10K_STATE_OFF &&
2059 ar->state != ATH10K_STATE_RESTARTING) {
2064 ret = ath10k_hif_power_up(ar);
2066 ath10k_err("could not init hif (%d)\n", ret);
2067 ar->state = ATH10K_STATE_OFF;
2071 ret = ath10k_core_start(ar);
2073 ath10k_err("could not init core (%d)\n", ret);
2074 ath10k_hif_power_down(ar);
2075 ar->state = ATH10K_STATE_OFF;
2079 if (ar->state == ATH10K_STATE_OFF)
2080 ar->state = ATH10K_STATE_ON;
2081 else if (ar->state == ATH10K_STATE_RESTARTING)
2082 ar->state = ATH10K_STATE_RESTARTED;
2084 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2086 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2089 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2091 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2094 ath10k_regd_update(ar);
2097 mutex_unlock(&ar->conf_mutex);
2101 static void ath10k_stop(struct ieee80211_hw *hw)
2103 struct ath10k *ar = hw->priv;
2105 mutex_lock(&ar->conf_mutex);
2106 if (ar->state == ATH10K_STATE_ON ||
2107 ar->state == ATH10K_STATE_RESTARTED ||
2108 ar->state == ATH10K_STATE_WEDGED)
2111 ar->state = ATH10K_STATE_OFF;
2112 mutex_unlock(&ar->conf_mutex);
2114 ath10k_mgmt_over_wmi_tx_purge(ar);
2116 cancel_work_sync(&ar->offchan_tx_work);
2117 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2118 cancel_work_sync(&ar->restart_work);
2121 static int ath10k_config_ps(struct ath10k *ar)
2123 struct ath10k_vif *arvif;
2126 lockdep_assert_held(&ar->conf_mutex);
2128 list_for_each_entry(arvif, &ar->arvifs, list) {
2129 ret = ath10k_mac_vif_setup_ps(arvif);
2131 ath10k_warn("could not setup powersave (%d)\n", ret);
2139 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2141 struct ath10k *ar = hw->priv;
2142 struct ieee80211_conf *conf = &hw->conf;
2146 mutex_lock(&ar->conf_mutex);
2148 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2149 ath10k_dbg(ATH10K_DBG_MAC,
2150 "mac config channel %d mhz flags 0x%x\n",
2151 conf->chandef.chan->center_freq,
2152 conf->chandef.chan->flags);
2154 spin_lock_bh(&ar->data_lock);
2155 ar->rx_channel = conf->chandef.chan;
2156 spin_unlock_bh(&ar->data_lock);
2158 ath10k_config_radar_detection(ar);
2161 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2162 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2163 hw->conf.power_level);
2165 param = ar->wmi.pdev_param->txpower_limit2g;
2166 ret = ath10k_wmi_pdev_set_param(ar, param,
2167 hw->conf.power_level * 2);
2169 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2170 hw->conf.power_level, ret);
2172 param = ar->wmi.pdev_param->txpower_limit5g;
2173 ret = ath10k_wmi_pdev_set_param(ar, param,
2174 hw->conf.power_level * 2);
2176 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2177 hw->conf.power_level, ret);
2180 if (changed & IEEE80211_CONF_CHANGE_PS)
2181 ath10k_config_ps(ar);
2183 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2184 if (conf->flags & IEEE80211_CONF_MONITOR)
2185 ret = ath10k_monitor_create(ar);
2187 ret = ath10k_monitor_destroy(ar);
2190 mutex_unlock(&ar->conf_mutex);
2196 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2197 * because we will send mgmt frames without CCK. This requirement
2198 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2201 static int ath10k_add_interface(struct ieee80211_hw *hw,
2202 struct ieee80211_vif *vif)
2204 struct ath10k *ar = hw->priv;
2205 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2206 enum wmi_sta_powersave_param param;
2212 mutex_lock(&ar->conf_mutex);
2214 memset(arvif, 0, sizeof(*arvif));
2219 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2220 INIT_LIST_HEAD(&arvif->list);
2222 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2223 ath10k_warn("Only one monitor interface allowed\n");
2228 bit = ffs(ar->free_vdev_map);
2234 arvif->vdev_id = bit - 1;
2235 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2238 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2240 switch (vif->type) {
2241 case NL80211_IFTYPE_UNSPECIFIED:
2242 case NL80211_IFTYPE_STATION:
2243 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2245 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2247 case NL80211_IFTYPE_ADHOC:
2248 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2250 case NL80211_IFTYPE_AP:
2251 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2254 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2256 case NL80211_IFTYPE_MONITOR:
2257 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2264 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
2265 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2267 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2268 arvif->vdev_subtype, vif->addr);
2270 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
2274 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2275 list_add(&arvif->list, &ar->arvifs);
2277 vdev_param = ar->wmi.vdev_param->def_keyid;
2278 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2279 arvif->def_wep_key_idx);
2281 ath10k_warn("Failed to set default keyid: %d\n", ret);
2282 goto err_vdev_delete;
2285 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2286 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2287 ATH10K_HW_TXRX_NATIVE_WIFI);
2288 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2289 if (ret && ret != -EOPNOTSUPP) {
2290 ath10k_warn("Failed to set TX encap: %d\n", ret);
2291 goto err_vdev_delete;
2294 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2295 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2297 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2298 goto err_vdev_delete;
2302 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2303 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2304 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2305 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2308 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2309 goto err_peer_delete;
2312 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2313 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2314 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2317 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2318 goto err_peer_delete;
2321 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2322 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2323 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2326 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2327 goto err_peer_delete;
2331 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2333 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2334 arvif->vdev_id, ret);
2335 goto err_peer_delete;
2338 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2340 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2341 arvif->vdev_id, ret);
2342 goto err_peer_delete;
2345 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2346 ar->monitor_present = true;
2348 mutex_unlock(&ar->conf_mutex);
2352 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2353 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2356 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2357 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2358 list_del(&arvif->list);
2361 mutex_unlock(&ar->conf_mutex);
2366 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2367 struct ieee80211_vif *vif)
2369 struct ath10k *ar = hw->priv;
2370 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2373 mutex_lock(&ar->conf_mutex);
2375 cancel_work_sync(&arvif->wep_key_work);
2377 spin_lock_bh(&ar->data_lock);
2378 if (arvif->beacon) {
2379 dev_kfree_skb_any(arvif->beacon);
2380 arvif->beacon = NULL;
2382 spin_unlock_bh(&ar->data_lock);
2384 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2385 list_del(&arvif->list);
2387 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2388 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2390 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2392 kfree(arvif->u.ap.noa_data);
2395 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2398 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2400 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2402 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2403 ar->monitor_present = false;
2405 ath10k_peer_cleanup(ar, arvif->vdev_id);
2407 mutex_unlock(&ar->conf_mutex);
2411 * FIXME: Has to be verified.
2413 #define SUPPORTED_FILTERS \
2414 (FIF_PROMISC_IN_BSS | \
2419 FIF_BCN_PRBRESP_PROMISC | \
2423 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2424 unsigned int changed_flags,
2425 unsigned int *total_flags,
2428 struct ath10k *ar = hw->priv;
2431 mutex_lock(&ar->conf_mutex);
2433 changed_flags &= SUPPORTED_FILTERS;
2434 *total_flags &= SUPPORTED_FILTERS;
2435 ar->filter_flags = *total_flags;
2437 /* Monitor must not be started if it wasn't created first.
2438 * Promiscuous mode may be started on a non-monitor interface - in
2439 * such case the monitor vdev is not created so starting the
2440 * monitor makes no sense. Since ath10k uses no special RX filters
2441 * (only BSS filter in STA mode) there's no need for any special
2443 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2444 !ar->monitor_enabled && ar->monitor_present) {
2445 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2446 ar->monitor_vdev_id);
2448 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2450 ath10k_warn("Unable to start monitor mode\n");
2451 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2452 ar->monitor_enabled && ar->monitor_present) {
2453 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2454 ar->monitor_vdev_id);
2456 ret = ath10k_monitor_stop(ar);
2458 ath10k_warn("Unable to stop monitor mode\n");
2461 mutex_unlock(&ar->conf_mutex);
2464 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2465 struct ieee80211_vif *vif,
2466 struct ieee80211_bss_conf *info,
2469 struct ath10k *ar = hw->priv;
2470 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2472 u32 vdev_param, pdev_param;
2474 mutex_lock(&ar->conf_mutex);
2476 if (changed & BSS_CHANGED_IBSS)
2477 ath10k_control_ibss(arvif, info, vif->addr);
2479 if (changed & BSS_CHANGED_BEACON_INT) {
2480 arvif->beacon_interval = info->beacon_int;
2481 vdev_param = ar->wmi.vdev_param->beacon_interval;
2482 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2483 arvif->beacon_interval);
2484 ath10k_dbg(ATH10K_DBG_MAC,
2485 "mac vdev %d beacon_interval %d\n",
2486 arvif->vdev_id, arvif->beacon_interval);
2489 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2493 if (changed & BSS_CHANGED_BEACON) {
2494 ath10k_dbg(ATH10K_DBG_MAC,
2495 "vdev %d set beacon tx mode to staggered\n",
2498 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2499 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
2500 WMI_BEACON_STAGGERED_MODE);
2502 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2506 if (changed & BSS_CHANGED_BEACON_INFO) {
2507 arvif->dtim_period = info->dtim_period;
2509 ath10k_dbg(ATH10K_DBG_MAC,
2510 "mac vdev %d dtim_period %d\n",
2511 arvif->vdev_id, arvif->dtim_period);
2513 vdev_param = ar->wmi.vdev_param->dtim_period;
2514 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2515 arvif->dtim_period);
2517 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2521 if (changed & BSS_CHANGED_SSID &&
2522 vif->type == NL80211_IFTYPE_AP) {
2523 arvif->u.ap.ssid_len = info->ssid_len;
2525 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2526 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2529 if (changed & BSS_CHANGED_BSSID) {
2530 if (!is_zero_ether_addr(info->bssid)) {
2531 ath10k_dbg(ATH10K_DBG_MAC,
2532 "mac vdev %d create peer %pM\n",
2533 arvif->vdev_id, info->bssid);
2535 ret = ath10k_peer_create(ar, arvif->vdev_id,
2538 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2539 info->bssid, arvif->vdev_id, ret);
2541 if (vif->type == NL80211_IFTYPE_STATION) {
2543 * this is never erased as we it for crypto key
2544 * clearing; this is FW requirement
2546 memcpy(arvif->u.sta.bssid, info->bssid,
2549 ath10k_dbg(ATH10K_DBG_MAC,
2550 "mac vdev %d start %pM\n",
2551 arvif->vdev_id, info->bssid);
2553 /* FIXME: check return value */
2554 ret = ath10k_vdev_start(arvif);
2558 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2559 * so driver need to store it. It is needed when leaving
2560 * IBSS in order to remove BSSID peer.
2562 if (vif->type == NL80211_IFTYPE_ADHOC)
2563 memcpy(arvif->u.ibss.bssid, info->bssid,
2568 if (changed & BSS_CHANGED_BEACON_ENABLED)
2569 ath10k_control_beaconing(arvif, info);
2571 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2573 if (info->use_cts_prot)
2578 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2579 arvif->vdev_id, cts_prot);
2581 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2582 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2585 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2589 if (changed & BSS_CHANGED_ERP_SLOT) {
2591 if (info->use_short_slot)
2592 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2595 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2597 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2598 arvif->vdev_id, slottime);
2600 vdev_param = ar->wmi.vdev_param->slot_time;
2601 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2604 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2608 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2610 if (info->use_short_preamble)
2611 preamble = WMI_VDEV_PREAMBLE_SHORT;
2613 preamble = WMI_VDEV_PREAMBLE_LONG;
2615 ath10k_dbg(ATH10K_DBG_MAC,
2616 "mac vdev %d preamble %dn",
2617 arvif->vdev_id, preamble);
2619 vdev_param = ar->wmi.vdev_param->preamble;
2620 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2623 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2627 if (changed & BSS_CHANGED_ASSOC) {
2629 ath10k_bss_assoc(hw, vif, info);
2632 mutex_unlock(&ar->conf_mutex);
2635 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2636 struct ieee80211_vif *vif,
2637 struct cfg80211_scan_request *req)
2639 struct ath10k *ar = hw->priv;
2640 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2641 struct wmi_start_scan_arg arg;
2645 mutex_lock(&ar->conf_mutex);
2647 spin_lock_bh(&ar->data_lock);
2648 if (ar->scan.in_progress) {
2649 spin_unlock_bh(&ar->data_lock);
2654 INIT_COMPLETION(ar->scan.started);
2655 INIT_COMPLETION(ar->scan.completed);
2656 ar->scan.in_progress = true;
2657 ar->scan.aborting = false;
2658 ar->scan.is_roc = false;
2659 ar->scan.vdev_id = arvif->vdev_id;
2660 spin_unlock_bh(&ar->data_lock);
2662 memset(&arg, 0, sizeof(arg));
2663 ath10k_wmi_start_scan_init(ar, &arg);
2664 arg.vdev_id = arvif->vdev_id;
2665 arg.scan_id = ATH10K_SCAN_ID;
2668 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2671 arg.ie_len = req->ie_len;
2672 memcpy(arg.ie, req->ie, arg.ie_len);
2676 arg.n_ssids = req->n_ssids;
2677 for (i = 0; i < arg.n_ssids; i++) {
2678 arg.ssids[i].len = req->ssids[i].ssid_len;
2679 arg.ssids[i].ssid = req->ssids[i].ssid;
2682 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2685 if (req->n_channels) {
2686 arg.n_channels = req->n_channels;
2687 for (i = 0; i < arg.n_channels; i++)
2688 arg.channels[i] = req->channels[i]->center_freq;
2691 ret = ath10k_start_scan(ar, &arg);
2693 ath10k_warn("could not start hw scan (%d)\n", ret);
2694 spin_lock_bh(&ar->data_lock);
2695 ar->scan.in_progress = false;
2696 spin_unlock_bh(&ar->data_lock);
2700 mutex_unlock(&ar->conf_mutex);
2704 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2705 struct ieee80211_vif *vif)
2707 struct ath10k *ar = hw->priv;
2710 mutex_lock(&ar->conf_mutex);
2711 ret = ath10k_abort_scan(ar);
2713 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2715 ieee80211_scan_completed(hw, 1 /* aborted */);
2717 mutex_unlock(&ar->conf_mutex);
2720 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2721 struct ath10k_vif *arvif,
2722 enum set_key_cmd cmd,
2723 struct ieee80211_key_conf *key)
2725 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2728 /* 10.1 firmware branch requires default key index to be set to group
2729 * key index after installing it. Otherwise FW/HW Txes corrupted
2730 * frames with multi-vif APs. This is not required for main firmware
2731 * branch (e.g. 636).
2733 * FIXME: This has been tested only in AP. It remains unknown if this
2734 * is required for multi-vif STA interfaces on 10.1 */
2736 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2739 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
2742 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
2745 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2751 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2754 ath10k_warn("failed to set group key as default key: %d\n",
2758 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2759 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2760 struct ieee80211_key_conf *key)
2762 struct ath10k *ar = hw->priv;
2763 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2764 struct ath10k_peer *peer;
2765 const u8 *peer_addr;
2766 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2767 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2770 if (key->keyidx > WMI_MAX_KEY_INDEX)
2773 mutex_lock(&ar->conf_mutex);
2776 peer_addr = sta->addr;
2777 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2778 peer_addr = vif->bss_conf.bssid;
2780 peer_addr = vif->addr;
2782 key->hw_key_idx = key->keyidx;
2784 /* the peer should not disappear in mid-way (unless FW goes awry) since
2785 * we already hold conf_mutex. we just make sure its there now. */
2786 spin_lock_bh(&ar->data_lock);
2787 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2788 spin_unlock_bh(&ar->data_lock);
2791 if (cmd == SET_KEY) {
2792 ath10k_warn("cannot install key for non-existent peer %pM\n",
2797 /* if the peer doesn't exist there is no key to disable
2805 arvif->wep_keys[key->keyidx] = key;
2807 arvif->wep_keys[key->keyidx] = NULL;
2809 if (cmd == DISABLE_KEY)
2810 ath10k_clear_vdev_key(arvif, key);
2813 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2815 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2819 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
2821 spin_lock_bh(&ar->data_lock);
2822 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2823 if (peer && cmd == SET_KEY)
2824 peer->keys[key->keyidx] = key;
2825 else if (peer && cmd == DISABLE_KEY)
2826 peer->keys[key->keyidx] = NULL;
2827 else if (peer == NULL)
2828 /* impossible unless FW goes crazy */
2829 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2830 spin_unlock_bh(&ar->data_lock);
2833 mutex_unlock(&ar->conf_mutex);
2837 static int ath10k_sta_state(struct ieee80211_hw *hw,
2838 struct ieee80211_vif *vif,
2839 struct ieee80211_sta *sta,
2840 enum ieee80211_sta_state old_state,
2841 enum ieee80211_sta_state new_state)
2843 struct ath10k *ar = hw->priv;
2844 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2847 mutex_lock(&ar->conf_mutex);
2849 if (old_state == IEEE80211_STA_NOTEXIST &&
2850 new_state == IEEE80211_STA_NONE &&
2851 vif->type != NL80211_IFTYPE_STATION) {
2853 * New station addition.
2855 ath10k_dbg(ATH10K_DBG_MAC,
2856 "mac vdev %d peer create %pM (new sta)\n",
2857 arvif->vdev_id, sta->addr);
2859 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2861 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
2862 sta->addr, arvif->vdev_id, ret);
2863 } else if ((old_state == IEEE80211_STA_NONE &&
2864 new_state == IEEE80211_STA_NOTEXIST)) {
2866 * Existing station deletion.
2868 ath10k_dbg(ATH10K_DBG_MAC,
2869 "mac vdev %d peer delete %pM (sta gone)\n",
2870 arvif->vdev_id, sta->addr);
2871 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2873 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2874 sta->addr, arvif->vdev_id);
2876 if (vif->type == NL80211_IFTYPE_STATION)
2877 ath10k_bss_disassoc(hw, vif);
2878 } else if (old_state == IEEE80211_STA_AUTH &&
2879 new_state == IEEE80211_STA_ASSOC &&
2880 (vif->type == NL80211_IFTYPE_AP ||
2881 vif->type == NL80211_IFTYPE_ADHOC)) {
2885 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2888 ret = ath10k_station_assoc(ar, arvif, sta);
2890 ath10k_warn("Failed to associate station: %pM\n",
2892 } else if (old_state == IEEE80211_STA_ASSOC &&
2893 new_state == IEEE80211_STA_AUTH &&
2894 (vif->type == NL80211_IFTYPE_AP ||
2895 vif->type == NL80211_IFTYPE_ADHOC)) {
2899 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2902 ret = ath10k_station_disassoc(ar, arvif, sta);
2904 ath10k_warn("Failed to disassociate station: %pM\n",
2908 mutex_unlock(&ar->conf_mutex);
2912 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2913 u16 ac, bool enable)
2915 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2919 lockdep_assert_held(&ar->conf_mutex);
2921 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2925 case IEEE80211_AC_VO:
2926 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2927 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2929 case IEEE80211_AC_VI:
2930 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2931 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2933 case IEEE80211_AC_BE:
2934 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2935 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2937 case IEEE80211_AC_BK:
2938 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2939 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2944 arvif->u.sta.uapsd |= value;
2946 arvif->u.sta.uapsd &= ~value;
2948 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2949 WMI_STA_PS_PARAM_UAPSD,
2950 arvif->u.sta.uapsd);
2952 ath10k_warn("could not set uapsd params %d\n", ret);
2956 if (arvif->u.sta.uapsd)
2957 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2959 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2961 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2962 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2965 ath10k_warn("could not set rx wake param %d\n", ret);
2971 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2972 struct ieee80211_vif *vif, u16 ac,
2973 const struct ieee80211_tx_queue_params *params)
2975 struct ath10k *ar = hw->priv;
2976 struct wmi_wmm_params_arg *p = NULL;
2979 mutex_lock(&ar->conf_mutex);
2982 case IEEE80211_AC_VO:
2983 p = &ar->wmm_params.ac_vo;
2985 case IEEE80211_AC_VI:
2986 p = &ar->wmm_params.ac_vi;
2988 case IEEE80211_AC_BE:
2989 p = &ar->wmm_params.ac_be;
2991 case IEEE80211_AC_BK:
2992 p = &ar->wmm_params.ac_bk;
3001 p->cwmin = params->cw_min;
3002 p->cwmax = params->cw_max;
3003 p->aifs = params->aifs;
3006 * The channel time duration programmed in the HW is in absolute
3007 * microseconds, while mac80211 gives the txop in units of
3010 p->txop = params->txop * 32;
3012 /* FIXME: FW accepts wmm params per hw, not per vif */
3013 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3015 ath10k_warn("could not set wmm params %d\n", ret);
3019 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3021 ath10k_warn("could not set sta uapsd %d\n", ret);
3024 mutex_unlock(&ar->conf_mutex);
3028 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3030 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3031 struct ieee80211_vif *vif,
3032 struct ieee80211_channel *chan,
3034 enum ieee80211_roc_type type)
3036 struct ath10k *ar = hw->priv;
3037 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3038 struct wmi_start_scan_arg arg;
3041 mutex_lock(&ar->conf_mutex);
3043 spin_lock_bh(&ar->data_lock);
3044 if (ar->scan.in_progress) {
3045 spin_unlock_bh(&ar->data_lock);
3050 INIT_COMPLETION(ar->scan.started);
3051 INIT_COMPLETION(ar->scan.completed);
3052 INIT_COMPLETION(ar->scan.on_channel);
3053 ar->scan.in_progress = true;
3054 ar->scan.aborting = false;
3055 ar->scan.is_roc = true;
3056 ar->scan.vdev_id = arvif->vdev_id;
3057 ar->scan.roc_freq = chan->center_freq;
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;
3065 arg.channels[0] = chan->center_freq;
3066 arg.dwell_time_active = duration;
3067 arg.dwell_time_passive = duration;
3068 arg.max_scan_time = 2 * duration;
3069 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3070 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3072 ret = ath10k_start_scan(ar, &arg);
3074 ath10k_warn("could not start roc scan (%d)\n", ret);
3075 spin_lock_bh(&ar->data_lock);
3076 ar->scan.in_progress = false;
3077 spin_unlock_bh(&ar->data_lock);
3081 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3083 ath10k_warn("could not switch to channel for roc scan\n");
3084 ath10k_abort_scan(ar);
3091 mutex_unlock(&ar->conf_mutex);
3095 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3097 struct ath10k *ar = hw->priv;
3099 mutex_lock(&ar->conf_mutex);
3100 ath10k_abort_scan(ar);
3101 mutex_unlock(&ar->conf_mutex);
3107 * Both RTS and Fragmentation threshold are interface-specific
3108 * in ath10k, but device-specific in mac80211.
3111 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3113 struct ath10k *ar = hw->priv;
3114 struct ath10k_vif *arvif;
3117 mutex_lock(&ar->conf_mutex);
3118 list_for_each_entry(arvif, &ar->arvifs, list) {
3119 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3120 arvif->vdev_id, value);
3122 ret = ath10k_mac_set_rts(arvif, value);
3124 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3125 arvif->vdev_id, ret);
3129 mutex_unlock(&ar->conf_mutex);
3134 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3136 struct ath10k *ar = hw->priv;
3137 struct ath10k_vif *arvif;
3140 mutex_lock(&ar->conf_mutex);
3141 list_for_each_entry(arvif, &ar->arvifs, list) {
3142 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3143 arvif->vdev_id, value);
3145 ret = ath10k_mac_set_rts(arvif, value);
3147 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3148 arvif->vdev_id, ret);
3152 mutex_unlock(&ar->conf_mutex);
3157 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3159 struct ath10k *ar = hw->priv;
3163 /* mac80211 doesn't care if we really xmit queued frames or not
3164 * we'll collect those frames either way if we stop/delete vdevs */
3168 mutex_lock(&ar->conf_mutex);
3170 if (ar->state == ATH10K_STATE_WEDGED)
3173 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3176 spin_lock_bh(&ar->htt.tx_lock);
3177 empty = (ar->htt.num_pending_tx == 0);
3178 spin_unlock_bh(&ar->htt.tx_lock);
3180 skip = (ar->state == ATH10K_STATE_WEDGED);
3183 }), ATH10K_FLUSH_TIMEOUT_HZ);
3185 if (ret <= 0 || skip)
3186 ath10k_warn("tx not flushed\n");
3189 mutex_unlock(&ar->conf_mutex);
3192 /* TODO: Implement this function properly
3193 * For now it is needed to reply to Probe Requests in IBSS mode.
3194 * Propably we need this information from FW.
3196 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3202 static int ath10k_suspend(struct ieee80211_hw *hw,
3203 struct cfg80211_wowlan *wowlan)
3205 struct ath10k *ar = hw->priv;
3208 ar->is_target_paused = false;
3210 ret = ath10k_wmi_pdev_suspend_target(ar);
3212 ath10k_warn("could not suspend target (%d)\n", ret);
3216 ret = wait_event_interruptible_timeout(ar->event_queue,
3217 ar->is_target_paused == true,
3220 ath10k_warn("suspend interrupted (%d)\n", ret);
3222 } else if (ret == 0) {
3223 ath10k_warn("suspend timed out - target pause event never came\n");
3227 ret = ath10k_hif_suspend(ar);
3229 ath10k_warn("could not suspend hif (%d)\n", ret);
3235 ret = ath10k_wmi_pdev_resume_target(ar);
3237 ath10k_warn("could not resume target (%d)\n", ret);
3241 static int ath10k_resume(struct ieee80211_hw *hw)
3243 struct ath10k *ar = hw->priv;
3246 ret = ath10k_hif_resume(ar);
3248 ath10k_warn("could not resume hif (%d)\n", ret);
3252 ret = ath10k_wmi_pdev_resume_target(ar);
3254 ath10k_warn("could not resume target (%d)\n", ret);
3262 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3264 struct ath10k *ar = hw->priv;
3266 mutex_lock(&ar->conf_mutex);
3268 /* If device failed to restart it will be in a different state, e.g.
3269 * ATH10K_STATE_WEDGED */
3270 if (ar->state == ATH10K_STATE_RESTARTED) {
3271 ath10k_info("device successfully recovered\n");
3272 ar->state = ATH10K_STATE_ON;
3275 mutex_unlock(&ar->conf_mutex);
3278 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3279 struct survey_info *survey)
3281 struct ath10k *ar = hw->priv;
3282 struct ieee80211_supported_band *sband;
3283 struct survey_info *ar_survey = &ar->survey[idx];
3286 mutex_lock(&ar->conf_mutex);
3288 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3289 if (sband && idx >= sband->n_channels) {
3290 idx -= sband->n_channels;
3295 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3297 if (!sband || idx >= sband->n_channels) {
3302 spin_lock_bh(&ar->data_lock);
3303 memcpy(survey, ar_survey, sizeof(*survey));
3304 spin_unlock_bh(&ar->data_lock);
3306 survey->channel = &sband->channels[idx];
3309 mutex_unlock(&ar->conf_mutex);
3313 static const struct ieee80211_ops ath10k_ops = {
3315 .start = ath10k_start,
3316 .stop = ath10k_stop,
3317 .config = ath10k_config,
3318 .add_interface = ath10k_add_interface,
3319 .remove_interface = ath10k_remove_interface,
3320 .configure_filter = ath10k_configure_filter,
3321 .bss_info_changed = ath10k_bss_info_changed,
3322 .hw_scan = ath10k_hw_scan,
3323 .cancel_hw_scan = ath10k_cancel_hw_scan,
3324 .set_key = ath10k_set_key,
3325 .sta_state = ath10k_sta_state,
3326 .conf_tx = ath10k_conf_tx,
3327 .remain_on_channel = ath10k_remain_on_channel,
3328 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3329 .set_rts_threshold = ath10k_set_rts_threshold,
3330 .set_frag_threshold = ath10k_set_frag_threshold,
3331 .flush = ath10k_flush,
3332 .tx_last_beacon = ath10k_tx_last_beacon,
3333 .restart_complete = ath10k_restart_complete,
3334 .get_survey = ath10k_get_survey,
3336 .suspend = ath10k_suspend,
3337 .resume = ath10k_resume,
3341 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3342 .bitrate = (_rate), \
3343 .flags = (_flags), \
3344 .hw_value = (_rateid), \
3347 #define CHAN2G(_channel, _freq, _flags) { \
3348 .band = IEEE80211_BAND_2GHZ, \
3349 .hw_value = (_channel), \
3350 .center_freq = (_freq), \
3351 .flags = (_flags), \
3352 .max_antenna_gain = 0, \
3356 #define CHAN5G(_channel, _freq, _flags) { \
3357 .band = IEEE80211_BAND_5GHZ, \
3358 .hw_value = (_channel), \
3359 .center_freq = (_freq), \
3360 .flags = (_flags), \
3361 .max_antenna_gain = 0, \
3365 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3375 CHAN2G(10, 2457, 0),
3376 CHAN2G(11, 2462, 0),
3377 CHAN2G(12, 2467, 0),
3378 CHAN2G(13, 2472, 0),
3379 CHAN2G(14, 2484, 0),
3382 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
3383 CHAN5G(36, 5180, 0),
3384 CHAN5G(40, 5200, 0),
3385 CHAN5G(44, 5220, 0),
3386 CHAN5G(48, 5240, 0),
3387 CHAN5G(52, 5260, 0),
3388 CHAN5G(56, 5280, 0),
3389 CHAN5G(60, 5300, 0),
3390 CHAN5G(64, 5320, 0),
3391 CHAN5G(100, 5500, 0),
3392 CHAN5G(104, 5520, 0),
3393 CHAN5G(108, 5540, 0),
3394 CHAN5G(112, 5560, 0),
3395 CHAN5G(116, 5580, 0),
3396 CHAN5G(120, 5600, 0),
3397 CHAN5G(124, 5620, 0),
3398 CHAN5G(128, 5640, 0),
3399 CHAN5G(132, 5660, 0),
3400 CHAN5G(136, 5680, 0),
3401 CHAN5G(140, 5700, 0),
3402 CHAN5G(149, 5745, 0),
3403 CHAN5G(153, 5765, 0),
3404 CHAN5G(157, 5785, 0),
3405 CHAN5G(161, 5805, 0),
3406 CHAN5G(165, 5825, 0),
3409 static struct ieee80211_rate ath10k_rates[] = {
3411 RATETAB_ENT(10, 0x82, 0),
3412 RATETAB_ENT(20, 0x84, 0),
3413 RATETAB_ENT(55, 0x8b, 0),
3414 RATETAB_ENT(110, 0x96, 0),
3416 RATETAB_ENT(60, 0x0c, 0),
3417 RATETAB_ENT(90, 0x12, 0),
3418 RATETAB_ENT(120, 0x18, 0),
3419 RATETAB_ENT(180, 0x24, 0),
3420 RATETAB_ENT(240, 0x30, 0),
3421 RATETAB_ENT(360, 0x48, 0),
3422 RATETAB_ENT(480, 0x60, 0),
3423 RATETAB_ENT(540, 0x6c, 0),
3426 #define ath10k_a_rates (ath10k_rates + 4)
3427 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3428 #define ath10k_g_rates (ath10k_rates + 0)
3429 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3431 struct ath10k *ath10k_mac_create(void)
3433 struct ieee80211_hw *hw;
3436 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3446 void ath10k_mac_destroy(struct ath10k *ar)
3448 ieee80211_free_hw(ar->hw);
3451 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3454 .types = BIT(NL80211_IFTYPE_STATION)
3455 | BIT(NL80211_IFTYPE_P2P_CLIENT)
3459 .types = BIT(NL80211_IFTYPE_P2P_GO)
3463 .types = BIT(NL80211_IFTYPE_AP)
3467 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
3468 static const struct ieee80211_iface_limit ath10k_if_dfs_limits[] = {
3471 .types = BIT(NL80211_IFTYPE_AP)
3476 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
3478 .limits = ath10k_if_limits,
3479 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3480 .max_interfaces = 8,
3481 .num_different_channels = 1,
3482 .beacon_int_infra_match = true,
3484 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
3486 .limits = ath10k_if_dfs_limits,
3487 .n_limits = ARRAY_SIZE(ath10k_if_dfs_limits),
3488 .max_interfaces = 8,
3489 .num_different_channels = 1,
3490 .beacon_int_infra_match = true,
3491 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
3492 BIT(NL80211_CHAN_WIDTH_20) |
3493 BIT(NL80211_CHAN_WIDTH_40) |
3494 BIT(NL80211_CHAN_WIDTH_80),
3499 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3501 struct ieee80211_sta_vht_cap vht_cap = {0};
3505 vht_cap.vht_supported = 1;
3506 vht_cap.cap = ar->vht_cap_info;
3509 for (i = 0; i < 8; i++) {
3510 if (i < ar->num_rf_chains)
3511 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3513 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3516 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3517 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3522 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3525 struct ieee80211_sta_ht_cap ht_cap = {0};
3527 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3530 ht_cap.ht_supported = 1;
3531 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3532 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3533 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3534 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3535 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3537 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3538 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3540 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3541 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3543 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3546 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3547 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3552 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3553 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3555 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3558 stbc = ar->ht_cap_info;
3559 stbc &= WMI_HT_CAP_RX_STBC;
3560 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3561 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3562 stbc &= IEEE80211_HT_CAP_RX_STBC;
3567 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3568 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3570 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3571 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3573 /* max AMSDU is implicitly taken from vht_cap_info */
3574 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3575 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3577 for (i = 0; i < ar->num_rf_chains; i++)
3578 ht_cap.mcs.rx_mask[i] = 0xFF;
3580 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3586 static void ath10k_get_arvif_iter(void *data, u8 *mac,
3587 struct ieee80211_vif *vif)
3589 struct ath10k_vif_iter *arvif_iter = data;
3590 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3592 if (arvif->vdev_id == arvif_iter->vdev_id)
3593 arvif_iter->arvif = arvif;
3596 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3598 struct ath10k_vif_iter arvif_iter;
3601 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3602 arvif_iter.vdev_id = vdev_id;
3604 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3605 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3607 ath10k_get_arvif_iter,
3609 if (!arvif_iter.arvif) {
3610 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3614 return arvif_iter.arvif;
3617 int ath10k_mac_register(struct ath10k *ar)
3619 struct ieee80211_supported_band *band;
3620 struct ieee80211_sta_vht_cap vht_cap;
3621 struct ieee80211_sta_ht_cap ht_cap;
3625 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3627 SET_IEEE80211_DEV(ar->hw, ar->dev);
3629 ht_cap = ath10k_get_ht_cap(ar);
3630 vht_cap = ath10k_create_vht_cap(ar);
3632 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3633 channels = kmemdup(ath10k_2ghz_channels,
3634 sizeof(ath10k_2ghz_channels),
3641 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3642 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3643 band->channels = channels;
3644 band->n_bitrates = ath10k_g_rates_size;
3645 band->bitrates = ath10k_g_rates;
3646 band->ht_cap = ht_cap;
3648 /* vht is not supported in 2.4 GHz */
3650 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3653 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3654 channels = kmemdup(ath10k_5ghz_channels,
3655 sizeof(ath10k_5ghz_channels),
3662 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3663 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3664 band->channels = channels;
3665 band->n_bitrates = ath10k_a_rates_size;
3666 band->bitrates = ath10k_a_rates;
3667 band->ht_cap = ht_cap;
3668 band->vht_cap = vht_cap;
3669 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3672 ar->hw->wiphy->interface_modes =
3673 BIT(NL80211_IFTYPE_STATION) |
3674 BIT(NL80211_IFTYPE_ADHOC) |
3675 BIT(NL80211_IFTYPE_AP) |
3676 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3677 BIT(NL80211_IFTYPE_P2P_GO);
3679 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3680 IEEE80211_HW_SUPPORTS_PS |
3681 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3682 IEEE80211_HW_SUPPORTS_UAPSD |
3683 IEEE80211_HW_MFP_CAPABLE |
3684 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3685 IEEE80211_HW_HAS_RATE_CONTROL |
3686 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3687 IEEE80211_HW_WANT_MONITOR_VIF |
3688 IEEE80211_HW_AP_LINK_PS;
3690 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3691 * bytes is used for padding/alignment if necessary. */
3692 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3694 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3695 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3697 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3698 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3699 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3702 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3703 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3705 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3707 ar->hw->channel_change_time = 5000;
3708 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3710 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3711 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3713 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3715 * on LL hardware queues are managed entirely by the FW
3716 * so we only advertise to mac we can do the queues thing
3720 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
3721 ar->hw->wiphy->n_iface_combinations = ARRAY_SIZE(ath10k_if_comb);
3723 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3725 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
3726 /* Init ath dfs pattern detector */
3727 ar->ath_common.debug_mask = ATH_DBG_DFS;
3728 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
3731 if (!ar->dfs_detector)
3732 ath10k_warn("dfs pattern detector init failed\n");
3735 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3736 ath10k_reg_notifier);
3738 ath10k_err("Regulatory initialization failed\n");
3742 ret = ieee80211_register_hw(ar->hw);
3744 ath10k_err("ieee80211 registration failed: %d\n", ret);
3748 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3749 ret = regulatory_hint(ar->hw->wiphy,
3750 ar->ath_common.regulatory.alpha2);
3752 goto err_unregister;
3758 ieee80211_unregister_hw(ar->hw);
3760 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3761 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3766 void ath10k_mac_unregister(struct ath10k *ar)
3768 ieee80211_unregister_hw(ar->hw);
3770 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
3771 ar->dfs_detector->exit(ar->dfs_detector);
3773 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3774 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3776 SET_IEEE80211_DEV(ar->hw, NULL);