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>
33 static int ath10k_send_key(struct ath10k_vif *arvif,
34 struct ieee80211_key_conf *key,
38 struct wmi_vdev_install_key_arg arg = {
39 .vdev_id = arvif->vdev_id,
40 .key_idx = key->keyidx,
41 .key_len = key->keylen,
46 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
47 arg.key_flags = WMI_KEY_PAIRWISE;
49 arg.key_flags = WMI_KEY_GROUP;
51 switch (key->cipher) {
52 case WLAN_CIPHER_SUITE_CCMP:
53 arg.key_cipher = WMI_CIPHER_AES_CCM;
54 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
56 case WLAN_CIPHER_SUITE_TKIP:
57 arg.key_cipher = WMI_CIPHER_TKIP;
58 arg.key_txmic_len = 8;
59 arg.key_rxmic_len = 8;
61 case WLAN_CIPHER_SUITE_WEP40:
62 case WLAN_CIPHER_SUITE_WEP104:
63 arg.key_cipher = WMI_CIPHER_WEP;
64 /* AP/IBSS mode requires self-key to be groupwise
65 * Otherwise pairwise key must be set */
66 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
67 arg.key_flags = WMI_KEY_PAIRWISE;
70 ath10k_warn("cipher %d is not supported\n", key->cipher);
74 if (cmd == DISABLE_KEY) {
75 arg.key_cipher = WMI_CIPHER_NONE;
79 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
82 static int ath10k_install_key(struct ath10k_vif *arvif,
83 struct ieee80211_key_conf *key,
87 struct ath10k *ar = arvif->ar;
90 INIT_COMPLETION(ar->install_key_done);
92 ret = ath10k_send_key(arvif, key, cmd, macaddr);
96 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
103 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
106 struct ath10k *ar = arvif->ar;
107 struct ath10k_peer *peer;
111 lockdep_assert_held(&ar->conf_mutex);
113 spin_lock_bh(&ar->data_lock);
114 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
115 spin_unlock_bh(&ar->data_lock);
120 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
121 if (arvif->wep_keys[i] == NULL)
124 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
129 peer->keys[i] = arvif->wep_keys[i];
135 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
138 struct ath10k *ar = arvif->ar;
139 struct ath10k_peer *peer;
144 lockdep_assert_held(&ar->conf_mutex);
146 spin_lock_bh(&ar->data_lock);
147 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
148 spin_unlock_bh(&ar->data_lock);
153 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
154 if (peer->keys[i] == NULL)
157 ret = ath10k_install_key(arvif, peer->keys[i],
159 if (ret && first_errno == 0)
163 ath10k_warn("could not remove peer wep key %d (%d)\n",
166 peer->keys[i] = NULL;
172 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
173 struct ieee80211_key_conf *key)
175 struct ath10k *ar = arvif->ar;
176 struct ath10k_peer *peer;
182 lockdep_assert_held(&ar->conf_mutex);
185 /* since ath10k_install_key we can't hold data_lock all the
186 * time, so we try to remove the keys incrementally */
187 spin_lock_bh(&ar->data_lock);
189 list_for_each_entry(peer, &ar->peers, list) {
190 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
191 if (peer->keys[i] == key) {
192 memcpy(addr, peer->addr, ETH_ALEN);
193 peer->keys[i] = NULL;
198 if (i < ARRAY_SIZE(peer->keys))
201 spin_unlock_bh(&ar->data_lock);
203 if (i == ARRAY_SIZE(peer->keys))
206 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
207 if (ret && first_errno == 0)
211 ath10k_warn("could not remove key for %pM\n", addr);
218 /*********************/
219 /* General utilities */
220 /*********************/
222 static inline enum wmi_phy_mode
223 chan_to_phymode(const struct cfg80211_chan_def *chandef)
225 enum wmi_phy_mode phymode = MODE_UNKNOWN;
227 switch (chandef->chan->band) {
228 case IEEE80211_BAND_2GHZ:
229 switch (chandef->width) {
230 case NL80211_CHAN_WIDTH_20_NOHT:
233 case NL80211_CHAN_WIDTH_20:
234 phymode = MODE_11NG_HT20;
236 case NL80211_CHAN_WIDTH_40:
237 phymode = MODE_11NG_HT40;
239 case NL80211_CHAN_WIDTH_5:
240 case NL80211_CHAN_WIDTH_10:
241 case NL80211_CHAN_WIDTH_80:
242 case NL80211_CHAN_WIDTH_80P80:
243 case NL80211_CHAN_WIDTH_160:
244 phymode = MODE_UNKNOWN;
248 case IEEE80211_BAND_5GHZ:
249 switch (chandef->width) {
250 case NL80211_CHAN_WIDTH_20_NOHT:
253 case NL80211_CHAN_WIDTH_20:
254 phymode = MODE_11NA_HT20;
256 case NL80211_CHAN_WIDTH_40:
257 phymode = MODE_11NA_HT40;
259 case NL80211_CHAN_WIDTH_80:
260 phymode = MODE_11AC_VHT80;
262 case NL80211_CHAN_WIDTH_5:
263 case NL80211_CHAN_WIDTH_10:
264 case NL80211_CHAN_WIDTH_80P80:
265 case NL80211_CHAN_WIDTH_160:
266 phymode = MODE_UNKNOWN;
274 WARN_ON(phymode == MODE_UNKNOWN);
278 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
281 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
282 * 0 for no restriction
291 switch (mpdudensity) {
297 /* Our lower layer calculations limit our precision to
313 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
317 lockdep_assert_held(&ar->conf_mutex);
319 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
323 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
330 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
334 lockdep_assert_held(&ar->conf_mutex);
336 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
340 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
347 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
349 struct ath10k_peer *peer, *tmp;
351 lockdep_assert_held(&ar->conf_mutex);
353 spin_lock_bh(&ar->data_lock);
354 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
355 if (peer->vdev_id != vdev_id)
358 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
359 peer->addr, vdev_id);
361 list_del(&peer->list);
364 spin_unlock_bh(&ar->data_lock);
367 /************************/
368 /* Interface management */
369 /************************/
371 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
375 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
376 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
383 static int ath10k_vdev_start(struct ath10k_vif *arvif)
385 struct ath10k *ar = arvif->ar;
386 struct ieee80211_conf *conf = &ar->hw->conf;
387 struct ieee80211_channel *channel = conf->chandef.chan;
388 struct wmi_vdev_start_request_arg arg = {};
391 lockdep_assert_held(&ar->conf_mutex);
393 INIT_COMPLETION(ar->vdev_setup_done);
395 arg.vdev_id = arvif->vdev_id;
396 arg.dtim_period = arvif->dtim_period;
397 arg.bcn_intval = arvif->beacon_interval;
399 arg.channel.freq = channel->center_freq;
401 arg.channel.band_center_freq1 = conf->chandef.center_freq1;
403 arg.channel.mode = chan_to_phymode(&conf->chandef);
405 arg.channel.min_power = channel->max_power * 3;
406 arg.channel.max_power = channel->max_power * 4;
407 arg.channel.max_reg_power = channel->max_reg_power * 4;
408 arg.channel.max_antenna_gain = channel->max_antenna_gain;
410 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
411 arg.ssid = arvif->u.ap.ssid;
412 arg.ssid_len = arvif->u.ap.ssid_len;
413 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
414 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
415 arg.ssid = arvif->vif->bss_conf.ssid;
416 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
419 ret = ath10k_wmi_vdev_start(ar, &arg);
421 ath10k_warn("WMI vdev start failed: ret %d\n", ret);
425 ret = ath10k_vdev_setup_sync(ar);
427 ath10k_warn("vdev setup failed %d\n", ret);
434 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
436 struct ath10k *ar = arvif->ar;
439 lockdep_assert_held(&ar->conf_mutex);
441 INIT_COMPLETION(ar->vdev_setup_done);
443 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
445 ath10k_warn("WMI vdev stop failed: ret %d\n", ret);
449 ret = ath10k_vdev_setup_sync(ar);
451 ath10k_warn("vdev setup failed %d\n", ret);
458 static int ath10k_monitor_start(struct ath10k *ar, int vdev_id)
460 struct ieee80211_channel *channel = ar->hw->conf.chandef.chan;
461 struct wmi_vdev_start_request_arg arg = {};
462 enum nl80211_channel_type type;
465 lockdep_assert_held(&ar->conf_mutex);
467 type = cfg80211_get_chandef_type(&ar->hw->conf.chandef);
469 arg.vdev_id = vdev_id;
470 arg.channel.freq = channel->center_freq;
471 arg.channel.band_center_freq1 = ar->hw->conf.chandef.center_freq1;
473 /* TODO setup this dynamically, what in case we
474 don't have any vifs? */
475 arg.channel.mode = chan_to_phymode(&ar->hw->conf.chandef);
477 arg.channel.min_power = channel->max_power * 3;
478 arg.channel.max_power = channel->max_power * 4;
479 arg.channel.max_reg_power = channel->max_reg_power * 4;
480 arg.channel.max_antenna_gain = channel->max_antenna_gain;
482 ret = ath10k_wmi_vdev_start(ar, &arg);
484 ath10k_warn("Monitor vdev start failed: ret %d\n", ret);
488 ret = ath10k_vdev_setup_sync(ar);
490 ath10k_warn("Monitor vdev setup failed %d\n", ret);
494 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
496 ath10k_warn("Monitor vdev up failed: %d\n", ret);
500 ar->monitor_vdev_id = vdev_id;
501 ar->monitor_enabled = true;
506 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
508 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
513 static int ath10k_monitor_stop(struct ath10k *ar)
517 lockdep_assert_held(&ar->conf_mutex);
519 /* For some reasons, ath10k_wmi_vdev_down() here couse
520 * often ath10k_wmi_vdev_stop() to fail. Next we could
521 * not run monitor vdev and driver reload
522 * required. Don't see such problems we skip
523 * ath10k_wmi_vdev_down() here.
526 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
528 ath10k_warn("Monitor vdev stop failed: %d\n", ret);
530 ret = ath10k_vdev_setup_sync(ar);
532 ath10k_warn("Monitor_down sync failed: %d\n", ret);
534 ar->monitor_enabled = false;
538 static int ath10k_monitor_create(struct ath10k *ar)
542 lockdep_assert_held(&ar->conf_mutex);
544 if (ar->monitor_present) {
545 ath10k_warn("Monitor mode already enabled\n");
549 bit = ffs(ar->free_vdev_map);
551 ath10k_warn("No free VDEV slots\n");
555 ar->monitor_vdev_id = bit - 1;
556 ar->free_vdev_map &= ~(1 << ar->monitor_vdev_id);
558 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
559 WMI_VDEV_TYPE_MONITOR,
562 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret);
566 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface created, vdev id: %d\n",
567 ar->monitor_vdev_id);
569 ar->monitor_present = true;
574 * Restore the ID to the global map.
576 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
580 static int ath10k_monitor_destroy(struct ath10k *ar)
584 lockdep_assert_held(&ar->conf_mutex);
586 if (!ar->monitor_present)
589 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
591 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret);
595 ar->free_vdev_map |= 1 << (ar->monitor_vdev_id);
596 ar->monitor_present = false;
598 ath10k_dbg(ATH10K_DBG_MAC, "Monitor interface destroyed, vdev id: %d\n",
599 ar->monitor_vdev_id);
603 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
604 struct ieee80211_bss_conf *info)
608 if (!info->enable_beacon) {
609 ath10k_vdev_stop(arvif);
613 arvif->tx_seq_no = 0x1000;
615 ret = ath10k_vdev_start(arvif);
619 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, 0, info->bssid);
621 ath10k_warn("Failed to bring up VDEV: %d\n",
625 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d up\n", arvif->vdev_id);
628 static void ath10k_control_ibss(struct ath10k_vif *arvif,
629 struct ieee80211_bss_conf *info,
630 const u8 self_peer[ETH_ALEN])
634 if (!info->ibss_joined) {
635 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
637 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
638 self_peer, arvif->vdev_id, ret);
640 if (is_zero_ether_addr(arvif->u.ibss.bssid))
643 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id,
644 arvif->u.ibss.bssid);
646 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
647 arvif->u.ibss.bssid, arvif->vdev_id, ret);
651 memset(arvif->u.ibss.bssid, 0, ETH_ALEN);
656 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
658 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
659 self_peer, arvif->vdev_id, ret);
663 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id,
664 WMI_VDEV_PARAM_ATIM_WINDOW,
665 ATH10K_DEFAULT_ATIM);
667 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
668 arvif->vdev_id, ret);
672 * Review this when mac80211 gains per-interface powersave support.
674 static void ath10k_ps_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
676 struct ath10k_generic_iter *ar_iter = data;
677 struct ieee80211_conf *conf = &ar_iter->ar->hw->conf;
678 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
679 enum wmi_sta_powersave_param param;
680 enum wmi_sta_ps_mode psmode;
683 if (vif->type != NL80211_IFTYPE_STATION)
686 if (conf->flags & IEEE80211_CONF_PS) {
687 psmode = WMI_STA_PS_MODE_ENABLED;
688 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
690 ret = ath10k_wmi_set_sta_ps_param(ar_iter->ar,
693 conf->dynamic_ps_timeout);
695 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
702 psmode = WMI_STA_PS_MODE_DISABLED;
705 ar_iter->ret = ath10k_wmi_set_psmode(ar_iter->ar, arvif->vdev_id,
708 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
709 psmode, arvif->vdev_id);
711 ath10k_dbg(ATH10K_DBG_MAC, "Set PS Mode: %d for VDEV: %d\n",
712 psmode, arvif->vdev_id);
715 /**********************/
716 /* Station management */
717 /**********************/
719 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
720 struct ath10k_vif *arvif,
721 struct ieee80211_sta *sta,
722 struct ieee80211_bss_conf *bss_conf,
723 struct wmi_peer_assoc_complete_arg *arg)
725 memcpy(arg->addr, sta->addr, ETH_ALEN);
726 arg->vdev_id = arvif->vdev_id;
727 arg->peer_aid = sta->aid;
728 arg->peer_flags |= WMI_PEER_AUTH;
730 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
732 * Seems FW have problems with Power Save in STA
733 * mode when we setup this parameter to high (eg. 5).
734 * Often we see that FW don't send NULL (with clean P flags)
735 * frame even there is info about buffered frames in beacons.
736 * Sometimes we have to wait more than 10 seconds before FW
737 * will wakeup. Often sending one ping from AP to our device
738 * just fail (more than 50%).
740 * Seems setting this FW parameter to 1 couse FW
741 * will check every beacon and will wakup immediately
742 * after detection buffered data.
744 arg->peer_listen_intval = 1;
746 arg->peer_listen_intval = ar->hw->conf.listen_interval;
748 arg->peer_num_spatial_streams = 1;
751 * The assoc capabilities are available only in managed mode.
753 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && bss_conf)
754 arg->peer_caps = bss_conf->assoc_capability;
757 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
758 struct ath10k_vif *arvif,
759 struct wmi_peer_assoc_complete_arg *arg)
761 struct ieee80211_vif *vif = arvif->vif;
762 struct ieee80211_bss_conf *info = &vif->bss_conf;
763 struct cfg80211_bss *bss;
764 const u8 *rsnie = NULL;
765 const u8 *wpaie = NULL;
767 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
768 info->bssid, NULL, 0, 0, 0);
770 const struct cfg80211_bss_ies *ies;
773 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
775 ies = rcu_dereference(bss->ies);
777 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
778 WLAN_OUI_TYPE_MICROSOFT_WPA,
782 cfg80211_put_bss(ar->hw->wiphy, bss);
785 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
786 if (rsnie || wpaie) {
787 ath10k_dbg(ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
788 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
792 ath10k_dbg(ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
793 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
797 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
798 struct ieee80211_sta *sta,
799 struct wmi_peer_assoc_complete_arg *arg)
801 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
802 const struct ieee80211_supported_band *sband;
803 const struct ieee80211_rate *rates;
807 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
808 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
809 rates = sband->bitrates;
811 rateset->num_rates = 0;
813 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
817 rateset->rates[rateset->num_rates] = rates->hw_value;
818 rateset->num_rates++;
822 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
823 struct ieee80211_sta *sta,
824 struct wmi_peer_assoc_complete_arg *arg)
826 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
830 if (!ht_cap->ht_supported)
833 arg->peer_flags |= WMI_PEER_HT;
834 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
835 ht_cap->ampdu_factor)) - 1;
837 arg->peer_mpdu_density =
838 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
840 arg->peer_ht_caps = ht_cap->cap;
841 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
843 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
844 arg->peer_flags |= WMI_PEER_LDPC;
846 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
847 arg->peer_flags |= WMI_PEER_40MHZ;
848 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
851 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
852 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
854 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
855 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
857 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
858 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
859 arg->peer_flags |= WMI_PEER_STBC;
862 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
864 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
865 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
866 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
867 arg->peer_rate_caps |= stbc;
868 arg->peer_flags |= WMI_PEER_STBC;
871 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
872 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
874 if (smps == WLAN_HT_CAP_SM_PS_STATIC) {
875 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
876 arg->peer_flags |= WMI_PEER_STATIC_MIMOPS;
877 } else if (smps == WLAN_HT_CAP_SM_PS_DYNAMIC) {
878 arg->peer_flags |= WMI_PEER_SPATIAL_MUX;
879 arg->peer_flags |= WMI_PEER_DYN_MIMOPS;
882 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
883 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
884 else if (ht_cap->mcs.rx_mask[1])
885 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
887 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
888 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
889 arg->peer_ht_rates.rates[n++] = i;
891 arg->peer_ht_rates.num_rates = n;
892 arg->peer_num_spatial_streams = max((n+7) / 8, 1);
894 ath10k_dbg(ATH10K_DBG_MAC, "mcs cnt %d nss %d\n",
895 arg->peer_ht_rates.num_rates,
896 arg->peer_num_spatial_streams);
899 static void ath10k_peer_assoc_h_qos_ap(struct ath10k *ar,
900 struct ath10k_vif *arvif,
901 struct ieee80211_sta *sta,
902 struct ieee80211_bss_conf *bss_conf,
903 struct wmi_peer_assoc_complete_arg *arg)
909 arg->peer_flags |= WMI_PEER_QOS;
911 if (sta->wme && sta->uapsd_queues) {
912 ath10k_dbg(ATH10K_DBG_MAC, "uapsd_queues: 0x%X, max_sp: %d\n",
913 sta->uapsd_queues, sta->max_sp);
915 arg->peer_flags |= WMI_PEER_APSD;
916 arg->peer_flags |= WMI_RC_UAPSD_FLAG;
918 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
919 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
920 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
921 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
922 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
923 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
924 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
925 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
926 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
927 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
928 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
929 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
932 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
933 max_sp = sta->max_sp;
935 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
937 WMI_AP_PS_PEER_PARAM_UAPSD,
940 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
942 WMI_AP_PS_PEER_PARAM_MAX_SP,
945 /* TODO setup this based on STA listen interval and
946 beacon interval. Currently we don't know
947 sta->listen_interval - mac80211 patch required.
948 Currently use 10 seconds */
949 ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
951 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
956 static void ath10k_peer_assoc_h_qos_sta(struct ath10k *ar,
957 struct ath10k_vif *arvif,
958 struct ieee80211_sta *sta,
959 struct ieee80211_bss_conf *bss_conf,
960 struct wmi_peer_assoc_complete_arg *arg)
963 arg->peer_flags |= WMI_PEER_QOS;
966 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
967 struct ieee80211_sta *sta,
968 struct wmi_peer_assoc_complete_arg *arg)
970 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
972 if (!vht_cap->vht_supported)
975 arg->peer_flags |= WMI_PEER_VHT;
977 arg->peer_vht_caps = vht_cap->cap;
979 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
980 arg->peer_flags |= WMI_PEER_80MHZ;
982 arg->peer_vht_rates.rx_max_rate =
983 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
984 arg->peer_vht_rates.rx_mcs_set =
985 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
986 arg->peer_vht_rates.tx_max_rate =
987 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
988 arg->peer_vht_rates.tx_mcs_set =
989 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
991 ath10k_dbg(ATH10K_DBG_MAC, "mac vht peer\n");
994 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
995 struct ath10k_vif *arvif,
996 struct ieee80211_sta *sta,
997 struct ieee80211_bss_conf *bss_conf,
998 struct wmi_peer_assoc_complete_arg *arg)
1000 switch (arvif->vdev_type) {
1001 case WMI_VDEV_TYPE_AP:
1002 ath10k_peer_assoc_h_qos_ap(ar, arvif, sta, bss_conf, arg);
1004 case WMI_VDEV_TYPE_STA:
1005 ath10k_peer_assoc_h_qos_sta(ar, arvif, sta, bss_conf, arg);
1012 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1013 struct ath10k_vif *arvif,
1014 struct ieee80211_sta *sta,
1015 struct wmi_peer_assoc_complete_arg *arg)
1017 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1019 /* FIXME: add VHT */
1021 switch (ar->hw->conf.chandef.chan->band) {
1022 case IEEE80211_BAND_2GHZ:
1023 if (sta->ht_cap.ht_supported) {
1024 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1025 phymode = MODE_11NG_HT40;
1027 phymode = MODE_11NG_HT20;
1033 case IEEE80211_BAND_5GHZ:
1034 if (sta->ht_cap.ht_supported) {
1035 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1036 phymode = MODE_11NA_HT40;
1038 phymode = MODE_11NA_HT20;
1048 arg->peer_phymode = phymode;
1049 WARN_ON(phymode == MODE_UNKNOWN);
1052 static int ath10k_peer_assoc(struct ath10k *ar,
1053 struct ath10k_vif *arvif,
1054 struct ieee80211_sta *sta,
1055 struct ieee80211_bss_conf *bss_conf)
1057 struct wmi_peer_assoc_complete_arg arg;
1059 memset(&arg, 0, sizeof(struct wmi_peer_assoc_complete_arg));
1061 ath10k_peer_assoc_h_basic(ar, arvif, sta, bss_conf, &arg);
1062 ath10k_peer_assoc_h_crypto(ar, arvif, &arg);
1063 ath10k_peer_assoc_h_rates(ar, sta, &arg);
1064 ath10k_peer_assoc_h_ht(ar, sta, &arg);
1065 ath10k_peer_assoc_h_vht(ar, sta, &arg);
1066 ath10k_peer_assoc_h_qos(ar, arvif, sta, bss_conf, &arg);
1067 ath10k_peer_assoc_h_phymode(ar, arvif, sta, &arg);
1069 return ath10k_wmi_peer_assoc(ar, &arg);
1072 /* can be called only in mac80211 callbacks due to `key_count` usage */
1073 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1074 struct ieee80211_vif *vif,
1075 struct ieee80211_bss_conf *bss_conf)
1077 struct ath10k *ar = hw->priv;
1078 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1079 struct ieee80211_sta *ap_sta;
1084 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1086 ath10k_warn("Failed to find station entry for %pM\n",
1092 ret = ath10k_peer_assoc(ar, arvif, ap_sta, bss_conf);
1094 ath10k_warn("Peer assoc failed for %pM\n", bss_conf->bssid);
1101 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, bss_conf->aid,
1104 ath10k_warn("VDEV: %d up failed: ret %d\n",
1105 arvif->vdev_id, ret);
1107 ath10k_dbg(ATH10K_DBG_MAC,
1108 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1109 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1115 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1116 struct ieee80211_vif *vif)
1118 struct ath10k *ar = hw->priv;
1119 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1123 * For some reason, calling VDEV-DOWN before VDEV-STOP
1124 * makes the FW to send frames via HTT after disassociation.
1125 * No idea why this happens, even though VDEV-DOWN is supposed
1126 * to be analogous to link down, so just stop the VDEV.
1128 ret = ath10k_vdev_stop(arvif);
1130 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d stopped\n",
1134 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1135 * report beacons from previously associated network through HTT.
1136 * This in turn would spam mac80211 WARN_ON if we bring down all
1137 * interfaces as it expects there is no rx when no interface is
1140 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1142 ath10k_dbg(ATH10K_DBG_MAC, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1143 arvif->vdev_id, ret);
1145 ath10k_wmi_flush_tx(ar);
1147 arvif->def_wep_key_index = 0;
1150 static int ath10k_station_assoc(struct ath10k *ar, struct ath10k_vif *arvif,
1151 struct ieee80211_sta *sta)
1155 ret = ath10k_peer_assoc(ar, arvif, sta, NULL);
1157 ath10k_warn("WMI peer assoc failed for %pM\n", sta->addr);
1161 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1163 ath10k_warn("could not install peer wep keys (%d)\n", ret);
1170 static int ath10k_station_disassoc(struct ath10k *ar, struct ath10k_vif *arvif,
1171 struct ieee80211_sta *sta)
1175 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1177 ath10k_warn("could not clear all peer wep keys (%d)\n", ret);
1188 static int ath10k_update_channel_list(struct ath10k *ar)
1190 struct ieee80211_hw *hw = ar->hw;
1191 struct ieee80211_supported_band **bands;
1192 enum ieee80211_band band;
1193 struct ieee80211_channel *channel;
1194 struct wmi_scan_chan_list_arg arg = {0};
1195 struct wmi_channel_arg *ch;
1201 bands = hw->wiphy->bands;
1202 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1206 for (i = 0; i < bands[band]->n_channels; i++) {
1207 if (bands[band]->channels[i].flags &
1208 IEEE80211_CHAN_DISABLED)
1215 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1216 arg.channels = kzalloc(len, GFP_KERNEL);
1221 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1225 for (i = 0; i < bands[band]->n_channels; i++) {
1226 channel = &bands[band]->channels[i];
1228 if (channel->flags & IEEE80211_CHAN_DISABLED)
1231 ch->allow_ht = true;
1233 /* FIXME: when should we really allow VHT? */
1234 ch->allow_vht = true;
1237 !(channel->flags & IEEE80211_CHAN_NO_IBSS);
1240 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1242 passive = channel->flags & IEEE80211_CHAN_PASSIVE_SCAN;
1243 ch->passive = passive;
1245 ch->freq = channel->center_freq;
1246 ch->min_power = channel->max_power * 3;
1247 ch->max_power = channel->max_power * 4;
1248 ch->max_reg_power = channel->max_reg_power * 4;
1249 ch->max_antenna_gain = channel->max_antenna_gain;
1250 ch->reg_class_id = 0; /* FIXME */
1252 /* FIXME: why use only legacy modes, why not any
1253 * HT/VHT modes? Would that even make any
1255 if (channel->band == IEEE80211_BAND_2GHZ)
1256 ch->mode = MODE_11G;
1258 ch->mode = MODE_11A;
1260 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1263 ath10k_dbg(ATH10K_DBG_WMI,
1264 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1265 __func__, ch - arg.channels, arg.n_channels,
1266 ch->freq, ch->max_power, ch->max_reg_power,
1267 ch->max_antenna_gain, ch->mode);
1273 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1274 kfree(arg.channels);
1279 static void ath10k_reg_notifier(struct wiphy *wiphy,
1280 struct regulatory_request *request)
1282 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1283 struct reg_dmn_pair_mapping *regpair;
1284 struct ath10k *ar = hw->priv;
1287 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1289 ret = ath10k_update_channel_list(ar);
1291 ath10k_warn("could not update channel list (%d)\n", ret);
1293 regpair = ar->ath_common.regulatory.regpair;
1294 /* Target allows setting up per-band regdomain but ath_common provides
1295 * a combined one only */
1296 ret = ath10k_wmi_pdev_set_regdomain(ar,
1297 regpair->regDmnEnum,
1298 regpair->regDmnEnum, /* 2ghz */
1299 regpair->regDmnEnum, /* 5ghz */
1300 regpair->reg_2ghz_ctl,
1301 regpair->reg_5ghz_ctl);
1303 ath10k_warn("could not set pdev regdomain (%d)\n", ret);
1311 * Frames sent to the FW have to be in "Native Wifi" format.
1312 * Strip the QoS field from the 802.11 header.
1314 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw *hw,
1315 struct ieee80211_tx_control *control,
1316 struct sk_buff *skb)
1318 struct ieee80211_hdr *hdr = (void *)skb->data;
1321 if (!ieee80211_is_data_qos(hdr->frame_control))
1324 qos_ctl = ieee80211_get_qos_ctl(hdr);
1325 memmove(qos_ctl, qos_ctl + IEEE80211_QOS_CTL_LEN,
1326 skb->len - ieee80211_hdrlen(hdr->frame_control));
1327 skb_trim(skb, skb->len - IEEE80211_QOS_CTL_LEN);
1330 static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
1332 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1333 struct ieee80211_vif *vif = info->control.vif;
1334 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1335 struct ath10k *ar = arvif->ar;
1336 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1337 struct ieee80211_key_conf *key = info->control.hw_key;
1340 /* TODO AP mode should be implemented */
1341 if (vif->type != NL80211_IFTYPE_STATION)
1344 if (!ieee80211_has_protected(hdr->frame_control))
1350 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1351 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1354 if (key->keyidx == arvif->def_wep_key_index)
1357 ath10k_dbg(ATH10K_DBG_MAC, "new wep keyidx will be %d\n", key->keyidx);
1359 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1360 WMI_VDEV_PARAM_DEF_KEYID,
1363 ath10k_warn("could not update wep keyidx (%d)\n", ret);
1367 arvif->def_wep_key_index = key->keyidx;
1370 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar, struct sk_buff *skb)
1372 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1373 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1374 struct ieee80211_vif *vif = info->control.vif;
1375 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1377 /* This is case only for P2P_GO */
1378 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1379 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1382 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1383 spin_lock_bh(&ar->data_lock);
1384 if (arvif->u.ap.noa_data)
1385 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
1387 memcpy(skb_put(skb, arvif->u.ap.noa_len),
1388 arvif->u.ap.noa_data,
1389 arvif->u.ap.noa_len);
1390 spin_unlock_bh(&ar->data_lock);
1394 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
1396 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1399 if (ieee80211_is_mgmt(hdr->frame_control))
1400 ret = ath10k_htt_mgmt_tx(ar->htt, skb);
1401 else if (ieee80211_is_nullfunc(hdr->frame_control))
1402 /* FW does not report tx status properly for NullFunc frames
1403 * unless they are sent through mgmt tx path. mac80211 sends
1404 * those frames when it detects link/beacon loss and depends on
1405 * the tx status to be correct. */
1406 ret = ath10k_htt_mgmt_tx(ar->htt, skb);
1408 ret = ath10k_htt_tx(ar->htt, skb);
1411 ath10k_warn("tx failed (%d). dropping packet.\n", ret);
1412 ieee80211_free_txskb(ar->hw, skb);
1416 void ath10k_offchan_tx_purge(struct ath10k *ar)
1418 struct sk_buff *skb;
1421 skb = skb_dequeue(&ar->offchan_tx_queue);
1425 ieee80211_free_txskb(ar->hw, skb);
1429 void ath10k_offchan_tx_work(struct work_struct *work)
1431 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
1432 struct ath10k_peer *peer;
1433 struct ieee80211_hdr *hdr;
1434 struct sk_buff *skb;
1435 const u8 *peer_addr;
1439 /* FW requirement: We must create a peer before FW will send out
1440 * an offchannel frame. Otherwise the frame will be stuck and
1441 * never transmitted. We delete the peer upon tx completion.
1442 * It is unlikely that a peer for offchannel tx will already be
1443 * present. However it may be in some rare cases so account for that.
1444 * Otherwise we might remove a legitimate peer and break stuff. */
1447 skb = skb_dequeue(&ar->offchan_tx_queue);
1451 mutex_lock(&ar->conf_mutex);
1453 ath10k_dbg(ATH10K_DBG_MAC, "processing offchannel skb %p\n",
1456 hdr = (struct ieee80211_hdr *)skb->data;
1457 peer_addr = ieee80211_get_DA(hdr);
1458 vdev_id = ATH10K_SKB_CB(skb)->htt.vdev_id;
1460 spin_lock_bh(&ar->data_lock);
1461 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
1462 spin_unlock_bh(&ar->data_lock);
1465 ath10k_dbg(ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
1466 peer_addr, vdev_id);
1469 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
1471 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1472 peer_addr, vdev_id, ret);
1475 spin_lock_bh(&ar->data_lock);
1476 INIT_COMPLETION(ar->offchan_tx_completed);
1477 ar->offchan_tx_skb = skb;
1478 spin_unlock_bh(&ar->data_lock);
1480 ath10k_tx_htt(ar, skb);
1482 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
1485 ath10k_warn("timed out waiting for offchannel skb %p\n",
1489 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
1491 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1492 peer_addr, vdev_id, ret);
1495 mutex_unlock(&ar->conf_mutex);
1504 * This gets called if we dont get a heart-beat during scan.
1505 * This may indicate the FW has hung and we need to abort the
1506 * scan manually to prevent cancel_hw_scan() from deadlocking
1508 void ath10k_reset_scan(unsigned long ptr)
1510 struct ath10k *ar = (struct ath10k *)ptr;
1512 spin_lock_bh(&ar->data_lock);
1513 if (!ar->scan.in_progress) {
1514 spin_unlock_bh(&ar->data_lock);
1518 ath10k_warn("scan timeout. resetting. fw issue?\n");
1520 if (ar->scan.is_roc)
1521 ieee80211_remain_on_channel_expired(ar->hw);
1523 ieee80211_scan_completed(ar->hw, 1 /* aborted */);
1525 ar->scan.in_progress = false;
1526 complete_all(&ar->scan.completed);
1527 spin_unlock_bh(&ar->data_lock);
1530 static int ath10k_abort_scan(struct ath10k *ar)
1532 struct wmi_stop_scan_arg arg = {
1533 .req_id = 1, /* FIXME */
1534 .req_type = WMI_SCAN_STOP_ONE,
1535 .u.scan_id = ATH10K_SCAN_ID,
1539 lockdep_assert_held(&ar->conf_mutex);
1541 del_timer_sync(&ar->scan.timeout);
1543 spin_lock_bh(&ar->data_lock);
1544 if (!ar->scan.in_progress) {
1545 spin_unlock_bh(&ar->data_lock);
1549 ar->scan.aborting = true;
1550 spin_unlock_bh(&ar->data_lock);
1552 ret = ath10k_wmi_stop_scan(ar, &arg);
1554 ath10k_warn("could not submit wmi stop scan (%d)\n", ret);
1558 ath10k_wmi_flush_tx(ar);
1560 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
1562 ath10k_warn("timed out while waiting for scan to stop\n");
1564 /* scan completion may be done right after we timeout here, so let's
1565 * check the in_progress and tell mac80211 scan is completed. if we
1566 * don't do that and FW fails to send us scan completion indication
1567 * then userspace won't be able to scan anymore */
1570 spin_lock_bh(&ar->data_lock);
1571 if (ar->scan.in_progress) {
1572 ath10k_warn("could not stop scan. its still in progress\n");
1573 ar->scan.in_progress = false;
1574 ath10k_offchan_tx_purge(ar);
1577 spin_unlock_bh(&ar->data_lock);
1582 static int ath10k_start_scan(struct ath10k *ar,
1583 const struct wmi_start_scan_arg *arg)
1587 lockdep_assert_held(&ar->conf_mutex);
1589 ret = ath10k_wmi_start_scan(ar, arg);
1593 /* make sure we submit the command so the completion
1594 * timeout makes sense */
1595 ath10k_wmi_flush_tx(ar);
1597 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
1599 ath10k_abort_scan(ar);
1603 /* the scan can complete earlier, before we even
1604 * start the timer. in that case the timer handler
1605 * checks ar->scan.in_progress and bails out if its
1606 * false. Add a 200ms margin to account event/command
1608 mod_timer(&ar->scan.timeout, jiffies +
1609 msecs_to_jiffies(arg->max_scan_time+200));
1613 /**********************/
1614 /* mac80211 callbacks */
1615 /**********************/
1617 static void ath10k_tx(struct ieee80211_hw *hw,
1618 struct ieee80211_tx_control *control,
1619 struct sk_buff *skb)
1621 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1622 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1623 struct ath10k *ar = hw->priv;
1624 struct ath10k_vif *arvif = NULL;
1628 if (info->control.vif) {
1629 arvif = ath10k_vif_to_arvif(info->control.vif);
1630 vdev_id = arvif->vdev_id;
1631 } else if (ar->monitor_enabled) {
1632 vdev_id = ar->monitor_vdev_id;
1635 /* We should disable CCK RATE due to P2P */
1636 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
1637 ath10k_dbg(ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1639 /* we must calculate tid before we apply qos workaround
1640 * as we'd lose the qos control field */
1641 tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1642 if (ieee80211_is_data_qos(hdr->frame_control) &&
1643 is_unicast_ether_addr(ieee80211_get_DA(hdr))) {
1644 u8 *qc = ieee80211_get_qos_ctl(hdr);
1645 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
1648 ath10k_tx_h_qos_workaround(hw, control, skb);
1649 ath10k_tx_h_update_wep_key(skb);
1650 ath10k_tx_h_add_p2p_noa_ie(ar, skb);
1651 ath10k_tx_h_seq_no(skb);
1653 memset(ATH10K_SKB_CB(skb), 0, sizeof(*ATH10K_SKB_CB(skb)));
1654 ATH10K_SKB_CB(skb)->htt.vdev_id = vdev_id;
1655 ATH10K_SKB_CB(skb)->htt.tid = tid;
1657 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
1658 spin_lock_bh(&ar->data_lock);
1659 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
1660 ATH10K_SKB_CB(skb)->htt.vdev_id = ar->scan.vdev_id;
1661 spin_unlock_bh(&ar->data_lock);
1663 ath10k_dbg(ATH10K_DBG_MAC, "queued offchannel skb %p\n", skb);
1665 skb_queue_tail(&ar->offchan_tx_queue, skb);
1666 ieee80211_queue_work(hw, &ar->offchan_tx_work);
1670 ath10k_tx_htt(ar, skb);
1674 * Initialize various parameters with default vaules.
1676 static int ath10k_start(struct ieee80211_hw *hw)
1678 struct ath10k *ar = hw->priv;
1681 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS, 1);
1683 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1686 ret = ath10k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 0);
1688 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1694 static void ath10k_stop(struct ieee80211_hw *hw)
1696 struct ath10k *ar = hw->priv;
1698 /* avoid leaks in case FW never confirms scan for offchannel */
1699 cancel_work_sync(&ar->offchan_tx_work);
1700 ath10k_offchan_tx_purge(ar);
1703 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
1705 struct ath10k_generic_iter ar_iter;
1706 struct ath10k *ar = hw->priv;
1707 struct ieee80211_conf *conf = &hw->conf;
1711 mutex_lock(&ar->conf_mutex);
1713 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1714 ath10k_dbg(ATH10K_DBG_MAC, "Config channel %d mhz\n",
1715 conf->chandef.chan->center_freq);
1716 spin_lock_bh(&ar->data_lock);
1717 ar->rx_channel = conf->chandef.chan;
1718 spin_unlock_bh(&ar->data_lock);
1721 if (changed & IEEE80211_CONF_CHANGE_PS) {
1722 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
1724 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
1726 ieee80211_iterate_active_interfaces_atomic(hw,
1734 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1735 if (conf->flags & IEEE80211_CONF_MONITOR)
1736 ret = ath10k_monitor_create(ar);
1738 ret = ath10k_monitor_destroy(ar);
1741 mutex_unlock(&ar->conf_mutex);
1747 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1748 * because we will send mgmt frames without CCK. This requirement
1749 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1752 static int ath10k_add_interface(struct ieee80211_hw *hw,
1753 struct ieee80211_vif *vif)
1755 struct ath10k *ar = hw->priv;
1756 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1757 enum wmi_sta_powersave_param param;
1759 u32 value, rts, frag;
1762 mutex_lock(&ar->conf_mutex);
1767 if ((vif->type == NL80211_IFTYPE_MONITOR) && ar->monitor_present) {
1768 ath10k_warn("Only one monitor interface allowed\n");
1773 bit = ffs(ar->free_vdev_map);
1779 arvif->vdev_id = bit - 1;
1780 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
1781 ar->free_vdev_map &= ~(1 << arvif->vdev_id);
1784 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
1786 switch (vif->type) {
1787 case NL80211_IFTYPE_UNSPECIFIED:
1788 case NL80211_IFTYPE_STATION:
1789 arvif->vdev_type = WMI_VDEV_TYPE_STA;
1791 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
1793 case NL80211_IFTYPE_ADHOC:
1794 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
1796 case NL80211_IFTYPE_AP:
1797 arvif->vdev_type = WMI_VDEV_TYPE_AP;
1800 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
1802 case NL80211_IFTYPE_MONITOR:
1803 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
1810 ath10k_dbg(ATH10K_DBG_MAC, "Add interface: id %d type %d subtype %d\n",
1811 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype);
1813 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
1814 arvif->vdev_subtype, vif->addr);
1816 ath10k_warn("WMI vdev create failed: ret %d\n", ret);
1820 ret = ath10k_wmi_vdev_set_param(ar, 0, WMI_VDEV_PARAM_DEF_KEYID,
1821 arvif->def_wep_key_index);
1823 ath10k_warn("Failed to set default keyid: %d\n", ret);
1825 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1826 WMI_VDEV_PARAM_TX_ENCAP_TYPE,
1827 ATH10K_HW_TXRX_NATIVE_WIFI);
1829 ath10k_warn("Failed to set TX encap: %d\n", ret);
1831 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1832 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
1834 ath10k_warn("Failed to create peer for AP: %d\n", ret);
1839 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
1840 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
1841 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
1842 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1845 ath10k_warn("Failed to set RX wake policy: %d\n", ret);
1847 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1848 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1849 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1852 ath10k_warn("Failed to set TX wake thresh: %d\n", ret);
1854 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1855 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1856 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1859 ath10k_warn("Failed to set PSPOLL count: %d\n", ret);
1862 rts = min_t(u32, ar->hw->wiphy->rts_threshold, ATH10K_RTS_MAX);
1863 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1864 WMI_VDEV_PARAM_RTS_THRESHOLD,
1867 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
1868 arvif->vdev_id, ret);
1870 frag = clamp_t(u32, ar->hw->wiphy->frag_threshold,
1871 ATH10K_FRAGMT_THRESHOLD_MIN,
1872 ATH10K_FRAGMT_THRESHOLD_MAX);
1873 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1874 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
1877 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
1878 arvif->vdev_id, ret);
1880 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1881 ar->monitor_present = true;
1884 mutex_unlock(&ar->conf_mutex);
1888 static void ath10k_remove_interface(struct ieee80211_hw *hw,
1889 struct ieee80211_vif *vif)
1891 struct ath10k *ar = hw->priv;
1892 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1895 mutex_lock(&ar->conf_mutex);
1897 ath10k_dbg(ATH10K_DBG_MAC, "Remove interface: id %d\n", arvif->vdev_id);
1899 ar->free_vdev_map |= 1 << (arvif->vdev_id);
1901 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
1902 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
1904 ath10k_warn("Failed to remove peer for AP: %d\n", ret);
1906 kfree(arvif->u.ap.noa_data);
1909 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
1911 ath10k_warn("WMI vdev delete failed: %d\n", ret);
1913 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
1914 ar->monitor_present = false;
1916 ath10k_peer_cleanup(ar, arvif->vdev_id);
1918 mutex_unlock(&ar->conf_mutex);
1922 * FIXME: Has to be verified.
1924 #define SUPPORTED_FILTERS \
1925 (FIF_PROMISC_IN_BSS | \
1930 FIF_BCN_PRBRESP_PROMISC | \
1934 static void ath10k_configure_filter(struct ieee80211_hw *hw,
1935 unsigned int changed_flags,
1936 unsigned int *total_flags,
1939 struct ath10k *ar = hw->priv;
1942 mutex_lock(&ar->conf_mutex);
1944 changed_flags &= SUPPORTED_FILTERS;
1945 *total_flags &= SUPPORTED_FILTERS;
1946 ar->filter_flags = *total_flags;
1948 if ((ar->filter_flags & FIF_PROMISC_IN_BSS) &&
1949 !ar->monitor_enabled) {
1950 ret = ath10k_monitor_start(ar, ar->monitor_vdev_id);
1952 ath10k_warn("Unable to start monitor mode\n");
1954 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode started\n");
1955 } else if (!(ar->filter_flags & FIF_PROMISC_IN_BSS) &&
1956 ar->monitor_enabled) {
1957 ret = ath10k_monitor_stop(ar);
1959 ath10k_warn("Unable to stop monitor mode\n");
1961 ath10k_dbg(ATH10K_DBG_MAC, "Monitor mode stopped\n");
1964 mutex_unlock(&ar->conf_mutex);
1967 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
1968 struct ieee80211_vif *vif,
1969 struct ieee80211_bss_conf *info,
1972 struct ath10k *ar = hw->priv;
1973 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1976 mutex_lock(&ar->conf_mutex);
1978 if (changed & BSS_CHANGED_IBSS)
1979 ath10k_control_ibss(arvif, info, vif->addr);
1981 if (changed & BSS_CHANGED_BEACON_INT) {
1982 arvif->beacon_interval = info->beacon_int;
1983 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
1984 WMI_VDEV_PARAM_BEACON_INTERVAL,
1985 arvif->beacon_interval);
1987 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
1990 ath10k_dbg(ATH10K_DBG_MAC,
1991 "Beacon interval: %d set for VDEV: %d\n",
1992 arvif->beacon_interval, arvif->vdev_id);
1995 if (changed & BSS_CHANGED_BEACON) {
1996 ret = ath10k_wmi_pdev_set_param(ar,
1997 WMI_PDEV_PARAM_BEACON_TX_MODE,
1998 WMI_BEACON_STAGGERED_MODE);
2000 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2003 ath10k_dbg(ATH10K_DBG_MAC,
2004 "Set staggered beacon mode for VDEV: %d\n",
2008 if (changed & BSS_CHANGED_BEACON_INFO) {
2009 arvif->dtim_period = info->dtim_period;
2011 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2012 WMI_VDEV_PARAM_DTIM_PERIOD,
2013 arvif->dtim_period);
2015 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2018 ath10k_dbg(ATH10K_DBG_MAC,
2019 "Set dtim period: %d for VDEV: %d\n",
2020 arvif->dtim_period, arvif->vdev_id);
2023 if (changed & BSS_CHANGED_SSID &&
2024 vif->type == NL80211_IFTYPE_AP) {
2025 arvif->u.ap.ssid_len = info->ssid_len;
2027 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2028 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2031 if (changed & BSS_CHANGED_BSSID) {
2032 if (!is_zero_ether_addr(info->bssid)) {
2033 ret = ath10k_peer_create(ar, arvif->vdev_id,
2036 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2037 info->bssid, arvif->vdev_id);
2039 ath10k_dbg(ATH10K_DBG_MAC,
2040 "Added peer: %pM for VDEV: %d\n",
2041 info->bssid, arvif->vdev_id);
2044 if (vif->type == NL80211_IFTYPE_STATION) {
2046 * this is never erased as we it for crypto key
2047 * clearing; this is FW requirement
2049 memcpy(arvif->u.sta.bssid, info->bssid,
2052 ret = ath10k_vdev_start(arvif);
2054 ath10k_dbg(ATH10K_DBG_MAC,
2055 "VDEV: %d started with BSSID: %pM\n",
2056 arvif->vdev_id, info->bssid);
2060 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2061 * so driver need to store it. It is needed when leaving
2062 * IBSS in order to remove BSSID peer.
2064 if (vif->type == NL80211_IFTYPE_ADHOC)
2065 memcpy(arvif->u.ibss.bssid, info->bssid,
2070 if (changed & BSS_CHANGED_BEACON_ENABLED)
2071 ath10k_control_beaconing(arvif, info);
2073 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2075 if (info->use_cts_prot)
2080 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2081 WMI_VDEV_PARAM_ENABLE_RTSCTS,
2084 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2087 ath10k_dbg(ATH10K_DBG_MAC,
2088 "Set CTS prot: %d for VDEV: %d\n",
2089 cts_prot, arvif->vdev_id);
2092 if (changed & BSS_CHANGED_ERP_SLOT) {
2094 if (info->use_short_slot)
2095 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2098 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2100 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2101 WMI_VDEV_PARAM_SLOT_TIME,
2104 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2107 ath10k_dbg(ATH10K_DBG_MAC,
2108 "Set slottime: %d for VDEV: %d\n",
2109 slottime, arvif->vdev_id);
2112 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2114 if (info->use_short_preamble)
2115 preamble = WMI_VDEV_PREAMBLE_SHORT;
2117 preamble = WMI_VDEV_PREAMBLE_LONG;
2119 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
2120 WMI_VDEV_PARAM_PREAMBLE,
2123 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2126 ath10k_dbg(ATH10K_DBG_MAC,
2127 "Set preamble: %d for VDEV: %d\n",
2128 preamble, arvif->vdev_id);
2131 if (changed & BSS_CHANGED_ASSOC) {
2133 ath10k_bss_assoc(hw, vif, info);
2136 mutex_unlock(&ar->conf_mutex);
2139 static int ath10k_hw_scan(struct ieee80211_hw *hw,
2140 struct ieee80211_vif *vif,
2141 struct cfg80211_scan_request *req)
2143 struct ath10k *ar = hw->priv;
2144 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2145 struct wmi_start_scan_arg arg;
2149 mutex_lock(&ar->conf_mutex);
2151 spin_lock_bh(&ar->data_lock);
2152 if (ar->scan.in_progress) {
2153 spin_unlock_bh(&ar->data_lock);
2158 INIT_COMPLETION(ar->scan.started);
2159 INIT_COMPLETION(ar->scan.completed);
2160 ar->scan.in_progress = true;
2161 ar->scan.aborting = false;
2162 ar->scan.is_roc = false;
2163 ar->scan.vdev_id = arvif->vdev_id;
2164 spin_unlock_bh(&ar->data_lock);
2166 memset(&arg, 0, sizeof(arg));
2167 ath10k_wmi_start_scan_init(ar, &arg);
2168 arg.vdev_id = arvif->vdev_id;
2169 arg.scan_id = ATH10K_SCAN_ID;
2172 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
2175 arg.ie_len = req->ie_len;
2176 memcpy(arg.ie, req->ie, arg.ie_len);
2180 arg.n_ssids = req->n_ssids;
2181 for (i = 0; i < arg.n_ssids; i++) {
2182 arg.ssids[i].len = req->ssids[i].ssid_len;
2183 arg.ssids[i].ssid = req->ssids[i].ssid;
2187 if (req->n_channels) {
2188 arg.n_channels = req->n_channels;
2189 for (i = 0; i < arg.n_channels; i++)
2190 arg.channels[i] = req->channels[i]->center_freq;
2193 ret = ath10k_start_scan(ar, &arg);
2195 ath10k_warn("could not start hw scan (%d)\n", ret);
2196 spin_lock_bh(&ar->data_lock);
2197 ar->scan.in_progress = false;
2198 spin_unlock_bh(&ar->data_lock);
2202 mutex_unlock(&ar->conf_mutex);
2206 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
2207 struct ieee80211_vif *vif)
2209 struct ath10k *ar = hw->priv;
2212 mutex_lock(&ar->conf_mutex);
2213 ret = ath10k_abort_scan(ar);
2215 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2217 ieee80211_scan_completed(hw, 1 /* aborted */);
2219 mutex_unlock(&ar->conf_mutex);
2222 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2223 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2224 struct ieee80211_key_conf *key)
2226 struct ath10k *ar = hw->priv;
2227 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2228 struct ath10k_peer *peer;
2229 const u8 *peer_addr;
2230 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2231 key->cipher == WLAN_CIPHER_SUITE_WEP104;
2234 if (key->keyidx > WMI_MAX_KEY_INDEX)
2237 mutex_lock(&ar->conf_mutex);
2240 peer_addr = sta->addr;
2241 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2242 peer_addr = vif->bss_conf.bssid;
2244 peer_addr = vif->addr;
2246 key->hw_key_idx = key->keyidx;
2248 /* the peer should not disappear in mid-way (unless FW goes awry) since
2249 * we already hold conf_mutex. we just make sure its there now. */
2250 spin_lock_bh(&ar->data_lock);
2251 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2252 spin_unlock_bh(&ar->data_lock);
2255 if (cmd == SET_KEY) {
2256 ath10k_warn("cannot install key for non-existent peer %pM\n",
2261 /* if the peer doesn't exist there is no key to disable
2269 arvif->wep_keys[key->keyidx] = key;
2271 arvif->wep_keys[key->keyidx] = NULL;
2273 if (cmd == DISABLE_KEY)
2274 ath10k_clear_vdev_key(arvif, key);
2277 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
2279 ath10k_warn("ath10k_install_key failed (%d)\n", ret);
2283 spin_lock_bh(&ar->data_lock);
2284 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
2285 if (peer && cmd == SET_KEY)
2286 peer->keys[key->keyidx] = key;
2287 else if (peer && cmd == DISABLE_KEY)
2288 peer->keys[key->keyidx] = NULL;
2289 else if (peer == NULL)
2290 /* impossible unless FW goes crazy */
2291 ath10k_warn("peer %pM disappeared!\n", peer_addr);
2292 spin_unlock_bh(&ar->data_lock);
2295 mutex_unlock(&ar->conf_mutex);
2299 static int ath10k_sta_state(struct ieee80211_hw *hw,
2300 struct ieee80211_vif *vif,
2301 struct ieee80211_sta *sta,
2302 enum ieee80211_sta_state old_state,
2303 enum ieee80211_sta_state new_state)
2305 struct ath10k *ar = hw->priv;
2306 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2309 mutex_lock(&ar->conf_mutex);
2311 if (old_state == IEEE80211_STA_NOTEXIST &&
2312 new_state == IEEE80211_STA_NONE &&
2313 vif->type != NL80211_IFTYPE_STATION) {
2315 * New station addition.
2317 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
2319 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2320 sta->addr, arvif->vdev_id);
2322 ath10k_dbg(ATH10K_DBG_MAC,
2323 "Added peer: %pM for VDEV: %d\n",
2324 sta->addr, arvif->vdev_id);
2325 } else if ((old_state == IEEE80211_STA_NONE &&
2326 new_state == IEEE80211_STA_NOTEXIST)) {
2328 * Existing station deletion.
2330 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
2332 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2333 sta->addr, arvif->vdev_id);
2335 ath10k_dbg(ATH10K_DBG_MAC,
2336 "Removed peer: %pM for VDEV: %d\n",
2337 sta->addr, arvif->vdev_id);
2339 if (vif->type == NL80211_IFTYPE_STATION)
2340 ath10k_bss_disassoc(hw, vif);
2341 } else if (old_state == IEEE80211_STA_AUTH &&
2342 new_state == IEEE80211_STA_ASSOC &&
2343 (vif->type == NL80211_IFTYPE_AP ||
2344 vif->type == NL80211_IFTYPE_ADHOC)) {
2348 ret = ath10k_station_assoc(ar, arvif, sta);
2350 ath10k_warn("Failed to associate station: %pM\n",
2353 ath10k_dbg(ATH10K_DBG_MAC,
2354 "Station %pM moved to assoc state\n",
2356 } else if (old_state == IEEE80211_STA_ASSOC &&
2357 new_state == IEEE80211_STA_AUTH &&
2358 (vif->type == NL80211_IFTYPE_AP ||
2359 vif->type == NL80211_IFTYPE_ADHOC)) {
2363 ret = ath10k_station_disassoc(ar, arvif, sta);
2365 ath10k_warn("Failed to disassociate station: %pM\n",
2368 ath10k_dbg(ATH10K_DBG_MAC,
2369 "Station %pM moved to disassociated state\n",
2373 mutex_unlock(&ar->conf_mutex);
2377 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
2378 u16 ac, bool enable)
2380 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2384 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
2388 case IEEE80211_AC_VO:
2389 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
2390 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
2392 case IEEE80211_AC_VI:
2393 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
2394 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
2396 case IEEE80211_AC_BE:
2397 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
2398 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
2400 case IEEE80211_AC_BK:
2401 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
2402 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
2407 arvif->u.sta.uapsd |= value;
2409 arvif->u.sta.uapsd &= ~value;
2411 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2412 WMI_STA_PS_PARAM_UAPSD,
2413 arvif->u.sta.uapsd);
2415 ath10k_warn("could not set uapsd params %d\n", ret);
2419 if (arvif->u.sta.uapsd)
2420 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
2422 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2424 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2425 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
2428 ath10k_warn("could not set rx wake param %d\n", ret);
2434 static int ath10k_conf_tx(struct ieee80211_hw *hw,
2435 struct ieee80211_vif *vif, u16 ac,
2436 const struct ieee80211_tx_queue_params *params)
2438 struct ath10k *ar = hw->priv;
2439 struct wmi_wmm_params_arg *p = NULL;
2442 mutex_lock(&ar->conf_mutex);
2445 case IEEE80211_AC_VO:
2446 p = &ar->wmm_params.ac_vo;
2448 case IEEE80211_AC_VI:
2449 p = &ar->wmm_params.ac_vi;
2451 case IEEE80211_AC_BE:
2452 p = &ar->wmm_params.ac_be;
2454 case IEEE80211_AC_BK:
2455 p = &ar->wmm_params.ac_bk;
2464 p->cwmin = params->cw_min;
2465 p->cwmax = params->cw_max;
2466 p->aifs = params->aifs;
2469 * The channel time duration programmed in the HW is in absolute
2470 * microseconds, while mac80211 gives the txop in units of
2473 p->txop = params->txop * 32;
2475 /* FIXME: FW accepts wmm params per hw, not per vif */
2476 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
2478 ath10k_warn("could not set wmm params %d\n", ret);
2482 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
2484 ath10k_warn("could not set sta uapsd %d\n", ret);
2487 mutex_unlock(&ar->conf_mutex);
2491 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2493 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
2494 struct ieee80211_vif *vif,
2495 struct ieee80211_channel *chan,
2497 enum ieee80211_roc_type type)
2499 struct ath10k *ar = hw->priv;
2500 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2501 struct wmi_start_scan_arg arg;
2504 mutex_lock(&ar->conf_mutex);
2506 spin_lock_bh(&ar->data_lock);
2507 if (ar->scan.in_progress) {
2508 spin_unlock_bh(&ar->data_lock);
2513 INIT_COMPLETION(ar->scan.started);
2514 INIT_COMPLETION(ar->scan.completed);
2515 INIT_COMPLETION(ar->scan.on_channel);
2516 ar->scan.in_progress = true;
2517 ar->scan.aborting = false;
2518 ar->scan.is_roc = true;
2519 ar->scan.vdev_id = arvif->vdev_id;
2520 ar->scan.roc_freq = chan->center_freq;
2521 spin_unlock_bh(&ar->data_lock);
2523 memset(&arg, 0, sizeof(arg));
2524 ath10k_wmi_start_scan_init(ar, &arg);
2525 arg.vdev_id = arvif->vdev_id;
2526 arg.scan_id = ATH10K_SCAN_ID;
2528 arg.channels[0] = chan->center_freq;
2529 arg.dwell_time_active = duration;
2530 arg.dwell_time_passive = duration;
2531 arg.max_scan_time = 2 * duration;
2532 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
2533 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
2535 ret = ath10k_start_scan(ar, &arg);
2537 ath10k_warn("could not start roc scan (%d)\n", ret);
2538 spin_lock_bh(&ar->data_lock);
2539 ar->scan.in_progress = false;
2540 spin_unlock_bh(&ar->data_lock);
2544 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
2546 ath10k_warn("could not switch to channel for roc scan\n");
2547 ath10k_abort_scan(ar);
2554 mutex_unlock(&ar->conf_mutex);
2558 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2560 struct ath10k *ar = hw->priv;
2562 mutex_lock(&ar->conf_mutex);
2563 ath10k_abort_scan(ar);
2564 mutex_unlock(&ar->conf_mutex);
2570 * Both RTS and Fragmentation threshold are interface-specific
2571 * in ath10k, but device-specific in mac80211.
2573 static void ath10k_set_rts_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2575 struct ath10k_generic_iter *ar_iter = data;
2576 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2577 u32 rts = ar_iter->ar->hw->wiphy->rts_threshold;
2579 rts = min_t(u32, rts, ATH10K_RTS_MAX);
2581 ar_iter->ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2582 WMI_VDEV_PARAM_RTS_THRESHOLD,
2585 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2588 ath10k_dbg(ATH10K_DBG_MAC,
2589 "Set RTS threshold: %d for VDEV: %d\n",
2590 rts, arvif->vdev_id);
2593 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2595 struct ath10k_generic_iter ar_iter;
2596 struct ath10k *ar = hw->priv;
2598 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2601 mutex_lock(&ar->conf_mutex);
2602 ieee80211_iterate_active_interfaces_atomic(
2603 hw, IEEE80211_IFACE_ITER_NORMAL,
2604 ath10k_set_rts_iter, &ar_iter);
2605 mutex_unlock(&ar->conf_mutex);
2610 static void ath10k_set_frag_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
2612 struct ath10k_generic_iter *ar_iter = data;
2613 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2614 u32 frag = ar_iter->ar->hw->wiphy->frag_threshold;
2617 frag = clamp_t(u32, frag,
2618 ATH10K_FRAGMT_THRESHOLD_MIN,
2619 ATH10K_FRAGMT_THRESHOLD_MAX);
2621 ret = ath10k_wmi_vdev_set_param(ar_iter->ar, arvif->vdev_id,
2622 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD,
2627 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2630 ath10k_dbg(ATH10K_DBG_MAC,
2631 "Set frag threshold: %d for VDEV: %d\n",
2632 frag, arvif->vdev_id);
2635 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2637 struct ath10k_generic_iter ar_iter;
2638 struct ath10k *ar = hw->priv;
2640 memset(&ar_iter, 0, sizeof(struct ath10k_generic_iter));
2643 mutex_lock(&ar->conf_mutex);
2644 ieee80211_iterate_active_interfaces_atomic(
2645 hw, IEEE80211_IFACE_ITER_NORMAL,
2646 ath10k_set_frag_iter, &ar_iter);
2647 mutex_unlock(&ar->conf_mutex);
2652 static void ath10k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
2654 struct ath10k *ar = hw->priv;
2657 /* mac80211 doesn't care if we really xmit queued frames or not
2658 * we'll collect those frames either way if we stop/delete vdevs */
2662 ret = wait_event_timeout(ar->htt->empty_tx_wq, ({
2664 spin_lock_bh(&ar->htt->tx_lock);
2665 empty = bitmap_empty(ar->htt->used_msdu_ids,
2666 ar->htt->max_num_pending_tx);
2667 spin_unlock_bh(&ar->htt->tx_lock);
2669 }), ATH10K_FLUSH_TIMEOUT_HZ);
2671 ath10k_warn("tx not flushed\n");
2674 /* TODO: Implement this function properly
2675 * For now it is needed to reply to Probe Requests in IBSS mode.
2676 * Propably we need this information from FW.
2678 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
2683 static const struct ieee80211_ops ath10k_ops = {
2685 .start = ath10k_start,
2686 .stop = ath10k_stop,
2687 .config = ath10k_config,
2688 .add_interface = ath10k_add_interface,
2689 .remove_interface = ath10k_remove_interface,
2690 .configure_filter = ath10k_configure_filter,
2691 .bss_info_changed = ath10k_bss_info_changed,
2692 .hw_scan = ath10k_hw_scan,
2693 .cancel_hw_scan = ath10k_cancel_hw_scan,
2694 .set_key = ath10k_set_key,
2695 .sta_state = ath10k_sta_state,
2696 .conf_tx = ath10k_conf_tx,
2697 .remain_on_channel = ath10k_remain_on_channel,
2698 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
2699 .set_rts_threshold = ath10k_set_rts_threshold,
2700 .set_frag_threshold = ath10k_set_frag_threshold,
2701 .flush = ath10k_flush,
2702 .tx_last_beacon = ath10k_tx_last_beacon,
2705 #define RATETAB_ENT(_rate, _rateid, _flags) { \
2706 .bitrate = (_rate), \
2707 .flags = (_flags), \
2708 .hw_value = (_rateid), \
2711 #define CHAN2G(_channel, _freq, _flags) { \
2712 .band = IEEE80211_BAND_2GHZ, \
2713 .hw_value = (_channel), \
2714 .center_freq = (_freq), \
2715 .flags = (_flags), \
2716 .max_antenna_gain = 0, \
2720 #define CHAN5G(_channel, _freq, _flags) { \
2721 .band = IEEE80211_BAND_5GHZ, \
2722 .hw_value = (_channel), \
2723 .center_freq = (_freq), \
2724 .flags = (_flags), \
2725 .max_antenna_gain = 0, \
2729 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
2739 CHAN2G(10, 2457, 0),
2740 CHAN2G(11, 2462, 0),
2741 CHAN2G(12, 2467, 0),
2742 CHAN2G(13, 2472, 0),
2743 CHAN2G(14, 2484, 0),
2746 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
2747 CHAN5G(36, 5180, 0),
2748 CHAN5G(40, 5200, 0),
2749 CHAN5G(44, 5220, 0),
2750 CHAN5G(48, 5240, 0),
2751 CHAN5G(52, 5260, 0),
2752 CHAN5G(56, 5280, 0),
2753 CHAN5G(60, 5300, 0),
2754 CHAN5G(64, 5320, 0),
2755 CHAN5G(100, 5500, 0),
2756 CHAN5G(104, 5520, 0),
2757 CHAN5G(108, 5540, 0),
2758 CHAN5G(112, 5560, 0),
2759 CHAN5G(116, 5580, 0),
2760 CHAN5G(120, 5600, 0),
2761 CHAN5G(124, 5620, 0),
2762 CHAN5G(128, 5640, 0),
2763 CHAN5G(132, 5660, 0),
2764 CHAN5G(136, 5680, 0),
2765 CHAN5G(140, 5700, 0),
2766 CHAN5G(149, 5745, 0),
2767 CHAN5G(153, 5765, 0),
2768 CHAN5G(157, 5785, 0),
2769 CHAN5G(161, 5805, 0),
2770 CHAN5G(165, 5825, 0),
2773 static struct ieee80211_rate ath10k_rates[] = {
2775 RATETAB_ENT(10, 0x82, 0),
2776 RATETAB_ENT(20, 0x84, 0),
2777 RATETAB_ENT(55, 0x8b, 0),
2778 RATETAB_ENT(110, 0x96, 0),
2780 RATETAB_ENT(60, 0x0c, 0),
2781 RATETAB_ENT(90, 0x12, 0),
2782 RATETAB_ENT(120, 0x18, 0),
2783 RATETAB_ENT(180, 0x24, 0),
2784 RATETAB_ENT(240, 0x30, 0),
2785 RATETAB_ENT(360, 0x48, 0),
2786 RATETAB_ENT(480, 0x60, 0),
2787 RATETAB_ENT(540, 0x6c, 0),
2790 #define ath10k_a_rates (ath10k_rates + 4)
2791 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
2792 #define ath10k_g_rates (ath10k_rates + 0)
2793 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
2795 struct ath10k *ath10k_mac_create(void)
2797 struct ieee80211_hw *hw;
2800 hw = ieee80211_alloc_hw(sizeof(struct ath10k), &ath10k_ops);
2810 void ath10k_mac_destroy(struct ath10k *ar)
2812 ieee80211_free_hw(ar->hw);
2815 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
2818 .types = BIT(NL80211_IFTYPE_STATION)
2819 | BIT(NL80211_IFTYPE_P2P_CLIENT)
2820 | BIT(NL80211_IFTYPE_P2P_GO)
2821 | BIT(NL80211_IFTYPE_AP)
2825 static const struct ieee80211_iface_combination ath10k_if_comb = {
2826 .limits = ath10k_if_limits,
2827 .n_limits = ARRAY_SIZE(ath10k_if_limits),
2828 .max_interfaces = 8,
2829 .num_different_channels = 1,
2830 .beacon_int_infra_match = true,
2833 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
2835 struct ieee80211_sta_vht_cap vht_cap = {0};
2838 vht_cap.vht_supported = 1;
2839 vht_cap.cap = ar->vht_cap_info;
2841 /* FIXME: check dynamically how many streams board supports */
2842 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
2843 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
2844 IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
2845 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
2846 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
2847 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
2848 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
2849 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
2851 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
2852 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
2857 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
2860 struct ieee80211_sta_ht_cap ht_cap = {0};
2862 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
2865 ht_cap.ht_supported = 1;
2866 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
2867 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
2868 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
2869 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
2870 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
2872 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
2873 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
2875 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
2876 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
2878 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
2881 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
2882 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
2887 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
2888 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
2890 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
2893 stbc = ar->ht_cap_info;
2894 stbc &= WMI_HT_CAP_RX_STBC;
2895 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
2896 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
2897 stbc &= IEEE80211_HT_CAP_RX_STBC;
2902 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
2903 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
2905 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
2906 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
2908 /* max AMSDU is implicitly taken from vht_cap_info */
2909 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
2910 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
2912 for (i = 0; i < WMI_MAX_SPATIAL_STREAM; i++)
2913 ht_cap.mcs.rx_mask[i] = 0xFF;
2915 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
2921 static void ath10k_get_arvif_iter(void *data, u8 *mac,
2922 struct ieee80211_vif *vif)
2924 struct ath10k_vif_iter *arvif_iter = data;
2925 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2927 if (arvif->vdev_id == arvif_iter->vdev_id)
2928 arvif_iter->arvif = arvif;
2931 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
2933 struct ath10k_vif_iter arvif_iter;
2936 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
2937 arvif_iter.vdev_id = vdev_id;
2939 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
2940 ieee80211_iterate_active_interfaces_atomic(ar->hw,
2942 ath10k_get_arvif_iter,
2944 if (!arvif_iter.arvif) {
2945 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id);
2949 return arvif_iter.arvif;
2952 int ath10k_mac_register(struct ath10k *ar)
2954 struct ieee80211_supported_band *band;
2955 struct ieee80211_sta_vht_cap vht_cap;
2956 struct ieee80211_sta_ht_cap ht_cap;
2960 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
2962 SET_IEEE80211_DEV(ar->hw, ar->dev);
2964 ht_cap = ath10k_get_ht_cap(ar);
2965 vht_cap = ath10k_create_vht_cap(ar);
2967 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
2968 channels = kmemdup(ath10k_2ghz_channels,
2969 sizeof(ath10k_2ghz_channels),
2974 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
2975 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
2976 band->channels = channels;
2977 band->n_bitrates = ath10k_g_rates_size;
2978 band->bitrates = ath10k_g_rates;
2979 band->ht_cap = ht_cap;
2981 /* vht is not supported in 2.4 GHz */
2983 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
2986 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
2987 channels = kmemdup(ath10k_5ghz_channels,
2988 sizeof(ath10k_5ghz_channels),
2991 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
2992 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
2993 kfree(band->channels);
2998 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
2999 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
3000 band->channels = channels;
3001 band->n_bitrates = ath10k_a_rates_size;
3002 band->bitrates = ath10k_a_rates;
3003 band->ht_cap = ht_cap;
3004 band->vht_cap = vht_cap;
3005 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
3008 ar->hw->wiphy->interface_modes =
3009 BIT(NL80211_IFTYPE_STATION) |
3010 BIT(NL80211_IFTYPE_ADHOC) |
3011 BIT(NL80211_IFTYPE_AP) |
3012 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3013 BIT(NL80211_IFTYPE_P2P_GO);
3015 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
3016 IEEE80211_HW_SUPPORTS_PS |
3017 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
3018 IEEE80211_HW_SUPPORTS_UAPSD |
3019 IEEE80211_HW_MFP_CAPABLE |
3020 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3021 IEEE80211_HW_HAS_RATE_CONTROL |
3022 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
3023 IEEE80211_HW_WANT_MONITOR_VIF |
3024 IEEE80211_HW_AP_LINK_PS;
3026 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3027 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
3029 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
3030 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3031 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
3034 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
3035 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
3037 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
3039 ar->hw->channel_change_time = 5000;
3040 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
3042 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
3043 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
3045 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
3047 * on LL hardware queues are managed entirely by the FW
3048 * so we only advertise to mac we can do the queues thing
3052 ar->hw->wiphy->iface_combinations = &ath10k_if_comb;
3053 ar->hw->wiphy->n_iface_combinations = 1;
3055 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
3056 ath10k_reg_notifier);
3058 ath10k_err("Regulatory initialization failed\n");
3062 ret = ieee80211_register_hw(ar->hw);
3064 ath10k_err("ieee80211 registration failed: %d\n", ret);
3068 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
3069 ret = regulatory_hint(ar->hw->wiphy,
3070 ar->ath_common.regulatory.alpha2);
3077 ieee80211_unregister_hw(ar->hw);
3081 void ath10k_mac_unregister(struct ath10k *ar)
3083 ieee80211_unregister_hw(ar->hw);
3085 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
3086 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
3088 SET_IEEE80211_DEV(ar->hw, NULL);