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>
37 static int ath10k_send_key(struct ath10k_vif *arvif,
38 struct ieee80211_key_conf *key,
40 const u8 *macaddr, bool def_idx)
42 struct ath10k *ar = arvif->ar;
43 struct wmi_vdev_install_key_arg arg = {
44 .vdev_id = arvif->vdev_id,
45 .key_idx = key->keyidx,
46 .key_len = key->keylen,
51 lockdep_assert_held(&arvif->ar->conf_mutex);
53 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
54 arg.key_flags = WMI_KEY_PAIRWISE;
56 arg.key_flags = WMI_KEY_GROUP;
58 switch (key->cipher) {
59 case WLAN_CIPHER_SUITE_CCMP:
60 arg.key_cipher = WMI_CIPHER_AES_CCM;
61 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
63 case WLAN_CIPHER_SUITE_TKIP:
64 arg.key_cipher = WMI_CIPHER_TKIP;
65 arg.key_txmic_len = 8;
66 arg.key_rxmic_len = 8;
68 case WLAN_CIPHER_SUITE_WEP40:
69 case WLAN_CIPHER_SUITE_WEP104:
70 arg.key_cipher = WMI_CIPHER_WEP;
71 /* AP/IBSS mode requires self-key to be groupwise
72 * Otherwise pairwise key must be set */
73 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
74 arg.key_flags = WMI_KEY_PAIRWISE;
77 arg.key_flags |= WMI_KEY_TX_USAGE;
79 case WLAN_CIPHER_SUITE_AES_CMAC:
80 /* this one needs to be done in software */
83 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
87 if (cmd == DISABLE_KEY) {
88 arg.key_cipher = WMI_CIPHER_NONE;
92 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
95 static int ath10k_install_key(struct ath10k_vif *arvif,
96 struct ieee80211_key_conf *key,
98 const u8 *macaddr, bool def_idx)
100 struct ath10k *ar = arvif->ar;
103 lockdep_assert_held(&ar->conf_mutex);
105 reinit_completion(&ar->install_key_done);
107 ret = ath10k_send_key(arvif, key, cmd, macaddr, def_idx);
111 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
118 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
121 struct ath10k *ar = arvif->ar;
122 struct ath10k_peer *peer;
127 lockdep_assert_held(&ar->conf_mutex);
129 spin_lock_bh(&ar->data_lock);
130 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
131 spin_unlock_bh(&ar->data_lock);
136 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
137 if (arvif->wep_keys[i] == NULL)
139 /* set TX_USAGE flag for default key id */
140 if (arvif->def_wep_key_idx == i)
145 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
150 spin_lock_bh(&ar->data_lock);
151 peer->keys[i] = arvif->wep_keys[i];
152 spin_unlock_bh(&ar->data_lock);
158 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
161 struct ath10k *ar = arvif->ar;
162 struct ath10k_peer *peer;
167 lockdep_assert_held(&ar->conf_mutex);
169 spin_lock_bh(&ar->data_lock);
170 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
171 spin_unlock_bh(&ar->data_lock);
176 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
177 if (peer->keys[i] == NULL)
180 /* key flags are not required to delete the key */
181 ret = ath10k_install_key(arvif, peer->keys[i],
182 DISABLE_KEY, addr, false);
183 if (ret && first_errno == 0)
187 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
190 spin_lock_bh(&ar->data_lock);
191 peer->keys[i] = NULL;
192 spin_unlock_bh(&ar->data_lock);
198 bool ath10k_mac_is_peer_wep_key_set(struct ath10k *ar, const u8 *addr,
201 struct ath10k_peer *peer;
204 lockdep_assert_held(&ar->data_lock);
206 /* We don't know which vdev this peer belongs to,
207 * since WMI doesn't give us that information.
209 * FIXME: multi-bss needs to be handled.
211 peer = ath10k_peer_find(ar, 0, addr);
215 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
216 if (peer->keys[i] && peer->keys[i]->keyidx == keyidx)
223 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
224 struct ieee80211_key_conf *key)
226 struct ath10k *ar = arvif->ar;
227 struct ath10k_peer *peer;
233 lockdep_assert_held(&ar->conf_mutex);
236 /* since ath10k_install_key we can't hold data_lock all the
237 * time, so we try to remove the keys incrementally */
238 spin_lock_bh(&ar->data_lock);
240 list_for_each_entry(peer, &ar->peers, list) {
241 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
242 if (peer->keys[i] == key) {
243 ether_addr_copy(addr, peer->addr);
244 peer->keys[i] = NULL;
249 if (i < ARRAY_SIZE(peer->keys))
252 spin_unlock_bh(&ar->data_lock);
254 if (i == ARRAY_SIZE(peer->keys))
256 /* key flags are not required to delete the key */
257 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr, false);
258 if (ret && first_errno == 0)
262 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
269 /*********************/
270 /* General utilities */
271 /*********************/
273 static inline enum wmi_phy_mode
274 chan_to_phymode(const struct cfg80211_chan_def *chandef)
276 enum wmi_phy_mode phymode = MODE_UNKNOWN;
278 switch (chandef->chan->band) {
279 case IEEE80211_BAND_2GHZ:
280 switch (chandef->width) {
281 case NL80211_CHAN_WIDTH_20_NOHT:
282 if (chandef->chan->flags & IEEE80211_CHAN_NO_OFDM)
287 case NL80211_CHAN_WIDTH_20:
288 phymode = MODE_11NG_HT20;
290 case NL80211_CHAN_WIDTH_40:
291 phymode = MODE_11NG_HT40;
293 case NL80211_CHAN_WIDTH_5:
294 case NL80211_CHAN_WIDTH_10:
295 case NL80211_CHAN_WIDTH_80:
296 case NL80211_CHAN_WIDTH_80P80:
297 case NL80211_CHAN_WIDTH_160:
298 phymode = MODE_UNKNOWN;
302 case IEEE80211_BAND_5GHZ:
303 switch (chandef->width) {
304 case NL80211_CHAN_WIDTH_20_NOHT:
307 case NL80211_CHAN_WIDTH_20:
308 phymode = MODE_11NA_HT20;
310 case NL80211_CHAN_WIDTH_40:
311 phymode = MODE_11NA_HT40;
313 case NL80211_CHAN_WIDTH_80:
314 phymode = MODE_11AC_VHT80;
316 case NL80211_CHAN_WIDTH_5:
317 case NL80211_CHAN_WIDTH_10:
318 case NL80211_CHAN_WIDTH_80P80:
319 case NL80211_CHAN_WIDTH_160:
320 phymode = MODE_UNKNOWN;
328 WARN_ON(phymode == MODE_UNKNOWN);
332 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
335 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
336 * 0 for no restriction
345 switch (mpdudensity) {
351 /* Our lower layer calculations limit our precision to
367 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
371 lockdep_assert_held(&ar->conf_mutex);
373 if (ar->num_peers >= ar->max_num_peers)
376 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
378 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
383 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
385 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
395 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
397 struct ath10k *ar = arvif->ar;
401 param = ar->wmi.pdev_param->sta_kickout_th;
402 ret = ath10k_wmi_pdev_set_param(ar, param,
403 ATH10K_KICKOUT_THRESHOLD);
405 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
406 arvif->vdev_id, ret);
410 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
411 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
412 ATH10K_KEEPALIVE_MIN_IDLE);
414 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
415 arvif->vdev_id, ret);
419 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
420 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
421 ATH10K_KEEPALIVE_MAX_IDLE);
423 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
424 arvif->vdev_id, ret);
428 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
429 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
430 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
432 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
433 arvif->vdev_id, ret);
440 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
442 struct ath10k *ar = arvif->ar;
445 vdev_param = ar->wmi.vdev_param->rts_threshold;
446 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
449 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
451 struct ath10k *ar = arvif->ar;
454 if (value != 0xFFFFFFFF)
455 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
456 ATH10K_FRAGMT_THRESHOLD_MIN,
457 ATH10K_FRAGMT_THRESHOLD_MAX);
459 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
460 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
463 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
467 lockdep_assert_held(&ar->conf_mutex);
469 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
473 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
482 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
484 struct ath10k_peer *peer, *tmp;
486 lockdep_assert_held(&ar->conf_mutex);
488 spin_lock_bh(&ar->data_lock);
489 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
490 if (peer->vdev_id != vdev_id)
493 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
494 peer->addr, vdev_id);
496 list_del(&peer->list);
500 spin_unlock_bh(&ar->data_lock);
503 static void ath10k_peer_cleanup_all(struct ath10k *ar)
505 struct ath10k_peer *peer, *tmp;
507 lockdep_assert_held(&ar->conf_mutex);
509 spin_lock_bh(&ar->data_lock);
510 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
511 list_del(&peer->list);
514 spin_unlock_bh(&ar->data_lock);
517 ar->num_stations = 0;
520 /************************/
521 /* Interface management */
522 /************************/
524 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
526 struct ath10k *ar = arvif->ar;
528 lockdep_assert_held(&ar->data_lock);
533 if (!arvif->beacon_buf)
534 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
535 arvif->beacon->len, DMA_TO_DEVICE);
537 if (WARN_ON(arvif->beacon_state != ATH10K_BEACON_SCHEDULED &&
538 arvif->beacon_state != ATH10K_BEACON_SENT))
541 dev_kfree_skb_any(arvif->beacon);
543 arvif->beacon = NULL;
544 arvif->beacon_state = ATH10K_BEACON_SCHEDULED;
547 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
549 struct ath10k *ar = arvif->ar;
551 lockdep_assert_held(&ar->data_lock);
553 ath10k_mac_vif_beacon_free(arvif);
555 if (arvif->beacon_buf) {
556 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
557 arvif->beacon_buf, arvif->beacon_paddr);
558 arvif->beacon_buf = NULL;
562 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
566 lockdep_assert_held(&ar->conf_mutex);
568 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
571 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
572 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
579 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
581 struct cfg80211_chan_def *chandef = &ar->chandef;
582 struct ieee80211_channel *channel = chandef->chan;
583 struct wmi_vdev_start_request_arg arg = {};
586 lockdep_assert_held(&ar->conf_mutex);
588 arg.vdev_id = vdev_id;
589 arg.channel.freq = channel->center_freq;
590 arg.channel.band_center_freq1 = chandef->center_freq1;
592 /* TODO setup this dynamically, what in case we
593 don't have any vifs? */
594 arg.channel.mode = chan_to_phymode(chandef);
595 arg.channel.chan_radar =
596 !!(channel->flags & IEEE80211_CHAN_RADAR);
598 arg.channel.min_power = 0;
599 arg.channel.max_power = channel->max_power * 2;
600 arg.channel.max_reg_power = channel->max_reg_power * 2;
601 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
603 reinit_completion(&ar->vdev_setup_done);
605 ret = ath10k_wmi_vdev_start(ar, &arg);
607 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
612 ret = ath10k_vdev_setup_sync(ar);
614 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i start: %d\n",
619 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
621 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
626 ar->monitor_vdev_id = vdev_id;
628 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
629 ar->monitor_vdev_id);
633 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
635 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
636 ar->monitor_vdev_id, ret);
641 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
645 lockdep_assert_held(&ar->conf_mutex);
647 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
649 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
650 ar->monitor_vdev_id, ret);
652 reinit_completion(&ar->vdev_setup_done);
654 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
656 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
657 ar->monitor_vdev_id, ret);
659 ret = ath10k_vdev_setup_sync(ar);
661 ath10k_warn(ar, "failed to synchronize monitor vdev %i stop: %d\n",
662 ar->monitor_vdev_id, ret);
664 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
665 ar->monitor_vdev_id);
669 static int ath10k_monitor_vdev_create(struct ath10k *ar)
673 lockdep_assert_held(&ar->conf_mutex);
675 if (ar->free_vdev_map == 0) {
676 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
680 bit = __ffs64(ar->free_vdev_map);
682 ar->monitor_vdev_id = bit;
684 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
685 WMI_VDEV_TYPE_MONITOR,
688 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
689 ar->monitor_vdev_id, ret);
693 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
694 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
695 ar->monitor_vdev_id);
700 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
704 lockdep_assert_held(&ar->conf_mutex);
706 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
708 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
709 ar->monitor_vdev_id, ret);
713 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
715 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
716 ar->monitor_vdev_id);
720 static int ath10k_monitor_start(struct ath10k *ar)
724 lockdep_assert_held(&ar->conf_mutex);
726 ret = ath10k_monitor_vdev_create(ar);
728 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
732 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
734 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
735 ath10k_monitor_vdev_delete(ar);
739 ar->monitor_started = true;
740 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
745 static int ath10k_monitor_stop(struct ath10k *ar)
749 lockdep_assert_held(&ar->conf_mutex);
751 ret = ath10k_monitor_vdev_stop(ar);
753 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
757 ret = ath10k_monitor_vdev_delete(ar);
759 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
763 ar->monitor_started = false;
764 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
769 static int ath10k_monitor_recalc(struct ath10k *ar)
773 lockdep_assert_held(&ar->conf_mutex);
775 should_start = ar->monitor ||
776 ar->filter_flags & FIF_PROMISC_IN_BSS ||
777 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
779 ath10k_dbg(ar, ATH10K_DBG_MAC,
780 "mac monitor recalc started? %d should? %d\n",
781 ar->monitor_started, should_start);
783 if (should_start == ar->monitor_started)
787 return ath10k_monitor_start(ar);
789 return ath10k_monitor_stop(ar);
792 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
794 struct ath10k *ar = arvif->ar;
795 u32 vdev_param, rts_cts = 0;
797 lockdep_assert_held(&ar->conf_mutex);
799 vdev_param = ar->wmi.vdev_param->enable_rtscts;
801 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
802 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
804 if (arvif->num_legacy_stations > 0)
805 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
808 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
812 static int ath10k_start_cac(struct ath10k *ar)
816 lockdep_assert_held(&ar->conf_mutex);
818 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
820 ret = ath10k_monitor_recalc(ar);
822 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
823 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
827 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
828 ar->monitor_vdev_id);
833 static int ath10k_stop_cac(struct ath10k *ar)
835 lockdep_assert_held(&ar->conf_mutex);
837 /* CAC is not running - do nothing */
838 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
841 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
842 ath10k_monitor_stop(ar);
844 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
849 static void ath10k_recalc_radar_detection(struct ath10k *ar)
853 lockdep_assert_held(&ar->conf_mutex);
857 if (!ar->radar_enabled)
860 if (ar->num_started_vdevs > 0)
863 ret = ath10k_start_cac(ar);
866 * Not possible to start CAC on current channel so starting
867 * radiation is not allowed, make this channel DFS_UNAVAILABLE
868 * by indicating that radar was detected.
870 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
871 ieee80211_radar_detected(ar->hw);
875 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
877 struct ath10k *ar = arvif->ar;
878 struct cfg80211_chan_def *chandef = &ar->chandef;
879 struct wmi_vdev_start_request_arg arg = {};
882 lockdep_assert_held(&ar->conf_mutex);
884 reinit_completion(&ar->vdev_setup_done);
886 arg.vdev_id = arvif->vdev_id;
887 arg.dtim_period = arvif->dtim_period;
888 arg.bcn_intval = arvif->beacon_interval;
890 arg.channel.freq = chandef->chan->center_freq;
891 arg.channel.band_center_freq1 = chandef->center_freq1;
892 arg.channel.mode = chan_to_phymode(chandef);
894 arg.channel.min_power = 0;
895 arg.channel.max_power = chandef->chan->max_power * 2;
896 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
897 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
899 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
900 arg.ssid = arvif->u.ap.ssid;
901 arg.ssid_len = arvif->u.ap.ssid_len;
902 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
904 /* For now allow DFS for AP mode */
905 arg.channel.chan_radar =
906 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
907 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
908 arg.ssid = arvif->vif->bss_conf.ssid;
909 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
912 ath10k_dbg(ar, ATH10K_DBG_MAC,
913 "mac vdev %d start center_freq %d phymode %s\n",
914 arg.vdev_id, arg.channel.freq,
915 ath10k_wmi_phymode_str(arg.channel.mode));
918 ret = ath10k_wmi_vdev_restart(ar, &arg);
920 ret = ath10k_wmi_vdev_start(ar, &arg);
923 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
928 ret = ath10k_vdev_setup_sync(ar);
931 "failed to synchronize setup for vdev %i restart %d: %d\n",
932 arg.vdev_id, restart, ret);
936 ar->num_started_vdevs++;
937 ath10k_recalc_radar_detection(ar);
942 static int ath10k_vdev_start(struct ath10k_vif *arvif)
944 return ath10k_vdev_start_restart(arvif, false);
947 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
949 return ath10k_vdev_start_restart(arvif, true);
952 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
954 struct ath10k *ar = arvif->ar;
957 lockdep_assert_held(&ar->conf_mutex);
959 reinit_completion(&ar->vdev_setup_done);
961 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
963 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
964 arvif->vdev_id, ret);
968 ret = ath10k_vdev_setup_sync(ar);
970 ath10k_warn(ar, "failed to synchronize setup for vdev %i stop: %d\n",
971 arvif->vdev_id, ret);
975 WARN_ON(ar->num_started_vdevs == 0);
977 if (ar->num_started_vdevs != 0) {
978 ar->num_started_vdevs--;
979 ath10k_recalc_radar_detection(ar);
985 static int ath10k_mac_setup_bcn_p2p_ie(struct ath10k_vif *arvif,
988 struct ath10k *ar = arvif->ar;
989 struct ieee80211_mgmt *mgmt;
993 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
996 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
999 mgmt = (void *)bcn->data;
1000 p2p_ie = cfg80211_find_vendor_ie(WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1001 mgmt->u.beacon.variable,
1002 bcn->len - (mgmt->u.beacon.variable -
1007 ret = ath10k_wmi_p2p_go_bcn_ie(ar, arvif->vdev_id, p2p_ie);
1009 ath10k_warn(ar, "failed to submit p2p go bcn ie for vdev %i: %d\n",
1010 arvif->vdev_id, ret);
1017 static int ath10k_mac_remove_vendor_ie(struct sk_buff *skb, unsigned int oui,
1018 u8 oui_type, size_t ie_offset)
1025 if (WARN_ON(skb->len < ie_offset))
1028 ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
1029 skb->data + ie_offset,
1030 skb->len - ie_offset);
1035 end = skb->data + skb->len;
1038 if (WARN_ON(next > end))
1041 memmove(ie, next, end - next);
1042 skb_trim(skb, skb->len - len);
1047 static int ath10k_mac_setup_bcn_tmpl(struct ath10k_vif *arvif)
1049 struct ath10k *ar = arvif->ar;
1050 struct ieee80211_hw *hw = ar->hw;
1051 struct ieee80211_vif *vif = arvif->vif;
1052 struct ieee80211_mutable_offsets offs = {};
1053 struct sk_buff *bcn;
1056 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1059 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1061 ath10k_warn(ar, "failed to get beacon template from mac80211\n");
1065 ret = ath10k_mac_setup_bcn_p2p_ie(arvif, bcn);
1067 ath10k_warn(ar, "failed to setup p2p go bcn ie: %d\n", ret);
1072 /* P2P IE is inserted by firmware automatically (as configured above)
1073 * so remove it from the base beacon template to avoid duplicate P2P
1074 * IEs in beacon frames.
1076 ath10k_mac_remove_vendor_ie(bcn, WLAN_OUI_WFA, WLAN_OUI_TYPE_WFA_P2P,
1077 offsetof(struct ieee80211_mgmt,
1078 u.beacon.variable));
1080 ret = ath10k_wmi_bcn_tmpl(ar, arvif->vdev_id, offs.tim_offset, bcn, 0,
1085 ath10k_warn(ar, "failed to submit beacon template command: %d\n",
1093 static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
1095 struct ath10k *ar = arvif->ar;
1096 struct ieee80211_hw *hw = ar->hw;
1097 struct ieee80211_vif *vif = arvif->vif;
1098 struct sk_buff *prb;
1101 if (!test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map))
1104 prb = ieee80211_proberesp_get(hw, vif);
1106 ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
1110 ret = ath10k_wmi_prb_tmpl(ar, arvif->vdev_id, prb);
1114 ath10k_warn(ar, "failed to submit probe resp template command: %d\n",
1122 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
1123 struct ieee80211_bss_conf *info)
1125 struct ath10k *ar = arvif->ar;
1128 lockdep_assert_held(&arvif->ar->conf_mutex);
1130 if (!info->enable_beacon) {
1131 ath10k_vdev_stop(arvif);
1133 arvif->is_started = false;
1134 arvif->is_up = false;
1136 spin_lock_bh(&arvif->ar->data_lock);
1137 ath10k_mac_vif_beacon_free(arvif);
1138 spin_unlock_bh(&arvif->ar->data_lock);
1143 arvif->tx_seq_no = 0x1000;
1145 ret = ath10k_vdev_start(arvif);
1150 ether_addr_copy(arvif->bssid, info->bssid);
1152 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1155 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
1156 arvif->vdev_id, ret);
1157 ath10k_vdev_stop(arvif);
1161 arvif->is_started = true;
1162 arvif->is_up = true;
1164 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1167 static void ath10k_control_ibss(struct ath10k_vif *arvif,
1168 struct ieee80211_bss_conf *info,
1169 const u8 self_peer[ETH_ALEN])
1171 struct ath10k *ar = arvif->ar;
1175 lockdep_assert_held(&arvif->ar->conf_mutex);
1177 if (!info->ibss_joined) {
1178 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
1180 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
1181 self_peer, arvif->vdev_id, ret);
1183 if (is_zero_ether_addr(arvif->bssid))
1186 eth_zero_addr(arvif->bssid);
1191 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1193 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1194 self_peer, arvif->vdev_id, ret);
1198 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1199 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1200 ATH10K_DEFAULT_ATIM);
1202 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1203 arvif->vdev_id, ret);
1206 static int ath10k_mac_vif_recalc_ps_wake_threshold(struct ath10k_vif *arvif)
1208 struct ath10k *ar = arvif->ar;
1213 lockdep_assert_held(&arvif->ar->conf_mutex);
1215 if (arvif->u.sta.uapsd)
1216 value = WMI_STA_PS_TX_WAKE_THRESHOLD_NEVER;
1218 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
1220 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
1221 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param, value);
1223 ath10k_warn(ar, "failed to submit ps wake threshold %u on vdev %i: %d\n",
1224 value, arvif->vdev_id, ret);
1231 static int ath10k_mac_vif_recalc_ps_poll_count(struct ath10k_vif *arvif)
1233 struct ath10k *ar = arvif->ar;
1238 lockdep_assert_held(&arvif->ar->conf_mutex);
1240 if (arvif->u.sta.uapsd)
1241 value = WMI_STA_PS_PSPOLL_COUNT_UAPSD;
1243 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
1245 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
1246 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
1249 ath10k_warn(ar, "failed to submit ps poll count %u on vdev %i: %d\n",
1250 value, arvif->vdev_id, ret);
1257 static int ath10k_mac_ps_vif_count(struct ath10k *ar)
1259 struct ath10k_vif *arvif;
1262 lockdep_assert_held(&ar->conf_mutex);
1264 list_for_each_entry(arvif, &ar->arvifs, list)
1271 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1273 struct ath10k *ar = arvif->ar;
1274 struct ieee80211_vif *vif = arvif->vif;
1275 struct ieee80211_conf *conf = &ar->hw->conf;
1276 enum wmi_sta_powersave_param param;
1277 enum wmi_sta_ps_mode psmode;
1282 lockdep_assert_held(&arvif->ar->conf_mutex);
1284 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1287 enable_ps = arvif->ps;
1289 if (enable_ps && ath10k_mac_ps_vif_count(ar) > 1 &&
1290 !test_bit(ATH10K_FW_FEATURE_MULTI_VIF_PS_SUPPORT,
1292 ath10k_warn(ar, "refusing to enable ps on vdev %i: not supported by fw\n",
1298 psmode = WMI_STA_PS_MODE_ENABLED;
1299 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1301 ps_timeout = conf->dynamic_ps_timeout;
1302 if (ps_timeout == 0) {
1303 /* Firmware doesn't like 0 */
1304 ps_timeout = ieee80211_tu_to_usec(
1305 vif->bss_conf.beacon_int) / 1000;
1308 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1311 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1312 arvif->vdev_id, ret);
1316 psmode = WMI_STA_PS_MODE_DISABLED;
1319 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1320 arvif->vdev_id, psmode ? "enable" : "disable");
1322 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1324 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1325 psmode, arvif->vdev_id, ret);
1332 static int ath10k_mac_vif_disable_keepalive(struct ath10k_vif *arvif)
1334 struct ath10k *ar = arvif->ar;
1335 struct wmi_sta_keepalive_arg arg = {};
1338 lockdep_assert_held(&arvif->ar->conf_mutex);
1340 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
1343 if (!test_bit(WMI_SERVICE_STA_KEEP_ALIVE, ar->wmi.svc_map))
1346 /* Some firmware revisions have a bug and ignore the `enabled` field.
1347 * Instead use the interval to disable the keepalive.
1349 arg.vdev_id = arvif->vdev_id;
1351 arg.method = WMI_STA_KEEPALIVE_METHOD_NULL_FRAME;
1352 arg.interval = WMI_STA_KEEPALIVE_INTERVAL_DISABLE;
1354 ret = ath10k_wmi_sta_keepalive(ar, &arg);
1356 ath10k_warn(ar, "failed to submit keepalive on vdev %i: %d\n",
1357 arvif->vdev_id, ret);
1364 /**********************/
1365 /* Station management */
1366 /**********************/
1368 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1369 struct ieee80211_vif *vif)
1371 /* Some firmware revisions have unstable STA powersave when listen
1372 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1373 * generate NullFunc frames properly even if buffered frames have been
1374 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1375 * buffered frames. Often pinging the device from AP would simply fail.
1377 * As a workaround set it to 1.
1379 if (vif->type == NL80211_IFTYPE_STATION)
1382 return ar->hw->conf.listen_interval;
1385 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1386 struct ieee80211_vif *vif,
1387 struct ieee80211_sta *sta,
1388 struct wmi_peer_assoc_complete_arg *arg)
1390 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1392 lockdep_assert_held(&ar->conf_mutex);
1394 ether_addr_copy(arg->addr, sta->addr);
1395 arg->vdev_id = arvif->vdev_id;
1396 arg->peer_aid = sta->aid;
1397 arg->peer_flags |= WMI_PEER_AUTH;
1398 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1399 arg->peer_num_spatial_streams = 1;
1400 arg->peer_caps = vif->bss_conf.assoc_capability;
1403 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1404 struct ieee80211_vif *vif,
1405 struct wmi_peer_assoc_complete_arg *arg)
1407 struct ieee80211_bss_conf *info = &vif->bss_conf;
1408 struct cfg80211_bss *bss;
1409 const u8 *rsnie = NULL;
1410 const u8 *wpaie = NULL;
1412 lockdep_assert_held(&ar->conf_mutex);
1414 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1415 info->bssid, NULL, 0, IEEE80211_BSS_TYPE_ANY,
1416 IEEE80211_PRIVACY_ANY);
1418 const struct cfg80211_bss_ies *ies;
1421 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1423 ies = rcu_dereference(bss->ies);
1425 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1426 WLAN_OUI_TYPE_MICROSOFT_WPA,
1430 cfg80211_put_bss(ar->hw->wiphy, bss);
1433 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1434 if (rsnie || wpaie) {
1435 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1436 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1440 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1441 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1445 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1446 struct ieee80211_sta *sta,
1447 struct wmi_peer_assoc_complete_arg *arg)
1449 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1450 const struct ieee80211_supported_band *sband;
1451 const struct ieee80211_rate *rates;
1455 lockdep_assert_held(&ar->conf_mutex);
1457 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1458 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1459 rates = sband->bitrates;
1461 rateset->num_rates = 0;
1463 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1464 if (!(ratemask & 1))
1467 rateset->rates[rateset->num_rates] = rates->hw_value;
1468 rateset->num_rates++;
1472 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1473 struct ieee80211_sta *sta,
1474 struct wmi_peer_assoc_complete_arg *arg)
1476 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1480 lockdep_assert_held(&ar->conf_mutex);
1482 if (!ht_cap->ht_supported)
1485 arg->peer_flags |= WMI_PEER_HT;
1486 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1487 ht_cap->ampdu_factor)) - 1;
1489 arg->peer_mpdu_density =
1490 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1492 arg->peer_ht_caps = ht_cap->cap;
1493 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1495 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1496 arg->peer_flags |= WMI_PEER_LDPC;
1498 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1499 arg->peer_flags |= WMI_PEER_40MHZ;
1500 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1503 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1504 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1506 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1507 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1509 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1510 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1511 arg->peer_flags |= WMI_PEER_STBC;
1514 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1515 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1516 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1517 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1518 arg->peer_rate_caps |= stbc;
1519 arg->peer_flags |= WMI_PEER_STBC;
1522 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1523 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1524 else if (ht_cap->mcs.rx_mask[1])
1525 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1527 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1528 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1529 arg->peer_ht_rates.rates[n++] = i;
1532 * This is a workaround for HT-enabled STAs which break the spec
1533 * and have no HT capabilities RX mask (no HT RX MCS map).
1535 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1536 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1538 * Firmware asserts if such situation occurs.
1541 arg->peer_ht_rates.num_rates = 8;
1542 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1543 arg->peer_ht_rates.rates[i] = i;
1545 arg->peer_ht_rates.num_rates = n;
1546 arg->peer_num_spatial_streams = sta->rx_nss;
1549 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1551 arg->peer_ht_rates.num_rates,
1552 arg->peer_num_spatial_streams);
1555 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1556 struct ath10k_vif *arvif,
1557 struct ieee80211_sta *sta)
1563 lockdep_assert_held(&ar->conf_mutex);
1565 if (sta->wme && sta->uapsd_queues) {
1566 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1567 sta->uapsd_queues, sta->max_sp);
1569 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1570 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1571 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1572 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1573 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1574 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1575 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1576 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1577 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1578 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1579 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1580 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1582 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1583 max_sp = sta->max_sp;
1585 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1587 WMI_AP_PS_PEER_PARAM_UAPSD,
1590 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1591 arvif->vdev_id, ret);
1595 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1597 WMI_AP_PS_PEER_PARAM_MAX_SP,
1600 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1601 arvif->vdev_id, ret);
1605 /* TODO setup this based on STA listen interval and
1606 beacon interval. Currently we don't know
1607 sta->listen_interval - mac80211 patch required.
1608 Currently use 10 seconds */
1609 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1610 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1613 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1614 arvif->vdev_id, ret);
1622 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1623 struct ieee80211_sta *sta,
1624 struct wmi_peer_assoc_complete_arg *arg)
1626 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1629 if (!vht_cap->vht_supported)
1632 arg->peer_flags |= WMI_PEER_VHT;
1634 if (ar->hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
1635 arg->peer_flags |= WMI_PEER_VHT_2G;
1637 arg->peer_vht_caps = vht_cap->cap;
1639 ampdu_factor = (vht_cap->cap &
1640 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1641 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1643 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1644 * zero in VHT IE. Using it would result in degraded throughput.
1645 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1646 * it if VHT max_mpdu is smaller. */
1647 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1648 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1649 ampdu_factor)) - 1);
1651 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1652 arg->peer_flags |= WMI_PEER_80MHZ;
1654 arg->peer_vht_rates.rx_max_rate =
1655 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1656 arg->peer_vht_rates.rx_mcs_set =
1657 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1658 arg->peer_vht_rates.tx_max_rate =
1659 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1660 arg->peer_vht_rates.tx_mcs_set =
1661 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1663 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1664 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1667 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1668 struct ieee80211_vif *vif,
1669 struct ieee80211_sta *sta,
1670 struct wmi_peer_assoc_complete_arg *arg)
1672 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1674 switch (arvif->vdev_type) {
1675 case WMI_VDEV_TYPE_AP:
1677 arg->peer_flags |= WMI_PEER_QOS;
1679 if (sta->wme && sta->uapsd_queues) {
1680 arg->peer_flags |= WMI_PEER_APSD;
1681 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1684 case WMI_VDEV_TYPE_STA:
1685 if (vif->bss_conf.qos)
1686 arg->peer_flags |= WMI_PEER_QOS;
1688 case WMI_VDEV_TYPE_IBSS:
1690 arg->peer_flags |= WMI_PEER_QOS;
1696 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM qos %d\n",
1697 sta->addr, !!(arg->peer_flags & WMI_PEER_QOS));
1700 static bool ath10k_mac_sta_has_11g_rates(struct ieee80211_sta *sta)
1702 /* First 4 rates in ath10k_rates are CCK (11b) rates. */
1703 return sta->supp_rates[IEEE80211_BAND_2GHZ] >> 4;
1706 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1707 struct ieee80211_vif *vif,
1708 struct ieee80211_sta *sta,
1709 struct wmi_peer_assoc_complete_arg *arg)
1711 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1713 switch (ar->hw->conf.chandef.chan->band) {
1714 case IEEE80211_BAND_2GHZ:
1715 if (sta->vht_cap.vht_supported) {
1716 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1717 phymode = MODE_11AC_VHT40;
1719 phymode = MODE_11AC_VHT20;
1720 } else if (sta->ht_cap.ht_supported) {
1721 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1722 phymode = MODE_11NG_HT40;
1724 phymode = MODE_11NG_HT20;
1725 } else if (ath10k_mac_sta_has_11g_rates(sta)) {
1732 case IEEE80211_BAND_5GHZ:
1736 if (sta->vht_cap.vht_supported) {
1737 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1738 phymode = MODE_11AC_VHT80;
1739 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1740 phymode = MODE_11AC_VHT40;
1741 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1742 phymode = MODE_11AC_VHT20;
1743 } else if (sta->ht_cap.ht_supported) {
1744 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1745 phymode = MODE_11NA_HT40;
1747 phymode = MODE_11NA_HT20;
1757 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1758 sta->addr, ath10k_wmi_phymode_str(phymode));
1760 arg->peer_phymode = phymode;
1761 WARN_ON(phymode == MODE_UNKNOWN);
1764 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1765 struct ieee80211_vif *vif,
1766 struct ieee80211_sta *sta,
1767 struct wmi_peer_assoc_complete_arg *arg)
1769 lockdep_assert_held(&ar->conf_mutex);
1771 memset(arg, 0, sizeof(*arg));
1773 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1774 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1775 ath10k_peer_assoc_h_rates(ar, sta, arg);
1776 ath10k_peer_assoc_h_ht(ar, sta, arg);
1777 ath10k_peer_assoc_h_vht(ar, sta, arg);
1778 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1779 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1784 static const u32 ath10k_smps_map[] = {
1785 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1786 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1787 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1788 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1791 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1793 const struct ieee80211_sta_ht_cap *ht_cap)
1797 if (!ht_cap->ht_supported)
1800 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1801 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1803 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1806 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1807 WMI_PEER_SMPS_STATE,
1808 ath10k_smps_map[smps]);
1811 static int ath10k_mac_vif_recalc_txbf(struct ath10k *ar,
1812 struct ieee80211_vif *vif,
1813 struct ieee80211_sta_vht_cap vht_cap)
1815 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1820 if (!(ar->vht_cap_info &
1821 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1822 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
1823 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1824 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
1827 param = ar->wmi.vdev_param->txbf;
1830 if (WARN_ON(param == WMI_VDEV_PARAM_UNSUPPORTED))
1833 /* The following logic is correct. If a remote STA advertises support
1834 * for being a beamformer then we should enable us being a beamformee.
1837 if (ar->vht_cap_info &
1838 (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
1839 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)) {
1840 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)
1841 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1843 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)
1844 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
1847 if (ar->vht_cap_info &
1848 (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
1849 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) {
1850 if (vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)
1851 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1853 if (vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE)
1854 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
1857 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFEE)
1858 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
1860 if (value & WMI_VDEV_PARAM_TXBF_MU_TX_BFER)
1861 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
1863 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param, value);
1865 ath10k_warn(ar, "failed to submit vdev param txbf 0x%x: %d\n",
1873 /* can be called only in mac80211 callbacks due to `key_count` usage */
1874 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1875 struct ieee80211_vif *vif,
1876 struct ieee80211_bss_conf *bss_conf)
1878 struct ath10k *ar = hw->priv;
1879 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1880 struct ieee80211_sta_ht_cap ht_cap;
1881 struct ieee80211_sta_vht_cap vht_cap;
1882 struct wmi_peer_assoc_complete_arg peer_arg;
1883 struct ieee80211_sta *ap_sta;
1886 lockdep_assert_held(&ar->conf_mutex);
1888 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1889 arvif->vdev_id, arvif->bssid, arvif->aid);
1893 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1895 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1896 bss_conf->bssid, arvif->vdev_id);
1901 /* ap_sta must be accessed only within rcu section which must be left
1902 * before calling ath10k_setup_peer_smps() which might sleep. */
1903 ht_cap = ap_sta->ht_cap;
1904 vht_cap = ap_sta->vht_cap;
1906 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1908 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1909 bss_conf->bssid, arvif->vdev_id, ret);
1916 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1918 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1919 bss_conf->bssid, arvif->vdev_id, ret);
1923 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1925 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1926 arvif->vdev_id, ret);
1930 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
1932 ath10k_warn(ar, "failed to recalc txbf for vdev %i on bss %pM: %d\n",
1933 arvif->vdev_id, bss_conf->bssid, ret);
1937 ath10k_dbg(ar, ATH10K_DBG_MAC,
1938 "mac vdev %d up (associated) bssid %pM aid %d\n",
1939 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1941 WARN_ON(arvif->is_up);
1943 arvif->aid = bss_conf->aid;
1944 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1946 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1948 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1949 arvif->vdev_id, ret);
1953 arvif->is_up = true;
1955 /* Workaround: Some firmware revisions (tested with qca6174
1956 * WLAN.RM.2.0-00073) have buggy powersave state machine and must be
1957 * poked with peer param command.
1959 ret = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, arvif->bssid,
1960 WMI_PEER_DUMMY_VAR, 1);
1962 ath10k_warn(ar, "failed to poke peer %pM param for ps workaround on vdev %i: %d\n",
1963 arvif->bssid, arvif->vdev_id, ret);
1968 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1969 struct ieee80211_vif *vif)
1971 struct ath10k *ar = hw->priv;
1972 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1973 struct ieee80211_sta_vht_cap vht_cap = {};
1976 lockdep_assert_held(&ar->conf_mutex);
1978 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1979 arvif->vdev_id, arvif->bssid);
1981 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1983 ath10k_warn(ar, "faield to down vdev %i: %d\n",
1984 arvif->vdev_id, ret);
1986 arvif->def_wep_key_idx = -1;
1988 ret = ath10k_mac_vif_recalc_txbf(ar, vif, vht_cap);
1990 ath10k_warn(ar, "failed to recalc txbf for vdev %i: %d\n",
1991 arvif->vdev_id, ret);
1995 arvif->is_up = false;
1998 static int ath10k_station_assoc(struct ath10k *ar,
1999 struct ieee80211_vif *vif,
2000 struct ieee80211_sta *sta,
2003 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2004 struct wmi_peer_assoc_complete_arg peer_arg;
2007 lockdep_assert_held(&ar->conf_mutex);
2009 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
2011 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
2012 sta->addr, arvif->vdev_id, ret);
2016 peer_arg.peer_reassoc = reassoc;
2017 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
2019 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2020 sta->addr, arvif->vdev_id, ret);
2024 /* Re-assoc is run only to update supported rates for given station. It
2025 * doesn't make much sense to reconfigure the peer completely.
2028 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
2031 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
2032 arvif->vdev_id, ret);
2036 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
2038 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
2039 sta->addr, arvif->vdev_id, ret);
2044 arvif->num_legacy_stations++;
2045 ret = ath10k_recalc_rtscts_prot(arvif);
2047 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2048 arvif->vdev_id, ret);
2053 /* Plumb cached keys only for static WEP */
2054 if (arvif->def_wep_key_idx != -1) {
2055 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
2057 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
2058 arvif->vdev_id, ret);
2067 static int ath10k_station_disassoc(struct ath10k *ar,
2068 struct ieee80211_vif *vif,
2069 struct ieee80211_sta *sta)
2071 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2074 lockdep_assert_held(&ar->conf_mutex);
2077 arvif->num_legacy_stations--;
2078 ret = ath10k_recalc_rtscts_prot(arvif);
2080 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
2081 arvif->vdev_id, ret);
2086 ret = ath10k_clear_peer_keys(arvif, sta->addr);
2088 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
2089 arvif->vdev_id, ret);
2100 static int ath10k_update_channel_list(struct ath10k *ar)
2102 struct ieee80211_hw *hw = ar->hw;
2103 struct ieee80211_supported_band **bands;
2104 enum ieee80211_band band;
2105 struct ieee80211_channel *channel;
2106 struct wmi_scan_chan_list_arg arg = {0};
2107 struct wmi_channel_arg *ch;
2113 lockdep_assert_held(&ar->conf_mutex);
2115 bands = hw->wiphy->bands;
2116 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2120 for (i = 0; i < bands[band]->n_channels; i++) {
2121 if (bands[band]->channels[i].flags &
2122 IEEE80211_CHAN_DISABLED)
2129 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
2130 arg.channels = kzalloc(len, GFP_KERNEL);
2135 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2139 for (i = 0; i < bands[band]->n_channels; i++) {
2140 channel = &bands[band]->channels[i];
2142 if (channel->flags & IEEE80211_CHAN_DISABLED)
2145 ch->allow_ht = true;
2147 /* FIXME: when should we really allow VHT? */
2148 ch->allow_vht = true;
2151 !(channel->flags & IEEE80211_CHAN_NO_IR);
2154 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
2157 !!(channel->flags & IEEE80211_CHAN_RADAR);
2159 passive = channel->flags & IEEE80211_CHAN_NO_IR;
2160 ch->passive = passive;
2162 ch->freq = channel->center_freq;
2163 ch->band_center_freq1 = channel->center_freq;
2165 ch->max_power = channel->max_power * 2;
2166 ch->max_reg_power = channel->max_reg_power * 2;
2167 ch->max_antenna_gain = channel->max_antenna_gain * 2;
2168 ch->reg_class_id = 0; /* FIXME */
2170 /* FIXME: why use only legacy modes, why not any
2171 * HT/VHT modes? Would that even make any
2173 if (channel->band == IEEE80211_BAND_2GHZ)
2174 ch->mode = MODE_11G;
2176 ch->mode = MODE_11A;
2178 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
2181 ath10k_dbg(ar, ATH10K_DBG_WMI,
2182 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
2183 ch - arg.channels, arg.n_channels,
2184 ch->freq, ch->max_power, ch->max_reg_power,
2185 ch->max_antenna_gain, ch->mode);
2191 ret = ath10k_wmi_scan_chan_list(ar, &arg);
2192 kfree(arg.channels);
2197 static enum wmi_dfs_region
2198 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
2200 switch (dfs_region) {
2201 case NL80211_DFS_UNSET:
2202 return WMI_UNINIT_DFS_DOMAIN;
2203 case NL80211_DFS_FCC:
2204 return WMI_FCC_DFS_DOMAIN;
2205 case NL80211_DFS_ETSI:
2206 return WMI_ETSI_DFS_DOMAIN;
2207 case NL80211_DFS_JP:
2208 return WMI_MKK4_DFS_DOMAIN;
2210 return WMI_UNINIT_DFS_DOMAIN;
2213 static void ath10k_regd_update(struct ath10k *ar)
2215 struct reg_dmn_pair_mapping *regpair;
2217 enum wmi_dfs_region wmi_dfs_reg;
2218 enum nl80211_dfs_regions nl_dfs_reg;
2220 lockdep_assert_held(&ar->conf_mutex);
2222 ret = ath10k_update_channel_list(ar);
2224 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
2226 regpair = ar->ath_common.regulatory.regpair;
2228 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2229 nl_dfs_reg = ar->dfs_detector->region;
2230 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
2232 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
2235 /* Target allows setting up per-band regdomain but ath_common provides
2236 * a combined one only */
2237 ret = ath10k_wmi_pdev_set_regdomain(ar,
2238 regpair->reg_domain,
2239 regpair->reg_domain, /* 2ghz */
2240 regpair->reg_domain, /* 5ghz */
2241 regpair->reg_2ghz_ctl,
2242 regpair->reg_5ghz_ctl,
2245 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
2248 static void ath10k_reg_notifier(struct wiphy *wiphy,
2249 struct regulatory_request *request)
2251 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
2252 struct ath10k *ar = hw->priv;
2255 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
2257 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
2258 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
2259 request->dfs_region);
2260 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
2261 request->dfs_region);
2263 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
2264 request->dfs_region);
2267 mutex_lock(&ar->conf_mutex);
2268 if (ar->state == ATH10K_STATE_ON)
2269 ath10k_regd_update(ar);
2270 mutex_unlock(&ar->conf_mutex);
2277 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
2279 if (ieee80211_is_mgmt(hdr->frame_control))
2280 return HTT_DATA_TX_EXT_TID_MGMT;
2282 if (!ieee80211_is_data_qos(hdr->frame_control))
2283 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2285 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
2286 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2288 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
2291 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
2294 return ath10k_vif_to_arvif(vif)->vdev_id;
2296 if (ar->monitor_started)
2297 return ar->monitor_vdev_id;
2299 ath10k_warn(ar, "failed to resolve vdev id\n");
2303 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
2304 * Control in the header.
2306 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
2308 struct ieee80211_hdr *hdr = (void *)skb->data;
2309 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
2312 if (!ieee80211_is_data_qos(hdr->frame_control))
2315 qos_ctl = ieee80211_get_qos_ctl(hdr);
2316 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
2317 skb->data, (void *)qos_ctl - (void *)skb->data);
2318 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
2320 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
2321 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
2322 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
2323 * it is safe to downgrade to NullFunc.
2325 hdr = (void *)skb->data;
2326 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
2327 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
2328 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
2332 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
2333 struct ieee80211_vif *vif,
2334 struct sk_buff *skb)
2336 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2337 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2339 /* This is case only for P2P_GO */
2340 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
2341 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
2344 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
2345 spin_lock_bh(&ar->data_lock);
2346 if (arvif->u.ap.noa_data)
2347 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2349 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2350 arvif->u.ap.noa_data,
2351 arvif->u.ap.noa_len);
2352 spin_unlock_bh(&ar->data_lock);
2356 static bool ath10k_mac_need_offchan_tx_work(struct ath10k *ar)
2358 /* FIXME: Not really sure since when the behaviour changed. At some
2359 * point new firmware stopped requiring creation of peer entries for
2360 * offchannel tx (and actually creating them causes issues with wmi-htc
2361 * tx credit replenishment and reliability). Assuming it's at least 3.4
2362 * because that's when the `freq` was introduced to TX_FRM HTT command.
2364 return !(ar->htt.target_version_major >= 3 &&
2365 ar->htt.target_version_minor >= 4);
2368 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2370 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2373 if (ar->htt.target_version_major >= 3) {
2374 /* Since HTT 3.0 there is no separate mgmt tx command */
2375 ret = ath10k_htt_tx(&ar->htt, skb);
2379 if (ieee80211_is_mgmt(hdr->frame_control)) {
2380 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2382 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2383 ATH10K_MAX_NUM_MGMT_PENDING) {
2384 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2389 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2390 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2392 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2394 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2396 ieee80211_is_nullfunc(hdr->frame_control)) {
2397 /* FW does not report tx status properly for NullFunc frames
2398 * unless they are sent through mgmt tx path. mac80211 sends
2399 * those frames when it detects link/beacon loss and depends
2400 * on the tx status to be correct. */
2401 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2403 ret = ath10k_htt_tx(&ar->htt, skb);
2408 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2410 ieee80211_free_txskb(ar->hw, skb);
2414 void ath10k_offchan_tx_purge(struct ath10k *ar)
2416 struct sk_buff *skb;
2419 skb = skb_dequeue(&ar->offchan_tx_queue);
2423 ieee80211_free_txskb(ar->hw, skb);
2427 void ath10k_offchan_tx_work(struct work_struct *work)
2429 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2430 struct ath10k_peer *peer;
2431 struct ieee80211_hdr *hdr;
2432 struct sk_buff *skb;
2433 const u8 *peer_addr;
2437 /* FW requirement: We must create a peer before FW will send out
2438 * an offchannel frame. Otherwise the frame will be stuck and
2439 * never transmitted. We delete the peer upon tx completion.
2440 * It is unlikely that a peer for offchannel tx will already be
2441 * present. However it may be in some rare cases so account for that.
2442 * Otherwise we might remove a legitimate peer and break stuff. */
2445 skb = skb_dequeue(&ar->offchan_tx_queue);
2449 mutex_lock(&ar->conf_mutex);
2451 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2454 hdr = (struct ieee80211_hdr *)skb->data;
2455 peer_addr = ieee80211_get_DA(hdr);
2456 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2458 spin_lock_bh(&ar->data_lock);
2459 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2460 spin_unlock_bh(&ar->data_lock);
2463 /* FIXME: should this use ath10k_warn()? */
2464 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2465 peer_addr, vdev_id);
2468 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2470 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2471 peer_addr, vdev_id, ret);
2474 spin_lock_bh(&ar->data_lock);
2475 reinit_completion(&ar->offchan_tx_completed);
2476 ar->offchan_tx_skb = skb;
2477 spin_unlock_bh(&ar->data_lock);
2479 ath10k_tx_htt(ar, skb);
2481 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2484 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2488 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2490 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2491 peer_addr, vdev_id, ret);
2494 mutex_unlock(&ar->conf_mutex);
2498 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2500 struct sk_buff *skb;
2503 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2507 ieee80211_free_txskb(ar->hw, skb);
2511 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2513 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2514 struct sk_buff *skb;
2518 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2522 ret = ath10k_wmi_mgmt_tx(ar, skb);
2524 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2526 ieee80211_free_txskb(ar->hw, skb);
2535 void __ath10k_scan_finish(struct ath10k *ar)
2537 lockdep_assert_held(&ar->data_lock);
2539 switch (ar->scan.state) {
2540 case ATH10K_SCAN_IDLE:
2542 case ATH10K_SCAN_RUNNING:
2543 if (ar->scan.is_roc)
2544 ieee80211_remain_on_channel_expired(ar->hw);
2546 case ATH10K_SCAN_ABORTING:
2547 if (!ar->scan.is_roc)
2548 ieee80211_scan_completed(ar->hw,
2550 ATH10K_SCAN_ABORTING));
2552 case ATH10K_SCAN_STARTING:
2553 ar->scan.state = ATH10K_SCAN_IDLE;
2554 ar->scan_channel = NULL;
2555 ath10k_offchan_tx_purge(ar);
2556 cancel_delayed_work(&ar->scan.timeout);
2557 complete_all(&ar->scan.completed);
2562 void ath10k_scan_finish(struct ath10k *ar)
2564 spin_lock_bh(&ar->data_lock);
2565 __ath10k_scan_finish(ar);
2566 spin_unlock_bh(&ar->data_lock);
2569 static int ath10k_scan_stop(struct ath10k *ar)
2571 struct wmi_stop_scan_arg arg = {
2572 .req_id = 1, /* FIXME */
2573 .req_type = WMI_SCAN_STOP_ONE,
2574 .u.scan_id = ATH10K_SCAN_ID,
2578 lockdep_assert_held(&ar->conf_mutex);
2580 ret = ath10k_wmi_stop_scan(ar, &arg);
2582 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2586 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2588 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2590 } else if (ret > 0) {
2595 /* Scan state should be updated upon scan completion but in case
2596 * firmware fails to deliver the event (for whatever reason) it is
2597 * desired to clean up scan state anyway. Firmware may have just
2598 * dropped the scan completion event delivery due to transport pipe
2599 * being overflown with data and/or it can recover on its own before
2600 * next scan request is submitted.
2602 spin_lock_bh(&ar->data_lock);
2603 if (ar->scan.state != ATH10K_SCAN_IDLE)
2604 __ath10k_scan_finish(ar);
2605 spin_unlock_bh(&ar->data_lock);
2610 static void ath10k_scan_abort(struct ath10k *ar)
2614 lockdep_assert_held(&ar->conf_mutex);
2616 spin_lock_bh(&ar->data_lock);
2618 switch (ar->scan.state) {
2619 case ATH10K_SCAN_IDLE:
2620 /* This can happen if timeout worker kicked in and called
2621 * abortion while scan completion was being processed.
2624 case ATH10K_SCAN_STARTING:
2625 case ATH10K_SCAN_ABORTING:
2626 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2627 ath10k_scan_state_str(ar->scan.state),
2630 case ATH10K_SCAN_RUNNING:
2631 ar->scan.state = ATH10K_SCAN_ABORTING;
2632 spin_unlock_bh(&ar->data_lock);
2634 ret = ath10k_scan_stop(ar);
2636 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2638 spin_lock_bh(&ar->data_lock);
2642 spin_unlock_bh(&ar->data_lock);
2645 void ath10k_scan_timeout_work(struct work_struct *work)
2647 struct ath10k *ar = container_of(work, struct ath10k,
2650 mutex_lock(&ar->conf_mutex);
2651 ath10k_scan_abort(ar);
2652 mutex_unlock(&ar->conf_mutex);
2655 static int ath10k_start_scan(struct ath10k *ar,
2656 const struct wmi_start_scan_arg *arg)
2660 lockdep_assert_held(&ar->conf_mutex);
2662 ret = ath10k_wmi_start_scan(ar, arg);
2666 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2668 ret = ath10k_scan_stop(ar);
2670 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2675 /* If we failed to start the scan, return error code at
2676 * this point. This is probably due to some issue in the
2677 * firmware, but no need to wedge the driver due to that...
2679 spin_lock_bh(&ar->data_lock);
2680 if (ar->scan.state == ATH10K_SCAN_IDLE) {
2681 spin_unlock_bh(&ar->data_lock);
2684 spin_unlock_bh(&ar->data_lock);
2686 /* Add a 200ms margin to account for event/command processing */
2687 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2688 msecs_to_jiffies(arg->max_scan_time+200));
2692 /**********************/
2693 /* mac80211 callbacks */
2694 /**********************/
2696 static void ath10k_tx(struct ieee80211_hw *hw,
2697 struct ieee80211_tx_control *control,
2698 struct sk_buff *skb)
2700 struct ath10k *ar = hw->priv;
2701 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2702 struct ieee80211_vif *vif = info->control.vif;
2703 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2705 /* We should disable CCK RATE due to P2P */
2706 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2707 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2709 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2710 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2711 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2713 /* it makes no sense to process injected frames like that */
2714 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2715 ath10k_tx_h_nwifi(hw, skb);
2716 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2717 ath10k_tx_h_seq_no(vif, skb);
2720 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2721 spin_lock_bh(&ar->data_lock);
2722 ATH10K_SKB_CB(skb)->htt.freq = ar->scan.roc_freq;
2723 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2724 spin_unlock_bh(&ar->data_lock);
2726 if (ath10k_mac_need_offchan_tx_work(ar)) {
2727 ATH10K_SKB_CB(skb)->htt.freq = 0;
2728 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2730 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2733 skb_queue_tail(&ar->offchan_tx_queue, skb);
2734 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2739 ath10k_tx_htt(ar, skb);
2742 /* Must not be called with conf_mutex held as workers can use that also. */
2743 void ath10k_drain_tx(struct ath10k *ar)
2745 /* make sure rcu-protected mac80211 tx path itself is drained */
2748 ath10k_offchan_tx_purge(ar);
2749 ath10k_mgmt_over_wmi_tx_purge(ar);
2751 cancel_work_sync(&ar->offchan_tx_work);
2752 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2755 void ath10k_halt(struct ath10k *ar)
2757 struct ath10k_vif *arvif;
2759 lockdep_assert_held(&ar->conf_mutex);
2761 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2762 ar->filter_flags = 0;
2763 ar->monitor = false;
2765 if (ar->monitor_started)
2766 ath10k_monitor_stop(ar);
2768 ar->monitor_started = false;
2770 ath10k_scan_finish(ar);
2771 ath10k_peer_cleanup_all(ar);
2772 ath10k_core_stop(ar);
2773 ath10k_hif_power_down(ar);
2775 spin_lock_bh(&ar->data_lock);
2776 list_for_each_entry(arvif, &ar->arvifs, list)
2777 ath10k_mac_vif_beacon_cleanup(arvif);
2778 spin_unlock_bh(&ar->data_lock);
2781 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2783 struct ath10k *ar = hw->priv;
2785 mutex_lock(&ar->conf_mutex);
2787 if (ar->cfg_tx_chainmask) {
2788 *tx_ant = ar->cfg_tx_chainmask;
2789 *rx_ant = ar->cfg_rx_chainmask;
2791 *tx_ant = ar->supp_tx_chainmask;
2792 *rx_ant = ar->supp_rx_chainmask;
2795 mutex_unlock(&ar->conf_mutex);
2800 static void ath10k_check_chain_mask(struct ath10k *ar, u32 cm, const char *dbg)
2802 /* It is not clear that allowing gaps in chainmask
2803 * is helpful. Probably it will not do what user
2804 * is hoping for, so warn in that case.
2806 if (cm == 15 || cm == 7 || cm == 3 || cm == 1 || cm == 0)
2809 ath10k_warn(ar, "mac %s antenna chainmask may be invalid: 0x%x. Suggested values: 15, 7, 3, 1 or 0.\n",
2813 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2817 lockdep_assert_held(&ar->conf_mutex);
2819 ath10k_check_chain_mask(ar, tx_ant, "tx");
2820 ath10k_check_chain_mask(ar, rx_ant, "rx");
2822 ar->cfg_tx_chainmask = tx_ant;
2823 ar->cfg_rx_chainmask = rx_ant;
2825 if ((ar->state != ATH10K_STATE_ON) &&
2826 (ar->state != ATH10K_STATE_RESTARTED))
2829 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2832 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2837 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2840 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2848 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2850 struct ath10k *ar = hw->priv;
2853 mutex_lock(&ar->conf_mutex);
2854 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2855 mutex_unlock(&ar->conf_mutex);
2859 static int ath10k_start(struct ieee80211_hw *hw)
2861 struct ath10k *ar = hw->priv;
2865 * This makes sense only when restarting hw. It is harmless to call
2866 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2867 * commands will be submitted while restarting.
2869 ath10k_drain_tx(ar);
2871 mutex_lock(&ar->conf_mutex);
2873 switch (ar->state) {
2874 case ATH10K_STATE_OFF:
2875 ar->state = ATH10K_STATE_ON;
2877 case ATH10K_STATE_RESTARTING:
2879 ar->state = ATH10K_STATE_RESTARTED;
2881 case ATH10K_STATE_ON:
2882 case ATH10K_STATE_RESTARTED:
2883 case ATH10K_STATE_WEDGED:
2887 case ATH10K_STATE_UTF:
2892 ret = ath10k_hif_power_up(ar);
2894 ath10k_err(ar, "Could not init hif: %d\n", ret);
2898 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2900 ath10k_err(ar, "Could not init core: %d\n", ret);
2901 goto err_power_down;
2904 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2906 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2910 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2912 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2916 if (ar->cfg_tx_chainmask)
2917 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2918 ar->cfg_rx_chainmask);
2921 * By default FW set ARP frames ac to voice (6). In that case ARP
2922 * exchange is not working properly for UAPSD enabled AP. ARP requests
2923 * which arrives with access category 0 are processed by network stack
2924 * and send back with access category 0, but FW changes access category
2925 * to 6. Set ARP frames access category to best effort (0) solves
2929 ret = ath10k_wmi_pdev_set_param(ar,
2930 ar->wmi.pdev_param->arp_ac_override, 0);
2932 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2937 ar->num_started_vdevs = 0;
2938 ath10k_regd_update(ar);
2940 ath10k_spectral_start(ar);
2942 mutex_unlock(&ar->conf_mutex);
2946 ath10k_core_stop(ar);
2949 ath10k_hif_power_down(ar);
2952 ar->state = ATH10K_STATE_OFF;
2955 mutex_unlock(&ar->conf_mutex);
2959 static void ath10k_stop(struct ieee80211_hw *hw)
2961 struct ath10k *ar = hw->priv;
2963 ath10k_drain_tx(ar);
2965 mutex_lock(&ar->conf_mutex);
2966 if (ar->state != ATH10K_STATE_OFF) {
2968 ar->state = ATH10K_STATE_OFF;
2970 mutex_unlock(&ar->conf_mutex);
2972 cancel_delayed_work_sync(&ar->scan.timeout);
2973 cancel_work_sync(&ar->restart_work);
2976 static int ath10k_config_ps(struct ath10k *ar)
2978 struct ath10k_vif *arvif;
2981 lockdep_assert_held(&ar->conf_mutex);
2983 list_for_each_entry(arvif, &ar->arvifs, list) {
2984 ret = ath10k_mac_vif_setup_ps(arvif);
2986 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2994 static const char *chandef_get_width(enum nl80211_chan_width width)
2997 case NL80211_CHAN_WIDTH_20_NOHT:
2999 case NL80211_CHAN_WIDTH_20:
3001 case NL80211_CHAN_WIDTH_40:
3003 case NL80211_CHAN_WIDTH_80:
3005 case NL80211_CHAN_WIDTH_80P80:
3007 case NL80211_CHAN_WIDTH_160:
3009 case NL80211_CHAN_WIDTH_5:
3011 case NL80211_CHAN_WIDTH_10:
3017 static void ath10k_config_chan(struct ath10k *ar)
3019 struct ath10k_vif *arvif;
3022 lockdep_assert_held(&ar->conf_mutex);
3024 ath10k_dbg(ar, ATH10K_DBG_MAC,
3025 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
3026 ar->chandef.chan->center_freq,
3027 ar->chandef.center_freq1,
3028 ar->chandef.center_freq2,
3029 chandef_get_width(ar->chandef.width));
3031 /* First stop monitor interface. Some FW versions crash if there's a
3032 * lone monitor interface. */
3033 if (ar->monitor_started)
3034 ath10k_monitor_stop(ar);
3036 list_for_each_entry(arvif, &ar->arvifs, list) {
3037 if (!arvif->is_started)
3043 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3046 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
3048 ath10k_warn(ar, "failed to down vdev %d: %d\n",
3049 arvif->vdev_id, ret);
3054 /* all vdevs are downed now - attempt to restart and re-up them */
3056 list_for_each_entry(arvif, &ar->arvifs, list) {
3057 if (!arvif->is_started)
3060 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
3063 ret = ath10k_vdev_restart(arvif);
3065 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
3066 arvif->vdev_id, ret);
3073 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
3076 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
3077 arvif->vdev_id, ret);
3082 ath10k_monitor_recalc(ar);
3085 static int ath10k_mac_txpower_setup(struct ath10k *ar, int txpower)
3090 lockdep_assert_held(&ar->conf_mutex);
3092 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac txpower %d\n", txpower);
3094 param = ar->wmi.pdev_param->txpower_limit2g;
3095 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3097 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
3102 param = ar->wmi.pdev_param->txpower_limit5g;
3103 ret = ath10k_wmi_pdev_set_param(ar, param, txpower * 2);
3105 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
3113 static int ath10k_mac_txpower_recalc(struct ath10k *ar)
3115 struct ath10k_vif *arvif;
3116 int ret, txpower = -1;
3118 lockdep_assert_held(&ar->conf_mutex);
3120 list_for_each_entry(arvif, &ar->arvifs, list) {
3121 WARN_ON(arvif->txpower < 0);
3124 txpower = arvif->txpower;
3126 txpower = min(txpower, arvif->txpower);
3129 if (WARN_ON(txpower == -1))
3132 ret = ath10k_mac_txpower_setup(ar, txpower);
3134 ath10k_warn(ar, "failed to setup tx power %d: %d\n",
3142 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
3144 struct ath10k *ar = hw->priv;
3145 struct ieee80211_conf *conf = &hw->conf;
3148 mutex_lock(&ar->conf_mutex);
3150 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
3151 ath10k_dbg(ar, ATH10K_DBG_MAC,
3152 "mac config channel %dMHz flags 0x%x radar %d\n",
3153 conf->chandef.chan->center_freq,
3154 conf->chandef.chan->flags,
3155 conf->radar_enabled);
3157 spin_lock_bh(&ar->data_lock);
3158 ar->rx_channel = conf->chandef.chan;
3159 spin_unlock_bh(&ar->data_lock);
3161 ar->radar_enabled = conf->radar_enabled;
3162 ath10k_recalc_radar_detection(ar);
3164 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
3165 ar->chandef = conf->chandef;
3166 ath10k_config_chan(ar);
3170 if (changed & IEEE80211_CONF_CHANGE_PS)
3171 ath10k_config_ps(ar);
3173 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
3174 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
3175 ret = ath10k_monitor_recalc(ar);
3177 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
3180 mutex_unlock(&ar->conf_mutex);
3184 static u32 get_nss_from_chainmask(u16 chain_mask)
3186 if ((chain_mask & 0x15) == 0x15)
3188 else if ((chain_mask & 0x7) == 0x7)
3190 else if ((chain_mask & 0x3) == 0x3)
3197 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
3198 * because we will send mgmt frames without CCK. This requirement
3199 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
3202 static int ath10k_add_interface(struct ieee80211_hw *hw,
3203 struct ieee80211_vif *vif)
3205 struct ath10k *ar = hw->priv;
3206 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3207 enum wmi_sta_powersave_param param;
3213 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3215 mutex_lock(&ar->conf_mutex);
3217 memset(arvif, 0, sizeof(*arvif));
3222 INIT_LIST_HEAD(&arvif->list);
3224 if (ar->free_vdev_map == 0) {
3225 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
3229 bit = __ffs64(ar->free_vdev_map);
3231 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
3232 bit, ar->free_vdev_map);
3234 arvif->vdev_id = bit;
3235 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
3237 switch (vif->type) {
3238 case NL80211_IFTYPE_P2P_DEVICE:
3239 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3240 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
3242 case NL80211_IFTYPE_UNSPECIFIED:
3243 case NL80211_IFTYPE_STATION:
3244 arvif->vdev_type = WMI_VDEV_TYPE_STA;
3246 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
3248 case NL80211_IFTYPE_ADHOC:
3249 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
3251 case NL80211_IFTYPE_AP:
3252 arvif->vdev_type = WMI_VDEV_TYPE_AP;
3255 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
3257 case NL80211_IFTYPE_MONITOR:
3258 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
3265 /* Some firmware revisions don't wait for beacon tx completion before
3266 * sending another SWBA event. This could lead to hardware using old
3267 * (freed) beacon data in some cases, e.g. tx credit starvation
3268 * combined with missed TBTT. This is very very rare.
3270 * On non-IOMMU-enabled hosts this could be a possible security issue
3271 * because hw could beacon some random data on the air. On
3272 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
3273 * device would crash.
3275 * Since there are no beacon tx completions (implicit nor explicit)
3276 * propagated to host the only workaround for this is to allocate a
3277 * DMA-coherent buffer for a lifetime of a vif and use it for all
3278 * beacon tx commands. Worst case for this approach is some beacons may
3279 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
3281 if (vif->type == NL80211_IFTYPE_ADHOC ||
3282 vif->type == NL80211_IFTYPE_AP) {
3283 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
3284 IEEE80211_MAX_FRAME_LEN,
3285 &arvif->beacon_paddr,
3287 if (!arvif->beacon_buf) {
3289 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
3295 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
3296 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
3297 arvif->beacon_buf ? "single-buf" : "per-skb");
3299 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
3300 arvif->vdev_subtype, vif->addr);
3302 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
3303 arvif->vdev_id, ret);
3307 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
3308 list_add(&arvif->list, &ar->arvifs);
3310 /* It makes no sense to have firmware do keepalives. mac80211 already
3311 * takes care of this with idle connection polling.
3313 ret = ath10k_mac_vif_disable_keepalive(arvif);
3315 ath10k_warn(ar, "failed to disable keepalive on vdev %i: %d\n",
3316 arvif->vdev_id, ret);
3317 goto err_vdev_delete;
3320 arvif->def_wep_key_idx = -1;
3322 vdev_param = ar->wmi.vdev_param->tx_encap_type;
3323 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3324 ATH10K_HW_TXRX_NATIVE_WIFI);
3325 /* 10.X firmware does not support this VDEV parameter. Do not warn */
3326 if (ret && ret != -EOPNOTSUPP) {
3327 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
3328 arvif->vdev_id, ret);
3329 goto err_vdev_delete;
3332 if (ar->cfg_tx_chainmask) {
3333 u16 nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
3335 vdev_param = ar->wmi.vdev_param->nss;
3336 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3339 ath10k_warn(ar, "failed to set vdev %i chainmask 0x%x, nss %i: %d\n",
3340 arvif->vdev_id, ar->cfg_tx_chainmask, nss,
3342 goto err_vdev_delete;
3346 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3347 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
3349 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
3350 arvif->vdev_id, ret);
3351 goto err_vdev_delete;
3354 ret = ath10k_mac_set_kickout(arvif);
3356 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
3357 arvif->vdev_id, ret);
3358 goto err_peer_delete;
3362 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
3363 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
3364 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3365 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3368 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
3369 arvif->vdev_id, ret);
3370 goto err_peer_delete;
3373 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
3375 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
3376 arvif->vdev_id, ret);
3377 goto err_peer_delete;
3380 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
3382 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
3383 arvif->vdev_id, ret);
3384 goto err_peer_delete;
3388 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
3390 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3391 arvif->vdev_id, ret);
3392 goto err_peer_delete;
3395 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
3397 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
3398 arvif->vdev_id, ret);
3399 goto err_peer_delete;
3402 arvif->txpower = vif->bss_conf.txpower;
3403 ret = ath10k_mac_txpower_recalc(ar);
3405 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3406 goto err_peer_delete;
3409 mutex_unlock(&ar->conf_mutex);
3413 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
3414 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
3417 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3418 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3419 list_del(&arvif->list);
3422 if (arvif->beacon_buf) {
3423 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
3424 arvif->beacon_buf, arvif->beacon_paddr);
3425 arvif->beacon_buf = NULL;
3428 mutex_unlock(&ar->conf_mutex);
3433 static void ath10k_remove_interface(struct ieee80211_hw *hw,
3434 struct ieee80211_vif *vif)
3436 struct ath10k *ar = hw->priv;
3437 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3440 mutex_lock(&ar->conf_mutex);
3442 spin_lock_bh(&ar->data_lock);
3443 ath10k_mac_vif_beacon_cleanup(arvif);
3444 spin_unlock_bh(&ar->data_lock);
3446 ret = ath10k_spectral_vif_stop(arvif);
3448 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
3449 arvif->vdev_id, ret);
3451 ar->free_vdev_map |= 1LL << arvif->vdev_id;
3452 list_del(&arvif->list);
3454 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3455 ret = ath10k_wmi_peer_delete(arvif->ar, arvif->vdev_id,
3458 ath10k_warn(ar, "failed to submit AP self-peer removal on vdev %i: %d\n",
3459 arvif->vdev_id, ret);
3461 kfree(arvif->u.ap.noa_data);
3464 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3467 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3469 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3470 arvif->vdev_id, ret);
3472 /* Some firmware revisions don't notify host about self-peer removal
3473 * until after associated vdev is deleted.
3475 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
3476 ret = ath10k_wait_for_peer_deleted(ar, arvif->vdev_id,
3479 ath10k_warn(ar, "failed to remove AP self-peer on vdev %i: %d\n",
3480 arvif->vdev_id, ret);
3482 spin_lock_bh(&ar->data_lock);
3484 spin_unlock_bh(&ar->data_lock);
3487 ath10k_peer_cleanup(ar, arvif->vdev_id);
3489 mutex_unlock(&ar->conf_mutex);
3493 * FIXME: Has to be verified.
3495 #define SUPPORTED_FILTERS \
3496 (FIF_PROMISC_IN_BSS | \
3501 FIF_BCN_PRBRESP_PROMISC | \
3505 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3506 unsigned int changed_flags,
3507 unsigned int *total_flags,
3510 struct ath10k *ar = hw->priv;
3513 mutex_lock(&ar->conf_mutex);
3515 changed_flags &= SUPPORTED_FILTERS;
3516 *total_flags &= SUPPORTED_FILTERS;
3517 ar->filter_flags = *total_flags;
3519 ret = ath10k_monitor_recalc(ar);
3521 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3523 mutex_unlock(&ar->conf_mutex);
3526 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3527 struct ieee80211_vif *vif,
3528 struct ieee80211_bss_conf *info,
3531 struct ath10k *ar = hw->priv;
3532 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3534 u32 vdev_param, pdev_param, slottime, preamble;
3536 mutex_lock(&ar->conf_mutex);
3538 if (changed & BSS_CHANGED_IBSS)
3539 ath10k_control_ibss(arvif, info, vif->addr);
3541 if (changed & BSS_CHANGED_BEACON_INT) {
3542 arvif->beacon_interval = info->beacon_int;
3543 vdev_param = ar->wmi.vdev_param->beacon_interval;
3544 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3545 arvif->beacon_interval);
3546 ath10k_dbg(ar, ATH10K_DBG_MAC,
3547 "mac vdev %d beacon_interval %d\n",
3548 arvif->vdev_id, arvif->beacon_interval);
3551 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3552 arvif->vdev_id, ret);
3555 if (changed & BSS_CHANGED_BEACON) {
3556 ath10k_dbg(ar, ATH10K_DBG_MAC,
3557 "vdev %d set beacon tx mode to staggered\n",
3560 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3561 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3562 WMI_BEACON_STAGGERED_MODE);
3564 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3565 arvif->vdev_id, ret);
3567 ret = ath10k_mac_setup_bcn_tmpl(arvif);
3569 ath10k_warn(ar, "failed to update beacon template: %d\n",
3573 if (changed & BSS_CHANGED_AP_PROBE_RESP) {
3574 ret = ath10k_mac_setup_prb_tmpl(arvif);
3576 ath10k_warn(ar, "failed to setup probe resp template on vdev %i: %d\n",
3577 arvif->vdev_id, ret);
3580 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
3581 arvif->dtim_period = info->dtim_period;
3583 ath10k_dbg(ar, ATH10K_DBG_MAC,
3584 "mac vdev %d dtim_period %d\n",
3585 arvif->vdev_id, arvif->dtim_period);
3587 vdev_param = ar->wmi.vdev_param->dtim_period;
3588 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3589 arvif->dtim_period);
3591 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3592 arvif->vdev_id, ret);
3595 if (changed & BSS_CHANGED_SSID &&
3596 vif->type == NL80211_IFTYPE_AP) {
3597 arvif->u.ap.ssid_len = info->ssid_len;
3599 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3600 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3603 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3604 ether_addr_copy(arvif->bssid, info->bssid);
3606 if (changed & BSS_CHANGED_BEACON_ENABLED)
3607 ath10k_control_beaconing(arvif, info);
3609 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3610 arvif->use_cts_prot = info->use_cts_prot;
3611 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3612 arvif->vdev_id, info->use_cts_prot);
3614 ret = ath10k_recalc_rtscts_prot(arvif);
3616 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3617 arvif->vdev_id, ret);
3620 if (changed & BSS_CHANGED_ERP_SLOT) {
3621 if (info->use_short_slot)
3622 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3625 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3627 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3628 arvif->vdev_id, slottime);
3630 vdev_param = ar->wmi.vdev_param->slot_time;
3631 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3634 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3635 arvif->vdev_id, ret);
3638 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3639 if (info->use_short_preamble)
3640 preamble = WMI_VDEV_PREAMBLE_SHORT;
3642 preamble = WMI_VDEV_PREAMBLE_LONG;
3644 ath10k_dbg(ar, ATH10K_DBG_MAC,
3645 "mac vdev %d preamble %dn",
3646 arvif->vdev_id, preamble);
3648 vdev_param = ar->wmi.vdev_param->preamble;
3649 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3652 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3653 arvif->vdev_id, ret);
3656 if (changed & BSS_CHANGED_ASSOC) {
3658 /* Workaround: Make sure monitor vdev is not running
3659 * when associating to prevent some firmware revisions
3660 * (e.g. 10.1 and 10.2) from crashing.
3662 if (ar->monitor_started)
3663 ath10k_monitor_stop(ar);
3664 ath10k_bss_assoc(hw, vif, info);
3665 ath10k_monitor_recalc(ar);
3667 ath10k_bss_disassoc(hw, vif);
3671 if (changed & BSS_CHANGED_TXPOWER) {
3672 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3673 arvif->vdev_id, info->txpower);
3675 arvif->txpower = info->txpower;
3676 ret = ath10k_mac_txpower_recalc(ar);
3678 ath10k_warn(ar, "failed to recalc tx power: %d\n", ret);
3681 if (changed & BSS_CHANGED_PS) {
3682 arvif->ps = vif->bss_conf.ps;
3684 ret = ath10k_config_ps(ar);
3686 ath10k_warn(ar, "failed to setup ps on vdev %i: %d\n",
3687 arvif->vdev_id, ret);
3690 mutex_unlock(&ar->conf_mutex);
3693 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3694 struct ieee80211_vif *vif,
3695 struct ieee80211_scan_request *hw_req)
3697 struct ath10k *ar = hw->priv;
3698 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3699 struct cfg80211_scan_request *req = &hw_req->req;
3700 struct wmi_start_scan_arg arg;
3704 mutex_lock(&ar->conf_mutex);
3706 spin_lock_bh(&ar->data_lock);
3707 switch (ar->scan.state) {
3708 case ATH10K_SCAN_IDLE:
3709 reinit_completion(&ar->scan.started);
3710 reinit_completion(&ar->scan.completed);
3711 ar->scan.state = ATH10K_SCAN_STARTING;
3712 ar->scan.is_roc = false;
3713 ar->scan.vdev_id = arvif->vdev_id;
3716 case ATH10K_SCAN_STARTING:
3717 case ATH10K_SCAN_RUNNING:
3718 case ATH10K_SCAN_ABORTING:
3722 spin_unlock_bh(&ar->data_lock);
3727 memset(&arg, 0, sizeof(arg));
3728 ath10k_wmi_start_scan_init(ar, &arg);
3729 arg.vdev_id = arvif->vdev_id;
3730 arg.scan_id = ATH10K_SCAN_ID;
3733 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3736 arg.ie_len = req->ie_len;
3737 memcpy(arg.ie, req->ie, arg.ie_len);
3741 arg.n_ssids = req->n_ssids;
3742 for (i = 0; i < arg.n_ssids; i++) {
3743 arg.ssids[i].len = req->ssids[i].ssid_len;
3744 arg.ssids[i].ssid = req->ssids[i].ssid;
3747 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3750 if (req->n_channels) {
3751 arg.n_channels = req->n_channels;
3752 for (i = 0; i < arg.n_channels; i++)
3753 arg.channels[i] = req->channels[i]->center_freq;
3756 ret = ath10k_start_scan(ar, &arg);
3758 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3759 spin_lock_bh(&ar->data_lock);
3760 ar->scan.state = ATH10K_SCAN_IDLE;
3761 spin_unlock_bh(&ar->data_lock);
3765 mutex_unlock(&ar->conf_mutex);
3769 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3770 struct ieee80211_vif *vif)
3772 struct ath10k *ar = hw->priv;
3774 mutex_lock(&ar->conf_mutex);
3775 ath10k_scan_abort(ar);
3776 mutex_unlock(&ar->conf_mutex);
3778 cancel_delayed_work_sync(&ar->scan.timeout);
3781 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3782 struct ath10k_vif *arvif,
3783 enum set_key_cmd cmd,
3784 struct ieee80211_key_conf *key)
3786 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3789 /* 10.1 firmware branch requires default key index to be set to group
3790 * key index after installing it. Otherwise FW/HW Txes corrupted
3791 * frames with multi-vif APs. This is not required for main firmware
3792 * branch (e.g. 636).
3794 * FIXME: This has been tested only in AP. It remains unknown if this
3795 * is required for multi-vif STA interfaces on 10.1 */
3797 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3800 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3803 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3806 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3812 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3815 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3816 arvif->vdev_id, ret);
3819 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3820 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3821 struct ieee80211_key_conf *key)
3823 struct ath10k *ar = hw->priv;
3824 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3825 struct ath10k_peer *peer;
3826 const u8 *peer_addr;
3827 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3828 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3829 bool def_idx = false;
3832 if (key->keyidx > WMI_MAX_KEY_INDEX)
3835 mutex_lock(&ar->conf_mutex);
3838 peer_addr = sta->addr;
3839 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3840 peer_addr = vif->bss_conf.bssid;
3842 peer_addr = vif->addr;
3844 key->hw_key_idx = key->keyidx;
3846 /* the peer should not disappear in mid-way (unless FW goes awry) since
3847 * we already hold conf_mutex. we just make sure its there now. */
3848 spin_lock_bh(&ar->data_lock);
3849 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3850 spin_unlock_bh(&ar->data_lock);
3853 if (cmd == SET_KEY) {
3854 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3859 /* if the peer doesn't exist there is no key to disable
3867 arvif->wep_keys[key->keyidx] = key;
3869 arvif->wep_keys[key->keyidx] = NULL;
3871 if (cmd == DISABLE_KEY)
3872 ath10k_clear_vdev_key(arvif, key);
3875 /* set TX_USAGE flag for all the keys incase of dot1x-WEP. For
3876 * static WEP, do not set this flag for the keys whose key id
3877 * is greater than default key id.
3879 if (arvif->def_wep_key_idx == -1)
3882 ret = ath10k_install_key(arvif, key, cmd, peer_addr, def_idx);
3884 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3885 arvif->vdev_id, peer_addr, ret);
3889 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3891 spin_lock_bh(&ar->data_lock);
3892 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3893 if (peer && cmd == SET_KEY)
3894 peer->keys[key->keyidx] = key;
3895 else if (peer && cmd == DISABLE_KEY)
3896 peer->keys[key->keyidx] = NULL;
3897 else if (peer == NULL)
3898 /* impossible unless FW goes crazy */
3899 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3900 spin_unlock_bh(&ar->data_lock);
3903 mutex_unlock(&ar->conf_mutex);
3907 static void ath10k_set_default_unicast_key(struct ieee80211_hw *hw,
3908 struct ieee80211_vif *vif,
3911 struct ath10k *ar = hw->priv;
3912 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3915 mutex_lock(&arvif->ar->conf_mutex);
3917 if (arvif->ar->state != ATH10K_STATE_ON)
3920 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
3921 arvif->vdev_id, keyidx);
3923 ret = ath10k_wmi_vdev_set_param(arvif->ar,
3925 arvif->ar->wmi.vdev_param->def_keyid,
3929 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
3935 arvif->def_wep_key_idx = keyidx;
3937 mutex_unlock(&arvif->ar->conf_mutex);
3940 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3943 struct ath10k_vif *arvif;
3944 struct ath10k_sta *arsta;
3945 struct ieee80211_sta *sta;
3946 u32 changed, bw, nss, smps;
3949 arsta = container_of(wk, struct ath10k_sta, update_wk);
3950 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3951 arvif = arsta->arvif;
3954 spin_lock_bh(&ar->data_lock);
3956 changed = arsta->changed;
3963 spin_unlock_bh(&ar->data_lock);
3965 mutex_lock(&ar->conf_mutex);
3967 if (changed & IEEE80211_RC_BW_CHANGED) {
3968 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3971 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3972 WMI_PEER_CHAN_WIDTH, bw);
3974 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3975 sta->addr, bw, err);
3978 if (changed & IEEE80211_RC_NSS_CHANGED) {
3979 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3982 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3985 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3986 sta->addr, nss, err);
3989 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3990 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3993 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3994 WMI_PEER_SMPS_STATE, smps);
3996 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3997 sta->addr, smps, err);
4000 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED ||
4001 changed & IEEE80211_RC_NSS_CHANGED) {
4002 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates/nss\n",
4005 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
4007 ath10k_warn(ar, "failed to reassociate station: %pM\n",
4011 mutex_unlock(&ar->conf_mutex);
4014 static int ath10k_mac_inc_num_stations(struct ath10k_vif *arvif)
4016 struct ath10k *ar = arvif->ar;
4018 lockdep_assert_held(&ar->conf_mutex);
4020 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4021 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4024 if (ar->num_stations >= ar->max_num_stations)
4032 static void ath10k_mac_dec_num_stations(struct ath10k_vif *arvif)
4034 struct ath10k *ar = arvif->ar;
4036 lockdep_assert_held(&ar->conf_mutex);
4038 if (arvif->vdev_type != WMI_VDEV_TYPE_AP &&
4039 arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
4045 static int ath10k_sta_state(struct ieee80211_hw *hw,
4046 struct ieee80211_vif *vif,
4047 struct ieee80211_sta *sta,
4048 enum ieee80211_sta_state old_state,
4049 enum ieee80211_sta_state new_state)
4051 struct ath10k *ar = hw->priv;
4052 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4053 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4056 if (old_state == IEEE80211_STA_NOTEXIST &&
4057 new_state == IEEE80211_STA_NONE) {
4058 memset(arsta, 0, sizeof(*arsta));
4059 arsta->arvif = arvif;
4060 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
4063 /* cancel must be done outside the mutex to avoid deadlock */
4064 if ((old_state == IEEE80211_STA_NONE &&
4065 new_state == IEEE80211_STA_NOTEXIST))
4066 cancel_work_sync(&arsta->update_wk);
4068 mutex_lock(&ar->conf_mutex);
4070 if (old_state == IEEE80211_STA_NOTEXIST &&
4071 new_state == IEEE80211_STA_NONE) {
4073 * New station addition.
4075 ath10k_dbg(ar, ATH10K_DBG_MAC,
4076 "mac vdev %d peer create %pM (new sta) sta %d / %d peer %d / %d\n",
4077 arvif->vdev_id, sta->addr,
4078 ar->num_stations + 1, ar->max_num_stations,
4079 ar->num_peers + 1, ar->max_num_peers);
4081 ret = ath10k_mac_inc_num_stations(arvif);
4083 ath10k_warn(ar, "refusing to associate station: too many connected already (%d)\n",
4084 ar->max_num_stations);
4088 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
4090 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
4091 sta->addr, arvif->vdev_id, ret);
4092 ath10k_mac_dec_num_stations(arvif);
4096 if (vif->type == NL80211_IFTYPE_STATION) {
4097 WARN_ON(arvif->is_started);
4099 ret = ath10k_vdev_start(arvif);
4101 ath10k_warn(ar, "failed to start vdev %i: %d\n",
4102 arvif->vdev_id, ret);
4103 WARN_ON(ath10k_peer_delete(ar, arvif->vdev_id,
4105 ath10k_mac_dec_num_stations(arvif);
4109 arvif->is_started = true;
4111 } else if ((old_state == IEEE80211_STA_NONE &&
4112 new_state == IEEE80211_STA_NOTEXIST)) {
4114 * Existing station deletion.
4116 ath10k_dbg(ar, ATH10K_DBG_MAC,
4117 "mac vdev %d peer delete %pM (sta gone)\n",
4118 arvif->vdev_id, sta->addr);
4120 if (vif->type == NL80211_IFTYPE_STATION) {
4121 WARN_ON(!arvif->is_started);
4123 ret = ath10k_vdev_stop(arvif);
4125 ath10k_warn(ar, "failed to stop vdev %i: %d\n",
4126 arvif->vdev_id, ret);
4128 arvif->is_started = false;
4131 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
4133 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
4134 sta->addr, arvif->vdev_id, ret);
4136 ath10k_mac_dec_num_stations(arvif);
4137 } else if (old_state == IEEE80211_STA_AUTH &&
4138 new_state == IEEE80211_STA_ASSOC &&
4139 (vif->type == NL80211_IFTYPE_AP ||
4140 vif->type == NL80211_IFTYPE_ADHOC)) {
4144 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
4147 ret = ath10k_station_assoc(ar, vif, sta, false);
4149 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
4150 sta->addr, arvif->vdev_id, ret);
4151 } else if (old_state == IEEE80211_STA_ASSOC &&
4152 new_state == IEEE80211_STA_AUTH &&
4153 (vif->type == NL80211_IFTYPE_AP ||
4154 vif->type == NL80211_IFTYPE_ADHOC)) {
4158 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
4161 ret = ath10k_station_disassoc(ar, vif, sta);
4163 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
4164 sta->addr, arvif->vdev_id, ret);
4167 mutex_unlock(&ar->conf_mutex);
4171 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
4172 u16 ac, bool enable)
4174 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4175 struct wmi_sta_uapsd_auto_trig_arg arg = {};
4176 u32 prio = 0, acc = 0;
4180 lockdep_assert_held(&ar->conf_mutex);
4182 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4186 case IEEE80211_AC_VO:
4187 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4188 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
4192 case IEEE80211_AC_VI:
4193 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4194 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
4198 case IEEE80211_AC_BE:
4199 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4200 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
4204 case IEEE80211_AC_BK:
4205 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4206 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
4213 arvif->u.sta.uapsd |= value;
4215 arvif->u.sta.uapsd &= ~value;
4217 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4218 WMI_STA_PS_PARAM_UAPSD,
4219 arvif->u.sta.uapsd);
4221 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
4225 if (arvif->u.sta.uapsd)
4226 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4228 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4230 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4231 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4234 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
4236 ret = ath10k_mac_vif_recalc_ps_wake_threshold(arvif);
4238 ath10k_warn(ar, "failed to recalc ps wake threshold on vdev %i: %d\n",
4239 arvif->vdev_id, ret);
4243 ret = ath10k_mac_vif_recalc_ps_poll_count(arvif);
4245 ath10k_warn(ar, "failed to recalc ps poll count on vdev %i: %d\n",
4246 arvif->vdev_id, ret);
4250 if (test_bit(WMI_SERVICE_STA_UAPSD_BASIC_AUTO_TRIG, ar->wmi.svc_map) ||
4251 test_bit(WMI_SERVICE_STA_UAPSD_VAR_AUTO_TRIG, ar->wmi.svc_map)) {
4252 /* Only userspace can make an educated decision when to send
4253 * trigger frame. The following effectively disables u-UAPSD
4254 * autotrigger in firmware (which is enabled by default
4255 * provided the autotrigger service is available).
4259 arg.user_priority = prio;
4260 arg.service_interval = 0;
4261 arg.suspend_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4262 arg.delay_interval = WMI_STA_UAPSD_MAX_INTERVAL_MSEC;
4264 ret = ath10k_wmi_vdev_sta_uapsd(ar, arvif->vdev_id,
4265 arvif->bssid, &arg, 1);
4267 ath10k_warn(ar, "failed to set uapsd auto trigger %d\n",
4277 static int ath10k_conf_tx(struct ieee80211_hw *hw,
4278 struct ieee80211_vif *vif, u16 ac,
4279 const struct ieee80211_tx_queue_params *params)
4281 struct ath10k *ar = hw->priv;
4282 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4283 struct wmi_wmm_params_arg *p = NULL;
4286 mutex_lock(&ar->conf_mutex);
4289 case IEEE80211_AC_VO:
4290 p = &arvif->wmm_params.ac_vo;
4292 case IEEE80211_AC_VI:
4293 p = &arvif->wmm_params.ac_vi;
4295 case IEEE80211_AC_BE:
4296 p = &arvif->wmm_params.ac_be;
4298 case IEEE80211_AC_BK:
4299 p = &arvif->wmm_params.ac_bk;
4308 p->cwmin = params->cw_min;
4309 p->cwmax = params->cw_max;
4310 p->aifs = params->aifs;
4313 * The channel time duration programmed in the HW is in absolute
4314 * microseconds, while mac80211 gives the txop in units of
4317 p->txop = params->txop * 32;
4319 if (ar->wmi.ops->gen_vdev_wmm_conf) {
4320 ret = ath10k_wmi_vdev_wmm_conf(ar, arvif->vdev_id,
4321 &arvif->wmm_params);
4323 ath10k_warn(ar, "failed to set vdev wmm params on vdev %i: %d\n",
4324 arvif->vdev_id, ret);
4328 /* This won't work well with multi-interface cases but it's
4329 * better than nothing.
4331 ret = ath10k_wmi_pdev_set_wmm_params(ar, &arvif->wmm_params);
4333 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
4338 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4340 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
4343 mutex_unlock(&ar->conf_mutex);
4347 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
4349 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
4350 struct ieee80211_vif *vif,
4351 struct ieee80211_channel *chan,
4353 enum ieee80211_roc_type type)
4355 struct ath10k *ar = hw->priv;
4356 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4357 struct wmi_start_scan_arg arg;
4360 mutex_lock(&ar->conf_mutex);
4362 spin_lock_bh(&ar->data_lock);
4363 switch (ar->scan.state) {
4364 case ATH10K_SCAN_IDLE:
4365 reinit_completion(&ar->scan.started);
4366 reinit_completion(&ar->scan.completed);
4367 reinit_completion(&ar->scan.on_channel);
4368 ar->scan.state = ATH10K_SCAN_STARTING;
4369 ar->scan.is_roc = true;
4370 ar->scan.vdev_id = arvif->vdev_id;
4371 ar->scan.roc_freq = chan->center_freq;
4374 case ATH10K_SCAN_STARTING:
4375 case ATH10K_SCAN_RUNNING:
4376 case ATH10K_SCAN_ABORTING:
4380 spin_unlock_bh(&ar->data_lock);
4385 duration = max(duration, WMI_SCAN_CHAN_MIN_TIME_MSEC);
4387 memset(&arg, 0, sizeof(arg));
4388 ath10k_wmi_start_scan_init(ar, &arg);
4389 arg.vdev_id = arvif->vdev_id;
4390 arg.scan_id = ATH10K_SCAN_ID;
4392 arg.channels[0] = chan->center_freq;
4393 arg.dwell_time_active = duration;
4394 arg.dwell_time_passive = duration;
4395 arg.max_scan_time = 2 * duration;
4396 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
4397 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
4399 ret = ath10k_start_scan(ar, &arg);
4401 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
4402 spin_lock_bh(&ar->data_lock);
4403 ar->scan.state = ATH10K_SCAN_IDLE;
4404 spin_unlock_bh(&ar->data_lock);
4408 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
4410 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
4412 ret = ath10k_scan_stop(ar);
4414 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
4422 mutex_unlock(&ar->conf_mutex);
4426 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
4428 struct ath10k *ar = hw->priv;
4430 mutex_lock(&ar->conf_mutex);
4431 ath10k_scan_abort(ar);
4432 mutex_unlock(&ar->conf_mutex);
4434 cancel_delayed_work_sync(&ar->scan.timeout);
4440 * Both RTS and Fragmentation threshold are interface-specific
4441 * in ath10k, but device-specific in mac80211.
4444 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4446 struct ath10k *ar = hw->priv;
4447 struct ath10k_vif *arvif;
4450 mutex_lock(&ar->conf_mutex);
4451 list_for_each_entry(arvif, &ar->arvifs, list) {
4452 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
4453 arvif->vdev_id, value);
4455 ret = ath10k_mac_set_rts(arvif, value);
4457 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
4458 arvif->vdev_id, ret);
4462 mutex_unlock(&ar->conf_mutex);
4467 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4468 u32 queues, bool drop)
4470 struct ath10k *ar = hw->priv;
4474 /* mac80211 doesn't care if we really xmit queued frames or not
4475 * we'll collect those frames either way if we stop/delete vdevs */
4479 mutex_lock(&ar->conf_mutex);
4481 if (ar->state == ATH10K_STATE_WEDGED)
4484 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
4487 spin_lock_bh(&ar->htt.tx_lock);
4488 empty = (ar->htt.num_pending_tx == 0);
4489 spin_unlock_bh(&ar->htt.tx_lock);
4491 skip = (ar->state == ATH10K_STATE_WEDGED) ||
4492 test_bit(ATH10K_FLAG_CRASH_FLUSH,
4496 }), ATH10K_FLUSH_TIMEOUT_HZ);
4498 if (ret <= 0 || skip)
4499 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
4500 skip, ar->state, ret);
4503 mutex_unlock(&ar->conf_mutex);
4506 /* TODO: Implement this function properly
4507 * For now it is needed to reply to Probe Requests in IBSS mode.
4508 * Propably we need this information from FW.
4510 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
4516 static int ath10k_suspend(struct ieee80211_hw *hw,
4517 struct cfg80211_wowlan *wowlan)
4519 struct ath10k *ar = hw->priv;
4522 mutex_lock(&ar->conf_mutex);
4524 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
4526 if (ret == -ETIMEDOUT)
4532 ret = ath10k_hif_suspend(ar);
4534 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
4541 ret = ath10k_wmi_pdev_resume_target(ar);
4543 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4547 mutex_unlock(&ar->conf_mutex);
4551 static int ath10k_resume(struct ieee80211_hw *hw)
4553 struct ath10k *ar = hw->priv;
4556 mutex_lock(&ar->conf_mutex);
4558 ret = ath10k_hif_resume(ar);
4560 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
4565 ret = ath10k_wmi_pdev_resume_target(ar);
4567 ath10k_warn(ar, "failed to resume target: %d\n", ret);
4574 mutex_unlock(&ar->conf_mutex);
4579 static void ath10k_reconfig_complete(struct ieee80211_hw *hw,
4580 enum ieee80211_reconfig_type reconfig_type)
4582 struct ath10k *ar = hw->priv;
4584 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
4587 mutex_lock(&ar->conf_mutex);
4589 /* If device failed to restart it will be in a different state, e.g.
4590 * ATH10K_STATE_WEDGED */
4591 if (ar->state == ATH10K_STATE_RESTARTED) {
4592 ath10k_info(ar, "device successfully recovered\n");
4593 ar->state = ATH10K_STATE_ON;
4594 ieee80211_wake_queues(ar->hw);
4597 mutex_unlock(&ar->conf_mutex);
4600 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
4601 struct survey_info *survey)
4603 struct ath10k *ar = hw->priv;
4604 struct ieee80211_supported_band *sband;
4605 struct survey_info *ar_survey = &ar->survey[idx];
4608 mutex_lock(&ar->conf_mutex);
4610 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4611 if (sband && idx >= sband->n_channels) {
4612 idx -= sband->n_channels;
4617 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4619 if (!sband || idx >= sband->n_channels) {
4624 spin_lock_bh(&ar->data_lock);
4625 memcpy(survey, ar_survey, sizeof(*survey));
4626 spin_unlock_bh(&ar->data_lock);
4628 survey->channel = &sband->channels[idx];
4630 if (ar->rx_channel == survey->channel)
4631 survey->filled |= SURVEY_INFO_IN_USE;
4634 mutex_unlock(&ar->conf_mutex);
4638 /* Helper table for legacy fixed_rate/bitrate_mask */
4639 static const u8 cck_ofdm_rate[] = {
4656 /* Check if only one bit set */
4657 static int ath10k_check_single_mask(u32 mask)
4665 mask &= ~BIT(bit - 1);
4673 ath10k_default_bitrate_mask(struct ath10k *ar,
4674 enum ieee80211_band band,
4675 const struct cfg80211_bitrate_mask *mask)
4677 u32 legacy = 0x00ff;
4680 u16 nrf = ar->num_rf_chains;
4682 if (ar->cfg_tx_chainmask)
4683 nrf = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4686 case IEEE80211_BAND_2GHZ:
4690 case IEEE80211_BAND_5GHZ:
4696 if (mask->control[band].legacy != legacy)
4699 for (i = 0; i < nrf; i++)
4700 if (mask->control[band].ht_mcs[i] != ht)
4703 for (i = 0; i < nrf; i++)
4704 if (mask->control[band].vht_mcs[i] != vht)
4711 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4712 enum ieee80211_band band,
4715 int ht_nss = 0, vht_nss = 0, i;
4718 if (ath10k_check_single_mask(mask->control[band].legacy))
4722 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4723 if (mask->control[band].ht_mcs[i] == 0xff)
4725 else if (mask->control[band].ht_mcs[i] == 0x00)
4734 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4735 if (mask->control[band].vht_mcs[i] == 0x03ff)
4737 else if (mask->control[band].vht_mcs[i] == 0x0000)
4745 if (ht_nss > 0 && vht_nss > 0)
4749 *fixed_nss = ht_nss;
4751 *fixed_nss = vht_nss;
4759 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4760 enum ieee80211_band band,
4761 enum wmi_rate_preamble *preamble)
4763 int legacy = 0, ht = 0, vht = 0, i;
4765 *preamble = WMI_RATE_PREAMBLE_OFDM;
4768 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4773 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4774 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4779 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4780 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4784 /* Currently we support only one fixed_rate */
4785 if ((legacy + ht + vht) != 1)
4789 *preamble = WMI_RATE_PREAMBLE_HT;
4791 *preamble = WMI_RATE_PREAMBLE_VHT;
4797 ath10k_bitrate_mask_rate(struct ath10k *ar,
4798 const struct cfg80211_bitrate_mask *mask,
4799 enum ieee80211_band band,
4803 u8 rate = 0, pream = 0, nss = 0, i;
4804 enum wmi_rate_preamble preamble;
4806 /* Check if single rate correct */
4807 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4813 case WMI_RATE_PREAMBLE_CCK:
4814 case WMI_RATE_PREAMBLE_OFDM:
4815 i = ffs(mask->control[band].legacy) - 1;
4817 if (band == IEEE80211_BAND_2GHZ && i < 4)
4818 pream = WMI_RATE_PREAMBLE_CCK;
4820 if (band == IEEE80211_BAND_5GHZ)
4823 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4826 rate = cck_ofdm_rate[i];
4828 case WMI_RATE_PREAMBLE_HT:
4829 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4830 if (mask->control[band].ht_mcs[i])
4833 if (i == IEEE80211_HT_MCS_MASK_LEN)
4836 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4839 case WMI_RATE_PREAMBLE_VHT:
4840 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4841 if (mask->control[band].vht_mcs[i])
4844 if (i == NL80211_VHT_NSS_MAX)
4847 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4852 *fixed_nss = nss + 1;
4856 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4859 *fixed_rate = pream | nss | rate;
4864 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4865 const struct cfg80211_bitrate_mask *mask,
4866 enum ieee80211_band band,
4870 /* First check full NSS mask, if we can simply limit NSS */
4871 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4874 /* Next Check single rate is set */
4875 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4878 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4883 struct ath10k *ar = arvif->ar;
4887 mutex_lock(&ar->conf_mutex);
4889 if (arvif->fixed_rate == fixed_rate &&
4890 arvif->fixed_nss == fixed_nss &&
4891 arvif->force_sgi == force_sgi)
4894 if (fixed_rate == WMI_FIXED_RATE_NONE)
4895 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4898 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4900 vdev_param = ar->wmi.vdev_param->fixed_rate;
4901 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4902 vdev_param, fixed_rate);
4904 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4910 arvif->fixed_rate = fixed_rate;
4912 vdev_param = ar->wmi.vdev_param->nss;
4913 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4914 vdev_param, fixed_nss);
4917 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4923 arvif->fixed_nss = fixed_nss;
4925 vdev_param = ar->wmi.vdev_param->sgi;
4926 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4930 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4936 arvif->force_sgi = force_sgi;
4939 mutex_unlock(&ar->conf_mutex);
4943 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4944 struct ieee80211_vif *vif,
4945 const struct cfg80211_bitrate_mask *mask)
4947 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4948 struct ath10k *ar = arvif->ar;
4949 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4950 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4951 u8 fixed_nss = ar->num_rf_chains;
4954 if (ar->cfg_tx_chainmask)
4955 fixed_nss = get_nss_from_chainmask(ar->cfg_tx_chainmask);
4957 force_sgi = mask->control[band].gi;
4958 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4961 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4962 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4968 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4969 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4973 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4974 fixed_nss, force_sgi);
4977 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4978 struct ieee80211_vif *vif,
4979 struct ieee80211_sta *sta,
4982 struct ath10k *ar = hw->priv;
4983 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4986 spin_lock_bh(&ar->data_lock);
4988 ath10k_dbg(ar, ATH10K_DBG_MAC,
4989 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4990 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4993 if (changed & IEEE80211_RC_BW_CHANGED) {
4994 bw = WMI_PEER_CHWIDTH_20MHZ;
4996 switch (sta->bandwidth) {
4997 case IEEE80211_STA_RX_BW_20:
4998 bw = WMI_PEER_CHWIDTH_20MHZ;
5000 case IEEE80211_STA_RX_BW_40:
5001 bw = WMI_PEER_CHWIDTH_40MHZ;
5003 case IEEE80211_STA_RX_BW_80:
5004 bw = WMI_PEER_CHWIDTH_80MHZ;
5006 case IEEE80211_STA_RX_BW_160:
5007 ath10k_warn(ar, "Invalid bandwidth %d in rc update for %pM\n",
5008 sta->bandwidth, sta->addr);
5009 bw = WMI_PEER_CHWIDTH_20MHZ;
5016 if (changed & IEEE80211_RC_NSS_CHANGED)
5017 arsta->nss = sta->rx_nss;
5019 if (changed & IEEE80211_RC_SMPS_CHANGED) {
5020 smps = WMI_PEER_SMPS_PS_NONE;
5022 switch (sta->smps_mode) {
5023 case IEEE80211_SMPS_AUTOMATIC:
5024 case IEEE80211_SMPS_OFF:
5025 smps = WMI_PEER_SMPS_PS_NONE;
5027 case IEEE80211_SMPS_STATIC:
5028 smps = WMI_PEER_SMPS_STATIC;
5030 case IEEE80211_SMPS_DYNAMIC:
5031 smps = WMI_PEER_SMPS_DYNAMIC;
5033 case IEEE80211_SMPS_NUM_MODES:
5034 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
5035 sta->smps_mode, sta->addr);
5036 smps = WMI_PEER_SMPS_PS_NONE;
5043 arsta->changed |= changed;
5045 spin_unlock_bh(&ar->data_lock);
5047 ieee80211_queue_work(hw, &arsta->update_wk);
5050 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
5053 * FIXME: Return 0 for time being. Need to figure out whether FW
5054 * has the API to fetch 64-bit local TSF
5060 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
5061 struct ieee80211_vif *vif,
5062 enum ieee80211_ampdu_mlme_action action,
5063 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
5066 struct ath10k *ar = hw->priv;
5067 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5069 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
5070 arvif->vdev_id, sta->addr, tid, action);
5073 case IEEE80211_AMPDU_RX_START:
5074 case IEEE80211_AMPDU_RX_STOP:
5075 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
5076 * creation/removal. Do we need to verify this?
5079 case IEEE80211_AMPDU_TX_START:
5080 case IEEE80211_AMPDU_TX_STOP_CONT:
5081 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5082 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5083 case IEEE80211_AMPDU_TX_OPERATIONAL:
5084 /* Firmware offloads Tx aggregation entirely so deny mac80211
5085 * Tx aggregation requests.
5093 static const struct ieee80211_ops ath10k_ops = {
5095 .start = ath10k_start,
5096 .stop = ath10k_stop,
5097 .config = ath10k_config,
5098 .add_interface = ath10k_add_interface,
5099 .remove_interface = ath10k_remove_interface,
5100 .configure_filter = ath10k_configure_filter,
5101 .bss_info_changed = ath10k_bss_info_changed,
5102 .hw_scan = ath10k_hw_scan,
5103 .cancel_hw_scan = ath10k_cancel_hw_scan,
5104 .set_key = ath10k_set_key,
5105 .set_default_unicast_key = ath10k_set_default_unicast_key,
5106 .sta_state = ath10k_sta_state,
5107 .conf_tx = ath10k_conf_tx,
5108 .remain_on_channel = ath10k_remain_on_channel,
5109 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
5110 .set_rts_threshold = ath10k_set_rts_threshold,
5111 .flush = ath10k_flush,
5112 .tx_last_beacon = ath10k_tx_last_beacon,
5113 .set_antenna = ath10k_set_antenna,
5114 .get_antenna = ath10k_get_antenna,
5115 .reconfig_complete = ath10k_reconfig_complete,
5116 .get_survey = ath10k_get_survey,
5117 .set_bitrate_mask = ath10k_set_bitrate_mask,
5118 .sta_rc_update = ath10k_sta_rc_update,
5119 .get_tsf = ath10k_get_tsf,
5120 .ampdu_action = ath10k_ampdu_action,
5121 .get_et_sset_count = ath10k_debug_get_et_sset_count,
5122 .get_et_stats = ath10k_debug_get_et_stats,
5123 .get_et_strings = ath10k_debug_get_et_strings,
5125 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
5128 .suspend = ath10k_suspend,
5129 .resume = ath10k_resume,
5131 #ifdef CONFIG_MAC80211_DEBUGFS
5132 .sta_add_debugfs = ath10k_sta_add_debugfs,
5136 #define RATETAB_ENT(_rate, _rateid, _flags) { \
5137 .bitrate = (_rate), \
5138 .flags = (_flags), \
5139 .hw_value = (_rateid), \
5142 #define CHAN2G(_channel, _freq, _flags) { \
5143 .band = IEEE80211_BAND_2GHZ, \
5144 .hw_value = (_channel), \
5145 .center_freq = (_freq), \
5146 .flags = (_flags), \
5147 .max_antenna_gain = 0, \
5151 #define CHAN5G(_channel, _freq, _flags) { \
5152 .band = IEEE80211_BAND_5GHZ, \
5153 .hw_value = (_channel), \
5154 .center_freq = (_freq), \
5155 .flags = (_flags), \
5156 .max_antenna_gain = 0, \
5160 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
5170 CHAN2G(10, 2457, 0),
5171 CHAN2G(11, 2462, 0),
5172 CHAN2G(12, 2467, 0),
5173 CHAN2G(13, 2472, 0),
5174 CHAN2G(14, 2484, 0),
5177 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
5178 CHAN5G(36, 5180, 0),
5179 CHAN5G(40, 5200, 0),
5180 CHAN5G(44, 5220, 0),
5181 CHAN5G(48, 5240, 0),
5182 CHAN5G(52, 5260, 0),
5183 CHAN5G(56, 5280, 0),
5184 CHAN5G(60, 5300, 0),
5185 CHAN5G(64, 5320, 0),
5186 CHAN5G(100, 5500, 0),
5187 CHAN5G(104, 5520, 0),
5188 CHAN5G(108, 5540, 0),
5189 CHAN5G(112, 5560, 0),
5190 CHAN5G(116, 5580, 0),
5191 CHAN5G(120, 5600, 0),
5192 CHAN5G(124, 5620, 0),
5193 CHAN5G(128, 5640, 0),
5194 CHAN5G(132, 5660, 0),
5195 CHAN5G(136, 5680, 0),
5196 CHAN5G(140, 5700, 0),
5197 CHAN5G(149, 5745, 0),
5198 CHAN5G(153, 5765, 0),
5199 CHAN5G(157, 5785, 0),
5200 CHAN5G(161, 5805, 0),
5201 CHAN5G(165, 5825, 0),
5204 /* Note: Be careful if you re-order these. There is code which depends on this
5207 static struct ieee80211_rate ath10k_rates[] = {
5209 RATETAB_ENT(10, 0x82, 0),
5210 RATETAB_ENT(20, 0x84, 0),
5211 RATETAB_ENT(55, 0x8b, 0),
5212 RATETAB_ENT(110, 0x96, 0),
5214 RATETAB_ENT(60, 0x0c, 0),
5215 RATETAB_ENT(90, 0x12, 0),
5216 RATETAB_ENT(120, 0x18, 0),
5217 RATETAB_ENT(180, 0x24, 0),
5218 RATETAB_ENT(240, 0x30, 0),
5219 RATETAB_ENT(360, 0x48, 0),
5220 RATETAB_ENT(480, 0x60, 0),
5221 RATETAB_ENT(540, 0x6c, 0),
5224 #define ath10k_a_rates (ath10k_rates + 4)
5225 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
5226 #define ath10k_g_rates (ath10k_rates + 0)
5227 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
5229 struct ath10k *ath10k_mac_create(size_t priv_size)
5231 struct ieee80211_hw *hw;
5234 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
5244 void ath10k_mac_destroy(struct ath10k *ar)
5246 ieee80211_free_hw(ar->hw);
5249 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
5252 .types = BIT(NL80211_IFTYPE_STATION)
5253 | BIT(NL80211_IFTYPE_P2P_CLIENT)
5257 .types = BIT(NL80211_IFTYPE_P2P_GO)
5261 .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
5265 .types = BIT(NL80211_IFTYPE_AP)
5269 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
5272 .types = BIT(NL80211_IFTYPE_AP)
5276 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
5278 .limits = ath10k_if_limits,
5279 .n_limits = ARRAY_SIZE(ath10k_if_limits),
5280 .max_interfaces = 8,
5281 .num_different_channels = 1,
5282 .beacon_int_infra_match = true,
5286 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
5288 .limits = ath10k_10x_if_limits,
5289 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
5290 .max_interfaces = 8,
5291 .num_different_channels = 1,
5292 .beacon_int_infra_match = true,
5293 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
5294 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5295 BIT(NL80211_CHAN_WIDTH_20) |
5296 BIT(NL80211_CHAN_WIDTH_40) |
5297 BIT(NL80211_CHAN_WIDTH_80),
5302 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
5304 struct ieee80211_sta_vht_cap vht_cap = {0};
5308 vht_cap.vht_supported = 1;
5309 vht_cap.cap = ar->vht_cap_info;
5312 for (i = 0; i < 8; i++) {
5313 if (i < ar->num_rf_chains)
5314 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
5316 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
5319 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
5320 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
5325 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
5328 struct ieee80211_sta_ht_cap ht_cap = {0};
5330 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
5333 ht_cap.ht_supported = 1;
5334 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
5335 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
5336 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
5337 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
5338 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
5340 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
5341 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
5343 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
5344 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
5346 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
5349 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
5350 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
5355 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
5356 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
5358 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
5361 stbc = ar->ht_cap_info;
5362 stbc &= WMI_HT_CAP_RX_STBC;
5363 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
5364 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
5365 stbc &= IEEE80211_HT_CAP_RX_STBC;
5370 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
5371 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
5373 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
5374 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
5376 /* max AMSDU is implicitly taken from vht_cap_info */
5377 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
5378 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
5380 for (i = 0; i < ar->num_rf_chains; i++)
5381 ht_cap.mcs.rx_mask[i] = 0xFF;
5383 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
5388 static void ath10k_get_arvif_iter(void *data, u8 *mac,
5389 struct ieee80211_vif *vif)
5391 struct ath10k_vif_iter *arvif_iter = data;
5392 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
5394 if (arvif->vdev_id == arvif_iter->vdev_id)
5395 arvif_iter->arvif = arvif;
5398 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
5400 struct ath10k_vif_iter arvif_iter;
5403 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
5404 arvif_iter.vdev_id = vdev_id;
5406 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
5407 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5409 ath10k_get_arvif_iter,
5411 if (!arvif_iter.arvif) {
5412 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
5416 return arvif_iter.arvif;
5419 int ath10k_mac_register(struct ath10k *ar)
5421 static const u32 cipher_suites[] = {
5422 WLAN_CIPHER_SUITE_WEP40,
5423 WLAN_CIPHER_SUITE_WEP104,
5424 WLAN_CIPHER_SUITE_TKIP,
5425 WLAN_CIPHER_SUITE_CCMP,
5426 WLAN_CIPHER_SUITE_AES_CMAC,
5428 struct ieee80211_supported_band *band;
5429 struct ieee80211_sta_vht_cap vht_cap;
5430 struct ieee80211_sta_ht_cap ht_cap;
5434 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5436 SET_IEEE80211_DEV(ar->hw, ar->dev);
5438 ht_cap = ath10k_get_ht_cap(ar);
5439 vht_cap = ath10k_create_vht_cap(ar);
5441 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
5442 channels = kmemdup(ath10k_2ghz_channels,
5443 sizeof(ath10k_2ghz_channels),
5450 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
5451 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
5452 band->channels = channels;
5453 band->n_bitrates = ath10k_g_rates_size;
5454 band->bitrates = ath10k_g_rates;
5455 band->ht_cap = ht_cap;
5457 /* Enable the VHT support at 2.4 GHz */
5458 band->vht_cap = vht_cap;
5460 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
5463 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
5464 channels = kmemdup(ath10k_5ghz_channels,
5465 sizeof(ath10k_5ghz_channels),
5472 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
5473 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
5474 band->channels = channels;
5475 band->n_bitrates = ath10k_a_rates_size;
5476 band->bitrates = ath10k_a_rates;
5477 band->ht_cap = ht_cap;
5478 band->vht_cap = vht_cap;
5479 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
5482 ar->hw->wiphy->interface_modes =
5483 BIT(NL80211_IFTYPE_STATION) |
5484 BIT(NL80211_IFTYPE_AP);
5486 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
5487 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
5489 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
5490 ar->hw->wiphy->interface_modes |=
5491 BIT(NL80211_IFTYPE_P2P_DEVICE) |
5492 BIT(NL80211_IFTYPE_P2P_CLIENT) |
5493 BIT(NL80211_IFTYPE_P2P_GO);
5495 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5496 IEEE80211_HW_SUPPORTS_PS |
5497 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5498 IEEE80211_HW_MFP_CAPABLE |
5499 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5500 IEEE80211_HW_HAS_RATE_CONTROL |
5501 IEEE80211_HW_AP_LINK_PS |
5502 IEEE80211_HW_SPECTRUM_MGMT |
5503 IEEE80211_HW_SW_CRYPTO_CONTROL;
5505 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
5507 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5508 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
5510 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
5511 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
5512 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
5515 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
5516 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
5518 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
5519 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
5521 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
5523 if (test_bit(WMI_SERVICE_BEACON_OFFLOAD, ar->wmi.svc_map)) {
5524 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5526 /* Firmware delivers WPS/P2P Probe Requests frames to driver so
5527 * that userspace (e.g. wpa_supplicant/hostapd) can generate
5528 * correct Probe Responses. This is more of a hack advert..
5530 ar->hw->wiphy->probe_resp_offload |=
5531 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5532 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5533 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5536 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
5537 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5538 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
5540 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5541 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE;
5544 * on LL hardware queues are managed entirely by the FW
5545 * so we only advertise to mac we can do the queues thing
5549 switch (ar->wmi.op_version) {
5550 case ATH10K_FW_WMI_OP_VERSION_MAIN:
5551 case ATH10K_FW_WMI_OP_VERSION_TLV:
5552 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
5553 ar->hw->wiphy->n_iface_combinations =
5554 ARRAY_SIZE(ath10k_if_comb);
5555 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
5557 case ATH10K_FW_WMI_OP_VERSION_10_1:
5558 case ATH10K_FW_WMI_OP_VERSION_10_2:
5559 case ATH10K_FW_WMI_OP_VERSION_10_2_4:
5560 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
5561 ar->hw->wiphy->n_iface_combinations =
5562 ARRAY_SIZE(ath10k_10x_if_comb);
5564 case ATH10K_FW_WMI_OP_VERSION_UNSET:
5565 case ATH10K_FW_WMI_OP_VERSION_MAX:
5571 ar->hw->netdev_features = NETIF_F_HW_CSUM;
5573 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
5574 /* Init ath dfs pattern detector */
5575 ar->ath_common.debug_mask = ATH_DBG_DFS;
5576 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
5579 if (!ar->dfs_detector)
5580 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
5583 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
5584 ath10k_reg_notifier);
5586 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
5590 ar->hw->wiphy->cipher_suites = cipher_suites;
5591 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5593 ret = ieee80211_register_hw(ar->hw);
5595 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
5599 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
5600 ret = regulatory_hint(ar->hw->wiphy,
5601 ar->ath_common.regulatory.alpha2);
5603 goto err_unregister;
5609 ieee80211_unregister_hw(ar->hw);
5611 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5612 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5617 void ath10k_mac_unregister(struct ath10k *ar)
5619 ieee80211_unregister_hw(ar->hw);
5621 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
5622 ar->dfs_detector->exit(ar->dfs_detector);
5624 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
5625 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
5627 SET_IEEE80211_DEV(ar->hw, NULL);