2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
34 static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
47 lockdep_assert_held(&arvif->ar->conf_mutex);
49 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
52 arg.key_flags = WMI_KEY_GROUP;
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
59 case WLAN_CIPHER_SUITE_TKIP:
60 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
85 static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
90 struct ath10k *ar = arvif->ar;
93 lockdep_assert_held(&ar->conf_mutex);
95 INIT_COMPLETION(ar->install_key_done);
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
108 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
116 lockdep_assert_held(&ar->conf_mutex);
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
134 peer->keys[i] = arvif->wep_keys[i];
140 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
149 lockdep_assert_held(&ar->conf_mutex);
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
162 ret = ath10k_install_key(arvif, peer->keys[i],
164 if (ret && first_errno == 0)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
171 peer->keys[i] = NULL;
177 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
187 lockdep_assert_held(&ar->conf_mutex);
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
203 if (i < ARRAY_SIZE(peer->keys))
206 spin_unlock_bh(&ar->data_lock);
208 if (i == ARRAY_SIZE(peer->keys))
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
216 ath10k_warn("could not remove key for %pM\n", addr);
223 /*********************/
224 /* General utilities */
225 /*********************/
227 static inline enum wmi_phy_mode
228 chan_to_phymode(const struct cfg80211_chan_def *chandef)
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
279 WARN_ON(phymode == MODE_UNKNOWN);
283 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
296 switch (mpdudensity) {
302 /* Our lower layer calculations limit our precision to
318 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
322 lockdep_assert_held(&ar->conf_mutex);
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
328 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
335 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
339 lockdep_assert_held(&ar->conf_mutex);
341 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
345 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
352 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
354 struct ath10k_peer *peer, *tmp;
356 lockdep_assert_held(&ar->conf_mutex);
358 spin_lock_bh(&ar->data_lock);
359 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
360 if (peer->vdev_id != vdev_id)
363 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
364 peer->addr, vdev_id);
366 list_del(&peer->list);
369 spin_unlock_bh(&ar->data_lock);
372 /************************/
373 /* Interface management */
374 /************************/
376 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
380 lockdep_assert_held(&ar->conf_mutex);
382 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
383 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
390 static int ath10k_vdev_start(struct ath10k_vif *arvif)
392 struct ath10k *ar = arvif->ar;
393 struct ieee80211_conf *conf = &ar->hw->conf;
394 struct ieee80211_channel *channel = conf->chandef.chan;
395 struct wmi_vdev_start_request_arg arg = {};
398 lockdep_assert_held(&ar->conf_mutex);
400 INIT_COMPLETION(ar->vdev_setup_done);
402 arg.vdev_id = arvif->vdev_id;
403 arg.dtim_period = arvif->dtim_period;
404 arg.bcn_intval = arvif->beacon_interval;
406 arg.channel.freq = channel->center_freq;
408 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
410 arg.channel.mode = chan_to_phymode(&conf->chandef);
412 arg.channel.min_power = channel->max_power * 3;
413 arg.channel.max_power = channel->max_power * 4;
414 arg.channel.max_reg_power = channel->max_reg_power * 4;
415 arg.channel.max_antenna_gain = channel->max_antenna_gain;
417 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
418 arg.ssid = arvif->u.ap.ssid;
419 arg.ssid_len = arvif->u.ap.ssid_len;
420 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
421 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
422 arg.ssid = arvif->vif->bss_conf.ssid;
423 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
426 ret = ath10k_wmi_vdev_start(ar, &arg);
428 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
432 ret = ath10k_vdev_setup_sync(ar);
434 ath10k_warn("vdev setup failed %d\n", ret);
441 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
443 struct ath10k *ar = arvif->ar;
446 lockdep_assert_held(&ar->conf_mutex);
448 INIT_COMPLETION(ar->vdev_setup_done);
450 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
452 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
456 ret = ath10k_vdev_setup_sync(ar);
458 ath10k_warn("vdev setup failed %d\n", ret);
465 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
467 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
468 struct wmi_vdev_start_request_arg arg = {};
469 enum nl80211_channel_type type;
472 lockdep_assert_held(&ar->conf_mutex);
474 type = cfg80211_get_chandef_type(&ar->hw->conf.chandef);
476 arg.vdev_id = vdev_id;
477 arg.channel.freq = channel->center_freq;
478 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
480 /* TODO setup this dynamically, what in case we
481 don't have any vifs? */
482 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
484 arg.channel.min_power = channel->max_power * 3;
485 arg.channel.max_power = channel->max_power * 4;
486 arg.channel.max_reg_power = channel->max_reg_power * 4;
487 arg.channel.max_antenna_gain = channel->max_antenna_gain;
489 ret = ath10k_wmi_vdev_start(ar, &arg);
491 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
495 ret = ath10k_vdev_setup_sync(ar);
497 ath10k_warn("Monitor vdev setup failed %d\n", ret);
501 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
503 ath10k_warn("Monitor vdev up failed: %d\n", ret);
507 ar->monitor_vdev_id = vdev_id;
508 ar->monitor_enabled = true;
513 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
515 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
520 static int ath10k_monitor_stop(struct ath10k *ar)
524 lockdep_assert_held(&ar->conf_mutex);
526 /* For some reasons, ath10k_wmi_vdev_down() here couse
527 * often ath10k_wmi_vdev_stop() to fail. Next we could
528 * not run monitor vdev and driver reload
529 * required. Don't see such problems we skip
530 * ath10k_wmi_vdev_down() here.
533 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
535 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
537 ret = ath10k_vdev_setup_sync(ar);
539 ath10k_warn("Monitor_down sync failed: %d\n", ret);
541 ar->monitor_enabled = false;
545 static int ath10k_monitor_create(struct ath10k *ar)
549 lockdep_assert_held(&ar->conf_mutex);
551 if (ar->monitor_present) {
552 ath10k_warn("Monitor mode already enabled\n");
556 bit = ffs(ar->free_vdev_map);
558 ath10k_warn("No free VDEV slots\n");
562 ar->monitor_vdev_id = bit - 1;
563 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
565 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
566 WMI_VDEV_TYPE_MONITOR,
569 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
573 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface created, vdev id: %d\n",
574 ar->monitor_vdev_id);
576 ar->monitor_present = true;
581 * Restore the ID to the global map.
583 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
587 static int ath10k_monitor_destroy(struct ath10k *ar)
591 lockdep_assert_held(&ar->conf_mutex);
593 if (!ar->monitor_present)
596 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
598 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
602 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
603 ar->monitor_present = false;
605 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface destroyed, vdev id: %d\n",
606 ar->monitor_vdev_id);
610 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
611 struct ieee80211_bss_conf *info)
615 lockdep_assert_held(&arvif->ar->conf_mutex);
617 if (!info->enable_beacon) {
618 ath10k_vdev_stop(arvif);
622 arvif->tx_seq_no = 0x1000;
624 ret = ath10k_vdev_start(arvif);
628 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
630 ath10k_warn("Failed to bring up VDEV: %d\n",
634 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d up\n", arvif->vdev_id);
637 static void ath10k_control_ibss(struct ath10k_vif *arvif,
638 struct ieee80211_bss_conf *info,
639 const u8 self_peer[ETH_ALEN])
643 lockdep_assert_held(&arvif->ar->conf_mutex);
645 if (!info->ibss_joined) {
646 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
648 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
649 self_peer, arvif->vdev_id, ret);
651 if (is_zero_ether_addr(arvif->u.ibss.bssid))
654 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
655 arvif->u.ibss.bssid);
657 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
658 arvif->u.ibss.bssid, arvif->vdev_id, ret);
662 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
667 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
669 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
670 self_peer, arvif->vdev_id, ret);
674 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
675 WMI_VDEV_PARAM_ATIM_WINDOW,
676 ATH10K_DEFAULT_ATIM);
678 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
679 arvif->vdev_id, ret);
683 * Review this when mac80211 gains per-interface powersave support.
685 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
687 struct ath10k_generic_iter *ar_iter = data;
688 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
689 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
690 enum wmi_sta_powersave_param param;
691 enum wmi_sta_ps_mode psmode;
694 lockdep_assert_held(&arvif->ar->conf_mutex);
696 if (vif->type != NL80211_IFTYPE_STATION)
699 if (conf->flags & IEEE80211_CONF_PS) {
700 psmode = WMI_STA_PS_MODE_ENABLED;
701 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
703 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
706 conf->dynamic_ps_timeout);
708 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
715 psmode = WMI_STA_PS_MODE_DISABLED;
718 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
721 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
722 psmode, arvif->vdev_id);
724 ath10k_dbg(ATH10K_DBG_MAC, "Set PS Mode: %d for VDEV: %d\n",
725 psmode, arvif->vdev_id);
728 /**********************/
729 /* Station management */
730 /**********************/
732 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
733 struct ath10k_vif *arvif,
734 struct ieee80211_sta *sta,
735 struct ieee80211_bss_conf *bss_conf,
736 struct wmi_peer_assoc_complete_arg *arg)
738 lockdep_assert_held(&ar->conf_mutex);
740 memcpy(arg->addr, sta->addr, ETH_ALEN);
741 arg->vdev_id = arvif->vdev_id;
742 arg->peer_aid = sta->aid;
743 arg->peer_flags |= WMI_PEER_AUTH;
745 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
747 * Seems FW have problems with Power Save in STA
748 * mode when we setup this parameter to high (eg. 5).
749 * Often we see that FW don't send NULL (with clean P flags)
750 * frame even there is info about buffered frames in beacons.
751 * Sometimes we have to wait more than 10 seconds before FW
752 * will wakeup. Often sending one ping from AP to our device
753 * just fail (more than 50%).
755 * Seems setting this FW parameter to 1 couse FW
756 * will check every beacon and will wakup immediately
757 * after detection buffered data.
759 arg->peer_listen_intval = 1;
761 arg->peer_listen_intval = ar->hw->conf.listen_interval;
763 arg->peer_num_spatial_streams = 1;
766 * The assoc capabilities are available only in managed mode.
768 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
769 arg->peer_caps = bss_conf->assoc_capability;
772 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
773 struct ath10k_vif *arvif,
774 struct wmi_peer_assoc_complete_arg *arg)
776 struct ieee80211_vif *vif = arvif->vif;
777 struct ieee80211_bss_conf *info = &vif->bss_conf;
778 struct cfg80211_bss *bss;
779 const u8 *rsnie = NULL;
780 const u8 *wpaie = NULL;
782 lockdep_assert_held(&ar->conf_mutex);
784 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
785 info->bssid, NULL, 0, 0, 0);
787 const struct cfg80211_bss_ies *ies;
790 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
792 ies = rcu_dereference(bss->ies);
794 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
795 WLAN_OUI_TYPE_MICROSOFT_WPA,
799 cfg80211_put_bss(ar->hw->wiphy, bss);
802 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
803 if (rsnie || wpaie) {
804 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
805 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
809 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
810 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
814 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
815 struct ieee80211_sta *sta,
816 struct wmi_peer_assoc_complete_arg *arg)
818 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
819 const struct ieee80211_supported_band *sband;
820 const struct ieee80211_rate *rates;
824 lockdep_assert_held(&ar->conf_mutex);
826 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
827 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
828 rates = sband->bitrates;
830 rateset->num_rates = 0;
832 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
836 rateset->rates[rateset->num_rates] = rates->hw_value;
837 rateset->num_rates++;
841 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
842 struct ieee80211_sta *sta,
843 struct wmi_peer_assoc_complete_arg *arg)
845 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
849 lockdep_assert_held(&ar->conf_mutex);
851 if (!ht_cap->ht_supported)
854 arg->peer_flags |= WMI_PEER_HT;
855 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
856 ht_cap->ampdu_factor)) - 1;
858 arg->peer_mpdu_density =
859 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
861 arg->peer_ht_caps = ht_cap->cap;
862 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
864 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
865 arg->peer_flags |= WMI_PEER_LDPC;
867 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
868 arg->peer_flags |= WMI_PEER_40MHZ;
869 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
872 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
873 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
875 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
876 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
878 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
879 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
880 arg->peer_flags |= WMI_PEER_STBC;
883 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
885 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
886 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
887 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
888 arg->peer_rate_caps |= stbc;
889 arg->peer_flags |= WMI_PEER_STBC;
892 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
893 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
895 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
896 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
897 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
898 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
899 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
900 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
903 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
904 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
905 else if (ht_cap->mcs.rx_mask[1])
906 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
908 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
909 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
910 arg->peer_ht_rates.rates[n++] = i;
912 arg->peer_ht_rates.num_rates = n;
913 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
915 ath10k_dbg(ATH10K_DBG_MAC, "mcs cnt %d nss %d\n",
916 arg->peer_ht_rates.num_rates,
917 arg->peer_num_spatial_streams);
920 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
921 struct ath10k_vif *arvif,
922 struct ieee80211_sta *sta,
923 struct ieee80211_bss_conf *bss_conf,
924 struct wmi_peer_assoc_complete_arg *arg)
929 lockdep_assert_held(&ar->conf_mutex);
932 arg->peer_flags |= WMI_PEER_QOS;
934 if (sta->wme && sta->uapsd_queues) {
935 ath10k_dbg(ATH10K_DBG_MAC, "uapsd_queues: 0x%X, max_sp: %d\n",
936 sta->uapsd_queues, sta->max_sp);
938 arg->peer_flags |= WMI_PEER_APSD;
939 arg->peer_flags |= WMI_RC_UAPSD_FLAG;
941 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
942 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
943 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
944 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
945 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
946 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
947 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
948 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
949 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
950 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
951 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
952 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
955 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
956 max_sp = sta->max_sp;
958 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
960 WMI_AP_PS_PEER_PARAM_UAPSD,
963 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
965 WMI_AP_PS_PEER_PARAM_MAX_SP,
968 /* TODO setup this based on STA listen interval and
969 beacon interval. Currently we don't know
970 sta->listen_interval - mac80211 patch required.
971 Currently use 10 seconds */
972 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
974 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
979 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
980 struct ath10k_vif *arvif,
981 struct ieee80211_sta *sta,
982 struct ieee80211_bss_conf *bss_conf,
983 struct wmi_peer_assoc_complete_arg *arg)
986 arg->peer_flags |= WMI_PEER_QOS;
989 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
990 struct ieee80211_sta *sta,
991 struct wmi_peer_assoc_complete_arg *arg)
993 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
995 if (!vht_cap->vht_supported)
998 arg->peer_flags |= WMI_PEER_VHT;
1000 arg->peer_vht_caps = vht_cap->cap;
1002 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1003 arg->peer_flags |= WMI_PEER_80MHZ;
1005 arg->peer_vht_rates.rx_max_rate =
1006 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1007 arg->peer_vht_rates.rx_mcs_set =
1008 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1009 arg->peer_vht_rates.tx_max_rate =
1010 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1011 arg->peer_vht_rates.tx_mcs_set =
1012 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1014 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer\n");
1017 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1018 struct ath10k_vif *arvif,
1019 struct ieee80211_sta *sta,
1020 struct ieee80211_bss_conf *bss_conf,
1021 struct wmi_peer_assoc_complete_arg *arg)
1023 switch (arvif->vdev_type) {
1024 case WMI_VDEV_TYPE_AP:
1025 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1027 case WMI_VDEV_TYPE_STA:
1028 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1035 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1036 struct ath10k_vif *arvif,
1037 struct ieee80211_sta *sta,
1038 struct wmi_peer_assoc_complete_arg *arg)
1040 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1042 /* FIXME: add VHT */
1044 switch (ar->hw->conf.chandef.chan->band) {
1045 case IEEE80211_BAND_2GHZ:
1046 if (sta->ht_cap.ht_supported) {
1047 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1048 phymode = MODE_11NG_HT40;
1050 phymode = MODE_11NG_HT20;
1056 case IEEE80211_BAND_5GHZ:
1057 if (sta->ht_cap.ht_supported) {
1058 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1059 phymode = MODE_11NA_HT40;
1061 phymode = MODE_11NA_HT20;
1071 arg->peer_phymode = phymode;
1072 WARN_ON(phymode == MODE_UNKNOWN);
1075 static int ath10k_peer_assoc(struct ath10k *ar,
1076 struct ath10k_vif *arvif,
1077 struct ieee80211_sta *sta,
1078 struct ieee80211_bss_conf *bss_conf)
1080 struct wmi_peer_assoc_complete_arg arg;
1082 lockdep_assert_held(&ar->conf_mutex);
1084 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1086 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1087 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1088 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1089 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1090 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1091 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1092 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1094 return ath10k_wmi_peer_assoc(ar, &arg);
1097 /* can be called only in mac80211 callbacks due to `key_count` usage */
1098 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1099 struct ieee80211_vif *vif,
1100 struct ieee80211_bss_conf *bss_conf)
1102 struct ath10k *ar = hw->priv;
1103 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1104 struct ieee80211_sta *ap_sta;
1107 lockdep_assert_held(&ar->conf_mutex);
1111 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1113 ath10k_warn("Failed to find station entry for %pM\n",
1119 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1121 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1128 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1131 ath10k_warn("VDEV: %d up failed: ret %d\n",
1132 arvif->vdev_id, ret);
1134 ath10k_dbg(ATH10K_DBG_MAC,
1135 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1136 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1142 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1143 struct ieee80211_vif *vif)
1145 struct ath10k *ar = hw->priv;
1146 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1149 lockdep_assert_held(&ar->conf_mutex);
1152 * For some reason, calling VDEV-DOWN before VDEV-STOP
1153 * makes the FW to send frames via HTT after disassociation.
1154 * No idea why this happens, even though VDEV-DOWN is supposed
1155 * to be analogous to link down, so just stop the VDEV.
1157 ret = ath10k_vdev_stop(arvif);
1159 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d stopped\n",
1163 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1164 * report beacons from previously associated network through HTT.
1165 * This in turn would spam mac80211 WARN_ON if we bring down all
1166 * interfaces as it expects there is no rx when no interface is
1169 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1171 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1172 arvif->vdev_id, ret);
1174 ath10k_wmi_flush_tx(ar);
1176 arvif->def_wep_key_index = 0;
1179 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1180 struct ieee80211_sta *sta)
1184 lockdep_assert_held(&ar->conf_mutex);
1186 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1188 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1192 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1194 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1201 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1202 struct ieee80211_sta *sta)
1206 lockdep_assert_held(&ar->conf_mutex);
1208 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1210 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1221 static int ath10k_update_channel_list(struct ath10k *ar)
1223 struct ieee80211_hw *hw = ar->hw;
1224 struct ieee80211_supported_band **bands;
1225 enum ieee80211_band band;
1226 struct ieee80211_channel *channel;
1227 struct wmi_scan_chan_list_arg arg = {0};
1228 struct wmi_channel_arg *ch;
1234 lockdep_assert_held(&ar->conf_mutex);
1236 bands = hw->wiphy->bands;
1237 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1241 for (i = 0; i < bands[band]->n_channels; i++) {
1242 if (bands[band]->channels[i].flags &
1243 IEEE80211_CHAN_DISABLED)
1250 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1251 arg.channels = kzalloc(len, GFP_KERNEL);
1256 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1260 for (i = 0; i < bands[band]->n_channels; i++) {
1261 channel = &bands[band]->channels[i];
1263 if (channel->flags & IEEE80211_CHAN_DISABLED)
1266 ch->allow_ht = true;
1268 /* FIXME: when should we really allow VHT? */
1269 ch->allow_vht = true;
1272 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1275 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1277 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1278 ch->passive = passive;
1280 ch->freq = channel->center_freq;
1281 ch->min_power = channel->max_power * 3;
1282 ch->max_power = channel->max_power * 4;
1283 ch->max_reg_power = channel->max_reg_power * 4;
1284 ch->max_antenna_gain = channel->max_antenna_gain;
1285 ch->reg_class_id = 0; /* FIXME */
1287 /* FIXME: why use only legacy modes, why not any
1288 * HT/VHT modes? Would that even make any
1290 if (channel->band == IEEE80211_BAND_2GHZ)
1291 ch->mode = MODE_11G;
1293 ch->mode = MODE_11A;
1295 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1298 ath10k_dbg(ATH10K_DBG_WMI,
1299 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1300 __func__, ch - arg.channels, arg.n_channels,
1301 ch->freq, ch->max_power, ch->max_reg_power,
1302 ch->max_antenna_gain, ch->mode);
1308 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1309 kfree(arg.channels);
1314 static void ath10k_regd_update(struct ath10k *ar)
1316 struct reg_dmn_pair_mapping *regpair;
1319 lockdep_assert_held(&ar->conf_mutex);
1321 ret = ath10k_update_channel_list(ar);
1323 ath10k_warn("could not update channel list (%d)\n", ret);
1325 regpair = ar->ath_common.regulatory.regpair;
1327 /* Target allows setting up per-band regdomain but ath_common provides
1328 * a combined one only */
1329 ret = ath10k_wmi_pdev_set_regdomain(ar,
1330 regpair->regDmnEnum,
1331 regpair->regDmnEnum, /* 2ghz */
1332 regpair->regDmnEnum, /* 5ghz */
1333 regpair->reg_2ghz_ctl,
1334 regpair->reg_5ghz_ctl);
1336 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1339 static void ath10k_reg_notifier(struct wiphy *wiphy,
1340 struct regulatory_request *request)
1342 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1343 struct ath10k *ar = hw->priv;
1345 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1347 mutex_lock(&ar->conf_mutex);
1348 if (ar->state == ATH10K_STATE_ON)
1349 ath10k_regd_update(ar);
1350 mutex_unlock(&ar->conf_mutex);
1358 * Frames sent to the FW have to be in "Native Wifi" format.
1359 * Strip the QoS field from the 802.11 header.
1361 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1362 struct ieee80211_tx_control *control,
1363 struct sk_buff *skb)
1365 struct ieee80211_hdr *hdr = (void *)skb->data;
1368 if (!ieee80211_is_data_qos(hdr->frame_control))
1371 qos_ctl = ieee80211_get_qos_ctl(hdr);
1372 memmove(qos_ctl, qos_ctl + IEEE80211_QOS_CTL_LEN,
1373 skb->len - ieee80211_hdrlen(hdr->frame_control));
1374 skb_trim(skb, skb->len - IEEE80211_QOS_CTL_LEN);
1377 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1379 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1380 struct ieee80211_vif *vif = info->control.vif;
1381 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1382 struct ath10k *ar = arvif->ar;
1383 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1384 struct ieee80211_key_conf *key = info->control.hw_key;
1387 /* TODO AP mode should be implemented */
1388 if (vif->type != NL80211_IFTYPE_STATION)
1391 if (!ieee80211_has_protected(hdr->frame_control))
1397 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1398 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1401 if (key->keyidx == arvif->def_wep_key_index)
1404 ath10k_dbg(ATH10K_DBG_MAC, "new wep keyidx will be %d\n", key->keyidx);
1406 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1407 WMI_VDEV_PARAM_DEF_KEYID,
1410 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1414 arvif->def_wep_key_index = key->keyidx;
1417 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1419 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1420 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1421 struct ieee80211_vif *vif = info->control.vif;
1422 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1424 /* This is case only for P2P_GO */
1425 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1426 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1429 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1430 spin_lock_bh(&ar->data_lock);
1431 if (arvif->u.ap.noa_data)
1432 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1434 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1435 arvif->u.ap.noa_data,
1436 arvif->u.ap.noa_len);
1437 spin_unlock_bh(&ar->data_lock);
1441 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1443 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1446 if (ieee80211_is_mgmt(hdr->frame_control))
1447 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1448 else if (ieee80211_is_nullfunc(hdr->frame_control))
1449 /* FW does not report tx status properly for NullFunc frames
1450 * unless they are sent through mgmt tx path. mac80211 sends
1451 * those frames when it detects link/beacon loss and depends on
1452 * the tx status to be correct. */
1453 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1455 ret = ath10k_htt_tx(&ar->htt, skb);
1458 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1459 ieee80211_free_txskb(ar->hw, skb);
1463 void ath10k_offchan_tx_purge(struct ath10k *ar)
1465 struct sk_buff *skb;
1468 skb = skb_dequeue(&ar->offchan_tx_queue);
1472 ieee80211_free_txskb(ar->hw, skb);
1476 void ath10k_offchan_tx_work(struct work_struct *work)
1478 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1479 struct ath10k_peer *peer;
1480 struct ieee80211_hdr *hdr;
1481 struct sk_buff *skb;
1482 const u8 *peer_addr;
1486 /* FW requirement: We must create a peer before FW will send out
1487 * an offchannel frame. Otherwise the frame will be stuck and
1488 * never transmitted. We delete the peer upon tx completion.
1489 * It is unlikely that a peer for offchannel tx will already be
1490 * present. However it may be in some rare cases so account for that.
1491 * Otherwise we might remove a legitimate peer and break stuff. */
1494 skb = skb_dequeue(&ar->offchan_tx_queue);
1498 mutex_lock(&ar->conf_mutex);
1500 ath10k_dbg(ATH10K_DBG_MAC, "processing offchannel skb %p\n",
1503 hdr = (struct ieee80211_hdr *)skb->data;
1504 peer_addr = ieee80211_get_DA(hdr);
1505 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1507 spin_lock_bh(&ar->data_lock);
1508 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1509 spin_unlock_bh(&ar->data_lock);
1512 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1513 peer_addr, vdev_id);
1516 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1518 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1519 peer_addr, vdev_id, ret);
1522 spin_lock_bh(&ar->data_lock);
1523 INIT_COMPLETION(ar->offchan_tx_completed);
1524 ar->offchan_tx_skb = skb;
1525 spin_unlock_bh(&ar->data_lock);
1527 ath10k_tx_htt(ar, skb);
1529 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1532 ath10k_warn("timed out waiting for offchannel skb %p\n",
1536 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1538 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1539 peer_addr, vdev_id, ret);
1542 mutex_unlock(&ar->conf_mutex);
1551 * This gets called if we dont get a heart-beat during scan.
1552 * This may indicate the FW has hung and we need to abort the
1553 * scan manually to prevent cancel_hw_scan() from deadlocking
1555 void ath10k_reset_scan(unsigned long ptr)
1557 struct ath10k *ar = (struct ath10k *)ptr;
1559 spin_lock_bh(&ar->data_lock);
1560 if (!ar->scan.in_progress) {
1561 spin_unlock_bh(&ar->data_lock);
1565 ath10k_warn("scan timeout. resetting. fw issue?\n");
1567 if (ar->scan.is_roc)
1568 ieee80211_remain_on_channel_expired(ar->hw);
1570 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1572 ar->scan.in_progress = false;
1573 complete_all(&ar->scan.completed);
1574 spin_unlock_bh(&ar->data_lock);
1577 static int ath10k_abort_scan(struct ath10k *ar)
1579 struct wmi_stop_scan_arg arg = {
1580 .req_id = 1, /* FIXME */
1581 .req_type = WMI_SCAN_STOP_ONE,
1582 .u.scan_id = ATH10K_SCAN_ID,
1586 lockdep_assert_held(&ar->conf_mutex);
1588 del_timer_sync(&ar->scan.timeout);
1590 spin_lock_bh(&ar->data_lock);
1591 if (!ar->scan.in_progress) {
1592 spin_unlock_bh(&ar->data_lock);
1596 ar->scan.aborting = true;
1597 spin_unlock_bh(&ar->data_lock);
1599 ret = ath10k_wmi_stop_scan(ar, &arg);
1601 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1602 spin_lock_bh(&ar->data_lock);
1603 ar->scan.in_progress = false;
1604 ath10k_offchan_tx_purge(ar);
1605 spin_unlock_bh(&ar->data_lock);
1609 ath10k_wmi_flush_tx(ar);
1611 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1613 ath10k_warn("timed out while waiting for scan to stop\n");
1615 /* scan completion may be done right after we timeout here, so let's
1616 * check the in_progress and tell mac80211 scan is completed. if we
1617 * don't do that and FW fails to send us scan completion indication
1618 * then userspace won't be able to scan anymore */
1621 spin_lock_bh(&ar->data_lock);
1622 if (ar->scan.in_progress) {
1623 ath10k_warn("could not stop scan. its still in progress\n");
1624 ar->scan.in_progress = false;
1625 ath10k_offchan_tx_purge(ar);
1628 spin_unlock_bh(&ar->data_lock);
1633 static int ath10k_start_scan(struct ath10k *ar,
1634 const struct wmi_start_scan_arg *arg)
1638 lockdep_assert_held(&ar->conf_mutex);
1640 ret = ath10k_wmi_start_scan(ar, arg);
1644 /* make sure we submit the command so the completion
1645 * timeout makes sense */
1646 ath10k_wmi_flush_tx(ar);
1648 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1650 ath10k_abort_scan(ar);
1654 /* the scan can complete earlier, before we even
1655 * start the timer. in that case the timer handler
1656 * checks ar->scan.in_progress and bails out if its
1657 * false. Add a 200ms margin to account event/command
1659 mod_timer(&ar->scan.timeout, jiffies +
1660 msecs_to_jiffies(arg->max_scan_time+200));
1664 /**********************/
1665 /* mac80211 callbacks */
1666 /**********************/
1668 static void ath10k_tx(struct ieee80211_hw *hw,
1669 struct ieee80211_tx_control *control,
1670 struct sk_buff *skb)
1672 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1673 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1674 struct ath10k *ar = hw->priv;
1675 struct ath10k_vif *arvif = NULL;
1679 if (info->control.vif) {
1680 arvif = ath10k_vif_to_arvif(info->control.vif);
1681 vdev_id = arvif->vdev_id;
1682 } else if (ar->monitor_enabled) {
1683 vdev_id = ar->monitor_vdev_id;
1686 /* We should disable CCK RATE due to P2P */
1687 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1688 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1690 /* we must calculate tid before we apply qos workaround
1691 * as we'd lose the qos control field */
1692 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1693 if (ieee80211_is_data_qos(hdr->frame_control) &&
1694 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1695 u8 *qc = ieee80211_get_qos_ctl(hdr);
1696 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1699 ath10k_tx_h_qos_workaround(hw, control, skb);
1700 ath10k_tx_h_update_wep_key(skb);
1701 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1702 ath10k_tx_h_seq_no(skb);
1704 memset(ATH10K_SKB_CB(skb), 0, sizeof(*ATH10K_SKB_CB(skb)));
1705 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1706 ATH10K_SKB_CB(skb)->htt.tid = tid;
1708 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1709 spin_lock_bh(&ar->data_lock);
1710 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1711 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1712 spin_unlock_bh(&ar->data_lock);
1714 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1716 skb_queue_tail(&ar->offchan_tx_queue, skb);
1717 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1721 ath10k_tx_htt(ar, skb);
1725 * Initialize various parameters with default vaules.
1727 static int ath10k_start(struct ieee80211_hw *hw)
1729 struct ath10k *ar = hw->priv;
1732 mutex_lock(&ar->conf_mutex);
1734 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1736 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1739 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1741 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1744 ar->state = ATH10K_STATE_ON;
1745 ath10k_regd_update(ar);
1747 mutex_unlock(&ar->conf_mutex);
1751 static void ath10k_stop(struct ieee80211_hw *hw)
1753 struct ath10k *ar = hw->priv;
1755 mutex_lock(&ar->conf_mutex);
1756 ath10k_offchan_tx_purge(ar);
1757 ar->state = ATH10K_STATE_OFF;
1758 mutex_unlock(&ar->conf_mutex);
1760 cancel_work_sync(&ar->offchan_tx_work);
1763 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1765 struct ath10k_generic_iter ar_iter;
1766 struct ath10k *ar = hw->priv;
1767 struct ieee80211_conf *conf = &hw->conf;
1771 mutex_lock(&ar->conf_mutex);
1773 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1774 ath10k_dbg(ATH10K_DBG_MAC, "Config channel %d mhz\n",
1775 conf->chandef.chan->center_freq);
1776 spin_lock_bh(&ar->data_lock);
1777 ar->rx_channel = conf->chandef.chan;
1778 spin_unlock_bh(&ar->data_lock);
1781 if (changed & IEEE80211_CONF_CHANGE_PS) {
1782 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1784 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
1786 ieee80211_iterate_active_interfaces_atomic(hw,
1794 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1795 if (conf->flags & IEEE80211_CONF_MONITOR)
1796 ret = ath10k_monitor_create(ar);
1798 ret = ath10k_monitor_destroy(ar);
1801 mutex_unlock(&ar->conf_mutex);
1807 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1808 * because we will send mgmt frames without CCK. This requirement
1809 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1812 static int ath10k_add_interface(struct ieee80211_hw *hw,
1813 struct ieee80211_vif *vif)
1815 struct ath10k *ar = hw->priv;
1816 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1817 enum wmi_sta_powersave_param param;
1819 u32 value, rts, frag;
1822 mutex_lock(&ar->conf_mutex);
1827 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1828 ath10k_warn("Only one monitor interface allowed\n");
1833 bit = ffs(ar->free_vdev_map);
1839 arvif->vdev_id = bit - 1;
1840 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1841 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1844 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1846 switch (vif->type) {
1847 case NL80211_IFTYPE_UNSPECIFIED:
1848 case NL80211_IFTYPE_STATION:
1849 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1851 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1853 case NL80211_IFTYPE_ADHOC:
1854 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1856 case NL80211_IFTYPE_AP:
1857 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1860 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1862 case NL80211_IFTYPE_MONITOR:
1863 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1870 ath10k_dbg(ATH10K_DBG_MAC, "Add interface: id %d type %d subtype %d\n",
1871 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1873 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1874 arvif->vdev_subtype, vif->addr);
1876 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1880 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
1881 arvif->def_wep_key_index);
1883 ath10k_warn("Failed to set default keyid: %d\n", ret);
1885 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1886 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
1887 ATH10K_HW_TXRX_NATIVE_WIFI);
1889 ath10k_warn("Failed to set TX encap: %d\n", ret);
1891 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1892 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
1894 ath10k_warn("Failed to create peer for AP: %d\n", ret);
1899 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
1900 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
1901 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
1902 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1905 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
1907 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1908 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1909 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1912 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
1914 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1915 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1916 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1919 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
1922 rts = min_t(u32, ar->hw->wiphy->rts_threshold, ATH10K_RTS_MAX);
1923 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1924 WMI_VDEV_PARAM_RTS_THRESHOLD,
1927 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
1928 arvif->vdev_id, ret);
1930 frag = clamp_t(u32, ar->hw->wiphy->frag_threshold,
1931 ATH10K_FRAGMT_THRESHOLD_MIN,
1932 ATH10K_FRAGMT_THRESHOLD_MAX);
1933 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1934 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
1937 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
1938 arvif->vdev_id, ret);
1940 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1941 ar->monitor_present = true;
1944 mutex_unlock(&ar->conf_mutex);
1948 static void ath10k_remove_interface(struct ieee80211_hw *hw,
1949 struct ieee80211_vif *vif)
1951 struct ath10k *ar = hw->priv;
1952 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1955 mutex_lock(&ar->conf_mutex);
1957 ath10k_dbg(ATH10K_DBG_MAC, "Remove interface: id %d\n", arvif->vdev_id);
1959 ar->free_vdev_map |= 1 << (arvif->vdev_id);
1961 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1962 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
1964 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
1966 kfree(arvif->u.ap.noa_data);
1969 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
1971 ath10k_warn("WMI vdev delete failed: %d\n", ret);
1973 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1974 ar->monitor_present = false;
1976 ath10k_peer_cleanup(ar, arvif->vdev_id);
1978 mutex_unlock(&ar->conf_mutex);
1982 * FIXME: Has to be verified.
1984 #define SUPPORTED_FILTERS \
1985 (FIF_PROMISC_IN_BSS | \
1990 FIF_BCN_PRBRESP_PROMISC | \
1994 static void ath10k_configure_filter(struct ieee80211_hw *hw,
1995 unsigned int changed_flags,
1996 unsigned int *total_flags,
1999 struct ath10k *ar = hw->priv;
2002 mutex_lock(&ar->conf_mutex);
2004 changed_flags &= SUPPORTED_FILTERS;
2005 *total_flags &= SUPPORTED_FILTERS;
2006 ar->filter_flags = *total_flags;
2008 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2009 !ar->monitor_enabled) {
2010 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2012 ath10k_warn("Unable to start monitor mode\n");
2014 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode started\n");
2015 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2016 ar->monitor_enabled) {
2017 ret = ath10k_monitor_stop(ar);
2019 ath10k_warn("Unable to stop monitor mode\n");
2021 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode stopped\n");
2024 mutex_unlock(&ar->conf_mutex);
2027 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2028 struct ieee80211_vif *vif,
2029 struct ieee80211_bss_conf *info,
2032 struct ath10k *ar = hw->priv;
2033 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2036 mutex_lock(&ar->conf_mutex);
2038 if (changed & BSS_CHANGED_IBSS)
2039 ath10k_control_ibss(arvif, info, vif->addr);
2041 if (changed & BSS_CHANGED_BEACON_INT) {
2042 arvif->beacon_interval = info->beacon_int;
2043 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2044 WMI_VDEV_PARAM_BEACON_INTERVAL,
2045 arvif->beacon_interval);
2047 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2050 ath10k_dbg(ATH10K_DBG_MAC,
2051 "Beacon interval: %d set for VDEV: %d\n",
2052 arvif->beacon_interval, arvif->vdev_id);
2055 if (changed & BSS_CHANGED_BEACON) {
2056 ret = ath10k_wmi_pdev_set_param(ar,
2057 WMI_PDEV_PARAM_BEACON_TX_MODE,
2058 WMI_BEACON_STAGGERED_MODE);
2060 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2063 ath10k_dbg(ATH10K_DBG_MAC,
2064 "Set staggered beacon mode for VDEV: %d\n",
2068 if (changed & BSS_CHANGED_BEACON_INFO) {
2069 arvif->dtim_period = info->dtim_period;
2071 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2072 WMI_VDEV_PARAM_DTIM_PERIOD,
2073 arvif->dtim_period);
2075 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2078 ath10k_dbg(ATH10K_DBG_MAC,
2079 "Set dtim period: %d for VDEV: %d\n",
2080 arvif->dtim_period, arvif->vdev_id);
2083 if (changed & BSS_CHANGED_SSID &&
2084 vif->type == NL80211_IFTYPE_AP) {
2085 arvif->u.ap.ssid_len = info->ssid_len;
2087 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2088 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2091 if (changed & BSS_CHANGED_BSSID) {
2092 if (!is_zero_ether_addr(info->bssid)) {
2093 ret = ath10k_peer_create(ar, arvif->vdev_id,
2096 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2097 info->bssid, arvif->vdev_id);
2099 ath10k_dbg(ATH10K_DBG_MAC,
2100 "Added peer: %pM for VDEV: %d\n",
2101 info->bssid, arvif->vdev_id);
2104 if (vif->type == NL80211_IFTYPE_STATION) {
2106 * this is never erased as we it for crypto key
2107 * clearing; this is FW requirement
2109 memcpy(arvif->u.sta.bssid, info->bssid,
2112 ret = ath10k_vdev_start(arvif);
2114 ath10k_dbg(ATH10K_DBG_MAC,
2115 "VDEV: %d started with BSSID: %pM\n",
2116 arvif->vdev_id, info->bssid);
2120 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2121 * so driver need to store it. It is needed when leaving
2122 * IBSS in order to remove BSSID peer.
2124 if (vif->type == NL80211_IFTYPE_ADHOC)
2125 memcpy(arvif->u.ibss.bssid, info->bssid,
2130 if (changed & BSS_CHANGED_BEACON_ENABLED)
2131 ath10k_control_beaconing(arvif, info);
2133 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2135 if (info->use_cts_prot)
2140 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2141 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2144 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2147 ath10k_dbg(ATH10K_DBG_MAC,
2148 "Set CTS prot: %d for VDEV: %d\n",
2149 cts_prot, arvif->vdev_id);
2152 if (changed & BSS_CHANGED_ERP_SLOT) {
2154 if (info->use_short_slot)
2155 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2158 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2160 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2161 WMI_VDEV_PARAM_SLOT_TIME,
2164 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2167 ath10k_dbg(ATH10K_DBG_MAC,
2168 "Set slottime: %d for VDEV: %d\n",
2169 slottime, arvif->vdev_id);
2172 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2174 if (info->use_short_preamble)
2175 preamble = WMI_VDEV_PREAMBLE_SHORT;
2177 preamble = WMI_VDEV_PREAMBLE_LONG;
2179 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2180 WMI_VDEV_PARAM_PREAMBLE,
2183 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2186 ath10k_dbg(ATH10K_DBG_MAC,
2187 "Set preamble: %d for VDEV: %d\n",
2188 preamble, arvif->vdev_id);
2191 if (changed & BSS_CHANGED_ASSOC) {
2193 ath10k_bss_assoc(hw, vif, info);
2196 mutex_unlock(&ar->conf_mutex);
2199 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2200 struct ieee80211_vif *vif,
2201 struct cfg80211_scan_request *req)
2203 struct ath10k *ar = hw->priv;
2204 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2205 struct wmi_start_scan_arg arg;
2209 mutex_lock(&ar->conf_mutex);
2211 spin_lock_bh(&ar->data_lock);
2212 if (ar->scan.in_progress) {
2213 spin_unlock_bh(&ar->data_lock);
2218 INIT_COMPLETION(ar->scan.started);
2219 INIT_COMPLETION(ar->scan.completed);
2220 ar->scan.in_progress = true;
2221 ar->scan.aborting = false;
2222 ar->scan.is_roc = false;
2223 ar->scan.vdev_id = arvif->vdev_id;
2224 spin_unlock_bh(&ar->data_lock);
2226 memset(&arg, 0, sizeof(arg));
2227 ath10k_wmi_start_scan_init(ar, &arg);
2228 arg.vdev_id = arvif->vdev_id;
2229 arg.scan_id = ATH10K_SCAN_ID;
2232 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2235 arg.ie_len = req->ie_len;
2236 memcpy(arg.ie, req->ie, arg.ie_len);
2240 arg.n_ssids = req->n_ssids;
2241 for (i = 0; i < arg.n_ssids; i++) {
2242 arg.ssids[i].len = req->ssids[i].ssid_len;
2243 arg.ssids[i].ssid = req->ssids[i].ssid;
2247 if (req->n_channels) {
2248 arg.n_channels = req->n_channels;
2249 for (i = 0; i < arg.n_channels; i++)
2250 arg.channels[i] = req->channels[i]->center_freq;
2253 ret = ath10k_start_scan(ar, &arg);
2255 ath10k_warn("could not start hw scan (%d)\n", ret);
2256 spin_lock_bh(&ar->data_lock);
2257 ar->scan.in_progress = false;
2258 spin_unlock_bh(&ar->data_lock);
2262 mutex_unlock(&ar->conf_mutex);
2266 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2267 struct ieee80211_vif *vif)
2269 struct ath10k *ar = hw->priv;
2272 mutex_lock(&ar->conf_mutex);
2273 ret = ath10k_abort_scan(ar);
2275 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2277 ieee80211_scan_completed(hw, 1 /* aborted */);
2279 mutex_unlock(&ar->conf_mutex);
2282 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2283 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2284 struct ieee80211_key_conf *key)
2286 struct ath10k *ar = hw->priv;
2287 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2288 struct ath10k_peer *peer;
2289 const u8 *peer_addr;
2290 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2291 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2294 if (key->keyidx > WMI_MAX_KEY_INDEX)
2297 mutex_lock(&ar->conf_mutex);
2300 peer_addr = sta->addr;
2301 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2302 peer_addr = vif->bss_conf.bssid;
2304 peer_addr = vif->addr;
2306 key->hw_key_idx = key->keyidx;
2308 /* the peer should not disappear in mid-way (unless FW goes awry) since
2309 * we already hold conf_mutex. we just make sure its there now. */
2310 spin_lock_bh(&ar->data_lock);
2311 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2312 spin_unlock_bh(&ar->data_lock);
2315 if (cmd == SET_KEY) {
2316 ath10k_warn("cannot install key for non-existent peer %pM\n",
2321 /* if the peer doesn't exist there is no key to disable
2329 arvif->wep_keys[key->keyidx] = key;
2331 arvif->wep_keys[key->keyidx] = NULL;
2333 if (cmd == DISABLE_KEY)
2334 ath10k_clear_vdev_key(arvif, key);
2337 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2339 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2343 spin_lock_bh(&ar->data_lock);
2344 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2345 if (peer && cmd == SET_KEY)
2346 peer->keys[key->keyidx] = key;
2347 else if (peer && cmd == DISABLE_KEY)
2348 peer->keys[key->keyidx] = NULL;
2349 else if (peer == NULL)
2350 /* impossible unless FW goes crazy */
2351 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2352 spin_unlock_bh(&ar->data_lock);
2355 mutex_unlock(&ar->conf_mutex);
2359 static int ath10k_sta_state(struct ieee80211_hw *hw,
2360 struct ieee80211_vif *vif,
2361 struct ieee80211_sta *sta,
2362 enum ieee80211_sta_state old_state,
2363 enum ieee80211_sta_state new_state)
2365 struct ath10k *ar = hw->priv;
2366 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2369 mutex_lock(&ar->conf_mutex);
2371 if (old_state == IEEE80211_STA_NOTEXIST &&
2372 new_state == IEEE80211_STA_NONE &&
2373 vif->type != NL80211_IFTYPE_STATION) {
2375 * New station addition.
2377 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2379 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2380 sta->addr, arvif->vdev_id);
2382 ath10k_dbg(ATH10K_DBG_MAC,
2383 "Added peer: %pM for VDEV: %d\n",
2384 sta->addr, arvif->vdev_id);
2385 } else if ((old_state == IEEE80211_STA_NONE &&
2386 new_state == IEEE80211_STA_NOTEXIST)) {
2388 * Existing station deletion.
2390 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2392 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2393 sta->addr, arvif->vdev_id);
2395 ath10k_dbg(ATH10K_DBG_MAC,
2396 "Removed peer: %pM for VDEV: %d\n",
2397 sta->addr, arvif->vdev_id);
2399 if (vif->type == NL80211_IFTYPE_STATION)
2400 ath10k_bss_disassoc(hw, vif);
2401 } else if (old_state == IEEE80211_STA_AUTH &&
2402 new_state == IEEE80211_STA_ASSOC &&
2403 (vif->type == NL80211_IFTYPE_AP ||
2404 vif->type == NL80211_IFTYPE_ADHOC)) {
2408 ret = ath10k_station_assoc(ar, arvif, sta);
2410 ath10k_warn("Failed to associate station: %pM\n",
2413 ath10k_dbg(ATH10K_DBG_MAC,
2414 "Station %pM moved to assoc state\n",
2416 } else if (old_state == IEEE80211_STA_ASSOC &&
2417 new_state == IEEE80211_STA_AUTH &&
2418 (vif->type == NL80211_IFTYPE_AP ||
2419 vif->type == NL80211_IFTYPE_ADHOC)) {
2423 ret = ath10k_station_disassoc(ar, arvif, sta);
2425 ath10k_warn("Failed to disassociate station: %pM\n",
2428 ath10k_dbg(ATH10K_DBG_MAC,
2429 "Station %pM moved to disassociated state\n",
2433 mutex_unlock(&ar->conf_mutex);
2437 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2438 u16 ac, bool enable)
2440 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2444 lockdep_assert_held(&ar->conf_mutex);
2446 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2450 case IEEE80211_AC_VO:
2451 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2452 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2454 case IEEE80211_AC_VI:
2455 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2456 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2458 case IEEE80211_AC_BE:
2459 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2460 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2462 case IEEE80211_AC_BK:
2463 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2464 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2469 arvif->u.sta.uapsd |= value;
2471 arvif->u.sta.uapsd &= ~value;
2473 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2474 WMI_STA_PS_PARAM_UAPSD,
2475 arvif->u.sta.uapsd);
2477 ath10k_warn("could not set uapsd params %d\n", ret);
2481 if (arvif->u.sta.uapsd)
2482 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2484 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2486 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2487 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2490 ath10k_warn("could not set rx wake param %d\n", ret);
2496 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2497 struct ieee80211_vif *vif, u16 ac,
2498 const struct ieee80211_tx_queue_params *params)
2500 struct ath10k *ar = hw->priv;
2501 struct wmi_wmm_params_arg *p = NULL;
2504 mutex_lock(&ar->conf_mutex);
2507 case IEEE80211_AC_VO:
2508 p = &ar->wmm_params.ac_vo;
2510 case IEEE80211_AC_VI:
2511 p = &ar->wmm_params.ac_vi;
2513 case IEEE80211_AC_BE:
2514 p = &ar->wmm_params.ac_be;
2516 case IEEE80211_AC_BK:
2517 p = &ar->wmm_params.ac_bk;
2526 p->cwmin = params->cw_min;
2527 p->cwmax = params->cw_max;
2528 p->aifs = params->aifs;
2531 * The channel time duration programmed in the HW is in absolute
2532 * microseconds, while mac80211 gives the txop in units of
2535 p->txop = params->txop * 32;
2537 /* FIXME: FW accepts wmm params per hw, not per vif */
2538 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2540 ath10k_warn("could not set wmm params %d\n", ret);
2544 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2546 ath10k_warn("could not set sta uapsd %d\n", ret);
2549 mutex_unlock(&ar->conf_mutex);
2553 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2555 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2556 struct ieee80211_vif *vif,
2557 struct ieee80211_channel *chan,
2559 enum ieee80211_roc_type type)
2561 struct ath10k *ar = hw->priv;
2562 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2563 struct wmi_start_scan_arg arg;
2566 mutex_lock(&ar->conf_mutex);
2568 spin_lock_bh(&ar->data_lock);
2569 if (ar->scan.in_progress) {
2570 spin_unlock_bh(&ar->data_lock);
2575 INIT_COMPLETION(ar->scan.started);
2576 INIT_COMPLETION(ar->scan.completed);
2577 INIT_COMPLETION(ar->scan.on_channel);
2578 ar->scan.in_progress = true;
2579 ar->scan.aborting = false;
2580 ar->scan.is_roc = true;
2581 ar->scan.vdev_id = arvif->vdev_id;
2582 ar->scan.roc_freq = chan->center_freq;
2583 spin_unlock_bh(&ar->data_lock);
2585 memset(&arg, 0, sizeof(arg));
2586 ath10k_wmi_start_scan_init(ar, &arg);
2587 arg.vdev_id = arvif->vdev_id;
2588 arg.scan_id = ATH10K_SCAN_ID;
2590 arg.channels[0] = chan->center_freq;
2591 arg.dwell_time_active = duration;
2592 arg.dwell_time_passive = duration;
2593 arg.max_scan_time = 2 * duration;
2594 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2595 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2597 ret = ath10k_start_scan(ar, &arg);
2599 ath10k_warn("could not start roc scan (%d)\n", ret);
2600 spin_lock_bh(&ar->data_lock);
2601 ar->scan.in_progress = false;
2602 spin_unlock_bh(&ar->data_lock);
2606 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2608 ath10k_warn("could not switch to channel for roc scan\n");
2609 ath10k_abort_scan(ar);
2616 mutex_unlock(&ar->conf_mutex);
2620 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2622 struct ath10k *ar = hw->priv;
2624 mutex_lock(&ar->conf_mutex);
2625 ath10k_abort_scan(ar);
2626 mutex_unlock(&ar->conf_mutex);
2632 * Both RTS and Fragmentation threshold are interface-specific
2633 * in ath10k, but device-specific in mac80211.
2635 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2637 struct ath10k_generic_iter *ar_iter = data;
2638 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2639 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2641 lockdep_assert_held(&arvif->ar->conf_mutex);
2643 rts = min_t(u32, rts, ATH10K_RTS_MAX);
2645 ar_iter->ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2646 WMI_VDEV_PARAM_RTS_THRESHOLD,
2649 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2652 ath10k_dbg(ATH10K_DBG_MAC,
2653 "Set RTS threshold: %d for VDEV: %d\n",
2654 rts, arvif->vdev_id);
2657 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2659 struct ath10k_generic_iter ar_iter;
2660 struct ath10k *ar = hw->priv;
2662 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2665 mutex_lock(&ar->conf_mutex);
2666 ieee80211_iterate_active_interfaces_atomic(
2667 hw, IEEE80211_IFACE_ITER_NORMAL,
2668 ath10k_set_rts_iter, &ar_iter);
2669 mutex_unlock(&ar->conf_mutex);
2674 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2676 struct ath10k_generic_iter *ar_iter = data;
2677 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2678 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2681 lockdep_assert_held(&arvif->ar->conf_mutex);
2683 frag = clamp_t(u32, frag,
2684 ATH10K_FRAGMT_THRESHOLD_MIN,
2685 ATH10K_FRAGMT_THRESHOLD_MAX);
2687 ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2688 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
2693 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2696 ath10k_dbg(ATH10K_DBG_MAC,
2697 "Set frag threshold: %d for VDEV: %d\n",
2698 frag, arvif->vdev_id);
2701 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2703 struct ath10k_generic_iter ar_iter;
2704 struct ath10k *ar = hw->priv;
2706 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2709 mutex_lock(&ar->conf_mutex);
2710 ieee80211_iterate_active_interfaces_atomic(
2711 hw, IEEE80211_IFACE_ITER_NORMAL,
2712 ath10k_set_frag_iter, &ar_iter);
2713 mutex_unlock(&ar->conf_mutex);
2718 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2720 struct ath10k *ar = hw->priv;
2723 /* mac80211 doesn't care if we really xmit queued frames or not
2724 * we'll collect those frames either way if we stop/delete vdevs */
2728 mutex_lock(&ar->conf_mutex);
2730 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
2732 spin_lock_bh(&ar->htt.tx_lock);
2733 empty = bitmap_empty(ar->htt.used_msdu_ids,
2734 ar->htt.max_num_pending_tx);
2735 spin_unlock_bh(&ar->htt.tx_lock);
2737 }), ATH10K_FLUSH_TIMEOUT_HZ);
2739 ath10k_warn("tx not flushed\n");
2741 mutex_unlock(&ar->conf_mutex);
2744 /* TODO: Implement this function properly
2745 * For now it is needed to reply to Probe Requests in IBSS mode.
2746 * Propably we need this information from FW.
2748 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2754 static int ath10k_suspend(struct ieee80211_hw *hw,
2755 struct cfg80211_wowlan *wowlan)
2757 struct ath10k *ar = hw->priv;
2760 ar->is_target_paused = false;
2762 ret = ath10k_wmi_pdev_suspend_target(ar);
2764 ath10k_warn("could not suspend target (%d)\n", ret);
2768 ret = wait_event_interruptible_timeout(ar->event_queue,
2769 ar->is_target_paused == true,
2772 ath10k_warn("suspend interrupted (%d)\n", ret);
2774 } else if (ret == 0) {
2775 ath10k_warn("suspend timed out - target pause event never came\n");
2779 ret = ath10k_hif_suspend(ar);
2781 ath10k_warn("could not suspend hif (%d)\n", ret);
2787 ret = ath10k_wmi_pdev_resume_target(ar);
2789 ath10k_warn("could not resume target (%d)\n", ret);
2793 static int ath10k_resume(struct ieee80211_hw *hw)
2795 struct ath10k *ar = hw->priv;
2798 ret = ath10k_hif_resume(ar);
2800 ath10k_warn("could not resume hif (%d)\n", ret);
2804 ret = ath10k_wmi_pdev_resume_target(ar);
2806 ath10k_warn("could not resume target (%d)\n", ret);
2814 static const struct ieee80211_ops ath10k_ops = {
2816 .start = ath10k_start,
2817 .stop = ath10k_stop,
2818 .config = ath10k_config,
2819 .add_interface = ath10k_add_interface,
2820 .remove_interface = ath10k_remove_interface,
2821 .configure_filter = ath10k_configure_filter,
2822 .bss_info_changed = ath10k_bss_info_changed,
2823 .hw_scan = ath10k_hw_scan,
2824 .cancel_hw_scan = ath10k_cancel_hw_scan,
2825 .set_key = ath10k_set_key,
2826 .sta_state = ath10k_sta_state,
2827 .conf_tx = ath10k_conf_tx,
2828 .remain_on_channel = ath10k_remain_on_channel,
2829 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
2830 .set_rts_threshold = ath10k_set_rts_threshold,
2831 .set_frag_threshold = ath10k_set_frag_threshold,
2832 .flush = ath10k_flush,
2833 .tx_last_beacon = ath10k_tx_last_beacon,
2835 .suspend = ath10k_suspend,
2836 .resume = ath10k_resume,
2840 #define RATETAB_ENT(_rate, _rateid, _flags) { \
2841 .bitrate = (_rate), \
2842 .flags = (_flags), \
2843 .hw_value = (_rateid), \
2846 #define CHAN2G(_channel, _freq, _flags) { \
2847 .band = IEEE80211_BAND_2GHZ, \
2848 .hw_value = (_channel), \
2849 .center_freq = (_freq), \
2850 .flags = (_flags), \
2851 .max_antenna_gain = 0, \
2855 #define CHAN5G(_channel, _freq, _flags) { \
2856 .band = IEEE80211_BAND_5GHZ, \
2857 .hw_value = (_channel), \
2858 .center_freq = (_freq), \
2859 .flags = (_flags), \
2860 .max_antenna_gain = 0, \
2864 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
2874 CHAN2G(10, 2457, 0),
2875 CHAN2G(11, 2462, 0),
2876 CHAN2G(12, 2467, 0),
2877 CHAN2G(13, 2472, 0),
2878 CHAN2G(14, 2484, 0),
2881 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
2882 CHAN5G(36, 5180, 0),
2883 CHAN5G(40, 5200, 0),
2884 CHAN5G(44, 5220, 0),
2885 CHAN5G(48, 5240, 0),
2886 CHAN5G(52, 5260, 0),
2887 CHAN5G(56, 5280, 0),
2888 CHAN5G(60, 5300, 0),
2889 CHAN5G(64, 5320, 0),
2890 CHAN5G(100, 5500, 0),
2891 CHAN5G(104, 5520, 0),
2892 CHAN5G(108, 5540, 0),
2893 CHAN5G(112, 5560, 0),
2894 CHAN5G(116, 5580, 0),
2895 CHAN5G(120, 5600, 0),
2896 CHAN5G(124, 5620, 0),
2897 CHAN5G(128, 5640, 0),
2898 CHAN5G(132, 5660, 0),
2899 CHAN5G(136, 5680, 0),
2900 CHAN5G(140, 5700, 0),
2901 CHAN5G(149, 5745, 0),
2902 CHAN5G(153, 5765, 0),
2903 CHAN5G(157, 5785, 0),
2904 CHAN5G(161, 5805, 0),
2905 CHAN5G(165, 5825, 0),
2908 static struct ieee80211_rate ath10k_rates[] = {
2910 RATETAB_ENT(10, 0x82, 0),
2911 RATETAB_ENT(20, 0x84, 0),
2912 RATETAB_ENT(55, 0x8b, 0),
2913 RATETAB_ENT(110, 0x96, 0),
2915 RATETAB_ENT(60, 0x0c, 0),
2916 RATETAB_ENT(90, 0x12, 0),
2917 RATETAB_ENT(120, 0x18, 0),
2918 RATETAB_ENT(180, 0x24, 0),
2919 RATETAB_ENT(240, 0x30, 0),
2920 RATETAB_ENT(360, 0x48, 0),
2921 RATETAB_ENT(480, 0x60, 0),
2922 RATETAB_ENT(540, 0x6c, 0),
2925 #define ath10k_a_rates (ath10k_rates + 4)
2926 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
2927 #define ath10k_g_rates (ath10k_rates + 0)
2928 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
2930 struct ath10k *ath10k_mac_create(void)
2932 struct ieee80211_hw *hw;
2935 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
2945 void ath10k_mac_destroy(struct ath10k *ar)
2947 ieee80211_free_hw(ar->hw);
2950 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
2953 .types = BIT(NL80211_IFTYPE_STATION)
2954 | BIT(NL80211_IFTYPE_P2P_CLIENT)
2955 | BIT(NL80211_IFTYPE_P2P_GO)
2956 | BIT(NL80211_IFTYPE_AP)
2960 static const struct ieee80211_iface_combination ath10k_if_comb = {
2961 .limits = ath10k_if_limits,
2962 .n_limits = ARRAY_SIZE(ath10k_if_limits),
2963 .max_interfaces = 8,
2964 .num_different_channels = 1,
2965 .beacon_int_infra_match = true,
2968 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
2970 struct ieee80211_sta_vht_cap vht_cap = {0};
2973 vht_cap.vht_supported = 1;
2974 vht_cap.cap = ar->vht_cap_info;
2976 /* FIXME: check dynamically how many streams board supports */
2977 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
2978 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
2979 IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
2980 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
2981 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
2982 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
2983 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
2984 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
2986 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
2987 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
2992 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
2995 struct ieee80211_sta_ht_cap ht_cap = {0};
2997 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3000 ht_cap.ht_supported = 1;
3001 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3002 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3003 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3004 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3005 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3007 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3008 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3010 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3011 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3013 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3016 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3017 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3022 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3023 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3025 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3028 stbc = ar->ht_cap_info;
3029 stbc &= WMI_HT_CAP_RX_STBC;
3030 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3031 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3032 stbc &= IEEE80211_HT_CAP_RX_STBC;
3037 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3038 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3040 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3041 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3043 /* max AMSDU is implicitly taken from vht_cap_info */
3044 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3045 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3047 for (i = 0; i < WMI_MAX_SPATIAL_STREAM; i++)
3048 ht_cap.mcs.rx_mask[i] = 0xFF;
3050 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3056 static void ath10k_get_arvif_iter(void *data, u8 *mac,
3057 struct ieee80211_vif *vif)
3059 struct ath10k_vif_iter *arvif_iter = data;
3060 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3062 if (arvif->vdev_id == arvif_iter->vdev_id)
3063 arvif_iter->arvif = arvif;
3066 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3068 struct ath10k_vif_iter arvif_iter;
3071 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3072 arvif_iter.vdev_id = vdev_id;
3074 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3075 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3077 ath10k_get_arvif_iter,
3079 if (!arvif_iter.arvif) {
3080 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3084 return arvif_iter.arvif;
3087 int ath10k_mac_register(struct ath10k *ar)
3089 struct ieee80211_supported_band *band;
3090 struct ieee80211_sta_vht_cap vht_cap;
3091 struct ieee80211_sta_ht_cap ht_cap;
3095 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3097 SET_IEEE80211_DEV(ar->hw, ar->dev);
3099 ht_cap = ath10k_get_ht_cap(ar);
3100 vht_cap = ath10k_create_vht_cap(ar);
3102 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3103 channels = kmemdup(ath10k_2ghz_channels,
3104 sizeof(ath10k_2ghz_channels),
3109 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3110 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3111 band->channels = channels;
3112 band->n_bitrates = ath10k_g_rates_size;
3113 band->bitrates = ath10k_g_rates;
3114 band->ht_cap = ht_cap;
3116 /* vht is not supported in 2.4 GHz */
3118 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3121 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3122 channels = kmemdup(ath10k_5ghz_channels,
3123 sizeof(ath10k_5ghz_channels),
3126 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3127 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3128 kfree(band->channels);
3133 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3134 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3135 band->channels = channels;
3136 band->n_bitrates = ath10k_a_rates_size;
3137 band->bitrates = ath10k_a_rates;
3138 band->ht_cap = ht_cap;
3139 band->vht_cap = vht_cap;
3140 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3143 ar->hw->wiphy->interface_modes =
3144 BIT(NL80211_IFTYPE_STATION) |
3145 BIT(NL80211_IFTYPE_ADHOC) |
3146 BIT(NL80211_IFTYPE_AP) |
3147 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3148 BIT(NL80211_IFTYPE_P2P_GO);
3150 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3151 IEEE80211_HW_SUPPORTS_PS |
3152 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3153 IEEE80211_HW_SUPPORTS_UAPSD |
3154 IEEE80211_HW_MFP_CAPABLE |
3155 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3156 IEEE80211_HW_HAS_RATE_CONTROL |
3157 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3158 IEEE80211_HW_WANT_MONITOR_VIF |
3159 IEEE80211_HW_AP_LINK_PS;
3161 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3162 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3164 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3165 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3166 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3169 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3170 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3172 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3174 ar->hw->channel_change_time = 5000;
3175 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3177 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3178 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3180 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3182 * on LL hardware queues are managed entirely by the FW
3183 * so we only advertise to mac we can do the queues thing
3187 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3188 ar->hw->wiphy->n_iface_combinations = 1;
3190 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3191 ath10k_reg_notifier);
3193 ath10k_err("Regulatory initialization failed\n");
3197 ret = ieee80211_register_hw(ar->hw);
3199 ath10k_err("ieee80211 registration failed: %d\n", ret);
3203 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3204 ret = regulatory_hint(ar->hw->wiphy,
3205 ar->ath_common.regulatory.alpha2);
3212 ieee80211_unregister_hw(ar->hw);
3216 void ath10k_mac_unregister(struct ath10k *ar)
3218 ieee80211_unregister_hw(ar->hw);
3220 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3221 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3223 SET_IEEE80211_DEV(ar->hw, NULL);