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("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);
335 spin_lock_bh(&ar->data_lock);
337 spin_unlock_bh(&ar->data_lock);
342 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
344 struct ath10k *ar = arvif->ar;
348 param = ar->wmi.pdev_param->sta_kickout_th;
349 ret = ath10k_wmi_pdev_set_param(ar, param,
350 ATH10K_KICKOUT_THRESHOLD);
352 ath10k_warn("Failed to set kickout threshold: %d\n", ret);
356 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
357 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
358 ATH10K_KEEPALIVE_MIN_IDLE);
360 ath10k_warn("Failed to set keepalive minimum idle time : %d\n",
365 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
366 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
367 ATH10K_KEEPALIVE_MAX_IDLE);
369 ath10k_warn("Failed to set keepalive maximum idle time: %d\n",
374 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
375 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
376 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
378 ath10k_warn("Failed to set keepalive maximum unresponsive time: %d\n",
386 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
388 struct ath10k *ar = arvif->ar;
391 if (value != 0xFFFFFFFF)
392 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
395 vdev_param = ar->wmi.vdev_param->rts_threshold;
396 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
399 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
401 struct ath10k *ar = arvif->ar;
404 if (value != 0xFFFFFFFF)
405 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
406 ATH10K_FRAGMT_THRESHOLD_MIN,
407 ATH10K_FRAGMT_THRESHOLD_MAX);
409 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
410 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
413 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
417 lockdep_assert_held(&ar->conf_mutex);
419 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
423 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
427 spin_lock_bh(&ar->data_lock);
429 spin_unlock_bh(&ar->data_lock);
434 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
436 struct ath10k_peer *peer, *tmp;
438 lockdep_assert_held(&ar->conf_mutex);
440 spin_lock_bh(&ar->data_lock);
441 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
442 if (peer->vdev_id != vdev_id)
445 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
446 peer->addr, vdev_id);
448 list_del(&peer->list);
452 spin_unlock_bh(&ar->data_lock);
455 static void ath10k_peer_cleanup_all(struct ath10k *ar)
457 struct ath10k_peer *peer, *tmp;
459 lockdep_assert_held(&ar->conf_mutex);
461 spin_lock_bh(&ar->data_lock);
462 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
463 list_del(&peer->list);
467 spin_unlock_bh(&ar->data_lock);
470 /************************/
471 /* Interface management */
472 /************************/
474 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
478 lockdep_assert_held(&ar->conf_mutex);
480 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
481 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
488 static int ath10k_vdev_start(struct ath10k_vif *arvif)
490 struct ath10k *ar = arvif->ar;
491 struct cfg80211_chan_def *chandef = &ar->chandef;
492 struct wmi_vdev_start_request_arg arg = {};
495 lockdep_assert_held(&ar->conf_mutex);
497 reinit_completion(&ar->vdev_setup_done);
499 arg.vdev_id = arvif->vdev_id;
500 arg.dtim_period = arvif->dtim_period;
501 arg.bcn_intval = arvif->beacon_interval;
503 arg.channel.freq = chandef->chan->center_freq;
504 arg.channel.band_center_freq1 = chandef->center_freq1;
505 arg.channel.mode = chan_to_phymode(chandef);
507 arg.channel.min_power = 0;
508 arg.channel.max_power = chandef->chan->max_power * 2;
509 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
510 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
512 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
513 arg.ssid = arvif->u.ap.ssid;
514 arg.ssid_len = arvif->u.ap.ssid_len;
515 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
517 /* For now allow DFS for AP mode */
518 arg.channel.chan_radar =
519 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
520 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
521 arg.ssid = arvif->vif->bss_conf.ssid;
522 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
525 ath10k_dbg(ATH10K_DBG_MAC,
526 "mac vdev %d start center_freq %d phymode %s\n",
527 arg.vdev_id, arg.channel.freq,
528 ath10k_wmi_phymode_str(arg.channel.mode));
530 ret = ath10k_wmi_vdev_start(ar, &arg);
532 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
536 ret = ath10k_vdev_setup_sync(ar);
538 ath10k_warn("vdev setup failed %d\n", ret);
545 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
547 struct ath10k *ar = arvif->ar;
550 lockdep_assert_held(&ar->conf_mutex);
552 reinit_completion(&ar->vdev_setup_done);
554 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
556 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
560 ret = ath10k_vdev_setup_sync(ar);
562 ath10k_warn("vdev setup failed %d\n", ret);
569 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
571 struct cfg80211_chan_def *chandef = &ar->chandef;
572 struct ieee80211_channel *channel = chandef->chan;
573 struct wmi_vdev_start_request_arg arg = {};
576 lockdep_assert_held(&ar->conf_mutex);
578 if (!ar->monitor_present) {
579 ath10k_warn("mac montor stop -- monitor is not present\n");
583 arg.vdev_id = vdev_id;
584 arg.channel.freq = channel->center_freq;
585 arg.channel.band_center_freq1 = chandef->center_freq1;
587 /* TODO setup this dynamically, what in case we
588 don't have any vifs? */
589 arg.channel.mode = chan_to_phymode(chandef);
590 arg.channel.chan_radar =
591 !!(channel->flags & IEEE80211_CHAN_RADAR);
593 arg.channel.min_power = 0;
594 arg.channel.max_power = channel->max_power * 2;
595 arg.channel.max_reg_power = channel->max_reg_power * 2;
596 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
598 ret = ath10k_wmi_vdev_start(ar, &arg);
600 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
604 ret = ath10k_vdev_setup_sync(ar);
606 ath10k_warn("Monitor vdev setup failed %d\n", ret);
610 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
612 ath10k_warn("Monitor vdev up failed: %d\n", ret);
616 ar->monitor_vdev_id = vdev_id;
617 ar->monitor_enabled = true;
622 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
624 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
629 static int ath10k_monitor_stop(struct ath10k *ar)
633 lockdep_assert_held(&ar->conf_mutex);
635 if (!ar->monitor_present) {
636 ath10k_warn("mac montor stop -- monitor is not present\n");
640 if (!ar->monitor_enabled) {
641 ath10k_warn("mac montor stop -- monitor is not enabled\n");
645 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
647 ath10k_warn("Monitor vdev down failed: %d\n", ret);
649 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
651 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
653 ret = ath10k_vdev_setup_sync(ar);
655 ath10k_warn("Monitor_down sync failed: %d\n", ret);
657 ar->monitor_enabled = false;
661 static int ath10k_monitor_create(struct ath10k *ar)
665 lockdep_assert_held(&ar->conf_mutex);
667 if (ar->monitor_present) {
668 ath10k_warn("Monitor mode already enabled\n");
672 bit = ffs(ar->free_vdev_map);
674 ath10k_warn("No free VDEV slots\n");
678 ar->monitor_vdev_id = bit - 1;
679 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
681 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
682 WMI_VDEV_TYPE_MONITOR,
685 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
689 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
690 ar->monitor_vdev_id);
692 ar->monitor_present = true;
697 * Restore the ID to the global map.
699 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
703 static int ath10k_monitor_destroy(struct ath10k *ar)
707 lockdep_assert_held(&ar->conf_mutex);
709 if (!ar->monitor_present)
712 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
714 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
718 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
719 ar->monitor_present = false;
721 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
722 ar->monitor_vdev_id);
726 static int ath10k_start_cac(struct ath10k *ar)
730 lockdep_assert_held(&ar->conf_mutex);
732 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
734 ret = ath10k_monitor_create(ar);
736 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
740 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
742 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
743 ath10k_monitor_destroy(ar);
747 ath10k_dbg(ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
748 ar->monitor_vdev_id);
753 static int ath10k_stop_cac(struct ath10k *ar)
755 lockdep_assert_held(&ar->conf_mutex);
757 /* CAC is not running - do nothing */
758 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
761 ath10k_monitor_stop(ar);
762 ath10k_monitor_destroy(ar);
763 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
765 ath10k_dbg(ATH10K_DBG_MAC, "mac cac finished\n");
770 static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state)
773 case NL80211_DFS_USABLE:
775 case NL80211_DFS_UNAVAILABLE:
776 return "UNAVAILABLE";
777 case NL80211_DFS_AVAILABLE:
785 static void ath10k_config_radar_detection(struct ath10k *ar)
787 struct ieee80211_channel *chan = ar->hw->conf.chandef.chan;
788 bool radar = ar->hw->conf.radar_enabled;
789 bool chan_radar = !!(chan->flags & IEEE80211_CHAN_RADAR);
790 enum nl80211_dfs_state dfs_state = chan->dfs_state;
793 lockdep_assert_held(&ar->conf_mutex);
795 ath10k_dbg(ATH10K_DBG_MAC,
796 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
797 chan->center_freq, radar, chan_radar,
798 ath10k_dfs_state(dfs_state));
801 * It's safe to call it even if CAC is not started.
802 * This call here guarantees changing channel, etc. will stop CAC.
812 if (dfs_state != NL80211_DFS_USABLE)
815 ret = ath10k_start_cac(ar);
818 * Not possible to start CAC on current channel so starting
819 * radiation is not allowed, make this channel DFS_UNAVAILABLE
820 * by indicating that radar was detected.
822 ath10k_warn("failed to start CAC (%d)\n", ret);
823 ieee80211_radar_detected(ar->hw);
827 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
828 struct ieee80211_bss_conf *info)
832 lockdep_assert_held(&arvif->ar->conf_mutex);
834 if (!info->enable_beacon) {
835 ath10k_vdev_stop(arvif);
837 arvif->is_started = false;
838 arvif->is_up = false;
840 spin_lock_bh(&arvif->ar->data_lock);
842 ath10k_skb_unmap(arvif->ar->dev, arvif->beacon);
843 dev_kfree_skb_any(arvif->beacon);
845 arvif->beacon = NULL;
846 arvif->beacon_sent = false;
848 spin_unlock_bh(&arvif->ar->data_lock);
853 arvif->tx_seq_no = 0x1000;
855 ret = ath10k_vdev_start(arvif);
860 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
862 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
865 ath10k_warn("Failed to bring up VDEV: %d\n",
867 ath10k_vdev_stop(arvif);
871 arvif->is_started = true;
874 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
877 static void ath10k_control_ibss(struct ath10k_vif *arvif,
878 struct ieee80211_bss_conf *info,
879 const u8 self_peer[ETH_ALEN])
884 lockdep_assert_held(&arvif->ar->conf_mutex);
886 if (!info->ibss_joined) {
887 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
889 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
890 self_peer, arvif->vdev_id, ret);
892 if (is_zero_ether_addr(arvif->bssid))
895 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
898 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
899 arvif->bssid, arvif->vdev_id, ret);
903 memset(arvif->bssid, 0, ETH_ALEN);
908 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
910 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
911 self_peer, arvif->vdev_id, ret);
915 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
916 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
917 ATH10K_DEFAULT_ATIM);
919 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
920 arvif->vdev_id, ret);
924 * Review this when mac80211 gains per-interface powersave support.
926 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
928 struct ath10k *ar = arvif->ar;
929 struct ieee80211_conf *conf = &ar->hw->conf;
930 enum wmi_sta_powersave_param param;
931 enum wmi_sta_ps_mode psmode;
934 lockdep_assert_held(&arvif->ar->conf_mutex);
936 if (arvif->vif->type != NL80211_IFTYPE_STATION)
939 if (conf->flags & IEEE80211_CONF_PS) {
940 psmode = WMI_STA_PS_MODE_ENABLED;
941 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
943 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
944 conf->dynamic_ps_timeout);
946 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
951 psmode = WMI_STA_PS_MODE_DISABLED;
954 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
955 arvif->vdev_id, psmode ? "enable" : "disable");
957 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
959 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
960 psmode, arvif->vdev_id);
967 /**********************/
968 /* Station management */
969 /**********************/
971 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
972 struct ath10k_vif *arvif,
973 struct ieee80211_sta *sta,
974 struct ieee80211_bss_conf *bss_conf,
975 struct wmi_peer_assoc_complete_arg *arg)
977 lockdep_assert_held(&ar->conf_mutex);
979 memcpy(arg->addr, sta->addr, ETH_ALEN);
980 arg->vdev_id = arvif->vdev_id;
981 arg->peer_aid = sta->aid;
982 arg->peer_flags |= WMI_PEER_AUTH;
984 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
986 * Seems FW have problems with Power Save in STA
987 * mode when we setup this parameter to high (eg. 5).
988 * Often we see that FW don't send NULL (with clean P flags)
989 * frame even there is info about buffered frames in beacons.
990 * Sometimes we have to wait more than 10 seconds before FW
991 * will wakeup. Often sending one ping from AP to our device
992 * just fail (more than 50%).
994 * Seems setting this FW parameter to 1 couse FW
995 * will check every beacon and will wakup immediately
996 * after detection buffered data.
998 arg->peer_listen_intval = 1;
1000 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1002 arg->peer_num_spatial_streams = 1;
1005 * The assoc capabilities are available only in managed mode.
1007 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
1008 arg->peer_caps = bss_conf->assoc_capability;
1011 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1012 struct ath10k_vif *arvif,
1013 struct wmi_peer_assoc_complete_arg *arg)
1015 struct ieee80211_vif *vif = arvif->vif;
1016 struct ieee80211_bss_conf *info = &vif->bss_conf;
1017 struct cfg80211_bss *bss;
1018 const u8 *rsnie = NULL;
1019 const u8 *wpaie = NULL;
1021 lockdep_assert_held(&ar->conf_mutex);
1023 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1024 info->bssid, NULL, 0, 0, 0);
1026 const struct cfg80211_bss_ies *ies;
1029 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1031 ies = rcu_dereference(bss->ies);
1033 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1034 WLAN_OUI_TYPE_MICROSOFT_WPA,
1038 cfg80211_put_bss(ar->hw->wiphy, bss);
1041 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1042 if (rsnie || wpaie) {
1043 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1044 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1048 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1049 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1053 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1054 struct ieee80211_sta *sta,
1055 struct wmi_peer_assoc_complete_arg *arg)
1057 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1058 const struct ieee80211_supported_band *sband;
1059 const struct ieee80211_rate *rates;
1063 lockdep_assert_held(&ar->conf_mutex);
1065 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1066 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1067 rates = sband->bitrates;
1069 rateset->num_rates = 0;
1071 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1072 if (!(ratemask & 1))
1075 rateset->rates[rateset->num_rates] = rates->hw_value;
1076 rateset->num_rates++;
1080 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1081 struct ieee80211_sta *sta,
1082 struct wmi_peer_assoc_complete_arg *arg)
1084 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1088 lockdep_assert_held(&ar->conf_mutex);
1090 if (!ht_cap->ht_supported)
1093 arg->peer_flags |= WMI_PEER_HT;
1094 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1095 ht_cap->ampdu_factor)) - 1;
1097 arg->peer_mpdu_density =
1098 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1100 arg->peer_ht_caps = ht_cap->cap;
1101 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1103 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1104 arg->peer_flags |= WMI_PEER_LDPC;
1106 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1107 arg->peer_flags |= WMI_PEER_40MHZ;
1108 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1111 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1112 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1114 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1115 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1117 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1118 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1119 arg->peer_flags |= WMI_PEER_STBC;
1122 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1124 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1125 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1126 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1127 arg->peer_rate_caps |= stbc;
1128 arg->peer_flags |= WMI_PEER_STBC;
1131 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1132 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1134 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
1135 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1136 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
1137 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
1138 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
1139 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
1142 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1143 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1144 else if (ht_cap->mcs.rx_mask[1])
1145 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1147 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1148 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1149 arg->peer_ht_rates.rates[n++] = i;
1152 * This is a workaround for HT-enabled STAs which break the spec
1153 * and have no HT capabilities RX mask (no HT RX MCS map).
1155 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1156 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1158 * Firmware asserts if such situation occurs.
1161 arg->peer_ht_rates.num_rates = 8;
1162 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1163 arg->peer_ht_rates.rates[i] = i;
1165 arg->peer_ht_rates.num_rates = n;
1166 arg->peer_num_spatial_streams = sta->rx_nss;
1169 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1171 arg->peer_ht_rates.num_rates,
1172 arg->peer_num_spatial_streams);
1175 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1176 struct ath10k_vif *arvif,
1177 struct ieee80211_sta *sta)
1183 lockdep_assert_held(&ar->conf_mutex);
1185 if (sta->wme && sta->uapsd_queues) {
1186 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1187 sta->uapsd_queues, sta->max_sp);
1189 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1190 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1191 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1192 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1193 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1194 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1195 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1196 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1197 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1198 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1199 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1200 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1203 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1204 max_sp = sta->max_sp;
1206 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1208 WMI_AP_PS_PEER_PARAM_UAPSD,
1211 ath10k_warn("failed to set ap ps peer param uapsd: %d\n",
1216 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1218 WMI_AP_PS_PEER_PARAM_MAX_SP,
1221 ath10k_warn("failed to set ap ps peer param max sp: %d\n",
1226 /* TODO setup this based on STA listen interval and
1227 beacon interval. Currently we don't know
1228 sta->listen_interval - mac80211 patch required.
1229 Currently use 10 seconds */
1230 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1231 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME, 10);
1233 ath10k_warn("failed to set ap ps peer param ageout time: %d\n",
1242 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1243 struct ieee80211_sta *sta,
1244 struct wmi_peer_assoc_complete_arg *arg)
1246 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1249 if (!vht_cap->vht_supported)
1252 arg->peer_flags |= WMI_PEER_VHT;
1253 arg->peer_vht_caps = vht_cap->cap;
1256 ampdu_factor = (vht_cap->cap &
1257 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1258 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1260 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1261 * zero in VHT IE. Using it would result in degraded throughput.
1262 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1263 * it if VHT max_mpdu is smaller. */
1264 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1265 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1266 ampdu_factor)) - 1);
1268 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1269 arg->peer_flags |= WMI_PEER_80MHZ;
1271 arg->peer_vht_rates.rx_max_rate =
1272 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1273 arg->peer_vht_rates.rx_mcs_set =
1274 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1275 arg->peer_vht_rates.tx_max_rate =
1276 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1277 arg->peer_vht_rates.tx_mcs_set =
1278 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1280 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1281 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1284 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1285 struct ath10k_vif *arvif,
1286 struct ieee80211_sta *sta,
1287 struct ieee80211_bss_conf *bss_conf,
1288 struct wmi_peer_assoc_complete_arg *arg)
1290 switch (arvif->vdev_type) {
1291 case WMI_VDEV_TYPE_AP:
1293 arg->peer_flags |= WMI_PEER_QOS;
1295 if (sta->wme && sta->uapsd_queues) {
1296 arg->peer_flags |= WMI_PEER_APSD;
1297 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1300 case WMI_VDEV_TYPE_STA:
1302 arg->peer_flags |= WMI_PEER_QOS;
1309 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1310 struct ath10k_vif *arvif,
1311 struct ieee80211_sta *sta,
1312 struct wmi_peer_assoc_complete_arg *arg)
1314 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1316 switch (ar->hw->conf.chandef.chan->band) {
1317 case IEEE80211_BAND_2GHZ:
1318 if (sta->ht_cap.ht_supported) {
1319 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1320 phymode = MODE_11NG_HT40;
1322 phymode = MODE_11NG_HT20;
1328 case IEEE80211_BAND_5GHZ:
1332 if (sta->vht_cap.vht_supported) {
1333 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1334 phymode = MODE_11AC_VHT80;
1335 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1336 phymode = MODE_11AC_VHT40;
1337 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1338 phymode = MODE_11AC_VHT20;
1339 } else if (sta->ht_cap.ht_supported) {
1340 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1341 phymode = MODE_11NA_HT40;
1343 phymode = MODE_11NA_HT20;
1353 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1354 sta->addr, ath10k_wmi_phymode_str(phymode));
1356 arg->peer_phymode = phymode;
1357 WARN_ON(phymode == MODE_UNKNOWN);
1360 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1361 struct ath10k_vif *arvif,
1362 struct ieee80211_sta *sta,
1363 struct ieee80211_bss_conf *bss_conf,
1364 struct wmi_peer_assoc_complete_arg *arg)
1366 lockdep_assert_held(&ar->conf_mutex);
1368 memset(arg, 0, sizeof(*arg));
1370 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, arg);
1371 ath10k_peer_assoc_h_crypto(ar, arvif, arg);
1372 ath10k_peer_assoc_h_rates(ar, sta, arg);
1373 ath10k_peer_assoc_h_ht(ar, sta, arg);
1374 ath10k_peer_assoc_h_vht(ar, sta, arg);
1375 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, arg);
1376 ath10k_peer_assoc_h_phymode(ar, arvif, sta, arg);
1381 /* can be called only in mac80211 callbacks due to `key_count` usage */
1382 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1383 struct ieee80211_vif *vif,
1384 struct ieee80211_bss_conf *bss_conf)
1386 struct ath10k *ar = hw->priv;
1387 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1388 struct wmi_peer_assoc_complete_arg peer_arg;
1389 struct ieee80211_sta *ap_sta;
1392 lockdep_assert_held(&ar->conf_mutex);
1396 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1398 ath10k_warn("Failed to find station entry for %pM\n",
1404 ret = ath10k_peer_assoc_prepare(ar, arvif, ap_sta,
1405 bss_conf, &peer_arg);
1407 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1408 bss_conf->bssid, ret);
1415 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1417 ath10k_warn("Peer assoc failed for %pM\n: %d",
1418 bss_conf->bssid, ret);
1422 ath10k_dbg(ATH10K_DBG_MAC,
1423 "mac vdev %d up (associated) bssid %pM aid %d\n",
1424 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1426 arvif->aid = bss_conf->aid;
1427 memcpy(arvif->bssid, bss_conf->bssid, ETH_ALEN);
1429 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1431 ath10k_warn("VDEV: %d up failed: ret %d\n",
1432 arvif->vdev_id, ret);
1436 arvif->is_up = true;
1442 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1443 struct ieee80211_vif *vif)
1445 struct ath10k *ar = hw->priv;
1446 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1449 lockdep_assert_held(&ar->conf_mutex);
1452 * For some reason, calling VDEV-DOWN before VDEV-STOP
1453 * makes the FW to send frames via HTT after disassociation.
1454 * No idea why this happens, even though VDEV-DOWN is supposed
1455 * to be analogous to link down, so just stop the VDEV.
1457 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1460 /* FIXME: check return value */
1461 ret = ath10k_vdev_stop(arvif);
1464 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1465 * report beacons from previously associated network through HTT.
1466 * This in turn would spam mac80211 WARN_ON if we bring down all
1467 * interfaces as it expects there is no rx when no interface is
1470 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1472 /* FIXME: why don't we print error if wmi call fails? */
1473 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1475 arvif->def_wep_key_idx = 0;
1477 arvif->is_started = false;
1478 arvif->is_up = false;
1481 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1482 struct ieee80211_sta *sta)
1484 struct wmi_peer_assoc_complete_arg peer_arg;
1487 lockdep_assert_held(&ar->conf_mutex);
1489 ret = ath10k_peer_assoc_prepare(ar, arvif, sta, NULL, &peer_arg);
1491 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1496 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1498 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1503 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1505 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1509 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1511 ath10k_warn("could not set qos params for STA %pM, %d\n",
1519 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1520 struct ieee80211_sta *sta)
1524 lockdep_assert_held(&ar->conf_mutex);
1526 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1528 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1539 static int ath10k_update_channel_list(struct ath10k *ar)
1541 struct ieee80211_hw *hw = ar->hw;
1542 struct ieee80211_supported_band **bands;
1543 enum ieee80211_band band;
1544 struct ieee80211_channel *channel;
1545 struct wmi_scan_chan_list_arg arg = {0};
1546 struct wmi_channel_arg *ch;
1552 lockdep_assert_held(&ar->conf_mutex);
1554 bands = hw->wiphy->bands;
1555 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1559 for (i = 0; i < bands[band]->n_channels; i++) {
1560 if (bands[band]->channels[i].flags &
1561 IEEE80211_CHAN_DISABLED)
1568 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1569 arg.channels = kzalloc(len, GFP_KERNEL);
1574 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1578 for (i = 0; i < bands[band]->n_channels; i++) {
1579 channel = &bands[band]->channels[i];
1581 if (channel->flags & IEEE80211_CHAN_DISABLED)
1584 ch->allow_ht = true;
1586 /* FIXME: when should we really allow VHT? */
1587 ch->allow_vht = true;
1590 !(channel->flags & IEEE80211_CHAN_NO_IR);
1593 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1596 !!(channel->flags & IEEE80211_CHAN_RADAR);
1598 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1599 ch->passive = passive;
1601 ch->freq = channel->center_freq;
1603 ch->max_power = channel->max_power * 2;
1604 ch->max_reg_power = channel->max_reg_power * 2;
1605 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1606 ch->reg_class_id = 0; /* FIXME */
1608 /* FIXME: why use only legacy modes, why not any
1609 * HT/VHT modes? Would that even make any
1611 if (channel->band == IEEE80211_BAND_2GHZ)
1612 ch->mode = MODE_11G;
1614 ch->mode = MODE_11A;
1616 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1619 ath10k_dbg(ATH10K_DBG_WMI,
1620 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1621 ch - arg.channels, arg.n_channels,
1622 ch->freq, ch->max_power, ch->max_reg_power,
1623 ch->max_antenna_gain, ch->mode);
1629 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1630 kfree(arg.channels);
1635 static void ath10k_regd_update(struct ath10k *ar)
1637 struct reg_dmn_pair_mapping *regpair;
1640 lockdep_assert_held(&ar->conf_mutex);
1642 ret = ath10k_update_channel_list(ar);
1644 ath10k_warn("could not update channel list (%d)\n", ret);
1646 regpair = ar->ath_common.regulatory.regpair;
1648 /* Target allows setting up per-band regdomain but ath_common provides
1649 * a combined one only */
1650 ret = ath10k_wmi_pdev_set_regdomain(ar,
1651 regpair->reg_domain,
1652 regpair->reg_domain, /* 2ghz */
1653 regpair->reg_domain, /* 5ghz */
1654 regpair->reg_2ghz_ctl,
1655 regpair->reg_5ghz_ctl);
1657 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1660 static void ath10k_reg_notifier(struct wiphy *wiphy,
1661 struct regulatory_request *request)
1663 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1664 struct ath10k *ar = hw->priv;
1667 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1669 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1670 ath10k_dbg(ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1671 request->dfs_region);
1672 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1673 request->dfs_region);
1675 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1676 request->dfs_region);
1679 mutex_lock(&ar->conf_mutex);
1680 if (ar->state == ATH10K_STATE_ON)
1681 ath10k_regd_update(ar);
1682 mutex_unlock(&ar->conf_mutex);
1689 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1691 if (ieee80211_is_mgmt(hdr->frame_control))
1692 return HTT_DATA_TX_EXT_TID_MGMT;
1694 if (!ieee80211_is_data_qos(hdr->frame_control))
1695 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1697 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1698 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1700 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1703 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1704 struct ieee80211_tx_info *info)
1706 if (info->control.vif)
1707 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1709 if (ar->monitor_enabled)
1710 return ar->monitor_vdev_id;
1712 ath10k_warn("could not resolve vdev id\n");
1717 * Frames sent to the FW have to be in "Native Wifi" format.
1718 * Strip the QoS field from the 802.11 header.
1720 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1721 struct ieee80211_tx_control *control,
1722 struct sk_buff *skb)
1724 struct ieee80211_hdr *hdr = (void *)skb->data;
1727 if (!ieee80211_is_data_qos(hdr->frame_control))
1730 qos_ctl = ieee80211_get_qos_ctl(hdr);
1731 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1732 skb->data, (void *)qos_ctl - (void *)skb->data);
1733 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1736 static void ath10k_tx_wep_key_work(struct work_struct *work)
1738 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1740 int ret, keyidx = arvif->def_wep_key_newidx;
1742 if (arvif->def_wep_key_idx == keyidx)
1745 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1746 arvif->vdev_id, keyidx);
1748 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1750 arvif->ar->wmi.vdev_param->def_keyid,
1753 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1757 arvif->def_wep_key_idx = keyidx;
1760 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1762 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1763 struct ieee80211_vif *vif = info->control.vif;
1764 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1765 struct ath10k *ar = arvif->ar;
1766 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1767 struct ieee80211_key_conf *key = info->control.hw_key;
1769 if (!ieee80211_has_protected(hdr->frame_control))
1775 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1776 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1779 if (key->keyidx == arvif->def_wep_key_idx)
1782 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1783 * queueing frames until key index is updated is not an option because
1784 * sk_buff may need more processing to be done, e.g. offchannel */
1785 arvif->def_wep_key_newidx = key->keyidx;
1786 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1789 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1791 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1792 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1793 struct ieee80211_vif *vif = info->control.vif;
1794 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1796 /* This is case only for P2P_GO */
1797 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1798 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1801 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1802 spin_lock_bh(&ar->data_lock);
1803 if (arvif->u.ap.noa_data)
1804 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1806 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1807 arvif->u.ap.noa_data,
1808 arvif->u.ap.noa_len);
1809 spin_unlock_bh(&ar->data_lock);
1813 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1815 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1818 if (ar->htt.target_version_major >= 3) {
1819 /* Since HTT 3.0 there is no separate mgmt tx command */
1820 ret = ath10k_htt_tx(&ar->htt, skb);
1824 if (ieee80211_is_mgmt(hdr->frame_control)) {
1825 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1827 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1828 ATH10K_MAX_NUM_MGMT_PENDING) {
1829 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1834 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1835 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1837 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1839 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1841 ieee80211_is_nullfunc(hdr->frame_control)) {
1842 /* FW does not report tx status properly for NullFunc frames
1843 * unless they are sent through mgmt tx path. mac80211 sends
1844 * those frames when it detects link/beacon loss and depends
1845 * on the tx status to be correct. */
1846 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1848 ret = ath10k_htt_tx(&ar->htt, skb);
1853 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1854 ieee80211_free_txskb(ar->hw, skb);
1858 void ath10k_offchan_tx_purge(struct ath10k *ar)
1860 struct sk_buff *skb;
1863 skb = skb_dequeue(&ar->offchan_tx_queue);
1867 ieee80211_free_txskb(ar->hw, skb);
1871 void ath10k_offchan_tx_work(struct work_struct *work)
1873 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1874 struct ath10k_peer *peer;
1875 struct ieee80211_hdr *hdr;
1876 struct sk_buff *skb;
1877 const u8 *peer_addr;
1881 /* FW requirement: We must create a peer before FW will send out
1882 * an offchannel frame. Otherwise the frame will be stuck and
1883 * never transmitted. We delete the peer upon tx completion.
1884 * It is unlikely that a peer for offchannel tx will already be
1885 * present. However it may be in some rare cases so account for that.
1886 * Otherwise we might remove a legitimate peer and break stuff. */
1889 skb = skb_dequeue(&ar->offchan_tx_queue);
1893 mutex_lock(&ar->conf_mutex);
1895 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
1898 hdr = (struct ieee80211_hdr *)skb->data;
1899 peer_addr = ieee80211_get_DA(hdr);
1900 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
1902 spin_lock_bh(&ar->data_lock);
1903 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1904 spin_unlock_bh(&ar->data_lock);
1907 /* FIXME: should this use ath10k_warn()? */
1908 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1909 peer_addr, vdev_id);
1912 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1914 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1915 peer_addr, vdev_id, ret);
1918 spin_lock_bh(&ar->data_lock);
1919 reinit_completion(&ar->offchan_tx_completed);
1920 ar->offchan_tx_skb = skb;
1921 spin_unlock_bh(&ar->data_lock);
1923 ath10k_tx_htt(ar, skb);
1925 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1928 ath10k_warn("timed out waiting for offchannel skb %p\n",
1932 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1934 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1935 peer_addr, vdev_id, ret);
1938 mutex_unlock(&ar->conf_mutex);
1942 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1944 struct sk_buff *skb;
1947 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1951 ieee80211_free_txskb(ar->hw, skb);
1955 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1957 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1958 struct sk_buff *skb;
1962 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1966 ret = ath10k_wmi_mgmt_tx(ar, skb);
1968 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
1969 ieee80211_free_txskb(ar->hw, skb);
1979 * This gets called if we dont get a heart-beat during scan.
1980 * This may indicate the FW has hung and we need to abort the
1981 * scan manually to prevent cancel_hw_scan() from deadlocking
1983 void ath10k_reset_scan(unsigned long ptr)
1985 struct ath10k *ar = (struct ath10k *)ptr;
1987 spin_lock_bh(&ar->data_lock);
1988 if (!ar->scan.in_progress) {
1989 spin_unlock_bh(&ar->data_lock);
1993 ath10k_warn("scan timeout. resetting. fw issue?\n");
1995 if (ar->scan.is_roc)
1996 ieee80211_remain_on_channel_expired(ar->hw);
1998 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
2000 ar->scan.in_progress = false;
2001 complete_all(&ar->scan.completed);
2002 spin_unlock_bh(&ar->data_lock);
2005 static int ath10k_abort_scan(struct ath10k *ar)
2007 struct wmi_stop_scan_arg arg = {
2008 .req_id = 1, /* FIXME */
2009 .req_type = WMI_SCAN_STOP_ONE,
2010 .u.scan_id = ATH10K_SCAN_ID,
2014 lockdep_assert_held(&ar->conf_mutex);
2016 del_timer_sync(&ar->scan.timeout);
2018 spin_lock_bh(&ar->data_lock);
2019 if (!ar->scan.in_progress) {
2020 spin_unlock_bh(&ar->data_lock);
2024 ar->scan.aborting = true;
2025 spin_unlock_bh(&ar->data_lock);
2027 ret = ath10k_wmi_stop_scan(ar, &arg);
2029 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
2030 spin_lock_bh(&ar->data_lock);
2031 ar->scan.in_progress = false;
2032 ath10k_offchan_tx_purge(ar);
2033 spin_unlock_bh(&ar->data_lock);
2037 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2039 ath10k_warn("timed out while waiting for scan to stop\n");
2041 /* scan completion may be done right after we timeout here, so let's
2042 * check the in_progress and tell mac80211 scan is completed. if we
2043 * don't do that and FW fails to send us scan completion indication
2044 * then userspace won't be able to scan anymore */
2047 spin_lock_bh(&ar->data_lock);
2048 if (ar->scan.in_progress) {
2049 ath10k_warn("could not stop scan. its still in progress\n");
2050 ar->scan.in_progress = false;
2051 ath10k_offchan_tx_purge(ar);
2054 spin_unlock_bh(&ar->data_lock);
2059 static int ath10k_start_scan(struct ath10k *ar,
2060 const struct wmi_start_scan_arg *arg)
2064 lockdep_assert_held(&ar->conf_mutex);
2066 ret = ath10k_wmi_start_scan(ar, arg);
2070 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2072 ath10k_abort_scan(ar);
2076 /* the scan can complete earlier, before we even
2077 * start the timer. in that case the timer handler
2078 * checks ar->scan.in_progress and bails out if its
2079 * false. Add a 200ms margin to account event/command
2081 mod_timer(&ar->scan.timeout, jiffies +
2082 msecs_to_jiffies(arg->max_scan_time+200));
2086 /**********************/
2087 /* mac80211 callbacks */
2088 /**********************/
2090 static void ath10k_tx(struct ieee80211_hw *hw,
2091 struct ieee80211_tx_control *control,
2092 struct sk_buff *skb)
2094 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2095 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2096 struct ath10k *ar = hw->priv;
2099 /* We should disable CCK RATE due to P2P */
2100 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2101 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2103 /* we must calculate tid before we apply qos workaround
2104 * as we'd lose the qos control field */
2105 tid = ath10k_tx_h_get_tid(hdr);
2106 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
2108 /* it makes no sense to process injected frames like that */
2109 if (info->control.vif &&
2110 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
2111 ath10k_tx_h_qos_workaround(hw, control, skb);
2112 ath10k_tx_h_update_wep_key(skb);
2113 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
2114 ath10k_tx_h_seq_no(skb);
2117 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
2118 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2119 ATH10K_SKB_CB(skb)->htt.tid = tid;
2121 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2122 spin_lock_bh(&ar->data_lock);
2123 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2124 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2125 spin_unlock_bh(&ar->data_lock);
2127 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
2129 skb_queue_tail(&ar->offchan_tx_queue, skb);
2130 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2134 ath10k_tx_htt(ar, skb);
2138 * Initialize various parameters with default vaules.
2140 void ath10k_halt(struct ath10k *ar)
2142 lockdep_assert_held(&ar->conf_mutex);
2144 ath10k_stop_cac(ar);
2145 del_timer_sync(&ar->scan.timeout);
2146 ath10k_offchan_tx_purge(ar);
2147 ath10k_mgmt_over_wmi_tx_purge(ar);
2148 ath10k_peer_cleanup_all(ar);
2149 ath10k_core_stop(ar);
2150 ath10k_hif_power_down(ar);
2152 spin_lock_bh(&ar->data_lock);
2153 if (ar->scan.in_progress) {
2154 del_timer(&ar->scan.timeout);
2155 ar->scan.in_progress = false;
2156 ieee80211_scan_completed(ar->hw, true);
2158 spin_unlock_bh(&ar->data_lock);
2161 static int ath10k_start(struct ieee80211_hw *hw)
2163 struct ath10k *ar = hw->priv;
2166 mutex_lock(&ar->conf_mutex);
2168 if (ar->state != ATH10K_STATE_OFF &&
2169 ar->state != ATH10K_STATE_RESTARTING) {
2174 ret = ath10k_hif_power_up(ar);
2176 ath10k_err("could not init hif (%d)\n", ret);
2177 ar->state = ATH10K_STATE_OFF;
2181 ret = ath10k_core_start(ar);
2183 ath10k_err("could not init core (%d)\n", ret);
2184 ath10k_hif_power_down(ar);
2185 ar->state = ATH10K_STATE_OFF;
2189 if (ar->state == ATH10K_STATE_OFF)
2190 ar->state = ATH10K_STATE_ON;
2191 else if (ar->state == ATH10K_STATE_RESTARTING)
2192 ar->state = ATH10K_STATE_RESTARTED;
2194 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2196 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2199 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2201 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2205 * By default FW set ARP frames ac to voice (6). In that case ARP
2206 * exchange is not working properly for UAPSD enabled AP. ARP requests
2207 * which arrives with access category 0 are processed by network stack
2208 * and send back with access category 0, but FW changes access category
2209 * to 6. Set ARP frames access category to best effort (0) solves
2213 ret = ath10k_wmi_pdev_set_param(ar,
2214 ar->wmi.pdev_param->arp_ac_override, 0);
2216 ath10k_warn("could not set arp ac override parameter: %d\n",
2221 ath10k_regd_update(ar);
2225 mutex_unlock(&ar->conf_mutex);
2229 static void ath10k_stop(struct ieee80211_hw *hw)
2231 struct ath10k *ar = hw->priv;
2233 mutex_lock(&ar->conf_mutex);
2234 if (ar->state == ATH10K_STATE_ON ||
2235 ar->state == ATH10K_STATE_RESTARTED ||
2236 ar->state == ATH10K_STATE_WEDGED)
2239 ar->state = ATH10K_STATE_OFF;
2240 mutex_unlock(&ar->conf_mutex);
2242 ath10k_mgmt_over_wmi_tx_purge(ar);
2244 cancel_work_sync(&ar->offchan_tx_work);
2245 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2246 cancel_work_sync(&ar->restart_work);
2249 static int ath10k_config_ps(struct ath10k *ar)
2251 struct ath10k_vif *arvif;
2254 lockdep_assert_held(&ar->conf_mutex);
2256 list_for_each_entry(arvif, &ar->arvifs, list) {
2257 ret = ath10k_mac_vif_setup_ps(arvif);
2259 ath10k_warn("could not setup powersave (%d)\n", ret);
2267 static const char *chandef_get_width(enum nl80211_chan_width width)
2270 case NL80211_CHAN_WIDTH_20_NOHT:
2272 case NL80211_CHAN_WIDTH_20:
2274 case NL80211_CHAN_WIDTH_40:
2276 case NL80211_CHAN_WIDTH_80:
2278 case NL80211_CHAN_WIDTH_80P80:
2280 case NL80211_CHAN_WIDTH_160:
2282 case NL80211_CHAN_WIDTH_5:
2284 case NL80211_CHAN_WIDTH_10:
2290 static void ath10k_config_chan(struct ath10k *ar)
2292 struct ath10k_vif *arvif;
2293 bool monitor_was_enabled;
2296 lockdep_assert_held(&ar->conf_mutex);
2298 ath10k_dbg(ATH10K_DBG_MAC,
2299 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2300 ar->chandef.chan->center_freq,
2301 ar->chandef.center_freq1,
2302 ar->chandef.center_freq2,
2303 chandef_get_width(ar->chandef.width));
2305 /* First stop monitor interface. Some FW versions crash if there's a
2306 * lone monitor interface. */
2307 monitor_was_enabled = ar->monitor_enabled;
2309 if (ar->monitor_enabled)
2310 ath10k_monitor_stop(ar);
2312 list_for_each_entry(arvif, &ar->arvifs, list) {
2313 if (!arvif->is_started)
2316 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2319 ret = ath10k_vdev_stop(arvif);
2321 ath10k_warn("could not stop vdev %d (%d)\n",
2322 arvif->vdev_id, ret);
2327 /* all vdevs are now stopped - now attempt to restart them */
2329 list_for_each_entry(arvif, &ar->arvifs, list) {
2330 if (!arvif->is_started)
2333 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2336 ret = ath10k_vdev_start(arvif);
2338 ath10k_warn("could not start vdev %d (%d)\n",
2339 arvif->vdev_id, ret);
2346 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2349 ath10k_warn("could not bring vdev up %d (%d)\n",
2350 arvif->vdev_id, ret);
2355 if (monitor_was_enabled)
2356 ath10k_monitor_start(ar, ar->monitor_vdev_id);
2359 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2361 struct ath10k *ar = hw->priv;
2362 struct ieee80211_conf *conf = &hw->conf;
2366 mutex_lock(&ar->conf_mutex);
2368 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2369 ath10k_dbg(ATH10K_DBG_MAC,
2370 "mac config channel %d mhz flags 0x%x\n",
2371 conf->chandef.chan->center_freq,
2372 conf->chandef.chan->flags);
2374 spin_lock_bh(&ar->data_lock);
2375 ar->rx_channel = conf->chandef.chan;
2376 spin_unlock_bh(&ar->data_lock);
2378 ath10k_config_radar_detection(ar);
2380 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2381 ar->chandef = conf->chandef;
2382 ath10k_config_chan(ar);
2386 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2387 ath10k_dbg(ATH10K_DBG_MAC, "mac config power %d\n",
2388 hw->conf.power_level);
2390 param = ar->wmi.pdev_param->txpower_limit2g;
2391 ret = ath10k_wmi_pdev_set_param(ar, param,
2392 hw->conf.power_level * 2);
2394 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2395 hw->conf.power_level, ret);
2397 param = ar->wmi.pdev_param->txpower_limit5g;
2398 ret = ath10k_wmi_pdev_set_param(ar, param,
2399 hw->conf.power_level * 2);
2401 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2402 hw->conf.power_level, ret);
2405 if (changed & IEEE80211_CONF_CHANGE_PS)
2406 ath10k_config_ps(ar);
2408 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2409 if (conf->flags & IEEE80211_CONF_MONITOR)
2410 ret = ath10k_monitor_create(ar);
2412 ret = ath10k_monitor_destroy(ar);
2415 mutex_unlock(&ar->conf_mutex);
2421 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2422 * because we will send mgmt frames without CCK. This requirement
2423 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2426 static int ath10k_add_interface(struct ieee80211_hw *hw,
2427 struct ieee80211_vif *vif)
2429 struct ath10k *ar = hw->priv;
2430 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2431 enum wmi_sta_powersave_param param;
2437 mutex_lock(&ar->conf_mutex);
2439 memset(arvif, 0, sizeof(*arvif));
2444 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2445 INIT_LIST_HEAD(&arvif->list);
2447 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2448 ath10k_warn("Only one monitor interface allowed\n");
2453 bit = ffs(ar->free_vdev_map);
2459 arvif->vdev_id = bit - 1;
2460 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2463 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2465 switch (vif->type) {
2466 case NL80211_IFTYPE_UNSPECIFIED:
2467 case NL80211_IFTYPE_STATION:
2468 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2470 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2472 case NL80211_IFTYPE_ADHOC:
2473 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2475 case NL80211_IFTYPE_AP:
2476 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2479 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2481 case NL80211_IFTYPE_MONITOR:
2482 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2489 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
2490 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2492 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2493 arvif->vdev_subtype, vif->addr);
2495 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
2499 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2500 list_add(&arvif->list, &ar->arvifs);
2502 vdev_param = ar->wmi.vdev_param->def_keyid;
2503 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2504 arvif->def_wep_key_idx);
2506 ath10k_warn("Failed to set default keyid: %d\n", ret);
2507 goto err_vdev_delete;
2510 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2511 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2512 ATH10K_HW_TXRX_NATIVE_WIFI);
2513 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2514 if (ret && ret != -EOPNOTSUPP) {
2515 ath10k_warn("Failed to set TX encap: %d\n", ret);
2516 goto err_vdev_delete;
2519 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2520 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2522 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2523 goto err_vdev_delete;
2526 ret = ath10k_mac_set_kickout(arvif);
2528 ath10k_warn("Failed to set kickout parameters: %d\n",
2530 goto err_peer_delete;
2534 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2535 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2536 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2537 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2540 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2541 goto err_peer_delete;
2544 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2545 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2546 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2549 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2550 goto err_peer_delete;
2553 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2554 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2555 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2558 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2559 goto err_peer_delete;
2563 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2565 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2566 arvif->vdev_id, ret);
2567 goto err_peer_delete;
2570 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2572 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2573 arvif->vdev_id, ret);
2574 goto err_peer_delete;
2577 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2578 ar->monitor_present = true;
2580 mutex_unlock(&ar->conf_mutex);
2584 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2585 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2588 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2589 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2590 list_del(&arvif->list);
2593 mutex_unlock(&ar->conf_mutex);
2598 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2599 struct ieee80211_vif *vif)
2601 struct ath10k *ar = hw->priv;
2602 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2605 mutex_lock(&ar->conf_mutex);
2607 cancel_work_sync(&arvif->wep_key_work);
2609 spin_lock_bh(&ar->data_lock);
2610 if (arvif->beacon) {
2611 dev_kfree_skb_any(arvif->beacon);
2612 arvif->beacon = NULL;
2614 spin_unlock_bh(&ar->data_lock);
2616 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2617 list_del(&arvif->list);
2619 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2620 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2622 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2624 kfree(arvif->u.ap.noa_data);
2627 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2630 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2632 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2634 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2635 ar->monitor_present = false;
2637 ath10k_peer_cleanup(ar, arvif->vdev_id);
2639 mutex_unlock(&ar->conf_mutex);
2643 * FIXME: Has to be verified.
2645 #define SUPPORTED_FILTERS \
2646 (FIF_PROMISC_IN_BSS | \
2651 FIF_BCN_PRBRESP_PROMISC | \
2655 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2656 unsigned int changed_flags,
2657 unsigned int *total_flags,
2660 struct ath10k *ar = hw->priv;
2663 mutex_lock(&ar->conf_mutex);
2665 changed_flags &= SUPPORTED_FILTERS;
2666 *total_flags &= SUPPORTED_FILTERS;
2667 ar->filter_flags = *total_flags;
2669 /* Monitor must not be started if it wasn't created first.
2670 * Promiscuous mode may be started on a non-monitor interface - in
2671 * such case the monitor vdev is not created so starting the
2672 * monitor makes no sense. Since ath10k uses no special RX filters
2673 * (only BSS filter in STA mode) there's no need for any special
2675 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2676 !ar->monitor_enabled && ar->monitor_present) {
2677 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2678 ar->monitor_vdev_id);
2680 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2682 ath10k_warn("Unable to start monitor mode\n");
2683 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2684 ar->monitor_enabled && ar->monitor_present) {
2685 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2686 ar->monitor_vdev_id);
2688 ret = ath10k_monitor_stop(ar);
2690 ath10k_warn("Unable to stop monitor mode\n");
2693 mutex_unlock(&ar->conf_mutex);
2696 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2697 struct ieee80211_vif *vif,
2698 struct ieee80211_bss_conf *info,
2701 struct ath10k *ar = hw->priv;
2702 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2704 u32 vdev_param, pdev_param;
2706 mutex_lock(&ar->conf_mutex);
2708 if (changed & BSS_CHANGED_IBSS)
2709 ath10k_control_ibss(arvif, info, vif->addr);
2711 if (changed & BSS_CHANGED_BEACON_INT) {
2712 arvif->beacon_interval = info->beacon_int;
2713 vdev_param = ar->wmi.vdev_param->beacon_interval;
2714 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2715 arvif->beacon_interval);
2716 ath10k_dbg(ATH10K_DBG_MAC,
2717 "mac vdev %d beacon_interval %d\n",
2718 arvif->vdev_id, arvif->beacon_interval);
2721 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2725 if (changed & BSS_CHANGED_BEACON) {
2726 ath10k_dbg(ATH10K_DBG_MAC,
2727 "vdev %d set beacon tx mode to staggered\n",
2730 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2731 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
2732 WMI_BEACON_STAGGERED_MODE);
2734 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2738 if (changed & BSS_CHANGED_BEACON_INFO) {
2739 arvif->dtim_period = info->dtim_period;
2741 ath10k_dbg(ATH10K_DBG_MAC,
2742 "mac vdev %d dtim_period %d\n",
2743 arvif->vdev_id, arvif->dtim_period);
2745 vdev_param = ar->wmi.vdev_param->dtim_period;
2746 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2747 arvif->dtim_period);
2749 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2753 if (changed & BSS_CHANGED_SSID &&
2754 vif->type == NL80211_IFTYPE_AP) {
2755 arvif->u.ap.ssid_len = info->ssid_len;
2757 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2758 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2761 if (changed & BSS_CHANGED_BSSID) {
2762 if (!is_zero_ether_addr(info->bssid)) {
2763 ath10k_dbg(ATH10K_DBG_MAC,
2764 "mac vdev %d create peer %pM\n",
2765 arvif->vdev_id, info->bssid);
2767 ret = ath10k_peer_create(ar, arvif->vdev_id,
2770 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2771 info->bssid, arvif->vdev_id, ret);
2773 if (vif->type == NL80211_IFTYPE_STATION) {
2775 * this is never erased as we it for crypto key
2776 * clearing; this is FW requirement
2778 memcpy(arvif->bssid, info->bssid, ETH_ALEN);
2780 ath10k_dbg(ATH10K_DBG_MAC,
2781 "mac vdev %d start %pM\n",
2782 arvif->vdev_id, info->bssid);
2784 ret = ath10k_vdev_start(arvif);
2786 ath10k_warn("failed to start vdev: %d\n",
2791 arvif->is_started = true;
2795 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2796 * so driver need to store it. It is needed when leaving
2797 * IBSS in order to remove BSSID peer.
2799 if (vif->type == NL80211_IFTYPE_ADHOC)
2800 memcpy(arvif->bssid, info->bssid,
2805 if (changed & BSS_CHANGED_BEACON_ENABLED)
2806 ath10k_control_beaconing(arvif, info);
2808 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2810 if (info->use_cts_prot)
2815 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2816 arvif->vdev_id, cts_prot);
2818 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2819 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2822 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2826 if (changed & BSS_CHANGED_ERP_SLOT) {
2828 if (info->use_short_slot)
2829 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2832 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2834 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2835 arvif->vdev_id, slottime);
2837 vdev_param = ar->wmi.vdev_param->slot_time;
2838 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2841 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2845 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2847 if (info->use_short_preamble)
2848 preamble = WMI_VDEV_PREAMBLE_SHORT;
2850 preamble = WMI_VDEV_PREAMBLE_LONG;
2852 ath10k_dbg(ATH10K_DBG_MAC,
2853 "mac vdev %d preamble %dn",
2854 arvif->vdev_id, preamble);
2856 vdev_param = ar->wmi.vdev_param->preamble;
2857 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2860 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2864 if (changed & BSS_CHANGED_ASSOC) {
2866 ath10k_bss_assoc(hw, vif, info);
2870 mutex_unlock(&ar->conf_mutex);
2873 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2874 struct ieee80211_vif *vif,
2875 struct cfg80211_scan_request *req)
2877 struct ath10k *ar = hw->priv;
2878 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2879 struct wmi_start_scan_arg arg;
2883 mutex_lock(&ar->conf_mutex);
2885 spin_lock_bh(&ar->data_lock);
2886 if (ar->scan.in_progress) {
2887 spin_unlock_bh(&ar->data_lock);
2892 reinit_completion(&ar->scan.started);
2893 reinit_completion(&ar->scan.completed);
2894 ar->scan.in_progress = true;
2895 ar->scan.aborting = false;
2896 ar->scan.is_roc = false;
2897 ar->scan.vdev_id = arvif->vdev_id;
2898 spin_unlock_bh(&ar->data_lock);
2900 memset(&arg, 0, sizeof(arg));
2901 ath10k_wmi_start_scan_init(ar, &arg);
2902 arg.vdev_id = arvif->vdev_id;
2903 arg.scan_id = ATH10K_SCAN_ID;
2906 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2909 arg.ie_len = req->ie_len;
2910 memcpy(arg.ie, req->ie, arg.ie_len);
2914 arg.n_ssids = req->n_ssids;
2915 for (i = 0; i < arg.n_ssids; i++) {
2916 arg.ssids[i].len = req->ssids[i].ssid_len;
2917 arg.ssids[i].ssid = req->ssids[i].ssid;
2920 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2923 if (req->n_channels) {
2924 arg.n_channels = req->n_channels;
2925 for (i = 0; i < arg.n_channels; i++)
2926 arg.channels[i] = req->channels[i]->center_freq;
2929 ret = ath10k_start_scan(ar, &arg);
2931 ath10k_warn("could not start hw scan (%d)\n", ret);
2932 spin_lock_bh(&ar->data_lock);
2933 ar->scan.in_progress = false;
2934 spin_unlock_bh(&ar->data_lock);
2938 mutex_unlock(&ar->conf_mutex);
2942 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2943 struct ieee80211_vif *vif)
2945 struct ath10k *ar = hw->priv;
2948 mutex_lock(&ar->conf_mutex);
2949 ret = ath10k_abort_scan(ar);
2951 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2953 ieee80211_scan_completed(hw, 1 /* aborted */);
2955 mutex_unlock(&ar->conf_mutex);
2958 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
2959 struct ath10k_vif *arvif,
2960 enum set_key_cmd cmd,
2961 struct ieee80211_key_conf *key)
2963 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
2966 /* 10.1 firmware branch requires default key index to be set to group
2967 * key index after installing it. Otherwise FW/HW Txes corrupted
2968 * frames with multi-vif APs. This is not required for main firmware
2969 * branch (e.g. 636).
2971 * FIXME: This has been tested only in AP. It remains unknown if this
2972 * is required for multi-vif STA interfaces on 10.1 */
2974 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
2977 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
2980 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
2983 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2989 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2992 ath10k_warn("failed to set group key as default key: %d\n",
2996 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2997 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2998 struct ieee80211_key_conf *key)
3000 struct ath10k *ar = hw->priv;
3001 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3002 struct ath10k_peer *peer;
3003 const u8 *peer_addr;
3004 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3005 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3008 if (key->keyidx > WMI_MAX_KEY_INDEX)
3011 mutex_lock(&ar->conf_mutex);
3014 peer_addr = sta->addr;
3015 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3016 peer_addr = vif->bss_conf.bssid;
3018 peer_addr = vif->addr;
3020 key->hw_key_idx = key->keyidx;
3022 /* the peer should not disappear in mid-way (unless FW goes awry) since
3023 * we already hold conf_mutex. we just make sure its there now. */
3024 spin_lock_bh(&ar->data_lock);
3025 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3026 spin_unlock_bh(&ar->data_lock);
3029 if (cmd == SET_KEY) {
3030 ath10k_warn("cannot install key for non-existent peer %pM\n",
3035 /* if the peer doesn't exist there is no key to disable
3043 arvif->wep_keys[key->keyidx] = key;
3045 arvif->wep_keys[key->keyidx] = NULL;
3047 if (cmd == DISABLE_KEY)
3048 ath10k_clear_vdev_key(arvif, key);
3051 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3053 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
3057 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3059 spin_lock_bh(&ar->data_lock);
3060 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3061 if (peer && cmd == SET_KEY)
3062 peer->keys[key->keyidx] = key;
3063 else if (peer && cmd == DISABLE_KEY)
3064 peer->keys[key->keyidx] = NULL;
3065 else if (peer == NULL)
3066 /* impossible unless FW goes crazy */
3067 ath10k_warn("peer %pM disappeared!\n", peer_addr);
3068 spin_unlock_bh(&ar->data_lock);
3071 mutex_unlock(&ar->conf_mutex);
3075 static int ath10k_sta_state(struct ieee80211_hw *hw,
3076 struct ieee80211_vif *vif,
3077 struct ieee80211_sta *sta,
3078 enum ieee80211_sta_state old_state,
3079 enum ieee80211_sta_state new_state)
3081 struct ath10k *ar = hw->priv;
3082 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3086 mutex_lock(&ar->conf_mutex);
3088 if (old_state == IEEE80211_STA_NOTEXIST &&
3089 new_state == IEEE80211_STA_NONE &&
3090 vif->type != NL80211_IFTYPE_STATION) {
3092 * New station addition.
3094 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3095 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3097 max_num_peers = TARGET_NUM_PEERS;
3099 if (ar->num_peers >= max_num_peers) {
3100 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3101 ar->num_peers, max_num_peers);
3106 ath10k_dbg(ATH10K_DBG_MAC,
3107 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3108 arvif->vdev_id, sta->addr, ar->num_peers);
3110 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3112 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3113 sta->addr, arvif->vdev_id, ret);
3114 } else if ((old_state == IEEE80211_STA_NONE &&
3115 new_state == IEEE80211_STA_NOTEXIST)) {
3117 * Existing station deletion.
3119 ath10k_dbg(ATH10K_DBG_MAC,
3120 "mac vdev %d peer delete %pM (sta gone)\n",
3121 arvif->vdev_id, sta->addr);
3122 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3124 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
3125 sta->addr, arvif->vdev_id);
3127 if (vif->type == NL80211_IFTYPE_STATION)
3128 ath10k_bss_disassoc(hw, vif);
3129 } else if (old_state == IEEE80211_STA_AUTH &&
3130 new_state == IEEE80211_STA_ASSOC &&
3131 (vif->type == NL80211_IFTYPE_AP ||
3132 vif->type == NL80211_IFTYPE_ADHOC)) {
3136 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
3139 ret = ath10k_station_assoc(ar, arvif, sta);
3141 ath10k_warn("Failed to associate station: %pM\n",
3143 } else if (old_state == IEEE80211_STA_ASSOC &&
3144 new_state == IEEE80211_STA_AUTH &&
3145 (vif->type == NL80211_IFTYPE_AP ||
3146 vif->type == NL80211_IFTYPE_ADHOC)) {
3150 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3153 ret = ath10k_station_disassoc(ar, arvif, sta);
3155 ath10k_warn("Failed to disassociate station: %pM\n",
3159 mutex_unlock(&ar->conf_mutex);
3163 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3164 u16 ac, bool enable)
3166 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3170 lockdep_assert_held(&ar->conf_mutex);
3172 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3176 case IEEE80211_AC_VO:
3177 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3178 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3180 case IEEE80211_AC_VI:
3181 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3182 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3184 case IEEE80211_AC_BE:
3185 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3186 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3188 case IEEE80211_AC_BK:
3189 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3190 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3195 arvif->u.sta.uapsd |= value;
3197 arvif->u.sta.uapsd &= ~value;
3199 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3200 WMI_STA_PS_PARAM_UAPSD,
3201 arvif->u.sta.uapsd);
3203 ath10k_warn("could not set uapsd params %d\n", ret);
3207 if (arvif->u.sta.uapsd)
3208 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3210 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3212 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3213 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3216 ath10k_warn("could not set rx wake param %d\n", ret);
3222 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3223 struct ieee80211_vif *vif, u16 ac,
3224 const struct ieee80211_tx_queue_params *params)
3226 struct ath10k *ar = hw->priv;
3227 struct wmi_wmm_params_arg *p = NULL;
3230 mutex_lock(&ar->conf_mutex);
3233 case IEEE80211_AC_VO:
3234 p = &ar->wmm_params.ac_vo;
3236 case IEEE80211_AC_VI:
3237 p = &ar->wmm_params.ac_vi;
3239 case IEEE80211_AC_BE:
3240 p = &ar->wmm_params.ac_be;
3242 case IEEE80211_AC_BK:
3243 p = &ar->wmm_params.ac_bk;
3252 p->cwmin = params->cw_min;
3253 p->cwmax = params->cw_max;
3254 p->aifs = params->aifs;
3257 * The channel time duration programmed in the HW is in absolute
3258 * microseconds, while mac80211 gives the txop in units of
3261 p->txop = params->txop * 32;
3263 /* FIXME: FW accepts wmm params per hw, not per vif */
3264 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3266 ath10k_warn("could not set wmm params %d\n", ret);
3270 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3272 ath10k_warn("could not set sta uapsd %d\n", ret);
3275 mutex_unlock(&ar->conf_mutex);
3279 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3281 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3282 struct ieee80211_vif *vif,
3283 struct ieee80211_channel *chan,
3285 enum ieee80211_roc_type type)
3287 struct ath10k *ar = hw->priv;
3288 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3289 struct wmi_start_scan_arg arg;
3292 mutex_lock(&ar->conf_mutex);
3294 spin_lock_bh(&ar->data_lock);
3295 if (ar->scan.in_progress) {
3296 spin_unlock_bh(&ar->data_lock);
3301 reinit_completion(&ar->scan.started);
3302 reinit_completion(&ar->scan.completed);
3303 reinit_completion(&ar->scan.on_channel);
3304 ar->scan.in_progress = true;
3305 ar->scan.aborting = false;
3306 ar->scan.is_roc = true;
3307 ar->scan.vdev_id = arvif->vdev_id;
3308 ar->scan.roc_freq = chan->center_freq;
3309 spin_unlock_bh(&ar->data_lock);
3311 memset(&arg, 0, sizeof(arg));
3312 ath10k_wmi_start_scan_init(ar, &arg);
3313 arg.vdev_id = arvif->vdev_id;
3314 arg.scan_id = ATH10K_SCAN_ID;
3316 arg.channels[0] = chan->center_freq;
3317 arg.dwell_time_active = duration;
3318 arg.dwell_time_passive = duration;
3319 arg.max_scan_time = 2 * duration;
3320 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3321 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3323 ret = ath10k_start_scan(ar, &arg);
3325 ath10k_warn("could not start roc scan (%d)\n", ret);
3326 spin_lock_bh(&ar->data_lock);
3327 ar->scan.in_progress = false;
3328 spin_unlock_bh(&ar->data_lock);
3332 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3334 ath10k_warn("could not switch to channel for roc scan\n");
3335 ath10k_abort_scan(ar);
3342 mutex_unlock(&ar->conf_mutex);
3346 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3348 struct ath10k *ar = hw->priv;
3350 mutex_lock(&ar->conf_mutex);
3351 ath10k_abort_scan(ar);
3352 mutex_unlock(&ar->conf_mutex);
3358 * Both RTS and Fragmentation threshold are interface-specific
3359 * in ath10k, but device-specific in mac80211.
3362 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3364 struct ath10k *ar = hw->priv;
3365 struct ath10k_vif *arvif;
3368 mutex_lock(&ar->conf_mutex);
3369 list_for_each_entry(arvif, &ar->arvifs, list) {
3370 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3371 arvif->vdev_id, value);
3373 ret = ath10k_mac_set_rts(arvif, value);
3375 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3376 arvif->vdev_id, ret);
3380 mutex_unlock(&ar->conf_mutex);
3385 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3387 struct ath10k *ar = hw->priv;
3388 struct ath10k_vif *arvif;
3391 mutex_lock(&ar->conf_mutex);
3392 list_for_each_entry(arvif, &ar->arvifs, list) {
3393 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3394 arvif->vdev_id, value);
3396 ret = ath10k_mac_set_rts(arvif, value);
3398 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3399 arvif->vdev_id, ret);
3403 mutex_unlock(&ar->conf_mutex);
3408 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
3410 struct ath10k *ar = hw->priv;
3414 /* mac80211 doesn't care if we really xmit queued frames or not
3415 * we'll collect those frames either way if we stop/delete vdevs */
3419 mutex_lock(&ar->conf_mutex);
3421 if (ar->state == ATH10K_STATE_WEDGED)
3424 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3427 spin_lock_bh(&ar->htt.tx_lock);
3428 empty = (ar->htt.num_pending_tx == 0);
3429 spin_unlock_bh(&ar->htt.tx_lock);
3431 skip = (ar->state == ATH10K_STATE_WEDGED);
3434 }), ATH10K_FLUSH_TIMEOUT_HZ);
3436 if (ret <= 0 || skip)
3437 ath10k_warn("tx not flushed\n");
3440 mutex_unlock(&ar->conf_mutex);
3443 /* TODO: Implement this function properly
3444 * For now it is needed to reply to Probe Requests in IBSS mode.
3445 * Propably we need this information from FW.
3447 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3453 static int ath10k_suspend(struct ieee80211_hw *hw,
3454 struct cfg80211_wowlan *wowlan)
3456 struct ath10k *ar = hw->priv;
3459 mutex_lock(&ar->conf_mutex);
3461 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
3463 if (ret == -ETIMEDOUT)
3469 ret = ath10k_hif_suspend(ar);
3471 ath10k_warn("could not suspend hif (%d)\n", ret);
3478 ret = ath10k_wmi_pdev_resume_target(ar);
3480 ath10k_warn("could not resume target (%d)\n", ret);
3484 mutex_unlock(&ar->conf_mutex);
3488 static int ath10k_resume(struct ieee80211_hw *hw)
3490 struct ath10k *ar = hw->priv;
3493 mutex_lock(&ar->conf_mutex);
3495 ret = ath10k_hif_resume(ar);
3497 ath10k_warn("could not resume hif (%d)\n", ret);
3502 ret = ath10k_wmi_pdev_resume_target(ar);
3504 ath10k_warn("could not resume target (%d)\n", ret);
3511 mutex_unlock(&ar->conf_mutex);
3516 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3518 struct ath10k *ar = hw->priv;
3520 mutex_lock(&ar->conf_mutex);
3522 /* If device failed to restart it will be in a different state, e.g.
3523 * ATH10K_STATE_WEDGED */
3524 if (ar->state == ATH10K_STATE_RESTARTED) {
3525 ath10k_info("device successfully recovered\n");
3526 ar->state = ATH10K_STATE_ON;
3529 mutex_unlock(&ar->conf_mutex);
3532 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3533 struct survey_info *survey)
3535 struct ath10k *ar = hw->priv;
3536 struct ieee80211_supported_band *sband;
3537 struct survey_info *ar_survey = &ar->survey[idx];
3540 mutex_lock(&ar->conf_mutex);
3542 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3543 if (sband && idx >= sband->n_channels) {
3544 idx -= sband->n_channels;
3549 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3551 if (!sband || idx >= sband->n_channels) {
3556 spin_lock_bh(&ar->data_lock);
3557 memcpy(survey, ar_survey, sizeof(*survey));
3558 spin_unlock_bh(&ar->data_lock);
3560 survey->channel = &sband->channels[idx];
3563 mutex_unlock(&ar->conf_mutex);
3567 /* Helper table for legacy fixed_rate/bitrate_mask */
3568 static const u8 cck_ofdm_rate[] = {
3585 /* Check if only one bit set */
3586 static int ath10k_check_single_mask(u32 mask)
3594 mask &= ~BIT(bit - 1);
3602 ath10k_default_bitrate_mask(struct ath10k *ar,
3603 enum ieee80211_band band,
3604 const struct cfg80211_bitrate_mask *mask)
3606 u32 legacy = 0x00ff;
3611 case IEEE80211_BAND_2GHZ:
3615 case IEEE80211_BAND_5GHZ:
3621 if (mask->control[band].legacy != legacy)
3624 for (i = 0; i < ar->num_rf_chains; i++)
3625 if (mask->control[band].ht_mcs[i] != ht)
3628 for (i = 0; i < ar->num_rf_chains; i++)
3629 if (mask->control[band].vht_mcs[i] != vht)
3636 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
3637 enum ieee80211_band band,
3640 int ht_nss = 0, vht_nss = 0, i;
3643 if (ath10k_check_single_mask(mask->control[band].legacy))
3647 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
3648 if (mask->control[band].ht_mcs[i] == 0xff)
3650 else if (mask->control[band].ht_mcs[i] == 0x00)
3659 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
3660 if (mask->control[band].vht_mcs[i] == 0x03ff)
3662 else if (mask->control[band].vht_mcs[i] == 0x0000)
3670 if (ht_nss > 0 && vht_nss > 0)
3674 *fixed_nss = ht_nss;
3676 *fixed_nss = vht_nss;
3684 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
3685 enum ieee80211_band band,
3686 enum wmi_rate_preamble *preamble)
3688 int legacy = 0, ht = 0, vht = 0, i;
3690 *preamble = WMI_RATE_PREAMBLE_OFDM;
3693 legacy = ath10k_check_single_mask(mask->control[band].legacy);
3698 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3699 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
3704 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3705 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
3709 /* Currently we support only one fixed_rate */
3710 if ((legacy + ht + vht) != 1)
3714 *preamble = WMI_RATE_PREAMBLE_HT;
3716 *preamble = WMI_RATE_PREAMBLE_VHT;
3722 ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask *mask,
3723 enum ieee80211_band band,
3727 u8 rate = 0, pream = 0, nss = 0, i;
3728 enum wmi_rate_preamble preamble;
3730 /* Check if single rate correct */
3731 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
3737 case WMI_RATE_PREAMBLE_CCK:
3738 case WMI_RATE_PREAMBLE_OFDM:
3739 i = ffs(mask->control[band].legacy) - 1;
3741 if (band == IEEE80211_BAND_2GHZ && i < 4)
3742 pream = WMI_RATE_PREAMBLE_CCK;
3744 if (band == IEEE80211_BAND_5GHZ)
3747 if (i >= ARRAY_SIZE(cck_ofdm_rate))
3750 rate = cck_ofdm_rate[i];
3752 case WMI_RATE_PREAMBLE_HT:
3753 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
3754 if (mask->control[band].ht_mcs[i])
3757 if (i == IEEE80211_HT_MCS_MASK_LEN)
3760 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
3763 case WMI_RATE_PREAMBLE_VHT:
3764 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
3765 if (mask->control[band].vht_mcs[i])
3768 if (i == NL80211_VHT_NSS_MAX)
3771 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3776 *fixed_nss = nss + 1;
3780 ath10k_dbg(ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3783 *fixed_rate = pream | nss | rate;
3788 static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask *mask,
3789 enum ieee80211_band band,
3793 /* First check full NSS mask, if we can simply limit NSS */
3794 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
3797 /* Next Check single rate is set */
3798 return ath10k_bitrate_mask_rate(mask, band, fixed_rate, fixed_nss);
3801 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
3805 struct ath10k *ar = arvif->ar;
3809 mutex_lock(&ar->conf_mutex);
3811 if (arvif->fixed_rate == fixed_rate &&
3812 arvif->fixed_nss == fixed_nss)
3815 if (fixed_rate == WMI_FIXED_RATE_NONE)
3816 ath10k_dbg(ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
3818 vdev_param = ar->wmi.vdev_param->fixed_rate;
3819 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3820 vdev_param, fixed_rate);
3822 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3828 arvif->fixed_rate = fixed_rate;
3830 vdev_param = ar->wmi.vdev_param->nss;
3831 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
3832 vdev_param, fixed_nss);
3835 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3841 arvif->fixed_nss = fixed_nss;
3844 mutex_unlock(&ar->conf_mutex);
3848 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
3849 struct ieee80211_vif *vif,
3850 const struct cfg80211_bitrate_mask *mask)
3852 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3853 struct ath10k *ar = arvif->ar;
3854 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
3855 u8 fixed_rate = WMI_FIXED_RATE_NONE;
3856 u8 fixed_nss = ar->num_rf_chains;
3858 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
3859 if (!ath10k_get_fixed_rate_nss(mask, band,
3865 return ath10k_set_fixed_rate_param(arvif, fixed_rate, fixed_nss);
3868 static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
3869 struct ieee80211_vif *vif,
3870 struct cfg80211_chan_def *chandef)
3872 /* there's no need to do anything here. vif->csa_active is enough */
3876 static const struct ieee80211_ops ath10k_ops = {
3878 .start = ath10k_start,
3879 .stop = ath10k_stop,
3880 .config = ath10k_config,
3881 .add_interface = ath10k_add_interface,
3882 .remove_interface = ath10k_remove_interface,
3883 .configure_filter = ath10k_configure_filter,
3884 .bss_info_changed = ath10k_bss_info_changed,
3885 .hw_scan = ath10k_hw_scan,
3886 .cancel_hw_scan = ath10k_cancel_hw_scan,
3887 .set_key = ath10k_set_key,
3888 .sta_state = ath10k_sta_state,
3889 .conf_tx = ath10k_conf_tx,
3890 .remain_on_channel = ath10k_remain_on_channel,
3891 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3892 .set_rts_threshold = ath10k_set_rts_threshold,
3893 .set_frag_threshold = ath10k_set_frag_threshold,
3894 .flush = ath10k_flush,
3895 .tx_last_beacon = ath10k_tx_last_beacon,
3896 .restart_complete = ath10k_restart_complete,
3897 .get_survey = ath10k_get_survey,
3898 .set_bitrate_mask = ath10k_set_bitrate_mask,
3899 .channel_switch_beacon = ath10k_channel_switch_beacon,
3901 .suspend = ath10k_suspend,
3902 .resume = ath10k_resume,
3906 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3907 .bitrate = (_rate), \
3908 .flags = (_flags), \
3909 .hw_value = (_rateid), \
3912 #define CHAN2G(_channel, _freq, _flags) { \
3913 .band = IEEE80211_BAND_2GHZ, \
3914 .hw_value = (_channel), \
3915 .center_freq = (_freq), \
3916 .flags = (_flags), \
3917 .max_antenna_gain = 0, \
3921 #define CHAN5G(_channel, _freq, _flags) { \
3922 .band = IEEE80211_BAND_5GHZ, \
3923 .hw_value = (_channel), \
3924 .center_freq = (_freq), \
3925 .flags = (_flags), \
3926 .max_antenna_gain = 0, \
3930 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3940 CHAN2G(10, 2457, 0),
3941 CHAN2G(11, 2462, 0),
3942 CHAN2G(12, 2467, 0),
3943 CHAN2G(13, 2472, 0),
3944 CHAN2G(14, 2484, 0),
3947 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
3948 CHAN5G(36, 5180, 0),
3949 CHAN5G(40, 5200, 0),
3950 CHAN5G(44, 5220, 0),
3951 CHAN5G(48, 5240, 0),
3952 CHAN5G(52, 5260, 0),
3953 CHAN5G(56, 5280, 0),
3954 CHAN5G(60, 5300, 0),
3955 CHAN5G(64, 5320, 0),
3956 CHAN5G(100, 5500, 0),
3957 CHAN5G(104, 5520, 0),
3958 CHAN5G(108, 5540, 0),
3959 CHAN5G(112, 5560, 0),
3960 CHAN5G(116, 5580, 0),
3961 CHAN5G(120, 5600, 0),
3962 CHAN5G(124, 5620, 0),
3963 CHAN5G(128, 5640, 0),
3964 CHAN5G(132, 5660, 0),
3965 CHAN5G(136, 5680, 0),
3966 CHAN5G(140, 5700, 0),
3967 CHAN5G(149, 5745, 0),
3968 CHAN5G(153, 5765, 0),
3969 CHAN5G(157, 5785, 0),
3970 CHAN5G(161, 5805, 0),
3971 CHAN5G(165, 5825, 0),
3974 static struct ieee80211_rate ath10k_rates[] = {
3976 RATETAB_ENT(10, 0x82, 0),
3977 RATETAB_ENT(20, 0x84, 0),
3978 RATETAB_ENT(55, 0x8b, 0),
3979 RATETAB_ENT(110, 0x96, 0),
3981 RATETAB_ENT(60, 0x0c, 0),
3982 RATETAB_ENT(90, 0x12, 0),
3983 RATETAB_ENT(120, 0x18, 0),
3984 RATETAB_ENT(180, 0x24, 0),
3985 RATETAB_ENT(240, 0x30, 0),
3986 RATETAB_ENT(360, 0x48, 0),
3987 RATETAB_ENT(480, 0x60, 0),
3988 RATETAB_ENT(540, 0x6c, 0),
3991 #define ath10k_a_rates (ath10k_rates + 4)
3992 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3993 #define ath10k_g_rates (ath10k_rates + 0)
3994 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3996 struct ath10k *ath10k_mac_create(void)
3998 struct ieee80211_hw *hw;
4001 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
4011 void ath10k_mac_destroy(struct ath10k *ar)
4013 ieee80211_free_hw(ar->hw);
4016 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4019 .types = BIT(NL80211_IFTYPE_STATION)
4020 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4024 .types = BIT(NL80211_IFTYPE_P2P_GO)
4028 .types = BIT(NL80211_IFTYPE_AP)
4032 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4035 .types = BIT(NL80211_IFTYPE_AP)
4039 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4041 .limits = ath10k_if_limits,
4042 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4043 .max_interfaces = 8,
4044 .num_different_channels = 1,
4045 .beacon_int_infra_match = true,
4049 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4051 .limits = ath10k_10x_if_limits,
4052 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4053 .max_interfaces = 8,
4054 .num_different_channels = 1,
4055 .beacon_int_infra_match = true,
4056 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4057 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4058 BIT(NL80211_CHAN_WIDTH_20) |
4059 BIT(NL80211_CHAN_WIDTH_40) |
4060 BIT(NL80211_CHAN_WIDTH_80),
4065 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4067 struct ieee80211_sta_vht_cap vht_cap = {0};
4071 vht_cap.vht_supported = 1;
4072 vht_cap.cap = ar->vht_cap_info;
4075 for (i = 0; i < 8; i++) {
4076 if (i < ar->num_rf_chains)
4077 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4079 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4082 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4083 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4088 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4091 struct ieee80211_sta_ht_cap ht_cap = {0};
4093 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4096 ht_cap.ht_supported = 1;
4097 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4098 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4099 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4100 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4101 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4103 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4104 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4106 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4107 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4109 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4112 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4113 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4118 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4119 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4121 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4124 stbc = ar->ht_cap_info;
4125 stbc &= WMI_HT_CAP_RX_STBC;
4126 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4127 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4128 stbc &= IEEE80211_HT_CAP_RX_STBC;
4133 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4134 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4136 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4137 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4139 /* max AMSDU is implicitly taken from vht_cap_info */
4140 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4141 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4143 for (i = 0; i < ar->num_rf_chains; i++)
4144 ht_cap.mcs.rx_mask[i] = 0xFF;
4146 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4152 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4153 struct ieee80211_vif *vif)
4155 struct ath10k_vif_iter *arvif_iter = data;
4156 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4158 if (arvif->vdev_id == arvif_iter->vdev_id)
4159 arvif_iter->arvif = arvif;
4162 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4164 struct ath10k_vif_iter arvif_iter;
4167 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4168 arvif_iter.vdev_id = vdev_id;
4170 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4171 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4173 ath10k_get_arvif_iter,
4175 if (!arvif_iter.arvif) {
4176 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
4180 return arvif_iter.arvif;
4183 int ath10k_mac_register(struct ath10k *ar)
4185 struct ieee80211_supported_band *band;
4186 struct ieee80211_sta_vht_cap vht_cap;
4187 struct ieee80211_sta_ht_cap ht_cap;
4191 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4193 SET_IEEE80211_DEV(ar->hw, ar->dev);
4195 ht_cap = ath10k_get_ht_cap(ar);
4196 vht_cap = ath10k_create_vht_cap(ar);
4198 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4199 channels = kmemdup(ath10k_2ghz_channels,
4200 sizeof(ath10k_2ghz_channels),
4207 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4208 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4209 band->channels = channels;
4210 band->n_bitrates = ath10k_g_rates_size;
4211 band->bitrates = ath10k_g_rates;
4212 band->ht_cap = ht_cap;
4214 /* vht is not supported in 2.4 GHz */
4216 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4219 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4220 channels = kmemdup(ath10k_5ghz_channels,
4221 sizeof(ath10k_5ghz_channels),
4228 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4229 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4230 band->channels = channels;
4231 band->n_bitrates = ath10k_a_rates_size;
4232 band->bitrates = ath10k_a_rates;
4233 band->ht_cap = ht_cap;
4234 band->vht_cap = vht_cap;
4235 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4238 ar->hw->wiphy->interface_modes =
4239 BIT(NL80211_IFTYPE_STATION) |
4240 BIT(NL80211_IFTYPE_ADHOC) |
4241 BIT(NL80211_IFTYPE_AP);
4243 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4244 ar->hw->wiphy->interface_modes |=
4245 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4246 BIT(NL80211_IFTYPE_P2P_GO);
4248 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4249 IEEE80211_HW_SUPPORTS_PS |
4250 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4251 IEEE80211_HW_SUPPORTS_UAPSD |
4252 IEEE80211_HW_MFP_CAPABLE |
4253 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4254 IEEE80211_HW_HAS_RATE_CONTROL |
4255 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4256 IEEE80211_HW_WANT_MONITOR_VIF |
4257 IEEE80211_HW_AP_LINK_PS;
4259 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4260 * bytes is used for padding/alignment if necessary. */
4261 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4263 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4264 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4266 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4267 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4268 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4271 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4272 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4274 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4276 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4278 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4279 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4280 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4282 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4284 * on LL hardware queues are managed entirely by the FW
4285 * so we only advertise to mac we can do the queues thing
4289 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4290 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4291 ar->hw->wiphy->n_iface_combinations =
4292 ARRAY_SIZE(ath10k_10x_if_comb);
4294 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4295 ar->hw->wiphy->n_iface_combinations =
4296 ARRAY_SIZE(ath10k_if_comb);
4299 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4301 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4302 /* Init ath dfs pattern detector */
4303 ar->ath_common.debug_mask = ATH_DBG_DFS;
4304 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4307 if (!ar->dfs_detector)
4308 ath10k_warn("dfs pattern detector init failed\n");
4311 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4312 ath10k_reg_notifier);
4314 ath10k_err("Regulatory initialization failed\n");
4318 ret = ieee80211_register_hw(ar->hw);
4320 ath10k_err("ieee80211 registration failed: %d\n", ret);
4324 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4325 ret = regulatory_hint(ar->hw->wiphy,
4326 ar->ath_common.regulatory.alpha2);
4328 goto err_unregister;
4334 ieee80211_unregister_hw(ar->hw);
4336 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4337 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4342 void ath10k_mac_unregister(struct ath10k *ar)
4344 ieee80211_unregister_hw(ar->hw);
4346 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4347 ar->dfs_detector->exit(ar->dfs_detector);
4349 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4350 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4352 SET_IEEE80211_DEV(ar->hw, NULL);