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>
33 static int ath10k_send_key(struct ath10k_vif *arvif,
34 struct ieee80211_key_conf *key,
38 struct wmi_vdev_install_key_arg arg = {
39 .vdev_id = arvif->vdev_id,
40 .key_idx = key->keyidx,
41 .key_len = key->keylen,
46 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
47 arg.key_flags = WMI_KEY_PAIRWISE;
49 arg.key_flags = WMI_KEY_GROUP;
51 switch (key->cipher) {
52 case WLAN_CIPHER_SUITE_CCMP:
53 arg.key_cipher = WMI_CIPHER_AES_CCM;
54 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
56 case WLAN_CIPHER_SUITE_TKIP:
57 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
58 arg.key_cipher = WMI_CIPHER_TKIP;
59 arg.key_txmic_len = 8;
60 arg.key_rxmic_len = 8;
62 case WLAN_CIPHER_SUITE_WEP40:
63 case WLAN_CIPHER_SUITE_WEP104:
64 arg.key_cipher = WMI_CIPHER_WEP;
65 /* AP/IBSS mode requires self-key to be groupwise
66 * Otherwise pairwise key must be set */
67 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
68 arg.key_flags = WMI_KEY_PAIRWISE;
71 ath10k_warn("cipher %d is not supported\n", key->cipher);
75 if (cmd == DISABLE_KEY) {
76 arg.key_cipher = WMI_CIPHER_NONE;
80 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
83 static int ath10k_install_key(struct ath10k_vif *arvif,
84 struct ieee80211_key_conf *key,
88 struct ath10k *ar = arvif->ar;
91 INIT_COMPLETION(ar->install_key_done);
93 ret = ath10k_send_key(arvif, key, cmd, macaddr);
97 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
104 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
107 struct ath10k *ar = arvif->ar;
108 struct ath10k_peer *peer;
112 lockdep_assert_held(&ar->conf_mutex);
114 spin_lock_bh(&ar->data_lock);
115 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
116 spin_unlock_bh(&ar->data_lock);
121 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
122 if (arvif->wep_keys[i] == NULL)
125 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
130 peer->keys[i] = arvif->wep_keys[i];
136 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
139 struct ath10k *ar = arvif->ar;
140 struct ath10k_peer *peer;
145 lockdep_assert_held(&ar->conf_mutex);
147 spin_lock_bh(&ar->data_lock);
148 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
149 spin_unlock_bh(&ar->data_lock);
154 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
155 if (peer->keys[i] == NULL)
158 ret = ath10k_install_key(arvif, peer->keys[i],
160 if (ret && first_errno == 0)
164 ath10k_warn("could not remove peer wep key %d (%d)\n",
167 peer->keys[i] = NULL;
173 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
174 struct ieee80211_key_conf *key)
176 struct ath10k *ar = arvif->ar;
177 struct ath10k_peer *peer;
183 lockdep_assert_held(&ar->conf_mutex);
186 /* since ath10k_install_key we can't hold data_lock all the
187 * time, so we try to remove the keys incrementally */
188 spin_lock_bh(&ar->data_lock);
190 list_for_each_entry(peer, &ar->peers, list) {
191 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
192 if (peer->keys[i] == key) {
193 memcpy(addr, peer->addr, ETH_ALEN);
194 peer->keys[i] = NULL;
199 if (i < ARRAY_SIZE(peer->keys))
202 spin_unlock_bh(&ar->data_lock);
204 if (i == ARRAY_SIZE(peer->keys))
207 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
208 if (ret && first_errno == 0)
212 ath10k_warn("could not remove key for %pM\n", addr);
219 /*********************/
220 /* General utilities */
221 /*********************/
223 static inline enum wmi_phy_mode
224 chan_to_phymode(const struct cfg80211_chan_def *chandef)
226 enum wmi_phy_mode phymode = MODE_UNKNOWN;
228 switch (chandef->chan->band) {
229 case IEEE80211_BAND_2GHZ:
230 switch (chandef->width) {
231 case NL80211_CHAN_WIDTH_20_NOHT:
234 case NL80211_CHAN_WIDTH_20:
235 phymode = MODE_11NG_HT20;
237 case NL80211_CHAN_WIDTH_40:
238 phymode = MODE_11NG_HT40;
240 case NL80211_CHAN_WIDTH_80:
241 case NL80211_CHAN_WIDTH_80P80:
242 case NL80211_CHAN_WIDTH_160:
243 phymode = MODE_UNKNOWN;
247 case IEEE80211_BAND_5GHZ:
248 switch (chandef->width) {
249 case NL80211_CHAN_WIDTH_20_NOHT:
252 case NL80211_CHAN_WIDTH_20:
253 phymode = MODE_11NA_HT20;
255 case NL80211_CHAN_WIDTH_40:
256 phymode = MODE_11NA_HT40;
258 case NL80211_CHAN_WIDTH_80:
259 phymode = MODE_11AC_VHT80;
261 case NL80211_CHAN_WIDTH_80P80:
262 case NL80211_CHAN_WIDTH_160:
263 phymode = MODE_UNKNOWN;
271 WARN_ON(phymode == MODE_UNKNOWN);
275 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
278 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
279 * 0 for no restriction
288 switch (mpdudensity) {
294 /* Our lower layer calculations limit our precision to
310 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
314 lockdep_assert_held(&ar->conf_mutex);
316 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
320 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
327 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
331 lockdep_assert_held(&ar->conf_mutex);
333 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
337 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
344 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
346 struct ath10k_peer *peer, *tmp;
348 lockdep_assert_held(&ar->conf_mutex);
350 spin_lock_bh(&ar->data_lock);
351 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
352 if (peer->vdev_id != vdev_id)
355 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
356 peer->addr, vdev_id);
358 list_del(&peer->list);
361 spin_unlock_bh(&ar->data_lock);
364 /************************/
365 /* Interface management */
366 /************************/
368 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
372 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
373 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
380 static int ath10k_vdev_start(struct ath10k_vif *arvif)
382 struct ath10k *ar = arvif->ar;
383 struct ieee80211_conf *conf = &ar->hw->conf;
384 struct ieee80211_channel *channel = conf->chandef.chan;
385 struct wmi_vdev_start_request_arg arg = {};
388 lockdep_assert_held(&ar->conf_mutex);
390 INIT_COMPLETION(ar->vdev_setup_done);
392 arg.vdev_id = arvif->vdev_id;
393 arg.dtim_period = arvif->dtim_period;
394 arg.bcn_intval = arvif->beacon_interval;
396 arg.channel.freq = channel->center_freq;
398 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
400 arg.channel.mode = chan_to_phymode(&conf->chandef);
402 arg.channel.min_power = channel->max_power * 3;
403 arg.channel.max_power = channel->max_power * 4;
404 arg.channel.max_reg_power = channel->max_reg_power * 4;
405 arg.channel.max_antenna_gain = channel->max_antenna_gain;
407 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
408 arg.ssid = arvif->u.ap.ssid;
409 arg.ssid_len = arvif->u.ap.ssid_len;
410 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
411 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
412 arg.ssid = arvif->vif->bss_conf.ssid;
413 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
416 ret = ath10k_wmi_vdev_start(ar, &arg);
418 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
422 ret = ath10k_vdev_setup_sync(ar);
424 ath10k_warn("vdev setup failed %d\n", ret);
431 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
433 struct ath10k *ar = arvif->ar;
436 lockdep_assert_held(&ar->conf_mutex);
438 INIT_COMPLETION(ar->vdev_setup_done);
440 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
442 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
446 ret = ath10k_vdev_setup_sync(ar);
448 ath10k_warn("vdev setup failed %d\n", ret);
455 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
457 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
458 struct wmi_vdev_start_request_arg arg = {};
459 enum nl80211_channel_type type;
462 lockdep_assert_held(&ar->conf_mutex);
464 type = cfg80211_get_chandef_type(&ar->hw->conf.chandef);
466 arg.vdev_id = vdev_id;
467 arg.channel.freq = channel->center_freq;
468 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
470 /* TODO setup this dynamically, what in case we
471 don't have any vifs? */
472 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
474 arg.channel.min_power = channel->max_power * 3;
475 arg.channel.max_power = channel->max_power * 4;
476 arg.channel.max_reg_power = channel->max_reg_power * 4;
477 arg.channel.max_antenna_gain = channel->max_antenna_gain;
479 ret = ath10k_wmi_vdev_start(ar, &arg);
481 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
485 ret = ath10k_vdev_setup_sync(ar);
487 ath10k_warn("Monitor vdev setup failed %d\n", ret);
491 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
493 ath10k_warn("Monitor vdev up failed: %d\n", ret);
497 ar->monitor_vdev_id = vdev_id;
498 ar->monitor_enabled = true;
503 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
505 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
510 static int ath10k_monitor_stop(struct ath10k *ar)
514 lockdep_assert_held(&ar->conf_mutex);
516 /* For some reasons, ath10k_wmi_vdev_down() here couse
517 * often ath10k_wmi_vdev_stop() to fail. Next we could
518 * not run monitor vdev and driver reload
519 * required. Don't see such problems we skip
520 * ath10k_wmi_vdev_down() here.
523 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
525 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
527 ret = ath10k_vdev_setup_sync(ar);
529 ath10k_warn("Monitor_down sync failed: %d\n", ret);
531 ar->monitor_enabled = false;
535 static int ath10k_monitor_create(struct ath10k *ar)
539 lockdep_assert_held(&ar->conf_mutex);
541 if (ar->monitor_present) {
542 ath10k_warn("Monitor mode already enabled\n");
546 bit = ffs(ar->free_vdev_map);
548 ath10k_warn("No free VDEV slots\n");
552 ar->monitor_vdev_id = bit - 1;
553 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
555 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
556 WMI_VDEV_TYPE_MONITOR,
559 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
563 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface created, vdev id: %d\n",
564 ar->monitor_vdev_id);
566 ar->monitor_present = true;
571 * Restore the ID to the global map.
573 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
577 static int ath10k_monitor_destroy(struct ath10k *ar)
581 lockdep_assert_held(&ar->conf_mutex);
583 if (!ar->monitor_present)
586 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
588 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
592 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
593 ar->monitor_present = false;
595 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface destroyed, vdev id: %d\n",
596 ar->monitor_vdev_id);
600 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
601 struct ieee80211_bss_conf *info)
605 if (!info->enable_beacon) {
606 ath10k_vdev_stop(arvif);
610 arvif->tx_seq_no = 0x1000;
612 ret = ath10k_vdev_start(arvif);
616 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
618 ath10k_warn("Failed to bring up VDEV: %d\n",
622 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d up\n", arvif->vdev_id);
625 static void ath10k_control_ibss(struct ath10k_vif *arvif,
626 struct ieee80211_bss_conf *info,
627 const u8 self_peer[ETH_ALEN])
631 if (!info->ibss_joined) {
632 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
634 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
635 self_peer, arvif->vdev_id, ret);
637 if (is_zero_ether_addr(arvif->u.ibss.bssid))
640 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
641 arvif->u.ibss.bssid);
643 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
644 arvif->u.ibss.bssid, arvif->vdev_id, ret);
648 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
653 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
655 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
656 self_peer, arvif->vdev_id, ret);
660 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
661 WMI_VDEV_PARAM_ATIM_WINDOW,
662 ATH10K_DEFAULT_ATIM);
664 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
665 arvif->vdev_id, ret);
669 * Review this when mac80211 gains per-interface powersave support.
671 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
673 struct ath10k_generic_iter *ar_iter = data;
674 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
675 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
676 enum wmi_sta_powersave_param param;
677 enum wmi_sta_ps_mode psmode;
680 if (vif->type != NL80211_IFTYPE_STATION)
683 if (conf->flags & IEEE80211_CONF_PS) {
684 psmode = WMI_STA_PS_MODE_ENABLED;
685 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
687 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
690 conf->dynamic_ps_timeout);
692 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
699 psmode = WMI_STA_PS_MODE_DISABLED;
702 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
705 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
706 psmode, arvif->vdev_id);
708 ath10k_dbg(ATH10K_DBG_MAC, "Set PS Mode: %d for VDEV: %d\n",
709 psmode, arvif->vdev_id);
712 /**********************/
713 /* Station management */
714 /**********************/
716 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
717 struct ath10k_vif *arvif,
718 struct ieee80211_sta *sta,
719 struct ieee80211_bss_conf *bss_conf,
720 struct wmi_peer_assoc_complete_arg *arg)
722 memcpy(arg->addr, sta->addr, ETH_ALEN);
723 arg->vdev_id = arvif->vdev_id;
724 arg->peer_aid = sta->aid;
725 arg->peer_flags |= WMI_PEER_AUTH;
727 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
729 * Seems FW have problems with Power Save in STA
730 * mode when we setup this parameter to high (eg. 5).
731 * Often we see that FW don't send NULL (with clean P flags)
732 * frame even there is info about buffered frames in beacons.
733 * Sometimes we have to wait more than 10 seconds before FW
734 * will wakeup. Often sending one ping from AP to our device
735 * just fail (more than 50%).
737 * Seems setting this FW parameter to 1 couse FW
738 * will check every beacon and will wakup immediately
739 * after detection buffered data.
741 arg->peer_listen_intval = 1;
743 arg->peer_listen_intval = ar->hw->conf.listen_interval;
745 arg->peer_num_spatial_streams = 1;
748 * The assoc capabilities are available only in managed mode.
750 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
751 arg->peer_caps = bss_conf->assoc_capability;
754 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
755 struct ath10k_vif *arvif,
756 struct wmi_peer_assoc_complete_arg *arg)
758 struct ieee80211_vif *vif = arvif->vif;
759 struct ieee80211_bss_conf *info = &vif->bss_conf;
760 struct cfg80211_bss *bss;
761 const u8 *rsnie = NULL;
762 const u8 *wpaie = NULL;
764 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
765 info->bssid, NULL, 0, 0, 0);
767 const struct cfg80211_bss_ies *ies;
770 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
772 ies = rcu_dereference(bss->ies);
774 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
775 WLAN_OUI_TYPE_MICROSOFT_WPA,
779 cfg80211_put_bss(ar->hw->wiphy, bss);
782 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
783 if (rsnie || wpaie) {
784 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
785 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
789 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
790 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
794 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
795 struct ieee80211_sta *sta,
796 struct wmi_peer_assoc_complete_arg *arg)
798 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
799 const struct ieee80211_supported_band *sband;
800 const struct ieee80211_rate *rates;
804 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
805 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
806 rates = sband->bitrates;
808 rateset->num_rates = 0;
810 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
814 rateset->rates[rateset->num_rates] = rates->hw_value;
815 rateset->num_rates++;
819 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
820 struct ieee80211_sta *sta,
821 struct wmi_peer_assoc_complete_arg *arg)
823 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
827 if (!ht_cap->ht_supported)
830 arg->peer_flags |= WMI_PEER_HT;
831 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
832 ht_cap->ampdu_factor)) - 1;
834 arg->peer_mpdu_density =
835 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
837 arg->peer_ht_caps = ht_cap->cap;
838 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
840 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
841 arg->peer_flags |= WMI_PEER_LDPC;
843 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
844 arg->peer_flags |= WMI_PEER_40MHZ;
845 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
848 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
849 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
851 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
852 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
854 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
855 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
856 arg->peer_flags |= WMI_PEER_STBC;
859 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
861 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
862 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
863 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
864 arg->peer_rate_caps |= stbc;
865 arg->peer_flags |= WMI_PEER_STBC;
868 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
869 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
871 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
872 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
873 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
874 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
875 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
876 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
879 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
880 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
881 else if (ht_cap->mcs.rx_mask[1])
882 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
884 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
885 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
886 arg->peer_ht_rates.rates[n++] = i;
888 arg->peer_ht_rates.num_rates = n;
889 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
891 ath10k_dbg(ATH10K_DBG_MAC, "mcs cnt %d nss %d\n",
892 arg->peer_ht_rates.num_rates,
893 arg->peer_num_spatial_streams);
896 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
897 struct ath10k_vif *arvif,
898 struct ieee80211_sta *sta,
899 struct ieee80211_bss_conf *bss_conf,
900 struct wmi_peer_assoc_complete_arg *arg)
906 arg->peer_flags |= WMI_PEER_QOS;
908 if (sta->wme && sta->uapsd_queues) {
909 ath10k_dbg(ATH10K_DBG_MAC, "uapsd_queues: 0x%X, max_sp: %d\n",
910 sta->uapsd_queues, sta->max_sp);
912 arg->peer_flags |= WMI_PEER_APSD;
913 arg->peer_flags |= WMI_RC_UAPSD_FLAG;
915 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
916 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
917 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
918 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
919 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
920 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
921 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
922 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
923 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
924 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
925 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
926 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
929 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
930 max_sp = sta->max_sp;
932 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
934 WMI_AP_PS_PEER_PARAM_UAPSD,
937 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
939 WMI_AP_PS_PEER_PARAM_MAX_SP,
942 /* TODO setup this based on STA listen interval and
943 beacon interval. Currently we don't know
944 sta->listen_interval - mac80211 patch required.
945 Currently use 10 seconds */
946 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
948 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
953 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
954 struct ath10k_vif *arvif,
955 struct ieee80211_sta *sta,
956 struct ieee80211_bss_conf *bss_conf,
957 struct wmi_peer_assoc_complete_arg *arg)
960 arg->peer_flags |= WMI_PEER_QOS;
963 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
964 struct ieee80211_sta *sta,
965 struct wmi_peer_assoc_complete_arg *arg)
967 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
969 if (!vht_cap->vht_supported)
972 arg->peer_flags |= WMI_PEER_VHT;
974 arg->peer_vht_caps = vht_cap->cap;
976 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
977 arg->peer_flags |= WMI_PEER_80MHZ;
979 arg->peer_vht_rates.rx_max_rate =
980 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
981 arg->peer_vht_rates.rx_mcs_set =
982 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
983 arg->peer_vht_rates.tx_max_rate =
984 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
985 arg->peer_vht_rates.tx_mcs_set =
986 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
988 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer\n");
991 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
992 struct ath10k_vif *arvif,
993 struct ieee80211_sta *sta,
994 struct ieee80211_bss_conf *bss_conf,
995 struct wmi_peer_assoc_complete_arg *arg)
997 switch (arvif->vdev_type) {
998 case WMI_VDEV_TYPE_AP:
999 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1001 case WMI_VDEV_TYPE_STA:
1002 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1009 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1010 struct ath10k_vif *arvif,
1011 struct ieee80211_sta *sta,
1012 struct wmi_peer_assoc_complete_arg *arg)
1014 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1016 /* FIXME: add VHT */
1018 switch (ar->hw->conf.chandef.chan->band) {
1019 case IEEE80211_BAND_2GHZ:
1020 if (sta->ht_cap.ht_supported) {
1021 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1022 phymode = MODE_11NG_HT40;
1024 phymode = MODE_11NG_HT20;
1030 case IEEE80211_BAND_5GHZ:
1031 if (sta->ht_cap.ht_supported) {
1032 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1033 phymode = MODE_11NA_HT40;
1035 phymode = MODE_11NA_HT20;
1045 arg->peer_phymode = phymode;
1046 WARN_ON(phymode == MODE_UNKNOWN);
1049 static int ath10k_peer_assoc(struct ath10k *ar,
1050 struct ath10k_vif *arvif,
1051 struct ieee80211_sta *sta,
1052 struct ieee80211_bss_conf *bss_conf)
1054 struct wmi_peer_assoc_complete_arg arg;
1056 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1058 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1059 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1060 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1061 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1062 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1063 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1064 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1066 return ath10k_wmi_peer_assoc(ar, &arg);
1069 /* can be called only in mac80211 callbacks due to `key_count` usage */
1070 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1071 struct ieee80211_vif *vif,
1072 struct ieee80211_bss_conf *bss_conf)
1074 struct ath10k *ar = hw->priv;
1075 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1076 struct ieee80211_sta *ap_sta;
1081 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1083 ath10k_warn("Failed to find station entry for %pM\n",
1089 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1091 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1098 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1101 ath10k_warn("VDEV: %d up failed: ret %d\n",
1102 arvif->vdev_id, ret);
1104 ath10k_dbg(ATH10K_DBG_MAC,
1105 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1106 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1112 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1113 struct ieee80211_vif *vif)
1115 struct ath10k *ar = hw->priv;
1116 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1120 * For some reason, calling VDEV-DOWN before VDEV-STOP
1121 * makes the FW to send frames via HTT after disassociation.
1122 * No idea why this happens, even though VDEV-DOWN is supposed
1123 * to be analogous to link down, so just stop the VDEV.
1125 ret = ath10k_vdev_stop(arvif);
1127 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d stopped\n",
1131 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1132 * report beacons from previously associated network through HTT.
1133 * This in turn would spam mac80211 WARN_ON if we bring down all
1134 * interfaces as it expects there is no rx when no interface is
1137 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1139 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1140 arvif->vdev_id, ret);
1142 ath10k_wmi_flush_tx(ar);
1144 arvif->def_wep_key_index = 0;
1147 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1148 struct ieee80211_sta *sta)
1152 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1154 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1158 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1160 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1167 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1168 struct ieee80211_sta *sta)
1172 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1174 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1185 static int ath10k_update_channel_list(struct ath10k *ar)
1187 struct ieee80211_hw *hw = ar->hw;
1188 struct ieee80211_supported_band **bands;
1189 enum ieee80211_band band;
1190 struct ieee80211_channel *channel;
1191 struct wmi_scan_chan_list_arg arg = {0};
1192 struct wmi_channel_arg *ch;
1198 bands = hw->wiphy->bands;
1199 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1203 for (i = 0; i < bands[band]->n_channels; i++) {
1204 if (bands[band]->channels[i].flags &
1205 IEEE80211_CHAN_DISABLED)
1212 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1213 arg.channels = kzalloc(len, GFP_KERNEL);
1218 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1222 for (i = 0; i < bands[band]->n_channels; i++) {
1223 channel = &bands[band]->channels[i];
1225 if (channel->flags & IEEE80211_CHAN_DISABLED)
1228 ch->allow_ht = true;
1230 /* FIXME: when should we really allow VHT? */
1231 ch->allow_vht = true;
1234 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1237 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1239 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1240 ch->passive = passive;
1242 ch->freq = channel->center_freq;
1243 ch->min_power = channel->max_power * 3;
1244 ch->max_power = channel->max_power * 4;
1245 ch->max_reg_power = channel->max_reg_power * 4;
1246 ch->max_antenna_gain = channel->max_antenna_gain;
1247 ch->reg_class_id = 0; /* FIXME */
1249 /* FIXME: why use only legacy modes, why not any
1250 * HT/VHT modes? Would that even make any
1252 if (channel->band == IEEE80211_BAND_2GHZ)
1253 ch->mode = MODE_11G;
1255 ch->mode = MODE_11A;
1257 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1260 ath10k_dbg(ATH10K_DBG_WMI,
1261 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1262 __func__, ch - arg.channels, arg.n_channels,
1263 ch->freq, ch->max_power, ch->max_reg_power,
1264 ch->max_antenna_gain, ch->mode);
1270 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1271 kfree(arg.channels);
1276 static void ath10k_reg_notifier(struct wiphy *wiphy,
1277 struct regulatory_request *request)
1279 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1280 struct reg_dmn_pair_mapping *regpair;
1281 struct ath10k *ar = hw->priv;
1284 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1286 ret = ath10k_update_channel_list(ar);
1288 ath10k_warn("could not update channel list (%d)\n", ret);
1290 regpair = ar->ath_common.regulatory.regpair;
1291 /* Target allows setting up per-band regdomain but ath_common provides
1292 * a combined one only */
1293 ret = ath10k_wmi_pdev_set_regdomain(ar,
1294 regpair->regDmnEnum,
1295 regpair->regDmnEnum, /* 2ghz */
1296 regpair->regDmnEnum, /* 5ghz */
1297 regpair->reg_2ghz_ctl,
1298 regpair->reg_5ghz_ctl);
1300 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1308 * Frames sent to the FW have to be in "Native Wifi" format.
1309 * Strip the QoS field from the 802.11 header.
1311 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1312 struct ieee80211_tx_control *control,
1313 struct sk_buff *skb)
1315 struct ieee80211_hdr *hdr = (void *)skb->data;
1318 if (!ieee80211_is_data_qos(hdr->frame_control))
1321 qos_ctl = ieee80211_get_qos_ctl(hdr);
1322 memmove(qos_ctl, qos_ctl + IEEE80211_QOS_CTL_LEN,
1323 skb->len - ieee80211_hdrlen(hdr->frame_control));
1324 skb_trim(skb, skb->len - IEEE80211_QOS_CTL_LEN);
1327 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1329 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1330 struct ieee80211_vif *vif = info->control.vif;
1331 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1332 struct ath10k *ar = arvif->ar;
1333 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1334 struct ieee80211_key_conf *key = info->control.hw_key;
1337 /* TODO AP mode should be implemented */
1338 if (vif->type != NL80211_IFTYPE_STATION)
1341 if (!ieee80211_has_protected(hdr->frame_control))
1347 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1348 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1351 if (key->keyidx == arvif->def_wep_key_index)
1354 ath10k_dbg(ATH10K_DBG_MAC, "new wep keyidx will be %d\n", key->keyidx);
1356 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1357 WMI_VDEV_PARAM_DEF_KEYID,
1360 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1364 arvif->def_wep_key_index = key->keyidx;
1367 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1369 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1370 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1371 struct ieee80211_vif *vif = info->control.vif;
1372 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1374 /* This is case only for P2P_GO */
1375 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1376 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1379 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1380 spin_lock_bh(&ar->data_lock);
1381 if (arvif->u.ap.noa_data)
1382 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1384 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1385 arvif->u.ap.noa_data,
1386 arvif->u.ap.noa_len);
1387 spin_unlock_bh(&ar->data_lock);
1391 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1393 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1396 if (ieee80211_is_mgmt(hdr->frame_control))
1397 ret = ath10k_htt_mgmt_tx(ar->htt, skb);
1398 else if (ieee80211_is_nullfunc(hdr->frame_control))
1399 /* FW does not report tx status properly for NullFunc frames
1400 * unless they are sent through mgmt tx path. mac80211 sends
1401 * those frames when it detects link/beacon loss and depends on
1402 * the tx status to be correct. */
1403 ret = ath10k_htt_mgmt_tx(ar->htt, skb);
1405 ret = ath10k_htt_tx(ar->htt, skb);
1408 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1409 ieee80211_free_txskb(ar->hw, skb);
1413 void ath10k_offchan_tx_purge(struct ath10k *ar)
1415 struct sk_buff *skb;
1418 skb = skb_dequeue(&ar->offchan_tx_queue);
1422 ieee80211_free_txskb(ar->hw, skb);
1426 void ath10k_offchan_tx_work(struct work_struct *work)
1428 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1429 struct ath10k_peer *peer;
1430 struct ieee80211_hdr *hdr;
1431 struct sk_buff *skb;
1432 const u8 *peer_addr;
1436 /* FW requirement: We must create a peer before FW will send out
1437 * an offchannel frame. Otherwise the frame will be stuck and
1438 * never transmitted. We delete the peer upon tx completion.
1439 * It is unlikely that a peer for offchannel tx will already be
1440 * present. However it may be in some rare cases so account for that.
1441 * Otherwise we might remove a legitimate peer and break stuff. */
1444 skb = skb_dequeue(&ar->offchan_tx_queue);
1448 mutex_lock(&ar->conf_mutex);
1450 ath10k_dbg(ATH10K_DBG_MAC, "processing offchannel skb %p\n",
1453 hdr = (struct ieee80211_hdr *)skb->data;
1454 peer_addr = ieee80211_get_DA(hdr);
1455 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1457 spin_lock_bh(&ar->data_lock);
1458 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1459 spin_unlock_bh(&ar->data_lock);
1462 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1463 peer_addr, vdev_id);
1466 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1468 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1469 peer_addr, vdev_id, ret);
1472 spin_lock_bh(&ar->data_lock);
1473 INIT_COMPLETION(ar->offchan_tx_completed);
1474 ar->offchan_tx_skb = skb;
1475 spin_unlock_bh(&ar->data_lock);
1477 ath10k_tx_htt(ar, skb);
1479 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1482 ath10k_warn("timed out waiting for offchannel skb %p\n",
1486 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1488 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1489 peer_addr, vdev_id, ret);
1492 mutex_unlock(&ar->conf_mutex);
1501 * This gets called if we dont get a heart-beat during scan.
1502 * This may indicate the FW has hung and we need to abort the
1503 * scan manually to prevent cancel_hw_scan() from deadlocking
1505 void ath10k_reset_scan(unsigned long ptr)
1507 struct ath10k *ar = (struct ath10k *)ptr;
1509 spin_lock_bh(&ar->data_lock);
1510 if (!ar->scan.in_progress) {
1511 spin_unlock_bh(&ar->data_lock);
1515 ath10k_warn("scan timeout. resetting. fw issue?\n");
1517 if (ar->scan.is_roc)
1518 ieee80211_remain_on_channel_expired(ar->hw);
1520 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1522 ar->scan.in_progress = false;
1523 complete_all(&ar->scan.completed);
1524 spin_unlock_bh(&ar->data_lock);
1527 static int ath10k_abort_scan(struct ath10k *ar)
1529 struct wmi_stop_scan_arg arg = {
1530 .req_id = 1, /* FIXME */
1531 .req_type = WMI_SCAN_STOP_ONE,
1532 .u.scan_id = ATH10K_SCAN_ID,
1536 lockdep_assert_held(&ar->conf_mutex);
1538 del_timer_sync(&ar->scan.timeout);
1540 spin_lock_bh(&ar->data_lock);
1541 if (!ar->scan.in_progress) {
1542 spin_unlock_bh(&ar->data_lock);
1546 ar->scan.aborting = true;
1547 spin_unlock_bh(&ar->data_lock);
1549 ret = ath10k_wmi_stop_scan(ar, &arg);
1551 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1555 ath10k_wmi_flush_tx(ar);
1557 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1559 ath10k_warn("timed out while waiting for scan to stop\n");
1561 /* scan completion may be done right after we timeout here, so let's
1562 * check the in_progress and tell mac80211 scan is completed. if we
1563 * don't do that and FW fails to send us scan completion indication
1564 * then userspace won't be able to scan anymore */
1567 spin_lock_bh(&ar->data_lock);
1568 if (ar->scan.in_progress) {
1569 ath10k_warn("could not stop scan. its still in progress\n");
1570 ar->scan.in_progress = false;
1571 ath10k_offchan_tx_purge(ar);
1574 spin_unlock_bh(&ar->data_lock);
1579 static int ath10k_start_scan(struct ath10k *ar,
1580 const struct wmi_start_scan_arg *arg)
1584 lockdep_assert_held(&ar->conf_mutex);
1586 ret = ath10k_wmi_start_scan(ar, arg);
1590 /* make sure we submit the command so the completion
1591 * timeout makes sense */
1592 ath10k_wmi_flush_tx(ar);
1594 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1596 ath10k_abort_scan(ar);
1600 /* the scan can complete earlier, before we even
1601 * start the timer. in that case the timer handler
1602 * checks ar->scan.in_progress and bails out if its
1603 * false. Add a 200ms margin to account event/command
1605 mod_timer(&ar->scan.timeout, jiffies +
1606 msecs_to_jiffies(arg->max_scan_time+200));
1610 /**********************/
1611 /* mac80211 callbacks */
1612 /**********************/
1614 static void ath10k_tx(struct ieee80211_hw *hw,
1615 struct ieee80211_tx_control *control,
1616 struct sk_buff *skb)
1618 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1619 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1620 struct ath10k *ar = hw->priv;
1621 struct ath10k_vif *arvif = NULL;
1625 if (info->control.vif) {
1626 arvif = ath10k_vif_to_arvif(info->control.vif);
1627 vdev_id = arvif->vdev_id;
1628 } else if (ar->monitor_enabled) {
1629 vdev_id = ar->monitor_vdev_id;
1632 /* We should disable CCK RATE due to P2P */
1633 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1634 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1636 /* we must calculate tid before we apply qos workaround
1637 * as we'd lose the qos control field */
1638 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1639 if (ieee80211_is_data_qos(hdr->frame_control) &&
1640 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1641 u8 *qc = ieee80211_get_qos_ctl(hdr);
1642 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1645 ath10k_tx_h_qos_workaround(hw, control, skb);
1646 ath10k_tx_h_update_wep_key(skb);
1647 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1648 ath10k_tx_h_seq_no(skb);
1650 memset(ATH10K_SKB_CB(skb), 0, sizeof(*ATH10K_SKB_CB(skb)));
1651 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1652 ATH10K_SKB_CB(skb)->htt.tid = tid;
1654 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1655 spin_lock_bh(&ar->data_lock);
1656 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1657 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1658 spin_unlock_bh(&ar->data_lock);
1660 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1662 skb_queue_tail(&ar->offchan_tx_queue, skb);
1663 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1667 ath10k_tx_htt(ar, skb);
1671 * Initialize various parameters with default vaules.
1673 static int ath10k_start(struct ieee80211_hw *hw)
1675 struct ath10k *ar = hw->priv;
1678 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1680 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1683 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1685 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1691 static void ath10k_stop(struct ieee80211_hw *hw)
1693 struct ath10k *ar = hw->priv;
1695 /* avoid leaks in case FW never confirms scan for offchannel */
1696 cancel_work_sync(&ar->offchan_tx_work);
1697 ath10k_offchan_tx_purge(ar);
1700 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1702 struct ath10k_generic_iter ar_iter;
1703 struct ath10k *ar = hw->priv;
1704 struct ieee80211_conf *conf = &hw->conf;
1708 mutex_lock(&ar->conf_mutex);
1710 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1711 ath10k_dbg(ATH10K_DBG_MAC, "Config channel %d mhz\n",
1712 conf->chandef.chan->center_freq);
1713 spin_lock_bh(&ar->data_lock);
1714 ar->rx_channel = conf->chandef.chan;
1715 spin_unlock_bh(&ar->data_lock);
1718 if (changed & IEEE80211_CONF_CHANGE_PS) {
1719 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1721 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
1723 ieee80211_iterate_active_interfaces_atomic(hw,
1731 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1732 if (conf->flags & IEEE80211_CONF_MONITOR)
1733 ret = ath10k_monitor_create(ar);
1735 ret = ath10k_monitor_destroy(ar);
1738 mutex_unlock(&ar->conf_mutex);
1744 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1745 * because we will send mgmt frames without CCK. This requirement
1746 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1749 static int ath10k_add_interface(struct ieee80211_hw *hw,
1750 struct ieee80211_vif *vif)
1752 struct ath10k *ar = hw->priv;
1753 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1754 enum wmi_sta_powersave_param param;
1759 mutex_lock(&ar->conf_mutex);
1764 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1765 ath10k_warn("Only one monitor interface allowed\n");
1770 bit = ffs(ar->free_vdev_map);
1776 arvif->vdev_id = bit - 1;
1777 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1778 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1781 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1783 switch (vif->type) {
1784 case NL80211_IFTYPE_UNSPECIFIED:
1785 case NL80211_IFTYPE_STATION:
1786 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1788 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1790 case NL80211_IFTYPE_ADHOC:
1791 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1793 case NL80211_IFTYPE_AP:
1794 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1797 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1799 case NL80211_IFTYPE_MONITOR:
1800 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1807 ath10k_dbg(ATH10K_DBG_MAC, "Add interface: id %d type %d subtype %d\n",
1808 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1810 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1811 arvif->vdev_subtype, vif->addr);
1813 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1817 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
1818 arvif->def_wep_key_index);
1820 ath10k_warn("Failed to set default keyid: %d\n", ret);
1822 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1823 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
1824 ATH10K_HW_TXRX_NATIVE_WIFI);
1826 ath10k_warn("Failed to set TX encap: %d\n", ret);
1828 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1829 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
1831 ath10k_warn("Failed to create peer for AP: %d\n", ret);
1836 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
1837 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
1838 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
1839 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1842 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
1844 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1845 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1846 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1849 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
1851 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1852 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1853 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1856 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
1859 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1860 ar->monitor_present = true;
1863 mutex_unlock(&ar->conf_mutex);
1867 static void ath10k_remove_interface(struct ieee80211_hw *hw,
1868 struct ieee80211_vif *vif)
1870 struct ath10k *ar = hw->priv;
1871 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1874 mutex_lock(&ar->conf_mutex);
1876 ath10k_dbg(ATH10K_DBG_MAC, "Remove interface: id %d\n", arvif->vdev_id);
1878 ar->free_vdev_map |= 1 << (arvif->vdev_id);
1880 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1881 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
1883 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
1885 kfree(arvif->u.ap.noa_data);
1888 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
1890 ath10k_warn("WMI vdev delete failed: %d\n", ret);
1892 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1893 ar->monitor_present = false;
1895 ath10k_peer_cleanup(ar, arvif->vdev_id);
1897 mutex_unlock(&ar->conf_mutex);
1901 * FIXME: Has to be verified.
1903 #define SUPPORTED_FILTERS \
1904 (FIF_PROMISC_IN_BSS | \
1909 FIF_BCN_PRBRESP_PROMISC | \
1913 static void ath10k_configure_filter(struct ieee80211_hw *hw,
1914 unsigned int changed_flags,
1915 unsigned int *total_flags,
1918 struct ath10k *ar = hw->priv;
1921 mutex_lock(&ar->conf_mutex);
1923 changed_flags &= SUPPORTED_FILTERS;
1924 *total_flags &= SUPPORTED_FILTERS;
1925 ar->filter_flags = *total_flags;
1927 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
1928 !ar->monitor_enabled) {
1929 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
1931 ath10k_warn("Unable to start monitor mode\n");
1933 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode started\n");
1934 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
1935 ar->monitor_enabled) {
1936 ret = ath10k_monitor_stop(ar);
1938 ath10k_warn("Unable to stop monitor mode\n");
1940 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode stopped\n");
1943 mutex_unlock(&ar->conf_mutex);
1946 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
1947 struct ieee80211_vif *vif,
1948 struct ieee80211_bss_conf *info,
1951 struct ath10k *ar = hw->priv;
1952 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1955 mutex_lock(&ar->conf_mutex);
1957 if (changed & BSS_CHANGED_IBSS)
1958 ath10k_control_ibss(arvif, info, vif->addr);
1960 if (changed & BSS_CHANGED_BEACON_INT) {
1961 arvif->beacon_interval = info->beacon_int;
1962 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1963 WMI_VDEV_PARAM_BEACON_INTERVAL,
1964 arvif->beacon_interval);
1966 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
1969 ath10k_dbg(ATH10K_DBG_MAC,
1970 "Beacon interval: %d set for VDEV: %d\n",
1971 arvif->beacon_interval, arvif->vdev_id);
1974 if (changed & BSS_CHANGED_BEACON) {
1975 ret = ath10k_wmi_pdev_set_param(ar,
1976 WMI_PDEV_PARAM_BEACON_TX_MODE,
1977 WMI_BEACON_STAGGERED_MODE);
1979 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
1982 ath10k_dbg(ATH10K_DBG_MAC,
1983 "Set staggered beacon mode for VDEV: %d\n",
1987 if (changed & BSS_CHANGED_DTIM_PERIOD) {
1988 arvif->dtim_period = info->dtim_period;
1990 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1991 WMI_VDEV_PARAM_DTIM_PERIOD,
1992 arvif->dtim_period);
1994 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
1997 ath10k_dbg(ATH10K_DBG_MAC,
1998 "Set dtim period: %d for VDEV: %d\n",
1999 arvif->dtim_period, arvif->vdev_id);
2002 if (changed & BSS_CHANGED_SSID &&
2003 vif->type == NL80211_IFTYPE_AP) {
2004 arvif->u.ap.ssid_len = info->ssid_len;
2006 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2007 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2010 if (changed & BSS_CHANGED_BSSID) {
2011 if (!is_zero_ether_addr(info->bssid)) {
2012 ret = ath10k_peer_create(ar, arvif->vdev_id,
2015 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2016 info->bssid, arvif->vdev_id);
2018 ath10k_dbg(ATH10K_DBG_MAC,
2019 "Added peer: %pM for VDEV: %d\n",
2020 info->bssid, arvif->vdev_id);
2023 if (vif->type == NL80211_IFTYPE_STATION) {
2025 * this is never erased as we it for crypto key
2026 * clearing; this is FW requirement
2028 memcpy(arvif->u.sta.bssid, info->bssid,
2031 ret = ath10k_vdev_start(arvif);
2033 ath10k_dbg(ATH10K_DBG_MAC,
2034 "VDEV: %d started with BSSID: %pM\n",
2035 arvif->vdev_id, info->bssid);
2039 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2040 * so driver need to store it. It is needed when leaving
2041 * IBSS in order to remove BSSID peer.
2043 if (vif->type == NL80211_IFTYPE_ADHOC)
2044 memcpy(arvif->u.ibss.bssid, info->bssid,
2049 if (changed & BSS_CHANGED_BEACON_ENABLED)
2050 ath10k_control_beaconing(arvif, info);
2052 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2054 if (info->use_cts_prot)
2059 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2060 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2063 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2066 ath10k_dbg(ATH10K_DBG_MAC,
2067 "Set CTS prot: %d for VDEV: %d\n",
2068 cts_prot, arvif->vdev_id);
2071 if (changed & BSS_CHANGED_ERP_SLOT) {
2073 if (info->use_short_slot)
2074 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2077 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2079 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2080 WMI_VDEV_PARAM_SLOT_TIME,
2083 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2086 ath10k_dbg(ATH10K_DBG_MAC,
2087 "Set slottime: %d for VDEV: %d\n",
2088 slottime, arvif->vdev_id);
2091 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2093 if (info->use_short_preamble)
2094 preamble = WMI_VDEV_PREAMBLE_SHORT;
2096 preamble = WMI_VDEV_PREAMBLE_LONG;
2098 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2099 WMI_VDEV_PARAM_PREAMBLE,
2102 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2105 ath10k_dbg(ATH10K_DBG_MAC,
2106 "Set preamble: %d for VDEV: %d\n",
2107 preamble, arvif->vdev_id);
2110 if (changed & BSS_CHANGED_ASSOC) {
2112 ath10k_bss_assoc(hw, vif, info);
2115 mutex_unlock(&ar->conf_mutex);
2118 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2119 struct ieee80211_vif *vif,
2120 struct cfg80211_scan_request *req)
2122 struct ath10k *ar = hw->priv;
2123 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2124 struct wmi_start_scan_arg arg;
2128 mutex_lock(&ar->conf_mutex);
2130 spin_lock_bh(&ar->data_lock);
2131 if (ar->scan.in_progress) {
2132 spin_unlock_bh(&ar->data_lock);
2137 INIT_COMPLETION(ar->scan.started);
2138 INIT_COMPLETION(ar->scan.completed);
2139 ar->scan.in_progress = true;
2140 ar->scan.aborting = false;
2141 ar->scan.is_roc = false;
2142 ar->scan.vdev_id = arvif->vdev_id;
2143 spin_unlock_bh(&ar->data_lock);
2145 memset(&arg, 0, sizeof(arg));
2146 ath10k_wmi_start_scan_init(ar, &arg);
2147 arg.vdev_id = arvif->vdev_id;
2148 arg.scan_id = ATH10K_SCAN_ID;
2151 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2154 arg.ie_len = req->ie_len;
2155 memcpy(arg.ie, req->ie, arg.ie_len);
2159 arg.n_ssids = req->n_ssids;
2160 for (i = 0; i < arg.n_ssids; i++) {
2161 arg.ssids[i].len = req->ssids[i].ssid_len;
2162 arg.ssids[i].ssid = req->ssids[i].ssid;
2166 if (req->n_channels) {
2167 arg.n_channels = req->n_channels;
2168 for (i = 0; i < arg.n_channels; i++)
2169 arg.channels[i] = req->channels[i]->center_freq;
2172 ret = ath10k_start_scan(ar, &arg);
2174 ath10k_warn("could not start hw scan (%d)\n", ret);
2175 spin_lock_bh(&ar->data_lock);
2176 ar->scan.in_progress = false;
2177 spin_unlock_bh(&ar->data_lock);
2181 mutex_unlock(&ar->conf_mutex);
2185 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2186 struct ieee80211_vif *vif)
2188 struct ath10k *ar = hw->priv;
2191 mutex_lock(&ar->conf_mutex);
2192 ret = ath10k_abort_scan(ar);
2194 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2196 ieee80211_scan_completed(hw, 1 /* aborted */);
2198 mutex_unlock(&ar->conf_mutex);
2201 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2202 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2203 struct ieee80211_key_conf *key)
2205 struct ath10k *ar = hw->priv;
2206 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2207 struct ath10k_peer *peer;
2208 const u8 *peer_addr;
2209 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2210 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2213 if (key->keyidx > WMI_MAX_KEY_INDEX)
2216 mutex_lock(&ar->conf_mutex);
2219 peer_addr = sta->addr;
2220 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2221 peer_addr = vif->bss_conf.bssid;
2223 peer_addr = vif->addr;
2225 key->hw_key_idx = key->keyidx;
2227 /* the peer should not disappear in mid-way (unless FW goes awry) since
2228 * we already hold conf_mutex. we just make sure its there now. */
2229 spin_lock_bh(&ar->data_lock);
2230 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2231 spin_unlock_bh(&ar->data_lock);
2234 if (cmd == SET_KEY) {
2235 ath10k_warn("cannot install key for non-existent peer %pM\n",
2240 /* if the peer doesn't exist there is no key to disable
2248 arvif->wep_keys[key->keyidx] = key;
2250 arvif->wep_keys[key->keyidx] = NULL;
2252 if (cmd == DISABLE_KEY)
2253 ath10k_clear_vdev_key(arvif, key);
2256 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2258 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2262 spin_lock_bh(&ar->data_lock);
2263 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2264 if (peer && cmd == SET_KEY)
2265 peer->keys[key->keyidx] = key;
2266 else if (peer && cmd == DISABLE_KEY)
2267 peer->keys[key->keyidx] = NULL;
2268 else if (peer == NULL)
2269 /* impossible unless FW goes crazy */
2270 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2271 spin_unlock_bh(&ar->data_lock);
2274 mutex_unlock(&ar->conf_mutex);
2278 static int ath10k_sta_state(struct ieee80211_hw *hw,
2279 struct ieee80211_vif *vif,
2280 struct ieee80211_sta *sta,
2281 enum ieee80211_sta_state old_state,
2282 enum ieee80211_sta_state new_state)
2284 struct ath10k *ar = hw->priv;
2285 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2288 mutex_lock(&ar->conf_mutex);
2290 if (old_state == IEEE80211_STA_NOTEXIST &&
2291 new_state == IEEE80211_STA_NONE &&
2292 vif->type != NL80211_IFTYPE_STATION) {
2294 * New station addition.
2296 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2298 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2299 sta->addr, arvif->vdev_id);
2301 ath10k_dbg(ATH10K_DBG_MAC,
2302 "Added peer: %pM for VDEV: %d\n",
2303 sta->addr, arvif->vdev_id);
2304 } else if ((old_state == IEEE80211_STA_NONE &&
2305 new_state == IEEE80211_STA_NOTEXIST)) {
2307 * Existing station deletion.
2309 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2311 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2312 sta->addr, arvif->vdev_id);
2314 ath10k_dbg(ATH10K_DBG_MAC,
2315 "Removed peer: %pM for VDEV: %d\n",
2316 sta->addr, arvif->vdev_id);
2318 if (vif->type == NL80211_IFTYPE_STATION)
2319 ath10k_bss_disassoc(hw, vif);
2320 } else if (old_state == IEEE80211_STA_AUTH &&
2321 new_state == IEEE80211_STA_ASSOC &&
2322 (vif->type == NL80211_IFTYPE_AP ||
2323 vif->type == NL80211_IFTYPE_ADHOC)) {
2327 ret = ath10k_station_assoc(ar, arvif, sta);
2329 ath10k_warn("Failed to associate station: %pM\n",
2332 ath10k_dbg(ATH10K_DBG_MAC,
2333 "Station %pM moved to assoc state\n",
2335 } else if (old_state == IEEE80211_STA_ASSOC &&
2336 new_state == IEEE80211_STA_AUTH &&
2337 (vif->type == NL80211_IFTYPE_AP ||
2338 vif->type == NL80211_IFTYPE_ADHOC)) {
2342 ret = ath10k_station_disassoc(ar, arvif, sta);
2344 ath10k_warn("Failed to disassociate station: %pM\n",
2347 ath10k_dbg(ATH10K_DBG_MAC,
2348 "Station %pM moved to disassociated state\n",
2352 mutex_unlock(&ar->conf_mutex);
2356 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2357 u16 ac, bool enable)
2359 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2363 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2367 case IEEE80211_AC_VO:
2368 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2369 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2371 case IEEE80211_AC_VI:
2372 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2373 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2375 case IEEE80211_AC_BE:
2376 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2377 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2379 case IEEE80211_AC_BK:
2380 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2381 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2386 arvif->u.sta.uapsd |= value;
2388 arvif->u.sta.uapsd &= ~value;
2390 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2391 WMI_STA_PS_PARAM_UAPSD,
2392 arvif->u.sta.uapsd);
2394 ath10k_warn("could not set uapsd params %d\n", ret);
2398 if (arvif->u.sta.uapsd)
2399 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2401 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2403 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2404 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2407 ath10k_warn("could not set rx wake param %d\n", ret);
2413 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2414 struct ieee80211_vif *vif, u16 ac,
2415 const struct ieee80211_tx_queue_params *params)
2417 struct ath10k *ar = hw->priv;
2418 struct wmi_wmm_params_arg *p = NULL;
2421 mutex_lock(&ar->conf_mutex);
2424 case IEEE80211_AC_VO:
2425 p = &ar->wmm_params.ac_vo;
2427 case IEEE80211_AC_VI:
2428 p = &ar->wmm_params.ac_vi;
2430 case IEEE80211_AC_BE:
2431 p = &ar->wmm_params.ac_be;
2433 case IEEE80211_AC_BK:
2434 p = &ar->wmm_params.ac_bk;
2443 p->cwmin = params->cw_min;
2444 p->cwmax = params->cw_max;
2445 p->aifs = params->aifs;
2448 * The channel time duration programmed in the HW is in absolute
2449 * microseconds, while mac80211 gives the txop in units of
2452 p->txop = params->txop * 32;
2454 /* FIXME: FW accepts wmm params per hw, not per vif */
2455 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2457 ath10k_warn("could not set wmm params %d\n", ret);
2461 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2463 ath10k_warn("could not set sta uapsd %d\n", ret);
2466 mutex_unlock(&ar->conf_mutex);
2470 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2472 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2473 struct ieee80211_vif *vif,
2474 struct ieee80211_channel *chan,
2476 enum ieee80211_roc_type type)
2478 struct ath10k *ar = hw->priv;
2479 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2480 struct wmi_start_scan_arg arg;
2483 mutex_lock(&ar->conf_mutex);
2485 spin_lock_bh(&ar->data_lock);
2486 if (ar->scan.in_progress) {
2487 spin_unlock_bh(&ar->data_lock);
2492 INIT_COMPLETION(ar->scan.started);
2493 INIT_COMPLETION(ar->scan.completed);
2494 INIT_COMPLETION(ar->scan.on_channel);
2495 ar->scan.in_progress = true;
2496 ar->scan.aborting = false;
2497 ar->scan.is_roc = true;
2498 ar->scan.vdev_id = arvif->vdev_id;
2499 ar->scan.roc_freq = chan->center_freq;
2500 spin_unlock_bh(&ar->data_lock);
2502 memset(&arg, 0, sizeof(arg));
2503 ath10k_wmi_start_scan_init(ar, &arg);
2504 arg.vdev_id = arvif->vdev_id;
2505 arg.scan_id = ATH10K_SCAN_ID;
2507 arg.channels[0] = chan->center_freq;
2508 arg.dwell_time_active = duration;
2509 arg.dwell_time_passive = duration;
2510 arg.max_scan_time = 2 * duration;
2511 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2512 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2514 ret = ath10k_start_scan(ar, &arg);
2516 ath10k_warn("could not start roc scan (%d)\n", ret);
2517 spin_lock_bh(&ar->data_lock);
2518 ar->scan.in_progress = false;
2519 spin_unlock_bh(&ar->data_lock);
2523 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2525 ath10k_warn("could not switch to channel for roc scan\n");
2526 ath10k_abort_scan(ar);
2533 mutex_unlock(&ar->conf_mutex);
2537 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2539 struct ath10k *ar = hw->priv;
2541 mutex_lock(&ar->conf_mutex);
2542 ath10k_abort_scan(ar);
2543 mutex_unlock(&ar->conf_mutex);
2549 * Both RTS and Fragmentation threshold are interface-specific
2550 * in ath10k, but device-specific in mac80211.
2552 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2554 struct ath10k_generic_iter *ar_iter = data;
2555 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2556 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2558 rts = min_t(u32, rts, ATH10K_RTS_MAX);
2560 ar_iter->ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2561 WMI_VDEV_PARAM_RTS_THRESHOLD,
2564 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2567 ath10k_dbg(ATH10K_DBG_MAC,
2568 "Set RTS threshold: %d for VDEV: %d\n",
2569 rts, arvif->vdev_id);
2572 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2574 struct ath10k_generic_iter ar_iter;
2575 struct ath10k *ar = hw->priv;
2577 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2580 mutex_lock(&ar->conf_mutex);
2581 ieee80211_iterate_active_interfaces(hw, IEEE80211_IFACE_ITER_RESUME_ALL,
2582 ath10k_set_rts_iter, &ar_iter);
2583 mutex_unlock(&ar->conf_mutex);
2588 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2590 struct ath10k_generic_iter *ar_iter = data;
2591 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2592 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2595 frag = clamp_t(u32, frag,
2596 ATH10K_FRAGMT_THRESHOLD_MIN,
2597 ATH10K_FRAGMT_THRESHOLD_MAX);
2599 ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2600 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
2605 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2608 ath10k_dbg(ATH10K_DBG_MAC,
2609 "Set frag threshold: %d for VDEV: %d\n",
2610 frag, arvif->vdev_id);
2613 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2615 struct ath10k_generic_iter ar_iter;
2616 struct ath10k *ar = hw->priv;
2618 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2621 mutex_lock(&ar->conf_mutex);
2622 ieee80211_iterate_active_interfaces(hw, IEEE80211_IFACE_ITER_RESUME_ALL,
2623 ath10k_set_frag_iter, &ar_iter);
2624 mutex_unlock(&ar->conf_mutex);
2629 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2631 struct ath10k *ar = hw->priv;
2634 /* mac80211 doesn't care if we really xmit queued frames or not
2635 * we'll collect those frames either way if we stop/delete vdevs */
2639 ret = wait_event_timeout(ar->htt->empty_tx_wq, ({
2641 spin_lock_bh(&ar->htt->tx_lock);
2642 empty = bitmap_empty(ar->htt->used_msdu_ids,
2643 ar->htt->max_num_pending_tx);
2644 spin_unlock_bh(&ar->htt->tx_lock);
2646 }), ATH10K_FLUSH_TIMEOUT_HZ);
2648 ath10k_warn("tx not flushed\n");
2651 /* TODO: Implement this function properly
2652 * For now it is needed to reply to Probe Requests in IBSS mode.
2653 * Propably we need this information from FW.
2655 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2660 static const struct ieee80211_ops ath10k_ops = {
2662 .start = ath10k_start,
2663 .stop = ath10k_stop,
2664 .config = ath10k_config,
2665 .add_interface = ath10k_add_interface,
2666 .remove_interface = ath10k_remove_interface,
2667 .configure_filter = ath10k_configure_filter,
2668 .bss_info_changed = ath10k_bss_info_changed,
2669 .hw_scan = ath10k_hw_scan,
2670 .cancel_hw_scan = ath10k_cancel_hw_scan,
2671 .set_key = ath10k_set_key,
2672 .sta_state = ath10k_sta_state,
2673 .conf_tx = ath10k_conf_tx,
2674 .remain_on_channel = ath10k_remain_on_channel,
2675 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
2676 .set_rts_threshold = ath10k_set_rts_threshold,
2677 .set_frag_threshold = ath10k_set_frag_threshold,
2678 .flush = ath10k_flush,
2679 .tx_last_beacon = ath10k_tx_last_beacon,
2682 #define RATETAB_ENT(_rate, _rateid, _flags) { \
2683 .bitrate = (_rate), \
2684 .flags = (_flags), \
2685 .hw_value = (_rateid), \
2688 #define CHAN2G(_channel, _freq, _flags) { \
2689 .band = IEEE80211_BAND_2GHZ, \
2690 .hw_value = (_channel), \
2691 .center_freq = (_freq), \
2692 .flags = (_flags), \
2693 .max_antenna_gain = 0, \
2697 #define CHAN5G(_channel, _freq, _flags) { \
2698 .band = IEEE80211_BAND_5GHZ, \
2699 .hw_value = (_channel), \
2700 .center_freq = (_freq), \
2701 .flags = (_flags), \
2702 .max_antenna_gain = 0, \
2706 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
2716 CHAN2G(10, 2457, 0),
2717 CHAN2G(11, 2462, 0),
2718 CHAN2G(12, 2467, 0),
2719 CHAN2G(13, 2472, 0),
2720 CHAN2G(14, 2484, 0),
2723 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
2724 CHAN5G(36, 5180, 14),
2725 CHAN5G(40, 5200, 15),
2726 CHAN5G(44, 5220, 16),
2727 CHAN5G(48, 5240, 17),
2728 CHAN5G(52, 5260, 18),
2729 CHAN5G(56, 5280, 19),
2730 CHAN5G(60, 5300, 20),
2731 CHAN5G(64, 5320, 21),
2732 CHAN5G(100, 5500, 22),
2733 CHAN5G(104, 5520, 23),
2734 CHAN5G(108, 5540, 24),
2735 CHAN5G(112, 5560, 25),
2736 CHAN5G(116, 5580, 26),
2737 CHAN5G(120, 5600, 27),
2738 CHAN5G(124, 5620, 28),
2739 CHAN5G(128, 5640, 29),
2740 CHAN5G(132, 5660, 30),
2741 CHAN5G(136, 5680, 31),
2742 CHAN5G(140, 5700, 32),
2743 CHAN5G(149, 5745, 33),
2744 CHAN5G(153, 5765, 34),
2745 CHAN5G(157, 5785, 35),
2746 CHAN5G(161, 5805, 36),
2747 CHAN5G(165, 5825, 37),
2750 static struct ieee80211_rate ath10k_rates[] = {
2752 RATETAB_ENT(10, 0x82, 0),
2753 RATETAB_ENT(20, 0x84, 0),
2754 RATETAB_ENT(55, 0x8b, 0),
2755 RATETAB_ENT(110, 0x96, 0),
2757 RATETAB_ENT(60, 0x0c, 0),
2758 RATETAB_ENT(90, 0x12, 0),
2759 RATETAB_ENT(120, 0x18, 0),
2760 RATETAB_ENT(180, 0x24, 0),
2761 RATETAB_ENT(240, 0x30, 0),
2762 RATETAB_ENT(360, 0x48, 0),
2763 RATETAB_ENT(480, 0x60, 0),
2764 RATETAB_ENT(540, 0x6c, 0),
2767 #define ath10k_a_rates (ath10k_rates + 4)
2768 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
2769 #define ath10k_g_rates (ath10k_rates + 0)
2770 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
2772 struct ath10k *ath10k_mac_create(void)
2774 struct ieee80211_hw *hw;
2777 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
2787 void ath10k_mac_destroy(struct ath10k *ar)
2789 ieee80211_free_hw(ar->hw);
2792 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
2795 .types = BIT(NL80211_IFTYPE_STATION)
2796 | BIT(NL80211_IFTYPE_P2P_CLIENT)
2797 | BIT(NL80211_IFTYPE_P2P_GO)
2798 | BIT(NL80211_IFTYPE_AP)
2802 static const struct ieee80211_iface_combination ath10k_if_comb = {
2803 .limits = ath10k_if_limits,
2804 .n_limits = ARRAY_SIZE(ath10k_if_limits),
2805 .max_interfaces = 8,
2806 .num_different_channels = 1,
2807 .beacon_int_infra_match = true,
2810 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
2812 struct ieee80211_sta_vht_cap vht_cap = {0};
2815 vht_cap.vht_supported = 1;
2816 vht_cap.cap = ar->vht_cap_info;
2818 /* FIXME: check dynamically how many streams board supports */
2819 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
2820 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
2821 IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
2822 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
2823 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
2824 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
2825 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
2826 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
2828 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
2829 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
2834 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
2837 struct ieee80211_sta_ht_cap ht_cap = {0};
2839 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
2842 ht_cap.ht_supported = 1;
2843 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2844 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
2845 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2846 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
2847 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
2849 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
2850 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2852 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
2853 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2855 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
2858 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
2859 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
2864 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
2865 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2867 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
2870 stbc = ar->ht_cap_info;
2871 stbc &= WMI_HT_CAP_RX_STBC;
2872 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
2873 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
2874 stbc &= IEEE80211_HT_CAP_RX_STBC;
2879 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
2880 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
2882 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
2883 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
2885 /* max AMSDU is implicitly taken from vht_cap_info */
2886 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
2887 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2889 for (i = 0; i < WMI_MAX_SPATIAL_STREAM; i++)
2890 ht_cap.mcs.rx_mask[i] = 0xFF;
2892 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
2898 static void ath10k_get_arvif_iter(void *data, u8 *mac,
2899 struct ieee80211_vif *vif)
2901 struct ath10k_vif_iter *arvif_iter = data;
2902 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2904 if (arvif->vdev_id == arvif_iter->vdev_id)
2905 arvif_iter->arvif = arvif;
2908 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
2910 struct ath10k_vif_iter arvif_iter;
2913 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
2914 arvif_iter.vdev_id = vdev_id;
2916 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
2917 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2919 ath10k_get_arvif_iter,
2921 if (!arvif_iter.arvif) {
2922 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
2926 return arvif_iter.arvif;
2929 int ath10k_mac_register(struct ath10k *ar)
2931 struct ieee80211_supported_band *band;
2932 struct ieee80211_sta_vht_cap vht_cap;
2933 struct ieee80211_sta_ht_cap ht_cap;
2937 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
2939 SET_IEEE80211_DEV(ar->hw, ar->dev);
2941 ht_cap = ath10k_get_ht_cap(ar);
2942 vht_cap = ath10k_create_vht_cap(ar);
2944 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
2945 channels = kmemdup(ath10k_2ghz_channels,
2946 sizeof(ath10k_2ghz_channels),
2951 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
2952 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
2953 band->channels = channels;
2954 band->n_bitrates = ath10k_g_rates_size;
2955 band->bitrates = ath10k_g_rates;
2956 band->ht_cap = ht_cap;
2958 /* vht is not supported in 2.4 GHz */
2960 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
2963 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
2964 channels = kmemdup(ath10k_5ghz_channels,
2965 sizeof(ath10k_5ghz_channels),
2968 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
2969 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
2970 kfree(band->channels);
2975 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
2976 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
2977 band->channels = channels;
2978 band->n_bitrates = ath10k_a_rates_size;
2979 band->bitrates = ath10k_a_rates;
2980 band->ht_cap = ht_cap;
2981 band->vht_cap = vht_cap;
2982 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
2985 ar->hw->wiphy->interface_modes =
2986 BIT(NL80211_IFTYPE_STATION) |
2987 BIT(NL80211_IFTYPE_ADHOC) |
2988 BIT(NL80211_IFTYPE_AP) |
2989 BIT(NL80211_IFTYPE_P2P_CLIENT) |
2990 BIT(NL80211_IFTYPE_P2P_GO);
2992 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
2993 IEEE80211_HW_SUPPORTS_PS |
2994 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
2995 IEEE80211_HW_SUPPORTS_UAPSD |
2996 IEEE80211_HW_MFP_CAPABLE |
2997 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
2998 IEEE80211_HW_HAS_RATE_CONTROL |
2999 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3000 IEEE80211_HW_WANT_MONITOR_VIF |
3001 IEEE80211_HW_AP_LINK_PS;
3003 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3004 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3006 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3007 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3008 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3011 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3012 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3014 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3016 ar->hw->channel_change_time = 5000;
3017 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3019 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3020 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3022 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3024 * on LL hardware queues are managed entirely by the FW
3025 * so we only advertise to mac we can do the queues thing
3029 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3030 ar->hw->wiphy->n_iface_combinations = 1;
3032 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3033 ath10k_reg_notifier);
3035 ath10k_err("Regulatory initialization failed\n");
3039 ret = ieee80211_register_hw(ar->hw);
3041 ath10k_err("ieee80211 registration failed: %d\n", ret);
3045 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3046 ret = regulatory_hint(ar->hw->wiphy,
3047 ar->ath_common.regulatory.alpha2);
3054 ieee80211_unregister_hw(ar->hw);
3058 void ath10k_mac_unregister(struct ath10k *ar)
3060 ieee80211_unregister_hw(ar->hw);
3062 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3063 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3065 SET_IEEE80211_DEV(ar->hw, NULL);