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_mac_set_rts(struct ath10k_vif *arvif, u32 value)
337 if (value != 0xFFFFFFFF)
338 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
341 return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
342 WMI_VDEV_PARAM_RTS_THRESHOLD,
346 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
348 if (value != 0xFFFFFFFF)
349 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
350 ATH10K_FRAGMT_THRESHOLD_MIN,
351 ATH10K_FRAGMT_THRESHOLD_MAX);
353 return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
354 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
358 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
362 lockdep_assert_held(&ar->conf_mutex);
364 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
368 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
375 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
377 struct ath10k_peer *peer, *tmp;
379 lockdep_assert_held(&ar->conf_mutex);
381 spin_lock_bh(&ar->data_lock);
382 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
383 if (peer->vdev_id != vdev_id)
386 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
387 peer->addr, vdev_id);
389 list_del(&peer->list);
392 spin_unlock_bh(&ar->data_lock);
395 static void ath10k_peer_cleanup_all(struct ath10k *ar)
397 struct ath10k_peer *peer, *tmp;
399 lockdep_assert_held(&ar->conf_mutex);
401 spin_lock_bh(&ar->data_lock);
402 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
403 list_del(&peer->list);
406 spin_unlock_bh(&ar->data_lock);
409 /************************/
410 /* Interface management */
411 /************************/
413 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
417 lockdep_assert_held(&ar->conf_mutex);
419 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
420 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
427 static int ath10k_vdev_start(struct ath10k_vif *arvif)
429 struct ath10k *ar = arvif->ar;
430 struct ieee80211_conf *conf = &ar->hw->conf;
431 struct ieee80211_channel *channel = conf->chandef.chan;
432 struct wmi_vdev_start_request_arg arg = {};
435 lockdep_assert_held(&ar->conf_mutex);
437 INIT_COMPLETION(ar->vdev_setup_done);
439 arg.vdev_id = arvif->vdev_id;
440 arg.dtim_period = arvif->dtim_period;
441 arg.bcn_intval = arvif->beacon_interval;
443 arg.channel.freq = channel->center_freq;
445 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
447 arg.channel.mode = chan_to_phymode(&conf->chandef);
449 arg.channel.min_power = channel->max_power * 3;
450 arg.channel.max_power = channel->max_power * 4;
451 arg.channel.max_reg_power = channel->max_reg_power * 4;
452 arg.channel.max_antenna_gain = channel->max_antenna_gain;
454 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
455 arg.ssid = arvif->u.ap.ssid;
456 arg.ssid_len = arvif->u.ap.ssid_len;
457 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
458 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
459 arg.ssid = arvif->vif->bss_conf.ssid;
460 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
463 ath10k_dbg(ATH10K_DBG_MAC,
464 "mac vdev %d start center_freq %d phymode %s\n",
465 arg.vdev_id, arg.channel.freq,
466 ath10k_wmi_phymode_str(arg.channel.mode));
468 ret = ath10k_wmi_vdev_start(ar, &arg);
470 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
474 ret = ath10k_vdev_setup_sync(ar);
476 ath10k_warn("vdev setup failed %d\n", ret);
483 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
485 struct ath10k *ar = arvif->ar;
488 lockdep_assert_held(&ar->conf_mutex);
490 INIT_COMPLETION(ar->vdev_setup_done);
492 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
494 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
498 ret = ath10k_vdev_setup_sync(ar);
500 ath10k_warn("vdev setup failed %d\n", ret);
507 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
509 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
510 struct wmi_vdev_start_request_arg arg = {};
513 lockdep_assert_held(&ar->conf_mutex);
515 arg.vdev_id = vdev_id;
516 arg.channel.freq = channel->center_freq;
517 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
519 /* TODO setup this dynamically, what in case we
520 don't have any vifs? */
521 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
523 arg.channel.min_power = channel->max_power * 3;
524 arg.channel.max_power = channel->max_power * 4;
525 arg.channel.max_reg_power = channel->max_reg_power * 4;
526 arg.channel.max_antenna_gain = channel->max_antenna_gain;
528 ret = ath10k_wmi_vdev_start(ar, &arg);
530 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
534 ret = ath10k_vdev_setup_sync(ar);
536 ath10k_warn("Monitor vdev setup failed %d\n", ret);
540 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
542 ath10k_warn("Monitor vdev up failed: %d\n", ret);
546 ar->monitor_vdev_id = vdev_id;
547 ar->monitor_enabled = true;
552 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
554 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
559 static int ath10k_monitor_stop(struct ath10k *ar)
563 lockdep_assert_held(&ar->conf_mutex);
565 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
567 ath10k_warn("Monitor vdev down failed: %d\n", ret);
569 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
571 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
573 ret = ath10k_vdev_setup_sync(ar);
575 ath10k_warn("Monitor_down sync failed: %d\n", ret);
577 ar->monitor_enabled = false;
581 static int ath10k_monitor_create(struct ath10k *ar)
585 lockdep_assert_held(&ar->conf_mutex);
587 if (ar->monitor_present) {
588 ath10k_warn("Monitor mode already enabled\n");
592 bit = ffs(ar->free_vdev_map);
594 ath10k_warn("No free VDEV slots\n");
598 ar->monitor_vdev_id = bit - 1;
599 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
601 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
602 WMI_VDEV_TYPE_MONITOR,
605 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
609 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
610 ar->monitor_vdev_id);
612 ar->monitor_present = true;
617 * Restore the ID to the global map.
619 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
623 static int ath10k_monitor_destroy(struct ath10k *ar)
627 lockdep_assert_held(&ar->conf_mutex);
629 if (!ar->monitor_present)
632 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
634 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
638 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
639 ar->monitor_present = false;
641 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
642 ar->monitor_vdev_id);
646 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
647 struct ieee80211_bss_conf *info)
651 lockdep_assert_held(&arvif->ar->conf_mutex);
653 if (!info->enable_beacon) {
654 ath10k_vdev_stop(arvif);
658 arvif->tx_seq_no = 0x1000;
660 ret = ath10k_vdev_start(arvif);
664 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
666 ath10k_warn("Failed to bring up VDEV: %d\n",
670 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
673 static void ath10k_control_ibss(struct ath10k_vif *arvif,
674 struct ieee80211_bss_conf *info,
675 const u8 self_peer[ETH_ALEN])
679 lockdep_assert_held(&arvif->ar->conf_mutex);
681 if (!info->ibss_joined) {
682 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
684 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
685 self_peer, arvif->vdev_id, ret);
687 if (is_zero_ether_addr(arvif->u.ibss.bssid))
690 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
691 arvif->u.ibss.bssid);
693 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
694 arvif->u.ibss.bssid, arvif->vdev_id, ret);
698 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
703 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
705 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
706 self_peer, arvif->vdev_id, ret);
710 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
711 WMI_VDEV_PARAM_ATIM_WINDOW,
712 ATH10K_DEFAULT_ATIM);
714 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
715 arvif->vdev_id, ret);
719 * Review this when mac80211 gains per-interface powersave support.
721 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
723 struct ath10k_generic_iter *ar_iter = data;
724 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
725 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
726 enum wmi_sta_powersave_param param;
727 enum wmi_sta_ps_mode psmode;
730 lockdep_assert_held(&arvif->ar->conf_mutex);
732 if (vif->type != NL80211_IFTYPE_STATION)
735 if (conf->flags & IEEE80211_CONF_PS) {
736 psmode = WMI_STA_PS_MODE_ENABLED;
737 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
739 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
742 conf->dynamic_ps_timeout);
744 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
751 psmode = WMI_STA_PS_MODE_DISABLED;
754 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
755 arvif->vdev_id, psmode ? "enable" : "disable");
757 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
760 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
761 psmode, arvif->vdev_id);
764 /**********************/
765 /* Station management */
766 /**********************/
768 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
769 struct ath10k_vif *arvif,
770 struct ieee80211_sta *sta,
771 struct ieee80211_bss_conf *bss_conf,
772 struct wmi_peer_assoc_complete_arg *arg)
774 lockdep_assert_held(&ar->conf_mutex);
776 memcpy(arg->addr, sta->addr, ETH_ALEN);
777 arg->vdev_id = arvif->vdev_id;
778 arg->peer_aid = sta->aid;
779 arg->peer_flags |= WMI_PEER_AUTH;
781 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
783 * Seems FW have problems with Power Save in STA
784 * mode when we setup this parameter to high (eg. 5).
785 * Often we see that FW don't send NULL (with clean P flags)
786 * frame even there is info about buffered frames in beacons.
787 * Sometimes we have to wait more than 10 seconds before FW
788 * will wakeup. Often sending one ping from AP to our device
789 * just fail (more than 50%).
791 * Seems setting this FW parameter to 1 couse FW
792 * will check every beacon and will wakup immediately
793 * after detection buffered data.
795 arg->peer_listen_intval = 1;
797 arg->peer_listen_intval = ar->hw->conf.listen_interval;
799 arg->peer_num_spatial_streams = 1;
802 * The assoc capabilities are available only in managed mode.
804 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
805 arg->peer_caps = bss_conf->assoc_capability;
808 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
809 struct ath10k_vif *arvif,
810 struct wmi_peer_assoc_complete_arg *arg)
812 struct ieee80211_vif *vif = arvif->vif;
813 struct ieee80211_bss_conf *info = &vif->bss_conf;
814 struct cfg80211_bss *bss;
815 const u8 *rsnie = NULL;
816 const u8 *wpaie = NULL;
818 lockdep_assert_held(&ar->conf_mutex);
820 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
821 info->bssid, NULL, 0, 0, 0);
823 const struct cfg80211_bss_ies *ies;
826 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
828 ies = rcu_dereference(bss->ies);
830 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
831 WLAN_OUI_TYPE_MICROSOFT_WPA,
835 cfg80211_put_bss(ar->hw->wiphy, bss);
838 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
839 if (rsnie || wpaie) {
840 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
841 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
845 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
846 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
850 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
851 struct ieee80211_sta *sta,
852 struct wmi_peer_assoc_complete_arg *arg)
854 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
855 const struct ieee80211_supported_band *sband;
856 const struct ieee80211_rate *rates;
860 lockdep_assert_held(&ar->conf_mutex);
862 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
863 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
864 rates = sband->bitrates;
866 rateset->num_rates = 0;
868 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
872 rateset->rates[rateset->num_rates] = rates->hw_value;
873 rateset->num_rates++;
877 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
878 struct ieee80211_sta *sta,
879 struct wmi_peer_assoc_complete_arg *arg)
881 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
885 lockdep_assert_held(&ar->conf_mutex);
887 if (!ht_cap->ht_supported)
890 arg->peer_flags |= WMI_PEER_HT;
891 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
892 ht_cap->ampdu_factor)) - 1;
894 arg->peer_mpdu_density =
895 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
897 arg->peer_ht_caps = ht_cap->cap;
898 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
900 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
901 arg->peer_flags |= WMI_PEER_LDPC;
903 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
904 arg->peer_flags |= WMI_PEER_40MHZ;
905 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
908 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
909 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
911 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
912 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
914 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
915 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
916 arg->peer_flags |= WMI_PEER_STBC;
919 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
921 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
922 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
923 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
924 arg->peer_rate_caps |= stbc;
925 arg->peer_flags |= WMI_PEER_STBC;
928 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
929 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
931 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
932 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
933 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
934 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
935 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
936 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
939 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
940 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
941 else if (ht_cap->mcs.rx_mask[1])
942 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
944 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
945 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
946 arg->peer_ht_rates.rates[n++] = i;
948 arg->peer_ht_rates.num_rates = n;
949 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
951 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
953 arg->peer_ht_rates.num_rates,
954 arg->peer_num_spatial_streams);
957 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
958 struct ath10k_vif *arvif,
959 struct ieee80211_sta *sta,
960 struct ieee80211_bss_conf *bss_conf,
961 struct wmi_peer_assoc_complete_arg *arg)
966 lockdep_assert_held(&ar->conf_mutex);
969 arg->peer_flags |= WMI_PEER_QOS;
971 if (sta->wme && sta->uapsd_queues) {
972 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
973 sta->uapsd_queues, sta->max_sp);
975 arg->peer_flags |= WMI_PEER_APSD;
976 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
978 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
979 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
980 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
981 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
982 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
983 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
984 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
985 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
986 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
987 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
988 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
989 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
992 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
993 max_sp = sta->max_sp;
995 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
997 WMI_AP_PS_PEER_PARAM_UAPSD,
1000 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1002 WMI_AP_PS_PEER_PARAM_MAX_SP,
1005 /* TODO setup this based on STA listen interval and
1006 beacon interval. Currently we don't know
1007 sta->listen_interval - mac80211 patch required.
1008 Currently use 10 seconds */
1009 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1011 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1016 static void ath10k_peer_assoc_h_qos_sta(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)
1023 arg->peer_flags |= WMI_PEER_QOS;
1026 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1027 struct ieee80211_sta *sta,
1028 struct wmi_peer_assoc_complete_arg *arg)
1030 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1032 if (!vht_cap->vht_supported)
1035 arg->peer_flags |= WMI_PEER_VHT;
1037 arg->peer_vht_caps = vht_cap->cap;
1039 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1040 arg->peer_flags |= WMI_PEER_80MHZ;
1042 arg->peer_vht_rates.rx_max_rate =
1043 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1044 arg->peer_vht_rates.rx_mcs_set =
1045 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1046 arg->peer_vht_rates.tx_max_rate =
1047 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1048 arg->peer_vht_rates.tx_mcs_set =
1049 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1051 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1052 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1055 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1056 struct ath10k_vif *arvif,
1057 struct ieee80211_sta *sta,
1058 struct ieee80211_bss_conf *bss_conf,
1059 struct wmi_peer_assoc_complete_arg *arg)
1061 switch (arvif->vdev_type) {
1062 case WMI_VDEV_TYPE_AP:
1063 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1065 case WMI_VDEV_TYPE_STA:
1066 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1073 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1074 struct ath10k_vif *arvif,
1075 struct ieee80211_sta *sta,
1076 struct wmi_peer_assoc_complete_arg *arg)
1078 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1080 switch (ar->hw->conf.chandef.chan->band) {
1081 case IEEE80211_BAND_2GHZ:
1082 if (sta->ht_cap.ht_supported) {
1083 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1084 phymode = MODE_11NG_HT40;
1086 phymode = MODE_11NG_HT20;
1092 case IEEE80211_BAND_5GHZ:
1096 if (sta->vht_cap.vht_supported) {
1097 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1098 phymode = MODE_11AC_VHT80;
1099 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1100 phymode = MODE_11AC_VHT40;
1101 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1102 phymode = MODE_11AC_VHT20;
1103 } else if (sta->ht_cap.ht_supported) {
1104 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1105 phymode = MODE_11NA_HT40;
1107 phymode = MODE_11NA_HT20;
1117 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1118 sta->addr, ath10k_wmi_phymode_str(phymode));
1120 arg->peer_phymode = phymode;
1121 WARN_ON(phymode == MODE_UNKNOWN);
1124 static int ath10k_peer_assoc(struct ath10k *ar,
1125 struct ath10k_vif *arvif,
1126 struct ieee80211_sta *sta,
1127 struct ieee80211_bss_conf *bss_conf)
1129 struct wmi_peer_assoc_complete_arg arg;
1131 lockdep_assert_held(&ar->conf_mutex);
1133 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1135 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1136 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1137 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1138 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1139 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1140 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1141 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1143 return ath10k_wmi_peer_assoc(ar, &arg);
1146 /* can be called only in mac80211 callbacks due to `key_count` usage */
1147 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1148 struct ieee80211_vif *vif,
1149 struct ieee80211_bss_conf *bss_conf)
1151 struct ath10k *ar = hw->priv;
1152 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1153 struct ieee80211_sta *ap_sta;
1156 lockdep_assert_held(&ar->conf_mutex);
1160 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1162 ath10k_warn("Failed to find station entry for %pM\n",
1168 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1170 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1177 ath10k_dbg(ATH10K_DBG_MAC,
1178 "mac vdev %d up (associated) bssid %pM aid %d\n",
1179 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1181 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1184 ath10k_warn("VDEV: %d up failed: ret %d\n",
1185 arvif->vdev_id, ret);
1191 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1192 struct ieee80211_vif *vif)
1194 struct ath10k *ar = hw->priv;
1195 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1198 lockdep_assert_held(&ar->conf_mutex);
1201 * For some reason, calling VDEV-DOWN before VDEV-STOP
1202 * makes the FW to send frames via HTT after disassociation.
1203 * No idea why this happens, even though VDEV-DOWN is supposed
1204 * to be analogous to link down, so just stop the VDEV.
1206 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1209 /* FIXME: check return value */
1210 ret = ath10k_vdev_stop(arvif);
1213 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1214 * report beacons from previously associated network through HTT.
1215 * This in turn would spam mac80211 WARN_ON if we bring down all
1216 * interfaces as it expects there is no rx when no interface is
1219 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1221 /* FIXME: why don't we print error if wmi call fails? */
1222 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1224 arvif->def_wep_key_index = 0;
1227 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1228 struct ieee80211_sta *sta)
1232 lockdep_assert_held(&ar->conf_mutex);
1234 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1236 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1240 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1242 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1249 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1250 struct ieee80211_sta *sta)
1254 lockdep_assert_held(&ar->conf_mutex);
1256 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1258 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1269 static int ath10k_update_channel_list(struct ath10k *ar)
1271 struct ieee80211_hw *hw = ar->hw;
1272 struct ieee80211_supported_band **bands;
1273 enum ieee80211_band band;
1274 struct ieee80211_channel *channel;
1275 struct wmi_scan_chan_list_arg arg = {0};
1276 struct wmi_channel_arg *ch;
1282 lockdep_assert_held(&ar->conf_mutex);
1284 bands = hw->wiphy->bands;
1285 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1289 for (i = 0; i < bands[band]->n_channels; i++) {
1290 if (bands[band]->channels[i].flags &
1291 IEEE80211_CHAN_DISABLED)
1298 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1299 arg.channels = kzalloc(len, GFP_KERNEL);
1304 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1308 for (i = 0; i < bands[band]->n_channels; i++) {
1309 channel = &bands[band]->channels[i];
1311 if (channel->flags & IEEE80211_CHAN_DISABLED)
1314 ch->allow_ht = true;
1316 /* FIXME: when should we really allow VHT? */
1317 ch->allow_vht = true;
1320 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1323 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1325 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1326 ch->passive = passive;
1328 ch->freq = channel->center_freq;
1329 ch->min_power = channel->max_power * 3;
1330 ch->max_power = channel->max_power * 4;
1331 ch->max_reg_power = channel->max_reg_power * 4;
1332 ch->max_antenna_gain = channel->max_antenna_gain;
1333 ch->reg_class_id = 0; /* FIXME */
1335 /* FIXME: why use only legacy modes, why not any
1336 * HT/VHT modes? Would that even make any
1338 if (channel->band == IEEE80211_BAND_2GHZ)
1339 ch->mode = MODE_11G;
1341 ch->mode = MODE_11A;
1343 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1346 ath10k_dbg(ATH10K_DBG_WMI,
1347 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1348 ch - arg.channels, arg.n_channels,
1349 ch->freq, ch->max_power, ch->max_reg_power,
1350 ch->max_antenna_gain, ch->mode);
1356 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1357 kfree(arg.channels);
1362 static void ath10k_regd_update(struct ath10k *ar)
1364 struct reg_dmn_pair_mapping *regpair;
1367 lockdep_assert_held(&ar->conf_mutex);
1369 ret = ath10k_update_channel_list(ar);
1371 ath10k_warn("could not update channel list (%d)\n", ret);
1373 regpair = ar->ath_common.regulatory.regpair;
1375 /* Target allows setting up per-band regdomain but ath_common provides
1376 * a combined one only */
1377 ret = ath10k_wmi_pdev_set_regdomain(ar,
1378 regpair->regDmnEnum,
1379 regpair->regDmnEnum, /* 2ghz */
1380 regpair->regDmnEnum, /* 5ghz */
1381 regpair->reg_2ghz_ctl,
1382 regpair->reg_5ghz_ctl);
1384 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1387 static void ath10k_reg_notifier(struct wiphy *wiphy,
1388 struct regulatory_request *request)
1390 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1391 struct ath10k *ar = hw->priv;
1393 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1395 mutex_lock(&ar->conf_mutex);
1396 if (ar->state == ATH10K_STATE_ON)
1397 ath10k_regd_update(ar);
1398 mutex_unlock(&ar->conf_mutex);
1406 * Frames sent to the FW have to be in "Native Wifi" format.
1407 * Strip the QoS field from the 802.11 header.
1409 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1410 struct ieee80211_tx_control *control,
1411 struct sk_buff *skb)
1413 struct ieee80211_hdr *hdr = (void *)skb->data;
1416 if (!ieee80211_is_data_qos(hdr->frame_control))
1419 qos_ctl = ieee80211_get_qos_ctl(hdr);
1420 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1421 skb->data, (void *)qos_ctl - (void *)skb->data);
1422 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1425 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1427 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1428 struct ieee80211_vif *vif = info->control.vif;
1429 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1430 struct ath10k *ar = arvif->ar;
1431 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1432 struct ieee80211_key_conf *key = info->control.hw_key;
1435 if (!ieee80211_has_protected(hdr->frame_control))
1441 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1442 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1445 if (key->keyidx == arvif->def_wep_key_index)
1448 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d keyidx %d\n",
1449 arvif->vdev_id, key->keyidx);
1451 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1452 WMI_VDEV_PARAM_DEF_KEYID,
1455 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1459 arvif->def_wep_key_index = key->keyidx;
1462 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1464 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1465 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1466 struct ieee80211_vif *vif = info->control.vif;
1467 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1469 /* This is case only for P2P_GO */
1470 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1471 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1474 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1475 spin_lock_bh(&ar->data_lock);
1476 if (arvif->u.ap.noa_data)
1477 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1479 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1480 arvif->u.ap.noa_data,
1481 arvif->u.ap.noa_len);
1482 spin_unlock_bh(&ar->data_lock);
1486 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1488 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1491 if (ar->htt.target_version_major >= 3) {
1492 /* Since HTT 3.0 there is no separate mgmt tx command */
1493 ret = ath10k_htt_tx(&ar->htt, skb);
1497 if (ieee80211_is_mgmt(hdr->frame_control))
1498 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1499 else if (ieee80211_is_nullfunc(hdr->frame_control))
1500 /* FW does not report tx status properly for NullFunc frames
1501 * unless they are sent through mgmt tx path. mac80211 sends
1502 * those frames when it detects link/beacon loss and depends on
1503 * the tx status to be correct. */
1504 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1506 ret = ath10k_htt_tx(&ar->htt, skb);
1510 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1511 ieee80211_free_txskb(ar->hw, skb);
1515 void ath10k_offchan_tx_purge(struct ath10k *ar)
1517 struct sk_buff *skb;
1520 skb = skb_dequeue(&ar->offchan_tx_queue);
1524 ieee80211_free_txskb(ar->hw, skb);
1528 void ath10k_offchan_tx_work(struct work_struct *work)
1530 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1531 struct ath10k_peer *peer;
1532 struct ieee80211_hdr *hdr;
1533 struct sk_buff *skb;
1534 const u8 *peer_addr;
1538 /* FW requirement: We must create a peer before FW will send out
1539 * an offchannel frame. Otherwise the frame will be stuck and
1540 * never transmitted. We delete the peer upon tx completion.
1541 * It is unlikely that a peer for offchannel tx will already be
1542 * present. However it may be in some rare cases so account for that.
1543 * Otherwise we might remove a legitimate peer and break stuff. */
1546 skb = skb_dequeue(&ar->offchan_tx_queue);
1550 mutex_lock(&ar->conf_mutex);
1552 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
1555 hdr = (struct ieee80211_hdr *)skb->data;
1556 peer_addr = ieee80211_get_DA(hdr);
1557 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1559 spin_lock_bh(&ar->data_lock);
1560 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1561 spin_unlock_bh(&ar->data_lock);
1564 /* FIXME: should this use ath10k_warn()? */
1565 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1566 peer_addr, vdev_id);
1569 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1571 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1572 peer_addr, vdev_id, ret);
1575 spin_lock_bh(&ar->data_lock);
1576 INIT_COMPLETION(ar->offchan_tx_completed);
1577 ar->offchan_tx_skb = skb;
1578 spin_unlock_bh(&ar->data_lock);
1580 ath10k_tx_htt(ar, skb);
1582 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1585 ath10k_warn("timed out waiting for offchannel skb %p\n",
1589 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1591 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1592 peer_addr, vdev_id, ret);
1595 mutex_unlock(&ar->conf_mutex);
1604 * This gets called if we dont get a heart-beat during scan.
1605 * This may indicate the FW has hung and we need to abort the
1606 * scan manually to prevent cancel_hw_scan() from deadlocking
1608 void ath10k_reset_scan(unsigned long ptr)
1610 struct ath10k *ar = (struct ath10k *)ptr;
1612 spin_lock_bh(&ar->data_lock);
1613 if (!ar->scan.in_progress) {
1614 spin_unlock_bh(&ar->data_lock);
1618 ath10k_warn("scan timeout. resetting. fw issue?\n");
1620 if (ar->scan.is_roc)
1621 ieee80211_remain_on_channel_expired(ar->hw);
1623 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1625 ar->scan.in_progress = false;
1626 complete_all(&ar->scan.completed);
1627 spin_unlock_bh(&ar->data_lock);
1630 static int ath10k_abort_scan(struct ath10k *ar)
1632 struct wmi_stop_scan_arg arg = {
1633 .req_id = 1, /* FIXME */
1634 .req_type = WMI_SCAN_STOP_ONE,
1635 .u.scan_id = ATH10K_SCAN_ID,
1639 lockdep_assert_held(&ar->conf_mutex);
1641 del_timer_sync(&ar->scan.timeout);
1643 spin_lock_bh(&ar->data_lock);
1644 if (!ar->scan.in_progress) {
1645 spin_unlock_bh(&ar->data_lock);
1649 ar->scan.aborting = true;
1650 spin_unlock_bh(&ar->data_lock);
1652 ret = ath10k_wmi_stop_scan(ar, &arg);
1654 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1655 spin_lock_bh(&ar->data_lock);
1656 ar->scan.in_progress = false;
1657 ath10k_offchan_tx_purge(ar);
1658 spin_unlock_bh(&ar->data_lock);
1662 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1664 ath10k_warn("timed out while waiting for scan to stop\n");
1666 /* scan completion may be done right after we timeout here, so let's
1667 * check the in_progress and tell mac80211 scan is completed. if we
1668 * don't do that and FW fails to send us scan completion indication
1669 * then userspace won't be able to scan anymore */
1672 spin_lock_bh(&ar->data_lock);
1673 if (ar->scan.in_progress) {
1674 ath10k_warn("could not stop scan. its still in progress\n");
1675 ar->scan.in_progress = false;
1676 ath10k_offchan_tx_purge(ar);
1679 spin_unlock_bh(&ar->data_lock);
1684 static int ath10k_start_scan(struct ath10k *ar,
1685 const struct wmi_start_scan_arg *arg)
1689 lockdep_assert_held(&ar->conf_mutex);
1691 ret = ath10k_wmi_start_scan(ar, arg);
1695 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1697 ath10k_abort_scan(ar);
1701 /* the scan can complete earlier, before we even
1702 * start the timer. in that case the timer handler
1703 * checks ar->scan.in_progress and bails out if its
1704 * false. Add a 200ms margin to account event/command
1706 mod_timer(&ar->scan.timeout, jiffies +
1707 msecs_to_jiffies(arg->max_scan_time+200));
1711 /**********************/
1712 /* mac80211 callbacks */
1713 /**********************/
1715 static void ath10k_tx(struct ieee80211_hw *hw,
1716 struct ieee80211_tx_control *control,
1717 struct sk_buff *skb)
1719 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1720 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1721 struct ath10k *ar = hw->priv;
1722 struct ath10k_vif *arvif = NULL;
1726 if (info->control.vif) {
1727 arvif = ath10k_vif_to_arvif(info->control.vif);
1728 vdev_id = arvif->vdev_id;
1729 } else if (ar->monitor_enabled) {
1730 vdev_id = ar->monitor_vdev_id;
1733 /* We should disable CCK RATE due to P2P */
1734 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1735 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1737 /* we must calculate tid before we apply qos workaround
1738 * as we'd lose the qos control field */
1739 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1740 if (ieee80211_is_mgmt(hdr->frame_control)) {
1741 tid = HTT_DATA_TX_EXT_TID_MGMT;
1742 } else if (ieee80211_is_data_qos(hdr->frame_control) &&
1743 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1744 u8 *qc = ieee80211_get_qos_ctl(hdr);
1745 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1748 /* it makes no sense to process injected frames like that */
1749 if (info->control.vif &&
1750 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1751 ath10k_tx_h_qos_workaround(hw, control, skb);
1752 ath10k_tx_h_update_wep_key(skb);
1753 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1754 ath10k_tx_h_seq_no(skb);
1757 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
1758 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1759 ATH10K_SKB_CB(skb)->htt.tid = tid;
1761 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1762 spin_lock_bh(&ar->data_lock);
1763 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1764 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1765 spin_unlock_bh(&ar->data_lock);
1767 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1769 skb_queue_tail(&ar->offchan_tx_queue, skb);
1770 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1774 ath10k_tx_htt(ar, skb);
1778 * Initialize various parameters with default vaules.
1780 void ath10k_halt(struct ath10k *ar)
1782 lockdep_assert_held(&ar->conf_mutex);
1784 del_timer_sync(&ar->scan.timeout);
1785 ath10k_offchan_tx_purge(ar);
1786 ath10k_peer_cleanup_all(ar);
1787 ath10k_core_stop(ar);
1788 ath10k_hif_power_down(ar);
1790 spin_lock_bh(&ar->data_lock);
1791 if (ar->scan.in_progress) {
1792 del_timer(&ar->scan.timeout);
1793 ar->scan.in_progress = false;
1794 ieee80211_scan_completed(ar->hw, true);
1796 spin_unlock_bh(&ar->data_lock);
1799 static int ath10k_start(struct ieee80211_hw *hw)
1801 struct ath10k *ar = hw->priv;
1804 mutex_lock(&ar->conf_mutex);
1806 if (ar->state != ATH10K_STATE_OFF &&
1807 ar->state != ATH10K_STATE_RESTARTING) {
1812 ret = ath10k_hif_power_up(ar);
1814 ath10k_err("could not init hif (%d)\n", ret);
1815 ar->state = ATH10K_STATE_OFF;
1819 ret = ath10k_core_start(ar);
1821 ath10k_err("could not init core (%d)\n", ret);
1822 ath10k_hif_power_down(ar);
1823 ar->state = ATH10K_STATE_OFF;
1827 if (ar->state == ATH10K_STATE_OFF)
1828 ar->state = ATH10K_STATE_ON;
1829 else if (ar->state == ATH10K_STATE_RESTARTING)
1830 ar->state = ATH10K_STATE_RESTARTED;
1832 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1834 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1837 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1839 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1842 ath10k_regd_update(ar);
1845 mutex_unlock(&ar->conf_mutex);
1849 static void ath10k_stop(struct ieee80211_hw *hw)
1851 struct ath10k *ar = hw->priv;
1853 mutex_lock(&ar->conf_mutex);
1854 if (ar->state == ATH10K_STATE_ON ||
1855 ar->state == ATH10K_STATE_RESTARTED ||
1856 ar->state == ATH10K_STATE_WEDGED)
1859 ar->state = ATH10K_STATE_OFF;
1860 mutex_unlock(&ar->conf_mutex);
1862 cancel_work_sync(&ar->offchan_tx_work);
1863 cancel_work_sync(&ar->restart_work);
1866 static void ath10k_config_ps(struct ath10k *ar)
1868 struct ath10k_generic_iter ar_iter;
1870 lockdep_assert_held(&ar->conf_mutex);
1872 /* During HW reconfiguration mac80211 reports all interfaces that were
1873 * running until reconfiguration was started. Since FW doesn't have any
1874 * vdevs at this point we must not iterate over this interface list.
1875 * This setting will be updated upon add_interface(). */
1876 if (ar->state == ATH10K_STATE_RESTARTED)
1879 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1882 ieee80211_iterate_active_interfaces_atomic(
1883 ar->hw, IEEE80211_IFACE_ITER_NORMAL,
1884 ath10k_ps_iter, &ar_iter);
1887 ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
1890 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1892 struct ath10k *ar = hw->priv;
1893 struct ieee80211_conf *conf = &hw->conf;
1896 mutex_lock(&ar->conf_mutex);
1898 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1899 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
1900 conf->chandef.chan->center_freq);
1901 spin_lock_bh(&ar->data_lock);
1902 ar->rx_channel = conf->chandef.chan;
1903 spin_unlock_bh(&ar->data_lock);
1906 if (changed & IEEE80211_CONF_CHANGE_PS)
1907 ath10k_config_ps(ar);
1909 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1910 if (conf->flags & IEEE80211_CONF_MONITOR)
1911 ret = ath10k_monitor_create(ar);
1913 ret = ath10k_monitor_destroy(ar);
1916 mutex_unlock(&ar->conf_mutex);
1922 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1923 * because we will send mgmt frames without CCK. This requirement
1924 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1927 static int ath10k_add_interface(struct ieee80211_hw *hw,
1928 struct ieee80211_vif *vif)
1930 struct ath10k *ar = hw->priv;
1931 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1932 enum wmi_sta_powersave_param param;
1937 mutex_lock(&ar->conf_mutex);
1939 memset(arvif, 0, sizeof(*arvif));
1944 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1945 ath10k_warn("Only one monitor interface allowed\n");
1950 bit = ffs(ar->free_vdev_map);
1956 arvif->vdev_id = bit - 1;
1957 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1958 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1961 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1963 switch (vif->type) {
1964 case NL80211_IFTYPE_UNSPECIFIED:
1965 case NL80211_IFTYPE_STATION:
1966 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1968 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1970 case NL80211_IFTYPE_ADHOC:
1971 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1973 case NL80211_IFTYPE_AP:
1974 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1977 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1979 case NL80211_IFTYPE_MONITOR:
1980 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1987 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
1988 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1990 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1991 arvif->vdev_subtype, vif->addr);
1993 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1997 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
1998 arvif->def_wep_key_index);
2000 ath10k_warn("Failed to set default keyid: %d\n", ret);
2002 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2003 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
2004 ATH10K_HW_TXRX_NATIVE_WIFI);
2006 ath10k_warn("Failed to set TX encap: %d\n", ret);
2008 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2009 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2011 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2016 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2017 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2018 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2019 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2022 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2024 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2025 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2026 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2029 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2031 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2032 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2033 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2036 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2039 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2041 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2042 arvif->vdev_id, ret);
2044 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2046 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2047 arvif->vdev_id, ret);
2049 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2050 ar->monitor_present = true;
2053 mutex_unlock(&ar->conf_mutex);
2057 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2058 struct ieee80211_vif *vif)
2060 struct ath10k *ar = hw->priv;
2061 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2064 mutex_lock(&ar->conf_mutex);
2066 spin_lock_bh(&ar->data_lock);
2067 if (arvif->beacon) {
2068 dev_kfree_skb_any(arvif->beacon);
2069 arvif->beacon = NULL;
2071 spin_unlock_bh(&ar->data_lock);
2073 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2075 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2076 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2078 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2080 kfree(arvif->u.ap.noa_data);
2083 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2086 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2088 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2090 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2091 ar->monitor_present = false;
2093 ath10k_peer_cleanup(ar, arvif->vdev_id);
2095 mutex_unlock(&ar->conf_mutex);
2099 * FIXME: Has to be verified.
2101 #define SUPPORTED_FILTERS \
2102 (FIF_PROMISC_IN_BSS | \
2107 FIF_BCN_PRBRESP_PROMISC | \
2111 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2112 unsigned int changed_flags,
2113 unsigned int *total_flags,
2116 struct ath10k *ar = hw->priv;
2119 mutex_lock(&ar->conf_mutex);
2121 changed_flags &= SUPPORTED_FILTERS;
2122 *total_flags &= SUPPORTED_FILTERS;
2123 ar->filter_flags = *total_flags;
2125 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2126 !ar->monitor_enabled) {
2127 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2128 ar->monitor_vdev_id);
2130 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2132 ath10k_warn("Unable to start monitor mode\n");
2133 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2134 ar->monitor_enabled) {
2135 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2136 ar->monitor_vdev_id);
2138 ret = ath10k_monitor_stop(ar);
2140 ath10k_warn("Unable to stop monitor mode\n");
2143 mutex_unlock(&ar->conf_mutex);
2146 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2147 struct ieee80211_vif *vif,
2148 struct ieee80211_bss_conf *info,
2151 struct ath10k *ar = hw->priv;
2152 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2155 mutex_lock(&ar->conf_mutex);
2157 if (changed & BSS_CHANGED_IBSS)
2158 ath10k_control_ibss(arvif, info, vif->addr);
2160 if (changed & BSS_CHANGED_BEACON_INT) {
2161 arvif->beacon_interval = info->beacon_int;
2162 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2163 WMI_VDEV_PARAM_BEACON_INTERVAL,
2164 arvif->beacon_interval);
2165 ath10k_dbg(ATH10K_DBG_MAC,
2166 "mac vdev %d beacon_interval %d\n",
2167 arvif->vdev_id, arvif->beacon_interval);
2170 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2174 if (changed & BSS_CHANGED_BEACON) {
2175 ath10k_dbg(ATH10K_DBG_MAC,
2176 "vdev %d set beacon tx mode to staggered\n",
2179 ret = ath10k_wmi_pdev_set_param(ar,
2180 WMI_PDEV_PARAM_BEACON_TX_MODE,
2181 WMI_BEACON_STAGGERED_MODE);
2183 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2187 if (changed & BSS_CHANGED_BEACON_INFO) {
2188 arvif->dtim_period = info->dtim_period;
2190 ath10k_dbg(ATH10K_DBG_MAC,
2191 "mac vdev %d dtim_period %d\n",
2192 arvif->vdev_id, arvif->dtim_period);
2194 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2195 WMI_VDEV_PARAM_DTIM_PERIOD,
2196 arvif->dtim_period);
2198 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2202 if (changed & BSS_CHANGED_SSID &&
2203 vif->type == NL80211_IFTYPE_AP) {
2204 arvif->u.ap.ssid_len = info->ssid_len;
2206 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2207 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2210 if (changed & BSS_CHANGED_BSSID) {
2211 if (!is_zero_ether_addr(info->bssid)) {
2212 ath10k_dbg(ATH10K_DBG_MAC,
2213 "mac vdev %d create peer %pM\n",
2214 arvif->vdev_id, info->bssid);
2216 ret = ath10k_peer_create(ar, arvif->vdev_id,
2219 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2220 info->bssid, arvif->vdev_id);
2222 if (vif->type == NL80211_IFTYPE_STATION) {
2224 * this is never erased as we it for crypto key
2225 * clearing; this is FW requirement
2227 memcpy(arvif->u.sta.bssid, info->bssid,
2230 ath10k_dbg(ATH10K_DBG_MAC,
2231 "mac vdev %d start %pM\n",
2232 arvif->vdev_id, info->bssid);
2234 /* FIXME: check return value */
2235 ret = ath10k_vdev_start(arvif);
2239 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2240 * so driver need to store it. It is needed when leaving
2241 * IBSS in order to remove BSSID peer.
2243 if (vif->type == NL80211_IFTYPE_ADHOC)
2244 memcpy(arvif->u.ibss.bssid, info->bssid,
2249 if (changed & BSS_CHANGED_BEACON_ENABLED)
2250 ath10k_control_beaconing(arvif, info);
2252 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2254 if (info->use_cts_prot)
2259 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2260 arvif->vdev_id, cts_prot);
2262 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2263 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2266 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2270 if (changed & BSS_CHANGED_ERP_SLOT) {
2272 if (info->use_short_slot)
2273 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2276 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2278 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2279 arvif->vdev_id, slottime);
2281 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2282 WMI_VDEV_PARAM_SLOT_TIME,
2285 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2289 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2291 if (info->use_short_preamble)
2292 preamble = WMI_VDEV_PREAMBLE_SHORT;
2294 preamble = WMI_VDEV_PREAMBLE_LONG;
2296 ath10k_dbg(ATH10K_DBG_MAC,
2297 "mac vdev %d preamble %dn",
2298 arvif->vdev_id, preamble);
2300 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2301 WMI_VDEV_PARAM_PREAMBLE,
2304 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2308 if (changed & BSS_CHANGED_ASSOC) {
2310 ath10k_bss_assoc(hw, vif, info);
2313 mutex_unlock(&ar->conf_mutex);
2316 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2317 struct ieee80211_vif *vif,
2318 struct cfg80211_scan_request *req)
2320 struct ath10k *ar = hw->priv;
2321 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2322 struct wmi_start_scan_arg arg;
2326 mutex_lock(&ar->conf_mutex);
2328 spin_lock_bh(&ar->data_lock);
2329 if (ar->scan.in_progress) {
2330 spin_unlock_bh(&ar->data_lock);
2335 INIT_COMPLETION(ar->scan.started);
2336 INIT_COMPLETION(ar->scan.completed);
2337 ar->scan.in_progress = true;
2338 ar->scan.aborting = false;
2339 ar->scan.is_roc = false;
2340 ar->scan.vdev_id = arvif->vdev_id;
2341 spin_unlock_bh(&ar->data_lock);
2343 memset(&arg, 0, sizeof(arg));
2344 ath10k_wmi_start_scan_init(ar, &arg);
2345 arg.vdev_id = arvif->vdev_id;
2346 arg.scan_id = ATH10K_SCAN_ID;
2349 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2352 arg.ie_len = req->ie_len;
2353 memcpy(arg.ie, req->ie, arg.ie_len);
2357 arg.n_ssids = req->n_ssids;
2358 for (i = 0; i < arg.n_ssids; i++) {
2359 arg.ssids[i].len = req->ssids[i].ssid_len;
2360 arg.ssids[i].ssid = req->ssids[i].ssid;
2363 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2366 if (req->n_channels) {
2367 arg.n_channels = req->n_channels;
2368 for (i = 0; i < arg.n_channels; i++)
2369 arg.channels[i] = req->channels[i]->center_freq;
2372 ret = ath10k_start_scan(ar, &arg);
2374 ath10k_warn("could not start hw scan (%d)\n", ret);
2375 spin_lock_bh(&ar->data_lock);
2376 ar->scan.in_progress = false;
2377 spin_unlock_bh(&ar->data_lock);
2381 mutex_unlock(&ar->conf_mutex);
2385 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2386 struct ieee80211_vif *vif)
2388 struct ath10k *ar = hw->priv;
2391 mutex_lock(&ar->conf_mutex);
2392 ret = ath10k_abort_scan(ar);
2394 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2396 ieee80211_scan_completed(hw, 1 /* aborted */);
2398 mutex_unlock(&ar->conf_mutex);
2401 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2402 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2403 struct ieee80211_key_conf *key)
2405 struct ath10k *ar = hw->priv;
2406 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2407 struct ath10k_peer *peer;
2408 const u8 *peer_addr;
2409 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2410 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2413 if (key->keyidx > WMI_MAX_KEY_INDEX)
2416 mutex_lock(&ar->conf_mutex);
2419 peer_addr = sta->addr;
2420 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2421 peer_addr = vif->bss_conf.bssid;
2423 peer_addr = vif->addr;
2425 key->hw_key_idx = key->keyidx;
2427 /* the peer should not disappear in mid-way (unless FW goes awry) since
2428 * we already hold conf_mutex. we just make sure its there now. */
2429 spin_lock_bh(&ar->data_lock);
2430 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2431 spin_unlock_bh(&ar->data_lock);
2434 if (cmd == SET_KEY) {
2435 ath10k_warn("cannot install key for non-existent peer %pM\n",
2440 /* if the peer doesn't exist there is no key to disable
2448 arvif->wep_keys[key->keyidx] = key;
2450 arvif->wep_keys[key->keyidx] = NULL;
2452 if (cmd == DISABLE_KEY)
2453 ath10k_clear_vdev_key(arvif, key);
2456 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2458 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2462 spin_lock_bh(&ar->data_lock);
2463 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2464 if (peer && cmd == SET_KEY)
2465 peer->keys[key->keyidx] = key;
2466 else if (peer && cmd == DISABLE_KEY)
2467 peer->keys[key->keyidx] = NULL;
2468 else if (peer == NULL)
2469 /* impossible unless FW goes crazy */
2470 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2471 spin_unlock_bh(&ar->data_lock);
2474 mutex_unlock(&ar->conf_mutex);
2478 static int ath10k_sta_state(struct ieee80211_hw *hw,
2479 struct ieee80211_vif *vif,
2480 struct ieee80211_sta *sta,
2481 enum ieee80211_sta_state old_state,
2482 enum ieee80211_sta_state new_state)
2484 struct ath10k *ar = hw->priv;
2485 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2488 mutex_lock(&ar->conf_mutex);
2490 if (old_state == IEEE80211_STA_NOTEXIST &&
2491 new_state == IEEE80211_STA_NONE &&
2492 vif->type != NL80211_IFTYPE_STATION) {
2494 * New station addition.
2496 ath10k_dbg(ATH10K_DBG_MAC,
2497 "mac vdev %d peer create %pM (new sta)\n",
2498 arvif->vdev_id, sta->addr);
2500 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2502 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2503 sta->addr, arvif->vdev_id);
2504 } else if ((old_state == IEEE80211_STA_NONE &&
2505 new_state == IEEE80211_STA_NOTEXIST)) {
2507 * Existing station deletion.
2509 ath10k_dbg(ATH10K_DBG_MAC,
2510 "mac vdev %d peer delete %pM (sta gone)\n",
2511 arvif->vdev_id, sta->addr);
2512 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2514 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2515 sta->addr, arvif->vdev_id);
2517 if (vif->type == NL80211_IFTYPE_STATION)
2518 ath10k_bss_disassoc(hw, vif);
2519 } else if (old_state == IEEE80211_STA_AUTH &&
2520 new_state == IEEE80211_STA_ASSOC &&
2521 (vif->type == NL80211_IFTYPE_AP ||
2522 vif->type == NL80211_IFTYPE_ADHOC)) {
2526 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2529 ret = ath10k_station_assoc(ar, arvif, sta);
2531 ath10k_warn("Failed to associate station: %pM\n",
2533 } else if (old_state == IEEE80211_STA_ASSOC &&
2534 new_state == IEEE80211_STA_AUTH &&
2535 (vif->type == NL80211_IFTYPE_AP ||
2536 vif->type == NL80211_IFTYPE_ADHOC)) {
2540 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2543 ret = ath10k_station_disassoc(ar, arvif, sta);
2545 ath10k_warn("Failed to disassociate station: %pM\n",
2549 mutex_unlock(&ar->conf_mutex);
2553 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2554 u16 ac, bool enable)
2556 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2560 lockdep_assert_held(&ar->conf_mutex);
2562 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2566 case IEEE80211_AC_VO:
2567 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2568 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2570 case IEEE80211_AC_VI:
2571 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2572 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2574 case IEEE80211_AC_BE:
2575 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2576 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2578 case IEEE80211_AC_BK:
2579 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2580 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2585 arvif->u.sta.uapsd |= value;
2587 arvif->u.sta.uapsd &= ~value;
2589 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2590 WMI_STA_PS_PARAM_UAPSD,
2591 arvif->u.sta.uapsd);
2593 ath10k_warn("could not set uapsd params %d\n", ret);
2597 if (arvif->u.sta.uapsd)
2598 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2600 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2602 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2603 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2606 ath10k_warn("could not set rx wake param %d\n", ret);
2612 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2613 struct ieee80211_vif *vif, u16 ac,
2614 const struct ieee80211_tx_queue_params *params)
2616 struct ath10k *ar = hw->priv;
2617 struct wmi_wmm_params_arg *p = NULL;
2620 mutex_lock(&ar->conf_mutex);
2623 case IEEE80211_AC_VO:
2624 p = &ar->wmm_params.ac_vo;
2626 case IEEE80211_AC_VI:
2627 p = &ar->wmm_params.ac_vi;
2629 case IEEE80211_AC_BE:
2630 p = &ar->wmm_params.ac_be;
2632 case IEEE80211_AC_BK:
2633 p = &ar->wmm_params.ac_bk;
2642 p->cwmin = params->cw_min;
2643 p->cwmax = params->cw_max;
2644 p->aifs = params->aifs;
2647 * The channel time duration programmed in the HW is in absolute
2648 * microseconds, while mac80211 gives the txop in units of
2651 p->txop = params->txop * 32;
2653 /* FIXME: FW accepts wmm params per hw, not per vif */
2654 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2656 ath10k_warn("could not set wmm params %d\n", ret);
2660 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2662 ath10k_warn("could not set sta uapsd %d\n", ret);
2665 mutex_unlock(&ar->conf_mutex);
2669 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2671 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2672 struct ieee80211_vif *vif,
2673 struct ieee80211_channel *chan,
2675 enum ieee80211_roc_type type)
2677 struct ath10k *ar = hw->priv;
2678 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2679 struct wmi_start_scan_arg arg;
2682 mutex_lock(&ar->conf_mutex);
2684 spin_lock_bh(&ar->data_lock);
2685 if (ar->scan.in_progress) {
2686 spin_unlock_bh(&ar->data_lock);
2691 INIT_COMPLETION(ar->scan.started);
2692 INIT_COMPLETION(ar->scan.completed);
2693 INIT_COMPLETION(ar->scan.on_channel);
2694 ar->scan.in_progress = true;
2695 ar->scan.aborting = false;
2696 ar->scan.is_roc = true;
2697 ar->scan.vdev_id = arvif->vdev_id;
2698 ar->scan.roc_freq = chan->center_freq;
2699 spin_unlock_bh(&ar->data_lock);
2701 memset(&arg, 0, sizeof(arg));
2702 ath10k_wmi_start_scan_init(ar, &arg);
2703 arg.vdev_id = arvif->vdev_id;
2704 arg.scan_id = ATH10K_SCAN_ID;
2706 arg.channels[0] = chan->center_freq;
2707 arg.dwell_time_active = duration;
2708 arg.dwell_time_passive = duration;
2709 arg.max_scan_time = 2 * duration;
2710 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2711 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2713 ret = ath10k_start_scan(ar, &arg);
2715 ath10k_warn("could not start roc scan (%d)\n", ret);
2716 spin_lock_bh(&ar->data_lock);
2717 ar->scan.in_progress = false;
2718 spin_unlock_bh(&ar->data_lock);
2722 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2724 ath10k_warn("could not switch to channel for roc scan\n");
2725 ath10k_abort_scan(ar);
2732 mutex_unlock(&ar->conf_mutex);
2736 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2738 struct ath10k *ar = hw->priv;
2740 mutex_lock(&ar->conf_mutex);
2741 ath10k_abort_scan(ar);
2742 mutex_unlock(&ar->conf_mutex);
2748 * Both RTS and Fragmentation threshold are interface-specific
2749 * in ath10k, but device-specific in mac80211.
2751 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2753 struct ath10k_generic_iter *ar_iter = data;
2754 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2755 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2757 lockdep_assert_held(&arvif->ar->conf_mutex);
2759 /* During HW reconfiguration mac80211 reports all interfaces that were
2760 * running until reconfiguration was started. Since FW doesn't have any
2761 * vdevs at this point we must not iterate over this interface list.
2762 * This setting will be updated upon add_interface(). */
2763 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2766 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
2767 arvif->vdev_id, rts);
2769 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
2771 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2775 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2777 struct ath10k_generic_iter ar_iter;
2778 struct ath10k *ar = hw->priv;
2780 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2783 mutex_lock(&ar->conf_mutex);
2784 ieee80211_iterate_active_interfaces_atomic(
2785 hw, IEEE80211_IFACE_ITER_NORMAL,
2786 ath10k_set_rts_iter, &ar_iter);
2787 mutex_unlock(&ar->conf_mutex);
2792 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2794 struct ath10k_generic_iter *ar_iter = data;
2795 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2796 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2798 lockdep_assert_held(&arvif->ar->conf_mutex);
2800 /* During HW reconfiguration mac80211 reports all interfaces that were
2801 * running until reconfiguration was started. Since FW doesn't have any
2802 * vdevs at this point we must not iterate over this interface list.
2803 * This setting will be updated upon add_interface(). */
2804 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2807 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
2808 arvif->vdev_id, frag);
2810 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
2812 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2816 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2818 struct ath10k_generic_iter ar_iter;
2819 struct ath10k *ar = hw->priv;
2821 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2824 mutex_lock(&ar->conf_mutex);
2825 ieee80211_iterate_active_interfaces_atomic(
2826 hw, IEEE80211_IFACE_ITER_NORMAL,
2827 ath10k_set_frag_iter, &ar_iter);
2828 mutex_unlock(&ar->conf_mutex);
2833 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2835 struct ath10k *ar = hw->priv;
2839 /* mac80211 doesn't care if we really xmit queued frames or not
2840 * we'll collect those frames either way if we stop/delete vdevs */
2844 mutex_lock(&ar->conf_mutex);
2846 if (ar->state == ATH10K_STATE_WEDGED)
2849 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
2852 spin_lock_bh(&ar->htt.tx_lock);
2853 empty = (ar->htt.num_pending_tx == 0);
2854 spin_unlock_bh(&ar->htt.tx_lock);
2856 skip = (ar->state == ATH10K_STATE_WEDGED);
2859 }), ATH10K_FLUSH_TIMEOUT_HZ);
2861 if (ret <= 0 || skip)
2862 ath10k_warn("tx not flushed\n");
2865 mutex_unlock(&ar->conf_mutex);
2868 /* TODO: Implement this function properly
2869 * For now it is needed to reply to Probe Requests in IBSS mode.
2870 * Propably we need this information from FW.
2872 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2878 static int ath10k_suspend(struct ieee80211_hw *hw,
2879 struct cfg80211_wowlan *wowlan)
2881 struct ath10k *ar = hw->priv;
2884 ar->is_target_paused = false;
2886 ret = ath10k_wmi_pdev_suspend_target(ar);
2888 ath10k_warn("could not suspend target (%d)\n", ret);
2892 ret = wait_event_interruptible_timeout(ar->event_queue,
2893 ar->is_target_paused == true,
2896 ath10k_warn("suspend interrupted (%d)\n", ret);
2898 } else if (ret == 0) {
2899 ath10k_warn("suspend timed out - target pause event never came\n");
2903 ret = ath10k_hif_suspend(ar);
2905 ath10k_warn("could not suspend hif (%d)\n", ret);
2911 ret = ath10k_wmi_pdev_resume_target(ar);
2913 ath10k_warn("could not resume target (%d)\n", ret);
2917 static int ath10k_resume(struct ieee80211_hw *hw)
2919 struct ath10k *ar = hw->priv;
2922 ret = ath10k_hif_resume(ar);
2924 ath10k_warn("could not resume hif (%d)\n", ret);
2928 ret = ath10k_wmi_pdev_resume_target(ar);
2930 ath10k_warn("could not resume target (%d)\n", ret);
2938 static void ath10k_restart_complete(struct ieee80211_hw *hw)
2940 struct ath10k *ar = hw->priv;
2942 mutex_lock(&ar->conf_mutex);
2944 /* If device failed to restart it will be in a different state, e.g.
2945 * ATH10K_STATE_WEDGED */
2946 if (ar->state == ATH10K_STATE_RESTARTED) {
2947 ath10k_info("device successfully recovered\n");
2948 ar->state = ATH10K_STATE_ON;
2951 mutex_unlock(&ar->conf_mutex);
2954 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
2955 struct survey_info *survey)
2957 struct ath10k *ar = hw->priv;
2958 struct ieee80211_supported_band *sband;
2959 struct survey_info *ar_survey = &ar->survey[idx];
2962 mutex_lock(&ar->conf_mutex);
2964 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
2965 if (sband && idx >= sband->n_channels) {
2966 idx -= sband->n_channels;
2971 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
2973 if (!sband || idx >= sband->n_channels) {
2978 spin_lock_bh(&ar->data_lock);
2979 memcpy(survey, ar_survey, sizeof(*survey));
2980 spin_unlock_bh(&ar->data_lock);
2982 survey->channel = &sband->channels[idx];
2985 mutex_unlock(&ar->conf_mutex);
2989 static const struct ieee80211_ops ath10k_ops = {
2991 .start = ath10k_start,
2992 .stop = ath10k_stop,
2993 .config = ath10k_config,
2994 .add_interface = ath10k_add_interface,
2995 .remove_interface = ath10k_remove_interface,
2996 .configure_filter = ath10k_configure_filter,
2997 .bss_info_changed = ath10k_bss_info_changed,
2998 .hw_scan = ath10k_hw_scan,
2999 .cancel_hw_scan = ath10k_cancel_hw_scan,
3000 .set_key = ath10k_set_key,
3001 .sta_state = ath10k_sta_state,
3002 .conf_tx = ath10k_conf_tx,
3003 .remain_on_channel = ath10k_remain_on_channel,
3004 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3005 .set_rts_threshold = ath10k_set_rts_threshold,
3006 .set_frag_threshold = ath10k_set_frag_threshold,
3007 .flush = ath10k_flush,
3008 .tx_last_beacon = ath10k_tx_last_beacon,
3009 .restart_complete = ath10k_restart_complete,
3010 .get_survey = ath10k_get_survey,
3012 .suspend = ath10k_suspend,
3013 .resume = ath10k_resume,
3017 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3018 .bitrate = (_rate), \
3019 .flags = (_flags), \
3020 .hw_value = (_rateid), \
3023 #define CHAN2G(_channel, _freq, _flags) { \
3024 .band = IEEE80211_BAND_2GHZ, \
3025 .hw_value = (_channel), \
3026 .center_freq = (_freq), \
3027 .flags = (_flags), \
3028 .max_antenna_gain = 0, \
3032 #define CHAN5G(_channel, _freq, _flags) { \
3033 .band = IEEE80211_BAND_5GHZ, \
3034 .hw_value = (_channel), \
3035 .center_freq = (_freq), \
3036 .flags = (_flags), \
3037 .max_antenna_gain = 0, \
3041 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3051 CHAN2G(10, 2457, 0),
3052 CHAN2G(11, 2462, 0),
3053 CHAN2G(12, 2467, 0),
3054 CHAN2G(13, 2472, 0),
3055 CHAN2G(14, 2484, 0),
3058 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
3059 CHAN5G(36, 5180, 0),
3060 CHAN5G(40, 5200, 0),
3061 CHAN5G(44, 5220, 0),
3062 CHAN5G(48, 5240, 0),
3063 CHAN5G(52, 5260, 0),
3064 CHAN5G(56, 5280, 0),
3065 CHAN5G(60, 5300, 0),
3066 CHAN5G(64, 5320, 0),
3067 CHAN5G(100, 5500, 0),
3068 CHAN5G(104, 5520, 0),
3069 CHAN5G(108, 5540, 0),
3070 CHAN5G(112, 5560, 0),
3071 CHAN5G(116, 5580, 0),
3072 CHAN5G(120, 5600, 0),
3073 CHAN5G(124, 5620, 0),
3074 CHAN5G(128, 5640, 0),
3075 CHAN5G(132, 5660, 0),
3076 CHAN5G(136, 5680, 0),
3077 CHAN5G(140, 5700, 0),
3078 CHAN5G(149, 5745, 0),
3079 CHAN5G(153, 5765, 0),
3080 CHAN5G(157, 5785, 0),
3081 CHAN5G(161, 5805, 0),
3082 CHAN5G(165, 5825, 0),
3085 static struct ieee80211_rate ath10k_rates[] = {
3087 RATETAB_ENT(10, 0x82, 0),
3088 RATETAB_ENT(20, 0x84, 0),
3089 RATETAB_ENT(55, 0x8b, 0),
3090 RATETAB_ENT(110, 0x96, 0),
3092 RATETAB_ENT(60, 0x0c, 0),
3093 RATETAB_ENT(90, 0x12, 0),
3094 RATETAB_ENT(120, 0x18, 0),
3095 RATETAB_ENT(180, 0x24, 0),
3096 RATETAB_ENT(240, 0x30, 0),
3097 RATETAB_ENT(360, 0x48, 0),
3098 RATETAB_ENT(480, 0x60, 0),
3099 RATETAB_ENT(540, 0x6c, 0),
3102 #define ath10k_a_rates (ath10k_rates + 4)
3103 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3104 #define ath10k_g_rates (ath10k_rates + 0)
3105 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3107 struct ath10k *ath10k_mac_create(void)
3109 struct ieee80211_hw *hw;
3112 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3122 void ath10k_mac_destroy(struct ath10k *ar)
3124 ieee80211_free_hw(ar->hw);
3127 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3130 .types = BIT(NL80211_IFTYPE_STATION)
3131 | BIT(NL80211_IFTYPE_P2P_CLIENT)
3135 .types = BIT(NL80211_IFTYPE_P2P_GO)
3139 .types = BIT(NL80211_IFTYPE_AP)
3143 static const struct ieee80211_iface_combination ath10k_if_comb = {
3144 .limits = ath10k_if_limits,
3145 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3146 .max_interfaces = 8,
3147 .num_different_channels = 1,
3148 .beacon_int_infra_match = true,
3151 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3153 struct ieee80211_sta_vht_cap vht_cap = {0};
3157 vht_cap.vht_supported = 1;
3158 vht_cap.cap = ar->vht_cap_info;
3161 for (i = 0; i < 8; i++) {
3162 if (i < ar->num_rf_chains)
3163 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3165 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3168 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3169 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3174 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3177 struct ieee80211_sta_ht_cap ht_cap = {0};
3179 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3182 ht_cap.ht_supported = 1;
3183 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3184 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3185 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3186 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3187 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3189 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3190 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3192 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3193 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3195 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3198 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3199 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3204 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3205 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3207 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3210 stbc = ar->ht_cap_info;
3211 stbc &= WMI_HT_CAP_RX_STBC;
3212 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3213 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3214 stbc &= IEEE80211_HT_CAP_RX_STBC;
3219 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3220 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3222 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3223 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3225 /* max AMSDU is implicitly taken from vht_cap_info */
3226 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3227 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3229 for (i = 0; i < ar->num_rf_chains; i++)
3230 ht_cap.mcs.rx_mask[i] = 0xFF;
3232 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3238 static void ath10k_get_arvif_iter(void *data, u8 *mac,
3239 struct ieee80211_vif *vif)
3241 struct ath10k_vif_iter *arvif_iter = data;
3242 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3244 if (arvif->vdev_id == arvif_iter->vdev_id)
3245 arvif_iter->arvif = arvif;
3248 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3250 struct ath10k_vif_iter arvif_iter;
3253 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3254 arvif_iter.vdev_id = vdev_id;
3256 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3257 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3259 ath10k_get_arvif_iter,
3261 if (!arvif_iter.arvif) {
3262 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3266 return arvif_iter.arvif;
3269 int ath10k_mac_register(struct ath10k *ar)
3271 struct ieee80211_supported_band *band;
3272 struct ieee80211_sta_vht_cap vht_cap;
3273 struct ieee80211_sta_ht_cap ht_cap;
3277 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3279 SET_IEEE80211_DEV(ar->hw, ar->dev);
3281 ht_cap = ath10k_get_ht_cap(ar);
3282 vht_cap = ath10k_create_vht_cap(ar);
3284 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3285 channels = kmemdup(ath10k_2ghz_channels,
3286 sizeof(ath10k_2ghz_channels),
3293 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3294 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3295 band->channels = channels;
3296 band->n_bitrates = ath10k_g_rates_size;
3297 band->bitrates = ath10k_g_rates;
3298 band->ht_cap = ht_cap;
3300 /* vht is not supported in 2.4 GHz */
3302 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3305 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3306 channels = kmemdup(ath10k_5ghz_channels,
3307 sizeof(ath10k_5ghz_channels),
3314 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3315 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3316 band->channels = channels;
3317 band->n_bitrates = ath10k_a_rates_size;
3318 band->bitrates = ath10k_a_rates;
3319 band->ht_cap = ht_cap;
3320 band->vht_cap = vht_cap;
3321 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3324 ar->hw->wiphy->interface_modes =
3325 BIT(NL80211_IFTYPE_STATION) |
3326 BIT(NL80211_IFTYPE_ADHOC) |
3327 BIT(NL80211_IFTYPE_AP) |
3328 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3329 BIT(NL80211_IFTYPE_P2P_GO);
3331 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3332 IEEE80211_HW_SUPPORTS_PS |
3333 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3334 IEEE80211_HW_SUPPORTS_UAPSD |
3335 IEEE80211_HW_MFP_CAPABLE |
3336 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3337 IEEE80211_HW_HAS_RATE_CONTROL |
3338 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3339 IEEE80211_HW_WANT_MONITOR_VIF |
3340 IEEE80211_HW_AP_LINK_PS;
3342 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3343 * bytes is used for padding/alignment if necessary. */
3344 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3346 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3347 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3349 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3350 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3351 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3354 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3355 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3357 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3359 ar->hw->channel_change_time = 5000;
3360 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3362 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3363 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3365 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3367 * on LL hardware queues are managed entirely by the FW
3368 * so we only advertise to mac we can do the queues thing
3372 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3373 ar->hw->wiphy->n_iface_combinations = 1;
3375 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3377 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3378 ath10k_reg_notifier);
3380 ath10k_err("Regulatory initialization failed\n");
3384 ret = ieee80211_register_hw(ar->hw);
3386 ath10k_err("ieee80211 registration failed: %d\n", ret);
3390 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3391 ret = regulatory_hint(ar->hw->wiphy,
3392 ar->ath_common.regulatory.alpha2);
3394 goto err_unregister;
3400 ieee80211_unregister_hw(ar->hw);
3402 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3403 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3408 void ath10k_mac_unregister(struct ath10k *ar)
3410 ieee80211_unregister_hw(ar->hw);
3412 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3413 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3415 SET_IEEE80211_DEV(ar->hw, NULL);