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 lockdep_assert_held(&arvif->ar->conf_mutex);
48 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
49 arg.key_flags = WMI_KEY_PAIRWISE;
51 arg.key_flags = WMI_KEY_GROUP;
53 switch (key->cipher) {
54 case WLAN_CIPHER_SUITE_CCMP:
55 arg.key_cipher = WMI_CIPHER_AES_CCM;
56 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 case WLAN_CIPHER_SUITE_TKIP:
59 arg.key_cipher = WMI_CIPHER_TKIP;
60 arg.key_txmic_len = 8;
61 arg.key_rxmic_len = 8;
63 case WLAN_CIPHER_SUITE_WEP40:
64 case WLAN_CIPHER_SUITE_WEP104:
65 arg.key_cipher = WMI_CIPHER_WEP;
66 /* AP/IBSS mode requires self-key to be groupwise
67 * Otherwise pairwise key must be set */
68 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
69 arg.key_flags = WMI_KEY_PAIRWISE;
72 ath10k_warn("cipher %d is not supported\n", key->cipher);
76 if (cmd == DISABLE_KEY) {
77 arg.key_cipher = WMI_CIPHER_NONE;
81 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
84 static int ath10k_install_key(struct ath10k_vif *arvif,
85 struct ieee80211_key_conf *key,
89 struct ath10k *ar = arvif->ar;
92 lockdep_assert_held(&ar->conf_mutex);
94 INIT_COMPLETION(ar->install_key_done);
96 ret = ath10k_send_key(arvif, key, cmd, macaddr);
100 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
107 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
110 struct ath10k *ar = arvif->ar;
111 struct ath10k_peer *peer;
115 lockdep_assert_held(&ar->conf_mutex);
117 spin_lock_bh(&ar->data_lock);
118 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
119 spin_unlock_bh(&ar->data_lock);
124 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
125 if (arvif->wep_keys[i] == NULL)
128 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
133 peer->keys[i] = arvif->wep_keys[i];
139 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
142 struct ath10k *ar = arvif->ar;
143 struct ath10k_peer *peer;
148 lockdep_assert_held(&ar->conf_mutex);
150 spin_lock_bh(&ar->data_lock);
151 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
152 spin_unlock_bh(&ar->data_lock);
157 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
158 if (peer->keys[i] == NULL)
161 ret = ath10k_install_key(arvif, peer->keys[i],
163 if (ret && first_errno == 0)
167 ath10k_warn("could not remove peer wep key %d (%d)\n",
170 peer->keys[i] = NULL;
176 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
177 struct ieee80211_key_conf *key)
179 struct ath10k *ar = arvif->ar;
180 struct ath10k_peer *peer;
186 lockdep_assert_held(&ar->conf_mutex);
189 /* since ath10k_install_key we can't hold data_lock all the
190 * time, so we try to remove the keys incrementally */
191 spin_lock_bh(&ar->data_lock);
193 list_for_each_entry(peer, &ar->peers, list) {
194 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
195 if (peer->keys[i] == key) {
196 memcpy(addr, peer->addr, ETH_ALEN);
197 peer->keys[i] = NULL;
202 if (i < ARRAY_SIZE(peer->keys))
205 spin_unlock_bh(&ar->data_lock);
207 if (i == ARRAY_SIZE(peer->keys))
210 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
211 if (ret && first_errno == 0)
215 ath10k_warn("could not remove key for %pM\n", addr);
222 /*********************/
223 /* General utilities */
224 /*********************/
226 static inline enum wmi_phy_mode
227 chan_to_phymode(const struct cfg80211_chan_def *chandef)
229 enum wmi_phy_mode phymode = MODE_UNKNOWN;
231 switch (chandef->chan->band) {
232 case IEEE80211_BAND_2GHZ:
233 switch (chandef->width) {
234 case NL80211_CHAN_WIDTH_20_NOHT:
237 case NL80211_CHAN_WIDTH_20:
238 phymode = MODE_11NG_HT20;
240 case NL80211_CHAN_WIDTH_40:
241 phymode = MODE_11NG_HT40;
243 case NL80211_CHAN_WIDTH_5:
244 case NL80211_CHAN_WIDTH_10:
245 case NL80211_CHAN_WIDTH_80:
246 case NL80211_CHAN_WIDTH_80P80:
247 case NL80211_CHAN_WIDTH_160:
248 phymode = MODE_UNKNOWN;
252 case IEEE80211_BAND_5GHZ:
253 switch (chandef->width) {
254 case NL80211_CHAN_WIDTH_20_NOHT:
257 case NL80211_CHAN_WIDTH_20:
258 phymode = MODE_11NA_HT20;
260 case NL80211_CHAN_WIDTH_40:
261 phymode = MODE_11NA_HT40;
263 case NL80211_CHAN_WIDTH_80:
264 phymode = MODE_11AC_VHT80;
266 case NL80211_CHAN_WIDTH_5:
267 case NL80211_CHAN_WIDTH_10:
268 case NL80211_CHAN_WIDTH_80P80:
269 case NL80211_CHAN_WIDTH_160:
270 phymode = MODE_UNKNOWN;
278 WARN_ON(phymode == MODE_UNKNOWN);
282 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
285 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
286 * 0 for no restriction
295 switch (mpdudensity) {
301 /* Our lower layer calculations limit our precision to
317 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
321 lockdep_assert_held(&ar->conf_mutex);
323 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
327 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
334 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
338 lockdep_assert_held(&ar->conf_mutex);
340 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
344 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
351 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
353 struct ath10k_peer *peer, *tmp;
355 lockdep_assert_held(&ar->conf_mutex);
357 spin_lock_bh(&ar->data_lock);
358 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
359 if (peer->vdev_id != vdev_id)
362 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
363 peer->addr, vdev_id);
365 list_del(&peer->list);
368 spin_unlock_bh(&ar->data_lock);
371 /************************/
372 /* Interface management */
373 /************************/
375 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
379 lockdep_assert_held(&ar->conf_mutex);
381 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
382 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
389 static int ath10k_vdev_start(struct ath10k_vif *arvif)
391 struct ath10k *ar = arvif->ar;
392 struct ieee80211_conf *conf = &ar->hw->conf;
393 struct ieee80211_channel *channel = conf->chandef.chan;
394 struct wmi_vdev_start_request_arg arg = {};
397 lockdep_assert_held(&ar->conf_mutex);
399 INIT_COMPLETION(ar->vdev_setup_done);
401 arg.vdev_id = arvif->vdev_id;
402 arg.dtim_period = arvif->dtim_period;
403 arg.bcn_intval = arvif->beacon_interval;
405 arg.channel.freq = channel->center_freq;
407 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
409 arg.channel.mode = chan_to_phymode(&conf->chandef);
411 arg.channel.min_power = channel->max_power * 3;
412 arg.channel.max_power = channel->max_power * 4;
413 arg.channel.max_reg_power = channel->max_reg_power * 4;
414 arg.channel.max_antenna_gain = channel->max_antenna_gain;
416 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
417 arg.ssid = arvif->u.ap.ssid;
418 arg.ssid_len = arvif->u.ap.ssid_len;
419 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
420 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
421 arg.ssid = arvif->vif->bss_conf.ssid;
422 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
425 ret = ath10k_wmi_vdev_start(ar, &arg);
427 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
431 ret = ath10k_vdev_setup_sync(ar);
433 ath10k_warn("vdev setup failed %d\n", ret);
440 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
442 struct ath10k *ar = arvif->ar;
445 lockdep_assert_held(&ar->conf_mutex);
447 INIT_COMPLETION(ar->vdev_setup_done);
449 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
451 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
455 ret = ath10k_vdev_setup_sync(ar);
457 ath10k_warn("vdev setup failed %d\n", ret);
464 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
466 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
467 struct wmi_vdev_start_request_arg arg = {};
468 enum nl80211_channel_type type;
471 lockdep_assert_held(&ar->conf_mutex);
473 type = cfg80211_get_chandef_type(&ar->hw->conf.chandef);
475 arg.vdev_id = vdev_id;
476 arg.channel.freq = channel->center_freq;
477 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
479 /* TODO setup this dynamically, what in case we
480 don't have any vifs? */
481 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
483 arg.channel.min_power = channel->max_power * 3;
484 arg.channel.max_power = channel->max_power * 4;
485 arg.channel.max_reg_power = channel->max_reg_power * 4;
486 arg.channel.max_antenna_gain = channel->max_antenna_gain;
488 ret = ath10k_wmi_vdev_start(ar, &arg);
490 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
494 ret = ath10k_vdev_setup_sync(ar);
496 ath10k_warn("Monitor vdev setup failed %d\n", ret);
500 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
502 ath10k_warn("Monitor vdev up failed: %d\n", ret);
506 ar->monitor_vdev_id = vdev_id;
507 ar->monitor_enabled = true;
512 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
514 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
519 static int ath10k_monitor_stop(struct ath10k *ar)
523 lockdep_assert_held(&ar->conf_mutex);
525 /* For some reasons, ath10k_wmi_vdev_down() here couse
526 * often ath10k_wmi_vdev_stop() to fail. Next we could
527 * not run monitor vdev and driver reload
528 * required. Don't see such problems we skip
529 * ath10k_wmi_vdev_down() here.
532 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
534 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
536 ret = ath10k_vdev_setup_sync(ar);
538 ath10k_warn("Monitor_down sync failed: %d\n", ret);
540 ar->monitor_enabled = false;
544 static int ath10k_monitor_create(struct ath10k *ar)
548 lockdep_assert_held(&ar->conf_mutex);
550 if (ar->monitor_present) {
551 ath10k_warn("Monitor mode already enabled\n");
555 bit = ffs(ar->free_vdev_map);
557 ath10k_warn("No free VDEV slots\n");
561 ar->monitor_vdev_id = bit - 1;
562 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
564 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
565 WMI_VDEV_TYPE_MONITOR,
568 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
572 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface created, vdev id: %d\n",
573 ar->monitor_vdev_id);
575 ar->monitor_present = true;
580 * Restore the ID to the global map.
582 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
586 static int ath10k_monitor_destroy(struct ath10k *ar)
590 lockdep_assert_held(&ar->conf_mutex);
592 if (!ar->monitor_present)
595 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
597 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
601 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
602 ar->monitor_present = false;
604 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface destroyed, vdev id: %d\n",
605 ar->monitor_vdev_id);
609 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
610 struct ieee80211_bss_conf *info)
614 lockdep_assert_held(&arvif->ar->conf_mutex);
616 if (!info->enable_beacon) {
617 ath10k_vdev_stop(arvif);
621 arvif->tx_seq_no = 0x1000;
623 ret = ath10k_vdev_start(arvif);
627 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
629 ath10k_warn("Failed to bring up VDEV: %d\n",
633 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d up\n", arvif->vdev_id);
636 static void ath10k_control_ibss(struct ath10k_vif *arvif,
637 struct ieee80211_bss_conf *info,
638 const u8 self_peer[ETH_ALEN])
642 lockdep_assert_held(&arvif->ar->conf_mutex);
644 if (!info->ibss_joined) {
645 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
647 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
648 self_peer, arvif->vdev_id, ret);
650 if (is_zero_ether_addr(arvif->u.ibss.bssid))
653 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
654 arvif->u.ibss.bssid);
656 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
657 arvif->u.ibss.bssid, arvif->vdev_id, ret);
661 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
666 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
668 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
669 self_peer, arvif->vdev_id, ret);
673 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
674 WMI_VDEV_PARAM_ATIM_WINDOW,
675 ATH10K_DEFAULT_ATIM);
677 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
678 arvif->vdev_id, ret);
682 * Review this when mac80211 gains per-interface powersave support.
684 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
686 struct ath10k_generic_iter *ar_iter = data;
687 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
688 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
689 enum wmi_sta_powersave_param param;
690 enum wmi_sta_ps_mode psmode;
693 lockdep_assert_held(&arvif->ar->conf_mutex);
695 if (vif->type != NL80211_IFTYPE_STATION)
698 if (conf->flags & IEEE80211_CONF_PS) {
699 psmode = WMI_STA_PS_MODE_ENABLED;
700 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
702 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
705 conf->dynamic_ps_timeout);
707 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
714 psmode = WMI_STA_PS_MODE_DISABLED;
717 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
720 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
721 psmode, arvif->vdev_id);
723 ath10k_dbg(ATH10K_DBG_MAC, "Set PS Mode: %d for VDEV: %d\n",
724 psmode, arvif->vdev_id);
727 /**********************/
728 /* Station management */
729 /**********************/
731 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
732 struct ath10k_vif *arvif,
733 struct ieee80211_sta *sta,
734 struct ieee80211_bss_conf *bss_conf,
735 struct wmi_peer_assoc_complete_arg *arg)
737 lockdep_assert_held(&ar->conf_mutex);
739 memcpy(arg->addr, sta->addr, ETH_ALEN);
740 arg->vdev_id = arvif->vdev_id;
741 arg->peer_aid = sta->aid;
742 arg->peer_flags |= WMI_PEER_AUTH;
744 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
746 * Seems FW have problems with Power Save in STA
747 * mode when we setup this parameter to high (eg. 5).
748 * Often we see that FW don't send NULL (with clean P flags)
749 * frame even there is info about buffered frames in beacons.
750 * Sometimes we have to wait more than 10 seconds before FW
751 * will wakeup. Often sending one ping from AP to our device
752 * just fail (more than 50%).
754 * Seems setting this FW parameter to 1 couse FW
755 * will check every beacon and will wakup immediately
756 * after detection buffered data.
758 arg->peer_listen_intval = 1;
760 arg->peer_listen_intval = ar->hw->conf.listen_interval;
762 arg->peer_num_spatial_streams = 1;
765 * The assoc capabilities are available only in managed mode.
767 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
768 arg->peer_caps = bss_conf->assoc_capability;
771 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
772 struct ath10k_vif *arvif,
773 struct wmi_peer_assoc_complete_arg *arg)
775 struct ieee80211_vif *vif = arvif->vif;
776 struct ieee80211_bss_conf *info = &vif->bss_conf;
777 struct cfg80211_bss *bss;
778 const u8 *rsnie = NULL;
779 const u8 *wpaie = NULL;
781 lockdep_assert_held(&ar->conf_mutex);
783 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
784 info->bssid, NULL, 0, 0, 0);
786 const struct cfg80211_bss_ies *ies;
789 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
791 ies = rcu_dereference(bss->ies);
793 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
794 WLAN_OUI_TYPE_MICROSOFT_WPA,
798 cfg80211_put_bss(ar->hw->wiphy, bss);
801 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
802 if (rsnie || wpaie) {
803 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
804 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
808 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
809 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
813 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
814 struct ieee80211_sta *sta,
815 struct wmi_peer_assoc_complete_arg *arg)
817 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
818 const struct ieee80211_supported_band *sband;
819 const struct ieee80211_rate *rates;
823 lockdep_assert_held(&ar->conf_mutex);
825 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
826 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
827 rates = sband->bitrates;
829 rateset->num_rates = 0;
831 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
835 rateset->rates[rateset->num_rates] = rates->hw_value;
836 rateset->num_rates++;
840 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
841 struct ieee80211_sta *sta,
842 struct wmi_peer_assoc_complete_arg *arg)
844 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
848 lockdep_assert_held(&ar->conf_mutex);
850 if (!ht_cap->ht_supported)
853 arg->peer_flags |= WMI_PEER_HT;
854 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
855 ht_cap->ampdu_factor)) - 1;
857 arg->peer_mpdu_density =
858 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
860 arg->peer_ht_caps = ht_cap->cap;
861 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
863 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
864 arg->peer_flags |= WMI_PEER_LDPC;
866 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
867 arg->peer_flags |= WMI_PEER_40MHZ;
868 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
871 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
872 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
874 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
875 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
877 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
878 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
879 arg->peer_flags |= WMI_PEER_STBC;
882 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
884 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
885 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
886 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
887 arg->peer_rate_caps |= stbc;
888 arg->peer_flags |= WMI_PEER_STBC;
891 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
892 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
894 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
895 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
896 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
897 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
898 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
899 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
902 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
903 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
904 else if (ht_cap->mcs.rx_mask[1])
905 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
907 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
908 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
909 arg->peer_ht_rates.rates[n++] = i;
911 arg->peer_ht_rates.num_rates = n;
912 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
914 ath10k_dbg(ATH10K_DBG_MAC, "mcs cnt %d nss %d\n",
915 arg->peer_ht_rates.num_rates,
916 arg->peer_num_spatial_streams);
919 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
920 struct ath10k_vif *arvif,
921 struct ieee80211_sta *sta,
922 struct ieee80211_bss_conf *bss_conf,
923 struct wmi_peer_assoc_complete_arg *arg)
928 lockdep_assert_held(&ar->conf_mutex);
931 arg->peer_flags |= WMI_PEER_QOS;
933 if (sta->wme && sta->uapsd_queues) {
934 ath10k_dbg(ATH10K_DBG_MAC, "uapsd_queues: 0x%X, max_sp: %d\n",
935 sta->uapsd_queues, sta->max_sp);
937 arg->peer_flags |= WMI_PEER_APSD;
938 arg->peer_flags |= WMI_RC_UAPSD_FLAG;
940 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
941 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
942 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
943 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
944 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
945 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
946 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
947 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
948 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
949 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
950 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
951 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
954 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
955 max_sp = sta->max_sp;
957 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
959 WMI_AP_PS_PEER_PARAM_UAPSD,
962 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
964 WMI_AP_PS_PEER_PARAM_MAX_SP,
967 /* TODO setup this based on STA listen interval and
968 beacon interval. Currently we don't know
969 sta->listen_interval - mac80211 patch required.
970 Currently use 10 seconds */
971 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
973 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
978 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
979 struct ath10k_vif *arvif,
980 struct ieee80211_sta *sta,
981 struct ieee80211_bss_conf *bss_conf,
982 struct wmi_peer_assoc_complete_arg *arg)
985 arg->peer_flags |= WMI_PEER_QOS;
988 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
989 struct ieee80211_sta *sta,
990 struct wmi_peer_assoc_complete_arg *arg)
992 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
994 if (!vht_cap->vht_supported)
997 arg->peer_flags |= WMI_PEER_VHT;
999 arg->peer_vht_caps = vht_cap->cap;
1001 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1002 arg->peer_flags |= WMI_PEER_80MHZ;
1004 arg->peer_vht_rates.rx_max_rate =
1005 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1006 arg->peer_vht_rates.rx_mcs_set =
1007 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1008 arg->peer_vht_rates.tx_max_rate =
1009 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1010 arg->peer_vht_rates.tx_mcs_set =
1011 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1013 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer\n");
1016 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1017 struct ath10k_vif *arvif,
1018 struct ieee80211_sta *sta,
1019 struct ieee80211_bss_conf *bss_conf,
1020 struct wmi_peer_assoc_complete_arg *arg)
1022 switch (arvif->vdev_type) {
1023 case WMI_VDEV_TYPE_AP:
1024 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1026 case WMI_VDEV_TYPE_STA:
1027 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1034 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1035 struct ath10k_vif *arvif,
1036 struct ieee80211_sta *sta,
1037 struct wmi_peer_assoc_complete_arg *arg)
1039 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1041 /* FIXME: add VHT */
1043 switch (ar->hw->conf.chandef.chan->band) {
1044 case IEEE80211_BAND_2GHZ:
1045 if (sta->ht_cap.ht_supported) {
1046 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1047 phymode = MODE_11NG_HT40;
1049 phymode = MODE_11NG_HT20;
1055 case IEEE80211_BAND_5GHZ:
1056 if (sta->ht_cap.ht_supported) {
1057 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1058 phymode = MODE_11NA_HT40;
1060 phymode = MODE_11NA_HT20;
1070 arg->peer_phymode = phymode;
1071 WARN_ON(phymode == MODE_UNKNOWN);
1074 static int ath10k_peer_assoc(struct ath10k *ar,
1075 struct ath10k_vif *arvif,
1076 struct ieee80211_sta *sta,
1077 struct ieee80211_bss_conf *bss_conf)
1079 struct wmi_peer_assoc_complete_arg arg;
1081 lockdep_assert_held(&ar->conf_mutex);
1083 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1085 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1086 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1087 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1088 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1089 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1090 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1091 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1093 return ath10k_wmi_peer_assoc(ar, &arg);
1096 /* can be called only in mac80211 callbacks due to `key_count` usage */
1097 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1098 struct ieee80211_vif *vif,
1099 struct ieee80211_bss_conf *bss_conf)
1101 struct ath10k *ar = hw->priv;
1102 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1103 struct ieee80211_sta *ap_sta;
1106 lockdep_assert_held(&ar->conf_mutex);
1110 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1112 ath10k_warn("Failed to find station entry for %pM\n",
1118 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1120 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1127 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1130 ath10k_warn("VDEV: %d up failed: ret %d\n",
1131 arvif->vdev_id, ret);
1133 ath10k_dbg(ATH10K_DBG_MAC,
1134 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1135 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1141 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1142 struct ieee80211_vif *vif)
1144 struct ath10k *ar = hw->priv;
1145 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1148 lockdep_assert_held(&ar->conf_mutex);
1151 * For some reason, calling VDEV-DOWN before VDEV-STOP
1152 * makes the FW to send frames via HTT after disassociation.
1153 * No idea why this happens, even though VDEV-DOWN is supposed
1154 * to be analogous to link down, so just stop the VDEV.
1156 ret = ath10k_vdev_stop(arvif);
1158 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d stopped\n",
1162 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1163 * report beacons from previously associated network through HTT.
1164 * This in turn would spam mac80211 WARN_ON if we bring down all
1165 * interfaces as it expects there is no rx when no interface is
1168 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1170 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1171 arvif->vdev_id, ret);
1173 ath10k_wmi_flush_tx(ar);
1175 arvif->def_wep_key_index = 0;
1178 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1179 struct ieee80211_sta *sta)
1183 lockdep_assert_held(&ar->conf_mutex);
1185 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1187 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1191 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1193 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1200 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1201 struct ieee80211_sta *sta)
1205 lockdep_assert_held(&ar->conf_mutex);
1207 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1209 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1220 static int ath10k_update_channel_list(struct ath10k *ar)
1222 struct ieee80211_hw *hw = ar->hw;
1223 struct ieee80211_supported_band **bands;
1224 enum ieee80211_band band;
1225 struct ieee80211_channel *channel;
1226 struct wmi_scan_chan_list_arg arg = {0};
1227 struct wmi_channel_arg *ch;
1233 lockdep_assert_held(&ar->conf_mutex);
1235 bands = hw->wiphy->bands;
1236 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1240 for (i = 0; i < bands[band]->n_channels; i++) {
1241 if (bands[band]->channels[i].flags &
1242 IEEE80211_CHAN_DISABLED)
1249 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1250 arg.channels = kzalloc(len, GFP_KERNEL);
1255 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1259 for (i = 0; i < bands[band]->n_channels; i++) {
1260 channel = &bands[band]->channels[i];
1262 if (channel->flags & IEEE80211_CHAN_DISABLED)
1265 ch->allow_ht = true;
1267 /* FIXME: when should we really allow VHT? */
1268 ch->allow_vht = true;
1271 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1274 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1276 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1277 ch->passive = passive;
1279 ch->freq = channel->center_freq;
1280 ch->min_power = channel->max_power * 3;
1281 ch->max_power = channel->max_power * 4;
1282 ch->max_reg_power = channel->max_reg_power * 4;
1283 ch->max_antenna_gain = channel->max_antenna_gain;
1284 ch->reg_class_id = 0; /* FIXME */
1286 /* FIXME: why use only legacy modes, why not any
1287 * HT/VHT modes? Would that even make any
1289 if (channel->band == IEEE80211_BAND_2GHZ)
1290 ch->mode = MODE_11G;
1292 ch->mode = MODE_11A;
1294 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1297 ath10k_dbg(ATH10K_DBG_WMI,
1298 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1299 __func__, ch - arg.channels, arg.n_channels,
1300 ch->freq, ch->max_power, ch->max_reg_power,
1301 ch->max_antenna_gain, ch->mode);
1307 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1308 kfree(arg.channels);
1313 static void ath10k_reg_notifier(struct wiphy *wiphy,
1314 struct regulatory_request *request)
1316 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1317 struct reg_dmn_pair_mapping *regpair;
1318 struct ath10k *ar = hw->priv;
1321 mutex_lock(&ar->conf_mutex);
1323 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1325 ret = ath10k_update_channel_list(ar);
1327 ath10k_warn("could not update channel list (%d)\n", ret);
1329 regpair = ar->ath_common.regulatory.regpair;
1330 /* Target allows setting up per-band regdomain but ath_common provides
1331 * a combined one only */
1332 ret = ath10k_wmi_pdev_set_regdomain(ar,
1333 regpair->regDmnEnum,
1334 regpair->regDmnEnum, /* 2ghz */
1335 regpair->regDmnEnum, /* 5ghz */
1336 regpair->reg_2ghz_ctl,
1337 regpair->reg_5ghz_ctl);
1339 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1341 mutex_unlock(&ar->conf_mutex);
1349 * Frames sent to the FW have to be in "Native Wifi" format.
1350 * Strip the QoS field from the 802.11 header.
1352 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1353 struct ieee80211_tx_control *control,
1354 struct sk_buff *skb)
1356 struct ieee80211_hdr *hdr = (void *)skb->data;
1359 if (!ieee80211_is_data_qos(hdr->frame_control))
1362 qos_ctl = ieee80211_get_qos_ctl(hdr);
1363 memmove(qos_ctl, qos_ctl + IEEE80211_QOS_CTL_LEN,
1364 skb->len - ieee80211_hdrlen(hdr->frame_control));
1365 skb_trim(skb, skb->len - IEEE80211_QOS_CTL_LEN);
1368 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
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);
1373 struct ath10k *ar = arvif->ar;
1374 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1375 struct ieee80211_key_conf *key = info->control.hw_key;
1378 /* TODO AP mode should be implemented */
1379 if (vif->type != NL80211_IFTYPE_STATION)
1382 if (!ieee80211_has_protected(hdr->frame_control))
1388 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1389 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1392 if (key->keyidx == arvif->def_wep_key_index)
1395 ath10k_dbg(ATH10K_DBG_MAC, "new wep keyidx will be %d\n", key->keyidx);
1397 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1398 WMI_VDEV_PARAM_DEF_KEYID,
1401 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1405 arvif->def_wep_key_index = key->keyidx;
1408 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1410 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1411 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1412 struct ieee80211_vif *vif = info->control.vif;
1413 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1415 /* This is case only for P2P_GO */
1416 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1417 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1420 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1421 spin_lock_bh(&ar->data_lock);
1422 if (arvif->u.ap.noa_data)
1423 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1425 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1426 arvif->u.ap.noa_data,
1427 arvif->u.ap.noa_len);
1428 spin_unlock_bh(&ar->data_lock);
1432 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1437 if (ieee80211_is_mgmt(hdr->frame_control))
1438 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1439 else if (ieee80211_is_nullfunc(hdr->frame_control))
1440 /* FW does not report tx status properly for NullFunc frames
1441 * unless they are sent through mgmt tx path. mac80211 sends
1442 * those frames when it detects link/beacon loss and depends on
1443 * the tx status to be correct. */
1444 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1446 ret = ath10k_htt_tx(&ar->htt, skb);
1449 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1450 ieee80211_free_txskb(ar->hw, skb);
1454 void ath10k_offchan_tx_purge(struct ath10k *ar)
1456 struct sk_buff *skb;
1459 skb = skb_dequeue(&ar->offchan_tx_queue);
1463 ieee80211_free_txskb(ar->hw, skb);
1467 void ath10k_offchan_tx_work(struct work_struct *work)
1469 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1470 struct ath10k_peer *peer;
1471 struct ieee80211_hdr *hdr;
1472 struct sk_buff *skb;
1473 const u8 *peer_addr;
1477 /* FW requirement: We must create a peer before FW will send out
1478 * an offchannel frame. Otherwise the frame will be stuck and
1479 * never transmitted. We delete the peer upon tx completion.
1480 * It is unlikely that a peer for offchannel tx will already be
1481 * present. However it may be in some rare cases so account for that.
1482 * Otherwise we might remove a legitimate peer and break stuff. */
1485 skb = skb_dequeue(&ar->offchan_tx_queue);
1489 mutex_lock(&ar->conf_mutex);
1491 ath10k_dbg(ATH10K_DBG_MAC, "processing offchannel skb %p\n",
1494 hdr = (struct ieee80211_hdr *)skb->data;
1495 peer_addr = ieee80211_get_DA(hdr);
1496 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1498 spin_lock_bh(&ar->data_lock);
1499 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1500 spin_unlock_bh(&ar->data_lock);
1503 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1504 peer_addr, vdev_id);
1507 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1509 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1510 peer_addr, vdev_id, ret);
1513 spin_lock_bh(&ar->data_lock);
1514 INIT_COMPLETION(ar->offchan_tx_completed);
1515 ar->offchan_tx_skb = skb;
1516 spin_unlock_bh(&ar->data_lock);
1518 ath10k_tx_htt(ar, skb);
1520 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1523 ath10k_warn("timed out waiting for offchannel skb %p\n",
1527 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1529 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1530 peer_addr, vdev_id, ret);
1533 mutex_unlock(&ar->conf_mutex);
1542 * This gets called if we dont get a heart-beat during scan.
1543 * This may indicate the FW has hung and we need to abort the
1544 * scan manually to prevent cancel_hw_scan() from deadlocking
1546 void ath10k_reset_scan(unsigned long ptr)
1548 struct ath10k *ar = (struct ath10k *)ptr;
1550 spin_lock_bh(&ar->data_lock);
1551 if (!ar->scan.in_progress) {
1552 spin_unlock_bh(&ar->data_lock);
1556 ath10k_warn("scan timeout. resetting. fw issue?\n");
1558 if (ar->scan.is_roc)
1559 ieee80211_remain_on_channel_expired(ar->hw);
1561 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1563 ar->scan.in_progress = false;
1564 complete_all(&ar->scan.completed);
1565 spin_unlock_bh(&ar->data_lock);
1568 static int ath10k_abort_scan(struct ath10k *ar)
1570 struct wmi_stop_scan_arg arg = {
1571 .req_id = 1, /* FIXME */
1572 .req_type = WMI_SCAN_STOP_ONE,
1573 .u.scan_id = ATH10K_SCAN_ID,
1577 lockdep_assert_held(&ar->conf_mutex);
1579 del_timer_sync(&ar->scan.timeout);
1581 spin_lock_bh(&ar->data_lock);
1582 if (!ar->scan.in_progress) {
1583 spin_unlock_bh(&ar->data_lock);
1587 ar->scan.aborting = true;
1588 spin_unlock_bh(&ar->data_lock);
1590 ret = ath10k_wmi_stop_scan(ar, &arg);
1592 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1593 spin_lock_bh(&ar->data_lock);
1594 ar->scan.in_progress = false;
1595 ath10k_offchan_tx_purge(ar);
1596 spin_unlock_bh(&ar->data_lock);
1600 ath10k_wmi_flush_tx(ar);
1602 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1604 ath10k_warn("timed out while waiting for scan to stop\n");
1606 /* scan completion may be done right after we timeout here, so let's
1607 * check the in_progress and tell mac80211 scan is completed. if we
1608 * don't do that and FW fails to send us scan completion indication
1609 * then userspace won't be able to scan anymore */
1612 spin_lock_bh(&ar->data_lock);
1613 if (ar->scan.in_progress) {
1614 ath10k_warn("could not stop scan. its still in progress\n");
1615 ar->scan.in_progress = false;
1616 ath10k_offchan_tx_purge(ar);
1619 spin_unlock_bh(&ar->data_lock);
1624 static int ath10k_start_scan(struct ath10k *ar,
1625 const struct wmi_start_scan_arg *arg)
1629 lockdep_assert_held(&ar->conf_mutex);
1631 ret = ath10k_wmi_start_scan(ar, arg);
1635 /* make sure we submit the command so the completion
1636 * timeout makes sense */
1637 ath10k_wmi_flush_tx(ar);
1639 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1641 ath10k_abort_scan(ar);
1645 /* the scan can complete earlier, before we even
1646 * start the timer. in that case the timer handler
1647 * checks ar->scan.in_progress and bails out if its
1648 * false. Add a 200ms margin to account event/command
1650 mod_timer(&ar->scan.timeout, jiffies +
1651 msecs_to_jiffies(arg->max_scan_time+200));
1655 /**********************/
1656 /* mac80211 callbacks */
1657 /**********************/
1659 static void ath10k_tx(struct ieee80211_hw *hw,
1660 struct ieee80211_tx_control *control,
1661 struct sk_buff *skb)
1663 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1664 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1665 struct ath10k *ar = hw->priv;
1666 struct ath10k_vif *arvif = NULL;
1670 if (info->control.vif) {
1671 arvif = ath10k_vif_to_arvif(info->control.vif);
1672 vdev_id = arvif->vdev_id;
1673 } else if (ar->monitor_enabled) {
1674 vdev_id = ar->monitor_vdev_id;
1677 /* We should disable CCK RATE due to P2P */
1678 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1679 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1681 /* we must calculate tid before we apply qos workaround
1682 * as we'd lose the qos control field */
1683 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1684 if (ieee80211_is_data_qos(hdr->frame_control) &&
1685 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1686 u8 *qc = ieee80211_get_qos_ctl(hdr);
1687 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1690 ath10k_tx_h_qos_workaround(hw, control, skb);
1691 ath10k_tx_h_update_wep_key(skb);
1692 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1693 ath10k_tx_h_seq_no(skb);
1695 memset(ATH10K_SKB_CB(skb), 0, sizeof(*ATH10K_SKB_CB(skb)));
1696 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1697 ATH10K_SKB_CB(skb)->htt.tid = tid;
1699 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1700 spin_lock_bh(&ar->data_lock);
1701 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1702 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1703 spin_unlock_bh(&ar->data_lock);
1705 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1707 skb_queue_tail(&ar->offchan_tx_queue, skb);
1708 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1712 ath10k_tx_htt(ar, skb);
1716 * Initialize various parameters with default vaules.
1718 static int ath10k_start(struct ieee80211_hw *hw)
1720 struct ath10k *ar = hw->priv;
1723 mutex_lock(&ar->conf_mutex);
1725 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1727 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1730 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1732 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1735 mutex_unlock(&ar->conf_mutex);
1739 static void ath10k_stop(struct ieee80211_hw *hw)
1741 struct ath10k *ar = hw->priv;
1743 mutex_lock(&ar->conf_mutex);
1744 ath10k_offchan_tx_purge(ar);
1745 mutex_unlock(&ar->conf_mutex);
1747 cancel_work_sync(&ar->offchan_tx_work);
1750 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1752 struct ath10k_generic_iter ar_iter;
1753 struct ath10k *ar = hw->priv;
1754 struct ieee80211_conf *conf = &hw->conf;
1758 mutex_lock(&ar->conf_mutex);
1760 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1761 ath10k_dbg(ATH10K_DBG_MAC, "Config channel %d mhz\n",
1762 conf->chandef.chan->center_freq);
1763 spin_lock_bh(&ar->data_lock);
1764 ar->rx_channel = conf->chandef.chan;
1765 spin_unlock_bh(&ar->data_lock);
1768 if (changed & IEEE80211_CONF_CHANGE_PS) {
1769 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1771 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
1773 ieee80211_iterate_active_interfaces_atomic(hw,
1781 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1782 if (conf->flags & IEEE80211_CONF_MONITOR)
1783 ret = ath10k_monitor_create(ar);
1785 ret = ath10k_monitor_destroy(ar);
1788 mutex_unlock(&ar->conf_mutex);
1794 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1795 * because we will send mgmt frames without CCK. This requirement
1796 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1799 static int ath10k_add_interface(struct ieee80211_hw *hw,
1800 struct ieee80211_vif *vif)
1802 struct ath10k *ar = hw->priv;
1803 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1804 enum wmi_sta_powersave_param param;
1806 u32 value, rts, frag;
1809 mutex_lock(&ar->conf_mutex);
1814 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1815 ath10k_warn("Only one monitor interface allowed\n");
1820 bit = ffs(ar->free_vdev_map);
1826 arvif->vdev_id = bit - 1;
1827 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1828 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1831 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1833 switch (vif->type) {
1834 case NL80211_IFTYPE_UNSPECIFIED:
1835 case NL80211_IFTYPE_STATION:
1836 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1838 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1840 case NL80211_IFTYPE_ADHOC:
1841 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1843 case NL80211_IFTYPE_AP:
1844 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1847 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1849 case NL80211_IFTYPE_MONITOR:
1850 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1857 ath10k_dbg(ATH10K_DBG_MAC, "Add interface: id %d type %d subtype %d\n",
1858 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1860 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1861 arvif->vdev_subtype, vif->addr);
1863 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1867 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
1868 arvif->def_wep_key_index);
1870 ath10k_warn("Failed to set default keyid: %d\n", ret);
1872 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1873 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
1874 ATH10K_HW_TXRX_NATIVE_WIFI);
1876 ath10k_warn("Failed to set TX encap: %d\n", ret);
1878 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1879 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
1881 ath10k_warn("Failed to create peer for AP: %d\n", ret);
1886 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
1887 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
1888 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
1889 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1892 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
1894 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1895 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1896 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1899 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
1901 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1902 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1903 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1906 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
1909 rts = min_t(u32, ar->hw->wiphy->rts_threshold, ATH10K_RTS_MAX);
1910 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1911 WMI_VDEV_PARAM_RTS_THRESHOLD,
1914 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
1915 arvif->vdev_id, ret);
1917 frag = clamp_t(u32, ar->hw->wiphy->frag_threshold,
1918 ATH10K_FRAGMT_THRESHOLD_MIN,
1919 ATH10K_FRAGMT_THRESHOLD_MAX);
1920 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1921 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
1924 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
1925 arvif->vdev_id, ret);
1927 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1928 ar->monitor_present = true;
1931 mutex_unlock(&ar->conf_mutex);
1935 static void ath10k_remove_interface(struct ieee80211_hw *hw,
1936 struct ieee80211_vif *vif)
1938 struct ath10k *ar = hw->priv;
1939 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1942 mutex_lock(&ar->conf_mutex);
1944 ath10k_dbg(ATH10K_DBG_MAC, "Remove interface: id %d\n", arvif->vdev_id);
1946 ar->free_vdev_map |= 1 << (arvif->vdev_id);
1948 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1949 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
1951 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
1953 kfree(arvif->u.ap.noa_data);
1956 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
1958 ath10k_warn("WMI vdev delete failed: %d\n", ret);
1960 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1961 ar->monitor_present = false;
1963 ath10k_peer_cleanup(ar, arvif->vdev_id);
1965 mutex_unlock(&ar->conf_mutex);
1969 * FIXME: Has to be verified.
1971 #define SUPPORTED_FILTERS \
1972 (FIF_PROMISC_IN_BSS | \
1977 FIF_BCN_PRBRESP_PROMISC | \
1981 static void ath10k_configure_filter(struct ieee80211_hw *hw,
1982 unsigned int changed_flags,
1983 unsigned int *total_flags,
1986 struct ath10k *ar = hw->priv;
1989 mutex_lock(&ar->conf_mutex);
1991 changed_flags &= SUPPORTED_FILTERS;
1992 *total_flags &= SUPPORTED_FILTERS;
1993 ar->filter_flags = *total_flags;
1995 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
1996 !ar->monitor_enabled) {
1997 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
1999 ath10k_warn("Unable to start monitor mode\n");
2001 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode started\n");
2002 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2003 ar->monitor_enabled) {
2004 ret = ath10k_monitor_stop(ar);
2006 ath10k_warn("Unable to stop monitor mode\n");
2008 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode stopped\n");
2011 mutex_unlock(&ar->conf_mutex);
2014 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2015 struct ieee80211_vif *vif,
2016 struct ieee80211_bss_conf *info,
2019 struct ath10k *ar = hw->priv;
2020 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2023 mutex_lock(&ar->conf_mutex);
2025 if (changed & BSS_CHANGED_IBSS)
2026 ath10k_control_ibss(arvif, info, vif->addr);
2028 if (changed & BSS_CHANGED_BEACON_INT) {
2029 arvif->beacon_interval = info->beacon_int;
2030 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2031 WMI_VDEV_PARAM_BEACON_INTERVAL,
2032 arvif->beacon_interval);
2034 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2037 ath10k_dbg(ATH10K_DBG_MAC,
2038 "Beacon interval: %d set for VDEV: %d\n",
2039 arvif->beacon_interval, arvif->vdev_id);
2042 if (changed & BSS_CHANGED_BEACON) {
2043 ret = ath10k_wmi_pdev_set_param(ar,
2044 WMI_PDEV_PARAM_BEACON_TX_MODE,
2045 WMI_BEACON_STAGGERED_MODE);
2047 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2050 ath10k_dbg(ATH10K_DBG_MAC,
2051 "Set staggered beacon mode for VDEV: %d\n",
2055 if (changed & BSS_CHANGED_BEACON_INFO) {
2056 arvif->dtim_period = info->dtim_period;
2058 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2059 WMI_VDEV_PARAM_DTIM_PERIOD,
2060 arvif->dtim_period);
2062 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2065 ath10k_dbg(ATH10K_DBG_MAC,
2066 "Set dtim period: %d for VDEV: %d\n",
2067 arvif->dtim_period, arvif->vdev_id);
2070 if (changed & BSS_CHANGED_SSID &&
2071 vif->type == NL80211_IFTYPE_AP) {
2072 arvif->u.ap.ssid_len = info->ssid_len;
2074 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2075 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2078 if (changed & BSS_CHANGED_BSSID) {
2079 if (!is_zero_ether_addr(info->bssid)) {
2080 ret = ath10k_peer_create(ar, arvif->vdev_id,
2083 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2084 info->bssid, arvif->vdev_id);
2086 ath10k_dbg(ATH10K_DBG_MAC,
2087 "Added peer: %pM for VDEV: %d\n",
2088 info->bssid, arvif->vdev_id);
2091 if (vif->type == NL80211_IFTYPE_STATION) {
2093 * this is never erased as we it for crypto key
2094 * clearing; this is FW requirement
2096 memcpy(arvif->u.sta.bssid, info->bssid,
2099 ret = ath10k_vdev_start(arvif);
2101 ath10k_dbg(ATH10K_DBG_MAC,
2102 "VDEV: %d started with BSSID: %pM\n",
2103 arvif->vdev_id, info->bssid);
2107 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2108 * so driver need to store it. It is needed when leaving
2109 * IBSS in order to remove BSSID peer.
2111 if (vif->type == NL80211_IFTYPE_ADHOC)
2112 memcpy(arvif->u.ibss.bssid, info->bssid,
2117 if (changed & BSS_CHANGED_BEACON_ENABLED)
2118 ath10k_control_beaconing(arvif, info);
2120 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2122 if (info->use_cts_prot)
2127 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2128 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2131 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2134 ath10k_dbg(ATH10K_DBG_MAC,
2135 "Set CTS prot: %d for VDEV: %d\n",
2136 cts_prot, arvif->vdev_id);
2139 if (changed & BSS_CHANGED_ERP_SLOT) {
2141 if (info->use_short_slot)
2142 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2145 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2147 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2148 WMI_VDEV_PARAM_SLOT_TIME,
2151 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2154 ath10k_dbg(ATH10K_DBG_MAC,
2155 "Set slottime: %d for VDEV: %d\n",
2156 slottime, arvif->vdev_id);
2159 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2161 if (info->use_short_preamble)
2162 preamble = WMI_VDEV_PREAMBLE_SHORT;
2164 preamble = WMI_VDEV_PREAMBLE_LONG;
2166 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2167 WMI_VDEV_PARAM_PREAMBLE,
2170 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2173 ath10k_dbg(ATH10K_DBG_MAC,
2174 "Set preamble: %d for VDEV: %d\n",
2175 preamble, arvif->vdev_id);
2178 if (changed & BSS_CHANGED_ASSOC) {
2180 ath10k_bss_assoc(hw, vif, info);
2183 mutex_unlock(&ar->conf_mutex);
2186 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2187 struct ieee80211_vif *vif,
2188 struct cfg80211_scan_request *req)
2190 struct ath10k *ar = hw->priv;
2191 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2192 struct wmi_start_scan_arg arg;
2196 mutex_lock(&ar->conf_mutex);
2198 spin_lock_bh(&ar->data_lock);
2199 if (ar->scan.in_progress) {
2200 spin_unlock_bh(&ar->data_lock);
2205 INIT_COMPLETION(ar->scan.started);
2206 INIT_COMPLETION(ar->scan.completed);
2207 ar->scan.in_progress = true;
2208 ar->scan.aborting = false;
2209 ar->scan.is_roc = false;
2210 ar->scan.vdev_id = arvif->vdev_id;
2211 spin_unlock_bh(&ar->data_lock);
2213 memset(&arg, 0, sizeof(arg));
2214 ath10k_wmi_start_scan_init(ar, &arg);
2215 arg.vdev_id = arvif->vdev_id;
2216 arg.scan_id = ATH10K_SCAN_ID;
2219 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2222 arg.ie_len = req->ie_len;
2223 memcpy(arg.ie, req->ie, arg.ie_len);
2227 arg.n_ssids = req->n_ssids;
2228 for (i = 0; i < arg.n_ssids; i++) {
2229 arg.ssids[i].len = req->ssids[i].ssid_len;
2230 arg.ssids[i].ssid = req->ssids[i].ssid;
2234 if (req->n_channels) {
2235 arg.n_channels = req->n_channels;
2236 for (i = 0; i < arg.n_channels; i++)
2237 arg.channels[i] = req->channels[i]->center_freq;
2240 ret = ath10k_start_scan(ar, &arg);
2242 ath10k_warn("could not start hw scan (%d)\n", ret);
2243 spin_lock_bh(&ar->data_lock);
2244 ar->scan.in_progress = false;
2245 spin_unlock_bh(&ar->data_lock);
2249 mutex_unlock(&ar->conf_mutex);
2253 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2254 struct ieee80211_vif *vif)
2256 struct ath10k *ar = hw->priv;
2259 mutex_lock(&ar->conf_mutex);
2260 ret = ath10k_abort_scan(ar);
2262 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2264 ieee80211_scan_completed(hw, 1 /* aborted */);
2266 mutex_unlock(&ar->conf_mutex);
2269 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2270 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2271 struct ieee80211_key_conf *key)
2273 struct ath10k *ar = hw->priv;
2274 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2275 struct ath10k_peer *peer;
2276 const u8 *peer_addr;
2277 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2278 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2281 if (key->keyidx > WMI_MAX_KEY_INDEX)
2284 mutex_lock(&ar->conf_mutex);
2287 peer_addr = sta->addr;
2288 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2289 peer_addr = vif->bss_conf.bssid;
2291 peer_addr = vif->addr;
2293 key->hw_key_idx = key->keyidx;
2295 /* the peer should not disappear in mid-way (unless FW goes awry) since
2296 * we already hold conf_mutex. we just make sure its there now. */
2297 spin_lock_bh(&ar->data_lock);
2298 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2299 spin_unlock_bh(&ar->data_lock);
2302 if (cmd == SET_KEY) {
2303 ath10k_warn("cannot install key for non-existent peer %pM\n",
2308 /* if the peer doesn't exist there is no key to disable
2316 arvif->wep_keys[key->keyidx] = key;
2318 arvif->wep_keys[key->keyidx] = NULL;
2320 if (cmd == DISABLE_KEY)
2321 ath10k_clear_vdev_key(arvif, key);
2324 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2326 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2330 spin_lock_bh(&ar->data_lock);
2331 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2332 if (peer && cmd == SET_KEY)
2333 peer->keys[key->keyidx] = key;
2334 else if (peer && cmd == DISABLE_KEY)
2335 peer->keys[key->keyidx] = NULL;
2336 else if (peer == NULL)
2337 /* impossible unless FW goes crazy */
2338 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2339 spin_unlock_bh(&ar->data_lock);
2342 mutex_unlock(&ar->conf_mutex);
2346 static int ath10k_sta_state(struct ieee80211_hw *hw,
2347 struct ieee80211_vif *vif,
2348 struct ieee80211_sta *sta,
2349 enum ieee80211_sta_state old_state,
2350 enum ieee80211_sta_state new_state)
2352 struct ath10k *ar = hw->priv;
2353 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2356 mutex_lock(&ar->conf_mutex);
2358 if (old_state == IEEE80211_STA_NOTEXIST &&
2359 new_state == IEEE80211_STA_NONE &&
2360 vif->type != NL80211_IFTYPE_STATION) {
2362 * New station addition.
2364 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2366 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2367 sta->addr, arvif->vdev_id);
2369 ath10k_dbg(ATH10K_DBG_MAC,
2370 "Added peer: %pM for VDEV: %d\n",
2371 sta->addr, arvif->vdev_id);
2372 } else if ((old_state == IEEE80211_STA_NONE &&
2373 new_state == IEEE80211_STA_NOTEXIST)) {
2375 * Existing station deletion.
2377 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2379 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2380 sta->addr, arvif->vdev_id);
2382 ath10k_dbg(ATH10K_DBG_MAC,
2383 "Removed peer: %pM for VDEV: %d\n",
2384 sta->addr, arvif->vdev_id);
2386 if (vif->type == NL80211_IFTYPE_STATION)
2387 ath10k_bss_disassoc(hw, vif);
2388 } else if (old_state == IEEE80211_STA_AUTH &&
2389 new_state == IEEE80211_STA_ASSOC &&
2390 (vif->type == NL80211_IFTYPE_AP ||
2391 vif->type == NL80211_IFTYPE_ADHOC)) {
2395 ret = ath10k_station_assoc(ar, arvif, sta);
2397 ath10k_warn("Failed to associate station: %pM\n",
2400 ath10k_dbg(ATH10K_DBG_MAC,
2401 "Station %pM moved to assoc state\n",
2403 } else if (old_state == IEEE80211_STA_ASSOC &&
2404 new_state == IEEE80211_STA_AUTH &&
2405 (vif->type == NL80211_IFTYPE_AP ||
2406 vif->type == NL80211_IFTYPE_ADHOC)) {
2410 ret = ath10k_station_disassoc(ar, arvif, sta);
2412 ath10k_warn("Failed to disassociate station: %pM\n",
2415 ath10k_dbg(ATH10K_DBG_MAC,
2416 "Station %pM moved to disassociated state\n",
2420 mutex_unlock(&ar->conf_mutex);
2424 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2425 u16 ac, bool enable)
2427 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2431 lockdep_assert_held(&ar->conf_mutex);
2433 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2437 case IEEE80211_AC_VO:
2438 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2439 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2441 case IEEE80211_AC_VI:
2442 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2443 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2445 case IEEE80211_AC_BE:
2446 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2447 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2449 case IEEE80211_AC_BK:
2450 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2451 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2456 arvif->u.sta.uapsd |= value;
2458 arvif->u.sta.uapsd &= ~value;
2460 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2461 WMI_STA_PS_PARAM_UAPSD,
2462 arvif->u.sta.uapsd);
2464 ath10k_warn("could not set uapsd params %d\n", ret);
2468 if (arvif->u.sta.uapsd)
2469 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2471 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2473 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2474 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2477 ath10k_warn("could not set rx wake param %d\n", ret);
2483 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2484 struct ieee80211_vif *vif, u16 ac,
2485 const struct ieee80211_tx_queue_params *params)
2487 struct ath10k *ar = hw->priv;
2488 struct wmi_wmm_params_arg *p = NULL;
2491 mutex_lock(&ar->conf_mutex);
2494 case IEEE80211_AC_VO:
2495 p = &ar->wmm_params.ac_vo;
2497 case IEEE80211_AC_VI:
2498 p = &ar->wmm_params.ac_vi;
2500 case IEEE80211_AC_BE:
2501 p = &ar->wmm_params.ac_be;
2503 case IEEE80211_AC_BK:
2504 p = &ar->wmm_params.ac_bk;
2513 p->cwmin = params->cw_min;
2514 p->cwmax = params->cw_max;
2515 p->aifs = params->aifs;
2518 * The channel time duration programmed in the HW is in absolute
2519 * microseconds, while mac80211 gives the txop in units of
2522 p->txop = params->txop * 32;
2524 /* FIXME: FW accepts wmm params per hw, not per vif */
2525 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2527 ath10k_warn("could not set wmm params %d\n", ret);
2531 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2533 ath10k_warn("could not set sta uapsd %d\n", ret);
2536 mutex_unlock(&ar->conf_mutex);
2540 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2542 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2543 struct ieee80211_vif *vif,
2544 struct ieee80211_channel *chan,
2546 enum ieee80211_roc_type type)
2548 struct ath10k *ar = hw->priv;
2549 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2550 struct wmi_start_scan_arg arg;
2553 mutex_lock(&ar->conf_mutex);
2555 spin_lock_bh(&ar->data_lock);
2556 if (ar->scan.in_progress) {
2557 spin_unlock_bh(&ar->data_lock);
2562 INIT_COMPLETION(ar->scan.started);
2563 INIT_COMPLETION(ar->scan.completed);
2564 INIT_COMPLETION(ar->scan.on_channel);
2565 ar->scan.in_progress = true;
2566 ar->scan.aborting = false;
2567 ar->scan.is_roc = true;
2568 ar->scan.vdev_id = arvif->vdev_id;
2569 ar->scan.roc_freq = chan->center_freq;
2570 spin_unlock_bh(&ar->data_lock);
2572 memset(&arg, 0, sizeof(arg));
2573 ath10k_wmi_start_scan_init(ar, &arg);
2574 arg.vdev_id = arvif->vdev_id;
2575 arg.scan_id = ATH10K_SCAN_ID;
2577 arg.channels[0] = chan->center_freq;
2578 arg.dwell_time_active = duration;
2579 arg.dwell_time_passive = duration;
2580 arg.max_scan_time = 2 * duration;
2581 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2582 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2584 ret = ath10k_start_scan(ar, &arg);
2586 ath10k_warn("could not start roc scan (%d)\n", ret);
2587 spin_lock_bh(&ar->data_lock);
2588 ar->scan.in_progress = false;
2589 spin_unlock_bh(&ar->data_lock);
2593 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2595 ath10k_warn("could not switch to channel for roc scan\n");
2596 ath10k_abort_scan(ar);
2603 mutex_unlock(&ar->conf_mutex);
2607 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2609 struct ath10k *ar = hw->priv;
2611 mutex_lock(&ar->conf_mutex);
2612 ath10k_abort_scan(ar);
2613 mutex_unlock(&ar->conf_mutex);
2619 * Both RTS and Fragmentation threshold are interface-specific
2620 * in ath10k, but device-specific in mac80211.
2622 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2624 struct ath10k_generic_iter *ar_iter = data;
2625 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2626 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2628 lockdep_assert_held(&arvif->ar->conf_mutex);
2630 rts = min_t(u32, rts, ATH10K_RTS_MAX);
2632 ar_iter->ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2633 WMI_VDEV_PARAM_RTS_THRESHOLD,
2636 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2639 ath10k_dbg(ATH10K_DBG_MAC,
2640 "Set RTS threshold: %d for VDEV: %d\n",
2641 rts, arvif->vdev_id);
2644 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2646 struct ath10k_generic_iter ar_iter;
2647 struct ath10k *ar = hw->priv;
2649 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2652 mutex_lock(&ar->conf_mutex);
2653 ieee80211_iterate_active_interfaces_atomic(
2654 hw, IEEE80211_IFACE_ITER_NORMAL,
2655 ath10k_set_rts_iter, &ar_iter);
2656 mutex_unlock(&ar->conf_mutex);
2661 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2663 struct ath10k_generic_iter *ar_iter = data;
2664 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2665 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2668 lockdep_assert_held(&arvif->ar->conf_mutex);
2670 frag = clamp_t(u32, frag,
2671 ATH10K_FRAGMT_THRESHOLD_MIN,
2672 ATH10K_FRAGMT_THRESHOLD_MAX);
2674 ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2675 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
2680 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2683 ath10k_dbg(ATH10K_DBG_MAC,
2684 "Set frag threshold: %d for VDEV: %d\n",
2685 frag, arvif->vdev_id);
2688 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2690 struct ath10k_generic_iter ar_iter;
2691 struct ath10k *ar = hw->priv;
2693 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2696 mutex_lock(&ar->conf_mutex);
2697 ieee80211_iterate_active_interfaces_atomic(
2698 hw, IEEE80211_IFACE_ITER_NORMAL,
2699 ath10k_set_frag_iter, &ar_iter);
2700 mutex_unlock(&ar->conf_mutex);
2705 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2707 struct ath10k *ar = hw->priv;
2710 /* mac80211 doesn't care if we really xmit queued frames or not
2711 * we'll collect those frames either way if we stop/delete vdevs */
2715 mutex_lock(&ar->conf_mutex);
2717 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
2719 spin_lock_bh(&ar->htt.tx_lock);
2720 empty = bitmap_empty(ar->htt.used_msdu_ids,
2721 ar->htt.max_num_pending_tx);
2722 spin_unlock_bh(&ar->htt.tx_lock);
2724 }), ATH10K_FLUSH_TIMEOUT_HZ);
2726 ath10k_warn("tx not flushed\n");
2728 mutex_unlock(&ar->conf_mutex);
2731 /* TODO: Implement this function properly
2732 * For now it is needed to reply to Probe Requests in IBSS mode.
2733 * Propably we need this information from FW.
2735 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2740 static const struct ieee80211_ops ath10k_ops = {
2742 .start = ath10k_start,
2743 .stop = ath10k_stop,
2744 .config = ath10k_config,
2745 .add_interface = ath10k_add_interface,
2746 .remove_interface = ath10k_remove_interface,
2747 .configure_filter = ath10k_configure_filter,
2748 .bss_info_changed = ath10k_bss_info_changed,
2749 .hw_scan = ath10k_hw_scan,
2750 .cancel_hw_scan = ath10k_cancel_hw_scan,
2751 .set_key = ath10k_set_key,
2752 .sta_state = ath10k_sta_state,
2753 .conf_tx = ath10k_conf_tx,
2754 .remain_on_channel = ath10k_remain_on_channel,
2755 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
2756 .set_rts_threshold = ath10k_set_rts_threshold,
2757 .set_frag_threshold = ath10k_set_frag_threshold,
2758 .flush = ath10k_flush,
2759 .tx_last_beacon = ath10k_tx_last_beacon,
2762 #define RATETAB_ENT(_rate, _rateid, _flags) { \
2763 .bitrate = (_rate), \
2764 .flags = (_flags), \
2765 .hw_value = (_rateid), \
2768 #define CHAN2G(_channel, _freq, _flags) { \
2769 .band = IEEE80211_BAND_2GHZ, \
2770 .hw_value = (_channel), \
2771 .center_freq = (_freq), \
2772 .flags = (_flags), \
2773 .max_antenna_gain = 0, \
2777 #define CHAN5G(_channel, _freq, _flags) { \
2778 .band = IEEE80211_BAND_5GHZ, \
2779 .hw_value = (_channel), \
2780 .center_freq = (_freq), \
2781 .flags = (_flags), \
2782 .max_antenna_gain = 0, \
2786 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
2796 CHAN2G(10, 2457, 0),
2797 CHAN2G(11, 2462, 0),
2798 CHAN2G(12, 2467, 0),
2799 CHAN2G(13, 2472, 0),
2800 CHAN2G(14, 2484, 0),
2803 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
2804 CHAN5G(36, 5180, 0),
2805 CHAN5G(40, 5200, 0),
2806 CHAN5G(44, 5220, 0),
2807 CHAN5G(48, 5240, 0),
2808 CHAN5G(52, 5260, 0),
2809 CHAN5G(56, 5280, 0),
2810 CHAN5G(60, 5300, 0),
2811 CHAN5G(64, 5320, 0),
2812 CHAN5G(100, 5500, 0),
2813 CHAN5G(104, 5520, 0),
2814 CHAN5G(108, 5540, 0),
2815 CHAN5G(112, 5560, 0),
2816 CHAN5G(116, 5580, 0),
2817 CHAN5G(120, 5600, 0),
2818 CHAN5G(124, 5620, 0),
2819 CHAN5G(128, 5640, 0),
2820 CHAN5G(132, 5660, 0),
2821 CHAN5G(136, 5680, 0),
2822 CHAN5G(140, 5700, 0),
2823 CHAN5G(149, 5745, 0),
2824 CHAN5G(153, 5765, 0),
2825 CHAN5G(157, 5785, 0),
2826 CHAN5G(161, 5805, 0),
2827 CHAN5G(165, 5825, 0),
2830 static struct ieee80211_rate ath10k_rates[] = {
2832 RATETAB_ENT(10, 0x82, 0),
2833 RATETAB_ENT(20, 0x84, 0),
2834 RATETAB_ENT(55, 0x8b, 0),
2835 RATETAB_ENT(110, 0x96, 0),
2837 RATETAB_ENT(60, 0x0c, 0),
2838 RATETAB_ENT(90, 0x12, 0),
2839 RATETAB_ENT(120, 0x18, 0),
2840 RATETAB_ENT(180, 0x24, 0),
2841 RATETAB_ENT(240, 0x30, 0),
2842 RATETAB_ENT(360, 0x48, 0),
2843 RATETAB_ENT(480, 0x60, 0),
2844 RATETAB_ENT(540, 0x6c, 0),
2847 #define ath10k_a_rates (ath10k_rates + 4)
2848 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
2849 #define ath10k_g_rates (ath10k_rates + 0)
2850 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
2852 struct ath10k *ath10k_mac_create(void)
2854 struct ieee80211_hw *hw;
2857 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
2867 void ath10k_mac_destroy(struct ath10k *ar)
2869 ieee80211_free_hw(ar->hw);
2872 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
2875 .types = BIT(NL80211_IFTYPE_STATION)
2876 | BIT(NL80211_IFTYPE_P2P_CLIENT)
2877 | BIT(NL80211_IFTYPE_P2P_GO)
2878 | BIT(NL80211_IFTYPE_AP)
2882 static const struct ieee80211_iface_combination ath10k_if_comb = {
2883 .limits = ath10k_if_limits,
2884 .n_limits = ARRAY_SIZE(ath10k_if_limits),
2885 .max_interfaces = 8,
2886 .num_different_channels = 1,
2887 .beacon_int_infra_match = true,
2890 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
2892 struct ieee80211_sta_vht_cap vht_cap = {0};
2895 vht_cap.vht_supported = 1;
2896 vht_cap.cap = ar->vht_cap_info;
2898 /* FIXME: check dynamically how many streams board supports */
2899 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
2900 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
2901 IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
2902 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
2903 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
2904 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
2905 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
2906 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
2908 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
2909 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
2914 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
2917 struct ieee80211_sta_ht_cap ht_cap = {0};
2919 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
2922 ht_cap.ht_supported = 1;
2923 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2924 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
2925 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2926 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
2927 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
2929 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
2930 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2932 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
2933 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2935 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
2938 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
2939 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
2944 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
2945 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2947 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
2950 stbc = ar->ht_cap_info;
2951 stbc &= WMI_HT_CAP_RX_STBC;
2952 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
2953 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
2954 stbc &= IEEE80211_HT_CAP_RX_STBC;
2959 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
2960 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
2962 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
2963 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
2965 /* max AMSDU is implicitly taken from vht_cap_info */
2966 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
2967 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2969 for (i = 0; i < WMI_MAX_SPATIAL_STREAM; i++)
2970 ht_cap.mcs.rx_mask[i] = 0xFF;
2972 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
2978 static void ath10k_get_arvif_iter(void *data, u8 *mac,
2979 struct ieee80211_vif *vif)
2981 struct ath10k_vif_iter *arvif_iter = data;
2982 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2984 if (arvif->vdev_id == arvif_iter->vdev_id)
2985 arvif_iter->arvif = arvif;
2988 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
2990 struct ath10k_vif_iter arvif_iter;
2993 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
2994 arvif_iter.vdev_id = vdev_id;
2996 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
2997 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2999 ath10k_get_arvif_iter,
3001 if (!arvif_iter.arvif) {
3002 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3006 return arvif_iter.arvif;
3009 int ath10k_mac_register(struct ath10k *ar)
3011 struct ieee80211_supported_band *band;
3012 struct ieee80211_sta_vht_cap vht_cap;
3013 struct ieee80211_sta_ht_cap ht_cap;
3017 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3019 SET_IEEE80211_DEV(ar->hw, ar->dev);
3021 ht_cap = ath10k_get_ht_cap(ar);
3022 vht_cap = ath10k_create_vht_cap(ar);
3024 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3025 channels = kmemdup(ath10k_2ghz_channels,
3026 sizeof(ath10k_2ghz_channels),
3031 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3032 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3033 band->channels = channels;
3034 band->n_bitrates = ath10k_g_rates_size;
3035 band->bitrates = ath10k_g_rates;
3036 band->ht_cap = ht_cap;
3038 /* vht is not supported in 2.4 GHz */
3040 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3043 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3044 channels = kmemdup(ath10k_5ghz_channels,
3045 sizeof(ath10k_5ghz_channels),
3048 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3049 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3050 kfree(band->channels);
3055 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3056 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3057 band->channels = channels;
3058 band->n_bitrates = ath10k_a_rates_size;
3059 band->bitrates = ath10k_a_rates;
3060 band->ht_cap = ht_cap;
3061 band->vht_cap = vht_cap;
3062 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3065 ar->hw->wiphy->interface_modes =
3066 BIT(NL80211_IFTYPE_STATION) |
3067 BIT(NL80211_IFTYPE_ADHOC) |
3068 BIT(NL80211_IFTYPE_AP) |
3069 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3070 BIT(NL80211_IFTYPE_P2P_GO);
3072 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3073 IEEE80211_HW_SUPPORTS_PS |
3074 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3075 IEEE80211_HW_SUPPORTS_UAPSD |
3076 IEEE80211_HW_MFP_CAPABLE |
3077 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3078 IEEE80211_HW_HAS_RATE_CONTROL |
3079 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3080 IEEE80211_HW_WANT_MONITOR_VIF |
3081 IEEE80211_HW_AP_LINK_PS;
3083 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3084 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3086 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3087 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3088 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3091 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3092 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3094 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3096 ar->hw->channel_change_time = 5000;
3097 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3099 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3100 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3102 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3104 * on LL hardware queues are managed entirely by the FW
3105 * so we only advertise to mac we can do the queues thing
3109 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3110 ar->hw->wiphy->n_iface_combinations = 1;
3112 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3113 ath10k_reg_notifier);
3115 ath10k_err("Regulatory initialization failed\n");
3119 ret = ieee80211_register_hw(ar->hw);
3121 ath10k_err("ieee80211 registration failed: %d\n", ret);
3125 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3126 ret = regulatory_hint(ar->hw->wiphy,
3127 ar->ath_common.regulatory.alpha2);
3134 ieee80211_unregister_hw(ar->hw);
3138 void ath10k_mac_unregister(struct ath10k *ar)
3140 ieee80211_unregister_hw(ar->hw);
3142 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3143 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3145 SET_IEEE80211_DEV(ar->hw, NULL);