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 ret = ath10k_wmi_vdev_start(ar, &arg);
465 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
469 ret = ath10k_vdev_setup_sync(ar);
471 ath10k_warn("vdev setup failed %d\n", ret);
478 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
480 struct ath10k *ar = arvif->ar;
483 lockdep_assert_held(&ar->conf_mutex);
485 INIT_COMPLETION(ar->vdev_setup_done);
487 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
489 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
493 ret = ath10k_vdev_setup_sync(ar);
495 ath10k_warn("vdev setup failed %d\n", ret);
502 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
504 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
505 struct wmi_vdev_start_request_arg arg = {};
508 lockdep_assert_held(&ar->conf_mutex);
510 arg.vdev_id = vdev_id;
511 arg.channel.freq = channel->center_freq;
512 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
514 /* TODO setup this dynamically, what in case we
515 don't have any vifs? */
516 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
518 arg.channel.min_power = channel->max_power * 3;
519 arg.channel.max_power = channel->max_power * 4;
520 arg.channel.max_reg_power = channel->max_reg_power * 4;
521 arg.channel.max_antenna_gain = channel->max_antenna_gain;
523 ret = ath10k_wmi_vdev_start(ar, &arg);
525 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
529 ret = ath10k_vdev_setup_sync(ar);
531 ath10k_warn("Monitor vdev setup failed %d\n", ret);
535 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
537 ath10k_warn("Monitor vdev up failed: %d\n", ret);
541 ar->monitor_vdev_id = vdev_id;
542 ar->monitor_enabled = true;
547 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
549 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
554 static int ath10k_monitor_stop(struct ath10k *ar)
558 lockdep_assert_held(&ar->conf_mutex);
560 /* For some reasons, ath10k_wmi_vdev_down() here couse
561 * often ath10k_wmi_vdev_stop() to fail. Next we could
562 * not run monitor vdev and driver reload
563 * required. Don't see such problems we skip
564 * ath10k_wmi_vdev_down() here.
567 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
569 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
571 ret = ath10k_vdev_setup_sync(ar);
573 ath10k_warn("Monitor_down sync failed: %d\n", ret);
575 ar->monitor_enabled = false;
579 static int ath10k_monitor_create(struct ath10k *ar)
583 lockdep_assert_held(&ar->conf_mutex);
585 if (ar->monitor_present) {
586 ath10k_warn("Monitor mode already enabled\n");
590 bit = ffs(ar->free_vdev_map);
592 ath10k_warn("No free VDEV slots\n");
596 ar->monitor_vdev_id = bit - 1;
597 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
599 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
600 WMI_VDEV_TYPE_MONITOR,
603 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
607 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface created, vdev id: %d\n",
608 ar->monitor_vdev_id);
610 ar->monitor_present = true;
615 * Restore the ID to the global map.
617 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
621 static int ath10k_monitor_destroy(struct ath10k *ar)
625 lockdep_assert_held(&ar->conf_mutex);
627 if (!ar->monitor_present)
630 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
632 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
636 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
637 ar->monitor_present = false;
639 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface destroyed, vdev id: %d\n",
640 ar->monitor_vdev_id);
644 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
645 struct ieee80211_bss_conf *info)
649 lockdep_assert_held(&arvif->ar->conf_mutex);
651 if (!info->enable_beacon) {
652 ath10k_vdev_stop(arvif);
656 arvif->tx_seq_no = 0x1000;
658 ret = ath10k_vdev_start(arvif);
662 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
664 ath10k_warn("Failed to bring up VDEV: %d\n",
668 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d up\n", arvif->vdev_id);
671 static void ath10k_control_ibss(struct ath10k_vif *arvif,
672 struct ieee80211_bss_conf *info,
673 const u8 self_peer[ETH_ALEN])
677 lockdep_assert_held(&arvif->ar->conf_mutex);
679 if (!info->ibss_joined) {
680 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
682 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
683 self_peer, arvif->vdev_id, ret);
685 if (is_zero_ether_addr(arvif->u.ibss.bssid))
688 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
689 arvif->u.ibss.bssid);
691 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
692 arvif->u.ibss.bssid, arvif->vdev_id, ret);
696 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
701 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
703 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
704 self_peer, arvif->vdev_id, ret);
708 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
709 WMI_VDEV_PARAM_ATIM_WINDOW,
710 ATH10K_DEFAULT_ATIM);
712 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
713 arvif->vdev_id, ret);
717 * Review this when mac80211 gains per-interface powersave support.
719 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
721 struct ath10k_generic_iter *ar_iter = data;
722 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
723 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
724 enum wmi_sta_powersave_param param;
725 enum wmi_sta_ps_mode psmode;
728 lockdep_assert_held(&arvif->ar->conf_mutex);
730 if (vif->type != NL80211_IFTYPE_STATION)
733 if (conf->flags & IEEE80211_CONF_PS) {
734 psmode = WMI_STA_PS_MODE_ENABLED;
735 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
737 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
740 conf->dynamic_ps_timeout);
742 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
749 psmode = WMI_STA_PS_MODE_DISABLED;
752 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
755 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
756 psmode, arvif->vdev_id);
758 ath10k_dbg(ATH10K_DBG_MAC, "Set PS Mode: %d for VDEV: %d\n",
759 psmode, arvif->vdev_id);
762 /**********************/
763 /* Station management */
764 /**********************/
766 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
767 struct ath10k_vif *arvif,
768 struct ieee80211_sta *sta,
769 struct ieee80211_bss_conf *bss_conf,
770 struct wmi_peer_assoc_complete_arg *arg)
772 lockdep_assert_held(&ar->conf_mutex);
774 memcpy(arg->addr, sta->addr, ETH_ALEN);
775 arg->vdev_id = arvif->vdev_id;
776 arg->peer_aid = sta->aid;
777 arg->peer_flags |= WMI_PEER_AUTH;
779 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
781 * Seems FW have problems with Power Save in STA
782 * mode when we setup this parameter to high (eg. 5).
783 * Often we see that FW don't send NULL (with clean P flags)
784 * frame even there is info about buffered frames in beacons.
785 * Sometimes we have to wait more than 10 seconds before FW
786 * will wakeup. Often sending one ping from AP to our device
787 * just fail (more than 50%).
789 * Seems setting this FW parameter to 1 couse FW
790 * will check every beacon and will wakup immediately
791 * after detection buffered data.
793 arg->peer_listen_intval = 1;
795 arg->peer_listen_intval = ar->hw->conf.listen_interval;
797 arg->peer_num_spatial_streams = 1;
800 * The assoc capabilities are available only in managed mode.
802 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
803 arg->peer_caps = bss_conf->assoc_capability;
806 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
807 struct ath10k_vif *arvif,
808 struct wmi_peer_assoc_complete_arg *arg)
810 struct ieee80211_vif *vif = arvif->vif;
811 struct ieee80211_bss_conf *info = &vif->bss_conf;
812 struct cfg80211_bss *bss;
813 const u8 *rsnie = NULL;
814 const u8 *wpaie = NULL;
816 lockdep_assert_held(&ar->conf_mutex);
818 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
819 info->bssid, NULL, 0, 0, 0);
821 const struct cfg80211_bss_ies *ies;
824 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
826 ies = rcu_dereference(bss->ies);
828 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
829 WLAN_OUI_TYPE_MICROSOFT_WPA,
833 cfg80211_put_bss(ar->hw->wiphy, bss);
836 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
837 if (rsnie || wpaie) {
838 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
839 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
843 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
844 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
848 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
849 struct ieee80211_sta *sta,
850 struct wmi_peer_assoc_complete_arg *arg)
852 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
853 const struct ieee80211_supported_band *sband;
854 const struct ieee80211_rate *rates;
858 lockdep_assert_held(&ar->conf_mutex);
860 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
861 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
862 rates = sband->bitrates;
864 rateset->num_rates = 0;
866 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
870 rateset->rates[rateset->num_rates] = rates->hw_value;
871 rateset->num_rates++;
875 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
876 struct ieee80211_sta *sta,
877 struct wmi_peer_assoc_complete_arg *arg)
879 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
883 lockdep_assert_held(&ar->conf_mutex);
885 if (!ht_cap->ht_supported)
888 arg->peer_flags |= WMI_PEER_HT;
889 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
890 ht_cap->ampdu_factor)) - 1;
892 arg->peer_mpdu_density =
893 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
895 arg->peer_ht_caps = ht_cap->cap;
896 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
898 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
899 arg->peer_flags |= WMI_PEER_LDPC;
901 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
902 arg->peer_flags |= WMI_PEER_40MHZ;
903 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
906 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
907 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
909 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
910 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
912 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
913 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
914 arg->peer_flags |= WMI_PEER_STBC;
917 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
919 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
920 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
921 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
922 arg->peer_rate_caps |= stbc;
923 arg->peer_flags |= WMI_PEER_STBC;
926 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
927 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
929 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
930 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
931 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
932 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
933 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
934 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
937 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
938 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
939 else if (ht_cap->mcs.rx_mask[1])
940 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
942 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
943 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
944 arg->peer_ht_rates.rates[n++] = i;
946 arg->peer_ht_rates.num_rates = n;
947 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
949 ath10k_dbg(ATH10K_DBG_MAC, "mcs cnt %d nss %d\n",
950 arg->peer_ht_rates.num_rates,
951 arg->peer_num_spatial_streams);
954 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
955 struct ath10k_vif *arvif,
956 struct ieee80211_sta *sta,
957 struct ieee80211_bss_conf *bss_conf,
958 struct wmi_peer_assoc_complete_arg *arg)
963 lockdep_assert_held(&ar->conf_mutex);
966 arg->peer_flags |= WMI_PEER_QOS;
968 if (sta->wme && sta->uapsd_queues) {
969 ath10k_dbg(ATH10K_DBG_MAC, "uapsd_queues: 0x%X, max_sp: %d\n",
970 sta->uapsd_queues, sta->max_sp);
972 arg->peer_flags |= WMI_PEER_APSD;
973 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
975 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
976 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
977 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
978 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
979 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
980 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
981 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
982 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
983 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
984 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
985 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
986 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
989 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
990 max_sp = sta->max_sp;
992 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
994 WMI_AP_PS_PEER_PARAM_UAPSD,
997 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
999 WMI_AP_PS_PEER_PARAM_MAX_SP,
1002 /* TODO setup this based on STA listen interval and
1003 beacon interval. Currently we don't know
1004 sta->listen_interval - mac80211 patch required.
1005 Currently use 10 seconds */
1006 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1008 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1013 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1014 struct ath10k_vif *arvif,
1015 struct ieee80211_sta *sta,
1016 struct ieee80211_bss_conf *bss_conf,
1017 struct wmi_peer_assoc_complete_arg *arg)
1020 arg->peer_flags |= WMI_PEER_QOS;
1023 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1024 struct ieee80211_sta *sta,
1025 struct wmi_peer_assoc_complete_arg *arg)
1027 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1029 if (!vht_cap->vht_supported)
1032 arg->peer_flags |= WMI_PEER_VHT;
1034 arg->peer_vht_caps = vht_cap->cap;
1036 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1037 arg->peer_flags |= WMI_PEER_80MHZ;
1039 arg->peer_vht_rates.rx_max_rate =
1040 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1041 arg->peer_vht_rates.rx_mcs_set =
1042 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1043 arg->peer_vht_rates.tx_max_rate =
1044 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1045 arg->peer_vht_rates.tx_mcs_set =
1046 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1048 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer\n");
1051 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1052 struct ath10k_vif *arvif,
1053 struct ieee80211_sta *sta,
1054 struct ieee80211_bss_conf *bss_conf,
1055 struct wmi_peer_assoc_complete_arg *arg)
1057 switch (arvif->vdev_type) {
1058 case WMI_VDEV_TYPE_AP:
1059 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1061 case WMI_VDEV_TYPE_STA:
1062 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1069 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1070 struct ath10k_vif *arvif,
1071 struct ieee80211_sta *sta,
1072 struct wmi_peer_assoc_complete_arg *arg)
1074 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1076 /* FIXME: add VHT */
1078 switch (ar->hw->conf.chandef.chan->band) {
1079 case IEEE80211_BAND_2GHZ:
1080 if (sta->ht_cap.ht_supported) {
1081 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1082 phymode = MODE_11NG_HT40;
1084 phymode = MODE_11NG_HT20;
1090 case IEEE80211_BAND_5GHZ:
1091 if (sta->ht_cap.ht_supported) {
1092 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1093 phymode = MODE_11NA_HT40;
1095 phymode = MODE_11NA_HT20;
1105 arg->peer_phymode = phymode;
1106 WARN_ON(phymode == MODE_UNKNOWN);
1109 static int ath10k_peer_assoc(struct ath10k *ar,
1110 struct ath10k_vif *arvif,
1111 struct ieee80211_sta *sta,
1112 struct ieee80211_bss_conf *bss_conf)
1114 struct wmi_peer_assoc_complete_arg arg;
1116 lockdep_assert_held(&ar->conf_mutex);
1118 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1120 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1121 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1122 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1123 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1124 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1125 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1126 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1128 return ath10k_wmi_peer_assoc(ar, &arg);
1131 /* can be called only in mac80211 callbacks due to `key_count` usage */
1132 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1133 struct ieee80211_vif *vif,
1134 struct ieee80211_bss_conf *bss_conf)
1136 struct ath10k *ar = hw->priv;
1137 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1138 struct ieee80211_sta *ap_sta;
1141 lockdep_assert_held(&ar->conf_mutex);
1145 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1147 ath10k_warn("Failed to find station entry for %pM\n",
1153 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1155 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1162 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1165 ath10k_warn("VDEV: %d up failed: ret %d\n",
1166 arvif->vdev_id, ret);
1168 ath10k_dbg(ATH10K_DBG_MAC,
1169 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1170 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1176 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1177 struct ieee80211_vif *vif)
1179 struct ath10k *ar = hw->priv;
1180 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1183 lockdep_assert_held(&ar->conf_mutex);
1186 * For some reason, calling VDEV-DOWN before VDEV-STOP
1187 * makes the FW to send frames via HTT after disassociation.
1188 * No idea why this happens, even though VDEV-DOWN is supposed
1189 * to be analogous to link down, so just stop the VDEV.
1191 ret = ath10k_vdev_stop(arvif);
1193 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d stopped\n",
1197 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1198 * report beacons from previously associated network through HTT.
1199 * This in turn would spam mac80211 WARN_ON if we bring down all
1200 * interfaces as it expects there is no rx when no interface is
1203 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1205 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1206 arvif->vdev_id, ret);
1208 ath10k_wmi_flush_tx(ar);
1210 arvif->def_wep_key_index = 0;
1213 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1214 struct ieee80211_sta *sta)
1218 lockdep_assert_held(&ar->conf_mutex);
1220 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1222 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1226 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1228 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1235 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1236 struct ieee80211_sta *sta)
1240 lockdep_assert_held(&ar->conf_mutex);
1242 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1244 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1255 static int ath10k_update_channel_list(struct ath10k *ar)
1257 struct ieee80211_hw *hw = ar->hw;
1258 struct ieee80211_supported_band **bands;
1259 enum ieee80211_band band;
1260 struct ieee80211_channel *channel;
1261 struct wmi_scan_chan_list_arg arg = {0};
1262 struct wmi_channel_arg *ch;
1268 lockdep_assert_held(&ar->conf_mutex);
1270 bands = hw->wiphy->bands;
1271 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1275 for (i = 0; i < bands[band]->n_channels; i++) {
1276 if (bands[band]->channels[i].flags &
1277 IEEE80211_CHAN_DISABLED)
1284 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1285 arg.channels = kzalloc(len, GFP_KERNEL);
1290 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1294 for (i = 0; i < bands[band]->n_channels; i++) {
1295 channel = &bands[band]->channels[i];
1297 if (channel->flags & IEEE80211_CHAN_DISABLED)
1300 ch->allow_ht = true;
1302 /* FIXME: when should we really allow VHT? */
1303 ch->allow_vht = true;
1306 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1309 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1311 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1312 ch->passive = passive;
1314 ch->freq = channel->center_freq;
1315 ch->min_power = channel->max_power * 3;
1316 ch->max_power = channel->max_power * 4;
1317 ch->max_reg_power = channel->max_reg_power * 4;
1318 ch->max_antenna_gain = channel->max_antenna_gain;
1319 ch->reg_class_id = 0; /* FIXME */
1321 /* FIXME: why use only legacy modes, why not any
1322 * HT/VHT modes? Would that even make any
1324 if (channel->band == IEEE80211_BAND_2GHZ)
1325 ch->mode = MODE_11G;
1327 ch->mode = MODE_11A;
1329 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1332 ath10k_dbg(ATH10K_DBG_WMI,
1333 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1334 __func__, ch - arg.channels, arg.n_channels,
1335 ch->freq, ch->max_power, ch->max_reg_power,
1336 ch->max_antenna_gain, ch->mode);
1342 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1343 kfree(arg.channels);
1348 static void ath10k_regd_update(struct ath10k *ar)
1350 struct reg_dmn_pair_mapping *regpair;
1353 lockdep_assert_held(&ar->conf_mutex);
1355 ret = ath10k_update_channel_list(ar);
1357 ath10k_warn("could not update channel list (%d)\n", ret);
1359 regpair = ar->ath_common.regulatory.regpair;
1361 /* Target allows setting up per-band regdomain but ath_common provides
1362 * a combined one only */
1363 ret = ath10k_wmi_pdev_set_regdomain(ar,
1364 regpair->regDmnEnum,
1365 regpair->regDmnEnum, /* 2ghz */
1366 regpair->regDmnEnum, /* 5ghz */
1367 regpair->reg_2ghz_ctl,
1368 regpair->reg_5ghz_ctl);
1370 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1373 static void ath10k_reg_notifier(struct wiphy *wiphy,
1374 struct regulatory_request *request)
1376 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1377 struct ath10k *ar = hw->priv;
1379 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1381 mutex_lock(&ar->conf_mutex);
1382 if (ar->state == ATH10K_STATE_ON)
1383 ath10k_regd_update(ar);
1384 mutex_unlock(&ar->conf_mutex);
1392 * Frames sent to the FW have to be in "Native Wifi" format.
1393 * Strip the QoS field from the 802.11 header.
1395 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1396 struct ieee80211_tx_control *control,
1397 struct sk_buff *skb)
1399 struct ieee80211_hdr *hdr = (void *)skb->data;
1402 if (!ieee80211_is_data_qos(hdr->frame_control))
1405 qos_ctl = ieee80211_get_qos_ctl(hdr);
1406 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1407 skb->data, (void *)qos_ctl - (void *)skb->data);
1408 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1411 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1413 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1414 struct ieee80211_vif *vif = info->control.vif;
1415 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1416 struct ath10k *ar = arvif->ar;
1417 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1418 struct ieee80211_key_conf *key = info->control.hw_key;
1421 /* TODO AP mode should be implemented */
1422 if (vif->type != NL80211_IFTYPE_STATION)
1425 if (!ieee80211_has_protected(hdr->frame_control))
1431 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1432 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1435 if (key->keyidx == arvif->def_wep_key_index)
1438 ath10k_dbg(ATH10K_DBG_MAC, "new wep keyidx will be %d\n", key->keyidx);
1440 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1441 WMI_VDEV_PARAM_DEF_KEYID,
1444 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1448 arvif->def_wep_key_index = key->keyidx;
1451 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1453 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1454 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1455 struct ieee80211_vif *vif = info->control.vif;
1456 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1458 /* This is case only for P2P_GO */
1459 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1460 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1463 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1464 spin_lock_bh(&ar->data_lock);
1465 if (arvif->u.ap.noa_data)
1466 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1468 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1469 arvif->u.ap.noa_data,
1470 arvif->u.ap.noa_len);
1471 spin_unlock_bh(&ar->data_lock);
1475 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1477 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1480 if (ieee80211_is_mgmt(hdr->frame_control))
1481 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1482 else if (ieee80211_is_nullfunc(hdr->frame_control))
1483 /* FW does not report tx status properly for NullFunc frames
1484 * unless they are sent through mgmt tx path. mac80211 sends
1485 * those frames when it detects link/beacon loss and depends on
1486 * the tx status to be correct. */
1487 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1489 ret = ath10k_htt_tx(&ar->htt, skb);
1492 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1493 ieee80211_free_txskb(ar->hw, skb);
1497 void ath10k_offchan_tx_purge(struct ath10k *ar)
1499 struct sk_buff *skb;
1502 skb = skb_dequeue(&ar->offchan_tx_queue);
1506 ieee80211_free_txskb(ar->hw, skb);
1510 void ath10k_offchan_tx_work(struct work_struct *work)
1512 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1513 struct ath10k_peer *peer;
1514 struct ieee80211_hdr *hdr;
1515 struct sk_buff *skb;
1516 const u8 *peer_addr;
1520 /* FW requirement: We must create a peer before FW will send out
1521 * an offchannel frame. Otherwise the frame will be stuck and
1522 * never transmitted. We delete the peer upon tx completion.
1523 * It is unlikely that a peer for offchannel tx will already be
1524 * present. However it may be in some rare cases so account for that.
1525 * Otherwise we might remove a legitimate peer and break stuff. */
1528 skb = skb_dequeue(&ar->offchan_tx_queue);
1532 mutex_lock(&ar->conf_mutex);
1534 ath10k_dbg(ATH10K_DBG_MAC, "processing offchannel skb %p\n",
1537 hdr = (struct ieee80211_hdr *)skb->data;
1538 peer_addr = ieee80211_get_DA(hdr);
1539 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1541 spin_lock_bh(&ar->data_lock);
1542 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1543 spin_unlock_bh(&ar->data_lock);
1546 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1547 peer_addr, vdev_id);
1550 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1552 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1553 peer_addr, vdev_id, ret);
1556 spin_lock_bh(&ar->data_lock);
1557 INIT_COMPLETION(ar->offchan_tx_completed);
1558 ar->offchan_tx_skb = skb;
1559 spin_unlock_bh(&ar->data_lock);
1561 ath10k_tx_htt(ar, skb);
1563 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1566 ath10k_warn("timed out waiting for offchannel skb %p\n",
1570 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1572 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1573 peer_addr, vdev_id, ret);
1576 mutex_unlock(&ar->conf_mutex);
1585 * This gets called if we dont get a heart-beat during scan.
1586 * This may indicate the FW has hung and we need to abort the
1587 * scan manually to prevent cancel_hw_scan() from deadlocking
1589 void ath10k_reset_scan(unsigned long ptr)
1591 struct ath10k *ar = (struct ath10k *)ptr;
1593 spin_lock_bh(&ar->data_lock);
1594 if (!ar->scan.in_progress) {
1595 spin_unlock_bh(&ar->data_lock);
1599 ath10k_warn("scan timeout. resetting. fw issue?\n");
1601 if (ar->scan.is_roc)
1602 ieee80211_remain_on_channel_expired(ar->hw);
1604 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1606 ar->scan.in_progress = false;
1607 complete_all(&ar->scan.completed);
1608 spin_unlock_bh(&ar->data_lock);
1611 static int ath10k_abort_scan(struct ath10k *ar)
1613 struct wmi_stop_scan_arg arg = {
1614 .req_id = 1, /* FIXME */
1615 .req_type = WMI_SCAN_STOP_ONE,
1616 .u.scan_id = ATH10K_SCAN_ID,
1620 lockdep_assert_held(&ar->conf_mutex);
1622 del_timer_sync(&ar->scan.timeout);
1624 spin_lock_bh(&ar->data_lock);
1625 if (!ar->scan.in_progress) {
1626 spin_unlock_bh(&ar->data_lock);
1630 ar->scan.aborting = true;
1631 spin_unlock_bh(&ar->data_lock);
1633 ret = ath10k_wmi_stop_scan(ar, &arg);
1635 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1636 spin_lock_bh(&ar->data_lock);
1637 ar->scan.in_progress = false;
1638 ath10k_offchan_tx_purge(ar);
1639 spin_unlock_bh(&ar->data_lock);
1643 ath10k_wmi_flush_tx(ar);
1645 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1647 ath10k_warn("timed out while waiting for scan to stop\n");
1649 /* scan completion may be done right after we timeout here, so let's
1650 * check the in_progress and tell mac80211 scan is completed. if we
1651 * don't do that and FW fails to send us scan completion indication
1652 * then userspace won't be able to scan anymore */
1655 spin_lock_bh(&ar->data_lock);
1656 if (ar->scan.in_progress) {
1657 ath10k_warn("could not stop scan. its still in progress\n");
1658 ar->scan.in_progress = false;
1659 ath10k_offchan_tx_purge(ar);
1662 spin_unlock_bh(&ar->data_lock);
1667 static int ath10k_start_scan(struct ath10k *ar,
1668 const struct wmi_start_scan_arg *arg)
1672 lockdep_assert_held(&ar->conf_mutex);
1674 ret = ath10k_wmi_start_scan(ar, arg);
1678 /* make sure we submit the command so the completion
1679 * timeout makes sense */
1680 ath10k_wmi_flush_tx(ar);
1682 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1684 ath10k_abort_scan(ar);
1688 /* the scan can complete earlier, before we even
1689 * start the timer. in that case the timer handler
1690 * checks ar->scan.in_progress and bails out if its
1691 * false. Add a 200ms margin to account event/command
1693 mod_timer(&ar->scan.timeout, jiffies +
1694 msecs_to_jiffies(arg->max_scan_time+200));
1698 /**********************/
1699 /* mac80211 callbacks */
1700 /**********************/
1702 static void ath10k_tx(struct ieee80211_hw *hw,
1703 struct ieee80211_tx_control *control,
1704 struct sk_buff *skb)
1706 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1707 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1708 struct ath10k *ar = hw->priv;
1709 struct ath10k_vif *arvif = NULL;
1713 if (info->control.vif) {
1714 arvif = ath10k_vif_to_arvif(info->control.vif);
1715 vdev_id = arvif->vdev_id;
1716 } else if (ar->monitor_enabled) {
1717 vdev_id = ar->monitor_vdev_id;
1720 /* We should disable CCK RATE due to P2P */
1721 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1722 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1724 /* we must calculate tid before we apply qos workaround
1725 * as we'd lose the qos control field */
1726 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1727 if (ieee80211_is_data_qos(hdr->frame_control) &&
1728 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1729 u8 *qc = ieee80211_get_qos_ctl(hdr);
1730 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1733 /* it makes no sense to process injected frames like that */
1734 if (info->control.vif &&
1735 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1736 ath10k_tx_h_qos_workaround(hw, control, skb);
1737 ath10k_tx_h_update_wep_key(skb);
1738 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1739 ath10k_tx_h_seq_no(skb);
1742 memset(ATH10K_SKB_CB(skb), 0, sizeof(*ATH10K_SKB_CB(skb)));
1743 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1744 ATH10K_SKB_CB(skb)->htt.tid = tid;
1746 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1747 spin_lock_bh(&ar->data_lock);
1748 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1749 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1750 spin_unlock_bh(&ar->data_lock);
1752 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1754 skb_queue_tail(&ar->offchan_tx_queue, skb);
1755 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1759 ath10k_tx_htt(ar, skb);
1763 * Initialize various parameters with default vaules.
1765 void ath10k_halt(struct ath10k *ar)
1767 lockdep_assert_held(&ar->conf_mutex);
1769 del_timer_sync(&ar->scan.timeout);
1770 ath10k_offchan_tx_purge(ar);
1771 ath10k_peer_cleanup_all(ar);
1772 ath10k_core_stop(ar);
1773 ath10k_hif_power_down(ar);
1775 spin_lock_bh(&ar->data_lock);
1776 if (ar->scan.in_progress) {
1777 del_timer(&ar->scan.timeout);
1778 ar->scan.in_progress = false;
1779 ieee80211_scan_completed(ar->hw, true);
1781 spin_unlock_bh(&ar->data_lock);
1784 static int ath10k_start(struct ieee80211_hw *hw)
1786 struct ath10k *ar = hw->priv;
1789 mutex_lock(&ar->conf_mutex);
1791 if (ar->state != ATH10K_STATE_OFF &&
1792 ar->state != ATH10K_STATE_RESTARTING) {
1797 ret = ath10k_hif_power_up(ar);
1799 ath10k_err("could not init hif (%d)\n", ret);
1800 ar->state = ATH10K_STATE_OFF;
1804 ret = ath10k_core_start(ar);
1806 ath10k_err("could not init core (%d)\n", ret);
1807 ath10k_hif_power_down(ar);
1808 ar->state = ATH10K_STATE_OFF;
1812 if (ar->state == ATH10K_STATE_OFF)
1813 ar->state = ATH10K_STATE_ON;
1814 else if (ar->state == ATH10K_STATE_RESTARTING)
1815 ar->state = ATH10K_STATE_RESTARTED;
1817 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1819 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1822 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1824 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1827 ath10k_regd_update(ar);
1830 mutex_unlock(&ar->conf_mutex);
1834 static void ath10k_stop(struct ieee80211_hw *hw)
1836 struct ath10k *ar = hw->priv;
1838 mutex_lock(&ar->conf_mutex);
1839 if (ar->state == ATH10K_STATE_ON ||
1840 ar->state == ATH10K_STATE_RESTARTED ||
1841 ar->state == ATH10K_STATE_WEDGED)
1844 ar->state = ATH10K_STATE_OFF;
1845 mutex_unlock(&ar->conf_mutex);
1847 cancel_work_sync(&ar->offchan_tx_work);
1848 cancel_work_sync(&ar->restart_work);
1851 static void ath10k_config_ps(struct ath10k *ar)
1853 struct ath10k_generic_iter ar_iter;
1855 lockdep_assert_held(&ar->conf_mutex);
1857 /* During HW reconfiguration mac80211 reports all interfaces that were
1858 * running until reconfiguration was started. Since FW doesn't have any
1859 * vdevs at this point we must not iterate over this interface list.
1860 * This setting will be updated upon add_interface(). */
1861 if (ar->state == ATH10K_STATE_RESTARTED)
1864 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1867 ieee80211_iterate_active_interfaces_atomic(
1868 ar->hw, IEEE80211_IFACE_ITER_NORMAL,
1869 ath10k_ps_iter, &ar_iter);
1872 ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
1875 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1877 struct ath10k *ar = hw->priv;
1878 struct ieee80211_conf *conf = &hw->conf;
1881 mutex_lock(&ar->conf_mutex);
1883 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1884 ath10k_dbg(ATH10K_DBG_MAC, "Config channel %d mhz\n",
1885 conf->chandef.chan->center_freq);
1886 spin_lock_bh(&ar->data_lock);
1887 ar->rx_channel = conf->chandef.chan;
1888 spin_unlock_bh(&ar->data_lock);
1891 if (changed & IEEE80211_CONF_CHANGE_PS)
1892 ath10k_config_ps(ar);
1894 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1895 if (conf->flags & IEEE80211_CONF_MONITOR)
1896 ret = ath10k_monitor_create(ar);
1898 ret = ath10k_monitor_destroy(ar);
1901 ath10k_wmi_flush_tx(ar);
1902 mutex_unlock(&ar->conf_mutex);
1908 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1909 * because we will send mgmt frames without CCK. This requirement
1910 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1913 static int ath10k_add_interface(struct ieee80211_hw *hw,
1914 struct ieee80211_vif *vif)
1916 struct ath10k *ar = hw->priv;
1917 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1918 enum wmi_sta_powersave_param param;
1923 mutex_lock(&ar->conf_mutex);
1925 memset(arvif, 0, sizeof(*arvif));
1930 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1931 ath10k_warn("Only one monitor interface allowed\n");
1936 bit = ffs(ar->free_vdev_map);
1942 arvif->vdev_id = bit - 1;
1943 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1944 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1947 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1949 switch (vif->type) {
1950 case NL80211_IFTYPE_UNSPECIFIED:
1951 case NL80211_IFTYPE_STATION:
1952 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1954 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1956 case NL80211_IFTYPE_ADHOC:
1957 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1959 case NL80211_IFTYPE_AP:
1960 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1963 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1965 case NL80211_IFTYPE_MONITOR:
1966 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1973 ath10k_dbg(ATH10K_DBG_MAC, "Add interface: id %d type %d subtype %d\n",
1974 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1976 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1977 arvif->vdev_subtype, vif->addr);
1979 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1983 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
1984 arvif->def_wep_key_index);
1986 ath10k_warn("Failed to set default keyid: %d\n", ret);
1988 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1989 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
1990 ATH10K_HW_TXRX_NATIVE_WIFI);
1992 ath10k_warn("Failed to set TX encap: %d\n", ret);
1994 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1995 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
1997 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2002 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2003 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2004 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2005 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2008 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2010 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2011 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2012 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2015 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2017 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2018 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2019 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2022 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2025 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2027 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2028 arvif->vdev_id, ret);
2030 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2032 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2033 arvif->vdev_id, ret);
2035 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2036 ar->monitor_present = true;
2039 mutex_unlock(&ar->conf_mutex);
2043 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2044 struct ieee80211_vif *vif)
2046 struct ath10k *ar = hw->priv;
2047 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2050 mutex_lock(&ar->conf_mutex);
2052 ath10k_dbg(ATH10K_DBG_MAC, "Remove interface: id %d\n", arvif->vdev_id);
2054 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2056 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2057 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2059 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2061 kfree(arvif->u.ap.noa_data);
2064 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2066 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2068 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2069 ar->monitor_present = false;
2071 ath10k_peer_cleanup(ar, arvif->vdev_id);
2073 mutex_unlock(&ar->conf_mutex);
2077 * FIXME: Has to be verified.
2079 #define SUPPORTED_FILTERS \
2080 (FIF_PROMISC_IN_BSS | \
2085 FIF_BCN_PRBRESP_PROMISC | \
2089 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2090 unsigned int changed_flags,
2091 unsigned int *total_flags,
2094 struct ath10k *ar = hw->priv;
2097 mutex_lock(&ar->conf_mutex);
2099 changed_flags &= SUPPORTED_FILTERS;
2100 *total_flags &= SUPPORTED_FILTERS;
2101 ar->filter_flags = *total_flags;
2103 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2104 !ar->monitor_enabled) {
2105 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2107 ath10k_warn("Unable to start monitor mode\n");
2109 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode started\n");
2110 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2111 ar->monitor_enabled) {
2112 ret = ath10k_monitor_stop(ar);
2114 ath10k_warn("Unable to stop monitor mode\n");
2116 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode stopped\n");
2119 mutex_unlock(&ar->conf_mutex);
2122 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2123 struct ieee80211_vif *vif,
2124 struct ieee80211_bss_conf *info,
2127 struct ath10k *ar = hw->priv;
2128 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2131 mutex_lock(&ar->conf_mutex);
2133 if (changed & BSS_CHANGED_IBSS)
2134 ath10k_control_ibss(arvif, info, vif->addr);
2136 if (changed & BSS_CHANGED_BEACON_INT) {
2137 arvif->beacon_interval = info->beacon_int;
2138 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2139 WMI_VDEV_PARAM_BEACON_INTERVAL,
2140 arvif->beacon_interval);
2142 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2145 ath10k_dbg(ATH10K_DBG_MAC,
2146 "Beacon interval: %d set for VDEV: %d\n",
2147 arvif->beacon_interval, arvif->vdev_id);
2150 if (changed & BSS_CHANGED_BEACON) {
2151 ret = ath10k_wmi_pdev_set_param(ar,
2152 WMI_PDEV_PARAM_BEACON_TX_MODE,
2153 WMI_BEACON_STAGGERED_MODE);
2155 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2158 ath10k_dbg(ATH10K_DBG_MAC,
2159 "Set staggered beacon mode for VDEV: %d\n",
2163 if (changed & BSS_CHANGED_BEACON_INFO) {
2164 arvif->dtim_period = info->dtim_period;
2166 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2167 WMI_VDEV_PARAM_DTIM_PERIOD,
2168 arvif->dtim_period);
2170 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2173 ath10k_dbg(ATH10K_DBG_MAC,
2174 "Set dtim period: %d for VDEV: %d\n",
2175 arvif->dtim_period, arvif->vdev_id);
2178 if (changed & BSS_CHANGED_SSID &&
2179 vif->type == NL80211_IFTYPE_AP) {
2180 arvif->u.ap.ssid_len = info->ssid_len;
2182 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2183 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2186 if (changed & BSS_CHANGED_BSSID) {
2187 if (!is_zero_ether_addr(info->bssid)) {
2188 ret = ath10k_peer_create(ar, arvif->vdev_id,
2191 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2192 info->bssid, arvif->vdev_id);
2194 ath10k_dbg(ATH10K_DBG_MAC,
2195 "Added peer: %pM for VDEV: %d\n",
2196 info->bssid, arvif->vdev_id);
2199 if (vif->type == NL80211_IFTYPE_STATION) {
2201 * this is never erased as we it for crypto key
2202 * clearing; this is FW requirement
2204 memcpy(arvif->u.sta.bssid, info->bssid,
2207 ret = ath10k_vdev_start(arvif);
2209 ath10k_dbg(ATH10K_DBG_MAC,
2210 "VDEV: %d started with BSSID: %pM\n",
2211 arvif->vdev_id, info->bssid);
2215 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2216 * so driver need to store it. It is needed when leaving
2217 * IBSS in order to remove BSSID peer.
2219 if (vif->type == NL80211_IFTYPE_ADHOC)
2220 memcpy(arvif->u.ibss.bssid, info->bssid,
2225 if (changed & BSS_CHANGED_BEACON_ENABLED)
2226 ath10k_control_beaconing(arvif, info);
2228 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2230 if (info->use_cts_prot)
2235 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2236 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2239 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2242 ath10k_dbg(ATH10K_DBG_MAC,
2243 "Set CTS prot: %d for VDEV: %d\n",
2244 cts_prot, arvif->vdev_id);
2247 if (changed & BSS_CHANGED_ERP_SLOT) {
2249 if (info->use_short_slot)
2250 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2253 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2255 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2256 WMI_VDEV_PARAM_SLOT_TIME,
2259 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2262 ath10k_dbg(ATH10K_DBG_MAC,
2263 "Set slottime: %d for VDEV: %d\n",
2264 slottime, arvif->vdev_id);
2267 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2269 if (info->use_short_preamble)
2270 preamble = WMI_VDEV_PREAMBLE_SHORT;
2272 preamble = WMI_VDEV_PREAMBLE_LONG;
2274 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2275 WMI_VDEV_PARAM_PREAMBLE,
2278 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2281 ath10k_dbg(ATH10K_DBG_MAC,
2282 "Set preamble: %d for VDEV: %d\n",
2283 preamble, arvif->vdev_id);
2286 if (changed & BSS_CHANGED_ASSOC) {
2288 ath10k_bss_assoc(hw, vif, info);
2291 mutex_unlock(&ar->conf_mutex);
2294 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2295 struct ieee80211_vif *vif,
2296 struct cfg80211_scan_request *req)
2298 struct ath10k *ar = hw->priv;
2299 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2300 struct wmi_start_scan_arg arg;
2304 mutex_lock(&ar->conf_mutex);
2306 spin_lock_bh(&ar->data_lock);
2307 if (ar->scan.in_progress) {
2308 spin_unlock_bh(&ar->data_lock);
2313 INIT_COMPLETION(ar->scan.started);
2314 INIT_COMPLETION(ar->scan.completed);
2315 ar->scan.in_progress = true;
2316 ar->scan.aborting = false;
2317 ar->scan.is_roc = false;
2318 ar->scan.vdev_id = arvif->vdev_id;
2319 spin_unlock_bh(&ar->data_lock);
2321 memset(&arg, 0, sizeof(arg));
2322 ath10k_wmi_start_scan_init(ar, &arg);
2323 arg.vdev_id = arvif->vdev_id;
2324 arg.scan_id = ATH10K_SCAN_ID;
2327 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2330 arg.ie_len = req->ie_len;
2331 memcpy(arg.ie, req->ie, arg.ie_len);
2335 arg.n_ssids = req->n_ssids;
2336 for (i = 0; i < arg.n_ssids; i++) {
2337 arg.ssids[i].len = req->ssids[i].ssid_len;
2338 arg.ssids[i].ssid = req->ssids[i].ssid;
2341 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2344 if (req->n_channels) {
2345 arg.n_channels = req->n_channels;
2346 for (i = 0; i < arg.n_channels; i++)
2347 arg.channels[i] = req->channels[i]->center_freq;
2350 ret = ath10k_start_scan(ar, &arg);
2352 ath10k_warn("could not start hw scan (%d)\n", ret);
2353 spin_lock_bh(&ar->data_lock);
2354 ar->scan.in_progress = false;
2355 spin_unlock_bh(&ar->data_lock);
2359 mutex_unlock(&ar->conf_mutex);
2363 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2364 struct ieee80211_vif *vif)
2366 struct ath10k *ar = hw->priv;
2369 mutex_lock(&ar->conf_mutex);
2370 ret = ath10k_abort_scan(ar);
2372 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2374 ieee80211_scan_completed(hw, 1 /* aborted */);
2376 mutex_unlock(&ar->conf_mutex);
2379 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2380 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2381 struct ieee80211_key_conf *key)
2383 struct ath10k *ar = hw->priv;
2384 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2385 struct ath10k_peer *peer;
2386 const u8 *peer_addr;
2387 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2388 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2391 if (key->keyidx > WMI_MAX_KEY_INDEX)
2394 mutex_lock(&ar->conf_mutex);
2397 peer_addr = sta->addr;
2398 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2399 peer_addr = vif->bss_conf.bssid;
2401 peer_addr = vif->addr;
2403 key->hw_key_idx = key->keyidx;
2405 /* the peer should not disappear in mid-way (unless FW goes awry) since
2406 * we already hold conf_mutex. we just make sure its there now. */
2407 spin_lock_bh(&ar->data_lock);
2408 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2409 spin_unlock_bh(&ar->data_lock);
2412 if (cmd == SET_KEY) {
2413 ath10k_warn("cannot install key for non-existent peer %pM\n",
2418 /* if the peer doesn't exist there is no key to disable
2426 arvif->wep_keys[key->keyidx] = key;
2428 arvif->wep_keys[key->keyidx] = NULL;
2430 if (cmd == DISABLE_KEY)
2431 ath10k_clear_vdev_key(arvif, key);
2434 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2436 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2440 spin_lock_bh(&ar->data_lock);
2441 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2442 if (peer && cmd == SET_KEY)
2443 peer->keys[key->keyidx] = key;
2444 else if (peer && cmd == DISABLE_KEY)
2445 peer->keys[key->keyidx] = NULL;
2446 else if (peer == NULL)
2447 /* impossible unless FW goes crazy */
2448 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2449 spin_unlock_bh(&ar->data_lock);
2452 mutex_unlock(&ar->conf_mutex);
2456 static int ath10k_sta_state(struct ieee80211_hw *hw,
2457 struct ieee80211_vif *vif,
2458 struct ieee80211_sta *sta,
2459 enum ieee80211_sta_state old_state,
2460 enum ieee80211_sta_state new_state)
2462 struct ath10k *ar = hw->priv;
2463 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2466 mutex_lock(&ar->conf_mutex);
2468 if (old_state == IEEE80211_STA_NOTEXIST &&
2469 new_state == IEEE80211_STA_NONE &&
2470 vif->type != NL80211_IFTYPE_STATION) {
2472 * New station addition.
2474 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2476 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2477 sta->addr, arvif->vdev_id);
2479 ath10k_dbg(ATH10K_DBG_MAC,
2480 "Added peer: %pM for VDEV: %d\n",
2481 sta->addr, arvif->vdev_id);
2482 } else if ((old_state == IEEE80211_STA_NONE &&
2483 new_state == IEEE80211_STA_NOTEXIST)) {
2485 * Existing station deletion.
2487 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2489 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2490 sta->addr, arvif->vdev_id);
2492 ath10k_dbg(ATH10K_DBG_MAC,
2493 "Removed peer: %pM for VDEV: %d\n",
2494 sta->addr, arvif->vdev_id);
2496 if (vif->type == NL80211_IFTYPE_STATION)
2497 ath10k_bss_disassoc(hw, vif);
2498 } else if (old_state == IEEE80211_STA_AUTH &&
2499 new_state == IEEE80211_STA_ASSOC &&
2500 (vif->type == NL80211_IFTYPE_AP ||
2501 vif->type == NL80211_IFTYPE_ADHOC)) {
2505 ret = ath10k_station_assoc(ar, arvif, sta);
2507 ath10k_warn("Failed to associate station: %pM\n",
2510 ath10k_dbg(ATH10K_DBG_MAC,
2511 "Station %pM moved to assoc state\n",
2513 } else if (old_state == IEEE80211_STA_ASSOC &&
2514 new_state == IEEE80211_STA_AUTH &&
2515 (vif->type == NL80211_IFTYPE_AP ||
2516 vif->type == NL80211_IFTYPE_ADHOC)) {
2520 ret = ath10k_station_disassoc(ar, arvif, sta);
2522 ath10k_warn("Failed to disassociate station: %pM\n",
2525 ath10k_dbg(ATH10K_DBG_MAC,
2526 "Station %pM moved to disassociated state\n",
2530 mutex_unlock(&ar->conf_mutex);
2534 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2535 u16 ac, bool enable)
2537 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2541 lockdep_assert_held(&ar->conf_mutex);
2543 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2547 case IEEE80211_AC_VO:
2548 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2549 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2551 case IEEE80211_AC_VI:
2552 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2553 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2555 case IEEE80211_AC_BE:
2556 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2557 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2559 case IEEE80211_AC_BK:
2560 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2561 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2566 arvif->u.sta.uapsd |= value;
2568 arvif->u.sta.uapsd &= ~value;
2570 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2571 WMI_STA_PS_PARAM_UAPSD,
2572 arvif->u.sta.uapsd);
2574 ath10k_warn("could not set uapsd params %d\n", ret);
2578 if (arvif->u.sta.uapsd)
2579 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2581 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2583 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2584 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2587 ath10k_warn("could not set rx wake param %d\n", ret);
2593 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2594 struct ieee80211_vif *vif, u16 ac,
2595 const struct ieee80211_tx_queue_params *params)
2597 struct ath10k *ar = hw->priv;
2598 struct wmi_wmm_params_arg *p = NULL;
2601 mutex_lock(&ar->conf_mutex);
2604 case IEEE80211_AC_VO:
2605 p = &ar->wmm_params.ac_vo;
2607 case IEEE80211_AC_VI:
2608 p = &ar->wmm_params.ac_vi;
2610 case IEEE80211_AC_BE:
2611 p = &ar->wmm_params.ac_be;
2613 case IEEE80211_AC_BK:
2614 p = &ar->wmm_params.ac_bk;
2623 p->cwmin = params->cw_min;
2624 p->cwmax = params->cw_max;
2625 p->aifs = params->aifs;
2628 * The channel time duration programmed in the HW is in absolute
2629 * microseconds, while mac80211 gives the txop in units of
2632 p->txop = params->txop * 32;
2634 /* FIXME: FW accepts wmm params per hw, not per vif */
2635 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2637 ath10k_warn("could not set wmm params %d\n", ret);
2641 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2643 ath10k_warn("could not set sta uapsd %d\n", ret);
2646 mutex_unlock(&ar->conf_mutex);
2650 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2652 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2653 struct ieee80211_vif *vif,
2654 struct ieee80211_channel *chan,
2656 enum ieee80211_roc_type type)
2658 struct ath10k *ar = hw->priv;
2659 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2660 struct wmi_start_scan_arg arg;
2663 mutex_lock(&ar->conf_mutex);
2665 spin_lock_bh(&ar->data_lock);
2666 if (ar->scan.in_progress) {
2667 spin_unlock_bh(&ar->data_lock);
2672 INIT_COMPLETION(ar->scan.started);
2673 INIT_COMPLETION(ar->scan.completed);
2674 INIT_COMPLETION(ar->scan.on_channel);
2675 ar->scan.in_progress = true;
2676 ar->scan.aborting = false;
2677 ar->scan.is_roc = true;
2678 ar->scan.vdev_id = arvif->vdev_id;
2679 ar->scan.roc_freq = chan->center_freq;
2680 spin_unlock_bh(&ar->data_lock);
2682 memset(&arg, 0, sizeof(arg));
2683 ath10k_wmi_start_scan_init(ar, &arg);
2684 arg.vdev_id = arvif->vdev_id;
2685 arg.scan_id = ATH10K_SCAN_ID;
2687 arg.channels[0] = chan->center_freq;
2688 arg.dwell_time_active = duration;
2689 arg.dwell_time_passive = duration;
2690 arg.max_scan_time = 2 * duration;
2691 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2692 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2694 ret = ath10k_start_scan(ar, &arg);
2696 ath10k_warn("could not start roc scan (%d)\n", ret);
2697 spin_lock_bh(&ar->data_lock);
2698 ar->scan.in_progress = false;
2699 spin_unlock_bh(&ar->data_lock);
2703 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2705 ath10k_warn("could not switch to channel for roc scan\n");
2706 ath10k_abort_scan(ar);
2713 mutex_unlock(&ar->conf_mutex);
2717 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2719 struct ath10k *ar = hw->priv;
2721 mutex_lock(&ar->conf_mutex);
2722 ath10k_abort_scan(ar);
2723 mutex_unlock(&ar->conf_mutex);
2729 * Both RTS and Fragmentation threshold are interface-specific
2730 * in ath10k, but device-specific in mac80211.
2732 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2734 struct ath10k_generic_iter *ar_iter = data;
2735 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2736 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2738 lockdep_assert_held(&arvif->ar->conf_mutex);
2740 /* During HW reconfiguration mac80211 reports all interfaces that were
2741 * running until reconfiguration was started. Since FW doesn't have any
2742 * vdevs at this point we must not iterate over this interface list.
2743 * This setting will be updated upon add_interface(). */
2744 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2747 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
2749 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2752 ath10k_dbg(ATH10K_DBG_MAC,
2753 "Set RTS threshold: %d for VDEV: %d\n",
2754 rts, arvif->vdev_id);
2757 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2759 struct ath10k_generic_iter ar_iter;
2760 struct ath10k *ar = hw->priv;
2762 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2765 mutex_lock(&ar->conf_mutex);
2766 ieee80211_iterate_active_interfaces_atomic(
2767 hw, IEEE80211_IFACE_ITER_NORMAL,
2768 ath10k_set_rts_iter, &ar_iter);
2769 mutex_unlock(&ar->conf_mutex);
2774 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2776 struct ath10k_generic_iter *ar_iter = data;
2777 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2778 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2780 lockdep_assert_held(&arvif->ar->conf_mutex);
2782 /* During HW reconfiguration mac80211 reports all interfaces that were
2783 * running until reconfiguration was started. Since FW doesn't have any
2784 * vdevs at this point we must not iterate over this interface list.
2785 * This setting will be updated upon add_interface(). */
2786 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2789 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
2791 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2794 ath10k_dbg(ATH10K_DBG_MAC,
2795 "Set frag threshold: %d for VDEV: %d\n",
2796 frag, arvif->vdev_id);
2799 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2801 struct ath10k_generic_iter ar_iter;
2802 struct ath10k *ar = hw->priv;
2804 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2807 mutex_lock(&ar->conf_mutex);
2808 ieee80211_iterate_active_interfaces_atomic(
2809 hw, IEEE80211_IFACE_ITER_NORMAL,
2810 ath10k_set_frag_iter, &ar_iter);
2811 mutex_unlock(&ar->conf_mutex);
2816 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2818 struct ath10k *ar = hw->priv;
2822 /* mac80211 doesn't care if we really xmit queued frames or not
2823 * we'll collect those frames either way if we stop/delete vdevs */
2827 mutex_lock(&ar->conf_mutex);
2829 if (ar->state == ATH10K_STATE_WEDGED)
2832 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
2835 spin_lock_bh(&ar->htt.tx_lock);
2836 empty = bitmap_empty(ar->htt.used_msdu_ids,
2837 ar->htt.max_num_pending_tx);
2838 spin_unlock_bh(&ar->htt.tx_lock);
2840 skip = (ar->state == ATH10K_STATE_WEDGED);
2843 }), ATH10K_FLUSH_TIMEOUT_HZ);
2845 if (ret <= 0 || skip)
2846 ath10k_warn("tx not flushed\n");
2849 mutex_unlock(&ar->conf_mutex);
2852 /* TODO: Implement this function properly
2853 * For now it is needed to reply to Probe Requests in IBSS mode.
2854 * Propably we need this information from FW.
2856 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2862 static int ath10k_suspend(struct ieee80211_hw *hw,
2863 struct cfg80211_wowlan *wowlan)
2865 struct ath10k *ar = hw->priv;
2868 ar->is_target_paused = false;
2870 ret = ath10k_wmi_pdev_suspend_target(ar);
2872 ath10k_warn("could not suspend target (%d)\n", ret);
2876 ret = wait_event_interruptible_timeout(ar->event_queue,
2877 ar->is_target_paused == true,
2880 ath10k_warn("suspend interrupted (%d)\n", ret);
2882 } else if (ret == 0) {
2883 ath10k_warn("suspend timed out - target pause event never came\n");
2887 ret = ath10k_hif_suspend(ar);
2889 ath10k_warn("could not suspend hif (%d)\n", ret);
2895 ret = ath10k_wmi_pdev_resume_target(ar);
2897 ath10k_warn("could not resume target (%d)\n", ret);
2901 static int ath10k_resume(struct ieee80211_hw *hw)
2903 struct ath10k *ar = hw->priv;
2906 ret = ath10k_hif_resume(ar);
2908 ath10k_warn("could not resume hif (%d)\n", ret);
2912 ret = ath10k_wmi_pdev_resume_target(ar);
2914 ath10k_warn("could not resume target (%d)\n", ret);
2922 static void ath10k_restart_complete(struct ieee80211_hw *hw)
2924 struct ath10k *ar = hw->priv;
2926 mutex_lock(&ar->conf_mutex);
2928 /* If device failed to restart it will be in a different state, e.g.
2929 * ATH10K_STATE_WEDGED */
2930 if (ar->state == ATH10K_STATE_RESTARTED) {
2931 ath10k_info("device successfully recovered\n");
2932 ar->state = ATH10K_STATE_ON;
2935 mutex_unlock(&ar->conf_mutex);
2938 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
2939 struct survey_info *survey)
2941 struct ath10k *ar = hw->priv;
2942 struct ieee80211_supported_band *sband;
2943 struct survey_info *ar_survey = &ar->survey[idx];
2946 mutex_lock(&ar->conf_mutex);
2948 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
2949 if (sband && idx >= sband->n_channels) {
2950 idx -= sband->n_channels;
2955 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
2957 if (!sband || idx >= sband->n_channels) {
2962 spin_lock_bh(&ar->data_lock);
2963 memcpy(survey, ar_survey, sizeof(*survey));
2964 spin_unlock_bh(&ar->data_lock);
2966 survey->channel = &sband->channels[idx];
2969 mutex_unlock(&ar->conf_mutex);
2973 static const struct ieee80211_ops ath10k_ops = {
2975 .start = ath10k_start,
2976 .stop = ath10k_stop,
2977 .config = ath10k_config,
2978 .add_interface = ath10k_add_interface,
2979 .remove_interface = ath10k_remove_interface,
2980 .configure_filter = ath10k_configure_filter,
2981 .bss_info_changed = ath10k_bss_info_changed,
2982 .hw_scan = ath10k_hw_scan,
2983 .cancel_hw_scan = ath10k_cancel_hw_scan,
2984 .set_key = ath10k_set_key,
2985 .sta_state = ath10k_sta_state,
2986 .conf_tx = ath10k_conf_tx,
2987 .remain_on_channel = ath10k_remain_on_channel,
2988 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
2989 .set_rts_threshold = ath10k_set_rts_threshold,
2990 .set_frag_threshold = ath10k_set_frag_threshold,
2991 .flush = ath10k_flush,
2992 .tx_last_beacon = ath10k_tx_last_beacon,
2993 .restart_complete = ath10k_restart_complete,
2994 .get_survey = ath10k_get_survey,
2996 .suspend = ath10k_suspend,
2997 .resume = ath10k_resume,
3001 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3002 .bitrate = (_rate), \
3003 .flags = (_flags), \
3004 .hw_value = (_rateid), \
3007 #define CHAN2G(_channel, _freq, _flags) { \
3008 .band = IEEE80211_BAND_2GHZ, \
3009 .hw_value = (_channel), \
3010 .center_freq = (_freq), \
3011 .flags = (_flags), \
3012 .max_antenna_gain = 0, \
3016 #define CHAN5G(_channel, _freq, _flags) { \
3017 .band = IEEE80211_BAND_5GHZ, \
3018 .hw_value = (_channel), \
3019 .center_freq = (_freq), \
3020 .flags = (_flags), \
3021 .max_antenna_gain = 0, \
3025 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3035 CHAN2G(10, 2457, 0),
3036 CHAN2G(11, 2462, 0),
3037 CHAN2G(12, 2467, 0),
3038 CHAN2G(13, 2472, 0),
3039 CHAN2G(14, 2484, 0),
3042 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
3043 CHAN5G(36, 5180, 0),
3044 CHAN5G(40, 5200, 0),
3045 CHAN5G(44, 5220, 0),
3046 CHAN5G(48, 5240, 0),
3047 CHAN5G(52, 5260, 0),
3048 CHAN5G(56, 5280, 0),
3049 CHAN5G(60, 5300, 0),
3050 CHAN5G(64, 5320, 0),
3051 CHAN5G(100, 5500, 0),
3052 CHAN5G(104, 5520, 0),
3053 CHAN5G(108, 5540, 0),
3054 CHAN5G(112, 5560, 0),
3055 CHAN5G(116, 5580, 0),
3056 CHAN5G(120, 5600, 0),
3057 CHAN5G(124, 5620, 0),
3058 CHAN5G(128, 5640, 0),
3059 CHAN5G(132, 5660, 0),
3060 CHAN5G(136, 5680, 0),
3061 CHAN5G(140, 5700, 0),
3062 CHAN5G(149, 5745, 0),
3063 CHAN5G(153, 5765, 0),
3064 CHAN5G(157, 5785, 0),
3065 CHAN5G(161, 5805, 0),
3066 CHAN5G(165, 5825, 0),
3069 static struct ieee80211_rate ath10k_rates[] = {
3071 RATETAB_ENT(10, 0x82, 0),
3072 RATETAB_ENT(20, 0x84, 0),
3073 RATETAB_ENT(55, 0x8b, 0),
3074 RATETAB_ENT(110, 0x96, 0),
3076 RATETAB_ENT(60, 0x0c, 0),
3077 RATETAB_ENT(90, 0x12, 0),
3078 RATETAB_ENT(120, 0x18, 0),
3079 RATETAB_ENT(180, 0x24, 0),
3080 RATETAB_ENT(240, 0x30, 0),
3081 RATETAB_ENT(360, 0x48, 0),
3082 RATETAB_ENT(480, 0x60, 0),
3083 RATETAB_ENT(540, 0x6c, 0),
3086 #define ath10k_a_rates (ath10k_rates + 4)
3087 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3088 #define ath10k_g_rates (ath10k_rates + 0)
3089 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3091 struct ath10k *ath10k_mac_create(void)
3093 struct ieee80211_hw *hw;
3096 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3106 void ath10k_mac_destroy(struct ath10k *ar)
3108 ieee80211_free_hw(ar->hw);
3111 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3114 .types = BIT(NL80211_IFTYPE_STATION)
3115 | BIT(NL80211_IFTYPE_P2P_CLIENT)
3119 .types = BIT(NL80211_IFTYPE_P2P_GO)
3123 .types = BIT(NL80211_IFTYPE_AP)
3127 static const struct ieee80211_iface_combination ath10k_if_comb = {
3128 .limits = ath10k_if_limits,
3129 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3130 .max_interfaces = 8,
3131 .num_different_channels = 1,
3132 .beacon_int_infra_match = true,
3135 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3137 struct ieee80211_sta_vht_cap vht_cap = {0};
3141 vht_cap.vht_supported = 1;
3142 vht_cap.cap = ar->vht_cap_info;
3145 for (i = 0; i < 8; i++) {
3146 if (i < ar->num_rf_chains)
3147 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3149 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3152 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3153 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3158 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3161 struct ieee80211_sta_ht_cap ht_cap = {0};
3163 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3166 ht_cap.ht_supported = 1;
3167 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3168 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3169 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3170 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3171 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3173 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3174 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3176 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3177 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3179 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3182 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3183 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3188 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3189 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3191 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3194 stbc = ar->ht_cap_info;
3195 stbc &= WMI_HT_CAP_RX_STBC;
3196 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3197 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3198 stbc &= IEEE80211_HT_CAP_RX_STBC;
3203 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3204 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3206 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3207 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3209 /* max AMSDU is implicitly taken from vht_cap_info */
3210 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3211 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3213 for (i = 0; i < ar->num_rf_chains; i++)
3214 ht_cap.mcs.rx_mask[i] = 0xFF;
3216 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3222 static void ath10k_get_arvif_iter(void *data, u8 *mac,
3223 struct ieee80211_vif *vif)
3225 struct ath10k_vif_iter *arvif_iter = data;
3226 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3228 if (arvif->vdev_id == arvif_iter->vdev_id)
3229 arvif_iter->arvif = arvif;
3232 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3234 struct ath10k_vif_iter arvif_iter;
3237 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3238 arvif_iter.vdev_id = vdev_id;
3240 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3241 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3243 ath10k_get_arvif_iter,
3245 if (!arvif_iter.arvif) {
3246 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3250 return arvif_iter.arvif;
3253 int ath10k_mac_register(struct ath10k *ar)
3255 struct ieee80211_supported_band *band;
3256 struct ieee80211_sta_vht_cap vht_cap;
3257 struct ieee80211_sta_ht_cap ht_cap;
3261 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3263 SET_IEEE80211_DEV(ar->hw, ar->dev);
3265 ht_cap = ath10k_get_ht_cap(ar);
3266 vht_cap = ath10k_create_vht_cap(ar);
3268 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3269 channels = kmemdup(ath10k_2ghz_channels,
3270 sizeof(ath10k_2ghz_channels),
3277 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3278 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3279 band->channels = channels;
3280 band->n_bitrates = ath10k_g_rates_size;
3281 band->bitrates = ath10k_g_rates;
3282 band->ht_cap = ht_cap;
3284 /* vht is not supported in 2.4 GHz */
3286 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3289 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3290 channels = kmemdup(ath10k_5ghz_channels,
3291 sizeof(ath10k_5ghz_channels),
3298 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3299 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3300 band->channels = channels;
3301 band->n_bitrates = ath10k_a_rates_size;
3302 band->bitrates = ath10k_a_rates;
3303 band->ht_cap = ht_cap;
3304 band->vht_cap = vht_cap;
3305 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3308 ar->hw->wiphy->interface_modes =
3309 BIT(NL80211_IFTYPE_STATION) |
3310 BIT(NL80211_IFTYPE_ADHOC) |
3311 BIT(NL80211_IFTYPE_AP) |
3312 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3313 BIT(NL80211_IFTYPE_P2P_GO);
3315 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3316 IEEE80211_HW_SUPPORTS_PS |
3317 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3318 IEEE80211_HW_SUPPORTS_UAPSD |
3319 IEEE80211_HW_MFP_CAPABLE |
3320 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3321 IEEE80211_HW_HAS_RATE_CONTROL |
3322 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3323 IEEE80211_HW_WANT_MONITOR_VIF |
3324 IEEE80211_HW_AP_LINK_PS;
3326 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3327 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3329 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3330 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3331 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3334 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3335 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3337 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3339 ar->hw->channel_change_time = 5000;
3340 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3342 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3343 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3345 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3347 * on LL hardware queues are managed entirely by the FW
3348 * so we only advertise to mac we can do the queues thing
3352 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3353 ar->hw->wiphy->n_iface_combinations = 1;
3355 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3357 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3358 ath10k_reg_notifier);
3360 ath10k_err("Regulatory initialization failed\n");
3364 ret = ieee80211_register_hw(ar->hw);
3366 ath10k_err("ieee80211 registration failed: %d\n", ret);
3370 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3371 ret = regulatory_hint(ar->hw->wiphy,
3372 ar->ath_common.regulatory.alpha2);
3374 goto err_unregister;
3380 ieee80211_unregister_hw(ar->hw);
3382 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3383 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3388 void ath10k_mac_unregister(struct ath10k *ar)
3390 ieee80211_unregister_hw(ar->hw);
3392 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3393 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3395 SET_IEEE80211_DEV(ar->hw, NULL);