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>
35 static int ath10k_send_key(struct ath10k_vif *arvif,
36 struct ieee80211_key_conf *key,
40 struct ath10k *ar = arvif->ar;
41 struct wmi_vdev_install_key_arg arg = {
42 .vdev_id = arvif->vdev_id,
43 .key_idx = key->keyidx,
44 .key_len = key->keylen,
49 lockdep_assert_held(&arvif->ar->conf_mutex);
51 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
52 arg.key_flags = WMI_KEY_PAIRWISE;
54 arg.key_flags = WMI_KEY_GROUP;
56 switch (key->cipher) {
57 case WLAN_CIPHER_SUITE_CCMP:
58 arg.key_cipher = WMI_CIPHER_AES_CCM;
59 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
60 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
62 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
64 case WLAN_CIPHER_SUITE_TKIP:
65 arg.key_cipher = WMI_CIPHER_TKIP;
66 arg.key_txmic_len = 8;
67 arg.key_rxmic_len = 8;
69 case WLAN_CIPHER_SUITE_WEP40:
70 case WLAN_CIPHER_SUITE_WEP104:
71 arg.key_cipher = WMI_CIPHER_WEP;
72 /* AP/IBSS mode requires self-key to be groupwise
73 * Otherwise pairwise key must be set */
74 if (memcmp(macaddr, arvif->vif->addr, ETH_ALEN))
75 arg.key_flags = WMI_KEY_PAIRWISE;
78 ath10k_warn(ar, "cipher %d is not supported\n", key->cipher);
82 if (cmd == DISABLE_KEY) {
83 arg.key_cipher = WMI_CIPHER_NONE;
87 return ath10k_wmi_vdev_install_key(arvif->ar, &arg);
90 static int ath10k_install_key(struct ath10k_vif *arvif,
91 struct ieee80211_key_conf *key,
95 struct ath10k *ar = arvif->ar;
98 lockdep_assert_held(&ar->conf_mutex);
100 reinit_completion(&ar->install_key_done);
102 ret = ath10k_send_key(arvif, key, cmd, macaddr);
106 ret = wait_for_completion_timeout(&ar->install_key_done, 3*HZ);
113 static int ath10k_install_peer_wep_keys(struct ath10k_vif *arvif,
116 struct ath10k *ar = arvif->ar;
117 struct ath10k_peer *peer;
121 lockdep_assert_held(&ar->conf_mutex);
123 spin_lock_bh(&ar->data_lock);
124 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
125 spin_unlock_bh(&ar->data_lock);
130 for (i = 0; i < ARRAY_SIZE(arvif->wep_keys); i++) {
131 if (arvif->wep_keys[i] == NULL)
134 ret = ath10k_install_key(arvif, arvif->wep_keys[i], SET_KEY,
139 peer->keys[i] = arvif->wep_keys[i];
145 static int ath10k_clear_peer_keys(struct ath10k_vif *arvif,
148 struct ath10k *ar = arvif->ar;
149 struct ath10k_peer *peer;
154 lockdep_assert_held(&ar->conf_mutex);
156 spin_lock_bh(&ar->data_lock);
157 peer = ath10k_peer_find(ar, arvif->vdev_id, addr);
158 spin_unlock_bh(&ar->data_lock);
163 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
164 if (peer->keys[i] == NULL)
167 ret = ath10k_install_key(arvif, peer->keys[i],
169 if (ret && first_errno == 0)
173 ath10k_warn(ar, "failed to remove peer wep key %d: %d\n",
176 peer->keys[i] = NULL;
182 static int ath10k_clear_vdev_key(struct ath10k_vif *arvif,
183 struct ieee80211_key_conf *key)
185 struct ath10k *ar = arvif->ar;
186 struct ath10k_peer *peer;
192 lockdep_assert_held(&ar->conf_mutex);
195 /* since ath10k_install_key we can't hold data_lock all the
196 * time, so we try to remove the keys incrementally */
197 spin_lock_bh(&ar->data_lock);
199 list_for_each_entry(peer, &ar->peers, list) {
200 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
201 if (peer->keys[i] == key) {
202 ether_addr_copy(addr, peer->addr);
203 peer->keys[i] = NULL;
208 if (i < ARRAY_SIZE(peer->keys))
211 spin_unlock_bh(&ar->data_lock);
213 if (i == ARRAY_SIZE(peer->keys))
216 ret = ath10k_install_key(arvif, key, DISABLE_KEY, addr);
217 if (ret && first_errno == 0)
221 ath10k_warn(ar, "failed to remove key for %pM: %d\n",
228 /*********************/
229 /* General utilities */
230 /*********************/
232 static inline enum wmi_phy_mode
233 chan_to_phymode(const struct cfg80211_chan_def *chandef)
235 enum wmi_phy_mode phymode = MODE_UNKNOWN;
237 switch (chandef->chan->band) {
238 case IEEE80211_BAND_2GHZ:
239 switch (chandef->width) {
240 case NL80211_CHAN_WIDTH_20_NOHT:
243 case NL80211_CHAN_WIDTH_20:
244 phymode = MODE_11NG_HT20;
246 case NL80211_CHAN_WIDTH_40:
247 phymode = MODE_11NG_HT40;
249 case NL80211_CHAN_WIDTH_5:
250 case NL80211_CHAN_WIDTH_10:
251 case NL80211_CHAN_WIDTH_80:
252 case NL80211_CHAN_WIDTH_80P80:
253 case NL80211_CHAN_WIDTH_160:
254 phymode = MODE_UNKNOWN;
258 case IEEE80211_BAND_5GHZ:
259 switch (chandef->width) {
260 case NL80211_CHAN_WIDTH_20_NOHT:
263 case NL80211_CHAN_WIDTH_20:
264 phymode = MODE_11NA_HT20;
266 case NL80211_CHAN_WIDTH_40:
267 phymode = MODE_11NA_HT40;
269 case NL80211_CHAN_WIDTH_80:
270 phymode = MODE_11AC_VHT80;
272 case NL80211_CHAN_WIDTH_5:
273 case NL80211_CHAN_WIDTH_10:
274 case NL80211_CHAN_WIDTH_80P80:
275 case NL80211_CHAN_WIDTH_160:
276 phymode = MODE_UNKNOWN;
284 WARN_ON(phymode == MODE_UNKNOWN);
288 static u8 ath10k_parse_mpdudensity(u8 mpdudensity)
291 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
292 * 0 for no restriction
301 switch (mpdudensity) {
307 /* Our lower layer calculations limit our precision to
323 static int ath10k_peer_create(struct ath10k *ar, u32 vdev_id, const u8 *addr)
327 lockdep_assert_held(&ar->conf_mutex);
329 ret = ath10k_wmi_peer_create(ar, vdev_id, addr);
331 ath10k_warn(ar, "failed to create wmi peer %pM on vdev %i: %i\n",
336 ret = ath10k_wait_for_peer_created(ar, vdev_id, addr);
338 ath10k_warn(ar, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
342 spin_lock_bh(&ar->data_lock);
344 spin_unlock_bh(&ar->data_lock);
349 static int ath10k_mac_set_kickout(struct ath10k_vif *arvif)
351 struct ath10k *ar = arvif->ar;
355 param = ar->wmi.pdev_param->sta_kickout_th;
356 ret = ath10k_wmi_pdev_set_param(ar, param,
357 ATH10K_KICKOUT_THRESHOLD);
359 ath10k_warn(ar, "failed to set kickout threshold on vdev %i: %d\n",
360 arvif->vdev_id, ret);
364 param = ar->wmi.vdev_param->ap_keepalive_min_idle_inactive_time_secs;
365 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
366 ATH10K_KEEPALIVE_MIN_IDLE);
368 ath10k_warn(ar, "failed to set keepalive minimum idle time on vdev %i: %d\n",
369 arvif->vdev_id, ret);
373 param = ar->wmi.vdev_param->ap_keepalive_max_idle_inactive_time_secs;
374 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
375 ATH10K_KEEPALIVE_MAX_IDLE);
377 ath10k_warn(ar, "failed to set keepalive maximum idle time on vdev %i: %d\n",
378 arvif->vdev_id, ret);
382 param = ar->wmi.vdev_param->ap_keepalive_max_unresponsive_time_secs;
383 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, param,
384 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE);
386 ath10k_warn(ar, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
387 arvif->vdev_id, ret);
394 static int ath10k_mac_set_rts(struct ath10k_vif *arvif, u32 value)
396 struct ath10k *ar = arvif->ar;
399 if (value != 0xFFFFFFFF)
400 value = min_t(u32, arvif->ar->hw->wiphy->rts_threshold,
403 vdev_param = ar->wmi.vdev_param->rts_threshold;
404 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
407 static int ath10k_mac_set_frag(struct ath10k_vif *arvif, u32 value)
409 struct ath10k *ar = arvif->ar;
412 if (value != 0xFFFFFFFF)
413 value = clamp_t(u32, arvif->ar->hw->wiphy->frag_threshold,
414 ATH10K_FRAGMT_THRESHOLD_MIN,
415 ATH10K_FRAGMT_THRESHOLD_MAX);
417 vdev_param = ar->wmi.vdev_param->fragmentation_threshold;
418 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param, value);
421 static int ath10k_peer_delete(struct ath10k *ar, u32 vdev_id, const u8 *addr)
425 lockdep_assert_held(&ar->conf_mutex);
427 ret = ath10k_wmi_peer_delete(ar, vdev_id, addr);
431 ret = ath10k_wait_for_peer_deleted(ar, vdev_id, addr);
435 spin_lock_bh(&ar->data_lock);
437 spin_unlock_bh(&ar->data_lock);
442 static void ath10k_peer_cleanup(struct ath10k *ar, u32 vdev_id)
444 struct ath10k_peer *peer, *tmp;
446 lockdep_assert_held(&ar->conf_mutex);
448 spin_lock_bh(&ar->data_lock);
449 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
450 if (peer->vdev_id != vdev_id)
453 ath10k_warn(ar, "removing stale peer %pM from vdev_id %d\n",
454 peer->addr, vdev_id);
456 list_del(&peer->list);
460 spin_unlock_bh(&ar->data_lock);
463 static void ath10k_peer_cleanup_all(struct ath10k *ar)
465 struct ath10k_peer *peer, *tmp;
467 lockdep_assert_held(&ar->conf_mutex);
469 spin_lock_bh(&ar->data_lock);
470 list_for_each_entry_safe(peer, tmp, &ar->peers, list) {
471 list_del(&peer->list);
475 spin_unlock_bh(&ar->data_lock);
478 /************************/
479 /* Interface management */
480 /************************/
482 void ath10k_mac_vif_beacon_free(struct ath10k_vif *arvif)
484 struct ath10k *ar = arvif->ar;
486 lockdep_assert_held(&ar->data_lock);
491 if (!arvif->beacon_buf)
492 dma_unmap_single(ar->dev, ATH10K_SKB_CB(arvif->beacon)->paddr,
493 arvif->beacon->len, DMA_TO_DEVICE);
495 dev_kfree_skb_any(arvif->beacon);
497 arvif->beacon = NULL;
498 arvif->beacon_sent = false;
501 static void ath10k_mac_vif_beacon_cleanup(struct ath10k_vif *arvif)
503 struct ath10k *ar = arvif->ar;
505 lockdep_assert_held(&ar->data_lock);
507 ath10k_mac_vif_beacon_free(arvif);
509 if (arvif->beacon_buf) {
510 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
511 arvif->beacon_buf, arvif->beacon_paddr);
512 arvif->beacon_buf = NULL;
516 static inline int ath10k_vdev_setup_sync(struct ath10k *ar)
520 lockdep_assert_held(&ar->conf_mutex);
522 ret = wait_for_completion_timeout(&ar->vdev_setup_done,
523 ATH10K_VDEV_SETUP_TIMEOUT_HZ);
530 static int ath10k_monitor_vdev_start(struct ath10k *ar, int vdev_id)
532 struct cfg80211_chan_def *chandef = &ar->chandef;
533 struct ieee80211_channel *channel = chandef->chan;
534 struct wmi_vdev_start_request_arg arg = {};
537 lockdep_assert_held(&ar->conf_mutex);
539 arg.vdev_id = vdev_id;
540 arg.channel.freq = channel->center_freq;
541 arg.channel.band_center_freq1 = chandef->center_freq1;
543 /* TODO setup this dynamically, what in case we
544 don't have any vifs? */
545 arg.channel.mode = chan_to_phymode(chandef);
546 arg.channel.chan_radar =
547 !!(channel->flags & IEEE80211_CHAN_RADAR);
549 arg.channel.min_power = 0;
550 arg.channel.max_power = channel->max_power * 2;
551 arg.channel.max_reg_power = channel->max_reg_power * 2;
552 arg.channel.max_antenna_gain = channel->max_antenna_gain * 2;
554 ret = ath10k_wmi_vdev_start(ar, &arg);
556 ath10k_warn(ar, "failed to request monitor vdev %i start: %d\n",
561 ret = ath10k_vdev_setup_sync(ar);
563 ath10k_warn(ar, "failed to synchronize setup for monitor vdev %i: %d\n",
568 ret = ath10k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
570 ath10k_warn(ar, "failed to put up monitor vdev %i: %d\n",
575 ar->monitor_vdev_id = vdev_id;
577 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i started\n",
578 ar->monitor_vdev_id);
582 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
584 ath10k_warn(ar, "failed to stop monitor vdev %i after start failure: %d\n",
585 ar->monitor_vdev_id, ret);
590 static int ath10k_monitor_vdev_stop(struct ath10k *ar)
594 lockdep_assert_held(&ar->conf_mutex);
596 ret = ath10k_wmi_vdev_down(ar, ar->monitor_vdev_id);
598 ath10k_warn(ar, "failed to put down monitor vdev %i: %d\n",
599 ar->monitor_vdev_id, ret);
601 ret = ath10k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
603 ath10k_warn(ar, "failed to to request monitor vdev %i stop: %d\n",
604 ar->monitor_vdev_id, ret);
606 ret = ath10k_vdev_setup_sync(ar);
608 ath10k_warn(ar, "failed to synchronise monitor vdev %i: %d\n",
609 ar->monitor_vdev_id, ret);
611 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %i stopped\n",
612 ar->monitor_vdev_id);
616 static int ath10k_monitor_vdev_create(struct ath10k *ar)
620 lockdep_assert_held(&ar->conf_mutex);
622 if (ar->free_vdev_map == 0) {
623 ath10k_warn(ar, "failed to find free vdev id for monitor vdev\n");
627 bit = __ffs64(ar->free_vdev_map);
629 ar->monitor_vdev_id = bit;
631 ret = ath10k_wmi_vdev_create(ar, ar->monitor_vdev_id,
632 WMI_VDEV_TYPE_MONITOR,
635 ath10k_warn(ar, "failed to request monitor vdev %i creation: %d\n",
636 ar->monitor_vdev_id, ret);
640 ar->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
641 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d created\n",
642 ar->monitor_vdev_id);
647 static int ath10k_monitor_vdev_delete(struct ath10k *ar)
651 lockdep_assert_held(&ar->conf_mutex);
653 ret = ath10k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
655 ath10k_warn(ar, "failed to request wmi monitor vdev %i removal: %d\n",
656 ar->monitor_vdev_id, ret);
660 ar->free_vdev_map |= 1LL << ar->monitor_vdev_id;
662 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor vdev %d deleted\n",
663 ar->monitor_vdev_id);
667 static int ath10k_monitor_start(struct ath10k *ar)
671 lockdep_assert_held(&ar->conf_mutex);
673 ret = ath10k_monitor_vdev_create(ar);
675 ath10k_warn(ar, "failed to create monitor vdev: %d\n", ret);
679 ret = ath10k_monitor_vdev_start(ar, ar->monitor_vdev_id);
681 ath10k_warn(ar, "failed to start monitor vdev: %d\n", ret);
682 ath10k_monitor_vdev_delete(ar);
686 ar->monitor_started = true;
687 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor started\n");
692 static int ath10k_monitor_stop(struct ath10k *ar)
696 lockdep_assert_held(&ar->conf_mutex);
698 ret = ath10k_monitor_vdev_stop(ar);
700 ath10k_warn(ar, "failed to stop monitor vdev: %d\n", ret);
704 ret = ath10k_monitor_vdev_delete(ar);
706 ath10k_warn(ar, "failed to delete monitor vdev: %d\n", ret);
710 ar->monitor_started = false;
711 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac monitor stopped\n");
716 static int ath10k_monitor_recalc(struct ath10k *ar)
720 lockdep_assert_held(&ar->conf_mutex);
722 should_start = ar->monitor ||
723 ar->filter_flags & FIF_PROMISC_IN_BSS ||
724 test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
726 ath10k_dbg(ar, ATH10K_DBG_MAC,
727 "mac monitor recalc started? %d should? %d\n",
728 ar->monitor_started, should_start);
730 if (should_start == ar->monitor_started)
734 return ath10k_monitor_start(ar);
736 return ath10k_monitor_stop(ar);
739 static int ath10k_recalc_rtscts_prot(struct ath10k_vif *arvif)
741 struct ath10k *ar = arvif->ar;
742 u32 vdev_param, rts_cts = 0;
744 lockdep_assert_held(&ar->conf_mutex);
746 vdev_param = ar->wmi.vdev_param->enable_rtscts;
748 if (arvif->use_cts_prot || arvif->num_legacy_stations > 0)
749 rts_cts |= SM(WMI_RTSCTS_ENABLED, WMI_RTSCTS_SET);
751 if (arvif->num_legacy_stations > 0)
752 rts_cts |= SM(WMI_RTSCTS_ACROSS_SW_RETRIES,
755 return ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
759 static int ath10k_start_cac(struct ath10k *ar)
763 lockdep_assert_held(&ar->conf_mutex);
765 set_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
767 ret = ath10k_monitor_recalc(ar);
769 ath10k_warn(ar, "failed to start monitor (cac): %d\n", ret);
770 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
774 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac start monitor vdev %d\n",
775 ar->monitor_vdev_id);
780 static int ath10k_stop_cac(struct ath10k *ar)
782 lockdep_assert_held(&ar->conf_mutex);
784 /* CAC is not running - do nothing */
785 if (!test_bit(ATH10K_CAC_RUNNING, &ar->dev_flags))
788 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
789 ath10k_monitor_stop(ar);
791 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac cac finished\n");
796 static void ath10k_recalc_radar_detection(struct ath10k *ar)
800 lockdep_assert_held(&ar->conf_mutex);
804 if (!ar->radar_enabled)
807 if (ar->num_started_vdevs > 0)
810 ret = ath10k_start_cac(ar);
813 * Not possible to start CAC on current channel so starting
814 * radiation is not allowed, make this channel DFS_UNAVAILABLE
815 * by indicating that radar was detected.
817 ath10k_warn(ar, "failed to start CAC: %d\n", ret);
818 ieee80211_radar_detected(ar->hw);
822 static int ath10k_vdev_start_restart(struct ath10k_vif *arvif, bool restart)
824 struct ath10k *ar = arvif->ar;
825 struct cfg80211_chan_def *chandef = &ar->chandef;
826 struct wmi_vdev_start_request_arg arg = {};
829 lockdep_assert_held(&ar->conf_mutex);
831 reinit_completion(&ar->vdev_setup_done);
833 arg.vdev_id = arvif->vdev_id;
834 arg.dtim_period = arvif->dtim_period;
835 arg.bcn_intval = arvif->beacon_interval;
837 arg.channel.freq = chandef->chan->center_freq;
838 arg.channel.band_center_freq1 = chandef->center_freq1;
839 arg.channel.mode = chan_to_phymode(chandef);
841 arg.channel.min_power = 0;
842 arg.channel.max_power = chandef->chan->max_power * 2;
843 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
844 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
846 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
847 arg.ssid = arvif->u.ap.ssid;
848 arg.ssid_len = arvif->u.ap.ssid_len;
849 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
851 /* For now allow DFS for AP mode */
852 arg.channel.chan_radar =
853 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
854 } else if (arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
855 arg.ssid = arvif->vif->bss_conf.ssid;
856 arg.ssid_len = arvif->vif->bss_conf.ssid_len;
859 ath10k_dbg(ar, ATH10K_DBG_MAC,
860 "mac vdev %d start center_freq %d phymode %s\n",
861 arg.vdev_id, arg.channel.freq,
862 ath10k_wmi_phymode_str(arg.channel.mode));
865 ret = ath10k_wmi_vdev_restart(ar, &arg);
867 ret = ath10k_wmi_vdev_start(ar, &arg);
870 ath10k_warn(ar, "failed to start WMI vdev %i: %d\n",
875 ret = ath10k_vdev_setup_sync(ar);
877 ath10k_warn(ar, "failed to synchronise setup for vdev %i: %d\n",
882 ar->num_started_vdevs++;
883 ath10k_recalc_radar_detection(ar);
888 static int ath10k_vdev_start(struct ath10k_vif *arvif)
890 return ath10k_vdev_start_restart(arvif, false);
893 static int ath10k_vdev_restart(struct ath10k_vif *arvif)
895 return ath10k_vdev_start_restart(arvif, true);
898 static int ath10k_vdev_stop(struct ath10k_vif *arvif)
900 struct ath10k *ar = arvif->ar;
903 lockdep_assert_held(&ar->conf_mutex);
905 reinit_completion(&ar->vdev_setup_done);
907 ret = ath10k_wmi_vdev_stop(ar, arvif->vdev_id);
909 ath10k_warn(ar, "failed to stop WMI vdev %i: %d\n",
910 arvif->vdev_id, ret);
914 ret = ath10k_vdev_setup_sync(ar);
916 ath10k_warn(ar, "failed to syncronise setup for vdev %i: %d\n",
917 arvif->vdev_id, ret);
921 WARN_ON(ar->num_started_vdevs == 0);
923 if (ar->num_started_vdevs != 0) {
924 ar->num_started_vdevs--;
925 ath10k_recalc_radar_detection(ar);
931 static void ath10k_control_beaconing(struct ath10k_vif *arvif,
932 struct ieee80211_bss_conf *info)
934 struct ath10k *ar = arvif->ar;
937 lockdep_assert_held(&arvif->ar->conf_mutex);
939 if (!info->enable_beacon) {
940 ath10k_vdev_stop(arvif);
942 arvif->is_started = false;
943 arvif->is_up = false;
945 spin_lock_bh(&arvif->ar->data_lock);
946 ath10k_mac_vif_beacon_free(arvif);
947 spin_unlock_bh(&arvif->ar->data_lock);
952 arvif->tx_seq_no = 0x1000;
954 ret = ath10k_vdev_start(arvif);
959 ether_addr_copy(arvif->bssid, info->bssid);
961 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
964 ath10k_warn(ar, "failed to bring up vdev %d: %i\n",
965 arvif->vdev_id, ret);
966 ath10k_vdev_stop(arvif);
970 arvif->is_started = true;
973 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
976 static void ath10k_control_ibss(struct ath10k_vif *arvif,
977 struct ieee80211_bss_conf *info,
978 const u8 self_peer[ETH_ALEN])
980 struct ath10k *ar = arvif->ar;
984 lockdep_assert_held(&arvif->ar->conf_mutex);
986 if (!info->ibss_joined) {
987 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, self_peer);
989 ath10k_warn(ar, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
990 self_peer, arvif->vdev_id, ret);
992 if (is_zero_ether_addr(arvif->bssid))
995 memset(arvif->bssid, 0, ETH_ALEN);
1000 ret = ath10k_peer_create(arvif->ar, arvif->vdev_id, self_peer);
1002 ath10k_warn(ar, "failed to create IBSS self peer %pM for vdev %d: %d\n",
1003 self_peer, arvif->vdev_id, ret);
1007 vdev_param = arvif->ar->wmi.vdev_param->atim_window;
1008 ret = ath10k_wmi_vdev_set_param(arvif->ar, arvif->vdev_id, vdev_param,
1009 ATH10K_DEFAULT_ATIM);
1011 ath10k_warn(ar, "failed to set IBSS ATIM for vdev %d: %d\n",
1012 arvif->vdev_id, ret);
1016 * Review this when mac80211 gains per-interface powersave support.
1018 static int ath10k_mac_vif_setup_ps(struct ath10k_vif *arvif)
1020 struct ath10k *ar = arvif->ar;
1021 struct ieee80211_conf *conf = &ar->hw->conf;
1022 enum wmi_sta_powersave_param param;
1023 enum wmi_sta_ps_mode psmode;
1026 lockdep_assert_held(&arvif->ar->conf_mutex);
1028 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1031 if (conf->flags & IEEE80211_CONF_PS) {
1032 psmode = WMI_STA_PS_MODE_ENABLED;
1033 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1035 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1036 conf->dynamic_ps_timeout);
1038 ath10k_warn(ar, "failed to set inactivity time for vdev %d: %i\n",
1039 arvif->vdev_id, ret);
1043 psmode = WMI_STA_PS_MODE_DISABLED;
1046 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d psmode %s\n",
1047 arvif->vdev_id, psmode ? "enable" : "disable");
1049 ret = ath10k_wmi_set_psmode(ar, arvif->vdev_id, psmode);
1051 ath10k_warn(ar, "failed to set PS Mode %d for vdev %d: %d\n",
1052 psmode, arvif->vdev_id, ret);
1059 /**********************/
1060 /* Station management */
1061 /**********************/
1063 static u32 ath10k_peer_assoc_h_listen_intval(struct ath10k *ar,
1064 struct ieee80211_vif *vif)
1066 /* Some firmware revisions have unstable STA powersave when listen
1067 * interval is set too high (e.g. 5). The symptoms are firmware doesn't
1068 * generate NullFunc frames properly even if buffered frames have been
1069 * indicated in Beacon TIM. Firmware would seldom wake up to pull
1070 * buffered frames. Often pinging the device from AP would simply fail.
1072 * As a workaround set it to 1.
1074 if (vif->type == NL80211_IFTYPE_STATION)
1077 return ar->hw->conf.listen_interval;
1080 static void ath10k_peer_assoc_h_basic(struct ath10k *ar,
1081 struct ieee80211_vif *vif,
1082 struct ieee80211_sta *sta,
1083 struct wmi_peer_assoc_complete_arg *arg)
1085 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1087 lockdep_assert_held(&ar->conf_mutex);
1089 ether_addr_copy(arg->addr, sta->addr);
1090 arg->vdev_id = arvif->vdev_id;
1091 arg->peer_aid = sta->aid;
1092 arg->peer_flags |= WMI_PEER_AUTH;
1093 arg->peer_listen_intval = ath10k_peer_assoc_h_listen_intval(ar, vif);
1094 arg->peer_num_spatial_streams = 1;
1095 arg->peer_caps = vif->bss_conf.assoc_capability;
1098 static void ath10k_peer_assoc_h_crypto(struct ath10k *ar,
1099 struct ieee80211_vif *vif,
1100 struct wmi_peer_assoc_complete_arg *arg)
1102 struct ieee80211_bss_conf *info = &vif->bss_conf;
1103 struct cfg80211_bss *bss;
1104 const u8 *rsnie = NULL;
1105 const u8 *wpaie = NULL;
1107 lockdep_assert_held(&ar->conf_mutex);
1109 bss = cfg80211_get_bss(ar->hw->wiphy, ar->hw->conf.chandef.chan,
1110 info->bssid, NULL, 0, 0, 0);
1112 const struct cfg80211_bss_ies *ies;
1115 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1117 ies = rcu_dereference(bss->ies);
1119 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1120 WLAN_OUI_TYPE_MICROSOFT_WPA,
1124 cfg80211_put_bss(ar->hw->wiphy, bss);
1127 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1128 if (rsnie || wpaie) {
1129 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: rsn ie found\n", __func__);
1130 arg->peer_flags |= WMI_PEER_NEED_PTK_4_WAY;
1134 ath10k_dbg(ar, ATH10K_DBG_WMI, "%s: wpa ie found\n", __func__);
1135 arg->peer_flags |= WMI_PEER_NEED_GTK_2_WAY;
1139 static void ath10k_peer_assoc_h_rates(struct ath10k *ar,
1140 struct ieee80211_sta *sta,
1141 struct wmi_peer_assoc_complete_arg *arg)
1143 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1144 const struct ieee80211_supported_band *sband;
1145 const struct ieee80211_rate *rates;
1149 lockdep_assert_held(&ar->conf_mutex);
1151 sband = ar->hw->wiphy->bands[ar->hw->conf.chandef.chan->band];
1152 ratemask = sta->supp_rates[ar->hw->conf.chandef.chan->band];
1153 rates = sband->bitrates;
1155 rateset->num_rates = 0;
1157 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1158 if (!(ratemask & 1))
1161 rateset->rates[rateset->num_rates] = rates->hw_value;
1162 rateset->num_rates++;
1166 static void ath10k_peer_assoc_h_ht(struct ath10k *ar,
1167 struct ieee80211_sta *sta,
1168 struct wmi_peer_assoc_complete_arg *arg)
1170 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1174 lockdep_assert_held(&ar->conf_mutex);
1176 if (!ht_cap->ht_supported)
1179 arg->peer_flags |= WMI_PEER_HT;
1180 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1181 ht_cap->ampdu_factor)) - 1;
1183 arg->peer_mpdu_density =
1184 ath10k_parse_mpdudensity(ht_cap->ampdu_density);
1186 arg->peer_ht_caps = ht_cap->cap;
1187 arg->peer_rate_caps |= WMI_RC_HT_FLAG;
1189 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1190 arg->peer_flags |= WMI_PEER_LDPC;
1192 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1193 arg->peer_flags |= WMI_PEER_40MHZ;
1194 arg->peer_rate_caps |= WMI_RC_CW40_FLAG;
1197 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_20)
1198 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1200 if (ht_cap->cap & IEEE80211_HT_CAP_SGI_40)
1201 arg->peer_rate_caps |= WMI_RC_SGI_FLAG;
1203 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1204 arg->peer_rate_caps |= WMI_RC_TX_STBC_FLAG;
1205 arg->peer_flags |= WMI_PEER_STBC;
1208 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1209 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1210 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1211 stbc = stbc << WMI_RC_RX_STBC_FLAG_S;
1212 arg->peer_rate_caps |= stbc;
1213 arg->peer_flags |= WMI_PEER_STBC;
1216 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1217 arg->peer_rate_caps |= WMI_RC_TS_FLAG;
1218 else if (ht_cap->mcs.rx_mask[1])
1219 arg->peer_rate_caps |= WMI_RC_DS_FLAG;
1221 for (i = 0, n = 0; i < IEEE80211_HT_MCS_MASK_LEN*8; i++)
1222 if (ht_cap->mcs.rx_mask[i/8] & (1 << i%8))
1223 arg->peer_ht_rates.rates[n++] = i;
1226 * This is a workaround for HT-enabled STAs which break the spec
1227 * and have no HT capabilities RX mask (no HT RX MCS map).
1229 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1230 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1232 * Firmware asserts if such situation occurs.
1235 arg->peer_ht_rates.num_rates = 8;
1236 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1237 arg->peer_ht_rates.rates[i] = i;
1239 arg->peer_ht_rates.num_rates = n;
1240 arg->peer_num_spatial_streams = sta->rx_nss;
1243 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1245 arg->peer_ht_rates.num_rates,
1246 arg->peer_num_spatial_streams);
1249 static int ath10k_peer_assoc_qos_ap(struct ath10k *ar,
1250 struct ath10k_vif *arvif,
1251 struct ieee80211_sta *sta)
1257 lockdep_assert_held(&ar->conf_mutex);
1259 if (sta->wme && sta->uapsd_queues) {
1260 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1261 sta->uapsd_queues, sta->max_sp);
1263 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1264 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1265 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1266 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1267 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1268 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1269 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1270 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1271 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1272 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1273 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1274 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1276 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1277 max_sp = sta->max_sp;
1279 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1281 WMI_AP_PS_PEER_PARAM_UAPSD,
1284 ath10k_warn(ar, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1285 arvif->vdev_id, ret);
1289 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id,
1291 WMI_AP_PS_PEER_PARAM_MAX_SP,
1294 ath10k_warn(ar, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1295 arvif->vdev_id, ret);
1299 /* TODO setup this based on STA listen interval and
1300 beacon interval. Currently we don't know
1301 sta->listen_interval - mac80211 patch required.
1302 Currently use 10 seconds */
1303 ret = ath10k_wmi_set_ap_ps_param(ar, arvif->vdev_id, sta->addr,
1304 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME,
1307 ath10k_warn(ar, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1308 arvif->vdev_id, ret);
1316 static void ath10k_peer_assoc_h_vht(struct ath10k *ar,
1317 struct ieee80211_sta *sta,
1318 struct wmi_peer_assoc_complete_arg *arg)
1320 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1323 if (!vht_cap->vht_supported)
1326 arg->peer_flags |= WMI_PEER_VHT;
1327 arg->peer_vht_caps = vht_cap->cap;
1329 ampdu_factor = (vht_cap->cap &
1330 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1331 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1333 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1334 * zero in VHT IE. Using it would result in degraded throughput.
1335 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1336 * it if VHT max_mpdu is smaller. */
1337 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1338 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1339 ampdu_factor)) - 1);
1341 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1342 arg->peer_flags |= WMI_PEER_80MHZ;
1344 arg->peer_vht_rates.rx_max_rate =
1345 __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1346 arg->peer_vht_rates.rx_mcs_set =
1347 __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1348 arg->peer_vht_rates.tx_max_rate =
1349 __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1350 arg->peer_vht_rates.tx_mcs_set =
1351 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map);
1353 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1354 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1357 static void ath10k_peer_assoc_h_qos(struct ath10k *ar,
1358 struct ieee80211_vif *vif,
1359 struct ieee80211_sta *sta,
1360 struct wmi_peer_assoc_complete_arg *arg)
1362 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1364 switch (arvif->vdev_type) {
1365 case WMI_VDEV_TYPE_AP:
1367 arg->peer_flags |= WMI_PEER_QOS;
1369 if (sta->wme && sta->uapsd_queues) {
1370 arg->peer_flags |= WMI_PEER_APSD;
1371 arg->peer_rate_caps |= WMI_RC_UAPSD_FLAG;
1374 case WMI_VDEV_TYPE_STA:
1375 if (vif->bss_conf.qos)
1376 arg->peer_flags |= WMI_PEER_QOS;
1383 static void ath10k_peer_assoc_h_phymode(struct ath10k *ar,
1384 struct ieee80211_vif *vif,
1385 struct ieee80211_sta *sta,
1386 struct wmi_peer_assoc_complete_arg *arg)
1388 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1390 switch (ar->hw->conf.chandef.chan->band) {
1391 case IEEE80211_BAND_2GHZ:
1392 if (sta->ht_cap.ht_supported) {
1393 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1394 phymode = MODE_11NG_HT40;
1396 phymode = MODE_11NG_HT20;
1402 case IEEE80211_BAND_5GHZ:
1406 if (sta->vht_cap.vht_supported) {
1407 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1408 phymode = MODE_11AC_VHT80;
1409 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1410 phymode = MODE_11AC_VHT40;
1411 else if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1412 phymode = MODE_11AC_VHT20;
1413 } else if (sta->ht_cap.ht_supported) {
1414 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1415 phymode = MODE_11NA_HT40;
1417 phymode = MODE_11NA_HT20;
1427 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac peer %pM phymode %s\n",
1428 sta->addr, ath10k_wmi_phymode_str(phymode));
1430 arg->peer_phymode = phymode;
1431 WARN_ON(phymode == MODE_UNKNOWN);
1434 static int ath10k_peer_assoc_prepare(struct ath10k *ar,
1435 struct ieee80211_vif *vif,
1436 struct ieee80211_sta *sta,
1437 struct wmi_peer_assoc_complete_arg *arg)
1439 lockdep_assert_held(&ar->conf_mutex);
1441 memset(arg, 0, sizeof(*arg));
1443 ath10k_peer_assoc_h_basic(ar, vif, sta, arg);
1444 ath10k_peer_assoc_h_crypto(ar, vif, arg);
1445 ath10k_peer_assoc_h_rates(ar, sta, arg);
1446 ath10k_peer_assoc_h_ht(ar, sta, arg);
1447 ath10k_peer_assoc_h_vht(ar, sta, arg);
1448 ath10k_peer_assoc_h_qos(ar, vif, sta, arg);
1449 ath10k_peer_assoc_h_phymode(ar, vif, sta, arg);
1454 static const u32 ath10k_smps_map[] = {
1455 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
1456 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
1457 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
1458 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
1461 static int ath10k_setup_peer_smps(struct ath10k *ar, struct ath10k_vif *arvif,
1463 const struct ieee80211_sta_ht_cap *ht_cap)
1467 if (!ht_cap->ht_supported)
1470 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1471 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1473 if (smps >= ARRAY_SIZE(ath10k_smps_map))
1476 return ath10k_wmi_peer_set_param(ar, arvif->vdev_id, addr,
1477 WMI_PEER_SMPS_STATE,
1478 ath10k_smps_map[smps]);
1481 /* can be called only in mac80211 callbacks due to `key_count` usage */
1482 static void ath10k_bss_assoc(struct ieee80211_hw *hw,
1483 struct ieee80211_vif *vif,
1484 struct ieee80211_bss_conf *bss_conf)
1486 struct ath10k *ar = hw->priv;
1487 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1488 struct ieee80211_sta_ht_cap ht_cap;
1489 struct wmi_peer_assoc_complete_arg peer_arg;
1490 struct ieee80211_sta *ap_sta;
1493 lockdep_assert_held(&ar->conf_mutex);
1497 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1499 ath10k_warn(ar, "failed to find station entry for bss %pM vdev %i\n",
1500 bss_conf->bssid, arvif->vdev_id);
1505 /* ap_sta must be accessed only within rcu section which must be left
1506 * before calling ath10k_setup_peer_smps() which might sleep. */
1507 ht_cap = ap_sta->ht_cap;
1509 ret = ath10k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg);
1511 ath10k_warn(ar, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1512 bss_conf->bssid, arvif->vdev_id, ret);
1519 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1521 ath10k_warn(ar, "failed to run peer assoc for %pM vdev %i: %d\n",
1522 bss_conf->bssid, arvif->vdev_id, ret);
1526 ret = ath10k_setup_peer_smps(ar, arvif, bss_conf->bssid, &ht_cap);
1528 ath10k_warn(ar, "failed to setup peer SMPS for vdev %i: %d\n",
1529 arvif->vdev_id, ret);
1533 ath10k_dbg(ar, ATH10K_DBG_MAC,
1534 "mac vdev %d up (associated) bssid %pM aid %d\n",
1535 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1537 arvif->aid = bss_conf->aid;
1538 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1540 ret = ath10k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1542 ath10k_warn(ar, "failed to set vdev %d up: %d\n",
1543 arvif->vdev_id, ret);
1547 arvif->is_up = true;
1553 static void ath10k_bss_disassoc(struct ieee80211_hw *hw,
1554 struct ieee80211_vif *vif)
1556 struct ath10k *ar = hw->priv;
1557 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1560 lockdep_assert_held(&ar->conf_mutex);
1563 * For some reason, calling VDEV-DOWN before VDEV-STOP
1564 * makes the FW to send frames via HTT after disassociation.
1565 * No idea why this happens, even though VDEV-DOWN is supposed
1566 * to be analogous to link down, so just stop the VDEV.
1568 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d stop (disassociated\n",
1571 /* FIXME: check return value */
1572 ret = ath10k_vdev_stop(arvif);
1575 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1576 * report beacons from previously associated network through HTT.
1577 * This in turn would spam mac80211 WARN_ON if we bring down all
1578 * interfaces as it expects there is no rx when no interface is
1581 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d down\n", arvif->vdev_id);
1583 /* FIXME: why don't we print error if wmi call fails? */
1584 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
1586 arvif->def_wep_key_idx = 0;
1588 arvif->is_started = false;
1589 arvif->is_up = false;
1592 static int ath10k_station_assoc(struct ath10k *ar,
1593 struct ieee80211_vif *vif,
1594 struct ieee80211_sta *sta,
1597 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1598 struct wmi_peer_assoc_complete_arg peer_arg;
1601 lockdep_assert_held(&ar->conf_mutex);
1603 ret = ath10k_peer_assoc_prepare(ar, vif, sta, &peer_arg);
1605 ath10k_warn(ar, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1606 sta->addr, arvif->vdev_id, ret);
1610 peer_arg.peer_reassoc = reassoc;
1611 ret = ath10k_wmi_peer_assoc(ar, &peer_arg);
1613 ath10k_warn(ar, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1614 sta->addr, arvif->vdev_id, ret);
1618 /* Re-assoc is run only to update supported rates for given station. It
1619 * doesn't make much sense to reconfigure the peer completely.
1622 ret = ath10k_setup_peer_smps(ar, arvif, sta->addr,
1625 ath10k_warn(ar, "failed to setup peer SMPS for vdev %d: %d\n",
1626 arvif->vdev_id, ret);
1630 ret = ath10k_peer_assoc_qos_ap(ar, arvif, sta);
1632 ath10k_warn(ar, "failed to set qos params for STA %pM for vdev %i: %d\n",
1633 sta->addr, arvif->vdev_id, ret);
1638 arvif->num_legacy_stations++;
1639 ret = ath10k_recalc_rtscts_prot(arvif);
1641 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1642 arvif->vdev_id, ret);
1647 ret = ath10k_install_peer_wep_keys(arvif, sta->addr);
1649 ath10k_warn(ar, "failed to install peer wep keys for vdev %i: %d\n",
1650 arvif->vdev_id, ret);
1658 static int ath10k_station_disassoc(struct ath10k *ar,
1659 struct ieee80211_vif *vif,
1660 struct ieee80211_sta *sta)
1662 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1665 lockdep_assert_held(&ar->conf_mutex);
1668 arvif->num_legacy_stations--;
1669 ret = ath10k_recalc_rtscts_prot(arvif);
1671 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1672 arvif->vdev_id, ret);
1677 ret = ath10k_clear_peer_keys(arvif, sta->addr);
1679 ath10k_warn(ar, "failed to clear all peer wep keys for vdev %i: %d\n",
1680 arvif->vdev_id, ret);
1691 static int ath10k_update_channel_list(struct ath10k *ar)
1693 struct ieee80211_hw *hw = ar->hw;
1694 struct ieee80211_supported_band **bands;
1695 enum ieee80211_band band;
1696 struct ieee80211_channel *channel;
1697 struct wmi_scan_chan_list_arg arg = {0};
1698 struct wmi_channel_arg *ch;
1704 lockdep_assert_held(&ar->conf_mutex);
1706 bands = hw->wiphy->bands;
1707 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1711 for (i = 0; i < bands[band]->n_channels; i++) {
1712 if (bands[band]->channels[i].flags &
1713 IEEE80211_CHAN_DISABLED)
1720 len = sizeof(struct wmi_channel_arg) * arg.n_channels;
1721 arg.channels = kzalloc(len, GFP_KERNEL);
1726 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1730 for (i = 0; i < bands[band]->n_channels; i++) {
1731 channel = &bands[band]->channels[i];
1733 if (channel->flags & IEEE80211_CHAN_DISABLED)
1736 ch->allow_ht = true;
1738 /* FIXME: when should we really allow VHT? */
1739 ch->allow_vht = true;
1742 !(channel->flags & IEEE80211_CHAN_NO_IR);
1745 !(channel->flags & IEEE80211_CHAN_NO_HT40PLUS);
1748 !!(channel->flags & IEEE80211_CHAN_RADAR);
1750 passive = channel->flags & IEEE80211_CHAN_NO_IR;
1751 ch->passive = passive;
1753 ch->freq = channel->center_freq;
1754 ch->band_center_freq1 = channel->center_freq;
1756 ch->max_power = channel->max_power * 2;
1757 ch->max_reg_power = channel->max_reg_power * 2;
1758 ch->max_antenna_gain = channel->max_antenna_gain * 2;
1759 ch->reg_class_id = 0; /* FIXME */
1761 /* FIXME: why use only legacy modes, why not any
1762 * HT/VHT modes? Would that even make any
1764 if (channel->band == IEEE80211_BAND_2GHZ)
1765 ch->mode = MODE_11G;
1767 ch->mode = MODE_11A;
1769 if (WARN_ON_ONCE(ch->mode == MODE_UNKNOWN))
1772 ath10k_dbg(ar, ATH10K_DBG_WMI,
1773 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1774 ch - arg.channels, arg.n_channels,
1775 ch->freq, ch->max_power, ch->max_reg_power,
1776 ch->max_antenna_gain, ch->mode);
1782 ret = ath10k_wmi_scan_chan_list(ar, &arg);
1783 kfree(arg.channels);
1788 static enum wmi_dfs_region
1789 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region)
1791 switch (dfs_region) {
1792 case NL80211_DFS_UNSET:
1793 return WMI_UNINIT_DFS_DOMAIN;
1794 case NL80211_DFS_FCC:
1795 return WMI_FCC_DFS_DOMAIN;
1796 case NL80211_DFS_ETSI:
1797 return WMI_ETSI_DFS_DOMAIN;
1798 case NL80211_DFS_JP:
1799 return WMI_MKK4_DFS_DOMAIN;
1801 return WMI_UNINIT_DFS_DOMAIN;
1804 static void ath10k_regd_update(struct ath10k *ar)
1806 struct reg_dmn_pair_mapping *regpair;
1808 enum wmi_dfs_region wmi_dfs_reg;
1809 enum nl80211_dfs_regions nl_dfs_reg;
1811 lockdep_assert_held(&ar->conf_mutex);
1813 ret = ath10k_update_channel_list(ar);
1815 ath10k_warn(ar, "failed to update channel list: %d\n", ret);
1817 regpair = ar->ath_common.regulatory.regpair;
1819 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1820 nl_dfs_reg = ar->dfs_detector->region;
1821 wmi_dfs_reg = ath10k_mac_get_dfs_region(nl_dfs_reg);
1823 wmi_dfs_reg = WMI_UNINIT_DFS_DOMAIN;
1826 /* Target allows setting up per-band regdomain but ath_common provides
1827 * a combined one only */
1828 ret = ath10k_wmi_pdev_set_regdomain(ar,
1829 regpair->reg_domain,
1830 regpair->reg_domain, /* 2ghz */
1831 regpair->reg_domain, /* 5ghz */
1832 regpair->reg_2ghz_ctl,
1833 regpair->reg_5ghz_ctl,
1836 ath10k_warn(ar, "failed to set pdev regdomain: %d\n", ret);
1839 static void ath10k_reg_notifier(struct wiphy *wiphy,
1840 struct regulatory_request *request)
1842 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1843 struct ath10k *ar = hw->priv;
1846 ath_reg_notifier_apply(wiphy, request, &ar->ath_common.regulatory);
1848 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector) {
1849 ath10k_dbg(ar, ATH10K_DBG_REGULATORY, "dfs region 0x%x\n",
1850 request->dfs_region);
1851 result = ar->dfs_detector->set_dfs_domain(ar->dfs_detector,
1852 request->dfs_region);
1854 ath10k_warn(ar, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1855 request->dfs_region);
1858 mutex_lock(&ar->conf_mutex);
1859 if (ar->state == ATH10K_STATE_ON)
1860 ath10k_regd_update(ar);
1861 mutex_unlock(&ar->conf_mutex);
1868 static u8 ath10k_tx_h_get_tid(struct ieee80211_hdr *hdr)
1870 if (ieee80211_is_mgmt(hdr->frame_control))
1871 return HTT_DATA_TX_EXT_TID_MGMT;
1873 if (!ieee80211_is_data_qos(hdr->frame_control))
1874 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1876 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr)))
1877 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1879 return ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
1882 static u8 ath10k_tx_h_get_vdev_id(struct ath10k *ar, struct ieee80211_vif *vif)
1885 return ath10k_vif_to_arvif(vif)->vdev_id;
1887 if (ar->monitor_started)
1888 return ar->monitor_vdev_id;
1890 ath10k_warn(ar, "failed to resolve vdev id\n");
1894 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1895 * Control in the header.
1897 static void ath10k_tx_h_nwifi(struct ieee80211_hw *hw, struct sk_buff *skb)
1899 struct ieee80211_hdr *hdr = (void *)skb->data;
1900 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
1903 if (!ieee80211_is_data_qos(hdr->frame_control))
1906 qos_ctl = ieee80211_get_qos_ctl(hdr);
1907 memmove(skb->data + IEEE80211_QOS_CTL_LEN,
1908 skb->data, (void *)qos_ctl - (void *)skb->data);
1909 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
1911 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1912 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1913 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1914 * it is safe to downgrade to NullFunc.
1916 if (ieee80211_is_qos_nullfunc(hdr->frame_control)) {
1917 hdr->frame_control &= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1918 cb->htt.tid = HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST;
1922 static void ath10k_tx_wep_key_work(struct work_struct *work)
1924 struct ath10k_vif *arvif = container_of(work, struct ath10k_vif,
1926 struct ath10k *ar = arvif->ar;
1927 int ret, keyidx = arvif->def_wep_key_newidx;
1929 mutex_lock(&arvif->ar->conf_mutex);
1931 if (arvif->ar->state != ATH10K_STATE_ON)
1934 if (arvif->def_wep_key_idx == keyidx)
1937 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1938 arvif->vdev_id, keyidx);
1940 ret = ath10k_wmi_vdev_set_param(arvif->ar,
1942 arvif->ar->wmi.vdev_param->def_keyid,
1945 ath10k_warn(ar, "failed to update wep key index for vdev %d: %d\n",
1951 arvif->def_wep_key_idx = keyidx;
1954 mutex_unlock(&arvif->ar->conf_mutex);
1957 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif *vif,
1958 struct ieee80211_key_conf *key,
1959 struct sk_buff *skb)
1961 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1962 struct ath10k *ar = arvif->ar;
1963 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1965 if (!ieee80211_has_protected(hdr->frame_control))
1971 if (key->cipher != WLAN_CIPHER_SUITE_WEP40 &&
1972 key->cipher != WLAN_CIPHER_SUITE_WEP104)
1975 if (key->keyidx == arvif->def_wep_key_idx)
1978 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1979 * queueing frames until key index is updated is not an option because
1980 * sk_buff may need more processing to be done, e.g. offchannel */
1981 arvif->def_wep_key_newidx = key->keyidx;
1982 ieee80211_queue_work(ar->hw, &arvif->wep_key_work);
1985 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k *ar,
1986 struct ieee80211_vif *vif,
1987 struct sk_buff *skb)
1989 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1990 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
1992 /* This is case only for P2P_GO */
1993 if (arvif->vdev_type != WMI_VDEV_TYPE_AP ||
1994 arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
1997 if (unlikely(ieee80211_is_probe_resp(hdr->frame_control))) {
1998 spin_lock_bh(&ar->data_lock);
1999 if (arvif->u.ap.noa_data)
2000 if (!pskb_expand_head(skb, 0, arvif->u.ap.noa_len,
2002 memcpy(skb_put(skb, arvif->u.ap.noa_len),
2003 arvif->u.ap.noa_data,
2004 arvif->u.ap.noa_len);
2005 spin_unlock_bh(&ar->data_lock);
2009 static void ath10k_tx_htt(struct ath10k *ar, struct sk_buff *skb)
2011 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2014 if (ar->htt.target_version_major >= 3) {
2015 /* Since HTT 3.0 there is no separate mgmt tx command */
2016 ret = ath10k_htt_tx(&ar->htt, skb);
2020 if (ieee80211_is_mgmt(hdr->frame_control)) {
2021 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2023 if (skb_queue_len(&ar->wmi_mgmt_tx_queue) >=
2024 ATH10K_MAX_NUM_MGMT_PENDING) {
2025 ath10k_warn(ar, "reached WMI management transmit queue limit\n");
2030 skb_queue_tail(&ar->wmi_mgmt_tx_queue, skb);
2031 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
2033 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2035 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX,
2037 ieee80211_is_nullfunc(hdr->frame_control)) {
2038 /* FW does not report tx status properly for NullFunc frames
2039 * unless they are sent through mgmt tx path. mac80211 sends
2040 * those frames when it detects link/beacon loss and depends
2041 * on the tx status to be correct. */
2042 ret = ath10k_htt_mgmt_tx(&ar->htt, skb);
2044 ret = ath10k_htt_tx(&ar->htt, skb);
2049 ath10k_warn(ar, "failed to transmit packet, dropping: %d\n",
2051 ieee80211_free_txskb(ar->hw, skb);
2055 void ath10k_offchan_tx_purge(struct ath10k *ar)
2057 struct sk_buff *skb;
2060 skb = skb_dequeue(&ar->offchan_tx_queue);
2064 ieee80211_free_txskb(ar->hw, skb);
2068 void ath10k_offchan_tx_work(struct work_struct *work)
2070 struct ath10k *ar = container_of(work, struct ath10k, offchan_tx_work);
2071 struct ath10k_peer *peer;
2072 struct ieee80211_hdr *hdr;
2073 struct sk_buff *skb;
2074 const u8 *peer_addr;
2078 /* FW requirement: We must create a peer before FW will send out
2079 * an offchannel frame. Otherwise the frame will be stuck and
2080 * never transmitted. We delete the peer upon tx completion.
2081 * It is unlikely that a peer for offchannel tx will already be
2082 * present. However it may be in some rare cases so account for that.
2083 * Otherwise we might remove a legitimate peer and break stuff. */
2086 skb = skb_dequeue(&ar->offchan_tx_queue);
2090 mutex_lock(&ar->conf_mutex);
2092 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac offchannel skb %p\n",
2095 hdr = (struct ieee80211_hdr *)skb->data;
2096 peer_addr = ieee80211_get_DA(hdr);
2097 vdev_id = ATH10K_SKB_CB(skb)->vdev_id;
2099 spin_lock_bh(&ar->data_lock);
2100 peer = ath10k_peer_find(ar, vdev_id, peer_addr);
2101 spin_unlock_bh(&ar->data_lock);
2104 /* FIXME: should this use ath10k_warn()? */
2105 ath10k_dbg(ar, ATH10K_DBG_MAC, "peer %pM on vdev %d already present\n",
2106 peer_addr, vdev_id);
2109 ret = ath10k_peer_create(ar, vdev_id, peer_addr);
2111 ath10k_warn(ar, "failed to create peer %pM on vdev %d: %d\n",
2112 peer_addr, vdev_id, ret);
2115 spin_lock_bh(&ar->data_lock);
2116 reinit_completion(&ar->offchan_tx_completed);
2117 ar->offchan_tx_skb = skb;
2118 spin_unlock_bh(&ar->data_lock);
2120 ath10k_tx_htt(ar, skb);
2122 ret = wait_for_completion_timeout(&ar->offchan_tx_completed,
2125 ath10k_warn(ar, "timed out waiting for offchannel skb %p\n",
2129 ret = ath10k_peer_delete(ar, vdev_id, peer_addr);
2131 ath10k_warn(ar, "failed to delete peer %pM on vdev %d: %d\n",
2132 peer_addr, vdev_id, ret);
2135 mutex_unlock(&ar->conf_mutex);
2139 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k *ar)
2141 struct sk_buff *skb;
2144 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2148 ieee80211_free_txskb(ar->hw, skb);
2152 void ath10k_mgmt_over_wmi_tx_work(struct work_struct *work)
2154 struct ath10k *ar = container_of(work, struct ath10k, wmi_mgmt_tx_work);
2155 struct sk_buff *skb;
2159 skb = skb_dequeue(&ar->wmi_mgmt_tx_queue);
2163 ret = ath10k_wmi_mgmt_tx(ar, skb);
2165 ath10k_warn(ar, "failed to transmit management frame via WMI: %d\n",
2167 ieee80211_free_txskb(ar->hw, skb);
2176 void __ath10k_scan_finish(struct ath10k *ar)
2178 lockdep_assert_held(&ar->data_lock);
2180 switch (ar->scan.state) {
2181 case ATH10K_SCAN_IDLE:
2183 case ATH10K_SCAN_RUNNING:
2184 case ATH10K_SCAN_ABORTING:
2185 if (ar->scan.is_roc)
2186 ieee80211_remain_on_channel_expired(ar->hw);
2188 ieee80211_scan_completed(ar->hw,
2190 ATH10K_SCAN_ABORTING));
2192 case ATH10K_SCAN_STARTING:
2193 ar->scan.state = ATH10K_SCAN_IDLE;
2194 ar->scan_channel = NULL;
2195 ath10k_offchan_tx_purge(ar);
2196 cancel_delayed_work(&ar->scan.timeout);
2197 complete_all(&ar->scan.completed);
2202 void ath10k_scan_finish(struct ath10k *ar)
2204 spin_lock_bh(&ar->data_lock);
2205 __ath10k_scan_finish(ar);
2206 spin_unlock_bh(&ar->data_lock);
2209 static int ath10k_scan_stop(struct ath10k *ar)
2211 struct wmi_stop_scan_arg arg = {
2212 .req_id = 1, /* FIXME */
2213 .req_type = WMI_SCAN_STOP_ONE,
2214 .u.scan_id = ATH10K_SCAN_ID,
2218 lockdep_assert_held(&ar->conf_mutex);
2220 ret = ath10k_wmi_stop_scan(ar, &arg);
2222 ath10k_warn(ar, "failed to stop wmi scan: %d\n", ret);
2226 ret = wait_for_completion_timeout(&ar->scan.completed, 3*HZ);
2228 ath10k_warn(ar, "failed to receive scan abortion completion: timed out\n");
2230 } else if (ret > 0) {
2235 /* Scan state should be updated upon scan completion but in case
2236 * firmware fails to deliver the event (for whatever reason) it is
2237 * desired to clean up scan state anyway. Firmware may have just
2238 * dropped the scan completion event delivery due to transport pipe
2239 * being overflown with data and/or it can recover on its own before
2240 * next scan request is submitted.
2242 spin_lock_bh(&ar->data_lock);
2243 if (ar->scan.state != ATH10K_SCAN_IDLE)
2244 __ath10k_scan_finish(ar);
2245 spin_unlock_bh(&ar->data_lock);
2250 static void ath10k_scan_abort(struct ath10k *ar)
2254 lockdep_assert_held(&ar->conf_mutex);
2256 spin_lock_bh(&ar->data_lock);
2258 switch (ar->scan.state) {
2259 case ATH10K_SCAN_IDLE:
2260 /* This can happen if timeout worker kicked in and called
2261 * abortion while scan completion was being processed.
2264 case ATH10K_SCAN_STARTING:
2265 case ATH10K_SCAN_ABORTING:
2266 ath10k_warn(ar, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2267 ath10k_scan_state_str(ar->scan.state),
2270 case ATH10K_SCAN_RUNNING:
2271 ar->scan.state = ATH10K_SCAN_ABORTING;
2272 spin_unlock_bh(&ar->data_lock);
2274 ret = ath10k_scan_stop(ar);
2276 ath10k_warn(ar, "failed to abort scan: %d\n", ret);
2278 spin_lock_bh(&ar->data_lock);
2282 spin_unlock_bh(&ar->data_lock);
2285 void ath10k_scan_timeout_work(struct work_struct *work)
2287 struct ath10k *ar = container_of(work, struct ath10k,
2290 mutex_lock(&ar->conf_mutex);
2291 ath10k_scan_abort(ar);
2292 mutex_unlock(&ar->conf_mutex);
2295 static int ath10k_start_scan(struct ath10k *ar,
2296 const struct wmi_start_scan_arg *arg)
2300 lockdep_assert_held(&ar->conf_mutex);
2302 ret = ath10k_wmi_start_scan(ar, arg);
2306 ret = wait_for_completion_timeout(&ar->scan.started, 1*HZ);
2308 ret = ath10k_scan_stop(ar);
2310 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
2315 /* Add a 200ms margin to account for event/command processing */
2316 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2317 msecs_to_jiffies(arg->max_scan_time+200));
2321 /**********************/
2322 /* mac80211 callbacks */
2323 /**********************/
2325 static void ath10k_tx(struct ieee80211_hw *hw,
2326 struct ieee80211_tx_control *control,
2327 struct sk_buff *skb)
2329 struct ath10k *ar = hw->priv;
2330 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2331 struct ieee80211_vif *vif = info->control.vif;
2332 struct ieee80211_key_conf *key = info->control.hw_key;
2333 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2335 /* We should disable CCK RATE due to P2P */
2336 if (info->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
2337 ath10k_dbg(ar, ATH10K_DBG_MAC, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2339 ATH10K_SKB_CB(skb)->htt.is_offchan = false;
2340 ATH10K_SKB_CB(skb)->htt.tid = ath10k_tx_h_get_tid(hdr);
2341 ATH10K_SKB_CB(skb)->vdev_id = ath10k_tx_h_get_vdev_id(ar, vif);
2343 /* it makes no sense to process injected frames like that */
2344 if (vif && vif->type != NL80211_IFTYPE_MONITOR) {
2345 ath10k_tx_h_nwifi(hw, skb);
2346 ath10k_tx_h_update_wep_key(vif, key, skb);
2347 ath10k_tx_h_add_p2p_noa_ie(ar, vif, skb);
2348 ath10k_tx_h_seq_no(vif, skb);
2351 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) {
2352 spin_lock_bh(&ar->data_lock);
2353 ATH10K_SKB_CB(skb)->htt.is_offchan = true;
2354 ATH10K_SKB_CB(skb)->vdev_id = ar->scan.vdev_id;
2355 spin_unlock_bh(&ar->data_lock);
2357 ath10k_dbg(ar, ATH10K_DBG_MAC, "queued offchannel skb %p\n",
2360 skb_queue_tail(&ar->offchan_tx_queue, skb);
2361 ieee80211_queue_work(hw, &ar->offchan_tx_work);
2365 ath10k_tx_htt(ar, skb);
2368 /* Must not be called with conf_mutex held as workers can use that also. */
2369 static void ath10k_drain_tx(struct ath10k *ar)
2371 /* make sure rcu-protected mac80211 tx path itself is drained */
2374 ath10k_offchan_tx_purge(ar);
2375 ath10k_mgmt_over_wmi_tx_purge(ar);
2377 cancel_work_sync(&ar->offchan_tx_work);
2378 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2381 void ath10k_halt(struct ath10k *ar)
2383 struct ath10k_vif *arvif;
2385 lockdep_assert_held(&ar->conf_mutex);
2387 clear_bit(ATH10K_CAC_RUNNING, &ar->dev_flags);
2388 ar->filter_flags = 0;
2389 ar->monitor = false;
2391 if (ar->monitor_started)
2392 ath10k_monitor_stop(ar);
2394 ar->monitor_started = false;
2396 ath10k_scan_finish(ar);
2397 ath10k_peer_cleanup_all(ar);
2398 ath10k_core_stop(ar);
2399 ath10k_hif_power_down(ar);
2401 spin_lock_bh(&ar->data_lock);
2402 list_for_each_entry(arvif, &ar->arvifs, list)
2403 ath10k_mac_vif_beacon_cleanup(arvif);
2404 spin_unlock_bh(&ar->data_lock);
2407 static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2409 struct ath10k *ar = hw->priv;
2411 mutex_lock(&ar->conf_mutex);
2413 if (ar->cfg_tx_chainmask) {
2414 *tx_ant = ar->cfg_tx_chainmask;
2415 *rx_ant = ar->cfg_rx_chainmask;
2417 *tx_ant = ar->supp_tx_chainmask;
2418 *rx_ant = ar->supp_rx_chainmask;
2421 mutex_unlock(&ar->conf_mutex);
2426 static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2430 lockdep_assert_held(&ar->conf_mutex);
2432 ar->cfg_tx_chainmask = tx_ant;
2433 ar->cfg_rx_chainmask = rx_ant;
2435 if ((ar->state != ATH10K_STATE_ON) &&
2436 (ar->state != ATH10K_STATE_RESTARTED))
2439 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2442 ath10k_warn(ar, "failed to set tx-chainmask: %d, req 0x%x\n",
2447 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2450 ath10k_warn(ar, "failed to set rx-chainmask: %d, req 0x%x\n",
2458 static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2460 struct ath10k *ar = hw->priv;
2463 mutex_lock(&ar->conf_mutex);
2464 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2465 mutex_unlock(&ar->conf_mutex);
2469 static int ath10k_start(struct ieee80211_hw *hw)
2471 struct ath10k *ar = hw->priv;
2475 * This makes sense only when restarting hw. It is harmless to call
2476 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2477 * commands will be submitted while restarting.
2479 ath10k_drain_tx(ar);
2481 mutex_lock(&ar->conf_mutex);
2483 switch (ar->state) {
2484 case ATH10K_STATE_OFF:
2485 ar->state = ATH10K_STATE_ON;
2487 case ATH10K_STATE_RESTARTING:
2489 ar->state = ATH10K_STATE_RESTARTED;
2491 case ATH10K_STATE_ON:
2492 case ATH10K_STATE_RESTARTED:
2493 case ATH10K_STATE_WEDGED:
2497 case ATH10K_STATE_UTF:
2502 ret = ath10k_hif_power_up(ar);
2504 ath10k_err(ar, "Could not init hif: %d\n", ret);
2508 ret = ath10k_core_start(ar, ATH10K_FIRMWARE_MODE_NORMAL);
2510 ath10k_err(ar, "Could not init core: %d\n", ret);
2511 goto err_power_down;
2514 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2516 ath10k_warn(ar, "failed to enable PMF QOS: %d\n", ret);
2520 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2522 ath10k_warn(ar, "failed to enable dynamic BW: %d\n", ret);
2526 if (ar->cfg_tx_chainmask)
2527 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2528 ar->cfg_rx_chainmask);
2531 * By default FW set ARP frames ac to voice (6). In that case ARP
2532 * exchange is not working properly for UAPSD enabled AP. ARP requests
2533 * which arrives with access category 0 are processed by network stack
2534 * and send back with access category 0, but FW changes access category
2535 * to 6. Set ARP frames access category to best effort (0) solves
2539 ret = ath10k_wmi_pdev_set_param(ar,
2540 ar->wmi.pdev_param->arp_ac_override, 0);
2542 ath10k_warn(ar, "failed to set arp ac override parameter: %d\n",
2547 ar->num_started_vdevs = 0;
2548 ath10k_regd_update(ar);
2550 ath10k_spectral_start(ar);
2552 mutex_unlock(&ar->conf_mutex);
2556 ath10k_core_stop(ar);
2559 ath10k_hif_power_down(ar);
2562 ar->state = ATH10K_STATE_OFF;
2565 mutex_unlock(&ar->conf_mutex);
2569 static void ath10k_stop(struct ieee80211_hw *hw)
2571 struct ath10k *ar = hw->priv;
2573 ath10k_drain_tx(ar);
2575 mutex_lock(&ar->conf_mutex);
2576 if (ar->state != ATH10K_STATE_OFF) {
2578 ar->state = ATH10K_STATE_OFF;
2580 mutex_unlock(&ar->conf_mutex);
2582 cancel_delayed_work_sync(&ar->scan.timeout);
2583 cancel_work_sync(&ar->restart_work);
2586 static int ath10k_config_ps(struct ath10k *ar)
2588 struct ath10k_vif *arvif;
2591 lockdep_assert_held(&ar->conf_mutex);
2593 list_for_each_entry(arvif, &ar->arvifs, list) {
2594 ret = ath10k_mac_vif_setup_ps(arvif);
2596 ath10k_warn(ar, "failed to setup powersave: %d\n", ret);
2604 static const char *chandef_get_width(enum nl80211_chan_width width)
2607 case NL80211_CHAN_WIDTH_20_NOHT:
2609 case NL80211_CHAN_WIDTH_20:
2611 case NL80211_CHAN_WIDTH_40:
2613 case NL80211_CHAN_WIDTH_80:
2615 case NL80211_CHAN_WIDTH_80P80:
2617 case NL80211_CHAN_WIDTH_160:
2619 case NL80211_CHAN_WIDTH_5:
2621 case NL80211_CHAN_WIDTH_10:
2627 static void ath10k_config_chan(struct ath10k *ar)
2629 struct ath10k_vif *arvif;
2632 lockdep_assert_held(&ar->conf_mutex);
2634 ath10k_dbg(ar, ATH10K_DBG_MAC,
2635 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2636 ar->chandef.chan->center_freq,
2637 ar->chandef.center_freq1,
2638 ar->chandef.center_freq2,
2639 chandef_get_width(ar->chandef.width));
2641 /* First stop monitor interface. Some FW versions crash if there's a
2642 * lone monitor interface. */
2643 if (ar->monitor_started)
2644 ath10k_monitor_stop(ar);
2646 list_for_each_entry(arvif, &ar->arvifs, list) {
2647 if (!arvif->is_started)
2653 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2656 ret = ath10k_wmi_vdev_down(ar, arvif->vdev_id);
2658 ath10k_warn(ar, "failed to down vdev %d: %d\n",
2659 arvif->vdev_id, ret);
2664 /* all vdevs are downed now - attempt to restart and re-up them */
2666 list_for_each_entry(arvif, &ar->arvifs, list) {
2667 if (!arvif->is_started)
2670 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
2673 ret = ath10k_vdev_restart(arvif);
2675 ath10k_warn(ar, "failed to restart vdev %d: %d\n",
2676 arvif->vdev_id, ret);
2683 ret = ath10k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
2686 ath10k_warn(ar, "failed to bring vdev up %d: %d\n",
2687 arvif->vdev_id, ret);
2692 ath10k_monitor_recalc(ar);
2695 static int ath10k_config(struct ieee80211_hw *hw, u32 changed)
2697 struct ath10k *ar = hw->priv;
2698 struct ieee80211_conf *conf = &hw->conf;
2702 mutex_lock(&ar->conf_mutex);
2704 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2705 ath10k_dbg(ar, ATH10K_DBG_MAC,
2706 "mac config channel %dMHz flags 0x%x radar %d\n",
2707 conf->chandef.chan->center_freq,
2708 conf->chandef.chan->flags,
2709 conf->radar_enabled);
2711 spin_lock_bh(&ar->data_lock);
2712 ar->rx_channel = conf->chandef.chan;
2713 spin_unlock_bh(&ar->data_lock);
2715 ar->radar_enabled = conf->radar_enabled;
2716 ath10k_recalc_radar_detection(ar);
2718 if (!cfg80211_chandef_identical(&ar->chandef, &conf->chandef)) {
2719 ar->chandef = conf->chandef;
2720 ath10k_config_chan(ar);
2724 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2725 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac config power %d\n",
2726 hw->conf.power_level);
2728 param = ar->wmi.pdev_param->txpower_limit2g;
2729 ret = ath10k_wmi_pdev_set_param(ar, param,
2730 hw->conf.power_level * 2);
2732 ath10k_warn(ar, "failed to set 2g txpower %d: %d\n",
2733 hw->conf.power_level, ret);
2735 param = ar->wmi.pdev_param->txpower_limit5g;
2736 ret = ath10k_wmi_pdev_set_param(ar, param,
2737 hw->conf.power_level * 2);
2739 ath10k_warn(ar, "failed to set 5g txpower %d: %d\n",
2740 hw->conf.power_level, ret);
2743 if (changed & IEEE80211_CONF_CHANGE_PS)
2744 ath10k_config_ps(ar);
2746 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
2747 ar->monitor = conf->flags & IEEE80211_CONF_MONITOR;
2748 ret = ath10k_monitor_recalc(ar);
2750 ath10k_warn(ar, "failed to recalc monitor: %d\n", ret);
2753 mutex_unlock(&ar->conf_mutex);
2759 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2760 * because we will send mgmt frames without CCK. This requirement
2761 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2764 static int ath10k_add_interface(struct ieee80211_hw *hw,
2765 struct ieee80211_vif *vif)
2767 struct ath10k *ar = hw->priv;
2768 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2769 enum wmi_sta_powersave_param param;
2775 mutex_lock(&ar->conf_mutex);
2777 memset(arvif, 0, sizeof(*arvif));
2782 INIT_WORK(&arvif->wep_key_work, ath10k_tx_wep_key_work);
2783 INIT_LIST_HEAD(&arvif->list);
2785 if (ar->free_vdev_map == 0) {
2786 ath10k_warn(ar, "Free vdev map is empty, no more interfaces allowed.\n");
2790 bit = __ffs64(ar->free_vdev_map);
2792 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac create vdev %i map %llx\n",
2793 bit, ar->free_vdev_map);
2795 arvif->vdev_id = bit;
2796 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
2799 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_DEVICE;
2801 switch (vif->type) {
2802 case NL80211_IFTYPE_UNSPECIFIED:
2803 case NL80211_IFTYPE_STATION:
2804 arvif->vdev_type = WMI_VDEV_TYPE_STA;
2806 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_CLIENT;
2808 case NL80211_IFTYPE_ADHOC:
2809 arvif->vdev_type = WMI_VDEV_TYPE_IBSS;
2811 case NL80211_IFTYPE_AP:
2812 arvif->vdev_type = WMI_VDEV_TYPE_AP;
2815 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_P2P_GO;
2817 case NL80211_IFTYPE_MONITOR:
2818 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
2825 /* Some firmware revisions don't wait for beacon tx completion before
2826 * sending another SWBA event. This could lead to hardware using old
2827 * (freed) beacon data in some cases, e.g. tx credit starvation
2828 * combined with missed TBTT. This is very very rare.
2830 * On non-IOMMU-enabled hosts this could be a possible security issue
2831 * because hw could beacon some random data on the air. On
2832 * IOMMU-enabled hosts DMAR faults would occur in most cases and target
2833 * device would crash.
2835 * Since there are no beacon tx completions (implicit nor explicit)
2836 * propagated to host the only workaround for this is to allocate a
2837 * DMA-coherent buffer for a lifetime of a vif and use it for all
2838 * beacon tx commands. Worst case for this approach is some beacons may
2839 * become corrupted, e.g. have garbled IEs or out-of-date TIM bitmap.
2841 if (vif->type == NL80211_IFTYPE_ADHOC ||
2842 vif->type == NL80211_IFTYPE_AP) {
2843 arvif->beacon_buf = dma_zalloc_coherent(ar->dev,
2844 IEEE80211_MAX_FRAME_LEN,
2845 &arvif->beacon_paddr,
2847 if (!arvif->beacon_buf) {
2849 ath10k_warn(ar, "failed to allocate beacon buffer: %d\n",
2855 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev create %d (add interface) type %d subtype %d bcnmode %s\n",
2856 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
2857 arvif->beacon_buf ? "single-buf" : "per-skb");
2859 ret = ath10k_wmi_vdev_create(ar, arvif->vdev_id, arvif->vdev_type,
2860 arvif->vdev_subtype, vif->addr);
2862 ath10k_warn(ar, "failed to create WMI vdev %i: %d\n",
2863 arvif->vdev_id, ret);
2867 ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
2868 list_add(&arvif->list, &ar->arvifs);
2870 vdev_param = ar->wmi.vdev_param->def_keyid;
2871 ret = ath10k_wmi_vdev_set_param(ar, 0, vdev_param,
2872 arvif->def_wep_key_idx);
2874 ath10k_warn(ar, "failed to set vdev %i default key id: %d\n",
2875 arvif->vdev_id, ret);
2876 goto err_vdev_delete;
2879 vdev_param = ar->wmi.vdev_param->tx_encap_type;
2880 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
2881 ATH10K_HW_TXRX_NATIVE_WIFI);
2882 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2883 if (ret && ret != -EOPNOTSUPP) {
2884 ath10k_warn(ar, "failed to set vdev %i TX encapsulation: %d\n",
2885 arvif->vdev_id, ret);
2886 goto err_vdev_delete;
2889 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2890 ret = ath10k_peer_create(ar, arvif->vdev_id, vif->addr);
2892 ath10k_warn(ar, "failed to create vdev %i peer for AP: %d\n",
2893 arvif->vdev_id, ret);
2894 goto err_vdev_delete;
2897 ret = ath10k_mac_set_kickout(arvif);
2899 ath10k_warn(ar, "failed to set vdev %i kickout parameters: %d\n",
2900 arvif->vdev_id, ret);
2901 goto err_peer_delete;
2905 if (arvif->vdev_type == WMI_VDEV_TYPE_STA) {
2906 param = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
2907 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
2908 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2911 ath10k_warn(ar, "failed to set vdev %i RX wake policy: %d\n",
2912 arvif->vdev_id, ret);
2913 goto err_peer_delete;
2916 param = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
2917 value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
2918 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2921 ath10k_warn(ar, "failed to set vdev %i TX wake thresh: %d\n",
2922 arvif->vdev_id, ret);
2923 goto err_peer_delete;
2926 param = WMI_STA_PS_PARAM_PSPOLL_COUNT;
2927 value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
2928 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
2931 ath10k_warn(ar, "failed to set vdev %i PSPOLL count: %d\n",
2932 arvif->vdev_id, ret);
2933 goto err_peer_delete;
2937 ret = ath10k_mac_set_rts(arvif, ar->hw->wiphy->rts_threshold);
2939 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
2940 arvif->vdev_id, ret);
2941 goto err_peer_delete;
2944 ret = ath10k_mac_set_frag(arvif, ar->hw->wiphy->frag_threshold);
2946 ath10k_warn(ar, "failed to set frag threshold for vdev %d: %d\n",
2947 arvif->vdev_id, ret);
2948 goto err_peer_delete;
2951 mutex_unlock(&ar->conf_mutex);
2955 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
2956 ath10k_wmi_peer_delete(ar, arvif->vdev_id, vif->addr);
2959 ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
2960 ar->free_vdev_map |= 1LL << arvif->vdev_id;
2961 list_del(&arvif->list);
2964 if (arvif->beacon_buf) {
2965 dma_free_coherent(ar->dev, IEEE80211_MAX_FRAME_LEN,
2966 arvif->beacon_buf, arvif->beacon_paddr);
2967 arvif->beacon_buf = NULL;
2970 mutex_unlock(&ar->conf_mutex);
2975 static void ath10k_remove_interface(struct ieee80211_hw *hw,
2976 struct ieee80211_vif *vif)
2978 struct ath10k *ar = hw->priv;
2979 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
2982 mutex_lock(&ar->conf_mutex);
2984 cancel_work_sync(&arvif->wep_key_work);
2986 spin_lock_bh(&ar->data_lock);
2987 ath10k_mac_vif_beacon_cleanup(arvif);
2988 spin_unlock_bh(&ar->data_lock);
2990 ret = ath10k_spectral_vif_stop(arvif);
2992 ath10k_warn(ar, "failed to stop spectral for vdev %i: %d\n",
2993 arvif->vdev_id, ret);
2995 ar->free_vdev_map |= 1LL << arvif->vdev_id;
2996 list_del(&arvif->list);
2998 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
2999 ret = ath10k_peer_delete(arvif->ar, arvif->vdev_id, vif->addr);
3001 ath10k_warn(ar, "failed to remove peer for AP vdev %i: %d\n",
3002 arvif->vdev_id, ret);
3004 kfree(arvif->u.ap.noa_data);
3007 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %i delete (remove interface)\n",
3010 ret = ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
3012 ath10k_warn(ar, "failed to delete WMI vdev %i: %d\n",
3013 arvif->vdev_id, ret);
3015 ath10k_peer_cleanup(ar, arvif->vdev_id);
3017 mutex_unlock(&ar->conf_mutex);
3021 * FIXME: Has to be verified.
3023 #define SUPPORTED_FILTERS \
3024 (FIF_PROMISC_IN_BSS | \
3029 FIF_BCN_PRBRESP_PROMISC | \
3033 static void ath10k_configure_filter(struct ieee80211_hw *hw,
3034 unsigned int changed_flags,
3035 unsigned int *total_flags,
3038 struct ath10k *ar = hw->priv;
3041 mutex_lock(&ar->conf_mutex);
3043 changed_flags &= SUPPORTED_FILTERS;
3044 *total_flags &= SUPPORTED_FILTERS;
3045 ar->filter_flags = *total_flags;
3047 ret = ath10k_monitor_recalc(ar);
3049 ath10k_warn(ar, "failed to recalc montior: %d\n", ret);
3051 mutex_unlock(&ar->conf_mutex);
3054 static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
3055 struct ieee80211_vif *vif,
3056 struct ieee80211_bss_conf *info,
3059 struct ath10k *ar = hw->priv;
3060 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3062 u32 vdev_param, pdev_param, slottime, preamble;
3064 mutex_lock(&ar->conf_mutex);
3066 if (changed & BSS_CHANGED_IBSS)
3067 ath10k_control_ibss(arvif, info, vif->addr);
3069 if (changed & BSS_CHANGED_BEACON_INT) {
3070 arvif->beacon_interval = info->beacon_int;
3071 vdev_param = ar->wmi.vdev_param->beacon_interval;
3072 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3073 arvif->beacon_interval);
3074 ath10k_dbg(ar, ATH10K_DBG_MAC,
3075 "mac vdev %d beacon_interval %d\n",
3076 arvif->vdev_id, arvif->beacon_interval);
3079 ath10k_warn(ar, "failed to set beacon interval for vdev %d: %i\n",
3080 arvif->vdev_id, ret);
3083 if (changed & BSS_CHANGED_BEACON) {
3084 ath10k_dbg(ar, ATH10K_DBG_MAC,
3085 "vdev %d set beacon tx mode to staggered\n",
3088 pdev_param = ar->wmi.pdev_param->beacon_tx_mode;
3089 ret = ath10k_wmi_pdev_set_param(ar, pdev_param,
3090 WMI_BEACON_STAGGERED_MODE);
3092 ath10k_warn(ar, "failed to set beacon mode for vdev %d: %i\n",
3093 arvif->vdev_id, ret);
3096 if (changed & BSS_CHANGED_BEACON_INFO) {
3097 arvif->dtim_period = info->dtim_period;
3099 ath10k_dbg(ar, ATH10K_DBG_MAC,
3100 "mac vdev %d dtim_period %d\n",
3101 arvif->vdev_id, arvif->dtim_period);
3103 vdev_param = ar->wmi.vdev_param->dtim_period;
3104 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3105 arvif->dtim_period);
3107 ath10k_warn(ar, "failed to set dtim period for vdev %d: %i\n",
3108 arvif->vdev_id, ret);
3111 if (changed & BSS_CHANGED_SSID &&
3112 vif->type == NL80211_IFTYPE_AP) {
3113 arvif->u.ap.ssid_len = info->ssid_len;
3115 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3116 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3120 * Firmware manages AP self-peer internally so make sure to not create
3121 * it in driver. Otherwise AP self-peer deletion may timeout later.
3123 if (changed & BSS_CHANGED_BSSID &&
3124 vif->type != NL80211_IFTYPE_AP) {
3125 if (!is_zero_ether_addr(info->bssid)) {
3126 if (vif->type == NL80211_IFTYPE_STATION) {
3127 ath10k_dbg(ar, ATH10K_DBG_MAC,
3128 "mac vdev %d create peer %pM\n",
3129 arvif->vdev_id, info->bssid);
3131 ret = ath10k_peer_create(ar, arvif->vdev_id,
3134 ath10k_warn(ar, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
3135 info->bssid, arvif->vdev_id,
3138 * this is never erased as we it for crypto key
3139 * clearing; this is FW requirement
3141 ether_addr_copy(arvif->bssid, info->bssid);
3143 ath10k_dbg(ar, ATH10K_DBG_MAC,
3144 "mac vdev %d start %pM\n",
3145 arvif->vdev_id, info->bssid);
3147 ret = ath10k_vdev_start(arvif);
3149 ath10k_warn(ar, "failed to start vdev %i: %d\n",
3150 arvif->vdev_id, ret);
3154 arvif->is_started = true;
3158 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3159 * so driver need to store it. It is needed when leaving
3160 * IBSS in order to remove BSSID peer.
3162 if (vif->type == NL80211_IFTYPE_ADHOC)
3163 memcpy(arvif->bssid, info->bssid,
3168 if (changed & BSS_CHANGED_BEACON_ENABLED)
3169 ath10k_control_beaconing(arvif, info);
3171 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3172 arvif->use_cts_prot = info->use_cts_prot;
3173 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d cts_prot %d\n",
3174 arvif->vdev_id, info->use_cts_prot);
3176 ret = ath10k_recalc_rtscts_prot(arvif);
3178 ath10k_warn(ar, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3179 arvif->vdev_id, ret);
3182 if (changed & BSS_CHANGED_ERP_SLOT) {
3183 if (info->use_short_slot)
3184 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3187 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3189 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d slot_time %d\n",
3190 arvif->vdev_id, slottime);
3192 vdev_param = ar->wmi.vdev_param->slot_time;
3193 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3196 ath10k_warn(ar, "failed to set erp slot for vdev %d: %i\n",
3197 arvif->vdev_id, ret);
3200 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3201 if (info->use_short_preamble)
3202 preamble = WMI_VDEV_PREAMBLE_SHORT;
3204 preamble = WMI_VDEV_PREAMBLE_LONG;
3206 ath10k_dbg(ar, ATH10K_DBG_MAC,
3207 "mac vdev %d preamble %dn",
3208 arvif->vdev_id, preamble);
3210 vdev_param = ar->wmi.vdev_param->preamble;
3211 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3214 ath10k_warn(ar, "failed to set preamble for vdev %d: %i\n",
3215 arvif->vdev_id, ret);
3218 if (changed & BSS_CHANGED_ASSOC) {
3220 /* Workaround: Make sure monitor vdev is not running
3221 * when associating to prevent some firmware revisions
3222 * (e.g. 10.1 and 10.2) from crashing.
3224 if (ar->monitor_started)
3225 ath10k_monitor_stop(ar);
3226 ath10k_bss_assoc(hw, vif, info);
3227 ath10k_monitor_recalc(ar);
3232 mutex_unlock(&ar->conf_mutex);
3235 static int ath10k_hw_scan(struct ieee80211_hw *hw,
3236 struct ieee80211_vif *vif,
3237 struct ieee80211_scan_request *hw_req)
3239 struct ath10k *ar = hw->priv;
3240 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3241 struct cfg80211_scan_request *req = &hw_req->req;
3242 struct wmi_start_scan_arg arg;
3246 mutex_lock(&ar->conf_mutex);
3248 spin_lock_bh(&ar->data_lock);
3249 switch (ar->scan.state) {
3250 case ATH10K_SCAN_IDLE:
3251 reinit_completion(&ar->scan.started);
3252 reinit_completion(&ar->scan.completed);
3253 ar->scan.state = ATH10K_SCAN_STARTING;
3254 ar->scan.is_roc = false;
3255 ar->scan.vdev_id = arvif->vdev_id;
3258 case ATH10K_SCAN_STARTING:
3259 case ATH10K_SCAN_RUNNING:
3260 case ATH10K_SCAN_ABORTING:
3264 spin_unlock_bh(&ar->data_lock);
3269 memset(&arg, 0, sizeof(arg));
3270 ath10k_wmi_start_scan_init(ar, &arg);
3271 arg.vdev_id = arvif->vdev_id;
3272 arg.scan_id = ATH10K_SCAN_ID;
3275 arg.scan_ctrl_flags |= WMI_SCAN_ADD_CCK_RATES;
3278 arg.ie_len = req->ie_len;
3279 memcpy(arg.ie, req->ie, arg.ie_len);
3283 arg.n_ssids = req->n_ssids;
3284 for (i = 0; i < arg.n_ssids; i++) {
3285 arg.ssids[i].len = req->ssids[i].ssid_len;
3286 arg.ssids[i].ssid = req->ssids[i].ssid;
3289 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3292 if (req->n_channels) {
3293 arg.n_channels = req->n_channels;
3294 for (i = 0; i < arg.n_channels; i++)
3295 arg.channels[i] = req->channels[i]->center_freq;
3298 ret = ath10k_start_scan(ar, &arg);
3300 ath10k_warn(ar, "failed to start hw scan: %d\n", ret);
3301 spin_lock_bh(&ar->data_lock);
3302 ar->scan.state = ATH10K_SCAN_IDLE;
3303 spin_unlock_bh(&ar->data_lock);
3307 mutex_unlock(&ar->conf_mutex);
3311 static void ath10k_cancel_hw_scan(struct ieee80211_hw *hw,
3312 struct ieee80211_vif *vif)
3314 struct ath10k *ar = hw->priv;
3316 mutex_lock(&ar->conf_mutex);
3317 cancel_delayed_work_sync(&ar->scan.timeout);
3318 ath10k_scan_abort(ar);
3319 mutex_unlock(&ar->conf_mutex);
3322 static void ath10k_set_key_h_def_keyidx(struct ath10k *ar,
3323 struct ath10k_vif *arvif,
3324 enum set_key_cmd cmd,
3325 struct ieee80211_key_conf *key)
3327 u32 vdev_param = arvif->ar->wmi.vdev_param->def_keyid;
3330 /* 10.1 firmware branch requires default key index to be set to group
3331 * key index after installing it. Otherwise FW/HW Txes corrupted
3332 * frames with multi-vif APs. This is not required for main firmware
3333 * branch (e.g. 636).
3335 * FIXME: This has been tested only in AP. It remains unknown if this
3336 * is required for multi-vif STA interfaces on 10.1 */
3338 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
3341 if (key->cipher == WLAN_CIPHER_SUITE_WEP40)
3344 if (key->cipher == WLAN_CIPHER_SUITE_WEP104)
3347 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3353 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
3356 ath10k_warn(ar, "failed to set vdev %i group key as default key: %d\n",
3357 arvif->vdev_id, ret);
3360 static int ath10k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3361 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3362 struct ieee80211_key_conf *key)
3364 struct ath10k *ar = hw->priv;
3365 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3366 struct ath10k_peer *peer;
3367 const u8 *peer_addr;
3368 bool is_wep = key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3369 key->cipher == WLAN_CIPHER_SUITE_WEP104;
3372 if (key->keyidx > WMI_MAX_KEY_INDEX)
3375 mutex_lock(&ar->conf_mutex);
3378 peer_addr = sta->addr;
3379 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3380 peer_addr = vif->bss_conf.bssid;
3382 peer_addr = vif->addr;
3384 key->hw_key_idx = key->keyidx;
3386 /* the peer should not disappear in mid-way (unless FW goes awry) since
3387 * we already hold conf_mutex. we just make sure its there now. */
3388 spin_lock_bh(&ar->data_lock);
3389 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3390 spin_unlock_bh(&ar->data_lock);
3393 if (cmd == SET_KEY) {
3394 ath10k_warn(ar, "failed to install key for non-existent peer %pM\n",
3399 /* if the peer doesn't exist there is no key to disable
3407 arvif->wep_keys[key->keyidx] = key;
3409 arvif->wep_keys[key->keyidx] = NULL;
3411 if (cmd == DISABLE_KEY)
3412 ath10k_clear_vdev_key(arvif, key);
3415 ret = ath10k_install_key(arvif, key, cmd, peer_addr);
3417 ath10k_warn(ar, "failed to install key for vdev %i peer %pM: %d\n",
3418 arvif->vdev_id, peer_addr, ret);
3422 ath10k_set_key_h_def_keyidx(ar, arvif, cmd, key);
3424 spin_lock_bh(&ar->data_lock);
3425 peer = ath10k_peer_find(ar, arvif->vdev_id, peer_addr);
3426 if (peer && cmd == SET_KEY)
3427 peer->keys[key->keyidx] = key;
3428 else if (peer && cmd == DISABLE_KEY)
3429 peer->keys[key->keyidx] = NULL;
3430 else if (peer == NULL)
3431 /* impossible unless FW goes crazy */
3432 ath10k_warn(ar, "Peer %pM disappeared!\n", peer_addr);
3433 spin_unlock_bh(&ar->data_lock);
3436 mutex_unlock(&ar->conf_mutex);
3440 static void ath10k_sta_rc_update_wk(struct work_struct *wk)
3443 struct ath10k_vif *arvif;
3444 struct ath10k_sta *arsta;
3445 struct ieee80211_sta *sta;
3446 u32 changed, bw, nss, smps;
3449 arsta = container_of(wk, struct ath10k_sta, update_wk);
3450 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3451 arvif = arsta->arvif;
3454 spin_lock_bh(&ar->data_lock);
3456 changed = arsta->changed;
3463 spin_unlock_bh(&ar->data_lock);
3465 mutex_lock(&ar->conf_mutex);
3467 if (changed & IEEE80211_RC_BW_CHANGED) {
3468 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM peer bw %d\n",
3471 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3472 WMI_PEER_CHAN_WIDTH, bw);
3474 ath10k_warn(ar, "failed to update STA %pM peer bw %d: %d\n",
3475 sta->addr, bw, err);
3478 if (changed & IEEE80211_RC_NSS_CHANGED) {
3479 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM nss %d\n",
3482 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3485 ath10k_warn(ar, "failed to update STA %pM nss %d: %d\n",
3486 sta->addr, nss, err);
3489 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3490 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM smps %d\n",
3493 err = ath10k_wmi_peer_set_param(ar, arvif->vdev_id, sta->addr,
3494 WMI_PEER_SMPS_STATE, smps);
3496 ath10k_warn(ar, "failed to update STA %pM smps %d: %d\n",
3497 sta->addr, smps, err);
3500 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3501 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac update sta %pM supp rates\n",
3504 err = ath10k_station_assoc(ar, arvif->vif, sta, true);
3506 ath10k_warn(ar, "failed to reassociate station: %pM\n",
3510 mutex_unlock(&ar->conf_mutex);
3513 static int ath10k_sta_state(struct ieee80211_hw *hw,
3514 struct ieee80211_vif *vif,
3515 struct ieee80211_sta *sta,
3516 enum ieee80211_sta_state old_state,
3517 enum ieee80211_sta_state new_state)
3519 struct ath10k *ar = hw->priv;
3520 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3521 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
3525 if (old_state == IEEE80211_STA_NOTEXIST &&
3526 new_state == IEEE80211_STA_NONE) {
3527 memset(arsta, 0, sizeof(*arsta));
3528 arsta->arvif = arvif;
3529 INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk);
3532 /* cancel must be done outside the mutex to avoid deadlock */
3533 if ((old_state == IEEE80211_STA_NONE &&
3534 new_state == IEEE80211_STA_NOTEXIST))
3535 cancel_work_sync(&arsta->update_wk);
3537 mutex_lock(&ar->conf_mutex);
3539 if (old_state == IEEE80211_STA_NOTEXIST &&
3540 new_state == IEEE80211_STA_NONE &&
3541 vif->type != NL80211_IFTYPE_STATION) {
3543 * New station addition.
3545 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features))
3546 max_num_peers = TARGET_10X_NUM_PEERS_MAX - 1;
3548 max_num_peers = TARGET_NUM_PEERS;
3550 if (ar->num_peers >= max_num_peers) {
3551 ath10k_warn(ar, "number of peers exceeded: peers number %d (max peers %d)\n",
3552 ar->num_peers, max_num_peers);
3557 ath10k_dbg(ar, ATH10K_DBG_MAC,
3558 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3559 arvif->vdev_id, sta->addr, ar->num_peers);
3561 ret = ath10k_peer_create(ar, arvif->vdev_id, sta->addr);
3563 ath10k_warn(ar, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3564 sta->addr, arvif->vdev_id, ret);
3565 } else if ((old_state == IEEE80211_STA_NONE &&
3566 new_state == IEEE80211_STA_NOTEXIST)) {
3568 * Existing station deletion.
3570 ath10k_dbg(ar, ATH10K_DBG_MAC,
3571 "mac vdev %d peer delete %pM (sta gone)\n",
3572 arvif->vdev_id, sta->addr);
3573 ret = ath10k_peer_delete(ar, arvif->vdev_id, sta->addr);
3575 ath10k_warn(ar, "failed to delete peer %pM for vdev %d: %i\n",
3576 sta->addr, arvif->vdev_id, ret);
3578 if (vif->type == NL80211_IFTYPE_STATION)
3579 ath10k_bss_disassoc(hw, vif);
3580 } else if (old_state == IEEE80211_STA_AUTH &&
3581 new_state == IEEE80211_STA_ASSOC &&
3582 (vif->type == NL80211_IFTYPE_AP ||
3583 vif->type == NL80211_IFTYPE_ADHOC)) {
3587 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM associated\n",
3590 ret = ath10k_station_assoc(ar, vif, sta, false);
3592 ath10k_warn(ar, "failed to associate station %pM for vdev %i: %i\n",
3593 sta->addr, arvif->vdev_id, ret);
3594 } else if (old_state == IEEE80211_STA_ASSOC &&
3595 new_state == IEEE80211_STA_AUTH &&
3596 (vif->type == NL80211_IFTYPE_AP ||
3597 vif->type == NL80211_IFTYPE_ADHOC)) {
3601 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac sta %pM disassociated\n",
3604 ret = ath10k_station_disassoc(ar, vif, sta);
3606 ath10k_warn(ar, "failed to disassociate station: %pM vdev %i: %i\n",
3607 sta->addr, arvif->vdev_id, ret);
3610 mutex_unlock(&ar->conf_mutex);
3614 static int ath10k_conf_tx_uapsd(struct ath10k *ar, struct ieee80211_vif *vif,
3615 u16 ac, bool enable)
3617 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3621 lockdep_assert_held(&ar->conf_mutex);
3623 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3627 case IEEE80211_AC_VO:
3628 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3629 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3631 case IEEE80211_AC_VI:
3632 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3633 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3635 case IEEE80211_AC_BE:
3636 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3637 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3639 case IEEE80211_AC_BK:
3640 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3641 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3646 arvif->u.sta.uapsd |= value;
3648 arvif->u.sta.uapsd &= ~value;
3650 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3651 WMI_STA_PS_PARAM_UAPSD,
3652 arvif->u.sta.uapsd);
3654 ath10k_warn(ar, "failed to set uapsd params: %d\n", ret);
3658 if (arvif->u.sta.uapsd)
3659 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3661 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3663 ret = ath10k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3664 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3667 ath10k_warn(ar, "failed to set rx wake param: %d\n", ret);
3673 static int ath10k_conf_tx(struct ieee80211_hw *hw,
3674 struct ieee80211_vif *vif, u16 ac,
3675 const struct ieee80211_tx_queue_params *params)
3677 struct ath10k *ar = hw->priv;
3678 struct wmi_wmm_params_arg *p = NULL;
3681 mutex_lock(&ar->conf_mutex);
3684 case IEEE80211_AC_VO:
3685 p = &ar->wmm_params.ac_vo;
3687 case IEEE80211_AC_VI:
3688 p = &ar->wmm_params.ac_vi;
3690 case IEEE80211_AC_BE:
3691 p = &ar->wmm_params.ac_be;
3693 case IEEE80211_AC_BK:
3694 p = &ar->wmm_params.ac_bk;
3703 p->cwmin = params->cw_min;
3704 p->cwmax = params->cw_max;
3705 p->aifs = params->aifs;
3708 * The channel time duration programmed in the HW is in absolute
3709 * microseconds, while mac80211 gives the txop in units of
3712 p->txop = params->txop * 32;
3714 /* FIXME: FW accepts wmm params per hw, not per vif */
3715 ret = ath10k_wmi_pdev_set_wmm_params(ar, &ar->wmm_params);
3717 ath10k_warn(ar, "failed to set wmm params: %d\n", ret);
3721 ret = ath10k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3723 ath10k_warn(ar, "failed to set sta uapsd: %d\n", ret);
3726 mutex_unlock(&ar->conf_mutex);
3730 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3732 static int ath10k_remain_on_channel(struct ieee80211_hw *hw,
3733 struct ieee80211_vif *vif,
3734 struct ieee80211_channel *chan,
3736 enum ieee80211_roc_type type)
3738 struct ath10k *ar = hw->priv;
3739 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
3740 struct wmi_start_scan_arg arg;
3743 mutex_lock(&ar->conf_mutex);
3745 spin_lock_bh(&ar->data_lock);
3746 switch (ar->scan.state) {
3747 case ATH10K_SCAN_IDLE:
3748 reinit_completion(&ar->scan.started);
3749 reinit_completion(&ar->scan.completed);
3750 reinit_completion(&ar->scan.on_channel);
3751 ar->scan.state = ATH10K_SCAN_STARTING;
3752 ar->scan.is_roc = true;
3753 ar->scan.vdev_id = arvif->vdev_id;
3754 ar->scan.roc_freq = chan->center_freq;
3757 case ATH10K_SCAN_STARTING:
3758 case ATH10K_SCAN_RUNNING:
3759 case ATH10K_SCAN_ABORTING:
3763 spin_unlock_bh(&ar->data_lock);
3768 memset(&arg, 0, sizeof(arg));
3769 ath10k_wmi_start_scan_init(ar, &arg);
3770 arg.vdev_id = arvif->vdev_id;
3771 arg.scan_id = ATH10K_SCAN_ID;
3773 arg.channels[0] = chan->center_freq;
3774 arg.dwell_time_active = duration;
3775 arg.dwell_time_passive = duration;
3776 arg.max_scan_time = 2 * duration;
3777 arg.scan_ctrl_flags |= WMI_SCAN_FLAG_PASSIVE;
3778 arg.scan_ctrl_flags |= WMI_SCAN_FILTER_PROBE_REQ;
3780 ret = ath10k_start_scan(ar, &arg);
3782 ath10k_warn(ar, "failed to start roc scan: %d\n", ret);
3783 spin_lock_bh(&ar->data_lock);
3784 ar->scan.state = ATH10K_SCAN_IDLE;
3785 spin_unlock_bh(&ar->data_lock);
3789 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3*HZ);
3791 ath10k_warn(ar, "failed to switch to channel for roc scan\n");
3793 ret = ath10k_scan_stop(ar);
3795 ath10k_warn(ar, "failed to stop scan: %d\n", ret);
3803 mutex_unlock(&ar->conf_mutex);
3807 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw *hw)
3809 struct ath10k *ar = hw->priv;
3811 mutex_lock(&ar->conf_mutex);
3812 cancel_delayed_work_sync(&ar->scan.timeout);
3813 ath10k_scan_abort(ar);
3814 mutex_unlock(&ar->conf_mutex);
3820 * Both RTS and Fragmentation threshold are interface-specific
3821 * in ath10k, but device-specific in mac80211.
3824 static int ath10k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3826 struct ath10k *ar = hw->priv;
3827 struct ath10k_vif *arvif;
3830 mutex_lock(&ar->conf_mutex);
3831 list_for_each_entry(arvif, &ar->arvifs, list) {
3832 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d rts threshold %d\n",
3833 arvif->vdev_id, value);
3835 ret = ath10k_mac_set_rts(arvif, value);
3837 ath10k_warn(ar, "failed to set rts threshold for vdev %d: %d\n",
3838 arvif->vdev_id, ret);
3842 mutex_unlock(&ar->conf_mutex);
3847 static int ath10k_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3849 struct ath10k *ar = hw->priv;
3850 struct ath10k_vif *arvif;
3853 mutex_lock(&ar->conf_mutex);
3854 list_for_each_entry(arvif, &ar->arvifs, list) {
3855 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac vdev %d fragmentation threshold %d\n",
3856 arvif->vdev_id, value);
3858 ret = ath10k_mac_set_rts(arvif, value);
3860 ath10k_warn(ar, "failed to set fragmentation threshold for vdev %d: %d\n",
3861 arvif->vdev_id, ret);
3865 mutex_unlock(&ar->conf_mutex);
3870 static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3871 u32 queues, bool drop)
3873 struct ath10k *ar = hw->priv;
3877 /* mac80211 doesn't care if we really xmit queued frames or not
3878 * we'll collect those frames either way if we stop/delete vdevs */
3882 mutex_lock(&ar->conf_mutex);
3884 if (ar->state == ATH10K_STATE_WEDGED)
3887 ret = wait_event_timeout(ar->htt.empty_tx_wq, ({
3890 spin_lock_bh(&ar->htt.tx_lock);
3891 empty = (ar->htt.num_pending_tx == 0);
3892 spin_unlock_bh(&ar->htt.tx_lock);
3894 skip = (ar->state == ATH10K_STATE_WEDGED);
3897 }), ATH10K_FLUSH_TIMEOUT_HZ);
3899 if (ret <= 0 || skip)
3900 ath10k_warn(ar, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
3901 skip, ar->state, ret);
3904 mutex_unlock(&ar->conf_mutex);
3907 /* TODO: Implement this function properly
3908 * For now it is needed to reply to Probe Requests in IBSS mode.
3909 * Propably we need this information from FW.
3911 static int ath10k_tx_last_beacon(struct ieee80211_hw *hw)
3917 static int ath10k_suspend(struct ieee80211_hw *hw,
3918 struct cfg80211_wowlan *wowlan)
3920 struct ath10k *ar = hw->priv;
3923 mutex_lock(&ar->conf_mutex);
3925 ret = ath10k_wait_for_suspend(ar, WMI_PDEV_SUSPEND);
3927 if (ret == -ETIMEDOUT)
3933 ret = ath10k_hif_suspend(ar);
3935 ath10k_warn(ar, "failed to suspend hif: %d\n", ret);
3942 ret = ath10k_wmi_pdev_resume_target(ar);
3944 ath10k_warn(ar, "failed to resume target: %d\n", ret);
3948 mutex_unlock(&ar->conf_mutex);
3952 static int ath10k_resume(struct ieee80211_hw *hw)
3954 struct ath10k *ar = hw->priv;
3957 mutex_lock(&ar->conf_mutex);
3959 ret = ath10k_hif_resume(ar);
3961 ath10k_warn(ar, "failed to resume hif: %d\n", ret);
3966 ret = ath10k_wmi_pdev_resume_target(ar);
3968 ath10k_warn(ar, "failed to resume target: %d\n", ret);
3975 mutex_unlock(&ar->conf_mutex);
3980 static void ath10k_restart_complete(struct ieee80211_hw *hw)
3982 struct ath10k *ar = hw->priv;
3984 mutex_lock(&ar->conf_mutex);
3986 /* If device failed to restart it will be in a different state, e.g.
3987 * ATH10K_STATE_WEDGED */
3988 if (ar->state == ATH10K_STATE_RESTARTED) {
3989 ath10k_info(ar, "device successfully recovered\n");
3990 ar->state = ATH10K_STATE_ON;
3993 mutex_unlock(&ar->conf_mutex);
3996 static int ath10k_get_survey(struct ieee80211_hw *hw, int idx,
3997 struct survey_info *survey)
3999 struct ath10k *ar = hw->priv;
4000 struct ieee80211_supported_band *sband;
4001 struct survey_info *ar_survey = &ar->survey[idx];
4004 mutex_lock(&ar->conf_mutex);
4006 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
4007 if (sband && idx >= sband->n_channels) {
4008 idx -= sband->n_channels;
4013 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
4015 if (!sband || idx >= sband->n_channels) {
4020 spin_lock_bh(&ar->data_lock);
4021 memcpy(survey, ar_survey, sizeof(*survey));
4022 spin_unlock_bh(&ar->data_lock);
4024 survey->channel = &sband->channels[idx];
4027 mutex_unlock(&ar->conf_mutex);
4031 /* Helper table for legacy fixed_rate/bitrate_mask */
4032 static const u8 cck_ofdm_rate[] = {
4049 /* Check if only one bit set */
4050 static int ath10k_check_single_mask(u32 mask)
4058 mask &= ~BIT(bit - 1);
4066 ath10k_default_bitrate_mask(struct ath10k *ar,
4067 enum ieee80211_band band,
4068 const struct cfg80211_bitrate_mask *mask)
4070 u32 legacy = 0x00ff;
4075 case IEEE80211_BAND_2GHZ:
4079 case IEEE80211_BAND_5GHZ:
4085 if (mask->control[band].legacy != legacy)
4088 for (i = 0; i < ar->num_rf_chains; i++)
4089 if (mask->control[band].ht_mcs[i] != ht)
4092 for (i = 0; i < ar->num_rf_chains; i++)
4093 if (mask->control[band].vht_mcs[i] != vht)
4100 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask *mask,
4101 enum ieee80211_band band,
4104 int ht_nss = 0, vht_nss = 0, i;
4107 if (ath10k_check_single_mask(mask->control[band].legacy))
4111 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
4112 if (mask->control[band].ht_mcs[i] == 0xff)
4114 else if (mask->control[band].ht_mcs[i] == 0x00)
4123 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4124 if (mask->control[band].vht_mcs[i] == 0x03ff)
4126 else if (mask->control[band].vht_mcs[i] == 0x0000)
4134 if (ht_nss > 0 && vht_nss > 0)
4138 *fixed_nss = ht_nss;
4140 *fixed_nss = vht_nss;
4148 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask *mask,
4149 enum ieee80211_band band,
4150 enum wmi_rate_preamble *preamble)
4152 int legacy = 0, ht = 0, vht = 0, i;
4154 *preamble = WMI_RATE_PREAMBLE_OFDM;
4157 legacy = ath10k_check_single_mask(mask->control[band].legacy);
4162 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4163 ht += ath10k_check_single_mask(mask->control[band].ht_mcs[i]);
4168 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4169 vht += ath10k_check_single_mask(mask->control[band].vht_mcs[i]);
4173 /* Currently we support only one fixed_rate */
4174 if ((legacy + ht + vht) != 1)
4178 *preamble = WMI_RATE_PREAMBLE_HT;
4180 *preamble = WMI_RATE_PREAMBLE_VHT;
4186 ath10k_bitrate_mask_rate(struct ath10k *ar,
4187 const struct cfg80211_bitrate_mask *mask,
4188 enum ieee80211_band band,
4192 u8 rate = 0, pream = 0, nss = 0, i;
4193 enum wmi_rate_preamble preamble;
4195 /* Check if single rate correct */
4196 if (!ath10k_bitrate_mask_correct(mask, band, &preamble))
4202 case WMI_RATE_PREAMBLE_CCK:
4203 case WMI_RATE_PREAMBLE_OFDM:
4204 i = ffs(mask->control[band].legacy) - 1;
4206 if (band == IEEE80211_BAND_2GHZ && i < 4)
4207 pream = WMI_RATE_PREAMBLE_CCK;
4209 if (band == IEEE80211_BAND_5GHZ)
4212 if (i >= ARRAY_SIZE(cck_ofdm_rate))
4215 rate = cck_ofdm_rate[i];
4217 case WMI_RATE_PREAMBLE_HT:
4218 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4219 if (mask->control[band].ht_mcs[i])
4222 if (i == IEEE80211_HT_MCS_MASK_LEN)
4225 rate = ffs(mask->control[band].ht_mcs[i]) - 1;
4228 case WMI_RATE_PREAMBLE_VHT:
4229 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4230 if (mask->control[band].vht_mcs[i])
4233 if (i == NL80211_VHT_NSS_MAX)
4236 rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4241 *fixed_nss = nss + 1;
4245 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4248 *fixed_rate = pream | nss | rate;
4253 static bool ath10k_get_fixed_rate_nss(struct ath10k *ar,
4254 const struct cfg80211_bitrate_mask *mask,
4255 enum ieee80211_band band,
4259 /* First check full NSS mask, if we can simply limit NSS */
4260 if (ath10k_bitrate_mask_nss(mask, band, fixed_nss))
4263 /* Next Check single rate is set */
4264 return ath10k_bitrate_mask_rate(ar, mask, band, fixed_rate, fixed_nss);
4267 static int ath10k_set_fixed_rate_param(struct ath10k_vif *arvif,
4272 struct ath10k *ar = arvif->ar;
4276 mutex_lock(&ar->conf_mutex);
4278 if (arvif->fixed_rate == fixed_rate &&
4279 arvif->fixed_nss == fixed_nss &&
4280 arvif->force_sgi == force_sgi)
4283 if (fixed_rate == WMI_FIXED_RATE_NONE)
4284 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac disable fixed bitrate mask\n");
4287 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac force sgi\n");
4289 vdev_param = ar->wmi.vdev_param->fixed_rate;
4290 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4291 vdev_param, fixed_rate);
4293 ath10k_warn(ar, "failed to set fixed rate param 0x%02x: %d\n",
4299 arvif->fixed_rate = fixed_rate;
4301 vdev_param = ar->wmi.vdev_param->nss;
4302 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id,
4303 vdev_param, fixed_nss);
4306 ath10k_warn(ar, "failed to set fixed nss param %d: %d\n",
4312 arvif->fixed_nss = fixed_nss;
4314 vdev_param = ar->wmi.vdev_param->sgi;
4315 ret = ath10k_wmi_vdev_set_param(ar, arvif->vdev_id, vdev_param,
4319 ath10k_warn(ar, "failed to set sgi param %d: %d\n",
4325 arvif->force_sgi = force_sgi;
4328 mutex_unlock(&ar->conf_mutex);
4332 static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4333 struct ieee80211_vif *vif,
4334 const struct cfg80211_bitrate_mask *mask)
4336 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4337 struct ath10k *ar = arvif->ar;
4338 enum ieee80211_band band = ar->hw->conf.chandef.chan->band;
4339 u8 fixed_rate = WMI_FIXED_RATE_NONE;
4340 u8 fixed_nss = ar->num_rf_chains;
4343 force_sgi = mask->control[band].gi;
4344 if (force_sgi == NL80211_TXRATE_FORCE_LGI)
4347 if (!ath10k_default_bitrate_mask(ar, band, mask)) {
4348 if (!ath10k_get_fixed_rate_nss(ar, mask, band,
4354 if (fixed_rate == WMI_FIXED_RATE_NONE && force_sgi) {
4355 ath10k_warn(ar, "failed to force SGI usage for default rate settings\n");
4359 return ath10k_set_fixed_rate_param(arvif, fixed_rate,
4360 fixed_nss, force_sgi);
4363 static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4364 struct ieee80211_vif *vif,
4365 struct ieee80211_sta *sta,
4368 struct ath10k *ar = hw->priv;
4369 struct ath10k_sta *arsta = (struct ath10k_sta *)sta->drv_priv;
4372 spin_lock_bh(&ar->data_lock);
4374 ath10k_dbg(ar, ATH10K_DBG_MAC,
4375 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4376 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4379 if (changed & IEEE80211_RC_BW_CHANGED) {
4380 bw = WMI_PEER_CHWIDTH_20MHZ;
4382 switch (sta->bandwidth) {
4383 case IEEE80211_STA_RX_BW_20:
4384 bw = WMI_PEER_CHWIDTH_20MHZ;
4386 case IEEE80211_STA_RX_BW_40:
4387 bw = WMI_PEER_CHWIDTH_40MHZ;
4389 case IEEE80211_STA_RX_BW_80:
4390 bw = WMI_PEER_CHWIDTH_80MHZ;
4392 case IEEE80211_STA_RX_BW_160:
4393 ath10k_warn(ar, "Invalid bandwith %d in rc update for %pM\n",
4394 sta->bandwidth, sta->addr);
4395 bw = WMI_PEER_CHWIDTH_20MHZ;
4402 if (changed & IEEE80211_RC_NSS_CHANGED)
4403 arsta->nss = sta->rx_nss;
4405 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4406 smps = WMI_PEER_SMPS_PS_NONE;
4408 switch (sta->smps_mode) {
4409 case IEEE80211_SMPS_AUTOMATIC:
4410 case IEEE80211_SMPS_OFF:
4411 smps = WMI_PEER_SMPS_PS_NONE;
4413 case IEEE80211_SMPS_STATIC:
4414 smps = WMI_PEER_SMPS_STATIC;
4416 case IEEE80211_SMPS_DYNAMIC:
4417 smps = WMI_PEER_SMPS_DYNAMIC;
4419 case IEEE80211_SMPS_NUM_MODES:
4420 ath10k_warn(ar, "Invalid smps %d in sta rc update for %pM\n",
4421 sta->smps_mode, sta->addr);
4422 smps = WMI_PEER_SMPS_PS_NONE;
4429 arsta->changed |= changed;
4431 spin_unlock_bh(&ar->data_lock);
4433 ieee80211_queue_work(hw, &arsta->update_wk);
4436 static u64 ath10k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
4439 * FIXME: Return 0 for time being. Need to figure out whether FW
4440 * has the API to fetch 64-bit local TSF
4446 static int ath10k_ampdu_action(struct ieee80211_hw *hw,
4447 struct ieee80211_vif *vif,
4448 enum ieee80211_ampdu_mlme_action action,
4449 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4452 struct ath10k *ar = hw->priv;
4453 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4455 ath10k_dbg(ar, ATH10K_DBG_MAC, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4456 arvif->vdev_id, sta->addr, tid, action);
4459 case IEEE80211_AMPDU_RX_START:
4460 case IEEE80211_AMPDU_RX_STOP:
4461 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4462 * creation/removal. Do we need to verify this?
4465 case IEEE80211_AMPDU_TX_START:
4466 case IEEE80211_AMPDU_TX_STOP_CONT:
4467 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4468 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4469 case IEEE80211_AMPDU_TX_OPERATIONAL:
4470 /* Firmware offloads Tx aggregation entirely so deny mac80211
4471 * Tx aggregation requests.
4479 static const struct ieee80211_ops ath10k_ops = {
4481 .start = ath10k_start,
4482 .stop = ath10k_stop,
4483 .config = ath10k_config,
4484 .add_interface = ath10k_add_interface,
4485 .remove_interface = ath10k_remove_interface,
4486 .configure_filter = ath10k_configure_filter,
4487 .bss_info_changed = ath10k_bss_info_changed,
4488 .hw_scan = ath10k_hw_scan,
4489 .cancel_hw_scan = ath10k_cancel_hw_scan,
4490 .set_key = ath10k_set_key,
4491 .sta_state = ath10k_sta_state,
4492 .conf_tx = ath10k_conf_tx,
4493 .remain_on_channel = ath10k_remain_on_channel,
4494 .cancel_remain_on_channel = ath10k_cancel_remain_on_channel,
4495 .set_rts_threshold = ath10k_set_rts_threshold,
4496 .set_frag_threshold = ath10k_set_frag_threshold,
4497 .flush = ath10k_flush,
4498 .tx_last_beacon = ath10k_tx_last_beacon,
4499 .set_antenna = ath10k_set_antenna,
4500 .get_antenna = ath10k_get_antenna,
4501 .restart_complete = ath10k_restart_complete,
4502 .get_survey = ath10k_get_survey,
4503 .set_bitrate_mask = ath10k_set_bitrate_mask,
4504 .sta_rc_update = ath10k_sta_rc_update,
4505 .get_tsf = ath10k_get_tsf,
4506 .ampdu_action = ath10k_ampdu_action,
4507 .get_et_sset_count = ath10k_debug_get_et_sset_count,
4508 .get_et_stats = ath10k_debug_get_et_stats,
4509 .get_et_strings = ath10k_debug_get_et_strings,
4511 CFG80211_TESTMODE_CMD(ath10k_tm_cmd)
4514 .suspend = ath10k_suspend,
4515 .resume = ath10k_resume,
4519 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4520 .bitrate = (_rate), \
4521 .flags = (_flags), \
4522 .hw_value = (_rateid), \
4525 #define CHAN2G(_channel, _freq, _flags) { \
4526 .band = IEEE80211_BAND_2GHZ, \
4527 .hw_value = (_channel), \
4528 .center_freq = (_freq), \
4529 .flags = (_flags), \
4530 .max_antenna_gain = 0, \
4534 #define CHAN5G(_channel, _freq, _flags) { \
4535 .band = IEEE80211_BAND_5GHZ, \
4536 .hw_value = (_channel), \
4537 .center_freq = (_freq), \
4538 .flags = (_flags), \
4539 .max_antenna_gain = 0, \
4543 static const struct ieee80211_channel ath10k_2ghz_channels[] = {
4553 CHAN2G(10, 2457, 0),
4554 CHAN2G(11, 2462, 0),
4555 CHAN2G(12, 2467, 0),
4556 CHAN2G(13, 2472, 0),
4557 CHAN2G(14, 2484, 0),
4560 static const struct ieee80211_channel ath10k_5ghz_channels[] = {
4561 CHAN5G(36, 5180, 0),
4562 CHAN5G(40, 5200, 0),
4563 CHAN5G(44, 5220, 0),
4564 CHAN5G(48, 5240, 0),
4565 CHAN5G(52, 5260, 0),
4566 CHAN5G(56, 5280, 0),
4567 CHAN5G(60, 5300, 0),
4568 CHAN5G(64, 5320, 0),
4569 CHAN5G(100, 5500, 0),
4570 CHAN5G(104, 5520, 0),
4571 CHAN5G(108, 5540, 0),
4572 CHAN5G(112, 5560, 0),
4573 CHAN5G(116, 5580, 0),
4574 CHAN5G(120, 5600, 0),
4575 CHAN5G(124, 5620, 0),
4576 CHAN5G(128, 5640, 0),
4577 CHAN5G(132, 5660, 0),
4578 CHAN5G(136, 5680, 0),
4579 CHAN5G(140, 5700, 0),
4580 CHAN5G(149, 5745, 0),
4581 CHAN5G(153, 5765, 0),
4582 CHAN5G(157, 5785, 0),
4583 CHAN5G(161, 5805, 0),
4584 CHAN5G(165, 5825, 0),
4587 static struct ieee80211_rate ath10k_rates[] = {
4589 RATETAB_ENT(10, 0x82, 0),
4590 RATETAB_ENT(20, 0x84, 0),
4591 RATETAB_ENT(55, 0x8b, 0),
4592 RATETAB_ENT(110, 0x96, 0),
4594 RATETAB_ENT(60, 0x0c, 0),
4595 RATETAB_ENT(90, 0x12, 0),
4596 RATETAB_ENT(120, 0x18, 0),
4597 RATETAB_ENT(180, 0x24, 0),
4598 RATETAB_ENT(240, 0x30, 0),
4599 RATETAB_ENT(360, 0x48, 0),
4600 RATETAB_ENT(480, 0x60, 0),
4601 RATETAB_ENT(540, 0x6c, 0),
4604 #define ath10k_a_rates (ath10k_rates + 4)
4605 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4606 #define ath10k_g_rates (ath10k_rates + 0)
4607 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4609 struct ath10k *ath10k_mac_create(size_t priv_size)
4611 struct ieee80211_hw *hw;
4614 hw = ieee80211_alloc_hw(sizeof(struct ath10k) + priv_size, &ath10k_ops);
4624 void ath10k_mac_destroy(struct ath10k *ar)
4626 ieee80211_free_hw(ar->hw);
4629 static const struct ieee80211_iface_limit ath10k_if_limits[] = {
4632 .types = BIT(NL80211_IFTYPE_STATION)
4633 | BIT(NL80211_IFTYPE_P2P_CLIENT)
4637 .types = BIT(NL80211_IFTYPE_P2P_GO)
4641 .types = BIT(NL80211_IFTYPE_AP)
4645 static const struct ieee80211_iface_limit ath10k_10x_if_limits[] = {
4648 .types = BIT(NL80211_IFTYPE_AP)
4652 static const struct ieee80211_iface_combination ath10k_if_comb[] = {
4654 .limits = ath10k_if_limits,
4655 .n_limits = ARRAY_SIZE(ath10k_if_limits),
4656 .max_interfaces = 8,
4657 .num_different_channels = 1,
4658 .beacon_int_infra_match = true,
4662 static const struct ieee80211_iface_combination ath10k_10x_if_comb[] = {
4664 .limits = ath10k_10x_if_limits,
4665 .n_limits = ARRAY_SIZE(ath10k_10x_if_limits),
4666 .max_interfaces = 8,
4667 .num_different_channels = 1,
4668 .beacon_int_infra_match = true,
4669 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4670 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4671 BIT(NL80211_CHAN_WIDTH_20) |
4672 BIT(NL80211_CHAN_WIDTH_40) |
4673 BIT(NL80211_CHAN_WIDTH_80),
4678 static struct ieee80211_sta_vht_cap ath10k_create_vht_cap(struct ath10k *ar)
4680 struct ieee80211_sta_vht_cap vht_cap = {0};
4684 vht_cap.vht_supported = 1;
4685 vht_cap.cap = ar->vht_cap_info;
4688 for (i = 0; i < 8; i++) {
4689 if (i < ar->num_rf_chains)
4690 mcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i*2);
4692 mcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i*2);
4695 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
4696 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
4701 static struct ieee80211_sta_ht_cap ath10k_get_ht_cap(struct ath10k *ar)
4704 struct ieee80211_sta_ht_cap ht_cap = {0};
4706 if (!(ar->ht_cap_info & WMI_HT_CAP_ENABLED))
4709 ht_cap.ht_supported = 1;
4710 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4711 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
4712 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4713 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4714 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4716 if (ar->ht_cap_info & WMI_HT_CAP_HT20_SGI)
4717 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4719 if (ar->ht_cap_info & WMI_HT_CAP_HT40_SGI)
4720 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4722 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS) {
4725 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4726 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4731 if (ar->ht_cap_info & WMI_HT_CAP_TX_STBC)
4732 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4734 if (ar->ht_cap_info & WMI_HT_CAP_RX_STBC) {
4737 stbc = ar->ht_cap_info;
4738 stbc &= WMI_HT_CAP_RX_STBC;
4739 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4740 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4741 stbc &= IEEE80211_HT_CAP_RX_STBC;
4746 if (ar->ht_cap_info & WMI_HT_CAP_LDPC)
4747 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4749 if (ar->ht_cap_info & WMI_HT_CAP_L_SIG_TXOP_PROT)
4750 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4752 /* max AMSDU is implicitly taken from vht_cap_info */
4753 if (ar->vht_cap_info & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4754 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4756 for (i = 0; i < ar->num_rf_chains; i++)
4757 ht_cap.mcs.rx_mask[i] = 0xFF;
4759 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4764 static void ath10k_get_arvif_iter(void *data, u8 *mac,
4765 struct ieee80211_vif *vif)
4767 struct ath10k_vif_iter *arvif_iter = data;
4768 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
4770 if (arvif->vdev_id == arvif_iter->vdev_id)
4771 arvif_iter->arvif = arvif;
4774 struct ath10k_vif *ath10k_get_arvif(struct ath10k *ar, u32 vdev_id)
4776 struct ath10k_vif_iter arvif_iter;
4779 memset(&arvif_iter, 0, sizeof(struct ath10k_vif_iter));
4780 arvif_iter.vdev_id = vdev_id;
4782 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
4783 ieee80211_iterate_active_interfaces_atomic(ar->hw,
4785 ath10k_get_arvif_iter,
4787 if (!arvif_iter.arvif) {
4788 ath10k_warn(ar, "No VIF found for vdev %d\n", vdev_id);
4792 return arvif_iter.arvif;
4795 int ath10k_mac_register(struct ath10k *ar)
4797 struct ieee80211_supported_band *band;
4798 struct ieee80211_sta_vht_cap vht_cap;
4799 struct ieee80211_sta_ht_cap ht_cap;
4803 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
4805 SET_IEEE80211_DEV(ar->hw, ar->dev);
4807 ht_cap = ath10k_get_ht_cap(ar);
4808 vht_cap = ath10k_create_vht_cap(ar);
4810 if (ar->phy_capability & WHAL_WLAN_11G_CAPABILITY) {
4811 channels = kmemdup(ath10k_2ghz_channels,
4812 sizeof(ath10k_2ghz_channels),
4819 band = &ar->mac.sbands[IEEE80211_BAND_2GHZ];
4820 band->n_channels = ARRAY_SIZE(ath10k_2ghz_channels);
4821 band->channels = channels;
4822 band->n_bitrates = ath10k_g_rates_size;
4823 band->bitrates = ath10k_g_rates;
4824 band->ht_cap = ht_cap;
4826 /* vht is not supported in 2.4 GHz */
4828 ar->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
4831 if (ar->phy_capability & WHAL_WLAN_11A_CAPABILITY) {
4832 channels = kmemdup(ath10k_5ghz_channels,
4833 sizeof(ath10k_5ghz_channels),
4840 band = &ar->mac.sbands[IEEE80211_BAND_5GHZ];
4841 band->n_channels = ARRAY_SIZE(ath10k_5ghz_channels);
4842 band->channels = channels;
4843 band->n_bitrates = ath10k_a_rates_size;
4844 band->bitrates = ath10k_a_rates;
4845 band->ht_cap = ht_cap;
4846 band->vht_cap = vht_cap;
4847 ar->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
4850 ar->hw->wiphy->interface_modes =
4851 BIT(NL80211_IFTYPE_STATION) |
4852 BIT(NL80211_IFTYPE_AP);
4854 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4855 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4857 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4858 ar->hw->wiphy->interface_modes |=
4859 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4860 BIT(NL80211_IFTYPE_P2P_GO);
4862 ar->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4863 IEEE80211_HW_SUPPORTS_PS |
4864 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
4865 IEEE80211_HW_SUPPORTS_UAPSD |
4866 IEEE80211_HW_MFP_CAPABLE |
4867 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4868 IEEE80211_HW_HAS_RATE_CONTROL |
4869 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
4870 IEEE80211_HW_AP_LINK_PS |
4871 IEEE80211_HW_SPECTRUM_MGMT;
4873 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4874 * bytes is used for padding/alignment if necessary. */
4875 ar->hw->extra_tx_headroom += sizeof(struct htt_data_tx_desc_frag)*2 + 4;
4877 if (ar->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
4878 ar->hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS;
4880 if (ar->ht_cap_info & WMI_HT_CAP_ENABLED) {
4881 ar->hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4882 ar->hw->flags |= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW;
4885 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
4886 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
4888 ar->hw->vif_data_size = sizeof(struct ath10k_vif);
4889 ar->hw->sta_data_size = sizeof(struct ath10k_sta);
4891 ar->hw->max_listen_interval = ATH10K_MAX_HW_LISTEN_INTERVAL;
4893 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
4894 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4895 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
4897 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
4899 * on LL hardware queues are managed entirely by the FW
4900 * so we only advertise to mac we can do the queues thing
4904 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4905 ar->hw->wiphy->iface_combinations = ath10k_10x_if_comb;
4906 ar->hw->wiphy->n_iface_combinations =
4907 ARRAY_SIZE(ath10k_10x_if_comb);
4909 ar->hw->wiphy->iface_combinations = ath10k_if_comb;
4910 ar->hw->wiphy->n_iface_combinations =
4911 ARRAY_SIZE(ath10k_if_comb);
4913 ar->hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
4916 ar->hw->netdev_features = NETIF_F_HW_CSUM;
4918 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED)) {
4919 /* Init ath dfs pattern detector */
4920 ar->ath_common.debug_mask = ATH_DBG_DFS;
4921 ar->dfs_detector = dfs_pattern_detector_init(&ar->ath_common,
4924 if (!ar->dfs_detector)
4925 ath10k_warn(ar, "failed to initialise DFS pattern detector\n");
4928 ret = ath_regd_init(&ar->ath_common.regulatory, ar->hw->wiphy,
4929 ath10k_reg_notifier);
4931 ath10k_err(ar, "failed to initialise regulatory: %i\n", ret);
4935 ret = ieee80211_register_hw(ar->hw);
4937 ath10k_err(ar, "failed to register ieee80211: %d\n", ret);
4941 if (!ath_is_world_regd(&ar->ath_common.regulatory)) {
4942 ret = regulatory_hint(ar->hw->wiphy,
4943 ar->ath_common.regulatory.alpha2);
4945 goto err_unregister;
4951 ieee80211_unregister_hw(ar->hw);
4953 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4954 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4959 void ath10k_mac_unregister(struct ath10k *ar)
4961 ieee80211_unregister_hw(ar->hw);
4963 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED) && ar->dfs_detector)
4964 ar->dfs_detector->exit(ar->dfs_detector);
4966 kfree(ar->mac.sbands[IEEE80211_BAND_2GHZ].channels);
4967 kfree(ar->mac.sbands[IEEE80211_BAND_5GHZ].channels);
4969 SET_IEEE80211_DEV(ar->hw, NULL);