2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
34 static int ath10k_send_key(struct ath10k_vif *arvif,
35 struct ieee80211_key_conf *key,
39 struct wmi_vdev_install_key_arg arg = {
40 .vdev_id = arvif->vdev_id,
41 .key_idx = key->keyidx,
42 .key_len = key->keylen,
47 lockdep_assert_held(&arvif->ar->conf_mutex);
49 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
50 arg.key_flags = WMI_KEY_PAIRWISE;
52 arg.key_flags = WMI_KEY_GROUP;
54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
59 case WLAN_CIPHER_SUITE_TKIP:
60 arg.key_cipher = WMI_CIPHER_TKIP;
61 arg.key_txmic_len = 8;
62 arg.key_rxmic_len = 8;
64 case WLAN_CIPHER_SUITE_WEP40:
65 case WLAN_CIPHER_SUITE_WEP104:
66 arg.key_cipher = WMI_CIPHER_WEP;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
70 arg.key_flags = WMI_KEY_PAIRWISE;
73 ath10k_warn("cipher %d is not supported\n", key->cipher);
77 if (cmd == DISABLE_KEY) {
78 arg.key_cipher = WMI_CIPHER_NONE;
82 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
85 static int ath10k_install_key(struct ath10k_vif *arvif,
86 struct ieee80211_key_conf *key,
90 struct ath10k *ar = arvif->ar;
93 lockdep_assert_held(&ar->conf_mutex);
95 INIT_COMPLETION(ar->install_key_done);
97 ret = ath10k_send_key(arvif, key, cmd, macaddr);
101 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
108 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
111 struct ath10k *ar = arvif->ar;
112 struct ath10k_peer *peer;
116 lockdep_assert_held(&ar->conf_mutex);
118 spin_lock_bh(&ar->data_lock);
119 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
120 spin_unlock_bh(&ar->data_lock);
125 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
126 if (arvif->wep_keys[i] == NULL)
129 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
134 peer->keys[i] = arvif->wep_keys[i];
140 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
143 struct ath10k *ar = arvif->ar;
144 struct ath10k_peer *peer;
149 lockdep_assert_held(&ar->conf_mutex);
151 spin_lock_bh(&ar->data_lock);
152 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
153 spin_unlock_bh(&ar->data_lock);
158 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
159 if (peer->keys[i] == NULL)
162 ret = ath10k_install_key(arvif, peer->keys[i],
164 if (ret && first_errno == 0)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
171 peer->keys[i] = NULL;
177 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
178 struct ieee80211_key_conf *key)
180 struct ath10k *ar = arvif->ar;
181 struct ath10k_peer *peer;
187 lockdep_assert_held(&ar->conf_mutex);
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar->data_lock);
194 list_for_each_entry(peer, &ar->peers, list) {
195 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
196 if (peer->keys[i] == key) {
197 memcpy(addr, peer->addr, ETH_ALEN);
198 peer->keys[i] = NULL;
203 if (i < ARRAY_SIZE(peer->keys))
206 spin_unlock_bh(&ar->data_lock);
208 if (i == ARRAY_SIZE(peer->keys))
211 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
212 if (ret && first_errno == 0)
216 ath10k_warn("could not remove key for %pM\n", addr);
223 /*********************/
224 /* General utilities */
225 /*********************/
227 static inline enum wmi_phy_mode
228 chan_to_phymode(const struct cfg80211_chan_def *chandef)
230 enum wmi_phy_mode phymode = MODE_UNKNOWN;
232 switch (chandef->chan->band) {
233 case IEEE80211_BAND_2GHZ:
234 switch (chandef->width) {
235 case NL80211_CHAN_WIDTH_20_NOHT:
238 case NL80211_CHAN_WIDTH_20:
239 phymode = MODE_11NG_HT20;
241 case NL80211_CHAN_WIDTH_40:
242 phymode = MODE_11NG_HT40;
244 case NL80211_CHAN_WIDTH_5:
245 case NL80211_CHAN_WIDTH_10:
246 case NL80211_CHAN_WIDTH_80:
247 case NL80211_CHAN_WIDTH_80P80:
248 case NL80211_CHAN_WIDTH_160:
249 phymode = MODE_UNKNOWN;
253 case IEEE80211_BAND_5GHZ:
254 switch (chandef->width) {
255 case NL80211_CHAN_WIDTH_20_NOHT:
258 case NL80211_CHAN_WIDTH_20:
259 phymode = MODE_11NA_HT20;
261 case NL80211_CHAN_WIDTH_40:
262 phymode = MODE_11NA_HT40;
264 case NL80211_CHAN_WIDTH_80:
265 phymode = MODE_11AC_VHT80;
267 case NL80211_CHAN_WIDTH_5:
268 case NL80211_CHAN_WIDTH_10:
269 case NL80211_CHAN_WIDTH_80P80:
270 case NL80211_CHAN_WIDTH_160:
271 phymode = MODE_UNKNOWN;
279 WARN_ON(phymode == MODE_UNKNOWN);
283 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
296 switch (mpdudensity) {
302 /* Our lower layer calculations limit our precision to
318 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
322 lockdep_assert_held(&ar->conf_mutex);
324 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
328 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
335 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
337 if (value != 0xFFFFFFFF)
338 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
341 return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
342 WMI_VDEV_PARAM_RTS_THRESHOLD,
346 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
348 if (value != 0xFFFFFFFF)
349 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
350 ATH10K_FRAGMT_THRESHOLD_MIN,
351 ATH10K_FRAGMT_THRESHOLD_MAX);
353 return ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
354 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
358 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
362 lockdep_assert_held(&ar->conf_mutex);
364 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
368 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
375 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
377 struct ath10k_peer *peer, *tmp;
379 lockdep_assert_held(&ar->conf_mutex);
381 spin_lock_bh(&ar->data_lock);
382 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
383 if (peer->vdev_id != vdev_id)
386 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
387 peer->addr, vdev_id);
389 list_del(&peer->list);
392 spin_unlock_bh(&ar->data_lock);
395 static void ath10k_peer_cleanup_all(struct ath10k *ar)
397 struct ath10k_peer *peer, *tmp;
399 lockdep_assert_held(&ar->conf_mutex);
401 spin_lock_bh(&ar->data_lock);
402 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
403 list_del(&peer->list);
406 spin_unlock_bh(&ar->data_lock);
409 /************************/
410 /* Interface management */
411 /************************/
413 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
417 lockdep_assert_held(&ar->conf_mutex);
419 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
420 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
427 static int ath10k_vdev_start(struct ath10k_vif *arvif)
429 struct ath10k *ar = arvif->ar;
430 struct ieee80211_conf *conf = &ar->hw->conf;
431 struct ieee80211_channel *channel = conf->chandef.chan;
432 struct wmi_vdev_start_request_arg arg = {};
435 lockdep_assert_held(&ar->conf_mutex);
437 INIT_COMPLETION(ar->vdev_setup_done);
439 arg.vdev_id = arvif->vdev_id;
440 arg.dtim_period = arvif->dtim_period;
441 arg.bcn_intval = arvif->beacon_interval;
443 arg.channel.freq = channel->center_freq;
445 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
447 arg.channel.mode = chan_to_phymode(&conf->chandef);
449 arg.channel.min_power = channel->max_power * 3;
450 arg.channel.max_power = channel->max_power * 4;
451 arg.channel.max_reg_power = channel->max_reg_power * 4;
452 arg.channel.max_antenna_gain = channel->max_antenna_gain;
454 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
455 arg.ssid = arvif->u.ap.ssid;
456 arg.ssid_len = arvif->u.ap.ssid_len;
457 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
458 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
459 arg.ssid = arvif->vif->bss_conf.ssid;
460 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
463 ath10k_dbg(ATH10K_DBG_MAC,
464 "mac vdev %d start center_freq %d phymode %s\n",
465 arg.vdev_id, arg.channel.freq,
466 ath10k_wmi_phymode_str(arg.channel.mode));
468 ret = ath10k_wmi_vdev_start(ar, &arg);
470 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
474 ret = ath10k_vdev_setup_sync(ar);
476 ath10k_warn("vdev setup failed %d\n", ret);
483 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
485 struct ath10k *ar = arvif->ar;
488 lockdep_assert_held(&ar->conf_mutex);
490 INIT_COMPLETION(ar->vdev_setup_done);
492 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
494 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
498 ret = ath10k_vdev_setup_sync(ar);
500 ath10k_warn("vdev setup failed %d\n", ret);
507 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
509 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
510 struct wmi_vdev_start_request_arg arg = {};
513 lockdep_assert_held(&ar->conf_mutex);
515 arg.vdev_id = vdev_id;
516 arg.channel.freq = channel->center_freq;
517 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
519 /* TODO setup this dynamically, what in case we
520 don't have any vifs? */
521 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
523 arg.channel.min_power = channel->max_power * 3;
524 arg.channel.max_power = channel->max_power * 4;
525 arg.channel.max_reg_power = channel->max_reg_power * 4;
526 arg.channel.max_antenna_gain = channel->max_antenna_gain;
528 ret = ath10k_wmi_vdev_start(ar, &arg);
530 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
534 ret = ath10k_vdev_setup_sync(ar);
536 ath10k_warn("Monitor vdev setup failed %d\n", ret);
540 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
542 ath10k_warn("Monitor vdev up failed: %d\n", ret);
546 ar->monitor_vdev_id = vdev_id;
547 ar->monitor_enabled = true;
552 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
554 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
559 static int ath10k_monitor_stop(struct ath10k *ar)
563 lockdep_assert_held(&ar->conf_mutex);
565 /* For some reasons, ath10k_wmi_vdev_down() here couse
566 * often ath10k_wmi_vdev_stop() to fail. Next we could
567 * not run monitor vdev and driver reload
568 * required. Don't see such problems we skip
569 * ath10k_wmi_vdev_down() here.
572 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
574 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
576 ret = ath10k_vdev_setup_sync(ar);
578 ath10k_warn("Monitor_down sync failed: %d\n", ret);
580 ar->monitor_enabled = false;
584 static int ath10k_monitor_create(struct ath10k *ar)
588 lockdep_assert_held(&ar->conf_mutex);
590 if (ar->monitor_present) {
591 ath10k_warn("Monitor mode already enabled\n");
595 bit = ffs(ar->free_vdev_map);
597 ath10k_warn("No free VDEV slots\n");
601 ar->monitor_vdev_id = bit - 1;
602 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
604 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
605 WMI_VDEV_TYPE_MONITOR,
608 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
612 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
613 ar->monitor_vdev_id);
615 ar->monitor_present = true;
620 * Restore the ID to the global map.
622 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
626 static int ath10k_monitor_destroy(struct ath10k *ar)
630 lockdep_assert_held(&ar->conf_mutex);
632 if (!ar->monitor_present)
635 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
637 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
641 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
642 ar->monitor_present = false;
644 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
645 ar->monitor_vdev_id);
649 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
650 struct ieee80211_bss_conf *info)
654 lockdep_assert_held(&arvif->ar->conf_mutex);
656 if (!info->enable_beacon) {
657 ath10k_vdev_stop(arvif);
661 arvif->tx_seq_no = 0x1000;
663 ret = ath10k_vdev_start(arvif);
667 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
669 ath10k_warn("Failed to bring up VDEV: %d\n",
673 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
676 static void ath10k_control_ibss(struct ath10k_vif *arvif,
677 struct ieee80211_bss_conf *info,
678 const u8 self_peer[ETH_ALEN])
682 lockdep_assert_held(&arvif->ar->conf_mutex);
684 if (!info->ibss_joined) {
685 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
687 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
688 self_peer, arvif->vdev_id, ret);
690 if (is_zero_ether_addr(arvif->u.ibss.bssid))
693 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
694 arvif->u.ibss.bssid);
696 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
697 arvif->u.ibss.bssid, arvif->vdev_id, ret);
701 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
706 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
708 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
709 self_peer, arvif->vdev_id, ret);
713 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
714 WMI_VDEV_PARAM_ATIM_WINDOW,
715 ATH10K_DEFAULT_ATIM);
717 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
718 arvif->vdev_id, ret);
722 * Review this when mac80211 gains per-interface powersave support.
724 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
726 struct ath10k_generic_iter *ar_iter = data;
727 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
728 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
729 enum wmi_sta_powersave_param param;
730 enum wmi_sta_ps_mode psmode;
733 lockdep_assert_held(&arvif->ar->conf_mutex);
735 if (vif->type != NL80211_IFTYPE_STATION)
738 if (conf->flags & IEEE80211_CONF_PS) {
739 psmode = WMI_STA_PS_MODE_ENABLED;
740 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
742 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
745 conf->dynamic_ps_timeout);
747 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
754 psmode = WMI_STA_PS_MODE_DISABLED;
757 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
758 arvif->vdev_id, psmode ? "enable" : "disable");
760 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
763 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
764 psmode, arvif->vdev_id);
767 /**********************/
768 /* Station management */
769 /**********************/
771 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
772 struct ath10k_vif *arvif,
773 struct ieee80211_sta *sta,
774 struct ieee80211_bss_conf *bss_conf,
775 struct wmi_peer_assoc_complete_arg *arg)
777 lockdep_assert_held(&ar->conf_mutex);
779 memcpy(arg->addr, sta->addr, ETH_ALEN);
780 arg->vdev_id = arvif->vdev_id;
781 arg->peer_aid = sta->aid;
782 arg->peer_flags |= WMI_PEER_AUTH;
784 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
786 * Seems FW have problems with Power Save in STA
787 * mode when we setup this parameter to high (eg. 5).
788 * Often we see that FW don't send NULL (with clean P flags)
789 * frame even there is info about buffered frames in beacons.
790 * Sometimes we have to wait more than 10 seconds before FW
791 * will wakeup. Often sending one ping from AP to our device
792 * just fail (more than 50%).
794 * Seems setting this FW parameter to 1 couse FW
795 * will check every beacon and will wakup immediately
796 * after detection buffered data.
798 arg->peer_listen_intval = 1;
800 arg->peer_listen_intval = ar->hw->conf.listen_interval;
802 arg->peer_num_spatial_streams = 1;
805 * The assoc capabilities are available only in managed mode.
807 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
808 arg->peer_caps = bss_conf->assoc_capability;
811 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
812 struct ath10k_vif *arvif,
813 struct wmi_peer_assoc_complete_arg *arg)
815 struct ieee80211_vif *vif = arvif->vif;
816 struct ieee80211_bss_conf *info = &vif->bss_conf;
817 struct cfg80211_bss *bss;
818 const u8 *rsnie = NULL;
819 const u8 *wpaie = NULL;
821 lockdep_assert_held(&ar->conf_mutex);
823 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
824 info->bssid, NULL, 0, 0, 0);
826 const struct cfg80211_bss_ies *ies;
829 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
831 ies = rcu_dereference(bss->ies);
833 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
834 WLAN_OUI_TYPE_MICROSOFT_WPA,
838 cfg80211_put_bss(ar->hw->wiphy, bss);
841 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
842 if (rsnie || wpaie) {
843 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
844 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
848 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
849 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
853 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
854 struct ieee80211_sta *sta,
855 struct wmi_peer_assoc_complete_arg *arg)
857 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
858 const struct ieee80211_supported_band *sband;
859 const struct ieee80211_rate *rates;
863 lockdep_assert_held(&ar->conf_mutex);
865 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
866 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
867 rates = sband->bitrates;
869 rateset->num_rates = 0;
871 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
875 rateset->rates[rateset->num_rates] = rates->hw_value;
876 rateset->num_rates++;
880 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
881 struct ieee80211_sta *sta,
882 struct wmi_peer_assoc_complete_arg *arg)
884 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
888 lockdep_assert_held(&ar->conf_mutex);
890 if (!ht_cap->ht_supported)
893 arg->peer_flags |= WMI_PEER_HT;
894 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
895 ht_cap->ampdu_factor)) - 1;
897 arg->peer_mpdu_density =
898 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
900 arg->peer_ht_caps = ht_cap->cap;
901 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
903 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
904 arg->peer_flags |= WMI_PEER_LDPC;
906 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
907 arg->peer_flags |= WMI_PEER_40MHZ;
908 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
911 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
912 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
914 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
915 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
917 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
918 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
919 arg->peer_flags |= WMI_PEER_STBC;
922 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
924 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
925 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
926 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
927 arg->peer_rate_caps |= stbc;
928 arg->peer_flags |= WMI_PEER_STBC;
931 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
932 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
934 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
935 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
936 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
937 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
938 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
939 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
942 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
943 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
944 else if (ht_cap->mcs.rx_mask[1])
945 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
947 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
948 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
949 arg->peer_ht_rates.rates[n++] = i;
951 arg->peer_ht_rates.num_rates = n;
952 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
954 ath10k_dbg(ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
956 arg->peer_ht_rates.num_rates,
957 arg->peer_num_spatial_streams);
960 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
961 struct ath10k_vif *arvif,
962 struct ieee80211_sta *sta,
963 struct ieee80211_bss_conf *bss_conf,
964 struct wmi_peer_assoc_complete_arg *arg)
969 lockdep_assert_held(&ar->conf_mutex);
972 arg->peer_flags |= WMI_PEER_QOS;
974 if (sta->wme && sta->uapsd_queues) {
975 ath10k_dbg(ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
976 sta->uapsd_queues, sta->max_sp);
978 arg->peer_flags |= WMI_PEER_APSD;
979 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
981 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
982 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
983 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
984 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
985 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
986 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
987 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
988 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
989 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
990 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
991 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
992 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
995 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
996 max_sp = sta->max_sp;
998 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1000 WMI_AP_PS_PEER_PARAM_UAPSD,
1003 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1005 WMI_AP_PS_PEER_PARAM_MAX_SP,
1008 /* TODO setup this based on STA listen interval and
1009 beacon interval. Currently we don't know
1010 sta->listen_interval - mac80211 patch required.
1011 Currently use 10 seconds */
1012 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1014 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1019 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
1020 struct ath10k_vif *arvif,
1021 struct ieee80211_sta *sta,
1022 struct ieee80211_bss_conf *bss_conf,
1023 struct wmi_peer_assoc_complete_arg *arg)
1026 arg->peer_flags |= WMI_PEER_QOS;
1029 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1030 struct ieee80211_sta *sta,
1031 struct wmi_peer_assoc_complete_arg *arg)
1033 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1035 if (!vht_cap->vht_supported)
1038 arg->peer_flags |= WMI_PEER_VHT;
1040 arg->peer_vht_caps = vht_cap->cap;
1042 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1043 arg->peer_flags |= WMI_PEER_80MHZ;
1045 arg->peer_vht_rates.rx_max_rate =
1046 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1047 arg->peer_vht_rates.rx_mcs_set =
1048 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1049 arg->peer_vht_rates.tx_max_rate =
1050 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1051 arg->peer_vht_rates.tx_mcs_set =
1052 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1054 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1055 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1058 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1059 struct ath10k_vif *arvif,
1060 struct ieee80211_sta *sta,
1061 struct ieee80211_bss_conf *bss_conf,
1062 struct wmi_peer_assoc_complete_arg *arg)
1064 switch (arvif->vdev_type) {
1065 case WMI_VDEV_TYPE_AP:
1066 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1068 case WMI_VDEV_TYPE_STA:
1069 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1076 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1077 struct ath10k_vif *arvif,
1078 struct ieee80211_sta *sta,
1079 struct wmi_peer_assoc_complete_arg *arg)
1081 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1083 switch (ar->hw->conf.chandef.chan->band) {
1084 case IEEE80211_BAND_2GHZ:
1085 if (sta->ht_cap.ht_supported) {
1086 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1087 phymode = MODE_11NG_HT40;
1089 phymode = MODE_11NG_HT20;
1095 case IEEE80211_BAND_5GHZ:
1099 if (sta->vht_cap.vht_supported) {
1100 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1101 phymode = MODE_11AC_VHT80;
1102 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1103 phymode = MODE_11AC_VHT40;
1104 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1105 phymode = MODE_11AC_VHT20;
1106 } else if (sta->ht_cap.ht_supported) {
1107 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1108 phymode = MODE_11NA_HT40;
1110 phymode = MODE_11NA_HT20;
1120 ath10k_dbg(ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1121 sta->addr, ath10k_wmi_phymode_str(phymode));
1123 arg->peer_phymode = phymode;
1124 WARN_ON(phymode == MODE_UNKNOWN);
1127 static int ath10k_peer_assoc(struct ath10k *ar,
1128 struct ath10k_vif *arvif,
1129 struct ieee80211_sta *sta,
1130 struct ieee80211_bss_conf *bss_conf)
1132 struct wmi_peer_assoc_complete_arg arg;
1134 lockdep_assert_held(&ar->conf_mutex);
1136 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1138 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1139 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1140 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1141 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1142 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1143 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1144 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1146 return ath10k_wmi_peer_assoc(ar, &arg);
1149 /* can be called only in mac80211 callbacks due to `key_count` usage */
1150 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1151 struct ieee80211_vif *vif,
1152 struct ieee80211_bss_conf *bss_conf)
1154 struct ath10k *ar = hw->priv;
1155 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1156 struct ieee80211_sta *ap_sta;
1159 lockdep_assert_held(&ar->conf_mutex);
1163 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1165 ath10k_warn("Failed to find station entry for %pM\n",
1171 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1173 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1180 ath10k_dbg(ATH10K_DBG_MAC,
1181 "mac vdev %d up (associated) bssid %pM aid %d\n",
1182 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1184 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1187 ath10k_warn("VDEV: %d up failed: ret %d\n",
1188 arvif->vdev_id, ret);
1194 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1195 struct ieee80211_vif *vif)
1197 struct ath10k *ar = hw->priv;
1198 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1201 lockdep_assert_held(&ar->conf_mutex);
1204 * For some reason, calling VDEV-DOWN before VDEV-STOP
1205 * makes the FW to send frames via HTT after disassociation.
1206 * No idea why this happens, even though VDEV-DOWN is supposed
1207 * to be analogous to link down, so just stop the VDEV.
1209 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1212 /* FIXME: check return value */
1213 ret = ath10k_vdev_stop(arvif);
1216 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1217 * report beacons from previously associated network through HTT.
1218 * This in turn would spam mac80211 WARN_ON if we bring down all
1219 * interfaces as it expects there is no rx when no interface is
1222 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1224 /* FIXME: why don't we print error if wmi call fails? */
1225 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1227 arvif->def_wep_key_index = 0;
1230 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1231 struct ieee80211_sta *sta)
1235 lockdep_assert_held(&ar->conf_mutex);
1237 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1239 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1243 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1245 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1252 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1253 struct ieee80211_sta *sta)
1257 lockdep_assert_held(&ar->conf_mutex);
1259 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1261 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1272 static int ath10k_update_channel_list(struct ath10k *ar)
1274 struct ieee80211_hw *hw = ar->hw;
1275 struct ieee80211_supported_band **bands;
1276 enum ieee80211_band band;
1277 struct ieee80211_channel *channel;
1278 struct wmi_scan_chan_list_arg arg = {0};
1279 struct wmi_channel_arg *ch;
1285 lockdep_assert_held(&ar->conf_mutex);
1287 bands = hw->wiphy->bands;
1288 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1292 for (i = 0; i < bands[band]->n_channels; i++) {
1293 if (bands[band]->channels[i].flags &
1294 IEEE80211_CHAN_DISABLED)
1301 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1302 arg.channels = kzalloc(len, GFP_KERNEL);
1307 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1311 for (i = 0; i < bands[band]->n_channels; i++) {
1312 channel = &bands[band]->channels[i];
1314 if (channel->flags & IEEE80211_CHAN_DISABLED)
1317 ch->allow_ht = true;
1319 /* FIXME: when should we really allow VHT? */
1320 ch->allow_vht = true;
1323 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1326 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1328 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1329 ch->passive = passive;
1331 ch->freq = channel->center_freq;
1332 ch->min_power = channel->max_power * 3;
1333 ch->max_power = channel->max_power * 4;
1334 ch->max_reg_power = channel->max_reg_power * 4;
1335 ch->max_antenna_gain = channel->max_antenna_gain;
1336 ch->reg_class_id = 0; /* FIXME */
1338 /* FIXME: why use only legacy modes, why not any
1339 * HT/VHT modes? Would that even make any
1341 if (channel->band == IEEE80211_BAND_2GHZ)
1342 ch->mode = MODE_11G;
1344 ch->mode = MODE_11A;
1346 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1349 ath10k_dbg(ATH10K_DBG_WMI,
1350 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1351 ch - arg.channels, arg.n_channels,
1352 ch->freq, ch->max_power, ch->max_reg_power,
1353 ch->max_antenna_gain, ch->mode);
1359 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1360 kfree(arg.channels);
1365 static void ath10k_regd_update(struct ath10k *ar)
1367 struct reg_dmn_pair_mapping *regpair;
1370 lockdep_assert_held(&ar->conf_mutex);
1372 ret = ath10k_update_channel_list(ar);
1374 ath10k_warn("could not update channel list (%d)\n", ret);
1376 regpair = ar->ath_common.regulatory.regpair;
1378 /* Target allows setting up per-band regdomain but ath_common provides
1379 * a combined one only */
1380 ret = ath10k_wmi_pdev_set_regdomain(ar,
1381 regpair->regDmnEnum,
1382 regpair->regDmnEnum, /* 2ghz */
1383 regpair->regDmnEnum, /* 5ghz */
1384 regpair->reg_2ghz_ctl,
1385 regpair->reg_5ghz_ctl);
1387 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1390 static void ath10k_reg_notifier(struct wiphy *wiphy,
1391 struct regulatory_request *request)
1393 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1394 struct ath10k *ar = hw->priv;
1396 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1398 mutex_lock(&ar->conf_mutex);
1399 if (ar->state == ATH10K_STATE_ON)
1400 ath10k_regd_update(ar);
1401 mutex_unlock(&ar->conf_mutex);
1409 * Frames sent to the FW have to be in "Native Wifi" format.
1410 * Strip the QoS field from the 802.11 header.
1412 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1413 struct ieee80211_tx_control *control,
1414 struct sk_buff *skb)
1416 struct ieee80211_hdr *hdr = (void *)skb->data;
1419 if (!ieee80211_is_data_qos(hdr->frame_control))
1422 qos_ctl = ieee80211_get_qos_ctl(hdr);
1423 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1424 skb->data, (void *)qos_ctl - (void *)skb->data);
1425 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1428 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1430 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1431 struct ieee80211_vif *vif = info->control.vif;
1432 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1433 struct ath10k *ar = arvif->ar;
1434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1435 struct ieee80211_key_conf *key = info->control.hw_key;
1438 if (!ieee80211_has_protected(hdr->frame_control))
1444 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1445 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1448 if (key->keyidx == arvif->def_wep_key_index)
1451 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d keyidx %d\n",
1452 arvif->vdev_id, key->keyidx);
1454 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1455 WMI_VDEV_PARAM_DEF_KEYID,
1458 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1462 arvif->def_wep_key_index = key->keyidx;
1465 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1467 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1468 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1469 struct ieee80211_vif *vif = info->control.vif;
1470 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1472 /* This is case only for P2P_GO */
1473 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1474 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1477 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1478 spin_lock_bh(&ar->data_lock);
1479 if (arvif->u.ap.noa_data)
1480 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1482 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1483 arvif->u.ap.noa_data,
1484 arvif->u.ap.noa_len);
1485 spin_unlock_bh(&ar->data_lock);
1489 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1491 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1494 if (ar->htt.target_version_major >= 3) {
1495 /* Since HTT 3.0 there is no separate mgmt tx command */
1496 ret = ath10k_htt_tx(&ar->htt, skb);
1500 if (ieee80211_is_mgmt(hdr->frame_control))
1501 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1502 else if (ieee80211_is_nullfunc(hdr->frame_control))
1503 /* FW does not report tx status properly for NullFunc frames
1504 * unless they are sent through mgmt tx path. mac80211 sends
1505 * those frames when it detects link/beacon loss and depends on
1506 * the tx status to be correct. */
1507 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
1509 ret = ath10k_htt_tx(&ar->htt, skb);
1513 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1514 ieee80211_free_txskb(ar->hw, skb);
1518 void ath10k_offchan_tx_purge(struct ath10k *ar)
1520 struct sk_buff *skb;
1523 skb = skb_dequeue(&ar->offchan_tx_queue);
1527 ieee80211_free_txskb(ar->hw, skb);
1531 void ath10k_offchan_tx_work(struct work_struct *work)
1533 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1534 struct ath10k_peer *peer;
1535 struct ieee80211_hdr *hdr;
1536 struct sk_buff *skb;
1537 const u8 *peer_addr;
1541 /* FW requirement: We must create a peer before FW will send out
1542 * an offchannel frame. Otherwise the frame will be stuck and
1543 * never transmitted. We delete the peer upon tx completion.
1544 * It is unlikely that a peer for offchannel tx will already be
1545 * present. However it may be in some rare cases so account for that.
1546 * Otherwise we might remove a legitimate peer and break stuff. */
1549 skb = skb_dequeue(&ar->offchan_tx_queue);
1553 mutex_lock(&ar->conf_mutex);
1555 ath10k_dbg(ATH10K_DBG_MAC, "mac offchannel skb %p\n",
1558 hdr = (struct ieee80211_hdr *)skb->data;
1559 peer_addr = ieee80211_get_DA(hdr);
1560 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1562 spin_lock_bh(&ar->data_lock);
1563 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1564 spin_unlock_bh(&ar->data_lock);
1567 /* FIXME: should this use ath10k_warn()? */
1568 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1569 peer_addr, vdev_id);
1572 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1574 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1575 peer_addr, vdev_id, ret);
1578 spin_lock_bh(&ar->data_lock);
1579 INIT_COMPLETION(ar->offchan_tx_completed);
1580 ar->offchan_tx_skb = skb;
1581 spin_unlock_bh(&ar->data_lock);
1583 ath10k_tx_htt(ar, skb);
1585 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1588 ath10k_warn("timed out waiting for offchannel skb %p\n",
1592 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1594 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1595 peer_addr, vdev_id, ret);
1598 mutex_unlock(&ar->conf_mutex);
1607 * This gets called if we dont get a heart-beat during scan.
1608 * This may indicate the FW has hung and we need to abort the
1609 * scan manually to prevent cancel_hw_scan() from deadlocking
1611 void ath10k_reset_scan(unsigned long ptr)
1613 struct ath10k *ar = (struct ath10k *)ptr;
1615 spin_lock_bh(&ar->data_lock);
1616 if (!ar->scan.in_progress) {
1617 spin_unlock_bh(&ar->data_lock);
1621 ath10k_warn("scan timeout. resetting. fw issue?\n");
1623 if (ar->scan.is_roc)
1624 ieee80211_remain_on_channel_expired(ar->hw);
1626 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1628 ar->scan.in_progress = false;
1629 complete_all(&ar->scan.completed);
1630 spin_unlock_bh(&ar->data_lock);
1633 static int ath10k_abort_scan(struct ath10k *ar)
1635 struct wmi_stop_scan_arg arg = {
1636 .req_id = 1, /* FIXME */
1637 .req_type = WMI_SCAN_STOP_ONE,
1638 .u.scan_id = ATH10K_SCAN_ID,
1642 lockdep_assert_held(&ar->conf_mutex);
1644 del_timer_sync(&ar->scan.timeout);
1646 spin_lock_bh(&ar->data_lock);
1647 if (!ar->scan.in_progress) {
1648 spin_unlock_bh(&ar->data_lock);
1652 ar->scan.aborting = true;
1653 spin_unlock_bh(&ar->data_lock);
1655 ret = ath10k_wmi_stop_scan(ar, &arg);
1657 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1658 spin_lock_bh(&ar->data_lock);
1659 ar->scan.in_progress = false;
1660 ath10k_offchan_tx_purge(ar);
1661 spin_unlock_bh(&ar->data_lock);
1665 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1667 ath10k_warn("timed out while waiting for scan to stop\n");
1669 /* scan completion may be done right after we timeout here, so let's
1670 * check the in_progress and tell mac80211 scan is completed. if we
1671 * don't do that and FW fails to send us scan completion indication
1672 * then userspace won't be able to scan anymore */
1675 spin_lock_bh(&ar->data_lock);
1676 if (ar->scan.in_progress) {
1677 ath10k_warn("could not stop scan. its still in progress\n");
1678 ar->scan.in_progress = false;
1679 ath10k_offchan_tx_purge(ar);
1682 spin_unlock_bh(&ar->data_lock);
1687 static int ath10k_start_scan(struct ath10k *ar,
1688 const struct wmi_start_scan_arg *arg)
1692 lockdep_assert_held(&ar->conf_mutex);
1694 ret = ath10k_wmi_start_scan(ar, arg);
1698 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1700 ath10k_abort_scan(ar);
1704 /* the scan can complete earlier, before we even
1705 * start the timer. in that case the timer handler
1706 * checks ar->scan.in_progress and bails out if its
1707 * false. Add a 200ms margin to account event/command
1709 mod_timer(&ar->scan.timeout, jiffies +
1710 msecs_to_jiffies(arg->max_scan_time+200));
1714 /**********************/
1715 /* mac80211 callbacks */
1716 /**********************/
1718 static void ath10k_tx(struct ieee80211_hw *hw,
1719 struct ieee80211_tx_control *control,
1720 struct sk_buff *skb)
1722 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1723 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1724 struct ath10k *ar = hw->priv;
1725 struct ath10k_vif *arvif = NULL;
1729 if (info->control.vif) {
1730 arvif = ath10k_vif_to_arvif(info->control.vif);
1731 vdev_id = arvif->vdev_id;
1732 } else if (ar->monitor_enabled) {
1733 vdev_id = ar->monitor_vdev_id;
1736 /* We should disable CCK RATE due to P2P */
1737 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1738 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1740 /* we must calculate tid before we apply qos workaround
1741 * as we'd lose the qos control field */
1742 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1743 if (ieee80211_is_mgmt(hdr->frame_control)) {
1744 tid = HTT_DATA_TX_EXT_TID_MGMT;
1745 } else if (ieee80211_is_data_qos(hdr->frame_control) &&
1746 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1747 u8 *qc = ieee80211_get_qos_ctl(hdr);
1748 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1751 /* it makes no sense to process injected frames like that */
1752 if (info->control.vif &&
1753 info->control.vif->type != NL80211_IFTYPE_MONITOR) {
1754 ath10k_tx_h_qos_workaround(hw, control, skb);
1755 ath10k_tx_h_update_wep_key(skb);
1756 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1757 ath10k_tx_h_seq_no(skb);
1760 ATH10K_SKB_CB(skb)->is_mapped = false;
1761 ATH10K_SKB_CB(skb)->is_aborted = false;
1762 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
1763 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1764 ATH10K_SKB_CB(skb)->htt.tid = tid;
1766 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1767 spin_lock_bh(&ar->data_lock);
1768 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1769 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1770 spin_unlock_bh(&ar->data_lock);
1772 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1774 skb_queue_tail(&ar->offchan_tx_queue, skb);
1775 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1779 ath10k_tx_htt(ar, skb);
1783 * Initialize various parameters with default vaules.
1785 void ath10k_halt(struct ath10k *ar)
1787 lockdep_assert_held(&ar->conf_mutex);
1789 del_timer_sync(&ar->scan.timeout);
1790 ath10k_offchan_tx_purge(ar);
1791 ath10k_peer_cleanup_all(ar);
1792 ath10k_core_stop(ar);
1793 ath10k_hif_power_down(ar);
1795 spin_lock_bh(&ar->data_lock);
1796 if (ar->scan.in_progress) {
1797 del_timer(&ar->scan.timeout);
1798 ar->scan.in_progress = false;
1799 ieee80211_scan_completed(ar->hw, true);
1801 spin_unlock_bh(&ar->data_lock);
1804 static int ath10k_start(struct ieee80211_hw *hw)
1806 struct ath10k *ar = hw->priv;
1809 mutex_lock(&ar->conf_mutex);
1811 if (ar->state != ATH10K_STATE_OFF &&
1812 ar->state != ATH10K_STATE_RESTARTING) {
1817 ret = ath10k_hif_power_up(ar);
1819 ath10k_err("could not init hif (%d)\n", ret);
1820 ar->state = ATH10K_STATE_OFF;
1824 ret = ath10k_core_start(ar);
1826 ath10k_err("could not init core (%d)\n", ret);
1827 ath10k_hif_power_down(ar);
1828 ar->state = ATH10K_STATE_OFF;
1832 if (ar->state == ATH10K_STATE_OFF)
1833 ar->state = ATH10K_STATE_ON;
1834 else if (ar->state == ATH10K_STATE_RESTARTING)
1835 ar->state = ATH10K_STATE_RESTARTED;
1837 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1839 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1842 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1844 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1847 ath10k_regd_update(ar);
1850 mutex_unlock(&ar->conf_mutex);
1854 static void ath10k_stop(struct ieee80211_hw *hw)
1856 struct ath10k *ar = hw->priv;
1858 mutex_lock(&ar->conf_mutex);
1859 if (ar->state == ATH10K_STATE_ON ||
1860 ar->state == ATH10K_STATE_RESTARTED ||
1861 ar->state == ATH10K_STATE_WEDGED)
1864 ar->state = ATH10K_STATE_OFF;
1865 mutex_unlock(&ar->conf_mutex);
1867 cancel_work_sync(&ar->offchan_tx_work);
1868 cancel_work_sync(&ar->restart_work);
1871 static void ath10k_config_ps(struct ath10k *ar)
1873 struct ath10k_generic_iter ar_iter;
1875 lockdep_assert_held(&ar->conf_mutex);
1877 /* During HW reconfiguration mac80211 reports all interfaces that were
1878 * running until reconfiguration was started. Since FW doesn't have any
1879 * vdevs at this point we must not iterate over this interface list.
1880 * This setting will be updated upon add_interface(). */
1881 if (ar->state == ATH10K_STATE_RESTARTED)
1884 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1887 ieee80211_iterate_active_interfaces_atomic(
1888 ar->hw, IEEE80211_IFACE_ITER_NORMAL,
1889 ath10k_ps_iter, &ar_iter);
1892 ath10k_warn("failed to set ps config (%d)\n", ar_iter.ret);
1895 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1897 struct ath10k *ar = hw->priv;
1898 struct ieee80211_conf *conf = &hw->conf;
1901 mutex_lock(&ar->conf_mutex);
1903 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1904 ath10k_dbg(ATH10K_DBG_MAC, "mac config channel %d mhz\n",
1905 conf->chandef.chan->center_freq);
1906 spin_lock_bh(&ar->data_lock);
1907 ar->rx_channel = conf->chandef.chan;
1908 spin_unlock_bh(&ar->data_lock);
1911 if (changed & IEEE80211_CONF_CHANGE_PS)
1912 ath10k_config_ps(ar);
1914 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1915 if (conf->flags & IEEE80211_CONF_MONITOR)
1916 ret = ath10k_monitor_create(ar);
1918 ret = ath10k_monitor_destroy(ar);
1921 mutex_unlock(&ar->conf_mutex);
1927 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1928 * because we will send mgmt frames without CCK. This requirement
1929 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1932 static int ath10k_add_interface(struct ieee80211_hw *hw,
1933 struct ieee80211_vif *vif)
1935 struct ath10k *ar = hw->priv;
1936 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1937 enum wmi_sta_powersave_param param;
1942 mutex_lock(&ar->conf_mutex);
1944 memset(arvif, 0, sizeof(*arvif));
1949 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1950 ath10k_warn("Only one monitor interface allowed\n");
1955 bit = ffs(ar->free_vdev_map);
1961 arvif->vdev_id = bit - 1;
1962 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1963 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1966 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1968 switch (vif->type) {
1969 case NL80211_IFTYPE_UNSPECIFIED:
1970 case NL80211_IFTYPE_STATION:
1971 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1973 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1975 case NL80211_IFTYPE_ADHOC:
1976 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1978 case NL80211_IFTYPE_AP:
1979 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1982 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1984 case NL80211_IFTYPE_MONITOR:
1985 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1992 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d\n",
1993 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1995 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1996 arvif->vdev_subtype, vif->addr);
1998 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
2002 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
2003 arvif->def_wep_key_index);
2005 ath10k_warn("Failed to set default keyid: %d\n", ret);
2007 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2008 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
2009 ATH10K_HW_TXRX_NATIVE_WIFI);
2011 ath10k_warn("Failed to set TX encap: %d\n", ret);
2013 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2014 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2016 ath10k_warn("Failed to create peer for AP: %d\n", ret);
2021 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2022 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2023 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2024 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2027 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
2029 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2030 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2031 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2034 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
2036 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2037 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2038 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2041 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
2044 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2046 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2047 arvif->vdev_id, ret);
2049 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2051 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2052 arvif->vdev_id, ret);
2054 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2055 ar->monitor_present = true;
2058 mutex_unlock(&ar->conf_mutex);
2062 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2063 struct ieee80211_vif *vif)
2065 struct ath10k *ar = hw->priv;
2066 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2069 mutex_lock(&ar->conf_mutex);
2071 spin_lock_bh(&ar->data_lock);
2072 if (arvif->beacon) {
2073 dev_kfree_skb_any(arvif->beacon);
2074 arvif->beacon = NULL;
2076 spin_unlock_bh(&ar->data_lock);
2078 ar->free_vdev_map |= 1 << (arvif->vdev_id);
2080 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2081 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
2083 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
2085 kfree(arvif->u.ap.noa_data);
2088 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev delete %d (remove interface)\n",
2091 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2093 ath10k_warn("WMI vdev delete failed: %d\n", ret);
2095 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2096 ar->monitor_present = false;
2098 ath10k_peer_cleanup(ar, arvif->vdev_id);
2100 mutex_unlock(&ar->conf_mutex);
2104 * FIXME: Has to be verified.
2106 #define SUPPORTED_FILTERS \
2107 (FIF_PROMISC_IN_BSS | \
2112 FIF_BCN_PRBRESP_PROMISC | \
2116 static void ath10k_configure_filter(struct ieee80211_hw *hw,
2117 unsigned int changed_flags,
2118 unsigned int *total_flags,
2121 struct ath10k *ar = hw->priv;
2124 mutex_lock(&ar->conf_mutex);
2126 changed_flags &= SUPPORTED_FILTERS;
2127 *total_flags &= SUPPORTED_FILTERS;
2128 ar->filter_flags = *total_flags;
2130 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2131 !ar->monitor_enabled) {
2132 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d start\n",
2133 ar->monitor_vdev_id);
2135 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
2137 ath10k_warn("Unable to start monitor mode\n");
2138 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
2139 ar->monitor_enabled) {
2140 ath10k_dbg(ATH10K_DBG_MAC, "mac monitor %d stop\n",
2141 ar->monitor_vdev_id);
2143 ret = ath10k_monitor_stop(ar);
2145 ath10k_warn("Unable to stop monitor mode\n");
2148 mutex_unlock(&ar->conf_mutex);
2151 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2152 struct ieee80211_vif *vif,
2153 struct ieee80211_bss_conf *info,
2156 struct ath10k *ar = hw->priv;
2157 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2160 mutex_lock(&ar->conf_mutex);
2162 if (changed & BSS_CHANGED_IBSS)
2163 ath10k_control_ibss(arvif, info, vif->addr);
2165 if (changed & BSS_CHANGED_BEACON_INT) {
2166 arvif->beacon_interval = info->beacon_int;
2167 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2168 WMI_VDEV_PARAM_BEACON_INTERVAL,
2169 arvif->beacon_interval);
2170 ath10k_dbg(ATH10K_DBG_MAC,
2171 "mac vdev %d beacon_interval %d\n",
2172 arvif->vdev_id, arvif->beacon_interval);
2175 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2179 if (changed & BSS_CHANGED_BEACON) {
2180 ath10k_dbg(ATH10K_DBG_MAC,
2181 "vdev %d set beacon tx mode to staggered\n",
2184 ret = ath10k_wmi_pdev_set_param(ar,
2185 WMI_PDEV_PARAM_BEACON_TX_MODE,
2186 WMI_BEACON_STAGGERED_MODE);
2188 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2192 if (changed & BSS_CHANGED_BEACON_INFO) {
2193 arvif->dtim_period = info->dtim_period;
2195 ath10k_dbg(ATH10K_DBG_MAC,
2196 "mac vdev %d dtim_period %d\n",
2197 arvif->vdev_id, arvif->dtim_period);
2199 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2200 WMI_VDEV_PARAM_DTIM_PERIOD,
2201 arvif->dtim_period);
2203 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2207 if (changed & BSS_CHANGED_SSID &&
2208 vif->type == NL80211_IFTYPE_AP) {
2209 arvif->u.ap.ssid_len = info->ssid_len;
2211 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2212 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2215 if (changed & BSS_CHANGED_BSSID) {
2216 if (!is_zero_ether_addr(info->bssid)) {
2217 ath10k_dbg(ATH10K_DBG_MAC,
2218 "mac vdev %d create peer %pM\n",
2219 arvif->vdev_id, info->bssid);
2221 ret = ath10k_peer_create(ar, arvif->vdev_id,
2224 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2225 info->bssid, arvif->vdev_id);
2227 if (vif->type == NL80211_IFTYPE_STATION) {
2229 * this is never erased as we it for crypto key
2230 * clearing; this is FW requirement
2232 memcpy(arvif->u.sta.bssid, info->bssid,
2235 ath10k_dbg(ATH10K_DBG_MAC,
2236 "mac vdev %d start %pM\n",
2237 arvif->vdev_id, info->bssid);
2239 /* FIXME: check return value */
2240 ret = ath10k_vdev_start(arvif);
2244 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2245 * so driver need to store it. It is needed when leaving
2246 * IBSS in order to remove BSSID peer.
2248 if (vif->type == NL80211_IFTYPE_ADHOC)
2249 memcpy(arvif->u.ibss.bssid, info->bssid,
2254 if (changed & BSS_CHANGED_BEACON_ENABLED)
2255 ath10k_control_beaconing(arvif, info);
2257 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2259 if (info->use_cts_prot)
2264 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
2265 arvif->vdev_id, cts_prot);
2267 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2268 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2271 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2275 if (changed & BSS_CHANGED_ERP_SLOT) {
2277 if (info->use_short_slot)
2278 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2281 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2283 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
2284 arvif->vdev_id, slottime);
2286 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2287 WMI_VDEV_PARAM_SLOT_TIME,
2290 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2294 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2296 if (info->use_short_preamble)
2297 preamble = WMI_VDEV_PREAMBLE_SHORT;
2299 preamble = WMI_VDEV_PREAMBLE_LONG;
2301 ath10k_dbg(ATH10K_DBG_MAC,
2302 "mac vdev %d preamble %dn",
2303 arvif->vdev_id, preamble);
2305 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2306 WMI_VDEV_PARAM_PREAMBLE,
2309 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2313 if (changed & BSS_CHANGED_ASSOC) {
2315 ath10k_bss_assoc(hw, vif, info);
2318 mutex_unlock(&ar->conf_mutex);
2321 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2322 struct ieee80211_vif *vif,
2323 struct cfg80211_scan_request *req)
2325 struct ath10k *ar = hw->priv;
2326 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2327 struct wmi_start_scan_arg arg;
2331 mutex_lock(&ar->conf_mutex);
2333 spin_lock_bh(&ar->data_lock);
2334 if (ar->scan.in_progress) {
2335 spin_unlock_bh(&ar->data_lock);
2340 INIT_COMPLETION(ar->scan.started);
2341 INIT_COMPLETION(ar->scan.completed);
2342 ar->scan.in_progress = true;
2343 ar->scan.aborting = false;
2344 ar->scan.is_roc = false;
2345 ar->scan.vdev_id = arvif->vdev_id;
2346 spin_unlock_bh(&ar->data_lock);
2348 memset(&arg, 0, sizeof(arg));
2349 ath10k_wmi_start_scan_init(ar, &arg);
2350 arg.vdev_id = arvif->vdev_id;
2351 arg.scan_id = ATH10K_SCAN_ID;
2354 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2357 arg.ie_len = req->ie_len;
2358 memcpy(arg.ie, req->ie, arg.ie_len);
2362 arg.n_ssids = req->n_ssids;
2363 for (i = 0; i < arg.n_ssids; i++) {
2364 arg.ssids[i].len = req->ssids[i].ssid_len;
2365 arg.ssids[i].ssid = req->ssids[i].ssid;
2368 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2371 if (req->n_channels) {
2372 arg.n_channels = req->n_channels;
2373 for (i = 0; i < arg.n_channels; i++)
2374 arg.channels[i] = req->channels[i]->center_freq;
2377 ret = ath10k_start_scan(ar, &arg);
2379 ath10k_warn("could not start hw scan (%d)\n", ret);
2380 spin_lock_bh(&ar->data_lock);
2381 ar->scan.in_progress = false;
2382 spin_unlock_bh(&ar->data_lock);
2386 mutex_unlock(&ar->conf_mutex);
2390 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2391 struct ieee80211_vif *vif)
2393 struct ath10k *ar = hw->priv;
2396 mutex_lock(&ar->conf_mutex);
2397 ret = ath10k_abort_scan(ar);
2399 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2401 ieee80211_scan_completed(hw, 1 /* aborted */);
2403 mutex_unlock(&ar->conf_mutex);
2406 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2407 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2408 struct ieee80211_key_conf *key)
2410 struct ath10k *ar = hw->priv;
2411 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2412 struct ath10k_peer *peer;
2413 const u8 *peer_addr;
2414 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2415 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2418 if (key->keyidx > WMI_MAX_KEY_INDEX)
2421 mutex_lock(&ar->conf_mutex);
2424 peer_addr = sta->addr;
2425 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2426 peer_addr = vif->bss_conf.bssid;
2428 peer_addr = vif->addr;
2430 key->hw_key_idx = key->keyidx;
2432 /* the peer should not disappear in mid-way (unless FW goes awry) since
2433 * we already hold conf_mutex. we just make sure its there now. */
2434 spin_lock_bh(&ar->data_lock);
2435 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2436 spin_unlock_bh(&ar->data_lock);
2439 if (cmd == SET_KEY) {
2440 ath10k_warn("cannot install key for non-existent peer %pM\n",
2445 /* if the peer doesn't exist there is no key to disable
2453 arvif->wep_keys[key->keyidx] = key;
2455 arvif->wep_keys[key->keyidx] = NULL;
2457 if (cmd == DISABLE_KEY)
2458 ath10k_clear_vdev_key(arvif, key);
2461 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2463 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2467 spin_lock_bh(&ar->data_lock);
2468 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2469 if (peer && cmd == SET_KEY)
2470 peer->keys[key->keyidx] = key;
2471 else if (peer && cmd == DISABLE_KEY)
2472 peer->keys[key->keyidx] = NULL;
2473 else if (peer == NULL)
2474 /* impossible unless FW goes crazy */
2475 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2476 spin_unlock_bh(&ar->data_lock);
2479 mutex_unlock(&ar->conf_mutex);
2483 static int ath10k_sta_state(struct ieee80211_hw *hw,
2484 struct ieee80211_vif *vif,
2485 struct ieee80211_sta *sta,
2486 enum ieee80211_sta_state old_state,
2487 enum ieee80211_sta_state new_state)
2489 struct ath10k *ar = hw->priv;
2490 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2493 mutex_lock(&ar->conf_mutex);
2495 if (old_state == IEEE80211_STA_NOTEXIST &&
2496 new_state == IEEE80211_STA_NONE &&
2497 vif->type != NL80211_IFTYPE_STATION) {
2499 * New station addition.
2501 ath10k_dbg(ATH10K_DBG_MAC,
2502 "mac vdev %d peer create %pM (new sta)\n",
2503 arvif->vdev_id, sta->addr);
2505 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2507 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2508 sta->addr, arvif->vdev_id);
2509 } else if ((old_state == IEEE80211_STA_NONE &&
2510 new_state == IEEE80211_STA_NOTEXIST)) {
2512 * Existing station deletion.
2514 ath10k_dbg(ATH10K_DBG_MAC,
2515 "mac vdev %d peer delete %pM (sta gone)\n",
2516 arvif->vdev_id, sta->addr);
2517 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2519 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2520 sta->addr, arvif->vdev_id);
2522 if (vif->type == NL80211_IFTYPE_STATION)
2523 ath10k_bss_disassoc(hw, vif);
2524 } else if (old_state == IEEE80211_STA_AUTH &&
2525 new_state == IEEE80211_STA_ASSOC &&
2526 (vif->type == NL80211_IFTYPE_AP ||
2527 vif->type == NL80211_IFTYPE_ADHOC)) {
2531 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM associated\n",
2534 ret = ath10k_station_assoc(ar, arvif, sta);
2536 ath10k_warn("Failed to associate station: %pM\n",
2538 } else if (old_state == IEEE80211_STA_ASSOC &&
2539 new_state == IEEE80211_STA_AUTH &&
2540 (vif->type == NL80211_IFTYPE_AP ||
2541 vif->type == NL80211_IFTYPE_ADHOC)) {
2545 ath10k_dbg(ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
2548 ret = ath10k_station_disassoc(ar, arvif, sta);
2550 ath10k_warn("Failed to disassociate station: %pM\n",
2554 mutex_unlock(&ar->conf_mutex);
2558 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2559 u16 ac, bool enable)
2561 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2565 lockdep_assert_held(&ar->conf_mutex);
2567 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2571 case IEEE80211_AC_VO:
2572 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2573 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2575 case IEEE80211_AC_VI:
2576 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2577 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2579 case IEEE80211_AC_BE:
2580 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2581 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2583 case IEEE80211_AC_BK:
2584 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2585 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2590 arvif->u.sta.uapsd |= value;
2592 arvif->u.sta.uapsd &= ~value;
2594 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2595 WMI_STA_PS_PARAM_UAPSD,
2596 arvif->u.sta.uapsd);
2598 ath10k_warn("could not set uapsd params %d\n", ret);
2602 if (arvif->u.sta.uapsd)
2603 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2605 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2607 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2608 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2611 ath10k_warn("could not set rx wake param %d\n", ret);
2617 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2618 struct ieee80211_vif *vif, u16 ac,
2619 const struct ieee80211_tx_queue_params *params)
2621 struct ath10k *ar = hw->priv;
2622 struct wmi_wmm_params_arg *p = NULL;
2625 mutex_lock(&ar->conf_mutex);
2628 case IEEE80211_AC_VO:
2629 p = &ar->wmm_params.ac_vo;
2631 case IEEE80211_AC_VI:
2632 p = &ar->wmm_params.ac_vi;
2634 case IEEE80211_AC_BE:
2635 p = &ar->wmm_params.ac_be;
2637 case IEEE80211_AC_BK:
2638 p = &ar->wmm_params.ac_bk;
2647 p->cwmin = params->cw_min;
2648 p->cwmax = params->cw_max;
2649 p->aifs = params->aifs;
2652 * The channel time duration programmed in the HW is in absolute
2653 * microseconds, while mac80211 gives the txop in units of
2656 p->txop = params->txop * 32;
2658 /* FIXME: FW accepts wmm params per hw, not per vif */
2659 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2661 ath10k_warn("could not set wmm params %d\n", ret);
2665 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2667 ath10k_warn("could not set sta uapsd %d\n", ret);
2670 mutex_unlock(&ar->conf_mutex);
2674 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2676 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2677 struct ieee80211_vif *vif,
2678 struct ieee80211_channel *chan,
2680 enum ieee80211_roc_type type)
2682 struct ath10k *ar = hw->priv;
2683 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2684 struct wmi_start_scan_arg arg;
2687 mutex_lock(&ar->conf_mutex);
2689 spin_lock_bh(&ar->data_lock);
2690 if (ar->scan.in_progress) {
2691 spin_unlock_bh(&ar->data_lock);
2696 INIT_COMPLETION(ar->scan.started);
2697 INIT_COMPLETION(ar->scan.completed);
2698 INIT_COMPLETION(ar->scan.on_channel);
2699 ar->scan.in_progress = true;
2700 ar->scan.aborting = false;
2701 ar->scan.is_roc = true;
2702 ar->scan.vdev_id = arvif->vdev_id;
2703 ar->scan.roc_freq = chan->center_freq;
2704 spin_unlock_bh(&ar->data_lock);
2706 memset(&arg, 0, sizeof(arg));
2707 ath10k_wmi_start_scan_init(ar, &arg);
2708 arg.vdev_id = arvif->vdev_id;
2709 arg.scan_id = ATH10K_SCAN_ID;
2711 arg.channels[0] = chan->center_freq;
2712 arg.dwell_time_active = duration;
2713 arg.dwell_time_passive = duration;
2714 arg.max_scan_time = 2 * duration;
2715 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2716 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2718 ret = ath10k_start_scan(ar, &arg);
2720 ath10k_warn("could not start roc scan (%d)\n", ret);
2721 spin_lock_bh(&ar->data_lock);
2722 ar->scan.in_progress = false;
2723 spin_unlock_bh(&ar->data_lock);
2727 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2729 ath10k_warn("could not switch to channel for roc scan\n");
2730 ath10k_abort_scan(ar);
2737 mutex_unlock(&ar->conf_mutex);
2741 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2743 struct ath10k *ar = hw->priv;
2745 mutex_lock(&ar->conf_mutex);
2746 ath10k_abort_scan(ar);
2747 mutex_unlock(&ar->conf_mutex);
2753 * Both RTS and Fragmentation threshold are interface-specific
2754 * in ath10k, but device-specific in mac80211.
2756 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2758 struct ath10k_generic_iter *ar_iter = data;
2759 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2760 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2762 lockdep_assert_held(&arvif->ar->conf_mutex);
2764 /* During HW reconfiguration mac80211 reports all interfaces that were
2765 * running until reconfiguration was started. Since FW doesn't have any
2766 * vdevs at this point we must not iterate over this interface list.
2767 * This setting will be updated upon add_interface(). */
2768 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2771 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d rts_threshold %d\n",
2772 arvif->vdev_id, rts);
2774 ar_iter->ret = ath10k_mac_set_rts(arvif, rts);
2776 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2780 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2782 struct ath10k_generic_iter ar_iter;
2783 struct ath10k *ar = hw->priv;
2785 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2788 mutex_lock(&ar->conf_mutex);
2789 ieee80211_iterate_active_interfaces_atomic(
2790 hw, IEEE80211_IFACE_ITER_NORMAL,
2791 ath10k_set_rts_iter, &ar_iter);
2792 mutex_unlock(&ar->conf_mutex);
2797 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2799 struct ath10k_generic_iter *ar_iter = data;
2800 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2801 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2803 lockdep_assert_held(&arvif->ar->conf_mutex);
2805 /* During HW reconfiguration mac80211 reports all interfaces that were
2806 * running until reconfiguration was started. Since FW doesn't have any
2807 * vdevs at this point we must not iterate over this interface list.
2808 * This setting will be updated upon add_interface(). */
2809 if (ar_iter->ar->state == ATH10K_STATE_RESTARTED)
2812 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d fragmentation_threshold %d\n",
2813 arvif->vdev_id, frag);
2815 ar_iter->ret = ath10k_mac_set_frag(arvif, frag);
2817 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2821 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2823 struct ath10k_generic_iter ar_iter;
2824 struct ath10k *ar = hw->priv;
2826 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2829 mutex_lock(&ar->conf_mutex);
2830 ieee80211_iterate_active_interfaces_atomic(
2831 hw, IEEE80211_IFACE_ITER_NORMAL,
2832 ath10k_set_frag_iter, &ar_iter);
2833 mutex_unlock(&ar->conf_mutex);
2838 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2840 struct ath10k *ar = hw->priv;
2844 /* mac80211 doesn't care if we really xmit queued frames or not
2845 * we'll collect those frames either way if we stop/delete vdevs */
2849 mutex_lock(&ar->conf_mutex);
2851 if (ar->state == ATH10K_STATE_WEDGED)
2854 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
2857 spin_lock_bh(&ar->htt.tx_lock);
2858 empty = (ar->htt.num_pending_tx == 0);
2859 spin_unlock_bh(&ar->htt.tx_lock);
2861 skip = (ar->state == ATH10K_STATE_WEDGED);
2864 }), ATH10K_FLUSH_TIMEOUT_HZ);
2866 if (ret <= 0 || skip)
2867 ath10k_warn("tx not flushed\n");
2870 mutex_unlock(&ar->conf_mutex);
2873 /* TODO: Implement this function properly
2874 * For now it is needed to reply to Probe Requests in IBSS mode.
2875 * Propably we need this information from FW.
2877 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2883 static int ath10k_suspend(struct ieee80211_hw *hw,
2884 struct cfg80211_wowlan *wowlan)
2886 struct ath10k *ar = hw->priv;
2889 ar->is_target_paused = false;
2891 ret = ath10k_wmi_pdev_suspend_target(ar);
2893 ath10k_warn("could not suspend target (%d)\n", ret);
2897 ret = wait_event_interruptible_timeout(ar->event_queue,
2898 ar->is_target_paused == true,
2901 ath10k_warn("suspend interrupted (%d)\n", ret);
2903 } else if (ret == 0) {
2904 ath10k_warn("suspend timed out - target pause event never came\n");
2908 ret = ath10k_hif_suspend(ar);
2910 ath10k_warn("could not suspend hif (%d)\n", ret);
2916 ret = ath10k_wmi_pdev_resume_target(ar);
2918 ath10k_warn("could not resume target (%d)\n", ret);
2922 static int ath10k_resume(struct ieee80211_hw *hw)
2924 struct ath10k *ar = hw->priv;
2927 ret = ath10k_hif_resume(ar);
2929 ath10k_warn("could not resume hif (%d)\n", ret);
2933 ret = ath10k_wmi_pdev_resume_target(ar);
2935 ath10k_warn("could not resume target (%d)\n", ret);
2943 static void ath10k_restart_complete(struct ieee80211_hw *hw)
2945 struct ath10k *ar = hw->priv;
2947 mutex_lock(&ar->conf_mutex);
2949 /* If device failed to restart it will be in a different state, e.g.
2950 * ATH10K_STATE_WEDGED */
2951 if (ar->state == ATH10K_STATE_RESTARTED) {
2952 ath10k_info("device successfully recovered\n");
2953 ar->state = ATH10K_STATE_ON;
2956 mutex_unlock(&ar->conf_mutex);
2959 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
2960 struct survey_info *survey)
2962 struct ath10k *ar = hw->priv;
2963 struct ieee80211_supported_band *sband;
2964 struct survey_info *ar_survey = &ar->survey[idx];
2967 mutex_lock(&ar->conf_mutex);
2969 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
2970 if (sband && idx >= sband->n_channels) {
2971 idx -= sband->n_channels;
2976 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
2978 if (!sband || idx >= sband->n_channels) {
2983 spin_lock_bh(&ar->data_lock);
2984 memcpy(survey, ar_survey, sizeof(*survey));
2985 spin_unlock_bh(&ar->data_lock);
2987 survey->channel = &sband->channels[idx];
2990 mutex_unlock(&ar->conf_mutex);
2994 static const struct ieee80211_ops ath10k_ops = {
2996 .start = ath10k_start,
2997 .stop = ath10k_stop,
2998 .config = ath10k_config,
2999 .add_interface = ath10k_add_interface,
3000 .remove_interface = ath10k_remove_interface,
3001 .configure_filter = ath10k_configure_filter,
3002 .bss_info_changed = ath10k_bss_info_changed,
3003 .hw_scan = ath10k_hw_scan,
3004 .cancel_hw_scan = ath10k_cancel_hw_scan,
3005 .set_key = ath10k_set_key,
3006 .sta_state = ath10k_sta_state,
3007 .conf_tx = ath10k_conf_tx,
3008 .remain_on_channel = ath10k_remain_on_channel,
3009 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
3010 .set_rts_threshold = ath10k_set_rts_threshold,
3011 .set_frag_threshold = ath10k_set_frag_threshold,
3012 .flush = ath10k_flush,
3013 .tx_last_beacon = ath10k_tx_last_beacon,
3014 .restart_complete = ath10k_restart_complete,
3015 .get_survey = ath10k_get_survey,
3017 .suspend = ath10k_suspend,
3018 .resume = ath10k_resume,
3022 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3023 .bitrate = (_rate), \
3024 .flags = (_flags), \
3025 .hw_value = (_rateid), \
3028 #define CHAN2G(_channel, _freq, _flags) { \
3029 .band = IEEE80211_BAND_2GHZ, \
3030 .hw_value = (_channel), \
3031 .center_freq = (_freq), \
3032 .flags = (_flags), \
3033 .max_antenna_gain = 0, \
3037 #define CHAN5G(_channel, _freq, _flags) { \
3038 .band = IEEE80211_BAND_5GHZ, \
3039 .hw_value = (_channel), \
3040 .center_freq = (_freq), \
3041 .flags = (_flags), \
3042 .max_antenna_gain = 0, \
3046 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
3056 CHAN2G(10, 2457, 0),
3057 CHAN2G(11, 2462, 0),
3058 CHAN2G(12, 2467, 0),
3059 CHAN2G(13, 2472, 0),
3060 CHAN2G(14, 2484, 0),
3063 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
3064 CHAN5G(36, 5180, 0),
3065 CHAN5G(40, 5200, 0),
3066 CHAN5G(44, 5220, 0),
3067 CHAN5G(48, 5240, 0),
3068 CHAN5G(52, 5260, 0),
3069 CHAN5G(56, 5280, 0),
3070 CHAN5G(60, 5300, 0),
3071 CHAN5G(64, 5320, 0),
3072 CHAN5G(100, 5500, 0),
3073 CHAN5G(104, 5520, 0),
3074 CHAN5G(108, 5540, 0),
3075 CHAN5G(112, 5560, 0),
3076 CHAN5G(116, 5580, 0),
3077 CHAN5G(120, 5600, 0),
3078 CHAN5G(124, 5620, 0),
3079 CHAN5G(128, 5640, 0),
3080 CHAN5G(132, 5660, 0),
3081 CHAN5G(136, 5680, 0),
3082 CHAN5G(140, 5700, 0),
3083 CHAN5G(149, 5745, 0),
3084 CHAN5G(153, 5765, 0),
3085 CHAN5G(157, 5785, 0),
3086 CHAN5G(161, 5805, 0),
3087 CHAN5G(165, 5825, 0),
3090 static struct ieee80211_rate ath10k_rates[] = {
3092 RATETAB_ENT(10, 0x82, 0),
3093 RATETAB_ENT(20, 0x84, 0),
3094 RATETAB_ENT(55, 0x8b, 0),
3095 RATETAB_ENT(110, 0x96, 0),
3097 RATETAB_ENT(60, 0x0c, 0),
3098 RATETAB_ENT(90, 0x12, 0),
3099 RATETAB_ENT(120, 0x18, 0),
3100 RATETAB_ENT(180, 0x24, 0),
3101 RATETAB_ENT(240, 0x30, 0),
3102 RATETAB_ENT(360, 0x48, 0),
3103 RATETAB_ENT(480, 0x60, 0),
3104 RATETAB_ENT(540, 0x6c, 0),
3107 #define ath10k_a_rates (ath10k_rates + 4)
3108 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3109 #define ath10k_g_rates (ath10k_rates + 0)
3110 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3112 struct ath10k *ath10k_mac_create(void)
3114 struct ieee80211_hw *hw;
3117 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
3127 void ath10k_mac_destroy(struct ath10k *ar)
3129 ieee80211_free_hw(ar->hw);
3132 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
3135 .types = BIT(NL80211_IFTYPE_STATION)
3136 | BIT(NL80211_IFTYPE_P2P_CLIENT)
3140 .types = BIT(NL80211_IFTYPE_P2P_GO)
3144 .types = BIT(NL80211_IFTYPE_AP)
3148 static const struct ieee80211_iface_combination ath10k_if_comb = {
3149 .limits = ath10k_if_limits,
3150 .n_limits = ARRAY_SIZE(ath10k_if_limits),
3151 .max_interfaces = 8,
3152 .num_different_channels = 1,
3153 .beacon_int_infra_match = true,
3156 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
3158 struct ieee80211_sta_vht_cap vht_cap = {0};
3162 vht_cap.vht_supported = 1;
3163 vht_cap.cap = ar->vht_cap_info;
3166 for (i = 0; i < 8; i++) {
3167 if (i < ar->num_rf_chains)
3168 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
3170 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
3173 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
3174 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
3179 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
3182 struct ieee80211_sta_ht_cap ht_cap = {0};
3184 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
3187 ht_cap.ht_supported = 1;
3188 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3189 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
3190 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3191 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3192 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3194 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
3195 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3197 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
3198 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3200 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
3203 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3204 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3209 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
3210 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3212 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
3215 stbc = ar->ht_cap_info;
3216 stbc &= WMI_HT_CAP_RX_STBC;
3217 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3218 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3219 stbc &= IEEE80211_HT_CAP_RX_STBC;
3224 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
3225 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3227 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
3228 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3230 /* max AMSDU is implicitly taken from vht_cap_info */
3231 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3232 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3234 for (i = 0; i < ar->num_rf_chains; i++)
3235 ht_cap.mcs.rx_mask[i] = 0xFF;
3237 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3243 static void ath10k_get_arvif_iter(void *data, u8 *mac,
3244 struct ieee80211_vif *vif)
3246 struct ath10k_vif_iter *arvif_iter = data;
3247 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3249 if (arvif->vdev_id == arvif_iter->vdev_id)
3250 arvif_iter->arvif = arvif;
3253 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
3255 struct ath10k_vif_iter arvif_iter;
3258 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
3259 arvif_iter.vdev_id = vdev_id;
3261 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
3262 ieee80211_iterate_active_interfaces_atomic(ar->hw,
3264 ath10k_get_arvif_iter,
3266 if (!arvif_iter.arvif) {
3267 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
3271 return arvif_iter.arvif;
3274 int ath10k_mac_register(struct ath10k *ar)
3276 struct ieee80211_supported_band *band;
3277 struct ieee80211_sta_vht_cap vht_cap;
3278 struct ieee80211_sta_ht_cap ht_cap;
3282 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
3284 SET_IEEE80211_DEV(ar->hw, ar->dev);
3286 ht_cap = ath10k_get_ht_cap(ar);
3287 vht_cap = ath10k_create_vht_cap(ar);
3289 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
3290 channels = kmemdup(ath10k_2ghz_channels,
3291 sizeof(ath10k_2ghz_channels),
3298 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
3299 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
3300 band->channels = channels;
3301 band->n_bitrates = ath10k_g_rates_size;
3302 band->bitrates = ath10k_g_rates;
3303 band->ht_cap = ht_cap;
3305 /* vht is not supported in 2.4 GHz */
3307 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
3310 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
3311 channels = kmemdup(ath10k_5ghz_channels,
3312 sizeof(ath10k_5ghz_channels),
3319 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
3320 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3321 band->channels = channels;
3322 band->n_bitrates = ath10k_a_rates_size;
3323 band->bitrates = ath10k_a_rates;
3324 band->ht_cap = ht_cap;
3325 band->vht_cap = vht_cap;
3326 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3329 ar->hw->wiphy->interface_modes =
3330 BIT(NL80211_IFTYPE_STATION) |
3331 BIT(NL80211_IFTYPE_ADHOC) |
3332 BIT(NL80211_IFTYPE_AP) |
3333 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3334 BIT(NL80211_IFTYPE_P2P_GO);
3336 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3337 IEEE80211_HW_SUPPORTS_PS |
3338 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3339 IEEE80211_HW_SUPPORTS_UAPSD |
3340 IEEE80211_HW_MFP_CAPABLE |
3341 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3342 IEEE80211_HW_HAS_RATE_CONTROL |
3343 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3344 IEEE80211_HW_WANT_MONITOR_VIF |
3345 IEEE80211_HW_AP_LINK_PS;
3347 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3348 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3350 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3351 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3352 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3355 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3356 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3358 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3360 ar->hw->channel_change_time = 5000;
3361 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3363 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3364 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3366 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3368 * on LL hardware queues are managed entirely by the FW
3369 * so we only advertise to mac we can do the queues thing
3373 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3374 ar->hw->wiphy->n_iface_combinations = 1;
3376 ar->hw->netdev_features = NETIF_F_HW_CSUM;
3378 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3379 ath10k_reg_notifier);
3381 ath10k_err("Regulatory initialization failed\n");
3385 ret = ieee80211_register_hw(ar->hw);
3387 ath10k_err("ieee80211 registration failed: %d\n", ret);
3391 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3392 ret = regulatory_hint(ar->hw->wiphy,
3393 ar->ath_common.regulatory.alpha2);
3395 goto err_unregister;
3401 ieee80211_unregister_hw(ar->hw);
3403 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3404 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3409 void ath10k_mac_unregister(struct ath10k *ar)
3411 ieee80211_unregister_hw(ar->hw);
3413 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3414 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3416 SET_IEEE80211_DEV(ar->hw, NULL);