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 struct ath10k *ar = arvif->ar;
340 if (value != 0xFFFFFFFF)
341 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
344 vdev_param = ar->wmi.vdev_param->rts_threshold;
345 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
348 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
350 struct ath10k *ar = arvif->ar;
353 if (value != 0xFFFFFFFF)
354 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
355 ATH10K_FRAGMT_THRESHOLD_MIN,
356 ATH10K_FRAGMT_THRESHOLD_MAX);
358 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
359 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
362 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
366 lockdep_assert_held(&ar->conf_mutex);
368 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
372 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
379 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
381 struct ath10k_peer *peer, *tmp;
383 lockdep_assert_held(&ar->conf_mutex);
385 spin_lock_bh(&ar->data_lock);
386 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
387 if (peer->vdev_id != vdev_id)
390 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
391 peer->addr, vdev_id);
393 list_del(&peer->list);
396 spin_unlock_bh(&ar->data_lock);
399 static void ath10k_peer_cleanup_all(struct ath10k *ar)
401 struct ath10k_peer *peer, *tmp;
403 lockdep_assert_held(&ar->conf_mutex);
405 spin_lock_bh(&ar->data_lock);
406 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
407 list_del(&peer->list);
410 spin_unlock_bh(&ar->data_lock);
413 /************************/
414 /* Interface management */
415 /************************/
417 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
421 lockdep_assert_held(&ar->conf_mutex);
423 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
424 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
431 static int ath10k_vdev_start(struct ath10k_vif *arvif)
433 struct ath10k *ar = arvif->ar;
434 struct ieee80211_conf *conf = &ar->hw->conf;
435 struct ieee80211_channel *channel = conf->chandef.chan;
436 struct wmi_vdev_start_request_arg arg = {};
439 lockdep_assert_held(&ar->conf_mutex);
441 INIT_COMPLETION(ar->vdev_setup_done);
443 arg.vdev_id = arvif->vdev_id;
444 arg.dtim_period = arvif->dtim_period;
445 arg.bcn_intval = arvif->beacon_interval;
447 arg.channel.freq = channel->center_freq;
449 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
451 arg.channel.mode = chan_to_phymode(&conf->chandef);
453 arg.channel.min_power = channel->max_power * 3;
454 arg.channel.max_power = channel->max_power * 4;
455 arg.channel.max_reg_power = channel->max_reg_power * 4;
456 arg.channel.max_antenna_gain = channel->max_antenna_gain;
458 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
459 arg.ssid = arvif->u.ap.ssid;
460 arg.ssid_len = arvif->u.ap.ssid_len;
461 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
462 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
463 arg.ssid = arvif->vif->bss_conf.ssid;
464 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
467 ath10k_dbg(ATH10K_DBG_MAC,
468 "mac vdev %d start center_freq %d phymode %s\n",
469 arg.vdev_id, arg.channel.freq,
470 ath10k_wmi_phymode_str(arg.channel.mode));
472 ret = ath10k_wmi_vdev_start(ar, &arg);
474 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
478 ret = ath10k_vdev_setup_sync(ar);
480 ath10k_warn("vdev setup failed %d\n", ret);
487 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
489 struct ath10k *ar = arvif->ar;
492 lockdep_assert_held(&ar->conf_mutex);
494 INIT_COMPLETION(ar->vdev_setup_done);
496 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
498 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
502 ret = ath10k_vdev_setup_sync(ar);
504 ath10k_warn("vdev setup failed %d\n", ret);
511 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
513 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
514 struct wmi_vdev_start_request_arg arg = {};
517 lockdep_assert_held(&ar->conf_mutex);
519 arg.vdev_id = vdev_id;
520 arg.channel.freq = channel->center_freq;
521 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
523 /* TODO setup this dynamically, what in case we
524 don't have any vifs? */
525 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
527 arg.channel.min_power = channel->max_power * 3;
528 arg.channel.max_power = channel->max_power * 4;
529 arg.channel.max_reg_power = channel->max_reg_power * 4;
530 arg.channel.max_antenna_gain = channel->max_antenna_gain;
532 ret = ath10k_wmi_vdev_start(ar, &arg);
534 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
538 ret = ath10k_vdev_setup_sync(ar);
540 ath10k_warn("Monitor vdev setup failed %d\n", ret);
544 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
546 ath10k_warn("Monitor vdev up failed: %d\n", ret);
550 ar->monitor_vdev_id = vdev_id;
551 ar->monitor_enabled = true;
556 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
558 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
563 static int ath10k_monitor_stop(struct ath10k *ar)
567 lockdep_assert_held(&ar->conf_mutex);
569 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
571 ath10k_warn("Monitor vdev down failed: %d\n", ret);
573 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
575 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
577 ret = ath10k_vdev_setup_sync(ar);
579 ath10k_warn("Monitor_down sync failed: %d\n", ret);
581 ar->monitor_enabled = false;
585 static int ath10k_monitor_create(struct ath10k *ar)
589 lockdep_assert_held(&ar->conf_mutex);
591 if (ar->monitor_present) {
592 ath10k_warn("Monitor mode already enabled\n");
596 bit = ffs(ar->free_vdev_map);
598 ath10k_warn("No free VDEV slots\n");
602 ar->monitor_vdev_id = bit - 1;
603 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
605 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
606 WMI_VDEV_TYPE_MONITOR,
609 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
613 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
614 ar->monitor_vdev_id);
616 ar->monitor_present = true;
621 * Restore the ID to the global map.
623 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
627 static int ath10k_monitor_destroy(struct ath10k *ar)
631 lockdep_assert_held(&ar->conf_mutex);
633 if (!ar->monitor_present)
636 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
638 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
642 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
643 ar->monitor_present = false;
645 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
646 ar->monitor_vdev_id);
650 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
651 struct ieee80211_bss_conf *info)
655 lockdep_assert_held(&arvif->ar->conf_mutex);
657 if (!info->enable_beacon) {
658 ath10k_vdev_stop(arvif);
662 arvif->tx_seq_no = 0x1000;
664 ret = ath10k_vdev_start(arvif);
668 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
670 ath10k_warn("Failed to bring up VDEV: %d\n",
674 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
677 static void ath10k_control_ibss(struct ath10k_vif *arvif,
678 struct ieee80211_bss_conf *info,
679 const u8 self_peer[ETH_ALEN])
684 lockdep_assert_held(&arvif->ar->conf_mutex);
686 if (!info->ibss_joined) {
687 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
689 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
690 self_peer, arvif->vdev_id, ret);
692 if (is_zero_ether_addr(arvif->u.ibss.bssid))
695 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
696 arvif->u.ibss.bssid);
698 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
699 arvif->u.ibss.bssid, arvif->vdev_id, ret);
703 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
708 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
710 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
711 self_peer, arvif->vdev_id, ret);
715 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
716 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
717 ATH10K_DEFAULT_ATIM);
719 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
720 arvif->vdev_id, ret);
724 * Review this when mac80211 gains per-interface powersave support.
726 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
728 struct ath10k_generic_iter *ar_iter = data;
729 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
730 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
731 enum wmi_sta_powersave_param param;
732 enum wmi_sta_ps_mode psmode;
735 lockdep_assert_held(&arvif->ar->conf_mutex);
737 if (vif->type != NL80211_IFTYPE_STATION)
740 if (conf->flags & IEEE80211_CONF_PS) {
741 psmode = WMI_STA_PS_MODE_ENABLED;
742 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
744 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
747 conf->dynamic_ps_timeout);
749 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
756 psmode = WMI_STA_PS_MODE_DISABLED;
759 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
760 arvif->vdev_id, psmode ? "enable" : "disable");
762 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
765 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
766 psmode, arvif->vdev_id);
769 /**********************/
770 /* Station management */
771 /**********************/
773 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
774 struct ath10k_vif *arvif,
775 struct ieee80211_sta *sta,
776 struct ieee80211_bss_conf *bss_conf,
777 struct wmi_peer_assoc_complete_arg *arg)
779 lockdep_assert_held(&ar->conf_mutex);
781 memcpy(arg->addr, sta->addr, ETH_ALEN);
782 arg->vdev_id = arvif->vdev_id;
783 arg->peer_aid = sta->aid;
784 arg->peer_flags |= WMI_PEER_AUTH;
786 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
788 * Seems FW have problems with Power Save in STA
789 * mode when we setup this parameter to high (eg. 5).
790 * Often we see that FW don't send NULL (with clean P flags)
791 * frame even there is info about buffered frames in beacons.
792 * Sometimes we have to wait more than 10 seconds before FW
793 * will wakeup. Often sending one ping from AP to our device
794 * just fail (more than 50%).
796 * Seems setting this FW parameter to 1 couse FW
797 * will check every beacon and will wakup immediately
798 * after detection buffered data.
800 arg->peer_listen_intval = 1;
802 arg->peer_listen_intval = ar->hw->conf.listen_interval;
804 arg->peer_num_spatial_streams = 1;
807 * The assoc capabilities are available only in managed mode.
809 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
810 arg->peer_caps = bss_conf->assoc_capability;
813 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
814 struct ath10k_vif *arvif,
815 struct wmi_peer_assoc_complete_arg *arg)
817 struct ieee80211_vif *vif = arvif->vif;
818 struct ieee80211_bss_conf *info = &vif->bss_conf;
819 struct cfg80211_bss *bss;
820 const u8 *rsnie = NULL;
821 const u8 *wpaie = NULL;
823 lockdep_assert_held(&ar->conf_mutex);
825 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
826 info->bssid, NULL, 0, 0, 0);
828 const struct cfg80211_bss_ies *ies;
831 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
833 ies = rcu_dereference(bss->ies);
835 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
836 WLAN_OUI_TYPE_MICROSOFT_WPA,
840 cfg80211_put_bss(ar->hw->wiphy, bss);
843 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
844 if (rsnie || wpaie) {
845 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
846 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
850 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
851 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
855 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
856 struct ieee80211_sta *sta,
857 struct wmi_peer_assoc_complete_arg *arg)
859 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
860 const struct ieee80211_supported_band *sband;
861 const struct ieee80211_rate *rates;
865 lockdep_assert_held(&ar->conf_mutex);
867 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
868 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
869 rates = sband->bitrates;
871 rateset->num_rates = 0;
873 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
877 rateset->rates[rateset->num_rates] = rates->hw_value;
878 rateset->num_rates++;
882 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
883 struct ieee80211_sta *sta,
884 struct wmi_peer_assoc_complete_arg *arg)
886 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
890 lockdep_assert_held(&ar->conf_mutex);
892 if (!ht_cap->ht_supported)
895 arg->peer_flags |= WMI_PEER_HT;
896 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
897 ht_cap->ampdu_factor)) - 1;
899 arg->peer_mpdu_density =
900 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
902 arg->peer_ht_caps = ht_cap->cap;
903 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
905 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
906 arg->peer_flags |= WMI_PEER_LDPC;
908 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
909 arg->peer_flags |= WMI_PEER_40MHZ;
910 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
913 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
914 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
916 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
917 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
919 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
920 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
921 arg->peer_flags |= WMI_PEER_STBC;
924 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
926 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
927 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
928 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
929 arg->peer_rate_caps |= stbc;
930 arg->peer_flags |= WMI_PEER_STBC;
933 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
934 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
936 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
937 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
938 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
939 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
940 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
941 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
944 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
945 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
946 else if (ht_cap->mcs.rx_mask[1])
947 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
949 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
950 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
951 arg->peer_ht_rates.rates[n++] = i;
953 arg->peer_ht_rates.num_rates = n;
954 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
956 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
958 arg->peer_ht_rates.num_rates,
959 arg->peer_num_spatial_streams);
962 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
963 struct ath10k_vif *arvif,
964 struct ieee80211_sta *sta,
965 struct ieee80211_bss_conf *bss_conf,
966 struct wmi_peer_assoc_complete_arg *arg)
971 lockdep_assert_held(&ar->conf_mutex);
974 arg->peer_flags |= WMI_PEER_QOS;
976 if (sta->wme && sta->uapsd_queues) {
977 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
978 sta->uapsd_queues, sta->max_sp);
980 arg->peer_flags |= WMI_PEER_APSD;
981 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
983 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
984 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
985 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
986 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
987 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
988 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
989 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
990 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
991 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
992 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
993 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
994 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
997 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
998 max_sp = sta->max_sp;
1000 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1002 WMI_AP_PS_PEER_PARAM_UAPSD,
1005 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1007 WMI_AP_PS_PEER_PARAM_MAX_SP,
1010 /* TODO setup this based on STA listen interval and
1011 beacon interval. Currently we don't know
1012 sta->listen_interval - mac80211 patch required.
1013 Currently use 10 seconds */
1014 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1016 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1021 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1022 struct ath10k_vif *arvif,
1023 struct ieee80211_sta *sta,
1024 struct ieee80211_bss_conf *bss_conf,
1025 struct wmi_peer_assoc_complete_arg *arg)
1028 arg->peer_flags |= WMI_PEER_QOS;
1031 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1032 struct ieee80211_sta *sta,
1033 struct wmi_peer_assoc_complete_arg *arg)
1035 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1038 if (!vht_cap->vht_supported)
1041 arg->peer_flags |= WMI_PEER_VHT;
1042 arg->peer_vht_caps = vht_cap->cap;
1045 ampdu_factor = (vht_cap->cap &
1046 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1047 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1049 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1050 * zero in VHT IE. Using it would result in degraded throughput.
1051 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1052 * it if VHT max_mpdu is smaller. */
1053 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1054 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1055 ampdu_factor)) - 1);
1057 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1058 arg->peer_flags |= WMI_PEER_80MHZ;
1060 arg->peer_vht_rates.rx_max_rate =
1061 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1062 arg->peer_vht_rates.rx_mcs_set =
1063 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1064 arg->peer_vht_rates.tx_max_rate =
1065 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1066 arg->peer_vht_rates.tx_mcs_set =
1067 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1069 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1070 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1073 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1074 struct ath10k_vif *arvif,
1075 struct ieee80211_sta *sta,
1076 struct ieee80211_bss_conf *bss_conf,
1077 struct wmi_peer_assoc_complete_arg *arg)
1079 switch (arvif->vdev_type) {
1080 case WMI_VDEV_TYPE_AP:
1081 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1083 case WMI_VDEV_TYPE_STA:
1084 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1091 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1092 struct ath10k_vif *arvif,
1093 struct ieee80211_sta *sta,
1094 struct wmi_peer_assoc_complete_arg *arg)
1096 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1098 switch (ar->hw->conf.chandef.chan->band) {
1099 case IEEE80211_BAND_2GHZ:
1100 if (sta->ht_cap.ht_supported) {
1101 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1102 phymode = MODE_11NG_HT40;
1104 phymode = MODE_11NG_HT20;
1110 case IEEE80211_BAND_5GHZ:
1114 if (sta->vht_cap.vht_supported) {
1115 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1116 phymode = MODE_11AC_VHT80;
1117 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1118 phymode = MODE_11AC_VHT40;
1119 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1120 phymode = MODE_11AC_VHT20;
1121 } else if (sta->ht_cap.ht_supported) {
1122 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1123 phymode = MODE_11NA_HT40;
1125 phymode = MODE_11NA_HT20;
1135 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1136 sta->addr, ath10k_wmi_phymode_str(phymode));
1138 arg->peer_phymode = phymode;
1139 WARN_ON(phymode == MODE_UNKNOWN);
1142 static int ath10k_peer_assoc(struct ath10k *ar,
1143 struct ath10k_vif *arvif,
1144 struct ieee80211_sta *sta,
1145 struct ieee80211_bss_conf *bss_conf)
1147 struct wmi_peer_assoc_complete_arg arg;
1149 lockdep_assert_held(&ar->conf_mutex);
1151 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1153 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1154 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1155 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1156 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1157 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1158 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1159 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1161 return ath10k_wmi_peer_assoc(ar, &arg);
1164 /* can be called only in mac80211 callbacks due to `key_count` usage */
1165 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1166 struct ieee80211_vif *vif,
1167 struct ieee80211_bss_conf *bss_conf)
1169 struct ath10k *ar = hw->priv;
1170 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1171 struct ieee80211_sta *ap_sta;
1174 lockdep_assert_held(&ar->conf_mutex);
1178 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1180 ath10k_warn("Failed to find station entry for %pM\n",
1186 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1188 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1195 ath10k_dbg(ATH10K_DBG_MAC,
1196 "mac vdev %d up (associated) bssid %pM aid %d\n",
1197 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1199 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1202 ath10k_warn("VDEV: %d up failed: ret %d\n",
1203 arvif->vdev_id, ret);
1209 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1210 struct ieee80211_vif *vif)
1212 struct ath10k *ar = hw->priv;
1213 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1216 lockdep_assert_held(&ar->conf_mutex);
1219 * For some reason, calling VDEV-DOWN before VDEV-STOP
1220 * makes the FW to send frames via HTT after disassociation.
1221 * No idea why this happens, even though VDEV-DOWN is supposed
1222 * to be analogous to link down, so just stop the VDEV.
1224 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1227 /* FIXME: check return value */
1228 ret = ath10k_vdev_stop(arvif);
1231 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1232 * report beacons from previously associated network through HTT.
1233 * This in turn would spam mac80211 WARN_ON if we bring down all
1234 * interfaces as it expects there is no rx when no interface is
1237 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1239 /* FIXME: why don't we print error if wmi call fails? */
1240 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1242 arvif->def_wep_key_idx = 0;
1245 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1246 struct ieee80211_sta *sta)
1250 lockdep_assert_held(&ar->conf_mutex);
1252 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1254 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1258 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1260 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1267 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1268 struct ieee80211_sta *sta)
1272 lockdep_assert_held(&ar->conf_mutex);
1274 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1276 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1287 static int ath10k_update_channel_list(struct ath10k *ar)
1289 struct ieee80211_hw *hw = ar->hw;
1290 struct ieee80211_supported_band **bands;
1291 enum ieee80211_band band;
1292 struct ieee80211_channel *channel;
1293 struct wmi_scan_chan_list_arg arg = {0};
1294 struct wmi_channel_arg *ch;
1300 lockdep_assert_held(&ar->conf_mutex);
1302 bands = hw->wiphy->bands;
1303 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1307 for (i = 0; i < bands[band]->n_channels; i++) {
1308 if (bands[band]->channels[i].flags &
1309 IEEE80211_CHAN_DISABLED)
1316 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1317 arg.channels = kzalloc(len, GFP_KERNEL);
1322 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1326 for (i = 0; i < bands[band]->n_channels; i++) {
1327 channel = &bands[band]->channels[i];
1329 if (channel->flags & IEEE80211_CHAN_DISABLED)
1332 ch->allow_ht = true;
1334 /* FIXME: when should we really allow VHT? */
1335 ch->allow_vht = true;
1338 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1341 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1343 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1344 ch->passive = passive;
1346 ch->freq = channel->center_freq;
1347 ch->min_power = channel->max_power * 3;
1348 ch->max_power = channel->max_power * 4;
1349 ch->max_reg_power = channel->max_reg_power * 4;
1350 ch->max_antenna_gain = channel->max_antenna_gain;
1351 ch->reg_class_id = 0; /* FIXME */
1353 /* FIXME: why use only legacy modes, why not any
1354 * HT/VHT modes? Would that even make any
1356 if (channel->band == IEEE80211_BAND_2GHZ)
1357 ch->mode = MODE_11G;
1359 ch->mode = MODE_11A;
1361 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1364 ath10k_dbg(ATH10K_DBG_WMI,
1365 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1366 ch - arg.channels, arg.n_channels,
1367 ch->freq, ch->max_power, ch->max_reg_power,
1368 ch->max_antenna_gain, ch->mode);
1374 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1375 kfree(arg.channels);
1380 static void ath10k_regd_update(struct ath10k *ar)
1382 struct reg_dmn_pair_mapping *regpair;
1385 lockdep_assert_held(&ar->conf_mutex);
1387 ret = ath10k_update_channel_list(ar);
1389 ath10k_warn("could not update channel list (%d)\n", ret);
1391 regpair = ar->ath_common.regulatory.regpair;
1393 /* Target allows setting up per-band regdomain but ath_common provides
1394 * a combined one only */
1395 ret = ath10k_wmi_pdev_set_regdomain(ar,
1396 regpair->regDmnEnum,
1397 regpair->regDmnEnum, /* 2ghz */
1398 regpair->regDmnEnum, /* 5ghz */
1399 regpair->reg_2ghz_ctl,
1400 regpair->reg_5ghz_ctl);
1402 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1405 static void ath10k_reg_notifier(struct wiphy *wiphy,
1406 struct regulatory_request *request)
1408 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1409 struct ath10k *ar = hw->priv;
1411 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1413 mutex_lock(&ar->conf_mutex);
1414 if (ar->state == ATH10K_STATE_ON)
1415 ath10k_regd_update(ar);
1416 mutex_unlock(&ar->conf_mutex);
1423 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1425 if (ieee80211_is_mgmt(hdr->frame_control))
1426 return HTT_DATA_TX_EXT_TID_MGMT;
1428 if (!ieee80211_is_data_qos(hdr->frame_control))
1429 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1431 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1432 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1434 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1437 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar,
1438 struct ieee80211_tx_info *info)
1440 if (info->control.vif)
1441 return ath10k_vif_to_arvif(info->control.vif)->vdev_id;
1443 if (ar->monitor_enabled)
1444 return ar->monitor_vdev_id;
1446 ath10k_warn("could not resolve vdev id\n");
1451 * Frames sent to the FW have to be in "Native Wifi" format.
1452 * Strip the QoS field from the 802.11 header.
1454 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1455 struct ieee80211_tx_control *control,
1456 struct sk_buff *skb)
1458 struct ieee80211_hdr *hdr = (void *)skb->data;
1461 if (!ieee80211_is_data_qos(hdr->frame_control))
1464 qos_ctl = ieee80211_get_qos_ctl(hdr);
1465 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1466 skb->data, (void *)qos_ctl - (void *)skb->data);
1467 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1470 static void ath10k_tx_wep_key_work(struct work_struct *work)
1472 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1474 int ret, keyidx = arvif->def_wep_key_newidx;
1476 if (arvif->def_wep_key_idx == keyidx)
1479 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1480 arvif->vdev_id, keyidx);
1482 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1484 arvif->ar->wmi.vdev_param->def_keyid,
1487 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1491 arvif->def_wep_key_idx = keyidx;
1494 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1496 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1497 struct ieee80211_vif *vif = info->control.vif;
1498 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1499 struct ath10k *ar = arvif->ar;
1500 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1501 struct ieee80211_key_conf *key = info->control.hw_key;
1503 if (!ieee80211_has_protected(hdr->frame_control))
1509 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1510 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1513 if (key->keyidx == arvif->def_wep_key_idx)
1516 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1517 * queueing frames until key index is updated is not an option because
1518 * sk_buff may need more processing to be done, e.g. offchannel */
1519 arvif->def_wep_key_newidx = key->keyidx;
1520 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1523 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1525 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1526 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1527 struct ieee80211_vif *vif = info->control.vif;
1528 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1530 /* This is case only for P2P_GO */
1531 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1532 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1535 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1536 spin_lock_bh(&ar->data_lock);
1537 if (arvif->u.ap.noa_data)
1538 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1540 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1541 arvif->u.ap.noa_data,
1542 arvif->u.ap.noa_len);
1543 spin_unlock_bh(&ar->data_lock);
1547 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1549 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1552 if (ar->htt.target_version_major >= 3) {
1553 /* Since HTT 3.0 there is no separate mgmt tx command */
1554 ret = ath10k_htt_tx(&ar->htt, skb);
1558 if (ieee80211_is_mgmt(hdr->frame_control)) {
1559 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1561 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
1562 ATH10K_MAX_NUM_MGMT_PENDING) {
1563 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1568 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
1569 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
1571 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1573 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
1575 ieee80211_is_nullfunc(hdr->frame_control)) {
1576 /* FW does not report tx status properly for NullFunc frames
1577 * unless they are sent through mgmt tx path. mac80211 sends
1578 * those frames when it detects link/beacon loss and depends
1579 * on the tx status to be correct. */
1580 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1582 ret = ath10k_htt_tx(&ar->htt, skb);
1587 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1588 ieee80211_free_txskb(ar->hw, skb);
1592 void ath10k_offchan_tx_purge(struct ath10k *ar)
1594 struct sk_buff *skb;
1597 skb = skb_dequeue(&ar->offchan_tx_queue);
1601 ieee80211_free_txskb(ar->hw, skb);
1605 void ath10k_offchan_tx_work(struct work_struct *work)
1607 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1608 struct ath10k_peer *peer;
1609 struct ieee80211_hdr *hdr;
1610 struct sk_buff *skb;
1611 const u8 *peer_addr;
1615 /* FW requirement: We must create a peer before FW will send out
1616 * an offchannel frame. Otherwise the frame will be stuck and
1617 * never transmitted. We delete the peer upon tx completion.
1618 * It is unlikely that a peer for offchannel tx will already be
1619 * present. However it may be in some rare cases so account for that.
1620 * Otherwise we might remove a legitimate peer and break stuff. */
1623 skb = skb_dequeue(&ar->offchan_tx_queue);
1627 mutex_lock(&ar->conf_mutex);
1629 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
1632 hdr = (struct ieee80211_hdr *)skb->data;
1633 peer_addr = ieee80211_get_DA(hdr);
1634 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
1636 spin_lock_bh(&ar->data_lock);
1637 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1638 spin_unlock_bh(&ar->data_lock);
1641 /* FIXME: should this use ath10k_warn()? */
1642 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1643 peer_addr, vdev_id);
1646 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1648 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1649 peer_addr, vdev_id, ret);
1652 spin_lock_bh(&ar->data_lock);
1653 INIT_COMPLETION(ar->offchan_tx_completed);
1654 ar->offchan_tx_skb = skb;
1655 spin_unlock_bh(&ar->data_lock);
1657 ath10k_tx_htt(ar, skb);
1659 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1662 ath10k_warn("timed out waiting for offchannel skb %p\n",
1666 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1668 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1669 peer_addr, vdev_id, ret);
1672 mutex_unlock(&ar->conf_mutex);
1676 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
1678 struct sk_buff *skb;
1681 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1685 ieee80211_free_txskb(ar->hw, skb);
1689 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
1691 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
1692 struct sk_buff *skb;
1696 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
1700 ret = ath10k_wmi_mgmt_tx(ar, skb);
1702 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret);
1711 * This gets called if we dont get a heart-beat during scan.
1712 * This may indicate the FW has hung and we need to abort the
1713 * scan manually to prevent cancel_hw_scan() from deadlocking
1715 void ath10k_reset_scan(unsigned long ptr)
1717 struct ath10k *ar = (struct ath10k *)ptr;
1719 spin_lock_bh(&ar->data_lock);
1720 if (!ar->scan.in_progress) {
1721 spin_unlock_bh(&ar->data_lock);
1725 ath10k_warn("scan timeout. resetting. fw issue?\n");
1727 if (ar->scan.is_roc)
1728 ieee80211_remain_on_channel_expired(ar->hw);
1730 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1732 ar->scan.in_progress = false;
1733 complete_all(&ar->scan.completed);
1734 spin_unlock_bh(&ar->data_lock);
1737 static int ath10k_abort_scan(struct ath10k *ar)
1739 struct wmi_stop_scan_arg arg = {
1740 .req_id = 1, /* FIXME */
1741 .req_type = WMI_SCAN_STOP_ONE,
1742 .u.scan_id = ATH10K_SCAN_ID,
1746 lockdep_assert_held(&ar->conf_mutex);
1748 del_timer_sync(&ar->scan.timeout);
1750 spin_lock_bh(&ar->data_lock);
1751 if (!ar->scan.in_progress) {
1752 spin_unlock_bh(&ar->data_lock);
1756 ar->scan.aborting = true;
1757 spin_unlock_bh(&ar->data_lock);
1759 ret = ath10k_wmi_stop_scan(ar, &arg);
1761 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1762 spin_lock_bh(&ar->data_lock);
1763 ar->scan.in_progress = false;
1764 ath10k_offchan_tx_purge(ar);
1765 spin_unlock_bh(&ar->data_lock);
1769 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1771 ath10k_warn("timed out while waiting for scan to stop\n");
1773 /* scan completion may be done right after we timeout here, so let's
1774 * check the in_progress and tell mac80211 scan is completed. if we
1775 * don't do that and FW fails to send us scan completion indication
1776 * then userspace won't be able to scan anymore */
1779 spin_lock_bh(&ar->data_lock);
1780 if (ar->scan.in_progress) {
1781 ath10k_warn("could not stop scan. its still in progress\n");
1782 ar->scan.in_progress = false;
1783 ath10k_offchan_tx_purge(ar);
1786 spin_unlock_bh(&ar->data_lock);
1791 static int ath10k_start_scan(struct ath10k *ar,
1792 const struct wmi_start_scan_arg *arg)
1796 lockdep_assert_held(&ar->conf_mutex);
1798 ret = ath10k_wmi_start_scan(ar, arg);
1802 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1804 ath10k_abort_scan(ar);
1808 /* the scan can complete earlier, before we even
1809 * start the timer. in that case the timer handler
1810 * checks ar->scan.in_progress and bails out if its
1811 * false. Add a 200ms margin to account event/command
1813 mod_timer(&ar->scan.timeout, jiffies +
1814 msecs_to_jiffies(arg->max_scan_time+200));
1818 /**********************/
1819 /* mac80211 callbacks */
1820 /**********************/
1822 static void ath10k_tx(struct ieee80211_hw *hw,
1823 struct ieee80211_tx_control *control,
1824 struct sk_buff *skb)
1826 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1827 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1828 struct ath10k *ar = hw->priv;
1831 /* We should disable CCK RATE due to P2P */
1832 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1833 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1835 /* we must calculate tid before we apply qos workaround
1836 * as we'd lose the qos control field */
1837 tid = ath10k_tx_h_get_tid(hdr);
1838 vdev_id = ath10k_tx_h_get_vdev_id(ar, info);
1840 /* it makes no sense to process injected frames like that */
1841 if (info->control.vif &&
1842 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1843 ath10k_tx_h_qos_workaround(hw, control, skb);
1844 ath10k_tx_h_update_wep_key(skb);
1845 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1846 ath10k_tx_h_seq_no(skb);
1849 ATH10K_SKB_CB(skb)->vdev_id = vdev_id;
1850 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
1851 ATH10K_SKB_CB(skb)->htt.tid = tid;
1853 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1854 spin_lock_bh(&ar->data_lock);
1855 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1856 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
1857 spin_unlock_bh(&ar->data_lock);
1859 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1861 skb_queue_tail(&ar->offchan_tx_queue, skb);
1862 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1866 ath10k_tx_htt(ar, skb);
1870 * Initialize various parameters with default vaules.
1872 void ath10k_halt(struct ath10k *ar)
1874 lockdep_assert_held(&ar->conf_mutex);
1876 del_timer_sync(&ar->scan.timeout);
1877 ath10k_offchan_tx_purge(ar);
1878 ath10k_mgmt_over_wmi_tx_purge(ar);
1879 ath10k_peer_cleanup_all(ar);
1880 ath10k_core_stop(ar);
1881 ath10k_hif_power_down(ar);
1883 spin_lock_bh(&ar->data_lock);
1884 if (ar->scan.in_progress) {
1885 del_timer(&ar->scan.timeout);
1886 ar->scan.in_progress = false;
1887 ieee80211_scan_completed(ar->hw, true);
1889 spin_unlock_bh(&ar->data_lock);
1892 static int ath10k_start(struct ieee80211_hw *hw)
1894 struct ath10k *ar = hw->priv;
1897 mutex_lock(&ar->conf_mutex);
1899 if (ar->state != ATH10K_STATE_OFF &&
1900 ar->state != ATH10K_STATE_RESTARTING) {
1905 ret = ath10k_hif_power_up(ar);
1907 ath10k_err("could not init hif (%d)\n", ret);
1908 ar->state = ATH10K_STATE_OFF;
1912 ret = ath10k_core_start(ar);
1914 ath10k_err("could not init core (%d)\n", ret);
1915 ath10k_hif_power_down(ar);
1916 ar->state = ATH10K_STATE_OFF;
1920 if (ar->state == ATH10K_STATE_OFF)
1921 ar->state = ATH10K_STATE_ON;
1922 else if (ar->state == ATH10K_STATE_RESTARTING)
1923 ar->state = ATH10K_STATE_RESTARTED;
1925 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
1927 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1930 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 0);
1932 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1935 ath10k_regd_update(ar);
1938 mutex_unlock(&ar->conf_mutex);
1942 static void ath10k_stop(struct ieee80211_hw *hw)
1944 struct ath10k *ar = hw->priv;
1946 mutex_lock(&ar->conf_mutex);
1947 if (ar->state == ATH10K_STATE_ON ||
1948 ar->state == ATH10K_STATE_RESTARTED ||
1949 ar->state == ATH10K_STATE_WEDGED)
1952 ar->state = ATH10K_STATE_OFF;
1953 mutex_unlock(&ar->conf_mutex);
1955 ath10k_mgmt_over_wmi_tx_purge(ar);
1957 cancel_work_sync(&ar->offchan_tx_work);
1958 cancel_work_sync(&ar->wmi_mgmt_tx_work);
1959 cancel_work_sync(&ar->restart_work);
1962 static void ath10k_config_ps(struct ath10k *ar)
1964 struct ath10k_generic_iter ar_iter;
1966 lockdep_assert_held(&ar->conf_mutex);
1968 /* During HW reconfiguration mac80211 reports all interfaces that were
1969 * running until reconfiguration was started. Since FW doesn't have any
1970 * vdevs at this point we must not iterate over this interface list.
1971 * This setting will be updated upon add_interface(). */
1972 if (ar->state == ATH10K_STATE_RESTARTED)
1975 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1978 ieee80211_iterate_active_interfaces_atomic(
1979 ar->hw, IEEE80211_IFACE_ITER_NORMAL,
1980 ath10k_ps_iter, &ar_iter);
1983 ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
1986 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1988 struct ath10k *ar = hw->priv;
1989 struct ieee80211_conf *conf = &hw->conf;
1992 mutex_lock(&ar->conf_mutex);
1994 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1995 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
1996 conf->chandef.chan->center_freq);
1997 spin_lock_bh(&ar->data_lock);
1998 ar->rx_channel = conf->chandef.chan;
1999 spin_unlock_bh(&ar->data_lock);
2002 if (changed & IEEE80211_CONF_CHANGE_PS)
2003 ath10k_config_ps(ar);
2005 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2006 if (conf->flags & IEEE80211_CONF_MONITOR)
2007 ret = ath10k_monitor_create(ar);
2009 ret = ath10k_monitor_destroy(ar);
2012 mutex_unlock(&ar->conf_mutex);
2018 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2019 * because we will send mgmt frames without CCK. This requirement
2020 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2023 static int ath10k_add_interface(struct ieee80211_hw *hw,
2024 struct ieee80211_vif *vif)
2026 struct ath10k *ar = hw->priv;
2027 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2028 enum wmi_sta_powersave_param param;
2034 mutex_lock(&ar->conf_mutex);
2036 memset(arvif, 0, sizeof(*arvif));
2041 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2043 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
2044 ath10k_warn("Only one monitor interface allowed\n");
2049 bit = ffs(ar->free_vdev_map);
2055 arvif->vdev_id = bit - 1;
2056 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2059 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2061 switch (vif->type) {
2062 case NL80211_IFTYPE_UNSPECIFIED:
2063 case NL80211_IFTYPE_STATION:
2064 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2066 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2068 case NL80211_IFTYPE_ADHOC:
2069 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2071 case NL80211_IFTYPE_AP:
2072 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2075 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2077 case NL80211_IFTYPE_MONITOR:
2078 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2085 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
2086 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
2088 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2089 arvif->vdev_subtype, vif->addr);
2091 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
2095 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2096 list_add(&arvif->list, &ar->arvifs);
2098 vdev_param = ar->wmi.vdev_param->def_keyid;
2099 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2100 arvif->def_wep_key_idx);
2102 ath10k_warn("Failed to set default keyid: %d\n", ret);
2103 goto err_vdev_delete;
2106 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2107 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2108 ATH10K_HW_TXRX_NATIVE_WIFI);
2109 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2110 if (ret && ret != -EOPNOTSUPP) {
2111 ath10k_warn("Failed to set TX encap: %d\n", ret);
2112 goto err_vdev_delete;
2115 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2116 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2118 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2119 goto err_vdev_delete;
2123 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2124 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2125 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2126 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2129 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2130 goto err_peer_delete;
2133 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2134 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2135 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2138 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2139 goto err_peer_delete;
2142 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2143 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2144 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2147 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2148 goto err_peer_delete;
2152 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2154 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2155 arvif->vdev_id, ret);
2156 goto err_peer_delete;
2159 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2161 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2162 arvif->vdev_id, ret);
2163 goto err_peer_delete;
2166 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2167 ar->monitor_present = true;
2169 mutex_unlock(&ar->conf_mutex);
2173 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2174 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2177 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2178 ar->free_vdev_map &= ~BIT(arvif->vdev_id);
2179 list_del(&arvif->list);
2182 mutex_unlock(&ar->conf_mutex);
2187 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2188 struct ieee80211_vif *vif)
2190 struct ath10k *ar = hw->priv;
2191 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2194 mutex_lock(&ar->conf_mutex);
2196 cancel_work_sync(&arvif->wep_key_work);
2198 spin_lock_bh(&ar->data_lock);
2199 if (arvif->beacon) {
2200 dev_kfree_skb_any(arvif->beacon);
2201 arvif->beacon = NULL;
2203 spin_unlock_bh(&ar->data_lock);
2205 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2206 list_del(&arvif->list);
2208 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2209 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2211 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2213 kfree(arvif->u.ap.noa_data);
2216 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2219 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2221 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2223 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2224 ar->monitor_present = false;
2226 ath10k_peer_cleanup(ar, arvif->vdev_id);
2228 mutex_unlock(&ar->conf_mutex);
2232 * FIXME: Has to be verified.
2234 #define SUPPORTED_FILTERS \
2235 (FIF_PROMISC_IN_BSS | \
2240 FIF_BCN_PRBRESP_PROMISC | \
2244 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2245 unsigned int changed_flags,
2246 unsigned int *total_flags,
2249 struct ath10k *ar = hw->priv;
2252 mutex_lock(&ar->conf_mutex);
2254 changed_flags &= SUPPORTED_FILTERS;
2255 *total_flags &= SUPPORTED_FILTERS;
2256 ar->filter_flags = *total_flags;
2258 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2259 !ar->monitor_enabled) {
2260 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2261 ar->monitor_vdev_id);
2263 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2265 ath10k_warn("Unable to start monitor mode\n");
2266 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2267 ar->monitor_enabled) {
2268 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2269 ar->monitor_vdev_id);
2271 ret = ath10k_monitor_stop(ar);
2273 ath10k_warn("Unable to stop monitor mode\n");
2276 mutex_unlock(&ar->conf_mutex);
2279 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2280 struct ieee80211_vif *vif,
2281 struct ieee80211_bss_conf *info,
2284 struct ath10k *ar = hw->priv;
2285 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2287 u32 vdev_param, pdev_param;
2289 mutex_lock(&ar->conf_mutex);
2291 if (changed & BSS_CHANGED_IBSS)
2292 ath10k_control_ibss(arvif, info, vif->addr);
2294 if (changed & BSS_CHANGED_BEACON_INT) {
2295 arvif->beacon_interval = info->beacon_int;
2296 vdev_param = ar->wmi.vdev_param->beacon_interval;
2297 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2298 arvif->beacon_interval);
2299 ath10k_dbg(ATH10K_DBG_MAC,
2300 "mac vdev %d beacon_interval %d\n",
2301 arvif->vdev_id, arvif->beacon_interval);
2304 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2308 if (changed & BSS_CHANGED_BEACON) {
2309 ath10k_dbg(ATH10K_DBG_MAC,
2310 "vdev %d set beacon tx mode to staggered\n",
2313 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
2314 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
2315 WMI_BEACON_STAGGERED_MODE);
2317 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2321 if (changed & BSS_CHANGED_BEACON_INFO) {
2322 arvif->dtim_period = info->dtim_period;
2324 ath10k_dbg(ATH10K_DBG_MAC,
2325 "mac vdev %d dtim_period %d\n",
2326 arvif->vdev_id, arvif->dtim_period);
2328 vdev_param = ar->wmi.vdev_param->dtim_period;
2329 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2330 arvif->dtim_period);
2332 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2336 if (changed & BSS_CHANGED_SSID &&
2337 vif->type == NL80211_IFTYPE_AP) {
2338 arvif->u.ap.ssid_len = info->ssid_len;
2340 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2341 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2344 if (changed & BSS_CHANGED_BSSID) {
2345 if (!is_zero_ether_addr(info->bssid)) {
2346 ath10k_dbg(ATH10K_DBG_MAC,
2347 "mac vdev %d create peer %pM\n",
2348 arvif->vdev_id, info->bssid);
2350 ret = ath10k_peer_create(ar, arvif->vdev_id,
2353 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2354 info->bssid, arvif->vdev_id);
2356 if (vif->type == NL80211_IFTYPE_STATION) {
2358 * this is never erased as we it for crypto key
2359 * clearing; this is FW requirement
2361 memcpy(arvif->u.sta.bssid, info->bssid,
2364 ath10k_dbg(ATH10K_DBG_MAC,
2365 "mac vdev %d start %pM\n",
2366 arvif->vdev_id, info->bssid);
2368 /* FIXME: check return value */
2369 ret = ath10k_vdev_start(arvif);
2373 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2374 * so driver need to store it. It is needed when leaving
2375 * IBSS in order to remove BSSID peer.
2377 if (vif->type == NL80211_IFTYPE_ADHOC)
2378 memcpy(arvif->u.ibss.bssid, info->bssid,
2383 if (changed & BSS_CHANGED_BEACON_ENABLED)
2384 ath10k_control_beaconing(arvif, info);
2386 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2388 if (info->use_cts_prot)
2393 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2394 arvif->vdev_id, cts_prot);
2396 vdev_param = ar->wmi.vdev_param->enable_rtscts;
2397 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2400 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2404 if (changed & BSS_CHANGED_ERP_SLOT) {
2406 if (info->use_short_slot)
2407 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2410 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2412 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2413 arvif->vdev_id, slottime);
2415 vdev_param = ar->wmi.vdev_param->slot_time;
2416 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2419 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2423 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2425 if (info->use_short_preamble)
2426 preamble = WMI_VDEV_PREAMBLE_SHORT;
2428 preamble = WMI_VDEV_PREAMBLE_LONG;
2430 ath10k_dbg(ATH10K_DBG_MAC,
2431 "mac vdev %d preamble %dn",
2432 arvif->vdev_id, preamble);
2434 vdev_param = ar->wmi.vdev_param->preamble;
2435 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2438 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2442 if (changed & BSS_CHANGED_ASSOC) {
2444 ath10k_bss_assoc(hw, vif, info);
2447 mutex_unlock(&ar->conf_mutex);
2450 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2451 struct ieee80211_vif *vif,
2452 struct cfg80211_scan_request *req)
2454 struct ath10k *ar = hw->priv;
2455 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2456 struct wmi_start_scan_arg arg;
2460 mutex_lock(&ar->conf_mutex);
2462 spin_lock_bh(&ar->data_lock);
2463 if (ar->scan.in_progress) {
2464 spin_unlock_bh(&ar->data_lock);
2469 INIT_COMPLETION(ar->scan.started);
2470 INIT_COMPLETION(ar->scan.completed);
2471 ar->scan.in_progress = true;
2472 ar->scan.aborting = false;
2473 ar->scan.is_roc = false;
2474 ar->scan.vdev_id = arvif->vdev_id;
2475 spin_unlock_bh(&ar->data_lock);
2477 memset(&arg, 0, sizeof(arg));
2478 ath10k_wmi_start_scan_init(ar, &arg);
2479 arg.vdev_id = arvif->vdev_id;
2480 arg.scan_id = ATH10K_SCAN_ID;
2483 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2486 arg.ie_len = req->ie_len;
2487 memcpy(arg.ie, req->ie, arg.ie_len);
2491 arg.n_ssids = req->n_ssids;
2492 for (i = 0; i < arg.n_ssids; i++) {
2493 arg.ssids[i].len = req->ssids[i].ssid_len;
2494 arg.ssids[i].ssid = req->ssids[i].ssid;
2497 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2500 if (req->n_channels) {
2501 arg.n_channels = req->n_channels;
2502 for (i = 0; i < arg.n_channels; i++)
2503 arg.channels[i] = req->channels[i]->center_freq;
2506 ret = ath10k_start_scan(ar, &arg);
2508 ath10k_warn("could not start hw scan (%d)\n", ret);
2509 spin_lock_bh(&ar->data_lock);
2510 ar->scan.in_progress = false;
2511 spin_unlock_bh(&ar->data_lock);
2515 mutex_unlock(&ar->conf_mutex);
2519 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2520 struct ieee80211_vif *vif)
2522 struct ath10k *ar = hw->priv;
2525 mutex_lock(&ar->conf_mutex);
2526 ret = ath10k_abort_scan(ar);
2528 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2530 ieee80211_scan_completed(hw, 1 /* aborted */);
2532 mutex_unlock(&ar->conf_mutex);
2535 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2536 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2537 struct ieee80211_key_conf *key)
2539 struct ath10k *ar = hw->priv;
2540 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2541 struct ath10k_peer *peer;
2542 const u8 *peer_addr;
2543 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2544 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2547 if (key->keyidx > WMI_MAX_KEY_INDEX)
2550 mutex_lock(&ar->conf_mutex);
2553 peer_addr = sta->addr;
2554 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2555 peer_addr = vif->bss_conf.bssid;
2557 peer_addr = vif->addr;
2559 key->hw_key_idx = key->keyidx;
2561 /* the peer should not disappear in mid-way (unless FW goes awry) since
2562 * we already hold conf_mutex. we just make sure its there now. */
2563 spin_lock_bh(&ar->data_lock);
2564 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2565 spin_unlock_bh(&ar->data_lock);
2568 if (cmd == SET_KEY) {
2569 ath10k_warn("cannot install key for non-existent peer %pM\n",
2574 /* if the peer doesn't exist there is no key to disable
2582 arvif->wep_keys[key->keyidx] = key;
2584 arvif->wep_keys[key->keyidx] = NULL;
2586 if (cmd == DISABLE_KEY)
2587 ath10k_clear_vdev_key(arvif, key);
2590 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2592 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2596 spin_lock_bh(&ar->data_lock);
2597 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2598 if (peer && cmd == SET_KEY)
2599 peer->keys[key->keyidx] = key;
2600 else if (peer && cmd == DISABLE_KEY)
2601 peer->keys[key->keyidx] = NULL;
2602 else if (peer == NULL)
2603 /* impossible unless FW goes crazy */
2604 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2605 spin_unlock_bh(&ar->data_lock);
2608 mutex_unlock(&ar->conf_mutex);
2612 static int ath10k_sta_state(struct ieee80211_hw *hw,
2613 struct ieee80211_vif *vif,
2614 struct ieee80211_sta *sta,
2615 enum ieee80211_sta_state old_state,
2616 enum ieee80211_sta_state new_state)
2618 struct ath10k *ar = hw->priv;
2619 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2622 mutex_lock(&ar->conf_mutex);
2624 if (old_state == IEEE80211_STA_NOTEXIST &&
2625 new_state == IEEE80211_STA_NONE &&
2626 vif->type != NL80211_IFTYPE_STATION) {
2628 * New station addition.
2630 ath10k_dbg(ATH10K_DBG_MAC,
2631 "mac vdev %d peer create %pM (new sta)\n",
2632 arvif->vdev_id, sta->addr);
2634 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2636 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2637 sta->addr, arvif->vdev_id);
2638 } else if ((old_state == IEEE80211_STA_NONE &&
2639 new_state == IEEE80211_STA_NOTEXIST)) {
2641 * Existing station deletion.
2643 ath10k_dbg(ATH10K_DBG_MAC,
2644 "mac vdev %d peer delete %pM (sta gone)\n",
2645 arvif->vdev_id, sta->addr);
2646 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2648 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2649 sta->addr, arvif->vdev_id);
2651 if (vif->type == NL80211_IFTYPE_STATION)
2652 ath10k_bss_disassoc(hw, vif);
2653 } else if (old_state == IEEE80211_STA_AUTH &&
2654 new_state == IEEE80211_STA_ASSOC &&
2655 (vif->type == NL80211_IFTYPE_AP ||
2656 vif->type == NL80211_IFTYPE_ADHOC)) {
2660 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2663 ret = ath10k_station_assoc(ar, arvif, sta);
2665 ath10k_warn("Failed to associate station: %pM\n",
2667 } else if (old_state == IEEE80211_STA_ASSOC &&
2668 new_state == IEEE80211_STA_AUTH &&
2669 (vif->type == NL80211_IFTYPE_AP ||
2670 vif->type == NL80211_IFTYPE_ADHOC)) {
2674 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2677 ret = ath10k_station_disassoc(ar, arvif, sta);
2679 ath10k_warn("Failed to disassociate station: %pM\n",
2683 mutex_unlock(&ar->conf_mutex);
2687 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2688 u16 ac, bool enable)
2690 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2694 lockdep_assert_held(&ar->conf_mutex);
2696 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2700 case IEEE80211_AC_VO:
2701 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2702 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2704 case IEEE80211_AC_VI:
2705 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2706 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2708 case IEEE80211_AC_BE:
2709 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2710 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2712 case IEEE80211_AC_BK:
2713 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2714 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2719 arvif->u.sta.uapsd |= value;
2721 arvif->u.sta.uapsd &= ~value;
2723 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2724 WMI_STA_PS_PARAM_UAPSD,
2725 arvif->u.sta.uapsd);
2727 ath10k_warn("could not set uapsd params %d\n", ret);
2731 if (arvif->u.sta.uapsd)
2732 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2734 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2736 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2737 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2740 ath10k_warn("could not set rx wake param %d\n", ret);
2746 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2747 struct ieee80211_vif *vif, u16 ac,
2748 const struct ieee80211_tx_queue_params *params)
2750 struct ath10k *ar = hw->priv;
2751 struct wmi_wmm_params_arg *p = NULL;
2754 mutex_lock(&ar->conf_mutex);
2757 case IEEE80211_AC_VO:
2758 p = &ar->wmm_params.ac_vo;
2760 case IEEE80211_AC_VI:
2761 p = &ar->wmm_params.ac_vi;
2763 case IEEE80211_AC_BE:
2764 p = &ar->wmm_params.ac_be;
2766 case IEEE80211_AC_BK:
2767 p = &ar->wmm_params.ac_bk;
2776 p->cwmin = params->cw_min;
2777 p->cwmax = params->cw_max;
2778 p->aifs = params->aifs;
2781 * The channel time duration programmed in the HW is in absolute
2782 * microseconds, while mac80211 gives the txop in units of
2785 p->txop = params->txop * 32;
2787 /* FIXME: FW accepts wmm params per hw, not per vif */
2788 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2790 ath10k_warn("could not set wmm params %d\n", ret);
2794 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2796 ath10k_warn("could not set sta uapsd %d\n", ret);
2799 mutex_unlock(&ar->conf_mutex);
2803 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2805 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2806 struct ieee80211_vif *vif,
2807 struct ieee80211_channel *chan,
2809 enum ieee80211_roc_type type)
2811 struct ath10k *ar = hw->priv;
2812 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2813 struct wmi_start_scan_arg arg;
2816 mutex_lock(&ar->conf_mutex);
2818 spin_lock_bh(&ar->data_lock);
2819 if (ar->scan.in_progress) {
2820 spin_unlock_bh(&ar->data_lock);
2825 INIT_COMPLETION(ar->scan.started);
2826 INIT_COMPLETION(ar->scan.completed);
2827 INIT_COMPLETION(ar->scan.on_channel);
2828 ar->scan.in_progress = true;
2829 ar->scan.aborting = false;
2830 ar->scan.is_roc = true;
2831 ar->scan.vdev_id = arvif->vdev_id;
2832 ar->scan.roc_freq = chan->center_freq;
2833 spin_unlock_bh(&ar->data_lock);
2835 memset(&arg, 0, sizeof(arg));
2836 ath10k_wmi_start_scan_init(ar, &arg);
2837 arg.vdev_id = arvif->vdev_id;
2838 arg.scan_id = ATH10K_SCAN_ID;
2840 arg.channels[0] = chan->center_freq;
2841 arg.dwell_time_active = duration;
2842 arg.dwell_time_passive = duration;
2843 arg.max_scan_time = 2 * duration;
2844 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2845 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2847 ret = ath10k_start_scan(ar, &arg);
2849 ath10k_warn("could not start roc scan (%d)\n", ret);
2850 spin_lock_bh(&ar->data_lock);
2851 ar->scan.in_progress = false;
2852 spin_unlock_bh(&ar->data_lock);
2856 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2858 ath10k_warn("could not switch to channel for roc scan\n");
2859 ath10k_abort_scan(ar);
2866 mutex_unlock(&ar->conf_mutex);
2870 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2872 struct ath10k *ar = hw->priv;
2874 mutex_lock(&ar->conf_mutex);
2875 ath10k_abort_scan(ar);
2876 mutex_unlock(&ar->conf_mutex);
2882 * Both RTS and Fragmentation threshold are interface-specific
2883 * in ath10k, but device-specific in mac80211.
2885 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2887 struct ath10k_generic_iter *ar_iter = data;
2888 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2889 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2891 lockdep_assert_held(&arvif->ar->conf_mutex);
2893 /* During HW reconfiguration mac80211 reports all interfaces that were
2894 * running until reconfiguration was started. Since FW doesn't have any
2895 * vdevs at this point we must not iterate over this interface list.
2896 * This setting will be updated upon add_interface(). */
2897 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2900 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
2901 arvif->vdev_id, rts);
2903 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
2905 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2909 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2911 struct ath10k_generic_iter ar_iter;
2912 struct ath10k *ar = hw->priv;
2914 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2917 mutex_lock(&ar->conf_mutex);
2918 ieee80211_iterate_active_interfaces_atomic(
2919 hw, IEEE80211_IFACE_ITER_NORMAL,
2920 ath10k_set_rts_iter, &ar_iter);
2921 mutex_unlock(&ar->conf_mutex);
2926 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2928 struct ath10k_generic_iter *ar_iter = data;
2929 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2930 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2932 lockdep_assert_held(&arvif->ar->conf_mutex);
2934 /* During HW reconfiguration mac80211 reports all interfaces that were
2935 * running until reconfiguration was started. Since FW doesn't have any
2936 * vdevs at this point we must not iterate over this interface list.
2937 * This setting will be updated upon add_interface(). */
2938 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2941 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
2942 arvif->vdev_id, frag);
2944 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
2946 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2950 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2952 struct ath10k_generic_iter ar_iter;
2953 struct ath10k *ar = hw->priv;
2955 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2958 mutex_lock(&ar->conf_mutex);
2959 ieee80211_iterate_active_interfaces_atomic(
2960 hw, IEEE80211_IFACE_ITER_NORMAL,
2961 ath10k_set_frag_iter, &ar_iter);
2962 mutex_unlock(&ar->conf_mutex);
2967 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2969 struct ath10k *ar = hw->priv;
2973 /* mac80211 doesn't care if we really xmit queued frames or not
2974 * we'll collect those frames either way if we stop/delete vdevs */
2978 mutex_lock(&ar->conf_mutex);
2980 if (ar->state == ATH10K_STATE_WEDGED)
2983 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
2986 spin_lock_bh(&ar->htt.tx_lock);
2987 empty = (ar->htt.num_pending_tx == 0);
2988 spin_unlock_bh(&ar->htt.tx_lock);
2990 skip = (ar->state == ATH10K_STATE_WEDGED);
2993 }), ATH10K_FLUSH_TIMEOUT_HZ);
2995 if (ret <= 0 || skip)
2996 ath10k_warn("tx not flushed\n");
2999 mutex_unlock(&ar->conf_mutex);
3002 /* TODO: Implement this function properly
3003 * For now it is needed to reply to Probe Requests in IBSS mode.
3004 * Propably we need this information from FW.
3006 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3012 static int ath10k_suspend(struct ieee80211_hw *hw,
3013 struct cfg80211_wowlan *wowlan)
3015 struct ath10k *ar = hw->priv;
3018 ar->is_target_paused = false;
3020 ret = ath10k_wmi_pdev_suspend_target(ar);
3022 ath10k_warn("could not suspend target (%d)\n", ret);
3026 ret = wait_event_interruptible_timeout(ar->event_queue,
3027 ar->is_target_paused == true,
3030 ath10k_warn("suspend interrupted (%d)\n", ret);
3032 } else if (ret == 0) {
3033 ath10k_warn("suspend timed out - target pause event never came\n");
3037 ret = ath10k_hif_suspend(ar);
3039 ath10k_warn("could not suspend hif (%d)\n", ret);
3045 ret = ath10k_wmi_pdev_resume_target(ar);
3047 ath10k_warn("could not resume target (%d)\n", ret);
3051 static int ath10k_resume(struct ieee80211_hw *hw)
3053 struct ath10k *ar = hw->priv;
3056 ret = ath10k_hif_resume(ar);
3058 ath10k_warn("could not resume hif (%d)\n", ret);
3062 ret = ath10k_wmi_pdev_resume_target(ar);
3064 ath10k_warn("could not resume target (%d)\n", ret);
3072 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3074 struct ath10k *ar = hw->priv;
3076 mutex_lock(&ar->conf_mutex);
3078 /* If device failed to restart it will be in a different state, e.g.
3079 * ATH10K_STATE_WEDGED */
3080 if (ar->state == ATH10K_STATE_RESTARTED) {
3081 ath10k_info("device successfully recovered\n");
3082 ar->state = ATH10K_STATE_ON;
3085 mutex_unlock(&ar->conf_mutex);
3088 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3089 struct survey_info *survey)
3091 struct ath10k *ar = hw->priv;
3092 struct ieee80211_supported_band *sband;
3093 struct survey_info *ar_survey = &ar->survey[idx];
3096 mutex_lock(&ar->conf_mutex);
3098 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
3099 if (sband && idx >= sband->n_channels) {
3100 idx -= sband->n_channels;
3105 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
3107 if (!sband || idx >= sband->n_channels) {
3112 spin_lock_bh(&ar->data_lock);
3113 memcpy(survey, ar_survey, sizeof(*survey));
3114 spin_unlock_bh(&ar->data_lock);
3116 survey->channel = &sband->channels[idx];
3119 mutex_unlock(&ar->conf_mutex);
3123 static const struct ieee80211_ops ath10k_ops = {
3125 .start = ath10k_start,
3126 .stop = ath10k_stop,
3127 .config = ath10k_config,
3128 .add_interface = ath10k_add_interface,
3129 .remove_interface = ath10k_remove_interface,
3130 .configure_filter = ath10k_configure_filter,
3131 .bss_info_changed = ath10k_bss_info_changed,
3132 .hw_scan = ath10k_hw_scan,
3133 .cancel_hw_scan = ath10k_cancel_hw_scan,
3134 .set_key = ath10k_set_key,
3135 .sta_state = ath10k_sta_state,
3136 .conf_tx = ath10k_conf_tx,
3137 .remain_on_channel = ath10k_remain_on_channel,
3138 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3139 .set_rts_threshold = ath10k_set_rts_threshold,
3140 .set_frag_threshold = ath10k_set_frag_threshold,
3141 .flush = ath10k_flush,
3142 .tx_last_beacon = ath10k_tx_last_beacon,
3143 .restart_complete = ath10k_restart_complete,
3144 .get_survey = ath10k_get_survey,
3146 .suspend = ath10k_suspend,
3147 .resume = ath10k_resume,
3151 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3152 .bitrate = (_rate), \
3153 .flags = (_flags), \
3154 .hw_value = (_rateid), \
3157 #define CHAN2G(_channel, _freq, _flags) { \
3158 .band = IEEE80211_BAND_2GHZ, \
3159 .hw_value = (_channel), \
3160 .center_freq = (_freq), \
3161 .flags = (_flags), \
3162 .max_antenna_gain = 0, \
3166 #define CHAN5G(_channel, _freq, _flags) { \
3167 .band = IEEE80211_BAND_5GHZ, \
3168 .hw_value = (_channel), \
3169 .center_freq = (_freq), \
3170 .flags = (_flags), \
3171 .max_antenna_gain = 0, \
3175 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3185 CHAN2G(10, 2457, 0),
3186 CHAN2G(11, 2462, 0),
3187 CHAN2G(12, 2467, 0),
3188 CHAN2G(13, 2472, 0),
3189 CHAN2G(14, 2484, 0),
3192 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
3193 CHAN5G(36, 5180, 0),
3194 CHAN5G(40, 5200, 0),
3195 CHAN5G(44, 5220, 0),
3196 CHAN5G(48, 5240, 0),
3197 CHAN5G(52, 5260, 0),
3198 CHAN5G(56, 5280, 0),
3199 CHAN5G(60, 5300, 0),
3200 CHAN5G(64, 5320, 0),
3201 CHAN5G(100, 5500, 0),
3202 CHAN5G(104, 5520, 0),
3203 CHAN5G(108, 5540, 0),
3204 CHAN5G(112, 5560, 0),
3205 CHAN5G(116, 5580, 0),
3206 CHAN5G(120, 5600, 0),
3207 CHAN5G(124, 5620, 0),
3208 CHAN5G(128, 5640, 0),
3209 CHAN5G(132, 5660, 0),
3210 CHAN5G(136, 5680, 0),
3211 CHAN5G(140, 5700, 0),
3212 CHAN5G(149, 5745, 0),
3213 CHAN5G(153, 5765, 0),
3214 CHAN5G(157, 5785, 0),
3215 CHAN5G(161, 5805, 0),
3216 CHAN5G(165, 5825, 0),
3219 static struct ieee80211_rate ath10k_rates[] = {
3221 RATETAB_ENT(10, 0x82, 0),
3222 RATETAB_ENT(20, 0x84, 0),
3223 RATETAB_ENT(55, 0x8b, 0),
3224 RATETAB_ENT(110, 0x96, 0),
3226 RATETAB_ENT(60, 0x0c, 0),
3227 RATETAB_ENT(90, 0x12, 0),
3228 RATETAB_ENT(120, 0x18, 0),
3229 RATETAB_ENT(180, 0x24, 0),
3230 RATETAB_ENT(240, 0x30, 0),
3231 RATETAB_ENT(360, 0x48, 0),
3232 RATETAB_ENT(480, 0x60, 0),
3233 RATETAB_ENT(540, 0x6c, 0),
3236 #define ath10k_a_rates (ath10k_rates + 4)
3237 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3238 #define ath10k_g_rates (ath10k_rates + 0)
3239 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3241 struct ath10k *ath10k_mac_create(void)
3243 struct ieee80211_hw *hw;
3246 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3256 void ath10k_mac_destroy(struct ath10k *ar)
3258 ieee80211_free_hw(ar->hw);
3261 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3264 .types = BIT(NL80211_IFTYPE_STATION)
3265 | BIT(NL80211_IFTYPE_P2P_CLIENT)
3269 .types = BIT(NL80211_IFTYPE_P2P_GO)
3273 .types = BIT(NL80211_IFTYPE_AP)
3277 static const struct ieee80211_iface_combination ath10k_if_comb = {
3278 .limits = ath10k_if_limits,
3279 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3280 .max_interfaces = 8,
3281 .num_different_channels = 1,
3282 .beacon_int_infra_match = true,
3285 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3287 struct ieee80211_sta_vht_cap vht_cap = {0};
3291 vht_cap.vht_supported = 1;
3292 vht_cap.cap = ar->vht_cap_info;
3295 for (i = 0; i < 8; i++) {
3296 if (i < ar->num_rf_chains)
3297 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3299 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3302 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3303 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3308 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3311 struct ieee80211_sta_ht_cap ht_cap = {0};
3313 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3316 ht_cap.ht_supported = 1;
3317 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3318 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3319 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3320 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3321 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3323 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3324 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3326 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3327 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3329 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3332 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3333 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3338 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3339 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3341 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3344 stbc = ar->ht_cap_info;
3345 stbc &= WMI_HT_CAP_RX_STBC;
3346 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3347 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3348 stbc &= IEEE80211_HT_CAP_RX_STBC;
3353 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3354 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3356 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3357 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3359 /* max AMSDU is implicitly taken from vht_cap_info */
3360 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3361 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3363 for (i = 0; i < ar->num_rf_chains; i++)
3364 ht_cap.mcs.rx_mask[i] = 0xFF;
3366 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3372 static void ath10k_get_arvif_iter(void *data, u8 *mac,
3373 struct ieee80211_vif *vif)
3375 struct ath10k_vif_iter *arvif_iter = data;
3376 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3378 if (arvif->vdev_id == arvif_iter->vdev_id)
3379 arvif_iter->arvif = arvif;
3382 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3384 struct ath10k_vif_iter arvif_iter;
3387 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3388 arvif_iter.vdev_id = vdev_id;
3390 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3391 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3393 ath10k_get_arvif_iter,
3395 if (!arvif_iter.arvif) {
3396 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3400 return arvif_iter.arvif;
3403 int ath10k_mac_register(struct ath10k *ar)
3405 struct ieee80211_supported_band *band;
3406 struct ieee80211_sta_vht_cap vht_cap;
3407 struct ieee80211_sta_ht_cap ht_cap;
3411 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3413 SET_IEEE80211_DEV(ar->hw, ar->dev);
3415 ht_cap = ath10k_get_ht_cap(ar);
3416 vht_cap = ath10k_create_vht_cap(ar);
3418 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3419 channels = kmemdup(ath10k_2ghz_channels,
3420 sizeof(ath10k_2ghz_channels),
3427 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3428 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3429 band->channels = channels;
3430 band->n_bitrates = ath10k_g_rates_size;
3431 band->bitrates = ath10k_g_rates;
3432 band->ht_cap = ht_cap;
3434 /* vht is not supported in 2.4 GHz */
3436 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3439 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3440 channels = kmemdup(ath10k_5ghz_channels,
3441 sizeof(ath10k_5ghz_channels),
3448 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3449 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3450 band->channels = channels;
3451 band->n_bitrates = ath10k_a_rates_size;
3452 band->bitrates = ath10k_a_rates;
3453 band->ht_cap = ht_cap;
3454 band->vht_cap = vht_cap;
3455 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3458 ar->hw->wiphy->interface_modes =
3459 BIT(NL80211_IFTYPE_STATION) |
3460 BIT(NL80211_IFTYPE_ADHOC) |
3461 BIT(NL80211_IFTYPE_AP) |
3462 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3463 BIT(NL80211_IFTYPE_P2P_GO);
3465 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3466 IEEE80211_HW_SUPPORTS_PS |
3467 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3468 IEEE80211_HW_SUPPORTS_UAPSD |
3469 IEEE80211_HW_MFP_CAPABLE |
3470 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3471 IEEE80211_HW_HAS_RATE_CONTROL |
3472 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3473 IEEE80211_HW_WANT_MONITOR_VIF |
3474 IEEE80211_HW_AP_LINK_PS;
3476 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3477 * bytes is used for padding/alignment if necessary. */
3478 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
3480 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3481 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3483 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3484 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3485 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3488 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3489 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3491 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3493 ar->hw->channel_change_time = 5000;
3494 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3496 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3497 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3499 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3501 * on LL hardware queues are managed entirely by the FW
3502 * so we only advertise to mac we can do the queues thing
3506 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3507 ar->hw->wiphy->n_iface_combinations = 1;
3509 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3511 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3512 ath10k_reg_notifier);
3514 ath10k_err("Regulatory initialization failed\n");
3518 ret = ieee80211_register_hw(ar->hw);
3520 ath10k_err("ieee80211 registration failed: %d\n", ret);
3524 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3525 ret = regulatory_hint(ar->hw->wiphy,
3526 ar->ath_common.regulatory.alpha2);
3528 goto err_unregister;
3534 ieee80211_unregister_hw(ar->hw);
3536 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3537 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3542 void ath10k_mac_unregister(struct ath10k *ar)
3544 ieee80211_unregister_hw(ar->hw);
3546 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3547 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3549 SET_IEEE80211_DEV(ar->hw, NULL);